2 * Copyright (C) 2014-2016 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
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() {
36 var app = ApplicationManager.get(0);
40 ApplicationManager.stopApplication(app.appId);
43 property string usageScenario
44 property size screenSize: Qt.size(Screen.width, Screen.height)
46 signal powerOffClicked();
48 function showPowerDialog() {
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);
64 d.modeSwitchWarningPopup.hide();
65 d.modeSwitchWarningPopup.destroy();
66 d.modeSwitchWarningPopup = null;
68 } else if (usageScenario == "desktop" && d.modeSwitchWarningPopup) {
69 d.modeSwitchWarningPopup.hide();
70 d.modeSwitchWarningPopup.destroy();
71 d.modeSwitchWarningPopup = null;
75 ApplicationsFilterModel {
77 applicationsModel: ApplicationManager
81 GlobalShortcut { // reboot/shutdown dialog
82 shortcut: Qt.Key_PowerDown
84 onTriggered: root.unitySessionService.RequestShutdown()
87 GlobalShortcut { // reboot/shutdown dialog
88 shortcut: Qt.Key_PowerOff
90 onTriggered: root.unitySessionService.RequestShutdown()
93 GlobalShortcut { // sleep
94 shortcut: Qt.Key_Sleep
95 onTriggered: root.unitySessionService.Suspend()
98 GlobalShortcut { // hibernate
99 shortcut: Qt.Key_Hibernate
100 onTriggered: root.unitySessionService.Hibernate()
103 GlobalShortcut { // logout/lock dialog
104 shortcut: Qt.Key_LogOff
105 onTriggered: root.unitySessionService.RequestLogout()
108 GlobalShortcut { // logout/lock dialog
109 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_Delete
110 onTriggered: root.unitySessionService.RequestLogout()
113 GlobalShortcut { // lock screen
114 shortcut: Qt.Key_ScreenSaver
115 onTriggered: LightDMService.greeter.showGreeter()
118 GlobalShortcut { // lock screen
119 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
120 onTriggered: LightDMService.greeter.showGreeter()
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;
140 objectName: "dialogLoader"
146 id: logoutDialogComponent
149 title: i18n.ctr("Title: Lock/Log out dialog", "Log out")
150 text: i18n.tr("Are you sure you want to log out?")
152 text: i18n.ctr("Button: Lock the system", "Lock")
154 LightDMService.greeter.showGreeter()
159 text: i18n.ctr("Button: Log out from the system", "Log Out")
161 unitySessionService.logout();
166 text: i18n.tr("Cancel")
175 id: rebootDialogComponent
178 title: i18n.ctr("Title: Reboot dialog", "Reboot")
179 text: i18n.tr("Are you sure you want to reboot?")
190 unitySessionService.reboot();
193 color: theme.palette.normal.negative
199 id: powerDialogComponent
202 title: i18n.ctr("Title: Power off/Restart dialog", "Power")
203 text: i18n.tr("Are you sure you would like\nto power off?")
205 text: i18n.ctr("Button: Power off the system", "Power off")
209 root.powerOffClicked();
211 color: theme.palette.normal.negative
214 text: i18n.ctr("Button: Restart the system", "Restart")
217 unitySessionService.reboot();
222 text: i18n.tr("Cancel")
231 target: root.unitySessionService
234 // Display a dialog to ask the user to confirm.
235 if (!dialogLoader.active) {
236 dialogLoader.sourceComponent = logoutDialogComponent;
237 dialogLoader.focus = true;
238 dialogLoader.active = true;
242 onShutdownRequested: {
243 // Display a dialog to ask the user to confirm.
248 // Display a dialog to ask the user to confirm.
250 // display a combined reboot/shutdown dialog, sadly the session indicator calls rather the "Reboot()" method
251 // than shutdown when clicking on the "Shutdown..." menu item
252 // FIXME: when/if session indicator is fixed, put the rebootDialogComponent here
259 unitySessionService.endSession();