00001
00002 #include "mythdialogbox.h"
00003
00004 #include <QCoreApplication>
00005 #include <QFileInfo>
00006 #include <QString>
00007 #include <QStringList>
00008 #include <QTimer>
00009 #include <QDateTime>
00010 #include <QDate>
00011 #include <QTime>
00012
00013 #include "mythlogging.h"
00014 #include "mythmiscutil.h"
00015
00016 #include "mythmainwindow.h"
00017 #include "mythfontproperties.h"
00018 #include "mythuiutils.h"
00019 #include "mythuitext.h"
00020 #include "mythuiimage.h"
00021 #include "mythuibuttonlist.h"
00022 #include "mythuibutton.h"
00023 #include "mythuistatetype.h"
00024
00025 QEvent::Type DialogCompletionEvent::kEventType =
00026 (QEvent::Type) QEvent::registerEventType();
00027
00028
00029 MythMenu::MythMenu(const QString &text, QObject *retobject, const QString &resultid) :
00030 m_parentMenu(NULL), m_title(""), m_text(text), m_resultid(resultid), m_retObject(retobject)
00031 {
00032 Init();
00033 }
00034
00035 MythMenu::MythMenu(const QString &title, const QString &text, QObject *retobject, const QString &resultid) :
00036 m_parentMenu(NULL), m_title(title), m_text(text), m_resultid(resultid), m_retObject(retobject)
00037 {
00038 Init();
00039 }
00040
00041 MythMenu::~MythMenu(void)
00042 {
00043 while (!m_menuItems.isEmpty())
00044 {
00045 MythMenuItem *item = m_menuItems.takeFirst();
00046
00047 if (item->SubMenu)
00048 delete item->SubMenu;
00049
00050 delete item;
00051 }
00052 }
00053
00054 void MythMenu::Init()
00055 {
00056 m_title.detach();
00057 m_text.detach();
00058 m_resultid.detach();
00059 }
00060
00061 void MythMenu::AddItem(const QString& title, const char* slot, MythMenu *subMenu, bool selected, bool checked)
00062 {
00063 MythMenuItem *item = new MythMenuItem(title, slot, checked, subMenu);
00064
00065 m_menuItems.append(item);
00066
00067 if (selected)
00068 m_selectedItem = m_menuItems.indexOf(item);
00069
00070 if (subMenu)
00071 subMenu->SetParent(this);
00072 }
00073
00074 void MythMenu::AddItem(const QString &title, QVariant data, MythMenu *subMenu, bool selected, bool checked)
00075 {
00076 MythMenuItem *item = new MythMenuItem(title, data, checked, subMenu);
00077
00078 m_menuItems.append(item);
00079
00080 if (selected)
00081 m_selectedItem = m_menuItems.indexOf(item);
00082
00083 if (subMenu)
00084 subMenu->SetParent(this);
00085 }
00086
00088
00089 MythDialogBox::MythDialogBox(const QString &text,
00090 MythScreenStack *parent, const char *name,
00091 bool fullscreen, bool osd)
00092 : MythScreenType(parent, name, false)
00093 {
00094 m_menu = NULL;
00095 m_currentMenu = NULL;
00096 m_retObject = NULL;
00097 m_titlearea = NULL;
00098 m_text = text;
00099 m_textarea = NULL;
00100 m_buttonList = NULL;
00101
00102 m_fullscreen = fullscreen;
00103 m_osdDialog = osd;
00104 m_useSlots = false;
00105
00106 m_backtext = "";
00107 m_backdata = 0;
00108 m_exittext = "";
00109 m_exitdata = 0;
00110 }
00111
00112 MythDialogBox::MythDialogBox(const QString &title, const QString &text,
00113 MythScreenStack *parent, const char *name,
00114 bool fullscreen, bool osd)
00115 : MythScreenType(parent, name, false)
00116 {
00117 m_menu = NULL;
00118 m_currentMenu = NULL;
00119 m_id = "";
00120 m_retObject = NULL;
00121 m_title = title;
00122 m_titlearea = NULL;
00123 m_text = text;
00124 m_textarea = NULL;
00125 m_buttonList = NULL;
00126
00127 m_fullscreen = fullscreen;
00128 m_osdDialog = osd;
00129 m_useSlots = false;
00130
00131 m_backtext = "";
00132 m_backdata = 0;
00133 m_exittext = "";
00134 m_exitdata = 0;
00135 }
00136
00137 MythDialogBox::MythDialogBox(MythMenu *menu, MythScreenStack *parent, const char *name,
00138 bool fullscreen, bool osd)
00139 : MythScreenType(parent, name, false)
00140 {
00141 m_menu = menu;
00142 m_currentMenu = m_menu;
00143 m_id = "";
00144 m_retObject = NULL;
00145 m_title = "";
00146 m_titlearea = NULL;
00147 m_textarea = NULL;
00148 m_buttonList = NULL;
00149
00150 m_fullscreen = fullscreen;
00151 m_osdDialog = osd;
00152 m_useSlots = false;
00153
00154 m_backtext = "";
00155 m_backdata = 0;
00156 m_exittext = "";
00157 m_exitdata = 0;
00158 }
00159
00160 MythDialogBox::~MythDialogBox(void)
00161 {
00162 if (m_menu)
00163 {
00164 delete m_menu;
00165 m_menu = NULL;
00166 }
00167 }
00168
00169 bool MythDialogBox::Create(void)
00170 {
00171 QString windowName = (m_fullscreen ? "MythDialogBox" : "MythPopupBox");
00172
00173 if (m_osdDialog)
00174 {
00175 if (!XMLParseBase::LoadWindowFromXML("osd.xml", windowName, this))
00176 return false;
00177 }
00178 else if (!CopyWindowFromBase(windowName, this))
00179 return false;
00180
00181 bool err = false;
00182 UIUtilW::Assign(this, m_titlearea, "title");
00183 UIUtilE::Assign(this, m_textarea, "messagearea", &err);
00184 UIUtilE::Assign(this, m_buttonList, "list", &err);
00185
00186 if (err)
00187 {
00188 LOG(VB_GENERAL, LOG_ERR, QString("Cannot load screen '%1'")
00189 .arg(windowName));
00190 return false;
00191 }
00192
00193 if (m_titlearea)
00194 m_titlearea->SetText(m_title);
00195 m_textarea->SetText(m_text);
00196
00197 BuildFocusList();
00198
00199 if (m_menu)
00200 updateMenu();
00201
00202 connect(m_buttonList, SIGNAL(itemClicked(MythUIButtonListItem*)),
00203 SLOT(Select(MythUIButtonListItem*)));
00204
00205 return true;
00206 }
00207
00208 void MythDialogBox::SetMenuItems(MythMenu* menu)
00209 {
00210 m_menu = menu;
00211 m_currentMenu = m_menu;
00212 updateMenu();
00213 }
00214
00215 void MythDialogBox::updateMenu(void)
00216 {
00217 if (!m_buttonList)
00218 {
00219 LOG(VB_GENERAL, LOG_ERR, "UpdateMenu() called before we have a button list to update!");
00220 return;
00221 }
00222
00223 if (!m_currentMenu)
00224 return;
00225
00226 if (m_titlearea)
00227 m_titlearea->SetText(m_currentMenu->m_title);
00228
00229 m_textarea->SetText(m_currentMenu->m_text);
00230
00231 m_buttonList->Reset();
00232
00233 for (int x = 0; x < m_currentMenu->m_menuItems.count(); x++)
00234 {
00235 MythMenuItem *menuItem = m_currentMenu->m_menuItems.at(x);
00236 MythUIButtonListItem *button = new MythUIButtonListItem(m_buttonList, menuItem->Text);
00237 button->SetData(qVariantFromValue(menuItem));
00238 button->setDrawArrow((menuItem->SubMenu != NULL));
00239
00240 if (m_currentMenu->m_selectedItem == x)
00241 m_buttonList->SetItemCurrent(button);
00242 }
00243 }
00244
00245 void MythDialogBox::Select(MythUIButtonListItem* item)
00246 {
00247 if (!item)
00248 return;
00249
00250 if (m_currentMenu)
00251 {
00252 MythMenuItem *menuItem = qVariantValue<MythMenuItem *>(item->GetData());
00253
00254 if (menuItem->SubMenu)
00255 {
00256 m_currentMenu->m_selectedItem = m_buttonList->GetCurrentPos();
00257 m_currentMenu = menuItem->SubMenu;
00258 updateMenu();
00259 return;
00260 }
00261
00262 const char *slot = qVariantValue<const char *>(menuItem->Data);
00263 if (menuItem->UseSlot && slot)
00264 {
00265 connect(this, SIGNAL(Selected()), m_currentMenu->m_retObject, slot,
00266 Qt::QueuedConnection);
00267 emit Selected();
00268 }
00269
00270 SendEvent(m_buttonList->GetItemPos(item), item->GetText(), menuItem->Data);
00271 }
00272 else
00273 {
00274 const char *slot = qVariantValue<const char *>(item->GetData());
00275 if (m_useSlots && slot)
00276 {
00277 connect(this, SIGNAL(Selected()), m_retObject, slot,
00278 Qt::QueuedConnection);
00279 emit Selected();
00280 }
00281
00282 SendEvent(m_buttonList->GetItemPos(item), item->GetText(), item->GetData());
00283 }
00284
00285 if (m_ScreenStack)
00286 m_ScreenStack->PopScreen(false);
00287 }
00288
00289 void MythDialogBox::SetReturnEvent(QObject *retobject,
00290 const QString &resultid)
00291 {
00292 m_retObject = retobject;
00293 m_id = resultid;
00294 }
00295
00296 void MythDialogBox::SetBackAction(const QString &text, QVariant data)
00297 {
00298 m_backtext = text;
00299 m_backdata = data;
00300 }
00301
00302 void MythDialogBox::SetExitAction(const QString &text, QVariant data)
00303 {
00304 m_exittext = text;
00305 m_exitdata = data;
00306 }
00307
00308 void MythDialogBox::SetText(const QString &text)
00309 {
00310 if (m_textarea)
00311 m_textarea->SetText(text);
00312 }
00313
00314 void MythDialogBox::AddButton(const QString &title, QVariant data, bool newMenu,
00315 bool setCurrent)
00316 {
00317 MythUIButtonListItem *button = new MythUIButtonListItem(m_buttonList, title);
00318 button->SetData(data);
00319 button->setDrawArrow(newMenu);
00320
00321 if (setCurrent)
00322 m_buttonList->SetItemCurrent(button);
00323 }
00324
00325 void MythDialogBox::AddButton(const QString &title, const char *slot,
00326 bool newMenu, bool setCurrent)
00327 {
00328 MythUIButtonListItem *button = new MythUIButtonListItem(m_buttonList, title);
00329
00330 m_useSlots = true;
00331
00332 if (slot)
00333 button->SetData(qVariantFromValue(slot));
00334 button->setDrawArrow(newMenu);
00335
00336 if (setCurrent)
00337 m_buttonList->SetItemCurrent(button);
00338 }
00339
00340 bool MythDialogBox::keyPressEvent(QKeyEvent *event)
00341 {
00342 if (GetFocusWidget()->keyPressEvent(event))
00343 return true;
00344
00345 bool handled = false;
00346 QStringList actions;
00347 handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions);
00348
00349 for (int i = 0; i < actions.size() && !handled; i++)
00350 {
00351 QString action = actions[i];
00352 handled = true;
00353
00354 if (action == "ESCAPE")
00355 {
00356 SendEvent(-1, m_exittext, m_exitdata);
00357 if (m_exitdata == 0 && m_exittext.isEmpty())
00358 Close();
00359 }
00360 else if ((action == "LEFT" &&
00361 m_buttonList->GetLayout() == MythUIButtonList::LayoutVertical) ||
00362 (action == "UP" &&
00363 m_buttonList->GetLayout() == MythUIButtonList::LayoutHorizontal))
00364 {
00365 if (m_currentMenu && m_currentMenu->m_parentMenu)
00366 {
00367 m_currentMenu = m_currentMenu->m_parentMenu;
00368 updateMenu();
00369 return true;
00370 }
00371
00372 SendEvent(-1, m_backtext, m_backdata);
00373 Close();
00374 }
00375 else if (action == "MENU")
00376 {
00377 SendEvent(-2);
00378 Close();
00379 }
00380 else if ((action == "RIGHT" &&
00381 m_buttonList->GetLayout() == MythUIButtonList::LayoutVertical) ||
00382 (action == "DOWN" &&
00383 m_buttonList->GetLayout() == MythUIButtonList::LayoutHorizontal))
00384 {
00385 Select(m_buttonList->GetItemCurrent());
00386 }
00387 else
00388 handled = false;
00389 }
00390
00391 if (!handled && MythScreenType::keyPressEvent(event))
00392 handled = true;
00393
00394 return handled;
00395 }
00396
00397 bool MythDialogBox::gestureEvent(MythGestureEvent *event)
00398 {
00399 bool handled = false;
00400 if (event->gesture() == MythGestureEvent::Click)
00401 {
00402 switch (event->GetButton())
00403 {
00404 case MythGestureEvent::RightButton :
00405 SendEvent(-2);
00406 Close();
00407 handled = true;
00408 break;
00409 default :
00410 break;
00411 }
00412
00413 }
00414
00415 if (!handled && MythScreenType::gestureEvent(event))
00416 handled = true;
00417
00418 return handled;
00419 }
00420
00421 void MythDialogBox::SendEvent(int res, QString text, QVariant data)
00422 {
00423 if (m_currentMenu)
00424 {
00425 emit Closed(m_currentMenu->m_resultid, res);
00426
00427 if (!m_currentMenu->m_retObject)
00428 return;
00429
00430 DialogCompletionEvent *dce = new DialogCompletionEvent(m_currentMenu->m_resultid, res, text, data);
00431 QCoreApplication::postEvent(m_currentMenu->m_retObject, dce);
00432 }
00433 else
00434 {
00435 emit Closed(m_id, res);
00436
00437 if (!m_retObject)
00438 return;
00439
00440 DialogCompletionEvent *dce = new DialogCompletionEvent(m_id, res, text, data);
00441 QCoreApplication::postEvent(m_retObject, dce);
00442 }
00443 }
00444
00446
00447 MythConfirmationDialog::MythConfirmationDialog(MythScreenStack *parent,
00448 const QString &message,
00449 bool showCancel)
00450 : MythScreenType(parent, "mythconfirmpopup")
00451 {
00452 m_messageText = NULL;
00453 m_message = message;
00454 m_showCancel = showCancel;
00455
00456 m_id = "";
00457 m_retObject = NULL;
00458 }
00459
00460 bool MythConfirmationDialog::Create(void)
00461 {
00462 if (!CopyWindowFromBase("MythConfirmationDialog", this))
00463 return false;
00464
00465 MythUIButton *okButton = NULL;
00466 MythUIButton *cancelButton = NULL;
00467
00468 bool err = false;
00469 UIUtilE::Assign(this, m_messageText, "message", &err);
00470 UIUtilE::Assign(this, okButton, "ok", &err);
00471 UIUtilE::Assign(this, cancelButton, "cancel", &err);
00472
00473 if (err)
00474 {
00475 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythConfirmationDialog'");
00476 return false;
00477 }
00478
00479 if (m_showCancel)
00480 {
00481 connect(cancelButton, SIGNAL(Clicked()), SLOT(Cancel()));
00482 }
00483 else
00484 cancelButton->SetVisible(false);
00485
00486 connect(okButton, SIGNAL(Clicked()), SLOT(Confirm()));
00487
00488 m_messageText->SetText(m_message);
00489
00490 BuildFocusList();
00491
00492 if (m_showCancel)
00493 SetFocusWidget(cancelButton);
00494 else
00495 SetFocusWidget(okButton);
00496
00497 return true;
00498 }
00499
00500 bool MythConfirmationDialog::keyPressEvent(QKeyEvent *event)
00501 {
00502 if (GetFocusWidget()->keyPressEvent(event))
00503 return true;
00504
00505 bool handled = false;
00506 QStringList actions;
00507 handled = GetMythMainWindow()->TranslateKeyPress("qt", event, actions);
00508
00509 for (int i = 0; i < actions.size() && !handled; i++)
00510 {
00511 QString action = actions[i];
00512 handled = true;
00513
00514 if (action == "ESCAPE")
00515 sendResult(false);
00516 else
00517 handled = false;
00518 }
00519
00520 if (!handled && MythScreenType::keyPressEvent(event))
00521 handled = true;
00522
00523 return handled;
00524 }
00525
00526 void MythConfirmationDialog::SetMessage(const QString &message)
00527 {
00528 m_message = message;
00529 if (m_messageText)
00530 m_messageText->SetText(m_message);
00531 }
00532
00533 void MythConfirmationDialog::SetReturnEvent(QObject *retobject,
00534 const QString &resultid)
00535 {
00536 m_retObject = retobject;
00537 m_id = resultid;
00538 }
00539
00540 void MythConfirmationDialog::Confirm()
00541 {
00542 sendResult(true);
00543 }
00544
00545 void MythConfirmationDialog::Cancel()
00546 {
00547 sendResult(false);
00548 }
00549
00550 void MythConfirmationDialog::sendResult(bool ok)
00551 {
00552 emit haveResult(ok);
00553
00554 if (m_retObject)
00555 {
00556 int res = 0;
00557 if (ok)
00558 res = 1;
00559
00560 DialogCompletionEvent *dce = new DialogCompletionEvent(m_id, res, "",
00561 m_resultData);
00562 QCoreApplication::postEvent(m_retObject, dce);
00563 }
00564
00565 Close();
00566 }
00567
00571 MythConfirmationDialog *ShowOkPopup(const QString &message, QObject *parent,
00572 const char *slot, bool showCancel)
00573 {
00574 QString LOC = "ShowOkPopup('" + message + "') - ";
00575 MythConfirmationDialog *pop;
00576 MythScreenStack *stk = NULL;
00577
00578
00579 if (!stk)
00580 {
00581 MythMainWindow *win = GetMythMainWindow();
00582
00583 if (win)
00584 stk = win->GetStack("popup stack");
00585 else
00586 {
00587 LOG(VB_GENERAL, LOG_ERR, LOC + "no main window?");
00588 return NULL;
00589 }
00590
00591 if (!stk)
00592 {
00593 LOG(VB_GENERAL, LOG_ERR, LOC + "no popup stack? "
00594 "Is there a MythThemeBase?");
00595 return NULL;
00596 }
00597 }
00598
00599 pop = new MythConfirmationDialog(stk, message, showCancel);
00600 if (pop->Create())
00601 {
00602 stk->AddScreen(pop);
00603 if (parent && slot)
00604 QObject::connect(pop, SIGNAL(haveResult(bool)), parent, slot,
00605 Qt::QueuedConnection);
00606 }
00607 else
00608 {
00609 delete pop;
00610 pop = NULL;
00611 LOG(VB_GENERAL, LOG_ERR, LOC + "Couldn't Create() Dialog");
00612 }
00613
00614 return pop;
00615 }
00616
00618
00619 MythTextInputDialog::MythTextInputDialog(MythScreenStack *parent,
00620 const QString &message,
00621 InputFilter filter,
00622 bool isPassword,
00623 const QString &defaultValue)
00624 : MythScreenType(parent, "mythtextinputpopup")
00625 {
00626 m_filter = filter;
00627 m_isPassword = isPassword;
00628 m_message = message;
00629 m_defaultValue = defaultValue;
00630 m_textEdit = NULL;
00631
00632 m_id = "";
00633 m_retObject = NULL;
00634 }
00635
00636 bool MythTextInputDialog::Create(void)
00637 {
00638 if (!CopyWindowFromBase("MythTextInputDialog", this))
00639 return false;
00640
00641 MythUIText *messageText = NULL;
00642 MythUIButton *okButton = NULL;
00643 MythUIButton *cancelButton = NULL;
00644
00645 bool err = false;
00646 UIUtilE::Assign(this, m_textEdit, "input", &err);
00647 UIUtilE::Assign(this, messageText, "message", &err);
00648 UIUtilE::Assign(this, okButton, "ok", &err);
00649 UIUtilW::Assign(this, cancelButton, "cancel");
00650
00651 if (err)
00652 {
00653 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythTextInputDialog'");
00654 return false;
00655 }
00656
00657 if (cancelButton)
00658 connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
00659 connect(okButton, SIGNAL(Clicked()), SLOT(sendResult()));
00660
00661 m_textEdit->SetFilter(m_filter);
00662 m_textEdit->SetText(m_defaultValue);
00663 m_textEdit->SetPassword(m_isPassword);
00664
00665 messageText->SetText(m_message);
00666
00667 BuildFocusList();
00668
00669 return true;
00670 }
00671
00672 void MythTextInputDialog::SetReturnEvent(QObject *retobject,
00673 const QString &resultid)
00674 {
00675 m_retObject = retobject;
00676 m_id = resultid;
00677 }
00678
00679 void MythTextInputDialog::sendResult()
00680 {
00681 QString inputString = m_textEdit->GetText();
00682 emit haveResult(inputString);
00683
00684 if (m_retObject)
00685 {
00686 DialogCompletionEvent *dce = new DialogCompletionEvent(m_id, 0,
00687 inputString, "");
00688 QCoreApplication::postEvent(m_retObject, dce);
00689 }
00690
00691 Close();
00692 }
00693
00695
00696
00711 MythUISearchDialog::MythUISearchDialog(MythScreenStack *parent,
00712 const QString &title,
00713 const QStringList &list,
00714 bool matchAnywhere,
00715 const QString &defaultValue)
00716 : MythScreenType(parent, "mythsearchdialogpopup")
00717 {
00718 m_list = list;
00719 m_matchAnywhere = matchAnywhere;
00720 m_title = title;
00721 m_defaultValue = defaultValue;
00722
00723 m_titleText = NULL;
00724 m_matchesText = NULL;
00725 m_textEdit = NULL;
00726 m_itemList = NULL;
00727
00728 m_id = "";
00729 m_retObject = NULL;
00730 }
00731
00732 bool MythUISearchDialog::Create(void)
00733 {
00734 if (!CopyWindowFromBase("MythSearchDialog", this))
00735 return false;
00736
00737 MythUIButton *okButton = NULL;
00738 MythUIButton *cancelButton = NULL;
00739
00740 bool err = false;
00741 UIUtilE::Assign(this, m_textEdit, "input", &err);
00742 UIUtilE::Assign(this, m_titleText, "title", &err);
00743 UIUtilW::Assign(this, m_matchesText, "matches");
00744 UIUtilE::Assign(this, m_itemList, "itemlist", &err);
00745 UIUtilE::Assign(this, okButton, "ok", &err);
00746 UIUtilW::Assign(this, cancelButton, "cancel");
00747
00748 if (err)
00749 {
00750 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythSearchDialog'");
00751 return false;
00752 }
00753
00754 if (cancelButton)
00755 connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
00756
00757 connect(okButton, SIGNAL(Clicked()), SLOT(slotSendResult()));
00758
00759 connect(m_itemList, SIGNAL(itemClicked(MythUIButtonListItem*)),
00760 SLOT(slotSendResult()));
00761
00762 m_textEdit->SetText(m_defaultValue);
00763 connect(m_textEdit, SIGNAL(valueChanged()), SLOT(slotUpdateList()));
00764
00765 m_titleText->SetText(m_title);
00766 if (m_matchesText)
00767 m_matchesText->SetText(tr("%n match(es)", "", 0));
00768
00769 BuildFocusList();
00770
00771 slotUpdateList();
00772
00773 return true;
00774 }
00775
00776 void MythUISearchDialog::SetReturnEvent(QObject *retobject,
00777 const QString &resultid)
00778 {
00779 m_retObject = retobject;
00780 m_id = resultid;
00781 }
00782
00783 void MythUISearchDialog::slotSendResult()
00784 {
00785 if (!m_itemList->GetItemCurrent())
00786 return;
00787
00788 QString result = m_itemList->GetValue();
00789
00790 emit haveResult(result);
00791
00792 if (m_retObject)
00793 {
00794 DialogCompletionEvent *dce = new DialogCompletionEvent(m_id, 0,
00795 result, "");
00796 QCoreApplication::postEvent(m_retObject, dce);
00797 }
00798
00799 Close();
00800 }
00801
00802 void MythUISearchDialog::slotUpdateList(void)
00803 {
00804 m_itemList->Reset();
00805
00806 for (int x = 0; x < m_list.size(); x++)
00807 {
00808 QString item = m_list.at(x);
00809
00810 if (m_matchAnywhere)
00811 {
00812 if (!item.contains(m_textEdit->GetText(), Qt::CaseInsensitive))
00813 continue;
00814 }
00815 else
00816 {
00817 if (!item.startsWith(m_textEdit->GetText(), Qt::CaseInsensitive))
00818 continue;
00819 }
00820
00821
00822 new MythUIButtonListItem(m_itemList, item, NULL, false);
00823 }
00824
00825 m_itemList->SetItemCurrent(0);
00826
00827 if (m_matchesText)
00828 m_matchesText->SetText(tr("%n match(es)", "", 0));
00829 }
00830
00832
00833 MythTimeInputDialog::MythTimeInputDialog(MythScreenStack *parent,
00834 const QString &message,
00835 int resolutionFlags,
00836 QDateTime startTime,
00837 int rangeLimit)
00838 : MythScreenType(parent, "timepopup"),
00839 m_message(message), m_startTime(startTime),
00840 m_resolution(resolutionFlags), m_rangeLimit(rangeLimit),
00841 m_dateList(NULL), m_timeList(NULL), m_retObject(NULL)
00842 {
00843 }
00844
00845 bool MythTimeInputDialog::Create()
00846 {
00847 if (!CopyWindowFromBase("MythTimeInputDialog", this))
00848 return false;
00849
00850 MythUIText *messageText = NULL;
00851 MythUIButton *okButton = NULL;
00852
00853 bool err = false;
00854 UIUtilE::Assign(this, messageText, "message", &err);
00855 UIUtilE::Assign(this, m_dateList, "dates", &err);
00856 UIUtilE::Assign(this, m_timeList, "times", &err);
00857 UIUtilE::Assign(this, okButton, "ok", &err);
00858
00859 if (err)
00860 {
00861 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythTimeInputDialog'");
00862 return false;
00863 }
00864
00865 m_dateList->SetVisible(false);
00866 m_timeList->SetVisible(false);
00867
00868 MythUIButtonListItem *item;
00869
00870 if (kNoDate != (m_resolution & 0xF))
00871 {
00872 QDate date(m_startTime.date());
00873
00874 int limit = 0;
00875 if (m_resolution & kFutureDates)
00876 {
00877 limit += m_rangeLimit;
00878 }
00879 if (m_resolution & kPastDates)
00880 {
00881 limit += m_rangeLimit;
00882 date = date.addDays(0-m_rangeLimit);
00883 }
00884
00885 QString text;
00886 int flags;
00887 bool selected = false;
00888 for (int x = 0; x <= limit; x++)
00889 {
00890 selected = false;
00891 if (m_resolution & kDay)
00892 {
00893 date = date.addDays(1);
00894 flags = kDateFull | kSimplify;
00895 if (m_rangeLimit >= 356)
00896 flags |= kAddYear;
00897 text = MythDateToString(date, flags);
00898
00899 if (date == m_startTime.date())
00900 selected = true;
00901 }
00902 else if (m_resolution & kMonth)
00903 {
00904 date = date.addMonths(1);
00905 text = date.toString("MMM yyyy");
00906
00907 if ((date.month() == m_startTime.date().month()) &&
00908 (date.year() == m_startTime.date().year()))
00909 selected = true;
00910 }
00911 else if (m_resolution & kYear)
00912 {
00913 date = date.addYears(1);
00914 text = date.toString("yyyy");
00915 if (date.year() == m_startTime.date().year())
00916 selected = true;
00917 }
00918
00919 item = new MythUIButtonListItem(m_dateList, text, NULL, false);
00920 item->SetData(QVariant(date));
00921
00922 if (selected)
00923 m_dateList->SetItemCurrent(item);
00924 }
00925 m_dateList->SetVisible(true);
00926 }
00927
00928
00929 if (kNoTime != (m_resolution & 0xF0))
00930 {
00931 QTime time(0,0,0);
00932 QString text;
00933 bool selected = false;
00934
00935 int limit = (m_resolution & kMinutes) ? (60 * 24) : 24;
00936
00937 for (int x = 0; x < limit; x++)
00938 {
00939 selected = false;
00940 if (m_resolution & kMinutes)
00941 {
00942 time = time.addSecs(60);
00943 text = MythTimeToString(time, kTime);
00944
00945 if (time == m_startTime.time())
00946 selected = true;
00947 }
00948 else if (m_resolution & kHours)
00949 {
00950 time = time.addSecs(60*60);
00951 text = time.toString("hh:00");
00952
00953 if (time.hour() == m_startTime.time().hour())
00954 selected = true;
00955 }
00956
00957 item = new MythUIButtonListItem(m_timeList, text, NULL, false);
00958 item->SetData(QVariant(time));
00959
00960 if (selected)
00961 m_timeList->SetItemCurrent(item);
00962 }
00963 m_timeList->SetVisible(true);
00964 }
00965
00966 if (messageText && !m_message.isEmpty())
00967 messageText->SetText(m_message);
00968
00969 connect(okButton, SIGNAL(Clicked()), SLOT(okClicked()));
00970
00971 BuildFocusList();
00972
00973 return true;
00974 }
00975
00976 void MythTimeInputDialog::SetReturnEvent(QObject* retobject,
00977 const QString& resultid)
00978 {
00979 m_retObject = retobject;
00980 m_id = resultid;
00981 }
00982
00983 void MythTimeInputDialog::okClicked(void)
00984 {
00985 QDateTime dateTime;
00986 QDate date = m_dateList->GetDataValue().toDate();
00987 QTime time = m_timeList->GetDataValue().toTime();
00988
00989 dateTime.setDate(date);
00990 dateTime.setTime(time);
00991
00992 emit haveResult(dateTime);
00993
00994 if (m_retObject)
00995 {
00996 QVariant data(dateTime);
00997 DialogCompletionEvent *dce = new DialogCompletionEvent(m_id, 0, "",
00998 data);
00999 QCoreApplication::postEvent(m_retObject, dce);
01000 }
01001
01002 Close();
01003 }