summaryrefslogtreecommitdiffstats
path: root/core/imagedownloader.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-03-10 14:15:50 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-05-13 13:52:35 -0700
commit3967b1fd4d6ed2191daf12816d2cee1949c21d0b (patch)
tree5ca6cd3ce7858053c7f4133e6eaa3522f444d332 /core/imagedownloader.h
parentf60343eebbf6a31a4643dde9f4454f6ce84f61d3 (diff)
downloadsubsurface-3967b1fd4d6ed2191daf12816d2cee1949c21d0b.tar.gz
Dive pictures: Introduce thumbnailer class
Create a new class, which performs all thumbnailing code. This is mostly code reshuffling. Thumbnails are extracted either from a cache or thumbnail calculation is started in a worker thread. Since getHashedImage() is called from a worker thread it makes no sense to call subfunctions in yet another worker thread. Remove these calls. In contrast to the previous code, on error the background thread produces a failure image, but it is not yet shown. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/imagedownloader.h')
-rw-r--r--core/imagedownloader.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/core/imagedownloader.h b/core/imagedownloader.h
index 337185869..d8e9d2d7d 100644
--- a/core/imagedownloader.h
+++ b/core/imagedownloader.h
@@ -5,6 +5,7 @@
#include <QImage>
#include <QFuture>
#include <QNetworkReply>
+#include <QThreadPool>
class ImageDownloader : public QObject {
Q_OBJECT
@@ -18,6 +19,31 @@ private:
QString filename;
};
+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, int size);
+
+ // If we change dive, clear all unfinished thumbnail creations
+ void clearWorkQueue();
+signals:
+ void thumbnailChanged(QString filename, QImage thumbnail);
+private:
+ Thumbnailer();
+ void processItem(QString filename, int size);
+
+ mutable QMutex lock;
+ QThreadPool pool;
+
+ QMap<QString,QFuture<void>> workingOn;
+};
+
QImage getHashedImage(const QString &filename);
#endif // IMAGEDOWNLOADER_H