diff --git a/crates/qbz-slint/src/blacklist_manager.rs b/crates/qbz-slint/src/blacklist_manager.rs new file mode 100644 index 000000000..c8c75db9e --- /dev/null +++ b/crates/qbz-slint/src/blacklist_manager.rs @@ -0,0 +1,170 @@ +//! Blacklist Manager controller — the Rust side of the Slint port of Tauri's +//! BlacklistManagerView (Task 11). Loads the per-user blacklist into +//! `BlacklistState`, applies search-as-you-type filtering controller-side, and +//! runs the toggle / remove / clear mutations against the +//! `crate::artist_blacklist` wrapper (the same fail-open singleton the artist +//! toggle in T9 mutates). +//! +//! Mirrors `crate::offline_manager`'s shape: a `load` entry point invoked on +//! navigation + an action set wired in `main.rs`. There is no change-notify on +//! the blacklist store (the fav_cache pattern), so the manager reloads on every +//! `open` — a mutation from elsewhere (the T9 artist toggle) is reflected the +//! next time the manager is opened, and the manager's own mutations re-push the +//! filtered list in place. +//! +//! Search filter (Tauri parity §7): trim the query; empty → the full list; +//! else a case-insensitive substring match on `artist_name` ONLY (notes are not +//! searched), preserving the backend's name-sorted order. `count` always +//! carries the FULL list length so the view can tell "empty blacklist" +//! (count==0) from "no search results" (count>0, filtered list empty). +//! +//! Date: `added_at` is unix SECONDS; formatted controller-side to "MMM D, YYYY" +//! (English; the Slint build has no gettext for Rust strings — matches T9 +//! toasts being `format!` English). + +use std::sync::Mutex as StdMutex; + +use chrono::{DateTime, Utc}; +use slint::{ComponentHandle, ModelRc, SharedString, VecModel}; + +use crate::{AppWindow, BlacklistState, BlacklistedArtistItem}; + +/// The live search query (Rust-side source of truth). The view echoes it back +/// from `BlacklistState.search-query`; this is what `refilter` reads so a +/// toggle/remove/clear re-push keeps the current filter applied. +static QUERY: StdMutex = StdMutex::new(String::new()); + +fn current_query() -> String { + QUERY.lock().map(|q| q.clone()).unwrap_or_default() +} + +fn set_query(q: String) { + if let Ok(mut guard) = QUERY.lock() { + *guard = q; + } +} + +/// Format a unix-seconds timestamp as "MMM D, YYYY" (English). Falls back to an +/// empty string for a non-representable value. +fn format_added(secs: i64) -> String { + DateTime::::from_timestamp(secs, 0) + .map(|dt| dt.format("%b %-d, %Y").to_string()) + .unwrap_or_default() +} + +/// Build the visible (filtered) `BlacklistedArtistItem`s from the full +/// name-sorted snapshot, applying the current query. +fn build_items() -> (Vec, i32) { + let all = crate::artist_blacklist::get_all(); + let count = all.len() as i32; + let query = current_query(); + let needle = query.trim().to_lowercase(); + + let items: Vec = all + .into_iter() + .filter(|a| needle.is_empty() || a.artist_name.to_lowercase().contains(&needle)) + .map(|a| { + let notes = a.notes.clone().unwrap_or_default(); + BlacklistedArtistItem { + // artist_id is u64; an int holds Qobuz ids comfortably for + // display + passing back on click/remove (matches OfflineRow + // carrying ids as strings — here the spec uses int). + artist_id: a.artist_id as i32, + artist_name: a.artist_name.into(), + added_at: a.added_at as i32, + added_display: format_added(a.added_at).into(), + has_notes: !notes.is_empty(), + notes: notes.into(), + } + }) + .collect(); + + (items, count) +} + +/// Push the filtered items + full count + enabled flag + query into Slint. +fn push(w: &AppWindow) { + let (items, count) = build_items(); + let st = w.global::(); + st.set_items(ModelRc::new(VecModel::from(items))); + st.set_count(count); + st.set_enabled(crate::artist_blacklist::is_enabled()); + st.set_search_query(SharedString::from(current_query())); +} + +/// Load (or refresh) the manager: mark loading, read the store, push state, +/// clear loading. Synchronous — the wrapper reads are in-memory / a single +/// SQLite query, so there is no worker hop (unlike the offline manager's +/// index scan). +pub fn load(weak: slint::Weak) { + let _ = weak.upgrade_in_event_loop(|w| { + w.global::().set_loading(true); + push(&w); + w.global::().set_loading(false); + }); +} + +// --- Actions ------------------------------------------------------------ + +/// Search-as-you-type: store the query and re-push the filtered list. `count` +/// stays the full length (so the empty-vs-no-results split stays correct). +pub fn search_changed(w: &AppWindow, query: String) { + set_query(query); + push(w); +} + +/// Toggle the global enable flag; on success re-read + re-push and info-toast. +/// On error, surface the wrapper's message (no state change). +pub fn toggle_enabled(w: &AppWindow) { + let new_state = !crate::artist_blacklist::is_enabled(); + match crate::artist_blacklist::set_enabled(new_state) { + Ok(()) => { + push(w); + let msg = if new_state { + "Blacklist enabled" + } else { + "Blacklist disabled" + }; + crate::toast::info(w, msg); + } + Err(e) => { + log::error!("[qbz-slint] blacklist toggle-enabled failed: {e}"); + crate::toast::error(w, "Failed to toggle blacklist"); + } + } +} + +/// Remove one artist (optimistic — re-push drops the row immediately) + toast. +pub fn remove(w: &AppWindow, artist_id: i32) { + // Capture the name before removing, for the toast. + let name = crate::artist_blacklist::get_all() + .into_iter() + .find(|a| a.artist_id == artist_id as u64) + .map(|a| a.artist_name) + .unwrap_or_else(|| "Artist".to_string()); + match crate::artist_blacklist::remove(artist_id as u64) { + Ok(()) => { + push(w); + crate::toast::success(w, format!("{name} removed from blacklist")); + } + Err(e) => { + log::error!("[qbz-slint] blacklist remove failed: {e}"); + crate::toast::error(w, "Failed to remove artist"); + } + } +} + +/// Clear every blacklisted artist + toast (the count is captured before). +pub fn clear_all(w: &AppWindow) { + let count = crate::artist_blacklist::count(); + match crate::artist_blacklist::clear_all() { + Ok(()) => { + push(w); + crate::toast::success(w, format!("Removed {count} artists from blacklist")); + } + Err(e) => { + log::error!("[qbz-slint] blacklist clear-all failed: {e}"); + crate::toast::error(w, "Failed to clear blacklist"); + } + } +} diff --git a/crates/qbz-slint/src/main.rs b/crates/qbz-slint/src/main.rs index 852ce02f0..bec6c485f 100644 --- a/crates/qbz-slint/src/main.rs +++ b/crates/qbz-slint/src/main.rs @@ -21,6 +21,7 @@ mod artist; mod artist_blacklist; mod artwork; mod auth; +mod blacklist_manager; mod commands; mod custom_artwork; mod dates; @@ -1197,6 +1198,7 @@ fn scope_for(entry: &nav::NavEntry) -> String { nav::NavEntry::Playlist(_) => "playlist".into(), nav::NavEntry::PlaylistManager => "playlist-manager".into(), nav::NavEntry::OfflineManager => "offline-manager".into(), + nav::NavEntry::BlacklistManager => "blacklist-manager".into(), nav::NavEntry::Mixtapes => "mixtapes".into(), nav::NavEntry::Collections => "collections".into(), nav::NavEntry::MixtapeDetail(_) => "mixtape-detail".into(), @@ -1346,6 +1348,13 @@ fn apply_entry( }); offline_manager::load(w2, handle.clone()); } + nav::NavEntry::BlacklistManager => { + let w2 = weak.clone(); + let _ = weak.upgrade_in_event_loop(|w| { + w.global::().set_view(ContentView::BlacklistManager); + }); + blacklist_manager::load(w2); + } nav::NavEntry::Mixtapes => { myqbz::navigate( weak.clone(), @@ -7695,6 +7704,108 @@ fn main() -> Result<(), Box> { }); } + // Artist Blacklist Manager actions (Task 11). Mutations are synchronous + // (in-memory set + single SQLite ops via the artist_blacklist wrapper), so + // no tokio handle is needed; each callback runs on the event-loop thread. + { + // open() — the forward-open seam (T10's Settings content-filtering row + // calls this). Records the nav entry, swaps the view, then loads the + // blacklist. Mirrors OfflineManagerActions.on_open. + let weak = window.as_weak(); + window.global::().on_open(move || { + nav::record(nav::NavEntry::BlacklistManager); + if let Some(w) = weak.upgrade() { + w.global::() + .set_view(ContentView::BlacklistManager); + update_nav_flags(&w); + } + blacklist_manager::load(weak.clone()); + }); + } + { + // back() — declared per the spec; the actual back chrome is the shared + // header NavButtons (which drives nav::go_back). Wired here for any + // future in-view trigger; routes through the same go-back path. + let weak = window.as_weak(); + let app_runtime_bl = app_runtime.clone(); + let bl_handle = tokio_rt.handle().clone(); + let image_cache_bl = image_cache.clone(); + window.global::().on_back(move || { + if let Some((entry, scroll)) = nav::go_back() { + let weak2 = weak.clone(); + arm_scroll_restore(&weak2, &entry, scroll); + apply_entry( + entry, + &app_runtime_bl, + &weak2, + &bl_handle, + &image_cache_bl, + ); + if let Some(w) = weak.upgrade() { + update_nav_flags(&w); + } + } + }); + } + { + let weak = window.as_weak(); + let bl_runtime_a = app_runtime.clone(); + let bl_handle_a = tokio_rt.handle().clone(); + let bl_image_cache_a = image_cache.clone(); + window + .global::() + .on_artist_select(move |id| { + let artist_id = id.to_string(); + nav::record(nav::NavEntry::Artist(artist_id.clone())); + navigate_artist( + bl_runtime_a.clone(), + weak.clone(), + &bl_handle_a, + bl_image_cache_a.clone(), + artist_id, + ); + if let Some(w) = weak.upgrade() { + update_nav_flags(&w); + } + }); + } + { + let weak = window.as_weak(); + window + .global::() + .on_toggle_enabled(move || { + if let Some(w) = weak.upgrade() { + blacklist_manager::toggle_enabled(&w); + } + }); + } + { + let weak = window.as_weak(); + window.global::().on_remove(move |id| { + if let Some(w) = weak.upgrade() { + blacklist_manager::remove(&w, id); + } + }); + } + { + let weak = window.as_weak(); + window.global::().on_clear_all(move || { + if let Some(w) = weak.upgrade() { + blacklist_manager::clear_all(&w); + } + }); + } + { + let weak = window.as_weak(); + window + .global::() + .on_search_changed(move |q| { + if let Some(w) = weak.upgrade() { + blacklist_manager::search_changed(&w, q.to_string()); + } + }); + } + // Offline Cache Manager actions. { let runtime = app_runtime.clone(); diff --git a/crates/qbz-slint/src/nav.rs b/crates/qbz-slint/src/nav.rs index 1f76a162c..073efda42 100644 --- a/crates/qbz-slint/src/nav.rs +++ b/crates/qbz-slint/src/nav.rs @@ -59,6 +59,10 @@ pub enum NavEntry { /// The Offline Cache Manager — the manage-downloads surface (Tauri's /// OfflineCacheManagerView). Session-scoped; no payload. OfflineManager, + /// The Artist Blacklist Manager — the manage-blacklist surface (Tauri's + /// BlacklistManagerView). Reached from the Settings content-filtering row. + /// Session-scoped (the search query lives in the controller); no payload. + BlacklistManager, /// The My QBZ > Mixtapes index grid (read-only in this slice). Toolbar /// state (sort/view/search) is session-scoped in the controller, so the /// entry carries no payload. diff --git a/crates/qbz-slint/ui/app.slint b/crates/qbz-slint/ui/app.slint index be90e9bc3..cc4304691 100644 --- a/crates/qbz-slint/ui/app.slint +++ b/crates/qbz-slint/ui/app.slint @@ -19,7 +19,7 @@ import { Toast } from "primitives/Toast.slint"; import { ShellState } from "state.slint"; // Re-export the state globals so the Rust layer can populate them. -export { HomeState, HomeActions, DiscoverState, DiscoverActions, SectionDescriptor, ConfigRow, DiscoverBrowseState, DiscoverBrowseActions, ForYouState, MixState, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, ShellState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, LyricsState, LyricsLineItem, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions, PlaylistPickerState, PlaylistPickerActions, DuplicateConfirmState, DuplicateConfirmActions, PlaylistState, PlaylistActions, SidebarState, SidebarActions, SidebarFolderPopupState, CreatePlaylistState, CreatePlaylistActions, EditPlaylistState, EditPlaylistActions, CreateFolderState, CreateFolderActions, MyQbzCreateState, MyQbzCreateActions, DragState, DragActions, PlaylistManagerState, PlaylistManagerActions, OfflineManagerState, OfflineManagerActions, MyQbzState, MyQbzActions, MixtapeCardItem, MyQbzAddState, MyQbzAddActions, MyQbzAddRow, MyQbzDetailState, MyQbzDetailActions, MixtapeDetailItem, MyQbzEditState, MyQbzEditActions, MyQbzMixState, MyQbzMixActions, DiscoBuilderState, DiscoBuilderActions, DiscoGroup, DiscoCandidate, LocalLibraryState, LocalLibraryActions, LibraryFoldersState, LibFolderEditState, LibraryManageActions, LibraryScanState, LibAlbumFilterState, LocalAlbumState, LocalAlbumActions, TagEditorState, TagEditorActions, FolderEditState, FolderEditActions, ToastState, TextUtil, QconnectDevState, QconnectDevice, AppearanceState, MyQbzBrandingState, EphemeralPlayChoiceState, EphemeralPlayChoiceActions, PlexSettingsState, PlexAuthActions, PlexSectionItem, ScrobbleState, ScrobbleActions, OfflineState, OfflineModeActions, OfflineFavoritesState, OfflineFavoritesActions, ImportLogEntry, PlaylistImportState, PlaylistImportActions, DacWizardState, DacWizardActions, DacCandidateRow, RemediationRow, DacConfigRow, InfoCreditRow, InfoCreditPair, AlbumCreditPerformer, AlbumCreditTrack, TrackInfoState, TrackInfoActions, AlbumInfoState, AlbumInfoActions, VisualizerState, ImmersiveState } from "state.slint"; +export { HomeState, HomeActions, DiscoverState, DiscoverActions, SectionDescriptor, ConfigRow, DiscoverBrowseState, DiscoverBrowseActions, ForYouState, MixState, GenreFilterState, GenreFilterActions, AlbumState, ArtistState, NavState, ShellState, SessionState, SettingsState, AlbumActions, ArtistActions, ArtworkActions, NowPlayingState, QueueState, LyricsState, LyricsLineItem, SearchState, SearchActions, NetworkSidebarState, NetworkSidebarActions, MusicianState, MusicianActions, LabelState, LabelActions, LocationViewState, LocationViewActions, FavoritesState, FavoritesActions, PlaylistPickerState, PlaylistPickerActions, DuplicateConfirmState, DuplicateConfirmActions, PlaylistState, PlaylistActions, SidebarState, SidebarActions, SidebarFolderPopupState, CreatePlaylistState, CreatePlaylistActions, EditPlaylistState, EditPlaylistActions, CreateFolderState, CreateFolderActions, MyQbzCreateState, MyQbzCreateActions, DragState, DragActions, PlaylistManagerState, PlaylistManagerActions, OfflineManagerState, OfflineManagerActions, BlacklistState, BlacklistActions, BlacklistedArtistItem, MyQbzState, MyQbzActions, MixtapeCardItem, MyQbzAddState, MyQbzAddActions, MyQbzAddRow, MyQbzDetailState, MyQbzDetailActions, MixtapeDetailItem, MyQbzEditState, MyQbzEditActions, MyQbzMixState, MyQbzMixActions, DiscoBuilderState, DiscoBuilderActions, DiscoGroup, DiscoCandidate, LocalLibraryState, LocalLibraryActions, LibraryFoldersState, LibFolderEditState, LibraryManageActions, LibraryScanState, LibAlbumFilterState, LocalAlbumState, LocalAlbumActions, TagEditorState, TagEditorActions, FolderEditState, FolderEditActions, ToastState, TextUtil, QconnectDevState, QconnectDevice, AppearanceState, MyQbzBrandingState, EphemeralPlayChoiceState, EphemeralPlayChoiceActions, PlexSettingsState, PlexAuthActions, PlexSectionItem, ScrobbleState, ScrobbleActions, OfflineState, OfflineModeActions, OfflineFavoritesState, OfflineFavoritesActions, ImportLogEntry, PlaylistImportState, PlaylistImportActions, DacWizardState, DacWizardActions, DacCandidateRow, RemediationRow, DacConfigRow, InfoCreditRow, InfoCreditPair, AlbumCreditPerformer, AlbumCreditTrack, TrackInfoState, TrackInfoActions, AlbumInfoState, AlbumInfoActions, VisualizerState, ImmersiveState } 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/settings/BlacklistManagerView.slint b/crates/qbz-slint/ui/settings/BlacklistManagerView.slint new file mode 100644 index 000000000..446b6b7f9 --- /dev/null +++ b/crates/qbz-slint/ui/settings/BlacklistManagerView.slint @@ -0,0 +1,581 @@ +// Artist Blacklist Manager — a faithful Slint port of Tauri's +// BlacklistManagerView.svelte (consolidated review §7). The standalone +// manage-blacklist surface reached from the Settings content-filtering row: +// a header (Back + ban icon + title), a description line, a controls row +// (enable/disable toggle / search-as-you-type with × clear / Clear-All / +// total-count badge), an amber disabled-warning banner, and a 4-branch body +// (loading / empty / no-search-results / list), plus a Clear-All confirm +// modal overlaid above everything (ADR-009 — declared last so it stacks on +// top; the manager itself has no other overlay). +// +// State + actions live in BlacklistState / BlacklistActions; the controller +// (crate::blacklist_manager) precomputes the date string + has-notes flag and +// pushes ONLY the search-filtered rows into `items`, while `count` stays the +// FULL list count — so "empty" = count==0 and "no results" = count>0 with an +// empty `items`. Rows show a generic blind-eye glyph (no artist image exists), +// the name, "Added {date}", optional italic notes, and a per-row remove X +// (optimistic, no confirm). The blacklist visual across the Slint port is +// `blind-eye.svg` (TrackRow + ArtistPageView, T5/T9), used here too instead of +// Tauri's lucide `Ban`. + +import { ScrollView } from "std-widgets.slint"; +import { Theme } from "../foundation/semantic-colors.slint"; +import { Typography } from "../foundation/typography.slint"; +import { Radius } from "../foundation/radius.slint"; +import { BlacklistState, BlacklistActions } from "../state.slint"; +import { QbzIcon } from "../primitives/QbzIcon.slint"; +import { LoadingSpinner } from "../primitives/LoadingSpinner.slint"; +import { NavButtons } from "../shell/NavButtons.slint"; + +// One blacklisted-artist row. +component ArtistRow inherits Rectangle { + in property artist-name; + in property added-display; + in property notes; + in property has-notes; + callback select(); + callback remove(); + height: 64px; + border-radius: Radius.md; + background: ta.has-hover ? Theme.surface-elevated : Theme.surface-card; + + HorizontalLayout { + padding-left: 16px; + padding-right: 8px; + spacing: 12px; + + // Clickable artist-info region — opens the artist page. + Rectangle { + horizontal-stretch: 1; + ta := TouchArea { + mouse-cursor: pointer; + clicked => { + root.select(); + } + } + HorizontalLayout { + spacing: 12px; + // Generic blind-eye avatar (no artist image data exists). + VerticalLayout { + alignment: center; + Rectangle { + width: 44px; + height: 44px; + border-radius: 22px; + background: Theme.surface-elevated; + QbzIcon { + source: @image-url("../assets/icons/blind-eye.svg"); + width: 20px; + height: 20px; + x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; + y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; + tint: Theme.text-muted; + } + } + } + // Name + meta (+ optional notes). + VerticalLayout { + alignment: center; + spacing: 2px; + Text { + text: root.artist-name; + color: Theme.text-primary; + font-size: Typography.body; + font-weight: Typography.medium; + overflow: elide; + } + Text { + text: @tr("Added {}", root.added-display); + color: Theme.text-muted; + font-size: Typography.legal; + overflow: elide; + } + if root.has-notes: Text { + text: root.notes; + color: Theme.text-muted; + font-size: Typography.legal; + font-italic: true; + overflow: elide; + } + } + } + } + + // Per-row remove (optimistic, no confirm). + VerticalLayout { + alignment: center; + Rectangle { + width: 36px; + height: 36px; + border-radius: Radius.sm; + background: rm-ta.has-hover ? #ef444426 : transparent; + QbzIcon { + source: @image-url("../assets/icons/x.svg"); + width: 18px; + height: 18px; + x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; + y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; + tint: rm-ta.has-hover ? #ef4444 : Theme.text-muted; + } + rm-ta := TouchArea { + mouse-cursor: pointer; + clicked => { + root.remove(); + } + } + } + } + } +} + +export component BlacklistManagerView inherits Rectangle { + background: Theme.surface-main; + + // Local modal flag (Clear-All confirmation). Lives in the view; the + // confirm only fires BlacklistActions.clear-all on the danger button. + property confirm-clear-open: false; + + VerticalLayout { + padding: 24px; + spacing: 14px; + + // Top bar — Back (ADR-004 via NavButtons; routes through nav history). + HorizontalLayout { + vertical-stretch: 0; + NavButtons { } + } + + // Header — blind-eye icon + title. + HorizontalLayout { + vertical-stretch: 0; + spacing: 12px; + VerticalLayout { + alignment: center; + QbzIcon { + source: @image-url("../assets/icons/blind-eye.svg"); + width: 24px; + height: 24px; + tint: Theme.text-muted; + } + } + VerticalLayout { + alignment: center; + Text { + text: @tr("Artist Blacklist"); + color: Theme.text-primary; + font-size: Typography.section; + font-weight: Typography.bold; + } + } + } + + // Description. + Text { + vertical-stretch: 0; + text: @tr("Blacklisted artists are hidden from search results, radio, suggestions, and similar artists."); + color: Theme.text-muted; + font-size: Typography.body; + wrap: word-wrap; + } + + // Controls row. + HorizontalLayout { + vertical-stretch: 0; + spacing: 12px; + + // Enable/Disable toggle. + Rectangle { + width: toggle-row.preferred-width + 28px; + height: 34px; + border-radius: Radius.sm; + background: toggle-ta.has-hover ? Theme.surface-hover : Theme.surface-elevated; + toggle-row := HorizontalLayout { + x: 14px; + width: self.preferred-width; + height: 100%; + spacing: 8px; + VerticalLayout { + alignment: center; + QbzIcon { + source: BlacklistState.enabled + ? @image-url("../assets/icons/eye.svg") + : @image-url("../assets/icons/eye-off.svg"); + width: 18px; + height: 18px; + tint: BlacklistState.enabled ? Theme.accent : Theme.text-muted; + } + } + VerticalLayout { + alignment: center; + Text { + text: BlacklistState.enabled ? @tr("Enabled") : @tr("Disabled"); + color: BlacklistState.enabled ? Theme.accent : Theme.text-muted; + font-size: Typography.legal; + vertical-alignment: center; + } + } + } + toggle-ta := TouchArea { + mouse-cursor: pointer; + clicked => { + BlacklistActions.toggle-enabled(); + } + } + } + + // Search input (search-as-you-type) + clear (×). + Rectangle { + width: 280px; + height: 34px; + border-radius: Radius.sm; + background: Theme.surface-elevated; + border-width: 1px; + border-color: search-in.has-focus ? Theme.accent : Theme.border-subtle; + HorizontalLayout { + padding-left: 10px; + padding-right: 6px; + spacing: 6px; + VerticalLayout { + alignment: center; + QbzIcon { + source: @image-url("../assets/icons/search.svg"); + width: 15px; + height: 15px; + tint: Theme.text-muted; + } + } + Rectangle { + horizontal-stretch: 1; + search-in := TextInput { + width: 100%; + height: 100%; + vertical-alignment: center; + color: Theme.text-primary; + font-size: Typography.legal; + text: BlacklistState.search-query; + // Search-as-you-type: every edit re-pushes the + // controller-filtered rows. No debounce (Tauri parity). + edited => { + BlacklistActions.search-changed(self.text); + } + } + } + if BlacklistState.search-query != "": VerticalLayout { + alignment: center; + Rectangle { + width: 24px; + height: 24px; + border-radius: Radius.sm; + background: clear-ta.has-hover ? Theme.surface-hover : transparent; + QbzIcon { + source: @image-url("../assets/icons/x.svg"); + width: 13px; + height: 13px; + x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; + y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; + tint: clear-ta.has-hover ? Theme.text-primary : Theme.text-muted; + } + clear-ta := TouchArea { + mouse-cursor: pointer; + clicked => { + search-in.text = ""; + BlacklistActions.search-changed(""); + } + } + } + } + } + } + + // Clear-All — only when there is something to clear (full count). + if BlacklistState.count > 0: Rectangle { + width: clear-all-row.preferred-width + 28px; + height: 34px; + border-radius: Radius.sm; + background: clear-all-ta.has-hover ? #ef444426 : Theme.surface-elevated; + clear-all-row := HorizontalLayout { + x: 14px; + width: self.preferred-width; + height: 100%; + spacing: 8px; + VerticalLayout { + alignment: center; + QbzIcon { + source: @image-url("../assets/icons/trash-2.svg"); + width: 16px; + height: 16px; + tint: #ef4444; + } + } + VerticalLayout { + alignment: center; + Text { + text: @tr("Clear All"); + color: #ef4444; + font-size: Typography.legal; + vertical-alignment: center; + } + } + } + clear-all-ta := TouchArea { + mouse-cursor: pointer; + clicked => { + root.confirm-clear-open = true; + } + } + } + + // Spacer + count badge (FULL count, right-aligned). + Rectangle { + horizontal-stretch: 1; + } + VerticalLayout { + alignment: center; + Text { + text: @tr("{} artists", BlacklistState.count); + color: Theme.text-muted; + font-size: Typography.legal; + horizontal-alignment: right; + } + } + } + + // Disabled warning banner. + if !BlacklistState.enabled: Rectangle { + vertical-stretch: 0; + height: warn-row.preferred-height + 24px; + border-radius: Radius.md; + background: #fbbf241a; + border-width: 1px; + border-color: #fbbf244d; + warn-row := HorizontalLayout { + padding: 12px; + spacing: 10px; + VerticalLayout { + alignment: center; + QbzIcon { + source: @image-url("../assets/icons/circle-alert.svg"); + width: 16px; + height: 16px; + tint: #fbbf24; + } + } + VerticalLayout { + alignment: center; + Text { + text: @tr("Blacklist filtering is disabled. Blacklisted artists are shown everywhere until you re-enable it."); + color: #fbbf24; + font-size: Typography.legal; + wrap: word-wrap; + } + } + } + } + + // Body — 4 mutually-exclusive branches (order is load-bearing). + Rectangle { + vertical-stretch: 1; + + // 1) Loading. + if BlacklistState.loading: VerticalLayout { + alignment: center; + HorizontalLayout { + alignment: center; + LoadingSpinner { } + } + HorizontalLayout { + alignment: center; + Text { + text: @tr("Loading blacklist…"); + color: Theme.text-muted; + font-size: Typography.body; + } + } + } + + // 2) Empty blacklist. + if !BlacklistState.loading && BlacklistState.count == 0: VerticalLayout { + alignment: center; + spacing: 12px; + HorizontalLayout { + alignment: center; + QbzIcon { + source: @image-url("../assets/icons/blind-eye.svg"); + width: 48px; + height: 48px; + tint: Theme.text-muted; + opacity: 0.3; + } + } + HorizontalLayout { + alignment: center; + Text { + text: @tr("No blacklisted artists"); + color: Theme.text-muted; + font-size: Typography.heading; + } + } + HorizontalLayout { + alignment: center; + Text { + text: @tr("To hide an artist, go to their page and use the menu."); + color: Theme.text-muted; + font-size: Typography.legal; + horizontal-alignment: center; + } + } + } + + // 3) No search results (full list non-empty, filtered empty). + if !BlacklistState.loading && BlacklistState.count > 0 && BlacklistState.items.length == 0: VerticalLayout { + alignment: center; + spacing: 12px; + HorizontalLayout { + alignment: center; + QbzIcon { + source: @image-url("../assets/icons/search.svg"); + width: 48px; + height: 48px; + tint: Theme.text-muted; + opacity: 0.3; + } + } + HorizontalLayout { + alignment: center; + Text { + text: @tr("No results for \"{}\"", BlacklistState.search-query); + color: Theme.text-muted; + font-size: Typography.heading; + } + } + } + + // 4) The list (no virtualization — plain for over the filtered rows). + if !BlacklistState.loading && BlacklistState.items.length > 0: ScrollView { + VerticalLayout { + spacing: 4px; + for item in BlacklistState.items: ArtistRow { + artist-name: item.artist-name; + added-display: item.added-display; + notes: item.notes; + has-notes: item.has-notes; + select => { + BlacklistActions.artist-select(item.artist-id); + } + remove => { + BlacklistActions.remove(item.artist-id); + } + } + } + } + } + } + + // Clear-All confirm modal — declared LAST so it stacks above the view + // (ADR-009 ≥ 3000 satisfied by declaration order; mirrors + // PlaylistDuplicateConfirmModal's scrim + centered card). Backdrop click + // dismisses; Esc dismisses via the focus-scope key handler. + if root.confirm-clear-open: Rectangle { + background: #000000bf; + // Scrim — click outside to dismiss. + TouchArea { + mouse-cursor: default; + clicked => { + root.confirm-clear-open = false; + } + } + // Esc dismiss. Grab focus on mount so the key handler is live. + esc-scope := FocusScope { + init => { + self.focus(); + } + key-pressed(event) => { + if (event.text == Key.Escape) { + root.confirm-clear-open = false; + return accept; + } + return reject; + } + } + Rectangle { + width: Math.min(root.width - 80px, 400px); + height: panel.preferred-height; + x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; + y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; + border-radius: Radius.md; + background: Theme.surface-main; + border-width: 1px; + border-color: Theme.border-subtle; + drop-shadow-blur: 32px; + drop-shadow-color: #00000080; + // Swallow clicks so they don't reach the scrim. + TouchArea { } + + panel := VerticalLayout { + padding: 24px; + spacing: 16px; + + Text { + text: @tr("Clear Blacklist?"); + color: Theme.text-primary; + font-size: Typography.heading; + font-weight: Typography.semibold; + } + Text { + text: @tr("This will remove all {} blacklisted artists. This cannot be undone.", BlacklistState.count); + color: Theme.text-secondary; + font-size: Typography.body; + wrap: word-wrap; + } + + HorizontalLayout { + alignment: end; + spacing: 10px; + + // Cancel. + Rectangle { + width: cancel-lbl.preferred-width + 32px; + height: 36px; + border-radius: Radius.sm; + background: cancel-ta.has-hover ? Theme.surface-hover : Theme.surface-elevated; + cancel-lbl := Text { + text: @tr("Cancel"); + color: Theme.text-primary; + font-size: Typography.body; + x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; + y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; + } + cancel-ta := TouchArea { + mouse-cursor: pointer; + clicked => { + root.confirm-clear-open = false; + } + } + } + // Danger Clear-All. + Rectangle { + width: danger-lbl.preferred-width + 32px; + height: 36px; + border-radius: Radius.sm; + background: danger-ta.has-hover ? #dc2626 : #ef4444; + danger-lbl := Text { + text: @tr("Clear All"); + color: #ffffff; + font-size: Typography.body; + font-weight: Typography.medium; + x: Math.round((parent.width - self.width) / 2 / 1px) * 1px; + y: Math.round((parent.height - self.height) / 2 / 1px) * 1px; + } + danger-ta := TouchArea { + mouse-cursor: pointer; + clicked => { + BlacklistActions.clear-all(); + root.confirm-clear-open = false; + } + } + } + } + } + } + } +} diff --git a/crates/qbz-slint/ui/shell/AppShell.slint b/crates/qbz-slint/ui/shell/AppShell.slint index 4d3074061..ecefb5898 100644 --- a/crates/qbz-slint/ui/shell/AppShell.slint +++ b/crates/qbz-slint/ui/shell/AppShell.slint @@ -61,6 +61,7 @@ import { CollectionsView } from "../myqbz/CollectionsView.slint"; import { MixtapeDetailView } from "../myqbz/MixtapeDetailView.slint"; import { DiscographyBuilderView } from "../myqbz/DiscographyBuilderView.slint"; import { OfflineManagerView } from "../offline/OfflineManagerView.slint"; +import { BlacklistManagerView } from "../settings/BlacklistManagerView.slint"; import { OfflinePlaceholder } from "../offline/OfflinePlaceholder.slint"; import { LocalLibraryView } from "../locallibrary/LocalLibraryView.slint"; import { SettingsView } from "../settings/SettingsView.slint"; @@ -298,6 +299,7 @@ export component AppShell inherits Rectangle { if NavState.view == ContentView.mixtape-detail: MixtapeDetailView { } if NavState.view == ContentView.discography-builder: DiscographyBuilderView { } if NavState.view == ContentView.offline-manager: OfflineManagerView { } + if NavState.view == ContentView.blacklist-manager: BlacklistManagerView { } if NavState.view == ContentView.local-library: LocalLibraryView { } if NavState.view == ContentView.mix && !OfflineState.offline: MixView { play-track(id) => { diff --git a/crates/qbz-slint/ui/state.slint b/crates/qbz-slint/ui/state.slint index 873029a0a..4d07fc84f 100644 --- a/crates/qbz-slint/ui/state.slint +++ b/crates/qbz-slint/ui/state.slint @@ -601,7 +601,7 @@ export global DragActions { } // Which content view the shell shows. -export enum ContentView { home, album, artist, settings, search, musician, label, label-releases, location, favorites, mix, playlist, discover-browse, playlist-manager, offline-manager, local-library, local-album, mixtapes, collections, mixtape-detail, discography-builder } +export enum ContentView { home, album, artist, settings, search, musician, label, label-releases, location, favorites, mix, playlist, discover-browse, playlist-manager, offline-manager, blacklist-manager, local-library, local-album, mixtapes, collections, mixtape-detail, discography-builder } // In-app toast (transient notification). Mirrors Tauri's toastStore: // a single toast at a time (a new one replaces the current), auto-hidden @@ -1817,6 +1817,54 @@ export global OfflineManagerActions { callback play-track(string /* track id */); } +// === Artist Blacklist Manager (Tauri's BlacklistManagerView) ============ +// The standalone manage-blacklist surface reached from the Settings content- +// filtering row. One blacklisted-artist row carries everything the view needs; +// the controller (crate::blacklist_manager) precomputes the date string + the +// has-notes flag so the .slint does no formatting. Search filtering is done +// controller-side: `items` already holds only the filtered rows, while `count` +// stays the FULL list count (drives the badge + the empty/no-results split). +export struct BlacklistedArtistItem { + // Numeric Qobuz artist id (fits an int for display + passing back on click + // / remove). Slint has no u64/i64; the controller passes it through as int. + artist-id: int, + artist-name: string, + // Unix seconds (kept for reference; the view renders `added-display`). + added-at: int, + // Controller-formatted "MMM D, YYYY" (English; gettext for Rust is unwired). + added-display: string, + notes: string, + has-notes: bool, +} + +export global BlacklistState { + // The CURRENTLY-VISIBLE rows (already search-filtered by the controller). + in property <[BlacklistedArtistItem]> items: []; + // Global enable flag (default-enabled, mirrors the backend default). + in property enabled: true; + in property loading: true; + // FULL list count (NOT the filtered length) — drives the count badge and + // the empty-vs-no-results branch (count==0 = empty; count>0 && items empty + // = no search results). + in property count: 0; + // Echoed back so the search input reflects the controller's query (and the + // no-results message can interpolate it). + in property search-query: ""; +} + +export global BlacklistActions { + // Forward-open seam: the Settings content-filtering row (T10) calls this to + // navigate INTO the manager (records the nav entry, swaps the view, loads). + // Mirrors OfflineManagerActions.open — the back chrome is NavButtons. + callback open(); + callback back(); + callback artist-select(int /* artist id */); + callback toggle-enabled(); + callback remove(int /* artist id */); + callback clear-all(); + callback search-changed(string /* query */); +} + // === My QBZ — Mixtapes & Collections (read-only index grids) ============ // Mirrors PlaylistManagerState/PmPlaylistItem. Both the Mixtapes grid and the // Collections grid render `MixtapeCardItem`s; the Rust controller (crate::myqbz)