diff options
author | Robert C. Helling <helling@atdotde.de> | 2016-12-15 14:31:20 +0100 |
---|---|---|
committer | Robert C. Helling <helling@atdotde.de> | 2016-12-30 19:43:00 +0100 |
commit | 10b8bda6626fe1de602e38da34de419972031755 (patch) | |
tree | 670b0e832156eea8ffe70ecef4a1ea5121c56f9d /core | |
parent | ca1349241b9f21c07f4a56399f68073cb764518f (diff) | |
download | subsurface-10b8bda6626fe1de602e38da34de419972031755.tar.gz |
Fix picture hashing logic for pictures on the web.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'core')
-rw-r--r-- | core/imagedownloader.cpp | 2 | ||||
-rw-r--r-- | core/qthelper.cpp | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/core/imagedownloader.cpp b/core/imagedownloader.cpp index d4dd85922..16c48a00e 100644 --- a/core/imagedownloader.cpp +++ b/core/imagedownloader.cpp @@ -100,6 +100,8 @@ SHashedImage::SHashedImage(struct picture *picture) : QImage() // This did not load anything. Let's try to get the image from other sources // Let's try to load it locally via its hash QString filename = fileFromHash(picture->hash); + if (filename.isNull()) + filename = QString(picture->filename); if (filename.isNull()) { // That didn't produce a local filename. // Try the cloud server diff --git a/core/qthelper.cpp b/core/qthelper.cpp index 885e89d98..088067f26 100644 --- a/core/qthelper.cpp +++ b/core/qthelper.cpp @@ -1075,6 +1075,8 @@ QByteArray hashFile(const QString filename) void learnHash(struct picture *picture, QByteArray hash) { + if (hash.isNull()) + return; if (picture->hash) free(picture->hash); QMutexLocker locker(&hashOfMutex); @@ -1100,6 +1102,8 @@ QString localFilePath(const QString originalFilename) QString fileFromHash(char *hash) { + if (!hash || !*hash) + return ""; QMutexLocker locker(&hashOfMutex); return localFilenameOf[QByteArray::fromHex(hash)]; @@ -1120,7 +1124,7 @@ void hashPicture(struct picture *picture) if (!picture) return; char *oldHash = copy_string(picture->hash); - learnHash(picture, hashFile(QString(picture->filename))); + learnHash(picture, hashFile(localFilePath(picture->filename))); if (!same_string(picture->hash, "") && !same_string(picture->hash, oldHash)) mark_divelist_changed((true)); free(oldHash); |