aboutsummaryrefslogtreecommitdiff
path: root/src/settings.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-02-26 14:03:47 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-02-26 14:03:47 +0100
commit67add6a37f9ab5de81b2e787f77aade39e01b176 (patch)
tree75f05d6eab7d7cddd036c9b1410ab114d49df83a /src/settings.cpp
parentUI changes (diff)
downloadsmolbote-67add6a37f9ab5de81b2e787f77aade39e01b176.tar.xz
installing config file
Diffstat (limited to 'src/settings.cpp')
-rw-r--r--src/settings.cpp23
1 files changed, 17 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);
}