|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 //#include <cntdb.h> |
|
17 #include <cntitem.h> |
|
18 #include <cntfldst.h> |
|
19 #include "NbCntTestLib.h" |
|
20 |
|
21 |
|
22 |
|
23 TContact::TContact(CContactItem* aCnt) |
|
24 :FirstName(KUidContactFieldGivenName, TUid::Null(), aCnt), |
|
25 Email(KUidContactFieldVCardMapEMAILINTERNET, aCnt), |
|
26 Address(KUidContactFieldAddress, aCnt), |
|
27 iCnt(aCnt) |
|
28 {}; |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 void TContact::TProp::operator= (const TDesC& aStr) |
|
34 { |
|
35 CContactItemField& field = Find(); |
|
36 field.TextStorage()->SetTextL(aStr); |
|
37 } |
|
38 |
|
39 |
|
40 TContact::TProp::operator const TPtrC() |
|
41 { |
|
42 const CContactItemField& field = Find(); |
|
43 return field.TextStorage()->Text(); |
|
44 } |
|
45 |
|
46 CContactItemField& TContact::TProp::Find() |
|
47 { |
|
48 for (TInt fieldNum = iCnt->CardFields().Count() - 1; fieldNum>=0; --fieldNum) //For all the fields of contact |
|
49 { |
|
50 CContactItemField& currField = iCnt->CardFields()[fieldNum]; //current contact field |
|
51 if (currField.ContentType().ContainsFieldType(iUid1)) |
|
52 { |
|
53 if (iUid2 == TUid::Null()) |
|
54 { //No need to check for the second UID |
|
55 return currField; |
|
56 } |
|
57 else if (currField.ContentType().ContainsFieldType(iUid2)) |
|
58 { |
|
59 return currField; |
|
60 } |
|
61 } |
|
62 } |
|
63 |
|
64 User::Leave(KErrBadName); //We didn't find the field |
|
65 |
|
66 CContactItemField* currField = NULL; //Unreachable code |
|
67 return *currField; |
|
68 } |
|
69 |
|
70 |
|
71 // |
|
72 |
|
73 |
|
74 EXPORT_C TCnt::TGetSet& TCnt::operator [](TUid aUid) |
|
75 { |
|
76 //TInt32* id = reinterpret_cast<TInt32*>(&aUid); |
|
77 TInt32 mapping; |
|
78 |
|
79 switch(aUid.iUid) |
|
80 { |
|
81 case KUidContactFieldPhoneNumberValue: |
|
82 case KUidContactFieldFaxValue: |
|
83 mapping = KIntContactFieldVCardMapTEL; |
|
84 break; |
|
85 |
|
86 case KUidContactFieldEMailValue: mapping = KIntContactFieldVCardMapEMAILINTERNET; |
|
87 break; |
|
88 case KUidContactFieldPostOfficeValue: mapping = KIntContactFieldVCardMapPOSTOFFICE; |
|
89 break; |
|
90 case KUidContactFieldExtendedAddressValue: mapping = KIntContactFieldVCardMapEXTENDEDADR; |
|
91 break; |
|
92 case KUidContactFieldAddressValue: mapping = KIntContactFieldVCardMapADR; |
|
93 break; |
|
94 case KUidContactFieldLocalityValue: mapping = KIntContactFieldVCardMapLOCALITY; |
|
95 break; |
|
96 case KUidContactFieldRegionValue: mapping = KIntContactFieldVCardMapREGION; |
|
97 break; |
|
98 case KUidContactFieldPostCodeValue: mapping = KIntContactFieldVCardMapPOSTCODE; |
|
99 break; |
|
100 case KUidContactFieldCountryValue: mapping = KIntContactFieldVCardMapCOUNTRY; |
|
101 break; |
|
102 case KUidContactFieldUrlValue: mapping = KIntContactFieldVCardMapURL; |
|
103 break; |
|
104 case KUidContactFieldSecondNameValue: mapping = KIntContactFieldVCardMapSECONDNAME; |
|
105 break; |
|
106 case KUidContactFieldCompanyNameValue: mapping = KIntContactFieldVCardMapORG; |
|
107 break; |
|
108 case KUidContactFieldJobTitleValue: mapping = KIntContactFieldVCardMapTITLE; |
|
109 break; |
|
110 case KUidContactFieldPictureValue: mapping = KIntContactFieldVCardMapLOGO; |
|
111 break; |
|
112 case KUidContactFieldBirthdayValue: mapping = KIntContactFieldVCardMapBDAY; |
|
113 break; |
|
114 case KUidContactFieldNoteValue: mapping = KIntContactFieldVCardMapNOTE; |
|
115 break; |
|
116 case KUidContactFieldCompanyNamePronunciationValue: mapping = KIntContactFieldVCardMapORGPronunciation; |
|
117 break; |
|
118 case KUidContactFieldSIPIDValue: mapping = KIntContactFieldVCardMapSIPID; |
|
119 break; |
|
120 default: |
|
121 mapping = KIntContactFieldVCardMapUnusedN; |
|
122 }; |
|
123 |
|
124 iTaker.iContType = CContentType::NewL(aUid, TUid::Uid(mapping)); |
|
125 CleanupStack::PushL(iTaker.iContType); |
|
126 return iTaker; |
|
127 } |
|
128 |
|
129 EXPORT_C TCnt::TGetSet& TCnt::TGetSet::operator[](TInt aIndex) |
|
130 { |
|
131 iIndex = aIndex; |
|
132 return *this; |
|
133 } |
|
134 |
|
135 EXPORT_C TCnt::TGetSet& TCnt::TGetSet::operator&(TUid aUid) |
|
136 { |
|
137 iContType->AddFieldTypeL(aUid); |
|
138 return *this; |
|
139 } |
|
140 |
|
141 _LIT(KFieldNotFound, "Field Not Found"); |
|
142 |
|
143 EXPORT_C void TCnt::TGetSet::operator= (const TDesC& aStr) |
|
144 { |
|
145 CContactItemField* aField = Find(); |
|
146 __ASSERT_ALWAYS(aField, User::Panic(KFieldNotFound, KErrBadName)); |
|
147 aField->TextStorage()->SetTextL(aStr); |
|
148 } |
|
149 |
|
150 EXPORT_C TBool TCnt::TGetSet::operator==(const TDesC& aStr) |
|
151 { |
|
152 CContactItemField* aField = Find(); |
|
153 __ASSERT_ALWAYS(aField, User::Panic(KFieldNotFound, KErrBadName)); |
|
154 return aField->TextStorage()->Text() == aStr; |
|
155 } |
|
156 |
|
157 EXPORT_C void TCnt::TGetSet::operator+= (const TDesC& aStr) |
|
158 { |
|
159 //Create the field if it is not found |
|
160 CContactItemField* field = CContactItemField::NewLC(KStorageTypeText, *iContType); |
|
161 iCnt->AddFieldL(*field); //Takes ownership |
|
162 |
|
163 field->TextStorage()->SetTextL(aStr); |
|
164 |
|
165 CleanupStack::Pop(field); |
|
166 CleanupStack::PopAndDestroy(iContType); |
|
167 } |
|
168 |
|
169 EXPORT_C TInt TCnt::TGetSet::Count() |
|
170 { |
|
171 TInt counter(0); |
|
172 const TInt numOfFields = iCnt->CardFields().Count(); |
|
173 for (TInt fieldNum = 0; fieldNum < numOfFields; ++fieldNum) //For all the fields of contact |
|
174 { |
|
175 CContactItemField& currField = iCnt->CardFields()[fieldNum]; //current contact field |
|
176 if (currField.ContentType() == *iContType) |
|
177 { |
|
178 ++counter; |
|
179 } |
|
180 } |
|
181 return counter; |
|
182 } |
|
183 |
|
184 |
|
185 EXPORT_C CContactItemField& TCnt::TGetSet::Field() |
|
186 { |
|
187 return *Find(); |
|
188 } |
|
189 |
|
190 |
|
191 EXPORT_C TCnt::TGetSet::operator const TPtrC() |
|
192 { |
|
193 const CContactItemField* aField = Find(); |
|
194 __ASSERT_ALWAYS(aField, User::Panic(KFieldNotFound, KErrBadName)); |
|
195 return aField->TextStorage()->Text(); |
|
196 } |
|
197 |
|
198 extern const TText* VCardMaping(const TFieldType& type); |
|
199 |
|
200 |
|
201 |
|
202 CContactItemField* TCnt::TGetSet::Find() |
|
203 { |
|
204 TInt fieldsToSkip = iIndex; |
|
205 const TInt numOfFields = iCnt->CardFields().Count(); |
|
206 |
|
207 for (TInt fieldNum = 0; fieldNum < numOfFields; ++fieldNum) //For all the fields of contact |
|
208 { |
|
209 CContactItemField& currField = iCnt->CardFields()[fieldNum]; //current contact field |
|
210 if (currField.ContentType() == *iContType) |
|
211 { |
|
212 if (!fieldsToSkip) |
|
213 { |
|
214 CleanupStack::PopAndDestroy(iContType); |
|
215 return &currField; |
|
216 } |
|
217 else |
|
218 { |
|
219 --fieldsToSkip; |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 return NULL; |
|
225 } |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 // Contact Builder. |
|
231 |
|
232 EXPORT_C CCntItemBuilder* CCntItemBuilder::NewLC(const CContactTemplate& aTemplate) |
|
233 { |
|
234 CCntItemBuilder* self = new (ELeave) CCntItemBuilder(aTemplate); |
|
235 CleanupStack::PushL(self); |
|
236 return self; |
|
237 } |
|
238 |
|
239 |
|
240 void CCntItemBuilder::ConstructL() |
|
241 { |
|
242 iCntModifier = CCntItemModifier::NewLC(); |
|
243 CleanupStack::Pop(iCntModifier); |
|
244 } |
|
245 |
|
246 EXPORT_C CCntItemBuilder::~CCntItemBuilder() |
|
247 { |
|
248 delete iCntModifier; |
|
249 } |
|
250 |
|
251 EXPORT_C CContactItem* CCntItemBuilder::GetCntItemLC() |
|
252 { |
|
253 CContactItem* contactItem = CContactCard::NewLC(&iTemplate); |
|
254 FillWithRandomDataL(*contactItem); |
|
255 return contactItem; //return ownership |
|
256 } |
|
257 |
|
258 |
|
259 |
|
260 void CCntItemBuilder::FillWithRandomDataL(CContactItem& aContactItem) |
|
261 { |
|
262 HBufC* buf=HBufC::NewLC(256); |
|
263 TPtr bufPtr=buf->Des(); |
|
264 SetRandomAlphaString(bufPtr,32); |
|
265 // 1 |
|
266 iCntModifier->SetTextFieldL(KUidContactFieldGivenName, bufPtr, aContactItem); |
|
267 SetRandomAlphaString(bufPtr,32); |
|
268 // 2 |
|
269 iCntModifier->SetTextFieldL(KUidContactFieldFamilyName, bufPtr, aContactItem); |
|
270 |
|
271 SetRandomAlphaString(bufPtr,32); |
|
272 // 3 |
|
273 iCntModifier->SetTextFieldL(KUidContactFieldCompanyName, bufPtr, aContactItem); |
|
274 |
|
275 SetRandomAlphaString(bufPtr,32); |
|
276 // 4 |
|
277 iCntModifier->SetTextFieldL(KUidContactFieldJobTitle, bufPtr, aContactItem); |
|
278 |
|
279 SetRandomNumericString(bufPtr,24); |
|
280 // 5 |
|
281 iCntModifier->SetTextFieldL(KUidContactFieldPhoneNumber, |
|
282 KUidContactFieldVCardMapWORK, |
|
283 KUidContactFieldVCardMapVOICE, |
|
284 bufPtr, aContactItem); |
|
285 |
|
286 SetRandomNumericString(bufPtr,24); |
|
287 // 6 |
|
288 iCntModifier->SetTextFieldL(KUidContactFieldPhoneNumber, |
|
289 KUidContactFieldVCardMapWORK, |
|
290 KUidContactFieldVCardMapVOICE, |
|
291 KUidContactFieldVCardMapCELL, |
|
292 bufPtr, aContactItem); |
|
293 |
|
294 |
|
295 SetRandomNumericString(bufPtr,24); |
|
296 // 7 |
|
297 iCntModifier->SetTextFieldL(KUidContactFieldPhoneNumber, |
|
298 KUidContactFieldVCardMapHOME, |
|
299 KUidContactFieldVCardMapVOICE, |
|
300 bufPtr, aContactItem); |
|
301 |
|
302 SetRandomNumericString(bufPtr,24); |
|
303 // 8 |
|
304 |
|
305 iCntModifier->SetTextFieldL(KUidContactFieldPhoneNumber, |
|
306 KUidContactFieldVCardMapHOME, |
|
307 KUidContactFieldVCardMapVOICE, |
|
308 KUidContactFieldVCardMapCELL, |
|
309 bufPtr, aContactItem); |
|
310 |
|
311 SetRandomNumericString(bufPtr,24); |
|
312 |
|
313 // 9 |
|
314 iCntModifier->SetTextFieldL(KUidContactFieldFax, |
|
315 bufPtr, aContactItem); |
|
316 |
|
317 SetRandomAlphaNumericString(bufPtr,48); |
|
318 |
|
319 // 10 |
|
320 iCntModifier->SetTextFieldL(KUidContactFieldEMail, |
|
321 KUidContactFieldVCardMapWORK, |
|
322 bufPtr, aContactItem); |
|
323 |
|
324 SetRandomAlphaNumericString(bufPtr,48); |
|
325 |
|
326 // 11 |
|
327 iCntModifier->SetTextFieldL(KUidContactFieldUrl, |
|
328 bufPtr, aContactItem); |
|
329 |
|
330 SetRandomAlphaNumericString(bufPtr,32); |
|
331 |
|
332 // 12 |
|
333 iCntModifier->SetTextFieldL(KUidContactFieldAddress, |
|
334 bufPtr, aContactItem); |
|
335 |
|
336 SetRandomAlphaString(bufPtr,32); |
|
337 // 13 |
|
338 iCntModifier->SetTextFieldL(KUidContactFieldLocality, |
|
339 bufPtr, aContactItem); |
|
340 |
|
341 SetRandomAlphaString(bufPtr,32); |
|
342 // 14 |
|
343 iCntModifier->SetTextFieldL(KUidContactFieldRegion, |
|
344 bufPtr, aContactItem); |
|
345 |
|
346 SetRandomAlphaNumericString(bufPtr,16); |
|
347 // 15 |
|
348 iCntModifier->SetTextFieldL(KUidContactFieldPostcode, |
|
349 bufPtr, aContactItem); |
|
350 |
|
351 SetRandomAlphaString(bufPtr,32); |
|
352 // 16 |
|
353 iCntModifier->SetTextFieldL(KUidContactFieldCountry, |
|
354 bufPtr, aContactItem); |
|
355 SetRandomAlphaNumericString(bufPtr,256); |
|
356 // 17 |
|
357 iCntModifier->SetTextFieldL(KUidContactFieldNote, |
|
358 bufPtr, aContactItem); |
|
359 |
|
360 CleanupStack::PopAndDestroy(buf); // buf |
|
361 } |
|
362 |
|
363 |
|
364 void CCntItemBuilder::SetRandomWordL(TDes& aBuf, TInt32 aType ) |
|
365 { |
|
366 TInt len = 16; |
|
367 SetRandomAlphaString(aBuf, len); |
|
368 |
|
369 // the following are to make these look a bite more realistic |
|
370 if(aType==KUidContactFieldEMailValue) |
|
371 { |
|
372 aBuf.Append('@'); |
|
373 HBufC* buf = HBufC::NewLC (KEmailAddrLen); |
|
374 SetRandomAlphaString (aBuf, KEmailAddrLen); |
|
375 aBuf.Append (buf->Des()); |
|
376 CleanupStack::PopAndDestroy(buf); |
|
377 aBuf.Append (_L(".co.uk")); |
|
378 } |
|
379 if(aType==KUidContactFieldCompanyNameValue || aType==KUidContactFieldCompanyNamePronunciationValue) |
|
380 { |
|
381 aBuf.Append(' '); |
|
382 aBuf.Append(_L(" Ltd.")); |
|
383 } |
|
384 } |
|
385 |
|
386 |
|
387 void CCntItemBuilder::SetRandomAlphaString(TDes& aBuf,TInt aLength) |
|
388 { |
|
389 aBuf.SetLength(aLength); |
|
390 |
|
391 for (TInt i=0; i<aLength; ++i) |
|
392 { |
|
393 aBuf[i]=RandomAlphaCharCode(); |
|
394 } |
|
395 } |
|
396 |
|
397 |
|
398 TText CCntItemBuilder::RandomAlphaCharCode() |
|
399 { |
|
400 return RandomCharCode('A','z',' '); |
|
401 } |
|
402 |
|
403 TText CCntItemBuilder::RandomNumericCharCode() |
|
404 { |
|
405 return RandomCharCode('0','9',' '); |
|
406 } |
|
407 |
|
408 TText CCntItemBuilder::RandomAlphaNumbericCharCode() |
|
409 { |
|
410 return RandomCharCode('0','z',' '); |
|
411 } |
|
412 |
|
413 TText CCntItemBuilder::RandomCharCode(TText aLowerBound,TText aUpperBound,TText aException) |
|
414 { |
|
415 TText charCode = 0; |
|
416 do |
|
417 { |
|
418 charCode = RandomCharCode(aLowerBound,aUpperBound); |
|
419 } |
|
420 while (charCode == aException); |
|
421 |
|
422 return charCode; |
|
423 } |
|
424 |
|
425 TText CCntItemBuilder::RandomCharCode(TText aLowerBound,TText aUpperBound) |
|
426 { |
|
427 // TTime now; |
|
428 // now.UniversalTime(); |
|
429 TInt64 randSeed = 45879; |
|
430 // TInt64 randSeed = now.Int64(); |
|
431 TText charCode = STATIC_CAST(TText,(Math::Rand(randSeed)%(aUpperBound-aLowerBound))+aLowerBound); |
|
432 |
|
433 ASSERT(charCode >= aLowerBound && charCode <= aUpperBound); |
|
434 return charCode; |
|
435 } |
|
436 |
|
437 |
|
438 void CCntItemBuilder::SetRandomNumericString(TDes& aBuf, TInt aLength) |
|
439 { |
|
440 aBuf.SetLength(aLength); |
|
441 |
|
442 for (TInt ii = 0; ii < aLength; ++ii) |
|
443 { |
|
444 aBuf[ii]=RandomNumericCharCode(); |
|
445 } |
|
446 } |
|
447 |
|
448 |
|
449 void CCntItemBuilder::SetRandomAlphaNumericString(TDes& aBuf,TInt aLength) |
|
450 { |
|
451 aBuf.SetLength(aLength); |
|
452 for (TInt ii = 0; ii < aLength; ++ii) |
|
453 { |
|
454 aBuf[ii]=RandomAlphaNumbericCharCode(); |
|
455 } |
|
456 } |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 // ---------- CCntItemModifier ---------------- |
|
465 |
|
466 |
|
467 EXPORT_C CCntItemModifier* CCntItemModifier::NewLC() |
|
468 { |
|
469 CCntItemModifier* self = new (ELeave) CCntItemModifier(); |
|
470 CleanupStack::PushL(self); |
|
471 return self; |
|
472 } |
|
473 |
|
474 EXPORT_C CCntItemModifier::~CCntItemModifier() |
|
475 { |
|
476 } |
|
477 |
|
478 |
|
479 EXPORT_C void CCntItemModifier::SetTextFieldL(TFieldType aFieldType, const TDesC& aText, CContactItem& aContactItem) |
|
480 { |
|
481 CContactItemFieldSet& fields = aContactItem.CardFields(); |
|
482 TInt fieldIndex = aContactItem.CardFields().Find(aFieldType); |
|
483 |
|
484 if (fieldIndex > KErrNotFound) |
|
485 { |
|
486 CContactItemField& field = fields[ fieldIndex ]; |
|
487 ASSERT(field.StorageType() == KStorageTypeText); |
|
488 |
|
489 STATIC_CAST(CContactTextField*, field.Storage())->SetText(aText.AllocL()); |
|
490 } |
|
491 else |
|
492 { |
|
493 InsertTextFieldL(aFieldType, aText, aContactItem); |
|
494 } |
|
495 } |
|
496 |
|
497 |
|
498 |
|
499 EXPORT_C void CCntItemModifier::SetTextFieldL(TFieldType aFieldType, TFieldType a2ndFieldType, |
|
500 const TDesC& aText, |
|
501 CContactItem& aContactItem) const |
|
502 { |
|
503 CContentType* contentTypeToMatch = CContentType::NewL(); |
|
504 CleanupStack::PushL (contentTypeToMatch); |
|
505 contentTypeToMatch->AddFieldTypeL (aFieldType); |
|
506 contentTypeToMatch->AddFieldTypeL (a2ndFieldType); |
|
507 |
|
508 CContactItemField& field = FindFieldL(*contentTypeToMatch, aContactItem); |
|
509 ASSERT(field.StorageType() == KStorageTypeText); |
|
510 STATIC_CAST(CContactTextField*, field.Storage())->SetText(aText.AllocL()); |
|
511 CleanupStack::PopAndDestroy(); // contentTypeToMatch. |
|
512 |
|
513 } |
|
514 |
|
515 |
|
516 EXPORT_C void CCntItemModifier::SetTextFieldL(TFieldType aFieldType, TFieldType a2ndFieldType, |
|
517 TFieldType a3rdFieldType, |
|
518 const TDesC& aText, CContactItem& aContactItem) const |
|
519 { |
|
520 CContentType* contentTypeToMatch = CContentType::NewL(); |
|
521 CleanupStack::PushL (contentTypeToMatch); |
|
522 contentTypeToMatch->AddFieldTypeL (aFieldType); |
|
523 contentTypeToMatch->AddFieldTypeL (a2ndFieldType); |
|
524 contentTypeToMatch->AddFieldTypeL (a3rdFieldType); |
|
525 |
|
526 CContactItemField& field = FindFieldL(*contentTypeToMatch, aContactItem); |
|
527 ASSERT(field.StorageType() == KStorageTypeText); |
|
528 STATIC_CAST(CContactTextField*, field.Storage())->SetText(aText.AllocL()); |
|
529 CleanupStack::PopAndDestroy(); // contentTypeToMatch. |
|
530 } |
|
531 |
|
532 |
|
533 EXPORT_C void CCntItemModifier::SetTextFieldL(TFieldType aFieldType, TFieldType a2ndFieldType, |
|
534 TFieldType a3rdFieldType, TFieldType a4thFieldType, |
|
535 const TDesC& aText, CContactItem& aContactItem) const |
|
536 { |
|
537 CContentType* contentTypeToMatch = CContentType::NewL(); |
|
538 CleanupStack::PushL (contentTypeToMatch); |
|
539 contentTypeToMatch->AddFieldTypeL (aFieldType); |
|
540 contentTypeToMatch->AddFieldTypeL (a2ndFieldType); |
|
541 contentTypeToMatch->AddFieldTypeL (a3rdFieldType); |
|
542 contentTypeToMatch->AddFieldTypeL (a4thFieldType); |
|
543 |
|
544 CContactItemField& field = FindFieldL(*contentTypeToMatch, aContactItem); |
|
545 ASSERT(field.StorageType() == KStorageTypeText); |
|
546 STATIC_CAST(CContactTextField*, field.Storage())->SetText(aText.AllocL()); |
|
547 CleanupStack::PopAndDestroy(); // contentTypeToMatch. |
|
548 } |
|
549 |
|
550 |
|
551 EXPORT_C TBool CCntItemModifier::FindTextFieldL(TFieldType aFieldType, TFieldType a2ndFieldType, |
|
552 TFieldType a3rdFieldType, TFieldType a4thFieldType, |
|
553 const TDesC& aText, CContactItem& aContactItem) const |
|
554 |
|
555 { |
|
556 CContentType* contentTypeToMatch = CContentType::NewL(); |
|
557 CleanupStack::PushL (contentTypeToMatch); |
|
558 contentTypeToMatch->AddFieldTypeL (aFieldType); |
|
559 contentTypeToMatch->AddFieldTypeL (a2ndFieldType); |
|
560 contentTypeToMatch->AddFieldTypeL (a3rdFieldType); |
|
561 contentTypeToMatch->AddFieldTypeL (a4thFieldType); |
|
562 |
|
563 CContactItemField& field = FindFieldL(*contentTypeToMatch, aContactItem); |
|
564 CContactTextField* textField = static_cast<CContactTextField*> (field.Storage()); |
|
565 CleanupStack::PopAndDestroy(); // contentTypeToMatch. |
|
566 if (textField->Text() == aText) |
|
567 { |
|
568 return TRUE; |
|
569 } |
|
570 return FALSE; |
|
571 } |
|
572 |
|
573 |
|
574 EXPORT_C TBool CCntItemModifier::FindTextFieldL(TFieldType aFieldType, |
|
575 const TDesC& aText, |
|
576 CContactItem& aContactItem)const |
|
577 { |
|
578 CContactItemFieldSet& fields = aContactItem.CardFields(); |
|
579 TInt fieldIndex = aContactItem.CardFields().Find(aFieldType); |
|
580 CContactItemField& field = fields[ fieldIndex ]; |
|
581 STATIC_CAST(CContactTextField*, field.Storage())->SetText(aText.AllocL()); |
|
582 CContactTextField* textField = static_cast<CContactTextField*> (field.Storage()); |
|
583 if (textField->Text() == aText) |
|
584 { |
|
585 return TRUE; |
|
586 } |
|
587 return FALSE; |
|
588 } |
|
589 |
|
590 |
|
591 EXPORT_C TBool CCntItemModifier::FindTextFieldL(TFieldType aFieldType, TFieldType a2ndFieldType, |
|
592 const TDesC& aText, |
|
593 CContactItem& aContactItem) const |
|
594 { |
|
595 CContentType* contentTypeToMatch = CContentType::NewL(); |
|
596 CleanupStack::PushL (contentTypeToMatch); |
|
597 contentTypeToMatch->AddFieldTypeL (aFieldType); |
|
598 contentTypeToMatch->AddFieldTypeL (a2ndFieldType); |
|
599 |
|
600 CContactItemField& field = FindFieldL(*contentTypeToMatch, aContactItem); |
|
601 CContactTextField* textField = static_cast<CContactTextField*> (field.Storage()); |
|
602 CleanupStack::PopAndDestroy(); // contentTypeToMatch. |
|
603 if (textField->Text() == aText) |
|
604 { |
|
605 return TRUE; |
|
606 } |
|
607 return FALSE; |
|
608 } |
|
609 |
|
610 |
|
611 |
|
612 TInt CCntItemModifier::FindField(TFieldType aFieldType, CContactItem& aContactItem) const |
|
613 { |
|
614 return aContactItem.CardFields().Find( aFieldType ); |
|
615 } |
|
616 |
|
617 |
|
618 CContactItemField& CCntItemModifier::FindFieldL(TFieldType aFieldType, CContactItem& aContactItem) const |
|
619 { |
|
620 CContactItemFieldSet& fields = aContactItem.CardFields(); |
|
621 TInt index=fields.Find(aFieldType); |
|
622 User::LeaveIfError(index); |
|
623 return fields[index]; |
|
624 } |
|
625 |
|
626 |
|
627 CContactItemField& CCntItemModifier::FindFieldL(const CContentType& aTypesToMatch, CContactItem& aContactItem) const |
|
628 { |
|
629 CContactItemFieldSet& fields = aContactItem.CardFields(); |
|
630 const TInt numTypesToMatch (aTypesToMatch.FieldTypeCount()); |
|
631 const TFieldType mainFieldType (aTypesToMatch.FieldType(0)); |
|
632 TInt index=-1; |
|
633 FOREVER |
|
634 { |
|
635 index = fields.FindNext(mainFieldType,index+1); |
|
636 User::LeaveIfError(index); |
|
637 |
|
638 CContactItemField& thisPhoneField=fields[index]; |
|
639 const CContentType& thisPhoneFieldTypes=thisPhoneField.ContentType(); |
|
640 const TInt numFieldTypes(thisPhoneFieldTypes.FieldTypeCount()); |
|
641 |
|
642 if (numFieldTypes != numTypesToMatch) |
|
643 { |
|
644 continue; |
|
645 } |
|
646 |
|
647 TInt numTypesLeftToMatch = numTypesToMatch; |
|
648 for (TInt ii=0;ii<numFieldTypes;++ii) |
|
649 { |
|
650 TFieldType thisFieldType(thisPhoneFieldTypes.FieldType(ii)); |
|
651 for (TInt jj=0;jj<numTypesToMatch;++jj) |
|
652 { |
|
653 TFieldType thisFieldTypeToMatch(aTypesToMatch.FieldType(jj)); |
|
654 if (thisFieldType==thisFieldTypeToMatch) |
|
655 { |
|
656 if (--numTypesLeftToMatch<=0) |
|
657 { |
|
658 return thisPhoneField; |
|
659 } |
|
660 |
|
661 break; |
|
662 } |
|
663 } |
|
664 } |
|
665 } |
|
666 } |
|
667 |
|
668 |
|
669 void CCntItemModifier::InsertTextFieldL(TFieldType aID, const TDesC& aStringOfStuff, CContactItem& aContactItem) |
|
670 { |
|
671 CContactItemField* itemFieldPtr = CContactItemField::NewLC( KStorageTypeText, aID ); |
|
672 CContactTextField* textStoragePtr = itemFieldPtr->TextStorage(); // we don't have ownership here, hence no stack. |
|
673 |
|
674 textStoragePtr->SetTextL( aStringOfStuff ); |
|
675 textStoragePtr = NULL; |
|
676 |
|
677 aContactItem.AddFieldL(*itemFieldPtr); // hand ownership over here |
|
678 CleanupStack::Pop(itemFieldPtr); // and pop, |
|
679 } |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 #ifndef EKA2 |
|
687 GLDEF_C TInt E32Dll(TDllReason /*aReason*/) |
|
688 { |
|
689 return KErrNone; |
|
690 } |
|
691 #endif |