terminate the search for covers immediately if there are no providers

if there's a search timeout, send back the results gathered so far (if any)
fixing the previous commit
This commit is contained in:
Paweł Bara 2011-04-02 15:31:28 +00:00
parent 886f3d4d6f
commit 3c61fbdade
3 changed files with 20 additions and 7 deletions

View File

@ -33,15 +33,19 @@ AlbumCoverFetcherSearch::AlbumCoverFetcherSearch(const CoverSearchRequest& reque
network_(network)
{
// we will terminate the search after kSearchTimeout miliseconds if we are not
// able to find any results before that point in time
// able to find all of the results before that point in time
startTimer(kSearchTimeout);
}
void AlbumCoverFetcherSearch::timerEvent(QTimerEvent* event) {
Q_UNUSED(event);
TerminateSearch();
}
void AlbumCoverFetcherSearch::TerminateSearch() {
if(request_.search) {
emit SearchFinished(request_.id, CoverSearchResults());
// send everything we've managed to find
emit SearchFinished(request_.id, results_);
} else {
emit AlbumCoverFetched(request_.id, QImage());
}
@ -51,11 +55,16 @@ void AlbumCoverFetcherSearch::Start() {
QList<CoverProvider*> providers_list = CoverProviders::instance().List();
providers_left_ = providers_list.size();
foreach(CoverProvider* provider, providers_list) {
QNetworkReply* reply = provider->SendRequest(request_.query);
// end this search before it even began if there are no providers...
if(!providers_left_) {
TerminateSearch();
} else {
foreach(CoverProvider* provider, providers_list) {
QNetworkReply* reply = provider->SendRequest(request_.query);
connect(reply, SIGNAL(finished()), SLOT(ProviderSearchFinished()));
providers_.insert(reply, provider);
connect(reply, SIGNAL(finished()), SLOT(ProviderSearchFinished()));
providers_.insert(reply, provider);
}
}
}

View File

@ -62,6 +62,9 @@ private slots:
void ProviderCoverFetchFinished();
private:
// Timeouts this search.
void TerminateSearch();
// Search request encapsulated by this AlbumCoverFetcherSearch.
CoverSearchRequest request_;
// Complete results (from all of the available providers).

View File

@ -15,6 +15,7 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "coverprovider.h"
#include "coverproviders.h"
@ -30,7 +31,7 @@ CoverProviders::CoverProviders()
// the default parent, namely CoverProviders::instance(), will
// cause an infinite recursion here
#ifdef HAVE_LIBLASTFM
cover_providers_.append(new LastFmCoverProvider(this));
cover_providers_.append(new LastFmCoverProvider(this));
#endif
}