uifw/AvKon/src/AknSettingCache.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*
       
     2 * Copyright (c) 2002-2006 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:  This cache contains certain system settings that are regularly
       
    15 *                needed in UI controls.
       
    16 *                AknEnv owns an instance of the cache.
       
    17 *                Values of the cached settings are initialized when read for the
       
    18 *                first time.
       
    19 *                CEikAppUi updates the cache before forwarding change events
       
    20 *                to application controls, which can then read them from cache.
       
    21 *
       
    22 *
       
    23 */
       
    24 
       
    25 
       
    26 // INCLUDE FILES
       
    27 #include <e32svr.h>
       
    28 #include "AknSettingCache.h"
       
    29 #include "AknPanic.h"
       
    30 #include <AknUtils.h>
       
    31 
       
    32 #include <e32property.h>
       
    33 #include <UikonInternalPSKeys.h>    // KUikLayoutState, KUikPreferredOrientation
       
    34 
       
    35 #include <centralrepository.h>
       
    36 #include <AvkonInternalCRKeys.h>    // KAknLayoutId
       
    37 #include <AknFepInternalCRKeys.h>   // KAknFepInputTxtLang
       
    38 
       
    39 #include <eikdef.h> // event UIDs
       
    40 #include <languages.hrh>
       
    41 #include <AknDef.h>
       
    42 #include "AknDebug.h"
       
    43 
       
    44 #include <featmgr.h>
       
    45 // CONSTANTS
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CAknSettingCache::NewL()
       
    51 // -----------------------------------------------------------------------------
       
    52 //
       
    53 CAknSettingCache* CAknSettingCache::NewL()
       
    54     {
       
    55     return new(ELeave) CAknSettingCache;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CAknSettingCache::~CAknSettingCache()
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CAknSettingCache::~CAknSettingCache()
       
    63     {
       
    64     iPlugins.Reset();
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CAknSettingCache::InputLanguage()
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C TLanguage CAknSettingCache::InputLanguage()
       
    72     {
       
    73     if (!(iFlags & EInputLanguage))
       
    74         {
       
    75         UpdateFromCenRep(KCRUidAknFep, KAknFepInputTxtLang, (TInt&)iInputLanguage, EInputLanguage);
       
    76         }
       
    77 
       
    78     return iInputLanguage;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CAknSettingCache::LayoutId()
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C TAknLayoutId CAknSettingCache::LayoutId()
       
    86     {
       
    87     if (!(iFlags & ELayoutId))
       
    88         {
       
    89         UpdateFromCenRep(KCRUidAvkon, KAknLayoutId, (TInt&)iLayoutId, ELayoutId);
       
    90         }
       
    91 
       
    92     return iLayoutId;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CAknSettingCache::HardwareLayoutState()
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C TInt CAknSettingCache::HardwareLayoutState()
       
   100     {
       
   101     if (!(iFlags & EHardwareLayout))
       
   102         {
       
   103         UpdateFromPubSub(KPSUidUikon, KUikLayoutState, (TInt&)iHardwareLayout, EHardwareLayout);
       
   104         }
       
   105 
       
   106     return iHardwareLayout;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // CAknSettingCache::PreferredOrientation()
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 EXPORT_C TInt CAknSettingCache::PreferredOrientation()
       
   114     {
       
   115     if (!(iFlags & EPreferredOrientation))
       
   116         {
       
   117         UpdateFromPubSub(KPSUidUikon, KUikPreferredOrientation,
       
   118             (TInt&)iPreferredOrientation, EPreferredOrientation);
       
   119         }
       
   120         
       
   121     return iPreferredOrientation;
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // CAknSettingCache::GlobalUiZoom()
       
   126 // -----------------------------------------------------------------------------
       
   127 //
       
   128 EXPORT_C TAknUiZoom CAknSettingCache::GlobalUiZoom()
       
   129     {
       
   130     if (!(iFlags & EGlobalUiZoom))
       
   131         {
       
   132         UpdateFromCenRep(KCRUidAvkon, KAknGlobalUiZoom, (TInt&)iGlobalUiZoom, EGlobalUiZoom);
       
   133         }
       
   134 
       
   135     return iGlobalUiZoom;
       
   136     }
       
   137 
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CAknSettingCache::Update()
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 EXPORT_C TBool CAknSettingCache::Update(TInt aEventId)
       
   144     {
       
   145     TBool changed(EFalse);
       
   146 
       
   147     switch (aEventId)
       
   148         {
       
   149         case KEikInputLanguageChange:
       
   150             {
       
   151             changed = UpdateFromCenRep(KCRUidAknFep, KAknFepInputTxtLang, (TInt&)iInputLanguage, EInputLanguage);
       
   152             break;
       
   153             }
       
   154 
       
   155         case KEikDynamicLayoutVariantSwitch:
       
   156             {
       
   157             changed = UpdateFromCenRep(KCRUidAvkon, KAknLayoutId, (TInt&)iLayoutId, ELayoutId);
       
   158             changed |= UpdateFromCenRep(KCRUidAvkon, KAknGlobalUiZoom, (TInt&)iGlobalUiZoom, EGlobalUiZoom);
       
   159             break;
       
   160             }
       
   161 
       
   162         case KAknHardwareLayoutSwitch:
       
   163             {
       
   164             changed = UpdateFromPubSub(KPSUidUikon, KUikLayoutState, (TInt&)iHardwareLayout, EHardwareLayout);            
       
   165             changed |= UpdateFromPubSub(KPSUidUikon, KUikPreferredOrientation, (TInt&)iPreferredOrientation, EPreferredOrientation);
       
   166             break;
       
   167             }
       
   168 
       
   169         default:
       
   170             {
       
   171             break;
       
   172             }
       
   173         }
       
   174 
       
   175     // only listen to the topmost plugin for a given event
       
   176     TBool topMost = ETrue;
       
   177     // search in reverse order, as most recent registrations take precedence
       
   178     TInt count = iPlugins.Count();
       
   179     for(TInt ii = count - 1; ii >= 0; ii--)
       
   180         {
       
   181         MAknSettingCacheUpdatePlugin* pPlugin = iPlugins[ii];
       
   182         if(pPlugin->HandlesEvent(aEventId))
       
   183             {
       
   184             // update all the plugins, as some or all of them may need to update some cached data
       
   185             TBool updated = pPlugin->Update(aEventId);
       
   186             if(topMost)
       
   187                 {
       
   188                 changed = updated;
       
   189                 topMost = EFalse;
       
   190                 }
       
   191             }
       
   192         }
       
   193 
       
   194     return changed;
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CAknSettingCache::RegisterPlugin
       
   199 // -----------------------------------------------------------------------------
       
   200 EXPORT_C void CAknSettingCache::RegisterPluginL(MAknSettingCacheUpdatePlugin* aPlugin)
       
   201     {
       
   202     iPlugins.AppendL(aPlugin);
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CAknSettingCache::DeRegisterPlugin
       
   207 // -----------------------------------------------------------------------------
       
   208 EXPORT_C void CAknSettingCache::DeRegisterPlugin(MAknSettingCacheUpdatePlugin* aPlugin)
       
   209     {
       
   210     TInt index = iPlugins.Find(aPlugin);
       
   211     if(index != KErrNotFound)
       
   212         {
       
   213         iPlugins.Remove(index);
       
   214         }
       
   215     }
       
   216 
       
   217 // -----------------------------------------------------------------------------
       
   218 // CAknSettingCache::PluginValue
       
   219 // -----------------------------------------------------------------------------
       
   220 EXPORT_C TInt CAknSettingCache::PluginValue(TInt aEventId, TInt& aValue)
       
   221     {
       
   222     // search in reverse order, as most recent registrations take precedence
       
   223     TInt count = iPlugins.Count();
       
   224     for(TInt ii = count - 1; ii >= 0; ii--)
       
   225         {
       
   226         MAknSettingCacheUpdatePlugin* pPlugin = iPlugins[ii];
       
   227         if(pPlugin->HandlesEvent(aEventId))
       
   228             {
       
   229             // only listen to the topmost plugin for a given event
       
   230             return pPlugin->GetValue(aEventId, aValue);
       
   231             }
       
   232         }
       
   233     return KErrNotFound;
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CAknSettingCache::TransparencyEnabled()
       
   238 // -----------------------------------------------------------------------------
       
   239 //  
       
   240 EXPORT_C TBool CAknSettingCache::TransparencyEnabled()
       
   241     {
       
   242     if ( !( iFlags & ETransparencyEnabled ) )
       
   243         {
       
   244         UpdateFromCenRep( KCRUidAvkon, KAknAvkonTransparencyEnabled, 
       
   245                           (TInt&)iTransparencyEnabled, ETransparencyEnabled );    
       
   246         }
       
   247     return iTransparencyEnabled == 1 ? ETrue : EFalse;      
       
   248     }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CAknSettingCache::CAknSettingCache()
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 CAknSettingCache::CAknSettingCache() :
       
   255     // default values used only in case INI-files do not exist
       
   256     iInputLanguage(ELangEnglish), iLayoutId(EAknLayoutIdELAF), iGlobalUiZoom(EAknUiZoomAutomatic)
       
   257     {
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CAknSettingCache::UpdateFromSharedData()
       
   262 // -----------------------------------------------------------------------------
       
   263 //
       
   264 TBool CAknSettingCache::UpdateFromPubSub(const TUid aUid, TUint32 aKey, TInt& aValue, TCacheFlag aFlag)
       
   265     {
       
   266     TBool changed = EFalse;
       
   267     TInt newValue = 0;
       
   268     
       
   269     TInt err = RProperty::Get(aUid, aKey, newValue);
       
   270     
       
   271 #ifdef AVKON_RDEBUG_INFO
       
   272     RDebug::Print(_L("xxxx CAknSettingCache::UpdateFromPubSub err=%d value=%d"), err, newValue);
       
   273 #endif
       
   274     
       
   275     if (err == KErrNone)
       
   276         {
       
   277         // cache updated
       
   278         iFlags |= aFlag;
       
   279         
       
   280         if (aValue != newValue)
       
   281             {
       
   282             changed = ETrue;
       
   283             aValue = newValue;
       
   284             }
       
   285         }
       
   286     
       
   287     return changed;
       
   288     }
       
   289 
       
   290 TBool CAknSettingCache::UpdateFromCenRep(const TUid aUid, TUint32 aKey, TInt& aValue, TCacheFlag aFlag)
       
   291     {
       
   292     CRepository* repository = NULL;
       
   293     TBool changed = EFalse;
       
   294     TInt newValue = 0;
       
   295     
       
   296     TRAPD(err, repository = CRepository::NewL(aUid));
       
   297     
       
   298     if (err == KErrNone)
       
   299         {
       
   300         err = repository->Get(aKey, newValue);
       
   301         }
       
   302     
       
   303     // Special case: automatic detection of the layout ID
       
   304     // based on UI language is done here.
       
   305     
       
   306     // Value -1 is used to indicate 'automatic' layout ID detection.
       
   307     
       
   308     if ((err == KErrNotFound || newValue == -1) &&
       
   309         aUid == KCRUidAvkon &&
       
   310         aKey == KAknLayoutId)
       
   311         {
       
   312         TLanguage uiLanguage = AknLangUtils::UserLanguage();
       
   313         switch(uiLanguage)
       
   314             {
       
   315             case ELangArabic:
       
   316             case ELangHebrew:
       
   317             case ELangFarsi:
       
   318             case ELangUrdu:
       
   319                 {
       
   320                 newValue = EAknLayoutIdABRW;
       
   321                 break;
       
   322                 }
       
   323             case ELangTaiwanChinese:
       
   324             case ELangHongKongChinese:
       
   325             case ELangPrcChinese:
       
   326             case ELangJapanese:
       
   327             case KLangTaiwanEnglish:
       
   328             case KLangHongKongEnglish:
       
   329             case KLangPrcEnglish:
       
   330             case KLangJapaneseEnglish:
       
   331             case KLangApacMalay:
       
   332             case KLangApacEnglish:
       
   333             case KLangApacIndonesian:
       
   334                 {
       
   335                 newValue = EAknLayoutIdAPAC;
       
   336                 break;
       
   337                 }
       
   338             default: // all others use ELAF. Thai moved to Elaf since 3.2 release.
       
   339                 {
       
   340                 if( FeatureManager::FeatureSupported(KFeatureIdAvkonApac) )
       
   341                     { /* If APAC layout is enabled */
       
   342                     newValue = EAknLayoutIdAPAC;
       
   343                     }
       
   344                 else
       
   345                     { /* Else ELAF */
       
   346                 newValue = EAknLayoutIdELAF;
       
   347                     }
       
   348                 break;
       
   349                 }
       
   350             }
       
   351         
       
   352         if (repository)
       
   353             {
       
   354             err = repository->Set(aKey, newValue);
       
   355             }
       
   356         }
       
   357     
       
   358     delete repository;
       
   359     
       
   360     if (err == KErrNone)
       
   361         {
       
   362         // cache updated
       
   363         iFlags |= aFlag;
       
   364         
       
   365         if (aValue != newValue)
       
   366             {
       
   367             changed = ETrue;
       
   368             aValue = newValue;
       
   369             }
       
   370         }
       
   371     
       
   372     return changed;
       
   373     }
       
   374 
       
   375 //  End of File