| 94 | Init(parent, state); |
| 95 | |
| 96 | if (!parseMenu(menufile)) |
| 97 | m_foundtheme = false; |
| 98 | } |
| 99 | |
| 100 | /** \brief Creates a dynamic themed menu. |
| 101 | * |
| 102 | * \param command external command to execute |
| 103 | * \param parent the screen stack that owns this UI type |
| 104 | * \param state theme state associated with this menu |
| 105 | */ |
| 106 | MythThemedMenu::MythThemedMenu(const QString command, MythScreenStack *parent, |
| 107 | MythThemedMenuState *state) |
| 108 | : MythThemedMenuState(parent, command) |
| 109 | { |
| 110 | Init(parent, state); |
| 111 | |
| 112 | QProcess process; |
| 113 | process.start(command); |
| 114 | if (!process.waitForFinished()) |
| 115 | { |
| 116 | process.kill(); |
| 117 | VERBOSE(VB_IMPORTANT, |
| 118 | QString("Command \"%1\" returned error\n").arg(command)); |
| 119 | ShowOkPopup(QObject::tr("Couldn't execute %1") |
| 120 | .arg(command)); |
| 121 | |
| 122 | m_foundtheme = false; |
| 123 | return; |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | QString errorMsg; |
| 128 | int errorLine = 0; |
| 129 | int errorColumn = 0; |
| 130 | |
| 131 | QDomDocument doc; |
| 132 | if (!doc.setContent(process.readAllStandardOutput(), false, |
| 133 | &errorMsg, &errorLine, &errorColumn)) |
| 134 | { |
| 135 | VERBOSE(VB_IMPORTANT, |
| 136 | QString("Error parsing output of: %1\nat line: %2 column: %3 msg: %4"). |
| 137 | arg(command).arg(errorLine).arg(errorColumn).arg(errorMsg)); |
| 138 | |
| 139 | ShowOkPopup(QObject::tr("Command %1 returned incomplete menu.") |
| 140 | .arg(command)); |
| 141 | |
| 142 | m_foundtheme = false; |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | if (!parseMenu(doc, command)) |
| 147 | m_foundtheme = false; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /** \brief Initializes the menu state. |
| 152 | * |
| 153 | * \param parent the screen stack that owns this UI type |
| 154 | * \param state theme state associated with this menu |
| 155 | */ |
| 156 | void MythThemedMenu::Init(MythScreenStack *parent, MythThemedMenuState *state) |
| 157 | { |
| 446 | /** \brief Parse the themebuttons to be added based on the contents |
| 447 | * of the provided XML document. |
| 448 | */ |
| 449 | bool MythThemedMenu::parseMenu(const QDomDocument &doc, const QString &menuname) |
| 450 | { |
| 451 | QDomElement docElem = doc.documentElement(); |
| 452 | |
| 453 | m_menumode = docElem.attribute("name", "MAIN"); |
| 454 | |
| 455 | QDomNode n = docElem.firstChild(); |
| 456 | while (!n.isNull()) |
| 457 | { |
| 458 | QDomElement e = n.toElement(); |
| 459 | if (!e.isNull()) |
| 460 | { |
| 461 | if (e.tagName() == "button") |
| 462 | { |
| 463 | parseThemeButton(e); |
| 464 | } |
| 465 | else |
| 466 | { |
| 467 | VERBOSE(VB_IMPORTANT, QString("MythThemedMenu: Unknown " |
| 468 | "element %1").arg(e.tagName())); |
| 469 | return false; |
| 470 | } |
| 471 | } |
| 472 | n = n.nextSibling(); |
| 473 | } |
| 474 | |
| 475 | if (m_buttonList->GetCount() == 0) |
| 476 | { |
| 477 | VERBOSE(VB_IMPORTANT, QString("MythThemedMenu: No buttons " |
| 478 | "for menu %1").arg(menuname)); |
| 479 | return false; |
| 480 | } |
| 481 | |
| 482 | if (LCD::Get()) |
| 483 | { |
| 484 | m_titleText = "MYTH-"; |
| 485 | m_titleText += m_menumode; |
| 486 | } |
| 487 | |
| 488 | if (m_titleState) |
| 489 | m_titleState->DisplayState(m_menumode); |
| 490 | |
| 491 | m_selection = ""; |
| 492 | return true; |
| 493 | } |
| 494 | |
448 | | QDomElement docElem = doc.documentElement(); |
449 | | |
450 | | m_menumode = docElem.attribute("name", "MAIN"); |
451 | | |
452 | | QDomNode n = docElem.firstChild(); |
453 | | while (!n.isNull()) |
454 | | { |
455 | | QDomElement e = n.toElement(); |
456 | | if (!e.isNull()) |
457 | | { |
458 | | if (e.tagName() == "button") |
459 | | { |
460 | | parseThemeButton(e); |
461 | | } |
462 | | else |
463 | | { |
464 | | VERBOSE(VB_IMPORTANT, QString("MythThemedMenu: Unknown " |
465 | | "element %1").arg(e.tagName())); |
466 | | return false; |
467 | | } |
468 | | } |
469 | | n = n.nextSibling(); |
470 | | } |
471 | | |
472 | | if (m_buttonList->GetCount() == 0) |
473 | | { |
474 | | VERBOSE(VB_IMPORTANT, QString("MythThemedMenu: No buttons " |
475 | | "for menu %1").arg(menuname)); |
476 | | return false; |
477 | | } |
478 | | |
479 | | if (LCD::Get()) |
480 | | { |
481 | | m_titleText = "MYTH-"; |
482 | | m_titleText += m_menumode; |
483 | | } |
484 | | |
485 | | if (m_titleState) |
486 | | m_titleState->DisplayState(m_menumode); |
487 | | |
488 | | m_selection = ""; |
489 | | return true; |
| 546 | return parseMenu(doc, menuname); |