bool CPVRChannelGroupInternal::Persist(void) { bool bReturn(true); CSingleLock lock(m_critSection); bool bHasNewChannels = HasNewChannels(); bool bHasChangedChannels = HasChangedChannels(); /* open the database */ CPVRDatabase *database = OpenPVRDatabase(); if (!database) return false; if (bHasNewChannels || bHasChangedChannels) CLog::Log(LOGDEBUG, "CPVRChannelGroupInternal - %s - persisting %d channels", __FUNCTION__, (int) size()); if (bHasNewChannels) { CLog::Log(LOGDEBUG, "CPVRChannelGroupInternal - %s - group '%s' has new channels. writing changes directly", __FUNCTION__, GroupName().c_str()); /* write directly to get channel ids */ for (unsigned int iChannelPtr = 0; iChannelPtr < size(); iChannelPtr++) { CPVRChannel *channel = at(iChannelPtr).channel; if (!channel->Persist()) { CLog::Log(LOGERROR, "CPVRChannelGroupInternal - %s - failed to persist channel '%s'", __FUNCTION__, channel->ChannelName().c_str()); bReturn = false; } } lock.Leave(); } else if (bHasChangedChannels) { /* queue queries */ for (unsigned int iChannelPtr = 0; iChannelPtr < size(); iChannelPtr++) at(iChannelPtr).channel->Persist(true); lock.Leave(); /* and commit them */ bReturn = database->CommitInsertQueries(); if (!bReturn) CLog::Log(LOGERROR, "CPVRChannelGroupInternal - %s - failed to persist channels", __FUNCTION__); } if (bReturn) bReturn = CPVRChannelGroup::Persist(); database->Close(); return bReturn; }
bool CPVRChannelGroupInternal::Persist(void) { bool bReturn = false; bool bRefreshChannelList = false; CPVRDatabase *database = CPVRManager::Get()->GetTVDatabase(); if (!database || !database->Open()) return bReturn; CLog::Log(LOGDEBUG, "CPVRChannelGroupInternal - %s - persisting %d channels", __FUNCTION__, size()); bReturn = true; for (unsigned int iChannelPtr = 0; iChannelPtr < size(); iChannelPtr++) { /* if this channel has an invalid ID, reload the list afterwards */ bRefreshChannelList = at(iChannelPtr).channel->ChannelID() <= 0; bReturn = at(iChannelPtr).channel->Persist(true) && bReturn; } if (bReturn) { if (bRefreshChannelList) { database->CommitInsertQueries(); CLog::Log(LOGDEBUG, "PVRChannelGroup - %s - reloading the channels list to get channel IDs", __FUNCTION__); Unload(); bReturn = LoadFromDb(true) > 0; } if (bReturn) bReturn = CPVRChannelGroup::Persist(); } database->Close(); return bReturn; }
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(); }
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; }