Ticket #5954: dynamic-menus-r24003.patch
File dynamic-menus-r24003.patch, 6.2 KB (added by , 16 years ago) |
---|
-
libs/libmythui/myththemedmenu.h
61 61 void CopyFrom(MythUIType*); 62 62 }; 63 63 64 class QDomDocument; 65 64 66 /// \brief Themed menu class, used for main menus in %MythTV frontend 65 67 class MPUBLIC MythThemedMenu : public MythThemedMenuState 66 68 { … … 94 96 void buttonAction(MythUIButtonListItem* item, bool skipPass = false); 95 97 96 98 private: 97 void Init(const QString &menufile); 99 MythThemedMenu(const QString command, MythScreenStack *parent, 100 MythThemedMenuState *state); 98 101 102 void Init(MythScreenStack *parent, MythThemedMenuState *state); 103 99 104 bool parseMenu(const QString &menuname); 105 bool parseMenu(const QDomDocument &doc, const QString &menuname); 100 106 void parseThemeButton(QDomElement &element); 101 107 102 108 void addButton(const QString &type, const QString &text, -
libs/libmythui/myththemedmenu.cpp
7 7 #include <QKeyEvent> 8 8 #include <QDomDocument> 9 9 #include <QFile> 10 #include <QProcess> 10 11 11 12 // Mythui headers 12 13 #include "mythmainwindow.h" … … 93 94 m_state(state), m_allocedstate(false), m_foundtheme(false), 94 95 m_exitModifier(0), m_ignorekeys(false), m_wantpop(false) 95 96 { 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 */ 109 MythThemedMenu::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 */ 159 void 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; 96 166 m_menuPopup = NULL; 97 167 98 168 if (!m_state) … … 101 171 m_allocedstate = true; 102 172 } 103 173 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 after110 * this method if this method was successful.111 *112 * \param menufile name of menu item xml file113 */114 void MythThemedMenu::Init(const QString &menufile)115 {116 174 ReloadExitKey(); 117 175 118 176 if (!m_state->m_loaded) … … 132 190 SLOT(setButtonActive(MythUIButtonListItem*))); 133 191 connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)), 134 192 SLOT(buttonAction(MythUIButtonListItem*))); 135 136 if (!parseMenu(menufile))137 m_foundtheme = false;138 193 } 139 194 140 195 MythThemedMenu::~MythThemedMenu(void) … … 495 550 if (text.isEmpty() && 496 551 info.attribute("lang","").isEmpty()) 497 552 { 498 text = qApp->translate("ThemeUI", 499 qPrintable(getFirstText(info))); 553 text = getFirstText(info); 500 554 } 501 555 else if (info.attribute("lang","").toLower() == 502 556 GetMythUI()->GetLanguageAndVariant()) … … 514 568 if (alttext.isEmpty() && 515 569 info.attribute("lang","").isEmpty()) 516 570 { 517 alttext = qApp->translate("ThemeUI", 518 qPrintable(getFirstText(info))); 571 alttext = getFirstText(info); 519 572 } 520 573 else if (info.attribute("lang","").toLower() == 521 574 GetMythUI()->GetLanguageAndVariant()) … … 653 706 654 707 VERBOSE(VB_GENERAL, QString("Loading menu theme from %1").arg(filename)); 655 708 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 */ 715 bool MythThemedMenu::parseMenu(const QDomDocument &doc, const QString &menuname) 716 { 656 717 QDomElement docElem = doc.documentElement(); 657 718 658 719 m_menumode = docElem.attribute("name", "MAIN"); … … 834 895 else 835 896 delete newmenu; 836 897 } 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 } 837 911 else if (action.left(6) == "UPMENU") 838 912 { 839 913 m_wantpop = true;