aboutsummaryrefslogtreecommitdiff
path: root/qdeduper/settings.cpp
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2022-09-26 22:14:18 -0400
committerGravatar Chris Xiong <chirs241097@gmail.com> 2022-09-26 22:17:44 -0400
commit2e7924a07d45c1d1468552f951dcd2f2dcc948fa (patch)
tree24b6788b505a82f70f7dd82f8d9f1570fc88fef1 /qdeduper/settings.cpp
parent43a058c0957bec3fc564a7a019bdc03829e32e70 (diff)
downloaddeduper-2e7924a07d45c1d1468552f951dcd2f2dcc948fa.tar.xz
Add a few basic settings items.
Yes I stole qmp's settings design and silently relicensed the (largely identical) code. But who in the world cares, plus I'm the author of qmp anyway.
Diffstat (limited to 'qdeduper/settings.cpp')
-rw-r--r--qdeduper/settings.cpp129
1 files changed, 129 insertions, 0 deletions
diff --git a/qdeduper/settings.cpp b/qdeduper/settings.cpp
new file mode 100644
index 0000000..75dfbfd
--- /dev/null
+++ b/qdeduper/settings.cpp
@@ -0,0 +1,129 @@
+#include <limits>
+
+#include "settings.hpp"
+
+SettingsRegistry::SettingsRegistry(QString path)
+{
+ s = new QSettings(path, QSettings::Format::IniFormat);
+}
+SettingsRegistry::~SettingsRegistry()
+{
+ delete s;
+}
+int SettingsRegistry::register_tab(QString tab_name)
+{
+ tabs.push_back(tab_name);
+ return tabs.size() - 1;
+}
+
+void SettingsRegistry::register_int_option(int tab, std::string key, QString desc, int min, int max, int defaultval)
+{
+ klist.push_back(key);
+ smap[key] = {
+ SettingsItem::ParameterType::_int,
+ tab,
+ key,
+ desc,
+ QVariant::fromValue<int>(min),
+ QVariant::fromValue<int>(max),
+ QVariant::fromValue<int>(defaultval),
+ nullptr};
+}
+
+int SettingsRegistry::get_option_int(std::string key)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_int)
+ return -1;
+ return s->value(QString::fromStdString(key), smap[key].defaultv).value<int>();
+}
+
+void SettingsRegistry::set_option_int(std::string key, int val)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_int)
+ return;
+ s->setValue(QString::fromStdString(key), QVariant::fromValue<int>(val));
+}
+
+void SettingsRegistry::register_bool_option(int tab, std::string key, QString desc, bool defaultval)
+{
+ klist.push_back(key);
+ smap[key] = {
+ SettingsItem::ParameterType::_bool,
+ tab,
+ key,
+ desc,
+ QVariant(),
+ QVariant(),
+ QVariant::fromValue<bool>(defaultval),
+ nullptr};
+}
+
+bool SettingsRegistry::get_option_bool(std::string key)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_bool)
+ return false;
+ return s->value(QString::fromStdString(key), smap[key].defaultv).value<bool>();
+}
+
+void SettingsRegistry::set_option_bool(std::string key, bool val)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_bool)
+ return;
+ s->setValue(QString::fromStdString(key), QVariant::fromValue<bool>(val));
+}
+
+void SettingsRegistry::register_double_option(int tab, std::string key, QString desc, double min, double max, double defaultval)
+{
+ klist.push_back(key);
+ smap[key] = {
+ SettingsItem::ParameterType::_double,
+ tab,
+ key,
+ desc,
+ QVariant::fromValue<double>(min),
+ QVariant::fromValue<double>(max),
+ QVariant::fromValue<double>(defaultval),
+ nullptr};
+}
+
+double SettingsRegistry::get_option_double(std::string key)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_double)
+ return std::numeric_limits<double>::quiet_NaN();
+ return s->value(QString::fromStdString(key), smap[key].defaultv).value<double>();
+}
+
+void SettingsRegistry::set_option_double(std::string key, double val)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_double)
+ return;
+ s->setValue(QString::fromStdString(key), QVariant::fromValue<double>(val));
+}
+
+void SettingsRegistry::register_keyseq_option(int tab, std::string key, QString desc, QKeySequence defaultval)
+{
+ klist.push_back(key);
+ smap[key] = {
+ SettingsItem::ParameterType::_keyseq,
+ tab,
+ key,
+ desc,
+ QVariant(),
+ QVariant(),
+ QVariant::fromValue<QKeySequence>(defaultval),
+ nullptr};
+}
+
+QKeySequence SettingsRegistry::get_option_keyseq(std::string key)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_keyseq)
+ return QKeySequence();
+ return s->value(QString::fromStdString(key), smap[key].defaultv).value<QKeySequence>();
+}
+
+void SettingsRegistry::set_option_keyseq(std::string key, QKeySequence ks)
+{
+ if (smap.find(key) == smap.end() || smap[key].type != SettingsItem::ParameterType::_keyseq)
+ return;
+ s->setValue(QString::fromStdString(key), QVariant::fromValue<QKeySequence>(ks));
+}