feat: playlist management, gapless playback, ReplayGain, Qobuz theme
Playlist management: - Add/remove tracks from playlists via right-click context menu - Create new playlists (right-click Playlists sidebar header) - Delete playlists with confirmation dialog (right-click playlist item) - Playlist view removes track immediately on delete (optimistic) - Deleting currently-open playlist clears the track view Gapless playback: - Single long-running audio thread owns AudioOutput; CPAL stream stays open between tracks eliminating device teardown/startup gap - Decode runs inline on the audio thread; command channel polled via try_recv() so Pause/Resume/Seek/Stop/Play all work without spawning - New Play command arriving mid-decode is handled immediately, reusing the same audio output for zero-gap transition - Position timer reduced from 500 ms to 50 ms for faster track-end detection - URL/metadata prefetch: when gapless is enabled Qt pre-fetches the next track while the current one is still playing ReplayGain: - Toggled in Settings → Playback - replaygain_track_gain (dB) from track audio_info converted to linear gain factor and applied per-sample alongside volume Qobuz dark theme: - Background #191919, base #141414, accent #FFB232 (yellow-orange) - Selection highlight, slider fill, scrollbar hover all use #FFB232 - Links use Qobuz blue #46B3EE - Hi-res H badges updated to #FFB232 (from #FFD700) - Now-playing row uses #FFB232 (was Spotify green) - QSS stylesheet for scrollbars, menus, inputs, buttons, groups Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -10,7 +10,7 @@ QobuzBackend::QobuzBackend(QObject *parent)
|
||||
m_backend = qobuz_backend_new(&QobuzBackend::eventTrampoline, this);
|
||||
|
||||
m_positionTimer = new QTimer(this);
|
||||
m_positionTimer->setInterval(500);
|
||||
m_positionTimer->setInterval(50);
|
||||
connect(m_positionTimer, &QTimer::timeout, this, &QobuzBackend::onPositionTick);
|
||||
m_positionTimer->start();
|
||||
}
|
||||
@@ -79,6 +79,40 @@ void QobuzBackend::getUserPlaylists(quint32 offset, quint32 limit)
|
||||
qobuz_backend_get_user_playlists(m_backend, offset, limit);
|
||||
}
|
||||
|
||||
// ---- playback options ----
|
||||
|
||||
void QobuzBackend::setReplayGain(bool enabled)
|
||||
{
|
||||
qobuz_backend_set_replaygain(m_backend, enabled);
|
||||
}
|
||||
|
||||
void QobuzBackend::prefetchTrack(qint64 trackId, int formatId)
|
||||
{
|
||||
qobuz_backend_prefetch_track(m_backend, trackId, formatId);
|
||||
}
|
||||
|
||||
// ---- playlist management ----
|
||||
|
||||
void QobuzBackend::createPlaylist(const QString &name)
|
||||
{
|
||||
qobuz_backend_create_playlist(m_backend, name.toUtf8().constData());
|
||||
}
|
||||
|
||||
void QobuzBackend::deletePlaylist(qint64 playlistId)
|
||||
{
|
||||
qobuz_backend_delete_playlist(m_backend, playlistId);
|
||||
}
|
||||
|
||||
void QobuzBackend::addTrackToPlaylist(qint64 playlistId, qint64 trackId)
|
||||
{
|
||||
qobuz_backend_add_track_to_playlist(m_backend, playlistId, trackId);
|
||||
}
|
||||
|
||||
void QobuzBackend::deleteTrackFromPlaylist(qint64 playlistId, qint64 playlistTrackId)
|
||||
{
|
||||
qobuz_backend_delete_track_from_playlist(m_backend, playlistId, playlistTrackId);
|
||||
}
|
||||
|
||||
// ---- fav modification ----
|
||||
|
||||
void QobuzBackend::addFavTrack(qint64 trackId)
|
||||
@@ -201,6 +235,12 @@ void QobuzBackend::onEvent(int eventType, const QString &json)
|
||||
case EV_STATE_CHANGED:
|
||||
emit stateChanged(obj["state"].toString());
|
||||
break;
|
||||
case 20: // EV_PLAYLIST_CREATED
|
||||
emit playlistCreated(obj);
|
||||
break;
|
||||
case 21: // EV_PLAYLIST_DELETED
|
||||
emit playlistDeleted(obj);
|
||||
break;
|
||||
case EV_GENERIC_ERR:
|
||||
case EV_TRACK_URL_ERR:
|
||||
emit error(obj["error"].toString());
|
||||
|
||||
@@ -36,6 +36,16 @@ public:
|
||||
void getFavArtists(quint32 offset = 0, quint32 limit = 200);
|
||||
void getUserPlaylists(quint32 offset = 0, quint32 limit = 200);
|
||||
|
||||
// --- playback options ---
|
||||
void setReplayGain(bool enabled);
|
||||
void prefetchTrack(qint64 trackId, int formatId = 6);
|
||||
|
||||
// --- playlist management ---
|
||||
void createPlaylist(const QString &name);
|
||||
void deletePlaylist(qint64 playlistId);
|
||||
void addTrackToPlaylist(qint64 playlistId, qint64 trackId);
|
||||
void deleteTrackFromPlaylist(qint64 playlistId, qint64 playlistTrackId);
|
||||
|
||||
// --- fav modification ---
|
||||
void addFavTrack(qint64 trackId);
|
||||
void removeFavTrack(qint64 trackId);
|
||||
@@ -66,6 +76,8 @@ signals:
|
||||
void albumLoaded(const QJsonObject &album);
|
||||
void artistLoaded(const QJsonObject &artist);
|
||||
void playlistLoaded(const QJsonObject &playlist);
|
||||
void playlistCreated(const QJsonObject &playlist);
|
||||
void playlistDeleted(const QJsonObject &result);
|
||||
|
||||
// favorites
|
||||
void favTracksLoaded(const QJsonObject &result);
|
||||
|
||||
@@ -36,6 +36,15 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent)
|
||||
}
|
||||
}
|
||||
playLayout->addRow(tr("Preferred quality:"), m_formatBox);
|
||||
|
||||
m_replayGain = new QCheckBox(tr("Enable ReplayGain (track gain normalisation)"), playGroup);
|
||||
m_replayGain->setChecked(AppSettings::instance().replayGainEnabled());
|
||||
playLayout->addRow(m_replayGain);
|
||||
|
||||
m_gapless = new QCheckBox(tr("Gapless playback (pre-fetch next track)"), playGroup);
|
||||
m_gapless->setChecked(AppSettings::instance().gaplessEnabled());
|
||||
playLayout->addRow(m_gapless);
|
||||
|
||||
layout->addWidget(playGroup);
|
||||
|
||||
// --- Last.fm group ---
|
||||
@@ -90,6 +99,8 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent)
|
||||
void SettingsDialog::applyChanges()
|
||||
{
|
||||
AppSettings::instance().setPreferredFormat(m_formatBox->currentData().toInt());
|
||||
AppSettings::instance().setReplayGainEnabled(m_replayGain->isChecked());
|
||||
AppSettings::instance().setGaplessEnabled(m_gapless->isChecked());
|
||||
AppSettings::instance().setLastFmEnabled(m_lastFmEnabled->isChecked());
|
||||
AppSettings::instance().setLastFmApiKey(m_lastFmApiKey->text().trimmed());
|
||||
AppSettings::instance().setLastFmApiSecret(m_lastFmApiSecret->text().trimmed());
|
||||
|
||||
@@ -17,7 +17,9 @@ public:
|
||||
|
||||
private:
|
||||
// Playback
|
||||
QComboBox *m_formatBox = nullptr;
|
||||
QComboBox *m_formatBox = nullptr;
|
||||
QCheckBox *m_replayGain = nullptr;
|
||||
QCheckBox *m_gapless = nullptr;
|
||||
|
||||
// Last.fm
|
||||
QCheckBox *m_lastFmEnabled = nullptr;
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include <QHeaderView>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QInputDialog>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
|
||||
namespace List
|
||||
{
|
||||
@@ -24,16 +27,29 @@ Library::Library(QobuzBackend *backend, QWidget *parent)
|
||||
{
|
||||
setHeaderHidden(true);
|
||||
setRootIsDecorated(true);
|
||||
setContextMenuPolicy(Qt::NoContextMenu);
|
||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
buildStaticNodes();
|
||||
|
||||
connect(m_backend, &QobuzBackend::userPlaylistsLoaded,
|
||||
this, &Library::onUserPlaylistsLoaded);
|
||||
connect(m_backend, &QobuzBackend::playlistCreated,
|
||||
this, [this](const QJsonObject &) { refresh(); });
|
||||
connect(m_backend, &QobuzBackend::playlistDeleted,
|
||||
this, [this](const QJsonObject &result) {
|
||||
const qint64 deletedId = static_cast<qint64>(result["playlist_id"].toDouble());
|
||||
if (deletedId == m_openPlaylistId) {
|
||||
m_openPlaylistId = 0;
|
||||
emit openPlaylistDeleted();
|
||||
}
|
||||
refresh();
|
||||
});
|
||||
connect(this, &QTreeWidget::itemClicked,
|
||||
this, &Library::onItemClicked);
|
||||
connect(this, &QTreeWidget::itemDoubleClicked,
|
||||
this, &Library::onItemDoubleClicked);
|
||||
connect(this, &QTreeWidget::customContextMenuRequested,
|
||||
this, &Library::onContextMenuRequested);
|
||||
}
|
||||
|
||||
void Library::buildStaticNodes()
|
||||
@@ -70,6 +86,7 @@ void Library::onUserPlaylistsLoaded(const QJsonObject &result)
|
||||
while (m_playlistsNode->childCount() > 0)
|
||||
delete m_playlistsNode->takeChild(0);
|
||||
|
||||
QVector<QPair<qint64, QString>> playlists;
|
||||
const QJsonArray items = result["items"].toArray();
|
||||
for (const auto &v : items) {
|
||||
const QJsonObject pl = v.toObject();
|
||||
@@ -80,7 +97,55 @@ void Library::onUserPlaylistsLoaded(const QJsonObject &result)
|
||||
item->setData(0, TypeRole, NodePlaylist);
|
||||
item->setData(0, IdRole, id);
|
||||
item->setData(0, NameRole, name);
|
||||
|
||||
playlists.append({id, name});
|
||||
}
|
||||
|
||||
emit userPlaylistsChanged(playlists);
|
||||
}
|
||||
|
||||
void Library::onContextMenuRequested(const QPoint &pos)
|
||||
{
|
||||
QTreeWidgetItem *item = itemAt(pos);
|
||||
if (!item) return;
|
||||
|
||||
const bool isHeader = (item == m_playlistsNode);
|
||||
const bool isPlaylistItem = (!isHeader && item->parent() == m_playlistsNode &&
|
||||
item->data(0, TypeRole).toInt() == NodePlaylist);
|
||||
|
||||
if (!isHeader && !isPlaylistItem) return;
|
||||
|
||||
QMenu menu(this);
|
||||
|
||||
auto *newPl = menu.addAction(tr("New Playlist…"));
|
||||
connect(newPl, &QAction::triggered, this, [this] {
|
||||
bool ok = false;
|
||||
const QString name = QInputDialog::getText(
|
||||
this, tr("New Playlist"), tr("Playlist name:"),
|
||||
QLineEdit::Normal, QString(), &ok);
|
||||
if (ok && !name.trimmed().isEmpty())
|
||||
m_backend->createPlaylist(name.trimmed());
|
||||
});
|
||||
|
||||
if (isPlaylistItem) {
|
||||
const qint64 plId = item->data(0, IdRole).toLongLong();
|
||||
const QString plName = item->data(0, NameRole).toString();
|
||||
|
||||
menu.addSeparator();
|
||||
auto *delPl = menu.addAction(tr("Delete \"%1\"…").arg(plName));
|
||||
connect(delPl, &QAction::triggered, this, [this, plId, plName] {
|
||||
const auto answer = QMessageBox::question(
|
||||
this,
|
||||
tr("Delete Playlist"),
|
||||
tr("Permanently delete \"%1\"? This cannot be undone.").arg(plName),
|
||||
QMessageBox::Yes | QMessageBox::Cancel,
|
||||
QMessageBox::Cancel);
|
||||
if (answer == QMessageBox::Yes)
|
||||
m_backend->deletePlaylist(plId);
|
||||
});
|
||||
}
|
||||
|
||||
menu.exec(viewport()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
void Library::onItemClicked(QTreeWidgetItem *item, int)
|
||||
@@ -95,6 +160,7 @@ void Library::onItemClicked(QTreeWidgetItem *item, int)
|
||||
case NodePlaylist: {
|
||||
const qint64 id = item->data(0, IdRole).toLongLong();
|
||||
const QString name = item->data(0, NameRole).toString();
|
||||
m_openPlaylistId = id;
|
||||
emit playlistRequested(id, name);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include "../backend/qobuzbackend.hpp"
|
||||
|
||||
#include <QTreeWidget>
|
||||
#include <QVector>
|
||||
#include <QPair>
|
||||
#include <QString>
|
||||
|
||||
namespace List
|
||||
{
|
||||
@@ -23,17 +26,23 @@ namespace List
|
||||
void favAlbumsRequested();
|
||||
void favArtistsRequested();
|
||||
void playlistRequested(qint64 playlistId, const QString &name);
|
||||
/// Emitted after playlists are loaded so others can cache the list.
|
||||
void userPlaylistsChanged(const QVector<QPair<qint64, QString>> &playlists);
|
||||
/// Emitted when the currently open playlist was deleted.
|
||||
void openPlaylistDeleted();
|
||||
|
||||
private slots:
|
||||
void onUserPlaylistsLoaded(const QJsonObject &result);
|
||||
void onItemClicked(QTreeWidgetItem *item, int column);
|
||||
void onItemDoubleClicked(QTreeWidgetItem *item, int column);
|
||||
void onContextMenuRequested(const QPoint &pos);
|
||||
|
||||
private:
|
||||
QobuzBackend *m_backend = nullptr;
|
||||
|
||||
QTreeWidgetItem *m_myLibNode = nullptr;
|
||||
QTreeWidgetItem *m_playlistsNode = nullptr;
|
||||
qint64 m_openPlaylistId = 0;
|
||||
|
||||
void buildStaticNodes();
|
||||
};
|
||||
|
||||
@@ -39,26 +39,41 @@ Tracks::Tracks(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
||||
|
||||
void Tracks::loadTracks(const QJsonArray &tracks)
|
||||
{
|
||||
setPlaylistContext(0);
|
||||
m_model->setTracks(tracks, false, /*useSequential=*/true);
|
||||
}
|
||||
|
||||
void Tracks::loadAlbum(const QJsonObject &album)
|
||||
{
|
||||
setPlaylistContext(0);
|
||||
const QJsonArray items = album["tracks"].toObject()["items"].toArray();
|
||||
m_model->setTracks(items); // album: use track_number
|
||||
}
|
||||
|
||||
void Tracks::loadPlaylist(const QJsonObject &playlist)
|
||||
{
|
||||
const qint64 id = static_cast<qint64>(playlist["id"].toDouble());
|
||||
setPlaylistContext(id);
|
||||
const QJsonArray items = playlist["tracks"].toObject()["items"].toArray();
|
||||
m_model->setTracks(items, /*usePosition=*/true);
|
||||
}
|
||||
|
||||
void Tracks::loadSearchTracks(const QJsonArray &tracks)
|
||||
{
|
||||
setPlaylistContext(0);
|
||||
m_model->setTracks(tracks, false, /*useSequential=*/true);
|
||||
}
|
||||
|
||||
void Tracks::setPlaylistContext(qint64 playlistId)
|
||||
{
|
||||
m_playlistId = playlistId;
|
||||
}
|
||||
|
||||
void Tracks::setUserPlaylists(const QVector<QPair<qint64, QString>> &playlists)
|
||||
{
|
||||
m_userPlaylists = playlists;
|
||||
}
|
||||
|
||||
void Tracks::setPlayingTrackId(qint64 id)
|
||||
{
|
||||
m_model->setPlayingId(id);
|
||||
@@ -134,6 +149,36 @@ void Tracks::onContextMenu(const QPoint &pos)
|
||||
});
|
||||
}
|
||||
|
||||
// Playlist management
|
||||
if (!m_userPlaylists.isEmpty()) {
|
||||
menu.addSeparator();
|
||||
auto *addToPlMenu = menu.addMenu(
|
||||
QIcon(":/res/icons/media-playlist-append.svg"), tr("Add to playlist"));
|
||||
for (const auto &pl : m_userPlaylists) {
|
||||
const qint64 plId = pl.first;
|
||||
const QString plName = pl.second;
|
||||
auto *act = addToPlMenu->addAction(plName);
|
||||
connect(act, &QAction::triggered, this, [this, id, plId] {
|
||||
emit addToPlaylistRequested(id, plId);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (m_playlistId > 0) {
|
||||
const qint64 playlistTrackId =
|
||||
m_model->data(index, TrackListModel::PlaylistTrackIdRole).toLongLong();
|
||||
if (playlistTrackId > 0) {
|
||||
if (m_userPlaylists.isEmpty()) menu.addSeparator();
|
||||
auto *remFromPl = menu.addAction(tr("Remove from this playlist"));
|
||||
const qint64 curPlaylistId = m_playlistId;
|
||||
const int curRow = index.row();
|
||||
connect(remFromPl, &QAction::triggered, this, [this, curPlaylistId, playlistTrackId, curRow] {
|
||||
emit removeFromPlaylistRequested(curPlaylistId, playlistTrackId);
|
||||
m_model->removeTrack(curRow); // optimistic: remove immediately from view
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
menu.exec(viewport()->mapToGlobal(pos));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include <QTreeView>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
#include <QVector>
|
||||
#include <QPair>
|
||||
#include <QString>
|
||||
|
||||
namespace List
|
||||
{
|
||||
@@ -25,13 +28,22 @@ namespace List
|
||||
/// Called when the backend fires EV_TRACK_CHANGED so the playing row is highlighted.
|
||||
void setPlayingTrackId(qint64 id);
|
||||
|
||||
/// Set which playlist is currently displayed (0 = none).
|
||||
void setPlaylistContext(qint64 playlistId);
|
||||
/// Provide the user's playlist list for the "Add to playlist" submenu.
|
||||
void setUserPlaylists(const QVector<QPair<qint64, QString>> &playlists);
|
||||
|
||||
signals:
|
||||
void playTrackRequested(qint64 trackId);
|
||||
void addToPlaylistRequested(qint64 trackId, qint64 playlistId);
|
||||
void removeFromPlaylistRequested(qint64 playlistId, qint64 playlistTrackId);
|
||||
|
||||
private:
|
||||
TrackListModel *m_model = nullptr;
|
||||
QobuzBackend *m_backend = nullptr;
|
||||
PlayQueue *m_queue = nullptr;
|
||||
qint64 m_playlistId = 0;
|
||||
QVector<QPair<qint64, QString>> m_userPlaylists;
|
||||
|
||||
void onDoubleClicked(const QModelIndex &index);
|
||||
void onContextMenu(const QPoint &pos);
|
||||
|
||||
74
src/main.cpp
74
src/main.cpp
@@ -11,27 +11,67 @@ int main(int argc, char *argv[])
|
||||
app.setOrganizationName(QStringLiteral("qobuz-qt"));
|
||||
app.setApplicationVersion(QStringLiteral("0.1.0"));
|
||||
|
||||
// Dark palette consistent with spotify-qt style
|
||||
// Qobuz dark palette
|
||||
// Accent: #FFB232 (yellow-orange), Blue: #46B3EE, Backgrounds: #191919 / #141414
|
||||
app.setStyle(QStyleFactory::create(QStringLiteral("Fusion")));
|
||||
QPalette darkPalette;
|
||||
darkPalette.setColor(QPalette::Window, QColor(35, 35, 35));
|
||||
darkPalette.setColor(QPalette::WindowText, Qt::white);
|
||||
darkPalette.setColor(QPalette::Base, QColor(25, 25, 25));
|
||||
darkPalette.setColor(QPalette::AlternateBase, QColor(45, 45, 45));
|
||||
darkPalette.setColor(QPalette::ToolTipBase, Qt::white);
|
||||
darkPalette.setColor(QPalette::ToolTipText, Qt::white);
|
||||
darkPalette.setColor(QPalette::Text, Qt::white);
|
||||
darkPalette.setColor(QPalette::Button, QColor(53, 53, 53));
|
||||
darkPalette.setColor(QPalette::ButtonText, Qt::white);
|
||||
darkPalette.setColor(QPalette::BrightText, Qt::red);
|
||||
darkPalette.setColor(QPalette::Link, QColor(42, 130, 218));
|
||||
darkPalette.setColor(QPalette::Highlight, QColor(42, 130, 218));
|
||||
darkPalette.setColor(QPalette::HighlightedText, Qt::black);
|
||||
darkPalette.setColor(QPalette::PlaceholderText, QColor(140, 140, 140));
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(127, 127, 127));
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(127, 127, 127));
|
||||
darkPalette.setColor(QPalette::Window, QColor(0x19, 0x19, 0x19));
|
||||
darkPalette.setColor(QPalette::WindowText, QColor(0xe8, 0xe8, 0xe8));
|
||||
darkPalette.setColor(QPalette::Base, QColor(0x14, 0x14, 0x14));
|
||||
darkPalette.setColor(QPalette::AlternateBase, QColor(0x1e, 0x1e, 0x1e));
|
||||
darkPalette.setColor(QPalette::ToolTipBase, QColor(0x19, 0x19, 0x19));
|
||||
darkPalette.setColor(QPalette::ToolTipText, QColor(0xe8, 0xe8, 0xe8));
|
||||
darkPalette.setColor(QPalette::Text, QColor(0xe8, 0xe8, 0xe8));
|
||||
darkPalette.setColor(QPalette::Button, QColor(0x2a, 0x2a, 0x2a));
|
||||
darkPalette.setColor(QPalette::ButtonText, QColor(0xe8, 0xe8, 0xe8));
|
||||
darkPalette.setColor(QPalette::BrightText, QColor(0xFF, 0xB2, 0x32));
|
||||
darkPalette.setColor(QPalette::Link, QColor(0x46, 0xB3, 0xEE)); // Qobuz blue
|
||||
darkPalette.setColor(QPalette::Highlight, QColor(0xFF, 0xB2, 0x32)); // Qobuz orange
|
||||
darkPalette.setColor(QPalette::HighlightedText, QColor(0x10, 0x10, 0x10)); // dark on orange
|
||||
darkPalette.setColor(QPalette::PlaceholderText, QColor(0x66, 0x66, 0x66));
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::Text, QColor(0x55, 0x55, 0x55));
|
||||
darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, QColor(0x55, 0x55, 0x55));
|
||||
darkPalette.setColor(QPalette::Mid, QColor(0x2f, 0x2f, 0x2f));
|
||||
darkPalette.setColor(QPalette::Dark, QColor(0x0e, 0x0e, 0x0e));
|
||||
app.setPalette(darkPalette);
|
||||
|
||||
// Stylesheet tweaks: orange accent on scrollbars, focus rings, etc.
|
||||
app.setStyleSheet(QStringLiteral(
|
||||
"QScrollBar:vertical { width: 6px; background: #141414; border: none; }"
|
||||
"QScrollBar::handle:vertical { background: #3a3a3a; border-radius: 3px; min-height: 20px; }"
|
||||
"QScrollBar::handle:vertical:hover { background: #FFB232; }"
|
||||
"QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { height: 0; }"
|
||||
"QScrollBar:horizontal { height: 6px; background: #141414; border: none; }"
|
||||
"QScrollBar::handle:horizontal { background: #3a3a3a; border-radius: 3px; min-width: 20px; }"
|
||||
"QScrollBar::handle:horizontal:hover { background: #FFB232; }"
|
||||
"QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal { width: 0; }"
|
||||
"QToolBar { background: #111111; border-bottom: 1px solid #2a2a2a; spacing: 4px; }"
|
||||
"QDockWidget { border: none; }"
|
||||
"QDockWidget::title { background: #1e1e1e; padding: 4px 8px; font-weight: bold; }"
|
||||
"QTreeView, QTreeWidget { border: none; outline: none; }"
|
||||
"QTreeView::item:selected, QTreeWidget::item:selected { color: #101010; }"
|
||||
"QHeaderView::section { background: #1e1e1e; border: none;"
|
||||
" border-right: 1px solid #2a2a2a; padding: 4px 8px; }"
|
||||
"QMenu { background: #1e1e1e; border: 1px solid #3a3a3a; }"
|
||||
"QMenu::item:selected { background: #FFB232; color: #101010; }"
|
||||
"QPushButton { background: #2a2a2a; border: 1px solid #3a3a3a; border-radius: 4px; padding: 4px 12px; }"
|
||||
"QPushButton:hover { background: #333333; border-color: #FFB232; }"
|
||||
"QPushButton:pressed { background: #FFB232; color: #101010; }"
|
||||
"QComboBox { background: #2a2a2a; border: 1px solid #3a3a3a; border-radius: 4px; padding: 3px 8px; }"
|
||||
"QComboBox:hover { border-color: #FFB232; }"
|
||||
"QComboBox QAbstractItemView { background: #1e1e1e; selection-background-color: #FFB232; selection-color: #101010; }"
|
||||
"QLineEdit { background: #1e1e1e; border: 1px solid #3a3a3a; border-radius: 4px; padding: 4px 8px; }"
|
||||
"QLineEdit:focus { border-color: #FFB232; }"
|
||||
"QGroupBox { border: 1px solid #2f2f2f; border-radius: 6px; margin-top: 8px; padding-top: 4px; }"
|
||||
"QGroupBox::title { subcontrol-origin: margin; left: 8px; color: #FFB232; }"
|
||||
"QCheckBox::indicator:checked { background: #FFB232; border: 1px solid #FFB232; border-radius: 2px; }"
|
||||
"QSlider::groove:horizontal { height: 4px; background: #2a2a2a; border-radius: 2px; }"
|
||||
"QSlider::handle:horizontal { background: #FFB232; width: 12px; height: 12px;"
|
||||
" margin: -4px 0; border-radius: 6px; }"
|
||||
"QSlider::sub-page:horizontal { background: #FFB232; border-radius: 2px; }"
|
||||
"QStatusBar { background: #111111; border-top: 1px solid #2a2a2a; }"
|
||||
));
|
||||
|
||||
auto *backend = new QobuzBackend;
|
||||
MainWindow window(backend);
|
||||
window.show();
|
||||
|
||||
@@ -77,12 +77,25 @@ 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::playlistLoaded, this, &MainWindow::onPlaylistLoaded);
|
||||
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 &) {
|
||||
statusBar()->showMessage(tr("Playlist deleted"), 3000);
|
||||
});
|
||||
connect(m_backend, &QobuzBackend::trackChanged, this, &MainWindow::onTrackChanged);
|
||||
connect(m_backend, &QobuzBackend::error, this, [this](const QString &msg) {
|
||||
statusBar()->showMessage(tr("Error: %1").arg(msg), 6000);
|
||||
});
|
||||
|
||||
// ---- Library signals ----
|
||||
connect(m_library, &List::Library::userPlaylistsChanged,
|
||||
this, &MainWindow::onUserPlaylistsChanged);
|
||||
connect(m_library, &List::Library::openPlaylistDeleted,
|
||||
this, [this] {
|
||||
m_content->showWelcome();
|
||||
statusBar()->showMessage(tr("Playlist deleted"), 3000);
|
||||
});
|
||||
|
||||
// ---- Library → backend ----
|
||||
connect(m_library, &List::Library::favTracksRequested, this, [this] {
|
||||
m_backend->getFavTracks();
|
||||
@@ -102,9 +115,19 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
statusBar()->showMessage(tr("Loading playlist: %1…").arg(name));
|
||||
});
|
||||
|
||||
// ---- Track list → playback ----
|
||||
// ---- Track list → playback / playlist management ----
|
||||
connect(m_content->tracksList(), &List::Tracks::playTrackRequested,
|
||||
this, &MainWindow::onPlayTrackRequested);
|
||||
connect(m_content->tracksList(), &List::Tracks::addToPlaylistRequested,
|
||||
this, [this](qint64 trackId, qint64 playlistId) {
|
||||
m_backend->addTrackToPlaylist(playlistId, trackId);
|
||||
statusBar()->showMessage(tr("Adding track to playlist…"), 3000);
|
||||
});
|
||||
connect(m_content->tracksList(), &List::Tracks::removeFromPlaylistRequested,
|
||||
this, [this](qint64 playlistId, qint64 playlistTrackId) {
|
||||
m_backend->deleteTrackFromPlaylist(playlistId, playlistTrackId);
|
||||
statusBar()->showMessage(tr("Removing track from playlist…"), 3000);
|
||||
});
|
||||
|
||||
// ---- Search panel ----
|
||||
connect(m_sidePanel, &SidePanel::View::albumSelected,
|
||||
@@ -129,6 +152,9 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
connect(m_toolBar, &MainToolBar::queueToggled,
|
||||
this, [this](bool v) { m_queuePanel->setVisible(v); });
|
||||
|
||||
// Apply playback options from saved settings
|
||||
m_backend->setReplayGain(AppSettings::instance().replayGainEnabled());
|
||||
|
||||
tryRestoreSession();
|
||||
}
|
||||
|
||||
@@ -233,6 +259,16 @@ void MainWindow::onTrackChanged(const QJsonObject &track)
|
||||
: track["performer"].toObject()["name"].toString();
|
||||
statusBar()->showMessage(
|
||||
artist.isEmpty() ? title : QStringLiteral("▶ %1 — %2").arg(artist, title));
|
||||
|
||||
// Gapless: prefetch next track URL so it starts immediately
|
||||
if (AppSettings::instance().gaplessEnabled() && m_queue->canGoNext()) {
|
||||
const auto upcoming = m_queue->upcomingTracks(1);
|
||||
if (!upcoming.isEmpty()) {
|
||||
const qint64 nextId = static_cast<qint64>(upcoming.first()["id"].toDouble());
|
||||
if (nextId > 0)
|
||||
m_backend->prefetchTrack(nextId, AppSettings::instance().preferredFormat());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onFavTracksLoaded(const QJsonObject &result)
|
||||
@@ -298,3 +334,15 @@ void MainWindow::onSearchToggled(bool visible)
|
||||
{
|
||||
m_sidePanel->setVisible(visible);
|
||||
}
|
||||
|
||||
void MainWindow::onPlaylistCreated(const QJsonObject &playlist)
|
||||
{
|
||||
statusBar()->showMessage(
|
||||
tr("Playlist '%1' created").arg(playlist["name"].toString()), 4000);
|
||||
}
|
||||
|
||||
void MainWindow::onUserPlaylistsChanged(const QVector<QPair<qint64, QString>> &playlists)
|
||||
{
|
||||
m_userPlaylists = playlists;
|
||||
m_content->tracksList()->setUserPlaylists(playlists);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
#include <QMainWindow>
|
||||
#include <QDockWidget>
|
||||
#include <QJsonObject>
|
||||
#include <QVector>
|
||||
#include <QPair>
|
||||
#include <QString>
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
{
|
||||
@@ -38,6 +41,8 @@ private slots:
|
||||
void onSearchAlbumSelected(const QString &albumId);
|
||||
void onSearchArtistSelected(qint64 artistId);
|
||||
void onSearchToggled(bool visible);
|
||||
void onPlaylistCreated(const QJsonObject &playlist);
|
||||
void onUserPlaylistsChanged(const QVector<QPair<qint64, QString>> &playlists);
|
||||
|
||||
void showLoginDialog();
|
||||
void showSettingsDialog();
|
||||
@@ -45,6 +50,7 @@ private slots:
|
||||
private:
|
||||
QobuzBackend *m_backend = nullptr;
|
||||
PlayQueue *m_queue = nullptr;
|
||||
QVector<QPair<qint64, QString>> m_userPlaylists;
|
||||
MainToolBar *m_toolBar = nullptr;
|
||||
MainContent *m_content = nullptr;
|
||||
List::Library *m_library = nullptr;
|
||||
|
||||
@@ -21,9 +21,10 @@ void TrackListModel::setTracks(const QJsonArray &tracks,
|
||||
for (const QJsonValue &v : tracks) {
|
||||
const QJsonObject t = v.toObject();
|
||||
TrackItem item;
|
||||
item.id = static_cast<qint64>(t["id"].toDouble());
|
||||
item.title = t["title"].toString();
|
||||
item.duration = static_cast<qint64>(t["duration"].toDouble());
|
||||
item.id = static_cast<qint64>(t["id"].toDouble());
|
||||
item.playlistTrackId = static_cast<qint64>(t["playlist_track_id"].toDouble());
|
||||
item.title = t["title"].toString();
|
||||
item.duration = static_cast<qint64>(t["duration"].toDouble());
|
||||
item.hiRes = t["hires_streamable"].toBool();
|
||||
item.streamable = t["streamable"].toBool(true);
|
||||
item.raw = t;
|
||||
@@ -68,6 +69,14 @@ void TrackListModel::clear()
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void TrackListModel::removeTrack(int row)
|
||||
{
|
||||
if (row < 0 || row >= m_tracks.size()) return;
|
||||
beginRemoveRows({}, row, row);
|
||||
m_tracks.removeAt(row);
|
||||
endRemoveRows();
|
||||
}
|
||||
|
||||
void TrackListModel::setPlayingId(qint64 id)
|
||||
{
|
||||
m_playingId = id;
|
||||
@@ -111,17 +120,18 @@ QVariant TrackListModel::data(const QModelIndex &index, int role) const
|
||||
}
|
||||
|
||||
if (role == Qt::ForegroundRole) {
|
||||
if (!t.streamable) return QColor(Qt::gray);
|
||||
if (isPlaying) return QColor(0x1d, 0xb9, 0x54); // Qobuz green
|
||||
if (!t.streamable) return QColor(0x55, 0x55, 0x55);
|
||||
if (isPlaying) return QColor(0xFF, 0xB2, 0x32); // Qobuz orange
|
||||
}
|
||||
|
||||
if (role == Qt::DecorationRole && index.column() == ColNumber && isPlaying) {
|
||||
return QIcon(QStringLiteral(":/res/icons/media-track-show-active.svg"));
|
||||
}
|
||||
|
||||
if (role == TrackIdRole) return t.id;
|
||||
if (role == TrackJsonRole) return t.raw;
|
||||
if (role == HiResRole) return t.hiRes;
|
||||
if (role == TrackIdRole) return t.id;
|
||||
if (role == TrackJsonRole) return t.raw;
|
||||
if (role == HiResRole) return t.hiRes;
|
||||
if (role == PlaylistTrackIdRole) return t.playlistTrackId;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -7,15 +7,16 @@
|
||||
#include <QFont>
|
||||
|
||||
struct TrackItem {
|
||||
qint64 id = 0;
|
||||
int number = 0;
|
||||
qint64 id = 0;
|
||||
qint64 playlistTrackId = 0;
|
||||
int number = 0;
|
||||
QString title;
|
||||
QString artist;
|
||||
QString album;
|
||||
QString albumId;
|
||||
qint64 duration = 0; // seconds
|
||||
bool hiRes = false;
|
||||
bool streamable = false;
|
||||
qint64 duration = 0; // seconds
|
||||
bool hiRes = false;
|
||||
bool streamable = false;
|
||||
QJsonObject raw;
|
||||
};
|
||||
|
||||
@@ -34,9 +35,10 @@ public:
|
||||
};
|
||||
|
||||
enum Role {
|
||||
TrackIdRole = Qt::UserRole + 1,
|
||||
TrackJsonRole = Qt::UserRole + 2,
|
||||
HiResRole = Qt::UserRole + 3,
|
||||
TrackIdRole = Qt::UserRole + 1,
|
||||
TrackJsonRole = Qt::UserRole + 2,
|
||||
HiResRole = Qt::UserRole + 3,
|
||||
PlaylistTrackIdRole = Qt::UserRole + 4,
|
||||
};
|
||||
|
||||
explicit TrackListModel(QObject *parent = nullptr);
|
||||
@@ -50,6 +52,9 @@ public:
|
||||
void setPlayingId(qint64 id);
|
||||
qint64 playingId() const { return m_playingId; }
|
||||
|
||||
/// Optimistically remove a row (e.g. after deleting from playlist).
|
||||
void removeTrack(int row);
|
||||
|
||||
const TrackItem &trackAt(int row) const { return m_tracks.at(row); }
|
||||
|
||||
// Returns the current (possibly sorted) raw JSON objects in display order.
|
||||
|
||||
@@ -31,6 +31,13 @@ public:
|
||||
bool rememberLogin() const { return m_settings.value("auth/remember", true).toBool(); }
|
||||
void setRememberLogin(bool r) { m_settings.setValue("auth/remember", r); }
|
||||
|
||||
// --- Playback extras ---
|
||||
bool replayGainEnabled() const { return m_settings.value("playback/replaygain", false).toBool(); }
|
||||
void setReplayGainEnabled(bool v) { m_settings.setValue("playback/replaygain", v); }
|
||||
|
||||
bool gaplessEnabled() const { return m_settings.value("playback/gapless", false).toBool(); }
|
||||
void setGaplessEnabled(bool v) { m_settings.setValue("playback/gapless", v); }
|
||||
|
||||
// --- Last.fm ---
|
||||
bool lastFmEnabled() const { return m_settings.value("lastfm/enabled", false).toBool(); }
|
||||
void setLastFmEnabled(bool v) { m_settings.setValue("lastfm/enabled", v); }
|
||||
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
auto *item = new QTreeWidgetItem(this);
|
||||
if (hiRes) {
|
||||
item->setText(0, QStringLiteral("H"));
|
||||
item->setForeground(0, QColor(QStringLiteral("#FFD700")));
|
||||
item->setForeground(0, QColor(QStringLiteral("#FFB232")));
|
||||
item->setFont(0, hiResFont);
|
||||
item->setTextAlignment(0, Qt::AlignCenter);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &) const override
|
||||
{
|
||||
return QSize(0, QFontMetrics(option.font).height() + 10);
|
||||
return QSize(0, QFontMetrics(option.font).height() + 4);
|
||||
}
|
||||
|
||||
void paint(QPainter *p, const QStyleOptionViewItem &option,
|
||||
|
||||
@@ -105,7 +105,7 @@ void SearchTab::onSearchResult(const QJsonObject &result)
|
||||
QStringList{QString(), a["title"].toString(), artist});
|
||||
if (hiRes) {
|
||||
item->setText(0, QStringLiteral("H"));
|
||||
item->setForeground(0, QColor(QStringLiteral("#FFD700")));
|
||||
item->setForeground(0, QColor(QStringLiteral("#FFB232")));
|
||||
item->setFont(0, hiResFont);
|
||||
item->setTextAlignment(0, Qt::AlignCenter);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user