|
MythTV
0.26-pre
|
00001 00002 #include "myththemedmenu.h" 00003 00004 // QT headers 00005 #include <QCoreApplication> 00006 #include <QDir> 00007 #include <QKeyEvent> 00008 #include <QDomDocument> 00009 #include <QFile> 00010 #include <QTextStream> 00011 00012 // libmythui headers 00013 #include "mythmainwindow.h" 00014 #include "mythdialogbox.h" 00015 #include "mythgesture.h" 00016 #include "mythuitext.h" 00017 #include "mythuistatetype.h" 00018 #include "xmlparsebase.h" 00019 #include "mythsystem.h" 00020 #include "mythuihelper.h" 00021 #include "lcddevice.h" 00022 #include "mythcorecontext.h" 00023 00024 // libmythbase headers 00025 #include "mythlogging.h" 00026 #include "mythdb.h" 00027 #include "mythdirs.h" 00028 #include "mythmedia.h" 00029 #include "mythversion.h" 00030 00031 MythThemedMenuState::MythThemedMenuState(MythScreenStack *parent, 00032 const QString &name) 00033 : MythScreenType(parent, name), 00034 m_callback(NULL), m_callbackdata(NULL), 00035 m_killable(false), m_loaded(false), m_titleState(NULL), 00036 m_watermarkState(NULL), m_buttonList(NULL), m_descriptionText(NULL) 00037 { 00038 } 00039 00040 MythThemedMenuState::~MythThemedMenuState() 00041 { 00042 } 00043 00044 bool MythThemedMenuState::Create(void) 00045 { 00046 if (!LoadWindowFromXML("menu-ui.xml", "mainmenu", this)) 00047 return false; 00048 00049 m_titleState = dynamic_cast<MythUIStateType *> (GetChild("titles")); 00050 m_watermarkState = dynamic_cast<MythUIStateType *> (GetChild("watermarks")); 00051 m_buttonList = dynamic_cast<MythUIButtonList *> (GetChild("menu")); 00052 m_descriptionText = dynamic_cast<MythUIText *> (GetChild("description")); 00053 00054 if (!m_buttonList) 00055 { 00056 LOG(VB_GENERAL, LOG_ERR, "Missing 'menu' buttonlist."); 00057 return false; 00058 } 00059 00060 m_loaded = true; 00061 00062 return true; 00063 } 00064 00065 void MythThemedMenuState::CopyFrom(MythUIType *base) 00066 { 00067 MythThemedMenuState *st = dynamic_cast<MythThemedMenuState *>(base); 00068 if (!st) 00069 { 00070 LOG(VB_GENERAL, LOG_INFO, "ERROR, bad parsing"); 00071 return; 00072 } 00073 00074 m_loaded = st->m_loaded; 00075 00076 MythScreenType::CopyFrom(base); 00077 00078 m_titleState = dynamic_cast<MythUIStateType *> (GetChild("titles")); 00079 m_watermarkState = dynamic_cast<MythUIStateType *> (GetChild("watermarks")); 00080 m_buttonList = dynamic_cast<MythUIButtonList *> (GetChild("menu")); 00081 m_descriptionText = dynamic_cast<MythUIText *> (GetChild("description")); 00082 } 00083 00085 00093 MythThemedMenu::MythThemedMenu(const QString &cdir, const QString &menufile, 00094 MythScreenStack *parent, const QString &name, 00095 bool allowreorder, MythThemedMenuState *state) 00096 : MythThemedMenuState(parent, name), 00097 m_state(state), m_allocedstate(false), m_foundtheme(false), 00098 m_ignorekeys(false), m_wantpop(false) 00099 { 00100 m_menuPopup = NULL; 00101 00102 if (!m_state) 00103 { 00104 m_state = new MythThemedMenuState(parent, "themedmenustate"); 00105 m_allocedstate = true; 00106 } 00107 00108 Init(menufile); 00109 } 00110 00118 void MythThemedMenu::Init(const QString &menufile) 00119 { 00120 if (!m_state->m_loaded) 00121 { 00122 if (m_state->Create()) 00123 m_foundtheme = true; 00124 } 00125 else 00126 m_foundtheme = true; 00127 00128 if (!m_foundtheme) 00129 return; 00130 00131 CopyFrom(m_state); 00132 00133 connect(m_buttonList, SIGNAL(itemSelected(MythUIButtonListItem*)), 00134 SLOT(setButtonActive(MythUIButtonListItem*))); 00135 connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)), 00136 SLOT(buttonAction(MythUIButtonListItem*))); 00137 00138 if (!parseMenu(menufile)) 00139 m_foundtheme = false; 00140 } 00141 00142 MythThemedMenu::~MythThemedMenu(void) 00143 { 00144 if (m_allocedstate) 00145 delete m_state; 00146 } 00147 00149 bool MythThemedMenu::foundTheme(void) 00150 { 00151 return m_foundtheme; 00152 } 00153 00155 void MythThemedMenu::setCallback(void (*lcallback)(void *, QString &), 00156 void *data) 00157 { 00158 m_state->m_callback = lcallback; 00159 m_state->m_callbackdata = data; 00160 } 00161 00162 void MythThemedMenu::setKillable(void) 00163 { 00164 m_state->m_killable = true; 00165 } 00166 00167 QString MythThemedMenu::getSelection(void) 00168 { 00169 return m_selection; 00170 } 00171 00172 void MythThemedMenu::setButtonActive(MythUIButtonListItem* item) 00173 { 00174 ThemedButton button = item->GetData().value<ThemedButton>(); 00175 if (m_watermarkState) 00176 { 00177 if (!(m_watermarkState->DisplayState(button.type))) 00178 m_watermarkState->Reset(); 00179 } 00180 00181 if (m_descriptionText) 00182 m_descriptionText->SetText(button.description); 00183 } 00184 00190 bool MythThemedMenu::keyPressEvent(QKeyEvent *event) 00191 { 00192 if (m_ignorekeys) 00193 return false; 00194 00195 m_ignorekeys = true; 00196 00197 MythUIType *type = GetFocusWidget(); 00198 if (type && type->keyPressEvent(event)) 00199 { 00200 m_ignorekeys = false; 00201 return true; 00202 } 00203 00204 QStringList actions; 00205 bool handled = false; 00206 00207 handled = GetMythMainWindow()->TranslateKeyPress("Main Menu", event, 00208 actions); 00209 00210 for (int i = 0; i < actions.size() && !handled; i++) 00211 { 00212 QString action = actions[i]; 00213 handled = true; 00214 00215 if (action == "ESCAPE" || action == "EXIT" || action == "EXITPROMPT") 00216 { 00217 bool callbacks = m_state->m_callback; 00218 bool lastScreen = (GetMythMainWindow()->GetMainStack() 00219 ->TotalScreens() == 1); 00220 QString menuaction = "UPMENU"; 00221 QString selExit = "EXITING_APP_PROMPT"; 00222 if (action == "EXIT") 00223 selExit = "EXITING_APP"; 00224 00225 if (!m_allocedstate) 00226 handleAction(menuaction); 00227 else if (m_state->m_killable) 00228 { 00229 m_wantpop = true; 00230 if (callbacks) 00231 { 00232 QString sel = "EXITING_MENU"; 00233 m_state->m_callback(m_state->m_callbackdata, sel); 00234 } 00235 00236 if (lastScreen) 00237 { 00238 if (callbacks) 00239 m_state->m_callback(m_state->m_callbackdata, selExit); 00240 QCoreApplication::exit(); 00241 } 00242 } 00243 else if ((action == "EXIT" || action == "EXITPROMPT" || 00244 (action == "ESCAPE" && 00245 (QCoreApplication::applicationName() == 00246 MYTH_APPNAME_MYTHTV_SETUP))) && lastScreen) 00247 { 00248 if (callbacks) 00249 m_state->m_callback(m_state->m_callbackdata, selExit); 00250 else 00251 { 00252 QCoreApplication::exit(); 00253 m_wantpop = true; 00254 } 00255 } 00256 } 00257 else if (action == "HELP") 00258 { 00259 aboutScreen(); 00260 } 00261 else if (action == "EJECT") 00262 { 00263 handleAction(action); 00264 } 00265 else 00266 handled = false; 00267 } 00268 00269 if (!handled && MythScreenType::keyPressEvent(event)) 00270 handled = true; 00271 00272 m_ignorekeys = false; 00273 00274 if (m_wantpop) 00275 m_ScreenStack->PopScreen(); 00276 00277 return handled; 00278 } 00279 00280 void MythThemedMenu::aboutToShow() 00281 { 00282 MythScreenType::aboutToShow(); 00283 m_buttonList->updateLCD(); 00284 } 00285 00286 void MythThemedMenu::ShowMenu() 00287 { 00288 if (m_menuPopup) 00289 return; 00290 00291 int override_menu = GetMythDB()->GetNumSetting("OverrideExitMenu"); 00292 QString label = tr("System Menu"); 00293 MythScreenStack* mainStack = GetMythMainWindow()->GetMainStack(); 00294 m_menuPopup = new MythDialogBox(label, mainStack, "menuPopup"); 00295 00296 if (m_menuPopup->Create()) 00297 mainStack->AddScreen(m_menuPopup); 00298 00299 m_menuPopup->SetReturnEvent(this, "popmenu"); 00300 00301 // HACK Implement a better check for this 00302 if (QCoreApplication::applicationName() == MYTH_APPNAME_MYTHFRONTEND) 00303 m_menuPopup->AddButton(tr("Enter standby mode"), QVariant("standby")); 00304 switch (override_menu) 00305 { 00306 case 2: 00307 case 4: 00308 // shutdown 00309 m_menuPopup->AddButton(tr("Shutdown"), QVariant("shutdown")); 00310 break; 00311 case 5: 00312 // reboot 00313 m_menuPopup->AddButton(tr("Reboot"), QVariant("reboot")); 00314 break; 00315 case 3: 00316 case 6: 00317 // both 00318 m_menuPopup->AddButton(tr("Shutdown"), QVariant("shutdown")); 00319 m_menuPopup->AddButton(tr("Reboot"), QVariant("reboot")); 00320 break; 00321 case 0: 00322 default: 00323 break; 00324 } 00325 00326 m_menuPopup->AddButton(tr("About"), QVariant("about")); 00327 } 00328 00329 void MythThemedMenu::aboutScreen() 00330 { 00331 QString distro_line; 00332 00333 QFile file("/etc/os_myth_release"); 00334 if (file.open(QFile::ReadOnly)) 00335 { 00336 QTextStream t( &file ); // use a text stream 00337 distro_line = t.readLine(); 00338 file.close(); 00339 } 00340 00341 QString label = tr("Revision: %1\n Branch: %2\n %3") 00342 .arg(MYTH_SOURCE_VERSION) 00343 .arg(MYTH_SOURCE_PATH) 00344 .arg(distro_line); 00345 00346 MythScreenStack* mainStack = GetMythMainWindow()->GetMainStack(); 00347 m_menuPopup = new MythDialogBox(label, mainStack, "version_dialog"); 00348 if (m_menuPopup->Create()) 00349 mainStack->AddScreen(m_menuPopup); 00350 00351 m_menuPopup->SetReturnEvent(this, "version"); 00352 m_menuPopup->AddButton(tr("Ok")); 00353 00354 } 00355 00356 void MythThemedMenu::customEvent(QEvent *event) 00357 { 00358 if (event->type() == DialogCompletionEvent::kEventType) 00359 { 00360 DialogCompletionEvent *dce = (DialogCompletionEvent*)(event); 00361 00362 QString resultid = dce->GetId(); 00363 //int buttonnum = dce->GetResult(); 00364 QString halt_cmd = GetMythDB()->GetSetting("HaltCommand"); 00365 QString reboot_cmd = GetMythDB()->GetSetting("RebootCommand"); 00366 00367 if (resultid == "popmenu") 00368 { 00369 QString action = dce->GetData().toString(); 00370 if (action == "shutdown") 00371 { 00372 if (!halt_cmd.isEmpty()) 00373 myth_system(halt_cmd); 00374 } 00375 else if (action == "reboot") 00376 { 00377 if (!reboot_cmd.isEmpty()) 00378 myth_system(reboot_cmd); 00379 } 00380 else if (action == "about") 00381 { 00382 aboutScreen(); 00383 } 00384 else if (action == "standby") 00385 { 00386 QString arg("standby_mode"); 00387 m_state->m_callback(m_state->m_callbackdata, arg); 00388 } 00389 } 00390 else if (resultid == "password") 00391 { 00392 QString text = dce->GetResultText(); 00393 MythUIButtonListItem *item = m_buttonList->GetItemCurrent(); 00394 ThemedButton button = item->GetData().value<ThemedButton>(); 00395 QString password = GetMythDB()->GetSetting(button.password); 00396 if (text == password) 00397 { 00398 QString timestamp_setting = QString("%1Time").arg(button.password); 00399 QDateTime curr_time = QDateTime::currentDateTime(); 00400 QString last_time_stamp = curr_time.toString(Qt::TextDate); 00401 GetMythDB()->SaveSetting(timestamp_setting, last_time_stamp); 00402 buttonAction(item, true); 00403 } 00404 } 00405 00406 m_menuPopup = NULL; 00407 } 00408 } 00409 00415 void MythThemedMenu::parseThemeButton(QDomElement &element) 00416 { 00417 QString type; 00418 QString text; 00419 QStringList action; 00420 QString alttext; 00421 QString description; 00422 QString password; 00423 00424 bool addit = true; 00425 00426 for (QDomNode child = element.firstChild(); !child.isNull(); 00427 child = child.nextSibling()) 00428 { 00429 QDomElement info = child.toElement(); 00430 if (!info.isNull()) 00431 { 00432 if (info.tagName() == "type") 00433 { 00434 type = getFirstText(info); 00435 } 00436 else if (info.tagName() == "text") 00437 { 00438 if (text.isEmpty() && 00439 info.attribute("lang","").isEmpty()) 00440 { 00441 text = qApp->translate("ThemeUI", 00442 parseText(info).toUtf8(), NULL, 00443 QCoreApplication::UnicodeUTF8); 00444 } 00445 else if (info.attribute("lang","").toLower() == 00446 gCoreContext->GetLanguageAndVariant()) 00447 { 00448 text = parseText(info); 00449 } 00450 else if (info.attribute("lang","").toLower() == 00451 gCoreContext->GetLanguage()) 00452 { 00453 text = parseText(info); 00454 } 00455 } 00456 else if (info.tagName() == "alttext") 00457 { 00458 if (alttext.isEmpty() && 00459 info.attribute("lang","").isEmpty()) 00460 { 00461 alttext = qApp->translate("ThemeUI", 00462 parseText(info).toUtf8(), NULL, 00463 QCoreApplication::UnicodeUTF8); 00464 } 00465 else if (info.attribute("lang","").toLower() == 00466 gCoreContext->GetLanguageAndVariant()) 00467 { 00468 alttext = parseText(info); 00469 } 00470 else if (info.attribute("lang","").toLower() == 00471 gCoreContext->GetLanguage()) 00472 { 00473 alttext = parseText(info); 00474 } 00475 } 00476 else if (info.tagName() == "action") 00477 { 00478 action += getFirstText(info); 00479 } 00480 else if (info.tagName() == "depends") 00481 { 00482 addit = findDepends(getFirstText(info)); 00483 } 00484 else if (info.tagName() == "dependssetting") 00485 { 00486 addit = GetMythDB()->GetNumSetting(getFirstText(info)); 00487 } 00488 else if (info.tagName() == "dependjumppoint") 00489 { 00490 addit = GetMythMainWindow()->DestinationExists( 00491 getFirstText(info)); 00492 } 00493 else if (info.tagName() == "dependswindow") 00494 { 00495 QString xmlFile = info.attribute("xmlfile", ""); 00496 QString windowName = getFirstText(info); 00497 if (xmlFile.isEmpty() || windowName.isEmpty()) 00498 addit = false; 00499 else 00500 addit = XMLParseBase::WindowExists(xmlFile, windowName); 00501 } 00502 else if (info.tagName() == "description") 00503 { 00504 if (description.isEmpty() && 00505 info.attribute("lang","").isEmpty()) 00506 { 00507 description = qApp->translate("ThemeUI", 00508 getFirstText(info).toUtf8(), 00509 NULL, 00510 QCoreApplication::UnicodeUTF8); 00511 } 00512 else if (info.attribute("lang","").toLower() == 00513 gCoreContext->GetLanguageAndVariant()) 00514 { 00515 description = getFirstText(info); 00516 } 00517 else if (info.attribute("lang","").toLower() == 00518 gCoreContext->GetLanguage()) 00519 { 00520 description = getFirstText(info); 00521 } 00522 } 00523 else if (info.tagName() == "password") 00524 { 00525 password = getFirstText(info); 00526 } 00527 else 00528 { 00529 LOG(VB_GENERAL, LOG_ERR, 00530 QString("MythThemedMenu: Unknown tag %1 in button") 00531 .arg(info.tagName())); 00532 } 00533 } 00534 } 00535 00536 if (text.isEmpty()) 00537 { 00538 LOG(VB_GENERAL, LOG_ERR, "MythThemedMenu: Missing 'text' in button"); 00539 return; 00540 } 00541 00542 if (action.empty()) 00543 { 00544 LOG(VB_GENERAL, LOG_ERR, "MythThemedMenu: Missing 'action' in button"); 00545 return; 00546 } 00547 00548 if (addit) 00549 addButton(type, text, alttext, action, description, password); 00550 } 00551 00565 bool MythThemedMenu::parseMenu(const QString &menuname) 00566 { 00567 QString filename = findMenuFile(menuname); 00568 00569 QDomDocument doc; 00570 QFile f(filename); 00571 00572 if (!f.exists() || !f.open(QIODevice::ReadOnly)) 00573 { 00574 LOG(VB_GENERAL, LOG_ERR, QString("MythThemedMenu: Couldn't read " 00575 "menu file %1").arg(menuname)); 00576 00577 if (menuname != "mainmenu.xml") 00578 ShowOkPopup(QObject::tr("MythTV could not locate the menu file %1") 00579 .arg(menuname)); 00580 return false; 00581 } 00582 00583 QString errorMsg; 00584 int errorLine = 0; 00585 int errorColumn = 0; 00586 00587 if (!doc.setContent(&f, false, &errorMsg, &errorLine, &errorColumn)) 00588 { 00589 LOG(VB_GENERAL, LOG_ERR, 00590 QString("Error parsing: %1\nat line: %2 column: %3 msg: %4"). 00591 arg(filename).arg(errorLine).arg(errorColumn).arg(errorMsg)); 00592 f.close(); 00593 00594 if (menuname != "mainmenu.xml") 00595 ShowOkPopup(QObject::tr("The menu file %1 is incomplete.") 00596 .arg(menuname)); 00597 return false; 00598 } 00599 00600 f.close(); 00601 00602 LOG(VB_GUI, LOG_INFO, QString("Loading menu theme from %1").arg(filename)); 00603 00604 QDomElement docElem = doc.documentElement(); 00605 00606 m_menumode = docElem.attribute("name", "MAIN"); 00607 00608 QDomNode n = docElem.firstChild(); 00609 while (!n.isNull()) 00610 { 00611 QDomElement e = n.toElement(); 00612 if (!e.isNull()) 00613 { 00614 if (e.tagName() == "button") 00615 { 00616 parseThemeButton(e); 00617 } 00618 else 00619 { 00620 LOG(VB_GENERAL, LOG_ERR, 00621 QString("MythThemedMenu: Unknown element %1") 00622 .arg(e.tagName())); 00623 return false; 00624 } 00625 } 00626 n = n.nextSibling(); 00627 } 00628 00629 if (m_buttonList->GetCount() == 0) 00630 { 00631 LOG(VB_GENERAL, LOG_ERR, 00632 QString("MythThemedMenu: No buttons for menu %1").arg(menuname)); 00633 return false; 00634 } 00635 00636 m_buttonList->SetLCDTitles("MYTH-" + m_menumode); 00637 00638 if (m_titleState) 00639 { 00640 m_titleState->EnsureStateLoaded(m_menumode); 00641 m_titleState->DisplayState(m_menumode); 00642 } 00643 00644 m_selection.clear(); 00645 return true; 00646 } 00647 00657 void MythThemedMenu::addButton(const QString &type, const QString &text, 00658 const QString &alttext, 00659 const QStringList &action, 00660 const QString &description, 00661 const QString &password) 00662 { 00663 ThemedButton newbutton; 00664 newbutton.type = type; 00665 newbutton.action = action; 00666 newbutton.text = text; 00667 newbutton.description = description; 00668 newbutton.password = password; 00669 00670 if (m_watermarkState) 00671 m_watermarkState->EnsureStateLoaded(type); 00672 00673 MythUIButtonListItem *listbuttonitem = 00674 new MythUIButtonListItem(m_buttonList, text, 00675 qVariantFromValue(newbutton)); 00676 00677 listbuttonitem->DisplayState(type, "icon"); 00678 listbuttonitem->SetText(description, "description"); 00679 } 00680 00681 void MythThemedMenu::buttonAction(MythUIButtonListItem *item, bool skipPass) 00682 { 00683 ThemedButton button = item->GetData().value<ThemedButton>(); 00684 00685 QString password; 00686 if (!skipPass) 00687 password = button.password; 00688 00689 QStringList::Iterator it = button.action.begin(); 00690 for (; it != button.action.end(); it++) 00691 { 00692 if (handleAction(*it, password)) 00693 break; 00694 } 00695 } 00696 00702 QString MythThemedMenu::findMenuFile(const QString &menuname) 00703 { 00704 QString testdir = GetConfDir() + '/' + menuname; 00705 QFile file(testdir); 00706 if (file.exists()) 00707 return testdir; 00708 else 00709 LOG(VB_FILE, LOG_DEBUG, "No menu file " + testdir); 00710 00711 testdir = GetMythUI()->GetMenuThemeDir() + '/' + menuname; 00712 file.setFileName(testdir); 00713 if (file.exists()) 00714 return testdir; 00715 else 00716 LOG(VB_FILE, LOG_DEBUG, "No menu file " + testdir); 00717 00718 testdir = GetMythUI()->GetThemeDir() + '/' + menuname; 00719 file.setFileName(testdir); 00720 if (file.exists()) 00721 return testdir; 00722 else 00723 LOG(VB_FILE, LOG_DEBUG, "No menu file " + testdir); 00724 00725 testdir = GetShareDir() + menuname; 00726 file.setFileName(testdir); 00727 if (file.exists()) 00728 return testdir; 00729 else 00730 LOG(VB_FILE, LOG_DEBUG, "No menu file " + testdir); 00731 00732 testdir = "../mythfrontend/" + menuname; 00733 file.setFileName(testdir); 00734 if (file.exists()) 00735 return testdir; 00736 else 00737 LOG(VB_FILE, LOG_DEBUG, "No menu file " + testdir); 00738 00739 testdir = GetShareDir() + "themes/defaultmenu/" + menuname; 00740 file.setFileName(testdir); 00741 if (file.exists()) 00742 return testdir; 00743 else 00744 LOG(VB_FILE, LOG_DEBUG, "No menu file " + testdir); 00745 00746 return QString(); 00747 } 00748 00754 bool MythThemedMenu::handleAction(const QString &action, const QString &password) 00755 { 00756 MythUIMenuCallbacks *cbs = GetMythUI()->GetMenuCBs(); 00757 00758 if (((password == "SetupPinCode") && 00759 GetMythDB()->GetNumSetting("SetupPinCodeRequired", 0)) || 00760 (!password.isEmpty() && password != "SetupPinCode")) 00761 { 00762 if (!checkPinCode(password)) 00763 return true; 00764 } 00765 00766 if (action.left(5) == "EXEC ") 00767 { 00768 QString rest = action.right(action.length() - 5); 00769 if (cbs && cbs->exec_program) 00770 cbs->exec_program(rest); 00771 00772 return false; 00773 } 00774 else if (action.left(7) == "EXECTV ") 00775 { 00776 QString rest = action.right(action.length() - 7).trimmed(); 00777 if (cbs && cbs->exec_program_tv) 00778 cbs->exec_program_tv(rest); 00779 } 00780 else if (action.left(5) == "MENU ") 00781 { 00782 QString menu = action.right(action.length() - 5); 00783 00784 MythScreenStack *stack = GetScreenStack(); 00785 00786 MythThemedMenu *newmenu = new MythThemedMenu("", menu, stack, menu, 00787 false, m_state); 00788 if (newmenu->foundTheme()) 00789 stack->AddScreen(newmenu); 00790 else 00791 delete newmenu; 00792 } 00793 else if (action.left(6) == "UPMENU") 00794 { 00795 m_wantpop = true; 00796 } 00797 else if (action.left(12) == "CONFIGPLUGIN") 00798 { 00799 QString rest = action.right(action.length() - 13); 00800 if (cbs && cbs->configplugin) 00801 cbs->configplugin(rest); 00802 } 00803 else if (action.left(6) == "PLUGIN") 00804 { 00805 QString rest = action.right(action.length() - 7); 00806 if (cbs && cbs->plugin) 00807 cbs->plugin(rest); 00808 } 00809 else if (action.left(8) == "SHUTDOWN") 00810 { 00811 if (m_allocedstate) 00812 { 00813 m_wantpop = true; 00814 } 00815 } 00816 else if (action.left(5) == "EJECT") 00817 { 00818 if (cbs && cbs->eject) 00819 cbs->eject(); 00820 } 00821 else if (action.left(5) == "JUMP ") 00822 { 00823 QString rest = action.right(action.length() - 5); 00824 GetMythMainWindow()->JumpTo(rest, false); 00825 } 00826 else if (action.left(6) == "MEDIA ") 00827 { 00828 // the format is MEDIA HANDLER URL 00829 // TODO: allow spaces in the url 00830 QStringList list = action.simplified().split(' '); 00831 if (list.size() >= 3) 00832 GetMythMainWindow()->HandleMedia(list[1], list[2]); 00833 } 00834 else 00835 { 00836 m_selection = action; 00837 if (m_state->m_callback) 00838 m_state->m_callback(m_state->m_callbackdata, m_selection); 00839 else 00840 LOG(VB_GENERAL, LOG_ERR, "Unknown menu action: " + action); 00841 } 00842 00843 return true; 00844 } 00845 00846 bool MythThemedMenu::findDepends(const QString &fileList) 00847 { 00848 QStringList files = fileList.split(" "); 00849 QString filename; 00850 00851 for (QStringList::Iterator it = files.begin(); it != files.end(); ++it ) 00852 { 00853 QString filename = findMenuFile(*it); 00854 if (!filename.isEmpty() && filename.endsWith(".xml")) 00855 return true; 00856 00857 QString newname = FindPluginName(*it); 00858 00859 QFile checkFile(newname); 00860 if (checkFile.exists()) 00861 return true; 00862 } 00863 00864 return false; 00865 } 00866 00875 bool MythThemedMenu::checkPinCode(const QString &password_setting) 00876 { 00877 QString timestamp_setting = QString("%1Time").arg(password_setting); 00878 QDateTime curr_time = QDateTime::currentDateTime(); 00879 QString last_time_stamp = GetMythDB()->GetSetting(timestamp_setting); 00880 QString password = GetMythDB()->GetSetting(password_setting); 00881 00882 // Password empty? Then skip asking for it 00883 if (password.isEmpty()) 00884 return true; 00885 00886 if (last_time_stamp.length() < 1) 00887 { 00888 LOG(VB_GENERAL, LOG_ERR, 00889 "MythThemedMenu: Could not read password/pin time stamp.\n" 00890 "This is only an issue if it happens repeatedly."); 00891 } 00892 else 00893 { 00894 QDateTime last_time = QDateTime::fromString(last_time_stamp, 00895 Qt::TextDate); 00896 if (last_time.secsTo(curr_time) < 120) 00897 { 00898 last_time_stamp = curr_time.toString(Qt::TextDate); 00899 GetMythDB()->SaveSetting(timestamp_setting, last_time_stamp); 00900 return true; 00901 } 00902 } 00903 00904 LOG(VB_GENERAL, LOG_INFO, QString("Using Password: %1") 00905 .arg(password_setting)); 00906 00907 QString text = tr("Enter password:"); 00908 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack"); 00909 MythTextInputDialog *dialog = 00910 new MythTextInputDialog(popupStack, text, FilterNone, true); 00911 00912 if (dialog->Create()) 00913 { 00914 dialog->SetReturnEvent(this, "password"); 00915 popupStack->AddScreen(dialog); 00916 } 00917 else 00918 delete dialog; 00919 00920 return false; 00921 } 00922 00926 void MythThemedMenu::mediaEvent(MythMediaEvent* event) 00927 { 00928 if (!event) 00929 return; 00930 00931 MythMediaDevice *device = event->getDevice(); 00932 00933 if (!device) 00934 return; 00935 00936 MythMediaType type = device->getMediaType(); 00937 MythMediaStatus status = device->getStatus(); 00938 00939 if ((status & ~MEDIASTAT_USEABLE) && 00940 (status & ~MEDIASTAT_MOUNTED)) 00941 return; 00942 00943 switch (type) 00944 { 00945 case MEDIATYPE_DVD : 00946 // DVD Available 00947 break; 00948 case MEDIATYPE_BD : 00949 // Blu-ray Available 00950 break; 00951 default : 00952 return; 00953 } 00954 }
1.7.6.1