From ed6bc97fd0e12a2e9c4bd0a3d02029c9bb88dbab Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Mon, 23 Feb 2015 12:45:54 +0100 Subject: [PATCH 3/4] Make double click on picture open the correct local file ... and update hash-databases correctly. Signed-off-by: Robert C. Helling --- qt-ui/divepicturewidget.cpp | 2 +- qthelper.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/qt-ui/divepicturewidget.cpp b/qt-ui/divepicturewidget.cpp index d4b29e6..9a4a7e3 100644 --- a/qt-ui/divepicturewidget.cpp +++ b/qt-ui/divepicturewidget.cpp @@ -144,5 +144,5 @@ DivePictureWidget::DivePictureWidget(QWidget *parent) : QListView(parent) void DivePictureWidget::doubleClicked(const QModelIndex &index) { QString filePath = model()->data(index, Qt::DisplayPropertyRole).toString(); - emit photoDoubleClicked(filePath); + emit photoDoubleClicked(MainWindow::instance()->localFilenameOf[MainWindow::instance()->hashOf[filePath]]); } diff --git a/qthelper.cpp b/qthelper.cpp index a58a21d..a784e57 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -441,12 +441,16 @@ QByteArray hashFile(const char *filename) QFile imagefile(filename); imagefile.open(QIODevice::ReadOnly); hash.addData(&imagefile); + MainWindow::instance()->hashOf[QString(filename)] = hash.result(); + MainWindow::instance()->localFilenameOf[hash.result()] = QString(filename); return hash.result(); } void updateHash(struct picture *picture) { + QByteArray hash = hashFile(MainWindow::instance()->localFilenameOf[QByteArray::fromHex(picture->hash)].toUtf8().data()); + MainWindow::instance()->hashOf[QString(picture->filename)] = hash; char *old = picture->hash; - picture->hash = strdup(hashFile(MainWindow::instance()->localFilenameOf[QByteArray::fromHex(picture->hash)].toUtf8().data()).toHex()); + picture->hash = strdup(hash.toHex()); free(old); } -- 1.9.3 (Apple Git-50)