cloudfileservices: Refactor context menu code
Add PopulateContextMenu, called once to populate the menu items, and UpdateContextMenu, called ever time a menu is shown, to allow service-specific behavior.
This commit is contained in:
parent
b57e66dd51
commit
c87409c896
|
@ -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) {
|
void CloudFileService::ShowContextMenu(const QPoint& global_pos) {
|
||||||
if (!context_menu_) {
|
if (!context_menu_) {
|
||||||
context_menu_.reset(new QMenu);
|
context_menu_.reset(new QMenu);
|
||||||
context_menu_->addActions(GetPlaylistActions());
|
PopulateContextMenu();
|
||||||
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()));
|
|
||||||
}
|
}
|
||||||
|
UpdateContextMenu();
|
||||||
context_menu_->popup(global_pos);
|
context_menu_->popup(global_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,11 @@ class CloudFileService : public InternetService {
|
||||||
QString GuessMimeTypeForFile(const QString& filename) const;
|
QString GuessMimeTypeForFile(const QString& filename) const;
|
||||||
void AbortReadTagsReplies();
|
void AbortReadTagsReplies();
|
||||||
|
|
||||||
|
// Called once when context menu is created
|
||||||
|
virtual void PopulateContextMenu();
|
||||||
|
// Called every time context menu is shown
|
||||||
|
virtual void UpdateContextMenu(){};
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void ShowCoverManager();
|
void ShowCoverManager();
|
||||||
void AddToPlaylist(QMimeData* mime);
|
void AddToPlaylist(QMimeData* mime);
|
||||||
|
|
|
@ -210,29 +210,27 @@ QUrl GoogleDriveService::GetStreamingUrlFromSongId(const QString& id) {
|
||||||
return QUrl(response->file().download_url());
|
return QUrl(response->file().download_url());
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoogleDriveService::ShowContextMenu(const QPoint& global_pos) {
|
void GoogleDriveService::PopulateContextMenu() {
|
||||||
if (!context_menu_) {
|
context_menu_->addActions(GetPlaylistActions());
|
||||||
context_menu_.reset(new QMenu);
|
open_in_drive_action_ = context_menu_->addAction(
|
||||||
context_menu_->addActions(GetPlaylistActions());
|
IconLoader::Load("googledrive", IconLoader::Provider),
|
||||||
open_in_drive_action_ = context_menu_->addAction(
|
tr("Open in Google Drive"), this, SLOT(OpenWithDrive()));
|
||||||
IconLoader::Load("googledrive", IconLoader::Provider),
|
context_menu_->addSeparator();
|
||||||
tr("Open in Google Drive"), this, SLOT(OpenWithDrive()));
|
update_action_ = context_menu_->addAction(
|
||||||
context_menu_->addSeparator();
|
IconLoader::Load("view-refresh", IconLoader::Base),
|
||||||
update_action_ = context_menu_->addAction(
|
tr("Check for updates"), this, SLOT(CheckForUpdates()));
|
||||||
IconLoader::Load("view-refresh", IconLoader::Base),
|
full_rescan_action_ = context_menu_->addAction(
|
||||||
tr("Check for updates"), this, SLOT(CheckForUpdates()));
|
IconLoader::Load("view-refresh", IconLoader::Base),
|
||||||
full_rescan_action_ = context_menu_->addAction(
|
tr("Do a full rescan..."), this, SLOT(FullRescanRequested()));
|
||||||
IconLoader::Load("view-refresh", IconLoader::Base),
|
context_menu_->addSeparator();
|
||||||
tr("Do a full rescan..."), this, SLOT(FullRescanRequested()));
|
context_menu_->addAction(IconLoader::Load("download", IconLoader::Base),
|
||||||
context_menu_->addSeparator();
|
tr("Cover Manager"), this, SLOT(ShowCoverManager()));
|
||||||
context_menu_->addAction(IconLoader::Load("download", IconLoader::Base),
|
context_menu_->addAction(IconLoader::Load("configure", IconLoader::Base),
|
||||||
tr("Cover Manager"), this,
|
tr("Configure..."), this,
|
||||||
SLOT(ShowCoverManager()));
|
SLOT(ShowSettingsDialog()));
|
||||||
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
|
// Only show some actions if there are real songs selected
|
||||||
bool songs_selected = false;
|
bool songs_selected = false;
|
||||||
for (const QModelIndex& index : model()->selected_indexes()) {
|
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);
|
open_in_drive_action_->setEnabled(songs_selected);
|
||||||
update_action_->setEnabled(!is_indexing());
|
update_action_->setEnabled(!is_indexing());
|
||||||
full_rescan_action_->setEnabled(!is_indexing());
|
full_rescan_action_->setEnabled(!is_indexing());
|
||||||
|
|
||||||
context_menu_->popup(global_pos);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GoogleDriveService::OpenWithDrive() {
|
void GoogleDriveService::OpenWithDrive() {
|
||||||
|
|
|
@ -40,7 +40,6 @@ class GoogleDriveService : public CloudFileService {
|
||||||
static const char* kSettingsGroup;
|
static const char* kSettingsGroup;
|
||||||
|
|
||||||
virtual bool has_credentials() const;
|
virtual bool has_credentials() const;
|
||||||
virtual void ShowContextMenu(const QPoint& global_pos);
|
|
||||||
|
|
||||||
google_drive::Client* client() const { return client_; }
|
google_drive::Client* client() const { return client_; }
|
||||||
QString refresh_token() const;
|
QString refresh_token() const;
|
||||||
|
@ -70,6 +69,9 @@ class GoogleDriveService : public CloudFileService {
|
||||||
void RefreshAuthorisation(const QString& refresh_token);
|
void RefreshAuthorisation(const QString& refresh_token);
|
||||||
void ListChanges(const QString& cursor);
|
void ListChanges(const QString& cursor);
|
||||||
|
|
||||||
|
void PopulateContextMenu() override;
|
||||||
|
void UpdateContextMenu() override;
|
||||||
|
|
||||||
google_drive::Client* client_;
|
google_drive::Client* client_;
|
||||||
|
|
||||||
QAction* open_in_drive_action_;
|
QAction* open_in_drive_action_;
|
||||||
|
|
Loading…
Reference in New Issue