diff -r 34879f5cfc63 -r 2666d9724c76 phonebookui/Phonebook2/MMCExtension/src/CPmuCopyFromDriveCmd.cpp --- a/phonebookui/Phonebook2/MMCExtension/src/CPmuCopyFromDriveCmd.cpp Mon Jun 21 15:24:27 2010 +0300 +++ b/phonebookui/Phonebook2/MMCExtension/src/CPmuCopyFromDriveCmd.cpp Thu Jul 15 18:22:55 2010 +0300 @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,7 @@ #include #include #include +#include // System includes #include @@ -145,7 +147,8 @@ // CPmuCopyFromMmcCmd::CPmuCopyFromMmcCmd( MPbk2ContactUiControl& aUiControl ) : CActive( EPriorityStandard ), - iUiControl( &aUiControl ) + iUiControl( &aUiControl ), + iCheckDuplicates( ETrue ) { CActiveScheduler::Add( this ); } @@ -163,6 +166,7 @@ delete iDecorator; delete iImportOperation; delete iVCardEngine; + Release( iAppServices ); } // -------------------------------------------------------------------------- @@ -186,18 +190,20 @@ // inline void CPmuCopyFromMmcCmd::ConstructL() { + iAppServices = CPbk2ApplicationServices::InstanceL(); + iVCardEngine = CVPbkVCardEng::NewL - ( Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager() ); + ( iAppServices->ContactManager() ); iDecorator = Pbk2ProcessDecoratorFactory::CreateProgressDialogDecoratorL ( R_PMU_COPY_PROGRESS_NOTE, EFalse ); + CPbk2StoreConfiguration* storeConfig = CPbk2StoreConfiguration::NewL(); CleanupStack::PushL( storeConfig ); - iTargetStore = Phonebook2::Pbk2AppUi()->ApplicationServices(). - ContactManager().ContactStoresL().Find( + iTargetStore = iAppServices->ContactManager().ContactStoresL().Find( storeConfig->DefaultSavingStoreL() ); - CleanupStack::PopAndDestroy( storeConfig ); + iCheckDuplicates = ( iTargetStore->StoreInfo().NumberOfContactsL() > 0 ); // set the default contacts path iContactsPath = PathInfo::MemoryCardContactsPath(); @@ -287,13 +293,11 @@ CleanupStack::PushL( this ); if ( !iTargetStore || - !IsValidStoreL( Phonebook2::Pbk2AppUi()->ApplicationServices(). - StoreValidityInformer(), iTargetStore ) ) + !IsValidStoreL( iAppServices->StoreValidityInformer(), iTargetStore ) ) { // if target store not available finish command ShowStoreNotAvailableNoteL - ( Phonebook2::Pbk2AppUi()->ApplicationServices(). - StoreProperties() ); + ( iAppServices->StoreProperties() ); iCommandObserver->CommandFinished(*this); } else @@ -304,7 +308,7 @@ } else { - Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager(). + iAppServices->ContactManager(). FsSession().GetDir( iContactsPath, KEntryAttNormal | KEntryAttMatchMask, @@ -417,6 +421,8 @@ { Cancel(); + delete iImportOperation; + iImportOperation = NULL; iState = EPmuCopyFromMmcCmdComplete; IssueRequest(); } @@ -437,11 +443,22 @@ NULL ); User::LeaveIfError( - iReadStream.Open( Phonebook2::Pbk2AppUi()->ApplicationServices(). - ContactManager().FsSession(), + iReadStream.Open( iAppServices->ContactManager().FsSession(), parse.FullName(), EFileRead ) ); - iImportOperation = - iVCardEngine->ImportVCardL( *iTargetStore, iReadStream, *this ); + + // Duplicate checking is one of the major performance bottlenecks in + // contact importing. ImportVCardForSyncL ignores the duplicate check so + // it is used if the target store is empty before importing. + if ( iCheckDuplicates ) + { + iImportOperation = + iVCardEngine->ImportVCardL( *iTargetStore, iReadStream, *this ); + } + else + { + iImportOperation = + iVCardEngine->ImportVCardForSyncL( *iTargetStore, iReadStream, *this ); + } ++iCurrentContactIndex; iDecorator->ProcessAdvance( 1 ); } @@ -527,8 +544,7 @@ TBool ret = EFalse; const TVPbkContactStoreUriPtr uri = - Phonebook2::Pbk2AppUi()->ApplicationServices(). - StoreConfiguration().DefaultSavingStoreL(); + iAppServices->StoreConfiguration().DefaultSavingStoreL(); TVPbkContactStoreUriPtr phoneMemoryUri ( VPbkContactStoreUris::DefaultCntDbUri() );