mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
As long as ProfileWidget2 and DivePictureModel showed the same set of pictures and any change would lead to a full recalculation of the set, it made sense to let ProfileWidget2 use DivePictureModel's data. Recently, keeping the two lists in sync become more and more of a burden. Therefore, disconnect ProfileWidget2 and DivePictureModel. This will lead to some code-duplication and perhaps a temporary drop in UI-performance, but in the end the code is distinctly simpler and also more flexible. Thus, for example the DivePhotoTab could be changed to support headings without having to touch ProfileWidget2 at all. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
74 lines
2.1 KiB
C++
74 lines
2.1 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef IMAGEDOWNLOADER_H
|
|
#define IMAGEDOWNLOADER_H
|
|
|
|
#include "metadata.h"
|
|
#include <QImage>
|
|
#include <QFuture>
|
|
#include <QNetworkReply>
|
|
#include <QThreadPool>
|
|
|
|
class ImageDownloader : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
static ImageDownloader *instance();
|
|
ImageDownloader();
|
|
public slots:
|
|
void load(QUrl url, QString filename);
|
|
signals:
|
|
void loaded(QString filename);
|
|
void failed(QString filename);
|
|
private:
|
|
QNetworkAccessManager manager;
|
|
void loadFromUrl(const QString &filename, const QUrl &);
|
|
void saveImage(QNetworkReply *reply);
|
|
};
|
|
|
|
struct PictureEntry;
|
|
class Thumbnailer : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
static Thumbnailer *instance();
|
|
|
|
// Schedule a thumbnail for fetching or calculation.
|
|
// Returns a placeholder thumbnail. The actual thumbnail will be sent
|
|
// via a signal later.
|
|
QImage fetchThumbnail(const QString &filename);
|
|
|
|
// Schedule multiple thumbnails for forced recalculation
|
|
void calculateThumbnails(const QVector<QString> &filenames);
|
|
|
|
// If we change dive, clear all unfinished thumbnail creations
|
|
void clearWorkQueue();
|
|
static int maxThumbnailSize();
|
|
static int defaultThumbnailSize();
|
|
static int thumbnailSize(double zoomLevel);
|
|
public slots:
|
|
void imageDownloaded(QString filename);
|
|
void imageDownloadFailed(QString filename);
|
|
signals:
|
|
void thumbnailChanged(QString filename, QImage thumbnail);
|
|
private:
|
|
struct Thumbnail {
|
|
QImage img;
|
|
mediatype_t type;
|
|
};
|
|
|
|
Thumbnailer();
|
|
static void addThumbnailToCache(const Thumbnail &thumbnail, const QString &picture_filename);
|
|
void recalculate(QString filename);
|
|
void processItem(QString filename, bool tryDownload);
|
|
Thumbnail getThumbnailFromCache(const QString &picture_filename);
|
|
Thumbnail fetchImage(const QString &filename, const QString &originalFilename, bool tryDownload);
|
|
Thumbnail getHashedImage(const QString &filename, bool tryDownload);
|
|
|
|
mutable QMutex lock;
|
|
QThreadPool pool;
|
|
QImage failImage; // Shown when image-fetching fails
|
|
QImage dummyImage; // Shown before thumbnail is fetched
|
|
QImage videoImage; // Place holder for videos
|
|
|
|
QMap<QString,QFuture<void>> workingOn;
|
|
};
|
|
|
|
#endif // IMAGEDOWNLOADER_H
|