summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2015-09-17 16:56:58 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-09-17 08:56:25 -0700
commitd0145621a1d6a76922cc271208e07ed5827a6590 (patch)
tree1cafd5ac0cfc8ea124d78872cebd67ca964bfbae
parent2d376de68ddde1bfc159f0e182120c1e8bc62610 (diff)
downloadsubsurface-d0145621a1d6a76922cc271208e07ed5827a6590.tar.gz
Hash images upon loading divelog file rather than when loading image
Up to now, we only computed hashes of images upon actually displaying the images. With this patch we start to compute hashes once we load the xml or from git. This happens in the background, so the user should note an increased CPU load only once per divelog. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c2
-rw-r--r--qthelper.cpp16
-rw-r--r--qthelper.h1
-rw-r--r--qthelperfromc.h1
4 files changed, 20 insertions, 0 deletions
diff --git a/dive.c b/dive.c
index c81584e65..10ce63859 100644
--- a/dive.c
+++ b/dive.c
@@ -9,6 +9,7 @@
#include "libdivecomputer.h"
#include "device.h"
#include "divelist.h"
+#include "qthelperfromc.h"
/* one could argue about the best place to have this variable -
* it's used in the UI, but it seems to make the most sense to have it
@@ -3014,6 +3015,7 @@ void dive_add_picture(struct dive *dive, struct picture *newpic)
pic_ptr = &(*pic_ptr)->next;
newpic->next = *pic_ptr;
*pic_ptr = newpic;
+ cache_picture(newpic);
return;
}
diff --git a/qthelper.cpp b/qthelper.cpp
index a4dc09057..6e3c957a6 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -1057,6 +1057,7 @@ void read_hashes()
if (hashfile.open(QIODevice::ReadOnly)) {
QDataStream stream(&hashfile);
stream >> localFilenameOf;
+ stream >> hashOf;
hashfile.close();
}
}
@@ -1067,6 +1068,7 @@ void write_hashes()
if (hashfile.open(QIODevice::WriteOnly)) {
QDataStream stream(&hashfile);
stream << localFilenameOf;
+ stream << hashOf;
hashfile.commit();
} else {
qDebug() << "cannot open" << hashfile.fileName();
@@ -1124,6 +1126,20 @@ void updateHash(struct picture *picture) {
free(old);
}
+void hashPicture(struct picture *picture)
+{
+ learnHash(picture, hashFile(QString(picture->filename)));
+ mark_divelist_changed((true));
+
+}
+
+extern "C" void cache_picture(struct picture *picture)
+{
+ QString filename = picture->filename;
+ if (!hashOf.contains(filename))
+ QtConcurrent::run(hashPicture, picture);
+}
+
void learnImages(const QDir dir, int max_recursions, bool recursed)
{
QDir current(dir);
diff --git a/qthelper.h b/qthelper.h
index f6c1cdb2b..f5457b1a9 100644
--- a/qthelper.h
+++ b/qthelper.h
@@ -118,6 +118,7 @@ void add_hash(const QString filename, QByteArray hash);
QString localFilePath(const QString originalFilename);
QString fileFromHash(char *hash);
void learnHash(struct picture *picture, QByteArray hash);
+extern "C" void cache_picture(struct picture *picture);
weight_t string_to_weight(const char *str);
depth_t string_to_depth(const char *str);
pressure_t string_to_pressure(const char *str);
diff --git a/qthelperfromc.h b/qthelperfromc.h
index e48e3b1c4..d64bfc04a 100644
--- a/qthelperfromc.h
+++ b/qthelperfromc.h
@@ -12,5 +12,6 @@ char *hashstring(char *filename);
bool picture_exists(struct picture *picture);
const char *local_file_path(struct picture *picture);
void savePictureLocal(struct picture *picture, const char *data, int len);
+void cache_picture(struct picture *picture);
#endif // QTHELPERFROMC_H