diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2018-07-08 23:29:49 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2018-07-08 23:29:49 +0200 |
commit | fa1801471c2708ed8266ec7b99bd4cec886ccc1b (patch) | |
tree | aa56218c2c7e4939aaf11a2046b0f12760326545 /options/globals.hpp | |
parent | 90940a774eab876c38d5cef981b4be5bae67a462 (diff) |
options: fix 2 issues
1. Calling valueChanged didn't invoke machinery in
value<t>, only base_value aka value_.
There's a fast path in value<t>::type() despite the
pessimization.
2. Split global scope stuff into options::globals from
the options::globals stuff
3. Adjust usages
Diffstat (limited to 'options/globals.hpp')
-rw-r--r-- | options/globals.hpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/options/globals.hpp b/options/globals.hpp new file mode 100644 index 00000000..4d74cbf0 --- /dev/null +++ b/options/globals.hpp @@ -0,0 +1,71 @@ +#pragma once + +#include "export.hpp" +#include "compat/macros.hpp" + +#include <optional> + +#include <QString> +#include <QSettings> +#include <QMutex> + +namespace options::globals::detail { + +struct ini_ctx; +struct saver_; + +OTR_OPTIONS_EXPORT ini_ctx& cur_settings(); +OTR_OPTIONS_EXPORT ini_ctx& global_settings(); +OTR_OPTIONS_EXPORT bool is_portable_installation(); + +struct ini_ctx +{ + std::optional<QSettings> qsettings { std::in_place }; + int refcount = 0; + bool modifiedp = false; + QMutex mtx { QMutex::Recursive }; + QString pathname; +}; + +struct OTR_OPTIONS_EXPORT saver_ final +{ + ini_ctx& ctx; + + cc_noinline ~saver_(); + explicit cc_noinline saver_(ini_ctx& ini); +}; + +template<typename F> +cc_noinline +auto with_settings_object_(ini_ctx& ini, F&& fun) +{ + saver_ saver { ini }; + + return fun(*ini.qsettings); +} + +} // ns options::globals::detail + +namespace options::globals +{ + OTR_OPTIONS_EXPORT void mark_ini_modified(); + OTR_OPTIONS_EXPORT QString ini_directory(); + OTR_OPTIONS_EXPORT QString ini_filename(); + OTR_OPTIONS_EXPORT QString ini_pathname(); + OTR_OPTIONS_EXPORT QString ini_combine(const QString& filename); + OTR_OPTIONS_EXPORT QStringList ini_list(); + + template<typename F> + auto with_settings_object(F&& fun) + { + using namespace detail; + return with_settings_object_(cur_settings(), fun); + } + + template<typename F> + auto with_global_settings_object(F&& fun) + { + using namespace detail; + return with_settings_object_(global_settings(), fun); + } +} // ns options::globals |