2 * Copyright (C) 2014-2017 Canonical, Ltd.
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.
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.
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/>.
18 import QtQuick.Window 2.2
19 import Unity.Application 0.1
20 import Unity.Session 0.1
21 import GlobalShortcut 1.0
22 import Ubuntu.Components 1.3
23 import Unity.Platform 1.0
28 acceptedButtons: Qt.AllButtons
30 onWheel: wheel.accepted = true
32 readonly property bool hasActiveDialog: dialogLoader.active || d.modeSwitchWarningPopup
34 // to be set from outside, useful mostly for testing purposes
35 property var unitySessionService: DBusUnitySessionService
36 property var closeAllApps: function() {
38 var app = ApplicationManager.get(0);
42 ApplicationManager.stopApplication(app.appId);
45 property string usageScenario
46 property size screenSize: Qt.size(Screen.width, Screen.height)
47 property bool hasKeyboard: false
49 signal powerOffClicked();
51 function showPowerDialog() {
55 onUsageScenarioChanged: {
56 // if we let the user switch manually to desktop mode, don't display the warning dialog
57 // see MenuItemFactory.qml, for the Desktop Mode switch logic
58 var isTabletSize = Math.min(screenSize.width, screenSize.height) > units.gu(60);
60 if (usageScenario != "desktop" && legacyAppsModel.count > 0 && !d.modeSwitchWarningPopup && !isTabletSize) {
61 var comp = Qt.createComponent(Qt.resolvedUrl("ModeSwitchWarningDialog.qml"))
62 d.modeSwitchWarningPopup = comp.createObject(root, {model: legacyAppsModel});
63 d.modeSwitchWarningPopup.forceClose.connect(function() {
64 for (var i = legacyAppsModel.count - 1; i >= 0; i--) {
65 ApplicationManager.stopApplication(legacyAppsModel.get(i).appId);
67 d.modeSwitchWarningPopup.hide();
68 d.modeSwitchWarningPopup.destroy();
69 d.modeSwitchWarningPopup = null;
71 } else if (usageScenario == "desktop" && d.modeSwitchWarningPopup) {
72 d.modeSwitchWarningPopup.hide();
73 d.modeSwitchWarningPopup.destroy();
74 d.modeSwitchWarningPopup = null;
78 ApplicationsFilterModel {
80 applicationsModel: ApplicationManager
84 GlobalShortcut { // reboot/shutdown dialog
85 shortcut: Qt.Key_PowerDown
87 onTriggered: root.unitySessionService.RequestShutdown()
90 GlobalShortcut { // reboot/shutdown dialog
91 shortcut: Qt.Key_PowerOff
93 onTriggered: root.unitySessionService.RequestShutdown()
96 GlobalShortcut { // sleep
97 shortcut: Qt.Key_Sleep
98 onTriggered: root.unitySessionService.Suspend()
101 GlobalShortcut { // hibernate
102 shortcut: Qt.Key_Hibernate
103 onTriggered: root.unitySessionService.Hibernate()
106 GlobalShortcut { // logout/lock dialog
107 shortcut: Qt.Key_LogOff
108 onTriggered: root.unitySessionService.RequestLogout()
111 GlobalShortcut { // logout/lock dialog
112 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_Delete
113 onTriggered: root.unitySessionService.RequestLogout()
116 GlobalShortcut { // lock screen
117 shortcut: Qt.Key_ScreenSaver
118 onTriggered: root.unitySessionService.PromptLock()
121 GlobalShortcut { // lock screen
122 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
123 onTriggered: root.unitySessionService.PromptLock()
126 GlobalShortcut { // lock screen
127 shortcut: Qt.MetaModifier|Qt.Key_L
128 onTriggered: root.unitySessionService.PromptLock()
132 id: d // private stuff
133 objectName: "dialogsPrivate"
135 property var modeSwitchWarningPopup: null
137 function showPowerDialog() {
138 if (!dialogLoader.active) {
139 dialogLoader.sourceComponent = powerDialogComponent;
140 dialogLoader.focus = true;
141 dialogLoader.active = true;
148 objectName: "dialogLoader"
153 if (previousFocusedItem) {
154 previousFocusedItem.forceActiveFocus(Qt.OtherFocusReason);
155 previousFocusedItem = undefined;
157 previousSourceComponent = undefined;
158 sourceComponent = undefined;
161 onSourceComponentChanged: {
162 if (previousSourceComponent !== sourceComponent) {
163 previousSourceComponent = sourceComponent;
164 previousFocusedItem = window.activeFocusItem;
168 property var previousSourceComponent: undefined
169 property var previousFocusedItem: undefined
173 id: logoutDialogComponent
176 title: i18n.ctr("Title: Lock/Log out dialog", "Log out")
177 text: i18n.tr("Are you sure you want to log out?")
180 text: i18n.ctr("Button: Lock the system", "Lock")
181 visible: root.unitySessionService.CanLock()
183 root.unitySessionService.PromptLock();
186 Component.onCompleted: if (root.hasKeyboard) forceActiveFocus(Qt.TabFocusReason)
191 text: i18n.ctr("Button: Log out from the system", "Log Out")
193 unitySessionService.logout();
199 text: i18n.tr("Cancel")
208 id: rebootDialogComponent
211 title: i18n.ctr("Title: Reboot dialog", "Reboot")
212 text: i18n.tr("Are you sure you want to reboot?")
226 unitySessionService.reboot();
229 color: theme.palette.normal.negative
230 Component.onCompleted: if (root.hasKeyboard) forceActiveFocus(Qt.TabFocusReason)
236 id: powerDialogComponent
239 title: i18n.ctr("Title: Power off/Restart dialog", "Power")
240 text: i18n.tr("Are you sure you would like\nto power off?")
244 text: i18n.ctr("Button: Power off the system", "Power off")
248 root.powerOffClicked();
250 color: theme.palette.normal.negative
251 Component.onCompleted: if (root.hasKeyboard) forceActiveFocus(Qt.TabFocusReason)
255 text: i18n.ctr("Button: Restart the system", "Restart")
258 unitySessionService.reboot();
264 text: i18n.tr("Cancel")
273 target: root.unitySessionService
276 // Display a dialog to ask the user to confirm.
277 if (!dialogLoader.active) {
278 dialogLoader.sourceComponent = logoutDialogComponent;
279 dialogLoader.focus = true;
280 dialogLoader.active = true;
284 onShutdownRequested: {
285 // Display a dialog to ask the user to confirm.
290 // Display a dialog to ask the user to confirm.
292 // display a combined reboot/shutdown dialog, sadly the session indicator calls rather the "Reboot()" method
293 // than shutdown when clicking on the "Shutdown..." menu item
294 // FIXME: when/if session indicator is fixed, put the rebootDialogComponent here
301 unitySessionService.endSession();