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 "GUIDialogPVRGroupManager.h"
23 #include "guilib/GUIKeyboardFactory.h"
24 #include "dialogs/GUIDialogOK.h"
25 #include "dialogs/GUIDialogYesNo.h"
26 #include "guilib/GUIWindowManager.h"
27 #include "guilib/Key.h"
28 #include "guilib/LocalizeStrings.h"
30 #include "pvr/PVRManager.h"
31 #include "pvr/channels/PVRChannelGroupsContainer.h"
36 #define CONTROL_LIST_CHANNELS_LEFT 11
37 #define CONTROL_LIST_CHANNELS_RIGHT 12
38 #define CONTROL_LIST_CHANNEL_GROUPS 13
39 #define CONTROL_CURRENT_GROUP_LABEL 20
40 #define CONTROL_UNGROUPED_LABEL 21
41 #define CONTROL_IN_GROUP_LABEL 22
42 #define BUTTON_NEWGROUP 26
43 #define BUTTON_RENAMEGROUP 27
44 #define BUTTON_DELGROUP 28
47 CGUIDialogPVRGroupManager::CGUIDialogPVRGroupManager() :
48 CGUIDialog(WINDOW_DIALOG_PVR_GROUP_MANAGER, "DialogPVRGroupManager.xml")
50 m_ungroupedChannels = new CFileItemList;
51 m_groupMembers = new CFileItemList;
52 m_channelGroups = new CFileItemList;
55 CGUIDialogPVRGroupManager::~CGUIDialogPVRGroupManager()
57 delete m_ungroupedChannels;
58 delete m_groupMembers;
59 delete m_channelGroups;
62 bool CGUIDialogPVRGroupManager::PersistChanges(void)
64 return g_PVRChannelGroups->Get(m_bIsRadio)->PersistAll();
67 bool CGUIDialogPVRGroupManager::CancelChanges(void)
73 bool CGUIDialogPVRGroupManager::ActionButtonOk(CGUIMessage &message)
76 unsigned int iControl = message.GetSenderId();
78 if (iControl == BUTTON_OK)
88 bool CGUIDialogPVRGroupManager::ActionButtonNewGroup(CGUIMessage &message)
91 unsigned int iControl = message.GetSenderId();
93 if (iControl == BUTTON_NEWGROUP)
95 CStdString strGroupName = "";
96 /* prompt for a group name */
97 if (CGUIKeyboardFactory::ShowAndGetInput(strGroupName, g_localizeStrings.Get(19139), false))
99 if (strGroupName != "")
101 /* add the group if it doesn't already exist */
102 CPVRChannelGroups *groups = ((CPVRChannelGroups *) g_PVRChannelGroups->Get(m_bIsRadio));
103 if (groups->AddGroup(strGroupName))
105 g_PVRChannelGroups->Get(m_bIsRadio)->GetByName(strGroupName)->SetGroupType(PVR_GROUP_TYPE_USER_DEFINED);
106 m_iSelectedChannelGroup = groups->Size() - 1;
117 bool CGUIDialogPVRGroupManager::ActionButtonDeleteGroup(CGUIMessage &message)
119 bool bReturn = false;
120 unsigned int iControl = message.GetSenderId();
122 if (iControl == BUTTON_DELGROUP)
124 if (!m_selectedGroup)
127 CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
131 pDialog->SetHeading(117);
132 pDialog->SetLine(0, "");
133 pDialog->SetLine(1, m_selectedGroup->GroupName());
134 pDialog->SetLine(2, "");
137 if (pDialog->IsConfirmed())
139 if (((CPVRChannelGroups *) g_PVRChannelGroups->Get(m_bIsRadio))->DeleteGroup(*m_selectedGroup))
149 bool CGUIDialogPVRGroupManager::ActionButtonRenameGroup(CGUIMessage &message)
151 bool bReturn = false;
152 unsigned int iControl = message.GetSenderId();
154 if (iControl == BUTTON_RENAMEGROUP)
156 if (!m_selectedGroup)
159 CStdString strGroupName(m_selectedGroup->GroupName());
160 if (CGUIKeyboardFactory::ShowAndGetInput(strGroupName, g_localizeStrings.Get(19139), false))
162 if (strGroupName != "")
164 m_selectedGroup->SetGroupName(strGroupName, true);
175 bool CGUIDialogPVRGroupManager::ActionButtonUngroupedChannels(CGUIMessage &message)
177 bool bReturn = false;
178 unsigned int iControl = message.GetSenderId();
180 if (m_viewUngroupedChannels.HasControl(iControl)) // list/thumb control
182 m_iSelectedUngroupedChannel = m_viewUngroupedChannels.GetSelectedItem();
183 int iAction = message.GetParam1();
185 if (iAction == ACTION_SELECT_ITEM || iAction == ACTION_MOUSE_LEFT_CLICK)
187 if (m_channelGroups->GetFolderCount() == 0)
189 CGUIDialogOK::ShowAndGetInput(19033,19137,0,19138);
191 else if (m_ungroupedChannels->GetFileCount() > 0)
193 CFileItemPtr pItemChannel = m_ungroupedChannels->Get(m_iSelectedUngroupedChannel);
194 if (m_selectedGroup->AddToGroup(*pItemChannel->GetPVRChannelInfoTag()))
204 bool CGUIDialogPVRGroupManager::ActionButtonGroupMembers(CGUIMessage &message)
206 bool bReturn = false;
207 unsigned int iControl = message.GetSenderId();
209 if (m_viewGroupMembers.HasControl(iControl)) // list/thumb control
211 m_iSelectedGroupMember = m_viewGroupMembers.GetSelectedItem();
212 int iAction = message.GetParam1();
214 if (iAction == ACTION_SELECT_ITEM || iAction == ACTION_MOUSE_LEFT_CLICK)
216 if (m_selectedGroup && m_groupMembers->GetFileCount() > 0)
218 CFileItemPtr pItemChannel = m_groupMembers->Get(m_iSelectedGroupMember);
219 m_selectedGroup->RemoveFromGroup(*pItemChannel->GetPVRChannelInfoTag());
229 bool CGUIDialogPVRGroupManager::ActionButtonChannelGroups(CGUIMessage &message)
231 bool bReturn = false;
232 unsigned int iControl = message.GetSenderId();
234 if (m_viewChannelGroups.HasControl(iControl)) // list/thumb control
236 int iAction = message.GetParam1();
238 if (iAction == ACTION_SELECT_ITEM || iAction == ACTION_MOUSE_LEFT_CLICK)
240 m_iSelectedChannelGroup = m_viewChannelGroups.GetSelectedItem();
249 bool CGUIDialogPVRGroupManager::OnMessageClick(CGUIMessage &message)
251 return ActionButtonOk(message) ||
252 ActionButtonNewGroup(message) ||
253 ActionButtonDeleteGroup(message) ||
254 ActionButtonRenameGroup(message) ||
255 ActionButtonUngroupedChannels(message) ||
256 ActionButtonGroupMembers(message) ||
257 ActionButtonChannelGroups(message);
260 bool CGUIDialogPVRGroupManager::OnMessage(CGUIMessage& message)
262 unsigned int iMessage = message.GetMessage();
266 case GUI_MSG_CLICKED:
268 OnMessageClick(message);
273 return CGUIDialog::OnMessage(message);
276 void CGUIDialogPVRGroupManager::OnInitWindow()
278 CGUIDialog::OnInitWindow();
279 m_iSelectedUngroupedChannel = 0;
280 m_iSelectedGroupMember = 0;
281 m_iSelectedChannelGroup = 0;
285 void CGUIDialogPVRGroupManager::OnDeinitWindow(int nextWindowID)
288 CGUIDialog::OnDeinitWindow(nextWindowID);
291 void CGUIDialogPVRGroupManager::OnWindowLoaded()
293 CGUIDialog::OnWindowLoaded();
295 m_viewUngroupedChannels.Reset();
296 m_viewUngroupedChannels.SetParentWindow(GetID());
297 m_viewUngroupedChannels.AddView(GetControl(CONTROL_LIST_CHANNELS_LEFT));
299 m_viewGroupMembers.Reset();
300 m_viewGroupMembers.SetParentWindow(GetID());
301 m_viewGroupMembers.AddView(GetControl(CONTROL_LIST_CHANNELS_RIGHT));
303 m_viewChannelGroups.Reset();
304 m_viewChannelGroups.SetParentWindow(GetID());
305 m_viewChannelGroups.AddView(GetControl(CONTROL_LIST_CHANNEL_GROUPS));
308 void CGUIDialogPVRGroupManager::OnWindowUnload()
310 CGUIDialog::OnWindowUnload();
311 m_viewUngroupedChannels.Reset();
312 m_viewGroupMembers.Reset();
313 m_viewChannelGroups.Reset();
316 void CGUIDialogPVRGroupManager::Update()
318 /* lock our display, as this window is rendered from the player thread */
319 g_graphicsContext.Lock();
320 m_viewUngroupedChannels.SetCurrentView(CONTROL_LIST_CHANNELS_LEFT);
321 m_viewGroupMembers.SetCurrentView(CONTROL_LIST_CHANNELS_RIGHT);
322 m_viewChannelGroups.SetCurrentView(CONTROL_LIST_CHANNEL_GROUPS);
326 /* get the groups list */
327 g_PVRChannelGroups->Get(m_bIsRadio)->GetGroupList(m_channelGroups);
328 m_viewChannelGroups.SetItems(*m_channelGroups);
329 m_viewChannelGroups.SetSelectedItem(m_iSelectedChannelGroup);
331 /* select a group or select the default group if no group was selected */
332 CFileItemPtr pItem = m_channelGroups->Get(m_viewChannelGroups.GetSelectedItem());
333 m_selectedGroup = g_PVRChannelGroups->Get(m_bIsRadio)->GetByName(pItem->m_strTitle);
336 /* set this group in the pvrmanager, so it becomes the selected group in other dialogs too */
337 g_PVRManager.SetPlayingGroup(m_selectedGroup);
338 SET_CONTROL_LABEL(CONTROL_CURRENT_GROUP_LABEL, m_selectedGroup->GroupName());
340 if (m_selectedGroup->IsInternalGroup())
342 CStdString strNewLabel;
343 strNewLabel.Format("%s %s", g_localizeStrings.Get(19022), m_bIsRadio ? g_localizeStrings.Get(19024) : g_localizeStrings.Get(19023));
344 SET_CONTROL_LABEL(CONTROL_UNGROUPED_LABEL, strNewLabel);
346 strNewLabel.Format("%s %s", g_localizeStrings.Get(19218), m_bIsRadio ? g_localizeStrings.Get(19024) : g_localizeStrings.Get(19023));
347 SET_CONTROL_LABEL(CONTROL_IN_GROUP_LABEL, strNewLabel);
351 CStdString strNewLabel;
352 strNewLabel.Format("%s", g_localizeStrings.Get(19219));
353 SET_CONTROL_LABEL(CONTROL_UNGROUPED_LABEL, strNewLabel);
355 strNewLabel.Format("%s %s", g_localizeStrings.Get(19220), m_selectedGroup->GroupName());
356 SET_CONTROL_LABEL(CONTROL_IN_GROUP_LABEL, strNewLabel);
359 /* get all channels that are not in this group for the center part */
360 m_selectedGroup->GetMembers(*m_ungroupedChannels, false);
361 m_viewUngroupedChannels.SetItems(*m_ungroupedChannels);
362 m_viewUngroupedChannels.SetSelectedItem(m_iSelectedUngroupedChannel);
364 /* get all channels in this group for the right side part */
365 m_selectedGroup->GetMembers(*m_groupMembers, true);
366 m_viewGroupMembers.SetItems(*m_groupMembers);
367 m_viewGroupMembers.SetSelectedItem(m_iSelectedGroupMember);
370 g_graphicsContext.Unlock();
373 void CGUIDialogPVRGroupManager::Clear()
375 m_viewUngroupedChannels.Clear();
376 m_viewGroupMembers.Clear();
377 m_viewChannelGroups.Clear();
379 m_ungroupedChannels->Clear();
380 m_groupMembers->Clear();
381 m_channelGroups->Clear();