idlehomescreen/widgetmanager/src/wmconfiguration.cpp
branchRCL_3
changeset 83 5456b4e8b3a8
child 93 b01126ce0bec
equal deleted inserted replaced
82:5f0182e07bfb 83:5456b4e8b3a8
       
     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 * WidgetManager configuration class
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <centralrepository.h>
       
    21 #include <StringLoader.h>
       
    22 #include <AknsConstants.h>
       
    23 #include <widgetregistryclient.h> // widget reqistry
       
    24 
       
    25 #include <widgetmanagerview.rsg>
       
    26 #include <widgetmanager.mbg>
       
    27 #include "wmconfiguration.h"
       
    28 #include "wmresourceloader.h"
       
    29 #include "wmcrkeys.h"
       
    30 
       
    31 // some constants regarging the central repository localised section.
       
    32 // these will ensure CR localisation section compatibility even if
       
    33 // new strings are added
       
    34 const TInt KLangOffsetOperatorUrl = KOperatorButtonUrl0 - KLangId0;
       
    35 const TInt KLangOffsetOperatorText = KOperatorButtonText0 - KLangId0;
       
    36 const TInt KLangGroupSize = KLangId1 - KLangId0;
       
    37 const TUint32 KLastLangId = KLangId9;
       
    38 
       
    39 _LIT( KOpAppTypeS60, "s60" );
       
    40 _LIT( KOpAppTypeCwrt, "cwrt" );
       
    41 _LIT( KOpAppTypeWrt, "wrt" );
       
    42 _LIT( KOpAppTypeJava, "java" );
       
    43 _LIT( KOpAppTypeQt, "qt" );
       
    44 _LIT( KSeparator, ":" );
       
    45 _LIT( KOperatorIcon, "uid(%d)");
       
    46 _LIT( KHexPrefix, "0x" );
       
    47 
       
    48 // ---------------------------------------------------------
       
    49 // CWmConfiguration::NewL
       
    50 // ---------------------------------------------------------
       
    51 //
       
    52 CWmConfiguration* CWmConfiguration::NewL(
       
    53         CWmResourceLoader& aResourceLoader )
       
    54     {
       
    55     CWmConfiguration* self = new (ELeave) CWmConfiguration( aResourceLoader );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     CleanupStack::Pop( self );
       
    59     return self;
       
    60     }
       
    61 
       
    62 // ---------------------------------------------------------
       
    63 // CWmConfiguration::CWmConfiguration()
       
    64 // ---------------------------------------------------------
       
    65 //
       
    66 CWmConfiguration::CWmConfiguration(
       
    67         CWmResourceLoader& aResourceLoader )
       
    68     : iResourceLoader( aResourceLoader )
       
    69 	{
       
    70 
       
    71     // ovi
       
    72     iOviStoreUid = KNullUid;
       
    73 
       
    74     // operator
       
    75     iOperatorAppIdUid = KNullUid;
       
    76     iOperatorAppType = EUnknown;
       
    77     iOperatorButtonEnabled = EFalse;
       
    78     iButtonsMirrored = EFalse;
       
    79 	}
       
    80 
       
    81 // ---------------------------------------------------------
       
    82 // CWmConfiguration::~CWmConfiguration()
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 CWmConfiguration::~CWmConfiguration()
       
    86 	{
       
    87     delete iRepository;
       
    88     // ovi
       
    89     delete iOviStoreClientParam;
       
    90     delete iOviButtonTitle;
       
    91     delete iOviButtonIcon;
       
    92     // operator
       
    93     delete iOperatorButtonTitle;
       
    94     delete iOperatorButtonIcon;
       
    95     delete iOperatorButtonUrl;
       
    96     delete iOperatorParam;
       
    97     delete iOperatorAppIdStr;
       
    98 	}
       
    99 
       
   100 // ---------------------------------------------------------
       
   101 // CWmConfiguration::ConstructL
       
   102 // ---------------------------------------------------------
       
   103 //
       
   104 void CWmConfiguration::ConstructL()
       
   105 	{
       
   106 	// localised ovistore button text
       
   107     iOviButtonTitle = StringLoader::LoadL( R_QTN_WM_GO_TO_OVI_STORE );
       
   108 
       
   109     // ovistore icon descriptor. It will look something like this:
       
   110     // skin( 0x101f86e3 0x23f6 ):mif( z:\resource\apps\widgetmanager.mif 16388 16389 )
       
   111     _LIT( KSkinMifIconFormat, "skin( 0x%x 0x%x ):mif( %S %d %d )");
       
   112     const TInt KMaxIconDescriptorLength = 256;
       
   113     TBuf<KMaxIconDescriptorLength> buf;
       
   114     buf.Format( KSkinMifIconFormat(),
       
   115              EAknsMajorGeneric, EAknsMinorGenericQgnMenuOviStore,
       
   116              &iResourceLoader.IconFilePath(),
       
   117              EMbmWidgetmanagerQgn_menu_ovistore,
       
   118              EMbmWidgetmanagerQgn_menu_ovistore_mask );
       
   119     iOviButtonIcon = buf.AllocL();
       
   120 
       
   121     // read data from repository
       
   122     TRAP_IGNORE( LoadConfigurationL(); );
       
   123 
       
   124 	}
       
   125 
       
   126 // ---------------------------------------------------------
       
   127 // CWmConfiguration::LoadConfigurationL
       
   128 // ---------------------------------------------------------
       
   129 //
       
   130 void CWmConfiguration::LoadConfigurationL()
       
   131     {
       
   132     iRepository = CRepository::NewL( 
       
   133             TUid::Uid( KCrWidgetManagerm ) );
       
   134 
       
   135     // read Ovi parameters
       
   136     ReadInt32Parameter( KOviStoreUid, iOviStoreUid.iUid );
       
   137     iOviStoreClientParam = ReadDescParameterL( KOviStoreClientParam ); 
       
   138     
       
   139     // read operator parameters if operator button enabled
       
   140     ReadIntParameter( KOperatorButtonEnabled, iOperatorButtonEnabled );
       
   141     if ( iOperatorButtonEnabled )
       
   142         {
       
   143         // determine language and read localised parameters
       
   144         iLanguageIndex = FindCorrectLanguageId();
       
   145         iOperatorButtonTitle = ReadLocalisedParameterL( KLangOffsetOperatorText );
       
   146         iOperatorButtonUrl = ReadLocalisedParameterL( KLangOffsetOperatorUrl );
       
   147         // read non-localised parameters
       
   148         iOperatorButtonIcon = ReadDescParameterL( KOperatorButtonIcon );
       
   149         ReadOperatorApplicationInfoL();
       
   150         iOperatorParam = ReadDescParameterL( KOperatorParam );
       
   151         ReadIntParameter( KOperatorButtonHigherPriority, iButtonsMirrored );
       
   152         }
       
   153 
       
   154     delete iRepository;
       
   155     iRepository = NULL;
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------
       
   159 // CWmConfiguration::FindCorrectLanguageId
       
   160 // ---------------------------------------------------------
       
   161 //
       
   162 TInt CWmConfiguration::FindCorrectLanguageId()
       
   163     {
       
   164     TInt languageIndex = KErrNotFound; // the correct language
       
   165     TInt englishIndex = KErrNotFound; // english
       
   166     TInt anyIndex = KErrNotFound; // backup - any existing
       
   167     TLanguage sysLang = User::Language();
       
   168     
       
   169     //read language id's from cenrep, find a match
       
   170     for( TUint32 i=KLangId0; i<=KLastLangId && languageIndex<0; i+=KLangGroupSize )
       
   171         {
       
   172         TInt crLang = 0;
       
   173         if ( iRepository->Get( i, crLang ) == KErrNone )
       
   174             {
       
   175             if ( crLang == sysLang && languageIndex < 0 )
       
   176                 { languageIndex = i; }
       
   177             if ( crLang == ELangEnglish && englishIndex < 0 )
       
   178                 { englishIndex = i; }
       
   179             if ( crLang > 0 && anyIndex < 0 )
       
   180                 { anyIndex = i; }
       
   181             }
       
   182         }
       
   183     
       
   184     // if correct language was not found, use english
       
   185     if ( languageIndex < 0 ) languageIndex = englishIndex;
       
   186     // if english was not found, use any configured language
       
   187     if ( languageIndex < 0 ) languageIndex = anyIndex;
       
   188     // if there are no languages configured, we're in trouble...
       
   189     if ( languageIndex < 0 ) languageIndex = 0;
       
   190     
       
   191     return languageIndex;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------
       
   195 // CWmConfiguration::ReadDescParameterL
       
   196 // ---------------------------------------------------------
       
   197 //
       
   198 HBufC* CWmConfiguration::ReadDescParameterL( TInt aKey )
       
   199     {
       
   200     TBuf<NCentralRepositoryConstants::KMaxUnicodeStringLength> buf;
       
   201     TInt err = iRepository->Get( aKey, buf );
       
   202 
       
   203     HBufC* heapBuffer = NULL;
       
   204     if ( err == KErrNone )
       
   205         {
       
   206         heapBuffer = HBufC::NewL( buf.Length() );
       
   207         heapBuffer->Des().Copy( buf );
       
   208         }
       
   209     return heapBuffer;
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // CWmConfiguration::ReadInt32ParameterIntL
       
   214 // ---------------------------------------------------------
       
   215 //
       
   216 void CWmConfiguration::ReadInt32Parameter( TInt aKey, TInt32& aValue )
       
   217     {
       
   218     TInt value = 0;
       
   219 	if ( iRepository->Get( aKey, value ) == KErrNone )
       
   220 	    {
       
   221         aValue = value;
       
   222 	    }
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------
       
   226 // CWmConfiguration::ReadIntParameterIntL
       
   227 // ---------------------------------------------------------
       
   228 //
       
   229 void CWmConfiguration::ReadIntParameter( TInt aKey, TInt& aValue )
       
   230     {
       
   231     aValue = 0;
       
   232 	iRepository->Get( aKey, aValue );
       
   233     }
       
   234 
       
   235 // ---------------------------------------------------------
       
   236 // CWmConfiguration::ReadLocalisedParameterL
       
   237 // ---------------------------------------------------------
       
   238 //
       
   239 HBufC* CWmConfiguration::ReadLocalisedParameterL(
       
   240         TInt aOffset )
       
   241     {
       
   242     TBuf<NCentralRepositoryConstants::KMaxUnicodeStringLength> buf;
       
   243     TInt err = KErrNone;
       
   244     
       
   245     err = iRepository->Get( iLanguageIndex + aOffset, buf );
       
   246     if ( err != KErrNone || buf.Length() == 0 )
       
   247         {
       
   248         // This language is empty. Try default language (index 0)
       
   249         err = iRepository->Get( KLangId0 + aOffset, buf );
       
   250         }
       
   251 
       
   252     // construct string in heap
       
   253     HBufC* heapBuffer = NULL;
       
   254     if ( err == KErrNone )
       
   255         {
       
   256         heapBuffer = buf.AllocL();
       
   257         }
       
   258     return heapBuffer;
       
   259     }
       
   260 
       
   261 // ---------------------------------------------------------
       
   262 // CWmConfiguration::ReadOperatorApplicationInfoL
       
   263 // ---------------------------------------------------------
       
   264 //
       
   265 void CWmConfiguration::ReadOperatorApplicationInfoL()
       
   266     {
       
   267     HBufC* applicationInfo = ReadDescParameterL( KOperatorAppTypeAndId );
       
   268     if ( applicationInfo && applicationInfo->Des().Length() > 0 )
       
   269         {
       
   270         CleanupStack::PushL( applicationInfo );
       
   271         applicationInfo->Des().TrimAll();
       
   272 
       
   273         // parse
       
   274         TInt separator = applicationInfo->Des().Find( KSeparator );
       
   275         if ( separator != KErrNotFound )
       
   276             {
       
   277             TPtrC type = applicationInfo->Des().Left( separator );
       
   278             TPtrC appId = applicationInfo->Des().Mid(
       
   279                     separator + KSeparator().Length() );
       
   280             
       
   281             if ( !type.Compare( KOpAppTypeS60 ) )
       
   282                 {
       
   283                 iOperatorAppType = ES60;
       
   284                 iOperatorAppIdUid = StringToUid( appId );
       
   285                 SetOperatorIconL( iOperatorAppIdUid );
       
   286                 }
       
   287             else if ( !type.Compare( KOpAppTypeCwrt ) )
       
   288                 {
       
   289                 iOperatorAppType = ECwrt;
       
   290                 iOperatorAppIdUid = FetchWidgetUidFromRegistryL( appId );
       
   291                 SetOperatorIconL( iOperatorAppIdUid );
       
   292                 }
       
   293             else if ( !type.Compare( KOpAppTypeWrt ) )
       
   294                 {
       
   295                 iOperatorAppType = EWrt;
       
   296                 iOperatorAppIdUid = FetchWidgetUidFromRegistryL( appId );
       
   297                 SetOperatorIconL( iOperatorAppIdUid );
       
   298                 }
       
   299             else if ( !type.Compare( KOpAppTypeJava ) )
       
   300                 {
       
   301                 //TODO: java support is not fully implemented
       
   302                 User::Leave( KErrGeneral );
       
   303                 iOperatorAppType = EJava;
       
   304                 iOperatorAppIdStr = appId.AllocL();
       
   305                 }
       
   306             else if ( !type.Compare( KOpAppTypeQt ) )
       
   307                 {
       
   308                 iOperatorAppType = EQt;
       
   309                 iOperatorAppIdUid = StringToUid( appId );
       
   310                 SetOperatorIconL( iOperatorAppIdUid );
       
   311                 }
       
   312             }
       
   313         CleanupStack::PopAndDestroy( applicationInfo );
       
   314         }
       
   315     }
       
   316 
       
   317 // ---------------------------------------------------------
       
   318 // CWmConfiguration::SetOperatorIcon
       
   319 // ---------------------------------------------------------
       
   320 //
       
   321 void CWmConfiguration::SetOperatorIconL( TUid aUid )
       
   322     {
       
   323     if ( iOperatorButtonIcon &&
       
   324         !iOperatorButtonIcon->Des().Length() )
       
   325         {
       
   326         delete iOperatorButtonIcon;
       
   327         iOperatorButtonIcon = NULL;
       
   328         iOperatorButtonIcon = HBufC::NewL(
       
   329                 KMaxUidName + KOperatorIcon().Length() );
       
   330         iOperatorButtonIcon->Des().Format(
       
   331                 KOperatorIcon(), aUid );
       
   332         }
       
   333     }
       
   334 
       
   335 // ---------------------------------------------------------
       
   336 // CWmConfiguration::FetchWidgetUidFromRegistryL
       
   337 // ---------------------------------------------------------
       
   338 //
       
   339 TUid CWmConfiguration::FetchWidgetUidFromRegistryL(
       
   340     const TDesC& aBundleId )
       
   341     {
       
   342     RWidgetRegistryClientSession clientSession;
       
   343     User::LeaveIfError( clientSession.Connect() );
       
   344     CleanupClosePushL( clientSession );
       
   345     TInt ret = clientSession.GetWidgetUidL( aBundleId );
       
   346     clientSession.Disconnect();
       
   347     CleanupStack::PopAndDestroy( &clientSession );
       
   348     return TUid::Uid( ret );
       
   349     }
       
   350      
       
   351 // ---------------------------------------------------------
       
   352 // CWmConfiguration::PortalButtonCount
       
   353 // ---------------------------------------------------------
       
   354 //
       
   355 TInt CWmConfiguration::PortalButtonCount()
       
   356     {
       
   357     return ( iOperatorButtonEnabled ? 2 : 1 );
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------
       
   361 // CWmConfiguration::PortalButtonText
       
   362 // ---------------------------------------------------------
       
   363 //
       
   364 const TDesC& CWmConfiguration::PortalButtonText( TInt aIndex )
       
   365     {
       
   366     if ( aIndex == 0 && iOviButtonTitle )
       
   367         return *iOviButtonTitle;
       
   368     if ( aIndex == 1 && iOperatorButtonTitle && iOperatorButtonEnabled )
       
   369         return *iOperatorButtonTitle;
       
   370     return KNullDesC;
       
   371     }
       
   372 
       
   373 // ---------------------------------------------------------
       
   374 // CWmConfiguration::PortalButtonIcon
       
   375 // ---------------------------------------------------------
       
   376 //
       
   377 const TDesC& CWmConfiguration::PortalButtonIcon( TInt aIndex )
       
   378     {
       
   379     if ( aIndex == 0 && iOviButtonIcon )
       
   380         return *iOviButtonIcon;
       
   381     if ( aIndex == 1 && iOperatorButtonIcon && iOperatorButtonEnabled )
       
   382         return *iOperatorButtonIcon;
       
   383     return KNullDesC;
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------
       
   387 // CWmConfiguration::PortalButtonBrowserUrl
       
   388 // ---------------------------------------------------------
       
   389 //
       
   390 const TDesC& CWmConfiguration::PortalButtonBrowserUrl( TInt aIndex )
       
   391     {
       
   392     // No support for ovi here
       
   393     if ( aIndex == 1 && iOperatorButtonUrl && iOperatorButtonEnabled )
       
   394         return *iOperatorButtonUrl;
       
   395     return KNullDesC;
       
   396     }
       
   397 
       
   398 // ---------------------------------------------------------
       
   399 // CWmConfiguration::PortalButtonClientUid
       
   400 // ---------------------------------------------------------
       
   401 //
       
   402 TUid CWmConfiguration::PortalButtonClientUid( TInt aIndex )
       
   403     {
       
   404     if ( aIndex == 0 )
       
   405         {
       
   406         return iOviStoreUid;
       
   407         } 
       
   408     // operator not supported. Get operator data using 
       
   409     // PortalButtonApplicationInfoL
       
   410     return KNullUid;
       
   411     }
       
   412 
       
   413 // ---------------------------------------------------------
       
   414 // CWmConfiguration::PortalButtonClientParam
       
   415 // ---------------------------------------------------------
       
   416 //
       
   417 const TDesC& CWmConfiguration::PortalButtonClientParam( TInt aIndex )
       
   418     {
       
   419     if ( aIndex == 0 && iOviStoreClientParam )
       
   420         {
       
   421         return *iOviStoreClientParam;
       
   422         }
       
   423     if ( aIndex == 1 && iOperatorParam && iOperatorButtonEnabled )
       
   424         {
       
   425         return *iOperatorParam;
       
   426         }
       
   427     return KNullDesC;
       
   428     }
       
   429 
       
   430 // ---------------------------------------------------------
       
   431 // CWmConfiguration::PortalButtonsMirrored
       
   432 // ---------------------------------------------------------
       
   433 //
       
   434 TBool CWmConfiguration::PortalButtonsMirrored()
       
   435     {
       
   436     return iButtonsMirrored;
       
   437     } 
       
   438    
       
   439 // ---------------------------------------------------------
       
   440 // CWmConfiguration::PortalButtonApplicationType
       
   441 // ---------------------------------------------------------
       
   442 //
       
   443 CWmConfiguration::TOpAppType CWmConfiguration::PortalButtonApplicationType( 
       
   444         TInt aIndex )
       
   445     {
       
   446     if ( aIndex == 1 )
       
   447         {
       
   448         return iOperatorAppType;
       
   449         }
       
   450     // no support for ovi
       
   451     return EUnknown;
       
   452     }
       
   453 
       
   454 // ---------------------------------------------------------
       
   455 // CWmConfiguration::PortalButtonApplicationId
       
   456 // ---------------------------------------------------------
       
   457 //
       
   458 void CWmConfiguration::PortalButtonApplicationId( 
       
   459         TInt aIndex, TDes& aOperatorAppId )
       
   460     {
       
   461     if ( aIndex == 1 )
       
   462         {
       
   463         aOperatorAppId.Copy( *iOperatorAppIdStr );
       
   464         }
       
   465     // no support for ovi
       
   466     }
       
   467 
       
   468 // ---------------------------------------------------------
       
   469 // CWmConfiguration::PortalButtonApplicationId
       
   470 // ---------------------------------------------------------
       
   471 //
       
   472 void CWmConfiguration::PortalButtonApplicationId( 
       
   473         TInt aIndex, TUid& aOperatorAppId )
       
   474     {
       
   475     if ( aIndex == 1 )
       
   476         {
       
   477         aOperatorAppId = iOperatorAppIdUid; 
       
   478         }
       
   479     // no support for ovi
       
   480     }
       
   481 
       
   482 // ---------------------------------------------------------
       
   483 // CWmConfiguration::StringToUid
       
   484 // ---------------------------------------------------------
       
   485 //
       
   486 TUid CWmConfiguration::StringToUid( const TDesC& aStr )
       
   487     {
       
   488     if ( aStr.Length() > 0 && aStr.Find( KHexPrefix ) == 0 )
       
   489         {
       
   490         // hex value 0x12345678
       
   491         TLex lex( aStr.Mid( KHexPrefix().Length() ) );
       
   492         TUint id = 0;
       
   493         if ( lex.Val( id, EHex ) == KErrNone )
       
   494             {
       
   495             return TUid::Uid( (TInt)id );
       
   496             }
       
   497         }
       
   498     else if (  aStr.Length() > 0 )
       
   499         {
       
   500         TLex lex( aStr );
       
   501         TUint id( 0 );
       
   502         if (  KErrNone == lex.Val( id ) )
       
   503             {
       
   504             return TUid::Uid( (TInt)id );
       
   505             }
       
   506         }
       
   507     return KNullUid;
       
   508     }
       
   509 
       
   510 
       
   511 // End of File
       
   512