Files
DarkRoom/ui/dr-ui/ui/albums.slint
T
dtourolle 7cbcacc02e Export to an album instead of a folder in the settings
Export took a path typed into the settings page, or a folder inside the
library on the server. The first is how exports end up somewhere nobody
looks; the second put JPEGs into the tree a scan catalogues, where they
came back as photographs beside the RAWs they were made from.

The destination is now an album (FR-EXP-10), chosen by name in the
export sheet. Albums are listed under the collections in the sidebar;
"+" there, or "New album…" in the sheet, opens a sheet for its name and
its folder — on this device through the platform's dialogue, or on the
server through the browser with "New folder". A server folder inside
the library is refused, and the sheet says why. Selecting an album
narrows the grid to the photographs behind its files: library::Scope
is Collection or Album, and scope_clause is the one place the two are
spelled, which also retires the two copies of the collection predicate
total_images_scoped and read_cells_scoped had inlined.

A batch resolves the album when it starts, and refuses in words when
none is chosen, it has gone, or its folder is local to another device.
Each item reports the image it came from, and the files written are
recorded against the album in one transaction when the batch ends.

A server album lives outside the library, so its queued uploads are
relative to the account root. That is a third line in the outbox's
.dest record rather than a leading slash, because a record written
before albums may carry a stray slash and must keep the meaning it was
written with.

An export folder set before albums becomes an album called "Exports"
on first open, so upgrading does not lose where exports were going.
The old destination fields stay in ExportSettings so older settings
files still read.
2026-09-26 14:13:53 -04:00

481 lines
17 KiB
Plaintext

// TRACES: FR-EXP-10 | FR-EXP-6
// Albums: named export folders, in the sidebar under the collections.
//
// An album is where finished pictures go. Its folder holds only the exported
// files; the catalog remembers which photograph each came from, so selecting
// an album shows the originals behind it, and the export sheet sends a
// selection to one by name rather than to a path typed into a field.
//
// The folder is on this device (chosen in the platform's dialogue, or on
// Android the system's folder picker) or on the library's server (chosen in
// the browser below, which can make a folder as well as open one). Not inside
// the library itself: a JPEG exported there would be catalogued by the next
// scan as a photograph of its own.
import { Theme } from "theme.slint";
import { Button, Caption, Field, Icon, PanelHeading, Value } from "widgets.slint";
import { Segmented } from "controls.slint";
export struct AlbumRow {
id: int,
name: string,
// Photographs exported into it — what the grid shows when it is opened.
count: int,
// Where its files go, in words: "On this device · ~/Exports/Web",
// "On the server · Shared/Web", or that this device has no folder for it.
detail: string,
// The album has no folder on this device yet: made elsewhere with a
// folder local to that device.
homeless: bool,
}
export global Albums {
in property <[AlbumRow]> rows;
/// The album scoping the grid, 0 for none.
in property <int> selected: 0;
callback select(int);
/// Open the sheet on a new album.
callback create();
/// Open the sheet on an existing one.
callback edit(int);
// --- the sheet ------------------------------------------------------
in property <bool> sheet-open: false;
/// Editing an existing album rather than making one.
in property <bool> sheet-editing: false;
in property <string> sheet-name;
/// Whether the library has a server to put a folder on. A folder library
/// has only this device.
in property <bool> server-available: false;
/// 0: this device. 1: the server.
in property <int> sheet-where: 0;
/// The folder chosen on this device, for display. Empty until chosen.
in property <string> sheet-device-folder;
/// Something to say — a refusal, a failed request.
in property <string> sheet-error;
/// Delete has been pressed once and waits to be confirmed.
in property <bool> sheet-confirming-delete: false;
/// What saving would do, when the button alone would not say.
in property <bool> sheet-can-save: false;
callback sheet-where-picked(int);
callback sheet-choose-device-folder();
callback sheet-name-edited(string);
callback sheet-save();
callback sheet-cancel();
callback sheet-delete();
// --- the server folder, while the sheet is choosing one ---------------
in property <string> browse-path;
in property <[string]> browse-entries;
in property <bool> browse-loading: false;
in property <bool> browse-at-root: true;
/// Why the folder shown cannot be used, or empty when it can.
in property <string> browse-refusal;
callback browse-into(string);
callback browse-up();
callback browse-make(string);
}
// A folder on the server: where it is, what is in it, and a way to make one.
//
// Confirms the folder *shown*, not one selected in the list — the rule the
// launch screen's picker already follows — so walking into a folder is
// choosing it, and there is no second selection that could disagree.
export component ServerFolderBrowser inherits VerticalLayout {
in property <string> path;
in property <[string]> entries;
in property <bool> loading;
in property <bool> at-root: true;
callback into(string);
callback up();
callback make(string);
property <bool> naming: false;
spacing: Theme.gap-sm;
HorizontalLayout {
spacing: Theme.gap-sm;
Button {
text: "↑ Up";
// Disabled rather than hidden at the root: a control that
// vanishes moves everything beside it.
enabled: !root.at-root && !root.loading;
clicked => { root.up(); }
}
Value {
text: root.path == "" ? "/" : "/" + root.path;
overflow: elide;
horizontal-stretch: 1;
min-width: 0px;
vertical-alignment: center;
}
Button {
text: "New folder";
enabled: !root.loading && !root.naming;
clicked => { root.naming = true; }
}
}
if root.naming: HorizontalLayout {
spacing: Theme.gap-sm;
name := Field {
horizontal-stretch: 1;
label: "New folder name";
placeholder: "Folder name";
accepted(t) => {
if (t != "") {
root.make(t);
root.naming = false;
}
}
init => { self.take-focus(); }
}
Button {
text: "Make";
enabled: name.text != "";
clicked => {
root.make(name.text);
root.naming = false;
}
}
Button {
text: "Cancel";
clicked => { root.naming = false; }
}
}
// A fixed height rather than one that grows with the listing: a folder
// with sixty children would otherwise push the buttons off the sheet.
Rectangle {
height: 200px;
background: Theme.ground;
border-radius: Theme.radius;
border-width: 1px;
border-color: Theme.rule;
if root.loading: Caption {
text: "Listing…";
horizontal-alignment: center;
vertical-alignment: center;
width: 100%;
height: 100%;
}
if !root.loading: Flickable {
x: 4px;
y: 4px;
width: parent.width - 8px;
height: parent.height - 8px;
viewport-height: list.preferred-height;
list := VerticalLayout {
width: 100%;
spacing: 2px;
alignment: start;
if root.entries.length == 0: Caption {
text: "No folders here. Use this one, make one, or go up.";
wrap: word-wrap;
}
for folder in root.entries: Rectangle {
height: 32px;
background: row-touch.has-hover ? Theme.hover : transparent;
border-radius: Theme.radius-sm;
accessible-role: button;
accessible-label: folder;
accessible-action-default => { root.into(folder); }
HorizontalLayout {
padding-left: Theme.gap-sm;
padding-right: Theme.gap-sm;
spacing: Theme.gap-sm;
Icon {
name: "chevron-right";
ink: Theme.ink-faint;
size: 10px;
y: (parent.height - self.height) / 2;
}
Value {
text: folder;
overflow: elide;
vertical-alignment: center;
horizontal-stretch: 1;
}
}
row-touch := TouchArea { clicked => { root.into(folder); } }
}
}
}
}
}
// One album in the sidebar.
component AlbumListRow inherits Rectangle {
in property <AlbumRow> entry;
in property <bool> selected;
callback clicked();
callback edit();
height: Theme.row-height;
background: root.selected ? Theme.surface-raised
: (touch.has-hover ? Theme.hover : transparent);
border-radius: Theme.radius-sm;
accessible-role: button;
accessible-label: root.entry.name + ", " + root.entry.detail;
accessible-action-default => { root.clicked(); }
touch := TouchArea {
clicked => { root.clicked(); }
double-clicked => { root.edit(); }
pointer-event(ev) => {
if (ev.kind == PointerEventKind.down && ev.button == PointerEventButton.right) {
root.edit();
}
}
}
HorizontalLayout {
padding-left: Theme.gap-sm;
padding-right: Theme.gap-sm;
spacing: Theme.gap-sm;
Text {
text: root.entry.name;
color: root.entry.homeless ? Theme.ink-faint
: (root.selected ? Theme.ink : Theme.ink-dim);
font-size: Theme.text;
font-weight: root.selected ? 600 : 400;
overflow: elide;
vertical-alignment: center;
horizontal-stretch: 1;
}
Text {
text: root.entry.count > 0 ? root.entry.count : "";
color: Theme.ink-faint;
font-size: Theme.text-sm;
vertical-alignment: center;
}
// The way in to rename, move or delete, where there is no right
// button and no double click: a finger.
Rectangle {
width: 22px;
accessible-role: button;
accessible-label: "Edit " + root.entry.name;
accessible-action-default => { root.edit(); }
Icon {
name: "chevron-right";
ink: Theme.ink-faint;
size: 10px;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
}
TouchArea { clicked => { root.edit(); } }
}
}
}
// The sidebar's albums: a heading with "+", and the list.
export component AlbumsSection inherits VerticalLayout {
spacing: 2px;
HorizontalLayout {
height: 26px;
spacing: Theme.gap-sm;
Text {
text: "ALBUMS";
color: Theme.ink-faint;
font-size: Theme.text-sm;
font-weight: 700;
letter-spacing: 1.2px;
vertical-alignment: center;
horizontal-stretch: 1;
}
Rectangle {
width: 22px;
height: 22px;
y: (parent.height - self.height) / 2;
background: add-touch.pressed ? Theme.pressed
: (add-touch.has-hover ? Theme.hover : transparent);
border-radius: Theme.radius-sm;
accessible-role: button;
accessible-label: "New album";
accessible-action-default => { Albums.create(); }
Icon {
name: "plus";
ink: Theme.ink-dim;
size: 12px;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
}
add-touch := TouchArea { clicked => { Albums.create(); } }
}
}
if Albums.rows.length == 0: Text {
text: "Press + to make an export folder. Exports sent to it are listed here.";
color: Theme.ink-faint;
font-size: Theme.text-sm;
wrap: word-wrap;
}
// At most five rows tall, then it scrolls: the albums share the column
// with the collection tree, which is the thing that should grow.
if Albums.rows.length > 0: Flickable {
height: min(Albums.rows.length, 5) * (Theme.row-height + 2px);
viewport-height: Albums.rows.length * (Theme.row-height + 2px);
for row[i] in Albums.rows: AlbumListRow {
y: i * (Theme.row-height + 2px);
width: parent.width;
entry: row;
selected: row.id == Albums.selected;
clicked => { Albums.select(row.id); }
edit => { Albums.edit(row.id); }
}
}
}
// Making an album, or changing one: its name and where its files go.
export component AlbumSheet inherits Rectangle {
background: #000000CC;
TouchArea { clicked => { Albums.sheet-cancel(); } }
Rectangle {
width: min(560px, parent.width - 2 * Theme.gap-lg);
height: min(body.preferred-height + 2 * Theme.gap-lg, parent.height - 2 * Theme.gap-lg);
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
background: Theme.surface;
border-radius: Theme.radius;
border-width: 1px;
border-color: Theme.rule;
TouchArea { }
Flickable {
viewport-height: body.preferred-height + 2 * Theme.gap-lg;
body := VerticalLayout {
x: Theme.gap-lg;
y: Theme.gap-lg;
width: parent.width - 2 * Theme.gap-lg;
spacing: Theme.gap;
alignment: start;
Text {
text: Albums.sheet-editing ? "Album" : "New album";
color: Theme.ink;
font-size: Theme.text-lg;
font-weight: 600;
}
PanelHeading { text: "NAME"; }
Field {
label: "Album name";
text: Albums.sheet-name;
placeholder: "Web, Prints, For Anna…";
edited(t) => { Albums.sheet-name-edited(t); }
accepted(t) => { Albums.sheet-name-edited(t); }
// The keyboard comes here when the sheet opens. Left on
// the grid, a name typed at once is read as shortcuts —
// P picks, R rejects, digits rate.
init => { self.take-focus(); }
}
PanelHeading { text: "FILES GO TO"; }
if Albums.server-available: Segmented {
label: "Where";
options: ["This device", "The server"];
selected: Albums.sheet-where;
picked(i) => { Albums.sheet-where-picked(i); }
}
if Albums.sheet-where == 0: HorizontalLayout {
spacing: Theme.gap-sm;
Value {
text: Albums.sheet-device-folder != "" ? Albums.sheet-device-folder : "No folder chosen";
placeholder: Albums.sheet-device-folder == "";
overflow: elide;
vertical-alignment: center;
horizontal-stretch: 1;
min-width: 0px;
}
Button {
text: Albums.sheet-device-folder != "" ? "Change…" : "Choose folder…";
clicked => { Albums.sheet-choose-device-folder(); }
}
}
if Albums.sheet-where == 0: Caption {
text: "The dialogue can make a new folder too. Only the exported files are written there.";
wrap: word-wrap;
}
if Albums.sheet-where == 1: ServerFolderBrowser {
path: Albums.browse-path;
entries: Albums.browse-entries;
loading: Albums.browse-loading;
at-root: Albums.browse-at-root;
into(name) => { Albums.browse-into(name); }
up => { Albums.browse-up(); }
make(name) => { Albums.browse-make(name); }
}
if Albums.sheet-where == 1 && Albums.browse-refusal != "": Caption {
text: Albums.browse-refusal;
warn: true;
wrap: word-wrap;
}
if Albums.sheet-error != "": Caption {
text: Albums.sheet-error;
warn: true;
wrap: word-wrap;
}
if Albums.sheet-confirming-delete: Caption {
text: "The album goes; the files already in its folder stay where they are.";
wrap: word-wrap;
}
HorizontalLayout {
spacing: Theme.gap-sm;
if Albums.sheet-editing: Button {
text: Albums.sheet-confirming-delete ? "Delete album" : "Delete…";
clicked => { Albums.sheet-delete(); }
}
Rectangle { horizontal-stretch: 1; }
Button {
text: "Cancel";
clicked => { Albums.sheet-cancel(); }
}
Button {
text: Albums.sheet-editing ? "Save" : "Make album";
primary: true;
enabled: Albums.sheet-can-save;
clicked => { Albums.sheet-save(); }
}
}
}
}
}
}