radioengine/settings/src/cradiosettingsimp.cpp
branchGCC_SURGE
changeset 37 451b2e1545b2
parent 14 63aabac4416d
parent 28 075425b8d9a4
equal deleted inserted replaced
26:6bcf277166c1 37:451b2e1545b2
    24 
    24 
    25 // User includes
    25 // User includes
    26 #include "cradiosettingsimp.h"
    26 #include "cradiosettingsimp.h"
    27 #include "cradioapplicationsettings.h"
    27 #include "cradioapplicationsettings.h"
    28 #include "cradioenginesettings.h"
    28 #include "cradioenginesettings.h"
    29 #include "cradiorepositorymanager.h"
    29 //#include "radioengineutils.h"
    30 #include "radioengineutils.h"
       
    31 #include "radioengineutils.h"
       
    32 #include "cradioenginelogger.h"
    30 #include "cradioenginelogger.h"
    33 
    31 
    34 // The name of the radio settings resource file.
       
    35 _LIT( KRadioSettingsResourceFile, "radioenginesettings.rsc" );
       
    36 
       
    37 // The granularity of the repository manager array.
       
    38 const TInt KRadioSettingsRepositoryManagerGranularity = 8;
       
    39 
    32 
    40 // ======== MEMBER FUNCTIONS ========
    33 // ======== MEMBER FUNCTIONS ========
    41 
    34 
    42 // ---------------------------------------------------------------------------
    35 // ---------------------------------------------------------------------------
    43 //
    36 //
    44 // ---------------------------------------------------------------------------
    37 // ---------------------------------------------------------------------------
    45 //
    38 //
    46 CRadioSettingsImp* CRadioSettingsImp::NewL( CCoeEnv* aCoeEnv )
    39 CRadioSettingsImp* CRadioSettingsImp::NewL()
    47     {
    40     {
       
    41     LEVEL3( LOG_METHOD_AUTO );
    48     CRadioSettingsImp* self = new (ELeave) CRadioSettingsImp;
    42     CRadioSettingsImp* self = new (ELeave) CRadioSettingsImp;
    49     CleanupStack::PushL( self );
    43     CleanupStack::PushL( self );
    50     self->ConstructL( aCoeEnv );
    44     self->ConstructL();
    51     CleanupStack::Pop( self );
    45     CleanupStack::Pop( self );
    52     return self;
    46     return self;
    53     }
    47     }
    54 
    48 
    55 // ---------------------------------------------------------------------------
    49 // ---------------------------------------------------------------------------
    56 //
    50 //
    57 // ---------------------------------------------------------------------------
    51 // ---------------------------------------------------------------------------
    58 //
    52 //
    59 void CRadioSettingsImp::ConstructL( CCoeEnv* aCoeEnv )
    53 void CRadioSettingsImp::ConstructL()
    60     {
    54     {
    61     RadioEngineUtils::InitializeL( aCoeEnv );
    55     LEVEL3( LOG_METHOD_AUTO );
    62     LoadResourcesL();
    56     iFsSession = new ( ELeave ) RFs;
    63 
    57     User::LeaveIfError( iFsSession->Connect() );
    64     iRepositoryManager = CRadioRepositoryManager::NewL( KRadioSettingsRepositoryManagerGranularity );
       
    65 
    58 
    66     // Constructs the implementors of the interfaces.
    59     // Constructs the implementors of the interfaces.
    67     iApplicationSettings = CRadioApplicationSettings::NewL( *iRepositoryManager, *RadioEngineUtils::Env() );
    60     iApplicationSettings = CRadioApplicationSettings::NewL();
    68     iEngineSettings = CRadioEngineSettings::NewL( *iRepositoryManager, *RadioEngineUtils::Env() );
    61     iEngineSettings = CRadioEngineSettings::NewL( *this );
    69     }
    62     }
    70 
    63 
    71 // ---------------------------------------------------------------------------
    64 // ---------------------------------------------------------------------------
    72 //
    65 //
    73 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    74 //
    67 //
    75 CRadioSettingsImp::CRadioSettingsImp()
    68 CRadioSettingsImp::CRadioSettingsImp()
    76     {
    69     {
       
    70     LEVEL3( LOG_METHOD_AUTO );
    77     }
    71     }
    78 
    72 
    79 // ---------------------------------------------------------------------------
    73 // ---------------------------------------------------------------------------
    80 //
    74 //
    81 // ---------------------------------------------------------------------------
    75 // ---------------------------------------------------------------------------
    82 //
    76 //
    83 CRadioSettingsImp::~CRadioSettingsImp()
    77 CRadioSettingsImp::~CRadioSettingsImp()
    84     {
    78     {
       
    79     LEVEL3( LOG_METHOD_AUTO );
       
    80     delete iEngineSettings;
    85     delete iApplicationSettings;
    81     delete iApplicationSettings;
    86     delete iEngineSettings;
    82     if ( iFsSession )
    87     delete iRepositoryManager;
    83         {
    88 
    84         if ( iFsSession->Handle() )
    89     if ( iResourceLoader )
    85             {
    90         {
    86             iFsSession->Close();
    91         iResourceLoader->Close();
    87             }
    92         }
    88         delete iFsSession;
    93     delete iResourceLoader;
    89         }
    94     RadioEngineUtils::Release();
       
    95     }
    90     }
    96 
    91 
    97 // ---------------------------------------------------------------------------
    92 // ---------------------------------------------------------------------------
    98 // Determines if region is allowed.
    93 // Determines if region is allowed.
    99 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
   100 //
    95 //
   101 TBool CRadioSettingsImp::IsRegionAllowed( TRadioRegion aRegionId ) const
    96 TBool CRadioSettingsImp::IsRegionAllowed( TRadioRegion aRegionId ) const
   102     {
    97     {
       
    98     LEVEL3( LOG_METHOD_AUTO );
   103     return iEngineSettings->IsRegionAllowed( aRegionId );
    99     return iEngineSettings->IsRegionAllowed( aRegionId );
   104     }
   100     }
   105 
   101 
   106 // ---------------------------------------------------------------------------
   102 // ---------------------------------------------------------------------------
   107 // Returns the application settings interface.
   103 // Returns the application settings interface.
   108 // ---------------------------------------------------------------------------
   104 // ---------------------------------------------------------------------------
   109 //
   105 //
   110 MRadioApplicationSettings& CRadioSettingsImp::ApplicationSettings() const
   106 MRadioApplicationSettings& CRadioSettingsImp::ApplicationSettings() const
   111     {
   107     {
       
   108     LEVEL3( LOG_METHOD_AUTO );
   112     return *iApplicationSettings;
   109     return *iApplicationSettings;
   113     }
   110     }
   114 
   111 
   115 // ---------------------------------------------------------------------------
   112 // ---------------------------------------------------------------------------
   116 // Returns the radio settings interface.
   113 // Returns the radio settings interface.
   117 // ---------------------------------------------------------------------------
   114 // ---------------------------------------------------------------------------
   118 //
   115 //
   119 MRadioEngineSettings& CRadioSettingsImp::EngineSettings() const
   116 MRadioEngineSettings& CRadioSettingsImp::EngineSettings() const
   120     {
   117     {
       
   118     LEVEL3( LOG_METHOD_AUTO );
   121     return *iEngineSettings;
   119     return *iEngineSettings;
   122     }
   120     }
   123 
   121 
   124 // ---------------------------------------------------------------------------
   122 // ---------------------------------------------------------------------------
   125 // Returns the radio settings setter interface.
   123 // Returns the radio settings setter interface.
   126 // ---------------------------------------------------------------------------
   124 // ---------------------------------------------------------------------------
   127 //
   125 //
   128 MRadioSettingsSetter& CRadioSettingsImp::RadioSetter() const
   126 MRadioSettingsSetter& CRadioSettingsImp::RadioSetter() const
   129     {
   127     {
       
   128     LEVEL3( LOG_METHOD_AUTO );
   130     return *iEngineSettings;
   129     return *iEngineSettings;
   131     }
   130     }
   132 
   131 
   133 // ---------------------------------------------------------------------------
   132 // ---------------------------------------------------------------------------
   134 // Returns the underlying repository.
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 CRadioRepositoryManager& CRadioSettingsImp::Repository() const
       
   138     {
       
   139     return *iRepositoryManager;
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // Static version of ResolveDriveL.
   133 // Static version of ResolveDriveL.
   144 // ---------------------------------------------------------------------------
   134 // ---------------------------------------------------------------------------
   145 //
   135 //
   146 void CRadioSettingsImp::ResolveDriveL( TFileName& aFileName, const TDesC& aPath )
   136 void CRadioSettingsImp::ResolveDriveL( TFileName& aFileName, const TDesC& aPath )
   147     {
   137     {
   148     LOG_FORMAT( "CRadioSettingsImp::ResolveDriveL( aFileName = %S, aPath = %S )", &aFileName, &aPath );
   138     LEVEL3( LOG_METHOD_AUTO );
   149 
   139     LEVEL3( LOG_FORMAT( "aFileName = %S, aPath = %S", &aFileName, &aPath ) );
   150     RFs& fsSession = RadioEngineUtils::FsSession();
   140     
   151     TFileName fileName;
   141     TFileName fileName;
   152     TFileName baseResource;
   142     TFileName baseResource;
   153     TFindFile finder( fsSession );
   143     TFindFile finder( *iFsSession );
   154     TLanguage language( ELangNone );
   144     TLanguage language( ELangNone );
   155 
   145 
   156     _LIT( resourceFileExt, ".rsc" );
   146     _LIT( resourceFileExt, ".rsc" );
   157     _LIT( resourceFileWildExt, ".r*" );
   147     _LIT( resourceFileWildExt, ".r*" );
   158 
   148 
   173         // TFindFile applies search order that is from
   163         // TFindFile applies search order that is from
   174         // drive Y to A, then Z
   164         // drive Y to A, then Z
   175         err = finder.FindByDir( aFileName, aPath );
   165         err = finder.FindByDir( aFileName, aPath );
   176         }
   166         }
   177 
   167 
   178     LOG_FORMAT( "CRadioSettingsImp::ResolveDriveL - err = %d", err );
   168     LEVEL3( LOG_FORMAT( "err = %d", err ) );
   179     TBool found = EFalse;
   169     TBool found = EFalse;
   180     if ( !isResourceFile && err == KErrNone )
   170     if ( !isResourceFile && ( KErrNone == err ) )
   181         {
   171         {
   182         found = ETrue;
   172         found = ETrue;
   183         aFileName.Zero();
   173         aFileName.Zero();
   184         aFileName.Append( finder.File() );
   174         aFileName.Append( finder.File() );
   185         }
   175         }
   186 
   176 
   187     while ( !found && err == KErrNone && isResourceFile )
   177     while ( !found && ( KErrNone == err ) && isResourceFile )
   188         {
   178         {
   189         // Found file
   179         // Found file
   190         fileName.Zero();
   180         fileName.Zero();
   191         TParsePtrC foundPath( finder.File() );
   181         TParsePtrC foundPath( finder.File() );
   192         fileName.Copy( foundPath.DriveAndPath() );
   182         fileName.Copy( foundPath.DriveAndPath() );
   193         fileName.Append( aFileName );
   183         fileName.Append( aFileName );
   194         BaflUtils::NearestLanguageFile( fsSession, fileName, language );
   184         BaflUtils::NearestLanguageFile( *iFsSession, fileName, language );
   195         if ( language != ELangNone && BaflUtils::FileExists( fsSession, fileName ) )
   185         if ( language != ELangNone && BaflUtils::FileExists( *iFsSession, fileName ) )
   196             {
   186             {
   197             found = ETrue;
   187             found = ETrue;
   198             aFileName.Zero();
   188             aFileName.Zero();
   199             aFileName.Copy( fileName );
   189             aFileName.Copy( fileName );
   200             }
   190             }
   201         else
   191         else
   202             {
   192             {
   203             if ( language == ELangNone &&
   193             if ( language == ELangNone &&
   204                  !baseResource.Compare( KNullDesC ) &&
   194                  !baseResource.Compare( KNullDesC ) &&
   205                  BaflUtils::FileExists( fsSession, fileName ) )
   195                  BaflUtils::FileExists( *iFsSession, fileName ) )
   206                 {
   196                 {
   207                 baseResource.Copy( fileName );
   197                 baseResource.Copy( fileName );
   208                 }
   198                 }
   209             CDir* entries = NULL;
   199             CDir* entries = NULL;
   210             err = finder.FindWild( entries );
   200             err = finder.FindWild( entries );
   213         }
   203         }
   214 
   204 
   215     if ( !found && baseResource.Compare( KNullDesC ) )
   205     if ( !found && baseResource.Compare( KNullDesC ) )
   216         {
   206         {
   217         // If we found *.rsc then better to use that than nothing
   207         // If we found *.rsc then better to use that than nothing
   218         if ( BaflUtils::FileExists( fsSession, baseResource ) )
   208         if ( BaflUtils::FileExists( *iFsSession, baseResource ) )
   219             {
   209             {
   220             found = ETrue;
   210             found = ETrue;
   221             aFileName.Zero();
   211             aFileName.Zero();
   222             aFileName.Append( baseResource );
   212             aFileName.Append( baseResource );
   223             }
   213             }
   224         }
   214         }
   225 
   215 
   226     if ( !found )
   216     if ( !found )
   227         {
   217         {
   228         LOG_FORMAT( "CRadioSettingsImp::ResolveDriveL - File %S not found ( err = %d )!", &aFileName, err );
   218         LEVEL3( LOG_FORMAT( "File %S not found ( err = %d )!", &aFileName, err ) );
   229         User::Leave( KErrNotFound );
   219         if ( !err )
   230         }
   220             {
   231 
   221             err = KErrNotFound;
   232     LOG_FORMAT( "CRadioSettingsImp::ResolveDriveL( aFileName = %S )", &aFileName );
   222             }
   233     }
   223         User::Leave( err );
   234 
   224         }
   235 // ---------------------------------------------------------------------------
   225 
   236 // Loads the required resources.
   226     LEVEL3( LOG_FORMAT( "aFileName = %S", &aFileName ) );
   237 // ---------------------------------------------------------------------------
   227     }
   238 //
   228 
   239 void CRadioSettingsImp::LoadResourcesL()
   229 // ---------------------------------------------------------------------------
   240     {
   230 // Returns the file server session
   241     // Allocated in heap only so that the resource loader header doesn't need to be
   231 // ---------------------------------------------------------------------------
   242     // included in the header of this class. This is because this will be included
   232 //
   243     // by a QT component that should not depend on CONE
   233 RFs& CRadioSettingsImp::FsSession()
   244     iResourceLoader = new (ELeave) RConeResourceLoader( *RadioEngineUtils::Env() );
   234     {
   245 
   235     LEVEL3( LOG_METHOD_AUTO );
   246     TFileName resourceFileName;
   236     return *iFsSession;
   247     resourceFileName.Append( KRadioSettingsResourceFile );
   237     }
   248 
   238 
   249     ResolveDriveL( resourceFileName, KDC_RESOURCE_FILES_DIR );
       
   250 
       
   251     iResourceLoader->OpenL( resourceFileName );
       
   252     }
       
   253