add type column to path table of texture database for saving paths to thumbs/fanart...
authorJonathan Marshall <jmarshall@never.you.mind>
Wed, 15 Feb 2012 06:39:13 +0000 (19:39 +1300)
committerJonathan Marshall <jmarshall@never.you.mind>
Tue, 3 Apr 2012 09:43:36 +0000 (21:43 +1200)
xbmc/TextureDatabase.cpp
xbmc/TextureDatabase.h
xbmc/ThumbLoader.cpp
xbmc/ThumbLoader.h
xbmc/dialogs/GUIDialogContextMenu.cpp
xbmc/pictures/GUIWindowPictures.cpp
xbmc/pictures/PictureThumbLoader.cpp

index 4bb432c..2ed0d5c 100644 (file)
@@ -52,10 +52,12 @@ bool CTextureDatabase::CreateTables()
     m_pDS->exec("CREATE INDEX idxTexture ON texture(urlhash)");
 
     CLog::Log(LOGINFO, "create path table");
-    m_pDS->exec("CREATE TABLE path (id integer primary key, urlhash integer, url text, texture text)\n");
+    m_pDS->exec("CREATE TABLE path (id integer primary key, urlhash integer, url text, type text, texture text)\n");
 
+    // TODO: Should the path index be a covering index? (we need only retrieve texture)
+    //       Also, do we actually need the urlhash'ing here, or will an index on the url suffice?
     CLog::Log(LOGINFO, "create path index");
-    m_pDS->exec("CREATE INDEX idxPath ON path(urlhash)");
+    m_pDS->exec("CREATE INDEX idxPath ON path(urlhash, type)");
   }
   catch (...)
   {
@@ -96,6 +98,13 @@ bool CTextureDatabase::UpdateOldVersion(int version)
     { // get rid of old cached thumbs as they were previously set to the cached thumb name instead of the source thumb
       m_pDS->exec("delete from path");
     }
+    if (version < 9)
+    { // get rid of the old path table and add the type column
+      m_pDS->dropIndex("path", "idxPath");
+      m_pDS->exec("DROP TABLE path");
+      m_pDS->exec("CREATE TABLE path (id integer primary key, urlhash integer, url text, type text, texture text)\n");
+      m_pDS->exec("CREATE INDEX idxPath ON path(urlhash, type)");
+    }
   }
   catch (...)
   {
@@ -216,7 +225,7 @@ unsigned int CTextureDatabase::GetURLHash(const CStdString &url) const
   return (unsigned int)crc;
 }
 
-CStdString CTextureDatabase::GetTextureForPath(const CStdString &url)
+CStdString CTextureDatabase::GetTextureForPath(const CStdString &url, const CStdString &type)
 {
   try
   {
@@ -225,7 +234,7 @@ CStdString CTextureDatabase::GetTextureForPath(const CStdString &url)
 
     unsigned int hash = GetURLHash(url);
 
-    CStdString sql = PrepareSQL("select texture from path where urlhash=%u", hash);
+    CStdString sql = PrepareSQL("select texture from path where urlhash=%u and type='%s'", hash, type.c_str());
     m_pDS->query(sql.c_str());
 
     if (!m_pDS->eof())
@@ -243,7 +252,7 @@ CStdString CTextureDatabase::GetTextureForPath(const CStdString &url)
   return "";
 }
 
-void CTextureDatabase::SetTextureForPath(const CStdString &url, const CStdString &texture)
+void CTextureDatabase::SetTextureForPath(const CStdString &url, const CStdString &type, const CStdString &texture)
 {
   try
   {
@@ -252,7 +261,7 @@ void CTextureDatabase::SetTextureForPath(const CStdString &url, const CStdString
 
     unsigned int hash = GetURLHash(url);
 
-    CStdString sql = PrepareSQL("select id from path where urlhash=%u", hash);
+    CStdString sql = PrepareSQL("select id from path where urlhash=%u and type='%s'", hash, type.c_str());
     m_pDS->query(sql.c_str());
     if (!m_pDS->eof())
     { // update
@@ -264,7 +273,7 @@ void CTextureDatabase::SetTextureForPath(const CStdString &url, const CStdString
     else
     { // add the texture
       m_pDS->close();
-      sql = PrepareSQL("insert into path (id, urlhash, url, texture) values(NULL, %u, '%s', '%s')", hash, url.c_str(), texture.c_str());
+      sql = PrepareSQL("insert into path (id, urlhash, url, type, texture) values(NULL, %u, '%s', '%s', '%s')", hash, url.c_str(), type.c_str(), texture.c_str());
       m_pDS->exec(sql.c_str());
     }
   }
index 6dc3351..ee091cd 100644 (file)
@@ -38,9 +38,10 @@ public:
    Used for retrieval of previously discovered images to save
    stat() on the filesystem all the time
    \param url path that may be associated with a texture
+   \param type type of image to look for
    \return URL of the texture associated with the given path
    */
-  CStdString GetTextureForPath(const CStdString &url);
+  CStdString GetTextureForPath(const CStdString &url, const CStdString &type);
 
   /*! \brief Set a texture associated with the given path
    Used for setting of previously discovered images to save
@@ -48,9 +49,10 @@ public:
    the actual image path, not the cached image path (the image will be
    cached at load time.)
    \param url path that was used to find the texture
+   \param type type of image to associate
    \param texture URL of the texture to associate with the path
    */
-  void SetTextureForPath(const CStdString &url, const CStdString &texture);
+  void SetTextureForPath(const CStdString &url, const CStdString &type, const CStdString &texture);
 
 protected:
   /*! \brief retrieve a hash for the given url
@@ -62,6 +64,6 @@ protected:
 
   virtual bool CreateTables();
   virtual bool UpdateOldVersion(int version);
-  virtual int GetMinVersion() const { return 8; };
+  virtual int GetMinVersion() const { return 9; };
   const char *GetBaseDBName() const { return "Textures"; };
 };
index f2f8398..bae679a 100644 (file)
@@ -70,14 +70,21 @@ bool CThumbLoader::LoadRemoteThumb(CFileItem *pItem)
   return pItem->HasThumbnail();
 }
 
-CStdString CThumbLoader::GetCachedThumb(const CFileItem &item)
+CStdString CThumbLoader::GetCachedImage(const CFileItem &item, const CStdString &type)
 {
   CTextureDatabase db;
   if (db.Open())
-    return db.GetTextureForPath(item.GetPath());
+    return db.GetTextureForPath(item.GetPath(), type);
   return "";
 }
 
+void CThumbLoader::SetCachedImage(const CFileItem &item, const CStdString &type, const CStdString &image)
+{
+  CTextureDatabase db;
+  if (db.Open())
+    db.SetTextureForPath(item.GetPath(), type, image);
+}
+
 CThumbExtractor::CThumbExtractor(const CFileItem& item, const CStdString& listpath, bool thumb, const CStdString& target)
 {
   m_listpath = listpath;
@@ -304,16 +311,12 @@ bool CProgramThumbLoader::FillThumb(CFileItem &item)
     return true;
 
   // see whether we have a cached image for this item
-  CStdString thumb = GetCachedThumb(item);
+  CStdString thumb = GetCachedImage(item, "thumb");
   if (thumb.IsEmpty())
   {
     thumb = GetLocalThumb(item);
     if (!thumb.IsEmpty())
-    {
-      CTextureDatabase db;
-      if (db.Open())
-        db.SetTextureForPath(item.GetPath(), thumb);
-    }
+      SetCachedImage(item, "thumb", thumb);
   }
   if (!thumb.IsEmpty())
   {
index 2365ee8..c245a8a 100644 (file)
@@ -69,12 +69,19 @@ public:
 
   bool LoadRemoteThumb(CFileItem *pItem);
 
-  /*! \brief Checks whether the given item has a thumb listed in the texture database
-   \param item CFileItem to check for a thumb
-   \return the thumb associated with this item
-   \sa CheckAndCacheThumb
+  /*! \brief Checks whether the given item has an image listed in the texture database
+   \param item CFileItem to check
+   \param type the type of image to retrieve
+   \return the image associated with this item
    */
-  static CStdString GetCachedThumb(const CFileItem &item);
+  static CStdString GetCachedImage(const CFileItem &item, const CStdString &type);
+
+  /*! \brief Associate an image with the given item in the texture database
+   \param item CFileItem to associate the image with
+   \param type the type of image
+   \param image the URL of the image
+   */
+  static void SetCachedImage(const CFileItem &item, const CStdString &type, const CStdString &image);
 };
 
 class CVideoThumbLoader : public CThumbLoader, public CJobQueue
index ab469e1..8c1e39e 100644 (file)
@@ -558,7 +558,7 @@ bool CGUIDialogContextMenu::OnContextButton(const CStdString &type, const CFileI
         { // store the thumb for this share
           CTextureDatabase db;
           if (db.Open())
-            db.SetTextureForPath(item->GetPath(), strThumb);
+            db.SetTextureForPath(item->GetPath(), "thumb", strThumb);
         }
         if (!cachedThumb.IsEmpty())
           XFILE::CFile::Cache(strThumb, cachedThumb);
index 9df0347..9d40258 100644 (file)
@@ -268,7 +268,7 @@ bool CGUIWindowPictures::Update(const CStdString &strDirectory)
   m_vecItems->SetThumbnailImage("");
   if (g_guiSettings.GetBool("pictures.generatethumbs"))
     m_thumbLoader.Load(*m_vecItems);
-  m_vecItems->SetThumbnailImage(CPictureThumbLoader::GetCachedThumb(*m_vecItems));
+  m_vecItems->SetThumbnailImage(CPictureThumbLoader::GetCachedImage(*m_vecItems, "thumb"));
 
   return true;
 }
index 38574b9..10f29a9 100644 (file)
@@ -90,8 +90,8 @@ bool CPictureThumbLoader::LoadItem(CFileItem* pItem)
     }
   }
   else if (!pItem->HasThumbnail())
-  { // folder, zip, cbz, rar, cbr, playlist
-    thumb = GetCachedThumb(*pItem);
+  { // folder, zip, cbz, rar, cbr, playlist may have a previously cached image
+    thumb = GetCachedImage(*pItem, "thumb");
   }
   if (!thumb.IsEmpty())
   {
@@ -133,7 +133,7 @@ void CPictureThumbLoader::ProcessFoldersAndArchives(CFileItem *pItem)
     CStdString strTBN(URIUtils::ReplaceExtension(pItem->GetPath(),".tbn"));
     if (CFile::Exists(strTBN))
     {
-      db.SetTextureForPath(pItem->GetPath(), strTBN);
+      db.SetTextureForPath(pItem->GetPath(), "thumb", strTBN);
       CTextureCache::Get().BackgroundCacheImage(strTBN);
       pItem->SetThumbnailImage(strTBN);
       return;
@@ -159,7 +159,7 @@ void CPictureThumbLoader::ProcessFoldersAndArchives(CFileItem *pItem)
     thumb = URIUtils::AddFileToFolder(strPath, thumb);
     if (CFile::Exists(thumb))
     {
-      db.SetTextureForPath(pItem->GetPath(), thumb);
+      db.SetTextureForPath(pItem->GetPath(), "thumb", thumb);
       CTextureCache::Get().BackgroundCacheImage(thumb);
       pItem->SetThumbnailImage(thumb);
       return;
@@ -213,7 +213,7 @@ void CPictureThumbLoader::ProcessFoldersAndArchives(CFileItem *pItem)
       { // less than 4 items, so just grab the first thumb
         items.Sort(SORT_METHOD_LABEL, SORT_ORDER_ASC);
         CStdString thumb = CTextureCache::GetWrappedThumbURL(items[0]->GetPath());
-        db.SetTextureForPath(pItem->GetPath(), thumb);
+        db.SetTextureForPath(pItem->GetPath(), "thumb", thumb);
         CTextureCache::Get().BackgroundCacheImage(thumb);
         pItem->SetThumbnailImage(thumb);
       }
@@ -228,7 +228,7 @@ void CPictureThumbLoader::ProcessFoldersAndArchives(CFileItem *pItem)
         CStdString relativeCacheFile = CTextureCache::GetCacheFile(thumb);
         CPicture::CreateFolderThumb(strFiles, CTextureCache::GetCachedPath(relativeCacheFile));
         CTextureCache::Get().AddCachedTexture(thumb, relativeCacheFile, "");
-        db.SetTextureForPath(pItem->GetPath(), thumb);
+        db.SetTextureForPath(pItem->GetPath(), "thumb", thumb);
         pItem->SetThumbnailImage(CTextureCache::GetCachedPath(relativeCacheFile));
       }
     }