From kde-commits Mon Jul 09 16:26:53 2012 From: Lukas Tinkl Date: Mon, 09 Jul 2012 16:26:53 +0000 To: kde-commits Subject: [kde-workspace] plasma/generic/applets/batterymonitor/contents/ui: fix Battery Monitor widget stops Message-Id: <20120709162653.F2F6AA60A6 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=134185145810582 Git commit cbfaa5161731e0789b348c9a6ebe67e10d49b190 by Lukas Tinkl. Committed on 09/07/2012 at 18:21. Pushed by lukas into branch 'master'. fix Battery Monitor widget stops tracking charging state changes after susp= end/resume cycle also fix the description to correctly reflect charging/discharging state BUG: 287952 M +3 -2 plasma/generic/applets/batterymonitor/contents/ui/PopupDialo= g.qml M +21 -8 plasma/generic/applets/batterymonitor/contents/ui/batterymon= itor.qml http://commits.kde.org/kde-workspace/cbfaa5161731e0789b348c9a6ebe67e10d49b1= 90 diff --git a/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.= qml b/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml index 4d106d2..dd99ec3 100644 --- a/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml +++ b/plasma/generic/applets/batterymonitor/contents/ui/PopupDialog.qml @@ -26,6 +26,7 @@ Item { height: childrenRect.height+24 = property int percent + property string batteryState property bool hasBattery property bool pluggedIn property alias screenBrightness: brightnessSlider.value @@ -65,7 +66,7 @@ Item { visible: remainingTime.visible anchors.right: parent.right } - = + Components.Label { text: i18nc("Label for power management inhibition", "Power ma= nagement enabled:") anchors.right: parent.right @@ -87,7 +88,7 @@ Item { } = Components.Label { - text: dialog.hasBattery ? stringForState(pluggedIn, percent) := i18nc("Battery is not plugged in", "Not present") + text: dialog.hasBattery ? stringForState(batteryState, percent= ) : i18nc("Battery is not plugged in", "Not present") font.weight: Font.Bold } = diff --git a/plasma/generic/applets/batterymonitor/contents/ui/batterymonit= or.qml b/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.q= ml index 412c4b6..72bb8ec 100644 --- a/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml +++ b/plasma/generic/applets/batterymonitor/contents/ui/batterymonitor.qml @@ -50,6 +50,7 @@ Item { property QtObject pmSource: plasmoid.rootItem.pmSource property bool hasBattery: pmSource.data["Battery"]["Has Batter= y"] property int percent: pmSource.data["Battery0"]["Percent"] + property string batteryState: pmSource.data["Battery0"]["State= "] property bool pluggedIn: pmSource.data["AC Adapter"]["Plugged = in"] property bool showOverlay: false = @@ -75,7 +76,7 @@ Item { property real size: Math.min(parent.width, parent.height) width: size height: size - = + BatteryIcon { id: batteryIcon monochrome: true @@ -119,7 +120,7 @@ Item { var text=3D""; text +=3D i18n("Battery:"); text +=3D " "; - text +=3D hasBattery ? plasmoid.rootItem.stringForStat= e(pluggedIn, percent) : i18nc("Battery is not plugged in", "Not present"); + text +=3D hasBattery ? plasmoid.rootItem.stringForStat= e(batteryState, percent) : i18nc("Battery is not plugged in", "Not present"= ); text +=3D "
"; text +=3D i18nc("tooltip", "AC Adapter:"); text +=3D " "; @@ -146,20 +147,32 @@ Item { } plasmoid.status =3D status; } + onSourceAdded: { + if (source =3D=3D "Battery0") { + connectSource(source) + } + } + onSourceRemoved: { + if (source =3D=3D "Battery0") { + disconnectSource(source) + } + } } = - function stringForState(pluggedIn, percent) { - if (pluggedIn) { - if (percent<100) return i18n("%1% (charging)", percent); - else return i18n("%1% (charged)", percent); - } else { + function stringForState(state, percent) { + if (state =3D=3D "Charging") + return i18n("%1% (charging)", percent); + else if (state =3D=3D "Discharging") return i18n("%1% (discharging)", percent); - } + else + return i18n("%1% (charged)", percent); + } = PopupDialog { id: dialogItem percent: pmSource.data["Battery0"]["Percent"] + batteryState: pmSource.data["Battery0"]["State"] hasBattery: pmSource.data["Battery"]["Has Battery"] pluggedIn: pmSource.data["AC Adapter"]["Plugged in"] screenBrightness: pmSource.data["PowerDevil"]["Screen Brightness"]