diff --git a/crates/qbz-slint/src/artwork.rs b/crates/qbz-slint/src/artwork.rs index 832360729..54490a6af 100644 --- a/crates/qbz-slint/src/artwork.rs +++ b/crates/qbz-slint/src/artwork.rs @@ -52,6 +52,8 @@ pub enum ArtworkTarget { /// A release card in `ArtistState.release-sections[section_idx] /// .albums[album_idx]`. ArtistRelease { section_idx: usize, album_idx: usize }, + /// A card in MusicianState.appearances[index]. + MusicianAppearance { index: usize }, } /// An artwork download job: which card, and the image URL. @@ -340,5 +342,12 @@ fn apply_artwork( item.artwork = image; section.albums.set_row_data(album_idx, item); } + ArtworkTarget::MusicianAppearance { index } => { + let model = window.global::().get_appearances(); + if let Some(mut item) = model.row_data(index) { + item.artwork = image; + model.set_row_data(index, item); + } + } } } diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index 3d53636e9..8d6527149 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -23,6 +23,7 @@ mod commands; mod custom_artwork; mod discovery_dismiss; mod home; +mod musician; mod nav; mod play_history; mod strip_html; @@ -413,9 +414,55 @@ fn apply_entry( nav::NavEntry::Search(query) => { navigate_search(runtime.clone(), weak.clone(), handle, image_cache.clone(), query); } + nav::NavEntry::Musician { name, role } => { + navigate_musician( + runtime.clone(), + weak.clone(), + handle, + image_cache.clone(), + name, + role, + ); + } } } +/// Open a MusicianPageView for `name + role`. Routes to the artist +/// page instead when the resolved musician has a Confirmed Qobuz +/// match (Tauri's `confidence === 'confirmed'` shortcut). Fetches +/// the first page of appearances inline; subsequent pages come +/// through the MusicianActions::load-more handler. +fn navigate_musician( + runtime: Arc>, + weak: slint::Weak, + handle: &tokio::runtime::Handle, + image_cache: artwork::ImageCache, + name: String, + role: String, +) { + handle.spawn(async move { + let _ = weak.upgrade_in_event_loop(|w| { + musician::reset_musician(&w); + w.global::().set_view(ContentView::Musician); + }); + match musician::load_musician(&runtime, &name, &role).await { + Ok(data) => { + let jobs = musician::artwork_jobs(&data); + let _ = weak.upgrade_in_event_loop(move |w| { + musician::apply_musician(&w, data); + }); + artwork::spawn_loads(jobs, weak.clone(), image_cache.clone()); + } + Err(e) => { + log::error!("[qbz-slint] musician load failed: {e}"); + let _ = weak.upgrade_in_event_loop(|w| { + w.global::().set_loading(false); + }); + } + } + }); +} + /// Resolve the desktop environment's UI font family. Reads the KDE /// Plasma general font from `kdeglobals` (`[General] font=`), whose /// value is a Qt font string `Family,pointSize,...` — only the family @@ -1261,13 +1308,67 @@ fn main() -> Result<(), Box> { } }); } - window - .global::() - .on_musician_clicked(|name, role| { - log::info!( - "[qbz-slint] network sidebar: musician clicked name={name} role={role}" - ); - }); + // Musician click — resolve the (name, role) first; if Qobuz has + // a confirmed exact match, jump straight to that artist's page. + // Otherwise open MusicianPageView (Contextual / Weak / None). + { + let runtime = app_runtime.clone(); + let weak = window.as_weak(); + let handle = tokio_rt.handle().clone(); + let image_cache = image_cache.clone(); + window + .global::() + .on_musician_clicked(move |name, role| { + let name = name.to_string(); + let role = role.to_string(); + let runtime = runtime.clone(); + let weak = weak.clone(); + let handle = handle.clone(); + let image_cache = image_cache.clone(); + tokio::spawn(async move { + let resolved = + runtime.core().musicbrainz_resolve_musician(&name, &role).await; + match resolved { + Ok(r) if matches!( + r.confidence, + qbz_integrations::musicbrainz::MusicianConfidence::Confirmed + ) => + { + if let Some(id) = r.qobuz_artist_id { + let artist_id = id.to_string(); + let weak2 = weak.clone(); + let _ = weak.clone().upgrade_in_event_loop(move |_| { + nav::record(nav::NavEntry::Artist(artist_id.clone())); + }); + navigate_artist( + runtime, + weak2, + &handle, + image_cache, + id.to_string(), + ); + return; + } + log::warn!( + "[qbz-slint] musician confirmed but no qobuz id" + ); + } + Ok(_) => { + // Fall through to MusicianPageView for + // Contextual / Weak / None. + } + Err(e) => { + log::warn!("[qbz-slint] musician resolve failed: {e}"); + } + } + nav::record(nav::NavEntry::Musician { + name: name.clone(), + role: role.clone(), + }); + navigate_musician(runtime, weak, &handle, image_cache, name, role); + }); + }); + } // discovery-dismissed — persist the rejection under the current // tag, then remove the row from the visible list. { @@ -1291,6 +1392,62 @@ fn main() -> Result<(), Box> { }); } + // Musician appearances pagination — Load more in + // MusicianPageView appends the next 20 albums onto the existing + // grid. + { + let runtime = app_runtime.clone(); + let weak = window.as_weak(); + let handle = tokio_rt.handle().clone(); + let image_cache = image_cache.clone(); + window + .global::() + .on_load_more(move || { + let Some(w) = weak.upgrade() else { + return; + }; + let state = w.global::(); + let name = state.get_name().to_string(); + let role = state.get_role().to_string(); + let offset = state.get_appearances().row_count() as u32; + if name.is_empty() { + return; + } + state.set_load_more_loading(true); + let runtime = runtime.clone(); + let weak = weak.clone(); + let handle = handle.clone(); + let image_cache = image_cache.clone(); + handle.clone().spawn(async move { + match musician::load_more_appearances(&runtime, &name, &role, offset).await { + Ok((data, total)) => { + let jobs: Vec = data + .iter() + .enumerate() + .filter(|(_, a)| !a.artwork_url.is_empty()) + .map(|(i, a)| artwork::ArtworkJob { + url: a.artwork_url.clone(), + target: artwork::ArtworkTarget::MusicianAppearance { + index: offset as usize + i, + }, + }) + .collect(); + let _ = weak.upgrade_in_event_loop(move |w| { + musician::append_appearances(&w, data, total); + }); + artwork::spawn_loads(jobs, weak, image_cache); + } + Err(e) => { + log::error!("[qbz-slint] musician load-more failed: {e}"); + let _ = weak.upgrade_in_event_loop(|w| { + w.global::().set_load_more_loading(false); + }); + } + } + }); + }); + } + // Artwork right-click menu wiring — Open in browser / Save as / // Add custom / Remove custom. Mirrors the v2_library_* + native // dialog flow Tauri uses on artist portraits + album covers. diff --git a/crates/qbz-slint/src/musician.rs b/crates/qbz-slint/src/musician.rs new file mode 100644 index 000000000..a0cca2604 --- /dev/null +++ b/crates/qbz-slint/src/musician.rs @@ -0,0 +1,206 @@ +//! MusicianPageView controller — loads the resolved musician + the +//! "Appears On" album grid and pushes them into `MusicianState`. +//! +//! Mirrors the Tauri MusicianPageView.svelte flow: +//! 1. Resolve the (name, role) via QbzCore::musicbrainz_resolve_musician. +//! 2. Fetch the first page of appearances +//! (QbzCore::musicbrainz_get_musician_appearances). +//! 3. Subsequent pages come from the MusicianActions::load-more +//! callback the view emits at the bottom of the grid. + +use std::sync::Arc; + +use qbz_app::shell::AppRuntime; +use qbz_core::FrontendAdapter; +use qbz_integrations::musicbrainz::MusicianConfidence; +use slint::{ComponentHandle, Model, ModelRc, VecModel}; + +use crate::artwork::{ArtworkJob, ArtworkTarget}; +use crate::{AppWindow, MusicianAppearanceItem, MusicianState}; + +/// Page size — kept in sync with the Tauri view's ITEMS_PER_PAGE. +pub const PAGE_SIZE: u32 = 20; + +/// Resolved-musician metadata + the current page bookkeeping. Plain +/// `Send` so the load step can run on a worker. +pub struct MusicianData { + pub name: String, + pub role: String, + pub confidence: MusicianConfidence, + pub appearances: Vec, + pub total: usize, + pub offset: u32, +} + +#[derive(Clone)] +pub struct AppearanceData { + pub album_id: String, + pub album_title: String, + pub artist_name: String, + pub year: String, + pub role_on_album: String, + pub artwork_url: String, +} + +/// Resolve the musician + fetch the first page of appearances. +pub async fn load_musician( + runtime: &Arc>, + name: &str, + role: &str, +) -> Result +where + A: FrontendAdapter + Send + Sync + 'static, +{ + let resolved = runtime + .core() + .musicbrainz_resolve_musician(name, role) + .await + .map_err(|e| e.to_string())?; + + let page = runtime + .core() + .musicbrainz_get_musician_appearances(name, role, PAGE_SIZE, 0) + .await + .map_err(|e| e.to_string())?; + + let appearances: Vec = page + .albums + .into_iter() + .map(|a| AppearanceData { + album_id: a.album_id, + album_title: a.album_title, + artist_name: a.artist_name, + year: a.year.unwrap_or_default(), + role_on_album: a.role_on_album, + artwork_url: a.album_artwork, + }) + .collect(); + let count = appearances.len() as u32; + + Ok(MusicianData { + name: resolved.name, + role: resolved.role, + confidence: resolved.confidence, + appearances, + total: page.total, + offset: count, + }) +} + +/// Fetch one more page of appearances, append to the current list. +pub async fn load_more_appearances( + runtime: &Arc>, + name: &str, + role: &str, + offset: u32, +) -> Result<(Vec, usize), String> +where + A: FrontendAdapter + Send + Sync + 'static, +{ + let page = runtime + .core() + .musicbrainz_get_musician_appearances(name, role, PAGE_SIZE, offset) + .await + .map_err(|e| e.to_string())?; + let appearances = page + .albums + .into_iter() + .map(|a| AppearanceData { + album_id: a.album_id, + album_title: a.album_title, + artist_name: a.artist_name, + year: a.year.unwrap_or_default(), + role_on_album: a.role_on_album, + artwork_url: a.album_artwork, + }) + .collect(); + Ok((appearances, page.total)) +} + +/// Apply the freshly loaded musician page to MusicianState. +pub fn apply_musician(window: &AppWindow, data: MusicianData) { + let items: Vec = data + .appearances + .into_iter() + .map(|a| MusicianAppearanceItem { + album_id: a.album_id.into(), + album_title: a.album_title.into(), + artist_name: a.artist_name.into(), + year: a.year.into(), + role_on_album: a.role_on_album.into(), + artwork_url: a.artwork_url.into(), + artwork: slint::Image::default(), + }) + .collect(); + let state = window.global::(); + state.set_name(data.name.into()); + state.set_role(data.role.into()); + state.set_confidence(confidence_label(data.confidence).into()); + state.set_appearances(ModelRc::new(VecModel::from(items))); + state.set_total(data.total as i32); + state.set_loading(false); +} + +/// Append a freshly fetched page of appearances onto the existing +/// model. Called by the MusicianActions::load-more handler. +pub fn append_appearances( + window: &AppWindow, + appearances: Vec, + total: usize, +) { + let state = window.global::(); + let model = state.get_appearances(); + let mut combined: Vec = (0..model.row_count()) + .filter_map(|i| model.row_data(i)) + .collect(); + for a in appearances { + combined.push(MusicianAppearanceItem { + album_id: a.album_id.into(), + album_title: a.album_title.into(), + artist_name: a.artist_name.into(), + year: a.year.into(), + role_on_album: a.role_on_album.into(), + artwork_url: a.artwork_url.into(), + artwork: slint::Image::default(), + }); + } + state.set_appearances(ModelRc::new(VecModel::from(combined))); + state.set_total(total as i32); + state.set_load_more_loading(false); +} + +pub fn reset_musician(window: &AppWindow) { + let state = window.global::(); + state.set_name("".into()); + state.set_role("".into()); + state.set_confidence("".into()); + state.set_appearances(ModelRc::new(VecModel::from( + Vec::::new(), + ))); + state.set_total(0); + state.set_loading(true); + state.set_load_more_loading(false); +} + +/// Artwork download jobs for the appearance grid — same pipeline +/// the Discover album cards use, so covers fill in progressively. +pub fn artwork_jobs(data: &MusicianData) -> Vec { + data.appearances + .iter() + .enumerate() + .filter(|(_, a)| !a.artwork_url.is_empty()) + .map(|(i, a)| ArtworkJob { + url: a.artwork_url.clone(), + target: ArtworkTarget::MusicianAppearance { index: i }, + }) + .collect() +} + +fn confidence_label(c: MusicianConfidence) -> &'static str { + match c { + MusicianConfidence::Confirmed => "confirmed", + MusicianConfidence::Contextual => "contextual", + MusicianConfidence::Weak => "weak", + MusicianConfidence::None => "none", + } +} diff --git a/crates/qbz-slint/src/nav.rs b/crates/qbz-slint/src/nav.rs index 9bee8d2c7..c73b82d82 100644 --- a/crates/qbz-slint/src/nav.rs +++ b/crates/qbz-slint/src/nav.rs @@ -18,6 +18,14 @@ pub enum NavEntry { Settings, /// A search results page; the string is the query. Search(String), + /// MusicianPageView — opened by the artist network sidebar when + /// the resolved musician does not have a confident Qobuz artist + /// match. Carries the musician name + the role for the + /// appearances query. + Musician { + name: String, + role: String, + }, } struct History { diff --git a/crates/qbz-slint/ui/app.slint b/crates/qbz-slint/ui/app.slint index 25c0d7fb6..843bd9ffc 100644 --- a/crates/qbz-slint/ui/app.slint +++ b/crates/qbz-slint/ui/app.slint @@ -17,7 +17,7 @@ import { LoginScreen } from "login/LoginScreen.slint"; import { AppShell } from "shell/AppShell.slint"; // Re-export the state globals so the Rust layer can populate them. -export { HomeState, AlbumState, ArtistState, NavState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions } from "state.slint"; +export { HomeState, AlbumState, ArtistState, NavState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions } 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`. diff --git a/crates/qbz-slint/ui/musician/MusicianPageView.slint b/crates/qbz-slint/ui/musician/MusicianPageView.slint new file mode 100644 index 000000000..f7489cb25 --- /dev/null +++ b/crates/qbz-slint/ui/musician/MusicianPageView.slint @@ -0,0 +1,269 @@ +// MusicianPageView — full page view opened from the artist network +// sidebar when a relationship row resolves with Contextual / Weak +// confidence (no exact Qobuz artist match). Mirrors Tauri's +// MusicianPageView.svelte: a small header (avatar + name + role) +// followed by Bands & Projects (when known) and the "Appears On" +// album grid with paginated load-more. + +import { Theme } from "../foundation/semantic-colors.slint"; +import { Typography } from "../foundation/typography.slint"; +import { Radius } from "../foundation/radius.slint"; +import { + MusicianState, + MusicianActions, + MusicianAppearanceItem, +} from "../state.slint"; +import { QbzIcon } from "../primitives/QbzIcon.slint"; +import { LoadingSpinner } from "../primitives/LoadingSpinner.slint"; +import { NavButtons } from "../shell/NavButtons.slint"; + +component AppearanceCard inherits Rectangle { + in property item; + callback clicked(string /* album-id */); + + width: 200px; + height: 270px; + + VerticalLayout { + spacing: 6px; + Rectangle { + width: 200px; + height: 200px; + border-radius: Radius.sm; + background: Theme.surface-elevated; + drop-shadow-blur: 18px; + drop-shadow-color: #00000060; + drop-shadow-offset-y: 6px; + clip: true; + Image { + width: 100%; + height: 100%; + source: root.item.artwork; + image-fit: cover; + } + TouchArea { + mouse-cursor: pointer; + clicked => { + root.clicked(root.item.album-id); + } + } + } + Text { + text: root.item.album-title; + color: Theme.text-primary; + font-size: Typography.body; + font-weight: Typography.medium; + overflow: elide; + width: 200px; + } + Text { + text: root.item.artist-name; + color: Theme.text-muted; + font-size: Typography.legal; + overflow: elide; + width: 200px; + } + HorizontalLayout { + spacing: 8px; + if root.item.year != "": Text { + text: root.item.year; + color: Theme.text-muted; + font-size: Typography.legal; + } + if root.item.role-on-album != "": Text { + text: root.item.role-on-album; + color: Theme.text-secondary; + font-size: Typography.legal; + font-weight: Typography.medium; + } + } + } +} + +export component MusicianPageView inherits Rectangle { + callback open-album(string); + + property card-width: 200px; + property card-height: 270px; + property card-gap: 24px; + + background: Theme.surface-main; + + Flickable { + viewport-width: self.width; + viewport-height: page.preferred-height; + + page := VerticalLayout { + width: parent.width; + padding-left: 32px; + padding-right: 32px; + padding-top: 11px; + padding-bottom: 100px; + spacing: 0px; + alignment: start; + + HorizontalLayout { + alignment: start; + NavButtons { } + } + + Rectangle { height: 22px; } + + // --- Musician header --------------------------------------- + HorizontalLayout { + spacing: 16px; + alignment: start; + Rectangle { + width: 56px; + height: 56px; + border-radius: 28px; + background: Theme.surface-elevated; + QbzIcon { + source: @image-url("../assets/icons/user.svg"); + width: 28px; + height: 28px; + x: (parent.width - self.width) / 2; + y: (parent.height - self.height) / 2; + tint: Theme.text-muted; + } + } + VerticalLayout { + alignment: center; + spacing: 2px; + Text { + text: MusicianState.name; + color: Theme.text-primary; + font-size: Typography.title; + font-weight: Typography.bold; + } + Text { + text: MusicianState.role; + color: Theme.text-muted; + font-size: Typography.body; + } + } + } + + Rectangle { height: 32px; } + + // --- Bands & Projects (chips) ------------------------------ + if MusicianState.bands.length > 0: VerticalLayout { + spacing: 10px; + Text { + text: @tr("Bands & Projects"); + color: Theme.text-primary; + font-size: Typography.heading; + font-weight: Typography.semibold; + } + HorizontalLayout { + spacing: 8px; + alignment: start; + for band in MusicianState.bands: Rectangle { + height: 32px; + border-radius: Radius.sm; + background: Theme.surface-card; + HorizontalLayout { + padding-left: 10px; + padding-right: 10px; + spacing: 8px; + VerticalLayout { + alignment: center; + QbzIcon { + source: @image-url("../assets/icons/music.svg"); + width: 14px; + height: 14px; + tint: Theme.text-muted; + } + } + Text { + text: band; + color: Theme.text-secondary; + font-size: Typography.body; + vertical-alignment: center; + } + } + } + } + Rectangle { height: 24px; } + } + + // --- Appears On -------------------------------------------- + HorizontalLayout { + spacing: 8px; + Text { + text: @tr("Appears On"); + color: Theme.text-primary; + font-size: Typography.heading; + font-weight: Typography.semibold; + vertical-alignment: center; + } + if MusicianState.total > 0: Text { + text: "(" + MusicianState.total + ")"; + color: Theme.text-muted; + font-size: Typography.body; + vertical-alignment: center; + } + } + Rectangle { height: 14px; } + + if MusicianState.loading + && MusicianState.appearances.length == 0: HorizontalLayout { + alignment: center; + LoadingSpinner { size: 36px; } + } + if !MusicianState.loading + && MusicianState.appearances.length == 0: Text { + text: @tr("No album appearances found."); + color: Theme.text-muted; + font-size: Typography.body; + } + + if MusicianState.appearances.length > 0: appearances-grid := Rectangle { + property columns: Math.max( + 1, + Math.floor((self.width + root.card-gap) / (root.card-width + root.card-gap))); + property rows: Math.ceil(MusicianState.appearances.length / self.columns); + height: self.rows > 0 + ? self.rows * root.card-height + + Math.max(0, self.rows - 1) * root.card-gap + : 0px; + for item[i] in MusicianState.appearances: AppearanceCard { + x: Math.mod(i, appearances-grid.columns) * (root.card-width + root.card-gap); + y: Math.floor(i / appearances-grid.columns) * (root.card-height + root.card-gap); + item: item; + clicked(id) => { + root.open-album(id); + } + } + } + + if MusicianState.appearances.length > 0 + && MusicianState.appearances.length < MusicianState.total: + HorizontalLayout { + alignment: center; + Rectangle { + width: load-more-text.preferred-width + 24px; + height: 32px; + load-more-text := Text { + text: MusicianState.load-more-loading + ? @tr("Loading…") + : @tr("Load more"); + color: load-more-ta.has-hover + ? Theme.text-primary + : Theme.text-secondary; + font-size: 13px; + x: (parent.width - self.width) / 2; + y: (parent.height - self.height) / 2; + } + load-more-ta := TouchArea { + mouse-cursor: pointer; + enabled: !MusicianState.load-more-loading; + clicked => { + MusicianActions.load-more(); + } + } + } + } + } + } +} diff --git a/crates/qbz-slint/ui/shell/AppShell.slint b/crates/qbz-slint/ui/shell/AppShell.slint index cebd2740a..16107eb25 100644 --- a/crates/qbz-slint/ui/shell/AppShell.slint +++ b/crates/qbz-slint/ui/shell/AppShell.slint @@ -16,6 +16,7 @@ import { LyricsSidebar } from "LyricsSidebar.slint"; import { HomeView } from "../discover/HomeView.slint"; import { AlbumPageView } from "../album/AlbumPageView.slint"; import { ArtistPageView } from "../artist/ArtistPageView.slint"; +import { MusicianPageView } from "../musician/MusicianPageView.slint"; import { SettingsView } from "../settings/SettingsView.slint"; import { SearchResultsView } from "../search/SearchResultsView.slint"; @@ -94,6 +95,11 @@ export component AppShell inherits Rectangle { root.media-action(kind, id, action); } } + if NavState.view == ContentView.musician: MusicianPageView { + open-album(id) => { + root.open-album(id); + } + } if NavState.view == ContentView.settings: SettingsView { settings-bool(k, v) => { root.settings-bool(k, v); diff --git a/crates/qbz-slint/ui/state.slint b/crates/qbz-slint/ui/state.slint index e95de0748..713d22b60 100644 --- a/crates/qbz-slint/ui/state.slint +++ b/crates/qbz-slint/ui/state.slint @@ -94,7 +94,7 @@ export global AlbumActions { } // Which content view the shell shows. -export enum ContentView { home, album, artist, settings, search } +export enum ContentView { home, album, artist, settings, search, musician } // Settings screen state. Audio and Playback preferences are loaded from // the persistence stores by the Rust settings controller and pushed here; @@ -395,6 +395,44 @@ export global NetworkSidebarActions { callback toggle(); } +// One row of MusicianPageView's "Appears On" grid — same shape as +// the album cards on Discover, plus a role label stamped onto each +// album by the Qobuz search wrapping (e.g. "Drums" / "Guitar"). +export struct MusicianAppearanceItem { + album-id: string, + album-title: string, + artist-name: string, + year: string, + role-on-album: string, + artwork-url: string, + artwork: image, +} + +// MusicianPageView state — opened by the artist network sidebar +// when a relationship row is clicked and the musician has no +// confident Qobuz artist match. Populated by `crate::musician` +// from the resolve + appearances backend calls. +export global MusicianState { + in property name; + in property role; + // "confirmed" | "contextual" | "weak" | "none" — the sidebar + // uses this to skip MusicianPageView entirely on Confirmed and + // navigate to the matched artist instead. + in property confidence; + // Bands / projects from MusicBrainz; not yet populated but + // kept in the data shape so the section renders cleanly when + // wired. + in property <[string]> bands: []; + in property <[MusicianAppearanceItem]> appearances: []; + in property total: 0; + in property loading: false; + in property load-more-loading: false; +} + +export global MusicianActions { + callback load-more(); +} + // Shell chrome state — collapsible left sidebar and right-side panels. // Globals are imported directly by the shell components, so toggles // need no callback plumbing.