author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 27 Aug 2009 07:43:07 +0300 | |
changeset 22 | fc9cf246af83 |
parent 19 | 989d2f495d90 |
child 33 | 50974a8b132e |
permissions | -rw-r--r-- |
19 | 1 |
/* |
2 |
* Copyright (c) 2002 - 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 the License "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: ?Description |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
||
20 |
||
21 |
// INCLUDE FILES |
|
22 |
#include <e32svr.h> |
|
23 |
#include <StifParser.h> |
|
24 |
#include <Stiftestinterface.h> |
|
25 |
#include <VPbkEng.rsg> |
|
26 |
||
27 |
#include <MVPbkContactFieldTextData.h> |
|
28 |
#include <MVPbkContactStoreList.h> |
|
29 |
#include <MVPbkContactOperationBase.h> |
|
30 |
#include <MVPbkContactLink.h> |
|
31 |
#include <CVPbkContactLinkArray.h> |
|
32 |
#include <MVPbkContactGroup.h> |
|
33 |
#include <utf.h> |
|
34 |
||
35 |
#include "tcontacts_sync.h" |
|
36 |
#include "singlecontact.h" |
|
37 |
||
38 |
// CONSTANTS |
|
39 |
_LIT(KError,"Error code is"); |
|
40 |
_LIT(KSuccess,"Successful"); |
|
41 |
_LIT(KNewLine,"\n"); |
|
42 |
_LIT(KServiceOpen,"Service handle created"); |
|
43 |
_LIT(KServiceClose,"Service handle deleted"); |
|
44 |
_LIT(KPhoneNumber,"9886431364"); |
|
45 |
_LIT(KGroup1,"Test1"); |
|
46 |
// ============================ MEMBER FUNCTIONS =============================== |
|
47 |
||
48 |
// ----------------------------------------------------------------------------- |
|
49 |
// CContactsUT::Delete |
|
50 |
// Delete here all resources allocated and opened from test methods. |
|
51 |
// Called from destructor. |
|
52 |
// ----------------------------------------------------------------------------- |
|
53 |
// |
|
54 |
void CContactsUT::Delete() |
|
55 |
{ |
|
56 |
||
57 |
} |
|
58 |
||
59 |
// ----------------------------------------------------------------------------- |
|
60 |
// CContactsUT::RunMethodL |
|
61 |
// Run specified method. Contains also table of test mothods and their names. |
|
62 |
// ----------------------------------------------------------------------------- |
|
63 |
// |
|
64 |
TInt CContactsUT::RunMethodL( |
|
65 |
CStifItemParser& aItem ) |
|
66 |
{ |
|
67 |
||
68 |
static TStifFunctionInfo const KFunctions[] = |
|
69 |
{ |
|
70 |
ENTRY( "Add_contact_sapi", CContactsUT::AddContactSAPIL ), |
|
71 |
ENTRY( "Delete_contact_sapi", CContactsUT::DeleteContactSAPIL ), |
|
72 |
ENTRY( "Modify_contact_sapi", CContactsUT::ModifyContactSAPIL ), |
|
73 |
ENTRY( "Import_contact_sapi", CContactsUT::ImportContactSAPIL ), |
|
74 |
ENTRY( "Export_contact_sapi", CContactsUT::ExportContactSAPIL ), |
|
75 |
ENTRY( "Getlist_delete_contact", CContactsUT::GetListDeleteContactL ), |
|
76 |
ENTRY( "Add_getlist_contact", CContactsUT::AddContactGetListL ), |
|
77 |
ENTRY( "Get_group", CContactsUT::GetGroupsL ), |
|
78 |
ENTRY( "Get_contact", CContactsUT::GetContactsL ), |
|
79 |
ENTRY( "Get_database", CContactsUT::GetDatabaseL ), |
|
80 |
ENTRY( "Add_contact", CContactsUT::AddL ), |
|
81 |
ENTRY( "Add_group", CContactsUT::AddGroupL ), |
|
82 |
ENTRY( "Modify_contact", CContactsUT::ModifyL ), |
|
83 |
ENTRY( "Modify_group", CContactsUT::ModifyGroupL ), |
|
84 |
ENTRY( "Delete_contact", CContactsUT::DeleteContactL ), |
|
85 |
ENTRY( "Delete_group", CContactsUT::DeleteGroupL ), |
|
86 |
ENTRY( "Organise_add", CContactsUT::OrganiseAddL ), |
|
87 |
ENTRY( "Organise_delete", CContactsUT::OrganiseDeleteL ), |
|
88 |
ENTRY( "Import", CContactsUT::ImportL ), |
|
89 |
ENTRY( "Export", CContactsUT::ExportL ), |
|
90 |
}; |
|
91 |
||
92 |
const TInt count = sizeof( KFunctions ) / |
|
93 |
sizeof( TStifFunctionInfo ); |
|
94 |
||
95 |
return RunInternalL( KFunctions, count, aItem ); |
|
96 |
||
97 |
} |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
98 |
void CContactsUT::HandleReturnArray(const TInt& aError, RPointerArray<HBufC8>& aArray, TInt aTransId ) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
99 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
100 |
CActiveScheduler::Stop(); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
101 |
} |
19 | 102 |
|
22
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
103 |
void CContactsUT::HandleReturnId( const TInt& aError, HBufC8* acntId, TInt aTransId ) |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
104 |
{ |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
105 |
CActiveScheduler::Stop(); |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
106 |
} |
fc9cf246af83
Revision: 200931
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
107 |
|
19 | 108 |
|
109 |
void CContactsUT::HandleReturnValue( TOperationEvent /*aEvent*/, const TInt& aError, TInt /*aTransId*/ ) |
|
110 |
{ |
|
111 |
CActiveScheduler::Stop(); |
|
112 |
_LIT(KFunc,"In Handle Return Value\n"); |
|
113 |
iLog->Log(KFunc); |
|
114 |
iErr = aError; |
|
115 |
TBuf<5> buf; |
|
116 |
buf.Num(aError); |
|
117 |
iLog->Log(KError); |
|
118 |
iLog->Log(buf); |
|
119 |
iLog->Log(KNewLine); |
|
120 |
} |
|
121 |
||
122 |
void CContactsUT::HandleReturnIter( const TInt& aError, CContactIter* aIter, TInt /*aTransId*/ ) |
|
123 |
{ |
|
124 |
CActiveScheduler::Stop(); |
|
125 |
_LIT(KFunc,"In Handle Return Iter\n"); |
|
126 |
iLog->Log(KFunc); |
|
127 |
iErr = aError; |
|
128 |
TBuf<5> buf; |
|
129 |
buf.Num(aError); |
|
130 |
iLog->Log(KError); |
|
131 |
iLog->Log(buf); |
|
132 |
iLog->Log(KNewLine); |
|
133 |
||
134 |
HBufC8* idBuf = NULL; |
|
135 |
_LIT8(KNumber,"MobilePhoneGen"); |
|
136 |
while(ETrue) |
|
137 |
{ |
|
138 |
aIter->NextL(iSingleContact,idBuf); |
|
139 |
if(!iSingleContact) |
|
140 |
{ |
|
141 |
break; |
|
142 |
} |
|
143 |
CleanupStack::PushL(idBuf); |
|
144 |
||
145 |
||
146 |
TInt count(iSingleContact->FieldCount()); |
|
147 |
CSingleContactField* field = NULL; |
|
148 |
while(count) |
|
149 |
{ |
|
150 |
TPtrC8 fieldKey; |
|
151 |
TPtrC label; |
|
152 |
TPtrC value; |
|
153 |
field = iSingleContact->FieldAt(--count); |
|
154 |
field->GetFieldDataL(fieldKey,label,value); |
|
155 |
if(!(fieldKey.Compare(KNumber)) && !(value.Compare(KPhoneNumber))) |
|
156 |
{ |
|
157 |
CleanupStack::Pop(idBuf); |
|
158 |
delete aIter; |
|
159 |
return; //NOTE |
|
160 |
} |
|
161 |
||
162 |
} |
|
163 |
CleanupStack::PopAndDestroy(idBuf); |
|
164 |
delete iSingleContact; |
|
165 |
iSingleContact = NULL; |
|
166 |
} |
|
167 |
delete aIter; |
|
168 |
} |
|
169 |
/* |
|
170 |
if(EGetContactDelete == iOperation ) |
|
171 |
{ |
|
172 |
iOperation = ENone; |
|
173 |
CSingleContact* singleContact = NULL; |
|
174 |
HBufC8* buf = NULL; |
|
175 |
TInt count = 0; |
|
176 |
while(ETrue) |
|
177 |
{ |
|
178 |
aIter->NextL(singleContact,buf); |
|
179 |
if(!singleContact) |
|
180 |
{ |
|
181 |
break; |
|
182 |
} |
|
183 |
iBuffer = buf; |
|
184 |
// delete buf; |
|
185 |
delete singleContact; |
|
186 |
break; |
|
187 |
} |
|
188 |
} |
|
189 |
if(iOperation == EContact) |
|
190 |
{ |
|
191 |
iOperation = ENone; |
|
192 |
||
193 |
CSingleContact* singleContact = NULL; |
|
194 |
HBufC8* buf = NULL; |
|
195 |
||
196 |
_LIT(KPhone,"560087"); |
|
197 |
_LIT8(KField,"MobilePhoneGen"); |
|
198 |
||
199 |
while(ETrue) |
|
200 |
{ |
|
201 |
aIter->NextL(singleContact,buf); |
|
202 |
CleanupStack::PushL(singleContact); |
|
203 |
CleanupStack::PushL(buf); |
|
204 |
if(!singleContact) |
|
205 |
{ |
|
206 |
break; |
|
207 |
} |
|
208 |
||
209 |
||
210 |
if(!buf->Compare(*iBuffer)) |
|
211 |
{ |
|
212 |
TInt count(singleContact->FieldCount()); |
|
213 |
CSingleContactField* field = NULL; |
|
214 |
while(count) |
|
215 |
{ |
|
216 |
TBuf8<50> fieldKey; |
|
217 |
TBuf<50> label; |
|
218 |
TBuf<50> value; |
|
219 |
field = singleContact->FieldAt(--count); |
|
220 |
field->GetFieldDataL(fieldKey,label,value); |
|
221 |
if(!fieldKey.Compare(KField)) |
|
222 |
{ |
|
223 |
field->SetFieldParamsL(KField,KNullDesC,KPhone); |
|
224 |
iLog->Log(_L("Phone Contact Field modified \n")); |
|
225 |
iServiceHandle->AddL(this,0,singleContact); |
|
226 |
iLog->Log(_L("AddL called\n")); |
|
227 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
228 |
CActiveScheduler::Start(); |
|
229 |
break; |
|
230 |
} |
|
231 |
} |
|
232 |
} |
|
233 |
||
234 |
CleanupStack::PopAndDestroy(buf); |
|
235 |
CleanupStack::PopAndDestroy(singleContact); |
|
236 |
} |
|
237 |
} |
|
238 |
if(EGetContact == iOperation ) |
|
239 |
{ |
|
240 |
iOperation = ENone; |
|
241 |
//iErr = KErrGeneral; |
|
242 |
_LIT8(KFirstName,"FirstName"); |
|
243 |
_LIT(KName,"Kats"); |
|
244 |
CSingleContact* singleContact = NULL; |
|
245 |
HBufC8* buf = NULL; |
|
246 |
TInt count = 0; |
|
247 |
while(ETrue) |
|
248 |
{ |
|
249 |
aIter->NextL(singleContact,buf); |
|
250 |
if(!singleContact) |
|
251 |
{ |
|
252 |
break; |
|
253 |
} |
|
254 |
++count; |
|
255 |
TInt count(singleContact->FieldCount()); |
|
256 |
while(count) |
|
257 |
{ |
|
258 |
CSingleContactField* field = singleContact->FieldAt(--count); |
|
259 |
TBuf8<256> fieldKey; |
|
260 |
TBuf<256> label; |
|
261 |
TBuf<256> value; |
|
262 |
field->GetFieldDataL(fieldKey,label,value); |
|
263 |
if (fieldKey == KFirstName && value == KName) |
|
264 |
{ |
|
265 |
iErr = KErrNone; |
|
266 |
} |
|
267 |
// delete field; |
|
268 |
} |
|
269 |
delete singleContact; |
|
270 |
} |
|
271 |
} |
|
272 |
||
273 |
if(EGetGroup == iOperation ) |
|
274 |
{ |
|
275 |
iOperation = ENone; |
|
276 |
CSingleContact* singleContact = NULL; |
|
277 |
HBufC8* buf = NULL; |
|
278 |
TInt count = 0; |
|
279 |
while(ETrue) |
|
280 |
{ |
|
281 |
aIter->NextL(singleContact,buf); |
|
282 |
iBuffer = buf; |
|
283 |
if(!singleContact) |
|
284 |
{ |
|
285 |
break; |
|
286 |
} |
|
287 |
++count; |
|
288 |
TInt fields(singleContact->FieldCount()); |
|
289 |
while(fields) |
|
290 |
{ |
|
291 |
CSingleContactField* field = singleContact->FieldAt(--fields); |
|
292 |
TBuf<256> groupId; |
|
293 |
RPointerArray<HBufC8> array; |
|
294 |
field->GetFieldDataL(groupId,array); |
|
295 |
TInt contacts(array.Count()); |
|
296 |
//array->Reset(); |
|
297 |
} |
|
298 |
||
299 |
} |
|
300 |
} |
|
301 |
delete aIter; |
|
302 |
}*/ |
|
303 |
||
304 |
void CContactsUT::HandleRetrieveContact( MVPbkStoreContact* /*aStoreContact*/, TInt /*aTransId*/ ) |
|
305 |
{ |
|
306 |
CActiveScheduler::Stop(); |
|
307 |
_LIT(KFunc,"In Handle Retrieve Contact\n"); |
|
308 |
iLog->Log(KFunc); |
|
309 |
} |
|
310 |
||
311 |
void CContactsUT::ContactOperationCompleted(TContactOpResult aResult) |
|
312 |
{ |
|
313 |
CActiveScheduler::Stop(); |
|
314 |
_LIT(KFunc,"In ContactOperationCompleted \n"); |
|
315 |
iLog->Log(KFunc); |
|
316 |
iErr = KErrNone; |
|
317 |
TBuf<5> buf; |
|
318 |
buf.Num(aResult.iOpCode); |
|
319 |
iLog->Log(KSuccess); |
|
320 |
iLog->Log(buf); |
|
321 |
iLog->Log(KNewLine); |
|
322 |
switch(iOperation) |
|
323 |
{/* |
|
324 |
case EContact: delete iStoreContact; |
|
325 |
iStoreContact = NULL; |
|
326 |
break;*/ |
|
327 |
case EGroup: delete iGroup; |
|
328 |
iGroup = NULL; |
|
329 |
break; |
|
330 |
} |
|
331 |
iOperation = ENone; |
|
332 |
} |
|
333 |
void CContactsUT::ContactOperationFailed |
|
334 |
(TContactOp /*aOpCode*/, TInt aErrorCode, TBool /*aErrorNotified*/) |
|
335 |
{ |
|
336 |
CActiveScheduler::Stop(); |
|
337 |
_LIT(KFunc,"In ContactOperationFailed \n"); |
|
338 |
iLog->Log(KFunc); |
|
339 |
iErr = aErrorCode; |
|
340 |
TBuf<5> buf; |
|
341 |
buf.Num(aErrorCode); |
|
342 |
iLog->Log(KError); |
|
343 |
iLog->Log(buf); |
|
344 |
iLog->Log(KNewLine); |
|
345 |
switch(iOperation) |
|
346 |
{ |
|
347 |
case EContact:/* delete iStoreContact; |
|
348 |
iStoreContact = NULL; |
|
349 |
break;*/ |
|
350 |
case EGroup: delete iGroup; |
|
351 |
iGroup = NULL; |
|
352 |
break; |
|
353 |
} |
|
354 |
iOperation = ENone; |
|
355 |
} |
|
356 |
||
357 |
void CContactsUT::FindCompleteL( MVPbkContactLinkArray* aResults ) |
|
358 |
{ |
|
359 |
CActiveScheduler::Stop(); |
|
360 |
_LIT(KFunc,"In FindCompleteL \n"); |
|
361 |
iLog->Log(KFunc); |
|
362 |
iErr = KErrNone; |
|
363 |
iFindResults = aResults; |
|
364 |
iLog->Log(KSuccess); |
|
365 |
} |
|
366 |
void CContactsUT::FindFailed( TInt aError ) |
|
367 |
{ |
|
368 |
CActiveScheduler::Stop(); |
|
369 |
_LIT(KFunc,"In FindFailed \n"); |
|
370 |
iLog->Log(KFunc); |
|
371 |
iErr = aError; |
|
372 |
TBuf<5> buf; |
|
373 |
buf.Num(aError); |
|
374 |
iLog->Log(KError); |
|
375 |
iLog->Log(buf); |
|
376 |
iLog->Log(KNewLine); |
|
377 |
} |
|
378 |
||
379 |
void CContactsUT::VPbkSingleContactOperationComplete( |
|
380 |
MVPbkContactOperationBase& aOperation, |
|
381 |
MVPbkStoreContact* aContact ) |
|
382 |
{ |
|
383 |
CActiveScheduler::Stop(); |
|
384 |
_LIT(KFunc,"In VPbkSingleContactOperationComplete \n"); |
|
385 |
iLog->Log(KFunc); |
|
386 |
iErr = KErrNone; |
|
387 |
||
388 |
if(iOperation == EVCard) |
|
389 |
{ |
|
390 |
iDestStream.CommitL(); |
|
391 |
delete iOp; |
|
392 |
iOp = NULL; |
|
393 |
iDestStream.Close(); |
|
394 |
delete iResult; |
|
395 |
iResult = NULL; |
|
396 |
} |
|
397 |
else if(iOperation == EVCardEx) |
|
398 |
{ |
|
399 |
delete iOp; |
|
400 |
iOp = NULL; |
|
401 |
} |
|
402 |
else |
|
403 |
{ |
|
404 |
delete iStoreContact; |
|
405 |
iStoreContact = NULL; |
|
406 |
iStoreContact = aContact; |
|
407 |
if( iOp == &aOperation ) |
|
408 |
{ |
|
409 |
delete iOp; |
|
410 |
iOp = NULL; |
|
411 |
} |
|
412 |
} |
|
413 |
iOperation = ENone; |
|
414 |
iLog->Log(KSuccess); |
|
415 |
} |
|
416 |
||
417 |
||
418 |
void CContactsUT::VPbkSingleContactOperationFailed( |
|
419 |
MVPbkContactOperationBase& aOperation, |
|
420 |
TInt aError ) |
|
421 |
{ |
|
422 |
CActiveScheduler::Stop(); |
|
423 |
_LIT(KFunc,"In VPbkSingleContactOperationFailed \n"); |
|
424 |
iLog->Log(KFunc); |
|
425 |
iErr = aError; |
|
426 |
; |
|
427 |
if(iOperation == EVCard) |
|
428 |
{ |
|
429 |
iDestStream.CommitL(); |
|
430 |
delete iOp; |
|
431 |
iOp = NULL; |
|
432 |
iDestStream.Close(); |
|
433 |
delete iBuffer; |
|
434 |
iBuffer = NULL; |
|
435 |
delete iResult; |
|
436 |
iResult = NULL; |
|
437 |
} |
|
438 |
else if(iOperation == EVCardEx) |
|
439 |
{ |
|
440 |
delete iOp; |
|
441 |
iOp = NULL; |
|
442 |
} |
|
443 |
else |
|
444 |
{ |
|
445 |
delete iStoreContact; |
|
446 |
iStoreContact = NULL; |
|
447 |
if( iOp == &aOperation ) |
|
448 |
{ |
|
449 |
delete iOp; |
|
450 |
iOp = NULL; |
|
451 |
} |
|
452 |
} |
|
453 |
TBuf<5> buf; |
|
454 |
buf.Num(aError); |
|
455 |
iLog->Log(KError); |
|
456 |
iLog->Log(buf); |
|
457 |
iLog->Log(KNewLine); |
|
458 |
||
459 |
iOperation = ENone; |
|
460 |
} |
|
461 |
||
462 |
void CContactsUT::StepComplete( |
|
463 |
MVPbkContactOperationBase& /*aOperation*/, |
|
464 |
TInt /*aStepSize*/ ) |
|
465 |
{ |
|
466 |
_LIT(KFunc,"In StepComplete \n"); |
|
467 |
iLog->Log(KFunc); |
|
468 |
iLog->Log(KSuccess); |
|
469 |
iLog->Log(KNewLine); |
|
470 |
} |
|
471 |
||
472 |
TBool CContactsUT::StepFailed( |
|
473 |
MVPbkContactOperationBase& /*aOperation*/, |
|
474 |
TInt /*aStepSize*/, TInt /*aError*/ ) |
|
475 |
{ |
|
476 |
_LIT(KFunc,"In StepFailed \n"); |
|
477 |
iLog->Log(KFunc); |
|
478 |
return EFalse; |
|
479 |
} |
|
480 |
||
481 |
void CContactsUT::OperationComplete( |
|
482 |
MVPbkContactOperationBase& /*aOperation*/ ) |
|
483 |
{ |
|
484 |
CActiveScheduler::Stop(); |
|
485 |
_LIT(KFunc,"In OperationComplete \n"); |
|
486 |
iLog->Log(KFunc); |
|
487 |
iErr = KErrNone; |
|
488 |
iLog->Log(KSuccess); |
|
489 |
iLog->Log(KNewLine); |
|
490 |
} |
|
491 |
||
492 |
||
493 |
//Delete all contacts |
|
494 |
void CContactsUT::DeleteAllL() |
|
495 |
{ |
|
496 |
// Print to UI |
|
497 |
_LIT( KContactsTest, "ContactsUT" ); |
|
498 |
_LIT( KExample, "In DeleteAllL" ); |
|
499 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
500 |
// Print to log file |
|
501 |
iLog->Log( KExample ); |
|
502 |
||
503 |
iErr = KErrNone; |
|
504 |
||
505 |
__UHEAP_MARK; |
|
506 |
iOp = iContactManager->MatchPhoneNumberL( |
|
507 |
KPhoneNumber, KPhoneNumber().Length(), *this ); |
|
508 |
CActiveScheduler::Start(); |
|
509 |
delete iOp; |
|
510 |
iOp = NULL; |
|
511 |
||
512 |
TInt count(iFindResults->Count()); |
|
513 |
iContactToDelete = CVPbkContactLinkArray::NewLC(); |
|
514 |
while(count) |
|
515 |
{ |
|
516 |
MVPbkContactLink* link = iFindResults->At(--count).CloneLC(); |
|
517 |
iContactToDelete->AppendL(link); |
|
518 |
CleanupStack::Pop(); |
|
519 |
} |
|
520 |
delete iFindResults; |
|
521 |
iFindResults = NULL; |
|
522 |
||
523 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
524 |
CActiveScheduler::Start(); |
|
525 |
delete iOp; |
|
526 |
iOp = NULL; |
|
527 |
CleanupStack::PopAndDestroy(iContactToDelete); |
|
528 |
iContactToDelete = NULL; |
|
529 |
||
530 |
||
531 |
__UHEAP_MARKEND; |
|
532 |
} |
|
533 |
||
534 |
//Add 1 contact |
|
535 |
void CContactsUT::AddOneContactL(TDesC& aName) |
|
536 |
{ |
|
537 |
// Print to UI |
|
538 |
_LIT( KContactsTest, "ContactsUT" ); |
|
539 |
_LIT( KExample, "In AddOneContactL" ); |
|
540 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
541 |
// Print to log file |
|
542 |
iLog->Log( KExample ); |
|
543 |
||
544 |
iErr = KErrNone; |
|
545 |
||
546 |
__UHEAP_MARK; |
|
547 |
CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
548 |
CleanupStack::PushL(fieldTypeRefList); |
|
549 |
||
550 |
fieldTypeRefList->AppendL( |
|
551 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
552 |
fieldTypeRefList->AppendL( |
|
553 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
554 |
||
555 |
// Create first contact |
|
556 |
iStoreContact = iStore->CreateNewContactLC(); |
|
557 |
||
558 |
// Create contact field for contact |
|
559 |
MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
560 |
// Set contact field data |
|
561 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( aName ); |
|
562 |
// Add the contact field to contact |
|
563 |
iStoreContact->AddFieldL( field ); |
|
564 |
CleanupStack::Pop(); // field |
|
565 |
||
566 |
// Create contact field for contact |
|
567 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
568 |
// Set contact field data |
|
569 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KPhoneNumber ); |
|
570 |
// Add the contact field to contact |
|
571 |
iStoreContact->AddFieldL( field ); |
|
572 |
CleanupStack::Pop(); // field |
|
573 |
||
574 |
// Commit the new created contact to contact store |
|
575 |
iStoreContact->CommitL( *this ); |
|
576 |
CActiveScheduler::Start(); |
|
577 |
CleanupStack::PopAndDestroy(); // iStoreContact |
|
578 |
iStoreContact = NULL; |
|
579 |
CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
580 |
__UHEAP_MARKEND; |
|
581 |
} |
|
582 |
||
583 |
//Check for contact |
|
584 |
void CContactsUT::CheckContactsL(TInt& aCount,RPointerArray<TDesC8>& aIdArray) |
|
585 |
{ |
|
586 |
// Print to UI |
|
587 |
_LIT( KContactsTest, "ContactsUT" ); |
|
588 |
_LIT( KExample, "In CheckContactsL" ); |
|
589 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
590 |
// Print to log file |
|
591 |
iLog->Log( KExample ); |
|
592 |
||
593 |
iErr = KErrNone; |
|
594 |
||
595 |
//__UHEAP_MARK; |
|
596 |
iOp = iContactManager->MatchPhoneNumberL( |
|
597 |
KPhoneNumber, KPhoneNumber().Length(), *this ); |
|
598 |
CActiveScheduler::Start(); |
|
599 |
delete iOp; |
|
600 |
iOp = NULL; |
|
601 |
||
602 |
aCount = iFindResults->Count(); |
|
603 |
TInt count(aCount); |
|
604 |
while(count) |
|
605 |
{ |
|
606 |
aIdArray.AppendL((const_cast<MVPbkContactLink&>(iFindResults->At(--count))).PackLC()); |
|
607 |
CleanupStack::Pop(); |
|
608 |
} |
|
609 |
delete iFindResults; |
|
610 |
iFindResults = NULL; |
|
611 |
// __UHEAP_MARKENDC(aCount); |
|
612 |
} |
|
613 |
||
614 |
// ----------------------------------------------------------------------------- |
|
615 |
// CContactsUT::?member_function |
|
616 |
// ?implementation_description |
|
617 |
// (other items were commented in a header). |
|
618 |
// ----------------------------------------------------------------------------- |
|
619 |
// |
|
620 |
TInt CContactsUT::AddContactSAPIL( CStifItemParser& aItem ) |
|
621 |
{ |
|
622 |
// Print to UI |
|
623 |
_LIT( KContactsTest, "ContactsUT" ); |
|
624 |
_LIT( KExample, "In AddContactSAPIL" ); |
|
625 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
626 |
// Print to log file |
|
627 |
iLog->Log( KExample ); |
|
628 |
||
629 |
TInt i = 0; |
|
630 |
TPtrC string; |
|
631 |
_LIT( KParam, "Param[%i]: %S" ); |
|
632 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
633 |
{ |
|
634 |
TestModuleIf().Printf( i, KContactsTest, |
|
635 |
KParam, i, &string ); |
|
636 |
i++; |
|
637 |
} |
|
638 |
||
639 |
iErr = KErrNone; |
|
640 |
||
641 |
DeleteAllL(); |
|
642 |
||
643 |
/**Add contact using SAPI Core class*/ |
|
644 |
||
645 |
_LIT8(KFirstName,"FirstName"); |
|
646 |
_LIT(KName,"Sikandar"); |
|
647 |
_LIT8(KNumber,"MobilePhoneGen"); |
|
648 |
||
649 |
__UHEAP_MARK; |
|
650 |
//instantiate service class |
|
651 |
CContactService* serviceHandle = CContactService::NewL(); |
|
652 |
CleanupStack::PushL(serviceHandle); |
|
653 |
iLog->Log( KServiceOpen ); |
|
654 |
||
655 |
CSingleContact* singleContact = CSingleContact::NewL(); |
|
656 |
CleanupStack::PushL(singleContact); |
|
657 |
iLog->Log(_L("single Contact created\n")); |
|
658 |
||
659 |
CSingleContactField* nameContactField = CSingleContactField::NewL(); |
|
660 |
CleanupStack::PushL(nameContactField); |
|
661 |
iLog->Log(_L("Name Contact Field created \n")); |
|
662 |
||
663 |
CSingleContactField* phoneContactField = CSingleContactField::NewL(); |
|
664 |
CleanupStack::PushL(phoneContactField); |
|
665 |
iLog->Log(_L("Phone Contact Field created \n")); |
|
666 |
||
667 |
nameContactField->SetFieldParamsL(KFirstName,KNullDesC,KName); |
|
668 |
singleContact->AddFieldToContactL(nameContactField); |
|
669 |
iLog->Log(_L("Name Contact Field added \n")); |
|
670 |
||
671 |
phoneContactField->SetFieldParamsL(KNumber,KNullDesC,KPhoneNumber); |
|
672 |
singleContact->AddFieldToContactL(phoneContactField); |
|
673 |
iLog->Log(_L("Phone Contact Field added \n")); |
|
674 |
||
675 |
serviceHandle->AddL(singleContact); |
|
676 |
iLog->Log(_L("AddL called\n")); |
|
677 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
678 |
||
679 |
CleanupStack::Pop(phoneContactField);//singleContactField |
|
680 |
CleanupStack::Pop(nameContactField);//singleContactField |
|
681 |
CleanupStack::PopAndDestroy(singleContact);//singleContact |
|
682 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
683 |
iLog->Log( KServiceClose ); |
|
684 |
__UHEAP_MARKEND; |
|
685 |
/**end */ |
|
686 |
||
687 |
TInt count; |
|
688 |
RPointerArray<TDesC8> idArray; |
|
689 |
CheckContactsL(count,idArray); |
|
690 |
if(count != 1) |
|
691 |
{ |
|
692 |
iErr = KErrGeneral; |
|
693 |
} |
|
694 |
idArray.ResetAndDestroy(); |
|
695 |
||
696 |
DeleteAllL(); |
|
697 |
return iErr; |
|
698 |
} |
|
699 |
||
700 |
// ----------------------------------------------------------------------------- |
|
701 |
// CContactsUT::?member_function |
|
702 |
// ?implementation_description |
|
703 |
// (other items were commented in a header). |
|
704 |
// ----------------------------------------------------------------------------- |
|
705 |
// |
|
706 |
TInt CContactsUT::DeleteContactSAPIL( CStifItemParser& aItem ) |
|
707 |
{ |
|
708 |
// Print to UI |
|
709 |
_LIT( KContactsTest, "ContactsUT" ); |
|
710 |
_LIT( KExample, "In DeleteContactSAPIL" ); |
|
711 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
712 |
// Print to log file |
|
713 |
iLog->Log( KExample ); |
|
714 |
||
715 |
TInt i = 0; |
|
716 |
TPtrC string; |
|
717 |
_LIT( KParam, "Param[%i]: %S" ); |
|
718 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
719 |
{ |
|
720 |
TestModuleIf().Printf( i, KContactsTest, |
|
721 |
KParam, i, &string ); |
|
722 |
i++; |
|
723 |
} |
|
724 |
||
725 |
iErr = KErrNone; |
|
726 |
||
727 |
DeleteAllL(); |
|
728 |
_LIT(KName,"SpiderMan"); |
|
729 |
TPtrC name(KName); |
|
730 |
AddOneContactL(name); |
|
731 |
||
732 |
TInt count(0); |
|
733 |
RPointerArray<TDesC8> idArray; |
|
734 |
CleanupClosePushL(idArray); |
|
735 |
CheckContactsL(count,idArray); |
|
736 |
if(count != 1) |
|
737 |
{ |
|
738 |
return KErrGeneral; |
|
739 |
} |
|
740 |
||
741 |
/**Delete using SAPI core class*/ |
|
742 |
||
743 |
__UHEAP_MARK; |
|
744 |
CContactService* serviceHandle = CContactService::NewL(); |
|
745 |
CleanupStack::PushL(serviceHandle); |
|
746 |
iLog->Log( KServiceOpen ); |
|
747 |
||
748 |
serviceHandle->DeleteL(idArray); |
|
749 |
iLog->Log(_L("DeleteL called\n")); |
|
750 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
751 |
//CActiveScheduler::Start(); |
|
752 |
||
753 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
754 |
iLog->Log( KServiceClose ); |
|
755 |
__UHEAP_MARKEND; |
|
756 |
/**end*/ |
|
757 |
CleanupStack::Pop(&idArray); |
|
758 |
idArray.ResetAndDestroy(); |
|
759 |
||
760 |
RPointerArray<TDesC8> idArray1; |
|
761 |
CleanupClosePushL(idArray1); |
|
762 |
CheckContactsL(count,idArray1); |
|
763 |
if(count) |
|
764 |
{ |
|
765 |
iErr = KErrGeneral; |
|
766 |
} |
|
767 |
CleanupStack::Pop(&idArray1); |
|
768 |
idArray.ResetAndDestroy(); |
|
769 |
return iErr; |
|
770 |
||
771 |
} |
|
772 |
||
773 |
// ----------------------------------------------------------------------------- |
|
774 |
// CContactsUT::?member_function |
|
775 |
// ?implementation_description |
|
776 |
// (other items were commented in a header). |
|
777 |
// ----------------------------------------------------------------------------- |
|
778 |
// |
|
779 |
TInt CContactsUT::ModifyContactSAPIL( CStifItemParser& aItem ) |
|
780 |
{ |
|
781 |
// Print to UI |
|
782 |
_LIT( KContactsTest, "ContactsUT" ); |
|
783 |
_LIT( KExample, "In ModifyContactSAPIL" ); |
|
784 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
785 |
// Print to log file |
|
786 |
iLog->Log( KExample ); |
|
787 |
||
788 |
TInt i = 0; |
|
789 |
TPtrC string; |
|
790 |
_LIT( KParam, "Param[%i]: %S" ); |
|
791 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
792 |
{ |
|
793 |
TestModuleIf().Printf( i, KContactsTest, |
|
794 |
KParam, i, &string ); |
|
795 |
i++; |
|
796 |
} |
|
797 |
||
798 |
iErr = KErrNone; |
|
799 |
||
800 |
DeleteAllL(); |
|
801 |
_LIT(KName,"SuperMan"); |
|
802 |
TPtrC name(KName); |
|
803 |
AddOneContactL(name); |
|
804 |
||
805 |
TInt count(0); |
|
806 |
RPointerArray<TDesC8> idArray; |
|
807 |
CleanupClosePushL(idArray); |
|
808 |
CheckContactsL(count,idArray); |
|
809 |
if(count != 1) |
|
810 |
{ |
|
811 |
return KErrGeneral; |
|
812 |
} |
|
813 |
||
814 |
/**Get using SAPI core class*/ |
|
815 |
__UHEAP_MARK; |
|
816 |
CContactService* serviceHandle = CContactService::NewL(); |
|
817 |
CleanupStack::PushL(serviceHandle); |
|
818 |
iLog->Log( KServiceOpen ); |
|
819 |
||
820 |
serviceHandle->GetListL(this,0,EContacts,*idArray[0]); |
|
821 |
iLog->Log(_L("GetListL called\n")); |
|
822 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
823 |
CActiveScheduler::Start(); |
|
824 |
||
825 |
if(!iSingleContact) |
|
826 |
{ |
|
827 |
return KErrGeneral; |
|
828 |
} |
|
829 |
||
830 |
_LIT(KName1,"SpiderMan"); |
|
831 |
_LIT8(KFirstName,"FirstName"); |
|
832 |
CSingleContactField* field = NULL; |
|
833 |
TInt fieldCount(iSingleContact->FieldCount()); |
|
834 |
while(fieldCount) |
|
835 |
{ |
|
836 |
TPtrC8 fieldKey; |
|
837 |
TPtrC label; |
|
838 |
TPtrC value; |
|
839 |
field = iSingleContact->FieldAt(--fieldCount); |
|
840 |
field->GetFieldDataL(fieldKey,label,value); |
|
841 |
if( !fieldKey.Compare(KFirstName) && !value.Compare(KName)) |
|
842 |
{ |
|
843 |
field->SetFieldParamsL(KFirstName,KNullDesC,KName1); |
|
844 |
iLog->Log(_L("Phone Contact Field modified \n")); |
|
845 |
break; |
|
846 |
} |
|
847 |
} |
|
848 |
// |
|
849 |
//MVPbkContactLinkArray* linkArray = iContactManager->CreateLinksLC(iSingleContact->GetContactId()); |
|
850 |
//iOp = iContactManager->RetrieveContactL(linkArray->At(0),*this); |
|
851 |
//CActiveScheduler::Start(); |
|
852 |
//CleanupStack::Pop(); |
|
853 |
// |
|
854 |
__UHEAP_MARK; |
|
855 |
serviceHandle->AddL(this,0,iSingleContact); |
|
856 |
iLog->Log(_L("AddL called\n")); |
|
857 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
858 |
CActiveScheduler::Start(); |
|
859 |
__UHEAP_MARKEND; |
|
860 |
||
861 |
delete iSingleContact; |
|
862 |
iSingleContact = NULL; |
|
863 |
||
864 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
865 |
iLog->Log( KServiceClose ); |
|
866 |
__UHEAP_MARKEND; |
|
867 |
/**end*/ |
|
868 |
||
869 |
||
870 |
CleanupStack::Pop(&idArray); |
|
871 |
idArray.ResetAndDestroy(); |
|
872 |
||
873 |
RPointerArray<TDesC8> idArray1; |
|
874 |
CleanupClosePushL(idArray1); |
|
875 |
CheckContactsL(count,idArray1); |
|
876 |
if(count != 1) |
|
877 |
{ |
|
878 |
iErr = KErrGeneral; |
|
879 |
} |
|
880 |
CleanupStack::Pop(); |
|
881 |
idArray1.ResetAndDestroy(); |
|
882 |
//to implement ..checking name |
|
883 |
return iErr; |
|
884 |
||
885 |
} |
|
886 |
||
887 |
// ----------------------------------------------------------------------------- |
|
888 |
// CContactsUT::?member_function |
|
889 |
// ?implementation_description |
|
890 |
// (other items were commented in a header). |
|
891 |
// ----------------------------------------------------------------------------- |
|
892 |
// |
|
893 |
TInt CContactsUT::ImportContactSAPIL( CStifItemParser& aItem ) |
|
894 |
{ |
|
895 |
// Print to UI |
|
896 |
_LIT( KContactsTest, "ContactsUT" ); |
|
897 |
_LIT( KExample, "In ImportContactSAPIL" ); |
|
898 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
899 |
// Print to log file |
|
900 |
iLog->Log( KExample ); |
|
901 |
||
902 |
TInt i = 0; |
|
903 |
TPtrC string; |
|
904 |
_LIT( KParam, "Param[%i]: %S" ); |
|
905 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
906 |
{ |
|
907 |
TestModuleIf().Printf( i, KContactsTest, |
|
908 |
KParam, i, &string ); |
|
909 |
i++; |
|
910 |
} |
|
911 |
||
912 |
iErr = KErrNone; |
|
913 |
_LIT(KFileName,"c:\\vcardim.vcf"); |
|
914 |
||
915 |
/* DeleteAllL(); |
|
916 |
||
917 |
_LIT(KName,"SuperMan"); |
|
918 |
TPtrC name(KName); |
|
919 |
AddOneContactL(name); |
|
920 |
||
921 |
TInt count(0); |
|
922 |
RPointerArray<TDesC8> idArray; |
|
923 |
CleanupClosePushL(idArray); |
|
924 |
CheckContactsL(count,idArray); |
|
925 |
if(count != 1) |
|
926 |
{ |
|
927 |
return KErrGeneral; |
|
928 |
} |
|
929 |
||
930 |
//__UHEAP_MARK; |
|
931 |
MVPbkContactLinkArray* linkArray = iContactManager->CreateLinksLC(*idArray[0]); |
|
932 |
iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
933 |
// Create the buffer to store the contact |
|
934 |
iBuffer = HBufC8::NewL( 1024 ); |
|
935 |
TPtr8 bufferPtr( iBuffer->Des() ); |
|
936 |
iDestStream.Open( bufferPtr ); |
|
937 |
//export the contact from MVPbkContactLink |
|
938 |
// __UHEAP_MARK; |
|
939 |
iOp = iVCardEngine->ExportVCardL( iDestStream, linkArray->At(0), *this ); |
|
940 |
CActiveScheduler::Start(); |
|
941 |
||
942 |
// __UHEAP_MARKEND; |
|
943 |
if( !iErr ) |
|
944 |
{ |
|
945 |
iDestStream.CommitL(); |
|
946 |
} |
|
947 |
||
948 |
iDestStream.Close(); |
|
949 |
if(iBuffer) |
|
950 |
{ |
|
951 |
RFile file; |
|
952 |
CleanupClosePushL(file); |
|
953 |
file.Replace(iRfs,KFileName,EFileWrite); |
|
954 |
file.Write(0,*iBuffer); |
|
955 |
CleanupStack::PopAndDestroy(&file); |
|
956 |
} |
|
957 |
delete iBuffer; |
|
958 |
iBuffer = NULL; |
|
959 |
delete iVCardEngine; |
|
960 |
iVCardEngine = NULL; |
|
961 |
CleanupStack::PopAndDestroy();//linkArray |
|
962 |
//__UHEAP_MARKEND; |
|
963 |
||
964 |
CleanupStack::Pop(&idArray); |
|
965 |
idArray.ResetAndDestroy(); |
|
966 |
DeleteAllL(); |
|
967 |
*/ |
|
968 |
DeleteAllL(); |
|
969 |
__UHEAP_MARK; |
|
970 |
CContactService* serviceHandle = CContactService::NewL(); |
|
971 |
CleanupStack::PushL(serviceHandle); |
|
972 |
iLog->Log( KServiceOpen ); |
|
973 |
||
974 |
TFileName importFile(KFileName); |
|
975 |
||
976 |
serviceHandle->ImportVCardToStoreL(this,0,importFile); |
|
977 |
iLog->Log(_L("ImportVCardToStoreL called\n")); |
|
978 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
979 |
CActiveScheduler::Start(); |
|
980 |
||
981 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
982 |
iLog->Log( KServiceClose ); |
|
983 |
__UHEAP_MARKEND; |
|
984 |
||
985 |
TInt count = 0; |
|
986 |
RPointerArray<TDesC8> idArray; |
|
987 |
CleanupClosePushL(idArray); |
|
988 |
CheckContactsL(count,idArray); |
|
989 |
if(count != 1) |
|
990 |
{ |
|
991 |
return KErrGeneral; |
|
992 |
} |
|
993 |
CleanupStack::Pop(&idArray); |
|
994 |
idArray.ResetAndDestroy(); |
|
995 |
return iErr; |
|
996 |
} |
|
997 |
||
998 |
// ----------------------------------------------------------------------------- |
|
999 |
// CContactsUT::?member_function |
|
1000 |
// ?implementation_description |
|
1001 |
// (other items were commented in a header). |
|
1002 |
// ----------------------------------------------------------------------------- |
|
1003 |
// |
|
1004 |
TInt CContactsUT::ExportContactSAPIL( CStifItemParser& aItem ) |
|
1005 |
{ |
|
1006 |
// Print to UI |
|
1007 |
_LIT( KContactsTest, "ContactsUT" ); |
|
1008 |
_LIT( KExample, "In ExportContactSAPIL" ); |
|
1009 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1010 |
// Print to log file |
|
1011 |
iLog->Log( KExample ); |
|
1012 |
||
1013 |
TInt i = 0; |
|
1014 |
TPtrC string; |
|
1015 |
_LIT( KParam, "Param[%i]: %S" ); |
|
1016 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1017 |
{ |
|
1018 |
TestModuleIf().Printf( i, KContactsTest, |
|
1019 |
KParam, i, &string ); |
|
1020 |
i++; |
|
1021 |
} |
|
1022 |
||
1023 |
iErr = KErrNone; |
|
1024 |
_LIT(KFileName,"c:\\vcardim.vcf"); |
|
1025 |
_LIT(KFileName1,"c:\\vcardim1.vcf"); |
|
1026 |
||
1027 |
DeleteAllL(); |
|
1028 |
||
1029 |
_LIT(KName,"SuperMan"); |
|
1030 |
TPtrC name(KName); |
|
1031 |
AddOneContactL(name); |
|
1032 |
||
1033 |
_LIT(KName1,"SpiderMan"); |
|
1034 |
TPtrC name1(KName1); |
|
1035 |
AddOneContactL(name1); |
|
1036 |
||
1037 |
TInt count(0); |
|
1038 |
RPointerArray<TDesC8> idArray; |
|
1039 |
CleanupClosePushL(idArray); |
|
1040 |
CheckContactsL(count,idArray); |
|
1041 |
TInt ret = iRfs.Delete(KFileName); |
|
1042 |
// ret = iRfs.Delete(KFileName1); |
|
1043 |
/* if(count != 1) |
|
1044 |
{ |
|
1045 |
return KErrGeneral; |
|
1046 |
}*/ |
|
1047 |
||
1048 |
/* __UHEAP_MARK; |
|
1049 |
RFile writeStream; |
|
1050 |
CleanupClosePushL(writeStream); |
|
1051 |
User::LeaveIfError(writeStream.Create(iRfs,KFileName,EFileWrite)); |
|
1052 |
while(count) |
|
1053 |
{ |
|
1054 |
writeStream.Write(*idArray[--count]); |
|
1055 |
} |
|
1056 |
CleanupStack::PopAndDestroy(&writeStream); |
|
1057 |
__UHEAP_MARKEND; |
|
1058 |
*/ |
|
1059 |
//iBuffer = HBufC8::NewL( 1024 ); |
|
1060 |
//TPtr8 bfrPtr(iBuffer->Des()); |
|
1061 |
// __UHEAP_MARK; |
|
1062 |
//RFileReadStream readStream; |
|
1063 |
// CleanupClosePushL(readStream); |
|
1064 |
// User::LeaveIfError(readStream.Open(iRfs,KFileName,EFileRead)); |
|
1065 |
||
1066 |
//TInt cells = User::CountAllocCells(); |
|
1067 |
__UHEAP_MARK; |
|
1068 |
RFileWriteStream destStream; |
|
1069 |
CleanupClosePushL(destStream); |
|
1070 |
User::LeaveIfError(destStream.Create(iRfs,KFileName,EFileWrite)); |
|
1071 |
iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
1072 |
while(count) |
|
1073 |
{ |
|
1074 |
MVPbkContactLinkArray* linkArray = iContactManager->CreateLinksLC(*idArray[--count]); |
|
1075 |
const MVPbkContactLink& link = linkArray->At(0); |
|
1076 |
iOp = iVCardEngine->ExportVCardL( destStream, link, *this ); |
|
1077 |
CActiveScheduler::Start(); |
|
1078 |
destStream.CommitL(); |
|
1079 |
CleanupStack::PopAndDestroy(); |
|
1080 |
} |
|
1081 |
delete iVCardEngine; |
|
1082 |
iVCardEngine = NULL; |
|
1083 |
CleanupStack::PopAndDestroy(&destStream); |
|
1084 |
__UHEAP_MARKEND; |
|
1085 |
CleanupStack::Pop(&idArray); |
|
1086 |
idArray.ResetAndDestroy(); |
|
1087 |
||
1088 |
/* |
|
1089 |
//CleanupStack::PushL(linkArray); |
|
1090 |
cells = User::CountAllocCells(); |
|
1091 |
iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
1092 |
||
1093 |
cells = User::CountAllocCells(); |
|
1094 |
RDesWriteStream destStream; |
|
1095 |
CleanupClosePushL(destStream); |
|
1096 |
//User::LeaveIfError(destStream.Create(iRfs,KFileName1,EFileWrite)); |
|
1097 |
destStream.Open(bfrPtr); |
|
1098 |
TInt links = linkArray->Count(); |
|
1099 |
while(links) |
|
1100 |
{ |
|
1101 |
const MVPbkContactLink& link = linkArray->At(--links); |
|
1102 |
iOp = iVCardEngine->ExportVCardL( destStream, link, *this ); |
|
1103 |
CActiveScheduler::Start(); |
|
1104 |
} |
|
1105 |
destStream.CommitL(); |
|
1106 |
CleanupStack::PopAndDestroy(&destStream); |
|
1107 |
||
1108 |
cells = User::CountAllocCells(); |
|
1109 |
delete iVCardEngine; |
|
1110 |
iVCardEngine = NULL; |
|
1111 |
cells = User::CountAllocCells(); |
|
1112 |
||
1113 |
CleanupStack::PopAndDestroy(); |
|
1114 |
cells = User::CountAllocCells(); |
|
1115 |
CleanupStack::PopAndDestroy(&readStream); |
|
1116 |
||
1117 |
// __UHEAP_MARKEND; |
|
1118 |
if(iBuffer) |
|
1119 |
{ |
|
1120 |
RFile file; |
|
1121 |
CleanupClosePushL(file); |
|
1122 |
file.Replace(iRfs,KFileName,EFileWrite); |
|
1123 |
file.Write(0,*iBuffer); |
|
1124 |
CleanupStack::PopAndDestroy(&file); |
|
1125 |
} |
|
1126 |
delete iBuffer; |
|
1127 |
iBuffer = NULL; |
|
1128 |
CleanupStack::Pop(&idArray); |
|
1129 |
idArray.ResetAndDestroy(); |
|
1130 |
/* |
|
1131 |
// Create the buffer to store the contact |
|
1132 |
iBuffer = HBufC8::NewL( 1024 ); |
|
1133 |
TPtr8 bufferPtr( iBuffer->Des() ); |
|
1134 |
iDestStream.Open( bufferPtr ); |
|
1135 |
//export the contact from MVPbkContactLink |
|
1136 |
// __UHEAP_MARK; |
|
1137 |
||
1138 |
CActiveScheduler::Start(); |
|
1139 |
||
1140 |
// __UHEAP_MARKEND; |
|
1141 |
if( !iErr ) |
|
1142 |
{ |
|
1143 |
iDestStream.CommitL(); |
|
1144 |
} |
|
1145 |
||
1146 |
iDestStream.Close(); |
|
1147 |
if(iBuffer) |
|
1148 |
{ |
|
1149 |
RFile file; |
|
1150 |
CleanupClosePushL(file); |
|
1151 |
file.Replace(iRfs,KFileName,EFileWrite); |
|
1152 |
file.Write(0,*iBuffer); |
|
1153 |
CleanupStack::PopAndDestroy(&file); |
|
1154 |
} |
|
1155 |
delete iBuffer; |
|
1156 |
iBuffer = NULL; |
|
1157 |
delete iVCardEngine; |
|
1158 |
iVCardEngine = NULL; |
|
1159 |
CleanupStack::PopAndDestroy();//linkArray |
|
1160 |
//__UHEAP_MARKEND; |
|
1161 |
||
1162 |
CleanupStack::Pop(&idArray); |
|
1163 |
idArray.ResetAndDestroy(); |
|
1164 |
DeleteAllL(); |
|
1165 |
*/ |
|
1166 |
/* __UHEAP_MARK; |
|
1167 |
CContactService* serviceHandle = CContactService::NewL(); |
|
1168 |
CleanupStack::PushL(serviceHandle); |
|
1169 |
iLog->Log( KServiceOpen ); |
|
1170 |
||
1171 |
TFileName exportFile(KFileName); |
|
1172 |
||
1173 |
serviceHandle->ExportVCardL(this,0,exportFile,idArray); |
|
1174 |
iLog->Log(_L("ExportVCardL called\n")); |
|
1175 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
1176 |
CActiveScheduler::Start(); |
|
1177 |
||
1178 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1179 |
iLog->Log( KServiceClose ); |
|
1180 |
__UHEAP_MARKEND; |
|
1181 |
*//* |
|
1182 |
TInt count = 0; |
|
1183 |
RPointerArray<TDesC8> idArray; |
|
1184 |
CleanupClosePushL(idArray); |
|
1185 |
CheckContactsL(count,idArray); |
|
1186 |
if(count != 1) |
|
1187 |
{ |
|
1188 |
return KErrGeneral; |
|
1189 |
}*/ |
|
1190 |
/* CleanupStack::Pop(&idArray); |
|
1191 |
idArray.ResetAndDestroy();*/ |
|
1192 |
return iErr; |
|
1193 |
} |
|
1194 |
// ----------------------------------------------------------------------------- |
|
1195 |
// CContactsUT::?member_function |
|
1196 |
// ?implementation_description |
|
1197 |
// (other items were commented in a header). |
|
1198 |
// ----------------------------------------------------------------------------- |
|
1199 |
// |
|
1200 |
TInt CContactsUT::GetListDeleteContactL( CStifItemParser& aItem ) |
|
1201 |
{ |
|
1202 |
// Print to UI |
|
1203 |
_LIT( KContactsTest, "ContactsUT" ); |
|
1204 |
_LIT( KExample, "In Add" ); |
|
1205 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1206 |
// Print to log file |
|
1207 |
iLog->Log( KExample ); |
|
1208 |
||
1209 |
TInt i = 0; |
|
1210 |
TPtrC string; |
|
1211 |
_LIT( KParam, "Param[%i]: %S" ); |
|
1212 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1213 |
{ |
|
1214 |
TestModuleIf().Printf( i, KContactsTest, |
|
1215 |
KParam, i, &string ); |
|
1216 |
i++; |
|
1217 |
} |
|
1218 |
||
1219 |
iErr = KErrNone; |
|
1220 |
||
1221 |
||
1222 |
/**Getlist using SAPI core class*/ |
|
1223 |
||
1224 |
//__UHEAP_MARK; |
|
1225 |
CContactService* serviceHandle = CContactService::NewL(); |
|
1226 |
CleanupStack::PushL(serviceHandle); |
|
1227 |
iLog->Log( KServiceOpen ); |
|
1228 |
||
1229 |
iOperation = EGetContactDelete; |
|
1230 |
serviceHandle->GetListL(this,0,EContacts); |
|
1231 |
iLog->Log(_L("GetListL called\n")); |
|
1232 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
1233 |
CActiveScheduler::Start(); |
|
1234 |
||
1235 |
//iOperation = EGetContact; |
|
1236 |
//iServiceHandle->GetListL(this,0,EContacts,*iBuffer); |
|
1237 |
//CActiveScheduler::Start(); |
|
1238 |
/**Delete using SAPI core class*/ |
|
1239 |
||
1240 |
// __UHEAP_MARK; |
|
1241 |
RPointerArray<TDesC8> idArray; |
|
1242 |
CleanupClosePushL(idArray); |
|
1243 |
idArray.AppendL(iBuffer); |
|
1244 |
||
1245 |
||
1246 |
serviceHandle->DeleteL(this,0,idArray); |
|
1247 |
iLog->Log(_L("DeleteL called\n")); |
|
1248 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
1249 |
CActiveScheduler::Start(); |
|
1250 |
||
1251 |
||
1252 |
CleanupStack::PopAndDestroy(&idArray);//singleContactField |
|
1253 |
||
1254 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1255 |
iLog->Log( KServiceClose ); |
|
1256 |
// __UHEAP_MARKEND; |
|
1257 |
||
1258 |
||
1259 |
||
1260 |
return iErr; |
|
1261 |
} |
|
1262 |
// ----------------------------------------------------------------------------- |
|
1263 |
// CContactsUT::?member_function |
|
1264 |
// ?implementation_description |
|
1265 |
// (other items were commented in a header). |
|
1266 |
// ----------------------------------------------------------------------------- |
|
1267 |
// |
|
1268 |
TInt CContactsUT::AddContactGetListL( CStifItemParser& aItem ) |
|
1269 |
{ |
|
1270 |
// Print to UI |
|
1271 |
_LIT( KContactsTest, "ContactsUT" ); |
|
1272 |
_LIT( KExample, "In Add" ); |
|
1273 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1274 |
// Print to log file |
|
1275 |
iLog->Log( KExample ); |
|
1276 |
||
1277 |
TInt i = 0; |
|
1278 |
TPtrC string; |
|
1279 |
_LIT( KParam, "Param[%i]: %S" ); |
|
1280 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1281 |
{ |
|
1282 |
TestModuleIf().Printf( i, KContactsTest, |
|
1283 |
KParam, i, &string ); |
|
1284 |
i++; |
|
1285 |
} |
|
1286 |
||
1287 |
iErr = KErrNone; |
|
1288 |
||
1289 |
/**Add contact using SAPI Core class*/ |
|
1290 |
||
1291 |
_LIT8(KFirstName,"FirstName"); |
|
1292 |
_LIT(KName,"Kats"); |
|
1293 |
_LIT8(KNumber,"MobilePhoneHome"); |
|
1294 |
_LIT(KPhone,"98789"); |
|
1295 |
||
1296 |
// __UHEAP_MARK; |
|
1297 |
//instantiate service class |
|
1298 |
CContactService* serviceHandle = CContactService::NewL(); |
|
1299 |
CleanupStack::PushL(serviceHandle); |
|
1300 |
iLog->Log( KServiceOpen ); |
|
1301 |
||
1302 |
CSingleContact* singleContact = CSingleContact::NewL(); |
|
1303 |
CleanupStack::PushL(singleContact); |
|
1304 |
iLog->Log(_L("single Contact created\n")); |
|
1305 |
||
1306 |
CSingleContactField* nameContactField = CSingleContactField::NewL(); |
|
1307 |
CleanupStack::PushL(nameContactField); |
|
1308 |
iLog->Log(_L("Name Contact Field created \n")); |
|
1309 |
||
1310 |
CSingleContactField* phoneContactField = CSingleContactField::NewL(); |
|
1311 |
CleanupStack::PushL(phoneContactField); |
|
1312 |
iLog->Log(_L("Phone Contact Field created \n")); |
|
1313 |
||
1314 |
nameContactField->SetFieldParamsL(KFirstName,KNullDesC,KName); |
|
1315 |
singleContact->AddFieldToContactL(nameContactField); |
|
1316 |
iLog->Log(_L("Name Contact Field added \n")); |
|
1317 |
||
1318 |
phoneContactField->SetFieldParamsL(KNumber,KNullDesC,KPhone); |
|
1319 |
singleContact->AddFieldToContactL(phoneContactField); |
|
1320 |
iLog->Log(_L("Phone Contact Field added \n")); |
|
1321 |
||
1322 |
serviceHandle->AddL(this,0,singleContact,KNullDesC8,KNullDesC); |
|
1323 |
iLog->Log(_L("AddL called\n")); |
|
1324 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
1325 |
CActiveScheduler::Start(); |
|
1326 |
||
1327 |
CleanupStack::Pop(phoneContactField);//singleContactField |
|
1328 |
CleanupStack::Pop(nameContactField);//singleContactField |
|
1329 |
CleanupStack::PopAndDestroy(singleContact);//singleContact |
|
1330 |
// CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1331 |
// iLog->Log( KServiceClose ); |
|
1332 |
// __UHEAP_MARKENDC(1); |
|
1333 |
/**end */ |
|
1334 |
||
1335 |
if(iErr) |
|
1336 |
{ |
|
1337 |
return iErr; |
|
1338 |
} |
|
1339 |
||
1340 |
/**Getlist using SAPI core class*/ |
|
1341 |
||
1342 |
//__UHEAP_MARK; |
|
1343 |
//serviceHandle = CContactService::NewL(); |
|
1344 |
// CleanupStack::PushL(serviceHandle); |
|
1345 |
iLog->Log( KServiceOpen ); |
|
1346 |
||
1347 |
iOperation = EGetContact; |
|
1348 |
serviceHandle->GetListL(this,0,EContacts); |
|
1349 |
iLog->Log(_L("GetListL called\n")); |
|
1350 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
1351 |
CActiveScheduler::Start(); |
|
1352 |
||
1353 |
//iOperation = EGetContact; |
|
1354 |
//iServiceHandle->GetListL(this,0,EContacts,*iBuffer); |
|
1355 |
//CActiveScheduler::Start(); |
|
1356 |
||
1357 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1358 |
iLog->Log( KServiceClose ); |
|
1359 |
// __UHEAP_MARKEND; |
|
1360 |
||
1361 |
if(iErr) |
|
1362 |
{ |
|
1363 |
return iErr; |
|
1364 |
} |
|
1365 |
/**Delete using virtual Phonebook */ |
|
1366 |
||
1367 |
||
1368 |
// Create find operation |
|
1369 |
iOp = iContactManager->MatchPhoneNumberL( |
|
1370 |
KPhone, KPhone().Length(), *this ); |
|
1371 |
CActiveScheduler::Start(); |
|
1372 |
||
1373 |
iErr = KErrGeneral; |
|
1374 |
TInt count(iFindResults->Count()); |
|
1375 |
while(count) |
|
1376 |
{ |
|
1377 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
1378 |
iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count)))); |
|
1379 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
1380 |
CActiveScheduler::Start(); |
|
1381 |
} |
|
1382 |
/**end */ |
|
1383 |
||
1384 |
||
1385 |
return iErr; |
|
1386 |
} |
|
1387 |
// ----------------------------------------------------------------------------- |
|
1388 |
// CContactsUT::?member_function |
|
1389 |
// ?implementation_description |
|
1390 |
// (other items were commented in a header). |
|
1391 |
// ----------------------------------------------------------------------------- |
|
1392 |
// |
|
1393 |
TInt CContactsUT::GetGroupsL( CStifItemParser& aItem ) |
|
1394 |
{ |
|
1395 |
||
1396 |
// Print to UI |
|
1397 |
_LIT( KContactsTest, "ContactsUT" ); |
|
1398 |
_LIT( KExample, "In Add" ); |
|
1399 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1400 |
// Print to log file |
|
1401 |
iLog->Log( KExample ); |
|
1402 |
||
1403 |
TInt i = 0; |
|
1404 |
TPtrC string; |
|
1405 |
_LIT( KParam, "Param[%i]: %S" ); |
|
1406 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1407 |
{ |
|
1408 |
TestModuleIf().Printf( i, KContactsTest, |
|
1409 |
KParam, i, &string ); |
|
1410 |
i++; |
|
1411 |
} |
|
1412 |
||
1413 |
iErr = KErrGeneral; |
|
1414 |
||
1415 |
/**Add 1 group using virtual phonebook */ |
|
1416 |
||
1417 |
||
1418 |
||
1419 |
iGroup = iStore->CreateNewContactGroupLC(); |
|
1420 |
iGroup->SetGroupLabelL(KGroup1); |
|
1421 |
iGroup->CommitL(*this); |
|
1422 |
||
1423 |
CActiveScheduler::Start(); |
|
1424 |
CleanupStack::Pop(); |
|
1425 |
||
1426 |
||
1427 |
// __UHEAP_MARK; |
|
1428 |
iServiceHandle = CContactService::NewL(); |
|
1429 |
iLog->Log( KServiceOpen ); |
|
1430 |
||
1431 |
CContactIter* iter = iServiceHandle->GetListL(EGroups); |
|
1432 |
iLog->Log(_L("GetListL called\n")); |
|
1433 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
1434 |
// CActiveScheduler::Start(); |
|
1435 |
||
1436 |
iErr = KErrGeneral; |
|
1437 |
CSingleContact* singleContact = NULL; |
|
1438 |
HBufC8* buf = NULL; |
|
1439 |
TInt count = 0; |
|
1440 |
while(ETrue) |
|
1441 |
{ |
|
1442 |
iter->NextL(singleContact,buf); |
|
1443 |
iBuffer = buf; |
|
1444 |
if(!singleContact) |
|
1445 |
{ |
|
1446 |
break; |
|
1447 |
} |
|
1448 |
++count; |
|
1449 |
TInt fields(singleContact->FieldCount()); |
|
1450 |
while(fields) |
|
1451 |
{ |
|
1452 |
CSingleContactField* field = singleContact->FieldAt(--fields); |
|
1453 |
TPtrC groupId; |
|
1454 |
RPointerArray<TDesC8> array; |
|
1455 |
field->GetFieldDataL(groupId,array); |
|
1456 |
||
1457 |
||
1458 |
if(groupId.Compare(KGroup1)==0) |
|
1459 |
{ |
|
1460 |
iErr = KErrNone; |
|
1461 |
break; |
|
1462 |
} |
|
1463 |
} |
|
1464 |
} |
|
1465 |
delete iServiceHandle;//serviceHandle |
|
1466 |
delete iter; |
|
1467 |
iServiceHandle = NULL; |
|
1468 |
iLog->Log( KServiceClose ); |
|
1469 |
return iErr; |
|
1470 |
||
1471 |
} |
|
1472 |
||
1473 |
TInt CContactsUT::GetDatabaseL( CStifItemParser& aItem ) |
|
1474 |
{ |
|
1475 |
||
1476 |
// Print to UI |
|
1477 |
_LIT( KContactsTest, "ContactsUT" ); |
|
1478 |
_LIT( KExample, "In Add" ); |
|
1479 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1480 |
// Print to log file |
|
1481 |
iLog->Log( KExample ); |
|
1482 |
||
1483 |
TInt i = 0; |
|
1484 |
TPtrC string; |
|
1485 |
_LIT( KParam, "Param[%i]: %S" ); |
|
1486 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1487 |
{ |
|
1488 |
TestModuleIf().Printf( i, KContactsTest, |
|
1489 |
KParam, i, &string ); |
|
1490 |
i++; |
|
1491 |
} |
|
1492 |
||
1493 |
iErr = KErrNone; |
|
1494 |
||
1495 |
||
1496 |
||
1497 |
// __UHEAP_MARK; |
|
1498 |
iServiceHandle = CContactService::NewL(); |
|
1499 |
iLog->Log( KServiceOpen ); |
|
1500 |
||
1501 |
iOperation = EGetDatabase; |
|
1502 |
||
1503 |
CContactIter* iter = CContactIter::NewL(); |
|
1504 |
iServiceHandle->GetListL(*iter); |
|
1505 |
iLog->Log(_L("GetListL called\n")); |
|
1506 |
TPtrC DbName; |
|
1507 |
iter->NextL(DbName); |
|
1508 |
||
1509 |
while(!DbName.Compare(KNullDesC)) |
|
1510 |
{ |
|
1511 |
iter->NextL(DbName); |
|
1512 |
} |
|
1513 |
||
1514 |
delete iServiceHandle;//serviceHandle |
|
1515 |
iServiceHandle = NULL; |
|
1516 |
delete iter; |
|
1517 |
iLog->Log( KServiceClose ); |
|
1518 |
// __UHEAP_MARKEND; |
|
1519 |
||
1520 |
||
1521 |
||
1522 |
||
1523 |
return iErr; |
|
1524 |
||
1525 |
} |
|
1526 |
||
1527 |
// ----------------------------------------------------------------------------- |
|
1528 |
// CContactsUT::?member_function |
|
1529 |
// ?implementation_description |
|
1530 |
// (other items were commented in a header). |
|
1531 |
// ----------------------------------------------------------------------------- |
|
1532 |
// |
|
1533 |
TInt CContactsUT::GetContactsL( CStifItemParser& aItem ) |
|
1534 |
{ |
|
1535 |
||
1536 |
||
1537 |
/**GetList using SAPI Core class */ |
|
1538 |
// __UHEAP_MARK; |
|
1539 |
||
1540 |
||
1541 |
||
1542 |
// Print to UI |
|
1543 |
_LIT( KContactsTest, "ContactsUT" ); |
|
1544 |
_LIT( KExample, "In Add" ); |
|
1545 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1546 |
// Print to log file |
|
1547 |
iLog->Log( KExample ); |
|
1548 |
||
1549 |
TInt i = 0; |
|
1550 |
TPtrC string; |
|
1551 |
_LIT( KParam, "Param[%i]: %S" ); |
|
1552 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1553 |
{ |
|
1554 |
TestModuleIf().Printf( i, KContactsTest, |
|
1555 |
KParam, i, &string ); |
|
1556 |
i++; |
|
1557 |
} |
|
1558 |
||
1559 |
iErr = KErrNone; |
|
1560 |
||
1561 |
/**Delete using virtual Phonebook */ |
|
1562 |
||
1563 |
_LIT(KPhone,"13579"); |
|
1564 |
// Create find operation |
|
1565 |
iOp = iContactManager->MatchPhoneNumberL( |
|
1566 |
KPhone, KPhone().Length(), *this ); |
|
1567 |
CActiveScheduler::Start(); |
|
1568 |
||
1569 |
iErr = KErrGeneral; |
|
1570 |
TInt count1(iFindResults->Count()); |
|
1571 |
while(count1) |
|
1572 |
{ |
|
1573 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
1574 |
iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count1)))); |
|
1575 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
1576 |
CActiveScheduler::Start(); |
|
1577 |
} |
|
1578 |
/**end */ |
|
1579 |
||
1580 |
/**Add 2 contacts using virtual phonebook*/ |
|
1581 |
||
1582 |
CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
1583 |
CleanupStack::PushL(fieldTypeRefList); |
|
1584 |
||
1585 |
fieldTypeRefList->AppendL( |
|
1586 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
1587 |
fieldTypeRefList->AppendL( |
|
1588 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
1589 |
||
1590 |
// Create first contact |
|
1591 |
iStoreContact = iStore->CreateNewContactLC(); |
|
1592 |
||
1593 |
// Create contact field for contact |
|
1594 |
MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
1595 |
// Set contact field data |
|
1596 |
_LIT(KFirstName,"Tenali"); |
|
1597 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
1598 |
// Add the contact field to contact |
|
1599 |
iStoreContact->AddFieldL( field ); |
|
1600 |
CleanupStack::Pop(); // field |
|
1601 |
||
1602 |
// Create contact field for contact |
|
1603 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
1604 |
// Set contact field data |
|
1605 |
_LIT(KFirstNumber,"13579"); |
|
1606 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
1607 |
// Add the contact field to contact |
|
1608 |
iStoreContact->AddFieldL( field ); |
|
1609 |
CleanupStack::Pop(); // field |
|
1610 |
||
1611 |
// Commit the new created contact to contact store |
|
1612 |
iStoreContact->CommitL( *this ); |
|
1613 |
CActiveScheduler::Start(); |
|
1614 |
CleanupStack::Pop(); // iStoreContact |
|
1615 |
||
1616 |
||
1617 |
// Create second contact |
|
1618 |
iStoreContact = iStore->CreateNewContactLC(); |
|
1619 |
||
1620 |
// Create contact field for contact |
|
1621 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
1622 |
// Set contact field data |
|
1623 |
_LIT(KSecondName,"Birbal"); |
|
1624 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondName ); |
|
1625 |
// Add the contact field to contact |
|
1626 |
iStoreContact->AddFieldL( field ); |
|
1627 |
CleanupStack::Pop(); // field |
|
1628 |
||
1629 |
// Create contact field for contact |
|
1630 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
1631 |
// Set contact field data |
|
1632 |
_LIT(KSecondNumber,"13579"); |
|
1633 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondNumber ); |
|
1634 |
// Add the contact field to contact |
|
1635 |
iStoreContact->AddFieldL( field ); |
|
1636 |
CleanupStack::Pop(); // field |
|
1637 |
||
1638 |
// Commit the new created contact to contact store |
|
1639 |
iStoreContact->CommitL( *this ); |
|
1640 |
CActiveScheduler::Start(); |
|
1641 |
CleanupStack::Pop(); // iStoreContact |
|
1642 |
||
1643 |
CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
1644 |
/**end*/ |
|
1645 |
||
1646 |
||
1647 |
||
1648 |
iServiceHandle = CContactService::NewL(); |
|
1649 |
iLog->Log( KServiceOpen ); |
|
1650 |
||
1651 |
iOperation = EGetContact; |
|
1652 |
CContactIter* iter = iServiceHandle->GetListL(EContacts); |
|
1653 |
||
1654 |
_LIT8(KFirstName1,"FirstName"); |
|
1655 |
_LIT(KTName,"Tenali"); |
|
1656 |
_LIT(KBName,"Birbal"); |
|
1657 |
TInt tError = KErrNotFound; |
|
1658 |
TInt bError = KErrNotFound; |
|
1659 |
CSingleContact* singleContact = NULL; |
|
1660 |
HBufC8* buf = NULL; |
|
1661 |
TInt count = 0; |
|
1662 |
while(ETrue) |
|
1663 |
{ |
|
1664 |
iter->NextL(singleContact,buf); |
|
1665 |
if(!singleContact) |
|
1666 |
{ |
|
1667 |
break; |
|
1668 |
} |
|
1669 |
++count; |
|
1670 |
TInt count(singleContact->FieldCount()); |
|
1671 |
while(count) |
|
1672 |
{ |
|
1673 |
CSingleContactField* field = singleContact->FieldAt(--count); |
|
1674 |
TPtrC8 fieldKey; |
|
1675 |
TPtrC label; |
|
1676 |
TPtrC value; |
|
1677 |
field->GetFieldDataL(fieldKey,label,value); |
|
1678 |
if (fieldKey == KFirstName1 && value == KTName) |
|
1679 |
{ |
|
1680 |
tError = KErrNone; |
|
1681 |
} |
|
1682 |
else if (fieldKey == KFirstName1 && value == KBName) |
|
1683 |
{ |
|
1684 |
bError = KErrNone; |
|
1685 |
} |
|
1686 |
} |
|
1687 |
delete singleContact; |
|
1688 |
} |
|
1689 |
if(tError == KErrNone && bError == KErrNone) |
|
1690 |
{ |
|
1691 |
iErr = KErrNone; |
|
1692 |
} |
|
1693 |
else |
|
1694 |
{ |
|
1695 |
iErr = KErrNotFound; |
|
1696 |
} |
|
1697 |
delete iServiceHandle;//serviceHandle |
|
1698 |
delete iter; |
|
1699 |
iServiceHandle = NULL; |
|
1700 |
iLog->Log( KServiceClose ); |
|
1701 |
return iErr; |
|
1702 |
} |
|
1703 |
||
1704 |
// ----------------------------------------------------------------------------- |
|
1705 |
// CContactsUT::?member_function |
|
1706 |
// ?implementation_description |
|
1707 |
// (other items were commented in a header). |
|
1708 |
// ----------------------------------------------------------------------------- |
|
1709 |
// |
|
1710 |
TInt CContactsUT::AddL( CStifItemParser& aItem ) |
|
1711 |
{ |
|
1712 |
__UHEAP_MARK; |
|
1713 |
||
1714 |
// Print to UI |
|
1715 |
_LIT( KContactsTest, "ContactsUT" ); |
|
1716 |
_LIT( KExample, "In Add" ); |
|
1717 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1718 |
// Print to log file |
|
1719 |
iLog->Log( KExample ); |
|
1720 |
||
1721 |
TInt i = 0; |
|
1722 |
TPtrC string; |
|
1723 |
_LIT( KParam, "Param[%i]: %S" ); |
|
1724 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1725 |
{ |
|
1726 |
TestModuleIf().Printf( i, KContactsTest, |
|
1727 |
KParam, i, &string ); |
|
1728 |
i++; |
|
1729 |
} |
|
1730 |
||
1731 |
iErr = KErrNone; |
|
1732 |
||
1733 |
/**Add contact using SAPI Core class*/ |
|
1734 |
||
1735 |
_LIT8(KFirstName,"FirstName"); |
|
1736 |
_LIT(KName,"Sikandar"); |
|
1737 |
_LIT8(KNumber,"MobilePhoneHome"); |
|
1738 |
_LIT(KPhone,"123456"); |
|
1739 |
||
1740 |
//instantiate service class |
|
1741 |
CContactService* serviceHandle = CContactService::NewL(); |
|
1742 |
CleanupStack::PushL(serviceHandle); |
|
1743 |
iLog->Log( KServiceOpen ); |
|
1744 |
||
1745 |
CSingleContact* singleContact = CSingleContact::NewL(); |
|
1746 |
CleanupStack::PushL(singleContact); |
|
1747 |
iLog->Log(_L("single Contact created\n")); |
|
1748 |
||
1749 |
CSingleContactField* nameContactField = CSingleContactField::NewL(); |
|
1750 |
CleanupStack::PushL(nameContactField); |
|
1751 |
iLog->Log(_L("Name Contact Field created \n")); |
|
1752 |
||
1753 |
CSingleContactField* phoneContactField = CSingleContactField::NewL(); |
|
1754 |
CleanupStack::PushL(phoneContactField); |
|
1755 |
iLog->Log(_L("Phone Contact Field created \n")); |
|
1756 |
||
1757 |
nameContactField->SetFieldParamsL(KFirstName,KNullDesC,KName); |
|
1758 |
singleContact->AddFieldToContactL(nameContactField); |
|
1759 |
iLog->Log(_L("Name Contact Field added \n")); |
|
1760 |
||
1761 |
phoneContactField->SetFieldParamsL(KNumber,KNullDesC,KPhone); |
|
1762 |
singleContact->AddFieldToContactL(phoneContactField); |
|
1763 |
iLog->Log(_L("Phone Contact Field added \n")); |
|
1764 |
||
1765 |
//temp |
|
1766 |
||
1767 |
serviceHandle->AddL(this,0,singleContact); |
|
1768 |
CActiveScheduler::Start(); |
|
1769 |
||
1770 |
||
1771 |
||
1772 |
||
1773 |
||
1774 |
||
1775 |
||
1776 |
serviceHandle->AddL(singleContact); |
|
1777 |
iLog->Log(_L("AddL called\n")); |
|
1778 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
1779 |
CleanupStack::Pop(phoneContactField);//singleContactField |
|
1780 |
CleanupStack::Pop(nameContactField);//singleContactField |
|
1781 |
CleanupStack::PopAndDestroy(singleContact);//singleContact |
|
1782 |
||
1783 |
||
1784 |
CContactIter* iter = serviceHandle->GetListL( EContacts,KNullDesC8,KName); |
|
1785 |
||
1786 |
HBufC8* buf = NULL; |
|
1787 |
TInt count = 0; |
|
1788 |
while(ETrue) |
|
1789 |
{ |
|
1790 |
iter->NextL(singleContact,buf); |
|
1791 |
if(!singleContact) |
|
1792 |
{ |
|
1793 |
break; |
|
1794 |
} |
|
1795 |
++count; |
|
1796 |
TInt count(singleContact->FieldCount()); |
|
1797 |
while(count) |
|
1798 |
{ |
|
1799 |
CSingleContactField* field = singleContact->FieldAt(--count); |
|
1800 |
TPtrC8 fieldKey; |
|
1801 |
TPtrC label; |
|
1802 |
TPtrC value; |
|
1803 |
field->GetFieldDataL(fieldKey,label,value); |
|
1804 |
if (fieldKey == KFirstName && value == KName) |
|
1805 |
{ |
|
1806 |
iErr = KErrNone; |
|
1807 |
} |
|
1808 |
} |
|
1809 |
delete singleContact; |
|
1810 |
delete buf; |
|
1811 |
} |
|
1812 |
delete buf; |
|
1813 |
||
1814 |
||
1815 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1816 |
delete iter; |
|
1817 |
iLog->Log( KServiceClose ); |
|
1818 |
__UHEAP_MARKEND; |
|
1819 |
/**end */ |
|
1820 |
||
1821 |
if(iErr) |
|
1822 |
{ |
|
1823 |
return iErr; |
|
1824 |
} |
|
1825 |
||
1826 |
/**Delete using virtual Phonebook */ |
|
1827 |
/* |
|
1828 |
||
1829 |
// Create find operation |
|
1830 |
iOp = iContactManager->MatchPhoneNumberL( |
|
1831 |
KPhone, KPhone().Length(), *this ); |
|
1832 |
CActiveScheduler::Start(); |
|
1833 |
||
1834 |
iErr = KErrGeneral; |
|
1835 |
TInt count(iFindResults->Count()); |
|
1836 |
while(count) |
|
1837 |
{ |
|
1838 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
1839 |
iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count)))); |
|
1840 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
1841 |
CActiveScheduler::Start(); |
|
1842 |
} |
|
1843 |
/**end */ |
|
1844 |
||
1845 |
||
1846 |
return iErr; |
|
1847 |
||
1848 |
} |
|
1849 |
||
1850 |
||
1851 |
// ----------------------------------------------------------------------------- |
|
1852 |
// CContactsUT::AddGroupL |
|
1853 |
// Example test method function. |
|
1854 |
// (other items were commented in a header). |
|
1855 |
// ----------------------------------------------------------------------------- |
|
1856 |
// |
|
1857 |
TInt CContactsUT::AddGroupL( CStifItemParser& aItem ) |
|
1858 |
{ |
|
1859 |
||
1860 |
// Print to UI |
|
1861 |
_LIT( KContactsTest, "ContactsTest" ); |
|
1862 |
_LIT( KExample, "In AddGroup" ); |
|
1863 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1864 |
// Print to log file |
|
1865 |
iLog->Log( KExample ); |
|
1866 |
||
1867 |
TInt i = 0; |
|
1868 |
TPtrC string; |
|
1869 |
_LIT( KParam, "Param[%i]: %S" ); |
|
1870 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1871 |
{ |
|
1872 |
TestModuleIf().Printf( i, KContactsTest, |
|
1873 |
KParam, i, &string ); |
|
1874 |
i++; |
|
1875 |
} |
|
1876 |
||
1877 |
iErr = KErrNone; |
|
1878 |
||
1879 |
/**Add group using SAPI core class */ |
|
1880 |
__UHEAP_MARK; |
|
1881 |
_LIT(KGroup,"Test"); |
|
1882 |
//instantiate service class |
|
1883 |
CContactService* serviceHandle = CContactService::NewL(); |
|
1884 |
CleanupStack::PushL(serviceHandle); |
|
1885 |
iLog->Log( KServiceOpen ); |
|
1886 |
||
1887 |
serviceHandle->AddL(NULL,KNullDesC8,KGroup); |
|
1888 |
iLog->Log(_L("AddL called\n")); |
|
1889 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
1890 |
||
1891 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1892 |
iLog->Log( KServiceClose ); |
|
1893 |
||
1894 |
/**end */ |
|
1895 |
__UHEAP_MARKEND; |
|
1896 |
if(iErr) |
|
1897 |
{ |
|
1898 |
return iErr; |
|
1899 |
} |
|
1900 |
||
1901 |
//Check for the added group using virtual phonebook classes |
|
1902 |
iFindResults = iStore->ContactGroupsLC(); |
|
1903 |
TInt count(iFindResults->Count()); |
|
1904 |
while(count) |
|
1905 |
{ |
|
1906 |
iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
1907 |
iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
1908 |
CActiveScheduler::Start(); |
|
1909 |
||
1910 |
if(iErr) |
|
1911 |
{ |
|
1912 |
break; |
|
1913 |
} |
|
1914 |
iErr = KErrGeneral; |
|
1915 |
iGroup = iStoreContact->Group(); |
|
1916 |
if(!iGroup->GroupLabel().Compare(KGroup)) |
|
1917 |
{ |
|
1918 |
iErr = KErrNone; |
|
1919 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
1920 |
iContactToDelete->AppendL(iResult); |
|
1921 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
1922 |
CActiveScheduler::Start(); |
|
1923 |
break; |
|
1924 |
} |
|
1925 |
} |
|
1926 |
CleanupStack::Pop(); |
|
1927 |
iFindResults = NULL; |
|
1928 |
/**end */ |
|
1929 |
||
1930 |
return iErr; |
|
1931 |
||
1932 |
} |
|
1933 |
||
1934 |
||
1935 |
// ----------------------------------------------------------------------------- |
|
1936 |
// CContactsUT::DeleteL |
|
1937 |
// Example test method function. |
|
1938 |
// (other items were commented in a header). |
|
1939 |
// ----------------------------------------------------------------------------- |
|
1940 |
// |
|
1941 |
TInt CContactsUT::DeleteContactL( CStifItemParser& aItem ) |
|
1942 |
{ |
|
1943 |
__UHEAP_MARK; |
|
1944 |
RPointerArray<TDesC8> idArray; |
|
1945 |
CleanupClosePushL(idArray); |
|
1946 |
CSingleContact* myContact=NULL; |
|
1947 |
||
1948 |
HBufC8* conactId = NULL; |
|
1949 |
||
1950 |
CContactService* serviceHandle = CContactService::NewL(); |
|
1951 |
CleanupStack::PushL(serviceHandle); |
|
1952 |
iLog->Log( KServiceOpen ); |
|
1953 |
||
1954 |
CContactIter* Iter = serviceHandle->GetListL( EContacts ); |
|
1955 |
||
1956 |
Iter->NextL(myContact,conactId); |
|
1957 |
||
1958 |
idArray.AppendL(&conactId->Des()); |
|
1959 |
||
1960 |
serviceHandle->DeleteL(idArray); |
|
1961 |
||
1962 |
iLog->Log(_L("DeleteL called\n")); |
|
1963 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
1964 |
//CActiveScheduler::Start(); |
|
1965 |
||
1966 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
1967 |
CleanupStack::PopAndDestroy(&idArray);//singleContactField |
|
1968 |
delete myContact; |
|
1969 |
delete conactId; |
|
1970 |
delete Iter; |
|
1971 |
iLog->Log( KServiceClose ); |
|
1972 |
__UHEAP_MARKEND; |
|
1973 |
return iErr; |
|
1974 |
||
1975 |
} |
|
1976 |
||
1977 |
// ----------------------------------------------------------------------------- |
|
1978 |
// CContactsUT::DeleteListL |
|
1979 |
// Example test method function. |
|
1980 |
// (other items were commented in a header). |
|
1981 |
// ----------------------------------------------------------------------------- |
|
1982 |
// |
|
1983 |
TInt CContactsUT::DeleteGroupL( CStifItemParser& aItem ) |
|
1984 |
{ |
|
1985 |
||
1986 |
// Print to UI |
|
1987 |
_LIT( KContactsTest, "ContactsTest" ); |
|
1988 |
_LIT( KExample, "In DeleteList" ); |
|
1989 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
1990 |
// Print to log file |
|
1991 |
iLog->Log( KExample ); |
|
1992 |
||
1993 |
TInt i = 0; |
|
1994 |
TPtrC string; |
|
1995 |
_LIT( KParam, "Param[%i]: %S" ); |
|
1996 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
1997 |
{ |
|
1998 |
TestModuleIf().Printf( i, KContactsTest, |
|
1999 |
KParam, i, &string ); |
|
2000 |
i++; |
|
2001 |
} |
|
2002 |
iErr = KErrNone; |
|
2003 |
||
2004 |
/**Add 2 groups using virtual phonebook */ |
|
2005 |
||
2006 |
_LIT(KGroup1,"Test1"); |
|
2007 |
_LIT(KGroup2,"Test2"); |
|
2008 |
iGroup = iStore->CreateNewContactGroupLC(); |
|
2009 |
iGroup->SetGroupLabelL(KGroup1); |
|
2010 |
iOperation = EGroup; |
|
2011 |
iGroup->CommitL(*this); |
|
2012 |
||
2013 |
CActiveScheduler::Start(); |
|
2014 |
CleanupStack::Pop(); |
|
2015 |
||
2016 |
iGroup = iStore->CreateNewContactGroupLC(); |
|
2017 |
iGroup->SetGroupLabelL(KGroup2); |
|
2018 |
iOperation = EGroup; |
|
2019 |
iGroup->CommitL(*this); |
|
2020 |
||
2021 |
CActiveScheduler::Start(); |
|
2022 |
CleanupStack::Pop(); |
|
2023 |
/**end */ |
|
2024 |
||
2025 |
if(iErr) |
|
2026 |
{ |
|
2027 |
return iErr; |
|
2028 |
} |
|
2029 |
||
2030 |
/**Delete the groups using SAPI core class */ |
|
2031 |
||
2032 |
/** Check for the added group using virtual phonebook classes */ |
|
2033 |
||
2034 |
iFindResults = iStore->ContactGroupsLC(); |
|
2035 |
TInt count(iFindResults->Count()); |
|
2036 |
if(count>1) |
|
2037 |
{ |
|
2038 |
HBufC8* groupId; |
|
2039 |
RPointerArray<TDesC8> idArray; |
|
2040 |
CleanupClosePushL(idArray); |
|
2041 |
while(count) |
|
2042 |
{ |
|
2043 |
iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
2044 |
iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
2045 |
CActiveScheduler::Start(); |
|
2046 |
||
2047 |
iGroup = iStoreContact->Group(); |
|
2048 |
if(!iGroup->GroupLabel().Compare(KGroup1) || !iGroup->GroupLabel().Compare(KGroup2)) |
|
2049 |
{ |
|
2050 |
groupId = iResult->PackLC(); |
|
2051 |
idArray.AppendL(groupId); |
|
2052 |
} |
|
2053 |
} |
|
2054 |
TInt num(idArray.Count()); |
|
2055 |
if( num < 2) |
|
2056 |
{ |
|
2057 |
return KErrGeneral; |
|
2058 |
} |
|
2059 |
__UHEAP_MARK; |
|
2060 |
CContactService* serviceHandle = CContactService::NewL(); |
|
2061 |
CleanupStack::PushL(serviceHandle); |
|
2062 |
iLog->Log( KServiceOpen ); |
|
2063 |
||
2064 |
serviceHandle->DeleteL(idArray); |
|
2065 |
iLog->Log(_L("DeleteL called\n")); |
|
2066 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
2067 |
//CActiveScheduler::Start(); |
|
2068 |
||
2069 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
2070 |
__UHEAP_MARKEND; |
|
2071 |
CleanupStack::PopAndDestroy(num);//destroy all contactIds |
|
2072 |
CleanupStack::PopAndDestroy(&idArray);//singleContactField |
|
2073 |
||
2074 |
iLog->Log( KServiceClose ); |
|
2075 |
} |
|
2076 |
CleanupStack::Pop(); |
|
2077 |
iFindResults = NULL; |
|
2078 |
/**end */ |
|
2079 |
||
2080 |
return iErr; |
|
2081 |
||
2082 |
} |
|
2083 |
||
2084 |
// ----------------------------------------------------------------------------- |
|
2085 |
// CContactsUT::ModifyL |
|
2086 |
// Example test method function. |
|
2087 |
// (other items were commented in a header). |
|
2088 |
// ----------------------------------------------------------------------------- |
|
2089 |
// |
|
2090 |
TInt CContactsUT::ModifyL( CStifItemParser& aItem ) |
|
2091 |
{ |
|
2092 |
// Print to UI |
|
2093 |
_LIT( KContactsTest, "ContactsTest" ); |
|
2094 |
_LIT( KExample, "In Modify" ); |
|
2095 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2096 |
// Print to log file |
|
2097 |
iLog->Log( KExample ); |
|
2098 |
||
2099 |
TInt i = 0; |
|
2100 |
TPtrC string; |
|
2101 |
_LIT( KParam, "Param[%i]: %S" ); |
|
2102 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2103 |
{ |
|
2104 |
TestModuleIf().Printf( i, KContactsTest, |
|
2105 |
KParam, i, &string ); |
|
2106 |
i++; |
|
2107 |
} |
|
2108 |
iErr = KErrNone; |
|
2109 |
||
2110 |
/** Add 1 contacts */ |
|
2111 |
||
2112 |
CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
2113 |
CleanupStack::PushL(fieldTypeRefList); |
|
2114 |
||
2115 |
fieldTypeRefList->AppendL( |
|
2116 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
2117 |
fieldTypeRefList->AppendL( |
|
2118 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
2119 |
||
2120 |
// Create first contact |
|
2121 |
iStoreContact = iStore->CreateNewContactLC(); |
|
2122 |
||
2123 |
// Create contact field for contact |
|
2124 |
MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2125 |
// Set contact field data |
|
2126 |
_LIT(KFirstName,"Tenali"); |
|
2127 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
2128 |
// Add the contact field to contact |
|
2129 |
iStoreContact->AddFieldL( field ); |
|
2130 |
CleanupStack::Pop(); // field |
|
2131 |
||
2132 |
// Create contact field for contact |
|
2133 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2134 |
// Set contact field data |
|
2135 |
_LIT(KFirstNumber,"123456"); |
|
2136 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
2137 |
// Add the contact field to contact |
|
2138 |
iStoreContact->AddFieldL( field ); |
|
2139 |
CleanupStack::Pop(); // field |
|
2140 |
||
2141 |
// Commit the new created contact to contact store |
|
2142 |
iStoreContact->CommitL( *this ); |
|
2143 |
CActiveScheduler::Start(); |
|
2144 |
CleanupStack::Pop(); // iStoreContact |
|
2145 |
||
2146 |
CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
2147 |
/** ends */ |
|
2148 |
||
2149 |
/** Retrieve contact ids and modify using SAPI core class */ |
|
2150 |
||
2151 |
// Phone number to be searched for |
|
2152 |
_LIT( KMatchNo, "123456" ); |
|
2153 |
// Create find operation |
|
2154 |
iOp = iContactManager->MatchPhoneNumberL( |
|
2155 |
KMatchNo, KMatchNo().Length(), *this ); |
|
2156 |
||
2157 |
CActiveScheduler::Start(); |
|
2158 |
TInt count(iFindResults->Count()); |
|
2159 |
/**end*/ |
|
2160 |
||
2161 |
/**Modify using SAPI core class*/ |
|
2162 |
||
2163 |
||
2164 |
iBuffer = (const_cast<MVPbkContactLink&>(iFindResults->At(--count))).PackLC(); |
|
2165 |
CleanupStack::Pop();//iBuffer |
|
2166 |
||
2167 |
//__UHEAP_MARK; |
|
2168 |
||
2169 |
iServiceHandle = CContactService::NewL(); |
|
2170 |
iLog->Log( KServiceOpen ); |
|
2171 |
||
2172 |
iOperation = EContact; |
|
2173 |
CContactIter* iter = iServiceHandle->GetListL(EContacts); |
|
2174 |
||
2175 |
||
2176 |
||
2177 |
iErr = KErrGeneral; |
|
2178 |
CSingleContact* singleContact = NULL; |
|
2179 |
HBufC8* buf = NULL; |
|
2180 |
||
2181 |
_LIT(KPhone,"Birbal"); |
|
2182 |
_LIT8(KField,"FirstName"); |
|
2183 |
||
2184 |
while(ETrue) |
|
2185 |
{ |
|
2186 |
// __UHEAP_MARK; |
|
2187 |
iter->NextL(singleContact,buf); |
|
2188 |
if(!singleContact) |
|
2189 |
{ |
|
2190 |
break; |
|
2191 |
} |
|
2192 |
CleanupStack::PushL(singleContact); |
|
2193 |
||
2194 |
if(!buf->Compare(*iBuffer)) |
|
2195 |
{ |
|
2196 |
TInt count(singleContact->FieldCount()); |
|
2197 |
CSingleContactField* field = NULL; |
|
2198 |
while(count) |
|
2199 |
{ |
|
2200 |
TPtrC8 fieldKey; |
|
2201 |
TPtrC label; |
|
2202 |
TPtrC value; |
|
2203 |
field = singleContact->FieldAt(--count); |
|
2204 |
field->GetFieldDataL(fieldKey,label,value); |
|
2205 |
if(!fieldKey.Compare(KField)) |
|
2206 |
{ |
|
2207 |
field->SetFieldParamsL(KField,KNullDesC,KPhone); |
|
2208 |
iLog->Log(_L("Phone Contact Field modified \n")); |
|
2209 |
//__UHEAP_MARK; |
|
2210 |
iServiceHandle->AddL(singleContact); |
|
2211 |
iLog->Log(_L("AddL called\n")); |
|
2212 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
2213 |
// CActiveScheduler::Start(); |
|
2214 |
//__UHEAP_MARKEND; |
|
2215 |
break; |
|
2216 |
} |
|
2217 |
} |
|
2218 |
} |
|
2219 |
||
2220 |
CleanupStack::PopAndDestroy(singleContact); |
|
2221 |
delete buf; |
|
2222 |
} |
|
2223 |
delete buf; |
|
2224 |
delete iter; |
|
2225 |
||
2226 |
CContactIter* iterr = iServiceHandle->GetListL(EContacts,iBuffer->Des()); |
|
2227 |
||
2228 |
while(ETrue) |
|
2229 |
{ |
|
2230 |
//__UHEAP_MARK; |
|
2231 |
iter->NextL(singleContact,buf); |
|
2232 |
if(!singleContact) |
|
2233 |
{ |
|
2234 |
break; |
|
2235 |
} |
|
2236 |
CleanupStack::PushL(singleContact); |
|
2237 |
||
2238 |
if(!buf->Compare(*iBuffer)) |
|
2239 |
{ |
|
2240 |
TInt count(singleContact->FieldCount()); |
|
2241 |
CSingleContactField* field = NULL; |
|
2242 |
while(count) |
|
2243 |
{ |
|
2244 |
TPtrC8 fieldKey; |
|
2245 |
TPtrC label; |
|
2246 |
TPtrC value; |
|
2247 |
field = singleContact->FieldAt(--count); |
|
2248 |
field->GetFieldDataL(fieldKey,label,value); |
|
2249 |
if(fieldKey == KField && value == KPhone) |
|
2250 |
{ |
|
2251 |
iErr = KErrNone; |
|
2252 |
} |
|
2253 |
} |
|
2254 |
} |
|
2255 |
CleanupStack::PopAndDestroy(singleContact); |
|
2256 |
delete buf; |
|
2257 |
} |
|
2258 |
delete buf; |
|
2259 |
iLog->Log(_L("GetListL called\n")); |
|
2260 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
2261 |
//CActiveScheduler::Start(); |
|
2262 |
||
2263 |
delete iServiceHandle;//serviceHandle |
|
2264 |
delete iterr; |
|
2265 |
iServiceHandle = NULL; |
|
2266 |
iLog->Log( KServiceClose ); |
|
2267 |
// __UHEAP_MARKEND; |
|
2268 |
||
2269 |
||
2270 |
||
2271 |
/** ends */ |
|
2272 |
||
2273 |
/**Delete using virtual Phonebook |
|
2274 |
_LIT(KPhone1,"560087"); |
|
2275 |
||
2276 |
// Create find operation |
|
2277 |
iOp = iContactManager->MatchPhoneNumberL( |
|
2278 |
KPhone1, KPhone1().Length(), *this ); |
|
2279 |
CActiveScheduler::Start(); |
|
2280 |
||
2281 |
iErr = KErrGeneral; |
|
2282 |
count = iFindResults->Count(); |
|
2283 |
while(count) |
|
2284 |
{ |
|
2285 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2286 |
iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count)))); |
|
2287 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
2288 |
CActiveScheduler::Start(); |
|
2289 |
} |
|
2290 |
/**end */ |
|
2291 |
||
2292 |
return iErr; |
|
2293 |
||
2294 |
} |
|
2295 |
||
2296 |
// ----------------------------------------------------------------------------- |
|
2297 |
// CContactsUT::ModifyGroupL |
|
2298 |
// Example test method function. |
|
2299 |
// (other items were commented in a header). |
|
2300 |
// ----------------------------------------------------------------------------- |
|
2301 |
// |
|
2302 |
TInt CContactsUT::ModifyGroupL( CStifItemParser& aItem ) |
|
2303 |
{ |
|
2304 |
||
2305 |
// Print to UI |
|
2306 |
_LIT( KContactsTest, "ContactsTest" ); |
|
2307 |
_LIT( KExample, "In ModifyGroup" ); |
|
2308 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2309 |
// Print to log file |
|
2310 |
iLog->Log( KExample ); |
|
2311 |
||
2312 |
TInt i = 0; |
|
2313 |
TPtrC string; |
|
2314 |
_LIT( KParam, "Param[%i]: %S" ); |
|
2315 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2316 |
{ |
|
2317 |
TestModuleIf().Printf( i, KContactsTest, |
|
2318 |
KParam, i, &string ); |
|
2319 |
i++; |
|
2320 |
} |
|
2321 |
iErr = KErrNone; |
|
2322 |
/**Add 1 group using virtual phonebook */ |
|
2323 |
||
2324 |
_LIT(KGroup1,"Modify1"); |
|
2325 |
_LIT(KGroup2,"Modify2"); |
|
2326 |
iGroup = iStore->CreateNewContactGroupLC(); |
|
2327 |
iGroup->SetGroupLabelL(KGroup1); |
|
2328 |
iOperation = EGroup; |
|
2329 |
iGroup->CommitL(*this); |
|
2330 |
||
2331 |
CActiveScheduler::Start(); |
|
2332 |
CleanupStack::Pop(); |
|
2333 |
/**end */ |
|
2334 |
||
2335 |
/** Check for the added group using virtual phonebook classes */ |
|
2336 |
iFindResults = iStore->ContactGroupsLC(); |
|
2337 |
TInt count(iFindResults->Count()); |
|
2338 |
while(count) |
|
2339 |
{ |
|
2340 |
iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
2341 |
iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
2342 |
CActiveScheduler::Start(); |
|
2343 |
||
2344 |
if(iErr) |
|
2345 |
{ |
|
2346 |
break; |
|
2347 |
} |
|
2348 |
iErr = KErrGeneral; |
|
2349 |
iGroup = iStoreContact->Group(); |
|
2350 |
if(!iGroup->GroupLabel().Compare(KGroup1)) |
|
2351 |
{ |
|
2352 |
__UHEAP_MARK; |
|
2353 |
CContactService* serviceHandle = CContactService::NewL(); |
|
2354 |
CleanupStack::PushL(serviceHandle); |
|
2355 |
iLog->Log( KServiceOpen ); |
|
2356 |
||
2357 |
serviceHandle->AddL(NULL,KNullDesC8,KGroup2); |
|
2358 |
iLog->Log(_L("ModifyGroupL called\n")); |
|
2359 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
2360 |
// CActiveScheduler::Start(); |
|
2361 |
||
2362 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
2363 |
iLog->Log( KServiceClose ); |
|
2364 |
__UHEAP_MARKEND; |
|
2365 |
} |
|
2366 |
} |
|
2367 |
CleanupStack::Pop(); |
|
2368 |
iFindResults = NULL; |
|
2369 |
/**end */ |
|
2370 |
||
2371 |
/** Check for the added group using virtual phonebook classes */ |
|
2372 |
iFindResults = iStore->ContactGroupsLC(); |
|
2373 |
count = iFindResults->Count(); |
|
2374 |
while(count) |
|
2375 |
{ |
|
2376 |
iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
2377 |
iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
2378 |
CActiveScheduler::Start(); |
|
2379 |
||
2380 |
if(iErr) |
|
2381 |
{ |
|
2382 |
break; |
|
2383 |
} |
|
2384 |
iErr = KErrGeneral; |
|
2385 |
iGroup = iStoreContact->Group(); |
|
2386 |
if(!iGroup->GroupLabel().Compare(KGroup2)) |
|
2387 |
{ |
|
2388 |
iErr = KErrNone; |
|
2389 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2390 |
iContactToDelete->AppendL(iResult); |
|
2391 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
2392 |
CActiveScheduler::Start(); |
|
2393 |
break; |
|
2394 |
} |
|
2395 |
} |
|
2396 |
CleanupStack::Pop(); |
|
2397 |
iFindResults = NULL; |
|
2398 |
||
2399 |
/**end */ |
|
2400 |
return iErr; |
|
2401 |
||
2402 |
} |
|
2403 |
||
2404 |
// ----------------------------------------------------------------------------- |
|
2405 |
// CContactsUT::OrganiseAddL |
|
2406 |
// Example test method function. |
|
2407 |
// (other items were commented in a header). |
|
2408 |
// ----------------------------------------------------------------------------- |
|
2409 |
// |
|
2410 |
TInt CContactsUT::OrganiseAddL( CStifItemParser& aItem ) |
|
2411 |
{ |
|
2412 |
||
2413 |
// Print to UI |
|
2414 |
_LIT( KContactsTest, "ContactsTest" ); |
|
2415 |
_LIT( KExample, "In OrganiseAdd" ); |
|
2416 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2417 |
// Print to log file |
|
2418 |
iLog->Log( KExample ); |
|
2419 |
||
2420 |
TInt i = 0; |
|
2421 |
TPtrC string; |
|
2422 |
_LIT( KParam, "Param[%i]: %S" ); |
|
2423 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2424 |
{ |
|
2425 |
TestModuleIf().Printf( i, KContactsTest, |
|
2426 |
KParam, i, &string ); |
|
2427 |
i++; |
|
2428 |
} |
|
2429 |
||
2430 |
iErr = KErrNone; |
|
2431 |
||
2432 |
/** Add 1 group */ |
|
2433 |
||
2434 |
_LIT(KGroup,"OrganiseTest1"); |
|
2435 |
iGroup = iStore->CreateNewContactGroupLC(); |
|
2436 |
iGroup->SetGroupLabelL(KGroup); |
|
2437 |
iOperation = EGroup; |
|
2438 |
iGroup->CommitL(*this); |
|
2439 |
||
2440 |
CActiveScheduler::Start(); |
|
2441 |
CleanupStack::Pop(); |
|
2442 |
/** ends */ |
|
2443 |
||
2444 |
||
2445 |
if(iErr) |
|
2446 |
{ |
|
2447 |
return iErr; |
|
2448 |
} |
|
2449 |
||
2450 |
/** Retrieve the group id */ |
|
2451 |
HBufC8* groupId = NULL; |
|
2452 |
iFindResults = iStore->ContactGroupsLC(); |
|
2453 |
TInt count(iFindResults->Count()); |
|
2454 |
iErr = KErrGeneral; |
|
2455 |
while(count) |
|
2456 |
{ |
|
2457 |
iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
2458 |
iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
2459 |
CActiveScheduler::Start(); |
|
2460 |
||
2461 |
iGroup = iStoreContact->Group(); |
|
2462 |
if(!iGroup->GroupLabel().Compare(KGroup)) |
|
2463 |
{ |
|
2464 |
groupId =iResult->PackLC(); |
|
2465 |
CleanupStack::Pop();//groupId |
|
2466 |
break; |
|
2467 |
} |
|
2468 |
} |
|
2469 |
CleanupStack::Pop();//iFindResults |
|
2470 |
CleanupStack::PushL(groupId); |
|
2471 |
iFindResults = NULL; |
|
2472 |
/** ends */ |
|
2473 |
||
2474 |
/** Add 2 contacts */ |
|
2475 |
||
2476 |
CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
2477 |
CleanupStack::PushL(fieldTypeRefList); |
|
2478 |
||
2479 |
fieldTypeRefList->AppendL( |
|
2480 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
2481 |
fieldTypeRefList->AppendL( |
|
2482 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
2483 |
||
2484 |
// Create first contact |
|
2485 |
iStoreContact = iStore->CreateNewContactLC(); |
|
2486 |
||
2487 |
// Create contact field for contact |
|
2488 |
MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2489 |
// Set contact field data |
|
2490 |
_LIT(KFirstName,"Tenali"); |
|
2491 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
2492 |
// Add the contact field to contact |
|
2493 |
iStoreContact->AddFieldL( field ); |
|
2494 |
CleanupStack::Pop(); // field |
|
2495 |
||
2496 |
// Create contact field for contact |
|
2497 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2498 |
// Set contact field data |
|
2499 |
_LIT(KFirstNumber,"24680"); |
|
2500 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
2501 |
// Add the contact field to contact |
|
2502 |
iStoreContact->AddFieldL( field ); |
|
2503 |
CleanupStack::Pop(); // field |
|
2504 |
||
2505 |
// Commit the new created contact to contact store |
|
2506 |
iStoreContact->CommitL( *this ); |
|
2507 |
CActiveScheduler::Start(); |
|
2508 |
CleanupStack::Pop(); // iStoreContact |
|
2509 |
||
2510 |
||
2511 |
// Create second contact |
|
2512 |
iStoreContact = iStore->CreateNewContactLC(); |
|
2513 |
||
2514 |
// Create contact field for contact |
|
2515 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2516 |
// Set contact field data |
|
2517 |
_LIT(KSecondName,"Birbal"); |
|
2518 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondName ); |
|
2519 |
// Add the contact field to contact |
|
2520 |
iStoreContact->AddFieldL( field ); |
|
2521 |
CleanupStack::Pop(); // field |
|
2522 |
||
2523 |
// Create contact field for contact |
|
2524 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2525 |
// Set contact field data |
|
2526 |
_LIT(KSecondNumber,"24680"); |
|
2527 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondNumber ); |
|
2528 |
// Add the contact field to contact |
|
2529 |
iStoreContact->AddFieldL( field ); |
|
2530 |
CleanupStack::Pop(); // field |
|
2531 |
||
2532 |
// Commit the new created contact to contact store |
|
2533 |
iStoreContact->CommitL( *this ); |
|
2534 |
CActiveScheduler::Start(); |
|
2535 |
CleanupStack::Pop(); // iStoreContact |
|
2536 |
||
2537 |
CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
2538 |
/** end */ |
|
2539 |
||
2540 |
||
2541 |
if(iErr) |
|
2542 |
{ |
|
2543 |
return iErr; |
|
2544 |
} |
|
2545 |
||
2546 |
||
2547 |
/** Retrieve the 2 contacts */ |
|
2548 |
||
2549 |
// Phone number to be searched for |
|
2550 |
_LIT( KMatchNo, "24680" ); |
|
2551 |
// Create find operation |
|
2552 |
iOp = iContactManager->MatchPhoneNumberL( |
|
2553 |
KMatchNo, KMatchNo().Length(), *this ); |
|
2554 |
||
2555 |
CActiveScheduler::Start(); |
|
2556 |
count = iFindResults->Count(); |
|
2557 |
/**end*/ |
|
2558 |
||
2559 |
/**Organise using SAPI core class*/ |
|
2560 |
if(count>1 && groupId) |
|
2561 |
{ |
|
2562 |
RPointerArray<TDesC8> idArray; |
|
2563 |
CleanupClosePushL(idArray); |
|
2564 |
TInt num(count); |
|
2565 |
while(count) |
|
2566 |
{ |
|
2567 |
HBufC8* contactId = (const_cast<MVPbkContactLink&>(iFindResults->At(--count))).PackLC(); |
|
2568 |
idArray.AppendL(contactId); |
|
2569 |
} |
|
2570 |
__UHEAP_MARK; |
|
2571 |
CContactService* serviceHandle = CContactService::NewL(); |
|
2572 |
CleanupStack::PushL(serviceHandle); |
|
2573 |
iLog->Log( KServiceOpen ); |
|
2574 |
||
2575 |
serviceHandle->OrganiseGroupsL(*groupId,idArray,ETrue); |
|
2576 |
iLog->Log(_L("OrganiseGroupsL called\n")); |
|
2577 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
2578 |
//CActiveScheduler::Start(); |
|
2579 |
||
2580 |
||
2581 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
2582 |
__UHEAP_MARKEND; |
|
2583 |
CleanupStack::PopAndDestroy(num);//destroy all contactIds |
|
2584 |
CleanupStack::PopAndDestroy(&idArray);//singleContactField |
|
2585 |
||
2586 |
iLog->Log( KServiceClose ); |
|
2587 |
} |
|
2588 |
/** ends */ |
|
2589 |
||
2590 |
||
2591 |
/** Check for the group and delete*/ |
|
2592 |
iFindResults = iStore->ContactGroupsLC(); |
|
2593 |
count = iFindResults->Count(); |
|
2594 |
iErr = KErrGeneral; |
|
2595 |
while(count) |
|
2596 |
{ |
|
2597 |
iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
2598 |
if(!(iResult->PackLC())->Compare(*groupId)) |
|
2599 |
{ |
|
2600 |
iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
2601 |
CActiveScheduler::Start(); |
|
2602 |
||
2603 |
iGroup = iStoreContact->Group(); |
|
2604 |
MVPbkContactLinkArray* linkArray = iGroup->ItemsContainedLC(); |
|
2605 |
iOp = iContactManager->DeleteContactsL( *linkArray, *this ); |
|
2606 |
CActiveScheduler::Start(); |
|
2607 |
CleanupStack::Pop();//linkArray |
|
2608 |
||
2609 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2610 |
iContactToDelete->AppendL(iResult); |
|
2611 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
2612 |
CActiveScheduler::Start(); |
|
2613 |
} |
|
2614 |
CleanupStack::PopAndDestroy(); |
|
2615 |
} |
|
2616 |
CleanupStack::Pop(); |
|
2617 |
iFindResults = NULL; |
|
2618 |
/**end */ |
|
2619 |
CleanupStack::PopAndDestroy(groupId); |
|
2620 |
||
2621 |
return iErr; |
|
2622 |
} |
|
2623 |
||
2624 |
||
2625 |
// ----------------------------------------------------------------------------- |
|
2626 |
// CContactsUT::OrganiseDeleteL |
|
2627 |
// Example test method function. |
|
2628 |
// (other items were commented in a header). |
|
2629 |
// ----------------------------------------------------------------------------- |
|
2630 |
// |
|
2631 |
TInt CContactsUT::OrganiseDeleteL( CStifItemParser& aItem ) |
|
2632 |
{ |
|
2633 |
||
2634 |
// Print to UI |
|
2635 |
_LIT( KContactsTest, "ContactsTest" ); |
|
2636 |
_LIT( KExample, "In OrganiseDelete" ); |
|
2637 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2638 |
// Print to log file |
|
2639 |
iLog->Log( KExample ); |
|
2640 |
||
2641 |
TInt i = 0; |
|
2642 |
TPtrC string; |
|
2643 |
_LIT( KParam, "Param[%i]: %S" ); |
|
2644 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2645 |
{ |
|
2646 |
TestModuleIf().Printf( i, KContactsTest, |
|
2647 |
KParam, i, &string ); |
|
2648 |
i++; |
|
2649 |
} |
|
2650 |
iErr = KErrNone; |
|
2651 |
||
2652 |
/** Add 1 group */ |
|
2653 |
||
2654 |
_LIT(KGroup,"OrganiseTest1"); |
|
2655 |
iGroup = iStore->CreateNewContactGroupLC(); |
|
2656 |
iGroup->SetGroupLabelL(KGroup); |
|
2657 |
iOperation = EGroup; |
|
2658 |
iGroup->CommitL(*this); |
|
2659 |
||
2660 |
CActiveScheduler::Start(); |
|
2661 |
CleanupStack::Pop(); |
|
2662 |
/** ends */ |
|
2663 |
||
2664 |
||
2665 |
if(iErr) |
|
2666 |
{ |
|
2667 |
return iErr; |
|
2668 |
} |
|
2669 |
||
2670 |
||
2671 |
/** Add 2 contacts */ |
|
2672 |
||
2673 |
CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
2674 |
CleanupStack::PushL(fieldTypeRefList); |
|
2675 |
||
2676 |
fieldTypeRefList->AppendL( |
|
2677 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
2678 |
fieldTypeRefList->AppendL( |
|
2679 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
2680 |
||
2681 |
// Create first contact |
|
2682 |
iStoreContact = iStore->CreateNewContactLC(); |
|
2683 |
||
2684 |
// Create contact field for contact |
|
2685 |
MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2686 |
// Set contact field data |
|
2687 |
_LIT(KFirstName,"Tenali"); |
|
2688 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
2689 |
// Add the contact field to contact |
|
2690 |
iStoreContact->AddFieldL( field ); |
|
2691 |
CleanupStack::Pop(); // field |
|
2692 |
||
2693 |
// Create contact field for contact |
|
2694 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2695 |
// Set contact field data |
|
2696 |
_LIT(KFirstNumber,"97531"); |
|
2697 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
2698 |
// Add the contact field to contact |
|
2699 |
iStoreContact->AddFieldL( field ); |
|
2700 |
CleanupStack::Pop(); // field |
|
2701 |
||
2702 |
// Commit the new created contact to contact store |
|
2703 |
iStoreContact->CommitL( *this ); |
|
2704 |
CActiveScheduler::Start(); |
|
2705 |
CleanupStack::Pop(); // iStoreContact |
|
2706 |
||
2707 |
||
2708 |
// Create second contact |
|
2709 |
iStoreContact = iStore->CreateNewContactLC(); |
|
2710 |
||
2711 |
// Create contact field for contact |
|
2712 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2713 |
// Set contact field data |
|
2714 |
_LIT(KSecondName,"Birbal"); |
|
2715 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondName ); |
|
2716 |
// Add the contact field to contact |
|
2717 |
iStoreContact->AddFieldL( field ); |
|
2718 |
CleanupStack::Pop(); // field |
|
2719 |
||
2720 |
// Create contact field for contact |
|
2721 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2722 |
// Set contact field data |
|
2723 |
_LIT(KSecondNumber,"97531"); |
|
2724 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KSecondNumber ); |
|
2725 |
// Add the contact field to contact |
|
2726 |
iStoreContact->AddFieldL( field ); |
|
2727 |
CleanupStack::Pop(); // field |
|
2728 |
||
2729 |
// Commit the new created contact to contact store |
|
2730 |
iStoreContact->CommitL( *this ); |
|
2731 |
CActiveScheduler::Start(); |
|
2732 |
CleanupStack::Pop(); // iStoreContact |
|
2733 |
||
2734 |
CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
2735 |
/** end */ |
|
2736 |
||
2737 |
||
2738 |
if(iErr) |
|
2739 |
{ |
|
2740 |
return iErr; |
|
2741 |
} |
|
2742 |
||
2743 |
/** Retrieve the 2 contacts */ |
|
2744 |
RPointerArray<TDesC8> idArray; |
|
2745 |
CleanupClosePushL(idArray); |
|
2746 |
// Phone number to be searched for |
|
2747 |
_LIT( KMatchNo, "97531" ); |
|
2748 |
// Create find operation |
|
2749 |
iOp = iContactManager->MatchPhoneNumberL( |
|
2750 |
KMatchNo, KMatchNo().Length(), *this ); |
|
2751 |
||
2752 |
CActiveScheduler::Start(); |
|
2753 |
TInt count = iFindResults->Count(); |
|
2754 |
TInt num(count); |
|
2755 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2756 |
while(count) |
|
2757 |
{ |
|
2758 |
iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
2759 |
iContactToDelete->AppendL(iResult); |
|
2760 |
idArray.AppendL(iResult->PackLC()); |
|
2761 |
} |
|
2762 |
/** ends */ |
|
2763 |
||
2764 |
/** Retrieve the group id */ |
|
2765 |
HBufC8* groupId = NULL; |
|
2766 |
iFindResults = iStore->ContactGroupsLC(); |
|
2767 |
count = iFindResults->Count(); |
|
2768 |
iErr = KErrGeneral; |
|
2769 |
while(count) |
|
2770 |
{ |
|
2771 |
iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
2772 |
iOp = iContactManager->RetrieveContactL(*iResult,*this); |
|
2773 |
CActiveScheduler::Start(); |
|
2774 |
||
2775 |
iGroup = iStoreContact->Group(); |
|
2776 |
if(!iGroup->GroupLabel().Compare(KGroup)) |
|
2777 |
{ |
|
2778 |
groupId =iResult->PackLC(); |
|
2779 |
TInt count(iContactToDelete->Count()); |
|
2780 |
while(count) |
|
2781 |
{ |
|
2782 |
iGroup->AddContactL(iContactToDelete->At(--count)); |
|
2783 |
} |
|
2784 |
CleanupStack::Pop(); |
|
2785 |
break; |
|
2786 |
} |
|
2787 |
} |
|
2788 |
CleanupStack::Pop(); |
|
2789 |
CleanupStack::PushL(groupId); |
|
2790 |
iFindResults = NULL; |
|
2791 |
delete iContactToDelete; |
|
2792 |
iContactToDelete = NULL; |
|
2793 |
/** ends */ |
|
2794 |
||
2795 |
/**Organise using SAPI core class*/ |
|
2796 |
if(groupId) |
|
2797 |
{ |
|
2798 |
__UHEAP_MARK; |
|
2799 |
CContactService* serviceHandle = CContactService::NewL(); |
|
2800 |
CleanupStack::PushL(serviceHandle); |
|
2801 |
iLog->Log( KServiceOpen ); |
|
2802 |
||
2803 |
serviceHandle->OrganiseGroupsL(*groupId,idArray,EFalse); |
|
2804 |
iLog->Log(_L("OrganiseGroupsL called\n")); |
|
2805 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
2806 |
//CActiveScheduler::Start(); |
|
2807 |
||
2808 |
||
2809 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
2810 |
||
2811 |
iLog->Log( KServiceClose ); |
|
2812 |
__UHEAP_MARKEND; |
|
2813 |
} |
|
2814 |
/** ends */ |
|
2815 |
||
2816 |
||
2817 |
/** Check for the group */ |
|
2818 |
iFindResults = iStore->ContactGroupsLC(); |
|
2819 |
count = iFindResults->Count(); |
|
2820 |
iErr = KErrGeneral; |
|
2821 |
while(count) |
|
2822 |
{ |
|
2823 |
iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
2824 |
if(!(iResult->PackLC())->Compare(*groupId)) |
|
2825 |
{ |
|
2826 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2827 |
iContactToDelete->AppendL(iResult); |
|
2828 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
2829 |
CActiveScheduler::Start(); |
|
2830 |
} |
|
2831 |
CleanupStack::PopAndDestroy(); |
|
2832 |
} |
|
2833 |
CleanupStack::Pop(); //iFindResults |
|
2834 |
iFindResults = NULL; |
|
2835 |
/**end */ |
|
2836 |
CleanupStack::PopAndDestroy(groupId); |
|
2837 |
CleanupStack::PopAndDestroy(num);//destroy all contactIds |
|
2838 |
CleanupStack::PopAndDestroy(&idArray);//singleContactField |
|
2839 |
||
2840 |
return iErr; |
|
2841 |
} |
|
2842 |
||
2843 |
// ----------------------------------------------------------------------------- |
|
2844 |
// CContactsUT::OrganiseDeleteL |
|
2845 |
// Example test method function. |
|
2846 |
// (other items were commented in a header). |
|
2847 |
// ----------------------------------------------------------------------------- |
|
2848 |
// |
|
2849 |
TInt CContactsUT::ImportL( CStifItemParser& aItem ) |
|
2850 |
{ |
|
2851 |
||
2852 |
// Print to UI |
|
2853 |
_LIT( KContactsTest, "ContactsTest" ); |
|
2854 |
_LIT( KExample, "In Import" ); |
|
2855 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
2856 |
// Print to log file |
|
2857 |
iLog->Log( KExample ); |
|
2858 |
||
2859 |
TInt i = 0; |
|
2860 |
TPtrC string; |
|
2861 |
_LIT( KParam, "Param[%i]: %S" ); |
|
2862 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
2863 |
{ |
|
2864 |
TestModuleIf().Printf( i, KContactsTest, |
|
2865 |
KParam, i, &string ); |
|
2866 |
i++; |
|
2867 |
} |
|
2868 |
iErr = KErrNone; |
|
2869 |
_LIT(KFileName,"c:\\vcardex.vcf"); |
|
2870 |
||
2871 |
/** Add 1 contact */ |
|
2872 |
CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
2873 |
CleanupStack::PushL(fieldTypeRefList); |
|
2874 |
||
2875 |
fieldTypeRefList->AppendL( |
|
2876 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
2877 |
fieldTypeRefList->AppendL( |
|
2878 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
2879 |
||
2880 |
// Create first contact |
|
2881 |
iStoreContact = iStore->CreateNewContactLC(); |
|
2882 |
||
2883 |
// Create contact field for contact |
|
2884 |
MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
2885 |
// Set contact field data |
|
2886 |
_LIT(KFirstName,"Tenali"); |
|
2887 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
2888 |
// Add the contact field to contact |
|
2889 |
iStoreContact->AddFieldL( field ); |
|
2890 |
CleanupStack::Pop(); // field |
|
2891 |
||
2892 |
// Create contact field for contact |
|
2893 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
2894 |
// Set contact field data |
|
2895 |
_LIT(KFirstNumber,"45678"); |
|
2896 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
2897 |
// Add the contact field to contact |
|
2898 |
iStoreContact->AddFieldL( field ); |
|
2899 |
CleanupStack::Pop(); // field |
|
2900 |
||
2901 |
// Commit the new created contact to contact store |
|
2902 |
iStoreContact->CommitL( *this ); |
|
2903 |
CActiveScheduler::Start(); |
|
2904 |
CleanupStack::Pop(); // iStoreContact |
|
2905 |
||
2906 |
CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
2907 |
/** end */ |
|
2908 |
||
2909 |
/** Retrieve the contact */ |
|
2910 |
||
2911 |
// Phone number to be searched for |
|
2912 |
_LIT( KMatchNo, "45678" ); |
|
2913 |
// Create find operation |
|
2914 |
iOp = iContactManager->MatchPhoneNumberL( |
|
2915 |
KMatchNo, KMatchNo().Length(), *this ); |
|
2916 |
||
2917 |
CActiveScheduler::Start(); |
|
2918 |
TInt count = iFindResults->Count(); |
|
2919 |
while(count) |
|
2920 |
{ |
|
2921 |
iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
2922 |
iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
2923 |
||
2924 |
// Create the buffer to store the contact |
|
2925 |
iBuffer = HBufC8::NewL( 1024 ); |
|
2926 |
TPtr8 bufferPtr( iBuffer->Des() ); |
|
2927 |
iDestStream.Open( bufferPtr ); |
|
2928 |
||
2929 |
iOperation = EVCard; |
|
2930 |
||
2931 |
//export the contact from MVPbkContactLink |
|
2932 |
iOp = iVCardEngine->ExportVCardL( iDestStream, *iResult, *this ); |
|
2933 |
CActiveScheduler::Start(); |
|
2934 |
||
2935 |
delete iVCardEngine; |
|
2936 |
iVCardEngine = NULL; |
|
2937 |
||
2938 |
if(iBuffer) |
|
2939 |
{ |
|
2940 |
RFile file; |
|
2941 |
CleanupClosePushL(file); |
|
2942 |
file.Replace(iRfs,KFileName,EFileWrite); |
|
2943 |
file.Write(0,*iBuffer); |
|
2944 |
CleanupStack::PopAndDestroy(&file); |
|
2945 |
delete iBuffer; |
|
2946 |
iBuffer = NULL; |
|
2947 |
} |
|
2948 |
||
2949 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2950 |
iContactToDelete->AppendL(iResult); |
|
2951 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
2952 |
CActiveScheduler::Start(); |
|
2953 |
} |
|
2954 |
iFindResults = NULL; |
|
2955 |
__UHEAP_MARK; |
|
2956 |
//using sapi |
|
2957 |
CContactService* serviceHandle = CContactService::NewL(); |
|
2958 |
CleanupStack::PushL(serviceHandle); |
|
2959 |
iLog->Log( KServiceOpen ); |
|
2960 |
||
2961 |
TFileName file(KFileName); |
|
2962 |
||
2963 |
serviceHandle->ImportVCardToStoreL(file); |
|
2964 |
iLog->Log(_L("ImportVCardToStoreL called\n")); |
|
2965 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
2966 |
// CActiveScheduler::Start(); |
|
2967 |
||
2968 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
2969 |
iLog->Log( KServiceClose ); |
|
2970 |
__UHEAP_MARKEND; |
|
2971 |
/**Delete using virtual Phonebook */ |
|
2972 |
||
2973 |
||
2974 |
// Create find operation |
|
2975 |
iOp = iContactManager->MatchPhoneNumberL( |
|
2976 |
KMatchNo, KMatchNo().Length(), *this ); |
|
2977 |
CActiveScheduler::Start(); |
|
2978 |
iErr = KErrGeneral; |
|
2979 |
count = iFindResults->Count(); |
|
2980 |
while(count) |
|
2981 |
{ |
|
2982 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
2983 |
iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count)))); |
|
2984 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
2985 |
CActiveScheduler::Start(); |
|
2986 |
} |
|
2987 |
/**end */ |
|
2988 |
||
2989 |
return iErr; |
|
2990 |
} |
|
2991 |
// ----------------------------------------------------------------------------- |
|
2992 |
// CContactsUT::OrganiseDeleteL |
|
2993 |
// Example test method function. |
|
2994 |
// (other items were commented in a header). |
|
2995 |
// ----------------------------------------------------------------------------- |
|
2996 |
// |
|
2997 |
TInt CContactsUT::ExportL( CStifItemParser& aItem ) |
|
2998 |
{ |
|
2999 |
||
3000 |
// Print to UI |
|
3001 |
_LIT( KContactsTest, "ContactsTest" ); |
|
3002 |
_LIT( KExample, "In Import" ); |
|
3003 |
TestModuleIf().Printf( 0, KContactsTest, KExample ); |
|
3004 |
// Print to log file |
|
3005 |
iLog->Log( KExample ); |
|
3006 |
||
3007 |
TInt i = 0; |
|
3008 |
TPtrC string; |
|
3009 |
_LIT( KParam, "Param[%i]: %S" ); |
|
3010 |
while ( aItem.GetNextString ( string ) == KErrNone ) |
|
3011 |
{ |
|
3012 |
TestModuleIf().Printf( i, KContactsTest, |
|
3013 |
KParam, i, &string ); |
|
3014 |
i++; |
|
3015 |
} |
|
3016 |
iErr = KErrNone; |
|
3017 |
_LIT(KFileName,"c:\\vcardim.vcf"); |
|
3018 |
RFs fs; |
|
3019 |
CleanupClosePushL(fs); |
|
3020 |
User::LeaveIfError(fs.Connect()); |
|
3021 |
RFile file; |
|
3022 |
if(!file.Open(fs,KFileName,EFileRead)) |
|
3023 |
{ |
|
3024 |
file.Close(); |
|
3025 |
fs.Delete(KFileName); |
|
3026 |
} |
|
3027 |
CleanupStack::PopAndDestroy(&fs); |
|
3028 |
||
3029 |
/** Add 1 contact */ |
|
3030 |
CVPbkFieldTypeRefsList* fieldTypeRefList = CVPbkFieldTypeRefsList::NewL(); |
|
3031 |
CleanupStack::PushL(fieldTypeRefList); |
|
3032 |
||
3033 |
fieldTypeRefList->AppendL( |
|
3034 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_FIRSTNAME ) ); |
|
3035 |
fieldTypeRefList->AppendL( |
|
3036 |
*iContactManager->FieldTypes().Find( R_VPBK_FIELD_TYPE_MOBILEPHONEGEN ) ); |
|
3037 |
||
3038 |
// Create first contact |
|
3039 |
iStoreContact = iStore->CreateNewContactLC(); |
|
3040 |
||
3041 |
// Create contact field for contact |
|
3042 |
MVPbkStoreContactField* field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 0 ) ); |
|
3043 |
// Set contact field data |
|
3044 |
_LIT(KFirstName,"Tenali"); |
|
3045 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstName ); |
|
3046 |
// Add the contact field to contact |
|
3047 |
iStoreContact->AddFieldL( field ); |
|
3048 |
CleanupStack::Pop(); // field |
|
3049 |
||
3050 |
// Create contact field for contact |
|
3051 |
field = iStoreContact->CreateFieldLC( fieldTypeRefList->FieldTypeAt( 1 ) ); |
|
3052 |
// Set contact field data |
|
3053 |
_LIT(KFirstNumber,"214365"); |
|
3054 |
(MVPbkContactFieldTextData::Cast(field->FieldData())).SetTextL( KFirstNumber ); |
|
3055 |
// Add the contact field to contact |
|
3056 |
iStoreContact->AddFieldL( field ); |
|
3057 |
CleanupStack::Pop(); // field |
|
3058 |
||
3059 |
// Commit the new created contact to contact store |
|
3060 |
iStoreContact->CommitL( *this ); |
|
3061 |
CActiveScheduler::Start(); |
|
3062 |
CleanupStack::Pop(); // iStoreContact |
|
3063 |
||
3064 |
CleanupStack::PopAndDestroy(fieldTypeRefList); |
|
3065 |
/** end */ |
|
3066 |
||
3067 |
/** Retrieve the contact */ |
|
3068 |
||
3069 |
// Phone number to be searched for |
|
3070 |
_LIT( KMatchNo, "214365" ); |
|
3071 |
// Create find operation |
|
3072 |
iOp = iContactManager->MatchPhoneNumberL( |
|
3073 |
KMatchNo, KMatchNo().Length(), *this ); |
|
3074 |
||
3075 |
CActiveScheduler::Start(); |
|
3076 |
TInt count = iFindResults->Count(); |
|
3077 |
||
3078 |
iResult = &(const_cast<MVPbkContactLink&>(iFindResults->At(--count))); |
|
3079 |
iBuffer = iResult->PackLC(); |
|
3080 |
CleanupStack::Pop(); |
|
3081 |
// __UHEAP_MARK; |
|
3082 |
//using sapi |
|
3083 |
CContactService* serviceHandle = CContactService::NewL(); |
|
3084 |
CleanupStack::PushL(serviceHandle); |
|
3085 |
iLog->Log( KServiceOpen ); |
|
3086 |
||
3087 |
CSingleContact* myContact=NULL; |
|
3088 |
||
3089 |
HBufC8* conactId = NULL; |
|
3090 |
TFileName filename(KFileName); |
|
3091 |
CContactIter* Iter = serviceHandle->GetListL( EContacts ); |
|
3092 |
||
3093 |
Iter->NextL(myContact,conactId); |
|
3094 |
||
3095 |
serviceHandle->ExportVCardL(filename,conactId->Des()); |
|
3096 |
||
3097 |
delete myContact; |
|
3098 |
delete Iter; |
|
3099 |
iLog->Log(_L("ExportVCardL called\n")); |
|
3100 |
iLog->Log(_L("Start Active Scheduler\n")); |
|
3101 |
//CActiveScheduler::Start(); |
|
3102 |
||
3103 |
CleanupStack::PopAndDestroy(serviceHandle);//serviceHandle |
|
3104 |
iLog->Log( KServiceClose ); |
|
3105 |
// __UHEAP_MARKEND; |
|
3106 |
||
3107 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
3108 |
iContactToDelete->AppendL(iResult); |
|
3109 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
3110 |
CActiveScheduler::Start(); |
|
3111 |
||
3112 |
delete iBuffer; |
|
3113 |
iBuffer = NULL; |
|
3114 |
||
3115 |
RPointerArray< MVPbkStoreContact > importedContacts; |
|
3116 |
CleanupClosePushL(importedContacts); |
|
3117 |
||
3118 |
iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
3119 |
||
3120 |
// Open the RFileReadStream that holds the vCard content |
|
3121 |
iErr = iSource.Open( iRfs, KFileName, EFileRead ); |
|
3122 |
||
3123 |
// Import the contact from RFileReadStream asynchronously |
|
3124 |
// The operation status is reported via MVPbkSingleContactOperationObserver. |
|
3125 |
iOp = iVCardEngine->ImportVCardL( importedContacts, *iStore, iSource, *this ); |
|
3126 |
CActiveScheduler::Start(); |
|
3127 |
||
3128 |
if(!importedContacts.Count()) |
|
3129 |
{ |
|
3130 |
return KErrGeneral; |
|
3131 |
||
3132 |
} |
|
3133 |
||
3134 |
// Close iImportedContacts |
|
3135 |
// |
|
3136 |
importedContacts.ResetAndDestroy(); |
|
3137 |
CleanupStack::PopAndDestroy(&importedContacts); |
|
3138 |
iFindResults = NULL; |
|
3139 |
||
3140 |
/**Delete using virtual Phonebook */ |
|
3141 |
||
3142 |
// Create find operation |
|
3143 |
iOp = iContactManager->MatchPhoneNumberL( |
|
3144 |
KMatchNo, KMatchNo().Length(), *this ); |
|
3145 |
CActiveScheduler::Start(); |
|
3146 |
||
3147 |
count = iFindResults->Count(); |
|
3148 |
while(count) |
|
3149 |
{ |
|
3150 |
iContactToDelete = CVPbkContactLinkArray::NewL(); |
|
3151 |
iContactToDelete->AppendL(&(const_cast<MVPbkContactLink&>(iFindResults->At(--count)))); |
|
3152 |
iOp = iContactManager->DeleteContactsL( *iContactToDelete, *this ); |
|
3153 |
CActiveScheduler::Start() ; |
|
3154 |
} |
|
3155 |
/**end */ |
|
3156 |
||
3157 |
return iErr; |
|
3158 |
} |
|
3159 |
||
3160 |
||
3161 |
||
3162 |
//End of file |