Only fetch lyrics when the lyrics tab is visible

This commit is contained in:
David Sansome 2010-10-02 13:37:10 +00:00
parent 61ea0cb24b
commit 1649ad48c5
7 changed files with 106 additions and 8 deletions

View File

@ -89,6 +89,7 @@ set(SOURCES
lyrics/lyricprovider.cpp lyrics/lyricprovider.cpp
lyrics/lyricsettings.cpp lyrics/lyricsettings.cpp
lyrics/lyricview.cpp lyrics/lyricview.cpp
lyrics/songinfobase.cpp
lyrics/ultimatelyricsreader.cpp lyrics/ultimatelyricsreader.cpp
playlist/playlist.cpp playlist/playlist.cpp
@ -224,6 +225,7 @@ set(HEADERS
lyrics/lyricprovider.h lyrics/lyricprovider.h
lyrics/lyricsettings.h lyrics/lyricsettings.h
lyrics/lyricview.h lyrics/lyricview.h
lyrics/songinfobase.h
lyrics/ultimatelyricsreader.h lyrics/ultimatelyricsreader.h
playlist/playlist.h playlist/playlist.h

View File

@ -19,7 +19,7 @@
#include "ui_lyricview.h" #include "ui_lyricview.h"
LyricView::LyricView(QWidget *parent) LyricView::LyricView(QWidget *parent)
: QWidget(parent), : SongInfoBase(parent),
ui_(new Ui_LyricView), ui_(new Ui_LyricView),
fetcher_(NULL), fetcher_(NULL),
current_request_id_(-1) current_request_id_(-1)
@ -40,7 +40,7 @@ void LyricView::set_network(NetworkAccessManager* network) {
SLOT(SearchProgress(int,QString))); SLOT(SearchProgress(int,QString)));
} }
void LyricView::SongChanged(const Song& metadata) { void LyricView::Update(const Song& metadata) {
current_request_id_ = fetcher_->SearchAsync(metadata); current_request_id_ = fetcher_->SearchAsync(metadata);
ui_->busy_text->SetText(tr("Searching...")); ui_->busy_text->SetText(tr("Searching..."));

View File

@ -17,15 +17,14 @@
#ifndef LYRICVIEW_H #ifndef LYRICVIEW_H
#define LYRICVIEW_H #define LYRICVIEW_H
#include "songinfobase.h"
#include "core/song.h" #include "core/song.h"
#include <QWidget>
class LyricFetcher; class LyricFetcher;
class NetworkAccessManager; class NetworkAccessManager;
class Ui_LyricView; class Ui_LyricView;
class LyricView : public QWidget { class LyricView : public SongInfoBase {
Q_OBJECT Q_OBJECT
public: public:
@ -35,8 +34,8 @@ public:
void set_network(NetworkAccessManager* network); void set_network(NetworkAccessManager* network);
LyricFetcher* fetcher() const { return fetcher_; } LyricFetcher* fetcher() const { return fetcher_; }
public slots: protected:
void SongChanged(const Song& metadata); void Update(const Song& metadata);
private slots: private slots:
void SearchProgress(int id, const QString& provider); void SearchProgress(int id, const QString& provider);

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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);
}

44
src/lyrics/songinfobase.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef SONGINFOBASE_H
#define SONGINFOBASE_H
#include <QWidget>
#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

View File

@ -351,7 +351,6 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg
connect(player_, SIGNAL(ForceShowOSD(Song)), SLOT(ForceShowOSD(Song))); connect(player_, SIGNAL(ForceShowOSD(Song)), SLOT(ForceShowOSD(Song)));
connect(playlists_, SIGNAL(CurrentSongChanged(Song)), osd_, SLOT(SongChanged(Song))); connect(playlists_, SIGNAL(CurrentSongChanged(Song)), osd_, SLOT(SongChanged(Song)));
connect(playlists_, SIGNAL(CurrentSongChanged(Song)), player_, SLOT(CurrentMetadataChanged(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(PlaylistChanged()), player_, SLOT(PlaylistChanged()));
connect(playlists_, SIGNAL(EditingFinished(QModelIndex)), SLOT(PlaylistEditFinished(QModelIndex))); connect(playlists_, SIGNAL(EditingFinished(QModelIndex)), SLOT(PlaylistEditFinished(QModelIndex)));
connect(playlists_, SIGNAL(Error(QString)), SLOT(ShowErrorDialog(QString))); connect(playlists_, SIGNAL(Error(QString)), SLOT(ShowErrorDialog(QString)));
@ -491,6 +490,7 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg
// Lyrics // Lyrics
lyric_view_->set_network(network); lyric_view_->set_network(network);
ConnectInfoView(lyric_view_);
// Analyzer // Analyzer
ui_->analyzer->SetEngine(player_->GetEngine()); ui_->analyzer->SetEngine(player_->GetEngine());
@ -1582,3 +1582,9 @@ void MainWindow::ShowVisualisations() {
void MainWindow::AddFancyTab(QWidget* widget, const QIcon& icon, const QString& label) { void MainWindow::AddFancyTab(QWidget* widget, const QIcon& icon, const QString& label) {
ui_->tabs->addTab(widget, icon, 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()));
}

View File

@ -59,6 +59,7 @@ class RadioItem;
class RadioModel; class RadioModel;
class RadioViewContainer; class RadioViewContainer;
class Song; class Song;
class SongInfoBase;
class SystemTrayIcon; class SystemTrayIcon;
class TaskManager; class TaskManager;
class TranscodeDialog; class TranscodeDialog;
@ -196,6 +197,7 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void AddDeviceSongsToPlaylist(bool clear_first, const SongList& songs); void AddDeviceSongsToPlaylist(bool clear_first, const SongList& songs);
void AddUrls(bool play_now, const QList<QUrl>& urls); void AddUrls(bool play_now, const QList<QUrl>& urls);
void AddFancyTab(QWidget* widget, const QIcon& icon, const QString& label); void AddFancyTab(QWidget* widget, const QIcon& icon, const QString& label);
void ConnectInfoView(SongInfoBase* view);
private: private:
Ui_MainWindow* ui_; Ui_MainWindow* ui_;