cmmanager/cmmgr/Framework/Src/cmdlg.cpp
branchRCL_3
changeset 57 05bc53fe583b
parent 55 fc7b30ed2058
child 58 83ca720e2b9a
equal deleted inserted replaced
55:fc7b30ed2058 57:05bc53fe583b
     1 /*
       
     2 * Copyright (c) 2006-2008 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:  Implementation of CCmDlg
       
    15 *
       
    16 */
       
    17 
       
    18 #include <avkon.hrh>
       
    19 #include <eikdef.h>
       
    20 #include <eikenv.h>
       
    21 #include <eikedwin.h>
       
    22 #include <cmmanager.rsg>
       
    23 #include <data_caging_path_literals.hrh>
       
    24 #include <aknnavide.h>
       
    25 #include <akntitle.h>
       
    26 #include <eikmenup.h>
       
    27 #include <StringLoader.h>
       
    28 #include <AknIconArray.h>
       
    29 #include <aknnavilabel.h>
       
    30 #include <cmmanager.mbg>
       
    31 #include <cmpluginembdestinationdef.h>
       
    32 #include <featmgr.h>
       
    33 
       
    34 #include <hlplch.h>
       
    35 #include <csxhelp/cp.hlp.hrh>
       
    36 
       
    37 #include "cmdlg.h"
       
    38 #include "cmmanager.hrh"
       
    39 #include "cmlistitem.h"
       
    40 #include "cmlistitemlist.h"
       
    41 #include <cmpluginbaseeng.h>
       
    42 #include <cmpluginbase.h>
       
    43 #include "cmdestinationimpl.h"
       
    44 #include <cmcommonui.h>
       
    45 #include <cmcommonconstants.h>
       
    46 #include <cmpbasesettingsdlg.h>
       
    47 #include "cmwizard.h"
       
    48 #include "selectdestinationdlg.h"
       
    49 #include <cmmanagerdef.h>
       
    50 #include <mcmdexec.h>
       
    51 #include "ccmdexec.h"
       
    52 #include "destdlg.h"
       
    53 #include "cmlogger.h"
       
    54 #include "cmconnsettingsuiimpl.h"
       
    55 
       
    56 using namespace CMManager;
       
    57 using namespace CommsDat;
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CCmDlg::ConstructAndRunLD
       
    61 // Constructs the dialog and runs it.
       
    62 // ---------------------------------------------------------------------------
       
    63 //
       
    64 TInt CCmDlg::ConstructAndRunLD(  TUint32 aHighlight,
       
    65                                           TUint32& aSelected )
       
    66     {
       
    67     CleanupStack::PushL( this );
       
    68 
       
    69     iHighlight = aHighlight;
       
    70     iSelected = &aSelected;
       
    71     
       
    72     ConstructL( R_CM_MENUBAR );
       
    73     PrepareLC( R_CM_DIALOG );
       
    74     CleanupStack::Pop( this );
       
    75 
       
    76     iModel = new( ELeave )CCmListboxModel();
       
    77     
       
    78     iCmDestinationImpl = iCmManager->DestinationL( iDestUid );
       
    79     
       
    80     iInfoPopupNoteController = CAknInfoPopupNoteController::NewL();
       
    81     
       
    82     // Trace changes in CommsDat
       
    83     iCmManager->WatcherRegisterL( this );
       
    84         
       
    85     return RunLD();
       
    86     }
       
    87     
       
    88 // ---------------------------------------------------------------------------
       
    89 // CCmDlg::NewL()
       
    90 // Two-phase dconstructor, second phase is ConstructAndRunLD
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 CCmDlg* CCmDlg::NewL(CCmManagerImpl* aCmManager, TUint32 aDestUid,
       
    94                      CDestDlg* aDestDlg)
       
    95     {
       
    96     CCmDlg* self = new (ELeave) CCmDlg( aCmManager, aDestUid, aDestDlg );
       
    97     return self;
       
    98     }
       
    99     
       
   100 // ---------------------------------------------------------------------------
       
   101 // CCmDlg::CCmDlg()
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 CCmDlg::CCmDlg( CCmManagerImpl* aCmManager, TUint32 aDestUid,
       
   105                 CDestDlg* aDestDlg )
       
   106     : iModelPassed( EFalse )
       
   107     , iCmManager( aCmManager )
       
   108     , iDestUid ( aDestUid )
       
   109     , iPrioritising ( EFalse )
       
   110     , iExitReason( KDialogUserExit )
       
   111     , iEscapeArrived( EFalse )
       
   112     , iExitduringProcessing( EFalse )
       
   113     , iBackduringProcessing( EFalse )
       
   114     , iDestDlg( aDestDlg )
       
   115     , iPluginExitExceptionally( EFalse )
       
   116     {
       
   117     }
       
   118     
       
   119 // ---------------------------------------------------------------------------
       
   120 // CCmDlg::~CCmDlg
       
   121 // Destructor
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 CCmDlg::~CCmDlg()
       
   125     {
       
   126     // iModel is deleted by the ListBox because LB owns the model...
       
   127     // of course only after we passed ownership...
       
   128     if ( !iModelPassed )
       
   129         {
       
   130         delete iModel;
       
   131         }
       
   132         
       
   133     delete iNaviDecorator;
       
   134     
       
   135     if ( iTitlePane )
       
   136         {
       
   137         // set old text back, if we have it...
       
   138         if ( iOldTitleText )
       
   139             {
       
   140             if ( iExitReason == KDialogUserBack || iPluginExitExceptionally  )
       
   141                 {
       
   142                 TRAP_IGNORE( iTitlePane->SetTextL( *iOldTitleText ) );
       
   143                 }
       
   144             delete iOldTitleText; iOldTitleText = NULL;
       
   145             }
       
   146         }    
       
   147         
       
   148     delete iOldTitleText;
       
   149     
       
   150     if(iCmDestinationImpl)
       
   151         {
       
   152         delete iCmDestinationImpl;
       
   153         iCmDestinationImpl = NULL;
       
   154         }    
       
   155     
       
   156     if ( iInfoPopupNoteController )
       
   157         {
       
   158         delete iInfoPopupNoteController;
       
   159         }
       
   160         
       
   161     if( iCmWizard )
       
   162         {
       
   163         delete iCmWizard;
       
   164         }
       
   165     iItemIndex.Close();
       
   166     
       
   167     delete iCmdExec;
       
   168     iCmdExec = NULL;
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // CCmDlg::PreLayoutDynInitL();
       
   173 // called by framework before dialog is shown
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CCmDlg::PreLayoutDynInitL()
       
   177     {
       
   178     iListbox = STATIC_CAST( CCmListbox*, Control( KCmListboxId ) );
       
   179     iListbox->CreateScrollBarFrameL( ETrue );
       
   180     iListbox->ScrollBarFrame()->SetScrollBarVisibilityL
       
   181                         ( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
       
   182     iListbox->SetListBoxObserver( this );
       
   183 
       
   184     iListbox->Model()->SetItemTextArray( iModel );
       
   185     iModelPassed = ETrue;
       
   186     InitTextsL();
       
   187     HandleListboxDataChangeL();
       
   188     iListbox->HandleItemAdditionL();
       
   189     
       
   190     if ( iHighlight )
       
   191         {
       
   192         iListbox->ScrollToMakeItemVisible( iHighlight );
       
   193         iListbox->SetCurrentItemIndex( iHighlight );
       
   194         }    
       
   195     }
       
   196     
       
   197 // --------------------------------------------------------------------------
       
   198 // CCmDlg::DynInitMenuPaneL
       
   199 // --------------------------------------------------------------------------
       
   200 //
       
   201 void CCmDlg::DynInitMenuPaneL( TInt aResourceId,
       
   202                                         CEikMenuPane* aMenuPane )
       
   203     {
       
   204     CAknDialog::DynInitMenuPaneL( aResourceId, aMenuPane );        
       
   205     
       
   206     if ( aResourceId == R_CM_MENU )
       
   207         {
       
   208     	if ( !iCmManager->IsHelpOn() )
       
   209             {
       
   210             aMenuPane->DeleteMenuItem( EAknCmdHelp );		    
       
   211             }
       
   212         // Menu items
       
   213     	TBool hideEdit      ( EFalse );
       
   214         TBool hideAdd       ( EFalse );
       
   215         TBool hideRename    ( EFalse );
       
   216         TBool hideDelete    ( EFalse );
       
   217         TBool hideCopy      ( EFalse );
       
   218         TBool hideMove      ( EFalse );
       
   219         TBool hidePrioritise( EFalse );
       
   220            
       
   221         // Edit, Rename, Delete and Organise menu items are hidden if:
       
   222         // 1. CM List is empty
       
   223         // 2. Embedded Destinations
       
   224         if ( !( iListbox->Model()->ItemTextArray()->MdcaCount() ) )
       
   225             {
       
   226             hidePrioritise = ETrue;
       
   227             hideEdit = ETrue;
       
   228             hideRename  = ETrue;
       
   229             hideDelete  = ETrue;
       
   230             hideCopy = ETrue;
       
   231             hideMove = ETrue;
       
   232             }
       
   233         // Embedded destinations can be deleted but not edited
       
   234         else if ( ( CurrentCML()->GetBoolAttributeL(ECmDestination) ) )
       
   235             {
       
   236             hideRename  = ETrue;
       
   237             }
       
   238         // Only one CM in the list OR highlighted CM is a virtual CM
       
   239         else if ( ( iListbox->Model()->ItemTextArray()->MdcaCount() == 1 ) )
       
   240             {
       
   241             hidePrioritise = ETrue;
       
   242             }            
       
   243         // virtual CMs pointing to destinations
       
   244         else if ( CurrentCML()->GetBoolAttributeL( ECmVirtual ) )
       
   245             {
       
   246             if ( CurrentCML()->GetIntAttributeL( ECmNextLayerSNAPId ) )
       
   247                 {
       
   248                 hidePrioritise = ETrue;
       
   249                 }
       
   250             }
       
   251  
       
   252         // All item specific options need to be dimmed if in prioritising view
       
   253         if ( iPrioritising )
       
   254             {
       
   255             hideEdit = ETrue;
       
   256             hideAdd = ETrue;
       
   257             hideRename = ETrue;
       
   258             hideDelete = ETrue;
       
   259             hideCopy = ETrue;
       
   260             hideMove = ETrue;
       
   261             hidePrioritise = ETrue;           
       
   262             }
       
   263 
       
   264         // Show or hide menu items
       
   265         aMenuPane->SetItemDimmed( ECmManagerUiCmdCmEdit,    hideEdit );
       
   266         aMenuPane->SetItemDimmed( ECmManagerUiCmdCmAdd,     hideAdd );
       
   267         aMenuPane->SetItemDimmed( ECmManagerUiCmdCmRename,  hideRename );            
       
   268         aMenuPane->SetItemDimmed( ECmManagerUiCmdCmDelete,  hideDelete );    
       
   269         aMenuPane->SetItemDimmed( ECmManagerUiCmdCmPrioritise, hidePrioritise );
       
   270         aMenuPane->SetItemDimmed( ECmManagerUiCmdCmMoveToOtherDestination, hideMove );
       
   271         aMenuPane->SetItemDimmed( ECmManagerUiCmdCmCopyToOtherDestination, hideCopy ); 
       
   272         }   
       
   273     }
       
   274     
       
   275 // ---------------------------------------------------------------------------
       
   276 // CCmDlg::InitTextsL
       
   277 // called before the dialog is shown
       
   278 // to initialize localized textual data
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 void CCmDlg::InitTextsL()
       
   282     {
       
   283     // set pane text if neccessary...
       
   284     // pane text needed if not pop-up...
       
   285     HBufC* primary = 
       
   286               iEikonEnv->AllocReadResourceLC( R_CMMANAGERUI_EMPTY_METHOD_VIEW_PRIMARY );
       
   287     HBufC* secondary = 
       
   288               iEikonEnv->AllocReadResourceLC( R_CMMANAGERUI_EMPTY_METHOD_VIEW_SECONDARY );
       
   289     CDesCArrayFlat* items = new (ELeave) CDesCArrayFlat(2);
       
   290     CleanupStack::PushL(items);
       
   291     items->AppendL(primary->Des()); 
       
   292     items->AppendL(secondary->Des());      
       
   293     HBufC* emptyText = 
       
   294           StringLoader::LoadLC( R_TWO_STRING_FOR_EMPTY_VIEW , *items);              
       
   295     iListbox->View()->SetListEmptyTextL( *emptyText );    
       
   296     CleanupStack::PopAndDestroy( emptyText );
       
   297     CleanupStack::PopAndDestroy( items );
       
   298     CleanupStack::PopAndDestroy( secondary );
       
   299     CleanupStack::PopAndDestroy( primary );
       
   300 
       
   301     iStatusPane = iEikonEnv->AppUiFactory()->StatusPane();
       
   302     iTitlePane = ( CAknTitlePane* )iStatusPane->ControlL(
       
   303                                           TUid::Uid( EEikStatusPaneUidTitle ) );
       
   304 
       
   305     iOldTitleText = iTitlePane->Text()->AllocL();
       
   306     HBufC* name = iCmDestinationImpl->NameLC();
       
   307     iTitlePane->SetTextL( *name );
       
   308     CleanupStack::PopAndDestroy( name );
       
   309 
       
   310     iNaviPane = ( CAknNavigationControlContainer* ) 
       
   311                     iStatusPane->ControlL( 
       
   312                             TUid::Uid( EEikStatusPaneUidNavi ) );
       
   313     iNaviDecorator = iNaviPane->CreateNavigationLabelL( KNullDesC );
       
   314     iNaviPane->PushL( *iNaviDecorator );
       
   315     }
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // CCmDlg::SetNoOfCMsL
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 
       
   322 void CCmDlg::SetNoOfCMsL(TInt aCount)
       
   323     {
       
   324     if ( iNaviDecorator )
       
   325         {
       
   326         if ( iNaviDecorator->ControlType() == 
       
   327              CAknNavigationDecorator::ENaviLabel)
       
   328             {
       
   329             CAknNaviLabel* naviLabel = 
       
   330                             (CAknNaviLabel*)iNaviDecorator->DecoratedControl();
       
   331             if (aCount)
       
   332                 {
       
   333                 HBufC* title = NULL;
       
   334                 
       
   335                 if (aCount == 1)
       
   336                     {
       
   337                     title = StringLoader::LoadLC( 
       
   338                                            R_CMMANAGERUI_NAVI_ONE_CONN_METHOD );
       
   339                     }
       
   340                 else
       
   341                     {
       
   342                     title = StringLoader::LoadLC( 
       
   343                                            R_CMMANAGERUI_NAVI_MANY_CONN_METHODS, 
       
   344                                            aCount );
       
   345                     }
       
   346                     
       
   347                 naviLabel->SetTextL(*title);
       
   348                   CleanupStack::PopAndDestroy( title );
       
   349                 }
       
   350             else
       
   351                 {
       
   352                 naviLabel->SetTextL(KNullDesC);
       
   353                 }
       
   354                 
       
   355             iNaviPane->PushL( *iNaviDecorator );
       
   356             }
       
   357         }
       
   358       
       
   359     }
       
   360 
       
   361 //----------------------------------------------------------
       
   362 // CCmDlg::CreateCustomControlL
       
   363 //----------------------------------------------------------
       
   364 //
       
   365 SEikControlInfo CCmDlg::CreateCustomControlL( TInt aControlType )
       
   366     {
       
   367     SEikControlInfo controlInfo;
       
   368     controlInfo.iTrailerTextId = 0;
       
   369     controlInfo.iFlags = 0;
       
   370     if ( aControlType == KCmListboxType )
       
   371         {
       
   372         controlInfo.iControl = new ( ELeave ) CCmListbox;
       
   373         }
       
   374     else
       
   375         {
       
   376         controlInfo.iControl = NULL;
       
   377         }
       
   378     return controlInfo;
       
   379     }
       
   380 
       
   381 // ---------------------------------------------------------------------------
       
   382 // CCmDlg::OkToExitL
       
   383 // Good to know : EAknSoftkeyCancel is never called, because
       
   384 // EEikDialogFlagNotifyEsc flag is not set in the resource.
       
   385 // ---------------------------------------------------------------------------
       
   386 //
       
   387 TBool CCmDlg::OkToExitL( TInt aButtonId )
       
   388     {
       
   389     LOGGER_ENTERFN( "CCmDlg::OkToExitL" );
       
   390 
       
   391     // Translate the button presses into commands for the appui & current
       
   392     // view to handle
       
   393     // Dialog should not exit
       
   394     TBool retVal( EFalse );
       
   395     
       
   396     switch ( aButtonId )
       
   397         {
       
   398         case EAknSoftkeyOk:
       
   399         case ECmManagerUiCmdCmEdit:
       
   400             {
       
   401             if ( !iProcessing )
       
   402                 {
       
   403                 if ( CMCount() )
       
   404                     {
       
   405                     iProcessing = ETrue;
       
   406                     ProcessCommandL( aButtonId );
       
   407                     iProcessing = EFalse;
       
   408                     }
       
   409                 else
       
   410                     {
       
   411                     iProcessing = ETrue;
       
   412                     AddConnectionMethodL();
       
   413                     iProcessing = EFalse;
       
   414                     }
       
   415                 }
       
   416             break;
       
   417             }
       
   418         case EAknSoftkeyClear:
       
   419             {
       
   420             ProcessCommandL( aButtonId );
       
   421             break;
       
   422             }
       
   423         case ECmManagerUiCmdCmPrioOk:
       
   424             {
       
   425             if ( iPrioritising )
       
   426                 {
       
   427                 FinishPriorizingL( ETrue );
       
   428                 }
       
   429                 
       
   430             break;
       
   431             }               
       
   432        case ECmManagerUiCmdCmPrioCancel:            
       
   433             {
       
   434             if ( !MenuShowing() )            
       
   435                 {
       
   436                 if ( iPrioritising )
       
   437                     {
       
   438                     FinishPriorizingL( EFalse );
       
   439                     }
       
   440                 }            
       
   441             break;
       
   442             }           
       
   443         case ECmManagerUiCmdCmUserExit:
       
   444             {
       
   445             iCmManager->WatcherUnRegister();
       
   446                         
       
   447             iExitReason = KDialogUserExit;
       
   448             break;
       
   449             }
       
   450         case EAknSoftkeyBack:
       
   451             {
       
   452             iCmManager->WatcherUnRegister();
       
   453             iExitReason = KDialogUserBack;
       
   454             
       
   455             if ( !iProcessing )
       
   456                 {
       
   457                 *iSelected = 0;
       
   458                 TryExitL( iExitReason );
       
   459                 }
       
   460             else
       
   461                 {
       
   462                 iBackduringProcessing = ETrue;
       
   463                 }
       
   464             break;
       
   465             }
       
   466         default:
       
   467             {
       
   468             if ( !iProcessing )
       
   469                 {
       
   470                 if ( aButtonId == EAknSoftkeyOptions )
       
   471                     {
       
   472                     DisplayMenuL();
       
   473                     }
       
   474                 else
       
   475                     {
       
   476                     retVal = ETrue;
       
   477                     }
       
   478                 }
       
   479             if ( iProcessing )
       
   480                 {
       
   481                 iExitduringProcessing = ETrue;
       
   482                 if( aButtonId == KDialogUserExit )
       
   483                     {
       
   484                     retVal = ETrue;
       
   485                     } 
       
   486                 
       
   487                 if ( iPluginExitExceptionally )
       
   488                     {
       
   489                     retVal = ETrue;
       
   490                     }
       
   491                 }
       
   492             break;
       
   493             }
       
   494         }
       
   495     return retVal;
       
   496     }
       
   497 
       
   498 // ---------------------------------------------------------------------------
       
   499 // CCmDlg::HandleListBoxEventL
       
   500 // ---------------------------------------------------------------------------
       
   501 //
       
   502 void CCmDlg::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
   503                                   TListBoxEvent aEventType )
       
   504     {
       
   505     LOGGER_ENTERFN( "CCmDlg::HandleListBoxEventL" );
       
   506 
       
   507     switch ( aEventType )
       
   508         {
       
   509         case EEventEnterKeyPressed:
       
   510             {
       
   511             if ( iPrioritising )
       
   512                 {
       
   513                 FinishPriorizingL( ETrue );
       
   514                 }
       
   515             else
       
   516                 {
       
   517                 if ( !iProcessing )
       
   518                     {
       
   519                     delete iCmdExec;
       
   520                     iCmdExec = NULL;
       
   521                     iCmdExec = new (ELeave) CCmdExec(*this);
       
   522                     iCmdExec->Execute();
       
   523                     }
       
   524                 }           
       
   525             break;            
       
   526             }
       
   527         case EEventItemSingleClicked:
       
   528             {
       
   529             if ( !iProcessing )
       
   530                 {
       
   531                 delete iCmdExec;
       
   532                 iCmdExec = NULL;
       
   533                 iCmdExec = new (ELeave) CCmdExec(*this);
       
   534                 iCmdExec->Execute();
       
   535                 }
       
   536             break;
       
   537             }
       
   538         case EEventEditingStarted:
       
   539             {
       
   540             break;
       
   541             }
       
   542         case EEventEditingStopped:
       
   543             {
       
   544             break;
       
   545             }
       
   546         default:
       
   547             {
       
   548             break;
       
   549             };
       
   550         };
       
   551     }
       
   552        
       
   553     
       
   554 // ---------------------------------------------------------------------------
       
   555 // CCmDlg::ProcessCommandL
       
   556 // ---------------------------------------------------------------------------
       
   557 //
       
   558 void CCmDlg::ProcessCommandL( TInt aCommandId )
       
   559     {
       
   560     LOGGER_ENTERFN( "CCmDlg::ProcessCommandL" );
       
   561 
       
   562     if ( MenuShowing() )
       
   563         {
       
   564         HideMenu();
       
   565         }
       
   566 
       
   567     switch ( aCommandId )
       
   568         {        
       
   569         // Connection Method Modification Commands
       
   570         case ECmManagerUiCmdCmAdd:
       
   571             {
       
   572             if ( !iProcessing )
       
   573                 {
       
   574                 iProcessing = ETrue;
       
   575                 TRAPD( err, AddConnectionMethodL() );
       
   576                 // Memory full
       
   577                 if (err == KLeaveWithoutAlert || err == KErrNoMemory)
       
   578                     {
       
   579                     iProcessing = EFalse;
       
   580                     return;
       
   581                     }
       
   582                 iProcessing = EFalse;
       
   583 
       
   584                 if ( iBackduringProcessing )
       
   585                     {
       
   586                     iBackduringProcessing = EFalse;
       
   587                     TryExitL( KDialogUserBack );
       
   588                     }
       
   589                 }
       
   590             break;
       
   591             }
       
   592 
       
   593         case ECmManagerUiCmdCmRename:            
       
   594             {
       
   595             RenameConnectionMethodL();
       
   596             break;
       
   597             }
       
   598             
       
   599         case EAknSoftkeyClear:
       
   600         case ECmManagerUiCmdCmDelete:            
       
   601             {
       
   602             if ( iPrioritising )
       
   603                 {
       
   604                 // Delete cannot be done if priorising has started.
       
   605                 break;
       
   606                 }
       
   607             DeleteCurrentCmL();         
       
   608             break;
       
   609             }
       
   610             
       
   611         case ECmManagerUiCmdCmPrioritise:            
       
   612             {
       
   613             PrioritiseConnectionMethodL();
       
   614             break;
       
   615             }
       
   616             
       
   617         case ECmManagerUiCmdCmCopyToOtherDestination:            
       
   618             {
       
   619             CopyConnectionMethodL();            
       
   620             break;
       
   621             }
       
   622             
       
   623         case ECmManagerUiCmdCmMoveToOtherDestination:            
       
   624             {            
       
   625             MoveConnectionMethodL();
       
   626             break;
       
   627             }
       
   628             
       
   629         case EAknSoftkeyOk:
       
   630         case ECmManagerUiCmdCmEdit:
       
   631             {
       
   632             EditConnectionMethodL();
       
   633             break;
       
   634             }   
       
   635 
       
   636         // Button Selection commands
       
   637         case EAknSoftkeyOptions:
       
   638             {
       
   639             DisplayMenuL();
       
   640             break;
       
   641             }
       
   642             
       
   643         case ECmManagerUiCmdCmUserExit:
       
   644             {
       
   645             if (!iProcessing)
       
   646                 {
       
   647                 *iSelected = 0;
       
   648                 iExitReason = KDialogUserExit;
       
   649                 TryExitL( iExitReason );
       
   650                 }
       
   651             break;
       
   652             }
       
   653             
       
   654         case EAknSoftkeyBack:
       
   655             {
       
   656             if (!iProcessing)
       
   657                 {
       
   658                 *iSelected = 0;
       
   659                 iExitReason = KDialogUserBack;
       
   660                 TryExitL( iExitReason );
       
   661                 }
       
   662             break;
       
   663             }
       
   664         case EAknCmdHelp:
       
   665             {
       
   666             HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   667                                     iEikonEnv->EikAppUi()->AppHelpContextL() );
       
   668             }
       
   669             break;
       
   670 
       
   671         default:
       
   672             {
       
   673             break;
       
   674             }
       
   675         }
       
   676     }
       
   677 
       
   678 // ---------------------------------------------------------------------------
       
   679 // CCmDlg::DeleteCurrentCmL
       
   680 // ---------------------------------------------------------------------------
       
   681 //
       
   682 void CCmDlg::DeleteCurrentCmL( )
       
   683     {
       
   684     LOGGER_ENTERFN( "CCmDlg::DeleteCurrentCmL" );
       
   685 
       
   686     TCmDefConnValue oldConn;
       
   687     if (iCmManager->IsDefConnSupported())
       
   688         {
       
   689         iCmManager->ReadDefConnL( oldConn );
       
   690         }
       
   691     CCmPluginBase* cm = CurrentCML();
       
   692     if ( !cm )
       
   693     	{
       
   694     	return;
       
   695     	}
       
   696 
       
   697     if ( cm->GetBoolAttributeL( ECmProtected ) )
       
   698         {
       
   699         TCmCommonUi::ShowNoteL( R_CMWIZARD_CANNOT_PERFORM_FOR_PROTECTED,
       
   700                                 TCmCommonUi::ECmErrorNote );
       
   701                                 
       
   702         return;
       
   703         }
       
   704    
       
   705     if ( cm->GetBoolAttributeL( ECmIsLinked ) )//same check as KErrLocked below
       
   706         {
       
   707         TCmCommonUi::ShowNoteL( 
       
   708                             R_QTN_NETW_CONSET_INFO_CANNOT_DELETE_VIRTUAL_REF,
       
   709                             TCmCommonUi::ECmErrorNote );
       
   710         
       
   711         return;
       
   712         }
       
   713    
       
   714     if ( cm->GetBoolAttributeL( ECmConnected ) )//same check as KErrInUse below
       
   715         {
       
   716         TCmCommonUi::ShowNoteL( R_CMMANAGERUI_INFO_CM_IN_USE_CANNOT_DELETE,
       
   717                                 TCmCommonUi::ECmErrorNote );
       
   718         
       
   719         return;
       
   720         }
       
   721 
       
   722     // EKOA-74KC3L: check if it is the last CM in a destination being referenced
       
   723     // by a VPN
       
   724     if ( iCmDestinationImpl &&
       
   725          iCmDestinationImpl->ConnectionMethodCount() == 1 )
       
   726         {
       
   727         // it is definitely the last, but is it referenced?
       
   728 
       
   729         // for each IAP in CM manager
       
   730         //   1. check if it is virtual
       
   731         //      if not => goto 1.
       
   732         //      if yes:
       
   733         //      2. check if it links to the destination of this CM
       
   734         //         if yes => carryOn = EFalse, ERROR
       
   735         //         if not: carryOn = ETrue
       
   736 
       
   737         CommsDat::CMDBRecordSet<CommsDat::CCDIAPRecord>* iaps = 
       
   738                                                     iCmManager->AllIapsL();
       
   739         
       
   740         CleanupStack::PushL( iaps );
       
   741         
       
   742         TBool carryOn = ETrue;
       
   743         TUint32 destId = iCmDestinationImpl->Id();
       
   744 
       
   745         // for each IAP in CM manager
       
   746         for ( TInt i = 0; carryOn && i < iaps->iRecords.Count(); ++i )
       
   747             {
       
   748             CommsDat::CCDIAPRecord* rec = (*iaps)[i];
       
   749             TUint32 bearerType = 0;
       
   750             
       
   751             TRAP_IGNORE( bearerType = 
       
   752                              iCmManager->BearerTypeFromIapRecordL( rec ) );
       
   753             if ( !bearerType )
       
   754                 {
       
   755                 continue;
       
   756                 }
       
   757                 
       
   758             // check if it is virtual
       
   759             if ( iCmManager->GetBearerInfoBoolL( bearerType, ECmVirtual ) )
       
   760                 {
       
   761                 // check if it links to the current destination
       
   762                 CCmPluginBase* plugin = NULL;            
       
   763                 TRAP_IGNORE( plugin = iCmManager->GetConnectionMethodL( 
       
   764                                                            rec->RecordId() ) );
       
   765 
       
   766                 if ( !plugin )
       
   767                     {
       
   768                     continue;
       
   769                     }
       
   770                 
       
   771                 if ( plugin->IsLinkedToSnap( destId ) )
       
   772                     {
       
   773                     // the CM links to this destination, deletion not allowed
       
   774                     carryOn = EFalse;
       
   775                     }
       
   776 
       
   777                 delete plugin;
       
   778                 }
       
   779                     
       
   780             }
       
   781             
       
   782         CleanupStack::PopAndDestroy( iaps );
       
   783         
       
   784         if ( !carryOn )
       
   785             {
       
   786             TCmCommonUi::ShowNoteL( R_QTN_NETW_CONSET_INFO_CANNOT_DELETE_VIRTUAL_REF,
       
   787                                 TCmCommonUi::ECmErrorNote );
       
   788             return;            
       
   789             }
       
   790         
       
   791         }
       
   792     
       
   793 
       
   794     // If it's an embedded destination, show a warning
       
   795     TBool showCmDeleteQuery( ETrue );
       
   796     if ( cm->GetBoolAttributeL( ECmDestination ) )
       
   797         {
       
   798         if ( TCmCommonUi::ShowConfirmationQueryL(
       
   799                             R_CMMANAGERUI_QUEST_EMBEDDED_DEST_DELETE ) )
       
   800             {
       
   801             // user wants to delete, set flag to avoid 2nd query message
       
   802             showCmDeleteQuery = EFalse;
       
   803             }
       
   804         else
       
   805             {
       
   806             return; // user cancelled delete request
       
   807             }
       
   808         }
       
   809 
       
   810     HBufC* cmName = cm->GetStringAttributeL( ECmName );
       
   811     CleanupStack::PushL( cmName );
       
   812     
       
   813     // Query for CM deletion - which will be skipped in the case of embedded 
       
   814     // destintations
       
   815     // Protected CM's cannot be deleted either
       
   816     if ( !showCmDeleteQuery || iAlreadyConfirmedDelete ||
       
   817          TCmCommonUi::ShowConfirmationQueryL( 
       
   818                                     R_CMMANAGERUI_QUEST_CM_DELETE,
       
   819                                     *cmName ) )
       
   820         {
       
   821         TInt err = KErrNone;
       
   822         if ( iCmDestinationImpl )
       
   823             {
       
   824             TRAP( err, iCmDestinationImpl->DeleteConnectionMethodL( *cm ) );
       
   825             }
       
   826         else
       
   827             {
       
   828             TRAP( err, (void)cm->DeleteL( ETrue ) );
       
   829             }
       
   830         
       
   831         switch ( err )
       
   832             {
       
   833             case KErrInUse: //shouldn't get here, already checked above
       
   834                 {
       
   835                 TCmCommonUi::ShowNoteL
       
   836                     ( R_CMMANAGERUI_INFO_CM_IN_USE_CANNOT_DELETE,
       
   837                     TCmCommonUi::ECmErrorNote );
       
   838                 }
       
   839                 break;
       
   840                 
       
   841             case KErrLocked://shouldn't get here, already checked above
       
   842                 {
       
   843                 TCmCommonUi::ShowNoteL
       
   844                     ( R_QTN_NETW_CONSET_INFO_CANNOT_DELETE_VIRTUAL_REF,
       
   845                       TCmCommonUi::ECmErrorNote );
       
   846                 }
       
   847                 break;
       
   848                 
       
   849             case KErrNone:
       
   850                 {
       
   851                 if ( iCmDestinationImpl )
       
   852                     {
       
   853                     iCmDestinationImpl->UpdateL();
       
   854                     }
       
   855                 if (iCmManager->IsDefConnSupported())
       
   856                     {
       
   857                     iDestDlg->ShowDefaultConnectionNoteL( oldConn );
       
   858                     }
       
   859                 HandleListboxDataChangeL();
       
   860                 iListbox->HandleItemRemovalL();
       
   861                 }
       
   862                 break;
       
   863 
       
   864             default:
       
   865                 {
       
   866                 }
       
   867                 break;
       
   868             }
       
   869         }
       
   870 
       
   871     CleanupStack::PopAndDestroy( cmName );
       
   872     }
       
   873 
       
   874 // --------------------------------------------------------------------------
       
   875 // CCmDlg::RenameConnectionMethodL    
       
   876 // --------------------------------------------------------------------------
       
   877 //
       
   878 void CCmDlg::RenameConnectionMethodL()
       
   879     {
       
   880     LOGGER_ENTERFN( "CCmDlg::RenameConnectionMethodL" );
       
   881 
       
   882     CCmPluginBase* cm = CurrentCML();
       
   883     if ( !cm )
       
   884         {
       
   885         return;
       
   886         }
       
   887 
       
   888     if ( cm->GetBoolAttributeL( ECmProtected ) )
       
   889         {
       
   890         TCmCommonUi::ShowNoteL( R_CMWIZARD_CANNOT_PERFORM_FOR_PROTECTED,
       
   891                                 TCmCommonUi::ECmErrorNote );
       
   892         return;
       
   893         }
       
   894 
       
   895     if ( CurrentCmInUseL() )
       
   896         {
       
   897         return;
       
   898         } 
       
   899            
       
   900     TBuf<KConnMethodNameMaxLength> buf;
       
   901     
       
   902     HBufC* cmName = cm->GetStringAttributeL(ECmName);
       
   903     CleanupStack::PushL(cmName);
       
   904     buf.Copy(*cmName);
       
   905     
       
   906     // Saves the recent naming method and set it to "Not accept"
       
   907     TUint32 savedNM = cm->GetIntAttributeL( ECmNamingMethod );
       
   908     cm->SetIntAttributeL( ECmNamingMethod, ENamingNotAccept );
       
   909 
       
   910     // Asks the new name
       
   911     TBool go = ETrue;
       
   912     TInt ret = TCmCommonUi::ShowConfirmationQueryWithInputL(
       
   913                                                 R_CMMANAGERUI_PRMPT_CM_MAME,
       
   914                                                 buf );
       
   915     
       
   916     // While the name is not unique or cancel pressed
       
   917     while( ret && go )
       
   918         {
       
   919         // Tries to save the nem name. If it is not unique
       
   920         // then ret == KErrArgument
       
   921         TRAPD( err, cm->SetStringAttributeL( ECmName, buf ) );
       
   922 
       
   923         if( KErrArgument == err )
       
   924             {
       
   925             // Opens a info note
       
   926             HBufC* noteLine = StringLoader::LoadLC(
       
   927                     R_CMMANAGERUI_INFO_CM_ALREADY_IN_USE, buf );
       
   928 
       
   929             TCmCommonUi::ShowNoteL( *noteLine, TCmCommonUi::ECmInfoNote );
       
   930 
       
   931             CleanupStack::PopAndDestroy( noteLine );
       
   932 
       
   933             // Asks the new name again
       
   934             ret = TCmCommonUi::ShowConfirmationQueryWithInputL(
       
   935                                                 R_CMMANAGERUI_PRMPT_CM_MAME,
       
   936                                                 buf );
       
   937             }
       
   938         else
       
   939             {
       
   940             // New name is unique loop can stop
       
   941             go = EFalse;
       
   942             }    
       
   943         }
       
   944 
       
   945     // Sets back the original naming method
       
   946     cm->SetIntAttributeL( ECmNamingMethod, savedNM );
       
   947 
       
   948     // If not cancel pressed the new name is set
       
   949     if( ret )
       
   950         {
       
   951         cm->UpdateL();
       
   952         
       
   953         HandleListboxDataChangeL();
       
   954         }
       
   955    
       
   956     CleanupStack::PopAndDestroy( cmName );
       
   957     }
       
   958 
       
   959 // --------------------------------------------------------------------------
       
   960 // CCmDlg::PrioritiseConnectionMethodL    
       
   961 // --------------------------------------------------------------------------
       
   962 //
       
   963 void CCmDlg::PrioritiseConnectionMethodL()
       
   964     {
       
   965     LOGGER_ENTERFN( "CCmDlg::PrioritiseConnectionMethodL" );
       
   966     
       
   967     ButtonGroupContainer().SetCommandSetL( R_SOFTKEYS_PRIO_OK_CANCEL__OK );
       
   968     iListbox->View()->SelectItemL( iListbox->CurrentItemIndex() );
       
   969     iListbox->View()->DrawItem( iListbox->CurrentItemIndex() );
       
   970     ButtonGroupContainer().DrawNow();
       
   971     iPrioritising = ETrue;
       
   972     iCmToPrioritise = iListbox->CurrentItemIndex();
       
   973     }
       
   974 
       
   975 // --------------------------------------------------------------------------
       
   976 // CCmDlg::AddConnectionMethodL    
       
   977 // --------------------------------------------------------------------------
       
   978 //
       
   979 void CCmDlg::AddConnectionMethodL()
       
   980     {
       
   981     LOGGER_ENTERFN( "CCmDlg::AddConnectionMethodL" );
       
   982 
       
   983     // Check first if parent destination is protected
       
   984     if ( iCmDestinationImpl && 
       
   985          iCmDestinationImpl->ProtectionLevel() == CMManager::EProtLevel1 )
       
   986         {
       
   987         TCmCommonUi::ShowNoteL( R_CMWIZARD_CANNOT_PERFORM_FOR_PROTECTED,
       
   988                                 TCmCommonUi::ECmErrorNote );
       
   989         return;
       
   990         }
       
   991 
       
   992     // Opens a Connection method creation wizard
       
   993     iCmWizard = new (ELeave) CCmWizard( *iCmManager );
       
   994 
       
   995     TInt itemstemp = iListbox->Model()->NumberOfItems();
       
   996 
       
   997     TInt ret( KErrNone );
       
   998     TRAPD( err, ret = iCmWizard->CreateConnectionMethodL( iCmDestinationImpl ) );
       
   999     if ( err )
       
  1000         {
       
  1001         TCmCommonUi::ShowNoteL( R_CMWIZARD_CANNOT_PERFORM_FOR_PROTECTED,
       
  1002                 TCmCommonUi::ECmErrorNote );
       
  1003         ret = KErrCancel;
       
  1004         }
       
  1005     delete iCmWizard;
       
  1006     iCmWizard = NULL;
       
  1007 
       
  1008 
       
  1009     // If application wanted to be closed before then RunAppShutter()
       
  1010     // should be called here                
       
  1011     if( iEscapeArrived )
       
  1012         {
       
  1013         ( ( CAknAppUi* )iEikonEnv->EikAppUi() )->RunAppShutter();
       
  1014         }
       
  1015     
       
  1016     if( ret != KErrCancel )
       
  1017         {
       
  1018         iHighlight = ret;
       
  1019 
       
  1020 
       
  1021         // Update the middle soft key if this is the first cm added
       
  1022         if ( CMCount() == 1 )
       
  1023             {
       
  1024             HBufC* text = StringLoader::LoadLC( R_QTN_MSK_EDIT );
       
  1025             ButtonGroupContainer().SetCommandL( ECmManagerUiCmdCmEdit, 
       
  1026                                                     *text );
       
  1027             CleanupStack::PopAndDestroy( text );
       
  1028             }
       
  1029         
       
  1030         //HandleListboxDataChangeL();
       
  1031         TRAP( err, HandleListboxDataChangeL() );
       
  1032         if ( err )
       
  1033             {
       
  1034             TCmCommonUi::ShowNoteL( R_CMWIZARD_CANNOT_PERFORM_FOR_PROTECTED,
       
  1035                     TCmCommonUi::ECmErrorNote );
       
  1036             return;
       
  1037             }
       
  1038         iListbox->HandleItemAdditionL();
       
  1039     
       
  1040         if (itemstemp < iListbox->Model()->NumberOfItems())
       
  1041             {
       
  1042             //first item cannot be deleted
       
  1043             iListbox->ScrollToMakeItemVisible( 
       
  1044                                     iListbox->Model()->NumberOfItems() -1 );
       
  1045             iListbox->SetCurrentItemIndex( iHighlight );
       
  1046             }
       
  1047         }
       
  1048     }
       
  1049 
       
  1050 // --------------------------------------------------------------------------
       
  1051 // CCmDlg::CopyConnectionMethodL    
       
  1052 // --------------------------------------------------------------------------
       
  1053 //
       
  1054 void CCmDlg::CopyConnectionMethodL()
       
  1055     {
       
  1056     LOGGER_ENTERFN( "CCmDlg::CopyConnectionMethodL" );
       
  1057 
       
  1058     CCmPluginBase* cm = CurrentCML();
       
  1059     if ( !cm )
       
  1060         {
       
  1061         return;
       
  1062         }
       
  1063     
       
  1064     if ( cm->GetBoolAttributeL( ECmProtected ) ||
       
  1065         ( iCmDestinationImpl && 
       
  1066          iCmDestinationImpl->ProtectionLevel() == CMManager::EProtLevel1 ) )
       
  1067         {
       
  1068         TCmCommonUi::ShowNoteL( R_CMWIZARD_CANNOT_PERFORM_FOR_PROTECTED,
       
  1069                                 TCmCommonUi::ECmErrorNote );
       
  1070         return;
       
  1071         }
       
  1072 
       
  1073     TUint32 destId( 0 );
       
  1074     
       
  1075     // build an array of possible parent destinations
       
  1076     TInt destCount=0;
       
  1077     TRAPD( retVal, destCount = iCmManager->DestinationCountL() );
       
  1078     if( retVal != KErrNone || destCount < 1 )
       
  1079         {
       
  1080         TCmCommonUi::ShowNoteL( R_CMWIZARD_NO_DESTINATION,
       
  1081                                 TCmCommonUi::ECmErrorNote );
       
  1082         return;
       
  1083         }
       
  1084         
       
  1085     RArray<TUint32> destArray( iCmManager->DestinationCountL() );
       
  1086     CleanupClosePushL( destArray );
       
  1087     
       
  1088     iCmManager->AllDestinationsL( destArray );
       
  1089     
       
  1090     // drop current destination (don't ask why)
       
  1091     if ( iCmDestinationImpl ) 
       
  1092         {
       
  1093         destId = iCmDestinationImpl->Id();
       
  1094         
       
  1095         TInt index = destArray.Find( destId );
       
  1096         if ( index != KErrNotFound )
       
  1097             {
       
  1098             destArray.Remove( index );
       
  1099             }
       
  1100         }
       
  1101     
       
  1102     
       
  1103     // now filter the destinations
       
  1104     CurrentCML()->FilterPossibleParentsL( destArray );
       
  1105 
       
  1106     // check if there are any remaining destinations
       
  1107     if ( !destArray.Count() )
       
  1108         {
       
  1109         TCmCommonUi::ShowNoteL( R_CMWIZARD_NO_VPN_STACKING,
       
  1110                                 TCmCommonUi::ECmErrorNote );        
       
  1111         CleanupStack::PopAndDestroy( &destArray );
       
  1112         return;
       
  1113         }
       
  1114 
       
  1115     // create a copy of the current connection method
       
  1116     CCmPluginBase* cmCopy = cm->CreateCopyL();
       
  1117     CleanupStack::PushL( cmCopy );
       
  1118 
       
  1119     // ok, there is at least 1, pop up the dialog
       
  1120     CSelectDestinationDlg* dlg = CSelectDestinationDlg::NewL( destId, 
       
  1121                                                               *iCmManager, 
       
  1122                                                               &destArray );
       
  1123 
       
  1124     if ( dlg->ExecuteLD( R_CMMANAGER_LIST_QUERY_WITH_MSGBOX ) )
       
  1125         {
       
  1126         CCmDestinationImpl* dest = iCmManager->DestinationL( destId );
       
  1127         CleanupStack::PushL( dest ); 
       
  1128         if ( iCmDestinationImpl )
       
  1129             {
       
  1130             // store it in commsdat
       
  1131             cmCopy->UpdateL();
       
  1132             dest->AddConnectionMethodL( *cmCopy );
       
  1133             }
       
  1134         else
       
  1135             {
       
  1136             iCmManager->CopyConnectionMethodL( *dest, *( cm ) );
       
  1137             }
       
  1138 
       
  1139         // Rare but UpdateL can leave that cause crash
       
  1140         TRAPD( err, dest->UpdateL() );
       
  1141         if( err < 0 )
       
  1142             {
       
  1143             CLOG_WRITE_1( "CCmDlg::CopyConnectionMethodL UpdateL: %d", err );
       
  1144             }
       
  1145     
       
  1146         CleanupStack::PopAndDestroy( dest );
       
  1147         HandleListboxDataChangeL();                             
       
  1148         }
       
  1149     CleanupStack::PopAndDestroy( cmCopy );
       
  1150     CleanupStack::PopAndDestroy( &destArray );
       
  1151     }
       
  1152 
       
  1153 // --------------------------------------------------------------------------
       
  1154 // CCmDlg::MoveConnectionMethodL
       
  1155 // --------------------------------------------------------------------------
       
  1156 //
       
  1157 void CCmDlg::MoveConnectionMethodL()
       
  1158     {
       
  1159     LOGGER_ENTERFN( "CCmDlg::MoveConnectionMethodL" );
       
  1160 
       
  1161     CCmPluginBase* cm = CurrentCML();
       
  1162     if ( !cm )
       
  1163         {
       
  1164         return;
       
  1165         }
       
  1166 
       
  1167     if ( cm->GetBoolAttributeL( ECmProtected ) ||
       
  1168          iCmDestinationImpl->ProtectionLevel() == CMManager::EProtLevel1 )
       
  1169         {
       
  1170         TCmCommonUi::ShowNoteL( R_CMWIZARD_CANNOT_PERFORM_FOR_PROTECTED,
       
  1171                                 TCmCommonUi::ECmErrorNote );
       
  1172         return;
       
  1173         }
       
  1174 
       
  1175     if ( CurrentCmInUseL() )
       
  1176         {
       
  1177         return;
       
  1178         }
       
  1179 
       
  1180     // build an array of possible parent destinations
       
  1181     RArray<TUint32> destArray( iCmManager->DestinationCountL() );
       
  1182     CleanupClosePushL( destArray );
       
  1183     
       
  1184     iCmManager->AllDestinationsL( destArray );
       
  1185     
       
  1186     TUint32 destId( 0 );
       
  1187 
       
  1188     // first remove the current parent (makes no sense moving a CM to its
       
  1189     // original destination)
       
  1190     if ( iCmDestinationImpl ) 
       
  1191         {
       
  1192         destId = iCmDestinationImpl->Id();
       
  1193         
       
  1194         TInt index = destArray.Find( destId );
       
  1195         if ( index != KErrNotFound )
       
  1196             {
       
  1197             destArray.Remove( index );
       
  1198             }
       
  1199         }
       
  1200     
       
  1201     // now filter the destinations
       
  1202     CurrentCML()->FilterPossibleParentsL( destArray );
       
  1203 
       
  1204     // check if there are any remaining destinations
       
  1205     if ( !destArray.Count() )
       
  1206         {
       
  1207         TCmCommonUi::ShowNoteL( R_CMWIZARD_NO_VPN_STACKING,
       
  1208                                 TCmCommonUi::ECmErrorNote );        
       
  1209         CleanupStack::PopAndDestroy( &destArray );
       
  1210         return;
       
  1211         }
       
  1212 
       
  1213         
       
  1214     CSelectDestinationDlg* dlg = CSelectDestinationDlg::NewL( destId, 
       
  1215                                                               *iCmManager, 
       
  1216                                                               &destArray );
       
  1217                     
       
  1218     if ( dlg->ExecuteLD( R_CMMANAGER_LIST_QUERY_WITH_MSGBOX ) )
       
  1219         {
       
  1220         CCmDestinationImpl* dest = iCmManager->DestinationL( destId );
       
  1221         CleanupStack::PushL( dest );
       
  1222         iCmManager->MoveConnectionMethodL( *iCmDestinationImpl,
       
  1223                                             *dest,
       
  1224                                             *( CurrentCML() ) );
       
  1225         CleanupStack::PopAndDestroy( dest );
       
  1226         iCmDestinationImpl->UpdateL();                            
       
  1227 
       
  1228         HandleListboxDataChangeL();
       
  1229         iListbox->HandleItemRemovalL();
       
  1230         }
       
  1231 
       
  1232     CleanupStack::PopAndDestroy( &destArray );
       
  1233     }
       
  1234 
       
  1235 // --------------------------------------------------------------------------
       
  1236 // CCmDlg::EditConnectionMethodL
       
  1237 // --------------------------------------------------------------------------
       
  1238 //
       
  1239 void CCmDlg::EditConnectionMethodL()
       
  1240     {
       
  1241     LOGGER_ENTERFN( "CCmDlg::EditConnectionMethodL" );
       
  1242 
       
  1243     CCmPluginBase* cm = NULL;
       
  1244     
       
  1245     TRAPD( err, cm = CurrentCML() );
       
  1246     
       
  1247     if( err == KErrNotSupported )
       
  1248         {
       
  1249         return;
       
  1250         }
       
  1251     else
       
  1252         {
       
  1253         User::LeaveIfError( err );
       
  1254         }
       
  1255 
       
  1256     if ( !cm )
       
  1257         {
       
  1258         return;
       
  1259         }
       
  1260 
       
  1261     // Must reload here in case another app changed the data (CurrentCML loads
       
  1262     // only if not already loaded)   
       
  1263     cm->ReLoadL();
       
  1264     
       
  1265     if ( cm->GetBoolAttributeL( ECmProtected ) ||
       
  1266          cm->GetBoolAttributeL( ECmDestination ) )
       
  1267         {
       
  1268         TCmCommonUi::ShowNoteL( R_CMWIZARD_CANNOT_PERFORM_FOR_PROTECTED,
       
  1269                                 TCmCommonUi::ECmErrorNote );        
       
  1270         }
       
  1271     else if ( cm->GetBoolAttributeL( ECmBearerHasUi ) )
       
  1272         {
       
  1273         // check if the cm is in use
       
  1274         if ( !CurrentCmInUseL() )
       
  1275             {
       
  1276             TInt ret = cm->RunSettingsL();
       
  1277             if ( ret == KDialogUserExit )
       
  1278                 {
       
  1279                 if( IsExceptionExitL() )
       
  1280                     {
       
  1281                     iPluginExitExceptionally = ETrue;
       
  1282                     TryExitL( KDialogUserBack );
       
  1283                     }
       
  1284                 else
       
  1285                     {
       
  1286                     TryExitL( KDialogUserExit );
       
  1287                     }
       
  1288                 }
       
  1289             else
       
  1290                 {
       
  1291                 if ( ret == KDialogUserDeleteConfirmed )
       
  1292                     {
       
  1293                     iAlreadyConfirmedDelete = ETrue;
       
  1294                     DeleteCurrentCmL();
       
  1295                     iAlreadyConfirmedDelete = EFalse;
       
  1296                     }
       
  1297                 if ( ret == KDialogUserDelete )
       
  1298                     {
       
  1299                     DeleteCurrentCmL();
       
  1300                     }
       
  1301                 
       
  1302                 // Reorder according to priorities, if needed
       
  1303                 ReOrderCMsL();
       
  1304                 
       
  1305                 HandleListboxDataChangeL();
       
  1306                 }
       
  1307             }
       
  1308         }
       
  1309     }
       
  1310     
       
  1311 // ---------------------------------------------------------------------------
       
  1312 // CCmDlg::OfferKeyEventL
       
  1313 // ---------------------------------------------------------------------------
       
  1314 //
       
  1315 TKeyResponse CCmDlg::OfferKeyEventL( const TKeyEvent& aKeyEvent, 
       
  1316                                      TEventCode aType )    
       
  1317     {
       
  1318     LOGGER_ENTERFN( "CCmDlg::OfferKeyEventL" );
       
  1319     CLOG_WRITE_1("Key iCode: %d", aKeyEvent.iCode );
       
  1320 
       
  1321     TKeyResponse retVal ( EKeyWasNotConsumed );
       
  1322 
       
  1323     if ( aKeyEvent.iCode == EKeyBackspace )
       
  1324         {
       
  1325         // While priorising delete item is disabled
       
  1326         if( !iPrioritising )
       
  1327             {
       
  1328             ProcessCommandL( ECmManagerUiCmdCmDelete );
       
  1329             }
       
  1330         retVal = EKeyWasConsumed;
       
  1331         }
       
  1332     else if ( aKeyEvent.iCode == EKeyEscape )
       
  1333         {
       
  1334         // Handling application close needs special care 
       
  1335         // because of iCmWizard 
       
  1336         if ( iCmWizard )
       
  1337             {
       
  1338             // if wizard alives then escape should do after wizard has ended.
       
  1339             CLOG_WRITE( "CCmDlg::OfferKeyEventL: Wizard in long process" );
       
  1340             iEscapeArrived = ETrue;
       
  1341             retVal = EKeyWasConsumed;
       
  1342             }
       
  1343         else    
       
  1344             {
       
  1345             CLOG_WRITE( "CCmDlg::OfferKeyEventL:Escape" );
       
  1346             retVal = CAknDialog::OfferKeyEventL( aKeyEvent, aType );
       
  1347             }
       
  1348         }
       
  1349     else
       
  1350         {
       
  1351         retVal = iListbox->OfferKeyEventL(aKeyEvent, aType);       
       
  1352         }
       
  1353 
       
  1354     return retVal;
       
  1355     }
       
  1356 // ---------------------------------------------------------------------------
       
  1357 // CCmDlg::HandleInfoPopupNoteEvent
       
  1358 // called before the dialog is shown to initialize listbox data
       
  1359 // ---------------------------------------------------------------------------
       
  1360 //    
       
  1361 void CCmDlg::HandleInfoPopupNoteEvent(
       
  1362                                 CAknInfoPopupNoteController* /*aController*/,
       
  1363                                 TAknInfoPopupNoteEvent /*aEvent*/ )
       
  1364     {
       
  1365     }
       
  1366 
       
  1367 // ---------------------------------------------------------------------------
       
  1368 // CCmDlg::CurrentCML
       
  1369 // Currently selected connection method in the list
       
  1370 // ---------------------------------------------------------------------------
       
  1371 //
       
  1372 CCmPluginBase* CCmDlg::CurrentCML()
       
  1373     {
       
  1374     if ( iItemIndex.Count() == 0 )
       
  1375     	{
       
  1376     	return NULL;
       
  1377     	}
       
  1378     return iCmDestinationImpl->GetConnectionMethodL( 
       
  1379         iItemIndex[iListbox->CurrentItemIndex()]);
       
  1380     }
       
  1381 
       
  1382 // ---------------------------------------------------------------------------
       
  1383 // CCmDlg::CMByIndexL
       
  1384 // a connection method in the list
       
  1385 // ---------------------------------------------------------------------------
       
  1386 //
       
  1387 CCmPluginBase* CCmDlg::CMByIndexL( TInt aIndex )
       
  1388     {
       
  1389     return iCmDestinationImpl->GetConnectionMethodL( aIndex );
       
  1390     }
       
  1391 
       
  1392 // ---------------------------------------------------------------------------
       
  1393 // CCmDlg::CMCount
       
  1394 // number of cms in the list
       
  1395 // ---------------------------------------------------------------------------
       
  1396 //
       
  1397 TInt CCmDlg::CMCount()
       
  1398     {
       
  1399     return iCmDestinationImpl->ConnectionMethodCount();
       
  1400     }
       
  1401     
       
  1402 // ---------------------------------------------------------------------------
       
  1403 // CCmDlg::HandleListboxDataChangeL
       
  1404 // called before the dialog is shown to initialize listbox data
       
  1405 // ---------------------------------------------------------------------------
       
  1406 //
       
  1407 void CCmDlg::HandleListboxDataChangeL()
       
  1408     {
       
  1409     TInt selected = 0;
       
  1410     if ( iListbox->CurrentItemIndex() )
       
  1411         {
       
  1412         selected = iListbox->CurrentItemIndex();
       
  1413         }
       
  1414     
       
  1415     LOGGER_ENTERFN( "CCmDlg::HandleListboxDataChangeL" );
       
  1416     iCmManager->OpenTransactionLC();
       
  1417 
       
  1418     RArray<TUint32> cmIds;
       
  1419     ConstructCMArrayL( cmIds );
       
  1420     CleanupClosePushL( cmIds );
       
  1421     
       
  1422     // Remove hidden Connection Methods from the array if uncat folder
       
  1423     if ( !iCmDestinationImpl )
       
  1424         {
       
  1425         ClearHiddenCMsFromArrayL( cmIds );
       
  1426         }
       
  1427     
       
  1428     /// Using test values for now.
       
  1429     CArrayPtr< CGulIcon >* icons = new( ELeave ) CAknIconArray( KCMGranularity );
       
  1430     CleanupStack::PushL( icons );
       
  1431     iModel->ResetAndDestroy();
       
  1432     
       
  1433     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();        
       
  1434     TParse mbmFile;
       
  1435     User::LeaveIfError( mbmFile.Set( KManagerIconFilename, 
       
  1436                                      &KDC_APP_BITMAP_DIR, 
       
  1437                                      NULL ) );        
       
  1438 
       
  1439     
       
  1440     icons->AppendL( AknsUtils::CreateGulIconL( 
       
  1441                               skinInstance, 
       
  1442                               KAknsIIDQgnIndiSettProtectedAdd,
       
  1443                               mbmFile.FullName(), 
       
  1444                               EMbmCmmanagerQgn_indi_sett_protected_add, 
       
  1445                               EMbmCmmanagerQgn_indi_sett_protected_add_mask ) );  
       
  1446 
       
  1447     //0..1 are reserved indexes!
       
  1448     CFbsBitmap* bitmap = NULL;
       
  1449     CFbsBitmap* mask = NULL;
       
  1450 
       
  1451     AknsUtils::CreateColorIconLC( skinInstance,
       
  1452                                   KAknsIIDQgnIndiDefaultConnAdd,
       
  1453                                   KAknsIIDQsnIconColors,
       
  1454                                   EAknsCIQsnIconColorsCG13,
       
  1455                                   bitmap,
       
  1456                                   mask,
       
  1457                                   mbmFile.FullName(),
       
  1458                                   EMbmCmmanagerQgn_indi_default_conn_add,
       
  1459                                   EMbmCmmanagerQgn_indi_default_conn_add_mask,
       
  1460                                   AKN_LAF_COLOR( 215 ) );
       
  1461 
       
  1462     CGulIcon* icon = CGulIcon::NewL( bitmap, mask ); // Ownership transferred
       
  1463     CleanupStack::Pop( 2 ); // bitmap, mask
       
  1464 
       
  1465     CleanupStack::PushL( icon );
       
  1466     icons->AppendL( icon );
       
  1467     CleanupStack::Pop( icon );
       
  1468 
       
  1469     RArray<TUint> bearerIdArray = RArray<TUint>( KCmArrayBigGranularity );
       
  1470     CleanupClosePushL( bearerIdArray );    
       
  1471     
       
  1472     TCmDefConnValue sel;
       
  1473     TInt defUid = KErrNotFound;
       
  1474     if ( iCmManager->IsDefConnSupported() )
       
  1475         {
       
  1476         iCmManager->ReadDefConnL(sel);
       
  1477         if ( sel.iType == EDCConnectionMethod )
       
  1478             {
       
  1479             defUid = sel.iId;
       
  1480             }
       
  1481         }
       
  1482     iItemIndex.Reset();
       
  1483     for ( TInt i = 0; i < cmIds.Count(); i++ )
       
  1484         {
       
  1485         TInt iconId = KErrNotFound;
       
  1486         CCDAccessPointRecord* destAPRecord = NULL;
       
  1487         CCDIAPRecord* iapRecord = NULL;
       
  1488         HBufC* name = NULL;
       
  1489         TBool isDest( cmIds[i] > KCmDefaultDestinationAPTagId );
       
  1490         TUint recId( 0 );
       
  1491         TBool protect;
       
  1492         TUint32 bearerType( 0 );
       
  1493         
       
  1494         if( isDest )
       
  1495             {
       
  1496             destAPRecord = static_cast<CCDAccessPointRecord *>(
       
  1497                            CCDRecordBase::RecordFactoryL( KCDTIdAccessPointRecord ) );
       
  1498             CleanupStack::PushL( destAPRecord );
       
  1499             destAPRecord->iRecordTag = cmIds[i];
       
  1500             if ( !destAPRecord->FindL( iCmManager->Session() ) )
       
  1501                 {
       
  1502                 User::Leave( KErrNotFound );
       
  1503                 }
       
  1504             
       
  1505             name = TPtrC( destAPRecord->iRecordName ).AllocLC();
       
  1506 
       
  1507             TProtectionLevel protLev = CCmDestinationImpl::ProtectionLevelL( *iCmManager, cmIds[i] );
       
  1508             
       
  1509             protect = (protLev == EProtLevel1) || (protLev == EProtLevel2);
       
  1510 
       
  1511             HBufC* destName = StringLoader::LoadL( R_QTN_NETW_CONSET_EMBEDDED_DEST,
       
  1512                                                    *name );
       
  1513                                                    
       
  1514             CleanupStack::PopAndDestroy( name );            
       
  1515             name = destName;            
       
  1516             CleanupStack::PushL( name );
       
  1517             
       
  1518             bearerType = KUidEmbeddedDestination;
       
  1519             }
       
  1520         else
       
  1521             {
       
  1522             recId = cmIds[i];
       
  1523             iapRecord = static_cast<CCDIAPRecord *>
       
  1524                           (CCDRecordBase::RecordFactoryL(KCDTIdIAPRecord));
       
  1525             CleanupStack::PushL( iapRecord );
       
  1526             
       
  1527             iapRecord->SetRecordId( recId );
       
  1528             iapRecord->LoadL( iCmManager->Session() );
       
  1529             
       
  1530             TRAPD( err, bearerType = iCmManager->BearerTypeFromIapRecordL( iapRecord ) );
       
  1531             
       
  1532             if( err == KErrNotSupported )
       
  1533                 // This is unsupported connection method -> don't add it to the list
       
  1534                 {
       
  1535                 CleanupStack::PopAndDestroy( iapRecord );
       
  1536                 continue;
       
  1537                 }
       
  1538             else
       
  1539                 {
       
  1540                 User::LeaveIfError( err );
       
  1541                 }
       
  1542             name = TPtrC( iapRecord->iRecordName ).AllocLC();
       
  1543             protect = iapRecord->Attributes() & ECDProtectedWrite;
       
  1544 
       
  1545             if ( bearerIdArray.Count() )
       
  1546                 {
       
  1547                 for ( TInt j = 0; j<bearerIdArray.Count(); j++ )
       
  1548                     {
       
  1549                     if ( bearerType == bearerIdArray[j] )
       
  1550                         {
       
  1551                         iconId = j+KCmReservedIconIndexCount;
       
  1552                         }
       
  1553                     }
       
  1554                 }
       
  1555             }
       
  1556 
       
  1557         if ( iconId == KErrNotFound )
       
  1558             {
       
  1559             TInt iconInt( 0 );
       
  1560             if( isDest )
       
  1561                 // Embedded destinations has not constant icon.
       
  1562                 {
       
  1563                 iconInt = (TInt)CCmDestinationImpl::IconIdL( *iCmManager,
       
  1564                                                              cmIds[i] );
       
  1565                 }
       
  1566             else
       
  1567                 {
       
  1568                 iconInt = iCmManager->GetBearerInfoIntL( bearerType, 
       
  1569                                                          ECmBearerIcon );
       
  1570                 }
       
  1571 
       
  1572             if (iconInt) 
       
  1573                 {
       
  1574                 if ( isDest )
       
  1575                     {
       
  1576                     // append zero - assuming that bearer type values differ from zero
       
  1577                     bearerIdArray.Append( 0 ); 
       
  1578                     }
       
  1579                 else
       
  1580                     {
       
  1581                     bearerIdArray.Append( bearerType );
       
  1582                     }
       
  1583 
       
  1584                 icons->AppendL( (CGulIcon*)iconInt );
       
  1585                 iconId = bearerIdArray.Count()-1+KCmReservedIconIndexCount;
       
  1586                 }
       
  1587             else 
       
  1588                 {
       
  1589                 iconId = KCmReservedIconIndexCount;
       
  1590                 }
       
  1591             }
       
  1592         TBool def = EFalse;
       
  1593         if ( defUid == recId ) 
       
  1594             {
       
  1595             def = ETrue;
       
  1596             }
       
  1597         
       
  1598         TInt nextLayerSnapId = 0;
       
  1599         if( !isDest ) 
       
  1600             {
       
  1601             // Check if it is VPN over destination    
       
  1602             // If yes the list item should have single line 
       
  1603             CCmPluginBase* plugin = iCmManager->GetConnectionMethodL( cmIds[i] );
       
  1604             CleanupStack::PushL( plugin );
       
  1605                    
       
  1606             if( plugin->GetBoolAttributeL( ECmVirtual ) )
       
  1607                 {
       
  1608                 nextLayerSnapId = plugin->GetIntAttributeL( ECmNextLayerSNAPId );
       
  1609                 }
       
  1610                 
       
  1611             CleanupStack::PopAndDestroy( plugin );
       
  1612             }
       
  1613 
       
  1614         CCmListItem* item = 
       
  1615                 CCmListItem::NewLC( 
       
  1616                             recId, 
       
  1617                             name,
       
  1618                             i, 
       
  1619                             iconId,
       
  1620                             protect,
       
  1621                             (nextLayerSnapId ? ETrue : EFalse),
       
  1622                             // reasons for single line
       
  1623                             ( isDest || !iCmDestinationImpl), 
       
  1624                             def );
       
  1625         CleanupStack::Pop( item );
       
  1626         CleanupStack::Pop( name );
       
  1627         CleanupStack::PopAndDestroy(); // iapRecord or nwRecord
       
  1628         CleanupStack::PushL( item );
       
  1629         iModel->AppendL( item );
       
  1630         CleanupStack::Pop( item );
       
  1631         iItemIndex.Append(i);
       
  1632         }
       
  1633     
       
  1634     TInt cmCount = iItemIndex.Count();
       
  1635     SetNoOfCMsL( cmCount );
       
  1636     
       
  1637     if ( !cmCount && iCmDestinationImpl )
       
  1638         {
       
  1639         HBufC* buf = 0;
       
  1640         // rare case probably only caused by bad configuration
       
  1641         if ( iCmDestinationImpl->ProtectionLevel() == EProtLevel1 )
       
  1642             {
       
  1643             buf = StringLoader::LoadLC( R_TEXT_SOFTKEY_OPTION );
       
  1644             }
       
  1645         else
       
  1646             {    
       
  1647             buf = StringLoader::LoadLC( R_CMMANAGERUI_MSK_ADD_METHOD );
       
  1648             }
       
  1649         ButtonGroupContainer().SetCommandL( ECmManagerUiCmdCmEdit, *buf );
       
  1650         ButtonGroupContainer().DrawDeferred();                                                    
       
  1651         CleanupStack::PopAndDestroy( buf );
       
  1652         }
       
  1653 
       
  1654     CleanupStack::PopAndDestroy( &bearerIdArray );
       
  1655     
       
  1656     CArrayPtr<CGulIcon>* oldIcons = 
       
  1657                             iListbox->ItemDrawer()->ColumnData()->IconArray();
       
  1658     if ( oldIcons )
       
  1659         {
       
  1660         oldIcons->ResetAndDestroy();
       
  1661         delete oldIcons;
       
  1662         }
       
  1663     
       
  1664     iListbox->ItemDrawer()->ColumnData()->SetIconArray( icons );
       
  1665 
       
  1666     CleanupStack::Pop( icons );
       
  1667     CleanupStack::PopAndDestroy( &cmIds ); 
       
  1668     
       
  1669     iCmManager->CommitTransactionL( KErrNone );
       
  1670 
       
  1671     // Fix for the added IAP not showing in the list.
       
  1672     iListbox->HandleItemAdditionL();
       
  1673 
       
  1674     iListbox->DrawNow();
       
  1675     iListbox->UpdateScrollBarsL();
       
  1676     
       
  1677     TInt count = iListbox->Model()->NumberOfItems();
       
  1678     if ( count )
       
  1679         {
       
  1680         if ( count <= selected )
       
  1681             {
       
  1682             selected = count - 1; // index, so --
       
  1683             }
       
  1684         if ( selected >= 0 )
       
  1685             {
       
  1686             iListbox->ScrollToMakeItemVisible( selected);
       
  1687             iListbox->SetCurrentItemIndex( selected );
       
  1688             }
       
  1689         }
       
  1690     }
       
  1691     
       
  1692 
       
  1693 // --------------------------------------------------------------------------
       
  1694 // CCmDlg::CurrentCmInUseL
       
  1695 // --------------------------------------------------------------------------
       
  1696 //
       
  1697 TBool CCmDlg::CurrentCmInUseL()
       
  1698     {
       
  1699     TBool retVal = CurrentCML()->GetBoolAttributeL( ECmConnected );
       
  1700     if ( retVal )
       
  1701         {
       
  1702         TCmCommonUi::ShowNoteL( R_QTN_SET_NOTE_AP_IN_USE_EDIT,
       
  1703                                 TCmCommonUi::ECmErrorNote );
       
  1704         retVal = ETrue;
       
  1705         }
       
  1706     return retVal;
       
  1707     }
       
  1708 
       
  1709 // --------------------------------------------------------------------------
       
  1710 // CCmDlg::ConstructCMArrayL
       
  1711 // --------------------------------------------------------------------------
       
  1712 //
       
  1713 void CCmDlg::ConstructCMArrayL( RArray<TUint32>& aCmIds )
       
  1714     {
       
  1715     iCmDestinationImpl->ReLoadConnectionMethodsL();
       
  1716     iCmDestinationImpl->ConnectMethodIdArrayL( aCmIds );
       
  1717     }
       
  1718 
       
  1719 // --------------------------------------------------------------------------
       
  1720 // CCmDlg::ClearHiddenCMsFromArrayL
       
  1721 // --------------------------------------------------------------------------
       
  1722 //
       
  1723 void CCmDlg::ClearHiddenCMsFromArrayL( RArray<TUint32>& aCmIds )
       
  1724     {
       
  1725     TBool hidden( EFalse );
       
  1726     TInt err( KErrNone );
       
  1727     for ( TInt index = 0; index < aCmIds.Count(); index++ )
       
  1728         {
       
  1729         TUint recId = aCmIds[index];
       
  1730         TRAP( err, hidden = iCmManager->GetConnectionMethodInfoBoolL( recId, ECmHidden ) );
       
  1731         if ( err || hidden )
       
  1732             {
       
  1733             aCmIds.Remove( index );
       
  1734             index--;
       
  1735             }
       
  1736         }
       
  1737     }
       
  1738 
       
  1739 // --------------------------------------------------------------------------
       
  1740 // CCmDlg::GetHelpContext
       
  1741 // --------------------------------------------------------------------------
       
  1742 //
       
  1743 void CCmDlg::GetHelpContext( TCoeHelpContext& aContext ) const
       
  1744     {
       
  1745     aContext.iMajor = KHelpUidPlugin;
       
  1746     aContext.iContext = KSET_HLP_CONN_METHODS_VIEW;
       
  1747     }
       
  1748     
       
  1749 // --------------------------------------------------------------------------
       
  1750 // CCmDlg::FinishPriorizingL
       
  1751 // --------------------------------------------------------------------------
       
  1752 //
       
  1753 void CCmDlg::FinishPriorizingL( TBool aOkPushed )
       
  1754     {
       
  1755     LOGGER_ENTERFN( "CCmDlg::FinishPriorizing" );
       
  1756 
       
  1757     iListbox->ClearSelection();
       
  1758     iPrioritising = EFalse;
       
  1759     
       
  1760     if( aOkPushed )
       
  1761         {
       
  1762         if ( CurrentCML()->GetBoolAttributeL( ECmDestination ) ||
       
  1763              (CurrentCML()->GetBoolAttributeL( ECmVirtual ) &&
       
  1764               CurrentCML()->GetIntAttributeL( ECmNextLayerSNAPId )) )
       
  1765             {
       
  1766             // Priorising not possible
       
  1767             TCmCommonUi::ShowNoteL( R_CMMANAGERUI_INFO_PRIO_NOT_POSSIBLE,
       
  1768                                     TCmCommonUi::ECmInfoNote );
       
  1769             }
       
  1770         else
       
  1771             {
       
  1772             CCmPluginBase* cm = CMByIndexL(iCmToPrioritise);
       
  1773             iCmDestinationImpl->ModifyPriorityL( 
       
  1774                                 *cm, 
       
  1775                                 iListbox->CurrentItemIndex());
       
  1776             iCmDestinationImpl->UpdateL();
       
  1777             HandleListboxDataChangeL();
       
  1778             }
       
  1779         }
       
  1780      // Set the softkeys back    
       
  1781      ButtonGroupContainer().SetCommandSetL(
       
  1782                                     R_SOFTKEYS_OPTIONS_BACK__EDIT );
       
  1783      ButtonGroupContainer().DrawDeferred();
       
  1784      }
       
  1785 
       
  1786 
       
  1787 // --------------------------------------------------------------------------
       
  1788 // CCmDlg::Execute
       
  1789 // --------------------------------------------------------------------------
       
  1790 //
       
  1791 void CCmDlg::Execute()
       
  1792     {
       
  1793     LOGGER_ENTERFN( "CCmDlg::Execute" );
       
  1794 
       
  1795     iInfoPopupNoteController->HideInfoPopupNote();
       
  1796     
       
  1797     if(iPrioritising)
       
  1798     	{
       
  1799     	TRAPD( err, FinishPriorizingL( ETrue ) );
       
  1800     	if ( err )
       
  1801     	    {
       
  1802     	    HandleLeaveError( err );
       
  1803     	    }
       
  1804     	}
       
  1805     else
       
  1806     	{
       
  1807         iProcessing = ETrue;
       
  1808         
       
  1809         TRAPD( err, ProcessCommandL(ECmManagerUiCmdCmEdit) );
       
  1810     	if ( err )
       
  1811     	    {
       
  1812     	    HandleLeaveError( err );
       
  1813     	    }
       
  1814 
       
  1815         iProcessing = EFalse;
       
  1816     	}
       
  1817     }
       
  1818 
       
  1819 // --------------------------------------------------------------------------
       
  1820 // CCmDlg::HandleLeaveError
       
  1821 // --------------------------------------------------------------------------
       
  1822 //
       
  1823 void CCmDlg::HandleLeaveError( TInt /*aError*/ )
       
  1824     {
       
  1825     if(iProcessing)
       
  1826         {
       
  1827         iProcessing = EFalse;
       
  1828         }
       
  1829     }
       
  1830 
       
  1831 // --------------------------------------------------------------------------
       
  1832 // CCmDlg::HandleResourceChange
       
  1833 // --------------------------------------------------------------------------
       
  1834 //
       
  1835 void CCmDlg::HandleResourceChange( TInt aType )
       
  1836     {
       
  1837     CCoeControl::HandleResourceChange( aType ); 
       
  1838 
       
  1839     if( aType == KEikDynamicLayoutVariantSwitch )
       
  1840         {
       
  1841         DrawNow(); 
       
  1842         }
       
  1843         
       
  1844     CAknDialog::HandleResourceChange(aType);        
       
  1845     }
       
  1846 
       
  1847 // --------------------------------------------------------------------------
       
  1848 // CCmDlg::GetInsertIndexL
       
  1849 // --------------------------------------------------------------------------
       
  1850 //
       
  1851 TInt CCmDlg::GetInsertIndexL( TInt aCount, TUint32 aPriority )
       
  1852     {
       
  1853     TInt ret = aCount;
       
  1854     TUint32 priority;
       
  1855     
       
  1856     
       
  1857     for ( TInt index = 0; index < aCount; index++ )
       
  1858         {
       
  1859         CCmPluginBase* cm = iCmDestinationImpl->GetConnectionMethodL( iItemIndex[index] );
       
  1860         
       
  1861         if ( cm->GetBoolAttributeL( ECmVirtual ) &&
       
  1862              !cm->GetIntAttributeL( ECmNextLayerSNAPId ) )
       
  1863              {
       
  1864              TUint32 underlying = cm->GetIntAttributeL( ECmNextLayerIapId );
       
  1865              if ( underlying != 0 )
       
  1866                 {
       
  1867                 // Find the index that this VPN Iap should be inserted
       
  1868                 TUint32 underlyingBearer = iCmManager->BearerTypeFromCmIdL( underlying );
       
  1869                 priority = iCmManager->GetBearerInfoIntL( underlyingBearer, ECmDefaultPriority );
       
  1870                 }
       
  1871              else
       
  1872                 {
       
  1873                 priority = KDataMobilitySelectionPolicyPriorityWildCard;
       
  1874                 }
       
  1875              }
       
  1876         else
       
  1877             {
       
  1878             priority = cm->Plugin()->GetIntAttributeL( ECmDefaultPriority );
       
  1879             }
       
  1880         
       
  1881         if (priority > aPriority)
       
  1882             {
       
  1883             ret = index;
       
  1884             break;
       
  1885             }
       
  1886         }
       
  1887     
       
  1888     return ret;
       
  1889     }
       
  1890 
       
  1891 // --------------------------------------------------------------------------
       
  1892 // CCmDlg::ReBuildItemIndexArrayL
       
  1893 // --------------------------------------------------------------------------
       
  1894 //
       
  1895 void CCmDlg::ReBuildItemIndexArrayL()
       
  1896     {
       
  1897     iCmManager->OpenTransactionLC();
       
  1898 
       
  1899     RArray<TUint32> cmIds;
       
  1900     ConstructCMArrayL( cmIds );
       
  1901     CleanupClosePushL( cmIds );
       
  1902     
       
  1903     // Remove hidden Connection Methods from the array if uncat folder
       
  1904     if ( !iCmDestinationImpl )
       
  1905         {
       
  1906         ClearHiddenCMsFromArrayL( cmIds );
       
  1907         }
       
  1908 
       
  1909     iItemIndex.Reset();
       
  1910     for ( TInt i = 0; i < cmIds.Count(); i++ )
       
  1911         {
       
  1912         iItemIndex.Append(i);
       
  1913         }
       
  1914 
       
  1915     CleanupStack::PopAndDestroy( &cmIds ); 
       
  1916     
       
  1917     iCmManager->CommitTransactionL( KErrNone );
       
  1918     }
       
  1919 
       
  1920 // --------------------------------------------------------------------------
       
  1921 // CCmDlg::ReOrderCMsL
       
  1922 // --------------------------------------------------------------------------
       
  1923 //
       
  1924 void CCmDlg::ReOrderCMsL()
       
  1925     {
       
  1926     ReBuildItemIndexArrayL();
       
  1927     
       
  1928     TBool prioAllowed = ETrue;
       
  1929     TInt firstNotAllowedEntry = 0;
       
  1930     TInt index = 0;
       
  1931     TInt count = iItemIndex.Count();
       
  1932     
       
  1933     if (!iCmDestinationImpl)
       
  1934         {
       
  1935         return;
       
  1936         }
       
  1937    
       
  1938     // This part is to move a SANP-referred VPN Iap to the end of list if the VPN Iap is changed from
       
  1939     // IAP-referred to SNAP-referred. 
       
  1940     for ( index = 0; index < count; index++ )
       
  1941         {
       
  1942         CCmPluginBase* cm = iCmDestinationImpl->GetConnectionMethodL( iItemIndex[index] );
       
  1943         
       
  1944         if ( cm->GetBoolAttributeL( ECmDestination ) ||
       
  1945              (cm->GetBoolAttributeL( ECmVirtual ) &&
       
  1946               cm->GetIntAttributeL( ECmNextLayerSNAPId )) )
       
  1947             {
       
  1948             prioAllowed = EFalse;
       
  1949             firstNotAllowedEntry = index;
       
  1950             }
       
  1951         else
       
  1952             {
       
  1953             if ( !prioAllowed )
       
  1954                 {
       
  1955                 iCmDestinationImpl->ModifyPriorityL(*cm, firstNotAllowedEntry);
       
  1956                 iCmDestinationImpl->UpdateL();
       
  1957                 // start from the beginning
       
  1958                 index = 0;
       
  1959                 prioAllowed = ETrue;
       
  1960                 continue;
       
  1961                 }
       
  1962             }
       
  1963         }
       
  1964 
       
  1965     // This part is to move a IAP-referred VPN Iap to a proper location of priority in list
       
  1966     // if the VAP Iap is changed from SNAP-referred to IAP-referred.
       
  1967     for ( index = 0; index < count; index++ )
       
  1968         {
       
  1969         CCmPluginBase* cm = iCmDestinationImpl->GetConnectionMethodL( iItemIndex[index] );
       
  1970 
       
  1971         if ( cm->GetBoolAttributeL( ECmVirtual ) &&
       
  1972              !cm->GetIntAttributeL( ECmNextLayerSNAPId ) )
       
  1973             {
       
  1974             TUint32 underlying = cm->GetIntAttributeL( ECmNextLayerIapId );
       
  1975             if ( underlying != 0 )
       
  1976                 {
       
  1977                 // Find the index that this VPN Iap should be inserted
       
  1978                 TUint32 underlyingBearer = iCmManager->BearerTypeFromCmIdL( underlying );
       
  1979                 TUint32 underlyingPrio = iCmManager->GetBearerInfoIntL( underlyingBearer, ECmDefaultPriority );
       
  1980                 TInt insertAt = GetInsertIndexL( index, underlyingPrio );
       
  1981                 
       
  1982                 // Modify the priority of this VPN Iap
       
  1983                 iCmDestinationImpl->ModifyPriorityL( *cm, insertAt );
       
  1984                 }
       
  1985             }
       
  1986         }
       
  1987         iCmDestinationImpl->UpdateL();
       
  1988     }
       
  1989 
       
  1990 // --------------------------------------------------------------------------
       
  1991 // CCmDlg::CommsDatChanges
       
  1992 // --------------------------------------------------------------------------
       
  1993 //
       
  1994 void CCmDlg::CommsDatChangesL()
       
  1995     {
       
  1996     if (iCmDestinationImpl)
       
  1997         {
       
  1998         // If the destination that is currently working on disappears
       
  1999         // with some reason then go back to parent view
       
  2000         if( !iCmManager->DestinationStillExistedL( iCmDestinationImpl ) )
       
  2001             {
       
  2002             iCmManager->WatcherUnRegister();
       
  2003             iExitReason = KDialogUserBack;
       
  2004             TryExitL( iExitReason );
       
  2005             return;
       
  2006             }
       
  2007         }
       
  2008     
       
  2009     // Update list box
       
  2010     HandleListboxDataChangeL();
       
  2011     }
       
  2012 
       
  2013 // --------------------------------------------------------------------------
       
  2014 // CCmDlg::IsExceptionExitL
       
  2015 // --------------------------------------------------------------------------
       
  2016 //
       
  2017 TBool CCmDlg::IsExceptionExitL()
       
  2018     {
       
  2019     TBool retV( EFalse );
       
  2020  
       
  2021     if (iCmDestinationImpl)
       
  2022         {
       
  2023         // If the destination that is currently working on disappears
       
  2024         // with some reason then go back to parent view
       
  2025         if( !iCmManager->DestinationStillExistedL( iCmDestinationImpl ) )
       
  2026             {
       
  2027             retV = ETrue;
       
  2028             }
       
  2029         }
       
  2030     
       
  2031     return retV;
       
  2032     }