From 30bd959bf76ddb05fc9426128e90f6dccad62228 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 15 Jun 2026 19:19:21 -0600 Subject: [PATCH] feat(album): multi-disc "Disc N" headers with per-disc context menu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Album and local-album track lists render a "Disc N" header above the first track of each disc when the album spans more than one disc (media_number-driven; single-disc albums render flat), matching Tauri. Each header carries a context menu (new — Tauri has none) with Play all / Shuffle / Add to queue / Play next scoped to that disc's tracks only; the whole-album header buttons are unchanged. The menu lives in a DiscHeaderMenu wrapper because Slint rejects a PopupWindow placed directly under a for/if delegate — wrapping it makes the popup a non-root child (same pattern as TrackRow + TrackContextMenu). Every TrackItem constructor gains disc-header-number: 0; artist top-tracks (a flat cross-album list) default the disc to 1. cc --- crates/qbz-slint/src/album.rs | 56 +++++++- crates/qbz-slint/src/artist.rs | 5 + crates/qbz-slint/src/favorites.rs | 2 + crates/qbz-slint/src/label.rs | 8 ++ crates/qbz-slint/src/local_library.rs | 55 +++++++- crates/qbz-slint/src/local_playlist.rs | 8 ++ crates/qbz-slint/src/main.rs | 125 ++++++++++++++++++ crates/qbz-slint/src/mix.rs | 2 + crates/qbz-slint/src/myqbz_detail.rs | 2 + crates/qbz-slint/src/playlist.rs | 2 + crates/qbz-slint/src/search.rs | 8 ++ crates/qbz-slint/ui/album/AlbumPageView.slint | 70 ++++++++-- .../qbz-slint/ui/album/LocalAlbumView.slint | 82 +++++++++--- .../ui/primitives/DiscContextMenu.slint | 59 +++++++++ .../ui/primitives/DiscHeaderMenu.slint | 46 +++++++ crates/qbz-slint/ui/state.slint | 16 +++ 16 files changed, 506 insertions(+), 40 deletions(-) create mode 100644 crates/qbz-slint/ui/primitives/DiscContextMenu.slint create mode 100644 crates/qbz-slint/ui/primitives/DiscHeaderMenu.slint diff --git a/crates/qbz-slint/src/album.rs b/crates/qbz-slint/src/album.rs index 947bf04a2..afb89d824 100644 --- a/crates/qbz-slint/src/album.rs +++ b/crates/qbz-slint/src/album.rs @@ -80,6 +80,10 @@ pub struct TrackData { pub quality_tier: String, pub quality_detail: String, pub explicit: bool, + /// Disc/media number (Qobuz `media_number`, defaulting to 1 when absent). + /// Used after mapping to decide where the "Disc N" headers fall when the + /// album spans more than one disc. + pub disc: u32, } /// Fetch and map a full album by id. @@ -260,6 +264,8 @@ fn map_track(track: Track) -> TrackData { track.maximum_sampling_rate, ), explicit: track.parental_warning, + // Tauri: `disc = track.media_number ?? 1`. + disc: track.media_number.unwrap_or(1), } } @@ -294,10 +300,41 @@ pub fn apply_album(window: &AppWindow, data: AlbumData) { // album link target is this album's own id (the album column is not // shown here, but album-id keeps the row model complete). let album_id: slint::SharedString = data.id.clone().into(); + // Multi-disc grouping (Tauri PurchaseAlbumDetailView: groupByDisc + + // isMultiDisc). The album is "multi-disc" when its tracks span more than + // one distinct disc number; only then do we emit "Disc N" headers. The + // header is stamped on the first track of each disc run, and tracks stay + // in their delivered order (Qobuz returns them disc-then-track ordered). + let is_multi_disc = { + let mut seen: Option = None; + let mut multi = false; + for track in &data.tracks { + match seen { + Some(d) if d != track.disc => { + multi = true; + break; + } + _ => seen = Some(track.disc), + } + } + multi + }; + let mut prev_disc: Option = None; let tracks: Vec = data .tracks .into_iter() - .map(|track| TrackItem { + .map(|track| { + // Stamp the disc number on the first row of each disc run, but + // only for multi-disc albums (single-disc renders flat → 0). The + // delegate renders `@tr("Disc") ` above the row when this is + // > 0, matching the Tauri `{$t('album.disc')} {discNum}` markup. + let disc_header_number = if is_multi_disc && prev_disc != Some(track.disc) { + track.disc as i32 + } else { + 0 + }; + prev_disc = Some(track.disc); + TrackItem { id: track.id.clone().into(), number: track.number.into(), title: track.title.into(), @@ -319,6 +356,8 @@ pub fn apply_album(window: &AppWindow, data: AlbumData) { // Qobuz album-detail rows; local albums override via map_local_track. source: "qobuz".into(), unlocking: false, + disc_header_number, + } }) .collect(); @@ -489,6 +528,21 @@ pub fn selected_play_tracks(window: &AppWindow) -> Vec { }) } +/// The full catalog Track objects for one disc of the open album (for the +/// per-disc "Disc N" header menu), resolved from the stashed raw album tracks. +/// `disc` matches `media_number` (defaulting to 1, exactly as `map_track` +/// stamps `TrackData.disc`), so it lines up with the rendered "Disc N" header. +/// Preserves the delivered (disc-then-track) order. +pub fn disc_play_tracks(disc: i32) -> Vec { + PLAY_TRACKS.with(|cell| { + cell.borrow() + .iter() + .filter(|t| t.media_number.unwrap_or(1) as i32 == disc) + .cloned() + .collect() + }) +} + /// Apply decoded header artwork pixels. Runs on the Slint event loop. pub fn apply_artwork(window: &AppWindow, pixels: &[u8], width: u32, height: u32) { let mut buffer = slint::SharedPixelBuffer::::new(width, height); diff --git a/crates/qbz-slint/src/artist.rs b/crates/qbz-slint/src/artist.rs index 18a59f171..63a2374fa 100644 --- a/crates/qbz-slint/src/artist.rs +++ b/crates/qbz-slint/src/artist.rs @@ -376,6 +376,9 @@ fn map_track(index: usize, track: PageArtistTrack) -> TrackData { quality_tier: tier(bit_depth).to_string(), quality_detail: crate::quality::detail(bit_depth, sample_rate), explicit: track.parental_warning.unwrap_or(false), + // Artist top-tracks are a flat cross-album list and never render + // "Disc N" headers, so the disc value is unused here — default to 1. + disc: 1, } } @@ -511,6 +514,8 @@ pub fn apply_artist(window: &AppWindow, data: ArtistData) { cache_progress: 0.0, source: "qobuz".into(), unlocking: false, + // Disc grouping is album-detail only; flat lists carry none. + disc_header_number: 0, }) .collect(); let release_sections: Vec = data diff --git a/crates/qbz-slint/src/favorites.rs b/crates/qbz-slint/src/favorites.rs index 72abfe650..dba057ae7 100644 --- a/crates/qbz-slint/src/favorites.rs +++ b/crates/qbz-slint/src/favorites.rs @@ -486,6 +486,8 @@ pub fn apply_favorites(window: &AppWindow, data: FavData) { cache_progress: 0.0, source: "qobuz".into(), unlocking: false, + // Disc grouping is album-detail only; flat lists carry none. + disc_header_number: 0, }) .collect(); // `tracks` is the full set the artwork pipeline targets; diff --git a/crates/qbz-slint/src/label.rs b/crates/qbz-slint/src/label.rs index be8f48ace..21d09b5ea 100644 --- a/crates/qbz-slint/src/label.rs +++ b/crates/qbz-slint/src/label.rs @@ -776,6 +776,8 @@ fn top_track_to_item(t: &TopTrack) -> TrackItem { cache_progress: 0.0, source: "qobuz".into(), unlocking: false, + // Disc grouping is album-detail only; flat lists carry none. + disc_header_number: 0, } } @@ -793,6 +795,12 @@ fn playlist_to_item(p: &PlaylistSlim) -> SearchPlaylistItem { cover2: slint::Image::default(), cover3: slint::Image::default(), cover4: slint::Image::default(), + // Label-landing playlist cards carry no category subtag, and a + // transparent dominant-colour is the sentinel for "no letterbox": + // the collage keeps the legacy cover-fit (the contain + dominant- + // colour treatment is Discover-only). + category: "".into(), + dominant_color: slint::Color::from_argb_u8(0, 0, 0, 0), } } diff --git a/crates/qbz-slint/src/local_library.rs b/crates/qbz-slint/src/local_library.rs index 671a853d7..f4fa0fe1c 100644 --- a/crates/qbz-slint/src/local_library.rs +++ b/crates/qbz-slint/src/local_library.rs @@ -783,6 +783,10 @@ fn map_local_track(t: qbz_library::LocalTrack) -> TrackItem { } .into(), unlocking: false, + // Default: no disc header. The flat Library Tracks tab never groups by + // disc; the local-album DETAIL view stamps this afterwards (see + // apply_album_version) for multi-disc local albums. + disc_header_number: 0, } } @@ -1336,17 +1340,48 @@ pub fn apply_album_version(window: &AppWindow, index: i32) { // Client-side filter (Qobuz album view parity): match title/artist; the // header badge/info stay album-level (computed from the full version above). let q = album_query().to_lowercase(); - let items: Vec = tracks + let shown: Vec<&qbz_library::LocalTrack> = tracks .iter() .filter(|t| { q.is_empty() || t.title.to_lowercase().contains(&q) || t.artist.to_lowercase().contains(&q) }) - .cloned() + .collect(); + // Multi-disc grouping (mirrors the Qobuz album view): the album is + // multi-disc when its shown tracks span more than one distinct disc + // number, and only then do we stamp "Disc N" headers on the first row of + // each disc run. Local tracks are already disc-then-track sorted upstream + // (album_versions sorts by (disc_number, track_number)). + let is_multi_disc = { + let mut seen: Option = None; + let mut multi = false; + for t in &shown { + let disc = t.disc_number.unwrap_or(1); + match seen { + Some(d) if d != disc => { + multi = true; + break; + } + _ => seen = Some(disc), + } + } + multi + }; + let mut prev_disc: Option = None; + let items: Vec = shown + .into_iter() .map(|t| { - let mut it = map_local_track(t); + let disc = t.disc_number.unwrap_or(1); + let disc_header_number = if is_multi_disc && prev_disc != Some(disc) { + disc as i32 + } else { + 0 + }; + prev_disc = Some(disc); + let mut it = map_local_track(t.clone()); it.album_id = group_key.clone().into(); + it.disc_header_number = disc_header_number; it }) .collect(); @@ -1676,6 +1711,20 @@ pub fn current_album_version_tracks(window: &AppWindow) -> Vec Vec { + current_album_version_tracks(window) + .into_iter() + .filter(|t| t.disc_number.unwrap_or(1) as i32 == disc) + .collect() +} + // ============================ Folders (flat) ============================== // // The Folders tab (flat mode) is the album grid grouped by directory rather diff --git a/crates/qbz-slint/src/local_playlist.rs b/crates/qbz-slint/src/local_playlist.rs index a0191987e..c14a7731b 100644 --- a/crates/qbz-slint/src/local_playlist.rs +++ b/crates/qbz-slint/src/local_playlist.rs @@ -885,6 +885,8 @@ fn row_item(item: &RowItem, queue: Option<&QueueTrack>) -> TrackItem { cache_progress: 0.0, source: "qobuz".into(), unlocking: false, + // Disc grouping is album-detail only; playlist rows carry none. + disc_header_number: 0, }, RowItem::Local(track) | RowItem::Plex(track) => { let (tier, quality_detail, _) = crate::quality::badge( @@ -924,6 +926,8 @@ fn row_item(item: &RowItem, queue: Option<&QueueTrack>) -> TrackItem { } .into(), unlocking: false, + // Disc grouping is album-detail only; playlist rows carry none. + disc_header_number: 0, } } RowItem::LocalFile { path } => { @@ -952,6 +956,8 @@ fn row_item(item: &RowItem, queue: Option<&QueueTrack>) -> TrackItem { cache_progress: 0.0, source: "local".into(), unlocking: false, + // Disc grouping is album-detail only; playlist rows carry none. + disc_header_number: 0, } } // Honest unavailable row: distinct title + the raw stored ref in @@ -991,6 +997,8 @@ fn row_item(item: &RowItem, queue: Option<&QueueTrack>) -> TrackItem { cache_progress: 0.0, source: if *kind == "plex" { "plex" } else { "" }.into(), unlocking: false, + // Disc grouping is album-detail only; playlist rows carry none. + disc_header_number: 0, }, } } diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index c62efed9f..fddf3b3dd 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -6916,6 +6916,79 @@ fn main() -> Result<(), Box> { }); } + // Per-disc "Disc N" header ⋯ menu (Qobuz album) — each action is scoped to + // that disc's tracks only, resolved from the album's stashed raw catalog + // tracks. Reuses the SAME queue ops as the album-header buttons (play_tracks + // / play_album_shuffled's xorshift / enqueue_tracks), just over the disc + // subset rather than the whole album. + { + let runtime = app_runtime.clone(); + let weak = window.as_weak(); + let handle = tokio_rt.handle().clone(); + window + .global::() + .on_disc_action(move |disc, action| { + let mut tracks = album::disc_play_tracks(disc); + if tracks.is_empty() { + return; + } + match action.as_str() { + "play" => { + playback::play_tracks( + runtime.clone(), + weak.clone(), + handle.clone(), + tracks, + 0, + ); + } + "shuffle" => { + // Same SystemTime-seeded xorshift Fisher-Yates as the + // album-header Shuffle (playback::play_album_shuffled), + // applied to the disc subset before play_tracks. + let mut seed = std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map(|d| d.as_nanos() as u64) + .unwrap_or(1) + | 1; + for i in (1..tracks.len()).rev() { + seed ^= seed << 13; + seed ^= seed >> 7; + seed ^= seed << 17; + let j = (seed % (i as u64 + 1)) as usize; + tracks.swap(i, j); + } + playback::play_tracks( + runtime.clone(), + weak.clone(), + handle.clone(), + tracks, + 0, + ); + } + "queue" => { + playback::enqueue_tracks( + runtime.clone(), + handle.clone(), + tracks, + false, + ); + } + "play-next" => { + playback::enqueue_tracks( + runtime.clone(), + handle.clone(), + tracks, + true, + ); + } + other => { + log::warn!("[qbz-slint] album disc-action: unknown action {other}"); + } + } + }); + } + // Artist in-page search — client-side filter over Popular Tracks // and every release-section album. { @@ -8885,6 +8958,58 @@ fn main() -> Result<(), Box> { local_library::search_album(weak.clone(), q.to_string()); }); } + { + // Per-disc "Disc N" header ⋯ menu (local album) — scoped to that disc's + // tracks only, resolved from the open version's track cache. Reuses the + // SAME local queue ops as the header play-all / shuffle buttons + // (play_local_tracks, shuffle flag) and the per-row menu's + // enqueue_local_tracks, just over the disc subset. + let runtime = app_runtime.clone(); + let weak = window.as_weak(); + let handle = tokio_rt.handle().clone(); + window + .global::() + .on_disc_action(move |disc, action| { + let Some(w) = weak.upgrade() else { return }; + let tracks = local_library::current_album_disc_tracks(&w, disc); + if tracks.is_empty() { + return; + } + match action.as_str() { + "play" => playback::play_local_tracks( + runtime.clone(), + weak.clone(), + handle.clone(), + tracks, + 0, + false, + ), + "shuffle" => playback::play_local_tracks( + runtime.clone(), + weak.clone(), + handle.clone(), + tracks, + 0, + true, + ), + "queue" => playback::enqueue_local_tracks( + runtime.clone(), + handle.clone(), + tracks, + false, + ), + "play-next" => playback::enqueue_local_tracks( + runtime.clone(), + handle.clone(), + tracks, + true, + ), + other => { + log::warn!("[qbz-slint] local disc-action: unknown action {other}"); + } + } + }); + } // Local Library — Albums tab controls (search / sort re-query page 1; // load-more pages on scroll; retry) + the shared AlbumCollectionView's diff --git a/crates/qbz-slint/src/mix.rs b/crates/qbz-slint/src/mix.rs index 5e064adb8..4a75261b0 100644 --- a/crates/qbz-slint/src/mix.rs +++ b/crates/qbz-slint/src/mix.rs @@ -295,6 +295,8 @@ fn to_item(track: &Track) -> TrackItem { cache_progress: 0.0, source: "qobuz".into(), unlocking: false, + // Disc grouping is album-detail only; flat lists carry none. + disc_header_number: 0, } } diff --git a/crates/qbz-slint/src/myqbz_detail.rs b/crates/qbz-slint/src/myqbz_detail.rs index 42adbda74..4fd5f8aa1 100644 --- a/crates/qbz-slint/src/myqbz_detail.rs +++ b/crates/qbz-slint/src/myqbz_detail.rs @@ -706,6 +706,8 @@ fn track_to_item(track: &qbz_models::QueueTrack, resolver_index: usize) -> Track cache_status: 0, cache_progress: 0.0, unlocking: false, + // Disc grouping is album-detail only; flat lists carry no header. + disc_header_number: 0, } } diff --git a/crates/qbz-slint/src/playlist.rs b/crates/qbz-slint/src/playlist.rs index 3ef121e8c..09c5b5b08 100644 --- a/crates/qbz-slint/src/playlist.rs +++ b/crates/qbz-slint/src/playlist.rs @@ -550,6 +550,8 @@ pub(crate) fn to_item(track: &Track) -> TrackItem { cache_progress: 0.0, source: "qobuz".into(), unlocking: false, + // Disc grouping is album-detail only; flat lists carry none. + disc_header_number: 0, } } diff --git a/crates/qbz-slint/src/search.rs b/crates/qbz-slint/src/search.rs index be385ea13..e28b6bb35 100644 --- a/crates/qbz-slint/src/search.rs +++ b/crates/qbz-slint/src/search.rs @@ -385,6 +385,8 @@ fn track_item(row: TrackRowData) -> TrackItem { cache_progress: 0.0, source: "qobuz".into(), unlocking: false, + // Disc grouping is album-detail only; flat lists carry none. + disc_header_number: 0, } } @@ -417,6 +419,12 @@ pub(crate) fn playlist_item(row: PlaylistRow) -> SearchPlaylistItem { cover2: slint::Image::default(), cover3: slint::Image::default(), cover4: slint::Image::default(), + // Search playlist results carry no category subtag, and a transparent + // dominant-colour is the sentinel for "no letterbox" — the collage + // keeps the legacy cover-fit (contain + dominant colour is Discover- + // only). + category: "".into(), + dominant_color: slint::Color::from_argb_u8(0, 0, 0, 0), } } diff --git a/crates/qbz-slint/ui/album/AlbumPageView.slint b/crates/qbz-slint/ui/album/AlbumPageView.slint index a9224f755..d11c69e4b 100644 --- a/crates/qbz-slint/ui/album/AlbumPageView.slint +++ b/crates/qbz-slint/ui/album/AlbumPageView.slint @@ -18,6 +18,7 @@ import { QualityBadgeFull } from "../primitives/QualityBadgeFull.slint"; import { TrackPlayCell } from "../primitives/TrackPlayCell.slint"; import { TrackContextMenu } from "../primitives/TrackContextMenu.slint"; import { AlbumContextMenu } from "../primitives/AlbumContextMenu.slint"; +import { DiscHeaderMenu } from "../primitives/DiscHeaderMenu.slint"; import { LoadingSpinner } from "../primitives/LoadingSpinner.slint"; import { ListScrollbar } from "../primitives/ListScrollbar.slint"; import { CircleAction } from "../primitives/CircleAction.slint"; @@ -721,20 +722,61 @@ export component AlbumPageView inherits Rectangle { Rectangle { width: 32px; } } - for track[index] in AlbumState.tracks: TrackRow { - track: track; - index: index; - // Number cell (no cover). Qobuz albums carry the - // favorite heart (matching the column header) + the - // offline-cache button; local albums show the source - // indicator instead. - show-artwork: false; - show-favorite: !AlbumState.is-local; - show-download: !AlbumState.is-local; - show-source: AlbumState.is-local; - multi-select-mode: AlbumState.multi-select; - media-action(kind, id, action) => { - root.media-action(kind, id, action); + // Each iteration is a thin column wrapper so a "Disc N" + // divider can precede the row when the model marks it as + // the first track of a disc (multi-disc albums only; on a + // single-disc album disc-header-number is always 0, so the + // header `if` never renders and the list stays flat — + // unchanged from before). Mirrors the Tauri + // PurchaseAlbumDetailView groupByDisc + isMultiDisc markup. + for track[index] in AlbumState.tracks: VerticalLayout { + spacing: 0px; + if track.disc-header-number > 0: Rectangle { + height: 40px; + HorizontalLayout { + padding-left: 12px; + padding-right: 12px; + spacing: 16px; + Text { + text: @tr("Disc") + " \{track.disc-header-number}"; + color: Theme.text-muted; + font-size: Typography.legal; + font-weight: 600; + letter-spacing: 0.5px; + vertical-alignment: center; + horizontal-alignment: left; + horizontal-stretch: 1; + } + // Per-disc ⋯ menu — actions scoped to this + // disc's tracks only (the column header reserves + // a 32px more-button slot on the right; this + // aligns with it). + VerticalLayout { + alignment: center; + DiscHeaderMenu { + disc: track.disc-header-number; + disc-action(d, a) => { + AlbumActions.disc-action(d, a); + } + } + } + } + } + TrackRow { + track: track; + index: index; + // Number cell (no cover). Qobuz albums carry the + // favorite heart (matching the column header) + the + // offline-cache button; local albums show the source + // indicator instead. + show-artwork: false; + show-favorite: !AlbumState.is-local; + show-download: !AlbumState.is-local; + show-source: AlbumState.is-local; + multi-select-mode: AlbumState.multi-select; + media-action(kind, id, action) => { + root.media-action(kind, id, action); + } } } } diff --git a/crates/qbz-slint/ui/album/LocalAlbumView.slint b/crates/qbz-slint/ui/album/LocalAlbumView.slint index a1f53c122..b094abbe6 100644 --- a/crates/qbz-slint/ui/album/LocalAlbumView.slint +++ b/crates/qbz-slint/ui/album/LocalAlbumView.slint @@ -15,6 +15,7 @@ import { TrackRow } from "../primitives/TrackRow.slint"; import { ListScrollbar } from "../primitives/ListScrollbar.slint"; import { QualityBadgeFull } from "../primitives/QualityBadgeFull.slint"; import { LoadingSpinner } from "../primitives/LoadingSpinner.slint"; +import { DiscHeaderMenu } from "../primitives/DiscHeaderMenu.slint"; import { ListView } from "std-widgets.slint"; // Source glyph for a version: hard-drive (local), Qobuz logo (offline cache), @@ -475,28 +476,65 @@ export component LocalAlbumView inherits Rectangle { Rectangle { width: 32px; } } - for track[index] in LocalAlbumState.tracks: TrackRow { - track: track; - index: index; - show-artwork: false; - show-album: false; - show-favorite: false; - show-download: false; - // Show the per-row source glyph (local / qobuz-offline / Plex). - show-source: true; - // Library surface: local menu even for qobuz_download - // rows (spec §3.4). - force-local-menu: true; - media-action(kind, id, action) => { - // Local-only: ignore album/artist link clicks. "play" - // (row body / play cell) plays; the context-menu - // actions (play-next / queue / add-to-playlist) route - // to their own handler instead of collapsing to play. - if (kind != "album" && kind != "artist") { - if (action == "play") { - LocalAlbumActions.play-track(id); - } else { - LocalAlbumActions.track-menu-action(id, action); + // Disc divider before the first row of each disc on a + // multi-disc local album (disc-header-number is stamped in + // apply_album_version; 0 for single-disc → flat list, as + // before). Same pattern as the Qobuz AlbumPageView. + for track[index] in LocalAlbumState.tracks: VerticalLayout { + spacing: 0px; + if track.disc-header-number > 0: Rectangle { + height: 40px; + HorizontalLayout { + padding-left: 12px; + padding-right: 12px; + spacing: 16px; + Text { + text: @tr("Disc") + " \{track.disc-header-number}"; + color: Theme.text-muted; + font-size: Typography.legal; + font-weight: 600; + letter-spacing: 0.5px; + vertical-alignment: center; + horizontal-alignment: left; + horizontal-stretch: 1; + } + // Per-disc ⋯ menu — actions scoped to this disc's + // tracks only (aligns with the column header's 32px + // right-edge more-button slot). + VerticalLayout { + alignment: center; + DiscHeaderMenu { + disc: track.disc-header-number; + disc-action(d, a) => { + LocalAlbumActions.disc-action(d, a); + } + } + } + } + } + TrackRow { + track: track; + index: index; + show-artwork: false; + show-album: false; + show-favorite: false; + show-download: false; + // Show the per-row source glyph (local / qobuz-offline / Plex). + show-source: true; + // Library surface: local menu even for qobuz_download + // rows (spec §3.4). + force-local-menu: true; + media-action(kind, id, action) => { + // Local-only: ignore album/artist link clicks. "play" + // (row body / play cell) plays; the context-menu + // actions (play-next / queue / add-to-playlist) route + // to their own handler instead of collapsing to play. + if (kind != "album" && kind != "artist") { + if (action == "play") { + LocalAlbumActions.play-track(id); + } else { + LocalAlbumActions.track-menu-action(id, action); + } } } } diff --git a/crates/qbz-slint/ui/primitives/DiscContextMenu.slint b/crates/qbz-slint/ui/primitives/DiscContextMenu.slint new file mode 100644 index 000000000..ef4ff3372 --- /dev/null +++ b/crates/qbz-slint/ui/primitives/DiscContextMenu.slint @@ -0,0 +1,59 @@ +// Per-disc "more" (⋯) context menu — opened from a "Disc N" separator in the +// album track list (Qobuz AlbumPageView + LocalAlbumView). NEW feature: Tauri +// has no per-disc menu. Each action is scoped to that disc's tracks only; the +// whole-album header buttons keep their own behavior. +// +// Mirrors AlbumContextMenu's structure (a PopupWindow hosting a ContextMenu + +// ContextMenuItem rows) so it reads like every other ⋯ menu. The `disc` +// property identifies which disc the four actions operate on. +// +// Play all -> disc-action(disc, "play") +// Shuffle -> disc-action(disc, "shuffle") +// -- +// Add to queue -> disc-action(disc, "queue") +// Play next -> disc-action(disc, "play-next") + +import { Theme } from "../foundation/semantic-colors.slint"; +import { ContextMenu } from "ContextMenu.slint"; +import { ContextMenuItem } from "ContextMenuItem.slint"; + +export component DiscContextMenu inherits PopupWindow { + in property disc; + callback disc-action(int, string); + + width: 200px; + // 4 rows x 33px + 1 separator x 1px + ContextMenu's 5/5 padding. + height: 4 * 33px + 1 * 1px + 10px; + + ContextMenu { + ContextMenuItem { + icon: @image-url("../assets/icons/play-fill.svg"); + label: @tr("Play all"); + clicked => { + root.disc-action(root.disc, "play"); + } + } + ContextMenuItem { + icon: @image-url("../assets/icons/shuffle.svg"); + label: @tr("Shuffle"); + clicked => { + root.disc-action(root.disc, "shuffle"); + } + } + Rectangle { height: 1px; background: Theme.border-subtle; } + ContextMenuItem { + icon: @image-url("../assets/icons/list-end.svg"); + label: @tr("Add to queue"); + clicked => { + root.disc-action(root.disc, "queue"); + } + } + ContextMenuItem { + icon: @image-url("../assets/icons/list-plus.svg"); + label: @tr("Play next"); + clicked => { + root.disc-action(root.disc, "play-next"); + } + } + } +} diff --git a/crates/qbz-slint/ui/primitives/DiscHeaderMenu.slint b/crates/qbz-slint/ui/primitives/DiscHeaderMenu.slint new file mode 100644 index 000000000..19061d7c9 --- /dev/null +++ b/crates/qbz-slint/ui/primitives/DiscHeaderMenu.slint @@ -0,0 +1,46 @@ +// Per-disc ⋯ trigger + context menu for the album track-list disc headers. +// +// WHY a component: Slint rejects a `PopupWindow` placed DIRECTLY under a +// `for`/`if` ("PopupWindow cannot be directly repeated or conditional" — +// the popup becomes the conditional/repeated root). Wrapping the trigger + +// `DiscContextMenu` here makes the PopupWindow a NON-root child of this +// component's Rectangle root, so mounting `DiscHeaderMenu` inside the disc +// header's `if` is fine (same shape as TrackRow embedding TrackContextMenu). + +import { Theme } from "../foundation/semantic-colors.slint"; +import { QbzIcon } from "QbzIcon.slint"; +import { DiscContextMenu } from "DiscContextMenu.slint"; + +export component DiscHeaderMenu inherits Rectangle { + in property disc; + // (disc, action) — action: "play" | "shuffle" | "queue" | "play-next". + callback disc-action(int, string); + + width: 32px; + height: 32px; + + more-ta := TouchArea { + mouse-cursor: pointer; + clicked => { + menu.show(); + } + QbzIcon { + source: @image-url("../assets/icons/ellipsis.svg"); + width: 16px; + height: 16px; + x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; + y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; + tint: more-ta.has-hover ? Theme.text-primary : Theme.text-muted; + } + } + + // Opens just below the ⋯, right edges aligned (opens leftward). + menu := DiscContextMenu { + x: 32px - self.width; + y: 36px; + disc: root.disc; + disc-action(d, a) => { + root.disc-action(d, a); + } + } +} diff --git a/crates/qbz-slint/ui/state.slint b/crates/qbz-slint/ui/state.slint index 7111ab226..189522788 100644 --- a/crates/qbz-slint/ui/state.slint +++ b/crates/qbz-slint/ui/state.slint @@ -368,6 +368,14 @@ export struct TrackItem { // True while this track's offline CMAF bundle is being decrypted for // playback — drives the padlock glyph (swaps the play/equalizer icon). unlocking: bool, + // Multi-disc grouping: the disc number whose "Disc N" header should be + // rendered ABOVE this row. Set (> 0) only on the first track of each + // disc, and only when the album spans more than one disc; 0 otherwise + // (single-disc albums and every non-leading track render flat, with no + // header). The "Disc" word is translated in the delegate via @tr so it + // flows through the gettext pipeline, matching the Tauri markup + // `{$t('album.disc')} {discNum}` (groupByDisc + isMultiDisc). + disc-header-number: int, } // Album detail screen state. @@ -552,6 +560,10 @@ export global AlbumActions { // | "queue" | "add-to-playlist" | "add-to-favorites" | "make-offline" | // "clear"). callback bulk-action(string); + // Per-disc context-menu action on a multi-disc album's "Disc N" header — + // scoped to that disc's tracks only (action = "play" | "shuffle" | "queue" + // | "play-next"). The whole-album header buttons are unaffected. + callback disc-action(int /* disc number */, string /* action */); } // Track drag-and-drop onto sidebar playlists (a star QBZ feature). @@ -942,6 +954,10 @@ export global LocalAlbumActions { // Client-side track filter (mirrors AlbumActions.search), applied over the // current version's tracks. callback search(string /* query */); + // Per-disc context-menu action on a multi-disc local album's "Disc N" + // header — scoped to that disc's tracks only (action = "play" | "shuffle" | + // "queue" | "play-next"). The whole-album header buttons are unaffected. + callback disc-action(int /* disc number */, string /* action */); } // ============================ Local Library management ====================