From 05e450c3c3dcc0de8955d77db8cb5a11cc2816f2 Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Wed, 17 Mar 2021 20:05:42 -0700 Subject: [PATCH] internet/core: Move core ShowContextMenu to base class Move CloudFileService::ShowContextMenu to the base class so that all services can utilize the pattern established in CloudFileService. ShowContextMenu creates the menu if it doesn't exist then calls an overridable method to populate the content. It then calls an update method before showing the menu. --- src/internet/core/cloudfileservice.cpp | 9 --------- src/internet/core/cloudfileservice.h | 5 +---- src/internet/core/internetservice.cpp | 9 +++++++++ src/internet/core/internetservice.h | 8 +++++++- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/internet/core/cloudfileservice.cpp b/src/internet/core/cloudfileservice.cpp index 054799805..936353fc6 100644 --- a/src/internet/core/cloudfileservice.cpp +++ b/src/internet/core/cloudfileservice.cpp @@ -107,15 +107,6 @@ void CloudFileService::PopulateContextMenu() { SLOT(ShowSettingsDialog())); } -void CloudFileService::ShowContextMenu(const QPoint& global_pos) { - if (!context_menu_) { - context_menu_.reset(new QMenu); - PopulateContextMenu(); - } - UpdateContextMenu(); - context_menu_->popup(global_pos); -} - void CloudFileService::ShowCoverManager() { if (!cover_manager_) { cover_manager_.reset(new AlbumCoverManager(app_, library_backend_.get())); diff --git a/src/internet/core/cloudfileservice.h b/src/internet/core/cloudfileservice.h index efc18faab..3363d6d3e 100644 --- a/src/internet/core/cloudfileservice.h +++ b/src/internet/core/cloudfileservice.h @@ -45,7 +45,6 @@ class CloudFileService : public InternetService { // InternetService virtual QStandardItem* CreateRootItem(); virtual void LazyPopulate(QStandardItem* item); - virtual void ShowContextMenu(const QPoint& point); virtual bool has_credentials() const = 0; bool is_indexing() const { return indexing_task_id_ != -1; } @@ -68,9 +67,7 @@ class CloudFileService : public InternetService { void AbortReadTagsReplies(); // Called once when context menu is created - virtual void PopulateContextMenu(); - // Called every time context menu is shown - virtual void UpdateContextMenu(){}; + virtual void PopulateContextMenu() override; protected slots: void ShowCoverManager(); diff --git a/src/internet/core/internetservice.cpp b/src/internet/core/internetservice.cpp index ed9e07e61..22e05c7e3 100644 --- a/src/internet/core/internetservice.cpp +++ b/src/internet/core/internetservice.cpp @@ -88,6 +88,15 @@ void InternetService::ShowUrlBox(const QString& title, const QString& url) { } } +void InternetService::ShowContextMenu(const QPoint& global_pos) { + if (!context_menu_) { + context_menu_.reset(new QMenu); + PopulateContextMenu(); + } + UpdateContextMenu(); + context_menu_->popup(global_pos); +} + QList InternetService::GetPlaylistActions() { return QList() << GetAppendToPlaylistAction() << GetReplacePlaylistAction() diff --git a/src/internet/core/internetservice.h b/src/internet/core/internetservice.h index 6552b5b22..1704e2803 100644 --- a/src/internet/core/internetservice.h +++ b/src/internet/core/internetservice.h @@ -64,7 +64,8 @@ class InternetService : public QObject { virtual void LazyPopulate(QStandardItem* parent) = 0; virtual bool has_initial_load_settings() const { return false; } virtual void InitialLoadSettings() {} - virtual void ShowContextMenu(const QPoint& global_pos) {} + virtual void ShowContextMenu(const QPoint& global_pos); + // Create a generator for smart playlists virtual smart_playlists::GeneratorPtr CreateGenerator(QStandardItem* item) { return smart_playlists::GeneratorPtr(); @@ -103,6 +104,11 @@ class InternetService : public QObject { void OpenInNewPlaylist(); protected: + // Called once when context menu is created + virtual void PopulateContextMenu(){}; + // Called every time context menu is shown + virtual void UpdateContextMenu(){}; + // Returns all the playlist insertion related QActions (see below). QList GetPlaylistActions();