[video] Fix the refresh of movies with additional versions or extras
[xbmc.git] / xbmc / ThumbLoader.cpp
blob3e1508cc49b7d79df0c640e9634d4493ae390067
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/FileUtils.h"
16 CThumbLoader::CThumbLoader() :
17 CBackgroundInfoLoader()
19 m_textureDatabase = new CTextureDatabase();
22 CThumbLoader::~CThumbLoader()
24 delete m_textureDatabase;
27 void CThumbLoader::OnLoaderStart()
29 m_textureDatabase->Open();
32 void CThumbLoader::OnLoaderFinish()
34 m_textureDatabase->Close();
37 std::string CThumbLoader::GetCachedImage(const CFileItem &item, const std::string &type)
39 if (!item.GetPath().empty() && m_textureDatabase->Open())
41 std::string image = m_textureDatabase->GetTextureForPath(item.GetPath(), type);
42 m_textureDatabase->Close();
43 return image;
45 return "";
48 void CThumbLoader::SetCachedImage(const CFileItem &item, const std::string &type, const std::string &image)
50 if (!item.GetPath().empty() && m_textureDatabase->Open())
52 m_textureDatabase->SetTextureForPath(item.GetPath(), type, image);
53 m_textureDatabase->Close();
57 CProgramThumbLoader::CProgramThumbLoader() = default;
59 CProgramThumbLoader::~CProgramThumbLoader() = default;
61 bool CProgramThumbLoader::LoadItem(CFileItem *pItem)
63 bool result = LoadItemCached(pItem);
64 result |= LoadItemLookup(pItem);
66 return result;
69 bool CProgramThumbLoader::LoadItemCached(CFileItem *pItem)
71 if (pItem->IsParentFolder())
72 return false;
74 return FillThumb(*pItem);
77 bool CProgramThumbLoader::LoadItemLookup(CFileItem *pItem)
79 return false;
82 bool CProgramThumbLoader::FillThumb(CFileItem &item)
84 // no need to do anything if we already have a thumb set
85 std::string thumb = item.GetArt("thumb");
87 if (thumb.empty())
88 { // see whether we have a cached image for this item
89 thumb = GetCachedImage(item, "thumb");
90 if (thumb.empty())
92 thumb = GetLocalThumb(item);
93 if (!thumb.empty())
94 SetCachedImage(item, "thumb", thumb);
98 if (!thumb.empty())
100 CServiceBroker::GetTextureCache()->BackgroundCacheImage(thumb);
101 item.SetArt("thumb", thumb);
103 return true;
106 std::string CProgramThumbLoader::GetLocalThumb(const CFileItem &item)
108 if (item.IsAddonsPath())
109 return "";
111 // look for the thumb
112 if (item.m_bIsFolder)
114 std::string folderThumb = item.GetFolderThumb();
115 if (CFileUtils::Exists(folderThumb))
116 return folderThumb;
118 else
120 std::string fileThumb(item.GetTBNFile());
121 if (CFileUtils::Exists(fileThumb))
122 return fileThumb;
124 return "";