From a7bcdf337270ff5823fbb8cda3c097d61e0d97c4 Mon Sep 17 00:00:00 2001 From: "Robert C. Helling" Date: Thu, 26 Feb 2015 14:44:27 +0100 Subject: [PATCH 2/2] UI to learn hashes of local image files This addes a menu entry for the user to select a directory that is recursively traversed to look for image files and compute the hashes of those images (for those images to be available to be displayed in dives according to their hash values). This traversal and hash computation happens in and independend thread and so far the only feedback to the user is that upon completion the dispayed images are updated. Signed-off-by: Robert C. Helling --- qt-ui/mainwindow.cpp | 18 ++++++++++++++++++ qt-ui/mainwindow.h | 1 + qt-ui/mainwindow.ui | 8 +++++++- qthelper.cpp | 23 +++++++++++++++++++++++ qthelper.h | 1 + 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 2c62106..b19cb8a 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -319,6 +319,24 @@ void MainWindow::on_actionSaveAs_triggered() file_save_as(); } +void MainWindow::on_actionHash_images_triggered() +{ + QFileDialog dialog(this, tr("Traverse image directories"), lastUsedDir(), filter()); + dialog.setFileMode(QFileDialog::Directory); + dialog.setViewMode(QFileDialog::Detail); + dialog.setLabelText(QFileDialog::Accept, tr("Scan")); + dialog.setLabelText(QFileDialog::Reject, tr("Cancel")); + QStringList dirnames; + if (dialog.exec()) + dirnames = dialog.selectedFiles(); + if (dirnames.isEmpty()) + return; + foreach (QString dir, dirnames) { + QtConcurrent::run(learnImages, QDir(dir), 10, false); + } + +} + ProfileWidget2 *MainWindow::graphics() const { return qobject_cast(applicationState["Default"].topRight->layout()->itemAt(1)->widget()); diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 85a6312..b5d1cad 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -103,6 +103,7 @@ slots: void on_actionPrint_triggered(); void on_actionPreferences_triggered(); void on_actionQuit_triggered(); + void on_actionHash_images_triggered(); /* log menu actions */ void on_actionDownloadDC_triggered(); diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index b6cd4a3..41a85bf 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -50,7 +50,7 @@ 0 0 861 - 25 + 22 @@ -67,6 +67,7 @@ + @@ -690,6 +691,11 @@ Ctrl+Shift+Z + + + Hash images + + diff --git a/qthelper.cpp b/qthelper.cpp index 17baa7f..35e45ed 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -474,3 +474,26 @@ void updateHash(struct picture *picture) { +void learnImages(const QDir dir, int max_recursions, bool recursed) +{ + QDir current(dir); + QStringList filters, files; + + if (max_recursions) { + foreach (QString dirname, dir.entryList(QStringList(), QDir::NoDotAndDotDot | QDir::Dirs)) { + learnImages(QDir(dir.filePath(dirname)), max_recursions - 1, true); + } + } + + foreach (QString format, QImageReader::supportedImageFormats()) { + filters.append(QString("*.").append(format)); + } + + foreach (QString file, dir.entryList(filters, QDir::Files)) { + files.append(dir.absoluteFilePath(file)); + } + + QtConcurrent::blockingMap(files, hashFile); + if (!recursed) + DivePictureModel::instance()->updateDivePictures(); +} diff --git a/qthelper.h b/qthelper.h index e164a41..8b553ba 100644 --- a/qthelper.h +++ b/qthelper.h @@ -21,6 +21,7 @@ void read_hashes(); void write_hashes(); void updateHash(struct picture *picture); QByteArray hashFile(const QString filename); +void learnImages(const QDir dir, int max_recursions, bool recursed); void add_hash(const QString filename, QByteArray &hash); QString localFilePath(const QString originalFilename); QString fileFromHash(char *hash); -- 1.9.3 (Apple Git-50)