feat(app): complete the Library: timeline, saved views, quick and mass actions, remote cards
The Library gets a third layout (year bands of photos per month over the card grid; a month narrows to its year and scrolls to it), saved views stored as app-scope settings rows, hover quick actions on cards and rows (open, analyse, render the sequence's preset, sync), the full mass actions bar (analyse, proxies, verify, tags, rating, move, upload, download, delete into the trash, CSV) with each button's reason when it cannot run, and, while signed in, the server's sequences without a local copy as remote cards filterable by origin. Delete shows the engine's dry run behind a typed confirmation and offers Undo; the Archive manager gets Delete… and a Trash dialog that restores sequences. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
27 files changed
+2582
-422
No files matched your search
@@ -0,0 +1,217 @@
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using Titano.App.Jobs;
|
||||
using Titano.App.Server;
|
||||
using Titano.App.Shell;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Data;
|
||||
using Titano.Data.Archiving;
|
||||
using Titano.Data.Archiving.Jobs;
|
||||
using Titano.Data.Processing;
|
||||
using Titano.Data.Sync;
|
||||
using Titano.Protocol;
|
||||
using Titano.Protocol.Client;
|
||||
|
||||
namespace Titano.App.Library;
|
||||
|
||||
/// <summary>
|
||||
/// What the Library's quick and mass actions run (BRIEF §12.2): analyses, proxies, verifies and renders as jobs on
|
||||
/// this PC's engine, or posted to the server for a sequence that only lives there; uploads, downloads and settings
|
||||
/// exchanges through the sync engine (as the Server screen does); ratings through the archive engine (sidecar and
|
||||
/// index together). Every queued job is announced with a toast that opens the Jobs screen.
|
||||
/// </summary>
|
||||
public sealed class LibraryActions(ShellViewModel shell)
|
||||
{
|
||||
/// <summary>Wire names of the job kinds a remote card posts (<c>POST /api/v1/jobs</c>).</summary>
|
||||
private const string RenderKind = "render";
|
||||
|
||||
private const string DeepAnalyseKind = "deep-analyse";
|
||||
|
||||
private Infrastructure.AppServices Services => shell.Services;
|
||||
|
||||
/// <summary>The signed-in server's sync engine and connection; null while signed out.</summary>
|
||||
public RemoteSource? Remote() =>
|
||||
Services.Sync is { Service: { } service, Server: { } server, Remote: { } remote } ? new RemoteSource(service, server, remote) : null;
|
||||
|
||||
/// <summary>What the signed-in account may do; nothing while signed out.</summary>
|
||||
public SyncRights Rights => Services.Server.User is { } user ? SyncRights.Of(user.Permissions) : default;
|
||||
|
||||
/// <summary>Deep analysis of sequences on this PC (one job), or of a remote card on the server.</summary>
|
||||
public async Task AnalyseAsync(IReadOnlyList<Sequence> sequences)
|
||||
{
|
||||
if (sequences is [{ Origin: SequenceOrigin.Server, SyncState: SyncState.RemoteOnly } remote])
|
||||
{
|
||||
await PostAsync(() => Task.FromResult(new CreateJobRequest(DeepAnalyseKind, [remote.Id], null)), JobKind.DeepAnalyse, remote.DisplayTitle);
|
||||
return;
|
||||
}
|
||||
await QueueAsync(ProcessingJobs.DeepAnalysis([.. sequences.Select(s => s.Id)], Label(sequences)));
|
||||
}
|
||||
|
||||
public Task ProxiesAsync(IReadOnlyList<Sequence> sequences) => QueueAsync(ArchiveJobs.Proxies([.. sequences.Select(s => s.Id)], Label(sequences)));
|
||||
|
||||
/// <summary>Verification is an archive job: one per archive, naming its sequences.</summary>
|
||||
public async Task VerifyAsync(IReadOnlyList<Sequence> sequences)
|
||||
{
|
||||
if (Services.Database is not { } db) return;
|
||||
foreach (var group in sequences.GroupBy(s => s.ArchiveId))
|
||||
{
|
||||
if (await db.Archives.GetAsync(group.Key) is { } archive) await QueueAsync(ArchiveJobs.Verify(archive, [.. group.Select(s => s.Id)]));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Render quick action: the sequence's own export (its recommended preset, else the default) with its project as
|
||||
/// stored, on this PC's engine — or posted to the server for a remote card, which renders it where the originals are.
|
||||
/// </summary>
|
||||
public async Task RenderAsync(Sequence sequence)
|
||||
{
|
||||
if (sequence is { Origin: SequenceOrigin.Server, SyncState: SyncState.RemoteOnly })
|
||||
{
|
||||
if (Remote() is not { } remote) return;
|
||||
await PostAsync(async () =>
|
||||
{
|
||||
var (project, width, height) = await RemoteProjectAsync(remote, sequence.Id);
|
||||
return new CreateJobRequest(RenderKind, [sequence.Id], ProcessingJobs.Render(sequence, project.Export with { Batch = [] }, width, height).ParametersJson);
|
||||
}, JobKind.Render, sequence.DisplayTitle);
|
||||
return;
|
||||
}
|
||||
if (Services.Database is not { } db) return;
|
||||
var first = (await db.Frames.ListBySequenceAsync(sequence.Id, -1, 1)).FirstOrDefault();
|
||||
var (w, h) = first is null ? (0, 0) : first.Orientation is >= 5 and <= 8 ? (first.Height, first.Width) : (first.Width, first.Height);
|
||||
var export = Project(sequence.SettingsJson).Export with { Batch = [] };
|
||||
await QueueAsync(ProcessingJobs.Render(sequence, export, w, h));
|
||||
}
|
||||
|
||||
/// <summary>Runs one row action of the sync table on a sequence (the card's Sync, a mass Upload or Download); false when it could not start.</summary>
|
||||
public async Task<bool> SyncAsync(SelectedSequence selected, SyncAction action)
|
||||
{
|
||||
if (Remote() is not { } remote || Services.Engine is not { } engine) return false;
|
||||
var entry = selected.Sync;
|
||||
switch (action)
|
||||
{
|
||||
case SyncAction.Upload when !selected.IsRemote:
|
||||
await remote.Service.EnqueueUploadAsync(engine, remote.Server, selected.Sequence);
|
||||
return true;
|
||||
case SyncAction.SendExports when !selected.IsRemote:
|
||||
await remote.Service.EnqueueSendExportsAsync(engine, remote.Server, selected.Sequence);
|
||||
return true;
|
||||
case SyncAction.DownloadOriginals when entry is not null:
|
||||
if ((entry.Local?.ArchiveId ?? (await Services.Sync.CurrentArchiveAsync())?.Id) is not { } archive)
|
||||
{
|
||||
shell.Notify(Loc.L("Errors.Sync.NoArchive"));
|
||||
return false;
|
||||
}
|
||||
await remote.Service.EnqueueDownloadAsync(engine, remote.Server, entry.Id, entry.Title, SyncDownloadMode.Originals, archive);
|
||||
return true;
|
||||
case SyncAction.GetExports when entry is not null:
|
||||
await remote.Service.EnqueueDownloadAsync(engine, remote.Server, entry.Id, entry.Title, SyncDownloadMode.Exports, null);
|
||||
return true;
|
||||
case SyncAction.SyncSettings when entry is not null:
|
||||
await remote.Service.SyncSettingsAsync(remote.Remote, entry.Id, Services.Sync.Policy, CancellationToken.None);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens a remote card with proxies (BRIEF §14.5): at once when its proxies are cached here, otherwise after the
|
||||
/// proxy download this queues. Returns that download job, or null when the editor opened (or nothing could start).
|
||||
/// </summary>
|
||||
public async Task<Guid?> OpenRemoteAsync(Sequence sequence)
|
||||
{
|
||||
if (Remote() is not { } remote || Services.Engine is not { } engine) return null;
|
||||
if (remote.Service.OpenRemote(remote.Server, sequence.Id) is not null)
|
||||
{
|
||||
shell.OpenSequence(sequence.Id);
|
||||
return null;
|
||||
}
|
||||
var job = await remote.Service.EnqueueDownloadAsync(engine, remote.Server, sequence.Id, sequence.DisplayTitle, SyncDownloadMode.Proxies, null);
|
||||
Queued(JobKind.Download, sequence.DisplayTitle);
|
||||
return job.Id;
|
||||
}
|
||||
|
||||
/// <summary>Sets the rating of sequences on this PC (sidecar and index together); returns how many changed.</summary>
|
||||
public async Task<int> RateAsync(IReadOnlyList<Sequence> sequences, int rating)
|
||||
{
|
||||
if (Services.Archives is not { } archives) return 0;
|
||||
var changed = 0;
|
||||
try
|
||||
{
|
||||
foreach (var s in sequences.Where(s => s.Rating != rating))
|
||||
{
|
||||
await Task.Run(() => archives.SetSequenceInfoAsync(s.Id, s.Title, s.Tags, rating, s.Notes));
|
||||
changed++;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException or DatabaseException)
|
||||
{
|
||||
Log.Warning("library", "Rating failed", ex);
|
||||
shell.Notify(Loc.L("Library.Rate.Failed"), ex.Message);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// <summary>"Deep analysis queued · Harbour sunset", with a way to the Jobs screen.</summary>
|
||||
public void Queued(JobKind kind, string label) =>
|
||||
shell.Notify(Loc.L("Library.Queued", JobText.Kind(kind), label), actionText: Loc.L("Shell.Nav.Jobs"), actionToolTip: Loc.L("Tooltips.Nav.Jobs"),
|
||||
action: () => shell.Navigate(SectionKey.Jobs));
|
||||
|
||||
public static string Label(IReadOnlyList<Sequence> sequences) =>
|
||||
sequences.Count == 1 ? sequences[0].DisplayTitle : Loc.Plural("Library.Selection.Count", sequences.Count);
|
||||
|
||||
private async Task QueueAsync(ArchiveJobRequest request)
|
||||
{
|
||||
if (Services.Engine is not { } engine || request.Targets.Count == 0) return;
|
||||
await engine.EnqueueAsync(request);
|
||||
Queued(request.Kind, request.Label ?? string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>Posts a job to the signed-in server, which runs it or hands it to a render node (BRIEF §14.6, §14.7).</summary>
|
||||
private async Task PostAsync(Func<Task<CreateJobRequest>> build, JobKind kind, string label)
|
||||
{
|
||||
var session = Services.Server;
|
||||
if (!session.IsConnected || session.Flow is not { Address: { } address, Token: { } token }) return;
|
||||
try
|
||||
{
|
||||
var request = await build();
|
||||
using var client = new TitanoClient(address, new CertificatePinning(session.Fingerprints), $"Titano ({Environment.MachineName})") { Token = token };
|
||||
await client.CreateJobAsync(request);
|
||||
shell.Notify(Loc.L("Library.QueuedServer", JobText.Kind(kind), label));
|
||||
}
|
||||
catch (Exception ex) when (ex is TitanoApiException or HttpRequestException or IOException or TaskCanceledException)
|
||||
{
|
||||
Log.Warning("library", $"Posting a {kind} job to {address} failed", ex);
|
||||
shell.Notify(Loc.L("Library.Post.Failed"), ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The project of a remote card: from its proxy cache when it was opened here, else from the server's manifest; and its frame size when cached.</summary>
|
||||
private static async Task<(ProjectSettings Project, int Width, int Height)> RemoteProjectAsync(RemoteSource remote, Guid id)
|
||||
{
|
||||
if (remote.Service.OpenRemote(remote.Server, id) is { } cached)
|
||||
{
|
||||
var frame = cached.Frames.FirstOrDefault(f => f.Width > 0);
|
||||
var size = frame is null ? (0, 0) : frame.Orientation is >= 5 and <= 8 ? (frame.Height, frame.Width) : (frame.Width, frame.Height);
|
||||
return (Project(cached.Sequence.SettingsJson), size.Item1, size.Item2);
|
||||
}
|
||||
var manifest = await remote.Remote.GetManifestAsync(id, CancellationToken.None);
|
||||
return (Project(manifest.SettingsJson), 0, 0);
|
||||
}
|
||||
|
||||
private static ProjectSettings Project(string? json)
|
||||
{
|
||||
try
|
||||
{
|
||||
return json is null ? new ProjectSettings() : ProjectSettings.FromJson(json);
|
||||
}
|
||||
catch (System.Text.Json.JsonException ex)
|
||||
{
|
||||
Log.Warning("library", "Unreadable project settings; rendering the defaults", ex);
|
||||
return new ProjectSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,15 @@ public enum StatusFilter
|
||||
Warnings,
|
||||
}
|
||||
|
||||
/// <summary>Library filters (search, year, camera, status, tag) and sort; immutable so a page request can carry it.</summary>
|
||||
/// <summary>Where the sequences of the Library live (BRIEF §4.4 mixed mode): both, this PC, or only the signed-in server.</summary>
|
||||
public enum OriginFilter
|
||||
{
|
||||
Any,
|
||||
Local,
|
||||
Server,
|
||||
}
|
||||
|
||||
/// <summary>Library filters (search, year, camera, status, tag, origin) and sort; immutable so a page request can carry it.</summary>
|
||||
public sealed record LibraryFilter
|
||||
{
|
||||
public string? Text { get; init; }
|
||||
@@ -24,10 +32,12 @@ public sealed record LibraryFilter
|
||||
public string? Camera { get; init; }
|
||||
public StatusFilter Status { get; init; }
|
||||
public string? Tag { get; init; }
|
||||
public OriginFilter Origin { get; init; }
|
||||
public SequenceSort Sort { get; init; } = SequenceSort.Newest;
|
||||
|
||||
/// <summary>No filter narrows the list (the sort may differ): an empty result means an empty library.</summary>
|
||||
public bool IsUnfiltered => string.IsNullOrWhiteSpace(Text) && Year is null && Camera is null && Status == StatusFilter.Any && Tag is null;
|
||||
public bool IsUnfiltered => string.IsNullOrWhiteSpace(Text) && Year is null && Camera is null && Status == StatusFilter.Any && Tag is null
|
||||
&& Origin == OriginFilter.Any;
|
||||
|
||||
/// <summary>The same sort without filters ("Clear filters").</summary>
|
||||
public LibraryFilter Cleared() => new() { Sort = Sort };
|
||||
@@ -50,6 +60,47 @@ public sealed record LibraryFilter
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The same test the index applies to its rows (<see cref="ToQuery"/>), for sequences that are not in the index
|
||||
/// (server sequences without a local copy): title, camera or tag text, capture year, camera model, status, tag.
|
||||
/// </summary>
|
||||
public bool Matches(Sequence sequence)
|
||||
{
|
||||
if (Year is { } year && sequence.FirstCapture?.Year != year) return false;
|
||||
if (Camera is not null && sequence.CameraModel != Camera) return false;
|
||||
var (with, without) = Flags(Status);
|
||||
if ((sequence.Status & with) != with || (sequence.Status & without) != 0) return false;
|
||||
if (Tag is not null && !sequence.Tags.Contains(TagRepository.Normalize(Tag), StringComparer.OrdinalIgnoreCase)) return false;
|
||||
if (string.IsNullOrWhiteSpace(Text)) return true;
|
||||
var text = Text.Trim();
|
||||
return new[] { sequence.Title, sequence.CameraMake, sequence.CameraModel }.Any(v => v?.Contains(text, StringComparison.OrdinalIgnoreCase) == true)
|
||||
|| sequence.Tags.Any(t => t.Contains(text, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>The index's order of <see cref="Sort"/> (missing values last, the id as tie-breaker), for merging pages with other sequences.</summary>
|
||||
public int Compare(Sequence a, Sequence b)
|
||||
{
|
||||
var order = Sort switch
|
||||
{
|
||||
SequenceSort.Newest => Nullable(a.FirstCapture, b.FirstCapture, descending: true),
|
||||
SequenceSort.Oldest => Nullable(a.FirstCapture, b.FirstCapture, descending: false),
|
||||
SequenceSort.Title => string.CompareOrdinal(a.DisplayTitle.ToLowerInvariant(), b.DisplayTitle.ToLowerInvariant()),
|
||||
SequenceSort.FrameCount => b.FrameCount.CompareTo(a.FrameCount),
|
||||
_ => b.TotalBytes.CompareTo(a.TotalBytes),
|
||||
};
|
||||
if (order != 0) return order;
|
||||
var ids = string.CompareOrdinal(a.Id.ToString(), b.Id.ToString());
|
||||
return Sort is SequenceSort.Oldest or SequenceSort.Title ? ids : -ids;
|
||||
|
||||
static int Nullable(DateTime? x, DateTime? y, bool descending) => (x, y) switch
|
||||
{
|
||||
(null, null) => 0,
|
||||
(null, _) => 1,
|
||||
(_, null) => -1,
|
||||
_ => descending ? y!.Value.CompareTo(x!.Value) : x!.Value.CompareTo(y!.Value),
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Flags that must be set and clear for a status choice.</summary>
|
||||
public static (SequenceStatus With, SequenceStatus Without) Flags(StatusFilter status) => status switch
|
||||
{
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
using Titano.App.Archiving;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Repositories;
|
||||
|
||||
namespace Titano.App.Library;
|
||||
|
||||
/// <summary>
|
||||
/// The Library's timeline layout (BRIEF §12.2): one band per capture year, newest first, with the density of photos
|
||||
/// per month (the Archive heatmap's figures), and the way between a band's month and the sequences of the grid.
|
||||
/// </summary>
|
||||
public sealed class LibraryTimeline
|
||||
{
|
||||
private LibraryTimeline(IReadOnlyList<HeatRow> bands, IReadOnlyList<int> years)
|
||||
{
|
||||
Bands = bands;
|
||||
Years = years;
|
||||
}
|
||||
|
||||
public static LibraryTimeline Empty { get; } = new([], []);
|
||||
|
||||
/// <summary>One row per year, newest first; months to come are NaN.</summary>
|
||||
public IReadOnlyList<HeatRow> Bands { get; }
|
||||
|
||||
/// <summary>The year of each band.</summary>
|
||||
public IReadOnlyList<int> Years { get; }
|
||||
|
||||
public static LibraryTimeline From(ArchiveStats stats, DateTime today)
|
||||
{
|
||||
var rows = ArchiveFigures.PhotosPerMonth(stats, today).Reverse().ToList();
|
||||
var first = stats.ByMonth.Count == 0 ? 0 : stats.ByMonth.Max(m => m.Year);
|
||||
return new LibraryTimeline(rows, [.. Enumerable.Range(0, rows.Count).Select(i => first - i)]);
|
||||
}
|
||||
|
||||
/// <summary>Year and month of a band's slot; null outside the bands.</summary>
|
||||
public (int Year, int Month)? MonthAt(int band, int slot) =>
|
||||
band >= 0 && band < Years.Count && slot is >= 0 and < 12 ? (Years[band], slot + 1) : null;
|
||||
|
||||
/// <summary>Band and slot of a month; (−1, −1) when no band shows that year.</summary>
|
||||
public (int Band, int Slot) SlotOf(int year, int month)
|
||||
{
|
||||
var band = IndexOf(Years, year);
|
||||
return band < 0 || month is < 1 or > 12 ? (-1, -1) : (band, month - 1);
|
||||
}
|
||||
|
||||
/// <summary>Position of the first sequence first captured in that month, in list order; −1 when none of <paramref name="sequences"/> is.</summary>
|
||||
public static int FirstOfMonth(IReadOnlyList<Sequence> sequences, int year, int month)
|
||||
{
|
||||
for (var i = 0; i < sequences.Count; i++)
|
||||
{
|
||||
if (sequences[i].FirstCapture is { } at && at.Year == year && at.Month == month) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int IndexOf(IReadOnlyList<int> values, int value)
|
||||
{
|
||||
for (var i = 0; i < values.Count; i++)
|
||||
{
|
||||
if (values[i] == value) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
using Titano.App.Server;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Sync;
|
||||
|
||||
namespace Titano.App.Library;
|
||||
|
||||
/// <summary>The actions of the Library's mass actions bar (BRIEF §12.2).</summary>
|
||||
public enum MassAction
|
||||
{
|
||||
Analyse,
|
||||
Proxies,
|
||||
Verify,
|
||||
Tag,
|
||||
Rate,
|
||||
Move,
|
||||
Upload,
|
||||
Download,
|
||||
Delete,
|
||||
ExportList,
|
||||
}
|
||||
|
||||
/// <summary>A selected sequence and, while signed in, its row of the sync table.</summary>
|
||||
public sealed record SelectedSequence(Sequence Sequence, SyncEntry? Sync)
|
||||
{
|
||||
/// <summary>Only on the server: no copy on this PC (a remote card).</summary>
|
||||
public bool IsRemote => Sequence is { Origin: SequenceOrigin.Server, SyncState: SyncState.RemoteOnly };
|
||||
}
|
||||
|
||||
/// <summary>What this PC can do right now.</summary>
|
||||
/// <param name="HasEngine">The index and the job engine are open.</param>
|
||||
/// <param name="IsSignedIn">A server session is open (uploads, downloads, remote cards).</param>
|
||||
public sealed record SelectionContext(bool HasEngine, bool IsSignedIn, SyncRights Rights);
|
||||
|
||||
/// <summary>
|
||||
/// Which selected sequences each mass action works on and, when it works on none, why (the disabled button's
|
||||
/// tooltip, DESIGN §4). Archive actions touch sequences on this PC; Upload and Download follow the sync table's own
|
||||
/// row actions (<see cref="SyncText.Actions"/>), so the Library and the Server screen never disagree.
|
||||
/// </summary>
|
||||
public static class MassActions
|
||||
{
|
||||
/// <summary>The selected sequences <paramref name="action"/> works on.</summary>
|
||||
public static IReadOnlyList<SelectedSequence> Targets(MassAction action, IReadOnlyList<SelectedSequence> selection, SelectionContext context) => action switch
|
||||
{
|
||||
MassAction.ExportList => selection,
|
||||
MassAction.Upload => [.. selection.Where(s => !s.IsRemote && UploadStep(s, context.Rights) is not null)],
|
||||
MassAction.Download => [.. selection.Where(s => DownloadStep(s, context.Rights) is not null)],
|
||||
_ => [.. selection.Where(s => !s.IsRemote)],
|
||||
};
|
||||
|
||||
/// <summary>Why <paramref name="action"/> cannot run on the selection, localized; null when it can.</summary>
|
||||
public static string? Blocker(MassAction action, IReadOnlyList<SelectedSequence> selection, SelectionContext context)
|
||||
{
|
||||
if (selection.Count == 0) return Loc.L("Library.Blocked.NoSelection");
|
||||
if (action == MassAction.ExportList) return null;
|
||||
if (!context.HasEngine) return Loc.L("Library.Blocked.NoIndex");
|
||||
var targets = Targets(action, selection, context);
|
||||
switch (action)
|
||||
{
|
||||
case MassAction.Upload or MassAction.Download when !context.IsSignedIn:
|
||||
return Loc.L("Library.Blocked.NotConnected");
|
||||
case MassAction.Upload when !context.Rights.CanUpload:
|
||||
return Loc.L("Library.Blocked.NoUploadRight");
|
||||
case MassAction.Download when !context.Rights.CanFetchOriginals:
|
||||
return Loc.L("Library.Blocked.NoDownloadRight");
|
||||
case MassAction.Upload when targets.Count == 0:
|
||||
return Loc.L("Library.Blocked.NothingToUpload");
|
||||
case MassAction.Download when targets.Count == 0:
|
||||
return Loc.L("Library.Blocked.NothingToDownload");
|
||||
case MassAction.Upload or MassAction.Download:
|
||||
return null;
|
||||
}
|
||||
if (targets.Count == 0) return Loc.L("Library.Blocked.ServerOnly");
|
||||
return action == MassAction.Move && targets.Select(t => t.Sequence.ArchiveId).Distinct().Count() > 1 ? Loc.L("Library.Blocked.Archives") : null;
|
||||
}
|
||||
|
||||
/// <summary>The enabled tooltip: what the action does to how many sequences.</summary>
|
||||
public static string ToolTip(MassAction action, int targets) => Loc.Plural("Tooltips.Library.Mass." + action, targets);
|
||||
|
||||
/// <summary>What an upload of a selected local sequence sends: its originals and settings, or only its renders; null when nothing.</summary>
|
||||
public static SyncAction? UploadStep(SelectedSequence selected, SyncRights rights)
|
||||
{
|
||||
// Compared before the table lists it: the sequence is only here.
|
||||
if (selected.Sync is not { } entry) return rights.CanUpload && !selected.IsRemote ? SyncAction.Upload : null;
|
||||
var actions = SyncText.Actions(entry, rights);
|
||||
return actions.Contains(SyncAction.Upload) ? SyncAction.Upload : actions.Contains(SyncAction.SendExports) ? SyncAction.SendExports : null;
|
||||
}
|
||||
|
||||
/// <summary>What a download of a selected sequence fetches: the server's originals, or only its renders; null when nothing.</summary>
|
||||
public static SyncAction? DownloadStep(SelectedSequence selected, SyncRights rights)
|
||||
{
|
||||
if (selected.Sync is not { } entry) return null;
|
||||
var actions = SyncText.Actions(entry, rights);
|
||||
return actions.Contains(SyncAction.DownloadOriginals) ? SyncAction.DownloadOriginals : actions.Contains(SyncAction.GetExports) ? SyncAction.GetExports : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The card's Sync quick action: the first transfer or settings exchange the sync table offers, or Resolve
|
||||
/// (on the Server screen) for a conflict; null with <paramref name="blocker"/> when there is nothing to do.
|
||||
/// </summary>
|
||||
public static SyncAction? QuickSync(SelectedSequence selected, SelectionContext context, out string? blocker)
|
||||
{
|
||||
blocker = null;
|
||||
if (!context.IsSignedIn)
|
||||
{
|
||||
blocker = Loc.L("Library.Blocked.NotConnected");
|
||||
return null;
|
||||
}
|
||||
if (selected.Sync is not { } entry) return UploadStep(selected, context.Rights) ?? Blocked(Loc.L("Library.Blocked.NoUploadRight"), out blocker);
|
||||
if (entry.Transfer is not null) return Blocked(Loc.L("Library.Blocked.Transferring"), out blocker);
|
||||
if (entry.Status == SyncStatus.Conflict) return SyncAction.KeepMine;
|
||||
var actions = SyncText.Actions(entry, context.Rights);
|
||||
SyncAction[] preferred = [SyncAction.Upload, SyncAction.DownloadOriginals, SyncAction.SyncSettings, SyncAction.SendExports, SyncAction.GetExports];
|
||||
foreach (var action in preferred)
|
||||
{
|
||||
if (actions.Contains(action)) return action;
|
||||
}
|
||||
return Blocked(Loc.L(entry.Status == SyncStatus.InSync ? "Library.Blocked.InSync" : "Library.Blocked.NoSyncRight"), out blocker);
|
||||
|
||||
static SyncAction? Blocked(string reason, out string? why)
|
||||
{
|
||||
why = reason;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Sync;
|
||||
using Titano.Protocol;
|
||||
|
||||
namespace Titano.App.Library;
|
||||
|
||||
/// <summary>
|
||||
/// Server sequences without a copy on this PC, as Library cards (BRIEF §4.4 mixed mode): from the sync table of the
|
||||
/// signed-in server, with the details of the server's listing when it was read, else what the table keeps.
|
||||
/// </summary>
|
||||
public static class RemoteCards
|
||||
{
|
||||
/// <summary>Entries of the sync table that have no local copy (only on the server, or kept here as proxies).</summary>
|
||||
public static IEnumerable<SyncEntry> RemoteOnly(IEnumerable<SyncEntry> entries) => entries.Where(e => e is { Local: null, Link: not null });
|
||||
|
||||
/// <summary>One card per remote-only entry: the listing's sequence when known, else the table's title, counts and status.</summary>
|
||||
public static IReadOnlyList<Sequence> Build(IEnumerable<SyncEntry> entries, IReadOnlyDictionary<Guid, SequenceDto>? listing) =>
|
||||
[
|
||||
.. RemoteOnly(entries).Select(e => listing is not null && listing.TryGetValue(e.Link!.RemoteId, out var dto) ? ToSequence(dto) : FromLink(e.Link!)),
|
||||
];
|
||||
|
||||
/// <summary>A server sequence as a card: origin server, remote only, no archive on this PC.</summary>
|
||||
public static Sequence ToSequence(SequenceDto dto) => new()
|
||||
{
|
||||
Id = dto.Id,
|
||||
ArchiveId = Guid.Empty,
|
||||
Title = dto.Title,
|
||||
Folder = dto.Folder,
|
||||
CameraMake = dto.CameraMake,
|
||||
CameraModel = dto.CameraModel,
|
||||
Lens = dto.Lens,
|
||||
FirstCapture = dto.FirstCapture,
|
||||
LastCapture = dto.LastCapture,
|
||||
FrameCount = dto.FrameCount,
|
||||
MedianInterval = dto.MedianInterval,
|
||||
TotalBytes = dto.TotalBytes,
|
||||
Status = (SequenceStatus)dto.Status,
|
||||
RenderedCount = dto.RenderedCount,
|
||||
HeroFrameId = dto.HeroFrameId,
|
||||
Tags = dto.Tags,
|
||||
Rating = dto.Rating,
|
||||
Notes = dto.Notes,
|
||||
SettingsVersion = dto.SettingsVersion,
|
||||
FramesVersion = dto.FramesVersion,
|
||||
WarningCount = dto.WarningCount,
|
||||
OwnerUserId = dto.OwnerUserId,
|
||||
UpdatedAt = dto.UpdatedAt,
|
||||
Origin = SequenceOrigin.Server,
|
||||
SyncState = SyncState.RemoteOnly,
|
||||
};
|
||||
|
||||
/// <summary>What the sync table knows of a server sequence when its listing could not be read.</summary>
|
||||
public static Sequence FromLink(SyncLink link) => new()
|
||||
{
|
||||
Id = link.RemoteId,
|
||||
ArchiveId = Guid.Empty,
|
||||
Title = link.Title,
|
||||
Folder = string.Empty,
|
||||
FrameCount = link.FrameCount,
|
||||
TotalBytes = link.TotalBytes,
|
||||
Status = link.RemoteStatus,
|
||||
RenderedCount = link.RenderCount,
|
||||
SettingsVersion = link.RemoteSettingsVersion,
|
||||
FramesVersion = link.RemoteFramesVersion,
|
||||
UpdatedAt = link.RemoteUpdatedAt,
|
||||
Origin = SequenceOrigin.Server,
|
||||
SyncState = SyncState.RemoteOnly,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interleaves remote cards with the index's pages in the order of the filter's sort: each page brings the remote
|
||||
/// cards that sort before its last row; the last page brings the rest. Not thread-safe: call from one thread (the UI).
|
||||
/// </summary>
|
||||
public sealed class RemoteMerge
|
||||
{
|
||||
private readonly List<Sequence> _pending = [];
|
||||
private LibraryFilter _filter = new();
|
||||
|
||||
/// <summary>Remote cards not yet handed out.</summary>
|
||||
public int Pending => _pending.Count;
|
||||
|
||||
/// <summary>Starts over with the cards that match <paramref name="filter"/>, in its order.</summary>
|
||||
public void Reset(LibraryFilter filter, IEnumerable<Sequence> remote)
|
||||
{
|
||||
_filter = filter;
|
||||
_pending.Clear();
|
||||
if (filter.Origin != OriginFilter.Local) _pending.AddRange(remote.Where(filter.Matches));
|
||||
_pending.Sort(filter.Compare);
|
||||
}
|
||||
|
||||
/// <summary>A page of the index with the remote cards that belong among it, in order; <paramref name="last"/> adds every card left.</summary>
|
||||
public IReadOnlyList<Sequence> Merge(IReadOnlyList<Sequence> page, bool last)
|
||||
{
|
||||
var take = last ? _pending.Count
|
||||
: page.Count == 0 ? 0
|
||||
: _pending.FindIndex(r => _filter.Compare(r, page[^1]) > 0) is var after and >= 0 ? after : _pending.Count;
|
||||
if (take == 0) return page;
|
||||
var merged = new List<Sequence>(page.Count + take);
|
||||
int a = 0, b = 0;
|
||||
while (a < page.Count || b < take)
|
||||
{
|
||||
if (b >= take || (a < page.Count && _filter.Compare(page[a], _pending[b]) <= 0)) merged.Add(page[a++]);
|
||||
else merged.Add(_pending[b++]);
|
||||
}
|
||||
_pending.RemoveRange(0, take);
|
||||
return merged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO;
|
||||
using System.Windows.Media;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Data.Sync;
|
||||
using Titano.Ui.Visuals;
|
||||
|
||||
namespace Titano.App.Library;
|
||||
|
||||
/// <summary>Hero thumbnails (and hover-scrub frames, where there are any) of the Library's cards.</summary>
|
||||
public interface ISequenceThumbnails
|
||||
{
|
||||
Task<ImageSource?> HeroAsync(Sequence sequence, int pixelWidth, CancellationToken ct);
|
||||
|
||||
/// <summary>Frames for hover scrubbing; null when the sequence has none to scrub.</summary>
|
||||
IThumbnailSource? ScrubSource(Sequence sequence);
|
||||
}
|
||||
|
||||
/// <summary>The signed-in server as remote cards see it: its sync engine, its key and a connection.</summary>
|
||||
public sealed record RemoteSource(SyncService Service, string Server, ISyncRemote Remote);
|
||||
|
||||
/// <summary>
|
||||
/// Thumbnails of server sequences without a copy here (BRIEF §4.4): the hero frame (else the first) from the proxy
|
||||
/// cache when the sequence was fetched with proxies, otherwise the server's thumbnail of that frame through the API.
|
||||
/// Decoded at a 64 px width step and kept in an LRU cache; failed downloads are not cached, so they are tried again.
|
||||
/// </summary>
|
||||
public sealed class RemoteThumbnails(Func<RemoteSource?> source, int capacity = 256) : ISequenceThumbnails, IDisposable
|
||||
{
|
||||
private const int WidthStep = 64;
|
||||
|
||||
private readonly ConcurrentDictionary<Guid, Guid?> _heroes = new();
|
||||
private ThumbnailCache<(Guid Sequence, int Width), ImageSource>? _cache;
|
||||
|
||||
private ThumbnailCache<(Guid Sequence, int Width), ImageSource> Cache => _cache ??= new(capacity, LoadAsync, maxConcurrentLoads: 4);
|
||||
|
||||
public Task<ImageSource?> HeroAsync(Sequence sequence, int pixelWidth, CancellationToken ct)
|
||||
{
|
||||
_heroes[sequence.Id] = sequence.HeroFrameId;
|
||||
return Cache.GetAsync((sequence.Id, Math.Clamp((pixelWidth + WidthStep - 1) / WidthStep * WidthStep, WidthStep, 1024)), ct);
|
||||
}
|
||||
|
||||
/// <summary>Remote cards do not scrub: every frame would be a download.</summary>
|
||||
public IThumbnailSource? ScrubSource(Sequence sequence) => null;
|
||||
|
||||
/// <summary>Forgets every thumbnail (another server, or the cache was cleared).</summary>
|
||||
public void Clear() => _cache?.Clear();
|
||||
|
||||
public void Dispose() => _cache?.Dispose();
|
||||
|
||||
private async Task<ImageSource?> LoadAsync((Guid Sequence, int Width) key, CancellationToken ct)
|
||||
{
|
||||
if (source() is not { } connection) return null;
|
||||
var hero = _heroes.GetValueOrDefault(key.Sequence);
|
||||
if (connection.Service.OpenRemote(connection.Server, key.Sequence) is { CachedCount: > 0 } cached)
|
||||
{
|
||||
var index = hero is { } id ? IndexOf(cached.Frames, id) : -1;
|
||||
if (index < 0 || cached.Files[index] is null) index = FirstCached(cached.Files);
|
||||
await using var file = new FileStream(cached.Files[index]!, FileMode.Open, FileAccess.Read, FileShare.Read, 1 << 16, FileOptions.Asynchronous);
|
||||
return ThumbnailService.DecodeStream(file, cached.Frames[index].Orientation, key.Width);
|
||||
}
|
||||
var frameId = hero ?? (await connection.Remote.GetManifestAsync(key.Sequence, ct).ConfigureAwait(false)).Frames.FirstOrDefault()?.Id;
|
||||
if (frameId is null) return null;
|
||||
using var thumbnail = new MemoryStream();
|
||||
await connection.Remote.DownloadFrameAsync(frameId.Value, "thumb", thumbnail, ct).ConfigureAwait(false);
|
||||
thumbnail.Position = 0;
|
||||
// The server draws its thumbnails upright.
|
||||
return ThumbnailService.DecodeStream(thumbnail, 1, key.Width);
|
||||
}
|
||||
|
||||
private static int IndexOf(IReadOnlyList<Frame> frames, Guid id)
|
||||
{
|
||||
for (var i = 0; i < frames.Count; i++)
|
||||
{
|
||||
if (frames[i].Id == id) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static int FirstCached(IReadOnlyList<string?> files)
|
||||
{
|
||||
for (var i = 0; i < files.Count; i++)
|
||||
{
|
||||
if (files[i] is not null) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Data.Repositories;
|
||||
|
||||
namespace Titano.App.Library;
|
||||
|
||||
/// <summary>A named set of Library filters and sort ("Night, 4K, not analysed"), BRIEF §12.2.</summary>
|
||||
public sealed record SavedView
|
||||
{
|
||||
public const int MaxName = 40;
|
||||
|
||||
public required Guid Id { get; init; }
|
||||
public required string Name { get; init; }
|
||||
public string? Text { get; init; }
|
||||
public int? Year { get; init; }
|
||||
public string? Camera { get; init; }
|
||||
public StatusFilter Status { get; init; }
|
||||
public string? Tag { get; init; }
|
||||
public OriginFilter Origin { get; init; }
|
||||
public SequenceSort Sort { get; init; } = SequenceSort.Newest;
|
||||
|
||||
public static SavedView Of(Guid id, string name, LibraryFilter filter) => new()
|
||||
{
|
||||
Id = id,
|
||||
Name = name.Trim(),
|
||||
Text = string.IsNullOrWhiteSpace(filter.Text) ? null : filter.Text.Trim(),
|
||||
Year = filter.Year,
|
||||
Camera = filter.Camera,
|
||||
Status = filter.Status,
|
||||
Tag = filter.Tag,
|
||||
Origin = filter.Origin,
|
||||
Sort = filter.Sort,
|
||||
};
|
||||
|
||||
public LibraryFilter ToFilter() => new() { Text = Text, Year = Year, Camera = Camera, Status = Status, Tag = Tag, Origin = Origin, Sort = Sort };
|
||||
|
||||
/// <summary>The Library shows exactly this view (search text compared trimmed and case-insensitively).</summary>
|
||||
public bool Matches(LibraryFilter filter) =>
|
||||
string.Equals(Text ?? string.Empty, filter.Text?.Trim() ?? string.Empty, StringComparison.OrdinalIgnoreCase)
|
||||
&& Year == filter.Year && Camera == filter.Camera && Status == filter.Status && Tag == filter.Tag && Origin == filter.Origin && Sort == filter.Sort;
|
||||
|
||||
/// <summary>The problem of a view name, localized; null when it can be used.</summary>
|
||||
/// <param name="others">Names of the other saved views (a name is used once).</param>
|
||||
public static string? Validate(string? name, IEnumerable<string> others)
|
||||
{
|
||||
var trimmed = name?.Trim() ?? string.Empty;
|
||||
if (trimmed.Length == 0) return Loc.L("Library.Views.Error.Empty");
|
||||
if (trimmed.Length > MaxName || trimmed.Any(char.IsControl)) return Loc.L("Library.Views.Error.Long", MaxName);
|
||||
return others.Contains(trimmed, StringComparer.CurrentCultureIgnoreCase) ? Loc.L("Library.Views.Error.Taken") : null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Saved views as app-scope settings rows (<c>library.view.<id></c>), one row per view.</summary>
|
||||
public sealed class SavedViewStore(SettingsRepository settings)
|
||||
{
|
||||
private const string Prefix = "library.view.";
|
||||
|
||||
/// <summary>Every saved view by name; unreadable rows are skipped.</summary>
|
||||
public async Task<IReadOnlyList<SavedView>> ListAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var views = new List<SavedView>();
|
||||
foreach (var (key, json) in await settings.ListAsync(SettingScope.App, null, cancellationToken))
|
||||
{
|
||||
if (!key.StartsWith(Prefix, StringComparison.Ordinal)) continue;
|
||||
try
|
||||
{
|
||||
if (JsonSerializer.Deserialize(json, SavedViewJson.Default.SavedView) is { } view) views.Add(view);
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
Log.Warning("library", $"Saved view {key} is unreadable", ex);
|
||||
}
|
||||
}
|
||||
return [.. views.OrderBy(v => v.Name, StringComparer.CurrentCultureIgnoreCase)];
|
||||
}
|
||||
|
||||
/// <summary>Adds the view or replaces the one with its id.</summary>
|
||||
public Task SaveAsync(SavedView view, CancellationToken cancellationToken = default) =>
|
||||
settings.SetAsync(SettingScope.App, null, Key(view.Id), view, SavedViewJson.Default.SavedView, cancellationToken);
|
||||
|
||||
public Task<bool> DeleteAsync(Guid id, CancellationToken cancellationToken = default) => settings.DeleteAsync(SettingScope.App, null, Key(id), cancellationToken);
|
||||
|
||||
private static string Key(Guid id) => Prefix + id.ToString("N");
|
||||
}
|
||||
|
||||
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
UseStringEnumConverter = true)]
|
||||
[JsonSerializable(typeof(SavedView))]
|
||||
internal sealed partial class SavedViewJson : JsonSerializerContext;
|
||||
@@ -1,20 +1,29 @@
|
||||
using System.Text.Json;
|
||||
using System.Windows.Media;
|
||||
using Titano.App.Infrastructure;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Export;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Naming;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Data.Processing;
|
||||
using Titano.Data.Sync;
|
||||
using Titano.Ui.Controls;
|
||||
using Titano.Ui.Mvvm;
|
||||
using Titano.Ui.Visuals;
|
||||
|
||||
namespace Titano.App.Library;
|
||||
|
||||
/// <summary>One sequence of the Library grid and list (BRIEF §12.2).</summary>
|
||||
/// <summary>One sequence of the Library grid and list (BRIEF §12.2): on this PC, or a server sequence without a copy here (a remote card).</summary>
|
||||
public sealed class SequenceItem : ObservableObject
|
||||
{
|
||||
private readonly ThumbnailService? _thumbnails;
|
||||
private readonly ISequenceThumbnails? _thumbnails;
|
||||
private Sequence _sequence;
|
||||
private SyncEntry? _sync;
|
||||
private string? _syncToolTip;
|
||||
private bool _canSync;
|
||||
private string? _presetName;
|
||||
private ImageSource? _thumbnail;
|
||||
private IThumbnailSource? _scrub;
|
||||
private CancellationTokenSource? _loading;
|
||||
@@ -22,7 +31,7 @@ public sealed class SequenceItem : ObservableObject
|
||||
private bool _isSelected;
|
||||
private bool _isAnalysing;
|
||||
|
||||
public SequenceItem(Sequence sequence, ThumbnailService? thumbnails)
|
||||
public SequenceItem(Sequence sequence, ISequenceThumbnails? thumbnails)
|
||||
{
|
||||
_sequence = sequence;
|
||||
_thumbnails = thumbnails;
|
||||
@@ -31,6 +40,23 @@ public sealed class SequenceItem : ObservableObject
|
||||
public Sequence Sequence => _sequence;
|
||||
public Guid Id => _sequence.Id;
|
||||
|
||||
/// <summary>Only on the signed-in server (the editor opens it with proxies; archive actions do not apply).</summary>
|
||||
public bool IsRemote => _sequence is { Origin: SequenceOrigin.Server, SyncState: SyncState.RemoteOnly };
|
||||
|
||||
/// <summary>Its row of the sync table of the signed-in server; null while signed out or not compared yet.</summary>
|
||||
public SyncEntry? Sync => _sync;
|
||||
|
||||
/// <summary>The Sync quick action can run (<see cref="SyncToolTip"/> says what it does, or why not).</summary>
|
||||
public bool CanSync => _canSync;
|
||||
|
||||
public string SyncToolTip => _syncToolTip ?? Loc.L("Library.Blocked.NotConnected");
|
||||
|
||||
/// <summary>"Render · 4K archive": the preset the Render quick action queues, the recommended one or the default.</summary>
|
||||
public string RenderToolTip => Loc.L(IsRemote ? "Tooltips.Library.QuickRenderServer" : "Tooltips.Library.QuickRender", PresetName);
|
||||
|
||||
/// <summary>The export preset of the sequence's project (the advisor's choice when it made one, else the default).</summary>
|
||||
public string PresetName => _presetName ??= ResolvePreset(_sequence.SettingsJson);
|
||||
|
||||
/// <summary>User title or "{date} {camera}".</summary>
|
||||
public string Title => _sequence.DisplayTitle;
|
||||
|
||||
@@ -70,6 +96,17 @@ public sealed class SequenceItem : ObservableObject
|
||||
/// <summary>Frames for hover scrubbing; created on first use.</summary>
|
||||
public IThumbnailSource? ScrubSource => _thumbnails is null || _sequence.FrameCount == 0 ? null : _scrub ??= _thumbnails.ScrubSource(_sequence);
|
||||
|
||||
/// <summary>The sync table's row of this sequence and what its Sync quick action does (or why it cannot).</summary>
|
||||
public void SetSync(SyncEntry? entry, bool canSync, string toolTip)
|
||||
{
|
||||
_sync = entry;
|
||||
_canSync = canSync;
|
||||
_syncToolTip = toolTip;
|
||||
OnPropertyChanged(nameof(Sync));
|
||||
OnPropertyChanged(nameof(CanSync));
|
||||
OnPropertyChanged(nameof(SyncToolTip));
|
||||
}
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get => _isSelected;
|
||||
@@ -90,6 +127,7 @@ public sealed class SequenceItem : ObservableObject
|
||||
public void Update(Sequence sequence)
|
||||
{
|
||||
var heroChanged = sequence.HeroFrameId != _sequence.HeroFrameId || sequence.FrameCount != _sequence.FrameCount;
|
||||
if (sequence.SettingsJson != _sequence.SettingsJson) _presetName = null;
|
||||
_sequence = sequence;
|
||||
if (heroChanged)
|
||||
{
|
||||
@@ -141,6 +179,19 @@ public sealed class SequenceItem : ObservableObject
|
||||
}
|
||||
}
|
||||
|
||||
private static string ResolvePreset(string? settingsJson)
|
||||
{
|
||||
try
|
||||
{
|
||||
var project = settingsJson is null ? new ProjectSettings() : ProjectSettings.FromJson(settingsJson);
|
||||
return ProcessingJobs.PresetName(ExportResolver.Resolve(project.Export));
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return ProcessingJobs.PresetName(ExportResolver.Resolve(new ExportSettings()));
|
||||
}
|
||||
}
|
||||
|
||||
private void RaiseStatuses()
|
||||
{
|
||||
OnPropertyChanged(nameof(Statuses));
|
||||
|
||||
@@ -17,7 +17,7 @@ public readonly record struct ThumbnailKey(Guid FrameId, int Width);
|
||||
/// original and decoded by WIC at the requested width (falling back to decoding the original), turned upright,
|
||||
/// frozen and kept in an LRU cache. Loads run off the UI thread and stop when the card scrolls away.
|
||||
/// </summary>
|
||||
public sealed class ThumbnailService : IDisposable
|
||||
public sealed class ThumbnailService : ISequenceThumbnails, IDisposable
|
||||
{
|
||||
/// <summary>Embedded previews larger than this are not read (a damaged index would make us read gigabytes).</summary>
|
||||
private const long MaxPreviewBytes = 64L << 20;
|
||||
@@ -81,6 +81,8 @@ public sealed class ThumbnailService : IDisposable
|
||||
/// <summary>Hover-scrub frames of a sequence, sampled to at most <paramref name="positions"/> positions.</summary>
|
||||
public IThumbnailSource ScrubSource(Sequence sequence, int positions = 120) => new ScrubFrames(this, sequence, positions);
|
||||
|
||||
IThumbnailSource? ISequenceThumbnails.ScrubSource(Sequence sequence) => ScrubSource(sequence);
|
||||
|
||||
/// <summary>Drops decoded thumbnails (Settings › Storage › Clear).</summary>
|
||||
public void Clear()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using System.Windows.Input;
|
||||
using Titano.App.Archiving;
|
||||
using Titano.App.Settings;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Ui.Mvvm;
|
||||
|
||||
namespace Titano.App.Library;
|
||||
|
||||
/// <summary>Names a saved view: "Save view" (the current filters under a new name) or "Rename view".</summary>
|
||||
public sealed class ViewNameDialogViewModel : ArchiveDialogViewModel
|
||||
{
|
||||
private readonly Func<string, Task> _save;
|
||||
|
||||
/// <param name="others">Names of the other saved views (each name is used once).</param>
|
||||
public ViewNameDialogViewModel(bool rename, string name, IReadOnlyList<string> others, Func<string, Task> save, Action<ArchiveDialogViewModel> close)
|
||||
: base(close)
|
||||
{
|
||||
IsRename = rename;
|
||||
_save = save;
|
||||
Name = new EditableField(name, n => SavedView.Validate(n, others), _ => { }, () => Loc.L("Tooltips.Library.ViewName"));
|
||||
Name.PropertyChanged += (_, _) =>
|
||||
{
|
||||
OnPropertyChanged(nameof(SaveToolTip));
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
};
|
||||
SaveCommand = new AsyncRelayCommand(SaveAsync, () => !IsBusy && !Name.HasErrors);
|
||||
}
|
||||
|
||||
public bool IsRename { get; }
|
||||
|
||||
public string Heading => Loc.L(IsRename ? "Library.Views.RenameHeading" : "Library.Views.SaveHeading");
|
||||
|
||||
public EditableField Name { get; }
|
||||
|
||||
public ICommand SaveCommand { get; }
|
||||
|
||||
public string SaveToolTip => Name.Error ?? Loc.L(IsRename ? "Tooltips.Library.ViewRenameApply" : "Tooltips.Library.ViewSaveApply");
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
IsBusy = true;
|
||||
try
|
||||
{
|
||||
await _save(Name.Text.Trim());
|
||||
Close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
IsBusy = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user