2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*/
|
|
|
|
|
2010-02-23 20:26:21 +01:00
|
|
|
#ifndef ALBUMCOVERFETCHER_H
|
|
|
|
#define ALBUMCOVERFETCHER_H
|
|
|
|
|
|
|
|
#include <QImage>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QObject>
|
2010-02-28 20:25:52 +01:00
|
|
|
#include <QQueue>
|
2010-02-23 20:26:21 +01:00
|
|
|
|
|
|
|
#include <lastfm/Album>
|
|
|
|
|
2010-03-03 20:14:14 +01:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
2010-02-23 20:26:21 +01:00
|
|
|
class QNetworkReply;
|
|
|
|
class QString;
|
|
|
|
|
|
|
|
class AlbumCoverFetcher : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2010-10-16 20:21:28 +02:00
|
|
|
AlbumCoverFetcher(QObject* parent = 0, QNetworkAccessManager* network = 0);
|
2010-02-23 20:26:21 +01:00
|
|
|
virtual ~AlbumCoverFetcher() {}
|
|
|
|
|
2010-06-12 19:13:01 +02:00
|
|
|
struct SearchResult {
|
|
|
|
QString artist;
|
|
|
|
QString album;
|
|
|
|
QString image_url;
|
|
|
|
};
|
|
|
|
typedef QList<SearchResult> SearchResults;
|
|
|
|
|
2010-02-28 20:25:52 +01:00
|
|
|
static const int kMaxConcurrentRequests;
|
|
|
|
|
2010-06-12 19:13:01 +02:00
|
|
|
quint64 SearchForCovers(const QString& query);
|
2010-02-28 20:25:52 +01:00
|
|
|
quint64 FetchAlbumCover(const QString& artist, const QString& album);
|
|
|
|
|
|
|
|
void Clear();
|
2010-02-23 20:26:21 +01:00
|
|
|
|
|
|
|
signals:
|
2010-02-28 20:25:52 +01:00
|
|
|
void AlbumCoverFetched(quint64, const QImage& cover);
|
2010-06-12 19:13:01 +02:00
|
|
|
void SearchFinished(quint64, const AlbumCoverFetcher::SearchResults& results);
|
2010-02-23 20:26:21 +01:00
|
|
|
|
|
|
|
private slots:
|
2010-06-22 15:54:07 +02:00
|
|
|
void AlbumSearchFinished();
|
2010-02-23 20:26:21 +01:00
|
|
|
void AlbumCoverFetchFinished();
|
2010-02-28 20:25:52 +01:00
|
|
|
void StartRequests();
|
2010-02-23 20:26:21 +01:00
|
|
|
|
|
|
|
private:
|
2010-02-28 20:25:52 +01:00
|
|
|
struct QueuedRequest {
|
|
|
|
quint64 id;
|
2010-06-12 19:13:01 +02:00
|
|
|
QString query;
|
2010-06-22 15:54:07 +02:00
|
|
|
bool search;
|
2010-02-28 20:25:52 +01:00
|
|
|
};
|
|
|
|
|
2010-06-12 19:13:01 +02:00
|
|
|
void AddRequest(const QueuedRequest req);
|
|
|
|
|
2010-03-03 21:35:19 +01:00
|
|
|
QNetworkAccessManager* network_;
|
2010-02-28 20:25:52 +01:00
|
|
|
quint64 next_id_;
|
|
|
|
|
|
|
|
QQueue<QueuedRequest> queued_requests_;
|
2010-06-22 15:54:07 +02:00
|
|
|
QMap<QNetworkReply*, QueuedRequest> active_requests_;
|
2010-02-28 20:25:52 +01:00
|
|
|
|
|
|
|
QTimer* request_starter_;
|
2010-02-23 20:26:21 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ALBUMCOVERFETCHER_H
|