Index: programs/mythfrontend/mythfrontend.pro
===================================================================
--- programs/mythfrontend/mythfrontend.pro	(revision 22974)
+++ programs/mythfrontend/mythfrontend.pro	(working copy)
@@ -5,7 +5,7 @@
 QT += network xml sql webkit
 
 TEMPLATE = app
-CONFIG += thread
+CONFIG += thread qdbus
 TARGET = mythfrontend
 target.path = $${PREFIX}/bin
 INSTALLS = target
Index: programs/mythfrontend/exitprompt.cpp
===================================================================
--- programs/mythfrontend/exitprompt.cpp	(revision 22974)
+++ programs/mythfrontend/exitprompt.cpp	(working copy)
@@ -1,5 +1,7 @@
 
 #include <QCoreApplication>
+#include <QtDBus>
+#include <QDBusInterface>
 
 #include "exitprompt.h"
 #include "mythcontext.h"
@@ -15,26 +17,66 @@
 
 void ExitPrompter::halt()
 {
-    QString halt_cmd = gContext->GetSetting("HaltCommand",
-                                            "sudo /sbin/halt -p");
-    if (!halt_cmd.isEmpty())
+    //QDBusInterface xfce("org.xfce.SessionManager", "/org/xfce/SessionManager",
+    //                    "org.xfce.Session.Manager");
+    QDBusInterface kde("org.kde.ksmserver", "/KSMServer",
+                        "org.kde.KSMServerInterface");
+    QDBusInterface gnome("org.gnome.SessionManager", "/org/gnome/SessionManager",
+                         "org.gnome.SessionManager");
+
+    QDBusReply<void> void_reply = kde.call("logout", 0, 2, 2);
+
+    //XFCE dbus interface appears broken for now
+    //https://bugs.launchpad.net/ubuntu/+source/xfce4-session/+bug/496094
+    //if (!void_reply.isValid())
+    //    void_reply = xfce.call("Shutdown", (uint) 2, (bool) false);
+    if (!void_reply.isValid())
     {
-        myth_system(halt_cmd);
+        QDBusReply<bool> bool_reply = gnome.call("CanShutdown");
+        if (bool_reply.isValid() && bool_reply.value() == 1)
+            void_reply=gnome.call("RequestShutdown");
     }
-    else
-        VERBOSE(VB_IMPORTANT, "Cannot halt - null command!");
+    if (!void_reply.isValid())
+    {
+        QString halt_cmd = gContext->GetSetting("HaltCommand",
+                                            "sudo /sbin/halt -p");
+        if (!halt_cmd.isEmpty())
+            myth_system(halt_cmd);
+        else
+            VERBOSE(VB_IMPORTANT, "Cannot halt - null command!");
+    }
 }
 
 void ExitPrompter::reboot()
 {
-    QString reboot_cmd = gContext->GetSetting("RebootCommand",
-                                              "sudo /sbin/reboot");
-    if (!reboot_cmd.isEmpty())
+    //QDBusInterface xfce("org.xfce.SessionManager", "/org/xfce/SessionManager",
+    //                    "org.xfce.Session.Manager");
+    QDBusInterface kde("org.kde.ksmserver", "/KSMServer",
+                        "org.kde.KSMServerInterface");
+    QDBusInterface gnome("org.gnome.SessionManager", "/org/gnome/SessionManager",
+                         "org.gnome.SessionManager");
+
+    QDBusReply<void> void_reply = kde.call("logout", 0, 1, 2);
+
+    //XFCE dbus interface appears broken for now
+    //https://bugs.launchpad.net/ubuntu/+source/xfce4-session/+bug/496094
+    //if (!void_reply.isValid())
+    //    void_reply = xfce.call("Shutdown", (uint) 3, (bool) false);
+    if (!void_reply.isValid())
     {
-        myth_system(reboot_cmd);
+        QDBusReply<bool> bool_reply = gnome.call("CanShutdown");
+        if (bool_reply.isValid() && bool_reply.value() == 1)
+            void_reply=gnome.call("RequestReboot");
     }
-    else
-        VERBOSE(VB_IMPORTANT, "Cannot reboot - null command!");
+    if (!void_reply.isValid())
+    {
+        QString reboot_cmd = gContext->GetSetting("RebootCommand",
+                                              "sudo /sbin/reboot");
+        if (!reboot_cmd.isEmpty())
+            myth_system(reboot_cmd);
+        else
+            VERBOSE(VB_IMPORTANT, "Cannot reboot - null command!");
+    }
 }
 
 void ExitPrompter::handleExit()

