feat(qt): every name on the artist line is its own link

With featured performers shown, the line is one elided StyledText whose
names are separate links: the main artist opens its page as before; a
featured name opens its page when the album credits carry its id and the
search for that name otherwise. Rows send the names with ids resolved.

cc
This commit is contained in:
vicrodh committed 2026-09-13 09:09:29 -06:00
1 parent 04e5c50045
commit 903dfbefc6
9 files changed
+150 -30

No files matched your search

+15
View File
@@ -233,6 +233,13 @@ pub fn featured_artists(performers: &str, row_artist: &str, title: &str) -> Vec<
out
}
/// "Is this the same person" for two credited names (the row's featured
/// performer vs. an album credit that carries an id).
pub fn same_artist_name(a: &str, b: &str) -> bool {
let (a, b) = (normalize_name(a), normalize_name(b));
!a.is_empty() && a == b
}
/// Lower-case, Latin-1 diacritics folded, apostrophes dropped, whitespace
/// collapsed — the comparison key for "is this the same person".
fn normalize_name(s: &str) -> String {
@@ -345,6 +352,14 @@ mod tests {
assert!(featured_artists(p, "Alice, Bob & Carol", "Song").is_empty());
}
#[test]
fn same_artist_name_folds_case_diacritics_and_apostrophes() {
assert!(same_artist_name("Émilie D'Angelo", "emilie dangelo"));
assert!(same_artist_name("Yo-Yo Ma", "YO-YO MA"));
assert!(!same_artist_name("Watt", "Andrew Watt"));
assert!(!same_artist_name("", ""));
}
#[test]
fn featured_artists_dedupes_case_and_diacritics_and_ignores_crew() {
let p = "Émilie, FeaturedArtist - emilie, Vocalist, FeaturedArtist - Dan, Producer - Main, MainArtist";
+49 -5
View File
@@ -978,22 +978,66 @@ Rectangle {
}
}
Text {
id: artistLine
width: parent.width
visible: (root.item.artist || "") !== ""
// Main artist first, then the featured performers, one comma
// separated list. Local / media-server rows carry no
// `featured` and stay as they are.
text: (root.item.artist || "")
+ (root.showFeaturedArtists && (root.item.featured || "") !== ""
? ", " + root.item.featured : "")
// `featured` and stay as they are. With links enabled and
// featured names present, every name is its own StyledText
// link: the main artist opens its page as before; a featured
// name opens its page when the album credits gave it an id
// and the search for that name otherwise. StyledText elides
// like plain text (probed: truncated stays true on one line).
readonly property var featured: root.showFeaturedArtists ? (root.item.featured || []) : []
readonly property bool linkMode: root.artistLink && featured.length > 0
function esc(s) {
return String(s).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
}
function hex(c) {
return "#" + [c.r, c.g, c.b].map(function (v) {
return ("0" + Math.round(v * 255).toString(16)).slice(-2)
}).join("")
}
function link(href, name) {
var hot = artistLine.hoveredLink === href
return '<a href="' + href + '"><font color="'
+ hex(hot ? theme.textPrimary : theme.textMuted) + '">' + esc(name) + '</font></a>'
}
textFormat: linkMode ? Text.StyledText : Text.PlainText
text: {
var names = featured.map(function (f) { return f.name })
if (!linkMode)
return (root.item.artist || "") + (names.length ? ", " + names.join(", ") : "")
var parts = [root.item.artistId ? link("main", root.item.artist) : esc(root.item.artist)]
for (var i = 0; i < featured.length; i++)
parts.push(link("f:" + i, featured[i].name))
return parts.join(", ")
}
linkColor: theme.textMuted
color: root.artistLink && root.item.artistId && artistLinkArea.containsMouse
? theme.textPrimary : theme.textMuted
font.pixelSize: 12
elide: Text.ElideRight
onLinkActivated: function (href) {
if (href === "main") {
if (root.routeGoToExternally) root.goToRequested("artist")
else QbzArtist.openArtist(root.item.artistId)
return
}
var f = featured[parseInt(href.slice(2))]
if (!f) return
if (f.id) QbzArtist.openArtist(f.id)
else QbzSearch.searchSubmit(f.name)
}
HoverHandler {
enabled: artistLine.linkMode
cursorShape: artistLine.hoveredLink !== "" ? Qt.PointingHandCursor : Qt.ArrowCursor
}
MouseArea {
id: artistLinkArea
anchors.fill: parent
enabled: root.artistLink && !!root.item.artistId
enabled: root.artistLink && !!root.item.artistId && !artistLine.linkMode
hoverEnabled: true
cursorShape: enabled ? Qt.PointingHandCursor : Qt.ArrowCursor
// Same routing as the menu's "Go to artist" — Slint drives
+73 -12
View File
@@ -30,6 +30,7 @@ use std::time::Instant;
use cxx_qt_lib::QString;
use qbz_app::shell::AppRuntime;
use qbz_core::LoggingAdapter;
use qbz_models::types::AlbumArtist;
use qbz_models::{Album, Track};
use serde::{Deserialize, Serialize};
use serde_json::json;
@@ -41,9 +42,11 @@ const RELEASE_PAGE_SIZE: u32 = 20;
#[derive(Clone, Default, Serialize)]
pub struct TrackRow {
/// Featured performers already joined ("X, Y"); "" when none.
/// Featured performers, main artist excluded; `id` is the Qobuz artist id
/// when the album credits name the same person, "" otherwise (the row
/// then falls back to a search by name). Empty when none.
#[serde(rename = "featured")]
pub featured: String,
pub featured: Vec<FeaturedArtist>,
pub id: String,
pub number: String,
pub title: String,
@@ -512,16 +515,42 @@ fn build_credits(album: &Album) -> Vec<(String, String, String)> {
}
/// album.rs `map_track` (with work headers for classical albums).
/// "X, Y" for the row's `feat.` suffix (empty = nothing to add). Qobuz rows
/// only — local / media-server rows never carry `performers`.
pub(crate) fn featured_join(performers: Option<&str>, artist: &str, title: &str) -> String {
let Some(performers) = performers else {
return String::new();
};
qbz_qobuz::performers::featured_artists(performers, artist, title).join(", ")
/// One featured performer on a track row (see `TrackRow::featured`).
#[derive(Clone, Debug, Default, PartialEq, Serialize)]
pub struct FeaturedArtist {
pub name: String,
/// Qobuz artist id as a string, "" when unknown.
pub id: String,
}
fn map_track(track: &Track) -> TrackRow {
/// The row's featured performers (empty = nothing to add). Qobuz rows only —
/// local / media-server rows never carry `performers`. `credits` are the
/// album-level artists (id + roles) when the caller has them: a featured
/// name that matches a credit gets that credit's id and links straight to
/// the artist page; any other name links to a search.
pub(crate) fn featured_list(
performers: Option<&str>,
artist: &str,
title: &str,
credits: &[AlbumArtist],
) -> Vec<FeaturedArtist> {
let Some(performers) = performers else {
return Vec::new();
};
qbz_qobuz::performers::featured_artists(performers, artist, title)
.into_iter()
.map(|name| {
let id = credits
.iter()
.find(|c| qbz_qobuz::performers::same_artist_name(&c.name, &name))
.map(|c| c.id.to_string())
.unwrap_or_default();
FeaturedArtist { name, id }
})
.collect()
}
fn map_track(track: &Track, credits: &[AlbumArtist]) -> TrackRow {
let work = track
.work
.as_ref()
@@ -548,7 +577,7 @@ fn map_track(track: &Track) -> TrackRow {
.map(|p| (p.name.clone(), p.id.to_string()))
.unwrap_or_default();
TrackRow {
featured: featured_join(track.performers.as_deref(), &artist, &track.title),
featured: featured_list(track.performers.as_deref(), &artist, &track.title, credits),
is_favorite: crate::fav_cache_qt::contains_track(track.id),
id: track.id.to_string(),
number: track.track_number.to_string(),
@@ -679,10 +708,11 @@ pub async fn load_album(
let booklet_url = pick_booklet_url(&album);
set_booklet_stash(&title, &booklet_url);
let artist_credits: &[AlbumArtist] = album.artists.as_deref().unwrap_or(&[]);
let tracks: Vec<TrackRow> = album
.tracks
.as_ref()
.map(|container| container.items.iter().map(map_track).collect())
.map(|container| container.items.iter().map(|t| map_track(t, artist_credits)).collect())
.unwrap_or_default();
// External links are built from the SAME artist/title the header shows.
@@ -1509,3 +1539,34 @@ fn spawn_deferred_rows(
publish_row(generation, "similarAlbums", "similarLoading", &similar);
});
}
#[cfg(test)]
mod tests {
use super::*;
fn credit(id: u64, name: &str, role: &str) -> AlbumArtist {
AlbumArtist {
id,
name: name.into(),
roles: Some(vec![role.into()]),
}
}
#[test]
fn featured_list_resolves_ids_from_the_album_credits_and_leaves_the_rest_searchable() {
let performers = "Alice, MainArtist - Bob, FeaturedArtist - Carol, Vocalist, FeaturedArtist";
let credits = [credit(1, "Alice", "main-artist"), credit(2, "bob", "featured-artist")];
assert_eq!(
featured_list(Some(performers), "Alice", "Song", &credits),
vec![
FeaturedArtist { name: "Bob".into(), id: "2".into() },
FeaturedArtist { name: "Carol".into(), id: String::new() },
]
);
assert!(featured_list(None, "Alice", "Song", &credits).is_empty());
assert_eq!(
featured_list(Some(performers), "Alice", "Song", &[])[0],
FeaturedArtist { name: "Bob".into(), id: String::new() }
);
}
}
+1 -1
View File
@@ -594,7 +594,7 @@ fn map_track(index: usize, track: PageArtistTrack) -> TrackRow {
.and_then(|r| r.streamable)
.unwrap_or(true);
TrackRow {
featured: String::new(),
featured: Vec::new(),
is_favorite: crate::fav_cache_qt::contains_track(track.id),
id: track.id.to_string(),
cache_status: if crate::offline_qt::is_cached(&track.id.to_string()) {
+1 -1
View File
@@ -1048,7 +1048,7 @@ fn to_row(track: &Track) -> TrackRow {
let bit_depth = track.maximum_bit_depth;
let sample_rate = track.maximum_sampling_rate;
TrackRow {
featured: String::new(),
featured: Vec::new(),
id: track.id.to_string(),
title,
artist: track
+1 -1
View File
@@ -1358,7 +1358,7 @@ fn parse_top_track(index: usize, raw: &Value) -> TrackRow {
raw.get("release_date_stream").and_then(|v| v.as_str()),
);
TrackRow {
featured: String::new(),
featured: Vec::new(),
is_favorite: id
.parse::<u64>()
.map(crate::fav_cache_qt::contains_track)
+4 -4
View File
@@ -806,7 +806,7 @@ pub(crate) fn row_to_display(item: &RowItem) -> (PlaylistTrackRow, Option<QueueT
} => {
let art = artwork_path.clone().unwrap_or_default();
let row = PlaylistTrackRow {
featured: String::new(),
featured: Vec::new(),
id: track_id.to_string(),
playlist_track_id: *track_id,
title: title.clone(),
@@ -881,7 +881,7 @@ pub(crate) fn row_to_display(item: &RowItem) -> (PlaylistTrackRow, Option<QueueT
)
.unwrap_or_default();
let row = PlaylistTrackRow {
featured: String::new(),
featured: Vec::new(),
id: queue.id.to_string(),
playlist_track_id: queue.id,
title: t.title.clone(),
@@ -932,7 +932,7 @@ pub(crate) fn row_to_display(item: &RowItem) -> (PlaylistTrackRow, Option<QueueT
.unwrap_or_else(|| path.clone());
(
PlaylistTrackRow {
featured: String::new(),
featured: Vec::new(),
id: path.clone(),
title: name,
source: "local".to_string(),
@@ -945,7 +945,7 @@ pub(crate) fn row_to_display(item: &RowItem) -> (PlaylistTrackRow, Option<QueueT
}
RowItem::Unresolved { kind, reference } => (
PlaylistTrackRow {
featured: String::new(),
featured: Vec::new(),
id: format!("{kind}:{reference}"),
title: qbz_i18n::t("Unavailable track"),
source: (*kind).to_string(),
+3 -3
View File
@@ -59,9 +59,9 @@ use serde::Serialize;
#[derive(Clone, Default, Serialize)]
pub struct PlaylistTrackRow {
/// Featured performers already joined ("X, Y"); "" when none.
/// Featured performers (see `album_qt::TrackRow::featured`); empty when none.
#[serde(rename = "featured")]
pub featured: String,
pub featured: Vec<crate::album_qt::FeaturedArtist>,
pub id: String,
/// The playlist membership row id (== catalog track id for Qobuz
/// playlists — what remove_tracks_from_playlist takes).
@@ -865,7 +865,7 @@ pub(crate) fn map_track(track: &Track) -> PlaylistTrackRow {
.map(|p| (p.name, p.id.to_string()))
.unwrap_or_default();
PlaylistTrackRow {
featured: crate::album_qt::featured_join(track.performers.as_deref(), &artist, &track.title),
featured: crate::album_qt::featured_list(track.performers.as_deref(), &artist, &track.title, &[]),
// Heart state at build time, from the favourite-id cache — the same
// O(1) read `album_qt` / `artist_qt` / `label_qt` rows use. It was
// never stamped here, so `TrackRow.qml` saw `undefined` on every
+3 -3
View File
@@ -194,9 +194,9 @@ pub struct CardRow {
#[derive(Clone, Default, Serialize)]
pub struct TrackRow {
/// Featured performers already joined ("X, Y"); "" when none.
/// Featured performers (see `album_qt::TrackRow::featured`); empty when none.
#[serde(rename = "featured")]
pub featured: String,
pub featured: Vec<crate::album_qt::FeaturedArtist>,
pub id: String,
pub title: String,
pub artist: String,
@@ -407,7 +407,7 @@ fn map_track(track: &Track) -> TrackRow {
.map(|p| (p.name, p.id.to_string()))
.unwrap_or_default();
TrackRow {
featured: crate::album_qt::featured_join(track.performers.as_deref(), &artist, &track.title),
featured: crate::album_qt::featured_list(track.performers.as_deref(), &artist, &track.title, &[]),
// Same story as `map_album`: the field was declared (line 186) and
// never stamped, so every search track row drew the empty heart and
// the first click sent `favorite/delete` on a track the user had