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.
9 #include "PVRGUIActionsUtils.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"
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
);
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.
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())
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())};
84 return std::make_shared
<CFileItem
>(groupMember
);
88 } // unnamed namespace
90 std::shared_ptr
<CFileItem
> CPVRGUIActionsUtils::LoadItem(const CFileItem
& item
)
92 std::shared_ptr
<CFileItem
> loadedItem
{LoadRecordingFileOrFolderItem(item
)};
96 loadedItem
= LoadChannelItem(item
);
100 CLog::LogFC(LOGWARNING
, LOGPVR
, "Error loading item details (path={})", item
.GetPath());