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() :
30 CBackgroundInfoLoader()
32 m_textureDatabase
= new CTextureDatabase();
35 CThumbLoader::~CThumbLoader()
37 delete m_textureDatabase
;
40 void CThumbLoader::OnLoaderStart()
42 m_textureDatabase
->Open();
45 void CThumbLoader::OnLoaderFinish()
47 m_textureDatabase
->Close();
50 CStdString
CThumbLoader::GetCachedImage(const CFileItem
&item
, const CStdString
&type
)
52 if (!item
.GetPath().empty() && m_textureDatabase
->Open())
54 CStdString image
= m_textureDatabase
->GetTextureForPath(item
.GetPath(), type
);
55 m_textureDatabase
->Close();
61 void CThumbLoader::SetCachedImage(const CFileItem
&item
, const CStdString
&type
, const CStdString
&image
)
63 if (!item
.GetPath().empty() && m_textureDatabase
->Open())
65 m_textureDatabase
->SetTextureForPath(item
.GetPath(), type
, image
);
66 m_textureDatabase
->Close();
70 CProgramThumbLoader::CProgramThumbLoader()
74 CProgramThumbLoader::~CProgramThumbLoader()
78 bool CProgramThumbLoader::LoadItem(CFileItem
*pItem
)
80 bool result
= LoadItemCached(pItem
);
81 result
|= LoadItemLookup(pItem
);
86 bool CProgramThumbLoader::LoadItemCached(CFileItem
*pItem
)
88 if (pItem
->IsParentFolder())
91 return FillThumb(*pItem
);
94 bool CProgramThumbLoader::LoadItemLookup(CFileItem
*pItem
)
99 bool CProgramThumbLoader::FillThumb(CFileItem
&item
)
101 // no need to do anything if we already have a thumb set
102 CStdString thumb
= item
.GetArt("thumb");
105 { // see whether we have a cached image for this item
106 thumb
= GetCachedImage(item
, "thumb");
109 thumb
= GetLocalThumb(item
);
111 SetCachedImage(item
, "thumb", thumb
);
117 CTextureCache::Get().BackgroundCacheImage(thumb
);
118 item
.SetArt("thumb", thumb
);
123 CStdString
CProgramThumbLoader::GetLocalThumb(const CFileItem
&item
)
125 if (item
.IsAddonsPath())
128 // look for the thumb
129 if (item
.m_bIsFolder
)
131 CStdString folderThumb
= item
.GetFolderThumb();
132 if (CFile::Exists(folderThumb
))
137 CStdString
fileThumb(item
.GetTBNFile());
138 if (CFile::Exists(fileThumb
))