diff --git a/src/internet/core/cloudfileservice.cpp b/src/internet/core/cloudfileservice.cpp index 2809beba0..054799805 100644 --- a/src/internet/core/cloudfileservice.cpp +++ b/src/internet/core/cloudfileservice.cpp @@ -97,18 +97,22 @@ void CloudFileService::LazyPopulate(QStandardItem* item) { } } +void CloudFileService::PopulateContextMenu() { + context_menu_->addActions(GetPlaylistActions()); + context_menu_->addAction(IconLoader::Load("download", IconLoader::Base), + tr("Cover Manager"), this, SLOT(ShowCoverManager())); + context_menu_->addSeparator(); + context_menu_->addAction(IconLoader::Load("configure", IconLoader::Base), + tr("Configure..."), this, + SLOT(ShowSettingsDialog())); +} + void CloudFileService::ShowContextMenu(const QPoint& global_pos) { if (!context_menu_) { context_menu_.reset(new QMenu); - context_menu_->addActions(GetPlaylistActions()); - context_menu_->addAction(IconLoader::Load("download", IconLoader::Base), - tr("Cover Manager"), this, - SLOT(ShowCoverManager())); - context_menu_->addSeparator(); - context_menu_->addAction(IconLoader::Load("configure", IconLoader::Base), - tr("Configure..."), this, - SLOT(ShowSettingsDialog())); + PopulateContextMenu(); } + UpdateContextMenu(); context_menu_->popup(global_pos); } diff --git a/src/internet/core/cloudfileservice.h b/src/internet/core/cloudfileservice.h index 75eeadd95..d88a0d854 100644 --- a/src/internet/core/cloudfileservice.h +++ b/src/internet/core/cloudfileservice.h @@ -67,6 +67,11 @@ class CloudFileService : public InternetService { QString GuessMimeTypeForFile(const QString& filename) const; void AbortReadTagsReplies(); + // Called once when context menu is created + virtual void PopulateContextMenu(); + // Called every time context menu is shown + virtual void UpdateContextMenu(){}; + protected slots: void ShowCoverManager(); void AddToPlaylist(QMimeData* mime); diff --git a/src/internet/googledrive/googledriveservice.cpp b/src/internet/googledrive/googledriveservice.cpp index 808688605..1fe9c3f5f 100644 --- a/src/internet/googledrive/googledriveservice.cpp +++ b/src/internet/googledrive/googledriveservice.cpp @@ -210,29 +210,27 @@ QUrl GoogleDriveService::GetStreamingUrlFromSongId(const QString& id) { return QUrl(response->file().download_url()); } -void GoogleDriveService::ShowContextMenu(const QPoint& global_pos) { - if (!context_menu_) { - context_menu_.reset(new QMenu); - context_menu_->addActions(GetPlaylistActions()); - open_in_drive_action_ = context_menu_->addAction( - IconLoader::Load("googledrive", IconLoader::Provider), - tr("Open in Google Drive"), this, SLOT(OpenWithDrive())); - context_menu_->addSeparator(); - update_action_ = context_menu_->addAction( - IconLoader::Load("view-refresh", IconLoader::Base), - tr("Check for updates"), this, SLOT(CheckForUpdates())); - full_rescan_action_ = context_menu_->addAction( - IconLoader::Load("view-refresh", IconLoader::Base), - tr("Do a full rescan..."), this, SLOT(FullRescanRequested())); - context_menu_->addSeparator(); - context_menu_->addAction(IconLoader::Load("download", IconLoader::Base), - tr("Cover Manager"), this, - SLOT(ShowCoverManager())); - context_menu_->addAction(IconLoader::Load("configure", IconLoader::Base), - tr("Configure..."), this, - SLOT(ShowSettingsDialog())); - } +void GoogleDriveService::PopulateContextMenu() { + context_menu_->addActions(GetPlaylistActions()); + open_in_drive_action_ = context_menu_->addAction( + IconLoader::Load("googledrive", IconLoader::Provider), + tr("Open in Google Drive"), this, SLOT(OpenWithDrive())); + context_menu_->addSeparator(); + update_action_ = context_menu_->addAction( + IconLoader::Load("view-refresh", IconLoader::Base), + tr("Check for updates"), this, SLOT(CheckForUpdates())); + full_rescan_action_ = context_menu_->addAction( + IconLoader::Load("view-refresh", IconLoader::Base), + tr("Do a full rescan..."), this, SLOT(FullRescanRequested())); + context_menu_->addSeparator(); + context_menu_->addAction(IconLoader::Load("download", IconLoader::Base), + tr("Cover Manager"), this, SLOT(ShowCoverManager())); + context_menu_->addAction(IconLoader::Load("configure", IconLoader::Base), + tr("Configure..."), this, + SLOT(ShowSettingsDialog())); +} +void GoogleDriveService::UpdateContextMenu() { // Only show some actions if there are real songs selected bool songs_selected = false; for (const QModelIndex& index : model()->selected_indexes()) { @@ -246,8 +244,6 @@ void GoogleDriveService::ShowContextMenu(const QPoint& global_pos) { open_in_drive_action_->setEnabled(songs_selected); update_action_->setEnabled(!is_indexing()); full_rescan_action_->setEnabled(!is_indexing()); - - context_menu_->popup(global_pos); } void GoogleDriveService::OpenWithDrive() { diff --git a/src/internet/googledrive/googledriveservice.h b/src/internet/googledrive/googledriveservice.h index a3324b4e1..c229947b0 100644 --- a/src/internet/googledrive/googledriveservice.h +++ b/src/internet/googledrive/googledriveservice.h @@ -40,7 +40,6 @@ class GoogleDriveService : public CloudFileService { static const char* kSettingsGroup; virtual bool has_credentials() const; - virtual void ShowContextMenu(const QPoint& global_pos); google_drive::Client* client() const { return client_; } QString refresh_token() const; @@ -70,6 +69,9 @@ class GoogleDriveService : public CloudFileService { void RefreshAuthorisation(const QString& refresh_token); void ListChanges(const QString& cursor); + void PopulateContextMenu() override; + void UpdateContextMenu() override; + google_drive::Client* client_; QAction* open_in_drive_action_;