aboutsummaryrefslogtreecommitdiff
path: root/lib/configuration
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-03-21 13:29:41 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2018-03-21 13:29:41 +0100
commitbb5574831aef42b2f81979c1df8f706d3956bdca (patch)
tree7ad31ba13d86e4501631391a70698e146848e268 /lib/configuration
parentUpdate manpage (diff)
downloadsmolbote-bb5574831aef42b2f81979c1df8f706d3956bdca.tar.xz
poi-config saving config
Diffstat (limited to 'lib/configuration')
-rw-r--r--lib/configuration/configuration.cpp17
-rw-r--r--lib/configuration/configuration.h2
2 files changed, 16 insertions, 3 deletions
diff --git a/lib/configuration/configuration.cpp b/lib/configuration/configuration.cpp
index c114155..c9bae90 100644
--- a/lib/configuration/configuration.cpp
+++ b/lib/configuration/configuration.cpp
@@ -81,14 +81,25 @@ Configuration::Configuration()
// store the defaults into the vm
{
- const char* argv[0];
+ const char *argv[0];
po::store(po::parse_command_line(0, argv, desc), vm);
}
-
}
Configuration::~Configuration() = default;
+QString Configuration::defaultUserConfigLocation()
+{
+ // try to locate an existing config
+ QString path = QStandardPaths::locate(QStandardPaths::ConfigLocation, "smolbote/smolbote.cfg");
+
+ // it's possible there is no config, so set the path properly
+ if(path.isEmpty())
+ path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/smolbote/smolbote.cfg";
+
+ return path;
+}
+
bool Configuration::read(const QString &path)
{
std::ifstream f(path.toStdString(), std::ifstream::in);
@@ -100,7 +111,7 @@ bool Configuration::parse(int argc, const char **argv)
{
try {
po::store(po::parse_command_line(argc, argv, desc), vm);
- } catch (const po::error &e) {
+ } catch(const po::error &e) {
return false;
}
diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h
index 4d58a90..c8fcdff 100644
--- a/lib/configuration/configuration.h
+++ b/lib/configuration/configuration.h
@@ -22,6 +22,8 @@ public:
explicit Configuration();
~Configuration();
+ static QString defaultUserConfigLocation();
+
bool read(const QString &path);
bool parse(int argc, const char **argv);