1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#ifndef ALBUMCOVERLOADER_H
19
#define ALBUMCOVERLOADER_H
21
#include "backgroundthread.h"
29
class NetworkAccessManager;
32
class AlbumCoverLoader : public QObject {
36
AlbumCoverLoader(QObject* parent = 0);
38
void Stop() { stop_requested_ = true; }
40
static QString ImageCacheDir();
42
void SetDesiredHeight(int height) { height_ = height; }
43
void SetScaleOutputImage(bool scale) { scale_ = scale; }
44
void SetPadOutputImage(bool padding) { padding_ = padding; }
45
void SetDefaultOutputImage(const QImage& image);
48
quint64 LoadImageAsync(const Song& song);
49
virtual quint64 LoadImageAsync(
50
const QString& art_automatic,
51
const QString& art_manual,
52
const QString& song_filename = QString(),
53
const QImage& embedded_image = QImage());
57
static QPixmap TryLoadPixmap(const QString& automatic, const QString& manual,
58
const QString& filename = QString());
61
void ImageLoaded(quint64 id, const QImage& image);
62
void ImageLoaded(quint64 id, const QImage& scaled, const QImage& original);
66
void RemoteFetchFinished();
75
Task() : redirects(0) {}
77
QString art_automatic;
79
QString song_filename;
80
QImage embedded_image;
85
struct TryLoadResult {
86
TryLoadResult(bool async, bool success, const QImage& i)
87
: started_async(async), loaded_success(success), image(i) {}
94
void ProcessTask(Task* task);
95
void NextState(Task* task);
96
TryLoadResult TryLoadImage(const Task& task);
97
QImage ScaleAndPad(const QImage& image) const;
108
QMap<QNetworkReply*, Task> remote_tasks_;
111
NetworkAccessManager* network_;
113
static const int kMaxRedirects = 3;
116
#endif // ALBUMCOVERLOADER_H