phonebookui/Phonebook2/Commands/src/CPbk2AiwInterestItemCall.cpp
branchRCL_3
changeset 63 f4a778e096c2
child 64 c1e8ba0c2b16
child 68 9da50d567e3c
equal deleted inserted replaced
62:5b6f26637ad3 63:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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:  Phonebook 2 call AIW interest item.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2AiwInterestItemCall.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "CPbk2CallCmd.h"
       
    24 #include "CPbk2PrependCmd.h"
       
    25 #include "CPbk2PocCmd.h"
       
    26 #include <MPbk2Command.h>
       
    27 #include "MPbk2CommandFactory.h"
       
    28 #include "CPbk2CallTypeSelector.h"
       
    29 #include <MPbk2ContactUiControl.h>
       
    30 #include <Pbk2UIControls.rsg>
       
    31 #include <Pbk2Commands.rsg>
       
    32 #include <CPbk2FieldPropertyArray.h>
       
    33 #include <CPbk2AddressSelect.h>
       
    34 #include <TPbk2AddressSelectParams.h>
       
    35 #include <TPbk2StoreContactAnalyzer.h>
       
    36 #include <CPbk2PresentationContact.h>
       
    37 #include <CPbk2PresentationContactFieldCollection.h>
       
    38 #include <MPbk2ApplicationServices.h>
       
    39 #include <MPbk2AppUi.h>
       
    40 #include <CPbk2ApplicationServices.h>
       
    41 #include "cpbk2storestatechecker.h"
       
    42 #include <MPbk2AppUi.h>
       
    43 
       
    44 // Virtual Phonebook
       
    45 #include <CVPbkContactManager.h>
       
    46 #include <MVPbkStoreContact.h>
       
    47 #include <MVPbkContactLink.h>
       
    48 #include <MVPbkContactOperationBase.h>
       
    49 #include <VPbkFieldTypeSelectorFactory.h>
       
    50 #include <MVPbkContactOperationBase.h>
       
    51 #include <CVPbkContactLinkArray.h>
       
    52 #include <CVPbkxSPContacts.h>
       
    53 #include <CVPbkFieldTypeSelector.h>
       
    54 
       
    55 // System includes
       
    56 #include <AiwServiceHandler.h>
       
    57 #include <eikmenup.h>
       
    58 #include <eikenv.h>
       
    59 #include <featmgr.h>
       
    60 #include <spsettingsvoiputils.h>
       
    61 
       
    62 // Debugging headers
       
    63 #include <Pbk2Debug.h>
       
    64 
       
    65 /// Unnamed namespace for local definitions
       
    66 namespace {
       
    67 
       
    68 /**
       
    69  * Standard error handling.
       
    70  *
       
    71  * @param aError    Error code.
       
    72  */
       
    73 void HandleError( const TInt aError )
       
    74     {
       
    75     if (aError != KErrNone)
       
    76         {
       
    77         // Get UIKON environment
       
    78         CEikonEnv* eikEnv = CEikonEnv::Static();
       
    79         if (eikEnv)
       
    80             {
       
    81             // Display standard error message
       
    82             eikEnv->HandleError(aError);
       
    83             }
       
    84         }
       
    85     }
       
    86 
       
    87 #ifdef _DEBUG
       
    88 enum TPanicCode
       
    89     {
       
    90     EPanicLogic_DynInitMenuPaneL = 1,
       
    91     EPanicPreCond_ExecuteCommandL,
       
    92     EPanicLogic_UnknownState
       
    93     };
       
    94 
       
    95 void Panic(TPanicCode aReason)
       
    96     {
       
    97     _LIT( KPanicText, "CPbk2AiwInterestItemCall" );
       
    98     User::Panic( KPanicText, aReason );
       
    99     }
       
   100 #endif // _DEBUG
       
   101 
       
   102 /**
       
   103  * Copies a link array to another.
       
   104  *
       
   105  * @param aSourceLinkArray    Link array which is copied
       
   106  * @param aTargetLinkArray    Links are copied to this
       
   107  */
       
   108 void CopyContactLinksL( const MVPbkContactLinkArray& aSourceLinkArray,
       
   109         CVPbkContactLinkArray& aTargetLinkArray )
       
   110     {
       
   111     const TInt count = aSourceLinkArray.Count();
       
   112     for ( TInt i(0); i < count; ++i )
       
   113         {
       
   114         const MVPbkContactLink& contactLink = aSourceLinkArray.At(i);
       
   115         aTargetLinkArray.AppendL( contactLink.CloneLC() );
       
   116         CleanupStack::Pop(); // link
       
   117         }
       
   118     }
       
   119 
       
   120 
       
   121 } /// namespace
       
   122 
       
   123 // --------------------------------------------------------------------------
       
   124 // CPbk2AiwInterestItemCall::CPbk2AiwInterestItemCall
       
   125 // --------------------------------------------------------------------------
       
   126 //
       
   127 inline CPbk2AiwInterestItemCall::CPbk2AiwInterestItemCall
       
   128         ( TInt aInterestId, CAiwServiceHandler& aServiceHandler ) :
       
   129             CPbk2AiwInterestItemBase( aInterestId, aServiceHandler )
       
   130     {
       
   131     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   132         "CPbk2AiwInterestItemCall::CPbk2AiwInterestItemCall") );
       
   133     CActiveScheduler::Add( this );
       
   134     }
       
   135 
       
   136 // --------------------------------------------------------------------------
       
   137 // CPbk2AiwInterestItemCall::~CPbk2AiwInterestItemCall
       
   138 // --------------------------------------------------------------------------
       
   139 //
       
   140 CPbk2AiwInterestItemCall::~CPbk2AiwInterestItemCall()
       
   141     {
       
   142     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   143         "CPbk2AiwInterestItemCall::~CPbk2AiwInterestItemCall") );
       
   144     Cancel();
       
   145     FeatureManager::UnInitializeLib();
       
   146     delete iStoreStateChecker;
       
   147     delete iFocusedField;
       
   148     delete iContactLink;
       
   149     delete iStoreContact;
       
   150     delete iSelector;
       
   151     delete iRetriever;
       
   152     delete ixSPManager;
       
   153     delete ixSPContactLinksArray;
       
   154     ixSPStoreContactsArray.ResetAndDestroy();
       
   155     Release( iAppServices );    
       
   156     }
       
   157 
       
   158 // --------------------------------------------------------------------------
       
   159 // CPbk2AiwInterestItemCall::ConstructL
       
   160 // --------------------------------------------------------------------------
       
   161 //
       
   162 inline void CPbk2AiwInterestItemCall::ConstructL()
       
   163     {
       
   164     iAppServices = CPbk2ApplicationServices::InstanceL();
       
   165 
       
   166     iFieldPropertyArray = &iAppServices->FieldProperties();
       
   167     iSelector = CPbk2CallTypeSelector::NewL( iAppServices->ContactManager() );
       
   168     iAppUi = Phonebook2::Pbk2AppUi();
       
   169 
       
   170     FeatureManager::InitializeLibL();
       
   171     }
       
   172 
       
   173 // --------------------------------------------------------------------------
       
   174 // CPbk2AiwInterestItemCall::NewL
       
   175 // --------------------------------------------------------------------------
       
   176 //
       
   177 CPbk2AiwInterestItemCall* CPbk2AiwInterestItemCall::NewL
       
   178         ( TInt aInterestId, CAiwServiceHandler& aServiceHandler )
       
   179     {
       
   180     CPbk2AiwInterestItemCall* self = new ( ELeave ) CPbk2AiwInterestItemCall
       
   181         ( aInterestId, aServiceHandler );
       
   182     CleanupStack::PushL( self );
       
   183     self->ConstructL();
       
   184     CleanupStack::Pop( self );
       
   185     return self;
       
   186     }
       
   187 
       
   188 // --------------------------------------------------------------------------
       
   189 // CPbk2AiwInterestItemCall::DynInitMenuPaneL
       
   190 // --------------------------------------------------------------------------
       
   191 //
       
   192 TBool CPbk2AiwInterestItemCall::DynInitMenuPaneL
       
   193         ( const TInt aResourceId, CEikMenuPane& aMenuPane,
       
   194         const MPbk2ContactUiControl& aControl )
       
   195     {
       
   196     TBool ret = EFalse;
       
   197 
       
   198     // Normal menu
       
   199     if ( aResourceId == R_PHONEBOOK2_CALL_MENU || 
       
   200         aResourceId == R_PHONEBOOK2_STYLUS_CALL_MENU )
       
   201         {
       
   202         ret = ETrue;
       
   203         FilterCallMenuL( aResourceId, aMenuPane, aControl );
       
   204         }
       
   205 
       
   206     // Context menu
       
   207     else if (aResourceId == R_PHONEBOOK2_CALL_CONTEXT_MENU)
       
   208         {
       
   209         ret = ETrue;
       
   210         FilterContextMenuL( aResourceId, aMenuPane, aControl );
       
   211         }
       
   212 
       
   213     return ret;
       
   214     }
       
   215 
       
   216 // --------------------------------------------------------------------------
       
   217 // CPbk2AiwInterestItemCall::HandleCommandL
       
   218 // --------------------------------------------------------------------------
       
   219 //
       
   220 TBool CPbk2AiwInterestItemCall::HandleCommandL
       
   221         ( const TInt aMenuCommandId, MPbk2ContactUiControl& aControl,
       
   222           TInt aServiceCommandId )
       
   223     {
       
   224     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   225         "CPbk2AiwInterestItemCall::HandleCommandL(0x%x)"), aMenuCommandId );
       
   226 
       
   227     // Reset previous request if active
       
   228     Cancel();
       
   229 
       
   230     TBool ret = EFalse;
       
   231     // Only handle this command if service command is call,
       
   232     // note that this section is accessed also when the send key
       
   233     // is pressed and the initiated command object can then be POC
       
   234     // call also
       
   235     if ( aServiceCommandId == KAiwCmdCall )
       
   236         {
       
   237         ret = ETrue;
       
   238         iMenuCommandId = aMenuCommandId;
       
   239         iControl = &aControl;
       
   240 
       
   241         // Retrieve store contact if needed
       
   242         MVPbkStoreContact* storeContact = const_cast<MVPbkStoreContact*>
       
   243             ( aControl.FocusedStoreContact() );
       
   244         if ( !storeContact )
       
   245             {
       
   246             // No need to check store state, store always available
       
   247             // if cmd is invoked from nameslist
       
   248             IssueNextAction( ERetrieveStoreContact );
       
   249             }
       
   250         else
       
   251             {
       
   252             // Check store availability, callback invokes
       
   253             // call if store is available
       
   254             CPbk2StoreStateChecker* temp =  CPbk2StoreStateChecker::NewL
       
   255                 (  storeContact->ParentStore(), *this );
       
   256             delete iStoreStateChecker;
       
   257             iStoreStateChecker = temp;
       
   258             }
       
   259         }
       
   260 
       
   261     return ret;
       
   262     }
       
   263 
       
   264 // --------------------------------------------------------------------------
       
   265 // CPbk2AiwInterestItemCall::VPbkSingleContactOperationComplete
       
   266 // --------------------------------------------------------------------------
       
   267 //
       
   268 void CPbk2AiwInterestItemCall::VPbkSingleContactOperationComplete
       
   269         ( MVPbkContactOperationBase& aOperation,
       
   270           MVPbkStoreContact* aContact )
       
   271     {
       
   272     if ( &aOperation == iRetriever )
       
   273         {
       
   274         if ( iState == ERetrieveStoreContact )
       
   275             {
       
   276             delete iStoreContact;
       
   277             iStoreContact = aContact;
       
   278             
       
   279             // Start retieving xSP contacts
       
   280             TRAPD( err, FetchxSPLinksL() );
       
   281             if (err != KErrNone)
       
   282                 {
       
   283                 IssueNextAction( EExecuteCall );
       
   284                 }
       
   285             }
       
   286         
       
   287         // Retrieve one xSP contact at a time
       
   288 		// No batch implementation for retrieve contacts
       
   289         if ( iState == ERetrieveXSPContact )
       
   290             {
       
   291             // xSP contact retrieval complete. Store it.
       
   292             TInt err = ixSPStoreContactsArray.Append( aContact );
       
   293             
       
   294             // Start retrieving next xSP contact links if any left
       
   295             if ( ixSPContactLinksArray->Count() > 0 && err == KErrNone )
       
   296                 {
       
   297                 IssueNextAction( ERetrieveXSPContact );
       
   298                 }
       
   299             // If none, or if error execute the call.
       
   300             else
       
   301                 {
       
   302                 IssueNextAction( EExecuteCall );
       
   303                 }            
       
   304             }
       
   305         }
       
   306     }
       
   307 
       
   308 // --------------------------------------------------------------------------
       
   309 // CPbk2AiwInterestItemCall::VPbkSingleContactOperationFailed
       
   310 // --------------------------------------------------------------------------
       
   311 //
       
   312 void CPbk2AiwInterestItemCall::VPbkSingleContactOperationFailed
       
   313     ( MVPbkContactOperationBase& aOperation, TInt aError )
       
   314     {
       
   315     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   316         "CPbk2AiwInterestItemCall::VPbkSingleContactOperationFailed(%d)"), aError );
       
   317     if ( &aOperation == iRetriever )
       
   318         {
       
   319         HandleError( aError );
       
   320         }
       
   321     }
       
   322 
       
   323 
       
   324 // --------------------------------------------------------------------------
       
   325 // CPbk2AiwInterestItemCall::StoreState
       
   326 // --------------------------------------------------------------------------
       
   327 //
       
   328 void CPbk2AiwInterestItemCall::StoreState
       
   329         ( MPbk2StoreStateCheckerObserver::TState aState )
       
   330     {
       
   331     if ( aState == MPbk2StoreStateCheckerObserver::EStoreAvailable )
       
   332         {
       
   333         IssueNextAction( EExecuteCall );
       
   334         }
       
   335     else
       
   336         {
       
   337         IssueNextAction( EShowUnavailableNote );
       
   338         }
       
   339     }
       
   340 
       
   341 // --------------------------------------------------------------------------
       
   342 // CPbk2AiwInterestItemCall::DoCancel
       
   343 // --------------------------------------------------------------------------
       
   344 //
       
   345 void CPbk2AiwInterestItemCall::DoCancel()
       
   346     {
       
   347     delete iContactLink;
       
   348     iContactLink = NULL;
       
   349     delete iRetriever;
       
   350     iRetriever = NULL;
       
   351 	ixSPStoreContactsArray.ResetAndDestroy();
       
   352     }
       
   353 
       
   354 // --------------------------------------------------------------------------
       
   355 // CPbk2AiwInterestItemCall::RunL
       
   356 // --------------------------------------------------------------------------
       
   357 //
       
   358 void CPbk2AiwInterestItemCall::RunL()
       
   359     {
       
   360     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   361         "CPbk2AiwInterestItemCall::RunL(%d)"), iState );
       
   362 
       
   363     switch ( iState )
       
   364         {
       
   365         case ERetrieveStoreContact:
       
   366             {
       
   367             RetrieveContactL();
       
   368             break;
       
   369             }
       
   370         case ERetrieveXSPContact:
       
   371             {
       
   372             RetrieveContactL();
       
   373             break;
       
   374             }
       
   375         case EExecuteCall:
       
   376             {
       
   377             MVPbkStoreContact* storeContact = const_cast<MVPbkStoreContact*>
       
   378                 ( iControl->FocusedStoreContact() );
       
   379             if ( !storeContact )
       
   380                 {
       
   381                 storeContact = iStoreContact;
       
   382                 }
       
   383             ExecuteCommandL( storeContact );
       
   384             break;
       
   385             }
       
   386         case EShowUnavailableNote:
       
   387             {
       
   388             if ( iStoreStateChecker )
       
   389                 {
       
   390                 iStoreStateChecker->ShowUnavailableNoteL();
       
   391                 }
       
   392             break;
       
   393             }
       
   394         default:
       
   395             {
       
   396             __ASSERT_DEBUG( EFalse, Panic( EPanicLogic_UnknownState ) );
       
   397             break;
       
   398             }
       
   399         }
       
   400     }
       
   401 
       
   402 // --------------------------------------------------------------------------
       
   403 // CPbk2AiwInterestItemCall::RunError
       
   404 // --------------------------------------------------------------------------
       
   405 //
       
   406 TInt CPbk2AiwInterestItemCall::RunError( TInt aError )
       
   407     {
       
   408     PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING(
       
   409         "CPbk2AiwInterestItemCall::RunError(%d)"), aError );
       
   410 
       
   411     HandleError( aError );
       
   412     return KErrNone;
       
   413     }
       
   414 
       
   415 // --------------------------------------------------------------------------
       
   416 // CPbk2AiwInterestItemCall::ExecuteCommandL
       
   417 // --------------------------------------------------------------------------
       
   418 //
       
   419 void CPbk2AiwInterestItemCall::ExecuteCommandL
       
   420         ( MVPbkStoreContact*& aStoreContact )
       
   421     {
       
   422     __ASSERT_DEBUG(iControl, Panic( EPanicPreCond_ExecuteCommandL ) );
       
   423 
       
   424     MPbk2Command* cmd = NULL;
       
   425     TBool launchTelephonyCall = ETrue;
       
   426 
       
   427     // Because send key is used also to launch POC calls
       
   428     // we have to verify what was the selection and is
       
   429     // it ok to launch a telephony call.
       
   430     // If command id is EPbk2CmdCall, then the call was launched
       
   431     // with the send key.
       
   432     if ( iMenuCommandId == EPbk2CmdCall )
       
   433         {
       
   434         TInt focusedFieldIndex = iControl->FocusedFieldIndex();
       
   435         if ( focusedFieldIndex != KErrNotFound )
       
   436             {
       
   437             MVPbkStoreContactField* focusedField =
       
   438                 FocusedFieldLC( *aStoreContact, focusedFieldIndex );
       
   439 
       
   440             launchTelephonyCall = iSelector->OkToLaunchTelephonyCallL
       
   441                 ( focusedField );
       
   442 
       
   443             CleanupStack::PopAndDestroy(); // focusedField
       
   444             }
       
   445         }
       
   446     else if (iMenuCommandId == EPbk2CmdPrepend)
       
   447         {
       
   448         cmd = CreatePrependCmdObjectL(
       
   449                 iMenuCommandId, *iControl, aStoreContact );
       
   450         }
       
   451 
       
   452 
       
   453     if ( !cmd )
       
   454         {
       
   455         if ( launchTelephonyCall )
       
   456             {
       
   457             cmd = CreateCallCmdObjectL
       
   458                 ( iMenuCommandId, *iControl, aStoreContact );
       
   459             }
       
   460         else
       
   461             {
       
   462             cmd = CreatePocCmdObjectL
       
   463                 ( iMenuCommandId, *iControl, *aStoreContact, NULL );
       
   464             }
       
   465         }
       
   466 
       
   467     if (cmd)
       
   468         {
       
   469         // Execute the command
       
   470         cmd->ExecuteLD();
       
   471         }
       
   472     }
       
   473 
       
   474 // --------------------------------------------------------------------------
       
   475 // CPbk2AiwInterestItemCall::CreateCallCmdObjectL
       
   476 // --------------------------------------------------------------------------
       
   477 //
       
   478 MPbk2Command* CPbk2AiwInterestItemCall::CreateCallCmdObjectL
       
   479         ( const TInt aMenuCommandId, MPbk2ContactUiControl& aControl,
       
   480         MVPbkStoreContact*& aStoreContact )
       
   481     {
       
   482     // We need a bunch of pre-initialized variables
       
   483     MPbk2Command* cmd = NULL;
       
   484     MVPbkStoreContactField* selectedField = NULL;
       
   485     TBool okToLaunchTelephonyCall = ETrue;
       
   486     TBool selectAccepted = ETrue;
       
   487     VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector action
       
   488         ( VPbkFieldTypeSelectorFactory::EEmptySelector );
       
   489 
       
   490     AssignFocusedFieldL( aControl, *aStoreContact );
       
   491 
       
   492     if ( aMenuCommandId == EPbk2CmdCall )
       
   493         {
       
   494         // Call launched with send key, an address select needs
       
   495         // to be constructed
       
   496         TResourceReader resReader;        
       
   497         
       
   498         TInt resourceId = R_PBK2_SEND_KEY_ADDRESS_SELECT;
       
   499         if( FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) )
       
   500         	{
       
   501         	resourceId = R_PBK2_SEND_KEY_ADDRESS_SELECT_VOIP;
       
   502         	}
       
   503         
       
   504         CCoeEnv::Static()->CreateResourceReaderLC
       
   505             ( resReader, resourceId );
       
   506 
       
   507         TPbk2AddressSelectParams params(
       
   508             *aStoreContact,
       
   509             iAppUi->ApplicationServices().ContactManager(),
       
   510             iAppUi->ApplicationServices().NameFormatter(),
       
   511             *iFieldPropertyArray,
       
   512             resReader,
       
   513             R_QTN_PHOB_QTL_CALL_TO_NAME );
       
   514         
       
   515         RVPbkContactFieldDefaultPriorities defaultPrioritiesArray;
       
   516         CVPbkFieldTypeSelector* actionTypeSelector = NULL;
       
   517         CSPSettingsVoIPUtils* sPSettings = CSPSettingsVoIPUtils::NewLC();
       
   518         
       
   519         // IsVoIPSupported() is used for checking whether the platfrom supports VOIP.
       
   520         // If the service has been defined, then the specific call should be shown.
       
   521         // If the platform supports VOIP and its address has been defined.
       
   522         // Then, internet calls and voip calls can be made.
       
   523         if ( sPSettings->IsVoIPSupported() && sPSettings->VoIPProfilesExistL() )
       
   524             {
       
   525             action = VPbkFieldTypeSelectorFactory::EVOIPCallSelector;
       
   526             actionTypeSelector = VPbkFieldTypeSelectorFactory::BuildContactActionTypeSelectorL(
       
   527                     VPbkFieldTypeSelectorFactory::EVOIPCallSelector,
       
   528                     iAppUi->ApplicationServices().ContactManager().FieldTypes());
       
   529             
       
   530             CleanupStack::PushL( actionTypeSelector );
       
   531             }
       
   532         // Normal voice calls
       
   533 		else
       
   534             {
       
   535             action = VPbkFieldTypeSelectorFactory::EVoiceCallSelector;
       
   536                         actionTypeSelector = VPbkFieldTypeSelectorFactory::BuildContactActionTypeSelectorL(
       
   537                     VPbkFieldTypeSelectorFactory::EVoiceCallSelector,
       
   538                     iAppUi->ApplicationServices().ContactManager().FieldTypes());
       
   539             
       
   540             CleanupStack::PushL( actionTypeSelector );
       
   541             }
       
   542         
       
   543         // Set default according to priority rule
       
   544         iSelector->SetDefaultPrioritiesLC
       
   545 		            ( defaultPrioritiesArray,
       
   546 		              *aStoreContact );
       
   547 
       
   548         
       
   549         params.iCommMethod = action;
       
   550         params.SetDefaultPriorities( defaultPrioritiesArray );
       
   551 
       
   552         if ( iFocusedField )
       
   553             {
       
   554             params.SetFocusedField( iFocusedField );
       
   555             // If we have field focused we don't launch call directly using
       
   556             // default number. The number selection dialog should be shown.
       
   557             params.SetUseDefaultDirectly( EFalse );
       
   558             }
       
   559         else
       
   560             {
       
   561             // Launch call directly using default values.
       
   562             params.SetUseDefaultDirectly( ETrue );
       
   563             }
       
   564         
       
   565         // Run address select
       
   566         CPbk2AddressSelect* addressSelect = CPbk2AddressSelect::NewL(
       
   567                 params,
       
   568                 *actionTypeSelector,
       
   569                 &ixSPStoreContactsArray.Array(),
       
   570                 NULL );
       
   571 
       
   572         selectedField = addressSelect->ExecuteLD();
       
   573         
       
   574         CleanupStack::PopAndDestroy( 4 ); // defaultPrioritiesArray, resReader, sPSettings, actionTypeSelector
       
   575 
       
   576         // Focused field used already in AddressSelect params and the
       
   577         // correct field is in selectedField variable.
       
   578         delete iFocusedField;
       
   579         iFocusedField = NULL;
       
   580 
       
   581         if( selectedField )
       
   582             {
       
   583             CleanupDeletePushL( selectedField );
       
   584             // Because send key is used also to launch POC calls
       
   585             // we have to verify what was the selection and is
       
   586             // it ok to launch a telephony call
       
   587             okToLaunchTelephonyCall = iSelector->OkToLaunchTelephonyCallL
       
   588                 ( selectedField );
       
   589             CleanupStack::Pop( selectedField );
       
   590             }
       
   591         else
       
   592             {
       
   593             selectAccepted = EFalse;
       
   594             }
       
   595         }
       
   596 
       
   597     if( selectAccepted )
       
   598         {
       
   599         if( okToLaunchTelephonyCall )
       
   600             {
       
   601             if ( iFocusedField && !selectedField )
       
   602                 {
       
   603                 // If field is focused it should be delivered to call command.
       
   604                 // The command object takes ownership of selectedField.
       
   605                 selectedField = iFocusedField;
       
   606                 iFocusedField = NULL;
       
   607                 }
       
   608 
       
   609             CleanupDeletePushL( selectedField );
       
   610             // Select was either accepted, or we are calling from
       
   611             // CallUI menus. In the latter case, the address select
       
   612             // will be shown later. Next, create the call command object.
       
   613             // Takes ownership of selectedField.
       
   614             cmd = CPbk2CallCmd::NewL( aStoreContact, selectedField,
       
   615                 aControl, aMenuCommandId, iServiceHandler, 
       
   616                 *iSelector, action );
       
   617             CleanupStack::Pop( selectedField );
       
   618             }
       
   619         else
       
   620             {
       
   621             // Select was accepted, but the selection indicates
       
   622             // we have to create a POC call
       
   623             cmd = CreatePocCmdObjectL( aMenuCommandId, aControl,
       
   624                 *aStoreContact, selectedField );
       
   625             }
       
   626         }
       
   627 
       
   628     return cmd;
       
   629     }
       
   630 
       
   631 // --------------------------------------------------------------------------
       
   632 // CPbk2AiwInterestItemCall::CreatePocCmdObjectL
       
   633 // --------------------------------------------------------------------------
       
   634 //
       
   635 MPbk2Command* CPbk2AiwInterestItemCall::CreatePocCmdObjectL
       
   636         (  const TInt aMenuCommandId,
       
   637            MPbk2ContactUiControl& aControl,
       
   638            MVPbkStoreContact& aStoreContact,
       
   639            MVPbkStoreContactField* aStoreContactField  )
       
   640     {
       
   641     MPbk2Command* cmd = NULL;
       
   642     MVPbkStoreContactField* field = aStoreContactField;
       
   643 
       
   644     if ( !field )
       
   645         {
       
   646         AssignFocusedFieldL( aControl, aStoreContact );
       
   647         field = iFocusedField;
       
   648         iFocusedField = NULL; // ownership was taken
       
   649         }
       
   650 
       
   651     CleanupDeletePushL( field );
       
   652     cmd = CPbk2PocCmd::NewL( aMenuCommandId, iServiceHandler,
       
   653         *iSelector, aControl, aStoreContact, field );
       
   654     CleanupStack::Pop( field );
       
   655 
       
   656     return cmd;
       
   657     }
       
   658 
       
   659 // --------------------------------------------------------------------------
       
   660 // CPbk2AiwInterestItemCall::CreatePrependCmdObjectL
       
   661 // --------------------------------------------------------------------------
       
   662 //
       
   663 MPbk2Command* CPbk2AiwInterestItemCall::CreatePrependCmdObjectL
       
   664         ( const TInt aMenuCommandId,
       
   665           MPbk2ContactUiControl& aControl, MVPbkStoreContact*& aStoreContact )
       
   666     {
       
   667     return CPbk2PrependCmd::NewL(
       
   668         aMenuCommandId,
       
   669         aControl,
       
   670         iServiceHandler,
       
   671         *iSelector,
       
   672         aStoreContact,
       
   673         *iFieldPropertyArray);
       
   674     }
       
   675 
       
   676 // --------------------------------------------------------------------------
       
   677 // CPbk2AiwInterestItemCall::RetrieveContactL
       
   678 // --------------------------------------------------------------------------
       
   679 //
       
   680 void CPbk2AiwInterestItemCall::RetrieveContactL()
       
   681     {
       
   682     if ( iState == ERetrieveStoreContact )
       
   683         {
       
   684         delete iContactLink;
       
   685         iContactLink = NULL;
       
   686         
       
   687         if( !iControl )
       
   688             {
       
   689             return;
       
   690             }
       
   691         
       
   692         const MVPbkBaseContact* focusedContact = iControl->FocusedContactL();
       
   693         
       
   694         if( !focusedContact )
       
   695             {
       
   696             User::Leave( KErrNotFound );
       
   697             }
       
   698         
       
   699         iContactLink = focusedContact->CreateLinkLC();
       
   700         CleanupStack::Pop(); // iContactLink
       
   701         
       
   702         delete iRetriever;
       
   703         iRetriever = NULL;
       
   704         iRetriever = iAppUi->ApplicationServices().
       
   705             ContactManager().RetrieveContactL( *iContactLink, *this );
       
   706         }
       
   707     
       
   708     if ( iState == ERetrieveXSPContact )
       
   709         {
       
   710         delete iRetriever;
       
   711         iRetriever = NULL;
       
   712         iRetriever = iAppUi->ApplicationServices().ContactManager().
       
   713             RetrieveContactL( ixSPContactLinksArray->At( 0 ), *this );
       
   714         ixSPContactLinksArray->Delete( 0 );
       
   715         }
       
   716     }
       
   717 
       
   718 // --------------------------------------------------------------------------
       
   719 // CPbk2AiwInterestItemCall::IssueNextAction
       
   720 // --------------------------------------------------------------------------
       
   721 //
       
   722 void CPbk2AiwInterestItemCall::IssueNextAction( TNextAction aState )
       
   723     {
       
   724     if ( !IsActive() )
       
   725         {
       
   726         iState = aState;
       
   727         TRequestStatus* status = &iStatus;
       
   728         User::RequestComplete(status, KErrNone);
       
   729         SetActive();
       
   730         }
       
   731     }
       
   732 
       
   733 // --------------------------------------------------------------------------
       
   734 // CPbk2AiwInterestItemCall::FocusedFieldLC
       
   735 // --------------------------------------------------------------------------
       
   736 //
       
   737 MVPbkStoreContactField* CPbk2AiwInterestItemCall::FocusedFieldLC
       
   738         ( MVPbkStoreContact& aStoreContact, TInt aFocusedFieldIndex )
       
   739     {
       
   740     TInt index( KErrNotFound );
       
   741     MVPbkStoreContactField* ret = NULL;
       
   742 
       
   743     CPbk2PresentationContact* presentationContact =
       
   744         CPbk2PresentationContact::NewL
       
   745             ( aStoreContact, *iFieldPropertyArray );
       
   746     CleanupStack::PushL( presentationContact );
       
   747 
       
   748     index = presentationContact->PresentationFields().StoreIndexOfField
       
   749         ( aFocusedFieldIndex );
       
   750 
       
   751     CleanupStack::PopAndDestroy( presentationContact );
       
   752 
       
   753     if ( index != KErrNotFound )
       
   754         {
       
   755         // Use FieldAtLC to avoid the unvalidity of the field
       
   756         // after new FieldAt call
       
   757         ret = aStoreContact.Fields().FieldAtLC( index );
       
   758         }
       
   759 
       
   760     return ret;
       
   761     }
       
   762 
       
   763 // --------------------------------------------------------------------------
       
   764 // CPbk2AiwInterestItemCall::AssignFocusedFieldL
       
   765 // --------------------------------------------------------------------------
       
   766 //
       
   767 inline void CPbk2AiwInterestItemCall::AssignFocusedFieldL
       
   768         ( MPbk2ContactUiControl& aControl,
       
   769           MVPbkStoreContact& aStoreContact )
       
   770     {
       
   771     TInt focusedFieldIndex = aControl.FocusedFieldIndex();
       
   772 
       
   773     delete iFocusedField;
       
   774     iFocusedField = NULL;
       
   775     if ( focusedFieldIndex != KErrNotFound )
       
   776         {
       
   777         iFocusedField =
       
   778             FocusedFieldLC( aStoreContact, focusedFieldIndex );
       
   779         CleanupStack::Pop(); // iFocusedField
       
   780         }
       
   781     }
       
   782 
       
   783 
       
   784 // --------------------------------------------------------------------------
       
   785 // CPbk2AiwInterestItemCall::VideoCallMenuVisibilityL
       
   786 // --------------------------------------------------------------------------
       
   787 //
       
   788 void CPbk2AiwInterestItemCall::VideoCallMenuVisibilityL
       
   789         ( CEikMenuPane& aMenuPane ) const
       
   790     {
       
   791     if ( FeatureManager::FeatureSupported
       
   792             ( KFeatureIdVideocallMenuVisibility ) )
       
   793         {
       
   794         TInt index = KErrNotFound;
       
   795         if ( aMenuPane.MenuItemExists( KAiwCmdCall, index ) &&
       
   796              index != KErrNotFound )
       
   797             {
       
   798             CEikMenuPaneItem::SData& itemData =
       
   799                 aMenuPane.ItemDataByIndexL( index );
       
   800             const TInt KDisableCascade = 0;
       
   801             itemData.iCascadeId = KDisableCascade;  // disable cascade menu
       
   802             }
       
   803         }
       
   804     }
       
   805 
       
   806 // --------------------------------------------------------------------------
       
   807 // CPbk2AiwInterestItemCall::FilterCallMenuL
       
   808 // Call menu filtering is done in the following situations:
       
   809 // 1. Contact info view: based on the currently selected (focused) field
       
   810 // 2. Names list: the list is empty
       
   811 // 3. Names list: contact(s) selected (marked)
       
   812 // --------------------------------------------------------------------------
       
   813 //
       
   814 void CPbk2AiwInterestItemCall::FilterCallMenuL
       
   815         ( const TInt aResourceId, CEikMenuPane& aMenuPane,
       
   816         const MPbk2ContactUiControl& aControl )
       
   817     {
       
   818     // Get empty parameter list
       
   819     CAiwGenericParamList& paramList =
       
   820         iServiceHandler.InParamListL();
       
   821     const MVPbkStoreContact* storeContact =
       
   822         aControl.FocusedStoreContact();
       
   823 
       
   824     // Store contact is not available if we are not in contact info view
       
   825     if ( storeContact )
       
   826         {
       
   827         TPbk2StoreContactAnalyzer analyzer
       
   828           ( iAppUi->ApplicationServices().
       
   829                 ContactManager(), storeContact );
       
   830 
       
   831         // Hide voice call options if an SIP field is focused
       
   832         const MVPbkBaseContactField* field = aControl.FocusedField();
       
   833         if( field && analyzer.IsFieldTypeIncludedL
       
   834              ( *field, R_PHONEBOOK2_SIP_SELECTOR ) &&
       
   835                  FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) )
       
   836             {
       
   837             TAiwVariant variant;
       
   838             TAiwGenericParam param
       
   839                 ( EGenericParamSIPAddress, variant );
       
   840             paramList.AppendL( param );
       
   841             }
       
   842         }
       
   843 
       
   844     // Check that the list is not empty and does not have marked items
       
   845     if ( aControl.NumberOfContacts() > 0 && !aControl.ContactsMarked() )
       
   846         {
       
   847         // Check item placement
       
   848         VideoCallMenuVisibilityL( aMenuPane );
       
   849 
       
   850         // Let provider add its menu items to the menu
       
   851         iServiceHandler.InitializeMenuPaneL(
       
   852             aMenuPane,
       
   853             aResourceId,
       
   854             EPbk2CmdLast,
       
   855             paramList);
       
   856         }
       
   857     // The list is empty or it has marked items -> hide call option
       
   858     else
       
   859         {
       
   860         aMenuPane.SetItemDimmed( KAiwCmdCall, ETrue );
       
   861         }
       
   862     }
       
   863 
       
   864 // --------------------------------------------------------------------------
       
   865 // CPbk2AiwInterestItemCall::FilterContextMenuL
       
   866 // --------------------------------------------------------------------------
       
   867 //
       
   868 void CPbk2AiwInterestItemCall::FilterContextMenuL
       
   869         ( const TInt aResourceId, CEikMenuPane& aMenuPane,
       
   870         const MPbk2ContactUiControl& aControl )
       
   871     {
       
   872     // Hide the item by default
       
   873     aMenuPane.SetItemDimmed( KAiwCmdCall, ETrue );
       
   874 
       
   875     // Get empty parameter list
       
   876     CAiwGenericParamList& paramList =
       
   877         iServiceHandler.InParamListL();
       
   878 
       
   879     if ( aControl.NumberOfContactFields() > 0 )
       
   880         {
       
   881         // Get the focused field
       
   882         const MVPbkBaseContactField* field =
       
   883             aControl.FocusedField();
       
   884         if ( field )
       
   885             {
       
   886             TPbk2StoreContactAnalyzer analyzer
       
   887                 ( iAppUi->ApplicationServices().
       
   888                   ContactManager(), NULL );
       
   889 
       
   890             if ( analyzer.IsFieldTypeIncludedL
       
   891                     ( *field, R_PHONEBOOK2_PHONENUMBER_SELECTOR ) )
       
   892                 {
       
   893                 aMenuPane.SetItemDimmed( KAiwCmdCall, EFalse );
       
   894                 VideoCallMenuVisibilityL( aMenuPane );
       
   895                 }
       
   896 
       
   897             // Next further investigate the field, is it a VoIP field
       
   898             if( analyzer.IsFieldTypeIncludedL
       
   899                 ( *field, R_PHONEBOOK2_SIP_SELECTOR ) &&
       
   900                  FeatureManager::FeatureSupported( KFeatureIdCommonVoip ) )
       
   901                 {
       
   902                 aMenuPane.SetItemDimmed( KAiwCmdCall, EFalse );
       
   903                 VideoCallMenuVisibilityL( aMenuPane );
       
   904 
       
   905                 // When we are on a Internet telephony field,
       
   906                 // the Call UI must show only the VoIP option
       
   907                 TAiwVariant variant;
       
   908                 TAiwGenericParam param
       
   909                     ( EGenericParamSIPAddress, variant );
       
   910                 paramList.AppendL( param );
       
   911                 }
       
   912 
       
   913             // Let provider add its menu items to the menu
       
   914             iServiceHandler.InitializeMenuPaneL
       
   915                 ( aMenuPane, aResourceId, EPbk2CmdLast, paramList );
       
   916             }
       
   917         }
       
   918     }
       
   919 
       
   920 // --------------------------------------------------------------------------
       
   921 // CPbk2AiwInterestItemCall::FetchxSPLinksL
       
   922 // --------------------------------------------------------------------------
       
   923 //
       
   924 void CPbk2AiwInterestItemCall::FetchxSPLinksL()
       
   925     {
       
   926     ixSPManager = CVPbkxSPContacts::NewL( iAppUi->ApplicationServices().ContactManager() );                                                              
       
   927     delete iRetriever;
       
   928     iRetriever = NULL;
       
   929     iRetriever = ixSPManager->GetxSPContactLinksL( *iStoreContact, *this, *this);
       
   930     }
       
   931 
       
   932 // --------------------------------------------------------------------------
       
   933 // CPbk2AiwInterestItemCall::VPbkOperationFailed
       
   934 // --------------------------------------------------------------------------
       
   935 //
       
   936 void CPbk2AiwInterestItemCall::VPbkOperationFailed(
       
   937                 MVPbkContactOperationBase* /*aOperation*/,
       
   938                 TInt aError )
       
   939     {
       
   940     // Ignore, xSP info can be omitted. Just run address select dialog
       
   941     HandleError( aError );
       
   942     IssueNextAction( EExecuteCall );
       
   943     }
       
   944 
       
   945 // --------------------------------------------------------------------------
       
   946 // CPbk2AiwInterestItemCall::VPbkOperationResultCompleted
       
   947 // --------------------------------------------------------------------------
       
   948 //
       
   949 void CPbk2AiwInterestItemCall::VPbkOperationResultCompleted(
       
   950                 MVPbkContactOperationBase* /*aOperation*/,
       
   951                 MVPbkContactLinkArray* aArray )
       
   952     {
       
   953     // Count is the number of contact links fetched
       
   954     TInt count = aArray != NULL ? aArray->Count() : 0;
       
   955     if ( count > 0 )
       
   956         {
       
   957         TRAPD( err,
       
   958             // Take an own copy of supplied contact links
       
   959             ixSPContactLinksArray = CVPbkContactLinkArray::NewL();
       
   960             CopyContactLinksL( *aArray, *ixSPContactLinksArray );
       
   961             );
       
   962         // If there was an, launch the call
       
   963         if ( err != KErrNone )
       
   964             {
       
   965             HandleError( err );
       
   966             IssueNextAction( EExecuteCall );
       
   967             }
       
   968         else
       
   969             {
       
   970             // Start fetching xSP contacts
       
   971             IssueNextAction( ERetrieveXSPContact );
       
   972             }
       
   973         }
       
   974     // If there are no contact links, launch call
       
   975     else
       
   976         {
       
   977         IssueNextAction( EExecuteCall );
       
   978         }
       
   979     }
       
   980 
       
   981 // End of File