1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
/*
* Copyright (C) 2005-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "ThumbLoader.h"
#include "FileItem.h"
#include "ServiceBroker.h"
#include "TextureCache.h"
#include "utils/FileUtils.h"
CThumbLoader::CThumbLoader() :
CBackgroundInfoLoader()
{
m_textureDatabase = new CTextureDatabase();
}
CThumbLoader::~CThumbLoader()
{
delete m_textureDatabase;
}
void CThumbLoader::OnLoaderStart()
{
m_textureDatabase->Open();
}
void CThumbLoader::OnLoaderFinish()
{
m_textureDatabase->Close();
}
std::string CThumbLoader::GetCachedImage(const CFileItem &item, const std::string &type)
{
if (!item.GetPath().empty() && m_textureDatabase->Open())
{
std::string image = m_textureDatabase->GetTextureForPath(item.GetPath(), type);
m_textureDatabase->Close();
return image;
}
return "";
}
void CThumbLoader::SetCachedImage(const CFileItem &item, const std::string &type, const std::string &image)
{
if (!item.GetPath().empty() && m_textureDatabase->Open())
{
m_textureDatabase->SetTextureForPath(item.GetPath(), type, image);
m_textureDatabase->Close();
}
}
CProgramThumbLoader::CProgramThumbLoader() = default;
CProgramThumbLoader::~CProgramThumbLoader() = default;
bool CProgramThumbLoader::LoadItem(CFileItem *pItem)
{
bool result = LoadItemCached(pItem);
result |= LoadItemLookup(pItem);
return result;
}
bool CProgramThumbLoader::LoadItemCached(CFileItem *pItem)
{
if (pItem->IsParentFolder())
return false;
return FillThumb(*pItem);
}
bool CProgramThumbLoader::LoadItemLookup(CFileItem *pItem)
{
return false;
}
bool CProgramThumbLoader::FillThumb(CFileItem &item)
{
// no need to do anything if we already have a thumb set
std::string thumb = item.GetArt("thumb");
if (thumb.empty())
{ // see whether we have a cached image for this item
thumb = GetCachedImage(item, "thumb");
if (thumb.empty())
{
thumb = GetLocalThumb(item);
if (!thumb.empty())
SetCachedImage(item, "thumb", thumb);
}
}
if (!thumb.empty())
{
CServiceBroker::GetTextureCache()->BackgroundCacheImage(thumb);
item.SetArt("thumb", thumb);
}
return true;
}
std::string CProgramThumbLoader::GetLocalThumb(const CFileItem &item)
{
if (item.IsAddonsPath())
return "";
// look for the thumb
if (item.m_bIsFolder)
{
std::string folderThumb = item.GetFolderThumb();
if (CFileUtils::Exists(folderThumb))
return folderThumb;
}
else
{
std::string fileThumb(item.GetTBNFile());
if (CFileUtils::Exists(fileThumb))
return fileThumb;
}
return "";
}
|