From 0b903ef40b727181fcf38356fd2486212973dae9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 31 May 2019 17:43:04 +0200 Subject: Fix .conf file reading, add messages/warnings --- src/config.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/config.cpp') diff --git a/src/config.cpp b/src/config.cpp index 63630d0..1689b00 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -5,6 +5,7 @@ #include #include #include +#include static QCommandLineParser parser; static QSettings* configFile = nullptr; @@ -81,8 +82,16 @@ bool Config::isSet(const ConfigOption* const option) return false; if (parser.isSet(option->cmdLine)) return true; - if (configFile != nullptr && !option->iniKey.isEmpty()) - return !configFile->value(option->iniKey, option->defaultValue).isNull(); + if (configFile != nullptr && !option->iniKey.isEmpty() && configFile->contains(option->iniKey)) { + // Option present in ini... + if (option->withArgument) // ...and needs an argument -> set either way + return true; + // If it doesn't require an argument, special case + QString val = configFile->value(option->iniKey).toString().toLower(); + if (!val.isEmpty() && val != QLatin1String("false") && val != QLatin1String("0") && val != QLatin1String("no") && val != QLatin1String("off")) + return true; // Everything except empty string, "false", "0", "no" and "off" is considered as "is set" + // Fall though otherwise + } return false; } @@ -93,10 +102,13 @@ bool Config::init(const QCoreApplication& app, const ConfigOption* const configF parser.process(app); if (configFileName != nullptr && parser.isSet(configFileName->cmdLine)) { QString file(parser.value(configFileName->cmdLine)); - if (!QFileInfo(file).exists()) + if (!QFileInfo(file).exists()) { + qDebug() << "--config file" << file << "does not exist!"; return false; + } configFile = new QSettings(file, QSettings::IniFormat); configFile->setIniCodec("UTF-8"); + qDebug() << "Using config file" << file; } return true; } -- cgit v1.2.3-55-g7522