applets/batterymonitor: Improve for desktop systems

As it was so far, it looked like the system was malfunctioning because
we were showing a battery with a big fat red mark. If there's no battery
we can show the default icon.

As for the name, we only say "battery and brightness" when there's
both of them. Otherwise we show either title.

If neither batteries nor brightness are available, we mark the applet as
passive so people can at least still access the power management blocking
checkbox which lives here.

BUG: 415073
FIXED-IN: 5.24
wilder-5.24
Aleix Pol Gonzalez 4 years ago committed by Nate Graham
parent eec26a0dcd
commit f9e39815dc
  1. 23
      applets/batterymonitor/package/contents/ui/main.qml

@ -20,6 +20,9 @@ Item {
id: batterymonitor id: batterymonitor
Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 10 Plasmoid.switchWidth: PlasmaCore.Units.gridUnit * 10
Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 10 Plasmoid.switchHeight: PlasmaCore.Units.gridUnit * 10
Plasmoid.title: (hasBatteries === hasBrightness ? i18n("Battery and Brightness") :
hasBrightness ? i18n("Brightness") :
hasBatteries ? i18n("Battery") : "")
LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft
LayoutMirroring.childrenInherit: true LayoutMirroring.childrenInherit: true
@ -37,8 +40,11 @@ Item {
return PlasmaCore.Types.PassiveStatus; return PlasmaCore.Types.PassiveStatus;
} }
readonly property bool hasBatteries: batteries.count > 0 && pmSource.data["Battery"]["Has Cumulative"]
readonly property bool hasBrightness: isBrightnessAvailable || isKeyboardBrightnessAvailable
Plasmoid.toolTipMainText: { Plasmoid.toolTipMainText: {
if (batteries.count === 0 || !pmSource.data["Battery"]["Has Cumulative"]) { if (!hasBatteries) {
return plasmoid.title return plasmoid.title
} else if (pmSource.data["Battery"]["State"] === "FullyCharged") { } else if (pmSource.data["Battery"]["State"] === "FullyCharged") {
return i18n("Fully Charged"); return i18n("Fully Charged");
@ -87,7 +93,7 @@ Item {
return parts.join("\n"); return parts.join("\n");
} }
Plasmoid.icon: "battery" Plasmoid.icon: !hasBatteries && hasBrightness ? "high-brightness" : "battery"
property bool disableBrightnessUpdate: true property bool disableBrightnessUpdate: true
@ -212,8 +218,15 @@ Item {
} }
} }
Plasmoid.compactRepresentation: CompactRepresentation {} Component {
id: batteryCompact
CompactRepresentation {}
}
Plasmoid.compactRepresentation: hasBatteries ? batteryCompact : null
readonly property bool isBrightnessAvailable: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Screen Brightness Available"] ? true : false
readonly property bool isKeyboardBrightnessAvailable: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Keyboard Brightness Available"] ? true : false
Plasmoid.fullRepresentation: PopupDialog { Plasmoid.fullRepresentation: PopupDialog {
id: dialogItem id: dialogItem
Layout.minimumWidth: PlasmaCore.Units.iconSizes.medium * 9 Layout.minimumWidth: PlasmaCore.Units.iconSizes.medium * 9
@ -223,8 +236,8 @@ Item {
model: plasmoid.expanded ? batteries : null model: plasmoid.expanded ? batteries : null
focus: true focus: true
isBrightnessAvailable: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Screen Brightness Available"] ? true : false isBrightnessAvailable: batterymonitor.isBrightnessAvailable
isKeyboardBrightnessAvailable: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Keyboard Brightness Available"] ? true : false isKeyboardBrightnessAvailable: batterymonitor.isKeyboardBrightnessAvailable
pluggedIn: pmSource.data["AC Adapter"] !== undefined && pmSource.data["AC Adapter"]["Plugged in"] pluggedIn: pmSource.data["AC Adapter"] !== undefined && pmSource.data["AC Adapter"]["Plugged in"]
remainingTime: batterymonitor.remainingTime remainingTime: batterymonitor.remainingTime

Loading…
Cancel
Save