aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-05-25 22:01:30 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-05-26 09:24:28 -0700
commit80224a98b1263fb1e89c7c46ecc2c51a96d0ffa4 (patch)
treee38e2baded28fd4b823c516f3935c5a4ec400fba
parentb34eeeaba257d14ff7fa2b32eccbceeeb2b4e66a (diff)
downloadsubsurface-80224a98b1263fb1e89c7c46ecc2c51a96d0ffa4.tar.gz
Dive pictures: Derive thumbnail file from picture filename
Since commit 6618c9ebfc6a7cebbef687fcb3aa74c70f504ff2, thumbnails are saved in individual files. The filename was simply the picture-hash. In a mailing-list discussion it turned out that in the future we might not hash images or change the hash. Therefore, derive the thumbnail filename from the image filename, using the SHA1 algorithm. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/imagedownloader.cpp9
-rw-r--r--core/qthelper.cpp10
2 files changed, 6 insertions, 13 deletions
diff --git a/core/imagedownloader.cpp b/core/imagedownloader.cpp
index db2d81b99..1d82c50c5 100644
--- a/core/imagedownloader.cpp
+++ b/core/imagedownloader.cpp
@@ -148,7 +148,6 @@ Thumbnailer *Thumbnailer::instance()
static QImage getThumbnailFromCache(const QString &picture_filename)
{
- // First, check if we know a hash for this filename
QString filename = thumbnailFileName(picture_filename);
if (filename.isEmpty())
return QImage();
@@ -173,14 +172,6 @@ static void addThumbnailToCache(const QImage &thumbnail, const QString &picture_
return;
QString filename = thumbnailFileName(picture_filename);
-
- // If we got a thumbnail, we are guaranteed to have its hash and therefore
- // thumbnailFileName() should return a filename.
- if (filename.isEmpty()) {
- qWarning() << "Internal error: can't get filename of recently created thumbnail";
- return;
- }
-
QSaveFile file(filename);
if (!file.open(QIODevice::WriteOnly))
return;
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index 11d74a14e..638931055 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -1088,12 +1088,14 @@ static QString thumbnailDir()
return QString(system_default_directory()) + "/thumbnails/";
}
-// Return filename of thumbnail if it is known to us.
-// If this is an unknown thumbnail, return an empty string.
+// Calculate thumbnail filename by hashing name of file.
QString thumbnailFileName(const QString &filename)
{
- QString hash = getHash(filename).toHex();
- return hash.isEmpty() ? QString() : thumbnailDir() + hash;
+ if (filename.isEmpty())
+ return QString();
+ QCryptographicHash hash(QCryptographicHash::Sha1);
+ hash.addData(filename.toUtf8());
+ return thumbnailDir() + hash.result().toHex();
}
extern "C" char *hashfile_name_string()