Merge pull request #4594 from FernetMenta/paplayer
[xbmc.git] / xbmc / ThumbLoader.cpp
blob4aa7b2c0ef682dd1e3fddf35e9e95fbb8f0d1b51
1 /*
2 * Copyright (C) 2005-2013 Team XBMC
3 * http://xbmc.org
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)
8 * any later version.
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"
23 #include "FileItem.h"
24 #include "TextureCache.h"
26 using namespace std;
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();
56 return image;
58 return "";
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);
83 return result;
86 bool CProgramThumbLoader::LoadItemCached(CFileItem *pItem)
88 if (pItem->IsParentFolder())
89 return false;
91 return FillThumb(*pItem);
94 bool CProgramThumbLoader::LoadItemLookup(CFileItem *pItem)
96 return false;
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");
104 if (thumb.empty())
105 { // see whether we have a cached image for this item
106 thumb = GetCachedImage(item, "thumb");
107 if (thumb.empty())
109 thumb = GetLocalThumb(item);
110 if (!thumb.empty())
111 SetCachedImage(item, "thumb", thumb);
115 if (!thumb.empty())
117 CTextureCache::Get().BackgroundCacheImage(thumb);
118 item.SetArt("thumb", thumb);
120 return true;
123 CStdString CProgramThumbLoader::GetLocalThumb(const CFileItem &item)
125 if (item.IsAddonsPath())
126 return "";
128 // look for the thumb
129 if (item.m_bIsFolder)
131 CStdString folderThumb = item.GetFolderThumb();
132 if (CFile::Exists(folderThumb))
133 return folderThumb;
135 else
137 CStdString fileThumb(item.GetTBNFile());
138 if (CFile::Exists(fileThumb))
139 return fileThumb;
141 return "";