diff --git a/src/Chronos.App/DesignTime/SampleCopies.cs b/src/Chronos.App/DesignTime/SampleCopies.cs
new file mode 100644
index 00000000..a664d396
--- /dev/null
+++ b/src/Chronos.App/DesignTime/SampleCopies.cs
@@ -0,0 +1,250 @@
+using Chronos.Core.Model;
+using Chronos.Data.Archiving;
+using Chronos.Data.Copies;
+using Chronos.Data.Jobs;
+using Chronos.Data.Sync;
+
+namespace Chronos.App.DesignTime;
+
+/// One sample pair: the pair, both sides, the photos of each class, the details that differ and the projects.
+internal sealed record SampleCopy(FoundCopy Copy, CopyFacts Here, CopyFacts There, IReadOnlyList Photos,
+ IReadOnlyList Details, CopyProjectsView Projects, Guid? PreselectedKeep = null);
+
+///
+/// The matches engine of the screenshots and the App tests (owner review 6, #73, design §8.7): pairs held in memory over the
+/// sample's own sequences; Compare answers from the pair; the planners build their plans from the choices as the real
+/// planners would, without touching a file; Enqueue queues a job the capture's engine does not run.
+///
+internal sealed class SampleCopyEngine : ICopyEngine
+{
+ private readonly List _pairs = [];
+ private Action? _found;
+
+ /// Written out, so the warnings-as-errors build raises no CS0067 for an event only tests raise.
+ public event Action? Found
+ {
+ add => _found += value;
+ remove => _found -= value;
+ }
+
+ /// What Find matches answers (the toast's count).
+ public CopyFindResult NextFind { get; set; } = CopyFindResult.Empty;
+
+ public IReadOnlyList Pairs => _pairs;
+
+ public void Add(SampleCopy pair) => _pairs.Add(pair);
+
+ /// Raises as a detection run would (the matches-found toast).
+ public void RaiseFound(CopyFindResult result) => _found?.Invoke(result);
+
+ public FoundCopy Get(Guid id) => Pair(id).Copy;
+
+ public Task> ListAsync(CancellationToken ct) =>
+ Task.FromResult>([.. _pairs.Where(p => p.Copy.IsListed).Select(p => new FoundCopyView(p.Copy, p.Here, p.There))]);
+
+ public Task FindAsync(ISyncRemote? remote, CancellationToken ct) => Task.FromResult(NextFind);
+
+ public Task CompareAsync(Guid copyId, ISyncRemote? remote, CancellationToken ct)
+ {
+ var pair = Pair(copyId);
+ var totals = Enum.GetValues()
+ .Select(c => new PhotoClassTotal(c, pair.Photos.Count(p => p.Class == c),
+ pair.Photos.Where(p => p.Class == c && p.Here is not null).Sum(p => p.Here!.Size),
+ pair.Photos.Where(p => p.Class == c && p.There is not null).Sum(p => p.There!.Size)))
+ .ToList();
+ var renders = new CopyRendersView(2, 1, 1, 180_000_000, 90_000_000);
+ var can = new CopyCapabilities(Integrate: true, LinkOnly: pair.Copy is { Kind: CopyKind.LocalServer, State: CopyState.Candidate }, DeleteThere: true, []);
+ return Task.FromResult(new CopyReview(pair.Copy, pair.Here, pair.There, new CopyComparisonResult(pair.Photos, totals, pair.Copy.Score),
+ pair.Details, pair.Projects, renders, can));
+ }
+
+ public Task PlanIntegrateAsync(Guid copyId, ISyncRemote remote, IntegrateChoices choices, CancellationToken ct)
+ {
+ var pair = Pair(copyId);
+ var (steps, leftOut) = Steps(pair, choices.Photos, choices.PerPhoto, merge: false);
+ var blocks = new List();
+ if (pair.Details.Any(d => !choices.Details.ContainsKey(d.Path))) blocks.Add(CopyBlock.DetailsUnchosen);
+ var projects = choices.Projects == CopyProjects.CopyAcross
+ ? pair.Projects.Here.Where(p => !p.IsMain).Select(p => new ProjectStep(CopySide.ThisPc, p.Id, p.Name, p.Name + " (STUDIO-PC)", p.Versions, p.HeadId))
+ .Concat(pair.Projects.There.Where(p => !p.IsMain).Select(p => new ProjectStep(CopySide.Other, p.Id, p.Name, p.Name + " (nas)", p.Versions, p.HeadId)))
+ .ToList()
+ : [];
+ var lasts = steps.Where(s => s.Action is PhotoAction.TrashHere or PhotoAction.TrashThere).Take(1)
+ .Select(s => new LastCopy(s.Key, s.Action == PhotoAction.TrashHere ? CopySide.ThisPc : CopySide.Other, s.FileName, s.Bytes)).ToList();
+ return Task.FromResult(new IntegratePlan(copyId, pair.Copy.Server ?? string.Empty, pair.Copy.LocalId, pair.Copy.RemoteId ?? Guid.Empty, choices,
+ steps, lasts, leftOut, null, null, null, choices.Details.Count, projects,
+ steps.Where(s => s.Action is PhotoAction.Fetch or PhotoAction.FetchVersion).Sum(s => s.Bytes),
+ steps.Where(s => s.Action is PhotoAction.Send or PhotoAction.SendVersion).Sum(s => s.Bytes),
+ 1_240_000_000_000, 2_900_000_000_000, blocks, 1, 1, 1, 1, "sample"));
+ }
+
+ public async Task EnqueueIntegrateAsync(JobEngine engine, IntegratePlan plan, CancellationToken ct)
+ {
+ var job = await engine.EnqueueAsync(JobKind.Integrate, [plan.LocalId], Pair(plan.CopyId).Here.Title);
+ Set(plan.CopyId, c => c with { State = CopyState.Integrating, PreviousState = c.State, JobId = job.Id });
+ return job;
+ }
+
+ public Task PlanMergeAsync(Guid copyId, Guid? keepId, MergeChoices choices, CancellationToken ct)
+ {
+ var pair = Pair(copyId);
+ var keep = keepId ?? pair.PreselectedKeep;
+ var blocks = new List();
+ if (keep is null) blocks.Add(CopyBlock.KeptUnchosen);
+ if (pair.Details.Any(d => !choices.Details.ContainsKey(d.Path))) blocks.Add(CopyBlock.DetailsUnchosen);
+ var keepsHere = keep is null || keep == pair.Copy.LocalId;
+ var (steps, _) = Steps(pair, choices.Photos, choices.PerPhoto, merge: true, keepsHere);
+ var drop = keepsHere ? pair.There : pair.Here;
+ var projects = (keepsHere ? pair.Projects.There : pair.Projects.Here).Where(p => !p.IsMain)
+ .Select(p => new ProjectStep(keepsHere ? CopySide.Other : CopySide.ThisPc, p.Id, p.Name, p.Name + " (2)", p.Versions, p.HeadId)).ToList();
+ return Task.FromResult(new MergePlan(copyId, keep ?? Guid.Empty, keepsHere ? pair.Copy.OtherId ?? Guid.Empty : pair.Copy.LocalId, choices, steps, [],
+ [new RenderStep(Guid.CreateVersion7(), "Alps 2025 4K.mp4", 640_000_000, null)], null, choices.Details.Count, projects,
+ ["card:CANON-EOS-R5:2025-07-14"], [], [pair.Copy.Server ?? "nas"], new DeletePlan([], []), drop.Bytes / 20, 1_240_000_000_000, blocks,
+ 1, 1, 1, 1, "sample"));
+ }
+
+ public async Task EnqueueMergeAsync(JobEngine engine, MergePlan plan, CancellationToken ct)
+ {
+ var job = await engine.EnqueueAsync(JobKind.MergeSequences, [plan.KeepId, plan.DropId], Pair(plan.CopyId).Here.Title);
+ Set(plan.CopyId, c => c with { State = CopyState.Integrating, PreviousState = c.State, JobId = job.Id });
+ return job;
+ }
+
+ public Task KeepApartAsync(Guid copyId, CancellationToken ct) => Change(copyId, c => c with { State = CopyState.KeptApart, PreviousState = c.State, AnsweredAt = SampleData.Now });
+
+ public Task AskAgainAsync(Guid copyId, CancellationToken ct) => Change(copyId, c => c with { State = CopyState.Candidate, PreviousState = c.State, AnsweredAt = null });
+
+ public Task LinkAsync(Guid copyId, ISyncRemote remote, CancellationToken ct) => Change(copyId, c => c with { State = CopyState.Linked, PreviousState = c.State });
+
+ public Task UnlinkAsync(Guid copyId, ISyncRemote? remote, CancellationToken ct) => Change(copyId, c => c with { State = CopyState.KeptApart, PreviousState = c.State });
+
+ public Task PlanTrashHereAsync(Guid copyId, IReadOnlyCollection photoKeys, CancellationToken ct) =>
+ Task.FromResult(new FrameDeletePlan(new Sequence { Id = Pair(copyId).Copy.LocalId, ArchiveId = Guid.Empty, Folder = string.Empty }, [], 0, []));
+
+ public Task TrashHereAsync(Guid copyId, FrameDeletePlan plan, ISyncRemote? remote, CancellationToken ct) => Task.FromResult(plan.Frames.Count);
+
+ public Task PlanTrashThereAsync(Guid copyId, ISyncRemote remote, IReadOnlyCollection photoKeys, CancellationToken ct)
+ {
+ var pair = Pair(copyId);
+ var photos = pair.Photos.Where(p => photoKeys.Contains(p.Key) && p.There is not null).ToList();
+ return Task.FromResult(new TrashTherePlan(copyId, pair.Copy.Server ?? string.Empty, pair.Copy.RemoteId ?? Guid.Empty,
+ [.. photos.Select(p => p.There!.FrameId)], [.. photos.Select(p => p.Key)], photos.Count, photos.Sum(p => p.There!.Size), 1, []));
+ }
+
+ public Task TrashThereAsync(TrashTherePlan plan, ISyncRemote remote, CancellationToken ct) => Task.FromResult(plan.Photos);
+
+ public Task KeepHereAsync(Guid copyId, CancellationToken ct) => Change(copyId, c => c with { State = CopyState.KeptApart, PreviousState = c.State });
+
+ public Task> TwinsAsync(CancellationToken ct) => Task.FromResult>(
+ [.. _pairs.Where(p => p.Copy is { Kind: CopyKind.LocalServer, State: CopyState.Integrated or CopyState.Linked })
+ .Select(p => new CopyTwin(p.Copy.Id, p.Copy.LocalId, p.Here.Where, "Main", p.Copy.Server ?? string.Empty, p.Copy.RemoteId ?? Guid.Empty, "Vertical"))]);
+
+ ///
+ /// The photo steps of the choices: photos only on one side travel to the other (unless Choose each leaves them out);
+ /// differing ones keep both (Union), or the winner's replaces the loser's, which goes to the trash.
+ ///
+ private static (List Steps, int LeftOut) Steps(SampleCopy pair, CopyPhotoPolicy policy, IReadOnlyDictionary perPhoto,
+ bool merge, bool keepsHere = true)
+ {
+ var steps = new List();
+ var leftOut = 0;
+ foreach (var photo in pair.Photos)
+ {
+ var here = photo.Here;
+ var there = photo.There;
+ var choice = perPhoto.TryGetValue(photo.Key, out var c) ? c : (PhotoChoice?)null;
+ switch (photo.Class)
+ {
+ case PhotoClass.OnlyHere when here is not null:
+ if (merge && keepsHere) break;
+ if (policy == CopyPhotoPolicy.ChoosePerPhoto && choice != PhotoChoice.Bring && !merge)
+ {
+ leftOut++;
+ break;
+ }
+ steps.Add(new(photo.Key, merge ? PhotoAction.Fetch : PhotoAction.Send, here.FrameId, here.FileName, here.Size, here.Sha256));
+ break;
+ case PhotoClass.OnlyThere when there is not null:
+ if (merge && !keepsHere) break;
+ if (policy == CopyPhotoPolicy.ChoosePerPhoto && choice != PhotoChoice.Bring && !merge)
+ {
+ leftOut++;
+ break;
+ }
+ steps.Add(new(photo.Key, PhotoAction.Fetch, there.FrameId, there.FileName, there.Size, there.Sha256));
+ break;
+ case PhotoClass.Differs when here is not null && there is not null:
+ var wanted = policy switch
+ {
+ CopyPhotoPolicy.Union => PhotoChoice.KeepBoth,
+ CopyPhotoPolicy.ThisPcWins => PhotoChoice.TakeHere,
+ CopyPhotoPolicy.OtherWins => PhotoChoice.TakeThere,
+ _ => choice ?? PhotoChoice.Leave,
+ };
+ if (wanted == PhotoChoice.Leave)
+ {
+ leftOut++;
+ break;
+ }
+ if (wanted is PhotoChoice.KeepBoth or PhotoChoice.TakeHere) steps.Add(new(photo.Key, PhotoAction.SendVersion, here.FrameId, here.FileName, here.Size, here.Sha256));
+ if (wanted is PhotoChoice.KeepBoth or PhotoChoice.TakeThere) steps.Add(new(photo.Key, PhotoAction.FetchVersion, there.FrameId, there.FileName, there.Size, there.Sha256));
+ if (wanted == PhotoChoice.TakeHere) steps.Add(new(photo.Key, PhotoAction.TrashThere, there.FrameId, there.FileName, there.Size, there.Sha256));
+ if (wanted == PhotoChoice.TakeThere) steps.Add(new(photo.Key, PhotoAction.TrashHere, here.FrameId, here.FileName, here.Size, here.Sha256));
+ break;
+ }
+ }
+ return (steps, leftOut);
+ }
+
+ private SampleCopy Pair(Guid copyId) => _pairs.Single(p => p.Copy.Id == copyId);
+
+ private void Set(Guid copyId, Func change)
+ {
+ var at = _pairs.FindIndex(p => p.Copy.Id == copyId);
+ _pairs[at] = _pairs[at] with { Copy = change(_pairs[at].Copy) };
+ }
+
+ private Task Change(Guid copyId, Func change)
+ {
+ Set(copyId, change);
+ return Task.CompletedTask;
+ }
+}
+
+/// The sample pairs (design §8.7): five time-lapses with titles of their own, so the sync scenes' counts stay.
+internal static class SampleCopies
+{
+ /// The photos of one side: name, size, capture time; every third one unhashed when asked.
+ internal static IEnumerable Photos(PhotoClass cls, int count, DateTime start, int from, bool here, bool there, string prefix = "IMG_")
+ {
+ for (var i = 0; i < count; i++)
+ {
+ var at = start.AddSeconds((from + i) * 10);
+ var name = $"{prefix}{from + i + 1:0000}.CR3";
+ var size = 24_000_000L + (from + i) % 7 * 310_000;
+ var sha = $"{cls}{from + i:x8}".PadRight(64, '0');
+ var h = here ? new CopyPhotoInput(Guid.CreateVersion7(), from + i, name, sha, size, at, false) : null;
+ var t = there ? new CopyPhotoInput(Guid.CreateVersion7(), from + i, name, cls == PhotoClass.Differs ? sha.Replace('0', '1') : sha, size + (cls == PhotoClass.Differs ? 4_096 : 0), at, false) : null;
+ yield return new ComparedPhoto(cls, sha, h, t, here ? 1 : 0, there ? 1 : 0, size);
+ }
+ }
+
+ internal static CopyScore Score(IReadOnlyList photos, int hints)
+ {
+ int Of(PhotoClass c) => photos.Count(p => p.Class == c);
+ var local = photos.Count(p => p.Here is not null);
+ var other = photos.Count(p => p.There is not null);
+ var shared = Of(PhotoClass.Same) + Of(PhotoClass.Differs);
+ var smaller = Math.Max(1, Math.Min(local, other));
+ return new CopyScore(Of(PhotoClass.Same), Of(PhotoClass.SameUnhashed), 0, Of(PhotoClass.OnlyHere), Of(PhotoClass.OnlyThere), Of(PhotoClass.Differs),
+ Of(PhotoClass.DeletedHere), Of(PhotoClass.DeletedThere), Of(PhotoClass.Versions), local, other,
+ Math.Min(1000, shared * 1000 / smaller), shared * 1000 / Math.Max(1, local + other - shared), hints);
+ }
+
+ internal static CopyFacts Facts(Sequence sequence, string where, int photos, bool originals = false, IReadOnlyList? servers = null) =>
+ new(sequence.DisplayTitle, where, sequence.ArchiveId, photos, photos * 24_000_000L, sequence.FirstCapture, sequence.LastCapture,
+ sequence.CameraModel, photos, sequence.Origin, servers ?? [], originals);
+
+ internal static ProjectLine Project(string name, bool main, int versions, int daysAgo) =>
+ new(Guid.CreateVersion7(), name, main, versions, Guid.CreateVersion7(), "sample", SampleData.Now.AddDays(-daysAgo));
+}
diff --git a/src/Chronos.App/DesignTime/SampleData.cs b/src/Chronos.App/DesignTime/SampleData.cs
index 4d2945fd..1407b62a 100644
--- a/src/Chronos.App/DesignTime/SampleData.cs
+++ b/src/Chronos.App/DesignTime/SampleData.cs
@@ -24,6 +24,7 @@ using Chronos.Core.Updates;
using Chronos.Core.Video;
using Chronos.Data;
using Chronos.Data.Archiving;
+using Chronos.Data.Copies;
using Chronos.Data.Jobs;
using Chronos.Data.Scheduling;
using Chronos.Data.Sync;
@@ -63,8 +64,11 @@ public sealed class SampleData
private SampleData(AppServices services) => _services = services;
- /// What the sample server says it can do (none: an older server, whose sequences open with proxies); tests set it.
- public IReadOnlyList Capabilities { get; set; } = [];
+ ///
+ /// What the sample server says it can do: the photo lookup and uploads into a sequence that matches need (owner review 6,
+ /// #73), but no projects (an older server's sequences open with proxies); tests set it.
+ ///
+ public IReadOnlyList Capabilities { get; set; } = [ServerCapabilities.PhotoLookup, ServerCapabilities.UploadInto];
/// The server-only sequence whose proxies keeps on this PC (Sunrise over Superga).
public Guid ProxiedSequenceId => _sunrise;
@@ -278,6 +282,120 @@ public sealed class SampleData
await db.Jobs.EnqueueAsync(SampleJobDetails.Apply(Transfer(JobKind.Download, _lakeComo, "Lake Como storm", originals, JobState.Paused, 300, 1_450)));
}
+ ///
+ /// The matches of the screenshots (owner review 6, #73, design §8.7), a phase of its own after the sync captures: five
+ /// time-lapses of their own (a second archive holds the other Alps 2025), so the sync scenes' counts stay. Lighthouse
+ /// 2026-08-13 is a match found on the server (24 photos only here, 2 different, three details differ), Meteor night kept
+ /// apart, Bridge works wk 41 integrated with 3 photos deleted on the server, Alps 2025 twice on this PC (the copy in the
+ /// server's originals archive preselected as the kept one), Garden 2026 deleted on the server. Returns the engine.
+ ///
+ internal async Task FillCopiesAsync()
+ {
+ var db = _db ?? throw new InvalidOperationException("FillAsync first.");
+ var main = (await db.Archives.ListAsync())[0];
+ var root = Path.Combine(_services.Environment.DataDirectory, "archive-nas");
+ Directory.CreateDirectory(root);
+ var originals = new Archive { Id = Guid.CreateVersion7(), Name = "ChronosArchive - Studio NAS", RootPath = root, Created = Now.AddMonths(-3) };
+ await db.Archives.UpsertAsync(originals);
+ var server = _services.Sync.LastServer ?? ServerAddress;
+ const string ServerName = "Studio NAS";
+ var start = new DateTime(2026, 8, 13, 21, 0, 0);
+
+ async Task SequenceAsync(string title, Guid archive, int frames, DateTime first, string camera)
+ {
+ var sequence = new Sequence
+ {
+ Id = Guid.CreateVersion7(),
+ ArchiveId = archive,
+ Title = title,
+ Folder = $"{first:yyyy}/{first:yyyy-MM-dd} {camera}",
+ CameraMake = "Canon",
+ CameraModel = camera,
+ FirstCapture = first,
+ LastCapture = first.AddSeconds(frames * 10),
+ FrameCount = frames,
+ MedianInterval = 10,
+ TotalBytes = frames * 24_000_000L,
+ Status = SequenceStatus.AnalyzedLight | SequenceStatus.ThumbsBuilt,
+ UpdatedAt = Now,
+ };
+ await db.Sequences.UpsertAsync(sequence);
+ return sequence;
+ }
+
+ var engine = new SampleCopyEngine();
+ FoundCopy Copy(Sequence local, CopyKind kind, CopyState state, IReadOnlyList photos, Guid? other = null, int gone = 0, int hints = 3) => new()
+ {
+ Id = Guid.CreateVersion7(),
+ Kind = kind,
+ LocalId = local.Id,
+ Server = kind == CopyKind.LocalServer ? server : null,
+ RemoteId = kind == CopyKind.LocalServer ? Guid.CreateVersion7() : null,
+ OtherId = other,
+ Evidence = CopyEvidence.Hashes,
+ State = state,
+ Score = SampleCopies.Score(photos, hints),
+ Fingerprint = "sample",
+ RemoteGoneHits = gone,
+ RemoteGoneAt = gone > 0 ? Now.AddDays(-1) : null,
+ FoundAt = Now.AddDays(-2),
+ UpdatedAt = Now.AddHours(-3),
+ AnsweredAt = state == CopyState.KeptApart ? Now.AddDays(-12) : null,
+ };
+ CopyProjectsView Projects(bool other) => new(
+ [SampleCopies.Project("Main", true, 4, 2), SampleCopies.Project("Vertical", false, 3, 5)],
+ other ? [SampleCopies.Project("Main", true, 2, 9), SampleCopies.Project("Slow pan", false, 1, 9)] : [SampleCopies.Project("Main", true, 2, 9)],
+ MainSame: false, ThereKeepsProjects: true);
+
+ // (1) Lighthouse: the card's photos, the Uploader sent part of them.
+ var lighthouse = await SequenceAsync("Lighthouse 2026-08-13", main.Id, 1_204, start, "Canon EOS R5");
+ List photos =
+ [
+ .. SampleCopies.Photos(PhotoClass.Same, 1_178, start, 0, here: true, there: true),
+ .. SampleCopies.Photos(PhotoClass.OnlyHere, 24, start, 1_178, here: true, there: false),
+ .. SampleCopies.Photos(PhotoClass.Differs, 2, start, 1_202, here: true, there: true),
+ ];
+ engine.Add(new SampleCopy(Copy(lighthouse, CopyKind.LocalServer, CopyState.Candidate, photos),
+ SampleCopies.Facts(lighthouse, main.Name, 1_204), SampleCopies.Facts(lighthouse, ServerName, 1_180), photos,
+ [new DetailLine("title", "Lighthouse 2026-08-13", "Lighthouse"), new DetailLine("rating", "4", "3"),
+ new DetailLine("exposure.deflickerWindow", "41", "33")], Projects(other: true)));
+
+ // (2) Meteor night: kept apart.
+ var meteor = await SequenceAsync("Meteor night", main.Id, 640, new DateTime(2026, 8, 12, 23, 10, 0), "Canon EOS R6");
+ photos = [.. SampleCopies.Photos(PhotoClass.Same, 320, start, 0, true, true), .. SampleCopies.Photos(PhotoClass.OnlyHere, 320, start, 320, true, false)];
+ engine.Add(new SampleCopy(Copy(meteor, CopyKind.LocalServer, CopyState.KeptApart, photos, hints: 1),
+ SampleCopies.Facts(meteor, main.Name, 640), SampleCopies.Facts(meteor, ServerName, 320), photos, [], Projects(other: false)));
+
+ // (3) Bridge works: integrated; the server deleted 3 photos since.
+ var bridge = await SequenceAsync("Bridge works wk 41", main.Id, 2_400, new DateTime(2026, 10, 6, 7, 0, 0), "Canon EOS R5");
+ photos = [.. SampleCopies.Photos(PhotoClass.Same, 2_397, start, 0, true, true), .. SampleCopies.Photos(PhotoClass.DeletedThere, 3, start, 2_397, true, false)];
+ engine.Add(new SampleCopy(Copy(bridge, CopyKind.LocalServer, CopyState.Integrated, photos),
+ SampleCopies.Facts(bridge, main.Name, 2_400), SampleCopies.Facts(bridge, ServerName, 2_397), photos, [], Projects(other: false)));
+
+ // (4) Alps 2025 twice on this PC: the copy downloaded into the server's originals archive is kept.
+ var alps = await SequenceAsync("Alps 2025", main.Id, 940, new DateTime(2025, 7, 14, 5, 30, 0), "Canon EOS R5");
+ var alpsNas = await SequenceAsync("Alps 2025", originals.Id, 902, new DateTime(2025, 7, 14, 5, 30, 0), "Canon EOS R5");
+ photos =
+ [
+ .. SampleCopies.Photos(PhotoClass.Same, 900, start, 0, true, true),
+ .. SampleCopies.Photos(PhotoClass.OnlyHere, 38, start, 900, true, false),
+ .. SampleCopies.Photos(PhotoClass.Versions, 2, start, 938, true, false, "IMG_V"),
+ ];
+ engine.Add(new SampleCopy(Copy(alps, CopyKind.LocalLocal, CopyState.Candidate, photos, other: alpsNas.Id),
+ SampleCopies.Facts(alps, main.Name, 940), SampleCopies.Facts(alpsNas, originals.Name, 902, originals: true, servers: [ServerName]), photos,
+ [new DetailLine("rating", "5", "4")], Projects(other: true), PreselectedKeep: alpsNas.Id));
+
+ // (5) Garden 2026: the server deleted its copy.
+ var garden = await SequenceAsync("Garden 2026", main.Id, 480, new DateTime(2026, 5, 2, 6, 0, 0), "Canon EOS R6");
+ photos = [.. SampleCopies.Photos(PhotoClass.Same, 480, start, 0, true, false)];
+ engine.Add(new SampleCopy(Copy(garden, CopyKind.LocalServer, CopyState.Linked, photos, gone: 2),
+ SampleCopies.Facts(garden, main.Name, 480), SampleCopies.Facts(garden, ServerName, 0), photos, [], Projects(other: false)));
+
+ engine.NextFind = new CopyFindResult([engine.Pairs[0].Copy, engine.Pairs[3].Copy], [], []);
+ _services.Sync.Copies = engine;
+ return engine;
+ }
+
///
/// Fetches the proxies of Sunrise over Superga into the proxy cache through a download job on a one-off engine (the
/// capture's engine does not run jobs), so the sync table shows a sequence kept with proxies only.
diff --git a/src/Chronos.App/Library/LibraryScenes.cs b/src/Chronos.App/Library/LibraryScenes.cs
index d84131f0..64cfaec7 100644
--- a/src/Chronos.App/Library/LibraryScenes.cs
+++ b/src/Chronos.App/Library/LibraryScenes.cs
@@ -17,6 +17,23 @@ public static class LibraryScenes
/// Sequences selected for the mass actions bar.
public const int MassSelection = 3;
+ ///
+ /// library-copies (owner review 6, #73): the cards of sequences in matches that ask for a choice, with "Also
+ /// elsewhere" or "Deleted there", found by ; the Matches list pushes the statuses after its reload.
+ ///
+ public static async Task ShowCopiesAsync(ShellViewModel shell, string search)
+ {
+ var library = shell.Library;
+ shell.Navigate(SectionKey.Library);
+ library.Dialog?.CloseCommand.Execute(null);
+ library.ClearSelectionCommand.Execute(null);
+ library.ClearFiltersCommand.Execute(null);
+ library.LayoutIndex = 0;
+ library.SearchText = search;
+ await library.RefreshAsync();
+ await shell.Server.Sync.Copies.ReloadAsync();
+ }
+
public static async Task ShowAsync(ShellViewModel shell, string scene)
{
var library = shell.Library;
diff --git a/src/Chronos.App/Library/SequenceItem.cs b/src/Chronos.App/Library/SequenceItem.cs
index 08a133af..9141dd0c 100644
--- a/src/Chronos.App/Library/SequenceItem.cs
+++ b/src/Chronos.App/Library/SequenceItem.cs
@@ -31,6 +31,7 @@ public sealed class SequenceItem : ObservableObject
private int _requestedWidth;
private bool _isSelected;
private bool _isAnalysing;
+ private CardStatus? _match;
public SequenceItem(Sequence sequence, ISequenceThumbnails? thumbnails)
{
@@ -100,7 +101,26 @@ public sealed class SequenceItem : ObservableObject
public string TagsText => string.Join(", ", _sequence.Tags);
/// Status glyphs of the card and the list (DESIGN §4: glyph + word, never colour alone).
- public IReadOnlyList Statuses => BuildStatuses(_sequence, _isAnalysing);
+ public IReadOnlyList Statuses => _match is { } match ? [.. BuildStatuses(_sequence, _isAnalysing), match] : BuildStatuses(_sequence, _isAnalysing);
+
+ ///
+ /// "Also elsewhere" or "Deleted there" (owner review 6, #73): the sequence is in a pair that asks for a choice; set by the
+ /// Matches list after each reload. Null otherwise.
+ ///
+ public CardStatus? MatchStatus => _match;
+
+ /// The pair asking for a choice: the card's menu and the list row offer Compare….
+ public bool HasMatch => _match is not null;
+
+ /// Takes the Matches list's status of this sequence (null: none).
+ public void SetMatch(CardStatus? status)
+ {
+ if (Equals(_match, status)) return;
+ _match = status;
+ OnPropertyChanged(nameof(MatchStatus));
+ OnPropertyChanged(nameof(HasMatch));
+ RaiseStatuses();
+ }
/// The single most relevant status for the list's State column.
public CardStatus PrimaryStatus => Statuses.FirstOrDefault(s => s.Kind is StatusKind.Error or StatusKind.Warning or StatusKind.Analysing)
diff --git a/src/Chronos.App/Sections/ArchiveViewModel.cs b/src/Chronos.App/Sections/ArchiveViewModel.cs
index 677fca87..fcbc4be1 100644
--- a/src/Chronos.App/Sections/ArchiveViewModel.cs
+++ b/src/Chronos.App/Sections/ArchiveViewModel.cs
@@ -747,7 +747,7 @@ public sealed class ArchiveViewModel : SectionViewModel
if (MaintenanceReports.MaintenanceKinds.Contains(job.Kind)) System.Windows.Application.Current?.Dispatcher.BeginInvoke(() => TrackRecent(job));
if (job.State is not (JobState.Done or JobState.Failed)) return;
if (job.Kind is not (JobKind.Scan or JobKind.Rebuild or JobKind.Verify or JobKind.Maintenance or JobKind.Import or JobKind.Proxies or JobKind.Thumbs
- or JobKind.LightAnalyse or JobKind.DeepAnalyse or JobKind.Move or JobKind.Convert)) return;
+ or JobKind.LightAnalyse or JobKind.DeepAnalyse or JobKind.Move or JobKind.Convert or JobKind.Integrate or JobKind.MergeSequences)) return;
System.Windows.Application.Current?.Dispatcher.BeginInvoke(() =>
{
if (_archive is not { } archive || !job.TargetIds.Any(id => id == archive.Id || _sequenceIds.Contains(id))) return;
diff --git a/src/Chronos.App/Sections/JobsViewModel.cs b/src/Chronos.App/Sections/JobsViewModel.cs
index 1c9aa794..96380b00 100644
--- a/src/Chronos.App/Sections/JobsViewModel.cs
+++ b/src/Chronos.App/Sections/JobsViewModel.cs
@@ -347,7 +347,7 @@ public sealed class JobsViewModel : SectionViewModel
Title = Loc.L("Shell.Job.Done"),
Message = JobText.Name(job),
ActionText = Loc.L("Jobs.Action.Open"),
- ActionToolTip = Loc.L("Tooltips.Jobs.Open"),
+ ActionToolTip = Loc.L(job.Kind is JobKind.Integrate or JobKind.MergeSequences ? "Tooltips.Jobs.OpenMatch" : "Tooltips.Jobs.Open"),
ActionCommand = new AsyncRelayCommand(() => OpenTargetAsync(job)),
RunsFromNotification = true,
};
@@ -507,6 +507,19 @@ public sealed class JobsViewModel : SectionViewModel
{
var db = Shell.Services.Database;
if (db is null || job.TargetIds.Count == 0) return;
+ // Owner review 6, #73: an Integrate shows its pair in Server › Matches; a merge opens the sequence it kept.
+ if (job.Kind == JobKind.Integrate)
+ {
+ var title = await db.Sequences.GetAsync(job.TargetIds[0]) is { } local ? local.DisplayTitle : null;
+ Shell.Navigate(SectionKey.Server);
+ Shell.Server.Sync.ShowFilter(Chronos.App.Server.SyncFilter.FoundCopies, title);
+ return;
+ }
+ if (job.Kind == JobKind.MergeSequences)
+ {
+ Shell.OpenSequence(job.TargetIds[0]);
+ return;
+ }
var targets = job.TargetIds.Distinct().ToList();
if (targets.Count > LibraryPager.DefaultPageSize)
{
diff --git a/src/Chronos.App/Sections/LibraryView.xaml b/src/Chronos.App/Sections/LibraryView.xaml
index 7664f1c9..deb302b1 100644
--- a/src/Chronos.App/Sections/LibraryView.xaml
+++ b/src/Chronos.App/Sections/LibraryView.xaml
@@ -12,10 +12,22 @@
+
+
+
+
+
-
+
+
@@ -267,11 +275,12 @@
+ Visibility="{Binding ShowChips, Converter={StaticResource BoolToVisibility}}">
+ IsChecked="{Binding IsSelected, Mode=OneWay}" Command="{Binding SelectCommand}" ToolTip="{Binding ToolTip}" Margin="0,1,10,1"
+ Visibility="{Binding IsVisible, Converter={StaticResource BoolToVisibility}}" />
@@ -289,9 +298,13 @@
+ Margin="10,0,0,0" Visibility="{Binding ShowSearch, Converter={StaticResource BoolToVisibility}}" />
+ ToolTipService.ShowOnDisabled="True" Height="30" Margin="10,0,0,0"
+ Visibility="{Binding IsMatches, Converter={x:Static ui:InverseBoolToVisibilityConverter.Instance}}" />
+
+
+
+
+
@@ -317,7 +337,7 @@
+ AutomationProperties.Name="{l:Loc Server.Sync.Title}" Visibility="{Binding ShowSyncList, Converter={StaticResource BoolToVisibility}}">
@@ -368,6 +388,52 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -387,4 +453,12 @@
+
+
+
+
+
+
+
diff --git a/src/Chronos.App/Sections/ServerView.xaml.cs b/src/Chronos.App/Sections/ServerView.xaml.cs
index fd8211f4..5b9c6069 100644
--- a/src/Chronos.App/Sections/ServerView.xaml.cs
+++ b/src/Chronos.App/Sections/ServerView.xaml.cs
@@ -1,12 +1,22 @@
+using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Threading;
namespace Chronos.App.Sections;
public partial class ServerView : UserControl
{
- public ServerView() => InitializeComponent();
+ private IInputElement? _beforeDialog;
+
+ public ServerView()
+ {
+ InitializeComponent();
+ DataContextChanged += OnDataContextChanged;
+ }
/// The ▾ button opens the list of servers found on the LAN under itself.
private void OnShowKnown(object sender, RoutedEventArgs e)
@@ -17,4 +27,34 @@ public partial class ServerView : UserControl
menu.Placement = PlacementMode.Bottom;
menu.IsOpen = true;
}
+
+ private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
+ {
+ if (e.OldValue is ServerViewModel old) old.PropertyChanged -= OnModelChanged;
+ if (e.NewValue is ServerViewModel model) model.PropertyChanged += OnModelChanged;
+ }
+
+ ///
+ /// A dialog that opens (Compare sequences) takes the keyboard; when it closes, the keyboard goes back to the control that
+ /// opened it, or to the first control of the section when that one can no longer take it.
+ ///
+ private void OnModelChanged(object? sender, PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName != nameof(ServerViewModel.Dialog) || sender is not ServerViewModel model) return;
+ if (model.Dialog is not null)
+ {
+ if (!IsVisible) return;
+ _beforeDialog ??= Keyboard.FocusedElement is Visual focused && IsAncestorOf(focused) ? Keyboard.FocusedElement : null;
+ Dispatcher.BeginInvoke(DispatcherPriority.Input, () => DialogHost.MoveFocus(new TraversalRequest(FocusNavigationDirection.First)));
+ return;
+ }
+ var back = _beforeDialog;
+ _beforeDialog = null;
+ if (!IsVisible) return;
+ Dispatcher.BeginInvoke(DispatcherPriority.Input, () =>
+ {
+ if (back is UIElement { IsVisible: true, IsEnabled: true, Focusable: true } element && element.Focus()) return;
+ Body.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
+ });
+ }
}
diff --git a/src/Chronos.App/Sections/ServerViewModel.cs b/src/Chronos.App/Sections/ServerViewModel.cs
index 9eb15672..7151379e 100644
--- a/src/Chronos.App/Sections/ServerViewModel.cs
+++ b/src/Chronos.App/Sections/ServerViewModel.cs
@@ -1,5 +1,6 @@
using System.ComponentModel;
using System.Windows.Input;
+using Chronos.App.Archiving;
using Chronos.App.Infrastructure;
using Chronos.App.Server;
using Chronos.App.Settings;
@@ -16,7 +17,7 @@ namespace Chronos.App.Sections;
/// status (name, version, latency, certificate), account and quota, sign out, the options of this PC (render node,
/// proxies kept offline, automatic project sync, uploads paused on metered networks), the server's running and paused jobs
/// () and the sync table ().
-/// The rail badge counts the settings conflicts waiting for a choice.
+/// The rail badge counts the settings conflicts and the matches waiting for a choice; the Compare dialog shows over the section.
///
public sealed class ServerViewModel : SectionViewModel
{
@@ -24,6 +25,10 @@ public sealed class ServerViewModel : SectionViewModel
private string _address;
private string? _errorText;
private ServerSession? _session;
+ private ArchiveDialogViewModel? _dialog;
+
+ /// Dialogs that show once the open one closes, oldest first.
+ private readonly Queue _waiting = new();
public ServerViewModel(ShellViewModel shell)
: base(SectionKey.Server, "Icon.Server")
@@ -42,6 +47,9 @@ public sealed class ServerViewModel : SectionViewModel
Sync = new SyncTableViewModel(shell);
_conflicts = Sync.Chips.Single(c => c.Filter == SyncFilter.Conflicts);
_conflicts.PropertyChanged += OnConflictsChanged;
+ Sync.Copies.OpenDialog = OpenDialogWhenFree;
+ Sync.Copies.CloseDialog = CloseDialog;
+ Sync.Copies.Changed += UpdateBadge;
Jobs = new ServerJobsViewModel(() => ServerJobsViewModel.AccountOf(Session), () => JobsConnection(Session), SynchronizationContext.Current,
(title, message) => Shell.Notify(title, message, isError: true));
SharePanel = new SharePanelViewModel(shell);
@@ -61,6 +69,44 @@ public sealed class ServerViewModel : SectionViewModel
public ShellViewModel Shell { get; }
+ /// The section's in-window dialog (Compare sequences, Delete…); null when none is open.
+ public ArchiveDialogViewModel? Dialog
+ {
+ get => _dialog;
+ private set
+ {
+ if (!Set(ref _dialog, value)) return;
+ OnPropertyChanged(nameof(IsDialogOpen));
+ OnPropertyChanged(nameof(IsContentEnabled));
+ }
+ }
+
+ public bool IsDialogOpen => _dialog is not null;
+
+ /// The section behind an open dialog takes neither clicks nor keyboard focus.
+ public bool IsContentEnabled => _dialog is null;
+
+ /// Shows now when none is open, else once the open one (and those waiting before it) closed.
+ internal void OpenDialogWhenFree(ArchiveDialogViewModel dialog)
+ {
+ if (_dialog is null) Dialog = dialog;
+ else _waiting.Enqueue(dialog);
+ }
+
+ /// Closes if it is the open one; the next one waiting shows (one closed meanwhile is skipped).
+ internal void CloseDialog(ArchiveDialogViewModel dialog)
+ {
+ if (!ReferenceEquals(_dialog, dialog)) return;
+ dialog.Dispose();
+ Dialog = null;
+ while (_waiting.TryDequeue(out var next))
+ {
+ if (next.IsClosed) continue;
+ Dialog = next;
+ return;
+ }
+ }
+
private ServerSession Session => _session ?? Shell.Services.Server;
public ICommand ConnectCommand { get; }
@@ -233,6 +279,8 @@ public sealed class ServerViewModel : SectionViewModel
public override void Dispose()
{
_conflicts.PropertyChanged -= OnConflictsChanged;
+ Sync.Copies.Changed -= UpdateBadge;
+ _dialog?.Dispose();
if (_session is not null) _session.PropertyChanged -= OnSessionChanged;
Shell.Settings.Encoders.CollectionChanged -= OnEncodersChanged;
Sync.Dispose();
@@ -249,9 +297,12 @@ public sealed class ServerViewModel : SectionViewModel
private void OnConflictsChanged(object? sender, PropertyChangedEventArgs e)
{
- if (e.PropertyName is nameof(SyncFilterChip.Count) or "" or null) Badge = _conflicts.Count;
+ if (e.PropertyName is nameof(SyncFilterChip.Count) or "" or null) UpdateBadge();
}
+ /// The rail badge: conflicts plus pairs asking for a choice (design §8.1).
+ private void UpdateBadge() => Badge = _conflicts.Count + Sync.Copies.AttentionCount;
+
private void SetSyncOption(bool value, bool current, Action store, [System.Runtime.CompilerServices.CallerMemberName] string? name = null)
{
if (value == current) return;
diff --git a/src/Chronos.App/Sections/SettingsView.xaml b/src/Chronos.App/Sections/SettingsView.xaml
index fedbf7c2..55fac5ca 100644
--- a/src/Chronos.App/Sections/SettingsView.xaml
+++ b/src/Chronos.App/Sections/SettingsView.xaml
@@ -681,6 +681,36 @@
shell:EditBehavior.Field="{Binding DefaultServer}" ToolTip="{Binding DefaultServer.ToolTip}" ui:Field.Placeholder="{l:Loc Server.AddressPlaceholder}"
AutomationProperties.Name="{l:Loc Settings.Server.Default}" FlowDirection="LeftToRight" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Chronos.App/Sections/SettingsViewModel.cs b/src/Chronos.App/Sections/SettingsViewModel.cs
index cac049b9..cd1c359d 100644
--- a/src/Chronos.App/Sections/SettingsViewModel.cs
+++ b/src/Chronos.App/Sections/SettingsViewModel.cs
@@ -92,7 +92,7 @@ public sealed class SettingsViewModel : SectionViewModel
"Settings.Workspace.Sync", "Settings.Workspace.AfterSave", "Settings.Workspace.VersionOnRender", "Settings.Workspace.SaveBeforeRender",
"Settings.Workspace.Kept", "Settings.Workspace.CleanAfter", "Settings.Workspace.OpenProject", "Settings.Workspace.Trash", "Settings.Workspace.Homes"]),
new(SettingsPage.Server, ["Settings.Server.Share", "Settings.Server.ShareName", "Settings.Server.HttpsPort", "Settings.Server.HttpPort",
- "Settings.Server.PublicHttpsPort", "Settings.Server.PublicHttpPort", "Settings.Server.Discovery", "Settings.Server.ShareFolder", "Settings.Server.Default", "Settings.Server.RenderNode", "Settings.Server.Certificates", "Settings.Server.Known"]),
+ "Settings.Server.PublicHttpsPort", "Settings.Server.PublicHttpPort", "Settings.Server.Discovery", "Settings.Server.ShareFolder", "Settings.Server.Default", "Settings.Server.CopyLinking", "Settings.Server.CopyPhotos", "Settings.Server.CopyProjects", "Settings.Server.RenderNode", "Settings.Server.Certificates", "Settings.Server.Known"]),
new(SettingsPage.Updates, ["Settings.General.CheckOnStart", "Settings.Updates.Latest", "About.Update.Check", "About.Releases"]),
new(SettingsPage.Advanced, ["Settings.Advanced.DataFolder", "Settings.Advanced.Logs", "Settings.Advanced.LogLevel", "Settings.Advanced.KeepLogs",
"Settings.Advanced.FileSize", "Settings.Advanced.LogsTotal", "Settings.Advanced.Rotation", "Settings.Advanced.Diagnostics",
@@ -180,6 +180,7 @@ public sealed class SettingsViewModel : SectionViewModel
// ---- Server › Sharing (owner review 5, #67); saving applies it to the share (AppServices.SaveSettings). ----
ShareRows = new ShareSettingsRows(_s, Save, Shell.Services.Environment.ShareDirectory, Shell.Services.Environment.PcName);
+ CopyRows = new CopySettingsRows(_s, Save);
// ---- Workspace ----
WorkspaceRows = new WorkspaceSettingsRows(_s, Save, () => AppEnvironment.Shown(Shell.Services.Workspace.Root), OpenWorkspaceFolder, ChangeWorkspaceFolderAsync,
@@ -838,6 +839,9 @@ public sealed class SettingsViewModel : SectionViewModel
/// Settings › Server › Sharing: this PC's library shared to the LAN (owner review 5, #67).
public ShareSettingsRows ShareRows { get; }
+ /// Settings › Server › Link matches, Integrate photos, Integrate projects (owner review 6, #73).
+ public CopySettingsRows CopyRows { get; }
+
public ICommand OpenDataFolderCommand { get; }
public ICommand OpenLogsCommand { get; }
public ICommand ExportDiagnosticsCommand { get; }
@@ -1278,7 +1282,7 @@ public sealed class SettingsViewModel : SectionViewModel
JobKind.Render, JobKind.Import, JobKind.Download, JobKind.UploadCommit, JobKind.Scan, JobKind.Rebuild, JobKind.Verify, JobKind.LightAnalyse,
JobKind.DeepAnalyse, JobKind.Thumbs, JobKind.Proxies, JobKind.Maintenance, JobKind.Duplicates, JobKind.Orphans, JobKind.Adopt, JobKind.Move,
JobKind.Backup, JobKind.Cleanup, JobKind.EmptyTrash, JobKind.Convert, JobKind.WorkspaceCopy, JobKind.WorkspaceRender, JobKind.WorkspaceSend,
- JobKind.WorkspaceMove, JobKind.VideoCopy,
+ JobKind.WorkspaceMove, JobKind.VideoCopy, JobKind.Integrate, JobKind.MergeSequences,
];
/// Stores for , keeping only the levels that differ from the defaults.
@@ -1675,6 +1679,7 @@ public sealed class SettingsViewModel : SectionViewModel
case SettingsPage.Server:
_s.RenderNodeOptIn = defaults.RenderNodeOptIn;
ShareRows.Reset();
+ CopyRows.Reset();
break;
case SettingsPage.Updates:
_s.CheckForUpdates = defaults.CheckForUpdates;
@@ -1783,6 +1788,7 @@ public sealed class SettingsViewModel : SectionViewModel
Logs.Refresh();
WorkspaceRows.Refresh();
ShareRows.Refresh();
+ CopyRows.Refresh();
UpdatePreview();
LoadCertificates();
OnAllPropertiesChanged();
@@ -1902,6 +1908,7 @@ public sealed class SettingsViewModel : SectionViewModel
foreach (var row in MissingExtensions) row.Refresh();
Logs.Refresh();
WorkspaceRows.Refresh();
+ CopyRows.Refresh();
ArchiveRoot.Refresh();
FolderTemplate.Refresh();
FileTemplate.Refresh();
diff --git a/src/Chronos.App/Server/Copies/CopyDetailRow.cs b/src/Chronos.App/Server/Copies/CopyDetailRow.cs
new file mode 100644
index 00000000..685e6fc7
--- /dev/null
+++ b/src/Chronos.App/Server/Copies/CopyDetailRow.cs
@@ -0,0 +1,59 @@
+using Chronos.Core.Localization;
+using Chronos.Data.Copies;
+using Chronos.Ui.Mvvm;
+
+namespace Chronos.App.Server.Copies;
+
+///
+/// A detail that differs (the Details part): its label, this PC's and the other side's value, and the side both take
+/// (nothing preselected: -1 until the user picks).
+///
+public sealed class CopyDetailRow(DetailLine line, bool isMerge, Action changed) : ObservableObject
+{
+ private int _choiceIndex = -1;
+
+ public DetailLine Line { get; } = line;
+ public string Path => Line.Path;
+ public string Label => SyncText.DetailLabel(Line.Path);
+ public string HereText => Value(Line.Here);
+ public string ThereText => Value(Line.There);
+ public string HereToolTip => Line.Here ?? Loc.L("Server.Sync.None");
+ public string ThereToolTip => Line.There ?? Loc.L("Server.Sync.None");
+
+ public string HereWord => Loc.L(isMerge ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.ThisPc");
+ public string ThereWord => Loc.L(isMerge ? "Server.Copies.Detail.Other" : "Server.Copies.Detail.Server");
+
+ /// "Deflicker window: This PC/Server": the line's one tab stop.
+ public string AccessibleName => Loc.L("Server.Copies.ControlFor", Label, HereWord + "/" + ThereWord);
+
+ public string ToolTip => Loc.L("Tooltips.Server.Copies.Detail");
+
+ /// 0 this PC (or the kept one), 1 the other side, -1 not chosen.
+ public int ChoiceIndex
+ {
+ get => _choiceIndex;
+ set
+ {
+ if (!Set(ref _choiceIndex, value)) return;
+ OnPropertyChanged(nameof(Chosen));
+ changed();
+ }
+ }
+
+ public CopySide? Chosen => _choiceIndex switch
+ {
+ 0 => CopySide.ThisPc,
+ 1 => CopySide.Other,
+ _ => null,
+ };
+
+ internal void SetQuietly(int index)
+ {
+ _choiceIndex = index;
+ OnPropertyChanged(nameof(ChoiceIndex));
+ OnPropertyChanged(nameof(Chosen));
+ }
+
+ private static string Value(string? value) => string.IsNullOrWhiteSpace(value) ? Loc.L("Server.Sync.None")
+ : value.Length <= 40 ? value : string.Concat(value.AsSpan(0, 39), "…");
+}
diff --git a/src/Chronos.App/Server/Copies/CopyDialogViewModel.cs b/src/Chronos.App/Server/Copies/CopyDialogViewModel.cs
new file mode 100644
index 00000000..fce69ab3
--- /dev/null
+++ b/src/Chronos.App/Server/Copies/CopyDialogViewModel.cs
@@ -0,0 +1,801 @@
+using System.Windows.Input;
+using Chronos.App.Archiving;
+using Chronos.App.Infrastructure;
+using Chronos.App.Settings;
+using Chronos.App.Shell;
+using Chronos.Core.Localization;
+using Chronos.Data.Copies;
+using Chronos.Data.Sync;
+using Chronos.Ui.Mvvm;
+
+namespace Chronos.App.Server.Copies;
+
+/// The four parts of the Compare dialog, in the order of its SegmentedControl.
+public enum CopyDialogPart
+{
+ Photos,
+ Details,
+ Projects,
+ Plan,
+}
+
+///
+/// Compare sequences / Merge sequences (owner review 6, #73, design §8.2): both sides of a pair, photo by photo (classes and
+/// the photos of one, with per-photo choices under Choose each), detail by detail (nothing preselected), projects (copied
+/// across or left), and the plan the engine computes from those choices (debounced 300 ms) with its blocks and their one
+/// action. Two footer buttons: Cancel and Integrate (Merge); a destructive plan confirms first, then the job is queued
+/// and the dialog closes. UI thread.
+///
+public sealed class CopyDialogViewModel : ArchiveDialogViewModel
+{
+ /// How long a choice waits before the plan is computed again.
+ internal static TimeSpan PlanDelay { get; set; } = TimeSpan.FromMilliseconds(300);
+
+ private readonly ShellViewModel _shell;
+ private readonly ICopyEngine _engine;
+ private readonly FoundCopyView _pair;
+ private readonly CopyRights _rights;
+ private readonly bool _integrate;
+ private readonly PhotoClass? _startClass;
+ private readonly Dictionary _perPhoto = [];
+ private readonly AsyncRelayCommand _apply;
+ private readonly AsyncRelayCommand _linkOnly;
+ private readonly AsyncRelayCommand _trash;
+ private readonly AsyncRelayCommand _deleteThere;
+ private CancellationTokenSource? _planning;
+ private CopyReview? _review;
+ private IntegratePlan? _plan;
+ private MergePlan? _merge;
+ private CopyDialogPart _part;
+ private SettingsOption _policy;
+ private int _projectsIndex;
+ private Guid? _keepId;
+ private CopyClassRow? _class;
+ private IReadOnlyList _classes = [];
+ private IReadOnlyList _photos = [];
+ private IReadOnlyList _details = [];
+ private IReadOnlyList _hereProjects = [];
+ private IReadOnlyList _thereProjects = [];
+ private IReadOnlyList _keep = [];
+ private IReadOnlyList _hereLines = [];
+ private IReadOnlyList _thereLines = [];
+ private IReadOnlyList _blocks = [];
+ private bool _isPlanning;
+ private bool _isLoaded;
+
+ public CopyDialogViewModel(ShellViewModel shell, ICopyEngine engine, FoundCopyView pair, CopyRights rights, CopyDialogPart part,
+ PhotoClass? photos, bool integrate, Action close)
+ : base(close)
+ {
+ _shell = shell;
+ _engine = engine;
+ _pair = pair;
+ _rights = rights;
+ _part = part;
+ _startClass = photos;
+ _integrate = integrate;
+ Policies = PolicyOptions(IsMerge);
+ var wanted = shell.Services.Settings.CopyPhotos;
+ _policy = Policies.FirstOrDefault(o => o.Value == wanted) ?? Policies[0];
+ _projectsIndex = !IsMerge && shell.Services.Settings.CopyProjects == CopyProjects.Leave ? 1 : 0;
+ _apply = new AsyncRelayCommand(ApplyAsync, () => _isLoaded && !IsBusy && !_isPlanning && (_part != CopyDialogPart.Plan || CanApplyPlan));
+ _linkOnly = new AsyncRelayCommand(LinkOnlyAsync, () => _isLoaded && !IsBusy && ShowLinkOnly);
+ _trash = new AsyncRelayCommand(() => TrashHereAsync([.. _photos.Where(p => p.IsSelected).Select(p => p.Key)]),
+ () => !IsBusy && _photos.Any(p => p.IsSelected));
+ _deleteThere = new AsyncRelayCommand(() => TrashThereAsync([.. _photos.Where(p => p.IsSelected).Select(p => p.Key)]),
+ () => !IsBusy && _photos.Any(p => p.IsSelected));
+ BringAllCommand = new RelayCommand(() => SetAll(bring: true));
+ BringNoneCommand = new RelayCommand(() => SetAll(bring: false));
+ AllBothCommand = new RelayCommand(() => SetAll(bring: true, choice: PhotoChoice.KeepBoth));
+ AllHereCommand = new RelayCommand(() => SetDetails(0));
+ AllThereCommand = new RelayCommand(() => SetDetails(1));
+ }
+
+ public FoundCopy Copy => _pair.Copy;
+ public bool IsMerge => Copy.Kind == CopyKind.LocalLocal;
+
+ public string Heading => Loc.L(IsMerge ? "Server.Copies.Dialog.Merge" : "Server.Copies.Dialog.Compare");
+
+ /// "This PC · Lighthouse · 1,204 photos · 18.2 GB".
+ public string HereText => Loc.L("Server.Copies.Where.ThisPc", CopyText.Facts(Here));
+
+ public string ThereText => IsMerge ? Loc.L("Server.Copies.Where.ThisPc", CopyText.Facts(There)) : CopyText.Facts(There);
+
+ private CopyFacts Here => _review?.Here ?? _pair.Here;
+ private CopyFacts There => _review?.There ?? _pair.There;
+ private string ServerName => _rights.ServerName ?? Copy.Server ?? There.Where;
+
+ public bool IsLoaded { get => _isLoaded; private set => Set(ref _isLoaded, value); }
+
+ public CopyReview? Review => _review;
+
+ // ---- Parts ----
+
+ public CopyDialogPart Part
+ {
+ get => _part;
+ set
+ {
+ if (!Set(ref _part, value)) return;
+ OnPropertyChanged(nameof(PartIndex));
+ OnPropertyChanged(nameof(IsPhotos));
+ OnPropertyChanged(nameof(IsDetails));
+ OnPropertyChanged(nameof(IsProjects));
+ OnPropertyChanged(nameof(IsPlan));
+ OnPropertyChanged(nameof(ApplyToolTip));
+ if (value == CopyDialogPart.Plan) SchedulePlan(TimeSpan.Zero);
+ _apply.RaiseCanExecuteChanged();
+ }
+ }
+
+ public int PartIndex
+ {
+ get => (int)_part;
+ set
+ {
+ if (value is >= 0 and <= 3) Part = (CopyDialogPart)value;
+ }
+ }
+
+ public bool IsPhotos => _part == CopyDialogPart.Photos;
+ public bool IsDetails => _part == CopyDialogPart.Details;
+ public bool IsProjects => _part == CopyDialogPart.Projects;
+ public bool IsPlan => _part == CopyDialogPart.Plan;
+
+ // ---- Photos ----
+
+ public IReadOnlyList> Policies { get; }
+
+ public SettingsOption Policy
+ {
+ get => _policy;
+ set
+ {
+ if (value is null || !Set(ref _policy, value)) return;
+ OnPropertyChanged(nameof(PolicyToolTip));
+ OnPropertyChanged(nameof(IsChoosing));
+ BuildPhotos();
+ Changed();
+ }
+ }
+
+ public string PolicyToolTip => string.Join(Environment.NewLine, Loc.L("Tooltips.Server.Copies.Policy"), _policy.ToolTip);
+
+ /// Choose each: the photo lists take ticks and version choices.
+ public bool IsChoosing => _policy.Value == CopyPhotoPolicy.ChoosePerPhoto;
+
+ public IReadOnlyList Classes { get => _classes; private set => Set(ref _classes, value); }
+
+ public CopyClassRow? SelectedClass
+ {
+ get => _class;
+ set
+ {
+ if (!Set(ref _class, value)) return;
+ BuildPhotos();
+ }
+ }
+
+ public IReadOnlyList Photos { get => _photos; private set => Set(ref _photos, value); }
+
+ public bool HasPhotos => _photos.Count > 0;
+
+ /// "No photos differ.": the selected class holds nothing (or the two sides hold the same photos).
+ public string? PhotosEmptyText => HasPhotos ? null : Loc.L("Server.Copies.Class.None");
+
+ public bool CanBringAll => _photos.Any(p => p.CanBring);
+ public bool CanKeepAllBoth => _photos.Any(p => p.CanChoose);
+ public bool CanTrashHere => _class?.Class == PhotoClass.DeletedThere && _photos.Count > 0;
+ public bool CanDeleteThere => !IsMerge && _class?.Class == PhotoClass.DeletedHere && _photos.Count > 0 && _review?.Can.DeleteThere == true;
+
+ public ICommand BringAllCommand { get; }
+ public ICommand BringNoneCommand { get; }
+ public ICommand AllBothCommand { get; }
+ public ICommand TrashCommand => _trash;
+ public ICommand DeleteThereCommand => _deleteThere;
+
+ // ---- Details ----
+
+ public IReadOnlyList Details { get => _details; private set => Set(ref _details, value); }
+ public bool HasDetails => _details.Count > 0;
+ public string? DetailsEmptyText => HasDetails ? null : Loc.L("Server.Copies.Detail.None");
+ public int Unchosen => _details.Count(d => d.Chosen is null);
+ public ICommand AllHereCommand { get; }
+ public ICommand AllThereCommand { get; }
+ public string AllHereText => Loc.L("Server.Copies.Detail.AllThisPc");
+ public string AllThereText => Loc.L("Server.Copies.Detail.AllServer");
+
+ // ---- Projects ----
+
+ /// 0 Copy across, 1 Leave them (a merge always copies: its other home goes to the trash).
+ public int ProjectsIndex
+ {
+ get => _projectsIndex;
+ set
+ {
+ if (IsMerge || value is < 0 or > 1 || !Set(ref _projectsIndex, value)) return;
+ OnPropertyChanged(nameof(ProjectsToolTip));
+ Changed();
+ }
+ }
+
+ public bool CanChooseProjects => !IsMerge && _review?.Projects.ThereKeepsProjects != false;
+
+ public string ProjectsToolTip => IsMerge ? Loc.L("Tooltips.Server.Copies.Projects.MergeAlways")
+ : Loc.L(_projectsIndex == 0 ? "Tooltips.Server.Copies.Projects.CopyAcross" : "Tooltips.Server.Copies.Projects.Leave");
+
+ public IReadOnlyList HereProjects { get => _hereProjects; private set => Set(ref _hereProjects, value); }
+ public IReadOnlyList ThereProjects { get => _thereProjects; private set => Set(ref _thereProjects, value); }
+
+ /// "nas keeps no projects: they stay." or "No other projects."; null when there are projects to show.
+ public string? ProjectsNote => _review is not { } review ? null
+ : !review.Projects.ThereKeepsProjects ? Loc.L("Server.Copies.Projects.NoneThere", ServerName)
+ : _hereProjects.Count + _thereProjects.Count == 0 ? Loc.L("Server.Copies.Projects.None")
+ : null;
+
+ // ---- Plan ----
+
+ public IReadOnlyList KeepOptions { get => _keep; private set => Set(ref _keep, value); }
+ public bool HasKeepOptions => _keep.Count > 0;
+ public IReadOnlyList HereLines { get => _hereLines; private set => Set(ref _hereLines, value); }
+ public IReadOnlyList ThereLines { get => _thereLines; private set => Set(ref _thereLines, value); }
+ public IReadOnlyList Blocks { get => _blocks; private set => Set(ref _blocks, value); }
+
+ /// "On this PC", or for a merge "Into {kept}".
+ public string HereHeading => IsMerge ? Loc.L("Server.Copies.Plan.Into", KeptFacts?.Where ?? Loc.L("Server.Copies.Plan.KeptCopy"))
+ : Loc.L("Server.Copies.Plan.OnThisPc");
+
+ public string ThereHeading => IsMerge ? DroppedFacts?.Where ?? There.Where : Loc.L("Server.Copies.Plan.OnServer", ServerName);
+
+ public bool IsPlanning
+ {
+ get => _isPlanning;
+ private set
+ {
+ if (!Set(ref _isPlanning, value)) return;
+ OnPropertyChanged(nameof(PlanningText));
+ _apply.RaiseCanExecuteChanged();
+ }
+ }
+
+ public string? PlanningText => _isPlanning ? Loc.L("Server.Copies.Planning") : null;
+
+ public IntegratePlan? Plan => _plan;
+ public MergePlan? MergePlan => _merge;
+
+ private bool CanApplyPlan => IsMerge ? _merge?.CanApply == true : _plan?.CanApply == true;
+
+ /// Link only: a pair with a server not linked yet; links the two without moving photos.
+ public bool ShowLinkOnly => !IsMerge && Copy.State == CopyState.Candidate && _review?.Can.LinkOnly == true;
+
+ public ICommand LinkOnlyCommand => _linkOnly;
+ public string LinkOnlyText => Loc.L("Server.Copies.Action.LinkOnly");
+ public string LinkOnlyToolTip => Loc.L("Tooltips.Server.Copies.LinkOnly");
+
+ // ---- Footer ----
+
+ public ICommand ApplyCommand => _apply;
+ public string ApplyText => Loc.L(IsMerge ? "Server.Copies.Action.Merge" : "Server.Copies.Action.IntegrateNow");
+
+ /// What Integrate (Merge) does, or the first reason it cannot.
+ public string ApplyToolTip => _part == CopyDialogPart.Plan && _blocks.Count > 0 ? _blocks[0].Text
+ : Loc.L(IsMerge ? "Tooltips.Server.Copies.Merge" : "Tooltips.Server.Copies.Integrate");
+
+ public string CancelToolTip => Loc.L("Tooltips.Server.Copies.Cancel");
+
+ /// Reads both sides, then opens on the part asked for (Integrate…: Details while any line is unchosen, else Plan).
+ public async Task LoadAsync()
+ {
+ IsLoaded = false;
+ BusyText = Loc.L("Server.Copies.Planning");
+ try
+ {
+ _review = await _engine.CompareAsync(Copy.Id, Copy.Kind == CopyKind.LocalServer ? _shell.Services.Sync.Remote : null, CancellationToken.None);
+ if (IsClosed) return;
+ Build(_review);
+ IsLoaded = true;
+ if (_integrate && _part == CopyDialogPart.Plan && Unchosen > 0) _part = CopyDialogPart.Details;
+ OnAllPropertiesChanged();
+ if (_part == CopyDialogPart.Plan) SchedulePlan(TimeSpan.Zero);
+ }
+ catch (Exception ex) when (Expected(ex))
+ {
+ ShowError(ex);
+ }
+ finally
+ {
+ BusyText = null;
+ _apply.RaiseCanExecuteChanged();
+ _linkOnly.RaiseCanExecuteChanged();
+ }
+ }
+
+ /// Computes the plan of the current choices now (tests, captures).
+ internal async Task PlanNowAsync()
+ {
+ _planning?.Cancel();
+ await PlanAsync(CancellationToken.None);
+ }
+
+ public override void Dispose()
+ {
+ _planning?.Cancel();
+ base.Dispose();
+ }
+
+ protected override void OnLanguageChanged()
+ {
+ if (_review is { } review) Build(review);
+ BuildPlanLines();
+ base.OnLanguageChanged();
+ }
+
+ private void Build(CopyReview review)
+ {
+ Classes = [.. review.Photos.Totals.Where(t => t.Count > 0).Select(t => new CopyClassRow(t))];
+ _class = _classes.FirstOrDefault(c => c.Class == _startClass)
+ ?? _classes.FirstOrDefault(c => c.Class is not (PhotoClass.Same or PhotoClass.Converted))
+ ?? _classes.FirstOrDefault();
+ BuildPhotos();
+ var chosen = _details.ToDictionary(d => d.Path, d => d.ChoiceIndex);
+ Details = [.. review.Details.Select(line => new CopyDetailRow(line, IsMerge, Changed))];
+ foreach (var row in _details) row.SetQuietly(chosen.GetValueOrDefault(row.Path, -1));
+ HereProjects = [.. review.Projects.Here.Select(p => new CopyProjectRow(p))];
+ ThereProjects = [.. review.Projects.There.Select(p => new CopyProjectRow(p))];
+ if (IsMerge)
+ {
+ KeepOptions = [new CopyKeepOption(Copy.LocalId, review.Here, Keep), new CopyKeepOption(Copy.OtherId ?? Guid.Empty, review.There, Keep)];
+ foreach (var option in _keep) option.SetQuietly(option.SequenceId == _keepId);
+ }
+ }
+
+ private void BuildPhotos()
+ {
+ var review = _review;
+ var cls = _class?.Class;
+ var choosing = IsChoosing;
+ var choices = VersionChoices(IsMerge);
+ Func? drop = cls == PhotoClass.Versions ? DropAsync : null;
+ Photos = review is null || cls is null ? []
+ : [.. review.Photos.Of(cls.Value).Select(p => new CopyPhotoRow(p, IsMerge,
+ choosing && !IsMerge && cls is PhotoClass.OnlyHere or PhotoClass.OnlyThere,
+ choosing && cls == PhotoClass.Differs, choices, _perPhoto.TryGetValue(p.Key, out var c) ? c : null, () => OnPhotoChanged(p.Key), drop))];
+ foreach (var row in _photos) row.PropertyChanged += (_, e) =>
+ {
+ if (e.PropertyName != nameof(CopyPhotoRow.IsSelected)) return;
+ _trash.RaiseCanExecuteChanged();
+ _deleteThere.RaiseCanExecuteChanged();
+ };
+ OnPropertyChanged(nameof(HasPhotos));
+ OnPropertyChanged(nameof(PhotosEmptyText));
+ OnPropertyChanged(nameof(CanBringAll));
+ OnPropertyChanged(nameof(CanKeepAllBoth));
+ OnPropertyChanged(nameof(CanTrashHere));
+ OnPropertyChanged(nameof(CanDeleteThere));
+ OnPropertyChanged(nameof(SelectedClass));
+ }
+
+ private void OnPhotoChanged(string key)
+ {
+ if (_photos.FirstOrDefault(p => p.Key == key)?.Chosen is { } chosen) _perPhoto[key] = chosen;
+ else _perPhoto.Remove(key);
+ Changed();
+ }
+
+ private void SetAll(bool bring, PhotoChoice? choice = null)
+ {
+ foreach (var row in _photos)
+ {
+ if (row.CanBring) row.SetQuietly(bring, null);
+ else if (row.CanChoose && choice is { } c) row.SetQuietly(false, row.Choices.FirstOrDefault(o => o.Value == c));
+ else continue;
+ if (row.Chosen is { } chosen) _perPhoto[row.Key] = chosen;
+ else _perPhoto.Remove(row.Key);
+ }
+ Changed();
+ }
+
+ private void SetDetails(int index)
+ {
+ foreach (var row in _details) row.SetQuietly(index);
+ Changed();
+ }
+
+ private void Keep(CopyKeepOption option)
+ {
+ _keepId = option.SequenceId;
+ foreach (var other in _keep.Where(o => !ReferenceEquals(o, option))) other.SetQuietly(false);
+ OnPropertyChanged(nameof(HereHeading));
+ OnPropertyChanged(nameof(ThereHeading));
+ Changed();
+ }
+
+ /// A choice changed: the plan follows once the user pauses.
+ private void Changed()
+ {
+ OnPropertyChanged(nameof(Unchosen));
+ if (_plan is not null || _merge is not null || _part == CopyDialogPart.Plan) SchedulePlan(PlanDelay);
+ }
+
+ private void SchedulePlan(TimeSpan delay)
+ {
+ if (!_isLoaded) return;
+ _planning?.Cancel();
+ var run = _planning = new CancellationTokenSource();
+ _ = Delayed();
+
+ async Task Delayed()
+ {
+ try
+ {
+ if (delay > TimeSpan.Zero) await Task.Delay(delay, run.Token);
+ await PlanAsync(run.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ // A newer choice planned instead.
+ }
+ }
+ }
+
+ private IntegrateChoices IntegrateChoices() => new(_policy.Value, IsChoosing ? new Dictionary(_perPhoto) : new Dictionary(),
+ DetailChoices(), _projectsIndex == 0 ? CopyProjects.CopyAcross : CopyProjects.Leave);
+
+ private MergeChoices MergeChoices() => new(_policy.Value, IsChoosing ? new Dictionary(_perPhoto) : new Dictionary(),
+ DetailChoices());
+
+ private Dictionary DetailChoices() =>
+ _details.Where(d => d.Chosen is not null).ToDictionary(d => d.Path, d => d.Chosen!.Value, StringComparer.Ordinal);
+
+ private async Task PlanAsync(CancellationToken ct)
+ {
+ IsPlanning = true;
+ ClearError();
+ try
+ {
+ if (IsMerge)
+ {
+ var merge = await _engine.PlanMergeAsync(Copy.Id, _keepId, MergeChoices(), ct);
+ ct.ThrowIfCancellationRequested();
+ _merge = merge;
+ if (_keepId is null && !merge.Blocks.Contains(CopyBlock.KeptUnchosen) && merge.KeepId != Guid.Empty)
+ {
+ _keepId = merge.KeepId;
+ foreach (var option in _keep) option.SetQuietly(option.SequenceId == _keepId);
+ }
+ }
+ else if (_shell.Services.Sync.Remote is { } remote && string.Equals(_shell.Services.Sync.Server, Copy.Server, StringComparison.OrdinalIgnoreCase))
+ {
+ var plan = await _engine.PlanIntegrateAsync(Copy.Id, remote, IntegrateChoices(), ct);
+ ct.ThrowIfCancellationRequested();
+ _plan = plan;
+ }
+ else
+ {
+ _plan = null;
+ ShowMessage(Loc.L("Tooltips.Server.Copies.SignIn", Copy.Server ?? string.Empty));
+ }
+ BuildPlanLines();
+ }
+ catch (OperationCanceledException)
+ {
+ throw;
+ }
+ catch (Exception ex) when (Expected(ex))
+ {
+ ShowError(ex);
+ }
+ finally
+ {
+ if (!ct.IsCancellationRequested) IsPlanning = false;
+ }
+ }
+
+ private CopyFacts? KeptFacts => _keepId is { } keep ? keep == Copy.LocalId ? Here : There : null;
+ private CopyFacts? DroppedFacts => _keepId is { } keep ? keep == Copy.LocalId ? There : Here : null;
+
+ /// The lines of the Plan part, last copies first; the blocks with their one action.
+ private void BuildPlanLines()
+ {
+ var here = new List();
+ var there = new List();
+ var blocks = new List();
+ if (_plan is { } plan)
+ {
+ Lasts(plan.LastCopies, here, there);
+ Photos(plan.Photos, PhotoAction.Fetch, PhotoAction.FetchVersion, "Server.Copies.Plan.Receives", here);
+ Photos(plan.Photos, PhotoAction.Send, PhotoAction.SendVersion, "Server.Copies.Plan.Receives", there);
+ Trash(plan.Photos, PhotoAction.TrashHere, here);
+ Trash(plan.Photos, PhotoAction.TrashThere, there);
+ var versions = plan.Photos.Count(p => p.Action == PhotoAction.SendVersion);
+ if (versions > 0) there.Add(new(Loc.Plural("Server.Copies.Plan.ServerUsesOurs", versions, ServerName), Loc.L("Tooltips.Server.Copies.Plan.ServerUsesOurs")));
+ if (plan.DetailChanges > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Details", plan.DetailChanges)));
+ var fromHere = plan.Projects.Count(p => p.From == CopySide.ThisPc);
+ var fromThere = plan.Projects.Count - fromHere;
+ if (fromThere > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Projects", fromThere)));
+ if (fromHere > 0) there.Add(new(Loc.Plural("Server.Copies.Plan.Projects", fromHere)));
+ here.Add(new(Loc.L("Server.Copies.Plan.Free", Formatting.Bytes(plan.FreeBytes)), Loc.L("Tooltips.Server.Copies.Plan.Free")));
+ if (plan.QuotaLeftBytes is { } quota) there.Add(new(Loc.L("Server.Copies.Plan.Quota", Formatting.Bytes(quota)), Loc.L("Tooltips.Server.Copies.Plan.Quota")));
+ if (plan.LeftOut > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.LeftOut", plan.LeftOut), Loc.L("Tooltips.Server.Copies.Plan.LeftOut")));
+ foreach (var row in _hereProjects.Concat(_thereProjects))
+ row.SetTarget(plan.Projects.FirstOrDefault(p => p.SourceProjectId == row.Project.Id)?.TargetName);
+ blocks.AddRange(plan.Blocks.Select(Block));
+ }
+ else if (_merge is { } merge)
+ {
+ Lasts(merge.LastCopies, here, there);
+ Photos(merge.Photos, PhotoAction.Fetch, PhotoAction.FetchVersion, "Server.Copies.Plan.Receives", here);
+ if (merge.DetailChanges > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Details", merge.DetailChanges)));
+ if (merge.Renders.Count > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Renders", merge.Renders.Count)));
+ if (merge.Projects.Count > 0) here.Add(new(Loc.Plural("Server.Copies.Plan.Projects", merge.Projects.Count)));
+ if (merge.SessionKeys.Count > 0)
+ here.Add(new(Loc.L("Server.Copies.Plan.SessionKeys", Formatting.Count(merge.SessionKeys.Count)),
+ string.Join(Environment.NewLine, [Loc.L("Tooltips.Server.Copies.Plan.SessionKeys"), .. merge.SkippedSessionKeys])));
+ foreach (var link in merge.Links) here.Add(new(Loc.L("Server.Copies.Plan.Relink", link), Loc.L("Tooltips.Server.Copies.Plan.Relink")));
+ here.Add(new(Loc.L("Server.Copies.Plan.Free", Formatting.Bytes(merge.FreeBytes)), Loc.L("Tooltips.Server.Copies.Plan.Free")));
+ if (DroppedFacts is { } dropped)
+ there.Add(new(Loc.Plural("Server.Copies.Plan.DropToTrash", dropped.Photos, Formatting.Bytes(dropped.Bytes)), IsWarning: true));
+ blocks.AddRange(merge.Blocks.Select(Block));
+ }
+ if (here.Count + there.Count == 0 && blocks.Count == 0 && (_plan ?? (object?)_merge) is not null) here.Add(new(Loc.L("Server.Copies.Plan.Nothing")));
+ HereLines = here;
+ ThereLines = there;
+ Blocks = blocks;
+ OnPropertyChanged(nameof(HereHeading));
+ OnPropertyChanged(nameof(ThereHeading));
+ OnPropertyChanged(nameof(ApplyToolTip));
+ _apply.RaiseCanExecuteChanged();
+
+ void Lasts(IReadOnlyList lasts, List h, List t)
+ {
+ var mine = lasts.Count(l => l.Side == CopySide.ThisPc);
+ var theirs = lasts.Count - mine;
+ if (mine > 0) h.Add(new(Loc.Plural("Server.Copies.Plan.LastCopies", mine), Loc.L("Tooltips.Server.Copies.Plan.LastCopies"), true));
+ if (theirs > 0) t.Add(new(Loc.Plural("Server.Copies.Plan.LastCopies", theirs), Loc.L("Tooltips.Server.Copies.Plan.LastCopies"), true));
+ }
+
+ static void Photos(IReadOnlyList steps, PhotoAction a, PhotoAction b, string key, List lines)
+ {
+ var moving = steps.Where(s => s.Action == a || s.Action == b).ToList();
+ if (moving.Count > 0) lines.Add(new(Loc.Plural(key, moving.Count, Formatting.Bytes(moving.Sum(s => s.Bytes)))));
+ var kept = steps.Count(s => s.Action == b);
+ if (kept > 0) lines.Add(new(Loc.Plural("Server.Copies.Plan.Versions", kept)));
+ }
+
+ static void Trash(IReadOnlyList steps, PhotoAction a, List lines)
+ {
+ var n = steps.Count(s => s.Action == a);
+ if (n > 0) lines.Add(new(Loc.Plural("Server.Copies.Plan.Trash", n), IsWarning: true));
+ }
+ }
+
+ private CopyBlockLine Block(CopyBlock block)
+ {
+ var need = _plan is { } plan ? Formatting.Bytes(plan.FetchBytes) : _merge is { } merge ? Formatting.Bytes(merge.CopyBytes) : null;
+ var text = CopyText.Block(block, Here.Title, ServerName, need, Unchosen);
+ Action? choose = block switch
+ {
+ CopyBlock.DetailsUnchosen => () => Part = CopyDialogPart.Details,
+ CopyBlock.KeptUnchosen => () => Part = CopyDialogPart.Plan,
+ _ => null,
+ };
+ return new CopyBlockLine(block, text, choose);
+ }
+
+ /// Integrate (Merge): from another part, on to the part still waiting for a choice; on the plan, confirm and queue.
+ private async Task ApplyAsync()
+ {
+ if (_part != CopyDialogPart.Plan)
+ {
+ Part = Unchosen > 0 && _part != CopyDialogPart.Details ? CopyDialogPart.Details : CopyDialogPart.Plan;
+ return;
+ }
+ if (_shell.Services.Engine is not { } jobs) return;
+ try
+ {
+ if (_plan is { CanApply: true } plan)
+ {
+ if (plan.Destructive && !_shell.Services.Dialogs.Confirm(ReplaceRequest(plan))) return;
+ IsBusy = true;
+ await _engine.EnqueueIntegrateAsync(jobs, plan, CancellationToken.None);
+ }
+ else if (_merge is { CanApply: true } merge)
+ {
+ if (!_shell.Services.Dialogs.Confirm(MergeRequest(merge))) return;
+ IsBusy = true;
+ await _engine.EnqueueMergeAsync(jobs, merge, CancellationToken.None);
+ }
+ else
+ {
+ return;
+ }
+ Close();
+ }
+ catch (StaleCopyPlanException ex)
+ {
+ ShowMessage(ex.Message);
+ SchedulePlan(TimeSpan.Zero);
+ }
+ catch (Exception ex) when (Expected(ex))
+ {
+ ShowError(ex);
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ }
+
+ private async Task LinkOnlyAsync()
+ {
+ if (_shell.Services.Sync.Remote is not { } remote) return;
+ IsBusy = true;
+ try
+ {
+ await _engine.LinkAsync(Copy.Id, remote, CancellationToken.None);
+ Close();
+ }
+ catch (Exception ex) when (Expected(ex))
+ {
+ ShowError(ex);
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ }
+
+ /// Drop…: this version of a Two versions photo goes to the trash of each side that holds it, after a confirmed plan.
+ private async Task DropAsync(CopyPhotoRow row)
+ {
+ if (row.Photo.Here is not null) await TrashHereAsync([row.Key]);
+ if (row.Photo.There is not null && !IsMerge) await TrashThereAsync([row.Key]);
+ }
+
+ /// To trash…: the dry run of moving these photos of this PC's copy to its archive trash, the confirmation, then the move.
+ private async Task TrashHereAsync(IReadOnlyCollection keys)
+ {
+ if (keys.Count == 0) return;
+ IsBusy = true;
+ try
+ {
+ var plan = await _engine.PlanTrashHereAsync(Copy.Id, keys, CancellationToken.None);
+ if (plan.Frames.Count == 0)
+ {
+ ShowMessage(Loc.L("Errors.Copies.NotThere"));
+ return;
+ }
+ var request = TrashRequest(plan.Frames.Count, plan.Frames.Select(f => f.FileName), Loc.L("Tooltips.Server.Copies.ToTrash"), []);
+ if (!_shell.Services.Dialogs.Confirm(request)) return;
+ await _engine.TrashHereAsync(Copy.Id, plan, Copy.Kind == CopyKind.LocalServer ? _shell.Services.Sync.Remote : null, CancellationToken.None);
+ }
+ catch (Exception ex) when (Expected(ex))
+ {
+ ShowError(ex);
+ return;
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ await LoadAsync();
+ }
+
+ /// Delete on server…: the server's dry run, the confirmation, then the move to the server's trash.
+ private async Task TrashThereAsync(IReadOnlyCollection keys)
+ {
+ if (keys.Count == 0 || _shell.Services.Sync.Remote is not { } remote) return;
+ IsBusy = true;
+ try
+ {
+ var plan = await _engine.PlanTrashThereAsync(Copy.Id, remote, keys, CancellationToken.None);
+ if (plan.Photos == 0)
+ {
+ ShowMessage(Loc.L("Errors.Copies.NotThere"));
+ return;
+ }
+ var names = _review?.Photos.Photos.Where(p => plan.Keys.Contains(p.Key)).Select(p => (p.There ?? p.Here)?.FileName ?? p.Key) ?? plan.Keys;
+ var request = TrashRequest(plan.Photos, names, Loc.L("Tooltips.Server.Copies.DeleteOnServer"), plan.LastCopies);
+ if (!_shell.Services.Dialogs.Confirm(request)) return;
+ await _engine.TrashThereAsync(plan, remote, CancellationToken.None);
+ }
+ catch (Exception ex) when (Expected(ex))
+ {
+ ShowError(ex);
+ return;
+ }
+ finally
+ {
+ IsBusy = false;
+ }
+ await LoadAsync();
+ }
+
+ /// "Replace photos?" (design §8.5): the losing versions per side, the last copies named first.
+ internal static ConfirmRequest ReplaceRequest(IntegratePlan plan)
+ {
+ var trashed = plan.Photos.Where(p => p.Action is PhotoAction.TrashHere or PhotoAction.TrashThere).ToList();
+ return new ConfirmRequest
+ {
+ Heading = Loc.L("Server.Copies.Confirm.Replace.Title"),
+ Message = Loc.Plural("Server.Copies.Confirm.Replace.Message", trashed.Count),
+ Detail = Lines(plan.LastCopies, trashed.Select(p => p.FileName)),
+ SafeText = Loc.L("Archive.Dialog.Cancel"),
+ SafeToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Safe"),
+ ActionText = Loc.L("Server.Copies.Action.IntegrateNow"),
+ ActionToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Replace.Action"),
+ IsDestructive = true,
+ };
+ }
+
+ /// "Merge sequences?" (design §8.5): the dropped sequence's facts, the last copies first, the typed photo count.
+ internal ConfirmRequest MergeRequest(MergePlan plan)
+ {
+ var keep = plan.KeepId == Copy.LocalId ? Here : There;
+ var drop = plan.KeepId == Copy.LocalId ? There : Here;
+ var only = _review?.Photos.Of(plan.KeepId == Copy.LocalId ? PhotoClass.OnlyThere : PhotoClass.OnlyHere).Count() ?? 0;
+ var facts = new List { Loc.Plural("Server.Copies.Plan.DropToTrash", drop.Photos, Formatting.Bytes(drop.Bytes)) };
+ if (only > 0) facts.Add(Loc.Plural("Server.Copies.Confirm.Merge.OnlyHere", only, drop.Where));
+ if (plan.Renders.Count > 0) facts.Add(Loc.Plural("Server.Copies.Plan.Renders", plan.Renders.Count));
+ if (plan.Projects.Count > 0) facts.Add(Loc.Plural("Server.Copies.Plan.Projects", plan.Projects.Count));
+ return new ConfirmRequest
+ {
+ Heading = Loc.L("Server.Copies.Confirm.Merge.Title"),
+ Message = Loc.L("Server.Copies.Confirm.Merge.Message", drop.Title, drop.Where, keep.Where),
+ Detail = Lines(plan.LastCopies, facts),
+ SafeText = Loc.L("Archive.Dialog.Cancel"),
+ SafeToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Safe"),
+ ActionText = Loc.L("Server.Copies.Action.Merge"),
+ ActionToolTip = Loc.L("Tooltips.Server.Copies.Confirm.Merge.Action"),
+ IsDestructive = true,
+ TypedConfirmation = drop.Photos.ToString(Loc.Culture),
+ TypedPrompt = Loc.L("Server.Copies.Confirm.Merge.TypedPrompt", drop.Title),
+ };
+ }
+
+ /// To trash… and Delete on server…: as the Library's delete confirmation, with the last copies named first.
+ private static ConfirmRequest TrashRequest(int photos, IEnumerable names, string message, IReadOnlyList lasts) => new()
+ {
+ Heading = Loc.Plural("Server.Copies.Plan.Trash", photos),
+ Message = message,
+ Detail = Lines(lasts, names),
+ DetailToolTip = Loc.L("Tooltips.Archive.DeletePlan"),
+ SafeText = Loc.L("Archive.Delete.Keep"),
+ SafeToolTip = Loc.L("Tooltips.Archive.DeleteKeep"),
+ ActionText = Loc.L("Archive.Delete.Action"),
+ ActionToolTip = message,
+ IsDestructive = true,
+ };
+
+ private static string Lines(IReadOnlyList lasts, IEnumerable rest)
+ {
+ const int Listed = 10;
+ var all = lasts.Select(l => Loc.L("Server.Copies.Confirm.LastCopy", l.FileName)).Concat(rest).ToList();
+ var lines = all.Take(Listed).ToList();
+ if (all.Count > Listed) lines.Add(Loc.Plural("Archive.Delete.More", all.Count - Listed));
+ return string.Join(Environment.NewLine, lines);
+ }
+
+ /// The policies of the Photos ComboBox: a merge's two "wins" name the kept and the other sequence.
+ internal static IReadOnlyList> PolicyOptions(bool merge) =>
+ [
+ new(CopyPhotoPolicy.Union, Loc.L("Server.Copies.Policy.Union"), Loc.L("Tooltips.Server.Copies.Policy.Union")),
+ new(CopyPhotoPolicy.ChoosePerPhoto, Loc.L("Server.Copies.Policy.ChoosePerPhoto"), Loc.L("Tooltips.Server.Copies.Policy.ChoosePerPhoto")),
+ new(CopyPhotoPolicy.ThisPcWins, Loc.L(merge ? "Server.Copies.Policy.KeptWins" : "Server.Copies.Policy.ThisPcWins"),
+ Loc.L(merge ? "Tooltips.Server.Copies.Policy.KeptWins" : "Tooltips.Server.Copies.Policy.ThisPcWins")),
+ new(CopyPhotoPolicy.OtherWins, Loc.L(merge ? "Server.Copies.Policy.OtherCopyWins" : "Server.Copies.Policy.OtherWins"),
+ Loc.L(merge ? "Tooltips.Server.Copies.Policy.OtherCopyWins" : "Tooltips.Server.Copies.Policy.OtherWins")),
+ ];
+
+ /// The choices of a Different photo under Choose each.
+ internal static IReadOnlyList> VersionChoices(bool merge) =>
+ [
+ new(PhotoChoice.KeepBoth, Loc.L("Server.Copies.Version.Both"), Loc.L("Tooltips.Server.Copies.Version")),
+ new(PhotoChoice.TakeHere, Loc.L(merge ? "Server.Copies.Detail.Kept" : "Server.Copies.Version.Here"), Loc.L("Tooltips.Server.Copies.Version")),
+ new(PhotoChoice.TakeThere, Loc.L(merge ? "Server.Copies.Detail.Other" : "Server.Copies.Version.There"), Loc.L("Tooltips.Server.Copies.Version")),
+ new(PhotoChoice.Leave, Loc.L("Server.Copies.Version.Leave"), Loc.L("Tooltips.Server.Copies.Version")),
+ ];
+
+ private static bool Expected(Exception ex) =>
+ ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException or System.IO.IOException or UnauthorizedAccessException;
+}
diff --git a/src/Chronos.App/Server/Copies/CopyDialogs.xaml b/src/Chronos.App/Server/Copies/CopyDialogs.xaml
new file mode 100644
index 00000000..3e7d4ad0
--- /dev/null
+++ b/src/Chronos.App/Server/Copies/CopyDialogs.xaml
@@ -0,0 +1,306 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Chronos.App/Server/Copies/CopyListViewModel.cs b/src/Chronos.App/Server/Copies/CopyListViewModel.cs
new file mode 100644
index 00000000..14958891
--- /dev/null
+++ b/src/Chronos.App/Server/Copies/CopyListViewModel.cs
@@ -0,0 +1,426 @@
+using System.Collections.ObjectModel;
+using System.Windows.Input;
+using Chronos.App.Archiving;
+using Chronos.App.Infrastructure;
+using Chronos.App.Shell;
+using Chronos.Core.Diagnostics;
+using Chronos.Core.Localization;
+using Chronos.Core.Model;
+using Chronos.Data.Copies;
+using Chronos.Data.Jobs;
+using Chronos.Data.Sync;
+using Chronos.Protocol;
+using Chronos.Ui.Controls;
+using Chronos.Ui.Mvvm;
+using Chronos.Ui.Visuals;
+
+namespace Chronos.App.Server.Copies;
+
+///
+/// Server › Matches (owner review 6, #73, design §8.1): the pairs of this server and of this PC's archives with both sides,
+/// their state and actions, Find matches, the toasts of detection runs (with Review), Unlink and Keep apart with Undo, the
+/// Library's "Also elsewhere" status and the Compare dialog. Reloads when the engine or a job of its kinds changes. UI thread.
+///
+public sealed class CopyListViewModel : ObservableObject, IDisposable
+{
+ private readonly ShellViewModel _shell;
+ private readonly AsyncRelayCommand _find;
+ private readonly SemaphoreSlim _reloading = new(1, 1);
+ private readonly Dictionary _deletedThere = [];
+ private IReadOnlyList _pairs = [];
+ private ICopyEngine? _engine;
+ private string _search = string.Empty;
+ private int _reloadQueued;
+ private bool _loaded;
+ private bool _attached;
+
+ public CopyListViewModel(ShellViewModel shell)
+ {
+ _shell = shell;
+ _find = new AsyncRelayCommand(FindAsync, () => Engine is not null && !IsFinding);
+ }
+
+ public ObservableCollection Rows { get; } = [];
+
+ /// Every listed pair of this server and of this PC's archives (the chip's count).
+ public IReadOnlyList Pairs => _pairs;
+
+ /// "Find matches": looks for pairs on the signed-in server and among this PC's archives now.
+ public ICommand FindCommand => _find;
+
+ public string FindToolTip => Host.Server is not null
+ ? Loc.L("Tooltips.Server.Copies.Find", ServerName ?? Host.Server)
+ : Loc.L("Tooltips.Server.Copies.FindLocal");
+
+ public bool IsFinding { get; private set; }
+
+ public int Count => _pairs.Count;
+
+ /// Pairs asking for a choice: the chip turns to the warning colours and the rail badge counts them.
+ public int AttentionCount => _pairs.Count(p => p.Copy.NeedsAttention);
+
+ public bool HasRows => Rows.Count > 0;
+
+ /// "No matches found.": the empty list's one sentence (its one button is Find matches).
+ public string? EmptyText => HasRows ? null : Loc.L(_pairs.Count == 0 ? "Server.Copies.Empty" : "Server.Sync.NoMatch");
+
+ public bool IsEmpty => !HasRows;
+
+ /// Opens a dialog over the Server section (set by ServerViewModel).
+ internal Action? OpenDialog { get; set; }
+
+ /// Closes a dialog of the Server section.
+ internal Action? CloseDialog { get; set; }
+
+ /// Shows the Matches chip (set by the sync table).
+ internal Action? ShowList { get; set; }
+
+ /// The search text of the sync table, applied to both titles of a pair.
+ public string SearchText
+ {
+ get => _search;
+ set
+ {
+ if (Set(ref _search, value ?? string.Empty)) ApplyFilter();
+ }
+ }
+
+ internal ICopyEngine? Engine => Host.Copies;
+
+ private SyncHost Host => _shell.Services.Sync;
+
+ private string? ServerName => _shell.Services.Server.IsConnected ? _shell.Services.Server.Flow.Info?.Name : null;
+
+ /// The server announces what an Integrate needs (photo lookup and upload into a sequence).
+ private bool CanIntegrate => _shell.Services.Server.IsConnected && _shell.Services.Server.Flow.Info?.Capabilities is { } capabilities
+ && capabilities.Contains(ServerCapabilities.PhotoLookup) && capabilities.Contains(ServerCapabilities.UploadInto);
+
+ private CopyRights Rights => new(Host.Server, ServerName, CanIntegrate, Host.CanUpload);
+
+ /// Raised after each reload (the chip count, the rail badge and the sync rows' marks follow it).
+ public event Action? Changed;
+
+ public void Attach()
+ {
+ if (_attached) return;
+ _attached = true;
+ Host.CopiesChanged += OnEngineChanged;
+ Host.Changed += OnHostChanged;
+ Loc.CultureChanged += OnCultureChanged;
+ if (_shell.Services.Jobs is { } jobs)
+ {
+ jobs.JobChanged += OnJobChanged;
+ jobs.Progress += OnProgress;
+ }
+ Follow(Engine);
+ _ = ReloadAsync();
+ }
+
+ public void Dispose()
+ {
+ if (!_attached) return;
+ _attached = false;
+ Host.CopiesChanged -= OnEngineChanged;
+ Host.Changed -= OnHostChanged;
+ Loc.CultureChanged -= OnCultureChanged;
+ if (_shell.Services.Jobs is { } jobs)
+ {
+ jobs.JobChanged -= OnJobChanged;
+ jobs.Progress -= OnProgress;
+ }
+ Follow(null);
+ }
+
+ /// The pair the sequence is in (this server's or a local one), the one asking for a choice first; null when none.
+ public FoundCopy? PairOf(Guid sequenceId) => _pairs
+ .Where(p => p.Copy.LocalId == sequenceId || p.Copy.OtherId == sequenceId || p.Copy.RemoteId == sequenceId)
+ .OrderByDescending(p => p.Copy.NeedsAttention)
+ .Select(p => p.Copy)
+ .FirstOrDefault();
+
+ /// Reads the pairs again; requests made while a pass runs share the next one.
+ public async Task ReloadAsync()
+ {
+ Interlocked.Exchange(ref _reloadQueued, 1);
+ await _reloading.WaitAsync();
+ try
+ {
+ while (Interlocked.Exchange(ref _reloadQueued, 0) == 1)
+ {
+ var server = Host.Server;
+ var all = Engine is { } engine ? await engine.ListAsync(CancellationToken.None) : [];
+ _pairs = [.. CopyText.Sorted(all.Where(p => p.Copy.Kind == CopyKind.LocalLocal
+ || string.Equals(p.Copy.Server, server, StringComparison.OrdinalIgnoreCase)))];
+ AnnounceDeletions();
+ ApplyFilter();
+ UpdateLibrary();
+ RaiseCounts();
+ }
+ }
+ catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
+ {
+ Log.Warning("copies", "The matches could not be read", ex);
+ }
+ finally
+ {
+ _reloading.Release();
+ }
+ }
+
+ /// Opens the Compare dialog of the pair the sequence is in (Library › Compare…); false when it is in none.
+ public bool Compare(Guid sequenceId)
+ {
+ if (_pairs.FirstOrDefault(p => p.Copy.Id == PairOf(sequenceId)?.Id) is not { } pair) return false;
+ Open(pair, CopyDialogPart.Photos);
+ return true;
+ }
+
+ /// Opens the Compare dialog of at (and a photo class).
+ internal CopyDialogViewModel? Open(FoundCopyView pair, CopyDialogPart part, PhotoClass? photos = null, bool integrate = false)
+ {
+ if (Engine is not { } engine || OpenDialog is not { } open) return null;
+ var dialog = new CopyDialogViewModel(_shell, engine, pair, Rights, part, photos, integrate, d => CloseDialog?.Invoke(d));
+ open(dialog);
+ _ = dialog.LoadAsync();
+ return dialog;
+ }
+
+ private void ApplyFilter()
+ {
+ var rights = Rights;
+ var wanted = _pairs.Where(p => CopyText.Matches(p, _search.Trim())).ToList();
+ var byId = Rows.ToDictionary(r => r.Id);
+ Rows.Clear();
+ foreach (var pair in wanted)
+ {
+ if (byId.TryGetValue(pair.Copy.Id, out var row)) row.Update(pair, rights);
+ else row = new CopyRow(pair, rights, ActAsync);
+ Rows.Add(row);
+ }
+ OnPropertyChanged(nameof(HasRows));
+ OnPropertyChanged(nameof(IsEmpty));
+ OnPropertyChanged(nameof(EmptyText));
+ }
+
+ private void RaiseCounts()
+ {
+ OnPropertyChanged(nameof(Pairs));
+ OnPropertyChanged(nameof(Count));
+ OnPropertyChanged(nameof(AttentionCount));
+ OnPropertyChanged(nameof(FindToolTip));
+ _find.RaiseCanExecuteChanged();
+ Changed?.Invoke();
+ }
+
+ /// The Library's cards and rows of local sequences in pairs that ask for a choice take "Also elsewhere" or "Deleted there".
+ private void UpdateLibrary()
+ {
+ foreach (var item in _shell.Library.Items)
+ {
+ var pair = _pairs.FirstOrDefault(p => p.Copy.NeedsAttention && (p.Copy.LocalId == item.Id || p.Copy.OtherId == item.Id));
+ item.SetMatch(pair is null ? null : LibraryStatus(pair, item.Id));
+ }
+ }
+
+ /// The card status of a sequence of .
+ internal static CardStatus LibraryStatus(FoundCopyView pair, Guid sequenceId)
+ {
+ var copy = pair.Copy;
+ if (copy.RemoteGone || copy.Score.DeletedThere > 0)
+ return new CardStatus(StatusKind.Warning, Loc.L("Library.Status.DeletedThere"),
+ Loc.L("Tooltips.Library.Status.DeletedThere", pair.There.Where));
+ var other = copy.Kind == CopyKind.LocalLocal && copy.OtherId == sequenceId ? pair.Here : pair.There;
+ return new CardStatus(StatusKind.Warning, Loc.L("Library.Status.CopyFound"), copy.Kind == CopyKind.LocalServer
+ ? Loc.L("Tooltips.Library.Status.CopyFound", other.Where, CopyText.SharedPercent(copy.Score))
+ : Loc.L("Tooltips.Library.Status.CopyFoundLocal", other.Where));
+ }
+
+ /// An integrated pair with newly deleted photos on the other side: "3 photos deleted on nas" · Review.
+ private void AnnounceDeletions()
+ {
+ foreach (var pair in _pairs)
+ {
+ var now = pair.Copy.State == CopyState.Integrated ? pair.Copy.Score.DeletedThere : 0;
+ var before = _deletedThere.GetValueOrDefault(pair.Copy.Id);
+ _deletedThere[pair.Copy.Id] = now;
+ if (!_loaded || now <= before) continue;
+ var shown = pair;
+ _shell.Notify(Loc.Plural("Server.Copies.DeletedToast", now - before, pair.There.Where), null, Loc.L("Server.Copies.Action.Review"),
+ Loc.L("Tooltips.Server.Copies.Review"), () => Review(shown));
+ }
+ _loaded = true;
+ }
+
+ private void Review(FoundCopyView pair)
+ {
+ _shell.Navigate(SectionKey.Server);
+ ShowList?.Invoke(null);
+ Open(pair, CopyDialogPart.Photos, PhotoClass.DeletedThere);
+ }
+
+ private async Task FindAsync()
+ {
+ if (Engine is not { } engine) return;
+ IsFinding = true;
+ _find.RaiseCanExecuteChanged();
+ try
+ {
+ var found = await engine.FindAsync(Host.Remote, CancellationToken.None);
+ if (found.IsEmpty) _shell.Notify(Loc.L("Server.Copies.Empty"));
+ else Announce(found);
+ }
+ catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
+ {
+ _shell.Notify(ex.Message, isError: true);
+ }
+ finally
+ {
+ IsFinding = false;
+ _find.RaiseCanExecuteChanged();
+ }
+ await ReloadAsync();
+ }
+
+ /// "2 matches found" · Review, and "3 sequences linked" · Show (design §8.4).
+ internal void Announce(CopyFindResult found)
+ {
+ var asking = found.New.Count + found.AskedAgain.Count;
+ if (asking > 0)
+ _shell.Notify(Loc.Plural("Server.Copies.Found", asking), null, Loc.L("Server.Copies.Action.Review"), Loc.L("Tooltips.Server.Copies.ReviewFound"), ShowMatches);
+ if (found.AutoLinked.Count > 0)
+ _shell.Notify(Loc.Plural("Server.Copies.Linked", found.AutoLinked.Count), null, Loc.L("Server.Sync.Show"), Loc.L("Tooltips.Server.Sync.Show"), ShowMatches);
+ }
+
+ private void ShowMatches()
+ {
+ _shell.Navigate(SectionKey.Server);
+ ShowList?.Invoke(null);
+ }
+
+ private async Task ActAsync(CopyRow row, CopyAction action)
+ {
+ if (Engine is not { } engine) return;
+ var pair = row.View;
+ var copy = pair.Copy;
+ try
+ {
+ switch (action)
+ {
+ case CopyAction.Compare:
+ Open(pair, CopyDialogPart.Photos);
+ return;
+ case CopyAction.Integrate or CopyAction.Merge:
+ Open(pair, CopyDialogPart.Plan, integrate: true);
+ return;
+ case CopyAction.Review:
+ Open(pair, CopyDialogPart.Photos, PhotoClass.DeletedThere);
+ return;
+ case CopyAction.KeepApart:
+ await engine.KeepApartAsync(copy.Id, CancellationToken.None);
+ Toast(Loc.L("Server.Copies.KeptApartToast", row.Title), (Loc.L("Tooltips.Server.Copies.UndoKeepApart"), () => engine.AskAgainAsync(copy.Id, CancellationToken.None)));
+ break;
+ case CopyAction.AskAgain:
+ await engine.AskAgainAsync(copy.Id, CancellationToken.None);
+ break;
+ case CopyAction.Unlink:
+ await engine.UnlinkAsync(copy.Id, Host.Remote, CancellationToken.None);
+ if (copy.Kind == CopyKind.LocalServer && Host.Remote is { } remote)
+ Toast(Loc.L("Server.Copies.Unlinked", row.Title), (Loc.L("Tooltips.Server.Copies.UndoUnlink"), () => engine.LinkAsync(copy.Id, remote, CancellationToken.None)));
+ break;
+ case CopyAction.KeepHere:
+ await engine.KeepHereAsync(copy.Id, CancellationToken.None);
+ break;
+ case CopyAction.UploadAgain:
+ if (Host is { Service: { } service, Server: { } server } && _shell.Services.Engine is { } jobs
+ && await _shell.Services.Database!.Sequences.GetAsync(copy.LocalId) is { } sequence)
+ await service.EnqueueUploadAsync(jobs, server, sequence);
+ break;
+ case CopyAction.ToTrash when OpenDialog is { } open:
+ var delete = new DeleteDialogViewModel(_shell, [copy.LocalId], d => CloseDialog?.Invoke(d));
+ open(delete);
+ await delete.RunAsync();
+ break;
+ case CopyAction.Pause when copy.JobId is { } paused:
+ await _shell.Services.Jobs!.PauseAsync(paused);
+ break;
+ case CopyAction.Resume when copy.JobId is { } resumed:
+ await _shell.Services.Jobs!.ResumeAsync(resumed);
+ break;
+ }
+ }
+ catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
+ {
+ _shell.Notify(ex.Message, isError: true);
+ }
+ await ReloadAsync();
+ }
+
+ /// A toast with Undo (Unlink and Keep apart ask no confirmation: design §8.5).
+ private void Toast(string title, (string ToolTip, Func Undo) undo) =>
+ _shell.Notify(title, null, Loc.L("Server.Copies.Action.Undo"), undo.ToolTip, async () =>
+ {
+ try
+ {
+ await undo.Undo();
+ }
+ catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException or System.Net.Http.HttpRequestException)
+ {
+ _shell.Notify(ex.Message, isError: true);
+ }
+ await ReloadAsync();
+ });
+
+ private void Follow(ICopyEngine? engine)
+ {
+ if (ReferenceEquals(_engine, engine)) return;
+ if (_engine is not null) _engine.Found -= OnFound;
+ _engine = engine;
+ if (_engine is not null) _engine.Found += OnFound;
+ }
+
+ private void OnFound(CopyFindResult found) => Dispatch(() =>
+ {
+ if (!found.IsEmpty && !IsFinding) Announce(found);
+ _ = ReloadAsync();
+ });
+
+ private void OnEngineChanged() => Dispatch(() =>
+ {
+ Follow(Engine);
+ _ = ReloadAsync();
+ });
+
+ private void OnHostChanged() => Dispatch(() => _ = ReloadAsync());
+
+ private void OnCultureChanged(object? sender, EventArgs e) => Dispatch(() =>
+ {
+ foreach (var row in Rows) row.Relabel();
+ UpdateLibrary();
+ OnAllPropertiesChanged();
+ });
+
+ private void OnJobChanged(Job job)
+ {
+ if (job.Kind is not (JobKind.Integrate or JobKind.MergeSequences)) return;
+ Dispatch(() =>
+ {
+ foreach (var row in Rows.Where(r => r.Copy.JobId == job.Id)) row.UpdateJob(job.State, job.ProgressDone, job.ProgressTotal);
+ if (job.State is JobState.Done or JobState.Failed or JobState.Cancelled or JobState.Queued) _ = ReloadAsync();
+ });
+ }
+
+ private void OnProgress(JobProgressInfo info)
+ {
+ if (info.Kind is not JobKind.Integrate) return;
+ Dispatch(() =>
+ {
+ foreach (var row in Rows.Where(r => r.Copy.JobId == info.JobId)) row.UpdateJob(JobState.Running, info.Done, info.Total);
+ });
+ }
+
+ private static void Dispatch(Action action)
+ {
+ if (System.Windows.Application.Current?.Dispatcher is not { } dispatcher || dispatcher.CheckAccess()) action();
+ else dispatcher.BeginInvoke(action);
+ }
+}
diff --git a/src/Chronos.App/Server/Copies/CopyPhotoRow.cs b/src/Chronos.App/Server/Copies/CopyPhotoRow.cs
new file mode 100644
index 00000000..376d2187
--- /dev/null
+++ b/src/Chronos.App/Server/Copies/CopyPhotoRow.cs
@@ -0,0 +1,123 @@
+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;
+
+/// A line of the Photos part's class table: glyph and class, count, bytes on each side, what it means.
+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;
+}
+
+///
+/// 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).
+///
+public sealed class CopyPhotoRow : ObservableObject
+{
+ private readonly Action _changed;
+ private bool _bring;
+ private bool _isSelected;
+ private SettingsOption? _choice;
+
+ public CopyPhotoRow(ComparedPhoto photo, bool isMerge, bool canBring, bool canChoose, IReadOnlyList> choices,
+ PhotoChoice? current, Action changed, Func? drop)
+ {
+ Photo = photo;
+ IsMerge = isMerge;
+ 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);
+
+ /// "This PC", "Server" (Kept, Other for a merge), or both.
+ 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);
+
+ /// Only here or Only there under Choose each: a Bring tick.
+ public bool CanBring { get; }
+
+ /// Different under Choose each: Keep both, This PC's, Server's, Leave.
+ public bool CanChoose { get; }
+
+ public IReadOnlyList> 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? Choice
+ {
+ get => _choice;
+ set
+ {
+ if (!Set(ref _choice, value)) return;
+ OnPropertyChanged(nameof(ChoiceAccessibleName));
+ _changed();
+ }
+ }
+
+ /// The row is selected in the list (To trash… acts on the selection).
+ public bool IsSelected { get => _isSelected; set => Set(ref _isSelected, value); }
+
+ /// The user's choice for this photo, or null when none.
+ 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"));
+
+ /// Sets the tick or the choice without raising one change per row (Bring all, All: keep both).
+ internal void SetQuietly(bool bring, SettingsOption? choice)
+ {
+ _bring = bring;
+ _choice = choice;
+ OnPropertyChanged(nameof(Bring));
+ OnPropertyChanged(nameof(Choice));
+ OnPropertyChanged(nameof(ChoiceAccessibleName));
+ }
+
+ private string Side(bool here) => Loc.L(IsMerge ? (here ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.Other")
+ : here ? "Server.Copies.Detail.ThisPc" : "Server.Copies.Detail.Server");
+}
diff --git a/src/Chronos.App/Server/Copies/CopyPlanLine.cs b/src/Chronos.App/Server/Copies/CopyPlanLine.cs
new file mode 100644
index 00000000..acc19efc
--- /dev/null
+++ b/src/Chronos.App/Server/Copies/CopyPlanLine.cs
@@ -0,0 +1,53 @@
+using System.Windows.Input;
+using Chronos.App.Infrastructure;
+using Chronos.Core.Localization;
+using Chronos.Data.Copies;
+using Chronos.Ui.Controls;
+using Chronos.Ui.Mvvm;
+
+namespace Chronos.App.Server.Copies;
+
+/// A line of the Plan part ("Receives 24 photos · 412 MB"); a warning line (last copies) leads its column.
+public sealed record CopyPlanLine(string Text, string? ToolTip = null, bool IsWarning = false)
+{
+ public StatusKind Kind => IsWarning ? StatusKind.Warning : StatusKind.Done;
+ public string ShownToolTip => ToolTip ?? Text;
+}
+
+/// Why the plan cannot be applied, with its one action where the dialog itself settles it (Choose).
+public sealed class CopyBlockLine(CopyBlock block, string text, Action? choose)
+{
+ public CopyBlock Block { get; } = block;
+ public string Text { get; } = text;
+ public ICommand? ChooseCommand { get; } = choose is null ? null : new RelayCommand(choose);
+ public bool HasChoose => ChooseCommand is not null;
+ public string ChooseText => Loc.L("Server.Copies.Action.Choose");
+ public string ChooseToolTip => Loc.L("Tooltips.Server.Copies.Choose");
+}
+
+/// A side of a local pair the merge keeps ("Main archive · 1,204 photos · 18.2 GB"): the Kept sequence radios.
+public sealed class CopyKeepOption(Guid sequenceId, CopyFacts facts, Action chosen) : ObservableObject
+{
+ private bool _isChecked;
+
+ public Guid SequenceId { get; } = sequenceId;
+ public string Text => Loc.L("Server.Copies.Plan.KeptChoice", facts.Where, Loc.Plural("Shell.Status.Photos", facts.Photos), Formatting.Bytes(facts.Bytes));
+ public string ToolTip => Loc.L("Tooltips.Server.Copies.KeptCopy");
+ public string AccessibleName => Loc.L("Server.Copies.ControlFor", facts.Where, Loc.L("Server.Copies.Plan.KeptCopy"));
+
+ public bool IsChecked
+ {
+ get => _isChecked;
+ set
+ {
+ if (!Set(ref _isChecked, value) || !value) return;
+ chosen(this);
+ }
+ }
+
+ internal void SetQuietly(bool value)
+ {
+ _isChecked = value;
+ OnPropertyChanged(nameof(IsChecked));
+ }
+}
diff --git a/src/Chronos.App/Server/Copies/CopyProjectRow.cs b/src/Chronos.App/Server/Copies/CopyProjectRow.cs
new file mode 100644
index 00000000..039964a2
--- /dev/null
+++ b/src/Chronos.App/Server/Copies/CopyProjectRow.cs
@@ -0,0 +1,29 @@
+using Chronos.App.Infrastructure;
+using Chronos.Core.Localization;
+using Chronos.Data.Copies;
+using Chronos.Ui.Mvvm;
+
+namespace Chronos.App.Server.Copies;
+
+/// A project of one side (the Projects part): name · versions · last change, and the name it gets at the other home.
+public sealed class CopyProjectRow(ProjectLine project) : ObservableObject
+{
+ private string? _target;
+
+ public ProjectLine Project { get; } = project;
+ public string Name => Project.Name;
+ public string VersionsText => Loc.Plural("Server.Copies.Projects.Versions", Project.Versions);
+ public string ChangedText => Formatting.Date(Project.UpdatedAt);
+
+ /// "→ Vertical (STUDIO-PC)" once the plan named it; null when it stays or Main.
+ public string? TargetText => _target is null ? null : Loc.L("Server.Copies.Projects.Target", _target);
+
+ public string ToolTip => Project.IsMain ? Loc.L("Tooltips.Server.Copies.Projects.Main")
+ : string.Join(Loc.Separator, Name, VersionsText, ChangedText);
+
+ internal void SetTarget(string? target)
+ {
+ _target = target;
+ OnPropertyChanged(nameof(TargetText));
+ }
+}
diff --git a/src/Chronos.App/Server/Copies/CopyRow.cs b/src/Chronos.App/Server/Copies/CopyRow.cs
new file mode 100644
index 00000000..fb97264d
--- /dev/null
+++ b/src/Chronos.App/Server/Copies/CopyRow.cs
@@ -0,0 +1,160 @@
+using System.Windows.Input;
+using Chronos.Core.Localization;
+using Chronos.Data.Copies;
+using Chronos.Ui.Controls;
+using Chronos.Ui.Mvvm;
+
+namespace Chronos.App.Server.Copies;
+
+/// A button of a Matches row; kept while the row offers it, so focus and tooltips survive a reload.
+public sealed class CopyRowAction : ObservableObject
+{
+ private readonly AsyncRelayCommand _command;
+ private string _toolTip = string.Empty;
+ private string _sequence = string.Empty;
+ private bool _isEnabled = true;
+
+ public CopyRowAction(CopyAction action, Func execute)
+ {
+ Action = action;
+ _command = new AsyncRelayCommand(execute, () => _isEnabled);
+ }
+
+ public CopyAction Action { get; }
+ public string Text => CopyText.Label(Action);
+ public ICommand Command => _command;
+
+ public string ToolTip { get => _toolTip; set => Set(ref _toolTip, value); }
+
+ public bool IsEnabled
+ {
+ get => _isEnabled;
+ set
+ {
+ if (Set(ref _isEnabled, value)) _command.RaiseCanExecuteChanged();
+ }
+ }
+
+ public string Sequence
+ {
+ get => _sequence;
+ set
+ {
+ if (Set(ref _sequence, value)) OnPropertyChanged(nameof(AccessibleName));
+ }
+ }
+
+ /// "Compare…: Lighthouse 2026-08-13": screen readers name the pair each of the identical buttons acts on.
+ public string AccessibleName => Loc.L("Server.Sync.ActionFor", Text, _sequence);
+
+ public void Relabel()
+ {
+ OnPropertyChanged(nameof(Text));
+ OnPropertyChanged(nameof(AccessibleName));
+ }
+}
+
+/// One row of Server › Matches (design §8.1): the sequence, both sides, the state and the actions that apply.
+public sealed class CopyRow : ObservableObject
+{
+ private readonly Func _act;
+ private FoundCopyView _view;
+ private CopyRights _rights;
+ private (long Done, long Total)? _progress;
+ private Core.Model.JobState? _job;
+ private IReadOnlyList _actions = [];
+
+ public CopyRow(FoundCopyView view, CopyRights rights, Func act)
+ {
+ _view = view;
+ _act = act;
+ UpdateActions(rights);
+ }
+
+ public FoundCopyView View => _view;
+ public FoundCopy Copy => _view.Copy;
+ public Guid Id => _view.Copy.Id;
+ public string Title => _view.Here.Title;
+
+ /// Both titles: the other copy may carry another name.
+ public string TitleToolTip => string.Equals(_view.Here.Title, _view.There.Title, StringComparison.CurrentCulture)
+ ? _view.Here.Title
+ : string.Join(Loc.Separator, _view.Here.Title, _view.There.Title);
+
+ public string HereText => CopyText.Where(_view.Here, isServer: false);
+ public string ThereText => CopyText.Where(_view.There, isServer: Copy.Kind == CopyKind.LocalServer);
+
+ public StatusKind StateKind => CopyText.State(Copy, _rights.ServerName, _progress).Kind;
+ public string StateText => CopyText.State(Copy, _rights.ServerName, _progress).Text;
+ public string StateToolTip => string.Join(Loc.Separator, StateText, CopyText.State(Copy, _rights.ServerName, _progress).ToolTip);
+
+ /// "Lighthouse 2026-08-13: match found": what a screen reader announces when the state changes.
+ public string StateAnnouncement => Loc.L("Server.Sync.Row.State", Title, StateText);
+
+ /// The pair asks for a choice: the row is drawn on the warning tint (the State word says it too).
+ public bool IsConflict => Copy.NeedsAttention;
+
+ public IReadOnlyList Actions
+ {
+ get => _actions;
+ private set => Set(ref _actions, value);
+ }
+
+ public void Update(FoundCopyView view, CopyRights rights)
+ {
+ _view = view;
+ UpdateActions(rights);
+ RaiseTexts();
+ }
+
+ /// The Integrate job's step ("integrating · 2 of 5") and whether it is paused.
+ public void UpdateJob(Core.Model.JobState? state, long done, long total)
+ {
+ _progress = (done, total);
+ if (_job != state)
+ {
+ _job = state;
+ UpdateActions(_rights);
+ }
+ RaiseTexts();
+ }
+
+ public void Relabel()
+ {
+ foreach (var action in _actions) action.Relabel();
+ UpdateActions(_rights);
+ RaiseTexts();
+ }
+
+ private void UpdateActions(CopyRights rights)
+ {
+ _rights = rights;
+ var wanted = CopyText.Actions(Copy, _job);
+ if (!wanted.SequenceEqual(_actions.Select(a => a.Action)))
+ {
+ var kept = _actions.ToDictionary(a => a.Action);
+ Actions = [.. wanted.Select(action => kept.GetValueOrDefault(action) ?? new CopyRowAction(action, () => _act(this, action)))];
+ }
+ foreach (var action in _actions)
+ {
+ action.ToolTip = CopyText.ToolTip(Copy, action.Action, rights);
+ action.IsEnabled = CopyText.Blocked(Copy, action.Action, rights) is null;
+ action.Sequence = Title;
+ }
+ }
+
+ private void RaiseTexts()
+ {
+ OnPropertyChanged(nameof(View));
+ OnPropertyChanged(nameof(Copy));
+ OnPropertyChanged(nameof(Title));
+ OnPropertyChanged(nameof(TitleToolTip));
+ OnPropertyChanged(nameof(HereText));
+ OnPropertyChanged(nameof(ThereText));
+ OnPropertyChanged(nameof(StateKind));
+ OnPropertyChanged(nameof(StateText));
+ OnPropertyChanged(nameof(StateToolTip));
+ OnPropertyChanged(nameof(StateAnnouncement));
+ OnPropertyChanged(nameof(IsConflict));
+ }
+}
diff --git a/src/Chronos.App/Server/Copies/CopyScenes.cs b/src/Chronos.App/Server/Copies/CopyScenes.cs
new file mode 100644
index 00000000..b388555d
--- /dev/null
+++ b/src/Chronos.App/Server/Copies/CopyScenes.cs
@@ -0,0 +1,115 @@
+using Chronos.App.Infrastructure;
+using Chronos.App.Shell;
+using Chronos.Data.Copies;
+using Chronos.Data.Sync;
+
+namespace Chronos.App.Server.Copies;
+
+///
+/// The Matches states that --capture renders (server-copies-<scene>-<theme>.png, design §8.7) and the
+/// screen smoke tests check, on the sample pairs: the list, the dialog at each part and with each list, the plan with and
+/// without a block, the merge of a local pair, the toast of Find matches, and the sync rows a pair marks.
+///
+public static class CopyScenes
+{
+ /// Scenes shown in the window (dialogs in-window included); the confirmations are separate windows.
+ public static readonly IReadOnlyList Views =
+ [
+ "server-copies", "server-copies-toast", "server-copies-photos", "server-copies-choose", "server-copies-versions",
+ "server-copies-review", "server-copies-details", "server-copies-projects", "server-copies-plan", "server-copies-blocked",
+ "server-copies-merge", "server-sync-copyfound", "server-copies-gone",
+ ];
+
+ /// The Lighthouse pair (a match found on the server).
+ public const string Lighthouse = "Lighthouse 2026-08-13";
+
+ /// The Alps pair (twice on this PC).
+ public const string Alps = "Alps 2025";
+
+ /// Shows ; returns the dialog it opened, if any.
+ public static async Task ShowAsync(ShellViewModel shell, string view)
+ {
+ var server = shell.Server;
+ var sync = server.Sync;
+ var list = sync.Copies;
+ shell.Navigate(SectionKey.Server);
+ if (server.Dialog is { } open) server.CloseDialog(open);
+ sync.SearchText = string.Empty;
+ await sync.ReloadAsync();
+ await list.ReloadAsync();
+ switch (view)
+ {
+ case "server-sync-copyfound":
+ sync.ShowFilter(SyncFilter.All);
+ return null;
+ case "server-copies-gone":
+ sync.ShowFilter(SyncFilter.All, "Garden");
+ return null;
+ case "server-copies-toast":
+ sync.ShowFilter(SyncFilter.FoundCopies);
+ if (list.Engine is { } engine) list.Announce(await engine.FindAsync(shell.Services.Sync.Remote, CancellationToken.None));
+ return null;
+ }
+ sync.ShowFilter(SyncFilter.FoundCopies);
+ if (view == "server-copies") return null;
+ var title = view is "server-copies-versions" or "server-copies-merge" ? Alps : view == "server-copies-review" ? "Bridge works wk 41" : Lighthouse;
+ if (list.Pairs.FirstOrDefault(p => p.Here.Title == title) is not { } pair) return null;
+ var (part, photos) = view switch
+ {
+ "server-copies-photos" => (CopyDialogPart.Photos, PhotoClass.OnlyHere),
+ "server-copies-choose" => (CopyDialogPart.Photos, PhotoClass.Differs),
+ "server-copies-versions" => (CopyDialogPart.Photos, PhotoClass.Versions),
+ "server-copies-review" => (CopyDialogPart.Photos, PhotoClass.DeletedThere),
+ "server-copies-details" => (CopyDialogPart.Details, (PhotoClass?)null),
+ "server-copies-projects" => (CopyDialogPart.Projects, null),
+ _ => (CopyDialogPart.Plan, null),
+ };
+ if (list.Open(pair, part, photos) is not { } dialog) return null;
+ await dialog.LoadAsync();
+ switch (view)
+ {
+ case "server-copies-choose":
+ dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ChoosePerPhoto);
+ dialog.SelectedClass = dialog.Classes.FirstOrDefault(c => c.Class == PhotoClass.Differs);
+ break;
+ case "server-copies-details":
+ if (dialog.Details.Count > 0) dialog.Details[0].ChoiceIndex = 0;
+ break;
+ case "server-copies-plan":
+ dialog.AllHereCommand.Execute(null);
+ dialog.Part = CopyDialogPart.Plan;
+ break;
+ }
+ if (dialog.IsPlan) await dialog.PlanNowAsync();
+ return dialog;
+ }
+
+ /// "Replace photos?": the Lighthouse plan where this PC's version of the different photos wins.
+ public static async Task ReplaceRequestAsync(ShellViewModel shell)
+ {
+ if (await ShowAsync(shell, "server-copies-plan") is not { } dialog) return null;
+ dialog.Policy = dialog.Policies.First(o => o.Value == CopyPhotoPolicy.ThisPcWins);
+ await dialog.PlanNowAsync();
+ var request = dialog.Plan is { } plan ? CopyDialogViewModel.ReplaceRequest(plan) : null;
+ shell.Server.CloseDialog(dialog);
+ return request;
+ }
+
+ /// "Merge sequences?": the Alps merge, with the typed photo count.
+ public static async Task MergeRequestAsync(ShellViewModel shell)
+ {
+ if (await ShowAsync(shell, "server-copies-merge") is not { } dialog) return null;
+ dialog.AllHereCommand.Execute(null);
+ await dialog.PlanNowAsync();
+ var request = dialog.MergePlan is { } plan ? dialog.MergeRequest(plan) : null;
+ shell.Server.CloseDialog(dialog);
+ return request;
+ }
+
+ /// Back to the sync table with no dialog and no search.
+ public static void Reset(ShellViewModel shell)
+ {
+ if (shell.Server.Dialog is { } open) shell.Server.CloseDialog(open);
+ shell.Server.Sync.ShowFilter(SyncFilter.All, string.Empty);
+ }
+}
diff --git a/src/Chronos.App/Server/Copies/CopyText.cs b/src/Chronos.App/Server/Copies/CopyText.cs
new file mode 100644
index 00000000..670d8700
--- /dev/null
+++ b/src/Chronos.App/Server/Copies/CopyText.cs
@@ -0,0 +1,174 @@
+using Chronos.App.Infrastructure;
+using Chronos.Core.Localization;
+using Chronos.Data.Copies;
+using Chronos.Data.Sync;
+using Chronos.Ui.Controls;
+
+namespace Chronos.App.Server.Copies;
+
+/// What a row of Server › Matches offers (design §8.1).
+public enum CopyAction
+{
+ Compare,
+ Integrate,
+ Merge,
+ KeepApart,
+ AskAgain,
+ Unlink,
+ Review,
+ KeepHere,
+ UploadAgain,
+ ToTrash,
+ Pause,
+ Resume,
+}
+
+/// What the signed-in account allows a pair's actions; Server is null when signed out.
+/// The signed-in server's key, or null.
+/// The name shown for that server.
+/// The server announces the capabilities an Integrate needs.
+/// The account may upload.
+/// The pair's sequences an Integrate or Merge job holds.
+public readonly record struct CopyRights(string? Server, string? ServerName, bool CanIntegrate, bool CanUpload, bool Busy = false);
+
+/// The words, glyphs and actions of a pair (design §8.1): plain functions of a , like .
+public static class CopyText
+{
+ /// The state glyph, word and tooltip of a pair; is the Integrate job's step (done, total).
+ public static (StatusKind Kind, string Text, string ToolTip) State(FoundCopy copy, string? serverName = null, (long Done, long Total)? progress = null)
+ {
+ var deleted = copy.Score.DeletedThere;
+ if (copy.RemoteGone && copy.State == CopyState.KeptApart)
+ return (StatusKind.Offline, Loc.L("Server.Copies.State.KeptHere"), Loc.L("Tooltips.Server.Copies.State.KeptHere"));
+ if (copy.RemoteGone)
+ return (StatusKind.Warning, Loc.L("Server.Copies.State.RemoteGone"), Loc.L("Tooltips.Server.Copies.State.RemoteGone"));
+ if (copy.State is CopyState.Linked or CopyState.Integrated && deleted > 0)
+ {
+ var key = copy.Kind == CopyKind.LocalLocal ? "Server.Copies.State.DeletedOther" : "Server.Copies.State.DeletedThere";
+ return (StatusKind.Warning, Loc.L(key, Formatting.Count(deleted)), Loc.Plural("Tooltips.Server.Copies.State.DeletedThere", deleted));
+ }
+ return copy.State switch
+ {
+ CopyState.Candidate => (StatusKind.Warning, Loc.L("Server.Copies.State.Candidate"),
+ Loc.L("Tooltips.Server.Copies.State.Candidate", SharedPercent(copy.Score))),
+ CopyState.KeptApart => (StatusKind.Offline, Loc.L("Server.Copies.State.KeptApart"),
+ Loc.L("Tooltips.Server.Copies.State.KeptApart", Formatting.Date(copy.AnsweredAt ?? copy.UpdatedAt))),
+ CopyState.Linked => (StatusKind.Synced, Loc.L("Server.Copies.State.Linked"), Loc.L("Tooltips.Server.Copies.State.Linked")),
+ CopyState.Integrating => (StatusKind.Running,
+ Loc.L("Server.Copies.State.Integrating", Formatting.Count(progress?.Done ?? 0), Formatting.Count(progress?.Total ?? 0)),
+ Loc.L("Tooltips.Server.Copies.State.Integrating")),
+ _ => (StatusKind.Done, Loc.L("Server.Copies.State.Integrated"), Loc.L("Tooltips.Server.Copies.State.Integrated")),
+ };
+ }
+
+ /// The share of the smaller side's photos the other holds too, in whole per cent ("98").
+ public static string SharedPercent(CopyScore score) =>
+ Math.Round(Math.Clamp(score.Containment, 0, 1000) / 10.0).ToString("0", Loc.Culture);
+
+ /// "Main archive · 1,204 photos": where one side of a pair lies.
+ public static string Where(CopyFacts facts, bool isServer) =>
+ Loc.Plural(isServer ? "Server.Copies.Where.Server" : "Server.Copies.Where.Archive", facts.Photos, facts.Where);
+
+ /// "Lighthouse · 1,204 photos · 18.2 GB": a side of the dialog's header.
+ public static string Facts(CopyFacts facts) => Loc.Plural("Server.Copies.Facts", facts.Photos, facts.Where, Formatting.Bytes(facts.Bytes));
+
+ /// The row's buttons in the order of design §8.1.
+ public static IReadOnlyList Actions(FoundCopy copy, Core.Model.JobState? job = null)
+ {
+ var local = copy.Kind == CopyKind.LocalLocal;
+ if (copy.RemoteGone)
+ return copy.State == CopyState.KeptApart ? [CopyAction.UploadAgain] : [CopyAction.KeepHere, CopyAction.UploadAgain, CopyAction.ToTrash];
+ return copy.State switch
+ {
+ CopyState.Candidate => [CopyAction.Compare, local ? CopyAction.Merge : CopyAction.Integrate, CopyAction.KeepApart],
+ CopyState.KeptApart => [CopyAction.Compare, CopyAction.AskAgain],
+ CopyState.Linked when copy.Score.DeletedThere > 0 => [CopyAction.Compare, CopyAction.Integrate, CopyAction.Unlink, CopyAction.Review],
+ CopyState.Linked => [CopyAction.Compare, CopyAction.Integrate, CopyAction.Unlink],
+ CopyState.Integrating => [job == Core.Model.JobState.Paused ? CopyAction.Resume : CopyAction.Pause],
+ _ when copy.Score.DeletedThere > 0 => [CopyAction.Compare, CopyAction.Unlink, CopyAction.Review],
+ _ => [CopyAction.Compare, CopyAction.Unlink],
+ };
+ }
+
+ /// The button's label ("Compare…", "Merge…").
+ public static string Label(CopyAction action) => action switch
+ {
+ CopyAction.Merge => Loc.L("Server.Copies.Action.MergeRow"),
+ CopyAction.Pause => Loc.L("Server.Sync.Action.Pause"),
+ CopyAction.Resume => Loc.L("Server.Sync.Action.Resume"),
+ _ => Loc.L("Server.Copies.Action." + action),
+ };
+
+ ///
+ /// Why the action cannot be pressed now, or null when it can: a pair of a server needs that server signed in; Integrate
+ /// a server that announces the capabilities; Upload again the upload right; nothing that moves files while a job holds it.
+ ///
+ public static string? Blocked(FoundCopy copy, CopyAction action, CopyRights rights)
+ {
+ if (action is CopyAction.Pause or CopyAction.Resume or CopyAction.KeepApart or CopyAction.AskAgain or CopyAction.KeepHere) return null;
+ if (copy.Kind == CopyKind.LocalServer && action is not CopyAction.ToTrash
+ && !string.Equals(copy.Server, rights.Server, StringComparison.OrdinalIgnoreCase))
+ return Loc.L("Tooltips.Server.Copies.SignIn", copy.Server ?? string.Empty);
+ if (rights.Busy && action is CopyAction.Integrate or CopyAction.Merge or CopyAction.ToTrash or CopyAction.UploadAgain)
+ return Loc.L("Errors.Copies.Busy");
+ return action switch
+ {
+ CopyAction.Integrate when !rights.CanIntegrate => Loc.L("Tooltips.Server.Copies.NeedsNewerServer"),
+ CopyAction.UploadAgain when !rights.CanUpload => Loc.L("Tooltips.Server.Sync.UploadAll.NoRight"),
+ _ => null,
+ };
+ }
+
+ /// What the button does; for a disabled one, why not.
+ public static string ToolTip(FoundCopy copy, CopyAction action, CopyRights rights) => Blocked(copy, action, rights) ?? action switch
+ {
+ CopyAction.UploadAgain => Loc.L("Tooltips.Server.Copies.UploadAgain", rights.ServerName ?? copy.Server ?? string.Empty),
+ CopyAction.ToTrash => Loc.L("Tooltips.Server.Copies.ToTrashSequence"),
+ CopyAction.Pause => Loc.L("Tooltips.Server.Sync.Pause"),
+ CopyAction.Resume => Loc.L("Tooltips.Server.Sync.Resume"),
+ _ => Loc.L("Tooltips.Server.Copies." + action),
+ };
+
+ /// Sorting (design §8.1): pairs asking for attention first, then the stronger hints, then by title.
+ public static IEnumerable Sorted(IEnumerable pairs) => pairs
+ .OrderByDescending(p => p.Copy.NeedsAttention)
+ .ThenByDescending(p => p.Copy.Score.Hints)
+ .ThenBy(p => p.Here.Title, StringComparer.CurrentCultureIgnoreCase);
+
+ /// The search of the Matches list: either title.
+ public static bool Matches(FoundCopyView pair, string search) => search.Length == 0
+ || pair.Here.Title.Contains(search, StringComparison.CurrentCultureIgnoreCase)
+ || pair.There.Title.Contains(search, StringComparison.CurrentCultureIgnoreCase);
+
+ /// The word of a photo class ("Only here").
+ public static string Class(PhotoClass c) => Loc.L("Server.Copies.Class." + c);
+
+ public static string ClassToolTip(PhotoClass c) => Loc.L("Tooltips.Server.Copies.Class." + c);
+
+ /// The glyph of a photo class: what an Integrate settles by itself is fine; what waits for a choice is a warning.
+ public static StatusKind ClassKind(PhotoClass c) => c switch
+ {
+ PhotoClass.Same or PhotoClass.Converted => StatusKind.Done,
+ PhotoClass.SameUnhashed => StatusKind.Queued,
+ PhotoClass.OnlyHere or PhotoClass.OnlyThere => StatusKind.Synced,
+ PhotoClass.DeletedHere => StatusKind.Offline,
+ _ => StatusKind.Warning,
+ };
+
+ /// The sentence of a block (each maps to one Errors.Copies.* key).
+ public static string Block(CopyBlock block, string title, string? server, string? need = null, int unchosen = 0) => block switch
+ {
+ CopyBlock.NeedsNewerServer => Loc.L("Errors.Copies.NeedsNewerServer", server ?? string.Empty),
+ CopyBlock.LinkTaken => Loc.L("Errors.Copies.LinkTaken", title, server ?? string.Empty),
+ CopyBlock.NoSpace => Loc.L("Errors.Copies.NoSpace", title, need ?? string.Empty),
+ CopyBlock.ArchiveOffline or CopyBlock.FolderMoved or CopyBlock.ChangedFile => Loc.L("Errors.Copies." + block, title),
+ CopyBlock.UnsentWorkspace => Loc.L("Errors.Copies.Unsent", title),
+ CopyBlock.BothLinked => Loc.L("Errors.Copies.BothLinked", server ?? string.Empty),
+ CopyBlock.TrashBlocked => Loc.L("Errors.Copies.TrashBlocked", title, need ?? string.Empty),
+ CopyBlock.DetailsUnchosen => Loc.Plural("Errors.Copies.DetailsUnchosen", unchosen),
+ _ => Loc.L("Errors.Copies." + block),
+ };
+
+ /// A block the user settles in the dialog itself: its line gets the one action Choose.
+ public static bool HasChoose(CopyBlock block) => block is CopyBlock.DetailsUnchosen or CopyBlock.KeptUnchosen;
+}
diff --git a/src/Chronos.App/Server/SyncRow.cs b/src/Chronos.App/Server/SyncRow.cs
index 43666dcd..aba56a72 100644
--- a/src/Chronos.App/Server/SyncRow.cs
+++ b/src/Chronos.App/Server/SyncRow.cs
@@ -22,7 +22,7 @@ public sealed class SyncRowAction : ObservableObject
}
public SyncAction Action { get; }
- public string Text => Loc.L("Server.Sync.Action." + Action);
+ public string Text => Action == SyncAction.Compare ? Loc.L("Server.Copies.Action.Compare") : Loc.L("Server.Sync.Action." + Action);
public ICommand Command => _command;
public string ToolTip
@@ -68,12 +68,14 @@ public sealed class SyncRow : ObservableObject
private readonly Func _act;
private SyncEntry _entry;
private SyncRights _rights;
+ private SyncMark _mark;
private IReadOnlyList _actions = [];
- public SyncRow(SyncEntry entry, SyncRights rights, Func act)
+ public SyncRow(SyncEntry entry, SyncRights rights, Func act, SyncMark mark = default)
{
_entry = entry;
_act = act;
+ _mark = mark;
UpdateActions(rights);
}
@@ -82,14 +84,17 @@ public sealed class SyncRow : ObservableObject
public string Title => _entry.Title;
public string LocalText => SyncText.Local(_entry);
public string ServerText => SyncText.Server(_entry);
- public StatusKind StateKind => SyncText.State(_entry).Kind;
- public string StateText => SyncText.State(_entry).Text;
+ /// The row's match and Upload all local skip, if any (owner review 6, #73).
+ public SyncMark Mark => _mark;
+
+ public StatusKind StateKind => SyncText.State(_entry, _mark).Kind;
+ public string StateText => SyncText.State(_entry, _mark).Text;
/// "Clouds over the Langhe: In sync": what a screen reader announces when the state changes (not progress).
public string StateAnnouncement => Loc.L("Server.Sync.Row.State", Title, StateText);
/// The state whole (its fixed column cuts the longer ones), then what it means or what differs.
- public string StateToolTip => string.Join(Loc.Separator, StateText, SyncText.State(_entry).ToolTip);
+ public string StateToolTip => string.Join(Loc.Separator, StateText, SyncText.State(_entry, _mark).ToolTip);
/// Settings differ on both sides: the row is drawn on the warning tint (the word in the State column says it too).
public bool IsConflict => _entry.Status == SyncStatus.Conflict && _entry.Transfer is null;
@@ -101,9 +106,10 @@ public sealed class SyncRow : ObservableObject
}
/// Takes a fresher comparison of the same sequence; buttons the row still offers are kept.
- public void Update(SyncEntry entry, SyncRights rights)
+ public void Update(SyncEntry entry, SyncRights rights, SyncMark mark = default)
{
_entry = entry;
+ _mark = mark;
UpdateActions(rights);
RaiseTexts();
}
@@ -130,7 +136,7 @@ public sealed class SyncRow : ObservableObject
private void UpdateActions(SyncRights rights)
{
_rights = rights;
- var wanted = SyncText.Actions(_entry, rights);
+ var wanted = SyncText.Actions(_entry, rights, _mark);
if (!wanted.SequenceEqual(_actions.Select(a => a.Action)))
{
var kept = _actions.ToDictionary(a => a.Action);
diff --git a/src/Chronos.App/Server/SyncTableViewModel.cs b/src/Chronos.App/Server/SyncTableViewModel.cs
index 81c635ac..bc4b6621 100644
--- a/src/Chronos.App/Server/SyncTableViewModel.cs
+++ b/src/Chronos.App/Server/SyncTableViewModel.cs
@@ -4,10 +4,12 @@ using System.IO;
using System.Windows.Input;
using System.Windows.Threading;
using Chronos.App.Infrastructure;
+using Chronos.App.Server.Copies;
using Chronos.App.Shell;
using Chronos.Core.Diagnostics;
using Chronos.Core.Localization;
using Chronos.Core.Model;
+using Chronos.Data.Copies;
using Chronos.Data.Jobs;
using Chronos.Data.Sync;
using Chronos.Ui.Mvvm;
@@ -19,14 +21,29 @@ public sealed class SyncFilterChip(SyncFilter filter, Action select)
{
private int _count;
private bool _isSelected;
+ private bool _attention;
+ private bool _isVisible = true;
public SyncFilter Filter { get; } = filter;
public string Text => Loc.L("Server.Sync.Filter." + Filter, Formatting.Count(_count));
public string ToolTip => Loc.L("Tooltips.Server.Sync.Filter." + Filter);
public ICommand SelectCommand { get; } = new RelayCommand(() => select(filter));
- /// Conflicts waiting for a choice: the chip is drawn in the warning colour unless it is the selected one.
- public bool NeedsAttention => Filter == SyncFilter.Conflicts && _count > 0;
+ /// Conflicts, or matches, waiting for a choice: the chip is drawn in the warning colour unless it is the selected one.
+ public bool NeedsAttention => Filter == SyncFilter.Conflicts ? _count > 0 : Filter == SyncFilter.FoundCopies && _attention;
+
+ /// Matches: some pair asks for a choice (set by the sync table from the copy list).
+ public bool Attention
+ {
+ get => _attention;
+ set
+ {
+ if (Set(ref _attention, value)) OnPropertyChanged(nameof(NeedsAttention));
+ }
+ }
+
+ /// The Matches chip shows signed out too while this PC has more than one archive; the others only signed in.
+ public bool IsVisible { get => _isVisible; set => Set(ref _isVisible, value); }
public bool IsSelected
{
@@ -86,11 +103,20 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
private int _progressQueued;
private int _reloadQueued;
private bool _attached;
+ private bool _hasArchives;
+
+ /// The local-only sequences the last Upload all local left out, and why (owner review 6, Q8).
+ private readonly Dictionary _skipped = [];
+
+ /// Show was pressed on the Upload all toast: Local only lists the skipped sequences first.
+ private bool _skippedFirst;
public SyncTableViewModel(ShellViewModel shell)
{
_shell = shell;
_chips = [.. Enum.GetValues().Select(f => new SyncFilterChip(f, Select) { IsSelected = f == SyncFilter.All })];
+ Copies = new CopyListViewModel(shell) { ShowList = search => ShowFilter(SyncFilter.FoundCopies, search) };
+ Copies.Changed += OnCopiesChanged;
_uploadAll = new AsyncRelayCommand(UploadAllAsync, () => IsActive && Rights.CanUpload && LocalOnly.Any());
OpenAdminCommand = new RelayCommand(() =>
{
@@ -107,6 +133,22 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
public ObservableCollection Rows { get; } = [];
public IReadOnlyList Chips => _chips;
+
+ /// Server › Matches (owner review 6, #73): shown in place of the rows while its chip is selected.
+ public CopyListViewModel Copies { get; }
+
+ /// The Matches chip is selected: the copy list, its header and Find matches replace the sync rows.
+ public bool IsMatches => _filter == SyncFilter.FoundCopies;
+
+ public bool ShowSyncList => !IsMatches && HasRows;
+ public bool ShowCopyList => IsMatches && Copies.HasRows;
+ public bool ShowCopyEmpty => IsMatches && Copies.IsEmpty;
+
+ /// The chips show while signed in, and signed out while this PC has more than one archive (local matches).
+ public bool ShowChips => IsActive || _hasArchives;
+
+ /// The search box filters the sync rows signed in, and the matches whenever they show.
+ public bool ShowSearch => IsActive || IsMatches;
public ICommand UploadAllCommand => _uploadAll;
public ICommand OpenAdminCommand { get; }
@@ -121,7 +163,9 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
get => _search;
set
{
- if (Set(ref _search, value ?? string.Empty)) ApplyFilter(rebuild: true);
+ if (!Set(ref _search, value ?? string.Empty)) return;
+ Copies.SearchText = _search;
+ ApplyFilter(rebuild: true);
}
}
@@ -130,7 +174,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
public bool HasRows => Rows.Count > 0;
- public SyncEmpty Empty => HasRows ? SyncEmpty.None
+ public SyncEmpty Empty => HasRows || IsMatches ? SyncEmpty.None
: !IsActive ? SyncEmpty.SignedOut
: _entries.Count == 0 ? SyncEmpty.Nothing
: SyncEmpty.NoMatch;
@@ -149,6 +193,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
!IsActive ? Loc.L("Tooltips.Server.Sync.UploadAll.NotConnected")
: !Rights.CanUpload ? Loc.L("Tooltips.Server.Sync.UploadAll.NoRight")
: !LocalOnly.Any() ? Loc.L("Tooltips.Server.Sync.UploadAll.Nothing")
+ : SelectUploads(new HashSet()).Skipped.Count is > 0 and var skipping ? Loc.Plural("Tooltips.Server.Sync.UploadAllSkipping", skipping)
: Loc.Plural("Tooltips.Server.Sync.UploadAll", LocalOnly.Count(), Formatting.Bytes(LocalOnly.Sum(e => e.Local!.TotalBytes)));
/// "Last sync 10:15 · manifest diff 0.4 s"; null before the first comparison.
@@ -187,9 +232,17 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
jobs.JobChanged += OnJobChanged;
jobs.Progress += OnProgress;
}
+ Copies.Attach();
_ = ReloadAsync();
}
+ /// Selects a chip (the Matches toasts' Review and Show, Library › Compare…), with a search text when given.
+ internal void ShowFilter(SyncFilter filter, string? search = null)
+ {
+ if (search is not null) SearchText = search;
+ Select(filter);
+ }
+
/// Reads the table again; requests made while a pass runs share the next one, which they wait for.
public async Task ReloadAsync()
{
@@ -224,20 +277,81 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
jobs.JobChanged -= OnJobChanged;
jobs.Progress -= OnProgress;
}
+ Copies.Changed -= OnCopiesChanged;
+ Copies.Dispose();
}
private void Select(SyncFilter filter)
{
_filter = filter;
+ if (filter != SyncFilter.LocalOnly) _skippedFirst = false;
foreach (var chip in _chips) chip.IsSelected = chip.Filter == filter;
ApplyFilter(rebuild: true);
+ RaiseLists();
}
+ private void RaiseLists()
+ {
+ OnPropertyChanged(nameof(IsMatches));
+ OnPropertyChanged(nameof(ShowSyncList));
+ OnPropertyChanged(nameof(ShowCopyList));
+ OnPropertyChanged(nameof(ShowCopyEmpty));
+ OnPropertyChanged(nameof(ShowChips));
+ OnPropertyChanged(nameof(ShowSearch));
+ OnPropertyChanged(nameof(Empty));
+ OnPropertyChanged(nameof(EmptyText));
+ }
+
+ /// The copy list reloaded: the Matches chip's count and colour, its visibility, and the rows' marks.
+ private void OnCopiesChanged()
+ {
+ var chip = _chips.Single(c => c.Filter == SyncFilter.FoundCopies);
+ chip.Count = Copies.Count;
+ chip.Attention = Copies.AttentionCount > 0;
+ _ = UpdateArchivesAsync();
+ ApplyFilter(rebuild: false);
+ OnPropertyChanged(nameof(UploadAllToolTip));
+ RaiseLists();
+ }
+
+ /// Whether this PC has more than one archive (the Matches chip shows signed out then).
+ private async Task UpdateArchivesAsync()
+ {
+ if (_shell.Services.Database is not { } db) return;
+ try
+ {
+ _hasArchives = (await db.Archives.ListAsync()).Count > 1;
+ }
+ catch (Data.DatabaseException)
+ {
+ _hasArchives = false;
+ }
+ UpdateChipVisibility();
+ OnPropertyChanged(nameof(ShowChips));
+ }
+
+ private void UpdateChipVisibility()
+ {
+ foreach (var chip in _chips) chip.IsVisible = chip.Filter == SyncFilter.FoundCopies ? IsActive || _hasArchives : IsActive;
+ }
+
+ /// What the Matches list adds to the row of : its pair and why Upload all left it out.
+ private SyncMark Mark(SyncEntry entry) => entry.Local is { } local
+ ? new SyncMark(Copies.PairOf(local.Id), _skipped.TryGetValue(local.Id, out var why) ? why : null, _shell.Services.Server.Flow.Info?.Name)
+ : new SyncMark(Copies.PairOf(entry.Id), null, _shell.Services.Server.Flow.Info?.Name);
+
+ /// The rule of Upload all local (design §6.4): what it sends, and what it leaves out and why.
+ private (IReadOnlyList Upload, IReadOnlyList<(SyncEntry Entry, UploadSkip Why)> Skipped) SelectUploads(IReadOnlySet busy) =>
+ UploadAllRule.Select(LocalOnly, [.. Copies.Pairs.Select(p => p.Copy)],
+ _shell.Services.Settings.KnownServers.Select(k => k.OriginalsArchiveId).OfType().ToHashSet(), busy);
+
/// Counts, rows, footer and the Library's sync glyphs after a reload.
private void Refresh()
{
- foreach (var chip in _chips) chip.Count = _entries.Count(e => SyncText.Matches(e, chip.Filter, string.Empty));
+ foreach (var chip in _chips.Where(c => c.Filter != SyncFilter.FoundCopies)) chip.Count = _entries.Count(e => SyncText.Matches(e, chip.Filter, string.Empty));
+ UpdateChipVisibility();
ApplyFilter(rebuild: false);
+ RaiseLists();
UpdateLibrary();
OnPropertyChanged(nameof(IsActive));
OnPropertyChanged(nameof(UploadAllToolTip));
@@ -257,6 +371,8 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
{
var rights = Rights;
var wanted = _entries.Where(e => SyncText.Matches(e, _filter, _search.Trim())).ToList();
+ // Show on the Upload all toast: the sequences it left out lead Local only.
+ if (_skippedFirst) wanted = [.. wanted.OrderByDescending(e => e.Local is { } l && _skipped.ContainsKey(l.Id))];
var byId = Rows.ToDictionary(r => r.Id);
if (rebuild)
{
@@ -270,7 +386,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
var entry = wanted[i];
if (i < Rows.Count && Rows[i].Id == entry.Id)
{
- Rows[i].Update(entry, rights);
+ Rows[i].Update(entry, rights, Mark(entry));
continue;
}
var row = Row(entry, rights, byId);
@@ -288,8 +404,8 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
/// The existing row of an entry, updated, or a new one.
private SyncRow Row(SyncEntry entry, SyncRights rights, Dictionary existing)
{
- if (!existing.TryGetValue(entry.Id, out var row)) return new SyncRow(entry, rights, ActAsync);
- row.Update(entry, rights);
+ if (!existing.TryGetValue(entry.Id, out var row)) return new SyncRow(entry, rights, ActAsync, Mark(entry));
+ row.Update(entry, rights, Mark(entry));
return row;
}
@@ -309,6 +425,9 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
var entry = row.Entry;
switch (action)
{
+ case SyncAction.Compare:
+ Copies.Compare(entry.Local?.Id ?? entry.Id);
+ return;
case SyncAction.Upload:
await service.EnqueueUploadAsync(engine, server, entry.Local!);
break;
@@ -396,16 +515,34 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
private async Task UploadAllAsync()
{
if (Host is not { Service: { } service, Server: { } server } || _shell.Services.Engine is not { } engine) return;
- var queued = 0;
- foreach (var entry in LocalOnly.ToList())
+ // Suspected matches, kept-apart sequences, those the server deleted, those an Integrate or Merge holds and those of a
+ // server's originals archive stay, flagged "skipped" with the reason (owner review 6, Q8).
+ var busy = new HashSet();
+ if (_shell.Services.Database is { } db)
{
- await service.EnqueueUploadAsync(engine, server, entry.Local!);
- queued++;
+ busy.UnionWith(await db.Jobs.ListPendingTargetsAsync(JobKind.Integrate));
+ busy.UnionWith(await db.Jobs.ListPendingTargetsAsync(JobKind.MergeSequences));
}
- _shell.Notify(Loc.Plural("Server.Sync.Queued", queued));
+ var (upload, skipped) = SelectUploads(busy);
+ _skipped.Clear();
+ foreach (var (entry, why) in skipped) _skipped[entry.Local!.Id] = why;
+ foreach (var entry in upload) await service.EnqueueUploadAsync(engine, server, entry.Local!);
+ if (skipped.Count == 0) _shell.Notify(Loc.Plural("Server.Sync.Queued", upload.Count));
+ else
+ _shell.Notify(Loc.L("Server.Sync.QueuedSkipped", Formatting.Count(upload.Count), Formatting.Count(skipped.Count)), null,
+ Loc.L("Server.Sync.Show"), Loc.L("Tooltips.Server.Sync.ShowSkipped"), ShowSkipped);
await ReloadAsync();
}
+ /// Show on the Upload all toast: Local only, the skipped sequences first.
+ private void ShowSkipped()
+ {
+ _shell.Navigate(SectionKey.Server);
+ Select(SyncFilter.LocalOnly);
+ _skippedFirst = true;
+ ApplyFilter(rebuild: true);
+ }
+
private void OnChanged() => Dispatch(() => _ = ReloadAsync());
private void OnCultureChanged(object? sender, EventArgs e) => Dispatch(() =>
@@ -417,7 +554,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
private void OnJobChanged(Job job)
{
- if (job.Kind is not (JobKind.UploadCommit or JobKind.Download)) return;
+ if (job.Kind is not (JobKind.UploadCommit or JobKind.Download or JobKind.Integrate or JobKind.MergeSequences)) return;
_progress.TryRemove(job.Id, out _);
Dispatch(() =>
{
diff --git a/src/Chronos.App/Server/SyncText.cs b/src/Chronos.App/Server/SyncText.cs
index e51b6e8d..c416db80 100644
--- a/src/Chronos.App/Server/SyncText.cs
+++ b/src/Chronos.App/Server/SyncText.cs
@@ -18,6 +18,9 @@ public enum SyncFilter
LocalOnly,
Remote,
Conflicts,
+
+ /// Matches (owner review 6, #73): the list is CopyList, not sync rows.
+ FoundCopies,
}
/// What a row of the sync table offers.
@@ -40,6 +43,19 @@ public enum SyncAction
/// that keeps no projects, whose sequences open with proxies as before.
///
OpenInWorkspace,
+
+ /// Compare the row's sequence with its match (owner review 6, #73).
+ Compare,
+}
+
+///
+/// What the Matches list adds to a sync row (owner review 6, #73): the pair the row's sequence is in, and why Upload all
+/// local left it out.
+///
+public readonly record struct SyncMark(Data.Copies.FoundCopy? Copy, Data.Copies.UploadSkip? Skipped, string? ServerName = null)
+{
+ /// The row's sequence is in a pair nobody answered yet.
+ public bool IsCandidate => Copy is { State: Data.Copies.CopyState.Candidate, RemoteGone: false };
}
/// What the signed-in account may do (server permission bits), and whether its server keeps projects.
@@ -163,6 +179,46 @@ public static class SyncText
};
}
+ ///
+ /// The State column with what the Matches list knows (owner review 6, #73): a transfer still shows first; then a sequence
+ /// in an unanswered pair reads "match found", one whose server copy was deleted "deleted on server" or "kept here", and
+ /// one Upload all local left out "skipped" with the reason.
+ ///
+ public static (StatusKind Kind, string Text, string ToolTip) State(SyncEntry entry, SyncMark mark)
+ {
+ if (entry.Transfer is not null) return State(entry);
+ if (mark.Copy is { RemoteGone: true } gone)
+ {
+ return gone.State == Data.Copies.CopyState.KeptApart
+ ? (StatusKind.Offline, Loc.L("Server.Sync.State.KeptHere"), Loc.L("Tooltips.Server.Copies.State.KeptHere"))
+ : (StatusKind.Warning, Loc.L("Server.Sync.State.RemoteGone"), Loc.L("Tooltips.Server.Copies.State.RemoteGone"));
+ }
+ if (mark.IsCandidate)
+ return (StatusKind.Warning, Loc.L("Server.Sync.State.CopyFound"), Loc.L("Tooltips.Server.Sync.State.CopyFound", mark.ServerName ?? mark.Copy!.Server ?? string.Empty));
+ if (mark.Skipped is { } why && entry.Status == SyncStatus.LocalOnly)
+ return (StatusKind.Offline, Loc.L("Server.Sync.State.Skipped"), Loc.L("Tooltips.Server.Sync.State.Skipped", Loc.L("Tooltips.Server.Sync.Skip." + why)));
+ return State(entry);
+ }
+
+ ///
+ /// The row's buttons with its match (design §8.1): a sequence in an unanswered pair offers Compare… first, then its usual
+ /// buttons; a linked one offers Compare… last.
+ ///
+ public static IReadOnlyList Actions(SyncEntry entry, SyncRights rights, SyncMark mark)
+ {
+ var actions = Actions(entry, rights);
+ if (entry.Transfer is not null || mark.Copy is null || mark.Copy.RemoteGone) return actions;
+ if (mark.IsCandidate) return [SyncAction.Compare, .. actions];
+ return entry.Link is not null ? [.. actions, SyncAction.Compare] : actions;
+ }
+
+ /// The label of a detail line of the Compare dialog ("Deflicker window"); "Other setting" when unknown.
+ public static string DetailLabel(string path)
+ {
+ var (key, _) = Setting(path);
+ return key == "Server.Setting.Other" ? Loc.L("Server.Copies.Detail.OtherSetting") : Loc.L(key);
+ }
+
/// One line for the State tooltip: "Deflicker window 41 here, 33 on the server · +2".
public static string ConflictSummary(SyncEntry entry)
{
@@ -283,6 +339,9 @@ public static class SyncText
/// The bytes an action moves (for the tooltips).
public static long Size(SyncEntry entry, SyncAction action) => action switch
{
+ // A linked sequence sends only the photos the server lacks: their share of the sequence's bytes.
+ SyncAction.Upload when entry is { Link.MissingRemote: > 0 and var missing, Local: { FrameCount: > 0 } local } && missing < local.FrameCount =>
+ (long)Math.Round((double)local.TotalBytes * missing / local.FrameCount),
SyncAction.Upload => entry.Local?.TotalBytes ?? 0,
SyncAction.DownloadOriginals => entry.Link?.TotalBytes ?? 0,
SyncAction.GetExports => entry.Link?.ExportsToGetBytes ?? 0,
@@ -300,6 +359,7 @@ public static class SyncText
SyncAction.GetExports => Loc.Plural("Tooltips.Server.Sync.GetExports", entry.Link!.ExportsToGet, Formatting.Bytes(Size(entry, action))),
SyncAction.SendExports => Loc.Plural("Tooltips.Server.Sync.SendExports", entry.Link!.ExportsToSend, Formatting.Bytes(Size(entry, action))),
SyncAction.OpenInWorkspace when !rights.KeepsProjects => Loc.L("Tooltips.Server.Sync.OpenInWorkspace.NoProjects"),
+ SyncAction.Compare => Loc.L("Tooltips.Server.Copies.Compare"),
_ => Loc.L("Tooltips.Server.Sync." + action),
};
@@ -314,6 +374,7 @@ public static class SyncText
SyncFilter.Remote => entry.Status is SyncStatus.RemoteOnly or SyncStatus.ProxiesOnly
|| entry is { Status: SyncStatus.Transferring, HasLocalOriginals: false, Link: not null },
SyncFilter.Conflicts => entry.Status == SyncStatus.Conflict,
+ SyncFilter.FoundCopies => false,
_ => true,
}) && (search.Length == 0 || entry.Title.Contains(search, StringComparison.CurrentCultureIgnoreCase));
diff --git a/src/Chronos.App/Settings/CopySettingsRows.cs b/src/Chronos.App/Settings/CopySettingsRows.cs
new file mode 100644
index 00000000..826b8547
--- /dev/null
+++ b/src/Chronos.App/Settings/CopySettingsRows.cs
@@ -0,0 +1,94 @@
+using Chronos.App.Infrastructure;
+using Chronos.Core.Localization;
+using Chronos.Data.Copies;
+using Chronos.Ui.Mvvm;
+
+namespace Chronos.App.Settings;
+
+///
+/// The matches rows of Settings › Server (owner review 6, #73, design §7): Link matches, Integrate photos and Integrate
+/// projects, each option with its tooltip. Each value is stored and saved at once; the rows read
+/// each time, so Reset and Import show the new values.
+///
+public sealed class CopySettingsRows(AppSettings settings, Action save) : ObservableObject
+{
+ public IReadOnlyList> LinkingOptions { get; private set; } = LinkingList();
+ public IReadOnlyList> PhotoOptions { get; private set; } = Photos();
+ public IReadOnlyList> ProjectOptions { get; private set; } = Projects();
+
+ public SettingsOption Linking
+ {
+ get => LinkingOptions.FirstOrDefault(o => o.Value == settings.CopyLinking) ?? LinkingOptions[0];
+ set
+ {
+ if (value is null || value.Value == settings.CopyLinking) return;
+ settings.CopyLinking = value.Value;
+ save();
+ OnPropertyChanged();
+ }
+ }
+
+ public SettingsOption PhotoPolicy
+ {
+ get => PhotoOptions.FirstOrDefault(o => o.Value == settings.CopyPhotos) ?? PhotoOptions[0];
+ set
+ {
+ if (value is null || value.Value == settings.CopyPhotos) return;
+ settings.CopyPhotos = value.Value;
+ save();
+ OnPropertyChanged();
+ }
+ }
+
+ public SettingsOption ProjectsChoice
+ {
+ get => ProjectOptions.FirstOrDefault(o => o.Value == settings.CopyProjects) ?? ProjectOptions[0];
+ set
+ {
+ if (value is null || value.Value == settings.CopyProjects) return;
+ settings.CopyProjects = value.Value;
+ save();
+ OnPropertyChanged();
+ }
+ }
+
+ /// The defaults of a new installation.
+ internal void Reset()
+ {
+ var defaults = new AppSettings();
+ settings.CopyLinking = defaults.CopyLinking;
+ settings.CopyPhotos = defaults.CopyPhotos;
+ settings.CopyProjects = defaults.CopyProjects;
+ Refresh();
+ }
+
+ /// Values another screen (or an import) changed, and labels in the current language.
+ internal void Refresh()
+ {
+ LinkingOptions = LinkingList();
+ PhotoOptions = Photos();
+ ProjectOptions = Projects();
+ OnAllPropertiesChanged();
+ }
+
+ private static IReadOnlyList> LinkingList() =>
+ [
+ new(CopyLinking.AskAlways, Loc.L("Settings.Server.CopyLinking.AskAlways"), Loc.L("Tooltips.Settings.CopyLinking.AskAlways")),
+ new(CopyLinking.WhenIdentical, Loc.L("Settings.Server.CopyLinking.WhenIdentical"), Loc.L("Tooltips.Settings.CopyLinking.WhenIdentical")),
+ new(CopyLinking.WhenHalfShared, Loc.L("Settings.Server.CopyLinking.WhenHalf"), Loc.L("Tooltips.Settings.CopyLinking.WhenHalf")),
+ ];
+
+ private static IReadOnlyList> Photos() =>
+ [
+ new(CopyPhotoPolicy.Union, Loc.L("Server.Copies.Policy.Union"), Loc.L("Tooltips.Settings.CopyPhotos.Union")),
+ new(CopyPhotoPolicy.ChoosePerPhoto, Loc.L("Server.Copies.Policy.ChoosePerPhoto"), Loc.L("Tooltips.Settings.CopyPhotos.ChoosePerPhoto")),
+ new(CopyPhotoPolicy.ThisPcWins, Loc.L("Server.Copies.Policy.ThisPcWins"), Loc.L("Tooltips.Settings.CopyPhotos.ThisPcWins")),
+ new(CopyPhotoPolicy.OtherWins, Loc.L("Server.Copies.Policy.OtherWins"), Loc.L("Tooltips.Settings.CopyPhotos.OtherWins")),
+ ];
+
+ private static IReadOnlyList> Projects() =>
+ [
+ new(CopyProjects.CopyAcross, Loc.L("Server.Copies.Projects.CopyAcross"), Loc.L("Tooltips.Settings.CopyProjects.CopyAcross")),
+ new(CopyProjects.Leave, Loc.L("Server.Copies.Projects.Leave"), Loc.L("Tooltips.Settings.CopyProjects.Leave")),
+ ];
+}
diff --git a/src/Chronos.App/Settings/SettingsRows.cs b/src/Chronos.App/Settings/SettingsRows.cs
index 5750f5ed..6a97104a 100644
--- a/src/Chronos.App/Settings/SettingsRows.cs
+++ b/src/Chronos.App/Settings/SettingsRows.cs
@@ -59,8 +59,8 @@ public sealed class SettingsPageItem(SettingsPage page, Func
internal void Refresh() => OnAllPropertiesChanged();
}
-/// A choice of a settings dropdown.
-public sealed record SettingsOption(T Value, string Label)
+/// A choice of a settings dropdown; says what the choice does (null: the box's tooltip only).
+public sealed record SettingsOption(T Value, string Label, string? ToolTip = null)
{
public override string ToString() => Label;
}
diff --git a/src/Chronos.App/Shell/ScreenCapture.cs b/src/Chronos.App/Shell/ScreenCapture.cs
index 422c5b71..43d2e4e9 100644
--- a/src/Chronos.App/Shell/ScreenCapture.cs
+++ b/src/Chronos.App/Shell/ScreenCapture.cs
@@ -12,6 +12,7 @@ using Chronos.App.Import;
using Chronos.App.Infrastructure;
using Chronos.App.Library;
using Chronos.App.Server;
+using Chronos.App.Server.Copies;
using Chronos.App.Settings;
using Chronos.Core.Diagnostics;
using Chronos.Core.Imaging.Geometry;
@@ -189,6 +190,7 @@ public static class ScreenCapture
written += await CaptureEditorAsync(window, shell, sample, directory);
written += await CaptureRemoteEditorAsync(window, shell, sample, directory);
+ written += await CaptureCopiesAsync(window, shell, sample, directory);
Log.Info("capture", $"{written} screenshot(s) written to {Path.GetFullPath(directory)}");
if (written == 0) Environment.ExitCode = 1;
}
@@ -291,6 +293,58 @@ public static class ScreenCapture
return written;
}
+ ///
+ /// Matches (owner review 6, #73, design §8.7), last as they add sequences of their own: the list, its toast, the dialog
+ /// at each part and list, the plan with and without a block, the merge, the two destructive confirmations, the sync rows
+ /// a pair marks, the Library's cards, the empty list, and the list signed out (local pairs only).
+ ///
+ private static async Task CaptureCopiesAsync(MainWindow window, ShellViewModel shell, SampleData sample, string directory)
+ {
+ var written = 0;
+ var engine = await sample.FillCopiesAsync();
+ await shell.Library.RefreshAsync();
+ foreach (var theme in Themes)
+ {
+ ThemeManager.Apply(theme);
+ foreach (var view in CopyScenes.Views)
+ {
+ DismissToasts(window);
+ await CopyScenes.ShowAsync(shell, view);
+ written += await SaveAsync(window, directory, view, theme);
+ }
+ CopyScenes.Reset(shell);
+ if (await CopyScenes.ReplaceRequestAsync(shell) is { } replace)
+ written += await SaveDialogAsync(new ConfirmDialog(replace), directory, "server-copies-replace-confirm", theme);
+ if (await CopyScenes.MergeRequestAsync(shell) is { } merge)
+ written += await SaveDialogAsync(new ConfirmDialog(merge), directory, "server-copies-confirm", theme);
+ CopyScenes.Reset(shell);
+ DismissToasts(window);
+ await LibraryScenes.ShowCopiesAsync(shell, CopyScenes.Alps);
+ written += await SaveAsync(window, directory, "library-copies", theme, waitForThumbnails: shell);
+ shell.Library.SearchText = string.Empty;
+ }
+
+ // No pair at all, then signed out: only this PC's own pairs stay (the chip shows with two archives).
+ shell.Services.Sync.Copies = new SampleCopyEngine();
+ foreach (var theme in Themes)
+ {
+ ThemeManager.Apply(theme);
+ DismissToasts(window);
+ await CopyScenes.ShowAsync(shell, "server-copies");
+ written += await SaveAsync(window, directory, "server-copies-empty", theme);
+ }
+ shell.Services.Sync.Copies = engine;
+ CopyScenes.Reset(shell);
+ await shell.Services.Server.SignOutAsync();
+ foreach (var theme in Themes)
+ {
+ ThemeManager.Apply(theme);
+ DismissToasts(window);
+ await CopyScenes.ShowAsync(shell, "server-copies");
+ written += await SaveAsync(window, directory, "server-copies-signedout", theme);
+ }
+ return written;
+ }
private static void SelectSyncFilter(ShellViewModel shell, SyncFilter filter) =>
shell.Server.Sync.Chips.First(c => c.Filter == filter).SelectCommand.Execute(null);
diff --git a/src/Chronos.App/Workspace/WorkspaceProjectItem.cs b/src/Chronos.App/Workspace/WorkspaceProjectItem.cs
index f61180c4..7154b158 100644
--- a/src/Chronos.App/Workspace/WorkspaceProjectItem.cs
+++ b/src/Chronos.App/Workspace/WorkspaceProjectItem.cs
@@ -15,9 +15,32 @@ namespace Chronos.App.Workspace;
public sealed class WorkspaceProjectItem(WorkspaceEntry entry, SequenceItem? sequence) : ObservableObject
{
private WorkspaceStatus? _status;
+ private string? _twinHome;
+ private string? _twinProject;
public WorkspaceEntry Entry { get; } = entry;
+ ///
+ /// The other home of the same time-lapse (a linked or integrated match) when it has a workspace project too; null
+ /// otherwise (owner review 6, #73). The picker shows a muted Twin chip after the name.
+ ///
+ public string? TwinHome => _twinHome;
+
+ public bool HasTwin => _twinHome is not null;
+
+ /// "Also at nas: Vertical."
+ public string? TwinToolTip => _twinHome is null ? null : Loc.L("Tooltips.Editor.Picker.Twin", _twinHome, _twinProject ?? string.Empty);
+
+ /// Marks the item as the twin of at (null: none).
+ public void SetTwin(string? home, string? project)
+ {
+ _twinHome = home;
+ _twinProject = project;
+ OnPropertyChanged(nameof(TwinHome));
+ OnPropertyChanged(nameof(HasTwin));
+ OnPropertyChanged(nameof(TwinToolTip));
+ }
+
/// The sequence's row of the library, for its thumbnail; null when the index no longer has it.
public SequenceItem? Sequence { get; } = sequence;
diff --git a/tests/Chronos.App.Tests/Server/CopyScreenSmokeTests.cs b/tests/Chronos.App.Tests/Server/CopyScreenSmokeTests.cs
new file mode 100644
index 00000000..b6963b24
--- /dev/null
+++ b/tests/Chronos.App.Tests/Server/CopyScreenSmokeTests.cs
@@ -0,0 +1,193 @@
+using System.Windows.Controls;
+using Chronos.App.Infrastructure;
+using Chronos.App.Library;
+using Chronos.App.Sections;
+using Chronos.App.Server;
+using Chronos.App.Server.Copies;
+using Chronos.App.Settings;
+using Chronos.App.Shell;
+using Chronos.App.Tests.Windows;
+using Chronos.Core.Localization;
+using Chronos.Data.Copies;
+using Chronos.Data.Sync;
+using Chronos.Testing;
+using Chronos.Ui.Controls;
+
+namespace Chronos.App.Tests.Server;
+
+///
+/// Server › Matches on the capture sample pairs (owner review 6, #73): the list and its chip, the Compare dialog in the
+/// window, its plan and blocks, the confirmations, the Library's match cards and the Settings rows.
+///
+[WindowsOnly]
+[Serial]
+[Timeout(300_000)]
+public sealed class CopyScreenSmokeTests
+{
+ [Test]
+ public Task TheMatchesListOrdersThePairsAndEveryActionSaysWhatItDoes() => ScreenHost.RunAsync(async () =>
+ {
+ await using var app = await StartAsync();
+ var shell = app.Shell;
+ var table = shell.Server.Sync;
+ var list = table.Copies;
+ await CopyScenes.ShowAsync(shell, "server-copies");
+
+ Assert.True(table.IsMatches);
+ Assert.True(table.ShowCopyList, "the Matches list replaces the sync table");
+ Assert.GreaterOrEqual(list.Count, 5);
+ Assert.Equal(list.Count, table.Chips.Single(c => c.Filter == SyncFilter.FoundCopies).Count);
+ Assert.True(list.AttentionCount > 0);
+ // Pairs that ask for a choice come first.
+ Assert.True(list.Rows[0].IsConflict);
+ Assert.True(list.Rows.SkipWhile(r => r.IsConflict).All(r => !r.IsConflict), "attention first, then the rest");
+ foreach (var row in list.Rows)
+ {
+ Assert.False(string.IsNullOrWhiteSpace(row.StateToolTip), $"{row.Title}: the state has a tooltip");
+ foreach (var action in row.Actions)
+ {
+ Assert.False(string.IsNullOrWhiteSpace(action.ToolTip), $"{row.Title}: {action.Text} has a tooltip");
+ Assert.LessOrEqual(action.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries).Length, 3, $"\"{action.Text}\" is at most three words");
+ }
+ }
+ var lighthouse = list.Rows.Single(r => r.Title == CopyScenes.Lighthouse);
+ Assert.SequenceEqual([CopyAction.Compare, CopyAction.Integrate, CopyAction.KeepApart], lighthouse.Actions.Select(a => a.Action));
+ Assert.SequenceEqual([CopyAction.Compare, CopyAction.Merge, CopyAction.KeepApart],
+ list.Rows.Single(r => r.Title == CopyScenes.Alps).Actions.Select(a => a.Action));
+ await app.ExpectAsync("server-copies");
+
+ // The search narrows the pairs, by either title.
+ table.SearchText = "Alps";
+ Assert.Count(1, list.Rows);
+ table.SearchText = string.Empty;
+
+ // The sync table marks the sequence of an unanswered pair and offers Compare… first.
+ table.ShowFilter(SyncFilter.All);
+ var marked = table.Rows.First(r => r.Title == CopyScenes.Lighthouse);
+ Assert.Equal(Loc.L("Server.Sync.State.CopyFound"), marked.StateText);
+ Assert.Equal(SyncAction.Compare, marked.Actions[0].Action);
+ CopyScenes.Reset(shell);
+ });
+
+ [Test]
+ public Task TheCompareDialogWaitsForTheDetailsAndConfirmsWhatItReplaces() => ScreenHost.RunAsync(async () =>
+ {
+ await using var app = await StartAsync();
+ var shell = app.Shell;
+ var server = shell.Server;
+ var list = server.Sync.Copies;
+ await CopyScenes.ShowAsync(shell, "server-copies");
+
+ // Integrate… opens on the details while one waits for a choice.
+ var pair = list.Pairs.Single(p => p.Here.Title == CopyScenes.Lighthouse);
+ var dialog = Assert.NotNull(list.Open(pair, CopyDialogPart.Plan, integrate: true));
+ await dialog.LoadAsync();
+ Assert.True(server.IsDialogOpen);
+ Assert.False(server.IsContentEnabled, "the screen behind the dialog takes no input");
+ Assert.Equal(CopyDialogPart.Details, dialog.Part);
+ Assert.Equal(3, dialog.Unchosen);
+ await app.ExpectAsync("server-copies-details");
+
+ // The footer: one primary action, Cancel answers Esc; both say what they do.
+ var cancel = app.FindAll