on xenial help sign in
Add poweroff key catching.
369c47fYing-Chun Liu
qml/Shell.qml+56−6
@@ -278,6 +278,8 @@ FocusScope {
278 }
278 }
279 }
279 }
280
280
281+ property bool dialogShown: false
282+
281 Component {
283 Component {
282 id: logoutDialog
284 id: logoutDialog
283 Dialog {
285 Dialog {
@@ -286,13 +288,17 @@ FocusScope {
286 text: "Are you sure that you want to logout?"
288 text: "Are you sure that you want to logout?"
287 Button {
289 Button {
288 text: "Cancel"
290 text: "Cancel"
291+ onClicked: {
289− onClicked: PopupUtils.close(dialogueLogout)
292+ PopupUtils.close(dialogueLogout);
293+ stages.dialogShown = false;
294+ }
290 }
295 }
291 Button {
296 Button {
292 text: "Yes"
297 text: "Yes"
293 onClicked: {
298 onClicked: {
294 DBusUnitySessionService.Logout();
299 DBusUnitySessionService.Logout();
295 PopupUtils.close(dialogueLogout);
300 PopupUtils.close(dialogueLogout);
301+ stages.dialogShown = false;
296 }
302 }
297 }
303 }
298 }
304 }
@@ -306,7 +312,10 @@ FocusScope {
306 text: "Are you sure that you want to shutdown?"
312 text: "Are you sure that you want to shutdown?"
307 Button {
313 Button {
308 text: "Cancel"
314 text: "Cancel"
315+ onClicked: {
309− onClicked: PopupUtils.close(dialogueShutdown)
316+ PopupUtils.close(dialogueShutdown);
317+ stages.dialogShown = false;
318+ }
310 }
319 }
311 Button {
320 Button {
312 text: "Yes"
321 text: "Yes"
@@ -314,6 +323,7 @@ FocusScope {
314 dBusUnitySessionServiceConnection.closeAllApps();
323 dBusUnitySessionServiceConnection.closeAllApps();
315 DBusUnitySessionService.Shutdown();
324 DBusUnitySessionService.Shutdown();
316 PopupUtils.close(dialogueShutdown);
325 PopupUtils.close(dialogueShutdown);
326+ stages.dialogShown = false;
317 }
327 }
318 }
328 }
319 }
329 }
@@ -327,7 +337,10 @@ FocusScope {
327 text: "Are you sure that you want to reboot?"
337 text: "Are you sure that you want to reboot?"
328 Button {
338 Button {
329 text: "Cancel"
339 text: "Cancel"
340+ onClicked: {
330− onClicked: PopupUtils.close(dialogueReboot)
341+ PopupUtils.close(dialogueReboot)
342+ stages.dialogShown = false;
343+ }
331 }
344 }
332 Button {
345 Button {
333 text: "Yes"
346 text: "Yes"
@@ -335,6 +348,7 @@ FocusScope {
335 dBusUnitySessionServiceConnection.closeAllApps();
348 dBusUnitySessionServiceConnection.closeAllApps();
336 DBusUnitySessionService.Reboot();
349 DBusUnitySessionService.Reboot();
337 PopupUtils.close(dialogueReboot);
350 PopupUtils.close(dialogueReboot);
351+ stages.dialogShown = false;
338 }
352 }
339 }
353 }
340 }
354 }
@@ -356,17 +370,26 @@ FocusScope {
356
370
357 onLogoutRequested: {
371 onLogoutRequested: {
358 // Display a dialog to ask the user to confirm.
372 // Display a dialog to ask the user to confirm.
373+ if (!stages.dialogShown) {
374+ stages.dialogShown = true;
359− PopupUtils.open(logoutDialog);
375+ PopupUtils.open(logoutDialog);
376+ }
360 }
377 }
361
378
362 onShutdownRequested: {
379 onShutdownRequested: {
363 // Display a dialog to ask the user to confirm.
380 // Display a dialog to ask the user to confirm.
381+ if (!stages.dialogShown) {
382+ stages.dialogShown = true;
364− PopupUtils.open(shutdownDialog);
383+ PopupUtils.open(shutdownDialog);
384+ }
365 }
385 }
366
386
367 onRebootRequested: {
387 onRebootRequested: {
368 // Display a dialog to ask the user to confirm.
388 // Display a dialog to ask the user to confirm.
389+ if (!stages.dialogShown) {
390+ stages.dialogShown = true;
369− PopupUtils.open(rebootDialog);
391+ PopupUtils.open(rebootDialog);
392+ }
370 }
393 }
371
394
372 onLogoutReady: {
395 onLogoutReady: {
@@ -759,4 +782,31 @@ FocusScope {
759 target: SessionBroadcast
782 target: SessionBroadcast
760 onShowHome: showHome()
783 onShowHome: showHome()
761 }
784 }
785+
786+ Keys.onPressed: {
787+ if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
788+ if (!powerKeyTimer.running) {
789+ powerKeyTimer.start();
790+ }
791+ event.accepted = true;
792+ }
793+ }
794+
795+ Keys.onReleased: {
796+ if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
797+ powerKeyTimer.stop();
798+ }
799+ event.accepted = true;
800+ }
801+
802+ Timer {
803+ id: powerKeyTimer
804+ interval: 500
805+ repeat: false
806+ triggeredOnStart: false
807+
808+ onTriggered: {
809+ DBusUnitySessionService.RequestShutdown();
810+ }
811+ }
762}
812}