|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #include "qradiotuner.h" |
|
43 #include "qmediaservice.h" |
|
44 #include "qmediaobject_p.h" |
|
45 #include "qradiotunercontrol.h" |
|
46 |
|
47 #include <QPair> |
|
48 |
|
49 |
|
50 QT_BEGIN_NAMESPACE |
|
51 |
|
52 /*! |
|
53 \class QRadioTuner |
|
54 \brief The QRadioTuner class provides an interface to the systems analog radio device. |
|
55 |
|
56 \ingroup multimedia |
|
57 |
|
58 You can control the systems analog radio device using this interface, for example: |
|
59 |
|
60 \code |
|
61 radio = new QRadioTuner; |
|
62 connect(radio,SIGNAL(frequencyChanged(int)),this,SLOT(freqChanged(int))); |
|
63 if (radio->isBandSupported(QRadioTuner::FM)) { |
|
64 radio->setBand(QRadioTuner::FM); |
|
65 radio->setFrequency(yourRadioStationFrequency); |
|
66 radio->setVolume(100); |
|
67 radio->start(); |
|
68 } |
|
69 \endcode |
|
70 |
|
71 The radio object will emit signals for any changes in state such as: |
|
72 bandChanged(), frequencyChanged(), stereoStatusChanged(), searchingChanged(), |
|
73 signalStrengthChanged(), volumeChanged(), mutedChanged(). |
|
74 |
|
75 You can change between the frequency bands using setBand() however it is recommended |
|
76 that you check to make sure the band is available first using isBandSupported(). |
|
77 |
|
78 */ |
|
79 |
|
80 |
|
81 class QRadioTunerPrivate : public QMediaObjectPrivate |
|
82 { |
|
83 public: |
|
84 QRadioTunerPrivate():provider(0), control(0) {} |
|
85 QMediaServiceProvider *provider; |
|
86 QRadioTunerControl* control; |
|
87 }; |
|
88 |
|
89 |
|
90 |
|
91 /*! |
|
92 Constructs a radio tuner based on a media service allocated by a media service \a provider. |
|
93 |
|
94 The \a parent is passed to QMediaObject. |
|
95 */ |
|
96 |
|
97 QRadioTuner::QRadioTuner(QObject *parent, QMediaServiceProvider* provider): |
|
98 QMediaObject(*new QRadioTunerPrivate, parent, provider->requestService(Q_MEDIASERVICE_RADIO)) |
|
99 { |
|
100 Q_D(QRadioTuner); |
|
101 |
|
102 d->provider = provider; |
|
103 |
|
104 if (d->service != 0) { |
|
105 d->control = qobject_cast<QRadioTunerControl*>(d->service->requestControl(QRadioTunerControl_iid)); |
|
106 if (d->control != 0) { |
|
107 connect(d->control, SIGNAL(stateChanged(QRadioTuner::State)), SIGNAL(stateChanged(QRadioTuner::State))); |
|
108 connect(d->control, SIGNAL(bandChanged(QRadioTuner::Band)), SIGNAL(bandChanged(QRadioTuner::Band))); |
|
109 connect(d->control, SIGNAL(frequencyChanged(int)), SIGNAL(frequencyChanged(int))); |
|
110 connect(d->control, SIGNAL(stereoStatusChanged(bool)), SIGNAL(stereoStatusChanged(bool))); |
|
111 connect(d->control, SIGNAL(searchingChanged(bool)), SIGNAL(searchingChanged(bool))); |
|
112 connect(d->control, SIGNAL(signalStrengthChanged(int)), SIGNAL(signalStrengthChanged(int))); |
|
113 connect(d->control, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged(int))); |
|
114 connect(d->control, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool))); |
|
115 } |
|
116 } |
|
117 } |
|
118 |
|
119 /*! |
|
120 Destroys a radio tuner. |
|
121 */ |
|
122 |
|
123 QRadioTuner::~QRadioTuner() |
|
124 { |
|
125 Q_D(QRadioTuner); |
|
126 |
|
127 if (d->service && d->control) |
|
128 d->service->releaseControl(d->control); |
|
129 |
|
130 d->provider->releaseService(d->service); |
|
131 } |
|
132 |
|
133 /*! |
|
134 Returns true if the radio tuner service is ready to use. |
|
135 */ |
|
136 bool QRadioTuner::isAvailable() const |
|
137 { |
|
138 if (d_func()->control != NULL) |
|
139 return d_func()->control->isAvailable(); |
|
140 else |
|
141 return false; |
|
142 } |
|
143 |
|
144 /*! |
|
145 Returns the availability error state. |
|
146 */ |
|
147 QtMultimediaKit::AvailabilityError QRadioTuner::availabilityError() const |
|
148 { |
|
149 if (d_func()->control != NULL) |
|
150 return d_func()->control->availabilityError(); |
|
151 else |
|
152 return QtMultimediaKit::ServiceMissingError; |
|
153 } |
|
154 |
|
155 /*! |
|
156 \property QRadioTuner::state |
|
157 Return the current radio tuner state. |
|
158 |
|
159 \sa QRadioTuner::State |
|
160 */ |
|
161 |
|
162 QRadioTuner::State QRadioTuner::state() const |
|
163 { |
|
164 return d_func()->control ? |
|
165 d_func()->control->state() : QRadioTuner::StoppedState; |
|
166 } |
|
167 |
|
168 /*! |
|
169 \property QRadioTuner::band |
|
170 \brief the frequency band a radio tuner is tuned to. |
|
171 |
|
172 \sa QRadioTuner::Band |
|
173 */ |
|
174 |
|
175 QRadioTuner::Band QRadioTuner::band() const |
|
176 { |
|
177 Q_D(const QRadioTuner); |
|
178 |
|
179 if (d->control != 0) |
|
180 return d->control->band(); |
|
181 |
|
182 return QRadioTuner::FM; |
|
183 } |
|
184 |
|
185 /*! |
|
186 \property QRadioTuner::frequency |
|
187 \brief the frequency in Hertz a radio tuner is tuned to. |
|
188 */ |
|
189 |
|
190 int QRadioTuner::frequency() const |
|
191 { |
|
192 Q_D(const QRadioTuner); |
|
193 |
|
194 if (d->control != 0) |
|
195 return d->control->frequency(); |
|
196 |
|
197 return 0; |
|
198 } |
|
199 |
|
200 /*! |
|
201 Returns the number of Hertz to increment the frequency by when stepping through frequencies |
|
202 within a given \a band. |
|
203 */ |
|
204 |
|
205 int QRadioTuner::frequencyStep(QRadioTuner::Band band) const |
|
206 { |
|
207 Q_D(const QRadioTuner); |
|
208 |
|
209 if(d->control != 0) |
|
210 return d->control->frequencyStep(band); |
|
211 |
|
212 return 0; |
|
213 } |
|
214 |
|
215 /*! |
|
216 Returns a frequency \a band's minimum and maximum frequency. |
|
217 */ |
|
218 |
|
219 QPair<int,int> QRadioTuner::frequencyRange(QRadioTuner::Band band) const |
|
220 { |
|
221 Q_D(const QRadioTuner); |
|
222 |
|
223 if(d->control != 0) |
|
224 return d->control->frequencyRange(band); |
|
225 |
|
226 return qMakePair<int,int>(0,0); |
|
227 } |
|
228 |
|
229 /*! |
|
230 \property QRadioTuner::stereo |
|
231 \brief whether a radio tuner is receiving a stereo signal. |
|
232 */ |
|
233 |
|
234 bool QRadioTuner::isStereo() const |
|
235 { |
|
236 Q_D(const QRadioTuner); |
|
237 |
|
238 if (d->control != 0) |
|
239 return d->control->isStereo(); |
|
240 |
|
241 return false; |
|
242 } |
|
243 |
|
244 |
|
245 /*! |
|
246 \property QRadioTuner::stereoMode |
|
247 \brief the stereo mode of a radio tuner. |
|
248 */ |
|
249 |
|
250 QRadioTuner::StereoMode QRadioTuner::stereoMode() const |
|
251 { |
|
252 Q_D(const QRadioTuner); |
|
253 |
|
254 if (d->control != 0) |
|
255 return d->control->stereoMode(); |
|
256 |
|
257 return QRadioTuner::Auto; |
|
258 } |
|
259 |
|
260 void QRadioTuner::setStereoMode(QRadioTuner::StereoMode mode) |
|
261 { |
|
262 Q_D(QRadioTuner); |
|
263 |
|
264 if (d->control != 0) |
|
265 return d->control->setStereoMode(mode); |
|
266 } |
|
267 |
|
268 /*! |
|
269 Identifies if a frequency \a band is supported by a radio tuner. |
|
270 |
|
271 Returns true if the band is supported, and false if it is not. |
|
272 */ |
|
273 |
|
274 bool QRadioTuner::isBandSupported(QRadioTuner::Band band) const |
|
275 { |
|
276 Q_D(const QRadioTuner); |
|
277 |
|
278 if (d->control != 0) |
|
279 return d->control->isBandSupported(band); |
|
280 |
|
281 return false; |
|
282 } |
|
283 |
|
284 /*! |
|
285 Activate the radio device. |
|
286 */ |
|
287 |
|
288 void QRadioTuner::start() |
|
289 { |
|
290 Q_D(const QRadioTuner); |
|
291 |
|
292 if (d->control != 0) |
|
293 d->control->start(); |
|
294 } |
|
295 |
|
296 /*! |
|
297 Deactivate the radio device. |
|
298 */ |
|
299 |
|
300 void QRadioTuner::stop() |
|
301 { |
|
302 Q_D(const QRadioTuner); |
|
303 |
|
304 if (d->control != 0) |
|
305 d->control->stop(); |
|
306 } |
|
307 |
|
308 /*! |
|
309 \property QRadioTuner::signalStrength |
|
310 \brief the strength of the current radio signal as a percentage. |
|
311 */ |
|
312 |
|
313 int QRadioTuner::signalStrength() const |
|
314 { |
|
315 Q_D(const QRadioTuner); |
|
316 |
|
317 if (d->control != 0) |
|
318 return d->control->signalStrength(); |
|
319 |
|
320 return 0; |
|
321 } |
|
322 |
|
323 /*! |
|
324 \property QRadioTuner::volume |
|
325 \brief the volume of a radio tuner's audio output as a percentage. |
|
326 */ |
|
327 |
|
328 |
|
329 int QRadioTuner::volume() const |
|
330 { |
|
331 Q_D(const QRadioTuner); |
|
332 |
|
333 if (d->control != 0) |
|
334 return d->control->volume(); |
|
335 |
|
336 return 0; |
|
337 } |
|
338 |
|
339 /*! |
|
340 \property QRadioTuner::muted |
|
341 \brief whether a radio tuner's audio output is muted. |
|
342 */ |
|
343 |
|
344 bool QRadioTuner::isMuted() const |
|
345 { |
|
346 Q_D(const QRadioTuner); |
|
347 |
|
348 if (d->control != 0) |
|
349 return d->control->isMuted(); |
|
350 |
|
351 return false; |
|
352 } |
|
353 |
|
354 /*! |
|
355 Sets a radio tuner's frequency \a band. |
|
356 |
|
357 Changing the band will reset the \l frequency to the new band's minimum frequency. |
|
358 */ |
|
359 |
|
360 void QRadioTuner::setBand(QRadioTuner::Band band) |
|
361 { |
|
362 Q_D(QRadioTuner); |
|
363 |
|
364 if (d->control != 0) |
|
365 d->control->setBand(band); |
|
366 } |
|
367 |
|
368 /*! |
|
369 Sets a radio tuner's \a frequency. |
|
370 |
|
371 If the tuner is set to a frequency outside the current \l band, the band will be changed to |
|
372 one occupied by the new frequency. |
|
373 */ |
|
374 |
|
375 void QRadioTuner::setFrequency(int frequency) |
|
376 { |
|
377 Q_D(QRadioTuner); |
|
378 |
|
379 if (d->control != 0) |
|
380 d->control->setFrequency(frequency); |
|
381 } |
|
382 |
|
383 void QRadioTuner::setVolume(int volume) |
|
384 { |
|
385 Q_D(QRadioTuner); |
|
386 |
|
387 if (d->control != 0) |
|
388 d->control->setVolume(volume); |
|
389 } |
|
390 |
|
391 void QRadioTuner::setMuted(bool muted) |
|
392 { |
|
393 Q_D(QRadioTuner); |
|
394 |
|
395 if (d->control != 0) |
|
396 d->control->setMuted(muted); |
|
397 } |
|
398 |
|
399 /*! |
|
400 \property QRadioTuner::searching |
|
401 \brief whether a radio tuner is currently scanning for a signal. |
|
402 |
|
403 \sa searchForward(), searchBackward(), cancelSearch() |
|
404 */ |
|
405 |
|
406 bool QRadioTuner::isSearching() const |
|
407 { |
|
408 Q_D(const QRadioTuner); |
|
409 |
|
410 if (d->control != 0) |
|
411 return d->control->isSearching(); |
|
412 |
|
413 return false; |
|
414 } |
|
415 |
|
416 /*! |
|
417 Starts a forward scan for a signal, starting from the current \l frequency. |
|
418 |
|
419 \sa searchBackward(), cancelSearch(), searching |
|
420 */ |
|
421 |
|
422 void QRadioTuner::searchForward() |
|
423 { |
|
424 Q_D(QRadioTuner); |
|
425 |
|
426 if (d->control != 0) |
|
427 d->control->searchForward(); |
|
428 } |
|
429 |
|
430 /*! |
|
431 Starts a backwards scan for a signal, starting from the current \l frequency. |
|
432 |
|
433 \sa searchForward(), cancelSearch(), searching |
|
434 */ |
|
435 |
|
436 void QRadioTuner::searchBackward() |
|
437 { |
|
438 Q_D(QRadioTuner); |
|
439 |
|
440 if (d->control != 0) |
|
441 d->control->searchBackward(); |
|
442 } |
|
443 |
|
444 /*! |
|
445 Stops scanning for a signal. |
|
446 |
|
447 \sa searchForward(), searchBackward(), searching |
|
448 */ |
|
449 |
|
450 void QRadioTuner::cancelSearch() |
|
451 { |
|
452 Q_D(QRadioTuner); |
|
453 |
|
454 if (d->control != 0) |
|
455 d->control->cancelSearch(); |
|
456 } |
|
457 |
|
458 /*! |
|
459 Returns the error state of a radio tuner. |
|
460 |
|
461 \sa errorString() |
|
462 */ |
|
463 |
|
464 QRadioTuner::Error QRadioTuner::error() const |
|
465 { |
|
466 Q_D(const QRadioTuner); |
|
467 |
|
468 if (d->control != 0) |
|
469 return d->control->error(); |
|
470 |
|
471 return QRadioTuner::ResourceError; |
|
472 } |
|
473 |
|
474 /*! |
|
475 Returns a description of a radio tuner's error state. |
|
476 |
|
477 \sa error() |
|
478 */ |
|
479 |
|
480 QString QRadioTuner::errorString() const |
|
481 { |
|
482 Q_D(const QRadioTuner); |
|
483 |
|
484 if (d->control != 0) |
|
485 return d->control->errorString(); |
|
486 |
|
487 return QString(); |
|
488 } |
|
489 |
|
490 /*! |
|
491 \fn void QRadioTuner::bandChanged(QRadioTuner::Band band) |
|
492 |
|
493 Signals a radio tuner's \a band has changed. |
|
494 */ |
|
495 |
|
496 /*! |
|
497 \fn void QRadioTuner::frequencyChanged(int frequency) |
|
498 |
|
499 Signals that the \a frequency a radio tuner is tuned to has changed. |
|
500 */ |
|
501 |
|
502 /*! |
|
503 \fn void QRadioTuner::mutedChanged(bool muted) |
|
504 |
|
505 Signals that the \a muted state of a radio tuner's audio output has changed. |
|
506 */ |
|
507 |
|
508 /*! |
|
509 \fn void QRadioTuner::volumeChanged(int volume) |
|
510 |
|
511 Signals that the \a volume of a radio tuner's audio output has changed. |
|
512 */ |
|
513 |
|
514 /*! |
|
515 \fn void QRadioTuner::searchingChanged(bool searching) |
|
516 |
|
517 Signals that the \a searching state of a radio tuner has changed. |
|
518 */ |
|
519 |
|
520 /*! |
|
521 \fn void QRadioTuner::stereoStatusChanged(bool stereo) |
|
522 |
|
523 Signals that the \a stereo state of a radio tuner has changed. |
|
524 */ |
|
525 |
|
526 /*! |
|
527 \fn void QRadioTuner::signalStrengthChanged(int strength) |
|
528 |
|
529 Signals that the \a strength of the signal received by a radio tuner has changed. |
|
530 */ |
|
531 |
|
532 /*! |
|
533 \fn void QRadioTuner::error(QRadioTuner::Error error) |
|
534 |
|
535 Signals that an \a error occurred. |
|
536 */ |
|
537 |
|
538 /*! |
|
539 \enum QRadioTuner::State |
|
540 |
|
541 Enumerates radio tuner states. |
|
542 |
|
543 \value ActiveState The tuner is started and active. |
|
544 \value StoppedState The tuner device is stopped. |
|
545 */ |
|
546 |
|
547 |
|
548 /*! |
|
549 \enum QRadioTuner::Band |
|
550 |
|
551 Enumerates radio frequency bands. |
|
552 |
|
553 \value AM 520 to 1610 kHz, 9 or 10kHz channel spacing, extended 1610 to 1710 kHz |
|
554 \value FM 87.5 to 108.0 MHz, except Japan 76-90 MHz |
|
555 \value SW 1.711 to 30.0 MHz, divided into 15 bands. 5kHz channel spacing |
|
556 \value LW 148.5 to 283.5 kHz, 9kHz channel spacing (Europe, Africa, Asia) |
|
557 \value FM2 range not defined, used when area supports more than one FM range. |
|
558 */ |
|
559 |
|
560 /*! |
|
561 \enum QRadioTuner::Error |
|
562 |
|
563 Enumerates radio tuner error conditions. |
|
564 |
|
565 \value NoError No errors have occurred. |
|
566 \value ResourceError There is no radio service available. |
|
567 \value OpenError Unable to open radio device. |
|
568 \value OutOfRangeError An attempt to set a frequency or band that is not supported by radio device. |
|
569 */ |
|
570 |
|
571 /*! |
|
572 \enum QRadioTuner::StereoMode |
|
573 |
|
574 Enumerates radio tuner policy for receiving stereo signals. |
|
575 |
|
576 \value Auto Uses the stereo mode matching the station. |
|
577 \value ForceStereo Provide stereo mode, converting if required. |
|
578 \value ForceMono Provide mono mode, converting if required. |
|
579 */ |
|
580 |
|
581 /*! \fn void QRadioTuner::stateChanged(QRadioTuner::State state) |
|
582 This signal is emitted when the state changes to \a state. |
|
583 */ |
|
584 |
|
585 #include "moc_qradiotuner.cpp" |
|
586 QT_END_NAMESPACE |
|
587 |