summaryrefslogtreecommitdiffstats
path: root/qthelper.cpp
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2015-04-24 17:10:55 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-04-24 09:36:21 -0700
commit757c4aab20cee9cd3699276a9b4f7a7aee4719c2 (patch)
treecc4e06502e06183a8267e6708dbb9870ad183816 /qthelper.cpp
parent98ae7b1f8657d153dd3b431638ff0110429b9d5f (diff)
downloadsubsurface-757c4aab20cee9cd3699276a9b4f7a7aee4719c2.tar.gz
Allow images to be added via the web
This adds a new divelist context menu entry which asks for a URL. The file is retrieved and if it is an image it is added to the cache and the url is associated to dives as with local files. NB this currently only works with URLs pointing directly to images. But it should not be too hard to add the possibility to add a direction via an html file and its image tags. To test: open dives/test43.xml and delete the image and then add the URL http://euve10195.vserver.de/~robert/wreck.jpg Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qthelper.cpp')
-rw-r--r--qthelper.cpp44
1 files changed, 25 insertions, 19 deletions
diff --git a/qthelper.cpp b/qthelper.cpp
index a5597e3fb..030ed94c9 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -337,22 +337,6 @@ extern "C" xsltStylesheetPtr get_stylesheet(const char *name)
return xslt;
}
-extern "C" void picture_load_exif_data(struct picture *p)
-{
- EXIFInfo exif;
- memblock mem;
-
- if (readfile(p->filename, &mem) <= 0)
- goto picture_load_exit;
- if (exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size) != PARSE_EXIF_SUCCESS)
- goto picture_load_exit;
- p->longitude.udeg= lrint(1000000.0 * exif.GeoLocation.Longitude);
- p->latitude.udeg = lrint(1000000.0 * exif.GeoLocation.Latitude);
-
-picture_load_exit:
- free(mem.buffer);
- return;
-}
extern "C" timestamp_t picture_get_timestamp(char *filename)
{
@@ -360,7 +344,8 @@ extern "C" timestamp_t picture_get_timestamp(char *filename)
memblock mem;
int retval;
- if (readfile(filename, &mem) <= 0)
+ // filename might not be the actual filename, so let's go via the hash.
+ if (readfile(localFilePath(QString(filename)).toUtf8().data(), &mem) <= 0)
return 0;
retval = exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
free(mem.buffer);
@@ -853,7 +838,8 @@ QByteArray hashFile(const QString filename)
void learnHash(struct picture *picture, QByteArray hash)
{
- free(picture->hash);
+ if (picture->hash)
+ free(picture->hash);
QMutexLocker locker(&hashOfMutex);
hashOf[QString(picture->filename)] = hash;
picture->hash = strdup(hash.toHex());
@@ -861,7 +847,10 @@ void learnHash(struct picture *picture, QByteArray hash)
QString localFilePath(const QString originalFilename)
{
- return localFilenameOf[hashOf[originalFilename]];
+ if (hashOf.contains(originalFilename) && localFilenameOf.contains(hashOf[originalFilename]))
+ return localFilenameOf[hashOf[originalFilename]];
+ else
+ return originalFilename;
}
QString fileFromHash(char *hash)
@@ -899,3 +888,20 @@ void learnImages(const QDir dir, int max_recursions, bool recursed)
QtConcurrent::blockingMap(files, hashFile);
}
+
+extern "C" void picture_load_exif_data(struct picture *p)
+{
+ EXIFInfo exif;
+ memblock mem;
+
+ if (readfile(localFilePath(QString(p->filename)).toUtf8().data(), &mem) <= 0)
+ goto picture_load_exit;
+ if (exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size) != PARSE_EXIF_SUCCESS)
+ goto picture_load_exit;
+ p->longitude.udeg= lrint(1000000.0 * exif.GeoLocation.Longitude);
+ p->latitude.udeg = lrint(1000000.0 * exif.GeoLocation.Latitude);
+
+picture_load_exit:
+ free(mem.buffer);
+ return;
+}