From aa50f0049e6f81470fcda0935ca3da661bc7e37e Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Fri, 23 Sep 2022 12:58:55 -0400 Subject: Load database into in-memory database. Show the progress dialog while loading. --- qdeduper/mingui.cpp | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'qdeduper/mingui.cpp') diff --git a/qdeduper/mingui.cpp b/qdeduper/mingui.cpp index 4f5b854..c9447c5 100644 --- a/qdeduper/mingui.cpp +++ b/qdeduper/mingui.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -201,15 +202,31 @@ void DeduperMainWindow::setup_menu() QString dbpath = QFileDialog::getOpenFileName(this, "Load Database", QString(), "Signature database (*.sigdb)"); if (!dbpath.isNull()) { - this->sdb = new SignatureDB(qstring_to_path(dbpath)); - if (!this->sdb->valid()) { - delete this->sdb; - this->sdb = nullptr; - QMessageBox::critical(this, "Error", "Error loading database."); - return; - } - curgroup = 0; - show_group(0); + if (this->sdb) delete this->sdb; + this->sdb = new SignatureDB(); + pd->setMaximum(0); + pd->setMinimum(0); + pd->setLabelText("Loading database..."); + pd->open(); + pd->setCancelButton(nullptr); + auto f = QtConcurrent::run([this, dbpath]() -> bool { + return this->sdb->load(qstring_to_path(dbpath)); + }); + QFutureWatcher *fw = new QFutureWatcher(this); + fw->setFuture(f); + QObject::connect(fw, &QFutureWatcher::finished, this, [this, fw] { + pd->close(); + if (!fw->result()) { + delete this->sdb; + this->sdb = nullptr; + QMessageBox::critical(this, "Error", "Error loading database."); + fw->deleteLater(); + return; + } + curgroup = 0; + show_group(0); + fw->deleteLater(); + }, Qt::ConnectionType::QueuedConnection); } }); menuact["load_db"] = load_db; @@ -474,6 +491,7 @@ void DeduperMainWindow::scan_dirs(std::vector> paths) this->pd->setLabelText("Preparing for database creation..."); this->pd->setMinimum(0); this->pd->setMaximum(0); + this->pd->setCancelButton(new QPushButton("Cancel")); auto f = QtConcurrent::run([this, paths] { FileScanner *fs = new FileScanner(); this->fsc = fs; @@ -528,12 +546,13 @@ void DeduperMainWindow::scan_dirs(std::vector> paths) }); QFutureWatcher *fw = new QFutureWatcher(this); fw->setFuture(f); - QObject::connect(fw, &QFutureWatcher::finished, this, [this] { + QObject::connect(fw, &QFutureWatcher::finished, this, [this, fw] { this->pd->reset(); this->pd->close(); this->curgroup = 0; this->vm = ViewMode::view_normal; this->show_group(this->curgroup); + fw->deleteLater(); }, Qt::ConnectionType::QueuedConnection); QObject::connect(pd, &QProgressDialog::canceled, [this] { if (this->fsc) this->fsc->interrupt(); -- cgit v1.2.3