Skip to content

Commit

Permalink
[PVR] If a user set a custom name for the pvr channel, this name shou…
Browse files Browse the repository at this point in the history
…ld be used too when searching icons
  • Loading branch information
Alexandre Maloteaux committed Mar 25, 2014
1 parent 165578b commit d88053a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 50 deletions.
14 changes: 7 additions & 7 deletions xbmc/pvr/channels/PVRChannel.cpp
Expand Up @@ -299,7 +299,7 @@ bool CPVRChannel::IsRecording(void) const
return g_PVRTimers->IsRecordingOnChannel(*this);
}

bool CPVRChannel::SetIconPath(const CStdString &strIconPath, bool bIsUserSetIcon /* = false */, bool bForceUserSetIconUpdate /* = false*/)
bool CPVRChannel::SetIconPath(const CStdString &strIconPath, bool bIsUserSetIcon /* = false */)
{
CSingleLock lock(m_critSection);

Expand All @@ -309,12 +309,7 @@ bool CPVRChannel::SetIconPath(const CStdString &strIconPath, bool bIsUserSetIcon
m_strIconPath = StringUtils::Format("%s", strIconPath.c_str());
SetChanged();
m_bChanged = true;

if (bForceUserSetIconUpdate )
m_bIsUserSetIcon = bIsUserSetIcon;
/* did the user change the icon? */
else if (bIsUserSetIcon)
m_bIsUserSetIcon = !m_strIconPath.empty();
m_bIsUserSetIcon = bIsUserSetIcon;

return true;
}
Expand Down Expand Up @@ -755,6 +750,11 @@ bool CPVRChannel::IsUserSetIcon(void) const
return m_bIsUserSetIcon;
}

bool CPVRChannel::IsIconExists() const
{
return CFile::Exists(IconPath());
}

CStdString CPVRChannel::ChannelName(void) const
{
CSingleLock lock(m_critSection);
Expand Down
10 changes: 7 additions & 3 deletions xbmc/pvr/channels/PVRChannel.h
Expand Up @@ -155,15 +155,19 @@ namespace PVR
* @return True if this user changed icon via GUI. False if not.
*/
bool IsUserSetIcon(void) const;


/*!
* @return True if the channel icon path exists
*/
bool IsIconExists(void) const;

/*!
* @brief Set the path to the icon for this channel.
* @param strIconPath The new path.
* @param bIsUserSetIcon true if user changed the icon via GUI, false otherwise.
* @param bForceUserSetIconUpdate true if UserSetIcon need to be updated even if IconPath is Empty
* @return True if the something changed, false otherwise.
*/
bool SetIconPath(const CStdString &strIconPath, bool bIsUserSetIcon = false, bool bForceUserSetIconUpdate = false);
bool SetIconPath(const CStdString &strIconPath, bool bIsUserSetIcon = false);

/*!
* @return The name for this channel used by XBMC.
Expand Down
79 changes: 48 additions & 31 deletions xbmc/pvr/channels/PVRChannelGroup.cpp
Expand Up @@ -240,17 +240,6 @@ bool CPVRChannelGroup::SetChannelIconPath(CPVRChannelPtr channel, const std::str
return false;
}

bool CPVRChannelGroup::VerifyChannelIconPath(CPVRChannelPtr channel)
{
if (CFile::Exists(channel->IconPath()))
return true;
else
{
channel->SetIconPath(std::string(), false, true);
return false;
}
}

void CPVRChannelGroup::SearchAndSetChannelIcons(bool bUpdateDb /* = false */)
{
if (CSettings::Get().GetString("pvrmenu.iconpath").empty())
Expand All @@ -266,35 +255,63 @@ void CPVRChannelGroup::SearchAndSetChannelIcons(bool bUpdateDb /* = false */)
{
PVRChannelGroupMember groupMember = m_members.at(ptr);

/* skip if an icon is already set */
if (!groupMember.channel->IconPath().empty())
{
//check if the file exist or empty it
if(VerifyChannelIconPath(groupMember.channel))
/* skip if an icon is already set and exists*/
if (!groupMember.channel->IsIconExists())
groupMember.channel->SetIconPath(std::string(), false);

This comment has been minimized.

Copy link
@xhaggi

xhaggi Mar 25, 2014

please use StringUtils::Empty instead of std:string()

else
continue;
}

CStdString strBasePath = CSettings::Get().GetString("pvrmenu.iconpath");
CStdString strSanitizedChannelName = CUtil::MakeLegalFileName(groupMember.channel->ClientChannelName());

CStdString strIconPath = strBasePath + strSanitizedChannelName;
StringUtils::ToLower(strSanitizedChannelName);
CStdString strIconPathLower = strBasePath + strSanitizedChannelName;
CStdString strSanitizedClientChannelName = CUtil::MakeLegalFileName(groupMember.channel->ClientChannelName());
CStdString strIconPath = strBasePath + strSanitizedClientChannelName;
StringUtils::ToLower(strSanitizedClientChannelName);
CStdString strIconPathLower = strBasePath + strSanitizedClientChannelName;
CStdString strIconPathUid;
strIconPathUid = StringUtils::Format("%08d", groupMember.channel->UniqueID());
strIconPathUid = URIUtils::AddFileToFolder(strBasePath, strIconPathUid);

SetChannelIconPath(groupMember.channel, strIconPath + ".tbn") ||
SetChannelIconPath(groupMember.channel, strIconPath + ".jpg") ||
SetChannelIconPath(groupMember.channel, strIconPath + ".png") ||
bool bIconFound =
SetChannelIconPath(groupMember.channel, strIconPath + ".tbn") ||
SetChannelIconPath(groupMember.channel, strIconPath + ".jpg") ||
SetChannelIconPath(groupMember.channel, strIconPath + ".png") ||

SetChannelIconPath(groupMember.channel, strIconPathLower + ".tbn") ||
SetChannelIconPath(groupMember.channel, strIconPathLower + ".jpg") ||
SetChannelIconPath(groupMember.channel, strIconPathLower + ".png") ||

SetChannelIconPath(groupMember.channel, strIconPathLower + ".tbn") ||
SetChannelIconPath(groupMember.channel, strIconPathLower + ".jpg") ||
SetChannelIconPath(groupMember.channel, strIconPathLower + ".png") ||
SetChannelIconPath(groupMember.channel, strIconPathUid + ".tbn") ||
SetChannelIconPath(groupMember.channel, strIconPathUid + ".jpg") ||
SetChannelIconPath(groupMember.channel, strIconPathUid + ".png");

// Lets do the same with the DB Channel Name if those are different
if(!bIconFound)
{
CStdString strSanitizedChannelName = CUtil::MakeLegalFileName(groupMember.channel->ChannelName());
CStdString strIconPath2 = strBasePath + strSanitizedChannelName;

SetChannelIconPath(groupMember.channel, strIconPathUid + ".tbn") ||
SetChannelIconPath(groupMember.channel, strIconPathUid + ".jpg") ||
SetChannelIconPath(groupMember.channel, strIconPathUid + ".png");
if(strIconPath2 != strIconPath)
{
bIconFound =
SetChannelIconPath(groupMember.channel, strIconPath2 + ".tbn") ||
SetChannelIconPath(groupMember.channel, strIconPath2 + ".jpg") ||
SetChannelIconPath(groupMember.channel, strIconPath2 + ".png") ;

if(!bIconFound)
{
CStdString strSanitizedLowerChannelName = strSanitizedChannelName;
StringUtils::ToLower(strSanitizedLowerChannelName);
CStdString strIconPathLower2 = strBasePath + strSanitizedLowerChannelName;
// Do not search Lowercase if user only changed a letter case ...
if(strIconPathLower2 != strIconPathLower)
{
SetChannelIconPath(groupMember.channel, strIconPathLower2 + ".tbn") ||
SetChannelIconPath(groupMember.channel, strIconPathLower2 + ".jpg") ||
SetChannelIconPath(groupMember.channel, strIconPathLower2 + ".png") ;
}
}
}
}

if (bUpdateDb)
groupMember.channel->Persist();
Expand Down
8 changes: 0 additions & 8 deletions xbmc/pvr/channels/PVRChannelGroup.h
Expand Up @@ -417,14 +417,6 @@ namespace PVR
*/
bool SetChannelIconPath(CPVRChannelPtr channel, const std::string& strIconPath);

/*!
* @brief Verify that Icon path exists and empty it if not
* @param channel The channel to verify
* @return True if the path exists and is not updated, false otherwise
*/

bool VerifyChannelIconPath(CPVRChannelPtr channel);

/*!
* @brief Load the channels stored in the database.
* @param bCompress If true, compress the database after storing the channels.
Expand Down
2 changes: 1 addition & 1 deletion xbmc/pvr/windows/GUIWindowPVRChannels.cpp
Expand Up @@ -500,7 +500,7 @@ bool CGUIWindowPVRChannels::OnContextButtonSetThumb(CFileItem *item, CONTEXT_BUT
CPVRChannelGroupPtr group = g_PVRChannelGroups->GetGroupAll(channel->IsRadio());
CPVRChannelPtr channelPtr = group->GetByUniqueID(channel->UniqueID());

channelPtr->SetIconPath(strThumb, true);
channelPtr->SetIconPath(strThumb, strThumb != "");
channelPtr->Persist();
UpdateData();
}
Expand Down

0 comments on commit d88053a

Please sign in to comment.