phonebookui/Phonebook2/UIControls/src/CPbk2FetchResults.cpp
branchRCL_3
changeset 85 38bb213f60ba
parent 63 f4a778e096c2
equal deleted inserted replaced
74:6b5524b4f673 85:38bb213f60ba
    36 #include <MVPbkContactOperationBase.h>
    36 #include <MVPbkContactOperationBase.h>
    37 #include <MVPbkContactViewBase.h>
    37 #include <MVPbkContactViewBase.h>
    38 
    38 
    39 // System includes
    39 // System includes
    40 #include <coemain.h>
    40 #include <coemain.h>
    41 #include <akninputblock.h>
       
    42 
    41 
    43 // Debugging headers
    42 // Debugging headers
    44 #include <Pbk2Debug.h>
    43 #include <Pbk2Debug.h>
    45 
    44 
    46 // --------------------------------------------------------------------------
    45 // --------------------------------------------------------------------------
    55           MPbk2FetchResultsObserver& aResultsObserver ) :
    54           MPbk2FetchResultsObserver& aResultsObserver ) :
    56                 iContactManager( aContactManager ),
    55                 iContactManager( aContactManager ),
    57                 iFetchDlg( aFetchDlg ),
    56                 iFetchDlg( aFetchDlg ),
    58                 iPages( aPages ),
    57                 iPages( aPages ),
    59                 iObserver( aObserver ),
    58                 iObserver( aObserver ),
    60                 iResultsObserver( aResultsObserver ),
    59                 iResultsObserver( aResultsObserver )
    61                 iWaitingForDelayedAppend( EFalse ),
       
    62                 iInputBlock( NULL )
       
    63     {
    60     {
    64     }
    61     }
    65 
    62 
    66 // --------------------------------------------------------------------------
    63 // --------------------------------------------------------------------------
    67 // CPbk2FetchResults::~CPbk2FetchResults
    64 // CPbk2FetchResults::~CPbk2FetchResults
    87         for ( TInt k = 0; k < iOperationQueue->Count(); k++ )
    84         for ( TInt k = 0; k < iOperationQueue->Count(); k++ )
    88             delete iOperationQueue->At(k);
    85             delete iOperationQueue->At(k);
    89         
    86         
    90         delete iOperationQueue;
    87         delete iOperationQueue;
    91         }
    88         }
    92     
       
    93     delete iWaitForAllOperationComplete;
       
    94     }
    89     }
    95 
    90 
    96 // --------------------------------------------------------------------------
    91 // --------------------------------------------------------------------------
    97 // CPbk2FetchResults::ConstructL
    92 // CPbk2FetchResults::ConstructL
    98 // --------------------------------------------------------------------------
    93 // --------------------------------------------------------------------------
   110         MVPbkContactStore& store = iStoreList->At( i );
   105         MVPbkContactStore& store = iStoreList->At( i );
   111         store.OpenL( *this );
   106         store.OpenL( *this );
   112         }
   107         }
   113     
   108     
   114     iOperationQueue = new (ELeave) CArrayFixFlat<CFRConatactOperation*>(4);
   109     iOperationQueue = new (ELeave) CArrayFixFlat<CFRConatactOperation*>(4);
   115     
       
   116     iWaitForAllOperationComplete = new (ELeave) CActiveSchedulerWait();
       
   117     }
   110     }
   118 
   111 
   119 // --------------------------------------------------------------------------
   112 // --------------------------------------------------------------------------
   120 // CPbk2FetchResults::NewL
   113 // CPbk2FetchResults::NewL
   121 // --------------------------------------------------------------------------
   114 // --------------------------------------------------------------------------
   138 // --------------------------------------------------------------------------
   131 // --------------------------------------------------------------------------
   139 // CPbk2FetchResults::AppendL
   132 // CPbk2FetchResults::AppendL
   140 // --------------------------------------------------------------------------
   133 // --------------------------------------------------------------------------
   141 //
   134 //
   142 void CPbk2FetchResults::AppendL( const MVPbkContactLink& aLink )
   135 void CPbk2FetchResults::AppendL( const MVPbkContactLink& aLink )
   143     { 
   136     {
   144     if ( iFetchDlg.IsSelectPermitted() )
   137     CFRConatactOperation* newAppendOperation = CFRConatactOperation::NewL( aLink, CFRConatactOperation::EAppendContact );
   145         {
   138     AppendContactOperationL(newAppendOperation);
   146         CFRConatactOperation* newAppendOperation = CFRConatactOperation::NewL( aLink, CFRConatactOperation::EAppendContact );
   139     ProcessNextContactOperationL();
   147         AppendContactOperationL(newAppendOperation);
       
   148         ProcessNextContactOperationL();
       
   149         }
       
   150     else
       
   151         {
       
   152         iPages.SelectContactL( aLink, EFalse );
       
   153         }
       
   154     }
   140     }
   155 
   141 
   156 // --------------------------------------------------------------------------
   142 // --------------------------------------------------------------------------
   157 // CPbk2FetchResults::AppendDelayedL
   143 // CPbk2FetchResults::AppendDelayedL
   158 // --------------------------------------------------------------------------
   144 // --------------------------------------------------------------------------
   159 //
   145 //
   160 void CPbk2FetchResults::AppendDelayedL( const MVPbkContactLink& aLink )
   146 void CPbk2FetchResults::AppendDelayedL( const MVPbkContactLink& aLink )
   161     {
   147     {
   162     // Add the feedback contact's operation to the head of the queue
       
   163     // in order to ensure that the checked contact's operation to be
       
   164     // handled firstly when phonebook receives the client feedback.
       
   165     CFRConatactOperation* newAppendOperation = CFRConatactOperation::NewL( aLink, CFRConatactOperation::EAppendContactDelayed );
   148     CFRConatactOperation* newAppendOperation = CFRConatactOperation::NewL( aLink, CFRConatactOperation::EAppendContactDelayed );
   166     iOperationQueue->InsertL( 0, newAppendOperation ); 
   149     AppendContactOperationL(newAppendOperation);
   167     // Waiting is over.
       
   168     iWaitingForDelayedAppend = EFalse;
       
   169     ProcessNextContactOperationL();
       
   170     }
       
   171 
       
   172 // --------------------------------------------------------------------------
       
   173 // CPbk2FetchResults::DenyAppendDelayedL
       
   174 // --------------------------------------------------------------------------
       
   175 //
       
   176 void CPbk2FetchResults::DenyAppendDelayedL( const MVPbkContactLink& aLink )
       
   177     {
       
   178     // Waiting is over, process next contact operation
       
   179     iWaitingForDelayedAppend = EFalse;
       
   180     ProcessNextContactOperationL();
   150     ProcessNextContactOperationL();
   181     }
   151     }
   182 
   152 
   183 // --------------------------------------------------------------------------
   153 // --------------------------------------------------------------------------
   184 // CPbk2FetchResults::RemoveL
   154 // CPbk2FetchResults::RemoveL
   201     iRetrieveOperation = NULL;
   171     iRetrieveOperation = NULL;
   202     
   172     
   203     RemoveCurrentContactOperation();
   173     RemoveCurrentContactOperation();
   204 
   174 
   205     iSelectedContacts->ResetAndDestroy();
   175     iSelectedContacts->ResetAndDestroy();
   206     }
       
   207 
       
   208 // --------------------------------------------------------------------------
       
   209 // CPbk2FetchResults::WaitOperationsCompleteL
       
   210 // --------------------------------------------------------------------------
       
   211 //
       
   212 void CPbk2FetchResults::WaitOperationsCompleteL()
       
   213     {
       
   214     if ( iWaitingForDelayedAppend || iOperationQueue->Count()>0 )
       
   215         {
       
   216         iInputBlock = CAknInputBlock::NewLC();
       
   217         CleanupStack::Pop( iInputBlock );
       
   218         
       
   219         iWaitForAllOperationComplete->Start();
       
   220         }
       
   221     }
   176     }
   222 
   177 
   223 // --------------------------------------------------------------------------
   178 // --------------------------------------------------------------------------
   224 // CPbk2FetchResults::Count
   179 // CPbk2FetchResults::Count
   225 // --------------------------------------------------------------------------
   180 // --------------------------------------------------------------------------
   371 
   326 
   372     if ( !aDelayed )
   327     if ( !aDelayed )
   373         {
   328         {
   374         // Observer needs to asked
   329         // Observer needs to asked
   375         accept = iObserver.AcceptFetchSelectionL( count, *link );
   330         accept = iObserver.AcceptFetchSelectionL( count, *link );
   376         // Determine whether accept query is needed
       
   377         if ( MPbk2FetchDlgObserver::EFetchDelayed == accept )
       
   378             {
       
   379             // Start to wait client feedback, block the operation queue,
       
   380             // process next operation until receive client feedback.
       
   381             iWaitingForDelayedAppend = ETrue;
       
   382             }
       
   383         }
   331         }
   384 
   332 
   385     if ( accept == MPbk2FetchDlgObserver::EFetchNo )
   333     if ( accept == MPbk2FetchDlgObserver::EFetchNo )
   386         {
   334         {
   387         // Observer did not accept or delayed the selection
   335         // Observer did not accept or delayed the selection
   539                           GetCurrentContactOperation()->GetOperationType();
   487                           GetCurrentContactOperation()->GetOperationType();
   540     
   488     
   541     // Remove executed operation from queue
   489     // Remove executed operation from queue
   542     RemoveCurrentContactOperation();
   490     RemoveCurrentContactOperation();
   543     
   491     
       
   492     // Initialize next operation from queue
       
   493     ProcessNextContactOperationL();   
   544     
   494     
   545     /**********************************************************************/
   495     /**********************************************************************/
   546     /**************! Dont use class members after SWITCH !*****************/
   496     /**************! Dont use class members after SWITCH !*****************/
   547     /*** DoAppendContactL, DoRemoveContactL are able to call destructor ***/
   497     /*** DoAppendContactL, DoRemoveContactL are able to call destructor ***/
   548     /**********************************************************************/
   498     /**********************************************************************/
   553     switch( operationType )
   503     switch( operationType )
   554         {
   504         {
   555         case CFRConatactOperation::EAppendContact:
   505         case CFRConatactOperation::EAppendContact:
   556             {
   506             {
   557             DoAppendContactL( *aContact, EFalse );
   507             DoAppendContactL( *aContact, EFalse );
   558             // Check whether next operation can be processed
       
   559             // after sending check request to client.
       
   560             ProcessNextContactOperationL();
       
   561             break;
   508             break;
   562             }
   509             }
   563             
   510             
   564         case CFRConatactOperation::EAppendContactDelayed:
   511         case CFRConatactOperation::EAppendContactDelayed:
   565             {
   512             {
   566             // Process new contact opretation before appending 
       
   567             // the delayed contact to results. It can save time.
       
   568             ProcessNextContactOperationL();   
       
   569             DoAppendContactL( *aContact, ETrue );
   513             DoAppendContactL( *aContact, ETrue );
   570             break;
   514             break;
   571             }
   515             }
   572         
   516         
   573         case CFRConatactOperation::ERemoveContact:
   517         case CFRConatactOperation::ERemoveContact:
   574             {
   518             {
   575             // Process new contact opretation before removing contact 
       
   576             // from results. It can save time.
       
   577             ProcessNextContactOperationL();   
       
   578             DoRemoveContactL( *aContact );
   519             DoRemoveContactL( *aContact );
   579             break;
   520             break;
   580             }
   521             }
   581         }
   522         }
   582     
   523     
   587 // CPbk2FetchResults::ProcessNextContactOperationL
   528 // CPbk2FetchResults::ProcessNextContactOperationL
   588 // --------------------------------------------------------------------------
   529 // --------------------------------------------------------------------------
   589 //
   530 //
   590 void CPbk2FetchResults::ProcessNextContactOperationL()
   531 void CPbk2FetchResults::ProcessNextContactOperationL()
   591     {
   532     {
   592     if( !iRetrieveOperation && !iWaitingForDelayedAppend )
   533     if( !iRetrieveOperation )
   593         {        
   534         {        
   594         // No operation is executing -> process next one
   535         // No operation is executing -> process next one
   595         
   536         
   596         if( GetCurrentContactOperation() )
   537         if( GetCurrentContactOperation() )
   597             {
   538             {
   598             // Start asynchronous contact retrieve operation, which completes
   539             // Start asynchronous contact retrieve operation, which completes
   599             // in CPbk2FetchResults::HandleContactOperationCompleteL.
   540             // in CPbk2FetchResults::HandleContactOperationCompleteL.
   600 			iRetrieveOperation =  iContactManager.RetrieveContactL( 
   541             iRetrieveOperation =  iContactManager.RetrieveContactL( *( GetCurrentContactOperation()->GetContactLink() ),
   601                     *( GetCurrentContactOperation()->GetContactLink() ),
   542                                                                    *this );
   602                     *this );
       
   603             }
   543             }
   604         else
   544         else
   605             {
   545             {
   606             if ( !iWaitingForDelayedAppend )
   546             // Empty operation queue -> do nothing
   607                 {
   547             PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING( "CPbk2FetchResults::ProcessNextContactOperationL emtpy queue" ));
   608                 // Every seleced contacts' operation finishes,
       
   609                 // stop the scheduler waiting for every operation.
       
   610                 if (iWaitForAllOperationComplete->IsStarted())
       
   611                     iWaitForAllOperationComplete->AsyncStop();
       
   612                 
       
   613                 // Stop blocking input 
       
   614                 delete iInputBlock;
       
   615                 iInputBlock = NULL;
       
   616                 }
       
   617             }
   548             }
   618         }
   549         }
   619     else
   550     else
   620         {
   551         {
   621         // Ongoing operation -> do nothing
   552         // Ongoing operation -> do nothing