summaryrefslogtreecommitdiffhomepage
path: root/options/globals.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-10-05 15:54:01 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-10-05 14:35:29 +0000
commitf0216a3c53d43918295f1bd81975b391f4e5ed3b (patch)
treeb6311d48559bbdb4b657beed1bd8164d9157b03f /options/globals.cpp
parent39ea3871c1b3f594df846bc0b9a627c9880ecea4 (diff)
options: don't use typeindex w/ lambdas
Rename traits' functions to be more explicit. Most of the changes are pretty old and I can't read them at this time, sorry. Adjust usages. Issue: #825 Reported-by: @DanielKinsman
Diffstat (limited to 'options/globals.cpp')
-rw-r--r--options/globals.cpp45
1 files changed, 30 insertions, 15 deletions
diff --git a/options/globals.cpp b/options/globals.cpp
index 85a6bdf2..33327090 100644
--- a/options/globals.cpp
+++ b/options/globals.cpp
@@ -9,6 +9,8 @@
namespace options::globals::detail {
+ini_ctx::ini_ctx() = default;
+
bool is_portable_installation()
{
#if defined _WIN32
@@ -23,11 +25,11 @@ saver_::~saver_()
{
if (--ctx.refcount == 0 && ctx.modifiedp)
{
- ctx.modifiedp = false;
auto& settings = *ctx.qsettings;
settings.sync();
if (settings.status() != QSettings::NoError)
qDebug() << "error with .ini file" << settings.fileName() << settings.status();
+ ctx.modifiedp = false;
}
ctx.mtx.unlock();
}
@@ -41,7 +43,6 @@ ini_ctx& cur_settings()
{
static ini_ctx ini;
const QString pathname = ini_pathname();
- static QString ini_pathname;
ini.mtx.lock();
@@ -51,7 +52,7 @@ ini_ctx& cur_settings()
ini.pathname = pathname;
}
- if (pathname != ini_pathname)
+ if (ini.pathname != pathname)
{
ini.qsettings.emplace(pathname, QSettings::IniFormat);
ini.pathname = pathname;
@@ -66,15 +67,20 @@ ini_ctx& global_settings()
ini.mtx.lock();
- if (!is_portable_installation())
- // Windows registry or xdg on Linux
- ini.qsettings.emplace(OPENTRACK_ORG);
- else
+ if (ini.pathname.isEmpty())
{
- static const QString pathname = OPENTRACK_BASE_PATH + QStringLiteral("/globals.ini");
- // file in executable's directory
- ini.qsettings.emplace(pathname, QSettings::IniFormat);
- ini.pathname = pathname;
+ if (!is_portable_installation())
+ // Windows registry or xdg on Linux
+ ini.qsettings.emplace(OPENTRACK_ORG);
+ else
+ {
+ static const QString pathname = OPENTRACK_BASE_PATH + QStringLiteral("/globals.ini");
+ // file in executable's directory
+ ini.qsettings.emplace(pathname, QSettings::IniFormat);
+ ini.pathname = pathname;
+ }
+
+ ini.pathname = "placeholder";
}
return ini;
@@ -85,6 +91,16 @@ ini_ctx& global_settings()
namespace options::globals
{
+using namespace detail;
+
+bool is_ini_modified()
+{
+ ini_ctx& ini = cur_settings();
+ bool ret = ini.modifiedp;
+ ini.mtx.unlock();
+ return ret;
+}
+
QString ini_filename()
{
return with_global_settings_object([&](QSettings& settings) {
@@ -119,11 +135,10 @@ QStringList ini_list()
return list;
}
-void mark_ini_modified()
+void mark_ini_modified(bool value)
{
- using namespace detail;
auto& ini = cur_settings();
- ini.modifiedp = true;
+ ini.modifiedp = value;
ini.mtx.unlock();
}
@@ -138,7 +153,7 @@ QString ini_directory()
static const QString subdir = "ini";
if (!QDir(dir).mkpath(subdir))
- return QString();
+ return {};
return dir + '/' + subdir;
}