Merge pull request #24943 from foresto/prev-subtitle
[xbmc.git] / xbmc / pvr / dialogs / GUIDialogPVRRadioRDSInfo.cpp
blob48eb10b9c7a269c9928b6d895771a30fa829fff8
1 /*
2 * Copyright (C) 2012-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIDialogPVRRadioRDSInfo.h"
11 #include "GUIUserMessages.h"
12 #include "ServiceBroker.h"
13 #include "guilib/GUIMessage.h"
14 #include "guilib/GUISpinControl.h"
15 #include "guilib/GUITextBox.h"
16 #include "guilib/LocalizeStrings.h"
17 #include "pvr/PVRManager.h"
18 #include "pvr/PVRPlaybackState.h"
19 #include "pvr/channels/PVRChannel.h"
20 #include "pvr/channels/PVRRadioRDSInfoTag.h"
22 using namespace PVR;
24 #define CONTROL_BTN_OK 10
25 #define SPIN_CONTROL_INFO 21
26 #define TEXT_INFO 22
27 #define CONTROL_NEXT_PAGE 60
28 #define CONTROL_INFO_LIST 70
30 #define INFO_NEWS 1
31 #define INFO_NEWS_LOCAL 2
32 #define INFO_SPORT 3
33 #define INFO_WEATHER 4
34 #define INFO_LOTTERY 5
35 #define INFO_STOCK 6
36 #define INFO_OTHER 7
37 #define INFO_CINEMA 8
38 #define INFO_HOROSCOPE 9
40 CGUIDialogPVRRadioRDSInfo::CGUIDialogPVRRadioRDSInfo()
41 : CGUIDialog(WINDOW_DIALOG_PVR_RADIO_RDS_INFO, "DialogPVRRadioRDSInfo.xml")
42 , m_InfoNews(29916, INFO_NEWS)
43 , m_InfoNewsLocal(29917, INFO_NEWS_LOCAL)
44 , m_InfoSport(29918, INFO_SPORT)
45 , m_InfoWeather(400, INFO_WEATHER)
46 , m_InfoLottery(29919, INFO_LOTTERY)
47 , m_InfoStock(29920, INFO_STOCK)
48 , m_InfoOther(29921, INFO_OTHER)
49 , m_InfoCinema(19602, INFO_CINEMA)
50 , m_InfoHoroscope(29922, INFO_HOROSCOPE)
54 bool CGUIDialogPVRRadioRDSInfo::OnMessage(CGUIMessage& message)
56 if (message.GetMessage() == GUI_MSG_CLICKED)
58 int iControl = message.GetSenderId();
60 if (iControl == CONTROL_BTN_OK)
62 Close();
63 return true;
65 else if (iControl == SPIN_CONTROL_INFO)
67 const std::shared_ptr<const CPVRChannel> channel =
68 CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
69 if (!channel)
70 return false;
72 const std::shared_ptr<const CPVRRadioRDSInfoTag> currentRDS = channel->GetRadioRDSInfoTag();
73 if (!currentRDS)
74 return false;
76 const CGUISpinControl* spin = static_cast<CGUISpinControl*>(GetControl(SPIN_CONTROL_INFO));
77 if (!spin)
78 return false;
80 CGUITextBox* textbox = static_cast<CGUITextBox*>(GetControl(TEXT_INFO));
81 if (!textbox)
82 return false;
84 std::string text;
85 switch (spin->GetValue())
87 case INFO_NEWS:
88 text = currentRDS->GetInfoNews();
89 break;
90 case INFO_NEWS_LOCAL:
91 text = currentRDS->GetInfoNewsLocal();
92 break;
93 case INFO_SPORT:
94 text = currentRDS->GetInfoSport();
95 break;
96 case INFO_WEATHER:
97 text = currentRDS->GetInfoWeather();
98 break;
99 case INFO_LOTTERY:
100 text = currentRDS->GetInfoLottery();
101 break;
102 case INFO_STOCK:
103 text = currentRDS->GetInfoStock();
104 break;
105 case INFO_OTHER:
106 text = currentRDS->GetInfoOther();
107 break;
108 case INFO_CINEMA:
109 text = currentRDS->GetInfoCinema();
110 break;
111 case INFO_HOROSCOPE:
112 text = currentRDS->GetInfoHoroscope();
113 break;
116 if (!text.empty())
117 textbox->SetInfo(KODI::GUILIB::GUIINFO::CGUIInfoLabel{text});
119 SET_CONTROL_VISIBLE(CONTROL_INFO_LIST);
122 else if (message.GetMessage() == GUI_MSG_NOTIFY_ALL)
124 if (message.GetParam1() == GUI_MSG_UPDATE_RADIOTEXT && IsActive())
126 UpdateInfoControls();
130 return CGUIDialog::OnMessage(message);
133 void CGUIDialogPVRRadioRDSInfo::OnInitWindow()
135 CGUIDialog::OnInitWindow();
137 InitInfoControls();
140 void CGUIDialogPVRRadioRDSInfo::InitInfoControls()
142 SET_CONTROL_HIDDEN(CONTROL_INFO_LIST);
144 CGUISpinControl* spin = static_cast<CGUISpinControl*>(GetControl(SPIN_CONTROL_INFO));
145 if (spin)
146 spin->Clear();
148 CGUITextBox* textbox = static_cast<CGUITextBox*>(GetControl(TEXT_INFO));
150 m_InfoNews.Init(spin, textbox);
151 m_InfoNewsLocal.Init(spin, textbox);
152 m_InfoSport.Init(spin, textbox);
153 m_InfoWeather.Init(spin, textbox);
154 m_InfoLottery.Init(spin, textbox);
155 m_InfoStock.Init(spin, textbox);
156 m_InfoOther.Init(spin, textbox);
157 m_InfoCinema.Init(spin, textbox);
158 m_InfoHoroscope.Init(spin, textbox);
160 if (spin && textbox)
161 UpdateInfoControls();
164 void CGUIDialogPVRRadioRDSInfo::UpdateInfoControls()
166 const std::shared_ptr<const CPVRChannel> channel =
167 CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
168 if (!channel)
169 return;
171 const std::shared_ptr<const CPVRRadioRDSInfoTag> currentRDS = channel->GetRadioRDSInfoTag();
172 if (!currentRDS)
173 return;
175 bool bInfoPresent = m_InfoNews.Update(currentRDS->GetInfoNews());
176 bInfoPresent |= m_InfoNewsLocal.Update(currentRDS->GetInfoNewsLocal());
177 bInfoPresent |= m_InfoSport.Update(currentRDS->GetInfoSport());
178 bInfoPresent |= m_InfoWeather.Update(currentRDS->GetInfoWeather());
179 bInfoPresent |= m_InfoLottery.Update(currentRDS->GetInfoLottery());
180 bInfoPresent |= m_InfoStock.Update(currentRDS->GetInfoStock());
181 bInfoPresent |= m_InfoOther.Update(currentRDS->GetInfoOther());
182 bInfoPresent |= m_InfoCinema.Update(currentRDS->GetInfoCinema());
183 bInfoPresent |= m_InfoHoroscope.Update(currentRDS->GetInfoHoroscope());
185 if (bInfoPresent)
186 SET_CONTROL_VISIBLE(CONTROL_INFO_LIST);
189 CGUIDialogPVRRadioRDSInfo::InfoControl::InfoControl(uint32_t iSpinLabelId, uint32_t iSpinControlId)
190 : m_iSpinLabelId(iSpinLabelId),
191 m_iSpinControlId(iSpinControlId)
195 void CGUIDialogPVRRadioRDSInfo::InfoControl::Init(CGUISpinControl* spin, CGUITextBox* textbox)
197 m_spinControl = spin;
198 m_textbox = textbox;
199 m_bSpinLabelPresent = false;
200 m_textboxValue.clear();
203 bool CGUIDialogPVRRadioRDSInfo::InfoControl::Update(const std::string& textboxValue)
205 if (m_spinControl && m_textbox && !textboxValue.empty())
207 if (!m_bSpinLabelPresent)
209 m_spinControl->AddLabel(g_localizeStrings.Get(m_iSpinLabelId), m_iSpinControlId);
210 m_bSpinLabelPresent = true;
213 if (m_textboxValue != textboxValue)
215 m_spinControl->SetValue(m_iSpinControlId);
216 m_textboxValue = textboxValue;
217 m_textbox->SetInfo(KODI::GUILIB::GUIINFO::CGUIInfoLabel{textboxValue});
218 return true;
221 return false;