Remove LiveTV menu.
[vuplus_xbmc] / xbmc / ThumbLoader.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://xbmc.org
4  *
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.
9  *
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.
14  *
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/>.
18  *
19  */
20
21 #include "ThumbLoader.h"
22 #include "filesystem/File.h"
23 #include "FileItem.h"
24 #include "TextureCache.h"
25
26 using namespace std;
27 using namespace XFILE;
28
29 CThumbLoader::CThumbLoader() :
30   CBackgroundInfoLoader()
31 {
32   m_textureDatabase = new CTextureDatabase();
33 }
34
35 CThumbLoader::~CThumbLoader()
36 {
37   delete m_textureDatabase;
38 }
39
40 void CThumbLoader::OnLoaderStart()
41 {
42   m_textureDatabase->Open();
43 }
44
45 void CThumbLoader::OnLoaderFinish()
46 {
47   m_textureDatabase->Close();
48 }
49
50 CStdString CThumbLoader::GetCachedImage(const CFileItem &item, const CStdString &type)
51 {
52   if (!item.GetPath().empty() && m_textureDatabase->Open())
53   {
54     CStdString image = m_textureDatabase->GetTextureForPath(item.GetPath(), type);
55     m_textureDatabase->Close();
56     return image;
57   }
58   return "";
59 }
60
61 void CThumbLoader::SetCachedImage(const CFileItem &item, const CStdString &type, const CStdString &image)
62 {
63   if (!item.GetPath().empty() && m_textureDatabase->Open())
64   {
65     m_textureDatabase->SetTextureForPath(item.GetPath(), type, image);
66     m_textureDatabase->Close();
67   }
68 }
69
70 CProgramThumbLoader::CProgramThumbLoader()
71 {
72 }
73
74 CProgramThumbLoader::~CProgramThumbLoader()
75 {
76 }
77
78 bool CProgramThumbLoader::LoadItem(CFileItem *pItem)
79 {
80   bool result  = LoadItemCached(pItem);
81        result |= LoadItemLookup(pItem);
82
83   return result;
84 }
85
86 bool CProgramThumbLoader::LoadItemCached(CFileItem *pItem)
87 {
88   if (pItem->IsParentFolder())
89     return false;
90
91   return FillThumb(*pItem);
92 }
93
94 bool CProgramThumbLoader::LoadItemLookup(CFileItem *pItem)
95 {
96   return false;
97 }
98
99 bool CProgramThumbLoader::FillThumb(CFileItem &item)
100 {
101   // no need to do anything if we already have a thumb set
102   CStdString thumb = item.GetArt("thumb");
103
104   if (thumb.empty())
105   { // see whether we have a cached image for this item
106     thumb = GetCachedImage(item, "thumb");
107     if (thumb.empty())
108     {
109       thumb = GetLocalThumb(item);
110       if (!thumb.empty())
111         SetCachedImage(item, "thumb", thumb);
112     }
113   }
114
115   if (!thumb.empty())
116   {
117     CTextureCache::Get().BackgroundCacheImage(thumb);
118     item.SetArt("thumb", thumb);
119   }
120   return true;
121 }
122
123 CStdString CProgramThumbLoader::GetLocalThumb(const CFileItem &item)
124 {
125   if (item.IsAddonsPath())
126     return "";
127
128   // look for the thumb
129   if (item.m_bIsFolder)
130   {
131     CStdString folderThumb = item.GetFolderThumb();
132     if (CFile::Exists(folderThumb))
133       return folderThumb;
134   }
135   else
136   {
137     CStdString fileThumb(item.GetTBNFile());
138     if (CFile::Exists(fileThumb))
139       return fileThumb;
140   }
141   return "";
142 }