|
1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: A class for copying fields to between contacts |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <Pbk2ContactFieldCopy.h> |
|
20 |
|
21 // From Phonebook2 |
|
22 #include <MPbk2ContactNameFormatter.h> |
|
23 |
|
24 // From Virtual Phonebook |
|
25 #include <MVPbkFieldType.h> |
|
26 #include <MVPbkContactFieldData.h> |
|
27 #include <CVPbkContactFieldIterator.h> |
|
28 #include <MVPbkStoreContact.h> |
|
29 |
|
30 // ======== GLOBAL FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // Pbk2ContactFieldCopy::CopyTitleFieldsL |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 EXPORT_C void Pbk2ContactFieldCopy::CopyTitleFieldsL( |
|
37 const MVPbkStoreContact& aSourceContact, |
|
38 MVPbkStoreContact& aTargetContact, |
|
39 MPbk2ContactNameFormatter& aNameFormatter ) |
|
40 { |
|
41 const MVPbkStoreContactFieldCollection& sourceFields = |
|
42 aSourceContact.Fields(); |
|
43 const TInt sourceFieldCount = sourceFields.FieldCount(); |
|
44 for ( TInt i = 0; i < sourceFieldCount; ++i ) |
|
45 { |
|
46 const MVPbkFieldType* type = |
|
47 sourceFields.FieldAt(i).BestMatchingFieldType(); |
|
48 if ( type && aNameFormatter.IsTitleFieldType( *type ) ) |
|
49 { |
|
50 MVPbkStoreContactFieldCollection& targetFields = |
|
51 aTargetContact.Fields(); |
|
52 CVPbkContactFieldTypeIterator* itr = |
|
53 CVPbkContactFieldTypeIterator::NewLC( *type, targetFields ); |
|
54 if ( !itr->HasNext() ) |
|
55 { |
|
56 // target has no this type of title field -> copy the field |
|
57 CopyFieldL( sourceFields.FieldAt(i), *type, aTargetContact ); |
|
58 } |
|
59 CleanupStack::PopAndDestroy( itr ); |
|
60 } |
|
61 } |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------------------------- |
|
65 // Pbk2ContactFieldCopy::CopyFieldL |
|
66 // --------------------------------------------------------------------------- |
|
67 // |
|
68 EXPORT_C void Pbk2ContactFieldCopy::CopyFieldL( |
|
69 const MVPbkStoreContactField& aSourceField, |
|
70 const MVPbkFieldType& aType, |
|
71 MVPbkStoreContact& aTargetContact ) |
|
72 { |
|
73 MVPbkStoreContactField* newField = aTargetContact.CreateFieldLC( aType ); |
|
74 if ( newField->SupportsLabel() ) |
|
75 { |
|
76 TPtrC fieldLabel = aSourceField.FieldLabel(); |
|
77 if (fieldLabel.Length() > 0) |
|
78 { |
|
79 newField->SetFieldLabelL(fieldLabel); |
|
80 } |
|
81 } |
|
82 newField->FieldData().CopyL(aSourceField.FieldData()); |
|
83 aTargetContact.AddFieldL(newField); |
|
84 CleanupStack::Pop(); // newField |
|
85 } |