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 (...)
{
{ // 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 (...)
{
return (unsigned int)crc;
}
-CStdString CTextureDatabase::GetTextureForPath(const CStdString &url)
+CStdString CTextureDatabase::GetTextureForPath(const CStdString &url, const CStdString &type)
{
try
{
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())
return "";
}
-void CTextureDatabase::SetTextureForPath(const CStdString &url, const CStdString &texture)
+void CTextureDatabase::SetTextureForPath(const CStdString &url, const CStdString &type, const CStdString &texture)
{
try
{
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
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());
}
}
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
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
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"; };
};
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;
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())
{
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
{ // 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);
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;
}
}
}
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())
{
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;
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;
{ // 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);
}
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));
}
}