feat(locallibrary): tag editor modal — manual edit + sidecar/direct save

The local-album tag editor (no remote lookup yet — that lands with the
remote-metadata crate move). Opens from a pencil on the local album detail.

- TagEditorModal.slint: album title/artist + year/genre/catalog + per-track
  title/track#/disc# table (indexed model write-back) + persistence QbzSelect
  (sidecar default / direct opt-in) + save-with-progress. Mounted last in
  AppShell (ADR-009 by mount order). ADR-008: dropdown, no pills.
- tag_editor.rs controller: open_tag_editor (off-thread pre-fetch via
  fetch_album_tracks_blocking + D1 year seed + can-direct-write CUE guard),
  save_tags (validate, is_dir gate, CUE guard, one-time direct-write confirm
  via rfd + library_kv ack, sidecar/direct branch on spawn_blocking with
  per-file progress, update_album_group_metadata via new with_db_mut, post-save
  refresh of the album + browse models), close.
- AlbumPageView: edit pencil CircleAction, visible is-local && source != plex;
  AlbumState gains `source`, set in apply_local_album.
- library_db: with_db_mut for the transactional metadata update.
- main.rs: on_media_action("album","edit") + TagEditorActions wiring (close/
  save/set-persistence with the CUE gate).

cc
This commit is contained in:
vicrodh committed 2026-05-29 15:03:58 -06:00
1 parent 7e0d970fd5
commit 4e79386daf
9 files changed
+838 -1

No files matched your search

+19
View File
@@ -81,6 +81,25 @@ where
}
}
/// Like `with_db`, but hands `f` a `&mut LibraryDatabase` — required by
/// methods that open a transaction (e.g. `update_album_group_metadata`). The
/// connection is opened fresh per call on the current (blocking) thread, so a
/// mutable borrow is free. Returns None (logged) if the DB can't be opened or
/// the op errors.
pub fn with_db_mut<F, R>(f: F) -> Option<R>
where
F: FnOnce(&mut LibraryDatabase) -> Result<R, LibraryError>,
{
let mut db = open()?;
match f(&mut db) {
Ok(r) => Some(r),
Err(e) => {
log::error!("[qbz-slint] library.db mut op failed: {e}");
None
}
}
}
/// Resolve the artwork-cache directory used for copied custom images,
/// matching Tauri (`<cache_dir>/qbz/artwork`).
pub fn artwork_cache_dir() -> Option<PathBuf> {
+7
View File
@@ -655,6 +655,12 @@ pub fn apply_local_album(
};
let total_secs: u64 = tracks.iter().map(|t| t.duration_secs).sum();
let info_line = format!("{} tracks · {}", tracks.len(), fmt_album_duration(total_secs));
// Album source for the tag-editor pencil gate (hidden for Plex). Computed
// before `tracks` is consumed below.
let source = tracks
.first()
.and_then(|t| t.source.clone())
.unwrap_or_default();
let items: Vec<TrackItem> = tracks
.into_iter()
.map(|t| {
@@ -667,6 +673,7 @@ pub fn apply_local_album(
let s = window.global::<crate::AlbumState>();
s.set_id(group_key.into());
s.set_is_local(true);
s.set_source(source.into());
s.set_title(title.into());
s.set_artist(artist.into());
s.set_artist_id("".into());
+38
View File
@@ -45,6 +45,7 @@ mod folders;
mod library_db;
mod local_library;
mod local_library_settings;
mod tag_editor;
mod offline;
mod offline_cache;
mod offline_manager;
@@ -2293,6 +2294,11 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
handle.clone(),
id,
),
("album", "edit") => {
// Open the local-album tag editor (group_key == directory_path
// for folder-grouped local albums).
tag_editor::open_tag_editor(weak.clone(), handle.clone(), id.clone(), id);
}
("album", "radio") => playback::play_album_radio(
runtime.clone(),
weak.clone(),
@@ -4147,6 +4153,38 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
.on_stop_scan(move || local_library_settings::stop_scan());
}
// Tag editor (local album metadata) — open via on_media_action("album",
// "edit"); these wire the modal's own actions.
{
let weak = window.as_weak();
window
.global::<TagEditorActions>()
.on_close(move || tag_editor::close_tag_editor(weak.clone()));
}
{
let weak = window.as_weak();
let handle = tokio_rt.handle().clone();
window
.global::<TagEditorActions>()
.on_save(move || tag_editor::save_tags(weak.clone(), handle.clone()));
}
{
let weak = window.as_weak();
window
.global::<TagEditorActions>()
.on_set_persistence(move |i| {
if let Some(w) = weak.upgrade() {
let s = w.global::<TagEditorState>();
// Ignore selecting Direct when unavailable (CUE album).
if i == 1 && !s.get_can_direct_write() {
s.set_persistence_index(0);
} else {
s.set_persistence_index(i);
}
}
});
}
// Local Library — Albums tab controls (search / sort re-query page 1;
// load-more pages on scroll; retry) + the shared AlbumCollectionView's
// open / per-card actions (album-detail + playback land with later slices).
+405
View File
@@ -0,0 +1,405 @@
//! Tag editor controller (Slint) — local album metadata.
//!
//! Opens from the local album detail's edit pencil, edits album + per-track
//! fields, and persists via sidecar (default) or opt-in direct file-write
//! (one-time confirm, blocked for CUE albums). The DB index is updated in the
//! same transaction. All DB / lofty work runs on `spawn_blocking`; the rfd
//! confirm runs async. Remote MusicBrainz/Discogs lookup is a follow-up.
use std::path::Path;
use std::sync::atomic::{AtomicU64, Ordering};
use slint::{ComponentHandle, Model, ModelRc, VecModel, Weak};
use qbz_library::{
AlbumMetadataOverride, AlbumTagSidecar, AlbumTagWrite, AlbumTrackUpdate, LibraryError,
TrackMetadataOverride, TrackTagWrite,
};
use crate::{AppWindow, TagEditorState, TagTrackEdit};
/// kv key for the direct-write one-time acknowledgement (replaces the Tauri
/// localStorage flag; cross-compat not required for an ack bit).
const ACK_KEY: &str = "localLibrary.tagEditor.directWriteAcknowledged";
/// Save generation — a newer save supersedes a slow one on apply.
static SAVE_GEN: AtomicU64 = AtomicU64::new(0);
/// Parse the year input (trim; empty => None = clear; 0..=3000 allowed).
fn parse_year(s: &str) -> Result<Option<u32>, ()> {
let t = s.trim();
if t.is_empty() {
return Ok(None);
}
match t.parse::<i64>() {
Ok(y) if (0..=3000).contains(&y) => Ok(Some(y as u32)),
_ => Err(()),
}
}
/// Lenient u32 parse for track/disc numbers (empty/invalid => None).
fn parse_num(s: &str) -> Option<u32> {
let t = s.trim();
if t.is_empty() {
return None;
}
t.parse::<u32>().ok()
}
/// Open the editor for a local album. Pre-fetches the album's tracks off-thread
/// (LocalTrack carries file_path/cue_* the AlbumState rows lack), then seeds +
/// opens on the UI thread. `group_key` and `directory_path` are equal for
/// folder-grouped local albums (the common case).
pub fn open_tag_editor(
weak: Weak<AppWindow>,
handle: tokio::runtime::Handle,
group_key: String,
directory_path: String,
) {
let gk = group_key.clone();
handle.spawn(async move {
let tracks = tokio::task::spawn_blocking(move || {
crate::local_library::fetch_album_tracks_blocking(&gk)
})
.await
.unwrap_or_default();
let _ = weak.upgrade_in_event_loop(move |w| {
populate(&w, group_key, directory_path, tracks);
});
});
}
fn populate(
w: &AppWindow,
group_key: String,
directory_path: String,
tracks: Vec<qbz_library::LocalTrack>,
) {
let album_title = tracks
.first()
.map(|t| {
if !t.album_group_title.is_empty() {
t.album_group_title.clone()
} else {
t.album.clone()
}
})
.unwrap_or_default();
let album_artist = qbz_library::compute_track_artist_match(&tracks).unwrap_or_default();
let year = tracks
.iter()
.find_map(|t| t.year)
.map(|y| y.to_string())
.unwrap_or_default();
let genre = tracks
.iter()
.find_map(|t| t.genre.clone().filter(|g| !g.trim().is_empty()))
.unwrap_or_default();
let catalog = tracks
.iter()
.find_map(|t| t.catalog_number.clone().filter(|c| !c.trim().is_empty()))
.unwrap_or_default();
let total_discs = tracks
.iter()
.filter_map(|t| t.disc_number)
.max()
.unwrap_or(1)
.max(1) as i32;
let can_direct = tracks
.iter()
.all(|t| t.cue_file_path.is_none() && t.cue_start_secs.is_none());
let rows: Vec<TagTrackEdit> = tracks
.iter()
.map(|t| TagTrackEdit {
id: t.id as i32,
file_path: t.file_path.clone().into(),
cue_file_path: t.cue_file_path.clone().unwrap_or_default().into(),
cue_start_secs: t.cue_start_secs.unwrap_or(-1.0) as f32,
has_cue: t.cue_file_path.is_some() || t.cue_start_secs.is_some(),
title: t.title.clone().into(),
disc_number: t.disc_number.map(|n| n.to_string()).unwrap_or_default().into(),
track_number: t.track_number.map(|n| n.to_string()).unwrap_or_default().into(),
})
.collect();
let s = w.global::<TagEditorState>();
s.set_album_group_key(group_key.into());
s.set_directory_path(directory_path.into());
s.set_album_title(album_title.into());
s.set_album_artist(album_artist.into());
s.set_year_input(year.into());
s.set_genre(genre.into());
s.set_catalog_number(catalog.into());
s.set_album_total_discs(total_discs);
s.set_can_direct_write(can_direct);
s.set_persistence_index(0);
s.set_saving(false);
s.set_write_progress_current(0);
s.set_write_progress_total(0);
s.set_tracks(ModelRc::new(VecModel::from(rows)));
s.set_open(true);
}
pub fn close_tag_editor(weak: Weak<AppWindow>) {
let _ = weak.upgrade_in_event_loop(|w| {
w.global::<TagEditorState>().set_open(false);
});
}
/// Persist the edits. Validates, gates the directory + CUE for direct mode,
/// confirms direct-write once, then writes (sidecar or files) + updates the DB
/// index on a blocking thread, and refreshes the open album.
pub fn save_tags(weak: Weak<AppWindow>, handle: tokio::runtime::Handle) {
let Some(w) = weak.upgrade() else {
return;
};
let s = w.global::<TagEditorState>();
let group_key = s.get_album_group_key().to_string();
let album_title = s.get_album_title().trim().to_string();
let album_artist = s.get_album_artist().to_string();
let year_input = s.get_year_input().to_string();
let genre = s.get_genre().to_string();
let catalog = s.get_catalog_number().to_string();
let directory_path = s.get_directory_path().to_string();
let direct = s.get_persistence_index() == 1;
let model = s.get_tracks();
let rows: Vec<TagTrackEdit> = (0..model.row_count())
.filter_map(|i| model.row_data(i))
.collect();
// Validate (UI thread; toast + abort, leave the modal open).
if album_title.is_empty() {
crate::toast::error_weak(&weak, "Album title is required");
return;
}
if rows.iter().any(|r| r.title.trim().is_empty()) {
crate::toast::error_weak(&weak, "Every track needs a title");
return;
}
let year = match parse_year(&year_input) {
Ok(y) => y,
Err(()) => {
crate::toast::error_weak(&weak, "Year must be a number");
return;
}
};
let album_dir = group_key.trim().to_string();
if !Path::new(&album_dir).is_dir() {
crate::toast::error_weak(&weak, "Album folder not found on disk");
return;
}
if direct && rows.iter().any(|r| r.has_cue) {
crate::toast::error_weak(
&weak,
"Writing tags to files isn't supported for CUE albums; use sidecar mode",
);
return;
}
// Build the Send-safe payloads up front.
let artist_opt = {
let a = album_artist.trim();
if a.is_empty() {
None
} else {
Some(a.to_string())
}
};
let genre_opt = {
let g = genre.trim();
if g.is_empty() {
None
} else {
Some(g.to_string())
}
};
let catalog_opt = {
let c = catalog.trim();
if c.is_empty() {
None
} else {
Some(c.to_string())
}
};
let track_updates: Vec<AlbumTrackUpdate> = rows
.iter()
.map(|r| AlbumTrackUpdate {
id: r.id as i64,
title: r.title.trim().to_string(),
disc_number: parse_num(&r.disc_number),
track_number: parse_num(&r.track_number),
})
.collect();
let tw_tracks: Vec<TrackTagWrite> = rows
.iter()
.map(|r| TrackTagWrite {
file_path: r.file_path.to_string(),
title: r.title.trim().to_string(),
track_number: parse_num(&r.track_number),
disc_number: parse_num(&r.disc_number),
})
.collect();
let track_overs: Vec<TrackMetadataOverride> = rows
.iter()
.map(|r| TrackMetadataOverride {
file_path: r.file_path.to_string(),
cue_start_secs: if r.cue_start_secs >= 0.0 {
Some(r.cue_start_secs as f64)
} else {
None
},
title: Some(r.title.trim().to_string()),
disc_number: parse_num(&r.disc_number),
track_number: parse_num(&r.track_number),
})
.collect();
let album_over = AlbumMetadataOverride {
album_title: Some(album_title.clone()),
album_artist: artist_opt.clone(),
year,
genre: genre_opt.clone(),
catalog_number: catalog_opt.clone(),
};
let tw_album = AlbumTagWrite {
album_title: album_title.clone(),
album_artist: album_artist.clone(),
year,
genre: genre_opt.clone(),
catalog_number: catalog_opt.clone(),
};
let handle2 = handle.clone();
handle.spawn(async move {
// Direct-write one-time confirm.
if direct {
let acked = tokio::task::spawn_blocking(|| {
crate::library_db::with_db(|db| db.get_kv(ACK_KEY))
})
.await
.ok()
.flatten()
.flatten()
.as_deref()
== Some("1");
if !acked {
let ok = rfd::AsyncMessageDialog::new()
.set_title("Write tags to audio files?")
.set_description(
"This modifies your audio files on disk and cannot be undone.",
)
.set_buttons(rfd::MessageButtons::YesNo)
.show()
.await
== rfd::MessageDialogResult::Yes;
if !ok {
return;
}
let _ = tokio::task::spawn_blocking(|| {
crate::library_db::with_db(|db| db.set_kv(ACK_KEY, "1"))
})
.await;
}
}
let gen = SAVE_GEN.fetch_add(1, Ordering::SeqCst) + 1;
let _ = weak.upgrade_in_event_loop(|w| {
w.global::<TagEditorState>().set_saving(true);
});
let weak_p = weak.clone();
let album_dir_c = album_dir.clone();
let group_key_c = group_key.clone();
let album_title_c = album_title.clone();
let album_artist_c = album_artist.clone();
let genre_d = genre_opt.clone();
let catalog_d = catalog_opt.clone();
let result: Result<(), LibraryError> = tokio::task::spawn_blocking(move || {
let dir = Path::new(&album_dir_c);
if direct {
qbz_library::write_album_tags_to_files(&tw_album, &tw_tracks, |cur, tot| {
let _ = weak_p.upgrade_in_event_loop(move |w| {
let s = w.global::<TagEditorState>();
s.set_write_progress_current(cur as i32);
s.set_write_progress_total(tot as i32);
});
})?;
let _ = qbz_library::delete_album_sidecar(dir);
} else {
let sidecar = AlbumTagSidecar::new(album_over, track_overs);
qbz_library::write_album_sidecar(dir, &sidecar)?;
}
// DB index update (transactional -> &mut db).
crate::library_db::with_db_mut(|db| {
let existing = db.get_album_tracks(&group_key_c)?;
let m = qbz_library::compute_track_artist_match(&existing);
db.update_album_group_metadata(
&group_key_c,
&album_title_c,
&album_artist_c,
year,
genre_d.as_deref(),
catalog_d.as_deref(),
m.as_deref(),
&track_updates,
)
})
.ok_or_else(|| LibraryError::Database("library index update failed".to_string()))?;
Ok(())
})
.await
.unwrap_or_else(|e| Err(LibraryError::Other(format!("save task panicked: {e}"))));
let ok = result.is_ok();
let err_msg = result.err().map(|e| e.to_string()).unwrap_or_default();
let _ = weak.upgrade_in_event_loop(move |w| {
if SAVE_GEN.load(Ordering::SeqCst) != gen {
return;
}
let s = w.global::<TagEditorState>();
s.set_saving(false);
s.set_write_progress_current(0);
s.set_write_progress_total(0);
if ok {
s.set_open(false);
}
});
if ok {
crate::toast::success_weak(&weak, "Album metadata saved");
// Refresh the open album detail + reset browse models (D7).
refresh_after_save(weak.clone(), handle2.clone(), group_key.clone());
} else {
crate::toast::error_weak(&weak, format!("Couldn't save metadata: {err_msg}"));
}
let _ = directory_path; // reserved (explicit directory plumbing, if added later)
});
}
/// Re-fetch the album's tracks and re-apply the detail view, and reset the
/// LocalLibrary browse models so the tabs re-fetch on next visit. Avoids a
/// full library reload (the 16K-track freeze).
fn refresh_after_save(weak: Weak<AppWindow>, handle: tokio::runtime::Handle, group_key: String) {
handle.spawn(async move {
let gk = group_key.clone();
let tracks = tokio::task::spawn_blocking(move || {
crate::local_library::fetch_album_tracks_blocking(&gk)
})
.await
.unwrap_or_default();
let _ = weak.upgrade_in_event_loop(move |w| {
crate::local_library::apply_local_album(&w, &group_key, tracks);
// Reset browse models so Albums/Folders/Tracks/Artists re-fetch.
let s = w.global::<crate::LocalLibraryState>();
let empty_albums = ModelRc::new(VecModel::from(Vec::<crate::AlbumCardItem>::new()));
let empty_tracks = ModelRc::new(VecModel::from(Vec::<crate::TrackItem>::new()));
s.set_albums(empty_albums.clone());
s.set_folders(empty_albums);
s.set_tracks(empty_tracks);
s.set_artists(ModelRc::new(VecModel::from(Vec::<crate::LocalArtistItem>::new())));
});
});
}
@@ -338,6 +338,17 @@ export component AlbumPageView inherits Rectangle {
alignment: center;
CircleAction { icon: @image-url("../assets/icons/shuffle.svg"); }
}
// Edit metadata (tag editor) — local albums only; hidden
// for Plex (tag write isn't supported there).
if AlbumState.is-local && AlbumState.source != "plex": VerticalLayout {
alignment: center;
CircleAction {
icon: @image-url("../assets/icons/pencil.svg");
clicked => {
root.media-action("album", AlbumState.id, "edit");
}
}
}
VerticalLayout {
alignment: center;
CircleAction {
+1 -1
View File
@@ -18,7 +18,7 @@ import { AppShell } from "shell/AppShell.slint";
import { Toast } from "primitives/Toast.slint";
// Re-export the state globals so the Rust layer can populate them.
export { HomeState, HomeActions, DiscoverBrowseState, DiscoverBrowseActions, ForYouState, MixState, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions, PlaylistPickerState, PlaylistPickerActions, PlaylistState, PlaylistActions, SidebarState, SidebarActions, CreatePlaylistState, CreatePlaylistActions, EditPlaylistState, EditPlaylistActions, CreateFolderState, CreateFolderActions, DragState, DragActions, PlaylistManagerState, PlaylistManagerActions, OfflineManagerState, OfflineManagerActions, LocalLibraryState, LocalLibraryActions, LibraryFoldersState, LibFolderEditState, LibraryManageActions, LibraryScanState, FolderEditState, FolderEditActions, ToastState } from "state.slint";
export { HomeState, HomeActions, DiscoverBrowseState, DiscoverBrowseActions, ForYouState, MixState, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions, PlaylistPickerState, PlaylistPickerActions, PlaylistState, PlaylistActions, SidebarState, SidebarActions, CreatePlaylistState, CreatePlaylistActions, EditPlaylistState, EditPlaylistActions, CreateFolderState, CreateFolderActions, DragState, DragActions, PlaylistManagerState, PlaylistManagerActions, OfflineManagerState, OfflineManagerActions, LocalLibraryState, LocalLibraryActions, LibraryFoldersState, LibFolderEditState, LibraryManageActions, LibraryScanState, TagEditorState, TagEditorActions, FolderEditState, FolderEditActions, ToastState } from "state.slint";
// Which top-level screen is shown. The app starts on `splash` while it
// restores a saved session, then resolves to `shell` or `login`.
@@ -0,0 +1,306 @@
// Local-album tag editor modal. Album + per-track fields, sidecar (default)
// or opt-in direct file-write. Mounted last in AppShell so it overlays all
// chrome (ADR-009). Remote MusicBrainz/Discogs lookup is a follow-up sub-slice.
//
// Driven by TagEditorState / TagEditorActions. visible:-gated (ADR-010 modal
// pattern, like EditPlaylistModal). ADR-008: persistence picker is a QbzSelect,
// no pills.
import { Theme } from "../foundation/semantic-colors.slint";
import { Typography } from "../foundation/typography.slint";
import { Radius } from "../foundation/radius.slint";
import { TagEditorState, TagEditorActions } from "../state.slint";
import { QbzIcon } from "QbzIcon.slint";
import { QbzSelect } from "QbzSelect.slint";
import { LineEdit, ScrollView } from "std-widgets.slint";
// A labeled field block (label above the control).
component Field inherits VerticalLayout {
in property <string> label;
spacing: 5px;
Text {
text: root.label;
color: Theme.text-muted;
font-size: Typography.legal;
font-weight: Typography.semibold;
}
@children
}
export component TagEditorModal inherits Rectangle {
visible: TagEditorState.open;
if TagEditorState.open: Rectangle {
background: #000000bf;
TouchArea {
mouse-cursor: default;
clicked => {
if (!TagEditorState.saving) {
TagEditorActions.close();
}
}
}
Rectangle {
width: Math.min(root.width - 80px, 820px);
height: Math.min(root.height - 80px, 720px);
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
border-radius: Radius.md;
background: Theme.surface-card;
border-width: 1px;
border-color: Theme.border-subtle;
drop-shadow-blur: 32px;
drop-shadow-color: #00000080;
TouchArea { }
VerticalLayout {
padding: 22px;
spacing: 14px;
// Header.
HorizontalLayout {
Text {
text: @tr("Edit metadata");
color: Theme.text-primary;
font-size: Typography.heading;
font-weight: Typography.semibold;
horizontal-stretch: 1;
vertical-alignment: center;
}
close-x := TouchArea {
width: 28px;
height: 28px;
mouse-cursor: pointer;
clicked => {
if (!TagEditorState.saving) {
TagEditorActions.close();
}
}
QbzIcon {
source: @image-url("../assets/icons/x.svg");
width: 17px;
height: 17px;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
tint: close-x.has-hover ? Theme.text-primary : Theme.text-muted;
}
}
}
// Album title + artist.
HorizontalLayout {
spacing: 12px;
Field {
label: @tr("Album title");
horizontal-stretch: 1;
LineEdit {
placeholder-text: @tr("Album title");
text <=> TagEditorState.album_title;
}
}
Field {
label: @tr("Album artist");
horizontal-stretch: 1;
LineEdit {
placeholder-text: @tr("Album artist");
text <=> TagEditorState.album_artist;
}
}
}
// Year / Genre / Catalog.
HorizontalLayout {
spacing: 12px;
Field {
label: @tr("Year");
width: 120px;
LineEdit {
placeholder-text: "—";
text <=> TagEditorState.year_input;
}
}
Field {
label: @tr("Genre");
horizontal-stretch: 1;
LineEdit {
placeholder-text: @tr("Genre");
text <=> TagEditorState.genre;
}
}
Field {
label: @tr("Catalog number");
horizontal-stretch: 1;
LineEdit {
placeholder-text: "—";
text <=> TagEditorState.catalog_number;
}
}
}
// Total discs (collected, not persisted — rendered once).
Text {
text: @tr("Total discs") + ": \{TagEditorState.album_total_discs}";
color: Theme.text-muted;
font-size: Typography.legal;
}
// Track table.
Text {
text: @tr("Tracks");
color: Theme.text-muted;
font-size: Typography.legal;
font-weight: Typography.semibold;
}
Rectangle {
vertical-stretch: 1;
border-radius: Radius.sm;
border-width: 1px;
border-color: Theme.border-subtle;
clip: true;
ScrollView {
horizontal-scrollbar-policy: ScrollBarPolicy.always-off;
VerticalLayout {
padding: 6px;
spacing: 4px;
for row[i] in TagEditorState.tracks: HorizontalLayout {
spacing: 8px;
height: 34px;
// Track number.
LineEdit {
width: 52px;
placeholder-text: "#";
text: row.track_number;
edited(t) => {
TagEditorState.tracks[i].track_number = t;
}
}
// Title.
LineEdit {
horizontal-stretch: 1;
placeholder-text: @tr("Title");
text: row.title;
edited(t) => {
TagEditorState.tracks[i].title = t;
}
}
// Disc.
LineEdit {
width: 52px;
placeholder-text: @tr("Disc");
text: row.disc_number;
edited(t) => {
TagEditorState.tracks[i].disc_number = t;
}
}
}
}
}
}
// Album path reference.
Text {
text: @tr("Album folder") + ": " + TagEditorState.directory_path;
color: Theme.text-muted;
font-size: Typography.legal;
overflow: elide;
}
// Footer: persistence picker (left) + Cancel/Save (right).
HorizontalLayout {
spacing: 12px;
VerticalLayout {
alignment: center;
QbzSelect {
menu-width: 220px;
options: [
@tr("Sidecar file (recommended)"),
@tr("Write to audio files"),
];
current-index: TagEditorState.persistence_index;
sm: true;
selected(i) => {
TagEditorActions.set-persistence(i);
}
}
}
// Direct-write warning / CUE-unsupported note.
VerticalLayout {
alignment: center;
horizontal-stretch: 1;
if TagEditorState.persistence_index == 1: Text {
text: @tr("This writes tags directly into your audio files.");
color: #d8a23a;
font-size: Typography.legal;
overflow: elide;
}
if !TagEditorState.can_direct_write: Text {
text: @tr("Direct write is unavailable for CUE-based albums.");
color: Theme.text-muted;
font-size: Typography.legal;
overflow: elide;
}
}
// Cancel.
VerticalLayout {
alignment: center;
Rectangle {
width: cancel-label.preferred-width + 28px;
height: 36px;
border-radius: Radius.sm;
background: cancel-ta.has-hover ? Theme.surface-hover : transparent;
border-width: 1px;
border-color: Theme.border-subtle;
opacity: TagEditorState.saving ? 0.5 : 1.0;
cancel-label := Text {
text: @tr("Cancel");
color: Theme.text-secondary;
font-size: Typography.body;
font-weight: Typography.medium;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
}
cancel-ta := TouchArea {
mouse-cursor: TagEditorState.saving ? default : pointer;
clicked => {
if (!TagEditorState.saving) {
TagEditorActions.close();
}
}
}
}
}
// Save.
VerticalLayout {
alignment: center;
Rectangle {
width: save-label.preferred-width + 36px;
height: 36px;
border-radius: Radius.sm;
background: save-ta.has-hover && !TagEditorState.saving
? Theme.accent-hover : Theme.accent;
opacity: TagEditorState.saving ? 0.6 : 1.0;
save-label := Text {
text: TagEditorState.write_progress_total > 0
? (@tr("Writing") + " \{TagEditorState.write_progress_current}/\{TagEditorState.write_progress_total}…")
: (TagEditorState.saving ? @tr("Saving…") : @tr("Save"));
color: Theme.accent-text;
font-size: Typography.body;
font-weight: Typography.semibold;
x: (parent.width - self.width) / 2;
y: (parent.height - self.height) / 2;
}
save-ta := TouchArea {
mouse-cursor: TagEditorState.saving ? default : pointer;
clicked => {
if (!TagEditorState.saving) {
TagEditorActions.save();
}
}
}
}
}
}
}
}
}
}
+4
View File
@@ -16,6 +16,7 @@ import { EditPlaylistModal } from "../primitives/EditPlaylistModal.slint";
import { CreateFolderModal } from "../primitives/CreateFolderModal.slint";
import { FolderEditModal } from "../primitives/FolderEditModal.slint";
import { LibFolderEditModal } from "../settings/LibFolderEditModal.slint";
import { TagEditorModal } from "../primitives/TagEditorModal.slint";
import { DragGhost } from "../primitives/DragGhost.slint";
import { PlayerBar } from "PlayerBar.slint";
import { QueueSidebar } from "QueueSidebar.slint";
@@ -284,6 +285,9 @@ export component AppShell inherits Rectangle {
// Global "Local Library folder settings" modal (Settings > Local Library).
LibFolderEditModal { }
// Global "Tag editor" modal (local album metadata).
TagEditorModal { }
// Floating track-drag ghost (follows the cursor, on top of all).
DragGhost { }
}
+47
View File
@@ -294,6 +294,9 @@ export global AlbumState {
// True when this is a Local Library album (local files / offline copies).
// Routes the play actions to local playback + hides Qobuz-only chrome.
in property <bool> is-local: false;
// Local source ("user" | "qobuz_download" | "plex" | ""). Gates the
// tag-editor pencil (hidden for Plex; tag write isn't supported there).
in property <string> source;
}
// Album-view actions wired to Rust callbacks.
@@ -592,6 +595,50 @@ export global LibraryManageActions {
callback set-filter(string /* query */);
}
// ============================ Tag editor ==================================
// Local-album metadata editor (Settings-independent modal launched from the
// local album detail). Sidecar (default) + opt-in direct file-write. Remote
// MusicBrainz/Discogs lookup lands as a follow-up sub-slice (needs the
// remote-metadata crate move).
// One editable track row. `cue_start_secs` is f64 (-1.0 = none); `has_cue`
// is precomputed (cue_file_path != "" || cue_start_secs >= 0) and disables
// direct file-write. disc/track 0 = unset sentinel (Option<u32>).
export struct TagTrackEdit {
id: int,
file_path: string,
cue_file_path: string,
cue_start_secs: float,
has_cue: bool,
title: string,
disc_number: string, // raw text (LineEdit); controller parses on save ("" = unset)
track_number: string, // raw text (LineEdit); controller parses on save ("" = unset)
}
export global TagEditorState {
in-out property <bool> open: false;
in property <string> album_group_key; // == LocalAlbum.id == directory_path
in-out property <string> album_title;
in-out property <string> album_artist;
in-out property <string> year_input; // raw text; controller parses
in-out property <string> genre;
in-out property <string> catalog_number;
in-out property <int> album_total_discs; // collected, NOT persisted (1:1)
in property <string> directory_path; // reference + is_dir gate
in property <bool> can_direct_write; // false if any track has_cue
in-out property <int> persistence_index: 0; // 0 = sidecar, 1 = direct
in-out property <[TagTrackEdit]> tracks: [];
in-out property <bool> saving: false;
in-out property <int> write_progress_current: 0;
in-out property <int> write_progress_total: 0;
}
export global TagEditorActions {
callback close();
callback save();
callback set-persistence(int); // QbzSelect index -> mode (controller maps)
}
// Global toast state, driven by crate::toast. The Toast overlay (mounted
// at the app root) renders whatever is here. The Rust layer owns timing
// (show + auto-hide); the UI only sets `visible = false` on the close