appinstaller/AppMngr2/GSSettingsPlugin/src/appmngr2gssettingsplugin.cpp
changeset 0 ba25891c3a9e
child 5 aba6b8104af3
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2003-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:   AppMngr2 Settings plug-in for GS (General Settings)
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "appmngr2gssettingsplugin.h"   // CAppMngrGSSettingsPlugin
       
    20 #include "appmngr2gssettingscontainer.h" // CAppMngr2GSSettingsContainer
       
    21 #include "appmngr2.hrh"                 // KAppMngr2AppUidValue
       
    22 #include <gsprivatepluginproviderids.h> // KGSPluginProviderInternal
       
    23 #include <appmngr2debugutils.h>         // FLOG macros
       
    24 #include <appmngr2driveutils.h>         // TAppMngr2DriveUtils
       
    25 #include <aknradiobuttonsettingpage.h>  // CAknRadioButtonSettingPage
       
    26 #include <akntextsettingpage.h>         // CAknTextSettingPage
       
    27 #include <SWInstallerInternalCRKeys.h>  // KCRUidSWInstallerSettings
       
    28 #include <centralrepository.h>          // CRepository
       
    29 #include <StringLoader.h>               // StringLoader
       
    30 #include <akntitle.h>                   // CAknTitlePane
       
    31 #include <aknnotewrappers.h>            // CAknInformationNote
       
    32 #include <hlplch.h>                     // HlpLauncher
       
    33 #include <featmgr.h>                    // FeatureManager
       
    34 #include <csxhelp/am.hlp.hrh>           // Help IDs
       
    35 #include <appmngr2gssettingspluginrsc.rsg> // Resource IDs
       
    36 #include <appmngr2.mbg>                 // Bitmap IDs
       
    37 
       
    38 _LIT( KAppMngr2GsSettingsPluginResourceFileName, "appmngr2gssettingspluginrsc.rsc" );  
       
    39 _LIT( KAppMngr2IconFileNameMif, "appmngr2.mif" );
       
    40 _LIT( KDriveZ, "z:" );
       
    41 
       
    42 // ======== MEMBER FUNCTIONS ========
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CAppMngr2GSSettingsPlugin::NewL()
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 CAppMngr2GSSettingsPlugin* CAppMngr2GSSettingsPlugin::NewL( TAny* /*aInitParams*/ )
       
    49     {
       
    50     CAppMngr2GSSettingsPlugin* self = new( ELeave ) CAppMngr2GSSettingsPlugin;
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CAppMngr2GSSettingsPlugin::~CAppMngr2GSSettingsPlugin()
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CAppMngr2GSSettingsPlugin::~CAppMngr2GSSettingsPlugin()
       
    62     {
       
    63     if( iContainer )
       
    64         {
       
    65         AppUi()->RemoveFromViewStack( *this, iContainer );
       
    66         delete iContainer;
       
    67         iContainer = NULL;
       
    68         }
       
    69     iResources.Close();
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CAppMngr2GSSettingsPlugin::GetCaptionL()
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void CAppMngr2GSSettingsPlugin::GetCaptionL( TDes& aCaption ) const
       
    77     {
       
    78     // the resource file is already opened.
       
    79     HBufC* result = StringLoader::LoadL( R_SET_FOLDER_APPLICATION_MANAGER );
       
    80     aCaption.Copy( *result );
       
    81     delete result;
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CAppMngr2GSSettingsPlugin::CreateIconL()
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 CGulIcon* CAppMngr2GSSettingsPlugin::CreateIconL( const TUid aIconType )
       
    89     {
       
    90     HBufC* iconFilePath = HBufC::NewLC( KDriveZ().Length() +
       
    91             KDC_APP_BITMAP_DIR().Length() + KAppMngr2IconFileNameMif().Length() );
       
    92     TPtr ptr = iconFilePath->Des();
       
    93     ptr.Append( KDriveZ );
       
    94     ptr.Append( KDC_APP_BITMAP_DIR );
       
    95     ptr.Append( KAppMngr2IconFileNameMif );
       
    96 
       
    97     CGulIcon* icon;
       
    98     TInt iconId = EMbmAppmngr2Qgn_prop_cp_inst_settings;
       
    99     TInt maskId = EMbmAppmngr2Qgn_prop_cp_inst_settings_mask;
       
   100     if( aIconType == KGSIconTypeLbxItem )
       
   101         {
       
   102         icon = AknsUtils::CreateGulIconL( AknsUtils::SkinInstance(),
       
   103                 KAknsIIDQgnPropCpInstSettings, *iconFilePath,
       
   104                 iconId, maskId );
       
   105         }
       
   106     else
       
   107         {
       
   108         icon = CGSPluginInterface::CreateIconL( aIconType );
       
   109         }
       
   110 
       
   111     CleanupStack::PopAndDestroy( iconFilePath );
       
   112     return icon;
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // CAppMngr2GSSettingsPlugin::PluginProviderCategory()
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 TInt CAppMngr2GSSettingsPlugin::PluginProviderCategory() const
       
   120     {
       
   121     return KGSPluginProviderInternal;
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CAppMngr2GSSettingsPlugin::Id()
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TUid CAppMngr2GSSettingsPlugin::Id() const
       
   129     {
       
   130     return KAppMngr2GSSettingsUid;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CAppMngr2GSSettingsPlugin::HandleCommandL()
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 void CAppMngr2GSSettingsPlugin::HandleCommandL( TInt aCommand )
       
   138     {
       
   139     switch ( aCommand )
       
   140         {
       
   141         case EAppMngr2CmdChange:
       
   142         case EAknSoftkeyChange:
       
   143             {
       
   144             HandleListBoxSelectionL();
       
   145             break;
       
   146             }
       
   147         case EAknSoftkeyBack:
       
   148             {
       
   149             AppUi()->ActivateLocalViewL( iPrevViewId.iViewUid );
       
   150             break;
       
   151             }
       
   152         case EAknSoftkeyExit:
       
   153             {
       
   154             static_cast<MEikCommandObserver*>( AppUi() )->ProcessCommandL( EAknCmdExit );
       
   155             break;
       
   156             }
       
   157         case EAknCmdHelp:
       
   158         case EEikCmdHelpContents:
       
   159             {
       
   160             if( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   161                 {
       
   162                 CArrayFix<TCoeHelpContext>* contexts =
       
   163                     new( ELeave ) CArrayFixFlat<TCoeHelpContext>( 1 );
       
   164                 CleanupStack::PushL( contexts );
       
   165                 TCoeHelpContext context;
       
   166                 context.iMajor = KAppMngr2AppUid;
       
   167                 context.iContext = KAM_HLP_GENERAL_SETTINGS;
       
   168                 contexts->AppendL( context );
       
   169                 CleanupStack::Pop( contexts );
       
   170                 HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), contexts );
       
   171                 }
       
   172             break;
       
   173             }
       
   174         default:
       
   175             {
       
   176             AppUi()->HandleCommandL( aCommand );
       
   177             break;
       
   178             }
       
   179         }
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // CAppMngr2GSSettingsPlugin::HandleViewRectChange()
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CAppMngr2GSSettingsPlugin::HandleViewRectChange()
       
   187     {
       
   188     if( iContainer )
       
   189         {
       
   190         iContainer->SetRect( ClientRect() );
       
   191         }
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CAppMngr2GSSettingsPlugin::DynInitMenuPaneL()
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CAppMngr2GSSettingsPlugin::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   199     {
       
   200     switch( aResourceId )
       
   201         {
       
   202         case R_APPMNGR2_SETTINGS_MENU:
       
   203             if( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   204                 {
       
   205                 aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   206                 }
       
   207             break;
       
   208         default:
       
   209             break;
       
   210         }
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CAppMngr2GSSettingsPlugin::HandleListBoxEventL()
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CAppMngr2GSSettingsPlugin::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   218         TListBoxEvent aEventType )
       
   219     {
       
   220     switch ( aEventType )
       
   221         {
       
   222         case EEventEnterKeyPressed:
       
   223         case EEventItemSingleClicked:
       
   224             HandleListBoxSelectionL();
       
   225             break;
       
   226         default:
       
   227            break;
       
   228         }
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // CAppMngr2GSSettingsPlugin::DoActivateL()
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 void CAppMngr2GSSettingsPlugin::DoActivateL( const TVwsViewId& aPrevViewId,
       
   236         TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/ )
       
   237     {
       
   238     iPrevViewId = aPrevViewId;
       
   239     if( iContainer )
       
   240         {
       
   241         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   242         delete iContainer;
       
   243         iContainer = NULL;
       
   244         }
       
   245     HBufC* jamSetTitle = StringLoader::LoadLC( R_AM_INSTALLATION_SETTINGS_TITLE );
       
   246     CEikStatusPane* statusPane = StatusPane();
       
   247     CAknTitlePane* titlePane;
       
   248     titlePane = ( CAknTitlePane* ) statusPane->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) );
       
   249     titlePane->SetTextL( jamSetTitle->Des() );
       
   250     CleanupStack::PopAndDestroy( jamSetTitle );
       
   251     jamSetTitle = NULL;
       
   252 
       
   253     iContainer = CAppMngr2GSSettingsContainer::NewL( ClientRect() );
       
   254     iContainer->SetMopParent( this );
       
   255     iContainer->MakeVisible( ETrue );
       
   256     iContainer->SetRect( ClientRect() );
       
   257     iContainer->ActivateL();
       
   258     AppUi()->AddToStackL( *this, iContainer );
       
   259     iContainer->ListBox()->SetListBoxObserver( this );
       
   260     }
       
   261 
       
   262 // ---------------------------------------------------------------------------
       
   263 // CAppMngr2GSSettingsPlugin::DoDeactivate()
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 void CAppMngr2GSSettingsPlugin::DoDeactivate()
       
   267     {
       
   268     if( iContainer )
       
   269         {
       
   270         iContainer->MakeVisible( EFalse );
       
   271         AppUi()->RemoveFromViewStack( *this, iContainer );
       
   272         delete iContainer;
       
   273         iContainer = NULL;
       
   274         }
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // CAppMngr2GSSettingsPlugin::HandleForegroundEventL()
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 void CAppMngr2GSSettingsPlugin::HandleForegroundEventL( TBool aForeground )
       
   282     {
       
   283     if( aForeground )
       
   284         {
       
   285         iContainer->UpdateListBoxContentL();
       
   286         }
       
   287     }
       
   288 
       
   289 // ---------------------------------------------------------------------------
       
   290 // CAppMngr2GSSettingsPlugin::CAppMngr2GSSettingsPlugin()
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 CAppMngr2GSSettingsPlugin::CAppMngr2GSSettingsPlugin() : iResources( *CCoeEnv::Static() )
       
   294     {
       
   295     }
       
   296 
       
   297 // ---------------------------------------------------------------------------
       
   298 // CAppMngr2GSSettingsPlugin::ConstructL()
       
   299 // ---------------------------------------------------------------------------
       
   300 //
       
   301 void CAppMngr2GSSettingsPlugin::ConstructL()
       
   302     {
       
   303     TFileName* fileName = TAppMngr2DriveUtils::NearestResourceFileLC(
       
   304             KAppMngr2GsSettingsPluginResourceFileName, iCoeEnv->FsSession() );
       
   305     
       
   306     iResources.OpenL( *fileName );
       
   307     BaseConstructL( R_APPMNGR2_SETTINGS_VIEW );
       
   308 
       
   309     CleanupStack::PopAndDestroy( fileName );
       
   310     }
       
   311 
       
   312 // ---------------------------------------------------------------------------
       
   313 // CAppMngr2GSSettingsPlugin::HandleListBoxSelectionL()
       
   314 // ---------------------------------------------------------------------------
       
   315 //
       
   316 void CAppMngr2GSSettingsPlugin::HandleListBoxSelectionL()
       
   317     {
       
   318     TInt currentIndex = iContainer->ListBox()->CurrentItemIndex();
       
   319     ShowSettingPageL( currentIndex );
       
   320     }
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // CAppMngr2GSSettingsPlugin::ShowSettingPageL()
       
   324 // ---------------------------------------------------------------------------
       
   325 //
       
   326 void CAppMngr2GSSettingsPlugin::ShowSettingPageL( TInt aSettingIndex )
       
   327     {
       
   328     FLOG( "CAppMngr2GSSettingsPlugin: ShowSettingPageL( %d )", aSettingIndex );
       
   329 
       
   330     // Variation flag may be used to hide "allow untrusted" option 
       
   331     TInt hideAllowUntrusted = 1;
       
   332     CRepository* variationDB = CRepository::NewLC( KCRUidSWInstallerLV );
       
   333     variationDB->Get( KSWInstallerHideUntrustedIns, hideAllowUntrusted );
       
   334     CleanupStack::PopAndDestroy( variationDB );
       
   335     if( hideAllowUntrusted )
       
   336         {
       
   337         // Increase the setting index so that allow untrusted is not taken into account
       
   338         aSettingIndex++;
       
   339         }
       
   340 
       
   341     if( aSettingIndex == EAppMngr2SettingOcsp || aSettingIndex == EAppMngr2SettingOcspUrl )
       
   342         {
       
   343         if( !FeatureManager::FeatureSupported( KFeatureIdOCSP ) )
       
   344             {
       
   345             // If OCSP feature is not supported, it's not allowed to change values
       
   346             HBufC* p = StringLoader::LoadLC( R_AM_NOTE_LOCKED_SETTIGS );
       
   347             CAknInformationNote* note = new ( ELeave ) CAknInformationNote( ETrue );
       
   348             note->ExecuteLD( p->Des() );
       
   349             CleanupStack::PopAndDestroy( p );
       
   350             return;
       
   351             }
       
   352         }
       
   353 
       
   354     HBufC* urlTextStr = HBufC::NewLC( NCentralRepositoryConstants::KMaxUnicodeStringLength );
       
   355     TPtr urlText( urlTextStr->Des() );
       
   356     urlText.Zero();
       
   357     TInt newIndex = 0;
       
   358 
       
   359     if( aSettingIndex == EAppMngr2SettingSwInstall || aSettingIndex == EAppMngr2SettingOcsp )
       
   360         {
       
   361         CRepository* repDB = CRepository::NewLC( KCRUidSWInstallerSettings );
       
   362         CAknSettingPage* dlg = NULL;
       
   363         CDesCArrayFlat* itemArray = NULL;
       
   364 
       
   365         if( aSettingIndex == EAppMngr2SettingSwInstall )
       
   366             {
       
   367             // Install software
       
   368             itemArray = iCoeEnv->ReadDesC16ArrayResourceL(
       
   369                     R_APPMNGR2_ALLOW_UNTRUSTED_VALUE_ARRAY );
       
   370             repDB->Get( KSWInstallerAllowUntrusted, newIndex );
       
   371             if( newIndex )
       
   372                 {
       
   373                 newIndex = 1;
       
   374                 }
       
   375             dlg = new ( ELeave ) CAknRadioButtonSettingPage(
       
   376                     R_APPMNGR2_SET_PAGE_ALLOW_UNTRUSTED,
       
   377                     newIndex, itemArray );
       
   378             }
       
   379         else
       
   380             {
       
   381             // OCSP check
       
   382             repDB->Get( KSWInstallerOcspProcedure, newIndex );
       
   383             newIndex = MapOCSPIndex( newIndex );
       
   384             itemArray = iCoeEnv->ReadDesC16ArrayResourceL(
       
   385                     R_APPMNGR2_OCSP_CHECK_VALUE_ARRAY );
       
   386             dlg = new ( ELeave ) CAknRadioButtonSettingPage(
       
   387                     R_APPMNGR2_OCSP_CHECK_PAGE, newIndex, itemArray );
       
   388             }
       
   389         CleanupStack::PopAndDestroy( repDB );
       
   390         CleanupStack::PushL( itemArray );
       
   391 
       
   392         if( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) )
       
   393             {
       
   394             SetPermissionL( aSettingIndex, newIndex, urlText );
       
   395             }
       
   396         CleanupStack::PopAndDestroy( itemArray );
       
   397         }
       
   398     else if( aSettingIndex == EAppMngr2SettingOcspUrl )
       
   399         {
       
   400         CRepository* repDB = CRepository::NewLC( KCRUidSWInstallerSettings );
       
   401         repDB->Get( KSWInstallerOcspDefaultURL, urlText );
       
   402         CAknTextSettingPage* textDlg = new ( ELeave ) CAknTextSettingPage(
       
   403                 R_APPMNGR2_OCSP_URL_SETTING_PAGE, urlText,
       
   404                 CAknTextSettingPage::EZeroLengthAllowed );
       
   405         CleanupStack::PushL( textDlg );
       
   406         textDlg->ConstructL();
       
   407         textDlg->TextControl()->SetTextLimit( KAppMngr2MaxOcspUrlLength );
       
   408 
       
   409         CleanupStack::Pop( textDlg );
       
   410         CleanupStack::PopAndDestroy( repDB );
       
   411 
       
   412         if( textDlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) )
       
   413             {
       
   414             // Remove spaces from URL text
       
   415             for( TInt pos = urlText.Length() - 1; pos >= 0; --pos ) {
       
   416                 if( TChar( urlText[pos] ).IsSpace() ) {
       
   417                     urlText.Delete( pos, 1 );
       
   418                 }
       
   419             }
       
   420             SetPermissionL( aSettingIndex, newIndex, urlText );
       
   421             }
       
   422         }
       
   423     else
       
   424         {
       
   425         ASSERT( EFalse );
       
   426         }
       
   427     
       
   428     CleanupStack::PopAndDestroy( urlTextStr );
       
   429     }
       
   430 
       
   431 // ---------------------------------------------------------------------------
       
   432 // CAppMngr2GSSettingsPlugin::SetPermissionL()
       
   433 // ---------------------------------------------------------------------------
       
   434 //
       
   435 void CAppMngr2GSSettingsPlugin::SetPermissionL( TInt aSettingIndex,
       
   436                                        TInt aNewValueIndex,
       
   437                                        TPtrC16 aUrlText )
       
   438     {
       
   439     FLOG( "CAppMngr2GSSettingsPlugin::SetPermissionL( %d, %d, %S )",
       
   440             aSettingIndex, aNewValueIndex, &aUrlText );
       
   441 
       
   442     // Write the setting value to Central repository
       
   443     CRepository* repDB = CRepository::NewLC( KCRUidSWInstallerSettings );
       
   444     switch( aSettingIndex )
       
   445         {
       
   446         case EAppMngr2SettingSwInstall:
       
   447             repDB->Set( KSWInstallerAllowUntrusted, aNewValueIndex );
       
   448             break;
       
   449         case EAppMngr2SettingOcsp:
       
   450             aNewValueIndex = MapOCSPIndex( aNewValueIndex );
       
   451             repDB->Set( KSWInstallerOcspProcedure, aNewValueIndex );
       
   452             break;
       
   453         case EAppMngr2SettingOcspUrl:
       
   454             repDB->Set( KSWInstallerOcspDefaultURL, aUrlText );
       
   455             break;
       
   456         default:
       
   457             ASSERT( EFalse );
       
   458             break;
       
   459         }
       
   460     CleanupStack::PopAndDestroy( repDB );
       
   461 
       
   462     iContainer->UpdateListBoxContentL();
       
   463     }
       
   464 
       
   465 // ---------------------------------------------------------------------------
       
   466 // CAppMngr2GSSettingsPlugin::MapOCSPIndex()
       
   467 // ---------------------------------------------------------------------------
       
   468 //
       
   469 TInt CAppMngr2GSSettingsPlugin::MapOCSPIndex( TInt aValue )
       
   470     {
       
   471     TInt result = 0;
       
   472 
       
   473     switch( aValue )
       
   474         {
       
   475         case ESWInstallerOcspProcedureOff:
       
   476             result = EAppMngr2OcspCheckValueArrayOff;
       
   477             break;
       
   478         case ESWInstallerOcspProcedureOn:
       
   479             result = EAppMngr2OcspCheckValueArrayOn;
       
   480             break;
       
   481         case ESWInstallerOcspProcedureMust:
       
   482             result = EAppMngr2OcspCheckValueArrayMustPass;
       
   483             break;
       
   484         default:
       
   485             break;
       
   486         }
       
   487 
       
   488     return result;
       
   489     }
       
   490