aboutsummaryrefslogtreecommitdiff
path: root/qdeduper
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2022-10-02 19:46:19 -0400
committerGravatar Chris Xiong <chirs241097@gmail.com> 2022-10-02 19:46:19 -0400
commitffc70008a51db72f4cfcfbf1e82753f96cb23d95 (patch)
tree02c0566e53dfb4ab6d0150ec420a0f7b78334125 /qdeduper
parentfc7f2c61537677c99f76ad301add108d9e0e96c3 (diff)
downloaddeduper-ffc70008a51db72f4cfcfbf1e82753f96cb23d95.tar.xz
Implement toolbar customization.
Diffstat (limited to 'qdeduper')
-rw-r--r--qdeduper/mingui.cpp109
-rw-r--r--qdeduper/mingui.hpp2
-rw-r--r--qdeduper/preferencedialog.cpp112
-rw-r--r--qdeduper/preferencedialog.hpp12
-rw-r--r--qdeduper/settings.cpp56
-rw-r--r--qdeduper/settings.hpp6
6 files changed, 245 insertions, 52 deletions
diff --git a/qdeduper/mingui.cpp b/qdeduper/mingui.cpp
index f599ba0..89628f1 100644
--- a/qdeduper/mingui.cpp
+++ b/qdeduper/mingui.cpp
@@ -57,23 +57,23 @@ const std::vector<int> iadefkeys = {
Qt::Key::Key_U, Qt::Key::Key_I, Qt::Key::Key_O, Qt::Key::Key_P
};
const std::map<std::string, QKeySequence> defhk = {
- {"00_create_db", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_T)},
- {"01_load_db", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_O)},
- {"02_save_db", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_W)},
- {"03_save_list", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_E)},
- {"04_load_list", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_R)},
- {"05_search_image", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_Slash)},
- {"06_preferences", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_P)},
- {"07_exit", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_Q)},
- {"08_next_group", QKeySequence(Qt::Key::Key_M)},
- {"09_prev_group", QKeySequence(Qt::Key::Key_Z)},
- {"10_skip_group", QKeySequence(Qt::Key::Key_B)},
- {"11_single_mode_toggle", QKeySequence()},
- {"12_mark_all", QKeySequence(Qt::Key::Key_X)},
- {"13_mark_none", QKeySequence(Qt::Key::Key_C)},
- {"14_mark_all_dir", QKeySequence()},
- {"15_mark_all_dir_rec", QKeySequence()},
- {"16_view_marked", QKeySequence()},
+ {"create_db", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_T)},
+ {"load_db", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_O)},
+ {"save_db", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_W)},
+ {"save_list", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_E)},
+ {"load_list", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_R)},
+ {"search_image", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_Slash)},
+ {"preferences", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_P)},
+ {"exit", QKeySequence(Qt::Modifier::CTRL | Qt::Key::Key_Q)},
+ {"next_group", QKeySequence(Qt::Key::Key_M)},
+ {"prev_group", QKeySequence(Qt::Key::Key_Z)},
+ {"skip_group", QKeySequence(Qt::Key::Key_B)},
+ {"single_mode_toggle", QKeySequence()},
+ {"mark_all", QKeySequence(Qt::Key::Key_X)},
+ {"mark_none", QKeySequence(Qt::Key::Key_C)},
+ {"mark_all_dir", QKeySequence()},
+ {"mark_all_dir_rec", QKeySequence()},
+ {"view_marked", QKeySequence()},
};
const std::vector<int> iadefmo = {
0, //mark_toggle
@@ -185,8 +185,7 @@ DeduperMainWindow::DeduperMainWindow()
int hkt = sr->register_tab("Shortcuts");
for (auto &hkp : defhk)
{
- std::string hkn = hkp.first.substr(3);
- sr->register_keyseq_option(hkt, "hotkey/" + hkn, QString(), hkp.second);
+ sr->register_keyseq_option(hkt, "hotkey/" + hkp.first, QString(), hkp.second);
}
for (size_t i = 0; i < iadefmo.size(); ++i)
{
@@ -198,10 +197,13 @@ DeduperMainWindow::DeduperMainWindow()
std::string iakt = "hotkey/item_" + std::to_string(i) + "_action_key";
sr->register_int_option(hkt, iakt, QString(), INT_MIN, INT_MAX, iadefkeys[i]);
}
+ int tbt = sr->register_tab("Toolbar");
+ sr->register_strlist_option(tbt, "toolbar_actions", "", {"prev_group", "next_group", "skip_group", "single_mode_toggle", "sort"});
prefdlg = new PreferenceDialog(sr, this);
prefdlg->setModal(true);
prefdlg->close();
- prefdlg->set_hkactions(hkt, defhk, menuact);
+ prefdlg->set_hkactions(hkt, actionlist, menuact);
+ prefdlg->set_toolbaractions(tbt, menuact);
QObject::connect(menuact["preferences"], &QAction::triggered, prefdlg, &PreferenceDialog::open);
QObject::connect(prefdlg, &PreferenceDialog::accepted, this, &DeduperMainWindow::apply_prefs);
apply_prefs();
@@ -250,7 +252,7 @@ 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;
+ register_action("create_db", create_db);
QAction *load_db = file->addAction("Load Database...");
load_db->setIcon(this->style()->standardIcon(QStyle::StandardPixmap::SP_DialogOpenButton));
QObject::connect(load_db, &QAction::triggered, [this] {
@@ -287,7 +289,7 @@ void DeduperMainWindow::setup_menu()
}, Qt::ConnectionType::QueuedConnection);
}
});
- menuact["load_db"] = load_db;
+ register_action("load_db", load_db);
QAction *save_db = file->addAction("Save Database...");
save_db->setIcon(this->style()->standardIcon(QStyle::StandardPixmap::SP_DialogSaveButton));
@@ -296,16 +298,16 @@ void DeduperMainWindow::setup_menu()
if (!dbpath.isNull() && this->sdb)
this->sdb->save(utilities::qstring_to_path(dbpath));
});
- menuact["save_db"] = save_db;
+ register_action("save_db", save_db);
file->addSeparator();
QAction *savelist = file->addAction("Export Marked Images List...");
QObject::connect(savelist, &QAction::triggered, [this]{Q_EMIT this->save_list();});
- menuact["save_list"] = savelist;
+ register_action("save_list", savelist);
QAction *loadlist = file->addAction("Import Marked Images List...");
QObject::connect(loadlist, &QAction::triggered, [this]{Q_EMIT this->load_list();});
- menuact["load_list"] = loadlist;
+ register_action("load_list", loadlist);
file->addSeparator();
QAction *search_img = file->addAction("Search for Image...");
@@ -315,19 +317,19 @@ void DeduperMainWindow::setup_menu()
searched_image = utilities::qstring_to_path(fpath);
search_image(searched_image);
});
- menuact["search_image"] = search_img;
+ register_action("search_image", search_img);
file->addSeparator();
QAction *pref = file->addAction("Preferences...");
- menuact["preferences"] = pref;
+ register_action("preferences", pref);
QAction *exita = file->addAction("Exit");
QObject::connect(exita, &QAction::triggered, [this] {
if (this->modified_check()) qApp->quit();
});
- menuact["exit"] = exita;
+ register_action("exit", exita);
QAction *nxtgrp = view->addAction("Next Group");
nxtgrp->setIcon(this->style()->standardIcon(QStyle::StandardPixmap::SP_ArrowRight));
- menuact["next_group"] = nxtgrp;
+ register_action("next_group", nxtgrp);
QObject::connect(nxtgrp, &QAction::triggered, [this] {
if (this->vm == ViewMode::view_searchresult) { this->show_group(curgroup); return; }
if (this->sdb && curgroup + 1 < this->sdb->num_groups())
@@ -336,7 +338,7 @@ void DeduperMainWindow::setup_menu()
QAction *prvgrp = view->addAction("Previous Group");
prvgrp->setIcon(this->style()->standardIcon(QStyle::StandardPixmap::SP_ArrowLeft));
- menuact["prev_group"] = prvgrp;
+ register_action("prev_group", prvgrp);
QObject::connect(prvgrp, &QAction::triggered, [this] {
if (this->vm == ViewMode::view_searchresult) { this->show_group(curgroup); return; }
if (this->sdb && curgroup > 0)
@@ -345,7 +347,7 @@ void DeduperMainWindow::setup_menu()
QAction *skip = view->addAction("Skip to Group...");
skip->setIcon(this->style()->standardIcon(QStyle::StandardPixmap::SP_ArrowUp));
- menuact["skip_group"] = skip;
+ register_action("skip_group", skip);
QObject::connect(skip, &QAction::triggered, [this] {
if (!this->sdb) return;
bool ok = false;
@@ -359,7 +361,7 @@ void DeduperMainWindow::setup_menu()
view->addSeparator();
QAction *singlemode = view->addAction("Single Item Mode");
singlemode->setCheckable(true);
- menuact["single_mode_toggle"] = singlemode;
+ register_action("single_mode_toggle", singlemode);
QObject::connect(singlemode, &QAction::triggered, [this] (bool c) {
id->set_single_item_mode(c);
});
@@ -434,14 +436,15 @@ void DeduperMainWindow::setup_menu()
}
sasc->setChecked(true);
sordg->setExclusionPolicy(QActionGroup::ExclusionPolicy::Exclusive);
+ register_action("sort", sort);
QAction *mall = mark->addAction("Mark All");
QObject::connect(mall, &QAction::triggered, [this]{this->mark_all();});
- menuact["mark_all"] = mall;
+ register_action("mark_all", mall);
QAction *mnone = mark->addAction("Mark None");
QObject::connect(mnone, &QAction::triggered, [this]{this->mark_none();});
- menuact["mark_none"] = mnone;
+ register_action("mark_none", mnone);
QAction *madir = mark->addAction("Mark All within directory...");
QObject::connect(madir, &QAction::triggered, [this] {
@@ -461,7 +464,7 @@ void DeduperMainWindow::setup_menu()
itm->setCheckState(marked.find(fp) == marked.end() ? Qt::CheckState::Unchecked : Qt::CheckState::Checked);
}
});
- menuact["mark_all_dir"] = madir;
+ register_action("mark_all_dir", madir);
QAction *madirr = mark->addAction("Mark All within directory and subdirectory...");
QObject::connect(madirr, &QAction::triggered, [this] {
QString s = QFileDialog::getExistingDirectory(this, "Open");
@@ -480,11 +483,11 @@ void DeduperMainWindow::setup_menu()
itm->setCheckState(marked.find(fp) == marked.end() ? Qt::CheckState::Unchecked : Qt::CheckState::Checked);
}
});
- menuact["mark_all_dir_rec"] = madirr;
+ register_action("mark_all_dir_rec", madirr);
mark->addSeparator();
QAction *view_marked = mark->addAction("Review Marked Images");
QObject::connect(view_marked, &QAction::triggered, this, &DeduperMainWindow::show_marked);
- menuact["view_marked"] = view_marked;
+ register_action("view_marked", view_marked);
help->addAction("Help");
help->addSeparator();
@@ -520,13 +523,6 @@ void DeduperMainWindow::setup_menu()
tb = new QToolBar(this);
this->addToolBar(tb);
- tb->addAction(prvgrp);
- tb->addAction(nxtgrp);
- tb->addAction(skip);
- tb->addAction(sort);
- QToolButton *tbsortb = qobject_cast<QToolButton*>(tb->widgetForAction(sort));
- tbsortb->setPopupMode(QToolButton::ToolButtonPopupMode::InstantPopup);
- tb->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon);
for (auto &ap : menuact)
this->addAction(ap.second);
@@ -816,9 +812,8 @@ void DeduperMainWindow::apply_prefs()
this->rampupd->stop();
this->dbramusg->setText(QString());
}
- for (auto &hkp : defhk)
+ for (auto &hkn : actionlist)
{
- std::string hkn = hkp.first.substr(3);
QKeySequence ks = sr->get_option_keyseq("hotkey/" + hkn);
menuact[hkn]->setShortcut(ks);
}
@@ -834,6 +829,22 @@ void DeduperMainWindow::apply_prefs()
QKeySequence ks = ~im ? QKeySequence(static_cast<Qt::Key>(ik | im)) : QKeySequence();
act->setShortcut(ks);
}
+ auto tbal = sr->get_option_strlist("toolbar_actions");
+ tb->clear();
+ bool tbvisible = false;
+ for (auto &tban : tbal)
+ {
+ if (menuact.find(tban.toStdString()) == menuact.end()) continue;
+ tbvisible = true;
+ QAction *act = menuact[tban.toStdString()];
+ tb->addAction(act);
+ if (act->menu())
+ {
+ QToolButton *tbb = qobject_cast<QToolButton*>(tb->widgetForAction(act));
+ tbb->setPopupMode(QToolButton::ToolButtonPopupMode::InstantPopup);
+ }
+ }
+ tb->setVisible(tbvisible);
}
void DeduperMainWindow::update_memusg()
@@ -842,6 +853,12 @@ void DeduperMainWindow::update_memusg()
dbramusg->setText(QString("Database memory usage: %1").arg(QLocale::system().formattedDataSize(this->sdb->db_memory_usage())));
}
+void DeduperMainWindow::register_action(const std::string &actn, QAction *act)
+{
+ menuact[actn] = act;
+ actionlist.push_back(actn);
+}
+
void DeduperMainWindow::sort_reassign_hotkeys()
{
im->setSortRole(this->sort_role);
diff --git a/qdeduper/mingui.hpp b/qdeduper/mingui.hpp
index 19db256..0fc191f 100644
--- a/qdeduper/mingui.hpp
+++ b/qdeduper/mingui.hpp
@@ -60,6 +60,7 @@ private:
QListView *lv;
QToolBar *tb = nullptr;
std::map<std::string, QAction*> menuact;
+ std::vector<std::string> actionlist;
QList<QAction*> selhk;
QStandardItemModel *im = nullptr;
ImageItemDelegate *id = nullptr;
@@ -112,6 +113,7 @@ public Q_SLOTS:
void show_marked();
void apply_prefs();
void update_memusg();
+ void register_action(const std::string &actn, QAction *act);
Q_SIGNALS:
void next();
void prev();
diff --git a/qdeduper/preferencedialog.cpp b/qdeduper/preferencedialog.cpp
index 40d2aea..c1be65b 100644
--- a/qdeduper/preferencedialog.cpp
+++ b/qdeduper/preferencedialog.cpp
@@ -14,6 +14,8 @@
#include <QAction>
#include <QTableView>
#include <QStandardItemModel>
+#include <QSortFilterProxyModel>
+#include <QListView>
#include <QKeySequenceEdit>
#include <QGroupBox>
#include <QMessageBox>
@@ -21,6 +23,13 @@
#include "preferencedialog.hpp"
#include "settings.hpp"
+enum ToolbarActionRoles
+{
+ action_role = Qt::ItemDataRole::UserRole + 1,
+ order_role,
+ hide_role
+};
+
PreferenceDialog::PreferenceDialog(SettingsRegistry *sr, QWidget *parent) : QDialog(parent)
{
this->sr = sr;
@@ -128,9 +137,9 @@ void PreferenceDialog::setup_widgets()
}
}
-void PreferenceDialog::set_hkactions(int tab, std::map<std::string, QKeySequence> defmap, std::map<std::string, QAction*> actmap)
+void PreferenceDialog::set_hkactions(int tab, const std::vector<std::string> &actlist, const std::map<std::string, QAction*> &actmap)
{
- this->defmap = defmap;
+ this->actlist = actlist;
this->actmap = actmap;
this->hktv = new QTableView();
this->hkim = new QStandardItemModel();
@@ -158,6 +167,76 @@ void PreferenceDialog::set_hkactions(int tab, std::map<std::string, QKeySequence
}
}
+void PreferenceDialog::set_toolbaractions(int tab, const std::map<std::string, QAction*> &actmap)
+{
+ QGridLayout *l = this->tabs[tab];
+ tbaav = new QListView();
+ tbaam = new QStandardItemModel();
+ tbapm = new QSortFilterProxyModel();
+ tbapm->setSourceModel(tbaam);
+ tbapm->setSortRole(ToolbarActionRoles::order_role);
+ tbapm->setFilterRole(ToolbarActionRoles::hide_role);
+ tbapm->setFilterKeyColumn(0);
+ tbapm->setFilterFixedString("0");
+ tbaav->setModel(tbapm);
+ tbeav = new QListView();
+ tbeam = new QStandardItemModel();
+ tbeav->setModel(tbeam);
+ tbaav->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
+ tbeav->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
+ tbaav->setDragDropMode(QAbstractItemView::DragDropMode::NoDragDrop);
+ tbeav->setDragDropMode(QAbstractItemView::DragDropMode::InternalMove);
+ QPushButton *pbadd = new QPushButton(">");
+ QPushButton *pbdel = new QPushButton("<");
+ pbadd->setMaximumWidth(24);
+ pbdel->setMaximumWidth(24);
+ QVBoxLayout *vbl = new QVBoxLayout();
+ vbl->addWidget(pbadd);
+ vbl->addWidget(pbdel);
+ l->addWidget(new QLabel("Available Buttons"), 0, 0);
+ l->addWidget(new QLabel("Enabled Buttons"), 0, 2);
+ l->addWidget(tbaav, 1, 0);
+ l->addLayout(vbl, 1, 1);
+ l->addWidget(tbeav, 1, 2);
+ l->addWidget(new QLabel("Drag to sort enabled buttons."), 2, 0, 1, 3);
+ tbaam->clear();
+ for (size_t i = 0; i < actlist.size(); ++i)
+ {
+ auto &actn = actlist[i];
+ QAction *act = this->actmap[actn];
+ QStandardItem *itm = new QStandardItem(act->text());
+ itm->setIcon(act->icon());
+ itm->setData(QString::fromStdString(actn), ToolbarActionRoles::action_role);
+ itm->setData(QVariant::fromValue<size_t>(i), ToolbarActionRoles::order_role);
+ itm->setData("0", ToolbarActionRoles::hide_role);
+ tbaam->appendRow(itm);
+ }
+ QObject::connect(pbadd, &QPushButton::clicked, [this] {
+ QModelIndex idx = tbaav->currentIndex();
+ if (!idx.isValid()) return;
+ QString actn = idx.data(ToolbarActionRoles::action_role).value<QString>();
+ QAction *act = this->actmap[actn.toStdString()];
+ QStandardItem *itm = new QStandardItem(act->text());
+ itm->setIcon(act->icon());
+ itm->setData(actn, ToolbarActionRoles::action_role);
+ itm->setDropEnabled(false);
+ tbeam->appendRow(itm);
+ tbaam->setData(tbapm->mapToSource(idx), "1", ToolbarActionRoles::hide_role);
+ });
+ QObject::connect(pbdel, &QPushButton::clicked, [this] {
+ QModelIndex idx = tbeav->currentIndex();
+ if (!idx.isValid()) return;
+ QString actn = idx.data(ToolbarActionRoles::action_role).value<QString>();
+ for (int i = 0; i < tbaam->rowCount(); ++i)
+ {
+ const auto &idx = tbaam->index(i, 0);
+ if (tbaam->data(idx, ToolbarActionRoles::action_role).value<QString>() == actn)
+ tbaam->setData(idx, "0", ToolbarActionRoles::hide_role);
+ }
+ tbeam->removeRows(idx.row(), 1);
+ });
+}
+
void PreferenceDialog::load_widget_status()
{
for (auto &k : sr->klist)
@@ -193,9 +272,8 @@ void PreferenceDialog::load_widget_status()
}
this->hkim->clear();
this->hkim->setHorizontalHeaderLabels({"Menu Item", "Hotkey"});
- for (auto &hkp : this->defmap)
+ for (auto &actn : this->actlist)
{
- std::string actn = hkp.first.substr(3);
QKeySequence ks = sr->get_option_keyseq("hotkey/" + actn);
if (this->actmap.find(actn) == this->actmap.end())
continue;
@@ -227,6 +305,28 @@ void PreferenceDialog::load_widget_status()
int im = sr->get_option_int(iamt);
mes[i]->set_modifier(static_cast<Qt::Modifier>(im));
}
+ for (int i = 0; i < tbaam->rowCount(); ++i)
+ {
+ const auto &idx = tbaam->index(i, 0);
+ tbaam->setData(idx, "0", ToolbarActionRoles::hide_role);
+ }
+ auto tbal = sr->get_option_strlist("toolbar_actions");
+ this->tbeam->clear();
+ for (auto &tban : tbal)
+ {
+ QAction *act = this->actmap[tban.toStdString()];
+ QStandardItem *itm = new QStandardItem(act->text());
+ itm->setIcon(act->icon());
+ itm->setData(tban, ToolbarActionRoles::action_role);
+ itm->setDropEnabled(false);
+ for (int i = 0; i < tbaam->rowCount(); ++i)
+ {
+ const auto &idx = tbaam->index(i, 0);
+ if (tbaam->data(idx, ToolbarActionRoles::action_role).value<QString>() == tban)
+ tbaam->setData(idx, "1", ToolbarActionRoles::hide_role);
+ }
+ tbeam->appendRow(itm);
+ }
}
void PreferenceDialog::save_widget_status()
@@ -275,6 +375,10 @@ void PreferenceDialog::save_widget_status()
std::string iamt = "hotkey/item_action_mod_" + std::to_string(i);
sr->set_option_int(iamt, mes[i]->get_modifier());
}
+ QStringList tbal;
+ for (int i = 0; i < tbeam->rowCount(); ++i)
+ tbal.push_back(tbeam->item(i)->data(ToolbarActionRoles::action_role).value<QString>());
+ sr->set_option_strlist("toolbar_actions", tbal);
}
int PreferenceDialog::verify_shortcuts(QKeySequence *bks)
diff --git a/qdeduper/preferencedialog.hpp b/qdeduper/preferencedialog.hpp
index 78e78c5..b8b2d15 100644
--- a/qdeduper/preferencedialog.hpp
+++ b/qdeduper/preferencedialog.hpp
@@ -16,7 +16,9 @@ class QTabWidget;
class QGridLayout;
class QDialogButtonBox;
class QTableView;
+class QListView;
class QStandardItemModel;
+class QSortFilterProxyModel;
class ModifierEdit : public QPushButton
{
@@ -38,7 +40,8 @@ class PreferenceDialog : public QDialog
public:
PreferenceDialog(SettingsRegistry *sr, QWidget *parent = nullptr);
void setup_widgets();
- void set_hkactions(int tab, std::map<std::string, QKeySequence> defmap, std::map<std::string, QAction*> actmap);
+ void set_hkactions(int tab, const std::vector<std::string> &actlist, const std::map<std::string, QAction*> &actmap);
+ void set_toolbaractions(int tab, const std::map<std::string, QAction*> &actmap);
void load_widget_status();
void save_widget_status();
@@ -54,7 +57,12 @@ private:
QDialogButtonBox *bb;
QTableView *hktv = nullptr;
QStandardItemModel *hkim = nullptr;
- std::map<std::string, QKeySequence> defmap;
+ QListView *tbaav = nullptr;
+ QStandardItemModel *tbaam = nullptr;
+ QSortFilterProxyModel *tbapm = nullptr;
+ QListView *tbeav = nullptr;
+ QStandardItemModel *tbeam = nullptr;
+ std::vector<std::string> actlist;
std::map<std::string, QAction*> actmap;
std::vector<ModifierEdit*> mes;
};
diff --git a/qdeduper/settings.cpp b/qdeduper/settings.cpp
index 75dfbfd..e19cc56 100644
--- a/qdeduper/settings.cpp
+++ b/qdeduper/settings.cpp
@@ -127,3 +127,59 @@ void SettingsRegistry::set_option_keyseq(std::string key, QKeySequence ks)
return;
s->setValue(QString::fromStdString(key), QVariant::fromValue<QKeySequence>(ks));
}
+
+void SettingsRegistry::register_str_option(int tab, std::string key, QString desc, QString defaultval)
+{
+ klist.push_back(key);
+ smap[key] = {
+ SettingsItem::ParameterType::_str,
+ tab,
+ key,
+ desc,
+ QVariant(),
+ QVariant(),
+ QVariant::fromValue<QString>(defaultval),
+ nullptr};
+}
+
+QString SettingsRegistry::get_option_str(std::string key)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_str)
+ return QString();
+ return s->value(QString::fromStdString(key), smap[key].defaultv).value<QString>();
+}
+
+void SettingsRegistry::set_option_str(std::string key, QString str)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_str)
+ return;
+ s->setValue(QString::fromStdString(key), QVariant::fromValue<QString>(str));
+}
+
+void SettingsRegistry::register_strlist_option(int tab, std::string key, QString desc, QStringList defaultval)
+{
+ klist.push_back(key);
+ smap[key] = {
+ SettingsItem::ParameterType::_strlist,
+ tab,
+ key,
+ desc,
+ QVariant(),
+ QVariant(),
+ QVariant::fromValue<QStringList>(defaultval),
+ nullptr};
+}
+
+QStringList SettingsRegistry::get_option_strlist(std::string key)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_strlist)
+ return QStringList();
+ return s->value(QString::fromStdString(key), smap[key].defaultv).value<QStringList>();
+}
+
+void SettingsRegistry::set_option_strlist(std::string key, QStringList str)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_strlist)
+ return;
+ s->setValue(QString::fromStdString(key), QVariant::fromValue<QStringList>(str));
+}
diff --git a/qdeduper/settings.hpp b/qdeduper/settings.hpp
index fb1daa4..1ba75ee 100644
--- a/qdeduper/settings.hpp
+++ b/qdeduper/settings.hpp
@@ -47,6 +47,12 @@ public:
void register_keyseq_option(int tab, std::string key, QString desc, QKeySequence defaultval);
QKeySequence get_option_keyseq(std::string key);
void set_option_keyseq(std::string key, QKeySequence ks);
+ void register_str_option(int tab, std::string key, QString desc, QString defaultval);
+ QString get_option_str(std::string key);
+ void set_option_str(std::string key, QString str);
+ void register_strlist_option(int tab, std::string key, QString desc, QStringList defaultval);
+ QStringList get_option_strlist(std::string key);
+ void set_option_strlist(std::string key, QStringList str);
private:
QSettings *s;
QStringList tabs;