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 "GUIDialogPVRGuideSearch.h"
22 #include "Application.h"
23 #include "guilib/LocalizeStrings.h"
24 #include "guilib/GUIEditControl.h"
25 #include "guilib/GUIRadioButtonControl.h"
26 #include "guilib/GUISpinControlEx.h"
27 #include "guilib/GUIWindowManager.h"
28 #include "utils/StringUtils.h"
30 #include "addons/include/xbmc_pvr_types.h"
31 #include "pvr/PVRManager.h"
32 #include "epg/EpgSearchFilter.h"
33 #include "pvr/channels/PVRChannelGroupsContainer.h"
38 #define CONTROL_EDIT_SEARCH 9
39 #define CONTROL_BTN_INC_DESC 10
40 #define CONTROL_BTN_CASE_SENS 11
41 #define CONTROL_SPIN_MIN_DURATION 12
42 #define CONTROL_SPIN_MAX_DURATION 13
43 #define CONTROL_EDIT_START_DATE 14
44 #define CONTROL_EDIT_STOP_DATE 15
45 #define CONTROL_EDIT_START_TIME 16
46 #define CONTROL_EDIT_STOP_TIME 17
47 #define CONTROL_SPIN_GENRE 18
48 #define CONTROL_SPIN_NO_REPEATS 19
49 #define CONTROL_BTN_UNK_GENRE 20
50 #define CONTROL_SPIN_GROUPS 21
51 #define CONTROL_BTN_FTA_ONLY 22
52 #define CONTROL_SPIN_CHANNELS 23
53 #define CONTROL_BTN_IGNORE_TMR 24
54 #define CONTROL_BTN_CANCEL 25
55 #define CONTROL_BTN_SEARCH 26
56 #define CONTROL_BTN_IGNORE_REC 27
57 #define CONTROL_BTN_DEFAULTS 28
59 CGUIDialogPVRGuideSearch::CGUIDialogPVRGuideSearch(void) :
60 CGUIDialog(WINDOW_DIALOG_PVR_GUIDE_SEARCH, "DialogPVRGuideSearch.xml"),
67 void CGUIDialogPVRGuideSearch::UpdateChannelSpin(void)
69 CGUISpinControlEx *pSpin = (CGUISpinControlEx *)GetControl(CONTROL_SPIN_CHANNELS);
70 CGUISpinControlEx *pSpinGroups = (CGUISpinControlEx *)GetControl(CONTROL_SPIN_GROUPS);
71 if (!pSpin || !pSpinGroups)
74 int iChannelGroup = pSpin->GetValue();
77 pSpin->AddLabel(g_localizeStrings.Get(19217), EPG_SEARCH_UNSET);
79 int iGroupId = (iChannelGroup == EPG_SEARCH_UNSET) ?
80 XBMC_INTERNAL_GROUP_TV :
82 CPVRChannelGroupPtr group = g_PVRChannelGroups->GetByIdFromAll(iGroupId);
84 group = g_PVRChannelGroups->GetGroupAllTV();
86 for (int iChannelPtr = 0; iChannelPtr < group->Size(); iChannelPtr++)
88 CFileItemPtr channel = group->GetByIndex(iChannelPtr);
89 if (!channel || !channel->HasPVRChannelInfoTag())
92 int iChannelNumber = group->GetChannelNumber(*channel->GetPVRChannelInfoTag());
93 pSpin->AddLabel(channel->GetPVRChannelInfoTag()->ChannelName().c_str(), iChannelNumber);
97 void CGUIDialogPVRGuideSearch::UpdateGroupsSpin(void)
99 CGUISpinControlEx *pSpin = (CGUISpinControlEx *)GetControl(CONTROL_SPIN_GROUPS);
103 std::vector<CPVRChannelGroupPtr> group;
104 std::vector<CPVRChannelGroupPtr>::const_iterator it;
107 group = g_PVRChannelGroups->GetTV()->GetMembers();
108 for (it = group.begin(); it != group.end(); ++it)
109 pSpin->AddLabel((*it)->GroupName(), (*it)->GroupID());
112 group = g_PVRChannelGroups->GetRadio()->GetMembers();
113 for (it = group.begin(); it != group.end(); ++it)
114 pSpin->AddLabel((*it)->GroupName(), (*it)->GroupID());
116 pSpin->SetValue(m_searchFilter->m_iChannelGroup);
119 void CGUIDialogPVRGuideSearch::UpdateGenreSpin(void)
121 CGUISpinControlEx *pSpin = (CGUISpinControlEx *)GetControl(CONTROL_SPIN_GENRE);
126 pSpin->AddLabel(g_localizeStrings.Get(593), EPG_SEARCH_UNSET);
127 pSpin->AddLabel(g_localizeStrings.Get(19500), EPG_EVENT_CONTENTMASK_MOVIEDRAMA);
128 pSpin->AddLabel(g_localizeStrings.Get(19516), EPG_EVENT_CONTENTMASK_NEWSCURRENTAFFAIRS);
129 pSpin->AddLabel(g_localizeStrings.Get(19532), EPG_EVENT_CONTENTMASK_SHOW);
130 pSpin->AddLabel(g_localizeStrings.Get(19548), EPG_EVENT_CONTENTMASK_SPORTS);
131 pSpin->AddLabel(g_localizeStrings.Get(19564), EPG_EVENT_CONTENTMASK_CHILDRENYOUTH);
132 pSpin->AddLabel(g_localizeStrings.Get(19580), EPG_EVENT_CONTENTMASK_MUSICBALLETDANCE);
133 pSpin->AddLabel(g_localizeStrings.Get(19596), EPG_EVENT_CONTENTMASK_ARTSCULTURE);
134 pSpin->AddLabel(g_localizeStrings.Get(19612), EPG_EVENT_CONTENTMASK_SOCIALPOLITICALECONOMICS);
135 pSpin->AddLabel(g_localizeStrings.Get(19628), EPG_EVENT_CONTENTMASK_EDUCATIONALSCIENCE);
136 pSpin->AddLabel(g_localizeStrings.Get(19644), EPG_EVENT_CONTENTMASK_LEISUREHOBBIES);
137 pSpin->AddLabel(g_localizeStrings.Get(19660), EPG_EVENT_CONTENTMASK_SPECIAL);
138 pSpin->AddLabel(g_localizeStrings.Get(19499), EPG_EVENT_CONTENTMASK_USERDEFINED);
139 pSpin->SetValue(m_searchFilter->m_iGenreType);
142 void CGUIDialogPVRGuideSearch::UpdateDurationSpin(void)
144 /* minimum duration */
145 CGUISpinControlEx *pSpin = (CGUISpinControlEx *)GetControl(CONTROL_SPIN_MIN_DURATION);
150 pSpin->AddLabel("-", EPG_SEARCH_UNSET);
151 for (int i = 1; i < 12*60/5; i++)
154 string = StringUtils::Format(g_localizeStrings.Get(14044), i*5);
155 pSpin->AddLabel(string, i*5);
157 pSpin->SetValue(m_searchFilter->m_iMinimumDuration);
159 /* maximum duration */
160 pSpin = (CGUISpinControlEx *)GetControl(CONTROL_SPIN_MAX_DURATION);
165 pSpin->AddLabel("-", EPG_SEARCH_UNSET);
166 for (int i = 1; i < 12*60/5; i++)
169 string = StringUtils::Format(g_localizeStrings.Get(14044), i*5);
170 pSpin->AddLabel(string, i*5);
172 pSpin->SetValue(m_searchFilter->m_iMaximumDuration);
175 bool CGUIDialogPVRGuideSearch::OnMessage(CGUIMessage& message)
177 CGUIDialog::OnMessage(message);
179 switch (message.GetMessage())
181 case GUI_MSG_CLICKED:
183 int iControl = message.GetSenderId();
184 if (iControl == CONTROL_BTN_SEARCH)
192 else if (iControl == CONTROL_BTN_CANCEL)
198 else if (iControl == CONTROL_BTN_DEFAULTS)
202 m_searchFilter->Reset();
208 else if (iControl == CONTROL_SPIN_GROUPS)
220 void CGUIDialogPVRGuideSearch::OnInitWindow()
222 CGUIDialog::OnInitWindow();
224 m_bConfirmed = false;
228 void CGUIDialogPVRGuideSearch::OnWindowLoaded()
231 return CGUIDialog::OnWindowLoaded();
234 void CGUIDialogPVRGuideSearch::ReadDateTime(const CStdString &strDate, const CStdString &strTime, CDateTime &dateTime) const
236 int iHours, iMinutes;
237 sscanf(strTime, "%d:%d", &iHours, &iMinutes);
238 dateTime.SetFromDBDate(strDate);
239 dateTime.SetDateTime(dateTime.GetYear(), dateTime.GetMonth(), dateTime.GetDay(), iHours, iMinutes, 0);
242 void CGUIDialogPVRGuideSearch::OnSearch()
245 CGUISpinControlEx *pSpin;
246 CGUIEditControl *pEdit;
247 CGUIRadioButtonControl *pRadioButton;
252 pEdit = (CGUIEditControl *)GetControl(CONTROL_EDIT_SEARCH);
253 if (pEdit) m_searchFilter->m_strSearchTerm = pEdit->GetLabel2();
255 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_INC_DESC);
256 if (pRadioButton) m_searchFilter->m_bSearchInDescription = pRadioButton->IsSelected();
258 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_CASE_SENS);
259 if (pRadioButton) m_searchFilter->m_bIsCaseSensitive = pRadioButton->IsSelected();
261 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_FTA_ONLY);
262 if (pRadioButton) m_searchFilter->m_bFTAOnly = pRadioButton->IsSelected();
264 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_UNK_GENRE);
265 if (pRadioButton) m_searchFilter->m_bIncludeUnknownGenres = pRadioButton->IsSelected();
267 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_IGNORE_REC);
268 if (pRadioButton) m_searchFilter->m_bIgnorePresentRecordings = pRadioButton->IsSelected();
270 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_IGNORE_TMR);
271 if (pRadioButton) m_searchFilter->m_bIgnorePresentTimers = pRadioButton->IsSelected();
273 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_SPIN_NO_REPEATS);
274 if (pRadioButton) m_searchFilter->m_bPreventRepeats = pRadioButton->IsSelected();
276 pSpin = (CGUISpinControlEx *)GetControl(CONTROL_SPIN_GENRE);
277 if (pSpin) m_searchFilter->m_iGenreType = pSpin->GetValue();
279 pSpin = (CGUISpinControlEx *)GetControl(CONTROL_SPIN_MIN_DURATION);
280 if (pSpin) m_searchFilter->m_iMinimumDuration = pSpin->GetValue();
282 pSpin = (CGUISpinControlEx *)GetControl(CONTROL_SPIN_MAX_DURATION);
283 if (pSpin) m_searchFilter->m_iMaximumDuration = pSpin->GetValue();
285 pSpin = (CGUISpinControlEx *)GetControl(CONTROL_SPIN_CHANNELS);
286 if (pSpin) m_searchFilter->m_iChannelNumber = pSpin->GetValue();
288 pSpin = (CGUISpinControlEx *)GetControl(CONTROL_SPIN_GROUPS);
289 if (pSpin) m_searchFilter->m_iChannelGroup = pSpin->GetValue();
291 pEdit = (CGUIEditControl *)GetControl(CONTROL_EDIT_START_TIME);
292 if (pEdit) strTmp = pEdit->GetLabel2();
294 pEdit = (CGUIEditControl *)GetControl(CONTROL_EDIT_START_DATE);
295 if (pEdit) ReadDateTime(pEdit->GetLabel2(), strTmp, m_searchFilter->m_startDateTime);
298 pEdit = (CGUIEditControl *)GetControl(CONTROL_EDIT_STOP_TIME);
299 if (pEdit) strTmp = pEdit->GetLabel2();
301 pEdit = (CGUIEditControl *)GetControl(CONTROL_EDIT_STOP_DATE);
302 if (pEdit) ReadDateTime(pEdit->GetLabel2(), strTmp, m_searchFilter->m_endDateTime);
305 void CGUIDialogPVRGuideSearch::Update()
307 CGUIEditControl *pEdit;
308 CGUIRadioButtonControl *pRadioButton;
313 pEdit = (CGUIEditControl *)GetControl(CONTROL_EDIT_SEARCH);
316 pEdit->SetLabel2(m_searchFilter->m_strSearchTerm);
317 pEdit->SetInputType(CGUIEditControl::INPUT_TYPE_TEXT, 16017);
320 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_CASE_SENS);
321 if (pRadioButton) pRadioButton->SetSelected(m_searchFilter->m_bIsCaseSensitive);
323 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_INC_DESC);
324 if (pRadioButton) pRadioButton->SetSelected(m_searchFilter->m_bSearchInDescription);
326 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_FTA_ONLY);
327 if (pRadioButton) pRadioButton->SetSelected(m_searchFilter->m_bFTAOnly);
329 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_UNK_GENRE);
330 if (pRadioButton) pRadioButton->SetSelected(m_searchFilter->m_bIncludeUnknownGenres);
332 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_IGNORE_REC);
333 if (pRadioButton) pRadioButton->SetSelected(m_searchFilter->m_bIgnorePresentRecordings);
335 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_BTN_IGNORE_TMR);
336 if (pRadioButton) pRadioButton->SetSelected(m_searchFilter->m_bIgnorePresentTimers);
338 pRadioButton = (CGUIRadioButtonControl *)GetControl(CONTROL_SPIN_NO_REPEATS);
339 if (pRadioButton) pRadioButton->SetSelected(m_searchFilter->m_bPreventRepeats);
341 /* Set time fields */
342 pEdit = (CGUIEditControl *)GetControl(CONTROL_EDIT_START_TIME);
345 pEdit->SetLabel2(m_searchFilter->m_endDateTime.GetAsLocalizedTime("", false));
346 pEdit->SetInputType(CGUIEditControl::INPUT_TYPE_TIME, 14066);
348 pEdit = (CGUIEditControl *)GetControl(CONTROL_EDIT_STOP_TIME);
351 pEdit->SetLabel2(m_searchFilter->m_startDateTime.GetAsLocalizedTime("", false));
352 pEdit->SetInputType(CGUIEditControl::INPUT_TYPE_TIME, 14066);
354 pEdit = (CGUIEditControl *)GetControl(CONTROL_EDIT_START_DATE);
357 pEdit->SetLabel2(m_searchFilter->m_startDateTime.GetAsDBDate());
358 pEdit->SetInputType(CGUIEditControl::INPUT_TYPE_DATE, 14067);
360 pEdit = (CGUIEditControl *)GetControl(CONTROL_EDIT_STOP_DATE);
363 pEdit->SetLabel2(m_searchFilter->m_endDateTime.GetAsDBDate());
364 pEdit->SetInputType(CGUIEditControl::INPUT_TYPE_DATE, 14067);
367 UpdateDurationSpin();