Files
qbz/crates/qbz-qt/qml/views/purchases/PurchaseListRow.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

157 lines
5.3 KiB
QML

// PurchaseListRow — the LIST arm of the Purchases albums tab. 1:1 port of
// purchases/PurchasesView.slint's `PurchaseListRow` (:305-395).
//
// NOT views/AlbumListRow.qml, for the same three reasons the .slint gives for
// not reusing its own shared row: the columns are different (this row carries a
// PURCHASE-DATE column and no ⋯ menu), the unavailable state has no arm there,
// and AlbumListRow's body click is hardwired to `QbzAlbum.openAlbum` — which
// would open the catalog page instead of the purchase detail.
//
// 60px, Radius.sm, 48x48 art, title over artist, a 110px quality column and a
// 110px purchase-date column, both right-aligned. Unavailable rows dim to .5,
// lose their hover fill, gain a trailing "Unavailable" label and do not open.
//
// NO ZEBRA: the .slint gives this row a transparent resting fill (:314), unlike
// the catalog AlbumListRow's odd-row alpha-4. Adding one here would be a stripe
// pattern this screen never had.
import QtQuick
import com.blitzfc.qbz
import "../../theme"
Rectangle {
id: root
/// One row of `list_json.albums` (§G.2).
property var album: ({})
signal clicked()
QbzTheme { id: theme }
readonly property bool avail: root.album.downloadable !== false
function t(s) { return QbzSession.tr(s, QbzSession.trRev) }
/// Epoch -> the viewer's short date. "" for a row that carries no stamp,
/// so the column collapses to blank rather than to 1970.
function purchaseDate() {
var ts = root.album.purchasedAt || 0
if (ts <= 0)
return ""
// Defensive: the seam says seconds, but a producer that ever hands
// milliseconds through would otherwise print a date in the year 55000.
var ms = ts > 100000000000 ? ts : ts * 1000
return new Date(ms).toLocaleDateString(Qt.locale(), Locale.ShortFormat)
}
width: parent ? parent.width : 0
height: 60
radius: theme.radiusSm
color: (rowArea.containsMouse && root.avail) ? theme.surfaceHover : "transparent"
opacity: root.avail ? 1.0 : 0.5
MouseArea {
id: rowArea
anchors.fill: parent
hoverEnabled: true
cursorShape: root.avail ? Qt.PointingHandCursor : Qt.ArrowCursor
onClicked: if (root.avail) root.clicked()
}
Row {
anchors.fill: parent
anchors.leftMargin: 8
anchors.rightMargin: 12
spacing: 12
// 48x48 art.
Item {
width: 48
height: parent.height
Rectangle {
width: 48
height: 48
anchors.verticalCenter: parent.verticalCenter
radius: theme.radiusSm
color: theme.surfaceElevated
RoundedImage {
id: art
anchors.fill: parent
// `artPath`, never `artworkUrl` — see PurchaseGridCard.
source: root.album.artPath || ""
radius: theme.radiusSm
}
QbzIcon {
visible: !art.ready
name: "disc-3"
width: 20
height: 20
anchors.centerIn: parent
tintName: "muted"
}
}
}
// Title over artist — the stretch column.
Column {
width: Math.max(0, parent.width - 48 - 110 - 110
- (unavailLabel.visible ? unavailLabel.width + 12 : 0)
- 3 * 12)
anchors.verticalCenter: parent.verticalCenter
spacing: 2
Text {
width: parent.width
text: root.album.title || ""
color: theme.textPrimary
font.pixelSize: theme.fontBody
font.weight: theme.weightMedium
elide: Text.ElideRight
}
Text {
width: parent.width
text: root.album.artist || ""
color: theme.textMuted
font.pixelSize: theme.fontLegal
elide: Text.ElideRight
}
}
// Quality column.
Text {
width: 110
height: parent.height
text: root.album.qualityTier || ""
color: theme.textSecondary
font.pixelSize: theme.fontLegal
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
// Purchase-date column.
Text {
width: 110
height: parent.height
text: root.purchaseDate()
color: theme.textMuted
font.pixelSize: theme.fontLegal
horizontalAlignment: Text.AlignRight
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
// Unavailable label — an EXTRA column that exists only on those rows
// (.slint:384-391), which is why the stretch column above subtracts it
// conditionally.
Text {
id: unavailLabel
visible: !root.avail
height: parent.height
text: root.t("Unavailable")
color: theme.textMuted
font.pixelSize: theme.fontLegal
verticalAlignment: Text.AlignVCenter
}
}
}