feat(app): Convert sequences from the Archive manager and the Library, with Undo after a Replace
Owner review 2, R7 asks for mass conversion after import on the desktop too, with a choice at every run between Replace and New sequence. The desktop now uses the engine's conversion, the same plan and job as the web panel. - Convert... in the Archive manager's mass operations (the set) and the Library's mass bar (the selection of one archive; server cards are left out, two archives are refused with their own reason). The dialog has the format (JPEG, TIFF 16-bit, Linear DNG, the archival default), a JPEG's quality (1-100, 95) and the mode, which starts unchosen at every open: Apply waits for it. Each choice has a tooltip that says what becomes of the originals. - The dry run stays in the dialog and follows the choices: each sequence with its photos and sizes before and after, the photos that stay as they are with why, the sequences left as they are (busy, offline, unreadable), a summary and the free space line; a volume without the space blocks Apply. The mode does not change what converts, so choosing it plans nothing again. - Apply asks to type the number of photos a Replace replaces, then queues the convert job of exactly the plan shown; New sequence leaves the originals as they are and asks nothing. - When a Replace job ends, its toast offers Undo: for each sequence it converted, the newest Replaced trash entry made while it ran goes back (a sequence changed since gets its originals as a new sequence). Undo runs once and never from the Windows notification. - The Library and the Archive screen read the sequences again after a conversion; --capture renders archive-convert from a sample plan. - Strings in en and it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 275469284f895fc92e2569339809e18bf59d1d6a) (cherry picked from commit 76ba41f58983275ae4b1478edd403efb11da7c79)
This commit is contained in:
1 parent
2143a093a2
commit
a1c1c21ebd
25 files changed
+1409
-19
No files matched your search
@@ -0,0 +1,130 @@
|
||||
using System.Globalization;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Core.Conversion;
|
||||
using Chronos.Core.Localization;
|
||||
|
||||
namespace Chronos.App.Archiving;
|
||||
|
||||
/// <summary>
|
||||
/// One sequence of the conversion dry run (owner review 2, R7): its name, what converts (photos, size before and after),
|
||||
/// and the photos that stay as they are or why the whole sequence is left as it is, each line with why.
|
||||
/// </summary>
|
||||
/// <param name="IsNamePath">The sequence has no title: <paramref name="Name"/> is its folder, read left to right.</param>
|
||||
/// <param name="IsBlocked">Nothing of the sequence converts now (busy, offline, unreadable).</param>
|
||||
public sealed record ConvertRow(Guid SequenceId, string Name, bool IsNamePath, string Note, IReadOnlyList<string> Kept, bool IsBlocked)
|
||||
{
|
||||
public bool HasNote => Note.Length > 0;
|
||||
|
||||
public bool HasKept => Kept.Count > 0;
|
||||
|
||||
/// <summary>What a screen reader says after the name: what converts, then every line of what stays.</summary>
|
||||
public string Description => string.Join(Environment.NewLine, [.. HasNote ? [Note] : (string[])[], .. Kept]);
|
||||
}
|
||||
|
||||
/// <summary>The free space line of a conversion dry run, and whether the volume lacks the space.</summary>
|
||||
public sealed record ConvertSpaceLine(string Text, bool IsShort);
|
||||
|
||||
/// <summary>
|
||||
/// The words of a mass conversion (owner review 2, R7; BRIEF §12.5): the engine's dry run (<see cref="ConvertPlan"/>) as
|
||||
/// rows, a summary and the free space line, and the typed confirmation a Replace asks for.
|
||||
/// </summary>
|
||||
public static class ConvertPlans
|
||||
{
|
||||
/// <summary>The targets in the order the dialog offers them.</summary>
|
||||
public static readonly IReadOnlyList<ConvertTarget> Targets = [ConvertTarget.Jpeg, ConvertTarget.Tiff16, ConvertTarget.LinearDng];
|
||||
|
||||
/// <summary>The problem of a JPEG quality as typed, localized; null when it is 1–100.</summary>
|
||||
public static string? ValidateQuality(string? text) =>
|
||||
int.TryParse(text?.Trim(), NumberStyles.Integer, Loc.Culture, out var quality) && quality is >= 1 and <= 100
|
||||
? null
|
||||
: Loc.L("Errors.Number.Range", 1.ToString("N0", Loc.Culture), 100.ToString("N0", Loc.Culture));
|
||||
|
||||
/// <summary>A valid quality as typed (see <see cref="ValidateQuality"/>).</summary>
|
||||
public static int ParseQuality(string text) => int.Parse(text.Trim(), NumberStyles.Integer, Loc.Culture);
|
||||
|
||||
/// <summary>The rows of a plan in its order: every sequence that converts, or whose photos stay as they are, with why.</summary>
|
||||
public static IReadOnlyList<ConvertRow> Rows(ConvertPlan plan)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(plan);
|
||||
return [.. plan.Sequences.Where(s => s.Frames.Count > 0 || s.Skipped.Count > 0 || s.Blocked.Count > 0).Select(Row)];
|
||||
}
|
||||
|
||||
public static ConvertRow Row(ConvertSequencePlan step)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(step);
|
||||
var named = !string.IsNullOrWhiteSpace(step.Title);
|
||||
var name = named ? step.Title : step.Folder.Length > 0 ? step.Folder : step.SequenceId.ToString("N")[..8];
|
||||
var note = step.Converts
|
||||
? Loc.Plural("Shell.Status.Photos", step.Frames.Count) + Loc.Separator + Sizes(step.BytesBefore, step.BytesAfter)
|
||||
: string.Empty;
|
||||
// What blocks the whole sequence comes first: the photos it would skip anyway do not matter until it can convert.
|
||||
List<string> kept = [.. step.Blocked.Distinct().Select(b => Loc.L("Archive.Convert.Blocked." + b))];
|
||||
kept.AddRange(step.Skipped.Select(s => Loc.L("Archive.Convert.Skipped." + s.Reason) + Loc.Separator + Loc.Plural("Shell.Status.Photos", s.Frames)));
|
||||
return new ConvertRow(step.SequenceId, name, !named, note, kept, step.Blocked.Count > 0);
|
||||
}
|
||||
|
||||
/// <summary>"12.4 GB → 9.8 GB".</summary>
|
||||
public static string Sizes(long before, long after) => Loc.L("Archive.Convert.Sizes", Formatting.Bytes(before), Formatting.Bytes(after));
|
||||
|
||||
/// <summary>
|
||||
/// "12 of 36 change · 3,600 photos · 41 GB → 32 GB · 20 skipped": the sequences converted of those planned, then the
|
||||
/// photos and their sizes when something converts, the photos skipped when there are any.
|
||||
/// </summary>
|
||||
public static string Summary(ConvertPlan plan)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(plan);
|
||||
var parts = new List<string> { Loc.Plural("Archive.Rename.Summary", plan.Converted.Count(), plan.Sequences.Count) };
|
||||
if (plan.Frames > 0)
|
||||
{
|
||||
parts.Add(Loc.Plural("Shell.Status.Photos", plan.Frames));
|
||||
parts.Add(Sizes(plan.BytesBefore, plan.BytesAfter));
|
||||
}
|
||||
if (plan.Skipped > 0) parts.Add(Loc.Plural("Archive.Convert.SkippedPhotos", plan.Skipped));
|
||||
return string.Join(Loc.Separator, parts);
|
||||
}
|
||||
|
||||
/// <summary>"Needs 12 GB, free 340 GB", or that the volume lacks it, or that its free space cannot be measured.</summary>
|
||||
public static ConvertSpaceLine Space(ConvertSpace space)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(space);
|
||||
var required = Formatting.Bytes(space.Required);
|
||||
if (space.Free is not { } free) return new(Loc.L("Archive.Convert.SpaceUnknown", required), false);
|
||||
return space.Enough
|
||||
? new(Loc.L("Archive.Convert.Space", required, Formatting.Bytes(free)), false)
|
||||
: new(Loc.L("Archive.Convert.SpaceShort", required, Formatting.Bytes(free)), true);
|
||||
}
|
||||
|
||||
/// <summary>"Linear DNG": the target as the dialog names it.</summary>
|
||||
public static string TargetText(ConvertTarget target) => Loc.L("Archive.Convert.Target." + target);
|
||||
|
||||
/// <summary>
|
||||
/// The destructive confirmation of a Replace: the sequences whose photos are replaced, that the originals move to the
|
||||
/// archive's trash, and the number of photos to type; null when the plan converts nothing.
|
||||
/// </summary>
|
||||
public static ConfirmRequest? ReplaceRequest(ConvertPlan plan)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(plan);
|
||||
var converted = plan.Converted.ToList();
|
||||
if (converted.Count == 0) return null;
|
||||
var count = plan.Frames.ToString(CultureInfo.InvariantCulture);
|
||||
var lines = converted.Take(DeletePlans.ListedLines).Select(s => Loc.L("Archive.Delete.Line", Row(s).Name,
|
||||
Loc.Plural("Shell.Status.Photos", s.Frames.Count), Formatting.Bytes(s.BytesBefore))).ToList();
|
||||
if (converted.Count > DeletePlans.ListedLines) lines.Add(Loc.Plural("Archive.Delete.More", converted.Count - DeletePlans.ListedLines));
|
||||
return new ConfirmRequest
|
||||
{
|
||||
Heading = Loc.Plural("Archive.Convert.ReplaceHeading", converted.Count),
|
||||
Message = Loc.L("Archive.Convert.ReplaceMessage", Loc.Plural("Shell.Status.Photos", plan.Frames), Formatting.Bytes(plan.BytesBefore),
|
||||
TargetText(plan.Options.Target)),
|
||||
Detail = string.Join(Environment.NewLine, lines),
|
||||
IsDetailMonospaced = false,
|
||||
DetailToolTip = Loc.L("Tooltips.Archive.ConvertPlan"),
|
||||
SafeText = Loc.L("Archive.Delete.Keep"),
|
||||
SafeToolTip = Loc.L("Tooltips.Archive.DeleteKeep"),
|
||||
ActionText = Loc.L("Archive.Convert.Replace"),
|
||||
ActionToolTip = Loc.Plural("Tooltips.Archive.ConvertReplace", plan.Frames),
|
||||
IsDestructive = true,
|
||||
TypedConfirmation = count,
|
||||
TypedPrompt = Loc.L("Archive.Delete.Type", count),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user