1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qdeclarativeradiodata_p.h"
41
42QT_BEGIN_NAMESPACE
43
44/*!
45 \qmltype RadioData
46 \instantiates QDeclarativeRadioData
47 \inqmlmodule QtMultimedia
48 \brief Access RDS data from a QML application.
49 \ingroup multimedia_qml
50 \ingroup multimedia_radio_qml
51 \inherits Item
52
53 \c RadioData is your gateway to all the data available through RDS. RDS is the Radio Data System
54 which allows radio stations to broadcast information like the \l stationId, \l programType, \l programTypeName,
55 \l stationName, and \l radioText. This information can be read from the \c RadioData. It also allows
56 you to set whether the radio should tune to alternative frequencies if the current signal strength falls too much.
57
58 \qml
59 Rectangle {
60 width: 480
61 height: 320
62
63 Radio {
64 id: radio
65 band: Radio.FM
66 }
67
68 Column {
69 Text {
70 text: radio.radioData.stationName
71 }
72
73 Text {
74 text: radio.radioData.programTypeName
75 }
76
77 Text {
78 text: radio.radioData.radioText
79 }
80 }
81 }
82
83 \endqml
84
85 You use \c RadioData together with a \l Radio, either by
86 accessing the \c radioData property of the Radio, or
87 creating a separate RadioData. The properties of the
88 RadioData type will reflect the information broadcast by the
89 radio station the Radio is currently tuned to.
90
91 \sa {Radio Overview}
92*/
93QDeclarativeRadioData::QDeclarativeRadioData(QObject *parent) :
94 QObject(parent)
95{
96 m_radioTuner = new QRadioTuner(this);
97 m_radioData = m_radioTuner->radioData();
98
99 connectSignals();
100}
101
102QDeclarativeRadioData::QDeclarativeRadioData(QRadioTuner *tuner, QObject *parent) :
103 QObject(parent)
104{
105 m_radioTuner = tuner;
106 m_radioData = m_radioTuner->radioData();
107
108 connectSignals();
109}
110
111QDeclarativeRadioData::~QDeclarativeRadioData()
112{
113}
114
115/*!
116 \qmlproperty enumeration QtMultimedia::RadioData::availability
117
118 Returns the availability state of the radio data interface.
119
120 This is one of:
121
122 \table
123 \header \li Value \li Description
124 \row \li Available
125 \li The radio data interface is available to use
126 \row \li Busy
127 \li The radio data interface is usually available to use, but is currently busy.
128 \row \li Unavailable
129 \li The radio data interface is not available to use (there may be no radio
130 hardware)
131 \row \li ResourceMissing
132 \li There is one or more resources missing, so the radio cannot
133 be used. It may be possible to try again at a later time.
134 \endtable
135 */
136QDeclarativeRadioData::Availability QDeclarativeRadioData::availability() const
137{
138 if (m_radioData)
139 return Availability(m_radioData->availability());
140
141 return Unavailable;
142}
143
144
145/*!
146 \qmlproperty string QtMultimedia::RadioData::stationId
147
148 This property allows you to read the station Id of the currently tuned radio
149 station.
150 */
151QString QDeclarativeRadioData::stationId() const
152{
153 if (m_radioData)
154 return m_radioData->stationId();
155
156 return QString();
157}
158
159/*!
160 \qmlproperty enumeration QtMultimedia::RadioData::programType
161
162 This property holds the type of the currently playing program as transmitted
163 by the radio station. The value can be any one of the values defined in the
164 table below.
165
166 \table
167 \header \li Value
168 \row \li Undefined
169 \row \li News
170 \row \li CurrentAffairs
171 \row \li Information
172 \row \li Sport
173 \row \li Education
174 \row \li Drama
175 \row \li Culture
176 \row \li Science
177 \row \li Varied
178 \row \li PopMusic
179 \row \li RockMusic
180 \row \li EasyListening
181 \row \li LightClassical
182 \row \li SeriousClassical
183 \row \li OtherMusic
184 \row \li Weather
185 \row \li Finance
186 \row \li ChildrensProgrammes
187 \row \li SocialAffairs
188 \row \li Religion
189 \row \li PhoneIn
190 \row \li Travel
191 \row \li Leisure
192 \row \li JazzMusic
193 \row \li CountryMusic
194 \row \li NationalMusic
195 \row \li OldiesMusic
196 \row \li FolkMusic
197 \row \li Documentary
198 \row \li AlarmTest
199 \row \li Alarm
200 \row \li Talk
201 \row \li ClassicRock
202 \row \li AdultHits
203 \row \li SoftRock
204 \row \li Top40
205 \row \li Soft
206 \row \li Nostalgia
207 \row \li Classical
208 \row \li RhythmAndBlues
209 \row \li SoftRhythmAndBlues
210 \row \li Language
211 \row \li ReligiousMusic
212 \row \li ReligiousTalk
213 \row \li Personality
214 \row \li Public
215 \row \li College
216
217 \endtable
218 */
219QDeclarativeRadioData::ProgramType QDeclarativeRadioData::programType() const
220{
221 if (m_radioData)
222 return static_cast<QDeclarativeRadioData::ProgramType>(m_radioData->programType());
223
224 return Undefined;
225}
226
227/*!
228 \qmlproperty string QtMultimedia::RadioData::programTypeName
229
230 This property holds a string representation of the \l programType.
231 */
232QString QDeclarativeRadioData::programTypeName() const
233{
234 if (m_radioData)
235 return m_radioData->programTypeName();
236
237 return QString();
238}
239
240/*!
241 \qmlproperty string QtMultimedia::RadioData::stationName
242
243 This property has the name of the currently tuned radio station.
244 */
245QString QDeclarativeRadioData::stationName() const
246{
247 if (m_radioData)
248 return m_radioData->stationName();
249
250 return QString();
251}
252
253/*!
254 \qmlproperty string QtMultimedia::RadioData::radioText
255
256 This property holds free-text transmitted by the radio station. This is typically used to
257 show supporting information for the currently playing content, for instance song title or
258 artist name.
259 */
260QString QDeclarativeRadioData::radioText() const
261{
262 if (m_radioData)
263 return m_radioData->radioText();
264
265 return QString();
266}
267
268/*!
269 \qmlproperty bool QtMultimedia::RadioData::alternativeFrequenciesEnabled
270
271 This property allows you to specify whether the radio should try and tune to alternative
272 frequencies if the signal strength of the current station becomes too weak. The alternative
273 frequencies are emitted over RDS by the radio station, and the tuning happens automatically.
274 */
275bool QDeclarativeRadioData::alternativeFrequenciesEnabled() const
276{
277 if (m_radioData)
278 return m_radioData->isAlternativeFrequenciesEnabled();
279
280 return false;
281}
282
283void QDeclarativeRadioData::setAlternativeFrequenciesEnabled(bool enabled)
284{
285 if (m_radioData)
286 m_radioData->setAlternativeFrequenciesEnabled(enabled);
287}
288
289void QDeclarativeRadioData::_q_programTypeChanged(QRadioData::ProgramType programType)
290{
291 emit programTypeChanged(programType: static_cast<QDeclarativeRadioData::ProgramType>(programType));
292}
293
294void QDeclarativeRadioData::_q_error(QRadioData::Error errorCode)
295{
296 emit error(errorCode: static_cast<QDeclarativeRadioData::Error>(errorCode));
297 emit errorChanged();
298}
299
300void QDeclarativeRadioData::_q_availabilityChanged(QMultimedia::AvailabilityStatus availability)
301{
302 emit availabilityChanged(availability: Availability(availability));
303}
304
305void QDeclarativeRadioData::connectSignals()
306{
307 if (!m_radioData)
308 return;
309
310 connect(sender: m_radioData, SIGNAL(programTypeChanged(QRadioData::ProgramType)), receiver: this,
311 SLOT(_q_programTypeChanged(QRadioData::ProgramType)));
312
313 connect(sender: m_radioData, SIGNAL(stationIdChanged(QString)), receiver: this, SIGNAL(stationIdChanged(QString)));
314 connect(sender: m_radioData, SIGNAL(programTypeNameChanged(QString)), receiver: this, SIGNAL(programTypeNameChanged(QString)));
315 connect(sender: m_radioData, SIGNAL(stationNameChanged(QString)), receiver: this, SIGNAL(stationNameChanged(QString)));
316 connect(sender: m_radioData, SIGNAL(radioTextChanged(QString)), receiver: this, SIGNAL(radioTextChanged(QString)));
317 connect(sender: m_radioData, SIGNAL(alternativeFrequenciesEnabledChanged(bool)), receiver: this,
318 SIGNAL(alternativeFrequenciesEnabledChanged(bool)));
319 // Since the radio data type depends on the service for the tuner, the availability is also dictated from the tuner
320 connect(sender: m_radioTuner, SIGNAL(availabilityChanged(QMultimedia::AvailabilityStatus)), receiver: this, SLOT(_q_availabilityChanged(QMultimedia::AvailabilityStatus)));
321
322 connect(sender: m_radioData, SIGNAL(error(QRadioData::Error)), receiver: this, SLOT(_q_error(QRadioData::Error)));
323}
324
325QT_END_NAMESPACE
326

source code of qtmultimedia/src/imports/multimedia/qdeclarativeradiodata.cpp