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-*/
|
||||
target/
|
||||
src/visualizer/
|
||||
.cache/
|
||||
*.user
|
||||
*.autosave
|
||||
|
||||
@@ -35,6 +35,8 @@ enum QobuzEvent {
|
||||
EV_PLAYLIST_DELETED = 21,
|
||||
EV_PLAYLIST_TRACK_ADDED = 22,
|
||||
EV_USER_OK = 23,
|
||||
EV_ARTIST_RELEASES_OK = 24,
|
||||
EV_DEEP_SHUFFLE_OK = 25,
|
||||
};
|
||||
|
||||
// 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_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
|
||||
void qobuz_backend_create_playlist(QobuzBackendOpaque *backend, const char *name);
|
||||
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_add_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
|
||||
}
|
||||
|
||||
@@ -255,20 +255,6 @@ impl QobuzClient {
|
||||
|
||||
// --- 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> {
|
||||
let resp = self
|
||||
.get_request("artist/page")
|
||||
@@ -278,6 +264,28 @@ impl QobuzClient {
|
||||
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 ---
|
||||
|
||||
pub async fn search(&self, query: &str, offset: u32, limit: u32) -> Result<SearchCatalogDto> {
|
||||
@@ -439,4 +447,24 @@ impl QobuzClient {
|
||||
Self::check_response(resp).await?;
|
||||
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_ERR: c_int = 18;
|
||||
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 ----------
|
||||
|
||||
@@ -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) {
|
||||
let inner = &(*ptr).0;
|
||||
let token = CStr::from_ptr(token).to_string_lossy().into_owned();
|
||||
let client = inner.client.clone();
|
||||
// blocking_lock is available on tokio::sync::Mutex when not in an async context
|
||||
inner.rt.spawn(async move {
|
||||
client.lock().await.set_auth_token(token);
|
||||
});
|
||||
// Use blocking_lock (called from Qt main thread, not a tokio thread) so the
|
||||
// token is set before any subsequent getUser/library requests are spawned.
|
||||
inner.client.blocking_lock().set_auth_token(token);
|
||||
}
|
||||
|
||||
// ---------- 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 ----------
|
||||
|
||||
#[no_mangle]
|
||||
@@ -410,7 +513,7 @@ pub unsafe extern "C" fn qobuz_backend_play_track(
|
||||
if let Some(dur) = track.duration {
|
||||
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
|
||||
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 ----------
|
||||
|
||||
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 ----------
|
||||
|
||||
pub const EV_PLAYLIST_CREATED: c_int = 20;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use anyhow::Result;
|
||||
use rb::RB;
|
||||
use std::io::{self, Read, Seek, SeekFrom};
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
@@ -176,8 +177,12 @@ pub fn play_track_inline(
|
||||
}
|
||||
}
|
||||
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 mut stopped = false;
|
||||
@@ -195,11 +200,6 @@ pub fn play_track_inline(
|
||||
paused.store(false, Ordering::SeqCst);
|
||||
*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)) => {
|
||||
status.volume.store(v, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
mod decoder;
|
||||
pub mod output;
|
||||
|
||||
use rb::{SpscRb, RB};
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, AtomicU64, AtomicU8, Ordering},
|
||||
atomic::{AtomicBool, AtomicU32, AtomicU64, AtomicU8, Ordering},
|
||||
Arc,
|
||||
};
|
||||
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)]
|
||||
pub enum PlayerCommand {
|
||||
@@ -15,7 +19,6 @@ pub enum PlayerCommand {
|
||||
Pause,
|
||||
Resume,
|
||||
Stop,
|
||||
Seek(u64),
|
||||
SetVolume(u8),
|
||||
}
|
||||
|
||||
@@ -23,7 +26,6 @@ pub enum PlayerCommand {
|
||||
pub struct TrackInfo {
|
||||
pub track: TrackDto,
|
||||
pub url: String,
|
||||
pub format: Format,
|
||||
/// ReplayGain track gain in dB, if enabled and available.
|
||||
pub replaygain_db: Option<f64>,
|
||||
}
|
||||
@@ -33,7 +35,6 @@ pub enum PlayerState {
|
||||
Idle,
|
||||
Playing,
|
||||
Paused,
|
||||
Stopped,
|
||||
Error(String),
|
||||
}
|
||||
|
||||
@@ -53,10 +54,17 @@ pub struct PlayerStatus {
|
||||
pub replaygain_gain: Arc<std::sync::Mutex<f32>>,
|
||||
/// When false the audio output is torn down after each track, producing a gap.
|
||||
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 {
|
||||
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 {
|
||||
state: Arc::new(std::sync::Mutex::new(PlayerState::Idle)),
|
||||
position_secs: Arc::new(AtomicU64::new(0)),
|
||||
@@ -68,6 +76,10 @@ impl PlayerStatus {
|
||||
seek_target_secs: Arc::new(AtomicU64::new(0)),
|
||||
replaygain_gain: Arc::new(std::sync::Mutex::new(1.0)),
|
||||
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)
|
||||
}
|
||||
|
||||
pub fn get_current_track(&self) -> Option<TrackDto> {
|
||||
self.current_track.lock().unwrap().clone()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Player {
|
||||
@@ -169,10 +178,6 @@ fn player_loop(rx: std::sync::mpsc::Receiver<PlayerCommand>, status: PlayerStatu
|
||||
Ok(PlayerCommand::SetVolume(v)) => {
|
||||
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
|
||||
Err(RecvTimeoutError::Timeout) => {}
|
||||
Err(RecvTimeoutError::Disconnected) => break 'outer,
|
||||
@@ -210,6 +215,9 @@ fn player_loop(rx: std::sync::mpsc::Receiver<PlayerCommand>, status: PlayerStatu
|
||||
Err(e) => {
|
||||
eprintln!("playback error: {e}");
|
||||
*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 {
|
||||
ring_buf_producer: rb::Producer<f32>,
|
||||
viz_producer: Option<rb::Producer<f32>>,
|
||||
_stream: cpal::Stream,
|
||||
pub sample_rate: u32,
|
||||
pub channels: usize,
|
||||
@@ -51,12 +52,17 @@ impl AudioOutput {
|
||||
|
||||
Ok(Self {
|
||||
ring_buf_producer: producer,
|
||||
viz_producer: None,
|
||||
_stream: stream,
|
||||
sample_rate,
|
||||
channels,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_viz_producer(&mut self, producer: rb::Producer<f32>) {
|
||||
self.viz_producer = Some(producer);
|
||||
}
|
||||
|
||||
pub fn write(
|
||||
&mut self,
|
||||
decoded: AudioBufferRef<'_>,
|
||||
@@ -70,6 +76,11 @@ impl AudioOutput {
|
||||
sample_buf.copy_interleaved_ref(decoded);
|
||||
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[..];
|
||||
while !remaining.is_empty() {
|
||||
if stop.load(Ordering::SeqCst) {
|
||||
|
||||
@@ -61,6 +61,19 @@ void QobuzBackend::getArtist(qint64 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)
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
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 ----
|
||||
|
||||
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::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 ----
|
||||
|
||||
void QobuzBackend::onPositionTick()
|
||||
@@ -227,6 +265,17 @@ void QobuzBackend::onEvent(int eventType, const QString &json)
|
||||
case EV_ARTIST_OK:
|
||||
emit artistLoaded(obj);
|
||||
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:
|
||||
emit error(obj["error"].toString());
|
||||
break;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QTimer>
|
||||
|
||||
@@ -29,6 +30,8 @@ public:
|
||||
void search(const QString &query, quint32 offset = 0, quint32 limit = 20);
|
||||
void getAlbum(const QString &albumId);
|
||||
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);
|
||||
|
||||
// --- favorites ---
|
||||
@@ -53,6 +56,8 @@ public:
|
||||
void removeFavTrack(qint64 trackId);
|
||||
void addFavAlbum(const QString &albumId);
|
||||
void removeFavAlbum(const QString &albumId);
|
||||
void addFavArtist(qint64 artistId);
|
||||
void removeFavArtist(qint64 artistId);
|
||||
|
||||
// --- playback ---
|
||||
void playTrack(qint64 trackId, int formatId = 6);
|
||||
@@ -68,6 +73,11 @@ public:
|
||||
/// 1 = playing, 2 = paused, 0 = idle
|
||||
int state() const;
|
||||
|
||||
// --- visualizer PCM ---
|
||||
quint32 vizRead(float *buf, quint32 maxSamples);
|
||||
quint32 vizSampleRate() const;
|
||||
quint32 vizChannels() const;
|
||||
|
||||
signals:
|
||||
// auth
|
||||
void loginSuccess(const QString &token, const QJsonObject &user);
|
||||
@@ -78,6 +88,8 @@ signals:
|
||||
void searchResult(const QJsonObject &result);
|
||||
void albumLoaded(const QJsonObject &album);
|
||||
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 playlistCreated(const QJsonObject &playlist);
|
||||
void playlistDeleted(const QJsonObject &result);
|
||||
|
||||
@@ -40,7 +40,8 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
m_libraryDock->setObjectName(QStringLiteral("libraryDock"));
|
||||
m_libraryDock->setFeatures(QDockWidget::DockWidgetMovable);
|
||||
m_libraryDock->setWidget(m_library);
|
||||
m_libraryDock->setMinimumWidth(200);
|
||||
m_libraryDock->setMinimumWidth(180);
|
||||
m_library->setFixedWidth(220);
|
||||
addDockWidget(Qt::LeftDockWidgetArea, m_libraryDock);
|
||||
|
||||
// ---- 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::albumLoaded, this, &MainWindow::onAlbumLoaded);
|
||||
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::playlistCreated, this, &MainWindow::onPlaylistCreated);
|
||||
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…"));
|
||||
});
|
||||
connect(m_library, &List::Library::favArtistsRequested, this, [this] {
|
||||
m_showFavArtistsOnLoad = true;
|
||||
m_backend->getFavArtists();
|
||||
statusBar()->showMessage(tr("Loading favorite artists…"));
|
||||
});
|
||||
@@ -155,6 +161,8 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
this, &MainWindow::onSearchAlbumSelected);
|
||||
connect(m_content, &MainContent::artistRequested,
|
||||
this, &MainWindow::onSearchArtistSelected);
|
||||
connect(m_content, &MainContent::playTrackRequested,
|
||||
this, &MainWindow::onPlayTrackRequested);
|
||||
|
||||
// ---- Queue panel ----
|
||||
connect(m_queuePanel, &QueuePanel::skipToTrackRequested,
|
||||
@@ -165,6 +173,9 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
connect(m_toolBar, &MainToolBar::queueToggled,
|
||||
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
|
||||
m_backend->setReplayGain(AppSettings::instance().replayGainEnabled());
|
||||
m_backend->setGapless(AppSettings::instance().gaplessEnabled());
|
||||
@@ -210,6 +221,8 @@ void MainWindow::tryRestoreSession()
|
||||
m_backend->getUser(); // userLoaded will call m_library->refresh()
|
||||
else
|
||||
m_library->refresh();
|
||||
// Preload fav artists so the artist page fav button works immediately
|
||||
m_backend->getFavArtists();
|
||||
const QString name = AppSettings::instance().displayName();
|
||||
statusBar()->showMessage(tr("Signed in as %1").arg(
|
||||
name.isEmpty() ? AppSettings::instance().userEmail() : name));
|
||||
@@ -316,9 +329,22 @@ void MainWindow::onFavAlbumsLoaded(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);
|
||||
statusBar()->showMessage(
|
||||
tr("%1 favorite artists").arg(result["total"].toInt()), 4000);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onAlbumLoaded(const QJsonObject &album)
|
||||
@@ -331,8 +357,14 @@ void MainWindow::onAlbumLoaded(const QJsonObject &album)
|
||||
void MainWindow::onArtistLoaded(const QJsonObject &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(
|
||||
tr("Artist: %1").arg(artist["name"].toString()), 4000);
|
||||
tr("Artist: %1").arg(artist["name"].toObject()["display"].toString()), 4000);
|
||||
}
|
||||
|
||||
void MainWindow::onPlaylistLoaded(const QJsonObject &playlist)
|
||||
@@ -379,3 +411,4 @@ void MainWindow::onUserPlaylistsChanged(const QVector<QPair<qint64, QString>> &p
|
||||
m_userPlaylists = playlists;
|
||||
m_content->tracksList()->setUserPlaylists(playlists);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ private:
|
||||
QobuzBackend *m_backend = nullptr;
|
||||
PlayQueue *m_queue = nullptr;
|
||||
QVector<QPair<qint64, QString>> m_userPlaylists;
|
||||
QSet<qint64> m_favArtistIds;
|
||||
bool m_showFavArtistsOnLoad = false;
|
||||
MainToolBar *m_toolBar = nullptr;
|
||||
MainContent *m_content = nullptr;
|
||||
List::Library *m_library = nullptr;
|
||||
|
||||
@@ -51,8 +51,16 @@ void TrackListModel::setTracks(const QJsonArray &tracks,
|
||||
|
||||
const QJsonObject performer = t["performer"].toObject();
|
||||
item.artist = performer["name"].toString();
|
||||
if (item.artist.isEmpty())
|
||||
item.artist = t["album"].toObject()["artist"].toObject()["name"].toString();
|
||||
if (item.artist.isEmpty()) {
|
||||
// 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();
|
||||
item.album = album["title"].toString();
|
||||
|
||||
@@ -41,6 +41,25 @@ public:
|
||||
void setAlbums(const QJsonArray &albums)
|
||||
{
|
||||
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;
|
||||
hiResFont.setBold(true);
|
||||
hiResFont.setPointSizeF(hiResFont.pointSizeF() * 0.85);
|
||||
@@ -52,20 +71,17 @@ public:
|
||||
const QString ver = a["version"].toString().trimmed();
|
||||
const QString title = ver.isEmpty() ? base : base + QStringLiteral(" (") + ver + QLatin1Char(')');
|
||||
|
||||
// artist.name is either a plain string (old AlbumDto) or {display: ...} (artist/page)
|
||||
const QJsonValue artistNameVal = a["artist"].toObject()["name"];
|
||||
const QString artist = artistNameVal.isObject()
|
||||
? artistNameVal.toObject()["display"].toString()
|
||||
: artistNameVal.toString();
|
||||
|
||||
// year: release_date_original (old) or dates.original (artist/page)
|
||||
const QString date = a["release_date_original"].toString();
|
||||
const QString year = date.isEmpty()
|
||||
? a["dates"].toObject()["original"].toString().left(4)
|
||||
: date.left(4);
|
||||
|
||||
const int tracks = a["tracks_count"].toInt();
|
||||
// hires: flat field (old) or rights.hires_streamable (artist/page)
|
||||
const bool hiRes = a["hires_streamable"].toBool()
|
||||
|| a["rights"].toObject()["hires_streamable"].toBool();
|
||||
|
||||
|
||||
@@ -1,49 +1,69 @@
|
||||
#include "artistview.hpp"
|
||||
#include "albumlistview.hpp"
|
||||
#include "../model/tracklistmodel.hpp"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QScrollArea>
|
||||
#include <QHeaderView>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QPixmap>
|
||||
#include <QUrl>
|
||||
#include <QFont>
|
||||
#include <QJsonValue>
|
||||
#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(const QString &title, QWidget *parent)
|
||||
ArtistSection::ArtistSection(const QString &title, const QString &releaseType, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_baseTitle(title)
|
||||
, m_releaseType(releaseType)
|
||||
{
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->setSpacing(0);
|
||||
|
||||
m_toggle = new QToolButton(this);
|
||||
m_toggle = new QPushButton(this);
|
||||
m_toggle->setCheckable(true);
|
||||
m_toggle->setChecked(true);
|
||||
m_toggle->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||
m_toggle->setFlat(true);
|
||||
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);
|
||||
m_toggle->setStyleSheet(kToggleStyle);
|
||||
layout->addWidget(m_toggle);
|
||||
|
||||
m_list = new AlbumListView(this);
|
||||
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);
|
||||
|
||||
updateToggleText();
|
||||
}
|
||||
|
||||
void ArtistSection::setAlbums(const QJsonArray &albums)
|
||||
{
|
||||
m_list->setAlbums(albums);
|
||||
updateToggleText(albums.size());
|
||||
updateToggleText();
|
||||
}
|
||||
|
||||
bool ArtistSection::isEmpty() const
|
||||
@@ -51,51 +71,120 @@ bool ArtistSection::isEmpty() const
|
||||
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 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)
|
||||
ArtistView::ArtistView(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_backend(backend)
|
||||
, m_queue(queue)
|
||||
{
|
||||
auto *outerLayout = new QVBoxLayout(this);
|
||||
outerLayout->setContentsMargins(8, 8, 8, 8);
|
||||
outerLayout->setSpacing(6);
|
||||
outerLayout->setContentsMargins(0, 0, 0, 0);
|
||||
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();
|
||||
f.setPointSize(f.pointSize() + 4);
|
||||
f.setPointSize(f.pointSize() + 5);
|
||||
f.setBold(true);
|
||||
m_nameLabel->setFont(f);
|
||||
outerLayout->addWidget(m_nameLabel);
|
||||
vlay->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);
|
||||
m_bioEdit = new QTextEdit(info);
|
||||
m_bioEdit->setReadOnly(true);
|
||||
m_bioEdit->setFrameShape(QFrame::NoFrame);
|
||||
m_bioEdit->setMaximumHeight(56);
|
||||
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);
|
||||
scroll->setWidgetResizable(true);
|
||||
scroll->setFrameShape(QFrame::NoFrame);
|
||||
@@ -103,13 +192,49 @@ ArtistView::ArtistView(QWidget *parent)
|
||||
auto *content = new QWidget(scroll);
|
||||
auto *sectLayout = new QVBoxLayout(content);
|
||||
sectLayout->setContentsMargins(0, 0, 0, 0);
|
||||
sectLayout->setSpacing(8);
|
||||
sectLayout->setSpacing(0);
|
||||
|
||||
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);
|
||||
// Popular Tracks section — same toggle style as release sections
|
||||
m_topTracksSection = new QWidget(content);
|
||||
auto *ttLayout = new QVBoxLayout(m_topTracksSection);
|
||||
ttLayout->setContentsMargins(0, 0, 0, 0);
|
||||
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_secEps);
|
||||
@@ -121,6 +246,37 @@ ArtistView::ArtistView(QWidget *parent)
|
||||
scroll->setWidget(content);
|
||||
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_secEps, &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)
|
||||
{
|
||||
// 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());
|
||||
|
||||
// biography.content is HTML — strip tags for safe plain-text display
|
||||
// Biography: strip HTML tags
|
||||
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("<"));
|
||||
@@ -146,40 +303,122 @@ void ArtistView::setArtist(const QJsonObject &artist)
|
||||
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());
|
||||
m_bioEdit->setPlainText(plain);
|
||||
m_bioEdit->setVisible(!plain.isEmpty());
|
||||
} else {
|
||||
m_bioLabel->setVisible(false);
|
||||
m_bioEdit->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;
|
||||
// Artist portrait: images.portrait.hash + format → CDN URL
|
||||
const QJsonObject portrait = artist["images"].toObject()["portrait"].toObject();
|
||||
const QString hash = portrait["hash"].toString();
|
||||
const QString format = portrait["format"].toString();
|
||||
QString artUrl;
|
||||
if (!hash.isEmpty()) {
|
||||
artUrl = QStringLiteral("https://static.qobuz.com/images/artists/covers/large/%1.%2")
|
||||
.arg(hash, format.isEmpty() ? QStringLiteral("jpg") : format);
|
||||
} else {
|
||||
const QJsonObject img = artist["image"].toObject();
|
||||
artUrl = img["large"].toString();
|
||||
if (artUrl.isEmpty()) artUrl = img["small"].toString();
|
||||
}
|
||||
if (!artUrl.isEmpty() && artUrl != m_currentArtUrl) {
|
||||
m_currentArtUrl = artUrl;
|
||||
m_nam->get(QNetworkRequest(QUrl(artUrl)));
|
||||
} else if (artUrl.isEmpty()) {
|
||||
m_artLabel->setPixmap(QPixmap());
|
||||
m_currentArtUrl.clear();
|
||||
}
|
||||
|
||||
m_secAlbums->setAlbums(albums);
|
||||
m_secEps->setAlbums(eps);
|
||||
m_secLive->setAlbums(live);
|
||||
m_secCompilations->setAlbums(compilations);
|
||||
m_secOther->setAlbums({});
|
||||
// Popular tracks (flat array)
|
||||
const QJsonArray topTracks = artist["top_tracks"].toArray();
|
||||
m_topTracks->loadTracks(topTracks);
|
||||
|
||||
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);
|
||||
const int ttCount = topTracks.size();
|
||||
disconnect(m_topTracksToggle, &QPushButton::toggled, nullptr, nullptr);
|
||||
connect(m_topTracksToggle, &QPushButton::toggled, m_topTracks, &QWidget::setVisible);
|
||||
connect(m_topTracksToggle, &QPushButton::toggled, this, [this, ttCount](bool open) {
|
||||
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
|
||||
|
||||
#include "albumlistview.hpp"
|
||||
#include "../list/tracks.hpp"
|
||||
#include "../backend/qobuzbackend.hpp"
|
||||
#include "../playqueue.hpp"
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QToolButton>
|
||||
#include <QTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QSet>
|
||||
|
||||
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
|
||||
{
|
||||
Q_OBJECT
|
||||
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);
|
||||
bool isEmpty() const;
|
||||
QStringList albumIds() const;
|
||||
void setArtistPageMode();
|
||||
|
||||
signals:
|
||||
void albumSelected(const QString &albumId);
|
||||
|
||||
private:
|
||||
QString m_baseTitle;
|
||||
QToolButton *m_toggle = nullptr;
|
||||
QString m_releaseType;
|
||||
QPushButton *m_toggle = nullptr;
|
||||
AlbumListView *m_list = nullptr;
|
||||
|
||||
void updateToggleText(int count);
|
||||
void updateToggleText();
|
||||
};
|
||||
|
||||
/// Artist detail page: name, biography, and albums split into collapsible sections
|
||||
/// (Albums / EPs & Singles / Other) keyed on the release_type field.
|
||||
/// Artist detail page.
|
||||
class ArtistView : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ArtistView(QWidget *parent = nullptr);
|
||||
explicit ArtistView(QobuzBackend *backend, PlayQueue *queue, QWidget *parent = nullptr);
|
||||
|
||||
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:
|
||||
void albumSelected(const QString &albumId);
|
||||
void playTrackRequested(qint64 trackId);
|
||||
|
||||
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_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_secEps = nullptr;
|
||||
ArtistSection *m_secLive = nullptr;
|
||||
ArtistSection *m_secCompilations = 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_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(tracksPage); // 1
|
||||
@@ -57,6 +57,7 @@ MainContent::MainContent(QobuzBackend *backend, PlayQueue *queue, QWidget *paren
|
||||
connect(m_albumList, &AlbumListView::albumSelected, this, &MainContent::albumRequested);
|
||||
connect(m_artistList, &ArtistListView::artistSelected, this, &MainContent::artistRequested);
|
||||
connect(m_artistView, &ArtistView::albumSelected, this, &MainContent::albumRequested);
|
||||
connect(m_artistView, &ArtistView::playTrackRequested, this, &MainContent::playTrackRequested);
|
||||
}
|
||||
|
||||
void MainContent::showWelcome() { m_stack->setCurrentIndex(0); }
|
||||
@@ -106,3 +107,18 @@ void MainContent::showArtist(const QJsonObject &artist)
|
||||
m_artistView->setArtist(artist);
|
||||
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 showFavArtists(const QJsonObject &result);
|
||||
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:
|
||||
void albumRequested(const QString &albumId);
|
||||
void artistRequested(qint64 artistId);
|
||||
void playTrackRequested(qint64 trackId);
|
||||
|
||||
private:
|
||||
QobuzBackend *m_backend = nullptr;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <QNetworkRequest>
|
||||
#include <QResizeEvent>
|
||||
#include <QMenu>
|
||||
|
||||
MainToolBar::MainToolBar(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
||||
: QToolBar(parent)
|
||||
@@ -34,6 +35,22 @@ MainToolBar::MainToolBar(QobuzBackend *backend, PlayQueue *queue, QWidget *paren
|
||||
m_trackLabel->setTextFormat(Qt::RichText);
|
||||
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();
|
||||
|
||||
// ---- Media controls ----
|
||||
@@ -125,6 +142,7 @@ void MainToolBar::setPlaying(bool playing)
|
||||
|
||||
void MainToolBar::setCurrentTrack(const QJsonObject &track)
|
||||
{
|
||||
m_currentTrack = track;
|
||||
const QString title = track["title"].toString();
|
||||
const QString artist = track["performer"].toObject()["name"].toString().isEmpty()
|
||||
? track["album"].toObject()["artist"].toObject()["name"].toString()
|
||||
|
||||
@@ -27,6 +27,8 @@ public:
|
||||
signals:
|
||||
void searchToggled(bool visible);
|
||||
void queueToggled(bool visible);
|
||||
void albumRequested(const QString &albumId);
|
||||
void artistRequested(qint64 artistId);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
@@ -68,6 +70,7 @@ private:
|
||||
|
||||
QNetworkAccessManager *m_nam = nullptr;
|
||||
QString m_currentArtUrl;
|
||||
QJsonObject m_currentTrack;
|
||||
bool m_playing = false;
|
||||
bool m_seeking = false;
|
||||
};
|
||||
|
||||
@@ -119,7 +119,9 @@ public:
|
||||
|
||||
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_subtitle->setText(album["artist"].toObject()["name"].toString());
|
||||
m_subtitle->setEnabled(m_artistId > 0);
|
||||
|
||||
Reference in New Issue
Block a user