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 "PVRGUIActionsEPG.h"
12 #include "ServiceBroker.h"
13 #include "dialogs/GUIDialogYesNo.h"
14 #include "guilib/GUIComponent.h"
15 #include "guilib/GUIKeyboardFactory.h"
16 #include "guilib/GUIWindowManager.h"
17 #include "guilib/LocalizeStrings.h"
18 #include "guilib/WindowIDs.h"
19 #include "pvr/PVRItem.h"
20 #include "pvr/PVRManager.h"
21 #include "pvr/dialogs/GUIDialogPVRChannelGuide.h"
22 #include "pvr/dialogs/GUIDialogPVRGuideInfo.h"
23 #include "pvr/epg/EpgContainer.h"
24 #include "pvr/epg/EpgSearchFilter.h"
25 #include "pvr/guilib/PVRGUIActionsParentalControl.h"
26 #include "pvr/windows/GUIWindowPVRSearch.h"
27 #include "utils/Variant.h"
28 #include "utils/log.h"
37 PVR::CGUIWindowPVRSearchBase
* GetSearchWindow(bool bRadio
)
39 const int windowSearchId
= bRadio
? WINDOW_RADIO_SEARCH
: WINDOW_TV_SEARCH
;
41 PVR::CGUIWindowPVRSearchBase
* windowSearch
;
43 CGUIWindowManager
& windowMgr
= CServiceBroker::GetGUI()->GetWindowManager();
45 windowSearch
= windowMgr
.GetWindow
<PVR::CGUIWindowPVRRadioSearch
>(windowSearchId
);
47 windowSearch
= windowMgr
.GetWindow
<PVR::CGUIWindowPVRTVSearch
>(windowSearchId
);
50 CLog::LogF(LOGERROR
, "Unable to get {}!", bRadio
? "WINDOW_RADIO_SEARCH" : "WINDOW_TV_SEARCH");
54 } // unnamed namespace
56 bool CPVRGUIActionsEPG::ShowEPGInfo(const CFileItem
& item
) const
58 const std::shared_ptr
<const CPVRChannel
> channel(CPVRItem(item
).GetChannel());
59 if (channel
&& CServiceBroker::GetPVRManager().Get
<PVR::GUI::Parental
>().CheckParentalLock(
60 channel
) != ParentalCheckResult::SUCCESS
)
63 const std::shared_ptr
<CPVREpgInfoTag
> epgTag(CPVRItem(item
).GetEpgInfoTag());
66 CLog::LogF(LOGERROR
, "No epg tag!");
70 CGUIDialogPVRGuideInfo
* pDlgInfo
=
71 CServiceBroker::GetGUI()->GetWindowManager().GetWindow
<CGUIDialogPVRGuideInfo
>(
72 WINDOW_DIALOG_PVR_GUIDE_INFO
);
75 CLog::LogF(LOGERROR
, "Unable to get WINDOW_DIALOG_PVR_GUIDE_INFO!");
79 pDlgInfo
->SetProgInfo(std::make_shared
<CFileItem
>(epgTag
));
84 bool CPVRGUIActionsEPG::ShowChannelEPG(const CFileItem
& item
) const
86 const std::shared_ptr
<const CPVRChannel
> channel(CPVRItem(item
).GetChannel());
87 if (channel
&& CServiceBroker::GetPVRManager().Get
<PVR::GUI::Parental
>().CheckParentalLock(
88 channel
) != ParentalCheckResult::SUCCESS
)
91 CGUIDialogPVRChannelGuide
* pDlgInfo
=
92 CServiceBroker::GetGUI()->GetWindowManager().GetWindow
<CGUIDialogPVRChannelGuide
>(
93 WINDOW_DIALOG_PVR_CHANNEL_GUIDE
);
96 CLog::LogF(LOGERROR
, "Unable to get WINDOW_DIALOG_PVR_CHANNEL_GUIDE!");
100 pDlgInfo
->Open(channel
);
104 bool CPVRGUIActionsEPG::FindSimilar(const CFileItem
& item
) const
106 CGUIWindowPVRSearchBase
* windowSearch
= GetSearchWindow(CPVRItem(item
).IsRadio());
110 //! @todo If we want dialogs to spawn program search in a clean way - without having to force-close any
111 // other dialogs - we must introduce a search dialog with functionality similar to the search window.
113 for (int iId
= CServiceBroker::GetGUI()->GetWindowManager().GetTopmostModalDialog(
114 true /* ignoreClosing */);
115 iId
!= WINDOW_INVALID
;
116 iId
= CServiceBroker::GetGUI()->GetWindowManager().GetTopmostModalDialog(
117 true /* ignoreClosing */))
119 CLog::LogF(LOGWARNING
,
120 "Have to close modal dialog with id {} before search window can be opened.", iId
);
122 CGUIWindow
* window
= CServiceBroker::GetGUI()->GetWindowManager().GetWindow(iId
);
129 CLog::LogF(LOGERROR
, "Unable to get window instance {}! Cannot open search window.", iId
);
130 return false; // return, otherwise we run into an endless loop
134 windowSearch
->SetItemToSearch(item
);
135 CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(windowSearch
->GetID());
139 bool CPVRGUIActionsEPG::ExecuteSavedSearch(const CFileItem
& item
)
141 const auto searchFilter
= item
.GetEPGSearchFilter();
145 CLog::LogF(LOGERROR
, "Wrong item type. No EPG search filter present.");
149 CGUIWindowPVRSearchBase
* windowSearch
= GetSearchWindow(searchFilter
->IsRadio());
153 windowSearch
->SetItemToSearch(item
);
154 CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(windowSearch
->GetID());
158 bool CPVRGUIActionsEPG::EditSavedSearch(const CFileItem
& item
)
160 const auto searchFilter
= item
.GetEPGSearchFilter();
164 CLog::LogF(LOGERROR
, "Wrong item type. No EPG search filter present.");
168 CGUIWindowPVRSearchBase
* windowSearch
= GetSearchWindow(searchFilter
->IsRadio());
172 if (windowSearch
->OpenDialogSearch(item
) == CGUIDialogPVRGuideSearch::Result::SEARCH
)
173 CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(windowSearch
->GetID());
178 bool CPVRGUIActionsEPG::RenameSavedSearch(const CFileItem
& item
)
180 const auto searchFilter
= item
.GetEPGSearchFilter();
184 CLog::LogF(LOGERROR
, "Wrong item type. No EPG search filter present.");
188 std::string title
= searchFilter
->GetTitle();
189 if (CGUIKeyboardFactory::ShowAndGetInput(title
,
190 CVariant
{g_localizeStrings
.Get(528)}, // "Enter title"
193 searchFilter
->SetTitle(title
);
194 CServiceBroker::GetPVRManager().EpgContainer().PersistSavedSearch(*searchFilter
);
200 bool CPVRGUIActionsEPG::DeleteSavedSearch(const CFileItem
& item
)
202 const auto searchFilter
= item
.GetEPGSearchFilter();
206 CLog::LogF(LOGERROR
, "Wrong item type. No EPG search filter present.");
210 if (CGUIDialogYesNo::ShowAndGetInput(CVariant
{122}, // "Confirm delete"
211 CVariant
{19338}, // "Delete this saved search?"
212 CVariant
{""}, CVariant
{item
.GetLabel()}))
214 return CServiceBroker::GetPVRManager().EpgContainer().DeleteSavedSearch(*searchFilter
);