bool CPVRChannelGroupInternal::UpdateFromClient(const CPVRChannel &channel) { CSingleLock lock(m_critSection); CPVRChannel *realChannel = (CPVRChannel *) GetByClient(channel.UniqueID(), channel.ClientID()); if (realChannel != NULL) realChannel->UpdateFromClient(channel); else realChannel = new CPVRChannel(channel); return CPVRChannelGroup::AddToGroup(realChannel, 0, false); }
bool CPVRChannelGroupInternal::UpdateChannel(const CPVRChannel &channel) { CPVRChannel *updateChannel = (CPVRChannel *) GetByUniqueID(channel.UniqueID()); if (!updateChannel) { updateChannel = new CPVRChannel(channel.IsRadio()); PVRChannelGroupMember newMember = { updateChannel, 0 }; push_back(newMember); updateChannel->SetUniqueID(channel.UniqueID()); } updateChannel->UpdateFromClient(channel); return updateChannel->Persist(!m_bLoaded); }
bool CPVRChannelGroupInternal::AddAndUpdateChannels(const CPVRChannelGroup &channels, bool bUseBackendChannelNumbers) { bool bReturn(false); CSingleLock lock(m_critSection); /* go through the channel list and check for updated or new channels */ for (unsigned int iChannelPtr = 0; iChannelPtr < channels.size(); iChannelPtr++) { PVRChannelGroupMember member = channels.at(iChannelPtr); if (!member.channel) continue; /* check whether this channel is present in this container */ CPVRChannel *existingChannel = (CPVRChannel *) GetByClient(member.channel->UniqueID(), member.channel->ClientID()); if (existingChannel) { /* if it's present, update the current tag */ if (existingChannel->UpdateFromClient(*member.channel)) { existingChannel->Persist(!m_bLoaded); bReturn = true; CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - updated %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", member.channel->ChannelName().c_str()); } } else { /* new channel */ CPVRChannel *newChannel = new CPVRChannel(*member.channel); /* insert the new channel in this group */ int iChannelNumber = bUseBackendChannelNumbers ? member.channel->ClientChannelNumber() : 0; InsertInGroup(*newChannel, iChannelNumber, false); bReturn = true; CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - added %s channel '%s' at position %d", __FUNCTION__, m_bRadio ? "radio" : "TV", member.channel->ChannelName().c_str(), iChannelNumber); } } return bReturn; }
bool CPVRChannelGroupInternal::UpdateGroupEntries(const CPVRChannelGroup &channels) { bool bChanged = false; int iCurSize = size(); CPVRChannelGroup *newChannels = new CPVRChannelGroup(m_bRadio); CPVRDatabase *database = g_PVRManager.GetTVDatabase(); if (!database || !database->Open()) return bChanged; /* go through the channel list and check for updated or new channels */ for (unsigned int iChannelPtr = 0; iChannelPtr < channels.size(); iChannelPtr++) { const CPVRChannel *channel = channels.at(iChannelPtr).channel; /* check if this channel is present in this container */ CPVRChannel *existingChannel = (CPVRChannel *) GetByClient(channel->UniqueID(), channel->ClientID()); if (existingChannel) { /* if it's present, update the current tag */ if (existingChannel->UpdateFromClient(*channel)) { bChanged = true; CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - updated %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); } } else { /* new channel */ CPVRChannel *newChannel = new CPVRChannel(m_bRadio); newChannel->SetUniqueID(channel->UniqueID(), false); newChannel->UpdateFromClient(*channel); newChannels->AddToGroup(newChannel); int iChannelNumber = iCurSize == 0 ? channel->ClientChannelNumber() : 0; InsertInGroup(newChannel, iChannelNumber, false); bChanged = true; CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - added %s channel '%s' at position %d", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str(), iChannelNumber); } } /* persist changes */ for (unsigned int iChannelPtr = 0; iChannelPtr < newChannels->size(); iChannelPtr++) ((CPVRChannel *) newChannels->GetByIndex(iChannelPtr))->Persist(false); /* write immediately to get a db id */ delete newChannels; /* check for deleted channels */ unsigned int iSize = size(); for (unsigned int iChannelPtr = 0; iChannelPtr < iSize; iChannelPtr++) { CPVRChannel *channel = (CPVRChannel *) GetByIndex(iChannelPtr); if (!channel) continue; if (channels.GetByClient(channel->UniqueID(), channel->ClientID()) == NULL) { /* channel was not found */ CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - deleted %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); /* remove this channel from all non-system groups */ ((CPVRChannelGroups *) g_PVRChannelGroups->Get(m_bRadio))->RemoveFromAllGroups(channel); delete at(iChannelPtr).channel; erase(begin() + iChannelPtr); iChannelPtr--; iSize--; bChanged = true; } } database->Close(); /* try to find channel icons */ SearchAndSetChannelIcons(); CacheIcons(); if (bChanged || HasChanges()) { /* remove invalid channels */ RemoveInvalidChannels(); /* sort by client channel number if this is the first time */ if (iCurSize == 0) SortByClientChannelNumber(); /* renumber to make sure all channels have a channel number. new channels were added at the back, so they'll get the highest numbers */ Renumber(); return Persist(); } else { return true; } }
bool CPVRChannelGroupInternal::UpdateGroupEntries(CPVRChannelGroup *channels) { CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); if(!database && !database->Open()) return false; int iSize = size(); for (int ptr = 0; ptr < iSize; ptr++) { CPVRChannel *channel = at(ptr).channel; /* ignore virtual channels */ if (channel->IsVirtual()) continue; /* check if this channel is still present */ const CPVRChannel *existingChannel = channels->GetByUniqueID(channel->UniqueID()); if (existingChannel) { /* if it's present, update the current tag */ if (channel->UpdateFromClient(*existingChannel)) { channel->Persist(true); CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - updated %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); } /* remove this tag from the temporary channel list */ channels->RemoveByUniqueID(channel->UniqueID()); } else { /* channel is no longer present */ CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - removing %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); channel->Delete(); erase(begin() + ptr); ptr--; iSize--; } } /* the temporary channel list only contains new channels now */ for (unsigned int ptr = 0; ptr < channels->size(); ptr++) { CPVRChannel *channel = channels->at(ptr).channel; channel->Persist(true); PVRChannelGroupMember member = { channel, size() }; push_back(member); CLog::Log(LOGINFO,"PVRChannelGroupInternal - %s - added %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); } /* post the queries generated by the update */ database->CommitInsertQueries(); database->Close(); Renumber(); return true; }
bool CPVRChannels::Update(CPVRChannels *channels) { /* the database has already been opened */ CPVRDatabase *database = g_PVRManager.GetTVDatabase(); int iSize = size(); for (int ptr = 0; ptr < iSize; ptr++) { CPVRChannel *channel = at(ptr); /* ignore virtual channels */ if (channel->IsVirtual()) continue; /* check if this channel is still present */ CPVRChannel *existingChannel = channels->GetByUniqueID(channel->UniqueID()); if (existingChannel) { /* if it's present, update the current tag */ if (channel->UpdateFromClient(*existingChannel)) { channel->Persist(true); CLog::Log(LOGINFO,"%s - updated %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); } /* remove this tag from the temporary channel list */ channels->RemoveByUniqueID(channel->UniqueID()); } else { /* channel is no longer present */ CLog::Log(LOGINFO,"%s - removing %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); database->RemoveChannel(*channel); erase(begin() + ptr); ptr--; iSize--; } } /* the temporary channel list only contains new channels now */ for (unsigned int ptr = 0; ptr < channels->size(); ptr++) { CPVRChannel *channel = channels->at(ptr); channel->Persist(true); push_back(channel); CLog::Log(LOGINFO,"%s - added %s channel '%s'", __FUNCTION__, m_bRadio ? "radio" : "TV", channel->ChannelName().c_str()); } /* post the queries generated by the update */ database->CommitInsertQueries(); /* recount hidden channels */ m_iHiddenChannels = 0; for (unsigned int i = 0; i < size(); i++) { if (at(i)->IsHidden()) m_iHiddenChannels++; } m_bIsSorted = false; return true; }