Files
Chronos/src/Titano.App/Editor/ISequenceSource.cs
T
Alby96 5aeb6aa787 Add comprehensive tests for EditSection functionality in the Windows application
- Implement tests for picker behavior, including loading sequences, searching, and handling empty libraries.
- Validate sequence opening via Enter key and double-click actions.
- Ensure proper handling of unsaved edits and sequence deletion scenarios.
- Verify accessibility features for picker rows across different languages.
- Introduce a dialog counting mechanism to manage unsaved edit confirmations.
2026-10-19 12:10:42 +02:00

122 lines
6.4 KiB
C#

using Titano.Core.Analysis;
using Titano.Core.Analysis.Deep;
using Titano.Core.Imaging;
using Titano.Core.Model;
using Titano.Core.Project;
using Titano.Data.Archiving.Jobs;
namespace Titano.App.Editor;
/// <summary>
/// Where the sequence open in the editor lives: the local archive (<see cref="LocalSequenceSource"/>) or a server the
/// client is connected to (<see cref="RemoteSequenceSource"/>: proxies from the cache, project and jobs through the
/// API). The editor reads frames, saves the project, queues jobs and follows them only through this interface.
/// </summary>
public interface ISequenceSource : IAsyncDisposable
{
/// <summary>
/// The sequence lives on a server (BRIEF §14.5 "edit with proxies, render where the originals are"): its project is
/// saved there and its renders and analyses run there, one job per preset.
/// </summary>
bool IsRemote { get; }
/// <summary>
/// The project is shown, not changed: a server sequence for an account without the Edit right, or one whose frames
/// changed on the server (<see cref="IsOutdated"/>). The editor disables every change and the source refuses to
/// store one. It can turn true while the sequence is open (<see cref="ReadOnlyChanged"/>).
/// </summary>
bool IsReadOnly { get; }
/// <summary>
/// The frames this PC shows are no longer the sequence's (frames added or removed on the server since its proxies
/// were fetched): frame positions in the project would point at other frames, so nothing is saved or rendered until
/// the sequence is opened again with fresh proxies.
/// </summary>
bool IsOutdated { get; }
/// <summary><see cref="IsReadOnly"/> changed (any thread).</summary>
event Action? ReadOnlyChanged;
/// <summary>A job that may concern the sequence changed (any thread): this PC's engine, or the server's events.</summary>
event Action<Job>? JobChanged;
/// <summary>Everything the editor shows of the sequence; read off the UI thread.</summary>
/// <exception cref="EditorException">The sequence is gone, or its project cannot be read (corrupt, or written by a newer Titano).</exception>
Task<SequenceContent> LoadAsync(CancellationToken cancellationToken);
/// <summary>
/// Whether the frames <see cref="LoadAsync"/> read last are still the sequence's, in the same order: frames inserted
/// or removed since (a sync download, an import of earlier photos, a scan) moved the stored project's positions. A
/// server sequence whose frames changed becomes <see cref="IsOutdated"/>.
/// </summary>
/// <exception cref="EditorException">The sequence is gone.</exception>
Task<bool> FramesCurrentAsync(CancellationToken cancellationToken);
/// <summary>
/// Frame <paramref name="index"/> in linear light, oriented, long edge at most <paramref name="maxLongEdge"/>; null
/// when the frame cannot be read. The caller owns the buffer.
/// </summary>
ValueTask<ImageBuffer?> DecodeAsync(int index, int maxLongEdge, DecodePurpose purpose, CancellationToken cancellationToken);
/// <summary>
/// Stores <paramref name="project"/>, edited from <paramref name="basis"/> (the version last loaded or saved). A
/// change made meanwhile by someone else is kept where this edit left the value alone (<see cref="ProjectMerge"/>).
/// Returns the stored project.
/// </summary>
/// <exception cref="EditorException">The editor's own reason the project was not stored, worded for the user.</exception>
Task<ProjectSettings> SaveProjectAsync(ProjectSettings project, ProjectSettings basis, CancellationToken cancellationToken);
/// <summary>Queues an analysis or render job for the sequence; returns the job id.</summary>
Task<Guid> SubmitAsync(ArchiveJobRequest request, CancellationToken cancellationToken);
/// <summary>Recent jobs that may concern the sequence (queued, running, finished), for the busy state and the cost of Analyse.</summary>
Task<IReadOnlyList<Job>> ListJobsAsync(CancellationToken cancellationToken);
/// <summary>Cancels a job of the sequence that waits or runs; its new state arrives through <see cref="JobChanged"/>.</summary>
Task CancelJobAsync(Guid jobId, CancellationToken cancellationToken);
/// <summary>Queues a failed or cancelled job of the sequence again from its checkpoint.</summary>
Task RetryJobAsync(Guid jobId, CancellationToken cancellationToken);
}
/// <summary>A sequence as the editor opens it.</summary>
/// <param name="Frames">Frame rows in index order.</param>
/// <param name="Light">Light analysis of the frame metadata (BRIEF §10.1).</param>
/// <param name="Deep">The saved deep analysis when it describes the current frames, else null (<see cref="DeepOfOtherFrames"/> says why).</param>
/// <param name="SourceWidth">Dominant oriented full-resolution width (0 when unknown).</param>
/// <param name="ExportsFolder">Default output folder of renders; null when the sequence is not on this PC.</param>
/// <param name="Renders">Finished renders, newest first (an empty output path when the file is not on this PC).</param>
/// <param name="SavedCopies">This PC's projects kept by "Save both" when a sync conflict was settled, newest first.</param>
public sealed record SequenceContent(
Sequence Sequence,
IReadOnlyList<Frame> Frames,
ProjectSettings Project,
LightAnalysisReport Light,
DeepAnalysisReport? Deep,
int SourceWidth,
int SourceHeight,
string? ExportsFolder,
IReadOnlyList<Render> Renders,
IReadOnlyList<SavedCopy> SavedCopies)
{
/// <summary>Flags of frames that never reach a render (as the render job skips them).</summary>
public const FrameFlags NotRendered = FrameFlags.Missing | FrameFlags.Corrupt | FrameFlags.Excluded | FrameFlags.Undecodable;
public int Count => Frames.Count;
/// <summary>
/// A saved deep analysis exists and reads, but describes another number of frames (frames were added or removed since);
/// false when there is none or it cannot be read now (archive offline, file moved or damaged, a server that sends none).
/// </summary>
public bool DeepOfOtherFrames { get; init; }
/// <summary>Frames the render skips besides the project's exclusions.</summary>
public IEnumerable<int> NotRenderable()
{
for (var i = 0; i < Frames.Count; i++)
{
if ((Frames[i].Flags & NotRendered) != 0) yield return i;
}
}
}