CPVRChannelGroupPtr CPVRChannelGroups::GetLastPlayedGroup(int iChannelID /* = -1 */) const { CPVRChannelGroupPtr group; CSingleLock lock(m_critSection); for (std::vector<CPVRChannelGroupPtr>::const_iterator it = m_groups.begin(); it != m_groups.end(); ++it) { if ((*it)->LastWatched() > 0 && (!group || (*it)->LastWatched() > group->LastWatched()) && (iChannelID == -1 || (iChannelID >= 0 && (*it)->IsGroupMember(iChannelID))) && !(*it)->IsHidden()) group = (*it); } return group; }
bool CPVRManager::OpenLiveStream(const CFileItem &channel) { bool bReturn(false); if (!channel.HasPVRChannelInfoTag()) return bReturn; CLog::Log(LOGDEBUG,"PVRManager - %s - opening live stream on channel '%s'", __FUNCTION__, channel.GetPVRChannelInfoTag()->ChannelName().c_str()); // check if we're allowed to play this file if (IsParentalLocked(*channel.GetPVRChannelInfoTag())) return bReturn; CPVRChannelPtr playingChannel; CPVRChannelGroupPtr group; bool bPersistChanges(false); if ((bReturn = m_addons->OpenStream(*channel.GetPVRChannelInfoTag(), false)) != false) { CSingleLock lock(m_critSection); if(m_currentFile) delete m_currentFile; m_currentFile = new CFileItem(channel); if (m_addons->GetPlayingChannel(playingChannel)) { time_t tNow; CDateTime::GetCurrentDateTime().GetAsTime(tNow); /* update last watched timestamp for channel */ playingChannel->SetLastWatched(tNow); /* update last watched timestamp for group */ group = g_PVRManager.GetPlayingGroup(playingChannel->IsRadio()); group->SetLastWatched(tNow); /* update last played group */ m_channelGroups->SetLastPlayedGroup(group); bPersistChanges = true; } } if (bPersistChanges) { playingChannel->Persist(); group->Persist(); } return bReturn; }
void CPVRChannelGroups::SetSelectedGroup(CPVRChannelGroupPtr group) { // update the selected group { CSingleLock lock(m_critSection); if (m_selectedGroup) m_selectedGroup->SetSelectedGroup(false); m_selectedGroup = group; group->SetSelectedGroup(true); } // update the channel number cache group->Renumber(); }
CPVRChannelPtr CPVRChannelGroupsContainer::GetByUniqueID(int iUniqueChannelId, int iClientID) const { CPVRChannelPtr channel; CPVRChannelGroupPtr channelgroup = GetGroupAllTV(); if (channelgroup) channel = channelgroup->GetByClient(iUniqueChannelId, iClientID); if (!channelgroup || !channel) channelgroup = GetGroupAllRadio(); if (channelgroup) channel = channelgroup->GetByClient(iUniqueChannelId, iClientID); return channel; }
void CPVRChannelGroupsContainer::SearchMissingChannelIcons(void) { CLog::Log(LOGINFO, "PVRChannelGroupsContainer - %s - starting channel icon search", __FUNCTION__); // TODO: Add Process dialog here CPVRChannelGroupPtr channelgrouptv = GetGroupAllTV(); CPVRChannelGroupPtr channelgroupradio = GetGroupAllRadio(); if (channelgrouptv) channelgrouptv->SearchAndSetChannelIcons(true); if (channelgroupradio) channelgroupradio->SearchAndSetChannelIcons(true); CGUIDialogOK::ShowAndGetInput(19103,0,20177,0); }
bool EpgSearchFilter::MatchChannelNumber(const CEpgInfoTag &tag) const { bool bReturn(true); if (m_iChannelNumber != EPG_SEARCH_UNSET && g_PVRManager.IsStarted()) { CPVRChannelGroupPtr group = (m_iChannelGroup != EPG_SEARCH_UNSET) ? g_PVRChannelGroups->GetByIdFromAll(m_iChannelGroup) : g_PVRChannelGroups->GetGroupAllTV(); if (!group) group = CPVRManager::Get().ChannelGroups()->GetGroupAllTV(); bReturn = (m_iChannelNumber == (int) group->GetChannelNumber(*tag.ChannelTag())); } return bReturn; }
bool CPVREpgSearchFilter::MatchChannelNumber(const CPVREpgInfoTagPtr &tag) const { bool bReturn(true); if (m_channelNumber.IsValid() && CServiceBroker::GetPVRManager().IsStarted()) { CPVRChannelGroupPtr group = (m_iChannelGroup != EPG_SEARCH_UNSET) ? CServiceBroker::GetPVRManager().ChannelGroups()->GetByIdFromAll(m_iChannelGroup) : CServiceBroker::GetPVRManager().ChannelGroups()->GetGroupAllTV(); if (!group) group = CServiceBroker::GetPVRManager().ChannelGroups()->GetGroupAllTV(); bReturn = (m_channelNumber == group->GetChannelNumber(tag->Channel())); } return bReturn; }
void CGUIWindowPVRGuide::GetViewTimelineItems(CFileItemList &items) { CGUIEPGGridContainer* epgGridContainer = dynamic_cast<CGUIEPGGridContainer*>(GetControl(m_viewControl.GetCurrentControl())); if (!epgGridContainer) return; CPVRChannelGroupPtr group; { CSingleLock lock(m_critSection); // group change detected reset grid coordinates and refresh grid items if (!m_bRefreshTimelineItems && *m_cachedChannelGroup != *GetGroup()) { epgGridContainer->ResetCoordinates(); m_bRefreshTimelineItems = true; RefreshTimelineItems(); } if (m_newTimeline != nullptr) { m_cachedTimeline = m_newTimeline; m_newTimeline.reset(); } items.Clear(); items.RemoveDiscCache(GetID()); items.Assign(*m_cachedTimeline, false); group = m_cachedChannelGroup; } CDateTime startDate(group->GetFirstEPGDate()); CDateTime endDate(group->GetLastEPGDate()); CDateTime currentDate = CDateTime::GetCurrentDateTime().GetAsUTCDateTime(); if (!startDate.IsValid()) startDate = currentDate; if (!endDate.IsValid() || endDate < startDate) endDate = startDate; // limit start to linger time CDateTime maxPastDate = currentDate - CDateTimeSpan(0, 0, g_advancedSettings.m_iEpgLingerTime, 0); if (startDate < maxPastDate) startDate = maxPastDate; epgGridContainer->SetStartEnd(startDate, endDate); }
CPVRChannelGroupPtr CGUIWindowPVRChannels::SelectNextGroup(void) { CPVRChannelGroupPtr currentGroup = SelectedGroup(); CPVRChannelGroupPtr nextGroup = currentGroup->GetNextGroup(); while (nextGroup && *nextGroup != *currentGroup && nextGroup->Size() == 0) nextGroup = nextGroup->GetNextGroup(); /* always update so users can reset the list */ if (nextGroup) { SetSelectedGroup(nextGroup); UpdateData(); } return m_selectedGroup; }
bool CPVRChannelGroups::Update(const CPVRChannelGroup &group, bool bUpdateFromClient /* = false */) { if (group.GroupName().empty() && group.GroupID() <= 0) return true; CPVRChannelGroupPtr updateGroup; { CSingleLock lock(m_critSection); // There can be only one internal group! Make sure we never push a new one! if (group.IsInternalGroup()) updateGroup = GetGroupAll(); // try to find the group by id if (!updateGroup && group.GroupID() > 0) updateGroup = GetById(group.GroupID()); // try to find the group by name if we didn't find it yet if (!updateGroup) updateGroup = GetByName(group.GroupName()); if (!updateGroup) { // create a new group if none was found. Copy the properties immediately // so the group doesn't get flagged as "changed" further down. updateGroup = CPVRChannelGroupPtr(new CPVRChannelGroup(group.IsRadio(), group.GroupID(), group.GroupName())); m_groups.push_back(updateGroup); } updateGroup->SetRadio(group.IsRadio()); updateGroup->SetGroupID(group.GroupID()); updateGroup->SetGroupName(group.GroupName()); updateGroup->SetGroupType(group.GroupType()); updateGroup->SetPosition(group.GetPosition()); // don't override properties we only store locally in our PVR database if (!bUpdateFromClient) { updateGroup->SetLastWatched(group.LastWatched()); updateGroup->SetHidden(group.IsHidden()); } } // sort groups SortGroups(); // persist changes if (bUpdateFromClient) return updateGroup->Persist(); return true; }
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 CGUIDialogPVRChannelsOSD::OnAction(const CAction &action) { switch (action.GetID()) { case ACTION_PREVIOUS_CHANNELGROUP: case ACTION_NEXT_CHANNELGROUP: { CPVRChannelGroupPtr group = GetPlayingGroup(); CPVRChannelGroupPtr nextGroup = action.GetID() == ACTION_NEXT_CHANNELGROUP ? group->GetNextGroup() : group->GetPreviousGroup(); g_PVRManager.SetPlayingGroup(nextGroup); SetLastSelectedItem(group->GroupID()); Update(); return true; } } return CGUIDialog::OnAction(action); }
bool CPVRChannelGroups::Load(void) { CPVRDatabase *database = GetPVRDatabase(); 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; }
void CPVRManager::UpdateLastWatched(CPVRChannel &channel) { time_t tNow; CDateTime::GetCurrentDateTime().GetAsTime(tNow); // update last watched timestamp for channel // NOTE: method could be called with a fileitem copy as argument so we need to obtain the right channel instance CPVRChannelPtr channelPtr = m_channelGroups->GetChannelById(channel.ChannelID()); channelPtr->SetLastWatched(tNow); channelPtr->Persist(); // update last watched timestamp for group CPVRChannelGroupPtr group = GetPlayingGroup(channel.IsRadio()); group->SetLastWatched(tNow); group->Persist(); /* update last played group */ m_channelGroups->SetLastPlayedGroup(group); }
CPVRChannelPtr CPVRChannelGroupsContainer::GetByUniqueID(int iClientChannelNumber, int iClientID) { CPVRChannelPtr channel; CPVRChannelGroupPtr channelgroup = GetGroupAllTV(); /* First try to find the channel in the all tv channels group */ if (channelgroup) channel = channelgroup->GetByClient(iClientChannelNumber, iClientID); if (!channelgroup || !channel) { /* Channel or group not found, try the all radio channels group instead */ channelgroup = GetGroupAllRadio(); if (channelgroup) channel = channelgroup->GetByClient(iClientChannelNumber, iClientID); } return channel; }
void CGUIDialogPVRChannelManager::SaveList(void) { if (!m_bContainsChanges) return; /* display the progress dialog */ 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); /* persist all channels */ unsigned int iNextChannelNumber(0); CPVRChannelGroupPtr group = g_PVRChannelGroups->GetGroupAll(m_bIsRadio); if (!group) return; for (int iListPtr = 0; iListPtr < m_channelItems->Size(); iListPtr++) { CFileItemPtr pItem = m_channelItems->Get(iListPtr); if (!pItem->HasPVRChannelInfoTag()) continue; if (pItem->GetProperty("SupportsSettings").asBoolean()) RenameChannel(pItem); PersistChannel(pItem, group, &iNextChannelNumber); pDlgProgress->SetPercentage(iListPtr * 100 / m_channelItems->Size()); } group->SortAndRenumber(); group->Persist(); m_bContainsChanges = false; SetItemsUnchanged(); pDlgProgress->Close(); }
CPVRChannelPtr CPVRGUIChannelNavigator::GetNextOrPrevChannel(bool bNext) { const bool bPlayingRadio = CServiceBroker::GetPVRManager().IsPlayingRadio(); const bool bPlayingTV = CServiceBroker::GetPVRManager().IsPlayingTV(); if (bPlayingTV || bPlayingRadio) { const CPVRChannelGroupPtr group = CServiceBroker::GetPVRManager().GetPlayingGroup(bPlayingRadio); if (group) { CSingleLock lock(m_critSection); const CFileItemPtr item = bNext ? group->GetNextChannel(m_currentChannel) : group->GetPreviousChannel(m_currentChannel);; if (item) return item->GetPVRChannelInfoTag(); } } return CPVRChannelPtr(); }
bool CPVRManager::ChannelSwitch(unsigned int iChannelNumber) { CSingleLock lock(m_critSection); CPVRChannelGroupPtr playingGroup = GetPlayingGroup(m_addons->IsPlayingRadio()); if (!playingGroup) { CLog::Log(LOGERROR, "PVRManager - %s - cannot get the selected group", __FUNCTION__); return false; } CFileItemPtr channel = playingGroup->GetByChannelNumber(iChannelNumber); if (!channel || !channel->HasPVRChannelInfoTag()) { CLog::Log(LOGERROR, "PVRManager - %s - cannot find channel %d", __FUNCTION__, iChannelNumber); return false; } return PerformChannelSwitch(*channel->GetPVRChannelInfoTag(), false); }
void CPVRManager::CloseStream(void) { CPVRChannelPtr channel; CPVRChannelGroupPtr group; bool bPersistChanges(false); { CSingleLock lock(m_critSection); if (m_addons->GetPlayingChannel(channel)) { time_t tNow; CDateTime::GetCurrentDateTime().GetAsTime(tNow); /* update last watched timestamp for channel */ channel->SetLastWatched(tNow); /* update last watched timestamp for group */ group = g_PVRManager.GetPlayingGroup(channel->IsRadio()); group->SetLastWatched(tNow); /* update last played group */ m_channelGroups->SetLastPlayedGroup(group); bPersistChanges = true; // store channel settings g_application.SaveFileState(); } m_addons->CloseStream(); SAFE_DELETE(m_currentFile); } if (bPersistChanges) { channel->Persist(); group->Persist(); } }
bool CGUIWindowPVRChannels::OnContextButtonLock(CFileItem *item, CONTEXT_BUTTON button) { bool bReturn = false; if (button == CONTEXT_BUTTON_ADD_LOCK) { // ask for PIN first if (!g_PVRManager.CheckParentalPIN(g_localizeStrings.Get(19262).c_str())) return bReturn; CPVRChannelGroupPtr group = g_PVRChannelGroups->GetGroupAll(m_bRadio); if (!group) return bReturn; group->ToggleChannelLocked(*item); UpdateData(); bReturn = true; } return bReturn; }
bool CPVRChannelGroups::AddGroup(const CStdString &strName) { bool bPersist(false); CPVRChannelGroupPtr group; { CSingleLock lock(m_critSection); // check if there's no group with the same name yet group = GetByName(strName); if (!group) { // create a new group group = CPVRChannelGroupPtr(new CPVRChannelGroup(m_bRadio, -1, strName)); m_groups.push_back(group); bPersist = true; } } // persist in the db if a new group was added return bPersist ? group->Persist() : true; }
void CPVROperations::FillChannelGroupDetails(const CPVRChannelGroupPtr &channelGroup, const CVariant ¶meterObject, CVariant &result, bool append /* = false */) { if (channelGroup == NULL) return; CVariant object(CVariant::VariantTypeObject); object["channelgroupid"] = channelGroup->GroupID(); object["channeltype"] = channelGroup->IsRadio() ? "radio" : "tv"; object["label"] = channelGroup->GroupName(); if (append) result.append(object); else { CFileItemList channels; channelGroup->GetMembers(channels); object["channels"] = CVariant(CVariant::VariantTypeArray); HandleFileItemList("channelid", false, "channels", channels, parameterObject["channels"], object, false); result = object; } }
bool CPVRChannelGroups::AddGroup(const std::string &strName) { bool bPersist(false); CPVRChannelGroupPtr group; { CSingleLock lock(m_critSection); // check if there's no group with the same name yet group = GetByName(strName); if (!group) { // create a new group group.reset(new CPVRChannelGroup(m_bRadio, CPVRChannelGroup::INVALID_GROUP_ID, strName, GetGroupAll())); m_groups.push_back(group); bPersist = true; } } // persist in the db if a new group was added return bPersist ? group->Persist() : true; }
CFileItemPtr CPVRChannelGroupsContainer::GetByChannelIDFromAll(int iChannelID) { CPVRChannelPtr channel; CPVRChannelGroupPtr channelgroup = GetGroupAllTV(); if (channelgroup) channel = channelgroup->GetByChannelID(iChannelID); if (!channel) { channelgroup = GetGroupAllRadio(); if (channelgroup) channel = channelgroup->GetByChannelID(iChannelID); } if (channel) { CFileItemPtr retVal = CFileItemPtr(new CFileItem(*channel)); return retVal; } CFileItemPtr retVal = CFileItemPtr(new CFileItem); return retVal; }
bool CGUIWindowPVRGuide::RefreshTimelineItems() { if (m_bRefreshTimelineItems) { m_bRefreshTimelineItems = false; CPVRChannelGroupPtr group = GetGroup(); std::shared_ptr<CFileItemList> timeline = std::make_shared<CFileItemList>(); // can be very expensive. never call with lock aquired. group->GetEPGAll(*timeline, true); { CSingleLock lock(m_critSection); m_newTimeline = timeline; m_cachedChannelGroup = group; } return true; } return false; }
bool CGUIDialogPVRChannelsOSD::OnAction(const CAction &action) { switch (action.GetID()) { case ACTION_PREVIOUS_CHANNELGROUP: case ACTION_NEXT_CHANNELGROUP: { // save control states and currently selected item of group SaveControlStates(); // switch to next or previous group CPVRChannelGroupPtr group = GetPlayingGroup(); CPVRChannelGroupPtr nextGroup = action.GetID() == ACTION_NEXT_CHANNELGROUP ? group->GetNextGroup() : group->GetPreviousGroup(); g_PVRManager.SetPlayingGroup(nextGroup); Update(); // restore control states and previously selected item of group RestoreControlStates(); return true; } } return CGUIDialog::OnAction(action); }
void CPVRChannel::UpdatePath(unsigned int iNewChannelNumber) { CStdString strFileNameAndPath; CSingleLock lock(m_critSection); CPVRChannelGroupPtr group = g_PVRChannelGroups->GetGroupAll(m_bIsRadio); if (group) { strFileNameAndPath.Format("pvr://channels/%s/%s/%i.pvr", (m_bIsRadio ? "radio" : "tv"), group->GroupName().c_str(), iNewChannelNumber); if (m_strFileNameAndPath != strFileNameAndPath) { m_strFileNameAndPath = strFileNameAndPath; SetChanged(); } } }
bool CGUIDialogPVRChannelManager::PersistChannel(CFileItemPtr pItem, CPVRChannelGroupPtr group, unsigned int *iChannelNumber) { if (!pItem || !pItem->HasPVRChannelInfoTag() || !group) return false; /* get values from the form */ bool bHidden = !pItem->GetProperty("ActiveChannel").asBoolean(); bool bEPGEnabled = pItem->GetProperty("UseEPG").asBoolean(); bool bParentalLocked = pItem->GetProperty("ParentalLocked").asBoolean(); int iEPGSource = (int)pItem->GetProperty("EPGSource").asInteger(); std::string strChannelName= pItem->GetProperty("Name").asString(); std::string strIconPath = pItem->GetProperty("Icon").asString(); std::string strStreamURL = pItem->GetProperty("StreamURL").asString(); bool bUserSetIcon = pItem->GetProperty("UserSetIcon").asBoolean(); return group->UpdateChannel(*pItem, bHidden, bEPGEnabled, bParentalLocked, iEPGSource, ++(*iChannelNumber), strChannelName, strIconPath, strStreamURL, bUserSetIcon); }
bool CPVRChannelGroups::Update(const CPVRChannelGroup &group, bool bSaveInDb) { if (group.GroupName().empty() && group.GroupID() <= 0) return true; CPVRChannelGroupPtr updateGroup; { CSingleLock lock(m_critSection); // try to find the group by id if (group.GroupID() > 0) updateGroup = GetById(group.GroupID()); // try to find the group by name if we didn't find it yet if (!updateGroup) updateGroup = GetByName(group.GroupName()); if (!updateGroup) { // create a new group if none was found updateGroup = CPVRChannelGroupPtr(new CPVRChannelGroup(m_bRadio, group.GroupID(), group.GroupName())); updateGroup->SetGroupType(group.GroupType()); updateGroup->SetLastWatched(group.LastWatched()); m_groups.push_back(updateGroup); } else { // update existing group updateGroup->SetGroupID(group.GroupID()); updateGroup->SetGroupName(group.GroupName()); updateGroup->SetGroupType(group.GroupType()); } } // persist changes if (bSaveInDb && updateGroup) return updateGroup->Persist(); return true; }
CPVRChannelGroupPtr CGUIWindowPVRChannels::SelectNextGroup(void) { CPVRChannelGroupPtr currentGroup = SelectedGroup(); CPVRChannelGroupPtr nextGroup = currentGroup->GetNextGroup(); while (nextGroup && nextGroup->Size() == 0 && // break if the group matches *nextGroup != *currentGroup && // or if we hit the first group !nextGroup->IsInternalGroup()) nextGroup = nextGroup->GetNextGroup(); /* always update so users can reset the list */ if (nextGroup) { SetSelectedGroup(nextGroup); UpdateData(); } return m_selectedGroup; }