@@ -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
@@ -262,7 +263,128 @@ FocusScope {
262263 }
263264 }
264265
266+ property bool dialogShown: false
267+
268+ Component {
269+ id: logoutDialog
270+ Dialog {
271+ id: dialogueLogout
272+ title: "Logout"
273+ text: "Are you sure that you want to logout?"
274+ Button {
275+ text: "Cancel"
276+ onClicked: {
277+ PopupUtils.close(dialogueLogout);
278+ stages.dialogShown = false;
279+ }
280+ }
281+ Button {
282+ text: "Yes"
283+ onClicked: {
284+ DBusUnitySessionService.Logout();
285+ PopupUtils.close(dialogueLogout);
286+ stages.dialogShown = false;
287+ }
288+ }
289+ }
290+ }
291+
292+ Component {
293+ id: shutdownDialog
294+ Dialog {
295+ id: dialogueShutdown
296+ title: "Shutdown"
297+ text: "Are you sure that you want to shutdown?"
298+ Button {
299+ text: "Cancel"
300+ onClicked: {
301+ PopupUtils.close(dialogueShutdown);
302+ stages.dialogShown = false;
303+ }
304+ }
305+ Button {
306+ text: "Yes"
307+ onClicked: {
308+ dBusUnitySessionServiceConnection.closeAllApps();
309+ DBusUnitySessionService.Shutdown();
310+ PopupUtils.close(dialogueShutdown);
311+ stages.dialogShown = false;
312+ }
313+ }
314+ }
315+ }
316+
317+ Component {
318+ id: rebootDialog
319+ Dialog {
320+ id: dialogueReboot
321+ title: "Reboot"
322+ text: "Are you sure that you want to reboot?"
323+ Button {
324+ text: "Cancel"
325+ onClicked: {
326+ PopupUtils.close(dialogueReboot)
327+ stages.dialogShown = false;
328+ }
329+ }
330+ Button {
331+ text: "Yes"
332+ onClicked: {
333+ dBusUnitySessionServiceConnection.closeAllApps();
334+ DBusUnitySessionService.Reboot();
335+ PopupUtils.close(dialogueReboot);
336+ stages.dialogShown = false;
337+ }
338+ }
339+ }
340+ }
341+
342+ Component {
343+ id: powerDialog
344+ Dialog {
345+ id: dialoguePower
346+ title: "Power"
347+ text: i18n.tr("Are you sure you would like to turn power off?")
348+ Button {
349+ text: i18n.tr("Power off")
350+ onClicked: {
351+ dBusUnitySessionServiceConnection.closeAllApps();
352+ PopupUtils.close(dialoguePower);
353+ stages.dialogShown = false;
354+ shutdownFadeOutRectangle.enabled = true;
355+ shutdownFadeOutRectangle.visible = true;
356+ shutdownFadeOut.start();
357+ }
358+ }
359+ Button {
360+ text: i18n.tr("Restart")
361+ onClicked: {
362+ dBusUnitySessionServiceConnection.closeAllApps();
363+ DBusUnitySessionService.Reboot();
364+ PopupUtils.close(dialoguePower);
365+ stages.dialogShown = false;
366+ }
367+ }
368+ Button {
369+ text: i18n.tr("Cancel")
370+ onClicked: {
371+ PopupUtils.close(dialoguePower);
372+ stages.dialogShown = false;
373+ }
374+ }
375+ }
376+ }
377+
378+ function showPowerDialog() {
379+ if (!stages.dialogShown) {
380+ stages.dialogShown = true;
381+ PopupUtils.open(powerDialog);
382+ }
383+ }
384+
265385 Connections {
386+ id: dBusUnitySessionServiceConnection
387+ objectName: "dBusUnitySessionServiceConnection"
266388 target: DBusUnitySessionService
267389
268390 function closeAllApps() {
@@ -276,8 +398,27 @@ FocusScope {
276398 }
277399
278400 onLogoutRequested: {
279− // TODO: Display a dialog to ask the user to confirm.
280− DBusUnitySessionService.Logout();
401+ // Display a dialog to ask the user to confirm.
402+ if (!stages.dialogShown) {
403+ stages.dialogShown = true;
404+ PopupUtils.open(logoutDialog);
405+ }
406+ }
407+
408+ onShutdownRequested: {
409+ // Display a dialog to ask the user to confirm.
410+ if (!stages.dialogShown) {
411+ stages.dialogShown = true;
412+ PopupUtils.open(shutdownDialog);
413+ }
414+ }
415+
416+ onRebootRequested: {
417+ // Display a dialog to ask the user to confirm.
418+ if (!stages.dialogShown) {
419+ stages.dialogShown = true;
420+ PopupUtils.open(rebootDialog);
421+ }
281422 }
282423
283424 onLogoutReady: {
@@ -342,6 +483,8 @@ FocusScope {
342483 Connections {
343484 target: LightDM.Greeter
344485
486+ onShowGreeter: greeter.show()
487+
345488 onShowPrompt: {
346489 if (LightDM.Users.count == 1) {
347490 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
@@ -367,6 +510,12 @@ FocusScope {
367510 }
368511 }
369512
513+ Binding {
514+ target: LightDM.Greeter
515+ property: "active"
516+ value: greeter.shown || lockscreen.shown
517+ }
518+
370519 Rectangle {
371520 anchors.fill: parent
372521 color: "black"
@@ -406,6 +555,9 @@ FocusScope {
406555 onShownChanged: {
407556 if (shown) {
408557 lockscreen.reset();
558+ if (!LightDM.Greeter.promptless) {
559+ lockscreen.show();
560+ }
409561 // If there is only one user, we start authenticating with that one here.
410562 // If there are more users, the Greeter will handle that
411563 if (LightDM.Users.count == 1) {
@@ -466,10 +618,6 @@ FocusScope {
466618 stages.hide()
467619 }
468620
469− function hideIndicatorMenu(delay) {
470− panel.hideIndicatorMenu(delay);
471− }
472−
473621 Item {
474622 id: overlay
475623
@@ -673,4 +821,50 @@ FocusScope {
673821 target: SessionBroadcast
674822 onShowHome: showHome()
675823 }
824+
825+ Keys.onPressed: {
826+ if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
827+ if (!powerKeyTimer.running) {
828+ powerKeyTimer.start();
829+ }
830+ event.accepted = true;
831+ }
832+ }
833+
834+ Keys.onReleased: {
835+ if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
836+ powerKeyTimer.stop();
837+ event.accepted = true;
838+ }
839+ }
840+
841+ Timer {
842+ id: powerKeyTimer
843+ interval: 2000
844+ repeat: false
845+ triggeredOnStart: false
846+
847+ onTriggered: {
848+ stages.showPowerDialog();
849+ }
850+ }
851+
852+ Rectangle {
853+ id: shutdownFadeOutRectangle
854+ enabled: false
855+ visible: false
856+ color: "black"
857+ anchors.fill: parent
858+ opacity: 0.0
859+ NumberAnimation on opacity {
860+ id: shutdownFadeOut
861+ from: 0.0
862+ to: 1.0
863+ onStopped: {
864+ if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
865+ DBusUnitySessionService.Shutdown();
866+ }
867+ }
868+ }
869+ }
676870}