idlehomescreen/widgetmanager/src/wmconfiguration.cpp
branchRCL_3
changeset 18 d05a55b217df
parent 11 ff572dfe6d86
child 19 79311d856354
equal deleted inserted replaced
17:b8fae6b8a148 18:d05a55b217df
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include <centralrepository.h>
    20 #include <centralrepository.h>
    21 #include <StringLoader.h>
    21 #include <StringLoader.h>
    22 #include <AknsConstants.h>
    22 #include <AknsConstants.h>
       
    23 #include <widgetregistryclient.h> // widget reqistry
    23 
    24 
    24 #include <widgetmanagerview.rsg>
    25 #include <widgetmanagerview.rsg>
    25 #include <widgetmanager.mbg>
    26 #include <widgetmanager.mbg>
    26 #include "wmconfiguration.h"
    27 #include "wmconfiguration.h"
    27 #include "wmresourceloader.h"
    28 #include "wmresourceloader.h"
    33 const TInt KLangOffsetOperatorUrl = KOperatorButtonUrl0 - KLangId0;
    34 const TInt KLangOffsetOperatorUrl = KOperatorButtonUrl0 - KLangId0;
    34 const TInt KLangOffsetOperatorText = KOperatorButtonText0 - KLangId0;
    35 const TInt KLangOffsetOperatorText = KOperatorButtonText0 - KLangId0;
    35 const TInt KLangGroupSize = KLangId1 - KLangId0;
    36 const TInt KLangGroupSize = KLangId1 - KLangId0;
    36 const TUint32 KLastLangId = KLangId9;
    37 const TUint32 KLastLangId = KLangId9;
    37 
    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" );
    38 
    47 
    39 // ---------------------------------------------------------
    48 // ---------------------------------------------------------
    40 // CWmConfiguration::NewL
    49 // CWmConfiguration::NewL
    41 // ---------------------------------------------------------
    50 // ---------------------------------------------------------
    42 //
    51 //
    56 //
    65 //
    57 CWmConfiguration::CWmConfiguration(
    66 CWmConfiguration::CWmConfiguration(
    58         CWmResourceLoader& aResourceLoader )
    67         CWmResourceLoader& aResourceLoader )
    59     : iResourceLoader( aResourceLoader )
    68     : iResourceLoader( aResourceLoader )
    60 	{
    69 	{
    61     iRepository = NULL;
    70 
       
    71     // ovi
    62     iOviStoreUid = KNullUid;
    72     iOviStoreUid = KNullUid;
    63     iOviStoreClientParam = NULL;
    73 
    64     iOviButtonTitle = NULL;
    74     // operator
    65     iOviButtonIcon = NULL;
    75     iOperatorAppIdUid = KNullUid;
    66     iOperatorButtonTitle = NULL;
    76     iOperatorAppType = EUnknown;
    67     iOperatorButtonIcon = NULL;
    77     iOperatorButtonEnabled = EFalse;
    68     iOperatorButtonUrl = NULL;
    78     iButtonsMirrored = EFalse;
    69 	}
    79 	}
    70 
    80 
    71 // ---------------------------------------------------------
    81 // ---------------------------------------------------------
    72 // CWmConfiguration::~CWmConfiguration()
    82 // CWmConfiguration::~CWmConfiguration()
    73 // ---------------------------------------------------------
    83 // ---------------------------------------------------------
    74 //
    84 //
    75 CWmConfiguration::~CWmConfiguration()
    85 CWmConfiguration::~CWmConfiguration()
    76 	{
    86 	{
    77     delete iRepository;
    87     delete iRepository;
       
    88     // ovi
    78     delete iOviStoreClientParam;
    89     delete iOviStoreClientParam;
    79     delete iOviButtonTitle;
    90     delete iOviButtonTitle;
    80     delete iOviButtonIcon;
    91     delete iOviButtonIcon;
       
    92     // operator
    81     delete iOperatorButtonTitle;
    93     delete iOperatorButtonTitle;
    82     delete iOperatorButtonIcon;
    94     delete iOperatorButtonIcon;
    83     delete iOperatorButtonUrl;
    95     delete iOperatorButtonUrl;
       
    96     delete iOperatorParam;
       
    97     delete iOperatorAppIdStr;
    84 	}
    98 	}
    85 
    99 
    86 // ---------------------------------------------------------
   100 // ---------------------------------------------------------
    87 // CWmConfiguration::ConstructL
   101 // CWmConfiguration::ConstructL
    88 // ---------------------------------------------------------
   102 // ---------------------------------------------------------
   116 void CWmConfiguration::LoadConfigurationL()
   130 void CWmConfiguration::LoadConfigurationL()
   117     {
   131     {
   118     iRepository = CRepository::NewL( 
   132     iRepository = CRepository::NewL( 
   119             TUid::Uid( KCrWidgetManagerm ) );
   133             TUid::Uid( KCrWidgetManagerm ) );
   120 
   134 
   121     // read fixed parameters
   135     // read Ovi parameters
   122     ReadIntParameter( KOviStoreUid, iOviStoreUid.iUid );
   136     ReadInt32Parameter( KOviStoreUid, iOviStoreUid.iUid );
   123     iOviStoreClientParam = ReadDescParameterL( KOviStoreClientParam ); 
   137     iOviStoreClientParam = ReadDescParameterL( KOviStoreClientParam ); 
   124     // determine language and read localised parameters
   138     
   125     iLanguageIndex = FindCorrectLanguageId();
   139     // read operator parameters if operator button enabled
   126     iOperatorButtonTitle = ReadLocalisedParameterL( KLangOffsetOperatorText );
   140     ReadIntParameter( KOperatorButtonEnabled, iOperatorButtonEnabled );
   127     iOperatorButtonUrl = ReadLocalisedParameterL( KLangOffsetOperatorUrl );
   141     if ( iOperatorButtonEnabled )
   128 
   142         {
   129     if ( iOperatorButtonUrl && iOperatorButtonUrl->Length() > 0 )
   143         // determine language and read localised parameters
   130         {
   144         iLanguageIndex = FindCorrectLanguageId();
   131         // construct the operator button icon.
   145         iOperatorButtonTitle = ReadLocalisedParameterL( KLangOffsetOperatorText );
       
   146         iOperatorButtonUrl = ReadLocalisedParameterL( KLangOffsetOperatorUrl );
       
   147         // read non-localised parameters
   132         iOperatorButtonIcon = ReadDescParameterL( KOperatorButtonIcon );
   148         iOperatorButtonIcon = ReadDescParameterL( KOperatorButtonIcon );
       
   149         ReadOperatorApplicationInfoL();
       
   150         iOperatorParam = ReadDescParameterL( KOperatorParam );
       
   151         ReadIntParameter( KOperatorButtonHigherPriority, iButtonsMirrored );
   133         }
   152         }
   134 
   153 
   135     delete iRepository;
   154     delete iRepository;
   136     iRepository = NULL;
   155     iRepository = NULL;
   137     }
   156     }
   189         }
   208         }
   190     return heapBuffer;
   209     return heapBuffer;
   191     }
   210     }
   192 
   211 
   193 // ---------------------------------------------------------
   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 // ---------------------------------------------------------
   194 // CWmConfiguration::ReadIntParameterIntL
   226 // CWmConfiguration::ReadIntParameterIntL
   195 // ---------------------------------------------------------
   227 // ---------------------------------------------------------
   196 //
   228 //
   197 void CWmConfiguration::ReadIntParameter( TInt aKey, TInt32& aValue )
   229 void CWmConfiguration::ReadIntParameter( TInt aKey, TInt& aValue )
   198     {
   230     {
   199     TInt read = KErrNone;
   231     aValue = 0;
   200     TInt err = iRepository->Get( aKey, read );
   232 	iRepository->Get( aKey, aValue );
   201     if( err == KErrNone )
       
   202         {
       
   203         aValue = read;
       
   204         }
       
   205     }
   233     }
   206 
   234 
   207 // ---------------------------------------------------------
   235 // ---------------------------------------------------------
   208 // CWmConfiguration::ReadLocalisedParameterL
   236 // CWmConfiguration::ReadLocalisedParameterL
   209 // ---------------------------------------------------------
   237 // ---------------------------------------------------------
   229         }
   257         }
   230     return heapBuffer;
   258     return heapBuffer;
   231     }
   259     }
   232 
   260 
   233 // ---------------------------------------------------------
   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                 SetOperatorIcon( iOperatorAppIdUid );
       
   286                 }
       
   287             else if ( !type.Compare( KOpAppTypeCwrt ) )
       
   288                 {
       
   289                 iOperatorAppType = ECwrt;
       
   290                 iOperatorAppIdUid = FetchWidgetUidFromRegistryL( appId );
       
   291                 SetOperatorIcon( iOperatorAppIdUid );
       
   292                 }
       
   293             else if ( !type.Compare( KOpAppTypeWrt ) )
       
   294                 {
       
   295                 iOperatorAppType = EWrt;
       
   296                 iOperatorAppIdUid = FetchWidgetUidFromRegistryL( appId );
       
   297                 SetOperatorIcon( 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                 SetOperatorIcon( iOperatorAppIdUid );
       
   311                 }
       
   312             }
       
   313         CleanupStack::PopAndDestroy( applicationInfo );
       
   314         }
       
   315     }
       
   316 
       
   317 // ---------------------------------------------------------
       
   318 // CWmConfiguration::SetOperatorIcon
       
   319 // ---------------------------------------------------------
       
   320 //
       
   321 void CWmConfiguration::SetOperatorIcon( TUid aUid )
       
   322     {
       
   323     if ( iOperatorButtonIcon &&
       
   324         !iOperatorButtonIcon->Des().Length() )
       
   325         {
       
   326         delete iOperatorButtonIcon;
       
   327         iOperatorButtonIcon = NULL;
       
   328         TRAP_IGNORE( 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 // ---------------------------------------------------------
   234 // CWmConfiguration::PortalButtonCount
   352 // CWmConfiguration::PortalButtonCount
   235 // ---------------------------------------------------------
   353 // ---------------------------------------------------------
   236 //
   354 //
   237 TInt CWmConfiguration::PortalButtonCount()
   355 TInt CWmConfiguration::PortalButtonCount()
   238     {
   356     {
   239     if ( iOperatorButtonUrl && iOperatorButtonUrl->Length() > 0 )
   357     return ( iOperatorButtonEnabled ? 2 : 1 );
   240         return 2;
       
   241     return 1;
       
   242     }
   358     }
   243 
   359 
   244 // ---------------------------------------------------------
   360 // ---------------------------------------------------------
   245 // CWmConfiguration::PortalButtonText
   361 // CWmConfiguration::PortalButtonText
   246 // ---------------------------------------------------------
   362 // ---------------------------------------------------------
   247 //
   363 //
   248 const TDesC& CWmConfiguration::PortalButtonText( TInt aIndex )
   364 const TDesC& CWmConfiguration::PortalButtonText( TInt aIndex )
   249     {
   365     {
   250     IndexConversion( aIndex );
       
   251     if ( aIndex == 0 && iOviButtonTitle )
   366     if ( aIndex == 0 && iOviButtonTitle )
   252         return *iOviButtonTitle;
   367         return *iOviButtonTitle;
   253     if ( aIndex == 1 && iOperatorButtonTitle )
   368     if ( aIndex == 1 && iOperatorButtonTitle && iOperatorButtonEnabled )
   254         return *iOperatorButtonTitle;
   369         return *iOperatorButtonTitle;
   255     return KNullDesC;
   370     return KNullDesC;
   256     }
   371     }
   257 
   372 
   258 // ---------------------------------------------------------
   373 // ---------------------------------------------------------
   259 // CWmConfiguration::PortalButtonIcon
   374 // CWmConfiguration::PortalButtonIcon
   260 // ---------------------------------------------------------
   375 // ---------------------------------------------------------
   261 //
   376 //
   262 const TDesC& CWmConfiguration::PortalButtonIcon( TInt aIndex )
   377 const TDesC& CWmConfiguration::PortalButtonIcon( TInt aIndex )
   263     {
   378     {
   264     IndexConversion( aIndex );
       
   265     if ( aIndex == 0 && iOviButtonIcon )
   379     if ( aIndex == 0 && iOviButtonIcon )
   266         return *iOviButtonIcon;
   380         return *iOviButtonIcon;
   267     if ( aIndex == 1 && iOperatorButtonIcon )
   381     if ( aIndex == 1 && iOperatorButtonIcon && iOperatorButtonEnabled )
   268         return *iOperatorButtonIcon;
   382         return *iOperatorButtonIcon;
   269     return KNullDesC;
   383     return KNullDesC;
   270     }
   384     }
   271 
   385 
   272 // ---------------------------------------------------------
   386 // ---------------------------------------------------------
   273 // CWmConfiguration::PortalButtonBrowserUrl
   387 // CWmConfiguration::PortalButtonBrowserUrl
   274 // ---------------------------------------------------------
   388 // ---------------------------------------------------------
   275 //
   389 //
   276 const TDesC& CWmConfiguration::PortalButtonBrowserUrl( TInt aIndex )
   390 const TDesC& CWmConfiguration::PortalButtonBrowserUrl( TInt aIndex )
   277     {
   391     {
   278     if ( aIndex == 1 && iOperatorButtonUrl )
   392     // No support for ovi here
       
   393     if ( aIndex == 1 && iOperatorButtonUrl && iOperatorButtonEnabled )
   279         return *iOperatorButtonUrl;
   394         return *iOperatorButtonUrl;
   280     return KNullDesC;
   395     return KNullDesC;
   281     }
   396     }
   282 
   397 
   283 // ---------------------------------------------------------
   398 // ---------------------------------------------------------
   288     {
   403     {
   289     if ( aIndex == 0 )
   404     if ( aIndex == 0 )
   290         {
   405         {
   291         return iOviStoreUid;
   406         return iOviStoreUid;
   292         } 
   407         } 
   293     // Operator client uid not supported. 
   408     // operator not supported. Get operator data using 
   294     // If operator client is a widget we can use widget registry 
   409     // PortalButtonApplicationInfoL
   295     // to fetch uid of operator widget save it to member and return that here
       
   296     
       
   297     return KNullUid;
   410     return KNullUid;
   298     }
   411     }
   299 
   412 
   300 // ---------------------------------------------------------
   413 // ---------------------------------------------------------
   301 // CWmConfiguration::PortalButtonClientParam
   414 // CWmConfiguration::PortalButtonClientParam
   305     {
   418     {
   306     if ( aIndex == 0 && iOviStoreClientParam )
   419     if ( aIndex == 0 && iOviStoreClientParam )
   307         {
   420         {
   308         return *iOviStoreClientParam;
   421         return *iOviStoreClientParam;
   309         }
   422         }
   310     // Operator client param not supported. Can be added if needed.
   423     if ( aIndex == 1 && iOperatorParam && iOperatorButtonEnabled )
       
   424         {
       
   425         return *iOperatorParam;
       
   426         }
   311     return KNullDesC;
   427     return KNullDesC;
   312     }
   428     }
   313 
   429 
   314 
   430 // ---------------------------------------------------------
   315 // ---------------------------------------------------------
   431 // CWmConfiguration::PortalButtonsMirrored
   316 // CWmConfiguration::IndexConversion
   432 // ---------------------------------------------------------
   317 // ---------------------------------------------------------
   433 //
   318 //
   434 TBool CWmConfiguration::PortalButtonsMirrored()
   319 void CWmConfiguration::IndexConversion( TInt& /*aIndex*/ )
   435     {
   320     {
   436     return iButtonsMirrored;
   321     // if there is a need to configure switching button places
   437     } 
   322     // (operator button left, then OVI button) then this method
   438    
   323     // would have something like this:
   439 // ---------------------------------------------------------
   324     
   440 // CWmConfiguration::PortalButtonApplicationType
   325     // if ( iSwitchButtons ) aIndex = 1 - aIndex;
   441 // ---------------------------------------------------------
   326     
   442 //
   327     // but for now, this method is empty.
   443 CWmConfiguration::TOpAppType CWmConfiguration::PortalButtonApplicationType( 
   328     }
   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 
   329 
   510 
   330 // End of File
   511 // End of File
   331 
   512