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.
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"
24 #define CONTROL_BTN_OK 10
25 #define SPIN_CONTROL_INFO 21
27 #define CONTROL_NEXT_PAGE 60
28 #define CONTROL_INFO_LIST 70
31 #define INFO_NEWS_LOCAL 2
33 #define INFO_WEATHER 4
34 #define INFO_LOTTERY 5
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
)
65 else if (iControl
== SPIN_CONTROL_INFO
)
67 const std::shared_ptr
<const CPVRChannel
> channel
=
68 CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
72 const std::shared_ptr
<const CPVRRadioRDSInfoTag
> currentRDS
= channel
->GetRadioRDSInfoTag();
76 const CGUISpinControl
* spin
= static_cast<CGUISpinControl
*>(GetControl(SPIN_CONTROL_INFO
));
80 CGUITextBox
* textbox
= static_cast<CGUITextBox
*>(GetControl(TEXT_INFO
));
85 switch (spin
->GetValue())
88 text
= currentRDS
->GetInfoNews();
91 text
= currentRDS
->GetInfoNewsLocal();
94 text
= currentRDS
->GetInfoSport();
97 text
= currentRDS
->GetInfoWeather();
100 text
= currentRDS
->GetInfoLottery();
103 text
= currentRDS
->GetInfoStock();
106 text
= currentRDS
->GetInfoOther();
109 text
= currentRDS
->GetInfoCinema();
112 text
= currentRDS
->GetInfoHoroscope();
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();
140 void CGUIDialogPVRRadioRDSInfo::InitInfoControls()
142 SET_CONTROL_HIDDEN(CONTROL_INFO_LIST
);
144 CGUISpinControl
* spin
= static_cast<CGUISpinControl
*>(GetControl(SPIN_CONTROL_INFO
));
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
);
161 UpdateInfoControls();
164 void CGUIDialogPVRRadioRDSInfo::UpdateInfoControls()
166 const std::shared_ptr
<const CPVRChannel
> channel
=
167 CServiceBroker::GetPVRManager().PlaybackState()->GetPlayingChannel();
171 const std::shared_ptr
<const CPVRRadioRDSInfoTag
> currentRDS
= channel
->GetRadioRDSInfoTag();
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());
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
;
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
});