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
|
/*
* Copyright (C) 2012-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 "GUIWindowPVRSearch.h"
#include "ServiceBroker.h"
#include "dialogs/GUIDialogBusy.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "guilib/LocalizeStrings.h"
#include "input/Key.h"
#include "messaging/helpers/DialogOKHelper.h"
#include "threads/IRunnable.h"
#include "utils/URIUtils.h"
#include "utils/Variant.h"
#include "pvr/PVRGUIActions.h"
#include "pvr/PVRItem.h"
#include "pvr/PVRManager.h"
#include "pvr/addons/PVRClients.h"
#include "pvr/dialogs/GUIDialogPVRGuideSearch.h"
#include "pvr/epg/EpgContainer.h"
#include "pvr/epg/EpgSearchFilter.h"
using namespace PVR;
using namespace KODI::MESSAGING;
namespace
{
class AsyncSearchAction : private IRunnable
{
public:
AsyncSearchAction() = delete;
AsyncSearchAction(CFileItemList* items, CPVREpgSearchFilter* filter) : m_items(items), m_filter(filter) {}
bool Execute();
private:
// IRunnable implementation
void Run() override;
CFileItemList* m_items;
CPVREpgSearchFilter* m_filter;
};
bool AsyncSearchAction::Execute()
{
CGUIDialogBusy::Wait(this, 100, false);
return true;
}
void AsyncSearchAction::Run()
{
CServiceBroker::GetPVRManager().EpgContainer().GetEPGSearch(*m_items, *m_filter);
}
} // unnamed namespace
CGUIWindowPVRSearchBase::CGUIWindowPVRSearchBase(bool bRadio, int id, const std::string &xmlFile) :
CGUIWindowPVRBase(bRadio, id, xmlFile),
m_bSearchConfirmed(false)
{
}
void CGUIWindowPVRSearchBase::GetContextButtons(int itemNumber, CContextButtons &buttons)
{
if (itemNumber < 0 || itemNumber >= m_vecItems->Size())
return;
buttons.Add(CONTEXT_BUTTON_CLEAR, 19232); /* Clear search results */
CGUIWindowPVRBase::GetContextButtons(itemNumber, buttons);
}
bool CGUIWindowPVRSearchBase::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) ||
CGUIMediaWindow::OnContextButton(itemNumber, button);
}
void CGUIWindowPVRSearchBase::SetItemToSearch(const CFileItemPtr &item)
{
m_searchfilter.reset(new CPVREpgSearchFilter(m_bRadio));
if (item->IsUsablePVRRecording())
{
m_searchfilter->SetSearchPhrase(item->GetPVRRecordingInfoTag()->m_strTitle);
}
else
{
const CPVREpgInfoTagPtr epgTag(CPVRItem(item).GetEpgInfoTag());
if (epgTag)
m_searchfilter->SetSearchPhrase(epgTag->Title());
}
m_bSearchConfirmed = true;
if (IsActive())
Refresh(true);
}
void CGUIWindowPVRSearchBase::OnPrepareFileItems(CFileItemList &items)
{
bool bAddSpecialSearchItem = items.IsEmpty();
if (m_bSearchConfirmed)
{
bAddSpecialSearchItem = true;
items.Clear();
AsyncSearchAction(&items, m_searchfilter.get()).Execute();
if (items.IsEmpty())
HELPERS::ShowOKDialogText(CVariant{284}, // "No results found"
m_searchfilter->GetSearchTerm());
}
if (bAddSpecialSearchItem)
{
CFileItemPtr item(new CFileItem("pvr://guide/searchresults/search/", false));
item->SetLabel(g_localizeStrings.Get(19140)); // "Search..."
item->SetLabelPreformatted(true);
item->SetSpecialSort(SortSpecialOnTop);
item->SetIconImage("DefaultTVShows.png");
items.Add(item);
}
}
bool CGUIWindowPVRSearchBase::OnMessage(CGUIMessage &message)
{
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
CServiceBroker::GetPVRManager().GUIActions()->ShowEPGInfo(pItem);
return true;
}
case ACTION_CONTEXT_MENU:
case ACTION_MOUSE_RIGHT_CLICK:
OnPopupMenu(iItem);
return true;
case ACTION_RECORD:
CServiceBroker::GetPVRManager().GUIActions()->ToggleTimer(pItem);
return true;
}
}
}
}
return CGUIWindowPVRBase::OnMessage(message);
}
bool CGUIWindowPVRSearchBase::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;
}
void CGUIWindowPVRSearchBase::OpenDialogSearch()
{
CGUIDialogPVRGuideSearch* dlgSearch = CServiceBroker::GetGUI()->GetWindowManager().GetWindow<CGUIDialogPVRGuideSearch>(WINDOW_DIALOG_PVR_GUIDE_SEARCH);
if (!dlgSearch)
return;
if (!m_searchfilter)
m_searchfilter.reset(new CPVREpgSearchFilter(m_bRadio));
dlgSearch->SetFilterData(m_searchfilter.get());
/* Open dialog window */
dlgSearch->Open();
if (dlgSearch->IsConfirmed())
{
m_bSearchConfirmed = true;
Refresh(true);
}
}
|