[videodb] Remove nested transaction when saving state after stopping PVR playback
[xbmc.git] / xbmc / ThumbLoader.cpp
blob1dfce686594249566fb71bb868a827d680898419
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "ThumbLoader.h"
11 #include "FileItem.h"
12 #include "ServiceBroker.h"
13 #include "TextureCache.h"
14 #include "utils/ArtUtils.h"
15 #include "utils/FileUtils.h"
17 using namespace KODI;
19 CThumbLoader::CThumbLoader() :
20 CBackgroundInfoLoader()
22 m_textureDatabase = new CTextureDatabase();
25 CThumbLoader::~CThumbLoader()
27 delete m_textureDatabase;
30 void CThumbLoader::OnLoaderStart()
32 m_textureDatabase->Open();
35 void CThumbLoader::OnLoaderFinish()
37 m_textureDatabase->Close();
40 std::string CThumbLoader::GetCachedImage(const CFileItem &item, const std::string &type)
42 if (!item.GetPath().empty() && m_textureDatabase->Open())
44 std::string image = m_textureDatabase->GetTextureForPath(item.GetPath(), type);
45 m_textureDatabase->Close();
46 return image;
48 return "";
51 void CThumbLoader::SetCachedImage(const CFileItem &item, const std::string &type, const std::string &image)
53 if (!item.GetPath().empty() && m_textureDatabase->Open())
55 m_textureDatabase->SetTextureForPath(item.GetPath(), type, image);
56 m_textureDatabase->Close();
60 CProgramThumbLoader::CProgramThumbLoader() = default;
62 CProgramThumbLoader::~CProgramThumbLoader() = default;
64 bool CProgramThumbLoader::LoadItem(CFileItem *pItem)
66 bool result = LoadItemCached(pItem);
67 result |= LoadItemLookup(pItem);
69 return result;
72 bool CProgramThumbLoader::LoadItemCached(CFileItem *pItem)
74 if (pItem->IsParentFolder())
75 return false;
77 return FillThumb(*pItem);
80 bool CProgramThumbLoader::LoadItemLookup(CFileItem *pItem)
82 return false;
85 bool CProgramThumbLoader::FillThumb(CFileItem &item)
87 // no need to do anything if we already have a thumb set
88 std::string thumb = item.GetArt("thumb");
90 if (thumb.empty())
91 { // see whether we have a cached image for this item
92 thumb = GetCachedImage(item, "thumb");
93 if (thumb.empty())
95 thumb = GetLocalThumb(item);
96 if (!thumb.empty())
97 SetCachedImage(item, "thumb", thumb);
101 if (!thumb.empty())
103 CServiceBroker::GetTextureCache()->BackgroundCacheImage(thumb);
104 item.SetArt("thumb", thumb);
106 return true;
109 std::string CProgramThumbLoader::GetLocalThumb(const CFileItem &item)
111 if (item.IsAddonsPath())
112 return "";
114 // look for the thumb
115 if (item.m_bIsFolder)
117 const std::string folderThumb = ART::GetFolderThumb(item);
118 if (CFileUtils::Exists(folderThumb))
119 return folderThumb;
121 else
123 std::string fileThumb(ART::GetTBNFile(item));
124 if (CFileUtils::Exists(fileThumb))
125 return fileThumb;
127 return "";