phonebookui/Phonebook2/CommandsExtension/src/CPbk2MergeConflict.cpp
changeset 0 e686773b3f54
child 6 e8e3147d53eb
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Phonebook 2 merge conflict.
       
    15  *
       
    16  */
       
    17 
       
    18 // Phonebook2 includes
       
    19 #include <Pbk2AddressTools.h>
       
    20 #include <Pbk2UIControls.rsg>
       
    21 #include <CPbk2PresentationContact.h>
       
    22 #include <CPbk2PresentationContactFieldCollection.h>
       
    23 #include <CPbk2PresentationContactField.h>
       
    24 #include <MPbk2FieldProperty.h>
       
    25 
       
    26 //Virtual Phonebook
       
    27 #include <MVPbkContactFieldTextData.h>
       
    28 #include <MVPbkContactFieldDateTimeData.h>
       
    29 #include <MVPbkContactFieldUriData.h>
       
    30 #include <MVPbkContactFieldBinaryData.h>
       
    31 #include <MVPbkFieldType.h>
       
    32 #include <TVPbkFieldVersitProperty.h>
       
    33 
       
    34 // System includes
       
    35 #include <StringLoader.h>
       
    36 #include <avkon.rsg>
       
    37 
       
    38 #include "CPbk2MergeConflict.h"
       
    39 
       
    40 // Debugging headers
       
    41 #include <Pbk2Debug.h>
       
    42 #include <Pbk2Profile.h>
       
    43 
       
    44 /// Unnamed namespace for local definitions
       
    45 namespace 
       
    46     {
       
    47     const TInt KMaxDateLenght = 64;
       
    48     enum TPbk2PanicCodes
       
    49         {
       
    50         EPbk2NotInitialized,
       
    51         EPbk2NotChosen,
       
    52         EPbk2UnexpectedCase,
       
    53         EPbk2FieldTypeNotExists
       
    54         };
       
    55     
       
    56     void Panic(TPbk2PanicCodes aReason)
       
    57         {
       
    58         _LIT( KPanicText, "CPbk2_Merge_Conflict" );
       
    59         User::Panic( KPanicText, aReason );
       
    60         }
       
    61     } /// namespace
       
    62 
       
    63 // --------------------------------------------------------------------------
       
    64 // CPbk2MergeConflict::GetConflictType
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 EPbk2ConflictType CPbk2MergeConflict::GetConflictType() 
       
    68     {
       
    69     return iConflictType;
       
    70     }
       
    71 
       
    72 // --------------------------------------------------------------------------
       
    73 // CPbk2MergeConflict::CPbk2MergeConflict
       
    74 // --------------------------------------------------------------------------
       
    75 //
       
    76 CPbk2MergeConflict::CPbk2MergeConflict() 
       
    77     {
       
    78     iConflictType = EPbk2ConflictTypeNormal;
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // CPbk2MergeConflict::NewL
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 CPbk2MergeConflict* CPbk2MergeConflict::NewL() 
       
    86     {
       
    87     CPbk2MergeConflict* self = new ( ELeave ) CPbk2MergeConflict();
       
    88     return self;
       
    89     }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CPbk2MergeConflict::GetFieldsL
       
    93 // --------------------------------------------------------------------------
       
    94 //
       
    95 void CPbk2MergeConflict::GetFieldsL(  
       
    96         const MVPbkStoreContactField*& aFieldFirst, 
       
    97         const MVPbkStoreContactField*& aFieldSecond )
       
    98     {
       
    99     __ASSERT_ALWAYS( iFieldFirst && iFieldSecond, Panic( EPbk2NotInitialized ) );
       
   100     
       
   101     aFieldFirst = iFieldFirst;
       
   102     aFieldSecond = iFieldSecond;
       
   103     }
       
   104 
       
   105 // --------------------------------------------------------------------------
       
   106 // CPbk2MergeConflict::AddFields
       
   107 // --------------------------------------------------------------------------
       
   108 //
       
   109 void CPbk2MergeConflict::AddFields(  
       
   110         const MVPbkStoreContactField& aFieldFirst, 
       
   111         const MVPbkStoreContactField& aFieldSecond ) 
       
   112     {
       
   113     iFieldFirst = &aFieldFirst;
       
   114     iFieldSecond = &aFieldSecond;
       
   115     
       
   116     const MVPbkFieldType* fieldType = aFieldFirst.BestMatchingFieldType();
       
   117     __ASSERT_ALWAYS( fieldType, Panic( EPbk2FieldTypeNotExists ) );
       
   118 
       
   119     if( fieldType->NonVersitType() == EVPbkNonVersitTypeCodImage )
       
   120         {
       
   121         iConflictType = EPbk2ConflictTypeImage;
       
   122         }
       
   123     else
       
   124         {
       
   125         TArray<TVPbkFieldVersitProperty> versitPropArr = fieldType->VersitProperties();
       
   126         TInt count = versitPropArr.Count();
       
   127     
       
   128         for( TInt idx = 0; idx < count; idx++ )
       
   129             {
       
   130             TVPbkFieldVersitProperty versitProp = versitPropArr[idx];
       
   131             if( versitProp.Name() == EVPbkVersitNameLOGO ||
       
   132                 versitProp.Name() == EVPbkVersitNamePHOTO )
       
   133                 {
       
   134                 iConflictType = EPbk2ConflictTypeImage;
       
   135                 break;
       
   136                 }
       
   137             }
       
   138         }
       
   139     }
       
   140 
       
   141 // --------------------------------------------------------------------------
       
   142 // CPbk2MergeConflict::GetLabelLC
       
   143 // --------------------------------------------------------------------------
       
   144 //
       
   145 HBufC* CPbk2MergeConflict::GetLabelLC() 
       
   146     {
       
   147     __ASSERT_ALWAYS( iFieldFirst && iFieldSecond, Panic( EPbk2NotInitialized ) );
       
   148     
       
   149     return iFieldFirst->FieldLabel().AllocLC();
       
   150     }
       
   151 
       
   152 // --------------------------------------------------------------------------
       
   153 // CPbk2MergeConflict::GetTextLC
       
   154 // --------------------------------------------------------------------------
       
   155 //
       
   156 HBufC* CPbk2MergeConflict::GetTextLC( EPbk2ConflictedNumber aNumber ) 
       
   157     {
       
   158     __ASSERT_ALWAYS( iFieldFirst && iFieldSecond, Panic( EPbk2NotInitialized ) );
       
   159     
       
   160     const MVPbkStoreContactField* field;
       
   161     
       
   162     if( aNumber == EPbk2ConflictedFirst )
       
   163         {
       
   164         field = iFieldFirst;
       
   165         }
       
   166     else
       
   167         {
       
   168         field = iFieldSecond;
       
   169         }
       
   170     
       
   171     const MVPbkContactFieldData& data = field->FieldData();
       
   172     TVPbkFieldStorageType storageType = data.DataType();
       
   173    
       
   174     HBufC* retText = NULL;
       
   175     
       
   176     switch( storageType )
       
   177         {
       
   178         case EVPbkFieldStorageTypeText:
       
   179             retText = MVPbkContactFieldTextData::Cast( data ).Text().AllocLC();
       
   180             break;
       
   181         case EVPbkFieldStorageTypeUri:
       
   182             retText =  MVPbkContactFieldUriData::Cast( data ).Text().AllocLC();
       
   183             break;
       
   184         case EVPbkFieldStorageTypeBinary:
       
   185             // Bad method for getting binary data, get it from field
       
   186             Panic( EPbk2UnexpectedCase );
       
   187             break;
       
   188         case EVPbkFieldStorageTypeDateTime:
       
   189             {
       
   190             const MVPbkContactFieldDateTimeData& date = 
       
   191                 MVPbkContactFieldDateTimeData::Cast( data );
       
   192 
       
   193             TTime time( date.DateTime() );
       
   194             TBuf<KMaxDateLenght> dateBuffer;
       
   195             HBufC* dateFormat = CCoeEnv::Static()->AllocReadResourceLC
       
   196                 ( R_QTN_DATE_USUAL_WITH_ZERO ); // in avkon.rsg
       
   197             
       
   198             time.FormatL( dateBuffer, *dateFormat, TLocale() );
       
   199             CleanupStack::PopAndDestroy( dateFormat );
       
   200             retText = dateBuffer.AllocLC();
       
   201             }
       
   202             break;
       
   203         default:
       
   204             Panic( EPbk2UnexpectedCase );
       
   205         }
       
   206     TPtr ptr = retText->Des();
       
   207     CustomizeTextValueL( *field, ptr );
       
   208     return retText;
       
   209     }
       
   210 
       
   211 // --------------------------------------------------------------------------
       
   212 // CPbk2MergeConflict::ResolveConflict
       
   213 // --------------------------------------------------------------------------
       
   214 //
       
   215 void CPbk2MergeConflict::ResolveConflict( EPbk2ConflictedNumber aNumber ) 
       
   216     {
       
   217     __ASSERT_ALWAYS( iFieldFirst && iFieldSecond, Panic( EPbk2NotInitialized ) );
       
   218     
       
   219     if( aNumber == EPbk2ConflictedFirst )
       
   220         {
       
   221         iChosenField = iFieldFirst;
       
   222         }
       
   223     else
       
   224         {
       
   225         iChosenField = iFieldSecond;
       
   226         }
       
   227     }
       
   228 
       
   229 // --------------------------------------------------------------------------
       
   230 // CPbk2MergeConflict::GetChosenFieldsL
       
   231 // --------------------------------------------------------------------------
       
   232 //
       
   233 void CPbk2MergeConflict::GetChosenFieldsL( 
       
   234         RPointerArray<MVPbkStoreContactField>& aAddressFields )
       
   235     {
       
   236     __ASSERT_ALWAYS( iFieldFirst && iFieldSecond, Panic( EPbk2NotChosen ) );
       
   237     
       
   238     if ( iChosenField )
       
   239         {
       
   240         aAddressFields.AppendL( iChosenField );
       
   241         }
       
   242     }
       
   243 
       
   244 // --------------------------------------------------------------------------
       
   245 // CPbk2MergeConflict::CustomizeTextValueL
       
   246 // --------------------------------------------------------------------------
       
   247 //
       
   248 void CPbk2MergeConflict::CustomizeTextValueL( const MVPbkStoreContactField& aField, TDes& aBuf )
       
   249     {
       
   250     const MVPbkFieldType* fieldType= aField.BestMatchingFieldType();
       
   251     TVPbkNonVersitFieldType nonVersitType = fieldType->NonVersitType();
       
   252     if ( nonVersitType == EVPbkNonVersitTypeRingTone )
       
   253         {
       
   254         TParsePtr fileName = TParsePtr( aBuf );
       
   255         if ( fileName.NamePresent() )
       
   256             {
       
   257             TPtrC namePtr = fileName.Name();
       
   258             HBufC* name = namePtr.AllocL();
       
   259             aBuf.Copy( *name );
       
   260             delete name;
       
   261             }
       
   262         }
       
   263     }
       
   264 
       
   265 // --------------------------------------------------------------------------
       
   266 // CPbk2MergeConflictAddress::CPbk2MergeConflictAddress
       
   267 // --------------------------------------------------------------------------
       
   268 //
       
   269 CPbk2MergeConflictAddress::CPbk2MergeConflictAddress()
       
   270     {
       
   271     iConflictType = EPbk2ConflictTypeAddress;
       
   272     }
       
   273 
       
   274 // --------------------------------------------------------------------------
       
   275 // CPbk2MergeConflictAddress::GetConflictType
       
   276 // --------------------------------------------------------------------------
       
   277 //
       
   278 EPbk2ConflictType CPbk2MergeConflictAddress::GetConflictType() 
       
   279     {
       
   280     return iConflictType;
       
   281     }
       
   282 
       
   283 // --------------------------------------------------------------------------
       
   284 // CPbk2MergeConflictAddress::NewL
       
   285 // --------------------------------------------------------------------------
       
   286 //
       
   287 CPbk2MergeConflictAddress* CPbk2MergeConflictAddress::NewL() 
       
   288     {
       
   289     CPbk2MergeConflictAddress* self = new ( ELeave ) CPbk2MergeConflictAddress();
       
   290     return self;
       
   291     }
       
   292 
       
   293 // --------------------------------------------------------------------------
       
   294 // CPbk2MergeConflictAddress::AddAddress
       
   295 // --------------------------------------------------------------------------
       
   296 //
       
   297 void CPbk2MergeConflictAddress::AddAddress( 
       
   298         CPbk2PresentationContact& aContactFirst, 
       
   299         CPbk2PresentationContact& aContactSecond, 
       
   300         TPbk2FieldGroupId aAddressGroup ) 
       
   301     {
       
   302     iContactFirst = &aContactFirst;
       
   303     iContactSecond = &aContactSecond;
       
   304     iAddressGroup = aAddressGroup;
       
   305     }
       
   306 
       
   307 // --------------------------------------------------------------------------
       
   308 // CPbk2MergeConflictAddress::GetLabelLC
       
   309 // --------------------------------------------------------------------------
       
   310 //
       
   311 HBufC* CPbk2MergeConflictAddress::GetLabelLC() 
       
   312     {
       
   313     HBufC* retLebel = NULL;
       
   314     switch( iAddressGroup )
       
   315         {
       
   316         case EPbk2FieldGroupIdPostalAddress:
       
   317             retLebel = StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS );
       
   318             break;
       
   319         case EPbk2FieldGroupIdHomeAddress:
       
   320             retLebel = StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS_HOME );
       
   321             break;
       
   322         case EPbk2FieldGroupIdCompanyAddress:
       
   323             retLebel = StringLoader::LoadLC( R_QTN_PHOB_HEADER_ADDRESS_WORK );
       
   324             break;
       
   325         default:
       
   326             Panic( EPbk2NotInitialized );
       
   327         }
       
   328     return retLebel;
       
   329     }
       
   330 
       
   331 // --------------------------------------------------------------------------
       
   332 // CPbk2MergeConflictAddress::GetTextLC
       
   333 // --------------------------------------------------------------------------
       
   334 //
       
   335 HBufC* CPbk2MergeConflictAddress::GetTextLC( EPbk2ConflictedNumber aNumber ) 
       
   336     {
       
   337     __ASSERT_ALWAYS( iContactFirst && iContactSecond, Panic( EPbk2NotInitialized ) );
       
   338     
       
   339     RBuf addressText;
       
   340     if( aNumber == EPbk2ConflictedFirst )
       
   341         {
       
   342         Pbk2AddressTools::GetAddressPreviewLC( *iContactFirst ,
       
   343                     iAddressGroup, addressText );
       
   344         }
       
   345     else
       
   346         {
       
   347         Pbk2AddressTools::GetAddressPreviewLC( *iContactSecond , 
       
   348                     iAddressGroup, addressText );
       
   349         }
       
   350     
       
   351     HBufC* retText = addressText.AllocL();
       
   352     CleanupStack::PopAndDestroy( &addressText );
       
   353     CleanupStack::PushL( retText );
       
   354     return retText;
       
   355     }
       
   356 
       
   357 // --------------------------------------------------------------------------
       
   358 // CPbk2MergeConflictAddress::ResolveConflict
       
   359 // --------------------------------------------------------------------------
       
   360 //
       
   361 void CPbk2MergeConflictAddress::ResolveConflict( EPbk2ConflictedNumber aNumber ) 
       
   362     {
       
   363     __ASSERT_ALWAYS( iContactFirst && iContactSecond, Panic( EPbk2NotInitialized ) );
       
   364     
       
   365     if( aNumber == EPbk2ConflictedFirst )
       
   366         {
       
   367         iContactChosenAddress = iContactFirst;
       
   368         }
       
   369     else
       
   370         {
       
   371         iContactChosenAddress = iContactSecond;
       
   372         }
       
   373     }
       
   374 
       
   375 // --------------------------------------------------------------------------
       
   376 // CPbk2MergeConflictAddress::GetChosenFieldsL
       
   377 // --------------------------------------------------------------------------
       
   378 //
       
   379 void CPbk2MergeConflictAddress::GetChosenFieldsL( 
       
   380         RPointerArray<MVPbkStoreContactField>& aAddressFields )
       
   381     {
       
   382     __ASSERT_ALWAYS( iContactChosenAddress, Panic( EPbk2NotChosen ) );
       
   383     
       
   384     CPbk2PresentationContactFieldCollection& fields = iContactChosenAddress->PresentationFields();
       
   385     
       
   386     for( TInt idx = 0; idx < fields.FieldCount(); idx++ )
       
   387         {
       
   388         CPbk2PresentationContactField& field = fields.At( idx );
       
   389         const MPbk2FieldProperty& property = field.FieldProperty();
       
   390         if( property.GroupId() == iAddressGroup )
       
   391             {
       
   392             aAddressFields.AppendL( &field );
       
   393             }
       
   394         }
       
   395     }
       
   396