2 * Copyright (C) 2012 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 "GUIDialogPVRChannelsOSD.h"
22 #include "Application.h"
23 #include "ApplicationMessenger.h"
25 #include "guilib/GUIWindowManager.h"
26 #include "dialogs/GUIDialogOK.h"
27 #include "GUIDialogPVRGuideInfo.h"
28 #include "ViewState.h"
29 #include "settings/GUISettings.h"
30 #include "GUIInfoManager.h"
32 #include "pvr/PVRManager.h"
33 #include "pvr/channels/PVRChannelGroupsContainer.h"
35 #include "pvr/timers/PVRTimerInfoTag.h"
36 #include "pvr/channels/PVRChannelGroupsContainer.h"
42 #define CONTROL_LIST 11
44 CGUIDialogPVRChannelsOSD::CGUIDialogPVRChannelsOSD() :
45 CGUIDialog(WINDOW_DIALOG_PVR_OSD_CHANNELS, "DialogPVRChannelsOSD.xml"),
48 m_vecItems = new CFileItemList;
51 CGUIDialogPVRChannelsOSD::~CGUIDialogPVRChannelsOSD()
55 if (IsObserving(g_infoManager))
56 g_infoManager.UnregisterObserver(this);
59 bool CGUIDialogPVRChannelsOSD::OnMessage(CGUIMessage& message)
61 switch (message.GetMessage())
63 case GUI_MSG_WINDOW_DEINIT:
65 g_PVRManager.SetPlayingGroup(m_group);
70 case GUI_MSG_WINDOW_INIT:
72 /* Close dialog immediately if now TV or radio channel is playing */
73 if (!g_PVRManager.IsPlaying())
79 m_group = GetPlayingGroup();
81 CGUIWindow::OnMessage(message);
90 int iControl = message.GetSenderId();
92 if (m_viewControl.HasControl(iControl)) // list/thumb control
94 int iItem = m_viewControl.GetSelectedItem();
95 int iAction = message.GetParam1();
97 if (iAction == ACTION_SELECT_ITEM || iAction == ACTION_MOUSE_LEFT_CLICK)
99 /* Switch to channel */
103 else if (iAction == ACTION_SHOW_INFO || iAction == ACTION_MOUSE_RIGHT_CLICK)
105 /* Show information Dialog */
115 int iAction = message.GetParam1();
117 if (iAction == ACTION_MOVE_RIGHT || iAction == ACTION_MOVE_LEFT)
119 CPVRChannelGroupPtr group = GetPlayingGroup();
120 CPVRChannelGroupPtr nextGroup = iAction == ACTION_MOVE_RIGHT ? group->GetNextGroup() : group->GetPreviousGroup();
121 g_PVRManager.SetPlayingGroup(nextGroup);
132 return CGUIDialog::OnMessage(message);
135 CPVRChannelGroupPtr CGUIDialogPVRChannelsOSD::GetPlayingGroup()
137 CPVRChannelPtr channel;
138 g_PVRManager.GetCurrentChannel(channel);
139 return g_PVRManager.GetPlayingGroup(channel->IsRadio());
142 void CGUIDialogPVRChannelsOSD::Update()
144 CGUIDialogPVRChannelsOSD::Update(false);
147 void CGUIDialogPVRChannelsOSD::Update(bool selectPlayingChannel)
149 // lock our display, as this window is rendered from the player thread
150 g_graphicsContext.Lock();
152 if (!IsObserving(g_infoManager))
153 g_infoManager.RegisterObserver(this);
155 m_viewControl.SetCurrentView(DEFAULT_VIEW_LIST);
157 // empty the list ready for population
160 CPVRChannelPtr channel;
161 g_PVRManager.GetCurrentChannel(channel);
162 CPVRChannelGroupPtr group = g_PVRManager.GetPlayingGroup(channel->IsRadio());
166 group->GetMembers(*m_vecItems);
167 m_viewControl.SetItems(*m_vecItems);
168 m_viewControl.SetSelectedItem(selectPlayingChannel ? group->GetIndex(*channel) : 0);
171 g_graphicsContext.Unlock();
174 void CGUIDialogPVRChannelsOSD::Clear()
176 m_viewControl.Clear();
180 void CGUIDialogPVRChannelsOSD::CloseOrSelect(unsigned int iItem)
182 if (g_guiSettings.GetBool("pvrmenu.closechannelosdonswitch"))
185 m_viewControl.SetSelectedItem(iItem);
188 void CGUIDialogPVRChannelsOSD::GotoChannel(int item)
190 /* Check file item is in list range and get his pointer */
191 if (item < 0 || item >= (int)m_vecItems->Size()) return;
192 CFileItemPtr pItem = m_vecItems->Get(item);
194 if (pItem->GetPath() == g_application.CurrentFile())
200 if (g_PVRManager.IsPlaying() && pItem->HasPVRChannelInfoTag() && g_application.m_pPlayer)
202 CPVRChannel *channel = pItem->GetPVRChannelInfoTag();
203 if (!g_PVRManager.CheckParentalLock(*channel) ||
204 !g_application.m_pPlayer->SwitchChannel(*channel))
211 CApplicationMessenger::Get().PlayFile(*pItem);
213 m_group = GetPlayingGroup();
218 void CGUIDialogPVRChannelsOSD::ShowInfo(int item)
220 /* Check file item is in list range and get his pointer */
221 if (item < 0 || item >= (int)m_vecItems->Size()) return;
223 CFileItemPtr pItem = m_vecItems->Get(item);
224 if (pItem && pItem->IsPVRChannel())
226 CPVRChannel *channel = pItem->GetPVRChannelInfoTag();
227 if (!g_PVRManager.CheckParentalLock(*channel))
230 /* Get the current running show on this channel from the EPG storage */
232 if (!channel->GetEPGNow(epgnow))
234 CFileItem *itemNow = new CFileItem(epgnow);
236 /* Load programme info dialog */
237 CGUIDialogPVRGuideInfo* pDlgInfo = (CGUIDialogPVRGuideInfo*)g_windowManager.GetWindow(WINDOW_DIALOG_PVR_GUIDE_INFO);
241 /* inform dialog about the file item and open dialog window */
242 pDlgInfo->SetProgInfo(itemNow);
244 delete itemNow; /* delete previuosly created FileItem */
250 void CGUIDialogPVRChannelsOSD::OnWindowLoaded()
252 CGUIDialog::OnWindowLoaded();
253 m_viewControl.Reset();
254 m_viewControl.SetParentWindow(GetID());
255 m_viewControl.AddView(GetControl(CONTROL_LIST));
258 void CGUIDialogPVRChannelsOSD::OnWindowUnload()
260 CGUIDialog::OnWindowUnload();
261 m_viewControl.Reset();
264 CGUIControl *CGUIDialogPVRChannelsOSD::GetFirstFocusableControl(int id)
266 if (m_viewControl.HasControl(id))
267 id = m_viewControl.GetCurrentControl();
269 return CGUIWindow::GetFirstFocusableControl(id);
272 void CGUIDialogPVRChannelsOSD::Notify(const Observable &obs, const ObservableMessage msg)
274 if (msg == ObservableMessageCurrentItem)
276 g_graphicsContext.Lock();
277 m_viewControl.SetItems(*m_vecItems);
278 g_graphicsContext.Unlock();