diff --git a/crates/qbz-ui/ui/discover/ExternalRecoView.slint b/crates/qbz-ui/ui/discover/ExternalRecoView.slint index c01f44374..d28eb0b3b 100644 --- a/crates/qbz-ui/ui/discover/ExternalRecoView.slint +++ b/crates/qbz-ui/ui/discover/ExternalRecoView.slint @@ -90,6 +90,10 @@ export component ExternalRecoView inherits VerticalLayout { if ExternalRecoState.weekly-exploration.length > 0: SlimCarousel { title: @tr("Weekly Exploration"); items: ExternalRecoState.weekly-exploration; + show-list-actions: true; + list-action(action) => { + root.media-action("ext-reco-list", "weekly-exploration", action); + } item-clicked(id) => { root.play-track(id); } @@ -99,6 +103,10 @@ export component ExternalRecoView inherits VerticalLayout { if ExternalRecoState.weekly-jams.length > 0: SlimCarousel { title: @tr("Weekly Jams"); items: ExternalRecoState.weekly-jams; + show-list-actions: true; + list-action(action) => { + root.media-action("ext-reco-list", "weekly-jams", action); + } item-clicked(id) => { root.play-track(id); } diff --git a/crates/qbz-ui/ui/discover/SlimCarousel.slint b/crates/qbz-ui/ui/discover/SlimCarousel.slint index 87af856be..d162a023c 100644 --- a/crates/qbz-ui/ui/discover/SlimCarousel.slint +++ b/crates/qbz-ui/ui/discover/SlimCarousel.slint @@ -47,6 +47,11 @@ export component SlimCarousel inherits VerticalLayout { in property title; in property <[SlimItem]> items; callback item-clicked(string); + // P7: optional title-adjacent list actions ("add to queue" / "create + // playlist from this list"). Off by default so the shared SlimCarousel rows + // (recent, popular) are unchanged; only the Weekly rows opt in. + in property show-list-actions: false; + callback list-action(string); property columns: 4; property rows: 3; @@ -71,6 +76,29 @@ export component SlimCarousel inherits VerticalLayout { vertical-alignment: center; horizontal-stretch: 1; } + // Title-adjacent list actions (P7): add the whole backing list to the + // queue / create a playlist from it. Icon buttons (ADR-008, no pills). + if root.show-list-actions: HorizontalLayout { + spacing: 4px; + VerticalLayout { + alignment: center; + NavButton { + icon: @image-url("../assets/icons/list-end.svg"); + clicked => { + root.list-action("queue"); + } + } + } + VerticalLayout { + alignment: center; + NavButton { + icon: @image-url("../assets/icons/list-music.svg"); + clicked => { + root.list-action("create-playlist"); + } + } + } + } // Only when there is a second page. if root.total > root.per-page: HorizontalLayout { spacing: 4px; diff --git a/crates/qbz/src/external_reco.rs b/crates/qbz/src/external_reco.rs index 0795afe47..28e628ba8 100644 --- a/crates/qbz/src/external_reco.rs +++ b/crates/qbz/src/external_reco.rs @@ -23,7 +23,7 @@ use qbz_external_reco::{ }; use qbz_integrations::{LastFmClient, ListenBrainzClient, MusicBrainzClient}; use qbz_models::{Album, Artist, Track}; -use slint::{ComponentHandle, ModelRc, VecModel}; +use slint::{ComponentHandle, Model, ModelRc, VecModel}; use crate::adapter::SlintAdapter; use crate::artwork::{ArtworkJob, ArtworkTarget, ImageCache}; @@ -335,6 +335,22 @@ enum TrackRow { WeeklyJams, } +/// Read the backing Qobuz track ids of one external-reco Weekly TRACK row +/// (Weekly Exploration / Weekly Jams) for the P7 title-adjacent buttons. +/// Returns the whole backing list (not just the 24 visible), in row order. +pub fn list_track_ids(window: &AppWindow, section: &str) -> Vec { + let s = window.global::(); + let model = match section { + "weekly-exploration" => s.get_weekly_exploration(), + "weekly-jams" => s.get_weekly_jams(), + _ => return Vec::new(), + }; + model + .iter() + .filter_map(|it| it.id.as_str().parse::().ok()) + .collect() +} + fn slim_from_artist(a: &ArtistReco) -> SlimItem { SlimItem { id: a.qobuz_artist_id.to_string().into(), diff --git a/crates/qbz/src/main.rs b/crates/qbz/src/main.rs index 0a72035c2..86f3af50f 100644 --- a/crates/qbz/src/main.rs +++ b/crates/qbz/src/main.rs @@ -8278,6 +8278,36 @@ fn main() -> Result<(), Box> { handle.clone(), id.clone(), ), + // External-reco Weekly rows (P7): the title-adjacent buttons. + // `id` carries the section key ("weekly-exploration"/"weekly-jams"). + ("ext-reco-list", "queue") => { + if let Some(w) = weak.upgrade() { + let ids = external_reco::list_track_ids(&w, &id); + playback::enqueue_track_ids( + runtime.clone(), + weak.clone(), + handle.clone(), + ids, + false, + ); + } + } + ("ext-reco-list", "create-playlist") => { + if let Some(w) = weak.upgrade() { + let ids = external_reco::list_track_ids(&w, &id); + if !ids.is_empty() { + let ids_str: Vec = + ids.iter().map(|i| i.to_string()).collect(); + playlist_picker::open_for_ids( + &w, + runtime.clone(), + &handle, + ids_str, + false, + ); + } + } + } ("track", "add-to-playlist") => { // Open the global picker for this track + load the // user's playlists. SOURCE-TYPED routing first: this diff --git a/crates/qbz/src/playback.rs b/crates/qbz/src/playback.rs index bfe8193ac..56e63def9 100644 --- a/crates/qbz/src/playback.rs +++ b/crates/qbz/src/playback.rs @@ -3172,6 +3172,35 @@ pub fn enqueue_playlist( /// Append (or insert-next) a batch of already-fetched tracks to the queue /// without re-fetching them. Used by the favorites bulk bar. +/// Resolve a list of Qobuz track ids (order-preserving) and enqueue them at the +/// end of the queue (or play-next). Backs the external-reco Weekly rows' +/// "add to queue" button (P7). Toasts the outcome. +pub fn enqueue_track_ids( + runtime: Runtime, + weak: slint::Weak, + handle: tokio::runtime::Handle, + ids: Vec, + next: bool, +) { + if ids.is_empty() { + return; + } + handle.spawn(async move { + match runtime.core().get_tracks_batch(&ids).await { + Ok(tracks) if !tracks.is_empty() => { + let n = tracks.len(); + enqueue_tracks(runtime, tokio::runtime::Handle::current(), tracks, next); + crate::toast::success_weak(&weak, format!("Added {n} tracks to queue")); + } + Ok(_) => crate::toast::error_weak(&weak, "No tracks to add"), + Err(e) => { + log::error!("[qbz-slint] enqueue_track_ids: get_tracks_batch failed: {e}"); + crate::toast::error_weak(&weak, "Failed to add tracks"); + } + } + }); +} + pub fn enqueue_tracks( runtime: Runtime, handle: tokio::runtime::Handle,