diff --git a/applets/battery/CMakeLists.txt b/applets/battery/CMakeLists.txt new file mode 100644 index 00000000..a7f39f43 --- /dev/null +++ b/applets/battery/CMakeLists.txt @@ -0,0 +1 @@ +plasma_install_package(package org.kde.plasma.phone.battery) diff --git a/applets/battery/Messages.sh b/applets/battery/Messages.sh new file mode 100755 index 00000000..72996c88 --- /dev/null +++ b/applets/battery/Messages.sh @@ -0,0 +1,4 @@ +#! /usr/bin/env bash +$EXTRACTRC `find . -name \*.rc -o -name \*.ui -o -name \*.kcfg` >> rc.cpp +$XGETTEXT `find . -name \*.js -o -name \*.qml -o -name \*.cpp` -o $podir/plasma_applet_org.kde.plasma.phone.battery.pot +rm -f rc.cpp diff --git a/applets/battery/package/contents/ui/ExpandedRepresentation.qml b/applets/battery/package/contents/ui/ExpandedRepresentation.qml new file mode 100644 index 00000000..5747c263 --- /dev/null +++ b/applets/battery/package/contents/ui/ExpandedRepresentation.qml @@ -0,0 +1,197 @@ +/* + * Copyright 2011 Sebastian Kügler + * Copyright 2011 Viranch Mehta + * 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.kquickcontrolsaddons 2.0 +import org.kde.plasma.workspace.components 2.0 + +FocusScope { + id: dialog + focus: true + + //property alias model: batteryList.model + property bool pluggedIn + + property int remainingTime + + property bool isBrightnessAvailable: false // FIXME: brightness... + + property QtObject model: pmSource.data["Battery0"] + + Component.onCompleted: { + // setup handler on slider value manually to avoid change on creation + + brightnessSlider.valueChanged.connect(function() { + batterymonitor.screenBrightness = brightnessSlider.value + }) + } + + Column { + id: settingsColumn + anchors.fill: parent + spacing: Math.round(units.gridUnit / 2) + + PlasmaComponents.Label { + // this is just for metrics, TODO use TextMetrics in 5.4 instead + id: percentageMeasurementLabel + text: i18nc("Used for measurement", "100%") + visible: false + } + RowLayout { + id: infoRow + width: parent.width + spacing: units.gridUnit + + BatteryIcon { + id: batteryIcon + Layout.alignment: Qt.AlignTop + width: units.iconSizes.large + height: width + batteryType: model["Type"] + percent: pmSource.data["Battery0"]["Percent"] + hasBattery: true + pluggedIn: pmSource.data["Battery0"]["State"] === "Charging" && pmSource.data["Battery0"]["Is Power Supply"] + } + + Column { + Layout.fillWidth: true + Layout.alignment: Qt.AlignTop + + + RowLayout { + width: parent.width + height: units.gridUnit + spacing: units.smallSpacing + +// Rectangle { +// color: "blue" +// opacity: 0.4 +// anchors.fill: parent +// } + + PlasmaComponents.Label { + id: batteryNameLabel + Layout.fillWidth: true + height: implicitHeight + elide: Text.ElideRight + text: model["Pretty Name"] + } + + PlasmaComponents.Label { + text: stringForBatteryState(pmSource.data["Battery0"]) + 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%", pmSource.data["Battery"]["Percent"]) + } + } + + PlasmaComponents.ProgressBar { + width: parent.width + minimumValue: 0 + maximumValue: 100 + visible: model["Plugged in"] + value: Number(pmSource.data["Battery0"]["Percent"]) + } + } + } + + RowLayout { + + visible: isBrightnessAvailable + + property alias icon: brightnessIcon.source + property alias label: brightnessLabel.text + property alias value: brightnessSlider.value + property alias maximumValue: brightnessSlider.maximumValue + width: parent.width + + icon: "video-display-brightness" + label: i18n("Screen Brightness") + value: batterymonitor.screenBrightness + maximumValue: batterymonitor.maximumScreenBrightness + // KeyNavigation.tab: keyboardBrightnessSlider + // KeyNavigation.backtab: batteryList + + // Manually dragging the slider around breaks the binding + spacing: units.gridUnit + + PlasmaCore.IconItem { + id: brightnessIcon + Layout.alignment: Qt.AlignTop + width: units.iconSizes.medium + height: width + } + + Column { + id: brightnessColumn + Layout.fillWidth: true + Layout.alignment: Qt.AlignTop + spacing: 0 + + PlasmaComponents.Label { + id: brightnessLabel + width: parent.width + height: paintedHeight + } + + PlasmaComponents.Slider { + id: brightnessSlider + width: parent.width + // Don't allow the slider to turn off the screen + // Please see https://git.reviewboard.kde.org/r/122505/ for more information + minimumValue: maximumValue > 100 ? 1 : 0 + stepSize: 1 + } + } + Connections { + target: batterymonitor + onScreenBrightnessChanged: brightnessSlider.value = batterymonitor.screenBrightness + } + } + /* + PlasmaExtras.Heading { + anchors { + left: parent.left + leftMargin: -Math.round(units.gridUnit / 2) + right: parent.right + } + level: 3 + opacity: 0.6 + visible: !isBrightnessAvailable + text: i18n("Changing screen brightness is not supported") + wrapMode: Text.Wrap + } + */ + } +} diff --git a/applets/battery/package/contents/ui/battery.qml b/applets/battery/package/contents/ui/battery.qml new file mode 100644 index 00000000..be3d8110 --- /dev/null +++ b/applets/battery/package/contents/ui/battery.qml @@ -0,0 +1,155 @@ +/* + * Copyright 2011, 2015 Sebastian Kügler + * Copyright 2011 Viranch Mehta + * 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.2 +import QtQuick.Layouts 1.1 +import org.kde.plasma.plasmoid 2.0 +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.workspace.components 2.0 + + +Item { + id: batterymonitor + width: units.gridUnit * 11 + height: units.gridUnit * 11 + Plasmoid.switchWidth: units.gridUnit * 10 + Plasmoid.switchHeight: units.gridUnit * 10 + + LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft + LayoutMirroring.childrenInherit: true + + property bool disableBrightnessUpdate: false + + property int screenBrightness + readonly property int maximumScreenBrightness: pmSource.data["PowerDevil"] ? pmSource.data["PowerDevil"]["Maximum Screen Brightness"] || 0 : 0 + + + onScreenBrightnessChanged: { + if (disableBrightnessUpdate) { + return; + } + var service = pmSource.serviceForSource("PowerDevil"); + var operation = service.operationDescription("setBrightness"); + operation.brightness = screenBrightness; + // show OSD only when the plasmoid isn't expanded since the moving slider is feedback enough + operation.silent = plasmoid.expanded + service.startOperationCall(operation); + } + + function action_powerdevilkcm() { + // FIXME: replace + KCMShell.open(["powerdevilprofilesconfig", "powerdevilactivitiesconfig", "powerdevilglobalconfig"]); + } + + function updateBrightness(rootItem, source) { + if (!source.data["PowerDevil"]) { + print("No 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"]; + } + rootItem.disableBrightnessUpdate = false; + } + + Component.onCompleted: { + updateBrightness(batterymonitor, pmSource); + plasmoid.removeAction("configure"); + plasmoid.setAction("powerdevilkcm", i18n("&Configure Power Saving..."), "preferences-system-power-management"); + } + + function updateLogic() { + plasmoid.status = plasmoidStatus(); +// Logic.updateTooltip(batterymonitor.remainingTime); + } + + function stringForBatteryState(batteryData) { + if (batteryData["Plugged in"]) { + switch(batteryData["State"]) { + case "NoCharge": return i18n("Not Charging"); + case "Discharging": return i18n("Discharging"); + case "FullyCharged": return i18n("Fully Charged"); + default: return i18n("Charging"); + } + } else { + return i18nc("Battery is currently not present in the bay","Not present"); + } + } + + function plasmoidStatus() { + var status = PlasmaCore.Types.PassiveStatus; + if (powermanagementDisabled) { + status = PlasmaCore.Types.ActiveStatus; + } + + if (pmSource.data["Battery"]["Has Cumulative"]) { + if (pmSource.data["Battery"]["State"] !== "Charging" && pmSource.data["Battery"]["Percent"] <= 5) { + status = PlasmaCore.Types.NeedsAttentionStatus + } else if (pmSource.data["Battery"]["State"] !== "FullyCharged") { + status = PlasmaCore.Types.ActiveStatus + } + } + + return status; + } + + Plasmoid.compactRepresentation: BatteryIcon { + id: batteryIcon + Layout.minimumHeight: units.iconSizes.small + anchors.horizontalCenter: parent.horizontalCenter + hasBattery: true + percent: pmSource.data["Battery"]["Percent"] + //pluggedIn: batteryContainer.pluggedIn +// height: batteryContainer.iconSize +// width: height + } + + Plasmoid.fullRepresentation: ExpandedRepresentation { + + + } + + property QtObject pmSource: PlasmaCore.DataSource { + id: pmSource + engine: "powermanagement" + connectedSources: sources + onSourceAdded: { + disconnectSource(source); + connectSource(source); + } + onSourceRemoved: { + disconnectSource(source); + } + /* FIXME: Brightness-related, but needs support lower in the stack first + onDataChanged: { + updateBrightness(batterymonitor, pmSource) + } + Component.onCompleted: { + print("Connecting powerdevil"); + connectSource("PowerDevil"); + } + */ + } +} diff --git a/applets/battery/package/metadata.desktop b/applets/battery/package/metadata.desktop new file mode 100644 index 00000000..3d33b94c --- /dev/null +++ b/applets/battery/package/metadata.desktop @@ -0,0 +1,24 @@ +[Desktop Entry] +Name=Battery and Brightness +Comment=See the power status of your device +Encoding=UTF-8 +Keywords=Power Management;Battery;System;Energy;Device; +Icon=battery +Type=Service +X-KDE-ServiceTypes=Plasma/Applet,Plasma/PopupApplet +X-Plasma-API=declarativeappletscript + +X-Plasma-MainScript=ui/battery.qml +X-Plasma-NotificationArea=true +X-Plasma-Provides=org.kde.plasma.powermanagement + +X-KDE-PluginInfo-Author=Sebastian Kügler +X-KDE-PluginInfo-Category=System Information +X-KDE-PluginInfo-Email=sebas@kde.org +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-Name=org.kde.plasma.phone.battery +X-KDE-PluginInfo-Version=1.0 +X-KDE-PluginInfo-Website=http://vizZzion.org +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-EnabledByDefault=true +X-Plasma-DBusActivationService=org.kde.Solid.PowerManagement