2 * Copyright (C) 2012-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 "PVRClientMenuHooks.h"
11 #include "addons/kodi-dev-kit/include/kodi/c-api/addon-instance/pvr/pvr_menu_hook.h"
12 #include "guilib/LocalizeStrings.h"
13 #include "pvr/PVRContextMenus.h"
14 #include "utils/log.h"
21 CPVRClientMenuHook::CPVRClientMenuHook(const std::string
& addonId
, const PVR_MENUHOOK
& hook
)
23 m_hook(new PVR_MENUHOOK(hook
))
25 if (hook
.category
!= PVR_MENUHOOK_UNKNOWN
&&
26 hook
.category
!= PVR_MENUHOOK_ALL
&&
27 hook
.category
!= PVR_MENUHOOK_CHANNEL
&&
28 hook
.category
!= PVR_MENUHOOK_TIMER
&&
29 hook
.category
!= PVR_MENUHOOK_EPG
&&
30 hook
.category
!= PVR_MENUHOOK_RECORDING
&&
31 hook
.category
!= PVR_MENUHOOK_DELETED_RECORDING
&&
32 hook
.category
!= PVR_MENUHOOK_SETTING
)
33 CLog::LogF(LOGERROR
, "Unknown PVR_MENUHOOK_CAT value: {}", hook
.category
);
36 bool CPVRClientMenuHook::operator ==(const CPVRClientMenuHook
& right
) const
41 return m_addonId
== right
.m_addonId
&&
42 m_hook
->iHookId
== right
.m_hook
->iHookId
&&
43 m_hook
->iLocalizedStringId
== right
.m_hook
->iLocalizedStringId
&&
44 m_hook
->category
== right
.m_hook
->category
;
47 bool CPVRClientMenuHook::IsAllHook() const
49 return m_hook
->category
== PVR_MENUHOOK_ALL
;
52 bool CPVRClientMenuHook::IsChannelHook() const
54 return m_hook
->category
== PVR_MENUHOOK_CHANNEL
;
57 bool CPVRClientMenuHook::IsTimerHook() const
59 return m_hook
->category
== PVR_MENUHOOK_TIMER
;
62 bool CPVRClientMenuHook::IsEpgHook() const
64 return m_hook
->category
== PVR_MENUHOOK_EPG
;
67 bool CPVRClientMenuHook::IsRecordingHook() const
69 return m_hook
->category
== PVR_MENUHOOK_RECORDING
;
72 bool CPVRClientMenuHook::IsDeletedRecordingHook() const
74 return m_hook
->category
== PVR_MENUHOOK_DELETED_RECORDING
;
77 bool CPVRClientMenuHook::IsSettingsHook() const
79 return m_hook
->category
== PVR_MENUHOOK_SETTING
;
82 unsigned int CPVRClientMenuHook::GetId() const
84 return m_hook
->iHookId
;
87 unsigned int CPVRClientMenuHook::GetLabelId() const
89 return m_hook
->iLocalizedStringId
;
92 std::string
CPVRClientMenuHook::GetLabel() const
94 return g_localizeStrings
.GetAddonString(m_addonId
, m_hook
->iLocalizedStringId
);
97 void CPVRClientMenuHooks::AddHook(const PVR_MENUHOOK
& addonHook
)
100 m_hooks
= std::make_unique
<std::vector
<CPVRClientMenuHook
>>();
102 const CPVRClientMenuHook
hook(m_addonId
, addonHook
);
103 m_hooks
->emplace_back(hook
);
104 CPVRContextMenuManager::GetInstance().AddMenuHook(hook
);
107 void CPVRClientMenuHooks::Clear()
112 for (const auto& hook
: *m_hooks
)
113 CPVRContextMenuManager::GetInstance().RemoveMenuHook(hook
);
118 std::vector
<CPVRClientMenuHook
> CPVRClientMenuHooks::GetHooks(
119 const std::function
<bool(const CPVRClientMenuHook
& hook
)>& function
) const
121 std::vector
<CPVRClientMenuHook
> hooks
;
126 for (const CPVRClientMenuHook
& hook
: *m_hooks
)
128 if (function(hook
) || hook
.IsAllHook())
129 hooks
.emplace_back(hook
);
134 std::vector
<CPVRClientMenuHook
> CPVRClientMenuHooks::GetChannelHooks() const
136 return GetHooks([](const CPVRClientMenuHook
& hook
)
138 return hook
.IsChannelHook();
142 std::vector
<CPVRClientMenuHook
> CPVRClientMenuHooks::GetTimerHooks() const
144 return GetHooks([](const CPVRClientMenuHook
& hook
)
146 return hook
.IsTimerHook();
150 std::vector
<CPVRClientMenuHook
> CPVRClientMenuHooks::GetEpgHooks() const
152 return GetHooks([](const CPVRClientMenuHook
& hook
)
154 return hook
.IsEpgHook();
158 std::vector
<CPVRClientMenuHook
> CPVRClientMenuHooks::GetRecordingHooks() const
160 return GetHooks([](const CPVRClientMenuHook
& hook
)
162 return hook
.IsRecordingHook();
166 std::vector
<CPVRClientMenuHook
> CPVRClientMenuHooks::GetDeletedRecordingHooks() const
168 return GetHooks([](const CPVRClientMenuHook
& hook
)
170 return hook
.IsDeletedRecordingHook();
174 std::vector
<CPVRClientMenuHook
> CPVRClientMenuHooks::GetSettingsHooks() const
176 return GetHooks([](const CPVRClientMenuHook
& hook
)
178 return hook
.IsSettingsHook();