feat: artist/page endpoint, multi-disc fix, playlist ownership, UX improvements
- Switch artist view to artist/page API (proper sections: Albums, Singles & EPs, Live, Compilations; version in titles like "Deluxe") - Fix artist sections categorization using releases[].type from artist/page - Add getUser() backend call; fetch on session restore when userId=0 to fix playlist ownership (Remove from playlist / Delete playlist were missing) - Fix multi-disc double-click / Play Now queue start index (disc headers were counted in row index but excluded from currentTracksJson) - Hide redundant Album column when viewing an album - Make artist name in context header clickable (navigates to artist page) - Fix gap between title and artist name in context header (addStretch) - Fix queue panel track titles to include version field - Fix album list to show version in title column Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,7 @@ enum QobuzEvent {
|
||||
EV_PLAYLIST_CREATED = 20,
|
||||
EV_PLAYLIST_DELETED = 21,
|
||||
EV_PLAYLIST_TRACK_ADDED = 22,
|
||||
EV_USER_OK = 23,
|
||||
};
|
||||
|
||||
// Callback signature
|
||||
@@ -46,6 +47,7 @@ void qobuz_backend_free(QobuzBackendOpaque *backend);
|
||||
// Auth
|
||||
void qobuz_backend_login(QobuzBackendOpaque *backend, const char *email, const char *password);
|
||||
void qobuz_backend_set_token(QobuzBackendOpaque *backend, const char *token);
|
||||
void qobuz_backend_get_user(QobuzBackendOpaque *backend);
|
||||
|
||||
// Catalog
|
||||
void qobuz_backend_search(QobuzBackendOpaque *backend, const char *query, uint32_t offset, uint32_t limit);
|
||||
|
||||
@@ -266,6 +266,15 @@ impl QobuzClient {
|
||||
Ok(serde_json::from_value(body)?)
|
||||
}
|
||||
|
||||
pub async fn get_artist_page(&self, artist_id: i64) -> Result<Value> {
|
||||
let resp = self
|
||||
.get_request("artist/page")
|
||||
.query(&[("artist_id", artist_id.to_string())])
|
||||
.send()
|
||||
.await?;
|
||||
Self::check_response(resp).await
|
||||
}
|
||||
|
||||
// --- Search ---
|
||||
|
||||
pub async fn search(&self, query: &str, offset: u32, limit: u32) -> Result<SearchCatalogDto> {
|
||||
|
||||
@@ -46,6 +46,7 @@ pub struct SubscriptionDto {
|
||||
pub struct TrackDto {
|
||||
pub id: i64,
|
||||
pub title: Option<String>,
|
||||
pub version: Option<String>,
|
||||
pub duration: Option<i64>,
|
||||
pub track_number: Option<i32>,
|
||||
pub playlist_track_id: Option<i64>,
|
||||
@@ -120,6 +121,10 @@ pub struct ArtistDto {
|
||||
pub image: Option<ImageDto>,
|
||||
pub biography: Option<BiographyDto>,
|
||||
pub albums: Option<SearchResultItems<AlbumDto>>,
|
||||
#[serde(rename = "epSingles")]
|
||||
pub ep_singles: Option<SearchResultItems<AlbumDto>>,
|
||||
#[serde(rename = "liveAlbums")]
|
||||
pub live_albums: Option<SearchResultItems<AlbumDto>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Clone, Serialize)]
|
||||
|
||||
@@ -239,7 +239,7 @@ pub unsafe extern "C" fn qobuz_backend_get_artist(ptr: *mut Backend, artist_id:
|
||||
let cb = inner.cb; let ud = inner.ud;
|
||||
|
||||
spawn(inner, async move {
|
||||
let result = client.lock().await.get_artist(artist_id).await;
|
||||
let result = client.lock().await.get_artist_page(artist_id).await;
|
||||
let (ev, json) = match result {
|
||||
Ok(r) => (EV_ARTIST_OK, serde_json::to_string(&r).unwrap_or_default()),
|
||||
Err(e) => (EV_ARTIST_ERR, err_json(&e.to_string())),
|
||||
@@ -563,6 +563,25 @@ pub unsafe extern "C" fn qobuz_backend_remove_fav_album(ptr: *mut Backend, album
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- User ----------
|
||||
|
||||
pub const EV_USER_OK: c_int = 23;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn qobuz_backend_get_user(ptr: *mut Backend) {
|
||||
let inner = &(*ptr).0;
|
||||
let client = inner.client.clone();
|
||||
let cb = inner.cb; let ud = inner.ud;
|
||||
spawn(inner, async move {
|
||||
let result = client.lock().await.get_user().await;
|
||||
let (ev, json) = match result {
|
||||
Ok(r) => (EV_USER_OK, serde_json::to_string(&r).unwrap_or_default()),
|
||||
Err(e) => (EV_GENERIC_ERR, err_json(&e.to_string())),
|
||||
};
|
||||
call_cb(cb, ud, ev, &json);
|
||||
});
|
||||
}
|
||||
|
||||
// ---------- Playlist management ----------
|
||||
|
||||
pub const EV_PLAYLIST_CREATED: c_int = 20;
|
||||
|
||||
@@ -35,6 +35,11 @@ void QobuzBackend::setToken(const QString &token)
|
||||
qobuz_backend_set_token(m_backend, token.toUtf8().constData());
|
||||
}
|
||||
|
||||
void QobuzBackend::getUser()
|
||||
{
|
||||
qobuz_backend_get_user(m_backend);
|
||||
}
|
||||
|
||||
// ---- catalog ----
|
||||
|
||||
void QobuzBackend::search(const QString &query, quint32 offset, quint32 limit)
|
||||
@@ -249,6 +254,9 @@ void QobuzBackend::onEvent(int eventType, const QString &json)
|
||||
case 22: // EV_PLAYLIST_TRACK_ADDED
|
||||
emit playlistTrackAdded(static_cast<qint64>(obj["playlist_id"].toDouble()));
|
||||
break;
|
||||
case EV_USER_OK:
|
||||
emit userLoaded(obj);
|
||||
break;
|
||||
case EV_GENERIC_ERR:
|
||||
case EV_TRACK_URL_ERR:
|
||||
emit error(obj["error"].toString());
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
// --- auth ---
|
||||
void login(const QString &email, const QString &password);
|
||||
void setToken(const QString &token);
|
||||
void getUser();
|
||||
|
||||
// --- catalog ---
|
||||
void search(const QString &query, quint32 offset = 0, quint32 limit = 20);
|
||||
@@ -71,6 +72,7 @@ signals:
|
||||
// auth
|
||||
void loginSuccess(const QString &token, const QJsonObject &user);
|
||||
void loginError(const QString &error);
|
||||
void userLoaded(const QJsonObject &user);
|
||||
|
||||
// catalog
|
||||
void searchResult(const QJsonObject &result);
|
||||
|
||||
@@ -35,24 +35,32 @@ Tracks::Tracks(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
||||
this, &Tracks::onDoubleClicked);
|
||||
connect(this, &QTreeView::customContextMenuRequested,
|
||||
this, &Tracks::onContextMenu);
|
||||
connect(m_model, &QAbstractItemModel::modelReset, this, [this] {
|
||||
for (int row : m_model->discHeaderRows())
|
||||
setFirstColumnSpanned(row, {}, true);
|
||||
setSortingEnabled(!m_model->hasMultipleDiscs());
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void Tracks::loadTracks(const QJsonArray &tracks)
|
||||
{
|
||||
setPlaylistContext(0);
|
||||
setColumnHidden(TrackListModel::ColAlbum, false);
|
||||
m_model->setTracks(tracks, false, /*useSequential=*/true);
|
||||
}
|
||||
|
||||
void Tracks::loadAlbum(const QJsonObject &album)
|
||||
{
|
||||
setPlaylistContext(0);
|
||||
setColumnHidden(TrackListModel::ColAlbum, true);
|
||||
const QJsonArray items = album["tracks"].toObject()["items"].toArray();
|
||||
m_model->setTracks(items); // album: use track_number
|
||||
}
|
||||
|
||||
void Tracks::loadPlaylist(const QJsonObject &playlist)
|
||||
{
|
||||
setColumnHidden(TrackListModel::ColAlbum, false);
|
||||
const qint64 id = static_cast<qint64>(playlist["id"].toDouble());
|
||||
const qint64 ownId = static_cast<qint64>(playlist["owner"].toObject()["id"].toDouble());
|
||||
const qint64 myId = AppSettings::instance().userId();
|
||||
@@ -65,6 +73,7 @@ void Tracks::loadPlaylist(const QJsonObject &playlist)
|
||||
void Tracks::loadSearchTracks(const QJsonArray &tracks)
|
||||
{
|
||||
setPlaylistContext(0);
|
||||
setColumnHidden(TrackListModel::ColAlbum, false);
|
||||
m_model->setTracks(tracks, false, /*useSequential=*/true);
|
||||
}
|
||||
|
||||
@@ -118,7 +127,11 @@ void Tracks::onDoubleClicked(const QModelIndex &index)
|
||||
{
|
||||
const qint64 id = m_model->data(index, TrackListModel::TrackIdRole).toLongLong();
|
||||
if (id > 0) {
|
||||
m_queue->setContext(m_model->currentTracksJson(), index.row());
|
||||
// Compute filtered row (disc headers excluded from currentTracksJson)
|
||||
int filteredRow = 0;
|
||||
for (int r = 0; r < index.row(); ++r)
|
||||
if (!m_model->trackAt(r).isDiscHeader) ++filteredRow;
|
||||
m_queue->setContext(m_model->currentTracksJson(), filteredRow);
|
||||
emit playTrackRequested(id);
|
||||
}
|
||||
}
|
||||
@@ -129,6 +142,7 @@ void Tracks::onContextMenu(const QPoint &pos)
|
||||
if (!index.isValid()) return;
|
||||
|
||||
const qint64 id = m_model->data(index, TrackListModel::TrackIdRole).toLongLong();
|
||||
if (id <= 0) return; // disc header row
|
||||
const QJsonObject trackJson = m_model->data(index, TrackListModel::TrackJsonRole).toJsonObject();
|
||||
|
||||
QMenu menu(this);
|
||||
@@ -153,9 +167,12 @@ void Tracks::onContextMenu(const QPoint &pos)
|
||||
});
|
||||
}
|
||||
|
||||
const int row = index.row();
|
||||
connect(playNow, &QAction::triggered, this, [this, id, row] {
|
||||
m_queue->setContext(m_model->currentTracksJson(), row);
|
||||
// Compute filtered row for multi-disc albums (disc headers excluded from currentTracksJson)
|
||||
int filteredRow = 0;
|
||||
for (int r = 0; r < index.row(); ++r)
|
||||
if (!m_model->trackAt(r).isDiscHeader) ++filteredRow;
|
||||
connect(playNow, &QAction::triggered, this, [this, id, filteredRow] {
|
||||
m_queue->setContext(m_model->currentTracksJson(), filteredRow);
|
||||
emit playTrackRequested(id);
|
||||
});
|
||||
connect(playNext, &QAction::triggered, this, [this, trackJson] {
|
||||
|
||||
@@ -72,6 +72,13 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
// ---- Backend signals ----
|
||||
connect(m_backend, &QobuzBackend::loginSuccess, this, &MainWindow::onLoginSuccess);
|
||||
connect(m_backend, &QobuzBackend::loginError, this, &MainWindow::onLoginError);
|
||||
connect(m_backend, &QobuzBackend::userLoaded, this, [this](const QJsonObject &user) {
|
||||
const qint64 id = static_cast<qint64>(user["id"].toDouble());
|
||||
if (id > 0) {
|
||||
AppSettings::instance().setUserId(id);
|
||||
m_library->refresh(); // re-load playlists with correct ownership now
|
||||
}
|
||||
});
|
||||
connect(m_backend, &QobuzBackend::favTracksLoaded, this, &MainWindow::onFavTracksLoaded);
|
||||
connect(m_backend, &QobuzBackend::favAlbumsLoaded, this, &MainWindow::onFavAlbumsLoaded);
|
||||
connect(m_backend, &QobuzBackend::favArtistsLoaded, this, &MainWindow::onFavArtistsLoaded);
|
||||
@@ -199,7 +206,10 @@ void MainWindow::tryRestoreSession()
|
||||
const QString token = AppSettings::instance().authToken();
|
||||
if (!token.isEmpty()) {
|
||||
m_backend->setToken(token);
|
||||
m_library->refresh();
|
||||
if (AppSettings::instance().userId() == 0)
|
||||
m_backend->getUser(); // userLoaded will call m_library->refresh()
|
||||
else
|
||||
m_library->refresh();
|
||||
const QString name = AppSettings::instance().displayName();
|
||||
statusBar()->showMessage(tr("Signed in as %1").arg(
|
||||
name.isEmpty() ? AppSettings::instance().userEmail() : name));
|
||||
|
||||
@@ -17,17 +17,27 @@ void TrackListModel::setTracks(const QJsonArray &tracks,
|
||||
m_tracks.clear();
|
||||
m_tracks.reserve(tracks.size());
|
||||
|
||||
// Parse into a temporary list first so we can detect multi-disc
|
||||
QVector<TrackItem> parsed;
|
||||
parsed.reserve(tracks.size());
|
||||
|
||||
int seq = 1;
|
||||
for (const QJsonValue &v : tracks) {
|
||||
const QJsonObject t = v.toObject();
|
||||
TrackItem item;
|
||||
item.id = static_cast<qint64>(t["id"].toDouble());
|
||||
item.playlistTrackId = static_cast<qint64>(t["playlist_track_id"].toDouble());
|
||||
item.title = t["title"].toString();
|
||||
item.discNumber = t["media_number"].toInt(1);
|
||||
item.duration = static_cast<qint64>(t["duration"].toDouble());
|
||||
item.hiRes = t["hires_streamable"].toBool();
|
||||
item.streamable = t["streamable"].toBool(true);
|
||||
item.raw = t;
|
||||
item.streamable = t["streamable"].toBool(true);
|
||||
item.hiRes = t["hires_streamable"].toBool();
|
||||
item.raw = t;
|
||||
|
||||
// Combine title + version ("Melody" + "Vocal Remix" → "Melody (Vocal Remix)")
|
||||
const QString base = t["title"].toString();
|
||||
const QString version = t["version"].toString().trimmed();
|
||||
item.title = version.isEmpty() ? base
|
||||
: base + QStringLiteral(" (") + version + QLatin1Char(')');
|
||||
|
||||
if (useSequential) {
|
||||
item.number = seq++;
|
||||
@@ -48,17 +58,46 @@ void TrackListModel::setTracks(const QJsonArray &tracks,
|
||||
item.album = album["title"].toString();
|
||||
item.albumId = album["id"].toString();
|
||||
|
||||
m_tracks.append(item);
|
||||
parsed.append(item);
|
||||
}
|
||||
|
||||
// Re-apply sort silently inside the reset (no layout signals needed here)
|
||||
if (m_sortColumn >= 0)
|
||||
sortData(m_sortColumn, m_sortOrder);
|
||||
// Multi-disc only makes sense for album context (not playlists / fav / search)
|
||||
int maxDisc = 1;
|
||||
if (!usePosition && !useSequential) {
|
||||
for (const TrackItem &t : parsed)
|
||||
maxDisc = qMax(maxDisc, t.discNumber);
|
||||
}
|
||||
m_hasMultipleDiscs = (maxDisc > 1);
|
||||
|
||||
if (m_hasMultipleDiscs) {
|
||||
// Sort by disc then track number
|
||||
std::stable_sort(parsed.begin(), parsed.end(), [](const TrackItem &a, const TrackItem &b) {
|
||||
return a.discNumber != b.discNumber ? a.discNumber < b.discNumber
|
||||
: a.number < b.number;
|
||||
});
|
||||
// Interleave disc header items
|
||||
int currentDisc = -1;
|
||||
for (const TrackItem &t : parsed) {
|
||||
if (t.discNumber != currentDisc) {
|
||||
TrackItem header;
|
||||
header.isDiscHeader = true;
|
||||
header.discNumber = t.discNumber;
|
||||
header.title = tr("Disc %1").arg(t.discNumber);
|
||||
m_tracks.append(header);
|
||||
currentDisc = t.discNumber;
|
||||
}
|
||||
m_tracks.append(t);
|
||||
}
|
||||
} else {
|
||||
m_tracks = parsed;
|
||||
// Re-apply sort silently inside the reset
|
||||
if (m_sortColumn >= 0)
|
||||
sortData(m_sortColumn, m_sortOrder);
|
||||
}
|
||||
|
||||
endResetModel();
|
||||
|
||||
// Tell external listeners the sorted order is ready (e.g. PlayQueue sync)
|
||||
if (m_sortColumn >= 0)
|
||||
if (!m_hasMultipleDiscs && m_sortColumn >= 0)
|
||||
emit sortApplied();
|
||||
}
|
||||
|
||||
@@ -115,6 +154,23 @@ void TrackListModel::setPlayingId(qint64 id)
|
||||
{Qt::FontRole, Qt::DecorationRole});
|
||||
}
|
||||
|
||||
Qt::ItemFlags TrackListModel::flags(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= m_tracks.size())
|
||||
return Qt::NoItemFlags;
|
||||
if (m_tracks.at(index.row()).isDiscHeader)
|
||||
return Qt::ItemIsEnabled;
|
||||
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||
}
|
||||
|
||||
QVector<int> TrackListModel::discHeaderRows() const
|
||||
{
|
||||
QVector<int> rows;
|
||||
for (int i = 0; i < m_tracks.size(); ++i)
|
||||
if (m_tracks[i].isDiscHeader) rows.append(i);
|
||||
return rows;
|
||||
}
|
||||
|
||||
int TrackListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return parent.isValid() ? 0 : m_tracks.size();
|
||||
@@ -131,6 +187,19 @@ QVariant TrackListModel::data(const QModelIndex &index, int role) const
|
||||
return {};
|
||||
|
||||
const TrackItem &t = m_tracks.at(index.row());
|
||||
|
||||
// Disc header rows: styled separator spanning all columns via setFirstColumnSpanned
|
||||
if (t.isDiscHeader) {
|
||||
if (role == Qt::DisplayRole && index.column() == ColNumber)
|
||||
return t.title;
|
||||
if (role == Qt::FontRole) {
|
||||
QFont f; f.setBold(true); return f;
|
||||
}
|
||||
if (role == Qt::ForegroundRole)
|
||||
return QColor(0xFF, 0xB2, 0x32);
|
||||
return {};
|
||||
}
|
||||
|
||||
const bool isPlaying = (t.id == m_playingId && m_playingId != 0);
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
@@ -213,7 +282,8 @@ void TrackListModel::sort(int column, Qt::SortOrder order)
|
||||
m_sortColumn = column;
|
||||
m_sortOrder = order;
|
||||
|
||||
if (m_tracks.isEmpty()) return;
|
||||
// Multi-disc albums keep their disc-ordered layout; don't re-sort
|
||||
if (m_hasMultipleDiscs || m_tracks.isEmpty()) return;
|
||||
|
||||
emit layoutAboutToBeChanged();
|
||||
sortData(column, order);
|
||||
|
||||
@@ -11,6 +11,8 @@ struct TrackItem {
|
||||
qint64 id = 0;
|
||||
qint64 playlistTrackId = 0;
|
||||
int number = 0;
|
||||
int discNumber = 1;
|
||||
bool isDiscHeader = false;
|
||||
QString title;
|
||||
QString artist;
|
||||
QString album;
|
||||
@@ -58,17 +60,22 @@ public:
|
||||
void removeFavId(qint64 id);
|
||||
bool isFav(qint64 id) const { return m_favIds.contains(id); }
|
||||
|
||||
bool hasMultipleDiscs() const { return m_hasMultipleDiscs; }
|
||||
QVector<int> discHeaderRows() const;
|
||||
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||
|
||||
/// Optimistically remove a row (e.g. after deleting from playlist).
|
||||
void removeTrack(int row);
|
||||
|
||||
const TrackItem &trackAt(int row) const { return m_tracks.at(row); }
|
||||
|
||||
// Returns the current (possibly sorted) raw JSON objects in display order.
|
||||
// Returns the current (possibly sorted) raw JSON objects in display order, skipping disc headers.
|
||||
QJsonArray currentTracksJson() const
|
||||
{
|
||||
QJsonArray out;
|
||||
for (const auto &t : m_tracks)
|
||||
out.append(t.raw);
|
||||
if (!t.isDiscHeader) out.append(t.raw);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -88,7 +95,8 @@ signals:
|
||||
private:
|
||||
QVector<TrackItem> m_tracks;
|
||||
QSet<qint64> m_favIds;
|
||||
qint64 m_playingId = 0;
|
||||
qint64 m_playingId = 0;
|
||||
bool m_hasMultipleDiscs = false;
|
||||
int m_sortColumn = -1;
|
||||
Qt::SortOrder m_sortOrder = Qt::AscendingOrder;
|
||||
|
||||
|
||||
@@ -47,13 +47,27 @@ public:
|
||||
|
||||
for (const auto &v : albums) {
|
||||
const QJsonObject a = v.toObject();
|
||||
const QString id = a["id"].toString();
|
||||
const QString title = a["title"].toString();
|
||||
const QString artist = a["artist"].toObject()["name"].toString();
|
||||
const QString date = a["release_date_original"].toString();
|
||||
const QString year = date.left(4);
|
||||
const int tracks = a["tracks_count"].toInt();
|
||||
const bool hiRes = a["hires_streamable"].toBool();
|
||||
const QString id = a["id"].toString();
|
||||
const QString base = a["title"].toString();
|
||||
const QString ver = a["version"].toString().trimmed();
|
||||
const QString title = ver.isEmpty() ? base : base + QStringLiteral(" (") + ver + QLatin1Char(')');
|
||||
|
||||
// artist.name is either a plain string (old AlbumDto) or {display: ...} (artist/page)
|
||||
const QJsonValue artistNameVal = a["artist"].toObject()["name"];
|
||||
const QString artist = artistNameVal.isObject()
|
||||
? artistNameVal.toObject()["display"].toString()
|
||||
: artistNameVal.toString();
|
||||
|
||||
// year: release_date_original (old) or dates.original (artist/page)
|
||||
const QString date = a["release_date_original"].toString();
|
||||
const QString year = date.isEmpty()
|
||||
? a["dates"].toObject()["original"].toString().left(4)
|
||||
: date.left(4);
|
||||
|
||||
const int tracks = a["tracks_count"].toInt();
|
||||
// hires: flat field (old) or rights.hires_streamable (artist/page)
|
||||
const bool hiRes = a["hires_streamable"].toBool()
|
||||
|| a["rights"].toObject()["hires_streamable"].toBool();
|
||||
|
||||
auto *item = new QTreeWidgetItem(this);
|
||||
if (hiRes) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <QScrollArea>
|
||||
#include <QFont>
|
||||
#include <QJsonValue>
|
||||
#include <QRegularExpression>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ArtistSection
|
||||
@@ -104,50 +105,74 @@ ArtistView::ArtistView(QWidget *parent)
|
||||
sectLayout->setContentsMargins(0, 0, 0, 0);
|
||||
sectLayout->setSpacing(8);
|
||||
|
||||
m_secAlbums = new ArtistSection(tr("Albums"), content);
|
||||
m_secEps = new ArtistSection(tr("EPs & Singles"), content);
|
||||
m_secOther = new ArtistSection(tr("Other"), content);
|
||||
m_secAlbums = new ArtistSection(tr("Albums"), content);
|
||||
m_secEps = new ArtistSection(tr("Singles & EPs"), content);
|
||||
m_secLive = new ArtistSection(tr("Live"), content);
|
||||
m_secCompilations = new ArtistSection(tr("Compilations"), content);
|
||||
m_secOther = new ArtistSection(tr("Other"), content);
|
||||
|
||||
sectLayout->addWidget(m_secAlbums);
|
||||
sectLayout->addWidget(m_secEps);
|
||||
sectLayout->addWidget(m_secLive);
|
||||
sectLayout->addWidget(m_secCompilations);
|
||||
sectLayout->addWidget(m_secOther);
|
||||
sectLayout->addStretch();
|
||||
|
||||
scroll->setWidget(content);
|
||||
outerLayout->addWidget(scroll, 1);
|
||||
|
||||
connect(m_secAlbums, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
||||
connect(m_secEps, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
||||
connect(m_secOther, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
||||
connect(m_secAlbums, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
||||
connect(m_secEps, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
||||
connect(m_secLive, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
||||
connect(m_secCompilations, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
||||
connect(m_secOther, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
||||
}
|
||||
|
||||
void ArtistView::setArtist(const QJsonObject &artist)
|
||||
{
|
||||
m_nameLabel->setText(artist["name"].toString());
|
||||
// artist/page: name is {"display": "..."}
|
||||
m_nameLabel->setText(artist["name"].toObject()["display"].toString());
|
||||
|
||||
const QString summary = artist["biography"].toObject()["summary"].toString();
|
||||
m_bioLabel->setText(summary);
|
||||
m_bioLabel->setVisible(!summary.isEmpty());
|
||||
// biography.content is HTML — strip tags for the summary label
|
||||
const QString bioHtml = artist["biography"].toObject()["content"].toString();
|
||||
if (!bioHtml.isEmpty()) {
|
||||
// Remove HTML tags for plain-text display
|
||||
QString plain = bioHtml;
|
||||
plain.remove(QRegularExpression(QStringLiteral("<[^>]*>")));
|
||||
plain = plain.trimmed();
|
||||
m_bioLabel->setText(plain);
|
||||
m_bioLabel->setVisible(true);
|
||||
} else {
|
||||
m_bioLabel->setVisible(false);
|
||||
}
|
||||
|
||||
const QJsonArray allAlbums = artist["albums"].toObject()["items"].toArray();
|
||||
|
||||
QJsonArray albums, eps, other;
|
||||
for (const QJsonValue &v : allAlbums) {
|
||||
const QJsonObject a = v.toObject();
|
||||
const QString rt = a["release_type"].toString();
|
||||
if (rt == QStringLiteral("album"))
|
||||
albums.append(a);
|
||||
else if (rt == QStringLiteral("epSingle"))
|
||||
eps.append(a);
|
||||
else
|
||||
other.append(a);
|
||||
// releases is an array of {type, has_more, items[]}
|
||||
// types we care about: "album", "epSingle", "live"
|
||||
const QJsonArray releases = artist["releases"].toArray();
|
||||
QJsonArray albums, eps, live, compilations;
|
||||
for (const QJsonValue &rv : releases) {
|
||||
const QJsonObject rg = rv.toObject();
|
||||
const QString type = rg["type"].toString();
|
||||
const QJsonArray items = rg["items"].toArray();
|
||||
if (type == QStringLiteral("album"))
|
||||
albums = items;
|
||||
else if (type == QStringLiteral("epSingle"))
|
||||
eps = items;
|
||||
else if (type == QStringLiteral("live"))
|
||||
live = items;
|
||||
else if (type == QStringLiteral("compilation"))
|
||||
compilations = items;
|
||||
}
|
||||
|
||||
m_secAlbums->setAlbums(albums);
|
||||
m_secEps->setAlbums(eps);
|
||||
m_secOther->setAlbums(other);
|
||||
m_secLive->setAlbums(live);
|
||||
m_secCompilations->setAlbums(compilations);
|
||||
m_secOther->setAlbums({});
|
||||
|
||||
m_secAlbums->setVisible(!m_secAlbums->isEmpty());
|
||||
m_secEps->setVisible(!m_secEps->isEmpty());
|
||||
m_secOther->setVisible(!m_secOther->isEmpty());
|
||||
m_secLive->setVisible(!m_secLive->isEmpty());
|
||||
m_secCompilations->setVisible(!m_secCompilations->isEmpty());
|
||||
m_secOther->setVisible(false);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,9 @@ signals:
|
||||
private:
|
||||
QLabel *m_nameLabel = nullptr;
|
||||
QLabel *m_bioLabel = nullptr;
|
||||
ArtistSection *m_secAlbums = nullptr;
|
||||
ArtistSection *m_secEps = nullptr;
|
||||
ArtistSection *m_secOther = nullptr;
|
||||
ArtistSection *m_secAlbums = nullptr;
|
||||
ArtistSection *m_secEps = nullptr;
|
||||
ArtistSection *m_secLive = nullptr;
|
||||
ArtistSection *m_secCompilations = nullptr;
|
||||
ArtistSection *m_secOther = nullptr;
|
||||
};
|
||||
|
||||
@@ -36,6 +36,11 @@ MainContent::MainContent(QobuzBackend *backend, PlayQueue *queue, QWidget *paren
|
||||
[this] { m_tracks->playAll(false); });
|
||||
QObject::connect(m_header->shuffleButton(), &QPushButton::clicked,
|
||||
[this] { m_tracks->playAll(true); });
|
||||
QObject::connect(m_header->subtitleButton(), &QPushButton::clicked,
|
||||
[this] {
|
||||
const qint64 id = m_header->artistId();
|
||||
if (id > 0) emit artistRequested(id);
|
||||
});
|
||||
|
||||
m_albumList = new AlbumListView(this);
|
||||
m_artistList = new ArtistListView(this);
|
||||
|
||||
@@ -173,7 +173,9 @@ void QueuePanel::refresh()
|
||||
|
||||
for (int i = 0; i < upcoming.size(); ++i) {
|
||||
const QJsonObject &t = upcoming.at(i);
|
||||
const QString title = t["title"].toString();
|
||||
const QString base = t["title"].toString();
|
||||
const QString ver = t["version"].toString().trimmed();
|
||||
const QString title = ver.isEmpty() ? base : base + QStringLiteral(" (") + ver + QLatin1Char(')');
|
||||
const QString artist = t["performer"].toObject()["name"].toString().isEmpty()
|
||||
? t["album"].toObject()["artist"].toObject()["name"].toString()
|
||||
: t["performer"].toObject()["name"].toString();
|
||||
|
||||
@@ -49,11 +49,16 @@ public:
|
||||
m_title->setWordWrap(true);
|
||||
vlay->addWidget(m_title);
|
||||
|
||||
m_subtitle = new QLabel(info);
|
||||
m_subtitle = new QPushButton(info);
|
||||
m_subtitle->setFlat(true);
|
||||
m_subtitle->setStyleSheet(QStringLiteral(
|
||||
"QPushButton { border: none; background: none; text-align: left; padding: 0; margin: 0; }"
|
||||
"QPushButton:enabled:hover { color: #FFB232; }"
|
||||
"QPushButton:!enabled { color: palette(text); }"
|
||||
));
|
||||
QFont sf = m_subtitle->font();
|
||||
sf.setPointSize(sf.pointSize() + 1);
|
||||
m_subtitle->setFont(sf);
|
||||
m_subtitle->setWordWrap(true);
|
||||
vlay->addWidget(m_subtitle);
|
||||
|
||||
m_meta = new QLabel(info);
|
||||
@@ -90,6 +95,7 @@ public:
|
||||
|
||||
btnRow->addStretch();
|
||||
vlay->addLayout(btnRow);
|
||||
vlay->addStretch(1);
|
||||
|
||||
hlay->addWidget(info, 1);
|
||||
|
||||
@@ -108,10 +114,16 @@ public:
|
||||
QPushButton *playButton() { return m_playBtn; }
|
||||
QPushButton *shuffleButton() { return m_shuffleBtn; }
|
||||
|
||||
QPushButton *subtitleButton() { return m_subtitle; }
|
||||
qint64 artistId() const { return m_artistId; }
|
||||
|
||||
void setAlbum(const QJsonObject &album)
|
||||
{
|
||||
m_title->setText(album["title"].toString());
|
||||
m_artistId = static_cast<qint64>(album["artist"].toObject()["id"].toDouble());
|
||||
m_subtitle->setText(album["artist"].toObject()["name"].toString());
|
||||
m_subtitle->setEnabled(m_artistId > 0);
|
||||
m_subtitle->setCursor(m_artistId > 0 ? Qt::PointingHandCursor : Qt::ArrowCursor);
|
||||
m_meta->setText(buildAlbumMeta(album));
|
||||
fetchArt(album["image"].toObject());
|
||||
show();
|
||||
@@ -120,9 +132,12 @@ public:
|
||||
void setPlaylist(const QJsonObject &playlist)
|
||||
{
|
||||
m_title->setText(playlist["name"].toString());
|
||||
m_artistId = 0;
|
||||
const QString desc = playlist["description"].toString();
|
||||
const QString owner = playlist["owner"].toObject()["name"].toString();
|
||||
m_subtitle->setText(desc.isEmpty() ? owner : desc);
|
||||
m_subtitle->setEnabled(false);
|
||||
m_subtitle->setCursor(Qt::ArrowCursor);
|
||||
m_meta->setText(buildPlaylistMeta(playlist));
|
||||
|
||||
// Try images300 → images150 → images (API returns mosaic arrays, not image_rectangle)
|
||||
@@ -200,10 +215,11 @@ private:
|
||||
|
||||
QLabel *m_art = nullptr;
|
||||
QLabel *m_title = nullptr;
|
||||
QLabel *m_subtitle = nullptr;
|
||||
QPushButton *m_subtitle = nullptr;
|
||||
QLabel *m_meta = nullptr;
|
||||
QPushButton *m_playBtn = nullptr;
|
||||
QPushButton *m_shuffleBtn = nullptr;
|
||||
QNetworkAccessManager *m_nam = nullptr;
|
||||
QString m_currentArtUrl;
|
||||
qint64 m_artistId = 0;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user