radioengine/settings/src/cradiosettingsimp.cpp
branchRCL_3
changeset 20 93c594350b9a
parent 19 cce62ebc198e
equal deleted inserted replaced
19:cce62ebc198e 20:93c594350b9a
     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 <bautils.h>
       
    20 #include <coemain.h>
       
    21 #include <ConeResLoader.h>
       
    22 #include <f32file.h>
       
    23 #include <data_caging_path_literals.hrh>
       
    24 
       
    25 // User includes
       
    26 #include "cradiosettingsimp.h"
       
    27 #include "cradioapplicationsettings.h"
       
    28 #include "cradioenginesettings.h"
       
    29 //#include "radioengineutils.h"
       
    30 #include "cradioenginelogger.h"
       
    31 
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CRadioSettingsImp* CRadioSettingsImp::NewL()
       
    40     {
       
    41     LEVEL3( LOG_METHOD_AUTO );
       
    42     CRadioSettingsImp* self = new (ELeave) CRadioSettingsImp;
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 void CRadioSettingsImp::ConstructL()
       
    54     {
       
    55     LEVEL3( LOG_METHOD_AUTO );
       
    56     iFsSession = new ( ELeave ) RFs;
       
    57     User::LeaveIfError( iFsSession->Connect() );
       
    58 
       
    59     // Constructs the implementors of the interfaces.
       
    60     iApplicationSettings = CRadioApplicationSettings::NewL();
       
    61     iEngineSettings = CRadioEngineSettings::NewL( *this );
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 CRadioSettingsImp::CRadioSettingsImp()
       
    69     {
       
    70     LEVEL3( LOG_METHOD_AUTO );
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CRadioSettingsImp::~CRadioSettingsImp()
       
    78     {
       
    79     LEVEL3( LOG_METHOD_AUTO );
       
    80     delete iEngineSettings;
       
    81     delete iApplicationSettings;
       
    82     if ( iFsSession )
       
    83         {
       
    84         iFsSession->Close();
       
    85         }
       
    86     delete iFsSession;
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // Determines if region is allowed.
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 TBool CRadioSettingsImp::IsRegionAllowed( TRadioRegion aRegionId ) const
       
    94     {
       
    95     LEVEL3( LOG_METHOD_AUTO );
       
    96     return iEngineSettings->IsRegionAllowed( aRegionId );
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // Returns the application settings interface.
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 MRadioApplicationSettings& CRadioSettingsImp::ApplicationSettings() const
       
   104     {
       
   105     LEVEL3( LOG_METHOD_AUTO );
       
   106     return *iApplicationSettings;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Returns the radio settings interface.
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 MRadioEngineSettings& CRadioSettingsImp::EngineSettings() const
       
   114     {
       
   115     LEVEL3( LOG_METHOD_AUTO );
       
   116     return *iEngineSettings;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // Returns the radio settings setter interface.
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 MRadioSettingsSetter& CRadioSettingsImp::RadioSetter() const
       
   124     {
       
   125     LEVEL3( LOG_METHOD_AUTO );
       
   126     return *iEngineSettings;
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------------------------
       
   130 // Static version of ResolveDriveL.
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void CRadioSettingsImp::ResolveDriveL( TFileName& aFileName, const TDesC& aPath )
       
   134     {
       
   135     LEVEL3( LOG_METHOD_AUTO );
       
   136     LEVEL3( LOG_FORMAT( "aFileName = %S, aPath = %S", &aFileName, &aPath ) );
       
   137 
       
   138     TFileName fileName;
       
   139     TFileName baseResource;
       
   140     TFindFile finder( *iFsSession );
       
   141     TLanguage language( ELangNone );
       
   142 
       
   143     _LIT( resourceFileExt, ".rsc" );
       
   144     _LIT( resourceFileWildExt, ".r*" );
       
   145 
       
   146     TParsePtrC parse( aFileName );
       
   147     TBool isResourceFile = ( parse.Ext() == resourceFileExt() );
       
   148 
       
   149     TInt err = KErrUnknown;
       
   150     if  ( isResourceFile )
       
   151         {
       
   152         CDir* entries = NULL;
       
   153         fileName.Copy( parse.Name() );
       
   154         fileName.Append( resourceFileWildExt() );
       
   155         err = finder.FindWildByDir( fileName, aPath, entries );
       
   156         delete entries;
       
   157         }
       
   158     else
       
   159         {
       
   160         // TFindFile applies search order that is from
       
   161         // drive Y to A, then Z
       
   162         err = finder.FindByDir( aFileName, aPath );
       
   163         }
       
   164 
       
   165     LEVEL3( LOG_FORMAT( "err = %d", err ) );
       
   166     TBool found = EFalse;
       
   167     if ( !isResourceFile && ( KErrNone == err ) )
       
   168         {
       
   169         found = ETrue;
       
   170         aFileName.Zero();
       
   171         aFileName.Append( finder.File() );
       
   172         }
       
   173 
       
   174     while ( !found && ( KErrNone == err ) && isResourceFile )
       
   175         {
       
   176         // Found file
       
   177         fileName.Zero();
       
   178         TParsePtrC foundPath( finder.File() );
       
   179         fileName.Copy( foundPath.DriveAndPath() );
       
   180         fileName.Append( aFileName );
       
   181         BaflUtils::NearestLanguageFile( *iFsSession, fileName, language );
       
   182         if ( language != ELangNone && BaflUtils::FileExists( *iFsSession, fileName ) )
       
   183             {
       
   184             found = ETrue;
       
   185             aFileName.Zero();
       
   186             aFileName.Copy( fileName );
       
   187             }
       
   188         else
       
   189             {
       
   190             if ( language == ELangNone &&
       
   191                  !baseResource.Compare( KNullDesC ) &&
       
   192                  BaflUtils::FileExists( *iFsSession, fileName ) )
       
   193                 {
       
   194                 baseResource.Copy( fileName );
       
   195                 }
       
   196             CDir* entries = NULL;
       
   197             err = finder.FindWild( entries );
       
   198             delete entries;
       
   199             }
       
   200         }
       
   201 
       
   202     if ( !found && baseResource.Compare( KNullDesC ) )
       
   203         {
       
   204         // If we found *.rsc then better to use that than nothing
       
   205         if ( BaflUtils::FileExists( *iFsSession, baseResource ) )
       
   206             {
       
   207             found = ETrue;
       
   208             aFileName.Zero();
       
   209             aFileName.Append( baseResource );
       
   210             }
       
   211         }
       
   212 
       
   213     if ( !found )
       
   214         {
       
   215         LEVEL3( LOG_FORMAT( "File %S not found ( err = %d )!", &aFileName, err ) );
       
   216         if ( !err )
       
   217             {
       
   218             err = KErrNotFound;
       
   219             }
       
   220         User::Leave( err );
       
   221         }
       
   222 
       
   223     LEVEL3( LOG_FORMAT( "aFileName = %S", &aFileName ) );
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // Returns the file server session
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 RFs& CRadioSettingsImp::FsSession()
       
   231     {
       
   232     LEVEL3( LOG_METHOD_AUTO );
       
   233     return *iFsSession;
       
   234     }