Split high and low notification controls (fixes issue #9)
This commit is contained in:
parent
6a5945c6d9
commit
6c461c57d1
13 changed files with 321 additions and 164 deletions
|
@ -36,10 +36,12 @@ Page {
|
|||
autoStopCharging.checked = settings.limitEnabled
|
||||
highLimitSlider.value = settings.highLimit
|
||||
lowLimitSlider.value = settings.lowLimit
|
||||
notificationsSwitch.checked = settings.notificationsEnabled
|
||||
highNotificationsSwitch.checked = settings.highNotificationsEnabled
|
||||
lowNotificationsSwitch.checked = settings.lowNotificationsEnabled
|
||||
highAlertSlider.value = settings.highAlert
|
||||
lowAlertSlider.value = settings.lowAlert
|
||||
intervalSlider.value = settings.interval
|
||||
highIntervalSlider.value = settings.highNotificationsInterval
|
||||
lowIntervalSlider.value = settings.lowNotificationsInterval
|
||||
console.debug("SettingsPage values updated")
|
||||
daemonCheck.start()
|
||||
}
|
||||
|
@ -121,15 +123,41 @@ Page {
|
|||
width: isPortrait ? parent.width : parent.width / 2
|
||||
spacing: Theme.paddingMedium
|
||||
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
text: qsTr("Background service")
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
TextSwitch {
|
||||
id: daemonEnabledSwitch
|
||||
text: qsTr("Start background service at startup")
|
||||
checked: true
|
||||
onClicked: {
|
||||
busy = true
|
||||
checked = !checked
|
||||
daemonToggle.start()
|
||||
}
|
||||
}
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
text: qsTr("Charging settings")
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
Label {
|
||||
text: qsTr("This option disables charging automatically when the battery has charged above the pausing percentage and enables it again when the battery has depleted below the resuming percentage.")
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
leftMargin: Theme.horizontalPageMargin*2
|
||||
rightMargin: Theme.horizontalPageMargin
|
||||
}
|
||||
color: Theme.primaryColor
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
TextSwitch {
|
||||
id: autoStopCharging
|
||||
text: qsTr("Automatic charging control")
|
||||
description: qsTr("This option disables charging automatically when the battery has charged above the pausing percentage and enables it again when the battery has depleted below the resuming percentage.")
|
||||
onCheckedChanged: settings.limitEnabled = checked
|
||||
}
|
||||
|
||||
|
@ -180,11 +208,28 @@ Page {
|
|||
text: qsTr("Notification settings")
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
Label {
|
||||
text: qsTr("Display visual and audible notifications about reached battery charge levels, when the battery charge is below or above desired percentage.")
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
leftMargin: Theme.horizontalPageMargin*2
|
||||
rightMargin: Theme.horizontalPageMargin
|
||||
}
|
||||
color: Theme.primaryColor
|
||||
font.pixelSize: Theme.fontSizeExtraSmall
|
||||
wrapMode: Text.Wrap
|
||||
}
|
||||
|
||||
TextSwitch {
|
||||
id: notificationsSwitch
|
||||
text: qsTr("Use notifications")
|
||||
description: qsTr("Display visual and audible notifications about reached battery charge levels, when the battery charge is below or above desired percentage.")
|
||||
onCheckedChanged: settings.notificationsEnabled = checked
|
||||
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
|
||||
}
|
||||
MySlider {
|
||||
id: highAlertSlider
|
||||
|
@ -222,29 +267,24 @@ Page {
|
|||
}
|
||||
}
|
||||
MySlider {
|
||||
id: intervalSlider
|
||||
id: highIntervalSlider
|
||||
width: parent.width
|
||||
label: qsTr("Notification interval")
|
||||
label: qsTr("Battery high notification interval")
|
||||
minimumValue: 60
|
||||
maximumValue: 600
|
||||
stepSize: 10
|
||||
valueText: Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60)
|
||||
onReleased: settings.interval = value
|
||||
onReleased: settings.highNotificationsInterval = value
|
||||
}
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
text: qsTr("Background service")
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
TextSwitch {
|
||||
id: daemonEnabledSwitch
|
||||
text: qsTr("Start background service at startup")
|
||||
checked: true
|
||||
onClicked: {
|
||||
busy = true
|
||||
checked = !checked
|
||||
daemonToggle.start()
|
||||
}
|
||||
MySlider {
|
||||
id: lowIntervalSlider
|
||||
width: parent.width
|
||||
label: qsTr("Battery low notification interval")
|
||||
minimumValue: 60
|
||||
maximumValue: 600
|
||||
stepSize: 10
|
||||
valueText: Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60)
|
||||
onReleased: settings.lowNotificationsInterval = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,11 @@ Settings::Settings(QObject *parent) : QObject(parent)
|
|||
// Read in the values
|
||||
loadInteger(sLowAlert, &lowAlert, 10, 99);
|
||||
loadInteger(sHighAlert, &highAlert, 11, 100);
|
||||
loadInteger(sInterval, &interval, 60, 600);
|
||||
loadInteger(sHighNotificationsInterval, &highNotificationsInterval, 60, 600);
|
||||
loadInteger(sLowNotificationsInterval, &lowNotificationsInterval, 60, 600);
|
||||
loadInteger(sLimitEnabled, &limitEnabled, 0, 1);
|
||||
loadInteger(sNotificationsEnabled, ¬ificationsEnabled, 0, 1);
|
||||
loadInteger(sHighNotificationsEnabled, &highNotificationsEnabled, 0, 1);
|
||||
loadInteger(sLowNotificationsEnabled, &lowNotificationsEnabled, 0, 1);
|
||||
loadInteger(sLowLimit, &lowLimit, 20, 94);
|
||||
loadInteger(sHighLimit, &highLimit, 21, 95);
|
||||
|
||||
|
@ -40,9 +42,11 @@ Settings::~Settings()
|
|||
{
|
||||
saveInteger(sLowAlert, &lowAlert);
|
||||
saveInteger(sHighAlert, &highAlert);
|
||||
saveInteger(sInterval, &interval);
|
||||
saveInteger(sHighNotificationsInterval, &highNotificationsInterval);
|
||||
saveInteger(sLowNotificationsInterval, &lowNotificationsInterval);
|
||||
saveInteger(sLimitEnabled, &limitEnabled);
|
||||
saveInteger(sNotificationsEnabled, ¬ificationsEnabled);
|
||||
saveInteger(sHighNotificationsEnabled, &highNotificationsEnabled);
|
||||
saveInteger(sLowNotificationsEnabled, &lowNotificationsEnabled);
|
||||
saveInteger(sLowLimit, &lowLimit);
|
||||
saveInteger(sHighLimit, &highLimit);
|
||||
mySettings->setValue(sNotificationTitle, notificationTitle);
|
||||
|
@ -53,18 +57,20 @@ Settings::~Settings()
|
|||
}
|
||||
|
||||
// Getters condensed.
|
||||
int Settings::getLowAlert() { return lowAlert; }
|
||||
int Settings::getHighAlert() { return highAlert; }
|
||||
int Settings::getInterval() { return interval; }
|
||||
int Settings::getLowLimit() { return lowLimit; }
|
||||
int Settings::getHighLimit() { return highLimit; }
|
||||
bool Settings::getLimitEnabled() { return limitEnabled == 1; }
|
||||
bool Settings::getNotificationsEnabled() { return notificationsEnabled == 1; }
|
||||
QString Settings::getLowAlertFile() { return lowAlertFile; }
|
||||
QString Settings::getHighAlertFile() { return highAlertFile; }
|
||||
QString Settings::getNotificationTitle() { return notificationTitle; }
|
||||
QString Settings::getNotificationLowText() { return notificationLowText; }
|
||||
QString Settings::getNotificationHighText() { return notificationHighText; }
|
||||
int Settings::getLowAlert() { return lowAlert; }
|
||||
int Settings::getHighAlert() { return highAlert; }
|
||||
int Settings::getHighNotificationsInterval() { return highNotificationsInterval; }
|
||||
int Settings::getLowNotificationsInterval() { return lowNotificationsInterval; }
|
||||
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; }
|
||||
QString Settings::getNotificationLowText() { return notificationLowText; }
|
||||
QString Settings::getNotificationHighText() { return notificationHighText; }
|
||||
|
||||
void Settings::setLowAlert(int newLimit) {
|
||||
lowAlert = newLimit;
|
||||
|
@ -83,12 +89,20 @@ void Settings::setHighAlert(int newLimit) {
|
|||
qDebug() << sHighAlert << newLimit;
|
||||
}
|
||||
|
||||
void Settings::setInterval(int newInterval) {
|
||||
interval = newInterval;
|
||||
saveInteger(sInterval, &interval);
|
||||
void Settings::setHighNotificationsInterval(int newInterval) {
|
||||
highNotificationsInterval = newInterval;
|
||||
saveInteger(sHighNotificationsInterval, &highNotificationsInterval);
|
||||
mySettings->sync();
|
||||
emit intervalChanged(interval);
|
||||
qDebug() << sInterval << newInterval;
|
||||
emit highNotificationsIntervalChanged(highNotificationsInterval);
|
||||
qDebug() << sHighNotificationsInterval << newInterval;
|
||||
}
|
||||
|
||||
void Settings::setLowNotificationsInterval(int newInterval) {
|
||||
lowNotificationsInterval = newInterval;
|
||||
saveInteger(sLowNotificationsInterval, &lowNotificationsInterval);
|
||||
mySettings->sync();
|
||||
emit highNotificationsIntervalChanged(lowNotificationsInterval);
|
||||
qDebug() << sLowNotificationsInterval << newInterval;
|
||||
}
|
||||
|
||||
void Settings::setLowLimit(int newLimit) {
|
||||
|
@ -116,12 +130,20 @@ void Settings::setLimitEnabled(bool newEnabled) {
|
|||
qDebug() << sLimitEnabled << newEnabled;
|
||||
}
|
||||
|
||||
void Settings::setNotificationsEnabled(bool newEnabled) {
|
||||
notificationsEnabled = (newEnabled ? 1 : 0);
|
||||
saveInteger(sNotificationsEnabled, ¬ificationsEnabled);
|
||||
void Settings::setHighNotificationsEnabled(bool newEnabled) {
|
||||
highNotificationsEnabled = (newEnabled ? 1 : 0);
|
||||
saveInteger(sHighNotificationsEnabled, &highNotificationsEnabled);
|
||||
mySettings->sync();
|
||||
emit notificationsEnabledChanged(notificationsEnabled);
|
||||
qDebug() << sNotificationsEnabled << newEnabled;
|
||||
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) {
|
||||
|
|
|
@ -27,11 +27,13 @@ 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 interval READ getInterval WRITE setInterval NOTIFY intervalChanged)
|
||||
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 notificationsEnabled READ getNotificationsEnabled WRITE setNotificationsEnabled NOTIFY notificationsEnabledChanged)
|
||||
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 notificationTitle READ getNotificationTitle WRITE setNotificationTitle NOTIFY notificationTitleChanged)
|
||||
|
@ -44,11 +46,13 @@ public:
|
|||
|
||||
int getLowAlert();
|
||||
int getHighAlert();
|
||||
int getInterval();
|
||||
int getHighNotificationsInterval();
|
||||
int getLowNotificationsInterval();
|
||||
int getLowLimit();
|
||||
int getHighLimit();
|
||||
bool getLimitEnabled();
|
||||
bool getNotificationsEnabled();
|
||||
bool getHighNotificationsEnabled();
|
||||
bool getLowNotificationsEnabled();
|
||||
QString getLowAlertFile();
|
||||
QString getHighAlertFile();
|
||||
QString getNotificationTitle();
|
||||
|
@ -57,11 +61,13 @@ public:
|
|||
|
||||
void setLowAlert(int newLimit);
|
||||
void setHighAlert(int newLimit);
|
||||
void setInterval(int newInterval);
|
||||
void setHighNotificationsInterval(int newInterval);
|
||||
void setLowNotificationsInterval(int newInterval);
|
||||
void setLowLimit(int newLimit);
|
||||
void setHighLimit(int newLimit);
|
||||
void setLimitEnabled(bool newEnabled);
|
||||
void setNotificationsEnabled(bool newEnabled);
|
||||
void setHighNotificationsEnabled(bool newEnabled);
|
||||
void setLowNotificationsEnabled(bool newEnabled);
|
||||
void setNotificationTitle(QString newText);
|
||||
void setNotificationLowText(QString newText);
|
||||
void setNotificationHighText(QString newText);
|
||||
|
@ -72,9 +78,11 @@ private:
|
|||
// Default values
|
||||
int lowAlert = 25;
|
||||
int highAlert = 75;
|
||||
int interval = 60;
|
||||
int highNotificationsInterval = 60;
|
||||
int lowNotificationsInterval = 60;
|
||||
int limitEnabled = 0; // Converted to boolean for QML
|
||||
int notificationsEnabled = 1; // 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";
|
||||
|
@ -86,9 +94,11 @@ private:
|
|||
// To avoid repeating the same string over and over and over...
|
||||
const char* sLowAlert = "lowAlert";
|
||||
const char* sHighAlert = "highAlert";
|
||||
const char* sInterval = "interval";
|
||||
const char* sHighNotificationsInterval = "highNotificationsInterval";
|
||||
const char* sLowNotificationsInterval = "lowNotificationsInterval";
|
||||
const char* sLimitEnabled = "limitEnabled";
|
||||
const char* sNotificationsEnabled = "notificationsEnabled";
|
||||
const char* sHighNotificationsEnabled = "highNotificationsEnabled";
|
||||
const char* sLowNotificationsEnabled = "lowNotificationsEnabled";
|
||||
const char* sLowLimit = "lowLimit";
|
||||
const char* sHighLimit = "highLimit";
|
||||
const char* sLowAlertFile = "lowAlertFile";
|
||||
|
@ -104,9 +114,11 @@ private:
|
|||
signals:
|
||||
void lowAlertChanged(int);
|
||||
void highAlertChanged(int);
|
||||
void intervalChanged(int);
|
||||
void highNotificationsIntervalChanged(int);
|
||||
void lowNotificationsIntervalChanged(int);
|
||||
void limitEnabledChanged(bool);
|
||||
void notificationsEnabledChanged(bool);
|
||||
void highNotificationsEnabledChanged(bool);
|
||||
void lowNotificationsEnabledChanged(bool);
|
||||
void lowLimitChanged(int);
|
||||
void highLimitChanged(int);
|
||||
void lowAlertFileChanged(QString);
|
||||
|
|
|
@ -269,14 +269,6 @@
|
|||
<source>Notification settings</source>
|
||||
<translation>Ilmoitusasetukset</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Use notifications</source>
|
||||
<translation>Käytä ilmoituksia</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Notification interval</source>
|
||||
<translation>Ilmoitusten väli</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>About</source>
|
||||
<comment>About this application</comment>
|
||||
|
@ -314,5 +306,21 @@
|
|||
<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>
|
||||
</message>
|
||||
<message>
|
||||
<source>Battery low notification interval</source>
|
||||
<translation>Matalan varauksen ilmoituksen aikaväli</translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -286,10 +286,6 @@
|
|||
<source>Notification settings</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Use notifications</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Display visual and audible notifications about reached battery charge levels, when the battery charge is below or above desired percentage.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -302,10 +298,6 @@
|
|||
<source>Battery low notification</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Notification interval</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Background service</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -314,5 +306,21 @@
|
|||
<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>
|
||||
</message>
|
||||
<message>
|
||||
<source>Battery low notification interval</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -269,14 +269,6 @@
|
|||
<source>Notification settings</source>
|
||||
<translation>Aviseringsinställningar</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Use notifications</source>
|
||||
<translation>Använd avisering</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Notification interval</source>
|
||||
<translation>Aviseringsintervall</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>About</source>
|
||||
<comment>About this application</comment>
|
||||
|
@ -314,5 +306,21 @@
|
|||
<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>
|
||||
</message>
|
||||
<message>
|
||||
<source>Battery low notification interval</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -286,10 +286,6 @@
|
|||
<source>Notification settings</source>
|
||||
<translation>通知设置</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Use notifications</source>
|
||||
<translation>使用通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Display visual and audible notifications about reached battery charge levels, when the battery charge is below or above desired percentage.</source>
|
||||
<translation>当电池电量低于或高于所需百分比时,显示有关已达到电池电量水平的视觉及听觉通知。</translation>
|
||||
|
@ -302,10 +298,6 @@
|
|||
<source>Battery low notification</source>
|
||||
<translation>低电量通知</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Notification interval</source>
|
||||
<translation>通知间隔</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Background service</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -314,5 +306,21 @@
|
|||
<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>
|
||||
</message>
|
||||
<message>
|
||||
<source>Battery low notification interval</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -269,14 +269,6 @@
|
|||
<source>Notification settings</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Use notifications</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Notification interval</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>About</source>
|
||||
<comment>About this application</comment>
|
||||
|
@ -314,5 +306,21 @@
|
|||
<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>
|
||||
</message>
|
||||
<message>
|
||||
<source>Battery low notification interval</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -17,13 +17,14 @@
|
|||
*/
|
||||
#include "battery.h"
|
||||
|
||||
Battery::Battery(Settings *newSettings, QTimer *newUpdater, QTimer *newNotifier, Notification *newNotification, QObject *parent) : QObject(parent)
|
||||
Battery::Battery(QObject *parent) : QObject(parent)
|
||||
{
|
||||
QString filename;
|
||||
settings = newSettings;
|
||||
updateTimer = newUpdater;
|
||||
notifyTimer = newNotifier;
|
||||
notification = newNotification;
|
||||
settings = new Settings(this);
|
||||
updateTimer = new QTimer(this);
|
||||
highNotifyTimer = new QTimer(this);
|
||||
lowNotifyTimer = new QTimer(this);
|
||||
notification = new Notification(this);
|
||||
|
||||
// Number: charge percentage, e.g. 42
|
||||
chargeFile = new QFile("/sys/class/power_supply/battery/capacity", this);
|
||||
|
@ -86,7 +87,8 @@ Battery::Battery(Settings *newSettings, QTimer *newUpdater, QTimer *newNotifier,
|
|||
|
||||
connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateData()));
|
||||
connect(settings, SIGNAL(configChanged()), this, SLOT(updateConfig()));
|
||||
connect(notifyTimer, SIGNAL(timeout()), this, SLOT(showNotification()));
|
||||
connect(highNotifyTimer, SIGNAL(timeout()), this, SLOT(showHighNotification()));
|
||||
connect(lowNotifyTimer, SIGNAL(timeout()), this, SLOT(showLowNotification()));
|
||||
|
||||
updateConfig();
|
||||
|
||||
|
@ -124,7 +126,7 @@ void Battery::updateData()
|
|||
qDebug() << "Charging status:" << state;
|
||||
|
||||
// Hide/show notification right away
|
||||
showNotification();
|
||||
updateNotification();
|
||||
// Reset the timer, too
|
||||
updateConfig();
|
||||
}
|
||||
|
@ -143,23 +145,16 @@ void Battery::updateData()
|
|||
}
|
||||
|
||||
void Battery::updateConfig() {
|
||||
notifyTimer->stop();
|
||||
notifyTimer->setInterval(settings->getInterval() * 1000);
|
||||
if(settings->getNotificationsEnabled())
|
||||
notifyTimer->start();
|
||||
highNotifyTimer->stop();
|
||||
lowNotifyTimer->stop();
|
||||
highNotifyTimer->setInterval(settings->getHighNotificationsInterval() * 1000);
|
||||
lowNotifyTimer->setInterval(settings->getLowNotificationsInterval() * 1000);
|
||||
highNotifyTimer->start();
|
||||
lowNotifyTimer->start();
|
||||
}
|
||||
|
||||
void Battery::showNotification() {
|
||||
if(!settings->getNotificationsEnabled())
|
||||
return;
|
||||
|
||||
qInfo() << "battery" << charge << "low" << settings->getLowAlert() << "high" << settings->getHighAlert() << "state" << state;
|
||||
|
||||
if(charge <= settings->getLowAlert() && state != "charging") {
|
||||
qDebug() << "Battery notification timer: empty enough battery";
|
||||
notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile());
|
||||
}
|
||||
else if((charge >= settings->getHighAlert() && state != "discharging")
|
||||
void Battery::showHighNotification() {
|
||||
if(settings->getHighNotificationsEnabled() && (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());
|
||||
|
@ -169,6 +164,34 @@ void Battery::showNotification() {
|
|||
notification->close();
|
||||
}
|
||||
}
|
||||
|
||||
void Battery::showLowNotification() {
|
||||
if(settings->getLowNotificationsEnabled() && charge <= settings->getLowAlert() && state != "charging") {
|
||||
qDebug() << "Battery notification timer: empty enough battery";
|
||||
notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile());
|
||||
}
|
||||
else {
|
||||
qDebug() << "Battery notification timer: close notification";
|
||||
notification->close();
|
||||
}
|
||||
}
|
||||
|
||||
void Battery::updateNotification() {
|
||||
if(settings->getHighNotificationsEnabled() && (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") {
|
||||
qDebug() << "Battery notification timer: empty enough battery";
|
||||
notification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile());
|
||||
}
|
||||
else {
|
||||
qDebug() << "Battery notification timer: close notification";
|
||||
notification->close();
|
||||
}
|
||||
}
|
||||
|
||||
int Battery::getCharge() { return charge; }
|
||||
|
||||
QString Battery::getState() { return state; }
|
||||
|
@ -208,16 +231,20 @@ bool Battery::getChargerConnected() {
|
|||
}
|
||||
|
||||
void Battery::shutdown() {
|
||||
qDebug() << "\nPreparing for exit...";
|
||||
qDebug() << "Preparing for exit...";
|
||||
blockSignals(true);
|
||||
if(updateTimer) {
|
||||
updateTimer->stop();
|
||||
qDebug() << "Timer stopped";
|
||||
}
|
||||
notification->close();
|
||||
if(notifyTimer) {
|
||||
notifyTimer->stop();
|
||||
qDebug() << "Notification stopped";
|
||||
if(highNotifyTimer) {
|
||||
highNotifyTimer->stop();
|
||||
qDebug() << "High battery notification stopped";
|
||||
}
|
||||
if(lowNotifyTimer) {
|
||||
lowNotifyTimer->stop();
|
||||
qDebug() << "Low battery notification stopped";
|
||||
}
|
||||
if(!setChargingEnabled(true)) {
|
||||
qWarning() << "ERROR! Could not restore charger status! Your device" << endl
|
||||
|
|
|
@ -33,7 +33,7 @@ class Battery : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Battery(Settings *newSettings, QTimer *newUpdater, QTimer *newNotifier, Notification *newNotification, QObject *parent = nullptr);
|
||||
Battery(QObject *parent = nullptr);
|
||||
~Battery();
|
||||
|
||||
int getCharge();
|
||||
|
@ -55,7 +55,8 @@ private:
|
|||
QFile *chargingEnabledFile = nullptr;
|
||||
Settings *settings = nullptr;
|
||||
QTimer *updateTimer = nullptr;
|
||||
QTimer *notifyTimer = nullptr;
|
||||
QTimer *highNotifyTimer = nullptr;
|
||||
QTimer *lowNotifyTimer = nullptr;
|
||||
Notification *notification = nullptr;
|
||||
|
||||
// Default values:
|
||||
|
@ -84,7 +85,9 @@ signals:
|
|||
|
||||
public slots:
|
||||
void updateConfig();
|
||||
void showNotification();
|
||||
void showHighNotification();
|
||||
void showLowNotification();
|
||||
void updateNotification();
|
||||
};
|
||||
|
||||
#endif // BATTERY_H
|
||||
|
|
|
@ -19,10 +19,8 @@
|
|||
#include <QObject>
|
||||
#include <QTimer>
|
||||
#include "battery.h"
|
||||
#include "settings.h"
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include "notification.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
@ -42,7 +40,7 @@ int main(int argc, char** argv)
|
|||
qputenv(logEnvVar, "*.info=true");
|
||||
else if(!strcmp(argv[i],"--help")) {
|
||||
printf("%s %s\n\n", APP_NAME, APP_VERSION);
|
||||
printf("This binary is meant to run as a service with root access,\n");
|
||||
printf("This binary is meant to run as a service as user nemo,\n");
|
||||
printf("but it can be run manually for debugging purposes, too.\n\n");
|
||||
printf("Usage:\n");
|
||||
printf(" --verbose Enable informational messages\n");
|
||||
|
@ -56,22 +54,14 @@ int main(int argc, char** argv)
|
|||
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
QTimer *updater = new QTimer();
|
||||
QTimer *notifier = new QTimer();
|
||||
Settings *settings = new Settings();
|
||||
Notification *notification = new Notification();
|
||||
Battery *battery = new Battery(settings, updater, notifier, notification);
|
||||
Battery battery;
|
||||
|
||||
// Exit gracefully on Ctrl-C and service stop
|
||||
QObject::connect(&app, SIGNAL(aboutToQuit()), battery, SLOT(shutdown()));
|
||||
QObject::connect(&app, SIGNAL(aboutToQuit()), &battery, SLOT(shutdown()));
|
||||
signal(SIGINT, app.exit);
|
||||
signal(SIGTERM, app.exit);
|
||||
|
||||
int retval = app.exec();
|
||||
|
||||
delete updater;
|
||||
delete settings;
|
||||
delete battery;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,19 @@ Settings::Settings(QObject *parent) : QObject(parent)
|
|||
qInfo() << "Migrated old upperLimit value";
|
||||
}
|
||||
|
||||
if(mySettings->contains("notificationsEnabled")) {
|
||||
mySettings->setValue(sHighNotificationsEnabled, mySettings->value("notificationsEnabled"));
|
||||
mySettings->remove("notificationsEnabled");
|
||||
qInfo() << "Migrated old upperLimit value";
|
||||
}
|
||||
|
||||
if(mySettings->contains("interval")) {
|
||||
mySettings->setValue(sHighNotificationsInterval, mySettings->value("interval"));
|
||||
mySettings->setValue(sLowNotificationsInterval, mySettings->value("interval"));
|
||||
mySettings->remove("interval");
|
||||
qInfo() << "Migrated old notification interval value";
|
||||
}
|
||||
|
||||
// Do this here, because...
|
||||
watcher = new QFileSystemWatcher(QStringList(mySettings->fileName()));
|
||||
connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(updateConfig(QString)));
|
||||
|
@ -77,9 +90,11 @@ void Settings::updateConfig(QString path) {
|
|||
// Read in the values
|
||||
loadInteger(sLowAlert, &lowAlert, 10, 99);
|
||||
loadInteger(sHighAlert, &highAlert, 11, 100);
|
||||
loadInteger(sInterval, &interval, 60, 600);
|
||||
loadInteger(sHighNotificationsInterval, &highNotificationsInterval, 60, 600);
|
||||
loadInteger(sLowNotificationsInterval, &lowNotificationsInterval, 60, 600);
|
||||
loadInteger(sLimitEnabled, &limitEnabled, 0, 1);
|
||||
loadInteger(sNotificationsEnabled, ¬ificationsEnabled, 0, 1);
|
||||
loadInteger(sHighNotificationsEnabled, &highNotificationsEnabled, 0, 1);
|
||||
loadInteger(sLowNotificationsEnabled, &lowNotificationsEnabled, 0, 1);
|
||||
loadInteger(sLowLimit, &lowLimit, 20, 94);
|
||||
loadInteger(sHighLimit, &highLimit, 21, 95);
|
||||
|
||||
|
@ -107,15 +122,17 @@ void Settings::updateConfig(QString path) {
|
|||
}
|
||||
|
||||
// Getters condensed
|
||||
int Settings::getLowAlert() { return lowAlert; }
|
||||
int Settings::getHighAlert() { return highAlert; }
|
||||
int Settings::getInterval() { return interval; }
|
||||
int Settings::getLowLimit() { return lowLimit; }
|
||||
int Settings::getHighLimit() { return highLimit; }
|
||||
bool Settings::getLimitEnabled() { return limitEnabled == 1; }
|
||||
bool Settings::getNotificationsEnabled() { return notificationsEnabled == 1; }
|
||||
QString Settings::getLowAlertFile() { return lowAlertFile; }
|
||||
QString Settings::getHighAlertFile() { return highAlertFile; }
|
||||
QString Settings::getNotificationTitle() { return notificationTitle; }
|
||||
QString Settings::getNotificationLowText() { return notificationLowText; }
|
||||
QString Settings::getNotificationHighText() { return notificationHighText; }
|
||||
int Settings::getLowAlert() { return lowAlert; }
|
||||
int Settings::getHighAlert() { return highAlert; }
|
||||
int Settings::getHighNotificationsInterval() { return highNotificationsInterval; }
|
||||
int Settings::getLowNotificationsInterval() { return lowNotificationsInterval; }
|
||||
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; }
|
||||
QString Settings::getNotificationLowText() { return notificationLowText; }
|
||||
QString Settings::getNotificationHighText() { return notificationHighText; }
|
||||
|
|
|
@ -34,11 +34,13 @@ public:
|
|||
|
||||
int getLowAlert();
|
||||
int getHighAlert();
|
||||
int getInterval();
|
||||
int getHighNotificationsInterval();
|
||||
int getLowNotificationsInterval();
|
||||
int getLowLimit();
|
||||
int getHighLimit();
|
||||
bool getLimitEnabled();
|
||||
bool getNotificationsEnabled();
|
||||
bool getHighNotificationsEnabled();
|
||||
bool getLowNotificationsEnabled();
|
||||
QString getLowAlertFile();
|
||||
QString getHighAlertFile();
|
||||
QString getNotificationTitle();
|
||||
|
@ -52,11 +54,13 @@ private:
|
|||
// Default values
|
||||
int lowAlert = 25;
|
||||
int highAlert = 75;
|
||||
int interval = 60;
|
||||
int highNotificationsInterval = 60;
|
||||
int lowNotificationsInterval = 60;
|
||||
|
||||
// Converted to boolean for QML
|
||||
int limitEnabled = 0;
|
||||
int notificationsEnabled = 1;
|
||||
int highNotificationsEnabled = 1; // Converted to boolean for QML
|
||||
int lowNotificationsEnabled = 1; // Converted to boolean for QML
|
||||
int daemonEnabled = 1;
|
||||
|
||||
int lowLimit = 65;
|
||||
|
@ -70,9 +74,11 @@ private:
|
|||
// To avoid repeating the same string over and over and over...
|
||||
const char* sLowAlert = "lowAlert";
|
||||
const char* sHighAlert = "highAlert";
|
||||
const char* sInterval = "interval";
|
||||
const char* sHighNotificationsInterval = "highNotificationsInterval";
|
||||
const char* sLowNotificationsInterval = "lowNotificationsInterval";
|
||||
const char* sLimitEnabled = "limitEnabled";
|
||||
const char* sNotificationsEnabled = "notificationsEnabled";
|
||||
const char* sHighNotificationsEnabled = "highNotificationsEnabled";
|
||||
const char* sLowNotificationsEnabled = "lowNotificationsEnabled";
|
||||
const char* sLowLimit = "lowLimit";
|
||||
const char* sHighLimit = "highLimit";
|
||||
const char* sLowAlertFile = "lowAlertFile";
|
||||
|
|
Loading…
Reference in a new issue