mirror of
https://github.com/clementine-player/Clementine
synced 2025-01-31 19:45:31 +01:00
fixed an error where entering the Cover Searcher dialog without query would make it show the busy indicator forever
further refactoring of album cover changes (QMenu in controller)
This commit is contained in:
parent
4e9aef16cb
commit
2fec795b89
@ -25,41 +25,52 @@
|
||||
#include "ui/coverfromurldialog.h"
|
||||
#include "ui/iconloader.h"
|
||||
|
||||
#include <QAction>
|
||||
#include <QCryptographicHash>
|
||||
#include <QDialog>
|
||||
#include <QFileDialog>
|
||||
#include <QLabel>
|
||||
#include <QList>
|
||||
#include <QMenu>
|
||||
|
||||
const char* AlbumCoverChoiceController::kImageFileFilter =
|
||||
QT_TR_NOOP("Images (*.png *.jpg *.jpeg *.bmp *.gif *.xpm *.pbm *.pgm *.ppm *.xbm *.tiff)");
|
||||
const char* AlbumCoverChoiceController::kAllFilesFilter =
|
||||
QT_TR_NOOP("All files (*)");
|
||||
|
||||
AlbumCoverChoiceController::AlbumCoverChoiceController(LibraryBackend* library, QWidget* parent)
|
||||
AlbumCoverChoiceController::AlbumCoverChoiceController(QWidget* parent)
|
||||
: QWidget(parent),
|
||||
#ifdef HAVE_LIBLASTFM
|
||||
cover_searcher_(new AlbumCoverSearcher(QIcon(":/nocover.png"), this)),
|
||||
cover_fetcher_(new AlbumCoverFetcher(this)),
|
||||
#endif
|
||||
cover_from_url_dialog_(NULL),
|
||||
library_(library)
|
||||
library_(NULL),
|
||||
menu_(new QMenu(this))
|
||||
{
|
||||
#ifdef HAVE_LIBLASTFM
|
||||
cover_searcher_->Init(cover_fetcher_);
|
||||
#endif
|
||||
|
||||
cover_from_file_ = menu_->addAction(IconLoader::Load("document-open"), tr("Load cover from disk..."));
|
||||
cover_from_url_ = menu_->addAction(IconLoader::Load("download"), tr("Load cover from URL..."));
|
||||
search_for_cover_ = menu_->addAction(IconLoader::Load("find"), tr("Search for album covers..."));
|
||||
unset_cover_ = menu_->addAction(IconLoader::Load("list-remove"), tr("Unset cover"));
|
||||
show_cover_ = menu_->addAction(IconLoader::Load("zoom-in"), tr("Show fullsize..."));
|
||||
}
|
||||
|
||||
AlbumCoverChoiceController::~AlbumCoverChoiceController()
|
||||
{
|
||||
}
|
||||
|
||||
QList<QAction*> AlbumCoverChoiceController::PrepareAlbumChoiceMenu(QObject* parent) {
|
||||
return QList<QAction*>()
|
||||
<< 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);
|
||||
QList<QAction*> AlbumCoverChoiceController::GetAllActions() {
|
||||
return QList<QAction*>() << cover_from_file_ << cover_from_url_
|
||||
<< search_for_cover_ << unset_cover_
|
||||
<< show_cover_;
|
||||
}
|
||||
|
||||
void AlbumCoverChoiceController::SetLibrary(LibraryBackend* library) {
|
||||
library_ = library;
|
||||
}
|
||||
|
||||
QString AlbumCoverChoiceController::LoadCoverFromFile(Song* song) {
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <QAction>
|
||||
#include <QList>
|
||||
#include <QMenu>
|
||||
#include <QWidget>
|
||||
|
||||
class AlbumCoverFetcher;
|
||||
@ -33,11 +34,16 @@ class AlbumCoverChoiceController : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AlbumCoverChoiceController(LibraryBackend* library, QWidget* parent = 0);
|
||||
AlbumCoverChoiceController(QWidget* parent = 0);
|
||||
~AlbumCoverChoiceController();
|
||||
|
||||
static const char* kImageFileFilter;
|
||||
static const char* kAllFilesFilter;
|
||||
// Getters for all QActions implemented by this controller.
|
||||
|
||||
QAction* cover_from_file_action() const { return cover_from_file_; }
|
||||
QAction* cover_from_url_action() const { return cover_from_url_; }
|
||||
QAction* search_for_cover_action() const { return search_for_cover_; }
|
||||
QAction* unset_cover_action() const { return unset_cover_; }
|
||||
QAction* show_cover_action() const { return show_cover_; }
|
||||
|
||||
// Returns QAction* for every operation implemented by this controller.
|
||||
// The list contains QAction* for:
|
||||
@ -46,7 +52,11 @@ class AlbumCoverChoiceController : public QWidget {
|
||||
// 3. searching for cover using last.fm
|
||||
// 4. unsetting the cover manually
|
||||
// 5. showing the cover in original size
|
||||
QList<QAction*> PrepareAlbumChoiceMenu(QObject* parent);
|
||||
QList<QAction*> GetAllActions();
|
||||
|
||||
// Sets LibraryBackend on this controller. This is necessary for the controller
|
||||
// to work properly!
|
||||
void SetLibrary(LibraryBackend* library);
|
||||
|
||||
// All of the methods below require a currently selected song as an
|
||||
// input parameter. Also - LoadCoverFromFile, LoadCoverFromURL,
|
||||
@ -81,6 +91,8 @@ class AlbumCoverChoiceController : public QWidget {
|
||||
QString SaveCoverInCache(const QString& artist, const QString& album, const QImage& image);
|
||||
|
||||
private:
|
||||
static const char* kImageFileFilter;
|
||||
static const char* kAllFilesFilter;
|
||||
|
||||
#ifdef HAVE_LIBLASTFM
|
||||
AlbumCoverSearcher* cover_searcher_;
|
||||
@ -90,6 +102,14 @@ private:
|
||||
CoverFromURLDialog* cover_from_url_dialog_;
|
||||
|
||||
LibraryBackend* library_;
|
||||
|
||||
QMenu* menu_;
|
||||
|
||||
QAction* cover_from_file_;
|
||||
QAction* cover_from_url_;
|
||||
QAction* search_for_cover_;
|
||||
QAction* unset_cover_;
|
||||
QAction* show_cover_;
|
||||
};
|
||||
|
||||
#endif // ALBUMCOVERCHOICECONTROLLER_H
|
||||
|
@ -50,7 +50,7 @@ AlbumCoverManager::AlbumCoverManager(LibraryBackend* backend, QWidget* parent,
|
||||
: QMainWindow(parent),
|
||||
constructed_(false),
|
||||
ui_(new Ui_CoverManager),
|
||||
album_cover_choice_controller_(new AlbumCoverChoiceController(backend, this)),
|
||||
album_cover_choice_controller_(new AlbumCoverChoiceController(this)),
|
||||
backend_(backend),
|
||||
cover_loader_(new BackgroundThreadImplementation<AlbumCoverLoader, AlbumCoverLoader>(this)),
|
||||
cover_fetcher_(new AlbumCoverFetcher(this, network)),
|
||||
@ -73,6 +73,8 @@ AlbumCoverManager::AlbumCoverManager(LibraryBackend* backend, QWidget* parent,
|
||||
ui_->action_add_to_playlist->setIcon(IconLoader::Load("media-playback-start"));
|
||||
ui_->action_load->setIcon(IconLoader::Load("media-playback-start"));
|
||||
|
||||
album_cover_choice_controller_->SetLibrary(backend_);
|
||||
|
||||
// Get a square version of nocover.png
|
||||
QImage nocover(":/nocover.png");
|
||||
nocover = nocover.scaled(120, 120, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
@ -122,19 +124,18 @@ void AlbumCoverManager::Init() {
|
||||
|
||||
// Context menu
|
||||
|
||||
QList<QAction*> actions = album_cover_choice_controller_->PrepareAlbumChoiceMenu(this);
|
||||
QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
|
||||
|
||||
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()));
|
||||
connect(album_cover_choice_controller_->cover_from_file_action(),
|
||||
SIGNAL(triggered()), this, SLOT(LoadCoverFromFile()));
|
||||
connect(album_cover_choice_controller_->cover_from_url_action(),
|
||||
SIGNAL(triggered()), this, SLOT(LoadCoverFromURL()));
|
||||
connect(album_cover_choice_controller_->search_for_cover_action(),
|
||||
SIGNAL(triggered()), this, SLOT(SearchForCover()));
|
||||
connect(album_cover_choice_controller_->unset_cover_action(),
|
||||
SIGNAL(triggered()), this, SLOT(UnsetCover()));
|
||||
connect(album_cover_choice_controller_->show_cover_action(),
|
||||
SIGNAL(triggered()), this, SLOT(ShowCover()));
|
||||
|
||||
context_menu_->addActions(actions);
|
||||
context_menu_->addSeparator();
|
||||
@ -436,10 +437,10 @@ bool AlbumCoverManager::eventFilter(QObject *obj, QEvent *event) {
|
||||
some_with_covers = true;
|
||||
}
|
||||
|
||||
cover_from_file_->setEnabled(context_menu_items_.size() == 1);
|
||||
cover_from_url_->setEnabled(context_menu_items_.size() == 1);
|
||||
show_cover_->setEnabled(some_with_covers && context_menu_items_.size() == 1);
|
||||
unset_cover_->setEnabled(some_with_covers);
|
||||
album_cover_choice_controller_->cover_from_file_action()->setEnabled(context_menu_items_.size() == 1);
|
||||
album_cover_choice_controller_->cover_from_url_action()->setEnabled(context_menu_items_.size() == 1);
|
||||
album_cover_choice_controller_->show_cover_action()->setEnabled(some_with_covers && context_menu_items_.size() == 1);
|
||||
album_cover_choice_controller_->unset_cover_action()->setEnabled(some_with_covers);
|
||||
|
||||
QContextMenuEvent* e = static_cast<QContextMenuEvent*>(event);
|
||||
context_menu_->popup(e->globalPos());
|
||||
|
@ -143,12 +143,6 @@ class AlbumCoverManager : public QMainWindow {
|
||||
AlbumCoverChoiceController* album_cover_choice_controller_;
|
||||
LibraryBackend* backend_;
|
||||
|
||||
QAction* cover_from_file_;
|
||||
QAction* cover_from_url_;
|
||||
QAction* search_for_cover_;
|
||||
QAction* unset_cover_;
|
||||
QAction* show_cover_;
|
||||
|
||||
QAction* filter_all_;
|
||||
QAction* filter_with_covers_;
|
||||
QAction* filter_without_covers_;
|
||||
|
@ -58,7 +58,10 @@ void AlbumCoverSearcher::Init(AlbumCoverFetcher* fetcher) {
|
||||
QImage AlbumCoverSearcher::Exec(const QString &query) {
|
||||
ui_->query->setText(query);
|
||||
ui_->query->setFocus();
|
||||
Search();
|
||||
|
||||
if(!query.isEmpty()) {
|
||||
Search();
|
||||
}
|
||||
|
||||
if (exec() == QDialog::Rejected)
|
||||
return QImage();
|
||||
|
@ -46,7 +46,7 @@ const char* EditTagDialog::kTagFetchOnLoadText = QT_TR_NOOP("Generating audio fi
|
||||
EditTagDialog::EditTagDialog(QWidget* parent)
|
||||
: QDialog(parent),
|
||||
ui_(new Ui_EditTagDialog),
|
||||
album_cover_choice_controller_(NULL),
|
||||
album_cover_choice_controller_(new AlbumCoverChoiceController(this)),
|
||||
backend_(NULL),
|
||||
loading_(false),
|
||||
ignore_edits_(false),
|
||||
@ -133,19 +133,18 @@ EditTagDialog::EditTagDialog(QWidget* parent)
|
||||
// Set up the album cover menu
|
||||
cover_menu_ = new QMenu(this);
|
||||
|
||||
QList<QAction*> actions = album_cover_choice_controller_->PrepareAlbumChoiceMenu(this);
|
||||
QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
|
||||
|
||||
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()));
|
||||
connect(album_cover_choice_controller_->cover_from_file_action(),
|
||||
SIGNAL(triggered()), this, SLOT(LoadCoverFromFile()));
|
||||
connect(album_cover_choice_controller_->cover_from_url_action(),
|
||||
SIGNAL(triggered()), this, SLOT(LoadCoverFromURL()));
|
||||
connect(album_cover_choice_controller_->search_for_cover_action(),
|
||||
SIGNAL(triggered()), this, SLOT(SearchForCover()));
|
||||
connect(album_cover_choice_controller_->unset_cover_action(),
|
||||
SIGNAL(triggered()), this, SLOT(UnsetCover()));
|
||||
connect(album_cover_choice_controller_->show_cover_action(),
|
||||
SIGNAL(triggered()), this, SLOT(ShowCover()));
|
||||
|
||||
cover_menu_->addActions(actions);
|
||||
|
||||
@ -259,7 +258,7 @@ void EditTagDialog::SetSongsFinished() {
|
||||
|
||||
void EditTagDialog::SetTagCompleter(LibraryBackend* backend) {
|
||||
backend_ = backend;
|
||||
album_cover_choice_controller_ = new AlbumCoverChoiceController(backend, this);
|
||||
album_cover_choice_controller_->SetLibrary(backend);
|
||||
|
||||
new TagCompleter(backend, Playlist::Column_Artist, ui_->artist);
|
||||
new TagCompleter(backend, Playlist::Column_Album, ui_->album);
|
||||
@ -420,12 +419,12 @@ void EditTagDialog::UpdateSummaryTab(const Song& song) {
|
||||
ui_->summary->setText(summary);
|
||||
|
||||
#ifndef HAVE_LIBLASTFM
|
||||
cover_from_file_->setEnabled(false);
|
||||
search_for_cover_->setEnabled(false);
|
||||
album_cover_choice_controller_->cover_from_file_action()->setEnabled(false);
|
||||
album_cover_choice_controller_->search_for_cover_action()->setEnabled(false);
|
||||
#endif
|
||||
|
||||
unset_cover_->setEnabled(art_is_set);
|
||||
show_cover_->setEnabled(art_is_set);
|
||||
album_cover_choice_controller_->unset_cover_action()->setEnabled(art_is_set);
|
||||
album_cover_choice_controller_->show_cover_action()->setEnabled(art_is_set);
|
||||
ui_->summary_art_button->setEnabled(song.id() != -1);
|
||||
|
||||
ui_->length->setText(Utilities::PrettyTime(song.length()));
|
||||
|
@ -160,12 +160,6 @@ private:
|
||||
|
||||
QMenu* cover_menu_;
|
||||
|
||||
QAction* cover_from_file_;
|
||||
QAction* cover_from_url_;
|
||||
QAction* search_for_cover_;
|
||||
QAction* unset_cover_;
|
||||
QAction* show_cover_;
|
||||
|
||||
QPushButton* previous_button_;
|
||||
QPushButton* next_button_;
|
||||
|
||||
|
@ -22,12 +22,6 @@
|
||||
#include "ui/albumcoverchoicecontroller.h"
|
||||
#include "ui/iconloader.h"
|
||||
|
||||
#ifdef HAVE_LIBLASTFM
|
||||
# include "core/albumcoverfetcher.h"
|
||||
# include "ui/albumcovermanager.h"
|
||||
# include "ui/albumcoversearcher.h"
|
||||
#endif
|
||||
|
||||
#include <QMenu>
|
||||
#include <QMovie>
|
||||
#include <QPainter>
|
||||
@ -61,7 +55,7 @@ const int NowPlayingWidget::kTopBorder = 4;
|
||||
|
||||
NowPlayingWidget::NowPlayingWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
album_cover_choice_controller_(NULL),
|
||||
album_cover_choice_controller_(new AlbumCoverChoiceController(this)),
|
||||
cover_loader_(new BackgroundThreadImplementation<AlbumCoverLoader, AlbumCoverLoader>(this)),
|
||||
kitten_loader_(NULL),
|
||||
mode_(SmallSongDetails),
|
||||
@ -93,19 +87,18 @@ NowPlayingWidget::NowPlayingWidget(QWidget *parent)
|
||||
menu_->addActions(mode_group->actions());
|
||||
menu_->addSeparator();
|
||||
|
||||
QList<QAction*> actions = album_cover_choice_controller_->PrepareAlbumChoiceMenu(this);
|
||||
QList<QAction*> actions = album_cover_choice_controller_->GetAllActions();
|
||||
|
||||
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()));
|
||||
connect(album_cover_choice_controller_->cover_from_file_action(),
|
||||
SIGNAL(triggered()), this, SLOT(LoadCoverFromFile()));
|
||||
connect(album_cover_choice_controller_->cover_from_url_action(),
|
||||
SIGNAL(triggered()), this, SLOT(LoadCoverFromURL()));
|
||||
connect(album_cover_choice_controller_->search_for_cover_action(),
|
||||
SIGNAL(triggered()), this, SLOT(SearchForCover()));
|
||||
connect(album_cover_choice_controller_->unset_cover_action(),
|
||||
SIGNAL(triggered()), this, SLOT(UnsetCover()));
|
||||
connect(album_cover_choice_controller_->show_cover_action(),
|
||||
SIGNAL(triggered()), this, SLOT(ShowCover()));
|
||||
|
||||
menu_->addActions(actions);
|
||||
menu_->addSeparator();
|
||||
@ -365,16 +358,16 @@ void NowPlayingWidget::resizeEvent(QResizeEvent* e) {
|
||||
|
||||
void NowPlayingWidget::contextMenuEvent(QContextMenuEvent* e) {
|
||||
#ifndef HAVE_LIBLASTFM
|
||||
cover_from_file_->setEnabled(false);
|
||||
search_for_cover_->setEnabled(false);
|
||||
album_cover_choice_controller_->cover_from_file_action()->setEnabled(false);
|
||||
album_cover_choice_controller_->search_for_cover_action()->setEnabled(false);
|
||||
#endif
|
||||
|
||||
const bool art_is_set =
|
||||
!metadata_.art_manual().isEmpty() &&
|
||||
metadata_.art_manual() != AlbumCoverLoader::kManuallyUnsetCover;
|
||||
|
||||
unset_cover_->setEnabled(art_is_set);
|
||||
show_cover_->setEnabled(art_is_set);
|
||||
album_cover_choice_controller_->unset_cover_action()->setEnabled(art_is_set);
|
||||
album_cover_choice_controller_->show_cover_action()->setEnabled(art_is_set);
|
||||
|
||||
menu_->popup(mapToGlobal(e->pos()));
|
||||
}
|
||||
@ -447,5 +440,5 @@ void NowPlayingWidget::ShowCover() {
|
||||
}
|
||||
|
||||
void NowPlayingWidget::SetLibraryBackend(LibraryBackend* backend) {
|
||||
album_cover_choice_controller_ = new AlbumCoverChoiceController(backend, this);
|
||||
album_cover_choice_controller_->SetLibrary(backend);
|
||||
}
|
||||
|
@ -23,11 +23,6 @@
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
#ifdef HAVE_LIBLASTFM
|
||||
class AlbumCoverFetcher;
|
||||
class AlbumCoverSearcher;
|
||||
#endif
|
||||
|
||||
class AlbumCoverChoiceController;
|
||||
class AlbumCoverLoader;
|
||||
class LibraryBackend;
|
||||
@ -118,12 +113,6 @@ private:
|
||||
|
||||
QAction* above_statusbar_action_;
|
||||
|
||||
QAction* cover_from_file_;
|
||||
QAction* cover_from_url_;
|
||||
QAction* search_for_cover_;
|
||||
QAction* unset_cover_;
|
||||
QAction* show_cover_;
|
||||
|
||||
bool visible_;
|
||||
int small_ideal_height_;
|
||||
int cover_height_;
|
||||
|
Loading…
x
Reference in New Issue
Block a user