phonebookui/Phonebook2/CommandsExtension/src/CPbk2DeleteContactsCmd.cpp
branchRCL_3
changeset 20 f4a778e096c2
child 21 9da50d567e3c
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     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                     while ( MVPbkContactLink* link = iContactIterator->NextL() )
       
   243                         {
       
   244                         if ( !IsFromReadOnlyStore( *link ) )
       
   245                             {
       
   246                             CleanupDeletePushL( link );
       
   247                             RetrieveContactL( *link );
       
   248                             CleanupStack::PopAndDestroy(); // link
       
   249                             break;
       
   250                             }
       
   251                         }
       
   252                     }                   
       
   253                 }
       
   254             else
       
   255                 {
       
   256                 if (iUiControl)
       
   257                     {
       
   258                     const MVPbkBaseContact* focusedContact =
       
   259                             iUiControl->FocusedContactL();
       
   260                     if ( focusedContact )
       
   261                         {
       
   262                         MVPbkContactLink* link = focusedContact->CreateLinkLC();
       
   263                         RetrieveContactL( *link );
       
   264                         CleanupStack::PopAndDestroy(); // link
       
   265                         }
       
   266                     }
       
   267                 else
       
   268                     {
       
   269                     // nothing to delete
       
   270                     IssueStopRequest( EStopping );
       
   271                     }
       
   272                 }            
       
   273             break;
       
   274             }
       
   275         case EConfirming:
       
   276             {
       
   277             ConfirmDeletionL();
       
   278             break;
       
   279             }
       
   280         case EStarting:
       
   281             {
       
   282             
       
   283             // Returns NULL if there are no selected contacts.
       
   284             // In that case we will delete the focused contact.
       
   285             if ( iUiControl )
       
   286                 {
       
   287                 //Re-Fetch the Contact Iterator
       
   288                 MPbk2ContactLinkIterator* contactIterator = iUiControl->SelectedContactsIteratorL();
       
   289                 if ( contactIterator )
       
   290                     {
       
   291                     delete iContactIterator;
       
   292                     iContactIterator = contactIterator;
       
   293                     }
       
   294                 }
       
   295                 
       
   296             if( iDecorator )
       
   297             	{
       
   298                 iDecorator->ProcessStartedL( iContactCount );
       
   299             	}
       
   300             
       
   301             if ( iContactIterator )
       
   302                 {
       
   303                 iContactIterator->SetToLast();
       
   304                 }
       
   305             DoDeleteContactsL();
       
   306             break;
       
   307             }
       
   308         case EDeleting:
       
   309             {
       
   310             // Do nothing
       
   311             break;
       
   312             }
       
   313         case EStopping:
       
   314             {
       
   315             // Decorator calls ProcessDismissed
       
   316             if( iDecorator )
       
   317             	{
       
   318                 iDecorator->ProcessStopped();            	
       
   319             	}
       
   320             else
       
   321             	{
       
   322                 ProcessDismissed( KErrNone );
       
   323             	}
       
   324             break;
       
   325             }
       
   326         case ECanceling:
       
   327             {
       
   328             ProcessDismissed( KErrCancel );
       
   329             break;
       
   330             }
       
   331         default:
       
   332             {
       
   333             __ASSERT_DEBUG(EFalse, Panic(ERunL_InvalidState));
       
   334             break;
       
   335             }
       
   336         }
       
   337 
       
   338     PBK2_DEBUG_PRINT
       
   339         (PBK2_DEBUG_STRING("CPbk2DeleteContactsCmd::RunL end"));
       
   340     }
       
   341 
       
   342 // --------------------------------------------------------------------------
       
   343 // CPbk2DeleteContactsCmd::RunError
       
   344 // --------------------------------------------------------------------------
       
   345 //
       
   346 TInt CPbk2DeleteContactsCmd::RunError( 
       
   347         TInt aError )
       
   348     {
       
   349     return FilterErrors( aError );
       
   350     }
       
   351 
       
   352 // --------------------------------------------------------------------------
       
   353 // CPbk2DeleteContactsCmd::VPbkSingleContactOperationComplete
       
   354 // --------------------------------------------------------------------------
       
   355 //
       
   356 void CPbk2DeleteContactsCmd::VPbkSingleContactOperationComplete(
       
   357         MVPbkContactOperationBase& aOperation,
       
   358         MVPbkStoreContact* aContact )
       
   359     {
       
   360     if ( &aOperation == iRetrieveOperation )
       
   361         {
       
   362         delete iRetrieveOperation;
       
   363         iRetrieveOperation = NULL;
       
   364 
       
   365         // We now have a store contact and we can issue a confirmation
       
   366         iStoreContact = aContact;
       
   367         iState = EConfirming;
       
   368         IssueRequest();
       
   369         }
       
   370     }
       
   371 
       
   372 // --------------------------------------------------------------------------
       
   373 // CPbk2DeleteContactsCmd::VPbkSingleContactOperationFailed
       
   374 // --------------------------------------------------------------------------
       
   375 //
       
   376 void CPbk2DeleteContactsCmd::VPbkSingleContactOperationFailed(
       
   377         MVPbkContactOperationBase& aOperation,
       
   378         TInt aError )
       
   379     {
       
   380     if ( &aOperation == iRetrieveOperation )
       
   381         {
       
   382         delete iRetrieveOperation;
       
   383         iRetrieveOperation = NULL;
       
   384 
       
   385         // We cannot get the contact, so we have to
       
   386         // fail. We cannot continue, since this operation
       
   387         // was executed only in case of one contact.
       
   388         ProcessDismissed( aError );
       
   389         }
       
   390     }
       
   391 
       
   392 // --------------------------------------------------------------------------
       
   393 // CPbk2DeleteContactsCmd::StepComplete
       
   394 // --------------------------------------------------------------------------
       
   395 //
       
   396 void CPbk2DeleteContactsCmd::StepComplete(
       
   397         MVPbkContactOperationBase& aOperation,
       
   398         TInt aStepSize )
       
   399     {
       
   400     if ( &aOperation == iDeleteOperation )
       
   401         {
       
   402         // Indicate process advancement to the decorator
       
   403         if( iDecorator )
       
   404         	{
       
   405             iDecorator->ProcessAdvance( aStepSize );
       
   406         	}
       
   407         }
       
   408     }
       
   409 
       
   410 // --------------------------------------------------------------------------
       
   411 // CPbk2DeleteContactsCmd::StepFailed
       
   412 // --------------------------------------------------------------------------
       
   413 //
       
   414 TBool CPbk2DeleteContactsCmd::StepFailed(
       
   415         MVPbkContactOperationBase& aOperation,
       
   416         TInt /*aStepSize*/,
       
   417         TInt aError )
       
   418     {
       
   419     TBool result = ETrue;
       
   420 
       
   421     if ( &aOperation == iDeleteOperation )
       
   422         {
       
   423         // Check whether the error is a serious one
       
   424         TInt err = FilterErrors( aError );
       
   425         if ( err != KErrNone )
       
   426             {
       
   427             Cancel();
       
   428             result = EFalse;
       
   429             }
       
   430         }
       
   431 
       
   432     return result;
       
   433     }
       
   434 
       
   435 // --------------------------------------------------------------------------
       
   436 // CPbk2DeleteContactsCmd::OperationComplete
       
   437 // --------------------------------------------------------------------------
       
   438 //
       
   439 void CPbk2DeleteContactsCmd::OperationComplete(
       
   440         MVPbkContactOperationBase& aOperation )
       
   441     {
       
   442     if ( &aOperation == iDeleteOperation )
       
   443         {
       
   444         delete iDeleteOperation;
       
   445         iDeleteOperation = NULL;
       
   446 
       
   447         if ( iContactIterator && iContactIterator->HasPrevious() )
       
   448             {
       
   449             TRAPD( error, DoDeleteContactsL() );
       
   450             if ( error != KErrNone )
       
   451                 {
       
   452                 FilterErrors( error );
       
   453                 IssueStopRequest( EStopping );
       
   454                 }
       
   455             }
       
   456         else
       
   457             {
       
   458             IssueStopRequest( EStopping );
       
   459             }
       
   460         }
       
   461     }
       
   462 
       
   463 // --------------------------------------------------------------------------
       
   464 // CPbk2DeleteContactsCmd::ProcessDismissed
       
   465 // --------------------------------------------------------------------------
       
   466 //
       
   467 void CPbk2DeleteContactsCmd::ProcessDismissed( TInt aCancelCode )
       
   468     {
       
   469     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   470         ("CPbk2DeleteContactsCmd::ProcessDismissed()"));
       
   471 
       
   472     __ASSERT_DEBUG(iCommandObserver, Panic(EPanicPreCond_Null_Pointer));
       
   473 
       
   474     Cancel();
       
   475     delete iDeleteOperation;
       
   476     iDeleteOperation = NULL;
       
   477 
       
   478     if ( aCancelCode != KErrCancel && iUiControl)
       
   479         {
       
   480         // Don't remove list markings if user canceled
       
   481         iUiControl->SetBlank(EFalse);
       
   482         iUiControl->UpdateAfterCommandExecution();
       
   483         }
       
   484 
       
   485     // Notify command owner that the command has finished
       
   486     iCommandObserver->CommandFinished( *this );
       
   487     }
       
   488 
       
   489 // --------------------------------------------------------------------------
       
   490 // CPbk2DeleteContactsCmd::RetrieveContactL
       
   491 // --------------------------------------------------------------------------
       
   492 //
       
   493 void CPbk2DeleteContactsCmd::RetrieveContactL(
       
   494         const MVPbkContactLink& aContactLink )
       
   495     {
       
   496     // Retrieve the actual store contact from the given link
       
   497     iRetrieveOperation = iAppServices->
       
   498         ContactManager().RetrieveContactL( aContactLink, *this );
       
   499     }
       
   500 
       
   501 // --------------------------------------------------------------------------
       
   502 // CPbk2DeleteContactsCmd::DoDeleteContactsL
       
   503 // --------------------------------------------------------------------------
       
   504 //
       
   505 void CPbk2DeleteContactsCmd::DoDeleteContactsL()
       
   506     {
       
   507     delete iContactsToDelete;
       
   508     iContactsToDelete = NULL;
       
   509     iContactsToDelete = CVPbkContactLinkArray::NewL();
       
   510     const TInt KDeleteBlockSize = 200;
       
   511 
       
   512     if ( iContactIterator )
       
   513         {
       
   514         for ( TInt i = 0; i < KDeleteBlockSize &&
       
   515                 iContactIterator->HasPrevious(); ++i )
       
   516             {
       
   517             MVPbkContactLink* link = iContactIterator->PreviousL();
       
   518             CleanupDeletePushL( link );
       
   519             iContactsToDelete->AppendL( link ); // takes ownership
       
   520             CleanupStack::Pop(); // link
       
   521             }
       
   522         }
       
   523     else
       
   524         {
       
   525         __ASSERT_DEBUG( iStoreContact,
       
   526             Panic( EPanicLogic_DoDeleteContactsL ) );
       
   527 
       
   528         MVPbkContactLink* link = iStoreContact->CreateLinkLC();
       
   529         iContactsToDelete->AppendL( link ); // takes ownership
       
   530         CleanupStack::Pop(); // link
       
   531         }
       
   532 
       
   533     iDeleteOperation = iAppServices->
       
   534         ContactManager().DeleteContactsL( *iContactsToDelete, *this );
       
   535 
       
   536     if (iUiControl)
       
   537         {
       
   538         // Blank UI control to avoid flicker
       
   539         iUiControl->SetBlank( ETrue );
       
   540         }
       
   541 
       
   542     iState = EDeleting;
       
   543     IssueRequest();
       
   544     }
       
   545 
       
   546 // --------------------------------------------------------------------------
       
   547 // CPbk2DeleteContactsCmd::FilterErrors
       
   548 // --------------------------------------------------------------------------
       
   549 //
       
   550 inline TInt CPbk2DeleteContactsCmd::FilterErrors( TInt aErrorCode )
       
   551 	{
       
   552 	PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   553         ( "CPbk2DeleteContactsCmd::FilterErrors(%d) start" ), aErrorCode );
       
   554 
       
   555 	TInt result = aErrorCode;
       
   556 	switch ( aErrorCode )
       
   557 		{
       
   558 		case KErrNotFound:  // FALLTHROUGH
       
   559 		case KErrInUse:
       
   560 			{
       
   561 			// If you only have one contact or it's the last contact that failed, 
       
   562 			// remove the progress bar. 
       
   563 			if ( iContactCount == KOneContact || 
       
   564 				( ( iContactIterator ) && !( iContactIterator->HasNext() ) ) ) 
       
   565 				{ 
       
   566 				Cancel(); 
       
   567 				if ( iDecorator )
       
   568 					{
       
   569 					iDecorator->ProcessStopped();
       
   570 				 	}
       
   571 				ProcessDismissed( aErrorCode );
       
   572 				} 
       
   573 			else 
       
   574 				{ 
       
   575 				// Ignore these errors 
       
   576 				// KErrNotFound means that somebody got the contact first  
       
   577 				// KErrInUse means that the contact is open
       
   578 				result = KErrNone;   
       
   579 				}
       
   580 			CCoeEnv::Static()->HandleError( aErrorCode ); 
       
   581 			
       
   582 			break; 
       
   583 			}
       
   584 
       
   585 		default:  // Something more serious happened -> give up
       
   586 			{
       
   587 			Cancel();
       
   588 			ProcessDismissed( aErrorCode );
       
   589 			
       
   590 			break;
       
   591 			}
       
   592 		}
       
   593 	
       
   594 	PBK2_DEBUG_PRINT( PBK2_DEBUG_STRING
       
   595 		( "CPbk2DeleteContactsCmd::FilterErrors(%d) end" ), result );
       
   596 	
       
   597 	return result;
       
   598 	}
       
   599 
       
   600 // --------------------------------------------------------------------------
       
   601 // CPbk2DeleteContactsCmd::IssueRequest
       
   602 // --------------------------------------------------------------------------
       
   603 //
       
   604 void CPbk2DeleteContactsCmd::IssueRequest()
       
   605     {
       
   606     TRequestStatus* status = &iStatus;
       
   607     User::RequestComplete( status, KErrNone );
       
   608     SetActive();
       
   609     }
       
   610 
       
   611 // --------------------------------------------------------------------------
       
   612 // CPbk2DeleteContactsCmd::IssueStopRequest
       
   613 // --------------------------------------------------------------------------
       
   614 //
       
   615 void CPbk2DeleteContactsCmd::IssueStopRequest( TProcessState aState )
       
   616     {
       
   617     iState = aState;
       
   618     if ( !IsActive() )
       
   619         {
       
   620         IssueRequest();
       
   621         }
       
   622     }
       
   623 
       
   624 // --------------------------------------------------------------------------
       
   625 // CPbk2DeleteContactsCmd::ConfirmDeletionL
       
   626 // --------------------------------------------------------------------------
       
   627 //
       
   628 void CPbk2DeleteContactsCmd::ConfirmDeletionL()
       
   629     {
       
   630     CPbk2GeneralConfirmationQuery* query =
       
   631             CPbk2GeneralConfirmationQuery::NewL();
       
   632     TInt queryResult = KErrNotFound;
       
   633     if (iContactCount > 1)
       
   634         {
       
   635         queryResult = query->ExecuteLD(
       
   636             iContactCount, R_QTN_PHOB_QUERY_DELETE_N_ENTRIES );
       
   637         }
       
   638     else
       
   639         {
       
   640         queryResult = query->ExecuteLD(
       
   641                     *iStoreContact, R_QTN_QUERY_COMMON_CONF_DELETE, MPbk2ContactNameFormatter::EPreserveAllOriginalSpaces );
       
   642             
       
   643         }
       
   644 
       
   645     if (queryResult)
       
   646         {
       
   647         // Continue with starting the deletion
       
   648         iState = EStarting;
       
   649         IssueRequest();
       
   650         }
       
   651     else
       
   652         {
       
   653         IssueStopRequest(ECanceling);
       
   654         }
       
   655     }
       
   656 
       
   657 // --------------------------------------------------------------------------
       
   658 // CPbk2DeleteContactsCmd::GetContactCountL
       
   659 // --------------------------------------------------------------------------
       
   660 //
       
   661 TInt CPbk2DeleteContactsCmd::GetContactCountL()
       
   662     {
       
   663     TInt result = 0;
       
   664 
       
   665     if ( iContactIterator )
       
   666         {
       
   667         iContactIterator->SetToFirst();
       
   668         while( iContactIterator->HasNext() )
       
   669             {
       
   670             MVPbkContactLink* link = iContactIterator->NextL();
       
   671             if ( link && !IsFromReadOnlyStore( *link ) )
       
   672                 {
       
   673                 ++result;
       
   674                 }
       
   675             delete link;
       
   676             link = NULL;
       
   677             }
       
   678         }
       
   679     else
       
   680         {
       
   681         if (iUiControl)
       
   682             {            
       
   683             // There was no iterator so there are no selected contacts,
       
   684             // this means we are deleting only the focused contact
       
   685             const MVPbkBaseContact* focusedContact = iUiControl->FocusedContactL();
       
   686             if ( focusedContact )
       
   687                 {
       
   688                 MVPbkContactLink* link = focusedContact->CreateLinkLC();
       
   689                 if ( link && !IsFromReadOnlyStore( *link ) )
       
   690                     {
       
   691                     ++result;
       
   692                     }
       
   693                 CleanupStack::PopAndDestroy(); // link
       
   694                 }
       
   695             }
       
   696         }
       
   697 
       
   698     return result;
       
   699     }
       
   700 
       
   701 // --------------------------------------------------------------------------
       
   702 // CPbk2DeleteContactsCmd::IsFromReadOnlyStore
       
   703 // --------------------------------------------------------------------------
       
   704 //
       
   705 TBool CPbk2DeleteContactsCmd::IsFromReadOnlyStore
       
   706         ( const MVPbkContactLink& aContactLink ) const
       
   707     {
       
   708     TBool ret = EFalse;
       
   709 
       
   710     const MVPbkContactStore& store = aContactLink.ContactStore();
       
   711     if ( store.StoreProperties().ReadOnly() )
       
   712         {
       
   713         ret = ETrue;
       
   714         }
       
   715 
       
   716     return ret;
       
   717     }
       
   718 
       
   719 //  End of File