From acfd3d928d6080cf3495e909a9042049421404bf Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Mon, 29 Jun 2026 14:53:31 -0600 Subject: [PATCH] feat(slint): keyboard multi-select on the built-out surfaces (Mix, Label, LocalLibrary Albums) Extend the keyboard multi-select feature to the surfaces that had no working selection in the Slint port. - Mix (DailyQ/WeeklyQ/FavQ/TopQ all render through one MixView): mode toggle + MultiSelectBar, per-row checkbox via the central toggle arm + a ContentView::Mix branch (model + recount), bulk play-next/queue/ add-to-playlist. Shift-range, Ctrl+A and Escape inherited automatically. - Label Popular Tracks: was a dead stub (checkboxes with no bar/recount/ router arms). Converted the local mode flag to LabelState.multi-select, added a real MultiSelectBar + label.rs recount/select_all/clear/selected, and the missing select-toggle/bulk router arms. - LocalLibrary Albums grid (a previously-missing surface): AlbumCardItem gains a `selected` field; a `select-mode` prop is threaded through the shared AlbumCard / AlbumListRow / AlbumGrid / AlbumCollectionView (default false, so Discover/Label/Favorites are untouched). Albums toolbar toggle + MultiSelectBar; local_library.rs album select fns (flat + grouped, id-resilient Shift-range over AlbumCardItem); album->tracks bulk resolve via fetch_album_tracks_blocking on spawn_blocking for queue/play-next/ add-to-playlist/add-to-mixtape; Ctrl+A and Escape routed by active-tab. cargo check -p qbz green (qbz_ui compiles clean). cc --- crates/qbz-ui/ui/discover/AlbumCard.slint | 37 ++- .../ui/discover/AlbumCollectionView.slint | 9 + crates/qbz-ui/ui/label/LabelPageView.slint | 65 ++--- .../ui/locallibrary/LocalLibraryView.slint | 27 ++ crates/qbz-ui/ui/mix/MixView.slint | 38 ++- .../qbz-ui/ui/primitives/AlbumListRow.slint | 39 ++- crates/qbz-ui/ui/state.slint | 20 +- crates/qbz/src/home.rs | 1 + crates/qbz/src/label.rs | 81 ++++++ crates/qbz/src/local_library.rs | 197 ++++++++++++++ crates/qbz/src/main.rs | 240 +++++++++++++++++- crates/qbz/src/mix.rs | 85 ++++++- crates/qbz/src/selection.rs | 2 + 13 files changed, 783 insertions(+), 58 deletions(-) diff --git a/crates/qbz-ui/ui/discover/AlbumCard.slint b/crates/qbz-ui/ui/discover/AlbumCard.slint index 2681b1f2c..f79bf00e9 100644 --- a/crates/qbz-ui/ui/discover/AlbumCard.slint +++ b/crates/qbz-ui/ui/discover/AlbumCard.slint @@ -77,6 +77,10 @@ export component AlbumCard inherits Rectangle { // Always-visible source badge on the artwork (Local Library: local | // qobuz-offline | plex). Off elsewhere (single-source catalogs). in property show-source-badge: false; + // Multi-select mode (Local Library albums): a checkbox overlay replaces the + // hover action buttons, and the card click toggles selection instead of + // opening. Default false → every other AlbumCard consumer is untouched. + in property select-mode: false; // Fade out when the card is being removed (favorites un-favorite). opacity: root.album.removing ? 0.0 : 1.0; animate opacity { duration: 250ms; } @@ -161,12 +165,41 @@ export component AlbumCard inherits Rectangle { height: 100%; mouse-cursor: pointer; clicked => { - root.clicked(root.album.id); + if (root.select-mode) { + root.media-action("album", root.album.id, "toggle-select"); + } else { + root.clicked(root.album.id); + } } } - // Hover action buttons — favorite / play / more. + // Multi-select checkbox — top-right of the art, shown only in + // select-mode (the card click toggles; this is the indicator). + if root.select-mode: Rectangle { + x: parent.width - self.width - 8px; + y: 8px; + width: 24px; + height: 24px; + border-radius: 12px; + background: root.album.selected ? Theme.accent : #00000099; + border-width: 1.5px; + border-color: root.album.selected ? Theme.accent : #ffffffcc; + animate background { duration: 120ms; } + QbzIcon { + source: @image-url("../assets/icons/check.svg"); + visible: root.album.selected; + width: 14px; + height: 14px; + x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; + y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; + tint: #ffffff; + } + } + + // Hover action buttons — favorite / play / more. Hidden in + // select-mode (the click toggles selection instead). HorizontalLayout { + visible: !root.select-mode; x: 0px; y: 120px; width: 200px; diff --git a/crates/qbz-ui/ui/discover/AlbumCollectionView.slint b/crates/qbz-ui/ui/discover/AlbumCollectionView.slint index 08dc01db0..b488de3fc 100644 --- a/crates/qbz-ui/ui/discover/AlbumCollectionView.slint +++ b/crates/qbz-ui/ui/discover/AlbumCollectionView.slint @@ -20,6 +20,7 @@ component AlbumGrid inherits Rectangle { in property card-gap: 24px; in property show-favorite: true; in property show-source-badge: false; + in property select-mode: false; callback open-album(string); callback open-artist(string); callback media-action(string, string, string); @@ -40,6 +41,7 @@ component AlbumGrid inherits Rectangle { album: album; show-favorite: root.show-favorite; show-source-badge: root.show-source-badge; + select-mode: root.select-mode; clicked(id) => { root.open-album(id); } @@ -65,6 +67,9 @@ export component AlbumCollectionView inherits VerticalLayout { // Forwarded to AlbumCard — show the always-visible source badge on the // grid card art (Local Library: local | qobuz-offline | plex). in property show-source-badge: false; + // Forwarded to AlbumCard / AlbumListRow — checkbox + toggle-on-click + // (Local Library albums multi-select). Default false everywhere else. + in property select-mode: false; in property card-width: 200px; in property card-height: 246px; in property card-gap: 24px; @@ -98,6 +103,7 @@ export component AlbumCollectionView inherits VerticalLayout { album: album; index: i; show-source: root.show-source; + select-mode: root.select-mode; clicked(id) => { root.open-album(id); } @@ -115,6 +121,7 @@ export component AlbumCollectionView inherits VerticalLayout { albums: section.albums; show-favorite: root.show-favorite; show-source-badge: root.show-source-badge; + select-mode: root.select-mode; card-width: root.card-width; card-height: root.card-height; card-gap: root.card-gap; @@ -136,6 +143,7 @@ export component AlbumCollectionView inherits VerticalLayout { albums: root.albums; show-favorite: root.show-favorite; show-source-badge: root.show-source-badge; + select-mode: root.select-mode; card-width: root.card-width; card-height: root.card-height; card-gap: root.card-gap; @@ -160,6 +168,7 @@ export component AlbumCollectionView inherits VerticalLayout { album: album; index: i; show-source: root.show-source; + select-mode: root.select-mode; clicked(id) => { root.open-album(id); } diff --git a/crates/qbz-ui/ui/label/LabelPageView.slint b/crates/qbz-ui/ui/label/LabelPageView.slint index c931b8896..8b3a1f8a1 100644 --- a/crates/qbz-ui/ui/label/LabelPageView.slint +++ b/crates/qbz-ui/ui/label/LabelPageView.slint @@ -12,12 +12,13 @@ import { Theme } from "../foundation/semantic-colors.slint"; import { Typography } from "../foundation/typography.slint"; import { Radius } from "../foundation/radius.slint"; -import { LabelState, LabelActions, TrackItem, DragState, NavState } from "../state.slint"; +import { LabelState, LabelActions, TrackItem, DragState, NavState, BulkAction } from "../state.slint"; import { QbzIcon } from "../primitives/QbzIcon.slint"; import { TrackRow } from "../primitives/TrackRow.slint"; import { CircleAction } from "../primitives/CircleAction.slint"; import { LoadingSpinner } from "../primitives/LoadingSpinner.slint"; import { ListScrollbar } from "../primitives/ListScrollbar.slint"; +import { MultiSelectBar } from "../primitives/MultiSelectBar.slint"; import { NavButtons } from "../shell/NavButtons.slint"; import { JumpNavBar } from "../primitives/JumpNavBar.slint"; import { Carousel } from "../discover/Carousel.slint"; @@ -42,7 +43,6 @@ export component LabelPageView inherits Rectangle { property active-jump-tab: "about"; // Popular Tracks progressive reveal: 5 -> 20 -> 50 (Tauri's steps). property preview-count: 5; - property multi-select-mode: false; background: Theme.surface-main; @@ -227,9 +227,9 @@ export component LabelPageView inherits Rectangle { } CircleAction { icon: @image-url("../assets/icons/square-check-big.svg"); - active: root.multi-select-mode; + active: LabelState.multi-select; clicked => { - root.multi-select-mode = !root.multi-select-mode; + root.media-action("label", "", "select-toggle"); } } CircleAction { @@ -242,48 +242,23 @@ export component LabelPageView inherits Rectangle { } if LabelState.top-tracks.length > 0: Rectangle { height: 10px; } - // Select-all row (multi-select mode). - if root.multi-select-mode && LabelState.top-tracks.length > 0: HorizontalLayout { - height: 36px; - padding-left: 12px; - padding-right: 12px; - spacing: 16px; - VerticalLayout { - alignment: center; - Rectangle { - width: 28px; - height: 28px; - Rectangle { - x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; - y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; - width: 22px; - height: 22px; - border-radius: 11px; - background: transparent; - border-width: 1.5px; - border-color: check-all-ta.has-hover - ? Theme.text-primary - : Theme.text-muted; - check-all-ta := TouchArea { - mouse-cursor: pointer; - clicked => { - root.media-action("label", "", "select-all-top-tracks"); - } - } - } - } - } - VerticalLayout { - alignment: center; - horizontal-stretch: 1; - Text { - text: @tr("Select all"); - color: Theme.text-secondary; - font-size: Typography.body; - font-weight: Typography.medium; - } + // Bulk action bar — visible in multi-select mode. Actions bubble + // via media-action("label",...). Replaces the old dead Select-all + // row (the checkbox now lives on each TrackRow + this bar). + if LabelState.multi-select && LabelState.top-tracks.length > 0: MultiSelectBar { + selected-count: LabelState.selected-count; + actions: [ + { id: "select-all", label: @tr("Select all"), icon: @image-url("../assets/icons/square-check-big.svg"), danger: false, needs-selection: false }, + { id: "play-next", label: @tr("Play next"), icon: @image-url("../assets/icons/list-plus.svg"), danger: false, needs-selection: true }, + { id: "queue", label: @tr("Add to queue"), icon: @image-url("../assets/icons/list-end.svg"), danger: false, needs-selection: true }, + { id: "add-to-playlist", label: @tr("Add to playlist"), icon: @image-url("../assets/icons/list-music.svg"), danger: false, needs-selection: true }, + { id: "clear", label: @tr("Clear"), icon: @image-url("../assets/icons/x.svg"), danger: false, needs-selection: true }, + ]; + action(id) => { + root.media-action("label", "", id); } } + if LabelState.multi-select && LabelState.top-tracks.length > 0: Rectangle { height: 8px; } for track[index] in LabelState.top-tracks: TrackRow { visible: index < root.preview-count; @@ -292,7 +267,7 @@ export component LabelPageView inherits Rectangle { index: index; // Label tracks carry the album thumbnail (Tauri shows it). show-artwork: true; - multi-select-mode: root.multi-select-mode; + multi-select-mode: LabelState.multi-select; media-action(kind, id, action) => { root.media-action(kind, id, action); } diff --git a/crates/qbz-ui/ui/locallibrary/LocalLibraryView.slint b/crates/qbz-ui/ui/locallibrary/LocalLibraryView.slint index d623d020d..4900f7d7d 100644 --- a/crates/qbz-ui/ui/locallibrary/LocalLibraryView.slint +++ b/crates/qbz-ui/ui/locallibrary/LocalLibraryView.slint @@ -852,6 +852,16 @@ export component LocalLibraryView inherits Rectangle { } } } + // Multi-select toggle. + VerticalLayout { + alignment: center; + CircleIconBtn { + icon: @image-url("../assets/icons/square-check-big.svg"); + clicked => { + LocalLibraryActions.albums-toggle-multi-select(); + } + } + } } // Tracks toolbar — multi-select toggle + search + group-by. @@ -1131,11 +1141,28 @@ export component LocalLibraryView inherits Rectangle { padding-bottom: 100px; spacing: 0px; alignment: start; + // Bulk action bar — visible in albums multi-select. + if LocalLibraryState.albums-multi-select: MultiSelectBar { + selected-count: LocalLibraryState.albums-selected-count; + actions: [ + { id: "select-all", label: @tr("Select all"), icon: @image-url("../assets/icons/square-check-big.svg"), danger: false, needs-selection: false }, + { id: "queue", label: @tr("Add to queue"), icon: @image-url("../assets/icons/list-end.svg"), danger: false, needs-selection: true }, + { id: "play-next", label: @tr("Play next"), icon: @image-url("../assets/icons/list-plus.svg"), danger: false, needs-selection: true }, + { id: "add-to-playlist", label: @tr("Add to playlist"), icon: @image-url("../assets/icons/list-music.svg"), danger: false, needs-selection: true }, + { id: "add-to-mixtape", label: @tr("Add to Mixtape/Collection"), icon: @image-url("../assets/icons/cassette-tape.svg"), danger: false, needs-selection: true }, + { id: "clear", label: @tr("Clear"), icon: @image-url("../assets/icons/x.svg"), danger: false, needs-selection: true }, + ]; + action(id) => { + LocalLibraryActions.albums-bulk-action(id); + } + } + if LocalLibraryState.albums-multi-select: Rectangle { height: 8px; } AlbumCollectionView { albums: LocalLibraryState.albums-visible; grouped: LocalLibraryState.albums-grouped; is-grouped: LocalLibraryState.albums-group != "off"; view-mode: LocalLibraryState.albums-view-mode; + select-mode: LocalLibraryState.albums-multi-select; // List view shows the SOURCE column (local/offline/plex). show-source: true; // Local albums aren't Qobuz-favoritable — hide the heart. diff --git a/crates/qbz-ui/ui/mix/MixView.slint b/crates/qbz-ui/ui/mix/MixView.slint index 8a2609627..69ca3ff4e 100644 --- a/crates/qbz-ui/ui/mix/MixView.slint +++ b/crates/qbz-ui/ui/mix/MixView.slint @@ -8,17 +8,19 @@ import { Theme } from "../foundation/semantic-colors.slint"; import { Typography } from "../foundation/typography.slint"; import { Radius } from "../foundation/radius.slint"; -import { MixState, DragState, NavState } from "../state.slint"; +import { MixState, DragState, NavState, BulkAction } from "../state.slint"; import { QbzIcon } from "../primitives/QbzIcon.slint"; import { TrackRow } from "../primitives/TrackRow.slint"; import { LoadingSpinner } from "../primitives/LoadingSpinner.slint"; import { ListScrollbar } from "../primitives/ListScrollbar.slint"; +import { MultiSelectBar } from "../primitives/MultiSelectBar.slint"; import { NavButtons } from "../shell/NavButtons.slint"; // Circular header action button (Play / Shuffle / Save / Refresh). component CircleAction inherits Rectangle { in property icon; in property primary: false; + in property active: false; in property diameter: 38px; in property enabled: true; callback clicked(); @@ -36,7 +38,9 @@ component CircleAction inherits Rectangle { height: root.primary ? 18px : 16px; x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; - tint: root.primary ? #ffffff : Theme.text-secondary; + tint: root.primary + ? #ffffff + : (root.active ? Theme.accent : Theme.text-secondary); } ta := TouchArea { mouse-cursor: root.enabled ? pointer : default; @@ -182,6 +186,18 @@ export component MixView inherits Rectangle { enabled: MixState.tracks.length > 0; } } + // Multi-select toggle (accent-tinted when active). + VerticalLayout { + alignment: center; + CircleAction { + icon: @image-url("../assets/icons/square-check-big.svg"); + active: MixState.multi-select; + enabled: MixState.tracks.length > 0; + clicked => { + root.media-action("mix", "", "select-toggle"); + } + } + } VerticalLayout { alignment: center; CircleAction { @@ -197,6 +213,23 @@ export component MixView inherits Rectangle { Rectangle { height: 28px; } + // Bulk action bar — visible in multi-select mode. Scrolls with the + // page (same as AlbumView). Actions bubble via media-action("mix"). + if MixState.multi-select: MultiSelectBar { + selected-count: MixState.selected-count; + actions: [ + { id: "select-all", label: @tr("Select all"), icon: @image-url("../assets/icons/square-check-big.svg"), danger: false, needs-selection: false }, + { id: "play-next", label: @tr("Play next"), icon: @image-url("../assets/icons/list-plus.svg"), danger: false, needs-selection: true }, + { id: "queue", label: @tr("Add to queue"), icon: @image-url("../assets/icons/list-end.svg"), danger: false, needs-selection: true }, + { id: "add-to-playlist", label: @tr("Add to playlist"), icon: @image-url("../assets/icons/list-music.svg"), danger: false, needs-selection: true }, + { id: "clear", label: @tr("Clear"), icon: @image-url("../assets/icons/x.svg"), danger: false, needs-selection: true }, + ]; + action(id) => { + root.media-action("mix", "", id); + } + } + if MixState.multi-select: Rectangle { height: 8px; } + if MixState.loading: HorizontalLayout { alignment: center; LoadingSpinner { size: 36px; } @@ -261,6 +294,7 @@ export component MixView inherits Rectangle { for track[i] in MixState.tracks: TrackRow { track: track; index: i; + multi-select-mode: MixState.multi-select; show-artwork: true; show-album: true; show-favorite: true; diff --git a/crates/qbz-ui/ui/primitives/AlbumListRow.slint b/crates/qbz-ui/ui/primitives/AlbumListRow.slint index a32cac774..82557db5f 100644 --- a/crates/qbz-ui/ui/primitives/AlbumListRow.slint +++ b/crates/qbz-ui/ui/primitives/AlbumListRow.slint @@ -143,6 +143,10 @@ export component AlbumListRow inherits Rectangle { in property rank; // The SOURCE column is hidden in single-source contexts (Discover). in property show-source: true; + // Multi-select mode (Local Library albums): a leading checkbox + row click + // toggles selection instead of opening. Default false → other consumers + // (Discover/Label/Favorites lists) are untouched. + in property select-mode: false; callback clicked(string); // kind ("album" | "artist"), id, action ("play" | "queue" | @@ -164,7 +168,11 @@ export component AlbumListRow inherits Rectangle { ta := TouchArea { mouse-cursor: pointer; clicked => { - root.clicked(root.album.id); + if (root.select-mode) { + root.media-action("album", root.album.id, "toggle-select"); + } else { + root.clicked(root.album.id); + } } } @@ -173,6 +181,29 @@ export component AlbumListRow inherits Rectangle { padding-right: 12px; spacing: AlbumListCols.gap; + // --- Multi-select checkbox (leading) -------------------------- + if root.select-mode: VerticalLayout { + alignment: center; + Rectangle { + width: 18px; + height: 18px; + border-radius: 9px; + background: root.album.selected ? Theme.accent : transparent; + border-width: root.album.selected ? 0px : 1.5px; + border-color: Theme.text-muted; + animate background { duration: 120ms; } + QbzIcon { + source: @image-url("../assets/icons/check.svg"); + visible: root.album.selected; + width: 11px; + height: 11px; + x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; + y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; + tint: #ffffff; + } + } + } + // --- # --------------------------------------------------------- if root.show-rank: Text { width: AlbumListCols.rank; @@ -216,7 +247,11 @@ export component AlbumListRow inherits Rectangle { art-ta := TouchArea { mouse-cursor: pointer; clicked => { - root.media-action("album", root.album.id, "play"); + if (root.select-mode) { + root.media-action("album", root.album.id, "toggle-select"); + } else { + root.media-action("album", root.album.id, "play"); + } } } } diff --git a/crates/qbz-ui/ui/state.slint b/crates/qbz-ui/ui/state.slint index 19bde86f5..b26e350bc 100644 --- a/crates/qbz-ui/ui/state.slint +++ b/crates/qbz-ui/ui/state.slint @@ -27,6 +27,7 @@ export struct AlbumCardItem { artwork: image, // empty until the artwork pipeline resolves it is-favorite: bool, // filled accent heart on the card when favorited removing: bool, // fading out (un-favorited in the favorites view) + selected: bool, // checkbox state in a multi-select grid (LocalLibrary) // --- List-row extras (AlbumListRow; ignored by the grid AlbumCard) ---- release-type: string, // "Album" | "EP" | "Single" | "Live" | "Compilation" source: string, // "qobuz" | "local" | "plex" | "" — hideable column @@ -1026,6 +1027,8 @@ export global LocalLibraryState { in-out property albums-group: "off"; // off | alpha | artist in property <[AlphaJump]> albums-alpha: []; // A-Z jumps (alpha group) in property albums-shown: 0; // count after filter + in-out property albums-multi-select: false; // album checkboxes on + in property albums-selected-count: 0; // bar count + select-all // --- Tracks tab (server-paginated flat list — the 16K-freeze fix) --- // Group-by / multi-select / per-row play land with the playback slice. @@ -1150,9 +1153,14 @@ export global LocalLibraryActions { callback open-album(string /* album id */); // Open an artist (lands with the Artists slice). callback open-artist(string /* artist id */); - // Per-card action (play / queue / play-next) — lands with the playback - // slice. Wired now so the shared AlbumCollectionView contract is honored. + // Per-card action (play / queue / play-next / toggle-select). The Albums + // grid honors the shared AlbumCollectionView contract. callback album-action(string /* album id */, string /* action */); + // Toggle the Albums-grid multi-select mode. + callback albums-toggle-multi-select(); + // Albums bulk bar action: select-all | clear | queue | play-next | + // add-to-playlist | add-to-mixtape. + callback albums-bulk-action(string /* action */); // --- Tracks tab --- callback tracks-search(string /* query */); @@ -3370,6 +3378,10 @@ export global LabelState { in property is-following: false; // Popular tracks (album-thumbnail rows, multi-select capable). in property <[TrackItem]> top-tracks: []; + // Multi-select (mirrors AlbumState): mode flag + count. Per-row toggle + // routes through the shared media-action("track",...) arm. + in-out property multi-select: false; + in property selected-count: 0; // Releases + Critics' Picks carousels (reuse Carousel). in property releases-section; in property critics-section; @@ -4798,6 +4810,10 @@ export global MixState { in property track-count: 0; in property total-duration; in property loading: false; + // Keyboard/checkbox multi-select (mirrors AlbumState): mode flag + count. + // Per-row toggle routes through the shared media-action("track",...) arm. + in-out property multi-select: false; + in property selected-count: 0; } // Search results screen state. The Rust search controller populates the diff --git a/crates/qbz/src/home.rs b/crates/qbz/src/home.rs index f36fe8dc3..a8ebc6fdc 100644 --- a/crates/qbz/src/home.rs +++ b/crates/qbz/src/home.rs @@ -604,6 +604,7 @@ pub(crate) fn card_to_item(card: CardData) -> AlbumCardItem { plain_year: card.plain_year.into(), is_favorite: false, removing: false, + selected: false, } } diff --git a/crates/qbz/src/label.rs b/crates/qbz/src/label.rs index 6a50ed7bc..41a841a44 100644 --- a/crates/qbz/src/label.rs +++ b/crates/qbz/src/label.rs @@ -359,6 +359,87 @@ pub fn top_tracks_for_play() -> Vec { PLAY_TOP_TRACKS.with(|c| c.borrow().clone()) } +// ==================== Multi-select (Popular Tracks) ==================== + +/// Toggle Popular Tracks multi-select; leaving clears the selection + anchor. +pub fn set_multi_select(window: &AppWindow, on: bool) { + window.global::().set_multi_select(on); + crate::selection::clear_anchor(); + if !on { + clear_selection(window); + } +} + +/// Recompute the "N selected" count from the Popular Tracks rows. +pub fn recount_selected(window: &AppWindow) { + let state = window.global::(); + let model = state.get_top_tracks(); + let count = (0..model.row_count()) + .filter(|&i| model.row_data(i).map(|t| t.selected).unwrap_or(false)) + .count(); + state.set_selected_count(count as i32); +} + +/// Select every row, or clear if all are already selected (the bulk bar's +/// "Select all" toggle — Ctrl+A goes through `selection::select_all`). +pub fn select_all(window: &AppWindow) { + let model = window.global::().get_top_tracks(); + let total = model.row_count(); + let selected = (0..total) + .filter(|&i| model.row_data(i).map(|t| t.selected).unwrap_or(false)) + .count(); + let target = selected != total; + for i in 0..total { + if let Some(mut item) = model.row_data(i) { + if item.selected != target { + item.selected = target; + model.set_row_data(i, item); + } + } + } + recount_selected(window); +} + +/// Clear the selection (uncheck all), keeping multi-select mode on. +pub fn clear_selection(window: &AppWindow) { + let model = window.global::().get_top_tracks(); + for i in 0..model.row_count() { + if let Some(mut item) = model.row_data(i) { + if item.selected { + item.selected = false; + model.set_row_data(i, item); + } + } + } + window.global::().set_selected_count(0); +} + +/// Catalog ids of the selected rows (for add-to-playlist — Qobuz ids only). +pub fn selected_ids(window: &AppWindow) -> Vec { + let model = window.global::().get_top_tracks(); + (0..model.row_count()) + .filter_map(|i| model.row_data(i)) + .filter(|t| t.selected) + .map(|t| t.id.to_string()) + .filter(|s| s.parse::().is_ok()) + .collect() +} + +/// Full `Track` objects for the selected rows (for enqueue), resolved from the +/// cached top tracks in DISPLAY order. +pub fn selected_play_tracks(window: &AppWindow) -> Vec { + let model = window.global::().get_top_tracks(); + let cur = top_tracks_for_play(); + (0..model.row_count()) + .filter_map(|i| model.row_data(i)) + .filter(|t| t.selected) + .filter_map(|t| { + let id = t.id.to_string(); + cur.iter().find(|c| c.id.to_string() == id).cloned() + }) + .collect() +} + /// Fetch + map the full label landing page. pub async fn load_label_page( runtime: &Arc>, diff --git a/crates/qbz/src/local_library.rs b/crates/qbz/src/local_library.rs index b1f8cd5f1..2e1757456 100644 --- a/crates/qbz/src/local_library.rs +++ b/crates/qbz/src/local_library.rs @@ -1048,6 +1048,203 @@ pub fn local_track_by_id(id: &str) -> Option { tracks_current().iter().find(|t| t.id.to_string() == id).cloned() } +// ==================== Albums multi-select ==================== +// +// Albums are `AlbumCardItem` (not `TrackItem`), so they get their own select +// path (not the central toggle arm). The rendered set is either the flat +// `albums-visible` or, when grouping is on, the concatenation of the +// `albums-grouped` sections — both are patched so a Shift-range / select-all +// stays consistent across the duplicate copies of an album id. + +/// Enter/leave Albums multi-select; leaving clears the selection + anchor. +pub fn set_albums_multi_select(window: &AppWindow, on: bool) { + window.global::().set_albums_multi_select(on); + crate::selection::clear_anchor(); + if !on { + clear_albums_selection(window); + } +} + +/// Rendered album ids in display order (flat `albums-visible`, or the +/// concatenation of the grouped sections when grouping is on). +fn rendered_album_ids(window: &AppWindow) -> Vec { + let s = window.global::(); + let grouped = s.get_albums_grouped(); + if grouped.row_count() > 0 { + let mut out = Vec::new(); + for gi in 0..grouped.row_count() { + if let Some(sec) = grouped.row_data(gi) { + for i in 0..sec.albums.row_count() { + if let Some(a) = sec.albums.row_data(i) { + out.push(a.id.to_string()); + } + } + } + } + out + } else { + let m = s.get_albums_visible(); + (0..m.row_count()) + .filter_map(|i| m.row_data(i)) + .map(|a| a.id.to_string()) + .collect() + } +} + +/// Apply `f` to each rendered album model (flat `albums-visible` + every grouped +/// section). The source `albums` set is intentionally NOT touched — a re-sort / +/// re-filter rebuilds the rendered set from it and resets the selection, which +/// matches Tauri's anchor-reset-on-rebuild behavior. +fn for_each_album_model(window: &AppWindow, mut f: impl FnMut(&ModelRc)) { + let s = window.global::(); + f(&s.get_albums_visible()); + let grouped = s.get_albums_grouped(); + for gi in 0..grouped.row_count() { + if let Some(sec) = grouped.row_data(gi) { + f(&sec.albums); + } + } +} + +/// Set `selected = value` on every album row whose id is in `ids`. +fn set_albums_selected(window: &AppWindow, ids: &std::collections::HashSet, value: bool) { + for_each_album_model(window, |m| { + for i in 0..m.row_count() { + if let Some(mut it) = m.row_data(i) { + if ids.contains(it.id.as_str()) && it.selected != value { + it.selected = value; + m.set_row_data(i, it); + } + } + } + }); +} + +/// Current selected state of one album id (read from the rendered set). +fn album_is_selected(window: &AppWindow, id: &str) -> bool { + let mut found = false; + for_each_album_model(window, |m| { + if found { + return; + } + for i in 0..m.row_count() { + if let Some(a) = m.row_data(i) { + if a.id.as_str() == id { + found = a.selected; + return; + } + } + } + }); + found +} + +/// Recount distinct selected albums into `albums-selected-count`. +pub fn recount_albums_selected(window: &AppWindow) { + let mut seen = std::collections::HashSet::new(); + for_each_album_model(window, |m| { + for i in 0..m.row_count() { + if let Some(a) = m.row_data(i) { + if a.selected { + seen.insert(a.id.to_string()); + } + } + } + }); + window + .global::() + .set_albums_selected_count(seen.len() as i32); +} + +/// Per-card toggle (by id). Plain/Ctrl+Click = single toggle; Shift+Click = +/// additive range from the anchor over the rendered album order. +pub fn toggle_album_select(window: &AppWindow, id: &str) { + let ids = rendered_album_ids(window); + let Some(clicked) = ids.iter().position(|a| a == id) else { + return; + }; + let shift = crate::keybindings::mods().2; + if shift { + if let Some((a_idx, a_id)) = + crate::selection::anchor_for(crate::selection::SURFACE_LOCAL_ALBUMS) + { + // Re-resolve the anchor against the live order (resilient to re-sort). + let anchor = if ids.get(a_idx).map(|s| *s == a_id).unwrap_or(false) { + Some(a_idx) + } else { + ids.iter().position(|s| *s == a_id) + }; + if let Some(anchor) = anchor { + let lo = anchor.min(clicked); + let hi = anchor.max(clicked); + let range: std::collections::HashSet = + ids[lo..=hi].iter().cloned().collect(); + set_albums_selected(window, &range, true); + crate::selection::set_anchor( + crate::selection::SURFACE_LOCAL_ALBUMS, + clicked, + id, + ); + recount_albums_selected(window); + return; + } + } + } + let now = !album_is_selected(window, id); + let one: std::collections::HashSet = std::iter::once(id.to_string()).collect(); + set_albums_selected(window, &one, now); + crate::selection::set_anchor(crate::selection::SURFACE_LOCAL_ALBUMS, clicked, id); + recount_albums_selected(window); +} + +/// Select-all toggle (the bulk bar button) — select all, or clear if all are +/// already selected. Ctrl+A uses `select_all_albums_only` (never clears). +pub fn select_all_albums(window: &AppWindow) { + let ids = rendered_album_ids(window); + let total = ids.len(); + let selected = ids.iter().filter(|id| album_is_selected(window, id)).count(); + let target = selected != total; + let all: std::collections::HashSet = ids.into_iter().collect(); + set_albums_selected(window, &all, target); + recount_albums_selected(window); +} + +/// Select every rendered album (Ctrl+A — never clears). +pub fn select_all_albums_only(window: &AppWindow) { + let all: std::collections::HashSet = + rendered_album_ids(window).into_iter().collect(); + set_albums_selected(window, &all, true); + recount_albums_selected(window); +} + +/// Clear the album selection (multi-select mode stays on). +pub fn clear_albums_selection(window: &AppWindow) { + let all: std::collections::HashSet = + rendered_album_ids(window).into_iter().collect(); + set_albums_selected(window, &all, false); + window + .global::() + .set_albums_selected_count(0); +} + +/// The selected album ids (group keys), in rendered order. +pub fn selected_album_ids(window: &AppWindow) -> Vec { + let ids = rendered_album_ids(window); + ids.into_iter() + .filter(|id| album_is_selected(window, id)) + .collect() +} + +/// Resolve the selected albums to their `LocalTrack`s (BLOCKING — DB; call from +/// `spawn_blocking`). Each album's tracks are concatenated in rendered order. +pub fn selected_albums_tracks_blocking(album_keys: &[String]) -> Vec { + let mut out = Vec::new(); + for key in album_keys { + out.extend(fetch_album_tracks_blocking(key)); + } + out +} + fn spawn_tracks_page_load(window: &AppWindow, handle: tokio::runtime::Handle, gen: u64) { let s = window.global::(); let query = s.get_tracks_search().to_string(); diff --git a/crates/qbz/src/main.rs b/crates/qbz/src/main.rs index df74f62b9..3877e744d 100644 --- a/crates/qbz/src/main.rs +++ b/crates/qbz/src/main.rs @@ -806,6 +806,17 @@ fn select_all_active_surface(window: &AppWindow) -> bool { offline_manager::set_all_selected(window, true); return true; } + // LocalLibrary Albums tab selects AlbumCardItem (not TrackItem) — its own + // select-all-only path. The Tracks tab falls through to the TrackItem match. + if view == ContentView::LocalLibrary + && window.global::().get_active_tab().as_str() == "albums" + { + if window.global::().get_albums_multi_select() { + local_library::select_all_albums_only(window); + return true; + } + return false; + } let (model, on): (slint::ModelRc, bool) = match view { ContentView::Album => ( window.global::().get_tracks(), @@ -827,6 +838,14 @@ fn select_all_active_surface(window: &AppWindow) -> bool { window.global::().get_tracks_visible(), window.global::().get_tracks_multi_select(), ), + ContentView::Mix => ( + window.global::().get_tracks(), + window.global::().get_multi_select(), + ), + ContentView::Label => ( + window.global::().get_top_tracks(), + window.global::().get_multi_select(), + ), _ => return false, }; if !on { @@ -841,6 +860,8 @@ fn select_all_active_surface(window: &AppWindow) -> bool { ContentView::Playlist => playlist::recount_selected(window), ContentView::Favorites => favorites::recount_selected(window), ContentView::LocalLibrary => local_library::recount_tracks_selected(window), + ContentView::Mix => mix::recount_selected(window), + ContentView::Label => label::recount_selected(window), _ => {} } true @@ -873,12 +894,26 @@ pub(crate) fn exit_active_multi_select(window: &AppWindow) -> bool { favorites::set_multi_select(window, false); true } + ContentView::LocalLibrary + if window.global::().get_albums_multi_select() => + { + local_library::set_albums_multi_select(window, false); + true + } ContentView::LocalLibrary if window.global::().get_tracks_multi_select() => { local_library::set_tracks_multi_select(window, false); true } + ContentView::Mix if window.global::().get_multi_select() => { + mix::set_multi_select(window, false); + true + } + ContentView::Label if window.global::().get_multi_select() => { + label::set_multi_select(window, false); + true + } // Offline Manager has no mode to leave (always-on selection); Escape // clears the selection when something is selected. ContentView::OfflineManager @@ -8986,6 +9021,51 @@ fn main() -> Result<(), Box> { ); } } + // Label Popular Tracks multi-select: mode toggle + bulk bar. + ("label", "select-toggle") => { + if let Some(w) = weak.upgrade() { + let on = w.global::().get_multi_select(); + label::set_multi_select(&w, !on); + } + } + ("label", "select-all") => { + if let Some(w) = weak.upgrade() { + label::select_all(&w); + } + } + ("label", "clear") => { + if let Some(w) = weak.upgrade() { + label::clear_selection(&w); + } + } + ("label", "queue") => { + if let Some(w) = weak.upgrade() { + let tracks = label::selected_play_tracks(&w); + playback::enqueue_tracks(runtime.clone(), handle.clone(), tracks, false); + } + } + ("label", "play-next") => { + if let Some(w) = weak.upgrade() { + let tracks = label::selected_play_tracks(&w); + playback::enqueue_tracks(runtime.clone(), handle.clone(), tracks, true); + } + } + ("label", "add-to-playlist") => { + if let Some(w) = weak.upgrade() { + let ids = label::selected_ids(&w); + if !ids.is_empty() { + playlist_picker::open_multi(&w, &ids, false); + let runtime = runtime.clone(); + let weak = weak.clone(); + handle.spawn(async move { + let playlists = playlist_picker::load(&runtime).await; + let _ = weak.upgrade_in_event_loop(move |w| { + playlist_picker::apply(&w, playlists); + }); + }); + } + } + } // More-Labels card click -> open that label's landing. ("label", "open") => { if let Ok(label_id) = id.parse::() { @@ -9112,6 +9192,10 @@ fn main() -> Result<(), Box> { w.global::().get_tracks_visible(), selection::SURFACE_FAVORITES, ), + ContentView::Mix => ( + w.global::().get_tracks(), + selection::SURFACE_MIX, + ), _ => ( w.global::().get_top_tracks(), selection::SURFACE_ARTIST, @@ -9155,6 +9239,8 @@ fn main() -> Result<(), Box> { ContentView::Artist => artist::recount_selected(&w), ContentView::Playlist => playlist::recount_selected(&w), ContentView::Favorites => favorites::recount_selected(&w), + ContentView::Mix => mix::recount_selected(&w), + ContentView::Label => label::recount_selected(&w), _ => {} } } @@ -9206,6 +9292,52 @@ fn main() -> Result<(), Box> { } } } + // Mix multi-select: mode toggle + bulk bar (select-all toggles + // all/none; Ctrl+A select-all-only goes through the key handler). + ("mix", "select-toggle") => { + if let Some(w) = weak.upgrade() { + let on = w.global::().get_multi_select(); + mix::set_multi_select(&w, !on); + } + } + ("mix", "select-all") => { + if let Some(w) = weak.upgrade() { + mix::select_all(&w); + } + } + ("mix", "clear") => { + if let Some(w) = weak.upgrade() { + mix::clear_selection(&w); + } + } + ("mix", "queue") => { + if let Some(w) = weak.upgrade() { + let tracks = mix::selected_play_tracks(&w); + playback::enqueue_tracks(runtime.clone(), handle.clone(), tracks, false); + } + } + ("mix", "play-next") => { + if let Some(w) = weak.upgrade() { + let tracks = mix::selected_play_tracks(&w); + playback::enqueue_tracks(runtime.clone(), handle.clone(), tracks, true); + } + } + ("mix", "add-to-playlist") => { + if let Some(w) = weak.upgrade() { + let ids = mix::selected_ids(&w); + if !ids.is_empty() { + playlist_picker::open_multi(&w, &ids, false); + let runtime = runtime.clone(); + let weak = weak.clone(); + handle.spawn(async move { + let playlists = playlist_picker::load(&runtime).await; + let _ = weak.upgrade_in_event_loop(move |w| { + playlist_picker::apply(&w, playlists); + }); + }); + } + } + } ("playlist", "cache") => { if let Ok(pid) = id.parse::() { offline_cache::cache_playlist( @@ -14236,8 +14368,8 @@ fn main() -> Result<(), Box> { let handle = tokio_rt.handle().clone(); window .global::() - .on_album_action(move |id, action| { - if action.as_str() == "play" { + .on_album_action(move |id, action| match action.as_str() { + "play" => { // The whole album becomes the queue and auto-advances. playback::play_local_album( runtime.clone(), @@ -14246,8 +14378,14 @@ fn main() -> Result<(), Box> { id.to_string(), None, ); - } else { - // play-next / queue land with a later slice. + } + "toggle-select" => { + if let Some(w) = weak.upgrade() { + local_library::toggle_album_select(&w, id.as_str()); + } + } + _ => { + // Single-album play-next / queue land with a later slice. log::debug!("[qbz-slint] local album action (queue slice pending): {id} {action}"); } }); @@ -14565,6 +14703,100 @@ fn main() -> Result<(), Box> { } }); } + { + // Albums-grid multi-select toggle. + let weak = window.as_weak(); + window + .global::() + .on_albums_toggle_multi_select(move || { + if let Some(w) = weak.upgrade() { + let on = w.global::().get_albums_multi_select(); + local_library::set_albums_multi_select(&w, !on); + } + }); + } + { + // Albums-grid bulk bar. Album->tracks resolution is a blocking DB read + // (fetch_album_tracks_blocking), so it runs on spawn_blocking; the + // resulting LocalTracks feed the same enqueue/playlist/mixtape paths as + // the Tracks tab. + let runtime = app_runtime.clone(); + let weak = window.as_weak(); + let handle = tokio_rt.handle().clone(); + window + .global::() + .on_albums_bulk_action(move |action| { + let Some(w) = weak.upgrade() else { + return; + }; + match action.as_str() { + "select-all" => local_library::select_all_albums(&w), + "clear" => local_library::clear_albums_selection(&w), + "queue" | "play-next" => { + let keys = local_library::selected_album_ids(&w); + let play_next = action.as_str() == "play-next"; + let runtime = runtime.clone(); + let handle2 = handle.clone(); + handle.spawn(async move { + let rows = tokio::task::spawn_blocking(move || { + local_library::selected_albums_tracks_blocking(&keys) + }) + .await + .unwrap_or_default(); + playback::enqueue_local_tracks(runtime, handle2, rows, play_next); + }); + local_library::clear_albums_selection(&w); + } + "add-to-playlist" => { + let keys = local_library::selected_album_ids(&w); + if !keys.is_empty() { + let runtime = runtime.clone(); + let weak2 = weak.clone(); + handle.spawn(async move { + let rows = tokio::task::spawn_blocking(move || { + local_library::selected_albums_tracks_blocking(&keys) + }) + .await + .unwrap_or_default(); + let ids: Vec = rows.iter().map(local_picker_ref).collect(); + let runtime2 = runtime.clone(); + let _ = weak2.upgrade_in_event_loop(move |w| { + if !ids.is_empty() { + playlist_picker::open_multi(&w, &ids, true); + } + }); + let playlists = playlist_picker::load(&runtime2).await; + let _ = weak2.upgrade_in_event_loop(move |w| { + playlist_picker::apply(&w, playlists); + }); + }); + } + } + "add-to-mixtape" => { + let keys = local_library::selected_album_ids(&w); + if !keys.is_empty() { + let weak2 = weak.clone(); + let handle2 = handle.clone(); + handle.spawn(async move { + let rows = tokio::task::spawn_blocking(move || { + local_library::selected_albums_tracks_blocking(&keys) + }) + .await + .unwrap_or_default(); + let _ = weak2.upgrade_in_event_loop(move |w| { + let items = myqbz_add::track_items_from_local(&rows); + if !items.is_empty() { + open_add_to_mixtape(w.as_weak(), handle2, items); + local_library::clear_albums_selection(&w); + } + }); + }); + } + } + _ => {} + } + }); + } // ---- Folders tree rail: search / collapse / multi-select ---- { diff --git a/crates/qbz/src/mix.rs b/crates/qbz/src/mix.rs index c287fc940..f9eec772e 100644 --- a/crates/qbz/src/mix.rs +++ b/crates/qbz/src/mix.rs @@ -19,7 +19,7 @@ use qbz_app::settings::reco_store::HomeSeedLimits; use qbz_app::shell::AppRuntime; use qbz_core::FrontendAdapter; use qbz_models::{Track, TrackToAnalyse}; -use slint::{ComponentHandle, ModelRc, VecModel}; +use slint::{ComponentHandle, Model, ModelRc, VecModel}; use crate::artwork::{ArtworkJob, ArtworkTarget}; use crate::{AppWindow, MixState, TrackItem}; @@ -407,6 +407,89 @@ pub fn shuffled_tracks() -> Vec { tracks } +// ==================== Multi-select (track selection) ==================== + +/// Toggle multi-select mode; leaving the mode clears the selection. Drops the +/// Shift-range anchor on either transition. +pub fn set_multi_select(window: &AppWindow, on: bool) { + window.global::().set_multi_select(on); + crate::selection::clear_anchor(); + if !on { + clear_selection(window); + } +} + +/// Recompute the "N selected" count from the track rows. +pub fn recount_selected(window: &AppWindow) { + let state = window.global::(); + let model = state.get_tracks(); + let count = (0..model.row_count()) + .filter(|&i| model.row_data(i).map(|t| t.selected).unwrap_or(false)) + .count(); + state.set_selected_count(count as i32); +} + +/// Select every row, or clear if all are already selected (the toggle the +/// "Select all" bulk button drives — same semantics as the album/favorites bar; +/// Ctrl+A goes through `selection::select_all`, which only ever selects). +pub fn select_all(window: &AppWindow) { + let model = window.global::().get_tracks(); + let total = model.row_count(); + let selected = (0..total) + .filter(|&i| model.row_data(i).map(|t| t.selected).unwrap_or(false)) + .count(); + let target = selected != total; + for i in 0..total { + if let Some(mut item) = model.row_data(i) { + if item.selected != target { + item.selected = target; + model.set_row_data(i, item); + } + } + } + recount_selected(window); +} + +/// Clear the selection (uncheck all), keeping multi-select mode on. +pub fn clear_selection(window: &AppWindow) { + let model = window.global::().get_tracks(); + for i in 0..model.row_count() { + if let Some(mut item) = model.row_data(i) { + if item.selected { + item.selected = false; + model.set_row_data(i, item); + } + } + } + window.global::().set_selected_count(0); +} + +/// The catalog ids of the selected rows (for add-to-playlist — Qobuz ids only). +pub fn selected_ids(window: &AppWindow) -> Vec { + let model = window.global::().get_tracks(); + (0..model.row_count()) + .filter_map(|i| model.row_data(i)) + .filter(|t| t.selected) + .map(|t| t.id.to_string()) + .filter(|s| s.parse::().is_ok()) + .collect() +} + +/// The full `Track` objects for the selected rows (for enqueue), resolved from +/// the cached mix tracks in DISPLAY order. +pub fn selected_play_tracks(window: &AppWindow) -> Vec { + let model = window.global::().get_tracks(); + let cur = current_tracks(); + (0..model.row_count()) + .filter_map(|i| model.row_data(i)) + .filter(|t| t.selected) + .filter_map(|t| { + let id = t.id.to_string(); + cur.iter().find(|c| c.id.to_string() == id).cloned() + }) + .collect() +} + /// Index of `track_id` within the current mix (for play-from-here). pub fn index_of(track_id: &str) -> usize { CURRENT_MIX diff --git a/crates/qbz/src/selection.rs b/crates/qbz/src/selection.rs index 99799574d..6f54d77b7 100644 --- a/crates/qbz/src/selection.rs +++ b/crates/qbz/src/selection.rs @@ -32,6 +32,8 @@ pub const SURFACE_FAVORITES: u16 = 4; pub const SURFACE_LABEL: u16 = 5; pub const SURFACE_LOCAL_TRACKS: u16 = 6; pub const SURFACE_OFFLINE: u16 = 7; +pub const SURFACE_MIX: u16 = 8; +pub const SURFACE_LOCAL_ALBUMS: u16 = 9; #[derive(Clone)] struct Anchor {