skins/AknSkins/srvsrc/aknssrviconconfigmap.cpp
changeset 0 05e9090e2422
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Contains icon configuration information.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <centralrepository.h>
       
    19 
       
    20 #include "aknssrviconconfigmap.h"
       
    21 
       
    22 // @todo - we should get this from somewhere.
       
    23 const TUid KUidIconCaptionRepository = { 0x1028583d };
       
    24 
       
    25 // Highest 8 bit tell the application number which has been configured.
       
    26 // This is basically a running series, starting from zero.
       
    27 const TUint32 KAknsSrvAppBits =      0xFF000000;
       
    28 
       
    29 // Lowest 16 bits tell the language variant strings and icons.
       
    30 const TUint32 KAknsSrvLanguageBits = 0x0000FFFF;
       
    31 
       
    32 // Partial key to find the configured apps.
       
    33 const TUint32 KAknsSrvUidKey  =      0x00FFFFFF;
       
    34 
       
    35 // How many icons have been configured for this application.
       
    36 const TUint8 KAknsSrvIconCount = 0x02;
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 // ---------------------------------------------------------------------------
       
    40 // Symbian 1st phase constructor.
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CAknsSrvIconConfigMap* CAknsSrvIconConfigMap::NewL()
       
    44     {
       
    45     CAknsSrvIconConfigMap* self = new( ELeave ) CAknsSrvIconConfigMap;
       
    46     CleanupStack::PushL( self );
       
    47     self->ConstructL();
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // Destructor
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CAknsSrvIconConfigMap::~CAknsSrvIconConfigMap()
       
    57     {
       
    58     DeleteCurrentIconMap();
       
    59     }
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // Checks if the given application UID is found from array.
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 void CAknsSrvIconConfigMap::IsIconConfiguredL(
       
    66     TUid aApplicationUid, TBool& aIsConfigured )
       
    67     {
       
    68     if ( iCurrentLanguage != User::Language() )
       
    69         {
       
    70         CreateAndParseRepositoryL();
       
    71         }
       
    72 
       
    73     TInt found = iAppUidArray.Find( aApplicationUid.iUid );
       
    74     if ( found == KErrNotFound )
       
    75         {
       
    76         aIsConfigured = EFalse;
       
    77         }
       
    78     else
       
    79         {
       
    80         aIsConfigured = ETrue;
       
    81         }
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Destroys the application array.
       
    86 // ---------------------------------------------------------------------------
       
    87 //    
       
    88 void CAknsSrvIconConfigMap::DeleteCurrentIconMap()
       
    89     {
       
    90     iAppUidArray.Reset();
       
    91     iAppUidArray.Close();
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // Reads and parses cenrep configuration file.
       
    96 // ---------------------------------------------------------------------------
       
    97 //    
       
    98 void CAknsSrvIconConfigMap::ReadAndParseConfigFileL( CRepository* aRepository )
       
    99     {
       
   100     DeleteCurrentIconMap();
       
   101     
       
   102 	RArray<TUint32> appUidKeys;
       
   103 	CleanupClosePushL( appUidKeys );
       
   104 	
       
   105 	// Find all appUID keys that have been configured.
       
   106 	// error ignored, array is empty in error cases
       
   107 	aRepository->FindL( KAknsSrvUidKey, ~KAknsSrvAppBits, appUidKeys );
       
   108 	TInt appCount = appUidKeys.Count();
       
   109 
       
   110 	for (TInt appIndex = 0; appIndex < appCount; appIndex++)
       
   111 		{
       
   112 		TUint32 key = appUidKeys[appIndex];
       
   113 		TInt appUidVal = 0;
       
   114         User::LeaveIfError( aRepository->Get( key, appUidVal ) );
       
   115         
       
   116         RArray<TUint32> applicationKeys;
       
   117         // error ignored, array is empty in error cases
       
   118         // Find all configuration keys for this appUid.
       
   119         aRepository->FindL( key, KAknsSrvAppBits, applicationKeys );
       
   120         TInt appKeyCount = applicationKeys.Count();
       
   121 
       
   122 	    for (TInt appKeyIndex = 0; appKeyIndex < appKeyCount; appKeyIndex++)
       
   123 		    {		    
       
   124 		    // Each application might have the following configured for each language
       
   125 		    //  - [0..1] short caption (bits 32..25)
       
   126 		    //  - [0..1] long caption (bits 24..17)
       
   127 		    //  - [0..1] number of icons (bits 16..9)
       
   128 		    //  - [0..n] path of icon filename (bits 8..1)
       
   129 		    TUint32 applicationConfigKey = applicationKeys[appKeyIndex];
       
   130 		    TUint8 iconNumberblock = applicationConfigKey >> 16;
       
   131 		    
       
   132 		    if ( iconNumberblock == KAknsSrvIconCount )
       
   133 		        {
       
   134 		        TLanguage language = 
       
   135 		            static_cast<TLanguage>(applicationConfigKey & KAknsSrvLanguageBits);
       
   136 		        TInt noOfIcons = 0;
       
   137 		        User::LeaveIfError( aRepository->Get( applicationConfigKey, noOfIcons ) );
       
   138 		        if ( (noOfIcons > 0 ) && language == iCurrentLanguage )
       
   139 		            {
       
   140 		            iAppUidArray.Append( appUidVal );
       
   141 		            break; // once appUid has been added, we can skip to next app.
       
   142 		            }
       
   143 		        }		   
       
   144 		    }
       
   145 		}
       
   146     iAppUidArray.Sort();
       
   147 	CleanupStack::PopAndDestroy(&appUidKeys);
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // Creates, reads and parses central repository.
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CAknsSrvIconConfigMap::CreateAndParseRepositoryL()
       
   155     {
       
   156     CRepository* iconRepository = CRepository::NewLC( KUidIconCaptionRepository );
       
   157     ReadAndParseConfigFileL( iconRepository );
       
   158     CleanupStack::PopAndDestroy( iconRepository );
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // C++ constructor.
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 CAknsSrvIconConfigMap::CAknsSrvIconConfigMap()
       
   166     {
       
   167     iCurrentLanguage = User::Language();
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // Symbian second phase constructor.
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void CAknsSrvIconConfigMap::ConstructL()
       
   175     {
       
   176     TRAP_IGNORE( CreateAndParseRepositoryL() );
       
   177     }
       
   178 
       
   179 // End of file