diff --git a/src/globalsearch/digitallyimportedsearchprovider.cpp b/src/globalsearch/digitallyimportedsearchprovider.cpp index 6eb89ec1b..014a4501d 100644 --- a/src/globalsearch/digitallyimportedsearchprovider.cpp +++ b/src/globalsearch/digitallyimportedsearchprovider.cpp @@ -24,7 +24,7 @@ DigitallyImportedSearchProvider::DigitallyImportedSearchProvider( : SimpleSearchProvider(parent), service_(service) { - Init(service_->name(), service->url_scheme(), service_->icon(), false, false); + Init(service_->name(), service->url_scheme(), service_->icon()); icon_ = ScaleAndPad(QImage(service_->icon_path())); set_safe_words(QStringList() << "sky.fm" << "skyfm" << "di.fm" << "difm" diff --git a/src/globalsearch/groovesharksearchprovider.cpp b/src/globalsearch/groovesharksearchprovider.cpp index 2ea2e4960..2a4238809 100644 --- a/src/globalsearch/groovesharksearchprovider.cpp +++ b/src/globalsearch/groovesharksearchprovider.cpp @@ -31,7 +31,9 @@ GroovesharkSearchProvider::GroovesharkSearchProvider(QObject* parent) void GroovesharkSearchProvider::Init(GroovesharkService* service) { service_ = service; SearchProvider::Init("Grooveshark", "grooveshark", - QIcon(":providers/grooveshark.png"), true, false); + QIcon(":providers/grooveshark.png"), + WantsDelayedQueries | ArtIsProbablyRemote); + connect(service_, SIGNAL(SimpleSearchResults(int, SongList)), SLOT(SearchDone(int, SongList))); connect(service_, SIGNAL(AlbumSearchResult(int, SongList)), diff --git a/src/globalsearch/lastfmsearchprovider.cpp b/src/globalsearch/lastfmsearchprovider.cpp index 5300f0ca6..9e01b727d 100644 --- a/src/globalsearch/lastfmsearchprovider.cpp +++ b/src/globalsearch/lastfmsearchprovider.cpp @@ -23,7 +23,7 @@ LastFMSearchProvider::LastFMSearchProvider(LastFMService* service, QObject* parent) : SimpleSearchProvider(parent), service_(service) { - Init("Last.fm", "lastfm", QIcon(":last.fm/as.png"), false, false); + Init("Last.fm", "lastfm", QIcon(":last.fm/as.png")); icon_ = ScaleAndPad(QImage(":last.fm/as.png")); set_safe_words(QStringList() << "lastfm" << "last.fm"); diff --git a/src/globalsearch/librarysearchprovider.cpp b/src/globalsearch/librarysearchprovider.cpp index 770ff4539..dad24f589 100644 --- a/src/globalsearch/librarysearchprovider.cpp +++ b/src/globalsearch/librarysearchprovider.cpp @@ -33,7 +33,7 @@ LibrarySearchProvider::LibrarySearchProvider(LibraryBackendInterface* backend, backend_(backend), cover_loader_(new BackgroundThreadImplementation(this)) { - Init(name, id, icon, false, true); + Init(name, id, icon, WantsSerialisedArtQueries); cover_loader_->Start(true); cover_loader_->Worker()->SetDesiredHeight(kArtHeight); diff --git a/src/globalsearch/searchprovider.cpp b/src/globalsearch/searchprovider.cpp index fcd958a32..042e78101 100644 --- a/src/globalsearch/searchprovider.cpp +++ b/src/globalsearch/searchprovider.cpp @@ -25,17 +25,17 @@ const int SearchProvider::kArtHeight = 32; SearchProvider::SearchProvider(QObject* parent) - : QObject(parent) + : QObject(parent), + hints_(0) { } -void SearchProvider::Init(const QString& name, const QString& id, const QIcon& icon, - bool delay_searches, bool serialised_art) { +void SearchProvider::Init(const QString& name, const QString& id, + const QIcon& icon, Hints hints) { name_ = name; id_ = id; icon_ = icon; - delay_searches_ = delay_searches; - serialised_art_ = serialised_art; + hints_ = hints; } QStringList SearchProvider::TokenizeQuery(const QString& query) { diff --git a/src/globalsearch/searchprovider.h b/src/globalsearch/searchprovider.h index 742e729d8..a0a4262bb 100644 --- a/src/globalsearch/searchprovider.h +++ b/src/globalsearch/searchprovider.h @@ -76,11 +76,34 @@ public: }; typedef QList ResultList; + enum Hint { + NoHints = 0x00, + + // Indicates that queries to this provider mean making requests to a third + // party. To be polite, queries should be buffered by a few milliseconds + // instead of executing them each time the user types a character. + WantsDelayedQueries = 0x01, + + // Indicates that this provider wants to be given art queries one after the + // other (serially), instead of all at once (in parallel). + WantsSerialisedArtQueries = 0x02, + + // Indicates that album cover art is probably going to be loaded remotely. + // If a third-party application is making art requests over dbus and has + // to get all the art it can before showing results to the user, it might + // not load art from this provider. + ArtIsProbablyRemote = 0x04 + }; + Q_DECLARE_FLAGS(Hints, Hint) + const QString& name() const { return name_; } const QString& id() const { return id_; } const QIcon& icon() const { return icon_; } - const bool wants_delayed_queries() const { return delay_searches_; } - const bool wants_serialised_art() const { return serialised_art_; } + + Hints hints() const { return hints_; } + bool wants_delayed_queries() const { return hints() & WantsDelayedQueries; } + bool wants_serialised_art() const { return hints() & WantsSerialisedArtQueries; } + bool art_is_probably_remote() const { return hints() & ArtIsProbablyRemote; } // Starts a search. Must emit ResultsAvailable zero or more times and then // SearchFinished exactly once, using this ID. @@ -116,18 +139,18 @@ protected: // Subclasses must call this from their constructors. void Init(const QString& name, const QString& id, const QIcon& icon, - bool delay_searches, bool serialised_art); + Hints hints = NoHints); private: QString name_; QString id_; QIcon icon_; - bool delay_searches_; - bool serialised_art_; + Hints hints_; }; Q_DECLARE_METATYPE(SearchProvider::Result) Q_DECLARE_METATYPE(SearchProvider::ResultList) +Q_DECLARE_OPERATORS_FOR_FLAGS(SearchProvider::Hints) class BlockingSearchProvider : public SearchProvider { diff --git a/src/globalsearch/spotifysearchprovider.cpp b/src/globalsearch/spotifysearchprovider.cpp index 814ab6599..8b3c8e86a 100644 --- a/src/globalsearch/spotifysearchprovider.cpp +++ b/src/globalsearch/spotifysearchprovider.cpp @@ -28,7 +28,8 @@ SpotifySearchProvider::SpotifySearchProvider(QObject* parent) server_(NULL), service_(NULL) { - Init("Spotify", "spotify", QIcon(":icons/svg/spotify.svg"), true, true); + Init("Spotify", "spotify", QIcon(":icons/svg/spotify.svg"), + WantsDelayedQueries | WantsSerialisedArtQueries | ArtIsProbablyRemote); } SpotifyServer* SpotifySearchProvider::server() {