// Allow user to select a Fanart void CGUIWindowVideoInfo::OnGetFanart() { CFileItemList items; // ensure the fanart is unpacked m_movieItem->GetVideoInfoTag()->m_fanart.Unpack(); // Grab the thumbnails from the web CStdString strPath; CUtil::AddFileToFolder(g_advancedSettings.m_cachePath,"fanartthumbs",strPath); CUtil::WipeDir(strPath); DIRECTORY::CDirectory::Create(strPath); for (unsigned int i = 0; i < m_movieItem->GetVideoInfoTag()->m_fanart.GetNumFanarts(); i++) { CStdString strItemPath; strItemPath.Format("fanart://Remote%i",i); CFileItemPtr item(new CFileItem(strItemPath, false)); item->SetThumbnailImage("http://this.is/a/thumb/from/the/web"); item->SetIconImage("defaultPicture.png"); item->GetVideoInfoTag()->m_fanart = m_movieItem->GetVideoInfoTag()->m_fanart; item->SetProperty("fanart_number", (int)i); item->SetLabel(g_localizeStrings.Get(415)); item->SetProperty("labelonthumbload", g_localizeStrings.Get(20015)); // make sure any previously cached thumb is removed if (CFile::Exists(item->GetCachedPictureThumb())) CFile::Delete(item->GetCachedPictureThumb()); items.Add(item); } CFileItem item(*m_movieItem->GetVideoInfoTag()); CStdString cachedThumb(item.GetCachedFanart()); CStdString strLocal = item.CacheFanart(true); if (!strLocal.IsEmpty()) { CFileItemPtr itemLocal(new CFileItem("fanart://Local",false)); itemLocal->SetThumbnailImage(strLocal); itemLocal->SetLabel(g_localizeStrings.Get(20017)); items.Add(itemLocal); } if (CFile::Exists(cachedThumb)) { CFileItemPtr itemCurrent(new CFileItem("fanart://Current",false)); itemCurrent->SetThumbnailImage(cachedThumb); itemCurrent->SetLabel(g_localizeStrings.Get(20016)); items.Add(itemCurrent); } CFileItemPtr itemNone(new CFileItem("fanart://None", false)); itemNone->SetThumbnailImage("defaultVideoBig.png"); itemNone->SetLabel(g_localizeStrings.Get(20018)); items.Add(itemNone); CStdString result; VECSOURCES sources(g_settings.m_videoSources); g_mediaManager.GetLocalDrives(sources); bool flip=false; if (!CGUIDialogFileBrowser::ShowAndGetImage(items, sources, g_localizeStrings.Get(20019), result, &flip) || result.Equals("fanart://Current")) return; // user cancelled if (CFile::Exists(cachedThumb)) CFile::Delete(cachedThumb); if (result.Equals("fanart://Local")) result = strLocal; if (result.Left(15) == "fanart://Remote") { int iFanart = atoi(result.Mid(15).c_str()); // set new primary fanart, and update our database accordingly m_movieItem->GetVideoInfoTag()->m_fanart.SetPrimaryFanart(iFanart); CVideoDatabase db; if (db.Open()) { db.UpdateFanart(*m_movieItem, GetContentType(m_movieItem.get())); db.Close(); } // download the fullres fanart image CStdString tempFile = "special://temp/fanart_download.jpg"; CAsyncFileCopy downloader; bool succeeded = downloader.Copy(m_movieItem->GetVideoInfoTag()->m_fanart.GetImageURL(), tempFile, g_localizeStrings.Get(13413)); if (succeeded) { CPicture pic; if (flip) pic.ConvertFile(tempFile, cachedThumb,0,1920,-1,100,true); else pic.CacheImage(tempFile, cachedThumb); } CFile::Delete(tempFile); if (!succeeded) return; // failed or cancelled download, so don't do anything } else if (CFile::Exists(result)) { // local file CPicture pic; if (flip) pic.ConvertFile(result, cachedThumb,0,1920,-1,100,true); else pic.CacheImage(result, cachedThumb); } CUtil::DeleteVideoDatabaseDirectoryCache(); // to get them new thumbs to show if (CFile::Exists(cachedThumb)) m_movieItem->SetProperty("fanart_image", cachedThumb); else m_movieItem->ClearProperty("fanart_image"); m_hasUpdatedThumb = true; // Update our screen Update(); }