feat: add album favorites in header and unify browse controls
Some checks failed
Build for Windows / build-windows (push) Has been cancelled
Some checks failed
Build for Windows / build-windows (push) Has been cancelled
Improve album workflow with in-header favorite toggle, keep favorite state synced from backend, and normalize browse top-bar sizing while increasing audio output buffer headroom to reduce glitches.
This commit is contained in:
@@ -205,6 +205,7 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
#endif
|
||||
|
||||
connect(m_library, &List::Library::favAlbumsRequested, this, [this] {
|
||||
m_showFavAlbumsOnLoad = true;
|
||||
m_backend->getFavAlbums();
|
||||
statusBar()->showMessage(tr("Loading favorite albums…"));
|
||||
});
|
||||
@@ -259,6 +260,19 @@ MainWindow::MainWindow(QobuzBackend *backend, QWidget *parent)
|
||||
this, &MainWindow::onSearchAlbumSelected);
|
||||
connect(m_content, &MainContent::artistRequested,
|
||||
this, &MainWindow::onSearchArtistSelected);
|
||||
connect(m_content, &MainContent::albumFavoriteToggled,
|
||||
this, [this](const QString &albumId, bool favorite) {
|
||||
if (favorite) {
|
||||
m_backend->addFavAlbum(albumId);
|
||||
m_favAlbumIds.insert(albumId);
|
||||
statusBar()->showMessage(tr("Added album to favorites"), 3000);
|
||||
} else {
|
||||
m_backend->removeFavAlbum(albumId);
|
||||
m_favAlbumIds.remove(albumId);
|
||||
statusBar()->showMessage(tr("Removed album from favorites"), 3000);
|
||||
}
|
||||
m_content->setFavAlbumIds(m_favAlbumIds);
|
||||
});
|
||||
connect(m_content, &MainContent::playlistRequested,
|
||||
this, [this](qint64 playlistId) {
|
||||
m_backend->getPlaylist(playlistId);
|
||||
@@ -337,6 +351,8 @@ void MainWindow::tryRestoreSession()
|
||||
m_backend->getUser(); // userLoaded will call m_library->refresh()
|
||||
else
|
||||
m_library->refresh();
|
||||
// Preload fav albums so the album page fav button is accurate immediately.
|
||||
m_backend->getFavAlbums();
|
||||
// Preload fav artists so the artist page fav button works immediately
|
||||
m_backend->getFavArtists();
|
||||
const QString name = AppSettings::instance().displayName();
|
||||
@@ -388,6 +404,8 @@ void MainWindow::onLoginSuccess(const QString &token, const QJsonObject &user)
|
||||
statusBar()->showMessage(tr("Signed in as %1").arg(
|
||||
displayName.isEmpty() ? email : displayName));
|
||||
m_library->refresh();
|
||||
m_backend->getFavAlbums();
|
||||
m_backend->getFavArtists();
|
||||
}
|
||||
|
||||
void MainWindow::onLoginError(const QString &error)
|
||||
@@ -449,9 +467,26 @@ void MainWindow::onFavTracksLoaded(const QJsonObject &result)
|
||||
|
||||
void MainWindow::onFavAlbumsLoaded(const QJsonObject &result)
|
||||
{
|
||||
m_content->showFavAlbums(result);
|
||||
statusBar()->showMessage(
|
||||
tr("%1 favorite albums").arg(result["total"].toInt()), 4000);
|
||||
// Always cache fav album IDs (needed by the album page fav button)
|
||||
m_favAlbumIds.clear();
|
||||
const QJsonArray items = result["items"].toArray();
|
||||
for (const QJsonValue &v : items) {
|
||||
const QJsonObject album = v.toObject();
|
||||
QString id = album["id"].toString();
|
||||
if (id.isEmpty() && album["id"].isDouble())
|
||||
id = QString::number(static_cast<qint64>(album["id"].toDouble()));
|
||||
if (!id.isEmpty())
|
||||
m_favAlbumIds.insert(id);
|
||||
}
|
||||
m_content->setFavAlbumIds(m_favAlbumIds);
|
||||
|
||||
// Only navigate to the fav albums page if the user explicitly requested it
|
||||
if (m_showFavAlbumsOnLoad) {
|
||||
m_showFavAlbumsOnLoad = false;
|
||||
m_content->showFavAlbums(result);
|
||||
statusBar()->showMessage(
|
||||
tr("%1 favorite albums").arg(result["total"].toInt()), 4000);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onFavArtistsLoaded(const QJsonObject &result)
|
||||
|
||||
Reference in New Issue
Block a user