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