mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 21:20:19 +00:00
d33e3b22fc
Instead of generating one ImageDownloader object per image to be downloaded and running every image download in a separate worker thread, use one global ImageDownloader object owned by the UI thread. The images are downloaded using event based IO (as probably was the intention of the QNetworkManager class). User-visible change: after download from the internet, the thumbnail is shown without having to change dives. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef IMAGEDOWNLOADER_H
|
|
#define IMAGEDOWNLOADER_H
|
|
|
|
#include <QImage>
|
|
#include <QFuture>
|
|
#include <QNetworkReply>
|
|
#include <QThreadPool>
|
|
|
|
class ImageDownloader : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
static ImageDownloader *instance();
|
|
ImageDownloader();
|
|
public slots:
|
|
void load(QString filename, bool fromHash);
|
|
signals:
|
|
void loaded(QString filename);
|
|
void failed(QString filename);
|
|
private:
|
|
QNetworkAccessManager manager;
|
|
void loadFromUrl(const QString &filename, const QUrl &);
|
|
void saveImage(QNetworkReply *reply);
|
|
};
|
|
|
|
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.
|
|
QImage fetchThumbnail(PictureEntry &entry);
|
|
|
|
// 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:
|
|
Thumbnailer();
|
|
void processItem(QString filename);
|
|
|
|
mutable QMutex lock;
|
|
QThreadPool pool;
|
|
QImage failImage; // Shown when image-fetching fails
|
|
QImage dummyImage; // Shown before thumbnail is fetched
|
|
|
|
QMap<QString,QFuture<void>> workingOn;
|
|
};
|
|
|
|
#endif // IMAGEDOWNLOADER_H
|