Index: mythfrontend.pro
===================================================================
--- mythfrontend.pro	(revision 22974)
+++ 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: exitprompt.cpp
===================================================================
--- exitprompt.cpp	(revision 22974)
+++ 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 kde("org.kde.ksmserver", "/KSMServer",
+                        "org.kde.KSMServerInterface");
+    QDBusInterface gnome("org.gnome.SessionManager", "/org/gnome/SessionManager",
+                         "org.gnome.SessionManager");
+    QDBusInterface consolekit("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager",
+                              "org.freedesktop.ConsoleKit.Manager",QDBusConnection::systemBus());
+
+    QDBusReply<void> void_reply = kde.call("logout", 0, 2, 2);
+    QDBusReply<bool> bool_reply = gnome.call("CanShutdown");
+
+    if (!void_reply.isValid() && bool_reply.isValid() && bool_reply.value() ==1)
+        void_reply = gnome.call("RequestShutdown");
+    if (!void_reply.isValid())
     {
-        myth_system(halt_cmd);
+        bool_reply = consolekit.call("CanStop");
+        if (bool_reply.isValid() && bool_reply.value() ==1)
+            void_reply = consolekit.call("Stop");
     }
-    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 kde("org.kde.ksmserver", "/KSMServer",
+                        "org.kde.KSMServerInterface");
+    QDBusInterface gnome("org.gnome.SessionManager", "/org/gnome/SessionManager",
+                         "org.gnome.SessionManager");
+    QDBusInterface consolekit("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager",
+                              "org.freedesktop.ConsoleKit.Manager",QDBusConnection::systemBus());
+
+    QDBusReply<void> void_reply = kde.call("logout", 0, 1, 2);
+    QDBusReply<bool> bool_reply = gnome.call("CanShutdown");
+
+    if (!void_reply.isValid() && bool_reply.isValid() && bool_reply.value() == 1)
     {
-        myth_system(reboot_cmd);
+        void_reply=gnome.call("RequestReboot");
     }
-    else
-        VERBOSE(VB_IMPORTANT, "Cannot reboot - null command!");
+    if (!void_reply.isValid())
+    {
+        bool_reply = consolekit.call("CanRestart");
+        if (bool_reply.isValid() && bool_reply.value() ==1)
+            void_reply = consolekit.call("Restart");
+    }
+    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()

