From 2250dcc9ad11d1f093f2eeacd70ec7e26dfd9ace Mon Sep 17 00:00:00 2001 From: Kai Sommerfeld Date: Sat, 13 Jan 2018 14:30:53 +0100 Subject: [PATCH] [PVR] Refactor channel group's path handling. --- xbmc/pvr/channels/PVRChannel.cpp | 5 ++--- xbmc/pvr/channels/PVRChannelGroup.cpp | 5 +++++ xbmc/pvr/channels/PVRChannelGroup.h | 6 ++++++ xbmc/pvr/channels/PVRChannelGroups.cpp | 27 +++++++++++--------------- 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/xbmc/pvr/channels/PVRChannel.cpp b/xbmc/pvr/channels/PVRChannel.cpp index e0a093953528f..5125d7476254e 100644 --- a/xbmc/pvr/channels/PVRChannel.cpp +++ b/xbmc/pvr/channels/PVRChannel.cpp @@ -407,9 +407,8 @@ void CPVRChannel::UpdatePath(CPVRChannelGroupInternal* group) std::string strFileNameAndPath; CSingleLock lock(m_critSection); - strFileNameAndPath = StringUtils::Format("pvr://channels/%s/%s/%s_%d.pvr", - (m_bIsRadio ? "radio" : "tv"), - group->GroupName().c_str(), + strFileNameAndPath = StringUtils::Format("%s%s_%d.pvr", + group->GetPath(), CServiceBroker::GetPVRManager().Clients()->GetClientAddonId(m_iClientId).c_str(), m_iUniqueId); if (m_strFileNameAndPath != strFileNameAndPath) diff --git a/xbmc/pvr/channels/PVRChannelGroup.cpp b/xbmc/pvr/channels/PVRChannelGroup.cpp index 6468ca041a86f..9163e80248301 100644 --- a/xbmc/pvr/channels/PVRChannelGroup.cpp +++ b/xbmc/pvr/channels/PVRChannelGroup.cpp @@ -204,6 +204,11 @@ bool CPVRChannelGroup::Update(void) return UpdateGroupEntries(PVRChannels_tmp); } +std::string CPVRChannelGroup::GetPath() const +{ + return StringUtils::Format("pvr://channels/%s/%s/", m_bRadio ? "radio" : "tv", GroupName().c_str()); +} + bool CPVRChannelGroup::SetChannelNumber(const CPVRChannelPtr &channel, const CPVRChannelNumber &channelNumber) { bool bReturn(false); diff --git a/xbmc/pvr/channels/PVRChannelGroup.h b/xbmc/pvr/channels/PVRChannelGroup.h index b0210f79a5aa6..65f9897196692 100644 --- a/xbmc/pvr/channels/PVRChannelGroup.h +++ b/xbmc/pvr/channels/PVRChannelGroup.h @@ -117,6 +117,12 @@ namespace PVR */ virtual bool Update(void); + /*! + * @brief Get the path of this group. + * @return the path. + */ + std::string GetPath() const; + /*! * @brief Change the channelnumber of a group. Used by CGUIDialogPVRChannelManager. Call SortByChannelNumber() and Renumber() after all changes are done. * @param channel The channel to change the channel number for. diff --git a/xbmc/pvr/channels/PVRChannelGroups.cpp b/xbmc/pvr/channels/PVRChannelGroups.cpp index e75ae0e809658..7c2bf6db6c3e3 100644 --- a/xbmc/pvr/channels/PVRChannelGroups.cpp +++ b/xbmc/pvr/channels/PVRChannelGroups.cpp @@ -133,25 +133,23 @@ void CPVRChannelGroups::SortGroups() } } -CFileItemPtr CPVRChannelGroups::GetByPath(const std::string &strPath) const +CFileItemPtr CPVRChannelGroups::GetByPath(const std::string &strInPath) const { - // get the filename from curl - CURL url(strPath); - std::string strFileName = url.GetFileName(); - URIUtils::RemoveSlashAtEnd(strFileName); + std::string strPath = strInPath; + URIUtils::RemoveSlashAtEnd(strPath); std::string strCheckPath; - for (std::vector::const_iterator it = m_groups.begin(); it != m_groups.end(); ++it) + for (const auto& group: m_groups) { // check if the path matches - strCheckPath = StringUtils::Format("channels/%s/%s/", (*it)->IsRadio() ? "radio" : "tv", (*it)->GroupName().c_str()); - if (URIUtils::PathHasParent(strFileName, strCheckPath)) + strCheckPath = group->GetPath(); + if (URIUtils::PathHasParent(strPath, strCheckPath)) { - strFileName.erase(0, strCheckPath.length()); - std::vector split(StringUtils::Split(strFileName, '_', 2)); + strPath.erase(0, strCheckPath.size()); + std::vector split(StringUtils::Split(strPath, '_', 2)); if (split.size() == 2) { - CPVRChannelPtr channel((*it)->GetByUniqueID(atoi(split[1].c_str()), CServiceBroker::GetPVRManager().Clients()->GetClientId(split[0]))); + const CPVRChannelPtr channel = group->GetByUniqueID(atoi(split[1].c_str()), CServiceBroker::GetPVRManager().Clients()->GetClientId(split[0])); if (channel) return CFileItemPtr(new CFileItem(channel)); } @@ -159,8 +157,7 @@ CFileItemPtr CPVRChannelGroups::GetByPath(const std::string &strPath) const } // no match - CFileItemPtr retVal(new CFileItem); - return retVal; + return CFileItemPtr(new CFileItem()); } CPVRChannelGroupPtr CPVRChannelGroups::GetById(int iGroupId) const @@ -392,15 +389,13 @@ int CPVRChannelGroups::GetGroupList(CFileItemList* results, bool bExcludeHidden int iReturn(0); CSingleLock lock(m_critSection); - std::string strPath; for (std::vector::const_iterator it = m_groups.begin(); it != m_groups.end(); ++it) { // exclude hidden groups if desired if (bExcludeHidden && (*it)->IsHidden()) continue; - strPath = StringUtils::Format("pvr://channels/%s/%s/", m_bRadio ? "radio" : "tv", (*it)->GroupName().c_str()); - CFileItemPtr group(new CFileItem(strPath, true)); + CFileItemPtr group(new CFileItem((*it)->GetPath(), true)); group->m_strTitle = (*it)->GroupName(); group->SetLabel((*it)->GroupName()); results->Add(group);