diff options
-rw-r--r-- | qdeduper/mingui.cpp | 40 | ||||
-rw-r--r-- | qdeduper/sigdb_qt.cpp | 50 | ||||
-rw-r--r-- | qdeduper/sigdb_qt.hpp | 11 |
3 files changed, 83 insertions, 18 deletions
diff --git a/qdeduper/mingui.cpp b/qdeduper/mingui.cpp index 2f21e5e..845bc70 100644 --- a/qdeduper/mingui.cpp +++ b/qdeduper/mingui.cpp @@ -56,6 +56,15 @@ QString fsstr_to_qstring(const fs::path::string_type &s) #endif } +fs::path qstring_to_path(const QString &s) +{ +#if PATH_VALSIZE == 2 //the degenerate platform + return fs::path(s.toStdWString()); +#else + return fs::path(s.toStdString()); +#endif +} + Q_DECLARE_METATYPE(fs::path) DeduperMainWindow::DeduperMainWindow() @@ -174,8 +183,33 @@ void DeduperMainWindow::setup_menu() QAction *create_db = file->addAction("Create Database..."); QObject::connect(create_db, &QAction::triggered, this, &DeduperMainWindow::create_new); menuact["create_db"] = create_db; - file->addAction("Load Database..."); - file->addAction("Save Database..."); + QAction *load_db = file->addAction("Load Database..."); + load_db->setIcon(this->style()->standardIcon(QStyle::StandardPixmap::SP_DialogOpenButton)); + QObject::connect(load_db, &QAction::triggered, [this] { + 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); + } + }); + menuact["load_db"] = load_db; + + QAction *save_db = file->addAction("Save Database..."); + save_db->setIcon(this->style()->standardIcon(QStyle::StandardPixmap::SP_DialogSaveButton)); + QObject::connect(save_db, &QAction::triggered, [this] { + QString dbpath = QFileDialog::getSaveFileName(this, "Save Database", QString(), "Signature database (*.sigdb)"); + if (!dbpath.isNull() && this->sdb) + this->sdb->save(qstring_to_path(dbpath)); + }); + menuact["save_db"] = save_db; file->addSeparator(); file->addAction("Export Marked Images List..."); file->addAction("Import Marked Images List..."); @@ -249,11 +283,13 @@ void DeduperMainWindow::update_actions() menuact["next_group"]->setEnabled(false); menuact["prev_group"]->setEnabled(false); menuact["skip_group"]->setEnabled(false); + menuact["save_db"]->setEnabled(false); return; } menuact["skip_group"]->setEnabled(true); menuact["prev_group"]->setEnabled(curgroup > 0); menuact["next_group"]->setEnabled(curgroup + 1 < sdb->num_groups()); + menuact["save_db"]->setEnabled(true); } void DeduperMainWindow::show_images(const std::vector<fs::path> &fns) diff --git a/qdeduper/sigdb_qt.cpp b/qdeduper/sigdb_qt.cpp index c901bad..692f9c7 100644 --- a/qdeduper/sigdb_qt.cpp +++ b/qdeduper/sigdb_qt.cpp @@ -37,6 +37,7 @@ SignatureDB::SignatureDB() : QObject(nullptr) SignatureDB::SignatureDB(const fs::path &dbpath) : QObject(nullptr) { sdb = new signature_db(dbpath); + create_priv_struct(); } SignatureDB::~SignatureDB() @@ -44,21 +45,9 @@ SignatureDB::~SignatureDB() delete sdb; } -void SignatureDB::scan_files(const std::vector<fs::path> &files, int njobs) +void SignatureDB::create_priv_struct() { - populate_cfg_t pcfg = { - 3, - 3, - cfg_full, - cfg_subslice, - 0.3, - [this](size_t c,int){Q_EMIT image_scanned(c);}, - njobs - }; - sdb->populate(files, pcfg); - - Q_EMIT image_scanned(~size_t(0)); - + if (!valid()) return; auto ids = sdb->get_image_ids(); sdb->batch_get_signature_begin(); for (auto &id : ids) @@ -80,6 +69,29 @@ void SignatureDB::scan_files(const std::vector<fs::path> &files, int njobs) this->groups = std::move(gps); } +bool SignatureDB::valid() +{ + return sdb->valid(); +} + +void SignatureDB::scan_files(const std::vector<fs::path> &files, int njobs) +{ + populate_cfg_t pcfg = { + 3, + 3, + cfg_full, + cfg_subslice, + 0.3, + [this](size_t c,int){Q_EMIT image_scanned(c);}, + njobs + }; + sdb->populate(files, pcfg); + + Q_EMIT image_scanned(~size_t(0)); + + create_priv_struct(); +} + size_t SignatureDB::num_groups() { return groups.size(); @@ -120,3 +132,13 @@ size_t SignatureDB::get_path_id(const fs::path& p) return ~size_t(0); else return frmap[p]; } + +bool SignatureDB::load(const fs::path &p) +{ + return sdb->from_db_file(p); +} + +bool SignatureDB::save(const fs::path &p) +{ + return sdb->to_db_file(p); +} diff --git a/qdeduper/sigdb_qt.hpp b/qdeduper/sigdb_qt.hpp index 8a5178a..070662d 100644 --- a/qdeduper/sigdb_qt.hpp +++ b/qdeduper/sigdb_qt.hpp @@ -22,18 +22,25 @@ private: std::unordered_map<fs::path, size_t> frmap; std::map<std::pair<size_t, size_t>, double> distmap; std::vector<std::vector<size_t>> groups; + + void create_priv_struct(); public: SignatureDB(); - SignatureDB(const fs::path& dbpath); + SignatureDB(const fs::path &dbpath); ~SignatureDB(); + bool valid(); + void scan_files(const std::vector<fs::path> &files, int njobs); size_t num_groups(); std::vector<size_t> get_group(size_t gid); std::map<std::pair<size_t, size_t>, double> group_distances(size_t gid); fs::path get_image_path(size_t id); - size_t get_path_id(const fs::path& p); + size_t get_path_id(const fs::path &p); + + bool load(const fs::path &p); + bool save(const fs::path &p); Q_SIGNALS: void image_scanned(size_t n); }; |