feat(qt): Rust share seam, and fix the dead label share link

The port had no clipboard seam at all. share_qt.rs ports the URL builders and
the clipboard from crates/qbz/src/share.rs:1-70. The long-lived
OnceLock<Mutex<Option<Clipboard>>> is copied verbatim with its reason:
arboard ties the offer's lifetime to the LAST live Clipboard object, so a
create-per-copy port passes on KDE, which runs a clipboard manager that
accepts the handoff, and silently loses the text everywhere else (#514).
arboard carries the wayland-data-control feature at the same pin the
reference uses; without it arboard is X11-only and every copy fails on a
Wayland-only session.

The label header's Share was not merely silent - it copied a link that does
not resolve. open.qobuz.com has no /label/ route. The host is per-ENTITY, not
per-app: track and album on open.qobuz.com, artist, playlist and label on
play.qobuz.com. That asymmetry is why the five builders are ported as a set
and why no call site formats its own URL any more: this one did, and got it
wrong. QbzHome::label_share now copies play.qobuz.com/label/{id} and raises
the "Link copied" toast, 1:1 with main.rs:13164-13178, and the QML
Loader/TextEdit clipboard hack it replaced is deleted - its own comment
claimed there was no toast seam, which stopped being true when toast_qt.rs
landed.

Only the URL builders and the clipboard are ported. share.rs:72-184 is the
Song.link/Odesli resolution, which applies to tracks and albums; artists and
labels are link-only, so porting it now would be dead async HTTP.

LabelView also adopts QbzLoadMore here - its two changes share the file.

cc
This commit is contained in:
vicrodh committed 2026-08-02 16:32:51 -06:00
1 parent 6f4fb72f57
commit edbc037b0f
6 files changed
+288 -51

No files matched your search

+13
View File
@@ -24,6 +24,19 @@ urlencoding = "2"
open = "5"
dirs = "5"
# Share links (src/share_qt.rs, the port of crates/qbz/src/share.rs:32-70).
# Rust owns the clipboard on this side because the toast does: cxx-qt-lib 0.7
# ships no QClipboard binding, and QML cannot publish QbzShell.toastJson, so
# splitting the copy and its confirmation across the boundary would buy
# nothing. Same pin as the reference (crates/qbz/Cargo.toml:68), comment
# included:
#
# wayland-data-control: Wayland-native clipboard via the data-control
# protocols (GNOME/KDE/sway/niri/Hyprland), falling back to X11 when Wayland
# is absent (#514 — without it arboard is X11-only and every copy fails on
# Wayland-only sessions).
arboard = { version = "3", features = ["wayland-data-control"] }
qbz-core = { path = "../qbz-core" }
qbz-app = { path = "../qbz-app" }
qbz-audio = { path = "../qbz-audio" }
+82 -48
View File
@@ -102,22 +102,15 @@ Rectangle {
}
}
// --- Share (TrackRow.qml's Loader/TextEdit pattern — QtQuick exposes no
// Clipboard type, and there is no toast seam, so the copy is silent).
Loader {
id: clipLoader
active: false
sourceComponent: TextEdit { visible: false }
}
function copyToClipboard(text) {
if (!text || text === "")
return
clipLoader.active = true
clipLoader.item.text = text
clipLoader.item.selectAll()
clipLoader.item.copy()
clipLoader.active = false
}
// --- Share ------------------------------------------------------------
// The QML `Loader`/`TextEdit`/`copy()` clipboard hack that used to live
// here is GONE. Its header said "there is no toast seam, so the copy is
// silent" — both halves of that are now false (`toast_qt.rs`, and
// `share_qt.rs` since the artist Share landed), and the hack was not
// merely silent: it formatted `https://open.qobuz.com/label/{id}`, a host
// with no `/label/` route, so the link it copied did not resolve at all.
// The header ⋯ entry calls `QbzHome.labelShare(id)` and Rust owns the URL,
// the clipboard and the "Link copied" toast — 1:1 with main.rs:13164-13178.
// ============================ shared rail =============================
// ONE horizontal rail for all five carousels; `kind` picks the card, the
@@ -405,8 +398,13 @@ Rectangle {
{ "label": QbzSession.tr("Share", QbzSession.trRev), "icon": "link", "action": "share" },
]
onPicked: function (a) {
// Share goes through Rust (share_qt::share_label): it owns
// the long-lived clipboard AND the "Link copied" toast the
// reference raises (main.rs:13164-13178). The URL is built
// there too — this call site used to format it here and
// got the HOST wrong (see the header note above).
if (a === "share")
root.copyToClipboard("https://open.qobuz.com/label/" + (root.doc.id || ""))
QbzHome.labelShare(root.doc.id || "")
else
QbzHome.labelTopAction(a)
}
@@ -516,6 +514,41 @@ Rectangle {
width: parent ? parent.width : 0
visible: index < root.previewCount
height: visible ? 50 : 0
// SMOOTH REVEAL (owner, 2026-08-02: "que la
// aparicion de lo que se cargue, sea smooth").
// This site is CLIENT-SIDE: every row of
// topTracks is already instantiated by the
// Repeater and only gated on `previewCount`
// (LabelPageView.slint:426, which snaps), so the
// fade goes on the rows themselves — there is no
// appended tail and therefore no `fadeFrom`
// threshold to keep.
//
// It is safe to fade UNCONDITIONALLY here, which
// is NOT true of the network-backed Load-more
// sites: a QML Behavior does not run while its
// object is being created, so when the label
// document is republished (the artwork pass —
// see onDocChanged above) and the Repeater
// rebuilds every delegate, each one takes its
// opacity as a plain initial value and NOTHING
// re-fades. The animation only ever runs when
// `previewCount` moves on delegates that already
// exist, i.e. exactly on the reveal.
//
// 220ms / OutCubic = the content duration this
// round standardises on (controls/QbzLoadMore
// .qml uses 180ms for its skeleton).
// The COLLAPSE back to 5 stays instant on
// purpose: `visible` is left snapping, so the
// rows leave the layout in the same frame. Held
// open for a 220ms fade-out instead, the page
// would show ~2200px of blank list and then jump
// — worse than the snap, not better.
opacity: index < root.previewCount ? 1.0 : 0.0
Behavior on opacity {
NumberAnimation { duration: 220; easing.type: Easing.OutCubic }
}
item: modelData
number: index + 1
showArtwork: true
@@ -545,40 +578,41 @@ Rectangle {
}
}
// Reveal control: 5 -> 20 -> 50, then back to 5.
// Reveal control: 5 -> 20 -> 50, then back to 5
// (LabelPageView.slint:439-466). This was the fifth
// hand-rolled copy of the plain Load-more shape; it is
// now controls/QbzLoadMore.qml, arm (e) in that file's
// inventory — same 28-tall box, same 13px centred label,
// same hover textPrimary / textSecondary, same
// `implicitWidth + 24` hit box. Idle pixels unchanged.
//
// CLIENT-SIDE, so no fetch to wait on: `busy` stays
// false and `skeleton` stays "none", which is what keeps
// a placeholder from appearing under a button whose
// rows are revealed in the same frame. The smooth half
// of the owner's request lives on the TrackRow delegate
// above, not here (see the SMOOTH REVEAL note there).
Item { visible: root.topTracks.length > 5; width: 1; height: visible ? 4 : 0 }
Item {
QbzLoadMore {
visible: root.topTracks.length > 5
width: parent.width
height: visible ? 28 : 0
Rectangle {
anchors.centerIn: parent
width: revealText.implicitWidth + 24
height: 28
color: "transparent"
Text {
id: revealText
anchors.centerIn: parent
text: (root.previewCount < 50
&& root.topTracks.length > root.previewCount)
? QbzSession.tr("Load more", QbzSession.trRev)
: QbzSession.tr("View less", QbzSession.trRev)
color: revealArea.containsMouse ? theme.textPrimary : theme.textSecondary
font.pixelSize: 13
}
MouseArea {
id: revealArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
if (root.previewCount < 50
&& root.topTracks.length > root.previewCount)
root.previewCount = root.previewCount === 5 ? 20 : 50
else
root.previewCount = 5
}
}
buttonHeight: 28
skeleton: "none"
busy: false
// The label ternary is verbatim from the copy this
// replaces: "Load more" while the reveal can still
// grow, "View less" once it cannot (both are
// existing msgids — no new strings).
label: (root.previewCount < 50
&& root.topTracks.length > root.previewCount)
? QbzSession.tr("Load more", QbzSession.trRev)
: QbzSession.tr("View less", QbzSession.trRev)
onClicked: {
if (root.previewCount < 50
&& root.topTracks.length > root.previewCount)
root.previewCount = root.previewCount === 5 ? 20 : 50
else
root.previewCount = 5
}
}
}
+12
View File
@@ -164,6 +164,12 @@ pub mod qbz_home {
fn label_top_action(self: Pin<&mut QbzHome>, mode: QString);
#[qinvokable]
fn label_open_releases(self: Pin<&mut QbzHome>);
/// Label header ⋯ → Share. Rust-side because the reference raises a
/// toast and only Rust can publish `QbzShell.toastJson` — and because
/// the URL host is per-entity (`play.qobuz.com` for a label), which a
/// QML call site formatting its own string got wrong.
#[qinvokable]
fn label_share(self: Pin<&mut QbzHome>, label_id: QString);
// --- Discover > For You: Qobuz Mixes / Radio / Spotlight ----------
/// A Qobuz Mixes tile: open the mix landing page ("daily" | "weekly"
@@ -432,6 +438,12 @@ impl qbz_home::QbzHome {
crate::label_qt::open_releases();
}
/// Straight through to `share_qt` — no nav and no bridge state is touched,
/// exactly like `QbzArtist::share`.
pub fn label_share(self: Pin<&mut Self>, label_id: QString) {
crate::share_qt::share_label(label_id.to_string());
}
// --- Discover > For You: mixes / radio / spotlight ---------------------
pub fn open_mix(self: Pin<&mut Self>, kind: QString) {
+8 -3
View File
@@ -28,9 +28,14 @@
//! `album_blacklisted` (label.rs:92, :133, :537, :567) and stamps the row
//! flag (:900); `derive_releases` here does neither, so a blocked artist's
//! album still RENDERS on a label page (playing it is already blocked).
//! - **Share** is QML-side (a clipboard write through the `TrackRow.qml`
//! Loader/TextEdit pattern) — there is no Rust clipboard bridge and no
//! toast seam, so no invokable exists for it here.
//! - **Share** is DONE and Rust-side (`QbzHome::label_share` →
//! `share_qt::share_label`), 1:1 with `main.rs:13164-13178`: the
//! `play.qobuz.com/label/{id}` link plus the "Link copied" success toast.
//! It used to be a QML clipboard write that formatted
//! `open.qobuz.com/label/{id}` — a host with NO `/label/` route, so the
//! copied link was dead on arrival (owner-reported 2026-08-02). The host is
//! per-entity, not per-app: track/album on `open.`, artist/playlist/label on
//! `play.` — which is exactly why the URL builders live in one place now.
//! - **Scroll restore**: no Qt counterpart exists (`nav_qt` stores view ids
//! only), so `report-scroll` / `sr-restore` are not ported.
+172
View File
@@ -0,0 +1,172 @@
//! Share links + system clipboard — the Qt port of `crates/qbz/src/share.rs`
//! (lines 1-70: the URL builders and the clipboard). Driven by the artist
//! header's ⋯ → Share (`qml/views/ArtistView.qml`, the overflow menu).
//!
//! **Only the first half of the reference is ported.** `share.rs:72-184`
//! (`share_http_client`, `deezer_lookup`, `songlink_for_track`,
//! `albumlink_for_album`, `songlink_url`) resolves Song.link / Album.link for
//! the TRACK and ALBUM context menus. Artists have no such path anywhere in
//! the Slint tree — `main.rs:12749` ("artist","share") is two statements, copy
//! + toast — and this port has no Song.link call site at all, so porting those
//! resolvers now would be dead async HTTP. The module header of the reference
//! naming "Song.link" is about track/album only; do not read it as an artist
//! feature.
//!
//! **The `open.` vs `play.` split is deliberate, not a typo.** Track and album
//! moved to `open.qobuz.com` for #514 (`share.rs:4`, `:14-16`, which records
//! that Tauri used `play.qobuz.com/album/{id}` and that the change is
//! intentional); playlist / artist / label stay on the web player at
//! `play.qobuz.com`. Normalising all five onto one host breaks parity.
//!
//! **Why the clipboard lives in Rust here.** cxx-qt-lib 0.7 exposes no
//! QClipboard binding, so QML's own idiom (an inactive `Loader` holding an
//! invisible `TextEdit`, `selectAll()` + `copy()` — `qml/rows/TrackRow.qml`)
//! is the only QML route; but only Rust can publish `QbzShell.toastJson`
//! (`toast_qt.rs`), and the reference arm raises a toast. Splitting the two
//! halves across the boundary would need a second invokable for no gain, so
//! the whole action is one Rust seam. The four existing QML clipboard sites
//! keep their idiom — this does not replace them.
// The five builders are ported as a set on purpose: they are the reference's
// complete URL surface and the album / track / label / playlist Share arms
// will reuse them verbatim when those menus are wired. Keeping the set intact
// (rather than growing it one host at a time) is what stops a later arm from
// re-deriving a URL and reintroducing the `open.`/`play.` mix-up that
// `qml/views/LabelView.qml` already shipped once. Same allowance the toast
// publisher takes for its unused kinds (`toast_qt.rs:27`).
#![allow(dead_code)]
/// Canonical Qobuz track URL — the `open.qobuz.com` share form (#514).
/// `share.rs:4-7`.
pub(crate) fn qobuz_track_url(track_id: &str) -> String {
format!("https://open.qobuz.com/track/{track_id}")
}
/// Qobuz web-player playlist URL (matches Tauri's share-playlist link).
/// `share.rs:9-12`.
pub(crate) fn qobuz_playlist_url(playlist_id: &str) -> String {
format!("https://play.qobuz.com/playlist/{playlist_id}")
}
/// Qobuz album URL — the `open.qobuz.com` form (#514; Tauri's
/// `shareAlbumQobuzLink` used `https://play.qobuz.com/album/{id}`). Also
/// the source URL fed to Song.link for the album-level "Album.link".
/// `share.rs:14-19`.
pub(crate) fn qobuz_album_url(album_id: &str) -> String {
format!("https://open.qobuz.com/album/{album_id}")
}
/// Qobuz web-player artist URL (header Share action). `share.rs:21-24`.
pub(crate) fn qobuz_artist_url(artist_id: &str) -> String {
format!("https://play.qobuz.com/artist/{artist_id}")
}
/// Qobuz web-player label URL (label-page header Share action). There is no
/// Song.link/Album.link equivalent for labels — Qobuz-link only.
/// `share.rs:26-30`.
pub(crate) fn qobuz_label_url(label_id: &str) -> String {
format!("https://play.qobuz.com/label/{label_id}")
}
/// Long-lived clipboard instance. arboard ties the offer's lifetime to the
/// LAST live `Clipboard` object: dropping it destroys the X11 selection
/// window (contents survive only when a clipboard MANAGER accepts the
/// handoff — KDE ships one, stock GNOME/XFCE/Cinnamon do not) and ends the
/// Wayland offer with the same rule. The old create-per-copy pattern
/// therefore worked on KDE and silently lost the text everywhere else
/// (HiFi-wizard copy report, #514). One instance kept alive for the whole
/// process serves the offer like any normal app.
///
/// This is the #514 fix, verbatim from `share.rs:32-41` — it is NOT
/// boilerplate to be simplified into a local. A create-per-copy port would
/// pass every test run on KDE and lose the text everywhere else.
static CLIPBOARD: std::sync::OnceLock<std::sync::Mutex<Option<arboard::Clipboard>>> =
std::sync::OnceLock::new();
/// Copy `text` to the system clipboard. Runs on a blocking thread —
/// clipboard backends (X11/Wayland) can block. `share.rs:43-70`.
///
/// The one adaptation vs the reference: in the Slint app the arm already runs
/// inside a tokio context, whereas a cxx-qt invokable runs on the **Qt event
/// loop thread**, where a bare `tokio::task::spawn_blocking` panics ("must be
/// called from the context of a Tokio runtime"). It therefore goes through
/// `crate::spawn` (main.rs) onto the process-global runtime first — the same
/// `spawn` + `spawn_blocking` sandwich `local_ephemeral.rs`, `browse_qt.rs`
/// and `ambient_qt.rs` already use.
///
/// Fire-and-forget by design: the caller never learns whether the copy
/// worked, which is why the toast at the call site is unconditional
/// (`main.rs:12758-12761` does the same).
pub(crate) fn copy_to_clipboard(text: String) {
crate::spawn(async move {
let _ = tokio::task::spawn_blocking(move || {
let cell = CLIPBOARD.get_or_init(|| std::sync::Mutex::new(None));
let mut guard = match cell.lock() {
Ok(g) => g,
Err(poisoned) => poisoned.into_inner(),
};
if guard.is_none() {
match arboard::Clipboard::new() {
Ok(c) => *guard = Some(c),
Err(e) => {
log::warn!("[qbz-qt] clipboard unavailable: {e}");
return;
}
}
}
if let Some(clipboard) = guard.as_mut() {
if let Err(e) = clipboard.set_text(text) {
log::warn!("[qbz-qt] clipboard set failed: {e}");
// Drop the instance so the next copy reconnects — the
// display connection may have gone away.
*guard = None;
}
}
})
.await;
});
}
/// Artist header ⋯ → Share. `artist/ArtistPageView.slint:530-538` fires
/// `media-action("artist", ArtistState.id, "share")`; the arm at
/// `crates/qbz/src/main.rs:12749-12763` copies `share::qobuz_artist_url(&id)`
/// and raises the "Link copied" success toast.
///
/// Link-ONLY: there is no Song.link/Odesli path for artists (see the module
/// header), so there is no "Fetching…" info toast either — the reference
/// shows one only for the track/album Song.link arms.
///
/// The empty-id guard is the reference's: `main.rs:12755` skips both the copy
/// and the toast when the id is empty, so a header that has not resolved yet
/// stays silent instead of copying `.../artist/`.
pub(crate) fn share_artist(artist_id: String) {
if artist_id.is_empty() {
return;
}
copy_to_clipboard(qobuz_artist_url(&artist_id));
// "Link copied" is an EXISTING msgid, present in all eight catalogues
// (crates/qbz-ui/translations/*/LC_MESSAGES/qbz-ui.po) — no new string.
crate::toast_qt::success(qbz_i18n::t("Link copied"));
}
/// Label header ⋯ → Share. Same shape as `share_artist`, and the reference is
/// the same `media-action` table: `crates/qbz/src/main.rs:13164-13178` copies
/// `share::qobuz_label_url(&label_id)` and raises the "Link copied" success
/// toast. Link-only — the reference's own comment there says there is no
/// Song.link/Album.link equivalent for labels.
///
/// THIS REPLACES A BROKEN LINK, not just a missing toast. `LabelView.qml`
/// copied `https://open.qobuz.com/label/{id}` through a QML `TextEdit`, and
/// `open.qobuz.com` has NO `/label/` route — the copied URL simply did not
/// resolve. The host is per-ENTITY, not per-app (#514): track and album live
/// on `open.qobuz.com`, artist / playlist / label on `play.qobuz.com`. Owner-
/// confirmed 2026-08-02 with a working example, `https://play.qobuz.com/label/
/// 68307`. That asymmetry is why the five builders above are ported as a set:
/// a call site that formats its own URL gets this wrong, and did.
pub(crate) fn share_label(label_id: String) {
if label_id.is_empty() {
return;
}
copy_to_clipboard(qobuz_label_url(&label_id));
crate::toast_qt::success(qbz_i18n::t("Link copied"));
}