1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
/*
* Copyright (C) 2016-2018 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "PVRGUIActionsEPG.h"
#include "FileItem.h"
#include "ServiceBroker.h"
#include "dialogs/GUIDialogYesNo.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIKeyboardFactory.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/LocalizeStrings.h"
#include "guilib/WindowIDs.h"
#include "pvr/PVRItem.h"
#include "pvr/PVRManager.h"
#include "pvr/dialogs/GUIDialogPVRChannelGuide.h"
#include "pvr/dialogs/GUIDialogPVRGuideInfo.h"
#include "pvr/epg/EpgContainer.h"
#include "pvr/epg/EpgSearchFilter.h"
#include "pvr/guilib/PVRGUIActionsParentalControl.h"
#include "pvr/windows/GUIWindowPVRSearch.h"
#include "utils/Variant.h"
#include "utils/log.h"
#include <memory>
#include <string>
using namespace PVR;
namespace
{
PVR::CGUIWindowPVRSearchBase* GetSearchWindow(bool bRadio)
{
const int windowSearchId = bRadio ? WINDOW_RADIO_SEARCH : WINDOW_TV_SEARCH;
PVR::CGUIWindowPVRSearchBase* windowSearch;
CGUIWindowManager& windowMgr = CServiceBroker::GetGUI()->GetWindowManager();
if (bRadio)
windowSearch = windowMgr.GetWindow<PVR::CGUIWindowPVRRadioSearch>(windowSearchId);
else
windowSearch = windowMgr.GetWindow<PVR::CGUIWindowPVRTVSearch>(windowSearchId);
if (!windowSearch)
CLog::LogF(LOGERROR, "Unable to get {}!", bRadio ? "WINDOW_RADIO_SEARCH" : "WINDOW_TV_SEARCH");
return windowSearch;
}
} // unnamed namespace
bool CPVRGUIActionsEPG::ShowEPGInfo(const CFileItem& item) const
{
const std::shared_ptr<CPVRChannel> channel(CPVRItem(item).GetChannel());
if (channel && CServiceBroker::GetPVRManager().Get<PVR::GUI::Parental>().CheckParentalLock(
channel) != ParentalCheckResult::SUCCESS)
return false;
const std::shared_ptr<CPVREpgInfoTag> epgTag(CPVRItem(item).GetEpgInfoTag());
if (!epgTag)
{
CLog::LogF(LOGERROR, "No epg tag!");
return false;
}
CGUIDialogPVRGuideInfo* pDlgInfo =
CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogPVRGuideInfo>(
WINDOW_DIALOG_PVR_GUIDE_INFO);
if (!pDlgInfo)
{
CLog::LogF(LOGERROR, "Unable to get WINDOW_DIALOG_PVR_GUIDE_INFO!");
return false;
}
pDlgInfo->SetProgInfo(std::make_shared<CFileItem>(epgTag));
pDlgInfo->Open();
return true;
}
bool CPVRGUIActionsEPG::ShowChannelEPG(const CFileItem& item) const
{
const std::shared_ptr<CPVRChannel> channel(CPVRItem(item).GetChannel());
if (channel && CServiceBroker::GetPVRManager().Get<PVR::GUI::Parental>().CheckParentalLock(
channel) != ParentalCheckResult::SUCCESS)
return false;
CGUIDialogPVRChannelGuide* pDlgInfo =
CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogPVRChannelGuide>(
WINDOW_DIALOG_PVR_CHANNEL_GUIDE);
if (!pDlgInfo)
{
CLog::LogF(LOGERROR, "Unable to get WINDOW_DIALOG_PVR_CHANNEL_GUIDE!");
return false;
}
pDlgInfo->Open(channel);
return true;
}
bool CPVRGUIActionsEPG::FindSimilar(const CFileItem& item) const
{
CGUIWindowPVRSearchBase* windowSearch = GetSearchWindow(CPVRItem(item).IsRadio());
if (!windowSearch)
return false;
//! @todo If we want dialogs to spawn program search in a clean way - without having to force-close any
// other dialogs - we must introduce a search dialog with functionality similar to the search window.
for (int iId = CServiceBroker::GetGUI()->GetWindowManager().GetTopmostModalDialog(
true /* ignoreClosing */);
iId != WINDOW_INVALID;
iId = CServiceBroker::GetGUI()->GetWindowManager().GetTopmostModalDialog(
true /* ignoreClosing */))
{
CLog::LogF(LOGWARNING,
"Have to close modal dialog with id {} before search window can be opened.", iId);
CGUIWindow* window = CServiceBroker::GetGUI()->GetWindowManager().GetWindow(iId);
if (window)
{
window->Close();
}
else
{
CLog::LogF(LOGERROR, "Unable to get window instance {}! Cannot open search window.", iId);
return false; // return, otherwise we run into an endless loop
}
}
windowSearch->SetItemToSearch(item);
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(windowSearch->GetID());
return true;
};
bool CPVRGUIActionsEPG::ExecuteSavedSearch(const CFileItem& item)
{
const auto searchFilter = item.GetEPGSearchFilter();
if (!searchFilter)
{
CLog::LogF(LOGERROR, "Wrong item type. No EPG search filter present.");
return false;
}
CGUIWindowPVRSearchBase* windowSearch = GetSearchWindow(searchFilter->IsRadio());
if (!windowSearch)
return false;
windowSearch->SetItemToSearch(item);
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(windowSearch->GetID());
return true;
}
bool CPVRGUIActionsEPG::EditSavedSearch(const CFileItem& item)
{
const auto searchFilter = item.GetEPGSearchFilter();
if (!searchFilter)
{
CLog::LogF(LOGERROR, "Wrong item type. No EPG search filter present.");
return false;
}
CGUIWindowPVRSearchBase* windowSearch = GetSearchWindow(searchFilter->IsRadio());
if (!windowSearch)
return false;
if (windowSearch->OpenDialogSearch(item) == CGUIDialogPVRGuideSearch::Result::SEARCH)
CServiceBroker::GetGUI()->GetWindowManager().ActivateWindow(windowSearch->GetID());
return true;
}
bool CPVRGUIActionsEPG::RenameSavedSearch(const CFileItem& item)
{
const auto searchFilter = item.GetEPGSearchFilter();
if (!searchFilter)
{
CLog::LogF(LOGERROR, "Wrong item type. No EPG search filter present.");
return false;
}
std::string title = searchFilter->GetTitle();
if (CGUIKeyboardFactory::ShowAndGetInput(title,
CVariant{g_localizeStrings.Get(528)}, // "Enter title"
false))
{
searchFilter->SetTitle(title);
CServiceBroker::GetPVRManager().EpgContainer().PersistSavedSearch(*searchFilter);
return true;
}
return false;
}
bool CPVRGUIActionsEPG::DeleteSavedSearch(const CFileItem& item)
{
const auto searchFilter = item.GetEPGSearchFilter();
if (!searchFilter)
{
CLog::LogF(LOGERROR, "Wrong item type. No EPG search filter present.");
return false;
}
if (CGUIDialogYesNo::ShowAndGetInput(CVariant{122}, // "Confirm delete"
CVariant{19338}, // "Delete this saved search?"
CVariant{""}, CVariant{item.GetLabel()}))
{
return CServiceBroker::GetPVRManager().EpgContainer().DeleteSavedSearch(*searchFilter);
}
return false;
}
|