Files
Chronos/src/Chronos.App/Server/Copies/CopyPhotoRow.cs
T
Alby96andClaude Opus 5.5 b34b6b6fe0 fix(copies): close the owner review 6 verification findings
A merge could still trash photos it never verified, resume against a
pair the user had answered meanwhile, and take different unhashed
photos for copies; the dialog and the lists worded several facts
wrongly or lost them on refresh.

- Merge: a retry resumes only while the pair is still the job's;
  Verify requires the other archive online and its folder in place,
  stops on an unreadable photo, files a differing unhashed photo as a
  second version and must cover every frame before Trash; the plan
  hashes unmatched unhashed photos first, lists "Deleted in the other"
  and names the relinked servers; second versions stay discoverable
  (CopySides.VersionsAsync).
- Integrate: a retry after a failure before the journal runs again.
- Sync: a sequence back after a 404 stays Linked while its link holds;
  a local cull no longer asks for attention.
- Block lines of both planners name the right sequence, archive,
  server and space through one formatter.
- Compare dialog: one Details row per setting with worded values,
  Projects headings, Choose focuses the kept-sequence radios, the
  photo selection reaches rows outside the viewport, the Replace
  confirmation lists the losers per side, plan lines read as queued.
- Matches and Library: counts first and grouped, integrating shown as
  a share, local matches name the other archive, the Library keeps its
  match and "deleted on server" statuses across a refresh.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 15:02:39 +01:00

127 lines
5.2 KiB
C#

using System.Windows.Input;
using Chronos.App.Infrastructure;
using Chronos.App.Settings;
using Chronos.Core.Localization;
using Chronos.Data.Copies;
using Chronos.Data.Sync;
using Chronos.Ui.Controls;
using Chronos.Ui.Mvvm;
namespace Chronos.App.Server.Copies;
/// <summary>A line of the Photos part's class table: glyph and class, count, bytes on each side, what it means.</summary>
public sealed class CopyClassRow(PhotoClassTotal total) : ObservableObject
{
public PhotoClass Class { get; } = total.Class;
public StatusKind Kind => CopyText.ClassKind(Class);
public string Text => CopyText.Class(Class);
public string CountText => Formatting.Count(total.Count);
public string HereBytesText => total.HereBytes > 0 ? Formatting.Bytes(total.HereBytes) : string.Empty;
public string ThereBytesText => total.ThereBytes > 0 ? Formatting.Bytes(total.ThereBytes) : string.Empty;
public string ToolTip => CopyText.ClassToolTip(Class);
public int Count => total.Count;
}
/// <summary>
/// A photo of the Photos part's list: capture time, name, size, where it lies, and per policy a Bring tick (Only here,
/// Only there under Choose each), a version choice (Different under Choose each) or Drop… (Two versions).
/// </summary>
public sealed class CopyPhotoRow : ObservableObject, ISelectableRow
{
private readonly Action _changed;
private readonly bool _swapped;
private bool _bring;
private bool _isSelected;
private SettingsOption<PhotoChoice>? _choice;
/// <param name="swapped">A merge keeping the pair's other sequence: the photo's second side is the kept one.</param>
public CopyPhotoRow(ComparedPhoto photo, bool isMerge, bool canBring, bool canChoose, IReadOnlyList<SettingsOption<PhotoChoice>> choices,
PhotoChoice? current, Action changed, Func<CopyPhotoRow, Task>? drop, bool swapped = false)
{
Photo = photo;
IsMerge = isMerge;
_swapped = isMerge && swapped;
CanBring = canBring;
CanChoose = canChoose;
Choices = choices;
_changed = changed;
_bring = current == PhotoChoice.Bring;
_choice = current is { } c and not PhotoChoice.Bring ? choices.FirstOrDefault(o => o.Value == c) : null;
if (drop is not null) DropCommand = new AsyncRelayCommand(() => drop(this));
}
public ComparedPhoto Photo { get; }
public bool IsMerge { get; }
public string Key => Photo.Key;
private CopyPhotoInput? Input => Photo.Here ?? Photo.There;
public string TimeText => Input?.CapturedAt is { } at ? Formatting.Date(at) + " " + at.ToString("T", Loc.Culture) : string.Empty;
public string Name => Input?.FileName ?? Photo.Key;
public string SizeText => Formatting.Bytes(Photo.Bytes);
/// <summary>"This PC", "Server" (Kept, Other for a merge), or both.</summary>
public string SideText => (Photo.Here, Photo.There) switch
{
(not null, not null) => string.Join(Loc.Separator, Side(true), Side(false)),
(not null, null) => Side(true),
_ => Side(false),
};
public string ToolTip => string.Join(Loc.Separator, Name, SizeText, SideText);
/// <summary>Only here or Only there under Choose each: a Bring tick.</summary>
public bool CanBring { get; }
/// <summary>Different under Choose each: Keep both, This PC's, Server's, Leave.</summary>
public bool CanChoose { get; }
public IReadOnlyList<SettingsOption<PhotoChoice>> Choices { get; }
public ICommand? DropCommand { get; }
public bool CanDrop => DropCommand is not null;
public bool Bring
{
get => _bring;
set
{
if (!Set(ref _bring, value)) return;
_changed();
}
}
public SettingsOption<PhotoChoice>? Choice
{
get => _choice;
set
{
if (!Set(ref _choice, value)) return;
OnPropertyChanged(nameof(ChoiceAccessibleName));
_changed();
}
}
/// <summary>The row is selected in the list (To trash… acts on the selection).</summary>
public bool IsSelected { get => _isSelected; set => Set(ref _isSelected, value); }
/// <summary>The user's choice for this photo, or null when none.</summary>
public PhotoChoice? Chosen => CanBring ? (_bring ? PhotoChoice.Bring : null) : _choice?.Value;
public string BringAccessibleName => Loc.L("Server.Copies.ControlFor", Name, Loc.L("Server.Copies.Photo.Bring"));
public string ChoiceAccessibleName => Loc.L("Server.Copies.ControlFor", Name, _choice?.Label ?? Loc.L("Server.Copies.Version.Leave"));
public string DropAccessibleName => Loc.L("Server.Copies.ControlFor", Name, Loc.L("Server.Copies.Action.Drop"));
/// <summary>Sets the tick or the choice without raising one change per row (Bring all, All: keep both).</summary>
internal void SetQuietly(bool bring, SettingsOption<PhotoChoice>? choice)
{
_bring = bring;
_choice = choice;
OnPropertyChanged(nameof(Bring));
OnPropertyChanged(nameof(Choice));
OnPropertyChanged(nameof(ChoiceAccessibleName));
}
private string Side(bool here) => Loc.L(IsMerge ? (here != _swapped ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.Other")
: here ? "Server.Copies.Detail.ThisPc" : "Server.Copies.Detail.Server");
}