phonebookui/Phonebook2/CommandsExtension/src/CPbk2DeleteContactsCmd.cpp
changeset 0 e686773b3f54
child 3 04ab22b956c2
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2005-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 "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:  Phonebook 2 delete contacts command.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2DeleteContactsCmd.h"
       
    21 
       
    22 // Phonebook2
       
    23 #include <MPbk2CommandObserver.h>
       
    24 #include "MPbk2ProcessDecorator.h"
       
    25 #include "Pbk2ProcessDecoratorFactory.h"
       
    26 #include <Pbk2Commands.rsg>
       
    27 #include <Pbk2UIControls.rsg>
       
    28 #include <MPbk2ContactUiControl.h>
       
    29 #include <MPbk2ContactNameFormatter.h>
       
    30 #include <CPbk2GeneralConfirmationQuery.h>
       
    31 #include <MPbk2ContactLinkIterator.h>
       
    32 #include <CPbk2ApplicationServices.h>
       
    33 #include <MPbk2AppUi.h>
       
    34 
       
    35 // Virtual Phonebook
       
    36 #include <CVPbkContactManager.h>
       
    37 #include <MVPbkContactLink.h>
       
    38 #include <MVPbkStoreContact.h>
       
    39 #include <MVPbkContactOperationBase.h>
       
    40 #include <MVPbkContactStore.h>
       
    41 #include <MVPbkContactStoreProperties.h>
       
    42 #include <CVPbkContactLinkArray.h>
       
    43 
       
    44 // System includes
       
    45 #include <AknQueryDialog.h>
       
    46 
       
    47 // Debugging headers
       
    48 #include <Pbk2Debug.h>
       
    49 
       
    50 
       
    51 /// Unnamed namespace for local definitions
       
    52 namespace {
       
    53 
       
    54 const TInt KOneContact = 1;
       
    55 
       
    56 // LOCAL DEBUG CODE
       
    57 #ifdef _DEBUG
       
    58 enum TPanicCode
       
    59     {
       
    60     EPanicPreCond_ResetWhenDestroyed = 1,
       
    61     ERunL_InvalidState,
       
    62     EPanicLogic_DoDeleteContactsL,
       
    63     EPanicPreCond_Null_Pointer
       
    64     };
       
    65 
       
    66 void Panic(TPanicCode aReason)
       
    67     {
       
    68     _LIT(KPanicText, "CPbk2DeleteContactsCmd");
       
    69     User::Panic(KPanicText,aReason);
       
    70     }
       
    71 #endif // _DEBUG
       
    72 
       
    73 }
       
    74 
       
    75 // --------------------------------------------------------------------------
       
    76 // CPbk2DeleteContactsCmd::CPbk2DeleteContactsCmd
       
    77 // --------------------------------------------------------------------------
       
    78 //
       
    79 inline CPbk2DeleteContactsCmd::CPbk2DeleteContactsCmd(
       
    80         MPbk2ContactUiControl& aUiControl ) :
       
    81     CActive( EPriorityIdle ),
       
    82     iUiControl( &aUiControl )
       
    83     {
       
    84     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
    85         ("CPbk2DeleteContactsCmd::CPbk2DeleteContactsCmd(0x%x)"), this);
       
    86 
       
    87     CActiveScheduler::Add( this );
       
    88     }
       
    89 
       
    90 // --------------------------------------------------------------------------
       
    91 // CPbk2DeleteContactsCmd::~CPbk2DeleteContactsCmd
       
    92 // --------------------------------------------------------------------------
       
    93 //
       
    94 CPbk2DeleteContactsCmd::~CPbk2DeleteContactsCmd()
       
    95     {
       
    96     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
    97         ("CPbk2DeleteContactsCmd::~CPbk2DeleteContactsCmd(0x%x)"), this);
       
    98 
       
    99     Cancel();
       
   100     if (iUiControl)
       
   101         {
       
   102         iUiControl->RegisterCommand(NULL);
       
   103         }
       
   104     delete iDecorator;
       
   105     delete iContactIterator;
       
   106     delete iContactsToDelete;
       
   107 
       
   108     delete iRetrieveOperation;
       
   109     delete iDeleteOperation;
       
   110     delete iListContactsOperation;
       
   111     delete iStoreContact;
       
   112     Release( iAppServices );
       
   113     }
       
   114 
       
   115 // --------------------------------------------------------------------------
       
   116 // CPbk2DeleteContactsCmd::ConstructL
       
   117 // --------------------------------------------------------------------------
       
   118 //
       
   119 inline void CPbk2DeleteContactsCmd::ConstructL()
       
   120     {
       
   121     iAppServices = CPbk2ApplicationServices::InstanceL();
       
   122 
       
   123     // register command to ui control
       
   124     iUiControl->RegisterCommand(this);
       
   125 
       
   126     // Returns NULL if there are no selected contacts.
       
   127     // In that case we will delete the focused contact.
       
   128     iContactIterator = iUiControl->SelectedContactsIteratorL();
       
   129 
       
   130     iContactCount = GetContactCountL();
       
   131 
       
   132     if( iContactCount > 1 )
       
   133     	{
       
   134     	//we are deleting multiple contacts
       
   135         iDecorator = Pbk2ProcessDecoratorFactory::CreateProgressDialogDecoratorL
       
   136             ( R_QTN_PHOB_NOTE_CLEARING_PB_WITH_CANCEL, EFalse );
       
   137 
       
   138         iDecorator->SetObserver(*this);
       
   139     	}
       
   140     }
       
   141 
       
   142 // --------------------------------------------------------------------------
       
   143 // CPbk2DeleteContactsCmd::NewL
       
   144 // --------------------------------------------------------------------------
       
   145 //
       
   146 CPbk2DeleteContactsCmd* CPbk2DeleteContactsCmd::NewL(
       
   147         MPbk2ContactUiControl& aUiControl )
       
   148     {
       
   149     CPbk2DeleteContactsCmd* self = new(ELeave) CPbk2DeleteContactsCmd(
       
   150             aUiControl );
       
   151     CleanupStack::PushL( self );
       
   152     self->ConstructL();
       
   153     CleanupStack::Pop( self );
       
   154     return self;
       
   155     }
       
   156 
       
   157 // --------------------------------------------------------------------------
       
   158 // CPbk2DeleteContactsCmd::ExecuteLD
       
   159 // --------------------------------------------------------------------------
       
   160 //
       
   161 void CPbk2DeleteContactsCmd::ExecuteLD()
       
   162     {
       
   163     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   164         ("CPbk2DeleteContactsCmd::ExecuteLD(0x%x)"), this);
       
   165 
       
   166     CleanupStack::PushL(this);
       
   167 
       
   168     if ( iContactCount > KOneContact )
       
   169         {
       
   170         // Move straight to confirm phase
       
   171         iState = EConfirming;
       
   172         IssueRequest();
       
   173         }
       
   174     else if ( iContactCount == KOneContact )
       
   175         {
       
   176         // There was only one contact, we have to retrieve it to get
       
   177         // its name
       
   178         iState = ERetrieving;
       
   179         IssueRequest();
       
   180         }
       
   181     else 
       
   182         {
       
   183         // If iContactCount == 0 we should end this command properly.
       
   184         // This happens when contact to be deleted is from read-only store.
       
   185         ProcessDismissed( KErrNone );
       
   186         }        
       
   187 
       
   188     CleanupStack::Pop( this );
       
   189     }
       
   190 
       
   191 // --------------------------------------------------------------------------
       
   192 // CPbk2DeleteContactsCmd::AddObserver
       
   193 // --------------------------------------------------------------------------
       
   194 //
       
   195 void CPbk2DeleteContactsCmd::AddObserver(
       
   196         MPbk2CommandObserver& aObserver )
       
   197     {
       
   198     iCommandObserver = &aObserver;
       
   199     }
       
   200 
       
   201 // --------------------------------------------------------------------------
       
   202 // CPbk2DeleteContactsCmd::ResetUiControl
       
   203 // --------------------------------------------------------------------------
       
   204 //
       
   205 void CPbk2DeleteContactsCmd::ResetUiControl(
       
   206         MPbk2ContactUiControl& aUiControl)
       
   207     {
       
   208     if (iUiControl == &aUiControl)
       
   209         {
       
   210         iUiControl = NULL;
       
   211         }
       
   212     }
       
   213 
       
   214 // --------------------------------------------------------------------------
       
   215 // CPbk2DeleteContactsCmd::DoCancel
       
   216 // --------------------------------------------------------------------------
       
   217 //
       
   218 void CPbk2DeleteContactsCmd::DoCancel()
       
   219     {
       
   220     }
       
   221 
       
   222 // --------------------------------------------------------------------------
       
   223 // CPbk2DeleteContactsCmd::RunL
       
   224 // --------------------------------------------------------------------------
       
   225 //
       
   226 void CPbk2DeleteContactsCmd::RunL()
       
   227     {
       
   228     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   229         ("CPbk2DeleteContactsCmd::RunL() start"), this);
       
   230 
       
   231    switch ( iState )
       
   232         {
       
   233         case ERetrieving:
       
   234             {
       
   235             // Retrieve phase is executed only when there is one contact
       
   236             // to delete. Check is the contact marked one or focused one.            
       
   237             if ( iContactIterator )
       
   238                 {
       
   239                 iContactIterator->SetToFirst();
       
   240                 if ( iContactIterator->HasNext() )
       
   241                     {
       
   242                     MVPbkContactLink* link = iContactIterator->NextL();
       
   243                     CleanupDeletePushL( link );
       
   244                     if ( link )
       
   245                         {
       
   246                         RetrieveContactL( *link );
       
   247                         }                    
       
   248                     CleanupStack::PopAndDestroy(); // link
       
   249                     }                   
       
   250                 }
       
   251             else
       
   252                 {
       
   253                 if (iUiControl)
       
   254                     {
       
   255                     const MVPbkBaseContact* focusedContact =
       
   256                             iUiControl->FocusedContactL();
       
   257                     if ( focusedContact )
       
   258                         {
       
   259                         MVPbkContactLink* link = focusedContact->CreateLinkLC();
       
   260                         RetrieveContactL( *link );
       
   261                         CleanupStack::PopAndDestroy(); // link
       
   262                         }
       
   263                     }
       
   264                 else
       
   265                     {
       
   266                     // nothing to delete
       
   267                     IssueStopRequest( EStopping );
       
   268                     }
       
   269                 }            
       
   270             break;
       
   271             }
       
   272         case EConfirming:
       
   273             {
       
   274             ConfirmDeletionL();
       
   275             break;
       
   276             }
       
   277         case EStarting:
       
   278             {
       
   279             if( iDecorator )
       
   280             	{
       
   281                 iDecorator->ProcessStartedL( iContactCount );
       
   282             	}
       
   283             
       
   284             if ( iContactIterator )
       
   285                 {
       
   286                 iContactIterator->SetToLast();
       
   287                 }
       
   288             DoDeleteContactsL();
       
   289             break;
       
   290             }
       
   291         case EDeleting:
       
   292             {
       
   293             // Do nothing
       
   294             break;
       
   295             }
       
   296         case EStopping:
       
   297             {
       
   298             // Decorator calls ProcessDismissed
       
   299             if( iDecorator )
       
   300             	{
       
   301                 iDecorator->ProcessStopped();            	
       
   302             	}
       
   303             else
       
   304             	{
       
   305                 ProcessDismissed( KErrNone );
       
   306             	}
       
   307             break;
       
   308             }
       
   309         case ECanceling:
       
   310             {
       
   311             ProcessDismissed( KErrCancel );
       
   312             break;
       
   313             }
       
   314         default:
       
   315             {
       
   316             __ASSERT_DEBUG(EFalse, Panic(ERunL_InvalidState));
       
   317             break;
       
   318             }
       
   319         }
       
   320 
       
   321     PBK2_DEBUG_PRINT
       
   322         (PBK2_DEBUG_STRING("CPbk2DeleteContactsCmd::RunL end"));
       
   323     }
       
   324 
       
   325 // --------------------------------------------------------------------------
       
   326 // CPbk2DeleteContactsCmd::RunError
       
   327 // --------------------------------------------------------------------------
       
   328 //
       
   329 TInt CPbk2DeleteContactsCmd::RunError( 
       
   330         TInt aError )
       
   331     {
       
   332     return FilterErrors( aError );
       
   333     }
       
   334 
       
   335 // --------------------------------------------------------------------------
       
   336 // CPbk2DeleteContactsCmd::VPbkSingleContactOperationComplete
       
   337 // --------------------------------------------------------------------------
       
   338 //
       
   339 void CPbk2DeleteContactsCmd::VPbkSingleContactOperationComplete(
       
   340         MVPbkContactOperationBase& aOperation,
       
   341         MVPbkStoreContact* aContact )
       
   342     {
       
   343     if ( &aOperation == iRetrieveOperation )
       
   344         {
       
   345         delete iRetrieveOperation;
       
   346         iRetrieveOperation = NULL;
       
   347 
       
   348         // We now have a store contact and we can issue a confirmation
       
   349         iStoreContact = aContact;
       
   350         iState = EConfirming;
       
   351         IssueRequest();
       
   352         }
       
   353     }
       
   354 
       
   355 // --------------------------------------------------------------------------
       
   356 // CPbk2DeleteContactsCmd::VPbkSingleContactOperationFailed
       
   357 // --------------------------------------------------------------------------
       
   358 //
       
   359 void CPbk2DeleteContactsCmd::VPbkSingleContactOperationFailed(
       
   360         MVPbkContactOperationBase& aOperation,
       
   361         TInt aError )
       
   362     {
       
   363     if ( &aOperation == iRetrieveOperation )
       
   364         {
       
   365         delete iRetrieveOperation;
       
   366         iRetrieveOperation = NULL;
       
   367 
       
   368         // We cannot get the contact, so we have to
       
   369         // fail. We cannot continue, since this operation
       
   370         // was executed only in case of one contact.
       
   371         ProcessDismissed( aError );
       
   372         }
       
   373     }
       
   374 
       
   375 // --------------------------------------------------------------------------
       
   376 // CPbk2DeleteContactsCmd::StepComplete
       
   377 // --------------------------------------------------------------------------
       
   378 //
       
   379 void CPbk2DeleteContactsCmd::StepComplete(
       
   380         MVPbkContactOperationBase& aOperation,
       
   381         TInt aStepSize )
       
   382     {
       
   383     if ( &aOperation == iDeleteOperation )
       
   384         {
       
   385         // Indicate process advancement to the decorator
       
   386         if( iDecorator )
       
   387         	{
       
   388             iDecorator->ProcessAdvance( aStepSize );
       
   389         	}
       
   390         }
       
   391     }
       
   392 
       
   393 // --------------------------------------------------------------------------
       
   394 // CPbk2DeleteContactsCmd::StepFailed
       
   395 // --------------------------------------------------------------------------
       
   396 //
       
   397 TBool CPbk2DeleteContactsCmd::StepFailed(
       
   398         MVPbkContactOperationBase& aOperation,
       
   399         TInt /*aStepSize*/,
       
   400         TInt aError )
       
   401     {
       
   402     TBool result = ETrue;
       
   403 
       
   404     if ( &aOperation == iDeleteOperation )
       
   405         {
       
   406         // Check whether the error is a serious one
       
   407         TInt err = FilterErrors( aError );
       
   408         if ( err != KErrNone )
       
   409             {
       
   410             Cancel();
       
   411             result = EFalse;
       
   412             }
       
   413         }
       
   414 
       
   415     return result;
       
   416     }
       
   417 
       
   418 // --------------------------------------------------------------------------
       
   419 // CPbk2DeleteContactsCmd::OperationComplete
       
   420 // --------------------------------------------------------------------------
       
   421 //
       
   422 void CPbk2DeleteContactsCmd::OperationComplete(
       
   423         MVPbkContactOperationBase& aOperation )
       
   424     {
       
   425     if ( &aOperation == iDeleteOperation )
       
   426         {
       
   427         delete iDeleteOperation;
       
   428         iDeleteOperation = NULL;
       
   429 
       
   430         if ( iContactIterator && iContactIterator->HasPrevious() )
       
   431             {
       
   432             TRAPD( error, DoDeleteContactsL() );
       
   433             if ( error != KErrNone )
       
   434                 {
       
   435                 FilterErrors( error );
       
   436                 IssueStopRequest( EStopping );
       
   437                 }
       
   438             }
       
   439         else
       
   440             {
       
   441             IssueStopRequest( EStopping );
       
   442             }
       
   443         }
       
   444     }
       
   445 
       
   446 // --------------------------------------------------------------------------
       
   447 // CPbk2DeleteContactsCmd::ProcessDismissed
       
   448 // --------------------------------------------------------------------------
       
   449 //
       
   450 void CPbk2DeleteContactsCmd::ProcessDismissed( TInt aCancelCode )
       
   451     {
       
   452     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   453         ("CPbk2DeleteContactsCmd::ProcessDismissed()"));
       
   454 
       
   455     __ASSERT_DEBUG(iCommandObserver, Panic(EPanicPreCond_Null_Pointer));
       
   456 
       
   457     Cancel();
       
   458     delete iDeleteOperation;
       
   459     iDeleteOperation = NULL;
       
   460 
       
   461     if ( aCancelCode != KErrCancel && iUiControl)
       
   462         {
       
   463         // Don't remove list markings if user canceled
       
   464         iUiControl->SetBlank(EFalse);
       
   465         iUiControl->UpdateAfterCommandExecution();
       
   466         }
       
   467 
       
   468     // Notify command owner that the command has finished
       
   469     iCommandObserver->CommandFinished( *this );
       
   470     }
       
   471 
       
   472 // --------------------------------------------------------------------------
       
   473 // CPbk2DeleteContactsCmd::RetrieveContactL
       
   474 // --------------------------------------------------------------------------
       
   475 //
       
   476 void CPbk2DeleteContactsCmd::RetrieveContactL(
       
   477         const MVPbkContactLink& aContactLink )
       
   478     {
       
   479     // Retrieve the actual store contact from the given link
       
   480     iRetrieveOperation = iAppServices->
       
   481         ContactManager().RetrieveContactL( aContactLink, *this );
       
   482     }
       
   483 
       
   484 // --------------------------------------------------------------------------
       
   485 // CPbk2DeleteContactsCmd::DoDeleteContactsL
       
   486 // --------------------------------------------------------------------------
       
   487 //
       
   488 void CPbk2DeleteContactsCmd::DoDeleteContactsL()
       
   489     {
       
   490     delete iContactsToDelete;
       
   491     iContactsToDelete = NULL;
       
   492     iContactsToDelete = CVPbkContactLinkArray::NewL();
       
   493     const TInt KDeleteBlockSize = 200;
       
   494 
       
   495     if ( iContactIterator )
       
   496         {
       
   497         for ( TInt i = 0; i < KDeleteBlockSize &&
       
   498                 iContactIterator->HasPrevious(); ++i )
       
   499             {
       
   500             MVPbkContactLink* link = iContactIterator->PreviousL();
       
   501             CleanupDeletePushL( link );
       
   502             iContactsToDelete->AppendL( link ); // takes ownership
       
   503             CleanupStack::Pop(); // link
       
   504             }
       
   505         }
       
   506     else
       
   507         {
       
   508         __ASSERT_DEBUG( iStoreContact,
       
   509             Panic( EPanicLogic_DoDeleteContactsL ) );
       
   510 
       
   511         MVPbkContactLink* link = iStoreContact->CreateLinkLC();
       
   512         iContactsToDelete->AppendL( link ); // takes ownership
       
   513         CleanupStack::Pop(); // link
       
   514         }
       
   515 
       
   516     iDeleteOperation = iAppServices->
       
   517         ContactManager().DeleteContactsL( *iContactsToDelete, *this );
       
   518 
       
   519     if (iUiControl)
       
   520         {
       
   521         // Blank UI control to avoid flicker
       
   522         iUiControl->SetBlank( ETrue );
       
   523         }
       
   524 
       
   525     iState = EDeleting;
       
   526     IssueRequest();
       
   527     }
       
   528 
       
   529 // --------------------------------------------------------------------------
       
   530 // CPbk2DeleteContactsCmd::FilterErrors
       
   531 // --------------------------------------------------------------------------
       
   532 //
       
   533 inline TInt CPbk2DeleteContactsCmd::FilterErrors( TInt aErrorCode )
       
   534 	{
       
   535 	PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   536         ( "CPbk2DeleteContactsCmd::FilterErrors(%d) start" ), aErrorCode );
       
   537 
       
   538 	TInt result = aErrorCode;
       
   539 	switch ( aErrorCode )
       
   540 		{
       
   541 		case KErrNotFound:  // FALLTHROUGH
       
   542 		case KErrInUse:
       
   543 			{
       
   544 			// If you only have one contact or it's the last contact that failed, 
       
   545 			// remove the progress bar. 
       
   546 			if ( iContactCount == KOneContact || 
       
   547 				( ( iContactIterator ) && !( iContactIterator->HasNext() ) ) ) 
       
   548 				{ 
       
   549 				Cancel(); 
       
   550 				if ( iDecorator )
       
   551 					{
       
   552 					iDecorator->ProcessStopped();
       
   553 				 	}
       
   554 				ProcessDismissed( aErrorCode );
       
   555 				} 
       
   556 			else 
       
   557 				{ 
       
   558 				// Ignore these errors 
       
   559 				// KErrNotFound means that somebody got the contact first  
       
   560 				// KErrInUse means that the contact is open
       
   561 				result = KErrNone;   
       
   562 				}
       
   563 			CCoeEnv::Static()->HandleError( aErrorCode ); 
       
   564 			
       
   565 			break; 
       
   566 			}
       
   567 
       
   568 		default:  // Something more serious happened -> give up
       
   569 			{
       
   570 			Cancel();
       
   571 			ProcessDismissed( aErrorCode );
       
   572 			
       
   573 			break;
       
   574 			}
       
   575 		}
       
   576 	
       
   577 	PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   578 		( "CPbk2DeleteContactsCmd::FilterErrors(%d) end" ), result );
       
   579 	
       
   580 	return result;
       
   581 	}
       
   582 
       
   583 // --------------------------------------------------------------------------
       
   584 // CPbk2DeleteContactsCmd::IssueRequest
       
   585 // --------------------------------------------------------------------------
       
   586 //
       
   587 void CPbk2DeleteContactsCmd::IssueRequest()
       
   588     {
       
   589     TRequestStatus* status = &iStatus;
       
   590     User::RequestComplete( status, KErrNone );
       
   591     SetActive();
       
   592     }
       
   593 
       
   594 // --------------------------------------------------------------------------
       
   595 // CPbk2DeleteContactsCmd::IssueStopRequest
       
   596 // --------------------------------------------------------------------------
       
   597 //
       
   598 void CPbk2DeleteContactsCmd::IssueStopRequest( TProcessState aState )
       
   599     {
       
   600     iState = aState;
       
   601     if ( !IsActive() )
       
   602         {
       
   603         IssueRequest();
       
   604         }
       
   605     }
       
   606 
       
   607 // --------------------------------------------------------------------------
       
   608 // CPbk2DeleteContactsCmd::ConfirmDeletionL
       
   609 // --------------------------------------------------------------------------
       
   610 //
       
   611 void CPbk2DeleteContactsCmd::ConfirmDeletionL()
       
   612     {
       
   613     CPbk2GeneralConfirmationQuery* query =
       
   614             CPbk2GeneralConfirmationQuery::NewL();
       
   615     TInt queryResult = KErrNotFound;
       
   616     if (iContactCount > 1)
       
   617         {
       
   618         queryResult = query->ExecuteLD(
       
   619             iContactCount, R_QTN_PHOB_QUERY_DELETE_N_ENTRIES );
       
   620         }
       
   621     else
       
   622         {
       
   623         queryResult = query->ExecuteLD(
       
   624                     *iStoreContact, R_QTN_QUERY_COMMON_CONF_DELETE, MPbk2ContactNameFormatter::EPreserveAllOriginalSpaces );
       
   625             
       
   626         }
       
   627 
       
   628     if (queryResult)
       
   629         {
       
   630         // Continue with starting the deletion
       
   631         iState = EStarting;
       
   632         IssueRequest();
       
   633         }
       
   634     else
       
   635         {
       
   636         IssueStopRequest(ECanceling);
       
   637         }
       
   638     }
       
   639 
       
   640 // --------------------------------------------------------------------------
       
   641 // CPbk2DeleteContactsCmd::GetContactCountL
       
   642 // --------------------------------------------------------------------------
       
   643 //
       
   644 TInt CPbk2DeleteContactsCmd::GetContactCountL()
       
   645     {
       
   646     TInt result = 0;
       
   647 
       
   648     if ( iContactIterator )
       
   649         {
       
   650         iContactIterator->SetToFirst();
       
   651         while( iContactIterator->HasNext() )
       
   652             {
       
   653             MVPbkContactLink* link = iContactIterator->NextL();
       
   654             if ( link && !IsFromReadOnlyStore( *link ) )
       
   655                 {
       
   656                 ++result;
       
   657                 }
       
   658             delete link;
       
   659             link = NULL;
       
   660             }
       
   661         }
       
   662     else
       
   663         {
       
   664         if (iUiControl)
       
   665             {            
       
   666             // There was no iterator so there are no selected contacts,
       
   667             // this means we are deleting only the focused contact
       
   668             const MVPbkBaseContact* focusedContact = iUiControl->FocusedContactL();
       
   669             if ( focusedContact )
       
   670                 {
       
   671                 MVPbkContactLink* link = focusedContact->CreateLinkLC();
       
   672                 if ( link && !IsFromReadOnlyStore( *link ) )
       
   673                     {
       
   674                     ++result;
       
   675                     }
       
   676                 CleanupStack::PopAndDestroy(); // link
       
   677                 }
       
   678             }
       
   679         }
       
   680 
       
   681     return result;
       
   682     }
       
   683 
       
   684 // --------------------------------------------------------------------------
       
   685 // CPbk2DeleteContactsCmd::IsFromReadOnlyStore
       
   686 // --------------------------------------------------------------------------
       
   687 //
       
   688 TBool CPbk2DeleteContactsCmd::IsFromReadOnlyStore
       
   689         ( const MVPbkContactLink& aContactLink ) const
       
   690     {
       
   691     TBool ret = EFalse;
       
   692 
       
   693     const MVPbkContactStore& store = aContactLink.ContactStore();
       
   694     if ( store.StoreProperties().ReadOnly() )
       
   695         {
       
   696         ret = ETrue;
       
   697         }
       
   698 
       
   699     return ret;
       
   700     }
       
   701 
       
   702 //  End of File