Merge branch 'refactor/mainwindow-setup'
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -38,6 +38,27 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
m_content = new MainContent(m_backend, m_queue, this);
|
||||
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) ----
|
||||
m_library = new List::Library(m_backend, 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->hide();
|
||||
addDockWidget(Qt::RightDockWidgetArea, m_sidePanel);
|
||||
}
|
||||
|
||||
setupMenuBar();
|
||||
statusBar()->showMessage(tr("Ready"));
|
||||
|
||||
// ---- Scrobbler ----
|
||||
void MainWindow::setupScrobbler()
|
||||
{
|
||||
m_scrobbler = new LastFmScrobbler(this);
|
||||
connect(m_backend, &QobuzBackend::trackChanged,
|
||||
m_scrobbler, &LastFmScrobbler::onTrackStarted);
|
||||
@@ -73,11 +93,13 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
connect(m_backend, &QobuzBackend::trackFinished,
|
||||
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,
|
||||
m_scrobbler, &LastFmScrobbler::onTrackFinished);
|
||||
}
|
||||
|
||||
// ---- Gapless Signal ----
|
||||
void MainWindow::setupGapless()
|
||||
{
|
||||
connect(m_backend, &QobuzBackend::positionChanged, this, [this](quint64 pos, quint64 dur) {
|
||||
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::loginError, this, &MainWindow::onLoginError);
|
||||
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) {
|
||||
statusBar()->showMessage(tr("Error: %1").arg(msg), 6000);
|
||||
});
|
||||
}
|
||||
|
||||
// ---- Library signals ----
|
||||
void MainWindow::connectLibrarySignals()
|
||||
{
|
||||
connect(m_library, &List::Library::userPlaylistIdsChanged,
|
||||
this, [this](const QSet<qint64> &playlistIds) {
|
||||
m_userPlaylistIds = playlistIds;
|
||||
@@ -167,52 +241,6 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
m_backend->getFavTracks();
|
||||
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] {
|
||||
m_showFavAlbumsOnLoad = true;
|
||||
m_backend->getFavAlbums();
|
||||
@@ -236,7 +264,10 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
m_content->showPlaylistBrowser();
|
||||
statusBar()->showMessage(tr("Browse Playlists"));
|
||||
});
|
||||
}
|
||||
|
||||
void MainWindow::connectContentSignals()
|
||||
{
|
||||
// ---- Track list → playback / playlist management ----
|
||||
connect(m_content->tracksList(), &List::Tracks::playTrackRequested,
|
||||
this, &MainWindow::onPlayTrackRequested);
|
||||
@@ -300,8 +331,10 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
// ---- Queue panel ----
|
||||
connect(m_queuePanel, &QueuePanel::skipToTrackRequested,
|
||||
this, &MainWindow::onPlayTrackRequested);
|
||||
}
|
||||
|
||||
// ---- Toolbar toggles ----
|
||||
void MainWindow::connectToolbarSignals()
|
||||
{
|
||||
connect(m_toolBar, &MainToolBar::searchToggled, this, &MainWindow::onSearchToggled);
|
||||
connect(m_toolBar, &MainToolBar::queueToggled,
|
||||
this, [this](bool v) { m_queuePanel->setVisible(v); });
|
||||
@@ -314,12 +347,6 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
|
||||
connect(m_toolBar, &MainToolBar::albumRequested, this, &MainWindow::onSearchAlbumSelected);
|
||||
connect(m_toolBar, &MainToolBar::artistRequested, this, &MainWindow::onSearchArtistSelected);
|
||||
|
||||
// Apply playback options from saved settings
|
||||
m_backend->setReplayGain(AppSettings::instance().replayGainEnabled());
|
||||
m_backend->setGapless(AppSettings::instance().gaplessEnabled());
|
||||
|
||||
tryRestoreSession();
|
||||
}
|
||||
|
||||
void MainWindow::setupMenuBar()
|
||||
|
||||
@@ -72,5 +72,13 @@ private:
|
||||
bool m_nextTrackPrefetched = false;
|
||||
|
||||
void setupMenuBar();
|
||||
void setupDocks();
|
||||
void setupScrobbler();
|
||||
void setupGapless();
|
||||
void setupMpris();
|
||||
void connectBackendSignals();
|
||||
void connectLibrarySignals();
|
||||
void connectContentSignals();
|
||||
void connectToolbarSignals();
|
||||
void tryRestoreSession();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user