diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-02-26 14:03:47 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2017-02-26 14:03:47 +0100 |
commit | 67add6a37f9ab5de81b2e787f77aade39e01b176 (patch) | |
tree | 75f05d6eab7d7cddd036c9b1410ab114d49df83a /src | |
parent | UI changes (diff) | |
download | smolbote-67add6a37f9ab5de81b2e787f77aade39e01b176.tar.xz |
installing config file
Diffstat (limited to 'src')
-rw-r--r-- | src/settings.cpp | 23 | ||||
-rw-r--r-- | src/settings.h | 2 |
2 files changed, 19 insertions, 6 deletions
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 |