2 * Copyright (C) 2014-2015 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/>.
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 // to be set from outside, useful mostly for testing purposes
31 property var unitySessionService: DBusUnitySessionService
32 property var closeAllApps: function() {
34 var app = ApplicationManager.get(0);
38 ApplicationManager.stopApplication(app.appId);
41 property string usageScenario
43 signal powerOffClicked();
45 function showPowerDialog() {
49 onUsageScenarioChanged: {
50 if (usageScenario != "desktop" && legacyAppsModel.count > 0 && !d.modeSwitchWarningPopup) {
51 var comp = Qt.createComponent(Qt.resolvedUrl("ModeSwitchWarningDialog.qml"))
52 d.modeSwitchWarningPopup = comp.createObject(root, {model: legacyAppsModel});
53 d.modeSwitchWarningPopup.forceClose.connect(function() {
54 for (var i = legacyAppsModel.count - 1; i >= 0; i--) {
55 ApplicationManager.stopApplication(legacyAppsModel.get(i).appId);
57 d.modeSwitchWarningPopup.hide();
58 d.modeSwitchWarningPopup.destroy();
59 d.modeSwitchWarningPopup = null;
61 } else if (usageScenario == "desktop" && d.modeSwitchWarningPopup) {
62 d.modeSwitchWarningPopup.hide();
63 d.modeSwitchWarningPopup.destroy();
64 d.modeSwitchWarningPopup = null;
68 ApplicationsFilterModel {
70 applicationsModel: ApplicationManager
74 GlobalShortcut { // reboot/shutdown dialog
75 shortcut: Qt.Key_PowerDown
77 onTriggered: root.unitySessionService.RequestShutdown()
80 GlobalShortcut { // reboot/shutdown dialog
81 shortcut: Qt.Key_PowerOff
83 onTriggered: root.unitySessionService.RequestShutdown()
86 GlobalShortcut { // sleep
87 shortcut: Qt.Key_Sleep
88 onTriggered: root.unitySessionService.Suspend()
91 GlobalShortcut { // hibernate
92 shortcut: Qt.Key_Hibernate
93 onTriggered: root.unitySessionService.Hibernate()
96 GlobalShortcut { // logout/lock dialog
97 shortcut: Qt.Key_LogOff
98 onTriggered: root.unitySessionService.RequestLogout()
101 GlobalShortcut { // logout/lock dialog
102 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_Delete
103 onTriggered: root.unitySessionService.RequestLogout()
106 GlobalShortcut { // lock screen
107 shortcut: Qt.Key_ScreenSaver
108 onTriggered: lightDM.greeter.showGreeter()
111 GlobalShortcut { // lock screen
112 shortcut: Qt.ControlModifier|Qt.AltModifier|Qt.Key_L
113 onTriggered: lightDM.greeter.showGreeter()
117 id: d // private stuff
118 objectName: "dialogsPrivate"
120 property var modeSwitchWarningPopup: null
122 function showPowerDialog() {
123 if (!dialogLoader.active) {
124 dialogLoader.sourceComponent = powerDialogComponent;
125 dialogLoader.focus = true;
126 dialogLoader.active = true;
133 objectName: "dialogLoader"
138 LightDM {id: lightDM} // Provide backend access
141 id: logoutDialogComponent
144 title: i18n.ctr("Title: Lock/Log out dialog", "Log out")
145 text: i18n.tr("Are you sure you want to log out?")
147 text: i18n.ctr("Button: Lock the system", "Lock")
149 lightDM.greeter.showGreeter()
154 text: i18n.ctr("Button: Log out from the system", "Log Out")
156 unitySessionService.logout();
161 text: i18n.tr("Cancel")
170 id: rebootDialogComponent
173 title: i18n.ctr("Title: Reboot dialog", "Reboot")
174 text: i18n.tr("Are you sure you want to reboot?")
185 unitySessionService.reboot();
188 color: theme.palette.normal.negative
194 id: powerDialogComponent
197 title: i18n.ctr("Title: Power off/Restart dialog", "Power")
198 text: i18n.tr("Are you sure you would like\nto power off?")
200 text: i18n.ctr("Button: Power off the system", "Power off")
204 root.powerOffClicked();
206 color: theme.palette.normal.negative
209 text: i18n.ctr("Button: Restart the system", "Restart")
212 unitySessionService.reboot();
217 text: i18n.tr("Cancel")
226 target: root.unitySessionService
229 // Display a dialog to ask the user to confirm.
230 if (!dialogLoader.active) {
231 dialogLoader.sourceComponent = logoutDialogComponent;
232 dialogLoader.focus = true;
233 dialogLoader.active = true;
237 onShutdownRequested: {
238 // Display a dialog to ask the user to confirm.
243 // Display a dialog to ask the user to confirm.
245 // display a combined reboot/shutdown dialog, sadly the session indicator calls rather the "Reboot()" method
246 // than shutdown when clicking on the "Shutdown..." menu item
247 // FIXME: when/if session indicator is fixed, put the rebootDialogComponent here
254 unitySessionService.endSession();