Make it possible to receive SearchResults before SearchFinished

This commit is contained in:
Jonas Kvinge 2020-05-14 19:30:29 +02:00
parent 0ebfa10d32
commit e3c367984b
3 changed files with 20 additions and 2 deletions

View File

@ -101,6 +101,7 @@ void AlbumCoverFetcherSearch::Start(CoverProviders *cover_providers) {
continue; continue;
} }
connect(provider, SIGNAL(SearchResults(int, CoverSearchResults)), SLOT(ProviderSearchResults(int, CoverSearchResults)));
connect(provider, SIGNAL(SearchFinished(int, CoverSearchResults)), SLOT(ProviderSearchFinished(int, CoverSearchResults))); connect(provider, SIGNAL(SearchFinished(int, CoverSearchResults)), SLOT(ProviderSearchFinished(int, CoverSearchResults)));
const int id = cover_providers->NextId(); const int id = cover_providers->NextId();
const bool success = provider->StartSearch(request_.artist, request_.album, request_.title, id); const bool success = provider->StartSearch(request_.artist, request_.album, request_.title, id);
@ -118,10 +119,15 @@ void AlbumCoverFetcherSearch::Start(CoverProviders *cover_providers) {
} }
void AlbumCoverFetcherSearch::ProviderSearchFinished(const int id, const CoverSearchResults &results) { void AlbumCoverFetcherSearch::ProviderSearchResults(const int id, const CoverSearchResults &results) {
if (!pending_requests_.contains(id)) return; if (!pending_requests_.contains(id)) return;
CoverProvider *provider = pending_requests_.take(id); CoverProvider *provider = pending_requests_[id];
ProviderSearchResults(provider, results);
}
void AlbumCoverFetcherSearch::ProviderSearchResults(CoverProvider *provider, const CoverSearchResults &results) {
CoverSearchResults results_copy(results); CoverSearchResults results_copy(results);
for (int i = 0 ; i < results_copy.count() ; ++i) { for (int i = 0 ; i < results_copy.count() ; ++i) {
@ -142,6 +148,15 @@ void AlbumCoverFetcherSearch::ProviderSearchFinished(const int id, const CoverSe
results_.append(results_copy); results_.append(results_copy);
statistics_.total_images_by_provider_[provider->name()]++; statistics_.total_images_by_provider_[provider->name()]++;
}
void AlbumCoverFetcherSearch::ProviderSearchFinished(const int id, const CoverSearchResults &results) {
if (!pending_requests_.contains(id)) return;
CoverProvider *provider = pending_requests_.take(id);
ProviderSearchResults(provider, results);
// Do we have more providers left? // Do we have more providers left?
if (!pending_requests_.isEmpty()) { if (!pending_requests_.isEmpty()) {
return; return;

View File

@ -66,6 +66,8 @@ class AlbumCoverFetcherSearch : public QObject {
void AlbumCoverFetched(const quint64, const QUrl &cover_url, const QImage &cover); void AlbumCoverFetched(const quint64, const QUrl &cover_url, const QImage &cover);
private slots: private slots:
void ProviderSearchResults(const int id, const CoverSearchResults &results);
void ProviderSearchResults(CoverProvider *provider, const CoverSearchResults &results);
void ProviderSearchFinished(const int id, const CoverSearchResults &results); void ProviderSearchFinished(const int id, const CoverSearchResults &results);
void ProviderCoverFetchFinished(QNetworkReply *reply); void ProviderCoverFetchFinished(QNetworkReply *reply);
void TerminateSearch(); void TerminateSearch();

View File

@ -70,6 +70,7 @@ class CoverProvider : public QObject {
void AuthenticationComplete(bool, QStringList = QStringList()); void AuthenticationComplete(bool, QStringList = QStringList());
void AuthenticationSuccess(); void AuthenticationSuccess();
void AuthenticationFailure(QStringList); void AuthenticationFailure(QStringList);
void SearchResults(int, CoverSearchResults);
void SearchFinished(int, CoverSearchResults); void SearchFinished(int, CoverSearchResults);
private: private: