summaryrefslogtreecommitdiffhomepage
path: root/options/group.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-10-08 13:39:23 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-10-08 13:42:40 +0200
commit863b8cad6d95ed2492ac929066f843664a49998d (patch)
tree527a20e268234ac81b86d6e88506c3b847f5dc25 /options/group.hpp
parentced9bbd4c1b7d3a3968dbf8b1731bc49ff9f9164 (diff)
add complete(?) portable config support
Diffstat (limited to 'options/group.hpp')
-rw-r--r--options/group.hpp33
1 files changed, 26 insertions, 7 deletions
diff --git a/options/group.hpp b/options/group.hpp
index c07fe576..b1aad156 100644
--- a/options/group.hpp
+++ b/options/group.hpp
@@ -23,20 +23,28 @@ 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;
+ 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
{
QSettings& s;
- QMutex& mtx;
- QMutexLocker lck;
+ int& refcount;
+ bool& modifiedp;
- ~saver_();
- saver_(QSettings& s, QMutex&);
+ never_inline ~saver_();
+ never_inline saver_(QSettings& s, int& refcount, bool& modifiedp);
};
static std::shared_ptr<QSettings> cur_settings_object();
+ static std::shared_ptr<QSettings> cur_global_settings_object();
public:
std::map<QString, QVariant> kvs;
@@ -67,9 +75,20 @@ public:
never_inline
static auto with_settings_object(F&& fun)
{
- saver_ saver { *cur_settings_object(), cur_ini_mtx };
+ 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, ini_modifiedp };
+ global_ini_modifiedp = true;
- return fun(static_cast<QSettings&>(saver.s));
+ return fun(saver.s);
}
};