on 04789ec help sign in
unity8/qml/Components/Dialogs.qml
213 lines 6.1 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 Ubuntu.Components 1.1
22import Ubuntu.Components.Popups 0.1
24Item {
25 id: root
27 function onPowerKeyPressed() {
28 // FIXME: event.isAutoRepeat is always false on Nexus 4.
29 // So we use powerKeyTimer.running to avoid the PowerOff key repeat
30 // https://launchpad.net/bugs/1349416
31 if (!powerKeyTimer.running) {
32 powerKeyTimer.restart();
33 }
34 }
36 function onPowerKeyReleased() {
37 powerKeyTimer.stop();
38 }
40 signal powerOffClicked();
42 QtObject {
43 id: d // private stuff
45 property bool dialogShown: false
47 function showPowerDialog() {
48 if (!d.dialogShown) {
49 d.dialogShown = true;
50 PopupUtils.open(powerDialog, root, {"z": root.z});
51 }
52 }
53 }
55 Timer {
56 id: powerKeyTimer
57 interval: 2000
58 repeat: false
59 triggeredOnStart: false
61 onTriggered: {
62 d.showPowerDialog();
63 }
64 }
66 Component {
67 id: logoutDialog
68 Dialog {
69 id: dialogueLogout
70 title: i18n.tr("Log out")
71 text: i18n.tr("Are you sure you want to log out?")
72 Button {
73 text: i18n.tr("No")
74 onClicked: {
75 PopupUtils.close(dialogueLogout);
76 d.dialogShown = false;
77 }
78 }
79 Button {
80 text: i18n.tr("Yes")
81 onClicked: {
82 DBusUnitySessionService.Logout();
83 PopupUtils.close(dialogueLogout);
84 d.dialogShown = false;
85 }
86 }
87 }
88 }
90 Component {
91 id: shutdownDialog
92 Dialog {
93 id: dialogueShutdown
94 title: i18n.tr("Shut down")
95 text: i18n.tr("Are you sure you want to shut down?")
96 Button {
97 text: i18n.tr("No")
98 onClicked: {
99 PopupUtils.close(dialogueShutdown);
100 d.dialogShown = false;
101 }
102 }
103 Button {
104 text: i18n.tr("Yes")
105 onClicked: {
106 dBusUnitySessionServiceConnection.closeAllApps();
107 DBusUnitySessionService.Shutdown();
108 PopupUtils.close(dialogueShutdown);
109 d.dialogShown = false;
110 }
111 }
112 }
113 }
115 Component {
116 id: rebootDialog
117 Dialog {
118 id: dialogueReboot
119 title: i18n.tr("Reboot")
120 text: i18n.tr("Are you sure you want to reboot?")
121 Button {
122 text: i18n.tr("No")
123 onClicked: {
124 PopupUtils.close(dialogueReboot)
125 d.dialogShown = false;
126 }
127 }
128 Button {
129 text: i18n.tr("Yes")
130 onClicked: {
131 dBusUnitySessionServiceConnection.closeAllApps();
132 DBusUnitySessionService.Reboot();
133 PopupUtils.close(dialogueReboot);
134 d.dialogShown = false;
135 }
136 }
137 }
138 }
140 Component {
141 id: powerDialog
142 Dialog {
143 id: dialoguePower
144 title: i18n.tr("Power")
145 text: i18n.tr("Are you sure you would like\nto power off?")
146 Button {
147 text: i18n.tr("Power off")
148 onClicked: {
149 dBusUnitySessionServiceConnection.closeAllApps();
150 PopupUtils.close(dialoguePower);
151 d.dialogShown = false;
152 root.powerOffClicked();
153 }
154 color: UbuntuColors.red
155 }
156 Button {
157 text: i18n.tr("Cancel")
158 onClicked: {
159 PopupUtils.close(dialoguePower);
160 d.dialogShown = false;
161 }
162 color: UbuntuColors.coolGrey
163 }
164 }
165 }
168 Connections {
169 id: dBusUnitySessionServiceConnection
170 objectName: "dBusUnitySessionServiceConnection"
171 target: DBusUnitySessionService
173 function closeAllApps() {
174 while (true) {
175 var app = ApplicationManager.get(0);
176 if (app === null) {
177 break;
178 }
179 ApplicationManager.stopApplication(app.appId);
180 }
181 }
183 onLogoutRequested: {
184 // Display a dialog to ask the user to confirm.
185 if (!d.dialogShown) {
186 d.dialogShown = true;
187 PopupUtils.open(logoutDialog, root, {"z": root.z});
188 }
189 }
191 onShutdownRequested: {
192 // Display a dialog to ask the user to confirm.
193 if (!d.dialogShown) {
194 d.dialogShown = true;
195 PopupUtils.open(shutdownDialog, root, {"z": root.z});
196 }
197 }
199 onRebootRequested: {
200 // Display a dialog to ask the user to confirm.
201 if (!d.dialogShown) {
202 d.dialogShown = true;
203 PopupUtils.open(rebootDialog, root, {"z": root.z});
204 }
205 }
207 onLogoutReady: {
208 closeAllApps();
209 Qt.quit();
210 }
211 }