[Windows] Fix driver version detection of AMD RDNA+ GPU on Windows 10
[xbmc.git] / xbmc / pvr / PVRContextMenus.cpp
blob47004fa744912e1ded4074909f3348c0ac37e513
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 "PVRContextMenus.h"
11 #include "ContextMenuItem.h"
12 #include "FileItem.h"
13 #include "ServiceBroker.h"
14 #include "guilib/LocalizeStrings.h"
15 #include "pvr/PVRManager.h"
16 #include "pvr/addons/PVRClient.h"
17 #include "pvr/addons/PVRClientMenuHooks.h"
18 #include "pvr/addons/PVRClients.h"
19 #include "pvr/channels/PVRChannel.h"
20 #include "pvr/channels/PVRChannelGroupsContainer.h"
21 #include "pvr/epg/EpgInfoTag.h"
22 #include "pvr/guilib/PVRGUIActionsEPG.h"
23 #include "pvr/guilib/PVRGUIActionsPlayback.h"
24 #include "pvr/guilib/PVRGUIActionsRecordings.h"
25 #include "pvr/guilib/PVRGUIActionsTimers.h"
26 #include "pvr/recordings/PVRRecording.h"
27 #include "pvr/recordings/PVRRecordings.h"
28 #include "pvr/recordings/PVRRecordingsPath.h"
29 #include "pvr/timers/PVRTimerInfoTag.h"
30 #include "pvr/timers/PVRTimers.h"
31 #include "pvr/timers/PVRTimersPath.h"
32 #include "settings/Settings.h"
33 #include "settings/SettingsComponent.h"
34 #include "utils/URIUtils.h"
36 #include <memory>
37 #include <string>
39 namespace PVR
41 namespace CONTEXTMENUITEM
43 #define DECL_STATICCONTEXTMENUITEM(clazz) \
44 class clazz : public CStaticContextMenuAction \
45 { \
46 public: \
47 explicit clazz(uint32_t label) : CStaticContextMenuAction(label) {} \
48 bool IsVisible(const CFileItem& item) const override; \
49 bool Execute(const CFileItemPtr& item) const override; \
52 #define DECL_CONTEXTMENUITEM(clazz) \
53 class clazz : public IContextMenuItem \
54 { \
55 public: \
56 std::string GetLabel(const CFileItem& item) const override; \
57 bool IsVisible(const CFileItem& item) const override; \
58 bool Execute(const CFileItemPtr& item) const override; \
61 DECL_STATICCONTEXTMENUITEM(PlayEpgTag);
62 DECL_CONTEXTMENUITEM(PlayEpgTagFromHere);
63 DECL_STATICCONTEXTMENUITEM(PlayRecording);
64 DECL_CONTEXTMENUITEM(ShowInformation);
65 DECL_STATICCONTEXTMENUITEM(ShowChannelGuide);
66 DECL_STATICCONTEXTMENUITEM(FindSimilar);
67 DECL_STATICCONTEXTMENUITEM(StartRecording);
68 DECL_STATICCONTEXTMENUITEM(StopRecording);
69 DECL_STATICCONTEXTMENUITEM(AddTimerRule);
70 DECL_CONTEXTMENUITEM(EditTimerRule);
71 DECL_STATICCONTEXTMENUITEM(DeleteTimerRule);
72 DECL_CONTEXTMENUITEM(EditTimer);
73 DECL_CONTEXTMENUITEM(DeleteTimer);
74 DECL_STATICCONTEXTMENUITEM(EditRecording);
75 DECL_CONTEXTMENUITEM(DeleteRecording);
76 DECL_STATICCONTEXTMENUITEM(UndeleteRecording);
77 DECL_STATICCONTEXTMENUITEM(DeleteWatchedRecordings);
78 DECL_CONTEXTMENUITEM(ToggleTimerState);
79 DECL_STATICCONTEXTMENUITEM(AddReminder);
80 DECL_STATICCONTEXTMENUITEM(ExecuteSearch);
81 DECL_STATICCONTEXTMENUITEM(EditSearch);
82 DECL_STATICCONTEXTMENUITEM(RenameSearch);
83 DECL_STATICCONTEXTMENUITEM(DeleteSearch);
85 class PVRClientMenuHook : public IContextMenuItem
87 public:
88 explicit PVRClientMenuHook(const CPVRClientMenuHook& hook) : m_hook(hook) {}
90 std::string GetLabel(const CFileItem& item) const override;
91 bool IsVisible(const CFileItem& item) const override;
92 bool Execute(const CFileItemPtr& item) const override;
94 const CPVRClientMenuHook& GetHook() const { return m_hook; }
96 private:
97 const CPVRClientMenuHook m_hook;
100 std::shared_ptr<CPVRTimerInfoTag> GetTimerInfoTagFromItem(const CFileItem& item)
102 std::shared_ptr<CPVRTimerInfoTag> timer;
104 const std::shared_ptr<const CPVREpgInfoTag> epg(item.GetEPGInfoTag());
105 if (epg)
106 timer = CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(epg);
108 if (!timer)
109 timer = item.GetPVRTimerInfoTag();
111 return timer;
114 ///////////////////////////////////////////////////////////////////////////////
115 // Play epg tag
117 bool PlayEpgTag::IsVisible(const CFileItem& item) const
119 const std::shared_ptr<const CPVREpgInfoTag> epg(item.GetEPGInfoTag());
120 if (epg)
121 return epg->IsPlayable();
123 return false;
126 bool PlayEpgTag::Execute(const CFileItemPtr& item) const
128 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Playback>().PlayEpgTag(*item);
131 ///////////////////////////////////////////////////////////////////////////////
132 // Play epg tag from here
134 std::string PlayEpgTagFromHere::GetLabel(const CFileItem& item) const
136 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
137 CSettings::SETTING_PVRPLAYBACK_AUTOPLAYNEXTPROGRAMME))
138 return g_localizeStrings.Get(19354); /* Play only this programme */
140 return g_localizeStrings.Get(19353); /* Play programmes from here */
143 bool PlayEpgTagFromHere::IsVisible(const CFileItem& item) const
145 const std::shared_ptr<const CPVREpgInfoTag> epg(item.GetEPGInfoTag());
146 if (epg)
147 return epg->IsPlayable();
149 return false;
152 bool PlayEpgTagFromHere::Execute(const CFileItemPtr& item) const
154 ContentUtils::PlayMode mode{ContentUtils::PlayMode::PLAY_FROM_HERE};
155 if (CServiceBroker::GetSettingsComponent()->GetSettings()->GetBool(
156 CSettings::SETTING_PVRPLAYBACK_AUTOPLAYNEXTPROGRAMME))
157 mode = ContentUtils::PlayMode::PLAY_ONLY_THIS;
159 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Playback>().PlayEpgTag(*item, mode);
162 ///////////////////////////////////////////////////////////////////////////////
163 // Play recording
165 bool PlayRecording::IsVisible(const CFileItem& item) const
167 const std::shared_ptr<const CPVRRecording> recording =
168 CServiceBroker::GetPVRManager().Recordings()->GetRecordingForEpgTag(item.GetEPGInfoTag());
169 if (recording)
170 return !recording->IsDeleted();
172 return false;
175 bool PlayRecording::Execute(const CFileItemPtr& item) const
177 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Playback>().PlayRecording(
178 *item, true /* bCheckResume */);
181 ///////////////////////////////////////////////////////////////////////////////
182 // Show information (epg, recording)
184 std::string ShowInformation::GetLabel(const CFileItem& item) const
186 if (item.GetPVRRecordingInfoTag())
187 return g_localizeStrings.Get(19053); /* Recording Information */
189 return g_localizeStrings.Get(19047); /* Programme information */
192 bool ShowInformation::IsVisible(const CFileItem& item) const
194 const std::shared_ptr<const CPVRChannel> channel(item.GetPVRChannelInfoTag());
195 if (channel)
196 return channel->GetEPGNow().get() != nullptr;
198 if (item.HasEPGInfoTag())
199 return !item.GetEPGInfoTag()->IsGapTag();
201 const std::shared_ptr<const CPVRTimerInfoTag> timer(item.GetPVRTimerInfoTag());
202 if (timer && !URIUtils::PathEquals(item.GetPath(), CPVRTimersPath::PATH_ADDTIMER))
203 return timer->GetEpgInfoTag().get() != nullptr;
205 if (item.GetPVRRecordingInfoTag())
206 return true;
208 return false;
211 bool ShowInformation::Execute(const CFileItemPtr& item) const
213 if (item->GetPVRRecordingInfoTag())
214 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Recordings>().ShowRecordingInfo(*item);
216 return CServiceBroker::GetPVRManager().Get<PVR::GUI::EPG>().ShowEPGInfo(*item);
219 ///////////////////////////////////////////////////////////////////////////////
220 // Show channel guide
222 bool ShowChannelGuide::IsVisible(const CFileItem& item) const
224 const std::shared_ptr<const CPVRChannel> channel(item.GetPVRChannelInfoTag());
225 if (channel)
226 return channel->GetEPGNow().get() != nullptr;
228 return false;
231 bool ShowChannelGuide::Execute(const CFileItemPtr& item) const
233 return CServiceBroker::GetPVRManager().Get<PVR::GUI::EPG>().ShowChannelEPG(*item);
236 ///////////////////////////////////////////////////////////////////////////////
237 // Find similar
239 bool FindSimilar::IsVisible(const CFileItem& item) const
241 const std::shared_ptr<const CPVRChannel> channel(item.GetPVRChannelInfoTag());
242 if (channel)
243 return channel->GetEPGNow().get() != nullptr;
245 if (item.HasEPGInfoTag())
246 return !item.GetEPGInfoTag()->IsGapTag();
248 const std::shared_ptr<const CPVRTimerInfoTag> timer(item.GetPVRTimerInfoTag());
249 if (timer && !URIUtils::PathEquals(item.GetPath(), CPVRTimersPath::PATH_ADDTIMER))
250 return timer->GetEpgInfoTag().get() != nullptr;
252 const std::shared_ptr<const CPVRRecording> recording(item.GetPVRRecordingInfoTag());
253 if (recording)
254 return !recording->IsDeleted();
256 return false;
259 bool FindSimilar::Execute(const CFileItemPtr& item) const
261 return CServiceBroker::GetPVRManager().Get<PVR::GUI::EPG>().FindSimilar(*item);
264 ///////////////////////////////////////////////////////////////////////////////
265 // Start recording
267 bool StartRecording::IsVisible(const CFileItem& item) const
269 const std::shared_ptr<const CPVRClient> client = CServiceBroker::GetPVRManager().GetClient(item);
271 std::shared_ptr<CPVRChannel> channel = item.GetPVRChannelInfoTag();
272 if (channel)
273 return client && client->GetClientCapabilities().SupportsTimers() &&
274 !CServiceBroker::GetPVRManager().Timers()->IsRecordingOnChannel(*channel);
276 const std::shared_ptr<const CPVREpgInfoTag> epg = item.GetEPGInfoTag();
277 if (epg && epg->IsRecordable())
279 if (epg->IsGapTag())
281 channel = CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelForEpgTag(epg);
282 if (channel)
284 return client && client->GetClientCapabilities().SupportsTimers() &&
285 !CServiceBroker::GetPVRManager().Timers()->IsRecordingOnChannel(*channel);
288 else
290 return client && client->GetClientCapabilities().SupportsTimers() &&
291 !CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(epg);
294 return false;
297 bool StartRecording::Execute(const CFileItemPtr& item) const
299 const std::shared_ptr<const CPVREpgInfoTag> epgTag = item->GetEPGInfoTag();
300 if (!epgTag || epgTag->IsActive())
302 // instant recording
303 std::shared_ptr<CPVRChannel> channel;
304 if (epgTag)
305 channel = CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelForEpgTag(epgTag);
307 if (!channel)
308 channel = item->GetPVRChannelInfoTag();
310 if (channel)
311 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Timers>().SetRecordingOnChannel(channel,
312 true);
315 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Timers>().AddTimer(*item, false);
318 ///////////////////////////////////////////////////////////////////////////////
319 // Stop recording
321 bool StopRecording::IsVisible(const CFileItem& item) const
323 const std::shared_ptr<const CPVRRecording> recording(item.GetPVRRecordingInfoTag());
324 if (recording && recording->IsInProgress())
325 return true;
327 std::shared_ptr<CPVRChannel> channel = item.GetPVRChannelInfoTag();
328 if (channel)
329 return CServiceBroker::GetPVRManager().Timers()->IsRecordingOnChannel(*channel);
331 const std::shared_ptr<const CPVRTimerInfoTag> timer(GetTimerInfoTagFromItem(item));
332 if (timer && !URIUtils::PathEquals(item.GetPath(), CPVRTimersPath::PATH_ADDTIMER))
333 return timer->IsRecording();
335 const std::shared_ptr<const CPVREpgInfoTag> epg = item.GetEPGInfoTag();
336 if (epg && epg->IsGapTag())
338 channel = CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelForEpgTag(epg);
339 if (channel)
340 return CServiceBroker::GetPVRManager().Timers()->IsRecordingOnChannel(*channel);
343 return false;
346 bool StopRecording::Execute(const CFileItemPtr& item) const
348 const std::shared_ptr<const CPVREpgInfoTag> epgTag = item->GetEPGInfoTag();
349 if (epgTag && epgTag->IsGapTag())
351 // instance recording
352 const std::shared_ptr<CPVRChannel> channel =
353 CServiceBroker::GetPVRManager().ChannelGroups()->GetChannelForEpgTag(epgTag);
354 if (channel)
355 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Timers>().SetRecordingOnChannel(channel,
356 false);
359 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Timers>().StopRecording(*item);
362 ///////////////////////////////////////////////////////////////////////////////
363 // Edit recording
365 bool EditRecording::IsVisible(const CFileItem& item) const
367 const std::shared_ptr<const CPVRRecording> recording(item.GetPVRRecordingInfoTag());
368 if (recording && !recording->IsDeleted() && !recording->IsInProgress())
370 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Recordings>().CanEditRecording(item);
372 return false;
375 bool EditRecording::Execute(const CFileItemPtr& item) const
377 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Recordings>().EditRecording(*item);
380 ///////////////////////////////////////////////////////////////////////////////
381 // Delete recording
383 std::string DeleteRecording::GetLabel(const CFileItem& item) const
385 const std::shared_ptr<const CPVRRecording> recording(item.GetPVRRecordingInfoTag());
386 if (recording && recording->IsDeleted())
387 return g_localizeStrings.Get(19291); /* Delete permanently */
389 return g_localizeStrings.Get(117); /* Delete */
392 bool DeleteRecording::IsVisible(const CFileItem& item) const
394 const std::shared_ptr<const CPVRClient> client = CServiceBroker::GetPVRManager().GetClient(item);
395 if (client && !client->GetClientCapabilities().SupportsRecordingsDelete())
396 return false;
398 const std::shared_ptr<const CPVRRecording> recording(item.GetPVRRecordingInfoTag());
399 if (recording && !recording->IsInProgress())
400 return true;
402 // recordings folder?
403 if (item.m_bIsFolder &&
404 CServiceBroker::GetPVRManager().Clients()->AnyClientSupportingRecordingsDelete())
406 const CPVRRecordingsPath path(item.GetPath());
407 return path.IsValid() && !path.IsRecordingsRoot();
410 return false;
413 bool DeleteRecording::Execute(const CFileItemPtr& item) const
415 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Recordings>().DeleteRecording(*item);
418 ///////////////////////////////////////////////////////////////////////////////
419 // Undelete recording
421 bool UndeleteRecording::IsVisible(const CFileItem& item) const
423 const std::shared_ptr<const CPVRRecording> recording(item.GetPVRRecordingInfoTag());
424 if (recording && recording->IsDeleted())
425 return true;
427 return false;
430 bool UndeleteRecording::Execute(const CFileItemPtr& item) const
432 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Recordings>().UndeleteRecording(*item);
435 ///////////////////////////////////////////////////////////////////////////////
436 // Delete watched recordings
438 bool DeleteWatchedRecordings::IsVisible(const CFileItem& item) const
440 // recordings folder?
441 if (item.m_bIsFolder && !item.IsParentFolder())
442 return CPVRRecordingsPath(item.GetPath()).IsValid();
444 return false;
447 bool DeleteWatchedRecordings::Execute(const std::shared_ptr<CFileItem>& item) const
449 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Recordings>().DeleteWatchedRecordings(*item);
452 ///////////////////////////////////////////////////////////////////////////////
453 // Add reminder
455 bool AddReminder::IsVisible(const CFileItem& item) const
457 const std::shared_ptr<const CPVREpgInfoTag> epg = item.GetEPGInfoTag();
458 if (epg && !CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(epg) &&
459 epg->StartAsLocalTime() > CDateTime::GetCurrentDateTime())
460 return true;
462 return false;
465 bool AddReminder::Execute(const std::shared_ptr<CFileItem>& item) const
467 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Timers>().AddReminder(*item);
470 ///////////////////////////////////////////////////////////////////////////////
471 // Activate / deactivate timer or timer rule
473 std::string ToggleTimerState::GetLabel(const CFileItem& item) const
475 const std::shared_ptr<const CPVRTimerInfoTag> timer(item.GetPVRTimerInfoTag());
476 if (timer && !timer->IsDisabled())
477 return g_localizeStrings.Get(844); /* Deactivate */
479 return g_localizeStrings.Get(843); /* Activate */
482 bool ToggleTimerState::IsVisible(const CFileItem& item) const
484 const std::shared_ptr<const CPVRTimerInfoTag> timer(item.GetPVRTimerInfoTag());
485 if (!timer || URIUtils::PathEquals(item.GetPath(), CPVRTimersPath::PATH_ADDTIMER) ||
486 timer->IsBroken())
487 return false;
489 return timer->GetTimerType()->SupportsEnableDisable();
492 bool ToggleTimerState::Execute(const CFileItemPtr& item) const
494 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Timers>().ToggleTimerState(*item);
497 ///////////////////////////////////////////////////////////////////////////////
498 // Add timer rule
500 bool AddTimerRule::IsVisible(const CFileItem& item) const
502 const std::shared_ptr<const CPVREpgInfoTag> epg = item.GetEPGInfoTag();
503 return (epg && !epg->IsGapTag() &&
504 !CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(epg));
507 bool AddTimerRule::Execute(const CFileItemPtr& item) const
509 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Timers>().AddTimerRule(*item, true, true);
512 ///////////////////////////////////////////////////////////////////////////////
513 // Edit timer rule
515 std::string EditTimerRule::GetLabel(const CFileItem& item) const
517 const std::shared_ptr<const CPVRTimerInfoTag> timer(GetTimerInfoTagFromItem(item));
518 if (timer && !URIUtils::PathEquals(item.GetPath(), CPVRTimersPath::PATH_ADDTIMER))
520 const std::shared_ptr<const CPVRTimerInfoTag> parentTimer(
521 CServiceBroker::GetPVRManager().Timers()->GetTimerRule(timer));
522 if (parentTimer)
524 if (!parentTimer->GetTimerType()->IsReadOnly())
525 return g_localizeStrings.Get(19243); /* Edit timer rule */
529 return g_localizeStrings.Get(19304); /* View timer rule */
532 bool EditTimerRule::IsVisible(const CFileItem& item) const
534 const std::shared_ptr<const CPVRTimerInfoTag> timer(GetTimerInfoTagFromItem(item));
535 if (timer && !URIUtils::PathEquals(item.GetPath(), CPVRTimersPath::PATH_ADDTIMER))
536 return timer->HasParent();
538 return false;
541 bool EditTimerRule::Execute(const CFileItemPtr& item) const
543 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Timers>().EditTimerRule(*item);
546 ///////////////////////////////////////////////////////////////////////////////
547 // Delete timer rule
549 bool DeleteTimerRule::IsVisible(const CFileItem& item) const
551 const std::shared_ptr<const CPVRTimerInfoTag> timer(GetTimerInfoTagFromItem(item));
552 if (timer && !URIUtils::PathEquals(item.GetPath(), CPVRTimersPath::PATH_ADDTIMER))
554 const std::shared_ptr<const CPVRTimerInfoTag> parentTimer(
555 CServiceBroker::GetPVRManager().Timers()->GetTimerRule(timer));
556 if (parentTimer)
557 return parentTimer->GetTimerType()->AllowsDelete();
560 return false;
563 bool DeleteTimerRule::Execute(const CFileItemPtr& item) const
565 auto& timers = CServiceBroker::GetPVRManager().Get<PVR::GUI::Timers>();
566 const std::shared_ptr<CFileItem> parentTimer = timers.GetTimerRule(*item);
567 if (parentTimer)
568 return timers.DeleteTimerRule(*parentTimer);
570 return false;
573 ///////////////////////////////////////////////////////////////////////////////
574 // Edit / View timer
576 std::string EditTimer::GetLabel(const CFileItem& item) const
578 const std::shared_ptr<const CPVRTimerInfoTag> timer(GetTimerInfoTagFromItem(item));
579 if (timer)
581 const std::shared_ptr<const CPVRTimerType> timerType = timer->GetTimerType();
582 if (item.GetEPGInfoTag())
584 if (timerType->IsReminder())
585 return g_localizeStrings.Get(timerType->IsReadOnly() ? 829 /* View reminder */
586 : 830); /* Edit reminder */
587 else
588 return g_localizeStrings.Get(timerType->IsReadOnly() ? 19241 /* View timer */
589 : 19242); /* Edit timer */
591 else
592 return g_localizeStrings.Get(timerType->IsReadOnly() ? 21483 : 21450); /* View/Edit */
594 return g_localizeStrings.Get(19241); /* View timer */
597 bool EditTimer::IsVisible(const CFileItem& item) const
599 const std::shared_ptr<const CPVRTimerInfoTag> timer(GetTimerInfoTagFromItem(item));
600 return timer && (!item.GetEPGInfoTag() ||
601 !URIUtils::PathEquals(item.GetPath(), CPVRTimersPath::PATH_ADDTIMER));
604 bool EditTimer::Execute(const CFileItemPtr& item) const
606 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Timers>().EditTimer(*item);
609 ///////////////////////////////////////////////////////////////////////////////
610 // Delete timer
612 std::string DeleteTimer::GetLabel(const CFileItem& item) const
614 if (item.GetPVRTimerInfoTag())
615 return g_localizeStrings.Get(117); /* Delete */
617 const std::shared_ptr<const CPVREpgInfoTag> epg = item.GetEPGInfoTag();
618 if (epg)
620 const std::shared_ptr<const CPVRTimerInfoTag> timer =
621 CServiceBroker::GetPVRManager().Timers()->GetTimerForEpgTag(epg);
622 if (timer && timer->IsReminder())
623 return g_localizeStrings.Get(827); /* Delete reminder */
625 return g_localizeStrings.Get(19060); /* Delete timer */
628 bool DeleteTimer::IsVisible(const CFileItem& item) const
630 const std::shared_ptr<const CPVRTimerInfoTag> timer(GetTimerInfoTagFromItem(item));
631 if (timer &&
632 (!item.GetEPGInfoTag() ||
633 !URIUtils::PathEquals(item.GetPath(), CPVRTimersPath::PATH_ADDTIMER)) &&
634 !timer->IsRecording())
635 return timer->GetTimerType()->AllowsDelete();
637 return false;
640 bool DeleteTimer::Execute(const CFileItemPtr& item) const
642 return CServiceBroker::GetPVRManager().Get<PVR::GUI::Timers>().DeleteTimer(*item);
645 ///////////////////////////////////////////////////////////////////////////////
646 // PVR Client menu hook
648 std::string PVRClientMenuHook::GetLabel(const CFileItem& item) const
650 return m_hook.GetLabel();
653 bool PVRClientMenuHook::IsVisible(const CFileItem& item) const
655 const std::shared_ptr<const CPVRClient> client = CServiceBroker::GetPVRManager().GetClient(item);
656 if (!client || m_hook.GetAddonId() != client->ID())
657 return false;
659 if (m_hook.IsAllHook())
660 return !item.m_bIsFolder &&
661 !URIUtils::PathEquals(item.GetPath(), CPVRTimersPath::PATH_ADDTIMER);
662 else if (m_hook.IsEpgHook())
663 return item.IsEPG();
664 else if (m_hook.IsChannelHook())
665 return item.IsPVRChannel();
666 else if (m_hook.IsDeletedRecordingHook())
667 return item.IsDeletedPVRRecording();
668 else if (m_hook.IsRecordingHook())
669 return item.IsUsablePVRRecording();
670 else if (m_hook.IsTimerHook())
671 return item.IsPVRTimer();
672 else
673 return false;
676 bool PVRClientMenuHook::Execute(const CFileItemPtr& item) const
678 const std::shared_ptr<CPVRClient> client = CServiceBroker::GetPVRManager().GetClient(*item);
679 if (!client)
680 return false;
682 if (item->IsEPG())
683 return client->CallEpgTagMenuHook(m_hook, item->GetEPGInfoTag()) == PVR_ERROR_NO_ERROR;
684 else if (item->IsPVRChannel())
685 return client->CallChannelMenuHook(m_hook, item->GetPVRChannelInfoTag()) == PVR_ERROR_NO_ERROR;
686 else if (item->IsDeletedPVRRecording())
687 return client->CallRecordingMenuHook(m_hook, item->GetPVRRecordingInfoTag(), true) ==
688 PVR_ERROR_NO_ERROR;
689 else if (item->IsUsablePVRRecording())
690 return client->CallRecordingMenuHook(m_hook, item->GetPVRRecordingInfoTag(), false) ==
691 PVR_ERROR_NO_ERROR;
692 else if (item->IsPVRTimer())
693 return client->CallTimerMenuHook(m_hook, item->GetPVRTimerInfoTag()) == PVR_ERROR_NO_ERROR;
694 else
695 return false;
698 ///////////////////////////////////////////////////////////////////////////////
699 // Execute saved search
701 bool ExecuteSearch::IsVisible(const CFileItem& item) const
703 return item.HasEPGSearchFilter();
706 bool ExecuteSearch::Execute(const std::shared_ptr<CFileItem>& item) const
708 return CServiceBroker::GetPVRManager().Get<PVR::GUI::EPG>().ExecuteSavedSearch(*item);
711 ///////////////////////////////////////////////////////////////////////////////
712 // Edit saved search
714 bool EditSearch::IsVisible(const CFileItem& item) const
716 return item.HasEPGSearchFilter();
719 bool EditSearch::Execute(const std::shared_ptr<CFileItem>& item) const
721 return CServiceBroker::GetPVRManager().Get<PVR::GUI::EPG>().EditSavedSearch(*item);
724 ///////////////////////////////////////////////////////////////////////////////
725 // Rename saved search
727 bool RenameSearch::IsVisible(const CFileItem& item) const
729 return item.HasEPGSearchFilter();
732 bool RenameSearch::Execute(const std::shared_ptr<CFileItem>& item) const
734 return CServiceBroker::GetPVRManager().Get<PVR::GUI::EPG>().RenameSavedSearch(*item);
737 ///////////////////////////////////////////////////////////////////////////////
738 // Delete saved search
740 bool DeleteSearch::IsVisible(const CFileItem& item) const
742 return item.HasEPGSearchFilter();
745 bool DeleteSearch::Execute(const std::shared_ptr<CFileItem>& item) const
747 return CServiceBroker::GetPVRManager().Get<PVR::GUI::EPG>().DeleteSavedSearch(*item);
750 } // namespace CONTEXTMENUITEM
752 CPVRContextMenuManager& CPVRContextMenuManager::GetInstance()
754 static CPVRContextMenuManager instance;
755 return instance;
758 CPVRContextMenuManager::CPVRContextMenuManager()
759 : m_items({
760 std::make_shared<CONTEXTMENUITEM::PlayEpgTag>(19190), /* Play programme */
761 std::make_shared<CONTEXTMENUITEM::PlayEpgTagFromHere>(),
762 std::make_shared<CONTEXTMENUITEM::PlayRecording>(19687), /* Play recording */
763 std::make_shared<CONTEXTMENUITEM::ShowInformation>(),
764 std::make_shared<CONTEXTMENUITEM::ShowChannelGuide>(19686), /* Channel guide */
765 std::make_shared<CONTEXTMENUITEM::FindSimilar>(19003), /* Find similar */
766 std::make_shared<CONTEXTMENUITEM::ToggleTimerState>(),
767 std::make_shared<CONTEXTMENUITEM::AddTimerRule>(19061), /* Add timer */
768 std::make_shared<CONTEXTMENUITEM::EditTimerRule>(),
769 std::make_shared<CONTEXTMENUITEM::DeleteTimerRule>(19295), /* Delete timer rule */
770 std::make_shared<CONTEXTMENUITEM::EditTimer>(),
771 std::make_shared<CONTEXTMENUITEM::DeleteTimer>(),
772 std::make_shared<CONTEXTMENUITEM::StartRecording>(264), /* Record */
773 std::make_shared<CONTEXTMENUITEM::StopRecording>(19059), /* Stop recording */
774 std::make_shared<CONTEXTMENUITEM::EditRecording>(21450), /* Edit */
775 std::make_shared<CONTEXTMENUITEM::DeleteRecording>(),
776 std::make_shared<CONTEXTMENUITEM::UndeleteRecording>(19290), /* Undelete */
777 std::make_shared<CONTEXTMENUITEM::DeleteWatchedRecordings>(19327), /* Delete watched */
778 std::make_shared<CONTEXTMENUITEM::AddReminder>(826), /* Set reminder */
779 std::make_shared<CONTEXTMENUITEM::ExecuteSearch>(137), /* Search */
780 std::make_shared<CONTEXTMENUITEM::EditSearch>(21450), /* Edit */
781 std::make_shared<CONTEXTMENUITEM::RenameSearch>(118), /* Rename */
782 std::make_shared<CONTEXTMENUITEM::DeleteSearch>(117), /* Delete */
787 void CPVRContextMenuManager::AddMenuHook(const CPVRClientMenuHook& hook)
789 if (hook.IsSettingsHook())
790 return; // settings hooks are not handled using context menus
792 const auto item = std::make_shared<CONTEXTMENUITEM::PVRClientMenuHook>(hook);
793 m_items.emplace_back(item);
794 m_events.Publish(PVRContextMenuEvent(PVRContextMenuEventAction::ADD_ITEM, item));
797 void CPVRContextMenuManager::RemoveMenuHook(const CPVRClientMenuHook& hook)
799 if (hook.IsSettingsHook())
800 return; // settings hooks are not handled using context menus
802 for (auto it = m_items.begin(); it < m_items.end(); ++it)
804 const CONTEXTMENUITEM::PVRClientMenuHook* cmh =
805 dynamic_cast<const CONTEXTMENUITEM::PVRClientMenuHook*>((*it).get());
806 if (cmh && cmh->GetHook() == hook)
808 m_events.Publish(PVRContextMenuEvent(PVRContextMenuEventAction::REMOVE_ITEM, *it));
809 m_items.erase(it);
810 return;
815 } // namespace PVR