cmmanager/cmmgr/Plugins/cmpluginvpn/src/cmpvpnnextlayerselectdlg.cpp
changeset 20 9c97ad6591ae
parent 18 fcbbe021d614
child 21 b8e8e15e80f2
child 23 7ec726f93df1
child 28 860702281757
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
     1 /*
       
     2 * Copyright (c) 2006 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:  Popup for selecting the underlying connection method or 
       
    15 *                destination for a VPN connection method
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // includes
       
    21 #include <badesca.h> // arrays
       
    22 #include <gulicon.h> // icons
       
    23 #include <StringLoader.h>
       
    24 #include <data_caging_path_literals.hrh>
       
    25 #include <featmgr.h>
       
    26 #include <cmpluginvpn.mbg>
       
    27 #include <cmpluginvpnui.rsg>
       
    28 #include <cmmanager.rsg>
       
    29 #include <cmmanager.mbg> 
       
    30 #include <eikenv.h>
       
    31 #include <aknlists.h>
       
    32 #include <eikfrlb.h> // CEikFormattedCellListBox
       
    33 #include <aknradiobuttonsettingpage.h>
       
    34 #include <cmpluginbaseeng.h>
       
    35 #include <cmpluginbase.h>
       
    36 
       
    37 #include <hlplch.h>
       
    38 #include <csxhelp/cp.hlp.hrh>
       
    39 
       
    40 #include "cmlogger.h"
       
    41 #include "cmdestinationimpl.h"
       
    42 #include "cmmanagerimpl.h"
       
    43 #include "cmpvpnnextlayerselectdlg.h"
       
    44 #include "cmvpncommonconstants.h"
       
    45 #include <cmcommonconstants.h>
       
    46 #include <cmpluginvpndef.h>
       
    47 
       
    48 using namespace CMManager;
       
    49 // --------------------------------------------------------------------------
       
    50 // CmPluginVpnNextLayerSelectDlg::NewL
       
    51 // --------------------------------------------------------------------------
       
    52 //
       
    53 CmPluginVpnNextLayerSelectDlg* CmPluginVpnNextLayerSelectDlg::NewL( 
       
    54                                         CCmPluginBaseEng& aCmPluginBaseEng,
       
    55                                         RArray<TUint32>& aBindableMethods,
       
    56                                         TBool& aSnapSelected,
       
    57                                         TUint32& aNextLayerId )
       
    58     {
       
    59     CmPluginVpnNextLayerSelectDlg* self = 
       
    60             new ( ELeave ) CmPluginVpnNextLayerSelectDlg( aCmPluginBaseEng,
       
    61                                                           aBindableMethods,
       
    62                                                           aSnapSelected,
       
    63                                                           aNextLayerId,
       
    64                                                           0 );
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68     return self;
       
    69     }
       
    70       
       
    71 // --------------------------------------------------------------------------
       
    72 // CmPluginVpnNextLayerSelectDlg::CmPluginVpnNextLayerSelectDlg
       
    73 // --------------------------------------------------------------------------
       
    74 //
       
    75 CmPluginVpnNextLayerSelectDlg::CmPluginVpnNextLayerSelectDlg(
       
    76                                         CCmPluginBaseEng& aCmPluginBaseEng,
       
    77                                         RArray<TUint32>& aBindableMethods,
       
    78                                         TBool& aSnapSelected,
       
    79                                         TUint32& aNextLayerId,
       
    80                                         TInt aDummyIndex )
       
    81     : CAknListQueryDialog( &aDummyIndex )
       
    82     , iMyEikonEnv( *CEikonEnv::Static() )
       
    83     , iCmPluginBaseEng( aCmPluginBaseEng )
       
    84     , iSnapSelected( aSnapSelected )
       
    85     , iNextLayerId( aNextLayerId )
       
    86     , iResourceReader( *CCoeEnv::Static() )
       
    87     , iDestinations( aBindableMethods )
       
    88     , iEasyWlanId(0)  
       
    89     , iCmManager( iCmPluginBaseEng.CmMgr() ) 
       
    90     , iUncatItems( EFalse )
       
    91     {
       
    92     ;
       
    93     }
       
    94     
       
    95     
       
    96 // --------------------------------------------------------------------------
       
    97 // CmPluginVpnNextLayerSelectDlg::~CmPluginVpnPolicySelectionDlg
       
    98 // --------------------------------------------------------------------------
       
    99 //
       
   100 CmPluginVpnNextLayerSelectDlg::~CmPluginVpnNextLayerSelectDlg()
       
   101     {
       
   102     if (  iAsyncCancel )
       
   103         {
       
   104         delete  iAsyncCancel;
       
   105         iAsyncCancel = NULL;
       
   106         }
       
   107     
       
   108     iResourceReader.Close();
       
   109     }
       
   110 
       
   111 // --------------------------------------------------------------------------
       
   112 // CmPluginVpnNextLayerSelectDlg::ConstructL
       
   113 // --------------------------------------------------------------------------
       
   114 //
       
   115 void CmPluginVpnNextLayerSelectDlg::ConstructL()
       
   116     {    
       
   117     LoadResourceL( KPluginVPNResDirAndFileName );
       
   118     
       
   119     // get the EasyWlan id if it's supported
       
   120     if ( FeatureManager::FeatureSupported( KFeatureIdProtocolWlan ) )
       
   121         {
       
   122         iEasyWlanId = iCmManager.EasyWlanIdL();
       
   123         }   
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CmPluginVpnNextLayerSelectDlg::CancelAsynchronouslyL
       
   128 // ---------------------------------------------------------------------------
       
   129 TInt CmPluginVpnNextLayerSelectDlg::CancelAsynchronouslyL( TAny* aObject )
       
   130     {
       
   131     CmPluginVpnNextLayerSelectDlg* myself =
       
   132         static_cast< CmPluginVpnNextLayerSelectDlg* >( aObject );
       
   133     
       
   134     myself->TryExitL( EAknSoftkeyCancel );
       
   135     return 0;
       
   136     }
       
   137     
       
   138 // ----------------------------------------------------------------------------
       
   139 // CmPluginVpnNextLayerSelectDlg::PreLayoutDynInitL
       
   140 // ----------------------------------------------------------------------------
       
   141 //
       
   142 void CmPluginVpnNextLayerSelectDlg::PreLayoutDynInitL()
       
   143     {
       
   144     CAknDialog::ConstructL( R_VPN_REAL_CM_SELECTION_MENUBAR );
       
   145     
       
   146     // Let the base class do its job first
       
   147     CAknListQueryDialog::PreLayoutDynInitL();
       
   148 
       
   149     SetTextsAndIconsL();
       
   150     }
       
   151 
       
   152 // ----------------------------------------------------------------------------
       
   153 // CmPluginVpnNextLayerSelectDlg::OkToExitL
       
   154 // ----------------------------------------------------------------------------
       
   155 //
       
   156 TBool CmPluginVpnNextLayerSelectDlg::OkToExitL( TInt aButtonId )
       
   157     {
       
   158     TBool result = EFalse;
       
   159     
       
   160     if ( aButtonId == EAknSoftkeyDone  || aButtonId == EAknSoftkeyOk )
       
   161         {
       
   162         result = ETrue;
       
   163         }
       
   164     else if ( aButtonId == EAknSoftkeySelect )
       
   165         {
       
   166         ProcessCommandL( ECmManagerUiCmdDestSelect );
       
   167         }    
       
   168     else if ( aButtonId == EAknSoftkeyOptions )
       
   169         {
       
   170         ProcessCommandL( EAknSoftkeyOptions );
       
   171         }
       
   172     else if ( aButtonId == EAknSoftkeyBack || aButtonId == EAknSoftkeyCancel )
       
   173         {
       
   174         result = ETrue;
       
   175         }
       
   176     else
       
   177         {
       
   178     
       
   179         }
       
   180 
       
   181     return result;
       
   182     }
       
   183     
       
   184 // --------------------------------------------------------------------------
       
   185 // CmPluginVpnNextLayerSelectDlg::SetTextsAndIconsL
       
   186 // --------------------------------------------------------------------------
       
   187 //
       
   188 void CmPluginVpnNextLayerSelectDlg::SetTextsAndIconsL()
       
   189     {
       
   190     LOGGER_ENTERFN( "CmPluginVpnNextLayerSelectDlg::SetTextsAndIconsL" );
       
   191     
       
   192     // Item text array
       
   193     CDesCArray* itemArray =
       
   194                 new ( ELeave ) CDesCArrayFlat( KCmArrayMediumGranularity );
       
   195     CleanupStack::PushL( itemArray );
       
   196     SetItemTextArray( itemArray ); // ownership taken
       
   197     SetOwnershipType( ELbmOwnsItemArray );
       
   198     CleanupStack::Pop( itemArray ); // as ownership is taken
       
   199                     
       
   200     // Icon array
       
   201     CArrayPtr<CGulIcon>* icons =
       
   202          new ( ELeave ) CArrayPtrFlat<CGulIcon>( KCmArrayMediumGranularity );
       
   203     CleanupStack::PushL( icons );
       
   204     SetIconArrayL( icons );
       
   205     // ownership taken by SetIconArrayL!
       
   206     CleanupStack::Pop( icons ); // as ownership is taken
       
   207     
       
   208     // Step through the Destinations - do not show:
       
   209     // Parent Destinations or Destinations with no non-virtual CMs
       
   210     // Show Uncategorised if valid and EasyWlan if supported
       
   211     TInt destCount = iDestinations.Count();
       
   212     for ( TInt i = 0; i < destCount; i++ )
       
   213         {        
       
   214         switch ( iDestinations[i] )
       
   215             {
       
   216             case KDestItemUncategorized:
       
   217                 {
       
   218                 // Append 'Uncategorised' if necessary
       
   219                 AppendUncatDestinationL( *itemArray, *icons );
       
   220                 break;
       
   221                 }
       
   222             case KDestItemEasyWlan:
       
   223                 {
       
   224                 // Append 'EasyWlan' if supported
       
   225                 TRAPD( err, AppendEasyWlanL( *itemArray, *icons ) );
       
   226                 if ( err != KErrNotSupported )
       
   227                     {
       
   228                     User::LeaveIfError( err );
       
   229                     }
       
   230                 break;
       
   231                 }
       
   232             // normal destination
       
   233             default:
       
   234                 {
       
   235                 CCmDestinationImpl* dest = 
       
   236                 iCmManager.DestinationL( iDestinations[i] );
       
   237                 CleanupStack::PushL( dest );
       
   238                 TInt numCms = dest->ConnectionMethodCount();        
       
   239                 AppendDestinationTextsL( *dest,numCms, *itemArray, *icons );                
       
   240                 CleanupStack::PopAndDestroy( dest );
       
   241                 break;
       
   242                 }                    
       
   243             }
       
   244         }
       
   245     }
       
   246 
       
   247 
       
   248 // --------------------------------------------------------------------------
       
   249 // CmPluginVpnNextLayerSelectDlg::AppendDestinationsTextsL
       
   250 // --------------------------------------------------------------------------
       
   251 //
       
   252 void CmPluginVpnNextLayerSelectDlg::AppendDestinationTextsL(
       
   253                                             CCmDestinationImpl& aDestination,
       
   254                                             TInt aNumCms,
       
   255                                             CDesCArray& aItems,
       
   256                                             CArrayPtr<CGulIcon>& aIcons )
       
   257     {
       
   258     LOGGER_ENTERFN( "CmPluginVpnNextLayerSelectDlg::AppendDestinationL" );
       
   259     // icon
       
   260     CGulIcon* icon = ( CGulIcon* ) aDestination.IconL();
       
   261     CleanupStack::PushL( icon );
       
   262     aIcons.AppendL( icon );
       
   263     TInt iconIndex = aIcons.Count() - 1;
       
   264     CleanupStack::Pop( icon ); // icon array took over ownership
       
   265     
       
   266     // compile the list item
       
   267     HBufC* firstLine = aDestination.NameLC();
       
   268     HBufC* secondLine;
       
   269     
       
   270     if ( aNumCms == 1 )
       
   271         {
       
   272         secondLine = StringLoader::LoadLC(
       
   273                         R_CMMANAGERUI_CONN_METHODS_AMOUNT_ONE );
       
   274         }
       
   275     else
       
   276         {
       
   277         secondLine = StringLoader::LoadLC( 
       
   278                         R_CMMANAGERUI_CONN_METHODS_AMOUNT_MANY,
       
   279                         aNumCms );
       
   280         }
       
   281         
       
   282     HBufC* item = FormatListItemTextsLC( *firstLine, 
       
   283                                          *secondLine,
       
   284                                          iconIndex );
       
   285     aItems.AppendL( *item );
       
   286 
       
   287     CleanupStack::PopAndDestroy( item );
       
   288     CleanupStack::PopAndDestroy( secondLine );
       
   289     CleanupStack::PopAndDestroy( firstLine );
       
   290     }
       
   291 
       
   292 // --------------------------------------------------------------------------
       
   293 // CmPluginVpnNextLayerSelectDlg::AppendUncatDestinationL
       
   294 // --------------------------------------------------------------------------
       
   295 //
       
   296 void CmPluginVpnNextLayerSelectDlg::AppendUncatDestinationL( 
       
   297                                                 CDesCArray& aItems,
       
   298                                                 CArrayPtr<CGulIcon>& aIcons )
       
   299     {
       
   300     LOGGER_ENTERFN( "CmPluginVpnNextLayerSelectDlg::AppendUncatDestinationL" );
       
   301 
       
   302     TParse mbmFile;
       
   303     User::LeaveIfError( mbmFile.Set( KManagerIconFilename, 
       
   304                         &KDC_APP_BITMAP_DIR, 
       
   305                         NULL ) );
       
   306     
       
   307     // icon
       
   308     CGulIcon* icon = AknsUtils::CreateGulIconL(
       
   309                 AknsUtils::SkinInstance(), 
       
   310                 KAknsIIDQgnPropSetConnDestUncategorized,
       
   311                 mbmFile.FullName(), 
       
   312                 EMbmCmmanagerQgn_prop_set_conn_dest_uncategorized, 
       
   313                 EMbmCmmanagerQgn_prop_set_conn_dest_uncategorized_mask );
       
   314     CleanupStack::PushL( icon );
       
   315     aIcons.AppendL( icon );
       
   316     CleanupStack::Pop( icon );  // icon array took over ownership
       
   317     TInt iconIndex = aIcons.Count() - 1;
       
   318     
       
   319     // remove virtual CMs
       
   320     RArray<TUint32> uncatCms ( KCmArraySmallGranularity );    
       
   321     iCmManager.ConnectionMethodL( uncatCms );
       
   322     CleanupClosePushL( uncatCms );
       
   323     
       
   324     for ( TInt i = 0; i < uncatCms.Count(); i++ )
       
   325         {
       
   326         TInt bearerType = iCmManager.GetConnectionMethodInfoIntL( 
       
   327                                         uncatCms[i], ECmBearerType );
       
   328         
       
   329         if ( iCmManager.GetBearerInfoBoolL( bearerType, ECmVirtual ) )
       
   330             {
       
   331             uncatCms.Remove(i);
       
   332             i--;
       
   333             }        
       
   334         }
       
   335     
       
   336     // second line text
       
   337     HBufC* secondLine;            
       
   338     if ( uncatCms.Count() == 1 )
       
   339         {
       
   340         secondLine = StringLoader::LoadLC(
       
   341                             R_CMMANAGERUI_CONN_METHODS_AMOUNT_ONE );
       
   342         }
       
   343     else
       
   344         {
       
   345         secondLine = StringLoader::LoadLC( 
       
   346                             R_CMMANAGERUI_CONN_METHODS_AMOUNT_MANY,
       
   347                             uncatCms.Count() );
       
   348         }    
       
   349 
       
   350     // compile the texts
       
   351     HBufC* item = FormatListItemTextsLC( R_CMMANAGERUI_DEST_UNCATEGORIZED,
       
   352                                          *secondLine,
       
   353                                          iconIndex );            
       
   354     aItems.AppendL( *item );
       
   355 
       
   356     CleanupStack::PopAndDestroy( item );
       
   357     CleanupStack::PopAndDestroy( secondLine );
       
   358     CleanupStack::PopAndDestroy( &uncatCms );
       
   359     }
       
   360                                                  
       
   361 // --------------------------------------------------------------------------
       
   362 // CmPluginVpnNextLayerSelectDlg::AppendEasyWlanL
       
   363 // --------------------------------------------------------------------------
       
   364 //
       
   365 void CmPluginVpnNextLayerSelectDlg::AppendEasyWlanL( 
       
   366                                                 CDesCArray& aItems,
       
   367                                                 CArrayPtr<CGulIcon>& aIcons )
       
   368     {
       
   369     LOGGER_ENTERFN( "CmPluginVpnNextLayerSelectDlg::AppendEasyWlanL" );
       
   370 
       
   371     // icon
       
   372     CCmPluginBase* cm = iCmManager.GetConnectionMethodL( iEasyWlanId );
       
   373     CleanupStack::PushL( cm );
       
   374     CGulIcon* icon = ( CGulIcon* ) cm->GetIntAttributeL( ECmBearerIcon );
       
   375     CleanupStack::PushL( icon );
       
   376     aIcons.AppendL( icon );  // ownership passed to array
       
   377     TInt iconIndex = aIcons.Count() - 1;
       
   378     CleanupStack::Pop( icon );
       
   379     CleanupStack::PopAndDestroy( cm );
       
   380     
       
   381     // compile the texts
       
   382     HBufC* easyWlan = FormatListItemTextsLC( 
       
   383                                 R_QTN_NETW_CONSET_VPN_EASY_WLAN,
       
   384                                 R_QTN_NETW_CONSET_VPN_EASY_WLAN_PROMPT,
       
   385                                 iconIndex );
       
   386     aItems.AppendL( *easyWlan );
       
   387     
       
   388     CleanupStack::PopAndDestroy( easyWlan );
       
   389     }
       
   390     
       
   391 // --------------------------------------------------------------------------
       
   392 // CmPluginVpnNextLayerSelectDlg::DynInitMenuPaneL
       
   393 // --------------------------------------------------------------------------
       
   394 //
       
   395 void CmPluginVpnNextLayerSelectDlg::DynInitMenuPaneL( 
       
   396                                 TInt aResourceId, CEikMenuPane* aMenuPane )
       
   397     {
       
   398     if ( aResourceId == R_VPN_REAL_CM_SELECTION_MENU )
       
   399         {
       
   400     	if (!iCmManager.IsHelpOn())
       
   401             {
       
   402             aMenuPane->DeleteMenuItem( EAknCmdHelp );		    
       
   403             }
       
   404         TUint32 highlighted = iDestinations[ ListBox()->CurrentItemIndex() ];
       
   405         
       
   406         switch ( highlighted )
       
   407             {
       
   408             case KDestItemUncategorized:
       
   409                 {
       
   410                 aMenuPane->SetItemDimmed( ECmManagerUiCmdDestSelect, ETrue );
       
   411                 break;                
       
   412                 }
       
   413             case KDestItemEasyWlan:
       
   414                 {
       
   415                 aMenuPane->SetItemDimmed( ECmManagerUiCmdCMSelect, ETrue );
       
   416                 break;
       
   417                 }
       
   418             default:
       
   419                 {
       
   420                 break;
       
   421                 }
       
   422             }
       
   423         }
       
   424     }
       
   425 
       
   426 // --------------------------------------------------------------------------
       
   427 // CmPluginVpnNextLayerSelectDlg::ProcessCommandL
       
   428 // --------------------------------------------------------------------------
       
   429 //
       
   430 void CmPluginVpnNextLayerSelectDlg::ProcessCommandL( TInt aCommandId )
       
   431     {
       
   432     if ( MenuShowing() )
       
   433         {
       
   434         HideMenu();
       
   435         }
       
   436     switch ( aCommandId )
       
   437         {
       
   438         case EAknSoftkeyOptions:
       
   439             {
       
   440             DisplayMenuL();
       
   441             break;
       
   442             }
       
   443         case ECmManagerUiCmdDestSelect:
       
   444             {            
       
   445             TUint32 destId = iDestinations[ ListBox()->CurrentItemIndex() ];
       
   446             
       
   447             if ( destId != KDestItemUncategorized )
       
   448                 {
       
   449                 TUint32 attribute = ECmNextLayerSNAPId;
       
   450                 
       
   451                 // EasyWlan was selected
       
   452                 if ( destId == KDestItemEasyWlan )
       
   453                     {
       
   454                     attribute = ECmNextLayerIapId;
       
   455                     destId = iEasyWlanId;
       
   456                     }
       
   457                 iCmPluginBaseEng.SetIntAttributeL( attribute, destId );
       
   458 
       
   459                 // We cannot use TryExitL here, since if the pointer event
       
   460                 // handling is ongoing, i.e., we got here from this class's
       
   461                 // HandleListBoxEventL, there will be a KERN-EXEC 3 panic.
       
   462                 // Calling base class HandleListBoxEventL will exit the
       
   463                 // dialog asynchronously with return value ETrue.
       
   464                 CAknListQueryDialog::HandleListBoxEventL( ListBox(),
       
   465                      EEventItemSingleClicked );
       
   466                 break;
       
   467                 }
       
   468             
       
   469             // For uncategorised destinations, flow through to ECmManagerUiCmdCMSelect
       
   470             }
       
   471         case ECmManagerUiCmdCMSelect:
       
   472             {
       
   473             // select a connection method from the highlighted destination
       
   474             TUint32 destId = iDestinations[ ListBox()->CurrentItemIndex() ];
       
   475             TUint32 cmId (0);
       
   476             if ( ShowCMSelectionDlgL( destId, cmId ) )
       
   477                 {
       
   478                 iCmPluginBaseEng.SetIntAttributeL( ECmNextLayerIapId, cmId );
       
   479                 
       
   480                 // We cannot use TryExitL here, since if the pointer event
       
   481                 // handling is ongoing, i.e., we got here from this class's
       
   482                 // HandleListBoxEventL, there will be a KERN-EXEC 3 panic.
       
   483                 // Calling base class HandleListBoxEventL will exit the
       
   484                 // dialog asynchronously with return value ETrue.
       
   485                 CAknListQueryDialog::HandleListBoxEventL( ListBox(),
       
   486                                      EEventItemSingleClicked );
       
   487                 }
       
   488             else
       
   489                 {
       
   490                 // We need to exit asynchronously, in case we ended up here
       
   491                 // from HandleListBoxEventL. The callback function will exit
       
   492                 // the dialog with return value EFalse.
       
   493                 TCallBack cb( CancelAsynchronouslyL, this );
       
   494                 iAsyncCancel = new( ELeave ) CAsyncCallBack( cb, CActive::EPriorityHigh );
       
   495                 iAsyncCancel->CallBack();
       
   496                 }
       
   497             break;
       
   498             }
       
   499         case EAknCmdHelp:
       
   500             {
       
   501             HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   502                                     iEikonEnv->EikAppUi()->AppHelpContextL() );
       
   503             }
       
   504             break;
       
   505         case EAknSoftkeyBack:
       
   506             {
       
   507             TryExitL( EAknSoftkeyBack );
       
   508             break;
       
   509             } 
       
   510         default:
       
   511             {
       
   512             CAknListQueryDialog::ProcessCommandL( aCommandId );
       
   513             break;
       
   514             }
       
   515         }
       
   516     }
       
   517 
       
   518 // ---------------------------------------------------------------------------
       
   519 // CmPluginVpnNextLayerSelectDlg::OfferKeyEventL
       
   520 // ---------------------------------------------------------------------------
       
   521 //
       
   522 TKeyResponse CmPluginVpnNextLayerSelectDlg::OfferKeyEventL( 
       
   523                                                 const TKeyEvent& aKeyEvent, 
       
   524                                                 TEventCode aType )    
       
   525     {
       
   526     TKeyResponse retVal ( EKeyWasNotConsumed );
       
   527     TUint highlighted = iDestinations[ ListBox()->CurrentItemIndex() ];
       
   528     
       
   529     switch ( aKeyEvent.iScanCode )
       
   530         {
       
   531         case EStdKeyDownArrow:
       
   532         case EStdKeyUpArrow:
       
   533             {
       
   534             // If focus is on the 'uncategorised' destination, 
       
   535             // change the soft key to 'Open'
       
   536             if ( highlighted == KDestItemUncategorized )
       
   537                 {
       
   538                 ButtonGroupContainer().SetCommandL( 
       
   539                                 ECmManagerUiCmdDestSelect, 
       
   540                                 *( StringLoader::LoadLC( R_QTN_MSK_OPEN ) ) 
       
   541                                                     );
       
   542                 ButtonGroupContainer().DrawDeferred();
       
   543                 CleanupStack::PopAndDestroy();
       
   544                 }
       
   545             else
       
   546                 {
       
   547                 ButtonGroupContainer().SetCommandL( 
       
   548                                ECmManagerUiCmdDestSelect, 
       
   549                                *( StringLoader::LoadLC( R_QTN_MSK_SELECT ) ) 
       
   550                                                     );
       
   551                 ButtonGroupContainer().DrawDeferred();
       
   552                 CleanupStack::PopAndDestroy();
       
   553                 }
       
   554             break;
       
   555             }
       
   556         case EStdKeyNo:
       
   557             {
       
   558             TryExitL( EAknSoftkeyCancel );
       
   559             return EKeyWasConsumed;
       
   560             }
       
   561         default:
       
   562             {
       
   563             // If focus is on the 'uncategorised' destination, 
       
   564             // change the soft key to 'Open'
       
   565             if ( highlighted == KDestItemUncategorized )
       
   566                 {
       
   567                 ButtonGroupContainer().SetCommandL( 
       
   568                                 ECmManagerUiCmdDestSelect, 
       
   569                                 *( StringLoader::LoadLC( R_QTN_MSK_OPEN ) ) 
       
   570                                                     );
       
   571                 ButtonGroupContainer().DrawDeferred();
       
   572                 CleanupStack::PopAndDestroy();
       
   573                 }
       
   574                 
       
   575             if ( aKeyEvent.iCode == EKeyEscape )
       
   576                 {
       
   577                 TryExitL( EAknSoftkeyCancel );
       
   578                 return EKeyWasConsumed;
       
   579                 }
       
   580             }
       
   581         }
       
   582     retVal = ListBox()->OfferKeyEventL( aKeyEvent, aType );
       
   583     
       
   584     return retVal;
       
   585     }
       
   586 
       
   587 
       
   588 // ---------------------------------------------------------------------------
       
   589 // CmPluginVpnNextLayerSelectDlg::HandleListBoxEventL
       
   590 // ---------------------------------------------------------------------------
       
   591 void CmPluginVpnNextLayerSelectDlg::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   592                                     TListBoxEvent aEventType )
       
   593     {
       
   594     switch ( aEventType )
       
   595         {
       
   596         case EEventEnterKeyPressed:
       
   597         case EEventItemSingleClicked:
       
   598             {
       
   599             ProcessCommandL( ECmManagerUiCmdDestSelect );
       
   600             
       
   601             break;
       
   602             }
       
   603         default:
       
   604             {
       
   605             break;
       
   606             };
       
   607         };
       
   608     }
       
   609 
       
   610     
       
   611 // --------------------------------------------------------------------------
       
   612 // CmPluginVpnNextLayerSelectDlg::LoadResourceL
       
   613 // --------------------------------------------------------------------------
       
   614 //
       
   615 void CmPluginVpnNextLayerSelectDlg::LoadResourceL( 
       
   616                                                 const TDesC& aResFileName )
       
   617     {
       
   618     LOGGER_ENTERFN( "CmPluginVpnNextLayerSelectDlg::LoadResourceL" );
       
   619     TInt err ( KErrNone );
       
   620     
       
   621     // Add resource file.
       
   622     TParse* fp = new ( ELeave ) TParse();
       
   623     err = fp->Set( aResFileName, 
       
   624                         &KDC_RESOURCE_FILES_DIR, 
       
   625                         NULL ); 
       
   626     if ( err )
       
   627         {
       
   628         User::Leave( err );
       
   629         }   
       
   630 
       
   631     TFileName resourceFileNameBuf = fp->FullName();
       
   632     delete fp;
       
   633 
       
   634     iResourceReader.OpenL( resourceFileNameBuf );
       
   635     }
       
   636 
       
   637 
       
   638 // --------------------------------------------------------------------------
       
   639 // CmPluginVpnNextLayerSelectDlg::FormatListItemTextsLC
       
   640 // --------------------------------------------------------------------------
       
   641 //
       
   642 HBufC* CmPluginVpnNextLayerSelectDlg::FormatListItemTextsLC( 
       
   643                                                 TInt aFirstLineResId,
       
   644                                                 TInt aSecondLineResId,
       
   645                                                 TInt aIconIndex )
       
   646     {
       
   647     HBufC* firstLine = StringLoader::LoadLC( aFirstLineResId );
       
   648     HBufC* secondLine = StringLoader::LoadLC( aSecondLineResId );
       
   649     
       
   650     HBufC* retVal = FormatListItemTextsL( *firstLine,
       
   651                                           *secondLine,
       
   652                                           aIconIndex );
       
   653     CleanupStack::PopAndDestroy( secondLine );
       
   654     CleanupStack::PopAndDestroy( firstLine );
       
   655     CleanupStack::PushL( retVal );
       
   656     return retVal;
       
   657     }
       
   658     
       
   659 // --------------------------------------------------------------------------
       
   660 // CmPluginVpnNextLayerSelectDlg::FormatListItemTextsLC
       
   661 // --------------------------------------------------------------------------
       
   662 //
       
   663 HBufC* CmPluginVpnNextLayerSelectDlg::FormatListItemTextsLC( 
       
   664                                                 const TDesC& aFirstLine,
       
   665                                                 const TDesC& aSecondLine,
       
   666                                                 TInt aIconIndex )
       
   667     {
       
   668     HBufC* retVal = FormatListItemTextsL( aFirstLine,
       
   669                                           aSecondLine,
       
   670                                           aIconIndex );
       
   671     CleanupStack::PushL( retVal );
       
   672     return retVal;
       
   673     }
       
   674 
       
   675 // --------------------------------------------------------------------------
       
   676 // CmPluginVpnNextLayerSelectDlg::FormatListItemTextsLC
       
   677 // --------------------------------------------------------------------------
       
   678 //
       
   679 HBufC* CmPluginVpnNextLayerSelectDlg::FormatListItemTextsLC( 
       
   680                                                 TInt aFirstLineResId,
       
   681                                                 const TDesC& aSecondLine,
       
   682                                                 TInt aIconIndex )
       
   683     {
       
   684     // Load the first string
       
   685     HBufC* firstLine = StringLoader::LoadLC( aFirstLineResId );
       
   686     
       
   687     HBufC* retVal = FormatListItemTextsL( *firstLine,
       
   688                                           aSecondLine,
       
   689                                           aIconIndex );
       
   690     CleanupStack::PopAndDestroy( firstLine );
       
   691     CleanupStack::PushL( retVal );
       
   692     return retVal;
       
   693     }
       
   694 
       
   695 // --------------------------------------------------------------------------
       
   696 // CmPluginVpnNextLayerSelectDlg::FormatListItemTextsL
       
   697 // --------------------------------------------------------------------------
       
   698 //
       
   699 HBufC* CmPluginVpnNextLayerSelectDlg::FormatListItemTextsL( 
       
   700                                                 const TDesC& aFirstLine,
       
   701                                                 const TDesC& aSecondLine,
       
   702                                                 TInt aIconIndex )
       
   703     {
       
   704     HBufC* retVal = HBufC::NewL( aFirstLine.Length() + 
       
   705                            aSecondLine.Length() + 
       
   706                            KNumberOfStaticCharsIn2LineFormattedString );
       
   707     
       
   708     TPtr ptr ( retVal->Des() );
       
   709     ptr.AppendNum( aIconIndex );
       
   710     ptr.Append( TChar( KSettingsListBoxItemPrefix ) );
       
   711     ptr.Append( aFirstLine );
       
   712     ptr.Append( TChar( KSettingsListBoxItemPrefix ) );
       
   713     ptr.Append( aSecondLine );
       
   714     
       
   715     return retVal;
       
   716     }
       
   717 
       
   718 // --------------------------------------------------------------------------
       
   719 // CmPluginVpnNextLayerSelectDlg::ShowCMSelectionDlgL
       
   720 // --------------------------------------------------------------------------
       
   721 //
       
   722 TBool CmPluginVpnNextLayerSelectDlg::ShowCMSelectionDlgL( 
       
   723                                                     TUint32 aDestinationId,
       
   724                                                     TUint32& aCmId )
       
   725     {
       
   726     LOGGER_ENTERFN( "CmPluginVpnNextLayerSelectDlg::ShowCMSelectionDlgL" );
       
   727     TBool retVal ( EFalse );
       
   728         
       
   729     // Collect item texts
       
   730     CDesCArrayFlat* items = 
       
   731             new ( ELeave ) CDesCArrayFlat( KCmArraySmallGranularity );
       
   732     CleanupStack::PushL( items );
       
   733     
       
   734     RPointerArray<CCmPluginBase> cmDataArray ( KCmArrayMediumGranularity );
       
   735     iCmManager.CreateFlatCMListLC( aDestinationId , cmDataArray );
       
   736     CleanupStack::Pop( &cmDataArray );
       
   737     CCmManagerImpl::CleanupResetAndDestroyPushL(cmDataArray);
       
   738     iCmManager.FilterOutVirtualsL( cmDataArray );
       
   739 
       
   740 
       
   741     // after it, get the names for each element
       
   742     // and finally make up the real items array.
       
   743     
       
   744     // Get the names of the connection methods
       
   745     // virtuals are already filtered out, 
       
   746     TInt count = cmDataArray.Count();
       
   747     for ( TInt i = 0; i < count; i++ )
       
   748         {
       
   749         HBufC* cmName = 
       
   750             iCmManager.GetConnectionMethodInfoStringL( cmDataArray[i]->GetIntAttributeL( ECmId ),
       
   751                                                        ECmName );
       
   752         CleanupStack::PushL( cmName );
       
   753             
       
   754         // append the name to the string
       
   755         items->AppendL( *cmName );
       
   756             
       
   757         CleanupStack::PopAndDestroy( cmName );
       
   758         }
       
   759         
       
   760     // Display the radio button page
       
   761     TInt selected ( 0 );
       
   762     TInt resId( R_VPN_REAL_CM_RADIO_BUTTON_SETTING_PAGE );
       
   763         
       
   764     CAknRadioButtonSettingPage* dlg = 
       
   765                             new ( ELeave ) CAknRadioButtonSettingPage(
       
   766                                     resId,
       
   767                                     selected, 
       
   768                                     items );
       
   769     CleanupStack::PushL( dlg );
       
   770     dlg->SetSettingTextL(
       
   771                 *StringLoader::LoadLC( R_CMWIZARD_SELECT_CONN_METHOD ) );
       
   772     CleanupStack::PopAndDestroy();            
       
   773     CleanupStack::Pop( dlg );
       
   774 
       
   775     TInt result = 0;
       
   776     TRAPD( err, result = dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ) );
       
   777 
       
   778     User::LeaveIfError( err );
       
   779 
       
   780     if ( result )
       
   781 
       
   782         {
       
   783         // store result
       
   784         aCmId = cmDataArray[ selected ]->GetIntAttributeL( ECmId );
       
   785         retVal = ETrue;
       
   786         }
       
   787     
       
   788     CleanupStack::PopAndDestroy( &cmDataArray );
       
   789     CleanupStack::PopAndDestroy( items );
       
   790     return retVal;
       
   791     }
       
   792     
       
   793 
       
   794 // --------------------------------------------------------------------------
       
   795 // CmPluginVpnNextLayerSelectDlg::GetHelpContext
       
   796 // --------------------------------------------------------------------------
       
   797 //
       
   798 void CmPluginVpnNextLayerSelectDlg::GetHelpContext( 
       
   799                                             TCoeHelpContext& aContext ) const
       
   800     {
       
   801     aContext.iMajor = KHelpUidPlugin;
       
   802     aContext.iContext = KSET_HLP_VPN_DEST_ASSOC_VIEW;
       
   803     }
       
   804