Merge pull request #4477 from xhaggi/pvr-icon-fixes
authorjmarshallnz <jcmarsha@gmail.com>
Wed, 26 Mar 2014 18:52:33 +0000 (07:52 +1300)
committerTrent Nelson <trent.a.b.nelson@gmail.com>
Thu, 27 Mar 2014 01:51:41 +0000 (19:51 -0600)
[pvr] fixes related to chanel icons

xbmc/pvr/channels/PVRChannel.cpp
xbmc/pvr/channels/PVRChannel.h
xbmc/pvr/channels/PVRChannelGroup.cpp
xbmc/pvr/channels/PVRChannelGroup.h
xbmc/pvr/dialogs/GUIDialogPVRChannelManager.cpp

index 1bc9b16..8a0d5af 100644 (file)
@@ -309,10 +309,7 @@ bool CPVRChannel::SetIconPath(const CStdString &strIconPath, bool bIsUserSetIcon
     m_strIconPath = StringUtils::Format("%s", strIconPath.c_str());
     SetChanged();
     m_bChanged = true;
-
-    /* did the user change the icon? */
-    if (bIsUserSetIcon)
-      m_bIsUserSetIcon = !m_strIconPath.empty();
+    m_bIsUserSetIcon = bIsUserSetIcon && !m_strIconPath.empty();
          
     return true;
   }
@@ -753,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);
index 74fd087..999996f 100644 (file)
@@ -155,7 +155,12 @@ 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.
index 6429924..0ec84b4 100644 (file)
@@ -255,31 +255,56 @@ void CPVRChannelGroup::SearchAndSetChannelIcons(bool bUpdateDb /* = false */)
   {
     PVRChannelGroupMember groupMember = m_members.at(ptr);
 
-    /* skip if an icon is already set */
-    if (!groupMember.channel->IconPath().empty())
+    /* skip if an icon is already set and exists */
+    if (groupMember.channel->IsIconExists())
       continue;
 
-    CStdString strBasePath = CSettings::Get().GetString("pvrmenu.iconpath");
-    CStdString strSanitizedChannelName = CUtil::MakeLegalFileName(groupMember.channel->ClientChannelName());
+    /* reset icon before searching for a new one */
+    groupMember.channel->SetIconPath(StringUtils::Empty);
 
-    CStdString strIconPath = strBasePath + strSanitizedChannelName;
-    StringUtils::ToLower(strSanitizedChannelName);
-    CStdString strIconPathLower = strBasePath + strSanitizedChannelName;
+    CStdString strBasePath = CSettings::Get().GetString("pvrmenu.iconpath");
+    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");
+      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;
+      CStdString strSanitizedLowerChannelName = strSanitizedChannelName;
+      StringUtils::ToLower(strSanitizedLowerChannelName);
+      CStdString strIconPathLower2 = strBasePath + strSanitizedLowerChannelName;
+
+      if (strIconPathLower != strIconPathLower2)
+      {
+        SetChannelIconPath(groupMember.channel, strIconPath2 + ".tbn") ||
+        SetChannelIconPath(groupMember.channel, strIconPath2 + ".jpg") ||
+        SetChannelIconPath(groupMember.channel, strIconPath2 + ".png") ||
+
+        SetChannelIconPath(groupMember.channel, strIconPathLower2 + ".tbn") ||
+        SetChannelIconPath(groupMember.channel, strIconPathLower2 + ".jpg") ||
+        SetChannelIconPath(groupMember.channel, strIconPathLower2 + ".png");
+      } 
+    }
 
     if (bUpdateDb)
       groupMember.channel->Persist();
@@ -1207,7 +1232,7 @@ void CPVRChannelGroup::SetPreventSortAndRenumber(bool bPreventSortAndRenumber /*
   m_bPreventSortAndRenumber = bPreventSortAndRenumber;
 }
 
-bool CPVRChannelGroup::UpdateChannel(const CFileItem &item, bool bHidden, bool bVirtual, bool bEPGEnabled, bool bParentalLocked, int iEPGSource, int iChannelNumber, const CStdString &strChannelName, const CStdString &strIconPath, const CStdString &strStreamURL)
+bool CPVRChannelGroup::UpdateChannel(const CFileItem &item, bool bHidden, bool bVirtual, bool bEPGEnabled, bool bParentalLocked, int iEPGSource, int iChannelNumber, const CStdString &strChannelName, const CStdString &strIconPath, const CStdString &strStreamURL, bool bUserSetIcon)
 {
   if (!item.HasPVRChannelInfoTag())
     return false;
@@ -1222,7 +1247,7 @@ bool CPVRChannelGroup::UpdateChannel(const CFileItem &item, bool bHidden, bool b
   channel->SetChannelName(strChannelName);
   channel->SetHidden(bHidden);
   channel->SetLocked(bParentalLocked);
-  channel->SetIconPath(strIconPath);
+  channel->SetIconPath(strIconPath, bUserSetIcon);
 
   if (bVirtual)
     channel->SetStreamURL(strStreamURL);
index 0260e9d..61b3cfb 100644 (file)
@@ -384,7 +384,7 @@ namespace PVR
      */
     CDateTime GetLastEPGDate(void) const;
 
-    bool UpdateChannel(const CFileItem &channel, bool bHidden, bool bVirtual, bool bEPGEnabled, bool bParentalLocked, int iEPGSource, int iChannelNumber, const CStdString &strChannelName, const CStdString &strIconPath, const CStdString &strStreamURL);
+    bool UpdateChannel(const CFileItem &channel, bool bHidden, bool bVirtual, bool bEPGEnabled, bool bParentalLocked, int iEPGSource, int iChannelNumber, const CStdString &strChannelName, const CStdString &strIconPath, const CStdString &strStreamURL, bool bUserSetIcon = false);
 
     bool ToggleChannelLocked(const CFileItem &channel);
 
index 5f70aa0..afe6d38 100644 (file)
@@ -359,6 +359,7 @@ bool CGUIDialogPVRChannelManager::OnClickButtonChannelLogo(CGUIMessage &message)
 
   pItem->SetProperty("Icon", strThumb);
   pItem->SetProperty("Changed", true);
+  pItem->SetProperty("UserSetIcon", true);
   m_bContainsChanges = true;
   return true;
 }
@@ -773,8 +774,9 @@ bool CGUIDialogPVRChannelManager::PersistChannel(CFileItemPtr pItem, CPVRChannel
   CStdString strChannelName = pItem->GetProperty("Name").asString();
   CStdString strIconPath    = pItem->GetProperty("Icon").asString();
   CStdString strStreamURL   = pItem->GetProperty("StreamURL").asString();
+  bool bUserSetIcon         = pItem->GetProperty("UserSetIcon").asBoolean();
 
-  return group->UpdateChannel(*pItem, bHidden, bVirtual, bEPGEnabled, bParentalLocked, iEPGSource, ++(*iChannelNumber), strChannelName, strIconPath, strStreamURL);
+  return group->UpdateChannel(*pItem, bHidden, bVirtual, bEPGEnabled, bParentalLocked, iEPGSource, ++(*iChannelNumber), strChannelName, strIconPath, strStreamURL, bUserSetIcon);
 }
 
 void CGUIDialogPVRChannelManager::SaveList(void)