Code cleanup; rename variables. Separate alert and charger limits.
This commit is contained in:
parent
799ecd40db
commit
e1b59a98a5
3 changed files with 117 additions and 93 deletions
|
@ -64,29 +64,34 @@ Page {
|
|||
font.pixelSize: Theme.fontSizeSmall
|
||||
}
|
||||
Slider {
|
||||
id: upperChargeLimit
|
||||
id: highAlertSlider
|
||||
width: parent.width
|
||||
label: qsTr("Charging limit")
|
||||
minimumValue: 60
|
||||
minimumValue: 10
|
||||
maximumValue: 99
|
||||
stepSize: 1
|
||||
value: settings.upperLimit
|
||||
value: settings.highAlert
|
||||
valueText: value + "%"
|
||||
onValueChanged: {
|
||||
settings.upperLimit = value
|
||||
if((value - 2) < continueChargeLimit.value)
|
||||
continueChargeLimit.value = value - 2
|
||||
settings.highLimit = value
|
||||
if(lowAlertSlider.value >= value)
|
||||
lowAlertSlider.value = value - 1
|
||||
}
|
||||
}
|
||||
Slider {
|
||||
id: lowAlertSlider
|
||||
width: parent.width
|
||||
label: qsTr("Discharging limit")
|
||||
minimumValue: 10
|
||||
maximumValue: 40
|
||||
maximumValue: 99
|
||||
stepSize: 1
|
||||
value: settings.lowerLimit
|
||||
value: settings.lowAlert
|
||||
valueText: value + "%"
|
||||
onValueChanged: settings.lowerLimit = value
|
||||
onValueChanged: {
|
||||
settings.highLimit = value
|
||||
if(highAlertSlider.value <= value)
|
||||
highAlertSlider.value = value + 1
|
||||
}
|
||||
}
|
||||
TextSwitch {
|
||||
id: autoStopCharging
|
||||
|
@ -97,16 +102,36 @@ Page {
|
|||
}
|
||||
|
||||
Slider {
|
||||
id: continueChargeLimit
|
||||
id: highLimitSlider
|
||||
handleVisible: enabled
|
||||
width: parent.width
|
||||
label: qsTr("Stop charging limit")
|
||||
minimumValue: 20
|
||||
maximumValue: 95
|
||||
stepSize: 1
|
||||
value: settings.lowLimit
|
||||
valueText: value + "%"
|
||||
onValueChanged: {
|
||||
settings.lowLimit = value
|
||||
if(lowLimitSlider.value >= value)
|
||||
lowLimitSlider.value = value - 1
|
||||
}
|
||||
}
|
||||
Slider {
|
||||
id: lowLimitSlider
|
||||
handleVisible: enabled
|
||||
width: parent.width
|
||||
label: qsTr("Resume charging limit")
|
||||
minimumValue: 50
|
||||
maximumValue: upperChargeLimit.value - 2
|
||||
minimumValue: 20
|
||||
maximumValue: 95
|
||||
stepSize: 1
|
||||
value: settings.chargeLimit
|
||||
value: settings.highLimit
|
||||
valueText: value + "%"
|
||||
onValueChanged: settings.chargeLimit = value
|
||||
onValueChanged: {
|
||||
settings.highLimit = value
|
||||
if(highLimitSlider.value <= value)
|
||||
highLimitSlider.value = value + 1
|
||||
}
|
||||
}
|
||||
Label {
|
||||
x: Theme.paddingLarge*2
|
||||
|
@ -129,7 +154,7 @@ Page {
|
|||
id: button
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Enable")
|
||||
onClicked: battery.chargingEnabled = true
|
||||
onClicked: chargingEnabled = true
|
||||
}
|
||||
}
|
||||
Column {
|
||||
|
@ -137,7 +162,7 @@ Page {
|
|||
Button {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: qsTr("Disable")
|
||||
onClicked: battery.chargingEnabled = false
|
||||
onClicked: chargingEnabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,70 +20,53 @@
|
|||
Settings::Settings(QObject *parent) : QObject(parent)
|
||||
{
|
||||
int tempValue;
|
||||
if(mySettings.contains("lowerLimit")) {
|
||||
tempValue = mySettings.value("lowerLimit").toInt();
|
||||
if(tempValue >= 10 && tempValue <= 50) {
|
||||
lowerLimit = tempValue;
|
||||
emit lowerLimitChanged();
|
||||
if(mySettings.contains(sLowAlert)) {
|
||||
tempValue = mySettings.value(sLowAlert).toInt();
|
||||
if(tempValue >= 10 && tempValue <= 99) {
|
||||
lowAlert = tempValue;
|
||||
emit lowAlertChanged();
|
||||
}
|
||||
}
|
||||
if(mySettings.contains("upperLimit")) {
|
||||
tempValue = mySettings.value("upperLimit").toInt();
|
||||
if(tempValue >= 60 && tempValue <= 100) {
|
||||
upperLimit = tempValue;
|
||||
emit upperLimitChanged();
|
||||
if(mySettings.contains(sHighAlert)) {
|
||||
tempValue = mySettings.value(sHighAlert).toInt();
|
||||
if(tempValue >= 10 && tempValue <= 99) {
|
||||
highAlert = tempValue;
|
||||
emit highAlertChanged();
|
||||
}
|
||||
}
|
||||
if(mySettings.contains("interval")) {
|
||||
tempValue = mySettings.value("interval").toInt();
|
||||
if(mySettings.contains(sInterval)) {
|
||||
tempValue = mySettings.value(sInterval).toInt();
|
||||
if(tempValue >= 60 && tempValue <= 600) {
|
||||
interval = tempValue;
|
||||
emit intervalChanged();
|
||||
}
|
||||
}
|
||||
if(mySettings.contains("limitEnabled")) {
|
||||
limitEnabled = (mySettings.value("limitEnabled").toInt() == 1);
|
||||
if(mySettings.contains(sLimitEnabled)) {
|
||||
limitEnabled = (mySettings.value(sLimitEnabled).toInt() == 1);
|
||||
emit limitEnabledChanged();
|
||||
}
|
||||
if(mySettings.contains("chargeLimit")) {
|
||||
tempValue = mySettings.value("chargeLimit").toInt();
|
||||
if(tempValue >= 50 && tempValue <= (upperLimit - 2)) {
|
||||
chargeLimit = tempValue;
|
||||
emit chargeLimitChanged();
|
||||
if(mySettings.contains(sLowLimit)) {
|
||||
tempValue = mySettings.value(sLowLimit).toInt();
|
||||
if(tempValue >= 20 && tempValue <= 95) {
|
||||
lowLimit = tempValue;
|
||||
emit lowLimitChanged();
|
||||
}
|
||||
}
|
||||
if(mySettings.contains(sHighLimit)) {
|
||||
tempValue = mySettings.value(sHighLimit).toInt();
|
||||
if(tempValue >= 20 && tempValue <= 95) {
|
||||
highLimit = tempValue;
|
||||
emit highLimitChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Settings::~Settings()
|
||||
{
|
||||
int limitValue = limitEnabled ? 1 : 0;
|
||||
mySettings.setValue("lowerLimit", QByteArray::number(lowerLimit));
|
||||
mySettings.setValue("upperLimit", QByteArray::number(upperLimit));
|
||||
mySettings.setValue("interval", QByteArray::number(interval));
|
||||
mySettings.setValue("limitEnabled", QByteArray::number(limitValue));
|
||||
mySettings.setValue("chargeLimit", QByteArray::number(chargeLimit));
|
||||
mySettings.setValue(sLowAlert, QByteArray::number(lowAlert));
|
||||
mySettings.setValue(sHighAlert, QByteArray::number(highAlert));
|
||||
mySettings.setValue(sInterval, QByteArray::number(interval));
|
||||
mySettings.setValue(sLimitEnabled, QByteArray::number(limitEnabled ? 1 : 0));
|
||||
mySettings.setValue(sLowLimit, QByteArray::number(lowLimit));
|
||||
mySettings.setValue(sHighLimit, QByteArray::number(highLimit));
|
||||
}
|
||||
|
||||
int Settings::getLowerLimit() { return lowerLimit; }
|
||||
|
||||
int Settings::getUpperLimit() { return upperLimit; }
|
||||
|
||||
int Settings::getInterval() { return interval; }
|
||||
|
||||
QString Settings::getLowAlert() { return lowAlertFile; }
|
||||
|
||||
QString Settings::getHighAlert() { return highAlertFile; }
|
||||
|
||||
bool Settings::getLimitEnabled() { return limitEnabled; }
|
||||
|
||||
int Settings::getChargeLimit() { return chargeLimit; }
|
||||
|
||||
void Settings::setLowerLimit(int newLimit) { lowerLimit = newLimit; }
|
||||
|
||||
void Settings::setUpperLimit(int newLimit) { upperLimit = newLimit; }
|
||||
|
||||
void Settings::setInterval(int newInterval) { interval = newInterval; }
|
||||
|
||||
void Settings::setLimitEnabled(bool newEnabled) { limitEnabled = newEnabled; }
|
||||
|
||||
void Settings::setChargeLimit(int newLimit) { chargeLimit = newLimit; }
|
||||
|
|
|
@ -24,52 +24,68 @@
|
|||
class Settings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int lowerLimit READ getLowerLimit WRITE setLowerLimit NOTIFY lowerLimitChanged)
|
||||
Q_PROPERTY(int upperLimit READ getUpperLimit WRITE setUpperLimit NOTIFY upperLimitChanged)
|
||||
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 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(int chargeLimit READ getChargeLimit WRITE setChargeLimit NOTIFY chargeLimitChanged)
|
||||
Q_PROPERTY(QString lowAlertFile READ getLowAlert NOTIFY lowAlertChanged)
|
||||
Q_PROPERTY(QString highAlertFile READ getHighAlert NOTIFY highAlertChanged)
|
||||
Q_PROPERTY(QString lowAlertFile READ getLowAlertFile NOTIFY lowAlertFileChanged)
|
||||
Q_PROPERTY(QString highAlertFile READ getHighAlertFile NOTIFY highAlertFileChanged)
|
||||
|
||||
public:
|
||||
Settings(QObject* parent = nullptr);
|
||||
~Settings();
|
||||
|
||||
// QML-exposed stuff
|
||||
int getLowerLimit();
|
||||
int getUpperLimit();
|
||||
int getInterval();
|
||||
bool getLimitEnabled();
|
||||
int getChargeLimit();
|
||||
QString getLowAlert();
|
||||
QString getHighAlert();
|
||||
void setLowerLimit(int newLimit);
|
||||
void setUpperLimit(int newLimit);
|
||||
void setInterval(int newInterval);
|
||||
void setLimitEnabled(bool newEnabled);
|
||||
void setChargeLimit(int newLimit);
|
||||
int getLowAlert() { return lowAlert; }
|
||||
int getHighAlert() { return highAlert; }
|
||||
int getInterval() { return interval; }
|
||||
int getLowLimit() { return lowLimit; }
|
||||
int getHighLimit() { return highLimit; }
|
||||
bool getLimitEnabled() { return limitEnabled; }
|
||||
QString getLowAlertFile() { return lowAlertFile; }
|
||||
|
||||
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; }
|
||||
QString getHighAlertFile() { return highAlertFile; }
|
||||
|
||||
|
||||
private:
|
||||
QSettings mySettings;
|
||||
|
||||
// Default values
|
||||
int lowerLimit = 25;
|
||||
int upperLimit = 75;
|
||||
int lowAlert = 25;
|
||||
int highAlert = 75;
|
||||
int interval = 60;
|
||||
bool limitEnabled = false;
|
||||
int chargeLimit = 70;
|
||||
int lowLimit = 65;
|
||||
int highLimit = 70;
|
||||
QString lowAlertFile = "/usr/share/sounds/jolla-ambient/stereo/general_warning.wav";
|
||||
QString highAlertFile = "/usr/share/sounds/jolla-ambient/stereo/positive_confirmation.wav";
|
||||
|
||||
// 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* sLimitEnabled = "limitEnabled";
|
||||
const char* sLowLimit = "lowLimit";
|
||||
const char* sHighLimit = "highLimit";
|
||||
const char* sLowAlertFile = "lowAlertFile";
|
||||
const char* sHighAlertFile = "highAlertFile";
|
||||
|
||||
signals:
|
||||
int lowerLimitChanged();
|
||||
int upperLimitChanged();
|
||||
int lowAlertChanged();
|
||||
int highAlertChanged();
|
||||
int intervalChanged();
|
||||
bool limitEnabledChanged();
|
||||
int chargeLimitChanged();
|
||||
QString lowAlertChanged();
|
||||
QString highAlertChanged();
|
||||
int lowLimitChanged();
|
||||
int highLimitChanged();
|
||||
QString lowAlertFileChanged();
|
||||
QString highAlertFileChanged();
|
||||
};
|
||||
|
||||
#endif // SETTINGS_H
|
||||
|
|
Loading…
Reference in a new issue