VTB: release CVBuffer after it actually has been rendered
[xbmc.git] / xbmc / pvr / PVRActionListener.cpp
blobd8e29a1c3a07669b32e0f9e8e215f965b049176d
1 /*
2 * Copyright (C) 2005-2015 Team XBMC
3 * http://xbmc.org
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.
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 "Application.h"
22 #include "dialogs/GUIDialogNumeric.h"
23 #include "guilib/LocalizeStrings.h"
24 #include "guilib/GUIWindowManager.h"
25 #include "input/Key.h"
26 #include "messaging/ApplicationMessenger.h"
27 #include "settings/AdvancedSettings.h"
28 #include "settings/Settings.h"
29 #include "utils/log.h"
30 #include "utils/StringUtils.h"
32 #include "pvr/PVRManager.h"
33 #include "pvr/channels/PVRChannelGroupsContainer.h"
35 #include "PVRActionListener.h"
37 using namespace PVR;
38 using namespace KODI::MESSAGING;
40 CPVRActionListener::CPVRActionListener()
44 CPVRActionListener &CPVRActionListener::GetInstance()
46 static CPVRActionListener instance;
47 return instance;
50 bool CPVRActionListener::OnAction(const CAction &action)
52 switch (action.GetID())
54 case ACTION_PVR_PLAY:
55 case ACTION_PVR_PLAY_TV:
56 case ACTION_PVR_PLAY_RADIO:
58 // see if we're already playing a PVR stream and if not or the stream type
59 // doesn't match the demanded type, start playback of according type
60 bool isPlayingPvr(g_PVRManager.IsPlaying() && g_application.CurrentFileItem().HasPVRChannelInfoTag());
61 switch (action.GetID())
63 case ACTION_PVR_PLAY:
64 if (!isPlayingPvr)
65 g_PVRManager.StartPlayback(PlaybackTypeAny);
66 break;
67 case ACTION_PVR_PLAY_TV:
68 if (!isPlayingPvr || g_application.CurrentFileItem().GetPVRChannelInfoTag()->IsRadio())
69 g_PVRManager.StartPlayback(PlaybackTypeTv);
70 break;
71 case ACTION_PVR_PLAY_RADIO:
72 if (!isPlayingPvr || !g_application.CurrentFileItem().GetPVRChannelInfoTag()->IsRadio())
73 g_PVRManager.StartPlayback(PlaybackTypeRadio);
74 break;
76 return true;
78 case REMOTE_0:
79 case REMOTE_1:
80 case REMOTE_2:
81 case REMOTE_3:
82 case REMOTE_4:
83 case REMOTE_5:
84 case REMOTE_6:
85 case REMOTE_7:
86 case REMOTE_8:
87 case REMOTE_9:
89 if (g_application.CurrentFileItem().IsLiveTV() &&
90 (g_windowManager.IsWindowActive(WINDOW_FULLSCREEN_VIDEO) ||
91 g_windowManager.IsWindowActive(WINDOW_VISUALISATION)))
93 // do not consume action if a python modal is the top most dialog
94 // as a python modal can't return that it consumed the action.
95 if (g_windowManager.IsPythonWindow(g_windowManager.GetTopMostModalDialogID()))
96 return false;
98 if(g_PVRManager.IsPlaying())
100 // pvr client addon
101 CPVRChannelPtr playingChannel(g_PVRManager.GetCurrentChannel());
102 if(!playingChannel)
103 return false;
105 if (action.GetID() == REMOTE_0)
107 CPVRChannelGroupPtr group = g_PVRChannelGroups->GetPreviousPlayedGroup();
108 if (group)
110 g_PVRManager.SetPlayingGroup(group);
111 CFileItemPtr fileItem = group->GetLastPlayedChannel(playingChannel->ChannelID());
112 if (fileItem && fileItem->HasPVRChannelInfoTag())
114 CLog::Log(LOGDEBUG, "%s - switch to channel number %d", __FUNCTION__, fileItem->GetPVRChannelInfoTag()->ChannelNumber());
115 CApplicationMessenger::GetInstance().SendMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1,static_cast<void*>(
116 new CAction(ACTION_CHANNEL_SWITCH, static_cast<float>(fileItem->GetPVRChannelInfoTag()->ChannelNumber()))));
120 else
122 int autoCloseTime = CSettings::GetInstance().GetBool(CSettings::SETTING_PVRPLAYBACK_CONFIRMCHANNELSWITCH) ? 0 : g_advancedSettings.m_iPVRNumericChannelSwitchTimeout;
123 std::string strChannel = StringUtils::Format("%i", action.GetID() - REMOTE_0);
124 if (CGUIDialogNumeric::ShowAndGetNumber(strChannel, g_localizeStrings.Get(19000), autoCloseTime) || autoCloseTime)
126 int iChannelNumber = atoi(strChannel.c_str());
127 if (iChannelNumber > 0 && iChannelNumber != playingChannel->ChannelNumber())
129 CPVRChannelGroupPtr selectedGroup = g_PVRManager.GetPlayingGroup(playingChannel->IsRadio());
130 CFileItemPtr channel = selectedGroup->GetByChannelNumber(iChannelNumber);
131 if (!channel || !channel->HasPVRChannelInfoTag())
132 return false;
134 CApplicationMessenger::GetInstance().PostMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1, static_cast<void*>(
135 new CAction(ACTION_CHANNEL_SWITCH, static_cast<float>(iChannelNumber))));
141 return true;
143 break;
145 return false;