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, ISelectableRow { private readonly Action _changed; private readonly bool _swapped; private bool _bring; private bool _isSelected; private SettingsOption? _choice; /// A merge keeping the pair's other sequence: the photo's second side is the kept one. public CopyPhotoRow(ComparedPhoto photo, bool isMerge, bool canBring, bool canChoose, IReadOnlyList> choices, PhotoChoice? current, Action changed, Func? drop, bool swapped = false) { Photo = photo; IsMerge = isMerge; _swapped = isMerge && swapped; CanBring = canBring; CanChoose = canChoose; Choices = choices; _changed = changed; _bring = current == PhotoChoice.Bring; _choice = current is { } c and not PhotoChoice.Bring ? choices.FirstOrDefault(o => o.Value == c) : null; if (drop is not null) DropCommand = new AsyncRelayCommand(() => drop(this)); } public ComparedPhoto Photo { get; } public bool IsMerge { get; } public string Key => Photo.Key; private CopyPhotoInput? Input => Photo.Here ?? Photo.There; public string TimeText => Input?.CapturedAt is { } at ? Formatting.Date(at) + " " + at.ToString("T", Loc.Culture) : string.Empty; public string Name => Input?.FileName ?? Photo.Key; public string SizeText => Formatting.Bytes(Photo.Bytes); /// "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 != _swapped ? "Server.Copies.Detail.Kept" : "Server.Copies.Detail.Other") : here ? "Server.Copies.Detail.ThisPc" : "Server.Copies.Detail.Server"); }