Fix broken state detection, move state translations to QML
This commit is contained in:
parent
8eafae5808
commit
722cac24b9
3 changed files with 16 additions and 22 deletions
|
@ -22,7 +22,14 @@ import Nemo.Notifications 1.0
|
|||
|
||||
Page {
|
||||
id: page
|
||||
property variant statusText: {
|
||||
"idle": qsTr("idle", "Charger plugged in, not using nor charging battery"),
|
||||
"discharging": qsTr("discharging", "Charger not plugged in, battery discharging"),
|
||||
"charging": qsTr("charging", "Charger plugged in and battery charging"),
|
||||
"unknown": qsTr("unknown", "Battery not detected, or faulty, or something")
|
||||
}
|
||||
|
||||
// Finally, emit the signal
|
||||
// The effective value will be restricted by ApplicationWindow.allowedOrientations
|
||||
allowedOrientations: Orientation.All
|
||||
|
||||
|
@ -112,7 +119,7 @@ Page {
|
|||
+qsTr("State:")
|
||||
value: battery.charge+"%\n"
|
||||
+(battery.charging ? qsTr("yes") : qsTr("no"))+"\n"
|
||||
+qsTr(battery.state)
|
||||
+statusText[battery.state]
|
||||
}
|
||||
Label {
|
||||
x: Theme.paddingLarge
|
||||
|
|
|
@ -54,21 +54,9 @@ void Battery::updateData()
|
|||
chargingFile->close();
|
||||
}
|
||||
if(stateFile->open(QIODevice::ReadOnly)) {
|
||||
nextStatus = (QString(stateFile->readAll()));
|
||||
if(nextStatus != state) {
|
||||
state = nextStatus;
|
||||
|
||||
// Update translated text accordingly
|
||||
if(state == "")
|
||||
stateTr = tr("idle", "Charger plugged in, not using nor charging battery");
|
||||
else if(state == "discharging")
|
||||
stateTr = tr("discharging", "Charger not plugged in, battery discharging");
|
||||
else if(state == "charging")
|
||||
stateTr = tr("charging", "Charger plugged in and battery charging");
|
||||
else if(state == "unknown")
|
||||
stateTr = tr("unknown", "Battery not detected, or faulty, or something");
|
||||
|
||||
// Finally, emit the signal
|
||||
nextState = (QString(stateFile->readAll()));
|
||||
if(nextState != state) {
|
||||
state = nextState;
|
||||
emit stateChanged();
|
||||
}
|
||||
stateFile->close();
|
||||
|
@ -79,4 +67,4 @@ int Battery::getCharge(){ return charge; }
|
|||
|
||||
bool Battery::getCharging() { return charging; }
|
||||
|
||||
QString Battery::getState() { return stateTr; }
|
||||
QString Battery::getState() { return state; }
|
||||
|
|
|
@ -48,12 +48,11 @@ private:
|
|||
// Default values:
|
||||
int charge = 100; // 100% full
|
||||
bool charging = true; // Charger plugged in
|
||||
QString state = "idle"; // Not charging
|
||||
QString stateTr = state; // Translated state text
|
||||
QString state = "idle"; // dis/charging, idle, unknown
|
||||
|
||||
int nextCharge = charge;
|
||||
bool nextCharging = charging;
|
||||
QString nextStatus = state;
|
||||
int nextCharge = charge;
|
||||
bool nextCharging = charging;
|
||||
QString nextState = state;
|
||||
|
||||
signals:
|
||||
int chargeChanged();
|
||||
|
|
Loading…
Reference in a new issue