aboutsummaryrefslogtreecommitdiff
path: root/qdeduper/mingui.cpp
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2022-09-19 18:26:36 -0400
committerGravatar Chris Xiong <chirs241097@gmail.com> 2022-09-19 18:27:15 -0400
commit683c66d81898e1d7d4cb814a5740169529c3313e (patch)
tree2bd09916fce34141b3ce00822f816485fe1cc8dd /qdeduper/mingui.cpp
parent817075ec9bd6bd656a4a6dc23363e950474b21d5 (diff)
downloaddeduper-683c66d81898e1d7d4cb814a5740169529c3313e.tar.xz
Scanning can now be cancelled.
Fix terminate() of thread pool blocking if wait() is already called.
Diffstat (limited to 'qdeduper/mingui.cpp')
-rw-r--r--qdeduper/mingui.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/qdeduper/mingui.cpp b/qdeduper/mingui.cpp
index 845bc70..4e4cc87 100644
--- a/qdeduper/mingui.cpp
+++ b/qdeduper/mingui.cpp
@@ -6,6 +6,7 @@
#include <cstdio>
#include <chrono>
+#include <thread>
#include <cwchar>
#include <QDebug>
@@ -175,10 +176,10 @@ DeduperMainWindow::DeduperMainWindow()
void DeduperMainWindow::setup_menu()
{
- QMenu *file = this->menuBar()->addMenu("File");
- QMenu *view = this->menuBar()->addMenu("View");
- QMenu *mark = this->menuBar()->addMenu("Marks");
- QMenu *help = this->menuBar()->addMenu("Help");
+ QMenu *file = this->menuBar()->addMenu("&File");
+ QMenu *view = this->menuBar()->addMenu("&View");
+ QMenu *mark = this->menuBar()->addMenu("&Marks");
+ QMenu *help = this->menuBar()->addMenu("&Help");
QAction *create_db = file->addAction("Create Database...");
QObject::connect(create_db, &QAction::triggered, this, &DeduperMainWindow::create_new);
@@ -396,6 +397,7 @@ void DeduperMainWindow::scan_dirs(std::vector<std::pair<fs::path, bool>> paths)
this->pd->setMaximum(0);
auto f = QtConcurrent::run([this, paths] {
FileScanner *fs = new FileScanner();
+ this->fsc = fs;
std::for_each(paths.begin(), paths.end(), [fs](auto p){fs->add_path(p.first, p.second);});
fs->add_magic_number("\x89PNG\r\n");
fs->add_magic_number("\xff\xd8\xff");
@@ -413,6 +415,12 @@ void DeduperMainWindow::scan_dirs(std::vector<std::pair<fs::path, bool>> paths)
}
}, Qt::ConnectionType::QueuedConnection);
fs->scan();
+ if (fs->interrupted())
+ {
+ delete fs;
+ this->fsc = nullptr;
+ return;
+ }
this->pd->setMaximum(fs->file_list().size() - 1);
this->pd->setLabelText("Scanning...");
this->sdb = new SignatureDB();
@@ -431,8 +439,9 @@ void DeduperMainWindow::scan_dirs(std::vector<std::pair<fs::path, bool>> paths)
this->pd->setLabelText("Finalizing...");
}
}, Qt::ConnectionType::QueuedConnection);
- this->sdb->scan_files(fs->file_list(), 8);
+ this->sdb->scan_files(fs->file_list(), std::thread::hardware_concurrency());
delete fs;
+ this->fsc = nullptr;
});
QFutureWatcher<void> *fw = new QFutureWatcher<void>(this);
fw->setFuture(f);
@@ -442,6 +451,10 @@ void DeduperMainWindow::scan_dirs(std::vector<std::pair<fs::path, bool>> paths)
this->curgroup = 0;
this->show_group(this->curgroup);
}, Qt::ConnectionType::QueuedConnection);
+ QObject::connect(pd, &QProgressDialog::canceled, [this] {
+ if (this->fsc) this->fsc->interrupt();
+ if (this->sdb) this->sdb->interrupt_scan();
+ });
}
void DeduperMainWindow::show_group(size_t gid)