Files
qbz/crates/qbz-qt/qml/views/purchases/PurchaseAlbumsCollection.qml
T
vicrodh 7d98ad044f feat(purchases): the Qt frontend — list, album detail, routing and gating
Two screens, a controller and a bridge. `QbzPurchases` publishes one JSON
document per screen plus a revision counter, so QML re-parses even when the text
is byte-identical.

- The list: two tabs with per-type counters, a server-side search on a 300 ms
  debounce, and a toolbar that DIFFERS by tab — Albums gets group, sort,
  direction, two filters and grid/list; Tracks gets group and the filters only.
  Building the Albums toolbar on both would have invented two controls.
- The detail: a format dropdown whose selection re-scopes every downloaded mark,
  the progress section and Add-to-Library together; a determinate bar counted in
  TRACKS, never bytes; goodies as an album-level action counted separately.
- The album download is the frontend loop, not the Rust command the reference
  registered and never called. Sequential, concurrency 1, cancellable, and a
  failed track does not abort the album.
- Both prefs are read at runtime, not merely written. `show_purchases` is the
  master gate and `nav_tb_purchases` only relocates the entry to the title bar;
  both default false, so Purchases still ships hidden.
- Scanned local rows keep their raw `qobuz_purchase` source so the gold badge
  survives in list mode as well as grid, while still classifying under the
  Offline source filter. Remote feed rows deliberately stay `qobuz`: stamping
  them would badge every purchase the user merely OWNS as locally downloaded.

Defects fixed after the screens were written, none of which any test could have
caught:

- `QbzPurchases.boot()` was called nowhere. Without the Qt-thread hop every
  publish is a silent no-op, so both screens would have stayed permanently empty
  with nothing logged. The cause was an ownership gap rather than the code:
  `Main.qml` belonged to no lane because the plan listed the files each lane
  CREATES rather than the files it TOUCHES, and "belongs to nobody" is
  indistinguishable from "done" until something runs.
- A second download of the same album nested inside the first. The store rewrites
  its destination to the album subfolder after the first successful track so that
  Add-to-Library adds the album rather than the whole music root, and the download
  planner read that value first — producing `.../Album [q]/Artist/Album [q]/...`,
  one level deeper each time. The picked ROOT and the resolved ALBUM FOLDER are
  now separate fields with names that cannot be confused, with a regression test.
- A tab counter could stick at zero forever with its list plainly full: the two
  ids calls each swallow their error, and the reference's backfill from the list
  response was missing.
- Cancelling made the whole progress block vanish instead of showing the
  cancelled state, whose msgid was already translated in all eight catalogs.
- Add-to-Library re-walked the entire library when the folder id it needed was
  already in hand.
- A live language switch and a logout left the previous state behind.

Deliberate divergences from the contract, each recorded with its reason: the page
header is a plain `fontSection` title with no icon tile, because nothing else in
this application announces itself over a large coloured square; purchase download
status travels inside the album document rather than on the shared cache channel,
which is keyed by track id alone and would let the two features overwrite each
other on the same row.

Gate: release build clean, QML audits 278 files / 37 bridges, `cargo test -p
qbz-qt` 398 passing, offscreen smoke green with zero QML complaints.

Not verified, and cannot be from here: every populated screen. This account owns
nothing, so only the empty states have ever rendered.

cc
2026-08-16 11:54:05 -06:00

97 lines
3.8 KiB
QML

// PurchaseAlbumsCollection — one collection of purchased albums, drawn as a
// grid or as a list. 1:1 port of purchases/PurchasesView.slint's
// `AlbumsCollection` (:1155-1210).
//
// "One collection" = either the whole flat set, or ONE group's albums when the
// toolbar's grouping is on; the host mounts as many of these as there are
// groups, which is what keeps the group headers and their bodies in one place.
//
// GEOMETRY, off the .slint: grid cards 162x232 on a 16px gap (the Tauri
// `auto-fill minmax(162px, 1fr)` column math, reproduced exactly), list rows
// 60px on a 4px gap. The root is content-sized in both arms so the page's one
// Flickable owns the scroll — there is no nested scroller here.
//
// NO WINDOWING. views/AlbumCollection.qml samples a visible band every 80ms and
// mounts only the cards inside it; that machinery is coupled to ITS delegate
// (cards/AlbumCard.qml) and its host contract, and §15.1 forbids building
// virtualisation of our own. Every purchased album therefore mounts, exactly as
// it does in Tauri and in the .slint. Recorded as a known cost, not an
// oversight: a very large purchase library will pay for it on entry.
import QtQuick
import com.blitzfc.qbz
import "../../theme"
Item {
id: root
/// Rows of `list_json.albums` (§G.2) — already searched / sorted / filtered
/// by the controller.
property var albums: []
/// "grid" | "list".
property string viewMode: "grid"
signal openAlbum(string albumId)
QbzTheme { id: theme }
readonly property int cardWidth: 162
readonly property int cardHeight: 232
readonly property int cardGap: 16
readonly property int listRowHeight: 60
readonly property int listGap: 4
readonly property int columns: Math.max(
1, Math.floor((width + root.cardGap) / (root.cardWidth + root.cardGap)))
readonly property int gridRows:
Math.ceil(root.albums.length / Math.max(1, root.columns))
width: parent ? parent.width : 0
// Content-sized: the page Flickable reads this through its Column.
height: root.viewMode === "list"
? (root.albums.length > 0
? root.albums.length * root.listRowHeight
+ (root.albums.length - 1) * root.listGap
: 0)
: (root.gridRows > 0
? root.gridRows * root.cardHeight + (root.gridRows - 1) * root.cardGap
: 0)
// --- Grid -------------------------------------------------------------
Item {
visible: root.viewMode !== "list"
anchors.fill: parent
Repeater {
// The model is gated on the arm so the hidden arm builds no
// delegates at all (the AlbumCollection convention) — a hidden
// Repeater still instantiates everything otherwise.
model: root.viewMode !== "list" ? root.albums : []
delegate: PurchaseGridCard {
required property var modelData
required property int index
x: (index % root.columns) * (root.cardWidth + root.cardGap)
y: Math.floor(index / root.columns) * (root.cardHeight + root.cardGap)
width: root.cardWidth
height: root.cardHeight
album: modelData
onClicked: root.openAlbum(modelData.id || "")
}
}
}
// --- List -------------------------------------------------------------
Column {
visible: root.viewMode === "list"
anchors.fill: parent
spacing: root.listGap
Repeater {
model: root.viewMode === "list" ? root.albums : []
delegate: PurchaseListRow {
required property var modelData
width: parent ? parent.width : 0
album: modelData
onClicked: root.openAlbum(modelData.id || "")
}
}
}
}