Skip to main content

rsynko_manager/
queue.rs

1use crate::ManagerSorts;
2use crate::*;
3use ambassador::delegatable_trait;
4use std::path::{Path, PathBuf};
5
6/// Specifies ordered queue observation and stable selection.
7#[delegatable_trait]
8pub trait QueueCatalogAlg: ManagerSorts {
9    /// Observes stable identities in collection order.
10    fn queue_ids(&self) -> impl Iterator<Item = Self::Id>;
11    /// Observes the selected stable identity.
12    fn selected_queue_id(&self) -> Option<Self::Id>;
13    /// Sets the selected stable identity.
14    fn set_selected_queue_id(&mut self, selected: Option<Self::Id>);
15    /// Observes one entry by stable identity.
16    fn queue_entry(&self, id: Self::Id) -> Option<&Self::Entry>;
17}
18
19/// Specifies the queue-entry observations used by manager derivations.
20pub trait QueueEntryAlg {
21    /// Observes the submitted source until extraction supplies a title, and that title after.
22    fn label(&self) -> &str;
23    /// Observes the source the request was submitted with.
24    fn source(&self) -> &str;
25    /// Observes the lifecycle phase the request has reached.
26    fn phase(&self) -> TransferPhase;
27    /// Observes the rehearsal mode, and that the request has none when it has none.
28    fn dry_run(&self) -> Option<bool>;
29    /// Observes exactly what an interpreter would run to perform the request.
30    ///
31    /// A request an interpreter performs by naming a program states that program and everything
32    /// it would be given, so a reader sees what pressing Space does before pressing it. A request
33    /// retrieved by fetching states nothing here: there is no command to read.
34    fn stated_command(&self) -> Option<String>;
35    /// Observes the explicit output path when present.
36    fn output(&self) -> Option<&Path>;
37    /// Observes how the output is named, which decides what an edited name is taken to be.
38    fn output_naming(&self) -> OutputNaming;
39    /// Observes whether request choices remain editable.
40    fn is_editable(&self) -> bool;
41    /// Derives visible details controls from transfer state.
42    fn detail_controls(&self) -> Vec<DetailControl>;
43    /// Derives the currently valid meaning of Space.
44    fn space_action(&self) -> Option<SpaceAction>;
45    /// Observes the notes stated about this request, in the order they were stated.
46    fn download_log(&self) -> impl Iterator<Item = &str>;
47}
48
49/// Denotes how one request's output is named.
50///
51/// The two are not interchangeable. A name this application invents for a file it produces has to
52/// be one every filesystem accepts, and is normalized until it is. A path somebody stated is
53/// already the answer, and normalizing it would replace the separators that make it a path.
54#[derive(Clone, Copy, Debug, PartialEq, Eq)]
55pub enum OutputNaming {
56    /// Names one file this application produces, made portable before it is used.
57    Portable,
58    /// Names one path somebody stated, taken exactly as it was written.
59    Stated,
60}
61
62/// Specifies ordered queue insertion.
63#[delegatable_trait]
64pub trait QueueAppendAlg: ManagerSorts {
65    /// Appends sources and returns their stable identities in source order.
66    fn append_sources(&mut self, requests: Vec<Self::Source>) -> Vec<Self::Id>;
67}
68
69/// Specifies queue removal.
70#[delegatable_trait]
71pub trait QueueRemoveAlg: ManagerSorts {
72    /// Removes one stable identity.
73    fn remove_queue_entry(&mut self, id: Self::Id);
74}
75
76/// Specifies cooperative pause transitions.
77#[delegatable_trait]
78pub trait QueuePauseAlg: ManagerSorts {
79    /// Toggles one active transfer between paused and resumed state.
80    fn toggle_queue_pause(&mut self, id: Self::Id);
81}
82
83/// Specifies fresh-request duplication.
84#[delegatable_trait]
85pub trait QueueDuplicateAlg: ManagerSorts {
86    /// Duplicates one source as a fresh request and returns its identity.
87    fn duplicate_queue_entry(&mut self, id: Self::Id) -> Option<Self::Id>;
88}
89
90/// Specifies ready-request format-choice editing.
91#[delegatable_trait]
92pub trait QueueFormatEditAlg: ManagerSorts {
93    /// Selects an adjacent choice: a preferred stream role, or one discovered identity.
94    fn cycle_queue_format(&mut self, id: Self::Id, forward: bool);
95}
96
97/// Specifies explicit output assignment.
98#[delegatable_trait]
99pub trait QueueOutputAlg: ManagerSorts {
100    /// Fixes one editable queue entry's explicit output file name.
101    fn set_queue_output(&mut self, id: Self::Id, output: PathBuf);
102}
103
104/// Specifies input replacement.
105#[delegatable_trait]
106pub trait QueueSourceAlg: ManagerSorts {
107    /// Replaces one request's input, while that request still permits it.
108    fn set_queue_source(&mut self, id: Self::Id, source: String);
109}
110
111/// Specifies format-catalog requests and external observations.
112#[delegatable_trait]
113pub trait FormatCatalogStateAlg: ManagerSorts {
114    /// Marks one editable entry as waiting for source inspection.
115    fn request_format_catalog(&mut self, id: Self::Id);
116    /// Applies one format-catalog observation.
117    fn apply_format_catalog_event(&mut self, id: Self::Id, event: FormatDiscoveryOp<Self::Format>);
118}
119
120/// Specifies extracted source naming observations.
121#[delegatable_trait]
122pub trait SourceMetadataAlg: ManagerSorts {
123    /// Applies extracted identity and title observations.
124    fn apply_source_metadata(&mut self, id: Self::Id, media_id: String, title: Option<String>);
125}
126
127/// Specifies transfer scheduling and observations by stable identity.
128#[delegatable_trait]
129pub trait TransferStateAlg: ManagerSorts {
130    /// Marks one entry as waiting for an interpreter.
131    fn set_waiting(&mut self, id: Self::Id);
132    /// Marks one failed entry as waiting without changing its fixed request.
133    fn restart_waiting(&mut self, id: Self::Id);
134    /// Applies one transfer observation.
135    fn apply_transfer_event(&mut self, id: Self::Id, event: TransferObservationOp);
136}