Un-following a Qobuz playlist left it in the sidebar and in My Library. toggle_follow called unsubscribe_playlist and settled the ownership snapshot and stopped there, so the row only left at the next full refetch. Both surfaces are patched directly now, in both directions: following from a card buys the metadata with one get_playlist rather than re-reading getUserPlaylists, which lags the write. The un-follow collapses a hearted-and-followed playlist to the one row the next load will actually produce instead of dropping it, because the local heart is a library.db flag that survives the unsubscribe — removing every row made it vanish and come back, which is the original complaint wearing the other shoe. The Plex mark on album cards was a hard-drive glyph tinted accent — a blue hard drive — and the three Qobuz kinds drew no badge at all. The badge now ports discover/AlbumCard.slint:326-354 exactly: 24x24 at radius 4 pinned bottom-right with a 6px inset, plex-logo untinted at 16, qobuz-logo at 18 (22 for a download), the purchase arm gold on its amber chip, hard-drive white at 14 for local only. The brand marks are plain Images: routing them through QbzIcon floods every pixel with the tint and flattens a logo to a silhouette. SourceIcon moves to controls/ since it is no longer local-only, and every other surface drawing a hard-drive was audited against its .slint. The local album detail loses the two nav chevrons above the art. They are a Tauri-era leftover from before the app had global navigation. My QBZ used a bespoke card in the grid. MyQbzDetailCard is deleted and the standard cards/AlbumCard is mounted with its overlay. localMode bundled four separate things — action routing, the heart, the pin and Block this album — so a multi-source container had to switch all four off together; it is split, and the catalog affordances now follow the ITEM. On a Qobuz cell the heart works through the shared favourite seam; on a track, playlist, local or Plex cell it is absent rather than dead. Row covers carry two rungs: the list keeps _50, the grid gets _600. Not the _230 that would merely cover a 200px card — the complaint was that the cover reads softer than a normal AlbumCard, and a normal AlbumCard is fed image.large, which IS _600. _200 is not a rung the CDN serves at all (it answers 404). The My QBZ grid sets reuseItems, and AlbumCard assigns to its own isFavorite and isPinned when toggled, which destroys the binding that fed them. A recycled delegate therefore showed the previous row's heart and the click added the new album while the glyph said remove. Restored with the Qt.binding idiom this port already uses on TrackCard, PlaylistCard and TrackRow. The details view no longer force-opens every row on entry, and the per-row open state persists. Library > Artists showed placeholders for nearly every portrait. The side panel never reported its artwork window — the one caller of libraryArtworkWindow is LibraryView.reportWindow, and the panel had no report call at all, so no key ever reached the resolver and artMap stayed empty for its rows. The rail now reports through that same path, with the section-header sentinel reportWindow already skips. Note the reference has no portrait fallback either: an artist Qobuz serves no image for is a placeholder on both sides. cc
169 lines
7.4 KiB
Rust
169 lines
7.4 KiB
Rust
//! Per-user library.db access — the local-only playlist flags, ported from
|
|
//! `crates/qbz/src/library_db.rs`. Opens
|
|
//! `<data_dir>/qbz/users/<uid>/library.db` on demand via the `qbz-library`
|
|
//! backend crate (ADR-006 — no glue copied).
|
|
//!
|
|
//! Why a LOCAL db and not the Qobuz API: the playlist heart is a qbz-only
|
|
//! flag. `/favorite/create` and `/favorite/delete` accept exactly five id
|
|
//! params — `album_ids`, `artist_ids`, `track_ids`, `label_ids`, `award_ids`
|
|
//! (inferred OpenAPI v10.0.0.0-beta, §Favorites) — there is no
|
|
//! `playlist_ids`, which is why the reference routes `("playlist",
|
|
//! "favorite")` to `db.set_playlist_favorite` instead (main.rs:13652, its
|
|
//! comment: "Qobuz /favorite/create rejects playlist_ids").
|
|
//!
|
|
//! `LibraryDatabase` holds a non-Send `rusqlite::Connection`, so every call
|
|
//! opens it fresh; async callers must wrap these in `spawn_blocking`.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
use qbz_app::user_data::UserDataPaths;
|
|
use qbz_library::{LibraryDatabase, LibraryError};
|
|
|
|
/// `<data_dir>/qbz/users/<uid>/library.db` — the same per-user path the
|
|
/// reference uses, so the local organization data is shared between builds.
|
|
///
|
|
/// `unwrap_or(0)` — the GUEST profile, not a bail. This used to `?` out when
|
|
/// `last_user_id` was absent, which is the state of a machine that has never
|
|
/// completed a Qobuz login: for that user `db_path()` was permanently `None`,
|
|
/// so `with_db` answered `None` to every call and the ENTIRE local-playlist
|
|
/// feature (plus folders, local favourites and the mixtape tables) simply did
|
|
/// not exist — for exactly the population local playlists are FOR. It survived
|
|
/// review because every developer machine has logged in at least once.
|
|
///
|
|
/// `users/0/` is the designed home for that data, not an invention:
|
|
/// `AppRuntime::activate_offline` resolves its own user with the SAME
|
|
/// `load_last_user_id().unwrap_or(0)`, and `adopt_guest_profile` (#553)
|
|
/// renames `users/0/` onto the account on first login precisely so work done
|
|
/// logged-off follows the user in. The reference has no such hole because it
|
|
/// binds a session-scoped id instead (`library_db::set_user(user_id)` from
|
|
/// `init_shell_for_user`, which qbz/src/main.rs:172 documents as shared by the
|
|
/// ONLINE AND OFFLINE entries) — this is the port's substitution of
|
|
/// `load_last_user_id()` for that id, made to agree with it in the one case
|
|
/// where they diverged.
|
|
///
|
|
/// Reads still pass `create: false`, so nothing is conjured by listing; only a
|
|
/// write brings `users/0/library.db` into existence.
|
|
fn db_path() -> Option<PathBuf> {
|
|
let uid = UserDataPaths::load_last_user_id().unwrap_or(0);
|
|
Some(
|
|
dirs::data_dir()?
|
|
.join("qbz")
|
|
.join("users")
|
|
.join(uid.to_string())
|
|
.join("library.db"),
|
|
)
|
|
}
|
|
|
|
/// Run `f` against the per-user database. `create` mirrors the reference's
|
|
/// `open()`: writes must be able to bring the file into existence (a fresh
|
|
/// account has no library.db until the first local flag is set), reads must
|
|
/// NOT — an empty result is the right answer and creating the file as a side
|
|
/// effect of a read is a surprise.
|
|
///
|
|
/// `pub(crate)` because this is the port's only CREATE-CAPABLE accessor, and
|
|
/// MyQBZ needs it twice on a fresh account: `run_mixtape_migrations` at
|
|
/// session activation and the first `create_collection`. The other accessor,
|
|
/// `local_state::with_db` (already `pub`), is the right one for every
|
|
/// `local_*` read, but it returns `None` when library.db is absent
|
|
/// (`local_state.rs:44-46`) — through it a brand-new account could never run
|
|
/// the migrations, so it could never create a mixtape. Slint has no such
|
|
/// split: its `library_db::open` always creates
|
|
/// (`qbz/src/library_db.rs:54-64`).
|
|
pub(crate) fn with_db<F, R>(create: bool, f: F) -> Option<R>
|
|
where
|
|
F: FnOnce(&LibraryDatabase) -> Result<R, LibraryError>,
|
|
{
|
|
let path = db_path()?;
|
|
if create {
|
|
if let Some(parent) = path.parent() {
|
|
let _ = std::fs::create_dir_all(parent);
|
|
}
|
|
} else if !path.exists() {
|
|
return None;
|
|
}
|
|
let db = match LibraryDatabase::open(&path) {
|
|
Ok(db) => db,
|
|
Err(e) => {
|
|
log::warn!("[qbz-qt] library.db open failed: {e}");
|
|
return None;
|
|
}
|
|
};
|
|
match f(&db) {
|
|
Ok(r) => Some(r),
|
|
Err(e) => {
|
|
log::error!("[qbz-qt] library.db op failed: {e}");
|
|
None
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Hearted playlist ids (favorites.rs `db.get_favorite_playlist_ids`).
|
|
/// Empty on any failure (missing user, missing db) — the Library sub-tab
|
|
/// then shows owned playlists only.
|
|
pub fn favorite_playlist_ids() -> Vec<u64> {
|
|
with_db(false, |db| db.get_favorite_playlist_ids()).unwrap_or_default()
|
|
}
|
|
|
|
/// Same read, against an EXPLICIT per-user directory (`<…>/users/<uid>/`).
|
|
///
|
|
/// Session activation seeds `fav_cache_qt` from here, and at that moment
|
|
/// `UserDataPaths::load_last_user_id()` is not a safe way to name the user
|
|
/// being activated — `db_path()` above would resolve to whoever was persisted
|
|
/// last. The caller already holds the right directory, so it passes it.
|
|
///
|
|
/// Read-only, never creates the file: a fresh account with no local flags
|
|
/// yet is an empty set, not an error.
|
|
pub fn favorite_playlist_ids_at(base_dir: &Path) -> Vec<u64> {
|
|
let path = base_dir.join("library.db");
|
|
if !path.exists() {
|
|
return Vec::new();
|
|
}
|
|
match LibraryDatabase::open(&path) {
|
|
Ok(db) => db.get_favorite_playlist_ids().unwrap_or_else(|e| {
|
|
log::warn!("[qbz-qt] library.db favorite playlist seed failed: {e}");
|
|
Vec::new()
|
|
}),
|
|
Err(e) => {
|
|
log::warn!("[qbz-qt] library.db open failed ({}): {e}", path.display());
|
|
Vec::new()
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Is this playlist hearted? Read straight from the db so the toggle picks
|
|
/// its direction from the authority, not from whatever a card happened to
|
|
/// render (main.rs `playlist_toggle_favorite_by_id`).
|
|
pub fn is_favorite_playlist(pid: u64) -> bool {
|
|
with_db(false, |db| db.get_favorite_playlist_ids())
|
|
.map(|ids| ids.contains(&pid))
|
|
.unwrap_or(false)
|
|
}
|
|
|
|
/// Set the heart. Returns false when the write did not land (no user, open
|
|
/// or sqlite failure) so the caller can leave the UI alone.
|
|
pub fn set_favorite_playlist(pid: u64, favorite: bool) -> bool {
|
|
with_db(true, |db| db.set_playlist_favorite(pid, favorite)).is_some()
|
|
}
|
|
|
|
/// Has this Qobuz playlist (by its SOURCE id) already been copied into the
|
|
/// user's library?
|
|
///
|
|
/// The reference seeds `PlaylistState.is-copied` from exactly this read when
|
|
/// the detail opens (`qbz/src/main.rs:4555`), which is what keeps the Copy
|
|
/// button hidden on the SECOND visit. The port used to carry `is_copied` in
|
|
/// the session document only, so a restart offered "Copy to your library"
|
|
/// again on a playlist that was already copied.
|
|
///
|
|
/// Read-only (`create: false`): a user with no local flags yet has no db, and
|
|
/// that is "not copied", not an error.
|
|
pub fn is_playlist_copied(pid: u64) -> bool {
|
|
with_db(false, |db| db.is_playlist_copied(pid)).unwrap_or(false)
|
|
}
|
|
|
|
/// Record that a Qobuz playlist (by its SOURCE id) was copied into the user's
|
|
/// library. Idempotent server-side of the sqlite (`INSERT OR IGNORE`), so a
|
|
/// re-copy is a no-op. Returns false when the write did not land.
|
|
pub fn mark_playlist_copied(pid: u64) -> bool {
|
|
with_db(true, |db| db.mark_playlist_copied(pid)).is_some()
|
|
}
|