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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
/*
* Copyright (C) 2012-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "ContextMenuManager.h"
#include "dialogs/GUIDialogOK.h"
#include "dialogs/GUIDialogProgress.h"
#include "epg/EpgContainer.h"
#include "guilib/GUIWindowManager.h"
#include "input/Key.h"
#include "utils/Variant.h"
#include "pvr/PVRManager.h"
#include "pvr/addons/PVRClients.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
#include "pvr/dialogs/GUIDialogPVRGuideSearch.h"
#include "GUIWindowPVRSearch.h"
using namespace PVR;
using namespace EPG;
CGUIWindowPVRSearch::CGUIWindowPVRSearch(bool bRadio) :
CGUIWindowPVRBase(bRadio, bRadio ? WINDOW_RADIO_SEARCH : WINDOW_TV_SEARCH, "MyPVRSearch.xml"),
m_bSearchConfirmed(false)
{
}
void CGUIWindowPVRSearch::GetContextButtons(int itemNumber, CContextButtons &buttons)
{
if (itemNumber < 0 || itemNumber >= m_vecItems->Size())
return;
CFileItemPtr pItem = m_vecItems->Get(itemNumber);
buttons.Add(CONTEXT_BUTTON_CLEAR, 19232); /* Clear search results */
CEpgInfoTagPtr epg(pItem->GetEPGInfoTag());
if (epg)
{
buttons.Add(CONTEXT_BUTTON_INFO, 19047); /* Programme information */
CPVRTimerInfoTagPtr timer(epg->Timer());
if (timer)
{
if (timer->IsRecording())
buttons.Add(CONTEXT_BUTTON_STOP_RECORD, 19059); /* Stop recording */
else
{
CPVRTimerTypePtr timerType(timer->GetTimerType());
if (timerType && !timerType->IsReadOnly())
buttons.Add(CONTEXT_BUTTON_DELETE_TIMER, 19060); /* Delete timer */
}
}
else if (g_PVRClients->SupportsTimers() && epg->EndAsLocalTime() > CDateTime::GetCurrentDateTime())
{
buttons.Add(CONTEXT_BUTTON_START_RECORD, 264); /* Record */
buttons.Add(CONTEXT_BUTTON_ADD_TIMER, 19061); /* Add timer */
}
if (epg->HasRecording())
buttons.Add(CONTEXT_BUTTON_PLAY_ITEM, 19687); /* Play recording */
CPVRChannelPtr channel(epg->ChannelTag());
if (channel &&
g_PVRClients->HasMenuHooks(channel->ClientID(), PVR_MENUHOOK_EPG))
buttons.Add(CONTEXT_BUTTON_MENU_HOOKS, 19195); /* PVR client specific action */
}
CGUIWindowPVRBase::GetContextButtons(itemNumber, buttons);
CContextMenuManager::GetInstance().AddVisibleItems(pItem, buttons);
}
void CGUIWindowPVRSearch::OnWindowLoaded()
{
CGUIMediaWindow::OnWindowLoaded();
m_searchfilter.Reset();
}
bool CGUIWindowPVRSearch::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
{
if (itemNumber < 0 || itemNumber >= m_vecItems->Size())
return false;
CFileItemPtr pItem = m_vecItems->Get(itemNumber);
return OnContextButtonClear(pItem.get(), button) ||
OnContextButtonInfo(pItem.get(), button) ||
OnContextButtonStartRecord(pItem.get(), button) ||
OnContextButtonStopRecord(pItem.get(), button) ||
OnContextButtonDeleteTimer(pItem.get(), button) ||
OnContextButtonPlay(pItem.get(), button) ||
CGUIWindowPVRBase::OnContextButton(itemNumber, button);
}
bool CGUIWindowPVRSearch::OnContextButton(const CFileItem &item, CONTEXT_BUTTON button)
{
bool bReturn = false;
switch(button)
{
case CONTEXT_BUTTON_FIND:
{
m_searchfilter.Reset();
// construct the search term
if (item.IsEPG())
m_searchfilter.m_strSearchTerm = "\"" + item.GetEPGInfoTag()->Title() + "\"";
else if (item.IsPVRChannel())
{
const CEpgInfoTagPtr tag(item.GetPVRChannelInfoTag()->GetEPGNow());
if (tag)
m_searchfilter.m_strSearchTerm = "\"" + tag->Title() + "\"";
}
else if (item.IsUsablePVRRecording())
m_searchfilter.m_strSearchTerm = "\"" + item.GetPVRRecordingInfoTag()->m_strTitle + "\"";
else if (item.IsPVRTimer())
{
const CPVRTimerInfoTagPtr info(item.GetPVRTimerInfoTag());
const CEpgInfoTagPtr tag(info->GetEpgInfoTag());
if (tag)
m_searchfilter.m_strSearchTerm = "\"" + tag->Title() + "\"";
else
m_searchfilter.m_strSearchTerm = "\"" + info->m_strTitle + "\"";
}
m_bSearchConfirmed = true;
Refresh(true);
bReturn = true;
break;
}
default:
bReturn = false;
}
return bReturn;
}
void CGUIWindowPVRSearch::OnPrepareFileItems(CFileItemList &items)
{
bool bAddSpecialSearchItem = items.IsEmpty();
if (m_bSearchConfirmed)
{
m_bSearchConfirmed = false;
bAddSpecialSearchItem = true;
CGUIDialogProgress* dlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
if (dlgProgress)
{
dlgProgress->SetHeading(CVariant{194}); // "Searching..."
dlgProgress->SetText(CVariant{m_searchfilter.m_strSearchTerm});
dlgProgress->Open();
dlgProgress->Progress();
}
// TODO should we limit the find similar search to the selected group?
g_EpgContainer.GetEPGSearch(items, m_searchfilter);
if (dlgProgress)
dlgProgress->Close();
if (items.IsEmpty())
CGUIDialogOK::ShowAndGetInput(CVariant{194}, // "Searching..."
CVariant{284}); // "No results found"
}
if (bAddSpecialSearchItem)
{
CFileItemPtr item(new CFileItem("pvr://guide/searchresults/search/", true));
item->SetLabel(g_localizeStrings.Get(19140)); // "Search..."
item->SetLabelPreformated(true);
item->SetSpecialSort(SortSpecialOnTop);
items.Add(item);
}
}
bool CGUIWindowPVRSearch::OnMessage(CGUIMessage &message)
{
if (!IsValidMessage(message))
return false;
if (message.GetMessage() == GUI_MSG_CLICKED)
{
if (message.GetSenderId() == m_viewControl.GetCurrentControl())
{
int iItem = m_viewControl.GetSelectedItem();
if (iItem >= 0 && iItem < m_vecItems->Size())
{
CFileItemPtr pItem = m_vecItems->Get(iItem);
/* process actions */
switch (message.GetParam1())
{
case ACTION_SHOW_INFO:
case ACTION_SELECT_ITEM:
case ACTION_MOUSE_LEFT_CLICK:
{
if (URIUtils::PathEquals(pItem->GetPath(), "pvr://guide/searchresults/search/"))
OpenDialogSearch();
else
ShowEPGInfo(pItem.get());
return true;
}
case ACTION_CONTEXT_MENU:
case ACTION_MOUSE_RIGHT_CLICK:
OnPopupMenu(iItem);
return true;
case ACTION_RECORD:
ActionToggleTimer(pItem.get());
return true;
}
}
}
}
return CGUIWindowPVRBase::OnMessage(message);
}
bool CGUIWindowPVRSearch::OnContextButtonClear(CFileItem *item, CONTEXT_BUTTON button)
{
bool bReturn = false;
if (button == CONTEXT_BUTTON_CLEAR)
{
bReturn = true;
m_bSearchConfirmed = false;
m_searchfilter.Reset();
Refresh(true);
}
return bReturn;
}
bool CGUIWindowPVRSearch::OnContextButtonInfo(CFileItem *item, CONTEXT_BUTTON button)
{
bool bReturn = false;
if (button == CONTEXT_BUTTON_INFO)
{
bReturn = true;
ShowEPGInfo(item);
}
return bReturn;
}
bool CGUIWindowPVRSearch::OnContextButtonPlay(CFileItem *item, CONTEXT_BUTTON button)
{
bool bReturn = false;
if (button == CONTEXT_BUTTON_PLAY_ITEM)
{
ActionPlayEpg(item, true /* play recording, not channel */);
bReturn = true;
}
return bReturn;
}
bool CGUIWindowPVRSearch::OnContextButtonStartRecord(CFileItem *item, CONTEXT_BUTTON button)
{
bool bReturn = false;
if ((button == CONTEXT_BUTTON_START_RECORD) ||
(button == CONTEXT_BUTTON_ADD_TIMER))
{
AddTimer(item, button == CONTEXT_BUTTON_ADD_TIMER);
bReturn = true;
}
return bReturn;
}
bool CGUIWindowPVRSearch::OnContextButtonStopRecord(CFileItem *item, CONTEXT_BUTTON button)
{
bool bReturn = false;
if (button == CONTEXT_BUTTON_STOP_RECORD)
{
StopRecordFile(item);
bReturn = true;
}
return bReturn;
}
bool CGUIWindowPVRSearch::OnContextButtonDeleteTimer(CFileItem *item, CONTEXT_BUTTON button)
{
bool bReturn = false;
if (button == CONTEXT_BUTTON_DELETE_TIMER)
{
DeleteTimer(item);
bReturn = true;
}
return bReturn;
}
void CGUIWindowPVRSearch::OpenDialogSearch()
{
CGUIDialogPVRGuideSearch* dlgSearch = (CGUIDialogPVRGuideSearch*)g_windowManager.GetWindow(WINDOW_DIALOG_PVR_GUIDE_SEARCH);
if (!dlgSearch)
return;
dlgSearch->SetFilterData(&m_searchfilter);
/* Set channel type filter */
m_searchfilter.m_bIsRadio = m_bRadio;
/* Open dialog window */
dlgSearch->Open();
if (dlgSearch->IsConfirmed())
{
m_bSearchConfirmed = true;
Refresh(true);
}
}
|