From 4a9d38bbdda41c1cf15b81d9903adc30f0d4aece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bara?= Date: Mon, 24 Jan 2011 18:32:09 +0000 Subject: [PATCH] final refactoring stage of cover changing code (common QAction*s) reset URL in 'Cover from URL' dialog on reentrance --- src/ui/albumcoverchoicecontroller.cpp | 9 ++++++++ src/ui/albumcoverchoicecontroller.h | 18 ++++++++++----- src/ui/albumcovermanager.cpp | 31 +++++++++++++------------- src/ui/coverfromurldialog.cpp | 3 +++ src/ui/edittagdialog.cpp | 32 ++++++++++++++------------- src/widgets/nowplayingwidget.cpp | 30 ++++++++++++------------- 6 files changed, 72 insertions(+), 51 deletions(-) diff --git a/src/ui/albumcoverchoicecontroller.cpp b/src/ui/albumcoverchoicecontroller.cpp index 0ff829b68..5e8af774f 100644 --- a/src/ui/albumcoverchoicecontroller.cpp +++ b/src/ui/albumcoverchoicecontroller.cpp @@ -53,6 +53,15 @@ AlbumCoverChoiceController::~AlbumCoverChoiceController() { } +QList AlbumCoverChoiceController::PrepareAlbumChoiceMenu(QObject* parent) { + return QList() + << new QAction(IconLoader::Load("document-open"), tr("Load cover from disk..."), parent) + << new QAction(IconLoader::Load("download"), tr("Load cover from URL..."), parent) + << new QAction(IconLoader::Load("find"), tr("Search for album covers..."), parent) + << new QAction(IconLoader::Load("list-remove"), tr("Unset cover"), parent) + << new QAction(IconLoader::Load("zoom-in"), tr("Show fullsize..."), parent); +} + QString AlbumCoverChoiceController::LoadCoverFromFile(Song* song) { QString dir; diff --git a/src/ui/albumcoverchoicecontroller.h b/src/ui/albumcoverchoicecontroller.h index 6352c52f0..14602510a 100644 --- a/src/ui/albumcoverchoicecontroller.h +++ b/src/ui/albumcoverchoicecontroller.h @@ -18,6 +18,8 @@ #ifndef ALBUMCOVERCHOICECONTROLLER_H #define ALBUMCOVERCHOICECONTROLLER_H +#include +#include #include class AlbumCoverFetcher; @@ -26,12 +28,7 @@ class CoverFromURLDialog; class LibraryBackend; class Song; -// Controller for the common album cover related menu options. This includes: -// - loading cover from file -// - loading cover from URL -// - searching for cover using last.fm -// - unsetting the cover manually -// - showing the cover in original size +// Controller for the common album cover related menu options. class AlbumCoverChoiceController : public QWidget { Q_OBJECT @@ -42,6 +39,15 @@ class AlbumCoverChoiceController : public QWidget { static const char* kImageFileFilter; static const char* kAllFilesFilter; + // Returns QAction* for every operation implemented by this controller. + // The list contains QAction* for: + // 1. loading cover from file + // 2. loading cover from URL + // 3. searching for cover using last.fm + // 4. unsetting the cover manually + // 5. showing the cover in original size + QList PrepareAlbumChoiceMenu(QObject* parent); + // All of the methods below require a currently selected song as an // input parameter. Also - LoadCoverFromFile, LoadCoverFromURL, // SearchForCover, UnsetCover and SaveCover all update manual path diff --git a/src/ui/albumcovermanager.cpp b/src/ui/albumcovermanager.cpp index 0e1c39413..ec6beb636 100644 --- a/src/ui/albumcovermanager.cpp +++ b/src/ui/albumcovermanager.cpp @@ -121,25 +121,26 @@ void AlbumCoverManager::Init() { ui_->view->setMenu(view_menu); // Context menu - cover_from_file_ = context_menu_->addAction( - IconLoader::Load("document-open"), tr("Load cover from disk..."), - this, SLOT(LoadCoverFromFile())); - cover_from_url_ = context_menu_->addAction( - IconLoader::Load("download"), tr("Load cover from URL..."), - this, SLOT(LoadCoverFromURL())); - search_for_cover_ = context_menu_->addAction( - IconLoader::Load("find"), tr("Search for album covers..."), - this, SLOT(SearchForCover())); - unset_cover_ = context_menu_->addAction( - IconLoader::Load("list-remove"), tr("Unset cover"), - this, SLOT(UnsetCover())); - show_cover_ = context_menu_->addAction( - IconLoader::Load("zoom-in"), tr("Show fullsize..."), - this, SLOT(ShowCover())); + QList actions = album_cover_choice_controller_->PrepareAlbumChoiceMenu(this); + + cover_from_file_ = actions[0]; + cover_from_url_ = actions[1]; + search_for_cover_ = actions[2]; + unset_cover_ = actions[3]; + show_cover_ = actions[4]; + + connect(cover_from_file_, SIGNAL(triggered()), this, SLOT(LoadCoverFromFile())); + connect(cover_from_url_, SIGNAL(triggered()), this, SLOT(LoadCoverFromURL())); + connect(search_for_cover_, SIGNAL(triggered()), this, SLOT(SearchForCover())); + connect(unset_cover_, SIGNAL(triggered()), this, SLOT(UnsetCover())); + connect(show_cover_, SIGNAL(triggered()), this, SLOT(ShowCover())); + + context_menu_->addActions(actions); context_menu_->addSeparator(); context_menu_->addAction(ui_->action_load); context_menu_->addAction(ui_->action_add_to_playlist); + ui_->albums->installEventFilter(this); // Connections diff --git a/src/ui/coverfromurldialog.cpp b/src/ui/coverfromurldialog.cpp index 285ed001f..680dbbd0c 100644 --- a/src/ui/coverfromurldialog.cpp +++ b/src/ui/coverfromurldialog.cpp @@ -39,7 +39,10 @@ CoverFromURLDialog::~CoverFromURLDialog() { } QImage CoverFromURLDialog::Exec() { + // reset state + ui_->url->setText("");; last_image_ = QImage(); + exec(); return last_image_; } diff --git a/src/ui/edittagdialog.cpp b/src/ui/edittagdialog.cpp index 5e8b12e9b..584ac584f 100644 --- a/src/ui/edittagdialog.cpp +++ b/src/ui/edittagdialog.cpp @@ -132,21 +132,23 @@ EditTagDialog::EditTagDialog(QWidget* parent) // Set up the album cover menu cover_menu_ = new QMenu(this); - cover_from_file_ = cover_menu_->addAction( - IconLoader::Load("document-open"), tr("Load cover from disk..."), - this, SLOT(LoadCoverFromFile())); - cover_from_url_ = cover_menu_->addAction( - IconLoader::Load("download"), tr("Load cover from URL..."), - this, SLOT(LoadCoverFromURL())); - search_for_cover_ = cover_menu_->addAction( - IconLoader::Load("find"), tr("Search for album covers..."), - this, SLOT(SearchForCover())); - unset_cover_ = cover_menu_->addAction( - IconLoader::Load("list-remove"), tr("Unset cover"), - this, SLOT(UnsetCover())); - show_cover_ = cover_menu_->addAction( - IconLoader::Load("zoom-in"), tr("Show fullsize..."), - this, SLOT(ShowCover())); + + QList actions = album_cover_choice_controller_->PrepareAlbumChoiceMenu(this); + + cover_from_file_ = actions[0]; + cover_from_url_ = actions[1]; + search_for_cover_ = actions[2]; + unset_cover_ = actions[3]; + show_cover_ = actions[4]; + + connect(cover_from_file_, SIGNAL(triggered()), this, SLOT(LoadCoverFromFile())); + connect(cover_from_url_, SIGNAL(triggered()), this, SLOT(LoadCoverFromURL())); + connect(search_for_cover_, SIGNAL(triggered()), this, SLOT(SearchForCover())); + connect(unset_cover_, SIGNAL(triggered()), this, SLOT(UnsetCover())); + connect(show_cover_, SIGNAL(triggered()), this, SLOT(ShowCover())); + + cover_menu_->addActions(actions); + ui_->summary_art_button->setMenu(cover_menu_); ui_->art->installEventFilter(this); diff --git a/src/widgets/nowplayingwidget.cpp b/src/widgets/nowplayingwidget.cpp index 3d5c57445..81f94075a 100644 --- a/src/widgets/nowplayingwidget.cpp +++ b/src/widgets/nowplayingwidget.cpp @@ -93,24 +93,24 @@ NowPlayingWidget::NowPlayingWidget(QWidget *parent) menu_->addActions(mode_group->actions()); menu_->addSeparator(); - cover_from_file_ = menu_->addAction( - IconLoader::Load("document-open"), tr("Load cover from disk..."), - this, SLOT(LoadCoverFromFile())); - cover_from_url_ = menu_->addAction( - IconLoader::Load("download"), tr("Load cover from URL..."), - this, SLOT(LoadCoverFromURL())); - search_for_cover_ = menu_->addAction( - IconLoader::Load("find"), tr("Search for album covers..."), - this, SLOT(SearchForCover())); - unset_cover_ = menu_->addAction( - IconLoader::Load("list-remove"), tr("Unset cover"), - this, SLOT(UnsetCover())); - show_cover_ = menu_->addAction( - IconLoader::Load("zoom-in"), tr("Show fullsize..."), - this, SLOT(ShowCover())); + QList actions = album_cover_choice_controller_->PrepareAlbumChoiceMenu(this); + cover_from_file_ = actions[0]; + cover_from_url_ = actions[1]; + search_for_cover_ = actions[2]; + unset_cover_ = actions[3]; + show_cover_ = actions[4]; + + connect(cover_from_file_, SIGNAL(triggered()), this, SLOT(LoadCoverFromFile())); + connect(cover_from_url_, SIGNAL(triggered()), this, SLOT(LoadCoverFromURL())); + connect(search_for_cover_, SIGNAL(triggered()), this, SLOT(SearchForCover())); + connect(unset_cover_, SIGNAL(triggered()), this, SLOT(UnsetCover())); + connect(show_cover_, SIGNAL(triggered()), this, SLOT(ShowCover())); + + menu_->addActions(actions); menu_->addSeparator(); above_statusbar_action_ = menu_->addAction(tr("Show above status bar")); + above_statusbar_action_->setCheckable(true); connect(above_statusbar_action_, SIGNAL(toggled(bool)), SLOT(ShowAboveStatusBar(bool))); above_statusbar_action_->setChecked(s.value("above_status_bar", false).toBool());