diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3427e5d91..0b52548bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -89,6 +89,7 @@ set(SOURCES lyrics/lyricprovider.cpp lyrics/lyricsettings.cpp lyrics/lyricview.cpp + lyrics/songinfobase.cpp lyrics/ultimatelyricsreader.cpp playlist/playlist.cpp @@ -224,6 +225,7 @@ set(HEADERS lyrics/lyricprovider.h lyrics/lyricsettings.h lyrics/lyricview.h + lyrics/songinfobase.h lyrics/ultimatelyricsreader.h playlist/playlist.h diff --git a/src/lyrics/lyricview.cpp b/src/lyrics/lyricview.cpp index 010a5211d..99e92fa24 100644 --- a/src/lyrics/lyricview.cpp +++ b/src/lyrics/lyricview.cpp @@ -19,7 +19,7 @@ #include "ui_lyricview.h" LyricView::LyricView(QWidget *parent) - : QWidget(parent), + : SongInfoBase(parent), ui_(new Ui_LyricView), fetcher_(NULL), current_request_id_(-1) @@ -40,7 +40,7 @@ void LyricView::set_network(NetworkAccessManager* network) { SLOT(SearchProgress(int,QString))); } -void LyricView::SongChanged(const Song& metadata) { +void LyricView::Update(const Song& metadata) { current_request_id_ = fetcher_->SearchAsync(metadata); ui_->busy_text->SetText(tr("Searching...")); diff --git a/src/lyrics/lyricview.h b/src/lyrics/lyricview.h index ad3193f8c..9bab3b7c5 100644 --- a/src/lyrics/lyricview.h +++ b/src/lyrics/lyricview.h @@ -17,15 +17,14 @@ #ifndef LYRICVIEW_H #define LYRICVIEW_H +#include "songinfobase.h" #include "core/song.h" -#include - class LyricFetcher; class NetworkAccessManager; class Ui_LyricView; -class LyricView : public QWidget { +class LyricView : public SongInfoBase { Q_OBJECT public: @@ -35,8 +34,8 @@ public: void set_network(NetworkAccessManager* network); LyricFetcher* fetcher() const { return fetcher_; } -public slots: - void SongChanged(const Song& metadata); +protected: + void Update(const Song& metadata); private slots: void SearchProgress(int id, const QString& provider); diff --git a/src/lyrics/songinfobase.cpp b/src/lyrics/songinfobase.cpp new file mode 100644 index 000000000..e95a8e17b --- /dev/null +++ b/src/lyrics/songinfobase.cpp @@ -0,0 +1,45 @@ +/* This file is part of Clementine. + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#include "songinfobase.h" + +SongInfoBase::SongInfoBase(QWidget* parent) + : QWidget(parent), + dirty_(false) +{ +} + +void SongInfoBase::SongChanged(const Song& metadata) { + if (isVisible()) { + Update(metadata); + dirty_ = false; + } else { + queued_metadata_ = metadata; + dirty_ = true; + } +} + +void SongInfoBase::SongFinished() { + dirty_ = false; +} + +void SongInfoBase::showEvent(QShowEvent* e) { + if (dirty_) { + Update(queued_metadata_); + dirty_ = false; + } + QWidget::showEvent(e); +} diff --git a/src/lyrics/songinfobase.h b/src/lyrics/songinfobase.h new file mode 100644 index 000000000..0e2faac08 --- /dev/null +++ b/src/lyrics/songinfobase.h @@ -0,0 +1,44 @@ +/* This file is part of Clementine. + + Clementine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Clementine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Clementine. If not, see . +*/ + +#ifndef SONGINFOBASE_H +#define SONGINFOBASE_H + +#include + +#include "core/song.h" + +class SongInfoBase : public QWidget { + Q_OBJECT + +public: + SongInfoBase(QWidget* parent = 0); + +public slots: + void SongChanged(const Song& metadata); + void SongFinished(); + +protected: + void showEvent(QShowEvent* e); + + virtual void Update(const Song& metadata) {} + +private: + Song queued_metadata_; + bool dirty_; +}; + +#endif // SONGINFOBASE_H diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 397763f3d..4c1561b56 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -351,7 +351,6 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg connect(player_, SIGNAL(ForceShowOSD(Song)), SLOT(ForceShowOSD(Song))); connect(playlists_, SIGNAL(CurrentSongChanged(Song)), osd_, SLOT(SongChanged(Song))); connect(playlists_, SIGNAL(CurrentSongChanged(Song)), player_, SLOT(CurrentMetadataChanged(Song))); - connect(playlists_, SIGNAL(CurrentSongChanged(Song)), lyric_view_, SLOT(SongChanged(Song))); connect(playlists_, SIGNAL(PlaylistChanged()), player_, SLOT(PlaylistChanged())); connect(playlists_, SIGNAL(EditingFinished(QModelIndex)), SLOT(PlaylistEditFinished(QModelIndex))); connect(playlists_, SIGNAL(Error(QString)), SLOT(ShowErrorDialog(QString))); @@ -491,6 +490,7 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg // Lyrics lyric_view_->set_network(network); + ConnectInfoView(lyric_view_); // Analyzer ui_->analyzer->SetEngine(player_->GetEngine()); @@ -1582,3 +1582,9 @@ void MainWindow::ShowVisualisations() { void MainWindow::AddFancyTab(QWidget* widget, const QIcon& icon, const QString& label) { ui_->tabs->addTab(widget, icon, label); } + +void MainWindow::ConnectInfoView(SongInfoBase* view) { + connect(playlists_, SIGNAL(CurrentSongChanged(Song)), view, SLOT(SongChanged(Song))); + connect(player_, SIGNAL(PlaylistFinished()), view, SLOT(SongFinished())); + connect(player_, SIGNAL(Stopped()), view, SLOT(SongFinished())); +} diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 88c825776..f847ec298 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -59,6 +59,7 @@ class RadioItem; class RadioModel; class RadioViewContainer; class Song; +class SongInfoBase; class SystemTrayIcon; class TaskManager; class TranscodeDialog; @@ -196,6 +197,7 @@ class MainWindow : public QMainWindow, public PlatformInterface { void AddDeviceSongsToPlaylist(bool clear_first, const SongList& songs); void AddUrls(bool play_now, const QList& urls); void AddFancyTab(QWidget* widget, const QIcon& icon, const QString& label); + void ConnectInfoView(SongInfoBase* view); private: Ui_MainWindow* ui_;