From b94df34839b90ff5133c213a363b79c6aa34f974 Mon Sep 17 00:00:00 2001 From: Matti Viljanen Date: Mon, 30 Nov 2020 22:58:37 +0200 Subject: [PATCH] Remove redundant high/low notification enabled --- application/qml/pages/SettingsPage.qml | 12 ---------- application/src/settings.cpp | 22 ------------------- application/src/settings.h | 16 ++------------ .../harbour-batterybuddy-de_DE.ts | 8 ------- .../translations/harbour-batterybuddy-fi.ts | 8 ------- .../translations/harbour-batterybuddy-fr.ts | 8 ------- .../translations/harbour-batterybuddy-pl.ts | 8 ------- .../translations/harbour-batterybuddy-sv.ts | 8 ------- .../harbour-batterybuddy-zh_CN.ts | 8 ------- .../translations/harbour-batterybuddy.ts | 8 ------- service/src/battery.cpp | 8 +++---- service/src/settings.cpp | 22 ++++++++++++++----- service/src/settings.h | 4 ---- 13 files changed, 22 insertions(+), 118 deletions(-) diff --git a/application/qml/pages/SettingsPage.qml b/application/qml/pages/SettingsPage.qml index 288032c..798c917 100644 --- a/application/qml/pages/SettingsPage.qml +++ b/application/qml/pages/SettingsPage.qml @@ -36,8 +36,6 @@ Page { autoStopCharging.checked = settings.limitEnabled highLimitSlider.value = settings.highLimit lowLimitSlider.value = settings.lowLimit - highNotificationsSwitch.checked = settings.highNotificationsEnabled - lowNotificationsSwitch.checked = settings.lowNotificationsEnabled highAlertSlider.value = settings.highAlert lowAlertSlider.value = settings.lowAlert highIntervalSlider.value = settings.highNotificationsInterval @@ -220,16 +218,6 @@ Page { wrapMode: Text.Wrap } - TextSwitch { - id: highNotificationsSwitch - text: qsTr("Show high charge notification") - onCheckedChanged: settings.highNotificationsEnabled = checked - } - TextSwitch { - id: lowNotificationsSwitch - text: qsTr("Show low charge notification") - onCheckedChanged: settings.lowNotificationsEnabled = checked - } Slider { id: highAlertSlider width: parent.width diff --git a/application/src/settings.cpp b/application/src/settings.cpp index 5f0337a..680441d 100644 --- a/application/src/settings.cpp +++ b/application/src/settings.cpp @@ -28,8 +28,6 @@ Settings::Settings(QObject *parent) : QObject(parent) loadInteger(sHighNotificationsInterval, &highNotificationsInterval, 50, 610); loadInteger(sLowNotificationsInterval, &lowNotificationsInterval, 50, 610); loadInteger(sLimitEnabled, &limitEnabled, 0, 1); - loadInteger(sHighNotificationsEnabled, &highNotificationsEnabled, 0, 1); - loadInteger(sLowNotificationsEnabled, &lowNotificationsEnabled, 0, 1); loadInteger(sLowLimit, &lowLimit, 20, 94); loadInteger(sHighLimit, &highLimit, 21, 95); @@ -45,8 +43,6 @@ Settings::~Settings() saveInteger(sHighNotificationsInterval, &highNotificationsInterval); saveInteger(sLowNotificationsInterval, &lowNotificationsInterval); saveInteger(sLimitEnabled, &limitEnabled); - saveInteger(sHighNotificationsEnabled, &highNotificationsEnabled); - saveInteger(sLowNotificationsEnabled, &lowNotificationsEnabled); saveInteger(sLowLimit, &lowLimit); saveInteger(sHighLimit, &highLimit); mySettings->setValue(sNotificationTitle, notificationTitle); @@ -64,8 +60,6 @@ int Settings::getLowNotificationsInterval() { return lowNotificationsInterv int Settings::getLowLimit() { return lowLimit; } int Settings::getHighLimit() { return highLimit; } bool Settings::getLimitEnabled() { return limitEnabled == 1; } -bool Settings::getHighNotificationsEnabled() { return highNotificationsEnabled == 1; } -bool Settings::getLowNotificationsEnabled() { return lowNotificationsEnabled == 1; } QString Settings::getLowAlertFile() { return lowAlertFile; } QString Settings::getHighAlertFile() { return highAlertFile; } QString Settings::getNotificationTitle() { return notificationTitle; } @@ -130,22 +124,6 @@ void Settings::setLimitEnabled(bool newEnabled) { qDebug() << sLimitEnabled << newEnabled; } -void Settings::setHighNotificationsEnabled(bool newEnabled) { - highNotificationsEnabled = (newEnabled ? 1 : 0); - saveInteger(sHighNotificationsEnabled, &highNotificationsEnabled); - mySettings->sync(); - emit highNotificationsEnabledChanged(highNotificationsEnabled); - qDebug() << sHighNotificationsEnabled << newEnabled; -} - -void Settings::setLowNotificationsEnabled(bool newEnabled) { - lowNotificationsEnabled = (newEnabled ? 1 : 0); - saveInteger(sLowNotificationsEnabled, &lowNotificationsEnabled); - mySettings->sync(); - emit lowNotificationsEnabledChanged(lowNotificationsEnabled); - qDebug() << sLowNotificationsEnabled << newEnabled; -} - void Settings::setNotificationTitle(QString newText) { notificationTitle = newText; mySettings->setValue(sNotificationTitle, notificationTitle); diff --git a/application/src/settings.h b/application/src/settings.h index 8cb468b..59443b0 100644 --- a/application/src/settings.h +++ b/application/src/settings.h @@ -25,17 +25,15 @@ class Settings : public QObject { Q_OBJECT - Q_PROPERTY(int lowAlert READ getLowAlert WRITE setLowAlert NOTIFY lowAlertChanged) Q_PROPERTY(int highAlert READ getHighAlert WRITE setHighAlert NOTIFY highAlertChanged) + Q_PROPERTY(int lowAlert READ getLowAlert WRITE setLowAlert NOTIFY lowAlertChanged) Q_PROPERTY(int highNotificationsInterval READ getHighNotificationsInterval WRITE setHighNotificationsInterval NOTIFY highNotificationsIntervalChanged) Q_PROPERTY(int lowNotificationsInterval READ getLowNotificationsInterval WRITE setLowNotificationsInterval NOTIFY lowNotificationsIntervalChanged) Q_PROPERTY(int highLimit READ getHighLimit WRITE setHighLimit NOTIFY highLimitChanged) Q_PROPERTY(int lowLimit READ getLowLimit WRITE setLowLimit NOTIFY lowLimitChanged) Q_PROPERTY(bool limitEnabled READ getLimitEnabled WRITE setLimitEnabled NOTIFY limitEnabledChanged) - Q_PROPERTY(bool highNotificationsEnabled READ getHighNotificationsEnabled WRITE setHighNotificationsEnabled NOTIFY highNotificationsEnabledChanged) - Q_PROPERTY(bool lowNotificationsEnabled READ getLowNotificationsEnabled WRITE setLowNotificationsEnabled NOTIFY lowNotificationsEnabledChanged) - Q_PROPERTY(QString lowAlertFile READ getLowAlertFile NOTIFY lowAlertFileChanged) Q_PROPERTY(QString highAlertFile READ getHighAlertFile NOTIFY highAlertFileChanged) + Q_PROPERTY(QString lowAlertFile READ getLowAlertFile NOTIFY lowAlertFileChanged) Q_PROPERTY(QString notificationTitle READ getNotificationTitle WRITE setNotificationTitle NOTIFY notificationTitleChanged) Q_PROPERTY(QString notificationLowText READ getNotificationLowText WRITE setNotificationLowText NOTIFY notificationLowTextChanged) Q_PROPERTY(QString notificationHighText READ getNotificationHighText WRITE setNotificationHighText NOTIFY notificationHighTextChanged) @@ -51,8 +49,6 @@ public: int getLowLimit(); int getHighLimit(); bool getLimitEnabled(); - bool getHighNotificationsEnabled(); - bool getLowNotificationsEnabled(); QString getLowAlertFile(); QString getHighAlertFile(); QString getNotificationTitle(); @@ -66,8 +62,6 @@ public: void setLowLimit(int newLimit); void setHighLimit(int newLimit); void setLimitEnabled(bool newEnabled); - void setHighNotificationsEnabled(bool newEnabled); - void setLowNotificationsEnabled(bool newEnabled); void setNotificationTitle(QString newText); void setNotificationLowText(QString newText); void setNotificationHighText(QString newText); @@ -81,8 +75,6 @@ private: int highNotificationsInterval = 60; int lowNotificationsInterval = 60; int limitEnabled = 0; // Converted to boolean for QML - int highNotificationsEnabled = 1; // Converted to boolean for QML - int lowNotificationsEnabled = 1; // Converted to boolean for QML int lowLimit = 65; int highLimit = 70; QString lowAlertFile = "/usr/share/sounds/jolla-ambient/stereo/general_warning.wav"; @@ -97,8 +89,6 @@ private: const char* sHighNotificationsInterval = "highNotificationsInterval"; const char* sLowNotificationsInterval = "lowNotificationsInterval"; const char* sLimitEnabled = "limitEnabled"; - const char* sHighNotificationsEnabled = "highNotificationsEnabled"; - const char* sLowNotificationsEnabled = "lowNotificationsEnabled"; const char* sLowLimit = "lowLimit"; const char* sHighLimit = "highLimit"; const char* sLowAlertFile = "lowAlertFile"; @@ -117,8 +107,6 @@ signals: void highNotificationsIntervalChanged(int); void lowNotificationsIntervalChanged(int); void limitEnabledChanged(bool); - void highNotificationsEnabledChanged(bool); - void lowNotificationsEnabledChanged(bool); void lowLimitChanged(int); void highLimitChanged(int); void lowAlertFileChanged(QString); diff --git a/application/translations/harbour-batterybuddy-de_DE.ts b/application/translations/harbour-batterybuddy-de_DE.ts index b25cfff..172f14f 100644 --- a/application/translations/harbour-batterybuddy-de_DE.ts +++ b/application/translations/harbour-batterybuddy-de_DE.ts @@ -314,14 +314,6 @@ Start background service at startup Starte den Hintergrunddienst beim Einschalten - - Show high charge notification - Zeige Hinweis, wenn der Akku voll ist - - - Show low charge notification - Zeige Hinweis, wenn der Akku leer ist - Battery high notification interval Intervall für Hinweis "battery voll" diff --git a/application/translations/harbour-batterybuddy-fi.ts b/application/translations/harbour-batterybuddy-fi.ts index 9d4e9cb..5d08998 100644 --- a/application/translations/harbour-batterybuddy-fi.ts +++ b/application/translations/harbour-batterybuddy-fi.ts @@ -310,14 +310,6 @@ Start background service at startup Käynnistä taustapalvelu kun puhelin käynnistyy - - Show high charge notification - Näytä korkean varauksen ilmoitukset - - - Show low charge notification - Näytä matalan varauksen ilmoitukset - Battery high notification interval Korkean varauksen ilmoituksen aikaväli diff --git a/application/translations/harbour-batterybuddy-fr.ts b/application/translations/harbour-batterybuddy-fr.ts index 094c73f..c1a76ff 100644 --- a/application/translations/harbour-batterybuddy-fr.ts +++ b/application/translations/harbour-batterybuddy-fr.ts @@ -310,14 +310,6 @@ Start background service at startup - - Show high charge notification - - - - Show low charge notification - - Battery high notification interval diff --git a/application/translations/harbour-batterybuddy-pl.ts b/application/translations/harbour-batterybuddy-pl.ts index b89038a..f454f50 100644 --- a/application/translations/harbour-batterybuddy-pl.ts +++ b/application/translations/harbour-batterybuddy-pl.ts @@ -310,14 +310,6 @@ Start background service at startup Uruchom proces w tle podczas uruchomienia - - Show high charge notification - Pokaż powiadomienie o wysokim poziomie naładowania - - - Show low charge notification - Pokaż powiadomienie o niskim poziomie naładowania - Battery high notification interval Interwał powiadamiania o wysokim poziomie naładowania diff --git a/application/translations/harbour-batterybuddy-sv.ts b/application/translations/harbour-batterybuddy-sv.ts index 2245b90..ba5a6eb 100644 --- a/application/translations/harbour-batterybuddy-sv.ts +++ b/application/translations/harbour-batterybuddy-sv.ts @@ -310,14 +310,6 @@ Start background service at startup - - Show high charge notification - - - - Show low charge notification - - Battery high notification interval diff --git a/application/translations/harbour-batterybuddy-zh_CN.ts b/application/translations/harbour-batterybuddy-zh_CN.ts index 6c19c68..cf91a64 100644 --- a/application/translations/harbour-batterybuddy-zh_CN.ts +++ b/application/translations/harbour-batterybuddy-zh_CN.ts @@ -312,14 +312,6 @@ Start background service at startup 启动时开始后台服务 - - Show high charge notification - 显示高充电通知 - - - Show low charge notification - 显示低电量通知 - Battery high notification interval 电池电量高通知区间 diff --git a/application/translations/harbour-batterybuddy.ts b/application/translations/harbour-batterybuddy.ts index 5b88664..6ae7ead 100644 --- a/application/translations/harbour-batterybuddy.ts +++ b/application/translations/harbour-batterybuddy.ts @@ -310,14 +310,6 @@ Start background service at startup - - Show high charge notification - - - - Show low charge notification - - Battery high notification interval diff --git a/service/src/battery.cpp b/service/src/battery.cpp index 392d9e9..0e85c1a 100644 --- a/service/src/battery.cpp +++ b/service/src/battery.cpp @@ -163,7 +163,7 @@ void Battery::resetTimers() { } void Battery::showHighNotification() { - if(settings->getHighNotificationsEnabled() && (charge >= settings->getHighAlert() && state != "discharging") + if(settings->getHighNotificationsInterval() < 610 && (charge >= settings->getHighAlert() && state != "discharging") && !(charge == 100 && state == "idle")) { qDebug() << "Battery notification timer: full enough battery"; notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationHighText(), settings->getHighAlertFile()); @@ -179,7 +179,7 @@ void Battery::showHighNotification() { } void Battery::showLowNotification() { - if(settings->getLowNotificationsEnabled() && charge <= settings->getLowAlert() && state != "charging") { + if(settings->getLowNotificationsInterval() < 610 && charge <= settings->getLowAlert() && state != "charging") { qDebug() << "Battery notification timer: empty enough battery"; notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile()); if(settings->getLowNotificationsInterval() == 50) { @@ -194,12 +194,12 @@ void Battery::showLowNotification() { } void Battery::updateNotification() { - if(settings->getHighNotificationsEnabled() && (charge >= settings->getHighAlert() && state != "discharging") + if(settings->getHighNotificationsInterval() < 610 && (charge >= settings->getHighAlert() && state != "discharging") && !(charge == 100 && state == "idle")) { qDebug() << "Battery notification timer: full enough battery"; notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationHighText(), settings->getHighAlertFile()); } - else if(settings->getLowNotificationsEnabled() && charge <= settings->getLowAlert() && state != "charging") { + else if(settings->getLowNotificationsInterval() < 610 && charge <= settings->getLowAlert() && state != "charging") { qDebug() << "Battery notification timer: empty enough battery"; notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile()); } diff --git a/service/src/settings.cpp b/service/src/settings.cpp index b99213c..3a41322 100644 --- a/service/src/settings.cpp +++ b/service/src/settings.cpp @@ -40,9 +40,9 @@ Settings::Settings(QObject *parent) : QObject(parent) } if(mySettings->contains("notificationsEnabled")) { - mySettings->setValue(sHighNotificationsEnabled, mySettings->value("notificationsEnabled")); + mySettings->setValue("highNotificationsEnabled", mySettings->value("notificationsEnabled")); mySettings->remove("notificationsEnabled"); - qInfo() << "Migrated old upperLimit value"; + qInfo() << "Migrated old notificationsEnabled value"; } if(mySettings->contains("interval")) { @@ -52,6 +52,20 @@ Settings::Settings(QObject *parent) : QObject(parent) qInfo() << "Migrated old notification interval value"; } + if(mySettings->contains("highNotificationsEnabled")) { + if(mySettings->value("highNotificationsEnabled").toInt() == 0) + mySettings->setValue(sHighNotificationsInterval, 610); + mySettings->remove("highNotificationsEnabled"); + qInfo() << "Migrated old highNotificationsEnabled value"; + } + + if(mySettings->contains("lowNotificationsEnabled")) { + if(mySettings->value("lowNotificationsEnabled").toInt() == 0) + mySettings->setValue(sLowNotificationsInterval, 610); + mySettings->remove("lowNotificationsEnabled"); + qInfo() << "Migrated old lowNotificationsEnabled value"; + } + // Do this here, because... watcher = new QFileSystemWatcher(QStringList(mySettings->fileName())); connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(updateConfig(QString))); @@ -99,8 +113,6 @@ void Settings::updateConfig(QString path) { restartTimers |= loadInteger(sHighNotificationsInterval, &highNotificationsInterval, 50, 610); restartTimers |= loadInteger(sLowNotificationsInterval, &lowNotificationsInterval, 50, 610); loadInteger(sLimitEnabled, &limitEnabled, 0, 1); - restartTimers |= loadInteger(sHighNotificationsEnabled, &highNotificationsEnabled, 0, 1); - restartTimers |= loadInteger(sLowNotificationsEnabled, &lowNotificationsEnabled, 0, 1); loadInteger(sLowLimit, &lowLimit, 20, 94); loadInteger(sHighLimit, &highLimit, 21, 95); @@ -139,8 +151,6 @@ int Settings::getLowNotificationsInterval() { return lowNotificationsInterv int Settings::getLowLimit() { return lowLimit; } int Settings::getHighLimit() { return highLimit; } bool Settings::getLimitEnabled() { return limitEnabled == 1; } -bool Settings::getHighNotificationsEnabled() { return highNotificationsEnabled == 1; } -bool Settings::getLowNotificationsEnabled() { return lowNotificationsEnabled == 1; } QString Settings::getLowAlertFile() { return lowAlertFile; } QString Settings::getHighAlertFile() { return highAlertFile; } QString Settings::getNotificationTitle() { return notificationTitle; } diff --git a/service/src/settings.h b/service/src/settings.h index e3e5bbe..cdc0deb 100644 --- a/service/src/settings.h +++ b/service/src/settings.h @@ -61,8 +61,6 @@ private: // Converted to boolean for QML int limitEnabled = 0; - int highNotificationsEnabled = 1; // Converted to boolean for QML - int lowNotificationsEnabled = 1; // Converted to boolean for QML int daemonEnabled = 1; int lowLimit = 65; @@ -79,8 +77,6 @@ private: const char* sHighNotificationsInterval = "highNotificationsInterval"; const char* sLowNotificationsInterval = "lowNotificationsInterval"; const char* sLimitEnabled = "limitEnabled"; - const char* sHighNotificationsEnabled = "highNotificationsEnabled"; - const char* sLowNotificationsEnabled = "lowNotificationsEnabled"; const char* sLowLimit = "lowLimit"; const char* sHighLimit = "highLimit"; const char* sLowAlertFile = "lowAlertFile";