Ticket #7749: use_session_ck_hal.diff

File use_session_ck_hal.diff, 4.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", 
     21                       "/KSMServer", 
     22                       "org.kde.KSMServerInterface"); 
     23    QDBusInterface gnome("org.gnome.SessionManager", 
     24                         "/org/gnome/SessionManager", 
     25                         "org.gnome.SessionManager"); 
     26    QDBusInterface consolekit("org.freedesktop.ConsoleKit", 
     27                              "/org/freedesktop/ConsoleKit/Manager", 
     28                              "org.freedesktop.ConsoleKit.Manager", 
     29                              QDBusConnection::systemBus()); 
     30    QDBusInterface hal("org.freedesktop.Hal", 
     31                       "/org/freedesktop/Hal/devices/computer", 
     32                       "org.freedesktop.Hal.Device.SystemPowerManagement", 
     33                       QDBusConnection::systemBus()); 
     34 
     35    QDBusReply<void> void_reply = kde.call("logout", 0, 2, 2); 
     36    QDBusReply<bool> bool_reply; 
     37    QDBusReply<int>  int_reply; 
     38 
     39    if (!void_reply.isValid()) 
    2140    { 
    22         myth_system(halt_cmd); 
     41        bool_reply = gnome.call("CanShutdown"); 
     42        if (bool_reply.isValid() && bool_reply.value() == 1) 
     43            void_reply = gnome.call("RequestShutdown"); 
    2344    } 
    24     else 
    25         VERBOSE(VB_IMPORTANT, "Cannot halt - null command!"); 
     45    if (!void_reply.isValid()) 
     46    { 
     47        bool_reply = consolekit.call("CanStop"); 
     48        if (bool_reply.isValid() && bool_reply.value() == 1) 
     49            void_reply = consolekit.call("Stop"); 
     50    } 
     51    if (!void_reply.isValid()) 
     52        int_reply = hal.call("Shutdown"); 
     53    if (!void_reply.isValid() && !int_reply.isValid()) 
     54    { 
     55        QString halt_cmd = gContext->GetSetting("HaltCommand", 
     56                                            "sudo /sbin/halt -p"); 
     57        if (!halt_cmd.isEmpty()) 
     58            myth_system(halt_cmd); 
     59        else 
     60            VERBOSE(VB_IMPORTANT, "Cannot halt - null command!"); 
     61    } 
    2662} 
    2763 
    2864void ExitPrompter::reboot() 
    2965{ 
    30     QString reboot_cmd = gContext->GetSetting("RebootCommand", 
    31                                               "sudo /sbin/reboot"); 
    32     if (!reboot_cmd.isEmpty()) 
     66    QDBusInterface kde("org.kde.ksmserver", 
     67                       "/KSMServer", 
     68                       "org.kde.KSMServerInterface"); 
     69    QDBusInterface gnome("org.gnome.SessionManager", 
     70                         "/org/gnome/SessionManager", 
     71                         "org.gnome.SessionManager"); 
     72    QDBusInterface consolekit("org.freedesktop.ConsoleKit", 
     73                              "/org/freedesktop/ConsoleKit/Manager", 
     74                              "org.freedesktop.ConsoleKit.Manager", 
     75                              QDBusConnection::systemBus()); 
     76    QDBusInterface hal("org.freedesktop.Hal", 
     77                       "/org/freedesktop/Hal/devices/computer", 
     78                       "org.freedesktop.Hal.Device.SystemPowerManagement", 
     79                       QDBusConnection::systemBus()); 
     80 
     81    QDBusReply<void> void_reply = kde.call("logout", 0, 1, 2); 
     82    QDBusReply<bool> bool_reply; 
     83    QDBusReply<int>  int_reply; 
     84 
     85    if (!void_reply.isValid()) 
    3386    { 
    34         myth_system(reboot_cmd); 
     87        bool_reply = gnome.call("CanShutdown"); 
     88        if (bool_reply.isValid() && bool_reply.value() == 1) 
     89            void_reply=gnome.call("RequestReboot"); 
    3590    } 
    36     else 
    37         VERBOSE(VB_IMPORTANT, "Cannot reboot - null command!"); 
     91    if (!void_reply.isValid()) 
     92    { 
     93        bool_reply = consolekit.call("CanRestart"); 
     94        if (bool_reply.isValid() && bool_reply.value() == 1) 
     95            void_reply = consolekit.call("Restart"); 
     96    } 
     97    if (!void_reply.isValid()) 
     98        int_reply = hal.call("Reboot"); 
     99    if (!void_reply.isValid() && !int_reply.isValid()) 
     100    { 
     101        QString reboot_cmd = gContext->GetSetting("RebootCommand", 
     102                                              "sudo /sbin/reboot"); 
     103        if (!reboot_cmd.isEmpty()) 
     104            myth_system(reboot_cmd); 
     105        else 
     106            VERBOSE(VB_IMPORTANT, "Cannot reboot - null command!"); 
     107    } 
    38108} 
    39109 
    40110void ExitPrompter::handleExit()