summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robert C. Helling <helling@atdotde.de>2015-02-26 14:44:27 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-02-27 06:30:49 +0100
commite6482bbdc8a1359d51c70aaf847d3aac7895b960 (patch)
treeaab14f7043fd1d19d182578e7549f4d9a8da151f
parentb02bf002a677e45dbaa4d28edadbaafc89a7badc (diff)
downloadsubsurface-e6482bbdc8a1359d51c70aaf847d3aac7895b960.tar.gz
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 <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--qt-ui/mainwindow.cpp18
-rw-r--r--qt-ui/mainwindow.h1
-rw-r--r--qt-ui/mainwindow.ui8
-rw-r--r--qthelper.cpp24
-rw-r--r--qthelper.h1
5 files changed, 51 insertions, 1 deletions
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 8c3b44c48..8dcb59c90 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<ProfileWidget2*>(applicationState["Default"].topRight->layout()->itemAt(1)->widget());
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index 5f4567f76..7514a0938 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -104,6 +104,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 b6cd4a358..41a85bf8a 100644
--- a/qt-ui/mainwindow.ui
+++ b/qt-ui/mainwindow.ui
@@ -50,7 +50,7 @@
<x>0</x>
<y>0</y>
<width>861</width>
- <height>25</height>
+ <height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@@ -67,6 +67,7 @@
<addaction name="actionPrint"/>
<addaction name="actionPreferences"/>
<addaction name="separator"/>
+ <addaction name="actionHash_images"/>
<addaction name="actionConfigure_Dive_Computer"/>
<addaction name="separator"/>
<addaction name="actionRecent1"/>
@@ -690,6 +691,11 @@
<string>Ctrl+Shift+Z</string>
</property>
</action>
+ <action name="actionHash_images">
+ <property name="text">
+ <string>Hash images</string>
+ </property>
+ </action>
</widget>
<customwidgets>
<customwidget>
diff --git a/qthelper.cpp b/qthelper.cpp
index 74c67d769..14e67e089 100644
--- a/qthelper.cpp
+++ b/qthelper.cpp
@@ -849,3 +849,27 @@ void updateHash(struct picture *picture) {
picture->hash = strdup(hash.toHex());
free(old);
}
+
+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 e164a41b6..8b553ba51 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);