|
1 // fcontacts.cpp |
|
2 // |
|
3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "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 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #include <fshell/ioutils.h> |
|
14 #include <CNTDB.H> |
|
15 #include <CNTITEM.H> |
|
16 #include <CNTFLDST.H> |
|
17 |
|
18 // Some things that v9.1 doesn't have |
|
19 #include "fcontacts_support.h" |
|
20 |
|
21 using namespace IoUtils; |
|
22 |
|
23 class CCmdContacts : public CCommandBase |
|
24 { |
|
25 public: |
|
26 static CCommandBase* NewLC(); |
|
27 ~CCmdContacts(); |
|
28 private: |
|
29 CCmdContacts(); |
|
30 |
|
31 TInt CheckDuplicateAndUpdate(CContactItemFieldSet &aFieldSet, CContactItemField &aField); |
|
32 void FillContactFieldSetL(CContactItemFieldSet &aFieldSet, TUid aType); |
|
33 void PrintContact(CContactItem* aContact); |
|
34 |
|
35 void PrintGroupContentsL(CContactItem* aContactGroup, TInt aVerboseLevel); |
|
36 void PrintGroupsJoined(CContactItem* aContact, TInt aVerboseLevel); |
|
37 void PrintTime(const TTime& aTime, TBool aNewline=EFalse); |
|
38 |
|
39 void PrintAcceptedOptions(); |
|
40 static const TDesC* UidName(TUid aUid); |
|
41 private: // From CCommandBase. |
|
42 virtual const TDesC& Name() const; |
|
43 virtual void DoRunL(); |
|
44 virtual void ArgumentsL(RCommandArgumentList& aArguments); |
|
45 virtual void OptionsL(RCommandOptionList& aOptions); |
|
46 |
|
47 void DoListL(); |
|
48 void DoAddL(); |
|
49 void DoDeleteL(); |
|
50 void DoChangeL(); |
|
51 void DoDeleteAllL(); |
|
52 void DoCreateGroupL(); |
|
53 void DoAddToGroupL(); |
|
54 void DoCompactL(); |
|
55 private: |
|
56 |
|
57 CContactDatabase* iDb; |
|
58 RArray<TBool> iVerbose; |
|
59 TInt iOptContactId; |
|
60 TInt iOptDestGrpId; |
|
61 HBufC* iMatch; |
|
62 TBool iShowFirstPhoneOnly; |
|
63 |
|
64 HBufC* iOptFirstName; |
|
65 HBufC* iOptLastName; |
|
66 HBufC* iOptTelephone; |
|
67 HBufC* iOptMobile; |
|
68 TFileName2 iOptPhotoFileName; |
|
69 HBufC* iOptGroupName; |
|
70 |
|
71 HBufC* iOptStr; |
|
72 enum |
|
73 { |
|
74 EList, EAdd, EDelete, EChange, EDeleteAll, ECreateGroup, EAddToGroup, ECompact |
|
75 } iCommand; |
|
76 }; |
|
77 |
|
78 |
|
79 CCommandBase* CCmdContacts::NewLC() |
|
80 { |
|
81 CCmdContacts* self = new(ELeave) CCmdContacts(); |
|
82 CleanupStack::PushL(self); |
|
83 self->BaseConstructL(); |
|
84 return self; |
|
85 } |
|
86 |
|
87 CCmdContacts::~CCmdContacts() |
|
88 { |
|
89 delete iOptFirstName; |
|
90 delete iOptLastName; |
|
91 delete iOptTelephone; |
|
92 delete iOptMobile; |
|
93 delete iOptGroupName; |
|
94 delete iOptStr; |
|
95 delete iMatch; |
|
96 delete iDb; |
|
97 iVerbose.Close(); |
|
98 } |
|
99 |
|
100 CCmdContacts::CCmdContacts() |
|
101 { |
|
102 } |
|
103 |
|
104 const TDesC& CCmdContacts::Name() const |
|
105 { |
|
106 _LIT(KName, "fcontacts"); |
|
107 return KName; |
|
108 } |
|
109 |
|
110 void CCmdContacts::ArgumentsL(RCommandArgumentList& aArguments) |
|
111 { |
|
112 aArguments.AppendEnumL((TInt&)iCommand, _L("command")); |
|
113 } |
|
114 |
|
115 void CCmdContacts::OptionsL(RCommandOptionList& aOptions) |
|
116 { |
|
117 aOptions.AppendBoolL(iVerbose, _L("verbose")); |
|
118 aOptions.AppendUintL((TUint&)iOptContactId, _L("contact-id")); |
|
119 aOptions.AppendUintL((TUint&)iOptDestGrpId, _L("group-id")); |
|
120 aOptions.AppendStringL(iMatch, _L("match")); |
|
121 aOptions.AppendBoolL(iShowFirstPhoneOnly, _L("first-phone-only")); |
|
122 aOptions.AppendStringL(iOptFirstName, _L("first-name")); |
|
123 aOptions.AppendStringL(iOptLastName, _L("last-name")); |
|
124 aOptions.AppendStringL(iOptTelephone, _L("telephone")); |
|
125 aOptions.AppendStringL(iOptMobile, _L("mobile")); |
|
126 aOptions.AppendFileNameL(iOptPhotoFileName, _L("photo")); |
|
127 aOptions.AppendStringL(iOptGroupName, _L("group")); |
|
128 } |
|
129 |
|
130 void CCmdContacts::DoRunL() |
|
131 { |
|
132 TRAPD(err, iDb = CContactDatabase::OpenL()); |
|
133 LeaveIfErr(err, _L("Couldn't open contacts database")); |
|
134 |
|
135 switch (iCommand) |
|
136 { |
|
137 case EList: |
|
138 DoListL(); |
|
139 break; |
|
140 case EAdd: |
|
141 DoAddL(); |
|
142 break; |
|
143 case EDelete: |
|
144 DoDeleteL(); |
|
145 break; |
|
146 case EChange: |
|
147 DoChangeL(); |
|
148 break; |
|
149 case EDeleteAll: |
|
150 DoDeleteAllL(); |
|
151 break; |
|
152 case ECreateGroup: |
|
153 DoCreateGroupL(); |
|
154 break; |
|
155 case EAddToGroup: |
|
156 DoAddToGroupL(); |
|
157 break; |
|
158 case ECompact: |
|
159 DoCompactL(); |
|
160 break; |
|
161 } |
|
162 } |
|
163 |
|
164 |
|
165 void CCmdContacts::DoListL() |
|
166 { |
|
167 if (iOptContactId) |
|
168 { |
|
169 CContactItem* contact = NULL; |
|
170 TRAPD(err, contact = iDb->ReadContactL(iOptContactId)); |
|
171 LeaveIfErr(err, _L("Couldn't read contact %d"), iOptContactId); |
|
172 PrintContact(contact); |
|
173 delete contact; |
|
174 } |
|
175 else |
|
176 { |
|
177 // List all |
|
178 TContactIter iter(*iDb); |
|
179 TContactItemId id; |
|
180 TBool foundMatch = EFalse; |
|
181 while ((id = iter.NextL()) != KNullContactId) |
|
182 { |
|
183 CContactItem* contact = iDb->ReadContactLC(id); |
|
184 TBool show = ETrue; |
|
185 if (iMatch) |
|
186 { |
|
187 show = EFalse; |
|
188 CContactItemFieldSet& fields = contact->CardFields(); |
|
189 TInt num = fields.Count(); |
|
190 for (TInt i = 0; i < num; i++) |
|
191 { |
|
192 CContactItemField& field = fields[i]; |
|
193 switch (field.StorageType()) |
|
194 { |
|
195 case KStorageTypeText: |
|
196 if (field.TextStorage()->Text().MatchF(*iMatch) != KErrNotFound) |
|
197 { |
|
198 show = ETrue; |
|
199 foundMatch = ETrue; |
|
200 } |
|
201 break; |
|
202 default: |
|
203 break; |
|
204 } |
|
205 if (show) break; |
|
206 } |
|
207 } |
|
208 if (show) |
|
209 { |
|
210 PrintContact(contact); |
|
211 } |
|
212 CleanupStack::PopAndDestroy(contact); |
|
213 if (show && iShowFirstPhoneOnly) |
|
214 { |
|
215 break; |
|
216 } |
|
217 } |
|
218 if (iMatch && !foundMatch) |
|
219 { |
|
220 User::Leave(KErrNotFound); |
|
221 } |
|
222 } |
|
223 } |
|
224 |
|
225 void CCmdContacts::DoAddL() |
|
226 { |
|
227 TContactItemId newId = 0; |
|
228 //create a "contact card" contact item |
|
229 CContactItem* contact = CContactCard::NewLC(); |
|
230 CContactItemFieldSet& fieldSet = contact->CardFields(); |
|
231 FillContactFieldSetL(fieldSet, KUidContactCard); |
|
232 |
|
233 TRAPD(err, newId = iDb->AddNewContactL(*contact)); |
|
234 LeaveIfErr(err, _L("Could not add this contact")); |
|
235 |
|
236 Printf(_L("Contact Added\r\nContact ID:%d\r\n"), newId); |
|
237 CleanupStack::PopAndDestroy(contact); |
|
238 } |
|
239 |
|
240 |
|
241 void CCmdContacts::DoDeleteL() |
|
242 { |
|
243 if (iOptContactId) |
|
244 { |
|
245 TRAPD(err, iDb->DeleteContactL(iOptContactId)); |
|
246 if (err == KErrNone) |
|
247 { |
|
248 Printf(_L("Contact %d deleted\r\n"), iOptContactId); |
|
249 } |
|
250 else |
|
251 { |
|
252 LeaveIfErr(err, _L("Could not detelet contact item %d"), iOptContactId); |
|
253 } |
|
254 } |
|
255 else |
|
256 { |
|
257 LeaveIfErr(KErrArgument, _L("No contact id specified. Use -i to specify a contact ID")); |
|
258 } |
|
259 } |
|
260 |
|
261 |
|
262 void CCmdContacts::DoChangeL() |
|
263 { |
|
264 if (iOptContactId) |
|
265 { |
|
266 PrintAcceptedOptions(); |
|
267 CContactItem* contact = NULL; |
|
268 TRAPD(err, contact = iDb->OpenContactL(iOptContactId)); |
|
269 LeaveIfErr(err, _L("could not open contact item %d"), iOptContactId); |
|
270 |
|
271 CleanupStack::PushL(contact); |
|
272 |
|
273 CContactItemFieldSet& FieldSet = contact->CardFields(); |
|
274 FillContactFieldSetL(FieldSet, KUidContactCard); |
|
275 |
|
276 TRAP(err, iDb->CommitContactL(*contact)); |
|
277 LeaveIfErr(err, _L("Could not commit the change for item %d"), iOptContactId); |
|
278 |
|
279 CleanupStack::PopAndDestroy(contact); |
|
280 |
|
281 } |
|
282 else |
|
283 { |
|
284 LeaveIfErr(KErrArgument, _L("No contact id specified. Use -i to specify a contact ID")); |
|
285 } |
|
286 } |
|
287 |
|
288 void CCmdContacts::DoDeleteAllL() |
|
289 { |
|
290 TInt TotalErrors = 0; //how many items are not deleted due to error |
|
291 TInt ContactItemCnt = iDb->CountL(); |
|
292 Printf(_L("Database contains %d items \r\n"), ContactItemCnt); |
|
293 // List all |
|
294 TContactIter iter(*iDb); |
|
295 TContactItemId id; |
|
296 while ((id = iter.NextL()) != KNullContactId) |
|
297 { |
|
298 Printf(_L("Deleting contact item %d ..."), id); |
|
299 TRAPD(err, iDb->DeleteContactL(id)); |
|
300 |
|
301 if (err==KErrNone) |
|
302 Printf(_L("done \r\n"), id); |
|
303 else |
|
304 { |
|
305 TotalErrors++; |
|
306 Printf(_L("fail, error code=%d \r\n"), err); |
|
307 } |
|
308 } |
|
309 |
|
310 if (TotalErrors > 0) |
|
311 { |
|
312 LeaveIfErr(KErrGeneral, _L("%d items are not deleted due to error"), TotalErrors); |
|
313 } |
|
314 } |
|
315 |
|
316 void CCmdContacts::DoCreateGroupL() |
|
317 { |
|
318 Printf(_L("Creating a new group... \r\n")); |
|
319 CContactItem* contact = NULL; |
|
320 TRAPD(err, contact = iDb->CreateContactGroupL()); |
|
321 LeaveIfErr(err, _L("Could not create contact group")); |
|
322 |
|
323 CleanupStack::PushL(contact); |
|
324 TContactItemId GroupId = contact->Id(); |
|
325 CleanupStack::PopAndDestroy(contact); |
|
326 contact = NULL; |
|
327 |
|
328 /////////////////////////////////////////////////// |
|
329 TRAP(err, contact = iDb->OpenContactL(GroupId)); |
|
330 LeaveIfErr(err, _L("Could not open contact group for editing")); |
|
331 CleanupStack::PushL(contact); |
|
332 |
|
333 Printf(_L("Changing group name for contact item %d... \r\n"), GroupId); |
|
334 |
|
335 CContactItemFieldSet& FieldSet = contact->CardFields(); |
|
336 FillContactFieldSetL(FieldSet, KUidContactGroup); |
|
337 TRAP(err, iDb->CommitContactL(*contact)); |
|
338 LeaveIfErr(err, _L("Could not sumbit the change")); |
|
339 |
|
340 CleanupStack::PopAndDestroy(contact); |
|
341 |
|
342 } |
|
343 |
|
344 void CCmdContacts::DoCompactL() |
|
345 { |
|
346 TRAPD(err, iDb->CompactL()); |
|
347 LeaveIfErr(err, _L("Could not compact the database")); |
|
348 } |
|
349 |
|
350 void CCmdContacts::DoAddToGroupL() |
|
351 { |
|
352 if (iOptContactId && iOptDestGrpId) |
|
353 { |
|
354 Printf(_L("Adding contact item %d to destination group item %d \r\n"), |
|
355 iOptContactId, iOptDestGrpId); |
|
356 TRAPD(err, iDb->AddContactToGroupL( (TContactItemId)iOptContactId, (TContactItemId)iOptDestGrpId) ) ; |
|
357 |
|
358 //this is most common mistake, need to point out especially to remind the user. |
|
359 if (err==KErrNotSupported) |
|
360 PrintError(KErrNotSupported, _L("Destination is not a group")); |
|
361 |
|
362 User::LeaveIfError(err); |
|
363 |
|
364 } |
|
365 else |
|
366 { |
|
367 LeaveIfErr(KErrArgument, _L("No contact id specified. Use -i to specify a contact ID")); |
|
368 } |
|
369 } |
|
370 |
|
371 |
|
372 // FOR TEST PURPOSE |
|
373 //to check if a field of the same type has already existed in a FieldSet. |
|
374 //if yes, delete that field first and then add it |
|
375 TInt CCmdContacts::CheckDuplicateAndUpdate(CContactItemFieldSet &aFieldSet, CContactItemField &aField) |
|
376 { |
|
377 const CContentType &newContentType=aField.ContentType(); |
|
378 TInt fieldPos=0; |
|
379 |
|
380 TInt FieldCnt = aFieldSet.Count(); |
|
381 for(; fieldPos<FieldCnt ; fieldPos++ ) |
|
382 { |
|
383 CContactItemField& TestedField = aFieldSet[fieldPos]; |
|
384 if (newContentType == TestedField.ContentType()) |
|
385 { |
|
386 aFieldSet.Remove(fieldPos); |
|
387 break; |
|
388 } |
|
389 } |
|
390 |
|
391 if (aField.Storage()->IsFull()) |
|
392 { |
|
393 CContactItemField* field=CContactItemField::NewLC(aField); |
|
394 aFieldSet.InsertL(fieldPos,*field); |
|
395 CleanupStack::Pop(); // field |
|
396 } |
|
397 |
|
398 return 0; |
|
399 } |
|
400 |
|
401 //this function will retrieve infomation from command line arguments and fill them into |
|
402 //a field set, FieldSet doesn't have to be empty |
|
403 //aType: either KUidContactCard or KUidContactGroup |
|
404 void CCmdContacts::FillContactFieldSetL(CContactItemFieldSet &aFieldSet, TUid aType) |
|
405 { |
|
406 if (aType == KUidContactGroup) |
|
407 { |
|
408 //group name |
|
409 if (iOptGroupName && iOptGroupName->Length()) |
|
410 { |
|
411 CContactItemField* field = NULL; |
|
412 field = CContactItemField::NewLC(KStorageTypeText); |
|
413 field->SetLabelL(_L("Group Label")); |
|
414 field->SetMapping(KUidContactFieldNone); |
|
415 field->AddFieldTypeL(KUidContactFieldTemplateLabel); |
|
416 CContactTextField* pFieldText = field->TextStorage(); |
|
417 pFieldText->SetTextL(*iOptGroupName); |
|
418 aFieldSet.UpdateFieldL(*field, 1); |
|
419 CleanupStack::PopAndDestroy(field); |
|
420 } |
|
421 } |
|
422 |
|
423 //Synchronization, for both Group and normal contacts |
|
424 { |
|
425 CContactItemField* field = NULL; |
|
426 field = CContactItemField::NewLC(KStorageTypeText); |
|
427 field->SetLabelL(_L("Synchronization")); |
|
428 field->SetMapping(KUidContactFieldVCardMapClass); |
|
429 field->AddFieldTypeL(KUidContactFieldClass); |
|
430 CContactTextField* pFieldText = field->TextStorage(); |
|
431 pFieldText->SetTextL(_L("private")); |
|
432 aFieldSet.UpdateFieldL(*field, 1); |
|
433 CleanupStack::PopAndDestroy(field); |
|
434 } |
|
435 |
|
436 if (aType == KUidContactCard) |
|
437 { |
|
438 //last name |
|
439 if (iOptLastName && iOptLastName->Length()) |
|
440 { |
|
441 CContactItemField* field = NULL; |
|
442 field = CContactItemField::NewLC(KStorageTypeText); |
|
443 field->SetLabelL(_L("Last name")); |
|
444 field->SetMapping(KUidContactFieldVCardMapUnusedN); |
|
445 field->AddFieldTypeL(KUidContactFieldFamilyName); |
|
446 CContactTextField* pFieldText = field->TextStorage(); |
|
447 pFieldText->SetTextL(*iOptLastName); |
|
448 aFieldSet.UpdateFieldL(*field, 1); |
|
449 CleanupStack::PopAndDestroy(field); |
|
450 } |
|
451 |
|
452 //first name |
|
453 if (iOptFirstName && iOptFirstName->Length()) |
|
454 { |
|
455 CContactItemField* field = NULL; |
|
456 field = CContactItemField::NewLC(KStorageTypeText); |
|
457 field->SetLabelL(_L("First name")); |
|
458 field->SetMapping(KUidContactFieldVCardMapUnusedN); |
|
459 field->AddFieldTypeL(KUidContactFieldGivenName); |
|
460 CContactTextField* pFieldText = field->TextStorage(); |
|
461 pFieldText->SetTextL(*iOptFirstName); |
|
462 aFieldSet.UpdateFieldL(*field, 1); |
|
463 CleanupStack::PopAndDestroy(field); |
|
464 } |
|
465 //general telephone |
|
466 if (iOptTelephone && iOptTelephone->Length()) |
|
467 { |
|
468 CContactItemField* field = NULL; |
|
469 field = CContactItemField::NewLC(KStorageTypeText); |
|
470 field->SetLabelL(_L("Telephone")); |
|
471 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
472 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
473 field->AddFieldTypeL(KUidContactFieldVCardMapVOICE); |
|
474 CContactTextField* pFieldText = field->TextStorage(); |
|
475 pFieldText->SetTextL(*iOptTelephone); |
|
476 aFieldSet.UpdateFieldL(*field, 1); |
|
477 CleanupStack::PopAndDestroy(field); |
|
478 } |
|
479 //mobile phone |
|
480 if (iOptMobile && iOptMobile->Length()) |
|
481 { |
|
482 CContactItemField* field = NULL; |
|
483 field = CContactItemField::NewLC(KStorageTypeText); |
|
484 field->SetLabelL(_L("Mobile")); |
|
485 field->SetMapping(KUidContactFieldVCardMapTEL); |
|
486 field->AddFieldTypeL(KUidContactFieldPhoneNumber); |
|
487 field->AddFieldTypeL(KUidContactFieldVCardMapCELL); |
|
488 CContactTextField* pFieldText = field->TextStorage(); |
|
489 pFieldText->SetTextL(*iOptMobile); |
|
490 aFieldSet.UpdateFieldL(*field, 1); |
|
491 CleanupStack::PopAndDestroy(field); |
|
492 } |
|
493 |
|
494 //photo |
|
495 if (iOptPhotoFileName.Length()) |
|
496 { |
|
497 RFile file; |
|
498 LeaveIfErr(file.Open(FsL(), iOptPhotoFileName, EFileRead), _L("Couldn't open file \"%S\""), &iOptPhotoFileName); |
|
499 TInt fileSize; |
|
500 LeaveIfErr(file.Size(fileSize), _L("Couldn't read the size of file \"%S\""), &iOptPhotoFileName); |
|
501 RBuf8 buf; |
|
502 buf.Create(fileSize); |
|
503 buf.CleanupClosePushL(); |
|
504 LeaveIfErr(file.Read(buf), _L("Couldn't read the contents of file \"%S\""), &iOptPhotoFileName); |
|
505 |
|
506 CContactItemField* field = CContactItemField::NewLC(KStorageTypeStore); |
|
507 field->SetLabelL(_L("Photo")); |
|
508 field->SetMapping(KUidContactFieldVCardMapPHOTO); |
|
509 field->AddFieldTypeL(KUidContactFieldPicture); |
|
510 CContactStoreField* storeField = field->StoreStorage(); |
|
511 storeField->SetThingL(buf); |
|
512 aFieldSet.UpdateFieldL(*field, 1); |
|
513 |
|
514 CleanupStack::PopAndDestroy(2, &buf); |
|
515 } |
|
516 } |
|
517 } |
|
518 |
|
519 void CCmdContacts::PrintContact(CContactItem* aContact) |
|
520 { |
|
521 TContactItemId ContactId = aContact->Id(); |
|
522 TUid ContactType = aContact->Type(); |
|
523 CContactItemFieldSet& fields = aContact->CardFields(); |
|
524 |
|
525 TBool verbose = (iVerbose.Count() > 0); |
|
526 TBool veryverbose = (iVerbose.Count() > 1); |
|
527 |
|
528 if (verbose) |
|
529 { |
|
530 Printf(_L("Contact item id %d:\r\n"), aContact->Id()); |
|
531 Printf(_L("\tLast modified: ")); |
|
532 PrintTime(aContact->LastModified(), ETrue); |
|
533 if (veryverbose) |
|
534 { |
|
535 Printf(_L("\tHidden=%d System=%d AccessCount=%d Deleted=%d\r\n"), aContact->IsHidden(), aContact->IsSystem(), aContact->AccessCount(), aContact->IsDeleted()); |
|
536 TPtrC uid = aContact->UidStringL(iDb->MachineId()); // Don't understand the syntax of this function |
|
537 Printf(_L("\tUid: %S\r\n"), &uid); |
|
538 TUint32 type = aContact->Type().iUid; |
|
539 Printf(_L("\tType: 0x%08x "), type); |
|
540 switch (type) |
|
541 { |
|
542 case KUidContactCardValue: |
|
543 Printf(_L("(KUidContactCard)\r\n")); break; |
|
544 case KUidContactGroupValue: |
|
545 Printf(_L("(KUidContactGroup)\r\n")); break; |
|
546 case KUidContactOwnCardValue: |
|
547 Printf(_L("(KUidContactOwnCard)\r\n")); break; |
|
548 case KUidContactICCEntryValue: |
|
549 Printf(_L("(KUidContactICCEntry)\r\n")); break; |
|
550 case KUidContactTemplateValue: |
|
551 Printf(_L("(KUidContactTemplate)\r\n")); break; |
|
552 case KUidContactCardTemplateValue: |
|
553 Printf(_L("(KUidContactCardTemplate)\r\n")); break; |
|
554 default: |
|
555 Printf(_L("(Unknown)\r\n")); break; |
|
556 } |
|
557 } |
|
558 |
|
559 PrintGroupContentsL(aContact, iVerbose.Count()); |
|
560 PrintGroupsJoined(aContact, iVerbose.Count()); |
|
561 |
|
562 TInt num = fields.Count(); |
|
563 for (TInt i = 0; i < num; i++) |
|
564 { |
|
565 CContactItemField& field = fields[i]; |
|
566 TPtrC label = field.Label(); |
|
567 Printf(_L("\t%d [%S]: "), field.Id(), &label); |
|
568 switch (field.StorageType()) |
|
569 { |
|
570 case KStorageTypeText: |
|
571 { |
|
572 TPtrC fieldText = field.TextStorage()->Text(); |
|
573 Printf(_L("KStorageTypeText: %S\r\n"), &fieldText); |
|
574 break; |
|
575 } |
|
576 case KStorageTypeDateTime: |
|
577 { |
|
578 TTime time = field.DateTimeStorage()->Time(); |
|
579 PrintTime(time, ETrue); |
|
580 break; |
|
581 } |
|
582 case KStorageTypeStore: |
|
583 { |
|
584 HBufC8* thing = field.StoreStorage()->Thing(); |
|
585 if (thing) |
|
586 { |
|
587 Printf(_L("<Binary data of length %d>\r\n"), thing->Size()); |
|
588 } |
|
589 else |
|
590 { |
|
591 Printf(_L("<Null binary data>\r\n")); |
|
592 } |
|
593 break; |
|
594 } |
|
595 case KStorageTypeContactItemId: |
|
596 { |
|
597 Printf(_L("<Contact item id %d>\r\n"), field.AgentStorage()->Value()); |
|
598 break; |
|
599 } |
|
600 default: |
|
601 Printf(_L("<Unknown storage type>")); |
|
602 break; |
|
603 } |
|
604 if (veryverbose) |
|
605 { |
|
606 Printf(_L("\t\tDeleted=%d Disabled=%d Hidden=%d Private=%d Readonly=%d SpeedDial=%d\r\n"), field.IsDeleted(), field.IsDisabled(), field.IsHidden(), field.IsPrivate(), field.IsReadOnly(), field.IsSpeedDial()); |
|
607 Printf(_L("\t\tUser flags: 0x%08x\r\n"), field.UserFlags()); |
|
608 const CContentType& contentType = field.ContentType(); |
|
609 Printf(_L("\t\tVCard mapping: 0x%08x (%S)\r\n"), contentType.Mapping(), UidName(contentType.Mapping())); |
|
610 TInt fieldTypeCount = contentType.FieldTypeCount(); |
|
611 for (TInt i = 0; i < fieldTypeCount; i++) |
|
612 { |
|
613 TUid fieldType = contentType.FieldType(i); |
|
614 Printf(_L("\t\tField type %d: 0x%08x (%S)\r\n"), i, fieldType, UidName(fieldType)); |
|
615 } |
|
616 } |
|
617 } |
|
618 } |
|
619 else |
|
620 { |
|
621 TInt found; |
|
622 if (ContactType == KUidContactGroup) |
|
623 { |
|
624 TPtrC GroupName; |
|
625 found = fields.Find(KUidContactFieldTemplateLabel, KUidContactFieldNone); |
|
626 if (found != KErrNotFound) |
|
627 GroupName.Set( fields[found].TextStorage()->Text() ); |
|
628 else |
|
629 GroupName.Set(_L("[Unnamed]")); |
|
630 |
|
631 Printf(_L("%d. [Group] %S "), ContactId, &GroupName); |
|
632 |
|
633 //list containing items... |
|
634 PrintGroupContentsL(aContact, 0); |
|
635 } |
|
636 else |
|
637 { |
|
638 if (iShowFirstPhoneOnly) |
|
639 { |
|
640 found = fields.Find(KUidContactFieldPhoneNumber); |
|
641 if (found != KErrNotFound) |
|
642 { |
|
643 TPtrC phone = TPtrC(fields[found].TextStorage()->Text()); |
|
644 Printf(_L("%S"), &phone); |
|
645 } |
|
646 } |
|
647 else |
|
648 { |
|
649 TPtrC first; |
|
650 found = fields.Find(KUidContactFieldGivenName); |
|
651 if (found != KErrNotFound) first.Set(fields[found].TextStorage()->Text()); |
|
652 TPtrC last; |
|
653 found = fields.Find(KUidContactFieldFamilyName); |
|
654 if (found != KErrNotFound) last.Set(fields[found].TextStorage()->Text()); |
|
655 TPtrC phone; |
|
656 found = fields.Find(KUidContactFieldPhoneNumber); |
|
657 if (found != KErrNotFound) phone.Set(fields[found].TextStorage()->Text()); |
|
658 Printf(_L("%d. %S %S %S\r\n"), ContactId, &first, &last, &phone); |
|
659 } |
|
660 } |
|
661 |
|
662 } |
|
663 } |
|
664 |
|
665 //This function will not LEAVE for the moment |
|
666 //aVerboseLevel: possible values: 0 1 2 |
|
667 // |
|
668 void CCmdContacts::PrintGroupContentsL(CContactItem* aContactGroup, TInt /*aVerboseLevel*/) |
|
669 { |
|
670 if (aContactGroup->Type() == KUidContactGroup) |
|
671 { |
|
672 CContactGroup* pContactGroup = (CContactGroup*)aContactGroup; |
|
673 const CContactIdArray* pContactIdAry = pContactGroup->ItemsContained(); |
|
674 |
|
675 // |
|
676 TInt ElementCount = pContactIdAry->Count(); |
|
677 Printf(_L("\tThis Group contains %d items."), ElementCount); |
|
678 if (ElementCount) |
|
679 { |
|
680 Printf(_L(" Member contact ID list: ")); |
|
681 TInt i; |
|
682 for (i=0; i<ElementCount; i++) |
|
683 { |
|
684 TContactItemId ID = (*pContactIdAry) [i]; |
|
685 Printf(_L("%d "), ID); |
|
686 } |
|
687 } |
|
688 Printf(_L("\r\n")); |
|
689 |
|
690 } |
|
691 } |
|
692 |
|
693 void CCmdContacts::PrintGroupsJoined(CContactItem* aContact, TInt aVerboseLevel) |
|
694 { |
|
695 if (aVerboseLevel < 1) return; |
|
696 TUid ContactType = aContact->Type(); |
|
697 if (ContactType == KUidContactGroup || ContactType == KUidContactCard) |
|
698 { |
|
699 CContactItemPlusGroup * pContact = (CContactItemPlusGroup *)aContact; |
|
700 const CContactIdArray* pContactIdAry = pContact->GroupsJoined(); |
|
701 |
|
702 if (!pContactIdAry) |
|
703 return; |
|
704 |
|
705 TInt ElementCount = pContactIdAry->Count(); |
|
706 Printf(_L("\tThis item belongs to %d groups."), ElementCount); |
|
707 if (ElementCount) |
|
708 { |
|
709 Printf(_L(" Group contact ID list: ")); |
|
710 TInt i; |
|
711 for (i=0; i<ElementCount; i++) |
|
712 { |
|
713 TContactItemId ID = (*pContactIdAry) [i]; |
|
714 Printf(_L("%d "), ID); |
|
715 } |
|
716 } |
|
717 Printf(_L("\r\n")); |
|
718 } |
|
719 } |
|
720 |
|
721 void CCmdContacts::PrintTime(const TTime& aTime, TBool aNewline) |
|
722 { |
|
723 _LIT8(KDateTimeFormat, "%d-%02d-%02d %02d:%02d:%02d"); |
|
724 TDateTime dt = aTime.DateTime(); |
|
725 Printf(KDateTimeFormat, dt.Year(), dt.Month()+1, dt.Day()+1, dt.Hour(), dt.Minute(), dt.Second()); |
|
726 if (aNewline) Printf(_L("\r\n")); |
|
727 } |
|
728 |
|
729 //print the accepted options from the command line |
|
730 void CCmdContacts::PrintAcceptedOptions() |
|
731 { |
|
732 //surname |
|
733 if (iOptLastName && iOptLastName->Length()) |
|
734 Printf(_L("surname: %S \r\n"), iOptLastName ); |
|
735 //first name |
|
736 if (iOptFirstName && iOptFirstName->Length()) |
|
737 Printf(_L("first name: %S \r\n"), iOptFirstName ); |
|
738 //general telephone |
|
739 if (iOptTelephone && iOptTelephone->Length()) |
|
740 Printf(_L("general telephone: %S \r\n"), iOptTelephone ); |
|
741 //mobile phone |
|
742 if (iOptMobile && iOptMobile->Length()) |
|
743 Printf(_L("mobile: %S \r\n"), iOptMobile ); |
|
744 //photo |
|
745 if (iOptPhotoFileName.Length()) |
|
746 Printf(_L("photo: %S \r\n"), &iOptPhotoFileName ); |
|
747 } |
|
748 |
|
749 |
|
750 #define CASE_LIT(x) case x: { _LIT(KName, #x); return &KName; } |
|
751 const TDesC* CCmdContacts::UidName(TUid aUid) |
|
752 { |
|
753 switch (aUid.iUid) |
|
754 { |
|
755 CASE_LIT(KUidContactFieldAddressValue) |
|
756 CASE_LIT(KUidContactFieldPostOfficeValue) |
|
757 CASE_LIT(KUidContactFieldExtendedAddressValue) |
|
758 CASE_LIT(KUidContactFieldLocalityValue) |
|
759 CASE_LIT(KUidContactFieldRegionValue) |
|
760 CASE_LIT(KUidContactFieldPostCodeValue) |
|
761 CASE_LIT(KUidContactFieldCountryValue) |
|
762 CASE_LIT(KUidContactFieldCompanyNameValue) |
|
763 CASE_LIT(KUidContactFieldCompanyNamePronunciationValue) |
|
764 CASE_LIT(KUidContactFieldPhoneNumberValue) |
|
765 CASE_LIT(KUidContactFieldGivenNameValue) |
|
766 CASE_LIT(KUidContactFieldFamilyNameValue) |
|
767 CASE_LIT(KUidContactFieldGivenNamePronunciationValue) |
|
768 CASE_LIT(KUidContactFieldFamilyNamePronunciationValue) |
|
769 CASE_LIT(KUidContactFieldAdditionalNameValue) |
|
770 CASE_LIT(KUidContactFieldSuffixNameValue) |
|
771 CASE_LIT(KUidContactFieldPrefixNameValue) |
|
772 CASE_LIT(KUidContactFieldHiddenValue) |
|
773 CASE_LIT(KUidContactFieldEMailValue) |
|
774 CASE_LIT(KUidContactFieldMsgValue) |
|
775 CASE_LIT(KUidContactFieldSmsValue) |
|
776 CASE_LIT(KUidContactFieldFaxValue) |
|
777 CASE_LIT(KUidContactFieldDefinedTextValue) |
|
778 CASE_LIT(KUidContactFieldNoteValue) |
|
779 CASE_LIT(KUidContactFieldBirthdayValue) |
|
780 CASE_LIT(KUidContactFieldUrlValue) |
|
781 CASE_LIT(KUidContactFieldStorageInlineValue) |
|
782 CASE_LIT(KUidContactFieldTemplateLabelValue) |
|
783 CASE_LIT(KUidContactFieldPictureValue) |
|
784 CASE_LIT(KUidContactFieldRingToneValue) |
|
785 CASE_LIT(KUidContactFieldDTMFValue) |
|
786 CASE_LIT(KUidContactsVoiceDialFieldValue) |
|
787 CASE_LIT(KUidContactFieldNoneValue) |
|
788 CASE_LIT(KUidContactFieldJobTitleValue) |
|
789 CASE_LIT(KUidContactFieldICCSlotValue) |
|
790 CASE_LIT(KUidContactFieldICCPhonebookValue) |
|
791 CASE_LIT(KUidContactFieldICCGroupValue) |
|
792 CASE_LIT(KUidContactFieldIMAddressValue) |
|
793 CASE_LIT(KUidContactFieldSecondNameValue) |
|
794 CASE_LIT(KUidContactFieldSIPIDValue) |
|
795 CASE_LIT(KUidContactFieldAssistantValue) |
|
796 CASE_LIT(KUidContactFieldAnniversaryValue) |
|
797 CASE_LIT(KUidContactFieldSpouseValue) |
|
798 CASE_LIT(KUidContactFieldChildrenValue) |
|
799 CASE_LIT(KUidContactFieldClassValue) |
|
800 CASE_LIT(KUidContactFieldDepartmentNameValue) |
|
801 CASE_LIT(KIntContactFieldVCardMapWORK) |
|
802 CASE_LIT(KIntContactFieldVCardMapHOME) |
|
803 CASE_LIT(KIntContactFieldVCardMapMSG) |
|
804 CASE_LIT(KIntContactFieldVCardMapVOICE) |
|
805 CASE_LIT(KIntContactFieldVCardMapFAX) |
|
806 CASE_LIT(KIntContactFieldVCardMapPREF) |
|
807 CASE_LIT(KIntContactFieldVCardMapCELL) |
|
808 CASE_LIT(KIntContactFieldVCardMapPAGER) |
|
809 CASE_LIT(KIntContactFieldVCardMapBBS) |
|
810 CASE_LIT(KIntContactFieldVCardMapMODEM) |
|
811 CASE_LIT(KIntContactFieldVCardMapCAR) |
|
812 CASE_LIT(KIntContactFieldVCardMapISDN) |
|
813 CASE_LIT(KIntContactFieldVCardMapVIDEO) |
|
814 CASE_LIT(KIntContactFieldVCardMapDOM) |
|
815 CASE_LIT(KIntContactFieldVCardMapADR) |
|
816 CASE_LIT(KIntContactFieldVCardMapPOSTOFFICE) |
|
817 CASE_LIT(KIntContactFieldVCardMapEXTENDEDADR) |
|
818 CASE_LIT(KIntContactFieldVCardMapLOCALITY) |
|
819 CASE_LIT(KIntContactFieldVCardMapREGION) |
|
820 CASE_LIT(KIntContactFieldVCardMapPOSTCODE) |
|
821 CASE_LIT(KIntContactFieldVCardMapCOUNTRY) |
|
822 CASE_LIT(KIntContactFieldVCardMapAGENT) |
|
823 CASE_LIT(KIntContactFieldVCardMapBDAY) |
|
824 CASE_LIT(KIntContactFieldVCardMapEMAILINTERNET) |
|
825 CASE_LIT(KIntContactFieldVCardMapGEO) |
|
826 CASE_LIT(KIntContactFieldVCardMapLABEL) |
|
827 CASE_LIT(KIntContactFieldVCardMapLOGO) |
|
828 CASE_LIT(KIntContactFieldVCardMapMAILER) |
|
829 CASE_LIT(KIntContactFieldVCardMapNOTE) |
|
830 CASE_LIT(KIntContactFieldVCardMapORG) |
|
831 CASE_LIT(KIntContactFieldVCardMapORGPronunciation) |
|
832 CASE_LIT(KIntContactFieldVCardMapPHOTO) |
|
833 CASE_LIT(KIntContactFieldVCardMapROLE) |
|
834 CASE_LIT(KIntContactFieldVCardMapSOUND) |
|
835 CASE_LIT(KIntContactFieldVCardMapTEL) |
|
836 CASE_LIT(KIntContactFieldVCardMapTELFAX) |
|
837 CASE_LIT(KIntContactFieldVCardMapTITLE) |
|
838 CASE_LIT(KIntContactFieldVCardMapURL) |
|
839 CASE_LIT(KIntContactFieldVCardMapUnusedN) |
|
840 CASE_LIT(KIntContactFieldVCardMapUnusedFN) |
|
841 CASE_LIT(KIntContactFieldVCardMapNotRequired) |
|
842 CASE_LIT(KIntContactFieldVCardMapUnknownXDash) |
|
843 CASE_LIT(KIntContactFieldVCardMapUnknown) |
|
844 CASE_LIT(KIntContactFieldVCardMapUID) |
|
845 CASE_LIT(KIntContactFieldVCardMapINTL) |
|
846 CASE_LIT(KIntContactFieldVCardMapPOSTAL) |
|
847 CASE_LIT(KIntContactFieldVCardMapPARCEL) |
|
848 CASE_LIT(KIntContactFieldVCardMapGIF) |
|
849 CASE_LIT(KIntContactFieldVCardMapCGM) |
|
850 CASE_LIT(KIntContactFieldVCardMapWMF) |
|
851 CASE_LIT(KIntContactFieldVCardMapBMP) |
|
852 CASE_LIT(KIntContactFieldVCardMapMET) |
|
853 CASE_LIT(KIntContactFieldVCardMapPMB) |
|
854 CASE_LIT(KIntContactFieldVCardMapDIB) |
|
855 CASE_LIT(KIntContactFieldVCardMapPICT) |
|
856 CASE_LIT(KIntContactFieldVCardMapTIFF) |
|
857 CASE_LIT(KIntContactFieldVCardMapPDF) |
|
858 CASE_LIT(KIntContactFieldVCardMapPS) |
|
859 CASE_LIT(KIntContactFieldVCardMapJPEG) |
|
860 CASE_LIT(KIntContactFieldVCardMapMPEG) |
|
861 CASE_LIT(KIntContactFieldVCardMapMPEG2) |
|
862 CASE_LIT(KIntContactFieldVCardMapAVI) |
|
863 CASE_LIT(KIntContactFieldVCardMapQTIME) |
|
864 CASE_LIT(KIntContactFieldVCardMapTZ) |
|
865 CASE_LIT(KIntContactFieldVCardMapKEY) |
|
866 CASE_LIT(KIntContactFieldVCardMapX509) |
|
867 CASE_LIT(KIntContactFieldVCardMapPGP) |
|
868 CASE_LIT(KIntContactFieldVCardMapSMIME) |
|
869 CASE_LIT(KIntContactFieldVCardMapWV) |
|
870 CASE_LIT(KIntContactFieldVCardMapSECONDNAME) |
|
871 CASE_LIT(KIntContactFieldVCardMapSIPID) |
|
872 CASE_LIT(KIntContactFieldVCardMapPOC) |
|
873 CASE_LIT(KIntContactFieldVCardMapSWIS) |
|
874 CASE_LIT(KIntContactFieldVCardMapVOIP) |
|
875 CASE_LIT(KIntContactFieldVCardMapAssistant) |
|
876 CASE_LIT(KIntContactFieldVCardMapAssistantTel) |
|
877 CASE_LIT(KIntContactFieldVCardMapAnniversary) |
|
878 CASE_LIT(KIntContactFieldVCardMapSpouse) |
|
879 CASE_LIT(KIntContactFieldVCardMapChildren) |
|
880 CASE_LIT(KIntContactFieldVCardMapClass) |
|
881 CASE_LIT(KIntContactFieldVCardMapDepartment) |
|
882 default: |
|
883 { |
|
884 _LIT(KUnknown, "Unknown"); |
|
885 return &KUnknown; |
|
886 } |
|
887 } |
|
888 } |
|
889 |
|
890 EXE_BOILER_PLATE(CCmdContacts) |
|
891 |