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