Warning, /plasma/plasma-workspace/applets/batterymonitor/package/contents/ui/PowerManagementItem.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2012-2013 Daniel Nicoletti <dantti12@gmail.com>
0003     SPDX-FileCopyrightText: 2013, 2015 Kai Uwe Broulik <kde@privat.broulik.de>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 import QtQuick
0009 import QtQuick.Layouts
0010 
0011 import org.kde.kwindowsystem
0012 import org.kde.plasma.components as PlasmaComponents3
0013 import org.kde.ksvg as KSvg
0014 import org.kde.kirigami as Kirigami
0015 
0016 ColumnLayout {
0017     id: root
0018 
0019     property alias pmCheckBox: pmCheckBox
0020     property alias disabled: pmCheckBox.checked
0021     property bool pluggedIn
0022 
0023     signal inhibitionChangeRequested(bool inhibit)
0024 
0025     // List of active power management inhibitions (applications that are
0026     // blocking sleep and screen locking).
0027     //
0028     // type: [{
0029     //  Icon: string,
0030     //  Name: string,
0031     //  Reason: string,
0032     // }]
0033     property var inhibitions: []
0034     property bool manuallyInhibited
0035     property bool inhibitsLidAction
0036 
0037     // UI to manually inhibit sleep and screen locking
0038     PlasmaComponents3.Switch {
0039         id: pmCheckBox
0040         Layout.fillWidth: true
0041         text: i18nc("Minimize the length of this string as much as possible", "Manually block sleep and screen locking")
0042         checked: root.manuallyInhibited
0043         focus: true
0044 
0045         KeyNavigation.up: dialog.KeyNavigation.up
0046         KeyNavigation.down: batteryList.children[0]
0047         KeyNavigation.backtab: dialog.KeyNavigation.backtab
0048         KeyNavigation.tab: KeyNavigation.down
0049 
0050         onToggled: {
0051             inhibitionChangeRequested(checked)
0052         }
0053     }
0054 
0055     // Separator line
0056     KSvg.SvgItem {
0057         Layout.fillWidth: true
0058 
0059         visible: inhibitionReasonsLayout.visible
0060 
0061         imagePath: "widgets/line"
0062         elementId: "horizontal-line"
0063     }
0064 
0065     // list of automatic inhibitions
0066     ColumnLayout {
0067         id: inhibitionReasonsLayout
0068 
0069         Layout.fillWidth: true
0070         visible: root.inhibitsLidAction || (root.inhibitions.length > 0)
0071 
0072         InhibitionHint {
0073             Layout.fillWidth: true
0074             visible: root.inhibitsLidAction
0075             iconSource: "computer-laptop"
0076             text: i18nc("Minimize the length of this string as much as possible", "Your laptop is configured not to sleep when closing the lid while an external monitor is connected.")
0077         }
0078 
0079         PlasmaComponents3.Label {
0080             id: inhibitionExplanation
0081             Layout.fillWidth: true
0082             visible: root.inhibitions.length > 1
0083             font: Kirigami.Theme.smallFont
0084             wrapMode: Text.WordWrap
0085             elide: Text.ElideRight
0086             maximumLineCount: 3
0087             text: i18np("%1 application is currently blocking sleep and screen locking:",
0088                         "%1 applications are currently blocking sleep and screen locking:",
0089                         root.inhibitions.length)
0090             textFormat: Text.PlainText
0091         }
0092 
0093         Repeater {
0094             model: root.inhibitions
0095 
0096             InhibitionHint {
0097                 property string icon: modelData.Icon
0098                     || (KWindowSystem.isPlatformWayland ? "wayland" : "xorg")
0099                 property string name: modelData.Name
0100                 property string reason: modelData.Reason
0101 
0102                 Layout.fillWidth: true
0103                 iconSource: icon
0104                 text: {
0105                     if (root.inhibitions.length === 1) {
0106                         if (reason && name) {
0107                             return i18n("%1 is currently blocking sleep and screen locking (%2)", name, reason)
0108                         } else if (name) {
0109                             return i18n("%1 is currently blocking sleep and screen locking (unknown reason)", name)
0110                         } else if (reason) {
0111                             return i18n("An application is currently blocking sleep and screen locking (%1)", reason)
0112                         } else {
0113                             return i18n("An application is currently blocking sleep and screen locking (unknown reason)")
0114                         }
0115                     } else {
0116                         if (reason && name) {
0117                             return i18nc("Application name: reason for preventing sleep and screen locking", "%1: %2", name, reason)
0118                         } else if (name) {
0119                             return i18nc("Application name: reason for preventing sleep and screen locking", "%1: unknown reason", name)
0120                         } else if (reason) {
0121                             return i18nc("Application name: reason for preventing sleep and screen locking", "Unknown application: %1", reason)
0122                         } else {
0123                             return i18nc("Application name: reason for preventing sleep and screen locking", "Unknown application: unknown reason")
0124                         }
0125                     }
0126                 }
0127             }
0128         }
0129     }
0130 }