Merge pull request #4857 from t-nelson/Gotham_13.2_backports
[vuplus_xbmc] / xbmc / ThumbLoader.cpp
index aa4cb82..4aa7b2c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *      Copyright (C) 2005-2013 Team XBMC
- *      http://www.xbmc.org
+ *      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
@@ -29,25 +29,42 @@ using namespace XFILE;
 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()
@@ -84,18 +101,18 @@ 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);