gssettingsuis/Gs/GSCallDivertPlugin/Src/GSCallDivertView.cpp
changeset 68 13e71d907dc3
equal deleted inserted replaced
40:6465d5bb863a 68:13e71d907dc3
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Main view handling for Call Divert.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "GSCallDivertContainer.h"
       
    21 #include "GSCallDivertModel.h"
       
    22 #include "GSCallDivertQuery.h"
       
    23 #include "GSCallDivertView.h"
       
    24 #include "GsLogger.h"
       
    25 #include "GSPhoneSettingConstants.h"
       
    26 #include "GSRestrictedDivertContainer.h"
       
    27 #include "LocalViewId.h"
       
    28 
       
    29 
       
    30 #include <AiwContactSelectionDataTypes.h>
       
    31 #include <AiwGenericParam.h>
       
    32 #include <aknnotewrappers.h>        //for AknErrorNote
       
    33 #include <AknUtils.h>
       
    34 #include <aknViewAppUi.h>
       
    35 #include <CPbk2SortOrderManager.h>
       
    36 #include <CPbk2StoreConfiguration.h>
       
    37 #include <CPbkContactItem.h>
       
    38 #include <CPbkSingleItemFetchDlg.h>
       
    39 #include <CVPbkContactLinkArray.h>
       
    40 #include <CVPbkContactManager.h>
       
    41 #include <featmgr.h>
       
    42 #include <gscommon.hrh>
       
    43 #include <gsfwviewuids.h>          // for restricted call forward
       
    44 #include <gscalldivertpluginrsc.rsg>
       
    45 #include <MPbk2ContactNameFormatter.h>
       
    46 #include <MVPbkContactFieldData.h>
       
    47 #include <MVPbkContactFieldTextData.h>
       
    48 #include <MVPbkContactLink.h>
       
    49 #include <MVPbkContactOperationBase.h>
       
    50 #include <MVPbkContactStoreList.h>
       
    51 #include <MVPbkStoreContact.h>
       
    52 #include <NumberGrouping.h>         // for Number Grouping
       
    53 #include <Pbk2ContactNameFormatterFactory.h>
       
    54 #include <PsetCallDiverting.h>
       
    55 #include <PsuiConstants.h>
       
    56 #include <RPbkViewResourceFile.h>
       
    57 #include <AiwServiceHandler.h>
       
    58 #include <coeaui.h>
       
    59 #include <CVPbkContactStoreUriArray.h>
       
    60 #include <CVPbkFieldTypeSelector.h>
       
    61 #include <hlplch.h>                 // for Help Launcher
       
    62 #include <hlplch.h>             // For HlpLauncher
       
    63 #include <RVPbkContactFieldDefaultPriorities.h>
       
    64 #include <StringLoader.h>
       
    65 #include <VPbkContactViewFilterBuilder.h>
       
    66 #include <voicemailboxdomaincrkeys.h>
       
    67 #include <centralrepository.h>
       
    68 
       
    69 using namespace AiwContactAssign;
       
    70 
       
    71 // LOCAL CONSTANTS
       
    72 _LIT( KGSDivertClassName, "CGSCallDivertView" );
       
    73 
       
    74 _LIT( KCallDivertInvalidchars, " ()" );
       
    75 
       
    76 // ========================= MEMBER FUNCTIONS ================================
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CGSCallDivertView::CGSCallDivertView
       
    80 //
       
    81 // C++ constructor.
       
    82 // ---------------------------------------------------------------------------
       
    83 CGSCallDivertView::CGSCallDivertView( CGSCallDivertModel* aModel )
       
    84     : iModel( aModel )
       
    85     {
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CGSCallDivertView::ConstructL
       
    90 //
       
    91 // Symbian OS two-phased constructor.
       
    92 // ---------------------------------------------------------------------------
       
    93 void CGSCallDivertView::ConstructL()
       
    94     {
       
    95     if( FeatureManager::FeatureSupported( KFeatureIdRestrictedCallDivert ) )
       
    96             {
       
    97             iModel->SetDivertServiceGroup( EGSSettIdVoiceDivert );
       
    98             }
       
    99     iModel->SetDivertView( this );
       
   100 
       
   101     iStoresOpened = EFalse;
       
   102     iNumberFetchedAsynchronously = EFalse;
       
   103 
       
   104     BaseConstructL( R_CF_DIV_VIEW );
       
   105 
       
   106     iTitles = iCoeEnv->ReadDesCArrayResourceL( R_TITLE_ARRAY );
       
   107     iRockerPress = EFalse;
       
   108 
       
   109     //Check video mailbox suppport from cenrep
       
   110     //Since it is static feature, needs to be checked only once
       
   111     CRepository* videoMailboxRepository = 
       
   112                         CRepository::NewLC( KCRUidVideoMailbox );
       
   113     videoMailboxRepository->Get( KVideoMbxSupport, iVideoMailboxSupported );
       
   114     CleanupStack::PopAndDestroy( videoMailboxRepository );
       
   115 
       
   116     // AIW for pbk2 contact selection functionality. Construct contact manager
       
   117     // with the same store configuration as in Phonebook currently.
       
   118     iServiceHandler = CAiwServiceHandler::NewL();
       
   119     iServiceHandler->AttachL( R_CALL_DIVERT_CONTACT_SELECTION_INTEREST );
       
   120     CPbk2StoreConfiguration* configuration = CPbk2StoreConfiguration::NewL();
       
   121     CleanupStack::PushL( configuration );
       
   122     CVPbkContactStoreUriArray* uriArray = configuration->CurrentConfigurationL();
       
   123     CleanupStack::PushL( uriArray );
       
   124     iContactManager = CVPbkContactManager::NewL( *uriArray );
       
   125     iContactManager->ContactStoresL().OpenAllL( *this );
       
   126     CleanupStack::PopAndDestroy( uriArray );
       
   127     CleanupStack::PopAndDestroy( configuration );
       
   128     }
       
   129 
       
   130 // ---------------------------------------------------------------------------
       
   131 // CGSCallDivertView::~CGSCallDivertView
       
   132 //
       
   133 // Destructor.
       
   134 // ---------------------------------------------------------------------------
       
   135 CGSCallDivertView::~CGSCallDivertView()
       
   136     {
       
   137     if ( iTitles )
       
   138         {
       
   139         delete iTitles;
       
   140         }
       
   141     if( iRetrieveOperation )
       
   142         {
       
   143         delete iRetrieveOperation;
       
   144         iRetrieveOperation = NULL;
       
   145         }
       
   146     if( iContactLinks )
       
   147         {
       
   148         delete iContactLinks;
       
   149         iContactLinks = NULL;
       
   150         }
       
   151     
       
   152     TRAP_IGNORE
       
   153         (
       
   154         if( iContactManager )
       
   155             {
       
   156             iContactManager->ContactStoresL().CloseAll( *this );
       
   157             iStoresOpened = EFalse;
       
   158             delete iContactManager;
       
   159             }
       
   160         );
       
   161     delete iServiceHandler;
       
   162 
       
   163 
       
   164     if( iContextMenuItems )
       
   165     	{
       
   166     	delete iContextMenuItems;
       
   167     	iContextMenuItems = NULL;
       
   168     	}
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // CGSCallDivertView::NewLC
       
   173 //
       
   174 // 1st phase constructor.
       
   175 // ---------------------------------------------------------------------------
       
   176 CGSCallDivertView* CGSCallDivertView::NewLC( CGSCallDivertModel* aModel )
       
   177     {
       
   178     CGSCallDivertView* self;
       
   179     self = new ( ELeave ) CGSCallDivertView( aModel );
       
   180     CleanupStack::PushL( self );
       
   181     self->ConstructL();
       
   182     return self;
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CGSCallDivertView::NewContainerL
       
   187 //
       
   188 // Creates new iContainer.
       
   189 // ---------------------------------------------------------------------------
       
   190 void CGSCallDivertView::NewContainerL()
       
   191     {
       
   192     if( FeatureManager::FeatureSupported( KFeatureIdRestrictedCallDivert ) )
       
   193         {
       
   194         iContainer = new (ELeave) CGSRestrictedDivertContainer();
       
   195         }
       
   196     else
       
   197         {
       
   198         iContainer = new (ELeave) CGSCallDivertContainer(
       
   199                      iModel->DivertServiceGroup() );
       
   200         }
       
   201     }
       
   202 
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CGSCallDivertView::Id
       
   206 //
       
   207 // implementation of the frameworks virtual function, closely related with view
       
   208 // architecture and has little or no relevance here
       
   209 // ---------------------------------------------------------------------------
       
   210 TUid CGSCallDivertView::Id() const
       
   211     {
       
   212     if( FeatureManager::FeatureSupported( KFeatureIdRestrictedCallDivert ) )
       
   213         {
       
   214         return KCallDivertPluginId;
       
   215         }
       
   216     else
       
   217         {
       
   218         return KCallDivertViewId;
       
   219         }
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CGSCallDivertView::HandleCommandL
       
   224 //
       
   225 // Handles the received commands
       
   226 // ---------------------------------------------------------------------------
       
   227 void CGSCallDivertView::HandleCommandL( TInt aCommand )
       
   228     {
       
   229     iVoiceMailboxDivert = EFalse;
       
   230     TBool sendRequest = EFalse;
       
   231     RMobilePhone::TMobilePhoneServiceAction info =
       
   232         RMobilePhone::EServiceActionRegister;
       
   233     TCallDivertSetting divertRequest;
       
   234 
       
   235     if ( aCommand != ECFCmdCancelAll && iContainer )
       
   236         {
       
   237         if( FeatureManager::FeatureSupported( KFeatureIdRestrictedCallDivert ) )
       
   238             {
       
   239             CGSRestrictedDivertContainer& container =
       
   240                 *static_cast<CGSRestrictedDivertContainer*>( iContainer );
       
   241             iCurrentItem = container.CurrentFeatureId();
       
   242             }
       
   243         else
       
   244             {
       
   245             CGSCallDivertContainer& container =
       
   246                 *static_cast<CGSCallDivertContainer*>( iContainer );
       
   247             iCurrentItem = container.CurrentFeatureId();
       
   248             }
       
   249         __GSLOGSTRING1("[CGSCallDivertView::HandleCommandL] iCurrentItem: %d", iCurrentItem);
       
   250 
       
   251         __ASSERT_ALWAYS( iCurrentItem != KErrNotFound, Panic( KGSDivertClassName,
       
   252                                                               EInvalidCurrentItem ) );
       
   253         }
       
   254 
       
   255     switch ( aCommand )
       
   256         {
       
   257         case EGSCmdAppChange:
       
   258             iRockerPress = EFalse;
       
   259             if ( iContainer )
       
   260             	{
       
   261             	HandleListBoxEventL( iContainer->iListBox, EEventEnterKeyPressed );
       
   262             	}            
       
   263             break;
       
   264         case EAknSoftkeyBack:
       
   265             if( FeatureManager::FeatureSupported( KFeatureIdRestrictedCallDivert ) )
       
   266                 {
       
   267                 iAppUi->ActivateLocalViewL( KGSTelPluginUid );
       
   268                 }
       
   269             else
       
   270                 {
       
   271                 iAppUi->ActivateLocalViewL( KCallDivertPluginId );
       
   272                 }
       
   273             break;
       
   274         case EAknSoftkeyExit:
       
   275             AppUi()->HandleCommandL( EEikCmdExit );
       
   276             break;
       
   277         case ECFCmdActivate:
       
   278             divertRequest.iSetting = EActivateDiverting;
       
   279             info = RMobilePhone::EServiceActionRegister;
       
   280 
       
   281             // Activate depends on the selected call type (voice/data/fax)
       
   282             switch( iModel->DivertServiceGroup() )
       
   283                 {
       
   284                 case EGSSettIdVoiceDivert:
       
   285                     // Handle voice divert. Fetch used numbers and show it in query.
       
   286                     ExecuteDivertQueryL(
       
   287                         divertRequest.iNumber,
       
   288                         iTitles->MdcaPoint( iCurrentItem ),
       
   289                         iVoiceMailboxDivert );
       
   290                     sendRequest = ETrue;
       
   291                     break;
       
   292                 case EGSSettIdVideoDivert:
       
   293                     if( iVideoMailboxSupported )
       
   294                         {
       
   295                         // Fetch used data divert number and show it in query.
       
   296                         ExecuteDivertQueryL(
       
   297                                 divertRequest.iNumber,
       
   298                                 iTitles->MdcaPoint( iCurrentItem ),
       
   299                                 iVoiceMailboxDivert );
       
   300                         sendRequest = ETrue;
       
   301                         }
       
   302                     else
       
   303                         {
       
   304                         DisplayDataCallDivertNumberQueryL( divertRequest.iNumber );
       
   305                         sendRequest = ETrue;
       
   306                         }
       
   307                     break;
       
   308                 default:
       
   309                     User::Panic( KGSDivertClassName, KErrArgument );
       
   310                     break;
       
   311                 }
       
   312             break;
       
   313         case ECFCmdCancel:
       
   314             if( FeatureManager::FeatureSupported( KFeatureIdRestrictedCallDivert ) )
       
   315                 {
       
   316                 sendRequest = EFalse;
       
   317                 iModel->CancelRestrictedCallDivertL();
       
   318                 }
       
   319             else
       
   320                 {
       
   321                 sendRequest = ETrue;
       
   322                 divertRequest.iSetting = ECancelDiverting;
       
   323                 info = RMobilePhone::EServiceActionErase;
       
   324                 }
       
   325             break;
       
   326         case ECFCmdCheckStatus:
       
   327             if( FeatureManager::FeatureSupported( KFeatureIdRestrictedCallDivert ) )
       
   328                 {
       
   329                 sendRequest = EFalse;
       
   330                 iModel->CheckStatusRestrictedCallDivertL();
       
   331                 }
       
   332             else
       
   333                 {
       
   334                 sendRequest = ETrue;
       
   335                 divertRequest.iSetting = ECheckStatus;
       
   336                 info = RMobilePhone::EServiceActionUnspecified;
       
   337                 }
       
   338             break;
       
   339         case ECFCmdCancelAll:
       
   340             sendRequest = ETrue;
       
   341             divertRequest.iSetting = EEraseDiverting;
       
   342             info = RMobilePhone::EServiceActionErase;
       
   343             break;
       
   344         case EAknCmdHelp:
       
   345             {
       
   346             if( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   347                 {
       
   348                 HlpLauncher::LaunchHelpApplicationL(
       
   349                     iEikonEnv->WsSession(), iAppUi->AppHelpContextL() );
       
   350                 }
       
   351             break;
       
   352             }
       
   353         default:
       
   354             iAppUi->HandleCommandL( aCommand );
       
   355             break;
       
   356         }
       
   357 
       
   358     // If a request needs to be sent.
       
   359     if ( sendRequest )
       
   360         {
       
   361         // will not divert in case empty number
       
   362         iModel->SendCallDivertRequestL( divertRequest,
       
   363                                         info,
       
   364                                         iVoiceMailboxDivert,
       
   365                                         aCommand,
       
   366                                         (TGSCallDivertServices) iCurrentItem );
       
   367         }
       
   368     }
       
   369 
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // CGSCallDivertView::HandleListBoxSelectionL
       
   373 //
       
   374 // Handles List box selection
       
   375 // ---------------------------------------------------------------------------
       
   376 void CGSCallDivertView::HandleListBoxSelectionL()
       
   377     {
       
   378     iRockerPress = ETrue;
       
   379     CEikMenuBar* menuBar = MenuBar();
       
   380     if ( iRockerPress )
       
   381         {
       
   382         menuBar->SetMenuTitleResourceId( R_CF_MENUBAR_OPTIONS_VIEW );
       
   383         menuBar->SetMenuType( CEikMenuBar::EMenuContext );
       
   384         }
       
   385     else
       
   386         {
       
   387         menuBar->SetMenuTitleResourceId( R_CF_MENUBAR_DIV_VIEW );
       
   388         menuBar->SetMenuType( CEikMenuBar::EMenuOptions );
       
   389         }
       
   390 
       
   391     // Display menu bar.
       
   392     menuBar->TryDisplayMenuBarL();
       
   393 
       
   394     // Reset menu type to original default (EMenuOptions).
       
   395     menuBar->SetMenuType( CEikMenuBar::EMenuOptions );
       
   396 
       
   397     iRockerPress = EFalse;
       
   398     }
       
   399 
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // CGSCallDivertView::ExecuteDivertQueryL
       
   403 //
       
   404 // --> voice calls -> all voice calls -> activate -> this popup.
       
   405 //                          OR
       
   406 // --> video calls -> all video calls -> activate -> this popup.
       
   407 //
       
   408 // ---Example---
       
   409 // All [voice/]video calls:
       
   410 // To [voice/]video mailbox
       
   411 // [050512345678]
       
   412 // [543454545435]
       
   413 // [342343242343]
       
   414 // To other number
       
   415 // ---------------------------------------------------------------------------
       
   416 //
       
   417 void CGSCallDivertView::ExecuteDivertQueryL( TTelNumber& aTelNumber,
       
   418                                              const TPtrC& aTitle,
       
   419                                              TBool& aVmbxValidNumber )
       
   420     {
       
   421     __GSLOGSTRING("[CGSCallDivertView::ExecuteDivertQueryL]");
       
   422 
       
   423     CAknSinglePopupMenuStyleListBox* list =
       
   424         new ( ELeave ) CAknSinglePopupMenuStyleListBox;
       
   425     CleanupStack::PushL( list );
       
   426 
       
   427     CDesC16ArrayFlat* defNumbers =
       
   428         new ( ELeave ) CDesC16ArrayFlat( KCFDefaultNumbers );
       
   429     CleanupStack::PushL( defNumbers );
       
   430 
       
   431     CAknPopupList* divertPopup =
       
   432         CAknPopupList::NewL( list, R_AVKON_SOFTKEYS_OK_CANCEL__OK );
       
   433     CleanupStack::PushL( divertPopup );
       
   434 
       
   435     list->ConstructL( divertPopup,CEikListBox::ELeftDownInViewRect );
       
   436     list->CreateScrollBarFrameL( ETrue );
       
   437     list->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   438         CEikScrollBarFrame::EOff,
       
   439         CEikScrollBarFrame::EAuto );
       
   440     divertPopup->SetTitleL( aTitle );
       
   441     if( iContextMenuItems )
       
   442     	{
       
   443     	delete iContextMenuItems;
       
   444     	iContextMenuItems = NULL;
       
   445     	}
       
   446     iContextMenuItems = new ( ELeave ) CDesCArrayFlat( KCFMaxNrOfTargets );
       
   447     if( iModel->DivertServiceGroup() == EGSSettIdVoiceDivert )
       
   448         {
       
   449         CreateVoiceDivertItemsL( *iContextMenuItems, *defNumbers );
       
   450         }
       
   451     else
       
   452         {
       
   453         CreateVideoDivertItemsL( *iContextMenuItems );
       
   454         }
       
   455     __GSLOGSTRING2( "[CGSCallDivertView::ExecuteDivertQueryL] ItemCount: %d, defNumCount: %d",
       
   456                     iContextMenuItems->Count(),
       
   457                     defNumbers->Count() );
       
   458     CTextListBoxModel* model = list->Model();
       
   459     model->SetItemTextArray( iContextMenuItems );
       
   460     model->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   461 
       
   462     // Executeld handles the events in the list
       
   463     TBool modified = divertPopup->ExecuteLD();
       
   464     __GSLOGSTRING1("[CGSCallDivertView::ExecuteDivertQueryL] modified: %d", modified);
       
   465     CleanupStack::Pop(); //voiceDivertPopup
       
   466 
       
   467     if ( modified )
       
   468         {
       
   469         if( iModel->DivertServiceGroup() == EGSSettIdVoiceDivert )
       
   470             {
       
   471             aTelNumber = HandleVoiceDivertSelectionL( *list,
       
   472                                                       *defNumbers,
       
   473                                                       aVmbxValidNumber );
       
   474             }
       
   475         else
       
   476             {
       
   477             aTelNumber = HandleVideoDivertSelectionL( *list );
       
   478             }
       
   479         }
       
   480     __GSLOGSTRING1( "[CGSCallDivertView::ExecuteVoiceDivertQueryL] aTelNumber: %S",
       
   481                     &aTelNumber);
       
   482     CleanupStack::PopAndDestroy( 2 ); //defNumbers, list
       
   483     __GSLOGSTRING( "[CGSCallDivertView::ExecuteVoiceDivertQueryL] End." );
       
   484     }
       
   485 
       
   486 
       
   487 // ---------------------------------------------------------------------------
       
   488 // CGSCallDivertView::HandleVoiceDivertSelectionL
       
   489 //
       
   490 // Handles user's choice in the Target list.
       
   491 // ---------------------------------------------------------------------------
       
   492 TTelNumber CGSCallDivertView::HandleVoiceDivertSelectionL(
       
   493     CAknSinglePopupMenuStyleListBox& aList,
       
   494     CDesC16ArrayFlat& aDefNumbers,
       
   495     TBool& aVmbxDivert )
       
   496     {
       
   497     __GSLOGSTRING("[CGSCallDivertView::HandleVoiceDivertSelectionL] Start...");
       
   498     TTelNumber telNumber;
       
   499     telNumber.Zero();
       
   500     TInt index = aList.CurrentItemIndex();
       
   501     __GSLOGSTRING1("[CGSCallDivertView::HandleVoiceDivertSelectionL] index: %d", index);
       
   502 
       
   503     if ( index == KCFDivertToMailBox )
       
   504         {
       
   505         if ( iModel->VoiceMailActivationL( telNumber ) == KErrNone )
       
   506             {
       
   507             if ( telNumber == KNullDesC )
       
   508                 {
       
   509                 ShowErrorNoteL();
       
   510                 }
       
   511             aVmbxDivert = ETrue;
       
   512             }
       
   513         }
       
   514     //To other number - make a dataquery
       
   515     else if ( index == ( aList.Model()->NumberOfItems() - 1 ) )
       
   516         {
       
   517         ExecuteDivertNumberQueryL( telNumber, R_TEXT_PRMPT_NUMBER );
       
   518         __GSLOGSTRING1("[CGSCallDivertView::HandleVoiceDivertSelectionL] telNumber: %S", &telNumber);
       
   519 
       
   520         UpdateDefaultVoiceDivertNumbersL( telNumber );
       
   521         }
       
   522     //To pre-defined default number
       
   523     else
       
   524         {
       
   525         telNumber = aDefNumbers.MdcaPoint( index - 1 );
       
   526         iModel->DivertHandler()->SwapDefaultNumberL( index );
       
   527         }
       
   528     __GSLOGSTRING("[CGSCallDivertView::HandleVoiceDivertSelectionL] End.");
       
   529     return telNumber;
       
   530     }
       
   531 
       
   532 
       
   533 // ---------------------------------------------------------------------------
       
   534 // CGSCallDivertView::HandleVideoDivertSelectionL
       
   535 //
       
   536 // Handles user's choice in the video Target list.
       
   537 // ---------------------------------------------------------------------------
       
   538 TTelNumber CGSCallDivertView::HandleVideoDivertSelectionL(
       
   539     CAknSinglePopupMenuStyleListBox& aList )
       
   540     {
       
   541     __GSLOGSTRING("[GSCallDivertView::HandleVideoDivertSelectionL] Start");
       
   542     TTelNumber telNumber( 0 );
       
   543     TInt index = aList.CurrentItemIndex();
       
   544     if ( index == KCFDivertToMailBox )
       
   545         {
       
   546         if ( iModel->VideoMailActivationL( telNumber ) == KErrNone )
       
   547             {
       
   548             if ( telNumber == KNullDesC )
       
   549                 {
       
   550                 ShowErrorNoteL();
       
   551                 }
       
   552             }
       
   553         }
       
   554     else if( index == ( aList.Model()->NumberOfItems() - 1 ) )
       
   555         { // To other number - make a dataquery (Last item in list)
       
   556         DisplayDataCallDivertNumberQueryL( telNumber );
       
   557         __GSLOGSTRING1("[GSCallDivertView::HandleVideoDivertSelectionL] telNumber: %S", &telNumber );
       
   558         }
       
   559     __GSLOGSTRING("[GSCallDivertView::HandleVideoDivertSelectionL] Finished");
       
   560     return telNumber;
       
   561     }
       
   562 
       
   563 
       
   564 // ---------------------------------------------------------------------------
       
   565 // CGSCallDivertView::DisplayDataCallDivertNumberQueryL
       
   566 //
       
   567 // Displays data call number query and sets call divert
       
   568 // ---------------------------------------------------------------------------
       
   569 void CGSCallDivertView::DisplayDataCallDivertNumberQueryL( TTelNumber& aTelNumber )
       
   570     {
       
   571     aTelNumber = *iModel->DivertHandler()->GetUsedDataNumberLC();
       
   572     ExecuteDivertNumberQueryL( aTelNumber, R_TEXT_PRMPT_DATA_NUMBER );
       
   573     if( aTelNumber != KNullDesC )
       
   574         {
       
   575         iModel->DivertHandler()->SetUsedDataNumberL( aTelNumber );
       
   576         }
       
   577     CleanupStack::PopAndDestroy(); // aTelNumber from GetUsedDataNumberLC()
       
   578     }
       
   579 
       
   580 
       
   581 // ---------------------------------------------------------------------------
       
   582 // CGSCallDivertView::ExecuteDivertNumberQueryL
       
   583 //
       
   584 // Executes general number query dialog used by all diverts (voice/data/fax)
       
   585 // ---------------------------------------------------------------------------
       
   586 //
       
   587 void CGSCallDivertView::ExecuteDivertNumberQueryL( TDes& aValue, TInt aType )
       
   588     {
       
   589     TBool accepted = EFalse;
       
   590     while ( !accepted )
       
   591         {
       
   592         RemoveInvalidChars( aValue ); 
       
   593         if ( aValue.Length() > KGSMaxDataLength )
       
   594             {
       
   595             //Chop the first extra digits and keep the last KGSMaxDataLength
       
   596             //digits intact. This is according to the spec.
       
   597             aValue.Delete( 0, aValue.Length() - KGSMaxDataLength );
       
   598             }
       
   599 
       
   600         __GSLOGSTRING1("[CGSCallDivertView]    ExecuteDivertNumberQueryL: aValue: %S", &aValue);
       
   601 
       
   602         if( AknTextUtils::DigitModeQuery( AknTextUtils::EDigitModeEditorDefault ) )
       
   603             {
       
   604             AknTextUtils::DisplayTextLanguageSpecificNumberConversion( aValue );
       
   605             }
       
   606         CGSCallDivertQuery* query = CGSCallDivertQuery::NewL( aValue,
       
   607             CAknQueryDialog::ENoTone,
       
   608             R_AVKON_SOFTKEYS_OK_CANCEL__OK, R_CF_SOFTKEYS_SEARCH_CANCEL );
       
   609         CleanupStack::PushL( query );
       
   610         SetPromptToQueryL( *query, aType );
       
   611         TInt queryAction = query->ExecuteLD( R_DATA_QUERY );
       
   612         CleanupStack::Pop( query );
       
   613         AknTextUtils::ConvertDigitsTo( aValue, EDigitTypeWestern );
       
   614         switch ( queryAction )
       
   615             {
       
   616             case EAknSoftkeySearch:
       
   617                 if( iStoresOpened )
       
   618                     {
       
   619                     // Reset the number selection because 'search' is selected.
       
   620                     aValue.Zero();
       
   621                     StartAsyncPhoneNumberFetchL();
       
   622                     accepted = ETrue;// Change to asynchronous mode
       
   623                     }
       
   624                 break;
       
   625             case EAknSoftkeyOk:
       
   626                 accepted = ETrue;
       
   627                 if ( ValidatePhoneNumberL( aValue ) > KCFValidPhoneNumber ||
       
   628                      aValue.Length() == 0 )
       
   629                     {
       
   630                     accepted = EFalse;
       
   631                     }
       
   632                 if ( iNumberFetchedAsynchronously )
       
   633                 	{
       
   634                 	switch( iModel->DivertServiceGroup() )
       
   635                 	    {
       
   636                 	    case EGSSettIdVoiceDivert:
       
   637                         	UpdateDefaultVoiceDivertNumbersL( aValue );
       
   638                         	break;
       
   639                 	    case EGSSettIdVideoDivert:
       
   640                             {
       
   641                 	        TTelNumber dataNumber( aValue );// Convert to TTelNumber
       
   642                 	        iModel->DivertHandler()->SetUsedDataNumberL( dataNumber );
       
   643                 	        break;
       
   644                             }
       
   645                 	    default:
       
   646                 	        break;
       
   647                 	    }
       
   648                 	iNumberFetchedAsynchronously = EFalse;
       
   649                 	}
       
   650                 break;
       
   651             case EAknSoftkeyBack:
       
   652             case EAknSoftkeyCancel:
       
   653             default:
       
   654                 accepted = ETrue;
       
   655                 aValue.Zero();
       
   656                 break;
       
   657             }
       
   658         }
       
   659     }
       
   660 
       
   661 
       
   662 // ---------------------------------------------------------------------------
       
   663 // CGSCallDivertView::StartAsyncPhoneNumberFetchL
       
   664 //
       
   665 // Fetches values from phonebook ASYNCHRONOUSLY (pbk2 requirement).
       
   666 // ---------------------------------------------------------------------------
       
   667 //
       
   668 void CGSCallDivertView::StartAsyncPhoneNumberFetchL()
       
   669     {
       
   670     TUint fetchFlags = 0;
       
   671 
       
   672     // Construct empty filter
       
   673     CVPbkFieldTypeSelector* contactViewFilter =
       
   674                             CVPbkFieldTypeSelector::NewL(iContactManager->FieldTypes());
       
   675     CleanupStack::PushL(contactViewFilter);
       
   676 
       
   677     // Append the filter object with suitable criteria (only contacts with
       
   678     // phone number shown)
       
   679     VPbkContactViewFilterBuilder::BuildContactViewFilterL(*contactViewFilter,
       
   680                               EVPbkContactViewFilterPhoneNumber, *iContactManager);
       
   681     RVPbkContactFieldDefaultPriorities array;
       
   682     CleanupClosePushL(array);
       
   683 
       
   684     TAiwSingleItemSelectionDataV3 data = TAiwSingleItemSelectionDataV3();
       
   685     // Details selection shows only phone numbers
       
   686     data.SetAddressSelectType(EAiwPhoneNumberSelect);
       
   687     data.SetDefaultPriorities(array);
       
   688     // Contact list shows only contacts that have phone number(s)
       
   689     data.SetFetchFilter(contactViewFilter);
       
   690     data.SetFlags(fetchFlags);
       
   691 
       
   692     CAiwGenericParamList& inParamList = iServiceHandler->InParamListL();
       
   693     TAiwGenericParam param(EGenericParamContactSelectionData,
       
   694                      TAiwVariant(TAiwSingleItemSelectionDataV3Pckg(data)));
       
   695     inParamList.AppendL(param);
       
   696 
       
   697     iServiceHandler->ExecuteServiceCmdL(
       
   698             KAiwCmdSelect,
       
   699             inParamList,
       
   700             iServiceHandler->OutParamListL(),
       
   701             0,
       
   702             this);
       
   703 
       
   704     CleanupStack::PopAndDestroy(); // array
       
   705     CleanupStack::PopAndDestroy( contactViewFilter );
       
   706     }
       
   707 
       
   708 
       
   709 // ---------------------------------------------------------------------------
       
   710 // CGSCallDivertView::ValidatePhoneNumberL
       
   711 //
       
   712 // Puts a single resource string into a list.
       
   713 // ---------------------------------------------------------------------------
       
   714 TInt CGSCallDivertView::ValidatePhoneNumberL( const TDesC& aDivertTo )
       
   715     {
       
   716     TInt enteredNumber = KErrNone;
       
   717     TInt noOfInvalidChars = KCFInvalidChars().Length();
       
   718 
       
   719     // Plus is a special case, as it is accepted as first character.
       
   720     // FindPlus returns KCFErrIllegalNumber(1) if the number is not
       
   721     // acceptable.
       
   722     enteredNumber += FindPlus( aDivertTo );
       
   723     for ( TInt index = 0; index < noOfInvalidChars; index++ )
       
   724         {
       
   725         enteredNumber += aDivertTo.Find(
       
   726             KCFInvalidChars().Mid( index, 1 ) );
       
   727         }
       
   728     // Find returns KErrNotFound(-1), if character(s) is not found.
       
   729     // Therefore, after four searches for special characters in the
       
   730     // number, all results that have greater than -5 as result are not
       
   731     // acceptable.
       
   732     if ( enteredNumber > KCFValidPhoneNumber )
       
   733         {
       
   734         ShowErrorNoteL();
       
   735         __GSLOGSTRING( "[CGSCallDivertView::ValidatePhoneNumberL] Invalid phone number. " );
       
   736         }
       
   737     return enteredNumber;
       
   738     }
       
   739 
       
   740 
       
   741 // ---------------------------------------------------------------------------
       
   742 // CGSCallDivertView::AppendDelayItemL
       
   743 //
       
   744 // Appends items to delay time list.
       
   745 // ---------------------------------------------------------------------------
       
   746 void CGSCallDivertView::AppendDelayItemL( CDesCArrayFlat& aArrayToAppend,
       
   747                                           TInt aIndex )
       
   748     {
       
   749     //Delay times are defined as 5,10,15,20,25,30.
       
   750     //Append each of these to a list.
       
   751     TInt delaySeconds = KCFDelayStep * ( aIndex + 1);
       
   752     HBufC* string = StringLoader::LoadLC( R_TEXT_SLIST_SECONDS, delaySeconds );
       
   753 
       
   754     TPtr bufPtr = string->Des();
       
   755     if( AknTextUtils::DigitModeQuery( AknTextUtils::EDigitModeShownToUser ) )
       
   756         {
       
   757         AknTextUtils::LanguageSpecificNumberConversion( bufPtr );
       
   758         }
       
   759     aArrayToAppend.AppendL( *string );
       
   760     CleanupStack::PopAndDestroy( string );
       
   761     }
       
   762 
       
   763 
       
   764 // ---------------------------------------------------------------------------
       
   765 // CGSCallDivertView::CreateVoiceDivertItemsL
       
   766 //
       
   767 // Creates items for the targert list.
       
   768 // ---------------------------------------------------------------------------
       
   769 void CGSCallDivertView::CreateVoiceDivertItemsL(
       
   770     CDesCArray& aItems,
       
   771     CDesC16ArrayFlat& aDefaultNumbers )
       
   772     {
       
   773     HBufC* item = StringLoader::LoadLC( R_TEXT_DIVERT_TO_VOICE_MAIL );
       
   774     aItems.AppendL( *item );
       
   775     CleanupStack::PopAndDestroy( item );
       
   776     ReadDefaultVoiceDivertNumbersL( aItems, aDefaultNumbers );
       
   777     HBufC* string = StringLoader::LoadLC( R_TEXT_DIVERT_TO_NUMBER );
       
   778     aItems.AppendL( *string );
       
   779     CleanupStack::PopAndDestroy( string );
       
   780     }
       
   781 
       
   782 
       
   783 // ---------------------------------------------------------------------------
       
   784 // CGSCallDivertView::CreateVideoDivertItemsL
       
   785 //
       
   786 // Creates items for the data target list.
       
   787 // ---------------------------------------------------------------------------
       
   788 void CGSCallDivertView::CreateVideoDivertItemsL( CDesCArray& aItems )
       
   789     {
       
   790     HBufC* item = StringLoader::LoadLC( R_QTN_SS_DIVERT_TO_VIDEO_MAILBOX );
       
   791     aItems.AppendL( *item );
       
   792     CleanupStack::PopAndDestroy( item );
       
   793     HBufC* string = StringLoader::LoadLC( R_QTN_SS_DIVERT_VCALL_TO_OTHER_NUMBER );
       
   794     aItems.AppendL( *string );
       
   795     CleanupStack::PopAndDestroy( string );
       
   796     }
       
   797 
       
   798 
       
   799 // ---------------------------------------------------------------------------
       
   800 //
       
   801 // Seeks '+' from given number. If '+' is first character, it is ignored.
       
   802 //
       
   803 // ---------------------------------------------------------------------------
       
   804 TInt CGSCallDivertView::FindPlus( const TDesC& aDivertTo )
       
   805     {
       
   806     TInt seekPlus = aDivertTo.Find( KCFPlusSign );
       
   807     if ( seekPlus == KErrNotFound )
       
   808         {
       
   809         //no '+' in the number
       
   810         return KErrNone;
       
   811         }
       
   812     //first char '+', but there can additional '+'s
       
   813     if ( seekPlus == 0 )
       
   814         {
       
   815         //ignore first '+'
       
   816         TPtrC concat = aDivertTo.Right( aDivertTo.Length() - 1 );
       
   817         seekPlus = concat.Find( KCFPlusSign );
       
   818         if ( seekPlus != KErrNotFound )
       
   819             {
       
   820             return KCFErrIllegalNumber; //two '+'s in number
       
   821             }
       
   822         return KErrNone;
       
   823         }
       
   824     //'+' in number, but not first char
       
   825     else
       
   826         {
       
   827         return KCFErrIllegalNumber;
       
   828         }
       
   829     }
       
   830 
       
   831 
       
   832 // ---------------------------------------------------------------------------
       
   833 // CGSCallDivertView::SetPromptToQueryL
       
   834 // Sets prompt to a query.
       
   835 //
       
   836 // ---------------------------------------------------------------------------
       
   837 void CGSCallDivertView::SetPromptToQueryL( CGSCallDivertQuery& aQuery,
       
   838                                            const TInt& aType )
       
   839     {
       
   840     HBufC* title = StringLoader::LoadLC( aType );
       
   841     aQuery.SetPromptL( *title );
       
   842     CleanupStack::PopAndDestroy( title );
       
   843     }
       
   844 
       
   845 
       
   846 // ---------------------------------------------------------------------------
       
   847 // CGSCallDivertView::CreateDelayTimeItemsL
       
   848 // Creates items for delay time list.
       
   849 //
       
   850 // ---------------------------------------------------------------------------
       
   851 //
       
   852 void CGSCallDivertView::CreateDelayTimeItemsL( CDesCArrayFlat& aItems)
       
   853     {
       
   854     for ( TInt index = 0; index < KGSNrOfDelays; index++ )
       
   855         {
       
   856         AppendDelayItemL( aItems, index );
       
   857         }
       
   858     }
       
   859 
       
   860 
       
   861 // ---------------------------------------------------------------------------
       
   862 // CGSCallDivertView::CreateRestrictedCallDivertDelayTimeItemsL
       
   863 // Creates items for Delay time list for restricted call divert.
       
   864 //
       
   865 // ---------------------------------------------------------------------------
       
   866 //
       
   867 void CGSCallDivertView::CreateRestrictedCallDivertDelayTimeItemsL(
       
   868     CDesCArrayFlat& aItems )
       
   869     {
       
   870     // first item is 0 seconds
       
   871     AppendDelayItemL( aItems, -1);
       
   872     for ( TInt index = 0; index < KGSNrOfDelays; index++ )
       
   873         {
       
   874         AppendDelayItemL( aItems, index );
       
   875         }
       
   876     AppendDelayItemL( aItems, ( 60 / KCFDelayStep ) - 1);
       
   877     AppendDelayItemL( aItems, ( 90 / KCFDelayStep ) - 1);
       
   878     AppendDelayItemL( aItems, ( 120 / KCFDelayStep ) - 1);
       
   879     }
       
   880 
       
   881 // -----------------------------------------------------------------------------
       
   882 // CGSCallDivertView::ProcessCommandL
       
   883 // -----------------------------------------------------------------------------
       
   884 void CGSCallDivertView::ProcessCommandL( TInt aCommand )
       
   885     {
       
   886     MenuBar()->SetContextMenuTitleResourceId( R_CALL_DIVERT_MSK_CONTEXTMENUBAR );
       
   887     // Call base class
       
   888     CAknView::ProcessCommandL( aCommand );
       
   889     }
       
   890 
       
   891 
       
   892 // ---------------------------------------------------------------------------
       
   893 //
       
   894 // Before showing a options menu, delete options key specific settings if
       
   895 // rocker key has been pressed.
       
   896 // ---------------------------------------------------------------------------
       
   897 //
       
   898 void CGSCallDivertView::DynInitMenuPaneL( TInt aResourceId,
       
   899                                           CEikMenuPane* aMenuPane )
       
   900     {
       
   901     TInt currentItem;
       
   902     CEikMenuBar* menuBar = MenuBar();
       
   903     if( FeatureManager::FeatureSupported( KFeatureIdRestrictedCallDivert ) )
       
   904         {
       
   905         CGSRestrictedDivertContainer &container =
       
   906             *static_cast<CGSRestrictedDivertContainer*>( iContainer );
       
   907         currentItem = container.CurrentFeatureId();
       
   908         }
       
   909     else
       
   910         {
       
   911         CGSCallDivertContainer& container =
       
   912             *static_cast<CGSCallDivertContainer*>( iContainer );
       
   913         currentItem = container.CurrentFeatureId();
       
   914         }
       
   915 
       
   916     if ( aResourceId == R_CF_DIV_VIEW_MENU )
       
   917         {
       
   918         if (!menuBar->ItemSpecificCommandsEnabled() && menuBar->GetMenuType() == CEikMenuBar::EMenuOptions)
       
   919         	{
       
   920         	aMenuPane->SetItemDimmed( ECFCmdActivate, ETrue );
       
   921         	aMenuPane->SetItemDimmed( ECFCmdCancel, ETrue );
       
   922         	aMenuPane->SetItemDimmed( ECFCmdCheckStatus, ETrue );
       
   923         	}
       
   924         //remove help, if not supported from the main divert view
       
   925         //in this step, help is added to context menu too, which
       
   926         //is deleted in the next conditional stmt
       
   927         if ( FeatureManager::FeatureSupported ( KFeatureIdHelp ) )
       
   928             {
       
   929             aMenuPane->SetItemDimmed( EAknCmdHelp, EFalse );
       
   930             }
       
   931         else
       
   932             {
       
   933             aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   934             }
       
   935 
       
   936         if ( iRockerPress )
       
   937             {
       
   938             //remove Exit & Help from the menu
       
   939             aMenuPane->SetItemDimmed( EAknCmdExit, ETrue );
       
   940             aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   941             }
       
   942         else
       
   943             {
       
   944             iRockerPress = EFalse;
       
   945             }
       
   946         }
       
   947 
       
   948     if ( aResourceId == R_CF_MSK_DIV_VIEW_MENU ||
       
   949          aResourceId == R_CF_DIV_VIEW_MENU )
       
   950         {
       
   951         // when not available does not have check status
       
   952         if ( currentItem == ECFDivertWhenNotAvailable )
       
   953             {
       
   954             aMenuPane->SetItemDimmed( ECFCmdCheckStatus, ETrue );
       
   955             }
       
   956         }
       
   957     }
       
   958 
       
   959 // ---------------------------------------------------------
       
   960 // CGSCallDivertView::ShowErrorNote
       
   961 //
       
   962 // ---------------------------------------------------------
       
   963 void CGSCallDivertView::ShowErrorNoteL()
       
   964     {
       
   965     HBufC* string = StringLoader::LoadLC( R_INVALID_NUMBER );
       
   966     CAknErrorNote* note = new ( ELeave ) CAknErrorNote ( ETrue );
       
   967     note->ExecuteLD( *string );
       
   968     CleanupStack::PopAndDestroy( string );
       
   969     }
       
   970 
       
   971 // ---------------------------------------------------------------------------
       
   972 // CGSCallDivertView::ReadDefaultVoiceDivertNumbersL
       
   973 //
       
   974 // Creates defcault items for the target list.
       
   975 // ---------------------------------------------------------------------------
       
   976 void CGSCallDivertView::ReadDefaultVoiceDivertNumbersL(
       
   977     CDesCArray& aItems,
       
   978     CDesC16ArrayFlat& aDefaultNumbers )
       
   979     {
       
   980     TInt amount = KErrNone;
       
   981 
       
   982     // this is for fetching name to a number from phonebook
       
   983     HBufC* defaultName = NULL;
       
   984 
       
   985     //Default numbers are fetched from shared data
       
   986     amount = iModel->DivertHandler()->GetDefaultNumbersL( aDefaultNumbers );
       
   987     __ASSERT_ALWAYS( amount == aDefaultNumbers.MdcaCount(),
       
   988         Panic( KGSDivertClassName, ECFDefaultNumberCountError ) );
       
   989 
       
   990     for ( TInt i = 0; i < amount; i++ )
       
   991         {
       
   992         //Default numbers should be checked, if there is a contact name associated
       
   993         // with it.
       
   994         defaultName = NULL;
       
   995         defaultName = iModel->MatchNumberToContactLC( aDefaultNumbers.MdcaPoint( i ) );
       
   996         __GSLOGSTRING1("[CGSCallDivertView]    ReadDefaultVoiceDivertNumbersL: defaultName: %S", &defaultName);
       
   997         if ( defaultName )
       
   998             {
       
   999             aItems.AppendL( *defaultName );
       
  1000             }
       
  1001         else
       
  1002             {
       
  1003             TTelNumber string;
       
  1004             if ( iModel->NumberGroupingSupportedL() )
       
  1005                 {
       
  1006                 CPNGNumberGrouping* numberGrouping = CPNGNumberGrouping::NewL(
       
  1007                     KPSUIMaxPSUIItemLength );
       
  1008                 CleanupStack::PushL( numberGrouping );
       
  1009 
       
  1010                 if ( aDefaultNumbers.MdcaPoint( i ).Length() <=
       
  1011                     numberGrouping->MaxDisplayLength() )
       
  1012                     {
       
  1013                     numberGrouping->Set( aDefaultNumbers.MdcaPoint( i ) );
       
  1014                     string = numberGrouping->FormattedNumber();
       
  1015                     }
       
  1016                 CleanupStack::PopAndDestroy( numberGrouping );
       
  1017                 }
       
  1018             if ( !string.Length() )
       
  1019                 {
       
  1020                 string = aDefaultNumbers.MdcaPoint(i);
       
  1021                 }
       
  1022             AknTextUtils::DisplayTextLanguageSpecificNumberConversion( string );
       
  1023             aItems.AppendL( string );
       
  1024             __GSLOGSTRING1("[CGSCallDivertView]    ReadDefaultVoiceDivertNumbersL: string: %S", &string);
       
  1025             }
       
  1026         CleanupStack::PopAndDestroy(); //defaultName
       
  1027         }
       
  1028     }
       
  1029 
       
  1030 // ---------------------------------------------------------------------------
       
  1031 // CGSCallDivertView::UpdateDefaultVoiceDivertNumbersL
       
  1032 //
       
  1033 // Updates most recently used numbers to cenrep
       
  1034 // ---------------------------------------------------------------------------
       
  1035 void CGSCallDivertView::UpdateDefaultVoiceDivertNumbersL(  TDes& aNumber )
       
  1036 
       
  1037     {
       
  1038     if ( aNumber !=  KNullDesC && iContextMenuItems )
       
  1039         {
       
  1040         //If activation is done to already existing default number,
       
  1041         //but using the "Other number" selection, this must be verified.
       
  1042         HBufC* contactName = iModel->MatchNumberToContactLC( aNumber );
       
  1043 
       
  1044         TInt found = KErrNone;
       
  1045         TInt loc = KErrNotFound;
       
  1046 
       
  1047         if ( contactName )
       
  1048             {
       
  1049             found = iContextMenuItems->Find( *contactName, loc );
       
  1050             }
       
  1051         else
       
  1052             {
       
  1053             found = iContextMenuItems->Find( aNumber, loc );
       
  1054             }
       
  1055         CleanupStack::PopAndDestroy(); //contactName
       
  1056 
       
  1057         if ( found > 0 ) //number is not part of current def.numbers
       
  1058             {
       
  1059             iModel->DivertHandler()->SetNewDefaultNumberL( aNumber );
       
  1060             }
       
  1061         else
       
  1062             {
       
  1063             iModel->DivertHandler()->SwapDefaultNumberL( loc );
       
  1064             }
       
  1065         }
       
  1066     else
       
  1067         {
       
  1068         __GSLOGSTRING( "[CGSCallDivertView::UpdateDefaultVoiceDivertNumbersL] iContextMenuItems == NULL!!" );
       
  1069         }
       
  1070 
       
  1071     }
       
  1072 
       
  1073 // ---------------------------------------------------------------------------
       
  1074 // CGSCallDivertView::HandleNotifyL
       
  1075 //
       
  1076 // AIW callback function.
       
  1077 // ---------------------------------------------------------------------------
       
  1078 TInt CGSCallDivertView::HandleNotifyL(
       
  1079     TInt aCmdId,
       
  1080     TInt aEventId,
       
  1081     CAiwGenericParamList& aEventParamList,
       
  1082     const CAiwGenericParamList& /*aInParamList*/ )
       
  1083     {
       
  1084     TInt err = KErrNone;
       
  1085     if( ( aCmdId == KAiwCmdSelect ) || ( aCmdId == KAiwCmdAssign ) )
       
  1086         {
       
  1087         if( aEventId == KAiwEventCompleted )
       
  1088             {
       
  1089             TInt index = 0;
       
  1090             iNumberFetchedAsynchronously = ETrue;
       
  1091             const TAiwGenericParam* param = aEventParamList.FindFirst(
       
  1092                 index, EGenericParamContactLinkArray );
       
  1093 
       
  1094             if( param && iStoresOpened )
       
  1095                 {
       
  1096                 if( iContactLinks )
       
  1097                     {
       
  1098                     delete iContactLinks;
       
  1099                     iContactLinks = NULL;
       
  1100                     }
       
  1101                 TPtrC8 contactLinks = param->Value().AsData();
       
  1102 
       
  1103                 CVPbkContactLinkArray* localContactLinks =
       
  1104                     CVPbkContactLinkArray::NewLC(
       
  1105                     contactLinks,
       
  1106                     iContactManager->ContactStoresL() );
       
  1107 
       
  1108                 CleanupStack::Pop( localContactLinks );
       
  1109                 iContactLinks = localContactLinks;
       
  1110 
       
  1111                 if( iContactLinks->Count() > 0 )
       
  1112                     {
       
  1113                     iRetrieveOperation = iContactManager->RetrieveContactL( iContactLinks->At( 0 ), *this );
       
  1114                     }
       
  1115                 }
       
  1116             }
       
  1117         else if (aEventId == KAiwEventCanceled)
       
  1118             {
       
  1119             // Do nothing.
       
  1120             }
       
  1121         else if (aEventId == KAiwEventOutParamCheck)
       
  1122             {
       
  1123             // This is needed as PBK2 mysteriously crashes if check is not
       
  1124             // acccepted. There's no actual need to check anything but to go
       
  1125             // ahead here so setting to ETrue.
       
  1126             err = ETrue;
       
  1127             }
       
  1128         else if (aEventId == KAiwEventQueryExit)
       
  1129             {
       
  1130             err = ETrue;
       
  1131             }
       
  1132         }
       
  1133     return err;
       
  1134     }
       
  1135 
       
  1136 
       
  1137 // --------------------------------------------------------------------------
       
  1138 // CGSCallDivertView::VPbkSingleContactOperationComplete
       
  1139 // --------------------------------------------------------------------------
       
  1140 //
       
  1141 void CGSCallDivertView::VPbkSingleContactOperationComplete(
       
  1142     MVPbkContactOperationBase& /*aOperation*/,
       
  1143     MVPbkStoreContact* aContact )
       
  1144     {
       
  1145     if( iRetrieveOperation )
       
  1146         {
       
  1147         delete iRetrieveOperation;
       
  1148         iRetrieveOperation = NULL;
       
  1149         }
       
  1150     TRAP_IGNORE
       
  1151         (
       
  1152         MVPbkStoreContactField* field = aContact->Fields().RetrieveField( iContactLinks->At( 0 ) );
       
  1153         if ( field && field->FieldData().DataType() == EVPbkFieldStorageTypeText )
       
  1154             {
       
  1155             // aContact has selected phone number from Pbk2 dialog. Set this as
       
  1156             // a text for ExecuteDivertNumberQueryL.
       
  1157             TCallDivertSetting setting;
       
  1158             setting.iSetting = EActivateDiverting;
       
  1159             setting.iNumber = MVPbkContactFieldTextData::Cast( field->FieldData() ).Text();
       
  1160 
       
  1161             //Ask for user input.
       
  1162             ExecuteDivertNumberQueryL( setting.iNumber, R_TEXT_PRMPT_NUMBER );
       
  1163 
       
  1164             // ExecuteDivertNumberQueryL() will set setting.iNumber to KNullDesC if user
       
  1165             // selected 'search'. In this case program execution is moved to
       
  1166             // pbk2 asynchronous dialog and this function can exit without
       
  1167             // sending call divert request.
       
  1168             if( setting.iNumber != KNullDesC )
       
  1169                 {
       
  1170                 // Send divert request.
       
  1171                 iModel->SendCallDivertRequestL( setting,
       
  1172                                                 RMobilePhone::EServiceActionRegister,
       
  1173                                                 iVoiceMailboxDivert,
       
  1174                                                 ECFCmdActivate,
       
  1175                                                 (TGSCallDivertServices) iCurrentItem );
       
  1176                 }
       
  1177             }
       
  1178         );
       
  1179     delete aContact;// Ownership is taken by this
       
  1180     }
       
  1181 
       
  1182 
       
  1183 // --------------------------------------------------------------------------
       
  1184 // CGSCallDivertView::VPbkSingleContactOperationFailed
       
  1185 // --------------------------------------------------------------------------
       
  1186 //
       
  1187 void CGSCallDivertView::VPbkSingleContactOperationFailed(
       
  1188     MVPbkContactOperationBase& /*aOperation*/,
       
  1189     TInt /*aError*/)
       
  1190     {
       
  1191     if( iRetrieveOperation )
       
  1192         {
       
  1193         delete iRetrieveOperation;
       
  1194         iRetrieveOperation = NULL;
       
  1195         }
       
  1196 
       
  1197     }
       
  1198 
       
  1199 // --------------------------------------------------------------------------
       
  1200 // CGSCallDivertView::OpenComplete
       
  1201 // --------------------------------------------------------------------------
       
  1202 //
       
  1203 void CGSCallDivertView::OpenComplete()
       
  1204     {
       
  1205     iStoresOpened = ETrue;
       
  1206     }
       
  1207 
       
  1208 // --------------------------------------------------------------------------
       
  1209 // CGSCallDivertView::StoreReady
       
  1210 // --------------------------------------------------------------------------
       
  1211 //
       
  1212 void CGSCallDivertView::StoreReady( MVPbkContactStore& /*aContactStore*/ )
       
  1213     {
       
  1214     // Do nothing
       
  1215     }
       
  1216 
       
  1217 // --------------------------------------------------------------------------
       
  1218 // CGSCallDivertView::StoreUnavailable
       
  1219 // --------------------------------------------------------------------------
       
  1220 //
       
  1221 void CGSCallDivertView::StoreUnavailable
       
  1222         ( MVPbkContactStore& /*aContactStore*/, TInt /*aReason*/ )
       
  1223     {
       
  1224     // Do nothing
       
  1225     }
       
  1226 
       
  1227 // --------------------------------------------------------------------------
       
  1228 // CGSCallDivertView::HandleStoreEventL
       
  1229 // --------------------------------------------------------------------------
       
  1230 //
       
  1231 void CGSCallDivertView::HandleStoreEventL( MVPbkContactStore& /*aContactStore*/,
       
  1232         TVPbkContactStoreEvent /*aStoreEvent*/ )
       
  1233     {
       
  1234     // Do nothing
       
  1235     }
       
  1236 
       
  1237 
       
  1238 
       
  1239 // ---------------------------------------------------------------------------
       
  1240 // CGSCallDivertView::CreateTimeListL
       
  1241 //
       
  1242 // Activates this view's popup list in order to change time-setting.
       
  1243 // ---------------------------------------------------------------------------
       
  1244 TInt CGSCallDivertView::CreateTimeListL()
       
  1245     {
       
  1246     CAknSinglePopupMenuStyleListBox* list =
       
  1247         new ( ELeave ) CAknSinglePopupMenuStyleListBox;
       
  1248     CleanupStack::PushL( list );
       
  1249 
       
  1250     CAknPopupList* popupList =
       
  1251         CAknPopupList::NewL( list, R_AVKON_SOFTKEYS_OK_CANCEL__OK );
       
  1252     CleanupStack::PushL( popupList );
       
  1253 
       
  1254     HBufC* title = StringLoader::LoadLC( R_TEXT_DELAY_HEADER );
       
  1255     popupList->SetTitleL( *title );
       
  1256     CleanupStack::PopAndDestroy( title );
       
  1257 
       
  1258     list->ConstructL( popupList,CEikListBox::ELeftDownInViewRect );
       
  1259     list->CreateScrollBarFrameL( ETrue );
       
  1260     list->ScrollBarFrame()->SetScrollBarVisibilityL(
       
  1261         CEikScrollBarFrame::EOff,
       
  1262         CEikScrollBarFrame::EAuto );
       
  1263 
       
  1264     CDesCArrayFlat* items;
       
  1265     if( FeatureManager::FeatureSupported( KFeatureIdRestrictedCallDivert ) )
       
  1266         {
       
  1267         items = new ( ELeave ) CDesCArrayFlat( KGSNrOfDelays + 4 );
       
  1268         CleanupStack::PushL( items );
       
  1269         CreateRestrictedCallDivertDelayTimeItemsL( *items );
       
  1270         }
       
  1271     else
       
  1272         {
       
  1273         items = new ( ELeave ) CDesCArrayFlat( KGSNrOfDelays );
       
  1274         CleanupStack::PushL( items );
       
  1275         CreateDelayTimeItemsL( *items );
       
  1276         }
       
  1277     CTextListBoxModel* model = list->Model();
       
  1278     model->SetItemTextArray( items );
       
  1279     model->SetOwnershipType( ELbmOwnsItemArray );
       
  1280     CleanupStack::Pop(); //items
       
  1281     list->HandleItemAdditionL();
       
  1282 
       
  1283     //set focus according to file read by phonesettings
       
  1284     //set delay timer field value
       
  1285     TInt currIndex = KErrNone;
       
  1286     if( FeatureManager::FeatureSupported( KFeatureIdRestrictedCallDivert ) )
       
  1287         {
       
  1288         TInt itemCount = items->Count();
       
  1289         if (( iModel->DivertHandler()->GetTimerValueL() / KCFDelayStep ) > ( itemCount - 4))
       
  1290             {
       
  1291             // Within 60, 90, 120 range
       
  1292             switch ( iModel->DivertHandler()->GetTimerValueL() )
       
  1293                 {
       
  1294                 case 60:
       
  1295                     currIndex = itemCount - 3;
       
  1296                     break;
       
  1297                 case 90:
       
  1298                     currIndex = itemCount - 2;
       
  1299                     break;
       
  1300                 case 120:
       
  1301                     currIndex = itemCount - 1;
       
  1302                     break;
       
  1303                 }
       
  1304             }
       
  1305         else
       
  1306             {
       
  1307             currIndex = iModel->DivertHandler()->GetTimerValueL() / KCFDelayStep;
       
  1308             }
       
  1309         }
       
  1310     else
       
  1311         {
       
  1312         currIndex = ( iModel->DivertHandler()->GetTimerValueL() / KCFDelayStep ) - 1;
       
  1313         }
       
  1314     __GSLOGSTRING1( "[CGSCallDivertView::CreateTimeListL] currIndex: %d", currIndex );
       
  1315 
       
  1316     list->SetCurrentItemIndex( currIndex );
       
  1317     //if possible show topmost item
       
  1318     list->SetTopItemIndex(0);
       
  1319 
       
  1320     TInt keyPress = popupList->ExecuteLD();
       
  1321     CleanupStack::Pop( popupList );
       
  1322     if ( keyPress )
       
  1323         {
       
  1324         TInt index = list->CurrentItemIndex();
       
  1325         __GSLOGSTRING1( "[CGSCallDivertView::CreateTimeListL] index: %d", index );
       
  1326 
       
  1327         if( FeatureManager::FeatureSupported( KFeatureIdRestrictedCallDivert ) )
       
  1328             {
       
  1329             TInt itemCount = items->Count();
       
  1330             if ( index > ( itemCount - 4))
       
  1331                 {
       
  1332                 // Within 60, 90, 120 range
       
  1333                 if ( index == itemCount - 3)
       
  1334                     {
       
  1335                     iModel->DivertHandler()->SetTimerValueL( 60 );
       
  1336                     }
       
  1337                 else if ( index == itemCount - 2 )
       
  1338                     {
       
  1339                     iModel->DivertHandler()->SetTimerValueL( 90 );
       
  1340                     }
       
  1341                 else if ( index == itemCount - 1 )
       
  1342                     {
       
  1343                     iModel->DivertHandler()->SetTimerValueL( 120 );
       
  1344                     }
       
  1345                 }
       
  1346             else
       
  1347                 {
       
  1348                 // first entry is 0 seconds
       
  1349                 currIndex = iModel->DivertHandler()->SetTimerValueL( index * KCFDelayStep );
       
  1350                 }
       
  1351             }
       
  1352         else
       
  1353             {
       
  1354             //save to file the correct value calculated from index
       
  1355             iModel->DivertHandler()->SetTimerValueL( ( index + 1 ) * KCFDelayStep );
       
  1356             }
       
  1357         }
       
  1358     CleanupStack::PopAndDestroy( list );
       
  1359     return keyPress;
       
  1360     }
       
  1361 
       
  1362 // --------------------------------------------------------------------------
       
  1363 // CGSCallDivertView::RemoveInvalidChars
       
  1364 // Remove invalid " ", "()" which were sync with PC suite. 
       
  1365 // --------------------------------------------------------------------------
       
  1366 //
       
  1367 void CGSCallDivertView::RemoveInvalidChars( TDes& aNumber )
       
  1368   {
       
  1369   TInt noOfInvalidchars = KCallDivertInvalidchars().Length();
       
  1370   TInt location = KErrNone; 
       
  1371   // delete the invalid chars of KCallDivertInvalidchars. 
       
  1372   //aNumber changed to valid phone number if it contains invalid chars
       
  1373   for ( TInt index = 0; index < noOfInvalidchars; index++ )
       
  1374        {     
       
  1375        while ( ETrue )
       
  1376            {
       
  1377            location = aNumber.Find( KCallDivertInvalidchars().Mid( index, 1 ) );   
       
  1378            if ( location == KErrNotFound )
       
  1379                {
       
  1380                break;
       
  1381                }
       
  1382            aNumber.Delete( location, 1 ); //delete the invalid char, aNumber changed
       
  1383            }
       
  1384        }
       
  1385   }
       
  1386 // End of File