|
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 "s60radiotunercontrol_since32.h" |
|
43 #include "s60radiotunerservice.h" |
|
44 |
|
45 #include <QtCore/qdebug.h> |
|
46 #include <RadioFmTunerUtility.h> |
|
47 |
|
48 S60RadioTunerControl::S60RadioTunerControl(QObject *parent) |
|
49 : QRadioTunerControl(parent) |
|
50 , m_error(0) |
|
51 , m_radioUtility(NULL) |
|
52 , m_fmTunerUtility(NULL) |
|
53 , m_playerUtility(NULL) |
|
54 , m_audioInitializationComplete(false) |
|
55 , m_muted(false) |
|
56 , m_isStereo(true) |
|
57 , m_vol(100) |
|
58 , m_signal(0) |
|
59 , m_radioError(QRadioTuner::NoError) |
|
60 , m_scanning(false) |
|
61 , m_currentBand(QRadioTuner::FM) |
|
62 , m_currentFreq(87500000) |
|
63 , m_stereoMode(QRadioTuner::Auto) |
|
64 , m_apiTunerState(QRadioTuner::StoppedState) |
|
65 , m_maxVolume(100) |
|
66 { |
|
67 initRadio(); |
|
68 } |
|
69 |
|
70 S60RadioTunerControl::~S60RadioTunerControl() |
|
71 { |
|
72 if (m_fmTunerUtility) { |
|
73 m_fmTunerUtility->Close(); |
|
74 } |
|
75 |
|
76 if(m_playerUtility) { |
|
77 m_playerUtility->Close(); |
|
78 } |
|
79 |
|
80 delete m_radioUtility; |
|
81 } |
|
82 |
|
83 QRadioTuner::State S60RadioTunerControl::state() const |
|
84 { |
|
85 return m_apiTunerState; |
|
86 } |
|
87 |
|
88 QRadioTuner::Band S60RadioTunerControl::band() const |
|
89 { |
|
90 return m_currentBand; |
|
91 } |
|
92 |
|
93 bool S60RadioTunerControl::isBandSupported(QRadioTuner::Band b) const |
|
94 { |
|
95 if(b == QRadioTuner::FM) |
|
96 return true; |
|
97 else if(b == QRadioTuner::LW) |
|
98 return false; |
|
99 else if(b == QRadioTuner::AM) |
|
100 return true; |
|
101 else if(b == QRadioTuner::SW) |
|
102 return false; |
|
103 else |
|
104 return false; |
|
105 } |
|
106 |
|
107 void S60RadioTunerControl::setBand(QRadioTuner::Band b) |
|
108 { |
|
109 QRadioTuner::Band tempBand = b; |
|
110 if (tempBand != m_currentBand) { |
|
111 m_currentBand = b; |
|
112 emit bandChanged(m_currentBand); |
|
113 } |
|
114 } |
|
115 |
|
116 int S60RadioTunerControl::frequency() const |
|
117 { |
|
118 return m_currentFreq; |
|
119 } |
|
120 |
|
121 void S60RadioTunerControl::setFrequency(int frequency) |
|
122 { |
|
123 m_currentFreq = frequency; |
|
124 m_fmTunerUtility->SetFrequency(m_currentFreq); |
|
125 } |
|
126 int S60RadioTunerControl::frequencyStep(QRadioTuner::Band b) const |
|
127 { |
|
128 int step = 0; |
|
129 if(b == QRadioTuner::FM) |
|
130 step = 100000; // 100kHz steps |
|
131 else if(b == QRadioTuner::LW) |
|
132 step = 1000; // 1kHz steps |
|
133 else if(b == QRadioTuner::AM) |
|
134 step = 1000; // 1kHz steps |
|
135 else if(b == QRadioTuner::SW) |
|
136 step = 500; // 500Hz steps |
|
137 |
|
138 return step; |
|
139 } |
|
140 |
|
141 QPair<int,int> S60RadioTunerControl::frequencyRange(QRadioTuner::Band band) const |
|
142 { |
|
143 int bottomFreq; |
|
144 int topFreq; |
|
145 |
|
146 int bandError = KErrNone; |
|
147 TFmRadioFrequencyRange range; |
|
148 |
|
149 if (m_fmTunerUtility) { |
|
150 bandError = m_fmTunerUtility->GetFrequencyRange(range, bottomFreq, topFreq); |
|
151 } |
|
152 if (!bandError) { |
|
153 return qMakePair<int,int>(bottomFreq, topFreq); |
|
154 } |
|
155 |
|
156 return qMakePair<int,int>(0,0); |
|
157 } |
|
158 |
|
159 bool S60RadioTunerControl::isStereo() const |
|
160 { |
|
161 return m_isStereo; |
|
162 } |
|
163 |
|
164 QRadioTuner::StereoMode S60RadioTunerControl::stereoMode() const |
|
165 { |
|
166 return m_stereoMode; |
|
167 } |
|
168 |
|
169 void S60RadioTunerControl::setStereoMode(QRadioTuner::StereoMode mode) |
|
170 { |
|
171 if (m_fmTunerUtility) { |
|
172 if (QRadioTuner::ForceMono == mode) { |
|
173 m_fmTunerUtility->ForceMonoReception(true); |
|
174 m_stereoMode = QRadioTuner::ForceMono; |
|
175 m_isStereo = false; |
|
176 } else { |
|
177 m_fmTunerUtility->ForceMonoReception(false); |
|
178 m_isStereo = true; |
|
179 m_stereoMode = QRadioTuner::ForceStereo; |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 int S60RadioTunerControl::signalStrength() const |
|
185 { |
|
186 // return value is a percentage value |
|
187 if (m_fmTunerUtility) { |
|
188 TInt maxSignalStrength; |
|
189 TInt currentSignalStrength; |
|
190 m_error = m_fmTunerUtility->GetMaxSignalStrength(maxSignalStrength); |
|
191 |
|
192 if (m_error == KErrNone) { |
|
193 m_error = m_fmTunerUtility->GetSignalStrength(currentSignalStrength); |
|
194 if (m_error == KErrNone) { |
|
195 if (currentSignalStrength == 0 || maxSignalStrength == 0) { |
|
196 return currentSignalStrength; |
|
197 } |
|
198 m_signal = currentSignalStrength / maxSignalStrength; |
|
199 } |
|
200 } |
|
201 } |
|
202 return m_signal; |
|
203 } |
|
204 |
|
205 int S60RadioTunerControl::volume() const |
|
206 { |
|
207 return m_vol; |
|
208 } |
|
209 |
|
210 void S60RadioTunerControl::setVolume(int volume) |
|
211 { |
|
212 if (m_playerUtility) { |
|
213 m_vol = volume; |
|
214 volume *= m_volMultiplier; |
|
215 m_playerUtility->SetVolume(volume); |
|
216 emit volumeChanged(m_vol); |
|
217 } |
|
218 } |
|
219 |
|
220 bool S60RadioTunerControl::isMuted() const |
|
221 { |
|
222 return m_muted; |
|
223 } |
|
224 |
|
225 void S60RadioTunerControl::setMuted(bool muted) |
|
226 { |
|
227 if (m_playerUtility) { |
|
228 m_muted = muted; |
|
229 m_playerUtility->Mute(m_muted); |
|
230 } |
|
231 } |
|
232 |
|
233 bool S60RadioTunerControl::isSearching() const |
|
234 { |
|
235 return m_scanning; |
|
236 } |
|
237 |
|
238 void S60RadioTunerControl::cancelSearch() |
|
239 { |
|
240 m_fmTunerUtility->CancelStationSeek(); |
|
241 m_scanning = false; |
|
242 emit searchingChanged(false); |
|
243 } |
|
244 |
|
245 void S60RadioTunerControl::searchForward() |
|
246 { |
|
247 m_fmTunerUtility->StationSeek(true); |
|
248 m_scanning = true; |
|
249 emit searchingChanged(true); |
|
250 } |
|
251 |
|
252 void S60RadioTunerControl::searchBackward() |
|
253 { |
|
254 m_fmTunerUtility->StationSeek(false); |
|
255 m_scanning = true; |
|
256 emit searchingChanged(true); |
|
257 } |
|
258 |
|
259 bool S60RadioTunerControl::isValid() const |
|
260 { |
|
261 return m_available; |
|
262 } |
|
263 |
|
264 bool S60RadioTunerControl::initRadio() |
|
265 { |
|
266 m_available = false; |
|
267 // create an instance of Radio Utility factory and indicate |
|
268 // FM Radio is a primary client |
|
269 TRAPD(utilityError, |
|
270 m_radioUtility = CRadioUtility::NewL(ETrue); |
|
271 // Get a tuner utility |
|
272 m_fmTunerUtility = &m_radioUtility->RadioFmTunerUtilityL(*this); |
|
273 // we want to listen radio in offline mode too |
|
274 m_fmTunerUtility->EnableTunerInOfflineMode(ETrue); |
|
275 // Get a player utility |
|
276 m_playerUtility = &m_radioUtility->RadioPlayerUtilityL(*this); |
|
277 ); |
|
278 if (utilityError != KErrNone) { |
|
279 m_radioError = QRadioTuner::ResourceError; |
|
280 return m_available; |
|
281 } |
|
282 |
|
283 m_tunerControl = false; |
|
284 |
|
285 m_available = true; |
|
286 return m_available; |
|
287 } |
|
288 |
|
289 bool S60RadioTunerControl::isAvailable() const |
|
290 { |
|
291 return m_available; |
|
292 } |
|
293 |
|
294 QtMultimediaKit::AvailabilityError S60RadioTunerControl::availabilityError() const |
|
295 { |
|
296 if (m_available) |
|
297 return QtMultimediaKit::NoError; |
|
298 else |
|
299 return QtMultimediaKit::ResourceError; |
|
300 } |
|
301 |
|
302 void S60RadioTunerControl::start() |
|
303 { |
|
304 if (!m_tunerControl) { |
|
305 m_fmTunerUtility->RequestTunerControl(); |
|
306 m_apiTunerState = QRadioTuner::ActiveState; |
|
307 emit stateChanged(m_apiTunerState); |
|
308 } else { |
|
309 m_playerUtility->Play(); |
|
310 m_apiTunerState = QRadioTuner::ActiveState; |
|
311 emit stateChanged(m_apiTunerState); |
|
312 } |
|
313 |
|
314 } |
|
315 |
|
316 void S60RadioTunerControl::stop() |
|
317 { |
|
318 if (m_playerUtility) { |
|
319 m_playerUtility->Stop(); |
|
320 m_apiTunerState = QRadioTuner::StoppedState; |
|
321 emit stateChanged(m_apiTunerState); |
|
322 } |
|
323 } |
|
324 |
|
325 QRadioTuner::Error S60RadioTunerControl::error() const |
|
326 { |
|
327 return m_radioError; |
|
328 } |
|
329 QString S60RadioTunerControl::errorString() const |
|
330 { |
|
331 return m_errorString; |
|
332 } |
|
333 |
|
334 void S60RadioTunerControl::MrpoStateChange(TPlayerState aState, TInt aError) |
|
335 { |
|
336 if (aError == KErrNone){ |
|
337 m_radioError = QRadioTuner::NoError; |
|
338 if (aState == ERadioPlayerIdle) { |
|
339 m_apiTunerState = QRadioTuner::ActiveState; |
|
340 } else if (aState == ERadioPlayerPlaying) { |
|
341 m_apiTunerState = QRadioTuner::ActiveState; |
|
342 } |
|
343 } |
|
344 emit stateChanged(m_apiTunerState); |
|
345 } |
|
346 |
|
347 void S60RadioTunerControl::MrpoVolumeChange(TInt aVolume) |
|
348 { |
|
349 m_vol = aVolume; |
|
350 emit volumeChanged(m_vol); |
|
351 } |
|
352 |
|
353 void S60RadioTunerControl::MrpoMuteChange(TBool aMute) |
|
354 { |
|
355 m_muted = aMute; |
|
356 emit mutedChanged(m_muted); |
|
357 } |
|
358 |
|
359 void S60RadioTunerControl::MrpoBalanceChange(TInt aLeftPercentage, TInt aRightPercentage) |
|
360 { |
|
361 // no actions |
|
362 } |
|
363 |
|
364 void S60RadioTunerControl::MrftoRequestTunerControlComplete(TInt aError) |
|
365 { |
|
366 if (aError == KErrNone) { |
|
367 m_playerUtility->GetMaxVolume(m_maxVolume); |
|
368 m_volMultiplier = float(m_maxVolume)/float(100); |
|
369 m_radioError = QRadioTuner::NoError; |
|
370 m_tunerControl = true; |
|
371 m_available = true; |
|
372 m_fmTunerUtility->SetFrequency(m_currentFreq); |
|
373 m_playerUtility->Play(); |
|
374 int signal = signalStrength(); |
|
375 if (m_signal != signal) { |
|
376 emit signalStrengthChanged(signal); |
|
377 m_signal = signal; |
|
378 } |
|
379 |
|
380 } else if (aError == KFmRadioErrAntennaNotConnected) { |
|
381 m_radioError = QRadioTuner::OpenError; |
|
382 } else if (aError == KErrAlreadyExists){ |
|
383 m_radioError = QRadioTuner::ResourceError; |
|
384 } else if (aError == KFmRadioErrFrequencyOutOfBandRange) { |
|
385 m_radioError = QRadioTuner::OutOfRangeError; |
|
386 }else{ |
|
387 m_radioError = QRadioTuner::OpenError; |
|
388 } |
|
389 |
|
390 } |
|
391 |
|
392 void S60RadioTunerControl::MrftoSetFrequencyRangeComplete(TInt aError) |
|
393 { |
|
394 if (aError == KFmRadioErrFrequencyOutOfBandRange || KFmRadioErrFrequencyNotValid) { |
|
395 m_radioError = QRadioTuner::OutOfRangeError; |
|
396 } else if (aError == KFmRadioErrHardwareFaulty || KFmRadioErrOfflineMode) { |
|
397 m_radioError = QRadioTuner::OpenError; |
|
398 } |
|
399 } |
|
400 |
|
401 void S60RadioTunerControl::MrftoSetFrequencyComplete(TInt aError) |
|
402 { |
|
403 if (aError == KErrNone) { |
|
404 m_radioError = QRadioTuner::NoError; |
|
405 } else if (aError == KFmRadioErrFrequencyOutOfBandRange || KFmRadioErrFrequencyNotValid) { |
|
406 m_radioError = QRadioTuner::OutOfRangeError; |
|
407 } else if (aError == KFmRadioErrHardwareFaulty || KFmRadioErrOfflineMode) { |
|
408 m_radioError = QRadioTuner::OpenError; |
|
409 } |
|
410 } |
|
411 |
|
412 void S60RadioTunerControl::MrftoStationSeekComplete(TInt aError, TInt aFrequency) |
|
413 { |
|
414 m_scanning = false; |
|
415 if (aError == KErrNone) { |
|
416 m_radioError = QRadioTuner::NoError; |
|
417 m_currentFreq = aFrequency; |
|
418 } else { |
|
419 m_radioError = QRadioTuner::OpenError; |
|
420 } |
|
421 } |
|
422 |
|
423 void S60RadioTunerControl::MrftoFmTransmitterStatusChange(TBool aActive) |
|
424 { |
|
425 //no actions |
|
426 } |
|
427 |
|
428 void S60RadioTunerControl::MrftoAntennaStatusChange(TBool aAttached) |
|
429 { |
|
430 if (aAttached && m_tunerControl) { |
|
431 m_playerUtility->Play(); |
|
432 } |
|
433 } |
|
434 |
|
435 void S60RadioTunerControl::MrftoOfflineModeStatusChange(TBool /*aOfflineMode*/) |
|
436 { |
|
437 |
|
438 } |
|
439 |
|
440 void S60RadioTunerControl::MrftoFrequencyRangeChange(TFmRadioFrequencyRange aBand /*, TInt aMinFreq, TInt aMaxFreq*/) |
|
441 { |
|
442 if (aBand == EFmRangeEuroAmerica) { |
|
443 setBand(QRadioTuner::FM); |
|
444 } |
|
445 } |
|
446 |
|
447 void S60RadioTunerControl::MrftoFrequencyChange(TInt aNewFrequency) |
|
448 { |
|
449 m_currentFreq = aNewFrequency; |
|
450 emit frequencyChanged(m_currentFreq); |
|
451 |
|
452 int signal = signalStrength(); |
|
453 if (m_signal != signal) { |
|
454 emit signalStrengthChanged(signal); |
|
455 m_signal = signal; |
|
456 } |
|
457 } |
|
458 |
|
459 void S60RadioTunerControl::MrftoForcedMonoChange(TBool aForcedMono) |
|
460 { |
|
461 if (aForcedMono) { |
|
462 m_stereoMode = QRadioTuner::ForceMono; |
|
463 } else { |
|
464 m_stereoMode = QRadioTuner::ForceStereo; |
|
465 } |
|
466 emit stereoStatusChanged(!aForcedMono); |
|
467 } |
|
468 |
|
469 void S60RadioTunerControl::MrftoSquelchChange(TBool aSquelch) |
|
470 { |
|
471 // no actions |
|
472 } |