2 * Copyright (C) 2012-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "GUIWindowPVRSearch.h"
23 #include "dialogs/GUIDialogOK.h"
24 #include "dialogs/GUIDialogProgress.h"
25 #include "guilib/GUIWindowManager.h"
26 #include "pvr/PVRManager.h"
27 #include "pvr/channels/PVRChannelGroupsContainer.h"
28 #include "pvr/dialogs/GUIDialogPVRGuideSearch.h"
29 #include "epg/EpgContainer.h"
30 #include "pvr/recordings/PVRRecordings.h"
31 #include "GUIWindowPVR.h"
32 #include "utils/log.h"
33 #include "pvr/addons/PVRClients.h"
38 CGUIWindowPVRSearch::CGUIWindowPVRSearch(CGUIWindowPVR *parent) :
39 CGUIWindowPVRCommon(parent, PVR_WINDOW_SEARCH, CONTROL_BTNSEARCH, CONTROL_LIST_SEARCH),
40 m_bSearchStarted(false),
41 m_bSearchConfirmed(false)
45 void CGUIWindowPVRSearch::GetContextButtons(int itemNumber, CContextButtons &buttons) const
47 if (itemNumber < 0 || itemNumber >= m_parent->m_vecItems->Size())
49 CFileItemPtr pItem = m_parent->m_vecItems->Get(itemNumber);
51 if (pItem->GetLabel() != g_localizeStrings.Get(19027))
53 if (pItem->GetEPGInfoTag()->EndAsLocalTime() > CDateTime::GetCurrentDateTime())
55 if (!pItem->GetEPGInfoTag()->HasTimer())
57 if (pItem->GetEPGInfoTag()->StartAsLocalTime() < CDateTime::GetCurrentDateTime())
58 buttons.Add(CONTEXT_BUTTON_START_RECORD, 264); /* RECORD programme */
60 buttons.Add(CONTEXT_BUTTON_START_RECORD, 19061); /* Create a Timer */
64 if (pItem->GetEPGInfoTag()->StartAsLocalTime() < CDateTime::GetCurrentDateTime())
65 buttons.Add(CONTEXT_BUTTON_STOP_RECORD, 19059); /* Stop recording */
67 buttons.Add(CONTEXT_BUTTON_STOP_RECORD, 19060); /* Delete Timer */
71 buttons.Add(CONTEXT_BUTTON_INFO, 19047); /* Epg info button */
72 buttons.Add(CONTEXT_BUTTON_SORTBY_CHANNEL, 19062); /* Sort by channel */
73 buttons.Add(CONTEXT_BUTTON_SORTBY_NAME, 103); /* Sort by Name */
74 buttons.Add(CONTEXT_BUTTON_SORTBY_DATE, 104); /* Sort by Date */
75 buttons.Add(CONTEXT_BUTTON_CLEAR, 19232); /* Clear search results */
76 if (pItem->GetEPGInfoTag()->HasPVRChannel() &&
77 g_PVRClients->HasMenuHooks(pItem->GetEPGInfoTag()->ChannelTag()->ClientID(), PVR_MENUHOOK_EPG))
78 buttons.Add(CONTEXT_BUTTON_MENU_HOOKS, 19195); /* PVR client specific action */
82 bool CGUIWindowPVRSearch::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
84 if (itemNumber < 0 || itemNumber >= m_parent->m_vecItems->Size())
86 CFileItemPtr pItem = m_parent->m_vecItems->Get(itemNumber);
88 return OnContextButtonClear(pItem.get(), button) ||
89 OnContextButtonInfo(pItem.get(), button) ||
90 OnContextButtonStopRecord(pItem.get(), button) ||
91 OnContextButtonStartRecord(pItem.get(), button) ||
92 CGUIWindowPVRCommon::OnContextButton(itemNumber, button);
95 void CGUIWindowPVRSearch::UpdateData(bool bUpdateSelectedFile /* = true */)
97 CLog::Log(LOGDEBUG, "CGUIWindowPVRSearch - %s - update window '%s'. set view to %d", __FUNCTION__, GetName(), m_iControlList);
98 m_bUpdateRequired = false;
100 /* lock the graphics context while updating */
101 CSingleLock graphicsLock(g_graphicsContext);
103 m_iSelected = m_parent->m_viewControl.GetSelectedItem();
104 m_parent->m_viewControl.Clear();
105 m_parent->m_vecItems->Clear();
106 m_parent->m_viewControl.SetCurrentView(m_iControlList);
108 if (m_bSearchConfirmed)
110 CGUIDialogProgress* dlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);
113 dlgProgress->SetHeading(194);
114 dlgProgress->SetLine(0, m_searchfilter.m_strSearchTerm);
115 dlgProgress->SetLine(1, "");
116 dlgProgress->SetLine(2, "");
117 dlgProgress->StartModal();
118 dlgProgress->Progress();
121 // TODO get this from the selected channel group
122 g_EpgContainer.GetEPGSearch(*m_parent->m_vecItems, m_searchfilter);
124 dlgProgress->Close();
126 if (m_parent->m_vecItems->Size() == 0)
128 CGUIDialogOK::ShowAndGetInput(194, 284, 0, 0);
129 m_bSearchConfirmed = false;
133 if (m_parent->m_vecItems->Size() == 0)
136 item.reset(new CFileItem("pvr://guide/searchresults/empty.epg", false));
137 item->SetLabel(g_localizeStrings.Get(19027));
138 item->SetLabelPreformated(true);
139 m_parent->m_vecItems->Add(item);
143 m_parent->m_vecItems->Sort(m_iSortMethod, m_iSortOrder);
146 m_parent->m_viewControl.SetItems(*m_parent->m_vecItems);
148 if (bUpdateSelectedFile)
149 m_parent->m_viewControl.SetSelectedItem(m_iSelected);
151 m_parent->SetLabel(CONTROL_LABELHEADER, g_localizeStrings.Get(283));
152 m_parent->SetLabel(CONTROL_LABELGROUP, "");
155 bool CGUIWindowPVRSearch::OnClickButton(CGUIMessage &message)
157 bool bReturn = false;
159 if (IsSelectedButton(message))
168 bool CGUIWindowPVRSearch::OnClickList(CGUIMessage &message)
170 bool bReturn = false;
172 if (IsSelectedList(message))
175 int iAction = message.GetParam1();
176 int iItem = m_parent->m_viewControl.GetSelectedItem();
178 /* get the fileitem pointer */
179 if (iItem < 0 || iItem >= m_parent->m_vecItems->Size())
181 CFileItemPtr pItem = m_parent->m_vecItems->Get(iItem);
183 /* process actions */
184 if (iAction == ACTION_SHOW_INFO || iAction == ACTION_SELECT_ITEM || iAction == ACTION_MOUSE_LEFT_CLICK)
185 ActionShowSearch(pItem.get());
186 else if (iAction == ACTION_CONTEXT_MENU || iAction == ACTION_MOUSE_RIGHT_CLICK)
187 m_parent->OnPopupMenu(iItem);
188 else if (iAction == ACTION_RECORD)
189 ActionRecord(pItem.get());
195 bool CGUIWindowPVRSearch::OnContextButtonClear(CFileItem *item, CONTEXT_BUTTON button)
197 bool bReturn = false;
199 if (button == CONTEXT_BUTTON_CLEAR)
203 m_bSearchStarted = false;
204 m_bSearchConfirmed = false;
205 m_searchfilter.Reset();
213 bool CGUIWindowPVRSearch::OnContextButtonInfo(CFileItem *item, CONTEXT_BUTTON button)
215 bool bReturn = false;
217 if (button == CONTEXT_BUTTON_INFO)
227 bool CGUIWindowPVRSearch::OnContextButtonStartRecord(CFileItem *item, CONTEXT_BUTTON button)
229 bool bReturn = false;
231 if (button == CONTEXT_BUTTON_START_RECORD)
235 StartRecordFile(item);
241 bool CGUIWindowPVRSearch::OnContextButtonStopRecord(CFileItem *item, CONTEXT_BUTTON button)
243 bool bReturn = false;
245 if (button == CONTEXT_BUTTON_STOP_RECORD)
249 StopRecordFile(item);
255 bool CGUIWindowPVRSearch::ActionShowSearch(CFileItem *item)
257 if (item->GetPath() == "pvr://guide/searchresults/empty.epg")
265 void CGUIWindowPVRSearch::ShowSearchResults()
267 /* Load timer settings dialog */
268 CGUIDialogPVRGuideSearch* pDlgInfo = (CGUIDialogPVRGuideSearch*)g_windowManager.GetWindow(WINDOW_DIALOG_PVR_GUIDE_SEARCH);
273 if (!m_bSearchStarted)
275 m_bSearchStarted = true;
276 m_searchfilter.Reset();
279 pDlgInfo->SetFilterData(&m_searchfilter);
281 /* Open dialog window */
284 if (pDlgInfo->IsConfirmed())
286 m_bSearchConfirmed = true;