aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmarshallnz <jcmarsha@gmail.com>2014-05-09 10:41:57 +1200
committerjmarshallnz <jcmarsha@gmail.com>2014-05-09 10:41:57 +1200
commitdacb5858a60dc78274edc08e83f8e532c21b07d5 (patch)
tree7f778b53602ce490b2f4d50e416781baba8bb03a
parent3dcd99f5d7b50b565159da0e8a5f13e7aa126249 (diff)
parentc7d8fcf17a8ce160fe9cf1a775b896cd4b399b31 (diff)
Merge pull request #4657 from xhaggi/channel-icon-scan
[pvr] rewrite of implementation for search of missing channel icons
-rwxr-xr-xlanguage/English/strings.po8
-rw-r--r--xbmc/pvr/PVRManager.cpp20
-rw-r--r--xbmc/pvr/PVRManager.h15
-rw-r--r--xbmc/pvr/channels/PVRChannelGroup.cpp110
-rw-r--r--xbmc/pvr/channels/PVRChannelGroup.h8
-rw-r--r--xbmc/pvr/channels/PVRChannelGroupsContainer.cpp3
6 files changed, 92 insertions, 72 deletions
diff --git a/language/English/strings.po b/language/English/strings.po
index a0e4d87546..0f3946c3df 100755
--- a/language/English/strings.po
+++ b/language/English/strings.po
@@ -8511,7 +8511,13 @@ msgctxt "#19285"
msgid "Browse for icon"
msgstr ""
-#empty strings from id 19286 to 19498
+#. Notification message if process starts searching for missing channel icons
+#: xbmc/pvr/PVRManager.cpp
+msgctxt "#19286"
+msgid "Searching for channel icons"
+msgstr ""
+
+#empty strings from id 19287 to 19498
#: xbmc/epg/Epg.cpp
msgctxt "#19499"
diff --git a/xbmc/pvr/PVRManager.cpp b/xbmc/pvr/PVRManager.cpp
index d9fe81b87e..13da2bd106 100644
--- a/xbmc/pvr/PVRManager.cpp
+++ b/xbmc/pvr/PVRManager.cpp
@@ -144,7 +144,7 @@ void CPVRManager::OnSettingAction(const CSetting *setting)
if (settingId == "pvrmenu.searchicons")
{
if (IsStarted())
- SearchMissingChannelIcons();
+ TriggerSearchMissingChannelIcons();
}
else if (settingId == "pvrmanager.resetdb")
{
@@ -449,13 +449,18 @@ void CPVRManager::Process(void)
bool bRestart(false);
while (IsStarted() && m_addons && m_addons->HasConnectedClients() && !bRestart)
{
- /* continue last watched channel after first startup */
+ /* first startup */
if (m_bFirstStart)
{
{
CSingleLock lock(m_critSection);
m_bFirstStart = false;
}
+
+ /* start job to search for missing channel icons */
+ TriggerSearchMissingChannelIcons();
+
+ /* continue last watched channel */
ContinueLastChannel();
}
/* execute the next pending jobs if there are any */
@@ -1455,6 +1460,11 @@ void CPVRManager::TriggerSaveChannelSettings(void)
QueueJob(new CPVRChannelSettingsSaveJob());
}
+void CPVRManager::TriggerSearchMissingChannelIcons(void)
+{
+ CJobManager::GetInstance().AddJob(new CPVRSearchMissingChannelIconsJob(), NULL);
+}
+
void CPVRManager::ExecutePendingJobs(void)
{
CSingleLock lock(m_critSectionTriggers);
@@ -1539,6 +1549,12 @@ bool CPVRChannelSwitchJob::DoWork(void)
return true;
}
+bool CPVRSearchMissingChannelIconsJob::DoWork(void)
+{
+ g_PVRManager.SearchMissingChannelIcons();
+ return true;
+}
+
bool CPVRManager::CreateChannelEpgs(void)
{
if (EpgsCreated())
diff --git a/xbmc/pvr/PVRManager.h b/xbmc/pvr/PVRManager.h
index 3f95260c7f..505bed6ab1 100644
--- a/xbmc/pvr/PVRManager.h
+++ b/xbmc/pvr/PVRManager.h
@@ -397,6 +397,11 @@ namespace PVR
void TriggerSaveChannelSettings(void);
/*!
+ * @brief Let the background thread search for missing channel icons.
+ */
+ void TriggerSearchMissingChannelIcons(void);
+
+ /*!
* @brief Update the channel that is currently active.
* @param item The new channel.
* @return True if it was updated correctly, false otherwise.
@@ -745,4 +750,14 @@ namespace PVR
CFileItem* m_previous;
CFileItem* m_next;
};
+
+ class CPVRSearchMissingChannelIconsJob : public CJob
+ {
+ public:
+ CPVRSearchMissingChannelIconsJob(void) {}
+ virtual ~CPVRSearchMissingChannelIconsJob() {}
+ virtual const char *GetType() const { return "pvr-search-missing-channel-icons"; }
+
+ bool DoWork();
+ };
}
diff --git a/xbmc/pvr/channels/PVRChannelGroup.cpp b/xbmc/pvr/channels/PVRChannelGroup.cpp
index 0ec84b44e2..a74a763c6e 100644
--- a/xbmc/pvr/channels/PVRChannelGroup.cpp
+++ b/xbmc/pvr/channels/PVRChannelGroup.cpp
@@ -29,6 +29,7 @@
#include "guilib/GUIWindowManager.h"
#include "dialogs/GUIDialogYesNo.h"
#include "dialogs/GUIDialogOK.h"
+#include "dialogs/GUIDialogExtendedProgressBar.h"
#include "music/tags/MusicInfoTag.h"
#include "utils/log.h"
#include "Util.h"
@@ -230,87 +231,80 @@ bool CPVRChannelGroup::MoveChannel(unsigned int iOldChannelNumber, unsigned int
return true;
}
-bool CPVRChannelGroup::SetChannelIconPath(CPVRChannelPtr channel, const std::string& strIconPath)
-{
- if (CFile::Exists(strIconPath))
- {
- channel->SetIconPath(strIconPath, g_advancedSettings.m_bPVRAutoScanIconsUserSet);
- return true;
- }
- return false;
-}
-
void CPVRChannelGroup::SearchAndSetChannelIcons(bool bUpdateDb /* = false */)
{
- if (CSettings::Get().GetString("pvrmenu.iconpath").empty())
+ std::string iconPath = CSettings::Get().GetString("pvrmenu.iconpath");
+ if (iconPath.empty())
return;
CPVRDatabase *database = GetPVRDatabase();
if (!database)
return;
+ /* fetch files in icon path for fast lookup */
+ CFileItemList fileItemList;
+ CDirectory::GetDirectory(iconPath, fileItemList, ".jpg|.png|.tbn");
+
+ if (fileItemList.IsEmpty())
+ return;
+
+ CGUIDialogExtendedProgressBar* dlgProgress = (CGUIDialogExtendedProgressBar*)g_windowManager.GetWindow(WINDOW_DIALOG_EXT_PROGRESS);
+ CGUIDialogProgressBarHandle* dlgProgressHandle = dlgProgress ? dlgProgress->GetHandle(g_localizeStrings.Get(19286)) : NULL;
+
CSingleLock lock(m_critSection);
- for (unsigned int ptr = 0; ptr < m_members.size(); ptr++)
+ /* create a map for fast lookup of normalized file base name */
+ std::map<std::string, std::string> fileItemMap;
+ const VECFILEITEMS &items = fileItemList.GetList();
+ for(VECFILEITEMS::const_iterator it = items.begin(); it != items.end(); ++it)
{
- PVRChannelGroupMember groupMember = m_members.at(ptr);
+ CStdString baseName = URIUtils::GetFileName((*it)->GetPath());
+ URIUtils::RemoveExtension(baseName);
+ StringUtils::ToLower(baseName);
+ fileItemMap.insert(std::make_pair(baseName, (*it)->GetPath()));
+ }
+
+ int channelIndex = 0;
+ for(std::vector<PVRChannelGroupMember>::const_iterator it = m_members.begin(); it != m_members.end(); ++it)
+ {
+ CPVRChannelPtr channel = (*it).channel;
+
+ /* update progress dialog */
+ if (dlgProgressHandle)
+ {
+ dlgProgressHandle->SetProgress(channelIndex++, m_members.size());
+ dlgProgressHandle->SetText(channel->ChannelName());
+ }
/* skip if an icon is already set and exists */
- if (groupMember.channel->IsIconExists())
+ if (channel->IsIconExists())
continue;
/* reset icon before searching for a new one */
- groupMember.channel->SetIconPath(StringUtils::Empty);
-
- 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);
-
- 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, 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)
+ channel->SetIconPath(StringUtils::Empty);
+
+ std::string strChannelUid = StringUtils::Format("%08d", channel->UniqueID());
+ std::string strLegalClientChannelName = CUtil::MakeLegalFileName(channel->ClientChannelName());
+ StringUtils::ToLower(strLegalClientChannelName);
+ std::string strLegalChannelName = CUtil::MakeLegalFileName(channel->ChannelName());
+ StringUtils::ToLower(strLegalChannelName);
+
+ std::map<std::string, std::string>::iterator itItem;
+ if ((itItem = fileItemMap.find(strLegalClientChannelName)) != fileItemMap.end() ||
+ (itItem = fileItemMap.find(strLegalChannelName)) != fileItemMap.end() ||
+ (itItem = fileItemMap.find(strChannelUid)) != fileItemMap.end())
{
- 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");
- }
+ channel->SetIconPath(itItem->second, g_advancedSettings.m_bPVRAutoScanIconsUserSet);
}
if (bUpdateDb)
- groupMember.channel->Persist();
+ channel->Persist();
/* TODO: start channel icon scraper here if nothing was found */
}
+
+ if (dlgProgressHandle)
+ dlgProgressHandle->MarkFinished();
}
/********** sort methods **********/
diff --git a/xbmc/pvr/channels/PVRChannelGroup.h b/xbmc/pvr/channels/PVRChannelGroup.h
index 61b3cfbd8c..cd33c1888f 100644
--- a/xbmc/pvr/channels/PVRChannelGroup.h
+++ b/xbmc/pvr/channels/PVRChannelGroup.h
@@ -410,14 +410,6 @@ namespace PVR
protected:
/*!
- * @brief Set a new channel icon path if the path exists
- * @param channel The channel to change
- * @param strIconPath The new path
- * @return True if the path exists, false otherwise
- */
- bool SetChannelIconPath(CPVRChannelPtr channel, const std::string& strIconPath);
-
- /*!
* @brief Load the channels stored in the database.
* @param bCompress If true, compress the database after storing the channels.
* @return The amount of channels that were added.
diff --git a/xbmc/pvr/channels/PVRChannelGroupsContainer.cpp b/xbmc/pvr/channels/PVRChannelGroupsContainer.cpp
index 3c76d1e731..da774ac78f 100644
--- a/xbmc/pvr/channels/PVRChannelGroupsContainer.cpp
+++ b/xbmc/pvr/channels/PVRChannelGroupsContainer.cpp
@@ -254,7 +254,6 @@ 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();
@@ -262,8 +261,6 @@ void CPVRChannelGroupsContainer::SearchMissingChannelIcons(void)
channelgrouptv->SearchAndSetChannelIcons(true);
if (channelgroupradio)
channelgroupradio->SearchAndSetChannelIcons(true);
-
- CGUIDialogOK::ShowAndGetInput(19167,0,20177,0);
}
CFileItemPtr CPVRChannelGroupsContainer::GetLastPlayedChannel(void) const