|
MythTV
0.26-pre
|
00001 #include <iostream> 00002 #include <set> 00003 #include <map> 00004 00005 // qt 00006 #include <QString> 00007 #include <QMetaType> 00008 #include <QDateTime> 00009 #include <QFileInfo> 00010 #include <QImageReader> 00011 00012 // myth 00013 #include <mythdb.h> 00014 #include <mythcontext.h> 00015 #include <mythdbcon.h> 00016 #include <mythdirs.h> 00017 #include <mythsystem.h> 00018 #include <mythprogressdialog.h> 00019 #include <storagegroup.h> 00020 #include <remotefile.h> 00021 #include <netgrabbermanager.h> 00022 #include <netutils.h> 00023 #include <metadata/videoutils.h> 00024 #include <rssparse.h> 00025 #include <mythcoreutil.h> 00026 00027 #include "netsearch.h" 00028 #include "netcommon.h" 00029 #include "rsseditor.h" 00030 #include "searcheditor.h" 00031 00032 using namespace std; 00033 00034 // --------------------------------------------------- 00035 00036 NetSearch::NetSearch(MythScreenStack *parent, const char *name) 00037 : MythScreenType(parent, name), 00038 m_searchResultList(NULL), m_siteList(NULL), 00039 m_search(NULL), m_thumbImage(NULL), 00040 m_downloadable(NULL), m_progress(NULL), 00041 m_busyPopup(NULL), m_okPopup(NULL), 00042 m_popupStack(), m_progressDialog(NULL), 00043 m_netSearch(NULL), m_reply(NULL), 00044 m_currentSearch(QString()), m_currentGrabber(0), 00045 m_currentCmd(QString()), m_downloadFile(QString()), 00046 m_pagenum(0) 00047 { 00048 m_mythXML = GetMythXMLURL(); 00049 m_playing = false; 00050 m_download = new MythDownloadManager(); 00051 m_imageDownload = new MetadataImageDownload(this); 00052 m_popupStack = GetMythMainWindow()->GetStack("popup stack"); 00053 m_menuPopup = NULL; 00054 gCoreContext->addListener(this); 00055 } 00056 00057 bool NetSearch::Create() 00058 { 00059 bool foundtheme = false; 00060 00061 m_type = static_cast<DialogType>(gCoreContext->GetNumSetting( 00062 "mythnetvision.ViewMode", DLG_SEARCH)); 00063 00064 // Load the theme for this screen 00065 foundtheme = LoadWindowFromXML("netvision-ui.xml", "netsearch", this); 00066 00067 if (!foundtheme) 00068 return false; 00069 00070 m_siteList = dynamic_cast<MythUIButtonList *> (GetChild("sites")); 00071 m_searchResultList = dynamic_cast<MythUIButtonList *> (GetChild("results")); 00072 00073 m_pageText = dynamic_cast<MythUIText *> (GetChild("page")); 00074 m_noSites = dynamic_cast<MythUIText *> (GetChild("nosites")); 00075 00076 m_thumbImage = dynamic_cast<MythUIImage *> (GetChild("preview")); 00077 00078 m_downloadable = dynamic_cast<MythUIStateType *> (GetChild("downloadable")); 00079 00080 m_progress = dynamic_cast<MythUIProgressBar *> (GetChild("progress")); 00081 00082 if (m_progress) 00083 m_progress->SetVisible(false); 00084 00085 if (m_noSites) 00086 m_noSites->SetVisible(false); 00087 00088 m_search = dynamic_cast<MythUITextEdit *> (GetChild("search")); 00089 m_search->SetMaxLength(255); 00090 00091 if (!m_siteList || !m_searchResultList || !m_search) 00092 { 00093 LOG(VB_GENERAL, LOG_ERR, "Theme is missing critical theme elements."); 00094 return false; 00095 } 00096 00097 // UI Hookups 00098 connect(m_siteList, SIGNAL(itemSelected(MythUIButtonListItem *)), 00099 SLOT(slotItemChanged())); 00100 connect(m_siteList, SIGNAL(itemClicked(MythUIButtonListItem *)), 00101 SLOT(doSearch(void))); 00102 connect(m_searchResultList, SIGNAL(itemClicked(MythUIButtonListItem *)), 00103 SLOT(streamWebVideo(void))); 00104 connect(m_searchResultList, SIGNAL(itemSelected(MythUIButtonListItem *)), 00105 SLOT(slotItemChanged())); 00106 00107 BuildFocusList(); 00108 00109 LoadInBackground(); 00110 00111 return true; 00112 } 00113 00114 void NetSearch::Load() 00115 { 00116 m_grabberList = findAllDBSearchGrabbers(VIDEO_FILE); 00117 } 00118 00119 void NetSearch::Init() 00120 { 00121 loadData(); 00122 } 00123 00124 NetSearch::~NetSearch() 00125 { 00126 cleanCacheDir(); 00127 00128 qDeleteAll(m_grabberList); 00129 m_grabberList.clear(); 00130 00131 if (m_netSearch) 00132 { 00133 m_netSearch->disconnect(); 00134 m_netSearch->deleteLater(); 00135 m_netSearch = NULL; 00136 } 00137 00138 if (m_download) 00139 { 00140 delete m_download; 00141 m_download = NULL; 00142 } 00143 00144 cleanThumbnailCacheDir(); 00145 00146 if (m_imageDownload) 00147 { 00148 delete m_imageDownload; 00149 m_imageDownload = NULL; 00150 } 00151 00152 gCoreContext->removeListener(this); 00153 } 00154 00155 void NetSearch::loadData(void) 00156 { 00157 fillGrabberButtonList(); 00158 00159 if (m_grabberList.count() == 0 && m_noSites) 00160 m_noSites->SetVisible(true); 00161 else if (m_noSites) 00162 m_noSites->SetVisible(false); 00163 00164 if (m_grabberList.isEmpty()) 00165 runSearchEditor(); 00166 } 00167 00168 bool NetSearch::keyPressEvent(QKeyEvent *event) 00169 { 00170 if (GetFocusWidget()->keyPressEvent(event)) 00171 return true; 00172 00173 bool handled = false; 00174 QStringList actions; 00175 handled = GetMythMainWindow()->TranslateKeyPress("Internet Video", event, actions); 00176 00177 for (int i = 0; i < actions.size() && !handled; i++) 00178 { 00179 QString action = actions[i]; 00180 handled = true; 00181 00182 if (action == "MENU") 00183 { 00184 showMenu(); 00185 } 00186 else 00187 handled = false; 00188 } 00189 00190 if (!handled && MythScreenType::keyPressEvent(event)) 00191 handled = true; 00192 00193 return handled; 00194 } 00195 00196 void NetSearch::createBusyDialog(QString title) 00197 { 00198 if (m_busyPopup) 00199 return; 00200 00201 QString message = title; 00202 00203 m_busyPopup = new MythUIBusyDialog(message, m_popupStack, 00204 "mythvideobusydialog"); 00205 00206 if (m_busyPopup->Create()) 00207 m_popupStack->AddScreen(m_busyPopup); 00208 else 00209 { 00210 delete m_busyPopup; 00211 m_busyPopup = NULL; 00212 } 00213 } 00214 00215 void NetSearch::showMenu(void) 00216 { 00217 QString label = tr("Search Options"); 00218 00219 MythDialogBox *menuPopup = new MythDialogBox(label, m_popupStack, 00220 "mythnetvisionmenupopup"); 00221 00222 if (menuPopup->Create()) 00223 { 00224 m_popupStack->AddScreen(menuPopup); 00225 00226 menuPopup->SetReturnEvent(this, "options"); 00227 00228 if (m_searchResultList->GetCount() > 0) 00229 { 00230 ResultItem *item = 00231 qVariantValue<ResultItem *>(m_searchResultList->GetDataValue()); 00232 00233 QString filename; 00234 bool exists = false; 00235 00236 if (item) 00237 { 00238 if (item->GetDownloadable()) 00239 menuPopup->AddButton(tr("Stream Video"), SLOT(streamWebVideo())); 00240 menuPopup->AddButton(tr("Open Web Link"), SLOT(showWebVideo())); 00241 00242 filename = GetDownloadFilename(item->GetTitle(), 00243 item->GetMediaURL()); 00244 00245 if (filename.startsWith("myth://")) 00246 exists = RemoteFile::Exists(filename); 00247 else 00248 exists = QFile::exists(filename); 00249 00250 if (item->GetDownloadable() && 00251 GetFocusWidget() == m_searchResultList) 00252 { 00253 if (exists) 00254 menuPopup->AddButton(tr("Play"), SLOT(doPlayVideo(filename))); 00255 else 00256 menuPopup->AddButton(tr("Save This Video"), SLOT(doDownloadAndPlay())); 00257 } 00258 00259 if (item->GetDownloadable() && 00260 GetFocusWidget() == m_searchResultList && 00261 exists) 00262 { 00263 menuPopup->AddButton(tr("Delete"), SLOT(slotDeleteVideo())); 00264 } 00265 } 00266 00267 if (m_pagenum > 1) 00268 menuPopup->AddButton(tr("Previous Page"), SLOT(getLastResults())); 00269 if (m_searchResultList->GetCount() > 0 && m_pagenum < m_maxpage) 00270 menuPopup->AddButton(tr("Next Page"), SLOT(getMoreResults())); 00271 } 00272 menuPopup->AddButton(tr("Manage Search Scripts"), SLOT(runSearchEditor())); 00273 00274 } 00275 else 00276 { 00277 delete menuPopup; 00278 } 00279 } 00280 00281 void NetSearch::fillGrabberButtonList() 00282 { 00283 m_siteList->Reset(); 00284 00285 for (GrabberScript::scriptList::iterator i = m_grabberList.begin(); 00286 i != m_grabberList.end(); ++i) 00287 { 00288 MythUIButtonListItem *item = 00289 new MythUIButtonListItem(m_siteList, (*i)->GetTitle()); 00290 if (item) 00291 { 00292 item->SetText((*i)->GetTitle(), "title"); 00293 item->SetData((*i)->GetCommandline()); 00294 QString thumb = QString("%1mythnetvision/icons/%2").arg(GetShareDir()) 00295 .arg((*i)->GetImage()); 00296 item->SetImage(thumb); 00297 } 00298 else 00299 delete item; 00300 } 00301 } 00302 00303 void NetSearch::cleanCacheDir() 00304 { 00305 QString cache = QString("%1/MythNetvision/thumbcache") 00306 .arg(GetConfDir()); 00307 QDir cacheDir(cache); 00308 QStringList thumbs = cacheDir.entryList(QDir::Files); 00309 00310 for (QStringList::const_iterator i = thumbs.end() - 1; 00311 i != thumbs.begin() - 1; --i) 00312 { 00313 QString filename = QString("%1/%2").arg(cache).arg(*i); 00314 LOG(VB_GENERAL, LOG_DEBUG, QString("Deleting file %1").arg(filename)); 00315 QFileInfo fi(filename); 00316 QDateTime lastmod = fi.lastModified(); 00317 if (lastmod.addDays(7) < QDateTime::currentDateTime()) 00318 QFile::remove(filename); 00319 } 00320 } 00321 00322 void NetSearch::doSearch() 00323 { 00324 m_searchResultList->Reset(); 00325 00326 int numScripts = m_siteList->GetCount(); 00327 for (int i = 0; i < numScripts; i++) 00328 m_siteList->GetItemAt(i)->SetText("", "count"); 00329 00330 if (m_pageText) 00331 m_pageText->Reset(); 00332 00333 m_pagenum = 1; 00334 m_maxpage = 1; 00335 00336 QString cmd = m_siteList->GetDataValue().toString(); 00337 QString grabber = m_siteList->GetItemCurrent()->GetText(); 00338 QString query = m_search->GetText(); 00339 00340 if (query.isEmpty()) 00341 return; 00342 00343 QFileInfo fi(cmd); 00344 m_currentCmd = fi.fileName(); 00345 m_currentGrabber = m_siteList->GetCurrentPos(); 00346 m_currentSearch = query; 00347 00348 QString title = tr("Searching %1 for \"%2\"...") 00349 .arg(grabber).arg(query); 00350 createBusyDialog(title); 00351 00352 m_netSearch = new QNetworkAccessManager(this); 00353 connect(m_netSearch, SIGNAL(finished(QNetworkReply*)), 00354 SLOT(searchFinished(void))); 00355 00356 QUrl init = GetMythXMLSearch(m_mythXML, m_currentSearch, 00357 m_currentCmd, m_pagenum); 00358 QUrl req(init.toEncoded(), QUrl::TolerantMode); 00359 LOG(VB_GENERAL, LOG_INFO, 00360 QString("Using Search URL %1").arg(req.toString())); 00361 m_reply = m_netSearch->get(QNetworkRequest(req)); 00362 } 00363 00364 void NetSearch::getLastResults() 00365 { 00366 m_searchResultList->Reset(); 00367 00368 m_pagenum--; 00369 00370 QString title = tr("Changing to page %1 of search \"%2\"...") 00371 .arg(QString::number(m_pagenum)) 00372 .arg(m_currentSearch); 00373 createBusyDialog(title); 00374 00375 QUrl req = GetMythXMLSearch(m_mythXML, m_currentSearch, 00376 m_currentCmd, m_pagenum); 00377 m_reply = m_netSearch->get(QNetworkRequest(req)); 00378 } 00379 00380 void NetSearch::getMoreResults() 00381 { 00382 m_searchResultList->Reset(); 00383 00384 m_pagenum++; 00385 00386 QString title = tr("Changing to page %1 of search \"%2\"...") 00387 .arg(QString::number(m_pagenum)) 00388 .arg(m_currentSearch); 00389 createBusyDialog(title); 00390 00391 QUrl req = GetMythXMLSearch(m_mythXML, m_currentSearch, 00392 m_currentCmd, m_pagenum); 00393 m_reply = m_netSearch->get(QNetworkRequest(req)); 00394 } 00395 00396 void NetSearch::searchFinished(void) 00397 { 00398 if (m_busyPopup) 00399 { 00400 m_busyPopup->Close(); 00401 m_busyPopup = NULL; 00402 } 00403 00404 Search *item = new Search(); 00405 QByteArray data = m_reply->readAll(); 00406 item->SetData(data); 00407 00408 item->process(); 00409 00410 uint searchresults = item->numResults(); 00411 uint returned = item->numReturned(); 00412 uint firstitem = item->numIndex(); 00413 00414 if (returned > 0) 00415 m_siteList->GetItemAt(m_currentGrabber)-> 00416 SetText(QString::number( 00417 searchresults), "count"); 00418 else 00419 return; 00420 00421 if (firstitem + returned == searchresults) 00422 m_maxpage = m_pagenum; 00423 else 00424 { 00425 if (((float)searchresults/returned + 0.999) >= 00426 ((int)searchresults/returned + 1)) 00427 m_maxpage = (searchresults/returned + 1); 00428 else 00429 m_maxpage = (searchresults/returned); 00430 } 00431 if (m_pageText && m_maxpage > 0 && m_pagenum > 0 && 00432 returned > 0) 00433 m_pageText->SetText(QString("%1 / %2") 00434 .arg(QString::number(m_pagenum)) 00435 .arg(QString::number(m_maxpage))); 00436 00437 ResultItem::resultList list = item->GetVideoList(); 00438 populateResultList(list); 00439 } 00440 00441 void NetSearch::searchTimeout(Search *) 00442 { 00443 if (m_busyPopup) 00444 { 00445 m_busyPopup->Close(); 00446 m_busyPopup = NULL; 00447 } 00448 00449 QString message = tr("Timed out waiting for query to " 00450 "finish. API might be down."); 00451 00452 // MythConfirmationDialog *okPopup = 00453 if (!m_okPopup) 00454 { 00455 m_okPopup = new MythConfirmationDialog(m_popupStack, 00456 message, false); 00457 00458 if (m_okPopup->Create()) 00459 m_popupStack->AddScreen(m_okPopup); 00460 else 00461 { 00462 delete m_okPopup; 00463 m_okPopup = NULL; 00464 } 00465 } 00466 } 00467 00468 void NetSearch::populateResultList(ResultItem::resultList list) 00469 { 00470 for (ResultItem::resultList::iterator i = list.begin(); 00471 i != list.end(); ++i) 00472 { 00473 QString title = (*i)->GetTitle(); 00474 MythUIButtonListItem *item = 00475 new MythUIButtonListItem( 00476 m_searchResultList, title); 00477 if (item) 00478 { 00479 MetadataMap metadataMap; 00480 (*i)->toMap(metadataMap); 00481 item->SetTextFromMap(metadataMap); 00482 00483 item->SetData(qVariantFromValue(*i)); 00484 00485 if (!(*i)->GetThumbnail().isEmpty()) 00486 { 00487 QString dlfile = (*i)->GetThumbnail(); 00488 00489 if (dlfile.contains("%SHAREDIR%")) 00490 { 00491 dlfile.replace("%SHAREDIR%", GetShareDir()); 00492 item->SetImage(dlfile); 00493 } 00494 else 00495 { 00496 uint pos = m_searchResultList->GetItemPos(item); 00497 00498 m_imageDownload->addThumb((*i)->GetTitle(), 00499 (*i)->GetThumbnail(), 00500 qVariantFromValue<uint>(pos)); 00501 } 00502 } 00503 } 00504 else 00505 delete item; 00506 } 00507 } 00508 00509 void NetSearch::streamWebVideo() 00510 { 00511 ResultItem *item = 00512 qVariantValue<ResultItem *>(m_searchResultList->GetDataValue()); 00513 00514 if (!item) 00515 return; 00516 00517 if (!item->GetDownloadable()) 00518 { 00519 showWebVideo(); 00520 return; 00521 } 00522 00523 GetMythMainWindow()->HandleMedia("Internal", item->GetMediaURL(), 00524 item->GetDescription(), item->GetTitle(), item->GetSubtitle(), QString(), 00525 item->GetSeason(), item->GetEpisode(), QString(), item->GetTime().toInt(), 00526 item->GetDate().toString("yyyy")); 00527 } 00528 00529 void NetSearch::showWebVideo() 00530 { 00531 ResultItem *item = 00532 qVariantValue<ResultItem *>(m_searchResultList->GetDataValue()); 00533 00534 if (!item) 00535 return; 00536 00537 if (!item->GetPlayer().isEmpty()) 00538 { 00539 QString cmd = item->GetPlayer(); 00540 QStringList args = item->GetPlayerArguments(); 00541 if (!args.size()) 00542 { 00543 args += item->GetMediaURL(); 00544 if (!args.size()) 00545 args += item->GetURL(); 00546 } 00547 else 00548 { 00549 args.replaceInStrings("%DIR%", QString(GetConfDir() + "/MythNetvision")); 00550 args.replaceInStrings("%MEDIAURL%", item->GetMediaURL()); 00551 args.replaceInStrings("%URL%", item->GetURL()); 00552 args.replaceInStrings("%TITLE%", item->GetTitle()); 00553 } 00554 QString playerCommand = cmd + " " + args.join(" "); 00555 00556 myth_system(playerCommand); 00557 } 00558 else 00559 { 00560 QString url = item->GetURL(); 00561 00562 LOG(VB_GENERAL, LOG_DEBUG, QString("Web URL = %1").arg(url)); 00563 00564 if (url.isEmpty()) 00565 return; 00566 00567 QString browser = gCoreContext->GetSetting("WebBrowserCommand", ""); 00568 QString zoom = gCoreContext->GetSetting("WebBrowserZoomLevel", "1.0"); 00569 00570 if (browser.isEmpty()) 00571 { 00572 ShowOkPopup(tr("No browser command set! MythNetVision needs MythBrowser " 00573 "installed to display the video.")); 00574 return; 00575 } 00576 00577 if (browser.toLower() == "internal") 00578 { 00579 GetMythMainWindow()->HandleMedia("WebBrowser", url); 00580 return; 00581 } 00582 else 00583 { 00584 QString cmd = browser; 00585 cmd.replace("%ZOOM%", zoom); 00586 cmd.replace("%URL%", url); 00587 cmd.replace('\'', "%27"); 00588 cmd.replace("&","\\&"); 00589 cmd.replace(";","\\;"); 00590 00591 GetMythMainWindow()->AllowInput(false); 00592 myth_system(cmd, kMSDontDisableDrawing); 00593 GetMythMainWindow()->AllowInput(true); 00594 return; 00595 } 00596 } 00597 } 00598 00599 void NetSearch::doPlayVideo(QString filename) 00600 { 00601 ResultItem *item = 00602 qVariantValue<ResultItem *>(m_searchResultList->GetDataValue()); 00603 00604 if (!item) 00605 return; 00606 00607 GetMythMainWindow()->HandleMedia("Internal", filename); 00608 } 00609 00610 void NetSearch::slotDeleteVideo() 00611 { 00612 QString message = tr("Are you sure you want to delete this file?"); 00613 00614 MythConfirmationDialog *confirmdialog = 00615 new MythConfirmationDialog(m_popupStack,message); 00616 00617 if (confirmdialog->Create()) 00618 { 00619 m_popupStack->AddScreen(confirmdialog); 00620 connect(confirmdialog, SIGNAL(haveResult(bool)), 00621 SLOT(doDeleteVideo(bool))); 00622 } 00623 else 00624 delete confirmdialog; 00625 } 00626 00627 void NetSearch::doDeleteVideo(bool remove) 00628 { 00629 if (!remove) 00630 return; 00631 00632 ResultItem *item = 00633 qVariantValue<ResultItem *>(m_searchResultList->GetDataValue()); 00634 00635 if (!item) 00636 return; 00637 00638 QString filename = GetDownloadFilename(item->GetTitle(), 00639 item->GetMediaURL()); 00640 00641 if (filename.startsWith("myth://")) 00642 RemoteFile::DeleteFile(filename); 00643 else 00644 { 00645 QFile file(filename); 00646 file.remove(); 00647 } 00648 } 00649 00650 void NetSearch::runSearchEditor() 00651 { 00652 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack(); 00653 00654 SearchEditor *searchedit = new SearchEditor(mainStack, "mythnetsearchedit"); 00655 00656 if (searchedit->Create()) 00657 { 00658 connect(searchedit, SIGNAL(itemsChanged()), this, 00659 SLOT(doListRefresh())); 00660 00661 mainStack->AddScreen(searchedit); 00662 } 00663 else 00664 { 00665 delete searchedit; 00666 } 00667 } 00668 00669 void NetSearch::doListRefresh() 00670 { 00671 m_grabberList = findAllDBSearchGrabbers(VIDEO_FILE); 00672 if (m_grabberList.isEmpty()) 00673 runSearchEditor(); 00674 00675 loadData(); 00676 } 00677 00678 void NetSearch::doDownloadAndPlay() 00679 { 00680 ResultItem *item = 00681 qVariantValue<ResultItem *>(m_searchResultList->GetDataValue()); 00682 00683 if (!item) 00684 return; 00685 00686 QString baseFilename = GetDownloadFilename(item->GetTitle(), 00687 item->GetMediaURL()); 00688 00689 QString finalFilename = generate_file_url("Default", 00690 gCoreContext->GetMasterHostName(), 00691 baseFilename); 00692 00693 LOG(VB_GENERAL, LOG_INFO, QString("Downloading %1 to %2") 00694 .arg(item->GetMediaURL()) .arg(finalFilename)); 00695 00696 // Does the file already exist? 00697 bool exists = RemoteFile::Exists(finalFilename); 00698 00699 if (exists) 00700 { 00701 doPlayVideo(finalFilename); 00702 return; 00703 } 00704 else 00705 DownloadVideo(item->GetMediaURL(), baseFilename); 00706 } 00707 00708 void NetSearch::DownloadVideo(QString url, QString dest) 00709 { 00710 initProgressDialog(); 00711 m_downloadFile = RemoteDownloadFile(url, "Default", dest); 00712 } 00713 00714 void NetSearch::initProgressDialog() 00715 { 00716 QString message = tr("Downloading Video..."); 00717 m_progressDialog = new MythUIProgressDialog(message, 00718 m_popupStack, "videodownloadprogressdialog"); 00719 00720 if (m_progressDialog->Create()) 00721 { 00722 m_popupStack->AddScreen(m_progressDialog, false); 00723 } 00724 else 00725 { 00726 delete m_progressDialog; 00727 m_progressDialog = NULL; 00728 } 00729 } 00730 00731 void NetSearch::slotItemChanged() 00732 { 00733 ResultItem *item = 00734 qVariantValue<ResultItem *>(m_searchResultList->GetDataValue()); 00735 00736 if (item && GetFocusWidget() == m_searchResultList) 00737 { 00738 MetadataMap metadataMap; 00739 item->toMap(metadataMap); 00740 SetTextFromMap(metadataMap); 00741 00742 if (!item->GetThumbnail().isEmpty() && m_thumbImage) 00743 { 00744 MythUIButtonListItem *btn = m_searchResultList->GetItemCurrent(); 00745 QString filename = btn->GetImage(); 00746 if (filename.contains("%SHAREDIR%")) 00747 filename.replace("%SHAREDIR%", GetShareDir()); 00748 m_thumbImage->Reset(); 00749 00750 if (!filename.isEmpty()) 00751 { 00752 m_thumbImage->SetFilename(filename); 00753 m_thumbImage->Load(); 00754 } 00755 } 00756 00757 if (m_downloadable) 00758 { 00759 if (item->GetDownloadable()) 00760 m_downloadable->DisplayState("yes"); 00761 else 00762 m_downloadable->DisplayState("no"); 00763 } 00764 } 00765 else if (GetFocusWidget() == m_siteList) 00766 { 00767 MythUIButtonListItem *item = m_siteList->GetItemCurrent(); 00768 00769 ResultItem *res = new ResultItem(item->GetText(), QString(), QString(), 00770 QString(), QString(), QString(), QString(), QDateTime(), 00771 0, 0, -1, QString(), QStringList(), QString(), QStringList(), 0, 0, QString(), 00772 0, QStringList(), 0, 0, 0); 00773 00774 MetadataMap metadataMap; 00775 res->toMap(metadataMap); 00776 SetTextFromMap(metadataMap); 00777 00778 if (m_thumbImage) 00779 { 00780 QString filename = item->GetImage(); 00781 m_thumbImage->Reset(); 00782 if (filename.contains("%SHAREDIR%")) 00783 filename.replace("%SHAREDIR%", GetShareDir()); 00784 00785 if (!filename.isEmpty()) 00786 { 00787 m_thumbImage->SetFilename(filename); 00788 m_thumbImage->Load(); 00789 } 00790 } 00791 } 00792 } 00793 00794 void NetSearch::slotDoProgress(qint64 bytesReceived, qint64 bytesTotal) 00795 { 00796 if (m_progress) 00797 { 00798 int total = bytesTotal/100; 00799 int received = bytesReceived/100; 00800 m_progress->SetTotal(total); 00801 m_progress->SetUsed(received); 00802 LOG(VB_GENERAL, LOG_DEBUG, QString("Progress event received: %1/%2") 00803 .arg(received).arg(total)); 00804 } 00805 } 00806 00807 void NetSearch::slotDownloadFinished() 00808 { 00809 if (m_progress) 00810 m_progress->SetVisible(false); 00811 } 00812 00813 void NetSearch::customEvent(QEvent *event) 00814 { 00815 if (event->type() == ThumbnailDLEvent::kEventType) 00816 { 00817 ThumbnailDLEvent *tde = (ThumbnailDLEvent *)event; 00818 00819 if (!tde) 00820 return; 00821 00822 ThumbnailData *data = tde->thumb; 00823 00824 if (!data) 00825 return; 00826 00827 QString title = data->title; 00828 QString file = data->url; 00829 uint pos = qVariantValue<uint>(data->data); 00830 00831 if (file.isEmpty() || !((uint)m_searchResultList->GetCount() >= pos)) 00832 { 00833 delete data; 00834 return; 00835 } 00836 00837 MythUIButtonListItem *item = 00838 m_searchResultList->GetItemAt(pos); 00839 00840 if (item && item->GetText() == title) 00841 { 00842 item->SetImage(file); 00843 } 00844 00845 delete data; 00846 } 00847 else if ((MythEvent::Type)(event->type()) == MythEvent::MythEventMessage) 00848 { 00849 MythEvent *me = (MythEvent *)event; 00850 QStringList tokens = me->Message().split(" ", QString::SkipEmptyParts); 00851 00852 if (tokens.isEmpty()) 00853 return; 00854 00855 if (tokens[0] == "DOWNLOAD_FILE") 00856 { 00857 QStringList args = me->ExtraDataList(); 00858 if ((tokens.size() != 2) || 00859 (args[1] != m_downloadFile)) 00860 return; 00861 00862 if (tokens[1] == "UPDATE") 00863 { 00864 QString message = tr("Downloading Video...\n" 00865 "(%1 of %2 MB)") 00866 .arg(QString::number(args[2].toInt() / 1024.0 / 1024.0, 'f', 2)) 00867 .arg(QString::number(args[3].toInt() / 1024.0 / 1024.0, 'f', 2)); 00868 m_progressDialog->SetMessage(message); 00869 m_progressDialog->SetTotal(args[3].toInt()); 00870 m_progressDialog->SetProgress(args[2].toInt()); 00871 } 00872 else if (tokens[1] == "FINISHED") 00873 { 00874 int fileSize = args[2].toInt(); 00875 int errorCode = args[4].toInt(); 00876 00877 if (m_progressDialog) 00878 m_progressDialog->Close(); 00879 00880 QFileInfo file(m_downloadFile); 00881 if ((m_downloadFile.startsWith("myth://"))) 00882 { 00883 if ((errorCode == 0) && 00884 (fileSize > 0)) 00885 { 00886 doPlayVideo(m_downloadFile); 00887 } 00888 else 00889 { 00890 ShowOkPopup(tr("Error downloading video to backend.")); 00891 } 00892 } 00893 } 00894 } 00895 } 00896 } 00897
1.7.6.1