|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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_31.h" |
|
43 #include "s60radiotunerservice.h" |
|
44 |
|
45 #include <QtCore/qdebug.h> |
|
46 #include <QFile> |
|
47 |
|
48 // from AudioPreference.h |
|
49 const TInt KAudioPriorityFMRadio = 79; |
|
50 const TUint KAudioPrefRadioAudioEvent = 0x03000001; |
|
51 |
|
52 S60RadioTunerControl::S60RadioTunerControl(QObject *parent) |
|
53 : QRadioTunerControl(parent) |
|
54 , m_error(0) |
|
55 , m_tunerState(0) |
|
56 , m_apiTunerState(QRadioTuner::StoppedState) |
|
57 , m_audioInitializationComplete(false) |
|
58 , m_radioError(QRadioTuner::NoError) |
|
59 , m_muted(false) |
|
60 , m_isStereo(true) |
|
61 , m_stereoMode(QRadioTuner::Auto) |
|
62 , m_signal(0) |
|
63 , m_currentBand(QRadioTuner::FM) |
|
64 , m_currentFreq(87500000) |
|
65 , m_scanning(false) |
|
66 , m_vol(100) |
|
67 { |
|
68 initRadio(); |
|
69 } |
|
70 |
|
71 S60RadioTunerControl::~S60RadioTunerControl() |
|
72 { |
|
73 if (m_tunerUtility) { |
|
74 m_tunerUtility->Close(); |
|
75 m_tunerUtility->CancelNotifyChange(); |
|
76 m_tunerUtility->CancelNotifySignalStrength(); |
|
77 m_tunerUtility->CancelNotifyStereoChange(); |
|
78 delete m_tunerUtility; |
|
79 } |
|
80 if (m_audioPlayerUtility) { |
|
81 m_audioPlayerUtility = NULL; |
|
82 } |
|
83 } |
|
84 |
|
85 bool S60RadioTunerControl::initRadio() |
|
86 { |
|
87 m_available = false; |
|
88 |
|
89 TRAPD(tunerError, m_tunerUtility = CMMTunerUtility::NewL(*this, CMMTunerUtility::ETunerBandFm, 1, |
|
90 CMMTunerUtility::ETunerAccessPriorityNormal)); |
|
91 if (tunerError != KErrNone) { |
|
92 m_radioError = QRadioTuner::OpenError; |
|
93 return m_available; |
|
94 } |
|
95 |
|
96 TRAPD(playerError, m_audioPlayerUtility = m_tunerUtility->TunerPlayerUtilityL(*this)); |
|
97 if (playerError != KErrNone) { |
|
98 m_radioError = QRadioTuner::OpenError; |
|
99 return m_available; |
|
100 } |
|
101 |
|
102 TRAPD(initializeError, m_audioPlayerUtility->InitializeL(KAudioPriorityFMRadio, |
|
103 TMdaPriorityPreference(KAudioPrefRadioAudioEvent))); |
|
104 if (initializeError != KErrNone) { |
|
105 m_radioError = QRadioTuner::OpenError; |
|
106 return m_available; |
|
107 } |
|
108 |
|
109 m_tunerUtility->NotifyChange(*this); |
|
110 m_tunerUtility->NotifyStereoChange(*this); |
|
111 m_tunerUtility->NotifySignalStrength(*this); |
|
112 setVolume(m_audioPlayerUtility->MaxVolume()/2); |
|
113 |
|
114 TFrequency freq(m_currentFreq); |
|
115 m_tunerUtility->Tune(freq); |
|
116 |
|
117 m_available = true; |
|
118 |
|
119 return m_available; |
|
120 } |
|
121 |
|
122 void S60RadioTunerControl::start() |
|
123 { |
|
124 if (!m_audioInitializationComplete) { |
|
125 TFrequency freq(m_currentFreq); |
|
126 m_tunerUtility->Tune(freq); |
|
127 } else { |
|
128 m_audioPlayerUtility->Play(); |
|
129 } |
|
130 |
|
131 m_apiTunerState = QRadioTuner::ActiveState; |
|
132 emit stateChanged(m_apiTunerState); |
|
133 } |
|
134 |
|
135 void S60RadioTunerControl::stop() |
|
136 { |
|
137 if (m_audioPlayerUtility) { |
|
138 m_audioPlayerUtility->Stop(); |
|
139 m_apiTunerState = QRadioTuner::StoppedState; |
|
140 emit stateChanged(m_apiTunerState); |
|
141 } |
|
142 } |
|
143 |
|
144 QRadioTuner::State S60RadioTunerControl::state() const |
|
145 { |
|
146 return m_apiTunerState; |
|
147 } |
|
148 |
|
149 QRadioTuner::Band S60RadioTunerControl::band() const |
|
150 { |
|
151 return m_currentBand; |
|
152 } |
|
153 |
|
154 bool S60RadioTunerControl::isBandSupported(QRadioTuner::Band b) const |
|
155 { |
|
156 if(b == QRadioTuner::FM) |
|
157 return true; |
|
158 else if(b == QRadioTuner::LW) |
|
159 return false; |
|
160 else if(b == QRadioTuner::AM) |
|
161 return true; |
|
162 else if(b == QRadioTuner::SW) |
|
163 return false; |
|
164 else |
|
165 return false; |
|
166 } |
|
167 |
|
168 void S60RadioTunerControl::setBand(QRadioTuner::Band b) |
|
169 { |
|
170 QRadioTuner::Band tempBand = b; |
|
171 if (tempBand != m_currentBand) { |
|
172 m_currentBand = b; |
|
173 emit bandChanged(m_currentBand); |
|
174 } |
|
175 } |
|
176 |
|
177 int S60RadioTunerControl::frequency() const |
|
178 { |
|
179 return m_currentFreq; |
|
180 } |
|
181 |
|
182 void S60RadioTunerControl::setFrequency(int frequency) |
|
183 { |
|
184 m_currentFreq = frequency; |
|
185 TFrequency freq(m_currentFreq); |
|
186 m_tunerUtility->Tune(freq); |
|
187 } |
|
188 |
|
189 int S60RadioTunerControl::frequencyStep(QRadioTuner::Band b) const |
|
190 { |
|
191 int step = 0; |
|
192 |
|
193 if(b == QRadioTuner::FM) |
|
194 step = 100000; // 100kHz steps |
|
195 else if(b == QRadioTuner::LW) |
|
196 step = 1000; // 1kHz steps |
|
197 else if(b == QRadioTuner::AM) |
|
198 step = 1000; // 1kHz steps |
|
199 else if(b == QRadioTuner::SW) |
|
200 step = 500; // 500Hz steps |
|
201 |
|
202 return step; |
|
203 } |
|
204 |
|
205 QPair<int,int> S60RadioTunerControl::frequencyRange(QRadioTuner::Band band) const |
|
206 { |
|
207 TFrequency bottomFreq; |
|
208 TFrequency topFreq; |
|
209 int bandError = KErrNone; |
|
210 |
|
211 if (m_tunerUtility){ |
|
212 bandError = m_tunerUtility->GetFrequencyBandRange(bottomFreq, topFreq); |
|
213 if (!bandError) { |
|
214 return qMakePair<int,int>(bottomFreq.iFrequency, topFreq.iFrequency); |
|
215 } |
|
216 } |
|
217 return qMakePair<int,int>(0,0); |
|
218 } |
|
219 |
|
220 CMMTunerUtility::TTunerBand S60RadioTunerControl::getNativeBand(QRadioTuner::Band b) const |
|
221 { |
|
222 // api match to native s60 bands |
|
223 if (b == QRadioTuner::AM) |
|
224 return CMMTunerUtility::ETunerBandAm; |
|
225 else if (b == QRadioTuner::FM) |
|
226 return CMMTunerUtility::ETunerBandFm; |
|
227 else if (b == QRadioTuner::LW) |
|
228 return CMMTunerUtility::ETunerBandLw; |
|
229 else |
|
230 return CMMTunerUtility::ETunerNoBand; |
|
231 } |
|
232 |
|
233 bool S60RadioTunerControl::isStereo() const |
|
234 { |
|
235 return m_isStereo; |
|
236 } |
|
237 |
|
238 QRadioTuner::StereoMode S60RadioTunerControl::stereoMode() const |
|
239 { |
|
240 return m_stereoMode; |
|
241 } |
|
242 |
|
243 void S60RadioTunerControl::setStereoMode(QRadioTuner::StereoMode mode) |
|
244 { |
|
245 m_stereoMode = mode; |
|
246 if (m_tunerUtility) { |
|
247 if (QRadioTuner::ForceMono == mode) |
|
248 m_tunerUtility->ForceMonoReception(true); |
|
249 else |
|
250 m_tunerUtility->ForceMonoReception(false); |
|
251 } |
|
252 } |
|
253 |
|
254 int S60RadioTunerControl::signalStrength() const |
|
255 { |
|
256 // return value is a percentage value |
|
257 if (m_tunerUtility) { |
|
258 TInt maxSignalStrength; |
|
259 TInt currentSignalStrength; |
|
260 m_error = m_tunerUtility->GetMaxSignalStrength(maxSignalStrength); |
|
261 if (m_error == KErrNone) { |
|
262 m_error = m_tunerUtility->GetSignalStrength(currentSignalStrength); |
|
263 if (m_error == KErrNone) { |
|
264 if (maxSignalStrength == 0 || currentSignalStrength == 0) { |
|
265 return 0; |
|
266 } |
|
267 m_signal = (currentSignalStrength/maxSignalStrength)*100; |
|
268 } |
|
269 } |
|
270 } |
|
271 return m_signal; |
|
272 } |
|
273 |
|
274 int S60RadioTunerControl::volume() const |
|
275 { |
|
276 return m_vol; |
|
277 } |
|
278 |
|
279 void S60RadioTunerControl::setVolume(int volume) |
|
280 { |
|
281 if (m_audioPlayerUtility) { |
|
282 m_vol = volume; |
|
283 TInt error = m_audioPlayerUtility->SetVolume(m_vol); |
|
284 emit volumeChanged(m_vol); |
|
285 } |
|
286 } |
|
287 |
|
288 bool S60RadioTunerControl::isMuted() const |
|
289 { |
|
290 return m_muted; |
|
291 } |
|
292 |
|
293 void S60RadioTunerControl::setMuted(bool muted) |
|
294 { |
|
295 if (m_audioPlayerUtility && m_audioInitializationComplete) { |
|
296 m_muted = muted; |
|
297 m_audioPlayerUtility->Mute(m_muted); |
|
298 emit mutedChanged(m_muted); |
|
299 } |
|
300 } |
|
301 |
|
302 bool S60RadioTunerControl::isSearching() const |
|
303 { |
|
304 if (m_tunerUtility) { |
|
305 TUint32 tempState; |
|
306 m_tunerUtility->GetState(tempState); |
|
307 if (tempState == CMMTunerUtility::ETunerStateRetuning || m_scanning) { |
|
308 return true; |
|
309 } else |
|
310 return false; |
|
311 } |
|
312 return true; |
|
313 } |
|
314 |
|
315 void S60RadioTunerControl::cancelSearch() |
|
316 { |
|
317 m_tunerUtility->CancelRetune(); |
|
318 m_scanning = false; |
|
319 emit searchingChanged(false); |
|
320 } |
|
321 |
|
322 void S60RadioTunerControl::searchForward() |
|
323 { |
|
324 m_scanning = true; |
|
325 setVolume(m_vol); |
|
326 m_tunerUtility->StationSeek(CMMTunerUtility::ESearchDirectionUp); |
|
327 emit searchingChanged(true); |
|
328 } |
|
329 |
|
330 void S60RadioTunerControl::searchBackward() |
|
331 { |
|
332 m_scanning = true; |
|
333 setVolume(m_vol); |
|
334 m_tunerUtility->StationSeek(CMMTunerUtility::ESearchDirectionDown); |
|
335 emit searchingChanged(true); |
|
336 } |
|
337 |
|
338 bool S60RadioTunerControl::isValid() const |
|
339 { |
|
340 return m_available; |
|
341 } |
|
342 |
|
343 bool S60RadioTunerControl::isAvailable() const |
|
344 { |
|
345 return m_available; |
|
346 } |
|
347 |
|
348 QtMedia::AvailabilityError S60RadioTunerControl::availabilityError() const |
|
349 { |
|
350 if (m_available) |
|
351 return QtMedia::NoError; |
|
352 else |
|
353 return QtMedia::ResourceError; |
|
354 } |
|
355 |
|
356 QRadioTuner::Error S60RadioTunerControl::error() const |
|
357 { |
|
358 return m_radioError; |
|
359 } |
|
360 |
|
361 QString S60RadioTunerControl::errorString() const |
|
362 { |
|
363 return m_errorString; |
|
364 } |
|
365 |
|
366 void S60RadioTunerControl::MToTuneComplete(TInt aError) |
|
367 { |
|
368 if (aError == KErrNone) { |
|
369 m_scanning = false; |
|
370 m_audioPlayerUtility->Play(); |
|
371 if (!m_audioInitializationComplete) { |
|
372 TRAPD(initializeError, m_audioPlayerUtility->InitializeL(KAudioPriorityFMRadio, |
|
373 TMdaPriorityPreference(KAudioPrefRadioAudioEvent))); |
|
374 if (initializeError != KErrNone) { |
|
375 m_radioError = QRadioTuner::OpenError; |
|
376 } |
|
377 } |
|
378 } |
|
379 } |
|
380 |
|
381 void S60RadioTunerControl::MTcoFrequencyChanged(const TFrequency& aOldFrequency, const TFrequency& aNewFrequency) |
|
382 { |
|
383 m_currentFreq = aNewFrequency.iFrequency; |
|
384 m_scanning = false; |
|
385 emit frequencyChanged(m_currentFreq); |
|
386 } |
|
387 |
|
388 void S60RadioTunerControl::MTcoStateChanged(const TUint32& aOldState, const TUint32& aNewState) |
|
389 { |
|
390 if (aNewState == CMMTunerUtility::ETunerStateActive) { |
|
391 m_apiTunerState = QRadioTuner::ActiveState; |
|
392 } |
|
393 if (aNewState == CMMTunerUtility::ETunerStatePlaying) { |
|
394 m_apiTunerState = QRadioTuner::ActiveState; |
|
395 } |
|
396 if (aOldState != aNewState){ |
|
397 emit stateChanged(m_apiTunerState); |
|
398 } |
|
399 } |
|
400 |
|
401 void S60RadioTunerControl::MTcoAntennaDetached() |
|
402 { |
|
403 // no actions |
|
404 } |
|
405 |
|
406 void S60RadioTunerControl::MTcoAntennaAttached() |
|
407 { |
|
408 // no actions |
|
409 } |
|
410 |
|
411 void S60RadioTunerControl::FlightModeChanged(TBool aFlightMode) |
|
412 { |
|
413 // no actions |
|
414 } |
|
415 |
|
416 void S60RadioTunerControl::MTsoStereoReceptionChanged(TBool aStereo) |
|
417 { |
|
418 m_isStereo = aStereo; |
|
419 emit stereoStatusChanged(aStereo); |
|
420 } |
|
421 |
|
422 void S60RadioTunerControl::MTsoForcedMonoChanged(TBool aForcedMono) |
|
423 { |
|
424 if (aForcedMono) { |
|
425 m_stereoMode = QRadioTuner::ForceMono; |
|
426 } |
|
427 } |
|
428 |
|
429 void S60RadioTunerControl::MssoSignalStrengthChanged(TInt aNewSignalStrength) |
|
430 { |
|
431 m_signal = aNewSignalStrength; |
|
432 emit signalStrengthChanged(m_signal); |
|
433 } |
|
434 |
|
435 void S60RadioTunerControl::MTapoInitializeComplete(TInt aError) |
|
436 { |
|
437 if (aError == KErrNone) { |
|
438 m_audioInitializationComplete = true; |
|
439 m_available = true; |
|
440 m_audioPlayerUtility->Play(); |
|
441 m_apiTunerState = QRadioTuner::ActiveState; |
|
442 emit stateChanged(m_apiTunerState); |
|
443 } else if (aError != KErrNone) { |
|
444 m_radioError = QRadioTuner::OpenError; |
|
445 } |
|
446 } |
|
447 |
|
448 void S60RadioTunerControl::MTapoPlayEvent(TEventType aEvent, TInt aError, TAny* aAdditionalInfo) |
|
449 { |
|
450 // no actions |
|
451 } |
|
452 |
|
453 |
|
454 |