fix(slint): album view layout and a working track search

Four album-view corrections from review:

- Explicit badge: the title row now uses `alignment: start`, so the E
  badge sits right after the track name instead of being stretched out
  to a fake column position.
- Label/awards sidebar: dropped `alignment: start` on the track/sidebar
  row — it had defeated the track list's stretch and left the sidebar
  floating mid-row with dead space. The list now stretches and the
  254px sidebar is flush right; it rides the content region inward when
  a main sidebar opens.
- Track search: now a real client-side filter — a TextInput drives the
  AlbumActions.search global callback; album.rs keeps the unfiltered
  list and filter_tracks() matches title/artist case-insensitively.
- Description modal: the Flickable is vertical-stretch bounded so long
  text scrolls, and strip_html keeps paragraph breaks as newlines.

cc
This commit is contained in:
vicrodh committed 2026-05-18 19:51:47 -06:00
1 parent e766bed21a
commit 9bd8692518
5 files changed
+123 -28

No files matched your search

+55 -6
View File
@@ -4,6 +4,7 @@
//! on the worker thread, and applies it to the `AlbumState` global on the
//! Slint event loop.
use std::cell::RefCell;
use std::sync::Arc;
use qbz_app::shell::AppRuntime;
@@ -13,6 +14,13 @@ use slint::{ComponentHandle, ModelRc, VecModel};
use crate::{AlbumState, AlbumTrackItem, AppWindow};
thread_local! {
/// The current album's full, unfiltered track list — kept so the
/// track search can filter against it without a re-fetch. UI thread
/// only, hence `thread_local`.
static FULL_TRACKS: RefCell<Vec<AlbumTrackItem>> = RefCell::new(Vec::new());
}
/// Plain, `Send` album data produced on the worker thread.
pub struct AlbumData {
pub id: String,
@@ -144,11 +152,22 @@ fn quality_detail(bit_depth: Option<u32>, sample_rate: Option<f64>) -> String {
format!("{depth}-bit / {rate} kHz")
}
/// Crude HTML strip for Qobuz album descriptions (tags + a few entities).
/// Crude HTML strip for Qobuz album descriptions. Break and paragraph
/// tags become newlines first so paragraph structure survives; remaining
/// tags are dropped and a few entities decoded.
fn strip_html(input: &str) -> String {
let normalized = input
.replace("<br>", "\n")
.replace("<br/>", "\n")
.replace("<br />", "\n")
.replace("<BR>", "\n")
.replace("<BR/>", "\n")
.replace("</p>", "\n\n")
.replace("</P>", "\n\n");
let mut out = String::new();
let mut in_tag = false;
for ch in input.chars() {
for ch in normalized.chars() {
match ch {
'<' => in_tag = true,
'>' => in_tag = false,
@@ -156,12 +175,17 @@ fn strip_html(input: &str) -> String {
_ => {}
}
}
out.replace("&amp;", "&")
let mut out = out
.replace("&amp;", "&")
.replace("&#39;", "'")
.replace("&quot;", "\"")
.replace("&nbsp;", " ")
.trim()
.to_string()
.replace("&nbsp;", " ");
// Collapse runs of blank lines left by stacked tags.
while out.contains("\n\n\n") {
out = out.replace("\n\n\n", "\n\n");
}
out.trim().to_string()
}
fn map_track(track: Track) -> TrackData {
@@ -235,12 +259,37 @@ pub fn apply_album(window: &AppWindow, data: AlbumData) {
state.set_description(data.description.into());
state.set_label(data.label.into());
state.set_awards(ModelRc::new(VecModel::from(awards)));
// Keep the unfiltered list for the track search, then show it all.
FULL_TRACKS.with(|cell| *cell.borrow_mut() = tracks.clone());
state.set_tracks(ModelRc::new(VecModel::from(tracks)));
}
/// Filter the visible track list by `query` (case-insensitive match on
/// title or artist), against the unfiltered list kept in `FULL_TRACKS`.
/// Runs on the Slint event loop.
pub fn filter_tracks(window: &AppWindow, query: &str) {
let needle = query.trim().to_lowercase();
let filtered: Vec<AlbumTrackItem> = FULL_TRACKS.with(|cell| {
cell.borrow()
.iter()
.filter(|track| {
needle.is_empty()
|| track.title.as_str().to_lowercase().contains(&needle)
|| track.artist.as_str().to_lowercase().contains(&needle)
})
.cloned()
.collect()
});
window
.global::<AlbumState>()
.set_tracks(ModelRc::new(VecModel::from(filtered)));
}
/// Clear album state and show an empty track list (used when opening a new
/// album so the previous one does not flash).
pub fn reset_album(window: &AppWindow) {
FULL_TRACKS.with(|cell| cell.borrow_mut().clear());
let state = window.global::<AlbumState>();
state.set_tracks(ModelRc::new(VecModel::from(Vec::<AlbumTrackItem>::new())));
state.set_artwork(slint::Image::default());
+12
View File
@@ -412,6 +412,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
log::info!("[qbz-slint] media-action: kind={kind} id={id} action={action}");
});
// Album track search — client-side filter, no backend round-trip.
{
let weak = window.as_weak();
window
.global::<AlbumActions>()
.on_search(move |query| {
if let Some(w) = weak.upgrade() {
album::filter_tracks(&w, query.as_str());
}
});
}
window.on_close_app(|| {
log::info!("[qbz-slint] closing");
let _ = slint::quit_event_loop();