summaryrefslogtreecommitdiffstats
path: root/subsurface-core
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2016-03-15 22:45:17 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-03-16 07:46:28 -0700
commite32ae20ca3e5dea67613b330a822cd18556d076a (patch)
tree7c53e086afe9357cefc6ab04128cc7bb0bd61c88 /subsurface-core
parent8a59d78faa4792934a11a774c9dffcd85f0c3340 (diff)
downloadsubsurface-e32ae20ca3e5dea67613b330a822cd18556d076a.tar.gz
Fix loading images from URLs
This was broken when introducing loading images from the server. Now it first tries the server and if that fails tries the actual URL. Still, the image does not show up immediately, since the DivePictureModel is unavailable to the image downloader to be told to update the images. This needs to be fixed but in the mean time, the image is shown when the dive is reselected (possibly on the next run) since it is then loaded from the cache. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'subsurface-core')
-rw-r--r--subsurface-core/imagedownloader.cpp13
-rw-r--r--subsurface-core/imagedownloader.h1
2 files changed, 12 insertions, 2 deletions
diff --git a/subsurface-core/imagedownloader.cpp b/subsurface-core/imagedownloader.cpp
index d28ec9503..daa49eadf 100644
--- a/subsurface-core/imagedownloader.cpp
+++ b/subsurface-core/imagedownloader.cpp
@@ -24,6 +24,7 @@ ImageDownloader::~ImageDownloader()
void ImageDownloader::load(bool fromHash){
QUrl url;
+ loadFromHash = fromHash;
if(fromHash)
url = cloudImageURL(picture->hash);
else
@@ -45,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();
@@ -64,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)
@@ -74,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()) {
diff --git a/subsurface-core/imagedownloader.h b/subsurface-core/imagedownloader.h
index 2ff68342c..f4e3df875 100644
--- a/subsurface-core/imagedownloader.h
+++ b/subsurface-core/imagedownloader.h
@@ -20,6 +20,7 @@ public:
private:
struct picture *picture;
QNetworkAccessManager manager;
+ bool loadFromHash;
private slots:
void saveImage(QNetworkReply *reply);