diff --git a/src/Titano.App/Archive/DeleteDialogViewModel.cs b/src/Titano.App/Archive/DeleteDialogViewModel.cs
new file mode 100644
index 00000000..8d0d1825
--- /dev/null
+++ b/src/Titano.App/Archive/DeleteDialogViewModel.cs
@@ -0,0 +1,174 @@
+using System.IO;
+using Titano.App.Infrastructure;
+using Titano.App.Shell;
+using Titano.Core.Archiving;
+using Titano.Core.Diagnostics;
+using Titano.Core.Localization;
+using Titano.Data;
+using Titano.Data.Archiving;
+using Titano.Ui.Mvvm;
+
+namespace Titano.App.Archiving;
+
+///
+/// "Delete…" of the Library and the Archive manager (BRIEF §0.2 rule 8, §12.2, §12.5) in an in-window dialog that says
+/// how far it is and stops on Cancel: the archive engine's dry run, sequence by sequence; the destructive confirmation
+/// that asks to type the number of sequences (DESIGN §4); then the move into the archives' trash, each sequence whole
+/// or not at all. The toast that follows names what moved and brings it back.
+///
+public sealed class DeleteDialogViewModel : ArchiveDialogViewModel
+{
+ private readonly ShellViewModel _shell;
+ private readonly IReadOnlyList _ids;
+ private CancellationTokenSource? _run;
+ private double _progress;
+
+ public DeleteDialogViewModel(ShellViewModel shell, IReadOnlyList sequenceIds, Action close)
+ : base(close)
+ {
+ _shell = shell;
+ _ids = sequenceIds;
+ }
+
+ /// "Deleting 3 sequences".
+ public string Heading => Loc.Plural("Archive.Delete.Progress", _ids.Count);
+
+ /// 0–1 of the dry run, then of the move.
+ public double Progress { get => _progress; private set => Set(ref _progress, value); }
+
+ protected override bool CanStop => _run is not null;
+
+ /// Stops the dry run, or the move after the sequence that is moving.
+ protected override void Stop() => _run?.Cancel();
+
+ public override void Dispose()
+ {
+ _run?.Cancel();
+ base.Dispose();
+ }
+
+ /// Plans, asks, deletes and offers to undo, then closes; true when something moved to the trash.
+ public async Task RunAsync()
+ {
+ using var run = _run = new CancellationTokenSource();
+ IsBusy = true;
+ try
+ {
+ if (_shell.Services.Archives is not { } archives || _ids.Count == 0) return false;
+ if (await PlanAsync(archives, run.Token) is not { } plan) return false;
+ if (DeletePlans.Request(plan) is not { } request)
+ {
+ _shell.Notify(Loc.L("Archive.Delete.Nothing"), string.Join(Environment.NewLine, DeletePlans.Blocked(plan, DeletePlans.BlockedLines)));
+ return false;
+ }
+ BusyText = null;
+ if (!_shell.Services.Dialogs.Confirm(request) || !await SequenceDeletion.CloseEditorAsync(_shell, plan)) return false;
+ return await DeleteAsync(archives, plan, run.Token);
+ }
+ finally
+ {
+ _run = null;
+ IsBusy = false;
+ Close();
+ }
+ }
+
+ /// The dry run; null when it was stopped or failed (said in a toast).
+ private async Task PlanAsync(ArchiveService archives, CancellationToken cancellationToken)
+ {
+ var checking = new Progress(n => Report("Archive.Delete.Checking", n, _ids.Count));
+ try
+ {
+ return await Task.Run(() => archives.PlanDeleteAsync(_ids, checking, cancellationToken), cancellationToken);
+ }
+ catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
+ {
+ return null;
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException or DatabaseException)
+ {
+ Log.Warning("archive", "Delete dry run failed", ex);
+ _shell.Notify(Loc.L("Archive.Delete.Failed"), ex.Message);
+ return null;
+ }
+ }
+
+ ///
+ /// Moves the planned sequences; whatever moved before a stop or a failure is read back from the trash, so the toast
+ /// names it and offers to bring it back.
+ ///
+ private async Task DeleteAsync(ArchiveService archives, DeletePlan plan, CancellationToken cancellationToken)
+ {
+ var started = DateTimeOffset.UtcNow;
+ var moving = new Progress(n => Report("Archive.Delete.Moving", n, plan.Steps.Count));
+ Report("Archive.Delete.Moving", 0, plan.Steps.Count);
+ Exception? failure = null;
+ try
+ {
+ await Task.Run(() => archives.DeleteAsync(plan, Environment.UserName, moving, cancellationToken), cancellationToken);
+ }
+ catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
+ {
+ Log.Info("archive", "Delete stopped between two sequences");
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or StaleDeletePlanException or NewerFormatException
+ or ArgumentException or DatabaseException)
+ {
+ Log.Warning("archive", "Delete failed", ex);
+ failure = ex;
+ }
+
+ var moved = await MovedAsync(archives, plan, started);
+ var removed = await RemovedRowsAsync(plan);
+ Log.Info("archive", $"{moved.Count} sequence(s) moved to the trash, {removed} without a folder removed from the index");
+ await SequenceDeletion.RefreshAsync(_shell);
+ var undo = moved.Count == 0 ? null : new AsyncRelayCommand(() => SequenceDeletion.RestoreAsync(_shell, moved));
+ if (failure is not null)
+ _shell.Notify(Loc.L("Archive.Delete.Failed"), failure.Message, undo is null ? null : Loc.L("Archive.Delete.Undo"), Loc.L("Tooltips.Archive.DeleteUndo"),
+ undo is null ? null : () => undo.Execute(null));
+ else if (moved.Count > 0)
+ _shell.Notify(Loc.Plural("Archive.Delete.Done", moved.Count), Loc.L("Archive.Delete.Kept"), Loc.L("Archive.Delete.Undo"),
+ Loc.L("Tooltips.Archive.DeleteUndo"), () => undo!.Execute(null));
+ else if (removed > 0)
+ _shell.Notify(Loc.Plural("Archive.Delete.Removed", removed));
+ return moved.Count + removed > 0;
+ }
+
+ /// The trash entries this run made: the planned sequences that entered their archive's trash since it started.
+ private static async Task> MovedAsync(ArchiveService archives, DeletePlan plan, DateTimeOffset started)
+ {
+ var planned = plan.Steps.Where(s => s.TrashFolder is not null).Select(s => s.Sequence.Id).ToHashSet();
+ var moved = new List();
+ foreach (var archive in plan.Steps.Where(s => s.TrashFolder is not null).Select(s => s.Sequence.ArchiveId).Distinct())
+ {
+ try
+ {
+ var entries = await Task.Run(() => archives.ListTrashAsync(archive));
+ moved.AddRange(entries.Where(e => planned.Contains(e.SequenceId) && e.DeletedAt >= started));
+ }
+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or ArgumentException or DatabaseException)
+ {
+ Log.Warning("archive", "The trash could not be read after a delete", ex);
+ }
+ }
+ return moved;
+ }
+
+ /// Planned sequences without a folder (nothing to keep in a trash) whose rows are gone.
+ private async Task RemovedRowsAsync(DeletePlan plan)
+ {
+ if (_shell.Services.Database is not { } db) return 0;
+ var removed = 0;
+ foreach (var step in plan.Steps.Where(s => s.TrashFolder is null))
+ {
+ if (await db.Sequences.GetAsync(step.Sequence.Id) is null) removed++;
+ }
+ return removed;
+ }
+
+ private void Report(string key, int done, int total)
+ {
+ BusyText = Loc.L(key, Formatting.Count(done), Formatting.Count(total));
+ Progress = total == 0 ? 0 : (double)done / total;
+ }
+}
diff --git a/src/Titano.App/Archive/DeletePlans.cs b/src/Titano.App/Archive/DeletePlans.cs
index 115d6513..9b747c18 100644
--- a/src/Titano.App/Archive/DeletePlans.cs
+++ b/src/Titano.App/Archive/DeletePlans.cs
@@ -8,8 +8,11 @@ namespace Titano.App.Archiving;
/// The words of a delete dry run (): the destructive confirmation and the lines of what cannot move.
public static class DeletePlans
{
- /// Sequences named one by one in the confirmation; the rest are counted.
- public const int ListedLines = 8;
+ /// Sequences that move, named one by one in the confirmation; the rest are counted.
+ public const int ListedLines = 6;
+
+ /// Sequences that cannot move, named one by one; the rest are counted. With it keeps the confirmation within a 768 px screen.
+ public const int BlockedLines = 3;
/// The destructive confirmation of a plan; null when nothing in it can move.
public static ConfirmRequest? Request(DeletePlan plan)
@@ -19,7 +22,7 @@ public static class DeletePlans
var lines = plan.Steps.Take(ListedLines).Select(s => Loc.L("Archive.Delete.Line", s.Sequence.DisplayTitle,
Loc.Plural("Shell.Status.Photos", s.Sequence.FrameCount), Formatting.Bytes(s.Bytes))).ToList();
if (plan.Steps.Count > ListedLines) lines.Add(Loc.Plural("Archive.Delete.More", plan.Steps.Count - ListedLines));
- lines.AddRange(Blocked(plan, ListedLines));
+ lines.AddRange(Blocked(plan, BlockedLines));
return new ConfirmRequest
{
Heading = Loc.Plural("Archive.Delete.Heading", plan.Steps.Count),
diff --git a/src/Titano.App/Archive/MassOperations.cs b/src/Titano.App/Archive/MassOperations.cs
index 6a6564af..f0b53e75 100644
--- a/src/Titano.App/Archive/MassOperations.cs
+++ b/src/Titano.App/Archive/MassOperations.cs
@@ -94,8 +94,7 @@ public sealed record ArchiveSetFilter(string? Camera = null, StatusFilter Status
{
if (Camera is not null && CameraOf(sequence) != Camera) return false;
if (Tag is not null && !sequence.Tags.Contains(Tag, StringComparer.OrdinalIgnoreCase)) return false;
- var (with, without) = LibraryFilter.Flags(Status);
- return (sequence.Status & with) == with && (sequence.Status & without) == 0;
+ return LibraryFilter.MatchesStatus(sequence, Status);
}
/// "Canon EOS R5 · Not analysed · sunset"; empty without a filter.
diff --git a/src/Titano.App/Archive/SequenceDeletion.cs b/src/Titano.App/Archive/SequenceDeletion.cs
index 695b1980..3d96da96 100644
--- a/src/Titano.App/Archive/SequenceDeletion.cs
+++ b/src/Titano.App/Archive/SequenceDeletion.cs
@@ -1,7 +1,5 @@
using System.IO;
-using Titano.App.Infrastructure;
using Titano.App.Shell;
-using Titano.Core.Archiving;
using Titano.Core.Diagnostics;
using Titano.Core.Localization;
using Titano.Data;
@@ -9,44 +7,9 @@ using Titano.Data.Archiving;
namespace Titano.App.Archiving;
-///
-/// "Delete" of the Library and the Archive manager (BRIEF §0.2 rule 8, §12.2, §12.5): the archive engine's dry run is
-/// shown in a destructive confirmation that asks to type the number of sequences (DESIGN §4), then the sequences move to
-/// their archive's trash; the toast that follows brings them back.
-///
+/// What Delete () and its Undo share in the Library and the Archive manager.
public static class SequenceDeletion
{
- /// Plans, asks, deletes and offers to undo; true when something moved to the trash.
- public static async Task RunAsync(ShellViewModel shell, IReadOnlyList sequenceIds)
- {
- if (shell.Services.Archives is not { } archives || sequenceIds.Count == 0) return false;
- try
- {
- var plan = await Task.Run(() => archives.PlanDeleteAsync(sequenceIds));
- if (DeletePlans.Request(plan) is not { } request)
- {
- shell.Notify(Loc.L("Archive.Delete.Nothing"), string.Join(Environment.NewLine, DeletePlans.Blocked(plan, DeletePlans.ListedLines)));
- return false;
- }
- if (!shell.Services.Dialogs.Confirm(request) || !await CloseEditorAsync(shell, plan)) return false;
- var entries = await Task.Run(() => archives.DeleteAsync(plan, Environment.UserName));
- Log.Info("archive", $"{entries.Count} sequence(s) moved to the trash, {plan.Steps.Count - entries.Count} removed from the index only");
- await RefreshAsync(shell);
- shell.Notify(Loc.Plural("Archive.Delete.Done", plan.Steps.Count), Loc.L("Archive.Delete.Kept"),
- entries.Count == 0 ? null : Loc.L("Archive.Delete.Undo"), Loc.L("Tooltips.Archive.DeleteUndo"),
- entries.Count == 0 ? null : () => _ = RestoreAsync(shell, entries));
- return true;
- }
- catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidDataException or StaleDeletePlanException or NewerFormatException
- or ArgumentException or DatabaseException)
- {
- Log.Warning("archive", "Delete failed", ex);
- shell.Notify(Loc.L("Archive.Delete.Failed"), ex.Message);
- await RefreshAsync(shell);
- return false;
- }
- }
-
/// Brings deleted sequences back from their archives' trash and indexes them again.
public static async Task RestoreAsync(ShellViewModel shell, IReadOnlyList entries)
{
@@ -74,7 +37,7 @@ public static class SequenceDeletion
/// The editor of a sequence about to move stores its last edit (so the trash keeps it) and closes; false when that
/// edit could not be stored and the user kept it.
///
- private static async Task CloseEditorAsync(ShellViewModel shell, DeletePlan plan)
+ internal static async Task CloseEditorAsync(ShellViewModel shell, DeletePlan plan)
{
if (shell.Sequence.Editor is null || shell.CurrentSequenceId is not { } open || plan.Steps.All(s => s.Sequence.Id != open)) return true;
if (!await shell.Sequence.ConfirmCloseAsync()) return false;
@@ -82,7 +45,7 @@ public static class SequenceDeletion
return true;
}
- private static async Task RefreshAsync(ShellViewModel shell)
+ internal static async Task RefreshAsync(ShellViewModel shell)
{
await shell.Library.RefreshAsync();
await shell.Archive.LoadAsync();
diff --git a/src/Titano.App/Library/LibraryActions.cs b/src/Titano.App/Library/LibraryActions.cs
index a19e0808..c46d1293 100644
--- a/src/Titano.App/Library/LibraryActions.cs
+++ b/src/Titano.App/Library/LibraryActions.cs
@@ -39,6 +39,9 @@ public sealed class LibraryActions(ShellViewModel shell)
/// What the signed-in account may do; nothing while signed out.
public SyncRights Rights => Services.Server.User is { } user ? SyncRights.Of(user.Permissions) : default;
+ /// A job can be posted to the server now (a remote card's Analyse and Render).
+ public bool CanPost => Services.Server is { IsConnected: true, Flow: { Address: not null, Token: not null } };
+
/// Deep analysis of sequences on this PC (one job), or of a remote card on the server.
public async Task AnalyseAsync(IReadOnlyList sequences)
{
@@ -63,8 +66,9 @@ public sealed class LibraryActions(ShellViewModel shell)
}
///
- /// 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.
+ /// The Render quick action: the sequence's own export with its project as stored — the preset chosen in the editor,
+ /// else the advisor's recommendation the analyses store in the project, else the default — on this PC's engine, or
+ /// posted to the server for a remote card, which renders it where the originals are.
///
public async Task RenderAsync(Sequence sequence)
{
@@ -134,16 +138,20 @@ public sealed class LibraryActions(ShellViewModel shell)
return job.Id;
}
- /// Sets the rating of sequences on this PC (sidecar and index together); returns how many changed.
+ ///
+ /// Sets the rating of sequences on this PC (sidecar and index together), changing nothing else: the title, tags and
+ /// notes are those the sidecar holds then, not the Library's copy. Returns how many changed.
+ ///
public async Task RateAsync(IReadOnlyList sequences, int rating)
{
- if (Services.Archives is not { } archives) return 0;
+ if (Services.Archives is not { } archives || Services.Database is not { } db) return 0;
var changed = 0;
try
{
- foreach (var s in sequences.Where(s => s.Rating != rating))
+ foreach (var s in sequences)
{
- await Task.Run(() => archives.SetSequenceInfoAsync(s.Id, s.Title, s.Tags, rating, s.Notes));
+ if (await db.Sequences.GetAsync(s.Id) is not { } current || current.Rating == rating) continue;
+ await Task.Run(() => archives.EditSequenceInfoAsync(s.Id, info => info with { Rating = rating }));
changed++;
}
}
@@ -174,7 +182,7 @@ public sealed class LibraryActions(ShellViewModel shell)
private async Task PostAsync(Func> build, JobKind kind, string label)
{
var session = Services.Server;
- if (!session.IsConnected || session.Flow is not { Address: { } address, Token: { } token }) return;
+ if (!CanPost || session.Flow is not { Address: { } address, Token: { } token }) return;
try
{
var request = await build();
diff --git a/src/Titano.App/Library/LibraryFacets.cs b/src/Titano.App/Library/LibraryFacets.cs
new file mode 100644
index 00000000..bd3a62bc
--- /dev/null
+++ b/src/Titano.App/Library/LibraryFacets.cs
@@ -0,0 +1,44 @@
+using Titano.Core.Model;
+using Titano.Data.Repositories;
+
+namespace Titano.App.Library;
+
+///
+/// What the Library's Year and Camera choices and its timeline bands count (BRIEF §4.4 mixed mode): the index's
+/// figures, the server's sequences without a copy here, or both, as the origin filter says.
+///
+public static class LibraryFacets
+{
+ ///
+ /// with its years, months and cameras replaced by those of the origins in view: the index's
+ /// own unless only the server's sequences show, plus the remote cards' unless only this PC's show.
+ ///
+ public static ArchiveStats Of(ArchiveStats local, IReadOnlyList remote, OriginFilter origin)
+ {
+ var keepLocal = origin != OriginFilter.Server;
+ var years = keepLocal ? local.ByYear.ToDictionary(y => y.Year) : [];
+ var months = keepLocal ? local.ByMonth.ToDictionary(m => (m.Year, m.Month)) : [];
+ var cameras = keepLocal ? local.ByCamera.ToDictionary(c => (c.Make, c.Model)) : [];
+ foreach (var s in origin == OriginFilter.Local ? [] : remote)
+ {
+ if (s.FirstCapture is { } at)
+ {
+ years[at.Year] = years.TryGetValue(at.Year, out var y)
+ ? y with { Sequences = y.Sequences + 1, Photos = y.Photos + s.FrameCount, Bytes = y.Bytes + s.TotalBytes }
+ : new YearBucket(at.Year, 1, s.FrameCount, s.TotalBytes);
+ months[(at.Year, at.Month)] = months.TryGetValue((at.Year, at.Month), out var m)
+ ? m with { Sequences = m.Sequences + 1, Photos = m.Photos + s.FrameCount }
+ : new MonthBucket(at.Year, at.Month, 1, s.FrameCount);
+ }
+ cameras[(s.CameraMake, s.CameraModel)] = cameras.TryGetValue((s.CameraMake, s.CameraModel), out var c)
+ ? c with { Sequences = c.Sequences + 1, Photos = c.Photos + s.FrameCount, Bytes = c.Bytes + s.TotalBytes }
+ : new CameraBucket(s.CameraMake, s.CameraModel, 1, s.FrameCount, s.TotalBytes);
+ }
+ return local with
+ {
+ ByYear = [.. years.Values.OrderBy(y => y.Year)],
+ ByMonth = [.. months.Values.OrderBy(m => m.Year).ThenBy(m => m.Month)],
+ ByCamera = [.. cameras.Values],
+ };
+ }
+}
diff --git a/src/Titano.App/Library/LibraryFilter.cs b/src/Titano.App/Library/LibraryFilter.cs
index 02076a1f..12391446 100644
--- a/src/Titano.App/Library/LibraryFilter.cs
+++ b/src/Titano.App/Library/LibraryFilter.cs
@@ -3,7 +3,7 @@ using Titano.Data.Repositories;
namespace Titano.App.Library;
-/// Status choices of the Library toolbar; each maps onto status flags the index can filter on.
+/// Status choices of the Library toolbar (Main.html: analysed, proxies, rendered, synced); each is a test the index can run.
public enum StatusFilter
{
Any,
@@ -11,8 +11,11 @@ public enum StatusFilter
NotAnalysed,
Proxies,
NoProxies,
+ Rendered,
+ NotRendered,
Verified,
NotVerified,
+ Synced,
Warnings,
}
@@ -42,6 +45,9 @@ public sealed record LibraryFilter
/// The same sort without filters ("Clear filters").
public LibraryFilter Cleared() => new() { Sort = Sort };
+ /// Sync states a "Synced" sequence is in: the ones whose card wears the ● Synced glyph.
+ public static IReadOnlyCollection SyncedStates { get; } = [SyncState.InSync, SyncState.LocalAhead];
+
/// The repository query for one page.
public SequenceQuery ToQuery(int limit, string? cursor)
{
@@ -54,6 +60,13 @@ public sealed record LibraryFilter
Tag = Tag,
WithStatus = with,
WithoutStatus = without,
+ Rendered = Status switch
+ {
+ StatusFilter.Rendered => true,
+ StatusFilter.NotRendered => false,
+ _ => null,
+ },
+ SyncStates = Status == StatusFilter.Synced ? SyncedStates : null,
Sort = Sort,
Limit = limit,
Cursor = cursor,
@@ -68,8 +81,7 @@ public sealed record LibraryFilter
{
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 (!MatchesStatus(sequence, Status)) 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();
@@ -101,7 +113,24 @@ public sealed record LibraryFilter
};
}
- /// Flags that must be set and clear for a status choice.
+ /// The status test of the index () on one sequence.
+ public static bool MatchesStatus(Sequence sequence, StatusFilter status)
+ {
+ switch (status)
+ {
+ case StatusFilter.Rendered:
+ return sequence.RenderedCount > 0;
+ case StatusFilter.NotRendered:
+ return sequence.RenderedCount == 0;
+ case StatusFilter.Synced:
+ return SyncedStates.Contains(sequence.SyncState);
+ default:
+ var (with, without) = Flags(status);
+ return (sequence.Status & with) == with && (sequence.Status & without) == 0;
+ }
+ }
+
+ /// Flags that must be set and clear for a status choice (none for the choices that test renders or sync).
public static (SequenceStatus With, SequenceStatus Without) Flags(StatusFilter status) => status switch
{
StatusFilter.Analysed => (SequenceStatus.AnalyzedLight, SequenceStatus.None),
diff --git a/src/Titano.App/Library/RemoteThumbnails.cs b/src/Titano.App/Library/RemoteThumbnails.cs
index ce0ea7b8..5c4008b6 100644
--- a/src/Titano.App/Library/RemoteThumbnails.cs
+++ b/src/Titano.App/Library/RemoteThumbnails.cs
@@ -22,13 +22,17 @@ public sealed record RemoteSource(SyncService Service, string Server, ISyncRemot
///
/// 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.
+/// The first frame of a sequence without a hero is asked once (one row of its frames page) and remembered. Decoded at
+/// a 64 px width step and kept in an LRU cache; failed downloads are not cached, so they are tried again.
///
public sealed class RemoteThumbnails(Func source, int capacity = 256) : ISequenceThumbnails, IDisposable
{
private const int WidthStep = 64;
private readonly ConcurrentDictionary _heroes = new();
+
+ /// The first frame of sequences without a hero frame (a sequence with no frame yet is asked again later).
+ private readonly ConcurrentDictionary _firstFrames = new();
private ThumbnailCache<(Guid Sequence, int Width), ImageSource>? _cache;
private ThumbnailCache<(Guid Sequence, int Width), ImageSource> Cache => _cache ??= new(capacity, LoadAsync, maxConcurrentLoads: 4);
@@ -43,7 +47,11 @@ public sealed class RemoteThumbnails(Func source, int capacity =
public IThumbnailSource? ScrubSource(Sequence sequence) => null;
/// Forgets every thumbnail (another server, or the cache was cleared).
- public void Clear() => _cache?.Clear();
+ public void Clear()
+ {
+ _cache?.Clear();
+ _firstFrames.Clear();
+ }
public void Dispose() => _cache?.Dispose();
@@ -58,7 +66,7 @@ public sealed class RemoteThumbnails(Func source, int capacity =
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;
+ var frameId = hero ?? await FirstFrameAsync(connection.Remote, key.Sequence, ct).ConfigureAwait(false);
if (frameId is null) return null;
using var thumbnail = new MemoryStream();
await connection.Remote.DownloadFrameAsync(frameId.Value, "thumb", thumbnail, ct).ConfigureAwait(false);
@@ -67,6 +75,14 @@ public sealed class RemoteThumbnails(Func source, int capacity =
return ThumbnailService.DecodeStream(thumbnail, 1, key.Width);
}
+ private async Task FirstFrameAsync(ISyncRemote remote, Guid sequence, CancellationToken ct)
+ {
+ if (_firstFrames.TryGetValue(sequence, out var known)) return known;
+ if ((await remote.FirstFrameAsync(sequence, ct).ConfigureAwait(false))?.Id is not { } first) return null;
+ _firstFrames[sequence] = first;
+ return first;
+ }
+
private static int IndexOf(IReadOnlyList frames, Guid id)
{
for (var i = 0; i < frames.Count; i++)
diff --git a/src/Titano.App/Library/SequenceItem.cs b/src/Titano.App/Library/SequenceItem.cs
index 62465fdc..8c785c1c 100644
--- a/src/Titano.App/Library/SequenceItem.cs
+++ b/src/Titano.App/Library/SequenceItem.cs
@@ -23,6 +23,7 @@ public sealed class SequenceItem : ObservableObject
private SyncEntry? _sync;
private string? _syncToolTip;
private bool _canSync;
+ private string? _quickBlocker;
private string? _presetName;
private ImageSource? _thumbnail;
private IThumbnailSource? _scrub;
@@ -51,12 +52,27 @@ public sealed class SequenceItem : ObservableObject
public string SyncToolTip => _syncToolTip ?? Loc.L("Library.Blocked.NotConnected");
- /// "Render · 4K archive": the preset the Render quick action queues, the recommended one or the default.
- public string RenderToolTip => Loc.L(IsRemote ? "Tooltips.Library.QuickRenderServer" : "Tooltips.Library.QuickRender", PresetName);
+ /// The Analyse and Render quick actions can start ( says why not).
+ public bool CanRunQuick => _quickBlocker is null;
- /// The export preset of the sequence's project (the advisor's choice when it made one, else the default).
+ /// What Analyse does here or on the server, or why it cannot start.
+ public string AnalyseToolTip => _quickBlocker ?? Loc.L(IsRemote ? "Tooltips.Library.AnalyseServer" : "Tooltips.Library.Analyse");
+
+ ///
+ /// "Queue a render with 4K archive…": the preset the Render quick action queues, or why it cannot start. A remote
+ /// card's project lives on the server, which renders it with the sequence's own preset.
+ ///
+ public string RenderToolTip => _quickBlocker ?? (IsRemote ? Loc.L("Tooltips.Library.QuickRenderServer") : Loc.L("Tooltips.Library.QuickRender", PresetName));
+
+ ///
+ /// The export preset of the sequence's project: the one chosen in the editor, else the advisor's recommendation the
+ /// analyses store in the project (Auto), else the default.
+ ///
public string PresetName => _presetName ??= ResolvePreset(_sequence.SettingsJson);
+ /// How the card reacts to the mouse; remote cards have no frames here to scrub.
+ public string CardToolTip => Loc.L(IsRemote ? "Tooltips.Library.CardRemote" : "Tooltips.Library.Card");
+
/// User title or "{date} {camera}".
public string Title => _sequence.DisplayTitle;
@@ -107,6 +123,16 @@ public sealed class SequenceItem : ObservableObject
OnPropertyChanged(nameof(SyncToolTip));
}
+ /// Why Analyse and Render cannot start now (no engine here, or the server is not connected); null when they can.
+ public void SetQuickBlocker(string? blocker)
+ {
+ if (_quickBlocker == blocker) return;
+ _quickBlocker = blocker;
+ OnPropertyChanged(nameof(CanRunQuick));
+ OnPropertyChanged(nameof(AnalyseToolTip));
+ OnPropertyChanged(nameof(RenderToolTip));
+ }
+
public bool IsSelected
{
get => _isSelected;
diff --git a/src/Titano.Ui/Visuals/TimelineBands.cs b/src/Titano.Ui/Visuals/TimelineBands.cs
index a2e743b9..a7479632 100644
--- a/src/Titano.Ui/Visuals/TimelineBands.cs
+++ b/src/Titano.Ui/Visuals/TimelineBands.cs
@@ -9,8 +9,10 @@ namespace Titano.Ui.Visuals;
/// Library timeline mode (BRIEF §12.2): one band per year with its label on the left and a density bar per slot
/// (month) on a scale shared by all bands, slot labels underneath and a divider between bands. The current slot
/// (, ) is outlined in Accent; clicking a slot makes it current
-/// and raises . Desired height = bands × , so the control
-/// scrolls inside a ScrollViewer.
+/// and raises . From the keyboard, the arrow keys move a dashed focus ring from month to
+/// month (Left and Right run across years, Up and Down change year, Home and End go to the year's ends) with its
+/// readout, and Enter or Space activates the slot under it. Desired height = bands × , so the
+/// control scrolls inside a ScrollViewer and brings the focused band into sight.
///
public sealed class TimelineBands : DrawingElement
{
@@ -46,6 +48,16 @@ public sealed class TimelineBands : DrawingElement
private (int Band, int Slot) _hover = (-1, -1);
+ /// The slot the keyboard is on; (−1, −1) until the control first takes keyboard focus.
+ private (int Band, int Slot) _keyboard = (-1, -1);
+
+ static TimelineBands()
+ {
+ FocusableProperty.OverrideMetadata(typeof(TimelineBands), new FrameworkPropertyMetadata(true));
+ // The focused slot is outlined on the drawing itself.
+ FocusVisualStyleProperty.OverrideMetadata(typeof(TimelineBands), new FrameworkPropertyMetadata(null));
+ }
+
/// One band per year: label + one value per slot.
public IReadOnlyList? Bands { get => (IReadOnlyList?)GetValue(BandsProperty); set => SetValue(BandsProperty, value); }
@@ -90,6 +102,7 @@ public sealed class TimelineBands : DrawingElement
protected override void OnDataChanged()
{
_hover = (-1, -1);
+ if (_keyboard.Band >= (Bands?.Count ?? 0) || _keyboard.Slot >= SlotCount) _keyboard = (-1, -1);
base.OnDataChanged();
}
@@ -137,6 +150,8 @@ public sealed class TimelineBands : DrawingElement
}
if (b == CurrentBand && s == CurrentSlot)
dc.DrawRoundedRectangle(null, GetPen("Brush.Accent", 1.5), new Rect(cx - pitch / 2 + 2, top + 4, pitch - 4, BandHeight - 8), 4, 4);
+ if (IsKeyboardFocused && b == _keyboard.Band && s == _keyboard.Slot)
+ dc.DrawRoundedRectangle(null, GetPen("Brush.Accent", 2, LineDash.Dashed), new Rect(cx - pitch / 2 + 0.5, top + 1, pitch - 1, BandHeight - 2), 5, 5);
}
if (b < bands.Count - 1)
{
@@ -174,10 +189,75 @@ public sealed class TimelineBands : DrawingElement
base.OnMouseLeftButtonUp(e);
var (band, slot) = HitTest(e.GetPosition(this));
if (band < 0) return;
+ _keyboard = (band, slot);
+ Activate(band, slot);
+ e.Handled = true;
+ }
+
+ protected override void OnGotKeyboardFocus(KeyboardFocusChangedEventArgs e)
+ {
+ base.OnGotKeyboardFocus(e);
+ if (_keyboard.Band < 0 && Bands is { Count: > 0 } && SlotCount > 0)
+ _keyboard = CurrentBand >= 0 && CurrentSlot >= 0 ? (CurrentBand, CurrentSlot) : (0, 0);
+ InvalidateVisual();
+ }
+
+ protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
+ {
+ base.OnLostKeyboardFocus(e);
+ Readout.Hide();
+ InvalidateVisual();
+ }
+
+ protected override void OnKeyDown(KeyEventArgs e)
+ {
+ base.OnKeyDown(e);
+ var bands = Bands?.Count ?? 0;
+ var slots = SlotCount;
+ if (e.Handled || bands == 0 || slots == 0) return;
+ var (band, slot) = _keyboard.Band >= 0 ? _keyboard : (0, 0);
+ switch (e.Key)
+ {
+ case Key.Enter or Key.Space:
+ Activate(band, slot);
+ e.Handled = true;
+ return;
+ // Bands run newest first: Left goes back in time, into the year below after January.
+ case Key.Left:
+ (band, slot) = slot > 0 ? (band, slot - 1) : band < bands - 1 ? (band + 1, slots - 1) : (band, slot);
+ break;
+ case Key.Right:
+ (band, slot) = slot < slots - 1 ? (band, slot + 1) : band > 0 ? (band - 1, 0) : (band, slot);
+ break;
+ case Key.Up:
+ band = Math.Max(0, band - 1);
+ break;
+ case Key.Down:
+ band = Math.Min(bands - 1, band + 1);
+ break;
+ case Key.Home:
+ slot = 0;
+ break;
+ case Key.End:
+ slot = slots - 1;
+ break;
+ default:
+ return;
+ }
+ _keyboard = (band, slot);
+ var pitch = SlotPitch;
+ var top = band * BandHeight;
+ BringIntoView(new Rect(0, top, ActualWidth, BandHeight));
+ Readout.Show(ReadoutText(band, slot), new Point(LabelColumn + pitch * (slot + 0.5), top + BandHeight / 2));
+ InvalidateVisual();
+ e.Handled = true;
+ }
+
+ private void Activate(int band, int slot)
+ {
SetCurrentValue(CurrentBandProperty, band);
SetCurrentValue(CurrentSlotProperty, slot);
RaiseEvent(new ChartItemEventArgs(SlotActivatedEvent, band, slot));
- e.Handled = true;
}
private (int Band, int Slot) HitTest(Point p)