2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "ThumbLoader.h"
22 #include "filesystem/File.h"
24 #include "TextureCache.h"
27 using namespace XFILE;
29 CThumbLoader::CThumbLoader(int nThreads) :
30 CBackgroundInfoLoader(nThreads)
34 CThumbLoader::~CThumbLoader()
38 CStdString CThumbLoader::GetCachedImage(const CFileItem &item, const CStdString &type)
41 if (!item.GetPath().empty() && db.Open())
42 return db.GetTextureForPath(item.GetPath(), type);
46 void CThumbLoader::SetCachedImage(const CFileItem &item, const CStdString &type, const CStdString &image)
49 if (!item.GetPath().empty() && db.Open())
50 db.SetTextureForPath(item.GetPath(), type, image);
53 CProgramThumbLoader::CProgramThumbLoader()
57 CProgramThumbLoader::~CProgramThumbLoader()
61 bool CProgramThumbLoader::LoadItem(CFileItem *pItem)
63 if (pItem->IsParentFolder()) return true;
64 return FillThumb(*pItem);
67 bool CProgramThumbLoader::FillThumb(CFileItem &item)
69 // no need to do anything if we already have a thumb set
70 CStdString thumb = item.GetArt("thumb");
73 { // see whether we have a cached image for this item
74 thumb = GetCachedImage(item, "thumb");
77 thumb = GetLocalThumb(item);
79 SetCachedImage(item, "thumb", thumb);
85 CTextureCache::Get().BackgroundCacheImage(thumb);
86 item.SetArt("thumb", thumb);
91 CStdString CProgramThumbLoader::GetLocalThumb(const CFileItem &item)
93 if (item.IsAddonsPath())
99 CStdString folderThumb = item.GetFolderThumb();
100 if (CFile::Exists(folderThumb))
105 CStdString fileThumb(item.GetTBNFile());
106 if (CFile::Exists(fileThumb))