wlansecuritysettings/wapisecuritysettingsui/src/wapisecuritysettingsdlg.cpp
changeset 17 8840d3e38314
equal deleted inserted replaced
2:1c7bc153c08e 17:8840d3e38314
       
     1 /*
       
     2 * ============================================================================
       
     3 *  Name     : wapisecuritysettingsdlg.cpp
       
     4 *  Part of  : WAPI Security Settings UI
       
     5 *
       
     6 *  Description:
       
     7 *     Implementation of dialog.
       
     8 *
       
     9 *  Version: %version:  16 %
       
    10 *
       
    11 *  Copyright (C) 2008 Nokia Corporation.
       
    12 *  This material, including documentation and any related 
       
    13 *  computer programs, is protected by copyright controlled by 
       
    14 *  Nokia Corporation. All rights are reserved. Copying, 
       
    15 *  including reproducing, storing,  adapting or translating, any 
       
    16 *  or all of this material requires the prior written consent of 
       
    17 *  Nokia Corporation. This material also contains confidential 
       
    18 *  information which may not be disclosed to others without the 
       
    19 *  prior written consent of Nokia Corporation.
       
    20 *
       
    21 * ============================================================================
       
    22 */
       
    23 
       
    24 // INCLUDE FILES
       
    25 #include <aknnavide.h>
       
    26 #include <akntitle.h>
       
    27 #include <aknradiobuttonsettingpage.h>
       
    28 #include <akntextsettingpage.h>
       
    29 #include <aknmfnesettingpage.h>
       
    30 #include <barsread.h>
       
    31 #include <StringLoader.h>
       
    32 #include <aknnotewrappers.h>
       
    33 
       
    34 #include <wapisecuritysettingsui.h>
       
    35 #include <wapisecuritysettingsui.rsg>
       
    36 #include "wapisecuritysettingsimpl.h"
       
    37 #include "wapisecuritysettingsuipanic.h"
       
    38 #include "wapisecuritysettingsdlg.h"
       
    39 #include "wapisecuritysettingsui.hrh"
       
    40 
       
    41 #include <hlplch.h>
       
    42 #include <csxhelp/wapi.hlp.hrh>
       
    43 
       
    44 #include <featmgr.h>
       
    45 
       
    46 
       
    47 // CONSTANT DECLARATIONS
       
    48 
       
    49 // Number of fields of main view
       
    50 LOCAL_D const TInt KNumOfFieldsMain = 3;
       
    51 
       
    52 LOCAL_D const TInt KTitles_Wapi_Main_Cert[KNumOfFieldsMain] =
       
    53                    {
       
    54                    R_WAPI_AUTH,
       
    55                    R_WAPI_CLIENT_CERT,
       
    56                    R_WAPI_ROOT_CERT
       
    57                    };
       
    58 LOCAL_D const TInt KFields_Wapi_Main_Cert[KNumOfFieldsMain] =
       
    59                    {
       
    60                    CWAPISecuritySettingsDlg::EWapiAuth,
       
    61                    CWAPISecuritySettingsDlg::EWapiUserCert,
       
    62                    CWAPISecuritySettingsDlg::EWapiCACert
       
    63                    };
       
    64 
       
    65 LOCAL_D const TInt KTitles_Wapi_Main_PSK[KNumOfFieldsMain] =
       
    66                    {
       
    67                    R_WAPI_AUTH,
       
    68                    R_WAPI_PRESHARED_KEY_FORMAT,
       
    69                    R_WAPI_PRESHARED_KEY
       
    70                    };
       
    71 LOCAL_D const TInt KFields_Wapi_Main_PSK[KNumOfFieldsMain] =
       
    72                    {
       
    73                    CWAPISecuritySettingsDlg::EWapiAuth,
       
    74                    CWAPISecuritySettingsDlg::EWapiPSKFormat,
       
    75                    CWAPISecuritySettingsDlg::EWapiPSK
       
    76                    };
       
    77 
       
    78 
       
    79 // ================= MEMBER FUNCTIONS =======================
       
    80 
       
    81 // ---------------------------------------------------------
       
    82 // CWAPISecuritySettingsDlg::CWAPISecuritySettingsDlg
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 CWAPISecuritySettingsDlg::CWAPISecuritySettingsDlg( TInt& aEventStore )
       
    86 : iEventStore( &aEventStore )
       
    87     {
       
    88     }
       
    89 
       
    90 
       
    91 // ---------------------------------------------------------
       
    92 // CWAPISecuritySettingsDlg::~CWAPISecuritySettingsDlg
       
    93 // ---------------------------------------------------------
       
    94 //
       
    95 CWAPISecuritySettingsDlg::~CWAPISecuritySettingsDlg()
       
    96     {
       
    97     if ( iTitlePane )
       
    98         {
       
    99         // set old text back, if we have it...
       
   100         if ( iOldTitleText )
       
   101             {
       
   102             TRAP_IGNORE( iTitlePane->SetTextL( *iOldTitleText ) );
       
   103             delete iOldTitleText;
       
   104             }
       
   105         }
       
   106     FeatureManager::UnInitializeLib();
       
   107      }
       
   108 
       
   109 
       
   110 // ---------------------------------------------------------
       
   111 // CWAPISecuritySettingsDlg::NewL
       
   112 // ---------------------------------------------------------
       
   113 //
       
   114 CWAPISecuritySettingsDlg* CWAPISecuritySettingsDlg::NewL( TInt& aEventStore )
       
   115     {
       
   116     CWAPISecuritySettingsDlg* secSett = 
       
   117                         new ( ELeave )CWAPISecuritySettingsDlg( aEventStore );
       
   118     return secSett;
       
   119     }
       
   120 
       
   121 
       
   122 // ---------------------------------------------------------
       
   123 // CWAPISecuritySettingsDlg::ConstructAndRunLD
       
   124 // ---------------------------------------------------------
       
   125 //
       
   126 TInt CWAPISecuritySettingsDlg::ConstructAndRunLD( 
       
   127                                 CWAPISecuritySettingsImpl* aSecuritySettings,
       
   128                                 const TDesC& aTitle )
       
   129     {
       
   130 	CleanupStack::PushL( this );
       
   131 
       
   132 	iSecuritySettings = aSecuritySettings;
       
   133     iConnectionName = aTitle;
       
   134 
       
   135     // Build menu according to current authentication scheme.
       
   136     if (iSecuritySettings->GetAuthentication() == EWapiAuthPSK)
       
   137         {
       
   138         iFieldsMain = ( TWapiMember* ) KFields_Wapi_Main_PSK;
       
   139         iTitlesMain = MUTABLE_CAST( TInt*, KTitles_Wapi_Main_PSK );
       
   140         }
       
   141     else // ... == EWapiAuthCert
       
   142         {
       
   143         iFieldsMain = ( TWapiMember* ) KFields_Wapi_Main_Cert;
       
   144         iTitlesMain = MUTABLE_CAST( TInt*, KTitles_Wapi_Main_Cert );
       
   145         }
       
   146     
       
   147     //Let's fetch pointers to the certificate arrays
       
   148 
       
   149     iSecuritySettings->GetCertificateLabels( iUserCertificates, iCACertificates );
       
   150 
       
   151     #if defined( _DEBUG ) || defined( DEBUG )
       
   152     if ( iUserCertificates )
       
   153         {
       
   154         RDebug::Print(_L("CWAPISecuritySettingsDlg::ConstructAndRunLD, %d user certs"), iUserCertificates->Count() );
       
   155         }
       
   156     else
       
   157         {
       
   158         RDebug::Print(_L("CWAPISecuritySettingsDlg::ConstructAndRunLD, no user certs") );
       
   159         }
       
   160     
       
   161     if ( iCACertificates )
       
   162         {
       
   163         RDebug::Print(_L("CWAPISecuritySettingsDlg::ConstructAndRunLD, %d ca certs"), iCACertificates->Count() );
       
   164         }
       
   165     else
       
   166         {
       
   167         RDebug::Print(_L("CWAPISecuritySettingsDlg::ConstructAndRunLD, no ca certs") );
       
   168         }
       
   169     #endif
       
   170     
       
   171     FeatureManager::InitializeLibL();
       
   172 
       
   173     ConstructL( R_WAPI_SECURITY_SETTINGS_MENUBAR );
       
   174     
       
   175     // ExecuteLD will PushL( this ), so we have to Pop it...
       
   176     CleanupStack::Pop( this ); // this
       
   177     return ExecuteLD( R_WAPISETTINGS_DIALOG );
       
   178     }
       
   179 
       
   180 
       
   181 // ---------------------------------------------------------
       
   182 // CWAPISecuritySettingsDlg::OkToExitL
       
   183 // ---------------------------------------------------------
       
   184 //
       
   185 TBool CWAPISecuritySettingsDlg::OkToExitL( TInt aButtonId )
       
   186 {
       
   187     // Translate the button presses into commands for the appui & current
       
   188     // view to handle
       
   189     TBool retval( EFalse );
       
   190     if ( aButtonId == EAknSoftkeyOptions )
       
   191         {
       
   192         DisplayMenuL();
       
   193         }
       
   194     else if ( aButtonId == EEikCmdExit )        // ShutDown requested
       
   195         {
       
   196         *iEventStore |= CWAPISecuritySettings::EShutDownReq;
       
   197         retval = ETrue;
       
   198         }
       
   199     else if ( aButtonId == EAknSoftkeyBack || aButtonId == EAknCmdExit )
       
   200         {
       
   201         if (iSecuritySettings->GetAuthentication() == EWapiAuthPSK)
       
   202             {
       
   203             if (iSecuritySettings->IsValid())
       
   204                 {
       
   205                 *iEventStore |= CWAPISecuritySettings::EValid;
       
   206                 retval = ETrue;
       
   207                 }
       
   208             else if ( aButtonId == EAknSoftkeyBack )
       
   209                 {
       
   210                 HBufC* stringHolder = StringLoader::LoadL(
       
   211                                 R_WAPI_QUEST_PRESHARED_KEY_DATA_MISSING, iEikonEnv );
       
   212                 CleanupStack::PushL( stringHolder );
       
   213     
       
   214                 CAknQueryDialog *queryDialog = new (ELeave) CAknQueryDialog();
       
   215     
       
   216                 queryDialog->PrepareLC( R_WAPI_SEC_SETT_CONF_QUERY );
       
   217                 queryDialog->SetPromptL( stringHolder->Des() );
       
   218                 retval = queryDialog->RunLD();
       
   219     
       
   220                 CleanupStack::PopAndDestroy( stringHolder );   // stringHolder
       
   221     
       
   222                 }
       
   223             else
       
   224                 {
       
   225                 retval = ETrue;
       
   226                 }
       
   227             }
       
   228         else
       
   229             {
       
   230             *iEventStore |= CWAPISecuritySettings::EValid;
       
   231             retval = ETrue;
       
   232             }
       
   233         
       
   234         if ( aButtonId == EAknCmdExit )
       
   235             {
       
   236             *iEventStore |= CWAPISecuritySettings::EExitReq;
       
   237             }
       
   238         
       
   239         }
       
   240     else if( aButtonId == EWapiSelCmdChange )
       
   241         {
       
   242         ChangeSettingsL();
       
   243         retval = EFalse; // don't exit the dialog
       
   244         }
       
   245 
       
   246     return retval;
       
   247 }
       
   248 
       
   249 
       
   250 // ---------------------------------------------------------
       
   251 // CWAPISecuritySettingsDlg::OfferKeyEventL
       
   252 // ---------------------------------------------------------
       
   253 //
       
   254 TKeyResponse CWAPISecuritySettingsDlg::OfferKeyEventL( 
       
   255                                 const TKeyEvent& aKeyEvent, TEventCode aType )
       
   256     {
       
   257     TKeyResponse retval( EKeyWasNotConsumed );
       
   258     TChar charCode( aKeyEvent.iCode );
       
   259 
       
   260     // Only interested in standard key events
       
   261     if ( aType == EEventKey )
       
   262         {
       
   263         // If a menu is showing offer key events to it.
       
   264         if ( CAknDialog::MenuShowing() )
       
   265             {
       
   266             retval = CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
   267             }
       
   268         else
       
   269             {
       
   270             if ( iList )
       
   271                 {
       
   272                 // as list IS consuming, must handle because it IS 
       
   273                 //the SHUTDOWN or, a view switch is shutting us down...
       
   274                 if ( aKeyEvent.iCode == EKeyEscape )
       
   275                     {
       
   276                     ProcessCommandL( EEikCmdExit );
       
   277                     retval = EKeyWasConsumed;
       
   278                     }
       
   279                 else
       
   280                     {
       
   281                     retval = iList->OfferKeyEventL( aKeyEvent, aType );
       
   282                     }
       
   283                 }
       
   284             else
       
   285                 {
       
   286                 if ( aKeyEvent.iCode == EKeyOK )
       
   287                     {
       
   288                     ProcessCommandL( EWapiSelCmdChange );
       
   289                     retval = EKeyWasConsumed;
       
   290                     }
       
   291                 }
       
   292             }
       
   293         }
       
   294     return retval;
       
   295     }
       
   296 
       
   297 
       
   298 // ---------------------------------------------------------
       
   299 // CWAPISecuritySettingsDlg::HandleListboxDataChangeL
       
   300 // ---------------------------------------------------------
       
   301 //
       
   302 void CWAPISecuritySettingsDlg::HandleListboxDataChangeL()
       
   303     {
       
   304     // fill up our new list with data
       
   305     CDesCArrayFlat* itemArray = new ( ELeave ) CDesCArrayFlat( 4 );
       
   306     CleanupStack::PushL( itemArray );
       
   307 
       
   308     FillListWithDataL( *itemArray, *iFieldsMain, KNumOfFieldsMain, 
       
   309             iTitlesMain );
       
   310 
       
   311     iList->Model()->SetItemTextArray( itemArray );
       
   312     
       
   313     CleanupStack::Pop( itemArray ); // now it is owned by the LB, so pop it
       
   314     iItemArray = itemArray;
       
   315 
       
   316     iList->HandleItemAdditionL();
       
   317     }
       
   318 
       
   319 
       
   320 // ---------------------------------------------------------
       
   321 // CWAPISecuritySettingsDlg::ProcessCommandL
       
   322 // ---------------------------------------------------------
       
   323 //
       
   324 void CWAPISecuritySettingsDlg::ProcessCommandL( TInt aCommandId )
       
   325     {
       
   326     if ( MenuShowing() )
       
   327         {
       
   328         HideMenu();
       
   329         }
       
   330 
       
   331     switch ( aCommandId )
       
   332         {
       
   333         case EWapiSelCmdChange:
       
   334             {
       
   335             ChangeSettingsL();
       
   336             break;
       
   337             }
       
   338 
       
   339         case EWapiSelCmdReset:
       
   340             {
       
   341             TRAPD( err, iSecuritySettings->ResetCertificateStoreL() );
       
   342 
       
   343             HBufC* label;
       
   344                             
       
   345             if ( err == KErrNone )
       
   346                 {
       
   347                 //Certificate store was emptied, RARRAY's were closed,
       
   348                 //pointer's were freed and certificates's in use were set
       
   349                 //to "None" when ResetcertificateStoreL was called.
       
   350                 //So we have to update the selections on the screen to
       
   351                 //"(Not defined)" and redraw
       
   352                 
       
   353                 //refresh pointers
       
   354                 iSecuritySettings->GetCertificateLabels( 
       
   355                                       iUserCertificates, iCACertificates );
       
   356                 
       
   357                 
       
   358                 for ( TInt i = 0; i < KNumOfFieldsMain; i++ )
       
   359                     {
       
   360 
       
   361                     TWapiMember* ptr = iFieldsMain + i;
       
   362                     TInt* tptr = iTitlesMain + i;
       
   363                     
       
   364                     UpdateListBoxItemL( *ptr, *tptr, i );
       
   365                     *iEventStore |= CWAPISecuritySettings::EModified;
       
   366 
       
   367                     iList->ScrollToMakeItemVisible( i );
       
   368                     iList->DrawItem( i );
       
   369                     }
       
   370 
       
   371 
       
   372                 
       
   373                 label = StringLoader::LoadL( R_WAPI_DONE, iEikonEnv );
       
   374                 }
       
   375             else
       
   376                 {
       
   377                 label = StringLoader::LoadL( R_WAPI_FAILURE, iEikonEnv );
       
   378                 }
       
   379 
       
   380             CleanupStack::PushL( label );
       
   381             
       
   382             CAknInformationNote* dialog = new (ELeave)CAknInformationNote( 
       
   383                     ETrue );
       
   384             dialog->ExecuteLD( *label );
       
   385             
       
   386             CleanupStack::PopAndDestroy( label );         
       
   387 
       
   388             break;
       
   389             }                  
       
   390             
       
   391         case EAknCmdHelp:
       
   392             {
       
   393             HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   394                                     iEikonEnv->EikAppUi()->AppHelpContextL() );
       
   395             break;
       
   396             }
       
   397 
       
   398         case EAknSoftkeyBack:
       
   399         case EAknCmdExit:
       
   400         case EEikCmdExit:
       
   401             {
       
   402             TryExitL( aCommandId );
       
   403             break;
       
   404             }
       
   405 
       
   406         default:
       
   407             {
       
   408             // silently ignore it
       
   409             break;
       
   410             }
       
   411         }
       
   412     }
       
   413 
       
   414 
       
   415 // ---------------------------------------------------------
       
   416 // CWAPISecuritySettingsDlg::HandleListBoxEventL
       
   417 // ---------------------------------------------------------
       
   418 //
       
   419 void CWAPISecuritySettingsDlg::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   420                                                    TListBoxEvent aEventType )
       
   421     {
       
   422     switch ( aEventType )
       
   423         {
       
   424         case EEventEnterKeyPressed:
       
   425         case EEventItemSingleClicked:
       
   426             {
       
   427             ChangeSettingsL();
       
   428             break;
       
   429             }
       
   430 
       
   431         case EEventEditingStarted:
       
   432         case EEventEditingStopped:
       
   433         case EEventPenDownOnItem:
       
   434         case EEventItemDraggingActioned:
       
   435             {
       
   436             break;
       
   437             }
       
   438 
       
   439         default:
       
   440             {
       
   441             __ASSERT_DEBUG( EFalse, Panic( EUnknownCase ) );
       
   442             break;
       
   443             };
       
   444         };
       
   445     }
       
   446 
       
   447 
       
   448 // ---------------------------------------------------------
       
   449 // CWAPISecuritySettingsDlg::PreLayoutDynInitL()
       
   450 // ---------------------------------------------------------
       
   451 //
       
   452 void CWAPISecuritySettingsDlg::PreLayoutDynInitL()
       
   453     {
       
   454     // first get StatusPane
       
   455     CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   456 
       
   457     // then get TitlePane
       
   458     iTitlePane = ( CAknTitlePane* ) statusPane->ControlL( TUid::Uid( 
       
   459                                                     EEikStatusPaneUidTitle ) );
       
   460     // if not already stored, store it for restoring
       
   461     if ( !iOldTitleText )
       
   462         {
       
   463         iOldTitleText = iTitlePane->Text()->AllocL();
       
   464         }
       
   465 
       
   466     // set new titlepane text
       
   467     iTitlePane->SetTextL( iConnectionName );
       
   468 
       
   469     iList = STATIC_CAST( CAknSettingStyleListBox*, 
       
   470                          Control( KWapiMainSettingsListboxId ) );
       
   471 
       
   472     iList->CreateScrollBarFrameL( ETrue );
       
   473     iList->ScrollBarFrame()->SetScrollBarVisibilityL
       
   474         ( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   475 
       
   476     HandleListboxDataChangeL();
       
   477 
       
   478     iList->SetCurrentItemIndex( 0 );
       
   479     iList->SetListBoxObserver( this );
       
   480     }
       
   481 
       
   482 
       
   483 
       
   484 // ---------------------------------------------------------
       
   485 // CWAPISecuritySettingsDlg::DynInitMenuPaneL
       
   486 // ---------------------------------------------------------
       
   487 //
       
   488 void CWAPISecuritySettingsDlg::DynInitMenuPaneL( TInt aResourceId, 
       
   489                                                  CEikMenuPane* aMenuPane )
       
   490     {
       
   491     CAknDialog::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   492     if ( aResourceId == R_WAPI_SECURITY_SETTINGS_MENU )
       
   493         {
       
   494         if( !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   495             {
       
   496             aMenuPane->DeleteMenuItem( EAknCmdHelp );
       
   497             }
       
   498         }
       
   499     }
       
   500 
       
   501 
       
   502 //----------------------------------------------------------
       
   503 // CWAPISecuritySettingsDlg::FillListWithDataL
       
   504 //----------------------------------------------------------
       
   505 //
       
   506 void CWAPISecuritySettingsDlg::FillListWithDataL( CDesCArrayFlat& aItemArray,
       
   507                                                   const TWapiMember& arr, 
       
   508                                                   TInt aLength,
       
   509                                                   const TInt* aRes )
       
   510     {
       
   511     TWapiMember* wapiMember = MUTABLE_CAST( TWapiMember*, &arr );
       
   512 
       
   513     for( TInt i = 0; i < aLength; i++ )
       
   514         {
       
   515         HBufC* itemText = CreateTextualListBoxItemL( *wapiMember, 
       
   516                                                          *aRes );         
       
   517         CleanupStack::PushL( itemText );
       
   518         aItemArray.AppendL( itemText->Des() );
       
   519         CleanupStack::PopAndDestroy( itemText );
       
   520 
       
   521         wapiMember++;
       
   522         aRes++;
       
   523         }
       
   524     }
       
   525 
       
   526 
       
   527 //----------------------------------------------------------
       
   528 // CWAPISecuritySettingsDlg::UpdateListBoxItemL
       
   529 //----------------------------------------------------------
       
   530 //
       
   531 void CWAPISecuritySettingsDlg::UpdateListBoxItemL( TWapiMember aMember, 
       
   532                                                    TInt aRes, TInt aPos )
       
   533     {
       
   534     HBufC* itemText = CreateTextualListBoxItemL( aMember, aRes );
       
   535     CleanupStack::PushL( itemText );
       
   536     // first try to add, if Leaves, list will be untouched
       
   537     iItemArray->InsertL( aPos, itemText->Des() );
       
   538     // if successful, previous item is scrolled up with one,
       
   539     // so delete that one...
       
   540     if ( ++aPos < iItemArray->MdcaCount() )
       
   541         {
       
   542         iItemArray->Delete( aPos );
       
   543         }
       
   544     CleanupStack::PopAndDestroy( itemText );
       
   545     }
       
   546 
       
   547 
       
   548 //----------------------------------------------------------
       
   549 // CWAPISecuritySettingsDlg::CreateTextualListBoxItemL
       
   550 //----------------------------------------------------------
       
   551 //
       
   552 HBufC* CWAPISecuritySettingsDlg::CreateTextualListBoxItemL( 
       
   553                                             TWapiMember aMember, TInt aRes )
       
   554     {
       
   555     #if defined( _DEBUG ) || defined( DEBUG )
       
   556     RDebug::Print(_L("CWAPISecuritySettingsDlg::CreateTextualListBoxItemL") );
       
   557     #endif
       
   558     
       
   559     
       
   560     // Define a heap descriptor to hold title text
       
   561     // that are "WAPI client certificate" or
       
   562     // "WAPI root certificate"
       
   563     HBufC* titleText = iEikonEnv->AllocReadResourceLC( aRes );
       
   564 //
       
   565 //    TInt certIndex = KNone;
       
   566 //    TPtrC certPtr;   
       
   567 
       
   568     HBufC* optText = NULL;
       
   569 
       
   570 
       
   571     switch ( aMember )
       
   572         {
       
   573         case EWapiAuth:
       
   574             {
       
   575             if (iSecuritySettings->GetAuthentication() == EWapiAuthPSK)
       
   576                 {
       
   577                 optText = iEikonEnv->AllocReadResourceLC(R_WAPI_AUTH_PSK);
       
   578                 }
       
   579             else // ... == EWapiAuthCert
       
   580                 {
       
   581                 optText = iEikonEnv->AllocReadResourceLC(R_WAPI_AUTH_CERT);
       
   582                 }
       
   583             }
       
   584             break;
       
   585         case EWapiUserCert:
       
   586         case EWapiCACert:
       
   587             {
       
   588             optText = FormatCertTextualListBoxItemL(aMember, aRes);
       
   589             break;
       
   590             }
       
   591         case EWapiPSKFormat:
       
   592             {
       
   593             if (iSecuritySettings->GetKeyFormat() == CWAPISecuritySettings::EWapiKeyAscii)
       
   594                 {
       
   595                 optText = iEikonEnv->AllocReadResourceLC(R_WAPI_PRESHARED_KEY_FORMAT_ASCII);                
       
   596                 }
       
   597             else // ... == EWapiKeyHex
       
   598                 {
       
   599                 optText = iEikonEnv->AllocReadResourceLC(R_WAPI_PRESHARED_KEY_FORMAT_HEX);
       
   600                 }
       
   601             break;
       
   602             }
       
   603         case EWapiPSK:
       
   604             {
       
   605             if (!iSecuritySettings->hasWapiPSKKey())
       
   606                 {
       
   607                 // PSK key not set.
       
   608                 optText = iEikonEnv->AllocReadResourceLC(R_WAPI_PRESHARED_KEY_NOT_DEFINED);
       
   609                 }
       
   610             else
       
   611                 {
       
   612                 // PSK key set.
       
   613                 _LIT( KStars, "****" );
       
   614                 optText = HBufC::NewLC( KStars().Length() );
       
   615                 optText->Des().Copy( KStars ); 
       
   616 
       
   617                 }
       
   618             break;
       
   619             }
       
   620         default:
       
   621             {
       
   622             __ASSERT_DEBUG( EFalse, Panic( EUnknownCase ) );
       
   623             break;
       
   624             }
       
   625         }
       
   626     _LIT( KTxtListItemFormat, " \t%S\t\t%S" );
       
   627     const TInt KSpaceAndTabsLength = 4;
       
   628         
       
   629     // Define a heap descriptor to hold all the item text
       
   630     // +4 for space and tab characters
       
   631 
       
   632     TInt length = titleText->Length() + optText->Length() 
       
   633                   + KSpaceAndTabsLength;
       
   634     
       
   635     HBufC* itemText = HBufC::NewLC( length );
       
   636 
       
   637     // Define a modifiable pointer descriptor to be able to append the title
       
   638     // text and the certificate label to the non-modifiable heap descriptor
       
   639     // itemText
       
   640     TPtr itemTextPtr = itemText->Des();
       
   641     itemTextPtr.Format( KTxtListItemFormat, titleText, optText );
       
   642  
       
   643     CleanupStack::Pop( itemText ); // itemtext is popped
       
   644 
       
   645     CleanupStack::PopAndDestroy( 2, titleText ); // optText, titleText
       
   646     return itemText;
       
   647     }
       
   648 
       
   649 //----------------------------------------------------------
       
   650 // CWAPISecuritySettingsDlg::FormatCertTextualListBoxItemL
       
   651 //----------------------------------------------------------
       
   652 //
       
   653 HBufC* CWAPISecuritySettingsDlg::FormatCertTextualListBoxItemL( 
       
   654                                             TWapiMember aMember, TInt /* aRes */ )
       
   655     {
       
   656     #if defined( _DEBUG ) || defined( DEBUG )
       
   657     RDebug::Print(_L("CWAPISecuritySettingsDlg::FormatCertTextualListBoxItemL") );
       
   658     #endif
       
   659     
       
   660     TInt certIndex = KCertNone;
       
   661     TPtrC certPtr;   
       
   662 
       
   663     //Check that pointers are not null for example after
       
   664     //certificate store has been reset.
       
   665     switch ( aMember )
       
   666         {
       
   667         case EWapiUserCert:
       
   668             {
       
   669             #if defined( _DEBUG ) || defined( DEBUG )
       
   670             RDebug::Print(_L("user certIndex = %d"), certIndex );
       
   671             #endif
       
   672                 
       
   673             if ( iUserCertificates )
       
   674                 {
       
   675                 iSecuritySettings->GetUserCertInUse( certIndex );
       
   676                 certPtr.Set ((*iUserCertificates)[certIndex]);
       
   677                 }
       
   678                 
       
   679             #if defined( _DEBUG ) || defined( DEBUG )
       
   680             RDebug::Print(_L("user certIndex = %d"), certIndex );
       
   681             #endif
       
   682                 
       
   683             break;
       
   684             }
       
   685 
       
   686         case EWapiCACert:
       
   687             {
       
   688             #if defined( _DEBUG ) || defined( DEBUG )
       
   689             RDebug::Print(_L("ca certIndex = %d"), certIndex );
       
   690             #endif
       
   691                 
       
   692             if ( iCACertificates )
       
   693                 {
       
   694                 iSecuritySettings->GetCACertInUse( certIndex );
       
   695                 certPtr.Set ((*iCACertificates)[certIndex]);
       
   696                 }
       
   697                 
       
   698             #if defined( _DEBUG ) || defined( DEBUG )
       
   699             RDebug::Print(_L("ca certIndex = %d"), certIndex );
       
   700             #endif
       
   701                 
       
   702             break;
       
   703             }
       
   704         default:
       
   705             {
       
   706             __ASSERT_DEBUG( EFalse, Panic( EUnknownCase ) );
       
   707             break;
       
   708             }
       
   709         }
       
   710  
       
   711     // Define a heap descriptor to hold the certificate label text
       
   712     HBufC16* certText;
       
   713     
       
   714     if ( certIndex == KCertNone )
       
   715         {
       
   716         // If "None" is selected from pop up setting page then 
       
   717         // "(Not defined)" is shown on the main screen. This item
       
   718         // has to localized text so read it from resource file.
       
   719         certText = iEikonEnv->AllocReadResourceLC( R_WAPI_CERT_NOT_DEFINED );
       
   720         }
       
   721     else
       
   722         {
       
   723         //Use certificate text found from certificate array
       
   724         //(pointer was set in switch case above)
       
   725         certText = HBufC::NewLC( (certPtr.Length()) ); //pushes pointer 
       
   726                                                        //to Cleanup stack
       
   727         certText->Des().Copy( certPtr ); 
       
   728         }
       
   729 
       
   730     return certText;
       
   731     }
       
   732 
       
   733 
       
   734 //----------------------------------------------------------
       
   735 // CWAPISecuritySettingsDlg::ShowPopupSettingPageL
       
   736 //----------------------------------------------------------
       
   737 //
       
   738 TBool CWAPISecuritySettingsDlg::ShowPopupSettingPageL( TWapiMember aData )
       
   739     {
       
   740     TInt currvalue( 0 );
       
   741     TBool retval( EFalse );
       
   742     CDesCArrayFlat* items = FillPopupSettingPageLC( aData,  currvalue );
       
   743     
       
   744     #if defined( _DEBUG ) || defined( DEBUG )
       
   745     RDebug::Print(_L("CWAPISecuritySettingsDlg::ShowPopupSettingPageL, %d items"), items->Count() );
       
   746     #endif
       
   747 
       
   748     TInt attr_resid( 0 );
       
   749 
       
   750     switch ( aData )
       
   751         {
       
   752         case EWapiUserCert:
       
   753             {
       
   754             attr_resid = R_WAPI_CLIENT_CERT;
       
   755             break;
       
   756             }
       
   757 
       
   758         case EWapiCACert:
       
   759             {
       
   760             attr_resid = R_WAPI_ROOT_CERT;
       
   761             break;
       
   762             }
       
   763   
       
   764         default:
       
   765             {
       
   766             __ASSERT_DEBUG( EFalse, Panic( EUnknownCase ) );
       
   767             attr_resid = 0;
       
   768             break;
       
   769             }
       
   770         }
       
   771 
       
   772     HBufC* titlebuf;
       
   773     CAknRadioButtonSettingPage* dlg;
       
   774     if ( attr_resid )
       
   775         {
       
   776         titlebuf = iEikonEnv->AllocReadResourceLC( attr_resid );
       
   777         dlg = new ( ELeave )CAknRadioButtonSettingPage( 
       
   778                             R_RADIO_BUTTON_SETTING_PAGE, currvalue, items );
       
   779         CleanupStack::PushL( dlg ); 
       
   780         TPtrC ptr( titlebuf->Des() );
       
   781         dlg->SetSettingTextL( ptr );
       
   782         CleanupStack::Pop( dlg ); // dlg
       
   783         }
       
   784     else
       
   785         {
       
   786         dlg = new ( ELeave )CAknRadioButtonSettingPage( 
       
   787                             R_RADIO_BUTTON_SETTING_PAGE, currvalue, items );
       
   788         }
       
   789     if ( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenAccepted ) )
       
   790         {
       
   791     	retval = UpdateFromPopupSettingPage( aData, currvalue );
       
   792 	    }
       
   793 
       
   794     if ( attr_resid )
       
   795         {
       
   796         CleanupStack::PopAndDestroy( titlebuf ); // titlebuf
       
   797         }
       
   798 
       
   799     CleanupStack::PopAndDestroy( items );   // items. It deletes also all 
       
   800                                             // elements in the array.
       
   801     return retval;
       
   802     }
       
   803 
       
   804 //----------------------------------------------------------
       
   805 // CWAPISecuritySettingsDlg::ShowPopupPSKSettingPageL
       
   806 //----------------------------------------------------------
       
   807 //
       
   808 TBool CWAPISecuritySettingsDlg::ShowPopupPSKSettingPageL()
       
   809     {
       
   810     TBool retval( EFalse );
       
   811 
       
   812     HBufC16* bufKeyData = HBufC16::NewLC( KWapiMaxKeyLength );
       
   813     TPtr16 ptrKeyData( bufKeyData->Des() );
       
   814 
       
   815     TBool showPage( ETrue );
       
   816     while ( showPage )
       
   817         {
       
   818         CAknTextSettingPage* settingPage = 
       
   819                 new( ELeave )CAknTextSettingPage( R_PSK_SETTING_PAGE_KEY_DATA,
       
   820                 ptrKeyData, EAknSettingPageNoOrdinalDisplayed );
       
   821 
       
   822         if ( settingPage->ExecuteLD( CAknSettingPage::EUpdateWhenAccepted ) )
       
   823             {
       
   824             HBufC8* buf8 = HBufC8::NewLC( bufKeyData->Des().Length() );
       
   825             buf8->Des().Copy( bufKeyData->Des() ); 
       
   826 
       
   827             if ( iSecuritySettings->SetWapiPSKKeyL(ptrKeyData) != KErrNone )
       
   828                 {
       
   829                 TInt resourceId = R_WAPI_INFO_PRESHARED_KEY_ILLEGAL_CHARS;
       
   830                 if ( (iSecuritySettings->GetKeyFormat()
       
   831                         == CWAPISecuritySettings::EWapiKeyHex)
       
   832                         && (ptrKeyData.Length() % 2 != 0))
       
   833                     {
       
   834                     resourceId = R_WAPI_INFO_PRESHARED_KEY_NOT_EVEN;
       
   835                     }
       
   836                 HBufC* stringLabel;
       
   837                 stringLabel = StringLoader::LoadL( resourceId );
       
   838                 CleanupStack::PushL( stringLabel );
       
   839 
       
   840                 CAknInformationNote* dialog = new ( ELeave )
       
   841                                               CAknInformationNote( ETrue );
       
   842 
       
   843                 CleanupStack::Pop( stringLabel );
       
   844 
       
   845                 dialog->ExecuteLD( *stringLabel );
       
   846                 delete stringLabel;
       
   847                 }
       
   848             else
       
   849                 {
       
   850                 retval = ETrue;
       
   851                 showPage = EFalse;
       
   852                 }
       
   853 
       
   854             CleanupStack::PopAndDestroy( buf8 ); // buf8
       
   855             }
       
   856         else
       
   857             {
       
   858             showPage = EFalse;
       
   859             }
       
   860         }
       
   861 
       
   862     CleanupStack::PopAndDestroy( bufKeyData ); // bufKeyData
       
   863 
       
   864     return retval;
       
   865     }
       
   866 
       
   867 // ---------------------------------------------------------
       
   868 // CWAPISecuritySettingsDlg::FillPopupSettingPageLC
       
   869 // ---------------------------------------------------------
       
   870 //
       
   871 CDesCArrayFlat* CWAPISecuritySettingsDlg::FillPopupSettingPageLC( 
       
   872                                                             TWapiMember aData,
       
   873                                                             TInt& aCurrvalue )
       
   874     {
       
   875     TInt certIndex = KCertNone;
       
   876     CDesCArrayFlat* items = new( ELeave)CDesCArrayFlat( 1 );
       
   877     CleanupStack::PushL( items );
       
   878 
       
   879     
       
   880     // "None" item is not read from the certificate table as it has to be 
       
   881     // localized string
       
   882      RBuf16 resourceText( iEikonEnv->AllocReadResourceL( R_WAPI_NONE ) );
       
   883      items->AppendL( resourceText );
       
   884      resourceText.Close();
       
   885     
       
   886     switch ( aData )
       
   887         {
       
   888         case EWapiUserCert:
       
   889             {
       
   890             // Let's add user certificate labels from RARRAY
       
   891             if ( iUserCertificates )
       
   892                 {
       
   893                 #if defined( _DEBUG ) || defined( DEBUG )
       
   894                 RDebug::Print(_L("CWAPISecuritySettingsDlg::FillPopupSettingPageLC, %d user certificates"), iUserCertificates->Count() );
       
   895                 #endif
       
   896                 
       
   897                 TPtrC ptr;
       
   898                 for ( TInt i = 1; i < iUserCertificates->Count(); i++ )
       
   899                     {
       
   900                     ptr.Set ((*iUserCertificates)[i]); // AppendL needs a pointer
       
   901                     items->AppendL( ptr );
       
   902                     }
       
   903                 }       
       
   904             iSecuritySettings->GetUserCertInUse( certIndex );   
       
   905             break;
       
   906             }
       
   907             
       
   908         case EWapiCACert:
       
   909             {
       
   910           //Lets add CA certificate labels from RARRAY
       
   911             if (iCACertificates)
       
   912                 {
       
   913                 TPtrC ptr;
       
   914                 for ( TInt i = 1; i < iCACertificates->Count(); i++ )
       
   915                     {
       
   916                     ptr.Set((*iCACertificates)[i]); // AppendL needs a pointer
       
   917                     items->AppendL( ptr );
       
   918                     }
       
   919                 }            
       
   920             iSecuritySettings->GetCACertInUse( certIndex );
       
   921             break;
       
   922             }
       
   923 
       
   924         default:
       
   925             {
       
   926             __ASSERT_DEBUG( EFalse, Panic ( EUnknownCase ) );
       
   927             break;
       
   928             }
       
   929         }
       
   930     aCurrvalue = certIndex; //Set current choice
       
   931     return items;
       
   932     }
       
   933 
       
   934 
       
   935 // ---------------------------------------------------------
       
   936 // CWAPISecuritySettingsDlg::UpdateFromPopupSettingPage
       
   937 // ---------------------------------------------------------
       
   938 //
       
   939 TBool CWAPISecuritySettingsDlg::UpdateFromPopupSettingPage( TWapiMember aData,
       
   940                                                             TInt aCurrvalue )
       
   941     {
       
   942     #if defined( _DEBUG ) || defined( DEBUG )
       
   943     RDebug::Print(_L("CWAPISecuritySettingsImpl::UpdateFromPopupSettingPage, aCurrvalue = %d"), aCurrvalue );
       
   944     #endif
       
   945     
       
   946     TInt certIndex;
       
   947     TBool retVal( EFalse );
       
   948 
       
   949     switch ( aData )
       
   950         {
       
   951         case EWapiUserCert:
       
   952             {
       
   953             //Fetch the current certificate in use
       
   954             iSecuritySettings->GetUserCertInUse( certIndex );
       
   955             
       
   956             if ( certIndex != aCurrvalue )
       
   957                 {
       
   958                 iSecuritySettings->SetUserCertInUse( aCurrvalue );
       
   959                 retVal = ETrue;
       
   960                 }
       
   961             break;
       
   962             }
       
   963 
       
   964         case EWapiCACert:
       
   965             {
       
   966             //Fetch the current certificate in use
       
   967             iSecuritySettings->GetCACertInUse( certIndex );
       
   968             
       
   969             if ( certIndex != aCurrvalue )
       
   970                 {
       
   971                 iSecuritySettings->SetCACertInUse( aCurrvalue );
       
   972                 retVal = ETrue;
       
   973                 }
       
   974              break;
       
   975   
       
   976             }
       
   977 
       
   978         default:
       
   979             {
       
   980             __ASSERT_DEBUG( EFalse, Panic( EUnknownCase ) );
       
   981             break;
       
   982             }
       
   983         }
       
   984     return retVal;
       
   985     }
       
   986 
       
   987 
       
   988 //----------------------------------------------------------
       
   989 // CWAPISecuritySettingsDlg::ChangeSettingsL
       
   990 //----------------------------------------------------------
       
   991 //
       
   992 void CWAPISecuritySettingsDlg::ChangeSettingsL()
       
   993     {
       
   994     TInt itemIndex = Max( iList->CurrentItemIndex(), 0 );
       
   995     TWapiMember* ptr = iFieldsMain + itemIndex;
       
   996     TInt* tptr = iTitlesMain + itemIndex;
       
   997 
       
   998     switch ( *ptr )
       
   999         {
       
  1000         case EWapiAuth:
       
  1001             {
       
  1002             if (iSecuritySettings->GetAuthentication() == EWapiAuthCert)
       
  1003                 {
       
  1004                 iSecuritySettings->SetAuthentication( EWapiAuthPSK );
       
  1005                 iFieldsMain = ( TWapiMember* ) KFields_Wapi_Main_PSK;
       
  1006                 iTitlesMain = MUTABLE_CAST( TInt*, KTitles_Wapi_Main_PSK );
       
  1007                 }
       
  1008             else // ... == EWapiAuthPSK
       
  1009                 {
       
  1010                 iSecuritySettings->SetAuthentication( EWapiAuthCert );
       
  1011                 iFieldsMain = ( TWapiMember* ) KFields_Wapi_Main_Cert;
       
  1012                 iTitlesMain = MUTABLE_CAST( TInt*, KTitles_Wapi_Main_Cert );
       
  1013                 }
       
  1014             HandleListboxDataChangeL();
       
  1015             *iEventStore |= CWAPISecuritySettings::EModified;
       
  1016             break;
       
  1017             }
       
  1018         case EWapiCACert:
       
  1019         case EWapiUserCert:
       
  1020             {
       
  1021             if ( ShowPopupSettingPageL( *ptr ) )
       
  1022                 {
       
  1023                 UpdateListBoxItemL( *ptr, *tptr, itemIndex );
       
  1024                 *iEventStore |= CWAPISecuritySettings::EModified;
       
  1025                 }
       
  1026             break;
       
  1027             }
       
  1028         case EWapiPSKFormat:
       
  1029             {
       
  1030             if (iSecuritySettings->GetKeyFormat() == CWAPISecuritySettings::EWapiKeyAscii)
       
  1031                 {
       
  1032                 iSecuritySettings->SetKeyFormat(CWAPISecuritySettings::EWapiKeyHex);
       
  1033                 }
       
  1034             else // ... == EWapiKeyHex
       
  1035                 {
       
  1036                 iSecuritySettings->SetKeyFormat(CWAPISecuritySettings::EWapiKeyAscii);
       
  1037                 }
       
  1038             UpdateListBoxItemL( *ptr, *tptr, itemIndex );
       
  1039             *iEventStore |= CWAPISecuritySettings::EModified;
       
  1040             break;
       
  1041             }
       
  1042         case EWapiPSK:
       
  1043             {
       
  1044             if ( ShowPopupPSKSettingPageL())
       
  1045                 {
       
  1046                 UpdateListBoxItemL(*ptr, *tptr, itemIndex);
       
  1047                 *iEventStore |= CWAPISecuritySettings::EModified;
       
  1048                 }
       
  1049             break;
       
  1050             }
       
  1051         default:
       
  1052             {
       
  1053             __ASSERT_DEBUG( EFalse, Panic( EUnknownCase ) );
       
  1054             break;
       
  1055             }
       
  1056         }
       
  1057         
       
  1058     iList->ScrollToMakeItemVisible( itemIndex );
       
  1059     iList->SetCurrentItemIndexAndDraw( itemIndex );
       
  1060     }
       
  1061 
       
  1062 
       
  1063 // ---------------------------------------------------------
       
  1064 // CWAPISecuritySettingsDlg::GetHelpContext
       
  1065 // ---------------------------------------------------------
       
  1066 //
       
  1067 void CWAPISecuritySettingsDlg::GetHelpContext( TCoeHelpContext& aContext ) const
       
  1068     {
       
  1069     aContext.iMajor = KWAPISecuritySettingsUiHelpMajor;
       
  1070     aContext.iContext = KSET_HLP_WLAN_WAPI_MAIN;
       
  1071     
       
  1072     }
       
  1073 
       
  1074 // End of File