int CPVRChannelGroup::LoadFromDb(bool bCompress /* = false */) { const CPVRDatabasePtr database(CServiceBroker::GetPVRManager().GetTVDatabase()); if (!database) return -1; int iChannelCount = Size(); const CPVRChannelGroupPtr allGroup = CServiceBroker::GetPVRManager().ChannelGroups()->GetGroupAll(IsRadio()); if (!allGroup) return -1; std::map<int, CPVRChannelPtr> allChannels; { CSingleLock lock(allGroup->m_critSection); for (const auto& groupMember : allGroup->m_members) { allChannels.insert(std::make_pair(groupMember.second.channel->ChannelID(), groupMember.second.channel)); } } database->Get(*this, allChannels); return Size() - iChannelCount; }
bool CPVRChannelGroup::Persist(void) { bool bReturn(true); const CPVRDatabasePtr database(g_PVRManager.GetTVDatabase()); CSingleLock lock(m_critSection); /* only persist if the group has changes and is fully loaded or never has been saved before */ if (!HasChanges() || (!m_bLoaded && m_iGroupId != -1)) return bReturn; // Mark newly created groups as loaded so future updates will also be persisted... if (m_iGroupId == -1) m_bLoaded = true; if (database) { CLog::Log(LOGDEBUG, "CPVRChannelGroup - %s - persisting channel group '%s' with %d channels", __FUNCTION__, GroupName().c_str(), (int) m_members.size()); m_bChanged = false; lock.Leave(); bReturn = database->Persist(*this); } else { bReturn = false; } return bReturn; }
int CPVRChannelGroup::LoadFromDb(bool bCompress /* = false */) { const CPVRDatabasePtr database(g_PVRManager.GetTVDatabase()); if (!database) return -1; int iChannelCount = Size(); database->Get(*this); return Size() - iChannelCount; }
int CPVRChannelGroup::LoadFromDb(bool bCompress /* = false */) { const CPVRDatabasePtr database(CServiceBroker::GetPVRManager().GetTVDatabase()); if (!database) return -1; int iChannelCount = Size(); database->Get(*this, *m_allChannelsGroup); return Size() - iChannelCount; }
bool CPVRChannel::SetLastWatched(time_t iLastWatched) { { CSingleLock lock(m_critSection); if (m_iLastWatched != iLastWatched) m_iLastWatched = iLastWatched; } const CPVRDatabasePtr database(g_PVRManager.GetTVDatabase()); if (database) return database->UpdateLastWatched(*this); return false; }
int CPVRChannelGroupInternal::LoadFromDb(bool bCompress /* = false */) { const CPVRDatabasePtr database(CServiceBroker::GetPVRManager().GetTVDatabase()); if (!database) return -1; int iChannelCount = Size(); if (database->Get(*this, bCompress) == 0) CLog::LogFC(LOGDEBUG, LOGPVR, "No channels in the database"); SortByChannelNumber(); return Size() - iChannelCount; }
bool CPVRChannelGroups::Load(void) { const CPVRDatabasePtr database(CServiceBroker::GetPVRManager().GetTVDatabase()); if (!database) return false; CSingleLock lock(m_critSection); // remove previous contents Clear(); CLog::LogFC(LOGDEBUG, LOGPVR, "Loading all %s channel groups", m_bRadio ? "radio" : "TV"); // create the internal channel group CPVRChannelGroupPtr internalGroup = CPVRChannelGroupPtr(new CPVRChannelGroupInternal(m_bRadio)); m_groups.push_back(internalGroup); // load groups from the database database->Get(*this); CLog::LogFC(LOGDEBUG, LOGPVR, "%d %s groups fetched from the database", m_groups.size(), m_bRadio ? "radio" : "TV"); // load channels of internal group std::vector<std::shared_ptr<CPVRChannel>> channelsToRemove; if (!internalGroup->Load(channelsToRemove)) { CLog::LogF(LOGERROR, "Failed to load 'all channels' group"); return false; } RemoveFromAllGroups(channelsToRemove); // load the other groups from the database if (!LoadUserDefinedChannelGroups()) { CLog::LogF(LOGERROR, "Failed to load user defined channel groups"); return false; } // set the last played group as selected group at startup CPVRChannelGroupPtr lastPlayedGroup = GetLastPlayedGroup(); SetSelectedGroup(lastPlayedGroup ? lastPlayedGroup : internalGroup); CLog::LogFC(LOGDEBUG, LOGPVR, "%d %s channel groups loaded", m_groups.size(), m_bRadio ? "radio" : "TV"); // need at least 1 group return m_groups.size() > 0; }
bool CPVRChannelGroup::SetLastWatched(time_t iLastWatched) { const CPVRDatabasePtr database(CServiceBroker::GetPVRManager().GetTVDatabase()); CSingleLock lock(m_critSection); if (m_iLastWatched != iLastWatched) { m_iLastWatched = iLastWatched; /* update the database immediately */ if (database) return database->UpdateLastWatched(*this); } return false; }
bool CPVRChannelGroups::DeleteGroup(const CPVRChannelGroup &group) { // don't delete internal groups if (group.IsInternalGroup()) { CLog::Log(LOGERROR, "CPVRChannelGroups - %s - cannot delete internal group '%s'", __FUNCTION__, group.GroupName().c_str()); return false; } bool bFound(false); CPVRChannelGroupPtr playingGroup; // delete the group in this container { CSingleLock lock(m_critSection); for (std::vector<CPVRChannelGroupPtr>::iterator it = m_groups.begin(); !bFound && it != m_groups.end();) { if (*(*it) == group || (group.GroupID() > 0 && (*it)->GroupID() == group.GroupID())) { // update the selected group in the gui if it's deleted CPVRChannelGroupPtr selectedGroup = GetSelectedGroup(); if (selectedGroup && *selectedGroup == group) playingGroup = GetGroupAll(); it = m_groups.erase(it); bFound = true; } else { ++it; } } } if (playingGroup) g_PVRManager.SetPlayingGroup(playingGroup); if (group.GroupID() > 0) { // delete the group from the database const CPVRDatabasePtr database(g_PVRManager.GetTVDatabase()); return database ? database->Delete(group) : false; } return bFound; }
bool CPVRChannelGroups::Load(void) { const CPVRDatabasePtr database(g_PVRManager.GetTVDatabase()); if (!database) return false; CSingleLock lock(m_critSection); // remove previous contents Clear(); CLog::Log(LOGDEBUG, "CPVRChannelGroups - %s - loading all %s channel groups", __FUNCTION__, m_bRadio ? "radio" : "TV"); // create the internal channel group CPVRChannelGroupPtr internalGroup = CPVRChannelGroupPtr(new CPVRChannelGroupInternal(m_bRadio)); m_groups.push_back(internalGroup); // load groups from the database database->Get(*this); CLog::Log(LOGDEBUG, "CPVRChannelGroups - %s - %" PRIuS" %s groups fetched from the database", __FUNCTION__, m_groups.size(), m_bRadio ? "radio" : "TV"); // load channels of internal group if (!internalGroup->Load()) { CLog::Log(LOGERROR, "CPVRChannelGroups - %s - failed to load channels", __FUNCTION__); return false; } // load the other groups from the database if (!LoadUserDefinedChannelGroups()) { CLog::Log(LOGERROR, "CPVRChannelGroups - %s - failed to load channel groups", __FUNCTION__); return false; } // set the last played group as selected group at startup CPVRChannelGroupPtr lastPlayedGroup = GetLastPlayedGroup(); SetSelectedGroup(lastPlayedGroup ? lastPlayedGroup : internalGroup); CLog::Log(LOGDEBUG, "CPVRChannelGroups - %s - %" PRIuS" %s channel groups loaded", __FUNCTION__, m_groups.size(), m_bRadio ? "radio" : "TV"); // need at least 1 group return m_groups.size() > 0; }
bool CPVRChannel::Delete(void) { bool bReturn = false; const CPVRDatabasePtr database = CServiceBroker::GetPVRManager().GetTVDatabase(); if (!database) return bReturn; const CPVREpgPtr epg = GetEPG(); if (epg) { CServiceBroker::GetPVRManager().EpgContainer().DeleteEpg(epg, true); CSingleLock lock(m_critSection); m_epg.reset(); } bReturn = database->Delete(*this); return bReturn; }
bool CPVRChannel::Persist() { { // not changed CSingleLock lock(m_critSection); if (!m_bChanged && m_iChannelId > 0) return true; } const CPVRDatabasePtr database(g_PVRManager.GetTVDatabase()); if (database) { bool bReturn = database->Persist(*this) && database->CommitInsertQueries(); CSingleLock lock(m_critSection); m_bChanged = !bReturn; return bReturn; } return false; }
bool CPVRChannel::SetLastWatched(time_t iLastWatched) { { CSingleLock lock(m_critSection); if (m_iLastWatched != iLastWatched) { m_iLastWatched = iLastWatched; const std::shared_ptr<CPVREpg> epg = GetEPG(); if (epg) epg->GetChannelData()->SetLastWatched(iLastWatched); } } const CPVRDatabasePtr database = CServiceBroker::GetPVRManager().GetTVDatabase(); if (database) return database->UpdateLastWatched(*this); return false; }
bool CPVRChannel::Delete(void) { bool bReturn = false; const CPVRDatabasePtr database(g_PVRManager.GetTVDatabase()); if (!database) return bReturn; /* delete the EPG table */ CEpgPtr epg = GetEPG(); if (epg) { CPVRChannelPtr empty; epg->SetChannel(empty); g_EpgContainer.DeleteEpg(*epg, true); CSingleLock lock(m_critSection); m_bEPGCreated = false; } bReturn = database->Delete(*this); return bReturn; }
bool CPVRChannel::Persist() { { // not changed CSingleLock lock(m_critSection); if (!m_bChanged && m_iChannelId > 0) return true; } const CPVRDatabasePtr database = CServiceBroker::GetPVRManager().GetTVDatabase(); if (database) { bool bReturn = database->Persist(*this, true); CSingleLock lock(m_critSection); m_bChanged = !bReturn; return bReturn; } return false; }