feat: initial qobuz-qt source
Lightweight Qt6 desktop client for Qobuz with a Rust audio backend (Symphonia/CPAL via staticlib FFI). Mirrors the spotify-qt layout: toolbar with playback controls, library/context docks on the left, tabbed search side panel on the right, queue panel, now-playing dock. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -4,56 +4,69 @@
|
||||
|
||||
#include <QWidget>
|
||||
#include <QHBoxLayout>
|
||||
#include <QNetworkRequest>
|
||||
|
||||
MainToolBar::MainToolBar(QobuzBackend *backend, QWidget *parent)
|
||||
MainToolBar::MainToolBar(QobuzBackend *backend, PlayQueue *queue, QWidget *parent)
|
||||
: QToolBar(parent)
|
||||
, m_backend(backend)
|
||||
, m_queue(queue)
|
||||
{
|
||||
setMovable(false);
|
||||
setFloatable(false);
|
||||
setContextMenuPolicy(Qt::PreventContextMenu);
|
||||
setIconSize(QSize(22, 22));
|
||||
|
||||
// Previous
|
||||
m_nam = new QNetworkAccessManager(this);
|
||||
connect(m_nam, &QNetworkAccessManager::finished, this, &MainToolBar::onAlbumArtReady);
|
||||
|
||||
// --- Album art thumbnail ---
|
||||
m_artLabel = new QLabel(this);
|
||||
m_artLabel->setFixedSize(36, 36);
|
||||
m_artLabel->setScaledContents(true);
|
||||
m_artLabel->setStyleSheet("border: 1px solid #444; background: #1a1a1a;");
|
||||
m_artLabel->setPixmap(QIcon(":/res/icons/view-media-album-cover.svg")
|
||||
.pixmap(32, 32));
|
||||
addWidget(m_artLabel);
|
||||
addSeparator();
|
||||
|
||||
// --- Playback controls ---
|
||||
m_previous = addAction(Icon::previous(), tr("Previous"));
|
||||
connect(m_previous, &QAction::triggered, this, &MainToolBar::onPrevious);
|
||||
|
||||
// Play/Pause
|
||||
m_playPause = addAction(Icon::play(), tr("Play"));
|
||||
m_playPause->setCheckable(false);
|
||||
connect(m_playPause, &QAction::triggered, this, [this](bool) { onPlayPause(false); });
|
||||
connect(m_playPause, &QAction::triggered, this, &MainToolBar::onPlayPause);
|
||||
|
||||
// Next
|
||||
m_next = addAction(Icon::next(), tr("Next"));
|
||||
connect(m_next, &QAction::triggered, this, &MainToolBar::onNext);
|
||||
|
||||
addSeparator();
|
||||
|
||||
// Track label
|
||||
// --- Track info label ---
|
||||
m_trackLabel = new QLabel(tr("Not playing"), this);
|
||||
m_trackLabel->setMinimumWidth(200);
|
||||
m_trackLabel->setMaximumWidth(320);
|
||||
m_trackLabel->setMinimumWidth(180);
|
||||
m_trackLabel->setMaximumWidth(340);
|
||||
m_trackLabel->setAlignment(Qt::AlignVCenter | Qt::AlignLeft);
|
||||
addWidget(m_trackLabel);
|
||||
|
||||
addSeparator();
|
||||
|
||||
// Progress slider
|
||||
// --- Progress slider ---
|
||||
m_progress = new ClickableSlider(Qt::Horizontal, this);
|
||||
m_progress->setRange(0, 1000);
|
||||
m_progress->setValue(0);
|
||||
m_progress->setMinimumWidth(180);
|
||||
m_progress->setMaximumWidth(400);
|
||||
m_progress->setMinimumWidth(160);
|
||||
m_progress->setMaximumWidth(380);
|
||||
addWidget(m_progress);
|
||||
|
||||
connect(m_progress, &QSlider::sliderPressed, this, [this] { m_seeking = true; });
|
||||
connect(m_progress, &QSlider::sliderReleased, this, &MainToolBar::onProgressReleased);
|
||||
|
||||
// Time label
|
||||
m_timeLabel = new QLabel("0:00 / 0:00", this);
|
||||
addWidget(m_timeLabel);
|
||||
|
||||
addSeparator();
|
||||
|
||||
// Volume button
|
||||
// --- Volume ---
|
||||
m_volume = new VolumeButton(this);
|
||||
m_volume->setValue(AppSettings::instance().volume());
|
||||
addWidget(m_volume);
|
||||
@@ -61,18 +74,36 @@ MainToolBar::MainToolBar(QobuzBackend *backend, QWidget *parent)
|
||||
|
||||
addSeparator();
|
||||
|
||||
// Search toggle
|
||||
// --- Shuffle ---
|
||||
m_shuffle = addAction(Icon::get(QStringLiteral("media-playlist-shuffle")), tr("Shuffle"));
|
||||
m_shuffle->setCheckable(true);
|
||||
connect(m_shuffle, &QAction::toggled, this, &MainToolBar::onShuffleToggled);
|
||||
|
||||
addSeparator();
|
||||
|
||||
// --- Queue toggle ---
|
||||
m_queueBtn = addAction(Icon::queue(), tr("Queue"));
|
||||
m_queueBtn->setCheckable(true);
|
||||
connect(m_queueBtn, &QAction::toggled, this, &MainToolBar::queueToggled);
|
||||
|
||||
// --- Search toggle ---
|
||||
m_search = addAction(Icon::search(), tr("Search"));
|
||||
m_search->setCheckable(true);
|
||||
connect(m_search, &QAction::toggled, this, &MainToolBar::searchToggled);
|
||||
|
||||
// Connect to backend signals
|
||||
connect(m_backend, &QobuzBackend::stateChanged, this, &MainToolBar::onBackendStateChanged);
|
||||
connect(m_backend, &QobuzBackend::trackChanged, this, &MainToolBar::onTrackChanged);
|
||||
// --- Backend signals ---
|
||||
connect(m_backend, &QobuzBackend::stateChanged, this, &MainToolBar::onBackendStateChanged);
|
||||
connect(m_backend, &QobuzBackend::trackChanged, this, &MainToolBar::onTrackChanged);
|
||||
connect(m_backend, &QobuzBackend::positionChanged, this, &MainToolBar::onPositionChanged);
|
||||
connect(m_backend, &QobuzBackend::trackFinished, this, &MainToolBar::onTrackFinished);
|
||||
connect(m_backend, &QobuzBackend::trackFinished, this, &MainToolBar::onTrackFinished);
|
||||
|
||||
// --- Queue signals ---
|
||||
connect(m_queue, &PlayQueue::queueChanged, this, &MainToolBar::onQueueChanged);
|
||||
onQueueChanged(); // initialise button states
|
||||
}
|
||||
|
||||
// ---- public ----
|
||||
|
||||
void MainToolBar::setPlaying(bool playing)
|
||||
{
|
||||
m_playing = playing;
|
||||
@@ -82,9 +113,10 @@ void MainToolBar::setPlaying(bool playing)
|
||||
|
||||
void MainToolBar::setCurrentTrack(const QJsonObject &track)
|
||||
{
|
||||
const QString title = track["title"].toString();
|
||||
const QJsonObject performer = track["performer"].toObject();
|
||||
const QString artist = performer["name"].toString();
|
||||
const QString title = track["title"].toString();
|
||||
const QString artist = track["performer"].toObject()["name"].toString().isEmpty()
|
||||
? track["album"].toObject()["artist"].toObject()["name"].toString()
|
||||
: track["performer"].toObject()["name"].toString();
|
||||
|
||||
if (title.isEmpty()) {
|
||||
m_trackLabel->setText(tr("Not playing"));
|
||||
@@ -93,55 +125,58 @@ void MainToolBar::setCurrentTrack(const QJsonObject &track)
|
||||
} else {
|
||||
m_trackLabel->setText(QStringLiteral("%1 — %2").arg(artist, title));
|
||||
}
|
||||
|
||||
// Album art
|
||||
const QString artUrl = track["album"].toObject()["image"].toObject()["small"].toString();
|
||||
if (!artUrl.isEmpty() && artUrl != m_currentArtUrl) {
|
||||
m_currentArtUrl = artUrl;
|
||||
fetchAlbumArt(artUrl);
|
||||
}
|
||||
}
|
||||
|
||||
void MainToolBar::updateProgress(quint64 position, quint64 duration)
|
||||
{
|
||||
if (m_seeking) return;
|
||||
|
||||
const int sliderPos = duration > 0
|
||||
? static_cast<int>(position * 1000 / duration)
|
||||
: 0;
|
||||
? static_cast<int>(position * 1000 / duration) : 0;
|
||||
m_progress->blockSignals(true);
|
||||
m_progress->setValue(sliderPos);
|
||||
m_progress->blockSignals(false);
|
||||
|
||||
const QString pos = TrackListModel::formatDuration(static_cast<qint64>(position));
|
||||
const QString dur = TrackListModel::formatDuration(static_cast<qint64>(duration));
|
||||
m_timeLabel->setText(QStringLiteral("%1 / %2").arg(pos, dur));
|
||||
m_timeLabel->setText(
|
||||
QStringLiteral("%1 / %2")
|
||||
.arg(TrackListModel::formatDuration(static_cast<qint64>(position)),
|
||||
TrackListModel::formatDuration(static_cast<qint64>(duration))));
|
||||
}
|
||||
|
||||
void MainToolBar::setVolume(int volume)
|
||||
{
|
||||
m_volume->setValue(volume);
|
||||
}
|
||||
// ---- private slots ----
|
||||
|
||||
// --- private slots ---
|
||||
|
||||
void MainToolBar::onPlayPause(bool)
|
||||
void MainToolBar::onPlayPause()
|
||||
{
|
||||
if (m_playing) {
|
||||
m_backend->pause();
|
||||
} else {
|
||||
m_backend->resume();
|
||||
}
|
||||
if (m_playing) m_backend->pause();
|
||||
else m_backend->resume();
|
||||
}
|
||||
|
||||
void MainToolBar::onPrevious()
|
||||
{
|
||||
// TODO: wire up to a queue / playlist
|
||||
if (!m_queue->canGoPrev()) return;
|
||||
const QJsonObject track = m_queue->stepBack();
|
||||
const qint64 id = static_cast<qint64>(track["id"].toDouble());
|
||||
if (id > 0)
|
||||
m_backend->playTrack(id, AppSettings::instance().preferredFormat());
|
||||
}
|
||||
|
||||
void MainToolBar::onNext()
|
||||
{
|
||||
// TODO: wire up to a queue / playlist
|
||||
if (!m_queue->canGoNext()) return;
|
||||
const QJsonObject track = m_queue->advance();
|
||||
const qint64 id = static_cast<qint64>(track["id"].toDouble());
|
||||
if (id > 0)
|
||||
m_backend->playTrack(id, AppSettings::instance().preferredFormat());
|
||||
}
|
||||
|
||||
void MainToolBar::onProgressReleased()
|
||||
{
|
||||
m_seeking = false;
|
||||
// Seek is not yet implemented in the Rust player, but we can at least
|
||||
// update the displayed position optimistically.
|
||||
}
|
||||
|
||||
void MainToolBar::onVolumeChanged(int volume)
|
||||
@@ -167,7 +202,37 @@ void MainToolBar::onPositionChanged(quint64 position, quint64 duration)
|
||||
|
||||
void MainToolBar::onTrackFinished()
|
||||
{
|
||||
setPlaying(false);
|
||||
m_progress->setValue(0);
|
||||
m_timeLabel->setText("0:00 / 0:00");
|
||||
// Auto-advance queue
|
||||
if (m_queue->canGoNext()) {
|
||||
onNext();
|
||||
} else {
|
||||
setPlaying(false);
|
||||
m_progress->setValue(0);
|
||||
m_timeLabel->setText("0:00 / 0:00");
|
||||
}
|
||||
}
|
||||
|
||||
void MainToolBar::onQueueChanged()
|
||||
{
|
||||
m_previous->setEnabled(m_queue->canGoPrev());
|
||||
m_next->setEnabled(m_queue->canGoNext());
|
||||
}
|
||||
|
||||
void MainToolBar::onShuffleToggled(bool checked)
|
||||
{
|
||||
m_queue->setShuffle(checked);
|
||||
}
|
||||
|
||||
void MainToolBar::fetchAlbumArt(const QString &url)
|
||||
{
|
||||
m_nam->get(QNetworkRequest(QUrl(url)));
|
||||
}
|
||||
|
||||
void MainToolBar::onAlbumArtReady(QNetworkReply *reply)
|
||||
{
|
||||
reply->deleteLater();
|
||||
if (reply->error() != QNetworkReply::NoError) return;
|
||||
QPixmap pix;
|
||||
if (pix.loadFromData(reply->readAll()))
|
||||
m_artLabel->setPixmap(pix);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user