Implement enable/disable notifications, fix emitting signals, move charger control buttons to MainPage
This commit is contained in:
parent
59950ddb7a
commit
3fe4589c21
5 changed files with 109 additions and 138 deletions
|
@ -60,8 +60,8 @@ ApplicationWindow
|
|||
|
||||
Timer {
|
||||
id: alertTimer
|
||||
interval: settings.interval * 1000 // sec -> msec
|
||||
running: true
|
||||
interval: settings.interval * 1000
|
||||
running: settings.notificationsEnabled
|
||||
repeat: true
|
||||
onTriggered: {
|
||||
if(battery.charge <= settings.lowerLimit && battery.state === "discharging") {
|
||||
|
|
|
@ -40,7 +40,7 @@ Page {
|
|||
SilicaFlickable {
|
||||
id: mainFlickable
|
||||
anchors.fill: parent
|
||||
contentHeight: column.height
|
||||
contentHeight: column.height + Theme.horizontalPageMargin
|
||||
|
||||
VerticalScrollDecorator { flickable: mainFlickable }
|
||||
|
||||
|
@ -112,9 +112,46 @@ Page {
|
|||
color: Theme.primaryColor
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
}
|
||||
Item {
|
||||
width: parent.width
|
||||
height: Theme.paddingLarge
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
text: qsTr("Charger control")
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
Label {
|
||||
x: Theme.paddingLarge*2
|
||||
width: parent.width - x*2;
|
||||
wrapMode: Text.Wrap
|
||||
text: qsTr("Using these controls overrides the automated settings.")
|
||||
color: Theme.primaryColor
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
}
|
||||
Row {
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
height: resumeButton.height
|
||||
|
||||
Column {
|
||||
width: parent.width / 2
|
||||
Button {
|
||||
id: resumeButton
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Resume")
|
||||
onClicked: battery.chargingEnabled = true
|
||||
enabled: !battery.chargingEnabled
|
||||
}
|
||||
}
|
||||
Column {
|
||||
width: parent.width / 2
|
||||
Button {
|
||||
id: pauseButton
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Pause")
|
||||
onClicked: battery.chargingEnabled = false
|
||||
enabled: battery.chargingEnabled
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@ Page {
|
|||
anchors.fill: parent
|
||||
contentHeight: header.height + settingsColumn.height + Theme.horizontalPageMargin
|
||||
|
||||
VerticalScrollDecorator { flickable: mainFlickable }
|
||||
|
||||
PageHeader {
|
||||
id: header
|
||||
title: qsTr("Settings")
|
||||
|
@ -43,64 +45,15 @@ Page {
|
|||
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
text: qsTr("Alert settings")
|
||||
text: qsTr("Charging settings")
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
MySlider {
|
||||
width: parent.width
|
||||
label: qsTr("Alert interval")
|
||||
minimumValue: 60
|
||||
maximumValue: 600
|
||||
stepSize: 10
|
||||
value: settings.interval
|
||||
valueText: Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60)
|
||||
onValueChanged: settings.interval = value
|
||||
}
|
||||
Label {
|
||||
x: Theme.paddingLarge*2
|
||||
width: parent.width - x*2;
|
||||
wrapMode: Text.Wrap
|
||||
text: qsTr("Set the maximum and minimum target charge levels.")
|
||||
color: Theme.primaryColor
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
}
|
||||
MySlider {
|
||||
id: highAlertSlider
|
||||
width: parent.width
|
||||
label: qsTr("Charging limit")
|
||||
minimumValue: 11
|
||||
maximumValue: 100
|
||||
stepSize: 1
|
||||
value: settings.highAlert
|
||||
valueText: value + "%"
|
||||
highlightDirection: Qt.RightToLeft
|
||||
onValueChanged: {
|
||||
settings.highAlert = value
|
||||
if(lowAlertSlider.value >= value)
|
||||
lowAlertSlider.value = value - 1
|
||||
}
|
||||
}
|
||||
MySlider {
|
||||
id: lowAlertSlider
|
||||
width: parent.width
|
||||
label: qsTr("Discharging limit")
|
||||
minimumValue: 10
|
||||
maximumValue: 99
|
||||
stepSize: 1
|
||||
value: settings.lowAlert
|
||||
valueText: value + "%"
|
||||
onValueChanged: {
|
||||
settings.lowAlert = value
|
||||
if(highAlertSlider.value <= value)
|
||||
highAlertSlider.value = value + 1
|
||||
}
|
||||
}
|
||||
TextSwitch {
|
||||
id: autoStopCharging
|
||||
text: qsTr("Stop charging when limit reached")
|
||||
description: qsTr("This option stops charging when battery has reached the percentage set in Charging limit value, and resumes charging when charge has decreased below Continue charge limit value. Generally a value close to the Charging limit value is recommened, such as 80% and 75%.")
|
||||
checked: settings.limitEnabled
|
||||
onCheckedChanged: settings.limitEnabled = checked
|
||||
Component.onCompleted: checked = settings.limitEnabled
|
||||
}
|
||||
|
||||
MySlider {
|
||||
|
@ -111,7 +64,7 @@ Page {
|
|||
minimumValue: 21
|
||||
maximumValue: 95
|
||||
stepSize: 1
|
||||
value: settings.highLimit
|
||||
Component.onCompleted: value = settings.highLimit
|
||||
valueText: value + "%"
|
||||
highlightDirection: Qt.RightToLeft
|
||||
onValueChanged: {
|
||||
|
@ -128,7 +81,7 @@ Page {
|
|||
minimumValue: 20
|
||||
maximumValue: 94
|
||||
stepSize: 1
|
||||
value: settings.lowLimit
|
||||
Component.onCompleted: value = settings.lowLimit
|
||||
valueText: value + "%"
|
||||
onValueChanged: {
|
||||
settings.lowLimit = value
|
||||
|
@ -136,86 +89,59 @@ Page {
|
|||
highLimitSlider.value = value + 1
|
||||
}
|
||||
}
|
||||
Label {
|
||||
x: Theme.paddingLarge*2
|
||||
width: parent.width - x*2;
|
||||
wrapMode: Text.Wrap
|
||||
text: qsTr("You can also independently stop and resume charging.")
|
||||
color: Theme.primaryColor
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
}
|
||||
Row {
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
height: resumeButton.height
|
||||
|
||||
Column {
|
||||
width: parent.width / 2
|
||||
Button {
|
||||
id: resumeButton
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Resume")
|
||||
onClicked: battery.chargingEnabled = true
|
||||
enabled: !battery.chargingEnabled
|
||||
}
|
||||
}
|
||||
Column {
|
||||
width: parent.width / 2
|
||||
Button {
|
||||
id: pauseButton
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Pause")
|
||||
onClicked: battery.chargingEnabled = false
|
||||
enabled: battery.chargingEnabled
|
||||
}
|
||||
}
|
||||
}
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
text: qsTr("Alert tests")
|
||||
text: qsTr("Notification settings")
|
||||
color: Theme.highlightColor
|
||||
}
|
||||
|
||||
Label {
|
||||
x: Theme.paddingLarge*2
|
||||
width: parent.width - x*2;
|
||||
wrapMode: Text.Wrap
|
||||
text: qsTr("Click the buttons to test the sound and notification.")
|
||||
color: Theme.primaryColor
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
TextSwitch {
|
||||
id: notificationsSwitch
|
||||
text: qsTr("Use notifications")
|
||||
description: qsTr("When the application is minimized, display visual and audible notifications about reached battery charge levels.")
|
||||
Component.onCompleted: checked = settings.notificationsEnabled
|
||||
onCheckedChanged: settings.notificationsEnabled = checked
|
||||
}
|
||||
Row {
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
MySlider {
|
||||
id: highAlertSlider
|
||||
width: parent.width
|
||||
label: qsTr("Charging limit")
|
||||
minimumValue: 11
|
||||
maximumValue: 100
|
||||
stepSize: 1
|
||||
Component.onCompleted: value = settings.highAlert
|
||||
valueText: value + "%"
|
||||
highlightDirection: Qt.RightToLeft
|
||||
onValueChanged: {
|
||||
settings.highAlert = value
|
||||
if(lowAlertSlider.value >= value)
|
||||
lowAlertSlider.value = value - 1
|
||||
}
|
||||
height: resumeButton.height
|
||||
|
||||
Column {
|
||||
width: parent.width / 2
|
||||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Charged")
|
||||
onClicked: {
|
||||
alertHigh.play()
|
||||
notification.republishTest()
|
||||
}
|
||||
}
|
||||
}
|
||||
Column {
|
||||
width: parent.width / 2
|
||||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Discharged")
|
||||
onClicked: {
|
||||
alertLow.play()
|
||||
notification.republishTest()
|
||||
}
|
||||
}
|
||||
}
|
||||
MySlider {
|
||||
id: lowAlertSlider
|
||||
width: parent.width
|
||||
label: qsTr("Discharging limit")
|
||||
minimumValue: 10
|
||||
maximumValue: 99
|
||||
stepSize: 1
|
||||
Component.onCompleted: value = settings.lowAlert
|
||||
valueText: value + "%"
|
||||
onValueChanged: {
|
||||
settings.lowAlert = value
|
||||
if(highAlertSlider.value <= value)
|
||||
highAlertSlider.value = value + 1
|
||||
}
|
||||
}
|
||||
MySlider {
|
||||
width: parent.width
|
||||
label: qsTr("Notification interval")
|
||||
minimumValue: 60
|
||||
maximumValue: 600
|
||||
stepSize: 10
|
||||
Component.onCompleted: value = settings.interval
|
||||
valueText: Math.floor(value / 60) + (value % 60 < 10 ? ":0" + value % 60 : ":" + value % 60)
|
||||
onValueChanged: settings.interval = value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ Settings::Settings(QObject *parent) : QObject(parent)
|
|||
loadInteger(sHighAlert, &highAlert, 11, 100);
|
||||
loadInteger(sInterval, &interval, 60, 600);
|
||||
loadInteger(sLimitEnabled, &limitEnabled, 0, 1);
|
||||
loadInteger(sNotificationsEnabled, ¬ificationsEnabled, 0, 1);
|
||||
loadInteger(sLowLimit, &lowLimit, 20, 94);
|
||||
loadInteger(sHighLimit, &highLimit, 21, 95);
|
||||
qInfo() << "Loaded" << sLimitEnabled << limitEnabled;
|
||||
|
@ -48,6 +49,7 @@ Settings::~Settings()
|
|||
mySettings.setValue(sHighAlert, QByteArray::number(highAlert));
|
||||
mySettings.setValue(sInterval, QByteArray::number(interval));
|
||||
mySettings.setValue(sLimitEnabled, QByteArray::number(limitEnabled));
|
||||
mySettings.setValue(sNotificationsEnabled, QByteArray::number(notificationsEnabled));
|
||||
mySettings.setValue(sLowLimit, QByteArray::number(lowLimit));
|
||||
mySettings.setValue(sHighLimit, QByteArray::number(highLimit));
|
||||
qInfo() << "Settings saved";
|
||||
|
|
|
@ -31,6 +31,7 @@ class Settings : public QObject
|
|||
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(QString lowAlertFile READ getLowAlertFile NOTIFY lowAlertFileChanged)
|
||||
Q_PROPERTY(QString highAlertFile READ getHighAlertFile NOTIFY highAlertFileChanged)
|
||||
|
||||
|
@ -44,15 +45,17 @@ public:
|
|||
int getLowLimit() { return lowLimit; }
|
||||
int getHighLimit() { return highLimit; }
|
||||
bool getLimitEnabled() { return limitEnabled == 1; }
|
||||
bool getNotificationsEnabled() { return notificationsEnabled == 1; }
|
||||
QString getLowAlertFile() { return lowAlertFile; }
|
||||
QString getHighAlertFile() { return highAlertFile;}
|
||||
|
||||
void setLowAlert(int newLimit) { lowAlert = newLimit; }
|
||||
void setHighAlert(int newLimit) { highAlert = newLimit; }
|
||||
void setInterval(int newInterval) { interval = newInterval; }
|
||||
void setLowLimit(int newLimit) { lowLimit = newLimit; }
|
||||
void setHighLimit(int newLimit) { highLimit = newLimit; }
|
||||
void setLimitEnabled(bool newEnabled) { limitEnabled = (newEnabled ? 1 : 0); }
|
||||
QString getHighAlertFile() { return highAlertFile; }
|
||||
void setLowAlert(int newLimit) { lowAlert = newLimit; emit lowAlertChanged(); }
|
||||
void setHighAlert(int newLimit) { highAlert = newLimit; emit highAlertChanged(); }
|
||||
void setInterval(int newInterval) { interval = newInterval; emit intervalChanged(); }
|
||||
void setLowLimit(int newLimit) { lowLimit = newLimit; emit lowLimitChanged(); }
|
||||
void setHighLimit(int newLimit) { highLimit = newLimit; emit highLimitChanged(); }
|
||||
void setLimitEnabled(bool newEnabled) { limitEnabled = (newEnabled ? 1 : 0); emit limitEnabledChanged(); }
|
||||
void setNotificationsEnabled(bool newEnabled) { notificationsEnabled = (newEnabled ? 1 : 0); emit notificationsEnabledChanged(); }
|
||||
|
||||
|
||||
private:
|
||||
|
@ -63,6 +66,7 @@ private:
|
|||
int highAlert = 75;
|
||||
int interval = 60;
|
||||
int limitEnabled = 0; // Converted to boolean for QML
|
||||
int notificationsEnabled = 1; // Converted to boolean for QML
|
||||
int lowLimit = 65;
|
||||
int highLimit = 70;
|
||||
QString lowAlertFile = "/usr/share/sounds/jolla-ambient/stereo/general_warning.wav";
|
||||
|
@ -73,6 +77,7 @@ private:
|
|||
const char* sHighAlert = "highAlert";
|
||||
const char* sInterval = "interval";
|
||||
const char* sLimitEnabled = "limitEnabled";
|
||||
const char* sNotificationsEnabled = "notificationsEnabled";
|
||||
const char* sLowLimit = "lowLimit";
|
||||
const char* sHighLimit = "highLimit";
|
||||
const char* sLowAlertFile = "lowAlertFile";
|
||||
|
@ -86,6 +91,7 @@ signals:
|
|||
int highAlertChanged();
|
||||
int intervalChanged();
|
||||
bool limitEnabledChanged();
|
||||
bool notificationsEnabledChanged();
|
||||
int lowLimitChanged();
|
||||
int highLimitChanged();
|
||||
QString lowAlertFileChanged();
|
||||
|
|
Loading…
Reference in a new issue