on 6337d13 help sign in
unity8/qml/Components/Dialogs.qml
274 lines 8.5 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17import QtQuick 2.0
19import Unity.Application 0.1
20import Unity.Session 0.1
21import GlobalShortcut 1.0
22import Ubuntu.Components 1.3
23import Unity.Platform 1.0
24import "../Greeter"
26Item {
27 id: root
29 // to be set from outside, useful mostly for testing purposes
30 property var unitySessionService: DBusUnitySessionService
31 property var closeAllApps: function() {
32 while (true) {
33 var app = ApplicationManager.get(0);
34 if (app === null) {
35 break;
36 }
37 ApplicationManager.stopApplication(app.appId);
38 }
39 }
40 property string usageScenario
42 signal powerOffClicked();
44 function showPowerDialog() {
45 d.showPowerDialog();
46 }
48 GlobalShortcut { // reboot/shutdown dialog
49 shortcut: Qt.Key_PowerDown
50 active: Platform.isPC
51 onTriggered: root.unitySessionService.RequestShutdown()
52 }
54 GlobalShortcut { // reboot/shutdown dialog
55 shortcut: Qt.Key_PowerOff
56 active: Platform.isPC
57 onTriggered: root.unitySessionService.RequestShutdown()
58 }
60 GlobalShortcut { // sleep
61 shortcut: Qt.Key_Sleep
62 onTriggered: root.unitySessionService.Suspend()
63 }
65 GlobalShortcut { // hibernate
66 shortcut: Qt.Key_Hibernate
67 onTriggered: root.unitySessionService.Hibernate()
68 }
70 GlobalShortcut { // logout/lock dialog
71 shortcut: Qt.Key_LogOff
72 onTriggered: root.unitySessionService.RequestLogout()
73 }
75 GlobalShortcut { // logout/lock dialog
76 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_Delete
77 onTriggered: root.unitySessionService.RequestLogout()
78 }
80 GlobalShortcut { // lock screen
81 shortcut: Qt.Key_ScreenSaver
82 onTriggered: lightDM.greeter.showGreeter()
83 }
85 GlobalShortcut { // lock screen
86 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
87 onTriggered: lightDM.greeter.showGreeter()
88 }
90 QtObject {
91 id: d // private stuff
92 objectName: "dialogsPrivate"
94 function showPowerDialog() {
95 if (!dialogLoader.active) {
96 dialogLoader.sourceComponent = powerDialogComponent;
97 dialogLoader.focus = true;
98 dialogLoader.active = true;
99 }
100 }
101 }
103 Loader {
104 id: dialogLoader
105 objectName: "dialogLoader"
106 anchors.fill: parent
107 active: false
108 }
110 LightDM {id: lightDM} // Provide backend access
112 Component {
113 id: logoutDialogComponent
114 ShellDialog {
115 id: logoutDialog
116 title: i18n.ctr("Title: Lock/Log out dialog", "Log out")
117 text: i18n.tr("Are you sure you want to log out?")
118 Button {
119 text: i18n.ctr("Button: Lock the system", "Lock")
120 onClicked: {
121 lightDM.greeter.showGreeter()
122 logoutDialog.hide();
123 }
124 }
125 Button {
126 text: i18n.ctr("Button: Log out from the system", "Log Out")
127 onClicked: {
128 unitySessionService.logout();
129 logoutDialog.hide();
130 }
131 }
132 Button {
133 text: i18n.tr("Cancel")
134 onClicked: {
135 logoutDialog.hide();
136 }
137 }
138 }
139 }
141 Component {
142 id: shutdownDialogComponent
143 ShellDialog {
144 id: shutdownDialog
145 title: i18n.ctr("Title: Reboot/Shut down dialog", "Shut down")
146 text: i18n.tr("Are you sure you want to shut down?")
147 Button {
148 text: i18n.ctr("Button: Reboot the system", "Reboot")
149 onClicked: {
150 root.closeAllApps();
151 unitySessionService.reboot();
152 shutdownDialog.hide();
153 }
154 color: UbuntuColors.lightGrey
155 }
156 Button {
157 text: i18n.ctr("Button: Shut down the system", "Shut down")
158 onClicked: {
159 root.closeAllApps();
160 unitySessionService.shutdown();
161 shutdownDialog.hide();
162 }
163 color: UbuntuColors.red
164 }
165 Button {
166 text: i18n.tr("Cancel")
167 onClicked: {
168 shutdownDialog.hide();
169 }
170 color: UbuntuColors.lightGrey
171 }
172 }
173 }
175 Component {
176 id: rebootDialogComponent
177 ShellDialog {
178 id: rebootDialog
179 title: i18n.ctr("Title: Reboot dialog", "Reboot")
180 text: i18n.tr("Are you sure you want to reboot?")
181 Button {
182 text: i18n.tr("No")
183 onClicked: {
184 rebootDialog.hide();
185 }
186 color: UbuntuColors.lightGrey
187 }
188 Button {
189 text: i18n.tr("Yes")
190 onClicked: {
191 root.closeAllApps();
192 unitySessionService.reboot();
193 rebootDialog.hide();
194 }
195 color: UbuntuColors.red
196 }
197 }
198 }
200 Component {
201 id: powerDialogComponent
202 ShellDialog {
203 id: powerDialog
204 title: i18n.ctr("Title: Power off/Restart dialog", "Power")
205 text: i18n.tr("Are you sure you would like\nto power off?")
206 Button {
207 text: i18n.ctr("Button: Power off the system", "Power off")
208 onClicked: {
209 root.closeAllApps();
210 powerDialog.hide();
211 root.powerOffClicked();
212 }
213 color: UbuntuColors.red
214 }
215 Button {
216 text: i18n.ctr("Button: Restart the system", "Restart")
217 onClicked: {
218 root.closeAllApps();
219 unitySessionService.reboot();
220 powerDialog.hide();
221 }
222 color: UbuntuColors.lightGrey
223 }
224 Button {
225 text: i18n.tr("Cancel")
226 onClicked: {
227 powerDialog.hide();
228 }
229 color: UbuntuColors.lightGrey
230 }
231 }
232 }
234 Connections {
235 target: root.unitySessionService
237 onLogoutRequested: {
238 // Display a dialog to ask the user to confirm.
239 if (!dialogLoader.active) {
240 dialogLoader.sourceComponent = logoutDialogComponent;
241 dialogLoader.focus = true;
242 dialogLoader.active = true;
243 }
244 }
246 onShutdownRequested: {
247 // Display a dialog to ask the user to confirm.
248 if (!dialogLoader.active) {
249 dialogLoader.sourceComponent = shutdownDialogComponent;
250 dialogLoader.focus = true;
251 dialogLoader.active = true;
252 }
253 }
255 onRebootRequested: {
256 // Display a dialog to ask the user to confirm.
257 if (!dialogLoader.active) {
258 // display a combined reboot/shutdown dialog, sadly the session indicator calls rather the "Reboot()" method
259 // than shutdown when clicking on the "Shutdown..." menu item
260 // FIXME: when/if session indicator is fixed, put the rebootDialogComponent here
261 dialogLoader.sourceComponent = shutdownDialogComponent;
262 dialogLoader.focus = true;
263 dialogLoader.active = true;
264 }
265 }
267 onLogoutReady: {
268 root.closeAllApps();
269 Qt.quit();
270 unitySessionService.endSession();
271 }
272 }