Merge pull request #4857 from t-nelson/Gotham_13.2_backports
[vuplus_xbmc] / xbmc / ThumbLoader.cpp
index 7ad40a1..4aa7b2c 100644 (file)
@@ -1,6 +1,6 @@
 /*
- *      Copyright (C) 2005-2012 Team XBMC
- *      http://www.xbmc.org
+ *      Copyright (C) 2005-2013 Team XBMC
+ *      http://xbmc.org
  *
  *  This Program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 using namespace std;
 using namespace XFILE;
 
-CThumbLoader::CThumbLoader(int nThreads) :
-  CBackgroundInfoLoader(nThreads)
+CThumbLoader::CThumbLoader() :
+  CBackgroundInfoLoader()
 {
+  m_textureDatabase = new CTextureDatabase();
 }
 
 CThumbLoader::~CThumbLoader()
 {
+  delete m_textureDatabase;
+}
+
+void CThumbLoader::OnLoaderStart()
+{
+  m_textureDatabase->Open();
+}
+
+void CThumbLoader::OnLoaderFinish()
+{
+  m_textureDatabase->Close();
 }
 
 CStdString CThumbLoader::GetCachedImage(const CFileItem &item, const CStdString &type)
 {
-  CTextureDatabase db;
-  if (!item.GetPath().empty() && db.Open())
-    return db.GetTextureForPath(item.GetPath(), type);
+  if (!item.GetPath().empty() && m_textureDatabase->Open())
+  {
+    CStdString image = m_textureDatabase->GetTextureForPath(item.GetPath(), type);
+    m_textureDatabase->Close();
+    return image;
+  }
   return "";
 }
 
 void CThumbLoader::SetCachedImage(const CFileItem &item, const CStdString &type, const CStdString &image)
 {
-  CTextureDatabase db;
-  if (!item.GetPath().empty() && db.Open())
-    db.SetTextureForPath(item.GetPath(), type, image);
+  if (!item.GetPath().empty() && m_textureDatabase->Open())
+  {
+    m_textureDatabase->SetTextureForPath(item.GetPath(), type, image);
+    m_textureDatabase->Close();
+  }
 }
 
 CProgramThumbLoader::CProgramThumbLoader()
@@ -60,27 +77,42 @@ CProgramThumbLoader::~CProgramThumbLoader()
 
 bool CProgramThumbLoader::LoadItem(CFileItem *pItem)
 {
-  if (pItem->IsParentFolder()) return true;
+  bool result  = LoadItemCached(pItem);
+       result |= LoadItemLookup(pItem);
+
+  return result;
+}
+
+bool CProgramThumbLoader::LoadItemCached(CFileItem *pItem)
+{
+  if (pItem->IsParentFolder())
+    return false;
+
   return FillThumb(*pItem);
 }
 
+bool CProgramThumbLoader::LoadItemLookup(CFileItem *pItem)
+{
+  return false;
+}
+
 bool CProgramThumbLoader::FillThumb(CFileItem &item)
 {
   // no need to do anything if we already have a thumb set
   CStdString thumb = item.GetArt("thumb");
 
-  if (thumb.IsEmpty())
+  if (thumb.empty())
   { // see whether we have a cached image for this item
     thumb = GetCachedImage(item, "thumb");
-    if (thumb.IsEmpty())
+    if (thumb.empty())
     {
       thumb = GetLocalThumb(item);
-      if (!thumb.IsEmpty())
+      if (!thumb.empty())
         SetCachedImage(item, "thumb", thumb);
     }
   }
 
-  if (!thumb.IsEmpty())
+  if (!thumb.empty())
   {
     CTextureCache::Get().BackgroundCacheImage(thumb);
     item.SetArt("thumb", thumb);
@@ -90,6 +122,9 @@ bool CProgramThumbLoader::FillThumb(CFileItem &item)
 
 CStdString CProgramThumbLoader::GetLocalThumb(const CFileItem &item)
 {
+  if (item.IsAddonsPath())
+    return "";
+
   // look for the thumb
   if (item.m_bIsFolder)
   {