void CGUIDialogExtendedProgressBar::UpdateState(unsigned int currentTime) { string strHeader; string strTitle; float fProgress(-1.0f); { CSingleLock lock(m_critSection); // delete finished items for (int iPtr = m_handles.size() - 1; iPtr >= 0; iPtr--) { if (m_handles.at(iPtr)->IsFinished()) { delete m_handles.at(iPtr); m_handles.erase(m_handles.begin() + iPtr); } } if (!m_handles.size()) { Close(false, 0, true, false); return; } // ensure the current item is in our range if (m_iCurrentItem >= m_handles.size()) m_iCurrentItem = m_handles.size() - 1; // update the current item ptr if (currentTime > m_iLastSwitchTime && currentTime - m_iLastSwitchTime >= ITEM_SWITCH_TIME_MS) { m_iLastSwitchTime = currentTime; // select next item if (++m_iCurrentItem > m_handles.size() - 1) m_iCurrentItem = 0; } CGUIDialogProgressBarHandle *handle = m_handles.at(m_iCurrentItem); if (handle) { strTitle = handle->Text(); strHeader = handle->Title(); fProgress = handle->Percentage(); } } SET_CONTROL_LABEL(CONTROL_LABELHEADER, strHeader); SET_CONTROL_LABEL(CONTROL_LABELTITLE, strTitle); if (fProgress > -1.0f) { SET_CONTROL_VISIBLE(CONTROL_PROGRESS); CGUIProgressControl* pProgressCtrl=(CGUIProgressControl*)GetControl(CONTROL_PROGRESS); if (pProgressCtrl) pProgressCtrl->SetPercentage(fProgress); } }
void DialogProgressBG::update(int percent, const String& heading, const String& message) { DelayedCallGuard dcguard(languageHook); CGUIDialogProgressBarHandle* pHandle = handle; if (pHandle == NULL) throw WindowException("Dialog not created."); if (percent >= 0 && percent <= 100) pHandle->SetPercentage((float)percent); if (!heading.empty()) pHandle->SetTitle(heading); if (!message.empty()) pHandle->SetText(message); }
void DialogProgressBG::update(int percent, const String& heading, const String& message) throw (WindowException) { DelayedCallGuard dcguard(languageHook); CGUIDialogExtendedProgressBar* pDialog = dlg; CGUIDialogProgressBarHandle* pHandle = handle; if (pDialog == NULL) throw WindowException("Error: Window is NULL, this is not possible :-)"); if (percent >= 0 && percent <= 100) pHandle->SetPercentage((float)percent); if (!heading.empty()) pHandle->SetTitle(heading); if (!message.empty()) pHandle->SetText(message); }
void DialogProgressBG::create(const String& heading, const String& message) throw (WindowException) { DelayedCallGuard dcguard(languageHook); CGUIDialogExtendedProgressBar* pDialog = (CGUIDialogExtendedProgressBar*)g_windowManager.GetWindow(WINDOW_DIALOG_EXT_PROGRESS); if (pDialog == NULL) throw WindowException("Error: Window is NULL, this is not possible :-)"); CGUIDialogProgressBarHandle* pHandle = pDialog->GetHandle(heading); dlg = pDialog; handle = pHandle; pHandle->SetTitle(heading); if (!message.empty()) pHandle->SetText(message); }
void CPVRChannelGroup::SearchAndSetChannelIcons(bool bUpdateDb /* = false */) { std::string iconPath = CServiceBroker::GetSettings().GetString(CSettings::SETTING_PVRMENU_ICONPATH); if (iconPath.empty()) return; /* fetch files in icon path for fast lookup */ CFileItemList fileItemList; XFILE::CDirectory::GetDirectory(iconPath, fileItemList, ".jpg|.png|.tbn"); if (fileItemList.IsEmpty()) return; CGUIDialogProgressBarHandle* dlgProgressHandle = g_PVRManager.ShowProgressDialog(g_localizeStrings.Get(19286)); // Searching for channel icons CSingleLock lock(m_critSection); /* create a map for fast lookup of normalized file base name */ std::map<std::string, std::string> fileItemMap; const VECFILEITEMS &items = fileItemList.GetList(); for(VECFILEITEMS::const_iterator it = items.begin(); it != items.end(); ++it) { std::string baseName = URIUtils::GetFileName((*it)->GetPath()); URIUtils::RemoveExtension(baseName); StringUtils::ToLower(baseName); fileItemMap.insert(std::make_pair(baseName, (*it)->GetPath())); } int channelIndex = 0; CPVRChannelPtr channel; for(PVR_CHANNEL_GROUP_MEMBERS::const_iterator it = m_members.begin(); it != m_members.end(); ++it) { channel = it->second.channel; /* update progress dialog */ if (dlgProgressHandle) { dlgProgressHandle->SetProgress(channelIndex++, m_members.size()); dlgProgressHandle->SetText(channel->ChannelName()); } /* skip if an icon is already set and exists */ if (channel->IsIconExists()) continue; /* reset icon before searching for a new one */ channel->SetIconPath(""); std::string strChannelUid = StringUtils::Format("%08d", channel->UniqueID()); std::string strLegalClientChannelName = CUtil::MakeLegalFileName(channel->ClientChannelName()); StringUtils::ToLower(strLegalClientChannelName); std::string strLegalChannelName = CUtil::MakeLegalFileName(channel->ChannelName()); StringUtils::ToLower(strLegalChannelName); std::map<std::string, std::string>::iterator itItem; if ((itItem = fileItemMap.find(strLegalClientChannelName)) != fileItemMap.end() || (itItem = fileItemMap.find(strLegalChannelName)) != fileItemMap.end() || (itItem = fileItemMap.find(strChannelUid)) != fileItemMap.end()) { channel->SetIconPath(itItem->second, g_advancedSettings.m_bPVRAutoScanIconsUserSet); } if (bUpdateDb) channel->Persist(); //! @todo start channel icon scraper here if nothing was found } if (dlgProgressHandle) dlgProgressHandle->MarkFinished(); }
void CEdenVideoArtUpdater::Process() { // grab all movies... CVideoDatabase db; if (!db.Open()) return; CFileItemList items; CGUIDialogExtendedProgressBar* dialog = (CGUIDialogExtendedProgressBar*)g_windowManager.GetWindow(WINDOW_DIALOG_EXT_PROGRESS); CGUIDialogProgressBarHandle *handle = dialog->GetHandle(g_localizeStrings.Get(314)); handle->SetTitle(g_localizeStrings.Get(12349)); // movies db.GetMoviesByWhere("videodb://movies/titles/", CDatabase::Filter(), items); for (int i = 0; i < items.Size(); i++) { CFileItemPtr item = items[i]; handle->SetProgress(i, items.Size()); handle->SetText(StringUtils::Format(g_localizeStrings.Get(12350).c_str(), item->GetLabel().c_str())); string cachedThumb = GetCachedVideoThumb(*item); string cachedFanart = GetCachedFanart(*item); item->SetPath(item->GetVideoInfoTag()->m_strFileNameAndPath); item->GetVideoInfoTag()->m_fanart.Unpack(); item->GetVideoInfoTag()->m_strPictureURL.Parse(); map<string, string> artwork; if (!db.GetArtForItem(item->GetVideoInfoTag()->m_iDbId, item->GetVideoInfoTag()->m_type, artwork) || (artwork.size() == 1 && artwork.find("thumb") != artwork.end())) { CStdString art = CVideoInfoScanner::GetImage(item.get(), true, item->GetVideoInfoTag()->m_basePath != item->GetPath(), "thumb"); std::string type; if (CacheTexture(art, cachedThumb, item->GetLabel(), type)) artwork.insert(make_pair(type, art)); art = CVideoInfoScanner::GetFanart(item.get(), true); if (CacheTexture(art, cachedFanart, item->GetLabel())) artwork.insert(make_pair("fanart", art)); if (artwork.empty()) artwork.insert(make_pair("thumb", "")); db.SetArtForItem(item->GetVideoInfoTag()->m_iDbId, item->GetVideoInfoTag()->m_type, artwork); } } items.Clear(); // music videos db.GetMusicVideosNav("videodb://musicvideos/titles/", items, false); for (int i = 0; i < items.Size(); i++) { CFileItemPtr item = items[i]; handle->SetProgress(i, items.Size()); handle->SetText(StringUtils::Format(g_localizeStrings.Get(12350).c_str(), item->GetLabel().c_str())); string cachedThumb = GetCachedVideoThumb(*item); string cachedFanart = GetCachedFanart(*item); item->SetPath(item->GetVideoInfoTag()->m_strFileNameAndPath); item->GetVideoInfoTag()->m_fanart.Unpack(); item->GetVideoInfoTag()->m_strPictureURL.Parse(); map<string, string> artwork; if (!db.GetArtForItem(item->GetVideoInfoTag()->m_iDbId, item->GetVideoInfoTag()->m_type, artwork) || (artwork.size() == 1 && artwork.find("thumb") != artwork.end())) { CStdString art = CVideoInfoScanner::GetImage(item.get(), true, item->GetVideoInfoTag()->m_basePath != item->GetPath(), "thumb"); std::string type; if (CacheTexture(art, cachedThumb, item->GetLabel(), type)) artwork.insert(make_pair(type, art)); art = CVideoInfoScanner::GetFanart(item.get(), true); if (CacheTexture(art, cachedFanart, item->GetLabel())) artwork.insert(make_pair("fanart", art)); if (artwork.empty()) artwork.insert(make_pair("thumb", "")); db.SetArtForItem(item->GetVideoInfoTag()->m_iDbId, item->GetVideoInfoTag()->m_type, artwork); } } items.Clear(); // tvshows // count the number of episodes db.GetTvShowsNav("videodb://tvshows/titles/", items); for (int i = 0; i < items.Size(); i++) { CFileItemPtr item = items[i]; handle->SetText(StringUtils::Format(g_localizeStrings.Get(12350).c_str(), item->GetLabel().c_str())); string cachedThumb = GetCachedVideoThumb(*item); string cachedFanart = GetCachedFanart(*item); item->SetPath(item->GetVideoInfoTag()->m_strPath); item->GetVideoInfoTag()->m_fanart.Unpack(); item->GetVideoInfoTag()->m_strPictureURL.Parse(); map<string, string> artwork; if (!db.GetArtForItem(item->GetVideoInfoTag()->m_iDbId, item->GetVideoInfoTag()->m_type, artwork) || (artwork.size() == 1 && artwork.find("thumb") != artwork.end())) { CStdString art = CVideoInfoScanner::GetImage(item.get(), true, false, "thumb"); std::string type; if (CacheTexture(art, cachedThumb, item->GetLabel(), type)) artwork.insert(make_pair(type, art)); art = CVideoInfoScanner::GetFanart(item.get(), true); if (CacheTexture(art, cachedFanart, item->GetLabel())) artwork.insert(make_pair("fanart", art)); if (artwork.empty()) artwork.insert(make_pair("thumb", "")); db.SetArtForItem(item->GetVideoInfoTag()->m_iDbId, item->GetVideoInfoTag()->m_type, artwork); } // now season art... map<int, map<string, string> > seasons; vector<string> artTypes; artTypes.push_back("thumb"); CVideoInfoScanner::GetSeasonThumbs(*item->GetVideoInfoTag(), seasons, artTypes, true); for (map<int, map<string, string> >::const_iterator j = seasons.begin(); j != seasons.end(); ++j) { if (j->second.empty()) continue; int idSeason = db.AddSeason(item->GetVideoInfoTag()->m_iDbId, j->first); map<string, string> seasonArt; if (idSeason > -1 && !db.GetArtForItem(idSeason, MediaTypeSeason, seasonArt)) { std::string cachedSeason = GetCachedSeasonThumb(j->first, item->GetVideoInfoTag()->m_strPath); std::string type; std::string originalUrl = j->second.begin()->second; if (CacheTexture(originalUrl, cachedSeason, "", type)) db.SetArtForItem(idSeason, MediaTypeSeason, type, originalUrl); } } // now episodes... CFileItemList items2; db.GetEpisodesByWhere("videodb://tvshows/titles/-1/-1/", db.PrepareSQL("episode_view.idShow=%d", item->GetVideoInfoTag()->m_iDbId), items2); for (int j = 0; j < items2.Size(); j++) { handle->SetProgress(j, items2.Size()); CFileItemPtr episode = items2[j]; string cachedThumb = GetCachedEpisodeThumb(*episode); if (!CFile::Exists(cachedThumb)) cachedThumb = GetCachedVideoThumb(*episode); episode->SetPath(episode->GetVideoInfoTag()->m_strFileNameAndPath); episode->GetVideoInfoTag()->m_strPictureURL.Parse(); map<string, string> artwork; if (!db.GetArtForItem(episode->GetVideoInfoTag()->m_iDbId, episode->GetVideoInfoTag()->m_type, artwork) || (artwork.size() == 1 && artwork.find("thumb") != artwork.end())) { CStdString art = CVideoInfoScanner::GetImage(episode.get(), true, episode->GetVideoInfoTag()->m_basePath != episode->GetPath(), "thumb"); if (CacheTexture(art, cachedThumb, episode->GetLabel())) artwork.insert(make_pair("thumb", art)); else artwork.insert(make_pair("thumb", "")); db.SetArtForItem(episode->GetVideoInfoTag()->m_iDbId, episode->GetVideoInfoTag()->m_type, artwork); } } } items.Clear(); // now sets db.GetSetsNav("videodb://movies/sets/", items, VIDEODB_CONTENT_MOVIES); for (int i = 0; i < items.Size(); i++) { CFileItemPtr item = items[i]; handle->SetProgress(i, items.Size()); handle->SetText(StringUtils::Format(g_localizeStrings.Get(12350).c_str(), item->GetLabel().c_str())); map<string, string> artwork; if (!db.GetArtForItem(item->GetVideoInfoTag()->m_iDbId, item->GetVideoInfoTag()->m_type, artwork)) { // grab the first movie from this set CFileItemList items2; db.GetMoviesNav("videodb://movies/titles/", items2, -1, -1, -1, -1, -1, -1, item->GetVideoInfoTag()->m_iDbId); if (items2.Size() > 1) { if (db.GetArtForItem(items2[0]->GetVideoInfoTag()->m_iDbId, items2[0]->GetVideoInfoTag()->m_type, artwork)) db.SetArtForItem(item->GetVideoInfoTag()->m_iDbId, item->GetVideoInfoTag()->m_type, artwork); } } } items.Clear(); // now actors if (CSettings::Get().GetBool("videolibrary.actorthumbs")) { db.GetActorsNav("videodb://movies/titles/", items, VIDEODB_CONTENT_MOVIES); db.GetActorsNav("videodb://tvshows/titles/", items, VIDEODB_CONTENT_TVSHOWS); db.GetActorsNav("videodb://tvshows/titles/", items, VIDEODB_CONTENT_EPISODES); db.GetActorsNav("videodb://musicvideos/titles/", items, VIDEODB_CONTENT_MUSICVIDEOS); for (int i = 0; i < items.Size(); i++) { CFileItemPtr item = items[i]; handle->SetProgress(i, items.Size()); handle->SetText(StringUtils::Format(g_localizeStrings.Get(12350).c_str(), item->GetLabel().c_str())); map<string, string> artwork; if (!db.GetArtForItem(item->GetVideoInfoTag()->m_iDbId, item->GetVideoInfoTag()->m_type, artwork)) { item->GetVideoInfoTag()->m_strPictureURL.Parse(); string cachedThumb = GetCachedActorThumb(*item); string art = CScraperUrl::GetThumbURL(item->GetVideoInfoTag()->m_strPictureURL.GetFirstThumb()); if (CacheTexture(art, cachedThumb, item->GetLabel())) artwork.insert(make_pair("thumb", art)); else artwork.insert(make_pair("thumb", "")); db.SetArtForItem(item->GetVideoInfoTag()->m_iDbId, item->GetVideoInfoTag()->m_type, artwork); } } } handle->MarkFinished(); ANNOUNCEMENT::CAnnouncementManager::Get().Announce(ANNOUNCEMENT::VideoLibrary, "xbmc", "OnScanFinished"); items.Clear(); }
bool CPVRClients::AutoconfigureClients(void) { bool bReturn(false); std::vector<PVR_CLIENT> autoConfigAddons; PVR_CLIENT addon; VECADDONS map; CAddonMgr::GetInstance().GetInstalledAddons(map, ADDON_PVRDLL); /** get the auto-configurable add-ons */ for (VECADDONS::iterator it = map.begin(); it != map.end(); ++it) { if (CAddonMgr::GetInstance().IsAddonDisabled((*it)->ID())) { addon = std::dynamic_pointer_cast<CPVRClient>(*it); if (addon->CanAutoconfigure()) autoConfigAddons.push_back(addon); } } /** no configurable add-ons found */ if (autoConfigAddons.empty()) return bReturn; /** display a progress bar while trying to auto-configure add-ons */ CGUIDialogExtendedProgressBar *loadingProgressDialog = (CGUIDialogExtendedProgressBar *)g_windowManager.GetWindow(WINDOW_DIALOG_EXT_PROGRESS); CGUIDialogProgressBarHandle* progressHandle = loadingProgressDialog->GetHandle(g_localizeStrings.Get(19688)); // Scanning for PVR services progressHandle->SetPercentage(0); progressHandle->SetText(g_localizeStrings.Get(19688)); //Scanning for PVR services /** start zeroconf and wait a second to get some responses */ CZeroconfBrowser::GetInstance()->Start(); for (std::vector<PVR_CLIENT>::iterator it = autoConfigAddons.begin(); !bReturn && it != autoConfigAddons.end(); ++it) (*it)->AutoconfigureRegisterType(); unsigned iIterations(0); float percentage(0.0f); float percentageStep(100.0f / PVR_CLIENT_AVAHI_SCAN_ITERATIONS); progressHandle->SetPercentage(percentage); /** while no add-ons were configured within 20 iterations */ while (!bReturn && iIterations++ < PVR_CLIENT_AVAHI_SCAN_ITERATIONS) { /** check each disabled add-on */ for (std::vector<PVR_CLIENT>::iterator it = autoConfigAddons.begin(); !bReturn && it != autoConfigAddons.end(); ++it) { if (addon->Autoconfigure()) { progressHandle->SetPercentage(100.0f); progressHandle->MarkFinished(); /** enable the add-on */ CAddonMgr::GetInstance().EnableAddon((*it)->ID()); CSingleLock lock(m_critSection); m_addons.push_back(*it); bReturn = true; } } /** wait a while and try again */ if (!bReturn) { percentage += percentageStep; progressHandle->SetPercentage(percentage); Sleep(PVR_CLIENT_AVAHI_SLEEP_TIME_MS); } } progressHandle->SetPercentage(100.0f); progressHandle->MarkFinished(); return bReturn; }
void CPVRChannelGroup::SearchAndSetChannelIcons(bool bUpdateDb /* = false */) { std::string iconPath = CSettings::Get().GetString("pvrmenu.iconpath"); if (iconPath.empty()) return; CPVRDatabase *database = GetPVRDatabase(); if (!database) return; /* fetch files in icon path for fast lookup */ CFileItemList fileItemList; XFILE::CDirectory::GetDirectory(iconPath, fileItemList, ".jpg|.png|.tbn"); if (fileItemList.IsEmpty()) return; CGUIDialogExtendedProgressBar* dlgProgress = (CGUIDialogExtendedProgressBar*)g_windowManager.GetWindow(WINDOW_DIALOG_EXT_PROGRESS); CGUIDialogProgressBarHandle* dlgProgressHandle = dlgProgress ? dlgProgress->GetHandle(g_localizeStrings.Get(19287)) : NULL; CSingleLock lock(m_critSection); /* create a map for fast lookup of normalized file base name */ std::map<std::string, std::string> fileItemMap; const VECFILEITEMS &items = fileItemList.GetList(); for(VECFILEITEMS::const_iterator it = items.begin(); it != items.end(); ++it) { std::string baseName = URIUtils::GetFileName((*it)->GetPath()); URIUtils::RemoveExtension(baseName); StringUtils::ToLower(baseName); fileItemMap.insert(std::make_pair(baseName, (*it)->GetPath())); } int channelIndex = 0; for(std::vector<PVRChannelGroupMember>::const_iterator it = m_members.begin(); it != m_members.end(); ++it) { CPVRChannelPtr channel = (*it).channel; /* update progress dialog */ if (dlgProgressHandle) { dlgProgressHandle->SetProgress(channelIndex++, m_members.size()); dlgProgressHandle->SetText(channel->ChannelName()); } /* skip if an icon is already set and exists */ if (channel->IsIconExists()) continue; /* reset icon before searching for a new one */ channel->SetIconPath(""); std::string strChannelUid = StringUtils::Format("%08d", channel->UniqueID()); std::string strLegalClientChannelName = CUtil::MakeLegalFileName(channel->ClientChannelName()); StringUtils::ToLower(strLegalClientChannelName); std::string strLegalChannelName = CUtil::MakeLegalFileName(channel->ChannelName()); StringUtils::ToLower(strLegalChannelName); std::map<std::string, std::string>::iterator itItem; if ((itItem = fileItemMap.find(strLegalClientChannelName)) != fileItemMap.end() || (itItem = fileItemMap.find(strLegalChannelName)) != fileItemMap.end() || (itItem = fileItemMap.find(strChannelUid)) != fileItemMap.end()) { channel->SetIconPath(itItem->second, g_advancedSettings.m_bPVRAutoScanIconsUserSet); } if (bUpdateDb) channel->Persist(); /* TODO: start channel icon scraper here if nothing was found */ } if (dlgProgressHandle) dlgProgressHandle->MarkFinished(); }
bool CCDDARipJob::DoWork() { CLog::Log(LOGINFO, "Start ripping track %s to %s", m_input.c_str(), m_output.c_str()); // if we are ripping to a samba share, rip it to hd first and then copy it it the share CFileItem file(m_output, false); if (file.IsRemote()) m_output = SetupTempFile(); if (m_output.empty()) { CLog::Log(LOGERROR, "CCDDARipper: Error opening file"); return false; } // init ripper CFile reader; CEncoder* encoder = nullptr; if (!reader.Open(m_input,READ_CACHED) || !(encoder=SetupEncoder(reader))) { CLog::Log(LOGERROR, "Error: CCDDARipper::Init failed"); return false; } // setup the progress dialog CGUIDialogExtendedProgressBar* pDlgProgress = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogExtendedProgressBar>(WINDOW_DIALOG_EXT_PROGRESS); CGUIDialogProgressBarHandle* handle = pDlgProgress->GetHandle(g_localizeStrings.Get(605)); int iTrack = atoi(m_input.substr(13, m_input.size() - 13 - 5).c_str()); std::string strLine0 = StringUtils::Format("%02i. %s - %s", iTrack, m_tag.GetArtistString().c_str(), m_tag.GetTitle().c_str()); handle->SetText(strLine0); // start ripping int percent=0; int oldpercent=0; bool cancelled(false); int result; while (!cancelled && (result=RipChunk(reader, encoder, percent)) == 0) { cancelled = ShouldCancel(percent,100); if (percent > oldpercent) { oldpercent = percent; handle->SetPercentage(static_cast<float>(percent)); } } // close encoder ripper encoder->CloseEncode(); delete encoder; reader.Close(); if (file.IsRemote() && !cancelled && result == 2) { // copy the ripped track to the share if (!CFile::Copy(m_output, file.GetPath())) { CLog::Log(LOGERROR, "CDDARipper: Error copying file from %s to %s", m_output.c_str(), file.GetPath().c_str()); CFile::Delete(m_output); return false; } // delete cached file CFile::Delete(m_output); } if (cancelled) { CLog::Log(LOGWARNING, "User Cancelled CDDA Rip"); CFile::Delete(m_output); } else if (result == 1) CLog::Log(LOGERROR, "CDDARipper: Error ripping %s", m_input.c_str()); else if (result < 0) CLog::Log(LOGERROR, "CDDARipper: Error encoding %s", m_input.c_str()); else { CLog::Log(LOGINFO, "Finished ripping %s", m_input.c_str()); if (m_eject) { CLog::Log(LOGINFO, "Ejecting CD"); g_mediaManager.EjectTray(); } } handle->MarkFinished(); return !cancelled && result == 2; }