mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
19fa2966ef
commit
d33e3b22fc
2 changed files with 98 additions and 78 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue