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
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-15 20:47:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								#include "metadata.h"
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-06 10:39:59 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#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-11 12:58:55 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									static ImageDownloader *instance();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									ImageDownloader();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public slots:
							 | 
						
					
						
							
								
									
										
										
										
											2018-06-12 12:50:34 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void load(QUrl url, QString filename);
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-11 12:58:55 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								signals:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void loaded(QString filename);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void failed(QString filename);
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-06 10:39:59 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								private:
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-11 12:58:55 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QNetworkAccessManager manager;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void loadFromUrl(const QString &filename, const QUrl &);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void saveImage(QNetworkReply *reply);
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-06 10:39:59 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-18 21:11:15 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								struct PictureEntry;
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 14:15:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								class Thumbnailer : public QObject {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									Q_OBJECT
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								public:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									static Thumbnailer *instance();
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// Schedule a thumbnail for fetching or calculation.
							 | 
						
					
						
							
								
									
										
										
										
											2019-02-02 21:23:52 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// If synchronous is false, returns a placeholder thumbnail.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// The actual thumbnail will be sent via a signal later.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// If synchronous is true, try to fetch the actual thumbnail.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// In this mode only precalculated thumbnails or thumbnails
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// from pictures are returned. Video extraction and remote
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// images are not supported.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QImage fetchThumbnail(const QString &filename, bool synchronous);
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 14:15:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-27 14:03:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									// Schedule multiple thumbnails for forced recalculation
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void calculateThumbnails(const QVector<QString> &filenames);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											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-11 12:58:55 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								public slots:
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void imageDownloaded(QString filename);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									void imageDownloadFailed(QString filename);
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 15:04:35 +02: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 14:15:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								signals:
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-15 17:56:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void thumbnailChanged(QString filename, QImage thumbnail, duration_t duration);
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 14:15:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								private:
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-15 20:47:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									struct Thumbnail {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										QImage img;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
										mediatype_t type;
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-13 22:55:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
										duration_t duration;
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-15 20:47:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 14:15:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Thumbnailer();
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 15:04:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Thumbnail fetchVideoThumbnail(const QString &filename, const QString &originalFilename, duration_t duration);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									Thumbnail extractVideoThumbnail(const QString &picture_filename, duration_t duration);
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-15 17:56:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Thumbnail addPictureThumbnailToCache(const QString &picture_filename, const QImage &thumbnail);
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 15:04:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Thumbnail addVideoThumbnailToCache(const QString &picture_filename, duration_t duration, const QImage &thumbnail, duration_t position);
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-15 17:56:18 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Thumbnail addUnknownThumbnailToCache(const QString &picture_filename);
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-27 14:03:29 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void recalculate(QString filename);
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-16 00:17:04 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void processItem(QString filename, bool tryDownload);
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-15 20:47:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Thumbnail getThumbnailFromCache(const QString &picture_filename);
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-13 22:55:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Thumbnail getPictureThumbnailFromStream(QDataStream &stream);
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 15:04:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Thumbnail getVideoThumbnailFromStream(QDataStream &stream, const QString &filename);
							 | 
						
					
						
							
								
									
										
										
										
											2018-05-15 20:47:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									Thumbnail fetchImage(const QString &filename, const QString &originalFilename, bool tryDownload);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									Thumbnail getHashedImage(const QString &filename, bool tryDownload);
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 15:04:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									void markVideoThumbnail(QImage &img);
							 | 
						
					
						
							
								
									
										
										
										
											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-05-15 20:47:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QImage videoImage;		// Place holder for videos
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-10 15:04:35 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QImage videoOverlayImage;	// Overlay for video thumbnails
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-08 21:24:44 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									QImage unknownImage;		// Place holder for files where we couldn't determine the type
							 | 
						
					
						
							
								
									
										
										
										
											2018-03-10 14:15:50 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									QMap<QString,QFuture<void>> workingOn;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								};
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2015-11-06 10:39:59 -08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								#endif // IMAGEDOWNLOADER_H
							 |