mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-17 20:09:50 +01:00
Add a flag that search providers can set to indicate they want one art request at a time
This commit is contained in:
parent
1d2c142fdc
commit
c96d402f26
@ -142,18 +142,47 @@ void GlobalSearch::ProviderDestroyedSlot(QObject* object) {
|
||||
|
||||
int GlobalSearch::LoadArtAsync(const SearchProvider::Result& result) {
|
||||
const int id = next_id_ ++;
|
||||
|
||||
pending_art_searches_[id] = result.pixmap_cache_key_;
|
||||
result.provider_->LoadArtAsync(id, result);
|
||||
|
||||
if (result.provider_->wants_serialised_art()) {
|
||||
QueuedArt request;
|
||||
request.id_ = id;
|
||||
request.result_ = result;
|
||||
|
||||
queued_art_[result.provider_].append(request);
|
||||
|
||||
if (queued_art_[result.provider_].count() == 1) {
|
||||
TakeNextQueuedArt(result.provider_);
|
||||
}
|
||||
} else {
|
||||
result.provider_->LoadArtAsync(id, result);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
void GlobalSearch::TakeNextQueuedArt(SearchProvider* provider) {
|
||||
if (queued_art_[provider].isEmpty())
|
||||
return;
|
||||
|
||||
const QueuedArt& data = queued_art_[provider].first();
|
||||
provider->LoadArtAsync(data.id_, data.result_);
|
||||
}
|
||||
|
||||
void GlobalSearch::ArtLoadedSlot(int id, const QImage& image) {
|
||||
SearchProvider* provider = static_cast<SearchProvider*>(sender());
|
||||
const QString key = pending_art_searches_.take(id);
|
||||
|
||||
QPixmap pixmap = QPixmap::fromImage(image);
|
||||
pixmap_cache_.insert(key, pixmap);
|
||||
|
||||
emit ArtLoaded(id, pixmap);
|
||||
|
||||
if (!queued_art_[provider].isEmpty()) {
|
||||
queued_art_[provider].removeFirst();
|
||||
TakeNextQueuedArt(provider);
|
||||
}
|
||||
}
|
||||
|
||||
bool GlobalSearch::FindCachedPixmap(const SearchProvider::Result& result,
|
||||
|
@ -63,6 +63,7 @@ private slots:
|
||||
void ProviderDestroyedSlot(QObject* object);
|
||||
|
||||
private:
|
||||
void TakeNextQueuedArt(SearchProvider* provider);
|
||||
QString PixmapCacheKey(const SearchProvider::Result& result) const;
|
||||
|
||||
private:
|
||||
@ -72,9 +73,15 @@ private:
|
||||
QList<SearchProvider*> providers_;
|
||||
};
|
||||
|
||||
struct QueuedArt {
|
||||
int id_;
|
||||
SearchProvider::Result result_;
|
||||
};
|
||||
|
||||
QList<SearchProvider*> providers_;
|
||||
|
||||
QMap<int, DelayedSearch> delayed_searches_;
|
||||
QMap<SearchProvider*, QList<QueuedArt> > queued_art_;
|
||||
|
||||
int next_id_;
|
||||
QMap<int, int> pending_search_providers_;
|
||||
|
@ -31,7 +31,7 @@ LibrarySearchProvider::LibrarySearchProvider(LibraryBackendInterface* backend,
|
||||
backend_(backend),
|
||||
cover_loader_(new BackgroundThreadImplementation<AlbumCoverLoader, AlbumCoverLoader>(this))
|
||||
{
|
||||
Init(name, icon, false);
|
||||
Init(name, icon, false, true);
|
||||
|
||||
cover_loader_->Start(true);
|
||||
cover_loader_->Worker()->SetDesiredHeight(kArtHeight);
|
||||
|
@ -29,10 +29,12 @@ SearchProvider::SearchProvider(QObject* parent)
|
||||
{
|
||||
}
|
||||
|
||||
void SearchProvider::Init(const QString& name, const QIcon& icon, bool query_lag) {
|
||||
void SearchProvider::Init(const QString& name, const QIcon& icon,
|
||||
bool delay_searches, bool serialised_art) {
|
||||
name_ = name;
|
||||
icon_ = icon;
|
||||
query_lag_ = query_lag;
|
||||
delay_searches_ = delay_searches;
|
||||
serialised_art_ = serialised_art;
|
||||
}
|
||||
|
||||
QStringList SearchProvider::TokenizeQuery(const QString& query) {
|
||||
|
@ -70,7 +70,8 @@ public:
|
||||
|
||||
const QString& name() const { return name_; }
|
||||
const QIcon& icon() const { return icon_; }
|
||||
const bool wants_delayed_queries() const { return query_lag_; }
|
||||
const bool wants_delayed_queries() const { return delay_searches_; }
|
||||
const bool wants_serialised_art() const { return serialised_art_; }
|
||||
|
||||
// Starts a search. Must emit ResultsAvailable zero or more times and then
|
||||
// SearchFinished exactly once, using this ID.
|
||||
@ -102,12 +103,14 @@ protected:
|
||||
static Result::MatchQuality MatchQuality(const QStringList& tokens, const QString& string);
|
||||
|
||||
// Subclasses must call this from their constructor
|
||||
void Init(const QString& name, const QIcon& icon, bool query_lag);
|
||||
void Init(const QString& name, const QIcon& icon,
|
||||
bool delay_searches, bool serialised_art);
|
||||
|
||||
private:
|
||||
QString name_;
|
||||
QIcon icon_;
|
||||
bool query_lag_;
|
||||
bool delay_searches_;
|
||||
bool serialised_art_;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(SearchProvider::Result)
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
#include "spotifysearchprovider.h"
|
||||
#include "core/logging.h"
|
||||
#include "internet/internetmodel.h"
|
||||
#include "internet/spotifyserver.h"
|
||||
#include "internet/spotifyservice.h"
|
||||
@ -25,7 +26,7 @@ SpotifySearchProvider::SpotifySearchProvider(QObject* parent)
|
||||
server_(NULL),
|
||||
service_(NULL)
|
||||
{
|
||||
Init("Spotify", QIcon(":icons/svg/spotify.svg"), true);
|
||||
Init("Spotify", QIcon(":icons/svg/spotify.svg"), true, true);
|
||||
}
|
||||
|
||||
SpotifyServer* SpotifySearchProvider::server() {
|
||||
@ -101,6 +102,7 @@ void SpotifySearchProvider::LoadArtAsync(int id, const Result& result) {
|
||||
}
|
||||
|
||||
QString image_id = result.metadata_.url().path();
|
||||
qLog(Debug) << __PRETTY_FUNCTION__ << image_id;
|
||||
if (image_id.startsWith('/'))
|
||||
image_id.remove(0, 1);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user