12 Commits

Author SHA1 Message Date
joren
183a53786f Merge branch 'refactor/uniform-menus'
Some checks failed
Build for Windows / build-windows (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-01 00:20:49 +02:00
joren
9f178a1cc3 feat: expand toolbar now-playing context menu to full track actions
- Replace bare "Go to Album"/"Go to Artist" with the full unified menu:
  Play next, Add to queue, Add to favorites, Open album/artist with
  names, Add to playlist submenu — all with icons
- Wire up new favTrackRequested/addToPlaylistRequested signals through
  MainWindow
- Pass user playlists to toolbar so the submenu is populated

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-01 00:17:41 +02:00
joren
d1a2bed593 refactor: unify context menus across all views
- Add icons to all context menus (search panel, genre browser, queue panel)
  matching the track list's established pattern
- Standardize navigation wording: "Open album: X" / "Open artist: X"
  consistently (was "Go to" in search panel, bare "Open Album" in genre browser)
- Genre browser album menu: add "Add to favorites" and "Open artist: X"
  (was missing both)
- Genre browser playlist menu: add icon, lowercase "playlist" for consistency
- Queue panel menu: add list-remove and go-up icons
- Track list: add icon to "Remove from this playlist" action
- Search panel album menu: add icons for all actions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 11:24:50 +02:00
joren
92d48e459e Merge branch 'refactor/color-constants'
Some checks failed
Build for Windows / build-windows (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 11:19:50 +02:00
joren
2139bbb726 Merge branch 'refactor/mainwindow-setup'
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 11:19:50 +02:00
joren
c2e0ff41ac Merge branch 'refactor/playqueue-split'
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 11:19:50 +02:00
joren
28771e12d5 fix: lazy-load genre/playlist views and cap playlist search scrolling
Some checks failed
Build for Windows / build-windows (push) Has been cancelled
- Defer eager-load scrollbar checks to next event loop iteration via
  QTimer::singleShot(0), fixing initial load not filling the viewport
- Playlist search: eagerly fill viewport, then show "Load more playlists…"
  button instead of infinite scroll to avoid loading thousands of results
- Increase search page size from 8 to 25
- Featured/discover playlists keep auto-scroll behavior unchanged

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 11:17:23 +02:00
joren
d1b9cb1210 refactor: centralize hardcoded color values into Colors namespace
Add src/util/colors.hpp with named constants for all QColor values
(brand accents, badge colors, text shades, surface backgrounds) and
replace scattered QColor constructor calls across 7 source files.
Stylesheet string colors are intentionally left inline.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 11:01:45 +02:00
joren
5f79170f48 refactor: split MainWindow constructor into focused setup methods
Extract the ~300-line constructor body into setupDocks(), setupScrobbler(),
setupGapless(), setupMpris(), connectBackendSignals(), connectLibrarySignals(),
connectContentSignals(), and connectToolbarSignals(). No behavioral changes;
all signal/slot connections and widget creation remain identical.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 11:00:19 +02:00
joren
dea16676ce refactor: split PlayQueue from header-only into .hpp/.cpp pair
Move all method implementations from playqueue.hpp into a new
playqueue.cpp, keeping only declarations and trivial inline getters
in the header. No logic or behavior changes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-31 10:58:06 +02:00
joren
e9a9077ece Merge branch 'refactor/code-quality'
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 10:54:49 +02:00
joren
86b5673e8a refactor: reduce duplication and replace magic stack indices
- Extract parseTrackItem() static helper in TrackListModel to eliminate
  ~45 lines of duplicated JSON parsing between setTracks() and appendTracks()
- Extract notifyFavChanged() helper to deduplicate addFavId/removeFavId loops
- Add StackPage enum to MainContent replacing magic integers 0-5 with
  named constants (PageWelcome, PageTracks, PageAlbumList, etc.)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-31 10:48:21 +02:00
21 changed files with 725 additions and 489 deletions

View File

@@ -6,8 +6,9 @@ target_sources(qobuz-qt PRIVATE
mainwindow.hpp mainwindow.hpp
mainwindow.cpp mainwindow.cpp
# Queue (header-only) # Queue
playqueue.hpp playqueue.hpp
playqueue.cpp
# Backend (Qt wrapper around Rust FFI) # Backend (Qt wrapper around Rust FFI)
backend/qobuzbackend.hpp backend/qobuzbackend.hpp

View File

@@ -347,7 +347,7 @@ void Tracks::onContextMenu(const QPoint &pos)
m_model->data(index, TrackListModel::PlaylistTrackIdRole).toLongLong(); m_model->data(index, TrackListModel::PlaylistTrackIdRole).toLongLong();
if (playlistTrackId > 0) { if (playlistTrackId > 0) {
if (m_userPlaylists.isEmpty()) menu.addSeparator(); if (m_userPlaylists.isEmpty()) menu.addSeparator();
auto *remFromPl = menu.addAction(tr("Remove from this playlist")); auto *remFromPl = menu.addAction(QIcon(":/res/icons/list-remove.svg"), tr("Remove from this playlist"));
const qint64 curPlaylistId = m_playlistId; const qint64 curPlaylistId = m_playlistId;
const int curRow = index.row(); const int curRow = index.row();
connect(remFromPl, &QAction::triggered, this, [this, curPlaylistId, playlistTrackId, curRow] { connect(remFromPl, &QAction::triggered, this, [this, curPlaylistId, playlistTrackId, curRow] {

View File

@@ -1,5 +1,6 @@
#include "mainwindow.hpp" #include "mainwindow.hpp"
#include "backend/qobuzbackend.hpp" #include "backend/qobuzbackend.hpp"
#include "util/colors.hpp"
#include <QApplication> #include <QApplication>
#include <QStyleFactory> #include <QStyleFactory>
@@ -15,24 +16,24 @@ int main(int argc, char *argv[])
// Accent: #FFB232 (yellow-orange), Blue: #46B3EE, Backgrounds: #191919 / #141414 // Accent: #FFB232 (yellow-orange), Blue: #46B3EE, Backgrounds: #191919 / #141414
app.setStyle(QStyleFactory::create(QStringLiteral("Fusion"))); app.setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
QPalette darkPalette; QPalette darkPalette;
darkPalette.setColor(QPalette::Window, QColor(0x19, 0x19, 0x19)); darkPalette.setColor(QPalette::Window, Colors::WindowBg);
darkPalette.setColor(QPalette::WindowText, QColor(0xe8, 0xe8, 0xe8)); darkPalette.setColor(QPalette::WindowText, Colors::LightText);
darkPalette.setColor(QPalette::Base, QColor(0x14, 0x14, 0x14)); darkPalette.setColor(QPalette::Base, Colors::BaseBg);
darkPalette.setColor(QPalette::AlternateBase, QColor(0x1e, 0x1e, 0x1e)); darkPalette.setColor(QPalette::AlternateBase, Colors::AlternateBaseBg);
darkPalette.setColor(QPalette::ToolTipBase, QColor(0x19, 0x19, 0x19)); darkPalette.setColor(QPalette::ToolTipBase, Colors::WindowBg);
darkPalette.setColor(QPalette::ToolTipText, QColor(0xe8, 0xe8, 0xe8)); darkPalette.setColor(QPalette::ToolTipText, Colors::LightText);
darkPalette.setColor(QPalette::Text, QColor(0xe8, 0xe8, 0xe8)); darkPalette.setColor(QPalette::Text, Colors::LightText);
darkPalette.setColor(QPalette::Button, QColor(0x2a, 0x2a, 0x2a)); darkPalette.setColor(QPalette::Button, Colors::ButtonSurface);
darkPalette.setColor(QPalette::ButtonText, QColor(0xe8, 0xe8, 0xe8)); darkPalette.setColor(QPalette::ButtonText, Colors::LightText);
darkPalette.setColor(QPalette::BrightText, QColor(0xFF, 0xB2, 0x32)); darkPalette.setColor(QPalette::BrightText, Colors::QobuzOrange);
darkPalette.setColor(QPalette::Link, QColor(0x46, 0xB3, 0xEE)); // Qobuz blue darkPalette.setColor(QPalette::Link, Colors::QobuzBlue);
darkPalette.setColor(QPalette::Highlight, QColor(0xFF, 0xB2, 0x32)); // Qobuz orange darkPalette.setColor(QPalette::Highlight, Colors::QobuzOrange);
darkPalette.setColor(QPalette::HighlightedText, QColor(0x10, 0x10, 0x10)); // dark on orange darkPalette.setColor(QPalette::HighlightedText, Colors::HighlightedFg);
darkPalette.setColor(QPalette::PlaceholderText, QColor(0x66, 0x66, 0x66)); darkPalette.setColor(QPalette::PlaceholderText, Colors::PlaceholderText);
darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(0x55, 0x55, 0x55)); darkPalette.setColor(QPalette::Disabled, QPalette::Text, Colors::DisabledText);
darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(0x55, 0x55, 0x55)); darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, Colors::DisabledText);
darkPalette.setColor(QPalette::Mid, QColor(0x2f, 0x2f, 0x2f)); darkPalette.setColor(QPalette::Mid, Colors::MidSurface);
darkPalette.setColor(QPalette::Dark, QColor(0x0e, 0x0e, 0x0e)); darkPalette.setColor(QPalette::Dark, Colors::DarkSurface);
app.setPalette(darkPalette); app.setPalette(darkPalette);
// Stylesheet tweaks: orange accent on scrollbars, focus rings, etc. // Stylesheet tweaks: orange accent on scrollbars, focus rings, etc.

View File

@@ -38,6 +38,27 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
m_content = new MainContent(m_backend, m_queue, this); m_content = new MainContent(m_backend, m_queue, this);
setCentralWidget(m_content); setCentralWidget(m_content);
setupDocks();
setupMenuBar();
statusBar()->showMessage(tr("Ready"));
setupScrobbler();
setupGapless();
setupMpris();
connectBackendSignals();
connectLibrarySignals();
connectContentSignals();
connectToolbarSignals();
// Apply playback options from saved settings
m_backend->setReplayGain(AppSettings::instance().replayGainEnabled());
m_backend->setGapless(AppSettings::instance().gaplessEnabled());
tryRestoreSession();
}
void MainWindow::setupDocks()
{
// ---- Library dock (left) ---- // ---- Library dock (left) ----
m_library = new List::Library(m_backend, this); m_library = new List::Library(m_backend, this);
m_libraryDock = new QDockWidget(tr("Library"), this); m_libraryDock = new QDockWidget(tr("Library"), this);
@@ -60,11 +81,10 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
m_sidePanel = new SidePanel::View(m_backend, m_queue, this); m_sidePanel = new SidePanel::View(m_backend, m_queue, this);
m_sidePanel->hide(); m_sidePanel->hide();
addDockWidget(Qt::RightDockWidgetArea, m_sidePanel); addDockWidget(Qt::RightDockWidgetArea, m_sidePanel);
}
setupMenuBar(); void MainWindow::setupScrobbler()
statusBar()->showMessage(tr("Ready")); {
// ---- Scrobbler ----
m_scrobbler = new LastFmScrobbler(this); m_scrobbler = new LastFmScrobbler(this);
connect(m_backend, &QobuzBackend::trackChanged, connect(m_backend, &QobuzBackend::trackChanged,
m_scrobbler, &LastFmScrobbler::onTrackStarted); m_scrobbler, &LastFmScrobbler::onTrackStarted);
@@ -73,11 +93,13 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
connect(m_backend, &QobuzBackend::trackFinished, connect(m_backend, &QobuzBackend::trackFinished,
m_scrobbler, &LastFmScrobbler::onTrackFinished); m_scrobbler, &LastFmScrobbler::onTrackFinished);
// 1. Scrobble the finished track during a gapless transition // Scrobble the finished track during a gapless transition
connect(m_backend, &QobuzBackend::trackTransitioned, connect(m_backend, &QobuzBackend::trackTransitioned,
m_scrobbler, &LastFmScrobbler::onTrackFinished); m_scrobbler, &LastFmScrobbler::onTrackFinished);
}
// ---- Gapless Signal ---- void MainWindow::setupGapless()
{
connect(m_backend, &QobuzBackend::positionChanged, this, [this](quint64 pos, quint64 dur) { connect(m_backend, &QobuzBackend::positionChanged, this, [this](quint64 pos, quint64 dur) {
if (!AppSettings::instance().gaplessEnabled() || dur == 0) return; if (!AppSettings::instance().gaplessEnabled() || dur == 0) return;
@@ -96,8 +118,58 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
} }
} }
}); });
}
// ---- Backend signals ---- void MainWindow::setupMpris()
{
#ifdef USE_DBUS
m_mpris = new Mpris(this);
connect(m_mpris->player(), &MprisPlayerAdaptor::playRequested, m_backend, [this] {
if (m_backend->state() == 2) m_backend->resume();
});
connect(m_mpris->player(), &MprisPlayerAdaptor::pauseRequested, m_backend, &QobuzBackend::pause);
connect(m_mpris->player(), &MprisPlayerAdaptor::playPauseRequested, m_backend, [this] {
if (m_backend->state() == 1)
m_backend->pause();
else
m_backend->resume();
});
connect(m_mpris->player(), &MprisPlayerAdaptor::stopRequested, m_backend, &QobuzBackend::stop);
connect(m_mpris->player(), &MprisPlayerAdaptor::nextRequested, this, [this] {
if (!m_queue->canGoNext()) return;
const qint64 id = static_cast<qint64>(m_queue->advance()["id"].toDouble());
if (id > 0) m_backend->playTrack(id);
});
connect(m_mpris->player(), &MprisPlayerAdaptor::previousRequested, this, [this] {
if (!m_queue->canGoPrev()) return;
const qint64 id = static_cast<qint64>(m_queue->stepBack()["id"].toDouble());
if (id > 0) m_backend->playTrack(id);
});
connect(m_mpris->player(), &MprisPlayerAdaptor::seekRequested, m_backend, [this](qlonglong offsetMicroseconds) {
qint64 newPos = m_backend->position() + (offsetMicroseconds / 1000000LL);
if (newPos < 0) newPos = 0;
m_backend->seek(newPos);
});
connect(m_mpris->player(), &MprisPlayerAdaptor::seekToRequested, m_backend, [this](qlonglong positionMicroseconds) {
m_backend->seek(positionMicroseconds / 1000000LL);
});
connect(m_mpris->player(), &MprisPlayerAdaptor::volumeChangeRequested, m_backend, [this](double vol) {
m_backend->setVolume(vol * 100);
});
connect(m_backend, &QobuzBackend::stateChanged, this, [this](const QString &state) {
if (state == "playing") m_mpris->player()->setPlaybackStatus("Playing");
else if (state == "paused") m_mpris->player()->setPlaybackStatus("Paused");
else m_mpris->player()->setPlaybackStatus("Stopped");
});
connect(m_backend, &QobuzBackend::positionChanged, this, [this](quint64 pos) {
m_mpris->player()->updatePosition(pos);
});
#endif
}
void MainWindow::connectBackendSignals()
{
connect(m_backend, &QobuzBackend::loginSuccess, this, &MainWindow::onLoginSuccess); connect(m_backend, &QobuzBackend::loginSuccess, this, &MainWindow::onLoginSuccess);
connect(m_backend, &QobuzBackend::loginError, this, &MainWindow::onLoginError); connect(m_backend, &QobuzBackend::loginError, this, &MainWindow::onLoginError);
connect(m_backend, &QobuzBackend::userLoaded, this, [this](const QJsonObject &user) { connect(m_backend, &QobuzBackend::userLoaded, this, [this](const QJsonObject &user) {
@@ -145,8 +217,10 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
connect(m_backend, &QobuzBackend::error, this, [this](const QString &msg) { connect(m_backend, &QobuzBackend::error, this, [this](const QString &msg) {
statusBar()->showMessage(tr("Error: %1").arg(msg), 6000); statusBar()->showMessage(tr("Error: %1").arg(msg), 6000);
}); });
}
// ---- Library signals ---- void MainWindow::connectLibrarySignals()
{
connect(m_library, &List::Library::userPlaylistIdsChanged, connect(m_library, &List::Library::userPlaylistIdsChanged,
this, [this](const QSet<qint64> &playlistIds) { this, [this](const QSet<qint64> &playlistIds) {
m_userPlaylistIds = playlistIds; m_userPlaylistIds = playlistIds;
@@ -167,52 +241,6 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
m_backend->getFavTracks(); m_backend->getFavTracks();
statusBar()->showMessage(tr("Loading favorite tracks…")); statusBar()->showMessage(tr("Loading favorite tracks…"));
}); });
#ifdef USE_DBUS
m_mpris = new Mpris(this);
connect(m_mpris->player(), &MprisPlayerAdaptor::playRequested, m_backend, [this] {
if (m_backend->state() == 2) m_backend->resume();
});
connect(m_mpris->player(), &MprisPlayerAdaptor::pauseRequested, m_backend, &QobuzBackend::pause);
connect(m_mpris->player(), &MprisPlayerAdaptor::playPauseRequested, m_backend, [this] {
if (m_backend->state() == 1)
m_backend->pause();
else
m_backend->resume();
});
connect(m_mpris->player(), &MprisPlayerAdaptor::stopRequested, m_backend, &QobuzBackend::stop);
connect(m_mpris->player(), &MprisPlayerAdaptor::nextRequested, this, [this] {
if (!m_queue->canGoNext()) return;
const qint64 id = static_cast<qint64>(m_queue->advance()["id"].toDouble());
if (id > 0) m_backend->playTrack(id);
});
connect(m_mpris->player(), &MprisPlayerAdaptor::previousRequested, this, [this] {
if (!m_queue->canGoPrev()) return;
const qint64 id = static_cast<qint64>(m_queue->stepBack()["id"].toDouble());
if (id > 0) m_backend->playTrack(id);
});
connect(m_mpris->player(), &MprisPlayerAdaptor::seekRequested, m_backend, [this](qlonglong offsetMicroseconds) {
qint64 newPos = m_backend->position() + (offsetMicroseconds / 1000000LL);
if (newPos < 0) newPos = 0;
m_backend->seek(newPos);
});
connect(m_mpris->player(), &MprisPlayerAdaptor::seekToRequested, m_backend, [this](qlonglong positionMicroseconds) {
m_backend->seek(positionMicroseconds / 1000000LL);
});
connect(m_mpris->player(), &MprisPlayerAdaptor::volumeChangeRequested, m_backend, [this](double vol) {
m_backend->setVolume(vol * 100);
});
connect(m_backend, &QobuzBackend::stateChanged, this, [this](const QString &state) {
if (state == "playing") m_mpris->player()->setPlaybackStatus("Playing");
else if (state == "paused") m_mpris->player()->setPlaybackStatus("Paused");
else m_mpris->player()->setPlaybackStatus("Stopped");
});
connect(m_backend, &QobuzBackend::positionChanged, this, [this](quint64 pos) {
m_mpris->player()->updatePosition(pos);
});
#endif
connect(m_library, &List::Library::favAlbumsRequested, this, [this] { connect(m_library, &List::Library::favAlbumsRequested, this, [this] {
m_showFavAlbumsOnLoad = true; m_showFavAlbumsOnLoad = true;
m_backend->getFavAlbums(); m_backend->getFavAlbums();
@@ -236,7 +264,10 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
m_content->showPlaylistBrowser(); m_content->showPlaylistBrowser();
statusBar()->showMessage(tr("Browse Playlists")); statusBar()->showMessage(tr("Browse Playlists"));
}); });
}
void MainWindow::connectContentSignals()
{
// ---- Track list → playback / playlist management ---- // ---- Track list → playback / playlist management ----
connect(m_content->tracksList(), &List::Tracks::playTrackRequested, connect(m_content->tracksList(), &List::Tracks::playTrackRequested,
this, &MainWindow::onPlayTrackRequested); this, &MainWindow::onPlayTrackRequested);
@@ -300,8 +331,10 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
// ---- Queue panel ---- // ---- Queue panel ----
connect(m_queuePanel, &QueuePanel::skipToTrackRequested, connect(m_queuePanel, &QueuePanel::skipToTrackRequested,
this, &MainWindow::onPlayTrackRequested); this, &MainWindow::onPlayTrackRequested);
}
// ---- Toolbar toggles ---- void MainWindow::connectToolbarSignals()
{
connect(m_toolBar, &MainToolBar::searchToggled, this, &MainWindow::onSearchToggled); connect(m_toolBar, &MainToolBar::searchToggled, this, &MainWindow::onSearchToggled);
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); });
@@ -314,12 +347,15 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
connect(m_toolBar, &MainToolBar::albumRequested, this, &MainWindow::onSearchAlbumSelected); connect(m_toolBar, &MainToolBar::albumRequested, this, &MainWindow::onSearchAlbumSelected);
connect(m_toolBar, &MainToolBar::artistRequested, this, &MainWindow::onSearchArtistSelected); connect(m_toolBar, &MainToolBar::artistRequested, this, &MainWindow::onSearchArtistSelected);
connect(m_toolBar, &MainToolBar::addToPlaylistRequested,
// Apply playback options from saved settings this, [this](qint64 trackId, qint64 playlistId) {
m_backend->setReplayGain(AppSettings::instance().replayGainEnabled()); m_backend->addTrackToPlaylist(playlistId, trackId);
m_backend->setGapless(AppSettings::instance().gaplessEnabled()); statusBar()->showMessage(tr("Adding track to playlist…"), 3000);
});
tryRestoreSession(); connect(m_toolBar, &MainToolBar::favTrackRequested,
this, [this](qint64 trackId) {
m_backend->addFavTrack(trackId);
});
} }
void MainWindow::setupMenuBar() void MainWindow::setupMenuBar()
@@ -602,4 +638,5 @@ 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);
m_sidePanel->searchTab()->setUserPlaylists(playlists); m_sidePanel->searchTab()->setUserPlaylists(playlists);
m_toolBar->setUserPlaylists(playlists);
} }

View File

@@ -72,5 +72,13 @@ private:
bool m_nextTrackPrefetched = false; bool m_nextTrackPrefetched = false;
void setupMenuBar(); void setupMenuBar();
void setupDocks();
void setupScrobbler();
void setupGapless();
void setupMpris();
void connectBackendSignals();
void connectLibrarySignals();
void connectContentSignals();
void connectToolbarSignals();
void tryRestoreSession(); void tryRestoreSession();
}; };

View File

@@ -1,4 +1,5 @@
#include "tracklistmodel.hpp" #include "tracklistmodel.hpp"
#include "../util/colors.hpp"
#include <QJsonValue> #include <QJsonValue>
#include <QColor> #include <QColor>
@@ -9,21 +10,11 @@ TrackListModel::TrackListModel(QObject *parent)
: QAbstractTableModel(parent) : QAbstractTableModel(parent)
{} {}
void TrackListModel::setTracks(const QJsonArray &tracks, TrackItem TrackListModel::parseTrackItem(const QJsonObject &t,
bool usePosition, bool usePosition,
bool useSequential) bool useSequential,
int &seq)
{ {
beginResetModel();
m_tracks.clear();
m_tracks.reserve(tracks.size());
// Parse into a temporary list first so we can detect multi-disc
QVector<TrackItem> parsed;
parsed.reserve(tracks.size());
int seq = 1;
for (const QJsonValue &v : tracks) {
const QJsonObject t = v.toObject();
TrackItem item; TrackItem item;
item.id = static_cast<qint64>(t["id"].toDouble()); item.id = static_cast<qint64>(t["id"].toDouble());
item.playlistTrackId = static_cast<qint64>(t["playlist_track_id"].toDouble()); item.playlistTrackId = static_cast<qint64>(t["playlist_track_id"].toDouble());
@@ -66,9 +57,25 @@ void TrackListModel::setTracks(const QJsonArray &tracks,
item.album = album["title"].toString(); item.album = album["title"].toString();
item.albumId = album["id"].toString(); item.albumId = album["id"].toString();
parsed.append(item); return item;
} }
void TrackListModel::setTracks(const QJsonArray &tracks,
bool usePosition,
bool useSequential)
{
beginResetModel();
m_tracks.clear();
m_tracks.reserve(tracks.size());
// Parse into a temporary list first so we can detect multi-disc
QVector<TrackItem> parsed;
parsed.reserve(tracks.size());
int seq = 1;
for (const QJsonValue &v : tracks)
parsed.append(parseTrackItem(v.toObject(), usePosition, useSequential, seq));
// Multi-disc only makes sense for album context (not playlists / fav / search) // Multi-disc only makes sense for album context (not playlists / fav / search)
int maxDisc = 1; int maxDisc = 1;
if (!usePosition && !useSequential) { if (!usePosition && !useSequential) {
@@ -134,49 +141,8 @@ void TrackListModel::appendTracks(const QJsonArray &tracks,
QVector<TrackItem> parsed; QVector<TrackItem> parsed;
parsed.reserve(tracks.size()); parsed.reserve(tracks.size());
for (const QJsonValue &v : tracks) { for (const QJsonValue &v : tracks)
const QJsonObject t = v.toObject(); parsed.append(parseTrackItem(v.toObject(), usePosition, useSequential, seq));
TrackItem item;
item.id = static_cast<qint64>(t["id"].toDouble());
item.playlistTrackId = static_cast<qint64>(t["playlist_track_id"].toDouble());
item.discNumber = t["media_number"].toInt(1);
item.duration = static_cast<qint64>(t["duration"].toDouble());
item.streamable = t["streamable"].toBool(true);
item.hiRes = t["hires_streamable"].toBool();
item.raw = t;
const QString base = t["title"].toString();
const QString version = t["version"].toString().trimmed();
item.title = version.isEmpty() ? base
: base + QStringLiteral(" (") + version + QLatin1Char(')');
if (useSequential) {
item.number = seq++;
} else if (usePosition) {
const int pos = t["position"].toInt();
item.number = pos > 0 ? pos : seq;
++seq;
} else {
item.number = t["track_number"].toInt();
}
const QJsonObject performer = t["performer"].toObject();
item.artist = performer["name"].toString();
if (item.artist.isEmpty()) {
const QJsonValue n = t["album"].toObject()["artist"].toObject()["name"];
item.artist = n.isObject() ? n.toObject()["display"].toString() : n.toString();
}
if (item.artist.isEmpty()) {
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();
item.albumId = album["id"].toString();
parsed.append(item);
}
if (parsed.isEmpty()) if (parsed.isEmpty())
return; return;
@@ -210,6 +176,16 @@ void TrackListModel::removeTrack(int row)
endRemoveRows(); endRemoveRows();
} }
void TrackListModel::notifyFavChanged(qint64 id)
{
for (int r = 0; r < m_tracks.size(); ++r) {
if (m_tracks[r].id == id) {
const auto idx = index(r, ColTitle);
emit dataChanged(idx, idx, {Qt::DecorationRole});
}
}
}
void TrackListModel::setFavIds(const QSet<qint64> &ids) void TrackListModel::setFavIds(const QSet<qint64> &ids)
{ {
m_favIds = ids; m_favIds = ids;
@@ -221,23 +197,13 @@ void TrackListModel::setFavIds(const QSet<qint64> &ids)
void TrackListModel::addFavId(qint64 id) void TrackListModel::addFavId(qint64 id)
{ {
m_favIds.insert(id); m_favIds.insert(id);
for (int r = 0; r < m_tracks.size(); ++r) { notifyFavChanged(id);
if (m_tracks[r].id == id) {
const auto idx = index(r, ColTitle);
emit dataChanged(idx, idx, {Qt::DecorationRole});
}
}
} }
void TrackListModel::removeFavId(qint64 id) void TrackListModel::removeFavId(qint64 id)
{ {
m_favIds.remove(id); m_favIds.remove(id);
for (int r = 0; r < m_tracks.size(); ++r) { notifyFavChanged(id);
if (m_tracks[r].id == id) {
const auto idx = index(r, ColTitle);
emit dataChanged(idx, idx, {Qt::DecorationRole});
}
}
} }
void TrackListModel::setPlayingId(qint64 id) void TrackListModel::setPlayingId(qint64 id)
@@ -290,7 +256,7 @@ QVariant TrackListModel::data(const QModelIndex &index, int role) const
QFont f; f.setBold(true); return f; QFont f; f.setBold(true); return f;
} }
if (role == Qt::ForegroundRole) if (role == Qt::ForegroundRole)
return QColor(0xFF, 0xB2, 0x32); return Colors::QobuzOrange;
return {}; return {};
} }
@@ -313,8 +279,8 @@ QVariant TrackListModel::data(const QModelIndex &index, int role) const
} }
if (role == Qt::ForegroundRole) { if (role == Qt::ForegroundRole) {
if (!t.streamable) return QColor(0x55, 0x55, 0x55); if (!t.streamable) return Colors::DisabledText;
if (isPlaying) return QColor(0xFF, 0xB2, 0x32); // Qobuz orange if (isPlaying) return Colors::QobuzOrange;
} }
if (role == Qt::DecorationRole && index.column() == ColNumber && isPlaying) { if (role == Qt::DecorationRole && index.column() == ColNumber && isPlaying) {

View File

@@ -105,4 +105,10 @@ private:
// Sort m_tracks in-place without emitting any signals. // Sort m_tracks in-place without emitting any signals.
void sortData(int column, Qt::SortOrder order); void sortData(int column, Qt::SortOrder order);
// Parse a single JSON track object into a TrackItem.
static TrackItem parseTrackItem(const QJsonObject &t, bool usePosition, bool useSequential, int &seq);
// Emit dataChanged(DecorationRole) for all rows matching id.
void notifyFavChanged(qint64 id);
}; };

238
src/playqueue.cpp Normal file
View File

@@ -0,0 +1,238 @@
#include "playqueue.hpp"
#include <algorithm>
#include <random>
PlayQueue::PlayQueue(QObject *parent) : QObject(parent) {}
void PlayQueue::setContext(const QJsonArray &tracks, int startIndex)
{
m_queue.clear();
m_playNext.clear();
// Only queue streamable tracks; find the filtered index for startIndex
int filteredStart = 0;
int filteredIdx = 0;
bool found = false;
for (int orig = 0; orig < tracks.size(); ++orig) {
const QJsonObject t = tracks[orig].toObject();
if (!t["streamable"].toBool(true))
continue;
if (!found && orig >= startIndex) {
filteredStart = filteredIdx;
found = true;
}
m_queue.append(t);
++filteredIdx;
}
m_index = qBound(0, filteredStart, qMax(0, m_queue.size() - 1));
if (m_shuffle)
shuffleQueue(m_index);
emit queueChanged();
}
void PlayQueue::reorderContext(const QJsonArray &tracks, qint64 currentId)
{
m_queue.clear();
for (const auto &v : tracks) {
const QJsonObject t = v.toObject();
if (t["streamable"].toBool(true))
m_queue.append(t);
}
m_index = 0;
for (int i = 0; i < m_queue.size(); ++i) {
if (static_cast<qint64>(m_queue[i]["id"].toDouble()) == currentId) {
m_index = i;
break;
}
}
emit queueChanged();
}
void PlayQueue::clearUpcoming()
{
m_playNext.clear();
if (m_index < m_queue.size())
m_queue.resize(m_index + 1); // keep up to and including current
emit queueChanged();
}
void PlayQueue::removeUpcoming(int upcomingIndex)
{
if (upcomingIndex < m_playNext.size()) {
m_playNext.removeAt(upcomingIndex);
} else {
const int queueIdx = m_index + 1 + (upcomingIndex - m_playNext.size());
if (queueIdx < m_queue.size())
m_queue.removeAt(queueIdx);
}
emit queueChanged();
}
void PlayQueue::setShuffle(bool enabled)
{
if (m_shuffle == enabled) return;
m_shuffle = enabled;
if (enabled && !m_queue.isEmpty())
shuffleQueue(m_index);
emit queueChanged();
}
void PlayQueue::shuffleNow()
{
if (m_queue.isEmpty()) return;
shuffleQueue(m_index);
emit queueChanged();
}
void PlayQueue::addToQueue(const QJsonObject &track)
{
m_playNext.append(track);
emit queueChanged();
}
void PlayQueue::playNext(const QJsonObject &track)
{
m_playNext.prepend(track);
emit queueChanged();
}
bool PlayQueue::hasCurrent() const
{
return (!m_playNext.isEmpty()) || (!m_queue.isEmpty());
}
QJsonObject PlayQueue::current() const
{
if (!m_playNext.isEmpty()) return m_playNext.first();
if (m_index < m_queue.size()) return m_queue.at(m_index);
return {};
}
qint64 PlayQueue::currentId() const
{
return static_cast<qint64>(current()["id"].toDouble());
}
QJsonObject PlayQueue::advance()
{
if (!m_playNext.isEmpty()) {
// Return the playNext item directly — do NOT call current() after
// removal, as that would fall back to the already-playing m_index track.
const QJsonObject next = m_playNext.takeFirst();
emit queueChanged();
return next;
}
++m_index;
emit queueChanged();
return current();
}
QJsonObject PlayQueue::stepBack()
{
if (m_index > 0) --m_index;
emit queueChanged();
return current();
}
bool PlayQueue::canGoNext() const
{
return !m_playNext.isEmpty() || (m_index + 1 < m_queue.size());
}
void PlayQueue::setCurrentById(qint64 id)
{
m_playNext.clear();
for (int i = 0; i < m_queue.size(); ++i) {
if (static_cast<qint64>(m_queue[i]["id"].toDouble()) == id) {
m_index = i;
emit queueChanged();
return;
}
}
}
QVector<QJsonObject> PlayQueue::upcomingTracks(int maxCount) const
{
QVector<QJsonObject> result;
result.append(m_playNext);
for (int i = m_index + 1; i < m_queue.size() && result.size() < maxCount; ++i)
result.append(m_queue.at(i));
return result;
}
QJsonObject PlayQueue::skipToUpcoming(int upcomingIndex)
{
// Remove items 0..upcomingIndex-1 from the front of upcoming
for (int i = 0; i < upcomingIndex; ++i) {
if (!m_playNext.isEmpty())
m_playNext.removeFirst();
else if (m_index + 1 < m_queue.size())
++m_index;
}
// Pop and return the target (now at upcoming[0])
if (!m_playNext.isEmpty()) {
const QJsonObject t = m_playNext.takeFirst();
emit queueChanged();
return t;
}
if (m_index + 1 < m_queue.size()) {
++m_index;
emit queueChanged();
return m_queue.at(m_index);
}
emit queueChanged();
return {};
}
void PlayQueue::setUpcomingOrder(const QVector<QJsonObject> &newOrder)
{
m_playNext = newOrder;
m_queue.resize(m_index + 1); // drop old main-queue tail
emit queueChanged();
}
void PlayQueue::appendToContext(const QJsonArray &tracks)
{
for (const auto &v : tracks) {
const QJsonObject t = v.toObject();
if (t["streamable"].toBool(true))
m_queue.append(t);
}
emit queueChanged();
}
void PlayQueue::moveUpcomingToTop(int upcomingIndex)
{
if (upcomingIndex < 0) return;
QJsonObject track;
if (upcomingIndex < m_playNext.size()) {
if (upcomingIndex == 0) return; // already at top
track = m_playNext.takeAt(upcomingIndex);
} else {
const int queueIdx = m_index + 1 + (upcomingIndex - m_playNext.size());
if (queueIdx >= m_queue.size()) return;
track = m_queue.takeAt(queueIdx);
}
m_playNext.prepend(track);
emit queueChanged();
}
void PlayQueue::shuffleQueue(int keepAtFront)
{
if (m_queue.isEmpty()) return;
// Keep the current track at index 0 of the remaining queue
if (keepAtFront >= 0 && keepAtFront < m_queue.size()) {
QJsonObject current = m_queue.takeAt(keepAtFront);
std::mt19937 rng(std::random_device{}());
std::shuffle(m_queue.begin(), m_queue.end(), rng);
m_queue.prepend(current);
} else {
std::mt19937 rng(std::random_device{}());
std::shuffle(m_queue.begin(), m_queue.end(), rng);
}
m_index = 0;
}

View File

@@ -4,8 +4,6 @@
#include <QVector> #include <QVector>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include <algorithm>
#include <random>
/// Local playback queue. Holds the ordered list of tracks for the current /// Local playback queue. Holds the ordered list of tracks for the current
/// context (album / playlist / search result / favourites) plus a separate /// context (album / playlist / search result / favourites) plus a separate
@@ -15,259 +13,83 @@ class PlayQueue : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit PlayQueue(QObject *parent = nullptr) : QObject(parent) {} explicit PlayQueue(QObject *parent = nullptr);
// ---- Loading a new context ---- // ---- Loading a new context ----
/// Replace the queue with all tracks from an album/playlist JSON context. /// Replace the queue with all tracks from an album/playlist JSON context.
/// @param startIndex Index of the track to start playing (-1 = first). /// @param startIndex Index of the track to start playing (-1 = first).
void setContext(const QJsonArray &tracks, int startIndex = 0) void setContext(const QJsonArray &tracks, int startIndex = 0);
{
m_queue.clear();
m_playNext.clear();
// Only queue streamable tracks; find the filtered index for startIndex
int filteredStart = 0;
int filteredIdx = 0;
bool found = false;
for (int orig = 0; orig < tracks.size(); ++orig) {
const QJsonObject t = tracks[orig].toObject();
if (!t["streamable"].toBool(true))
continue;
if (!found && orig >= startIndex) {
filteredStart = filteredIdx;
found = true;
}
m_queue.append(t);
++filteredIdx;
}
m_index = qBound(0, filteredStart, qMax(0, m_queue.size() - 1));
if (m_shuffle)
shuffleQueue(m_index);
emit queueChanged();
}
// ---- Re-order after a sort (keeps m_playNext, updates m_index) ---- // ---- Re-order after a sort (keeps m_playNext, updates m_index) ----
void reorderContext(const QJsonArray &tracks, qint64 currentId) void reorderContext(const QJsonArray &tracks, qint64 currentId);
{
m_queue.clear();
for (const auto &v : tracks) {
const QJsonObject t = v.toObject();
if (t["streamable"].toBool(true))
m_queue.append(t);
}
m_index = 0;
for (int i = 0; i < m_queue.size(); ++i) {
if (static_cast<qint64>(m_queue[i]["id"].toDouble()) == currentId) {
m_index = i;
break;
}
}
emit queueChanged();
}
// ---- Clear / remove upcoming ---- // ---- Clear / remove upcoming ----
/// Remove all "up next" entries (playNext + remaining main queue after current). /// Remove all "up next" entries (playNext + remaining main queue after current).
void clearUpcoming() void clearUpcoming();
{
m_playNext.clear();
if (m_index < m_queue.size())
m_queue.resize(m_index + 1); // keep up to and including current
emit queueChanged();
}
/// Remove one upcoming track by its index in upcomingTracks(). /// Remove one upcoming track by its index in upcomingTracks().
void removeUpcoming(int upcomingIndex) void removeUpcoming(int upcomingIndex);
{
if (upcomingIndex < m_playNext.size()) {
m_playNext.removeAt(upcomingIndex);
} else {
const int queueIdx = m_index + 1 + (upcomingIndex - m_playNext.size());
if (queueIdx < m_queue.size())
m_queue.removeAt(queueIdx);
}
emit queueChanged();
}
// ---- Shuffle ---- // ---- Shuffle ----
bool shuffleEnabled() const { return m_shuffle; } bool shuffleEnabled() const { return m_shuffle; }
void setShuffle(bool enabled) void setShuffle(bool enabled);
{
if (m_shuffle == enabled) return;
m_shuffle = enabled;
if (enabled && !m_queue.isEmpty())
shuffleQueue(m_index);
emit queueChanged();
}
/// Shuffle the current queue once without changing the global shuffle flag. /// Shuffle the current queue once without changing the global shuffle flag.
void shuffleNow() void shuffleNow();
{
if (m_queue.isEmpty()) return;
shuffleQueue(m_index);
emit queueChanged();
}
// ---- Play-next prepend queue (like "Add to queue" ---- // ---- Play-next prepend queue (like "Add to queue" ----
void addToQueue(const QJsonObject &track) void addToQueue(const QJsonObject &track);
{
m_playNext.append(track);
emit queueChanged();
}
void playNext(const QJsonObject &track) void playNext(const QJsonObject &track);
{
m_playNext.prepend(track);
emit queueChanged();
}
// ---- Navigation ---- // ---- Navigation ----
bool hasCurrent() const bool hasCurrent() const;
{
return (!m_playNext.isEmpty()) || (!m_queue.isEmpty());
}
QJsonObject current() const QJsonObject current() const;
{
if (!m_playNext.isEmpty()) return m_playNext.first();
if (m_index < m_queue.size()) return m_queue.at(m_index);
return {};
}
qint64 currentId() const qint64 currentId() const;
{
return static_cast<qint64>(current()["id"].toDouble());
}
/// Advance and return the track to play next. Returns {} at end of queue. /// Advance and return the track to play next. Returns {} at end of queue.
QJsonObject advance() QJsonObject advance();
{
if (!m_playNext.isEmpty()) {
// Return the playNext item directly — do NOT call current() after
// removal, as that would fall back to the already-playing m_index track.
const QJsonObject next = m_playNext.takeFirst();
emit queueChanged();
return next;
}
++m_index;
emit queueChanged();
return current();
}
/// Step backwards in the main queue (play-next is not affected). /// Step backwards in the main queue (play-next is not affected).
QJsonObject stepBack() QJsonObject stepBack();
{
if (m_index > 0) --m_index;
emit queueChanged();
return current();
}
bool canGoNext() const bool canGoNext() const;
{
return !m_playNext.isEmpty() || (m_index + 1 < m_queue.size());
}
bool canGoPrev() const { return m_index > 0; } bool canGoPrev() const { return m_index > 0; }
// ---- Index lookup ---- // ---- Index lookup ----
/// Set the current position by track id (after user double-clicks a row). /// Set the current position by track id (after user double-clicks a row).
void setCurrentById(qint64 id) void setCurrentById(qint64 id);
{
m_playNext.clear();
for (int i = 0; i < m_queue.size(); ++i) {
if (static_cast<qint64>(m_queue[i]["id"].toDouble()) == id) {
m_index = i;
emit queueChanged();
return;
}
}
}
// ---- Accessors for queue panel ---- // ---- Accessors for queue panel ----
QVector<QJsonObject> upcomingTracks(int maxCount = 200) const QVector<QJsonObject> upcomingTracks(int maxCount = 200) const;
{
QVector<QJsonObject> result;
result.append(m_playNext);
for (int i = m_index + 1; i < m_queue.size() && result.size() < maxCount; ++i)
result.append(m_queue.at(i));
return result;
}
int playNextCount() const { return m_playNext.size(); } int playNextCount() const { return m_playNext.size(); }
int totalSize() const { return m_playNext.size() + m_queue.size(); } int totalSize() const { return m_playNext.size() + m_queue.size(); }
int currentIndex() const { return m_index; } int currentIndex() const { return m_index; }
/// Skip to upcoming[upcomingIndex]: removes everything before it, pops and returns it. /// Skip to upcoming[upcomingIndex]: removes everything before it, pops and returns it.
QJsonObject skipToUpcoming(int upcomingIndex) QJsonObject skipToUpcoming(int upcomingIndex);
{
// Remove items 0..upcomingIndex-1 from the front of upcoming
for (int i = 0; i < upcomingIndex; ++i) {
if (!m_playNext.isEmpty())
m_playNext.removeFirst();
else if (m_index + 1 < m_queue.size())
++m_index;
}
// Pop and return the target (now at upcoming[0])
if (!m_playNext.isEmpty()) {
const QJsonObject t = m_playNext.takeFirst();
emit queueChanged();
return t;
}
if (m_index + 1 < m_queue.size()) {
++m_index;
emit queueChanged();
return m_queue.at(m_index);
}
emit queueChanged();
return {};
}
/// Replace the upcoming list with a new order (used after drag-reorder in UI). /// Replace the upcoming list with a new order (used after drag-reorder in UI).
void setUpcomingOrder(const QVector<QJsonObject> &newOrder) void setUpcomingOrder(const QVector<QJsonObject> &newOrder);
{
m_playNext = newOrder;
m_queue.resize(m_index + 1); // drop old main-queue tail
emit queueChanged();
}
/// Append tracks to the main queue tail (autoplay/discovery). /// Append tracks to the main queue tail (autoplay/discovery).
void appendToContext(const QJsonArray &tracks) void appendToContext(const QJsonArray &tracks);
{
for (const auto &v : tracks) {
const QJsonObject t = v.toObject();
if (t["streamable"].toBool(true))
m_queue.append(t);
}
emit queueChanged();
}
/// Move an upcoming item (by its index in upcomingTracks()) to the front of playNext. /// Move an upcoming item (by its index in upcomingTracks()) to the front of playNext.
void moveUpcomingToTop(int upcomingIndex) void moveUpcomingToTop(int upcomingIndex);
{
if (upcomingIndex < 0) return;
QJsonObject track;
if (upcomingIndex < m_playNext.size()) {
if (upcomingIndex == 0) return; // already at top
track = m_playNext.takeAt(upcomingIndex);
} else {
const int queueIdx = m_index + 1 + (upcomingIndex - m_playNext.size());
if (queueIdx >= m_queue.size()) return;
track = m_queue.takeAt(queueIdx);
}
m_playNext.prepend(track);
emit queueChanged();
}
signals: signals:
void queueChanged(); void queueChanged();
@@ -278,19 +100,5 @@ private:
int m_index = 0; int m_index = 0;
bool m_shuffle = false; bool m_shuffle = false;
void shuffleQueue(int keepAtFront) void shuffleQueue(int keepAtFront);
{
if (m_queue.isEmpty()) return;
// Keep the current track at index 0 of the remaining queue
if (keepAtFront >= 0 && keepAtFront < m_queue.size()) {
QJsonObject current = m_queue.takeAt(keepAtFront);
std::mt19937 rng(std::random_device{}());
std::shuffle(m_queue.begin(), m_queue.end(), rng);
m_queue.prepend(current);
} else {
std::mt19937 rng(std::random_device{}());
std::shuffle(m_queue.begin(), m_queue.end(), rng);
}
m_index = 0;
}
}; };

32
src/util/colors.hpp Normal file
View File

@@ -0,0 +1,32 @@
#pragma once
#include <QColor>
namespace Colors {
// Brand accents
inline const QColor QobuzOrange{0xFF, 0xB2, 0x32};
inline const QColor QobuzBlue {0x46, 0xB3, 0xEE};
// Badge / indicator colors used in tree-view item foregrounds
inline const QColor BadgeGreen {QStringLiteral("#2FA84F")};
inline const QColor BadgeBlue {QStringLiteral("#2B7CD3")};
inline const QColor BadgeGray {QStringLiteral("#8E8E93")};
// Text
inline const QColor LightText {0xe8, 0xe8, 0xe8};
inline const QColor SubduedText {0xaa, 0xaa, 0xaa};
inline const QColor PlaceholderText{0x66, 0x66, 0x66};
inline const QColor DisabledText {0x55, 0x55, 0x55};
// Surfaces / backgrounds
inline const QColor WindowBg {0x19, 0x19, 0x19};
inline const QColor BaseBg {0x14, 0x14, 0x14};
inline const QColor AlternateBaseBg{0x1e, 0x1e, 0x1e};
inline const QColor ButtonSurface {0x2a, 0x2a, 0x2a};
inline const QColor ContextBg {0x1a, 0x1a, 0x1a};
inline const QColor MidSurface {0x2f, 0x2f, 0x2f};
inline const QColor DarkSurface {0x0e, 0x0e, 0x0e};
inline const QColor HighlightedFg {0x10, 0x10, 0x10};
} // namespace Colors

View File

@@ -1,5 +1,7 @@
#pragma once #pragma once
#include "../util/colors.hpp"
#include <QTreeWidget> #include <QTreeWidget>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <QHeaderView> #include <QHeaderView>
@@ -89,7 +91,7 @@ public:
auto *item = new QTreeWidgetItem(this); auto *item = new QTreeWidgetItem(this);
if (hiRes) { if (hiRes) {
item->setText(0, QStringLiteral("H")); item->setText(0, QStringLiteral("H"));
item->setForeground(0, QColor(QStringLiteral("#FFB232"))); item->setForeground(0, Colors::QobuzOrange);
item->setFont(0, hiResFont); item->setFont(0, hiResFont);
item->setTextAlignment(0, Qt::AlignCenter); item->setTextAlignment(0, Qt::AlignCenter);
} }

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include "../../backend/qobuzbackend.hpp" #include "../../backend/qobuzbackend.hpp"
#include "../../util/colors.hpp"
#include <QDockWidget> #include <QDockWidget>
#include <QWidget> #include <QWidget>
@@ -32,11 +33,11 @@ namespace Context
{ {
QPainter p(this); QPainter p(this);
if (m_pix.isNull()) { if (m_pix.isNull()) {
p.fillRect(rect(), QColor(0x1a, 0x1a, 0x1a)); p.fillRect(rect(), Colors::ContextBg);
return; return;
} }
const QPixmap scaled = m_pix.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation); const QPixmap scaled = m_pix.scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
p.fillRect(rect(), QColor(0x1a, 0x1a, 0x1a)); p.fillRect(rect(), Colors::ContextBg);
p.drawPixmap((width() - scaled.width()) / 2, p.drawPixmap((width() - scaled.width()) / 2,
(height() - scaled.height()) / 2, (height() - scaled.height()) / 2,
scaled); scaled);

View File

@@ -1,4 +1,5 @@
#include "genrebrowser.hpp" #include "genrebrowser.hpp"
#include "../util/colors.hpp"
#include <QAction> #include <QAction>
#include <QDialog> #include <QDialog>
@@ -9,7 +10,9 @@
#include <QListWidget> #include <QListWidget>
#include <QMenu> #include <QMenu>
#include <QPushButton> #include <QPushButton>
#include <QScrollBar>
#include <QSignalBlocker> #include <QSignalBlocker>
#include <QTimer>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
#include <QVBoxLayout> #include <QVBoxLayout>
@@ -120,8 +123,18 @@ GenreBrowserView::GenreBrowserView(QobuzBackend *backend, PlayQueue *queue, QWid
m_playlistList->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents); m_playlistList->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
m_playlistList->header()->setStretchLastSection(false); m_playlistList->header()->setStretchLastSection(false);
auto *playlistPage = new QWidget(this);
auto *playlistPageLayout = new QVBoxLayout(playlistPage);
playlistPageLayout->setContentsMargins(0, 0, 0, 0);
playlistPageLayout->setSpacing(0);
playlistPageLayout->addWidget(m_playlistList, 1);
m_loadMorePlaylistsBtn = new QPushButton(tr("Load more playlists…"), this);
m_loadMorePlaylistsBtn->hide();
playlistPageLayout->addWidget(m_loadMorePlaylistsBtn);
m_resultsStack->addWidget(m_albumList); m_resultsStack->addWidget(m_albumList);
m_resultsStack->addWidget(m_playlistList); m_resultsStack->addWidget(playlistPage);
layout->addWidget(m_resultsStack, 1); layout->addWidget(m_resultsStack, 1);
connect(m_backend, &QobuzBackend::genresLoaded, connect(m_backend, &QobuzBackend::genresLoaded,
@@ -180,6 +193,12 @@ GenreBrowserView::GenreBrowserView(QobuzBackend *backend, PlayQueue *queue, QWid
this, &GenreBrowserView::onAlbumScroll); this, &GenreBrowserView::onAlbumScroll);
connect(m_playlistList->verticalScrollBar(), &QScrollBar::valueChanged, connect(m_playlistList->verticalScrollBar(), &QScrollBar::valueChanged,
this, &GenreBrowserView::onPlaylistScroll); this, &GenreBrowserView::onPlaylistScroll);
connect(m_loadMorePlaylistsBtn, &QPushButton::clicked, this, [this] {
m_loadMorePlaylistsBtn->hide();
requestPlaylistsPage(m_lastPlaylistGenreIds, m_lastPlaylistType,
m_lastPlaylistTags, m_lastPlaylistQuery,
m_playlistOffset, true);
});
m_kindCombo->setCurrentIndex(0); m_kindCombo->setCurrentIndex(0);
refreshModeUi(); refreshModeUi();
@@ -391,9 +410,12 @@ void GenreBrowserView::onFeaturedAlbumsLoaded(const QJsonObject &result)
} }
// If the viewport is not scrollable yet, eagerly fetch more pages. // If the viewport is not scrollable yet, eagerly fetch more pages.
// Deferred: the scrollbar maximum isn't updated until after layout runs.
QTimer::singleShot(0, this, [this] {
QScrollBar *bar = m_albumList->verticalScrollBar(); QScrollBar *bar = m_albumList->verticalScrollBar();
if (bar && bar->maximum() == 0 && m_albumOffset < m_albumTotal) if (bar && bar->maximum() == 0 && m_albumOffset < m_albumTotal)
requestAlbumsPage(m_lastAlbumGenreIds, m_lastAlbumType, m_albumOffset, true); requestAlbumsPage(m_lastAlbumGenreIds, m_lastAlbumType, m_albumOffset, true);
});
} }
void GenreBrowserView::onFeaturedPlaylistsLoaded(const QJsonObject &result) void GenreBrowserView::onFeaturedPlaylistsLoaded(const QJsonObject &result)
@@ -413,9 +435,11 @@ void GenreBrowserView::onFeaturedPlaylistsLoaded(const QJsonObject &result)
m_playlistTotal = m_playlistOffset; m_playlistTotal = m_playlistOffset;
m_loadingPlaylists = false; m_loadingPlaylists = false;
QTimer::singleShot(0, this, [this] {
QScrollBar *bar = m_playlistList->verticalScrollBar(); QScrollBar *bar = m_playlistList->verticalScrollBar();
if (bar && bar->maximum() == 0 && m_playlistOffset < m_playlistTotal) if (bar && bar->maximum() == 0 && m_playlistOffset < m_playlistTotal)
requestPlaylistsPage(m_lastPlaylistGenreIds, m_lastPlaylistType, m_lastPlaylistTags, m_lastPlaylistQuery, m_playlistOffset, true); requestPlaylistsPage(m_lastPlaylistGenreIds, m_lastPlaylistType, m_lastPlaylistTags, m_lastPlaylistQuery, m_playlistOffset, true);
});
} }
void GenreBrowserView::onDiscoverPlaylistsLoaded(const QJsonObject &result) void GenreBrowserView::onDiscoverPlaylistsLoaded(const QJsonObject &result)
@@ -435,9 +459,11 @@ void GenreBrowserView::onDiscoverPlaylistsLoaded(const QJsonObject &result)
m_playlistTotal = m_playlistOffset; m_playlistTotal = m_playlistOffset;
m_loadingPlaylists = false; m_loadingPlaylists = false;
QTimer::singleShot(0, this, [this] {
QScrollBar *bar = m_playlistList->verticalScrollBar(); QScrollBar *bar = m_playlistList->verticalScrollBar();
if (bar && bar->maximum() == 0 && m_playlistOffset < m_playlistTotal) if (bar && bar->maximum() == 0 && m_playlistOffset < m_playlistTotal)
requestPlaylistsPage(m_lastPlaylistGenreIds, m_lastPlaylistType, m_lastPlaylistTags, m_lastPlaylistQuery, m_playlistOffset, true); requestPlaylistsPage(m_lastPlaylistGenreIds, m_lastPlaylistType, m_lastPlaylistTags, m_lastPlaylistQuery, m_playlistOffset, true);
});
} }
void GenreBrowserView::onPlaylistSearchLoaded(const QJsonObject &result) void GenreBrowserView::onPlaylistSearchLoaded(const QJsonObject &result)
@@ -456,9 +482,25 @@ void GenreBrowserView::onPlaylistSearchLoaded(const QJsonObject &result)
m_playlistTotal = m_playlistOffset; m_playlistTotal = m_playlistOffset;
m_loadingPlaylists = false; m_loadingPlaylists = false;
// Eagerly fill the viewport, then switch to a manual "Load more" button.
if (m_playlistOffset >= m_playlistTotal) {
m_loadMorePlaylistsBtn->hide();
m_searchViewportFilled = true;
} else if (!m_searchViewportFilled) {
QTimer::singleShot(0, this, [this] {
QScrollBar *bar = m_playlistList->verticalScrollBar(); QScrollBar *bar = m_playlistList->verticalScrollBar();
if (bar && bar->maximum() == 0 && m_playlistOffset < m_playlistTotal) if (bar && bar->maximum() == 0 && m_playlistOffset < m_playlistTotal) {
requestPlaylistsPage(m_lastPlaylistGenreIds, m_lastPlaylistType, m_lastPlaylistTags, m_lastPlaylistQuery, m_playlistOffset, true); requestPlaylistsPage(m_lastPlaylistGenreIds, m_lastPlaylistType,
m_lastPlaylistTags, m_lastPlaylistQuery,
m_playlistOffset, true);
} else {
m_searchViewportFilled = true;
m_loadMorePlaylistsBtn->setVisible(m_playlistOffset < m_playlistTotal);
}
});
} else {
m_loadMorePlaylistsBtn->setVisible(true);
}
} }
void GenreBrowserView::onSelectionChanged() void GenreBrowserView::onSelectionChanged()
@@ -571,6 +613,9 @@ void GenreBrowserView::requestPlaylistsPage(const QString &genreIds, const QStri
m_loadingPlaylists = false; m_loadingPlaylists = false;
m_playlistOffset = 0; m_playlistOffset = 0;
m_playlistTotal = 0; m_playlistTotal = 0;
m_loadMorePlaylistsBtn->hide();
if (type == QStringLiteral("search"))
m_searchViewportFilled = false;
} }
m_lastPlaylistGenreIds = genreIds; m_lastPlaylistGenreIds = genreIds;
@@ -580,7 +625,7 @@ void GenreBrowserView::requestPlaylistsPage(const QString &genreIds, const QStri
m_loadingPlaylists = true; m_loadingPlaylists = true;
if (type == QStringLiteral("search")) { if (type == QStringLiteral("search")) {
m_backend->searchPlaylists(query, 8, static_cast<quint32>(offset)); m_backend->searchPlaylists(query, 25, static_cast<quint32>(offset));
} else if (type.startsWith(QStringLiteral("discover-"))) { } else if (type.startsWith(QStringLiteral("discover-"))) {
m_backend->discoverPlaylists(genreIds, tags, 25, static_cast<quint32>(offset)); m_backend->discoverPlaylists(genreIds, tags, 25, static_cast<quint32>(offset));
} else { } else {
@@ -608,6 +653,9 @@ void GenreBrowserView::onAlbumScroll(int value)
void GenreBrowserView::onPlaylistScroll(int value) void GenreBrowserView::onPlaylistScroll(int value)
{ {
// Search results use a manual "Load more" button instead of infinite scroll.
if (m_lastPlaylistType == QStringLiteral("search"))
return;
if (m_loadingPlaylists) if (m_loadingPlaylists)
return; return;
if (m_playlistOffset >= m_playlistTotal) if (m_playlistOffset >= m_playlistTotal)
@@ -675,16 +723,28 @@ void GenreBrowserView::onAlbumContextMenu(const QPoint &pos)
const QString albumId = item->data(1, Qt::UserRole).toString(); const QString albumId = item->data(1, Qt::UserRole).toString();
const qint64 artistId = item->data(2, Qt::UserRole).toLongLong(); const qint64 artistId = item->data(2, Qt::UserRole).toLongLong();
const QString albumTitle = item->text(1);
const QString artistName = item->text(2);
QMenu menu(this); QMenu menu(this);
auto *openAlbum = menu.addAction(tr("Open Album")); auto *openAlbum = menu.addAction(
QIcon(":/res/icons/view-media-album-cover.svg"),
tr("Open album: %1").arg(QString(albumTitle).replace(QLatin1Char('&'), QStringLiteral("&&"))));
connect(openAlbum, &QAction::triggered, this, [this, albumId] { connect(openAlbum, &QAction::triggered, this, [this, albumId] {
emit albumSelected(albumId); emit albumSelected(albumId);
}); });
auto *addFav = menu.addAction(QIcon(":/res/icons/starred-symbolic.svg"), tr("Add to favorites"));
connect(addFav, &QAction::triggered, this, [this, albumId] {
m_backend->addFavAlbum(albumId);
});
if (artistId > 0) { if (artistId > 0) {
auto *openArtist = menu.addAction(tr("Open Artist")); menu.addSeparator();
auto *openArtist = menu.addAction(
QIcon(":/res/icons/view-media-artist.svg"),
tr("Open artist: %1").arg(QString(artistName).replace(QLatin1Char('&'), QStringLiteral("&&"))));
connect(openArtist, &QAction::triggered, this, [this, artistId] { connect(openArtist, &QAction::triggered, this, [this, artistId] {
emit artistSelected(artistId); emit artistSelected(artistId);
}); });
@@ -714,7 +774,8 @@ void GenreBrowserView::onPlaylistContextMenu(const QPoint &pos)
return; return;
QMenu menu(this); QMenu menu(this);
auto *openPlaylist = menu.addAction(tr("Open Playlist")); auto *openPlaylist = menu.addAction(
QIcon(":/res/icons/view-media-playlist.svg"), tr("Open playlist"));
connect(openPlaylist, &QAction::triggered, this, [this, playlistId] { connect(openPlaylist, &QAction::triggered, this, [this, playlistId] {
emit playlistSelected(playlistId); emit playlistSelected(playlistId);
}); });
@@ -740,7 +801,7 @@ void GenreBrowserView::setPlaylistItems(const QJsonArray &items, bool append)
auto *item = new QTreeWidgetItem(m_playlistList, auto *item = new QTreeWidgetItem(m_playlistList,
QStringList{QStringLiteral("P"), name, owner, tracksCount > 0 ? QString::number(tracksCount) : QString()}); QStringList{QStringLiteral("P"), name, owner, tracksCount > 0 ? QString::number(tracksCount) : QString()});
item->setData(0, Qt::UserRole, playlistId); item->setData(0, Qt::UserRole, playlistId);
item->setForeground(0, QColor(QStringLiteral("#2B7CD3"))); item->setForeground(0, Colors::BadgeBlue);
item->setFont(0, tagFont); item->setFont(0, tagFont);
item->setTextAlignment(0, Qt::AlignCenter); item->setTextAlignment(0, Qt::AlignCenter);
} }

View File

@@ -70,6 +70,8 @@ private:
QStackedWidget *m_resultsStack = nullptr; QStackedWidget *m_resultsStack = nullptr;
AlbumListView *m_albumList = nullptr; AlbumListView *m_albumList = nullptr;
QTreeWidget *m_playlistList = nullptr; QTreeWidget *m_playlistList = nullptr;
QPushButton *m_loadMorePlaylistsBtn = nullptr;
bool m_searchViewportFilled = false;
BrowseMode m_mode = BrowseMode::Genres; BrowseMode m_mode = BrowseMode::Genres;
bool m_genresLoaded = false; bool m_genresLoaded = false;
int m_lastGenreComboIndex = 0; int m_lastGenreComboIndex = 0;

View File

@@ -61,14 +61,14 @@ MainContent::MainContent(QobuzBackend *backend, PlayQueue *queue, QWidget *paren
m_artistView = new ArtistView(backend, queue, this); m_artistView = new ArtistView(backend, queue, this);
m_genreBrowser = new GenreBrowserView(backend, queue, this); m_genreBrowser = new GenreBrowserView(backend, queue, this);
m_stack->addWidget(m_welcome); // 0 m_stack->addWidget(m_welcome); // PageWelcome
m_stack->addWidget(tracksPage); // 1 m_stack->addWidget(tracksPage); // PageTracks
m_stack->addWidget(m_albumList); // 2 m_stack->addWidget(m_albumList); // PageAlbumList
m_stack->addWidget(m_artistList); // 3 m_stack->addWidget(m_artistList); // PageArtistList
m_stack->addWidget(m_artistView); // 4 m_stack->addWidget(m_artistView); // PageArtistDetail
m_stack->addWidget(m_genreBrowser); // 5 m_stack->addWidget(m_genreBrowser); // PageGenreBrowser
m_stack->setCurrentIndex(0); m_stack->setCurrentIndex(PageWelcome);
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);
@@ -80,7 +80,7 @@ MainContent::MainContent(QobuzBackend *backend, PlayQueue *queue, QWidget *paren
connect(m_genreBrowser, &GenreBrowserView::playTrackRequested, this, &MainContent::playTrackRequested); connect(m_genreBrowser, &GenreBrowserView::playTrackRequested, this, &MainContent::playTrackRequested);
} }
void MainContent::showWelcome() { m_stack->setCurrentIndex(0); } void MainContent::showWelcome() { m_stack->setCurrentIndex(PageWelcome); }
void MainContent::showAlbum(const QJsonObject &album) void MainContent::showAlbum(const QJsonObject &album)
{ {
@@ -89,46 +89,46 @@ void MainContent::showAlbum(const QJsonObject &album)
albumId = QString::number(static_cast<qint64>(album["id"].toDouble())); albumId = QString::number(static_cast<qint64>(album["id"].toDouble()));
m_header->setAlbum(album, m_favAlbumIds.contains(albumId)); m_header->setAlbum(album, m_favAlbumIds.contains(albumId));
m_tracks->loadAlbum(album); m_tracks->loadAlbum(album);
m_stack->setCurrentIndex(1); m_stack->setCurrentIndex(PageTracks);
} }
void MainContent::showPlaylist(const QJsonObject &playlist, bool isFollowed, bool isOwned) void MainContent::showPlaylist(const QJsonObject &playlist, bool isFollowed, bool isOwned)
{ {
m_header->setPlaylist(playlist, isFollowed, isOwned); m_header->setPlaylist(playlist, isFollowed, isOwned);
m_tracks->loadPlaylist(playlist); m_tracks->loadPlaylist(playlist);
m_stack->setCurrentIndex(1); m_stack->setCurrentIndex(PageTracks);
} }
void MainContent::showFavTracks(const QJsonObject &result) void MainContent::showFavTracks(const QJsonObject &result)
{ {
m_header->hide(); m_header->hide();
m_tracks->loadTracks(result["items"].toArray()); m_tracks->loadTracks(result["items"].toArray());
m_stack->setCurrentIndex(1); m_stack->setCurrentIndex(PageTracks);
} }
void MainContent::showSearchTracks(const QJsonArray &tracks) void MainContent::showSearchTracks(const QJsonArray &tracks)
{ {
m_header->hide(); m_header->hide();
m_tracks->loadSearchTracks(tracks); m_tracks->loadSearchTracks(tracks);
m_stack->setCurrentIndex(1); m_stack->setCurrentIndex(PageTracks);
} }
void MainContent::showFavAlbums(const QJsonObject &result) void MainContent::showFavAlbums(const QJsonObject &result)
{ {
m_albumList->setAlbums(result["items"].toArray()); m_albumList->setAlbums(result["items"].toArray());
m_stack->setCurrentIndex(2); m_stack->setCurrentIndex(PageAlbumList);
} }
void MainContent::showFavArtists(const QJsonObject &result) void MainContent::showFavArtists(const QJsonObject &result)
{ {
m_artistList->setArtists(result["items"].toArray()); m_artistList->setArtists(result["items"].toArray());
m_stack->setCurrentIndex(3); m_stack->setCurrentIndex(PageArtistList);
} }
void MainContent::showArtist(const QJsonObject &artist) void MainContent::showArtist(const QJsonObject &artist)
{ {
m_artistView->setArtist(artist); m_artistView->setArtist(artist);
m_stack->setCurrentIndex(4); m_stack->setCurrentIndex(PageArtistDetail);
} }
void MainContent::updateArtistReleases(const QString &releaseType, const QJsonArray &items, bool hasMore, int offset) void MainContent::updateArtistReleases(const QString &releaseType, const QJsonArray &items, bool hasMore, int offset)
@@ -160,14 +160,14 @@ void MainContent::showGenreBrowser()
{ {
m_genreBrowser->ensureGenresLoaded(); m_genreBrowser->ensureGenresLoaded();
m_genreBrowser->setBrowseMode(GenreBrowserView::BrowseMode::Genres); m_genreBrowser->setBrowseMode(GenreBrowserView::BrowseMode::Genres);
m_stack->setCurrentIndex(5); m_stack->setCurrentIndex(PageGenreBrowser);
} }
void MainContent::showPlaylistBrowser() void MainContent::showPlaylistBrowser()
{ {
m_genreBrowser->ensureGenresLoaded(); m_genreBrowser->ensureGenresLoaded();
m_genreBrowser->setBrowseMode(GenreBrowserView::BrowseMode::PlaylistSearch); m_genreBrowser->setBrowseMode(GenreBrowserView::BrowseMode::PlaylistSearch);
m_stack->setCurrentIndex(5); m_stack->setCurrentIndex(PageGenreBrowser);
} }
void MainContent::setCurrentPlaylistFollowed(bool followed) void MainContent::setCurrentPlaylistFollowed(bool followed)

View File

@@ -52,6 +52,15 @@ signals:
void playTrackRequested(qint64 trackId); void playTrackRequested(qint64 trackId);
private: private:
enum StackPage {
PageWelcome = 0,
PageTracks = 1,
PageAlbumList = 2,
PageArtistList = 3,
PageArtistDetail = 4,
PageGenreBrowser = 5,
};
QobuzBackend *m_backend = nullptr; QobuzBackend *m_backend = nullptr;
QStackedWidget *m_stack = nullptr; QStackedWidget *m_stack = nullptr;
QLabel *m_welcome = nullptr; QLabel *m_welcome = nullptr;

View File

@@ -41,15 +41,62 @@ MainToolBar::MainToolBar(QobuzBackend *backend, PlayQueue *queue, QWidget *paren
connect(m_trackLabel, &QLabel::customContextMenuRequested, connect(m_trackLabel, &QLabel::customContextMenuRequested,
this, [this](const QPoint &pos) { this, [this](const QPoint &pos) {
if (m_currentTrack.isEmpty()) return; if (m_currentTrack.isEmpty()) return;
QMenu menu(this);
const qint64 trackId = static_cast<qint64>(m_currentTrack["id"].toDouble());
const QString albumId = m_currentTrack["album"].toObject()["id"].toString(); const QString albumId = m_currentTrack["album"].toObject()["id"].toString();
const QString albumTitle = m_currentTrack["album"].toObject()["title"].toString();
const qint64 artistId = static_cast<qint64>( const qint64 artistId = static_cast<qint64>(
m_currentTrack["performer"].toObject()["id"].toDouble()); m_currentTrack["performer"].toObject()["id"].toDouble());
if (!albumId.isEmpty()) const QString artistName = m_currentTrack["performer"].toObject()["name"].toString();
menu.addAction(tr("Go to Album"), this, [this, albumId] { emit albumRequested(albumId); });
if (artistId > 0) QMenu menu(this);
menu.addAction(tr("Go to Artist"), this, [this, artistId] { emit artistRequested(artistId); });
if (!menu.isEmpty()) auto *playNext = menu.addAction(QIcon(":/res/icons/media-skip-forward.svg"), tr("Play next"));
auto *addQueue = menu.addAction(QIcon(":/res/icons/media-playlist-append.svg"), tr("Add to queue"));
menu.addSeparator();
auto *addFav = menu.addAction(QIcon(":/res/icons/starred-symbolic.svg"), tr("Add to favorites"));
connect(addFav, &QAction::triggered, this, [this, trackId] {
emit favTrackRequested(trackId);
});
if (!albumId.isEmpty() || artistId > 0)
menu.addSeparator();
if (!albumId.isEmpty()) {
auto *openAlbum = menu.addAction(
QIcon(":/res/icons/view-media-album-cover.svg"),
tr("Open album: %1").arg(QString(albumTitle).replace(QLatin1Char('&'), QStringLiteral("&&"))));
connect(openAlbum, &QAction::triggered, this, [this, albumId] {
emit albumRequested(albumId);
});
}
if (artistId > 0) {
auto *openArtist = menu.addAction(
QIcon(":/res/icons/view-media-artist.svg"),
tr("Open artist: %1").arg(QString(artistName).replace(QLatin1Char('&'), QStringLiteral("&&"))));
connect(openArtist, &QAction::triggered, this, [this, artistId] {
emit artistRequested(artistId);
});
}
if (!m_userPlaylists.isEmpty()) {
menu.addSeparator();
auto *plMenu = menu.addMenu(QIcon(":/res/icons/media-playlist-append.svg"), tr("Add to playlist"));
for (const auto &pl : m_userPlaylists) {
auto *act = plMenu->addAction(QString(pl.second).replace(QLatin1Char('&'), QStringLiteral("&&")));
connect(act, &QAction::triggered, this, [this, trackId, plId = pl.first] {
emit addToPlaylistRequested(trackId, plId);
});
}
}
connect(playNext, &QAction::triggered, this, [this] {
m_queue->playNext(m_currentTrack);
});
connect(addQueue, &QAction::triggered, this, [this] {
m_queue->addToQueue(m_currentTrack);
});
menu.exec(m_trackLabel->mapToGlobal(pos)); menu.exec(m_trackLabel->mapToGlobal(pos));
}); });

View File

@@ -12,6 +12,7 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkReply> #include <QNetworkReply>
#include <QJsonObject> #include <QJsonObject>
#include <QPair>
#include <QVector> #include <QVector>
class MainToolBar : public QToolBar class MainToolBar : public QToolBar
@@ -27,11 +28,15 @@ public:
void setQueueToggleChecked(bool checked); void setQueueToggleChecked(bool checked);
void setSearchToggleChecked(bool checked); void setSearchToggleChecked(bool checked);
void setUserPlaylists(const QVector<QPair<qint64, QString>> &playlists) { m_userPlaylists = playlists; }
signals: signals:
void searchToggled(bool visible); void searchToggled(bool visible);
void queueToggled(bool visible); void queueToggled(bool visible);
void albumRequested(const QString &albumId); void albumRequested(const QString &albumId);
void artistRequested(qint64 artistId); void artistRequested(qint64 artistId);
void addToPlaylistRequested(qint64 trackId, qint64 playlistId);
void favTrackRequested(qint64 trackId);
protected: protected:
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
@@ -93,5 +98,7 @@ private:
qint64 m_pendingSeekStartedMs = 0; qint64 m_pendingSeekStartedMs = 0;
bool m_fetchingAutoplay = false; bool m_fetchingAutoplay = false;
QVector<QPair<qint64, QString>> m_userPlaylists;
void requestAutoplaySuggestions(); void requestAutoplaySuggestions();
}; };

View File

@@ -225,8 +225,8 @@ void QueuePanel::onContextMenu(const QPoint &pos)
const int idx = item->data(UpcomingIndexRole).toInt(); const int idx = item->data(UpcomingIndexRole).toInt();
QMenu menu(this); QMenu menu(this);
auto *removeAct = menu.addAction(tr("Remove from queue")); auto *removeAct = menu.addAction(QIcon(":/res/icons/list-remove.svg"), tr("Remove from queue"));
auto *toTopAct = menu.addAction(tr("Move to top (play next)")); auto *toTopAct = menu.addAction(QIcon(":/res/icons/go-up.svg"), tr("Move to top (play next)"));
connect(removeAct, &QAction::triggered, this, [this, idx] { m_queue->removeUpcoming(idx); }); connect(removeAct, &QAction::triggered, this, [this, idx] { m_queue->removeUpcoming(idx); });
connect(toTopAct, &QAction::triggered, this, [this, idx] { m_queue->moveUpcomingToTop(idx); }); connect(toTopAct, &QAction::triggered, this, [this, idx] { m_queue->moveUpcomingToTop(idx); });

View File

@@ -1,4 +1,5 @@
#include "view.hpp" #include "view.hpp"
#include "../../util/colors.hpp"
#include "../../util/trackinfo.hpp" #include "../../util/trackinfo.hpp"
#include <QVBoxLayout> #include <QVBoxLayout>
@@ -125,7 +126,7 @@ void SearchTab::onMostPopularResult(const QJsonObject &result)
const QString artist = content["performer"].toObject()["name"].toString(); const QString artist = content["performer"].toObject()["name"].toString();
const QString album = content["album"].toObject()["title"].toString(); const QString album = content["album"].toObject()["title"].toString();
item->setText(0, QStringLiteral("T")); item->setText(0, QStringLiteral("T"));
item->setForeground(0, QColor(QStringLiteral("#2FA84F"))); item->setForeground(0, Colors::BadgeGreen);
item->setFont(0, badgeFont); item->setFont(0, badgeFont);
item->setTextAlignment(0, Qt::AlignCenter); item->setTextAlignment(0, Qt::AlignCenter);
item->setText(1, title); item->setText(1, title);
@@ -139,8 +140,8 @@ void SearchTab::onMostPopularResult(const QJsonObject &result)
|| content["rights"].toObject()["hires_streamable"].toBool(); || content["rights"].toObject()["hires_streamable"].toBool();
item->setText(0, hiRes ? QStringLiteral("H") : QStringLiteral("A")); item->setText(0, hiRes ? QStringLiteral("H") : QStringLiteral("A"));
item->setForeground(0, hiRes item->setForeground(0, hiRes
? QColor(QStringLiteral("#FFB232")) ? Colors::QobuzOrange
: QColor(QStringLiteral("#8E8E93"))); : Colors::BadgeGray);
item->setFont(0, badgeFont); item->setFont(0, badgeFont);
item->setTextAlignment(0, Qt::AlignCenter); item->setTextAlignment(0, Qt::AlignCenter);
item->setText(1, title); item->setText(1, title);
@@ -149,7 +150,7 @@ void SearchTab::onMostPopularResult(const QJsonObject &result)
item->setData(1, IdRole, content["id"].toString()); item->setData(1, IdRole, content["id"].toString());
} else if (type == QStringLiteral("artists")) { } else if (type == QStringLiteral("artists")) {
item->setText(0, QStringLiteral("A")); item->setText(0, QStringLiteral("A"));
item->setForeground(0, QColor(QStringLiteral("#2B7CD3"))); item->setForeground(0, Colors::BadgeBlue);
item->setFont(0, badgeFont); item->setFont(0, badgeFont);
item->setTextAlignment(0, Qt::AlignCenter); item->setTextAlignment(0, Qt::AlignCenter);
item->setText(1, content["name"].toString()); item->setText(1, content["name"].toString());
@@ -193,7 +194,7 @@ void SearchTab::onSearchResult(const QJsonObject &result)
QStringList{QString(), a["title"].toString(), artist}); QStringList{QString(), a["title"].toString(), artist});
if (hiRes) { if (hiRes) {
item->setText(0, QStringLiteral("H")); item->setText(0, QStringLiteral("H"));
item->setForeground(0, QColor(QStringLiteral("#FFB232"))); item->setForeground(0, Colors::QobuzOrange);
item->setFont(0, hiResFont); item->setFont(0, hiResFont);
item->setTextAlignment(0, Qt::AlignCenter); item->setTextAlignment(0, Qt::AlignCenter);
} }
@@ -240,12 +241,15 @@ void SearchTab::onTrackContextMenu(const QPoint &pos)
QMenu menu(this); QMenu menu(this);
auto *playNow = menu.addAction(tr("Play now")); auto *playNow = menu.addAction(QIcon(":/res/icons/media-playback-start.svg"), tr("Play now"));
auto *playNext = menu.addAction(tr("Play next")); auto *playNext = menu.addAction(QIcon(":/res/icons/media-skip-forward.svg"), tr("Play next"));
auto *addQueue = menu.addAction(tr("Add to queue")); auto *addQueue = menu.addAction(QIcon(":/res/icons/media-playlist-append.svg"), tr("Add to queue"));
menu.addSeparator(); menu.addSeparator();
auto *addFav = menu.addAction(tr("Add to favorites")); auto *favAction = menu.addAction(QIcon(":/res/icons/starred-symbolic.svg"), tr("Add to favorites"));
connect(favAction, &QAction::triggered, this, [this, trackId] {
m_backend->addFavTrack(trackId);
});
// Open album / artist // Open album / artist
const QString albumId = trackJson["album"].toObject()["id"].toString(); const QString albumId = trackJson["album"].toObject()["id"].toString();
@@ -254,15 +258,20 @@ void SearchTab::onTrackContextMenu(const QPoint &pos)
const QString artistName = trackJson["performer"].toObject()["name"].toString(); const QString artistName = trackJson["performer"].toObject()["name"].toString();
const QString albumTitle = trackJson["album"].toObject()["title"].toString(); const QString albumTitle = trackJson["album"].toObject()["title"].toString();
if (!albumId.isEmpty() || artistId > 0)
menu.addSeparator(); menu.addSeparator();
if (!albumId.isEmpty()) { if (!albumId.isEmpty()) {
auto *openAlbum = menu.addAction(tr("Go to album: %1").arg(QString(albumTitle).replace(QLatin1Char('&'), QStringLiteral("&&")))); auto *openAlbum = menu.addAction(
QIcon(":/res/icons/view-media-album-cover.svg"),
tr("Open album: %1").arg(QString(albumTitle).replace(QLatin1Char('&'), QStringLiteral("&&"))));
connect(openAlbum, &QAction::triggered, this, [this, albumId] { connect(openAlbum, &QAction::triggered, this, [this, albumId] {
emit albumSelected(albumId); emit albumSelected(albumId);
}); });
} }
if (artistId > 0) { if (artistId > 0) {
auto *openArtist = menu.addAction(tr("Go to artist: %1").arg(QString(artistName).replace(QLatin1Char('&'), QStringLiteral("&&")))); auto *openArtist = menu.addAction(
QIcon(":/res/icons/view-media-artist.svg"),
tr("Open artist: %1").arg(QString(artistName).replace(QLatin1Char('&'), QStringLiteral("&&"))));
connect(openArtist, &QAction::triggered, this, [this, artistId] { connect(openArtist, &QAction::triggered, this, [this, artistId] {
emit artistSelected(artistId); emit artistSelected(artistId);
}); });
@@ -271,9 +280,9 @@ void SearchTab::onTrackContextMenu(const QPoint &pos)
// Add to playlist submenu // Add to playlist submenu
if (!m_userPlaylists.isEmpty()) { if (!m_userPlaylists.isEmpty()) {
menu.addSeparator(); menu.addSeparator();
auto *plMenu = menu.addMenu(tr("Add to playlist")); auto *plMenu = menu.addMenu(QIcon(":/res/icons/media-playlist-append.svg"), tr("Add to playlist"));
for (const auto &pl : m_userPlaylists) { for (const auto &pl : m_userPlaylists) {
auto *act = plMenu->addAction(pl.second); auto *act = plMenu->addAction(QString(pl.second).replace(QLatin1Char('&'), QStringLiteral("&&")));
connect(act, &QAction::triggered, this, [this, trackId, plId = pl.first] { connect(act, &QAction::triggered, this, [this, trackId, plId = pl.first] {
emit addToPlaylistRequested(trackId, plId); emit addToPlaylistRequested(trackId, plId);
}); });
@@ -293,9 +302,6 @@ void SearchTab::onTrackContextMenu(const QPoint &pos)
connect(addQueue, &QAction::triggered, this, [this, trackJson] { connect(addQueue, &QAction::triggered, this, [this, trackJson] {
m_queue->addToQueue(trackJson); m_queue->addToQueue(trackJson);
}); });
connect(addFav, &QAction::triggered, this, [this, trackId] {
m_backend->addFavTrack(trackId);
});
connect(info, &QAction::triggered, this, [this, trackJson] { connect(info, &QAction::triggered, this, [this, trackJson] {
showTrackInfo(trackJson); showTrackInfo(trackJson);
}); });
@@ -314,15 +320,17 @@ void SearchTab::onAlbumContextMenu(const QPoint &pos)
QMenu menu(this); QMenu menu(this);
auto *openAlbum = menu.addAction(tr("Open album")); auto *openAlbum = menu.addAction(QIcon(":/res/icons/view-media-album-cover.svg"), tr("Open album"));
auto *addFav = menu.addAction(tr("Add to favorites")); auto *addFav = menu.addAction(QIcon(":/res/icons/starred-symbolic.svg"), tr("Add to favorites"));
const qint64 artistId = static_cast<qint64>( const qint64 artistId = static_cast<qint64>(
albumJson["artist"].toObject()["id"].toDouble()); albumJson["artist"].toObject()["id"].toDouble());
const QString artistName = albumJson["artist"].toObject()["name"].toString(); const QString artistName = albumJson["artist"].toObject()["name"].toString();
if (artistId > 0) { if (artistId > 0) {
menu.addSeparator(); menu.addSeparator();
auto *openArtist = menu.addAction(tr("Go to artist: %1").arg(QString(artistName).replace(QLatin1Char('&'), QStringLiteral("&&")))); auto *openArtist = menu.addAction(
QIcon(":/res/icons/view-media-artist.svg"),
tr("Open artist: %1").arg(QString(artistName).replace(QLatin1Char('&'), QStringLiteral("&&"))));
connect(openArtist, &QAction::triggered, this, [this, artistId] { connect(openArtist, &QAction::triggered, this, [this, artistId] {
emit artistSelected(artistId); emit artistSelected(artistId);
}); });

View File

@@ -1,5 +1,7 @@
#pragma once #pragma once
#include "../util/colors.hpp"
#include <QWidget> #include <QWidget>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
@@ -63,7 +65,7 @@ public:
m_meta = new QLabel(info); m_meta = new QLabel(info);
QPalette mp = m_meta->palette(); QPalette mp = m_meta->palette();
mp.setColor(QPalette::WindowText, QColor(0xaa, 0xaa, 0xaa)); mp.setColor(QPalette::WindowText, Colors::SubduedText);
m_meta->setPalette(mp); m_meta->setPalette(mp);
vlay->addWidget(m_meta); vlay->addWidget(m_meta);