Merge pull request #25614 from garbear/show-version
[xbmc.git] / xbmc / pvr / guilib / PVRGUIActionsUtils.cpp
blobc6399f1a26e29c450d01ce2c3b31633f38e5624e
1 /*
2 * Copyright (C) 2016-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 "PVRGUIActionsUtils.h"
11 #include "FileItem.h"
12 #include "FileItemList.h"
13 #include "ServiceBroker.h"
14 #include "filesystem/Directory.h"
15 #include "pvr/PVRManager.h"
16 #include "pvr/channels/PVRChannelGroupsContainer.h"
17 #include "pvr/guilib/PVRGUIActionsEPG.h"
18 #include "pvr/guilib/PVRGUIActionsRecordings.h"
19 #include "utils/URIUtils.h"
20 #include "utils/log.h"
22 namespace PVR
24 bool CPVRGUIActionsUtils::HasInfoForItem(const CFileItem& item) const
26 return item.HasPVRRecordingInfoTag() || item.HasPVRChannelInfoTag() ||
27 item.HasPVRTimerInfoTag() || item.HasEPGSearchFilter();
30 bool CPVRGUIActionsUtils::OnInfo(const CFileItem& item)
32 if (item.HasPVRRecordingInfoTag())
34 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Recordings>().ShowRecordingInfo(item);
36 else if (item.HasPVRChannelInfoTag() || item.HasPVRTimerInfoTag())
38 return CServiceBroker::GetPVRManager().Get<PVR::GUI::EPG>().ShowEPGInfo(item);
40 else if (item.HasEPGSearchFilter())
42 return CServiceBroker::GetPVRManager().Get<PVR::GUI::EPG>().EditSavedSearch(item);
44 return false;
47 namespace
49 std::shared_ptr<CFileItem> LoadRecordingFileOrFolderItem(const CFileItem& item)
51 if (URIUtils::IsPVRRecordingFileOrFolder(item.GetPath()))
53 //! @todo prop misused to detect loaded state for recording folder item
54 if (item.HasPVRRecordingInfoTag() || item.HasProperty("watchedepisodes"))
55 return std::make_shared<CFileItem>(item); // already loaded
57 const std::string parentPath{URIUtils::GetParentPath(item.GetPath())};
59 //! @todo optimize, find a way to set the details of the item without loading parent directory.
60 CFileItemList items;
61 if (XFILE::CDirectory::GetDirectory(parentPath, items, "", XFILE::DIR_FLAG_DEFAULTS))
63 const std::string& path{item.GetPath()};
64 const auto it = std::find_if(items.cbegin(), items.cend(),
65 [&path](const auto& entry) { return entry->GetPath() == path; });
66 if (it != items.cend())
67 return *it;
70 return {};
73 std::shared_ptr<CFileItem> LoadChannelItem(const CFileItem& item)
75 if (URIUtils::IsPVRChannel(item.GetPath()))
77 if (item.HasPVRChannelInfoTag())
78 return std::make_shared<CFileItem>(item); // already loaded
80 const auto groups{CServiceBroker::GetPVRManager().ChannelGroups()};
81 const std::shared_ptr<CPVRChannelGroupMember> groupMember{
82 groups->GetChannelGroupMemberByPath(item.GetPath())};
83 if (groupMember)
84 return std::make_shared<CFileItem>(groupMember);
86 return {};
88 } // unnamed namespace
90 std::shared_ptr<CFileItem> CPVRGUIActionsUtils::LoadItem(const CFileItem& item)
92 std::shared_ptr<CFileItem> loadedItem{LoadRecordingFileOrFolderItem(item)};
93 if (loadedItem)
94 return loadedItem;
96 loadedItem = LoadChannelItem(item);
97 if (loadedItem)
98 return loadedItem;
100 CLog::LogFC(LOGWARNING, LOGPVR, "Error loading item details (path={})", item.GetPath());
101 return {};
104 } // namespace PVR