Compare commits
6 Commits
feat/playl
...
5d0011cb90
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d0011cb90 | ||
|
|
5bda2396d1 | ||
|
|
eb5c151d3a | ||
|
|
872fdecdce | ||
|
|
69fb818c38 | ||
|
|
56473cae6f |
@@ -88,9 +88,18 @@ if (UNIX AND NOT APPLE)
|
|||||||
target_link_libraries(qobuz-qt PRIVATE asound)
|
target_link_libraries(qobuz-qt PRIVATE asound)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# Compiler warnings
|
# Compiler warnings + hardening
|
||||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||||
target_compile_options(qobuz-qt PRIVATE -Wall -Wextra -Wno-unused-parameter)
|
target_compile_options(qobuz-qt PRIVATE
|
||||||
|
-Wall -Wextra -Wno-unused-parameter
|
||||||
|
-fstack-protector-strong
|
||||||
|
-D_FORTIFY_SOURCE=2
|
||||||
|
-fPIE
|
||||||
|
)
|
||||||
|
target_link_options(qobuz-qt PRIVATE
|
||||||
|
-pie
|
||||||
|
-Wl,-z,relro,-z,now
|
||||||
|
)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
# D-Bus
|
# D-Bus
|
||||||
|
|||||||
@@ -31,3 +31,4 @@ toml = "0.8"
|
|||||||
[profile.release]
|
[profile.release]
|
||||||
lto = "thin"
|
lto = "thin"
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
overflow-checks = true
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ enum QobuzEvent {
|
|||||||
EV_PLAYLIST_CREATED = 20,
|
EV_PLAYLIST_CREATED = 20,
|
||||||
EV_PLAYLIST_DELETED = 21,
|
EV_PLAYLIST_DELETED = 21,
|
||||||
EV_PLAYLIST_TRACK_ADDED = 22,
|
EV_PLAYLIST_TRACK_ADDED = 22,
|
||||||
|
EV_USER_OK = 23,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Callback signature
|
// Callback signature
|
||||||
@@ -46,6 +47,7 @@ void qobuz_backend_free(QobuzBackendOpaque *backend);
|
|||||||
// Auth
|
// Auth
|
||||||
void qobuz_backend_login(QobuzBackendOpaque *backend, const char *email, const char *password);
|
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_set_token(QobuzBackendOpaque *backend, const char *token);
|
||||||
|
void qobuz_backend_get_user(QobuzBackendOpaque *backend);
|
||||||
|
|
||||||
// Catalog
|
// Catalog
|
||||||
void qobuz_backend_search(QobuzBackendOpaque *backend, const char *query, uint32_t offset, uint32_t limit);
|
void qobuz_backend_search(QobuzBackendOpaque *backend, const char *query, uint32_t offset, uint32_t limit);
|
||||||
|
|||||||
@@ -60,6 +60,8 @@ impl QobuzClient {
|
|||||||
.as_secs()
|
.as_secs()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Compute the request signature required by the Qobuz API.
|
||||||
|
/// NOTE: MD5 is mandated by the Qobuz API protocol — not our choice.
|
||||||
fn request_sig(&self, method: &str, params: &mut Vec<(&str, String)>, ts: u64) -> String {
|
fn request_sig(&self, method: &str, params: &mut Vec<(&str, String)>, ts: u64) -> String {
|
||||||
params.sort_by_key(|(k, _)| *k);
|
params.sort_by_key(|(k, _)| *k);
|
||||||
let mut s = method.replace('/', "");
|
let mut s = method.replace('/', "");
|
||||||
@@ -116,6 +118,7 @@ impl QobuzClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// NOTE: Qobuz API requires credentials as GET query params — not our choice.
|
||||||
async fn oauth2_login(&mut self, email: &str, password: &str) -> Result<OAuthLoginResponse> {
|
async fn oauth2_login(&mut self, email: &str, password: &str) -> Result<OAuthLoginResponse> {
|
||||||
let ts = Self::ts();
|
let ts = Self::ts();
|
||||||
let mut sign_params: Vec<(&str, String)> = vec![
|
let mut sign_params: Vec<(&str, String)> = vec![
|
||||||
@@ -258,6 +261,7 @@ impl QobuzClient {
|
|||||||
.query(&[
|
.query(&[
|
||||||
("artist_id", artist_id.to_string()),
|
("artist_id", artist_id.to_string()),
|
||||||
("extra", "albums".to_string()),
|
("extra", "albums".to_string()),
|
||||||
|
("albums_limit", "200".to_string()),
|
||||||
])
|
])
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
@@ -265,6 +269,15 @@ impl QobuzClient {
|
|||||||
Ok(serde_json::from_value(body)?)
|
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 ---
|
// --- Search ---
|
||||||
|
|
||||||
pub async fn search(&self, query: &str, offset: u32, limit: u32) -> Result<SearchCatalogDto> {
|
pub async fn search(&self, query: &str, offset: u32, limit: u32) -> Result<SearchCatalogDto> {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ pub struct SubscriptionDto {
|
|||||||
pub struct TrackDto {
|
pub struct TrackDto {
|
||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub title: Option<String>,
|
pub title: Option<String>,
|
||||||
|
pub version: Option<String>,
|
||||||
pub duration: Option<i64>,
|
pub duration: Option<i64>,
|
||||||
pub track_number: Option<i32>,
|
pub track_number: Option<i32>,
|
||||||
pub playlist_track_id: Option<i64>,
|
pub playlist_track_id: Option<i64>,
|
||||||
@@ -98,6 +99,7 @@ pub struct AlbumDto {
|
|||||||
pub maximum_sampling_rate: Option<f64>,
|
pub maximum_sampling_rate: Option<f64>,
|
||||||
pub hires_streamable: Option<bool>,
|
pub hires_streamable: Option<bool>,
|
||||||
pub streamable: Option<bool>,
|
pub streamable: Option<bool>,
|
||||||
|
pub release_type: Option<String>,
|
||||||
pub tracks: Option<TracksWrapper>,
|
pub tracks: Option<TracksWrapper>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +121,10 @@ pub struct ArtistDto {
|
|||||||
pub image: Option<ImageDto>,
|
pub image: Option<ImageDto>,
|
||||||
pub biography: Option<BiographyDto>,
|
pub biography: Option<BiographyDto>,
|
||||||
pub albums: Option<SearchResultItems<AlbumDto>>,
|
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)]
|
#[derive(Debug, Deserialize, Clone, Serialize)]
|
||||||
|
|||||||
@@ -96,7 +96,9 @@ pub struct Backend(BackendInner);
|
|||||||
// ---------- Helpers ----------
|
// ---------- Helpers ----------
|
||||||
|
|
||||||
fn call_cb(cb: EventCallback, ud: SendPtr, ev: c_int, json: &str) {
|
fn call_cb(cb: EventCallback, ud: SendPtr, ev: c_int, json: &str) {
|
||||||
let cstr = CString::new(json).unwrap_or_else(|_| CString::new("{}").unwrap());
|
// Strip null bytes that would cause CString::new to fail
|
||||||
|
let safe = json.replace('\0', "");
|
||||||
|
let cstr = CString::new(safe).unwrap_or_else(|_| CString::new("{}").unwrap());
|
||||||
unsafe { cb(ud.0, ev, cstr.as_ptr()) };
|
unsafe { cb(ud.0, ev, cstr.as_ptr()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,8 +121,14 @@ pub unsafe extern "C" fn qobuz_backend_new(
|
|||||||
event_cb: EventCallback,
|
event_cb: EventCallback,
|
||||||
userdata: *mut c_void,
|
userdata: *mut c_void,
|
||||||
) -> *mut Backend {
|
) -> *mut Backend {
|
||||||
let rt = Runtime::new().expect("tokio runtime");
|
let rt = match Runtime::new() {
|
||||||
let client = Arc::new(Mutex::new(QobuzClient::new().expect("QobuzClient")));
|
Ok(r) => r,
|
||||||
|
Err(_) => return std::ptr::null_mut(),
|
||||||
|
};
|
||||||
|
let client = match QobuzClient::new() {
|
||||||
|
Ok(c) => Arc::new(Mutex::new(c)),
|
||||||
|
Err(_) => return std::ptr::null_mut(),
|
||||||
|
};
|
||||||
let player = Player::new();
|
let player = Player::new();
|
||||||
|
|
||||||
Box::into_raw(Box::new(Backend(BackendInner {
|
Box::into_raw(Box::new(Backend(BackendInner {
|
||||||
@@ -239,7 +247,7 @@ pub unsafe extern "C" fn qobuz_backend_get_artist(ptr: *mut Backend, artist_id:
|
|||||||
let cb = inner.cb; let ud = inner.ud;
|
let cb = inner.cb; let ud = inner.ud;
|
||||||
|
|
||||||
spawn(inner, async move {
|
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 {
|
let (ev, json) = match result {
|
||||||
Ok(r) => (EV_ARTIST_OK, serde_json::to_string(&r).unwrap_or_default()),
|
Ok(r) => (EV_ARTIST_OK, serde_json::to_string(&r).unwrap_or_default()),
|
||||||
Err(e) => (EV_ARTIST_ERR, err_json(&e.to_string())),
|
Err(e) => (EV_ARTIST_ERR, err_json(&e.to_string())),
|
||||||
@@ -563,6 +571,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 ----------
|
// ---------- Playlist management ----------
|
||||||
|
|
||||||
pub const EV_PLAYLIST_CREATED: c_int = 20;
|
pub const EV_PLAYLIST_CREATED: c_int = 20;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ target_sources(qobuz-qt PRIVATE
|
|||||||
view/albumlistview.hpp
|
view/albumlistview.hpp
|
||||||
view/artistlistview.hpp
|
view/artistlistview.hpp
|
||||||
view/artistview.hpp
|
view/artistview.hpp
|
||||||
|
view/artistview.cpp
|
||||||
view/sidepanel/view.hpp
|
view/sidepanel/view.hpp
|
||||||
view/sidepanel/view.cpp
|
view/sidepanel/view.cpp
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ QobuzBackend::QobuzBackend(QObject *parent)
|
|||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
m_backend = qobuz_backend_new(&QobuzBackend::eventTrampoline, this);
|
m_backend = qobuz_backend_new(&QobuzBackend::eventTrampoline, this);
|
||||||
|
if (!m_backend) {
|
||||||
|
qCritical("Failed to initialize Qobuz backend");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_positionTimer = new QTimer(this);
|
m_positionTimer = new QTimer(this);
|
||||||
m_positionTimer->setInterval(50);
|
m_positionTimer->setInterval(50);
|
||||||
@@ -35,6 +39,11 @@ void QobuzBackend::setToken(const QString &token)
|
|||||||
qobuz_backend_set_token(m_backend, token.toUtf8().constData());
|
qobuz_backend_set_token(m_backend, token.toUtf8().constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QobuzBackend::getUser()
|
||||||
|
{
|
||||||
|
qobuz_backend_get_user(m_backend);
|
||||||
|
}
|
||||||
|
|
||||||
// ---- catalog ----
|
// ---- catalog ----
|
||||||
|
|
||||||
void QobuzBackend::search(const QString &query, quint32 offset, quint32 limit)
|
void QobuzBackend::search(const QString &query, quint32 offset, quint32 limit)
|
||||||
@@ -189,7 +198,12 @@ void QobuzBackend::onPositionTick()
|
|||||||
|
|
||||||
void QobuzBackend::onEvent(int eventType, const QString &json)
|
void QobuzBackend::onEvent(int eventType, const QString &json)
|
||||||
{
|
{
|
||||||
const QJsonObject obj = QJsonDocument::fromJson(json.toUtf8()).object();
|
const QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
||||||
|
if (!doc.isObject()) {
|
||||||
|
emit error(tr("Malformed response from backend"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QJsonObject obj = doc.object();
|
||||||
|
|
||||||
switch (eventType) {
|
switch (eventType) {
|
||||||
case EV_LOGIN_OK:
|
case EV_LOGIN_OK:
|
||||||
@@ -249,6 +263,9 @@ void QobuzBackend::onEvent(int eventType, const QString &json)
|
|||||||
case 22: // EV_PLAYLIST_TRACK_ADDED
|
case 22: // EV_PLAYLIST_TRACK_ADDED
|
||||||
emit playlistTrackAdded(static_cast<qint64>(obj["playlist_id"].toDouble()));
|
emit playlistTrackAdded(static_cast<qint64>(obj["playlist_id"].toDouble()));
|
||||||
break;
|
break;
|
||||||
|
case EV_USER_OK:
|
||||||
|
emit userLoaded(obj);
|
||||||
|
break;
|
||||||
case EV_GENERIC_ERR:
|
case EV_GENERIC_ERR:
|
||||||
case EV_TRACK_URL_ERR:
|
case EV_TRACK_URL_ERR:
|
||||||
emit error(obj["error"].toString());
|
emit error(obj["error"].toString());
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ public:
|
|||||||
// --- auth ---
|
// --- auth ---
|
||||||
void login(const QString &email, const QString &password);
|
void login(const QString &email, const QString &password);
|
||||||
void setToken(const QString &token);
|
void setToken(const QString &token);
|
||||||
|
void getUser();
|
||||||
|
|
||||||
// --- catalog ---
|
// --- catalog ---
|
||||||
void search(const QString &query, quint32 offset = 0, quint32 limit = 20);
|
void search(const QString &query, quint32 offset = 0, quint32 limit = 20);
|
||||||
@@ -71,6 +72,7 @@ signals:
|
|||||||
// auth
|
// auth
|
||||||
void loginSuccess(const QString &token, const QJsonObject &user);
|
void loginSuccess(const QString &token, const QJsonObject &user);
|
||||||
void loginError(const QString &error);
|
void loginError(const QString &error);
|
||||||
|
void userLoaded(const QJsonObject &user);
|
||||||
|
|
||||||
// catalog
|
// catalog
|
||||||
void searchResult(const QJsonObject &result);
|
void searchResult(const QJsonObject &result);
|
||||||
|
|||||||
@@ -35,24 +35,32 @@ Tracks::Tracks(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
|||||||
this, &Tracks::onDoubleClicked);
|
this, &Tracks::onDoubleClicked);
|
||||||
connect(this, &QTreeView::customContextMenuRequested,
|
connect(this, &QTreeView::customContextMenuRequested,
|
||||||
this, &Tracks::onContextMenu);
|
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)
|
void Tracks::loadTracks(const QJsonArray &tracks)
|
||||||
{
|
{
|
||||||
setPlaylistContext(0);
|
setPlaylistContext(0);
|
||||||
|
setColumnHidden(TrackListModel::ColAlbum, false);
|
||||||
m_model->setTracks(tracks, false, /*useSequential=*/true);
|
m_model->setTracks(tracks, false, /*useSequential=*/true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tracks::loadAlbum(const QJsonObject &album)
|
void Tracks::loadAlbum(const QJsonObject &album)
|
||||||
{
|
{
|
||||||
setPlaylistContext(0);
|
setPlaylistContext(0);
|
||||||
|
setColumnHidden(TrackListModel::ColAlbum, true);
|
||||||
const QJsonArray items = album["tracks"].toObject()["items"].toArray();
|
const QJsonArray items = album["tracks"].toObject()["items"].toArray();
|
||||||
m_model->setTracks(items); // album: use track_number
|
m_model->setTracks(items); // album: use track_number
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tracks::loadPlaylist(const QJsonObject &playlist)
|
void Tracks::loadPlaylist(const QJsonObject &playlist)
|
||||||
{
|
{
|
||||||
|
setColumnHidden(TrackListModel::ColAlbum, false);
|
||||||
const qint64 id = static_cast<qint64>(playlist["id"].toDouble());
|
const qint64 id = static_cast<qint64>(playlist["id"].toDouble());
|
||||||
const qint64 ownId = static_cast<qint64>(playlist["owner"].toObject()["id"].toDouble());
|
const qint64 ownId = static_cast<qint64>(playlist["owner"].toObject()["id"].toDouble());
|
||||||
const qint64 myId = AppSettings::instance().userId();
|
const qint64 myId = AppSettings::instance().userId();
|
||||||
@@ -65,6 +73,7 @@ void Tracks::loadPlaylist(const QJsonObject &playlist)
|
|||||||
void Tracks::loadSearchTracks(const QJsonArray &tracks)
|
void Tracks::loadSearchTracks(const QJsonArray &tracks)
|
||||||
{
|
{
|
||||||
setPlaylistContext(0);
|
setPlaylistContext(0);
|
||||||
|
setColumnHidden(TrackListModel::ColAlbum, false);
|
||||||
m_model->setTracks(tracks, false, /*useSequential=*/true);
|
m_model->setTracks(tracks, false, /*useSequential=*/true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,12 +93,30 @@ void Tracks::setPlayingTrackId(qint64 id)
|
|||||||
m_model->setPlayingId(id);
|
m_model->setPlayingId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Tracks::setFavTrackIds(const QSet<qint64> &ids)
|
||||||
|
{
|
||||||
|
m_model->setFavIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tracks::addFavTrackId(qint64 id)
|
||||||
|
{
|
||||||
|
m_model->addFavId(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tracks::removeFavTrackId(qint64 id)
|
||||||
|
{
|
||||||
|
m_model->removeFavId(id);
|
||||||
|
}
|
||||||
|
|
||||||
void Tracks::playAll(bool shuffle)
|
void Tracks::playAll(bool shuffle)
|
||||||
{
|
{
|
||||||
const QJsonArray tracks = m_model->currentTracksJson();
|
const QJsonArray tracks = m_model->currentTracksJson();
|
||||||
if (tracks.isEmpty()) return;
|
if (tracks.isEmpty()) return;
|
||||||
m_queue->setShuffle(shuffle);
|
|
||||||
m_queue->setContext(tracks, 0);
|
m_queue->setContext(tracks, 0);
|
||||||
|
// Shuffle once without touching the global shuffle flag — so a subsequent
|
||||||
|
// double-click on a track plays in normal order (unless global shuffle is on).
|
||||||
|
if (shuffle && !m_queue->shuffleEnabled())
|
||||||
|
m_queue->shuffleNow();
|
||||||
const qint64 firstId = static_cast<qint64>(m_queue->current()["id"].toDouble());
|
const qint64 firstId = static_cast<qint64>(m_queue->current()["id"].toDouble());
|
||||||
if (firstId > 0)
|
if (firstId > 0)
|
||||||
emit playTrackRequested(firstId);
|
emit playTrackRequested(firstId);
|
||||||
@@ -100,7 +127,11 @@ void Tracks::onDoubleClicked(const QModelIndex &index)
|
|||||||
{
|
{
|
||||||
const qint64 id = m_model->data(index, TrackListModel::TrackIdRole).toLongLong();
|
const qint64 id = m_model->data(index, TrackListModel::TrackIdRole).toLongLong();
|
||||||
if (id > 0) {
|
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);
|
emit playTrackRequested(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,6 +142,7 @@ void Tracks::onContextMenu(const QPoint &pos)
|
|||||||
if (!index.isValid()) return;
|
if (!index.isValid()) return;
|
||||||
|
|
||||||
const qint64 id = m_model->data(index, TrackListModel::TrackIdRole).toLongLong();
|
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();
|
const QJsonObject trackJson = m_model->data(index, TrackListModel::TrackJsonRole).toJsonObject();
|
||||||
|
|
||||||
QMenu menu(this);
|
QMenu menu(this);
|
||||||
@@ -119,12 +151,28 @@ void Tracks::onContextMenu(const QPoint &pos)
|
|||||||
auto *playNext = menu.addAction(QIcon(":/res/icons/media-skip-forward.svg"), tr("Play next"));
|
auto *playNext = menu.addAction(QIcon(":/res/icons/media-skip-forward.svg"), tr("Play next"));
|
||||||
auto *addQueue = menu.addAction(QIcon(":/res/icons/media-playlist-append.svg"), tr("Add to queue"));
|
auto *addQueue = menu.addAction(QIcon(":/res/icons/media-playlist-append.svg"), tr("Add to queue"));
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
auto *addFav = menu.addAction(QIcon(":/res/icons/starred-symbolic.svg"), tr("Add to favorites"));
|
|
||||||
auto *remFav = menu.addAction(QIcon(":/res/icons/non-starred-symbolic.svg"), tr("Remove from favorites"));
|
|
||||||
|
|
||||||
const int row = index.row();
|
const bool isFav = m_model->isFav(id);
|
||||||
connect(playNow, &QAction::triggered, this, [this, id, row] {
|
if (isFav) {
|
||||||
m_queue->setContext(m_model->currentTracksJson(), row);
|
auto *remFav = menu.addAction(QIcon(":/res/icons/non-starred-symbolic.svg"), tr("Remove from favorites"));
|
||||||
|
connect(remFav, &QAction::triggered, this, [this, id] {
|
||||||
|
m_backend->removeFavTrack(id);
|
||||||
|
m_model->removeFavId(id);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
auto *addFav = menu.addAction(QIcon(":/res/icons/starred-symbolic.svg"), tr("Add to favorites"));
|
||||||
|
connect(addFav, &QAction::triggered, this, [this, id] {
|
||||||
|
m_backend->addFavTrack(id);
|
||||||
|
m_model->addFavId(id);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
emit playTrackRequested(id);
|
||||||
});
|
});
|
||||||
connect(playNext, &QAction::triggered, this, [this, trackJson] {
|
connect(playNext, &QAction::triggered, this, [this, trackJson] {
|
||||||
@@ -133,12 +181,6 @@ void Tracks::onContextMenu(const QPoint &pos)
|
|||||||
connect(addQueue, &QAction::triggered, this, [this, trackJson] {
|
connect(addQueue, &QAction::triggered, this, [this, trackJson] {
|
||||||
m_queue->addToQueue(trackJson);
|
m_queue->addToQueue(trackJson);
|
||||||
});
|
});
|
||||||
connect(addFav, &QAction::triggered, this, [this, id] {
|
|
||||||
m_backend->addFavTrack(id);
|
|
||||||
});
|
|
||||||
connect(remFav, &QAction::triggered, this, [this, id] {
|
|
||||||
m_backend->removeFavTrack(id);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Open album
|
// Open album
|
||||||
const QString albumId = m_model->trackAt(index.row()).albumId;
|
const QString albumId = m_model->trackAt(index.row()).albumId;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
namespace List
|
namespace List
|
||||||
{
|
{
|
||||||
@@ -28,6 +29,11 @@ namespace List
|
|||||||
/// Called when the backend fires EV_TRACK_CHANGED so the playing row is highlighted.
|
/// Called when the backend fires EV_TRACK_CHANGED so the playing row is highlighted.
|
||||||
void setPlayingTrackId(qint64 id);
|
void setPlayingTrackId(qint64 id);
|
||||||
|
|
||||||
|
/// Populate favorite track IDs so the star indicator and context menu reflect fav status.
|
||||||
|
void setFavTrackIds(const QSet<qint64> &ids);
|
||||||
|
void addFavTrackId(qint64 id);
|
||||||
|
void removeFavTrackId(qint64 id);
|
||||||
|
|
||||||
/// Start playing all tracks in the current view from the beginning.
|
/// Start playing all tracks in the current view from the beginning.
|
||||||
/// If shuffle is true, enables shuffle mode before starting.
|
/// If shuffle is true, enables shuffle mode before starting.
|
||||||
void playAll(bool shuffle = false);
|
void playAll(bool shuffle = false);
|
||||||
|
|||||||
@@ -72,6 +72,13 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
|||||||
// ---- Backend signals ----
|
// ---- Backend signals ----
|
||||||
connect(m_backend, &QobuzBackend::loginSuccess, this, &MainWindow::onLoginSuccess);
|
connect(m_backend, &QobuzBackend::loginSuccess, this, &MainWindow::onLoginSuccess);
|
||||||
connect(m_backend, &QobuzBackend::loginError, this, &MainWindow::onLoginError);
|
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::favTracksLoaded, this, &MainWindow::onFavTracksLoaded);
|
||||||
connect(m_backend, &QobuzBackend::favAlbumsLoaded, this, &MainWindow::onFavAlbumsLoaded);
|
connect(m_backend, &QobuzBackend::favAlbumsLoaded, this, &MainWindow::onFavAlbumsLoaded);
|
||||||
connect(m_backend, &QobuzBackend::favArtistsLoaded, this, &MainWindow::onFavArtistsLoaded);
|
connect(m_backend, &QobuzBackend::favArtistsLoaded, this, &MainWindow::onFavArtistsLoaded);
|
||||||
@@ -199,6 +206,9 @@ void MainWindow::tryRestoreSession()
|
|||||||
const QString token = AppSettings::instance().authToken();
|
const QString token = AppSettings::instance().authToken();
|
||||||
if (!token.isEmpty()) {
|
if (!token.isEmpty()) {
|
||||||
m_backend->setToken(token);
|
m_backend->setToken(token);
|
||||||
|
if (AppSettings::instance().userId() == 0)
|
||||||
|
m_backend->getUser(); // userLoaded will call m_library->refresh()
|
||||||
|
else
|
||||||
m_library->refresh();
|
m_library->refresh();
|
||||||
const QString name = AppSettings::instance().displayName();
|
const QString name = AppSettings::instance().displayName();
|
||||||
statusBar()->showMessage(tr("Signed in as %1").arg(
|
statusBar()->showMessage(tr("Signed in as %1").arg(
|
||||||
@@ -283,6 +293,15 @@ void MainWindow::onTrackChanged(const QJsonObject &track)
|
|||||||
|
|
||||||
void MainWindow::onFavTracksLoaded(const QJsonObject &result)
|
void MainWindow::onFavTracksLoaded(const QJsonObject &result)
|
||||||
{
|
{
|
||||||
|
// Cache fav IDs so the star indicator and context menu stay in sync
|
||||||
|
QSet<qint64> ids;
|
||||||
|
const QJsonArray items = result["items"].toArray();
|
||||||
|
for (const QJsonValue &v : items) {
|
||||||
|
const qint64 id = static_cast<qint64>(v.toObject()["id"].toDouble());
|
||||||
|
if (id > 0) ids.insert(id);
|
||||||
|
}
|
||||||
|
m_content->tracksList()->setFavTrackIds(ids);
|
||||||
|
|
||||||
m_content->showFavTracks(result);
|
m_content->showFavTracks(result);
|
||||||
statusBar()->showMessage(
|
statusBar()->showMessage(
|
||||||
tr("%1 favorite tracks").arg(result["total"].toInt()), 4000);
|
tr("%1 favorite tracks").arg(result["total"].toInt()), 4000);
|
||||||
|
|||||||
@@ -13,7 +13,9 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QSet>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
|||||||
@@ -17,18 +17,28 @@ void TrackListModel::setTracks(const QJsonArray &tracks,
|
|||||||
m_tracks.clear();
|
m_tracks.clear();
|
||||||
m_tracks.reserve(tracks.size());
|
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;
|
int seq = 1;
|
||||||
for (const QJsonValue &v : tracks) {
|
for (const QJsonValue &v : tracks) {
|
||||||
const QJsonObject t = v.toObject();
|
const QJsonObject t = v.toObject();
|
||||||
TrackItem item;
|
TrackItem item;
|
||||||
item.id = static_cast<qint64>(t["id"].toDouble());
|
item.id = static_cast<qint64>(t["id"].toDouble());
|
||||||
item.playlistTrackId = static_cast<qint64>(t["playlist_track_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.duration = static_cast<qint64>(t["duration"].toDouble());
|
||||||
item.hiRes = t["hires_streamable"].toBool();
|
|
||||||
item.streamable = t["streamable"].toBool(true);
|
item.streamable = t["streamable"].toBool(true);
|
||||||
|
item.hiRes = t["hires_streamable"].toBool();
|
||||||
item.raw = t;
|
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) {
|
if (useSequential) {
|
||||||
item.number = seq++;
|
item.number = seq++;
|
||||||
} else if (usePosition) {
|
} else if (usePosition) {
|
||||||
@@ -48,17 +58,46 @@ void TrackListModel::setTracks(const QJsonArray &tracks,
|
|||||||
item.album = album["title"].toString();
|
item.album = album["title"].toString();
|
||||||
item.albumId = album["id"].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)
|
// 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)
|
if (m_sortColumn >= 0)
|
||||||
sortData(m_sortColumn, m_sortOrder);
|
sortData(m_sortColumn, m_sortOrder);
|
||||||
|
}
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
|
|
||||||
// Tell external listeners the sorted order is ready (e.g. PlayQueue sync)
|
if (!m_hasMultipleDiscs && m_sortColumn >= 0)
|
||||||
if (m_sortColumn >= 0)
|
|
||||||
emit sortApplied();
|
emit sortApplied();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +116,36 @@ void TrackListModel::removeTrack(int row)
|
|||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrackListModel::setFavIds(const QSet<qint64> &ids)
|
||||||
|
{
|
||||||
|
m_favIds = ids;
|
||||||
|
if (!m_tracks.isEmpty())
|
||||||
|
emit dataChanged(index(0, ColTitle), index(rowCount() - 1, ColTitle),
|
||||||
|
{Qt::DecorationRole});
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackListModel::addFavId(qint64 id)
|
||||||
|
{
|
||||||
|
m_favIds.insert(id);
|
||||||
|
for (int r = 0; r < m_tracks.size(); ++r) {
|
||||||
|
if (m_tracks[r].id == id) {
|
||||||
|
const auto idx = index(r, ColTitle);
|
||||||
|
emit dataChanged(idx, idx, {Qt::DecorationRole});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackListModel::removeFavId(qint64 id)
|
||||||
|
{
|
||||||
|
m_favIds.remove(id);
|
||||||
|
for (int r = 0; r < m_tracks.size(); ++r) {
|
||||||
|
if (m_tracks[r].id == id) {
|
||||||
|
const auto idx = index(r, ColTitle);
|
||||||
|
emit dataChanged(idx, idx, {Qt::DecorationRole});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void TrackListModel::setPlayingId(qint64 id)
|
void TrackListModel::setPlayingId(qint64 id)
|
||||||
{
|
{
|
||||||
m_playingId = id;
|
m_playingId = id;
|
||||||
@@ -85,6 +154,23 @@ void TrackListModel::setPlayingId(qint64 id)
|
|||||||
{Qt::FontRole, Qt::DecorationRole});
|
{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
|
int TrackListModel::rowCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
return parent.isValid() ? 0 : m_tracks.size();
|
return parent.isValid() ? 0 : m_tracks.size();
|
||||||
@@ -101,6 +187,19 @@ QVariant TrackListModel::data(const QModelIndex &index, int role) const
|
|||||||
return {};
|
return {};
|
||||||
|
|
||||||
const TrackItem &t = m_tracks.at(index.row());
|
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);
|
const bool isPlaying = (t.id == m_playingId && m_playingId != 0);
|
||||||
|
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
@@ -128,6 +227,10 @@ QVariant TrackListModel::data(const QModelIndex &index, int role) const
|
|||||||
return QIcon(QStringLiteral(":/res/icons/media-track-show-active.svg"));
|
return QIcon(QStringLiteral(":/res/icons/media-track-show-active.svg"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (role == Qt::DecorationRole && index.column() == ColTitle && m_favIds.contains(t.id)) {
|
||||||
|
return QIcon(QStringLiteral(":/res/icons/starred-symbolic.svg"));
|
||||||
|
}
|
||||||
|
|
||||||
if (role == TrackIdRole) return t.id;
|
if (role == TrackIdRole) return t.id;
|
||||||
if (role == TrackJsonRole) return t.raw;
|
if (role == TrackJsonRole) return t.raw;
|
||||||
if (role == HiResRole) return t.hiRes;
|
if (role == HiResRole) return t.hiRes;
|
||||||
@@ -179,7 +282,8 @@ void TrackListModel::sort(int column, Qt::SortOrder order)
|
|||||||
m_sortColumn = column;
|
m_sortColumn = column;
|
||||||
m_sortOrder = order;
|
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();
|
emit layoutAboutToBeChanged();
|
||||||
sortData(column, order);
|
sortData(column, order);
|
||||||
@@ -190,7 +294,8 @@ void TrackListModel::sort(int column, Qt::SortOrder order)
|
|||||||
|
|
||||||
QString TrackListModel::formatDuration(qint64 secs)
|
QString TrackListModel::formatDuration(qint64 secs)
|
||||||
{
|
{
|
||||||
const int m = static_cast<int>(secs / 60);
|
if (secs < 0) secs = 0;
|
||||||
const int s = static_cast<int>(secs % 60);
|
const qint64 m = secs / 60;
|
||||||
|
const qint64 s = secs % 60;
|
||||||
return QStringLiteral("%1:%2").arg(m).arg(s, 2, 10, QLatin1Char('0'));
|
return QStringLiteral("%1:%2").arg(m).arg(s, 2, 10, QLatin1Char('0'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,15 @@
|
|||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QSet>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
|
||||||
struct TrackItem {
|
struct TrackItem {
|
||||||
qint64 id = 0;
|
qint64 id = 0;
|
||||||
qint64 playlistTrackId = 0;
|
qint64 playlistTrackId = 0;
|
||||||
int number = 0;
|
int number = 0;
|
||||||
|
int discNumber = 1;
|
||||||
|
bool isDiscHeader = false;
|
||||||
QString title;
|
QString title;
|
||||||
QString artist;
|
QString artist;
|
||||||
QString album;
|
QString album;
|
||||||
@@ -52,17 +55,27 @@ public:
|
|||||||
void setPlayingId(qint64 id);
|
void setPlayingId(qint64 id);
|
||||||
qint64 playingId() const { return m_playingId; }
|
qint64 playingId() const { return m_playingId; }
|
||||||
|
|
||||||
|
void setFavIds(const QSet<qint64> &ids);
|
||||||
|
void addFavId(qint64 id);
|
||||||
|
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).
|
/// Optimistically remove a row (e.g. after deleting from playlist).
|
||||||
void removeTrack(int row);
|
void removeTrack(int row);
|
||||||
|
|
||||||
const TrackItem &trackAt(int row) const { return m_tracks.at(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 currentTracksJson() const
|
||||||
{
|
{
|
||||||
QJsonArray out;
|
QJsonArray out;
|
||||||
for (const auto &t : m_tracks)
|
for (const auto &t : m_tracks)
|
||||||
out.append(t.raw);
|
if (!t.isDiscHeader) out.append(t.raw);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +94,9 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QVector<TrackItem> m_tracks;
|
QVector<TrackItem> m_tracks;
|
||||||
|
QSet<qint64> m_favIds;
|
||||||
qint64 m_playingId = 0;
|
qint64 m_playingId = 0;
|
||||||
|
bool m_hasMultipleDiscs = false;
|
||||||
int m_sortColumn = -1;
|
int m_sortColumn = -1;
|
||||||
Qt::SortOrder m_sortOrder = Qt::AscendingOrder;
|
Qt::SortOrder m_sortOrder = Qt::AscendingOrder;
|
||||||
|
|
||||||
|
|||||||
@@ -107,6 +107,14 @@ public:
|
|||||||
emit queueChanged();
|
emit queueChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shuffle the current queue once without changing the global shuffle flag.
|
||||||
|
void shuffleNow()
|
||||||
|
{
|
||||||
|
if (m_queue.isEmpty()) return;
|
||||||
|
shuffleQueue(m_index);
|
||||||
|
emit queueChanged();
|
||||||
|
}
|
||||||
|
|
||||||
// ---- Play-next prepend queue (like "Add to queue" ----
|
// ---- Play-next prepend queue (like "Add to queue" ----
|
||||||
|
|
||||||
void addToQueue(const QJsonObject &track)
|
void addToQueue(const QJsonObject &track)
|
||||||
|
|||||||
@@ -48,12 +48,26 @@ public:
|
|||||||
for (const auto &v : albums) {
|
for (const auto &v : albums) {
|
||||||
const QJsonObject a = v.toObject();
|
const QJsonObject a = v.toObject();
|
||||||
const QString id = a["id"].toString();
|
const QString id = a["id"].toString();
|
||||||
const QString title = a["title"].toString();
|
const QString base = a["title"].toString();
|
||||||
const QString artist = a["artist"].toObject()["name"].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 date = a["release_date_original"].toString();
|
||||||
const QString year = date.left(4);
|
const QString year = date.isEmpty()
|
||||||
|
? a["dates"].toObject()["original"].toString().left(4)
|
||||||
|
: date.left(4);
|
||||||
|
|
||||||
const int tracks = a["tracks_count"].toInt();
|
const int tracks = a["tracks_count"].toInt();
|
||||||
const bool hiRes = a["hires_streamable"].toBool();
|
// 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);
|
auto *item = new QTreeWidgetItem(this);
|
||||||
if (hiRes) {
|
if (hiRes) {
|
||||||
|
|||||||
185
src/view/artistview.cpp
Normal file
185
src/view/artistview.cpp
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
#include "artistview.hpp"
|
||||||
|
#include "albumlistview.hpp"
|
||||||
|
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QFont>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// ArtistSection
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ArtistSection::ArtistSection(const QString &title, QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
, m_baseTitle(title)
|
||||||
|
{
|
||||||
|
auto *layout = new QVBoxLayout(this);
|
||||||
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
layout->setSpacing(0);
|
||||||
|
|
||||||
|
m_toggle = new QToolButton(this);
|
||||||
|
m_toggle->setCheckable(true);
|
||||||
|
m_toggle->setChecked(true);
|
||||||
|
m_toggle->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||||
|
m_toggle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
m_toggle->setStyleSheet(QStringLiteral(
|
||||||
|
"QToolButton { text-align: left; font-weight: bold; padding: 4px 6px;"
|
||||||
|
" border: none; border-bottom: 1px solid #333; }"
|
||||||
|
"QToolButton:hover { background: #1e1e1e; }"
|
||||||
|
));
|
||||||
|
updateToggleText(0);
|
||||||
|
layout->addWidget(m_toggle);
|
||||||
|
|
||||||
|
m_list = new AlbumListView(this);
|
||||||
|
layout->addWidget(m_list);
|
||||||
|
|
||||||
|
connect(m_toggle, &QToolButton::toggled, m_list, &AlbumListView::setVisible);
|
||||||
|
connect(m_list, &AlbumListView::albumSelected, this, &ArtistSection::albumSelected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArtistSection::setAlbums(const QJsonArray &albums)
|
||||||
|
{
|
||||||
|
m_list->setAlbums(albums);
|
||||||
|
updateToggleText(albums.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ArtistSection::isEmpty() const
|
||||||
|
{
|
||||||
|
return m_list->topLevelItemCount() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArtistSection::updateToggleText(int count)
|
||||||
|
{
|
||||||
|
const QString arrow = m_toggle->isChecked() ? QStringLiteral("▼ ") : QStringLiteral("▶ ");
|
||||||
|
const QString text = count > 0
|
||||||
|
? QStringLiteral("%1%2 (%3)").arg(arrow, m_baseTitle).arg(count)
|
||||||
|
: arrow + m_baseTitle;
|
||||||
|
m_toggle->setText(text);
|
||||||
|
|
||||||
|
// Keep arrow in sync when toggled
|
||||||
|
disconnect(m_toggle, &QToolButton::toggled, nullptr, nullptr);
|
||||||
|
connect(m_toggle, &QToolButton::toggled, m_list, &AlbumListView::setVisible);
|
||||||
|
connect(m_toggle, &QToolButton::toggled, this, [this, count](bool open) {
|
||||||
|
const QString a = open ? QStringLiteral("▼ ") : QStringLiteral("▶ ");
|
||||||
|
const QString t = count > 0
|
||||||
|
? QStringLiteral("%1%2 (%3)").arg(a, m_baseTitle).arg(count)
|
||||||
|
: a + m_baseTitle;
|
||||||
|
m_toggle->setText(t);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// ArtistView
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ArtistView::ArtistView(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
{
|
||||||
|
auto *outerLayout = new QVBoxLayout(this);
|
||||||
|
outerLayout->setContentsMargins(8, 8, 8, 8);
|
||||||
|
outerLayout->setSpacing(6);
|
||||||
|
|
||||||
|
m_nameLabel = new QLabel(this);
|
||||||
|
QFont f = m_nameLabel->font();
|
||||||
|
f.setPointSize(f.pointSize() + 4);
|
||||||
|
f.setBold(true);
|
||||||
|
m_nameLabel->setFont(f);
|
||||||
|
outerLayout->addWidget(m_nameLabel);
|
||||||
|
|
||||||
|
m_bioLabel = new QLabel(this);
|
||||||
|
m_bioLabel->setWordWrap(true);
|
||||||
|
m_bioLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
||||||
|
m_bioLabel->setMaximumHeight(80);
|
||||||
|
outerLayout->addWidget(m_bioLabel);
|
||||||
|
|
||||||
|
// Scrollable sections area
|
||||||
|
auto *scroll = new QScrollArea(this);
|
||||||
|
scroll->setWidgetResizable(true);
|
||||||
|
scroll->setFrameShape(QFrame::NoFrame);
|
||||||
|
|
||||||
|
auto *content = new QWidget(scroll);
|
||||||
|
auto *sectLayout = new QVBoxLayout(content);
|
||||||
|
sectLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
sectLayout->setSpacing(8);
|
||||||
|
|
||||||
|
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_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)
|
||||||
|
{
|
||||||
|
// artist/page: name is {"display": "..."}
|
||||||
|
m_nameLabel->setText(artist["name"].toObject()["display"].toString());
|
||||||
|
|
||||||
|
// biography.content is HTML — strip tags for safe plain-text display
|
||||||
|
const QString bioHtml = artist["biography"].toObject()["content"].toString();
|
||||||
|
if (!bioHtml.isEmpty()) {
|
||||||
|
QString plain = bioHtml;
|
||||||
|
// Strip HTML entities and tags to prevent rendering injected content
|
||||||
|
plain.remove(QRegularExpression(QStringLiteral("<[^>]*>")));
|
||||||
|
plain.replace(QStringLiteral("&"), QStringLiteral("&"));
|
||||||
|
plain.replace(QStringLiteral("<"), QStringLiteral("<"));
|
||||||
|
plain.replace(QStringLiteral(">"), QStringLiteral(">"));
|
||||||
|
plain.replace(QStringLiteral("""), QStringLiteral("\""));
|
||||||
|
plain.replace(QStringLiteral("'"), QStringLiteral("'"));
|
||||||
|
plain.replace(QStringLiteral(" "), QStringLiteral(" "));
|
||||||
|
plain = plain.trimmed();
|
||||||
|
m_bioLabel->setTextFormat(Qt::PlainText);
|
||||||
|
m_bioLabel->setText(plain);
|
||||||
|
m_bioLabel->setVisible(!plain.isEmpty());
|
||||||
|
} else {
|
||||||
|
m_bioLabel->setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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_secLive->setAlbums(live);
|
||||||
|
m_secCompilations->setAlbums(compilations);
|
||||||
|
m_secOther->setAlbums({});
|
||||||
|
|
||||||
|
m_secAlbums->setVisible(!m_secAlbums->isEmpty());
|
||||||
|
m_secEps->setVisible(!m_secEps->isEmpty());
|
||||||
|
m_secLive->setVisible(!m_secLive->isEmpty());
|
||||||
|
m_secCompilations->setVisible(!m_secCompilations->isEmpty());
|
||||||
|
m_secOther->setVisible(false);
|
||||||
|
}
|
||||||
@@ -3,56 +3,44 @@
|
|||||||
#include "albumlistview.hpp"
|
#include "albumlistview.hpp"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QVBoxLayout>
|
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QFont>
|
#include <QToolButton>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
/// Artist detail page: name, biography summary, and their album list.
|
class AlbumListView;
|
||||||
|
|
||||||
|
/// One collapsible section (e.g. "Albums", "EPs & Singles") inside ArtistView.
|
||||||
|
class ArtistSection : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ArtistSection(const QString &title, QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void setAlbums(const QJsonArray &albums);
|
||||||
|
bool isEmpty() const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void albumSelected(const QString &albumId);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_baseTitle;
|
||||||
|
QToolButton *m_toggle = nullptr;
|
||||||
|
AlbumListView *m_list = nullptr;
|
||||||
|
|
||||||
|
void updateToggleText(int count);
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Artist detail page: name, biography, and albums split into collapsible sections
|
||||||
|
/// (Albums / EPs & Singles / Other) keyed on the release_type field.
|
||||||
class ArtistView : public QWidget
|
class ArtistView : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ArtistView(QWidget *parent = nullptr) : QWidget(parent)
|
explicit ArtistView(QWidget *parent = nullptr);
|
||||||
{
|
|
||||||
auto *layout = new QVBoxLayout(this);
|
|
||||||
layout->setContentsMargins(8, 8, 8, 8);
|
|
||||||
layout->setSpacing(6);
|
|
||||||
|
|
||||||
m_nameLabel = new QLabel(this);
|
void setArtist(const QJsonObject &artist);
|
||||||
QFont f = m_nameLabel->font();
|
|
||||||
f.setPointSize(f.pointSize() + 4);
|
|
||||||
f.setBold(true);
|
|
||||||
m_nameLabel->setFont(f);
|
|
||||||
|
|
||||||
m_bioLabel = new QLabel(this);
|
|
||||||
m_bioLabel->setWordWrap(true);
|
|
||||||
m_bioLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
|
||||||
m_bioLabel->setMaximumHeight(80);
|
|
||||||
|
|
||||||
m_albums = new AlbumListView(this);
|
|
||||||
|
|
||||||
layout->addWidget(m_nameLabel);
|
|
||||||
layout->addWidget(m_bioLabel);
|
|
||||||
layout->addWidget(m_albums, 1);
|
|
||||||
|
|
||||||
connect(m_albums, &AlbumListView::albumSelected,
|
|
||||||
this, &ArtistView::albumSelected);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setArtist(const QJsonObject &artist)
|
|
||||||
{
|
|
||||||
m_nameLabel->setText(artist["name"].toString());
|
|
||||||
|
|
||||||
const QString summary = artist["biography"].toObject()["summary"].toString();
|
|
||||||
m_bioLabel->setText(summary);
|
|
||||||
m_bioLabel->setVisible(!summary.isEmpty());
|
|
||||||
|
|
||||||
const QJsonArray albums = artist["albums"].toObject()["items"].toArray();
|
|
||||||
m_albums->setAlbums(albums);
|
|
||||||
}
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void albumSelected(const QString &albumId);
|
void albumSelected(const QString &albumId);
|
||||||
@@ -60,5 +48,9 @@ signals:
|
|||||||
private:
|
private:
|
||||||
QLabel *m_nameLabel = nullptr;
|
QLabel *m_nameLabel = nullptr;
|
||||||
QLabel *m_bioLabel = nullptr;
|
QLabel *m_bioLabel = nullptr;
|
||||||
AlbumListView *m_albums = nullptr;
|
ArtistSection *m_secAlbums = nullptr;
|
||||||
|
ArtistSection *m_secEps = nullptr;
|
||||||
|
ArtistSection *m_secLive = nullptr;
|
||||||
|
ArtistSection *m_secCompilations = nullptr;
|
||||||
|
ArtistSection *m_secOther = nullptr;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -22,11 +22,7 @@ View::View(QobuzBackend *backend, QWidget *parent)
|
|||||||
layout->setContentsMargins(8, 8, 8, 8);
|
layout->setContentsMargins(8, 8, 8, 8);
|
||||||
layout->setSpacing(6);
|
layout->setSpacing(6);
|
||||||
|
|
||||||
m_albumArt = new QLabel(container);
|
m_albumArt = new ArtWidget(container);
|
||||||
m_albumArt->setAlignment(Qt::AlignCenter);
|
|
||||||
m_albumArt->setStyleSheet(QStringLiteral(
|
|
||||||
"background: #1a1a1a; border-radius: 4px;"));
|
|
||||||
m_albumArt->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
|
||||||
layout->addWidget(m_albumArt);
|
layout->addWidget(m_albumArt);
|
||||||
|
|
||||||
m_title = new QLabel(tr("Not playing"), container);
|
m_title = new QLabel(tr("Not playing"), container);
|
||||||
@@ -45,7 +41,6 @@ View::View(QobuzBackend *backend, QWidget *parent)
|
|||||||
|
|
||||||
layout->addStretch();
|
layout->addStretch();
|
||||||
setWidget(container);
|
setWidget(container);
|
||||||
setMinimumWidth(160);
|
|
||||||
|
|
||||||
connect(m_backend, &QobuzBackend::trackChanged, this, &View::onTrackChanged);
|
connect(m_backend, &QobuzBackend::trackChanged, this, &View::onTrackChanged);
|
||||||
}
|
}
|
||||||
@@ -60,7 +55,6 @@ void View::onTrackChanged(const QJsonObject &track)
|
|||||||
m_title->setText(title.isEmpty() ? tr("Not playing") : title);
|
m_title->setText(title.isEmpty() ? tr("Not playing") : title);
|
||||||
m_artist->setText(artist);
|
m_artist->setText(artist);
|
||||||
|
|
||||||
// Prefer "large" image, fall back to "small"
|
|
||||||
const QJsonObject img = track["album"].toObject()["image"].toObject();
|
const QJsonObject img = track["album"].toObject()["image"].toObject();
|
||||||
QString artUrl = img["large"].toString();
|
QString artUrl = img["large"].toString();
|
||||||
if (artUrl.isEmpty())
|
if (artUrl.isEmpty())
|
||||||
@@ -77,26 +71,9 @@ void View::onArtReady(QNetworkReply *reply)
|
|||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
if (reply->error() != QNetworkReply::NoError)
|
if (reply->error() != QNetworkReply::NoError)
|
||||||
return;
|
return;
|
||||||
if (m_artPixmap.loadFromData(reply->readAll()))
|
QPixmap pix;
|
||||||
scaleArtToWidth();
|
if (pix.loadFromData(reply->readAll()))
|
||||||
}
|
m_albumArt->setPixmap(pix);
|
||||||
|
|
||||||
void View::resizeEvent(QResizeEvent *event)
|
|
||||||
{
|
|
||||||
QDockWidget::resizeEvent(event);
|
|
||||||
if (m_artPixmap.isNull()) return;
|
|
||||||
// Use the new dock width from the event so we don't lag behind the layout
|
|
||||||
const int side = qMax(32, event->size().width() - 16);
|
|
||||||
m_albumArt->setFixedHeight(side);
|
|
||||||
m_albumArt->setPixmap(m_artPixmap.scaled(side, side, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
||||||
}
|
|
||||||
|
|
||||||
void View::scaleArtToWidth()
|
|
||||||
{
|
|
||||||
if (m_artPixmap.isNull()) return;
|
|
||||||
const int side = qMax(32, width() - 16);
|
|
||||||
m_albumArt->setFixedHeight(side);
|
|
||||||
m_albumArt->setPixmap(m_artPixmap.scaled(side, side, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Context
|
} // namespace Context
|
||||||
|
|||||||
@@ -3,15 +3,49 @@
|
|||||||
#include "../../backend/qobuzbackend.hpp"
|
#include "../../backend/qobuzbackend.hpp"
|
||||||
|
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
|
#include <QWidget>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QResizeEvent>
|
#include <QPainter>
|
||||||
|
#include <QPaintEvent>
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
namespace Context
|
namespace Context
|
||||||
{
|
{
|
||||||
|
/// Square art widget: always as wide as its parent allows, height follows width.
|
||||||
|
class ArtWidget : public QWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ArtWidget(QWidget *parent = nullptr) : QWidget(parent)
|
||||||
|
{
|
||||||
|
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPixmap(const QPixmap &px) { m_pix = px; update(); }
|
||||||
|
bool hasHeightForWidth() const override { return true; }
|
||||||
|
int heightForWidth(int w) const override { return w; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent *) override
|
||||||
|
{
|
||||||
|
QPainter p(this);
|
||||||
|
if (m_pix.isNull()) {
|
||||||
|
p.fillRect(rect(), QColor(0x1a, 0x1a, 0x1a));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QPixmap scaled = m_pix.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||||
|
p.fillRect(rect(), QColor(0x1a, 0x1a, 0x1a));
|
||||||
|
p.drawPixmap((width() - scaled.width()) / 2,
|
||||||
|
(height() - scaled.height()) / 2,
|
||||||
|
scaled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QPixmap m_pix;
|
||||||
|
};
|
||||||
|
|
||||||
class View : public QDockWidget
|
class View : public QDockWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -23,18 +57,12 @@ namespace Context
|
|||||||
void onTrackChanged(const QJsonObject &track);
|
void onTrackChanged(const QJsonObject &track);
|
||||||
void onArtReady(QNetworkReply *reply);
|
void onArtReady(QNetworkReply *reply);
|
||||||
|
|
||||||
protected:
|
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void scaleArtToWidth();
|
|
||||||
|
|
||||||
QobuzBackend *m_backend = nullptr;
|
QobuzBackend *m_backend = nullptr;
|
||||||
QLabel *m_albumArt = nullptr;
|
ArtWidget *m_albumArt = nullptr;
|
||||||
QLabel *m_title = nullptr;
|
QLabel *m_title = nullptr;
|
||||||
QLabel *m_artist = nullptr;
|
QLabel *m_artist = nullptr;
|
||||||
QNetworkAccessManager *m_nam = nullptr;
|
QNetworkAccessManager *m_nam = nullptr;
|
||||||
QString m_currentArtUrl;
|
QString m_currentArtUrl;
|
||||||
QPixmap m_artPixmap;
|
|
||||||
};
|
};
|
||||||
} // namespace Context
|
} // namespace Context
|
||||||
|
|||||||
@@ -36,6 +36,11 @@ MainContent::MainContent(QobuzBackend *backend, PlayQueue *queue, QWidget *paren
|
|||||||
[this] { m_tracks->playAll(false); });
|
[this] { m_tracks->playAll(false); });
|
||||||
QObject::connect(m_header->shuffleButton(), &QPushButton::clicked,
|
QObject::connect(m_header->shuffleButton(), &QPushButton::clicked,
|
||||||
[this] { m_tracks->playAll(true); });
|
[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_albumList = new AlbumListView(this);
|
||||||
m_artistList = new ArtistListView(this);
|
m_artistList = new ArtistListView(this);
|
||||||
|
|||||||
@@ -150,8 +150,8 @@ void MainToolBar::setCurrentTrack(const QJsonObject &track)
|
|||||||
void MainToolBar::updateProgress(quint64 position, quint64 duration)
|
void MainToolBar::updateProgress(quint64 position, quint64 duration)
|
||||||
{
|
{
|
||||||
if (m_seeking) return;
|
if (m_seeking) return;
|
||||||
const int sliderPos = duration > 0
|
const int sliderPos = (duration > 0)
|
||||||
? static_cast<int>(position * 1000 / duration) : 0;
|
? static_cast<int>(qMin(position * 1000 / duration, quint64(1000))) : 0;
|
||||||
m_progress->blockSignals(true);
|
m_progress->blockSignals(true);
|
||||||
m_progress->setValue(sliderPos);
|
m_progress->setValue(sliderPos);
|
||||||
m_progress->blockSignals(false);
|
m_progress->blockSignals(false);
|
||||||
|
|||||||
@@ -173,7 +173,9 @@ void QueuePanel::refresh()
|
|||||||
|
|
||||||
for (int i = 0; i < upcoming.size(); ++i) {
|
for (int i = 0; i < upcoming.size(); ++i) {
|
||||||
const QJsonObject &t = upcoming.at(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()
|
const QString artist = t["performer"].toObject()["name"].toString().isEmpty()
|
||||||
? t["album"].toObject()["artist"].toObject()["name"].toString()
|
? t["album"].toObject()["artist"].toObject()["name"].toString()
|
||||||
: t["performer"].toObject()["name"].toString();
|
: t["performer"].toObject()["name"].toString();
|
||||||
|
|||||||
@@ -49,11 +49,16 @@ public:
|
|||||||
m_title->setWordWrap(true);
|
m_title->setWordWrap(true);
|
||||||
vlay->addWidget(m_title);
|
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();
|
QFont sf = m_subtitle->font();
|
||||||
sf.setPointSize(sf.pointSize() + 1);
|
sf.setPointSize(sf.pointSize() + 1);
|
||||||
m_subtitle->setFont(sf);
|
m_subtitle->setFont(sf);
|
||||||
m_subtitle->setWordWrap(true);
|
|
||||||
vlay->addWidget(m_subtitle);
|
vlay->addWidget(m_subtitle);
|
||||||
|
|
||||||
m_meta = new QLabel(info);
|
m_meta = new QLabel(info);
|
||||||
@@ -90,6 +95,7 @@ public:
|
|||||||
|
|
||||||
btnRow->addStretch();
|
btnRow->addStretch();
|
||||||
vlay->addLayout(btnRow);
|
vlay->addLayout(btnRow);
|
||||||
|
vlay->addStretch(1);
|
||||||
|
|
||||||
hlay->addWidget(info, 1);
|
hlay->addWidget(info, 1);
|
||||||
|
|
||||||
@@ -108,10 +114,16 @@ public:
|
|||||||
QPushButton *playButton() { return m_playBtn; }
|
QPushButton *playButton() { return m_playBtn; }
|
||||||
QPushButton *shuffleButton() { return m_shuffleBtn; }
|
QPushButton *shuffleButton() { return m_shuffleBtn; }
|
||||||
|
|
||||||
|
QPushButton *subtitleButton() { return m_subtitle; }
|
||||||
|
qint64 artistId() const { return m_artistId; }
|
||||||
|
|
||||||
void setAlbum(const QJsonObject &album)
|
void setAlbum(const QJsonObject &album)
|
||||||
{
|
{
|
||||||
m_title->setText(album["title"].toString());
|
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->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));
|
m_meta->setText(buildAlbumMeta(album));
|
||||||
fetchArt(album["image"].toObject());
|
fetchArt(album["image"].toObject());
|
||||||
show();
|
show();
|
||||||
@@ -120,9 +132,12 @@ public:
|
|||||||
void setPlaylist(const QJsonObject &playlist)
|
void setPlaylist(const QJsonObject &playlist)
|
||||||
{
|
{
|
||||||
m_title->setText(playlist["name"].toString());
|
m_title->setText(playlist["name"].toString());
|
||||||
|
m_artistId = 0;
|
||||||
const QString desc = playlist["description"].toString();
|
const QString desc = playlist["description"].toString();
|
||||||
const QString owner = playlist["owner"].toObject()["name"].toString();
|
const QString owner = playlist["owner"].toObject()["name"].toString();
|
||||||
m_subtitle->setText(desc.isEmpty() ? owner : desc);
|
m_subtitle->setText(desc.isEmpty() ? owner : desc);
|
||||||
|
m_subtitle->setEnabled(false);
|
||||||
|
m_subtitle->setCursor(Qt::ArrowCursor);
|
||||||
m_meta->setText(buildPlaylistMeta(playlist));
|
m_meta->setText(buildPlaylistMeta(playlist));
|
||||||
|
|
||||||
// Try images300 → images150 → images (API returns mosaic arrays, not image_rectangle)
|
// Try images300 → images150 → images (API returns mosaic arrays, not image_rectangle)
|
||||||
@@ -200,10 +215,11 @@ private:
|
|||||||
|
|
||||||
QLabel *m_art = nullptr;
|
QLabel *m_art = nullptr;
|
||||||
QLabel *m_title = nullptr;
|
QLabel *m_title = nullptr;
|
||||||
QLabel *m_subtitle = nullptr;
|
QPushButton *m_subtitle = nullptr;
|
||||||
QLabel *m_meta = nullptr;
|
QLabel *m_meta = nullptr;
|
||||||
QPushButton *m_playBtn = nullptr;
|
QPushButton *m_playBtn = nullptr;
|
||||||
QPushButton *m_shuffleBtn = nullptr;
|
QPushButton *m_shuffleBtn = nullptr;
|
||||||
QNetworkAccessManager *m_nam = nullptr;
|
QNetworkAccessManager *m_nam = nullptr;
|
||||||
QString m_currentArtUrl;
|
QString m_currentArtUrl;
|
||||||
|
qint64 m_artistId = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,10 +4,9 @@
|
|||||||
#include "../util/icon.hpp"
|
#include "../util/icon.hpp"
|
||||||
|
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QWidgetAction>
|
#include <QFrame>
|
||||||
#include <QMenu>
|
|
||||||
#include <QLabel>
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
/// A toolbar button that shows a volume slider popup when clicked.
|
/// A toolbar button that shows a volume slider popup when clicked.
|
||||||
class VolumeButton : public QToolButton
|
class VolumeButton : public QToolButton
|
||||||
@@ -17,33 +16,36 @@ class VolumeButton : public QToolButton
|
|||||||
public:
|
public:
|
||||||
explicit VolumeButton(QWidget *parent = nullptr) : QToolButton(parent)
|
explicit VolumeButton(QWidget *parent = nullptr) : QToolButton(parent)
|
||||||
{
|
{
|
||||||
setPopupMode(QToolButton::InstantPopup);
|
|
||||||
setIcon(Icon::volumeHigh());
|
setIcon(Icon::volumeHigh());
|
||||||
|
|
||||||
auto *menu = new QMenu(this);
|
// Qt::Popup closes automatically when the user clicks outside.
|
||||||
auto *widget = new QWidget(menu);
|
m_popup = new QFrame(this, Qt::Popup);
|
||||||
widget->setMinimumWidth(72);
|
m_popup->setFrameShape(QFrame::StyledPanel);
|
||||||
auto *layout = new QVBoxLayout(widget);
|
m_popup->setFrameShadow(QFrame::Raised);
|
||||||
layout->setContentsMargins(6, 6, 6, 6);
|
|
||||||
|
|
||||||
m_label = new QLabel("80%", widget);
|
auto *layout = new QVBoxLayout(m_popup);
|
||||||
|
layout->setContentsMargins(10, 10, 10, 10);
|
||||||
|
layout->setSpacing(6);
|
||||||
|
|
||||||
|
m_label = new QLabel(QStringLiteral("80%"), m_popup);
|
||||||
m_label->setAlignment(Qt::AlignCenter);
|
m_label->setAlignment(Qt::AlignCenter);
|
||||||
|
layout->addWidget(m_label);
|
||||||
|
|
||||||
m_slider = new ClickableSlider(Qt::Vertical, widget);
|
m_slider = new ClickableSlider(Qt::Vertical, m_popup);
|
||||||
m_slider->setRange(0, 100);
|
m_slider->setRange(0, 100);
|
||||||
m_slider->setValue(80);
|
m_slider->setValue(80);
|
||||||
m_slider->setFixedHeight(120);
|
m_slider->setFixedHeight(120);
|
||||||
|
layout->addWidget(m_slider, 0, Qt::AlignHCenter);
|
||||||
|
|
||||||
layout->addWidget(m_label);
|
// Size the popup at its maximum (label = "100%") and lock it
|
||||||
layout->addWidget(m_slider);
|
m_label->setText(QStringLiteral("100%"));
|
||||||
|
m_popup->adjustSize();
|
||||||
auto *action = new QWidgetAction(menu);
|
m_popup->setFixedSize(m_popup->sizeHint());
|
||||||
action->setDefaultWidget(widget);
|
m_label->setText(QStringLiteral("80%"));
|
||||||
menu->addAction(action);
|
|
||||||
setMenu(menu);
|
|
||||||
|
|
||||||
|
connect(this, &QToolButton::clicked, this, &VolumeButton::togglePopup);
|
||||||
connect(m_slider, &QSlider::valueChanged, this, [this](int v) {
|
connect(m_slider, &QSlider::valueChanged, this, [this](int v) {
|
||||||
m_label->setText(QString::number(v) + "%");
|
m_label->setText(QString::number(v) + QStringLiteral("%"));
|
||||||
updateIcon(v);
|
updateIcon(v);
|
||||||
emit volumeChanged(v);
|
emit volumeChanged(v);
|
||||||
});
|
});
|
||||||
@@ -56,14 +58,31 @@ public:
|
|||||||
m_slider->blockSignals(true);
|
m_slider->blockSignals(true);
|
||||||
m_slider->setValue(v);
|
m_slider->setValue(v);
|
||||||
m_slider->blockSignals(false);
|
m_slider->blockSignals(false);
|
||||||
m_label->setText(QString::number(v) + "%");
|
m_label->setText(QString::number(v) + QStringLiteral("%"));
|
||||||
updateIcon(v);
|
updateIcon(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void volumeChanged(int volume);
|
void volumeChanged(int volume);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void togglePopup()
|
||||||
|
{
|
||||||
|
if (m_popup->isVisible()) {
|
||||||
|
m_popup->hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Centre popup horizontally over button, place below it
|
||||||
|
const QPoint global = mapToGlobal(
|
||||||
|
QPoint(width() / 2 - m_popup->width() / 2,
|
||||||
|
height() + 4));
|
||||||
|
m_popup->move(global);
|
||||||
|
m_popup->show();
|
||||||
|
m_popup->raise();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QFrame *m_popup = nullptr;
|
||||||
ClickableSlider *m_slider = nullptr;
|
ClickableSlider *m_slider = nullptr;
|
||||||
QLabel *m_label = nullptr;
|
QLabel *m_label = nullptr;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user