void MetadataImageDownload::run() { RunProlog(); // Always handle thumbnails first, they're higher priority. ThumbnailData *thumb; while ((thumb = moreThumbs()) != NULL) { QString sFilename = getDownloadFilename(thumb->title, thumb->url); bool exists = QFile::exists(sFilename); if (!exists && !thumb->url.isEmpty()) { if (!GetMythDownloadManager()->download(thumb->url, sFilename)) { LOG(VB_GENERAL, LOG_ERR, QString("MetadataImageDownload: failed to download thumbnail from: %1") .arg(thumb->url)); delete thumb; continue; } } // inform parent we have thumbnail ready for it if (QFile::exists(sFilename) && m_parent) { LOG(VB_GENERAL, LOG_DEBUG, QString("Threaded Image Thumbnail Download: %1") .arg(sFilename)); thumb->url = sFilename; QCoreApplication::postEvent(m_parent, new ThumbnailDLEvent(thumb)); } else delete thumb; } MetadataLookup *lookup; while ((lookup = moreDownloads()) != NULL) { DownloadMap downloads = lookup->GetDownloads(); DownloadMap downloaded; for (DownloadMap::iterator i = downloads.begin(); i != downloads.end(); ++i) { VideoArtworkType type = i.key(); ArtworkInfo info = i.value(); QString filename = getDownloadFilename( type, lookup, info.url ); if (lookup->GetHost().isEmpty()) { QString path = getLocalWritePath(lookup->GetType(), type); QDir dirPath(path); if (!dirPath.exists()) if (!dirPath.mkpath(path)) { LOG(VB_GENERAL, LOG_ERR, QString("Metadata Image Download: Unable to create " "path %1, aborting download.").arg(path)); QCoreApplication::postEvent(m_parent, new ImageDLFailureEvent(lookup)); continue; } QString finalfile = path + "/" + filename; QString oldurl = info.url; info.url = finalfile; if (!QFile::exists(finalfile) || lookup->GetAllowOverwrites()) { QFile dest_file(finalfile); if (dest_file.exists()) { QFileInfo fi(finalfile); GetMythUI()->RemoveFromCacheByFile(fi.fileName()); dest_file.remove(); } LOG(VB_GENERAL, LOG_INFO, QString("Metadata Image Download: %1 ->%2") .arg(oldurl).arg(finalfile)); QByteArray *download = new QByteArray(); GetMythDownloadManager()->download(oldurl, download); QImage testImage; bool didLoad = testImage.loadFromData(*download); if (!didLoad) { LOG(VB_GENERAL, LOG_ERR, QString("Tried to write %1, but it appears to be " "an HTML redirect (filesize %2).") .arg(oldurl).arg(download->size())); delete download; download = NULL; QCoreApplication::postEvent(m_parent, new ImageDLFailureEvent(lookup)); continue; } if (dest_file.open(QIODevice::WriteOnly)) { off_t size = dest_file.write(*download, download->size()); if (size != download->size()) { LOG(VB_GENERAL, LOG_ERR, QString("Image Download: Error Writing Image " "to file: %1").arg(finalfile)); QCoreApplication::postEvent(m_parent, new ImageDLFailureEvent(lookup)); } else downloaded.insert(type, info); } delete download; } else downloaded.insert(type, info); } else { QString path = getStorageGroupURL(type, lookup->GetHost()); QString finalfile = path + filename; QString oldurl = info.url; info.url = finalfile; bool exists = false; bool onMaster = false; QString resolvedFN; if ((lookup->GetHost().toLower() == gCoreContext->GetHostName().toLower()) || (gCoreContext->IsThisHost(lookup->GetHost()))) { StorageGroup sg; resolvedFN = sg.FindFile(filename); exists = QFile::exists(resolvedFN); if (!exists) { resolvedFN = getLocalStorageGroupPath(type, lookup->GetHost()) + "/" + filename; } onMaster = true; } else exists = RemoteFile::Exists(finalfile); if (!exists || lookup->GetAllowOverwrites()) { if (exists && !onMaster) { QFileInfo fi(finalfile); GetMythUI()->RemoveFromCacheByFile(fi.fileName()); RemoteFile::DeleteFile(finalfile); } else if (exists) QFile::remove(resolvedFN); LOG(VB_GENERAL, LOG_INFO, QString("Metadata Image Download: %1 -> %2") .arg(oldurl).arg(finalfile)); QByteArray *download = new QByteArray(); GetMythDownloadManager()->download(oldurl, download); QImage testImage; bool didLoad = testImage.loadFromData(*download); if (!didLoad) { LOG(VB_GENERAL, LOG_ERR, QString("Tried to write %1, but it appears to be " "an HTML redirect or corrupt file " "(filesize %2).") .arg(oldurl).arg(download->size())); delete download; download = NULL; QCoreApplication::postEvent(m_parent, new ImageDLFailureEvent(lookup)); continue; } if (!onMaster) { RemoteFile *outFile = new RemoteFile(finalfile, true); if (!outFile->isOpen()) { LOG(VB_GENERAL, LOG_ERR, QString("Image Download: Failed to open " "remote file (%1) for write. Does " "Storage Group Exist?") .arg(finalfile)); delete outFile; outFile = NULL; QCoreApplication::postEvent(m_parent, new ImageDLFailureEvent(lookup)); } else { off_t written = outFile->Write(*download, download->size()); if (written != download->size()) { LOG(VB_GENERAL, LOG_ERR, QString("Image Download: Error Writing Image " "to file: %1").arg(finalfile)); QCoreApplication::postEvent(m_parent, new ImageDLFailureEvent(lookup)); } else downloaded.insert(type, info); delete outFile; outFile = NULL; } } else { QFile dest_file(resolvedFN); if (dest_file.open(QIODevice::WriteOnly)) { off_t size = dest_file.write(*download, download->size()); if (size != download->size()) { LOG(VB_GENERAL, LOG_ERR, QString("Image Download: Error Writing Image " "to file: %1").arg(finalfile)); QCoreApplication::postEvent(m_parent, new ImageDLFailureEvent(lookup)); } else downloaded.insert(type, info); } } delete download; } else downloaded.insert(type, info); } } lookup->SetDownloads(downloaded); QCoreApplication::postEvent(m_parent, new ImageDLEvent(lookup)); } RunEpilog(); }
void MetadataImageDownload::run() { RunProlog(); // Always handle thumbnails first, they're higher priority. ThumbnailData *thumb; while ((thumb = moreThumbs()) != NULL) { QString sFilename = getDownloadFilename(thumb->title, thumb->url); bool exists = QFile::exists(sFilename); if (!exists && !thumb->url.isEmpty()) { if (!GetMythDownloadManager()->download(thumb->url, sFilename)) { LOG(VB_GENERAL, LOG_ERR, QString("MetadataImageDownload: failed to download thumbnail from: %1") .arg(thumb->url)); delete thumb; continue; } } // inform parent we have thumbnail ready for it if (QFile::exists(sFilename) && m_parent) { LOG(VB_GENERAL, LOG_DEBUG, QString("Threaded Image Thumbnail Download: %1") .arg(sFilename)); thumb->url = sFilename; QCoreApplication::postEvent(m_parent, new ThumbnailDLEvent(thumb)); } else delete thumb; } while (true) { m_mutex.lock(); if (m_downloadList.isEmpty()) { // no more to process, we're done m_mutex.unlock(); break; } // Ref owns the MetadataLookup object for the duration of the loop // and it will be deleted automatically when the loop completes RefCountHandler<MetadataLookup> ref = m_downloadList.takeFirstAndDecr(); m_mutex.unlock(); MetadataLookup *lookup = ref; DownloadMap downloads = lookup->GetDownloads(); DownloadMap downloaded; bool errored = false; for (DownloadMap::iterator i = downloads.begin(); i != downloads.end(); ++i) { VideoArtworkType type = i.key(); ArtworkInfo info = i.value(); QString filename = getDownloadFilename( type, lookup, info.url ); if (lookup->GetHost().isEmpty()) { QString path = getLocalWritePath(lookup->GetType(), type); QDir dirPath(path); if (!dirPath.exists()) { if (!dirPath.mkpath(path)) { LOG(VB_GENERAL, LOG_ERR, QString("Metadata Image Download: Unable to create " "path %1, aborting download.").arg(path)); errored = true; break; } } QString finalfile = path + "/" + filename; QString oldurl = info.url; info.url = finalfile; if (!QFile::exists(finalfile) || lookup->GetAllowOverwrites()) { QFile dest_file(finalfile); if (dest_file.exists()) { QFileInfo fi(finalfile); GetMythUI()->RemoveFromCacheByFile(fi.fileName()); dest_file.remove(); } LOG(VB_GENERAL, LOG_INFO, QString("Metadata Image Download: %1 ->%2") .arg(oldurl).arg(finalfile)); QByteArray download; GetMythDownloadManager()->download(oldurl, &download); QImage testImage; bool didLoad = testImage.loadFromData(download); if (!didLoad) { LOG(VB_GENERAL, LOG_ERR, QString("Tried to write %1, but it appears to be " "an HTML redirect (filesize %2).") .arg(oldurl).arg(download.size())); errored = true; break; } if (dest_file.open(QIODevice::WriteOnly)) { off_t size = dest_file.write(download, download.size()); dest_file.close(); if (size != download.size()) { // File creation failed for some reason, delete it RemoteFile::DeleteFile(finalfile); LOG(VB_GENERAL, LOG_ERR, QString("Image Download: Error Writing Image " "to file: %1").arg(finalfile)); errored = true; break; } } } } else { QString path = getStorageGroupURL(type, lookup->GetHost()); QString finalfile = path + filename; QString oldurl = info.url; info.url = finalfile; bool exists = false; bool onMaster = false; QString resolvedFN; if (gCoreContext->IsMasterBackend() && gCoreContext->IsThisHost(lookup->GetHost())) { StorageGroup sg(getStorageGroupName(type), lookup->GetHost()); resolvedFN = sg.FindFile(filename); exists = !resolvedFN.isEmpty() && QFile::exists(resolvedFN); if (!exists) { resolvedFN = getLocalStorageGroupPath(type, lookup->GetHost()) + "/" + filename; } onMaster = true; } else exists = RemoteFile::Exists(finalfile); if (!exists || lookup->GetAllowOverwrites()) { if (exists && !onMaster) { QFileInfo fi(finalfile); GetMythUI()->RemoveFromCacheByFile(fi.fileName()); RemoteFile::DeleteFile(finalfile); } else if (exists) QFile::remove(resolvedFN); LOG(VB_GENERAL, LOG_INFO, QString("Metadata Image Download: %1 -> %2") .arg(oldurl).arg(finalfile)); QByteArray download; GetMythDownloadManager()->download(oldurl, &download); QImage testImage; bool didLoad = testImage.loadFromData(download); if (!didLoad) { LOG(VB_GENERAL, LOG_ERR, QString("Tried to write %1, but it appears to be " "an HTML redirect or corrupt file " "(filesize %2).") .arg(oldurl).arg(download.size())); errored = true; break; } if (!onMaster) { RemoteFile outFile(finalfile, true); if (!outFile.isOpen()) { LOG(VB_GENERAL, LOG_ERR, QString("Image Download: Failed to open " "remote file (%1) for write. Does " "Storage Group Exist?") .arg(finalfile)); errored = true; break; } off_t written = outFile.Write(download, download.size()); if (written != download.size()) { // File creation failed for some reason, delete it RemoteFile::DeleteFile(finalfile); LOG(VB_GENERAL, LOG_ERR, QString("Image Download: Error Writing Image " "to file: %1").arg(finalfile)); errored = true; break; } } else { QFile dest_file(resolvedFN); if (dest_file.open(QIODevice::WriteOnly)) { off_t size = dest_file.write(download, download.size()); dest_file.close(); if (size != download.size()) { // File creation failed for some reason, delete it RemoteFile::DeleteFile(resolvedFN); LOG(VB_GENERAL, LOG_ERR, QString("Image Download: Error Writing Image " "to file: %1").arg(finalfile)); errored = true; break; } } } } } if (!errored) { // update future Artwork Map with what we've successfully // retrieved (either downloaded or already existing downloaded.insert(type, info); } } if (errored) { QCoreApplication::postEvent(m_parent, new ImageDLFailureEvent(lookup)); errored = false; } lookup->SetDownloads(downloaded); QCoreApplication::postEvent(m_parent, new ImageDLEvent(lookup)); } RunEpilog(); }
bool MetadataResultsDialog::Create() { if (!LoadWindowFromXML("base.xml", "MythMetadataResults", this)) return false; bool err = false; UIUtilE::Assign(this, m_resultsList, "results", &err); if (err) { LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythMetadataResults'"); return false; } for (int i = 0; i != m_results.count(); ++i) { MythUIButtonListItem *button = new MythUIButtonListItem(m_resultsList, m_results[i]->GetTitle()); InfoMap metadataMap; m_results[i]->toMap(metadataMap); QString coverartfile; ArtworkList art = m_results[i]->GetArtwork(kArtworkCoverart); if (art.count() > 0) coverartfile = art.takeFirst().thumbnail; if (coverartfile.isEmpty()) { art = m_results[i]->GetArtwork(kArtworkBanner); if (art.count() > 0) coverartfile = art.takeFirst().thumbnail; } if (coverartfile.isEmpty()) { art = m_results[i]->GetArtwork(kArtworkScreenshot); if (art.count() > 0) coverartfile = art.takeFirst().thumbnail; } QString dlfile = getDownloadFilename(m_results[i]->GetTitle(), coverartfile); if (!coverartfile.isEmpty()) { int pos = m_resultsList->GetItemPos(button); if (QFile::exists(dlfile)) button->SetImage(dlfile); else m_imageDownload->addThumb(m_results[i]->GetTitle(), coverartfile, qVariantFromValue<uint>(pos)); } button->SetTextFromMap(metadataMap); button->SetData(qVariantFromValue<uint>(i)); } connect(m_resultsList, SIGNAL(itemClicked(MythUIButtonListItem *)), SLOT(sendResult(MythUIButtonListItem *))); BuildFocusList(); return true; }
bool ImageSearchResultsDialog::Create() { if (!LoadWindowFromXML("base.xml", "MythArtworkResults", this)) return false; bool err = false; UIUtilE::Assign(this, m_resultsList, "results", &err); if (err) { LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythArtworkResults'"); return false; } for (ArtworkList::const_iterator i = m_list.begin(); i != m_list.end(); ++i) { ArtworkInfo info = (*i); MythUIButtonListItem *button = new MythUIButtonListItem(m_resultsList, QString()); button->SetText(info.label, "label"); button->SetText(info.thumbnail, "thumbnail"); button->SetText(info.url, "url"); QString width = QString::number(info.width); QString height = QString::number(info.height); button->SetText(width, "width"); button->SetText(height, "height"); if (info.width > 0 && info.height > 0) button->SetText(QString("%1x%2").arg(width).arg(height), "resolution"); QString artfile = info.thumbnail; if (artfile.isEmpty()) artfile = info.url; QString dlfile = getDownloadFilename(info.label, artfile); if (!artfile.isEmpty()) { int pos = m_resultsList->GetItemPos(button); if (QFile::exists(dlfile)) button->SetImage(dlfile); else m_imageDownload->addThumb(info.label, artfile, qVariantFromValue<uint>(pos)); } button->SetData(qVariantFromValue<ArtworkInfo>(*i)); } connect(m_resultsList, SIGNAL(itemClicked(MythUIButtonListItem *)), SLOT(sendResult(MythUIButtonListItem *))); BuildFocusList(); return true; }
void MetadataImageDownload::run() { // Always handle thumbnails first, they're higher priority. ThumbnailData *thumb; while ((thumb = moreThumbs()) != NULL) { QString sFilename = getDownloadFilename(thumb->title, thumb->url); bool exists = QFile::exists(sFilename); if (!exists && !thumb->url.isEmpty()) GetMythDownloadManager()->download(thumb->url, sFilename); // inform parent we have thumbnail ready for it if (QFile::exists(sFilename) && m_parent) { VERBOSE(VB_GENERAL|VB_EXTRA, QString("Threaded Image Thumbnail Download: %1") .arg(sFilename)); thumb->url = sFilename; QCoreApplication::postEvent(m_parent, new ThumbnailDLEvent(thumb)); } else delete thumb; } MetadataLookup *lookup; while ((lookup = moreDownloads()) != NULL) { DownloadMap downloads = lookup->GetDownloads(); DownloadMap downloaded; for (DownloadMap::iterator i = downloads.begin(); i != downloads.end(); ++i) { ArtworkType type = i.key(); ArtworkInfo info = i.value(); QString filename = getDownloadFilename( type, lookup, info.url ); if (lookup->GetHost().isEmpty()) { QString path = getLocalWritePath(lookup->GetType(), type); QDir dirPath(path); if (!dirPath.exists()) if (!dirPath.mkpath(path)) { VERBOSE(VB_GENERAL, QString("Metadata Image Download: Unable to create " "path %1, aborting download.").arg(path)); continue; } QString finalfile = path + "/" + filename; QString oldurl = info.url; info.url = finalfile; if (!QFile::exists(finalfile) || lookup->GetAllowOverwrites()) { QFile dest_file(finalfile); if (dest_file.exists()) { QFileInfo fi(finalfile); GetMythUI()->RemoveFromCacheByFile(fi.fileName()); dest_file.remove(); } VERBOSE(VB_GENERAL, QString("Metadata Image Download: %1 ->%2") .arg(oldurl).arg(finalfile)); QByteArray *download = new QByteArray(); GetMythDownloadManager()->download(oldurl, download); QImage testImage; bool didLoad = testImage.loadFromData(*download); if (!didLoad) { VERBOSE(VB_IMPORTANT,QString("Tried to write %1, " "but it appears to be an HTML redirect " "(filesize %2).") .arg(oldurl).arg(download->size())); delete download; download = NULL; continue; } if (dest_file.open(QIODevice::WriteOnly)) { off_t size = dest_file.write(*download, download->size()); if (size != download->size()) { VERBOSE(VB_IMPORTANT, QString("Image Download: Error Writing Image " "to file: %1").arg(finalfile)); } else downloaded.insert(type, info); } delete download; } else downloaded.insert(type, info); } else { QString path = getStorageGroupURL(type, lookup->GetHost()); QString finalfile = path + filename; QString oldurl = info.url; info.url = finalfile; if (!RemoteFile::Exists(finalfile) || lookup->GetAllowOverwrites()) { if (RemoteFile::Exists(finalfile)) { QFileInfo fi(finalfile); GetMythUI()->RemoveFromCacheByFile(fi.fileName()); RemoteFile::DeleteFile(finalfile); } VERBOSE(VB_GENERAL, QString("Metadata Image Download: %1 -> %2") .arg(oldurl).arg(finalfile)); QByteArray *download = new QByteArray(); GetMythDownloadManager()->download(oldurl, download); QImage testImage; bool didLoad = testImage.loadFromData(*download); if (!didLoad) { VERBOSE(VB_IMPORTANT,QString("Tried to write %1, " "but it appears to be an HTML redirect " "or corrupt file (filesize %2).") .arg(oldurl).arg(download->size())); delete download; download = NULL; continue; } RemoteFile *outFile = new RemoteFile(finalfile, true); if (!outFile->isOpen()) { VERBOSE(VB_IMPORTANT, QString("Image Download: Failed to open " "remote file (%1) for write. Does " "Storage Group Exist?") .arg(finalfile)); delete outFile; outFile = NULL; } else { off_t written = outFile->Write(*download, download->size()); if (written != download->size()) { VERBOSE(VB_IMPORTANT, QString("Image Download: Error Writing Image " "to file: %1").arg(finalfile)); } else downloaded.insert(type, info); delete outFile; outFile = NULL; } delete download; } else downloaded.insert(type, info); } } lookup->SetDownloads(downloaded); QCoreApplication::postEvent(m_parent, new ImageDLEvent(lookup)); } }
void NetTree::slotItemChanged() { ResultItem *item; RSSSite *site; if (m_type == DLG_TREE) { item = qVariantValue<ResultItem *>(m_siteMap->GetCurrentNode()->GetData()); site = qVariantValue<RSSSite *>(m_siteMap->GetCurrentNode()->GetData()); } else { MythGenericTree *node = GetNodePtrFromButton(m_siteButtonList->GetItemCurrent()); if (!node) return; item = qVariantValue<ResultItem *>(node->GetData()); site = qVariantValue<RSSSite *>(node->GetData()); } if (item) { MetadataMap metadataMap; item->toMap(metadataMap); SetTextFromMap(metadataMap); if (!item->GetThumbnail().isEmpty() && m_thumbImage) { m_thumbImage->Reset(); QString dlfile = item->GetThumbnail(); if (dlfile.contains("%SHAREDIR%")) { dlfile.replace("%SHAREDIR%", GetShareDir()); m_thumbImage->SetFilename(dlfile); m_thumbImage->Load(); } else { QString sFilename = getDownloadFilename(item->GetTitle(), item->GetThumbnail()); bool exists = QFile::exists(sFilename); if (exists) { m_thumbImage->SetFilename(sFilename); m_thumbImage->Load(); } } } else if (m_thumbImage) m_thumbImage->Reset(); if (m_downloadable) { if (item->GetDownloadable()) m_downloadable->DisplayState("yes"); else m_downloadable->DisplayState("no"); } } else if (site) { ResultItem *res = new ResultItem(site->GetTitle(), QString(), site->GetDescription(), site->GetURL(), site->GetImage(), QString(), site->GetAuthor(), QDateTime(), 0, 0, -1, QString(), QStringList(), QString(), QStringList(), 0, 0, QString(), 0, QStringList(), 0, 0, 0); MetadataMap metadataMap; res->toMap(metadataMap); SetTextFromMap(metadataMap); if (!site->GetImage().isEmpty() && m_thumbImage) { m_thumbImage->SetFilename(site->GetImage()); m_thumbImage->Load(); } else if (m_thumbImage) m_thumbImage->Reset(); if (m_downloadable) { m_downloadable->Reset(); } } else { QString title; if (m_type == DLG_TREE) title = m_siteMap->GetItemCurrent()->GetText(); else title = m_siteButtonList->GetItemCurrent()->GetText(); QString thumb; if (m_type == DLG_TREE) thumb = m_siteMap->GetCurrentNode()-> GetData().toString(); else { MythGenericTree *node = GetNodePtrFromButton(m_siteButtonList->GetItemCurrent()); if (node) thumb = node->GetData().toString(); } ResultItem *res = new ResultItem(title, QString(), QString(), QString(), thumb, QString(), QString(), QDateTime(), 0, 0, -1, QString(), QStringList(), QString(), QStringList(), 0, 0, QString(), 0, QStringList(), 0, 0, 0); MetadataMap metadataMap; res->toMap(metadataMap); SetTextFromMap(metadataMap); if (m_thumbImage) { if (!thumb.startsWith("http://")) { if (thumb.contains("%SHAREDIR%")) thumb.replace("%SHAREDIR%", GetShareDir()); bool exists = QFile::exists(thumb); if (exists) { m_thumbImage->SetFilename(thumb); m_thumbImage->Load(); } else m_thumbImage->Reset(); } else { QString url = thumb; QString title; if (m_type == DLG_TREE) title = m_siteMap->GetItemCurrent()->GetText(); else title = m_siteButtonList->GetItemCurrent()->GetText(); QString sFilename = GetDownloadFilename(title, url); bool exists = QFile::exists(sFilename); if (exists && !url.isEmpty()) { m_thumbImage->SetFilename(sFilename); m_thumbImage->Load(); } else m_thumbImage->Reset(); } } if (m_downloadable) m_downloadable->Reset(); } }
void NetTree::UpdateItem(MythUIButtonListItem *item) { if (!item) return; MythGenericTree *node = GetNodePtrFromButton(item); if (!node) return; RSSSite *site = qVariantValue<RSSSite *>(node->GetData()); ResultItem *video = qVariantValue<ResultItem *>(node->GetData()); int nodeInt = node->getInt(); if (nodeInt == kSubFolder) { item->SetText(QString("%1").arg(node->visibleChildCount()), "childcount"); item->DisplayState("subfolder", "nodetype"); item->SetText(node->getString(), "title"); item->SetText(node->getString()); item->SetImage(node->GetData().toString()); } else if (nodeInt == kUpFolder) { item->DisplayState("upfolder", "nodetype"); item->SetText(node->getString(), "title"); item->SetText(node->getString()); } if (site) { item->SetText(site->GetTitle()); item->SetText(site->GetDescription(), "description"); item->SetText(site->GetURL(), "url"); item->SetImage(site->GetImage()); } else if (video) { item->SetText(video->GetTitle()); MetadataMap metadataMap; video->toMap(metadataMap); item->SetTextFromMap(metadataMap); int pos; if (m_type == DLG_TREE) pos = 0; else pos = m_siteButtonList->GetItemPos(item); QString dlfile = video->GetThumbnail(); if (dlfile.contains("%SHAREDIR%")) dlfile.replace("%SHAREDIR%", GetShareDir()); else dlfile = getDownloadFilename(video->GetTitle(), video->GetThumbnail()); if (QFile::exists(dlfile)) item->SetImage(dlfile); else if (video->GetThumbnail().startsWith("http")) m_imageDownload->addThumb(video->GetTitle(), video->GetThumbnail(), qVariantFromValue<uint>(pos)); } else { item->SetText(node->getString()); if (!node->GetData().toString().isEmpty()) { QString tpath = node->GetData().toString(); if (tpath.startsWith("http://")) { uint pos; if (m_type == DLG_TREE) pos = 0; else pos = m_siteButtonList->GetItemPos(item); QString dlfile = GetThumbnailFilename(tpath, node->getString()); if (QFile::exists(dlfile)) item->SetImage(dlfile); else m_imageDownload->addThumb(node->getString(), tpath, qVariantFromValue<uint>(pos)); } else if (tpath != "0") { QString filename = node->GetData().toString(); if (filename.contains("%SHAREDIR%")) filename.replace("%SHAREDIR%", GetShareDir()); item->SetImage(filename); } } } }