Ticket #7749: use_session_to_shutdown.patch

File use_session_to_shutdown.patch, 3.9 KB (added by superm1@…, 2 years ago)
  • programs/mythfrontend/mythfrontend.pro

     
    55QT += network xml sql webkit 
    66 
    77TEMPLATE = app 
    8 CONFIG += thread 
     8CONFIG += thread qdbus 
    99TARGET = mythfrontend 
    1010target.path = $${PREFIX}/bin 
    1111INSTALLS = target 
  • programs/mythfrontend/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 xfce("org.xfce.SessionManager", "/org/xfce/SessionManager", 
     21    //                    "org.xfce.Session.Manager"); 
     22    QDBusInterface kde("org.kde.ksmserver", "/KSMServer", 
     23                        "org.kde.KSMServerInterface"); 
     24    QDBusInterface gnome("org.gnome.SessionManager", "/org/gnome/SessionManager", 
     25                         "org.gnome.SessionManager"); 
     26 
     27    QDBusReply<void> void_reply = kde.call("logout", 0, 2, 2); 
     28 
     29    //XFCE dbus interface appears broken for now 
     30    //https://bugs.launchpad.net/ubuntu/+source/xfce4-session/+bug/496094 
     31    //if (!void_reply.isValid()) 
     32    //    void_reply = xfce.call("Shutdown", (uint) 2, (bool) false); 
     33    if (!void_reply.isValid()) 
    2134    { 
    22         myth_system(halt_cmd); 
     35        QDBusReply<bool> bool_reply = gnome.call("CanShutdown"); 
     36        if (bool_reply.isValid() && bool_reply.value() == 1) 
     37            void_reply=gnome.call("RequestShutdown"); 
    2338    } 
    24     else 
    25         VERBOSE(VB_IMPORTANT, "Cannot halt - null command!"); 
     39    if (!void_reply.isValid()) 
     40    { 
     41        QString halt_cmd = gContext->GetSetting("HaltCommand", 
     42                                            "sudo /sbin/halt -p"); 
     43        if (!halt_cmd.isEmpty()) 
     44            myth_system(halt_cmd); 
     45        else 
     46            VERBOSE(VB_IMPORTANT, "Cannot halt - null command!"); 
     47    } 
    2648} 
    2749 
    2850void ExitPrompter::reboot() 
    2951{ 
    30     QString reboot_cmd = gContext->GetSetting("RebootCommand", 
    31                                               "sudo /sbin/reboot"); 
    32     if (!reboot_cmd.isEmpty()) 
     52    //QDBusInterface xfce("org.xfce.SessionManager", "/org/xfce/SessionManager", 
     53    //                    "org.xfce.Session.Manager"); 
     54    QDBusInterface kde("org.kde.ksmserver", "/KSMServer", 
     55                        "org.kde.KSMServerInterface"); 
     56    QDBusInterface gnome("org.gnome.SessionManager", "/org/gnome/SessionManager", 
     57                         "org.gnome.SessionManager"); 
     58 
     59    QDBusReply<void> void_reply = kde.call("logout", 0, 1, 2); 
     60 
     61    //XFCE dbus interface appears broken for now 
     62    //https://bugs.launchpad.net/ubuntu/+source/xfce4-session/+bug/496094 
     63    //if (!void_reply.isValid()) 
     64    //    void_reply = xfce.call("Shutdown", (uint) 3, (bool) false); 
     65    if (!void_reply.isValid()) 
    3366    { 
    34         myth_system(reboot_cmd); 
     67        QDBusReply<bool> bool_reply = gnome.call("CanShutdown"); 
     68        if (bool_reply.isValid() && bool_reply.value() == 1) 
     69            void_reply=gnome.call("RequestReboot"); 
    3570    } 
    36     else 
    37         VERBOSE(VB_IMPORTANT, "Cannot reboot - null command!"); 
     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()