summaryrefslogtreecommitdiffstats
path: root/core/imagedownloader.h
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-03-11 12:58:55 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-05-13 13:52:35 -0700
commitd33e3b22fc5d2e878ee6e03a25e99870484da217 (patch)
treeaf13233a98f4091187c405221b0a5b8216c69589 /core/imagedownloader.h
parent19fa2966efae211f210ef0a761040d8bf2b7edfb (diff)
downloadsubsurface-d33e3b22fc5d2e878ee6e03a25e99870484da217.tar.gz
Dive pictures: refactor image downloader
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>
Diffstat (limited to 'core/imagedownloader.h')
-rw-r--r--core/imagedownloader.h21
1 files changed, 13 insertions, 8 deletions
diff --git a/core/imagedownloader.h b/core/imagedownloader.h
index 92edea0b6..bee262854 100644
--- a/core/imagedownloader.h
+++ b/core/imagedownloader.h
@@ -10,13 +10,17 @@
class ImageDownloader : public QObject {
Q_OBJECT
public:
- ImageDownloader(const QString &filename);
- void load(bool fromHash);
-
+ static ImageDownloader *instance();
+ ImageDownloader();
+public slots:
+ void load(QString filename, bool fromHash);
+signals:
+ void loaded(QString filename);
+ void failed(QString filename);
private:
- bool loadFromUrl(const QUrl &); // return true on success
- void saveImage(QNetworkReply *reply, bool &success);
- QString filename;
+ QNetworkAccessManager manager;
+ void loadFromUrl(const QString &filename, const QUrl &);
+ void saveImage(QNetworkReply *reply);
};
class PictureEntry;
@@ -35,6 +39,9 @@ public:
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:
@@ -49,6 +56,4 @@ private:
QMap<QString,QFuture<void>> workingOn;
};
-QImage getHashedImage(const QString &filename);
-
#endif // IMAGEDOWNLOADER_H