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 "GUIWindowPVR.h"
23 #include "GUIWindowPVRChannels.h"
24 #include "GUIWindowPVRGuide.h"
25 #include "GUIWindowPVRRecordings.h"
26 #include "GUIWindowPVRSearch.h"
27 #include "GUIWindowPVRTimers.h"
29 #include "pvr/PVRManager.h"
30 #include "pvr/addons/PVRClients.h"
31 #include "guilib/GUIMessage.h"
32 #include "guilib/GUIWindowManager.h"
33 #include "dialogs/GUIDialogBusy.h"
34 #include "dialogs/GUIDialogKaiToast.h"
35 #include "threads/SingleLock.h"
39 #define CHANNELS_REFRESH_INTERVAL 5000
41 CGUIWindowPVR::CGUIWindowPVR(void) :
42 CGUIMediaWindow(WINDOW_PVR, "MyPVR.xml"),
44 m_currentSubwindow(NULL),
45 m_savedSubwindow(NULL),
46 m_windowChannelsTV(NULL),
47 m_windowChannelsRadio(NULL),
49 m_windowRecordings(NULL),
54 m_loadType = LOAD_EVERY_TIME;
57 CGUIWindowPVR::~CGUIWindowPVR(void)
62 CGUIWindowPVRCommon *CGUIWindowPVR::GetActiveView(void) const
64 CSingleLock lock(m_critSection);
65 return m_currentSubwindow;
68 void CGUIWindowPVR::SetActiveView(CGUIWindowPVRCommon *window)
70 CSingleLock lock(m_critSection);
72 if ((!window && m_currentSubwindow) || (window && !m_currentSubwindow) ||
73 (window && m_currentSubwindow && window->GetWindowId() != m_currentSubwindow->GetWindowId()))
75 // switched views, save current history
76 if (m_currentSubwindow)
78 m_currentSubwindow->m_history = m_history;
79 m_currentSubwindow->m_iSelected = m_viewControl.GetSelectedItem();
82 if (window == m_windowChannelsRadio || window == m_windowChannelsTV)
83 m_refreshWatch.StartZero();
87 m_history = window->m_history;
89 m_history.ClearPathHistory();
91 m_currentSubwindow = window;
94 bool CGUIWindowPVR::Update(const CStdString &strDirectory, bool updateFilterPath)
96 CGUIWindowPVRCommon *view = GetActiveView();
99 view->BeforeUpdate(strDirectory);
101 if(!CGUIMediaWindow::Update(strDirectory))
105 view->AfterUpdate(*m_unfilteredItems);
110 void CGUIWindowPVR::GetContextButtons(int itemNumber, CContextButtons &buttons)
112 CGUIWindowPVRCommon *view = GetActiveView();
114 view->GetContextButtons(itemNumber, buttons);
116 CGUIMediaWindow::GetContextButtons(itemNumber, buttons);
119 CGUIWindowPVRCommon *CGUIWindowPVR::GetSavedView(void) const
121 CSingleLock lock(m_critSection);
122 return m_savedSubwindow;
125 bool CGUIWindowPVR::OnAction(const CAction &action)
127 CGUIWindowPVRCommon *view = GetActiveView();
128 return (view && view->OnAction(action)) ||
129 CGUIMediaWindow::OnAction(action);
132 bool CGUIWindowPVR::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
134 CGUIWindowPVRCommon *view = GetActiveView();
135 return (view && view->OnContextButton(itemNumber, button)) ||
136 CGUIMediaWindow::OnContextButton(itemNumber, button);
139 void CGUIWindowPVR::OnInitWindow(void)
141 if (!g_PVRManager.IsStarted() || !g_PVRClients->HasConnectedClients())
143 g_windowManager.PreviousWindow();
144 CGUIDialogKaiToast::QueueNotification(CGUIDialogKaiToast::Warning,
145 g_localizeStrings.Get(19045),
146 g_localizeStrings.Get(19044));
152 CSingleLock graphicsLock(g_graphicsContext);
153 SET_CONTROL_VISIBLE(CONTROL_LIST_TIMELINE);
155 CSingleLock lock(m_critSection);
156 if (m_savedSubwindow)
157 m_savedSubwindow->OnInitWindow();
159 bool bReset(m_bWasReset);
162 graphicsLock.Leave();
164 CGUIMediaWindow::OnInitWindow();
168 CGUIMessage msg(GUI_MSG_FOCUSED, GetID(), CONTROL_BTNCHANNELS_TV, 0, 0);
173 bool CGUIWindowPVR::OnMessage(CGUIMessage& message)
175 return (OnMessageFocus(message) ||OnMessageClick(message) ||
176 CGUIMediaWindow::OnMessage(message));
179 void CGUIWindowPVR::OnWindowLoaded(void)
183 CGUIMediaWindow::OnWindowLoaded();
184 m_viewControl.Reset();
185 m_viewControl.SetParentWindow(GetID());
187 m_viewControl.AddView(GetControl(CONTROL_LIST_CHANNELS_TV));
188 m_viewControl.AddView(GetControl(CONTROL_LIST_CHANNELS_RADIO));
189 m_viewControl.AddView(GetControl(CONTROL_LIST_RECORDINGS));
190 m_viewControl.AddView(GetControl(CONTROL_LIST_TIMERS));
191 m_viewControl.AddView(GetControl(CONTROL_LIST_GUIDE_CHANNEL));
192 m_viewControl.AddView(GetControl(CONTROL_LIST_GUIDE_NOW_NEXT));
193 m_viewControl.AddView(GetControl(CONTROL_LIST_TIMELINE));
194 m_viewControl.AddView(GetControl(CONTROL_LIST_SEARCH));
197 void CGUIWindowPVR::OnWindowUnload(void)
199 CGUIWindowPVRCommon *view = GetActiveView();
202 view->OnWindowUnload();
203 m_savedSubwindow = view;
207 m_savedSubwindow = NULL;
210 m_currentSubwindow = NULL;
212 m_viewControl.Reset();
213 CGUIMediaWindow::OnWindowUnload();
216 void CGUIWindowPVR::SetLabel(int iControl, const CStdString &strLabel)
218 SET_CONTROL_LABEL(iControl, strLabel);
221 void CGUIWindowPVR::SetLabel(int iControl, int iLabel)
223 SET_CONTROL_LABEL(iControl, iLabel);
226 void CGUIWindowPVR::UpdateButtons(void)
228 m_windowGuide->UpdateButtons();
231 bool CGUIWindowPVR::OnMessageFocus(CGUIMessage &message)
233 bool bReturn = false;
235 if (message.GetMessage() == GUI_MSG_FOCUSED)
237 m_windowChannelsRadio->OnMessageFocus(message) ||
238 m_windowChannelsTV->OnMessageFocus(message) ||
239 m_windowGuide->OnMessageFocus(message) ||
240 m_windowRecordings->OnMessageFocus(message) ||
241 m_windowSearch->OnMessageFocus(message) ||
242 m_windowTimers->OnMessageFocus(message);
244 m_savedSubwindow = NULL;
250 bool CGUIWindowPVR::OnMessageClick(CGUIMessage &message)
252 bool bReturn = false;
254 if (message.GetMessage() == GUI_MSG_CLICKED)
256 bReturn = m_windowChannelsRadio->OnClickButton(message) ||
257 m_windowChannelsTV->OnClickButton(message) ||
258 m_windowGuide->OnClickButton(message) ||
259 m_windowRecordings->OnClickButton(message) ||
260 m_windowSearch->OnClickButton(message) ||
261 m_windowTimers->OnClickButton(message) ||
263 m_windowChannelsRadio->OnClickList(message) ||
264 m_windowChannelsTV->OnClickList(message) ||
265 m_windowGuide->OnClickList(message) ||
266 m_windowRecordings->OnClickList(message) ||
267 m_windowSearch->OnClickList(message) ||
268 m_windowTimers->OnClickList(message);
274 void CGUIWindowPVR::CreateViews(void)
276 CSingleLock lock(m_critSection);
277 if (!m_windowChannelsRadio)
278 m_windowChannelsRadio = new CGUIWindowPVRChannels(this, true);
280 if (!m_windowChannelsTV)
281 m_windowChannelsTV = new CGUIWindowPVRChannels(this, false);
284 m_windowGuide = new CGUIWindowPVRGuide(this);
286 if (!m_windowRecordings)
287 m_windowRecordings = new CGUIWindowPVRRecordings(this);
290 m_windowSearch = new CGUIWindowPVRSearch(this);
293 m_windowTimers = new CGUIWindowPVRTimers(this);
296 void CGUIWindowPVR::Reset(void)
298 CSingleLock graphicsLock(g_graphicsContext);
299 CSingleLock lock(m_critSection);
304 m_windowChannelsRadio->ResetObservers();
305 m_windowChannelsTV->ResetObservers();
306 m_windowGuide->ResetObservers();
307 m_windowRecordings->ResetObservers();
308 m_windowTimers->ResetObservers();
313 void CGUIWindowPVR::Cleanup(void)
315 if (m_windowChannelsRadio)
316 m_windowChannelsRadio->UnregisterObservers();
317 SAFE_DELETE(m_windowChannelsRadio);
319 if (m_windowChannelsTV)
320 m_windowChannelsTV->UnregisterObservers();
321 SAFE_DELETE(m_windowChannelsTV);
324 m_windowGuide->UnregisterObservers();
325 SAFE_DELETE(m_windowGuide);
327 if (m_windowRecordings)
328 m_windowRecordings->UnregisterObservers();
329 SAFE_DELETE(m_windowRecordings);
331 SAFE_DELETE(m_windowSearch);
334 m_windowTimers->UnregisterObservers();
335 SAFE_DELETE(m_windowTimers);
337 m_currentSubwindow = NULL;
338 m_savedSubwindow = NULL;
344 void CGUIWindowPVR::FrameMove()
346 CGUIWindowPVRCommon* view = GetActiveView();
347 if (view == m_windowChannelsRadio || view == m_windowChannelsTV)
349 if (m_refreshWatch.GetElapsedMilliseconds() > CHANNELS_REFRESH_INTERVAL)
352 m_refreshWatch.Reset();
355 CGUIMediaWindow::FrameMove();