summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);