sysstatemgmt/syslangutil/ssmlangselcmd/src/ssmlanguageloader.cpp
branchRCL_3
changeset 21 ccb4f6b3db21
parent 0 4e1aa6a622a0
child 22 8cb079868133
equal deleted inserted replaced
20:1ddbe54d0645 21:ccb4f6b3db21
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    18 
    18 
    19 #include <e32std.h>
    19 #include <e32std.h>
    20 #include <hal.h>
    20 #include <hal.h>
    21 
    21 
    22 #include "ssmlanguageloader.h"
    22 #include "ssmlanguageloader.h"
       
    23 #include "ssmcommonlocale.h"
    23 #include "trace.h"
    24 #include "trace.h"
    24 
    25 
    25 _LIT( KLocaleDllNameBase, "ELOCL" );
       
    26 _LIT( KLocaleDllExtensionFormat, ".%u" );
       
    27 _LIT( KLocaleDllExtensionPadding, "0" );
       
    28 _LIT( KDefaultLocaleDllNameExtension, ".LOC" );
       
    29 const TInt KMaxLocaleDllNameLength = 16;
       
    30 const TInt KMaxLocaleDllExtensionLength = 6;
       
    31 const TInt KMinLocaleDllExtensionLength = 3;
       
    32 const TInt KLocaleDllExtensionPaddingPosition = 1;
       
    33 
       
    34 // ======== MEMBER FUNCTIONS ========
    26 // ======== MEMBER FUNCTIONS ========
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // SsmLanguageLoader::LoadLanguage
       
    38 //
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 TInt SsmLanguageLoader::LoadLanguage( const TInt aLanguage )
       
    42     {
       
    43     FUNC_LOG;
       
    44     INFO_1( "Loading language %d", aLanguage );
       
    45 
       
    46     TInt errorCode = StoreLanguageToHal( aLanguage );
       
    47     ERROR( errorCode, "Failed to store language code to HAL" );
       
    48 
       
    49     errorCode = LoadLocaleDll( aLanguage );
       
    50     ERROR( errorCode, "Failed to load locale DLL" );
       
    51 
       
    52     return errorCode;
       
    53     }
       
    54 
       
    55 
    27 
    56 // -----------------------------------------------------------------------------
    28 // -----------------------------------------------------------------------------
    57 // SsmLanguageLoader::StoreLanguageToHal
    29 // SsmLanguageLoader::StoreLanguageToHal
    58 //
    30 //
    59 // -----------------------------------------------------------------------------
    31 // -----------------------------------------------------------------------------
    65     TInt errorCode = HAL::Set( HAL::ELanguageIndex, aLanguage );
    37     TInt errorCode = HAL::Set( HAL::ELanguageIndex, aLanguage );
    66     return errorCode;
    38     return errorCode;
    67     }
    39     }
    68 
    40 
    69 
    41 
    70 // -----------------------------------------------------------------------------
    42 // ---------------------------------------------------------------------------
    71 // SsmLanguageLoader::LoadLocaleDll
    43 // SsmLanguageLoader::LoadLocale
    72 //
    44 //
    73 // -----------------------------------------------------------------------------
    45 // ---------------------------------------------------------------------------
    74 //
    46 //
    75 TInt SsmLanguageLoader::LoadLocaleDll( const TInt aLanguage )
    47 TInt SsmLanguageLoader::LoadLocale( const TInt aLanguage, const TInt aRegion, const TInt aCollation)
    76     {
    48     {
    77     FUNC_LOG;
    49     FUNC_LOG;
    78 
    50 
    79     // Dot plus five digit locale
    51     TInt errorCode = StoreLanguageToHal( aLanguage );
    80     TBuf<KMaxLocaleDllExtensionLength> extension; 
    52     ERROR( errorCode, "Failed to store language code to HAL" );
    81     extension.Format( KLocaleDllExtensionFormat, aLanguage );
    53 
    82     
    54     //Format the language dll to be loaded
    83     // Padd ".1" to ".01" for compatibility.
    55     //Dot plus four to six digit locale
    84     if ( extension.Length() < KMinLocaleDllExtensionLength ) 
    56     TBuf<KMaxDllExtensionLength> extension; 
       
    57     extension.Format( KDllExtensionFormat, aLanguage );
       
    58 
       
    59     //Padd with zero to make the file extension length to be minimum of four
       
    60     for( ; extension.Length() < KMinDllExtensionLength ;) 
    85         {
    61         {
    86         extension.Insert( KLocaleDllExtensionPaddingPosition,
    62         extension.Insert( KDllExtensionPaddingPosition, KDllExtensionPadding );
    87                           KLocaleDllExtensionPadding );
       
    88         }
       
    89     
       
    90     TBuf<KMaxLocaleDllNameLength> localeDllName;
       
    91     localeDllName = KLocaleDllNameBase;
       
    92     localeDllName.Append( extension );
       
    93 
       
    94     INFO_1( "Loading DLL named '%S'", &localeDllName );
       
    95 
       
    96     TInt errorCode = ChangeLocale( localeDllName );
       
    97 
       
    98     if ( errorCode == KErrNotFound ) // Try default locale
       
    99         {
       
   100         INFO( "SsmLanguageLoader: Loading default locale" );
       
   101 
       
   102         localeDllName = KLocaleDllNameBase;
       
   103         localeDllName.Append( KDefaultLocaleDllNameExtension );
       
   104 
       
   105         errorCode = ChangeLocale( localeDllName );
       
   106         }
    63         }
   107 
    64 
       
    65     TBuf<KMaxDllNameLength> languageDllName( KLanguageDllNameBase );
       
    66     languageDllName.Append( extension );
       
    67     INFO_1( "Loading language DLL named '%S'", &languageDllName );
       
    68 
       
    69     //Format the region dll to be loaded
       
    70     //Dot plus four to six digit locale
       
    71     extension.Zero();
       
    72     extension.Format( KDllExtensionFormat, aRegion );
       
    73 
       
    74     //Padd with zero to make the file extension length to be minimum of four
       
    75     for( ; extension.Length() < KMinDllExtensionLength ;) 
       
    76         {
       
    77         extension.Insert( KDllExtensionPaddingPosition, KDllExtensionPadding );
       
    78         }
       
    79 
       
    80     TBuf<KMaxDllNameLength> regionDllName( KRegionDllNameBase );
       
    81     regionDllName.Append( extension );
       
    82     INFO_1( "Loading Region DLL named '%S'", &regionDllName );
       
    83 
       
    84 
       
    85     //Format the collation file to be loaded
       
    86     //Dot plus four to six digit locale
       
    87     extension.Zero();
       
    88     extension.Format( KDllExtensionFormat, aCollation );
       
    89 
       
    90     //Padd with zero to make the file extension length to be minimum of four
       
    91     for( ; extension.Length() < KMinDllExtensionLength ;) 
       
    92         {
       
    93         extension.Insert( KDllExtensionPaddingPosition, KDllExtensionPadding );
       
    94         }
       
    95 
       
    96     TBuf<KMaxDllNameLength> collationDllName( KCollationDllNameBase );
       
    97     collationDllName.Append( extension );
       
    98     INFO_1( "Loading Collation DLL named '%S'", &collationDllName );
       
    99     
       
   100     //Load the given Language, Region and Collation dlls
       
   101     errorCode = ChangeLocale( languageDllName, regionDllName, collationDllName );
   108     if ( errorCode == KErrNone )
   102     if ( errorCode == KErrNone )
   109         {
   103         {
   110         TLocale().Set();
   104         TLocale().Set();
   111         }
   105         }
   112 
       
   113     return errorCode;
   106     return errorCode;
   114     }
   107     }
   115 
   108 
   116 
   109 // ---------------------------------------------------------------------------
   117 // -----------------------------------------------------------------------------
       
   118 // SsmLanguageLoader::ChangeLocale
   110 // SsmLanguageLoader::ChangeLocale
   119 //
   111 //
   120 // -----------------------------------------------------------------------------
   112 // ---------------------------------------------------------------------------
   121 //
   113 //
   122 TInt SsmLanguageLoader::ChangeLocale( const TDesC& aLocaleDllName )
   114 TInt SsmLanguageLoader::ChangeLocale( const TDesC& aLanguageDllName,  const TDesC& aRegionDllName, const TDesC& aCollationDllName )
   123     {
   115     {
   124     FUNC_LOG;
   116     FUNC_LOG;
       
   117     TExtendedLocale extLocale;
   125 
   118 
   126     TExtendedLocale extLocale;
   119     INFO_3( "Loading Language dll '%S', Region dll '%S' and Collation dll '%S'",
   127     TInt errorCode = extLocale.LoadLocale( aLocaleDllName );
   120             &aLanguageDllName, &aRegionDllName, &aCollationDllName );
   128     ERROR( errorCode, "Failed to load locale" );
   121     TInt errorCode = extLocale.LoadLocale( aLanguageDllName, aRegionDllName, aCollationDllName);
   129 
       
   130     if ( errorCode == KErrNone )
   122     if ( errorCode == KErrNone )
   131         {
   123         {
       
   124         //Save the loaded locale settings
   132         errorCode = extLocale.SaveSystemSettings();
   125         errorCode = extLocale.SaveSystemSettings();
   133         ERROR( errorCode, "Failed to set locale" );
   126         ERROR( errorCode, "Failed to save locale settings" );
       
   127         }
       
   128     else
       
   129         {
       
   130         INFO_3( "Failed to load Language dll '%S', Region dll '%S' and Collation dll '%S'",
       
   131                     &aLanguageDllName, &aRegionDllName, &aCollationDllName );
   134         }
   132         }
   135 
   133 
   136     return errorCode;
   134     return errorCode;
   137     }
   135     }