Ticket #5954: dynamic-menus-r24003.patch

File dynamic-menus-r24003.patch, 6.2 KB (added by andrei@…, 16 years ago)

Current (Apr 2010) version of the patch

  • libs/libmythui/myththemedmenu.h

     
    6161    void CopyFrom(MythUIType*);
    6262};
    6363
     64class QDomDocument;
     65
    6466/// \brief Themed menu class, used for main menus in %MythTV frontend
    6567class MPUBLIC MythThemedMenu : public MythThemedMenuState
    6668{
     
    9496    void buttonAction(MythUIButtonListItem* item, bool skipPass = false);
    9597
    9698  private:
    97     void Init(const QString &menufile);
     99    MythThemedMenu(const QString command, MythScreenStack *parent,
     100                    MythThemedMenuState *state);
    98101
     102    void Init(MythScreenStack *parent, MythThemedMenuState *state);
     103
    99104    bool parseMenu(const QString &menuname);
     105    bool parseMenu(const QDomDocument &doc, const QString &menuname);
    100106    void parseThemeButton(QDomElement &element);
    101107
    102108    void addButton(const QString &type, const QString &text,
  • libs/libmythui/myththemedmenu.cpp

     
    77#include <QKeyEvent>
    88#include <QDomDocument>
    99#include <QFile>
     10#include <QProcess>
    1011
    1112// Mythui headers
    1213#include "mythmainwindow.h"
     
    9394      m_state(state), m_allocedstate(false), m_foundtheme(false),
    9495      m_exitModifier(0), m_ignorekeys(false), m_wantpop(false)
    9596{
     97    Init(parent, state);
     98
     99    if (!parseMenu(menufile))
     100        m_foundtheme = false;
     101}
     102
     103/** \brief Creates a dynamic themed menu.
     104 *
     105 *  \param command      external command to execute
     106 *  \param parent       the screen stack that owns this UI type
     107 *  \param state        theme state associated with this menu
     108 */
     109MythThemedMenu::MythThemedMenu(const QString command, MythScreenStack *parent,
     110                               MythThemedMenuState *state)
     111              : MythThemedMenuState(parent, command)
     112{
     113    Init(parent, state);
     114
     115    QProcess process;
     116    process.start(command);
     117    if (!process.waitForFinished())
     118    {
     119        process.kill();
     120        VERBOSE(VB_IMPORTANT,
     121                QString("Command \"%1\" returned error\n").arg(command));
     122        ShowOkPopup(QObject::tr("Couldn't execute %1")
     123                    .arg(command));
     124
     125        m_foundtheme = false;
     126        return;
     127    }
     128    else
     129    {
     130        QString errorMsg;
     131        int errorLine = 0;
     132        int errorColumn = 0;
     133
     134        QDomDocument doc;
     135        if (!doc.setContent(process.readAllStandardOutput(), false,
     136            &errorMsg, &errorLine, &errorColumn))
     137        {
     138            VERBOSE(VB_IMPORTANT,
     139                    QString("Error parsing output of: %1\nat line: %2  column: %3 msg: %4").
     140                    arg(command).arg(errorLine).arg(errorColumn).arg(errorMsg));
     141
     142            ShowOkPopup(QObject::tr("Command %1 returned incomplete menu.")
     143                    .arg(command));
     144
     145            m_foundtheme = false;
     146            return;
     147        }
     148
     149        if (!parseMenu(doc, command))
     150            m_foundtheme = false;
     151    }
     152}
     153
     154/** \brief Initializes the menu state.
     155 *
     156 *  \param parent       the screen stack that owns this UI type
     157 *  \param state        theme state associated with this menu
     158*/
     159void MythThemedMenu::Init(MythScreenStack *parent, MythThemedMenuState *state)
     160{
     161    m_state = state;
     162    m_allocedstate = m_foundtheme = m_ignorekeys = m_wantpop = false;
     163    m_exitModifier = -1;
     164    m_menumode = "";
     165    m_buttonList = NULL;
    96166    m_menuPopup = NULL;
    97167
    98168    if (!m_state)
     
    101171        m_allocedstate = true;
    102172    }
    103173
    104     Init(menufile);
    105 }
    106 
    107 /** \brief Loads the main UI theme, and a menu theme.
    108  *
    109  *  See also foundtheme(void), it will return true when called after
    110  *  this method if this method was successful.
    111  *
    112  *  \param menufile name of menu item xml file
    113  */
    114 void MythThemedMenu::Init(const QString &menufile)
    115 {
    116174    ReloadExitKey();
    117175
    118176    if (!m_state->m_loaded)
     
    132190            SLOT(setButtonActive(MythUIButtonListItem*)));
    133191    connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)),
    134192            SLOT(buttonAction(MythUIButtonListItem*)));
    135 
    136     if (!parseMenu(menufile))
    137         m_foundtheme = false;
    138193}
    139194
    140195MythThemedMenu::~MythThemedMenu(void)
     
    495550                if (text.isEmpty() &&
    496551                    info.attribute("lang","").isEmpty())
    497552                {
    498                     text = qApp->translate("ThemeUI",
    499                                             qPrintable(getFirstText(info)));
     553                    text = getFirstText(info);
    500554                }
    501555                else if (info.attribute("lang","").toLower() ==
    502556                         GetMythUI()->GetLanguageAndVariant())
     
    514568                if (alttext.isEmpty() &&
    515569                    info.attribute("lang","").isEmpty())
    516570                {
    517                     alttext = qApp->translate("ThemeUI",
    518                                             qPrintable(getFirstText(info)));
     571                    alttext = getFirstText(info);
    519572                }
    520573                else if (info.attribute("lang","").toLower() ==
    521574                         GetMythUI()->GetLanguageAndVariant())
     
    653706
    654707    VERBOSE(VB_GENERAL, QString("Loading menu theme from %1").arg(filename));
    655708
     709    return parseMenu(doc, menuname);
     710}
     711
     712/** \brief Parse the themebuttons to be added based on the contents
     713 *         of the provided XML document.
     714 */
     715bool MythThemedMenu::parseMenu(const QDomDocument &doc, const QString &menuname)
     716{
    656717    QDomElement docElem = doc.documentElement();
    657718
    658719    m_menumode = docElem.attribute("name", "MAIN");
     
    834895        else
    835896            delete newmenu;
    836897    }
     898    else if (action.left(9) == "MENUEXEC ")
     899    {
     900        QString command = action.mid(9);
     901
     902        MythScreenStack *stack = GetScreenStack();
     903
     904        MythThemedMenu *newmenu = new MythThemedMenu(command, stack, m_state);
     905
     906        if (newmenu->foundTheme())
     907            stack->AddScreen(newmenu);
     908        else
     909            delete newmenu;
     910    }
    837911    else if (action.left(6) == "UPMENU")
    838912    {
    839913        m_wantpop = true;