bool CPVRChannelGroup::SetChannelIconPath(CPVRChannelPtr channel, const std::string& strIconPath) { if (CFile::Exists(strIconPath)) { channel->SetIconPath(strIconPath, g_advancedSettings.m_bPVRAutoScanIconsUserSet); return true; } return false; }
bool CPVRChannelGroup::UpdateChannel(const CFileItem &item, bool bHidden, bool bVirtual, bool bEPGEnabled, bool bParentalLocked, int iEPGSource, int iChannelNumber, const std::string &strChannelName, const std::string &strIconPath, const std::string &strStreamURL, bool bUserSetIcon) { if (!item.HasPVRChannelInfoTag()) return false; CSingleLock lock(m_critSection); /* get the real channel from the group */ CPVRChannelPtr channel = GetByUniqueID(item.GetPVRChannelInfoTag()->UniqueID()); if (!channel) return false; channel->SetChannelName(strChannelName, true); channel->SetHidden(bHidden); channel->SetLocked(bParentalLocked); channel->SetIconPath(strIconPath, bUserSetIcon); if (bVirtual) channel->SetStreamURL(strStreamURL); if (iEPGSource == 0) channel->SetEPGScraper("client"); // TODO add other scrapers channel->SetEPGEnabled(bEPGEnabled); /* set new values in the channel tag */ if (bHidden) { SortByChannelNumber(); // or previous changes will be overwritten RemoveFromGroup(*channel); } else { SetChannelNumber(*channel, iChannelNumber); } return true; }
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 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(); }