diff options
Diffstat (limited to 'options/group.hpp')
-rw-r--r-- | options/group.hpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/options/group.hpp b/options/group.hpp index e2a8058c..b0e13a6a 100644 --- a/options/group.hpp +++ b/options/group.hpp @@ -1,13 +1,16 @@ #pragma once #include "export.hpp" + #include "compat/util.hpp" + #include <map> #include <memory> #include <QString> #include <QList> #include <QVariant> #include <QSettings> +#include <QMutex> namespace options { @@ -15,12 +18,27 @@ namespace options { class OTR_OPTIONS_EXPORT group final { QString name; + + static QString cur_ini_pathname; + static std::shared_ptr<QSettings> cur_ini; + static QMutex cur_ini_mtx; + static int ini_refcount; + static bool ini_modifiedp; + struct OTR_OPTIONS_EXPORT saver_ final + { + QSettings& s; + QMutex& mtx; + QMutexLocker lck; + + ~saver_(); + saver_(QSettings& s, QMutex&); + }; + static std::shared_ptr<QSettings> cur_settings_object(); + public: std::map<QString, QVariant> kvs; - group(const QString& name, mem<QSettings> s); group(const QString& name); void save() const; - void save_deferred(QSettings& s) const; void put(const QString& s, const QVariant& d); bool contains(const QString& s) const; static QString ini_directory(); @@ -28,9 +46,11 @@ public: static QString ini_pathname(); static QString ini_combine(const QString& filename); static QStringList ini_list(); - static std::shared_ptr<QSettings> ini_file(); + + static void mark_ini_modified(); template<typename t> + OTR_NEVER_INLINE t get(const QString& k) const { auto value = kvs.find(k); @@ -38,6 +58,15 @@ public: return value->second.value<t>(); return t(); } + + template<typename F> + OTR_NEVER_INLINE + static auto with_settings_object(F&& fun) + { + saver_ saver { *cur_settings_object(), cur_ini_mtx }; + + return fun(static_cast<QSettings&>(saver.s)); + } }; } |