@@ -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 Utils 0.1
@@ -242,7 +243,128 @@ Item {
242243 }
243244 }
244245
246+ property bool dialogShown: false
247+
248+ Component {
249+ id: logoutDialog
250+ Dialog {
251+ id: dialogueLogout
252+ title: "Logout"
253+ text: "Are you sure that you want to logout?"
254+ Button {
255+ text: "Cancel"
256+ onClicked: {
257+ PopupUtils.close(dialogueLogout);
258+ stages.dialogShown = false;
259+ }
260+ }
261+ Button {
262+ text: "Yes"
263+ onClicked: {
264+ DBusUnitySessionService.Logout();
265+ PopupUtils.close(dialogueLogout);
266+ stages.dialogShown = false;
267+ }
268+ }
269+ }
270+ }
271+
272+ Component {
273+ id: shutdownDialog
274+ Dialog {
275+ id: dialogueShutdown
276+ title: "Shutdown"
277+ text: "Are you sure that you want to shutdown?"
278+ Button {
279+ text: "Cancel"
280+ onClicked: {
281+ PopupUtils.close(dialogueShutdown);
282+ stages.dialogShown = false;
283+ }
284+ }
285+ Button {
286+ text: "Yes"
287+ onClicked: {
288+ dBusUnitySessionServiceConnection.closeAllApps();
289+ DBusUnitySessionService.Shutdown();
290+ PopupUtils.close(dialogueShutdown);
291+ stages.dialogShown = false;
292+ }
293+ }
294+ }
295+ }
296+
297+ Component {
298+ id: rebootDialog
299+ Dialog {
300+ id: dialogueReboot
301+ title: "Reboot"
302+ text: "Are you sure that you want to reboot?"
303+ Button {
304+ text: "Cancel"
305+ onClicked: {
306+ PopupUtils.close(dialogueReboot)
307+ stages.dialogShown = false;
308+ }
309+ }
310+ Button {
311+ text: "Yes"
312+ onClicked: {
313+ dBusUnitySessionServiceConnection.closeAllApps();
314+ DBusUnitySessionService.Reboot();
315+ PopupUtils.close(dialogueReboot);
316+ stages.dialogShown = false;
317+ }
318+ }
319+ }
320+ }
321+
322+ Component {
323+ id: powerDialog
324+ Dialog {
325+ id: dialoguePower
326+ title: "Power"
327+ text: i18n.tr("Are you sure you would like to turn power off?")
328+ Button {
329+ text: i18n.tr("Power off")
330+ onClicked: {
331+ dBusUnitySessionServiceConnection.closeAllApps();
332+ PopupUtils.close(dialoguePower);
333+ stages.dialogShown = false;
334+ shutdownFadeOutRectangle.enabled = true;
335+ shutdownFadeOutRectangle.visible = true;
336+ shutdownFadeOut.start();
337+ }
338+ }
339+ Button {
340+ text: i18n.tr("Restart")
341+ onClicked: {
342+ dBusUnitySessionServiceConnection.closeAllApps();
343+ DBusUnitySessionService.Reboot();
344+ PopupUtils.close(dialoguePower);
345+ stages.dialogShown = false;
346+ }
347+ }
348+ Button {
349+ text: i18n.tr("Cancel")
350+ onClicked: {
351+ PopupUtils.close(dialoguePower);
352+ stages.dialogShown = false;
353+ }
354+ }
355+ }
356+ }
357+
358+ function showPowerDialog() {
359+ if (!stages.dialogShown) {
360+ stages.dialogShown = true;
361+ PopupUtils.open(powerDialog);
362+ }
363+ }
364+
245365 Connections {
366+ id: dBusUnitySessionServiceConnection
367+ objectName: "dBusUnitySessionServiceConnection"
246368 target: DBusUnitySessionService
247369
248370 function closeAllApps() {
@@ -256,8 +378,27 @@ Item {
256378 }
257379
258380 onLogoutRequested: {
259− // TODO: Display a dialog to ask the user to confirm.
260− DBusUnitySessionService.Logout();
381+ // Display a dialog to ask the user to confirm.
382+ if (!stages.dialogShown) {
383+ stages.dialogShown = true;
384+ PopupUtils.open(logoutDialog);
385+ }
386+ }
387+
388+ onShutdownRequested: {
389+ // Display a dialog to ask the user to confirm.
390+ if (!stages.dialogShown) {
391+ stages.dialogShown = true;
392+ PopupUtils.open(shutdownDialog);
393+ }
394+ }
395+
396+ onRebootRequested: {
397+ // Display a dialog to ask the user to confirm.
398+ if (!stages.dialogShown) {
399+ stages.dialogShown = true;
400+ PopupUtils.open(rebootDialog);
401+ }
261402 }
262403
263404 onLogoutReady: {
@@ -349,6 +490,8 @@ Item {
349490 Connections {
350491 target: LightDM.Greeter
351492
493+ onShowGreeter: greeter.show()
494+
352495 onShowPrompt: {
353496 if (LightDM.Users.count == 1) {
354497 // TODO: There's no better way for now to determine if its a PIN or a passphrase.
@@ -374,6 +517,12 @@ Item {
374517 }
375518 }
376519
520+ Binding {
521+ target: LightDM.Greeter
522+ property: "active"
523+ value: greeter.shown || lockscreen.shown
524+ }
525+
377526 Rectangle {
378527 anchors.fill: parent
379528 color: "black"
@@ -413,6 +562,9 @@ Item {
413562 onShownChanged: {
414563 if (shown) {
415564 lockscreen.reset();
565+ if (!LightDM.Greeter.promptless) {
566+ lockscreen.show();
567+ }
416568 // If there is only one user, we start authenticating with that one here.
417569 // If there are more users, the Greeter will handle that
418570 if (LightDM.Users.count == 1) {
@@ -613,4 +765,50 @@ Item {
613765 target: SessionBroadcast
614766 onShowHome: showHome()
615767 }
768+
769+ Keys.onPressed: {
770+ if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
771+ if (!powerKeyTimer.running) {
772+ powerKeyTimer.start();
773+ }
774+ event.accepted = true;
775+ }
776+ }
777+
778+ Keys.onReleased: {
779+ if (event.key == Qt.Key_PowerOff || event.key == Qt.Key_PowerDown) {
780+ powerKeyTimer.stop();
781+ event.accepted = true;
782+ }
783+ }
784+
785+ Timer {
786+ id: powerKeyTimer
787+ interval: 2000
788+ repeat: false
789+ triggeredOnStart: false
790+
791+ onTriggered: {
792+ stages.showPowerDialog();
793+ }
794+ }
795+
796+ Rectangle {
797+ id: shutdownFadeOutRectangle
798+ enabled: false
799+ visible: false
800+ color: "black"
801+ anchors.fill: parent
802+ opacity: 0.0
803+ NumberAnimation on opacity {
804+ id: shutdownFadeOut
805+ from: 0.0
806+ to: 1.0
807+ onStopped: {
808+ if (shutdownFadeOutRectangle.enabled && shutdownFadeOutRectangle.visible) {
809+ DBusUnitySessionService.Shutdown();
810+ }
811+ }
812+ }
813+ }
616814}