|
1 // Copyright (c) 2007-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 |
|
17 #include <e32test.h> |
|
18 #include <cntitem.h> |
|
19 #include <cntfldst.h> //to enable casting from ccontactfieldstorage* to ccontacttextfield* |
|
20 |
|
21 |
|
22 |
|
23 struct SFlagsDict |
|
24 { |
|
25 TInt iFlag; |
|
26 const TText* iDescript; |
|
27 }; |
|
28 |
|
29 #define FF(x) {x, _S(#x)} |
|
30 #define NbTestLast 0x00000000 |
|
31 |
|
32 //Contact field flag struct |
|
33 enum // er5 hard coded enum most of which have been used but not documented ;o( |
|
34 { |
|
35 EHidden =0x00000001, |
|
36 EReadOnly =0x00000002, |
|
37 ESynchronize =0x00000004, |
|
38 EDisabled =0x00000008, |
|
39 /* 0x00000010,-> 0x00000080 are used for |
|
40 the user defined attribs / categories like work / |
|
41 Personal / Other / None - used in er5 UI */ |
|
42 EUserMask =0x000000F0, |
|
43 ETemplateMask =EUserMask|ESynchronize|EReadOnly|EHidden, |
|
44 EOverRidesLabel =0x00000100, |
|
45 EUsesTemplateData =0x00000200, |
|
46 EUserAddedField =0x00000400, |
|
47 ETemplate =0x00000800, |
|
48 /* 0x00001000,-> 0x0000F000 are used for |
|
49 the storage type of the contact field */ |
|
50 ELabelUnspecified =0x40000000, |
|
51 EDeleted =0x80000000 |
|
52 }; |
|
53 enum |
|
54 // new extended enum to allow cntmodel to have |
|
55 // more attributes per field |
|
56 { |
|
57 EPrivate =0x00000001, |
|
58 ESpeedDial =0x00000002, |
|
59 EUserDefinedFilter =0x00000004, |
|
60 EUserDefinedFilter1 =0x00000008, |
|
61 EUserDefinedFilter2 =0x00000010, |
|
62 EUserDefinedFilter3 =0x00000020, |
|
63 EUserDefinedFilter4 =0x00000040 |
|
64 }; |
|
65 |
|
66 |
|
67 struct SDescArr |
|
68 { |
|
69 operator const TText*() const |
|
70 { |
|
71 return iDesc; |
|
72 } |
|
73 |
|
74 const TText* iDesc; |
|
75 }; |
|
76 |
|
77 |
|
78 |
|
79 #define VM(x) case x: return _S(#x); |
|
80 |
|
81 extern const TText* VCardMaping(const TFieldType& type) |
|
82 { |
|
83 switch (type.iUid) |
|
84 { |
|
85 //case KUidContactFieldAddressValue: return _S("KUidContactFieldAddressValue"); |
|
86 VM(KUidContactFieldAddressValue ); |
|
87 VM(KUidContactFieldPostOfficeValue ); |
|
88 VM(KUidContactFieldExtendedAddressValue ); |
|
89 VM(KUidContactFieldLocalityValue ); |
|
90 VM(KUidContactFieldRegionValue ); |
|
91 VM(KUidContactFieldPostCodeValue ); |
|
92 VM(KUidContactFieldCountryValue ); |
|
93 |
|
94 VM(KUidContactFieldCompanyNameValue ); |
|
95 VM(KUidContactFieldCompanyNamePronunciationValue ); |
|
96 VM(KUidContactFieldPhoneNumberValue ); |
|
97 VM(KUidContactFieldGivenNameValue ); |
|
98 VM(KUidContactFieldFamilyNameValue ); |
|
99 VM(KUidContactFieldGivenNamePronunciationValue ); |
|
100 VM(KUidContactFieldFamilyNamePronunciationValue ); |
|
101 |
|
102 VM(KUidContactFieldAdditionalNameValue); |
|
103 VM(KUidContactFieldSuffixNameValue ); |
|
104 VM(KUidContactFieldPrefixNameValue ); |
|
105 VM(KUidContactFieldHiddenValue ); |
|
106 VM(KUidContactFieldEMailValue ); |
|
107 VM(KUidContactFieldMsgValue ); |
|
108 VM(KUidContactFieldSmsValue ); |
|
109 VM(KUidContactFieldFaxValue ); |
|
110 |
|
111 VM(KUidContactFieldDefinedTextValue ); |
|
112 VM(KUidContactFieldNoteValue ); |
|
113 VM(KUidContactFieldBirthdayValue ); |
|
114 VM(KUidContactFieldUrlValue ); |
|
115 VM(KUidContactFieldStorageInlineValue); |
|
116 VM(KUidContactFieldTemplateLabelValue); |
|
117 VM(KUidContactFieldPictureValue ); |
|
118 VM(KUidContactFieldRingToneValue ); |
|
119 VM(KUidContactFieldDTMFValue ); |
|
120 VM(KUidContactsVoiceDialFieldValue ); |
|
121 VM(KUidContactFieldNoneValue ); |
|
122 VM(KUidContactFieldJobTitleValue ); |
|
123 VM(KUidContactFieldICCSlotValue ); |
|
124 VM(KUidContactFieldICCPhonebookValue); |
|
125 VM(KUidContactFieldICCGroupValue ); |
|
126 VM(KUidContactFieldIMAddressValue ); |
|
127 VM(KUidContactFieldSecondNameValue ); |
|
128 VM(KUidContactFieldSIPIDValue ); |
|
129 |
|
130 VM(KIntContactFieldVCardMapWORK ); |
|
131 VM(KIntContactFieldVCardMapHOME ); |
|
132 VM(KIntContactFieldVCardMapMSG ); |
|
133 VM(KIntContactFieldVCardMapVOICE); |
|
134 VM(KIntContactFieldVCardMapFAX ); |
|
135 VM(KIntContactFieldVCardMapPREF ); |
|
136 VM(KIntContactFieldVCardMapCELL ); |
|
137 VM(KIntContactFieldVCardMapPAGER); |
|
138 VM(KIntContactFieldVCardMapBBS ); |
|
139 VM(KIntContactFieldVCardMapMODEM); |
|
140 VM(KIntContactFieldVCardMapCAR ); |
|
141 VM(KIntContactFieldVCardMapISDN ); |
|
142 VM(KIntContactFieldVCardMapVIDEO); |
|
143 VM(KIntContactFieldVCardMapDOM ); |
|
144 |
|
145 VM(KIntContactFieldVCardMapADR ); |
|
146 VM(KIntContactFieldVCardMapPOSTOFFICE ); |
|
147 VM(KIntContactFieldVCardMapEXTENDEDADR ); |
|
148 VM(KIntContactFieldVCardMapLOCALITY ); |
|
149 VM(KIntContactFieldVCardMapREGION ); |
|
150 VM(KIntContactFieldVCardMapPOSTCODE ); |
|
151 VM(KIntContactFieldVCardMapCOUNTRY ); |
|
152 VM(KIntContactFieldVCardMapAGENT ); |
|
153 VM(KIntContactFieldVCardMapBDAY ); |
|
154 VM(KIntContactFieldVCardMapEMAILINTERNET); |
|
155 VM(KIntContactFieldVCardMapGEO ); |
|
156 VM(KIntContactFieldVCardMapLABEL ); |
|
157 VM(KIntContactFieldVCardMapLOGO ); |
|
158 VM(KIntContactFieldVCardMapMAILER ); |
|
159 VM(KIntContactFieldVCardMapNOTE ); |
|
160 VM(KIntContactFieldVCardMapORG ); |
|
161 VM(KIntContactFieldVCardMapORGPronunciation ); |
|
162 VM(KIntContactFieldVCardMapPHOTO ); |
|
163 VM(KIntContactFieldVCardMapROLE ); |
|
164 VM(KIntContactFieldVCardMapSOUND ); |
|
165 VM(KIntContactFieldVCardMapTEL ); |
|
166 VM(KIntContactFieldVCardMapTELFAX ); |
|
167 VM(KIntContactFieldVCardMapTITLE ); |
|
168 VM(KIntContactFieldVCardMapURL ); |
|
169 VM(KIntContactFieldVCardMapUnusedN ); |
|
170 VM(KIntContactFieldVCardMapUnusedFN ); |
|
171 VM(KIntContactFieldVCardMapNotRequired ); |
|
172 VM(KIntContactFieldVCardMapUnknownXDash ); |
|
173 VM(KIntContactFieldVCardMapUnknown ); |
|
174 VM(KIntContactFieldVCardMapUID ); |
|
175 VM(KIntContactFieldVCardMapINTL ); |
|
176 VM(KIntContactFieldVCardMapPOSTAL ); |
|
177 VM(KIntContactFieldVCardMapPARCEL ); |
|
178 VM(KIntContactFieldVCardMapGIF ); |
|
179 VM(KIntContactFieldVCardMapCGM ); |
|
180 VM(KIntContactFieldVCardMapWMF ); |
|
181 VM(KIntContactFieldVCardMapBMP ); |
|
182 VM(KIntContactFieldVCardMapMET ); |
|
183 VM(KIntContactFieldVCardMapPMB ); |
|
184 VM(KIntContactFieldVCardMapDIB ); |
|
185 VM(KIntContactFieldVCardMapPICT ); |
|
186 VM(KIntContactFieldVCardMapTIFF ); |
|
187 VM(KIntContactFieldVCardMapPDF ); |
|
188 VM(KIntContactFieldVCardMapPS ); |
|
189 VM(KIntContactFieldVCardMapJPEG ); |
|
190 VM(KIntContactFieldVCardMapMPEG ); |
|
191 VM(KIntContactFieldVCardMapMPEG2 ); |
|
192 VM(KIntContactFieldVCardMapAVI ); |
|
193 VM(KIntContactFieldVCardMapQTIME ); |
|
194 VM(KIntContactFieldVCardMapTZ ); |
|
195 VM(KIntContactFieldVCardMapKEY ); |
|
196 |
|
197 VM(KIntContactFieldVCardMapX509 ); |
|
198 VM(KIntContactFieldVCardMapPGP ); |
|
199 VM(KIntContactFieldVCardMapSMIME ); |
|
200 VM(KIntContactFieldVCardMapWV ); |
|
201 VM(KIntContactFieldVCardMapSECONDNAME ); |
|
202 VM(KIntContactFieldVCardMapSIPID ); |
|
203 VM(KIntContactFieldVCardMapPOC ); |
|
204 VM(KIntContactFieldVCardMapSWIS ); |
|
205 VM(KIntContactFieldVCardMapVOIP ); |
|
206 default: return _S("Unknown"); |
|
207 }; |
|
208 }; |
|
209 |
|
210 |
|
211 |
|
212 class CMyField : public CBase |
|
213 { |
|
214 public: |
|
215 CContentType *iContentType; |
|
216 TStorageType iStorageType; |
|
217 HBufC* iLabel; |
|
218 TInt iId; |
|
219 TUint32 iAttributes; |
|
220 TUint32 iExtendedAttributes; |
|
221 CContactFieldStorage* iStorage; |
|
222 TInt iTemplateFieldId; |
|
223 }; |
|
224 |
|
225 |
|
226 void PrintFieldsTableL(RFile& outFile, const CContactItemFieldSet& fldSet, TBuf8<255>& buf) |
|
227 { |
|
228 SDescArr sTStorageType[] = { |
|
229 _S("KStorageTypeText"), |
|
230 _S("KStorageTypeStore"), |
|
231 _S("KStorageTypeContactIt"), |
|
232 _S("KStorageTypeDateTime") |
|
233 }; |
|
234 |
|
235 SFlagsDict sFieldFlag[]= { |
|
236 FF(EHidden), |
|
237 FF(EReadOnly), |
|
238 FF(ESynchronize), |
|
239 FF(EDisabled), |
|
240 FF(EUserMask), |
|
241 FF(EOverRidesLabel), |
|
242 FF(EUsesTemplateData), |
|
243 FF(EUserAddedField), |
|
244 FF(ETemplate), |
|
245 FF(ELabelUnspecified), |
|
246 FF(EDeleted), |
|
247 FF(NbTestLast) |
|
248 }; |
|
249 |
|
250 outFile.Write(_L8("<html><body><table width=100% cellpadding=1 cellspacing=1 border=1>")); |
|
251 outFile.Write(_L8("<tr><td>Fld</td><td>Label</td><td>Field types:</td><td>Storg type</td>" \ |
|
252 "<td>Field</td><td>Attr</td><td>Ext.Att</td><td>Templ</td></tr>\r\n")); |
|
253 |
|
254 const TInt numOfFields = fldSet.Count(); |
|
255 for (TInt i=0; i < numOfFields; ++i) |
|
256 { |
|
257 const CContactItemField& field = fldSet[i]; |
|
258 const CMyField& myField = reinterpret_cast<const CMyField&>(field); |
|
259 const CContentType& conType = *myField.iContentType; |
|
260 |
|
261 buf.Format(_L8("<tr><td>%d</td>"), myField.iId); |
|
262 outFile.Write(buf); |
|
263 |
|
264 outFile.Write(_L8("<td>")); |
|
265 if (myField.iLabel) |
|
266 { |
|
267 buf.Copy(*myField.iLabel); |
|
268 outFile.Write(buf); |
|
269 } |
|
270 outFile.Write(_L8("</td>\r\n")); |
|
271 |
|
272 //test.Printf(_L("Field types are:")); |
|
273 outFile.Write(_L8("<td>")); |
|
274 |
|
275 for(TInt j=0; j < conType.FieldTypeCount(); ++j) |
|
276 { |
|
277 const TFieldType& fldType = conType.FieldType(j); |
|
278 //test.Printf(_L(" %s"), VCardMaping(fldType)); |
|
279 const TPtrC str = VCardMaping(fldType); |
|
280 buf.Copy(str); |
|
281 outFile.Write(buf); |
|
282 outFile.Write(_L8(",<br>")); |
|
283 } |
|
284 |
|
285 //Print Mapping of the field |
|
286 outFile.Write(_L8("MP>: ")); |
|
287 const TPtrC mapp = VCardMaping(conType.Mapping()); |
|
288 buf.Copy(mapp); |
|
289 outFile.Write(buf); |
|
290 |
|
291 outFile.Write(_L8("</td>\r\n<td>")); |
|
292 |
|
293 //test.Printf(_L("Storg type: %s"), sTStorageType[myField.iStorageType]); |
|
294 const TPtrC str (sTStorageType[myField.iStorageType]); |
|
295 buf.Copy(str); |
|
296 outFile.Write(buf); |
|
297 |
|
298 outFile.Write(_L8("</td>\r\n<td>")); |
|
299 switch(myField.iStorageType) |
|
300 { |
|
301 case KStorageTypeText: |
|
302 { |
|
303 const TPtrC& textFld = static_cast<CContactTextField*>(field.Storage())->Text(); |
|
304 //test.Printf(_L("Text : %S"), textFld); |
|
305 buf.Copy(textFld); |
|
306 outFile.Write(buf); |
|
307 } |
|
308 break; |
|
309 default: |
|
310 break; |
|
311 } |
|
312 |
|
313 outFile.Write(_L8("</td>\r\n")); |
|
314 |
|
315 //test.Printf(_L("Attributes: 0x%08x"), myField.iAttributes); |
|
316 buf.Format(_L8("<td>0x%08x"), myField.iAttributes); |
|
317 outFile.Write(buf); |
|
318 |
|
319 for (TInt i = 0;; ++i) |
|
320 { |
|
321 const SFlagsDict& aFlag = sFieldFlag[i]; |
|
322 |
|
323 if (aFlag.iFlag & myField.iAttributes) |
|
324 { |
|
325 TPtrC str(aFlag.iDescript); |
|
326 buf.Copy(str); |
|
327 |
|
328 outFile.Write(_L8(",<br>")); |
|
329 outFile.Write(buf); |
|
330 } |
|
331 |
|
332 |
|
333 if (aFlag.iFlag == NbTestLast) |
|
334 { |
|
335 break; |
|
336 } |
|
337 } |
|
338 |
|
339 outFile.Write(_L8("</td>\r\n")); |
|
340 |
|
341 //test.Printf(_L("Ext Attrib: 0x%08x"), myField.iExtendedAttributes); |
|
342 buf.Format(_L8("<td>0x%08x</td>\r\n"), myField.iExtendedAttributes); |
|
343 outFile.Write(buf); |
|
344 |
|
345 //test.Printf(_L("Temp fldId: 0x%08x"), myField.iTemplateFieldId); |
|
346 buf.Format(_L8("<td>%d</td>\r\n"), myField.iTemplateFieldId); |
|
347 outFile.Write(buf); |
|
348 |
|
349 |
|
350 outFile.Write(_L8("</tr>\r\n\r\n")); |
|
351 } |
|
352 |
|
353 outFile.Write(_L8("</table></body></html>\r\n")); |
|
354 } |
|
355 |
|
356 |
|
357 |
|
358 void PrintIdArrayL(RFile& outFile, const CContactIdArray* aArray, const TDesC8& aLabel, TBuf8<255>& buf) |
|
359 { |
|
360 outFile.Write(_L8("<tr><td>")); |
|
361 outFile.Write(aLabel); |
|
362 outFile.Write(_L8("</td><td>")); |
|
363 if (aArray) //If array exists |
|
364 { |
|
365 for (TInt i = 0; i < aArray->Count(); ++i) |
|
366 { |
|
367 const TContactItemId id = (*aArray)[i]; |
|
368 if (i) |
|
369 { |
|
370 outFile.Write(_L8("<br/>")); |
|
371 } |
|
372 |
|
373 buf.Format(_L8("%d (%x)"), id, id); |
|
374 outFile.Write(buf); |
|
375 } |
|
376 } |
|
377 else |
|
378 { |
|
379 outFile.Write(_L8("Not Initialised")); |
|
380 } |
|
381 outFile.Write(_L8("</td></tr>\r\n")); |
|
382 } |
|
383 |
|
384 |
|
385 class CMyContact : public CBase |
|
386 { |
|
387 public: |
|
388 CContactItemFieldSet* iFieldSet; |
|
389 TUint32 iAttributes; |
|
390 TContactItemId iId; |
|
391 TContactItemId iTemplateRefId; |
|
392 TTime iLastModified; |
|
393 TTime iCreationDate; |
|
394 TUint32 iAccessCount; |
|
395 HBufC* iGuid; |
|
396 }; |
|
397 |
|
398 class CMyContactPlusGroup : public CMyContact |
|
399 { |
|
400 public: |
|
401 CContactIdArray* iGroups; |
|
402 }; |
|
403 |
|
404 class CMyContactGroup : public CMyContactPlusGroup |
|
405 { |
|
406 public: |
|
407 CContactIdArray* iItems; |
|
408 }; |
|
409 |
|
410 EXPORT_C void PrintContactL(const TDesC& aFilename, const CContactItem& aContact) |
|
411 { |
|
412 TBuf8<255> buf; |
|
413 TBuf16<100> buf16; |
|
414 |
|
415 RFs fs; |
|
416 User::LeaveIfError(fs.Connect()); |
|
417 CleanupClosePushL(fs); |
|
418 |
|
419 fs.MkDirAll(aFilename); |
|
420 |
|
421 RFile outFile; |
|
422 User::LeaveIfError(outFile.Replace(fs, aFilename, EFileWrite | EFileStreamText)); |
|
423 CleanupClosePushL(outFile); |
|
424 |
|
425 const CMyContact& myContact = reinterpret_cast<const CMyContact&>(aContact); |
|
426 |
|
427 buf.Format(_L8("<table><tr><td>Attributes:</td><td>0x%08x</td></tr>\r\n"), myContact.iAttributes); |
|
428 outFile.Write(buf); |
|
429 |
|
430 buf.Format(_L8("<tr><td>Contact ID:</td><td>%d (%x)</td></tr>\r\n"), myContact.iId, myContact.iId); |
|
431 outFile.Write(buf); |
|
432 |
|
433 buf.Format(_L8("<tr><td>Template Ref ID:</td><td> %d (%x)</td></tr>\r\n"), myContact.iTemplateRefId, myContact.iTemplateRefId); |
|
434 outFile.Write(buf); |
|
435 |
|
436 |
|
437 /* outFile.Write(_L8("<tr><td>Last Modified:</td><td>")); |
|
438 myContact.iLastModified.FormatL(buf16,KDateTimeFormat); |
|
439 buf.Copy(buf16); |
|
440 outFile.Write(buf); |
|
441 outFile.Write(_L8("</td></tr>\r\n")); |
|
442 |
|
443 outFile.Write(_L8("<tr><td>Creation Date:</td><td>")); |
|
444 myContact.iCreationDate.FormatL(buf16,KDateTimeFormat); |
|
445 buf.Copy(buf16); |
|
446 outFile.Write(buf); |
|
447 outFile.Write(_L8("</td></tr>\r\n"));*/ |
|
448 |
|
449 buf.Format(_L8("<tr><td>Access count:</td><td> %d</td></tr>\r\n"), myContact.iTemplateRefId, myContact.iAccessCount); |
|
450 outFile.Write(buf); |
|
451 |
|
452 |
|
453 if (aContact.Type() == KUidContactCard || |
|
454 aContact.Type() == KUidContactGroup || |
|
455 aContact.Type() == KUidContactOwnCard) |
|
456 { |
|
457 const CMyContactPlusGroup& myContactPlusGroup = reinterpret_cast<const CMyContactPlusGroup&>(aContact); |
|
458 PrintIdArrayL(outFile, myContactPlusGroup.iGroups, _L8("Belongs to"), buf); |
|
459 |
|
460 if (aContact.Type() == KUidContactGroup) |
|
461 { |
|
462 const CMyContactGroup& myContactGrp = reinterpret_cast<const CMyContactGroup&>(aContact); |
|
463 PrintIdArrayL(outFile, myContactGrp.iItems, _L8("Contains"), buf); |
|
464 } |
|
465 } |
|
466 |
|
467 outFile.Write(_L8("</table><br/>\r\n")); |
|
468 |
|
469 PrintFieldsTableL(outFile, aContact.CardFields(), buf); |
|
470 |
|
471 CleanupStack::PopAndDestroy(&outFile); |
|
472 CleanupStack::PopAndDestroy(&fs); |
|
473 } |
|
474 |
|
475 |
|
476 |