@@ -19,6 +19,7 @@ import AccountsService 0.1
1919import GSettings 1.0
2020import Unity.Application 0.1
2121import Ubuntu.Components 0.1
22+import Ubuntu.Components.Popups 0.1
2223import Ubuntu.Gestures 0.1
2324import Unity.Launcher 0.1
2425import LightDM 0.1 as LightDM
@@ -268,7 +269,128 @@ FocusScope {
268269 }
269270 }
270271
272+ property bool dialogShown: false
273+
274+ Component {
275+ id: logoutDialog
276+ Dialog {
277+ id: dialogueLogout
278+ title: "Logout"
279+ text: "Are you sure that you want to logout?"
280+ Button {
281+ text: "Cancel"
282+ onClicked: {
283+ PopupUtils.close(dialogueLogout);
284+ stages.dialogShown = false;
285+ }
286+ }
287+ Button {
288+ text: "Yes"
289+ onClicked: {
290+ DBusUnitySessionService.Logout();
291+ PopupUtils.close(dialogueLogout);
292+ stages.dialogShown = false;
293+ }
294+ }
295+ }
296+ }
297+
298+ Component {
299+ id: shutdownDialog
300+ Dialog {
301+ id: dialogueShutdown
302+ title: "Shutdown"
303+ text: "Are you sure that you want to shutdown?"
304+ Button {
305+ text: "Cancel"
306+ onClicked: {
307+ PopupUtils.close(dialogueShutdown);
308+ stages.dialogShown = false;
309+ }
310+ }
311+ Button {
312+ text: "Yes"
313+ onClicked: {
314+ dBusUnitySessionServiceConnection.closeAllApps();
315+ DBusUnitySessionService.Shutdown();
316+ PopupUtils.close(dialogueShutdown);
317+ stages.dialogShown = false;
318+ }
319+ }
320+ }
321+ }
322+
323+ Component {
324+ id: rebootDialog
325+ Dialog {
326+ id: dialogueReboot
327+ title: "Reboot"
328+ text: "Are you sure that you want to reboot?"
329+ Button {
330+ text: "Cancel"
331+ onClicked: {
332+ PopupUtils.close(dialogueReboot)
333+ stages.dialogShown = false;
334+ }
335+ }
336+ Button {
337+ text: "Yes"
338+ onClicked: {
339+ dBusUnitySessionServiceConnection.closeAllApps();
340+ DBusUnitySessionService.Reboot();
341+ PopupUtils.close(dialogueReboot);
342+ stages.dialogShown = false;
343+ }
344+ }
345+ }
346+ }
347+
348+ Component {
349+ id: powerDialog
350+ Dialog {
351+ id: dialoguePower
352+ title: "Power"
353+ text: i18n.tr("Are you sure you would like to turn power off?")
354+ Button {
355+ text: i18n.tr("Power off")
356+ onClicked: {
357+ dBusUnitySessionServiceConnection.closeAllApps();
358+ PopupUtils.close(dialoguePower);
359+ stages.dialogShown = false;
360+ shutdownFadeOutRectangle.enabled = true;
361+ shutdownFadeOutRectangle.visible = true;
362+ shutdownFadeOut.start();
363+ }
364+ }
365+ Button {
366+ text: i18n.tr("Restart")
367+ onClicked: {
368+ dBusUnitySessionServiceConnection.closeAllApps();
369+ DBusUnitySessionService.Reboot();
370+ PopupUtils.close(dialoguePower);
371+ stages.dialogShown = false;
372+ }
373+ }
374+ Button {
375+ text: i18n.tr("Cancel")
376+ onClicked: {
377+ PopupUtils.close(dialoguePower);
378+ stages.dialogShown = false;
379+ }
380+ }
381+ }
382+ }
383+
384+ function showPowerDialog() {
385+ if (!stages.dialogShown) {
386+ stages.dialogShown = true;
387+ PopupUtils.open(powerDialog);
388+ }
389+ }
390+
271391 Connections {
392+ id: dBusUnitySessionServiceConnection
393+ objectName: "dBusUnitySessionServiceConnection"
272394 target: DBusUnitySessionService
273395
274396 function closeAllApps() {
@@ -282,8 +404,27 @@ FocusScope {
282404 }
283405
284406 onLogoutRequested: {
285− // TODO: Display a dialog to ask the user to confirm.
286− DBusUnitySessionService.Logout();
407+ // Display a dialog to ask the user to confirm.
408+ if (!stages.dialogShown) {
409+ stages.dialogShown = true;
410+ PopupUtils.open(logoutDialog);
411+ }
412+ }
413+
414+ onShutdownRequested: {
415+ // Display a dialog to ask the user to confirm.
416+ if (!stages.dialogShown) {
417+ stages.dialogShown = true;
418+ PopupUtils.open(shutdownDialog);
419+ }
420+ }
421+
422+ onRebootRequested: {
423+ // Display a dialog to ask the user to confirm.
424+ if (!stages.dialogShown) {
425+ stages.dialogShown = true;
426+ PopupUtils.open(rebootDialog);
427+ }
287428 }
288429
289430 onLogoutReady: {
@@ -348,6 +489,8 @@ FocusScope {
348489 Connections {
349490 target: LightDM.Greeter
350491
492+ onShowGreeter: greeter.show()
493+
351494 onShowPrompt: {
352495 if (LightDM.Users.count == 1) {
353496 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
@@ -373,6 +516,12 @@ FocusScope {
373516 }
374517 }
375518
519+ Binding {
520+ target: LightDM.Greeter
521+ property: "active"
522+ value: greeter.shown || lockscreen.shown
523+ }
524+
376525 Rectangle {
377526 anchors.fill: parent
378527 color: "black"
@@ -412,6 +561,9 @@ FocusScope {
412561 onShownChanged: {
413562 if (shown) {
414563 lockscreen.reset();
564+ if (!LightDM.Greeter.promptless) {
565+ lockscreen.show();
566+ }
415567 // If there is only one user, we start authenticating with that one here.
416568 // If there are more users, the Greeter will handle that
417569 if (LightDM.Users.count == 1) {
@@ -472,10 +624,6 @@ FocusScope {
472624 stages.hide()
473625 }
474626
475− function hideIndicatorMenu(delay) {
476− panel.hideIndicatorMenu(delay);
477− }
478−
479627 Item {
480628 id: overlay
481629
@@ -679,4 +827,50 @@ FocusScope {
679827 target: SessionBroadcast
680828 onShowHome: showHome()
681829 }
830+
831+ Keys.onPressed: {
832+ if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
833+ if (!powerKeyTimer.running) {
834+ powerKeyTimer.start();
835+ }
836+ event.accepted = true;
837+ }
838+ }
839+
840+ Keys.onReleased: {
841+ if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
842+ powerKeyTimer.stop();
843+ event.accepted = true;
844+ }
845+ }
846+
847+ Timer {
848+ id: powerKeyTimer
849+ interval: 2000
850+ repeat: false
851+ triggeredOnStart: false
852+
853+ onTriggered: {
854+ stages.showPowerDialog();
855+ }
856+ }
857+
858+ Rectangle {
859+ id: shutdownFadeOutRectangle
860+ enabled: false
861+ visible: false
862+ color: "black"
863+ anchors.fill: parent
864+ opacity: 0.0
865+ NumberAnimation on opacity {
866+ id: shutdownFadeOut
867+ from: 0.0
868+ to: 1.0
869+ onStopped: {
870+ if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
871+ DBusUnitySessionService.Shutdown();
872+ }
873+ }
874+ }
875+ }
682876}