summaryrefslogtreecommitdiffhomepage
path: root/options/group.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'options/group.hpp')
-rw-r--r--options/group.hpp113
1 files changed, 33 insertions, 80 deletions
diff --git a/options/group.hpp b/options/group.hpp
index f191fdd5..ef9f1121 100644
--- a/options/group.hpp
+++ b/options/group.hpp
@@ -1,96 +1,49 @@
#pragma once
+#include "options/defs.hpp"
+
+#include "compat/base-path.hpp"
+#include "compat/library-path.hpp"
+#include "compat/qhash.hpp"
#include "compat/macros.hpp"
#include "export.hpp"
-// included here to propagate into callers of options::group
-#include "metatype.hpp"
+#include <optional>
+#include <unordered_map>
-#include <map>
-#include <memory>
+#include <QHash>
#include <QString>
-#include <QList>
+#include <QMutex>
+#include <QFile>
+#include <QDir>
+#include <QStandardPaths>
#include <QVariant>
#include <QSettings>
-#include <QMutex>
+#include <QDebug>
// XXX TODO remove qsettings usage -sh 20180624
-namespace options {
-
-// snapshot of qsettings group at given time
-class OTR_OPTIONS_EXPORT group final
-{
- QString name;
-
- static QString cur_ini_pathname;
-
- static std::shared_ptr<QSettings> cur_ini;
- static int ini_refcount;
- static bool ini_modifiedp;
- static QMutex cur_ini_mtx;
-
- static std::shared_ptr<QSettings> cur_global_ini;
- static int global_ini_refcount;
- static bool global_ini_modifiedp;
- static QMutex global_ini_mtx;
-
- struct OTR_OPTIONS_EXPORT saver_ final
+namespace options::detail {
+ // snapshot of qsettings group at given time
+ class OTR_OPTIONS_EXPORT group final
{
- QSettings& s;
- int& refcount;
- bool& modifiedp;
-
- cc_noinline ~saver_();
- cc_noinline saver_(QSettings& s, int& refcount, bool& modifiedp);
+ QString name;
+
+ public:
+ std::unordered_map<QString, QVariant> kvs;
+ explicit group(const QString& name);
+ void save() const;
+ void put(const QString& s, const QVariant& d);
+ bool contains(const QString& s) const;
+
+ template<typename t>
+ cc_noinline t get(const QString& k) const
+ {
+ return get_variant(k).value<t>();
+ }
+
+ cc_noinline QVariant get_variant(const QString& name) const;
};
- static std::shared_ptr<QSettings> cur_settings_object();
- static std::shared_ptr<QSettings> cur_global_settings_object();
-
-public:
- std::map<QString, QVariant> kvs;
- group(const QString& name);
- void save() const;
- void put(const QString& s, const QVariant& d);
- bool contains(const QString& s) const;
- static QString ini_directory();
- static QString ini_filename();
- static QString ini_pathname();
- static QString ini_combine(const QString& filename);
- static QStringList ini_list();
- static bool is_portable_installation();
-
- static void mark_ini_modified();
-
- template<typename t>
- cc_noinline
- t get(const QString& k) const
- {
- auto value = kvs.find(k);
- if (value != kvs.cend())
- return value->second.value<t>();
- return t();
- }
-
- template<typename F>
- cc_noinline
- static auto with_settings_object(F&& fun)
- {
- QMutexLocker l(&cur_ini_mtx);
- saver_ saver { *cur_settings_object(), ini_refcount, ini_modifiedp };
-
- return fun(saver.s);
- }
-
- template<typename F>
- static auto with_global_settings_object(F&& fun)
- {
- QMutexLocker l(&global_ini_mtx);
- saver_ saver { *cur_global_settings_object(), global_ini_refcount, global_ini_modifiedp };
- global_ini_modifiedp = true;
+} // ns options::detail
- return fun(saver.s);
- }
-};
-}