Ticket #4571: svn_main_menu_popup.patch

File svn_main_menu_popup.patch, 5.7 KB (added by james.meyer@…, 15 years ago)

updated patch for sv rev 19291

  • libs/libmythui/myththemedmenu.h

     
    22#define MYTHTHEMEDMENU_H_
    33
    44#include "mythscreentype.h"
     5#include "mythdialogbox.h"
    56#include "mythuistatetype.h"
    67#include "mythuibuttonlist.h"
    78#include "xmlparsebase.h"
     
    7778    void ReloadExitKey(void);
    7879    virtual void aboutToShow(void);
    7980
     81    void doMenu();
     82    void aboutScreen();
     83    MythDialogBox *m_menuPopup;
     84    void customEvent(QEvent *event);
     85
    8086  protected:
    8187    virtual bool keyPressEvent(QKeyEvent *e);
    8288
  • libs/libmythui/myththemedmenu.cpp

     
    3232    m_callbackdata = NULL;
    3333
    3434    m_killable = false;
     35
    3536}
    3637
    3738MythThemedMenuState::~MythThemedMenuState()
     
    9596    m_exitModifier = -1;
    9697    m_menumode = "";
    9798    m_buttonList = NULL;
    98 
     99    m_menuPopup = NULL;
    99100    if (!m_state)
    100101    {
    101102        m_state = new MythThemedMenuState(parent, "themedmenustate");
     
    271272                m_wantpop = true;
    272273            }
    273274        }
     275        else if (action == "MENU")
     276        {
     277            doMenu();
     278        }
    274279        else
    275280            handled = false;
    276281    }
     
    292297    updateLCD();
    293298}
    294299
     300void MythThemedMenu::doMenu()
     301{
     302
     303    if (m_menuPopup)
     304        return;
     305    int allowsd =  GetMythDB()->GetNumSetting("AllowQuitShutdown");
     306    int override_menu = GetMythDB()->GetNumSetting("OverRideExitMenu");
     307    QString label = "System Menu";
     308    MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
     309    m_menuPopup = new MythDialogBox(label, mainStack, "menuPopup");
     310    if (m_menuPopup->Create())
     311        mainStack->AddScreen(m_menuPopup);
     312    if ( override_menu == 0 )
     313    {
     314        if ( allowsd != 0 && allowsd !=4  )
     315        {
     316            m_menuPopup->SetReturnEvent(this,"popmenu_exit");
     317            m_menuPopup->AddButton("Shutdown");
     318            m_menuPopup->AddButton("Reboot");
     319        }
     320        else
     321        {
     322            m_menuPopup->SetReturnEvent(this,"popmenu_noexit");
     323        }
     324    }
     325    if ( override_menu == 5 )
     326    { // reboot
     327        m_menuPopup->SetReturnEvent(this,"popmenu_reboot");
     328        m_menuPopup->AddButton("Reboot");
     329    }
     330    else if ( override_menu == 2 || override_menu == 4 )
     331    { // shutdown
     332            m_menuPopup->SetReturnEvent(this,"popmenu_shutdown");
     333            m_menuPopup->AddButton("Shutdown");
     334    }
     335    else if ( override_menu == 3 || override_menu == 6 )
     336    { //    both
     337        m_menuPopup->SetReturnEvent(this,"popmenu_exit");
     338        m_menuPopup->AddButton("Shutdown");
     339        m_menuPopup->AddButton("Reboot");
     340    }
     341    else
     342    {
     343        m_menuPopup->SetReturnEvent(this,"popmenu_noexit");
     344    }
     345
     346    m_menuPopup->AddButton("About");
     347    m_menuPopup->AddButton("Cancel");
     348
     349}
     350void MythThemedMenu::aboutScreen()
     351{
     352
     353    extern const char *myth_source_version;
     354    extern const char *myth_source_path;
     355    QString distro_line;
     356    distro_line="";
     357
     358    QFile file("/etc/os_myth_release");
     359    if ( file.open(QFile::ReadOnly))
     360    {
     361        QTextStream t( &file );        // use a text stream
     362        distro_line = t.readLine();
     363        file.close();
     364    }
     365
     366    QString label = "";
     367    label.append(QObject::tr("Revision: ") + myth_source_version   + "  \n  Branch:" +  myth_source_path  + "\n" + distro_line );
     368
     369    MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
     370    m_menuPopup = new MythDialogBox(label, mainStack, "About");
     371    if (m_menuPopup->Create())
     372        mainStack->AddScreen(m_menuPopup);
     373
     374    m_menuPopup->SetReturnEvent(this,"About");
     375    m_menuPopup->AddButton("OK!");
     376
     377}
     378
     379void MythThemedMenu::customEvent(QEvent *event)
     380{
     381    if (event->type() == kMythDialogBoxCompletionEventType)
     382    {
     383        DialogCompletionEvent *dce =
     384                dynamic_cast<DialogCompletionEvent*>(event);
     385        QString resultid= dce->GetId();
     386        int buttonnum  = dce->GetResult();
     387        QString halt_cmd=GetMythDB()->GetSetting("HaltCommand");
     388        QString reboot_cmd=GetMythDB()->GetSetting("RebootCommand");
     389
     390        if (resultid == "popmenu_exit")
     391        {
     392            if (buttonnum == 0)
     393            {
     394                if (!halt_cmd.isEmpty() )
     395                    system(halt_cmd.toAscii());
     396            }
     397
     398            if (buttonnum == 1)
     399            {
     400                if (!reboot_cmd.isEmpty() )
     401                    system(reboot_cmd.toAscii());
     402            }
     403
     404            if (buttonnum == 2)
     405            {
     406                aboutScreen();
     407            }
     408        }
     409
     410        if (resultid == "popmenu_noexit")
     411        {
     412            if (buttonnum == 0)
     413                aboutScreen();
     414        }
     415
     416        if (resultid == "popmenu_reboot")
     417        {
     418            if (buttonnum == 0)
     419            {
     420                if (!reboot_cmd.isEmpty() )
     421                    system(reboot_cmd.toAscii());
     422            }
     423
     424            if (buttonnum == 1)
     425            {
     426                aboutScreen();
     427            }
     428        }
     429
     430        if (resultid == "popmenu_shutdown")
     431        {
     432            if (buttonnum == 0)
     433            {
     434                if (!halt_cmd.isEmpty() )
     435                    system(halt_cmd.toAscii());
     436            }
     437
     438            if (buttonnum == 1)
     439            {
     440                aboutScreen();
     441            }
     442        }
     443
     444        m_menuPopup = NULL;
     445    }
     446}
     447
    295448/** \brief Parses the element's tags and set the ThemeButton's type,
    296449 *         text, depends, and action, then adds the button.
    297450 *