|
1 /* |
|
2 * Copyright (c) 2004-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: Maps a Contact Model field to a Virtual Phonebook field. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDES |
|
19 #include "TContactField.h" |
|
20 |
|
21 // From VPbkCntModel |
|
22 #include "CContact.h" |
|
23 #include "CContactLink.h" |
|
24 #include "CFieldTypeMap.h" |
|
25 #include "CFieldFactory.h" |
|
26 #include "CContactStore.h" |
|
27 |
|
28 // From VPbkEng |
|
29 #include <MVPbkContactStoreProperties.h> |
|
30 #include <MVPbkFieldType.h> |
|
31 #include <CVPbkContactManager.h> |
|
32 #include <VPbkStoreUriLiterals.h> |
|
33 #include <TVPbkContactStoreUriPtr.h> |
|
34 |
|
35 // System includes |
|
36 #include <cntdef.h> |
|
37 #include <cntfield.h> |
|
38 #include <cntitem.h> |
|
39 #include <cntdb.h> |
|
40 |
|
41 |
|
42 namespace VPbkCntModel { |
|
43 |
|
44 const TInt KSpeedDialKey1 = 1; |
|
45 const TInt KSpeedDialKey2 = 2; |
|
46 const TInt KSpeedDialKey3 = 3; |
|
47 const TInt KSpeedDialKey4 = 4; |
|
48 const TInt KSpeedDialKey5 = 5; |
|
49 const TInt KSpeedDialKey6 = 6; |
|
50 const TInt KSpeedDialKey7 = 7; |
|
51 const TInt KSpeedDialKey8 = 8; |
|
52 const TInt KSpeedDialKey9 = 9; |
|
53 |
|
54 TContactField::TContactField(CContact& aParentContact) : |
|
55 iParentContact(&aParentContact), |
|
56 iCntModelField(NULL) |
|
57 { |
|
58 } |
|
59 |
|
60 TContactField::~TContactField() |
|
61 { |
|
62 } |
|
63 |
|
64 void TContactField::SetField |
|
65 (CContactItemField& aCntModelField) |
|
66 { |
|
67 iCntModelField = &aCntModelField; |
|
68 iFieldData.SetField(aCntModelField); |
|
69 } |
|
70 |
|
71 void TContactField::SetParentContact(CContact& aParentContact) |
|
72 { |
|
73 iParentContact = &aParentContact; |
|
74 iFieldData.ResetField(); |
|
75 } |
|
76 |
|
77 MVPbkBaseContact& TContactField::ParentContact() const |
|
78 { |
|
79 return *iParentContact; |
|
80 } |
|
81 |
|
82 const MVPbkFieldType* TContactField::MatchFieldType(TInt aMatchPriority) const |
|
83 { |
|
84 const MVPbkFieldType* type = |
|
85 iParentContact->FieldTypeMap().GenericFieldType(*iCntModelField, |
|
86 aMatchPriority); |
|
87 |
|
88 // Match to the type only if it's supported by the store |
|
89 // (=system template). |
|
90 // E.g 3rd party can add fields that are not in system template using |
|
91 // the Contacts Model API. |
|
92 if ( type && |
|
93 iParentContact->Store().FieldFactory().ContainsSame( *type ) ) |
|
94 { |
|
95 return type; |
|
96 } |
|
97 return NULL; |
|
98 } |
|
99 |
|
100 const MVPbkFieldType* TContactField::BestMatchingFieldType() const |
|
101 { |
|
102 const MVPbkFieldType* type = NULL; |
|
103 TInt maxPriority = iParentContact->ContactStore().StoreProperties(). |
|
104 SupportedFields().MaxMatchPriority(); |
|
105 for (TInt i = 0; i <= maxPriority && !type; ++i) |
|
106 { |
|
107 type = MatchFieldType(i); |
|
108 } |
|
109 return type; |
|
110 } |
|
111 |
|
112 TBool TContactField::SupportsLabel() const |
|
113 { |
|
114 return |
|
115 iParentContact->ParentStore().StoreProperties().SupportsFieldLabels(); |
|
116 } |
|
117 |
|
118 TPtrC TContactField::FieldLabel() const |
|
119 { |
|
120 return iCntModelField->Label(); |
|
121 } |
|
122 |
|
123 void TContactField::SetFieldLabelL(const TDesC& aText) |
|
124 { |
|
125 iCntModelField->SetLabelL(aText); |
|
126 } |
|
127 |
|
128 TInt TContactField::MaxLabelLength() const |
|
129 { |
|
130 return KVPbkUnlimitedLabelLength; |
|
131 } |
|
132 |
|
133 const MVPbkContactFieldData& TContactField::FieldData() const |
|
134 { |
|
135 return iFieldData; |
|
136 } |
|
137 |
|
138 MVPbkContactFieldData& TContactField::FieldData() |
|
139 { |
|
140 return iFieldData; |
|
141 } |
|
142 |
|
143 TBool TContactField::IsSame(const MVPbkBaseContactField& aOther) const |
|
144 { |
|
145 if (&aOther.ParentContact() == iParentContact) |
|
146 { |
|
147 // Two fields have the same identity if they point to the same Contact |
|
148 // Model field. |
|
149 const TContactField& otherField = static_cast<const TContactField&>(aOther); |
|
150 return (iCntModelField == otherField.iCntModelField); |
|
151 } |
|
152 return EFalse; |
|
153 } |
|
154 |
|
155 MVPbkStoreContactField* TContactField::CloneLC() const |
|
156 { |
|
157 TContactField* clone = |
|
158 new (ELeave) TContactField(*iParentContact); |
|
159 clone->SetField(*this->NativeField()); |
|
160 CleanupDeletePushL(clone); |
|
161 return clone; |
|
162 } |
|
163 |
|
164 MVPbkContactLink* TContactField::CreateLinkLC() const |
|
165 { |
|
166 MVPbkContactLink* ret = NULL; |
|
167 TContactItemId itemId( iParentContact->NativeContact()->Id() ); |
|
168 if ( itemId != KGoldenTemplateId && |
|
169 itemId != KNullContactId ) |
|
170 { |
|
171 ret = CContactLink::NewLC(iParentContact->Store(), |
|
172 iParentContact->NativeContact()->Id(), |
|
173 iCntModelField->Id()); |
|
174 } |
|
175 return ret; |
|
176 } |
|
177 |
|
178 TAny* TContactField::StoreContactFieldExtension(TUid aExtensionUid) |
|
179 { |
|
180 if (aExtensionUid == KMVPbkStoreContactFieldExtension2Uid) |
|
181 { |
|
182 return static_cast<MVPbkStoreContactField2*>(this); |
|
183 } |
|
184 return NULL; |
|
185 } |
|
186 |
|
187 CArrayFix<TInt>* TContactField::SpeedDialIndexesL() |
|
188 { |
|
189 /* Should the store be checked here? |
|
190 MVPbkContactStore* store = aContactManager.ContactStoresL().Find( |
|
191 KVPbkDefaultCntDbURI()); |
|
192 |
|
193 if (store && &iParentContact->ContactStore() == store) |
|
194 { |
|
195 */ |
|
196 CArrayFix<TInt>* speedDialIndexArray = new(ELeave) CArrayFixFlat<TInt>(2); |
|
197 CleanupStack::PushL(speedDialIndexArray); |
|
198 |
|
199 const TInt fieldtypeCount = NativeField()->ContentType().FieldTypeCount(); |
|
200 |
|
201 for (TInt i = 0; i < fieldtypeCount; ++i) |
|
202 { |
|
203 TFieldType fieldType = NativeField()->ContentType().FieldType(i); |
|
204 switch (fieldType.iUid) |
|
205 { |
|
206 case KUidSpeedDialOneValue: |
|
207 speedDialIndexArray->AppendL(KSpeedDialKey1); |
|
208 break; |
|
209 |
|
210 case KUidSpeedDialTwoValue: |
|
211 speedDialIndexArray->AppendL(KSpeedDialKey2); |
|
212 break; |
|
213 |
|
214 case KUidSpeedDialThreeValue: |
|
215 speedDialIndexArray->AppendL(KSpeedDialKey3); |
|
216 break; |
|
217 |
|
218 case KUidSpeedDialFourValue: |
|
219 speedDialIndexArray->AppendL(KSpeedDialKey4); |
|
220 break; |
|
221 |
|
222 case KUidSpeedDialFiveValue: |
|
223 speedDialIndexArray->AppendL(KSpeedDialKey5); |
|
224 break; |
|
225 |
|
226 case KUidSpeedDialSixValue: |
|
227 speedDialIndexArray->AppendL(KSpeedDialKey6); |
|
228 break; |
|
229 |
|
230 case KUidSpeedDialSevenValue: |
|
231 speedDialIndexArray->AppendL(KSpeedDialKey7); |
|
232 break; |
|
233 |
|
234 case KUidSpeedDialEightValue: |
|
235 speedDialIndexArray->AppendL(KSpeedDialKey8); |
|
236 break; |
|
237 |
|
238 case KUidSpeedDialNineValue: |
|
239 speedDialIndexArray->AppendL(KSpeedDialKey9); |
|
240 break; |
|
241 |
|
242 // NO DEFAULT CASE - search only for speed dial Uids, ignore others |
|
243 } |
|
244 } |
|
245 |
|
246 if (speedDialIndexArray->Count() == 0) |
|
247 { |
|
248 CleanupStack::PopAndDestroy(speedDialIndexArray); |
|
249 return NULL; |
|
250 } |
|
251 CleanupStack::Pop(); // speedDialIndexArray |
|
252 return speedDialIndexArray; |
|
253 } |
|
254 |
|
255 MVPbkObjectHierarchy& TContactField::ParentObject() const |
|
256 { |
|
257 return *iParentContact; |
|
258 } |
|
259 |
|
260 void TContactField::ResetNativeField() |
|
261 { |
|
262 iCntModelField = NULL; |
|
263 iFieldData.ResetField(); |
|
264 } |
|
265 |
|
266 TInt TContactField::NativeFieldIndex() const |
|
267 { |
|
268 TInt result = KErrNotFound; |
|
269 |
|
270 CContactItemFieldSet& fields = iParentContact->NativeContact()->CardFields(); |
|
271 const TInt count = fields.Count(); |
|
272 for (TInt i = 0; i < count; ++i) |
|
273 { |
|
274 if (&fields[i] == NativeField()) |
|
275 { |
|
276 result = i; |
|
277 break; |
|
278 } |
|
279 } |
|
280 |
|
281 return result; |
|
282 } |
|
283 |
|
284 } // namespace VPbkCntModel |
|
285 |