diff options
-rw-r--r-- | data/poi.conf (renamed from test/config.toml) | 4 | ||||
-rw-r--r-- | smolbote.qbs | 12 | ||||
-rw-r--r-- | src/settings.cpp | 23 | ||||
-rw-r--r-- | src/settings.h | 2 |
4 files changed, 31 insertions, 10 deletions
diff --git a/test/config.toml b/data/poi.conf index 7542755..aec03e9 100644 --- a/test/config.toml +++ b/data/poi.conf @@ -8,7 +8,7 @@ [browser] singleInstance=true localSocket="smolbote-singlelock" -#lastSession="~settings/session.ini" +#sessionPath="~settings/session.ini" # Main window settings [window] @@ -37,7 +37,7 @@ tabtoolbarMovable=false homepage="https://duckduckgo.com" newtab="about:blank" profile="Default" -#search="https://duckduckgo.com/?q=$search&kp=-1" +#search="https://duckduckgo.com/?q=$term&kp=-1" # URL blocker [blocker] diff --git a/smolbote.qbs b/smolbote.qbs index 47c54d8..0d3b395 100644 --- a/smolbote.qbs +++ b/smolbote.qbs @@ -50,6 +50,7 @@ Project { defines.push('VERSION="'+git.version+'"'); return defines; } + Depends { name: "Qt"; submodules: ["core", "widgets", "webengine", "webenginewidgets"] } files: [ "data/resources.qrc", @@ -98,12 +99,19 @@ Project { "src/xbel/xbel.h", ] - Depends { name: "Qt"; submodules: ["core", "widgets", "webengine", "webenginewidgets"] } - // Properties for the produced executable Group { fileTagsFilter: product.type // filter selects produced executable qbs.install: true // install it } + + // config + Group { + name: "Configuration" + files: [ + "data/poi.conf" + ] + qbs.install: true + } } } 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 |