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 "GUIDialogPVRGuideInfo.h"
22 #include "Application.h"
23 #include "guilib/GUIWindowManager.h"
24 #include "dialogs/GUIDialogOK.h"
25 #include "dialogs/GUIDialogYesNo.h"
27 #include "pvr/PVRManager.h"
28 #include "pvr/channels/PVRChannelGroupsContainer.h"
29 #include "epg/EpgInfoTag.h"
30 #include "pvr/timers/PVRTimers.h"
31 #include "pvr/timers/PVRTimerInfoTag.h"
37 #define CONTROL_BTN_SWITCH 5
38 #define CONTROL_BTN_RECORD 6
39 #define CONTROL_BTN_OK 7
41 CGUIDialogPVRGuideInfo::CGUIDialogPVRGuideInfo(void)
42 : CGUIDialog(WINDOW_DIALOG_PVR_GUIDE_INFO, "DialogPVRGuideInfo.xml")
43 , m_progItem(new CFileItem)
47 CGUIDialogPVRGuideInfo::~CGUIDialogPVRGuideInfo(void)
51 bool CGUIDialogPVRGuideInfo::ActionStartTimer(const CEpgInfoTag *tag)
58 CPVRChannelPtr channel = tag->ChannelTag();
59 if (!channel || !g_PVRManager.CheckParentalLock(*channel))
62 // prompt user for confirmation of channel record
63 CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
67 pDialog->SetHeading(264);
68 pDialog->SetLine(0, "");
69 pDialog->SetLine(1, tag->Title());
70 pDialog->SetLine(2, "");
73 if (pDialog->IsConfirmed())
76 CPVRTimerInfoTag *newTimer = CPVRTimerInfoTag::CreateFromEpg(*tag);
79 bReturn = CPVRTimers::AddTimer(*newTimer);
92 bool CGUIDialogPVRGuideInfo::ActionCancelTimer(CFileItemPtr timer)
95 if (!timer || !timer->HasPVRTimerInfoTag())
100 // prompt user for confirmation of timer deletion
101 CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
105 pDialog->SetHeading(265);
106 pDialog->SetLine(0, "");
107 pDialog->SetLine(1, timer->GetPVRTimerInfoTag()->m_strTitle);
108 pDialog->SetLine(2, "");
111 if (pDialog->IsConfirmed())
114 bReturn = CPVRTimers::DeleteTimer(*timer);
121 bool CGUIDialogPVRGuideInfo::OnClickButtonOK(CGUIMessage &message)
123 bool bReturn = false;
125 if (message.GetSenderId() == CONTROL_BTN_OK)
134 bool CGUIDialogPVRGuideInfo::OnClickButtonRecord(CGUIMessage &message)
136 bool bReturn = false;
138 if (message.GetSenderId() == CONTROL_BTN_RECORD)
142 const CEpgInfoTag *tag = m_progItem->GetEPGInfoTag();
143 if (!tag || !tag->HasPVRChannel())
145 /* invalid channel */
146 CGUIDialogOK::ShowAndGetInput(19033,19067,0,0);
151 CFileItemPtr timerTag = g_PVRTimers->GetTimerForEpgTag(m_progItem.get());
152 bool bHasTimer = timerTag != NULL && timerTag->HasPVRTimerInfoTag();
155 ActionStartTimer(tag);
157 ActionCancelTimer(timerTag);
163 bool CGUIDialogPVRGuideInfo::OnClickButtonSwitch(CGUIMessage &message)
165 bool bReturn = false;
167 if (message.GetSenderId() == CONTROL_BTN_SWITCH)
171 if (!m_progItem->GetEPGInfoTag()->HasPVRChannel() ||
172 !g_application.PlayFile(CFileItem(*m_progItem->GetEPGInfoTag()->ChannelTag())))
173 CGUIDialogOK::ShowAndGetInput(19033,0,19035,0);
181 bool CGUIDialogPVRGuideInfo::OnMessage(CGUIMessage& message)
183 switch (message.GetMessage())
185 case GUI_MSG_WINDOW_INIT:
186 CGUIDialog::OnMessage(message);
189 case GUI_MSG_CLICKED:
190 return OnClickButtonOK(message) ||
191 OnClickButtonRecord(message) ||
192 OnClickButtonSwitch(message);
195 return CGUIDialog::OnMessage(message);
198 void CGUIDialogPVRGuideInfo::SetProgInfo(const CFileItem *item)
203 CFileItemPtr CGUIDialogPVRGuideInfo::GetCurrentListItem(int offset)
208 void CGUIDialogPVRGuideInfo::Update()
210 const CEpgInfoTag *tag = m_progItem->GetEPGInfoTag();
213 /* no epg event selected */
217 if (tag->EndAsLocalTime() <= CDateTime::GetCurrentDateTime())
219 /* event has passed. hide the record button */
220 SET_CONTROL_HIDDEN(CONTROL_BTN_RECORD);
224 CFileItemPtr match = g_PVRTimers->GetTimerForEpgTag(m_progItem.get());
225 if (!match || !match->HasPVRTimerInfoTag())
227 /* no timer present on this tag */
228 if (tag->StartAsLocalTime() < CDateTime::GetCurrentDateTime())
229 SET_CONTROL_LABEL(CONTROL_BTN_RECORD, 264);
231 SET_CONTROL_LABEL(CONTROL_BTN_RECORD, 19061);
235 /* timer present on this tag */
236 if (tag->StartAsLocalTime() < CDateTime::GetCurrentDateTime())
237 SET_CONTROL_LABEL(CONTROL_BTN_RECORD, 19059);
239 SET_CONTROL_LABEL(CONTROL_BTN_RECORD, 19060);