diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8d106d4..fbe2474 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -347,6 +347,15 @@ void MainWindow::connectToolbarSignals() connect(m_toolBar, &MainToolBar::albumRequested, this, &MainWindow::onSearchAlbumSelected); connect(m_toolBar, &MainToolBar::artistRequested, this, &MainWindow::onSearchArtistSelected); + connect(m_toolBar, &MainToolBar::addToPlaylistRequested, + this, [this](qint64 trackId, qint64 playlistId) { + m_backend->addTrackToPlaylist(playlistId, trackId); + statusBar()->showMessage(tr("Adding track to playlist…"), 3000); + }); + connect(m_toolBar, &MainToolBar::favTrackRequested, + this, [this](qint64 trackId) { + m_backend->addFavTrack(trackId); + }); } void MainWindow::setupMenuBar() @@ -629,4 +638,5 @@ void MainWindow::onUserPlaylistsChanged(const QVector> &p m_userPlaylists = playlists; m_content->tracksList()->setUserPlaylists(playlists); m_sidePanel->searchTab()->setUserPlaylists(playlists); + m_toolBar->setUserPlaylists(playlists); } diff --git a/src/view/maintoolbar.cpp b/src/view/maintoolbar.cpp index ee691b3..e08bad3 100644 --- a/src/view/maintoolbar.cpp +++ b/src/view/maintoolbar.cpp @@ -41,16 +41,63 @@ MainToolBar::MainToolBar(QobuzBackend *backend, PlayQueue *queue, QWidget *paren connect(m_trackLabel, &QLabel::customContextMenuRequested, this, [this](const QPoint &pos) { if (m_currentTrack.isEmpty()) return; - QMenu menu(this); + + const qint64 trackId = static_cast(m_currentTrack["id"].toDouble()); const QString albumId = m_currentTrack["album"].toObject()["id"].toString(); + const QString albumTitle = m_currentTrack["album"].toObject()["title"].toString(); const qint64 artistId = static_cast( m_currentTrack["performer"].toObject()["id"].toDouble()); - if (!albumId.isEmpty()) - menu.addAction(tr("Go to Album"), this, [this, albumId] { emit albumRequested(albumId); }); - if (artistId > 0) - menu.addAction(tr("Go to Artist"), this, [this, artistId] { emit artistRequested(artistId); }); - if (!menu.isEmpty()) - menu.exec(m_trackLabel->mapToGlobal(pos)); + const QString artistName = m_currentTrack["performer"].toObject()["name"].toString(); + + QMenu menu(this); + + auto *playNext = menu.addAction(QIcon(":/res/icons/media-skip-forward.svg"), tr("Play next")); + auto *addQueue = menu.addAction(QIcon(":/res/icons/media-playlist-append.svg"), tr("Add to queue")); + menu.addSeparator(); + + auto *addFav = menu.addAction(QIcon(":/res/icons/starred-symbolic.svg"), tr("Add to favorites")); + connect(addFav, &QAction::triggered, this, [this, trackId] { + emit favTrackRequested(trackId); + }); + + if (!albumId.isEmpty() || artistId > 0) + menu.addSeparator(); + if (!albumId.isEmpty()) { + auto *openAlbum = menu.addAction( + QIcon(":/res/icons/view-media-album-cover.svg"), + tr("Open album: %1").arg(QString(albumTitle).replace(QLatin1Char('&'), QStringLiteral("&&")))); + connect(openAlbum, &QAction::triggered, this, [this, albumId] { + emit albumRequested(albumId); + }); + } + if (artistId > 0) { + auto *openArtist = menu.addAction( + QIcon(":/res/icons/view-media-artist.svg"), + tr("Open artist: %1").arg(QString(artistName).replace(QLatin1Char('&'), QStringLiteral("&&")))); + connect(openArtist, &QAction::triggered, this, [this, artistId] { + emit artistRequested(artistId); + }); + } + + if (!m_userPlaylists.isEmpty()) { + menu.addSeparator(); + auto *plMenu = menu.addMenu(QIcon(":/res/icons/media-playlist-append.svg"), tr("Add to playlist")); + for (const auto &pl : m_userPlaylists) { + auto *act = plMenu->addAction(QString(pl.second).replace(QLatin1Char('&'), QStringLiteral("&&"))); + connect(act, &QAction::triggered, this, [this, trackId, plId = pl.first] { + emit addToPlaylistRequested(trackId, plId); + }); + } + } + + connect(playNext, &QAction::triggered, this, [this] { + m_queue->playNext(m_currentTrack); + }); + connect(addQueue, &QAction::triggered, this, [this] { + m_queue->addToQueue(m_currentTrack); + }); + + menu.exec(m_trackLabel->mapToGlobal(pos)); }); addSeparator(); diff --git a/src/view/maintoolbar.hpp b/src/view/maintoolbar.hpp index cbaa950..3e3f4d2 100644 --- a/src/view/maintoolbar.hpp +++ b/src/view/maintoolbar.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include class MainToolBar : public QToolBar @@ -27,11 +28,15 @@ public: void setQueueToggleChecked(bool checked); void setSearchToggleChecked(bool checked); + void setUserPlaylists(const QVector> &playlists) { m_userPlaylists = playlists; } + signals: void searchToggled(bool visible); void queueToggled(bool visible); void albumRequested(const QString &albumId); void artistRequested(qint64 artistId); + void addToPlaylistRequested(qint64 trackId, qint64 playlistId); + void favTrackRequested(qint64 trackId); protected: void resizeEvent(QResizeEvent *event) override; @@ -93,5 +98,7 @@ private: qint64 m_pendingSeekStartedMs = 0; bool m_fetchingAutoplay = false; + QVector> m_userPlaylists; + void requestAutoplaySuggestions(); };