2017-04-27 18:24:53 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-11-06 18:39:59 +00:00
|
|
|
#ifndef IMAGEDOWNLOADER_H
|
|
|
|
#define IMAGEDOWNLOADER_H
|
|
|
|
|
2018-05-15 18:47:35 +00:00
|
|
|
#include "metadata.h"
|
2015-11-06 18:39:59 +00:00
|
|
|
#include <QImage>
|
|
|
|
#include <QFuture>
|
|
|
|
#include <QNetworkReply>
|
2018-03-10 13:15:50 +00:00
|
|
|
#include <QThreadPool>
|
2015-11-06 18:39:59 +00:00
|
|
|
|
|
|
|
class ImageDownloader : public QObject {
|
2018-03-06 09:38:21 +00:00
|
|
|
Q_OBJECT
|
2015-11-06 18:39:59 +00:00
|
|
|
public:
|
2018-03-11 11:58:55 +00:00
|
|
|
static ImageDownloader *instance();
|
|
|
|
ImageDownloader();
|
|
|
|
public slots:
|
2018-06-12 10:50:34 +00:00
|
|
|
void load(QUrl url, QString filename);
|
2018-03-11 11:58:55 +00:00
|
|
|
signals:
|
|
|
|
void loaded(QString filename);
|
|
|
|
void failed(QString filename);
|
2015-11-06 18:39:59 +00:00
|
|
|
private:
|
2018-03-11 11:58:55 +00:00
|
|
|
QNetworkAccessManager manager;
|
|
|
|
void loadFromUrl(const QString &filename, const QUrl &);
|
|
|
|
void saveImage(QNetworkReply *reply);
|
2015-11-06 18:39:59 +00:00
|
|
|
};
|
|
|
|
|
2018-05-18 19:11:15 +00:00
|
|
|
struct PictureEntry;
|
2018-03-10 13:15:50 +00:00
|
|
|
class Thumbnailer : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static Thumbnailer *instance();
|
|
|
|
|
|
|
|
// Schedule a thumbnail for fetching or calculation.
|
2018-06-30 09:36:37 +00:00
|
|
|
// Returns a placeholder thumbnail. The actual thumbnail will be sent
|
2018-03-10 13:15:50 +00:00
|
|
|
// via a signal later.
|
2018-06-30 09:36:37 +00:00
|
|
|
QImage fetchThumbnail(const QString &filename);
|
2018-03-10 13:15:50 +00:00
|
|
|
|
2018-05-27 12:03:29 +00:00
|
|
|
// Schedule multiple thumbnails for forced recalculation
|
|
|
|
void calculateThumbnails(const QVector<QString> &filenames);
|
|
|
|
|
2018-03-10 13:15:50 +00:00
|
|
|
// If we change dive, clear all unfinished thumbnail creations
|
|
|
|
void clearWorkQueue();
|
2018-03-11 09:19:08 +00:00
|
|
|
static int maxThumbnailSize();
|
|
|
|
static int defaultThumbnailSize();
|
|
|
|
static int thumbnailSize(double zoomLevel);
|
2018-03-11 11:58:55 +00:00
|
|
|
public slots:
|
|
|
|
void imageDownloaded(QString filename);
|
|
|
|
void imageDownloadFailed(QString filename);
|
2018-07-10 13:04:35 +00:00
|
|
|
void frameExtracted(QString filename, QImage thumbnail, duration_t duration, duration_t offset);
|
|
|
|
void frameExtractionFailed(QString filename, duration_t duration);
|
|
|
|
void frameExtractionInvalid(QString filename, duration_t duration);
|
2018-03-10 13:15:50 +00:00
|
|
|
signals:
|
2018-07-15 15:56:18 +00:00
|
|
|
void thumbnailChanged(QString filename, QImage thumbnail, duration_t duration);
|
2018-03-10 13:15:50 +00:00
|
|
|
private:
|
2018-05-15 18:47:35 +00:00
|
|
|
struct Thumbnail {
|
|
|
|
QImage img;
|
|
|
|
mediatype_t type;
|
2018-07-13 20:55:35 +00:00
|
|
|
duration_t duration;
|
2018-05-15 18:47:35 +00:00
|
|
|
};
|
|
|
|
|
2018-03-10 13:15:50 +00:00
|
|
|
Thumbnailer();
|
2018-07-10 13:04:35 +00:00
|
|
|
Thumbnail fetchVideoThumbnail(const QString &filename, const QString &originalFilename, duration_t duration);
|
|
|
|
Thumbnail extractVideoThumbnail(const QString &picture_filename, duration_t duration);
|
2018-07-15 15:56:18 +00:00
|
|
|
Thumbnail addPictureThumbnailToCache(const QString &picture_filename, const QImage &thumbnail);
|
2018-07-10 13:04:35 +00:00
|
|
|
Thumbnail addVideoThumbnailToCache(const QString &picture_filename, duration_t duration, const QImage &thumbnail, duration_t position);
|
2018-07-15 15:56:18 +00:00
|
|
|
Thumbnail addUnknownThumbnailToCache(const QString &picture_filename);
|
2018-05-27 12:03:29 +00:00
|
|
|
void recalculate(QString filename);
|
2018-05-15 22:17:04 +00:00
|
|
|
void processItem(QString filename, bool tryDownload);
|
2018-05-15 18:47:35 +00:00
|
|
|
Thumbnail getThumbnailFromCache(const QString &picture_filename);
|
2018-07-13 20:55:35 +00:00
|
|
|
Thumbnail getPictureThumbnailFromStream(QDataStream &stream);
|
2018-07-10 13:04:35 +00:00
|
|
|
Thumbnail getVideoThumbnailFromStream(QDataStream &stream, const QString &filename);
|
2018-05-15 18:47:35 +00:00
|
|
|
Thumbnail fetchImage(const QString &filename, const QString &originalFilename, bool tryDownload);
|
|
|
|
Thumbnail getHashedImage(const QString &filename, bool tryDownload);
|
2018-07-10 13:04:35 +00:00
|
|
|
void markVideoThumbnail(QImage &img);
|
2018-03-10 13:15:50 +00:00
|
|
|
|
|
|
|
mutable QMutex lock;
|
|
|
|
QThreadPool pool;
|
2018-03-11 09:19:08 +00:00
|
|
|
QImage failImage; // Shown when image-fetching fails
|
|
|
|
QImage dummyImage; // Shown before thumbnail is fetched
|
2018-05-15 18:47:35 +00:00
|
|
|
QImage videoImage; // Place holder for videos
|
2018-07-10 13:04:35 +00:00
|
|
|
QImage videoOverlayImage; // Overlay for video thumbnails
|
2018-07-08 19:24:44 +00:00
|
|
|
QImage unknownImage; // Place holder for files where we couldn't determine the type
|
2018-03-10 13:15:50 +00:00
|
|
|
|
|
|
|
QMap<QString,QFuture<void>> workingOn;
|
|
|
|
};
|
|
|
|
|
2015-11-06 18:39:59 +00:00
|
|
|
#endif // IMAGEDOWNLOADER_H
|