261 |
259 |
262 if(iContactsGroupsMap == NULL) |
260 if(iContactsGroupsMap == NULL) |
263 { |
261 { |
264 iContactsGroupsMap = new(ELeave) RPtrHashMap<TDesC16, MVPbkStoreContact>(); |
262 iContactsGroupsMap = new(ELeave) RPtrHashMap<TDesC16, MVPbkStoreContact>(); |
265 } |
263 } |
266 iContactsGroupsMap->Insert(grpName, iTargetStore); |
264 // iContactsGroupsMap takes the ownership of iTargetStore |
|
265 TInt res = iContactsGroupsMap->Insert(grpName, iTargetStore); |
|
266 if ( res != KErrNone ) |
|
267 { |
|
268 delete iTargetStore; |
|
269 } |
|
270 iTargetStore = NULL; |
267 CleanupStack::Pop(); // To pop up grpName |
271 CleanupStack::Pop(); // To pop up grpName |
268 } |
272 } |
269 } |
273 } |
270 |
274 |
271 CleanupStack::PopAndDestroy(); // To pop up and destroy groupItem |
275 CleanupStack::PopAndDestroy(); // To pop up and destroy groupItem |
272 } |
276 } |
273 |
277 |
274 // ---------------------------------------------------------------------------- |
278 // ---------------------------------------------------------------------------- |
275 // CVPbkGroupCardHandler::DecodeContactGroupInVCardL |
279 // CVPbkGroupCardHandler::DecodeContactGroupInVCardL |
276 // ---------------------------------------------------------------------------- |
280 // ---------------------------------------------------------------------------- |
277 void CVPbkGroupCardHandler::DecodeContactGroupInVCardL(TPtr16 aValue) |
281 void CVPbkGroupCardHandler::DecodeContactGroupInVCardL(TPtr16 aValue, |
|
282 CVPbkGroupCardHandler** aSelfPointer ) |
278 { |
283 { |
279 if(iStore == NULL) |
284 if(iStore == NULL) |
280 return; |
285 return; |
|
286 iSelfPtr = aSelfPointer; |
281 const MVPbkContactLink* contactLink = iStore->CreateLinkLC(); |
287 const MVPbkContactLink* contactLink = iStore->CreateLinkLC(); |
282 |
288 |
283 TInt newLinePos = aValue.Find(KVersitTokencrlf()); |
289 TInt newLinePos = aValue.Find(KVersitTokencrlf()); |
284 |
290 |
285 if (newLinePos != KErrNotFound) |
291 if (newLinePos != KErrNotFound) |
347 aValue = aValue.Right( aValue.Length() - semiColonPos - KSemiColon().Length()); |
364 aValue = aValue.Right( aValue.Length() - semiColonPos - KSemiColon().Length()); |
348 } //End Of While loop |
365 } //End Of While loop |
349 |
366 |
350 CleanupStack::PopAndDestroy(); // For contactLink |
367 CleanupStack::PopAndDestroy(); // For contactLink |
351 |
368 |
352 if(iStore) |
369 if(!destroyed) |
353 { |
370 { |
|
371 iSelfPtr = NULL; |
354 delete iStore; |
372 delete iStore; |
355 iStore = NULL; |
373 iStore = NULL; |
356 } |
374 } |
357 |
375 |
358 } |
376 } |
359 // ---------------------------------------------------------------------------- |
377 // ---------------------------------------------------------------------------- |
360 // CVPbkGroupCardHandler::BuildContactGroupsHashMapL |
378 // CVPbkGroupCardHandler::BuildContactGroupsHashMapL |
361 // ---------------------------------------------------------------------------- |
379 // ---------------------------------------------------------------------------- |
362 void CVPbkGroupCardHandler::BuildContactGroupsHashMapL(MVPbkContactStore& aTargetContactStore) |
380 void CVPbkGroupCardHandler::BuildContactGroupsHashMapL( |
|
381 MVPbkContactStore& aTargetContactStore, |
|
382 CVPbkGroupCardHandler** aSelfPointer) |
363 { |
383 { |
364 //Get all the Group Links in current VPBK |
384 //Get all the Group Links in current VPBK |
365 MVPbkContactLinkArray* groupLinks = aTargetContactStore.ContactGroupsLC(); |
385 MVPbkContactLinkArray* groupLinks = aTargetContactStore.ContactGroupsLC(); |
366 |
386 |
367 if( (groupLinks == NULL || iContactsGroupsMap != NULL)) |
387 if( (groupLinks == NULL || iContactsGroupsMap != NULL)) |
368 return; |
388 return; |
369 |
389 |
|
390 iSelfPtr = aSelfPointer; |
|
391 |
370 iContactsGroupsMap = new(ELeave) RPtrHashMap<TDesC16, MVPbkStoreContact>(); |
392 iContactsGroupsMap = new(ELeave) RPtrHashMap<TDesC16, MVPbkStoreContact>(); |
371 |
393 |
372 TInt groupCount = 0; |
394 TInt groupCount = 0; |
373 groupCount = groupLinks->Count(); |
395 groupCount = groupLinks->Count(); |
374 |
396 |
375 // Get Group Name and Group store, store these values into Hash Table. |
397 // Get Group Name and Group store, store these values into Hash Table. |
376 for(TInt i = 0;i < groupCount;i++) |
398 TBool thisDestroyed = EFalse; |
|
399 for(TInt i = 0;i < groupCount && !thisDestroyed;i++) |
377 { |
400 { |
378 const MVPbkContactLink& groupLink = (*groupLinks)[i]; |
401 const MVPbkContactLink& groupLink = (*groupLinks)[i]; |
379 iData.GetContactManager().RetrieveContactL( groupLink, *this ); |
402 thisDestroyed = RetrieveContactL( groupLink, *this ); |
380 //wait for Retrieve operation to complete, to get storecontact for the current group link |
403 if (!thisDestroyed && iTargetStore) |
381 if( ! (iWait->IsStarted()) ) |
|
382 { |
|
383 iWait->Start(); |
|
384 } |
|
385 |
|
386 if (iTargetStore) |
|
387 { |
404 { |
388 MVPbkContactGroup* contactGrp = iTargetStore->Group(); |
405 MVPbkContactGroup* contactGrp = iTargetStore->Group(); |
389 if(contactGrp) |
406 if(contactGrp) |
390 { |
407 { |
391 TPtrC16 contactGroupName; |
408 TPtrC16 contactGroupName; |
392 contactGroupName.Set( contactGrp->GroupLabel()); |
409 contactGroupName.Set( contactGrp->GroupLabel()); |
393 HBufC16* grpName = contactGroupName.AllocLC(); |
410 HBufC16* grpName = contactGroupName.AllocLC(); |
394 iContactsGroupsMap->Insert(grpName, iTargetStore); |
411 // iContactsGroupsMap takes the ownership of iTargetStore |
|
412 TInt res = iContactsGroupsMap->Insert(grpName, iTargetStore); |
|
413 if ( res != KErrNone ) |
|
414 { |
|
415 delete iTargetStore; |
|
416 } |
|
417 iTargetStore = NULL; |
395 CleanupStack::Pop(); //grpName |
418 CleanupStack::Pop(); //grpName |
396 } |
419 } |
397 } |
420 } |
398 }// End of for loop |
421 }// End of for loop |
399 |
422 |
400 CleanupStack::PopAndDestroy(); //for groupLinks |
423 CleanupStack::PopAndDestroy(); //for groupLinks |
|
424 |
|
425 if ( !thisDestroyed ) |
|
426 { |
|
427 iSelfPtr = NULL; |
|
428 } |
|
429 } |
|
430 |
|
431 // ---------------------------------------------------------------------------- |
|
432 // CVPbkGroupCardHandler::RetrieveContactL |
|
433 // ---------------------------------------------------------------------------- |
|
434 TBool CVPbkGroupCardHandler::RetrieveContactL( const MVPbkContactLink& aLink, |
|
435 MVPbkSingleContactOperationObserver& aObserver) |
|
436 { |
|
437 delete iTargetStore; |
|
438 iTargetStore = NULL; |
|
439 iRetrieveOp = iData.GetContactManager().RetrieveContactL( aLink, aObserver ); |
|
440 |
|
441 TBool destroyed = EFalse; |
|
442 // Set iDestroyed to point to stack variable that is accessed from |
|
443 // destructor. |
|
444 iDestroyed = &destroyed; |
|
445 //wait for GetContactGroupStoreL operation to complete,to get storecontact |
|
446 if( ! (iWait->IsStarted()) ) |
|
447 { |
|
448 iWait->Start(); |
|
449 } |
|
450 |
|
451 if ( !destroyed ) |
|
452 { |
|
453 // Reset pointer to stack variable. |
|
454 iDestroyed = NULL; |
|
455 delete iRetrieveOp; |
|
456 iRetrieveOp = NULL; |
|
457 } |
|
458 return destroyed; |
401 } |
459 } |
402 |
460 |
403 // ---------------------------------------------------------------------------- |
461 // ---------------------------------------------------------------------------- |
404 // CVPbkGroupCardHandler::VPbkSingleContactOperationComplete |
462 // CVPbkGroupCardHandler::VPbkSingleContactOperationComplete |
405 // ---------------------------------------------------------------------------- |
463 // ---------------------------------------------------------------------------- |
406 void CVPbkGroupCardHandler::VPbkSingleContactOperationComplete( |
464 void CVPbkGroupCardHandler::VPbkSingleContactOperationComplete( |
407 MVPbkContactOperationBase& aOperation, |
465 MVPbkContactOperationBase& /*aOperation*/, |
408 MVPbkStoreContact* aContact) |
466 MVPbkStoreContact* aContact) |
409 { |
467 { |
410 iTargetStore = aContact; |
468 iTargetStore = aContact; |
411 |
|
412 MVPbkContactOperationBase* operation = &aOperation; |
|
413 if ( operation ) |
|
414 { |
|
415 delete operation; |
|
416 operation = NULL; |
|
417 } |
|
418 |
469 |
419 if( iWait->IsStarted() ) |
470 if( iWait->IsStarted() ) |
420 iWait->AsyncStop(); |
471 iWait->AsyncStop(); |
421 |
472 |
422 } |
473 } |
423 |
474 |
424 // ---------------------------------------------------------------------------- |
475 // ---------------------------------------------------------------------------- |
425 // CVPbkGroupCardHandler::VPbkSingleContactOperationFailed |
476 // CVPbkGroupCardHandler::VPbkSingleContactOperationFailed |
426 // ---------------------------------------------------------------------------- |
477 // ---------------------------------------------------------------------------- |
427 void CVPbkGroupCardHandler::VPbkSingleContactOperationFailed |
478 void CVPbkGroupCardHandler::VPbkSingleContactOperationFailed |
428 (MVPbkContactOperationBase& aOperation, TInt /*aError*/) |
479 (MVPbkContactOperationBase& /*aOperation*/, TInt /*aError*/) |
429 { |
480 { |
430 iTargetStore = NULL; //To Handle in Error case |
|
431 MVPbkContactOperationBase* operation = &aOperation; |
|
432 if ( operation ) |
|
433 { |
|
434 delete operation; |
|
435 operation = NULL; |
|
436 } |
|
437 |
|
438 if( iWait->IsStarted() ) |
481 if( iWait->IsStarted() ) |
439 iWait->AsyncStop(); |
482 iWait->AsyncStop(); |
440 } |
483 } |
441 |
484 |
442 // ---------------------------------------------------------------------------- |
485 // ---------------------------------------------------------------------------- |
443 // CVPbkGroupCardHandler::GetContactGroupStoreL |
486 // CVPbkGroupCardHandler::GetContactGroupStoreL |
444 // Retrieve the contact store of group contact |
487 // Retrieve the contact store of group contact |
445 // ---------------------------------------------------------------------------- |
488 // ---------------------------------------------------------------------------- |
446 void CVPbkGroupCardHandler::GetContactGroupStoreL(const MVPbkContactLink& aContactLink) |
489 void CVPbkGroupCardHandler::GetContactGroupStoreL( |
447 { |
490 const MVPbkContactLink& aContactLink, |
448 iData.GetContactManager().RetrieveContactL( aContactLink, *this ); |
491 CVPbkGroupCardHandler** aSelfPointer) |
449 //wait for GetContactGroupStoreL operation to complete,to get storecontact |
492 { |
450 if( ! (iWait->IsStarted()) ) |
493 iSelfPtr = aSelfPointer; |
451 { |
494 delete iStore; |
452 iWait->Start(); |
495 iStore = NULL; |
453 } |
496 if ( !RetrieveContactL( aContactLink, *this ) ) |
454 iStore = iTargetStore; |
497 { |
|
498 iSelfPtr = NULL; |
|
499 // iStore takes the ownership. |
|
500 iStore = iTargetStore; |
|
501 iTargetStore = NULL; |
|
502 } |
455 } |
503 } |
456 |
504 |
457 // ---------------------------------------------------------------------------- |
505 // ---------------------------------------------------------------------------- |
458 // CVPbkGroupCardHandler::ContactOperationCompleted |
506 // CVPbkGroupCardHandler::ContactOperationCompleted |
459 // ---------------------------------------------------------------------------- |
507 // ---------------------------------------------------------------------------- |