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