[video] fix selection after changing video or extra art
[xbmc.git] / xbmc / pvr / PVRThumbLoader.cpp
blob3f5fa638223d7c63c8610e910aa5c2eb83ce378e
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 "PVRThumbLoader.h"
11 #include "FileItem.h"
12 #include "ServiceBroker.h"
13 #include "TextureCache.h"
14 #include "pvr/PVRManager.h"
15 #include "pvr/filesystem/PVRGUIDirectory.h"
16 #include "settings/AdvancedSettings.h"
17 #include "settings/Settings.h"
18 #include "settings/SettingsComponent.h"
19 #include "utils/StringUtils.h"
20 #include "utils/log.h"
22 #include <ctime>
24 using namespace PVR;
26 bool CPVRThumbLoader::LoadItem(CFileItem* item)
28 bool result = LoadItemCached(item);
29 result |= LoadItemLookup(item);
30 return result;
33 bool CPVRThumbLoader::LoadItemCached(CFileItem* item)
35 return FillThumb(*item);
38 bool CPVRThumbLoader::LoadItemLookup(CFileItem* item)
40 return false;
43 void CPVRThumbLoader::OnLoaderFinish()
45 if (m_bInvalidated)
47 m_bInvalidated = false;
48 CServiceBroker::GetPVRManager().PublishEvent(PVREvent::ChannelGroupsInvalidated);
50 CThumbLoader::OnLoaderFinish();
53 void CPVRThumbLoader::ClearCachedImage(CFileItem& item)
55 const std::string thumb = item.GetArt("thumb");
56 if (!thumb.empty())
58 CServiceBroker::GetTextureCache()->ClearCachedImage(thumb);
59 if (m_textureDatabase->Open())
61 m_textureDatabase->ClearTextureForPath(item.GetPath(), "thumb");
62 m_textureDatabase->Close();
64 item.SetArt("thumb", "");
65 m_bInvalidated = true;
69 void CPVRThumbLoader::ClearCachedImages(const CFileItemList& items)
71 for (auto& item : items)
72 ClearCachedImage(*item);
75 bool CPVRThumbLoader::FillThumb(CFileItem& item)
77 // see whether we have a cached image for this item
78 std::string thumb = GetCachedImage(item, "thumb");
79 if (thumb.empty())
81 if (item.IsPVRChannelGroup())
82 thumb = CreateChannelGroupThumb(item);
83 else
84 CLog::LogF(LOGERROR, "Unsupported PVR item '{}'", item.GetPath());
86 if (!thumb.empty())
88 SetCachedImage(item, "thumb", thumb);
89 m_bInvalidated = true;
93 if (thumb.empty())
94 return false;
96 item.SetArt("thumb", thumb);
97 return true;
100 std::string CPVRThumbLoader::CreateChannelGroupThumb(const CFileItem& channelGroupItem)
102 return StringUtils::Format("{}?ts={}", // append timestamp to Thumb URL to enforce texture refresh
103 CTextureUtils::GetWrappedImageURL(channelGroupItem.GetPath(), "pvr"),
104 std::time(nullptr));