summaryrefslogtreecommitdiffstats
path: root/subsurface-core/imagedownloader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'subsurface-core/imagedownloader.cpp')
-rw-r--r--subsurface-core/imagedownloader.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/subsurface-core/imagedownloader.cpp b/subsurface-core/imagedownloader.cpp
index 9451f8a1b..daa49eadf 100644
--- a/subsurface-core/imagedownloader.cpp
+++ b/subsurface-core/imagedownloader.cpp
@@ -17,8 +17,14 @@ ImageDownloader::ImageDownloader(struct picture *pic)
picture = pic;
}
+ImageDownloader::~ImageDownloader()
+{
+ picture_free(picture);
+}
+
void ImageDownloader::load(bool fromHash){
QUrl url;
+ loadFromHash = fromHash;
if(fromHash)
url = cloudImageURL(picture->hash);
else
@@ -40,8 +46,11 @@ void ImageDownloader::saveImage(QNetworkReply *reply)
QByteArray imageData = reply->readAll();
QImage image = QImage();
image.loadFromData(imageData);
- if (image.isNull())
+ if (image.isNull()) {
+ if (loadFromHash)
+ load(false);
return;
+ }
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(imageData);
QString path = QStandardPaths::standardLocations(QStandardPaths::CacheLocation).first();
@@ -59,6 +68,11 @@ void ImageDownloader::saveImage(QNetworkReply *reply)
}
reply->manager()->deleteLater();
reply->deleteLater();
+ // This should be called to make the picture actually show.
+ // Problem is DivePictureModel is not in subsurface-core.
+ // Nevertheless, the image shows when the dive is selected the next time.
+ // DivePictureModel::instance()->updateDivePictures();
+
}
void loadPicture(struct picture *picture, bool fromHash)
@@ -69,7 +83,7 @@ void loadPicture(struct picture *picture, bool fromHash)
SHashedImage::SHashedImage(struct picture *picture) : QImage()
{
- QUrl url = QUrl::fromUserInput(QString(picture->filename));
+ QUrl url = QUrl::fromUserInput(localFilePath(QString(picture->filename)));
if(url.isLocalFile())
load(url.toLocalFile());
if (isNull()) {
@@ -79,21 +93,21 @@ SHashedImage::SHashedImage(struct picture *picture) : QImage()
if (filename.isNull()) {
// That didn't produce a local filename.
// Try the cloud server
- QtConcurrent::run(loadPicture, picture, true);
+ QtConcurrent::run(loadPicture, clone_picture(picture), true);
} else {
// Load locally from translated file name
load(filename);
if (!isNull()) {
// Make sure the hash still matches the image file
- QtConcurrent::run(updateHash, picture);
+ QtConcurrent::run(updateHash, clone_picture(picture));
} else {
// Interpret filename as URL
- QtConcurrent::run(loadPicture, picture, false);
+ QtConcurrent::run(loadPicture, clone_picture(picture), false);
}
}
} else {
// We loaded successfully. Now, make sure hash is up to date.
- QtConcurrent::run(hashPicture, picture);
+ QtConcurrent::run(hashPicture, clone_picture(picture));
}
}