From 1ee2d9e7081aea09259bd165244e44efc3e2e654 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Sun, 26 Apr 2020 11:33:46 +0300 Subject: [PATCH] Make sure that the same config file is used with the daemon --- application/src/settings.cpp | 23 +++++++++++++---------- application/src/settings.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/application/src/settings.cpp b/application/src/settings.cpp index d3f2c49..ce215c0 100644 --- a/application/src/settings.cpp +++ b/application/src/settings.cpp @@ -19,16 +19,19 @@ Settings::Settings(QObject *parent) : QObject(parent) { + mySettings = new QSettings("harbour-batterybuddy", "harbour-batterybuddy"); + qDebug() << "Using" << mySettings->fileName(); + // Migrate old settings - if(mySettings.contains("lowerLimit")) { - mySettings.setValue(sLowAlert, mySettings.value("lowerLimit")); - mySettings.remove("lowerLimit"); + if(mySettings->contains("lowerLimit")) { + mySettings->setValue(sLowAlert, mySettings->value("lowerLimit")); + mySettings->remove("lowerLimit"); qInfo() << "Migrated old lowerLimit value"; } - if(mySettings.contains("upperLimit")) { - mySettings.setValue(sHighAlert, mySettings.value("upperLimit")); - mySettings.remove("upperLimit"); + if(mySettings->contains("upperLimit")) { + mySettings->setValue(sHighAlert, mySettings->value("upperLimit")); + mySettings->remove("upperLimit"); qInfo() << "Migrated old upperLimit value"; } @@ -52,8 +55,8 @@ Settings::~Settings() saveInteger(sNotificationsEnabled, ¬ificationsEnabled); saveInteger(sLowLimit, &lowLimit); saveInteger(sHighLimit, &highLimit); - mySettings.sync(); - qInfo() << "Settings saved:" << (mySettings.status() == QSettings::NoError); + mySettings->sync(); + qInfo() << "Settings saved:" << (mySettings->status() == QSettings::NoError); } int Settings::getLowAlert() { @@ -140,11 +143,11 @@ int Settings::bound(int value, int min, int max) { } void Settings::loadInteger(const char* key, int *value, int min, int max) { - *value = bound(mySettings.value(key, *value).toInt(), min, max); + *value = bound(mySettings->value(key, *value).toInt(), min, max); qInfo() << "Loaded" << key << *value; } void Settings::saveInteger(const char* key, int *value) { - mySettings.setValue(key, QByteArray::number(*value)); + mySettings->setValue(key, QByteArray::number(*value)); qInfo() << "Saved" << key << *value; } diff --git a/application/src/settings.h b/application/src/settings.h index 59c788f..1171f9c 100644 --- a/application/src/settings.h +++ b/application/src/settings.h @@ -59,7 +59,7 @@ public: private: - QSettings mySettings; + QSettings *mySettings; // Default values int lowAlert = 25;