2017-04-27 20:24:53 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-11-06 10:39:59 -08:00
|
|
|
#ifndef IMAGEDOWNLOADER_H
|
|
|
|
#define IMAGEDOWNLOADER_H
|
|
|
|
|
|
|
|
#include <QImage>
|
|
|
|
#include <QFuture>
|
|
|
|
#include <QNetworkReply>
|
2018-03-10 14:15:50 +01:00
|
|
|
#include <QThreadPool>
|
2015-11-06 10:39:59 -08:00
|
|
|
|
|
|
|
class ImageDownloader : public QObject {
|
2018-03-06 10:38:21 +01:00
|
|
|
Q_OBJECT
|
2015-11-06 10:39:59 -08:00
|
|
|
public:
|
2018-03-07 16:37:31 +01:00
|
|
|
ImageDownloader(const QString &filename);
|
2016-01-09 16:29:49 +01:00
|
|
|
void load(bool fromHash);
|
2015-11-06 10:39:59 -08:00
|
|
|
|
|
|
|
private:
|
2018-02-08 22:45:55 +01:00
|
|
|
bool loadFromUrl(const QUrl &); // return true on success
|
|
|
|
void saveImage(QNetworkReply *reply, bool &success);
|
2018-03-07 16:37:31 +01:00
|
|
|
QString filename;
|
2015-11-06 10:39:59 -08:00
|
|
|
};
|
|
|
|
|
2018-03-10 14:15:50 +01:00
|
|
|
class PictureEntry;
|
|
|
|
class Thumbnailer : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static Thumbnailer *instance();
|
|
|
|
|
|
|
|
// Schedule a thumbnail for fetching or calculation.
|
|
|
|
// Returns a placehlder thumbnail. The actual thumbnail will be sent
|
|
|
|
// via a signal later.
|
2018-03-11 10:19:08 +01:00
|
|
|
QImage fetchThumbnail(PictureEntry &entry);
|
2018-03-10 14:15:50 +01:00
|
|
|
|
|
|
|
// If we change dive, clear all unfinished thumbnail creations
|
|
|
|
void clearWorkQueue();
|
2018-03-11 10:19:08 +01:00
|
|
|
static int maxThumbnailSize();
|
|
|
|
static int defaultThumbnailSize();
|
|
|
|
static int thumbnailSize(double zoomLevel);
|
2018-03-10 14:15:50 +01:00
|
|
|
signals:
|
|
|
|
void thumbnailChanged(QString filename, QImage thumbnail);
|
|
|
|
private:
|
|
|
|
Thumbnailer();
|
2018-03-11 10:19:08 +01:00
|
|
|
void processItem(QString filename);
|
2018-03-10 14:15:50 +01:00
|
|
|
|
|
|
|
mutable QMutex lock;
|
|
|
|
QThreadPool pool;
|
2018-03-11 10:19:08 +01:00
|
|
|
QImage failImage; // Shown when image-fetching fails
|
|
|
|
QImage dummyImage; // Shown before thumbnail is fetched
|
2018-03-10 14:15:50 +01:00
|
|
|
|
|
|
|
QMap<QString,QFuture<void>> workingOn;
|
|
|
|
};
|
|
|
|
|
2018-03-07 16:37:31 +01:00
|
|
|
QImage getHashedImage(const QString &filename);
|
2015-11-06 10:39:59 -08:00
|
|
|
|
|
|
|
#endif // IMAGEDOWNLOADER_H
|