on 27fa2c9 help sign in
unity8/qml/Components/Dialogs.qml
265 lines 8.5 kB history raw
1/*
2 * Copyright (C) 2014-2016 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.4
18import QtQuick.Window 2.2
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 Utils 0.1
25import "../Greeter"
27Item {
28 id: root
30 readonly property alias hasActiveDialog: dialogLoader.active
32 // to be set from outside, useful mostly for testing purposes
33 property var unitySessionService: DBusUnitySessionService
34 property var closeAllApps: function() {
35 while (true) {
36 var app = ApplicationManager.get(0);
37 if (app === null) {
38 break;
39 }
40 ApplicationManager.stopApplication(app.appId);
41 }
42 }
43 property string usageScenario
44 property size screenSize: Qt.size(Screen.width, Screen.height)
46 signal powerOffClicked();
48 function showPowerDialog() {
49 d.showPowerDialog();
50 }
52 onUsageScenarioChanged: {
53 // if we let the user switch manually to desktop mode, don't display the warning dialog
54 // see MenuItemFactory.qml, for the Desktop Mode switch logic
55 var isTabletSize = Math.min(screenSize.width, screenSize.height) > units.gu(60);
57 if (usageScenario != "desktop" && legacyAppsModel.count > 0 && !d.modeSwitchWarningPopup && !isTabletSize) {
58 var comp = Qt.createComponent(Qt.resolvedUrl("ModeSwitchWarningDialog.qml"))
59 d.modeSwitchWarningPopup = comp.createObject(root, {model: legacyAppsModel});
60 d.modeSwitchWarningPopup.forceClose.connect(function() {
61 for (var i = legacyAppsModel.count - 1; i >= 0; i--) {
62 ApplicationManager.stopApplication(legacyAppsModel.get(i).appId);
63 }
64 d.modeSwitchWarningPopup.hide();
65 d.modeSwitchWarningPopup.destroy();
66 d.modeSwitchWarningPopup = null;
67 })
68 } else if (usageScenario == "desktop" && d.modeSwitchWarningPopup) {
69 d.modeSwitchWarningPopup.hide();
70 d.modeSwitchWarningPopup.destroy();
71 d.modeSwitchWarningPopup = null;
72 }
73 }
75 ApplicationsFilterModel {
76 id: legacyAppsModel
77 applicationsModel: ApplicationManager
78 filterTouchApps: true
79 }
81 GlobalShortcut { // reboot/shutdown dialog
82 shortcut: Qt.Key_PowerDown
83 active: Platform.isPC
84 onTriggered: root.unitySessionService.RequestShutdown()
85 }
87 GlobalShortcut { // reboot/shutdown dialog
88 shortcut: Qt.Key_PowerOff
89 active: Platform.isPC
90 onTriggered: root.unitySessionService.RequestShutdown()
91 }
93 GlobalShortcut { // sleep
94 shortcut: Qt.Key_Sleep
95 onTriggered: root.unitySessionService.Suspend()
96 }
98 GlobalShortcut { // hibernate
99 shortcut: Qt.Key_Hibernate
100 onTriggered: root.unitySessionService.Hibernate()
101 }
103 GlobalShortcut { // logout/lock dialog
104 shortcut: Qt.Key_LogOff
105 onTriggered: root.unitySessionService.RequestLogout()
106 }
108 GlobalShortcut { // logout/lock dialog
109 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_Delete
110 onTriggered: root.unitySessionService.RequestLogout()
111 }
113 GlobalShortcut { // lock screen
114 shortcut: Qt.Key_ScreenSaver
115 onTriggered: LightDMService.greeter.showGreeter()
116 }
118 GlobalShortcut { // lock screen
119 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
120 onTriggered: LightDMService.greeter.showGreeter()
121 }
123 QtObject {
124 id: d // private stuff
125 objectName: "dialogsPrivate"
127 property var modeSwitchWarningPopup: null
129 function showPowerDialog() {
130 if (!dialogLoader.active) {
131 dialogLoader.sourceComponent = powerDialogComponent;
132 dialogLoader.focus = true;
133 dialogLoader.active = true;
134 }
135 }
136 }
138 Loader {
139 id: dialogLoader
140 objectName: "dialogLoader"
141 anchors.fill: parent
142 active: false
143 }
145 Component {
146 id: logoutDialogComponent
147 ShellDialog {
148 id: logoutDialog
149 title: i18n.ctr("Title: Lock/Log out dialog", "Log out")
150 text: i18n.tr("Are you sure you want to log out?")
151 Button {
152 text: i18n.ctr("Button: Lock the system", "Lock")
153 onClicked: {
154 LightDMService.greeter.showGreeter()
155 logoutDialog.hide();
156 }
157 }
158 Button {
159 focus: true
160 text: i18n.ctr("Button: Log out from the system", "Log Out")
161 onClicked: {
162 unitySessionService.logout();
163 logoutDialog.hide();
164 }
165 }
166 Button {
167 text: i18n.tr("Cancel")
168 onClicked: {
169 logoutDialog.hide();
170 }
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 }
187 Button {
188 focus: true
189 text: i18n.tr("Yes")
190 onClicked: {
191 root.closeAllApps();
192 unitySessionService.reboot();
193 rebootDialog.hide();
194 }
195 color: theme.palette.normal.negative
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 focus: true
208 text: i18n.ctr("Button: Power off the system", "Power off")
209 onClicked: {
210 root.closeAllApps();
211 powerDialog.hide();
212 root.powerOffClicked();
213 }
214 color: theme.palette.normal.negative
215 }
216 Button {
217 text: i18n.ctr("Button: Restart the system", "Restart")
218 onClicked: {
219 root.closeAllApps();
220 unitySessionService.reboot();
221 powerDialog.hide();
222 }
223 }
224 Button {
225 text: i18n.tr("Cancel")
226 onClicked: {
227 powerDialog.hide();
228 }
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 showPowerDialog();
248 }
250 onRebootRequested: {
251 // Display a dialog to ask the user to confirm.
253 // display a combined reboot/shutdown dialog, sadly the session indicator calls rather the "Reboot()" method
254 // than shutdown when clicking on the "Shutdown..." menu item
255 // FIXME: when/if session indicator is fixed, put the rebootDialogComponent here
256 showPowerDialog();
257 }
259 onLogoutReady: {
260 root.closeAllApps();
261 Qt.quit();
262 unitySessionService.endSession();
263 }
264 }