diff options
author | Chris Xiong <chirs241097@gmail.com> | 2022-09-23 12:58:55 -0400 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2022-09-23 12:58:55 -0400 |
commit | aa50f0049e6f81470fcda0935ca3da661bc7e37e (patch) | |
tree | 0e678011219dd0084c88e0d624931b14ac6f1e16 /qdeduper | |
parent | b41305a7ef92977fe24d365393242e963ceed40f (diff) | |
download | deduper-aa50f0049e6f81470fcda0935ca3da661bc7e37e.tar.xz |
Load database into in-memory database. Show the progress dialog while loading.
Diffstat (limited to 'qdeduper')
-rw-r--r-- | qdeduper/mingui.cpp | 39 | ||||
-rw-r--r-- | qdeduper/sigdb_qt.cpp | 11 |
2 files changed, 38 insertions, 12 deletions
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 <QCloseEvent> #include <QMouseEvent> #include <QScrollBar> +#include <QPushButton> #include <QToolBar> #include <QTimer> #include <QMenuBar> @@ -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<bool> *fw = new QFutureWatcher<bool>(this); + fw->setFuture(f); + QObject::connect(fw, &QFutureWatcher<bool>::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<std::pair<fs::path, bool>> 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<std::pair<fs::path, bool>> paths) }); QFutureWatcher<void> *fw = new QFutureWatcher<void>(this); fw->setFuture(f); - QObject::connect(fw, &QFutureWatcher<void>::finished, this, [this] { + QObject::connect(fw, &QFutureWatcher<void>::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(); diff --git a/qdeduper/sigdb_qt.cpp b/qdeduper/sigdb_qt.cpp index 733a198..45fc55a 100644 --- a/qdeduper/sigdb_qt.cpp +++ b/qdeduper/sigdb_qt.cpp @@ -48,6 +48,10 @@ SignatureDB::~SignatureDB() void SignatureDB::create_priv_struct() { if (!valid()) return; + fmap.clear(); + frmap.clear(); + distmap.clear(); + this->groups.clear(); auto ids = sdb->get_image_ids(); sdb->batch_get_signature_begin(); for (auto &id : ids) @@ -63,7 +67,6 @@ void SignatureDB::create_priv_struct() for (auto &dupe : dupes) distmap[std::make_pair(dupe.id1, dupe.id2)] = dupe.distance; - sdb->group_similar(); auto gps = sdb->groups_get(); gps.erase(std::remove_if(gps.begin(), gps.end(), [](std::vector<size_t> v){ return v.size() < 2; }), gps.end()); this->groups = std::move(gps); @@ -89,6 +92,8 @@ void SignatureDB::scan_files(const std::vector<fs::path> &files, int njobs) Q_EMIT image_scanned(~size_t(0)); + sdb->group_similar(); + create_priv_struct(); } void SignatureDB::interrupt_scan() @@ -156,7 +161,9 @@ size_t SignatureDB::get_path_id(const fs::path& p) bool SignatureDB::load(const fs::path &p) { - return sdb->from_db_file(p); + bool ret = sdb->from_db_file(p); + create_priv_struct(); + return ret; } bool SignatureDB::save(const fs::path &p) |