2010-03-24 00:11:46 +01: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-28 19:04:50 +01:00
|
|
|
#ifndef ALBUMCOVERLOADER_H
|
|
|
|
#define ALBUMCOVERLOADER_H
|
|
|
|
|
|
|
|
#include "backgroundthread.h"
|
2010-07-19 19:55:02 +02:00
|
|
|
#include "song.h"
|
2010-02-28 19:04:50 +01:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QMutex>
|
|
|
|
#include <QQueue>
|
|
|
|
|
2010-05-10 15:15:52 +02:00
|
|
|
class NetworkAccessManager;
|
|
|
|
class QNetworkReply;
|
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
class AlbumCoverLoader : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
AlbumCoverLoader(QObject* parent = 0);
|
2010-05-10 15:15:52 +02:00
|
|
|
|
|
|
|
void SetNetwork(NetworkAccessManager* network) { network_ = network; }
|
2010-03-25 15:33:09 +01:00
|
|
|
|
|
|
|
void Stop() { stop_requested_ = true; }
|
2010-02-28 19:04:50 +01:00
|
|
|
|
2010-02-28 20:25:52 +01:00
|
|
|
static QString ImageCacheDir();
|
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
void SetDesiredHeight(int height) { height_ = height; }
|
2010-05-17 00:41:01 +02:00
|
|
|
void SetPadOutputImage(bool padding) { padding_ = padding; }
|
2010-05-17 00:53:42 +02:00
|
|
|
void SetDefaultOutputImage(const QImage& image);
|
2010-07-19 19:55:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
quint64 LoadImageAsync(const Song& song);
|
|
|
|
quint64 LoadImageAsync(const QString& art_automatic,
|
|
|
|
const QString& art_manual,
|
|
|
|
const QString& song_filename = QString(),
|
|
|
|
const QImage& embedded_image = QImage());
|
2010-02-28 19:04:50 +01:00
|
|
|
|
|
|
|
void Clear();
|
|
|
|
|
2010-03-03 15:29:53 +01:00
|
|
|
static QPixmap TryLoadPixmap(const QString& automatic, const QString& manual);
|
|
|
|
|
|
|
|
static const char* kManuallyUnsetCover;
|
2010-07-19 19:55:02 +02:00
|
|
|
static const char* kEmbeddedCover;
|
2010-03-03 15:29:53 +01:00
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
signals:
|
|
|
|
void ImageLoaded(quint64 id, const QImage& image);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void ProcessTasks();
|
2010-05-10 15:15:52 +02:00
|
|
|
void RemoteFetchFinished(quint64 id, QNetworkReply* reply);
|
2010-02-28 19:04:50 +01:00
|
|
|
|
|
|
|
private:
|
2010-05-10 15:15:52 +02:00
|
|
|
enum State {
|
|
|
|
State_TryingManual,
|
|
|
|
State_TryingAuto,
|
|
|
|
};
|
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
struct Task {
|
|
|
|
quint64 id;
|
|
|
|
QString art_automatic;
|
|
|
|
QString art_manual;
|
2010-07-19 19:55:02 +02:00
|
|
|
QString song_filename;
|
|
|
|
QImage embedded_image;
|
2010-05-10 15:15:52 +02:00
|
|
|
State state;
|
2010-02-28 19:04:50 +01:00
|
|
|
};
|
|
|
|
|
2010-05-10 15:15:52 +02:00
|
|
|
struct TryLoadResult {
|
2010-07-19 19:55:02 +02:00
|
|
|
TryLoadResult(bool async, bool success, const QImage& i)
|
2010-05-10 15:15:52 +02:00
|
|
|
: started_async(async), loaded_success(success), image(i) {}
|
|
|
|
|
|
|
|
bool started_async;
|
|
|
|
bool loaded_success;
|
|
|
|
QImage image;
|
|
|
|
};
|
|
|
|
|
|
|
|
void ProcessTask(Task* task);
|
|
|
|
void NextState(Task* task);
|
|
|
|
TryLoadResult TryLoadImage(const Task& task);
|
|
|
|
QImage ScaleAndPad(const QImage& image) const;
|
2010-07-19 19:55:02 +02:00
|
|
|
QImage LoadFromTaglib(const QString& filename) const;
|
2010-05-10 15:15:52 +02:00
|
|
|
|
2010-03-25 15:33:09 +01:00
|
|
|
bool stop_requested_;
|
|
|
|
|
2010-02-28 19:04:50 +01:00
|
|
|
int height_;
|
2010-05-17 00:41:01 +02:00
|
|
|
bool padding_;
|
2010-05-17 00:53:42 +02:00
|
|
|
QImage default_;
|
2010-02-28 19:04:50 +01:00
|
|
|
|
|
|
|
QMutex mutex_;
|
|
|
|
QQueue<Task> tasks_;
|
2010-05-10 15:15:52 +02:00
|
|
|
QMap<quint64, Task> remote_tasks_;
|
2010-02-28 19:04:50 +01:00
|
|
|
quint64 next_id_;
|
2010-05-10 15:15:52 +02:00
|
|
|
|
|
|
|
NetworkAccessManager* network_;
|
2010-02-28 19:04:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ALBUMCOVERLOADER_H
|