PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/xbmc/pvr/windows/GUIWindowPVRChannels.cpp

https://github.com/koying/xbmc
C++ | 412 lines | 326 code | 60 blank | 26 comment | 53 complexity | 74dcbd1a3bdedc87bc27b45dedf42d8d MD5 | raw file
  1. /*
  2. * Copyright (C) 2012-2013 Team XBMC
  3. * http://xbmc.org
  4. *
  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)
  8. * any later version.
  9. *
  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.
  14. *
  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/>.
  18. *
  19. */
  20. #include "ContextMenuManager.h"
  21. #include "GUIInfoManager.h"
  22. #include "cores/AudioEngine/Engines/ActiveAE/AudioDSPAddons/ActiveAEDSP.h"
  23. #include "epg/EpgContainer.h"
  24. #include "dialogs/GUIDialogKaiToast.h"
  25. #include "dialogs/GUIDialogOK.h"
  26. #include "dialogs/GUIDialogYesNo.h"
  27. #include "guilib/GUIKeyboardFactory.h"
  28. #include "guilib/GUIRadioButtonControl.h"
  29. #include "guilib/GUIWindowManager.h"
  30. #include "input/Key.h"
  31. #include "threads/SingleLock.h"
  32. #include "utils/StringUtils.h"
  33. #include "utils/Variant.h"
  34. #include "pvr/PVRManager.h"
  35. #include "pvr/addons/PVRClients.h"
  36. #include "pvr/channels/PVRChannelGroupsContainer.h"
  37. #include "pvr/dialogs/GUIDialogPVRChannelManager.h"
  38. #include "pvr/dialogs/GUIDialogPVRGroupManager.h"
  39. #include "pvr/timers/PVRTimers.h"
  40. #include "GUIWindowPVRChannels.h"
  41. using namespace PVR;
  42. using namespace EPG;
  43. CGUIWindowPVRChannels::CGUIWindowPVRChannels(bool bRadio) :
  44. CGUIWindowPVRBase(bRadio, bRadio ? WINDOW_RADIO_CHANNELS : WINDOW_TV_CHANNELS, "MyPVRChannels.xml"),
  45. m_bShowHiddenChannels(false)
  46. {
  47. g_EpgContainer.RegisterObserver(this);
  48. g_infoManager.RegisterObserver(this);
  49. }
  50. CGUIWindowPVRChannels::~CGUIWindowPVRChannels()
  51. {
  52. g_infoManager.UnregisterObserver(this);
  53. g_EpgContainer.UnregisterObserver(this);
  54. }
  55. void CGUIWindowPVRChannels::GetContextButtons(int itemNumber, CContextButtons &buttons)
  56. {
  57. if (itemNumber < 0 || itemNumber >= m_vecItems->Size())
  58. return;
  59. CFileItemPtr pItem = m_vecItems->Get(itemNumber);
  60. CPVRChannelPtr channel(pItem->GetPVRChannelInfoTag());
  61. if (channel->GetEPGNow())
  62. {
  63. buttons.Add(CONTEXT_BUTTON_INFO, 19047); /* Programme information */
  64. buttons.Add(CONTEXT_BUTTON_FIND, 19003); /* Find similar */
  65. }
  66. if (channel->IsRecording())
  67. buttons.Add(CONTEXT_BUTTON_STOP_RECORD, 19059); /* Stop recording */
  68. else if (g_PVRClients->SupportsTimers(channel->ClientID()))
  69. buttons.Add(CONTEXT_BUTTON_START_RECORD, 264); /* Record */
  70. if (CServiceBroker::GetADSP().IsProcessing())
  71. buttons.Add(CONTEXT_BUTTON_ACTIVE_ADSP_SETTINGS, 15047); /* Audio DSP settings */
  72. if (g_PVRClients->HasMenuHooks(channel->ClientID(), PVR_MENUHOOK_CHANNEL))
  73. buttons.Add(CONTEXT_BUTTON_MENU_HOOKS, 19195); /* PVR client specific action */
  74. // Add parent buttons before the Manage button
  75. CGUIWindowPVRBase::GetContextButtons(itemNumber, buttons);
  76. buttons.Add(CONTEXT_BUTTON_EDIT, 16106); /* Manage... */
  77. }
  78. std::string CGUIWindowPVRChannels::GetDirectoryPath(void)
  79. {
  80. return StringUtils::Format("pvr://channels/%s/%s/",
  81. m_bRadio ? "radio" : "tv",
  82. m_bShowHiddenChannels ? ".hidden" : GetChannelGroup()->GroupName().c_str());
  83. }
  84. bool CGUIWindowPVRChannels::OnContextButton(int itemNumber, CONTEXT_BUTTON button)
  85. {
  86. if (itemNumber < 0 || itemNumber >= m_vecItems->Size())
  87. return false;
  88. CFileItemPtr pItem = m_vecItems->Get(itemNumber);
  89. return OnContextButtonAdd(pItem.get(), button) ||
  90. OnContextButtonInfo(pItem.get(), button) ||
  91. OnContextButtonGroupManager(pItem.get(), button) ||
  92. OnContextButtonUpdateEpg(pItem.get(), button) ||
  93. OnContextButtonStartRecord(pItem.get(), button) ||
  94. OnContextButtonStopRecord(pItem.get(), button) ||
  95. OnContextButtonManage(pItem.get(), button) ||
  96. OnContextButtonActiveAEDSPSettings(pItem.get(), button) ||
  97. CGUIWindowPVRBase::OnContextButton(itemNumber, button);
  98. }
  99. bool CGUIWindowPVRChannels::Update(const std::string &strDirectory, bool updateFilterPath /* = true */)
  100. {
  101. bool bReturn = CGUIWindowPVRBase::Update(strDirectory);
  102. if (bReturn)
  103. {
  104. CSingleLock lock(m_critSection);
  105. /* empty list for hidden channels */
  106. if (m_vecItems->GetObjectCount() == 0 && m_bShowHiddenChannels)
  107. {
  108. /* show the visible channels instead */
  109. m_bShowHiddenChannels = false;
  110. lock.Leave();
  111. Update(GetDirectoryPath());
  112. }
  113. }
  114. return bReturn;
  115. }
  116. void CGUIWindowPVRChannels::UpdateButtons(void)
  117. {
  118. CGUIRadioButtonControl *btnShowHidden = (CGUIRadioButtonControl*) GetControl(CONTROL_BTNSHOWHIDDEN);
  119. if (btnShowHidden)
  120. {
  121. btnShowHidden->SetVisible(g_PVRChannelGroups->GetGroupAll(m_bRadio)->GetNumHiddenChannels() > 0);
  122. btnShowHidden->SetSelected(m_bShowHiddenChannels);
  123. }
  124. CGUIWindowPVRBase::UpdateButtons();
  125. SET_CONTROL_LABEL(CONTROL_LABEL_HEADER1, m_bShowHiddenChannels ? g_localizeStrings.Get(19022) : GetChannelGroup()->GroupName());
  126. }
  127. bool CGUIWindowPVRChannels::OnAction(const CAction &action)
  128. {
  129. switch (action.GetID())
  130. {
  131. case REMOTE_0:
  132. case REMOTE_1:
  133. case REMOTE_2:
  134. case REMOTE_3:
  135. case REMOTE_4:
  136. case REMOTE_5:
  137. case REMOTE_6:
  138. case REMOTE_7:
  139. case REMOTE_8:
  140. case REMOTE_9:
  141. return ActionInputChannelNumber(action.GetID() - REMOTE_0);
  142. }
  143. return CGUIWindowPVRBase::OnAction(action);
  144. }
  145. bool CGUIWindowPVRChannels::OnMessage(CGUIMessage& message)
  146. {
  147. bool bReturn = false;
  148. switch (message.GetMessage())
  149. {
  150. case GUI_MSG_CLICKED:
  151. if (message.GetSenderId() == m_viewControl.GetCurrentControl())
  152. {
  153. int iItem = m_viewControl.GetSelectedItem();
  154. if (iItem >= 0 && iItem < m_vecItems->Size())
  155. {
  156. bReturn = true;
  157. switch (message.GetParam1())
  158. {
  159. case ACTION_SELECT_ITEM:
  160. case ACTION_MOUSE_LEFT_CLICK:
  161. case ACTION_PLAY:
  162. ActionPlayChannel(m_vecItems->Get(iItem).get());
  163. break;
  164. case ACTION_SHOW_INFO:
  165. ShowEPGInfo(m_vecItems->Get(iItem).get());
  166. break;
  167. case ACTION_DELETE_ITEM:
  168. ActionDeleteChannel(m_vecItems->Get(iItem).get());
  169. break;
  170. case ACTION_CONTEXT_MENU:
  171. case ACTION_MOUSE_RIGHT_CLICK:
  172. OnPopupMenu(iItem);
  173. break;
  174. default:
  175. bReturn = false;
  176. break;
  177. }
  178. }
  179. }
  180. else if (message.GetSenderId() == CONTROL_BTNSHOWHIDDEN)
  181. {
  182. CGUIRadioButtonControl *radioButton = (CGUIRadioButtonControl*)GetControl(CONTROL_BTNSHOWHIDDEN);
  183. if (radioButton)
  184. {
  185. m_bShowHiddenChannels = radioButton->IsSelected();
  186. Update(GetDirectoryPath());
  187. }
  188. bReturn = true;
  189. }
  190. else if (message.GetSenderId() == CONTROL_BTNFILTERCHANNELS)
  191. {
  192. std::string filter = GetProperty("filter").asString();
  193. CGUIKeyboardFactory::ShowAndGetFilter(filter, false);
  194. OnFilterItems(filter);
  195. UpdateButtons();
  196. bReturn = true;
  197. }
  198. break;
  199. case GUI_MSG_REFRESH_LIST:
  200. switch(message.GetParam1())
  201. {
  202. case ObservableMessageChannelGroup:
  203. case ObservableMessageTimers:
  204. case ObservableMessageEpg:
  205. case ObservableMessageEpgContainer:
  206. case ObservableMessageEpgActiveItem:
  207. case ObservableMessageCurrentItem:
  208. case ObservableMessageRecordings:
  209. {
  210. SetInvalid();
  211. break;
  212. }
  213. case ObservableMessageChannelGroupReset:
  214. {
  215. Refresh(true);
  216. break;
  217. }
  218. }
  219. break;
  220. }
  221. return bReturn || CGUIWindowPVRBase::OnMessage(message);
  222. }
  223. bool CGUIWindowPVRChannels::OnContextButtonAdd(CFileItem *item, CONTEXT_BUTTON button)
  224. {
  225. bool bReturn = false;
  226. if (button == CONTEXT_BUTTON_ADD)
  227. {
  228. CGUIDialogOK::ShowAndGetInput(CVariant{19033}, CVariant{19038});
  229. bReturn = true;
  230. }
  231. return bReturn;
  232. }
  233. bool CGUIWindowPVRChannels::OnContextButtonGroupManager(CFileItem *item, CONTEXT_BUTTON button)
  234. {
  235. bool bReturn = false;
  236. if (button == CONTEXT_BUTTON_GROUP_MANAGER)
  237. {
  238. ShowGroupManager();
  239. bReturn = true;
  240. }
  241. return bReturn;
  242. }
  243. bool CGUIWindowPVRChannels::OnContextButtonInfo(CFileItem *item, CONTEXT_BUTTON button)
  244. {
  245. bool bReturn = false;
  246. if (button == CONTEXT_BUTTON_INFO)
  247. {
  248. ShowEPGInfo(item);
  249. bReturn = true;
  250. }
  251. return bReturn;
  252. }
  253. bool CGUIWindowPVRChannels::OnContextButtonManage(CFileItem *item, CONTEXT_BUTTON button)
  254. {
  255. bool bReturn = false;
  256. if (button == CONTEXT_BUTTON_EDIT)
  257. {
  258. // Create context sub menu
  259. CContextButtons buttons;
  260. buttons.Add(CONTEXT_BUTTON_GROUP_MANAGER, 19048);
  261. buttons.Add(CONTEXT_BUTTON_CHANNEL_MANAGER, 19199);
  262. buttons.Add(CONTEXT_BUTTON_UPDATE_EPG, 19251);
  263. // Get the response
  264. int button = CGUIDialogContextMenu::ShowAndGetChoice(buttons);
  265. if (button >= 0)
  266. {
  267. switch ((CONTEXT_BUTTON)button)
  268. {
  269. case CONTEXT_BUTTON_GROUP_MANAGER:
  270. ShowGroupManager();
  271. break;
  272. case CONTEXT_BUTTON_CHANNEL_MANAGER:
  273. ShowChannelManager();
  274. break;
  275. case CONTEXT_BUTTON_UPDATE_EPG:
  276. OnContextButtonUpdateEpg(item, (CONTEXT_BUTTON)button);
  277. break;
  278. default:
  279. break;
  280. }
  281. // Refresh the list in case anything was changed
  282. Refresh(true);
  283. }
  284. bReturn = true;
  285. }
  286. return bReturn;
  287. }
  288. bool CGUIWindowPVRChannels::OnContextButtonStartRecord(CFileItem *item, CONTEXT_BUTTON button)
  289. {
  290. bool bReturn = false;
  291. if (button == CONTEXT_BUTTON_START_RECORD)
  292. {
  293. AddTimer(item);
  294. bReturn = true;
  295. }
  296. else if (button == CONTEXT_BUTTON_ADD_TIMER)
  297. {
  298. AddTimerRule(item);
  299. bReturn = true;
  300. }
  301. return bReturn;
  302. }
  303. bool CGUIWindowPVRChannels::OnContextButtonStopRecord(CFileItem *item, CONTEXT_BUTTON button)
  304. {
  305. bool bReturn = false;
  306. if (button == CONTEXT_BUTTON_STOP_RECORD)
  307. {
  308. StopRecordFile(item);
  309. bReturn = true;
  310. }
  311. return bReturn;
  312. }
  313. bool CGUIWindowPVRChannels::OnContextButtonUpdateEpg(CFileItem *item, CONTEXT_BUTTON button)
  314. {
  315. bool bReturn = false;
  316. if (button == CONTEXT_BUTTON_UPDATE_EPG)
  317. {
  318. CGUIDialogYesNo* pDialog = (CGUIDialogYesNo*)g_windowManager.GetWindow(WINDOW_DIALOG_YES_NO);
  319. if (!pDialog)
  320. return bReturn;
  321. CPVRChannelPtr channel(item->GetPVRChannelInfoTag());
  322. pDialog->SetHeading(CVariant{19251});
  323. pDialog->SetLine(0, CVariant{g_localizeStrings.Get(19252)});
  324. pDialog->SetLine(1, CVariant{channel->ChannelName()});
  325. pDialog->SetLine(2, CVariant{""});
  326. pDialog->Open();
  327. if (!pDialog->IsConfirmed())
  328. return bReturn;
  329. bReturn = UpdateEpgForChannel(item);
  330. std::string strMessage = StringUtils::Format("%s: '%s'", g_localizeStrings.Get(bReturn ? 19253 : 19254).c_str(), channel->ChannelName().c_str());
  331. CGUIDialogKaiToast::QueueNotification(bReturn ? CGUIDialogKaiToast::Info : CGUIDialogKaiToast::Error,
  332. g_localizeStrings.Get(19166),
  333. strMessage);
  334. }
  335. return bReturn;
  336. }
  337. void CGUIWindowPVRChannels::ShowChannelManager()
  338. {
  339. CGUIDialogPVRChannelManager *dialog = (CGUIDialogPVRChannelManager *)g_windowManager.GetWindow(WINDOW_DIALOG_PVR_CHANNEL_MANAGER);
  340. if (dialog)
  341. dialog->Open();
  342. }
  343. void CGUIWindowPVRChannels::ShowGroupManager(void)
  344. {
  345. /* Load group manager dialog */
  346. CGUIDialogPVRGroupManager* pDlgInfo = (CGUIDialogPVRGroupManager*)g_windowManager.GetWindow(WINDOW_DIALOG_PVR_GROUP_MANAGER);
  347. if (!pDlgInfo)
  348. return;
  349. pDlgInfo->SetRadio(m_bRadio);
  350. pDlgInfo->Open();
  351. return;
  352. }