emailuis/emailui/src/FreestyleEmailUiContactHandler.cpp
branchRCL_3
changeset 8 e1b6206813b4
parent 2 5253a20d2a1e
child 10 f5907b1a1053
equal deleted inserted replaced
4:e7aa27f58ae1 8:e1b6206813b4
    33 #include <VPbkEng.rsg>
    33 #include <VPbkEng.rsg>
    34 #include <CVPbkContactFieldIterator.h>
    34 #include <CVPbkContactFieldIterator.h>
    35 #include <MVPbkContactFieldTextData.h>
    35 #include <MVPbkContactFieldTextData.h>
    36 #include <MVPbkContactStoreList.h>
    36 #include <MVPbkContactStoreList.h>
    37 
    37 
       
    38 // CCA Launcher view
       
    39 #include <mccaparameter.h>
       
    40 #include <ccafactory.h>
       
    41 #include <ccapbkcontextlauncher.h>
       
    42 
    38 
    43 
    39 // Phonebook 2
    44 // Phonebook 2
    40 #include <CPbk2SortOrderManager.h>
    45 #include <CPbk2SortOrderManager.h>
    41 #include <MPbk2ContactNameFormatter.h>
    46 #include <MPbk2ContactNameFormatter.h>
    42 #include <Pbk2ContactNameFormatterFactory.h>        
    47 #include <Pbk2ContactNameFormatterFactory.h>        
    43 #include <Pbk2ViewId.hrh>
       
    44 #include <CPbk2ViewState.h>
       
    45 
    48 
    46 // Send UI
    49 // Send UI
    47 #include <sendui.h>
    50 #include <sendui.h>
    48 #include <SendUiConsts.h>
    51 #include <SendUiConsts.h>
    49 #include <CMessageData.h>
    52 #include <CMessageData.h>
    68 #include <AiwContactAssignDataTypes.h>
    71 #include <AiwContactAssignDataTypes.h>
    69 #include <AiwContactSelectionDataTypes.h>
    72 #include <AiwContactSelectionDataTypes.h>
    70 #include <AiwServiceHandler.h>
    73 #include <AiwServiceHandler.h>
    71 
    74 
    72 // FS Email framework
    75 // FS Email framework
    73 #include "CFSMailBox.h"
    76 #include "cfsmailbox.h"
    74 //</cmail>
    77 //</cmail>
    75 
    78 
    76 #include <FreestyleEmailUi.rsg>
    79 #include <FreestyleEmailUi.rsg>
    77 
    80 
    78 #include "FreestyleEmailUiContactHandler.h"
    81 #include "FreestyleEmailUiContactHandler.h"
   104     }
   107     }
   105 
   108 
   106 CFSEmailUiContactHandler::~CFSEmailUiContactHandler()
   109 CFSEmailUiContactHandler::~CFSEmailUiContactHandler()
   107     {
   110     {
   108     FUNC_LOG;
   111     FUNC_LOG;
   109 	delete iContactForMsgCreation;
   112     delete iContactForMsgCreation;
   110 	if (iPersistentSetting)
   113     if (iPersistentSetting)
   111         {
   114         {
   112         iPersistentSetting->Close();
   115         iPersistentSetting->Close();
   113         delete iPersistentSetting;
   116         delete iPersistentSetting;
   114         }          
   117         }          
   115     delete iClsListHandler;
   118     delete iClsListHandler;
   126     delete iLinksSet;
   129     delete iLinksSet;
   127     delete iLinkOperation;
   130     delete iLinkOperation;
   128     delete iLinkOperationFetch;
   131     delete iLinkOperationFetch;
   129     delete iCurrentLink;
   132     delete iCurrentLink;
   130     delete iLastClsItem;
   133     delete iLastClsItem;
       
   134     
       
   135     if ( iConnection )
       
   136         {
       
   137         iConnection->Close();
       
   138         }
   131     }
   139     }
   132 
   140 
   133 // -----------------------------------------------------------------------------
   141 // -----------------------------------------------------------------------------
   134 // CFSEmailUiContactHandler::AddToContactL
   142 // CFSEmailUiContactHandler::AddToContactL
   135 // -----------------------------------------------------------------------------
   143 // -----------------------------------------------------------------------------
   138                                                     TAddToContactsType aAddToContactsType,
   146                                                     TAddToContactsType aAddToContactsType,
   139                                                     MFSEmailUiContactHandlerObserver* aObserver )
   147                                                     MFSEmailUiContactHandlerObserver* aObserver )
   140     {
   148     {
   141     FUNC_LOG;
   149     FUNC_LOG;
   142     if ( iState == EContactHandlerIdle ) //Check that there are no other request on going
   150     if ( iState == EContactHandlerIdle ) //Check that there are no other request on going
   143     	{
   151         {
   144     	iState = EContactHandlerAddToContacts;
   152         iState = EContactHandlerAddToContacts;
   145     	iHandlerObserver = aObserver; //Can be null
   153         iHandlerObserver = aObserver; //Can be null
   146     	TUint assignFlags = 0;
   154         TUint assignFlags = 0;
   147     	if ( aAddToContactsType == EContactHandlerCreateNewContact )
   155         if ( aAddToContactsType == EContactHandlerCreateNewContact )
   148     		{
   156             {
   149     		// In case of EUpdateExisting, we don't have to do anything as default is updateexisting
   157             // In case of EUpdateExisting, we don't have to do anything as default is updateexisting
   150     		assignFlags = AiwContactAssign::ECreateNewContact;
   158             assignFlags = AiwContactAssign::ECreateNewContact;
   151     		}
   159             }
   152 
   160 
   153     	CAiwGenericParamList& inParamList =
   161         CAiwGenericParamList& inParamList =
   154     	iServiceHandler->InParamListL();
   162         iServiceHandler->InParamListL();
   155 
   163 
   156     	inParamList.AppendL(
   164         inParamList.AppendL(
   157     			TAiwGenericParam(
   165                 TAiwGenericParam(
   158     					EGenericParamContactAssignData,
   166                         EGenericParamContactAssignData,
   159     					TAiwVariant(AiwContactAssign::TAiwSingleContactAssignDataV1Pckg(
   167                         TAiwVariant(AiwContactAssign::TAiwSingleContactAssignDataV1Pckg(
   160     							AiwContactAssign::TAiwSingleContactAssignDataV1().SetFlags(assignFlags)))));
   168                                 AiwContactAssign::TAiwSingleContactAssignDataV1().SetFlags(assignFlags)))));
   161     	
   169         
   162     	TGenericParamIdValue updateType;
   170         TGenericParamIdValue updateType;
   163     	if ( aUpdateType == EContactUpdateEmail )
   171         if ( aUpdateType == EContactUpdateEmail )
   164     		{
   172             {
   165     		updateType = EGenericParamEmailAddress;
   173             updateType = EGenericParamEmailAddress;
   166     		}
   174             }
   167     	else // EContactUpdateNumber
   175         else // EContactUpdateNumber
   168     		{
   176             {
   169     		updateType = EGenericParamPhoneNumber;
   177             updateType = EGenericParamPhoneNumber;
   170     		}
   178             }
   171     	
   179         
   172     	inParamList.AppendL(
   180         inParamList.AppendL(
   173     			TAiwGenericParam(
   181                 TAiwGenericParam(
   174     					updateType,
   182                         updateType,
   175     					TAiwVariant(aDes)
   183                         TAiwVariant(aDes)
   176     			));
   184                 ));
   177 
   185 
   178     	//Async call, CallBack is HandleNotify
   186         //Async call, CallBack is HandleNotify
   179     	iServiceHandler->ExecuteServiceCmdL(
   187         iServiceHandler->ExecuteServiceCmdL(
   180     			KAiwCmdAssign,
   188                 KAiwCmdAssign,
   181     			inParamList,
   189                 inParamList,
   182     			iServiceHandler->OutParamListL(),
   190                 iServiceHandler->OutParamListL(),
   183     			0,
   191                 0,
   184     			this);
   192                 this);
   185     	}
   193         }
   186     }
   194     }
   187 
   195 
   188 // -----------------------------------------------------------------------------
   196 // -----------------------------------------------------------------------------
   189 // CFSEmailUiContactHandler::AddToContactsQueryL
   197 // CFSEmailUiContactHandler::AddToContactsQueryL
   190 // -----------------------------------------------------------------------------
   198 // -----------------------------------------------------------------------------
   191 TBool CFSEmailUiContactHandler::AddtoContactsQueryL( TAddToContactsType& aType )
   199 TBool CFSEmailUiContactHandler::AddtoContactsQueryL( TAddToContactsType& aType )
   192 	{
   200     {
   193     FUNC_LOG;
   201     FUNC_LOG;
   194 	// create popup list dialog asking new/update
   202     // create popup list dialog asking new/update
   195 	// Costruct listbox and popup list
   203     // Costruct listbox and popup list
   196 	CEikTextListBox* listbox = new ( ELeave ) CAknSinglePopupMenuStyleListBox();
   204     CEikTextListBox* listbox = new ( ELeave ) CAknSinglePopupMenuStyleListBox();
   197 	CleanupStack::PushL( listbox );
   205     CleanupStack::PushL( listbox );
   198 
   206 
   199 	CAknPopupList* popupList = CAknPopupList::NewL( listbox, 
   207     CAknPopupList* popupList = CAknPopupList::NewL( listbox, 
   200 			R_AVKON_SOFTKEYS_SELECT_BACK );
   208             R_AVKON_SOFTKEYS_SELECT_BACK );
   201 
   209 
   202 	CleanupStack::PushL( popupList );
   210     CleanupStack::PushL( popupList );
   203 	listbox->ConstructL( popupList, CEikListBox::ELeftDownInViewRect );
   211     listbox->ConstructL( popupList, CEikListBox::ELeftDownInViewRect );
   204 
   212 
   205 	listbox->CreateScrollBarFrameL(ETrue);
   213     listbox->CreateScrollBarFrameL(ETrue);
   206 	listbox->ScrollBarFrame()->SetScrollBarVisibilityL(
   214     listbox->ScrollBarFrame()->SetScrollBarVisibilityL(
   207 			CEikScrollBarFrame::EOff,
   215             CEikScrollBarFrame::EOff,
   208 			CEikScrollBarFrame::EAuto );
   216             CEikScrollBarFrame::EAuto );
   209 
   217 
   210     // Get list item array and put all removable theme names in it.
   218     // Get list item array and put all removable theme names in it.
   211     MDesCArray* itemList = listbox->Model()->ItemTextArray();
   219     MDesCArray* itemList = listbox->Model()->ItemTextArray();
   212     CDesCArray* listitems = static_cast< CDesCArray* >( itemList );
   220     CDesCArray* listitems = static_cast< CDesCArray* >( itemList );
   213 
   221 
   214     // Load title for popup list.
   222     // Load title for popup list.
   215     HBufC* resource = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_ADD_TO_CONTACTS );
   223     HBufC* resource = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_ADD_TO_CONTACTS );
   216     popupList->SetTitleL( *resource );
   224     popupList->SetTitleL( *resource );
   217     CleanupStack::PopAndDestroy( resource );            
   225     CleanupStack::PopAndDestroy( resource );            
   218 
   226 
   219 	// Load and append actual selection lines
   227     // Load and append actual selection lines
   220     resource = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_CREATE_NEW_CONTACT );
   228     resource = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_CREATE_NEW_CONTACT );
   221     listitems->AppendL( *resource );
   229     listitems->AppendL( *resource );
   222     CleanupStack::PopAndDestroy( resource );            
   230     CleanupStack::PopAndDestroy( resource );            
   223 
   231 
   224     resource = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_UPDATE_EXISTING );
   232     resource = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_UPDATE_EXISTING );
   226     CleanupStack::PopAndDestroy( resource );            
   234     CleanupStack::PopAndDestroy( resource );            
   227     
   235     
   228     TBool returnValue = EFalse;
   236     TBool returnValue = EFalse;
   229     // Execute popup list.
   237     // Execute popup list.
   230     if ( popupList->ExecuteLD() )
   238     if ( popupList->ExecuteLD() )
   231     	{
   239         {
   232     	if ( !listbox->CurrentItemIndex() )
   240         if ( !listbox->CurrentItemIndex() )
   233     		{
   241             {
   234     		aType = EContactHandlerCreateNewContact;
   242             aType = EContactHandlerCreateNewContact;
   235     		}
   243             }
   236     	else
   244         else
   237     		{
   245             {
   238     		//UpdateExisting is "default" so no flags are needed
   246             //UpdateExisting is "default" so no flags are needed
   239     		aType = EContactHandlerUpdateExisting;
   247             aType = EContactHandlerUpdateExisting;
   240     		}
   248             }
   241     	returnValue = ETrue; //User pressed OK
   249         returnValue = ETrue; //User pressed OK
   242     	}
   250         }
   243     CleanupStack::Pop( popupList ); 
   251     CleanupStack::Pop( popupList ); 
   244 	CleanupStack::PopAndDestroy( listbox );	
   252     CleanupStack::PopAndDestroy( listbox ); 
   245 
   253 
   246 	return returnValue;
   254     return returnValue;
   247 	}
   255     }
   248 
   256 
   249 // ---------------------------------------------------------------------------
   257 // ---------------------------------------------------------------------------
   250 // CFSEmailUiContactHandler::FindAndCallToContactByEmailL
   258 // CFSEmailUiContactHandler::FindAndCallToContactByEmailL
   251 // ---------------------------------------------------------------------------
   259 // ---------------------------------------------------------------------------
   252 //
   260 //
   271 
   279 
   272 // -----------------------------------------------------------------------------
   280 // -----------------------------------------------------------------------------
   273 // CFSEmailUiContactHandler::FindAndCreateMsgToContactByEmailL
   281 // CFSEmailUiContactHandler::FindAndCreateMsgToContactByEmailL
   274 // -----------------------------------------------------------------------------
   282 // -----------------------------------------------------------------------------
   275 void CFSEmailUiContactHandler::FindAndCreateMsgToContactByEmailL( const TDesC& aEmailAddress,
   283 void CFSEmailUiContactHandler::FindAndCreateMsgToContactByEmailL( const TDesC& aEmailAddress,
   276 															 	  CFSMailBox* aMailBox )
   284                                                                   CFSMailBox* aMailBox )
   277     {
   285     {
   278     FUNC_LOG;
   286     FUNC_LOG;
   279     if ( iOpenComplete && (iState == EContactHandlerIdle) ) //If contact stores all ready
   287     if ( iOpenComplete && (iState == EContactHandlerIdle) ) //If contact stores all ready
   280     	{
   288         {
   281     	
   289         
   282     	iState = EContactHandlerCreateMessage;
   290         iState = EContactHandlerCreateMessage;
   283      	iMailBox = aMailBox;     	
   291         iMailBox = aMailBox;        
   284 
   292 
   285      	FindContactLinkL( aEmailAddress );
   293         FindContactLinkL( aEmailAddress );
   286     	
   294         
   287     	}
   295         }
   288     }
   296     }
   289 
   297 
   290 
   298 
   291 	
   299     
   292 // ---------------------------------------------------------------------------
   300 // ---------------------------------------------------------------------------
   293 // Searches for the contact if necessary and shows the contact details.
   301 // Searches for the contact if necessary and shows the contact details.
   294 // ---------------------------------------------------------------------------
   302 // ---------------------------------------------------------------------------
   295 //
   303 //
   296 void CFSEmailUiContactHandler::ShowContactDetailsL( const TDesC& aAddress, 
   304 void CFSEmailUiContactHandler::ShowContactDetailsL( const TDesC& aAddress, 
   304     
   312     
   305     }
   313     }
   306 
   314 
   307 
   315 
   308 void CFSEmailUiContactHandler::MakeAiwCallL(MVPbkContactLink* aContactLink,
   316 void CFSEmailUiContactHandler::MakeAiwCallL(MVPbkContactLink* aContactLink,
   309 											const TDesC& aContactNumber,
   317                                             const TDesC& aContactNumber,
   310 											TBool aVoipOverride )
   318                                             TBool aVoipOverride )
   311     {
   319     {
   312     FUNC_LOG;
   320     FUNC_LOG;
   313     CAiwDialDataExt* dialData = CAiwDialDataExt::NewLC();
   321     CAiwDialDataExt* dialData = CAiwDialDataExt::NewLC();
   314     dialData->SetWindowGroup( CCoeEnv::Static()->RootWin().Identifier() );
   322     dialData->SetWindowGroup( CCoeEnv::Static()->RootWin().Identifier() );
   315    
   323    
   316     HBufC8* linkBuffer(NULL);
   324     HBufC8* linkBuffer(NULL);
   317     
   325     
   318     if( aContactLink )
   326     if( aContactLink )
   319     	{
   327         {
   320     	linkBuffer = aContactLink->PackLC();
   328         linkBuffer = aContactLink->PackLC();
   321     	dialData->SetContactLinkL( *linkBuffer );
   329         dialData->SetContactLinkL( *linkBuffer );
   322    		// Contact link exists, check if voip is preferred
   330         // Contact link exists, check if voip is preferred
   323 	   	// Create iPersistentSetting here only when needed for the first time
   331         // Create iPersistentSetting here only when needed for the first time
   324 		if ( !iPersistentSetting )
   332         if ( !iPersistentSetting )
   325 			{
   333             {
   326 		    iPersistentSetting = 
   334             iPersistentSetting = 
   327 		        PbkGlobalSettingFactory::CreatePersistentSettingL();
   335                 PbkGlobalSettingFactory::CreatePersistentSettingL();
   328 		    iPersistentSetting->
   336             iPersistentSetting->
   329 		        ConnectL(MPbkGlobalSetting::ERichCallSettingsCategory);		
   337                 ConnectL(MPbkGlobalSetting::ERichCallSettingsCategory);     
   330 			} 
   338             } 
   331 		if ( aVoipOverride || SelectBetweenCsAndVoip() == EAiwVoIPCall )
   339         if ( aVoipOverride || SelectBetweenCsAndVoip() == EAiwVoIPCall )
   332 			{
   340             {
   333 		    dialData->SetCallType( CAiwDialData::EAIWVoiP );      	  	
   341             dialData->SetCallType( CAiwDialData::EAIWVoiP );            
   334 			}
   342             }
   335         // <cmail> video call
   343         // <cmail> video call
   336         else if ( iVideoCall )
   344         else if ( iVideoCall )
   337             {
   345             {
   338             iVideoCall = EFalse;
   346             iVideoCall = EFalse;
   339             dialData->SetCallType( CAiwDialData::EAIWForcedVideo );
   347             dialData->SetCallType( CAiwDialData::EAIWForcedVideo );
   340             }
   348             }
   341         // </cmail>
   349         // </cmail>
   342 		else
   350         else
   343 			{
   351             {
   344 		    dialData->SetCallType( CAiwDialData::EAIWVoice );      	  	
   352             dialData->SetCallType( CAiwDialData::EAIWVoice );           
   345 			} 							
   353             }                           
   346     	}
   354         }
   347     else
   355     else
   348     	{
   356         {
   349 		if ( aVoipOverride )
   357         if ( aVoipOverride )
   350 			{
   358             {
   351 		    dialData->SetCallType( CAiwDialData::EAIWVoiP );      	  	
   359             dialData->SetCallType( CAiwDialData::EAIWVoiP );            
   352 			}
   360             }
   353         // <cmail> video call
   361         // <cmail> video call
   354         else if ( iVideoCall ) 
   362         else if ( iVideoCall ) 
   355             {
   363             {
   356             iVideoCall = EFalse;
   364             iVideoCall = EFalse;
   357             dialData->SetCallType( CAiwDialData::EAIWForcedVideo );
   365             dialData->SetCallType( CAiwDialData::EAIWForcedVideo );
   358             }
   366             }
   359         // </cmail>
   367         // </cmail>
   360 		else
   368         else
   361 			{
   369             {
   362 		    dialData->SetCallType( CAiwDialData::EAIWVoice );      	  	
   370             dialData->SetCallType( CAiwDialData::EAIWVoice );           
   363 			}   
   371             }   
   364     	dialData->SetPhoneNumberL( aContactNumber );
   372         dialData->SetPhoneNumberL( aContactNumber );
   365     	}
   373         }
   366     
   374     
   367     CAiwGenericParamList& inParamList = iServiceHandler->InParamListL();
   375     CAiwGenericParamList& inParamList = iServiceHandler->InParamListL();
   368     dialData->FillInParamListL( inParamList );    
   376     dialData->FillInParamListL( inParamList );    
   369     if( aContactLink )
   377     if( aContactLink )
   370     	{
   378         {
   371     	CleanupStack::PopAndDestroy( linkBuffer );
   379         CleanupStack::PopAndDestroy( linkBuffer );
   372     	}
   380         }
   373     
   381     
   374     CleanupStack::PopAndDestroy( dialData );
   382     CleanupStack::PopAndDestroy( dialData );
   375     
   383     
   376     iServiceHandler->ExecuteServiceCmdL(
   384     iServiceHandler->ExecuteServiceCmdL(
   377         KAiwCmdCall,
   385         KAiwCmdCall,
   378         inParamList,
   386         inParamList,
   379         iServiceHandler->OutParamListL(),
   387         iServiceHandler->OutParamListL(),
   380         0,
   388         0,
   381         NULL );
   389         NULL );
   382     if ( iHandlerObserver )
   390     if ( iHandlerObserver )
   383     	{
   391         {
   384     	RPointerArray<CFSEmailUiClsItem> emptyArray;
   392         RPointerArray<CFSEmailUiClsItem> emptyArray;
   385     	iHandlerObserver->OperationCompleteL( EFindAndCallToContactByEmailL, emptyArray );
   393         iHandlerObserver->OperationCompleteL( EFindAndCallToContactByEmailL, emptyArray );
   386     	emptyArray.Close();
   394         emptyArray.Close();
   387     	iHandlerObserver = NULL;
   395         iHandlerObserver = NULL;
   388     	}
   396         }
   389     iState = EContactHandlerIdle;
   397     iState = EContactHandlerIdle;
   390     } 
   398     } 
   391 
   399 
   392 
   400 
   393 TInt CFSEmailUiContactHandler::SelectBetweenCsAndVoip() const
   401 TInt CFSEmailUiContactHandler::SelectBetweenCsAndVoip() const
   394     {
   402     {
   395     FUNC_LOG;
   403     FUNC_LOG;
   396     // Default to voice call
   404     // Default to voice call
   397     TInt ret = EAiwVoice;
   405     TInt ret = EAiwVoice;
   398     
   406     
   399 	TInt preferred = KErrNotFound;
   407     TInt preferred = KErrNotFound;
   400     if ( iPersistentSetting )
   408     if ( iPersistentSetting )
   401     	{
   409         {
   402 	    iPersistentSetting->Get
   410         iPersistentSetting->Get
   403     	    (MPbkGlobalSetting::EPreferredTelephony, preferred);	
   411             (MPbkGlobalSetting::EPreferredTelephony, preferred);    
   404     	}
   412         }
   405    
   413    
   406     // VoIP type is preferred only if the setting is,
   414     // VoIP type is preferred only if the setting is,
   407     // KInternetCallPreferred. In other cases, like when the setting
   415     // KInternetCallPreferred. In other cases, like when the setting
   408     // is not found, voice call is preferred.
   416     // is not found, voice call is preferred.
   409     switch (preferred)
   417     switch (preferred)
   428 void CFSEmailUiContactHandler::SearchMatchesL( const TDesC& aText, 
   436 void CFSEmailUiContactHandler::SearchMatchesL( const TDesC& aText, 
   429     MFSEmailUiContactHandlerObserver* aObserver, CFSMailBox* aMailBox )
   437     MFSEmailUiContactHandlerObserver* aObserver, CFSMailBox* aMailBox )
   430     {
   438     {
   431     FUNC_LOG;
   439     FUNC_LOG;
   432     if ( (iState == EContactHandlerIdle) ||
   440     if ( (iState == EContactHandlerIdle) ||
   433     	 (iState == EContactHandlerSearchMatches)  )
   441          (iState == EContactHandlerSearchMatches)  )
   434     	{
   442         {
   435     	iState = EContactHandlerSearchMatches;
   443         iState = EContactHandlerSearchMatches;
   436     	iHandlerObserver = aObserver;
   444         iHandlerObserver = aObserver;
   437     	
   445         
   438     	iClsListHandler->SetCurrentMailboxL( aMailBox );
   446         iClsListHandler->SetCurrentMailboxL( aMailBox );
   439     	
   447         
   440     	//Async call, CallBack is ArrayUpdatedL (when error: OperationErrorL)
   448         //Async call, CallBack is ArrayUpdatedL (when error: OperationErrorL)
   441     	iClsListHandler->SearchMatchesL( aText );
   449         iClsListHandler->SearchMatchesL( aText );
   442     	}
   450         }
   443     }
   451     }
   444 
   452 
   445 TBool CFSEmailUiContactHandler::IsLanguageSupportedL()
   453 TBool CFSEmailUiContactHandler::IsLanguageSupportedL()
   446     {
   454     {
   447     FUNC_LOG;
   455     FUNC_LOG;
   448     return iClsListHandler->IsLanguageSupportedL();
   456     return iClsListHandler->IsLanguageSupportedL();
   449     }
   457     }
   450 
   458 
   451 CVPbkContactManager* CFSEmailUiContactHandler::GetContactManager()
   459 CVPbkContactManager* CFSEmailUiContactHandler::GetContactManager()
   452 	{
   460     {
   453     FUNC_LOG;
   461     FUNC_LOG;
   454 	return iContactManager;
   462     return iContactManager;
   455 	}
   463     }
   456 
   464 
   457 
   465 
   458 void CFSEmailUiContactHandler::GetAddressesFromPhonebookL(
   466 void CFSEmailUiContactHandler::GetAddressesFromPhonebookL(
   459     MFSEmailUiContactHandlerObserver* aObserver )
   467     MFSEmailUiContactHandlerObserver* aObserver )
   460 	{
   468     {
   461     FUNC_LOG;
   469     FUNC_LOG;
   462 	if ( iState == EContactHandlerIdle )
   470     if ( iState == EContactHandlerIdle )
   463 		{
   471         {
   464 		if ( !aObserver )
   472         if ( !aObserver )
   465 			{
   473             {
   466 			//Request can't be fulfilled without observer
   474             //Request can't be fulfilled without observer
   467 			return;
   475             return;
   468 			}
   476             }
   469 		iHandlerObserver = aObserver;
   477         iHandlerObserver = aObserver;
   470 		iState = EContactHandlerGetAddressesFromPhonebook;
   478         iState = EContactHandlerGetAddressesFromPhonebook;
   471 		TUint fetchFlags = 0;
   479         TUint fetchFlags = 0;
   472 
   480 
   473 		iContactObjects.ResetAndDestroy();
   481         iContactObjects.ResetAndDestroy();
   474 
   482 
   475 		CAiwGenericParamList& inParamList = iServiceHandler->InParamListL();
   483         CAiwGenericParamList& inParamList = iServiceHandler->InParamListL();
   476 		inParamList.AppendL(
   484         inParamList.AppendL(
   477 				TAiwGenericParam(
   485                 TAiwGenericParam(
   478 						EGenericParamContactSelectionData,
   486                         EGenericParamContactSelectionData,
   479 						TAiwVariant(TAiwMultipleItemSelectionDataV1Pckg(
   487                         TAiwVariant(TAiwMultipleItemSelectionDataV1Pckg(
   480 								TAiwMultipleItemSelectionDataV1().
   488                                 TAiwMultipleItemSelectionDataV1().
   481 								SetAddressSelectType(EAiwEMailSelect).
   489                                 SetAddressSelectType(EAiwEMailSelect).
   482 								SetFlags( fetchFlags )))));
   490                                 SetFlags( fetchFlags )))));
   483 
   491 
   484 
   492 
   485 		//Async call, CallBack is HandleNotify
   493         //Async call, CallBack is HandleNotify
   486 		iServiceHandler->ExecuteServiceCmdL(
   494         iServiceHandler->ExecuteServiceCmdL(
   487 				KAiwCmdSelect,
   495                 KAiwCmdSelect,
   488 				inParamList,
   496                 inParamList,
   489 				iServiceHandler->OutParamListL(),
   497                 iServiceHandler->OutParamListL(),
   490 				0,
   498                 0,
   491 				this);	
   499                 this);  
   492 		}
   500         }
   493 	}
   501     }
   494 
   502 
   495 // <cmail> video call
   503 // <cmail> video call
   496 // ---------------------------------------------------------------------------
   504 // ---------------------------------------------------------------------------
   497 // Enables/disables video call.
   505 // Enables/disables video call.
   498 // ---------------------------------------------------------------------------
   506 // ---------------------------------------------------------------------------
   506 /////////////////////////////////////////////////////////////////////////////
   514 /////////////////////////////////////////////////////////////////////////////
   507 // CFSEmailUiContactHandler::GetSmsAddressFromPhonebookAndSendL
   515 // CFSEmailUiContactHandler::GetSmsAddressFromPhonebookAndSendL
   508 //
   516 //
   509 /////////////////////////////////////////////////////////////////////////////
   517 /////////////////////////////////////////////////////////////////////////////
   510 void CFSEmailUiContactHandler::GetSmsAddressFromPhonebookAndSendL( MVPbkContactLink* aContactLink )
   518 void CFSEmailUiContactHandler::GetSmsAddressFromPhonebookAndSendL( MVPbkContactLink* aContactLink )
   511 	{
   519     {
   512     FUNC_LOG;
   520     FUNC_LOG;
   513 	if ( iState == EContactHandlerIdle )
   521     if ( iState == EContactHandlerIdle )
   514 		{
   522         {
   515 		iState = EContactHandlerGetSmsAddressFromPhonebook;
   523         iState = EContactHandlerGetSmsAddressFromPhonebook;
   516 
   524 
   517  		CAiwGenericParamList& inParamList = iServiceHandler->InParamListL();
   525         CAiwGenericParamList& inParamList = iServiceHandler->InParamListL();
   518  		// Set data type select
   526         // Set data type select
   519  	    TAiwSingleItemSelectionDataV3 dataSelect;
   527         TAiwSingleItemSelectionDataV3 dataSelect;
   520         dataSelect.SetAddressSelectType( EAiwPhoneNumberSelect );
   528         dataSelect.SetAddressSelectType( EAiwPhoneNumberSelect );
   521         TAiwSingleItemSelectionDataV3Pckg dataPckg( dataSelect );
   529         TAiwSingleItemSelectionDataV3Pckg dataPckg( dataSelect );
   522         inParamList.AppendL( TAiwGenericParam( EGenericParamContactSelectionData, 
   530         inParamList.AppendL( TAiwGenericParam( EGenericParamContactSelectionData, 
   523                            TAiwVariant( dataPckg )));
   531                            TAiwVariant( dataPckg )));
   524  	 		
   532             
   525  		// Append contact links 		
   533         // Append contact links         
   526        	CVPbkContactLinkArray* links = CVPbkContactLinkArray::NewLC();
   534         CVPbkContactLinkArray* links = CVPbkContactLinkArray::NewLC();
   527         links->AppendL( aContactLink ); // Clone ownership is transferred    
   535         links->AppendL( aContactLink ); // Clone ownership is transferred    
   528         HBufC8* packedLinks = links->PackLC();          
   536         HBufC8* packedLinks = links->PackLC();          
   529         inParamList.AppendL( TAiwGenericParam( EGenericParamContactLinkArray,
   537         inParamList.AppendL( TAiwGenericParam( EGenericParamContactLinkArray,
   530                           TAiwVariant(*packedLinks)));
   538                           TAiwVariant(*packedLinks)));
   531         CleanupStack::PopAndDestroy( packedLinks ); 
   539         CleanupStack::PopAndDestroy( packedLinks ); 
   532         CleanupStack::PopAndDestroy( links ); 
   540         CleanupStack::PopAndDestroy( links ); 
   533 
   541 
   534         //Async call, CallBack is HandleNotify
   542         //Async call, CallBack is HandleNotify
   535 		iServiceHandler->ExecuteServiceCmdL(
   543         iServiceHandler->ExecuteServiceCmdL(
   536 				KAiwCmdSelect,
   544                 KAiwCmdSelect,
   537 				inParamList,
   545                 inParamList,
   538 				iServiceHandler->OutParamListL(),
   546                 iServiceHandler->OutParamListL(),
   539 				0,
   547                 0,
   540 				this);	
   548                 this);  
   541 		}
   549         }
   542 	}
   550     }
   543 
   551 
   544 /////////////////////////////////////////////////////////////////////////////
   552 /////////////////////////////////////////////////////////////////////////////
   545 // CFSEmailUiContactHandler::GetMmsAddressFromPhonebookAndSendL
   553 // CFSEmailUiContactHandler::GetMmsAddressFromPhonebookAndSendL
   546 //
   554 //
   547 /////////////////////////////////////////////////////////////////////////////
   555 /////////////////////////////////////////////////////////////////////////////
   548 void CFSEmailUiContactHandler::GetMmsAddressFromPhonebookAndSendL( MVPbkContactLink* aContactLink,
   556 void CFSEmailUiContactHandler::GetMmsAddressFromPhonebookAndSendL( MVPbkContactLink* aContactLink,
   549 														    TBool aIsVoiceMessage )
   557                                                             TBool aIsVoiceMessage )
   550 	{
   558     {
   551     FUNC_LOG;
   559     FUNC_LOG;
   552 	if ( iState == EContactHandlerIdle )
   560     if ( iState == EContactHandlerIdle )
   553 		{
   561         {
   554 		if ( aIsVoiceMessage )
   562         if ( aIsVoiceMessage )
   555 			{
   563             {
   556 			iState = EContactHandlerGetVoiceMsgAddressFromPhonebook;		
   564             iState = EContactHandlerGetVoiceMsgAddressFromPhonebook;        
   557 			}
   565             }
   558 		else
   566         else
   559 			{
   567             {
   560 			iState = EContactHandlerGetMmsAddressFromPhonebook;			
   568             iState = EContactHandlerGetMmsAddressFromPhonebook;         
   561 			}
   569             }
   562 
   570 
   563  		CAiwGenericParamList& inParamList = iServiceHandler->InParamListL();
   571         CAiwGenericParamList& inParamList = iServiceHandler->InParamListL();
   564  		// Set data type select
   572         // Set data type select
   565  	    TAiwSingleItemSelectionDataV3 dataSelect;
   573         TAiwSingleItemSelectionDataV3 dataSelect;
   566         dataSelect.SetAddressSelectType( EAiwMMSSelect );
   574         dataSelect.SetAddressSelectType( EAiwMMSSelect );
   567         TAiwSingleItemSelectionDataV3Pckg dataPckg( dataSelect );
   575         TAiwSingleItemSelectionDataV3Pckg dataPckg( dataSelect );
   568         inParamList.AppendL( TAiwGenericParam( EGenericParamContactSelectionData, 
   576         inParamList.AppendL( TAiwGenericParam( EGenericParamContactSelectionData, 
   569                            TAiwVariant( dataPckg )));
   577                            TAiwVariant( dataPckg )));
   570  	 		
   578             
   571  		// Append contact links 				
   579         // Append contact links                 
   572        	CVPbkContactLinkArray* links = CVPbkContactLinkArray::NewLC();
   580         CVPbkContactLinkArray* links = CVPbkContactLinkArray::NewLC();
   573         links->AppendL( aContactLink ); // Clone ownership is transferred
   581         links->AppendL( aContactLink ); // Clone ownership is transferred
   574 	    HBufC8* packedLinks = links->PackLC();          
   582         HBufC8* packedLinks = links->PackLC();          
   575         inParamList.AppendL( TAiwGenericParam( EGenericParamContactLinkArray,
   583         inParamList.AppendL( TAiwGenericParam( EGenericParamContactLinkArray,
   576                           TAiwVariant(*packedLinks)));
   584                           TAiwVariant(*packedLinks)));
   577         CleanupStack::PopAndDestroy( packedLinks ); 
   585         CleanupStack::PopAndDestroy( packedLinks ); 
   578         CleanupStack::PopAndDestroy( links );
   586         CleanupStack::PopAndDestroy( links );
   579 
   587 
   580         //Async call, CallBack is HandleNotify
   588         //Async call, CallBack is HandleNotify
   581 		iServiceHandler->ExecuteServiceCmdL(
   589         iServiceHandler->ExecuteServiceCmdL(
   582 				KAiwCmdSelect,
   590                 KAiwCmdSelect,
   583 				inParamList,
   591                 inParamList,
   584 				iServiceHandler->OutParamListL(),
   592                 iServiceHandler->OutParamListL(),
   585 				0,
   593                 0,
   586 				this);	
   594                 this);  
   587 		}
   595         }
   588 	}
   596     }
   589 
   597 
   590 /////////////////////////////////////////////////////////////////////////////
   598 /////////////////////////////////////////////////////////////////////////////
   591 // CFSEmailUiContactHandler::ArrayUpdatedL
   599 // CFSEmailUiContactHandler::ArrayUpdatedL
   592 //
   600 //
   593 /////////////////////////////////////////////////////////////////////////////
   601 /////////////////////////////////////////////////////////////////////////////
   596     {
   604     {
   597     FUNC_LOG;
   605     FUNC_LOG;
   598 
   606 
   599     switch ( iState )
   607     switch ( iState )
   600         {
   608         {
   601 		case EContactHandlerCreateMessage:
   609         case EContactHandlerCreateMessage:
   602 			CreateMessageL( aMatchingItems );	
   610             CreateMessageL( aMatchingItems );   
   603 			break;
   611             break;
   604 		case EContactHandlerCallToContactByEmail:
   612         case EContactHandlerCallToContactByEmail:
   605 			if ( aMatchingItems.Count() )
   613             if ( aMatchingItems.Count() )
   606 				{
   614                 {
   607 				delete iLastClsItem;
   615                 delete iLastClsItem;
   608 				iLastClsItem = NULL;
   616                 iLastClsItem = NULL;
   609 				iLastClsItem = aMatchingItems[0]->CloneLC();
   617                 iLastClsItem = aMatchingItems[0]->CloneLC();
   610 				CleanupStack::Pop();
   618                 CleanupStack::Pop();
   611 				}
   619                 }
   612 			HandleCallL( aMatchingItems );
   620             HandleCallL( aMatchingItems );
   613 			break;
   621             break;
   614 		case EContactHandlerShowContactDetails:
   622         case EContactHandlerShowContactDetails:
   615 			ShowDetailsL( aMatchingItems );
   623             ShowDetailsL( aMatchingItems );
   616 			break;
   624             break;
   617 		case EContactHandlerSearchMatches: 
   625         case EContactHandlerSearchMatches: 
   618 			if ( aMatchingItems.Count() == 1 )
   626             if ( aMatchingItems.Count() == 1 )
   619 				{
   627                 {
   620 				if ( !iSearchMatch )
   628                 if ( !iSearchMatch )
   621 					{
   629                     {
   622 					iSearchMatch = CFSEmailUiClsItem::NewL();			
   630                     iSearchMatch = CFSEmailUiClsItem::NewL();           
   623 					}
   631                     }
   624 				iSearchMatch->SetDisplayNameL( aMatchingItems[0]->DisplayName() );
   632                 iSearchMatch->SetDisplayNameL( aMatchingItems[0]->DisplayName() );
   625 				iSearchMatch->SetEmailAddressL( aMatchingItems[0]->EmailAddress() );
   633                 iSearchMatch->SetEmailAddressL( aMatchingItems[0]->EmailAddress() );
   626 				}
   634                 }
   627 			else
   635             else
   628 			    {
   636                 {
   629 			    delete iSearchMatch;
   637                 delete iSearchMatch;
   630 			    iSearchMatch = NULL;
   638                 iSearchMatch = NULL;
   631 			    }
   639                 }
   632 	
   640     
   633 			// The ownership of the array content is transferred to observer.
   641             // The ownership of the array content is transferred to observer.
   634 			iState = EContactHandlerIdle;
   642             iState = EContactHandlerIdle;
   635 			if ( iHandlerObserver )
   643             if ( iHandlerObserver )
   636 				{
   644                 {
   637 				iHandlerObserver->OperationCompleteL( ESearchContacts, aMatchingItems );
   645                 iHandlerObserver->OperationCompleteL( ESearchContacts, aMatchingItems );
   638 				}
   646                 }
   639 			break;
   647             break;
   640 		default:
   648         default:
   641 			break;
   649             break;
   642         }
   650         }
   643 
   651 
   644     }
   652     }
   645 
   653 
   646 void CFSEmailUiContactHandler::OperationErrorL( TInt aErrorCode )
   654 void CFSEmailUiContactHandler::OperationErrorL( TInt aErrorCode )
   647 	{
   655     {
   648     FUNC_LOG;
   656     FUNC_LOG;
   649 	if ( iHandlerObserver )
   657     if ( iHandlerObserver )
   650 		{
   658         {
   651         // KerrNotReady --> caching in progress, KErrNotFound --> caching not started yet
   659         // KerrNotReady --> caching in progress, KErrNotFound --> caching not started yet
   652         if ( (aErrorCode == KErrNotReady) || (aErrorCode == KErrNotFound) )
   660         if ( (aErrorCode == KErrNotReady) || (aErrorCode == KErrNotFound) )
   653             {
   661             {
   654             iCachingInProgressError = ETrue;
   662             iCachingInProgressError = ETrue;
   655             iState = EContactHandlerIdle;
   663             iState = EContactHandlerIdle;
   660             // handle only if caching was in progress
   668             // handle only if caching was in progress
   661             if ( iCachingInProgressError )
   669             if ( iCachingInProgressError )
   662                 {
   670                 {
   663                 iCachingInProgressError = EFalse;
   671                 iCachingInProgressError = EFalse;
   664                 iState = EContactHandlerIdle;
   672                 iState = EContactHandlerIdle;
   665 		iHandlerObserver->OperationErrorL( ESearchContacts, aErrorCode );
   673         iHandlerObserver->OperationErrorL( ESearchContacts, aErrorCode );
   666 		}
   674         }
   667 	}
   675     }
   668         else
   676         else
   669             {
   677             {
   670             iState = EContactHandlerIdle;
   678             iState = EContactHandlerIdle;
   671             iHandlerObserver->OperationErrorL( ESearchContacts, aErrorCode );
   679             iHandlerObserver->OperationErrorL( ESearchContacts, aErrorCode );
   672             }
   680             }
   677         }
   685         }
   678     }
   686     }
   679 
   687 
   680 
   688 
   681 void CFSEmailUiContactHandler::VPbkSingleContactOperationComplete(
   689 void CFSEmailUiContactHandler::VPbkSingleContactOperationComplete(
   682 	    MVPbkContactOperationBase& aOperation,
   690         MVPbkContactOperationBase& aOperation,
   683 	    MVPbkStoreContact* aContact )
   691         MVPbkStoreContact* aContact )
   684 	{
   692     {
   685     FUNC_LOG;
   693     FUNC_LOG;
   686 //inform also client in case of error to enable client's actions (i.e. return search priority)
   694 //inform also client in case of error to enable client's actions (i.e. return search priority)
   687 //	TRAP_IGNORE( VPbkSingleContactOperationCompleteL( aOperation, aContact) );
   695 //  TRAP_IGNORE( VPbkSingleContactOperationCompleteL( aOperation, aContact) );
   688     TRAPD(error, VPbkSingleContactOperationCompleteL( aOperation, aContact) );
   696     TRAPD(error, VPbkSingleContactOperationCompleteL( aOperation, aContact) );
   689     if ( error != KErrNone )
   697     if ( error != KErrNone )
   690         {
   698         {
   691         TRAP_IGNORE(ObserverOperationErrorL( CurrentCommand(), error ));
   699         TRAP_IGNORE(ObserverOperationErrorL( CurrentCommand(), error ));
   692         }
   700         }
   693 //
   701 //
   694 	}
   702     }
   695 
   703 
   696 void CFSEmailUiContactHandler::VPbkSingleContactOperationCompleteL(
   704 void CFSEmailUiContactHandler::VPbkSingleContactOperationCompleteL(
   697 		    MVPbkContactOperationBase& aOperation,
   705             MVPbkContactOperationBase& aOperation,
   698 		    MVPbkStoreContact* aContact )
   706             MVPbkStoreContact* aContact )
   699 	{
   707     {
   700     FUNC_LOG;
   708     FUNC_LOG;
   701 	
   709     
   702 	if ( (iLinkOperationFetch == &aOperation) && iState == EContactHandlerGetAddressesFromPhonebook )
   710     if ( (iLinkOperationFetch == &aOperation) && iState == EContactHandlerGetAddressesFromPhonebook )
   703 		{
   711         {
   704 		CleanupDeletePushL( aContact );
   712         CleanupDeletePushL( aContact );
   705 		
   713         
   706 		RPointerArray<HBufC> firstname;
   714         RPointerArray<HBufC> firstname;
   707 		CleanupResetAndDestroyClosePushL( firstname );
   715         CleanupResetAndDestroyClosePushL( firstname );
   708 		RPointerArray<HBufC> lastname;
   716         RPointerArray<HBufC> lastname;
   709 		CleanupResetAndDestroyClosePushL( lastname );
   717         CleanupResetAndDestroyClosePushL( lastname );
   710 		RPointerArray<HBufC> emailAddresses;			
   718         RPointerArray<HBufC> emailAddresses;            
   711 		CleanupResetAndDestroyClosePushL( emailAddresses );
   719         CleanupResetAndDestroyClosePushL( emailAddresses );
   712 		GetContactFieldsL( iFirstnameFields, firstname, aContact );
   720         GetContactFieldsL( iFirstnameFields, firstname, aContact );
   713 		GetContactFieldsL( iLastnameFields, lastname, aContact );
   721         GetContactFieldsL( iLastnameFields, lastname, aContact );
   714 	
   722     
   715 		// Create display name, this will be used in UI.
   723         // Create display name, this will be used in UI.
   716 		TInt dispNameLength = 1;
   724         TInt dispNameLength = 1;
   717 		if ( firstname.Count() ) dispNameLength += firstname[0]->Length();
   725         if ( firstname.Count() ) dispNameLength += firstname[0]->Length();
   718 		if ( lastname.Count() ) dispNameLength += lastname[0]->Length();
   726         if ( lastname.Count() ) dispNameLength += lastname[0]->Length();
   719 		HBufC* displayname = HBufC::NewLC( dispNameLength );
   727         HBufC* displayname = HBufC::NewLC( dispNameLength );
   720 		
   728         
   721 		if ( firstname.Count() )
   729         if ( firstname.Count() )
   722 			{
   730             {
   723 			displayname->Des().Copy( *firstname[0] );
   731             displayname->Des().Copy( *firstname[0] );
   724 			displayname->Des().Append( KSpace );
   732             displayname->Des().Append( KSpace );
   725 			}
   733             }
   726 		if ( lastname.Count() )
   734         if ( lastname.Count() )
   727 			{
   735             {
   728 			displayname->Des().Append( *lastname[0] );
   736             displayname->Des().Append( *lastname[0] );
   729 			}
   737             }
   730 		
   738         
   731 		// retrieve selected email address
   739         // retrieve selected email address
   732 		MVPbkStoreContactFieldCollection& fields = aContact->Fields();
   740         MVPbkStoreContactFieldCollection& fields = aContact->Fields();
   733 		MVPbkBaseContactField* selectedField = fields.RetrieveField( *iCurrentLink );
   741         MVPbkBaseContactField* selectedField = fields.RetrieveField( *iCurrentLink );
   734 		HBufC* selectedEmailAddress = MVPbkContactFieldTextData::Cast( 
   742         HBufC* selectedEmailAddress = MVPbkContactFieldTextData::Cast( 
   735 						selectedField->FieldData() ).Text().AllocLC();
   743                         selectedField->FieldData() ).Text().AllocLC();
   736 
   744 
   737         //check number of email addreses
   745         //check number of email addreses
   738         GetContactFieldsL( iEmailFields, emailAddresses, aContact );
   746         GetContactFieldsL( iEmailFields, emailAddresses, aContact );
   739 		// create contact object
   747         // create contact object
   740 		CFSEmailUiClsItem* item = CFSEmailUiClsItem::NewLC();
   748         CFSEmailUiClsItem* item = CFSEmailUiClsItem::NewLC();
   741         
   749         
   742         if ( emailAddresses.Count() > 1 )
   750         if ( emailAddresses.Count() > 1 )
   743             {
   751             {
   744             item->SetMultipleEmails( ETrue );
   752             item->SetMultipleEmails( ETrue );
   745             }
   753             }
   746 
   754 
   747 		item->SetDisplayNameL( displayname->Des() );
   755         item->SetDisplayNameL( displayname->Des() );
   748 		item->SetEmailAddressL( *selectedEmailAddress );
   756         item->SetEmailAddressL( *selectedEmailAddress );
   749 		CleanupStack::Pop( item );
   757         CleanupStack::Pop( item );
   750 		iContactObjects.Append( item );
   758         iContactObjects.Append( item );
   751 
   759 
   752 		CleanupStack::PopAndDestroy( selectedEmailAddress );
   760         CleanupStack::PopAndDestroy( selectedEmailAddress );
   753 		selectedEmailAddress = NULL;
   761         selectedEmailAddress = NULL;
   754 
   762 
   755 		
   763         
   756 		CleanupStack::PopAndDestroy( displayname );
   764         CleanupStack::PopAndDestroy( displayname );
   757 		CleanupStack::PopAndDestroy( &emailAddresses );
   765         CleanupStack::PopAndDestroy( &emailAddresses );
   758 		CleanupStack::PopAndDestroy( &lastname );
   766         CleanupStack::PopAndDestroy( &lastname );
   759 		CleanupStack::PopAndDestroy( &firstname );
   767         CleanupStack::PopAndDestroy( &firstname );
   760 		CleanupStack::PopAndDestroy( aContact );
   768         CleanupStack::PopAndDestroy( aContact );
   761 		
   769         
   762 		// Get index of Next ContactLink if there's no LinkSet
   770         // Get index of Next ContactLink if there's no LinkSet
   763 		// or iCurrenLink index is set to 0
   771         // or iCurrenLink index is set to 0
   764 		TInt index = (iLinksSet && iCurrentLink ? iLinksSet->Find
   772         TInt index = (iLinksSet && iCurrentLink ? iLinksSet->Find
   765 				(*iCurrentLink) + 1 : 0);
   773                 (*iCurrentLink) + 1 : 0);
   766 		
   774         
   767 		if (iLinksSet && index < iLinksSet->Count())
   775         if (iLinksSet && index < iLinksSet->Count())
   768 		    {
   776             {
   769 		    iCurrentLink = &iLinksSet->At(index);
   777             iCurrentLink = &iLinksSet->At(index);
   770 		    delete iLinkOperationFetch;
   778             delete iLinkOperationFetch;
   771 		    iLinkOperationFetch = NULL;
   779             iLinkOperationFetch = NULL;
   772 
   780 
   773 		    //Async operation, callback VPbkSingleContactOperationCompleteL
   781             //Async operation, callback VPbkSingleContactOperationCompleteL
   774 		    //Error situations: VPbkSingleContactOperationFailed
   782             //Error situations: VPbkSingleContactOperationFailed
   775 		    iLinkOperationFetch = iContactManager->RetrieveContactL(
   783             iLinkOperationFetch = iContactManager->RetrieveContactL(
   776 		        *iCurrentLink, *this);
   784                 *iCurrentLink, *this);
   777 		    }
   785             }
   778 		else 
   786         else 
   779 		    {
   787             {
   780 		    delete iLinkOperationFetch; 
   788             delete iLinkOperationFetch; 
   781 		    iLinkOperationFetch = NULL;
   789             iLinkOperationFetch = NULL;
   782 
   790 
   783 		    iCurrentLink = NULL;
   791             iCurrentLink = NULL;
   784 		    iState = EContactHandlerIdle;
   792             iState = EContactHandlerIdle;
   785 		    delete iLinksSet;
   793             delete iLinksSet;
   786 		    iLinksSet = NULL;
   794             iLinksSet = NULL;
   787 
   795 
   788 		    if ( iHandlerObserver )
   796             if ( iHandlerObserver )
   789 		    	{
   797                 {
   790 		    	iHandlerObserver->OperationCompleteL( EGetAddressesFromPhonebook, iContactObjects );
   798                 iHandlerObserver->OperationCompleteL( EGetAddressesFromPhonebook, iContactObjects );
   791 		    	iContactObjects.ResetAndDestroy();
   799                 iContactObjects.ResetAndDestroy();
   792 		    	iHandlerObserver = NULL;
   800                 iHandlerObserver = NULL;
   793 		    	}
   801                 }
   794 			}
   802             }
   795 		}
   803         }
   796 	
   804     
   797 	else if ( (iLinkOperationFetch == &aOperation) && (iState == EContactHandlerCallToContactByEmail ) )
   805     else if ( (iLinkOperationFetch == &aOperation) && (iState == EContactHandlerCallToContactByEmail ) )
   798 	{	
   806     {   
   799 		CleanupDeletePushL( aContact );
   807         CleanupDeletePushL( aContact );
   800 	
   808     
   801 		RPointerArray<HBufC> phonenumbers;
   809         RPointerArray<HBufC> phonenumbers;
   802 		CleanupResetAndDestroyClosePushL( phonenumbers );
   810         CleanupResetAndDestroyClosePushL( phonenumbers );
   803 		GetContactFieldsL( iPhoneNumberFields, phonenumbers, aContact );
   811         GetContactFieldsL( iPhoneNumberFields, phonenumbers, aContact );
   804 		TInt phoneNumbersAvailable = phonenumbers.Count();
   812         TInt phoneNumbersAvailable = phonenumbers.Count();
   805 		CleanupStack::PopAndDestroy( &phonenumbers );
   813         CleanupStack::PopAndDestroy( &phonenumbers );
   806 		
   814         
   807 		if ( phoneNumbersAvailable )
   815         if ( phoneNumbersAvailable )
   808 			{
   816             {
   809 			if ( CallQueryL( iLastClsItem->DisplayName() ) )
   817             if ( CallQueryL( iLastClsItem->DisplayName() ) )
   810 				{
   818                 {
   811 				MakeAiwCallL( iLastClsItem->ContactLink(), KNullDesC );
   819                 MakeAiwCallL( iLastClsItem->ContactLink(), KNullDesC );
   812 				}
   820                 }
   813 			else
   821             else
   814 				{
   822                 {
   815 // user cancelled operation - inform client to enable its actions (i.e. return search priority)
   823 // user cancelled operation - inform client to enable its actions (i.e. return search priority)
   816                 ObserverOperationErrorL( EFindAndCallToContactByEmailL, KErrCancel );
   824                 ObserverOperationErrorL( EFindAndCallToContactByEmailL, KErrCancel );
   817 				iState = EContactHandlerIdle;
   825                 iState = EContactHandlerIdle;
   818 				}
   826                 }
   819 			}
   827             }
   820 		else 
   828         else 
   821 			{
   829             {
   822 	        if ( IsRemoteLookupSupported() )
   830             if ( IsRemoteLookupSupported() )
   823 	            {
   831                 {
   824 	            RemoteContactQueryL();
   832                 RemoteContactQueryL();
   825 	            }
   833                 }
   826 	        else
   834             else
   827 	            {
   835                 {
   828 	            TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_UI_VIEWER_NO_PHONE_NUMBER );					
   836                 TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_UI_VIEWER_NO_PHONE_NUMBER );                   
   829 //no phone number found - inform client to enable its actions (i.e. return search priority)
   837 //no phone number found - inform client to enable its actions (i.e. return search priority)
   830                 ObserverOperationErrorL( EFindAndCallToContactByEmailL, KErrNotFound );
   838                 ObserverOperationErrorL( EFindAndCallToContactByEmailL, KErrNotFound );
   831 	            }
   839                 }
   832 			iState = EContactHandlerIdle;
   840             iState = EContactHandlerIdle;
   833 			}
   841             }
   834 		
   842         
   835 		CleanupStack::PopAndDestroy( aContact );
   843         CleanupStack::PopAndDestroy( aContact );
   836 	}
   844     }
   837 	// Addition to get contact for message creation.
   845     // Addition to get contact for message creation.
   838 	else if ( (iLinkOperationFetch == &aOperation) && ( iMsgCreationHelperState == EContactHandlerGetSmsAddressFromPhonebook || 
   846     else if ( (iLinkOperationFetch == &aOperation) && ( iMsgCreationHelperState == EContactHandlerGetSmsAddressFromPhonebook || 
   839 		    iMsgCreationHelperState == EContactHandlerGetMmsAddressFromPhonebook || iMsgCreationHelperState == EContactHandlerGetVoiceMsgAddressFromPhonebook ) )
   847             iMsgCreationHelperState == EContactHandlerGetMmsAddressFromPhonebook || iMsgCreationHelperState == EContactHandlerGetVoiceMsgAddressFromPhonebook ) )
   840 		{
   848         {
   841 		if ( iContactForMsgCreation )
   849         if ( iContactForMsgCreation )
   842 			{
   850             {
   843 			delete iContactForMsgCreation;
   851             delete iContactForMsgCreation;
   844 			iContactForMsgCreation = NULL;
   852             iContactForMsgCreation = NULL;
   845 			}
   853             }
   846 		// Check that we have a contact for message creatiun
   854         // Check that we have a contact for message creatiun
   847 		if ( aContact )
   855         if ( aContact )
   848 			{
   856             {
   849 			// State is now idle.
   857             // State is now idle.
   850 			iState = EContactHandlerIdle;
   858             iState = EContactHandlerIdle;
   851 			// Store contact
   859             // Store contact
   852 			iContactForMsgCreation = aContact;
   860             iContactForMsgCreation = aContact;
   853 			// Create clonelink for address selection
   861             // Create clonelink for address selection
   854 	        MVPbkContactLink* cloneLink = iCurrentLink->CloneLC();  
   862             MVPbkContactLink* cloneLink = iCurrentLink->CloneLC();  
   855 	   		CleanupStack::Pop();
   863             CleanupStack::Pop();
   856 			switch ( iMsgCreationHelperState )
   864             switch ( iMsgCreationHelperState )
   857 				{
   865                 {
   858 				case EContactHandlerGetSmsAddressFromPhonebook:
   866                 case EContactHandlerGetSmsAddressFromPhonebook:
   859 					// Select SMS address, sending is done when callback completes
   867                     // Select SMS address, sending is done when callback completes
   860 					GetSmsAddressFromPhonebookAndSendL( cloneLink );
   868                     GetSmsAddressFromPhonebookAndSendL( cloneLink );
   861 					break;
   869                     break;
   862 				case EContactHandlerGetMmsAddressFromPhonebook:
   870                 case EContactHandlerGetMmsAddressFromPhonebook:
   863 					// Select MMS address, sending is done when callback completes
   871                     // Select MMS address, sending is done when callback completes
   864 					GetMmsAddressFromPhonebookAndSendL( cloneLink, EFalse );	
   872                     GetMmsAddressFromPhonebookAndSendL( cloneLink, EFalse );    
   865 					break;
   873                     break;
   866 				case EContactHandlerGetVoiceMsgAddressFromPhonebook:
   874                 case EContactHandlerGetVoiceMsgAddressFromPhonebook:
   867 					// Select Voice MSG address, sending is done when callback completes
   875                     // Select Voice MSG address, sending is done when callback completes
   868 					GetMmsAddressFromPhonebookAndSendL( cloneLink, ETrue );	
   876                     GetMmsAddressFromPhonebookAndSendL( cloneLink, ETrue ); 
   869 					break;
   877                     break;
   870 				default:
   878                 default:
   871 					iState = EContactHandlerIdle;
   879                     iState = EContactHandlerIdle;
   872 					iMsgCreationHelperState = EContactHandlerIdle;
   880                     iMsgCreationHelperState = EContactHandlerIdle;
   873 					break;
   881                     break;
   874 				}		
   882                 }       
   875 			}	
   883             }   
   876 		else
   884         else
   877 			{
   885             {
   878 			iMsgCreationHelperState = EContactHandlerIdle;
   886             iMsgCreationHelperState = EContactHandlerIdle;
   879 			iState = EContactHandlerIdle;
   887             iState = EContactHandlerIdle;
   880 			}
   888             }
   881 		}
   889         }
   882 	
   890     
   883 	}
   891     }
   884 
   892 
   885 void CFSEmailUiContactHandler::VPbkSingleContactOperationFailed(
   893 void CFSEmailUiContactHandler::VPbkSingleContactOperationFailed(
   886 	    MVPbkContactOperationBase& aOperation, TInt aError )
   894         MVPbkContactOperationBase& aOperation, TInt aError )
   887 	{
   895     {
   888     FUNC_LOG;
   896     FUNC_LOG;
   889 	TRAP_IGNORE( VPbkSingleContactOperationFailedL( aOperation, aError ) );
   897     TRAP_IGNORE( VPbkSingleContactOperationFailedL( aOperation, aError ) );
   890 	}
   898     }
   891 
   899 
   892 void CFSEmailUiContactHandler::VPbkSingleContactOperationFailedL(
   900 void CFSEmailUiContactHandler::VPbkSingleContactOperationFailedL(
   893 	    MVPbkContactOperationBase& /*aOperation*/, TInt aError )
   901         MVPbkContactOperationBase& /*aOperation*/, TInt aError )
   894 	{
   902     {
   895     FUNC_LOG;
   903     FUNC_LOG;
   896 	iState = EContactHandlerIdle;
   904     iState = EContactHandlerIdle;
   897 	if ( iHandlerObserver )
   905     if ( iHandlerObserver )
   898 		{
   906         {
   899 		iHandlerObserver->OperationErrorL( EFindAndCallToContactByEmailL, aError );
   907         iHandlerObserver->OperationErrorL( EFindAndCallToContactByEmailL, aError );
   900 		iHandlerObserver = NULL;
   908         iHandlerObserver = NULL;
   901 		}
   909         }
   902 	}
   910     }
   903 
   911 
   904 
   912 
   905 void CFSEmailUiContactHandler::OpenComplete()
   913 void CFSEmailUiContactHandler::OpenComplete()
   906 	{
   914     {
   907     FUNC_LOG;
   915     FUNC_LOG;
   908 	if ( iStoreReady )
   916     if ( iStoreReady )
   909 		{
   917         {
   910 		iOpenComplete = ETrue;
   918         iOpenComplete = ETrue;
   911 		}
   919         }
   912 	}
   920     }
   913 
   921 
   914 void CFSEmailUiContactHandler::StoreReady(MVPbkContactStore& /*aContactStore*/)
   922 void CFSEmailUiContactHandler::StoreReady(MVPbkContactStore& /*aContactStore*/)
   915 	{
   923     {
   916     FUNC_LOG;
   924     FUNC_LOG;
   917 	iStoreReady = ETrue;
   925     iStoreReady = ETrue;
   918 	}
   926     }
   919 
   927 
   920 
   928 
   921 void CFSEmailUiContactHandler::StoreUnavailable(MVPbkContactStore& /*aContactStore*/, TInt /*aReason*/)
   929 void CFSEmailUiContactHandler::StoreUnavailable(MVPbkContactStore& /*aContactStore*/, TInt /*aReason*/)
   922 	{
   930     {
   923     FUNC_LOG;
   931     FUNC_LOG;
   924 	iStoreReady = EFalse;
   932     iStoreReady = EFalse;
   925 	}
   933     }
   926 
   934 
   927 
   935 
   928 void CFSEmailUiContactHandler::HandleStoreEventL( MVPbkContactStore& /*aContactStore*/, 
   936 void CFSEmailUiContactHandler::HandleStoreEventL( MVPbkContactStore& /*aContactStore*/, 
   929                 								  TVPbkContactStoreEvent /*aStoreEvent*/)
   937                                                   TVPbkContactStoreEvent /*aStoreEvent*/)
   930 	{
   938     {
   931     FUNC_LOG;
   939     FUNC_LOG;
   932 	
   940     
   933 	}
   941     }
   934 
   942 
   935 // -----------------------------------------------------------------------------
   943 // -----------------------------------------------------------------------------
   936 // CFSEmailUiContactHandler::HandleNotifyL
   944 // CFSEmailUiContactHandler::HandleNotifyL
   937 // -----------------------------------------------------------------------------
   945 // -----------------------------------------------------------------------------
   938 TInt CFSEmailUiContactHandler::HandleNotifyL( TInt aCmdId, TInt aEventId,
   946 TInt CFSEmailUiContactHandler::HandleNotifyL( TInt aCmdId, TInt aEventId,
   939 	                CAiwGenericParamList& aEventParamList,
   947                     CAiwGenericParamList& aEventParamList,
   940 	                const CAiwGenericParamList& /*aInParamList*/)
   948                     const CAiwGenericParamList& /*aInParamList*/)
   941 	{
   949     {
   942     FUNC_LOG;
   950     FUNC_LOG;
   943 	TInt result = 0;
   951     TInt result = 0;
   944 	if ( (aCmdId == KAiwCmdAssign) && (iState == EContactHandlerAddToContacts) &&
   952     if ( (aCmdId == KAiwCmdAssign) && (iState == EContactHandlerAddToContacts) &&
   945 		 (aEventId == KAiwEventCompleted) )
   953          (aEventId == KAiwEventCompleted) )
   946 		{
   954         {
   947 		// Add to contacts function is completed
   955         // Add to contacts function is completed
   948 		iState = EContactHandlerIdle;
   956         iState = EContactHandlerIdle;
   949 		if ( iHandlerObserver )
   957         if ( iHandlerObserver )
   950 			{
   958             {
   951 			RPointerArray<CFSEmailUiClsItem> emptyItems;
   959             RPointerArray<CFSEmailUiClsItem> emptyItems;
   952 			iHandlerObserver->OperationCompleteL( EAddToContactL, emptyItems );
   960             iHandlerObserver->OperationCompleteL( EAddToContactL, emptyItems );
   953 			emptyItems.Close();
   961             emptyItems.Close();
   954 			iHandlerObserver = NULL;
   962             iHandlerObserver = NULL;
   955 			}
   963             }
   956 		
   964         
   957 		}
   965         }
   958 	else if ( (aCmdId == KAiwCmdSelect) && (iState == EContactHandlerGetAddressesFromPhonebook) &&
   966     else if ( (aCmdId == KAiwCmdSelect) && (iState == EContactHandlerGetAddressesFromPhonebook) &&
   959 			  (aEventId == KAiwEventCompleted))
   967               (aEventId == KAiwEventCompleted))
   960 		{
   968         {
   961 
   969 
   962 		TInt index = 0;
   970         TInt index = 0;
   963 		const TAiwGenericParam* param =
   971         const TAiwGenericParam* param =
   964 		aEventParamList.FindFirst(index, EGenericParamContactLinkArray);
   972         aEventParamList.FindFirst(index, EGenericParamContactLinkArray);
   965 		if (param)
   973         if (param)
   966 			{
   974             {
   967 			TPtrC8 contactLinks = param->Value().AsData();
   975             TPtrC8 contactLinks = param->Value().AsData();
   968 
   976 
   969 			iLinksSet = iContactManager->CreateLinksLC(contactLinks);
   977             iLinksSet = iContactManager->CreateLinksLC(contactLinks);
   970 			CleanupStack::Pop();
   978             CleanupStack::Pop();
   971 			if ( iLinksSet->Count() )
   979             if ( iLinksSet->Count() )
   972 				{
   980                 {
   973 				iCurrentLink = &iLinksSet->At(0);
   981                 iCurrentLink = &iLinksSet->At(0);
   974 				//Async operation, callback VPbkSingleContactOperationCompleteL
   982                 //Async operation, callback VPbkSingleContactOperationCompleteL
   975 				//Error situations: VPbkSingleContactOperationFailed
   983                 //Error situations: VPbkSingleContactOperationFailed
   976 				iLinkOperationFetch = iContactManager->RetrieveContactL( iLinksSet->At(0), *this );
   984                 iLinkOperationFetch = iContactManager->RetrieveContactL( iLinksSet->At(0), *this );
   977 				}
   985                 }
   978 
   986 
   979 			iContactManager->ContactStoresL().OpenAllL( *this );
   987             iContactManager->ContactStoresL().OpenAllL( *this );
   980 			}
   988             }
   981 
   989 
   982 		}
   990         }
   983 	else if ( (aCmdId == KAiwCmdSelect) && (iState == EContactHandlerGetSmsAddressFromPhonebook) &&
   991     else if ( (aCmdId == KAiwCmdSelect) && (iState == EContactHandlerGetSmsAddressFromPhonebook) &&
   984 			  (aEventId == KAiwEventCompleted))
   992               (aEventId == KAiwEventCompleted))
   985 		{
   993         {
   986 		iState = EContactHandlerIdle;
   994         iState = EContactHandlerIdle;
   987 		SendMessageL( aEventParamList,  EContactHandlerGetSmsAddressFromPhonebook );
   995         SendMessageL( aEventParamList,  EContactHandlerGetSmsAddressFromPhonebook );
   988 		}
   996         }
   989 	else if ( (aCmdId == KAiwCmdSelect) && (iState == EContactHandlerGetMmsAddressFromPhonebook) &&
   997     else if ( (aCmdId == KAiwCmdSelect) && (iState == EContactHandlerGetMmsAddressFromPhonebook) &&
   990 			  (aEventId == KAiwEventCompleted))
   998               (aEventId == KAiwEventCompleted))
   991 		{
   999         {
   992 		iState = EContactHandlerIdle;
  1000         iState = EContactHandlerIdle;
   993 		// Send SMS to contact address
  1001         // Send SMS to contact address
   994 		SendMessageL( aEventParamList,  EContactHandlerGetMmsAddressFromPhonebook );
  1002         SendMessageL( aEventParamList,  EContactHandlerGetMmsAddressFromPhonebook );
   995 		}
  1003         }
   996 	else if ( (aCmdId == KAiwCmdSelect) && (iState == EContactHandlerGetVoiceMsgAddressFromPhonebook) &&
  1004     else if ( (aCmdId == KAiwCmdSelect) && (iState == EContactHandlerGetVoiceMsgAddressFromPhonebook) &&
   997 			  (aEventId == KAiwEventCompleted))
  1005               (aEventId == KAiwEventCompleted))
   998 		{
  1006         {
   999 		iState = EContactHandlerIdle;
  1007         iState = EContactHandlerIdle;
  1000 		// Send Voice MSG to contact address
  1008         // Send Voice MSG to contact address
  1001 		SendMessageL( aEventParamList,  EContactHandlerGetVoiceMsgAddressFromPhonebook );
  1009         SendMessageL( aEventParamList,  EContactHandlerGetVoiceMsgAddressFromPhonebook );
  1002 		}
  1010         }
  1003 	
  1011     
  1004 	//Notify caller of the error
  1012     //Notify caller of the error
  1005 	else if ( aEventId == KAiwEventError )
  1013     else if ( aEventId == KAiwEventError )
  1006 		{
  1014         {
  1007 		iState = EContactHandlerIdle;
  1015         iState = EContactHandlerIdle;
  1008 		if ( iHandlerObserver )
  1016         if ( iHandlerObserver )
  1009 			{
  1017             {
  1010 			iHandlerObserver->OperationErrorL( CurrentCommand(), KErrGeneral );
  1018             iHandlerObserver->OperationErrorL( CurrentCommand(), KErrGeneral );
  1011 			iHandlerObserver = NULL;
  1019             iHandlerObserver = NULL;
  1012 			}
  1020             }
  1013 		}
  1021         }
  1014 
  1022 
  1015 	// We don't need to check outParams, or do anything special during the exit
  1023     // We don't need to check outParams, or do anything special during the exit
  1016 	else if ( (aEventId == KAiwEventQueryExit) )
  1024     else if ( (aEventId == KAiwEventQueryExit) )
  1017 		{
  1025         {
  1018 		result = ETrue;
  1026         result = ETrue;
  1019 		}
  1027         }
  1020 	
  1028     
  1021 	else if ( aEventId == KAiwEventOutParamCheck )
  1029     else if ( aEventId == KAiwEventOutParamCheck )
  1022 		{
  1030         {
  1023 		result = 1;
  1031         result = 1;
  1024 		}
  1032         }
  1025 	else if ( aEventId == KAiwEventCanceled )
  1033     else if ( aEventId == KAiwEventCanceled )
  1026 		{
  1034         {
  1027 		iState = EContactHandlerIdle;
  1035         iState = EContactHandlerIdle;
  1028 		if ( iHandlerObserver )
  1036         if ( iHandlerObserver )
  1029 			{
  1037             {
  1030 			RPointerArray<CFSEmailUiClsItem> emptyItems;
  1038             RPointerArray<CFSEmailUiClsItem> emptyItems;
  1031 			iHandlerObserver->OperationCompleteL( CurrentCommand(), emptyItems );
  1039             iHandlerObserver->OperationCompleteL( CurrentCommand(), emptyItems );
  1032 			emptyItems.Close();
  1040             emptyItems.Close();
  1033 			iHandlerObserver = NULL;
  1041             iHandlerObserver = NULL;
  1034 			}
  1042             }
  1035 		}
  1043         }
  1036 
  1044 
  1037     return result;
  1045     return result;
  1038     }
  1046     }
  1039 
  1047 
  1040 
  1048 
  1041 CFSEmailUiContactHandler::CFSEmailUiContactHandler( RFs& aSession ): 
  1049 CFSEmailUiContactHandler::CFSEmailUiContactHandler( RFs& aSession ): 
  1042 	iState(EContactHandlerIdle),
  1050     iState(EContactHandlerIdle),
  1043     iHandlerObserver(NULL),
  1051     iHandlerObserver(NULL),
  1044 	iOpenComplete(EFalse),
  1052     iOpenComplete(EFalse),
  1045 	iStoreReady(EFalse),
  1053     iStoreReady(EFalse),
  1046 	iUseSenderText(EFalse),
  1054     iUseSenderText(EFalse),
  1047 	iFs( aSession ),
  1055     iFs( aSession ),
  1048 	iCachingInProgressError(EFalse),
  1056     iCachingInProgressError(EFalse),
  1049     // <cmail> video call
  1057     // <cmail> video call
  1050     iVideoCall( EFalse )
  1058     iVideoCall( EFalse )
  1051     // </cmail>
  1059     // </cmail>
  1052     {
  1060     {
  1053     FUNC_LOG;
  1061     FUNC_LOG;
  1090             {
  1098             {
  1091             RemoteContactQueryL();
  1099             RemoteContactQueryL();
  1092             }
  1100             }
  1093         else
  1101         else
  1094             {
  1102             {
  1095             TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_UI_VIEWER_NO_PHONE_NUMBER );					
  1103             TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_UI_VIEWER_NO_PHONE_NUMBER );                   
  1096             }
  1104             }
  1097         // <cmail> video call flag needs to be cleared
  1105         // <cmail> video call flag needs to be cleared
  1098         iVideoCall = EFalse;
  1106         iVideoCall = EFalse;
  1099         // </cmail>
  1107         // </cmail>
  1100         iState = EContactHandlerIdle;
  1108         iState = EContactHandlerIdle;
  1101         }				
  1109         }               
  1102     else if ( aMatchingItems.Count() > 0 ) // Call to one directly
  1110     else if ( aMatchingItems.Count() > 0 ) // Call to one directly
  1103         {
  1111         {
  1104         // Create contact item in which to copy number or address, async operation.
  1112         // Create contact item in which to copy number or address, async operation.
  1105         delete iCurrentLink;
  1113         delete iCurrentLink;
  1106         iCurrentLink = NULL;
  1114         iCurrentLink = NULL;
  1107 
  1115 
  1108         iCurrentLink = aMatchingItems[0]->ContactLink()->CloneLC();
  1116         iCurrentLink = aMatchingItems[0]->ContactLink()->CloneLC();
  1109         CleanupStack::Pop();
  1117         CleanupStack::Pop();
  1110         if ( iLinkOperationFetch )
  1118         if ( iLinkOperationFetch )
  1111         	{
  1119             {
  1112         	delete iLinkOperationFetch;
  1120             delete iLinkOperationFetch;
  1113         	iLinkOperationFetch = NULL;
  1121             iLinkOperationFetch = NULL;
  1114         	}
  1122             }
  1115         
  1123         
  1116         //Async operation, callback VPbkSingleContactOperationCompleteL
  1124         //Async operation, callback VPbkSingleContactOperationCompleteL
  1117         //Error situations: VPbkSingleContactOperationFailed
  1125         //Error situations: VPbkSingleContactOperationFailed
  1118         iLinkOperationFetch = iContactManager->RetrieveContactL
  1126         iLinkOperationFetch = iContactManager->RetrieveContactL
  1119         (*iCurrentLink, *this);	
  1127         (*iCurrentLink, *this); 
  1120         
  1128         
  1121         }
  1129         }
  1122     }
  1130     }
  1123 
  1131 
  1124 void CFSEmailUiContactHandler::CreateMessageL( const RPointerArray<CFSEmailUiClsItem>& aMatchingItems )
  1132 void CFSEmailUiContactHandler::CreateMessageL( const RPointerArray<CFSEmailUiClsItem>& aMatchingItems )
  1125 	{
  1133     {
  1126     FUNC_LOG;
  1134     FUNC_LOG;
  1127 	iState = EContactHandlerIdle;
  1135     iState = EContactHandlerIdle;
  1128 	
  1136     
  1129 	if ( aMatchingItems.Count() == 0 )
  1137     if ( aMatchingItems.Count() == 0 )
  1130 		{
  1138         {
  1131         // <cmail>
  1139         // <cmail>
  1132         /*if ( IsRemoteLookupSupported() )
  1140         /*if ( IsRemoteLookupSupported() )
  1133             {
  1141             {
  1134             TInt answer = TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_FETCH_FROM_REMOTE_QUERY );
  1142             TInt answer = TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_FETCH_FROM_REMOTE_QUERY );
  1135             if ( answer )
  1143             if ( answer )
  1145             }*/
  1153             }*/
  1146         // phone number not found for email address in contacts - 
  1154         // phone number not found for email address in contacts - 
  1147         // no Text message available - subset of Multimedia and Voice message is displayed
  1155         // no Text message available - subset of Multimedia and Voice message is displayed
  1148         TFsEmailUiUtility::ShowCreateMessageQueryL( *iPreviousEmailAddress, ETrue );
  1156         TFsEmailUiUtility::ShowCreateMessageQueryL( *iPreviousEmailAddress, ETrue );
  1149         // </cmail>
  1157         // </cmail>
  1150 		iState = EContactHandlerIdle;
  1158         iState = EContactHandlerIdle;
  1151 		}
  1159         }
  1152 	else if ( aMatchingItems.Count() > 0 ) 
  1160     else if ( aMatchingItems.Count() > 0 ) 
  1153 		{
  1161         {
  1154 		CSendUi* sendUi = CSendUi::NewLC();
  1162         CSendUi* sendUi = CSendUi::NewLC();
  1155 
  1163 
  1156 		CArrayFix<TUid>* showedServicesUidArray = new( ELeave ) CArrayFixFlat<TUid>(4);
  1164         CArrayFix<TUid>* showedServicesUidArray = new( ELeave ) CArrayFixFlat<TUid>(4);
  1157 		CleanupStack::PushL( showedServicesUidArray );
  1165         CleanupStack::PushL( showedServicesUidArray );
  1158 
  1166 
  1159 		CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( 2 );
  1167         CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( 2 );
  1160 		CleanupStack::PushL( array );
  1168         CleanupStack::PushL( array );
  1161 
  1169 
  1162 		TSendingCapabilities noCapabilities(0,0,0);
  1170         TSendingCapabilities noCapabilities(0,0,0);
  1163 		
  1171         
  1164 		if( sendUi->ValidateServiceL( KSenduiMtmSmsUid, noCapabilities ) )
  1172         if( sendUi->ValidateServiceL( KSenduiMtmSmsUid, noCapabilities ) )
  1165 			{
  1173             {
  1166 			HBufC* textMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_TEXT_MESSAGE );
  1174             HBufC* textMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_TEXT_MESSAGE );
  1167 		    array->AppendL( *textMessage );
  1175             array->AppendL( *textMessage );
  1168 			CleanupStack::PopAndDestroy( textMessage );				
  1176             CleanupStack::PopAndDestroy( textMessage );             
  1169 			showedServicesUidArray->AppendL( KSenduiMtmSmsUid );
  1177             showedServicesUidArray->AppendL( KSenduiMtmSmsUid );
  1170 			}
  1178             }
  1171 		if( sendUi->ValidateServiceL( KSenduiMtmMmsUid, noCapabilities ) )
  1179         if( sendUi->ValidateServiceL( KSenduiMtmMmsUid, noCapabilities ) )
  1172 			{
  1180             {
  1173 			HBufC* multimediaMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_MULTIMEDIA_MESSAGE );
  1181             HBufC* multimediaMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_MULTIMEDIA_MESSAGE );
  1174 		    array->AppendL( *multimediaMessage );
  1182             array->AppendL( *multimediaMessage );
  1175 			CleanupStack::PopAndDestroy( multimediaMessage );				
  1183             CleanupStack::PopAndDestroy( multimediaMessage );               
  1176 			showedServicesUidArray->AppendL( KSenduiMtmMmsUid );
  1184             showedServicesUidArray->AppendL( KSenduiMtmMmsUid );
  1177 			}
  1185             }
  1178 		if( sendUi->ValidateServiceL( KSenduiMtmAudioMessageUid, noCapabilities ) )
  1186         if( sendUi->ValidateServiceL( KSenduiMtmAudioMessageUid, noCapabilities ) )
  1179 			{
  1187             {
  1180 			HBufC* voiceMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_VOICE_MESSAGE );
  1188             HBufC* voiceMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_VOICE_MESSAGE );
  1181 		    array->AppendL( *voiceMessage );
  1189             array->AppendL( *voiceMessage );
  1182 			CleanupStack::PopAndDestroy( voiceMessage );				
  1190             CleanupStack::PopAndDestroy( voiceMessage );                
  1183 			showedServicesUidArray->AppendL( KSenduiMtmAudioMessageUid );
  1191             showedServicesUidArray->AppendL( KSenduiMtmAudioMessageUid );
  1184 			}
  1192             }
  1185 
  1193 
  1186 		TInt selectedOption;
  1194         TInt selectedOption;
  1187 		CAknListQueryDialog* dlg = new ( ELeave ) CAknListQueryDialog( &selectedOption );
  1195         CAknListQueryDialog* dlg = new ( ELeave ) CAknListQueryDialog( &selectedOption );
  1188 		dlg->PrepareLC( R_MAIL_VIEWER_CREATE_MESSAGE_DIALOG  );
  1196         dlg->PrepareLC( R_MAIL_VIEWER_CREATE_MESSAGE_DIALOG  );
  1189 					
  1197                     
  1190 		dlg->SetItemTextArray( array );
  1198         dlg->SetItemTextArray( array );
  1191 		dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );	
  1199         dlg->SetOwnershipType( ELbmDoesNotOwnItemArray );   
  1192 		TInt ret = dlg->RunLD();
  1200         TInt ret = dlg->RunLD();
  1193 		CleanupStack::PopAndDestroy( array );
  1201         CleanupStack::PopAndDestroy( array );
  1194 		CleanupStack::PopAndDestroy( showedServicesUidArray );
  1202         CleanupStack::PopAndDestroy( showedServicesUidArray );
  1195 		CleanupStack::PopAndDestroy( sendUi );		
  1203         CleanupStack::PopAndDestroy( sendUi );      
  1196 	
  1204     
  1197 		// Continue sending process if query is not cancelled
  1205         // Continue sending process if query is not cancelled
  1198 		if( ret )
  1206         if( ret )
  1199 			{
  1207             {
  1200 			switch ( selectedOption )
  1208             switch ( selectedOption )
  1201 				{
  1209                 {
  1202 				case 0:
  1210                 case 0:
  1203 					// Select SMS address, sending is done when callback completes
  1211                     // Select SMS address, sending is done when callback completes
  1204 					iMsgCreationHelperState = EContactHandlerGetSmsAddressFromPhonebook;	
  1212                     iMsgCreationHelperState = EContactHandlerGetSmsAddressFromPhonebook;    
  1205 					break;
  1213                     break;
  1206 				case 1:
  1214                 case 1:
  1207 					// Select MMS address, sending is done when callback completes
  1215                     // Select MMS address, sending is done when callback completes
  1208 					iMsgCreationHelperState = EContactHandlerGetMmsAddressFromPhonebook;	
  1216                     iMsgCreationHelperState = EContactHandlerGetMmsAddressFromPhonebook;    
  1209 					break;
  1217                     break;
  1210 				case 2:
  1218                 case 2:
  1211 					// Select Voice MSG address, sending is done when callback completes
  1219                     // Select Voice MSG address, sending is done when callback completes
  1212 					iMsgCreationHelperState = EContactHandlerGetVoiceMsgAddressFromPhonebook;	
  1220                     iMsgCreationHelperState = EContactHandlerGetVoiceMsgAddressFromPhonebook;   
  1213 					break;
  1221                     break;
  1214 				default:
  1222                 default:
  1215 					iMsgCreationHelperState = EContactHandlerIdle;
  1223                     iMsgCreationHelperState = EContactHandlerIdle;
  1216 					break;
  1224                     break;
  1217 				}
  1225                 }
  1218 			// Create contact item in which to copy number or address, async operation.
  1226             // Create contact item in which to copy number or address, async operation.
  1219 			delete iCurrentLink;
  1227             delete iCurrentLink;
  1220 			iCurrentLink = NULL;
  1228             iCurrentLink = NULL;
  1221 			
  1229             
  1222 			iCurrentLink = aMatchingItems[0]->ContactLink()->CloneLC();
  1230             iCurrentLink = aMatchingItems[0]->ContactLink()->CloneLC();
  1223 			CleanupStack::Pop();
  1231             CleanupStack::Pop();
  1224 			if ( iLinkOperationFetch )
  1232             if ( iLinkOperationFetch )
  1225 				{
  1233                 {
  1226 				delete iLinkOperationFetch;
  1234                 delete iLinkOperationFetch;
  1227 				iLinkOperationFetch = NULL;
  1235                 iLinkOperationFetch = NULL;
  1228 				}
  1236                 }
  1229 			
  1237             
  1230 			//Async operation, callback VPbkSingleContactOperationCompleteL
  1238             //Async operation, callback VPbkSingleContactOperationCompleteL
  1231 			//Error situations: VPbkSingleContactOperationFailed
  1239             //Error situations: VPbkSingleContactOperationFailed
  1232 			iLinkOperationFetch = iContactManager->RetrieveContactL
  1240             iLinkOperationFetch = iContactManager->RetrieveContactL
  1233 			(*iCurrentLink, *this);											
  1241             (*iCurrentLink, *this);                                         
  1234 			}
  1242             }
  1235 		}
  1243         }
  1236 	}
  1244     }
  1237 
  1245 
  1238 // -----------------------------------------------------------------------------
  1246 // -----------------------------------------------------------------------------
  1239 // CFSEmailUiContactHandler::SendMessageL
  1247 // CFSEmailUiContactHandler::SendMessageL
  1240 // -----------------------------------------------------------------------------
  1248 // -----------------------------------------------------------------------------
  1241 void CFSEmailUiContactHandler::SendMessageL( CAiwGenericParamList& aEventParamList, TInt aServiceType )
  1249 void CFSEmailUiContactHandler::SendMessageL( CAiwGenericParamList& aEventParamList, TInt aServiceType )
  1242 	{
  1250     {
  1243     FUNC_LOG;
  1251     FUNC_LOG;
  1244 	TInt paramIndex(0);
  1252     TInt paramIndex(0);
  1245 	iState = EContactHandlerIdle;
  1253     iState = EContactHandlerIdle;
  1246 
  1254 
  1247 	const TAiwGenericParam* param = 
  1255     const TAiwGenericParam* param = 
  1248             aEventParamList.FindFirst( paramIndex, EGenericParamContactLinkArray );
  1256             aEventParamList.FindFirst( paramIndex, EGenericParamContactLinkArray );
  1249     if ( param )
  1257     if ( param )
  1250         {
  1258         {
  1251         TPtrC8 packedLinks = param->Value().AsData();
  1259         TPtrC8 packedLinks = param->Value().AsData();
  1252         if ( packedLinks.Length() > 0 )
  1260         if ( packedLinks.Length() > 0 )
  1253             {      
  1261             {      
  1254 	     	CSendUi* sendUi = CSendUi::NewLC();
  1262             CSendUi* sendUi = CSendUi::NewLC();
  1255     		CMessageData* messageData = CMessageData::NewLC();		 
  1263             CMessageData* messageData = CMessageData::NewLC();       
  1256             MVPbkContactLinkArray* linkArray = GetContactManager()->CreateLinksLC(packedLinks);
  1264             MVPbkContactLinkArray* linkArray = GetContactManager()->CreateLinksLC(packedLinks);
  1257             MVPbkStoreContactField* field = iContactForMsgCreation->Fields().RetrieveField(linkArray->At(0));
  1265             MVPbkStoreContactField* field = iContactForMsgCreation->Fields().RetrieveField(linkArray->At(0));
  1258             MVPbkContactFieldData& data = field->FieldData();
  1266             MVPbkContactFieldData& data = field->FieldData();
  1259             if (data.DataType() == EVPbkFieldStorageTypeText)
  1267             if (data.DataType() == EVPbkFieldStorageTypeText)
  1260                 {
  1268                 {
  1261                 const TDesC& dataText = MVPbkContactFieldTextData::Cast(data).Text();			
  1269                 const TDesC& dataText = MVPbkContactFieldTextData::Cast(data).Text();           
  1262 		     	// Get contact alias to message data if there is name data
  1270                 // Get contact alias to message data if there is name data
  1263                 //RFs& rFs = CEikonEnv::Static()->FsSession();
  1271                 //RFs& rFs = CEikonEnv::Static()->FsSession();
  1264 		        //User::LeaveIfError(rFs.Connect());    
  1272                 //User::LeaveIfError(rFs.Connect());    
  1265 			    CPbk2SortOrderManager* sortOrderManager = 
  1273                 CPbk2SortOrderManager* sortOrderManager = 
  1266 			    		CPbk2SortOrderManager::NewL(iContactManager->FieldTypes(), &iFs);
  1274                         CPbk2SortOrderManager::NewL(iContactManager->FieldTypes(), &iFs);
  1267 			    MPbk2ContactNameFormatter* nameFormatter = 
  1275                 MPbk2ContactNameFormatter* nameFormatter = 
  1268 			    		Pbk2ContactNameFormatterFactory::CreateL(iContactManager->FieldTypes(), *sortOrderManager, &iFs);		     
  1276                         Pbk2ContactNameFormatterFactory::CreateL(iContactManager->FieldTypes(), *sortOrderManager, &iFs);            
  1269 		     	HBufC* nameBuffer = nameFormatter->GetContactTitleL( iContactForMsgCreation->Fields(), 0);
  1277                 HBufC* nameBuffer = nameFormatter->GetContactTitleL( iContactForMsgCreation->Fields(), 0);
  1270 		     	
  1278                 
  1271 		     	delete sortOrderManager;
  1279                 delete sortOrderManager;
  1272 		     	sortOrderManager = NULL;
  1280                 sortOrderManager = NULL;
  1273 		     	delete nameFormatter;     
  1281                 delete nameFormatter;     
  1274 		     	nameFormatter = NULL;
  1282                 nameFormatter = NULL;
  1275 		        
  1283                 
  1276 		     	//rFs.Close();
  1284                 //rFs.Close();
  1277 		        if ( nameBuffer )
  1285                 if ( nameBuffer )
  1278 		            {
  1286                     {
  1279 		            CleanupStack::PushL( nameBuffer );
  1287                     CleanupStack::PushL( nameBuffer );
  1280 		            messageData->AppendToAddressL( dataText, *nameBuffer );
  1288                     messageData->AppendToAddressL( dataText, *nameBuffer );
  1281 		            CleanupStack::PopAndDestroy( nameBuffer );
  1289                     CleanupStack::PopAndDestroy( nameBuffer );
  1282 		            }
  1290                     }
  1283 		        else
  1291                 else
  1284 		            {
  1292                     {
  1285 					messageData->AppendToAddressL( dataText );	
  1293                     messageData->AppendToAddressL( dataText );  
  1286 		            }	
  1294                     }   
  1287 		        // Send selected message							
  1295                 // Send selected message                            
  1288 				TSendingCapabilities noCapabilities(0,0,0);
  1296                 TSendingCapabilities noCapabilities(0,0,0);
  1289 				switch ( aServiceType )
  1297                 switch ( aServiceType )
  1290 					{				
  1298                     {               
  1291 					case EContactHandlerGetSmsAddressFromPhonebook:
  1299                     case EContactHandlerGetSmsAddressFromPhonebook:
  1292 						{
  1300                         {
  1293 						if( sendUi->ValidateServiceL( KSenduiMtmSmsUid, noCapabilities ) )
  1301                         if( sendUi->ValidateServiceL( KSenduiMtmSmsUid, noCapabilities ) )
  1294 							{
  1302                             {
  1295 							sendUi->CreateAndSendMessageL( KSenduiMtmSmsUid, messageData, KNullUid, EFalse );							
  1303                             sendUi->CreateAndSendMessageL( KSenduiMtmSmsUid, messageData, KNullUid, EFalse );                           
  1296 							}
  1304                             }
  1297 						}					
  1305                         }                   
  1298 						break;
  1306                         break;
  1299 					case EContactHandlerGetMmsAddressFromPhonebook:
  1307                     case EContactHandlerGetMmsAddressFromPhonebook:
  1300 						{
  1308                         {
  1301 						if( sendUi->ValidateServiceL( KSenduiMtmMmsUid, noCapabilities ) )
  1309                         if( sendUi->ValidateServiceL( KSenduiMtmMmsUid, noCapabilities ) )
  1302 							{
  1310                             {
  1303 							sendUi->CreateAndSendMessageL( KSenduiMtmMmsUid, messageData, KNullUid, EFalse );							
  1311                             sendUi->CreateAndSendMessageL( KSenduiMtmMmsUid, messageData, KNullUid, EFalse );                           
  1304 							}
  1312                             }
  1305 						}
  1313                         }
  1306 						break;
  1314                         break;
  1307 					case EContactHandlerGetVoiceMsgAddressFromPhonebook:
  1315                     case EContactHandlerGetVoiceMsgAddressFromPhonebook:
  1308 						{
  1316                         {
  1309 						if( sendUi->ValidateServiceL( KSenduiMtmAudioMessageUid, noCapabilities ) )
  1317                         if( sendUi->ValidateServiceL( KSenduiMtmAudioMessageUid, noCapabilities ) )
  1310 							{
  1318                             {
  1311 							sendUi->CreateAndSendMessageL( KSenduiMtmAudioMessageUid, messageData, KNullUid, EFalse );							
  1319                             sendUi->CreateAndSendMessageL( KSenduiMtmAudioMessageUid, messageData, KNullUid, EFalse );                          
  1312 							}
  1320                             }
  1313 						}
  1321                         }
  1314 		 				break;
  1322                         break;
  1315 					default:
  1323                     default:
  1316 						break;			
  1324                         break;          
  1317 					}
  1325                     }
  1318                 }	
  1326                 }   
  1319             CleanupStack::PopAndDestroy( 3 ); // Sendui, messageData and linkArray.
  1327             CleanupStack::PopAndDestroy( 3 ); // Sendui, messageData and linkArray.
  1320             }
  1328             }
  1321         }
  1329         }
  1322 	}
  1330     }
  1323 // ---------------------------------------------------------------------------
  1331 // ---------------------------------------------------------------------------
  1324 // CFSEmailUiContactHandler::IsRemoteLookupSupported
  1332 // CFSEmailUiContactHandler::IsRemoteLookupSupported
  1325 // ---------------------------------------------------------------------------
  1333 // ---------------------------------------------------------------------------
  1326 //
  1334 //
  1327 TBool CFSEmailUiContactHandler::IsRemoteLookupSupported()
  1335 TBool CFSEmailUiContactHandler::IsRemoteLookupSupported()
  1333     }
  1341     }
  1334 
  1342 
  1335 
  1343 
  1336 void CFSEmailUiContactHandler::GetContactFieldsL( RArray<TInt>& aFieldIds,
  1344 void CFSEmailUiContactHandler::GetContactFieldsL( RArray<TInt>& aFieldIds,
  1337     RPointerArray<HBufC>& aNumbers, MVPbkStoreContact* aContact)
  1345     RPointerArray<HBufC>& aNumbers, MVPbkStoreContact* aContact)
  1338 	{
  1346     {
  1339     FUNC_LOG;
  1347     FUNC_LOG;
  1340 	for (TInt i = 0; i < aFieldIds.Count(); i++ )
  1348     for (TInt i = 0; i < aFieldIds.Count(); i++ )
  1341 		{
  1349         {
  1342 		const MVPbkFieldType*  myContactDataField = 
  1350         const MVPbkFieldType*  myContactDataField = 
  1343 		iContactManager->FieldTypes().Find( aFieldIds[i] );
  1351         iContactManager->FieldTypes().Find( aFieldIds[i] );
  1344 
  1352 
  1345 		CVPbkBaseContactFieldTypeIterator* itrNumber = 
  1353         CVPbkBaseContactFieldTypeIterator* itrNumber = 
  1346 		CVPbkBaseContactFieldTypeIterator::NewLC( *myContactDataField, 
  1354         CVPbkBaseContactFieldTypeIterator::NewLC( *myContactDataField, 
  1347 				aContact->Fields() );	
  1355                 aContact->Fields() );   
  1348 
  1356 
  1349 		// Iterate through each of the data fields
  1357         // Iterate through each of the data fields
  1350 		while ( itrNumber->HasNext() )
  1358         while ( itrNumber->HasNext() )
  1351 			{
  1359             {
  1352 			const MVPbkBaseContactField* field = itrNumber->Next();
  1360             const MVPbkBaseContactField* field = itrNumber->Next();
  1353 
  1361 
  1354 			if ( (field->FieldData()).DataType() == EVPbkFieldStorageTypeText )
  1362             if ( (field->FieldData()).DataType() == EVPbkFieldStorageTypeText )
  1355 				{
  1363                 {
  1356 				HBufC* toAppend = MVPbkContactFieldTextData::Cast(
  1364                 HBufC* toAppend = MVPbkContactFieldTextData::Cast(
  1357 						field->FieldData() ).Text().AllocL();
  1365                         field->FieldData() ).Text().AllocL();
  1358 				
  1366                 
  1359 				aNumbers.Append( toAppend );					
  1367                 aNumbers.Append( toAppend );                    
  1360 				}
  1368                 }
  1361 			}
  1369             }
  1362 		CleanupStack::PopAndDestroy( itrNumber ); 
  1370         CleanupStack::PopAndDestroy( itrNumber ); 
  1363 		}
  1371         }
  1364 	}
  1372     }
  1365 
  1373 
  1366 // ---------------------------------------------------------------------------
  1374 // ---------------------------------------------------------------------------
  1367 // Activates phonebook view to show details of give contact
  1375 // Activates phonebook view to show details of give contact
  1368 // ---------------------------------------------------------------------------
  1376 // ---------------------------------------------------------------------------
  1369 //
  1377 //
  1373     FUNC_LOG;
  1381     FUNC_LOG;
  1374     if ( aMatchingItems.Count() &&
  1382     if ( aMatchingItems.Count() &&
  1375         aMatchingItems[0]->ContactLink() )
  1383         aMatchingItems[0]->ContactLink() )
  1376         {
  1384         {
  1377         MVPbkContactLink* contact = aMatchingItems[0]->ContactLink();
  1385         MVPbkContactLink* contact = aMatchingItems[0]->ContactLink();
  1378         CPbk2ViewState* pbk2ViewParam = CPbk2ViewState::NewLC();
  1386         HBufC8* packed = contact->PackLC();
  1379         pbk2ViewParam->SetFocusedContact( contact->CloneLC() );
  1387 
  1380         CleanupStack::Pop(); // Cloned contact
  1388         HBufC16* link16 = HBufC16::NewLC(packed->Length());
  1381         pbk2ViewParam->SetFocusedFieldIndex( 3 );
  1389         link16->Des().Copy(packed->Des());
  1382         HBufC8* paramBuf = pbk2ViewParam->PackLC();
  1390 
  1383 
  1391         MCCAParameter*  param = TCCAFactory::NewParameterL();
  1384         // Make view id with Phonebook2's app UID3 and Contact Info View's id
  1392         CleanupClosePushL( *param );
  1385         const TVwsViewId viewId( TUid::Uid(0x101f4cce),
  1393         
  1386             TUid::Uid(EPbk2ContactInfoViewId) );
  1394         delete iConnection;
  1387 
  1395         iConnection = NULL;
  1388         // Activate the view
  1396         iConnection = TCCAFactory::NewConnectionL();
  1389         CEikonEnv::Static()->AppUi()->ActivateViewL( viewId,
  1397 
  1390             CPbk2ViewState::Uid(), *paramBuf );
  1398         // Setting up the contact link parameter, ownership transfers
  1391 
  1399         param->SetConnectionFlag(MCCAParameter::ENormal);
  1392         // Cleanup
  1400         param->SetContactDataFlag(MCCAParameter::EContactLink);
  1393         CleanupStack::PopAndDestroy( paramBuf );
  1401         param->SetContactDataL( link16->Des() );
  1394         CleanupStack::PopAndDestroy( pbk2ViewParam );
  1402 
       
  1403         // switch to details view
       
  1404         const TUid uid = TUid::Uid( 0x200159E7 ); 
       
  1405         param->SetLaunchedViewUid( uid);
       
  1406 
       
  1407         // Launching the  CCA application
       
  1408         iConnection->LaunchAppL( *param, this );
       
  1409 
       
  1410         CleanupStack::Pop( param );  // parameter is taken care by MCCAConnection
       
  1411         CleanupStack::PopAndDestroy( link16 );
       
  1412         CleanupStack::PopAndDestroy( packed );
  1395         }
  1413         }
  1396     else
  1414     else
  1397         {
  1415         {
  1398         TFsEmailUiUtility::ShowErrorNoteL(
  1416         TFsEmailUiUtility::ShowErrorNoteL(
  1399             R_FREESTYLE_EMAIL_UI_VIEWER_NO_EMAIL_ADDRESS, EFalse );
  1417             R_FREESTYLE_EMAIL_UI_VIEWER_NO_EMAIL_ADDRESS, EFalse );
  1418     iClsListHandler->SetCurrentMailboxL( NULL );
  1436     iClsListHandler->SetCurrentMailboxL( NULL );
  1419     iClsListHandler->SearchMatchesL( aDes );
  1437     iClsListHandler->SearchMatchesL( aDes );
  1420     }
  1438     }
  1421 
  1439 
  1422 void CFSEmailUiContactHandler::FormatFieldIds()
  1440 void CFSEmailUiContactHandler::FormatFieldIds()
  1423 	{
  1441     {
  1424     FUNC_LOG;
  1442     FUNC_LOG;
  1425 	iEmailFields.Append( R_VPBK_FIELD_TYPE_EMAILGEN );
  1443     iEmailFields.Append( R_VPBK_FIELD_TYPE_EMAILGEN );
  1426 	iEmailFields.Append( R_VPBK_FIELD_TYPE_EMAILWORK );
  1444     iEmailFields.Append( R_VPBK_FIELD_TYPE_EMAILWORK );
  1427 	iEmailFields.Append( R_VPBK_FIELD_TYPE_EMAILHOME );
  1445     iEmailFields.Append( R_VPBK_FIELD_TYPE_EMAILHOME );
  1428 	
  1446     
  1429 	iFirstnameFields.Append( R_VPBK_FIELD_TYPE_FIRSTNAME );
  1447     iFirstnameFields.Append( R_VPBK_FIELD_TYPE_FIRSTNAME );
  1430 	iLastnameFields.Append( R_VPBK_FIELD_TYPE_LASTNAME );
  1448     iLastnameFields.Append( R_VPBK_FIELD_TYPE_LASTNAME );
  1431 	
  1449     
  1432 	iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_LANDPHONEHOME );
  1450     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_LANDPHONEHOME );
  1433 	iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_MOBILEPHONEWORK );
  1451     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_MOBILEPHONEWORK );
  1434 	iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_MOBILEPHONEHOME );
  1452     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_MOBILEPHONEHOME );
  1435 	iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_LANDPHONEWORK );
  1453     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_LANDPHONEWORK );
  1436 	iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_LANDPHONEGEN );
  1454     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_LANDPHONEGEN );
  1437 	iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN );
  1455     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN );
  1438 	
  1456     
  1439 	}
  1457     }
  1440 
  1458 
  1441 void CFSEmailUiContactHandler::ResetFieldIds()
  1459 void CFSEmailUiContactHandler::ResetFieldIds()
  1442 	{
  1460     {
  1443     FUNC_LOG;
  1461     FUNC_LOG;
  1444 	iLastnameFields.Reset();
  1462     iLastnameFields.Reset();
  1445 	iFirstnameFields.Reset();
  1463     iFirstnameFields.Reset();
  1446 	iEmailFields.Reset();
  1464     iEmailFields.Reset();
  1447 	iPhoneNumberFields.Reset();
  1465     iPhoneNumberFields.Reset();
  1448 	}
  1466     }
  1449 
  1467 
  1450 
  1468 
  1451 // -----------------------------------------------------------------------------
  1469 // -----------------------------------------------------------------------------
  1452 // CFSEmailUiContactHandler::LaunchRemoteLookupL
  1470 // CFSEmailUiContactHandler::LaunchRemoteLookupL
  1453 // -----------------------------------------------------------------------------
  1471 // -----------------------------------------------------------------------------
  1454 TBool CFSEmailUiContactHandler::GetNameAndEmailFromRemoteLookupL( CFSMailBox& aMailBox,
  1472 TBool CFSEmailUiContactHandler::GetNameAndEmailFromRemoteLookupL( CFSMailBox& aMailBox,
  1455     const TDesC& aQueryString, TDes& aDisplayname, TDes& aEmailAddress )
  1473     const TDesC& aQueryString, TDes& aDisplayname, TDes& aEmailAddress )
  1456 	{
  1474     {
  1457     FUNC_LOG;
  1475     FUNC_LOG;
  1458 
  1476 
  1459 	CPbkxRemoteContactLookupServiceUiContext::TResult result;
  1477     CPbkxRemoteContactLookupServiceUiContext::TResult result;
  1460 	DoRemoteLookupL( aMailBox, aQueryString, result, 
  1478     DoRemoteLookupL( aMailBox, aQueryString, result, 
  1461 			         CPbkxRemoteContactLookupServiceUiContext::EModeContactSelector);
  1479                      CPbkxRemoteContactLookupServiceUiContext::EModeContactSelector);
  1462 
  1480 
  1463 	if ( result.iExitReason == 
  1481     if ( result.iExitReason == 
  1464 		 CPbkxRemoteContactLookupServiceUiContext::TResult::EExitContactSelected )
  1482          CPbkxRemoteContactLookupServiceUiContext::TResult::EExitContactSelected )
  1465 		{
  1483         {
  1466 		GetNameAndEmail( aDisplayname, aEmailAddress, *(result.iSelectedContactItem) );
  1484         GetNameAndEmail( aDisplayname, aEmailAddress, *(result.iSelectedContactItem) );
  1467 		return ETrue;
  1485         return ETrue;
  1468 		} 
  1486         } 
  1469 
  1487 
  1470 	return EFalse;
  1488     return EFalse;
  1471 	}
  1489     }
  1472 
  1490 
  1473 // -----------------------------------------------------------------------------
  1491 // -----------------------------------------------------------------------------
  1474 // CFSEmailUiContactHandler::LaunchRemoteLookupL
  1492 // CFSEmailUiContactHandler::LaunchRemoteLookupL
  1475 // -----------------------------------------------------------------------------
  1493 // -----------------------------------------------------------------------------
  1476 void CFSEmailUiContactHandler::LaunchRemoteLookupL( CFSMailBox& aMailBox )
  1494 void CFSEmailUiContactHandler::LaunchRemoteLookupL( CFSMailBox& aMailBox )
  1477 	{
  1495     {
  1478     FUNC_LOG;
  1496     FUNC_LOG;
  1479 
  1497 
  1480 	CPbkxRemoteContactLookupServiceUiContext::TResult result;
  1498     CPbkxRemoteContactLookupServiceUiContext::TResult result;
  1481 	DoRemoteLookupL( aMailBox, KNullDesC , result, 
  1499     DoRemoteLookupL( aMailBox, KNullDesC , result, 
  1482 				     CPbkxRemoteContactLookupServiceUiContext::EModeNormal );
  1500                      CPbkxRemoteContactLookupServiceUiContext::EModeNormal );
  1483 
  1501 
  1484 	}
  1502     }
  1485 
  1503 
  1486 // -----------------------------------------------------------------------------
  1504 // -----------------------------------------------------------------------------
  1487 // CFSEmailUiContactHandler::LaunchRemoteLookupL
  1505 // CFSEmailUiContactHandler::LaunchRemoteLookupL
  1488 // -----------------------------------------------------------------------------
  1506 // -----------------------------------------------------------------------------
  1489 HBufC* CFSEmailUiContactHandler::GetNameAndNumberFromRemoteLookupL( CFSMailBox& aMailBox, const TDesC& aQuery, 
  1507 HBufC* CFSEmailUiContactHandler::GetNameAndNumberFromRemoteLookupL( CFSMailBox& aMailBox, const TDesC& aQuery, 
  1490 													  RBuf& aPhoneNumber )
  1508                                                       RBuf& aPhoneNumber )
  1491 	{
  1509     {
  1492     FUNC_LOG;
  1510     FUNC_LOG;
  1493 
  1511 
  1494 	CPbkxRemoteContactLookupServiceUiContext::TResult result;
  1512     CPbkxRemoteContactLookupServiceUiContext::TResult result;
  1495 	DoRemoteLookupL( aMailBox, aQuery , result, 
  1513     DoRemoteLookupL( aMailBox, aQuery , result, 
  1496 				     CPbkxRemoteContactLookupServiceUiContext::EModeContactSelector );
  1514                      CPbkxRemoteContactLookupServiceUiContext::EModeContactSelector );
  1497 
  1515 
  1498 	HBufC* displayName = NULL;
  1516     HBufC* displayName = NULL;
  1499 	
  1517     
  1500 	if ( result.iExitReason == 
  1518     if ( result.iExitReason == 
  1501 	CPbkxRemoteContactLookupServiceUiContext::TResult::EExitContactSelected )
  1519     CPbkxRemoteContactLookupServiceUiContext::TResult::EExitContactSelected )
  1502 		{
  1520         {
  1503 		displayName = GetPhoneNumberAndNameL( aPhoneNumber, *(result.iSelectedContactItem) );
  1521         displayName = GetPhoneNumberAndNameL( aPhoneNumber, *(result.iSelectedContactItem) );
  1504 		} 
  1522         } 
  1505 	return displayName;
  1523     return displayName;
  1506 	}
  1524     }
  1507 
  1525 
  1508 void CFSEmailUiContactHandler::LaunchRemoteLookupWithQueryL( CFSMailBox& aMailBox, const TDesC& aQuery )
  1526 void CFSEmailUiContactHandler::LaunchRemoteLookupWithQueryL( CFSMailBox& aMailBox, const TDesC& aQuery )
  1509 	{
  1527     {
  1510     FUNC_LOG;
  1528     FUNC_LOG;
  1511 
  1529 
  1512 	CPbkxRemoteContactLookupServiceUiContext::TResult result;
  1530     CPbkxRemoteContactLookupServiceUiContext::TResult result;
  1513 	DoRemoteLookupL( aMailBox, aQuery , result, 
  1531     DoRemoteLookupL( aMailBox, aQuery , result, 
  1514 					     CPbkxRemoteContactLookupServiceUiContext::EModeExistingCriteria );
  1532                          CPbkxRemoteContactLookupServiceUiContext::EModeExistingCriteria );
  1515 
  1533 
  1516 	}
  1534     }
  1517 
  1535 
  1518 HBufC* CFSEmailUiContactHandler::GetLastSearchNameL( const TDesC& aEmailAddress )
  1536 HBufC* CFSEmailUiContactHandler::GetLastSearchNameL( const TDesC& aEmailAddress )
  1519 	{
  1537     {
  1520     FUNC_LOG;
  1538     FUNC_LOG;
  1521 	HBufC* name(NULL);
  1539     HBufC* name(NULL);
  1522 	if ( iSearchMatch )
  1540     if ( iSearchMatch )
  1523 		{
  1541         {
  1524 		if ( !iSearchMatch->EmailAddress().CompareF( aEmailAddress ) )
  1542         if ( !iSearchMatch->EmailAddress().CompareF( aEmailAddress ) )
  1525 			{
  1543             {
  1526 			if ( iSearchMatch->DisplayName() != KNullDesC )
  1544             if ( iSearchMatch->DisplayName() != KNullDesC )
  1527 				{
  1545                 {
  1528 				name = iSearchMatch->DisplayName().AllocL();
  1546                 name = iSearchMatch->DisplayName().AllocL();
  1529 				}
  1547                 }
  1530 			}
  1548             }
  1531 		}
  1549         }
  1532 	return name;
  1550     return name;
  1533 	}
  1551     }
  1534 
  1552 
  1535 void CFSEmailUiContactHandler::Reset()
  1553 void CFSEmailUiContactHandler::Reset()
  1536 	{
  1554     {
  1537     FUNC_LOG;
  1555     FUNC_LOG;
  1538 	iContactObjects.ResetAndDestroy();
  1556     iContactObjects.ResetAndDestroy();
  1539 	iState = EContactHandlerIdle;
  1557     iState = EContactHandlerIdle;
  1540 	delete iLinksSet;
  1558     delete iLinksSet;
  1541 	iLinksSet = NULL;
  1559     iLinksSet = NULL;
  1542 	delete iLinkOperation;
  1560     delete iLinkOperation;
  1543 	iLinkOperation = NULL;
  1561     iLinkOperation = NULL;
  1544 	delete iLinkOperationFetch;
  1562     delete iLinkOperationFetch;
  1545 	iLinkOperationFetch = NULL;
  1563     iLinkOperationFetch = NULL;
  1546 	iHandlerObserver = NULL;
  1564     iHandlerObserver = NULL;
  1547 	}
  1565     }
  1548 
  1566 
  1549 
  1567 
  1550 // ---------------------------------------------------------------------------
  1568 // ---------------------------------------------------------------------------
  1551 // Gets the name and email address from given contact item
  1569 // Gets the name and email address from given contact item
  1552 // ---------------------------------------------------------------------------
  1570 // ---------------------------------------------------------------------------
  1553 //
  1571 //
  1554 void CFSEmailUiContactHandler::GetNameAndEmail( TDes& aName, TDes& aEmail,
  1572 void CFSEmailUiContactHandler::GetNameAndEmail( TDes& aName, TDes& aEmail,
  1555     CContactItem& aItem ) const
  1573     CContactItem& aItem ) const
  1556 	{
  1574     {
  1557     FUNC_LOG;
  1575     FUNC_LOG;
  1558 	CContactItemFieldSet& fieldSet = aItem.CardFields();
  1576     CContactItemFieldSet& fieldSet = aItem.CardFields();
  1559 	aName.Zero();
  1577     aName.Zero();
  1560 
  1578 
  1561 	RBuf familyName;
  1579     RBuf familyName;
  1562 	RBuf givenName;
  1580     RBuf givenName;
  1563 	TInt pos;
  1581     TInt pos;
  1564 
  1582 
  1565 	pos = fieldSet.Find(KUidContactFieldFamilyName);
  1583     pos = fieldSet.Find(KUidContactFieldFamilyName);
  1566 	if (pos >= 0)
  1584     if (pos >= 0)
  1567 		{
  1585         {
  1568 		CContactItemField& itemField=fieldSet[pos];
  1586         CContactItemField& itemField=fieldSet[pos];
  1569 		if (!(itemField.IsHidden()) && !(itemField.IsDisabled()))
  1587         if (!(itemField.IsHidden()) && !(itemField.IsDisabled()))
  1570 			{
  1588             {
  1571 			CContactTextField* textField = itemField.TextStorage();
  1589             CContactTextField* textField = itemField.TextStorage();
  1572 			familyName.Create( textField->Text() );
  1590             familyName.Create( textField->Text() );
  1573 			}				
  1591             }               
  1574 		}
  1592         }
  1575 	pos = fieldSet.Find(KUidContactFieldGivenName);
  1593     pos = fieldSet.Find(KUidContactFieldGivenName);
  1576 	if (pos >= 0)
  1594     if (pos >= 0)
  1577 		{
  1595         {
  1578 		CContactItemField& itemField=fieldSet[pos];
  1596         CContactItemField& itemField=fieldSet[pos];
  1579 		if (!(itemField.IsHidden()) && !(itemField.IsDisabled()))
  1597         if (!(itemField.IsHidden()) && !(itemField.IsDisabled()))
  1580 			{
  1598             {
  1581 			CContactTextField* textField = itemField.TextStorage();
  1599             CContactTextField* textField = itemField.TextStorage();
  1582 			givenName.Create( textField->Text() );
  1600             givenName.Create( textField->Text() );
  1583 			}				
  1601             }               
  1584 		}	
  1602         }   
  1585 	RBuf email;
  1603     RBuf email;
  1586 	pos = fieldSet.Find(KUidContactFieldEMail);
  1604     pos = fieldSet.Find(KUidContactFieldEMail);
  1587 	if (pos >= 0)
  1605     if (pos >= 0)
  1588 		{
  1606         {
  1589 		CContactItemField& itemField=fieldSet[pos];
  1607         CContactItemField& itemField=fieldSet[pos];
  1590 		if (!(itemField.IsHidden()) && !(itemField.IsDisabled()))
  1608         if (!(itemField.IsHidden()) && !(itemField.IsDisabled()))
  1591 			{
  1609             {
  1592 			CContactTextField* textField = itemField.TextStorage();
  1610             CContactTextField* textField = itemField.TextStorage();
  1593 			email.Create( textField->Text() );
  1611             email.Create( textField->Text() );
  1594 			aEmail.Copy( email );
  1612             aEmail.Copy( email );
  1595 			}				
  1613             }               
  1596 		}
  1614         }
  1597 	email.Close();
  1615     email.Close();
  1598 
  1616 
  1599 
  1617 
  1600 	if ( familyName.Length() )
  1618     if ( familyName.Length() )
  1601 		{
  1619         {
  1602 		aName.Append(givenName);
  1620         aName.Append(givenName);
  1603 		aName.Trim();
  1621         aName.Trim();
  1604 		}
  1622         }
  1605 
  1623 
  1606 	if ( givenName.Length() )
  1624     if ( givenName.Length() )
  1607 		{
  1625         {
  1608 		aName.Append(' ');
  1626         aName.Append(' ');
  1609 		aName.Append(familyName);
  1627         aName.Append(familyName);
  1610 		aName.Trim();
  1628         aName.Trim();
  1611 		}
  1629         }
  1612 
  1630 
  1613 	givenName.Close();
  1631     givenName.Close();
  1614 	familyName.Close();
  1632     familyName.Close();
  1615 	}
  1633     }
  1616 
  1634 
  1617 // ---------------------------------------------------------------------------
  1635 // ---------------------------------------------------------------------------
  1618 // Gets the phone number from given contact item
  1636 // Gets the phone number from given contact item
  1619 // ---------------------------------------------------------------------------
  1637 // ---------------------------------------------------------------------------
  1620 //
  1638 //
  1621 HBufC* CFSEmailUiContactHandler::GetPhoneNumberAndNameL( RBuf& aPhoneNumber, CContactItem& aItem ) const
  1639 HBufC* CFSEmailUiContactHandler::GetPhoneNumberAndNameL( RBuf& aPhoneNumber, CContactItem& aItem ) const
  1622 	{
  1640     {
  1623     FUNC_LOG;
  1641     FUNC_LOG;
  1624 	TInt pos;
  1642     TInt pos;
  1625 	CContactItemFieldSet& fieldSet = aItem.CardFields();
  1643     CContactItemFieldSet& fieldSet = aItem.CardFields();
  1626 
  1644 
  1627 	pos = fieldSet.Find(KUidContactFieldPhoneNumber);
  1645     pos = fieldSet.Find(KUidContactFieldPhoneNumber);
  1628 	if (pos >= 0)
  1646     if (pos >= 0)
  1629 		{
  1647         {
  1630 		CContactItemField& itemField=fieldSet[pos];
  1648         CContactItemField& itemField=fieldSet[pos];
  1631 		if (!(itemField.IsHidden()) && !(itemField.IsDisabled()))
  1649         if (!(itemField.IsHidden()) && !(itemField.IsDisabled()))
  1632 			{
  1650             {
  1633 			CContactTextField* textField = itemField.TextStorage();
  1651             CContactTextField* textField = itemField.TextStorage();
  1634 			//aPhoneNumber.Create( textField->Text()->Length() );
  1652             //aPhoneNumber.Create( textField->Text()->Length() );
  1635 			//aPhoneNumber.Copy( textField->Text() );
  1653             //aPhoneNumber.Copy( textField->Text() );
  1636 			aPhoneNumber.Create( textField->Text() );
  1654             aPhoneNumber.Create( textField->Text() );
  1637 			}				
  1655             }               
  1638 		}
  1656         }
  1639 	
  1657     
  1640 	HBufC* firstname = NULL;
  1658     HBufC* firstname = NULL;
  1641 	
  1659     
  1642 	pos = fieldSet.Find( KUidContactFieldGivenName );
  1660     pos = fieldSet.Find( KUidContactFieldGivenName );
  1643 	if ( pos >= 0 )
  1661     if ( pos >= 0 )
  1644 		{
  1662         {
  1645 		CContactItemField& itemField=fieldSet[pos];
  1663         CContactItemField& itemField=fieldSet[pos];
  1646 		if ( !itemField.IsHidden() && !itemField.IsDisabled() )
  1664         if ( !itemField.IsHidden() && !itemField.IsDisabled() )
  1647 			{
  1665             {
  1648 			CContactTextField* textField = itemField.TextStorage();
  1666             CContactTextField* textField = itemField.TextStorage();
  1649 			firstname = textField->Text().AllocLC();
  1667             firstname = textField->Text().AllocLC();
  1650 			}				
  1668             }               
  1651 		}
  1669         }
  1652 	if ( !firstname )
  1670     if ( !firstname )
  1653 	    {
  1671         {
  1654 	    firstname = KNullDesC().AllocLC();
  1672         firstname = KNullDesC().AllocLC();
  1655 	    }
  1673         }
  1656 
  1674 
  1657 	HBufC* lastname = NULL;
  1675     HBufC* lastname = NULL;
  1658 	
  1676     
  1659 	pos = fieldSet.Find( KUidContactFieldFamilyName );
  1677     pos = fieldSet.Find( KUidContactFieldFamilyName );
  1660 	if ( pos >= 0 )
  1678     if ( pos >= 0 )
  1661 		{
  1679         {
  1662 		CContactItemField& itemField=fieldSet[pos];
  1680         CContactItemField& itemField=fieldSet[pos];
  1663 		if ( !itemField.IsHidden() && !itemField.IsDisabled() )
  1681         if ( !itemField.IsHidden() && !itemField.IsDisabled() )
  1664 			{
  1682             {
  1665 			CContactTextField* textField = itemField.TextStorage();
  1683             CContactTextField* textField = itemField.TextStorage();
  1666 			lastname = textField->Text().AllocLC();
  1684             lastname = textField->Text().AllocLC();
  1667 			}				
  1685             }               
  1668 		}
  1686         }
  1669 	if ( !lastname )
  1687     if ( !lastname )
  1670 	    {
  1688         {
  1671 	    lastname = KNullDesC().AllocLC();
  1689         lastname = KNullDesC().AllocLC();
  1672 	    }
  1690         }
  1673 	
  1691     
  1674 	HBufC* name = TFsEmailUiUtility::CreateDisplayNameLC( *firstname, *lastname, KNullDesC );
  1692     HBufC* name = TFsEmailUiUtility::CreateDisplayNameLC( *firstname, *lastname, KNullDesC );
  1675 	CleanupStack::Pop( name );
  1693     CleanupStack::Pop( name );
  1676 	CleanupStack::PopAndDestroy( lastname );
  1694     CleanupStack::PopAndDestroy( lastname );
  1677 	CleanupStack::PopAndDestroy( firstname );
  1695     CleanupStack::PopAndDestroy( firstname );
  1678 	
  1696     
  1679 	return name;
  1697     return name;
  1680 	}
  1698     }
  1681 
  1699 
  1682 // ---------------------------------------------------------------------------
  1700 // ---------------------------------------------------------------------------
  1683 // CFSEmailUiContactHandler::DoRemoteLookupL
  1701 // CFSEmailUiContactHandler::DoRemoteLookupL
  1684 // ---------------------------------------------------------------------------
  1702 // ---------------------------------------------------------------------------
  1685 //
  1703 //
  1686 void CFSEmailUiContactHandler::DoRemoteLookupL( CFSMailBox& aMailBox,
  1704 void CFSEmailUiContactHandler::DoRemoteLookupL( CFSMailBox& aMailBox,
  1687     const TDesC& aQueryString,
  1705     const TDesC& aQueryString,
  1688 	CPbkxRemoteContactLookupServiceUiContext::TResult& aResult,
  1706     CPbkxRemoteContactLookupServiceUiContext::TResult& aResult,
  1689 	CPbkxRemoteContactLookupServiceUiContext::TMode aContext )
  1707     CPbkxRemoteContactLookupServiceUiContext::TMode aContext )
  1690 	{
  1708     {
  1691     FUNC_LOG;
  1709     FUNC_LOG;
  1692    	TUid protocolUid = TUid::Null();
  1710     TUid protocolUid = TUid::Null();
  1693 	TUint accountId = 0;
  1711     TUint accountId = 0;
  1694 	aMailBox.GetRCLInfo( protocolUid, accountId );
  1712     aMailBox.GetRCLInfo( protocolUid, accountId );
  1695 	const TPbkxRemoteContactLookupProtocolAccountId KAccountId(
  1713     const TPbkxRemoteContactLookupProtocolAccountId KAccountId(
  1696 		protocolUid, accountId );
  1714         protocolUid, accountId );
  1697 		
  1715         
  1698 
  1716 
  1699 	CPbkxRemoteContactLookupEnv* env = CPbkxRemoteContactLookupEnv::NewL();
  1717     CPbkxRemoteContactLookupEnv* env = CPbkxRemoteContactLookupEnv::NewL();
  1700 	CleanupStack::PushL( env );
  1718     CleanupStack::PushL( env );
  1701 
  1719 
  1702 	MPbkxRemoteContactLookupServiceUi* serviceUi = env->ServiceUiL();
  1720     MPbkxRemoteContactLookupServiceUi* serviceUi = env->ServiceUiL();
  1703 
  1721 
  1704 	// If you want test with RCL dummyContactDatabase, KAccountId = serviceUi->DefaultAccountIdL();
  1722     // If you want test with RCL dummyContactDatabase, KAccountId = serviceUi->DefaultAccountIdL();
  1705 	MPbkxRemoteContactLookupServiceUi::TContextParams params = { KAccountId, aContext };
  1723     MPbkxRemoteContactLookupServiceUi::TContextParams params = { KAccountId, aContext };
  1706 
  1724 
  1707 	CPbkxRemoteContactLookupServiceUiContext* ctx( NULL );
  1725     CPbkxRemoteContactLookupServiceUiContext* ctx( NULL );
  1708 	ctx = serviceUi->NewContextL( params );
  1726     ctx = serviceUi->NewContextL( params );
  1709 
  1727 
  1710 	CleanupStack::PushL( ctx ); 
  1728     CleanupStack::PushL( ctx ); 
  1711 
  1729 
  1712 	ctx->ExecuteL( aQueryString, aResult );
  1730     ctx->ExecuteL( aQueryString, aResult );
  1713 
  1731 
  1714 	CleanupStack::PopAndDestroy( ctx );
  1732     CleanupStack::PopAndDestroy( ctx );
  1715 	CleanupStack::PopAndDestroy( env );
  1733     CleanupStack::PopAndDestroy( env );
  1716 
  1734 
  1717 	}
  1735     }
  1718 
  1736 
  1719 
  1737 
  1720 // ---------------------------------------------------------------------------
  1738 // ---------------------------------------------------------------------------
  1721 // Displays call query
  1739 // Displays call query
  1722 // ---------------------------------------------------------------------------
  1740 // ---------------------------------------------------------------------------
  1723 //
  1741 //
  1724 TBool CFSEmailUiContactHandler::CallQueryL(
  1742 TBool CFSEmailUiContactHandler::CallQueryL(
  1725     const TDesC& aDisplayName )
  1743     const TDesC& aDisplayName )
  1726 	{
  1744     {
  1727     FUNC_LOG;
  1745     FUNC_LOG;
  1728 	TInt answer = 0;
  1746     TInt answer = 0;
  1729 	
  1747     
  1730 	if ( aDisplayName.Length() )
  1748     if ( aDisplayName.Length() )
  1731 	    {
  1749         {
  1732 	    if ( iUseSenderText )
  1750         if ( iUseSenderText )
  1733 	    	{
  1751             {
  1734 	    	answer = TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_CALL_SENDER_QUERY, 
  1752             answer = TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_CALL_SENDER_QUERY, 
  1735 															aDisplayName );
  1753                                                             aDisplayName );
  1736 	    	}
  1754             }
  1737 	    else
  1755         else
  1738 	    	{
  1756             {
  1739 	    	answer = TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_UI_VIEWER_CALL_HOTSPOT, 
  1757             answer = TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_UI_VIEWER_CALL_HOTSPOT, 
  1740 															    aDisplayName );
  1758                                                                 aDisplayName );
  1741 	    	}
  1759             }
  1742 	    }
  1760         }
  1743 	else // Show basic note if display name is not available.
  1761     else // Show basic note if display name is not available.
  1744 	    {
  1762         {
  1745 	    _LIT(KEmpty, "");
  1763         _LIT(KEmpty, "");
  1746 	    // Create dialog
  1764         // Create dialog
  1747 	    CFSEmailUiCallDialog* queryNote = new ( ELeave ) CFSEmailUiCallDialog();
  1765         CFSEmailUiCallDialog* queryNote = new ( ELeave ) CFSEmailUiCallDialog();
  1748 	    CleanupStack::PushL( queryNote ); 
  1766         CleanupStack::PushL( queryNote ); 
  1749         // Createa and set text
  1767         // Createa and set text
  1750 	    HBufC* querytext = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_CALL_HOTSPOT, KEmpty );       
  1768         HBufC* querytext = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEWER_CALL_HOTSPOT, KEmpty );       
  1751 	    TPtr pointer = querytext->Des();
  1769         TPtr pointer = querytext->Des();
  1752 	    _LIT(KLineBreak, "\n");
  1770         _LIT(KLineBreak, "\n");
  1753         AknTextUtils::StripCharacters( pointer, KLineBreak );
  1771         AknTextUtils::StripCharacters( pointer, KLineBreak );
  1754 	    queryNote->SetPromptL( *querytext );       
  1772         queryNote->SetPromptL( *querytext );       
  1755 	    CleanupStack::PopAndDestroy( querytext );
  1773         CleanupStack::PopAndDestroy( querytext );
  1756         CleanupStack::Pop( queryNote );
  1774         CleanupStack::Pop( queryNote );
  1757         // Show note.
  1775         // Show note.
  1758         answer = queryNote->ExecuteLD( R_FSEMAIL_QUERY_DIALOG );
  1776         answer = queryNote->ExecuteLD( R_FSEMAIL_QUERY_DIALOG );
  1759 	    }
  1777         }
  1760 	
  1778     
  1761 	return answer;
  1779     return answer;
  1762 	}
  1780     }
  1763 
  1781 
  1764 
  1782 
  1765 
  1783 
  1766 // ---------------------------------------------------------------------------
  1784 // ---------------------------------------------------------------------------
  1767 // Creates copy of given CLS items and appends them to given array.
  1785 // Creates copy of given CLS items and appends them to given array.
  1791     iPreviousEmailAddress = NULL;
  1809     iPreviousEmailAddress = NULL;
  1792     iPreviousEmailAddress = aAddress.AllocL();
  1810     iPreviousEmailAddress = aAddress.AllocL();
  1793     }
  1811     }
  1794 
  1812 
  1795 void CFSEmailUiContactHandler::RemoteContactQueryL()
  1813 void CFSEmailUiContactHandler::RemoteContactQueryL()
  1796 	{
  1814     {
  1797 	FUNC_LOG;
  1815     FUNC_LOG;
  1798 	TInt answer = TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_FETCH_FROM_REMOTE_QUERY );
  1816     TInt answer = TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_FETCH_FROM_REMOTE_QUERY );
  1799 	if ( answer )	
  1817     if ( answer )   
  1800 		{
  1818         {
  1801 		LaunchRemoteLookupWithQueryL( *iMailBox, *iPreviousEmailAddress );
  1819         LaunchRemoteLookupWithQueryL( *iMailBox, *iPreviousEmailAddress );
  1802 		}
  1820         }
  1803     else // user cancelled operation inform client to enable its actions (i.e. return search priority)
  1821     else // user cancelled operation inform client to enable its actions (i.e. return search priority)
  1804         {
  1822         {
  1805         ObserverOperationErrorL( CurrentCommand(), KErrCancel );
  1823         ObserverOperationErrorL( CurrentCommand(), KErrCancel );
  1806         }
  1824         }
  1807 
  1825 
  1808 	}
  1826     }
  1809 
  1827 
  1810 TContactHandlerCmd CFSEmailUiContactHandler::CurrentCommand()
  1828 TContactHandlerCmd CFSEmailUiContactHandler::CurrentCommand()
  1811 	{
  1829     {
  1812     FUNC_LOG;
  1830     FUNC_LOG;
  1813 	switch (iState)
  1831     switch (iState)
  1814 		{
  1832         {
  1815 		case EContactHandlerAddToContacts:
  1833         case EContactHandlerAddToContacts:
  1816 			return EAddToContactL;
  1834             return EAddToContactL;
  1817 		case EContactHandlerSearchMatches:
  1835         case EContactHandlerSearchMatches:
  1818 			return ESearchContacts;
  1836             return ESearchContacts;
  1819 		case EContactHandlerShowContactDetails:
  1837         case EContactHandlerShowContactDetails:
  1820 			return EShowContactDetailsL;
  1838             return EShowContactDetailsL;
  1821 		case EContactHandlerGetAddressesFromPhonebook:
  1839         case EContactHandlerGetAddressesFromPhonebook:
  1822 			return EGetAddressesFromPhonebook;
  1840             return EGetAddressesFromPhonebook;
  1823 		case EContactHandlerCallToContactByEmail:
  1841         case EContactHandlerCallToContactByEmail:
  1824 			return ECallToContact;
  1842             return ECallToContact;
  1825 		case EContactHandlerCreateMessage:
  1843         case EContactHandlerCreateMessage:
  1826 			return ECreateMessage;
  1844             return ECreateMessage;
  1827 		default:
  1845         default:
  1828 			break;
  1846             break;
  1829 		}
  1847         }
  1830 	return EIdle;
  1848     return EIdle;
  1831 	}
  1849     }
  1832 
  1850 
  1833 void CFSEmailUiContactHandler::ClearObservers()
  1851 void CFSEmailUiContactHandler::ClearObservers()
  1834     {
  1852     {
  1835     iHandlerObserver = NULL;
  1853     iHandlerObserver = NULL;
  1836     }
  1854     }
  1843         iHandlerObserver->OperationErrorL( aCmd, aErrorCode ); 
  1861         iHandlerObserver->OperationErrorL( aCmd, aErrorCode ); 
  1844         iHandlerObserver = NULL;
  1862         iHandlerObserver = NULL;
  1845         }
  1863         }
  1846     }
  1864     }
  1847 
  1865 
       
  1866 void CFSEmailUiContactHandler::CCASimpleNotifyL( TNotifyType aType, TInt /*aReason*/ )
       
  1867     {
       
  1868     if ( MCCAObserver::EExitEvent == aType )
       
  1869         {
       
  1870         // Calling Close() for iConnection will close the running 
       
  1871         // CCApplication, so be careful when using it
       
  1872         if ( iConnection )
       
  1873             {
       
  1874             iConnection->Close();
       
  1875             iConnection = NULL;
       
  1876             }
       
  1877         }
       
  1878     }