[cosmetics] update date in GPL header
[vuplus_xbmc] / xbmc / ThumbLoader.cpp
1 /*
2  *      Copyright (C) 2005-2013 Team XBMC
3  *      http://www.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(int nThreads) :
30   CBackgroundInfoLoader(nThreads)
31 {
32 }
33
34 CThumbLoader::~CThumbLoader()
35 {
36 }
37
38 CStdString CThumbLoader::GetCachedImage(const CFileItem &item, const CStdString &type)
39 {
40   CTextureDatabase db;
41   if (!item.GetPath().empty() && db.Open())
42     return db.GetTextureForPath(item.GetPath(), type);
43   return "";
44 }
45
46 void CThumbLoader::SetCachedImage(const CFileItem &item, const CStdString &type, const CStdString &image)
47 {
48   CTextureDatabase db;
49   if (!item.GetPath().empty() && db.Open())
50     db.SetTextureForPath(item.GetPath(), type, image);
51 }
52
53 CProgramThumbLoader::CProgramThumbLoader()
54 {
55 }
56
57 CProgramThumbLoader::~CProgramThumbLoader()
58 {
59 }
60
61 bool CProgramThumbLoader::LoadItem(CFileItem *pItem)
62 {
63   if (pItem->IsParentFolder()) return true;
64   return FillThumb(*pItem);
65 }
66
67 bool CProgramThumbLoader::FillThumb(CFileItem &item)
68 {
69   // no need to do anything if we already have a thumb set
70   CStdString thumb = item.GetArt("thumb");
71
72   if (thumb.IsEmpty())
73   { // see whether we have a cached image for this item
74     thumb = GetCachedImage(item, "thumb");
75     if (thumb.IsEmpty())
76     {
77       thumb = GetLocalThumb(item);
78       if (!thumb.IsEmpty())
79         SetCachedImage(item, "thumb", thumb);
80     }
81   }
82
83   if (!thumb.IsEmpty())
84   {
85     CTextureCache::Get().BackgroundCacheImage(thumb);
86     item.SetArt("thumb", thumb);
87   }
88   return true;
89 }
90
91 CStdString CProgramThumbLoader::GetLocalThumb(const CFileItem &item)
92 {
93   if (item.IsAddonsPath())
94     return "";
95
96   // look for the thumb
97   if (item.m_bIsFolder)
98   {
99     CStdString folderThumb = item.GetFolderThumb();
100     if (CFile::Exists(folderThumb))
101       return folderThumb;
102   }
103   else
104   {
105     CStdString fileThumb(item.GetTBNFile());
106     if (CFile::Exists(fileThumb))
107       return fileThumb;
108   }
109   return "";
110 }