feat: seeking support and Last.fm scrobbling

Seeking:
- Rust player: seek_requested/seek_target_secs atomics on PlayerStatus
- Decoder loop checks for seek each iteration, calls format.seek() and resets decoder
- New qobuz_backend_seek C FFI + QobuzBackend::seek(quint64)
- Progress slider onProgressReleased now seeks to the dragged position

Last.fm:
- LastFmScrobbler: now-playing + scrobble (50% or 240s threshold, min 30s)
- API signature follows Last.fm spec (sorted params, md5)
- Settings dialog: API key/secret, username/password, Connect button with status
- AppSettings: lastfm/enabled, api_key, api_secret, session_key
- Scrobbler wired to trackChanged, positionChanged, trackFinished in MainWindow

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
joren
2026-03-24 01:13:06 +01:00
parent ecaee4d907
commit b9b47f80e7
14 changed files with 357 additions and 10 deletions

View File

@@ -1,15 +1,20 @@
#include "settings.hpp"
#include "../util/settings.hpp"
#include "../scrobbler/lastfm.hpp"
#include <QVBoxLayout>
#include <QFormLayout>
#include <QDialogButtonBox>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QNetworkReply>
SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent)
{
setWindowTitle(tr("Settings"));
setMinimumWidth(400);
setMinimumWidth(420);
m_nam = new QNetworkAccessManager(this);
auto *layout = new QVBoxLayout(this);
@@ -30,25 +35,98 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QDialog(parent)
break;
}
}
playLayout->addRow(tr("Preferred quality:"), m_formatBox);
layout->addWidget(playGroup);
// --- Last.fm group ---
auto *lfmGroup = new QGroupBox(tr("Last.fm Scrobbling"), this);
auto *lfmLayout = new QFormLayout(lfmGroup);
m_lastFmEnabled = new QCheckBox(tr("Enable scrobbling"), lfmGroup);
m_lastFmEnabled->setChecked(AppSettings::instance().lastFmEnabled());
lfmLayout->addRow(m_lastFmEnabled);
m_lastFmApiKey = new QLineEdit(AppSettings::instance().lastFmApiKey(), lfmGroup);
m_lastFmApiKey->setPlaceholderText(tr("Get one at last.fm/api"));
lfmLayout->addRow(tr("API Key:"), m_lastFmApiKey);
m_lastFmApiSecret = new QLineEdit(AppSettings::instance().lastFmApiSecret(), lfmGroup);
m_lastFmApiSecret->setEchoMode(QLineEdit::Password);
lfmLayout->addRow(tr("API Secret:"), m_lastFmApiSecret);
m_lastFmUsername = new QLineEdit(lfmGroup);
m_lastFmUsername->setPlaceholderText(tr("Last.fm username"));
lfmLayout->addRow(tr("Username:"), m_lastFmUsername);
m_lastFmPassword = new QLineEdit(lfmGroup);
m_lastFmPassword->setEchoMode(QLineEdit::Password);
m_lastFmPassword->setPlaceholderText(tr("Last.fm password"));
lfmLayout->addRow(tr("Password:"), m_lastFmPassword);
auto *connectRow = new QHBoxLayout;
m_lastFmConnect = new QPushButton(tr("Connect"), lfmGroup);
m_lastFmStatus = new QLabel(lfmGroup);
const bool hasSession = !AppSettings::instance().lastFmSessionKey().isEmpty();
m_lastFmStatus->setText(hasSession ? tr("Connected ✓") : tr("Not connected"));
m_lastFmStatus->setStyleSheet(hasSession ? "color: green;" : "color: gray;");
connectRow->addWidget(m_lastFmConnect);
connectRow->addWidget(m_lastFmStatus, 1);
lfmLayout->addRow(connectRow);
layout->addWidget(lfmGroup);
layout->addStretch();
auto *buttons = new QDialogButtonBox(
QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
layout->addWidget(buttons);
connect(buttons, &QDialogButtonBox::accepted, this, [this] {
applyChanges();
accept();
});
connect(m_lastFmConnect, &QPushButton::clicked, this, &SettingsDialog::onLastFmConnect);
connect(buttons, &QDialogButtonBox::accepted, this, [this] { applyChanges(); accept(); });
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
void SettingsDialog::applyChanges()
{
AppSettings::instance().setPreferredFormat(
m_formatBox->currentData().toInt());
AppSettings::instance().setPreferredFormat(m_formatBox->currentData().toInt());
AppSettings::instance().setLastFmEnabled(m_lastFmEnabled->isChecked());
AppSettings::instance().setLastFmApiKey(m_lastFmApiKey->text().trimmed());
AppSettings::instance().setLastFmApiSecret(m_lastFmApiSecret->text().trimmed());
}
void SettingsDialog::onLastFmConnect()
{
const QString apiKey = m_lastFmApiKey->text().trimmed();
const QString apiSecret = m_lastFmApiSecret->text().trimmed();
const QString username = m_lastFmUsername->text().trimmed();
const QString password = m_lastFmPassword->text();
if (apiKey.isEmpty() || apiSecret.isEmpty() || username.isEmpty() || password.isEmpty()) {
m_lastFmStatus->setText(tr("Fill in all fields first."));
m_lastFmStatus->setStyleSheet("color: red;");
return;
}
// Temporarily apply so the scrobbler util can use them for signing
AppSettings::instance().setLastFmApiKey(apiKey);
AppSettings::instance().setLastFmApiSecret(apiSecret);
m_lastFmConnect->setEnabled(false);
m_lastFmStatus->setText(tr("Connecting…"));
m_lastFmStatus->setStyleSheet("color: gray;");
// Reuse LastFmScrobbler::authenticate as a utility (temp instance)
auto *tmp = new LastFmScrobbler(this);
tmp->authenticate(username, password, [this, tmp](bool ok, const QString &err) {
tmp->deleteLater();
m_lastFmConnect->setEnabled(true);
if (ok) {
m_lastFmStatus->setText(tr("Connected ✓"));
m_lastFmStatus->setStyleSheet("color: green;");
} else {
m_lastFmStatus->setText(tr("Error: %1").arg(err));
m_lastFmStatus->setStyleSheet("color: red;");
}
});
}

View File

@@ -3,6 +3,10 @@
#include <QDialog>
#include <QComboBox>
#include <QLabel>
#include <QLineEdit>
#include <QCheckBox>
#include <QPushButton>
#include <QNetworkAccessManager>
class SettingsDialog : public QDialog
{
@@ -12,7 +16,19 @@ public:
explicit SettingsDialog(QWidget *parent = nullptr);
private:
// Playback
QComboBox *m_formatBox = nullptr;
// Last.fm
QCheckBox *m_lastFmEnabled = nullptr;
QLineEdit *m_lastFmApiKey = nullptr;
QLineEdit *m_lastFmApiSecret = nullptr;
QLineEdit *m_lastFmUsername = nullptr;
QLineEdit *m_lastFmPassword = nullptr;
QPushButton *m_lastFmConnect = nullptr;
QLabel *m_lastFmStatus = nullptr;
QNetworkAccessManager *m_nam = nullptr;
void applyChanges();
void onLastFmConnect();
};