bool CPVRChannelGroup::UpdateChannel(const CFileItem &item, bool bHidden, bool bVirtual, bool bEPGEnabled, bool bParentalLocked, int iEPGSource, int iChannelNumber, const CStdString &strChannelName, const CStdString &strIconPath, const CStdString &strStreamURL) { if (!item.HasPVRChannelInfoTag()) return false; CSingleLock lock(m_critSection); /* get the real channel from the group */ CPVRChannel *channel = GetByUniqueID(item.GetPVRChannelInfoTag()->UniqueID()); if (!channel) return false; channel->SetChannelName(strChannelName); channel->SetHidden(bHidden); channel->SetLocked(bParentalLocked); channel->SetIconPath(strIconPath); 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; }
bool CGUIDialogPVRChannelManager::OnClickButtonNewChannel(CGUIMessage &message) { std::vector<long> clients; CGUIDialogSelect* pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT); if (!pDlgSelect) return false; pDlgSelect->SetHeading(19213); // Select Client pDlgSelect->Add(g_localizeStrings.Get(19209)); clients.push_back(PVR_VIRTUAL_CLIENT_ID); PVR_CLIENTMAP clientMap; if (g_PVRClients->GetConnectedClients(clientMap) > 0) { PVR_CLIENTMAP_ITR itr; for (itr = clientMap.begin() ; itr != clientMap.end(); itr++) { clients.push_back((*itr).first); pDlgSelect->Add((*itr).second->Name()); } } pDlgSelect->DoModal(); int selection = pDlgSelect->GetSelectedLabel(); if (selection >= 0 && selection <= (int) clients.size()) { int clientID = clients[selection]; if (clientID == PVR_VIRTUAL_CLIENT_ID) { CStdString strURL = ""; if (CGUIKeyboardFactory::ShowAndGetInput(strURL, g_localizeStrings.Get(19214), false)) { if (!strURL.empty()) { CPVRChannel *newchannel = new CPVRChannel(m_bIsRadio); newchannel->SetChannelName(g_localizeStrings.Get(19204)); newchannel->SetEPGEnabled(false); newchannel->SetVirtual(true); newchannel->SetStreamURL(strURL); newchannel->SetClientID(PVR_VIRTUAL_CLIENT_ID); if (g_PVRChannelGroups->CreateChannel(*newchannel)) g_PVRChannelGroups->GetGroupAll(m_bIsRadio)->Persist(); CFileItemPtr channel(new CFileItem(*newchannel)); if (channel) { channel->SetProperty("ActiveChannel", true); channel->SetProperty("Name", g_localizeStrings.Get(19204)); channel->SetProperty("UseEPG", false); channel->SetProperty("Icon", newchannel->IconPath()); channel->SetProperty("EPGSource", (int)0); channel->SetProperty("ClientName", g_localizeStrings.Get(19209)); channel->SetProperty("ParentalLocked", false); m_channelItems->AddFront(channel, m_iSelected); m_viewControl.SetItems(*m_channelItems); Renumber(); } } } } else { CGUIDialogOK::ShowAndGetInput(19033,19038,0,0); } } return true; }
void CGUIDialogPVRChannelManager::SaveList() // XXX investigate: renumbering doesn't work { if (!m_bContainsChanges) return; CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); if (!database || !database->Open()) return; CGUIDialogProgress* pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); pDlgProgress->SetHeading(190); pDlgProgress->SetLine(0, ""); pDlgProgress->SetLine(1, 328); pDlgProgress->SetLine(2, ""); pDlgProgress->StartModal(); pDlgProgress->Progress(); pDlgProgress->SetPercentage(0); int iActiveChannels = 0; for (int iListPtr = 0; iListPtr < m_channelItems->Size(); iListPtr++) { if (m_channelItems->Get(iListPtr)->GetPropertyBOOL("ActiveChannel")) ++iActiveChannels; } // int iNextChannelNumber = 1; // int iNextHiddenChannelNumber = iActiveChannels + 1; bool bHasChangedItems = false; for (int iListPtr = 0; iListPtr < m_channelItems->Size(); iListPtr++) { bool bChanged = false; CFileItemPtr pItem = m_channelItems->Get(iListPtr); if (!pItem) continue; CPVRChannel *channel = pItem->GetPVRChannelInfoTag(); if (!channel) { //TODO add new channel continue; } /* get values from the form */ bool bHidden = !pItem->GetPropertyBOOL("ActiveChannel"); bool bVirtual = pItem->GetPropertyBOOL("Virtual"); bool bEPGEnabled = pItem->GetPropertyBOOL("UseEPG"); int iEPGSource = pItem->GetPropertyInt("EPGSource"); CStdString strChannelName = pItem->GetProperty("Name"); CStdString strIconPath = pItem->GetProperty("Icon"); CStdString strStreamURL = pItem->GetProperty("StreamURL"); /* set new values in the channel tag */ // TODO // if (bHidden) // bChanged = channel->SetChannelNumber(iNextHiddenChannelNumber++) || bChanged; // else // bChanged = channel->SetChannelNumber(iNextChannelNumber++) || bChanged; bChanged = channel->SetChannelName(strChannelName) || bChanged; bChanged = channel->SetHidden(bHidden) || bChanged; bChanged = channel->SetIconPath(strIconPath) || bChanged; if (bVirtual) bChanged = channel->SetStreamURL(strStreamURL) || bChanged; if (iEPGSource == 0) bChanged = channel->SetEPGScraper("client") || bChanged; // TODO add other scrapers bChanged = channel->SetEPGEnabled(bEPGEnabled) || bChanged; if (bChanged) { bHasChangedItems = true; channel->Persist(true); } pItem->SetProperty("Changed", false); pDlgProgress->SetPercentage(iListPtr * 100 / m_channelItems->Size()); } if (bHasChangedItems) { database->CommitInsertQueries(); CPVRManager::Get()->Start(); // XXX not a nice way to refresh the channels, but works for now } database->Close(); m_bContainsChanges = false; pDlgProgress->Close(); }