aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui/divelistview.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2014-06-02 18:28:02 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-06-02 23:59:29 -0700
commitd95d1735b5f0fec2941696a4bb1720eb00a6f59c (patch)
treeeae15bb2c25d051150292de7b17429d074c65d36 /qt-ui/divelistview.cpp
parent13e8aba7daee2104c859e17de3363a24c5a885c0 (diff)
downloadsubsurface-d95d1735b5f0fec2941696a4bb1720eb00a6f59c.tar.gz
Break picture handling code from C++ to C.
This commit breaks the loading of images that were done in the divelist into smaller bits. A bit of code refactor was done in order to correct the placement of a few methods. ShiftTimesDialog::EpochFromExiv got moved to Exif::epoch dive_add_picture is now used instead of add_event picture_load_exif_data got implemented using the old listview code. dive_set_geodata_from_picture got implemented using the old listview code. Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelistview.cpp')
-rw-r--r--qt-ui/divelistview.cpp50
1 files changed, 10 insertions, 40 deletions
diff --git a/qt-ui/divelistview.cpp b/qt-ui/divelistview.cpp
index 837886187..57ad3f21f 100644
--- a/qt-ui/divelistview.cpp
+++ b/qt-ui/divelistview.cpp
@@ -764,63 +764,33 @@ void DiveListView::shiftTimes()
void DiveListView::loadImages()
{
- struct memblock mem;
- EXIFInfo exif;
- int retval;
- time_t imagetime;
- struct divecomputer *dc;
- time_t when;
- int duration_s;
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(this);
shiftDialog.setOffset(lastImageTimeOffset());
shiftDialog.exec();
updateLastImageTimeOffset(shiftDialog.amount());
- for (int i = 0; i < fileNames.size(); ++i) {
- if (readfile(fileNames.at(i).toUtf8().data(), &mem) <= 0)
- continue;
- //TODO: This inner code should be ported to C-Code.
- retval = exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
- free(mem.buffer);
- if (retval != PARSE_EXIF_SUCCESS)
- continue;
- imagetime = shiftDialog.epochFromExiv(&exif);
- if (!imagetime)
- continue;
- imagetime += shiftDialog.amount(); // TODO: this should be cached and passed to the C-function
+ Q_FOREACH(const QString& fileName, fileNames) {
+ picture *p = alloc_picture();
+ p->filename = qstrdup(fileName.toUtf8().data());
+ picture_load_exif_data(p);
+
+ if (p->timestamp)
+ p->timestamp += shiftDialog.amount(); // TODO: this should be cached and passed to the C-function
int j = 0;
struct dive *dive;
for_each_dive (j, dive) {
if (!dive->selected)
continue;
- for_each_dc (dive, dc) {
- when = dc->when ? dc->when : dive->when;
- duration_s = dc->duration.seconds ? dc->duration.seconds : dive->duration.seconds;
- if (when - 3600 < imagetime && when + duration_s + 3600 > imagetime) {
- if (when > imagetime) {
- // Before dive
- add_event(dc, 0, 123, 0, 0, fileNames.at(i).toUtf8().data());
- } else if (when + duration_s < imagetime) {
- // After dive
- add_event(dc, duration_s, 123, 0, 0, fileNames.at(i).toUtf8().data());
- } else {
- add_event(dc, imagetime - when, 123, 0, 0, fileNames.at(i).toUtf8().data());
- }
- 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);
- }
- }
- }
+ dive_add_picture(dive, p);
+ dive_set_geodata_from_picture(dive, p);
}
}
+
mark_divelist_changed(true);
MainWindow::instance()->refreshDisplay();
MainWindow::instance()->graphics()->replot();