2010-03-23 23:11:46 +00:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
|
|
|
|
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 19:26:21 +00:00
|
|
|
#ifndef ALBUMCOVERFETCHER_H
|
|
|
|
#define ALBUMCOVERFETCHER_H
|
|
|
|
|
|
|
|
#include <QImage>
|
|
|
|
#include <QMap>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QObject>
|
2010-02-28 19:25:52 +00:00
|
|
|
#include <QQueue>
|
2010-02-23 19:26:21 +00:00
|
|
|
|
|
|
|
#include <lastfm/Album>
|
|
|
|
|
2010-03-03 19:14:14 +00:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
2010-02-23 19:26:21 +00:00
|
|
|
class QNetworkReply;
|
|
|
|
class QString;
|
|
|
|
|
2010-05-10 13:15:52 +00:00
|
|
|
class NetworkAccessManager;
|
|
|
|
|
2010-02-23 19:26:21 +00:00
|
|
|
class AlbumCoverFetcher : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2010-05-10 13:15:52 +00:00
|
|
|
AlbumCoverFetcher(NetworkAccessManager* network, QObject* parent = 0);
|
2010-02-23 19:26:21 +00:00
|
|
|
virtual ~AlbumCoverFetcher() {}
|
|
|
|
|
2010-02-28 19:25:52 +00:00
|
|
|
static const int kMaxConcurrentRequests;
|
|
|
|
|
|
|
|
quint64 FetchAlbumCover(const QString& artist, const QString& album);
|
|
|
|
|
|
|
|
void Clear();
|
2010-02-23 19:26:21 +00:00
|
|
|
|
|
|
|
signals:
|
2010-02-28 19:25:52 +00:00
|
|
|
void AlbumCoverFetched(quint64, const QImage& cover);
|
2010-02-23 19:26:21 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void AlbumGetInfoFinished();
|
|
|
|
void AlbumCoverFetchFinished();
|
2010-02-28 19:25:52 +00:00
|
|
|
void StartRequests();
|
2010-02-23 19:26:21 +00:00
|
|
|
|
|
|
|
private:
|
2010-02-28 19:25:52 +00:00
|
|
|
struct QueuedRequest {
|
|
|
|
quint64 id;
|
|
|
|
QString artist;
|
|
|
|
QString album;
|
|
|
|
};
|
|
|
|
|
2010-03-03 20:35:19 +00:00
|
|
|
QNetworkAccessManager* network_;
|
2010-02-28 19:25:52 +00:00
|
|
|
quint64 next_id_;
|
|
|
|
|
|
|
|
QQueue<QueuedRequest> queued_requests_;
|
|
|
|
QMap<QNetworkReply*, quint64> active_requests_;
|
|
|
|
|
|
|
|
QTimer* request_starter_;
|
2010-02-23 19:26:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ALBUMCOVERFETCHER_H
|