diff --git a/applets/batterymonitor/package/contents/ui/PowerManagementItem.qml b/applets/batterymonitor/package/contents/ui/PowerManagementItem.qml index 29d9e8557..08cfbd0ff 100755 --- a/applets/batterymonitor/package/contents/ui/PowerManagementItem.qml +++ b/applets/batterymonitor/package/contents/ui/PowerManagementItem.qml @@ -1,123 +1,124 @@ /* * 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 Components import org.kde.kquickcontrolsaddons 2.0 Column { property alias enabled: pmCheckBox.checked spacing: 0 RowLayout { width: parent.width spacing: units.gridUnit MouseArea { Layout.fillWidth: true height: childrenRect.height onClicked: { pmCheckBox.forceActiveFocus() pmCheckBox.checked = !pmCheckBox.checked } PlasmaCore.ToolTipArea { anchors.fill: parent subText: i18n("Disabling power management will prevent your screen and computer from turning off automatically.\n\nMost applications will automatically suppress power management when they don't want to have you interrupted.") } RowLayout { width: parent.width spacing: units.gridUnit Item { width: units.iconSizes.medium height: width Components.CheckBox { id: pmCheckBox anchors.centerIn: parent checked: true // we don't want to mess with the checked state but still reflect that changing it might not yield the desired result opacity: inhibitions.length > 0 ? 0.5 : 1 Behavior on opacity { NumberAnimation { duration: units.longDuration } } } } Components.Label { Layout.fillWidth: true text: i18n("Enable Power Management") } } } Components.ToolButton { iconSource: "configure" onClicked: batterymonitor.action_powerdevilkcm() tooltip: i18n("Configure Power Saving...") + visible: batterymonitor.kcmsAuthorized } } Column { anchors { left: parent.left leftMargin: units.iconSizes.medium + units.gridUnit right: parent.right } spacing: units.smallSpacing InhibitionHint { width: parent.width visible: pmSource.data["PowerDevil"] && pmSource.data["PowerDevil"]["Is Lid Present"] && !pmSource.data["PowerDevil"]["Triggers Lid Action"] iconSource: "computer-laptop" text: i18n("Your notebook is configured not to suspend when closing the lid while an external monitor is connected.") } InhibitionHint { width: parent.width visible: inhibitions.length > 0 iconSource: inhibitions.length > 0 ? inhibitions[0].Icon || "" : "" text: { if (inhibitions.length > 1) { return i18ncp("Some Application and n others are currently suppressing PM", "%2 and %1 other application are currently suppressing power management.", "%2 and %1 other applications are currently suppressing power management.", inhibitions.length - 1, inhibitions[0].Name) // plural only works on %1 } else if (inhibitions.length === 1) { if (!inhibitions[0].Reason) { return i18nc("Some Application is suppressing PM", "%1 is currently suppressing power management.", inhibitions[0].Name) } else { return i18nc("Some Application is suppressing PM: Reason provided by the app", "%1 is currently suppressing power management: %2", inhibitions[0].Name, inhibitions[0].Reason) } } else { return "" } } } } } diff --git a/applets/batterymonitor/package/contents/ui/batterymonitor.qml b/applets/batterymonitor/package/contents/ui/batterymonitor.qml index 961325d09..11a6fe6c2 100755 --- a/applets/batterymonitor/package/contents/ui/batterymonitor.qml +++ b/applets/batterymonitor/package/contents/ui/batterymonitor.qml @@ -1,252 +1,260 @@ /* * 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.plasmoid 2.0 import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.kcoreaddons 1.0 as KCoreAddons import org.kde.kquickcontrolsaddons 2.0 import "logic.js" as Logic Item { id: batterymonitor Plasmoid.switchWidth: units.gridUnit * 10 Plasmoid.switchHeight: units.gridUnit * 10 LayoutMirroring.enabled: Qt.application.layoutDirection == Qt.RightToLeft LayoutMirroring.childrenInherit: true Plasmoid.status: { if (powermanagementDisabled) { return PlasmaCore.Types.ActiveStatus } if (pmSource.data.Battery["Has Cumulative"]) { if (pmSource.data.Battery.State !== "Charging" && pmSource.data.Battery.Percent <= 5) { return PlasmaCore.Types.NeedsAttentionStatus } else if (pmSource.data["Battery"]["State"] !== "FullyCharged") { return PlasmaCore.Types.ActiveStatus } } return PlasmaCore.Types.PassiveStatus } Plasmoid.toolTipMainText: { if (batteries.count === 0) { return i18n("No Batteries Available"); } else if (!pmSource.data["Battery"]["Has Cumulative"]) { // Bug 362924: Distinguish between no batteries and no power supply batteries // just show the generic applet title in the latter case return i18n("Battery and Brightness") } else if (pmSource.data["Battery"]["State"] === "FullyCharged") { return i18n("Fully Charged"); } else if (pmSource.data["AC Adapter"] && pmSource.data["AC Adapter"]["Plugged in"]) { var percent = pmSource.data.Battery.Percent var state = pmSource.data.Battery.State if (state === "Charging") { return i18n("%1%. Charging", percent) } else if (state === "NoCharge") { return i18n("%1%. Plugged in, not Charging", percent) } else { return i18n("%1%. Plugged in", percent) } } else { if (remainingTime > 0) { return i18nc("%1 is remaining time, %2 is percentage", "%1 Remaining (%2%)", KCoreAddons.Format.formatDuration(remainingTime, KCoreAddons.FormatTypes.HideSeconds), pmSource.data["Battery"]["Percent"]) } else { return i18n("%1% Battery Remaining", pmSource.data["Battery"]["Percent"]); } } } Plasmoid.toolTipSubText: powermanagementDisabled ? i18n("Power management is disabled") : "" Plasmoid.icon: "battery" property bool disableBrightnessUpdate: false property int screenBrightness readonly property int maximumScreenBrightness: pmSource.data["PowerDevil"] ? pmSource.data["PowerDevil"]["Maximum Screen Brightness"] || 0 : 0 property int keyboardBrightness readonly property int maximumKeyboardBrightness: pmSource.data["PowerDevil"] ? pmSource.data["PowerDevil"]["Maximum Keyboard Brightness"] || 0 : 0 readonly property int remainingTime: Number(pmSource.data["Battery"]["Remaining msec"]) property bool powermanagementDisabled: false property var inhibitions: [] + readonly property var kcms: ["powerdevilprofilesconfig.desktop", + "powerdevilactivitiesconfig.desktop", + "powerdevilglobalconfig.desktop"] + readonly property bool kcmsAuthorized: KCMShell.authorize(batterymonitor.kcms).length > 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); } onKeyboardBrightnessChanged: { if (disableBrightnessUpdate) { return; } var service = pmSource.serviceForSource("PowerDevil"); var operation = service.operationDescription("setKeyboardBrightness"); operation.brightness = keyboardBrightness; operation.silent = plasmoid.expanded service.startOperationCall(operation); } function action_powerdevilkcm() { - KCMShell.open(["powerdevilprofilesconfig", "powerdevilactivitiesconfig", "powerdevilglobalconfig"]); + KCMShell.open(batterymonitor.kcms); } Component.onCompleted: { Logic.updateBrightness(batterymonitor, pmSource); plasmoid.removeAction("configure"); - plasmoid.setAction("powerdevilkcm", i18n("&Configure Power Saving..."), "preferences-system-power-management"); Logic.updateInhibitions(batterymonitor, pmSource) + + if (batterymonitor.kcmsAuthorized) { + plasmoid.setAction("powerdevilkcm", i18n("&Configure Power Saving..."), "preferences-system-power-management"); + } } Plasmoid.compactRepresentation: CompactRepresentation { property int wheelDelta: 0 onEntered: wheelDelta = 0 onExited: wheelDelta = 0 onWheel: { var delta = wheel.angleDelta.y || wheel.angleDelta.x if ((delta < 0 && wheelDelta > 0) || (delta > 0 && wheelDelta < 0)) { // reset when direction changes wheelDelta = 0 } wheelDelta += delta; // magic number 120 for common "one click" // See: http://qt-project.org/doc/qt-5/qml-qtquick-wheelevent.html#angleDelta-prop var increment = 0; while (wheelDelta >= 120) { wheelDelta -= 120; increment++; } while (wheelDelta <= -120) { wheelDelta += 120; increment--; } if (increment != 0) { var maximumBrightness = batterymonitor.maximumScreenBrightness // Don't allow the UI to turn off the screen // Please see https://git.reviewboard.kde.org/r/122505/ for more information var minimumBrightness = (maximumBrightness > 100 ? 1 : 0) var steps = Math.max(1, Math.round(maximumBrightness / 20)) batterymonitor.screenBrightness = Math.max(minimumBrightness, Math.min(maximumBrightness, batterymonitor.screenBrightness + increment * steps)); } } } property QtObject pmSource: PlasmaCore.DataSource { id: pmSource engine: "powermanagement" connectedSources: sources onSourceAdded: { disconnectSource(source); connectSource(source); } onSourceRemoved: { disconnectSource(source); } onDataChanged: { Logic.updateBrightness(batterymonitor, pmSource) Logic.updateInhibitions(batterymonitor, pmSource) } } property QtObject batteries: PlasmaCore.SortFilterModel { id: batteries filterRole: "Is Power Supply" sortOrder: Qt.DescendingOrder sourceModel: PlasmaCore.SortFilterModel { sortRole: "Pretty Name" sortOrder: Qt.AscendingOrder sortCaseSensitivity: Qt.CaseInsensitive sourceModel: PlasmaCore.DataModel { dataSource: pmSource sourceFilter: "Battery[0-9]+" } } } Plasmoid.fullRepresentation: PopupDialog { id: dialogItem Layout.minimumWidth: units.iconSizes.medium * 9 Layout.minimumHeight: units.gridUnit * 15 // TODO Probably needs a sensible preferredHeight too model: plasmoid.expanded ? batteries : null anchors.fill: parent focus: true isBrightnessAvailable: pmSource.data["PowerDevil"]["Screen Brightness Available"] ? true : false isKeyboardBrightnessAvailable: pmSource.data["PowerDevil"]["Keyboard Brightness Available"] ? true : false pluggedIn: pmSource.data["AC Adapter"] != undefined && pmSource.data["AC Adapter"]["Plugged in"] property int cookie1: -1 property int cookie2: -1 onPowermanagementChanged: { var service = pmSource.serviceForSource("PowerDevil"); if (checked) { var op1 = service.operationDescription("stopSuppressingSleep"); op1.cookie = cookie1; var op2 = service.operationDescription("stopSuppressingScreenPowerManagement"); op2.cookie = cookie2; var job1 = service.startOperationCall(op1); job1.finished.connect(function(job) { cookie1 = -1; }); var job2 = service.startOperationCall(op2); job2.finished.connect(function(job) { cookie2 = -1; }); } else { var reason = i18n("The battery applet has enabled system-wide inhibition"); var op1 = service.operationDescription("beginSuppressingSleep"); op1.reason = reason; var op2 = service.operationDescription("beginSuppressingScreenPowerManagement"); op2.reason = reason; var job1 = service.startOperationCall(op1); job1.finished.connect(function(job) { cookie1 = job.result; }); var job2 = service.startOperationCall(op2); job2.finished.connect(function(job) { cookie2 = job.result; }); } batterymonitor.powermanagementDisabled = !checked } } } diff --git a/applets/digital-clock/package/contents/ui/main.qml b/applets/digital-clock/package/contents/ui/main.qml index e4ff86fba..b62ee2064 100644 --- a/applets/digital-clock/package/contents/ui/main.qml +++ b/applets/digital-clock/package/contents/ui/main.qml @@ -1,93 +1,97 @@ /* * Copyright 2013 Heena Mahour * Copyright 2013 Sebastian Kügler * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, 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 General Public License * along with this program. If not, see . */ import QtQuick 2.0 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.components 2.0 as PlasmaComponents import org.kde.plasma.extras 2.0 as PlasmaExtras import org.kde.kquickcontrolsaddons 2.0 import org.kde.plasma.private.digitalclock 1.0 import org.kde.kquickcontrolsaddons 2.0 import org.kde.plasma.calendar 2.0 as PlasmaCalendar Item { id: root width: units.gridUnit * 10 height: units.gridUnit * 4 property string dateFormatString: setDateFormatString() property date tzDate: { // get the time for the given timezone from the dataengine var now = dataSource.data[plasmoid.configuration.lastSelectedTimezone]["DateTime"]; // get current UTC time var msUTC = now.getTime() + (now.getTimezoneOffset() * 60000); // add the dataengine TZ offset to it return new Date(msUTC + (dataSource.data[plasmoid.configuration.lastSelectedTimezone]["Offset"] * 1000)); } Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation Plasmoid.compactRepresentation: DigitalClock { } Plasmoid.fullRepresentation: CalendarView { } Plasmoid.toolTipItem: Loader { id: tooltipLoader Layout.minimumWidth: item.width Layout.maximumWidth: item.width Layout.minimumHeight: item.height Layout.maximumHeight: item.height source: "Tooltip.qml" } PlasmaCore.DataSource { id: dataSource engine: "time" connectedSources: plasmoid.configuration.selectedTimeZones interval: plasmoid.configuration.showSeconds ? 1000 : 60000 intervalAlignment: plasmoid.configuration.showSeconds ? PlasmaCore.Types.NoAlignment : PlasmaCore.Types.AlignToMinute } function setDateFormatString() { // remove "dddd" from the locale format string // /all/ locales in LongFormat have "dddd" either // at the beginning or at the end. so we just // remove it + the delimiter and space var format = Qt.locale().dateFormat(Locale.LongFormat); format = format.replace(/(^dddd.?\s)|(,?\sdddd$)/, ""); return format; } function action_clockkcm() { KCMShell.open("clock"); } function action_formatskcm() { KCMShell.open("formats"); } Component.onCompleted: { - plasmoid.setAction("clockkcm", i18n("Adjust Date and Time..."), "preferences-system-time"); - plasmoid.setAction("formatskcm", i18n("Set Time Format...")); + if (KCMShell.authorize("clock.desktop").length > 0) { + plasmoid.setAction("clockkcm", i18n("Adjust Date and Time..."), "preferences-system-time"); + } + if (KCMShell.authorize("formats.desktop").length > 0) { + plasmoid.setAction("formatskcm", i18n("Set Time Format...")); + } // Set the list of enabled plugins from config // to the manager PlasmaCalendar.EventPluginsManager.enabledPlugins = plasmoid.configuration.enabledCalendarPlugins; } }