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.
9 #include "ThumbLoader.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();
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
);
69 bool CProgramThumbLoader::LoadItemCached(CFileItem
*pItem
)
71 if (pItem
->IsParentFolder())
74 return FillThumb(*pItem
);
77 bool CProgramThumbLoader::LoadItemLookup(CFileItem
*pItem
)
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");
88 { // see whether we have a cached image for this item
89 thumb
= GetCachedImage(item
, "thumb");
92 thumb
= GetLocalThumb(item
);
94 SetCachedImage(item
, "thumb", thumb
);
100 CServiceBroker::GetTextureCache()->BackgroundCacheImage(thumb
);
101 item
.SetArt("thumb", thumb
);
106 std::string
CProgramThumbLoader::GetLocalThumb(const CFileItem
&item
)
108 if (item
.IsAddonsPath())
111 // look for the thumb
112 if (item
.m_bIsFolder
)
114 std::string folderThumb
= item
.GetFolderThumb();
115 if (CFileUtils::Exists(folderThumb
))
120 std::string
fileThumb(item
.GetTBNFile());
121 if (CFileUtils::Exists(fileThumb
))