emailuis/emailui/src/FreestyleEmailUiContactHandler.cpp
branchRCL_3
changeset 73 c8382f7b54ef
parent 70 968773a0b6ef
child 80 726fba06891a
--- a/emailuis/emailui/src/FreestyleEmailUiContactHandler.cpp	Tue Sep 14 20:48:24 2010 +0300
+++ b/emailuis/emailui/src/FreestyleEmailUiContactHandler.cpp	Wed Sep 15 11:52:37 2010 +0300
@@ -83,7 +83,14 @@
 
 //Constants
 const TInt KInternetCallPreferred = 1;
-
+/** UID of the CCA details view plugin implementation 
+  * ( from ccappdetailsviewpluginuids.hrh ) */
+const TInt KCCADetailsViewPluginImplmentationUid = 0x200159E7;
+/**  CCA Application 
+ *  ( from ccauids.h )*/ 
+const TInt KCCAAppUID = 0x2000B609;
+/** Phonebook2 App UID */
+const TInt KPbkUID3 = 0x101f4cce;
 
 CFSEmailUiContactHandler* CFSEmailUiContactHandler::NewL( RFs& aSession )
     {
@@ -336,13 +343,11 @@
             {
             dialData->SetCallType( CAiwDialData::EAIWVoiP );            
             }
-        // <cmail> video call
         else if ( iVideoCall )
             {
             iVideoCall = EFalse;
             dialData->SetCallType( CAiwDialData::EAIWForcedVideo );
             }
-        // </cmail>
         else
             {
             dialData->SetCallType( CAiwDialData::EAIWVoice );           
@@ -354,13 +359,11 @@
             {
             dialData->SetCallType( CAiwDialData::EAIWVoiP );            
             }
-        // <cmail> video call
         else if ( iVideoCall ) 
             {
             iVideoCall = EFalse;
             dialData->SetCallType( CAiwDialData::EAIWForcedVideo );
             }
-        // </cmail>
         else
             {
             dialData->SetCallType( CAiwDialData::EAIWVoice );           
@@ -501,22 +504,22 @@
         }
     }
 
-// <cmail> video call
 // ---------------------------------------------------------------------------
 // Enables/disables video call.
 // ---------------------------------------------------------------------------
 //
 void CFSEmailUiContactHandler::SetVideoCall( TBool aState )
     {
+    FUNC_LOG;
     iVideoCall = aState;
     }
-// </cmail>
 
-/////////////////////////////////////////////////////////////////////////////
+// ---------------------------------------------------------------------------
 // CFSEmailUiContactHandler::GetSmsAddressFromPhonebookAndSendL
+// ---------------------------------------------------------------------------
 //
-/////////////////////////////////////////////////////////////////////////////
-void CFSEmailUiContactHandler::GetSmsAddressFromPhonebookAndSendL( MVPbkContactLink* aContactLink )
+void CFSEmailUiContactHandler::GetSmsAddressFromPhonebookAndSendL( 
+    MVPbkContactLink* aContactLink )
     {
     FUNC_LOG;
     if ( iState == EContactHandlerIdle )
@@ -550,12 +553,12 @@
         }
     }
 
-/////////////////////////////////////////////////////////////////////////////
+// ---------------------------------------------------------------------------
 // CFSEmailUiContactHandler::GetMmsAddressFromPhonebookAndSendL
+// ---------------------------------------------------------------------------
 //
-/////////////////////////////////////////////////////////////////////////////
-void CFSEmailUiContactHandler::GetMmsAddressFromPhonebookAndSendL( MVPbkContactLink* aContactLink,
-                                                            TBool aIsVoiceMessage )
+void CFSEmailUiContactHandler::GetMmsAddressFromPhonebookAndSendL(
+    MVPbkContactLink* aContactLink, TBool aIsVoiceMessage )
     {
     FUNC_LOG;
     if ( iState == EContactHandlerIdle )
@@ -596,10 +599,35 @@
         }
     }
 
-/////////////////////////////////////////////////////////////////////////////
+// ---------------------------------------------------------------------------
+// Retrieves the first contact in contact link set.
+// ---------------------------------------------------------------------------
+//
+void CFSEmailUiContactHandler::RetrieveContactsL()
+    {
+    FUNC_LOG;
+    if ( iLinksSet->Count() )
+        {
+        delete iCurrentLink;
+        iCurrentLink = NULL;
+
+        iCurrentLink = iLinksSet->At(0).CloneLC();
+        CleanupStack::Pop();
+
+        delete iLinkOperationFetch;
+        iLinkOperationFetch = NULL;
+
+        //Async operation, callback VPbkSingleContactOperationCompleteL
+        //Error situations: VPbkSingleContactOperationFailed
+        iLinkOperationFetch = iContactManager->RetrieveContactL( 
+            *iCurrentLink, *this );
+        }
+    }
+
+// ---------------------------------------------------------------------------
 // CFSEmailUiContactHandler::ArrayUpdatedL
+// ---------------------------------------------------------------------------
 //
-/////////////////////////////////////////////////////////////////////////////
 void CFSEmailUiContactHandler::ArrayUpdatedL(
     const RPointerArray<CFSEmailUiClsItem>& aMatchingItems )
     {
@@ -628,7 +656,7 @@
                 {
                 if ( !iSearchMatch )
                     {
-                    iSearchMatch = CFSEmailUiClsItem::NewL();           
+                    iSearchMatch = CFSEmailUiClsItem::NewL();
                     }
                 iSearchMatch->SetDisplayNameL( aMatchingItems[0]->DisplayName() );
                 iSearchMatch->SetEmailAddressL( aMatchingItems[0]->EmailAddress() );
@@ -671,9 +699,9 @@
                 {
                 iCachingInProgressError = EFalse;
                 iState = EContactHandlerIdle;
-        iHandlerObserver->OperationErrorL( ESearchContacts, aErrorCode );
-        }
-    }
+                iHandlerObserver->OperationErrorL( ESearchContacts, aErrorCode );
+                }
+            }
         else
             {
             iState = EContactHandlerIdle;
@@ -692,14 +720,12 @@
         MVPbkStoreContact* aContact )
     {
     FUNC_LOG;
-//inform also client in case of error to enable client's actions (i.e. return search priority)
-//  TRAP_IGNORE( VPbkSingleContactOperationCompleteL( aOperation, aContact) );
+    //inform also client in case of error to enable client's actions (i.e. return search priority)
     TRAPD(error, VPbkSingleContactOperationCompleteL( aOperation, aContact) );
     if ( error != KErrNone )
         {
         TRAP_IGNORE(ObserverOperationErrorL( CurrentCommand(), error ));
         }
-//
     }
 
 void CFSEmailUiContactHandler::VPbkSingleContactOperationCompleteL(
@@ -720,23 +746,28 @@
         CleanupResetAndDestroyClosePushL( emailAddresses );
         GetContactFieldsL( iFirstnameFields, firstname, aContact );
         GetContactFieldsL( iLastnameFields, lastname, aContact );
-    
+
         // Create display name, this will be used in UI.
         TInt dispNameLength = 1;
         if ( firstname.Count() ) dispNameLength += firstname[0]->Length();
         if ( lastname.Count() ) dispNameLength += lastname[0]->Length();
         HBufC* displayname = HBufC::NewLC( dispNameLength );
-        
-        if ( firstname.Count() )
+        TPtr displaynamePtr = displayname->Des();
+        if ( firstname.Count() && firstname[0]->Length() )
             {
-            displayname->Des().Copy( *firstname[0] );
-            displayname->Des().Append( KSpace );
+            displaynamePtr.Copy( *firstname[0] );
+
+            // Append space only when both firstname and lastname are present.
+            if ( lastname.Count() && lastname[0]->Length() )
+                {
+                displaynamePtr.Append( KSpace );
+                }
             }
         if ( lastname.Count() )
             {
-            displayname->Des().Append( *lastname[0] );
+            displaynamePtr.Append( *lastname[0] );
             }
-        
+
         // retrieve selected email address
         MVPbkStoreContactFieldCollection& fields = aContact->Fields();
         MVPbkBaseContactField* selectedField = fields.RetrieveField( *iCurrentLink );
@@ -810,7 +841,7 @@
         }
     
     else if ( (iLinkOperationFetch == &aOperation) && (iState == EContactHandlerCallToContactByEmail ) )
-    {   
+        {
         CleanupDeletePushL( aContact );
     
         RPointerArray<HBufC> phonenumbers;
@@ -840,7 +871,7 @@
                 }
             else
                 {
-                TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_UI_VIEWER_NO_PHONE_NUMBER );                   
+                TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_UI_VIEWER_NO_PHONE_NUMBER );
 //no phone number found - inform client to enable its actions (i.e. return search priority)
                 ObserverOperationErrorL( EFindAndCallToContactByEmailL, KErrNotFound );
                 }
@@ -848,10 +879,12 @@
             }
         
         CleanupStack::PopAndDestroy( aContact );
-    }
+        }
     // Addition to get contact for message creation.
-    else if ( (iLinkOperationFetch == &aOperation) && ( iMsgCreationHelperState == EContactHandlerGetSmsAddressFromPhonebook || 
-            iMsgCreationHelperState == EContactHandlerGetMmsAddressFromPhonebook || iMsgCreationHelperState == EContactHandlerGetVoiceMsgAddressFromPhonebook ) )
+    else if ( (iLinkOperationFetch == &aOperation) && 
+                ( iMsgCreationHelperState == EContactHandlerGetSmsAddressFromPhonebook || 
+                  iMsgCreationHelperState == EContactHandlerGetMmsAddressFromPhonebook || 
+                  iMsgCreationHelperState == EContactHandlerGetVoiceMsgAddressFromPhonebook ) )
         {
         if ( iContactForMsgCreation )
             {
@@ -916,7 +949,11 @@
         }
     }
 
-
+// ---------------------------------------------------------------------------
+// From MVPbkContactStoreListObserver.
+// Called when the opening process is complete. 
+// ---------------------------------------------------------------------------
+//
 void CFSEmailUiContactHandler::OpenComplete()
     {
     FUNC_LOG;
@@ -924,6 +961,12 @@
         {
         iOpenComplete = ETrue;
         }
+
+    if ( iState == EContactHandlerGetAddressesFromPhonebook )
+        {
+        // Start retrieving contacts when stores are opened.
+        TRAP_IGNORE( RetrieveContactsL() );
+        }
     }
 
 void CFSEmailUiContactHandler::StoreReady(MVPbkContactStore& /*aContactStore*/)
@@ -968,37 +1011,23 @@
             emptyItems.Close();
             iHandlerObserver = NULL;
             }
-        
         }
     else if ( (aCmdId == KAiwCmdSelect) && (iState == EContactHandlerGetAddressesFromPhonebook) &&
               (aEventId == KAiwEventCompleted))
         {
-
         TInt index = 0;
         const TAiwGenericParam* param =
-        aEventParamList.FindFirst(index, EGenericParamContactLinkArray);
-        if (param)
+            aEventParamList.FindFirst( index, EGenericParamContactLinkArray );
+        if ( param )
             {
             TPtrC8 contactLinks = param->Value().AsData();
-
-            iLinksSet = iContactManager->CreateLinksLC(contactLinks);
+            iLinksSet = iContactManager->CreateLinksLC( contactLinks );
             CleanupStack::Pop();
-            if ( iLinksSet->Count() )
-                {
-                delete iCurrentLink;
-                iCurrentLink = NULL;
 
-                iCurrentLink = iLinksSet->At(0).CloneLC();
-                CleanupStack::Pop();
-                //Async operation, callback VPbkSingleContactOperationCompleteL
-                //Error situations: VPbkSingleContactOperationFailed
-                iLinkOperationFetch = iContactManager->RetrieveContactL( 
-                    iLinksSet->At(0), *this );
-                }
-
+            // Open all stores before retrieving contact details.
+            // Async operation, calls OpenComplete when all stores are opened.
             iContactManager->ContactStoresL().OpenAllL( *this );
             }
-
         }
     else if ( (aCmdId == KAiwCmdSelect) && (iState == EContactHandlerGetSmsAddressFromPhonebook) &&
               (aEventId == KAiwEventCompleted))
@@ -1066,9 +1095,7 @@
     iUseSenderText(EFalse),
     iFs( aSession ),
     iCachingInProgressError(EFalse),
-    // <cmail> video call
     iVideoCall( EFalse )
-    // </cmail>
     {
     FUNC_LOG;
     }
@@ -1112,13 +1139,11 @@
             }
         else
             {
-            TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_UI_VIEWER_NO_PHONE_NUMBER );                   
+            TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_UI_VIEWER_NO_PHONE_NUMBER );
             }
-        // <cmail> video call flag needs to be cleared
         iVideoCall = EFalse;
-        // </cmail>
         iState = EContactHandlerIdle;
-        }               
+        }
     else if ( aMatchingItems.Count() > 0 ) // Call to one directly
         {
         // Create contact item in which to copy number or address, async operation.
@@ -1136,7 +1161,7 @@
         //Async operation, callback VPbkSingleContactOperationCompleteL
         //Error situations: VPbkSingleContactOperationFailed
         iLinkOperationFetch = iContactManager->RetrieveContactL(
-            *iCurrentLink, *this);
+            *iCurrentLink, *this );
         }
     }
 
@@ -1412,8 +1437,8 @@
         param->SetContactDataL( link16->Des() );
 
         // switch to details view
-        const TUid uid = TUid::Uid( 0x200159E7 ); 
-        param->SetLaunchedViewUid( uid);
+        const TUid uid = TUid::Uid( KCCADetailsViewPluginImplmentationUid ); 
+        param->SetLaunchedViewUid( uid );
 
         // Launching the  CCA application
         iConnection->LaunchAppL( *param, this );
@@ -1432,6 +1457,70 @@
     }
 
 // ---------------------------------------------------------------------------
+// Return contact details view Id 
+// ---------------------------------------------------------------------------
+//
+TUid CFSEmailUiContactHandler::GetDetailsViewUid()
+	{
+	  return TUid::Uid( KCCADetailsViewPluginImplmentationUid ); 
+	}
+
+// ---------------------------------------------------------------------------
+// Return contact detail App Id (CCAPP) 
+// ---------------------------------------------------------------------------
+//
+TUid CFSEmailUiContactHandler::GetDetailsAppUid()
+	{
+	return TUid::Uid( KCCAAppUID ); 
+	}
+ 
+// ---------------------------------------------------------------------------
+// Close Details view using CCApplication
+// ---------------------------------------------------------------------------
+//
+void CFSEmailUiContactHandler::CloseContactDetailsL()
+	{
+	 CCASimpleNotifyL( MCCAObserver::EExitEvent,0 );   
+	 iContactDetailsClosed = ETrue;
+	}
+
+// ---------------------------------------------------------------------------
+// Check if Contact Details view was closed using CloseContactDetailsL method
+// ---------------------------------------------------------------------------
+//
+TBool CFSEmailUiContactHandler::WasDetailsClosed()
+	{
+	return iContactDetailsClosed;
+	}
+
+// ---------------------------------------------------------------------------
+// Reopen Details view for last addres or bring contacts app to foreground
+// ---------------------------------------------------------------------------
+//
+void CFSEmailUiContactHandler::ReopenContactDetailsL(RWsSession& session )
+	{
+	if( iPreviousEmailAddress )
+        {
+		HBufC* emailAddress = iPreviousEmailAddress->AllocLC();
+		ShowContactDetailsL( *emailAddress, EContactUpdateEmail, NULL );
+		CleanupStack::PopAndDestroy( emailAddress );
+		iContactDetailsClosed = EFalse;
+		}
+	else // if contact wasn't open from email
+	    {
+	    // Try to bring calling external app into foreground if found
+	    TApaTaskList taskList( session );
+	    TApaTask contAppTask = taskList.FindApp( TUid::Uid( KPbkUID3 ) );
+	    if ( contAppTask.Exists() )
+	        {
+	        contAppTask.BringToForeground();
+	        iContactDetailsClosed = EFalse;
+	        }
+	    }
+	}
+
+
+// ---------------------------------------------------------------------------
 // CFSEmailUiContactHandler::FindContactLinkL
 // Searches contacts matching with the given email address
 // ---------------------------------------------------------------------------
@@ -1454,17 +1543,16 @@
     iEmailFields.Append( R_VPBK_FIELD_TYPE_EMAILGEN );
     iEmailFields.Append( R_VPBK_FIELD_TYPE_EMAILWORK );
     iEmailFields.Append( R_VPBK_FIELD_TYPE_EMAILHOME );
-    
+
     iFirstnameFields.Append( R_VPBK_FIELD_TYPE_FIRSTNAME );
     iLastnameFields.Append( R_VPBK_FIELD_TYPE_LASTNAME );
-    
+
     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_LANDPHONEHOME );
     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_MOBILEPHONEWORK );
     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_MOBILEPHONEHOME );
     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_LANDPHONEWORK );
     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_LANDPHONEGEN );
     iPhoneNumberFields.Append( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN );
-    
     }
 
 void CFSEmailUiContactHandler::ResetFieldIds()
@@ -1478,7 +1566,7 @@
 
 
 // -----------------------------------------------------------------------------
-// CFSEmailUiContactHandler::LaunchRemoteLookupL
+// CFSEmailUiContactHandler::GetNameAndEmailFromRemoteLookupL
 // -----------------------------------------------------------------------------
 TBool CFSEmailUiContactHandler::GetNameAndEmailFromRemoteLookupL( CFSMailBox& aMailBox,
     const TDesC& aQueryString, TDes& aDisplayname, TDes& aEmailAddress )
@@ -1493,6 +1581,7 @@
          CPbkxRemoteContactLookupServiceUiContext::TResult::EExitContactSelected )
         {
         GetNameAndEmail( aDisplayname, aEmailAddress, *(result.iSelectedContactItem) );
+        delete result.iSelectedContactItem;
         return ETrue;
         } 
 
@@ -1513,7 +1602,7 @@
     }
 
 // -----------------------------------------------------------------------------
-// CFSEmailUiContactHandler::LaunchRemoteLookupL
+// CFSEmailUiContactHandler::GetNameAndNumberFromRemoteLookupL
 // -----------------------------------------------------------------------------
 HBufC* CFSEmailUiContactHandler::GetNameAndNumberFromRemoteLookupL(
     CFSMailBox& aMailBox, const TDesC& aQuery, RBuf& aPhoneNumber )
@@ -1564,6 +1653,8 @@
     FUNC_LOG;
     iContactObjects.ResetAndDestroy();
     iState = EContactHandlerIdle;
+    delete iCurrentLink;
+    iCurrentLink = NULL;
     delete iLinksSet;
     iLinksSet = NULL;
     delete iLinkOperation;
@@ -1876,7 +1967,7 @@
     iHandlerObserver = NULL;
     }
 
-// <cmail> call observer's MFSEmailUiContactHandlerObserver::OperationErrorL( TContactHandlerCmd aCmd, TInt aError ) 
+// Call observer's MFSEmailUiContactHandlerObserver::OperationErrorL( TContactHandlerCmd aCmd, TInt aError ) 
 void CFSEmailUiContactHandler::ObserverOperationErrorL( TContactHandlerCmd aCmd, TInt aErrorCode )
     {
     if( ( iHandlerObserver ) && ( KErrNone != aErrorCode ) )