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 "qradiodata.h"
41#include "qmediaservice.h"
42#include "qmediaobject_p.h"
43#include "qradiodatacontrol.h"
44#include "qmediaserviceprovider_p.h"
45
46#include <QPair>
47
48
49QT_BEGIN_NAMESPACE
50
51static void qRegisterRadioDataMetaTypes()
52{
53 qRegisterMetaType<QRadioData::Error>();
54 qRegisterMetaType<QRadioData::ProgramType>();
55}
56
57Q_CONSTRUCTOR_FUNCTION(qRegisterRadioDataMetaTypes)
58
59
60/*!
61 \class QRadioData
62 \obsolete
63 \brief The QRadioData class provides interfaces to the RDS functionality of the system radio.
64
65 \inmodule QtMultimedia
66 \ingroup multimedia
67 \ingroup multimedia_radio
68
69 The radio data object will emit signals for any changes in radio data. You can enable or disable
70 alternative frequency with setAlternativeFrequenciesEnabled().
71
72 You can get a QRadioData instance fromt the \l{QRadioTuner::radioData()}{radioData}
73 property from a QRadioTuner instance.
74
75 \snippet multimedia-snippets/media.cpp Radio data setup
76
77 Alternatively, you can pass an instance of QRadioTuner to the constructor to QRadioData.
78
79 \sa {Radio Overview}
80
81*/
82
83
84class QRadioDataPrivate
85{
86 Q_DECLARE_NON_CONST_PUBLIC(QRadioData)
87public:
88 QRadioDataPrivate();
89
90 QMediaObject *mediaObject;
91 QRadioDataControl* control;
92
93 void _q_serviceDestroyed();
94
95 QRadioData *q_ptr;
96};
97
98QRadioDataPrivate::QRadioDataPrivate()
99 : mediaObject(nullptr)
100 , control(nullptr)
101{}
102
103void QRadioDataPrivate::_q_serviceDestroyed()
104{
105 mediaObject = nullptr;
106 control = nullptr;
107}
108
109/*!
110 Constructs a radio data based on a \a mediaObject and \a parent.
111
112 The \a mediaObject should be an instance of \l QRadioTuner. It is preferable to use the
113 \l{QRadioTuner::radioData()}{radioData} property on a QRadioTuner instance to get an instance
114 of QRadioData.
115
116 During construction, this class is bound to the \a mediaObject using the
117 \l{QMediaObject::bind()}{bind()} method.
118*/
119
120QRadioData::QRadioData(QMediaObject *mediaObject, QObject *parent)
121 : QObject(parent)
122 , d_ptr(new QRadioDataPrivate)
123{
124 Q_D(QRadioData);
125
126 d->q_ptr = this;
127
128 if (mediaObject)
129 mediaObject->bind(this);
130}
131
132/*!
133 Destroys a radio data.
134*/
135
136QRadioData::~QRadioData()
137{
138 Q_D(QRadioData);
139
140 if (d->mediaObject)
141 d->mediaObject->unbind(this);
142
143 delete d_ptr;
144}
145
146/*!
147 \reimp
148*/
149QMediaObject *QRadioData::mediaObject() const
150{
151 return d_func()->mediaObject;
152}
153
154/*!
155 \reimp
156*/
157bool QRadioData::setMediaObject(QMediaObject *mediaObject)
158{
159 Q_D(QRadioData);
160
161 if (d->mediaObject) {
162 if (d->control) {
163 disconnect(sender: d->control, SIGNAL(stationIdChanged(QString)),
164 receiver: this, SIGNAL(stationIdChanged(QString)));
165 disconnect(sender: d->control, SIGNAL(programTypeChanged(QRadioData::ProgramType)),
166 receiver: this, SIGNAL(programTypeChanged(QRadioData::ProgramType)));
167 disconnect(sender: d->control, SIGNAL(programTypeNameChanged(QString)),
168 receiver: this, SIGNAL(programTypeNameChanged(QString)));
169 disconnect(sender: d->control, SIGNAL(stationNameChanged(QString)),
170 receiver: this, SIGNAL(stationNameChanged(QString)));
171 disconnect(sender: d->control, SIGNAL(radioTextChanged(QString)),
172 receiver: this, SIGNAL(radioTextChanged(QString)));
173 disconnect(sender: d->control, SIGNAL(alternativeFrequenciesEnabledChanged(bool)),
174 receiver: this, SIGNAL(alternativeFrequenciesEnabledChanged(bool)));
175 disconnect(sender: d->control, SIGNAL(error(QRadioData::Error)),
176 receiver: this, SIGNAL(error(QRadioData::Error)));
177
178 QMediaService *service = d->mediaObject->service();
179 service->releaseControl(control: d->control);
180 disconnect(sender: service, SIGNAL(destroyed()), receiver: this, SLOT(_q_serviceDestroyed()));
181 }
182 }
183
184 d->mediaObject = mediaObject;
185
186 if (d->mediaObject) {
187 QMediaService *service = mediaObject->service();
188 if (service) {
189 d->control = qobject_cast<QRadioDataControl*>(object: service->requestControl(QRadioDataControl_iid));
190
191 if (d->control) {
192 connect(sender: d->control, SIGNAL(stationIdChanged(QString)),
193 receiver: this, SIGNAL(stationIdChanged(QString)));
194 connect(sender: d->control, SIGNAL(programTypeChanged(QRadioData::ProgramType)),
195 receiver: this, SIGNAL(programTypeChanged(QRadioData::ProgramType)));
196 connect(sender: d->control, SIGNAL(programTypeNameChanged(QString)),
197 receiver: this, SIGNAL(programTypeNameChanged(QString)));
198 connect(sender: d->control, SIGNAL(stationNameChanged(QString)),
199 receiver: this, SIGNAL(stationNameChanged(QString)));
200 connect(sender: d->control, SIGNAL(radioTextChanged(QString)),
201 receiver: this, SIGNAL(radioTextChanged(QString)));
202 connect(sender: d->control, SIGNAL(alternativeFrequenciesEnabledChanged(bool)),
203 receiver: this, SIGNAL(alternativeFrequenciesEnabledChanged(bool)));
204 connect(sender: d->control, SIGNAL(error(QRadioData::Error)),
205 receiver: this, SIGNAL(error(QRadioData::Error)));
206
207 connect(sender: service, SIGNAL(destroyed()), receiver: this, SLOT(_q_serviceDestroyed()));
208
209 return true;
210 }
211 }
212 }
213
214 // without QRadioDataControl discard the media object
215 d->mediaObject = nullptr;
216 d->control = nullptr;
217
218 return false;
219}
220
221/*!
222 Returns the availability of the radio data service.
223
224 A long as there is a media service which provides radio functionality, then the
225 \l{QMultimedia::AvailabilityStatus}{availability} will be that
226 of the \l{QRadioTuner::availability()}{radio tuner}.
227*/
228QMultimedia::AvailabilityStatus QRadioData::availability() const
229{
230 Q_D(const QRadioData);
231
232 if (d->control == nullptr)
233 return QMultimedia::ServiceMissing;
234
235 return d->mediaObject->availability();
236}
237
238/*!
239 \property QRadioData::stationId
240 \brief Current Program Identification
241
242*/
243
244QString QRadioData::stationId() const
245{
246 Q_D(const QRadioData);
247
248 if (d->control != nullptr)
249 return d->control->stationId();
250 return QString();
251}
252
253/*!
254 \property QRadioData::programType
255 \brief Current Program Type
256
257*/
258
259QRadioData::ProgramType QRadioData::programType() const
260{
261 Q_D(const QRadioData);
262
263 if (d->control != nullptr)
264 return d->control->programType();
265
266 return QRadioData::Undefined;
267}
268
269/*!
270 \property QRadioData::programTypeName
271 \brief Current Program Type Name
272
273*/
274
275QString QRadioData::programTypeName() const
276{
277 Q_D(const QRadioData);
278
279 if (d->control != nullptr)
280 return d->control->programTypeName();
281 return QString();
282}
283
284/*!
285 \property QRadioData::stationName
286 \brief Current Program Service
287
288*/
289
290QString QRadioData::stationName() const
291{
292 Q_D(const QRadioData);
293
294 if (d->control != nullptr)
295 return d->control->stationName();
296 return QString();
297}
298
299/*!
300 \property QRadioData::radioText
301 \brief Current Radio Text
302
303*/
304
305QString QRadioData::radioText() const
306{
307 Q_D(const QRadioData);
308
309 if (d->control != nullptr)
310 return d->control->radioText();
311 return QString();
312}
313
314/*!
315 \property QRadioData::alternativeFrequenciesEnabled
316 \brief Is Alternative Frequency currently enabled
317
318*/
319
320bool QRadioData::isAlternativeFrequenciesEnabled() const
321{
322 Q_D(const QRadioData);
323
324 if (d->control != nullptr)
325 return d->control->isAlternativeFrequenciesEnabled();
326 return false;
327}
328
329void QRadioData::setAlternativeFrequenciesEnabled( bool enabled )
330{
331 Q_D(const QRadioData);
332
333 if (d->control != nullptr)
334 return d->control->setAlternativeFrequenciesEnabled(enabled);
335}
336
337/*!
338 Returns the error state of a radio data.
339
340 \sa errorString()
341*/
342
343QRadioData::Error QRadioData::error() const
344{
345 Q_D(const QRadioData);
346
347 if (d->control != nullptr)
348 return d->control->error();
349 return QRadioData::ResourceError;
350}
351
352/*!
353 Returns a description of a radio data's error state.
354
355 \sa error()
356*/
357QString QRadioData::errorString() const
358{
359 Q_D(const QRadioData);
360
361 if (d->control != nullptr)
362 return d->control->errorString();
363 return QString();
364}
365
366/*!
367 \fn void QRadioData::stationIdChanged(QString stationId)
368
369 Signals that the Program Identification code has changed to \a stationId
370*/
371
372/*!
373 \fn void QRadioData::programTypeChanged(QRadioData::ProgramType programType)
374
375 Signals that the Program Type code has changed to \a programType
376*/
377
378/*!
379 \fn void QRadioData::programTypeNameChanged(QString programTypeName)
380
381 Signals that the Program Type Name has changed to \a programTypeName
382*/
383
384/*!
385 \fn void QRadioData::stationNameChanged(QString stationName)
386
387 Signals that the Program Service has changed to \a stationName
388*/
389
390/*!
391 \fn void QRadioData::alternativeFrequenciesEnabledChanged(bool enabled)
392
393 Signals that automatically tuning to alternative frequencies has been
394 enabled or disabled according to \a enabled.
395*/
396
397/*!
398 \fn void QRadioData::radioTextChanged(QString radioText)
399
400 Signals that the Radio Text property has changed to \a radioText
401*/
402
403/*!
404 \fn void QRadioData::error(QRadioData::Error error)
405
406 Signals that an \a error occurred.
407*/
408
409/*!
410 \enum QRadioData::Error
411
412 Enumerates radio data error conditions.
413
414 \value NoError No errors have occurred.
415 \value ResourceError There is no radio service available.
416 \value OpenError Unable to open radio device.
417 \value OutOfRangeError An attempt to set a frequency or band that is not supported by radio device.
418*/
419
420/*!
421 \enum QRadioData::ProgramType
422
423 This property holds the type of the currently playing program as transmitted
424 by the radio station. The value can be any one of the values defined in the
425 table below.
426
427 \value Undefined
428 \value News
429 \value CurrentAffairs
430 \value Information
431 \value Sport
432 \value Education
433 \value Drama
434 \value Culture
435 \value Science
436 \value Varied
437 \value PopMusic
438 \value RockMusic
439 \value EasyListening
440 \value LightClassical
441 \value SeriousClassical
442 \value OtherMusic
443 \value Weather
444 \value Finance
445 \value ChildrensProgrammes
446 \value SocialAffairs
447 \value Religion
448 \value PhoneIn
449 \value Travel
450 \value Leisure
451 \value JazzMusic
452 \value CountryMusic
453 \value NationalMusic
454 \value OldiesMusic
455 \value FolkMusic
456 \value Documentary
457 \value AlarmTest
458 \value Alarm
459 \value Talk
460 \value ClassicRock
461 \value AdultHits
462 \value SoftRock
463 \value Top40
464 \value Soft
465 \value Nostalgia
466 \value Classical
467 \value RhythmAndBlues
468 \value SoftRhythmAndBlues
469 \value Language
470 \value ReligiousMusic
471 \value ReligiousTalk
472 \value Personality
473 \value Public
474 \value College
475*/
476
477QT_END_NAMESPACE
478
479#include "moc_qradiodata.cpp"
480

source code of qtmultimedia/src/multimedia/radio/qradiodata.cpp