Skip to content

Commit

Permalink
[PVR] Refactor channel group's path handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
ksooo committed Jan 15, 2018
1 parent 89ea0b5 commit 2250dcc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 19 deletions.
5 changes: 2 additions & 3 deletions xbmc/pvr/channels/PVRChannel.cpp
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions xbmc/pvr/channels/PVRChannelGroup.cpp
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions xbmc/pvr/channels/PVRChannelGroup.h
Expand Up @@ -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.
Expand Down
27 changes: 11 additions & 16 deletions xbmc/pvr/channels/PVRChannelGroups.cpp
Expand Up @@ -133,34 +133,31 @@ 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<CPVRChannelGroupPtr>::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<std::string> split(StringUtils::Split(strFileName, '_', 2));
strPath.erase(0, strCheckPath.size());
std::vector<std::string> 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));
}
}
}

// no match
CFileItemPtr retVal(new CFileItem);
return retVal;
return CFileItemPtr(new CFileItem());
}

CPVRChannelGroupPtr CPVRChannelGroups::GetById(int iGroupId) const
Expand Down Expand Up @@ -392,15 +389,13 @@ int CPVRChannelGroups::GetGroupList(CFileItemList* results, bool bExcludeHidden
int iReturn(0);
CSingleLock lock(m_critSection);

std::string strPath;
for (std::vector<CPVRChannelGroupPtr>::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);
Expand Down

0 comments on commit 2250dcc

Please sign in to comment.