diff --git a/applets/batterymonitor/package/contents/ui/BatteryItem.qml b/applets/batterymonitor/package/contents/ui/BatteryItem.qml index 11eb63d7a..3db05cff6 100644 --- a/applets/batterymonitor/package/contents/ui/BatteryItem.qml +++ b/applets/batterymonitor/package/contents/ui/BatteryItem.qml @@ -1,215 +1,215 @@ /* * Copyright 2012-2013 Daniel Nicoletti * Copyright 2013-2015 Kai Uwe Broulik * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import QtQuick 2.0 import QtQuick.Layouts 1.1 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.plasma.workspace.components 2.0 import org.kde.kcoreaddons 1.0 as KCoreAddons import "logic.js" as Logic Item { id: batteryItem height: childrenRect.height property var battery // NOTE: According to the UPower spec this property is only valid for primary batteries, however // UPower seems to set the Present property false when a device is added but not probed yet readonly property bool isPresent: model["Plugged in"] readonly property bool isBroken: model.Capacity > 0 && model.Capacity < 50 property Component batteryDetails: Flow { // GridLayout crashes with a Repeater in it somehow id: detailsLayout property int leftColumnWidth: 0 width: units.gridUnit * 11 PlasmaComponents.Label { id: brokenBatteryLabel width: parent ? parent.width : implicitWidth wrapMode: Text.WordWrap - text: batteryItem.isBroken && typeof model.Capacity !== "undefined" ? i18n("The capacity of this battery is %1%. This means it is broken and needs a replacement. Please contact your hardware vendor for more details.", model.Capacity) : "" + text: batteryItem.isBroken && typeof model.Capacity !== "undefined" ? i18n("This battery is %1% degraded and should be replaced. Please contact your hardware vendor for more details.", 100 - model.Capacity) : "" font.pointSize: !!detailsLayout.parent.inListView ? theme.smallestFont.pointSize : theme.defaultFont.pointSize visible: batteryItem.isBroken } Repeater { id: detailsRepeater model: Logic.batteryDetails(batteryItem.battery, batterymonitor.remainingTime) PlasmaComponents.Label { id: detailsLabel width: modelData.value && parent ? parent.width - detailsLayout.leftColumnWidth - units.smallSpacing : detailsLayout.leftColumnWidth + units.smallSpacing wrapMode: Text.NoWrap onPaintedWidthChanged: { // horrible HACK to get a column layout if (paintedWidth > detailsLayout.leftColumnWidth) { detailsLayout.leftColumnWidth = paintedWidth } } height: implicitHeight text: modelData.value ? modelData.value : modelData.label states: [ State { when: !!detailsLayout.parent.inListView // HACK PropertyChanges { target: detailsLabel horizontalAlignment: modelData.value ? Text.AlignRight : Text.AlignLeft font.pointSize: theme.smallestFont.pointSize width: parent ? parent.width / 2 : 0 elide: Text.ElideNone // eliding and height: implicitHeight causes loops } } ] } } } Column { width: parent.width spacing: 0 PlasmaCore.ToolTipArea { width: parent.width height: infoRow.height active: !detailsLoader.active z: 2 mainItem: Row { id: batteryItemToolTip property int _s: units.largeSpacing / 2 Layout.minimumWidth: implicitWidth + batteryItemToolTip._s Layout.minimumHeight: implicitHeight + batteryItemToolTip._s * 2 Layout.maximumWidth: implicitWidth + batteryItemToolTip._s Layout.maximumHeight: implicitHeight + batteryItemToolTip._s * 2 width: implicitWidth + batteryItemToolTip._s height: implicitHeight + batteryItemToolTip._s * 2 spacing: batteryItemToolTip._s*2 BatteryIcon { x: batteryItemToolTip._s * 2 y: batteryItemToolTip._s width: units.iconSizes.desktop // looks weird and small but that's what DefaultTooltip uses height: width batteryType: batteryIcon.batteryType percent: batteryIcon.percent hasBattery: batteryIcon.hasBattery pluggedIn: batteryIcon.pluggedIn visible: !batteryItem.isBroken } Column { id: mainColumn x: batteryItemToolTip._s y: batteryItemToolTip._s PlasmaExtras.Heading { level: 3 text: batteryNameLabel.text } Loader { sourceComponent: batteryItem.batteryDetails opacity: 0.5 } } } RowLayout { id: infoRow width: parent.width spacing: units.gridUnit BatteryIcon { id: batteryIcon Layout.alignment: Qt.AlignTop width: units.iconSizes.medium height: width batteryType: model.Type percent: model.Percent hasBattery: batteryItem.isPresent pluggedIn: model.State === "Charging" && model["Is Power Supply"] } Column { Layout.fillWidth: true Layout.alignment: batteryItem.isPresent ? Qt.AlignTop : Qt.AlignVCenter RowLayout { width: parent.width spacing: units.smallSpacing PlasmaComponents.Label { id: batteryNameLabel Layout.fillWidth: true height: implicitHeight elide: Text.ElideRight text: model["Pretty Name"] } PlasmaComponents.Label { text: Logic.stringForBatteryState(model) height: implicitHeight visible: model["Is Power Supply"] opacity: 0.6 } PlasmaComponents.Label { id: batteryPercent height: paintedHeight horizontalAlignment: Text.AlignRight visible: batteryItem.isPresent text: i18nc("Placeholder is battery percentage", "%1%", model.Percent) } } PlasmaComponents.ProgressBar { width: parent.width minimumValue: 0 maximumValue: 100 visible: batteryItem.isPresent value: Number(model.Percent) } } } } Loader { id: detailsLoader property bool inListView: true anchors { left: parent.left leftMargin: batteryIcon.width + units.gridUnit right: parent.right } visible: !!item opacity: 0.5 sourceComponent: batteryDetails } } } diff --git a/applets/batterymonitor/package/contents/ui/logic.js b/applets/batterymonitor/package/contents/ui/logic.js index 7dc671abf..cc587acd3 100644 --- a/applets/batterymonitor/package/contents/ui/logic.js +++ b/applets/batterymonitor/package/contents/ui/logic.js @@ -1,83 +1,83 @@ /* * Copyright 2011 Sebastian Kügler * Copyright 2012 Viranch Mehta * Copyright 2014-2016 Kai Uwe Broulik * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ function stringForBatteryState(batteryData) { if (batteryData["Plugged in"]) { switch(batteryData["State"]) { case "Discharging": return i18n("Discharging"); case "FullyCharged": return i18n("Fully Charged"); case "Charging": return i18n("Charging"); // when in doubt we're not charging default: return i18n("Not Charging"); } } else { return i18nc("Battery is currently not present in the bay","Not present"); } } function batteryDetails(batteryData, remainingTime) { var data = [] if (remainingTime > 0 && batteryData["Is Power Supply"] && (batteryData["State"] == "Discharging" || batteryData["State"] == "Charging")) { data.push({label: (batteryData["State"] == "Charging" ? i18n("Time To Full:") : i18n("Time To Empty:")) }) data.push({value: KCoreAddons.Format.formatDuration(remainingTime, KCoreAddons.FormatTypes.HideSeconds) }) } if (batteryData["Is Power Supply"] && batteryData["Capacity"] != "" && typeof batteryData["Capacity"] == "number") { - data.push({label: i18n("Capacity:") }) - data.push({value: i18nc("Placeholder is battery capacity", "%1%", batteryData["Capacity"]) }) + data.push({label: i18nc("The degradation in the battery's energy capacity", "Capacity degradation:") }) + data.push({value: i18nc("Placeholder is battery's capacity degradation", "%1%", 100 - batteryData["Capacity"]) }) } return data } function updateBrightness(rootItem, source) { if (!source.data["PowerDevil"]) { return; } // we don't want passive brightness change send setBrightness call rootItem.disableBrightnessUpdate = true; if (typeof source.data["PowerDevil"]["Screen Brightness"] === 'number') { rootItem.screenBrightness = source.data["PowerDevil"]["Screen Brightness"]; } if (typeof source.data["PowerDevil"]["Keyboard Brightness"] === 'number') { rootItem.keyboardBrightness = source.data["PowerDevil"]["Keyboard Brightness"]; } rootItem.disableBrightnessUpdate = false; } function updateInhibitions(rootItem, source) { var inhibitions = []; if (source.data["Inhibitions"]) { for(var key in pmSource.data["Inhibitions"]) { if (key === "plasmashell" || key === "plasmoidviewer") { // ignore our own inhibition continue } inhibitions.push(pmSource.data["Inhibitions"][key]) } } rootItem.inhibitions = inhibitions }