Compare commits
12 Commits
5d0011cb90
...
a21d0c8a33
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a21d0c8a33 | ||
|
|
333a620be2 | ||
|
|
b3cc2e3def | ||
|
|
3e96b6d7a8 | ||
|
|
963c9ad232 | ||
|
|
8310eceeb2 | ||
|
|
fb58c0ac8c | ||
|
|
e37de6d897 | ||
|
|
5ae18afa08 | ||
|
|
6f11b364aa | ||
|
|
4ba6d00748 | ||
|
|
e4c2694584 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,7 @@
|
|||||||
build/
|
build/
|
||||||
|
build-*/
|
||||||
target/
|
target/
|
||||||
|
src/visualizer/
|
||||||
.cache/
|
.cache/
|
||||||
*.user
|
*.user
|
||||||
*.autosave
|
*.autosave
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ enum QobuzEvent {
|
|||||||
EV_PLAYLIST_DELETED = 21,
|
EV_PLAYLIST_DELETED = 21,
|
||||||
EV_PLAYLIST_TRACK_ADDED = 22,
|
EV_PLAYLIST_TRACK_ADDED = 22,
|
||||||
EV_USER_OK = 23,
|
EV_USER_OK = 23,
|
||||||
|
EV_ARTIST_RELEASES_OK = 24,
|
||||||
|
EV_DEEP_SHUFFLE_OK = 25,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Callback signature
|
// Callback signature
|
||||||
@@ -79,6 +81,17 @@ void qobuz_backend_set_replaygain(QobuzBackendOpaque *backend, bool enabled);
|
|||||||
void qobuz_backend_set_gapless(QobuzBackendOpaque *backend, bool enabled);
|
void qobuz_backend_set_gapless(QobuzBackendOpaque *backend, bool enabled);
|
||||||
void qobuz_backend_prefetch_track(QobuzBackendOpaque *backend, int64_t track_id, int32_t format_id);
|
void qobuz_backend_prefetch_track(QobuzBackendOpaque *backend, int64_t track_id, int32_t format_id);
|
||||||
|
|
||||||
|
// Visualizer PCM access
|
||||||
|
uint32_t qobuz_backend_viz_read(QobuzBackendOpaque *backend, float *buf, uint32_t max_samples);
|
||||||
|
uint32_t qobuz_backend_viz_sample_rate(const QobuzBackendOpaque *backend);
|
||||||
|
uint32_t qobuz_backend_viz_channels(const QobuzBackendOpaque *backend);
|
||||||
|
|
||||||
|
// Artist releases (auto-paginates to fetch all)
|
||||||
|
void qobuz_backend_get_artist_releases(QobuzBackendOpaque *backend, int64_t artist_id, const char *release_type, uint32_t limit, uint32_t offset);
|
||||||
|
|
||||||
|
// Deep shuffle: fetch tracks from multiple albums (album_ids_json is a JSON array of strings)
|
||||||
|
void qobuz_backend_get_albums_tracks(QobuzBackendOpaque *backend, const char *album_ids_json);
|
||||||
|
|
||||||
// Playlist management
|
// Playlist management
|
||||||
void qobuz_backend_create_playlist(QobuzBackendOpaque *backend, const char *name);
|
void qobuz_backend_create_playlist(QobuzBackendOpaque *backend, const char *name);
|
||||||
void qobuz_backend_delete_playlist(QobuzBackendOpaque *backend, int64_t playlist_id);
|
void qobuz_backend_delete_playlist(QobuzBackendOpaque *backend, int64_t playlist_id);
|
||||||
@@ -90,6 +103,8 @@ void qobuz_backend_add_fav_track(QobuzBackendOpaque *backend, int64_t track_id);
|
|||||||
void qobuz_backend_remove_fav_track(QobuzBackendOpaque *backend, int64_t track_id);
|
void qobuz_backend_remove_fav_track(QobuzBackendOpaque *backend, int64_t track_id);
|
||||||
void qobuz_backend_add_fav_album(QobuzBackendOpaque *backend, const char *album_id);
|
void qobuz_backend_add_fav_album(QobuzBackendOpaque *backend, const char *album_id);
|
||||||
void qobuz_backend_remove_fav_album(QobuzBackendOpaque *backend, const char *album_id);
|
void qobuz_backend_remove_fav_album(QobuzBackendOpaque *backend, const char *album_id);
|
||||||
|
void qobuz_backend_add_fav_artist(QobuzBackendOpaque *backend, int64_t artist_id);
|
||||||
|
void qobuz_backend_remove_fav_artist(QobuzBackendOpaque *backend, int64_t artist_id);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -255,20 +255,6 @@ impl QobuzClient {
|
|||||||
|
|
||||||
// --- Artist ---
|
// --- Artist ---
|
||||||
|
|
||||||
pub async fn get_artist(&self, artist_id: i64) -> Result<ArtistDto> {
|
|
||||||
let resp = self
|
|
||||||
.get_request("artist/get")
|
|
||||||
.query(&[
|
|
||||||
("artist_id", artist_id.to_string()),
|
|
||||||
("extra", "albums".to_string()),
|
|
||||||
("albums_limit", "200".to_string()),
|
|
||||||
])
|
|
||||||
.send()
|
|
||||||
.await?;
|
|
||||||
let body = Self::check_response(resp).await?;
|
|
||||||
Ok(serde_json::from_value(body)?)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn get_artist_page(&self, artist_id: i64) -> Result<Value> {
|
pub async fn get_artist_page(&self, artist_id: i64) -> Result<Value> {
|
||||||
let resp = self
|
let resp = self
|
||||||
.get_request("artist/page")
|
.get_request("artist/page")
|
||||||
@@ -278,6 +264,28 @@ impl QobuzClient {
|
|||||||
Self::check_response(resp).await
|
Self::check_response(resp).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn get_artist_releases_list(
|
||||||
|
&self,
|
||||||
|
artist_id: i64,
|
||||||
|
release_type: &str,
|
||||||
|
limit: u32,
|
||||||
|
offset: u32,
|
||||||
|
) -> Result<Value> {
|
||||||
|
let resp = self
|
||||||
|
.get_request("artist/getReleasesList")
|
||||||
|
.query(&[
|
||||||
|
("artist_id", artist_id.to_string()),
|
||||||
|
("release_type", release_type.to_string()),
|
||||||
|
("sort", "release_date".to_string()),
|
||||||
|
("order", "desc".to_string()),
|
||||||
|
("limit", limit.to_string()),
|
||||||
|
("offset", offset.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> {
|
||||||
@@ -439,4 +447,24 @@ impl QobuzClient {
|
|||||||
Self::check_response(resp).await?;
|
Self::check_response(resp).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn add_fav_artist(&self, artist_id: i64) -> Result<()> {
|
||||||
|
let resp = self
|
||||||
|
.get_request("favorite/create")
|
||||||
|
.query(&[("type", "artists"), ("artist_ids", &artist_id.to_string())])
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
Self::check_response(resp).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn remove_fav_artist(&self, artist_id: i64) -> Result<()> {
|
||||||
|
let resp = self
|
||||||
|
.get_request("favorite/delete")
|
||||||
|
.query(&[("type", "artists"), ("artist_ids", &artist_id.to_string())])
|
||||||
|
.send()
|
||||||
|
.await?;
|
||||||
|
Self::check_response(resp).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -244,30 +244,5 @@ impl Format {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn label(self) -> &'static str {
|
|
||||||
match self {
|
|
||||||
Format::Mp3 => "MP3 320",
|
|
||||||
Format::Cd => "CD 16-bit",
|
|
||||||
Format::HiRes96 => "Hi-Res 24-bit/96kHz",
|
|
||||||
Format::HiRes192 => "Hi-Res 24-bit/192kHz",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn all() -> &'static [Format] {
|
|
||||||
&[Format::HiRes192, Format::HiRes96, Format::Cd, Format::Mp3]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- QWS ---
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone, Serialize)]
|
|
||||||
pub struct QwsTokenResponse {
|
|
||||||
pub jwt_qws: Option<QwsToken>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone, Serialize)]
|
|
||||||
pub struct QwsToken {
|
|
||||||
pub exp: Option<i64>,
|
|
||||||
pub jwt: Option<String>,
|
|
||||||
pub endpoint: Option<String>,
|
|
||||||
}
|
|
||||||
|
|||||||
167
rust/src/lib.rs
167
rust/src/lib.rs
@@ -68,6 +68,8 @@ pub const EV_POSITION: c_int = 16;
|
|||||||
pub const EV_TRACK_URL_OK: c_int = 17;
|
pub const EV_TRACK_URL_OK: c_int = 17;
|
||||||
pub const EV_TRACK_URL_ERR: c_int = 18;
|
pub const EV_TRACK_URL_ERR: c_int = 18;
|
||||||
pub const EV_GENERIC_ERR: c_int = 19;
|
pub const EV_GENERIC_ERR: c_int = 19;
|
||||||
|
pub const EV_ARTIST_RELEASES_OK: c_int = 24;
|
||||||
|
pub const EV_DEEP_SHUFFLE_OK: c_int = 25;
|
||||||
|
|
||||||
// ---------- Callback ----------
|
// ---------- Callback ----------
|
||||||
|
|
||||||
@@ -188,11 +190,9 @@ pub unsafe extern "C" fn qobuz_backend_login(
|
|||||||
pub unsafe extern "C" fn qobuz_backend_set_token(ptr: *mut Backend, token: *const c_char) {
|
pub unsafe extern "C" fn qobuz_backend_set_token(ptr: *mut Backend, token: *const c_char) {
|
||||||
let inner = &(*ptr).0;
|
let inner = &(*ptr).0;
|
||||||
let token = CStr::from_ptr(token).to_string_lossy().into_owned();
|
let token = CStr::from_ptr(token).to_string_lossy().into_owned();
|
||||||
let client = inner.client.clone();
|
// Use blocking_lock (called from Qt main thread, not a tokio thread) so the
|
||||||
// blocking_lock is available on tokio::sync::Mutex when not in an async context
|
// token is set before any subsequent getUser/library requests are spawned.
|
||||||
inner.rt.spawn(async move {
|
inner.client.blocking_lock().set_auth_token(token);
|
||||||
client.lock().await.set_auth_token(token);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- Search ----------
|
// ---------- Search ----------
|
||||||
@@ -256,6 +256,109 @@ pub unsafe extern "C" fn qobuz_backend_get_artist(ptr: *mut Backend, artist_id:
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- Artist releases ----------
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn qobuz_backend_get_artist_releases(
|
||||||
|
ptr: *mut Backend,
|
||||||
|
artist_id: i64,
|
||||||
|
release_type: *const c_char,
|
||||||
|
limit: u32,
|
||||||
|
_offset: u32,
|
||||||
|
) {
|
||||||
|
let inner = &(*ptr).0;
|
||||||
|
let client = inner.client.clone();
|
||||||
|
let cb = inner.cb; let ud = inner.ud;
|
||||||
|
let rtype = CStr::from_ptr(release_type).to_string_lossy().into_owned();
|
||||||
|
|
||||||
|
spawn(inner, async move {
|
||||||
|
// Auto-paginate: fetch all pages until has_more is false.
|
||||||
|
let mut all_items: Vec<serde_json::Value> = Vec::new();
|
||||||
|
let mut offset: u32 = 0;
|
||||||
|
loop {
|
||||||
|
let result = client.lock().await
|
||||||
|
.get_artist_releases_list(artist_id, &rtype, limit, offset)
|
||||||
|
.await;
|
||||||
|
match result {
|
||||||
|
Ok(r) => {
|
||||||
|
let obj = r.as_object().cloned().unwrap_or_default();
|
||||||
|
if let Some(items) = obj.get("items").and_then(|v| v.as_array()) {
|
||||||
|
all_items.extend(items.iter().cloned());
|
||||||
|
}
|
||||||
|
let has_more = obj.get("has_more").and_then(|v| v.as_bool()).unwrap_or(false);
|
||||||
|
if !has_more {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
offset += limit;
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
call_cb(cb, ud, EV_GENERIC_ERR, &err_json(&e.to_string()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let result = serde_json::json!({
|
||||||
|
"release_type": rtype,
|
||||||
|
"items": all_items,
|
||||||
|
"has_more": false,
|
||||||
|
"offset": 0
|
||||||
|
});
|
||||||
|
call_cb(cb, ud, EV_ARTIST_RELEASES_OK, &serde_json::to_string(&result).unwrap_or_default());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------- Deep shuffle (fetch tracks from multiple albums) ----------
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn qobuz_backend_get_albums_tracks(
|
||||||
|
ptr: *mut Backend,
|
||||||
|
album_ids_json: *const c_char,
|
||||||
|
) {
|
||||||
|
let inner = &(*ptr).0;
|
||||||
|
let client = inner.client.clone();
|
||||||
|
let cb = inner.cb; let ud = inner.ud;
|
||||||
|
let ids_str = CStr::from_ptr(album_ids_json).to_string_lossy().into_owned();
|
||||||
|
|
||||||
|
let album_ids: Vec<String> = match serde_json::from_str(&ids_str) {
|
||||||
|
Ok(v) => v,
|
||||||
|
Err(e) => {
|
||||||
|
call_cb(cb, ud, EV_GENERIC_ERR, &err_json(&e.to_string()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
spawn(inner, async move {
|
||||||
|
let mut all_tracks: Vec<serde_json::Value> = Vec::new();
|
||||||
|
for id in &album_ids {
|
||||||
|
let result = client.lock().await.get_album(id).await;
|
||||||
|
if let Ok(album) = result {
|
||||||
|
if let Some(tracks) = album.tracks.as_ref().and_then(|t| t.items.as_ref()) {
|
||||||
|
for t in tracks {
|
||||||
|
// Serialize track and inject album info for playback context
|
||||||
|
if let Ok(mut tv) = serde_json::to_value(t) {
|
||||||
|
if let Some(obj) = tv.as_object_mut() {
|
||||||
|
// Ensure album context is present on each track
|
||||||
|
if obj.get("album").is_none() || obj["album"].is_null() {
|
||||||
|
obj.insert("album".to_string(), serde_json::json!({
|
||||||
|
"id": album.id,
|
||||||
|
"title": album.title,
|
||||||
|
"artist": album.artist,
|
||||||
|
"image": album.image,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
all_tracks.push(tv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Skip albums that fail — don't abort the whole operation
|
||||||
|
}
|
||||||
|
let result = serde_json::json!({ "tracks": all_tracks });
|
||||||
|
call_cb(cb, ud, EV_DEEP_SHUFFLE_OK, &serde_json::to_string(&result).unwrap_or_default());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- Playlist ----------
|
// ---------- Playlist ----------
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
@@ -410,7 +513,7 @@ pub unsafe extern "C" fn qobuz_backend_play_track(
|
|||||||
if let Some(dur) = track.duration {
|
if let Some(dur) = track.duration {
|
||||||
status.duration_secs.store(dur as u64, std::sync::atomic::Ordering::Relaxed);
|
status.duration_secs.store(dur as u64, std::sync::atomic::Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
let _ = cmd_tx.send(player::PlayerCommand::Play(player::TrackInfo { track, url, format, replaygain_db }));
|
let _ = cmd_tx.send(player::PlayerCommand::Play(player::TrackInfo { track, url, replaygain_db }));
|
||||||
|
|
||||||
// 5. State notification
|
// 5. State notification
|
||||||
call_cb(cb, ud, EV_STATE_CHANGED, r#"{"state":"playing"}"#);
|
call_cb(cb, ud, EV_STATE_CHANGED, r#"{"state":"playing"}"#);
|
||||||
@@ -571,6 +674,30 @@ pub unsafe extern "C" fn qobuz_backend_remove_fav_album(ptr: *mut Backend, album
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn qobuz_backend_add_fav_artist(ptr: *mut Backend, artist_id: i64) {
|
||||||
|
let inner = &(*ptr).0;
|
||||||
|
let client = inner.client.clone();
|
||||||
|
let cb = inner.cb; let ud = inner.ud;
|
||||||
|
spawn(inner, async move {
|
||||||
|
if let Err(e) = client.lock().await.add_fav_artist(artist_id).await {
|
||||||
|
call_cb(cb, ud, EV_GENERIC_ERR, &err_json(&e.to_string()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn qobuz_backend_remove_fav_artist(ptr: *mut Backend, artist_id: i64) {
|
||||||
|
let inner = &(*ptr).0;
|
||||||
|
let client = inner.client.clone();
|
||||||
|
let cb = inner.cb; let ud = inner.ud;
|
||||||
|
spawn(inner, async move {
|
||||||
|
if let Err(e) = client.lock().await.remove_fav_artist(artist_id).await {
|
||||||
|
call_cb(cb, ud, EV_GENERIC_ERR, &err_json(&e.to_string()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- User ----------
|
// ---------- User ----------
|
||||||
|
|
||||||
pub const EV_USER_OK: c_int = 23;
|
pub const EV_USER_OK: c_int = 23;
|
||||||
@@ -590,6 +717,34 @@ pub unsafe extern "C" fn qobuz_backend_get_user(ptr: *mut Backend) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- Visualizer PCM access ----------
|
||||||
|
|
||||||
|
/// Read up to `max_samples` f32 PCM values into `buf`.
|
||||||
|
/// Returns the number of samples actually read.
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn qobuz_backend_viz_read(
|
||||||
|
ptr: *mut Backend,
|
||||||
|
buf: *mut f32,
|
||||||
|
max_samples: u32,
|
||||||
|
) -> u32 {
|
||||||
|
let consumer = &(*ptr).0.player.status.viz_consumer;
|
||||||
|
let Ok(mut lock) = consumer.try_lock() else { return 0 };
|
||||||
|
let slice = std::slice::from_raw_parts_mut(buf, max_samples as usize);
|
||||||
|
rb::RbConsumer::read(&mut *lock, slice).unwrap_or(0) as u32
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns current sample rate of the audio stream (0 if idle).
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn qobuz_backend_viz_sample_rate(ptr: *const Backend) -> u32 {
|
||||||
|
(*ptr).0.player.status.viz_sample_rate.load(std::sync::atomic::Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns current channel count (0 if idle).
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn qobuz_backend_viz_channels(ptr: *const Backend) -> u32 {
|
||||||
|
(*ptr).0.player.status.viz_channels.load(std::sync::atomic::Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
|
||||||
// ---------- Playlist management ----------
|
// ---------- Playlist management ----------
|
||||||
|
|
||||||
pub const EV_PLAYLIST_CREATED: c_int = 20;
|
pub const EV_PLAYLIST_CREATED: c_int = 20;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use rb::RB;
|
||||||
use std::io::{self, Read, Seek, SeekFrom};
|
use std::io::{self, Read, Seek, SeekFrom};
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
@@ -176,8 +177,12 @@ pub fn play_track_inline(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if audio_output.is_none() {
|
if audio_output.is_none() {
|
||||||
*audio_output = Some(AudioOutput::try_open(sample_rate, channels)?);
|
let mut ao = AudioOutput::try_open(sample_rate, channels)?;
|
||||||
|
ao.set_viz_producer(status.viz_ring.producer());
|
||||||
|
*audio_output = Some(ao);
|
||||||
}
|
}
|
||||||
|
status.viz_sample_rate.store(sample_rate, Ordering::Relaxed);
|
||||||
|
status.viz_channels.store(channels as u32, Ordering::Relaxed);
|
||||||
let ao = audio_output.as_mut().unwrap();
|
let ao = audio_output.as_mut().unwrap();
|
||||||
|
|
||||||
let mut stopped = false;
|
let mut stopped = false;
|
||||||
@@ -195,11 +200,6 @@ pub fn play_track_inline(
|
|||||||
paused.store(false, Ordering::SeqCst);
|
paused.store(false, Ordering::SeqCst);
|
||||||
*status.state.lock().unwrap() = super::PlayerState::Playing;
|
*status.state.lock().unwrap() = super::PlayerState::Playing;
|
||||||
}
|
}
|
||||||
Ok(PlayerCommand::Seek(s)) => {
|
|
||||||
status.seek_target_secs.store(s, Ordering::Relaxed);
|
|
||||||
status.seek_requested.load(Ordering::SeqCst); // read-side fence
|
|
||||||
status.seek_requested.store(true, Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
Ok(PlayerCommand::SetVolume(v)) => {
|
Ok(PlayerCommand::SetVolume(v)) => {
|
||||||
status.volume.store(v, Ordering::Relaxed);
|
status.volume.store(v, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,17 @@
|
|||||||
mod decoder;
|
mod decoder;
|
||||||
pub mod output;
|
pub mod output;
|
||||||
|
|
||||||
|
use rb::{SpscRb, RB};
|
||||||
use std::sync::{
|
use std::sync::{
|
||||||
atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering},
|
atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicU8, Ordering},
|
||||||
Arc,
|
Arc,
|
||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::api::{Format, TrackDto};
|
use crate::api::TrackDto;
|
||||||
|
|
||||||
|
/// Size of the visualizer ring buffer in f32 samples (~180ms at 44.1kHz stereo).
|
||||||
|
const VIZ_RING_SIZE: usize = 16 * 1024;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum PlayerCommand {
|
pub enum PlayerCommand {
|
||||||
@@ -15,7 +19,6 @@ pub enum PlayerCommand {
|
|||||||
Pause,
|
Pause,
|
||||||
Resume,
|
Resume,
|
||||||
Stop,
|
Stop,
|
||||||
Seek(u64),
|
|
||||||
SetVolume(u8),
|
SetVolume(u8),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +26,6 @@ pub enum PlayerCommand {
|
|||||||
pub struct TrackInfo {
|
pub struct TrackInfo {
|
||||||
pub track: TrackDto,
|
pub track: TrackDto,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
pub format: Format,
|
|
||||||
/// ReplayGain track gain in dB, if enabled and available.
|
/// ReplayGain track gain in dB, if enabled and available.
|
||||||
pub replaygain_db: Option<f64>,
|
pub replaygain_db: Option<f64>,
|
||||||
}
|
}
|
||||||
@@ -33,7 +35,6 @@ pub enum PlayerState {
|
|||||||
Idle,
|
Idle,
|
||||||
Playing,
|
Playing,
|
||||||
Paused,
|
Paused,
|
||||||
Stopped,
|
|
||||||
Error(String),
|
Error(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,10 +54,17 @@ pub struct PlayerStatus {
|
|||||||
pub replaygain_gain: Arc<std::sync::Mutex<f32>>,
|
pub replaygain_gain: Arc<std::sync::Mutex<f32>>,
|
||||||
/// When false the audio output is torn down after each track, producing a gap.
|
/// When false the audio output is torn down after each track, producing a gap.
|
||||||
pub gapless: Arc<AtomicBool>,
|
pub gapless: Arc<AtomicBool>,
|
||||||
|
/// Visualizer ring buffer (consumer side, read by FFI).
|
||||||
|
pub viz_ring: Arc<SpscRb<f32>>,
|
||||||
|
pub viz_consumer: Arc<std::sync::Mutex<rb::Consumer<f32>>>,
|
||||||
|
pub viz_sample_rate: Arc<AtomicU32>,
|
||||||
|
pub viz_channels: Arc<AtomicU32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlayerStatus {
|
impl PlayerStatus {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
let viz_ring = Arc::new(SpscRb::new(VIZ_RING_SIZE));
|
||||||
|
let viz_consumer = Arc::new(std::sync::Mutex::new(viz_ring.consumer()));
|
||||||
Self {
|
Self {
|
||||||
state: Arc::new(std::sync::Mutex::new(PlayerState::Idle)),
|
state: Arc::new(std::sync::Mutex::new(PlayerState::Idle)),
|
||||||
position_secs: Arc::new(AtomicU64::new(0)),
|
position_secs: Arc::new(AtomicU64::new(0)),
|
||||||
@@ -68,6 +76,10 @@ impl PlayerStatus {
|
|||||||
seek_target_secs: Arc::new(AtomicU64::new(0)),
|
seek_target_secs: Arc::new(AtomicU64::new(0)),
|
||||||
replaygain_gain: Arc::new(std::sync::Mutex::new(1.0)),
|
replaygain_gain: Arc::new(std::sync::Mutex::new(1.0)),
|
||||||
gapless: Arc::new(AtomicBool::new(false)),
|
gapless: Arc::new(AtomicBool::new(false)),
|
||||||
|
viz_ring,
|
||||||
|
viz_consumer,
|
||||||
|
viz_sample_rate: Arc::new(AtomicU32::new(0)),
|
||||||
|
viz_channels: Arc::new(AtomicU32::new(0)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,9 +99,6 @@ impl PlayerStatus {
|
|||||||
self.volume.load(Ordering::Relaxed)
|
self.volume.load(Ordering::Relaxed)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_current_track(&self) -> Option<TrackDto> {
|
|
||||||
self.current_track.lock().unwrap().clone()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
@@ -169,10 +178,6 @@ fn player_loop(rx: std::sync::mpsc::Receiver<PlayerCommand>, status: PlayerStatu
|
|||||||
Ok(PlayerCommand::SetVolume(v)) => {
|
Ok(PlayerCommand::SetVolume(v)) => {
|
||||||
status.volume.store(v, Ordering::Relaxed);
|
status.volume.store(v, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
Ok(PlayerCommand::Seek(s)) => {
|
|
||||||
status.seek_target_secs.store(s, Ordering::Relaxed);
|
|
||||||
status.seek_requested.store(true, Ordering::SeqCst);
|
|
||||||
}
|
|
||||||
Ok(_) => {} // Pause/Resume ignored when idle
|
Ok(_) => {} // Pause/Resume ignored when idle
|
||||||
Err(RecvTimeoutError::Timeout) => {}
|
Err(RecvTimeoutError::Timeout) => {}
|
||||||
Err(RecvTimeoutError::Disconnected) => break 'outer,
|
Err(RecvTimeoutError::Disconnected) => break 'outer,
|
||||||
@@ -210,6 +215,9 @@ fn player_loop(rx: std::sync::mpsc::Receiver<PlayerCommand>, status: PlayerStatu
|
|||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("playback error: {e}");
|
eprintln!("playback error: {e}");
|
||||||
*status.state.lock().unwrap() = PlayerState::Error(e.to_string());
|
*status.state.lock().unwrap() = PlayerState::Error(e.to_string());
|
||||||
|
// Signal track end so the queue advances to the next track
|
||||||
|
// instead of stalling on an unplayable track.
|
||||||
|
status.track_finished.store(true, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const RING_BUFFER_SIZE: usize = 32 * 1024;
|
|||||||
|
|
||||||
pub struct AudioOutput {
|
pub struct AudioOutput {
|
||||||
ring_buf_producer: rb::Producer<f32>,
|
ring_buf_producer: rb::Producer<f32>,
|
||||||
|
viz_producer: Option<rb::Producer<f32>>,
|
||||||
_stream: cpal::Stream,
|
_stream: cpal::Stream,
|
||||||
pub sample_rate: u32,
|
pub sample_rate: u32,
|
||||||
pub channels: usize,
|
pub channels: usize,
|
||||||
@@ -51,12 +52,17 @@ impl AudioOutput {
|
|||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
ring_buf_producer: producer,
|
ring_buf_producer: producer,
|
||||||
|
viz_producer: None,
|
||||||
_stream: stream,
|
_stream: stream,
|
||||||
sample_rate,
|
sample_rate,
|
||||||
channels,
|
channels,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_viz_producer(&mut self, producer: rb::Producer<f32>) {
|
||||||
|
self.viz_producer = Some(producer);
|
||||||
|
}
|
||||||
|
|
||||||
pub fn write(
|
pub fn write(
|
||||||
&mut self,
|
&mut self,
|
||||||
decoded: AudioBufferRef<'_>,
|
decoded: AudioBufferRef<'_>,
|
||||||
@@ -70,6 +76,11 @@ impl AudioOutput {
|
|||||||
sample_buf.copy_interleaved_ref(decoded);
|
sample_buf.copy_interleaved_ref(decoded);
|
||||||
let samples: Vec<f32> = sample_buf.samples().iter().map(|s| s * volume).collect();
|
let samples: Vec<f32> = sample_buf.samples().iter().map(|s| s * volume).collect();
|
||||||
|
|
||||||
|
// Best-effort copy for visualizer (non-blocking, ok to drop samples)
|
||||||
|
if let Some(ref mut viz) = self.viz_producer {
|
||||||
|
let _ = viz.write(&samples);
|
||||||
|
}
|
||||||
|
|
||||||
let mut remaining = &samples[..];
|
let mut remaining = &samples[..];
|
||||||
while !remaining.is_empty() {
|
while !remaining.is_empty() {
|
||||||
if stop.load(Ordering::SeqCst) {
|
if stop.load(Ordering::SeqCst) {
|
||||||
|
|||||||
@@ -61,6 +61,19 @@ void QobuzBackend::getArtist(qint64 artistId)
|
|||||||
qobuz_backend_get_artist(m_backend, artistId);
|
qobuz_backend_get_artist(m_backend, artistId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QobuzBackend::getArtistReleases(qint64 artistId, const QString &releaseType, quint32 limit, quint32 offset)
|
||||||
|
{
|
||||||
|
qobuz_backend_get_artist_releases(m_backend, artistId,
|
||||||
|
releaseType.toUtf8().constData(), limit, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QobuzBackend::getAlbumsTracks(const QStringList &albumIds)
|
||||||
|
{
|
||||||
|
const QJsonArray arr = QJsonArray::fromStringList(albumIds);
|
||||||
|
const QByteArray json = QJsonDocument(arr).toJson(QJsonDocument::Compact);
|
||||||
|
qobuz_backend_get_albums_tracks(m_backend, json.constData());
|
||||||
|
}
|
||||||
|
|
||||||
void QobuzBackend::getPlaylist(qint64 playlistId, quint32 offset, quint32 limit)
|
void QobuzBackend::getPlaylist(qint64 playlistId, quint32 offset, quint32 limit)
|
||||||
{
|
{
|
||||||
qobuz_backend_get_playlist(m_backend, playlistId, offset, limit);
|
qobuz_backend_get_playlist(m_backend, playlistId, offset, limit);
|
||||||
@@ -149,6 +162,16 @@ void QobuzBackend::removeFavAlbum(const QString &albumId)
|
|||||||
qobuz_backend_remove_fav_album(m_backend, albumId.toUtf8().constData());
|
qobuz_backend_remove_fav_album(m_backend, albumId.toUtf8().constData());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QobuzBackend::addFavArtist(qint64 artistId)
|
||||||
|
{
|
||||||
|
qobuz_backend_add_fav_artist(m_backend, artistId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void QobuzBackend::removeFavArtist(qint64 artistId)
|
||||||
|
{
|
||||||
|
qobuz_backend_remove_fav_artist(m_backend, artistId);
|
||||||
|
}
|
||||||
|
|
||||||
// ---- playback ----
|
// ---- playback ----
|
||||||
|
|
||||||
void QobuzBackend::playTrack(qint64 trackId, int formatId)
|
void QobuzBackend::playTrack(qint64 trackId, int formatId)
|
||||||
@@ -186,6 +209,21 @@ quint64 QobuzBackend::duration() const { return qobuz_backend_get_duration(m_bac
|
|||||||
int QobuzBackend::volume() const { return qobuz_backend_get_volume(m_backend); }
|
int QobuzBackend::volume() const { return qobuz_backend_get_volume(m_backend); }
|
||||||
int QobuzBackend::state() const { return qobuz_backend_get_state(m_backend); }
|
int QobuzBackend::state() const { return qobuz_backend_get_state(m_backend); }
|
||||||
|
|
||||||
|
quint32 QobuzBackend::vizRead(float *buf, quint32 maxSamples)
|
||||||
|
{
|
||||||
|
return qobuz_backend_viz_read(m_backend, buf, maxSamples);
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 QobuzBackend::vizSampleRate() const
|
||||||
|
{
|
||||||
|
return qobuz_backend_viz_sample_rate(m_backend);
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 QobuzBackend::vizChannels() const
|
||||||
|
{
|
||||||
|
return qobuz_backend_viz_channels(m_backend);
|
||||||
|
}
|
||||||
|
|
||||||
// ---- private slots ----
|
// ---- private slots ----
|
||||||
|
|
||||||
void QobuzBackend::onPositionTick()
|
void QobuzBackend::onPositionTick()
|
||||||
@@ -227,6 +265,17 @@ void QobuzBackend::onEvent(int eventType, const QString &json)
|
|||||||
case EV_ARTIST_OK:
|
case EV_ARTIST_OK:
|
||||||
emit artistLoaded(obj);
|
emit artistLoaded(obj);
|
||||||
break;
|
break;
|
||||||
|
case 24: // EV_ARTIST_RELEASES_OK
|
||||||
|
emit artistReleasesLoaded(
|
||||||
|
obj["release_type"].toString(),
|
||||||
|
obj["items"].toArray(),
|
||||||
|
obj["has_more"].toBool(),
|
||||||
|
obj["offset"].toInt()
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
case 25: // EV_DEEP_SHUFFLE_OK
|
||||||
|
emit deepShuffleTracksLoaded(obj["tracks"].toArray());
|
||||||
|
break;
|
||||||
case EV_ARTIST_ERR:
|
case EV_ARTIST_ERR:
|
||||||
emit error(obj["error"].toString());
|
emit error(obj["error"].toString());
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
#include <QJsonArray>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
@@ -29,6 +30,8 @@ public:
|
|||||||
void search(const QString &query, quint32 offset = 0, quint32 limit = 20);
|
void search(const QString &query, quint32 offset = 0, quint32 limit = 20);
|
||||||
void getAlbum(const QString &albumId);
|
void getAlbum(const QString &albumId);
|
||||||
void getArtist(qint64 artistId);
|
void getArtist(qint64 artistId);
|
||||||
|
void getArtistReleases(qint64 artistId, const QString &releaseType, quint32 limit = 50, quint32 offset = 0);
|
||||||
|
void getAlbumsTracks(const QStringList &albumIds);
|
||||||
void getPlaylist(qint64 playlistId, quint32 offset = 0, quint32 limit = 500);
|
void getPlaylist(qint64 playlistId, quint32 offset = 0, quint32 limit = 500);
|
||||||
|
|
||||||
// --- favorites ---
|
// --- favorites ---
|
||||||
@@ -53,6 +56,8 @@ public:
|
|||||||
void removeFavTrack(qint64 trackId);
|
void removeFavTrack(qint64 trackId);
|
||||||
void addFavAlbum(const QString &albumId);
|
void addFavAlbum(const QString &albumId);
|
||||||
void removeFavAlbum(const QString &albumId);
|
void removeFavAlbum(const QString &albumId);
|
||||||
|
void addFavArtist(qint64 artistId);
|
||||||
|
void removeFavArtist(qint64 artistId);
|
||||||
|
|
||||||
// --- playback ---
|
// --- playback ---
|
||||||
void playTrack(qint64 trackId, int formatId = 6);
|
void playTrack(qint64 trackId, int formatId = 6);
|
||||||
@@ -68,6 +73,11 @@ public:
|
|||||||
/// 1 = playing, 2 = paused, 0 = idle
|
/// 1 = playing, 2 = paused, 0 = idle
|
||||||
int state() const;
|
int state() const;
|
||||||
|
|
||||||
|
// --- visualizer PCM ---
|
||||||
|
quint32 vizRead(float *buf, quint32 maxSamples);
|
||||||
|
quint32 vizSampleRate() const;
|
||||||
|
quint32 vizChannels() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// auth
|
// auth
|
||||||
void loginSuccess(const QString &token, const QJsonObject &user);
|
void loginSuccess(const QString &token, const QJsonObject &user);
|
||||||
@@ -78,6 +88,8 @@ signals:
|
|||||||
void searchResult(const QJsonObject &result);
|
void searchResult(const QJsonObject &result);
|
||||||
void albumLoaded(const QJsonObject &album);
|
void albumLoaded(const QJsonObject &album);
|
||||||
void artistLoaded(const QJsonObject &artist);
|
void artistLoaded(const QJsonObject &artist);
|
||||||
|
void artistReleasesLoaded(const QString &releaseType, const QJsonArray &items, bool hasMore, int offset);
|
||||||
|
void deepShuffleTracksLoaded(const QJsonArray &tracks);
|
||||||
void playlistLoaded(const QJsonObject &playlist);
|
void playlistLoaded(const QJsonObject &playlist);
|
||||||
void playlistCreated(const QJsonObject &playlist);
|
void playlistCreated(const QJsonObject &playlist);
|
||||||
void playlistDeleted(const QJsonObject &result);
|
void playlistDeleted(const QJsonObject &result);
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
|||||||
m_libraryDock->setObjectName(QStringLiteral("libraryDock"));
|
m_libraryDock->setObjectName(QStringLiteral("libraryDock"));
|
||||||
m_libraryDock->setFeatures(QDockWidget::DockWidgetMovable);
|
m_libraryDock->setFeatures(QDockWidget::DockWidgetMovable);
|
||||||
m_libraryDock->setWidget(m_library);
|
m_libraryDock->setWidget(m_library);
|
||||||
m_libraryDock->setMinimumWidth(200);
|
m_libraryDock->setMinimumWidth(180);
|
||||||
|
m_library->setFixedWidth(220);
|
||||||
addDockWidget(Qt::LeftDockWidgetArea, m_libraryDock);
|
addDockWidget(Qt::LeftDockWidgetArea, m_libraryDock);
|
||||||
|
|
||||||
// ---- Now-playing context dock (left, below library) ----
|
// ---- Now-playing context dock (left, below library) ----
|
||||||
@@ -84,6 +85,10 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
|||||||
connect(m_backend, &QobuzBackend::favArtistsLoaded, this, &MainWindow::onFavArtistsLoaded);
|
connect(m_backend, &QobuzBackend::favArtistsLoaded, this, &MainWindow::onFavArtistsLoaded);
|
||||||
connect(m_backend, &QobuzBackend::albumLoaded, this, &MainWindow::onAlbumLoaded);
|
connect(m_backend, &QobuzBackend::albumLoaded, this, &MainWindow::onAlbumLoaded);
|
||||||
connect(m_backend, &QobuzBackend::artistLoaded, this, &MainWindow::onArtistLoaded);
|
connect(m_backend, &QobuzBackend::artistLoaded, this, &MainWindow::onArtistLoaded);
|
||||||
|
connect(m_backend, &QobuzBackend::artistReleasesLoaded,
|
||||||
|
m_content, &MainContent::updateArtistReleases);
|
||||||
|
connect(m_backend, &QobuzBackend::deepShuffleTracksLoaded,
|
||||||
|
m_content, &MainContent::onDeepShuffleTracks);
|
||||||
connect(m_backend, &QobuzBackend::playlistLoaded, this, &MainWindow::onPlaylistLoaded);
|
connect(m_backend, &QobuzBackend::playlistLoaded, this, &MainWindow::onPlaylistLoaded);
|
||||||
connect(m_backend, &QobuzBackend::playlistCreated, this, &MainWindow::onPlaylistCreated);
|
connect(m_backend, &QobuzBackend::playlistCreated, this, &MainWindow::onPlaylistCreated);
|
||||||
connect(m_backend, &QobuzBackend::playlistDeleted, this, [this](const QJsonObject &) {
|
connect(m_backend, &QobuzBackend::playlistDeleted, this, [this](const QJsonObject &) {
|
||||||
@@ -119,6 +124,7 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
|||||||
statusBar()->showMessage(tr("Loading favorite albums…"));
|
statusBar()->showMessage(tr("Loading favorite albums…"));
|
||||||
});
|
});
|
||||||
connect(m_library, &List::Library::favArtistsRequested, this, [this] {
|
connect(m_library, &List::Library::favArtistsRequested, this, [this] {
|
||||||
|
m_showFavArtistsOnLoad = true;
|
||||||
m_backend->getFavArtists();
|
m_backend->getFavArtists();
|
||||||
statusBar()->showMessage(tr("Loading favorite artists…"));
|
statusBar()->showMessage(tr("Loading favorite artists…"));
|
||||||
});
|
});
|
||||||
@@ -155,6 +161,8 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
|||||||
this, &MainWindow::onSearchAlbumSelected);
|
this, &MainWindow::onSearchAlbumSelected);
|
||||||
connect(m_content, &MainContent::artistRequested,
|
connect(m_content, &MainContent::artistRequested,
|
||||||
this, &MainWindow::onSearchArtistSelected);
|
this, &MainWindow::onSearchArtistSelected);
|
||||||
|
connect(m_content, &MainContent::playTrackRequested,
|
||||||
|
this, &MainWindow::onPlayTrackRequested);
|
||||||
|
|
||||||
// ---- Queue panel ----
|
// ---- Queue panel ----
|
||||||
connect(m_queuePanel, &QueuePanel::skipToTrackRequested,
|
connect(m_queuePanel, &QueuePanel::skipToTrackRequested,
|
||||||
@@ -165,6 +173,9 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
|||||||
connect(m_toolBar, &MainToolBar::queueToggled,
|
connect(m_toolBar, &MainToolBar::queueToggled,
|
||||||
this, [this](bool v) { m_queuePanel->setVisible(v); });
|
this, [this](bool v) { m_queuePanel->setVisible(v); });
|
||||||
|
|
||||||
|
connect(m_toolBar, &MainToolBar::albumRequested, this, &MainWindow::onSearchAlbumSelected);
|
||||||
|
connect(m_toolBar, &MainToolBar::artistRequested, this, &MainWindow::onSearchArtistSelected);
|
||||||
|
|
||||||
// Apply playback options from saved settings
|
// Apply playback options from saved settings
|
||||||
m_backend->setReplayGain(AppSettings::instance().replayGainEnabled());
|
m_backend->setReplayGain(AppSettings::instance().replayGainEnabled());
|
||||||
m_backend->setGapless(AppSettings::instance().gaplessEnabled());
|
m_backend->setGapless(AppSettings::instance().gaplessEnabled());
|
||||||
@@ -210,6 +221,8 @@ void MainWindow::tryRestoreSession()
|
|||||||
m_backend->getUser(); // userLoaded will call m_library->refresh()
|
m_backend->getUser(); // userLoaded will call m_library->refresh()
|
||||||
else
|
else
|
||||||
m_library->refresh();
|
m_library->refresh();
|
||||||
|
// Preload fav artists so the artist page fav button works immediately
|
||||||
|
m_backend->getFavArtists();
|
||||||
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(
|
||||||
name.isEmpty() ? AppSettings::instance().userEmail() : name));
|
name.isEmpty() ? AppSettings::instance().userEmail() : name));
|
||||||
@@ -316,9 +329,22 @@ void MainWindow::onFavAlbumsLoaded(const QJsonObject &result)
|
|||||||
|
|
||||||
void MainWindow::onFavArtistsLoaded(const QJsonObject &result)
|
void MainWindow::onFavArtistsLoaded(const QJsonObject &result)
|
||||||
{
|
{
|
||||||
|
// Always cache fav artist IDs (needed by the artist page fav button)
|
||||||
|
m_favArtistIds.clear();
|
||||||
|
const QJsonArray items = result["items"].toArray();
|
||||||
|
for (const QJsonValue &v : items) {
|
||||||
|
const qint64 id = static_cast<qint64>(v.toObject()["id"].toDouble());
|
||||||
|
if (id > 0) m_favArtistIds.insert(id);
|
||||||
|
}
|
||||||
|
m_content->setFavArtistIds(m_favArtistIds);
|
||||||
|
|
||||||
|
// Only navigate to the fav artists page if the user explicitly requested it
|
||||||
|
if (m_showFavArtistsOnLoad) {
|
||||||
|
m_showFavArtistsOnLoad = false;
|
||||||
m_content->showFavArtists(result);
|
m_content->showFavArtists(result);
|
||||||
statusBar()->showMessage(
|
statusBar()->showMessage(
|
||||||
tr("%1 favorite artists").arg(result["total"].toInt()), 4000);
|
tr("%1 favorite artists").arg(result["total"].toInt()), 4000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onAlbumLoaded(const QJsonObject &album)
|
void MainWindow::onAlbumLoaded(const QJsonObject &album)
|
||||||
@@ -331,8 +357,14 @@ void MainWindow::onAlbumLoaded(const QJsonObject &album)
|
|||||||
void MainWindow::onArtistLoaded(const QJsonObject &artist)
|
void MainWindow::onArtistLoaded(const QJsonObject &artist)
|
||||||
{
|
{
|
||||||
m_content->showArtist(artist);
|
m_content->showArtist(artist);
|
||||||
|
// Fire release requests only after the artist page is shown — avoids the
|
||||||
|
// race where a fast-responding release request arrives before setArtist()
|
||||||
|
// clears the sections, causing setArtist() to wipe out the data.
|
||||||
|
const qint64 artistId = static_cast<qint64>(artist["id"].toDouble());
|
||||||
|
for (const char *type : {"album", "epSingle", "live", "compilation"})
|
||||||
|
m_backend->getArtistReleases(artistId, QString::fromLatin1(type));
|
||||||
statusBar()->showMessage(
|
statusBar()->showMessage(
|
||||||
tr("Artist: %1").arg(artist["name"].toString()), 4000);
|
tr("Artist: %1").arg(artist["name"].toObject()["display"].toString()), 4000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onPlaylistLoaded(const QJsonObject &playlist)
|
void MainWindow::onPlaylistLoaded(const QJsonObject &playlist)
|
||||||
@@ -379,3 +411,4 @@ void MainWindow::onUserPlaylistsChanged(const QVector<QPair<qint64, QString>> &p
|
|||||||
m_userPlaylists = playlists;
|
m_userPlaylists = playlists;
|
||||||
m_content->tracksList()->setUserPlaylists(playlists);
|
m_content->tracksList()->setUserPlaylists(playlists);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ private:
|
|||||||
QobuzBackend *m_backend = nullptr;
|
QobuzBackend *m_backend = nullptr;
|
||||||
PlayQueue *m_queue = nullptr;
|
PlayQueue *m_queue = nullptr;
|
||||||
QVector<QPair<qint64, QString>> m_userPlaylists;
|
QVector<QPair<qint64, QString>> m_userPlaylists;
|
||||||
|
QSet<qint64> m_favArtistIds;
|
||||||
|
bool m_showFavArtistsOnLoad = false;
|
||||||
MainToolBar *m_toolBar = nullptr;
|
MainToolBar *m_toolBar = nullptr;
|
||||||
MainContent *m_content = nullptr;
|
MainContent *m_content = nullptr;
|
||||||
List::Library *m_library = nullptr;
|
List::Library *m_library = nullptr;
|
||||||
|
|||||||
@@ -51,8 +51,16 @@ void TrackListModel::setTracks(const QJsonArray &tracks,
|
|||||||
|
|
||||||
const QJsonObject performer = t["performer"].toObject();
|
const QJsonObject performer = t["performer"].toObject();
|
||||||
item.artist = performer["name"].toString();
|
item.artist = performer["name"].toString();
|
||||||
if (item.artist.isEmpty())
|
if (item.artist.isEmpty()) {
|
||||||
item.artist = t["album"].toObject()["artist"].toObject()["name"].toString();
|
// album.artist.name may be a plain string or {display:"..."} object
|
||||||
|
const QJsonValue n = t["album"].toObject()["artist"].toObject()["name"];
|
||||||
|
item.artist = n.isObject() ? n.toObject()["display"].toString() : n.toString();
|
||||||
|
}
|
||||||
|
if (item.artist.isEmpty()) {
|
||||||
|
// top_tracks format: artist.name.display
|
||||||
|
const QJsonValue n = t["artist"].toObject()["name"];
|
||||||
|
item.artist = n.isObject() ? n.toObject()["display"].toString() : n.toString();
|
||||||
|
}
|
||||||
|
|
||||||
const QJsonObject album = t["album"].toObject();
|
const QJsonObject album = t["album"].toObject();
|
||||||
item.album = album["title"].toString();
|
item.album = album["title"].toString();
|
||||||
|
|||||||
@@ -41,6 +41,25 @@ public:
|
|||||||
void setAlbums(const QJsonArray &albums)
|
void setAlbums(const QJsonArray &albums)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
addAlbums(albums);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Configure for artist page: hide Artist column, set fixed column widths
|
||||||
|
/// that match the Popular Tracks list for perfect vertical alignment.
|
||||||
|
void setArtistPageMode()
|
||||||
|
{
|
||||||
|
setColumnHidden(2, true); // Artist — redundant on artist page
|
||||||
|
header()->setSectionResizeMode(0, QHeaderView::Fixed);
|
||||||
|
header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
||||||
|
header()->setSectionResizeMode(3, QHeaderView::Fixed);
|
||||||
|
header()->setSectionResizeMode(4, QHeaderView::Fixed);
|
||||||
|
header()->resizeSection(0, 40);
|
||||||
|
header()->resizeSection(3, 120);
|
||||||
|
header()->resizeSection(4, 70);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addAlbums(const QJsonArray &albums)
|
||||||
|
{
|
||||||
QFont hiResFont;
|
QFont hiResFont;
|
||||||
hiResFont.setBold(true);
|
hiResFont.setBold(true);
|
||||||
hiResFont.setPointSizeF(hiResFont.pointSizeF() * 0.85);
|
hiResFont.setPointSizeF(hiResFont.pointSizeF() * 0.85);
|
||||||
@@ -52,20 +71,17 @@ public:
|
|||||||
const QString ver = a["version"].toString().trimmed();
|
const QString ver = a["version"].toString().trimmed();
|
||||||
const QString title = ver.isEmpty() ? base : base + QStringLiteral(" (") + ver + QLatin1Char(')');
|
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 QJsonValue artistNameVal = a["artist"].toObject()["name"];
|
||||||
const QString artist = artistNameVal.isObject()
|
const QString artist = artistNameVal.isObject()
|
||||||
? artistNameVal.toObject()["display"].toString()
|
? artistNameVal.toObject()["display"].toString()
|
||||||
: artistNameVal.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.isEmpty()
|
const QString year = date.isEmpty()
|
||||||
? a["dates"].toObject()["original"].toString().left(4)
|
? a["dates"].toObject()["original"].toString().left(4)
|
||||||
: date.left(4);
|
: date.left(4);
|
||||||
|
|
||||||
const int tracks = a["tracks_count"].toInt();
|
const int tracks = a["tracks_count"].toInt();
|
||||||
// hires: flat field (old) or rights.hires_streamable (artist/page)
|
|
||||||
const bool hiRes = a["hires_streamable"].toBool()
|
const bool hiRes = a["hires_streamable"].toBool()
|
||||||
|| a["rights"].toObject()["hires_streamable"].toBool();
|
|| a["rights"].toObject()["hires_streamable"].toBool();
|
||||||
|
|
||||||
|
|||||||
@@ -1,49 +1,69 @@
|
|||||||
#include "artistview.hpp"
|
#include "artistview.hpp"
|
||||||
#include "albumlistview.hpp"
|
#include "albumlistview.hpp"
|
||||||
|
#include "../model/tracklistmodel.hpp"
|
||||||
|
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
#include <QHeaderView>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QUrl>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QJsonValue>
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
|
||||||
|
// Shared button style (mirrors TrackContextHeader)
|
||||||
|
static const QString kBtnBase = QStringLiteral(
|
||||||
|
"QPushButton { padding: 5px 16px; border-radius: 4px; font-weight: bold; }"
|
||||||
|
);
|
||||||
|
|
||||||
|
// Section-toggle style: flat QPushButton, truly left-aligned
|
||||||
|
static const QString kToggleStyle = QStringLiteral(
|
||||||
|
"QPushButton { text-align: left; font-weight: bold; font-size: 13px;"
|
||||||
|
" padding: 6px 8px; border: none; border-bottom: 1px solid #333;"
|
||||||
|
" background: transparent; }"
|
||||||
|
"QPushButton:hover { background: #1e1e1e; }"
|
||||||
|
);
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// ArtistSection
|
// ArtistSection
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
ArtistSection::ArtistSection(const QString &title, QWidget *parent)
|
ArtistSection::ArtistSection(const QString &title, const QString &releaseType, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
, m_baseTitle(title)
|
, m_baseTitle(title)
|
||||||
|
, m_releaseType(releaseType)
|
||||||
{
|
{
|
||||||
auto *layout = new QVBoxLayout(this);
|
auto *layout = new QVBoxLayout(this);
|
||||||
layout->setContentsMargins(0, 0, 0, 0);
|
layout->setContentsMargins(0, 0, 0, 0);
|
||||||
layout->setSpacing(0);
|
layout->setSpacing(0);
|
||||||
|
|
||||||
m_toggle = new QToolButton(this);
|
m_toggle = new QPushButton(this);
|
||||||
m_toggle->setCheckable(true);
|
m_toggle->setCheckable(true);
|
||||||
m_toggle->setChecked(true);
|
m_toggle->setChecked(true);
|
||||||
m_toggle->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
m_toggle->setFlat(true);
|
||||||
m_toggle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
m_toggle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
m_toggle->setStyleSheet(QStringLiteral(
|
m_toggle->setStyleSheet(kToggleStyle);
|
||||||
"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);
|
layout->addWidget(m_toggle);
|
||||||
|
|
||||||
m_list = new AlbumListView(this);
|
m_list = new AlbumListView(this);
|
||||||
layout->addWidget(m_list);
|
layout->addWidget(m_list);
|
||||||
|
|
||||||
connect(m_toggle, &QToolButton::toggled, m_list, &AlbumListView::setVisible);
|
connect(m_toggle, &QPushButton::toggled, this, [this](bool checked) {
|
||||||
|
m_list->setVisible(checked);
|
||||||
|
updateToggleText();
|
||||||
|
});
|
||||||
connect(m_list, &AlbumListView::albumSelected, this, &ArtistSection::albumSelected);
|
connect(m_list, &AlbumListView::albumSelected, this, &ArtistSection::albumSelected);
|
||||||
|
|
||||||
|
updateToggleText();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArtistSection::setAlbums(const QJsonArray &albums)
|
void ArtistSection::setAlbums(const QJsonArray &albums)
|
||||||
{
|
{
|
||||||
m_list->setAlbums(albums);
|
m_list->setAlbums(albums);
|
||||||
updateToggleText(albums.size());
|
updateToggleText();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArtistSection::isEmpty() const
|
bool ArtistSection::isEmpty() const
|
||||||
@@ -51,51 +71,120 @@ bool ArtistSection::isEmpty() const
|
|||||||
return m_list->topLevelItemCount() == 0;
|
return m_list->topLevelItemCount() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ArtistSection::updateToggleText(int count)
|
QStringList ArtistSection::albumIds() const
|
||||||
{
|
{
|
||||||
|
QStringList ids;
|
||||||
|
for (int i = 0; i < m_list->topLevelItemCount(); ++i) {
|
||||||
|
const QString id = m_list->topLevelItem(i)->data(1, Qt::UserRole).toString();
|
||||||
|
if (!id.isEmpty())
|
||||||
|
ids.append(id);
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArtistSection::setArtistPageMode()
|
||||||
|
{
|
||||||
|
m_list->setArtistPageMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArtistSection::updateToggleText()
|
||||||
|
{
|
||||||
|
const int count = m_list->topLevelItemCount();
|
||||||
const QString arrow = m_toggle->isChecked() ? QStringLiteral("▼ ") : QStringLiteral("▶ ");
|
const QString arrow = m_toggle->isChecked() ? QStringLiteral("▼ ") : QStringLiteral("▶ ");
|
||||||
const QString text = count > 0
|
const QString text = count > 0
|
||||||
? QStringLiteral("%1%2 (%3)").arg(arrow, m_baseTitle).arg(count)
|
? QStringLiteral("%1%2 (%3)").arg(arrow, m_baseTitle).arg(count)
|
||||||
: arrow + m_baseTitle;
|
: arrow + m_baseTitle;
|
||||||
m_toggle->setText(text);
|
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::ArtistView(QWidget *parent)
|
ArtistView::ArtistView(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
, m_backend(backend)
|
||||||
|
, m_queue(queue)
|
||||||
{
|
{
|
||||||
auto *outerLayout = new QVBoxLayout(this);
|
auto *outerLayout = new QVBoxLayout(this);
|
||||||
outerLayout->setContentsMargins(8, 8, 8, 8);
|
outerLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
outerLayout->setSpacing(6);
|
outerLayout->setSpacing(0);
|
||||||
|
|
||||||
m_nameLabel = new QLabel(this);
|
// --- Artist header (same structure as TrackContextHeader) ---
|
||||||
|
auto *header = new QWidget(this);
|
||||||
|
header->setFixedHeight(148);
|
||||||
|
auto *hlay = new QHBoxLayout(header);
|
||||||
|
hlay->setContentsMargins(12, 8, 12, 8);
|
||||||
|
hlay->setSpacing(14);
|
||||||
|
|
||||||
|
m_artLabel = new QLabel(header);
|
||||||
|
m_artLabel->setFixedSize(120, 120);
|
||||||
|
m_artLabel->setScaledContents(true);
|
||||||
|
m_artLabel->setAlignment(Qt::AlignCenter);
|
||||||
|
m_artLabel->setStyleSheet(QStringLiteral("background: #1a1a1a; border-radius: 4px;"));
|
||||||
|
hlay->addWidget(m_artLabel, 0, Qt::AlignVCenter);
|
||||||
|
|
||||||
|
auto *info = new QWidget(header);
|
||||||
|
auto *vlay = new QVBoxLayout(info);
|
||||||
|
vlay->setContentsMargins(0, 0, 0, 0);
|
||||||
|
vlay->setSpacing(4);
|
||||||
|
|
||||||
|
m_nameLabel = new QLabel(info);
|
||||||
QFont f = m_nameLabel->font();
|
QFont f = m_nameLabel->font();
|
||||||
f.setPointSize(f.pointSize() + 4);
|
f.setPointSize(f.pointSize() + 5);
|
||||||
f.setBold(true);
|
f.setBold(true);
|
||||||
m_nameLabel->setFont(f);
|
m_nameLabel->setFont(f);
|
||||||
outerLayout->addWidget(m_nameLabel);
|
vlay->addWidget(m_nameLabel);
|
||||||
|
|
||||||
m_bioLabel = new QLabel(this);
|
m_bioEdit = new QTextEdit(info);
|
||||||
m_bioLabel->setWordWrap(true);
|
m_bioEdit->setReadOnly(true);
|
||||||
m_bioLabel->setAlignment(Qt::AlignTop | Qt::AlignLeft);
|
m_bioEdit->setFrameShape(QFrame::NoFrame);
|
||||||
m_bioLabel->setMaximumHeight(80);
|
m_bioEdit->setMaximumHeight(56);
|
||||||
outerLayout->addWidget(m_bioLabel);
|
m_bioEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||||
|
m_bioEdit->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
vlay->addWidget(m_bioEdit);
|
||||||
|
|
||||||
// Scrollable sections area
|
auto *btnRow = new QHBoxLayout;
|
||||||
|
btnRow->setSpacing(8);
|
||||||
|
btnRow->setContentsMargins(0, 4, 0, 0);
|
||||||
|
|
||||||
|
m_playBtn = new QPushButton(tr("▶ Play"), info);
|
||||||
|
m_playBtn->setStyleSheet(kBtnBase +
|
||||||
|
QStringLiteral("QPushButton { background: #FFB232; color: #000; }"
|
||||||
|
"QPushButton:pressed { background: #e09e28; }"));
|
||||||
|
|
||||||
|
m_shuffleBtn = new QPushButton(tr("⇄ Shuffle All"), info);
|
||||||
|
m_shuffleBtn->setStyleSheet(kBtnBase +
|
||||||
|
QStringLiteral("QPushButton { background: #2a2a2a; color: #FFB232; border: 1px solid #FFB232; }"
|
||||||
|
"QPushButton:pressed { background: #333; }"));
|
||||||
|
|
||||||
|
m_favBtn = new QPushButton(tr("♡ Favourite"), info);
|
||||||
|
m_favBtn->setStyleSheet(kBtnBase +
|
||||||
|
QStringLiteral("QPushButton { background: #2a2a2a; color: #ccc; border: 1px solid #555; }"
|
||||||
|
"QPushButton:pressed { background: #333; }"));
|
||||||
|
|
||||||
|
btnRow->addWidget(m_playBtn);
|
||||||
|
btnRow->addWidget(m_shuffleBtn);
|
||||||
|
btnRow->addWidget(m_favBtn);
|
||||||
|
btnRow->addStretch();
|
||||||
|
vlay->addLayout(btnRow);
|
||||||
|
vlay->addStretch(1);
|
||||||
|
|
||||||
|
hlay->addWidget(info, 1);
|
||||||
|
outerLayout->addWidget(header);
|
||||||
|
|
||||||
|
// --- Network manager for portrait ---
|
||||||
|
m_nam = new QNetworkAccessManager(this);
|
||||||
|
QObject::connect(m_nam, &QNetworkAccessManager::finished,
|
||||||
|
this, [this](QNetworkReply *reply) {
|
||||||
|
reply->deleteLater();
|
||||||
|
if (reply->error() != QNetworkReply::NoError) return;
|
||||||
|
QPixmap pix;
|
||||||
|
if (pix.loadFromData(reply->readAll()))
|
||||||
|
m_artLabel->setPixmap(pix);
|
||||||
|
});
|
||||||
|
|
||||||
|
// --- Scrollable sections area ---
|
||||||
auto *scroll = new QScrollArea(this);
|
auto *scroll = new QScrollArea(this);
|
||||||
scroll->setWidgetResizable(true);
|
scroll->setWidgetResizable(true);
|
||||||
scroll->setFrameShape(QFrame::NoFrame);
|
scroll->setFrameShape(QFrame::NoFrame);
|
||||||
@@ -103,13 +192,49 @@ ArtistView::ArtistView(QWidget *parent)
|
|||||||
auto *content = new QWidget(scroll);
|
auto *content = new QWidget(scroll);
|
||||||
auto *sectLayout = new QVBoxLayout(content);
|
auto *sectLayout = new QVBoxLayout(content);
|
||||||
sectLayout->setContentsMargins(0, 0, 0, 0);
|
sectLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
sectLayout->setSpacing(8);
|
sectLayout->setSpacing(0);
|
||||||
|
|
||||||
m_secAlbums = new ArtistSection(tr("Albums"), content);
|
// Popular Tracks section — same toggle style as release sections
|
||||||
m_secEps = new ArtistSection(tr("Singles & EPs"), content);
|
m_topTracksSection = new QWidget(content);
|
||||||
m_secLive = new ArtistSection(tr("Live"), content);
|
auto *ttLayout = new QVBoxLayout(m_topTracksSection);
|
||||||
m_secCompilations = new ArtistSection(tr("Compilations"), content);
|
ttLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
m_secOther = new ArtistSection(tr("Other"), content);
|
ttLayout->setSpacing(0);
|
||||||
|
|
||||||
|
m_topTracksToggle = new QPushButton(m_topTracksSection);
|
||||||
|
m_topTracksToggle->setCheckable(true);
|
||||||
|
m_topTracksToggle->setChecked(true);
|
||||||
|
m_topTracksToggle->setFlat(true);
|
||||||
|
m_topTracksToggle->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||||
|
m_topTracksToggle->setStyleSheet(kToggleStyle);
|
||||||
|
ttLayout->addWidget(m_topTracksToggle);
|
||||||
|
|
||||||
|
m_topTracks = new List::Tracks(backend, queue, m_topTracksSection);
|
||||||
|
m_topTracks->setMaximumHeight(320);
|
||||||
|
// Artist page column layout: hide Artist & Album, match album-section widths
|
||||||
|
m_topTracks->setColumnHidden(TrackListModel::ColArtist, true);
|
||||||
|
m_topTracks->setColumnHidden(TrackListModel::ColAlbum, true);
|
||||||
|
m_topTracks->header()->setSectionResizeMode(TrackListModel::ColNumber, QHeaderView::Fixed);
|
||||||
|
m_topTracks->header()->setSectionResizeMode(TrackListModel::ColTitle, QHeaderView::Stretch);
|
||||||
|
m_topTracks->header()->setSectionResizeMode(TrackListModel::ColDuration, QHeaderView::Fixed);
|
||||||
|
m_topTracks->header()->resizeSection(TrackListModel::ColNumber, 40);
|
||||||
|
m_topTracks->header()->resizeSection(TrackListModel::ColDuration, 70);
|
||||||
|
ttLayout->addWidget(m_topTracks);
|
||||||
|
|
||||||
|
connect(m_topTracksToggle, &QPushButton::toggled, m_topTracks, &QWidget::setVisible);
|
||||||
|
connect(m_topTracks, &List::Tracks::playTrackRequested, this, &ArtistView::playTrackRequested);
|
||||||
|
|
||||||
|
sectLayout->addWidget(m_topTracksSection);
|
||||||
|
|
||||||
|
// Release sections
|
||||||
|
m_secAlbums = new ArtistSection(tr("Albums"), QStringLiteral("album"), content);
|
||||||
|
m_secEps = new ArtistSection(tr("Singles & EPs"), QStringLiteral("epSingle"), content);
|
||||||
|
m_secLive = new ArtistSection(tr("Live"), QStringLiteral("live"), content);
|
||||||
|
m_secCompilations = new ArtistSection(tr("Compilations"), QStringLiteral("compilation"), content);
|
||||||
|
m_secOther = new ArtistSection(tr("Other"), QStringLiteral("other"), content);
|
||||||
|
|
||||||
|
// Uniform column layout: hide Artist column, match fixed widths across all sections
|
||||||
|
for (ArtistSection *sec : {m_secAlbums, m_secEps, m_secLive, m_secCompilations, m_secOther})
|
||||||
|
sec->setArtistPageMode();
|
||||||
|
|
||||||
sectLayout->addWidget(m_secAlbums);
|
sectLayout->addWidget(m_secAlbums);
|
||||||
sectLayout->addWidget(m_secEps);
|
sectLayout->addWidget(m_secEps);
|
||||||
@@ -121,6 +246,37 @@ ArtistView::ArtistView(QWidget *parent)
|
|||||||
scroll->setWidget(content);
|
scroll->setWidget(content);
|
||||||
outerLayout->addWidget(scroll, 1);
|
outerLayout->addWidget(scroll, 1);
|
||||||
|
|
||||||
|
// Play top tracks
|
||||||
|
connect(m_playBtn, &QPushButton::clicked, m_topTracks, [this] { m_topTracks->playAll(false); });
|
||||||
|
|
||||||
|
// Deep shuffle: fetch all album tracks, combine, shuffle, play
|
||||||
|
connect(m_shuffleBtn, &QPushButton::clicked, this, [this] {
|
||||||
|
const QStringList ids = allAlbumIds();
|
||||||
|
if (ids.isEmpty()) {
|
||||||
|
// Fallback: just shuffle popular tracks
|
||||||
|
m_topTracks->playAll(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_shuffleBtn->setEnabled(false);
|
||||||
|
m_shuffleBtn->setText(tr("Loading…"));
|
||||||
|
m_backend->getAlbumsTracks(ids);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Favourite button
|
||||||
|
connect(m_favBtn, &QPushButton::clicked, this, [this] {
|
||||||
|
if (m_artistId <= 0) return;
|
||||||
|
m_isFaved = !m_isFaved;
|
||||||
|
if (m_isFaved) {
|
||||||
|
m_backend->addFavArtist(m_artistId);
|
||||||
|
m_favArtistIds.insert(m_artistId);
|
||||||
|
} else {
|
||||||
|
m_backend->removeFavArtist(m_artistId);
|
||||||
|
m_favArtistIds.remove(m_artistId);
|
||||||
|
}
|
||||||
|
setFaved(m_isFaved);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Album section connections
|
||||||
connect(m_secAlbums, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
connect(m_secAlbums, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
||||||
connect(m_secEps, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
connect(m_secEps, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
||||||
connect(m_secLive, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
connect(m_secLive, &ArtistSection::albumSelected, this, &ArtistView::albumSelected);
|
||||||
@@ -130,14 +286,15 @@ ArtistView::ArtistView(QWidget *parent)
|
|||||||
|
|
||||||
void ArtistView::setArtist(const QJsonObject &artist)
|
void ArtistView::setArtist(const QJsonObject &artist)
|
||||||
{
|
{
|
||||||
// artist/page: name is {"display": "..."}
|
m_artistId = static_cast<qint64>(artist["id"].toDouble());
|
||||||
|
setFaved(m_favArtistIds.contains(m_artistId));
|
||||||
|
|
||||||
m_nameLabel->setText(artist["name"].toObject()["display"].toString());
|
m_nameLabel->setText(artist["name"].toObject()["display"].toString());
|
||||||
|
|
||||||
// biography.content is HTML — strip tags for safe plain-text display
|
// Biography: strip HTML tags
|
||||||
const QString bioHtml = artist["biography"].toObject()["content"].toString();
|
const QString bioHtml = artist["biography"].toObject()["content"].toString();
|
||||||
if (!bioHtml.isEmpty()) {
|
if (!bioHtml.isEmpty()) {
|
||||||
QString plain = bioHtml;
|
QString plain = bioHtml;
|
||||||
// Strip HTML entities and tags to prevent rendering injected content
|
|
||||||
plain.remove(QRegularExpression(QStringLiteral("<[^>]*>")));
|
plain.remove(QRegularExpression(QStringLiteral("<[^>]*>")));
|
||||||
plain.replace(QStringLiteral("&"), QStringLiteral("&"));
|
plain.replace(QStringLiteral("&"), QStringLiteral("&"));
|
||||||
plain.replace(QStringLiteral("<"), QStringLiteral("<"));
|
plain.replace(QStringLiteral("<"), QStringLiteral("<"));
|
||||||
@@ -146,40 +303,122 @@ void ArtistView::setArtist(const QJsonObject &artist)
|
|||||||
plain.replace(QStringLiteral("'"), QStringLiteral("'"));
|
plain.replace(QStringLiteral("'"), QStringLiteral("'"));
|
||||||
plain.replace(QStringLiteral(" "), QStringLiteral(" "));
|
plain.replace(QStringLiteral(" "), QStringLiteral(" "));
|
||||||
plain = plain.trimmed();
|
plain = plain.trimmed();
|
||||||
m_bioLabel->setTextFormat(Qt::PlainText);
|
m_bioEdit->setPlainText(plain);
|
||||||
m_bioLabel->setText(plain);
|
m_bioEdit->setVisible(!plain.isEmpty());
|
||||||
m_bioLabel->setVisible(!plain.isEmpty());
|
|
||||||
} else {
|
} else {
|
||||||
m_bioLabel->setVisible(false);
|
m_bioEdit->setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// releases is an array of {type, has_more, items[]}
|
// Artist portrait: images.portrait.hash + format → CDN URL
|
||||||
// types we care about: "album", "epSingle", "live"
|
const QJsonObject portrait = artist["images"].toObject()["portrait"].toObject();
|
||||||
const QJsonArray releases = artist["releases"].toArray();
|
const QString hash = portrait["hash"].toString();
|
||||||
QJsonArray albums, eps, live, compilations;
|
const QString format = portrait["format"].toString();
|
||||||
for (const QJsonValue &rv : releases) {
|
QString artUrl;
|
||||||
const QJsonObject rg = rv.toObject();
|
if (!hash.isEmpty()) {
|
||||||
const QString type = rg["type"].toString();
|
artUrl = QStringLiteral("https://static.qobuz.com/images/artists/covers/large/%1.%2")
|
||||||
const QJsonArray items = rg["items"].toArray();
|
.arg(hash, format.isEmpty() ? QStringLiteral("jpg") : format);
|
||||||
if (type == QStringLiteral("album"))
|
} else {
|
||||||
albums = items;
|
const QJsonObject img = artist["image"].toObject();
|
||||||
else if (type == QStringLiteral("epSingle"))
|
artUrl = img["large"].toString();
|
||||||
eps = items;
|
if (artUrl.isEmpty()) artUrl = img["small"].toString();
|
||||||
else if (type == QStringLiteral("live"))
|
}
|
||||||
live = items;
|
if (!artUrl.isEmpty() && artUrl != m_currentArtUrl) {
|
||||||
else if (type == QStringLiteral("compilation"))
|
m_currentArtUrl = artUrl;
|
||||||
compilations = items;
|
m_nam->get(QNetworkRequest(QUrl(artUrl)));
|
||||||
|
} else if (artUrl.isEmpty()) {
|
||||||
|
m_artLabel->setPixmap(QPixmap());
|
||||||
|
m_currentArtUrl.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_secAlbums->setAlbums(albums);
|
// Popular tracks (flat array)
|
||||||
m_secEps->setAlbums(eps);
|
const QJsonArray topTracks = artist["top_tracks"].toArray();
|
||||||
m_secLive->setAlbums(live);
|
m_topTracks->loadTracks(topTracks);
|
||||||
m_secCompilations->setAlbums(compilations);
|
|
||||||
m_secOther->setAlbums({});
|
|
||||||
|
|
||||||
m_secAlbums->setVisible(!m_secAlbums->isEmpty());
|
const int ttCount = topTracks.size();
|
||||||
m_secEps->setVisible(!m_secEps->isEmpty());
|
disconnect(m_topTracksToggle, &QPushButton::toggled, nullptr, nullptr);
|
||||||
m_secLive->setVisible(!m_secLive->isEmpty());
|
connect(m_topTracksToggle, &QPushButton::toggled, m_topTracks, &QWidget::setVisible);
|
||||||
m_secCompilations->setVisible(!m_secCompilations->isEmpty());
|
connect(m_topTracksToggle, &QPushButton::toggled, this, [this, ttCount](bool open) {
|
||||||
m_secOther->setVisible(false);
|
const QString a = open ? QStringLiteral("▼ ") : QStringLiteral("▶ ");
|
||||||
|
m_topTracksToggle->setText(ttCount > 0
|
||||||
|
? QStringLiteral("%1Popular Tracks (%2)").arg(a).arg(ttCount)
|
||||||
|
: a + tr("Popular Tracks"));
|
||||||
|
});
|
||||||
|
m_topTracksToggle->setChecked(true);
|
||||||
|
m_topTracks->setVisible(true);
|
||||||
|
m_topTracksToggle->setText(ttCount > 0
|
||||||
|
? QStringLiteral("▼ Popular Tracks (%1)").arg(ttCount)
|
||||||
|
: QStringLiteral("▼ Popular Tracks"));
|
||||||
|
m_topTracksSection->setVisible(!topTracks.isEmpty());
|
||||||
|
|
||||||
|
// Reset shuffle button state
|
||||||
|
m_shuffleBtn->setEnabled(true);
|
||||||
|
m_shuffleBtn->setText(tr("⇄ Shuffle All"));
|
||||||
|
|
||||||
|
// Clear release sections
|
||||||
|
for (ArtistSection *sec : {m_secAlbums, m_secEps, m_secLive, m_secCompilations, m_secOther}) {
|
||||||
|
sec->setAlbums({});
|
||||||
|
sec->setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArtistView::setReleases(const QString &releaseType, const QJsonArray &items,
|
||||||
|
bool /*hasMore*/, int /*offset*/)
|
||||||
|
{
|
||||||
|
ArtistSection *sec = nullptr;
|
||||||
|
if (releaseType == QStringLiteral("album")) sec = m_secAlbums;
|
||||||
|
else if (releaseType == QStringLiteral("epSingle")) sec = m_secEps;
|
||||||
|
else if (releaseType == QStringLiteral("live")) sec = m_secLive;
|
||||||
|
else if (releaseType == QStringLiteral("compilation")) sec = m_secCompilations;
|
||||||
|
else sec = m_secOther;
|
||||||
|
|
||||||
|
// Rust auto-paginates, so we always get the full list at once
|
||||||
|
sec->setAlbums(items);
|
||||||
|
sec->setVisible(!sec->isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArtistView::setFavArtistIds(const QSet<qint64> &ids)
|
||||||
|
{
|
||||||
|
m_favArtistIds = ids;
|
||||||
|
if (m_artistId > 0)
|
||||||
|
setFaved(ids.contains(m_artistId));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArtistView::onDeepShuffleTracks(const QJsonArray &tracks)
|
||||||
|
{
|
||||||
|
m_shuffleBtn->setEnabled(true);
|
||||||
|
m_shuffleBtn->setText(tr("⇄ Shuffle All"));
|
||||||
|
|
||||||
|
if (tracks.isEmpty()) return;
|
||||||
|
|
||||||
|
m_queue->setContext(tracks, 0);
|
||||||
|
m_queue->shuffleNow();
|
||||||
|
|
||||||
|
const QJsonObject first = m_queue->current();
|
||||||
|
const qint64 id = static_cast<qint64>(first["id"].toDouble());
|
||||||
|
if (id > 0)
|
||||||
|
emit playTrackRequested(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList ArtistView::allAlbumIds() const
|
||||||
|
{
|
||||||
|
QStringList ids;
|
||||||
|
for (const ArtistSection *sec : {m_secAlbums, m_secEps, m_secLive, m_secCompilations, m_secOther})
|
||||||
|
ids.append(sec->albumIds());
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ArtistView::setFaved(bool faved)
|
||||||
|
{
|
||||||
|
m_isFaved = faved;
|
||||||
|
if (faved) {
|
||||||
|
m_favBtn->setText(tr("♥ Favourited"));
|
||||||
|
m_favBtn->setStyleSheet(kBtnBase +
|
||||||
|
QStringLiteral("QPushButton { background: #2a2a2a; color: #FFB232; border: 1px solid #FFB232; }"
|
||||||
|
"QPushButton:pressed { background: #333; }"));
|
||||||
|
} else {
|
||||||
|
m_favBtn->setText(tr("♡ Favourite"));
|
||||||
|
m_favBtn->setStyleSheet(kBtnBase +
|
||||||
|
QStringLiteral("QPushButton { background: #2a2a2a; color: #ccc; border: 1px solid #555; }"
|
||||||
|
"QPushButton:pressed { background: #333; }"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,56 +1,92 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "albumlistview.hpp"
|
#include "albumlistview.hpp"
|
||||||
|
#include "../list/tracks.hpp"
|
||||||
|
#include "../backend/qobuzbackend.hpp"
|
||||||
|
#include "../playqueue.hpp"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QToolButton>
|
#include <QTextEdit>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
#include <QSet>
|
||||||
|
|
||||||
class AlbumListView;
|
class AlbumListView;
|
||||||
|
|
||||||
/// One collapsible section (e.g. "Albums", "EPs & Singles") inside ArtistView.
|
/// One collapsible section (Albums / EPs / Live / etc.) inside ArtistView.
|
||||||
class ArtistSection : public QWidget
|
class ArtistSection : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ArtistSection(const QString &title, QWidget *parent = nullptr);
|
explicit ArtistSection(const QString &title, const QString &releaseType, QWidget *parent = nullptr);
|
||||||
|
|
||||||
void setAlbums(const QJsonArray &albums);
|
void setAlbums(const QJsonArray &albums);
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
|
QStringList albumIds() const;
|
||||||
|
void setArtistPageMode();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void albumSelected(const QString &albumId);
|
void albumSelected(const QString &albumId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_baseTitle;
|
QString m_baseTitle;
|
||||||
QToolButton *m_toggle = nullptr;
|
QString m_releaseType;
|
||||||
|
QPushButton *m_toggle = nullptr;
|
||||||
AlbumListView *m_list = nullptr;
|
AlbumListView *m_list = nullptr;
|
||||||
|
|
||||||
void updateToggleText(int count);
|
void updateToggleText();
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Artist detail page: name, biography, and albums split into collapsible sections
|
/// Artist detail page.
|
||||||
/// (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);
|
explicit ArtistView(QobuzBackend *backend, PlayQueue *queue, QWidget *parent = nullptr);
|
||||||
|
|
||||||
void setArtist(const QJsonObject &artist);
|
void setArtist(const QJsonObject &artist);
|
||||||
|
void setReleases(const QString &releaseType, const QJsonArray &items,
|
||||||
|
bool hasMore = false, int offset = 0);
|
||||||
|
void setFavArtistIds(const QSet<qint64> &ids);
|
||||||
|
void onDeepShuffleTracks(const QJsonArray &tracks);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void albumSelected(const QString &albumId);
|
void albumSelected(const QString &albumId);
|
||||||
|
void playTrackRequested(qint64 trackId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QobuzBackend *m_backend = nullptr;
|
||||||
|
PlayQueue *m_queue = nullptr;
|
||||||
|
qint64 m_artistId = 0;
|
||||||
|
|
||||||
|
// Header widgets
|
||||||
|
QLabel *m_artLabel = nullptr;
|
||||||
QLabel *m_nameLabel = nullptr;
|
QLabel *m_nameLabel = nullptr;
|
||||||
QLabel *m_bioLabel = nullptr;
|
QTextEdit *m_bioEdit = nullptr;
|
||||||
|
QPushButton *m_playBtn = nullptr;
|
||||||
|
QPushButton *m_shuffleBtn = nullptr;
|
||||||
|
QPushButton *m_favBtn = nullptr;
|
||||||
|
QNetworkAccessManager *m_nam = nullptr;
|
||||||
|
QString m_currentArtUrl;
|
||||||
|
bool m_isFaved = false;
|
||||||
|
QSet<qint64> m_favArtistIds;
|
||||||
|
|
||||||
|
// Popular tracks section
|
||||||
|
QWidget *m_topTracksSection = nullptr;
|
||||||
|
QPushButton *m_topTracksToggle = nullptr;
|
||||||
|
List::Tracks *m_topTracks = nullptr;
|
||||||
|
|
||||||
|
// Release sections
|
||||||
ArtistSection *m_secAlbums = nullptr;
|
ArtistSection *m_secAlbums = nullptr;
|
||||||
ArtistSection *m_secEps = nullptr;
|
ArtistSection *m_secEps = nullptr;
|
||||||
ArtistSection *m_secLive = nullptr;
|
ArtistSection *m_secLive = nullptr;
|
||||||
ArtistSection *m_secCompilations = nullptr;
|
ArtistSection *m_secCompilations = nullptr;
|
||||||
ArtistSection *m_secOther = nullptr;
|
ArtistSection *m_secOther = nullptr;
|
||||||
|
|
||||||
|
QStringList allAlbumIds() const;
|
||||||
|
void setFaved(bool faved);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ MainContent::MainContent(QobuzBackend *backend, PlayQueue *queue, QWidget *paren
|
|||||||
|
|
||||||
m_albumList = new AlbumListView(this);
|
m_albumList = new AlbumListView(this);
|
||||||
m_artistList = new ArtistListView(this);
|
m_artistList = new ArtistListView(this);
|
||||||
m_artistView = new ArtistView(this);
|
m_artistView = new ArtistView(backend, queue, this);
|
||||||
|
|
||||||
m_stack->addWidget(m_welcome); // 0
|
m_stack->addWidget(m_welcome); // 0
|
||||||
m_stack->addWidget(tracksPage); // 1
|
m_stack->addWidget(tracksPage); // 1
|
||||||
@@ -57,6 +57,7 @@ MainContent::MainContent(QobuzBackend *backend, PlayQueue *queue, QWidget *paren
|
|||||||
connect(m_albumList, &AlbumListView::albumSelected, this, &MainContent::albumRequested);
|
connect(m_albumList, &AlbumListView::albumSelected, this, &MainContent::albumRequested);
|
||||||
connect(m_artistList, &ArtistListView::artistSelected, this, &MainContent::artistRequested);
|
connect(m_artistList, &ArtistListView::artistSelected, this, &MainContent::artistRequested);
|
||||||
connect(m_artistView, &ArtistView::albumSelected, this, &MainContent::albumRequested);
|
connect(m_artistView, &ArtistView::albumSelected, this, &MainContent::albumRequested);
|
||||||
|
connect(m_artistView, &ArtistView::playTrackRequested, this, &MainContent::playTrackRequested);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainContent::showWelcome() { m_stack->setCurrentIndex(0); }
|
void MainContent::showWelcome() { m_stack->setCurrentIndex(0); }
|
||||||
@@ -106,3 +107,18 @@ void MainContent::showArtist(const QJsonObject &artist)
|
|||||||
m_artistView->setArtist(artist);
|
m_artistView->setArtist(artist);
|
||||||
m_stack->setCurrentIndex(4);
|
m_stack->setCurrentIndex(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainContent::updateArtistReleases(const QString &releaseType, const QJsonArray &items, bool hasMore, int offset)
|
||||||
|
{
|
||||||
|
m_artistView->setReleases(releaseType, items, hasMore, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainContent::setFavArtistIds(const QSet<qint64> &ids)
|
||||||
|
{
|
||||||
|
m_artistView->setFavArtistIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainContent::onDeepShuffleTracks(const QJsonArray &tracks)
|
||||||
|
{
|
||||||
|
m_artistView->onDeepShuffleTracks(tracks);
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,10 +31,16 @@ public:
|
|||||||
void showFavAlbums(const QJsonObject &result);
|
void showFavAlbums(const QJsonObject &result);
|
||||||
void showFavArtists(const QJsonObject &result);
|
void showFavArtists(const QJsonObject &result);
|
||||||
void showArtist(const QJsonObject &artist);
|
void showArtist(const QJsonObject &artist);
|
||||||
|
void updateArtistReleases(const QString &releaseType, const QJsonArray &items, bool hasMore, int offset);
|
||||||
|
void setFavArtistIds(const QSet<qint64> &ids);
|
||||||
|
void onDeepShuffleTracks(const QJsonArray &tracks);
|
||||||
|
|
||||||
|
ArtistView *artistView() const { return m_artistView; }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void albumRequested(const QString &albumId);
|
void albumRequested(const QString &albumId);
|
||||||
void artistRequested(qint64 artistId);
|
void artistRequested(qint64 artistId);
|
||||||
|
void playTrackRequested(qint64 trackId);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QobuzBackend *m_backend = nullptr;
|
QobuzBackend *m_backend = nullptr;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
MainToolBar::MainToolBar(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
MainToolBar::MainToolBar(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
||||||
: QToolBar(parent)
|
: QToolBar(parent)
|
||||||
@@ -34,6 +35,22 @@ MainToolBar::MainToolBar(QobuzBackend *backend, PlayQueue *queue, QWidget *paren
|
|||||||
m_trackLabel->setTextFormat(Qt::RichText);
|
m_trackLabel->setTextFormat(Qt::RichText);
|
||||||
addWidget(m_trackLabel);
|
addWidget(m_trackLabel);
|
||||||
|
|
||||||
|
m_trackLabel->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
connect(m_trackLabel, &QLabel::customContextMenuRequested,
|
||||||
|
this, [this](const QPoint &pos) {
|
||||||
|
if (m_currentTrack.isEmpty()) return;
|
||||||
|
QMenu menu(this);
|
||||||
|
const QString albumId = m_currentTrack["album"].toObject()["id"].toString();
|
||||||
|
const qint64 artistId = static_cast<qint64>(
|
||||||
|
m_currentTrack["performer"].toObject()["id"].toDouble());
|
||||||
|
if (!albumId.isEmpty())
|
||||||
|
menu.addAction(tr("Go to Album"), this, [this, albumId] { emit albumRequested(albumId); });
|
||||||
|
if (artistId > 0)
|
||||||
|
menu.addAction(tr("Go to Artist"), this, [this, artistId] { emit artistRequested(artistId); });
|
||||||
|
if (!menu.isEmpty())
|
||||||
|
menu.exec(m_trackLabel->mapToGlobal(pos));
|
||||||
|
});
|
||||||
|
|
||||||
addSeparator();
|
addSeparator();
|
||||||
|
|
||||||
// ---- Media controls ----
|
// ---- Media controls ----
|
||||||
@@ -125,6 +142,7 @@ void MainToolBar::setPlaying(bool playing)
|
|||||||
|
|
||||||
void MainToolBar::setCurrentTrack(const QJsonObject &track)
|
void MainToolBar::setCurrentTrack(const QJsonObject &track)
|
||||||
{
|
{
|
||||||
|
m_currentTrack = track;
|
||||||
const QString title = track["title"].toString();
|
const QString title = track["title"].toString();
|
||||||
const QString artist = track["performer"].toObject()["name"].toString().isEmpty()
|
const QString artist = track["performer"].toObject()["name"].toString().isEmpty()
|
||||||
? track["album"].toObject()["artist"].toObject()["name"].toString()
|
? track["album"].toObject()["artist"].toObject()["name"].toString()
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void searchToggled(bool visible);
|
void searchToggled(bool visible);
|
||||||
void queueToggled(bool visible);
|
void queueToggled(bool visible);
|
||||||
|
void albumRequested(const QString &albumId);
|
||||||
|
void artistRequested(qint64 artistId);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
@@ -68,6 +70,7 @@ private:
|
|||||||
|
|
||||||
QNetworkAccessManager *m_nam = nullptr;
|
QNetworkAccessManager *m_nam = nullptr;
|
||||||
QString m_currentArtUrl;
|
QString m_currentArtUrl;
|
||||||
|
QJsonObject m_currentTrack;
|
||||||
bool m_playing = false;
|
bool m_playing = false;
|
||||||
bool m_seeking = false;
|
bool m_seeking = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -119,7 +119,9 @@ public:
|
|||||||
|
|
||||||
void setAlbum(const QJsonObject &album)
|
void setAlbum(const QJsonObject &album)
|
||||||
{
|
{
|
||||||
m_title->setText(album["title"].toString());
|
const QString base = album["title"].toString();
|
||||||
|
const QString ver = album["version"].toString().trimmed();
|
||||||
|
m_title->setText(ver.isEmpty() ? base : base + QStringLiteral(" (") + ver + QLatin1Char(')'));
|
||||||
m_artistId = static_cast<qint64>(album["artist"].toObject()["id"].toDouble());
|
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->setEnabled(m_artistId > 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user