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)
{
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, &notificationsEnabled);
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;
}

View file

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