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 --- data/poi.conf | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ smolbote.qbs | 12 ++++++++++-- src/settings.cpp | 23 +++++++++++++++++------ src/settings.h | 2 ++ test/config.toml | 57 -------------------------------------------------------- 5 files changed, 86 insertions(+), 65 deletions(-) create mode 100644 data/poi.conf delete mode 100644 test/config.toml diff --git a/data/poi.conf b/data/poi.conf new file mode 100644 index 0000000..aec03e9 --- /dev/null +++ b/data/poi.conf @@ -0,0 +1,57 @@ +# +# poi.conf +# +# See https://gitlab.com/xiannox/smolbote/wikis/settings for options +# + +# Browser: application-wide settings +[browser] +singleInstance=true +localSocket="smolbote-singlelock" +#sessionPath="~settings/session.ini" + +# Main window settings +[window] +height=720 +width=1280 +maximized=true +title="$title — smolbote [$profile]" + +# Main window shortcuts +[window.shortcuts] +focusAddress="F4" +tabNew="Ctrl+T" +tabClose="Ctrl+X" +tabLeft="Shift+Left" +tabRight="Shift+Right" +windowNew="Ctrl+N" +windowClose="Ctrl+Q" + +# Main window UI +[window.ui] +navtoolbarMovable=false +tabtoolbarMovable=false + +# General +[general] +homepage="https://duckduckgo.com" +newtab="about:blank" +profile="Default" +#search="https://duckduckgo.com/?q=$term&kp=-1" + +# URL blocker +[blocker] +dialogShortcut="Ctrl+Shift+A" +path="blocklist.txt" +#subscriptions=[] + +# Bookmark manager +[bookmarks] +dialogShortcut="Ctrl+Shift+B" +path="bookmarks.xbel" + +# Download manager +[downloads] +dialogShortcut="Ctrl+Shift+D" +path="~/Downloads" +auto=false 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 diff --git a/test/config.toml b/test/config.toml deleted file mode 100644 index 7542755..0000000 --- a/test/config.toml +++ /dev/null @@ -1,57 +0,0 @@ -# -# poi.conf -# -# See https://gitlab.com/xiannox/smolbote/wikis/settings for options -# - -# Browser: application-wide settings -[browser] -singleInstance=true -localSocket="smolbote-singlelock" -#lastSession="~settings/session.ini" - -# Main window settings -[window] -height=720 -width=1280 -maximized=true -title="$title — smolbote [$profile]" - -# Main window shortcuts -[window.shortcuts] -focusAddress="F4" -tabNew="Ctrl+T" -tabClose="Ctrl+X" -tabLeft="Shift+Left" -tabRight="Shift+Right" -windowNew="Ctrl+N" -windowClose="Ctrl+Q" - -# Main window UI -[window.ui] -navtoolbarMovable=false -tabtoolbarMovable=false - -# General -[general] -homepage="https://duckduckgo.com" -newtab="about:blank" -profile="Default" -#search="https://duckduckgo.com/?q=$search&kp=-1" - -# URL blocker -[blocker] -dialogShortcut="Ctrl+Shift+A" -path="blocklist.txt" -#subscriptions=[] - -# Bookmark manager -[bookmarks] -dialogShortcut="Ctrl+Shift+B" -path="bookmarks.xbel" - -# Download manager -[downloads] -dialogShortcut="Ctrl+Shift+D" -path="~/Downloads" -auto=false -- cgit v1.2.1