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