mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-16 19:31:02 +01:00
Fix the spotify resolver to not crash when not connected to spotify, or after logging out.
Fixes issue 2399
This commit is contained in:
parent
5f0afa397c
commit
fc0e2c4ea6
@ -52,7 +52,7 @@ SpotifyServer* SpotifySearchProvider::server() {
|
||||
SLOT(AlbumBrowseResponse(spotify_pb::BrowseAlbumResponse)));
|
||||
connect(server_, SIGNAL(destroyed()), SLOT(ServerDestroyed()));
|
||||
|
||||
return service_->server();
|
||||
return server_;
|
||||
}
|
||||
|
||||
void SpotifySearchProvider::ServerDestroyed() {
|
||||
|
@ -19,7 +19,7 @@ SongResolver::SongResolver(LibraryBackendInterface* library, QObject* parent)
|
||||
// Register in the order they should be checked.
|
||||
RegisterResolver(new LibraryResolver(library));
|
||||
#ifdef HAVE_SPOTIFY
|
||||
RegisterResolver(new SpotifyResolver(InternetModel::Service<SpotifyService>()->server()));
|
||||
RegisterResolver(new SpotifyResolver(InternetModel::Service<SpotifyService>()));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -6,15 +6,39 @@
|
||||
#include "internet/spotifyservice.h"
|
||||
#include "spotifyblob/common/spotifymessages.pb.h"
|
||||
|
||||
SpotifyResolver::SpotifyResolver(SpotifyServer* spotify, QObject* parent)
|
||||
SpotifyResolver::SpotifyResolver(SpotifyService* service, QObject* parent)
|
||||
: Resolver(parent),
|
||||
spotify_(spotify),
|
||||
next_id_(0) {
|
||||
connect(spotify_, SIGNAL(SearchResults(spotify_pb::SearchResponse)),
|
||||
service_(service),
|
||||
server_(NULL),
|
||||
next_id_(0)
|
||||
{
|
||||
}
|
||||
|
||||
SpotifyServer* SpotifyResolver::server() {
|
||||
if (server_)
|
||||
return server_;
|
||||
|
||||
if (service_->login_state() != SpotifyService::LoginState_LoggedIn)
|
||||
return NULL;
|
||||
|
||||
server_ = service_->server();
|
||||
connect(server_, SIGNAL(SearchResults(spotify_pb::SearchResponse)),
|
||||
SLOT(SearchFinished(spotify_pb::SearchResponse)));
|
||||
connect(server_, SIGNAL(destroyed()), SLOT(ServerDestroyed()));
|
||||
|
||||
return server_;
|
||||
}
|
||||
|
||||
void SpotifyResolver::ServerDestroyed() {
|
||||
server_ = NULL;
|
||||
}
|
||||
|
||||
int SpotifyResolver::ResolveSong(const Song& song) {
|
||||
SpotifyServer* s = server();
|
||||
if (!s) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
QString query_string;
|
||||
query_string += "artist:\"" + song.artist() + "\"";
|
||||
query_string += " title:\"" + song.title() + "\"";
|
||||
@ -22,7 +46,7 @@ int SpotifyResolver::ResolveSong(const Song& song) {
|
||||
|
||||
qLog(Debug) << query_string;
|
||||
|
||||
spotify_->Search(query_string, 25);
|
||||
s->Search(query_string, 25);
|
||||
|
||||
int id = next_id_++;
|
||||
queries_[query_string] = id;
|
||||
|
@ -9,12 +9,13 @@ namespace spotify_pb {
|
||||
class SearchResponse;
|
||||
}
|
||||
|
||||
class SpotifyService;
|
||||
class SpotifyServer;
|
||||
|
||||
class SpotifyResolver : public Resolver {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SpotifyResolver(SpotifyServer* service, QObject* parent = 0);
|
||||
SpotifyResolver(SpotifyService* service, QObject* parent = 0);
|
||||
int ResolveSong(const Song& song);
|
||||
|
||||
signals:
|
||||
@ -22,9 +23,14 @@ class SpotifyResolver : public Resolver {
|
||||
|
||||
private slots:
|
||||
void SearchFinished(const spotify_pb::SearchResponse& response);
|
||||
void ServerDestroyed();
|
||||
|
||||
private:
|
||||
SpotifyServer* spotify_;
|
||||
SpotifyServer* server();
|
||||
|
||||
private:
|
||||
SpotifyService* service_;
|
||||
SpotifyServer* server_;
|
||||
QMap<QString, int> queries_;
|
||||
int next_id_;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user