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 |
|
22 // User includes |
|
23 #include "radiointernalcrkeys.h" |
|
24 #include "radioenginesettings.rsg" |
|
25 #include "radioenginedef.h" |
|
26 #include "cradioenginesettings.h" |
|
27 #include "mradiosettingsobserver.h" |
|
28 #include "cradiorepositorymanager.h" |
|
29 |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CRadioEngineSettings* CRadioEngineSettings::NewL( CRadioRepositoryManager& aRepositoryManager, |
|
38 CCoeEnv& aCoeEnv ) |
|
39 { |
|
40 CRadioEngineSettings* self = new ( ELeave ) CRadioEngineSettings( aRepositoryManager, aCoeEnv ); |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL(); |
|
43 CleanupStack::Pop( self ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 void CRadioEngineSettings::ConstructL() |
|
52 { |
|
53 iRepositoryManager.AddObserverL( this ); |
|
54 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRHeadsetVolume, CRadioRepositoryManager::ERadioEntityInt ); |
|
55 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRSpeakerVolume, CRadioRepositoryManager::ERadioEntityInt ); |
|
56 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCROutputMode, CRadioRepositoryManager::ERadioEntityInt ); |
|
57 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRAudioRoute, CRadioRepositoryManager::ERadioEntityInt ); |
|
58 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRHeadsetMuteState, CRadioRepositoryManager::ERadioEntityInt ); |
|
59 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRSpeakerMuteState, CRadioRepositoryManager::ERadioEntityInt ); |
|
60 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRVisualRadioPowerState, CRadioRepositoryManager::ERadioEntityInt ); |
|
61 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRTunedFrequency, CRadioRepositoryManager::ERadioEntityInt ); |
|
62 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRDefaultMinVolumeLevel, CRadioRepositoryManager::ERadioEntityInt ); |
|
63 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRCurrentRegion, CRadioRepositoryManager::ERadioEntityInt ); |
|
64 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRRdsAfSearch, CRadioRepositoryManager::ERadioEntityInt ); |
|
65 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRNetworkId, CRadioRepositoryManager::ERadioEntityDes16 ); |
|
66 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRSubscriberId, CRadioRepositoryManager::ERadioEntityDes16 ); |
|
67 iRepositoryManager.AddEntityL( KRadioCRUid, KRadioCRCountryCode, CRadioRepositoryManager::ERadioEntityDes16 ); |
|
68 |
|
69 InitializeRegionsL(); |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CRadioEngineSettings::CRadioEngineSettings( CRadioRepositoryManager& aRepositoryManager, CCoeEnv& aCoeEnv ) |
|
77 : CRadioSettingsBase( aRepositoryManager, aCoeEnv ) |
|
78 { |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 CRadioEngineSettings::~CRadioEngineSettings() |
|
86 { |
|
87 iRepositoryManager.RemoveObserver( this ); |
|
88 iRegions.ResetAndDestroy(); |
|
89 iRegions.Close(); |
|
90 } |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // From class MRadioSettingsSetter. |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CRadioEngineSettings::SetObserver( MRadioSettingsObserver* aObserver ) |
|
97 { |
|
98 iObserver = aObserver; |
|
99 } |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // From class MRadioSettingsSetter. |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 TInt CRadioEngineSettings::SetHeadsetVolume( TInt aVolume ) |
|
106 { |
|
107 return iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCRHeadsetVolume, aVolume ); |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // From class MRadioEngineSettings. |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 TInt CRadioEngineSettings::HeadsetVolume() const |
|
115 { |
|
116 return iRepositoryManager.EntityValueInt( KRadioCRUid, KRadioCRHeadsetVolume ); |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // From class MRadioSettingsSetter. |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 TInt CRadioEngineSettings::SetSpeakerVolume( TInt aVolume ) |
|
124 { |
|
125 return iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCRSpeakerVolume, aVolume ); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------------------------- |
|
129 // From class MRadioEngineSettings. |
|
130 // --------------------------------------------------------------------------- |
|
131 // |
|
132 TInt CRadioEngineSettings::SpeakerVolume() const |
|
133 { |
|
134 return iRepositoryManager.EntityValueInt( KRadioCRUid, KRadioCRSpeakerVolume ); |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------------------------- |
|
138 // From class MRadioSettingsSetter. |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 TInt CRadioEngineSettings::SetVolume( TInt aVolume ) |
|
142 { |
|
143 if ( AudioRoute() == RadioEngine::ERadioHeadset ) |
|
144 { |
|
145 return SetHeadsetVolume( aVolume ); |
|
146 } |
|
147 else |
|
148 { |
|
149 return SetSpeakerVolume( aVolume ); |
|
150 } |
|
151 } |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // From class MRadioEngineSettings. |
|
155 // --------------------------------------------------------------------------- |
|
156 // |
|
157 TInt CRadioEngineSettings::Volume() const |
|
158 { |
|
159 if ( AudioRoute() == RadioEngine::ERadioHeadset ) |
|
160 { |
|
161 return HeadsetVolume(); |
|
162 } |
|
163 else |
|
164 { |
|
165 return SpeakerVolume(); |
|
166 } |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // From class MRadioSettingsSetter. |
|
171 // |
|
172 // --------------------------------------------------------------------------- |
|
173 // |
|
174 TInt CRadioEngineSettings::SetOutputMode( TInt aOutputMode ) |
|
175 { |
|
176 return iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCROutputMode, aOutputMode ); |
|
177 } |
|
178 |
|
179 // --------------------------------------------------------------------------- |
|
180 // From class MRadioEngineSettings. |
|
181 // |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 TInt CRadioEngineSettings::OutputMode() const |
|
185 { |
|
186 return iRepositoryManager.EntityValueInt( KRadioCRUid, KRadioCROutputMode ); |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------------------------- |
|
190 // From class MRadioSettingsSetter. |
|
191 // Stores the radio audio route ( headset/ihf ) to use. |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 TInt CRadioEngineSettings::SetAudioRoute( TInt aAudioRoute ) |
|
195 { |
|
196 return iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCRAudioRoute, aAudioRoute ); |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------------------------- |
|
200 // From class MRadioEngineSettings. |
|
201 // Retrieves the radio audio route in use. |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 TInt CRadioEngineSettings::AudioRoute() const |
|
205 { |
|
206 return iRepositoryManager.EntityValueInt( KRadioCRUid, KRadioCRAudioRoute ); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------------------------- |
|
210 // From class MRadioSettingsSetter. |
|
211 // |
|
212 // --------------------------------------------------------------------------- |
|
213 // |
|
214 TInt CRadioEngineSettings::SetHeadsetVolMuted( TBool aMuted ) |
|
215 { |
|
216 return iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCRHeadsetMuteState, aMuted ); |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------------------------- |
|
220 // From class MRadioEngineSettings. |
|
221 // |
|
222 // --------------------------------------------------------------------------- |
|
223 // |
|
224 TBool CRadioEngineSettings::IsHeadsetVolMuted() const |
|
225 { |
|
226 return iRepositoryManager.EntityValueInt( KRadioCRUid, KRadioCRHeadsetMuteState ); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // From class MRadioSettingsSetter. |
|
231 // |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 TInt CRadioEngineSettings::SetSpeakerVolMuted( TBool aMuted ) |
|
235 { |
|
236 return iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCRSpeakerMuteState, aMuted ); |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------------------------- |
|
240 // From class MRadioEngineSettings. |
|
241 // |
|
242 // --------------------------------------------------------------------------- |
|
243 // |
|
244 TBool CRadioEngineSettings::IsSpeakerVolMuted() const |
|
245 { |
|
246 return iRepositoryManager.EntityValueInt( KRadioCRUid, KRadioCRSpeakerMuteState ); |
|
247 } |
|
248 |
|
249 // --------------------------------------------------------------------------- |
|
250 // From class MRadioSettingsSetter. |
|
251 // |
|
252 // --------------------------------------------------------------------------- |
|
253 // |
|
254 TInt CRadioEngineSettings::SetVolMuted( TBool aMuted ) |
|
255 { |
|
256 if ( AudioRoute() == RadioEngine::ERadioHeadset ) |
|
257 { |
|
258 return SetHeadsetVolMuted( aMuted ); |
|
259 } |
|
260 else |
|
261 { |
|
262 return SetSpeakerVolMuted( aMuted ); |
|
263 } |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // From class MRadioEngineSettings. |
|
268 // |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 TBool CRadioEngineSettings::IsVolMuted() const |
|
272 { |
|
273 if ( AudioRoute() == RadioEngine::ERadioHeadset ) |
|
274 { |
|
275 return IsHeadsetVolMuted(); |
|
276 } |
|
277 else |
|
278 { |
|
279 return IsSpeakerVolMuted(); |
|
280 } |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // From class MRadioSettingsSetter. |
|
285 // |
|
286 // --------------------------------------------------------------------------- |
|
287 // |
|
288 TInt CRadioEngineSettings::SetPowerOn( TBool aPowerState ) |
|
289 { |
|
290 return iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCRVisualRadioPowerState, aPowerState ); |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------------------------- |
|
294 // From class MRadioEngineSettings. |
|
295 // |
|
296 // --------------------------------------------------------------------------- |
|
297 // |
|
298 TBool CRadioEngineSettings::IsPowerOn() const |
|
299 { |
|
300 return iRepositoryManager.EntityValueInt( KRadioCRUid, KRadioCRVisualRadioPowerState ); |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // From class MRadioSettingsSetter. |
|
305 // |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 TInt CRadioEngineSettings::SetTunedFrequency( TUint32 aFrequency ) |
|
309 { |
|
310 return iRepositoryManager.SetEntityValue( KRadioCRUid, |
|
311 KRadioCRTunedFrequency, static_cast<TInt>( aFrequency ) ); |
|
312 } |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // From class MRadioEngineSettings. |
|
316 // |
|
317 // --------------------------------------------------------------------------- |
|
318 // |
|
319 TUint32 CRadioEngineSettings::TunedFrequency() const |
|
320 { |
|
321 return static_cast<TUint32>( iRepositoryManager.EntityValueInt( KRadioCRUid, KRadioCRTunedFrequency ) ); |
|
322 } |
|
323 |
|
324 // --------------------------------------------------------------------------- |
|
325 // From class MRadioEngineSettings. |
|
326 // |
|
327 // --------------------------------------------------------------------------- |
|
328 // |
|
329 TInt CRadioEngineSettings::DefaultMinVolumeLevel() const |
|
330 { |
|
331 return iRepositoryManager.EntityValueInt( KRadioCRUid, KRadioCRDefaultMinVolumeLevel ); |
|
332 } |
|
333 |
|
334 // --------------------------------------------------------------------------- |
|
335 // From class MRadioEngineSettings. |
|
336 // |
|
337 // --------------------------------------------------------------------------- |
|
338 // |
|
339 TInt CRadioEngineSettings::CountRegions() const |
|
340 { |
|
341 return iRegions.Count(); |
|
342 } |
|
343 |
|
344 // --------------------------------------------------------------------------- |
|
345 // From class MRadioEngineSettings. |
|
346 // |
|
347 // --------------------------------------------------------------------------- |
|
348 // |
|
349 CRadioRegion& CRadioEngineSettings::Region( TInt aIndex ) const |
|
350 { |
|
351 if ( aIndex == KErrNotFound ) |
|
352 { |
|
353 aIndex = RegionIndexForId( DefaultRegion() ); |
|
354 } |
|
355 |
|
356 return *iRegions[aIndex]; |
|
357 } |
|
358 |
|
359 // --------------------------------------------------------------------------- |
|
360 // From class MRadioEngineSettings. |
|
361 // |
|
362 // --------------------------------------------------------------------------- |
|
363 // |
|
364 TRadioRegion CRadioEngineSettings::RegionId() const |
|
365 { |
|
366 return static_cast<TRadioRegion>( iRepositoryManager.EntityValueInt( KRadioCRUid, |
|
367 KRadioCRCurrentRegion ) ); |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 // From class MRadioEngineSettings. |
|
372 // |
|
373 // --------------------------------------------------------------------------- |
|
374 // |
|
375 TRadioRegion CRadioEngineSettings::DefaultRegion() const |
|
376 { |
|
377 TInt region( 0 ); |
|
378 |
|
379 TRAPD( err, iRepositoryManager.GetRepositoryValueL( KRadioCRUid, KRadioCRDefaultRegion, region ) ); |
|
380 |
|
381 TRadioRegion regionSetting = static_cast<TRadioRegion>( region ); |
|
382 |
|
383 if ( err != KErrNone ) |
|
384 { |
|
385 regionSetting = ERadioRegionNone; |
|
386 } |
|
387 return regionSetting; |
|
388 } |
|
389 |
|
390 |
|
391 // --------------------------------------------------------------------------- |
|
392 // From class MRadioEngineSettings. |
|
393 // |
|
394 // --------------------------------------------------------------------------- |
|
395 // |
|
396 TPtrC CRadioEngineSettings::NetworkId() const |
|
397 { |
|
398 return TPtrC( iRepositoryManager.EntityValueDes16( KRadioCRUid, KRadioCRNetworkId ) ); |
|
399 } |
|
400 |
|
401 // --------------------------------------------------------------------------- |
|
402 // From class MRadioEngineSettings. |
|
403 // |
|
404 // --------------------------------------------------------------------------- |
|
405 // |
|
406 TPtrC CRadioEngineSettings::SubscriberId() const |
|
407 { |
|
408 return TPtrC( iRepositoryManager.EntityValueDes16( KRadioCRUid, KRadioCRSubscriberId ) ); |
|
409 } |
|
410 |
|
411 // --------------------------------------------------------------------------- |
|
412 // From class MRadioEngineSettings. |
|
413 // |
|
414 // --------------------------------------------------------------------------- |
|
415 // |
|
416 TPtrC CRadioEngineSettings::CountryCode() const |
|
417 { |
|
418 return TPtrC( iRepositoryManager.EntityValueDes16( KRadioCRUid, KRadioCRCountryCode ) ); |
|
419 } |
|
420 |
|
421 // --------------------------------------------------------------------------- |
|
422 // From class MRadioSettingsSetter. |
|
423 // |
|
424 // --------------------------------------------------------------------------- |
|
425 // |
|
426 TInt CRadioEngineSettings::SetRegionId( TInt aRegion ) |
|
427 { |
|
428 __ASSERT_ALWAYS( RegionIndexForId( aRegion ) != KErrNotFound, |
|
429 User::Panic( _L( "CRadioEngineSettings" ), KErrArgument ) ); |
|
430 |
|
431 TInt err = iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCRCurrentRegion, aRegion ); |
|
432 if ( !err ) |
|
433 { |
|
434 UpdateCurrentRegionIdx( aRegion ); |
|
435 err = SetTunedFrequency( Region( iCurrentRegionIdx ).MinFrequency() ); |
|
436 } |
|
437 return err; |
|
438 } |
|
439 |
|
440 // --------------------------------------------------------------------------- |
|
441 // From class MRadioSettingsSetter. |
|
442 // |
|
443 // --------------------------------------------------------------------------- |
|
444 // |
|
445 TInt CRadioEngineSettings::SetRdsAfSearch( TBool aEnabled ) |
|
446 { |
|
447 return iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCRRdsAfSearch, aEnabled ); |
|
448 } |
|
449 |
|
450 // --------------------------------------------------------------------------- |
|
451 // From class MRadioSettingsSetter. |
|
452 // |
|
453 // --------------------------------------------------------------------------- |
|
454 // |
|
455 TInt CRadioEngineSettings::SetNetworkId( const TDesC& aNetworkId ) |
|
456 { |
|
457 return iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCRNetworkId, aNetworkId ); |
|
458 } |
|
459 |
|
460 // --------------------------------------------------------------------------- |
|
461 // From class MRadioSettingsSetter. |
|
462 // |
|
463 // --------------------------------------------------------------------------- |
|
464 // |
|
465 TInt CRadioEngineSettings::SetSubscriberId( const TDesC& aSubscriberId ) |
|
466 { |
|
467 return iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCRSubscriberId, aSubscriberId ); |
|
468 } |
|
469 |
|
470 // --------------------------------------------------------------------------- |
|
471 // From class MRadioSettingsSetter. |
|
472 // |
|
473 // --------------------------------------------------------------------------- |
|
474 // |
|
475 TInt CRadioEngineSettings::SetCountryCode( const TDesC& aCountryCode ) |
|
476 { |
|
477 return iRepositoryManager.SetEntityValue( KRadioCRUid, KRadioCRCountryCode, aCountryCode ); |
|
478 } |
|
479 |
|
480 // --------------------------------------------------------------------------- |
|
481 // From class MRadioEngineSettings. |
|
482 // |
|
483 // --------------------------------------------------------------------------- |
|
484 // |
|
485 TUint32 CRadioEngineSettings::FrequencyStepSize() const |
|
486 { |
|
487 return Region( iCurrentRegionIdx ).StepSize(); |
|
488 } |
|
489 |
|
490 // --------------------------------------------------------------------------- |
|
491 // From class MRadioEngineSettings. |
|
492 // |
|
493 // --------------------------------------------------------------------------- |
|
494 // |
|
495 TUint32 CRadioEngineSettings::MaxFrequency() const |
|
496 { |
|
497 return Region( iCurrentRegionIdx ).MaxFrequency(); |
|
498 } |
|
499 |
|
500 // --------------------------------------------------------------------------- |
|
501 // From class MRadioEngineSettings. |
|
502 // |
|
503 // --------------------------------------------------------------------------- |
|
504 // |
|
505 TUint32 CRadioEngineSettings::MinFrequency() const |
|
506 { |
|
507 return Region( iCurrentRegionIdx ).MinFrequency(); |
|
508 } |
|
509 |
|
510 // --------------------------------------------------------------------------- |
|
511 // From class MRadioEngineSettings. |
|
512 // |
|
513 // --------------------------------------------------------------------------- |
|
514 // |
|
515 TInt CRadioEngineSettings::DecimalCount() const |
|
516 { |
|
517 return Region( iCurrentRegionIdx ).DecimalCount(); |
|
518 } |
|
519 |
|
520 // --------------------------------------------------------------------------- |
|
521 // From class MRadioEngineSettings. |
|
522 // |
|
523 // --------------------------------------------------------------------------- |
|
524 // |
|
525 TBool CRadioEngineSettings::RdsAfSearchEnabled() const |
|
526 { |
|
527 return iRepositoryManager.EntityValueInt( KRadioCRUid, KRadioCRRdsAfSearch ); |
|
528 } |
|
529 |
|
530 // --------------------------------------------------------------------------- |
|
531 // Initializes the regions based on resources. |
|
532 // --------------------------------------------------------------------------- |
|
533 // |
|
534 void CRadioEngineSettings::InitializeRegionsL() |
|
535 { |
|
536 iRegions.ResetAndDestroy(); |
|
537 |
|
538 TResourceReader reader; |
|
539 iCoeEnv.CreateResourceReaderLC( reader, R_QRAD_REGIONS ); |
|
540 |
|
541 TInt regionCount = reader.ReadInt16(); |
|
542 |
|
543 for ( TInt i = 0 ; i < regionCount; i++ ) |
|
544 { |
|
545 TInt resId = reader.ReadInt32(); // The next resource ID to read. |
|
546 TResourceReader regionReader; |
|
547 iCoeEnv.CreateResourceReaderLC( regionReader, resId ); |
|
548 CRadioRegion* region = CRadioRegion::NewL( regionReader ); |
|
549 CleanupStack::PushL( region ); |
|
550 |
|
551 if ( IsRegionAllowed( region->Id() )) |
|
552 { |
|
553 User::LeaveIfError( iRegions.Append( region ) ); |
|
554 CleanupStack::Pop( region ); |
|
555 } |
|
556 else{ |
|
557 CleanupStack::PopAndDestroy( region ); |
|
558 } |
|
559 CleanupStack::PopAndDestroy(); |
|
560 } |
|
561 |
|
562 CleanupStack::PopAndDestroy(); |
|
563 |
|
564 if ( CountRegions() <= 0 || !IsRegionAllowed( DefaultRegion() ) ) |
|
565 { |
|
566 User::Leave( KErrCorrupt ); |
|
567 } |
|
568 |
|
569 UpdateCurrentRegionIdx( RegionId() ); |
|
570 } |
|
571 |
|
572 // --------------------------------------------------------------------------- |
|
573 // Converts Region ID to index |
|
574 // --------------------------------------------------------------------------- |
|
575 // |
|
576 TInt CRadioEngineSettings::RegionIndexForId( TInt aRegionId ) const |
|
577 { |
|
578 TInt idx = KErrNotFound; |
|
579 for ( TInt i = 0 ; i < CountRegions(); ++i ) |
|
580 { |
|
581 if ( Region( i ).Id() == static_cast<TRadioRegion>( aRegionId ) ) |
|
582 { |
|
583 idx = i; |
|
584 break; |
|
585 } |
|
586 } |
|
587 return idx; |
|
588 } |
|
589 |
|
590 // --------------------------------------------------------------------------- |
|
591 // Updates the current region |
|
592 // --------------------------------------------------------------------------- |
|
593 // |
|
594 void CRadioEngineSettings::UpdateCurrentRegionIdx( TInt aRegionId ) |
|
595 { |
|
596 iCurrentRegionIdx = RegionIndexForId( aRegionId ); |
|
597 } |
|
598 |
|
599 // --------------------------------------------------------------------------- |
|
600 // From class MRadioRepositoryEntityObserver. |
|
601 // --------------------------------------------------------------------------- |
|
602 // |
|
603 void CRadioEngineSettings::HandleRepositoryValueChangeL( const TUid& aUid, |
|
604 TUint32 aKey, |
|
605 TInt aValue, |
|
606 TInt aError ) |
|
607 { |
|
608 if ( !aError && aUid == KRadioCRUid && iObserver ) |
|
609 { |
|
610 if ( aKey == KRadioCRRdsAfSearch ) |
|
611 { |
|
612 iObserver->RdsAfSearchSettingChangedL( aValue ); |
|
613 } |
|
614 else if ( aKey == KRadioCRCurrentRegion ) |
|
615 { |
|
616 if ( iCurrentRegionIdx != RegionIndexForId( aValue ) ) |
|
617 { |
|
618 UpdateCurrentRegionIdx( aValue ); |
|
619 __ASSERT_ALWAYS( iCurrentRegionIdx != KErrNotFound, |
|
620 User::Panic( _L( "CRadioEngineSettings" ), KErrArgument ) ); |
|
621 User::LeaveIfError( SetTunedFrequency( Region( iCurrentRegionIdx ).MinFrequency() ) ); |
|
622 iObserver->RegionSettingChangedL( aValue ); |
|
623 } |
|
624 } |
|
625 else if ( aKey == KRadioCRRdsAfSearch ) |
|
626 { |
|
627 iObserver->RdsAfSearchSettingChangedL( aValue ); |
|
628 } |
|
629 else |
|
630 { |
|
631 } |
|
632 } |
|
633 } |
|
634 |
|
635 // --------------------------------------------------------------------------- |
|
636 // Determines if region is allowed . |
|
637 // --------------------------------------------------------------------------- |
|
638 // |
|
639 TBool CRadioEngineSettings::IsRegionAllowed( TRadioRegion aRegionId ) const |
|
640 { |
|
641 |
|
642 TInt regionAllowed( EFalse ); |
|
643 TInt err( KErrNone ); |
|
644 |
|
645 switch ( aRegionId ) |
|
646 { |
|
647 case ERadioRegionJapan: |
|
648 TRAP( err, iRepositoryManager.GetRepositoryValueL( KRadioCRUid, KRadioCRRegionAllowedJapan, regionAllowed ) ); |
|
649 break; |
|
650 |
|
651 case ERadioRegionAmerica: |
|
652 TRAP( err, iRepositoryManager.GetRepositoryValueL( KRadioCRUid, KRadioCRRegionAllowedAmerica, regionAllowed ) ); |
|
653 break; |
|
654 |
|
655 case ERadioRegionDefault: |
|
656 TRAP( err, iRepositoryManager.GetRepositoryValueL( KRadioCRUid, KRadioCRRegionAllowedDefault, regionAllowed ) ); |
|
657 break; |
|
658 |
|
659 default: |
|
660 break; |
|
661 } |
|
662 |
|
663 if ( err != KErrNone ) |
|
664 { |
|
665 regionAllowed = EFalse; |
|
666 } |
|
667 |
|
668 return TBool( regionAllowed ); |
|
669 } |
|