phonebookui/Phonebook2/CommandsExtension/src/CPbk2MergeContactsCmd.cpp
branchRCL_3
changeset 57 2666d9724c76
parent 32 2828b4d142c0
child 64 c1e8ba0c2b16
equal deleted inserted replaced
45:34879f5cfc63 57:2666d9724c76
    37 #include <CPbk2StoreConfiguration.h>
    37 #include <CPbk2StoreConfiguration.h>
    38 #include <CPbk2StorePropertyArray.h>
    38 #include <CPbk2StorePropertyArray.h>
    39 #include <CPbk2StoreProperty.h>
    39 #include <CPbk2StoreProperty.h>
    40 #include <Pbk2StoreProperty.hrh>
    40 #include <Pbk2StoreProperty.hrh>
    41 #include <Pbk2ProcessDecoratorFactory.h>
    41 #include <Pbk2ProcessDecoratorFactory.h>
       
    42 #include <MPbk2ContactNameFormatter.h>
    42 
    43 
    43 #include <CPbk2MergeConflictsDlg.h>
    44 #include <CPbk2MergeConflictsDlg.h>
    44 #include <CPbk2MergePhotoConflictDlg.h>
    45 #include <CPbk2MergePhotoConflictDlg.h>
    45 
    46 
    46 #include <Pbk2UIControls.rsg> 
    47 #include <Pbk2UIControls.rsg> 
   393     
   394     
   394     MVPbkContactStore& store = iStoreContactFirst->ParentStore();
   395     MVPbkContactStore& store = iStoreContactFirst->ParentStore();
   395     iMergedContact = store.CreateNewContactLC();
   396     iMergedContact = store.CreateNewContactLC();
   396     CleanupStack::Pop();
   397     CleanupStack::Pop();
   397     
   398     
   398     TInt mergedFieldsCount = iMergeResolver->CountMerged();
   399     // the conflict thumbnail data's field, used for comparing
   399     // add merged fields
   400     MVPbkStoreContactField* thumbnailPicField = NULL;
   400     for ( TInt i = 0; i < mergedFieldsCount; i++ )
       
   401         {
       
   402         MVPbkStoreContactField& field = iMergeResolver->GetMergedAt( i );
       
   403         AddFieldToMergedContactL( field );
       
   404         }
       
   405     
   401     
   406     TInt conflictCount = iMergeResolver->CountConflicts();
   402     TInt conflictCount = iMergeResolver->CountConflicts();
   407     // add conflicted fields
   403     // add conflicted fields
   408     for ( TInt i = 0; i < conflictCount; i++ )
   404     for ( TInt i = 0; i < conflictCount; i++ )
   409         {
   405         {
   416         /// if newFields == 0 not resolved conflict exist
   412         /// if newFields == 0 not resolved conflict exist
   417         
   413         
   418         for ( TInt j = 0; j < newFields; j++ )
   414         for ( TInt j = 0; j < newFields; j++ )
   419             {
   415             {
   420             MVPbkStoreContactField* field = fields[ j ];
   416             MVPbkStoreContactField* field = fields[ j ];
       
   417             const MVPbkFieldType* fieldType = field->BestMatchingFieldType();
       
   418             
       
   419             // assign value to thumnailPicField with the field's value
       
   420             if ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_THUMBNAILPIC )
       
   421                 {
       
   422                 thumbnailPicField = field;
       
   423                 }
   421             AddFieldToMergedContactL( *field );
   424             AddFieldToMergedContactL( *field );
   422             }
   425             } 
   423         fields.Close();
   426         fields.Close();
       
   427         }
       
   428     
       
   429     TInt mergedFieldsCount = iMergeResolver->CountMerged();
       
   430         
       
   431     // add merged fields
       
   432     for ( TInt i = 0; i < mergedFieldsCount; i++ )
       
   433         {
       
   434         MVPbkStoreContactField& field = iMergeResolver->GetMergedAt( i );
       
   435         const MVPbkFieldType* fieldType = field.BestMatchingFieldType();
       
   436         
       
   437         // avoid merging filePath when the two field unmatched to a contact
       
   438         if ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_CALLEROBJIMG && thumbnailPicField )
       
   439             {
       
   440             if ( !thumbnailPicField->ParentContact().IsSame( field.ParentContact() ) )
       
   441                 {
       
   442                 continue;
       
   443                 }
       
   444             }
       
   445         AddFieldToMergedContactL( field );
   424         }
   446         }
   425     
   447     
   426     iContactToCommit = new ( ELeave ) CArrayPtrFlat<MVPbkStoreContact>( 1 );
   448     iContactToCommit = new ( ELeave ) CArrayPtrFlat<MVPbkStoreContact>( 1 );
   427     iContactToCommit->AppendL( iMergedContact );
   449     iContactToCommit->AppendL( iMergedContact );
   428     iCommitOperation = iContactManager->CommitContactsL( iContactToCommit->Array(), *this );
   450     iCommitOperation = iContactManager->CommitContactsL( iContactToCommit->Array(), *this );
   437     HBufC* unnamed = StringLoader::LoadLC( R_QTN_PHOB_UNNAMED );
   459     HBufC* unnamed = StringLoader::LoadLC( R_QTN_PHOB_UNNAMED );
   438     CDesCArrayFlat* strings = new(ELeave) CDesCArrayFlat( 3 );
   460     CDesCArrayFlat* strings = new(ELeave) CDesCArrayFlat( 3 );
   439     CleanupStack::PushL( strings );
   461     CleanupStack::PushL( strings );
   440     
   462     
   441     HBufC* prompt = NULL;
   463     HBufC* prompt = NULL;
   442     if ( (iFirstContactString->Length() > 0 || iSecondContactString->Length() > 0)
   464 
   443             && iMergedContactString->Length() > 0 )
   465     if ( ( iFirstContactString->Compare( *unnamed ) || iSecondContactString->Compare( *unnamed ) )
   444         {
   466             && iMergedContactString->Compare( *unnamed ) )
   445         if ( 0 != iFirstContactString->Length() )
   467         {
   446             {
   468         strings->AppendL( *iFirstContactString );
   447             strings->AppendL( *iFirstContactString );
   469         strings->AppendL( *iSecondContactString );
   448             }
       
   449         else
       
   450             {
       
   451             strings->AppendL( *unnamed );
       
   452             }
       
   453         if ( 0 != iSecondContactString->Length() )
       
   454             {
       
   455             strings->AppendL( *iSecondContactString );
       
   456             }
       
   457         else
       
   458             {
       
   459             strings->AppendL( *unnamed );
       
   460             }
       
   461         strings->AppendL( *iMergedContactString );
   470         strings->AppendL( *iMergedContactString );
   462 
   471 
   463         prompt = StringLoader::LoadLC( R_QTN_PHOB_NOTE_CONTACTS_WERE_MERGED, *strings );
   472         prompt = StringLoader::LoadLC( R_QTN_PHOB_NOTE_CONTACTS_WERE_MERGED, *strings );
   464         }
   473         }
   465     else
   474     else
   481 // CPbk2MergeContactsCmd::ContactAsStringLC
   490 // CPbk2MergeContactsCmd::ContactAsStringLC
   482 // --------------------------------------------------------------------------
   491 // --------------------------------------------------------------------------
   483 //
   492 //
   484 HBufC* CPbk2MergeContactsCmd::ContactAsStringL( MVPbkStoreContact* aStoreContact )
   493 HBufC* CPbk2MergeContactsCmd::ContactAsStringL( MVPbkStoreContact* aStoreContact )
   485     {
   494     {
   486     _LIT(KResultFormat, "%S %S");
       
   487     TPtrC firstName( KNullDesC() );
       
   488     TPtrC lastName( KNullDesC() );
       
   489 	
       
   490     MVPbkStoreContactFieldCollection& fields = aStoreContact->Fields();
   495     MVPbkStoreContactFieldCollection& fields = aStoreContact->Fields();
   491     for ( TInt i(0); i < fields.FieldCount(); ++i )
       
   492         {
       
   493         MVPbkStoreContactField& field = fields.FieldAt( i );
       
   494         const MVPbkFieldType* fieldType = field.BestMatchingFieldType();
       
   495         if ( fieldType )
       
   496             {
       
   497             if ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_FIRSTNAME )
       
   498                 {
       
   499                 MVPbkContactFieldData& data = field.FieldData();
       
   500                 __ASSERT_DEBUG( data.DataType() == EVPbkFieldStorageTypeText, Panic( EPbk2WrongTypeOfData ) );
       
   501                 MVPbkContactFieldTextData& textData = MVPbkContactFieldTextData::Cast( data );
       
   502                 firstName.Set( textData.Text() );
       
   503                 }
       
   504             else if ( fieldType->FieldTypeResId() == R_VPBK_FIELD_TYPE_LASTNAME )
       
   505                 {
       
   506                 MVPbkContactFieldData& data = field.FieldData();
       
   507                 __ASSERT_DEBUG( data.DataType() == EVPbkFieldStorageTypeText, Panic( EPbk2WrongTypeOfData ) );
       
   508                 MVPbkContactFieldTextData& textData = MVPbkContactFieldTextData::Cast( data );
       
   509                 lastName.Set( textData.Text() );        
       
   510                 }
       
   511             }
       
   512         }
       
   513     
       
   514     HBufC* result = NULL;
   496     HBufC* result = NULL;
   515     if ( firstName.Length() > 0 && lastName.Length() > 0 )
   497     const TInt KDefaultListFormatting = 
   516         {
   498             MPbk2ContactNameFormatter::EDisableCompanyNameSeparator;
   517         result = HBufC::NewL( firstName.Length() + lastName.Length() + KResultFormat().Length() );
   499     result = Phonebook2::Pbk2AppUi()->
   518         TPtr resAsDes = result->Des();
   500             ApplicationServices().NameFormatter().GetContactTitleL( fields, KDefaultListFormatting );
   519         resAsDes.Format( KResultFormat, &firstName, &lastName );
   501     if( !result )
   520         }
   502         {
   521     else if ( firstName.Length() > 0 )
   503         result = StringLoader::LoadLC( R_QTN_PHOB_UNNAMED );
   522         {
   504         CleanupStack::Pop( result );
   523         result = firstName.AllocL(); 
       
   524         }    
       
   525     else
       
   526         {
       
   527         result = lastName.AllocL();
       
   528         }
   505         }
   529     return result;
   506     return result;
   530     }
   507     }
   531 
   508 
   532 // --------------------------------------------------------------------------
   509 // --------------------------------------------------------------------------