wlansecuritysettings/wlaneapsettingsui/EapMschapv2/ConfigUi/src/EapMschapv2UiView.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-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 the License "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: Implementation of EAP Mschapv2 UI settings dialog
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <eikdialg.h>
       
    22 #include <AknDialog.h>
       
    23 #include <aknlists.h>
       
    24 #include "EapMschapv2UiView.h"
       
    25 #include "EapMschapv2Ui.hrh"
       
    26 #include <EapMschapv2Ui.rsg>
       
    27 #include <akntextsettingpage.h>
       
    28 #include <aknsettingitemlist.h>
       
    29 #include "EapMschapv2UiSettingArray.h"
       
    30 #include <aknnavide.h>
       
    31 #include <aknnotewrappers.h> 
       
    32 #include <EapMsChapV2UiConnection.h>
       
    33 #include <EapMsChapV2UiDataConnection.h>
       
    34 #include <EapMsChapV2UiMsChapV2Data.h>
       
    35 
       
    36 #include <FeatMgr.h>
       
    37 #include <hlplch.h>
       
    38 #include <csxhelp/cp.hlp.hrh>
       
    39 
       
    40 
       
    41 // CONSTANTS
       
    42 // UID of general settings app, in which help texts are included
       
    43 const TUid KHelpUidPlugin = { 0x100058EC };
       
    44 
       
    45 _LIT( KEmptyString, "" );
       
    46 
       
    47 static const TInt KEapMsChapv2Id = 26;
       
    48 
       
    49 // MODULE DATA STRUCTURES
       
    50 enum 
       
    51     {
       
    52     EUsernameItem=0,
       
    53     EPasswordPromptItem,
       
    54     EPasswordItem
       
    55     };
       
    56 
       
    57 
       
    58 // ============================ MEMBER FUNCTIONS ===============================
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CEapMsChapV2UiDialog::CEapMsChapV2UiDialog
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CEapMsChapV2UiDialog::CEapMsChapV2UiDialog( 
       
    65                                         CEapMsChapV2UiConnection* aConnection,
       
    66 								        TInt& aButtonId )
       
    67 : CAknDialog(),
       
    68   iConnection( aConnection ),
       
    69   iUiData( 0 ), 
       
    70   iDataConnection( 0 ), 
       
    71   iSettingArray( 0 ), 
       
    72   iSettingListBox( 0 ), 
       
    73   iSettingListItemDrawer( 0 ), 
       
    74   iPassPrompt( EFalse ),
       
    75   iNaviPane( 0 ), 
       
    76   iNaviDecorator( 0 ), 
       
    77   iPreviousText( 0 ), 
       
    78   iButtonId( &aButtonId ),
       
    79   iIsUIConstructionCompleted( EFalse )
       
    80     {
       
    81     }
       
    82 
       
    83 
       
    84 // --------------------------------------------------z-------
       
    85 // CEapMsChapV2UiDialog::ConstructAndRunLD
       
    86 // ---------------------------------------------------------
       
    87 //
       
    88 TInt CEapMsChapV2UiDialog::ConstructAndRunLD( TInt aResourceId )
       
    89     {
       
    90     CleanupStack::PushL( this );
       
    91 
       
    92     iSettingArray = CEapMsChapV2SettingItemArray::NewL();
       
    93 
       
    94     User::LeaveIfError( iConnection->Connect() );
       
    95 
       
    96     iDataConnection = iConnection->GetDataConnection();
       
    97     if ( iDataConnection == 0 )
       
    98         {
       
    99         User::Leave( KErrNoMemory );
       
   100         }
       
   101 
       
   102     User::LeaveIfError( iDataConnection->Open() );
       
   103     User::LeaveIfError( iDataConnection->GetData( &iUiData ) );
       
   104 
       
   105     FeatureManager::InitializeLibL();
       
   106 
       
   107     ConstructL( R_MSCHAPV2_MENUBAR );
       
   108     
       
   109     // ExecuteLD will PushL( this ), so we have to Pop it...
       
   110     CleanupStack::Pop( this ); // this
       
   111     
       
   112     return CAknDialog::ExecuteLD( aResourceId );
       
   113     }
       
   114 
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CEapMsChapV2UiDialog::~CEapMsChapV2UiDialog
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 CEapMsChapV2UiDialog::~CEapMsChapV2UiDialog()
       
   121     {
       
   122     if ( iNaviDecorator )
       
   123         {
       
   124         delete iNaviDecorator;
       
   125         iNaviDecorator = NULL;
       
   126         }
       
   127 
       
   128     if ( iSettingArray )
       
   129         {
       
   130         iSettingArray->Array()->ResetAndDestroy();
       
   131         delete iSettingArray;
       
   132         }
       
   133 
       
   134     if ( iSettingListBox )
       
   135         {
       
   136         iSettingListBox = 0;
       
   137         }
       
   138 
       
   139     if ( iSettingListItemDrawer )
       
   140         {
       
   141         iSettingListItemDrawer = 0;
       
   142         }
       
   143 
       
   144     if ( iDataConnection )
       
   145         {
       
   146         iDataConnection->Close();
       
   147         delete iDataConnection;
       
   148         }
       
   149 
       
   150     if ( iConnection )
       
   151         {
       
   152         iConnection->Close();
       
   153         }
       
   154 
       
   155     delete iPreviousText;
       
   156     
       
   157     FeatureManager::UnInitializeLib();
       
   158     }
       
   159 
       
   160 
       
   161 // ---------------------------------------------------------
       
   162 // CEapMsChapV2UiDialog::HandleListBoxEventL
       
   163 // ---------------------------------------------------------
       
   164 //
       
   165 void CEapMsChapV2UiDialog::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   166                                                    TListBoxEvent aEventType )
       
   167     {
       
   168     switch ( aEventType )
       
   169         {
       
   170         case EEventEnterKeyPressed:
       
   171         case EEventItemSingleClicked:
       
   172             {
       
   173             OkToExitL( EMschapv2UiCmdChange );         
       
   174             break;
       
   175             }
       
   176 
       
   177         case EEventItemActioned:
       
   178         case EEventEditingStarted:
       
   179         case EEventEditingStopped:
       
   180         case EEventPenDownOnItem:
       
   181         case EEventItemDraggingActioned:
       
   182             {
       
   183             break;
       
   184             }
       
   185 
       
   186         default:
       
   187             {
       
   188             break;
       
   189             };
       
   190         };
       
   191     }    
       
   192 
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CEapMsChapV2UiDialog::PreLayoutDynInitL
       
   196 // -----------------------------------------------------------------------------
       
   197 //
       
   198 void CEapMsChapV2UiDialog::PreLayoutDynInitL()
       
   199     {
       
   200     ChangeTitleL( ETrue );
       
   201     
       
   202     TUid naviPaneUid;
       
   203     naviPaneUid.iUid = EEikStatusPaneUidNavi;
       
   204     CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   205     CEikStatusPaneBase::TPaneCapabilities subPane = 
       
   206                                 statusPane->PaneCapabilities( naviPaneUid );
       
   207     if ( subPane.IsPresent() && subPane.IsAppOwned() )
       
   208         {
       
   209         iNaviPane = static_cast<CAknNavigationControlContainer*>( 
       
   210                                         statusPane->ControlL(naviPaneUid) );
       
   211         // Set empty text to hide tabs.
       
   212         iNaviDecorator = iNaviPane->CreateNavigationLabelL( KEmptyString );
       
   213         iNaviPane->PushL( *iNaviDecorator );
       
   214         }            
       
   215             
       
   216     iSettingListBox = static_cast<CAknSettingStyleListBox*>(
       
   217                                     ControlOrNull( EMschapv2SettingsListBox) );
       
   218     iSettingListItemDrawer = static_cast<CSettingsListBoxItemDrawer*>( 
       
   219                                     iSettingListBox->ItemDrawer() ); 
       
   220 
       
   221     iSettingListBox->SetMopParent( this );
       
   222     iSettingListBox->CreateScrollBarFrameL( ETrue );
       
   223     iSettingListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   224                                                 CEikScrollBarFrame::EOff,
       
   225                                                 CEikScrollBarFrame::EAuto );
       
   226     iSettingListBox->SetListBoxObserver( this );                                                                                                
       
   227     DrawSettingsListL();
       
   228     
       
   229     iIsUIConstructionCompleted = ETrue;
       
   230     }
       
   231 
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // CEapMsChapV2UiDialog::ShowSettingPageL
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CEapMsChapV2UiDialog::ShowSettingPageL( TInt aCalledFromMenu ) 
       
   238     {
       
   239     TInt index = iSettingListBox->CurrentItemIndex();
       
   240 
       
   241     CAknSettingItem* item = iSettingArray->Array()->At( index );
       
   242     item->EditItemL( aCalledFromMenu );
       
   243     item->StoreL();
       
   244 
       
   245     if ( index == EPasswordPromptItem )
       
   246         {
       
   247         if ( !iPassPrompt )
       
   248             *iUiData->GetPasswordPrompt() = EFalse;
       
   249         else
       
   250             *iUiData->GetPasswordPrompt() = ETrue;
       
   251         }
       
   252 
       
   253     DrawNow();
       
   254     }
       
   255 
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CEapMsChapV2UiDialog::OkToExitL
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 TBool CEapMsChapV2UiDialog::OkToExitL( TInt aButtonId )
       
   262     {
       
   263     TBool ret( EFalse );
       
   264     switch ( aButtonId )
       
   265         {
       
   266         case EEikBidOk:
       
   267             {
       
   268             if( iIsUIConstructionCompleted )
       
   269                 {
       
   270                 if ( iSettingListBox->IsFocused() )
       
   271                     {
       
   272                     ShowSettingPageL( EFalse );
       
   273                     }
       
   274                 }
       
   275             else
       
   276                 {
       
   277                 #if defined(_DEBUG) || defined(DEBUG)
       
   278 				RDebug::Print(_L("CEapMsChapV2UiDialog::OkToExitL - UI not ready - Ignoring key press.\n") );
       
   279 				#endif
       
   280                 }
       
   281             break;
       
   282             }
       
   283 
       
   284         case EAknSoftkeyOptions:
       
   285             {
       
   286             DisplayMenuL();
       
   287             break;
       
   288             }
       
   289 
       
   290         case EAknSoftkeyBack:
       
   291         case EAknCmdExit:
       
   292             {
       
   293             if( iIsUIConstructionCompleted )
       
   294                 {
       
   295                 iDataConnection->Update();
       
   296                 ChangeTitleL( EFalse );
       
   297                 ret = ETrue;
       
   298                 }
       
   299             break;
       
   300             }
       
   301         
       
   302         case EMschapv2UiCmdChange:
       
   303             {
       
   304             if( iIsUIConstructionCompleted )
       
   305 				{
       
   306     			ShowSettingPageL( EFalse );
       
   307 				}
       
   308 			else
       
   309 			    {
       
   310 				#if defined(_DEBUG) || defined(DEBUG)
       
   311 				RDebug::Print(_L("CEapMsChapV2UiDialog::ProcessCommandL - UI not ready - Ignoring key press.\n") );
       
   312 				#endif						
       
   313 			    }
       
   314             break;
       
   315             }
       
   316 
       
   317         default:
       
   318             {
       
   319             break;
       
   320             }
       
   321         }
       
   322 
       
   323     if ( ret )
       
   324         {
       
   325         *iButtonId = aButtonId;
       
   326         }
       
   327 
       
   328     return ret;
       
   329     }
       
   330 
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // CEapMsChapV2UiDialog::DrawSettingsListL
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 void CEapMsChapV2UiDialog::DrawSettingsListL()
       
   337     {  
       
   338     iSettingArray->Array()->ResetAndDestroy();
       
   339 
       
   340     TInt ordinal = 0;
       
   341     iSettingArray->AddTextItemL( iUiData->GetUsername(), 
       
   342                                 EMschapv2SettingPageUserName,
       
   343                                 R_MSCHAPV2_USERNAME_STRING,
       
   344                                 R_MSCHAPV2_USERNAME_PAGE,
       
   345                                 NULL,
       
   346                                 ordinal++ );
       
   347     
       
   348     if ( *iUiData->GetPasswordPrompt() )
       
   349         {
       
   350         iPassPrompt = ETrue;
       
   351         }
       
   352     else{
       
   353         iPassPrompt = EFalse;
       
   354         }
       
   355 
       
   356     iSettingArray->AddBinarySettingItemL( R_MSCHAPV2_DISPLAY_YESNO_PAGE,
       
   357                                           R_MSCHAPV2_PASSPROMPT_STRING, 
       
   358                                           R_MSCHAPV2_YESNO_TEXTS,
       
   359                                           ordinal++,
       
   360                                           iPassPrompt );    
       
   361 
       
   362     iSettingArray->AddPasswordItemL( iUiData->GetPassword(), 
       
   363                                      EMschapv2SettingPagePassword,
       
   364                                      R_MSCHAPV2_PASSWORD_STRING,
       
   365                                      R_MSCHAPV2_PASSWORD_PAGE,
       
   366                                      NULL,
       
   367                                      ordinal++ );
       
   368 
       
   369 
       
   370     iSettingListBox->Model()->SetItemTextArray( iSettingArray->Array() );    
       
   371     iSettingListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   372     iSettingArray->Array()->RecalculateVisibleIndicesL();
       
   373     iSettingListBox->HandleItemAdditionL();
       
   374     iSettingListBox->UpdateScrollBarsL();
       
   375     }
       
   376 
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 // CEapMsChapV2UiDialog::ChangeTitleL
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 void CEapMsChapV2UiDialog::ChangeTitleL( TBool aIsStarted )
       
   383     {
       
   384     TUid titlePaneUid;
       
   385     titlePaneUid.iUid = EEikStatusPaneUidTitle;
       
   386 
       
   387     CEikStatusPane* statusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   388     CEikStatusPaneBase::TPaneCapabilities subPane = 
       
   389                                 statusPane->PaneCapabilities( titlePaneUid );
       
   390     
       
   391     if ( subPane.IsPresent() && subPane.IsAppOwned())
       
   392         {
       
   393         CAknTitlePane* titlePane = static_cast<CAknTitlePane*>( 
       
   394                                         statusPane->ControlL( titlePaneUid ) );
       
   395         if ( aIsStarted )
       
   396             { 
       
   397             // Store previous application title text
       
   398             const TDesC* prevText = titlePane->Text();    
       
   399 
       
   400             iPreviousText = HBufC::NewL( prevText->Length() );
       
   401             iPreviousText->Des().Append( *prevText );
       
   402 
       
   403             // EAGN-6QZD6U
       
   404             // Loadd different titles for plain MSCHAPv2 and EAP-MSCHAPv2
       
   405             TDesC* titleText;
       
   406             if( iConnection->GetBearerEAPType() == KEapMsChapv2Id )
       
   407                 {
       
   408                 titleText = iEikonEnv->AllocReadResourceLC( 
       
   409                                                 R_MSCHAPV2_SETTINGS_TITLE );
       
   410                 }
       
   411             else
       
   412                 {
       
   413                 titleText = iEikonEnv->AllocReadResourceLC( 
       
   414                                                 R_PLAIN_MSCHAPV2_SETTINGS_TITLE );
       
   415                 }
       
   416             titlePane->SetTextL( *titleText );
       
   417             CleanupStack::PopAndDestroy( titleText ); 
       
   418             }
       
   419         else
       
   420             {
       
   421             // Set calling application title text back
       
   422             titlePane->SetTextL( *iPreviousText );    
       
   423             // pop navidecorator when exiting
       
   424             iNaviPane->Pop( iNaviDecorator );    
       
   425             }    
       
   426         }
       
   427     }
       
   428 
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 // CEapMsChapV2UiDialog::DynInitMenuPaneL
       
   432 // -----------------------------------------------------------------------------
       
   433 //
       
   434 void CEapMsChapV2UiDialog::DynInitMenuPaneL( TInt aResourceId, 
       
   435                                              CEikMenuPane* aMenuPane )
       
   436     {
       
   437     CAknDialog::DynInitMenuPaneL( aResourceId, aMenuPane );
       
   438 
       
   439     if ( aResourceId == R_MSCHAPV2_MENU_PANE )
       
   440         {
       
   441         if ( aMenuPane && !FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   442             {
       
   443             aMenuPane->DeleteMenuItem( EAknCmdHelp );
       
   444             }
       
   445         }
       
   446     }
       
   447 
       
   448 
       
   449 // -----------------------------------------------------------------------------
       
   450 // CEapMsChapV2UiDialog::ProcessCommandL
       
   451 // -----------------------------------------------------------------------------
       
   452 //
       
   453 void CEapMsChapV2UiDialog::ProcessCommandL( TInt aCommand )
       
   454     {
       
   455     if ( MenuShowing() )
       
   456         {
       
   457         HideMenu();
       
   458         }
       
   459 
       
   460     switch( aCommand )
       
   461         {
       
   462         case EAknCmdExit:
       
   463             {
       
   464             TryExitL( aCommand );
       
   465             break;
       
   466             }
       
   467 
       
   468         case EAknCmdHelp:
       
   469             {
       
   470             HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   471                                     iEikonEnv->EikAppUi()->AppHelpContextL() );
       
   472             break;
       
   473             }
       
   474 
       
   475         case EMschapv2UiCmdChange:
       
   476             {
       
   477             if( iIsUIConstructionCompleted )
       
   478 				{
       
   479     			ShowSettingPageL( ETrue );
       
   480 				}
       
   481 			else
       
   482 			    {
       
   483 				#if defined(_DEBUG) || defined(DEBUG)
       
   484 				RDebug::Print(_L("CEapMsChapV2UiDialog::ProcessCommandL - UI not ready - Ignoring key press.\n") );
       
   485 				#endif						
       
   486 			    }
       
   487             break;
       
   488             }
       
   489 
       
   490         default:
       
   491             {
       
   492             break;
       
   493             }
       
   494         }
       
   495     }
       
   496 
       
   497 
       
   498 // -----------------------------------------------------------------------------
       
   499 // CEapMsChapV2UiDialog::GetHelpContext
       
   500 // -----------------------------------------------------------------------------
       
   501 //
       
   502 void CEapMsChapV2UiDialog::GetHelpContext( TCoeHelpContext& aContext ) const
       
   503     {
       
   504     aContext.iMajor = KHelpUidPlugin;
       
   505     if( iConnection->GetBearerEAPType() == KEapMsChapv2Id )
       
   506         {
       
   507         aContext.iContext = KSET_HLP_WLAN_EAP_MSCHAPV2;
       
   508         }
       
   509     else
       
   510         {
       
   511         aContext.iContext = KSET_HLP_WLAN_EAP_PLAIN_MSCHAP;
       
   512         }
       
   513     }
       
   514     
       
   515 
       
   516 //  End of File