647 } |
646 } |
648 } |
647 } |
649 |
648 |
650 bool CntSymbianEngine::removeContacts(const QList<QContactLocalId>& contactIds, QMap<int, QContactManager::Error> *errorMap, QContactManager::Error* error) |
649 bool CntSymbianEngine::removeContacts(const QList<QContactLocalId>& contactIds, QMap<int, QContactManager::Error> *errorMap, QContactManager::Error* error) |
651 { |
650 { |
|
651 QContactChangeSet changeSet; |
652 *error = QContactManager::NoError; |
652 *error = QContactManager::NoError; |
653 |
653 |
654 if (errorMap) { |
654 if (errorMap) { |
655 // if the errormap argument is null, we just don't do fine-grained reporting. |
655 // if the errormap argument is null, we just don't do fine-grained reporting. |
656 errorMap->clear(); |
656 errorMap->clear(); |
657 } |
657 } |
658 |
658 |
659 if (contactIds.count() == 0) { |
659 if (contactIds.count() == 0 || contactIds.contains(0)) { |
660 *error = QContactManager::BadArgumentError; |
660 *error = QContactManager::BadArgumentError; |
661 return false; |
661 return false; |
662 } |
662 } |
663 |
663 |
664 QContactManager::Error err; |
664 QContactManager::Error selfContactError; |
665 QContactLocalId selfCntId = selfContactId(&err); // err ignored |
665 QContactLocalId selfCntId = selfContactId(&selfContactError); // selfContactError ignored |
666 |
666 |
667 QContactChangeSet changeSet; |
667 #ifdef SYMBIAN_BACKEND_USE_SQLITE |
|
668 // try to batch remove all contacts |
|
669 TRAPD(err, |
|
670 CContactIdArray* idList = CContactIdArray::NewLC(); |
|
671 foreach (QContactLocalId contactId, contactIds) { |
|
672 idList->AddL(TContactItemId(contactId)); |
|
673 } |
|
674 m_dataBase->contactDatabase()->DeleteContactsL(*idList); |
|
675 CleanupStack::PopAndDestroy(idList); |
|
676 ); |
|
677 |
|
678 if (err == KErrNone) { |
|
679 foreach (QContactLocalId contactId, contactIds) { |
|
680 changeSet.insertRemovedContact(contactId); |
|
681 m_dataBase->appendContactEmitted(contactId); |
|
682 } |
|
683 if (contactIds.contains(selfCntId)) { |
|
684 QOwnCardPair ownCard(selfCntId, QContactLocalId(0)); |
|
685 changeSet.setOldAndNewSelfContactId(ownCard); |
|
686 } |
|
687 } |
|
688 else { |
|
689 CntSymbianTransformError::transformError(err, error); |
|
690 } |
|
691 #else |
668 for (int i = 0; i < contactIds.count(); i++) { |
692 for (int i = 0; i < contactIds.count(); i++) { |
669 QContactLocalId current = contactIds.at(i); |
693 QContactLocalId current = contactIds.at(i); |
670 QContactManager::Error functionError = QContactManager::NoError; |
694 QContactManager::Error functionError = QContactManager::NoError; |
671 if (!removeContact(current, changeSet, &functionError)) { |
695 if (!removeContact(current, changeSet, &functionError)) { |
672 *error = functionError; |
696 *error = functionError; |
673 if (errorMap) { |
697 if (errorMap) { |
674 errorMap->insert(i, functionError); |
698 errorMap->insert(i, functionError); |
675 } |
699 } |
676 } |
700 } |
677 #ifdef SYMBIAN_BACKEND_SIGNAL_EMISSION_TWEAK |
701 } |
678 else { |
702 #endif |
679 if (current == selfCntId ) { |
703 |
680 QOwnCardPair ownCard(selfCntId, QContactLocalId(0)); |
|
681 changeSet.setOldAndNewSelfContactId(ownCard); |
|
682 } |
|
683 } |
|
684 #endif |
|
685 } |
|
686 changeSet.emitSignals(this); |
704 changeSet.emitSignals(this); |
|
705 |
687 return (*error == QContactManager::NoError); |
706 return (*error == QContactManager::NoError); |
688 } |
707 } |
689 |
708 |
690 /* relationships */ |
709 /* relationships */ |
691 |
710 |