Ticket #5954: dynamic_menus.patch
File dynamic_menus.patch, 3.8 KB (added by , 15 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" … … 410 409 */ 411 410 bool MythThemedMenu::parseMenu(const QString &menuname) 412 411 { 413 QString filename = findMenuFile(menuname);414 415 412 QDomDocument doc; 416 QFile f(filename);417 413 418 if ( !f.exists() || !f.open(QIODevice::ReadOnly))414 if (menuname.startsWith('`')) 419 415 { 420 VERBOSE(VB_IMPORTANT, QString("MythThemedMenu: Couldn't read " 421 "menu file %1").arg(menuname)); 416 QString command = menuname.mid(1); 417 418 QProcess process; 419 process.start(command); 420 if (!process.waitForFinished()) 421 { 422 process.kill(); 423 VERBOSE(VB_IMPORTANT, 424 QString("Command \"%1\" returned error\n").arg(command)); 425 ShowOkPopup(QObject::tr("Couldn't execute %1") 426 .arg(command)); 427 return false; 428 } 429 else 430 { 431 QString errorMsg; 432 int errorLine = 0; 433 int errorColumn = 0; 422 434 423 if (menuname != "mainmenu.xml") 424 ShowOkPopup(QObject::tr("Myth could not locate the menu file %1") 425 .arg(menuname)); 426 return false; 435 if (!doc.setContent(process.readAllStandardOutput(), false, 436 &errorMsg, &errorLine, &errorColumn)) 437 { 438 VERBOSE(VB_IMPORTANT, 439 QString("Error parsing output of: %1\nat line: %2 column: %3 msg: %4"). 440 arg(command).arg(errorLine).arg(errorColumn).arg(errorMsg)); 441 442 ShowOkPopup(QObject::tr("Command %1 returned incomplete menu.") 443 .arg(command)); 444 return false; 445 } 446 } 427 447 } 448 else 449 { 450 QString filename = findMenuFile(menuname); 428 451 429 QString errorMsg; 430 int errorLine = 0; 431 int errorColumn = 0; 452 QFile f(filename); 432 453 433 if (!doc.setContent(&f, false, &errorMsg, &errorLine, &errorColumn)) 434 { 435 VERBOSE(VB_IMPORTANT, 436 QString("Error parsing: %1\nat line: %2 column: %3 msg: %4"). 437 arg(filename).arg(errorLine).arg(errorColumn).arg(errorMsg)); 454 if (!f.exists() || !f.open(QIODevice::ReadOnly)) 455 { 456 VERBOSE(VB_IMPORTANT, QString("MythThemedMenu: Couldn't read " 457 "menu file %1").arg(menuname)); 458 459 if (menuname != "mainmenu.xml") 460 ShowOkPopup(QObject::tr("Myth could not locate the menu file %1") 461 .arg(menuname)); 462 return false; 463 } 464 465 QString errorMsg; 466 int errorLine = 0; 467 int errorColumn = 0; 468 469 if (!doc.setContent(&f, false, &errorMsg, &errorLine, &errorColumn)) 470 { 471 VERBOSE(VB_IMPORTANT, 472 QString("Error parsing: %1\nat line: %2 column: %3 msg: %4"). 473 arg(filename).arg(errorLine).arg(errorColumn).arg(errorMsg)); 474 f.close(); 475 476 if (menuname != "mainmenu.xml") 477 ShowOkPopup(QObject::tr("The menu file %1 is incomplete.") 478 .arg(menuname)); 479 return false; 480 } 481 438 482 f.close(); 439 440 if (menuname != "mainmenu.xml")441 ShowOkPopup(QObject::tr("The menu file %1 is incomplete.")442 .arg(menuname));443 return false;444 483 } 445 484 446 f.close();447 448 485 QDomElement docElem = doc.documentElement(); 449 486 450 487 m_menumode = docElem.attribute("name", "MAIN");