aboutsummaryrefslogtreecommitdiff
path: root/src/browser.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-07-01 16:16:10 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2017-07-01 16:16:10 +0200
commitfeb69af5c8c2517ea21398810ec9c603aef3032e (patch)
tree9e62351a4874bee700b63c518fd0b1b399432049 /src/browser.cpp
parentStatus bar height capped; loading bar now hides after 2s (diff)
downloadsmolbote-feb69af5c8c2517ea21398810ec9c603aef3032e.tar.xz
Configuration defaults file
Diffstat (limited to 'src/browser.cpp')
-rw-r--r--src/browser.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/browser.cpp b/src/browser.cpp
index 9ee7315..355c24b 100644
--- a/src/browser.cpp
+++ b/src/browser.cpp
@@ -162,36 +162,43 @@ BlockerManager *Browser::blocklists()
void Browser::setConfigPath(const QString &path)
{
- // set custom config path if any
- if(!path.isEmpty()) {
- m_settings = new Settings(path);
- return;
- }
-
- // check if config file exists for this user
- QString cpath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/poi.conf";
- if(QFile::exists(cpath)) {
- m_settings = new Settings(cpath);
- }
+ QString configLocation, defaultsLocation;
+ // set defaults location
// check system-specific locations
#ifdef Q_OS_LINUX
- else if(QFile::exists("/usr/share/smolbote/poi.conf")) {
- m_settings = new Settings("/usr/share/smolbote/poi.conf");
+ if(QFile::exists("/usr/share/smolbote/poi.conf")) {
+ defaultsLocation = "/usr/share/smolbote/poi.conf";
} else if(QFile::exists("/usr/local/share/smolbote/poi.conf")) {
- m_settings = new Settings("/usr/local/share/smolbote/poi.conf");
+ defaultsLocation = "/usr/local/share/smolbote/poi.conf";
}
#endif
- else {
- m_settings = new Settings();
+ // if no default config is found, then use the built-in one
+ if(defaultsLocation.isEmpty()) {
+ defaultsLocation = ":/poi.toml";
}
+ // set custom config path if any
+ if(!path.isEmpty()) {
+ configLocation = path;
+
+ } else {
+ // check if config file exists for this user
+ QString cpath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation) + "/poi.conf";
+ if(QFile::exists(cpath)) {
+ configLocation = cpath;
+ }
+ }
+
+ m_settings = new Settings(configLocation, defaultsLocation);
+
if(m_settings->isEmpty()) {
// There are no keys in the settings
QMessageBox::information(0,
tr("Configuration is empty"),
- tr("The configuration file <i>%1</i> is empty. Using default values").arg(m_settings->filePath()));
+ tr("The configuration file <i>%1</i> is empty.<br>"
+ "Using default values from <i>%2</i>.").arg(configLocation, defaultsLocation));
}
}