Remove redundant high/low notification enabled

This commit is contained in:
Matti Viljanen 2020-11-30 22:58:37 +02:00
parent aea2ef3da2
commit b94df34839
13 changed files with 22 additions and 118 deletions

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -314,14 +314,6 @@
<source>Start background service at startup</source>
<translation>Starte den Hintergrunddienst beim Einschalten</translation>
</message>
<message>
<source>Show high charge notification</source>
<translation>Zeige Hinweis, wenn der Akku voll ist</translation>
</message>
<message>
<source>Show low charge notification</source>
<translation>Zeige Hinweis, wenn der Akku leer ist</translation>
</message>
<message>
<source>Battery high notification interval</source>
<translation>Intervall für Hinweis &quot;battery voll&quot;</translation>

View file

@ -310,14 +310,6 @@
<source>Start background service at startup</source>
<translation>Käynnistä taustapalvelu kun puhelin käynnistyy</translation>
</message>
<message>
<source>Show high charge notification</source>
<translation>Näytä korkean varauksen ilmoitukset</translation>
</message>
<message>
<source>Show low charge notification</source>
<translation>Näytä matalan varauksen ilmoitukset</translation>
</message>
<message>
<source>Battery high notification interval</source>
<translation>Korkean varauksen ilmoituksen aikaväli</translation>

View file

@ -310,14 +310,6 @@
<source>Start background service at startup</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show high charge notification</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show low charge notification</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Battery high notification interval</source>
<translation type="unfinished"></translation>

View file

@ -310,14 +310,6 @@
<source>Start background service at startup</source>
<translation>Uruchom proces w tle podczas uruchomienia</translation>
</message>
<message>
<source>Show high charge notification</source>
<translation>Pokaż powiadomienie o wysokim poziomie naładowania</translation>
</message>
<message>
<source>Show low charge notification</source>
<translation>Pokaż powiadomienie o niskim poziomie naładowania</translation>
</message>
<message>
<source>Battery high notification interval</source>
<translation>Interwał powiadamiania o wysokim poziomie naładowania</translation>

View file

@ -310,14 +310,6 @@
<source>Start background service at startup</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show high charge notification</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show low charge notification</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Battery high notification interval</source>
<translation type="unfinished"></translation>

View file

@ -312,14 +312,6 @@
<source>Start background service at startup</source>
<translation></translation>
</message>
<message>
<source>Show high charge notification</source>
<translation></translation>
</message>
<message>
<source>Show low charge notification</source>
<translation></translation>
</message>
<message>
<source>Battery high notification interval</source>
<translation></translation>

View file

@ -310,14 +310,6 @@
<source>Start background service at startup</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show high charge notification</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Show low charge notification</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Battery high notification interval</source>
<translation type="unfinished"></translation>

View file

@ -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());
}

View file

@ -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; }

View file

@ -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";