summaryrefslogtreecommitdiffhomepage
path: root/options
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2016-09-16 17:39:15 +0200
committerStanislaw Halik <sthalik@misaki.pl>2016-09-16 17:54:12 +0200
commitaf8d6f769c26d4d260d6fc430165b51aebbd0733 (patch)
tree2129d44b18bc919b339d7bfd9de9da6b3c921669 /options
parenta781170550b4354e0f5551e0b20560d84e4108ce (diff)
gui/main-window: exit program when config not writable
Note, it opens the config in read-write mode to check if it's writable. This might present a race condition when config is saved. However, we're expecting all config saving to be done in the user interface thread. Add a check for it however.
Diffstat (limited to 'options')
-rw-r--r--options/bundle.cpp6
-rw-r--r--options/group.cpp13
-rw-r--r--options/group.hpp1
3 files changed, 18 insertions, 2 deletions
diff --git a/options/bundle.cpp b/options/bundle.cpp
index e4c0ffbd..482e46d1 100644
--- a/options/bundle.cpp
+++ b/options/bundle.cpp
@@ -1,6 +1,9 @@
#include "bundle.hpp"
#include "value.hpp"
+#include <QThread>
+#include <QApplication>
+
using options::base_value;
namespace options
@@ -58,6 +61,9 @@ bool bundle::contains(const QString &name) const
void bundle::save_deferred(QSettings& s)
{
+ if (QThread::currentThread() != qApp->thread())
+ qCritical() << "group::save - current thread not ui thread";
+
if (group_name.size() == 0)
return;
diff --git a/options/group.cpp b/options/group.cpp
index 94e111aa..a17f185c 100644
--- a/options/group.cpp
+++ b/options/group.cpp
@@ -2,6 +2,7 @@
#include "defs.hpp"
#include <QStandardPaths>
#include <QDir>
+
#include <QDebug>
namespace options {
@@ -48,7 +49,7 @@ void group::put(const QString &s, const QVariant &d)
bool group::contains(const QString &s) const
{
- return kvs.count(s) != 0;
+ return kvs.find(s) != kvs.cend();
}
QString group::ini_directory()
@@ -64,7 +65,10 @@ QString group::ini_directory()
QString group::ini_filename()
{
QSettings settings(OPENTRACK_ORG);
- return settings.value(OPENTRACK_CONFIG_FILENAME_KEY, OPENTRACK_DEFAULT_CONFIG).toString();
+ const QString ret = settings.value(OPENTRACK_CONFIG_FILENAME_KEY, OPENTRACK_DEFAULT_CONFIG).toString();
+ if (ret.size() == 0)
+ return OPENTRACK_DEFAULT_CONFIG;
+ return ret;
}
QString group::ini_pathname()
@@ -75,6 +79,11 @@ QString group::ini_pathname()
return dir + "/" + ini_filename();
}
+QString group::ini_combine(const QString& filename)
+{
+ return ini_directory() + QStringLiteral("/") + filename;
+}
+
QStringList group::ini_list()
{
const auto dirname = ini_directory();
diff --git a/options/group.hpp b/options/group.hpp
index f5b3e523..82b508af 100644
--- a/options/group.hpp
+++ b/options/group.hpp
@@ -26,6 +26,7 @@ public:
static QString ini_directory();
static QString ini_filename();
static QString ini_pathname();
+ static QString ini_combine(const QString& filename);
static QStringList ini_list();
static std::shared_ptr<QSettings> ini_file();