Make sure that the same config file is used with the daemon

This commit is contained in:
Matti Viljanen 2020-04-26 11:33:46 +03:00
parent 542a5b7636
commit 1ee2d9e708
No known key found for this signature in database
GPG key ID: CF32A1495158F888
2 changed files with 14 additions and 11 deletions

View file

@ -19,16 +19,19 @@
Settings::Settings(QObject *parent) : QObject(parent) Settings::Settings(QObject *parent) : QObject(parent)
{ {
mySettings = new QSettings("harbour-batterybuddy", "harbour-batterybuddy");
qDebug() << "Using" << mySettings->fileName();
// Migrate old settings // Migrate old settings
if(mySettings.contains("lowerLimit")) { if(mySettings->contains("lowerLimit")) {
mySettings.setValue(sLowAlert, mySettings.value("lowerLimit")); mySettings->setValue(sLowAlert, mySettings->value("lowerLimit"));
mySettings.remove("lowerLimit"); mySettings->remove("lowerLimit");
qInfo() << "Migrated old lowerLimit value"; qInfo() << "Migrated old lowerLimit value";
} }
if(mySettings.contains("upperLimit")) { if(mySettings->contains("upperLimit")) {
mySettings.setValue(sHighAlert, mySettings.value("upperLimit")); mySettings->setValue(sHighAlert, mySettings->value("upperLimit"));
mySettings.remove("upperLimit"); mySettings->remove("upperLimit");
qInfo() << "Migrated old upperLimit value"; qInfo() << "Migrated old upperLimit value";
} }
@ -52,8 +55,8 @@ Settings::~Settings()
saveInteger(sNotificationsEnabled, &notificationsEnabled); saveInteger(sNotificationsEnabled, &notificationsEnabled);
saveInteger(sLowLimit, &lowLimit); saveInteger(sLowLimit, &lowLimit);
saveInteger(sHighLimit, &highLimit); saveInteger(sHighLimit, &highLimit);
mySettings.sync(); mySettings->sync();
qInfo() << "Settings saved:" << (mySettings.status() == QSettings::NoError); qInfo() << "Settings saved:" << (mySettings->status() == QSettings::NoError);
} }
int Settings::getLowAlert() { 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) { 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; qInfo() << "Loaded" << key << *value;
} }
void Settings::saveInteger(const char* key, int *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; qInfo() << "Saved" << key << *value;
} }

View file

@ -59,7 +59,7 @@ public:
private: private:
QSettings mySettings; QSettings *mySettings;
// Default values // Default values
int lowAlert = 25; int lowAlert = 25;