- Conflicts are settled against the versions the user was shown; a later change on
either side refuses the choice and compares again. Title, tags, rating and notes
changed differently on both sides are a conflict too (no silent tag union).
- Links are written under the engine's gate and forgotten only after a 404; linked
local copies are read by id; unlinked copies with the same originals are linked
by content.
- A failure on one sequence is recorded on its link; the others are still compared.
- Downloads hash unverified local copies first and restore originals missing here.
- Background proxy downloads give way to the user's requests; "Keep proxies offline"
refreshes the caches of sequences opened with proxies, checks free space and backs
off after a failure.
- Renders travel on request: Send exports (chunked, hash-verified upload keeping the
render id; new POST /sequences/{id}/renders endpoints) and Get exports.
- Server screen: stable row buttons, mockup column grid, Tab through rows, conflict
rows first on the card colour, localised conflict detail, Save both confirmation,
Pause metered uploads, culture switch, Library one-word sync glyphs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
192 lines
8.3 KiB
C#
192 lines
8.3 KiB
C#
using System.Windows.Media;
|
|
using Titano.App.Infrastructure;
|
|
using Titano.Core.Diagnostics;
|
|
using Titano.Core.Localization;
|
|
using Titano.Core.Model;
|
|
using Titano.Core.Naming;
|
|
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>
|
|
public sealed class SequenceItem : ObservableObject
|
|
{
|
|
private readonly ThumbnailService? _thumbnails;
|
|
private Sequence _sequence;
|
|
private ImageSource? _thumbnail;
|
|
private IThumbnailSource? _scrub;
|
|
private CancellationTokenSource? _loading;
|
|
private int _requestedWidth;
|
|
private bool _isSelected;
|
|
private bool _isAnalysing;
|
|
|
|
public SequenceItem(Sequence sequence, ThumbnailService? thumbnails)
|
|
{
|
|
_sequence = sequence;
|
|
_thumbnails = thumbnails;
|
|
}
|
|
|
|
public Sequence Sequence => _sequence;
|
|
public Guid Id => _sequence.Id;
|
|
|
|
/// <summary>User title or "{date} {camera}".</summary>
|
|
public string Title => _sequence.DisplayTitle;
|
|
|
|
/// <summary>"Canon EOS R5" (brand not repeated).</summary>
|
|
public string Camera => PathTemplate.CameraName(_sequence.CameraMake, _sequence.CameraModel);
|
|
|
|
/// <summary>Card line: count · camera · span.</summary>
|
|
public string Subtitle => string.Join(" · ", new[] { FramesText, Camera, SpanText }.Where(s => s.Length > 0));
|
|
|
|
public string FramesText => Formatting.Count(_sequence.FrameCount);
|
|
|
|
/// <summary>First capture date (camera clock).</summary>
|
|
public string DateText => _sequence.FirstCapture is { } first ? Formatting.Date(first) : string.Empty;
|
|
|
|
/// <summary>Time from first to last capture.</summary>
|
|
public string SpanText => _sequence is { FirstCapture: { } a, LastCapture: { } b } && b > a ? Formatting.Duration(b - a) : string.Empty;
|
|
|
|
public string IntervalText => _sequence.MedianInterval is > 0 and var s ? Loc.L("Library.Interval", s.ToString(s < 10 ? "0.#" : "0", Loc.Culture)) : string.Empty;
|
|
|
|
public string SizeText => Formatting.Bytes(_sequence.TotalBytes);
|
|
|
|
public string TagsText => string.Join(", ", _sequence.Tags);
|
|
|
|
/// <summary>Status glyphs of the card and the list (DESIGN §4: glyph + word, never colour alone).</summary>
|
|
public IReadOnlyList<CardStatus> Statuses => BuildStatuses(_sequence, _isAnalysing);
|
|
|
|
/// <summary>The single most relevant status for the list's State column.</summary>
|
|
public CardStatus PrimaryStatus => Statuses.FirstOrDefault(s => s.Kind is StatusKind.Error or StatusKind.Warning or StatusKind.Analysing)
|
|
?? Statuses[0];
|
|
|
|
public ImageSource? Thumbnail
|
|
{
|
|
get => _thumbnail;
|
|
private set => Set(ref _thumbnail, value);
|
|
}
|
|
|
|
/// <summary>Frames for hover scrubbing; created on first use.</summary>
|
|
public IThumbnailSource? ScrubSource => _thumbnails is null || _sequence.FrameCount == 0 ? null : _scrub ??= _thumbnails.ScrubSource(_sequence);
|
|
|
|
public bool IsSelected
|
|
{
|
|
get => _isSelected;
|
|
set => Set(ref _isSelected, value);
|
|
}
|
|
|
|
/// <summary>An analysis job runs on this sequence ("◐ Analysing").</summary>
|
|
public bool IsAnalysing
|
|
{
|
|
get => _isAnalysing;
|
|
set
|
|
{
|
|
if (Set(ref _isAnalysing, value)) RaiseStatuses();
|
|
}
|
|
}
|
|
|
|
/// <summary>Replaces the row with a fresher copy of the same sequence.</summary>
|
|
public void Update(Sequence sequence)
|
|
{
|
|
var heroChanged = sequence.HeroFrameId != _sequence.HeroFrameId || sequence.FrameCount != _sequence.FrameCount;
|
|
_sequence = sequence;
|
|
if (heroChanged)
|
|
{
|
|
_scrub = null;
|
|
if (_requestedWidth > 0) RequestThumbnail(_requestedWidth, force: true);
|
|
}
|
|
OnAllPropertiesChanged();
|
|
}
|
|
|
|
/// <summary>The card or row became visible: load the hero thumbnail (once per width).</summary>
|
|
public void RequestThumbnail(int pixelWidth, bool force = false)
|
|
{
|
|
if (_thumbnails is null || pixelWidth <= 0) return;
|
|
if (!force && _thumbnail is not null && pixelWidth <= _requestedWidth) return;
|
|
if (!force && _loading is not null && pixelWidth <= _requestedWidth) return;
|
|
_requestedWidth = pixelWidth;
|
|
_loading?.Cancel();
|
|
var cancellation = new CancellationTokenSource();
|
|
_loading = cancellation;
|
|
_ = LoadAsync(pixelWidth, cancellation);
|
|
}
|
|
|
|
/// <summary>The card left the screen (recycled): stop its load.</summary>
|
|
public void ReleaseThumbnail()
|
|
{
|
|
_loading?.Cancel();
|
|
_loading = null;
|
|
if (_thumbnail is null) _requestedWidth = 0;
|
|
}
|
|
|
|
private async Task LoadAsync(int pixelWidth, CancellationTokenSource cancellation)
|
|
{
|
|
try
|
|
{
|
|
var image = await _thumbnails!.HeroAsync(_sequence, pixelWidth, cancellation.Token);
|
|
if (!cancellation.IsCancellationRequested) Thumbnail = image;
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Warning("library", $"Thumbnail of {_sequence.Id} failed", ex);
|
|
}
|
|
finally
|
|
{
|
|
if (ReferenceEquals(_loading, cancellation)) _loading = null;
|
|
cancellation.Dispose();
|
|
}
|
|
}
|
|
|
|
private void RaiseStatuses()
|
|
{
|
|
OnPropertyChanged(nameof(Statuses));
|
|
OnPropertyChanged(nameof(PrimaryStatus));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Where a local copy stands against the server (the sync engine writes the state), in one word as DESIGN §4 draws
|
|
/// it ("● Synced", "● Remote", "▲ Conflict") with the detail in the tooltip; null while it is only here.
|
|
/// </summary>
|
|
public static CardStatus? SyncStatus(SyncState state) => state switch
|
|
{
|
|
SyncState.InSync => new CardStatus(StatusKind.Synced, Loc.L("Library.Status.Synced"), Loc.L("Tooltips.Library.Status.Synced")),
|
|
SyncState.LocalAhead => new CardStatus(StatusKind.Synced, Loc.L("Library.Status.Synced"), Loc.L("Tooltips.Library.Status.LocalAhead")),
|
|
SyncState.ServerAhead => new CardStatus(StatusKind.Remote, Loc.L("Library.Status.Remote"), Loc.L("Tooltips.Library.Status.ServerAhead")),
|
|
SyncState.Conflict => new CardStatus(StatusKind.Warning, Loc.L("Library.Status.Conflict"), Loc.L("Tooltips.Library.Status.Conflict")),
|
|
_ => null,
|
|
};
|
|
|
|
/// <summary>Card status row: analysed, proxies, renders, errors or warnings, sync (Main.html); the sync glyph is last so a narrow card cuts it first.</summary>
|
|
public static IReadOnlyList<CardStatus> BuildStatuses(Sequence s, bool analysing)
|
|
{
|
|
var list = new List<CardStatus>(5);
|
|
if (analysing) list.Add(new CardStatus(StatusKind.Analysing, Loc.L("Library.Status.Analysing"), Loc.L("Tooltips.Library.Status.Analysing")));
|
|
else if ((s.Status & SequenceStatus.AnalyzedLight) != 0) list.Add(new CardStatus(StatusKind.Analysed, Loc.L("Library.Status.Analysed"), Loc.L("Tooltips.Library.Status.Analysed")));
|
|
else list.Add(new CardStatus(StatusKind.NotAnalysed, Loc.L("Library.Status.Analysed"), Loc.L("Tooltips.Library.Status.NotAnalysed")));
|
|
|
|
if (s.Origin == SequenceOrigin.Server && s.SyncState == SyncState.RemoteOnly)
|
|
{
|
|
list.Add(new CardStatus(StatusKind.Remote, Loc.L("Library.Status.Remote"), Loc.L("Tooltips.Library.Status.Remote")));
|
|
}
|
|
else
|
|
{
|
|
list.Add((s.Status & SequenceStatus.ProxiesBuilt) != 0
|
|
? new CardStatus(StatusKind.Proxies, Loc.L("Library.Status.Proxies"), Loc.L("Tooltips.Library.Status.Proxies"))
|
|
: new CardStatus(StatusKind.NoProxies, Loc.L("Library.Status.Proxies"), Loc.L("Tooltips.Library.Status.NoProxies")));
|
|
}
|
|
|
|
if (s.RenderedCount > 0)
|
|
list.Add(new CardStatus(StatusKind.Rendered, Formatting.Count(s.RenderedCount), Loc.Plural("Tooltips.Library.Status.Rendered", s.RenderedCount)));
|
|
if ((s.Status & SequenceStatus.HasErrors) != 0)
|
|
list.Add(new CardStatus(StatusKind.Error, Formatting.Count(Math.Max(1, s.WarningCount)), Loc.L("Tooltips.Library.Status.Errors")));
|
|
else if (s.WarningCount > 0 || (s.Status & SequenceStatus.HasWarnings) != 0)
|
|
list.Add(new CardStatus(StatusKind.Warning, Formatting.Count(Math.Max(1, s.WarningCount)), Loc.Plural("Tooltips.Library.Status.Warnings", Math.Max(1, s.WarningCount))));
|
|
if (SyncStatus(s.SyncState) is { } sync) list.Add(sync);
|
|
return list;
|
|
}
|
|
}
|