2011-04-02 15:34:06 +02:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ALBUMCOVERFETCHERSEARCH_H
|
|
|
|
#define ALBUMCOVERFETCHERSEARCH_H
|
|
|
|
|
|
|
|
#include "albumcoverfetcher.h"
|
|
|
|
|
|
|
|
#include <QMap>
|
|
|
|
#include <QObject>
|
|
|
|
|
|
|
|
class CoverProvider;
|
2011-07-23 20:34:41 +02:00
|
|
|
class CoverProviders;
|
2011-06-26 17:07:19 +02:00
|
|
|
class NetworkTimeouts;
|
2011-04-02 15:34:06 +02:00
|
|
|
class QNetworkAccessManager;
|
|
|
|
class QNetworkReply;
|
|
|
|
|
2011-06-20 01:15:51 +02:00
|
|
|
// This class encapsulates a single search for covers initiated by an
|
|
|
|
// AlbumCoverFetcher. The search engages all of the known cover providers.
|
|
|
|
// AlbumCoverFetcherSearch signals search results to an interested
|
|
|
|
// AlbumCoverFetcher when all of the providers have done their part.
|
2011-04-02 15:34:06 +02:00
|
|
|
class AlbumCoverFetcherSearch : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2011-06-20 01:15:51 +02:00
|
|
|
AlbumCoverFetcherSearch(const CoverSearchRequest& request,
|
|
|
|
QNetworkAccessManager* network, QObject* parent);
|
2011-04-02 15:34:06 +02:00
|
|
|
|
2011-07-23 20:34:41 +02:00
|
|
|
void Start(CoverProviders* cover_providers);
|
2011-04-02 15:34:06 +02:00
|
|
|
|
2011-06-26 17:07:29 +02:00
|
|
|
// Cancels all pending requests. No Finished signals will be emitted, and it
|
|
|
|
// is the caller's responsibility to delete the AlbumCoverFetcherSearch.
|
|
|
|
void Cancel();
|
|
|
|
|
2011-06-26 17:07:48 +02:00
|
|
|
CoverSearchStatistics statistics() const { return statistics_; }
|
|
|
|
|
2011-04-02 15:34:06 +02:00
|
|
|
signals:
|
|
|
|
// It's the end of search (when there was no fetch-me-a-cover request).
|
2011-06-20 01:15:29 +02:00
|
|
|
void SearchFinished(quint64, const CoverSearchResults& results);
|
2011-06-26 17:07:48 +02:00
|
|
|
|
2011-04-02 15:34:06 +02:00
|
|
|
// It's the end of search and we've fetched a cover.
|
|
|
|
void AlbumCoverFetched(quint64, const QImage& cover);
|
|
|
|
|
|
|
|
private slots:
|
2011-06-20 01:15:51 +02:00
|
|
|
void ProviderSearchFinished(int id, const QList<CoverSearchResult>& results);
|
2011-04-02 15:34:06 +02:00
|
|
|
void ProviderCoverFetchFinished();
|
2011-06-26 17:07:19 +02:00
|
|
|
void TerminateSearch();
|
2011-04-02 15:34:06 +02:00
|
|
|
|
|
|
|
private:
|
2011-06-26 17:07:19 +02:00
|
|
|
void AllProvidersFinished();
|
|
|
|
|
|
|
|
void FetchMoreImages();
|
|
|
|
float ScoreImage(const QImage& image) const;
|
|
|
|
void SendBestImage();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const int kSearchTimeoutMs;
|
|
|
|
static const int kImageLoadTimeoutMs;
|
|
|
|
static const int kTargetSize;
|
|
|
|
static const float kGoodScore;
|
2011-04-02 17:31:28 +02:00
|
|
|
|
2011-06-26 17:07:48 +02:00
|
|
|
CoverSearchStatistics statistics_;
|
|
|
|
|
2011-04-02 15:34:06 +02:00
|
|
|
// Search request encapsulated by this AlbumCoverFetcherSearch.
|
|
|
|
CoverSearchRequest request_;
|
2011-06-26 17:07:19 +02:00
|
|
|
|
2011-04-02 15:34:06 +02:00
|
|
|
// Complete results (from all of the available providers).
|
|
|
|
CoverSearchResults results_;
|
|
|
|
|
2011-06-20 01:15:51 +02:00
|
|
|
QMap<int, CoverProvider*> pending_requests_;
|
2011-06-26 17:07:48 +02:00
|
|
|
QMap<QNetworkReply*, QString> pending_image_loads_;
|
2011-06-26 17:07:19 +02:00
|
|
|
NetworkTimeouts* image_load_timeout_;
|
|
|
|
|
2011-06-26 17:07:48 +02:00
|
|
|
// QMap is sorted by key (score). Values are (provider_name, image)
|
|
|
|
typedef QPair<QString, QImage> CandidateImage;
|
|
|
|
QMap<float, CandidateImage> candidate_images_;
|
2011-04-02 15:34:06 +02:00
|
|
|
|
|
|
|
QNetworkAccessManager* network_;
|
2011-06-26 17:07:29 +02:00
|
|
|
|
|
|
|
bool cancel_requested_;
|
2011-04-02 15:34:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ALBUMCOVERFETCHERSEARCH_H
|