diff --git a/src/context/contextview.cpp b/src/context/contextview.cpp index 5e8b938cf..1618b31cb 100644 --- a/src/context/contextview.cpp +++ b/src/context/contextview.cpp @@ -73,14 +73,14 @@ const char *ContextView::kSettingsGroup = "ContextView"; ContextView::ContextView(QWidget *parent) : QWidget(parent), - app_(nullptr), ui_(new Ui_ContextViewContainer), + app_(nullptr), collectionview_(nullptr), + album_cover_choice_controller_(nullptr), + lyrics_fetcher_(nullptr), menu_(new QMenu(this)), timeline_fade_(new QTimeLine(1000, this)), image_strawberry_(":/pictures/strawberry.png"), - album_cover_choice_controller_(new AlbumCoverChoiceController(this)), - lyrics_fetcher_(nullptr), active_(false), downloading_covers_(false) { @@ -99,56 +99,29 @@ ContextView::ContextView(QWidget *parent) : cover_loader_options_.scale_output_image_ = true; pixmap_current_ = QPixmap::fromImage(AlbumCoverLoader::ScaleAndPad(cover_loader_options_, image_strawberry_)); - AddActions(); - LoadSettings(); - } ContextView::~ContextView() { delete ui_; } -void ContextView::LoadSettings() { - - QSettings s; - s.beginGroup(kSettingsGroup); - - action_show_data_->setChecked(s.value("show_data", true).toBool()); - action_show_output_->setChecked(s.value("show_output", true).toBool()); - action_show_albums_->setChecked(s.value("show_albums", true).toBool()); - action_show_lyrics_->setChecked(s.value("show_lyrics", false).toBool()); - album_cover_choice_controller_->search_cover_auto_action()->setChecked(s.value("search_for_cover_auto", true).toBool()); - - s.endGroup(); - -} - -void ContextView::SetApplication(Application *app) { +void ContextView::SetApplication(Application *app, CollectionView *collectionview, AlbumCoverChoiceController *album_cover_choice_controller) { app_ = app; - - connect(app_->current_art_loader(), SIGNAL(ArtLoaded(Song, QString, QImage)), SLOT(AlbumArtLoaded(Song, QString, QImage))); - - album_cover_choice_controller_->SetApplication(app_); - connect(album_cover_choice_controller_, SIGNAL(AutomaticCoverSearchDone()), this, SLOT(AutomaticCoverSearchDone())); - connect(album_cover_choice_controller_->cover_from_file_action(), SIGNAL(triggered()), this, SLOT(LoadCoverFromFile())); - connect(album_cover_choice_controller_->cover_to_file_action(), SIGNAL(triggered()), this, SLOT(SaveCoverToFile())); - 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())); - connect(album_cover_choice_controller_->search_cover_auto_action(), SIGNAL(triggered()), this, SLOT(SearchCoverAutomatically())); + collectionview_ = collectionview; + album_cover_choice_controller_ = album_cover_choice_controller; ui_->widget_play_albums->SetApplication(app_); - lyrics_fetcher_ = new LyricsFetcher(app_->lyrics_providers(), this); - connect(lyrics_fetcher_, SIGNAL(LyricsFetched(quint64, const QString)), this, SLOT(UpdateLyrics(quint64, const QString))); -} - -void ContextView::SetCollectionView(CollectionView *collectionview) { - collectionview_ = collectionview; connect(collectionview_, SIGNAL(TotalSongCountUpdated_()), this, SLOT(UpdateNoSong())); connect(collectionview_, SIGNAL(TotalArtistCountUpdated_()), this, SLOT(UpdateNoSong())); connect(collectionview_, SIGNAL(TotalAlbumCountUpdated_()), this, SLOT(UpdateNoSong())); + connect(lyrics_fetcher_, SIGNAL(LyricsFetched(quint64, const QString)), this, SLOT(UpdateLyrics(quint64, const QString))); + connect(app_->current_art_loader(), SIGNAL(ArtLoaded(Song, QString, QImage)), SLOT(AlbumArtLoaded(Song, QString, QImage))); + connect(album_cover_choice_controller_, SIGNAL(AutomaticCoverSearchDone()), this, SLOT(AutomaticCoverSearchDone())); + connect(album_cover_choice_controller_->search_cover_auto_action(), SIGNAL(triggered()), this, SLOT(SearchCoverAutomatically())); + + AddActions(); + } void ContextView::AddActions() { @@ -175,24 +148,32 @@ void ContextView::AddActions() { menu_->addAction(action_show_lyrics_); menu_->addSeparator(); - connect(action_show_data_, SIGNAL(triggered()), this, SLOT(ActionShowData())); - connect(action_show_output_, SIGNAL(triggered()), this, SLOT(ActionShowOutput())); - connect(action_show_albums_, SIGNAL(triggered()), this, SLOT(ActionShowAlbums())); - connect(action_show_lyrics_, SIGNAL(triggered()), this, SLOT(ActionShowLyrics())); - QList cover_actions = album_cover_choice_controller_->GetAllActions(); cover_actions.append(album_cover_choice_controller_->search_cover_auto_action()); menu_->addActions(cover_actions); menu_->addSeparator(); + QSettings s; + s.beginGroup(kSettingsGroup); + action_show_data_->setChecked(s.value("show_data", true).toBool()); + action_show_output_->setChecked(s.value("show_output", true).toBool()); + action_show_albums_->setChecked(s.value("show_albums", true).toBool()); + action_show_lyrics_->setChecked(s.value("show_lyrics", false).toBool()); + s.endGroup(); + + connect(action_show_data_, SIGNAL(triggered()), this, SLOT(ActionShowData())); + connect(action_show_output_, SIGNAL(triggered()), this, SLOT(ActionShowOutput())); + connect(action_show_albums_, SIGNAL(triggered()), this, SLOT(ActionShowAlbums())); + connect(action_show_lyrics_, SIGNAL(triggered()), this, SLOT(ActionShowLyrics())); + } -void ContextView::Playing() { -} +void ContextView::Playing() {} void ContextView::Stopped() { active_ = false; + song_playing_ = song_empty_; song_ = song_empty_; downloading_covers_ = false; prev_artist_ = QString(); @@ -201,8 +182,7 @@ void ContextView::Stopped() { } -void ContextView::Error() { -} +void ContextView::Error() {} void ContextView::UpdateNoSong() { NoSong(); @@ -211,8 +191,9 @@ void ContextView::UpdateNoSong() { void ContextView::SongChanged(const Song &song) { image_previous_ = image_original_; - prev_artist_ = song_.artist(); + prev_artist_ = song_playing_.artist(); lyrics_ = QString(); + song_playing_ = song; song_ = song; UpdateSong(); update(); @@ -519,14 +500,11 @@ void ContextView::ScaleCover() { void ContextView::AlbumArtLoaded(const Song &song, const QString&, const QImage &image) { - if (song == song_) {} - else { - qLog(Error) << __PRETTY_FUNCTION__ << "Ignoring" << song.title() << "because current song is" << song_.title(); - return; - } + if (song.effective_albumartist() != song_playing_.effective_albumartist() || song.effective_album() != song_playing_.effective_album() || song.title() != song_playing_.title()) return; active_ = true; downloading_covers_ = false; + song_ = song; SetImage(image); GetCoverAutomatically(); @@ -556,14 +534,21 @@ void ContextView::SetImage(const QImage &image) { } -bool ContextView::GetCoverAutomatically() { +void ContextView::GetCoverAutomatically() { // Search for cover automatically? - bool search = !song_.has_manually_unset_cover() && song_.art_automatic().isEmpty() && song_.art_manual().isEmpty() && !song_.artist().isEmpty() && !song_.album().isEmpty(); + bool search = + album_cover_choice_controller_->search_cover_auto_action()->isChecked() && + !song_.has_manually_unset_cover() && + song_.art_automatic().isEmpty() && + song_.art_manual().isEmpty() && + !song_.effective_albumartist().isEmpty() && + !song_.effective_album().isEmpty(); if (search) { downloading_covers_ = true; - album_cover_choice_controller_->SearchCoverAutomatically(song_); + // This is done in mainwindow instead to avoid searching multiple times (ContextView & PlayingWidget) + //album_cover_choice_controller_->SearchCoverAutomatically(song_); // Show a spinner animation spinner_animation_.reset(new QMovie(":/pictures/spinner.gif", QByteArray(), this)); @@ -572,8 +557,6 @@ bool ContextView::GetCoverAutomatically() { update(); } - return search; - } void ContextView::AutomaticCoverSearchDone() { @@ -618,37 +601,6 @@ void ContextView::ActionShowLyrics() { if (lyrics_.isEmpty() && action_show_lyrics_->isChecked()) lyrics_fetcher_->Search(song_.artist(), song_.album(), song_.title()); } -void ContextView::LoadCoverFromFile() { - album_cover_choice_controller_->LoadCoverFromFile(&song_); -} - -void ContextView::LoadCoverFromURL() { - album_cover_choice_controller_->LoadCoverFromURL(&song_); -} - -void ContextView::SearchForCover() { - album_cover_choice_controller_->SearchForCover(&song_); -} - -void ContextView::SaveCoverToFile() { - album_cover_choice_controller_->SaveCoverToFile(song_, image_original_); -} - -void ContextView::UnsetCover() { - album_cover_choice_controller_->UnsetCover(&song_); -} - -void ContextView::ShowCover() { - album_cover_choice_controller_->ShowCover(song_); -} - void ContextView::SearchCoverAutomatically() { - - QSettings s; - s.beginGroup(kSettingsGroup); - s.setValue("search_for_cover_auto", album_cover_choice_controller_->search_cover_auto_action()->isChecked()); - s.endGroup(); - GetCoverAutomatically(); - } diff --git a/src/context/contextview.h b/src/context/contextview.h index 0df2fce42..95894cc45 100644 --- a/src/context/contextview.h +++ b/src/context/contextview.h @@ -61,8 +61,7 @@ class ContextView : public QWidget { ContextView(QWidget *parent = nullptr); ~ContextView(); - void SetApplication(Application *app); - void SetCollectionView(CollectionView *collectionview); + void SetApplication(Application *app, CollectionView *collectionview, AlbumCoverChoiceController *album_cover_choice_controller); ContextAlbumsView *albums() { return ui_->widget_play_albums; } @@ -72,30 +71,19 @@ class ContextView : public QWidget { void Stopped(); void Error(); void SongChanged(const Song &song); - void AlbumArtLoaded(const Song &song, const QString &uri, const QImage &image); - - void LoadCoverFromFile(); - void SaveCoverToFile(); - void LoadCoverFromURL(); - void SearchForCover(); - void UnsetCover(); - void ShowCover(); - void SearchCoverAutomatically(); - void AutomaticCoverSearchDone(); - void UpdateLyrics(quint64 id, const QString lyrics); private: - static const char *kSettingsGroup; - Application *app_; Ui_ContextViewContainer *ui_; + Application *app_; CollectionView *collectionview_; + AlbumCoverChoiceController *album_cover_choice_controller_; + LyricsFetcher *lyrics_fetcher_; + QMenu *menu_; QTimeLine *timeline_fade_; QImage image_strawberry_; - AlbumCoverChoiceController *album_cover_choice_controller_; - LyricsFetcher *lyrics_fetcher_; bool active_; bool downloading_covers_; @@ -105,6 +93,7 @@ class ContextView : public QWidget { QAction *action_show_lyrics_; AlbumCoverLoaderOptions cover_loader_options_; Song song_; + Song song_playing_; Song song_empty_; QImage image_original_; QImage image_previous_; @@ -116,7 +105,6 @@ class ContextView : public QWidget { QString prev_artist_; QString lyrics_; - void LoadSettings(); void AddActions(); void SetText(QLabel *label, int value, const QString &suffix, const QString &def = QString()); void NoSong(); @@ -124,7 +112,7 @@ class ContextView : public QWidget { void SetImage(const QImage &image); void DrawImage(QPainter *p); void ScaleCover(); - bool GetCoverAutomatically(); + void GetCoverAutomatically(); protected: bool eventFilter(QObject *, QEvent *); @@ -140,6 +128,10 @@ class ContextView : public QWidget { void ActionShowOutput(); void ActionShowAlbums(); void ActionShowLyrics(); + void UpdateLyrics(quint64 id, const QString lyrics); + void SearchCoverAutomatically(); + void AutomaticCoverSearchDone(); + void AlbumArtLoaded(const Song &song, const QString &uri, const QImage &image); void FadePreviousTrack(qreal value); }; diff --git a/src/core/mainwindow.cpp b/src/core/mainwindow.cpp index 03a401cf9..b780847a0 100644 --- a/src/core/mainwindow.cpp +++ b/src/core/mainwindow.cpp @@ -118,12 +118,16 @@ #include "equalizer/equalizer.h" #include "globalshortcuts/globalshortcuts.h" #include "covermanager/albumcovermanager.h" +#include "covermanager/albumcoverchoicecontroller.h" +#include "covermanager/albumcoverloader.h" +#include "covermanager/currentartloader.h" #include "device/devicemanager.h" #include "device/devicestatefiltermodel.h" #include "device/deviceview.h" #include "device/deviceviewcontainer.h" #include "transcoder/transcodedialog.h" #include "settings/behavioursettingspage.h" +#include "settings/playbacksettingspage.h" #include "settings/playlistsettingspage.h" #include "settings/settingsdialog.h" @@ -158,6 +162,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co tray_icon_(tray_icon), osd_(osd), edit_tag_dialog_(std::bind(&MainWindow::CreateEditTagDialog, this)), + album_cover_choice_controller_(new AlbumCoverChoiceController(this)), global_shortcuts_(new GlobalShortcuts(this)), context_view_(new ContextView(this)), collection_view_(new CollectionViewContainer(this)), @@ -215,10 +220,19 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co ui_->menu_help->menuAction()->setVisible(false); #endif + connect(app_->current_art_loader(), SIGNAL(ArtLoaded(Song, QString, QImage)), SLOT(AlbumArtLoaded(Song, QString, QImage))); + album_cover_choice_controller_->SetApplication(app); + connect(album_cover_choice_controller_->cover_from_file_action(), SIGNAL(triggered()), this, SLOT(LoadCoverFromFile())); + connect(album_cover_choice_controller_->cover_to_file_action(), SIGNAL(triggered()), this, SLOT(SaveCoverToFile())); + 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())); + connect(album_cover_choice_controller_->search_cover_auto_action(), SIGNAL(triggered()), this, SLOT(SearchCoverAutomatically())); + ui_->multi_loading_indicator->SetTaskManager(app_->task_manager()); - context_view_->SetApplication(app_); - context_view_->SetCollectionView(collection_view_->view()); - ui_->widget_playing->SetApplication(app_); + context_view_->SetApplication(app_, collection_view_->view(), album_cover_choice_controller_); + ui_->widget_playing->SetApplication(app_, album_cover_choice_controller_); int volume = app_->player()->GetVolume(); ui_->volume->setValue(volume); @@ -587,7 +601,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co connect(ui_->tabs, SIGNAL(ModeChanged(FancyTabWidget::Mode)), SLOT(SaveGeometry())); connect(ui_->tabs, SIGNAL(CurrentChanged(int)), SLOT(TabSwitched())); connect(ui_->tabs, SIGNAL(CurrentChanged(int)), SLOT(SaveGeometry())); - + // Context connect(app_->playlist_manager(), SIGNAL(CurrentSongChanged(Song)), context_view_, SLOT(SongChanged(Song))); connect(app_->player(), SIGNAL(PlaylistFinished()), context_view_, SLOT(Stopped())); @@ -760,6 +774,11 @@ void MainWindow::ReloadSettings() { doubleclick_playlist_addmode_ = PlaylistAddBehaviour(settings.value("doubleclick_playlist_addmode", PlaylistAddBehaviour_Play).toInt()); menu_playmode_ = PlayBehaviour(settings.value("menu_playmode", PlayBehaviour_IfStopped).toInt()); settings.endGroup(); + + settings.beginGroup(kSettingsGroup); + album_cover_choice_controller_->search_cover_auto_action()->setChecked(settings.value("search_for_cover_auto", true).toBool()); + settings.endGroup(); + } void MainWindow::ReloadAllSettings() { @@ -797,6 +816,10 @@ void MainWindow::MediaStopped() { tray_icon_->SetProgress(0); tray_icon_->SetStopped(); + song_playing_ = song_empty_; + song_ = song_empty_; + image_original_ = QImage(); + } void MainWindow::MediaPaused() { @@ -843,6 +866,8 @@ void MainWindow::VolumeChanged(int volume) { void MainWindow::SongChanged(const Song &song) { + song_playing_ = song; + song_ = song; setWindowTitle(song.PrettyTitleWithArtist()); tray_icon_->SetProgress(0); @@ -2299,4 +2324,62 @@ void MainWindow::SearchForAlbum() { } +void MainWindow::LoadCoverFromFile() { + album_cover_choice_controller_->LoadCoverFromFile(&song_); +} + +void MainWindow::LoadCoverFromURL() { + album_cover_choice_controller_->LoadCoverFromURL(&song_); +} + +void MainWindow::SearchForCover() { + album_cover_choice_controller_->SearchForCover(&song_); +} + +void MainWindow::SaveCoverToFile() { + album_cover_choice_controller_->SaveCoverToFile(song_, image_original_); +} + +void MainWindow::UnsetCover() { + album_cover_choice_controller_->UnsetCover(&song_); +} + +void MainWindow::ShowCover() { + album_cover_choice_controller_->ShowCover(song_); +} + +void MainWindow::SearchCoverAutomatically() { + + QSettings s; + s.beginGroup(PlaybackSettingsPage::kSettingsGroup); + s.setValue("search_for_cover_auto", album_cover_choice_controller_->search_cover_auto_action()->isChecked()); + s.endGroup(); + GetCoverAutomatically(); + +} + +void MainWindow::AlbumArtLoaded(const Song &song, const QString&, const QImage &image) { + + if (song.effective_albumartist() != song_playing_.effective_albumartist() || song.effective_album() != song_playing_.effective_album() || song.title() != song_playing_.title()) return; + + song_ = song; + image_original_ = image; + GetCoverAutomatically(); + +} + +void MainWindow::GetCoverAutomatically() { + + // Search for cover automatically? + bool search = + album_cover_choice_controller_->search_cover_auto_action()->isChecked() && + !song_.has_manually_unset_cover() && + song_.art_automatic().isEmpty() && + song_.art_manual().isEmpty() && + !song_.effective_albumartist().isEmpty() && + !song_.effective_album().isEmpty(); + + if (search) album_cover_choice_controller_->SearchCoverAutomatically(song_); + +} diff --git a/src/core/mainwindow.h b/src/core/mainwindow.h index 9df6f89bf..e3797a179 100644 --- a/src/core/mainwindow.h +++ b/src/core/mainwindow.h @@ -61,6 +61,7 @@ class AlbumCoverManager;; class Application; class ContextView; class CollectionViewContainer; +class AlbumCoverChoiceController; class CommandlineOptions; class DeviceView; class DeviceViewContainer; @@ -270,6 +271,15 @@ signals: void SearchForArtist(); void SearchForAlbum(); + void LoadCoverFromFile(); + void SaveCoverToFile(); + void LoadCoverFromURL(); + void SearchForCover(); + void UnsetCover(); + void ShowCover(); + void SearchCoverAutomatically(); + void AlbumArtLoaded(const Song &song, const QString &uri, const QImage &image); + private: void ApplyAddBehaviour(AddBehaviour b, MimeData *data) const; @@ -279,6 +289,8 @@ signals: // creates the icon by painting the full one depending on the current position QPixmap CreateOverlayedIcon(int position, int scrobble_point); + + void GetCoverAutomatically(); private: Ui_MainWindow *ui_; @@ -289,6 +301,7 @@ signals: OSD *osd_; Lazy edit_tag_dialog_; Lazy about_dialog_; + AlbumCoverChoiceController *album_cover_choice_controller_; GlobalShortcuts *global_shortcuts_; @@ -363,6 +376,11 @@ signals: PlaylistAddBehaviour doubleclick_playlist_addmode_; PlayBehaviour menu_playmode_; + Song song_; + Song song_playing_; + Song song_empty_; + QImage image_original_; + }; #endif // MAINWINDOW_H diff --git a/src/widgets/playingwidget.cpp b/src/widgets/playingwidget.cpp index 4411eeed1..ba152c206 100644 --- a/src/widgets/playingwidget.cpp +++ b/src/widgets/playingwidget.cpp @@ -70,12 +70,13 @@ const int PlayingWidget::kTopBorder = 4; PlayingWidget::PlayingWidget(QWidget *parent) : QWidget(parent), app_(nullptr), - album_cover_choice_controller_(new AlbumCoverChoiceController(this)), + album_cover_choice_controller_(nullptr), mode_(LargeSongDetails), menu_(new QMenu(this)), fit_cover_width_action_(nullptr), enabled_(false), visible_(false), + playing_(false), active_(false), small_ideal_height_(0), fit_width_(false), @@ -91,8 +92,8 @@ PlayingWidget::PlayingWidget(QWidget *parent) QSettings s; s.beginGroup(kSettingsGroup); mode_ = Mode(s.value("mode", LargeSongDetails).toInt()); - album_cover_choice_controller_->search_cover_auto_action()->setChecked(s.value("search_for_cover_auto", true).toBool()); fit_width_ = s.value("fit_cover_width", false).toBool(); + s.endGroup(); // Accept drops for setting album art setAcceptDrops(true); @@ -103,33 +104,15 @@ PlayingWidget::PlayingWidget(QWidget *parent) connect(mode_mapper, SIGNAL(mapped(int)), SLOT(SetMode(int))); CreateModeAction(SmallSongDetails, tr("Small album cover"), mode_group, mode_mapper); CreateModeAction(LargeSongDetails, tr("Large album cover"), mode_group, mode_mapper); - menu_->addActions(mode_group->actions()); fit_cover_width_action_ = menu_->addAction(tr("Fit cover to width")); - fit_cover_width_action_->setCheckable(true); fit_cover_width_action_->setEnabled(true); connect(fit_cover_width_action_, SIGNAL(toggled(bool)), SLOT(FitCoverWidth(bool))); fit_cover_width_action_->setChecked(fit_width_); menu_->addSeparator(); - QList actions = album_cover_choice_controller_->GetAllActions(); - - // Here we add the search automatically action, too! - actions.append(album_cover_choice_controller_->search_cover_auto_action()); - - connect(album_cover_choice_controller_->cover_from_file_action(), SIGNAL(triggered()), this, SLOT(LoadCoverFromFile())); - connect(album_cover_choice_controller_->cover_to_file_action(), SIGNAL(triggered()), this, SLOT(SaveCoverToFile())); - 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())); - connect(album_cover_choice_controller_->search_cover_auto_action(), SIGNAL(triggered()), this, SLOT(SearchCoverAutomatically())); - - menu_->addActions(actions); - menu_->addSeparator(); - // Animations connect(timeline_show_hide_, SIGNAL(frameChanged(int)), SLOT(SetHeight(int))); connect(timeline_fade_, SIGNAL(valueChanged(qreal)), SLOT(FadePreviousTrack(qreal))); @@ -143,20 +126,25 @@ PlayingWidget::PlayingWidget(QWidget *parent) UpdateHeight(); - connect(album_cover_choice_controller_, SIGNAL(AutomaticCoverSearchDone()), this, SLOT(AutomaticCoverSearchDone())); - } -PlayingWidget::~PlayingWidget() { -} +PlayingWidget::~PlayingWidget() {} -void PlayingWidget::SetApplication(Application *app) { +void PlayingWidget::SetApplication(Application *app, AlbumCoverChoiceController *album_cover_choice_controller) { app_ = app; - - album_cover_choice_controller_->SetApplication(app_); connect(app_->current_art_loader(), SIGNAL(ArtLoaded(Song, QString, QImage)), SLOT(AlbumArtLoaded(Song, QString, QImage))); + album_cover_choice_controller_ = album_cover_choice_controller; + album_cover_choice_controller_->SetApplication(app_); + QList cover_actions = album_cover_choice_controller_->GetAllActions(); + cover_actions.append(album_cover_choice_controller_->search_cover_auto_action()); + menu_->addActions(cover_actions); + menu_->addSeparator(); + + connect(album_cover_choice_controller_, SIGNAL(AutomaticCoverSearchDone()), this, SLOT(AutomaticCoverSearchDone())); + connect(album_cover_choice_controller_->search_cover_auto_action(), SIGNAL(triggered()), this, SLOT(SearchCoverAutomatically())); + } @@ -248,7 +236,10 @@ void PlayingWidget::Playing() { } void PlayingWidget::Stopped() { + playing_ = false; active_ = false; + song_playing_ = song_empty_; + song_ = song_empty_; SetVisible(false); } @@ -257,18 +248,20 @@ void PlayingWidget::Error() { } void PlayingWidget::SongChanged(const Song &song) { + playing_ = true; + song_playing_ = song; song_ = song; } void PlayingWidget::AlbumArtLoaded(const Song &song, const QString &, const QImage &image) { - if (song == song_) {} - else { - qLog(Error) << __PRETTY_FUNCTION__ << "Ignoring" << song.title() << "because current song is" << song_.title(); - return; - } + if (!playing_) return; + + if (song.effective_albumartist() != song_playing_.effective_albumartist() || song.effective_album() != song_playing_.effective_album() || song.title() != song_playing_.title()) return; + active_ = true; downloading_covers_ = false; + song_ = song; SetImage(image); GetCoverAutomatically(); @@ -469,35 +462,38 @@ void PlayingWidget::mouseReleaseEvent(QMouseEvent*) { } void PlayingWidget::dragEnterEvent(QDragEnterEvent *e) { - + if (AlbumCoverChoiceController::CanAcceptDrag(e)) { e->acceptProposedAction(); } QWidget::dragEnterEvent(e); - + } void PlayingWidget::dropEvent(QDropEvent *e) { - + album_cover_choice_controller_->SaveCover(&song_, e); QWidget::dropEvent(e); - + } -bool PlayingWidget::GetCoverAutomatically() { - +void PlayingWidget::GetCoverAutomatically() { + // Search for cover automatically? bool search = - album_cover_choice_controller_->search_cover_auto_action()->isChecked() && - !song_.has_manually_unset_cover() && - song_.art_automatic().isEmpty() && song_.art_manual().isEmpty() && - !song_.artist().isEmpty() && !song_.album().isEmpty(); + album_cover_choice_controller_->search_cover_auto_action()->isChecked() && + !song_.has_manually_unset_cover() && + song_.art_automatic().isEmpty() && + song_.art_manual().isEmpty() && + !song_.effective_albumartist().isEmpty() && + !song_.effective_album().isEmpty(); if (search) { downloading_covers_ = true; - album_cover_choice_controller_->SearchCoverAutomatically(song_); + // This is done in mainwindow instead to avoid searching multiple times (ContextView & PlayingWidget) + // album_cover_choice_controller_->SearchCoverAutomatically(song_); // Show a spinner animation spinner_animation_.reset(new QMovie(":/pictures/spinner.gif", QByteArray(), this)); @@ -506,8 +502,6 @@ bool PlayingWidget::GetCoverAutomatically() { update(); } - return search; - } void PlayingWidget::AutomaticCoverSearchDone() { @@ -519,37 +513,5 @@ void PlayingWidget::AutomaticCoverSearchDone() { } void PlayingWidget::SearchCoverAutomatically() { - - QSettings s; - s.beginGroup(kSettingsGroup); - s.setValue("search_for_cover_auto", album_cover_choice_controller_->search_cover_auto_action()->isChecked()); - s.endGroup(); - GetCoverAutomatically(); - } - -void PlayingWidget::LoadCoverFromFile() { - album_cover_choice_controller_->LoadCoverFromFile(&song_); -} - -void PlayingWidget::LoadCoverFromURL() { - album_cover_choice_controller_->LoadCoverFromURL(&song_); -} - -void PlayingWidget::SearchForCover() { - album_cover_choice_controller_->SearchForCover(&song_); -} - -void PlayingWidget::SaveCoverToFile() { - album_cover_choice_controller_->SaveCoverToFile(song_, image_original_); -} - -void PlayingWidget::UnsetCover() { - album_cover_choice_controller_->UnsetCover(&song_); -} - -void PlayingWidget::ShowCover() { - album_cover_choice_controller_->ShowCover(song_); -} - diff --git a/src/widgets/playingwidget.h b/src/widgets/playingwidget.h index ed1bdd244..966dfeb4d 100644 --- a/src/widgets/playingwidget.h +++ b/src/widgets/playingwidget.h @@ -66,7 +66,7 @@ class PlayingWidget : public QWidget { PlayingWidget(QWidget *parent = nullptr); ~PlayingWidget(); - void SetApplication(Application *app); + void SetApplication(Application *app, AlbumCoverChoiceController *album_cover_choice_controller); void SetEnabled(); void SetDisabled(); void set_ideal_height(int height); @@ -90,16 +90,9 @@ class PlayingWidget : public QWidget { void dropEvent(QDropEvent *e); private slots: - void SetMode(int mode); void FitCoverWidth(bool fit); - void LoadCoverFromFile(); - void SaveCoverToFile(); - void LoadCoverFromURL(); - void SearchForCover(); - void UnsetCover(); - void ShowCover(); void SearchCoverAutomatically(); void AutomaticCoverSearchDone(); @@ -129,6 +122,7 @@ class PlayingWidget : public QWidget { QAction *fit_cover_width_action_; bool enabled_; bool visible_; + bool playing_; bool active_; int small_ideal_height_; AlbumCoverLoaderOptions cover_loader_options_; @@ -141,6 +135,8 @@ class PlayingWidget : public QWidget { bool downloading_covers_; Song song_; + Song song_playing_; + Song song_empty_; QImage image_original_; QPixmap pixmap_cover_; QPixmap pixmap_previous_track_; @@ -153,7 +149,7 @@ class PlayingWidget : public QWidget { void SetImage(const QImage &image); void DrawContents(QPainter *p); void ScaleCover(); - bool GetCoverAutomatically(); + void GetCoverAutomatically(); };