1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <barsread.h> |
|
20 #include <coemain.h> |
|
21 #include <bautils.h> |
|
22 #include <data_caging_path_literals.hrh> |
|
23 #include <fmradioenginesettings.rsg> |
|
24 #include <centralrepository.h> |
|
25 |
|
26 // User includes |
|
27 #include "radiointernalcrkeys.h" |
|
28 #include "radioenginedef.h" |
|
29 #include "cradioenginesettings.h" |
|
30 #include "cradiosettingsimp.h" |
|
31 #include "mradiosettingsobserver.h" |
|
32 #include "cradioenginelogger.h" |
|
33 |
|
34 // This has to be the last include. |
|
35 #ifdef STUB_CONSTELLATION |
|
36 # include <RadioStubManager.h> |
|
37 #endif //STUB_CONSTELLATION |
|
38 |
|
39 |
|
40 /** |
|
41 * On/Off type flags used by TBitFlags. |
|
42 */ |
|
43 enum TFlagValues |
|
44 { |
|
45 EHeadsetVolMuted = 1 << 0 |
|
46 ,ESpeakerVolMuted = 1 << 1 |
|
47 ,EPowerOn = 1 << 2 |
|
48 ,EStereoOutput = 1 << 3 |
|
49 ,EHeadsetAudioRoute = 1 << 4 |
|
50 }; |
|
51 |
|
52 // ======== LOCAL FUNCTIONS ======== |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 // Normalize return value from TBitFlags to 1 or 0 just in case |
|
56 // Two negations: 16 => 0 => 1 |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 static TBool NormalizeBool( TBool aBool ) |
|
60 { |
|
61 // Normalize return value from TBitFlags to 1 or 0 just in case |
|
62 // Two negations: 16 => 0 => 1 |
|
63 return !( !aBool ); |
|
64 } |
|
65 |
|
66 |
|
67 // ======== MEMBER FUNCTIONS ======== |
|
68 |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 // --------------------------------------------------------------------------- |
|
72 // |
|
73 CRadioEngineSettings* CRadioEngineSettings::NewL( CRadioSettingsImp& aRadioSettingsImp ) |
|
74 { |
|
75 LEVEL3( LOG_METHOD_AUTO ); |
|
76 CRadioEngineSettings* self = new ( ELeave ) CRadioEngineSettings( aRadioSettingsImp ); |
|
77 CleanupStack::PushL( self ); |
|
78 self->ConstructL(); |
|
79 CleanupStack::Pop( self ); |
|
80 return self; |
|
81 } |
|
82 |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 void CRadioEngineSettings::ConstructL() |
|
88 { |
|
89 LEVEL3( LOG_METHOD_AUTO ); |
|
90 iRepository = CRepository::NewL( KRadioCRUid ); |
|
91 |
|
92 InitializeRegionsL(); |
|
93 |
|
94 InitializeDataHolders(); |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 CRadioEngineSettings::CRadioEngineSettings( CRadioSettingsImp& aRadioSettingsImp ) |
|
102 : iRadioSettingsImp( aRadioSettingsImp ) |
|
103 { |
|
104 LEVEL3( LOG_METHOD_AUTO ); |
|
105 } |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 CRadioEngineSettings::~CRadioEngineSettings() |
|
112 { |
|
113 LEVEL3( LOG_METHOD_AUTO ); |
|
114 iRegions.ResetAndDestroy(); |
|
115 iRegions.Close(); |
|
116 iResFile.Close(); |
|
117 delete iRepository; |
|
118 } |
|
119 |
|
120 // --------------------------------------------------------------------------- |
|
121 // From class MRadioSettingsSetter. |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 void CRadioEngineSettings::SetObserver( MRadioSettingsObserver* aObserver ) |
|
125 { |
|
126 LEVEL3( LOG_METHOD_AUTO ); |
|
127 iObserver = aObserver; |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // From class MRadioSettingsSetter. |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 TInt CRadioEngineSettings::SetHeadsetVolume( TInt aVolume ) |
|
135 { |
|
136 LEVEL3( LOG_METHOD_AUTO ); |
|
137 TInt err = iRepository->Set( KRadioCRHeadsetVolume, aVolume ); |
|
138 if ( !err ) |
|
139 { |
|
140 iHeadsetVolume = aVolume; |
|
141 } |
|
142 return err; |
|
143 } |
|
144 |
|
145 // --------------------------------------------------------------------------- |
|
146 // From class MRadioEngineSettings. |
|
147 // --------------------------------------------------------------------------- |
|
148 // |
|
149 TInt CRadioEngineSettings::HeadsetVolume() const |
|
150 { |
|
151 LEVEL3( LOG_METHOD_AUTO ); |
|
152 return iHeadsetVolume; |
|
153 } |
|
154 |
|
155 // --------------------------------------------------------------------------- |
|
156 // From class MRadioSettingsSetter. |
|
157 // --------------------------------------------------------------------------- |
|
158 // |
|
159 TInt CRadioEngineSettings::SetSpeakerVolume( TInt aVolume ) |
|
160 { |
|
161 LEVEL3( LOG_METHOD_AUTO ); |
|
162 TInt err = iRepository->Set( KRadioCRSpeakerVolume, aVolume ); |
|
163 if ( !err ) |
|
164 { |
|
165 iSpeakerVolume = aVolume; |
|
166 } |
|
167 return err; |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // From class MRadioEngineSettings. |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 TInt CRadioEngineSettings::SpeakerVolume() const |
|
175 { |
|
176 LEVEL3( LOG_METHOD_AUTO ); |
|
177 return iSpeakerVolume; |
|
178 } |
|
179 |
|
180 // --------------------------------------------------------------------------- |
|
181 // From class MRadioSettingsSetter. |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 TInt CRadioEngineSettings::SetVolume( TInt aVolume ) |
|
185 { |
|
186 LEVEL3( LOG_METHOD_AUTO ); |
|
187 if ( AudioRoute() == RadioEngine::ERadioHeadset ) |
|
188 { |
|
189 return SetHeadsetVolume( aVolume ); |
|
190 } |
|
191 else |
|
192 { |
|
193 return SetSpeakerVolume( aVolume ); |
|
194 } |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // From class MRadioEngineSettings. |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 TInt CRadioEngineSettings::Volume() const |
|
202 { |
|
203 LEVEL3( LOG_METHOD_AUTO ); |
|
204 if ( AudioRoute() == RadioEngine::ERadioHeadset ) |
|
205 { |
|
206 return HeadsetVolume(); |
|
207 } |
|
208 else |
|
209 { |
|
210 return SpeakerVolume(); |
|
211 } |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // From class MRadioSettingsSetter. |
|
216 // |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 TInt CRadioEngineSettings::SetOutputMode( TInt aOutputMode ) |
|
220 { |
|
221 LEVEL3( LOG_METHOD_AUTO ); |
|
222 TInt err = iRepository->Set( KRadioCROutputMode, aOutputMode ); |
|
223 if ( !err ) |
|
224 { |
|
225 iFlags.Assign( EStereoOutput, aOutputMode == RadioEngine::ERadioStereo ); |
|
226 } |
|
227 return err; |
|
228 } |
|
229 |
|
230 // --------------------------------------------------------------------------- |
|
231 // From class MRadioEngineSettings. |
|
232 // |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 TInt CRadioEngineSettings::OutputMode() const |
|
236 { |
|
237 LEVEL3( LOG_METHOD_AUTO ); |
|
238 return iFlags.IsSet( EStereoOutput ) ? RadioEngine::ERadioStereo : RadioEngine::ERadioMono; |
|
239 } |
|
240 |
|
241 // --------------------------------------------------------------------------- |
|
242 // From class MRadioSettingsSetter. |
|
243 // Stores the radio audio route ( headset/ihf ) to use. |
|
244 // --------------------------------------------------------------------------- |
|
245 // |
|
246 TInt CRadioEngineSettings::SetAudioRoute( TInt aAudioRoute ) |
|
247 { |
|
248 LEVEL3( LOG_METHOD_AUTO ); |
|
249 TInt err = iRepository->Set( KRadioCRAudioRoute, aAudioRoute ); |
|
250 if ( !err ) |
|
251 { |
|
252 iFlags.Assign( EHeadsetAudioRoute, aAudioRoute == RadioEngine::ERadioHeadset ); |
|
253 } |
|
254 return err; |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // From class MRadioEngineSettings. |
|
259 // Retrieves the radio audio route in use. |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 TInt CRadioEngineSettings::AudioRoute() const |
|
263 { |
|
264 LEVEL3( LOG_METHOD_AUTO ); |
|
265 return iFlags.IsSet( EHeadsetAudioRoute ) ? RadioEngine::ERadioHeadset : RadioEngine::ERadioSpeaker; |
|
266 } |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // From class MRadioSettingsSetter. |
|
270 // |
|
271 // --------------------------------------------------------------------------- |
|
272 // |
|
273 TInt CRadioEngineSettings::SetHeadsetVolMuted( TBool aMuted ) |
|
274 { |
|
275 LEVEL3( LOG_METHOD_AUTO ); |
|
276 return SetFlagValue( KRadioCRHeadsetMuteState, EHeadsetVolMuted, aMuted ); |
|
277 } |
|
278 |
|
279 // --------------------------------------------------------------------------- |
|
280 // From class MRadioEngineSettings. |
|
281 // |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 TBool CRadioEngineSettings::IsHeadsetVolMuted() const |
|
285 { |
|
286 LEVEL3( LOG_METHOD_AUTO ); |
|
287 return NormalizeBool( iFlags.IsSet( EHeadsetVolMuted ) ); |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------------------------- |
|
291 // From class MRadioSettingsSetter. |
|
292 // |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 TInt CRadioEngineSettings::SetSpeakerVolMuted( TBool aMuted ) |
|
296 { |
|
297 LEVEL3( LOG_METHOD_AUTO ); |
|
298 return SetFlagValue( KRadioCRSpeakerMuteState, ESpeakerVolMuted, aMuted ); |
|
299 } |
|
300 |
|
301 // --------------------------------------------------------------------------- |
|
302 // From class MRadioEngineSettings. |
|
303 // |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 TBool CRadioEngineSettings::IsSpeakerVolMuted() const |
|
307 { |
|
308 LEVEL3( LOG_METHOD_AUTO ); |
|
309 return NormalizeBool( iFlags.IsSet( ESpeakerVolMuted ) ); |
|
310 } |
|
311 |
|
312 // --------------------------------------------------------------------------- |
|
313 // From class MRadioSettingsSetter. |
|
314 // |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 TInt CRadioEngineSettings::SetVolMuted( TBool aMuted ) |
|
318 { |
|
319 LEVEL3( LOG_METHOD_AUTO ); |
|
320 if ( AudioRoute() == RadioEngine::ERadioHeadset ) |
|
321 { |
|
322 return SetHeadsetVolMuted( aMuted ); |
|
323 } |
|
324 else |
|
325 { |
|
326 return SetSpeakerVolMuted( aMuted ); |
|
327 } |
|
328 } |
|
329 |
|
330 // --------------------------------------------------------------------------- |
|
331 // From class MRadioEngineSettings. |
|
332 // |
|
333 // --------------------------------------------------------------------------- |
|
334 // |
|
335 TBool CRadioEngineSettings::IsVolMuted() const |
|
336 { |
|
337 LEVEL3( LOG_METHOD_AUTO ); |
|
338 if ( AudioRoute() == RadioEngine::ERadioHeadset ) |
|
339 { |
|
340 return IsHeadsetVolMuted(); |
|
341 } |
|
342 else |
|
343 { |
|
344 return IsSpeakerVolMuted(); |
|
345 } |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // From class MRadioSettingsSetter. |
|
350 // |
|
351 // --------------------------------------------------------------------------- |
|
352 // |
|
353 TInt CRadioEngineSettings::SetPowerOn( TBool aPowerState ) |
|
354 { |
|
355 LEVEL3( LOG_METHOD_AUTO ); |
|
356 return SetFlagValue( KRadioCRRadioPowerState, EPowerOn, aPowerState ); |
|
357 } |
|
358 |
|
359 // --------------------------------------------------------------------------- |
|
360 // From class MRadioEngineSettings. |
|
361 // |
|
362 // --------------------------------------------------------------------------- |
|
363 // |
|
364 TBool CRadioEngineSettings::IsPowerOn() const |
|
365 { |
|
366 LEVEL3( LOG_METHOD_AUTO ); |
|
367 return NormalizeBool( iFlags.IsSet( EPowerOn ) ); |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 // From class MRadioSettingsSetter. |
|
372 // |
|
373 // --------------------------------------------------------------------------- |
|
374 // |
|
375 TInt CRadioEngineSettings::SetTunedFrequency( TUint32 aFrequency ) |
|
376 { |
|
377 LEVEL3( LOG_METHOD_AUTO ); |
|
378 TInt err = iRepository->Set( KRadioCRTunedFrequency, static_cast<TInt>( aFrequency ) ); |
|
379 if ( !err ) |
|
380 { |
|
381 iFrequency = aFrequency; |
|
382 } |
|
383 return err; |
|
384 } |
|
385 |
|
386 // --------------------------------------------------------------------------- |
|
387 // From class MRadioEngineSettings. |
|
388 // |
|
389 // --------------------------------------------------------------------------- |
|
390 // |
|
391 TUint32 CRadioEngineSettings::TunedFrequency() const |
|
392 { |
|
393 LEVEL3( LOG_METHOD_AUTO ); |
|
394 return iFrequency; |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------------------------- |
|
398 // From class MRadioEngineSettings. |
|
399 // |
|
400 // --------------------------------------------------------------------------- |
|
401 // |
|
402 TInt CRadioEngineSettings::DefaultMinVolumeLevel() const |
|
403 { |
|
404 LEVEL3( LOG_METHOD_AUTO ); |
|
405 return iDefaultMinVolume; |
|
406 } |
|
407 |
|
408 // --------------------------------------------------------------------------- |
|
409 // From class MRadioEngineSettings. |
|
410 // |
|
411 // --------------------------------------------------------------------------- |
|
412 // |
|
413 TInt CRadioEngineSettings::CountRegions() const |
|
414 { |
|
415 LEVEL3( LOG_METHOD_AUTO ); |
|
416 return iRegions.Count(); |
|
417 } |
|
418 |
|
419 // --------------------------------------------------------------------------- |
|
420 // From class MRadioEngineSettings. |
|
421 // |
|
422 // --------------------------------------------------------------------------- |
|
423 // |
|
424 CRadioRegion& CRadioEngineSettings::Region( TInt aIndex ) const |
|
425 { |
|
426 LEVEL3( LOG_METHOD_AUTO ); |
|
427 if ( aIndex == KErrNotFound ) |
|
428 { |
|
429 aIndex = RegionIndexForId( DefaultRegion() ); |
|
430 } |
|
431 |
|
432 return *iRegions[aIndex]; |
|
433 } |
|
434 |
|
435 // --------------------------------------------------------------------------- |
|
436 // From class MRadioEngineSettings. |
|
437 // |
|
438 // --------------------------------------------------------------------------- |
|
439 // |
|
440 TRadioRegion CRadioEngineSettings::RegionId() const |
|
441 { |
|
442 LEVEL3( LOG_METHOD_AUTO ); |
|
443 return iRegionId; |
|
444 } |
|
445 |
|
446 // --------------------------------------------------------------------------- |
|
447 // From class MRadioEngineSettings. |
|
448 // |
|
449 // --------------------------------------------------------------------------- |
|
450 // |
|
451 TRadioRegion CRadioEngineSettings::DefaultRegion() const |
|
452 { |
|
453 LEVEL3( LOG_METHOD_AUTO ); |
|
454 return iDefaultRegion; |
|
455 } |
|
456 |
|
457 // --------------------------------------------------------------------------- |
|
458 // From class MRadioEngineSettings. |
|
459 // |
|
460 // --------------------------------------------------------------------------- |
|
461 // |
|
462 TPtrC CRadioEngineSettings::NetworkId() const |
|
463 { |
|
464 LEVEL3( LOG_METHOD_AUTO ); |
|
465 return TPtrC( iNetworkId ); |
|
466 } |
|
467 |
|
468 // --------------------------------------------------------------------------- |
|
469 // From class MRadioEngineSettings. |
|
470 // |
|
471 // --------------------------------------------------------------------------- |
|
472 // |
|
473 TPtrC CRadioEngineSettings::CountryCode() const |
|
474 { |
|
475 LEVEL3( LOG_METHOD_AUTO ); |
|
476 return TPtrC( iCountryCode ); |
|
477 } |
|
478 |
|
479 // --------------------------------------------------------------------------- |
|
480 // From class MRadioSettingsSetter. |
|
481 // |
|
482 // --------------------------------------------------------------------------- |
|
483 // |
|
484 TInt CRadioEngineSettings::SetRegionId( TInt aRegion ) |
|
485 { |
|
486 LEVEL3( LOG_METHOD_AUTO ); |
|
487 __ASSERT_ALWAYS( RegionIndexForId( aRegion ) != KErrNotFound, |
|
488 User::Panic( _L( "CRadioEngineSettings" ), KErrArgument ) ); |
|
489 |
|
490 TInt err = iRepository->Set( KRadioCRCurrentRegion, aRegion ); |
|
491 if ( !err ) |
|
492 { |
|
493 iRegionId = static_cast<TRadioRegion>( aRegion ); |
|
494 UpdateCurrentRegionIdx( aRegion ); |
|
495 err = SetTunedFrequency( Region( iCurrentRegionIdx ).MinFrequency() ); |
|
496 } |
|
497 return err; |
|
498 } |
|
499 |
|
500 // --------------------------------------------------------------------------- |
|
501 // From class MRadioSettingsSetter. |
|
502 // |
|
503 // --------------------------------------------------------------------------- |
|
504 // |
|
505 TInt CRadioEngineSettings::SetNetworkId( const TDesC& aNetworkId ) |
|
506 { |
|
507 LEVEL3( LOG_METHOD_AUTO ); |
|
508 iNetworkId.Copy( aNetworkId.Left( iNetworkId.MaxLength() ) ); |
|
509 return iRepository->Set( KRadioCRNetworkId, iNetworkId ); |
|
510 } |
|
511 |
|
512 // --------------------------------------------------------------------------- |
|
513 // From class MRadioSettingsSetter. |
|
514 // |
|
515 // --------------------------------------------------------------------------- |
|
516 // |
|
517 TInt CRadioEngineSettings::SetCountryCode( const TDesC& aCountryCode ) |
|
518 { |
|
519 LEVEL3( LOG_METHOD_AUTO ); |
|
520 iCountryCode.Copy( aCountryCode.Left( iCountryCode.MaxLength() ) ); |
|
521 return iRepository->Set( KRadioCRCountryCode, iCountryCode ); |
|
522 } |
|
523 |
|
524 // --------------------------------------------------------------------------- |
|
525 // From class MRadioEngineSettings. |
|
526 // |
|
527 // --------------------------------------------------------------------------- |
|
528 // |
|
529 TUint32 CRadioEngineSettings::FrequencyStepSize() const |
|
530 { |
|
531 LEVEL3( LOG_METHOD_AUTO ); |
|
532 return Region( iCurrentRegionIdx ).StepSize(); |
|
533 } |
|
534 |
|
535 // --------------------------------------------------------------------------- |
|
536 // From class MRadioEngineSettings. |
|
537 // |
|
538 // --------------------------------------------------------------------------- |
|
539 // |
|
540 TUint32 CRadioEngineSettings::MaxFrequency() const |
|
541 { |
|
542 LEVEL3( LOG_METHOD_AUTO ); |
|
543 return Region( iCurrentRegionIdx ).MaxFrequency(); |
|
544 } |
|
545 |
|
546 // --------------------------------------------------------------------------- |
|
547 // From class MRadioEngineSettings. |
|
548 // |
|
549 // --------------------------------------------------------------------------- |
|
550 // |
|
551 TUint32 CRadioEngineSettings::MinFrequency() const |
|
552 { |
|
553 LEVEL3( LOG_METHOD_AUTO ); |
|
554 return Region( iCurrentRegionIdx ).MinFrequency(); |
|
555 } |
|
556 |
|
557 // --------------------------------------------------------------------------- |
|
558 // From class MRadioEngineSettings. |
|
559 // |
|
560 // --------------------------------------------------------------------------- |
|
561 // |
|
562 TInt CRadioEngineSettings::DecimalCount() const |
|
563 { |
|
564 LEVEL3( LOG_METHOD_AUTO ); |
|
565 return Region( iCurrentRegionIdx ).DecimalCount(); |
|
566 } |
|
567 |
|
568 // --------------------------------------------------------------------------- |
|
569 // Initializes the data holders |
|
570 // --------------------------------------------------------------------------- |
|
571 // |
|
572 void CRadioEngineSettings::InitializeDataHolders() |
|
573 { |
|
574 TInt temp = 0; |
|
575 GetRepositoryValue( KRadioCRHeadsetMuteState, temp, EFalse ); |
|
576 iFlags.Assign( EHeadsetVolMuted, temp ); |
|
577 |
|
578 temp = RadioEngine::ERadioHeadsetDefaultVolume; |
|
579 GetRepositoryValue( KRadioCRHeadsetVolume, temp, temp ); |
|
580 iHeadsetVolume = temp; |
|
581 |
|
582 temp = 0; |
|
583 GetRepositoryValue( KRadioCRSpeakerMuteState, temp, EFalse ); |
|
584 iFlags.Assign( ESpeakerVolMuted, temp ); |
|
585 |
|
586 temp = RadioEngine::ERadioSpeakerDefaultVolume; |
|
587 GetRepositoryValue( KRadioCRSpeakerVolume, temp, temp ); |
|
588 iSpeakerVolume = temp; |
|
589 |
|
590 temp = 0; |
|
591 GetRepositoryValue( KRadioCRRadioPowerState, temp, EFalse ); |
|
592 iFlags.Assign( EPowerOn, temp ); |
|
593 |
|
594 temp = RadioEngine::ERadioStereo; |
|
595 if ( GetRepositoryValue( KRadioCROutputMode, temp, temp ) ) |
|
596 { |
|
597 iFlags.Assign( EStereoOutput, temp == RadioEngine::ERadioStereo ); |
|
598 } |
|
599 |
|
600 temp = RadioEngine::ERadioHeadset; |
|
601 if ( GetRepositoryValue( KRadioCRAudioRoute, temp, temp ) ) |
|
602 { |
|
603 iFlags.Assign( EHeadsetAudioRoute, temp == RadioEngine::ERadioHeadset ); |
|
604 } |
|
605 |
|
606 temp = RadioEngine::ERadioDefaultMinVolume; |
|
607 GetRepositoryValue( KRadioCRDefaultMinVolumeLevel, temp, temp ); |
|
608 iDefaultMinVolume = temp; |
|
609 |
|
610 temp = ERadioRegionDefault; |
|
611 GetRepositoryValue( KRadioCRDefaultRegion, temp, temp ); |
|
612 iDefaultRegion = static_cast<TRadioRegion>( temp ); |
|
613 |
|
614 temp = iDefaultRegion; |
|
615 GetRepositoryValue( KRadioCRCurrentRegion, temp, temp ); |
|
616 iRegionId = static_cast<TRadioRegion>( temp ); |
|
617 UpdateCurrentRegionIdx( iRegionId ); |
|
618 |
|
619 temp = MinFrequency(); |
|
620 GetRepositoryValue( KRadioCRTunedFrequency, temp, temp ); |
|
621 iFrequency = static_cast<TUint32>( temp ); |
|
622 } |
|
623 |
|
624 // --------------------------------------------------------------------------- |
|
625 // Gets a repository value and sets the default value if the key is not found |
|
626 // --------------------------------------------------------------------------- |
|
627 // |
|
628 TBool CRadioEngineSettings::GetRepositoryValue( int aKey, TInt& aValue, TInt aDefault ) |
|
629 { |
|
630 TInt temp = 0; |
|
631 TInt err = iRepository->Get( aKey, temp ); |
|
632 if ( !err ) |
|
633 { |
|
634 aValue = temp; |
|
635 return ETrue; |
|
636 } |
|
637 else if ( err == KErrNotFound ) |
|
638 { |
|
639 if ( iRepository->Set( aKey, aDefault ) == KErrNone ) |
|
640 { |
|
641 aValue = aDefault; |
|
642 return ETrue; |
|
643 } |
|
644 } |
|
645 return EFalse; |
|
646 } |
|
647 |
|
648 // --------------------------------------------------------------------------- |
|
649 // Sets a boolean value to cenrep and data holder |
|
650 // --------------------------------------------------------------------------- |
|
651 // |
|
652 TInt CRadioEngineSettings::SetFlagValue( int aKey, int aFlagId, TInt aValue ) |
|
653 { |
|
654 TInt err = iRepository->Set( aKey, aValue ); |
|
655 if ( !err ) |
|
656 { |
|
657 iFlags.Assign( aFlagId, aValue ); |
|
658 } |
|
659 return err; |
|
660 } |
|
661 |
|
662 // --------------------------------------------------------------------------- |
|
663 // Initializes the regions based on resources. |
|
664 // --------------------------------------------------------------------------- |
|
665 // |
|
666 void CRadioEngineSettings::InitializeRegionsL() |
|
667 { |
|
668 LEVEL3( LOG_METHOD_AUTO ); |
|
669 iRegions.ResetAndDestroy(); |
|
670 |
|
671 TResourceReader reader; |
|
672 |
|
673 TFileName resourceFileName; |
|
674 resourceFileName.Append( KRadioSettingsResourceFile ); |
|
675 |
|
676 //User::LeaveIfError( iRadioSettingsImp.FsSession().Connect() ); |
|
677 |
|
678 //TODO: Remove the ResolveDriveL |
|
679 iRadioSettingsImp.ResolveDriveL( resourceFileName, KDC_RESOURCE_FILES_DIR ); |
|
680 BaflUtils::NearestLanguageFile( iRadioSettingsImp.FsSession(), resourceFileName); |
|
681 |
|
682 iResFile.OpenL( iRadioSettingsImp.FsSession(), resourceFileName); |
|
683 |
|
684 iResFile.ConfirmSignatureL(); |
|
685 HBufC8* readBuffer = iResFile.AllocReadLC(R_QRAD_REGIONS); |
|
686 reader.SetBuffer(readBuffer); |
|
687 TInt regionCount = reader.ReadInt16(); |
|
688 |
|
689 for ( TInt i = 0; i < regionCount; ++i ) |
|
690 { |
|
691 TInt resId = reader.ReadInt32(); // The next resource ID to read. |
|
692 HBufC8* regionBuffer = iResFile.AllocReadLC(resId); |
|
693 TResourceReader regionReader; |
|
694 regionReader.SetBuffer(regionBuffer); |
|
695 |
|
696 CRadioRegion* region = CRadioRegion::NewL( regionReader ); |
|
697 CleanupStack::PushL( region ); |
|
698 |
|
699 if ( IsRegionAllowed( region->Id() )) |
|
700 { |
|
701 User::LeaveIfError( iRegions.Append( region ) ); |
|
702 CleanupStack::Pop( region ); |
|
703 } |
|
704 else{ |
|
705 CleanupStack::PopAndDestroy( region ); |
|
706 } |
|
707 CleanupStack::PopAndDestroy(regionBuffer); |
|
708 } |
|
709 |
|
710 if ( CountRegions() <= 0 || !IsRegionAllowed( DefaultRegion() ) ) |
|
711 { |
|
712 User::Leave( KErrCorrupt ); |
|
713 } |
|
714 |
|
715 UpdateCurrentRegionIdx( RegionId() ); |
|
716 CleanupStack::PopAndDestroy(readBuffer); |
|
717 } |
|
718 |
|
719 // --------------------------------------------------------------------------- |
|
720 // Converts Region ID to index |
|
721 // --------------------------------------------------------------------------- |
|
722 // |
|
723 TInt CRadioEngineSettings::RegionIndexForId( TInt aRegionId ) const |
|
724 { |
|
725 LEVEL3( LOG_METHOD_AUTO ); |
|
726 TInt idx = KErrNotFound; |
|
727 for ( TInt i = 0 ; i < CountRegions(); ++i ) |
|
728 { |
|
729 if ( Region( i ).Id() == static_cast<TRadioRegion>( aRegionId ) ) |
|
730 { |
|
731 idx = i; |
|
732 break; |
|
733 } |
|
734 } |
|
735 return idx; |
|
736 } |
|
737 |
|
738 // --------------------------------------------------------------------------- |
|
739 // Updates the current region |
|
740 // --------------------------------------------------------------------------- |
|
741 // |
|
742 void CRadioEngineSettings::UpdateCurrentRegionIdx( TInt aRegionId ) |
|
743 { |
|
744 LEVEL3( LOG_METHOD_AUTO ); |
|
745 iCurrentRegionIdx = RegionIndexForId( aRegionId ); |
|
746 } |
|
747 |
|
748 // --------------------------------------------------------------------------- |
|
749 // Determines if region is allowed . |
|
750 // --------------------------------------------------------------------------- |
|
751 // |
|
752 TBool CRadioEngineSettings::IsRegionAllowed( TRadioRegion aRegionId ) const |
|
753 { |
|
754 LEVEL3( LOG_METHOD_AUTO ); |
|
755 |
|
756 TInt regionAllowed( ETrue ); |
|
757 if ( ERadioRegionJapan == aRegionId ) |
|
758 { |
|
759 TInt err = iRepository->Get( KRadioCRRegionAllowedJapan, regionAllowed ); |
|
760 if ( err != KErrNone ) |
|
761 { |
|
762 // In case the key is not found or otherwise unsuccessfully read, |
|
763 // Japan region is allowed by default. |
|
764 regionAllowed = ETrue; |
|
765 } |
|
766 } |
|
767 |
|
768 return TBool( regionAllowed ); |
|
769 } |
|