2 * Copyright (C) 2005-2015 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 "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"
38 using namespace KODI::MESSAGING
;
40 CPVRActionListener::CPVRActionListener()
44 CPVRActionListener
&CPVRActionListener::GetInstance()
46 static CPVRActionListener instance
;
50 bool CPVRActionListener::OnAction(const CAction
&action
)
52 switch (action
.GetID())
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())
65 g_PVRManager
.StartPlayback(PlaybackTypeAny
);
67 case ACTION_PVR_PLAY_TV
:
68 if (!isPlayingPvr
|| g_application
.CurrentFileItem().GetPVRChannelInfoTag()->IsRadio())
69 g_PVRManager
.StartPlayback(PlaybackTypeTv
);
71 case ACTION_PVR_PLAY_RADIO
:
72 if (!isPlayingPvr
|| !g_application
.CurrentFileItem().GetPVRChannelInfoTag()->IsRadio())
73 g_PVRManager
.StartPlayback(PlaybackTypeRadio
);
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()))
98 if(g_PVRManager
.IsPlaying())
101 CPVRChannelPtr
playingChannel(g_PVRManager
.GetCurrentChannel());
105 if (action
.GetID() == REMOTE_0
)
107 CPVRChannelGroupPtr group
= g_PVRChannelGroups
->GetPreviousPlayedGroup();
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()))));
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())
134 CApplicationMessenger::GetInstance().PostMsg(TMSG_GUI_ACTION
, WINDOW_INVALID
, -1, static_cast<void*>(
135 new CAction(ACTION_CHANNEL_SWITCH
, static_cast<float>(iChannelNumber
))));