on e63da72 help sign in
unity8/qml/Components/Dialogs.qml
273 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 "../Greeter"
25Item {
26 id: root
28 // to be set from outside, useful mostly for testing purposes
29 property var unitySessionService: DBusUnitySessionService
30 property var closeAllApps: function() {
31 while (true) {
32 var app = ApplicationManager.get(0);
33 if (app === null) {
34 break;
35 }
36 ApplicationManager.stopApplication(app.appId);
37 }
38 }
39 property string usageScenario
41 signal powerOffClicked();
43 function showPowerDialog() {
44 d.showPowerDialog();
45 }
47 GlobalShortcut { // reboot/shutdown dialog
48 shortcut: Qt.Key_PowerDown
49 active: root.usageScenario === "desktop"
50 onTriggered: root.unitySessionService.RequestShutdown()
51 }
53 GlobalShortcut { // reboot/shutdown dialog
54 shortcut: Qt.Key_PowerOff
55 active: root.usageScenario === "desktop"
56 onTriggered: root.unitySessionService.RequestShutdown()
57 }
59 GlobalShortcut { // sleep
60 shortcut: Qt.Key_Sleep
61 onTriggered: root.unitySessionService.Suspend()
62 }
64 GlobalShortcut { // hibernate
65 shortcut: Qt.Key_Hibernate
66 onTriggered: root.unitySessionService.Hibernate()
67 }
69 GlobalShortcut { // logout/lock dialog
70 shortcut: Qt.Key_LogOff
71 onTriggered: root.unitySessionService.RequestLogout()
72 }
74 GlobalShortcut { // logout/lock dialog
75 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_Delete
76 onTriggered: root.unitySessionService.RequestLogout()
77 }
79 GlobalShortcut { // lock screen
80 shortcut: Qt.Key_ScreenSaver
81 onTriggered: lightDM.greeter.showGreeter()
82 }
84 GlobalShortcut { // lock screen
85 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
86 onTriggered: lightDM.greeter.showGreeter()
87 }
89 QtObject {
90 id: d // private stuff
91 objectName: "dialogsPrivate"
93 function showPowerDialog() {
94 if (!dialogLoader.active) {
95 dialogLoader.sourceComponent = powerDialogComponent;
96 dialogLoader.focus = true;
97 dialogLoader.active = true;
98 }
99 }
100 }
102 Loader {
103 id: dialogLoader
104 objectName: "dialogLoader"
105 anchors.fill: parent
106 active: false
107 }
109 LightDM {id: lightDM} // Provide backend access
111 Component {
112 id: logoutDialogComponent
113 ShellDialog {
114 id: logoutDialog
115 title: i18n.ctr("Title: Lock/Log out dialog", "Log out")
116 text: i18n.tr("Are you sure you want to log out?")
117 Button {
118 text: i18n.ctr("Button: Lock the system", "Lock")
119 onClicked: {
120 lightDM.greeter.showGreeter()
121 logoutDialog.hide();
122 }
123 }
124 Button {
125 text: i18n.ctr("Button: Log out from the system", "Log Out")
126 onClicked: {
127 unitySessionService.logout();
128 logoutDialog.hide();
129 }
130 }
131 Button {
132 text: i18n.tr("Cancel")
133 onClicked: {
134 logoutDialog.hide();
135 }
136 }
137 }
138 }
140 Component {
141 id: shutdownDialogComponent
142 ShellDialog {
143 id: shutdownDialog
144 title: i18n.ctr("Title: Reboot/Shut down dialog", "Shut down")
145 text: i18n.tr("Are you sure you want to shut down?")
146 Button {
147 text: i18n.ctr("Button: Reboot the system", "Reboot")
148 onClicked: {
149 root.closeAllApps();
150 unitySessionService.reboot();
151 shutdownDialog.hide();
152 }
153 color: UbuntuColors.lightGrey
154 }
155 Button {
156 text: i18n.ctr("Button: Shut down the system", "Shut down")
157 onClicked: {
158 root.closeAllApps();
159 unitySessionService.shutdown();
160 shutdownDialog.hide();
161 }
162 color: UbuntuColors.red
163 }
164 Button {
165 text: i18n.tr("Cancel")
166 onClicked: {
167 shutdownDialog.hide();
168 }
169 color: UbuntuColors.lightGrey
170 }
171 }
172 }
174 Component {
175 id: rebootDialogComponent
176 ShellDialog {
177 id: rebootDialog
178 title: i18n.ctr("Title: Reboot dialog", "Reboot")
179 text: i18n.tr("Are you sure you want to reboot?")
180 Button {
181 text: i18n.tr("No")
182 onClicked: {
183 rebootDialog.hide();
184 }
185 color: UbuntuColors.lightGrey
186 }
187 Button {
188 text: i18n.tr("Yes")
189 onClicked: {
190 root.closeAllApps();
191 unitySessionService.reboot();
192 rebootDialog.hide();
193 }
194 color: UbuntuColors.red
195 }
196 }
197 }
199 Component {
200 id: powerDialogComponent
201 ShellDialog {
202 id: powerDialog
203 title: i18n.ctr("Title: Power off/Restart dialog", "Power")
204 text: i18n.tr("Are you sure you would like\nto power off?")
205 Button {
206 text: i18n.ctr("Button: Power off the system", "Power off")
207 onClicked: {
208 root.closeAllApps();
209 powerDialog.hide();
210 root.powerOffClicked();
211 }
212 color: UbuntuColors.red
213 }
214 Button {
215 text: i18n.ctr("Button: Restart the system", "Restart")
216 onClicked: {
217 root.closeAllApps();
218 unitySessionService.reboot();
219 powerDialog.hide();
220 }
221 color: UbuntuColors.lightGrey
222 }
223 Button {
224 text: i18n.tr("Cancel")
225 onClicked: {
226 powerDialog.hide();
227 }
228 color: UbuntuColors.lightGrey
229 }
230 }
231 }
233 Connections {
234 target: root.unitySessionService
236 onLogoutRequested: {
237 // Display a dialog to ask the user to confirm.
238 if (!dialogLoader.active) {
239 dialogLoader.sourceComponent = logoutDialogComponent;
240 dialogLoader.focus = true;
241 dialogLoader.active = true;
242 }
243 }
245 onShutdownRequested: {
246 // Display a dialog to ask the user to confirm.
247 if (!dialogLoader.active) {
248 dialogLoader.sourceComponent = shutdownDialogComponent;
249 dialogLoader.focus = true;
250 dialogLoader.active = true;
251 }
252 }
254 onRebootRequested: {
255 // Display a dialog to ask the user to confirm.
256 if (!dialogLoader.active) {
257 // display a combined reboot/shutdown dialog, sadly the session indicator calls rather the "Reboot()" method
258 // than shutdown when clicking on the "Shutdown..." menu item
259 // FIXME: when/if session indicator is fixed, put the rebootDialogComponent here
260 dialogLoader.sourceComponent = shutdownDialogComponent;
261 dialogLoader.focus = true;
262 dialogLoader.active = true;
263 }
264 }
266 onLogoutReady: {
267 root.closeAllApps();
268 Qt.quit();
269 unitySessionService.endSession();
270 }
271 }