idlehomescreen/widgetmanager/src/wmconfiguration.cpp
changeset 2 08c6ee43b396
child 4 4d54b72983ae
equal deleted inserted replaced
1:5315654608de 2:08c6ee43b396
       
     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 
       
    24 #include <widgetmanagerview.rsg>
       
    25 #include <widgetmanager.mbg>
       
    26 #include "wmconfiguration.h"
       
    27 #include "wmresourceloader.h"
       
    28 #include "wmcrkeys.h"
       
    29 
       
    30 // CONSTANTS
       
    31 const TInt KMaxIconDescriptorLength = 256;
       
    32 
       
    33 // ---------------------------------------------------------
       
    34 // CWmConfiguration::NewL
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 CWmConfiguration* CWmConfiguration::NewL(
       
    38         CWmResourceLoader& aResourceLoader )
       
    39     {
       
    40     CWmConfiguration* self = new (ELeave) CWmConfiguration( aResourceLoader );
       
    41     CleanupStack::PushL( self );
       
    42     self->ConstructL();
       
    43     CleanupStack::Pop( self );
       
    44     return self;
       
    45     }
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CWmConfiguration::CWmConfiguration()
       
    49 // ---------------------------------------------------------
       
    50 //
       
    51 CWmConfiguration::CWmConfiguration(
       
    52         CWmResourceLoader& aResourceLoader )
       
    53     : iResourceLoader( aResourceLoader )
       
    54 	{
       
    55     iOviStoreText = NULL;
       
    56     iOviStoreIcon = NULL;
       
    57 	iRepository = NULL;
       
    58 	iOviStoreBundleId = NULL;
       
    59 	iOviStoreClientParam = NULL;
       
    60     iOviStoreUrl = NULL;
       
    61 	}
       
    62 
       
    63 // ---------------------------------------------------------
       
    64 // CWmConfiguration::~CWmConfiguration()
       
    65 // ---------------------------------------------------------
       
    66 //
       
    67 CWmConfiguration::~CWmConfiguration()
       
    68 	{
       
    69     delete iOviStoreText;
       
    70     delete iOviStoreIcon;
       
    71 	delete iRepository;
       
    72     delete iOviStoreBundleId;
       
    73     delete iOviStoreClientParam;
       
    74     delete iOviStoreUrl;
       
    75 	}
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // CWmConfiguration::ConstructL
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 void CWmConfiguration::ConstructL()
       
    82 	{
       
    83 	// localised ovistore button text
       
    84     iOviStoreText = StringLoader::LoadL( R_QTN_WM_GO_TO_OVI_STORE );
       
    85 
       
    86     // ovistore icon descriptor. It will look something like this:
       
    87     // skin( 0x101f86e3 0x23f6 ):mif( z:\resource\apps\widgetmanager.mif 16388 16389 )
       
    88     TBuf<KMaxIconDescriptorLength> buf;
       
    89     _LIT( KSkinMifIconFormat, "skin( 0x%x 0x%x ):mif( %S %d %d )");
       
    90     buf.Format( KSkinMifIconFormat(),
       
    91              EAknsMajorGeneric, EAknsMinorGenericQgnMenuOviStore,
       
    92              &iResourceLoader.IconFilePath(),
       
    93              EMbmWidgetmanagerQgn_menu_ovistore,
       
    94              EMbmWidgetmanagerQgn_menu_ovistore_mask );
       
    95     iOviStoreIcon = buf.AllocL();
       
    96 
       
    97     // read data from repository
       
    98     TRAP_IGNORE(
       
    99         iRepository = CRepository::NewL( 
       
   100                 TUid::Uid( KCrWidgetManagerm ) );
       
   101     
       
   102         iLanguageIndex = FindCorrectLanguageId();
       
   103         iOviStoreBundleId = ReadParameterL( KOviStoreBunbleId );
       
   104         iOviStoreClientParam = ReadParameterL( KOviStoreClientParam );
       
   105         iOviStoreUrl = ReadLocalisedParameterL( KOviStoreBrowserUrlOffset );
       
   106         );
       
   107 	}
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // CWmConfiguration::FindCorrectLanguageId
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 TInt CWmConfiguration::FindCorrectLanguageId()
       
   114     {
       
   115     TInt languageIndex = KErrNotFound; // the correct language
       
   116     TInt englishIndex = KErrNotFound; // english
       
   117     TInt anyIndex = KErrNotFound; // backup - any existing
       
   118     TLanguage sysLang = User::Language();
       
   119     
       
   120     //read language id's from cenrep, find a match
       
   121     for( TUint32 i=KLangId0; i<=KLangId9 && languageIndex<0; i+=KLangGroupSize )
       
   122         {
       
   123         TInt crLang = 0;
       
   124         if ( iRepository->Get( i, crLang ) == KErrNone )
       
   125             {
       
   126             if ( crLang == sysLang && languageIndex < 0 )
       
   127                 { languageIndex = i; }
       
   128             if ( crLang == ELangEnglish && englishIndex < 0 )
       
   129                 { englishIndex = i; }
       
   130             if ( crLang > 0 && anyIndex < 0 )
       
   131                 { anyIndex = i; }
       
   132             }
       
   133         }
       
   134     
       
   135     // if correct language was not found, use english
       
   136     if ( languageIndex < 0 ) languageIndex = englishIndex;
       
   137     // if english was not found, use any configured language
       
   138     if ( languageIndex < 0 ) languageIndex = anyIndex;
       
   139     // if there are no languages configured, we're in trouble...
       
   140     if ( languageIndex < 0 ) languageIndex = 0;
       
   141     
       
   142     return languageIndex;
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------
       
   146 // CWmConfiguration::ReadParameterL
       
   147 // ---------------------------------------------------------
       
   148 //
       
   149 HBufC* CWmConfiguration::ReadParameterL( TInt aKey )
       
   150     {
       
   151     TBuf<NCentralRepositoryConstants::KMaxUnicodeStringLength> buf;
       
   152     TInt err = iRepository->Get( aKey, buf );
       
   153 
       
   154     HBufC* heapBuffer = NULL;
       
   155     if ( err == KErrNone )
       
   156         {
       
   157         heapBuffer = HBufC::NewL( buf.Length() );
       
   158         heapBuffer->Des().Copy( buf );
       
   159         }
       
   160     return heapBuffer;
       
   161     }
       
   162 
       
   163 // ---------------------------------------------------------
       
   164 // CWmConfiguration::ReadLocalisedParameterL
       
   165 // ---------------------------------------------------------
       
   166 //
       
   167 HBufC* CWmConfiguration::ReadLocalisedParameterL(
       
   168         TInt aOffset )
       
   169     {
       
   170     TBuf<NCentralRepositoryConstants::KMaxUnicodeStringLength> buf;
       
   171     TInt err = KErrNone;
       
   172     
       
   173     err = iRepository->Get( iLanguageIndex + aOffset, buf );
       
   174     if ( err != KErrNone || buf.Length() == 0 )
       
   175         {
       
   176         // This language is empty. Try default language (index 0)
       
   177         err = iRepository->Get( KLangId0 + aOffset, buf );
       
   178         }
       
   179 
       
   180     // construct string in heap
       
   181     HBufC* heapBuffer = NULL;
       
   182     if ( err == KErrNone )
       
   183         {
       
   184         heapBuffer = buf.AllocL();
       
   185         }
       
   186     return heapBuffer;
       
   187     }
       
   188 
       
   189 // ---------------------------------------------------------
       
   190 // CWmConfiguration::PortalButtonCount
       
   191 // ---------------------------------------------------------
       
   192 //
       
   193 TInt CWmConfiguration::PortalButtonCount()
       
   194 	{
       
   195 	return 1;
       
   196 	}
       
   197 
       
   198 // ---------------------------------------------------------
       
   199 // CWmConfiguration::PortalButtonText
       
   200 // ---------------------------------------------------------
       
   201 //
       
   202 const TDesC& CWmConfiguration::PortalButtonText( TInt aIndex )
       
   203     {
       
   204     if ( aIndex == 0 && iOviStoreText ) return *iOviStoreText;
       
   205     return KNullDesC;
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------
       
   209 // CWmConfiguration::PortalButtonIcon
       
   210 // ---------------------------------------------------------
       
   211 //
       
   212 const TDesC& CWmConfiguration::PortalButtonIcon( TInt aIndex )
       
   213     {
       
   214     if ( aIndex == 0 && iOviStoreIcon ) return *iOviStoreIcon;
       
   215     return KNullDesC;
       
   216     }
       
   217 
       
   218 // ---------------------------------------------------------
       
   219 // CWmConfiguration::PortalButtonBundleId
       
   220 // ---------------------------------------------------------
       
   221 //
       
   222 const TDesC&
       
   223     CWmConfiguration::PortalButtonBundleId( TInt aIndex )
       
   224     {
       
   225     if ( aIndex == 0 && iOviStoreBundleId ) return *iOviStoreBundleId;
       
   226     return KNullDesC;
       
   227     }
       
   228 
       
   229 
       
   230 // ---------------------------------------------------------
       
   231 // CWmConfiguration::PortalButtonPrimaryMethod
       
   232 // ---------------------------------------------------------
       
   233 //
       
   234 CWmConfiguration::TMethod
       
   235     CWmConfiguration::PortalButtonPrimaryMethod( TInt aIndex )
       
   236     {
       
   237     if ( aIndex == 0 && iOviStoreClientParam ) return EWidget;
       
   238     return ENone;
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------
       
   242 // CWmConfiguration::PortalButtonPrimaryParams
       
   243 // ---------------------------------------------------------
       
   244 //
       
   245 const TDesC&
       
   246     CWmConfiguration::PortalButtonPrimaryParams( TInt aIndex )
       
   247     {
       
   248     if ( aIndex == 0 && iOviStoreClientParam ) return *iOviStoreClientParam;
       
   249     return KNullDesC;
       
   250     }
       
   251 
       
   252 
       
   253 // ---------------------------------------------------------
       
   254 // CWmConfiguration::PortalButtonSecondaryMethod
       
   255 // ---------------------------------------------------------
       
   256 //
       
   257 CWmConfiguration::TMethod
       
   258     CWmConfiguration::PortalButtonSecondaryMethod( TInt aIndex )
       
   259     {
       
   260     if ( aIndex == 0 && iOviStoreUrl ) return EHttp;
       
   261     return ENone;
       
   262     }
       
   263 
       
   264 // ---------------------------------------------------------
       
   265 // CWmConfiguration::PortalButtonSecondaryParams
       
   266 // ---------------------------------------------------------
       
   267 //
       
   268 const TDesC&
       
   269     CWmConfiguration::PortalButtonSecondaryParams( TInt aIndex )
       
   270     {
       
   271     if ( aIndex == 0 && iOviStoreUrl ) return *iOviStoreUrl;
       
   272     return KNullDesC;
       
   273     }
       
   274 
       
   275 
       
   276 
       
   277 
       
   278 // End of File
       
   279