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