Changeset View
Changeset View
Standalone View
Standalone View
plasmoid/package/contents/ui/PresentationModeItem.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright (c) 2018 Kai Uwe Broulik <kde@broulik.de> | ||||
3 | * Work sponsored by the LiMux project of | ||||
4 | * the city of Munich. | ||||
5 | * | ||||
6 | * This program is free software; you can redistribute it and/or | ||||
7 | * modify it under the terms of the GNU General Public License as | ||||
8 | * published by the Free Software Foundation; either version 2 of | ||||
9 | * the License or (at your option) version 3 or any later version | ||||
10 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
11 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
12 | * defined in Section 14 of version 3 of the license. | ||||
13 | * | ||||
14 | * This program is distributed in the hope that it will be useful, | ||||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
17 | * GNU General Public License for more details. | ||||
18 | * | ||||
19 | * You should have received a copy of the GNU General Public License | ||||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
21 | * | ||||
22 | */ | ||||
23 | | ||||
24 | import QtQuick 2.8 | ||||
25 | import QtQuick.Layouts 1.1 | ||||
26 | | ||||
27 | import org.kde.plasma.core 2.0 as PlasmaCore | ||||
28 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||||
29 | import org.kde.plasma.extras 2.0 as PlasmaExtras | ||||
30 | | ||||
31 | ColumnLayout { | ||||
32 | spacing: units.smallSpacing | ||||
33 | | ||||
34 | PlasmaExtras.Heading { | ||||
35 | Layout.fillWidth: true | ||||
36 | level: 2 | ||||
37 | text: i18n("Presentation Mode") | ||||
38 | } | ||||
39 | | ||||
40 | PlasmaExtras.DescriptiveLabel { | ||||
41 | Layout.fillWidth: true | ||||
42 | // remove spacing between heading and this descriptive label | ||||
43 | Layout.topMargin: -parent.spacing | ||||
44 | font.pointSize: theme.smallestFont.pointSize | ||||
45 | text: i18n("This will prevent your screen and computer from turning off automatically.") | ||||
46 | wrapMode: Text.WordWrap | ||||
47 | } | ||||
48 | | ||||
49 | PlasmaComponents.CheckBox { | ||||
50 | id: checkBox | ||||
51 | Layout.fillWidth: true | ||||
52 | text: i18n("Enable Presentation Mode") | ||||
53 | | ||||
54 | onCheckedChanged: { | ||||
55 | if (checked === root.presentationModeEnabled) { | ||||
56 | return; | ||||
57 | } | ||||
58 | | ||||
59 | // disable CheckBox while job is running | ||||
60 | checkBox.enabled = false; | ||||
61 | | ||||
62 | var service = pmSource.serviceForSource("PowerDevil"); | ||||
63 | | ||||
64 | if (checked) { | ||||
65 | var op = service.operationDescription("beginSuppressingScreenPowerManagement"); | ||||
66 | op.reason = i18n("User enabled presentation mode"); | ||||
67 | | ||||
68 | var job = service.startOperationCall(op); | ||||
69 | job.finished.connect(function (job) { | ||||
70 | presentationModeCookie = job.result; | ||||
71 | checkBox.enabled = true; | ||||
72 | }); | ||||
73 | } else { | ||||
74 | var op = service.operationDescription("stopSuppressingScreenPowerManagement"); | ||||
75 | op.cookie = presentationModeCookie; | ||||
76 | | ||||
77 | var job = service.startOperationCall(op); | ||||
78 | job.finished.connect(function (job) { | ||||
79 | presentationModeCookie = -1; | ||||
80 | checkBox.enabled = true; | ||||
81 | }); | ||||
82 | } | ||||
83 | } | ||||
84 | } | ||||
85 | | ||||
86 | RowLayout { | ||||
87 | Layout.fillWidth: true | ||||
88 | spacing: units.smallSpacing | ||||
89 | | ||||
90 | PlasmaCore.IconItem { | ||||
91 | Layout.preferredWidth: units.iconSizes.medium | ||||
92 | Layout.preferredHeight: units.iconSizes.medium | ||||
93 | source: pmSource.inhibitions[0] ? pmSource.inhibitions[0].Icon || "" : "" | ||||
94 | visible: valid | ||||
95 | } | ||||
96 | | ||||
97 | PlasmaComponents.Label { | ||||
98 | Layout.fillWidth: true | ||||
99 | Layout.maximumWidth: Math.min(units.gridUnit * 20, implicitWidth) | ||||
100 | font.pointSize: theme.smallestFont.pointSize | ||||
101 | wrapMode: Text.WordWrap | ||||
102 | elide: Text.ElideRight | ||||
103 | textFormat: Text.PlainText | ||||
104 | text: { | ||||
105 | var inhibitions = pmSource.inhibitions; | ||||
106 | if (inhibitions.length > 1) { | ||||
107 | return i18ncp("Some Application and n others enforce presentation mode", | ||||
108 | "%2 and %1 other application are enforcing presentation mode.", | ||||
109 | "%2 and %1 other applications are enforcing presentation mode.", | ||||
110 | inhibitions.length - 1, inhibitions[0].Name) // plural only works on %1 | ||||
111 | } else if (inhibitions.length === 1) { | ||||
112 | if (!inhibitions[0].Reason) { | ||||
113 | return i18nc("Some Application enforce presentation mode", | ||||
114 | "%1 is enforcing presentation mode.", inhibitions[0].Name) | ||||
115 | } else { | ||||
116 | return i18nc("Some Application enforce presentation mode: Reason provided by the app", | ||||
117 | "%1 is enforcing presentation mode: %2", inhibitions[0].Name, inhibitions[0].Reason) | ||||
118 | } | ||||
119 | } else { | ||||
120 | return ""; | ||||
121 | } | ||||
122 | } | ||||
123 | } | ||||
124 | } | ||||
125 | } |