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/ArtUtils.h"
15 #include "utils/FileUtils.h"
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();
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
);
72 bool CProgramThumbLoader::LoadItemCached(CFileItem
*pItem
)
74 if (pItem
->IsParentFolder())
77 return FillThumb(*pItem
);
80 bool CProgramThumbLoader::LoadItemLookup(CFileItem
*pItem
)
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");
91 { // see whether we have a cached image for this item
92 thumb
= GetCachedImage(item
, "thumb");
95 thumb
= GetLocalThumb(item
);
97 SetCachedImage(item
, "thumb", thumb
);
103 CServiceBroker::GetTextureCache()->BackgroundCacheImage(thumb
);
104 item
.SetArt("thumb", thumb
);
109 std::string
CProgramThumbLoader::GetLocalThumb(const CFileItem
&item
)
111 if (item
.IsAddonsPath())
114 // look for the thumb
115 if (item
.m_bIsFolder
)
117 const std::string folderThumb
= ART::GetFolderThumb(item
);
118 if (CFileUtils::Exists(folderThumb
))
123 std::string
fileThumb(ART::GetTBNFile(item
));
124 if (CFileUtils::Exists(fileThumb
))