00001 #include <mythtv/mythdbcon.h>
00002 #include <mythtv/uilistbtntype.h>
00003 #include <qapplication.h>
00004
00005 #include "weatherScreen.h"
00006 #include "weatherSource.h"
00007 #include "sourceManager.h"
00008
00009 #include "defs.h"
00010
00011 #include "weatherSetup.h"
00012
00013 #define GLBL_SCREEN 0
00014 #define SCREEN_SETUP_SCREEN 1
00015 #define SRC_SCREEN 2
00016
00017 GlobalSetup::GlobalSetup(MythMainWindow *parent)
00018 : MythThemedDialog(parent, "global-setup", "weather-", "Global Setup")
00019 {
00020 wireUI();
00021 loadData();
00022
00023 buildFocusList();
00024 assignFirstFocus();
00025 }
00026
00027 GlobalSetup::~GlobalSetup()
00028 {
00029 delete m_timeout_spinbox;
00030 delete m_hold_spinbox;
00031 }
00032
00033 void GlobalSetup::wireUI()
00034 {
00035 UIBlackHoleType *blckhl = getUIBlackHoleType("pgto_spinbox");
00036 if (!blckhl)
00037 {
00038 VERBOSE(VB_IMPORTANT, "error loading pgto_spinbox");
00039 }
00040 else
00041 {
00042 m_timeout_spinbox = new WeatherSpinBox(this);
00043 m_timeout_spinbox->setRange(1, 1000);
00044 m_timeout_spinbox->setLineStep(1);
00045 m_timeout_spinbox->setFont(gContext->GetMediumFont());
00046 m_timeout_spinbox->setFocusPolicy(QWidget::NoFocus);
00047 m_timeout_spinbox->setGeometry(blckhl->getScreenArea());
00048 blckhl->allowFocus(true);
00049 connect(blckhl, SIGNAL(takingFocus()), m_timeout_spinbox,
00050 SLOT(setFocus()));
00051
00052 connect(blckhl, SIGNAL(loosingFocus()), m_timeout_spinbox,
00053 SLOT(clearFocus()));
00054 }
00055
00056 blckhl = getUIBlackHoleType("hold_spinbox");
00057 if (!blckhl)
00058 {
00059 VERBOSE(VB_IMPORTANT, "error loading hold_spinbox");
00060 }
00061 else
00062 {
00063 m_hold_spinbox = new WeatherSpinBox(this);
00064 m_hold_spinbox->setRange(1, 1000);
00065 m_hold_spinbox->setLineStep(1);
00066 m_hold_spinbox->setFont(gContext->GetMediumFont());
00067 m_hold_spinbox->setFocusPolicy(QWidget::NoFocus);
00068 m_hold_spinbox->setGeometry(blckhl->getScreenArea());
00069 blckhl->allowFocus(true);
00070 connect(blckhl, SIGNAL(takingFocus()), m_hold_spinbox,
00071 SLOT(setFocus()));
00072 connect(blckhl, SIGNAL(loosingFocus()), m_hold_spinbox,
00073 SLOT(clearFocus()));
00074 }
00075
00076 m_background_check = getUICheckBoxType("backgroundcheck");
00077 if (!m_background_check)
00078 {
00079 VERBOSE(VB_IMPORTANT, "error loading backgroundcheck");
00080 }
00081 else
00082 {
00083 int setting = gContext->GetNumSetting("weatherbackgroundfetch", 0);
00084 m_background_check->setState((bool) setting);
00085 }
00086
00087 m_skip_check = getUICheckBoxType("skipcheck");
00088 if (!m_skip_check)
00089 {
00090 VERBOSE(VB_IMPORTANT, "error loading skipcheck");
00091 }
00092
00093 m_finish_btn = getUITextButtonType("finishbutton");
00094 if (m_finish_btn)
00095 {
00096 m_finish_btn->setText(tr("Finish"));
00097 connect(m_finish_btn, SIGNAL(pushed()), this, SLOT(saveData()));
00098 }
00099 }
00100
00101 void GlobalSetup::loadData()
00102 {
00103 m_timeout = gContext->GetNumSetting("weatherTimeout", 10);
00104 m_hold_timeout = gContext->GetNumSetting("weatherHoldTimeout", 20);
00105
00106 m_timeout_spinbox->setValue(m_timeout);
00107 m_hold_spinbox->setValue(m_hold_timeout);
00108 }
00109
00110 void GlobalSetup::saveData()
00111 {
00112 gContext->SaveSetting("weatherTimeout", m_timeout_spinbox->value());
00113 gContext->SaveSetting("weatherHoldTimeout", m_hold_spinbox->value());
00114 gContext->SaveSetting("weatherbackgroundfetch",
00115 m_background_check->getState() ? 1 : 0);
00116 accept();
00117 }
00118
00119 void GlobalSetup::keyPressEvent(QKeyEvent *e)
00120 {
00121 QStringList actions;
00122 gContext->GetMainWindow()->TranslateKeyPress("Weather", e, actions);
00123 UIType *curr = getCurrentFocusWidget();
00124 bool handled = false;
00125
00126 for (uint i = 0; i < actions.size() && !handled; ++i)
00127 {
00128 handled = true;
00129 QString action = actions[i];
00130 if (action == "DOWN")
00131 {
00132 nextPrevWidgetFocus(true);
00133 }
00134 else if (action == "UP")
00135 {
00136 nextPrevWidgetFocus(false);
00137 }
00138 else if (action == "SELECT")
00139 {
00140 UICheckBoxType *check = dynamic_cast<UICheckBoxType *>(curr);
00141 if (check)
00142 {
00143 check->push();
00144 }
00145 if (curr == m_finish_btn)
00146 m_finish_btn->push();
00147 }
00148 else
00149 handled = false;
00150 }
00151
00152 if (!handled)
00153 MythDialog::keyPressEvent(e);
00154 }
00155
00157
00158 ScreenSetup::ScreenSetup(MythMainWindow *parent, SourceManager *srcman) :
00159 MythThemedDialog(parent, "screen-setup", "weather-", "Screen Setup")
00160 {
00161 m_src_man = srcman;
00162 wireUI();
00163 loadData();
00164
00165 buildFocusList();
00166 assignFirstFocus();
00167 }
00168
00169 void ScreenSetup::wireUI()
00170 {
00171 m_help_txt = getUITextType("helptxt");
00172 if (!m_help_txt)
00173 {
00174 VERBOSE(VB_IMPORTANT, "error loading helptxt");
00175 }
00176
00177 UITextType *activeheader = getUITextType("activehdr");
00178 if (activeheader)
00179 activeheader->SetText(tr("Active Screens"));
00180
00181 UITextType *inactiveheader = getUITextType("inactivehdr");
00182 if (inactiveheader)
00183 inactiveheader->SetText(tr("Inactive Screens"));
00184
00185 m_active_list = getUIListBtnType("activelist");
00186 if (!m_active_list)
00187 {
00188 VERBOSE(VB_IMPORTANT, "error loading activelist");
00189 }
00190 else
00191 {
00192 m_active_list->calculateScreenArea();
00193 connect(m_active_list, SIGNAL(itemSelected(UIListBtnTypeItem *)),
00194 this, SLOT(activeListItemSelected(UIListBtnTypeItem *)));
00195 connect(m_active_list, SIGNAL(takingFocus()), this,
00196 SLOT(updateHelpText()));
00197 connect(m_active_list, SIGNAL(itemSelected(UIListBtnTypeItem *)),
00198 this, SLOT(updateHelpText()));
00199 }
00200
00201 m_inactive_list = getUIListBtnType("inactivelist");
00202 if (!m_inactive_list)
00203 {
00204 VERBOSE(VB_IMPORTANT, "error loading inactivelist");
00205 }
00206 else
00207 {
00208 m_inactive_list->calculateScreenArea();
00209 connect(m_inactive_list, SIGNAL(takingFocus()), this,
00210 SLOT(updateHelpText()));
00211 connect(m_inactive_list, SIGNAL(itemSelected(UIListBtnTypeItem *)),
00212 this, SLOT(updateHelpText()));
00213 }
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 m_finish_btn = getUITextButtonType("finishbutton");
00252 if (m_finish_btn)
00253 {
00254 m_finish_btn->setText(tr("Finish"));
00255 connect(m_finish_btn, SIGNAL(pushed()), this, SLOT(saveData()));
00256 }
00257
00258 }
00259
00260 void ScreenSetup::keyPressEvent(QKeyEvent *e)
00261 {
00262 QStringList actions;
00263 gContext->GetMainWindow()->TranslateKeyPress("Weather", e, actions);
00264 UIType *curr = getCurrentFocusWidget();
00265 UIListBtnType *list;
00266 bool handled = false;
00267
00268 for (uint i = 0; i < actions.size() && !handled; ++i)
00269 {
00270 handled = true;
00271 QString action = actions[i];
00272 if (action == "DOWN")
00273 cursorDown(curr);
00274 else if (action == "UP")
00275 cursorUp(curr);
00276 else if (action == "SELECT")
00277 cursorSelect(curr);
00278 else if (action == "RIGHT")
00279 {
00280 m_active_list->allowFocus(m_active_list->GetCount() > 0);
00281 nextPrevWidgetFocus(true);
00282 }
00283 else if (action == "LEFT")
00284 {
00285 m_active_list->allowFocus(m_active_list->GetCount() > 0);
00286 nextPrevWidgetFocus(false);
00287 }
00288 else if (action == "DELETE")
00289 {
00290 if (curr == m_active_list)
00291 {
00292 UIListBtnType *list = dynamic_cast<UIListBtnType *>(curr);
00293 deleteScreen(list);
00294 }
00295 }
00296 else if (action == "SEARCH" &&
00297 (list = dynamic_cast<UIListBtnType *>(curr)))
00298 {
00299 list->incSearchStart();
00300 updateForeground(list->getScreenArea());
00301 }
00302 else if (action == "NEXTSEARCH" &&
00303 (list = dynamic_cast<UIListBtnType *>(curr)))
00304 {
00305 list->incSearchNext();
00306 updateForeground(list->getScreenArea());
00307 }
00308 else
00309 handled = false;
00310 }
00311
00312 if (!handled)
00313 MythDialog::keyPressEvent(e);
00314 }
00315
00316 void ScreenSetup::updateHelpText()
00317 {
00318 UIType *itm = getCurrentFocusWidget();
00319 QString text;
00320 if (!itm) return;
00321
00322 if (itm == m_inactive_list)
00323 {
00324
00325 UIListBtnTypeItem *lbt = m_inactive_list->GetItemCurrent();
00326 if (!lbt)
00327 return;
00328
00329 ScreenListInfo *si = (ScreenListInfo *) lbt->getData();
00330 if (!si)
00331 return;
00332
00333 QStringList sources = si->sources;
00334
00335 text = tr("Add desired screen to the Active Screens list "
00336 "by pressing SELECT.") + "\n";
00337 text += lbt->text() + "\n";
00338 text += QString("%1: %2").arg(tr("Sources"))
00339 .arg(sources.join(", "));
00340 }
00341 else if (itm == m_active_list)
00342 {
00343 UIListBtnTypeItem *lbt = m_active_list->GetItemCurrent();
00344 if (!lbt)
00345 return;
00346
00347 ScreenListInfo *si = (ScreenListInfo *) lbt->getData();
00348 if (!si)
00349 return;
00350
00351 QDictIterator<TypeListInfo> it(si->types);
00352 TypeListInfo *ti = it.current();
00353 text += lbt->text() + "\n";
00354 if (si->hasUnits)
00355 text += tr("Units: ") +
00356 (si->units == ENG_UNITS ? tr("English Units") :
00357 tr("SI Units")) + " ";
00358 if (!si->multiLoc && ti)
00359 {
00360 text += tr("Location: ") + (ti->location != "" ?
00361 ti->location : tr("Not Defined")) + "\n";
00362 text += tr("Source: " ) +
00363 (ti->src ? ti->src->name : tr("Not Defined")) + "\n";
00364 }
00365 text += "\n" + tr("Press SELECT to ");
00366 if (!si->multiLoc)
00367 text += tr("change location; ");
00368 if (si->hasUnits)
00369 text += tr("change units; ");
00370 text += tr("move screen up or down; or remove screen.");
00371 }
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 m_help_txt->SetText(text);
00386 }
00387
00388 void ScreenSetup::loadData()
00389 {
00390 QIntDict<ScreenListInfo> active_screens;
00391 ScreenListInfo *si;
00392 TypeListInfo *ti;
00393
00394
00395
00396
00397
00398 QString uifile = gContext->GetThemeDir() + "/weather-ui.xml";
00399 if (!QFile::exists(uifile))
00400 uifile = gContext->GetShareDir() + "themes/default/weather-ui.xml";
00401
00402 if (!QFile::exists(uifile))
00403 {
00404 VERBOSE(VB_IMPORTANT, "Error locating weather-ui.xml");
00405 return;
00406 }
00407
00408 QFile xml(uifile);
00409 QDomDocument doc;
00410 if (!xml.open(IO_ReadOnly))
00411 return;
00412 QString msg;
00413 int line, col;
00414 if (!doc.setContent(&xml, false, &msg, &line, &col))
00415 {
00416 VERBOSE(VB_IMPORTANT, QString("Error parsing weather-ui.xml at line %1")
00417 .arg(line));
00418 VERBOSE(VB_IMPORTANT, QString("XML error %1")
00419 .arg(msg));
00420 return;
00421 }
00422
00423 QDomElement *win = 0;
00424 QDomNode n = doc.documentElement().firstChild();
00425 while (!n.isNull() && !win)
00426 {
00427 QDomElement e = n.toElement();
00428 if (e.isNull())
00429 continue;
00430 if (e.tagName() == "window")
00431 {
00432 QString name = e.attribute("name");
00433 if (!name.isNull() && name == "weather")
00434 win = &e;
00435 }
00436 n = n.nextSibling();
00437 }
00438 if (!win)
00439 {
00440 VERBOSE(VB_IMPORTANT, "weather window not found");
00441 return;
00442 }
00443 n = win->firstChild();
00444 QString tmpname;
00445 int context;
00446 QRect area;
00447 QStringList types;
00448 while (!n.isNull())
00449 {
00450 QDomElement e = n.toElement();
00451 if (e.tagName() == "font")
00452 {
00453 m_weather_screens.parseFont(e);
00454 }
00455 else if (e.tagName() == "container")
00456 {
00457 QString name = e.attribute("name");
00458 if (!name.isNull() && !name.isEmpty() && name != "startup"
00459 && name != "background")
00460 {
00461 m_weather_screens.parseContainer(e, tmpname, context, area);
00462 types = WeatherScreen::getAllDynamicTypes(m_weather_screens.GetSet(name));
00463 LayerSet *set = m_weather_screens.GetSet(name);
00464
00465 si = new ScreenListInfo;
00466 si->units = ENG_UNITS;
00467 si->hasUnits = !(bool) set->GetType("nounits");
00468 si->multiLoc = (bool) set->GetType("multilocation");
00469 si->types.setAutoDelete(true);
00470
00471 QStringList type_strs;
00472 for (uint i = 0; i < types.size(); ++i)
00473 {
00474 ti = new TypeListInfo;
00475 ti->name = types[i];
00476 ti->src = 0;
00477 si->types.insert(types[i], ti);
00478 type_strs << types[i];
00479 }
00480
00481 QPtrList<ScriptInfo> scriptList;
00482
00483
00484 if (m_src_man->findPossibleSources(type_strs, scriptList))
00485 {
00486 ScriptInfo *script;
00487 for (script = scriptList.first(); script;
00488 script = scriptList.next())
00489 {
00490 si->sources.append(script->name);
00491 }
00492 UIListBtnTypeItem *itm =
00493 new UIListBtnTypeItem(m_inactive_list, name);
00494 itm->setData(si);
00495 }
00496
00497 }
00498 }
00499 n = n.nextSibling();
00500 }
00501
00502 MSqlQuery db(MSqlQuery::InitCon());
00503 QString query = "SELECT weatherscreens.container, weatherscreens.units, "
00504 "weatherdatalayout.dataitem, weatherdatalayout.location, "
00505 "weathersourcesettings.source_name, weatherscreens.draworder "
00506 "FROM weatherscreens, weatherdatalayout, weathersourcesettings "
00507 "WHERE weatherscreens.hostname = :HOST "
00508 "AND weatherscreens.screen_id = weatherdatalayout.weatherscreens_screen_id "
00509 "AND weathersourcesettings.sourceid = weatherdatalayout.weathersourcesettings_sourceid "
00510 "ORDER BY weatherscreens.draworder;";
00511 db.prepare(query);
00512 db.bindValue(":HOST", gContext->GetHostName());
00513 if (!db.exec())
00514 {
00515 VERBOSE(VB_IMPORTANT, db.lastError().text());
00516 return;
00517 }
00518
00519 while (db.next())
00520 {
00521 QString name = db.value(0).toString();
00522 units_t units = db.value(1).toUInt();
00523 QString dataitem = db.value(2).toString();
00524 QString location = db.value(3).toString();
00525 QString src = db.value(4).toString();
00526 uint draworder = db.value(5).toUInt();
00527 LayerSet *set = m_weather_screens.GetSet(name);
00528
00529 ti = new TypeListInfo;
00530 ti->name = dataitem;
00531 ti->location = location;
00532 ti->src = m_src_man->getSourceByName(src);
00533 types = WeatherScreen::getAllDynamicTypes(m_weather_screens.GetSet(name));
00534
00535 if (!active_screens.find(draworder))
00536 {
00537 UIListBtnTypeItem *itm = new UIListBtnTypeItem(m_active_list, name);
00538 si = new ScreenListInfo;
00539 si->units = units;
00540 si->types.setAutoDelete(true);
00541
00542
00543 for (QStringList::Iterator type_i = types.begin(); type_i != types.end(); ++type_i )
00544 {
00545 if(*type_i == dataitem)
00546 {
00547 si->types.insert(dataitem, ti);
00548 }
00549 }
00550
00551 si->hasUnits = !(bool) set->GetType("nounits");
00552 si->multiLoc = (bool) set->GetType("multilocation");
00553 itm->setData(si);
00554 active_screens.insert(draworder, si);
00555 }
00556 else
00557 {
00558 si = active_screens[draworder];
00559 for (QStringList::Iterator type_i = types.begin(); type_i != types.end(); ++type_i )
00560 {
00561 if(*type_i == dataitem)
00562 {
00563 si->types.insert(dataitem, ti);
00564 }
00565 }
00566 }
00567 }
00568 }
00569
00570 inline QString format_msg(
00571 const QStringList ¬Defined, uint rows, uint columns)
00572 {
00573 const QString etc = QObject::tr("etc...");
00574 uint elen = etc.length();
00575 QStringList lines;
00576 lines += "";
00577 QStringList::iterator oit = lines.begin();
00578 QStringList::const_iterator iit = notDefined.begin();
00579 while (iit != notDefined.end())
00580 {
00581 QStringList::const_iterator nit = iit;
00582 nit++;
00583
00584 uint olen = (*oit).length();
00585 uint ilen = (*iit).length();
00586
00587 if (lines.size() >= rows)
00588 {
00589 if (((olen + 2 + ilen + 2 + elen) < columns) ||
00590 (((olen + 2 + ilen) < columns) && (nit == notDefined.end())))
00591 {
00592 *oit += ", " + *iit;
00593 }
00594 else
00595 {
00596 *oit += ", " + etc;
00597 nit = notDefined.end();
00598 }
00599 }
00600 else
00601 {
00602 if ((olen + 2 + ilen) < columns)
00603 {
00604 *oit += ", " + *iit;
00605 }
00606 else
00607 {
00608 *oit += ",";
00609 lines += "";
00610 oit++;
00611 *oit += *iit;
00612 }
00613 }
00614
00615 iit = nit;
00616 }
00617
00618 return lines.join("\n").mid(2);
00619 }
00620
00621 void ScreenSetup::saveData()
00622 {
00623
00624 QStringList notDefined;
00625 QPtrListIterator<UIListBtnTypeItem> screens = m_active_list->GetIterator();
00626 if (!screens)
00627 {
00628 MythPopupBox::showOkPopup(gContext->GetMainWindow(), "No Screens",
00629 tr("No Active Screens are defined. Define atleast one "
00630 "before continuing."));
00631 return;
00632 }
00633
00634 while (screens)
00635 {
00636 UIListBtnTypeItem *itm = *screens;
00637 ScreenListInfo *si = (ScreenListInfo *) itm->getData();
00638 QDictIterator<TypeListInfo> it(si->types);
00639 for (; it.current(); ++it)
00640 {
00641 TypeListInfo *ti = it.current();
00642 if (!ti->src)
00643 notDefined << ti->name;
00644 }
00645 ++screens;
00646 }
00647
00648 if (notDefined.size())
00649 {
00650 QString msg = tr("Can not proceed, the following data "
00651 "items do not have sources defined:\n");
00652 msg += format_msg(notDefined, 1, 400);
00653 MythPopupBox::showOkPopup(gContext->GetMainWindow(),
00654 "Undefined Sources", msg);
00655 return;
00656 }
00657
00658 MSqlQuery db(MSqlQuery::InitCon());
00659 MSqlQuery db2(MSqlQuery::InitCon());
00660 QString query = "DELETE FROM weatherscreens WHERE hostname=:HOST";
00661 db.prepare(query);
00662 db.bindValue(":HOST", gContext->GetHostName());
00663 db.exec();
00664
00665 query = "INSERT into weatherscreens (draworder, container, units, hostname) "
00666 "VALUES (:DRAW, :CONT, :UNITS, :HOST);";
00667 db.prepare(query);
00668 QPtrListIterator<UIListBtnTypeItem> an_it = m_active_list->GetIterator();
00669 int draworder = 0;
00670 while (an_it)
00671 {
00672 UIListBtnTypeItem *itm = *an_it;
00673 ScreenListInfo *si = (ScreenListInfo *) itm->getData();
00674 db.bindValue(":DRAW", draworder);
00675 db.bindValue(":CONT", itm->text());
00676 db.bindValue(":UNITS", si->units);
00677 db.bindValue(":HOST", gContext->GetHostName());
00678 if (db.exec())
00679 {
00680
00681 QString query2 = "SELECT screen_id FROM weatherscreens "
00682 "WHERE draworder = :DRAW AND hostname = :HOST;";
00683 db2.prepare(query2);
00684 db2.bindValue(":DRAW", draworder);
00685 db2.bindValue(":HOST", gContext->GetHostName());
00686 if (!db2.exec())
00687 {
00688 VERBOSE(VB_IMPORTANT, db2.executedQuery());
00689 VERBOSE(VB_IMPORTANT, db2.lastError().text());
00690 return;
00691 }
00692
00693 db2.next();
00694 int screen_id = db2.value(0).toInt();
00695
00696 query2 = "INSERT INTO weatherdatalayout (location, dataitem, "
00697 "weatherscreens_screen_id, weathersourcesettings_sourceid) "
00698 "VALUES (:LOC, :ITEM, :SCREENID, :SRCID);";
00699 db2.prepare(query2);
00700 QDictIterator<TypeListInfo> it(si->types);
00701 TypeListInfo *ti;
00702 for (; it.current(); ++it)
00703 {
00704 ti = it.current();
00705 db2.bindValue(":LOC", ti->location);
00706 db2.bindValue(":ITEM", ti->name);
00707 db2.bindValue(":SCREENID", screen_id);
00708 db2.bindValue(":SRCID", ti->src->id);
00709 if (!db2.exec())
00710 {
00711 VERBOSE(VB_IMPORTANT, db2.executedQuery());
00712 VERBOSE(VB_IMPORTANT, db2.lastError().text());
00713 return;
00714 }
00715 }
00716 }
00717 else
00718 {
00719 VERBOSE(VB_IMPORTANT, db.executedQuery());
00720 VERBOSE(VB_IMPORTANT, db.lastError().text());
00721 return;
00722 }
00723
00724 ++an_it;
00725 ++draworder;
00726 }
00727
00728 accept();
00729 }
00730
00731 typedef QMap<DialogCode, QString> CommandMap;
00732
00733 static DialogCode add_button(QStringList &buttons,
00734 CommandMap &commands,
00735 const QString &button_text,
00736 const QString &command)
00737 {
00738 int idx = buttons.size();
00739 buttons += button_text;
00740 commands[(DialogCode)((int)kDialogCodeButton0 + idx)] = command;
00741
00742 return (DialogCode)((int)kDialogCodeButton0 + idx);
00743 }
00744
00745 void ScreenSetup::doListSelect(UIListBtnType *list,
00746 UIListBtnTypeItem *selected)
00747 {
00748 if (!selected)
00749 return;
00750
00751 QString txt = selected->text();
00752 if (list == m_active_list)
00753 {
00754 ScreenListInfo *si = (ScreenListInfo *) selected->getData();
00755 QStringList buttons;
00756 CommandMap commands;
00757
00758 if (!si->multiLoc)
00759 add_button(buttons, commands, tr("Change Location"), "change_loc");
00760
00761 if (si->hasUnits)
00762 add_button(buttons, commands, tr("Change Units"), "change_units");
00763
00764 add_button(buttons, commands, tr("Move Up"), "move_up");
00765 add_button(buttons, commands, tr("Move Down"), "move_down");
00766 add_button(buttons, commands, tr("Remove"), "remove");
00767
00768 DialogCode cancelbtn =
00769 add_button(buttons, commands, tr("Cancel"), "cancel");
00770 commands[kDialogCodeRejected] = "cancel";
00771
00772 DialogCode res = MythPopupBox::ShowButtonPopup(
00773 gContext->GetMainWindow(), "Manipulate Screen",
00774 tr("Action to take on screen ") + selected->text(),
00775 buttons, cancelbtn);
00776
00777 QString cmd = commands[res];
00778 if (cmd == "change_loc")
00779 {
00780 doLocationDialog(si, true);
00781 }
00782 else if (cmd == "change_units")
00783 {
00784 showUnitsPopup(selected->text(),
00785 (ScreenListInfo *) selected->getData());
00786 updateHelpText();
00787 }
00788 else if (cmd == "move_up")
00789 {
00790 list->MoveItemUpDown(selected, true);
00791 }
00792 else if (cmd == "move_down")
00793 {
00794 list->MoveItemUpDown(selected, false);
00795 }
00796 else if (cmd == "remove")
00797 {
00798 deleteScreen(list);
00799 }
00800 }
00801 else if (list == m_inactive_list)
00802 {
00803 ScreenListInfo *si = (ScreenListInfo *) selected->getData();
00804 QStringList type_strs;
00805 QDict<TypeListInfo> types;
00806 QDictIterator<TypeListInfo> it(si->types);
00807 for (; it.current(); ++it)
00808 {
00809 TypeListInfo *newti = new TypeListInfo(*it.current());
00810 types.insert(it.currentKey(), newti);
00811 type_strs << it.currentKey();
00812 }
00813 bool hasUnits = si->hasUnits;
00814 bool multiLoc = si->multiLoc;
00815
00816 QPtrList<ScriptInfo> tmp;
00817 if (m_src_man->findPossibleSources(type_strs, tmp))
00818 {
00819 ScreenListInfo *newsi = new ScreenListInfo(*si);
00820
00821 newsi->types.setAutoDelete(true);
00822
00823 if (!list->GetCount())
00824 {
00825 list->allowFocus(false);
00826 nextPrevWidgetFocus(true);
00827 }
00828 if (hasUnits)
00829 showUnitsPopup(selected->text(), newsi);
00830
00831 if (!doLocationDialog(newsi, true))
00832 return;
00833
00834 UIListBtnTypeItem *itm = new UIListBtnTypeItem(m_active_list, txt);
00835 itm->setDrawArrow(multiLoc);
00836 itm->setData(newsi);
00837 if (m_active_list->GetCount())
00838 m_active_list->allowFocus(true);
00839 }
00840 else
00841 {
00842 MythPopupBox::showOkPopup(gContext->GetMainWindow(),
00843 "Add Screen Error",
00844 tr("Screen cannot be used, not all required data "
00845 "is supplied by existing sources"));
00846 }
00847 }
00848
00849
00850
00851
00852 }
00853
00854 bool ScreenSetup::doLocationDialog(ScreenListInfo *si, bool alltypes)
00855 {
00856
00857
00858
00859
00860 QStringList types;
00861 QPtrList<TypeListInfo> infos;
00862 if (alltypes)
00863 {
00864 QDictIterator<TypeListInfo> it(si->types);
00865 for (; it.current(); ++it)
00866 {
00867 TypeListInfo *ti = it.current();
00868 infos.append(ti);
00869 types << ti->name;
00870 }
00871 }
00872
00873
00874
00875
00876
00877
00878
00879 QString loc;
00880 ScriptInfo *src = 0;
00881 if (showLocationPopup(types, loc, src))
00882 {
00883 for (TypeListInfo *ti = infos.first(); ti; ti = infos.next())
00884 {
00885 ti->location = loc;
00886 ti->src = src;
00887 }
00888 updateHelpText();
00889
00890 return true;
00891 }
00892 else
00893 return false;
00894 }
00895
00896 void ScreenSetup::activeListItemSelected(UIListBtnTypeItem *itm)
00897 {
00898 if (!itm)
00899 itm = m_active_list->GetItemCurrent();
00900 if (!itm)
00901 return;
00902
00903 ScreenListInfo *si = (ScreenListInfo *) itm->getData();
00904 if (!si)
00905 return;
00906
00907 QDict<TypeListInfo> types = si->types;
00908
00909
00910 if (si->multiLoc)
00911 {
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923 }
00924 else
00925 {
00926
00927
00928
00929 }
00930 updateForeground();
00931 }
00932
00933 bool ScreenSetup::showUnitsPopup(const QString &name, ScreenListInfo *si)
00934 {
00935 if (!si) return false;
00936
00937 units_t *units = &si->units;
00938 QStringList unitsBtns;
00939 unitsBtns << tr("English Units") << tr("SI Units");
00940 DialogCode ret = MythPopupBox::ShowButtonPopup(
00941 gContext->GetMainWindow(), "Change Units",
00942 tr("Select units for screen ") + name, unitsBtns,
00943 *units == ENG_UNITS ? kDialogCodeButton0 : kDialogCodeButton1);
00944
00945 switch (ret)
00946 {
00947 case kDialogCodeButton0:
00948 *units = ENG_UNITS;
00949 break;
00950 case kDialogCodeButton1:
00951 *units = SI_UNITS;
00952 break;
00953 default:
00954 return false;
00955 }
00956 return true;
00957 }
00958
00959 bool ScreenSetup::showLocationPopup(QStringList types, QString &loc,
00960 ScriptInfo *&src)
00961 {
00962 LocationDialog dlg(gContext->GetMainWindow(), types, m_src_man);
00963 if (dlg.exec() == QDialog::Accepted)
00964 {
00965 loc = dlg.getLocation();
00966 src = dlg.getSource();
00967 return true;
00968 }
00969
00970 loc = QString();
00971 src = NULL;
00972 return false;
00973 }
00974
00975 void ScreenSetup::cursorUp(UIType *curr)
00976 {
00977 UIListBtnType *list = dynamic_cast<UIListBtnType *>(curr);
00978 if (list)
00979 {
00980 int index = list->GetItemPos(list->GetItemCurrent());
00981 if (index > 0)
00982 {
00983 list->MoveUp(UIListBtnType::MoveItem);
00984 updateForeground();
00985 }
00986 else
00987 nextPrevWidgetFocus(false);
00988 }
00989 else
00990 nextPrevWidgetFocus(false);
00991 }
00992
00993 void ScreenSetup::cursorDown(UIType *curr)
00994 {
00995 UIListBtnType *list = dynamic_cast<UIListBtnType *>(curr);
00996 if (list)
00997 {
00998 int index = list->GetItemPos(list->GetItemCurrent());
00999 if (index != list->GetCount() - 1)
01000 {
01001 list->MoveDown(UIListBtnType::MoveItem);
01002 updateForeground();
01003 }
01004 else
01005 nextPrevWidgetFocus(true);
01006 }
01007 else
01008 nextPrevWidgetFocus(true);
01009 }
01010
01011 void ScreenSetup::deleteScreen(UIListBtnType *list)
01012 {
01013
01014 if (list->GetItemCurrent())
01015 delete list->GetItemCurrent();
01016
01017 if (!list->GetCount())
01018 {
01019 nextPrevWidgetFocus(false);
01020 list->allowFocus(false);
01021
01022
01023
01024
01025 }
01026
01027 }
01028
01029 void ScreenSetup::cursorSelect(UIType *curr)
01030 {
01031 UIListBtnType *list = dynamic_cast<UIListBtnType *>(curr);
01032 if (list)
01033 {
01034 doListSelect(list, list->GetItemCurrent());
01035 updateForeground();
01036 }
01037
01038 if (curr == m_finish_btn)
01039 m_finish_btn->push();
01040 }
01041
01042 void ScreenSetup::cursorRight(UIType *curr)
01043 {
01044 if (curr == m_active_list)
01045 {
01046 UIListBtnTypeItem *itm = m_active_list->GetItemCurrent();
01047 if (((ScreenListInfo *) itm->getData())->multiLoc)
01048 {
01049 buildFocusList();
01050 nextPrevWidgetFocus(true);
01051 }
01052 }
01053 }
01054
01055 void ScreenSetup::cursorLeft(UIType *curr)
01056 {
01057
01058
01059
01060
01061 }
01062
01064
01065 SourceSetup::SourceSetup(MythMainWindow *parent) :
01066 MythThemedDialog(parent, "source-setup", "weather-", "Source Setup")
01067 {
01068 wireUI();
01069
01070 buildFocusList();
01071 assignFirstFocus();
01072 }
01073
01074 SourceSetup::~SourceSetup()
01075 {
01076 delete m_update_spinbox;
01077 delete m_retrieve_spinbox;
01078 QPtrListIterator<UIListBtnTypeItem> it = m_src_list->GetIterator();
01079 UIListBtnTypeItem *itm;
01080 while ((itm = it.current()))
01081 {
01082 if (itm->getData())
01083 delete (SourceListInfo *) itm->getData();
01084 ++it;
01085 }
01086 }
01087
01088 void SourceSetup::wireUI()
01089 {
01090 m_src_list = getUIListBtnType("srclist");
01091 if (!m_src_list)
01092 {
01093 VERBOSE(VB_IMPORTANT, "error loading srclist");
01094 }
01095 else
01096 {
01097 connect(m_src_list, SIGNAL(itemSelected(UIListBtnTypeItem *)),
01098 this, SLOT(sourceListItemSelected(UIListBtnTypeItem *)));
01099 connect(m_src_list, SIGNAL(takingFocus()),
01100 this, SLOT(sourceListItemSelected()));
01101 }
01102
01103 UIBlackHoleType *blckhl = getUIBlackHoleType("update_spinbox");
01104 if (!blckhl)
01105 {
01106 VERBOSE(VB_IMPORTANT, "error loading update_spinbox");
01107 }
01108 else
01109 {
01110 blckhl->allowFocus(true);
01111 m_update_spinbox = new WeatherSpinBox(this);
01112 m_update_spinbox->setRange(10, 600);
01113 m_update_spinbox->setLineStep(1);
01114 m_update_spinbox->setFont(gContext->GetMediumFont());
01115 m_update_spinbox->setFocusPolicy(QWidget::NoFocus);
01116 m_update_spinbox->setGeometry(blckhl->getScreenArea());
01117 connect(blckhl, SIGNAL(takingFocus()), m_update_spinbox,
01118 SLOT(setFocus()));
01119 connect(blckhl, SIGNAL(loosingFocus()), m_update_spinbox,
01120 SLOT(clearFocus()));
01121 connect(blckhl, SIGNAL(loosingFocus()), this,
01122 SLOT(updateSpinboxUpdate()));
01123 }
01124
01125 blckhl = getUIBlackHoleType("retrieve_spinbox");
01126 if (!blckhl)
01127 {
01128 VERBOSE(VB_IMPORTANT, "error loading retrieve_spinbox");
01129 }
01130 else
01131 {
01132 blckhl->allowFocus(true);
01133 m_retrieve_spinbox = new WeatherSpinBox(this);
01134 m_retrieve_spinbox->setRange(10, 1000);
01135 m_retrieve_spinbox->setLineStep(1);
01136 m_retrieve_spinbox->setFont(gContext->GetMediumFont());
01137 m_retrieve_spinbox->setFocusPolicy(QWidget::NoFocus);
01138 m_retrieve_spinbox->setGeometry(blckhl->getScreenArea());
01139
01140 connect(blckhl, SIGNAL(takingFocus()), m_retrieve_spinbox,
01141 SLOT(setFocus()));
01142 connect(blckhl, SIGNAL(loosingFocus()), m_retrieve_spinbox,
01143 SLOT(clearFocus()));
01144 connect(blckhl, SIGNAL(loosingFocus()), this,
01145 SLOT(retrieveSpinboxUpdate()));
01146 }
01147
01148 m_finish_btn = getUITextButtonType("finishbutton");
01149 if (m_finish_btn)
01150 {
01151 m_finish_btn->setText(tr("Finish"));
01152 connect(m_finish_btn, SIGNAL(pushed()), this, SLOT(saveData()));
01153 }
01154 }
01155
01156 bool SourceSetup::loadData()
01157 {
01158 MSqlQuery db(MSqlQuery::InitCon());
01159 QString query =
01160 "SELECT DISTINCT sourceid, source_name, update_timeout, retrieve_timeout, "
01161 "author, email, version FROM weathersourcesettings, weatherdatalayout "
01162 "WHERE weathersourcesettings.sourceid = weatherdatalayout.weathersourcesettings_sourceid "
01163 "AND hostname=:HOST;";
01164 db.prepare(query);
01165 db.bindValue(":HOST", gContext->GetHostName());
01166 if (!db.exec())
01167 {
01168 VERBOSE(VB_IMPORTANT, db.lastError().text());
01169 return false;
01170 }
01171
01172 if (!db.size())
01173 {
01174 return false;
01175 }
01176
01177 while (db.next())
01178 {
01179 SourceListInfo *si = new SourceListInfo;
01180 si->id = db.value(0).toUInt();
01181 si->name = db.value(1).toString();
01182 si->update_timeout = db.value(2).toUInt() / 60;
01183 si->retrieve_timeout = db.value(3).toUInt();
01184 si->author = db.value(4).toString();
01185 si->email = db.value(5).toString();
01186 si->version = db.value(6).toString();
01187
01188 UIListBtnTypeItem *item =
01189 new UIListBtnTypeItem(m_src_list, tr(si->name));
01190 item->setData(si);
01191 }
01192
01193 m_src_list->SetItemCurrent(0);
01194
01195 return true;
01196 }
01197
01198 void SourceSetup::saveData()
01199 {
01200 SourceListInfo *si =
01201 (SourceListInfo *) m_src_list->GetItemCurrent()->getData();
01202 si->retrieve_timeout = m_update_spinbox->value();
01203 si->update_timeout = m_retrieve_spinbox->value();
01204
01205 MSqlQuery db(MSqlQuery::InitCon());
01206 QString query = "UPDATE weathersourcesettings "
01207 "SET update_timeout = :UPDATE, retrieve_timeout = :RETRIEVE "
01208 "WHERE sourceid = :ID;";
01209 db.prepare(query);
01210
01211 QPtrListIterator<UIListBtnTypeItem> an_it = m_src_list->GetIterator();
01212
01213 while (an_it)
01214 {
01215 si = (SourceListInfo *) (*an_it)->getData();
01216 db.bindValue(":ID", si->id);
01217 db.bindValue(":UPDATE", si->update_timeout * 60);
01218 db.bindValue(":RETRIEVE", si->retrieve_timeout);
01219 if (!db.exec())
01220 {
01221 VERBOSE(VB_IMPORTANT, db.lastError().text());
01222 return;
01223 }
01224
01225 ++an_it;
01226 }
01227
01228 accept();
01229 }
01230
01231 void SourceSetup::updateSpinboxUpdate()
01232 {
01233 SourceListInfo *si =
01234 (SourceListInfo *) m_src_list->GetItemCurrent()->getData();
01235 si->retrieve_timeout = m_update_spinbox->value();
01236 }
01237
01238 void SourceSetup::retrieveSpinboxUpdate()
01239 {
01240 SourceListInfo *si =
01241 (SourceListInfo *) m_src_list->GetItemCurrent()->getData();
01242 si->update_timeout = m_retrieve_spinbox->value();
01243 }
01244
01245 void SourceSetup::keyPressEvent(QKeyEvent *e)
01246 {
01247 QStringList actions;
01248 gContext->GetMainWindow()->TranslateKeyPress("Weather", e, actions);
01249 UIType *curr = getCurrentFocusWidget();
01250 bool handled = false;
01251
01252 for (uint i = 0; i < actions.size() && !handled; ++i)
01253 {
01254 handled = true;
01255 QString action = actions[i];
01256 if (action == "DOWN" )
01257 {
01258 UIListBtnType *list;
01259 if (curr && (list = dynamic_cast<UIListBtnType *>(curr)))
01260 {
01261 int index = list->GetItemPos(list->GetItemCurrent());
01262 if (index != list->GetCount() - 1)
01263 {
01264 list->MoveDown(UIListBtnType::MoveItem);
01265 updateForeground();
01266 }
01267 }
01268 else
01269 nextPrevWidgetFocus(true);
01270 }
01271 else if (action == "UP")
01272 {
01273 UIListBtnType *list;
01274 if (curr && (list = dynamic_cast<UIListBtnType *>(curr)))
01275 {
01276 int index = list->GetItemPos(list->GetItemCurrent());
01277 if (index > 0)
01278 {
01279 list->MoveUp(UIListBtnType::MoveItem);
01280 updateForeground();
01281 }
01282 }
01283 else
01284 nextPrevWidgetFocus(false);
01285 }
01286 else if (action == "SELECT")
01287 {
01288 if (curr == m_finish_btn)
01289 m_finish_btn->push();
01290 }
01291 else if (action == "RIGHT")
01292 {
01293 if (curr == m_src_list)
01294 {
01295 nextPrevWidgetFocus(true);
01296 }
01297 }
01298 else if (action == "LEFT")
01299 {
01300 if (curr == m_src_list)
01301 {
01302 nextPrevWidgetFocus(false);
01303 }
01304 }
01305 else
01306 handled = false;
01307 }
01308 if (!handled)
01309 MythDialog::keyPressEvent(e);
01310 }
01311
01312 void SourceSetup::sourceListItemSelected(UIListBtnTypeItem *itm)
01313 {
01314 if (!itm)
01315 itm = m_src_list->GetItemCurrent();
01316
01317 if (!itm)
01318 return;
01319
01320 SourceListInfo *si = (SourceListInfo *) itm->getData();
01321 if (!si)
01322 return;
01323
01324 m_update_spinbox->setValue(si->retrieve_timeout);
01325 m_retrieve_spinbox->setValue(si->update_timeout);
01326 QString txt = tr("Author: ");
01327 txt += si->author;
01328 txt += "\n" + tr("Email: ") + si->email;
01329 txt += "\n" + tr("Version: ") + si->version;
01330 getUITextType("srcinfo")->SetText(txt);
01331 }
01332
01334
01335 LocationDialog::LocationDialog(MythMainWindow *parent, QStringList types,
01336 SourceManager *srcman) :
01337 MythThemedDialog(parent, "setup-location", "weather-", "Location Selection")
01338 {
01339
01340 m_types = types;
01341 m_src_man = srcman;
01342
01343 wireUI();
01344
01345 assignFirstFocus();
01346 }
01347
01348 void LocationDialog::wireUI()
01349 {
01350 m_edit = getUIRemoteEditType("loc-edit");
01351 m_edit->createEdit(this);
01352 m_list = getUIListBtnType("results");
01353 m_list->allowFocus(true);
01354 connect(m_list, SIGNAL(itemSelected(UIListBtnTypeItem *)),
01355 this, SLOT(itemSelected(UIListBtnTypeItem *)));
01356 m_btn = getUITextButtonType("searchbtn");
01357 connect(m_btn, SIGNAL(pushed()), this, SLOT(doSearch()));
01358 m_btn->setText(tr("Search"));
01359 }
01360
01361 void LocationDialog::doSearch()
01362 {
01363 QMap<ScriptInfo *, QStringList> result_cache;
01364 int numresults = 0;
01365 m_list->Reset();
01366 UITextType *resultslbl = getUITextType("numresults");
01367
01368 QString searchingresults = tr("Searching ... Results: %1");
01369
01370 resultslbl->SetText(searchingresults.arg(numresults));
01371 qApp->processEvents();
01372
01373 QPtrList<ScriptInfo> sources;
01374
01375 m_src_man->findPossibleSources(m_types, sources);
01376 QString search = m_edit->getText();
01377 ScriptInfo *si;
01378 for (si = sources.first(); si; si = sources.next())
01379 {
01380 if (!result_cache.contains(si))
01381 {
01382 QStringList results = m_src_man->getLocationList(si, search);
01383 result_cache[si] = results;
01384 numresults += results.size();
01385 resultslbl->SetText(searchingresults.arg(numresults));
01386 qApp->processEvents();
01387 }
01388 }
01389
01390 for (uint i = 0; i < result_cache.keys().size(); ++i)
01391 {
01392 si = result_cache.keys()[i];
01393 QStringList results = result_cache[si];
01394 QString name = si->name;
01395 for (uint ii = 0; ii < results.size(); ++ii)
01396 {
01397 QStringList tmp = QStringList::split("::", results[ii]);
01398 UIListBtnTypeItem *itm = new UIListBtnTypeItem(m_list, tmp[1]);
01399 ResultListInfo *ri = new ResultListInfo;
01400 ri->idstr = tmp[0];
01401 ri->src = si;
01402 itm->setData(ri);
01403 }
01404 }
01405 resultslbl->SetText(tr("Search Complete. Results: %1").arg(numresults));
01406 if (numresults)
01407 {
01408 m_list->allowFocus(true);
01409 nextPrevWidgetFocus(true);
01410 itemSelected(m_list->GetItemAt(0));
01411 }
01412 update();
01413 }
01414
01415 void LocationDialog::keyPressEvent(QKeyEvent *e)
01416 {
01417 QStringList actions;
01418 gContext->GetMainWindow()->TranslateKeyPress("Weather", e, actions);
01419 UIType *curr = getCurrentFocusWidget();
01420 bool handled = false;
01421
01422 for (uint i = 0; i < actions.size() && !handled; ++i)
01423 {
01424 handled = true;
01425 QString action = actions[i];
01426 if (action == "DOWN")
01427 {
01428 if (curr == m_list)
01429 {
01430 if (m_list->GetItemPos(m_list->GetItemCurrent()) !=
01431 m_list->GetCount() - 1)
01432 m_list->MoveDown(UIListBtnType::MoveItem);
01433 else
01434 nextPrevWidgetFocus(true);
01435 updateForeground(m_list->getScreenArea());
01436 }
01437 else
01438 nextPrevWidgetFocus(true);
01439 }
01440 else if (action == "UP")
01441 {
01442 if (curr == m_list)
01443 {
01444 if (m_list->GetItemPos(m_list->GetItemCurrent()) > 0)
01445 m_list->MoveUp(UIListBtnType::MoveItem);
01446 else nextPrevWidgetFocus(false);
01447 updateForeground(m_list->getScreenArea());
01448 }
01449 else
01450 nextPrevWidgetFocus(false);
01451 }
01452 else if (action == "PAGEUP" && curr == m_list)
01453 {
01454 m_list->MoveUp(UIListBtnType::MovePage);
01455 updateForeground(m_list->getScreenArea());
01456 }
01457 else if (action == "PAGEDOWN" && curr == m_list)
01458 {
01459 m_list->MoveDown(UIListBtnType::MovePage);
01460 updateForeground(m_list->getScreenArea());
01461 }
01462 else if (action == "PREVVIEW" && curr == m_list)
01463 {
01464 m_list->MoveUp(UIListBtnType::MoveMax);
01465 updateForeground(m_list->getScreenArea());
01466 }
01467 else if (action == "NEXTVIEW" && curr == m_list)
01468 {
01469 m_list->MoveDown(UIListBtnType::MoveMax);
01470 updateForeground(m_list->getScreenArea());
01471 }
01472 else if (action == "SEARCH" && curr == m_list)
01473 {
01474 m_list->incSearchStart();
01475 updateForeground(m_list->getScreenArea());
01476 }
01477 else if (action == "NEXTSEARCH" && curr == m_list)
01478 {
01479 m_list->incSearchNext();
01480 updateForeground(m_list->getScreenArea());
01481 }
01482 else if (action == "SELECT")
01483 {
01484 if (curr == m_btn)
01485 m_btn->push();
01486 else if (curr == m_list)
01487 accept();
01488 }
01489 else
01490 handled = false;
01491 }
01492
01493 if (!handled)
01494 MythDialog::keyPressEvent(e);
01495 }
01496
01497 void LocationDialog::itemSelected(UIListBtnTypeItem *itm)
01498 {
01499 UITextType *txt = getUITextType("source");
01500 ResultListInfo *ri = (ResultListInfo *)itm->getData();
01501 if (ri)
01502 txt->SetText(tr("Source: %1").arg(ri->src->name));
01503 }
01504
01505 QString LocationDialog::getLocation()
01506 {
01507 UIListBtnTypeItem *itm = m_list->GetItemCurrent();
01508 if (!itm)
01509 return NULL;
01510
01511 ResultListInfo *ri = (ResultListInfo *) itm->getData();
01512
01513 if (!ri)
01514 return NULL;
01515
01516 return ri->idstr;
01517 }
01518
01519 ScriptInfo *LocationDialog::getSource()
01520 {
01521 UIListBtnTypeItem *itm = m_list->GetItemCurrent();
01522 if (!itm)
01523 return NULL;
01524
01525 ResultListInfo *ri = (ResultListInfo *) itm->getData();
01526
01527 if (!ri)
01528 return NULL;
01529
01530 return ri->src;
01531 }