Ticket #5954: dynamic_menus-r19940.patch
File dynamic_menus-r19940.patch, 7.2 KB (added by , 17 years ago) |
---|
-
libs/libmythui/myththemedmenu.cpp
2 2 #include <QDir> 3 3 #include <QKeyEvent> 4 4 #include <QDomDocument> 5 #include <QProcess> 5 6 6 7 #include "myththemedmenu.h" 7 8 #include "mythmainwindow.h" … … 85 86 MythScreenStack *parent, const QString &name, 86 87 bool allowreorder, MythThemedMenuState *state) 87 88 : MythThemedMenuState(parent, name), 88 m_state(state), m_allocedstate(false), m_foundtheme(false), 89 m_parent(parent), m_state(state), 90 m_allocedstate(false), m_foundtheme(false), 89 91 m_exitModifier(-1), m_ignorekeys(false), m_wantpop(false) 90 92 { 91 if (!m_state)92 {93 m_state = new MythThemedMenuState(parent, "themedmenustate");94 m_allocedstate = true;95 }96 93 97 94 Init(menufile); 95 96 if (!findAndParseMenu(menufile)) 97 m_foundtheme = false; // We don't have separate vars for theme & menu 98 98 } 99 99 100 100 101 /** \brief Loads the main UI theme, and a menu theme. 101 102 * 102 103 * See also foundtheme(void), it will return true when called after … … 106 107 */ 107 108 void MythThemedMenu::Init(const QString &menufile) 108 109 { 110 if (!m_state) 111 { 112 m_state = new MythThemedMenuState(m_parent, "themedmenustate"); 113 m_allocedstate = true; 114 } 115 109 116 ReloadExitKey(); 110 117 111 118 if (!m_state->m_loaded) … … 125 132 SLOT(setButtonActive(MythUIButtonListItem*))); 126 133 connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)), 127 134 SLOT(buttonAction(MythUIButtonListItem*))); 128 129 if (!parseMenu(menufile))130 m_foundtheme = false;131 135 } 132 136 133 137 MythThemedMenu::~MythThemedMenu(void) … … 136 140 delete m_state; 137 141 } 138 142 143 /** \brief Creates a dynamic themed menu. 144 * 145 * \param command external command to execute 146 * \param parent the screen stack that owns this UI type 147 * \param state theme state associated with this menu 148 */ 149 MythThemedMenu::MythThemedMenu(const QString &command, 150 MythScreenStack *parent, 151 MythThemedMenuState *state) 152 : MythThemedMenuState(parent, command), 153 m_parent(parent), m_state(state), 154 m_allocedstate(false), m_foundtheme(false), 155 m_exitModifier(-1), m_ignorekeys(false), m_wantpop(false) 156 { 157 if (command.isEmpty()) 158 { 159 VERBOSE(VB_IMPORTANT, "Empty MENUEXEC action?"); 160 161 m_foundtheme = false; 162 return; 163 } 164 165 Init(command); 166 167 QProcess process; 168 process.start(command); 169 if (!process.waitForFinished()) 170 { 171 process.kill(); 172 VERBOSE(VB_IMPORTANT, "Command '" + command + "' returned error"); 173 ShowOkPopup(QObject::tr("Couldn't execute %1").arg(command)); 174 175 m_foundtheme = false; 176 return; 177 } 178 179 QString errorMsg; 180 int errorLine = 0; 181 int errorColumn = 0; 182 183 QDomDocument doc; 184 if (!doc.setContent(process.readAllStandardOutput(), 185 false, &errorMsg, &errorLine, &errorColumn)) 186 { 187 VERBOSE(VB_IMPORTANT, "Error parsing output of: " + command + 188 QString("\nat line: %1 column: %2 msg: %3") 189 .arg(errorLine).arg(errorColumn).arg(errorMsg)); 190 191 ShowOkPopup(QObject::tr("Command %1 returned incomplete menu.") 192 .arg(command)); 193 194 m_foundtheme = false; 195 return; 196 } 197 198 if (!parseMenu(doc, command)) 199 m_foundtheme = false; // We don't have separate vars for theme & menu 200 } 139 201 /// \brief Returns true iff a theme has been found by a previous call to Init() 140 202 bool MythThemedMenu::foundTheme(void) 141 203 { … … 411 473 * non-essential portion of MythTV which the theme does not support. 412 474 * 413 475 */ 414 bool MythThemedMenu:: parseMenu(const QString &menuname)476 bool MythThemedMenu::findAndParseMenu(const QString &menuname) 415 477 { 416 478 QString filename = findMenuFile(menuname); 417 479 … … 450 512 451 513 VERBOSE(VB_GENERAL, QString("Loading menu theme from %1").arg(filename)); 452 514 515 return parseMenu(doc, menuname); 516 } 517 518 /** \brief Parse the themebuttons to be added based on the contents 519 * of the provided XML document. 520 */ 521 bool MythThemedMenu::parseMenu(const QDomDocument &doc, const QString &menuname) 522 { 453 523 QDomElement docElem = doc.documentElement(); 454 524 455 525 m_menumode = docElem.attribute("name", "MAIN"); … … 652 722 else 653 723 delete newmenu; 654 724 } 725 else if (action.left(9) == "MENUEXEC ") 726 { 727 QString command = action.mid(9); 728 729 MythScreenStack *stack = GetScreenStack(); 730 731 MythThemedMenu *newmenu = new MythThemedMenu(command, stack, m_state); 732 733 if (newmenu->foundTheme()) 734 stack->AddScreen(newmenu); 735 else 736 delete newmenu; 737 } 655 738 else if (action.left(6) == "UPMENU") 656 739 { 657 740 m_wantpop = true; -
libs/libmythui/myththemedmenu.h
9 9 class MythMainWindow; 10 10 class MythThemedMenuState; 11 11 12 class QDomDocument; 12 13 class QKeyEvent; 13 14 14 15 struct ThemedButton … … 66 67 public: 67 68 MythThemedMenu(const QString &cdir, const QString &menufile, 68 69 MythScreenStack *parent, const QString &name, 69 bool allowreorder = false, MythThemedMenuState *state = NULL); 70 bool allowreorder = false, 71 MythThemedMenuState *state = NULL); 70 72 ~MythThemedMenu(); 71 73 72 74 bool foundTheme(void); … … 89 91 private: 90 92 void Init(const QString &menufile); 91 93 92 bool parseMenu(const QString &menuname); 94 bool findAndParseMenu(const QString &menuname); 95 96 MythThemedMenu(const QString &command, 97 MythScreenStack *parent, MythThemedMenuState *state); 98 99 bool parseMenu(const QDomDocument &doc, const QString &menuname); 93 100 void parseThemeButton(QDomElement &element); 94 101 95 102 void addButton(const QString &type, const QString &text, … … 106 113 107 114 void updateLCD(void); 108 115 109 Myth ThemedMenu*m_parent;116 MythScreenStack *m_parent; 110 117 111 118 MythThemedMenuState *m_state; 112 119 bool m_allocedstate; -
contrib/menus/random-menu.pl
1 #!/usr/bin/perl 2 3 # random-menu.pl - Hacky test script for MENUEXEC action 4 # 5 # When attached to a button, like this: 6 # <button> 7 # <type>RANDOM</type> 8 # <text>Random Menu</text> 9 # <action>MENUEXEC /home/nigel/random-menu.pl</action> 10 # </button> 11 # 12 # it creates a sub-menu randomly chosen from the installed menus. 13 14 my $menudir = '/usr/local/share/mythtv/*menu.xml'; 15 my @menus = glob($menudir); 16 my $chosen = $menus[rand($#menus + 1)]; # 10 menus, $#menus=9, rand=0..9.9999 17 18 print `cat $chosen`;