Ticket #7749: use_session_or_console_kit.patch

File use_session_or_console_kit.patch, 3.8 KB (added by superm1@…, 2 years ago)
  • mythfrontend.pro

     
    55QT += network xml sql webkit 
    66 
    77TEMPLATE = app 
    8 CONFIG += thread 
     8CONFIG += thread qdbus 
    99TARGET = mythfrontend 
    1010target.path = $${PREFIX}/bin 
    1111INSTALLS = target 
  • exitprompt.cpp

     
    11 
    22#include <QCoreApplication> 
     3#include <QtDBus> 
     4#include <QDBusInterface> 
    35 
    46#include "exitprompt.h" 
    57#include "mythcontext.h" 
     
    1517 
    1618void ExitPrompter::halt() 
    1719{ 
    18     QString halt_cmd = gContext->GetSetting("HaltCommand", 
    19                                             "sudo /sbin/halt -p"); 
    20     if (!halt_cmd.isEmpty()) 
     20    QDBusInterface kde("org.kde.ksmserver", "/KSMServer", 
     21                        "org.kde.KSMServerInterface"); 
     22    QDBusInterface gnome("org.gnome.SessionManager", "/org/gnome/SessionManager", 
     23                         "org.gnome.SessionManager"); 
     24    QDBusInterface consolekit("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", 
     25                              "org.freedesktop.ConsoleKit.Manager",QDBusConnection::systemBus()); 
     26 
     27    QDBusReply<void> void_reply = kde.call("logout", 0, 2, 2); 
     28    QDBusReply<bool> bool_reply = gnome.call("CanShutdown"); 
     29 
     30    if (!void_reply.isValid() && bool_reply.isValid() && bool_reply.value() ==1) 
     31        void_reply = gnome.call("RequestShutdown"); 
     32    if (!void_reply.isValid()) 
    2133    { 
    22         myth_system(halt_cmd); 
     34        bool_reply = consolekit.call("CanStop"); 
     35        if (bool_reply.isValid() && bool_reply.value() ==1) 
     36            void_reply = consolekit.call("Stop"); 
    2337    } 
    24     else 
    25         VERBOSE(VB_IMPORTANT, "Cannot halt - null command!"); 
     38    if (!void_reply.isValid()) 
     39    { 
     40        QString halt_cmd = gContext->GetSetting("HaltCommand", 
     41                                            "sudo /sbin/halt -p"); 
     42        if (!halt_cmd.isEmpty()) 
     43            myth_system(halt_cmd); 
     44        else 
     45            VERBOSE(VB_IMPORTANT, "Cannot halt - null command!"); 
     46    } 
    2647} 
    2748 
    2849void ExitPrompter::reboot() 
    2950{ 
    30     QString reboot_cmd = gContext->GetSetting("RebootCommand", 
    31                                               "sudo /sbin/reboot"); 
    32     if (!reboot_cmd.isEmpty()) 
     51    QDBusInterface kde("org.kde.ksmserver", "/KSMServer", 
     52                        "org.kde.KSMServerInterface"); 
     53    QDBusInterface gnome("org.gnome.SessionManager", "/org/gnome/SessionManager", 
     54                         "org.gnome.SessionManager"); 
     55    QDBusInterface consolekit("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", 
     56                              "org.freedesktop.ConsoleKit.Manager",QDBusConnection::systemBus()); 
     57 
     58    QDBusReply<void> void_reply = kde.call("logout", 0, 1, 2); 
     59    QDBusReply<bool> bool_reply = gnome.call("CanShutdown"); 
     60 
     61    if (!void_reply.isValid() && bool_reply.isValid() && bool_reply.value() == 1) 
    3362    { 
    34         myth_system(reboot_cmd); 
     63        void_reply=gnome.call("RequestReboot"); 
    3564    } 
    36     else 
    37         VERBOSE(VB_IMPORTANT, "Cannot reboot - null command!"); 
     65    if (!void_reply.isValid()) 
     66    { 
     67        bool_reply = consolekit.call("CanRestart"); 
     68        if (bool_reply.isValid() && bool_reply.value() ==1) 
     69            void_reply = consolekit.call("Restart"); 
     70    } 
     71    if (!void_reply.isValid()) 
     72    { 
     73        QString reboot_cmd = gContext->GetSetting("RebootCommand", 
     74                                              "sudo /sbin/reboot"); 
     75        if (!reboot_cmd.isEmpty()) 
     76            myth_system(reboot_cmd); 
     77        else 
     78            VERBOSE(VB_IMPORTANT, "Cannot reboot - null command!"); 
     79    } 
    3880} 
    3981 
    4082void ExitPrompter::handleExit()