401 _DBG_FILE("CNSmlContactsDataStore::DoCommitBatchL(): NOT ON BATCH MODE end"); |
506 _DBG_FILE("CNSmlContactsDataStore::DoCommitBatchL(): NOT ON BATCH MODE end"); |
402 return; |
507 return; |
403 } |
508 } |
404 // |
509 // |
405 // Go through Buffer and execute all commands return aResultArray |
510 // Go through Buffer and execute all commands return aResultArray |
406 // If none of commands succeeds KErrGeneral returned as status otherwise KErrNone returned |
|
407 // |
511 // |
408 TInt err = KErrNone; |
512 |
409 |
513 iResultArray = &aResultArray; |
410 TRAPD( leavecode, err = ExecuteBufferL(aResultArray) ); |
514 |
|
515 iIndex = 0; |
|
516 TRAPD( leavecode,ExecuteBufferL() ); |
411 |
517 |
412 if( leavecode != KErrNone ) |
518 if( leavecode != KErrNone ) |
413 { |
519 { |
414 err = leavecode; |
520 User::RequestComplete( iCallerStatus, leavecode ); |
415 } |
521 } |
416 // |
522 |
417 // Empty Buffer |
|
418 // |
|
419 iContactsBufferItemList.ResetAndDestroy(); |
|
420 |
|
421 if( iItemDataAddBatch ) |
|
422 { |
|
423 iItemDataAddBatch->Reset(); |
|
424 } |
|
425 |
|
426 iBatchMode = EFalse; // All data handled |
|
427 User::RequestComplete( iCallerStatus, err ); |
|
428 |
|
429 _DBG_FILE("CNSmlContactsDataStore::DoCommitBatchL(): end"); |
523 _DBG_FILE("CNSmlContactsDataStore::DoCommitBatchL(): end"); |
430 } |
524 } |
431 |
525 |
432 // ---------------------------------------------------------------------------- |
526 // ---------------------------------------------------------------------------- |
433 // void CNSmlContactsDataStore::ExecuteBufferL() |
527 // void CNSmlContactsDataStore::ExecuteBufferL() |
434 // ---------------------------------------------------------------------------- |
528 // ---------------------------------------------------------------------------- |
435 EXPORT_C TInt CNSmlContactsDataStore::ExecuteBufferL(RArray<TInt>& aResultArray) |
529 EXPORT_C void CNSmlContactsDataStore::ExecuteBufferL() |
436 { |
530 { |
437 _DBG_FILE("CNSmlContactsDataStore::ExecuteBufferL()"); |
531 _DBG_FILE("CNSmlContactsDataStore::ExecuteBufferL(): begin"); |
438 return DoExecuteBufferL( aResultArray ); |
532 |
439 } |
533 TInt retCommand( KErrNone ); |
440 |
534 |
|
535 // |
|
536 // Loop through buffered commands |
|
537 // |
|
538 if( iIndex < iContactsBufferItemList.Count()) |
|
539 { |
|
540 |
|
541 if( iContactsBufferItemList[iIndex]->iStatus!= KNSmlNoError ) |
|
542 { |
|
543 retCommand = iContactsBufferItemList[iIndex]->iStatus; |
|
544 } |
|
545 else if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemAdd ) |
|
546 { |
|
547 retCommand = ExecuteAddL(); |
|
548 } |
|
549 else if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemReplace || |
|
550 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemFieldLevelReplace ) |
|
551 { |
|
552 ExecuteUpdateL(); |
|
553 } |
|
554 else if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemMove ) |
|
555 { |
|
556 ExecuteMoveL(); |
|
557 } |
|
558 else if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemDelete || |
|
559 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemSoftDelete ) |
|
560 { |
|
561 ExecuteDeleteL(); |
|
562 } |
|
563 // |
|
564 // Set allready set commands from iContactsBufferItemList |
|
565 // |
|
566 if( ( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemAdd || |
|
567 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemReplace || |
|
568 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemFieldLevelReplace || |
|
569 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemDelete || |
|
570 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemSoftDelete ) && |
|
571 iContactsBufferItemList[iIndex]->iStatus != KNSmlNoError ) |
|
572 { |
|
573 retCommand = iContactsBufferItemList[iIndex]->iStatus; |
|
574 } |
|
575 |
|
576 |
|
577 //if an error occurs when performing any operation |
|
578 //return the error status |
|
579 else if(retCommand!=KErrNone) |
|
580 { |
|
581 User::RequestComplete( iCallerStatus, retCommand ); |
|
582 } |
|
583 |
|
584 iRetCommand = retCommand; |
|
585 } |
|
586 } |
|
587 |
|
588 // ---------------------------------------------------------------------------- |
|
589 // void CNSmlContactsDataStore::ExecuteAddL() |
|
590 // ---------------------------------------------------------------------------- |
|
591 |
|
592 EXPORT_C TInt CNSmlContactsDataStore::ExecuteAddL() |
|
593 { |
|
594 TInt retCommand( KErrNone ); |
|
595 StripPropertyL( iItemDataAddBatch, KVersitTokenUID() ); // Remove UID's from data |
|
596 |
|
597 TInt err( KErrNone ); |
|
598 if(iBatchMode) |
|
599 { |
|
600 TRAP( err,LdoAddItemsL( iItemDataAddBatch, |
|
601 iItemDataAddBatch->Ptr(0).Length()) ); |
|
602 if(err!=KErrNone) |
|
603 { |
|
604 retCommand = err; |
|
605 TInt j = iIndex; |
|
606 while( j < iContactsBufferItemList.Count() ) |
|
607 { |
|
608 if( iContactsBufferItemList[j]->iModType == ENSmlCntItemAdd && |
|
609 iContactsBufferItemList[j]->iStatus == KNSmlNoError ) |
|
610 { |
|
611 iContactsBufferItemList[j]->iStatus = KErrNotSupported; |
|
612 iResultArray->AppendL(KErrNotSupported); |
|
613 } |
|
614 j++; |
|
615 } |
|
616 } |
|
617 } |
|
618 else |
|
619 { |
|
620 const TPtr8 dataPtr = iItemDataAddBatch->Ptr(0); |
|
621 TRAP( err, LdoAddItemL( dataPtr, |
|
622 iContactsBufferItemList[iIndex]->iSize)); |
|
623 if(err!=KErrNone) |
|
624 { |
|
625 retCommand = err; |
|
626 } |
|
627 } |
|
628 return retCommand; |
|
629 } |
|
630 |
|
631 // ---------------------------------------------------------------------------- |
|
632 // void CNSmlContactsDataStore::ExecuteDeleteL() |
|
633 // ---------------------------------------------------------------------------- |
|
634 |
|
635 EXPORT_C void CNSmlContactsDataStore:: ExecuteDeleteL() |
|
636 { |
|
637 |
|
638 if(iBatchMode) |
|
639 { |
|
640 iContactLnks = CVPbkContactLinkArray::NewL(); |
|
641 |
|
642 TInt j=iIndex; |
|
643 while( j < iContactsBufferItemList.Count() ) |
|
644 { |
|
645 if( (iContactsBufferItemList[j]->iModType == ENSmlCntItemDelete || |
|
646 iContactsBufferItemList[j]->iModType == ENSmlCntItemSoftDelete) && |
|
647 iContactsBufferItemList[j]->iStatus == KNSmlNoError ) |
|
648 { |
|
649 TContactItemId id = iContactsBufferItemList[j]->iUid; |
|
650 |
|
651 if( id != 0 ) |
|
652 { |
|
653 MVPbkContactLink* contactLink = iIdConverter->IdentifierToLinkLC(id); |
|
654 //check if the contact link is valid |
|
655 TInt index = iContactViewBase->IndexOfLinkL(*contactLink); |
|
656 if(index != KErrNotFound) |
|
657 { |
|
658 iContactLnks->AppendL(contactLink); |
|
659 } |
|
660 else |
|
661 { |
|
662 iContactsBufferItemList[j]->iStatus = KErrNotFound; |
|
663 } |
|
664 |
|
665 CleanupStack::Pop();//contactLink |
|
666 } |
|
667 else |
|
668 { |
|
669 iContactsBufferItemList[j]->iStatus = KErrNotFound; |
|
670 } |
|
671 } |
|
672 j++; |
|
673 } |
|
674 |
|
675 delete iContactViewBase; |
|
676 iContactViewBase = NULL; |
|
677 |
|
678 iContactManager->DeleteContactsL( *iContactLnks, *this ); |
|
679 iLastOperation = ENSmlDeleteOp; |
|
680 } |
|
681 |
|
682 } |
|
683 |
|
684 // ---------------------------------------------------------------------------- |
|
685 // void CNSmlContactsDataStore::ExecuteUpdateL() |
|
686 // ---------------------------------------------------------------------------- |
|
687 |
|
688 EXPORT_C void CNSmlContactsDataStore::ExecuteUpdateL() |
|
689 { |
|
690 iUid = iContactsBufferItemList[iIndex]->iUid; |
|
691 |
|
692 iDataMod->SetUsedMimeType( iServerMimeType, iServerMimeVersion ); |
|
693 |
|
694 // Check whether merging is needed or not. |
|
695 if( iDataMod->NeedsMerge() ) |
|
696 { |
|
697 iMergeItem = CBufFlat::NewL(64); |
|
698 iWriteStream.Open(*iMergeItem); |
|
699 |
|
700 MVPbkContactLink* contactLink = iIdConverter->IdentifierToLinkLC(iUid); |
|
701 |
|
702 iVCardEngine->ExportVCardForSyncL(iWriteStream,*contactLink,*this); |
|
703 CleanupStack::PopAndDestroy(); |
|
704 |
|
705 iLastOperation = ENSMLUpdateExportOp; |
|
706 } |
|
707 else |
|
708 { |
|
709 LdoUpdateItemL(); |
|
710 } |
|
711 } |
|
712 |
|
713 // ---------------------------------------------------------------------------- |
|
714 // void CNSmlContactsDataStore::ExecuteMoveL |
|
715 // ---------------------------------------------------------------------------- |
|
716 |
|
717 EXPORT_C void CNSmlContactsDataStore::ExecuteMoveL() |
|
718 { |
|
719 // move command is not supported |
|
720 if(!iBatchMode) |
|
721 { |
|
722 ResetBuffer(); |
|
723 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
|
724 } |
|
725 else |
|
726 { |
|
727 iResultArray->AppendL(KErrNotSupported); |
|
728 iIndex++; |
|
729 if(iIndex == iContactsBufferItemList.Count() ) |
|
730 { |
|
731 ResetBuffer(); |
|
732 User::RequestComplete( iCallerStatus, KErrNone ); |
|
733 } |
|
734 else |
|
735 { |
|
736 ExecuteBufferL(); |
|
737 } |
|
738 } |
|
739 } |
441 // ---------------------------------------------------------------------------- |
740 // ---------------------------------------------------------------------------- |
442 // void CNSmlContactsDataStore::DoCancelBatch() |
741 // void CNSmlContactsDataStore::DoCancelBatch() |
443 // ---------------------------------------------------------------------------- |
742 // ---------------------------------------------------------------------------- |
444 EXPORT_C void CNSmlContactsDataStore::DoCancelBatch() |
743 EXPORT_C void CNSmlContactsDataStore::DoCancelBatch() |
445 { |
744 { |
1319 // ---------------------------------------------------------------------------- |
1538 // ---------------------------------------------------------------------------- |
1320 EXPORT_C CDesCArray* CNSmlContactsDataStore::DoListStoresLC() |
1539 EXPORT_C CDesCArray* CNSmlContactsDataStore::DoListStoresLC() |
1321 { |
1540 { |
1322 _DBG_FILE("CNSmlContactsDataStore::DoListStoresLC(): begin"); |
1541 _DBG_FILE("CNSmlContactsDataStore::DoListStoresLC(): begin"); |
1323 |
1542 |
1324 /*CDesCArray* cntStores = new (ELeave) CDesCArrayFlat(1); |
1543 MVPbkContactStoreList& storeList = iContactManager->ContactStoresL(); |
1325 iContactsDataStoreExtension->ListStoresL( cntStores ); |
1544 CDesCArrayFlat* stores = new (ELeave) CDesCArrayFlat(storeList.Count()); |
1326 CleanupStack::PushL( cntStores );*/ |
1545 CleanupStack::PushL( stores ); |
1327 |
1546 |
1328 CDesCArray* array = new (ELeave) CDesCArrayFlat(1); |
1547 TBuf<KVPbhkPrefixLength> phoneDataBasePrefix(KVPbhkSymbianDBPrefix); |
1329 array->AppendL(*iDefaultStoreName); |
1548 |
1330 CleanupStack::PushL( array ); |
1549 for(TInt i=0 ; i< storeList.Count(); i++) |
1331 |
1550 { |
1332 _DBG_FILE("CNSmlContactsDataStore::DoListStoresLC(): end"); |
1551 TBuf<KNSmlDefaultStoreNameMaxSize> currentStore(storeList.At(i).StoreProperties().Uri().UriDes()); |
1333 |
1552 |
1334 return array; |
1553 if(currentStore.Find(phoneDataBasePrefix) == 0)//Check if Symbian Database |
|
1554 { |
|
1555 //For backward compatability with local and remote servers |
|
1556 //The Symbian Db name remains unchanged |
|
1557 //The engine methods that create syncml packet, use this information in Database fields |
|
1558 stores->AppendL(*iPacketStoreName); |
|
1559 } |
|
1560 else//End Symbian Database check |
|
1561 { |
|
1562 stores->AppendL(storeList.At(i).StoreProperties().Uri().UriDes()); |
|
1563 } |
|
1564 } |
|
1565 |
|
1566 _DBG_FILE("CNSmlContactsDataStore::DoListStoresLC(): end"); |
|
1567 |
|
1568 return stores; |
1335 } |
1569 } |
1336 |
1570 |
1337 // ------------------------------------------------------------------------------------------------ |
1571 // ------------------------------------------------------------------------------------------------ |
1338 // TInt CNSmlContactsDataStore::LdoFetchItemL( TSmlDbItemUid& aUid, CBufBase& aItem ) |
1572 // TInt CNSmlContactsDataStore::LdoFetchItemL( TSmlDbItemUid& aUid, CBufBase& aItem ) |
1339 // ------------------------------------------------------------------------------------------------ |
1573 // ------------------------------------------------------------------------------------------------ |
1340 EXPORT_C TInt CNSmlContactsDataStore::LdoFetchItemL( TSmlDbItemUid& aUid, CBufBase& aItem ) |
1574 EXPORT_C void CNSmlContactsDataStore::LdoFetchItemL( TSmlDbItemUid& aUid, CBufBase& aItem ) |
1341 { |
1575 { |
1342 _DBG_FILE("CNSmlContactsDataStore::LdoFetchItemL(): begin"); |
1576 _DBG_FILE("CNSmlContactsDataStore::LdoFetchItemL(): begin"); |
1343 |
1577 |
1344 _DBG_FILE("CNSmlContactsDataStore::FetchItemL(): CContactDatabase::ExportSelectedContactsL() begin"); |
1578 iWriteStream.Open(aItem); |
1345 |
1579 |
1346 TInt err = KErrNone; |
1580 MVPbkContactLink* contactLink = iIdConverter->IdentifierToLinkLC(aUid); |
1347 TInt ret = KErrNone; |
1581 iVCardEngine->ExportVCardForSyncL(iWriteStream,*contactLink,*this); |
1348 |
1582 CleanupStack::PopAndDestroy(); |
1349 TRAP( err, ret = ExportContactsL( TUid::Uid(aUid), aItem ) ); |
1583 |
1350 |
1584 iLastOperation = ENSMLFetchOp; |
1351 if( ret != KErrNone ) |
|
1352 { |
|
1353 DBG_ARGS(_S("CNSmlContactsDataStore::FetchItemL(): Error = %d"), ret); |
|
1354 err = ret; |
|
1355 } |
|
1356 |
|
1357 _DBG_FILE("CNSmlContactsDataStore::FetchItemL(): CContactDatabase::ExportSelectedContactsL() end"); |
|
1358 |
1585 |
1359 _DBG_FILE("CNSmlContactsDataStore::LdoFetchItemL(): end"); |
1586 _DBG_FILE("CNSmlContactsDataStore::LdoFetchItemL(): end"); |
1360 return err; |
1587 |
1361 } |
1588 } |
1362 |
1589 |
1363 // ------------------------------------------------------------------------------------------------ |
1590 // ------------------------------------------------------------------------------------------------ |
1364 // TInt CNSmlContactsDataStore::LdoAddItemL( TSmlDbItemUid& aUid, |
1591 // TInt CNSmlContactsDataStore::LdoAddItemL( TSmlDbItemUid& aUid, |
1365 // const TDesC8& aItem, |
1592 // const TDesC8& aItem, |
1366 // TInt aSize, |
1593 // TInt aSize, |
1367 // TTime& aLastModified ) |
1594 // TTime& aLastModified, |
|
1595 // TBool& aConfidential ) |
1368 // ------------------------------------------------------------------------------------------------ |
1596 // ------------------------------------------------------------------------------------------------ |
1369 EXPORT_C TInt CNSmlContactsDataStore::LdoAddItemL( TSmlDbItemUid& aUid, |
1597 EXPORT_C void CNSmlContactsDataStore::LdoAddItemL( const TDesC8& aItem, |
1370 const TDesC8& aItem, |
1598 TInt aSize) |
1371 TInt aSize, |
|
1372 TTime& aLastModified ) |
|
1373 { |
1599 { |
1374 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemL(): begin"); |
1600 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemL(): begin"); |
1375 |
1601 |
1376 TInt ret( KErrNone ); |
|
1377 |
|
1378 if( !iOpened ) |
1602 if( !iOpened ) |
1379 { |
1603 { |
1380 User::Leave( KErrNotReady ); |
1604 User::Leave( KErrNotReady ); |
1381 } |
1605 } |
1382 |
1606 |
1383 // Is there enough space on drive ? |
1607 // Is there enough space on drive |
1384 if( DriveBelowCriticalLevelL( aSize ) ) |
1608 if( DriveBelowCriticalLevelL( aSize ) ) |
1385 { |
1609 { |
1386 return KErrDiskFull; |
1610 User::Leave( KErrDiskFull ); |
1387 } |
1611 } |
1388 |
1612 |
1389 HBufC8* buf = aItem.AllocLC(); |
1613 iBuf = aItem.AllocLC(); |
1390 StripPropertyL( buf, KVersitTokenUID() ); |
1614 StripPropertyL( iBuf, KVersitTokenUID() ); |
1391 |
1615 |
1392 CArrayFixFlat<TUid>* entryArray = NULL; |
1616 iReadStream.Open( *iBuf ); |
1393 TRAP( ret, entryArray = ImportContactsL( *buf ) ); |
1617 // import a vcard without checking for duplicates |
1394 |
1618 iVCardEngine->ImportVCardForSyncL(*iStore,iReadStream,*this); |
1395 DBG_ARGS(_S("New item to database with return value: '%d'"), ret ); |
1619 iLastOperation = ENSmlAddOp; |
1396 |
1620 CleanupStack::Pop(iBuf); |
1397 if( ret == KErrNone && entryArray != NULL ) |
|
1398 { |
|
1399 CleanupStack::PushL( entryArray ); |
|
1400 if( entryArray->Count() ) |
|
1401 { |
|
1402 TInt err(KErrNone); |
|
1403 TUid tId = entryArray->At( 0 ); |
|
1404 CNsmlContactItem* contactitem = CNsmlContactItem::NewL(); |
|
1405 CleanupStack::PushL( contactitem ); |
|
1406 err = iContactsDataStoreExtension->ReadContactL( tId, contactitem ); |
|
1407 if( err == KErrNone) |
|
1408 { |
|
1409 aLastModified = contactitem->iLastModified; |
|
1410 aUid = tId.iUid; |
|
1411 } |
|
1412 CleanupStack::PopAndDestroy( contactitem ); |
|
1413 } |
|
1414 else |
|
1415 { |
|
1416 ret = KErrNotSupported; |
|
1417 } |
|
1418 CleanupStack::PopAndDestroy( entryArray ); |
|
1419 CleanupStack::PopAndDestroy( buf ); |
|
1420 } |
|
1421 else |
|
1422 { |
|
1423 ret = KErrNotSupported; |
|
1424 CleanupStack::PopAndDestroy( buf ); |
|
1425 } |
|
1426 |
1621 |
1427 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemL(): end"); |
1622 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemL(): end"); |
1428 return ret; |
1623 |
1429 } |
1624 } |
1430 |
|
1431 // ------------------------------------------------------------------------------------------------ |
1625 // ------------------------------------------------------------------------------------------------ |
1432 // TInt CNSmlContactsDataStore::LdoAddItemsL( RArray<TInt>& aUids,CBufBase*& aItems, |
1626 // TInt CNSmlContactsDataStore::LdoAddItemsL( CBufBase*& aItems, |
1433 // TInt aSize, TTime& aLastModified ) |
1627 // TInt aSize) |
1434 // ------------------------------------------------------------------------------------------------ |
1628 // ------------------------------------------------------------------------------------------------ |
1435 EXPORT_C TInt CNSmlContactsDataStore::LdoAddItemsL( RArray<TInt>& aUids, |
1629 EXPORT_C void CNSmlContactsDataStore::LdoAddItemsL( CBufBase*& aItems, |
1436 CBufBase*& aItems, |
1630 TInt aSize) |
1437 TInt aSize, |
1631 { |
1438 TTime& aLastModified ) |
1632 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemL(): begin"); |
1439 { |
1633 |
1440 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemsL(): begin"); |
|
1441 |
|
1442 TInt ret( KErrNone ); |
|
1443 |
|
1444 if( !iOpened ) |
1634 if( !iOpened ) |
1445 { |
1635 { |
1446 User::Leave( KErrNotReady ); |
1636 User::Leave( KErrNotReady ); |
1447 } |
1637 } |
1448 |
1638 |
1449 // Is there enough space on drive ? |
1639 // Is there enough space on drive |
1450 if( DriveBelowCriticalLevelL( aSize ) ) |
1640 if( DriveBelowCriticalLevelL( aSize ) ) |
1451 { |
1641 { |
1452 return KErrDiskFull; |
1642 User::Leave( KErrDiskFull ); |
1453 } |
1643 } |
1454 |
1644 |
1455 CArrayFixFlat<TUid>* entryArray = NULL; |
1645 iReadStream.Open( aItems->Ptr(0) ); |
1456 TRAP( ret, entryArray = ImportContactsL( aItems->Ptr( 0 ) ) ); |
1646 // import vcards without checking for duplicates |
1457 |
1647 iVCardEngine->ImportVCardForSyncL(*iStore,iReadStream,*this); |
1458 DBG_ARGS(_S("New items to database with return value: '%d'"), ret ); |
1648 iLastOperation = ENSmlAddOp; |
1459 |
1649 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemL(): end"); |
1460 if( ret == KErrNone && entryArray != NULL) |
1650 |
1461 { |
1651 } |
1462 CleanupStack::PushL( entryArray ); |
1652 |
1463 if( entryArray->Count() ) |
|
1464 { |
|
1465 TInt i = 0; |
|
1466 while( i < entryArray->Count() ) |
|
1467 { |
|
1468 TUid tId = entryArray->At(i); |
|
1469 if (i == (entryArray->Count()-1) ) // Get last Modified date |
|
1470 { |
|
1471 TInt err(KErrNone); |
|
1472 CNsmlContactItem* contactitem = CNsmlContactItem::NewL(); |
|
1473 CleanupStack::PushL( contactitem ); |
|
1474 err = iContactsDataStoreExtension->ReadContactL( tId, contactitem ); |
|
1475 if( err == KErrNone ) |
|
1476 { |
|
1477 aLastModified = contactitem->iLastModified; |
|
1478 } |
|
1479 CleanupStack::PopAndDestroy( contactitem ); |
|
1480 } |
|
1481 aUids.Append( tId.iUid ); |
|
1482 i++; |
|
1483 } |
|
1484 } |
|
1485 else |
|
1486 { |
|
1487 ret = KErrNotSupported; |
|
1488 } |
|
1489 CleanupStack::PopAndDestroy( entryArray ); |
|
1490 } |
|
1491 else |
|
1492 { |
|
1493 ret = KErrNotSupported; |
|
1494 } |
|
1495 |
|
1496 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemsL(): end"); |
|
1497 return ret; |
|
1498 } |
|
1499 |
|
1500 // ------------------------------------------------------------------------------------------------ |
1653 // ------------------------------------------------------------------------------------------------ |
1501 // TInt CNSmlContactsDataStore::LdoUpdateItemL(TSmlDbItemUid aUid, |
1654 // TInt CNSmlContactsDataStore::LdoUpdateItemL(TSmlDbItemUid aUid, |
1502 // const TDesC8& aItem, |
1655 // const TDesC8& aItem, |
1503 // TInt aSize, |
1656 // TInt aSize, |
1504 // TTime& aLastModified ) |
1657 // TTime& aLastModified ) |
1505 // ------------------------------------------------------------------------------------------------ |
1658 // ------------------------------------------------------------------------------------------------ |
1506 EXPORT_C TInt CNSmlContactsDataStore::LdoUpdateItemL( TSmlDbItemUid aUid, |
1659 EXPORT_C void CNSmlContactsDataStore::LdoUpdateItemL() |
1507 const TDesC8& aItem, |
|
1508 TInt aSize, |
|
1509 TTime& aLastModified ) |
|
1510 { |
1660 { |
1511 _DBG_FILE("CNSmlContactsDataStore::LdoUpdateItemL(): begin"); |
1661 _DBG_FILE("CNSmlContactsDataStore::LdoUpdateItemL(): begin"); |
1512 TInt ret(KErrNone); |
1662 |
1513 |
1663 iBuf = iContactsBufferItemList[iIndex]->iItemData->Ptr(0).AllocLC(); |
1514 // Is there enough space on drive ? |
1664 // Remove UID's from data |
1515 if( DriveBelowCriticalLevelL( aSize) ) |
1665 StripPropertyL( iBuf, KVersitTokenUID() ); |
1516 { |
1666 |
1517 return KErrDiskFull; |
1667 iReadStream.Open( *iBuf ); |
1518 } |
1668 iContactLink = iIdConverter->IdentifierToLinkLC(iUid); |
1519 |
1669 iVCardEngine->ImportVCardMergeL(*iContactLink, *iStore, iReadStream, *this); |
1520 CNsmlContactItem* contactitem = CNsmlContactItem::NewL(); |
1670 |
1521 CleanupStack::PushL( contactitem ); |
1671 CleanupStack::Pop(); |
1522 ret = iContactsDataStoreExtension->ReadContactL( TUid::Uid( aUid ), contactitem ); |
1672 iLastOperation = ENSMLUpdateImportOp; |
1523 |
1673 CleanupStack::Pop(iBuf); |
1524 if( ret != KErrNone ) |
1674 |
1525 { |
|
1526 CleanupStack::PopAndDestroy( contactitem ); |
|
1527 DBG_ARGS(_S("CNSmlContactsDataStore::LdoUpdateItemL(): Error = %d"), ret); |
|
1528 return ret; |
|
1529 } |
|
1530 |
|
1531 // Set mimetype + version |
|
1532 iDataMod->SetUsedMimeType( iServerMimeType, iServerMimeVersion ); |
|
1533 |
|
1534 DBG_DUMP((void*)aItem.Ptr(), aItem.Length(), |
|
1535 _S8("CNSmlContactsDataStore::LdoUpdateItemL(): ReceivedItem:")); |
|
1536 |
|
1537 CBufBase* bItem = LdoMergeLC( aUid, aItem ); |
|
1538 HBufC8* hItemBuf = HBufC8::NewL( bItem->Size() + 80 ); |
|
1539 *hItemBuf = bItem->Ptr(0); |
|
1540 CleanupStack::PopAndDestroy(); // bItem |
|
1541 CleanupStack::PushL( hItemBuf ); |
|
1542 StripPropertyL( hItemBuf, KVersitTokenUID() ); |
|
1543 |
|
1544 TPtr8 hItemPtr( hItemBuf->Des() ); |
|
1545 HBufC8* endPropBuf = HBufC8::NewLC( KVersitTokenEND().Length() + KVersitTokenCRLF().Length() + KVersitTokenColon().Length() ); |
|
1546 TPtr8 endPropPtr( endPropBuf->Des() ); |
|
1547 endPropPtr.Append( KVersitTokenCRLF() ); |
|
1548 endPropPtr.Append( KVersitTokenEND() ); |
|
1549 endPropPtr.Append( KVersitTokenColon() ); |
|
1550 TInt endPos = hItemPtr.Find( endPropPtr ); |
|
1551 if( endPos == KErrNotFound ) |
|
1552 { |
|
1553 User::Leave( KErrNotSupported ); |
|
1554 } |
|
1555 hItemPtr.Insert( endPos, KVersitTokenCRLF() ); |
|
1556 endPos += KVersitTokenCRLF().Length(); |
|
1557 hItemPtr.Insert( endPos, KVersitTokenUID() ); |
|
1558 endPos += KVersitTokenUID().Length(); |
|
1559 hItemPtr.Insert( endPos, KVersitTokenColon() ); |
|
1560 endPos += KVersitTokenColon().Length(); |
|
1561 hItemPtr.Insert( endPos, *contactitem->iGuid ); |
|
1562 |
|
1563 DBG_DUMP((void*)hItemPtr.Ptr(), hItemPtr.Length(), |
|
1564 _S8("CNSmlContactsDataStore::LdoUpdateItemL(): MergedItem:")); |
|
1565 |
|
1566 CleanupStack::PopAndDestroy( endPropBuf ); |
|
1567 |
|
1568 // TODO: Get it reviewed |
|
1569 CArrayFixFlat<TUid>* entryArray = NULL; |
|
1570 TRAP( ret, entryArray = ImportContactsL( hItemPtr ) ); |
|
1571 |
|
1572 if( ret == KErrNone && entryArray != NULL) |
|
1573 { |
|
1574 CleanupStack::PushL( entryArray ); |
|
1575 if( !entryArray->Count() ) |
|
1576 { |
|
1577 ret = KErrNotSupported; |
|
1578 } |
|
1579 else |
|
1580 { |
|
1581 TInt err(KErrNone); |
|
1582 TUid tId = TUid::Uid( aUid ); |
|
1583 CNsmlContactItem* updatedContactitem = CNsmlContactItem::NewL(); |
|
1584 CleanupStack::PushL( updatedContactitem ); |
|
1585 err = iContactsDataStoreExtension->ReadContactL( tId, contactitem ); |
|
1586 if( err == KErrNone) |
|
1587 { |
|
1588 aLastModified = updatedContactitem->iLastModified; |
|
1589 } |
|
1590 CleanupStack::PopAndDestroy( updatedContactitem ); // updatedContact |
|
1591 } |
|
1592 CleanupStack::PopAndDestroy(3); // contactitem, hItemBuf, entryArray |
|
1593 } |
|
1594 else |
|
1595 { |
|
1596 ret = KErrNotSupported; |
|
1597 CleanupStack::PopAndDestroy(2); // contactitem, hItemBuf |
|
1598 } |
|
1599 |
|
1600 iFieldLevelReplace = EFalse; |
|
1601 _DBG_FILE("CNSmlContactsDataStore::LdoUpdateItemL(): end"); |
1675 _DBG_FILE("CNSmlContactsDataStore::LdoUpdateItemL(): end"); |
1602 return ret; |
1676 |
1603 } |
1677 } |
1604 |
1678 |
1605 // ------------------------------------------------------------------------------------------------ |
|
1606 // CBufBase* CNSmlContactsDataStore::LdoMergeLC( TSmlDbItemUid& aUid, const TDesC8& aItem ) |
|
1607 // ------------------------------------------------------------------------------------------------ |
|
1608 EXPORT_C CBufBase* CNSmlContactsDataStore::LdoMergeLC( TSmlDbItemUid& aUid, const TDesC8& aItem ) |
|
1609 { |
|
1610 _DBG_FILE("CNSmlContactsDataStore::LdoMergeLC(): begin"); |
|
1611 CBufFlat* b = CBufFlat::NewL(64); |
|
1612 CleanupStack::PushL( b ); |
|
1613 b->InsertL( 0, aItem ); |
|
1614 |
|
1615 if( iDataMod->NeedsMerge() ) |
|
1616 { |
|
1617 CBufFlat* mergeItem = CBufFlat::NewL(64); |
|
1618 CleanupStack::PushL( mergeItem ); |
|
1619 if( LdoFetchItemL( aUid, *mergeItem) == KErrNone ) |
|
1620 { |
|
1621 iDataMod->MergeRxL( *b, *mergeItem, iFieldLevelReplace ); |
|
1622 } |
|
1623 CleanupStack::PopAndDestroy(); // mergeItem |
|
1624 } |
|
1625 |
|
1626 _DBG_FILE("CNSmlContactsDataStore::LdoMergeLC(): end"); |
|
1627 return b; |
|
1628 } |
|
1629 |
1679 |
1630 // ------------------------------------------------------------------------------------------------ |
1680 // ------------------------------------------------------------------------------------------------ |
1631 // CNSmlContactsDataStore::DriveBelowCriticalLevelL() |
1681 // CNSmlContactsDataStore::DriveBelowCriticalLevelL() |
1632 // ------------------------------------------------------------------------------------------------ |
1682 // ------------------------------------------------------------------------------------------------ |
1633 EXPORT_C TBool CNSmlContactsDataStore::DriveBelowCriticalLevelL( TInt aSize ) |
1683 EXPORT_C TBool CNSmlContactsDataStore::DriveBelowCriticalLevelL( TInt aSize ) |
1756 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): property removed"); |
1805 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): property removed"); |
1757 } |
1806 } |
1758 CleanupStack::PopAndDestroy(); // propBuf |
1807 CleanupStack::PopAndDestroy(); // propBuf |
1759 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): end"); |
1808 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): end"); |
1760 } |
1809 } |
|
1810 |
|
1811 // ---------------------------------------------------------------------------- |
|
1812 // CNSmlContactsDataStore::IsConfidentialL |
|
1813 // ---------------------------------------------------------------------------- |
|
1814 // |
|
1815 EXPORT_C TBool CNSmlContactsDataStore::IsConfidentialL( MVPbkStoreContact& aItem ) |
|
1816 { |
|
1817 _DBG_FILE("CNSmlContactsDataStore::IsConfidentialL(): begin"); |
|
1818 TBool ret( EFalse ); |
|
1819 |
|
1820 //find X-CLASS field type |
|
1821 const MVPbkFieldType* syncclass = |
|
1822 iContactManager->FieldTypes().Find(R_VPBK_FIELD_TYPE_SYNCCLASS ); |
|
1823 CVPbkBaseContactFieldTypeIterator* itr = |
|
1824 CVPbkBaseContactFieldTypeIterator::NewLC( *syncclass, |
|
1825 aItem.Fields() ); |
|
1826 while ( itr->HasNext() ) |
|
1827 { |
|
1828 const MVPbkBaseContactField* field = itr->Next(); |
|
1829 const MVPbkContactFieldTextData& data = MVPbkContactFieldTextData::Cast(field->FieldData()); |
|
1830 TPtrC ptr = data.Text(); |
|
1831 //compare the sync type |
|
1832 if ( ptr.Compare( KNSmlContactSyncNoSync ) == 0 ) |
|
1833 { |
|
1834 _DBG_FILE("CNSmlContactsDataStore::IsConfidentialL(): \ |
|
1835 find confidential"); |
|
1836 ret = ETrue; |
|
1837 } |
|
1838 |
|
1839 } |
|
1840 CleanupStack::PopAndDestroy( itr ); |
|
1841 |
|
1842 _DBG_FILE("CNSmlContactsDataStore::IsConfidentialL(): end"); |
|
1843 return ret; |
|
1844 } |
|
1845 |
|
1846 // ---------------------------------------------------------------------------- |
|
1847 // CNSmlContactsDataStore::ResetBuffer |
|
1848 // ---------------------------------------------------------------------------- |
|
1849 // |
|
1850 EXPORT_C void CNSmlContactsDataStore:: ResetBuffer() |
|
1851 { |
|
1852 if( iItemDataAddBatch ) |
|
1853 { |
|
1854 iItemDataAddBatch->Reset(); |
|
1855 } |
|
1856 iContactsBufferItemList.ResetAndDestroy(); |
|
1857 } |
|
1858 // ----------------------------------------------------------------------------- |
|
1859 // From MVPbkContactStoreListObserver |
|
1860 // Called when a contact store is ready to use. |
|
1861 // ----------------------------------------------------------------------------- |
|
1862 |
|
1863 EXPORT_C void CNSmlContactsDataStore::StoreReady( MVPbkContactStore& /*aContactStore*/ ) |
|
1864 { |
|
1865 _DBG_FILE("CNSmlContactsDataStore::StoreReady(): begin"); |
|
1866 //The contact data base opened successfully |
|
1867 iOpened = ETrue; |
|
1868 //id to uniquely identify the opened store |
|
1869 iOpenedStoreId = DefaultHash::Des16( |
|
1870 iStore->StoreProperties().Uri().UriDes()); |
|
1871 |
|
1872 TRAPD(error, iContactsModsFetcher->FetchModificationsL( *iCallerStatus )); |
|
1873 if(error != KErrNone) |
|
1874 { |
|
1875 User::RequestComplete( iCallerStatus, error ); |
|
1876 } |
|
1877 _DBG_FILE("CNSmlContactsDataStore::StoreReady(): end"); |
|
1878 } |
|
1879 |
|
1880 |
|
1881 // --------------------------------------------------------------------------- |
|
1882 // From MVPbkContactStoreListObserver |
|
1883 // Called when a contact store becomes unavailable. |
|
1884 // --------------------------------------------------------------------------- |
|
1885 // |
|
1886 EXPORT_C void CNSmlContactsDataStore::StoreUnavailable( |
|
1887 MVPbkContactStore& /*aContactStore*/, |
|
1888 TInt aReason ) |
|
1889 { |
|
1890 _DBG_FILE("CNSmlContactsDataStore::StoreUnavailable(): begin"); |
|
1891 |
|
1892 //Unable open the default contact data base |
|
1893 iOpened = EFalse; |
|
1894 delete iStoreName; |
|
1895 iStoreName = NULL; |
|
1896 iOpenedStoreId = 0; |
|
1897 User::RequestComplete( iCallerStatus, aReason ); |
|
1898 _DBG_FILE("CNSmlContactsDataStore::StoreUnavailable(): end"); |
|
1899 return; |
|
1900 |
|
1901 } |
|
1902 |
|
1903 // --------------------------------------------------------------------------- |
|
1904 // From MVPbkContactStoreListObserver |
|
1905 // --------------------------------------------------------------------------- |
|
1906 // |
|
1907 EXPORT_C void CNSmlContactsDataStore::HandleStoreEventL( |
|
1908 MVPbkContactStore& /*aContactStore*/, |
|
1909 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
1910 { |
|
1911 //Indication not needed. |
|
1912 } |
|
1913 |
|
1914 // --------------------------------------------------------------------------- |
|
1915 // CNSmlContactsDataStore::VPbkSingleContactOperationComplete |
|
1916 // --------------------------------------------------------------------------- |
|
1917 // |
|
1918 EXPORT_C void CNSmlContactsDataStore::VPbkSingleContactOperationComplete( |
|
1919 MVPbkContactOperationBase& aOperation, |
|
1920 MVPbkStoreContact* aContact ) |
|
1921 { |
|
1922 MVPbkContactOperationBase* operation = &aOperation; |
|
1923 if ( operation ) |
|
1924 { |
|
1925 delete operation; |
|
1926 operation = NULL; |
|
1927 } |
|
1928 TRAPD(error ,SingleContactOperationCompleteL(aContact)); |
|
1929 delete aContact; |
|
1930 if(error!= KErrNone) |
|
1931 { |
|
1932 User::RequestComplete( iCallerStatus, error ); |
|
1933 } |
|
1934 } |
|
1935 |
|
1936 // --------------------------------------------------------------------------- |
|
1937 // CNSmlContactsDataStore::VPbkSingleContactOperationFailed |
|
1938 // --------------------------------------------------------------------------- |
|
1939 // |
|
1940 EXPORT_C void CNSmlContactsDataStore::VPbkSingleContactOperationFailed( |
|
1941 MVPbkContactOperationBase& aOperation, |
|
1942 TInt aError ) |
|
1943 { |
|
1944 MVPbkContactOperationBase* operation = &aOperation; |
|
1945 if ( operation ) |
|
1946 { |
|
1947 delete operation; |
|
1948 operation = NULL; |
|
1949 } |
|
1950 |
|
1951 if(iLastOperation == ENSMLFetchOp) |
|
1952 { |
|
1953 iWriteStream.Close(); |
|
1954 User::RequestComplete( iCallerStatus, aError ); |
|
1955 } |
|
1956 else if (iLastOperation == ENSMLUpdateExportOp) |
|
1957 { |
|
1958 iWriteStream.Close(); |
|
1959 delete iMergeItem; |
|
1960 iMergeItem = NULL; |
|
1961 User::RequestComplete( iCallerStatus, aError ); |
|
1962 } |
|
1963 else if (iLastOperation == ENSMLUpdateImportOp) |
|
1964 { |
|
1965 if(iBatchMode) |
|
1966 { |
|
1967 iResultArray->Append( aError ); |
|
1968 } |
|
1969 delete iContactLink; |
|
1970 iContactLink = NULL; |
|
1971 delete iBuf; |
|
1972 iBuf = NULL; |
|
1973 iReadStream.Close(); |
|
1974 iIndex++; |
|
1975 if(iIndex == iContactsBufferItemList.Count() ) |
|
1976 { |
|
1977 ResetBuffer(); |
|
1978 User::RequestComplete( iCallerStatus, aError ); |
|
1979 } |
|
1980 else |
|
1981 { |
|
1982 _DBG_FILE("VPbkSingleContactOperationFailed, Continuing to complete the Batch Operation"); |
|
1983 ExecuteBufferL(); |
|
1984 } |
|
1985 } |
|
1986 else if(iLastOperation == ENSmlRetrieveOp) |
|
1987 { |
|
1988 iRetrieveCount--; |
|
1989 if(iBatchMode) |
|
1990 { |
|
1991 iResultArray->AppendL( aError ); |
|
1992 } |
|
1993 iIndex++; |
|
1994 if(iIndex == iContactsBufferItemList.Count() ) |
|
1995 { |
|
1996 ResetBuffer(); |
|
1997 User::RequestComplete( iCallerStatus, aError ); |
|
1998 } |
|
1999 else if(!iRetrieveCount) |
|
2000 { |
|
2001 _DBG_FILE("VPbkSingleContactOperationFailed, Continuing to complete the Batch Operation"); |
|
2002 ExecuteBufferL(); |
|
2003 } |
|
2004 } |
|
2005 else |
|
2006 { |
|
2007 _DBG_FILE("VPbkSingleContactOperationFailed, No Matching LastOperation Completing the Operation"); |
|
2008 User::RequestComplete( iCallerStatus, aError ); |
|
2009 } |
|
2010 _DBG_FILE("CNSmlContactsDataStore::VPbkSingleContactOperationFailed(): end"); |
|
2011 } |
|
2012 // --------------------------------------------------------------------------- |
|
2013 // CNSmlContactsDataStore::VPbkSingleContactOperationFailed |
|
2014 // --------------------------------------------------------------------------- |
|
2015 // |
|
2016 EXPORT_C void CNSmlContactsDataStore::SingleContactOperationCompleteL( |
|
2017 MVPbkStoreContact* aContact) |
|
2018 { |
|
2019 if(iLastOperation == ENSMLFetchOp) |
|
2020 { |
|
2021 iWriteStream.Close(); |
|
2022 |
|
2023 iItemData->Compress(); |
|
2024 //strip the fields not supported by server |
|
2025 iDataMod->StripTxL( *iItemData ); |
|
2026 *iSize = iItemData->Size(); |
|
2027 iState = ENSmlItemOpen; |
|
2028 if ( iServerMaxObjectSize == 0 || *iSize <= iServerMaxObjectSize ) |
|
2029 { |
|
2030 User::RequestComplete( iCallerStatus, KErrNone ); |
|
2031 } |
|
2032 else |
|
2033 { |
|
2034 User::RequestComplete( iCallerStatus, KErrTooBig ); |
|
2035 } |
|
2036 } |
|
2037 else if (iLastOperation == ENSMLUpdateExportOp) |
|
2038 { |
|
2039 iDataMod->MergeRxL( *iContactsBufferItemList[iIndex]->iItemData, |
|
2040 *iMergeItem, iFieldLevelReplace ); |
|
2041 iWriteStream.Close(); |
|
2042 delete iMergeItem; |
|
2043 iMergeItem = NULL; |
|
2044 LdoUpdateItemL(); |
|
2045 } |
|
2046 else if (iLastOperation == ENSMLUpdateImportOp) |
|
2047 { |
|
2048 iFieldLevelReplace = EFalse; |
|
2049 |
|
2050 if(!IsConfidentialL(*aContact)) |
|
2051 { |
|
2052 TInt32 id = iIdConverter->LinkToIdentifier(*aContact->CreateLinkLC()); |
|
2053 |
|
2054 TNSmlSnapshotItem item(id); |
|
2055 |
|
2056 MVPbkStoreContact2* tempContact = |
|
2057 reinterpret_cast<MVPbkStoreContact2*> (aContact->StoreContactExtension (KMVPbkStoreContactExtension2Uid)); |
|
2058 |
|
2059 MVPbkStoreContactProperties *contactProterties |
|
2060 = tempContact ->PropertiesL();; |
|
2061 CleanupDeletePushL(contactProterties); |
|
2062 item.SetLastChangedDate(contactProterties->LastModifiedL()); |
|
2063 CleanupStack::PopAndDestroy(); |
|
2064 |
|
2065 item.SetSoftDelete( EFalse ); |
|
2066 |
|
2067 TRAP_IGNORE(iChangeFinder->ItemUpdatedL( item )); |
|
2068 |
|
2069 CleanupStack::PopAndDestroy(); |
|
2070 if(iBatchMode) |
|
2071 { |
|
2072 iResultArray->Append(KErrNone); |
|
2073 } |
|
2074 |
|
2075 delete iContactLink; |
|
2076 iContactLink = NULL; |
|
2077 |
|
2078 delete iBuf; |
|
2079 iBuf = NULL; |
|
2080 iReadStream.Close(); |
|
2081 |
|
2082 iIndex++; |
|
2083 if(iIndex == iContactsBufferItemList.Count() ) |
|
2084 { |
|
2085 ResetBuffer(); |
|
2086 User::RequestComplete( iCallerStatus, iRetCommand ); |
|
2087 } |
|
2088 else |
|
2089 { |
|
2090 ExecuteBufferL(); |
|
2091 } |
|
2092 } |
|
2093 |
|
2094 } |
|
2095 else if(iLastOperation == ENSmlRetrieveOp) |
|
2096 { |
|
2097 iRetrieveCount--; |
|
2098 if(!IsConfidentialL(*aContact)) |
|
2099 { |
|
2100 TInt32 id = iIdConverter->LinkToIdentifier(*aContact->CreateLinkLC()); |
|
2101 *iContactsBufferItemList[iIndex]->iPUid = id; |
|
2102 |
|
2103 TNSmlSnapshotItem item(id); |
|
2104 |
|
2105 MVPbkStoreContact2* tempContact = |
|
2106 reinterpret_cast<MVPbkStoreContact2*> (aContact->StoreContactExtension (KMVPbkStoreContactExtension2Uid)); |
|
2107 |
|
2108 MVPbkStoreContactProperties *contactProterties |
|
2109 = tempContact ->PropertiesL();; |
|
2110 CleanupDeletePushL(contactProterties); |
|
2111 item.SetLastChangedDate(contactProterties->LastModifiedL()); |
|
2112 CleanupStack::PopAndDestroy(); |
|
2113 |
|
2114 item.SetSoftDelete( EFalse ); |
|
2115 // Add the snapshot item to the Change Finder. |
|
2116 TRAP_IGNORE(iChangeFinder->ItemAddedL( item )); |
|
2117 |
|
2118 CleanupStack::PopAndDestroy(); |
|
2119 } |
|
2120 if(iBatchMode) |
|
2121 { |
|
2122 iResultArray->AppendL(iRetCommand); |
|
2123 } |
|
2124 |
|
2125 iIndex++; |
|
2126 if(iIndex == iContactsBufferItemList.Count() ) |
|
2127 { |
|
2128 ResetBuffer(); |
|
2129 User::RequestComplete( iCallerStatus, iRetCommand ); |
|
2130 } |
|
2131 else if(!iRetrieveCount) |
|
2132 { |
|
2133 ExecuteBufferL(); |
|
2134 } |
|
2135 |
|
2136 } |
|
2137 } |
|
2138 // --------------------------------------------------------------------------- |
|
2139 // CNSmlContactsDataStore::ContactsSaved. |
|
2140 // --------------------------------------------------------------------------- |
|
2141 // |
|
2142 EXPORT_C void CNSmlContactsDataStore::ContactsSaved( |
|
2143 MVPbkContactOperationBase& aOperation, |
|
2144 MVPbkContactLinkArray* aResults ) |
|
2145 { |
|
2146 MVPbkContactOperationBase* operation = &aOperation; |
|
2147 if ( operation ) |
|
2148 { |
|
2149 delete operation; |
|
2150 operation = NULL; |
|
2151 } |
|
2152 |
|
2153 if(iLastOperation == ENSmlAddOp) |
|
2154 { |
|
2155 //Count of contacts to be added from server to client |
|
2156 TInt cntAddCount( 0 ); |
|
2157 TInt i(iIndex); |
|
2158 while( i<iContactsBufferItemList.Count() ) |
|
2159 { |
|
2160 if ( iContactsBufferItemList[i]->iModType == ENSmlCntItemAdd && |
|
2161 iContactsBufferItemList[i]->iStatus == KNSmlNoError ) |
|
2162 { |
|
2163 cntAddCount++; |
|
2164 } |
|
2165 i++; |
|
2166 } |
|
2167 |
|
2168 //Count of contacts successfully added to client |
|
2169 iRetrieveCount = aResults->Count(); |
|
2170 |
|
2171 //Count of contacts which could not be added |
|
2172 TInt cntAddFailedCount(0); |
|
2173 cntAddFailedCount = cntAddCount-iRetrieveCount; |
|
2174 while(cntAddFailedCount > 0) |
|
2175 { |
|
2176 iContactsBufferItemList[iIndex++]->iStatus = KErrGeneral; |
|
2177 iResultArray->Append(KErrGeneral); |
|
2178 cntAddFailedCount--; |
|
2179 } |
|
2180 |
|
2181 if ( aResults->Count() > 0 ) |
|
2182 { |
|
2183 for(TInt i=0;i<aResults->Count();i++) |
|
2184 { |
|
2185 //retrieve the contact |
|
2186 TRAPD(error,iContactManager->RetrieveContactL( aResults->At(i), *this )); |
|
2187 if(error != KErrNone) |
|
2188 { |
|
2189 User::RequestComplete( iCallerStatus, error ); |
|
2190 } |
|
2191 iLastOperation = ENSmlRetrieveOp; |
|
2192 } |
|
2193 } |
|
2194 delete iBuf; |
|
2195 delete aResults; |
|
2196 iBuf = NULL; |
|
2197 iReadStream.Close(); |
|
2198 } |
|
2199 |
|
2200 } |
|
2201 |
|
2202 // --------------------------------------------------------------------------- |
|
2203 // CNSmlContactsDataStore::ContactsSavingFailed |
|
2204 // --------------------------------------------------------------------------- |
|
2205 // |
|
2206 EXPORT_C void CNSmlContactsDataStore::ContactsSavingFailed( |
|
2207 MVPbkContactOperationBase& aOperation, TInt aError ) |
|
2208 { |
|
2209 MVPbkContactOperationBase* operation = &aOperation; |
|
2210 if ( operation ) |
|
2211 { |
|
2212 delete operation; |
|
2213 operation = NULL; |
|
2214 } |
|
2215 |
|
2216 if(iLastOperation == ENSmlAddOp) |
|
2217 { |
|
2218 if(iBatchMode) |
|
2219 { |
|
2220 while( iIndex < iContactsBufferItemList.Count() && |
|
2221 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemAdd ) |
|
2222 { |
|
2223 iContactsBufferItemList[iIndex++]->iStatus = KErrGeneral; |
|
2224 iResultArray->Append(KErrGeneral); |
|
2225 } |
|
2226 } |
|
2227 else |
|
2228 { |
|
2229 iIndex++; |
|
2230 } |
|
2231 |
|
2232 if(iIndex == iContactsBufferItemList.Count()) |
|
2233 { |
|
2234 User::RequestComplete( iCallerStatus, aError ); |
|
2235 ResetBuffer(); |
|
2236 delete iBuf; |
|
2237 iBuf = NULL; |
|
2238 iReadStream.Close(); |
|
2239 } |
|
2240 //Execute the remaining commands in batch |
|
2241 else |
|
2242 { |
|
2243 TRAPD(error,ExecuteBufferL()); |
|
2244 if(error != KErrNone) |
|
2245 { |
|
2246 User::RequestComplete( iCallerStatus, error ); |
|
2247 } |
|
2248 } |
|
2249 } |
|
2250 } |
|
2251 // --------------------------------------------------------------------------- |
|
2252 // CNSmlContactsDataStore::StepComplete |
|
2253 // --------------------------------------------------------------------------- |
|
2254 // |
|
2255 EXPORT_C void CNSmlContactsDataStore::StepComplete( |
|
2256 MVPbkContactOperationBase& /*aOperation*/, |
|
2257 TInt aStepSize ) |
|
2258 { |
|
2259 if(iLastOperation == ENSmlDeleteOp) |
|
2260 { |
|
2261 if(iBatchMode) |
|
2262 { |
|
2263 for(TInt i = 0 ; i<aStepSize && iIndex < iContactsBufferItemList.Count() ;i++) |
|
2264 { |
|
2265 iResultArray->Append(KErrNone); |
|
2266 if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemDelete && |
|
2267 iContactsBufferItemList[iIndex]->iStatus == KNSmlNoError ) |
|
2268 { |
|
2269 iContactsBufferItemList[iIndex]->iStatus = KErrNone; |
|
2270 iUid = iContactsBufferItemList[iIndex]->iUid; |
|
2271 iChangeFinder->ItemDeleted( TNSmlSnapshotItem( iUid )); |
|
2272 } |
|
2273 else if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemSoftDelete && |
|
2274 iContactsBufferItemList[iIndex]->iStatus == KNSmlNoError ) |
|
2275 { |
|
2276 |
|
2277 iContactsBufferItemList[iIndex]->iStatus = KErrNone; |
|
2278 iUid = iContactsBufferItemList[iIndex]->iUid; |
|
2279 TRAP_IGNORE(iChangeFinder->ItemSoftDeletedL( TNSmlSnapshotItem( iUid ) )); |
|
2280 } |
|
2281 iIndex++; |
|
2282 } |
|
2283 } |
|
2284 else |
|
2285 { |
|
2286 iChangeFinder->ItemDeleted( TNSmlSnapshotItem( iUid ) ); |
|
2287 User::RequestComplete( iCallerStatus, KErrNone ); |
|
2288 } |
|
2289 } |
|
2290 } |
|
2291 // --------------------------------------------------------------------------- |
|
2292 // CNSmlContactsDataStore::StepFailed |
|
2293 // --------------------------------------------------------------------------- |
|
2294 // |
|
2295 EXPORT_C TBool CNSmlContactsDataStore::StepFailed( |
|
2296 MVPbkContactOperationBase& /*aOperation*/, |
|
2297 TInt /*aStepSize*/, |
|
2298 TInt aError ) |
|
2299 { |
|
2300 if(iLastOperation == ENSmlDeleteOp) |
|
2301 { |
|
2302 if(iBatchMode) |
|
2303 { |
|
2304 if( iIndex < iContactsBufferItemList.Count() && |
|
2305 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemDelete ) |
|
2306 { |
|
2307 iContactsBufferItemList[iIndex++]->iStatus = KErrGeneral; |
|
2308 iResultArray->Append(KErrGeneral); |
|
2309 } |
|
2310 |
|
2311 } |
|
2312 else |
|
2313 { |
|
2314 User::RequestComplete( iCallerStatus, aError ); |
|
2315 } |
|
2316 } |
|
2317 return ETrue; |
|
2318 } |
|
2319 // --------------------------------------------------------------------------- |
|
2320 // CNSmlContactsDataStore::OperationComplete |
|
2321 // --------------------------------------------------------------------------- |
|
2322 // |
|
2323 EXPORT_C void CNSmlContactsDataStore::OperationComplete |
|
2324 ( MVPbkContactOperationBase& aOperation ) |
|
2325 { |
|
2326 MVPbkContactOperationBase* operation = &aOperation; |
|
2327 if ( operation ) |
|
2328 { |
|
2329 delete operation; |
|
2330 operation = NULL; |
|
2331 } |
|
2332 |
|
2333 TRAPD(error ,OperationCompleteL()); |
|
2334 if(error != KErrNone) |
|
2335 { |
|
2336 User::RequestComplete( iCallerStatus, error ); |
|
2337 } |
|
2338 } |
|
2339 |
|
2340 // --------------------------------------------------------------------------- |
|
2341 // CNSmlContactsDataStore::OperationCompleteL |
|
2342 // --------------------------------------------------------------------------- |
|
2343 // |
|
2344 EXPORT_C void CNSmlContactsDataStore::OperationCompleteL() |
|
2345 { |
|
2346 if(iLastOperation == ENSmlDeleteOp) |
|
2347 { |
|
2348 if(iBatchMode ) |
|
2349 { |
|
2350 if(iResultArray->Count() != iContactsBufferItemList.Count()) |
|
2351 { |
|
2352 while( iIndex < iContactsBufferItemList.Count() && |
|
2353 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemDelete |
|
2354 && iContactsBufferItemList[iIndex]->iStatus == KErrNotFound ) |
|
2355 { |
|
2356 iResultArray->Append(KErrNotFound); |
|
2357 iIndex++; |
|
2358 } |
|
2359 } |
|
2360 |
|
2361 if(iIndex == iContactsBufferItemList.Count()) |
|
2362 { |
|
2363 if(iItemData) |
|
2364 { |
|
2365 iItemData->Reset(); |
|
2366 } |
|
2367 |
|
2368 ResetBuffer(); |
|
2369 User::RequestComplete( iCallerStatus, KErrNone ); |
|
2370 } |
|
2371 else |
|
2372 { |
|
2373 ExecuteBufferL(); |
|
2374 } |
|
2375 } |
|
2376 else |
|
2377 { |
|
2378 |
|
2379 if(iItemData) |
|
2380 { |
|
2381 iItemData->Reset(); |
|
2382 } |
|
2383 |
|
2384 ResetBuffer(); |
|
2385 } |
|
2386 } |
|
2387 else |
|
2388 { |
|
2389 if(iLastOperation == ENSMLDeleteAllOp) |
|
2390 { |
|
2391 iDeleteAllOperation = NULL; |
|
2392 } |
|
2393 if( iChangeFinder ) |
|
2394 { |
|
2395 iChangeFinder->ResetL(); |
|
2396 } |
|
2397 iSnapshotRegistered = EFalse; |
|
2398 |
|
2399 delete iContactLnks; |
|
2400 iContactLnks = NULL; |
|
2401 iContactLink = NULL; |
|
2402 |
|
2403 delete iContactViewBase; |
|
2404 iContactViewBase = NULL; |
|
2405 User::RequestComplete( iCallerStatus, KErrNone ); |
|
2406 |
|
2407 } |
|
2408 |
|
2409 } |
|
2410 |
|
2411 // --------------------------------------------------------------------------- |
|
2412 // CNSmlContactsDataStore::ContactViewReady |
|
2413 // Implements the view ready function of MVPbkContactViewObserver |
|
2414 // --------------------------------------------------------------------------- |
|
2415 EXPORT_C void CNSmlContactsDataStore::ContactViewReady( |
|
2416 MVPbkContactViewBase& /*aView*/ ) |
|
2417 { |
|
2418 if(iLastOperation == ENSMLDeleteAllOp) |
|
2419 { |
|
2420 TRAPD(error,DoDeleteAllContactsL()); |
|
2421 if(error != KErrNone) |
|
2422 { |
|
2423 User::RequestComplete( iCallerStatus, error ); |
|
2424 } |
|
2425 } |
|
2426 } |
|
2427 // --------------------------------------------------------------------------- |
|
2428 // CNSmlContactsDataStore::PrepareForContactsDeleteL() |
|
2429 // Delete all the contacts at client |
|
2430 // --------------------------------------------------------------------------- |
|
2431 EXPORT_C void CNSmlContactsDataStore::DoDeleteAllContactsL() |
|
2432 { |
|
2433 iContactLnks = CVPbkContactLinkArray::NewL(); |
|
2434 TInt contactCount = iContactViewBase->ContactCountL(); |
|
2435 //add all the contact links to ContactLinkArray |
|
2436 for( TInt i = 0; i < contactCount; i++ ) |
|
2437 { |
|
2438 const MVPbkViewContact& contact = |
|
2439 iContactViewBase->ContactAtL(i); |
|
2440 iContactLink = contact.CreateLinkLC(); |
|
2441 iContactLnks->AppendL(iContactLink); |
|
2442 CleanupStack::Pop(); |
|
2443 } |
|
2444 |
|
2445 iDeleteAllOperation = iContactManager->DeleteContactsL( *iContactLnks, *this ); |
|
2446 |
|
2447 } |
|
2448 |
|
2449 // --------------------------------------------------------------------------- |
|
2450 // CNSmlContactsDataStore::ContactViewUnavailable |
|
2451 // Implements the view unavailable function of MVPbkContactViewObserver |
|
2452 // --------------------------------------------------------------------------- |
|
2453 EXPORT_C void CNSmlContactsDataStore::ContactViewUnavailable( |
|
2454 MVPbkContactViewBase& /*aView*/ ) |
|
2455 { |
|
2456 |
|
2457 } |
|
2458 |
|
2459 // --------------------------------------------------------------------------- |
|
2460 // CNSmlContactsDataStore::ContactAddedToView |
|
2461 // Implements the add contact function of MVPbkContactViewObserver |
|
2462 // --------------------------------------------------------------------------- |
|
2463 EXPORT_C void CNSmlContactsDataStore::ContactAddedToView( |
|
2464 MVPbkContactViewBase& /*aView*/, |
|
2465 TInt /*aIndex*/, |
|
2466 const MVPbkContactLink& /*aContactLink*/ ) |
|
2467 { |
|
2468 } |
|
2469 |
|
2470 // --------------------------------------------------------------------------- |
|
2471 // CNSmlContactsDataStore::ContactRemovedFromView |
|
2472 // Implements the remove contact function of MVPbkContactViewObserver |
|
2473 // --------------------------------------------------------------------------- |
|
2474 EXPORT_C void CNSmlContactsDataStore::ContactRemovedFromView( |
|
2475 MVPbkContactViewBase& /*aView*/, |
|
2476 TInt /*aIndex*/, |
|
2477 const MVPbkContactLink& /*aContactLink*/ ) |
|
2478 { |
|
2479 } |
|
2480 |
|
2481 // --------------------------------------------------------------------------- |
|
2482 // CNSmlContactsDataStore::ContactViewError |
|
2483 // Implements the view error function of MVPbkContactViewObserver |
|
2484 // --------------------------------------------------------------------------- |
|
2485 EXPORT_C void CNSmlContactsDataStore::ContactViewError( |
|
2486 MVPbkContactViewBase& /*aView*/, |
|
2487 TInt /*aError*/, |
|
2488 TBool /*aErrorNotified*/ ) |
|
2489 { |
|
2490 |
|
2491 } |
|
2492 |
|
2493 // ----------------------------------------------------------------------------- |
|
2494 // CNSmlContactsDataStore::CreateViewL() |
|
2495 // Create a contact view |
|
2496 // ----------------------------------------------------------------------------- |
|
2497 EXPORT_C void CNSmlContactsDataStore::CreateViewL() |
|
2498 { |
|
2499 |
|
2500 CVPbkContactViewDefinition* viewDef = CVPbkContactViewDefinition::NewL(); |
|
2501 CleanupStack::PushL( viewDef ); |
|
2502 viewDef->SetType( EVPbkContactsView ); |
|
2503 |
|
2504 viewDef->SetUriL(iStore->StoreProperties().Uri().UriDes()); |
|
2505 |
|
2506 iContactViewBase = iContactManager->CreateContactViewLC( |
|
2507 *this, |
|
2508 *viewDef, |
|
2509 iContactManager->FieldTypes() ); |
|
2510 CleanupStack::Pop(); |
|
2511 CleanupStack::PopAndDestroy(viewDef); |
|
2512 } |
1761 |
2513 |
1762 // ------------------------------------------------------------------------------------------------ |
2514 // ------------------------------------------------------------------------------------------------ |
1763 // CNSmlContactsDataStore::GetStoreFormatResourceFileL |
2515 // CNSmlContactsDataStore::GetStoreFormatResourceFileL |
1764 // ------------------------------------------------------------------------------------------------ |
2516 // ------------------------------------------------------------------------------------------------ |
1765 EXPORT_C const TDesC& CNSmlContactsDataStore::GetStoreFormatResourceFileL() const |
2517 EXPORT_C const TDesC& CNSmlContactsDataStore::GetStoreFormatResourceFileL() |
1766 { |
2518 { |
1767 _DBG_FILE("CNSmlContactsDataStore::GetStoreFormatResourceFileL(): BEGIN"); |
2519 _DBG_FILE("CNSmlContactsDataStore::GetStoreFormatResourceFileL(): begin"); |
1768 |
2520 |
1769 // Check correct Data Sync protocol |
2521 // Check correct Data Sync protocol |
1770 TInt value( EDataSyncNotRunning ); |
2522 TInt value( EDataSyncNotRunning ); |
1771 TInt error = RProperty::Get( KPSUidDataSynchronizationInternalKeys, |
2523 TInt error = RProperty::Get( KPSUidDataSynchronizationInternalKeys, |
1772 KDataSyncStatus, |
2524 KDataSyncStatus, value ); |
1773 value ); |
2525 if ( error == KErrNone && |
1774 if ( error == KErrNone && value == EDataSyncRunning ) |
2526 value == EDataSyncRunning ) |
1775 { |
2527 { |
1776 _DBG_FILE("CNSmlContactsDataStore::GetStoreFormatResourceFileL() 1.1.2: END"); |
|
1777 return KNSmlContactsStoreFormatRsc_1_1_2; |
2528 return KNSmlContactsStoreFormatRsc_1_1_2; |
1778 } |
2529 } |
1779 else // error or protocol version 1.2 |
2530 else // error or protocol version 1.2 |
1780 { |
2531 { |
1781 _DBG_FILE("CNSmlContactsDataStore::GetStoreFormatResourceFileL() 1.2: END"); |
|
1782 return KNSmlContactsStoreFormatRsc_1_2; |
2532 return KNSmlContactsStoreFormatRsc_1_2; |
1783 } |
2533 } |
|
2534 _DBG_FILE("CNSmlContactsDataStore::GetStoreFormatResourceFileL(): end"); |
1784 } |
2535 } |
1785 |
2536 |
1786 |
2537 // ------------------------------------------------------------------------------------------------ |
1787 // ---------------------------------------------------------------------------- |
2538 // CNSmlContactsDataStore::CreateModsFetcherL |
1788 // CNSmlContactsDataStore::DoExecuteBufferL |
2539 // ------------------------------------------------------------------------------------------------ |
1789 // ---------------------------------------------------------------------------- |
2540 EXPORT_C MContactsModsFetcher* CNSmlContactsDataStore::CreateModsFetcherL() |
1790 EXPORT_C TInt CNSmlContactsDataStore::DoExecuteBufferL(RArray<TInt>& aResultArray) |
|
1791 { |
2541 { |
1792 _DBG_FILE("CNSmlContactsDataStore::DoExecuteBufferL(): begin"); |
2542 _DBG_FILE("CNSmlContactsDataStore::CreateModsFetcherL(): begin"); |
1793 |
2543 CNSmlContactsModsFetcher* modsFetcher = |
1794 TBool batchOK = EFalse; |
2544 new ( ELeave ) CNSmlContactsModsFetcher( iSnapshotRegistered, |
1795 TInt ret( KErrNone ); |
2545 *iContactManager,*iStore, iKey, *iChangeFinder ); |
1796 TInt retCommand( KErrNone ); |
2546 CleanupStack::PushL( modsFetcher ); |
1797 TInt itemAdds( 0 ); |
2547 modsFetcher->ConstructL(); |
1798 |
2548 CleanupStack::Pop( modsFetcher ); |
1799 aResultArray.Reset(); |
2549 _DBG_FILE("CNSmlContactsDataStore::CreateModsFetcherL(): end"); |
1800 |
2550 return modsFetcher; |
1801 if( iContactsBufferItemList.Count() == 0 ) |
|
1802 { |
|
1803 return retCommand; |
|
1804 } |
|
1805 |
|
1806 TInt i = 0; |
|
1807 // |
|
1808 // ResultArray initialized |
|
1809 // |
|
1810 while( i<iContactsBufferItemList.Count() ) |
|
1811 { |
|
1812 if ( iContactsBufferItemList[i]->iModType == ENSmlCntItemAdd && |
|
1813 iContactsBufferItemList[i]->iStatus == KNSmlNoError ) |
|
1814 { |
|
1815 itemAdds++; |
|
1816 } |
|
1817 aResultArray.Append( KErrGeneral ); |
|
1818 i++; |
|
1819 } |
|
1820 |
|
1821 i = 0; |
|
1822 // |
|
1823 // Loop through buffered commands |
|
1824 // |
|
1825 while( i<iContactsBufferItemList.Count() ) |
|
1826 { |
|
1827 if( iContactsBufferItemList[i]->iStatus!= KNSmlNoError ) |
|
1828 { |
|
1829 retCommand = iContactsBufferItemList[i]->iStatus; |
|
1830 } |
|
1831 else if( iContactsBufferItemList[i]->iModType == ENSmlCntItemAdd ) |
|
1832 { |
|
1833 ret =0 ; |
|
1834 iPUid = 0; |
|
1835 |
|
1836 StripPropertyL( iItemDataAddBatch, KVersitTokenUID() ); // Remove UID's from data |
|
1837 |
|
1838 TInt err( KErrNone ); |
|
1839 TTime lastModified; |
|
1840 if( iBatchMode ) // All adds handled when first add on iContactsBufferItemList |
|
1841 { |
|
1842 iAddResultArray.Reset(); |
|
1843 |
|
1844 TRAP( err, ret = LdoAddItemsL( iAddResultArray, iItemDataAddBatch, |
|
1845 iItemDataAddBatch->Ptr(0).Length(), |
|
1846 lastModified ) ); |
|
1847 if( err == KErrNone && ret == KErrNone && |
|
1848 itemAdds == iAddResultArray.Count() ) |
|
1849 { |
|
1850 TInt j = i; |
|
1851 TInt k = 0; |
|
1852 while( j < iContactsBufferItemList.Count() ) |
|
1853 { |
|
1854 if( iContactsBufferItemList[j]->iModType == ENSmlCntItemAdd && |
|
1855 iContactsBufferItemList[j]->iStatus == KNSmlNoError && |
|
1856 k < iAddResultArray.Count() ) |
|
1857 { |
|
1858 iContactsBufferItemList[j]->iStatus = KErrNone; |
|
1859 *iContactsBufferItemList[j]->iPUid = iAddResultArray[k]; |
|
1860 |
|
1861 TNSmlSnapshotItem item( iAddResultArray[k]); |
|
1862 item.SetLastChangedDate( lastModified ); |
|
1863 item.SetSoftDelete( EFalse ); |
|
1864 iChangeFinder->ItemAddedL( item ); |
|
1865 |
|
1866 k++; |
|
1867 } |
|
1868 j++; |
|
1869 } |
|
1870 } |
|
1871 else |
|
1872 { |
|
1873 TInt j = i; |
|
1874 while( j < iContactsBufferItemList.Count() ) |
|
1875 { |
|
1876 if( iContactsBufferItemList[j]->iModType == ENSmlCntItemAdd && |
|
1877 iContactsBufferItemList[j]->iStatus == KNSmlNoError ) |
|
1878 { |
|
1879 iContactsBufferItemList[j]->iStatus = KErrNotSupported; |
|
1880 } |
|
1881 j++; |
|
1882 } |
|
1883 } |
|
1884 } |
|
1885 else |
|
1886 { |
|
1887 TTime lastModified; |
|
1888 iPUid =iContactsBufferItemList[i]->iPUid; |
|
1889 const TPtr8 dataPtr = iItemDataAddBatch->Ptr(0); |
|
1890 TRAP( err, ret = LdoAddItemL(*iPUid, dataPtr, |
|
1891 iContactsBufferItemList[i]->iSize, |
|
1892 lastModified)); |
|
1893 if( (err == KErrNone) && (ret == KErrNone)) |
|
1894 { |
|
1895 // Add the snapshot item to the Change Finder. |
|
1896 // The Change finder maintains a list of all changes to the database. |
|
1897 |
|
1898 TNSmlSnapshotItem item( *iPUid ); |
|
1899 item.SetLastChangedDate( lastModified ); |
|
1900 item.SetSoftDelete( EFalse ); |
|
1901 |
|
1902 iChangeFinder->ItemAddedL( item ); |
|
1903 retCommand = KErrNone; |
|
1904 } |
|
1905 else if( err == KErrNone ) |
|
1906 { |
|
1907 retCommand = ret; |
|
1908 } |
|
1909 else |
|
1910 { |
|
1911 retCommand = err; |
|
1912 } |
|
1913 } |
|
1914 } |
|
1915 else if( iContactsBufferItemList[i]->iModType == ENSmlCntItemReplace || |
|
1916 iContactsBufferItemList[i]->iModType == ENSmlCntItemFieldLevelReplace ) |
|
1917 { |
|
1918 iItemData = iContactsBufferItemList[i]->iItemData; |
|
1919 iUid = iContactsBufferItemList[i]->iUid; |
|
1920 const TPtr8 dataPtr = iItemData->Ptr(0); |
|
1921 ret = 0; |
|
1922 TTime lastModified; |
|
1923 |
|
1924 TRAPD( err, ret = LdoUpdateItemL(iUid, dataPtr, |
|
1925 iContactsBufferItemList[i]->iSize, |
|
1926 lastModified )); |
|
1927 if( (err == KErrNone) && (ret == KErrNone) ) |
|
1928 { |
|
1929 retCommand = KErrNone; |
|
1930 iContactsBufferItemList[i]->iStatus = KErrNone; |
|
1931 |
|
1932 TNSmlSnapshotItem item( iUid ); |
|
1933 item.SetLastChangedDate( lastModified ); |
|
1934 item.SetSoftDelete( EFalse ); |
|
1935 |
|
1936 iChangeFinder->ItemUpdatedL( item ); |
|
1937 } |
|
1938 else if( err == KErrNone ) |
|
1939 { |
|
1940 retCommand = ret; |
|
1941 iContactsBufferItemList[i]->iStatus = ret; |
|
1942 } |
|
1943 else |
|
1944 { |
|
1945 retCommand = err; |
|
1946 iContactsBufferItemList[i]->iStatus = err; |
|
1947 } |
|
1948 iItemData = NULL; |
|
1949 } |
|
1950 else if( iContactsBufferItemList[i]->iModType == ENSmlCntItemMove ) |
|
1951 { |
|
1952 retCommand = KErrNotSupported; |
|
1953 } |
|
1954 else if( iContactsBufferItemList[i]->iModType == ENSmlCntItemDelete || |
|
1955 iContactsBufferItemList[i]->iModType == ENSmlCntItemSoftDelete ) |
|
1956 { |
|
1957 if( iBatchMode ) // All deletes handled when 1'st occurrence on list |
|
1958 { |
|
1959 CArrayFixFlat<TUid>* arrDelete = new(ELeave) CArrayFixFlat<TUid>(4); |
|
1960 CleanupStack::PushL( arrDelete ); |
|
1961 TInt j=i; |
|
1962 while( j < iContactsBufferItemList.Count() ) |
|
1963 { |
|
1964 if( (iContactsBufferItemList[j]->iModType == ENSmlCntItemDelete || |
|
1965 iContactsBufferItemList[j]->iModType == ENSmlCntItemSoftDelete) && |
|
1966 iContactsBufferItemList[j]->iStatus == KNSmlNoError ) |
|
1967 { |
|
1968 TUid id = TUid::Uid( iContactsBufferItemList[j]->iUid ); |
|
1969 CNsmlContactItem* contactitem = CNsmlContactItem::NewL(); |
|
1970 CleanupStack::PushL( contactitem ); |
|
1971 TInt err = KErrNone; |
|
1972 TInt ret = KErrNone; |
|
1973 TRAP( err, ret = iContactsDataStoreExtension->ReadContactL( id, contactitem ) ); |
|
1974 if( err == KErrNone && ret == KErrNone && id.iUid != 0 ) |
|
1975 { |
|
1976 arrDelete->AppendL( id ); |
|
1977 } |
|
1978 else if( err == KErrNone && ret == KErrNone ) |
|
1979 { |
|
1980 iContactsBufferItemList[j]->iStatus = KErrNotFound; |
|
1981 } |
|
1982 else |
|
1983 { |
|
1984 iContactsBufferItemList[j]->iStatus = err; |
|
1985 } |
|
1986 CleanupStack::PopAndDestroy( contactitem ); // item |
|
1987 } |
|
1988 j++; |
|
1989 } |
|
1990 if( arrDelete->Count() > 0 ) |
|
1991 { |
|
1992 TInt err2 = KErrInUse; |
|
1993 TRAP( err2, iContactsDataStoreExtension->DeleteContactsL( arrDelete ) ); |
|
1994 CleanupStack::PopAndDestroy( arrDelete ); |
|
1995 |
|
1996 if( err2 == KErrInUse ) |
|
1997 { |
|
1998 err2 = KErrGeneral; |
|
1999 } |
|
2000 |
|
2001 j= i; |
|
2002 while( j < iContactsBufferItemList.Count() ) // Mark deleted items |
|
2003 { |
|
2004 if( iContactsBufferItemList[j]->iModType == ENSmlCntItemDelete && |
|
2005 iContactsBufferItemList[j]->iStatus == KNSmlNoError ) |
|
2006 { |
|
2007 |
|
2008 iContactsBufferItemList[j]->iStatus = err2; |
|
2009 if( err2 == KErrNone ) |
|
2010 { |
|
2011 iUid = iContactsBufferItemList[j]->iUid; |
|
2012 iChangeFinder->ItemDeleted( TNSmlSnapshotItem( iUid )); |
|
2013 } |
|
2014 } |
|
2015 else if( iContactsBufferItemList[j]->iModType == ENSmlCntItemSoftDelete && |
|
2016 iContactsBufferItemList[j]->iStatus == KNSmlNoError ) |
|
2017 { |
|
2018 |
|
2019 iContactsBufferItemList[j]->iStatus = err2; |
|
2020 if( err2 == KErrNone ) |
|
2021 { |
|
2022 iUid = iContactsBufferItemList[j]->iUid; |
|
2023 iChangeFinder->ItemSoftDeletedL( TNSmlSnapshotItem( iUid ) ); |
|
2024 } |
|
2025 } |
|
2026 j++; |
|
2027 } |
|
2028 } |
|
2029 else |
|
2030 { |
|
2031 CleanupStack::PopAndDestroy( arrDelete ); |
|
2032 } |
|
2033 } |
|
2034 else |
|
2035 { |
|
2036 iUid = iContactsBufferItemList[i]->iUid; |
|
2037 TInt err = KErrNone; |
|
2038 TRAP( err, iContactsDataStoreExtension->DeleteContactL( TUid::Uid( iUid ) ) ); |
|
2039 if( err == KErrNone ) |
|
2040 { |
|
2041 iChangeFinder->ItemDeleted( TNSmlSnapshotItem( iUid ) ); |
|
2042 } |
|
2043 |
|
2044 iContactsBufferItemList[i]->iStatus = err; |
|
2045 retCommand = err; |
|
2046 } |
|
2047 } |
|
2048 // |
|
2049 // Set allready set commands from iContactsBufferItemList |
|
2050 // |
|
2051 if( ( iContactsBufferItemList[i]->iModType == ENSmlCntItemAdd || |
|
2052 iContactsBufferItemList[i]->iModType == ENSmlCntItemReplace || |
|
2053 iContactsBufferItemList[i]->iModType == ENSmlCntItemFieldLevelReplace || |
|
2054 iContactsBufferItemList[i]->iModType == ENSmlCntItemDelete || |
|
2055 iContactsBufferItemList[i]->iModType == ENSmlCntItemSoftDelete ) && |
|
2056 iContactsBufferItemList[i]->iStatus != KNSmlNoError ) |
|
2057 { |
|
2058 retCommand = iContactsBufferItemList[i]->iStatus; |
|
2059 } |
|
2060 |
|
2061 |
|
2062 if( !batchOK && retCommand == KErrNone ) // If one command is OK => batchOK |
|
2063 { |
|
2064 batchOK = ETrue; |
|
2065 } |
|
2066 |
|
2067 aResultArray[i++] = retCommand; |
|
2068 } |
|
2069 |
|
2070 if ( batchOK ) |
|
2071 { |
|
2072 _DBG_FILE("CNSmlContactsDataStore::DoExecuteBufferL(): end"); |
|
2073 return KErrNone; |
|
2074 } |
|
2075 |
|
2076 _DBG_FILE("CNSmlContactsDataStore::DoExecuteBufferL(): ERROR end"); |
|
2077 return KErrGeneral; // All commands failed |
|
2078 } |
2551 } |
2079 |
2552 |
2080 // ------------------------------------------------------------------------------------------------ |
2553 // ------------------------------------------------------------------------------------------------ |
2081 // CNSmlContactsDataStore::FetchModificationsL |
2554 // CNSmlContactsDataStore::GetDataMod |
2082 // ------------------------------------------------------------------------------------------------ |
2555 // ------------------------------------------------------------------------------------------------ |
2083 // |
|
2084 TInt CNSmlContactsDataStore::FetchModificationsL() |
|
2085 { |
|
2086 _DBG_FILE("CNSmlContactsDataStore::FetchModificationsL(): begin"); |
|
2087 |
|
2088 TInt error = KErrNone; |
|
2089 |
|
2090 if( !iSnapshot ) |
|
2091 { |
|
2092 iSnapshot = new (ELeave) CArrayFixSeg<TNSmlSnapshotItem>( KNSmlContactsGranularity ); |
|
2093 } |
|
2094 |
|
2095 iCntUidList->Reset(); |
|
2096 iContactsDataStoreExtension->ListContactsL( iCntUidList ); |
|
2097 |
|
2098 if( !iSnapshotRegistered ) |
|
2099 { |
|
2100 DBG_ARGS(_S("CNSmlContactsDataStore::FetchModificationsL(): Count = %d"), iCntUidList->Count()); |
|
2101 for ( TInt i = 0; i < iCntUidList->Count(); i++ ) |
|
2102 { |
|
2103 CNsmlContactItem* contactitem = CNsmlContactItem::NewL(); |
|
2104 CleanupStack::PushL( contactitem ); |
|
2105 error = iContactsDataStoreExtension->ReadContactL( iCntUidList->At(i), contactitem ); |
|
2106 if(error != KErrNone) |
|
2107 { |
|
2108 DBG_ARGS(_S("CNSmlContactsDataStore::FetchModificationsL(): Error = %d"), error); |
|
2109 CleanupStack::PopAndDestroy(contactitem); // item |
|
2110 return error; |
|
2111 } |
|
2112 TNSmlSnapshotItem snap( iCntUidList->At(i).iUid ); |
|
2113 snap.SetLastChangedDate( contactitem->iLastModified ); |
|
2114 iSnapshot->InsertIsqL( snap, iKey ); |
|
2115 |
|
2116 CleanupStack::PopAndDestroy(contactitem); // item |
|
2117 } |
|
2118 iSnapshot->Compress(); |
|
2119 |
|
2120 iChangeFinder->SetNewSnapshot( iSnapshot ); // changefinder takes ownership |
|
2121 iSnapshot = NULL; |
|
2122 iSnapshotRegistered = ETrue; |
|
2123 } |
|
2124 |
|
2125 _DBG_FILE("CNSmlContactsDataStore::FetchModificationsL(): end"); |
|
2126 return KErrNone; |
|
2127 } |
|
2128 |
|
2129 // ----------------------------------------------------------------------------» |
|
2130 // CNSmlContactsDataStore::GetDataMod |
|
2131 // return reference to datamod instance. |
|
2132 // ---------------------------------------------------------------------------- |
|
2133 EXPORT_C CNSmlDataModBase& CNSmlContactsDataStore::GetDataMod() |
2556 EXPORT_C CNSmlDataModBase& CNSmlContactsDataStore::GetDataMod() |
2134 { |
2557 { |
|
2558 _DBG_FILE("CNSmlContactsDataStore::GetDataMod()"); |
2135 return *iDataMod; |
2559 return *iDataMod; |
2136 } |
2560 } |
2137 |
2561 |
2138 // ---------------------------------------------------------------------------- |
|
2139 // CNSmlContactsDataStore::ExportContactsL |
|
2140 // ---------------------------------------------------------------------------- |
|
2141 EXPORT_C TInt CNSmlContactsDataStore::ExportContactsL( |
|
2142 const TUid& aUid, CBufBase& aContactBufBase ) |
|
2143 { |
|
2144 return iContactsDataStoreExtension->ExportContactsL( aUid, aContactBufBase ); |
|
2145 } |
|
2146 |
|
2147 // ---------------------------------------------------------------------------- |
|
2148 // CNSmlContactsDataStore::ImportContactsL |
|
2149 // ---------------------------------------------------------------------------- |
|
2150 EXPORT_C CArrayFixFlat<TUid>* CNSmlContactsDataStore::ImportContactsL( |
|
2151 const TDesC8& aContactBufBase ) |
|
2152 { |
|
2153 return iContactsDataStoreExtension->ImportContactsL( aContactBufBase ); |
|
2154 } |
|
2155 |
|
2156 // End of File |
2562 // End of File |