aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2014-01-27 14:44:26 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-02-06 11:29:23 -0800
commit5c1abde2a5217cc8217cb25c4a81515d0fda0253 (patch)
tree429bb0cb972b49b77bef11aa9e786b554de2bd46 /qt-ui/divelistview.cpp
parentc84ef319a2d83affbd4a0f2f7c391cdfb25d09ee (diff)
downloadsubsurface-5c1abde2a5217cc8217cb25c4a81515d0fda0253.tar.gz
Include images in profile
This adds an entry to the dive list context menu to load images. The user can select image files and set a time offset to align camera and dive computer clocks. Using the exif time stamp the images are tried to match to the times of the selected dives (with a grace period of an hour before and after the dive). Upon success an event of type 123 is created per image with the string value being the path to the image. Those images are displayed as thumbnails in the profile. If the matching dive does not yet have a geo location specified but the image provides one it is copied to the dive (making the camera a poor man's companion app). This patch includes easyexif https://code.google.com/p/easyexif/ which is originally under a New BSD License to parse the image meta data. This commit includes a new test dive dives/test31.xml with a matching image wreck.jpg to try out the functionallity. Obvious to do's: Have images on the map Have the images clickable Have a proper picture viewer Give visual reference for image time shifting. Use the new profile Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r--qt-ui/divelistview.cpp89
1 files changed, 89 insertions, 0 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 86a3b95fd..1b19d06fd 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -10,6 +10,8 @@
#include "mainwindow.h"
#include "subsurfacewebservices.h"
#include "../display.h"
+#include "exif.h"
+#include "../file.h"
#include <QApplication>
#include <QHeaderView>
#include <QDebug>
@@ -21,6 +23,9 @@
#include <QKeyEvent>
#include <QMenu>
#include <QFileDialog>
+#include <string>
+#include <iostream>
+
DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), mouseClickSelection(false),
sortColumn(0), currentOrder(Qt::DescendingOrder), searchBox(new QLineEdit(this))
@@ -735,6 +740,7 @@ void DiveListView::contextMenuEvent(QContextMenuEvent *event)
popup.addAction(tr("save As"), this, SLOT(saveSelectedDivesAs()));
popup.addAction(tr("export As UDDF"), this, SLOT(exportSelectedDivesAsUDDF()));
popup.addAction(tr("shift times"), this, SLOT(shiftTimes()));
+ popup.addAction(tr("load images"), this, SLOT(loadImages()));
}
if (d)
popup.addAction(tr("upload dive(s) to divelogs.de"), this, SLOT(uploadToDivelogsDE()));
@@ -794,7 +800,90 @@ void DiveListView::shiftTimes()
ShiftTimesDialog::instance()->show();
}
+void DiveListView::loadImages()
+{
+ struct memblock mem;
+ EXIFInfo exif;
+ int code;
+ time_t imagetime;
+ QStringList fileNames = QFileDialog::getOpenFileNames(this, tr("Open Image Files"), lastUsedImageDir(), tr("Image Files (*.jpg *.jpeg *.pnm *.tif *.tiff)"));
+
+ if (fileNames.isEmpty())
+ return;
+
+ updateLastUsedImageDir(QFileInfo(fileNames[0]).dir().path());
+
+ ShiftImageTimesDialog* shiftDialog = ShiftImageTimesDialog::instance();
+ shiftDialog->exec();
+
+ for (int i = 0; i < fileNames.size(); ++i) {
+ struct tm tm;
+ int year, month, day, hour, min, sec;
+ readfile(fileNames.at(i).toUtf8().data(), &mem);
+ code = exif.parseFrom((const unsigned char *) mem.buffer, (unsigned) mem.size);
+ free(mem.buffer);
+ sscanf(exif.DateTime.c_str(), "%d:%d:%d %d:%d:%d", &year, &month, &day, &hour, &min, &sec);
+ tm.tm_year = year;
+ tm.tm_mon = month - 1;
+ tm.tm_mday = day;
+ tm.tm_hour = hour;
+ tm.tm_min = min;
+ tm.tm_sec = sec;
+ imagetime = utc_mktime(&tm) + shiftDialog->amount;
+ int j = 0;
+ struct dive *dive;
+ for_each_dive(j, dive){
+ if (!dive->selected)
+ continue;
+ if (dive->when - 3600 < imagetime && dive->when + dive->duration.seconds + 3600 > imagetime){
+ if (dive->when > imagetime) {
+ ; // Before dive
+ add_event(&(dive->dc), 0, 123, 0, 0, fileNames.at(i).toUtf8().data());
+ mainWindow()->refreshDisplay();
+ mark_divelist_changed(true);
+ }
+ else if (dive->when + dive->duration.seconds < imagetime){
+ ; // After dive
+ add_event(&(dive->dc), dive->duration.seconds, 123, 0, 0, fileNames.at(i).toUtf8().data());
+ mainWindow()->refreshDisplay();
+ mark_divelist_changed(true);
+ }
+ else {
+ add_event(&(dive->dc), imagetime - dive->when, 123, 0, 0, fileNames.at(i).toUtf8().data());
+ mainWindow()->refreshDisplay();
+ mark_divelist_changed(true);
+ }
+ if (!dive->latitude.udeg && !IS_FP_SAME(exif.GeoLocation.Latitude, 0.0)){
+ dive->latitude.udeg = lrint(1000000.0 * exif.GeoLocation.Latitude);
+ dive->longitude.udeg = lrint(1000000.0 * exif.GeoLocation.Longitude);
+ mark_divelist_changed(true);
+ mainWindow()->refreshDisplay();
+ }
+ }
+ }
+ }
+}
+
void DiveListView::uploadToDivelogsDE()
{
DivelogsDeWebServices::instance()->prepareDivesForUpload();
}
+
+QString DiveListView::lastUsedImageDir()
+{
+ QSettings settings;
+ QString lastImageDir = QDir::homePath();
+
+ settings.beginGroup("FileDialog");
+ if (settings.contains("LastImageDir"))
+ if (QDir::setCurrent(settings.value("LastImageDir").toString()))
+ lastImageDir = settings.value("LastIamgeDir").toString();
+ return lastImageDir;
+}
+
+void DiveListView::updateLastUsedImageDir(const QString& dir)
+{
+ QSettings s;
+ s.beginGroup("FileDialog");
+ s.setValue("LastImageDir", dir);
+}