1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-17 12:02:48 +01:00

When toggling provider button, check if provider can be used by checking if user is logged-in, it this is necessary to make the provider work

This commit is contained in:
Arnaud Bienner 2011-10-20 15:03:47 +02:00
parent da825d4659
commit f0c8703dbc
11 changed files with 66 additions and 9 deletions

View File

@ -223,16 +223,26 @@ int GlobalSearch::LoadTracksAsync(const SearchProvider::Result& result) {
return id;
}
void GlobalSearch::SetProviderEnabled(const SearchProvider* const_provider,
bool GlobalSearch::SetProviderEnabled(const SearchProvider* const_provider,
bool enabled) {
SearchProvider* provider = const_cast<SearchProvider*>(const_provider);
if (!providers_.contains(provider))
return;
return true;
if (providers_[provider].enabled_ != enabled) {
providers_[provider].enabled_ = enabled;
emit ProviderToggled(provider, enabled);
// If we try to enable this provider but it is not logged in, don't change
// state, and show configuration menu, if any
if (enabled && !provider->IsLoggedIn()) {
provider->ShowConfig();
return false;
} else {
providers_[provider].enabled_ = enabled;
emit ProviderToggled(provider, enabled);
return true;
}
// TODO: save providers
}
return true;
}
bool GlobalSearch::is_provider_enabled(const SearchProvider* const_provider) const {

View File

@ -34,7 +34,9 @@ public:
static const char* kSettingsGroup;
void AddProvider(SearchProvider* provider);
void SetProviderEnabled(const SearchProvider* provider, bool enabled);
// Try to change provider state. Returns false if we can't (e.g. we can't
// enable a provider because it requires the user to be logged-in)
bool SetProviderEnabled(const SearchProvider* provider, bool enabled);
int SearchAsync(const QString& query);
int LoadArtAsync(const SearchProvider::Result& result);

View File

@ -771,5 +771,8 @@ void GlobalSearchWidget::ProviderButtonToggled(bool on) {
if (!provider)
return;
engine_->SetProviderEnabled(provider, on);
if (!engine_->SetProviderEnabled(provider, on)) {
// If we were not able to change provider state, toggle back provider button
button->toggle();
}
}

View File

@ -131,6 +131,14 @@ void GroovesharkSearchProvider::LoadTracksAsync(int id, const Result& result) {
}
bool GroovesharkSearchProvider::IsLoggedIn() {
return (service_ && service_->IsLoggedIn());
}
void GroovesharkSearchProvider::ShowConfig() {
service_->ShowConfig();
}
void GroovesharkSearchProvider::FetchAlbum(int id, const Result& result) {
service_->FetchSongsForAlbum(id, result.metadata_.url());
}

View File

@ -35,6 +35,8 @@ class GroovesharkSearchProvider : public SearchProvider {
void SearchAsync(int id, const QString& query);
void LoadArtAsync(int id, const Result& result);
void LoadTracksAsync(int id, const Result& result);
bool IsLoggedIn();
void ShowConfig();
private slots:
void SearchDone(int id, const SongList& songs);

View File

@ -94,6 +94,11 @@ public:
// ResultsAvailable. Must emit TracksLoaded exactly once with this ID.
virtual void LoadTracksAsync(int id, const Result& result) = 0;
// If provider needs user login to search and play songs, this method should
// be reimplemented
virtual bool IsLoggedIn() { return true; }
virtual void ShowConfig() { }
static QImage ScaleAndPad(const QImage& image);
signals:

View File

@ -192,4 +192,15 @@ void SpotifySearchProvider::AlbumBrowseResponse(const spotify_pb::BrowseAlbumRes
emit TracksLoaded(orig_id, mime_data);
}
bool SpotifySearchProvider::IsLoggedIn() {
if (server()) {
return service_->IsLoggedIn();
}
return false;
}
void SpotifySearchProvider::ShowConfig() {
if (service_) {
return service_->ShowConfig();
}
}

View File

@ -35,6 +35,9 @@ public:
void LoadArtAsync(int id, const Result& result);
void LoadTracksAsync(int id, const Result& result);
bool IsLoggedIn();
void ShowConfig();
private slots:
void ServerDestroyed();
void SearchFinishedSlot(const spotify_pb::SearchResponse& response);

View File

@ -61,7 +61,7 @@ class GroovesharkService : public InternetService {
qint64* length_nanosec);
void Login(const QString& username, const QString& password);
void Logout();
bool IsLoggedIn() { return !session_id_.isEmpty(); }
bool IsLoggedIn() const { return !session_id_.isEmpty(); }
void RetrieveUserPlaylists();
void MarkStreamKeyOver30Secs(const QString& stream_key, const QString& server_id);
void MarkSongComplete(const QString& song_id, const QString& stream_key, const QString& server_id);
@ -92,6 +92,9 @@ class GroovesharkService : public InternetService {
void AlbumSearchResult(int id, SongList songs);
void AlbumSongsLoaded(int id, SongList songs);
public slots:
void ShowConfig();
protected:
QModelIndex GetCurrentIndex();
@ -107,7 +110,6 @@ class GroovesharkService : public InternetService {
private slots:
void UpdateTotalSongCount(int count);
void ShowConfig();
void SessionCreated();
void OpenSearchTab();
void DoSearch();

View File

@ -56,6 +56,14 @@ public:
virtual QString Icon() { return QString(); }
// Services which need user login will need to reimplement this method
virtual bool IsLoggedIn() const { return true; }
public slots:
// Show configuration panel for services which have one
virtual void ShowConfig() { }
signals:
void StreamError(const QString& message);
void StreamMetadataFound(const QUrl& original_url, const Song& song);

View File

@ -68,6 +68,7 @@ public:
// Persisted in the settings and updated on each Login().
LoginState login_state() const { return login_state_; }
bool IsLoggedIn() const { return login_state_ == LoginState_LoggedIn; }
static void SongFromProtobuf(const spotify_pb::Track& track, Song* song);
@ -76,6 +77,9 @@ signals:
void LoginFinished(bool success);
void ImageLoaded(const QUrl& url, const QImage& image);
public slots:
void ShowConfig();
protected:
virtual QModelIndex GetCurrentIndex();
@ -104,7 +108,6 @@ private slots:
void OpenSearchTab();
void DoSearch();
void ShowConfig();
void SyncPlaylist();
void BlobDownloadFinished();