S021: tag editor and online lookup dialogs
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
parent
48eecf3163
commit
6ed36a90fd
16 changed files with 2033 additions and 11 deletions
|
|
@ -92,6 +92,7 @@ Never modify: `PROMPT.md` (the user's brief), the user's other projects under `~
|
|||
| `TUNAL_SETTINGS=<0-4> cargo run -p tunal -- <dir> --screenshot <png> --size 1000x700` (`XDG_CONFIG_HOME=<scratch>`) | settings dialog page over a folder | S013 |
|
||||
| `TUNAL_DRAG=x1,y1,x2,y2[,hold] TUNAL_REDUCED_MOTION=1 cargo run -p tunal -- <dir> --screenshot <png> --size 1200x760` (`XDG_CONFIG_HOME=<scratch>`) | drags between window points and drops (drop menu) or holds (glow + drag image) before the frame | S014 |
|
||||
| `TUNAL_APPEARANCE=1 XDG_CONFIG_HOME=<scratch> cargo run -p tunal -- <dir> --screenshot <png> --size 1000x760` | folder appearance dialog for `<dir>` (theme icons looked up at once); `cargo run -p tunal-dirmeta --example roundtrip -- <dir>` sets `Icon` in `<dir>/.directory` and prints the old values | S015 |
|
||||
| `TUNAL_TAGS=editor\|lookup\|mapping\|apply:<file>:<file> TUNAL_TAGS_SYNC=1 TUNAL_MUSICBRAINZ=<mock url> XDG_CONFIG_HOME=<scratch> cargo run -p tunal -- <dir> --screenshot <png> --size 1000x760` | tag editor / lookup / mapping over a folder; `apply` also writes the tags (scratch copies only); mock = a local server for both services | S021 |
|
||||
|
||||
Don't assume a tool exists: check first. When your plan creates a tool, add its row here.
|
||||
|
||||
|
|
|
|||
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -5537,6 +5537,7 @@ checksum = "d2df906b07856748fa3f6e0ad0cbaa047052d4a7dd609e231c4f72cee8c36f31"
|
|||
name = "tunal"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"image",
|
||||
"jiff",
|
||||
"png",
|
||||
"serde",
|
||||
|
|
@ -5547,6 +5548,7 @@ dependencies = [
|
|||
"tunal-devices",
|
||||
"tunal-dirmeta",
|
||||
"tunal-elevate",
|
||||
"tunal-tags",
|
||||
"tunal-theme",
|
||||
"tunal-thumbs",
|
||||
"zbus",
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ Edit tags of one or many audio files, look up metadata and covers, and embed the
|
|||
crates/tunal-tags API; crates/tunal/src/{actions.rs,menus.rs}; crates/tunal/ui/components/{dialog,text-field,list-row}.slint.
|
||||
|
||||
## Steps
|
||||
- [ ] 'Edit tags' action on audio files (single and multi) added to the registry and default menus.
|
||||
- [ ] Editor: fields with 'Keep' placeholder for mixed values, cover area (current, replace from file, remove, drop an image), save off-thread with progress.
|
||||
- [ ] Lookup: search prefilled from tags → candidate releases (title, artist, date, country, track count, cover) → file ↔ track mapping (auto, editable) → preview of changes → apply and embed cover.
|
||||
- [ ] Errors (offline, rate limited, not found) shown plainly.
|
||||
- [ ] PROGRESS entry, INDEX line, commit `S021: …`
|
||||
- [x] 'Edit tags' action on audio files (single and multi) added to the registry and default menus.
|
||||
- [x] Editor: fields with 'Keep' placeholder for mixed values, cover area (current, replace from file, remove, drop an image), save off-thread with progress.
|
||||
- [x] Lookup: search prefilled from tags → candidate releases (title, artist, date, country, track count, cover) → file ↔ track mapping (auto, editable) → preview of changes → apply and embed cover.
|
||||
- [x] Errors (offline, rate limited, not found) shown plainly.
|
||||
- [x] PROGRESS entry, INDEX line, commit `S021: …`
|
||||
|
||||
## End criteria
|
||||
- `cargo build --workspace`, `cargo clippy --workspace --all-targets -- -D warnings` and `cargo fmt --check` pass.
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ Tracker: https://claude.ai/artifact/4X8YCk3cQjUGyuyCqGuU7v
|
|||
|
||||
- [x] [S019 — Tag model with lofty](07%20Tag%20editor/S019-tag-model.md) · Sonnet medium
|
||||
- [x] [S020 — MusicBrainz and Cover Art Archive client](07%20Tag%20editor/S020-musicbrainz-client.md) · Sonnet high
|
||||
- [ ] [S021 — Tag editor UI](07%20Tag%20editor/S021-tag-editor-ui.md) · Opus medium
|
||||
- [x] [S021 — Tag editor UI](07%20Tag%20editor/S021-tag-editor-ui.md) · Opus medium
|
||||
|
||||
## 08 Audio player
|
||||
|
||||
|
|
|
|||
|
|
@ -114,6 +114,12 @@ pub fn read(path: &Path) -> Result<TrackTags, Error> {
|
|||
.unwrap_or_default())
|
||||
}
|
||||
|
||||
/// The playing time of a file in milliseconds, when lofty can tell.
|
||||
pub fn duration_ms(path: &Path) -> Option<u32> {
|
||||
let tagged = open(path).ok()?;
|
||||
u32::try_from(tagged.properties().duration().as_millis()).ok()
|
||||
}
|
||||
|
||||
/// Reads many files and merges them. Files that fail are returned with their error and left out.
|
||||
pub fn read_set(paths: &[PathBuf]) -> (TagSet, Vec<(PathBuf, Error)>) {
|
||||
let mut tracks = Vec::new();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ mod mb;
|
|||
mod model;
|
||||
|
||||
pub use http::{Client, NetError};
|
||||
pub use io::{Error, read, read_set, write, write_many};
|
||||
pub use io::{Error, duration_ms, read, read_set, write, write_many};
|
||||
pub use matching::{FileInfo, match_tracks};
|
||||
pub use mb::{RecordingHit, Release, ReleaseHit, Track};
|
||||
pub use model::{Cover, CoverEdit, Edit, Merged, TagEdit, TagSet, TrackTags};
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ tunal-elevate = { path = "../tunal-elevate" }
|
|||
tunal-devices = { path = "../tunal-devices" }
|
||||
tunal-dirmeta = { path = "../tunal-dirmeta" }
|
||||
tunal-thumbs = { path = "../tunal-thumbs" }
|
||||
tunal-tags = { path = "../tunal-tags" }
|
||||
image.workspace = true
|
||||
jiff.workspace = true
|
||||
serde.workspace = true
|
||||
zbus.workspace = true
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use crate::open::Opener;
|
|||
use crate::properties::Properties;
|
||||
use crate::shell::Shell;
|
||||
use crate::shell::pane::Pane;
|
||||
use crate::tags_bridge::{self, Tags};
|
||||
use crate::{MainWindow, MenuEntry, MenuItem};
|
||||
|
||||
/// Every action, by stable id (the context menu editor refers to these).
|
||||
|
|
@ -37,6 +38,7 @@ pub enum Action {
|
|||
OpenWith,
|
||||
Properties,
|
||||
Appearance,
|
||||
EditTags,
|
||||
}
|
||||
|
||||
enum Shortcut {
|
||||
|
|
@ -45,7 +47,7 @@ enum Shortcut {
|
|||
}
|
||||
|
||||
impl Action {
|
||||
pub const ALL: [Action; 15] = [
|
||||
pub const ALL: [Action; 16] = [
|
||||
Self::Cut,
|
||||
Self::Copy,
|
||||
Self::Paste,
|
||||
|
|
@ -61,6 +63,7 @@ impl Action {
|
|||
Self::OpenWith,
|
||||
Self::Properties,
|
||||
Self::Appearance,
|
||||
Self::EditTags,
|
||||
];
|
||||
|
||||
pub fn id(self) -> &'static str {
|
||||
|
|
@ -80,6 +83,7 @@ impl Action {
|
|||
Self::OpenWith => "open-with",
|
||||
Self::Properties => "properties",
|
||||
Self::Appearance => "appearance",
|
||||
Self::EditTags => "edit-tags",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -104,6 +108,7 @@ impl Action {
|
|||
Self::OpenWith => "Open with…",
|
||||
Self::Properties => "Properties",
|
||||
Self::Appearance => "Folder appearance…",
|
||||
Self::EditTags => "Edit tags…",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -125,6 +130,7 @@ impl Action {
|
|||
Self::OpenWith => "\u{e5c3}",
|
||||
Self::Properties => "\u{e88e}",
|
||||
Self::Appearance => "\u{e40a}",
|
||||
Self::EditTags => "\u{e892}",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +151,8 @@ impl Action {
|
|||
| Self::Open
|
||||
| Self::OpenWith
|
||||
| Self::Properties
|
||||
| Self::Appearance => {
|
||||
| Self::Appearance
|
||||
| Self::EditTags => {
|
||||
return None;
|
||||
}
|
||||
})
|
||||
|
|
@ -196,6 +203,7 @@ impl Action {
|
|||
Self::Open | Self::OpenWith => files && ctx.selected > 0,
|
||||
Self::Properties => true,
|
||||
Self::Appearance => files && ctx.selected <= 1,
|
||||
Self::EditTags => files && ctx.audio,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -209,6 +217,8 @@ pub struct Context {
|
|||
pub can_trash: bool,
|
||||
/// The clipboard holds something to paste.
|
||||
pub paste: bool,
|
||||
/// Every selected entry is a local audio file.
|
||||
pub audio: bool,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -231,6 +241,7 @@ pub struct Actions {
|
|||
opener: Rc<Opener>,
|
||||
properties: Rc<Properties>,
|
||||
appearance: Rc<Appearance>,
|
||||
tags: Rc<Tags>,
|
||||
}
|
||||
|
||||
impl Actions {
|
||||
|
|
@ -239,6 +250,7 @@ impl Actions {
|
|||
let opener = Opener::attach(ui, locations.clone(), bridge.clone());
|
||||
let properties = Properties::attach(ui, locations.clone());
|
||||
let appearance = Appearance::attach(ui, bridge.elevation());
|
||||
let tags = Tags::attach(ui, bridge.clone());
|
||||
let actions = Rc::new_cyclic(|me| Self {
|
||||
me: me.clone(),
|
||||
ui: ui.as_weak(),
|
||||
|
|
@ -251,6 +263,7 @@ impl Actions {
|
|||
opener,
|
||||
properties,
|
||||
appearance,
|
||||
tags,
|
||||
});
|
||||
let me = actions.me.clone();
|
||||
let shell_weak = Rc::downgrade(shell);
|
||||
|
|
@ -265,10 +278,23 @@ impl Actions {
|
|||
me.appearance_saved(dir, remembered);
|
||||
}
|
||||
});
|
||||
let shell_weak = Rc::downgrade(shell);
|
||||
actions.tags.on_written(move || {
|
||||
if let Some(shell) = shell_weak.upgrade() {
|
||||
for pane in shell.panes() {
|
||||
pane.model.refresh();
|
||||
}
|
||||
}
|
||||
});
|
||||
actions.bind(ui);
|
||||
actions
|
||||
}
|
||||
|
||||
/// Screenshots: opens the tag editor or lookup (see `TUNAL_TAGS` in main.rs).
|
||||
pub fn debug_tags(&self, spec: &str) {
|
||||
self.tags.debug_open(spec);
|
||||
}
|
||||
|
||||
/// Runs a file job (drag and drop).
|
||||
pub fn submit(&self, kind: JobKind) {
|
||||
self.bridge.submit(kind);
|
||||
|
|
@ -294,8 +320,12 @@ impl Actions {
|
|||
.and_then(|d| self.locations.resolve(&d).ok())
|
||||
.map(|l| l.capabilities())
|
||||
.unwrap_or_default();
|
||||
let selected = pane.model.selected_uris();
|
||||
Context {
|
||||
selected: pane.model.selected_uris().len(),
|
||||
audio: !selected.is_empty()
|
||||
&& !pane.model.selection_is_dir()
|
||||
&& selected.iter().all(tags_bridge::is_audio),
|
||||
selected: selected.len(),
|
||||
in_trash: pane.dir().is_some_and(|d| d.scheme() == tunal_core::TRASH),
|
||||
writable: caps.write,
|
||||
can_trash: caps.trash,
|
||||
|
|
@ -508,6 +538,13 @@ impl Actions {
|
|||
}
|
||||
return;
|
||||
}
|
||||
Action::EditTags => {
|
||||
let files: Vec<_> = uris.iter().filter_map(|u| u.to_path()).collect();
|
||||
if !files.is_empty() {
|
||||
self.tags.edit(files);
|
||||
}
|
||||
return;
|
||||
}
|
||||
Action::Settings => {
|
||||
if let Some(ui) = self.ui.upgrade() {
|
||||
ui.invoke_show_settings(0);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ mod screenshot;
|
|||
mod settings;
|
||||
mod shapes;
|
||||
mod shell;
|
||||
mod tags_bridge;
|
||||
mod theme_bridge;
|
||||
mod thumbs_bridge;
|
||||
|
||||
|
|
@ -99,6 +100,11 @@ fn window(
|
|||
if std::env::var_os("TUNAL_APPEARANCE").is_some() {
|
||||
shell.run_action(actions::Action::Appearance);
|
||||
}
|
||||
// `TUNAL_TAGS=editor|lookup|mapping:<file>:<file>…` opens the tag editor or the lookup
|
||||
// (screenshots; `TUNAL_TAGS_SYNC=1` runs its work in place, `TUNAL_MUSICBRAINZ=<url>` is a mock).
|
||||
if let Ok(spec) = std::env::var("TUNAL_TAGS") {
|
||||
shell.debug_tags(&spec);
|
||||
}
|
||||
Ok((ui, shell))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ impl Context {
|
|||
Self::File => &[
|
||||
"open",
|
||||
"open-with",
|
||||
"edit-tags",
|
||||
"-",
|
||||
"cut",
|
||||
"copy",
|
||||
|
|
@ -76,6 +77,7 @@ impl Context {
|
|||
"properties",
|
||||
],
|
||||
Self::Multiple => &[
|
||||
"edit-tags",
|
||||
"cut",
|
||||
"copy",
|
||||
"-",
|
||||
|
|
|
|||
|
|
@ -451,6 +451,12 @@ impl Shell {
|
|||
|
||||
/// Tab bar selection, toolbar, breadcrumb, sort menu, sidebar and status bar.
|
||||
/// Runs an action as if chosen from a menu (screenshot hooks).
|
||||
pub(crate) fn debug_tags(&self, spec: &str) {
|
||||
if let Some(actions) = self.actions.get() {
|
||||
actions.debug_tags(spec);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn run_action(&self, action: crate::actions::Action) {
|
||||
if let Some(actions) = self.actions.get() {
|
||||
actions.run(action);
|
||||
|
|
|
|||
1230
crates/tunal/src/tags_bridge.rs
Normal file
1230
crates/tunal/src/tags_bridge.rs
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -23,12 +23,14 @@ import { ErrorsDialog } from "dialogs/errors.slint";
|
|||
import { PropertiesDialog, PropertiesInfo, PropRow } from "dialogs/properties.slint";
|
||||
import { OpenWithDialog, AppRow } from "dialogs/open-with.slint";
|
||||
import { FolderAppearanceDialog, IconChoice } from "dialogs/folder-appearance.slint";
|
||||
import { TagEditorDialog, TagEditorData, TagField } from "dialogs/tag-editor.slint";
|
||||
import { TagLookupDialog, TagLookupData, ReleaseRow, MapRow } from "dialogs/tag-lookup.slint";
|
||||
import { SettingsDialog, SettingsData, EditRow } from "dialogs/settings.slint";
|
||||
import { Dnd, DropAction, DropMenu, DropTarget } from "components/drop-menu.slint";
|
||||
|
||||
export { Theme, Shapes, ShapeKind, MotionPrefs, MenuItem, MenuEntry, DetailRow, FolderState, FolderStatus, Grouping, NavKey, SortColumn, Travel, ViewMode, GridRow }
|
||||
export { ButtonKind, TabData, PaneData, Crumb, Completion, SidebarSection, PlaceItem, ToastData, ToastProgress, DialogAction, ConflictInfo, SettingsData, EditRow }
|
||||
export { PropertiesInfo, PropRow, AppRow, IconChoice, Dnd, DropAction, DropTarget }
|
||||
export { PropertiesInfo, PropRow, AppRow, IconChoice, Dnd, DropAction, DropTarget, TagEditorData, TagField, TagLookupData, ReleaseRow, MapRow }
|
||||
export { Gallery, GalleryPage } from "gallery.slint";
|
||||
|
||||
// The window: sidebar, tab bar, toolbar with the breadcrumb, the panes of the current tab
|
||||
|
|
@ -137,6 +139,29 @@ export component MainWindow inherits Window {
|
|||
callback appearance-saved(bool);
|
||||
callback appearance-done(bool);
|
||||
|
||||
// Tag editor and lookup (tags_bridge.rs).
|
||||
in-out property <TagEditorData> tag-editor;
|
||||
callback tag-editor-saved();
|
||||
callback tag-editor-lookup();
|
||||
callback tag-field-changed(int, string);
|
||||
callback tag-cover-path(string);
|
||||
callback tag-cover-dropped(data-transfer);
|
||||
callback tag-cover-removed();
|
||||
callback tag-cover-reset();
|
||||
in-out property <TagLookupData> tag-lookup;
|
||||
callback tag-artist-edited(string);
|
||||
callback tag-album-edited(string);
|
||||
callback tag-search();
|
||||
callback tag-release-picked(int);
|
||||
callback tag-next();
|
||||
callback tag-back();
|
||||
callback tag-lookup-cancelled();
|
||||
callback tag-map-step(int, int);
|
||||
callback tag-embed-toggled(bool);
|
||||
callback tag-apply();
|
||||
// Tags were written to the files; the argument is the message for a toast.
|
||||
callback tags-written(string);
|
||||
|
||||
// Properties (properties.rs) and Open with (open.rs).
|
||||
in property <PropertiesInfo> properties;
|
||||
callback properties-closed();
|
||||
|
|
@ -236,6 +261,22 @@ export component MainWindow inherits Window {
|
|||
appearance-dialog.close();
|
||||
}
|
||||
|
||||
public function show-tag-editor() {
|
||||
tag-editor-dialog.show();
|
||||
}
|
||||
|
||||
public function close-tag-editor() {
|
||||
tag-editor-dialog.close();
|
||||
}
|
||||
|
||||
public function show-tag-lookup() {
|
||||
tag-lookup-dialog.show();
|
||||
}
|
||||
|
||||
public function close-tag-lookup() {
|
||||
tag-lookup-dialog.close();
|
||||
}
|
||||
|
||||
public function show-open-with() {
|
||||
open-with-dialog.show();
|
||||
}
|
||||
|
|
@ -720,6 +761,69 @@ export component MainWindow inherits Window {
|
|||
}
|
||||
}
|
||||
|
||||
tag-editor-dialog := TagEditorDialog {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
data <=> root.tag-editor;
|
||||
saved => {
|
||||
root.tag-editor-saved();
|
||||
}
|
||||
lookup => {
|
||||
root.tag-editor-lookup();
|
||||
}
|
||||
field-changed(i, text) => {
|
||||
root.tag-field-changed(i, text);
|
||||
}
|
||||
cover-path-accepted(path) => {
|
||||
root.tag-cover-path(path);
|
||||
}
|
||||
cover-dropped(data) => {
|
||||
root.tag-cover-dropped(data);
|
||||
}
|
||||
cover-removed => {
|
||||
root.tag-cover-removed();
|
||||
}
|
||||
cover-reset => {
|
||||
root.tag-cover-reset();
|
||||
}
|
||||
}
|
||||
|
||||
tag-lookup-dialog := TagLookupDialog {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
data <=> root.tag-lookup;
|
||||
artist-edited(text) => {
|
||||
root.tag-artist-edited(text);
|
||||
}
|
||||
album-edited(text) => {
|
||||
root.tag-album-edited(text);
|
||||
}
|
||||
search => {
|
||||
root.tag-search();
|
||||
}
|
||||
release-picked(i) => {
|
||||
root.tag-release-picked(i);
|
||||
}
|
||||
next => {
|
||||
root.tag-next();
|
||||
}
|
||||
back => {
|
||||
root.tag-back();
|
||||
}
|
||||
cancelled => {
|
||||
root.tag-lookup-cancelled();
|
||||
}
|
||||
map-step(row, delta) => {
|
||||
root.tag-map-step(row, delta);
|
||||
}
|
||||
embed-toggled(on) => {
|
||||
root.tag-embed-toggled(on);
|
||||
}
|
||||
apply => {
|
||||
root.tag-apply();
|
||||
}
|
||||
}
|
||||
|
||||
errors-dialog := ErrorsDialog {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
|
|
|||
348
crates/tunal/ui/dialogs/tag-editor.slint
Normal file
348
crates/tunal/ui/dialogs/tag-editor.slint
Normal file
|
|
@ -0,0 +1,348 @@
|
|||
import { ScrollView } from "std-widgets.slint";
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Motion } from "../motion.slint";
|
||||
import { Icons } from "../components/icon.slint";
|
||||
import { Dialog } from "../components/dialog.slint";
|
||||
import { ButtonKind } from "../components/button.slint";
|
||||
import { IconButton } from "../components/icon-button.slint";
|
||||
import { TextField } from "../components/text-field.slint";
|
||||
import { Shape, ShapeKind } from "../components/shape.slint";
|
||||
|
||||
// One text field of the editor. `mixed` fields start empty with "Keep" as their placeholder:
|
||||
// the files differ, and leaving the field alone leaves each file as it is.
|
||||
export struct TagField {
|
||||
label: string,
|
||||
value: string,
|
||||
mixed: bool,
|
||||
error: string,
|
||||
}
|
||||
|
||||
export struct TagEditorData {
|
||||
// "3 files" or the name of the one file.
|
||||
subtitle: string,
|
||||
fields: [TagField],
|
||||
cover: image,
|
||||
has-cover: bool,
|
||||
// "Keep", "New cover", "Removed", "Covers differ".
|
||||
cover-note: string,
|
||||
cover-path: string,
|
||||
error: string,
|
||||
saving: bool,
|
||||
progress: float,
|
||||
}
|
||||
|
||||
// A tag field; `changed` reports the text for Rust, which keeps the values.
|
||||
component TagInput {
|
||||
in property <TagField> field;
|
||||
callback changed(string);
|
||||
public function focus-input() {
|
||||
input.focus-input();
|
||||
}
|
||||
|
||||
horizontal-stretch: 1;
|
||||
min-width: 0;
|
||||
preferred-height: input.preferred-height;
|
||||
|
||||
input := TextField {
|
||||
width: 100%;
|
||||
label: root.field.label;
|
||||
text: root.field.value;
|
||||
placeholder: root.field.mixed ? "Keep" : "";
|
||||
error: root.field.error;
|
||||
edited(text) => {
|
||||
root.changed(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The front cover: a picture or a placeholder, and a drop target for an image file.
|
||||
component CoverBox {
|
||||
in property <image> source;
|
||||
in property <bool> has-image;
|
||||
callback dropped(data-transfer);
|
||||
|
||||
width: 128px;
|
||||
height: 128px;
|
||||
|
||||
Rectangle {
|
||||
background: Theme.surface-container-highest;
|
||||
border-radius: Theme.corner-md;
|
||||
clip: true;
|
||||
|
||||
if root.has-image: Image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
source: root.source;
|
||||
image-fit: cover;
|
||||
}
|
||||
|
||||
if !root.has-image: Shape {
|
||||
size: 64px;
|
||||
x: (parent.width - self.width) / 2;
|
||||
y: (parent.height - self.height) / 2;
|
||||
shape: ShapeKind.clover;
|
||||
fill: Theme.tertiary-container;
|
||||
glyph: Icons.music-note;
|
||||
glyph-color: Theme.on-tertiary-container;
|
||||
}
|
||||
}
|
||||
|
||||
drop := DropArea {
|
||||
can-drop(event) => {
|
||||
event.proposed-action
|
||||
}
|
||||
dropped(event) => {
|
||||
root.dropped(event.data);
|
||||
event.proposed-action
|
||||
}
|
||||
}
|
||||
|
||||
// While an image is dragged over it.
|
||||
Rectangle {
|
||||
border-radius: Theme.corner-md;
|
||||
border-width: 2px;
|
||||
border-color: Theme.primary;
|
||||
background: Theme.primary.with-alpha(Theme.state-drag);
|
||||
opacity: drop.has-drag ? 1 : 0;
|
||||
animate opacity {
|
||||
duration: Motion.time(Motion.short3);
|
||||
easing: Motion.standard;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Edits the tags of one or many files. `saved` runs on Save and `lookup` on "Look up online";
|
||||
// the owner closes the dialog, or sets `error`.
|
||||
export component TagEditorDialog inherits Dialog {
|
||||
glyph: Icons.audio;
|
||||
in-out property <TagEditorData> data;
|
||||
callback saved();
|
||||
callback lookup();
|
||||
callback field-changed(int, string);
|
||||
callback cover-path-accepted(string);
|
||||
callback cover-dropped(data-transfer);
|
||||
callback cover-removed();
|
||||
callback cover-reset();
|
||||
|
||||
title: "Edit tags";
|
||||
body: root.data.subtitle;
|
||||
dialog-width: 680px;
|
||||
actions: [
|
||||
{ text: "Cancel", kind: ButtonKind.text },
|
||||
{ text: "Look up online", kind: ButtonKind.tonal },
|
||||
{ text: root.data.saving ? "Saving…" : "Save", kind: ButtonKind.filled }
|
||||
];
|
||||
default-action: 2;
|
||||
cancel-action: 0;
|
||||
content-focus: true;
|
||||
focus-content => {
|
||||
title-field.focus-input();
|
||||
}
|
||||
action(i) => {
|
||||
if root.data.saving {
|
||||
return;
|
||||
}
|
||||
if i == 0 {
|
||||
root.close();
|
||||
} else if i == 1 {
|
||||
root.lookup();
|
||||
} else {
|
||||
root.saved();
|
||||
}
|
||||
}
|
||||
|
||||
// The fields scroll when the window is too short for all of them.
|
||||
Rectangle {
|
||||
height: min(fields.preferred-height, max(160px, root.height - 300px));
|
||||
|
||||
ScrollView {
|
||||
fields := VerticalLayout {
|
||||
spacing: Theme.space-1;
|
||||
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-4;
|
||||
|
||||
VerticalLayout {
|
||||
spacing: Theme.space-1;
|
||||
alignment: start;
|
||||
|
||||
CoverBox {
|
||||
source: root.data.cover;
|
||||
has-image: root.data.has-cover;
|
||||
dropped(data) => {
|
||||
root.cover-dropped(data);
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
|
||||
IconButton {
|
||||
icon: Icons.delete;
|
||||
size: 32px;
|
||||
icon-size: 20px;
|
||||
tooltip: "Remove the cover";
|
||||
clicked => {
|
||||
root.cover-removed();
|
||||
}
|
||||
}
|
||||
|
||||
IconButton {
|
||||
icon: Icons.restore;
|
||||
size: 32px;
|
||||
icon-size: 20px;
|
||||
tooltip: "Undo cover changes";
|
||||
clicked => {
|
||||
root.cover-reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
text: root.data.cover-note;
|
||||
horizontal-alignment: center;
|
||||
color: Theme.on-surface-variant;
|
||||
font-size: Theme.label-medium.size;
|
||||
font-weight: Theme.label-medium.weight;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
alignment: start;
|
||||
|
||||
title-field := TagInput {
|
||||
field: root.data.fields[0];
|
||||
changed(text) => {
|
||||
root.field-changed(0, text);
|
||||
}
|
||||
}
|
||||
|
||||
TextField {
|
||||
label: "Cover image (full path, then Enter) or drop one on the cover";
|
||||
placeholder: "/path/to/cover.jpg";
|
||||
text <=> root.data.cover-path;
|
||||
accepted(text) => {
|
||||
root.cover-path-accepted(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
|
||||
TagInput {
|
||||
field: root.data.fields[1];
|
||||
changed(text) => {
|
||||
root.field-changed(1, text);
|
||||
}
|
||||
}
|
||||
|
||||
TagInput {
|
||||
field: root.data.fields[2];
|
||||
changed(text) => {
|
||||
root.field-changed(2, text);
|
||||
}
|
||||
}
|
||||
|
||||
TagInput {
|
||||
field: root.data.fields[3];
|
||||
changed(text) => {
|
||||
root.field-changed(3, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
|
||||
TagInput {
|
||||
field: root.data.fields[4];
|
||||
changed(text) => {
|
||||
root.field-changed(4, text);
|
||||
}
|
||||
}
|
||||
|
||||
TagInput {
|
||||
field: root.data.fields[5];
|
||||
changed(text) => {
|
||||
root.field-changed(5, text);
|
||||
}
|
||||
}
|
||||
|
||||
TagInput {
|
||||
field: root.data.fields[6];
|
||||
changed(text) => {
|
||||
root.field-changed(6, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
|
||||
TagInput {
|
||||
field: root.data.fields[7];
|
||||
changed(text) => {
|
||||
root.field-changed(7, text);
|
||||
}
|
||||
}
|
||||
|
||||
TagInput {
|
||||
field: root.data.fields[8];
|
||||
changed(text) => {
|
||||
root.field-changed(8, text);
|
||||
}
|
||||
}
|
||||
|
||||
TagInput {
|
||||
field: root.data.fields[9];
|
||||
changed(text) => {
|
||||
root.field-changed(9, text);
|
||||
}
|
||||
}
|
||||
|
||||
TagInput {
|
||||
field: root.data.fields[10];
|
||||
changed(text) => {
|
||||
root.field-changed(10, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TagInput {
|
||||
field: root.data.fields[11];
|
||||
changed(text) => {
|
||||
root.field-changed(11, text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if root.data.saving: Rectangle {
|
||||
height: 4px;
|
||||
border-radius: Theme.corner-full(4px);
|
||||
background: Theme.surface-container-highest;
|
||||
|
||||
Rectangle {
|
||||
x: 0;
|
||||
width: parent.width * root.data.progress;
|
||||
border-radius: parent.border-radius;
|
||||
background: Theme.primary;
|
||||
animate width {
|
||||
duration: Motion.time(Motion.short4);
|
||||
easing: Motion.standard;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if root.data.error != "": Text {
|
||||
text: root.data.error;
|
||||
color: Theme.error;
|
||||
font-size: Theme.body-small.size;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
}
|
||||
271
crates/tunal/ui/dialogs/tag-lookup.slint
Normal file
271
crates/tunal/ui/dialogs/tag-lookup.slint
Normal file
|
|
@ -0,0 +1,271 @@
|
|||
import { ListView } from "std-widgets.slint";
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Motion } from "../motion.slint";
|
||||
import { Icons } from "../components/icon.slint";
|
||||
import { Dialog } from "../components/dialog.slint";
|
||||
import { ButtonKind } from "../components/button.slint";
|
||||
import { IconButton } from "../components/icon-button.slint";
|
||||
import { ListRow } from "../components/list-row.slint";
|
||||
import { Switch } from "../components/switch.slint";
|
||||
import { TextField } from "../components/text-field.slint";
|
||||
|
||||
// A release found by the search.
|
||||
export struct ReleaseRow {
|
||||
title: string,
|
||||
// "Artist · 2020 · XW · 12 tracks".
|
||||
detail: string,
|
||||
cover: image,
|
||||
has-cover: bool,
|
||||
}
|
||||
|
||||
// One file and the release track it gets. `old-title` is what the file has now.
|
||||
export struct MapRow {
|
||||
file: string,
|
||||
old-title: string,
|
||||
track: string,
|
||||
matched: bool,
|
||||
}
|
||||
|
||||
export struct TagLookupData {
|
||||
// 0 search, 1 pick a release, 2 match files to tracks.
|
||||
step: int,
|
||||
busy: bool,
|
||||
// A plain line under the fields: progress, or why nothing came back.
|
||||
status: string,
|
||||
failed: bool,
|
||||
artist: string,
|
||||
album: string,
|
||||
results: [ReleaseRow],
|
||||
selected: int,
|
||||
// The chosen release, for the last step.
|
||||
release: string,
|
||||
mapping: [MapRow],
|
||||
summary: string,
|
||||
embed-cover: bool,
|
||||
cover: image,
|
||||
has-cover: bool,
|
||||
}
|
||||
|
||||
// Looks a release up on MusicBrainz and copies its tags and cover to the files. The owner
|
||||
// closes the dialog; `apply` runs on the last step.
|
||||
export component TagLookupDialog inherits Dialog {
|
||||
glyph: Icons.search;
|
||||
in-out property <TagLookupData> data;
|
||||
callback artist-edited(string);
|
||||
callback album-edited(string);
|
||||
callback search();
|
||||
callback release-picked(int);
|
||||
callback next();
|
||||
callback back();
|
||||
callback cancelled();
|
||||
callback map-step(int, int);
|
||||
callback embed-toggled(bool);
|
||||
callback apply();
|
||||
|
||||
title: "Look up tags";
|
||||
body: root.data.step == 0 ? "Search MusicBrainz for the album these files belong to."
|
||||
: root.data.step == 1 ? "Pick the release."
|
||||
: root.data.release;
|
||||
dialog-width: 640px;
|
||||
actions: root.data.step == 0
|
||||
? [{ text: "Cancel", kind: ButtonKind.text }, { text: "Search", kind: ButtonKind.filled }]
|
||||
: root.data.step == 1
|
||||
? [{ text: "Back", kind: ButtonKind.text }, { text: "Continue", kind: ButtonKind.filled }]
|
||||
: [{ text: "Back", kind: ButtonKind.text }, { text: "Apply", kind: ButtonKind.filled }];
|
||||
default-action: 1;
|
||||
cancel-action: 0;
|
||||
content-focus: root.data.step == 0;
|
||||
// The artist field (inside the first step) takes the focus when this changes.
|
||||
property <int> focus-request;
|
||||
focus-content => {
|
||||
root.focus-request += 1;
|
||||
}
|
||||
action(i) => {
|
||||
if root.data.busy {
|
||||
return;
|
||||
}
|
||||
if i == 0 {
|
||||
if root.data.step == 0 {
|
||||
root.cancelled();
|
||||
} else {
|
||||
root.back();
|
||||
}
|
||||
} else if root.data.step == 0 {
|
||||
root.search();
|
||||
} else if root.data.step == 1 {
|
||||
root.next();
|
||||
} else {
|
||||
root.apply();
|
||||
}
|
||||
}
|
||||
|
||||
if root.data.step == 0: VerticalLayout {
|
||||
artist-field := TextField {
|
||||
property <int> request: root.focus-request;
|
||||
|
||||
changed request => {
|
||||
self.focus-input();
|
||||
}
|
||||
label: "Artist";
|
||||
text: root.data.artist;
|
||||
edited(text) => {
|
||||
root.artist-edited(text);
|
||||
}
|
||||
accepted => {
|
||||
root.search();
|
||||
}
|
||||
}
|
||||
|
||||
TextField {
|
||||
label: "Album";
|
||||
text: root.data.album;
|
||||
edited(text) => {
|
||||
root.album-edited(text);
|
||||
}
|
||||
accepted => {
|
||||
root.search();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if root.data.step == 1: VerticalLayout {
|
||||
spacing: Theme.space-1;
|
||||
|
||||
for item[i] in root.data.results: ListRow {
|
||||
icon: Icons.audio;
|
||||
title: item.title;
|
||||
supporting: item.detail;
|
||||
shaped: true;
|
||||
shape-size: 44px;
|
||||
picture: item.cover;
|
||||
has-picture: item.has-cover;
|
||||
selected: i == root.data.selected;
|
||||
clicked => {
|
||||
root.release-picked(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if root.data.step == 2: VerticalLayout {
|
||||
spacing: Theme.space-2;
|
||||
|
||||
Rectangle {
|
||||
height: min(root.data.mapping.length * 52px + 4px, 280px);
|
||||
|
||||
ListView {
|
||||
for row[i] in root.data.mapping: Rectangle {
|
||||
height: 52px;
|
||||
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
padding-right: Theme.space-2;
|
||||
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
alignment: center;
|
||||
|
||||
Text {
|
||||
text: row.file;
|
||||
color: Theme.on-surface;
|
||||
font-size: Theme.body-medium.size;
|
||||
font-weight: Theme.body-medium.weight;
|
||||
overflow: elide;
|
||||
}
|
||||
|
||||
Text {
|
||||
text: row.old-title == "" ? "No title yet" : row.old-title;
|
||||
color: Theme.on-surface-variant;
|
||||
font-size: Theme.body-small.size;
|
||||
font-weight: Theme.body-small.weight;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
|
||||
IconButton {
|
||||
icon: Icons.arrow-back;
|
||||
size: 32px;
|
||||
icon-size: 20px;
|
||||
tooltip: "Previous track";
|
||||
clicked => {
|
||||
root.map-step(i, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
width: 220px;
|
||||
text: row.matched ? row.track : "Keep this file as it is";
|
||||
color: row.matched ? Theme.primary : Theme.on-surface-variant;
|
||||
font-size: Theme.body-medium.size;
|
||||
font-weight: Theme.label-large.weight;
|
||||
vertical-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
|
||||
IconButton {
|
||||
icon: Icons.arrow-forward;
|
||||
size: 32px;
|
||||
icon-size: 20px;
|
||||
tooltip: "Next track";
|
||||
clicked => {
|
||||
root.map-step(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
|
||||
Text {
|
||||
horizontal-stretch: 1;
|
||||
text: root.data.has-cover ? "Embed the release cover" : "No cover found for this release";
|
||||
color: Theme.on-surface;
|
||||
font-size: Theme.body-medium.size;
|
||||
font-weight: Theme.body-medium.weight;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
|
||||
if root.data.has-cover: Image {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
source: root.data.cover;
|
||||
image-fit: cover;
|
||||
}
|
||||
|
||||
Switch {
|
||||
enabled: root.data.has-cover;
|
||||
checked: root.data.embed-cover && root.data.has-cover;
|
||||
accessible-label: "Embed the release cover";
|
||||
clicked => {
|
||||
root.embed-toggled(!root.data.embed-cover);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
text: root.data.summary;
|
||||
color: Theme.on-surface-variant;
|
||||
font-size: Theme.body-small.size;
|
||||
font-weight: Theme.body-small.weight;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
}
|
||||
|
||||
if root.data.status != "": Text {
|
||||
text: root.data.status;
|
||||
color: root.data.failed ? Theme.error : Theme.on-surface-variant;
|
||||
font-size: Theme.body-small.size;
|
||||
font-weight: Theme.body-small.weight;
|
||||
wrap: word-wrap;
|
||||
}
|
||||
}
|
||||
|
|
@ -193,6 +193,13 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done,
|
|||
- Not done: real phone, hotplug events, MTP events, permission message (S036). Breadcrumb shows the serial and storage hex, not names. Long transfers hold the device lock (listing waits).
|
||||
- Later: device/storage names in breadcrumb; cancel a running GetObject (MTP Cancel request); free space in the sidebar tooltip.
|
||||
|
||||
## S021 — Tag editor UI
|
||||
- Done: action `edit-tags` ("Edit tags…", enabled when every selected entry is a local audio file; in the File and Several-items default menus; a saved `menus.toml` keeps its own layout). `tags_bridge.rs` (`Tags`), `ui/dialogs/tag-editor.slint` (`TagEditorDialog`), `tag-lookup.slint` (`TagLookupDialog`). Editor: 12 text fields (title, artist, album, album artist, genre, composer, date, track/disc no. and total, comment), mixed ones empty with "Keep"; an untouched field stays Keep, emptied = Clear, typed = Set (numbers checked); cover box (current/new/removed, remove + undo, image path field, drop an image file on it); Save writes off-thread with a progress bar, failed files listed and the dialog stays open; fields scroll when the window is short. "Look up online" → search (prefilled from the fields/tags; releases with as many tracks as files first) → releases with title, artist, date, country, track count and cover (first 6, fetched one by one) → files ↔ tracks (`match_tracks`, arrows to change, a track used twice is skipped, "Keep this file as it is") + embed-cover switch + summary → Apply writes title/artist/album/album artist/track+disc numbers and totals/date/first genre/MusicBrainz ids/cover on matched files. Errors (offline, busy, nothing found, release gone) as plain lines. Panes list again after a write. `tunal-tags::duration_ms(path)` added for matching.
|
||||
- Tools (CLAUDE.md §5): `TUNAL_TAGS=editor|lookup|mapping|apply:<file>:<file>…` with `TUNAL_TAGS_SYNC=1` (work in place) and `TUNAL_MUSICBRAINZ=<base url>` (mock for both services).
|
||||
- Verified: workspace build, clippy -D warnings, fmt --check, literal grep empty; screenshots light + dark of the multi-file editor, lookup results (cover shown) and mapping, against a scratchpad python mock; `apply` on scratch mp3s fixed album, set totals/date/genre/ids and replaced the cover (read back with the `tags` example). Real music and real MusicBrainz untouched.
|
||||
- Not done: no live window (typing, drop, clicks, progress bar motion, scrolling); no file chooser for the cover (path field or drop); a mixed field can't be cleared on purpose (only set); lookup apply doesn't offer per-field choice; offline/busy messages not seen live.
|
||||
- Later: file chooser; per-field "clear" for mixed values; recording search by title when no album; lookup for one file with no album tag uses the file name.
|
||||
|
||||
## Later
|
||||
- (orchestrator) Breadcrumb: a long path is hard-clipped at the bar's left edge with no elision mark, and the root crumb elides at 960 px — for S034.
|
||||
-
|
||||
|
|
|
|||
Loading…
Reference in a new issue