From 67add6a37f9ab5de81b2e787f77aade39e01b176 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 26 Feb 2017 14:03:47 +0100 Subject: installing config file --- src/settings.cpp | 23 +++++++++++++++++------ src/settings.h | 2 ++ 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/settings.cpp b/src/settings.cpp index efaed6f..7a08061 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -24,16 +24,26 @@ Settings::Settings(const QString &configFile) { - path = configFile; std::ifstream ifs(configFile.toStdString().c_str()); - toml::ParseResult pr = toml::parse(ifs); + if(ifs.is_open()) { + toml::ParseResult pr = toml::parse(ifs); + + if(!pr.valid()) { + qWarning("Invalid configuration: %s", pr.errorReason.c_str()); + return; + } + + v = pr.value; + ifs.close(); - if(!pr.valid()) { - qWarning("Invalid configuration: %s", pr.errorReason.c_str()); + } else { + qWarning("Cannot open configuration: %s", qUtf8Printable(configFile)); return; } - v = pr.value; + path = configFile; + homeLocation = QStandardPaths::writableLocation(QStandardPaths::HomeLocation); + settingsLocation = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation); } Settings::~Settings() @@ -104,7 +114,8 @@ QVariant Settings::value(const QString &key, const QVariant &defaultValue) const // check if key is a path, in which case replace '~' with the home location if(key.endsWith(QLatin1String("path"), Qt::CaseInsensitive)) { QString value = r.toString(); - value.replace('~', QStandardPaths::writableLocation(QStandardPaths::HomeLocation)); + value.replace("~settings", settingsLocation); + value.replace('~', homeLocation); r = QVariant(value); } diff --git a/src/settings.h b/src/settings.h index b536d62..12c508b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -40,6 +40,8 @@ private: toml::Value v; QString path; + QString homeLocation; + QString settingsLocation; }; #endif // SETTINGS_H -- cgit v1.2.1