diff --git a/qml/pages/MainPage.qml b/qml/pages/MainPage.qml index e045582..86c67e7 100644 --- a/qml/pages/MainPage.qml +++ b/qml/pages/MainPage.qml @@ -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 diff --git a/src/battery.cpp b/src/battery.cpp index 6605ae8..30f4197 100644 --- a/src/battery.cpp +++ b/src/battery.cpp @@ -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; } diff --git a/src/battery.h b/src/battery.h index 92b3e56..b134ae5 100644 --- a/src/battery.h +++ b/src/battery.h @@ -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();