Give the last.fm global search provider a config dialog

This commit is contained in:
David Sansome 2011-11-05 17:11:02 +00:00
parent e0beff096d
commit 37166ca19d
9 changed files with 24 additions and 12 deletions

View File

@ -184,5 +184,5 @@ void GlobalSearchSettingsPage::CurrentProviderChanged(QTreeWidgetItem* item) {
ui_->up->setEnabled(row != 0); ui_->up->setEnabled(row != 0);
ui_->down->setEnabled(row != root->childCount() - 1); ui_->down->setEnabled(row != root->childCount() - 1);
ui_->configure->setEnabled(provider->CanShowConfig()); ui_->configure->setEnabled(provider->can_show_config());
} }

View File

@ -32,7 +32,7 @@ void GroovesharkSearchProvider::Init(GroovesharkService* service) {
service_ = service; service_ = service;
SearchProvider::Init("Grooveshark", "grooveshark", SearchProvider::Init("Grooveshark", "grooveshark",
QIcon(":providers/grooveshark.png"), QIcon(":providers/grooveshark.png"),
WantsDelayedQueries | ArtIsProbablyRemote); WantsDelayedQueries | ArtIsProbablyRemote | CanShowConfig);
connect(service_, SIGNAL(SimpleSearchResults(int, SongList)), connect(service_, SIGNAL(SimpleSearchResults(int, SongList)),
SLOT(SearchDone(int, SongList))); SLOT(SearchDone(int, SongList)));

View File

@ -36,7 +36,6 @@ class GroovesharkSearchProvider : public SearchProvider {
void LoadArtAsync(int id, const Result& result); void LoadArtAsync(int id, const Result& result);
void LoadTracksAsync(int id, const Result& result); void LoadTracksAsync(int id, const Result& result);
bool IsLoggedIn(); bool IsLoggedIn();
bool CanShowConfig() const { return true; }
void ShowConfig(); void ShowConfig();
private slots: private slots:

View File

@ -23,7 +23,7 @@
LastFMSearchProvider::LastFMSearchProvider(LastFMService* service, QObject* parent) LastFMSearchProvider::LastFMSearchProvider(LastFMService* service, QObject* parent)
: SimpleSearchProvider(parent), : SimpleSearchProvider(parent),
service_(service) { service_(service) {
Init("Last.fm", "lastfm", QIcon(":last.fm/as.png")); Init("Last.fm", "lastfm", QIcon(":last.fm/as.png"), CanShowConfig);
icon_ = ScaleAndPad(QImage(":last.fm/as.png")); icon_ = ScaleAndPad(QImage(":last.fm/as.png"));
set_safe_words(QStringList() << "lastfm" << "last.fm"); set_safe_words(QStringList() << "lastfm" << "last.fm");
@ -74,3 +74,11 @@ void LastFMSearchProvider::RecreateItems() {
SetItems(items); SetItems(items);
} }
bool LastFMSearchProvider::IsLoggedIn() {
return service_->IsAuthenticated();
}
void LastFMSearchProvider::ShowConfig() {
service_->ShowConfig();
}

View File

@ -28,6 +28,9 @@ public:
void LoadArtAsync(int id, const Result& result); void LoadArtAsync(int id, const Result& result);
bool IsLoggedIn();
void ShowConfig();
protected: protected:
void RecreateItems(); void RecreateItems();

View File

@ -81,7 +81,12 @@ public:
// normal place in the song metadata. LoadArtAsync will never be called and // normal place in the song metadata. LoadArtAsync will never be called and
// WantsSerialisedArtQueries and ArtIsProbablyRemote will be ignored if // WantsSerialisedArtQueries and ArtIsProbablyRemote will be ignored if
// they are set as well. The GlobalSearch engine will load the art itself. // they are set as well. The GlobalSearch engine will load the art itself.
ArtIsInSongMetadata = 0x08 ArtIsInSongMetadata = 0x08,
// Indicates this provider has a config dialog that can be shown by calling
// CanShowConfig. If this is not set then the button will be greyed out
// in the GUI.
CanShowConfig = 0x10
}; };
Q_DECLARE_FLAGS(Hints, Hint) Q_DECLARE_FLAGS(Hints, Hint)
@ -94,6 +99,7 @@ public:
bool wants_serialised_art() const { return hints() & WantsSerialisedArtQueries; } bool wants_serialised_art() const { return hints() & WantsSerialisedArtQueries; }
bool art_is_probably_remote() const { return hints() & ArtIsProbablyRemote; } bool art_is_probably_remote() const { return hints() & ArtIsProbablyRemote; }
bool art_is_in_song_metadata() const { return hints() & ArtIsInSongMetadata; } bool art_is_in_song_metadata() const { return hints() & ArtIsInSongMetadata; }
bool can_show_config() const { return hints() & CanShowConfig; }
// Starts a search. Must emit ResultsAvailable zero or more times and then // Starts a search. Must emit ResultsAvailable zero or more times and then
// SearchFinished exactly once, using this ID. // SearchFinished exactly once, using this ID.
@ -110,8 +116,7 @@ public:
// If provider needs user login to search and play songs, this method should // If provider needs user login to search and play songs, this method should
// be reimplemented // be reimplemented
virtual bool IsLoggedIn() { return true; } virtual bool IsLoggedIn() { return true; }
virtual bool CanShowConfig() const { return false; } virtual void ShowConfig() { } // Remember to set the CanShowConfig hint
virtual void ShowConfig() { }
static QImage ScaleAndPad(const QImage& image); static QImage ScaleAndPad(const QImage& image);

View File

@ -29,7 +29,8 @@ SpotifySearchProvider::SpotifySearchProvider(QObject* parent)
service_(NULL) service_(NULL)
{ {
Init("Spotify", "spotify", QIcon(":icons/32x32/spotify.png"), Init("Spotify", "spotify", QIcon(":icons/32x32/spotify.png"),
WantsDelayedQueries | WantsSerialisedArtQueries | ArtIsProbablyRemote); WantsDelayedQueries | WantsSerialisedArtQueries | ArtIsProbablyRemote |
CanShowConfig);
} }
SpotifyServer* SpotifySearchProvider::server() { SpotifyServer* SpotifySearchProvider::server() {

View File

@ -36,7 +36,6 @@ public:
void LoadTracksAsync(int id, const Result& result); void LoadTracksAsync(int id, const Result& result);
bool IsLoggedIn(); bool IsLoggedIn();
bool CanShowConfig() const { return true; }
void ShowConfig(); void ShowConfig();
private slots: private slots:

View File

@ -58,9 +58,6 @@ public:
virtual QString Icon() { return QString(); } virtual QString Icon() { return QString(); }
// Services which need user login will need to reimplement this method
virtual bool IsLoggedIn() const { return true; }
public slots: public slots:
// Show configuration panel for services which have one // Show configuration panel for services which have one
virtual void ShowConfig() { } virtual void ShowConfig() { }