phonebookui/Phonebook2/UIControls/src/CPbk2NamesListControl.cpp
branchRCL_3
changeset 3 04ab22b956c2
parent 0 e686773b3f54
child 14 81f8547efd4f
equal deleted inserted replaced
0:e686773b3f54 3:04ab22b956c2
    39 #include "cpbk2predictiveviewstack.h"
    39 #include "cpbk2predictiveviewstack.h"
    40 #include <Pbk2Commands.hrh>
    40 #include <Pbk2Commands.hrh>
    41 #include <Pbk2InternalUID.h>
    41 #include <Pbk2InternalUID.h>
    42 #include "CPbk2PredictiveSearchFilter.h"
    42 #include "CPbk2PredictiveSearchFilter.h"
    43 #include "cpbk2contactviewdoublelistbox.h"
    43 #include "cpbk2contactviewdoublelistbox.h"
       
    44 #include <CPbk2ThumbnailManager.h>
       
    45 #include <Pbk2CommonUi.rsg>
       
    46 #include <Pbk2UIControls.rsg>
    44 
    47 
    45 // Virtual Phonebook
    48 // Virtual Phonebook
    46 #include <MVPbkContactViewBase.h>
    49 #include <MVPbkContactViewBase.h>
    47 #include <MVPbkViewContact.h>
    50 #include <MVPbkViewContact.h>
    48 #include <MVPbkContactLink.h>
    51 #include <MVPbkContactLink.h>
       
    52 #include <CVPbkContactLinkArray.h>
    49 
    53 
    50 // System includes
    54 // System includes
    51 #include <barsread.h>
    55 #include <barsread.h>
    52 #include <aknsfld.h>
    56 #include <aknsfld.h>
    53 #include <AknPriv.hrh>
    57 #include <AknPriv.hrh>
    54 #include <featmgr.h>
    58 #include <featmgr.h>
       
    59 #include <AknWaitDialog.h>
    55 
    60 
    56 // Debugging headers
    61 // Debugging headers
    57 #include <Pbk2Debug.h>
    62 #include <Pbk2Debug.h>
    58 
    63 
    59 
    64 
   263         CEikListBox& iListBox;
   268         CEikListBox& iListBox;
   264         /// Ref: Event sender
   269         /// Ref: Event sender
   265         MPbk2UiControlEventSender& iEventSender;
   270         MPbk2UiControlEventSender& iEventSender;
   266     };
   271     };
   267 
   272 
       
   273 
       
   274 /**
       
   275  * Background Task Handler.
       
   276  */
       
   277 NONSHARABLE_CLASS(CPbk2NamesListControlBgTask) : public CActive
       
   278     {    
       
   279     
       
   280     public:
       
   281         CPbk2NamesListControlBgTask( CPbk2NamesListControl& aControl );
       
   282         ~CPbk2NamesListControlBgTask();
       
   283 
       
   284         void AddEvent( CPbk2NamesListControl::TPbk2NamesListBgEvents aEvent );
       
   285         void ClearAllEvents();
       
   286         void RemoveEvent( CPbk2NamesListControl::TPbk2NamesListBgEvents aEvent );
       
   287         
       
   288     private: // From CActive
       
   289         void DoCancel();
       
   290         void RunL();
       
   291         TInt RunError(TInt aError);
       
   292 
       
   293     private:
       
   294         //Owns
       
   295         RArray <CPbk2NamesListControl::TPbk2NamesListBgEvents> iEventQueue;  
       
   296         
       
   297         //doesnt Own
       
   298         CPbk2NamesListControl& iControl;
       
   299     };
       
   300 
       
   301 /**
       
   302  * A helper class for mass update cases.
       
   303  */
       
   304 NONSHARABLE_CLASS( CPbk2HandleMassUpdate ) : public CBase
       
   305     {
       
   306     public: // Construction and destruction
       
   307         /**
       
   308          * Creates new instance of this class.
       
   309          * @return new instance of this class.
       
   310          */
       
   311         static CPbk2HandleMassUpdate* NewL(CEikListBox& iListBox);
       
   312 
       
   313         /**
       
   314          * Destructor.
       
   315          */
       
   316        ~CPbk2HandleMassUpdate();
       
   317 
       
   318     public: 
       
   319         /**
       
   320          * Call this function after each update event.
       
   321          * @return  ETrue if this event is part of a mass update.
       
   322          */	
       
   323        TBool MassUpdateCheckThis();
       
   324 
       
   325         /**
       
   326          * Call this function to check if mass update process is ongoing.
       
   327          * @return  ETrue if mass update process is ongoing.
       
   328          */	   
       
   329        TBool MassUpdateDetected();
       
   330        
       
   331     private: 
       
   332         CPbk2HandleMassUpdate(CEikListBox& iListBox);
       
   333         void ConstructL();
       
   334         TBool HandleMassUpdateCheckL(); 
       
   335         void HandleMassUpdateCheckReset();
       
   336         void HandleMassUpdateDone();
       
   337         static TInt HandleMassUpdateTimerCallBack(TAny* aAny);        
       
   338 
       
   339     private: 
       
   340 		CEikListBox& iListBox;
       
   341         TBool iHandleMassUpdate;
       
   342         TTime iHandleMassUpdateFirst;
       
   343         TTime iHandleMassUpdatePrev;        
       
   344         TInt  iHandleMassUpdateCount;
       
   345         CPeriodic* iHandleMassUpdateTimer;      
       
   346 		CAknWaitDialog*  iHandleMassUpdateDialog;		
       
   347     };
       
   348 
   268 // --------------------------------------------------------------------------
   349 // --------------------------------------------------------------------------
   269 // CPbk2UiControlEventSender::CPbk2UiControlEventSender
   350 // CPbk2UiControlEventSender::CPbk2UiControlEventSender
   270 // --------------------------------------------------------------------------
   351 // --------------------------------------------------------------------------
   271 //
   352 //
   272 CPbk2UiControlEventSender::CPbk2UiControlEventSender
   353 CPbk2UiControlEventSender::CPbk2UiControlEventSender
   537             {
   618             {
   538             iControl.Reset();
   619             iControl.Reset();
   539             }
   620             }
   540         }
   621         }
   541     }
   622     }
       
   623 
       
   624 // --------------------------------------------------------------------------
       
   625 // CPbk2HandleMassUpdate::NewL
       
   626 // --------------------------------------------------------------------------
       
   627 //
       
   628 CPbk2HandleMassUpdate* CPbk2HandleMassUpdate::NewL(CEikListBox& aListBox)
       
   629     {
       
   630     CPbk2HandleMassUpdate* self =
       
   631         new( ELeave ) CPbk2HandleMassUpdate(aListBox);
       
   632     CleanupStack::PushL( self );
       
   633     self->ConstructL();
       
   634     CleanupStack::Pop( self );
       
   635     return self;
       
   636     }
       
   637 
       
   638 // --------------------------------------------------------------------------
       
   639 // CPbk2HandleMassUpdate::~CPbk2HandleMassUpdate
       
   640 // --------------------------------------------------------------------------
       
   641 //
       
   642 CPbk2HandleMassUpdate::~CPbk2HandleMassUpdate()
       
   643     {
       
   644     delete iHandleMassUpdateDialog;
       
   645     delete iHandleMassUpdateTimer;    
       
   646     }
       
   647     
       
   648 // --------------------------------------------------------------------------
       
   649 // CPbk2HandleMassUpdate::CPbk2HandleMassUpdate
       
   650 // --------------------------------------------------------------------------
       
   651 //
       
   652 CPbk2HandleMassUpdate::CPbk2HandleMassUpdate(CEikListBox& aListBox) :
       
   653     iListBox(aListBox)
       
   654     {
       
   655     }	
       
   656 	
       
   657 // --------------------------------------------------------------------------
       
   658 // CPbk2HandleMassUpdate::ConstructL
       
   659 // --------------------------------------------------------------------------
       
   660 //
       
   661 void CPbk2HandleMassUpdate::ConstructL()
       
   662     {
       
   663     iHandleMassUpdateTimer = CPeriodic::NewL( CActive::EPriorityIdle );
       
   664     }    
       
   665 
       
   666 // --------------------------------------------------------------------------
       
   667 // CPbk2HandleMassUpdate::HandleMassUpdateCheckThis
       
   668 //
       
   669 // Functionality to detect mass updates done to contact database and to prevent
       
   670 // e.g nameslist flickering when constant updates are happening in background
       
   671 // when pc sync etc is adding hundreds of contacts in line
       
   672 // --------------------------------------------------------------------------
       
   673 //
       
   674 TBool CPbk2HandleMassUpdate::MassUpdateCheckThis()
       
   675     {
       
   676     TBool ret(EFalse);
       
   677     const TInt KNbrUpdBeforeMassCheck(5); 
       
   678     iHandleMassUpdateTimer->Cancel();
       
   679 
       
   680     if( iHandleMassUpdateCount > KNbrUpdBeforeMassCheck ) 
       
   681         {
       
   682         //candidates to be checked are they continual of a mass update
       
   683         TRAP_IGNORE(ret = HandleMassUpdateCheckL());
       
   684         }
       
   685     else if( iHandleMassUpdateCount > 0 ) 
       
   686         {
       
   687         //Subsequent updates that are handled normally even if 
       
   688         // they would be first ones in a mass update burst
       
   689         iHandleMassUpdateCount++;
       
   690         iHandleMassUpdatePrev.UniversalTime();
       
   691         }    
       
   692     else
       
   693         {
       
   694         //very first update, set time & counter
       
   695         HandleMassUpdateCheckReset();       
       
   696         }
       
   697     return ret;
       
   698     }
       
   699 	
       
   700 // --------------------------------------------------------------------------
       
   701 // CPbk2HandleMassUpdate::MassUpdateDetected
       
   702 // --------------------------------------------------------------------------
       
   703 //
       
   704 TBool CPbk2HandleMassUpdate::MassUpdateDetected()
       
   705     {
       
   706 	return iHandleMassUpdate;
       
   707 	}
       
   708 
       
   709 // --------------------------------------------------------------------------
       
   710 // CPbk2HandleMassUpdate::HandleMassUpdateCheckL
       
   711 // --------------------------------------------------------------------------
       
   712 //
       
   713 TBool CPbk2HandleMassUpdate::HandleMassUpdateCheckL()
       
   714     {
       
   715     //KDeltaAverage time per update to be considered as mass
       
   716     //update. One occasional update can take KDeltaMax time as long as 
       
   717     //average time not exeeded (therefore timeout for the very first updates in 
       
   718     //practice is also KDeltaAverage).  
       
   719     const TInt64 KDeltaAverage(2000000); 
       
   720     const TInt64 KDeltaMax(KDeltaAverage * 2);     
       
   721     const TTimeIntervalMicroSeconds KMaxPrev(KDeltaMax);  
       
   722     TBool ret(EFalse);
       
   723 
       
   724     TTime now;
       
   725     now.UniversalTime();    
       
   726     TTimeIntervalMicroSeconds fs = now.MicroSecondsFrom(iHandleMassUpdateFirst);
       
   727     TTimeIntervalMicroSeconds ps = now.MicroSecondsFrom(iHandleMassUpdatePrev);
       
   728     TTimeIntervalMicroSeconds maxCumu(KDeltaAverage * iHandleMassUpdateCount);
       
   729 
       
   730     if( fs < maxCumu && ps < KMaxPrev )
       
   731         {
       
   732         //mass update burst ongoing
       
   733         iHandleMassUpdate=ETrue;        
       
   734         iHandleMassUpdateCount++;
       
   735         iHandleMassUpdatePrev.UniversalTime();   
       
   736         iListBox.UpdateScrollBarsL();
       
   737 		
       
   738         if( !iHandleMassUpdateDialog )
       
   739             {
       
   740             iHandleMassUpdateDialog = new(ELeave) CAknWaitDialog
       
   741                 (reinterpret_cast<CEikDialog**>(&iHandleMassUpdateDialog), EFalse);
       
   742             iHandleMassUpdateDialog->SetTone(CAknNoteDialog::ENoTone);
       
   743             iHandleMassUpdateDialog->ExecuteLD(R_QTN_GEN_NOTE_SYNCHRONIZING_PROGRESS);  
       
   744 			//ExecuteLD above handles validity of pointer iHandleMassUpdateDialog plus 
       
   745 			//cleanupstack
       
   746             }
       
   747 			
       
   748         TCallBack callback(HandleMassUpdateTimerCallBack, this);
       
   749         TTimeIntervalMicroSeconds32 delta32(KDeltaMax);
       
   750         iHandleMassUpdateTimer->Start( delta32, delta32, callback );
       
   751         ret = ETrue;
       
   752         }
       
   753     else if(iHandleMassUpdate)
       
   754         {
       
   755         //mass update burst ended    
       
   756         HandleMassUpdateDone();
       
   757         ret = ETrue;        
       
   758         }
       
   759     else
       
   760         {
       
   761         //just normal update, set time & counter
       
   762         HandleMassUpdateCheckReset();
       
   763         }
       
   764     return ret;
       
   765     }
       
   766 
       
   767 // ----------------------------------------------------------------------------
       
   768 // CPbk2HandleMassUpdate::HandleMassUpdateCheckReset
       
   769 // ----------------------------------------------------------------------------
       
   770 //
       
   771 void CPbk2HandleMassUpdate::HandleMassUpdateCheckReset()
       
   772     {
       
   773     iHandleMassUpdate=EFalse;        
       
   774     iHandleMassUpdateCount = 1;  //set as first candidate for next burst
       
   775     iHandleMassUpdateFirst.UniversalTime();
       
   776     iHandleMassUpdatePrev=iHandleMassUpdateFirst;    
       
   777     }
       
   778 
       
   779 // ----------------------------------------------------------------------------
       
   780 // CPbk2HandleMassUpdate::HandleMassUpdateTimerCallBack
       
   781 // ----------------------------------------------------------------------------
       
   782 //
       
   783 TInt CPbk2HandleMassUpdate::HandleMassUpdateTimerCallBack(TAny* aAny)
       
   784     {
       
   785     CPbk2HandleMassUpdate* self = static_cast<CPbk2HandleMassUpdate*>( aAny );
       
   786     self->iHandleMassUpdateTimer->Cancel();    
       
   787     self->HandleMassUpdateDone();
       
   788     return KErrNone;
       
   789     }
       
   790 
       
   791 // ----------------------------------------------------------------------------
       
   792 // CPbk2HandleMassUpdate::HandleMassUpdateDone
       
   793 // ----------------------------------------------------------------------------
       
   794 //
       
   795 void CPbk2HandleMassUpdate::HandleMassUpdateDone()
       
   796     {
       
   797     if( iHandleMassUpdateDialog ) 
       
   798         {
       
   799         TRAP_IGNORE(iHandleMassUpdateDialog->ProcessFinishedL());
       
   800         //The below 2 lines just in case... ProcessFinishedL already took care of these
       
   801         delete iHandleMassUpdateDialog;     
       
   802         iHandleMassUpdateDialog = NULL;
       
   803         }
       
   804 
       
   805     HandleMassUpdateCheckReset();        
       
   806     iListBox.SetCurrentItemIndex(0);
       
   807     iListBox.SetTopItemIndex(0);
       
   808     }
       
   809 	
       
   810 ///////////////////////// End of helper classes /////////////////////////////
       
   811 
   542 
   812 
   543 // --------------------------------------------------------------------------
   813 // --------------------------------------------------------------------------
   544 // CPbk2NamesListControl::CPbk2NamesListControl
   814 // CPbk2NamesListControl::CPbk2NamesListControl
   545 // --------------------------------------------------------------------------
   815 // --------------------------------------------------------------------------
   546 //
   816 //
   584 // CPbk2NamesListControl::~CPbk2NamesListControl
   854 // CPbk2NamesListControl::~CPbk2NamesListControl
   585 // --------------------------------------------------------------------------
   855 // --------------------------------------------------------------------------
   586 //
   856 //
   587 CPbk2NamesListControl::~CPbk2NamesListControl()
   857 CPbk2NamesListControl::~CPbk2NamesListControl()
   588     {
   858     {
       
   859     ClearMarkedContactsInfo();
       
   860     
       
   861     if (iBgTask)
       
   862         {    
       
   863         delete iBgTask;
       
   864         iBgTask = NULL;
       
   865         }
       
   866     
   589     if ( iViewStack && iStackObserver )
   867     if ( iViewStack && iStackObserver )
   590         {
   868         {
   591         iViewStack->RemoveStackObserver( *iStackObserver );
   869         iViewStack->RemoveStackObserver( *iStackObserver );
   592         }
   870         }
   593 
   871 
       
   872     if( iThumbManager )
       
   873         {
       
   874         TRAP_IGNORE( iThumbManager->SetContactViewL( NULL ) );
       
   875         iThumbManager->RemoveObserver();
       
   876         }
       
   877     
   594     if (iCommand)
   878     if (iCommand)
   595         {
   879         {
   596         // inform the command that the control is deleted
   880         // inform the command that the control is deleted
   597         iCommand->ResetUiControl(*this);
   881         iCommand->ResetUiControl(*this);
   598         }
   882         }
   599     iObservers.Reset();
   883     iObservers.Reset();
   600     iCommandItems.ResetAndDestroy();
   884     iCommandItems.ResetAndDestroy();
       
   885 	delete iCheckMassUpdate;
   601     delete iListBoxSelectionObserver;
   886     delete iListBoxSelectionObserver;
   602     delete iStateFactory;
   887     delete iStateFactory;
   603     delete iListBox;
   888     delete iListBox;
   604     delete iFindBox;
   889     delete iFindBox;
   605     delete iThumbnailLoader;
   890     delete iThumbnailLoader;
   606     delete iEventSender;
   891     delete iEventSender;
   607     delete iStackObserver;
   892     delete iStackObserver;
   608     delete iUiExtension;
   893     delete iUiExtension;
   609     delete iViewStack;
   894     delete iViewStack;
   610     delete iSearchFilter;
   895     delete iSearchFilter;
   611 
   896     if( iOwnThumbManager )
       
   897         {
       
   898         delete iThumbManager;
       
   899         }
   612     if (iOwnBaseView)
   900     if (iOwnBaseView)
   613         {
   901         {
   614         delete iBaseView;
   902         delete iBaseView;
   615         }
   903         }
   616     if(iFeatureManagerInitilized)
   904     if(iFeatureManagerInitilized)
   617         {
   905         {
   618         FeatureManager::UnInitializeLib();
   906         FeatureManager::UnInitializeLib();
   619         }
   907         }
   620 
       
   621     // if thumbmanager, remove observer
       
   622     if( iThumbManager )
       
   623         {
       
   624         iThumbManager->RemoveObserver();
       
   625         }
       
   626 
       
   627     }
   908     }
   628 
   909 
   629 // --------------------------------------------------------------------------
   910 // --------------------------------------------------------------------------
   630 // CPbk2NamesListControl::NewL
   911 // CPbk2NamesListControl::NewL
   631 // --------------------------------------------------------------------------
   912 // --------------------------------------------------------------------------
   687     CCoeEnv::Static()->CreateResourceReaderLC(resReader, aResourceId);
   968     CCoeEnv::Static()->CreateResourceReaderLC(resReader, aResourceId);
   688     ConstructFromResourceL(resReader);
   969     ConstructFromResourceL(resReader);
   689     CleanupStack::PopAndDestroy(); // resReader
   970     CleanupStack::PopAndDestroy(); // resReader
   690     FeatureManager::InitializeLibL();
   971     FeatureManager::InitializeLibL();
   691     iFeatureManagerInitilized = ETrue;
   972     iFeatureManagerInitilized = ETrue;
       
   973 	iCheckMassUpdate = CPbk2HandleMassUpdate::NewL(*iListBox); //iListbox created in ConstructFromResourceL
   692     }
   974     }
   693 
   975 
   694 // --------------------------------------------------------------------------
   976 // --------------------------------------------------------------------------
   695 // CPbk2NamesListControl::ConstructFromResourceL
   977 // CPbk2NamesListControl::ConstructFromResourceL
   696 // --------------------------------------------------------------------------
   978 // --------------------------------------------------------------------------
   738     aReader.Rewind( sizeof( TInt32 ) );
  1020     aReader.Rewind( sizeof( TInt32 ) );
   739 
  1021 
   740     // Create the listbox and its model
  1022     // Create the listbox and its model
   741     if( flags & KPbk2ContactViewListControlDoubleRow )
  1023     if( flags & KPbk2ContactViewListControlDoubleRow )
   742         {
  1024         {
       
  1025         if( !iThumbManager )
       
  1026             {
       
  1027             iThumbManager = CPbk2ThumbnailManager::NewL( iContactManager );
       
  1028             iOwnThumbManager = ETrue;
       
  1029             }
       
  1030     
   743         iDoubleListBox = CPbk2ContactViewDoubleListBox::NewL
  1031         iDoubleListBox = CPbk2ContactViewDoubleListBox::NewL
   744             ( *this, aReader, iContactManager,
  1032             ( *this, aReader, iContactManager,
   745             *iViewStack, iNameFormatter, iStoreProperties,
  1033             *iViewStack, iNameFormatter, iStoreProperties,
   746             iUiExtension, *iSearchFilter, *iThumbManager );
  1034             iUiExtension, *iSearchFilter, *iThumbManager );
   747 
  1035 
   748         if( iThumbManager )
  1036         iThumbManager->SetObserver( *iDoubleListBox );
   749             {
  1037         iThumbManager->SetContactViewL( iViewStack );
   750             iThumbManager->SetObserver( *iDoubleListBox );
       
   751             iViewStack->AddObserverL( *iThumbManager );
       
   752             }
       
   753 
  1038 
   754         iListBox = iDoubleListBox;
  1039         iListBox = iDoubleListBox;
   755         }
  1040         }
   756     else
  1041     else
   757         {
  1042         {
   819         iNameFormatter, iCommandItems, *iSearchFilter );
  1104         iNameFormatter, iCommandItems, *iSearchFilter );
   820 
  1105 
   821     // Create the initial state
  1106     // Create the initial state
   822     iCurrentState = &iStateFactory->ActivateStartupStateL( iCurrentState );
  1107     iCurrentState = &iStateFactory->ActivateStartupStateL( iCurrentState );
   823 
  1108 
       
  1109     iBgTask = new (ELeave) CPbk2NamesListControlBgTask( *this );
       
  1110     
   824     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
  1111     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
   825         ("CPbk2NamesListControl::ConstructFromResourceL end"));
  1112         ("CPbk2NamesListControl::ConstructFromResourceL end"));
   826     }
  1113     }
   827 
  1114 
   828 // --------------------------------------------------------------------------
  1115 // --------------------------------------------------------------------------
  1073         }
  1360         }
  1074     else
  1361     else
  1075         {
  1362         {
  1076         HideThumbnail();
  1363         HideThumbnail();
  1077         }
  1364         }
  1078     ReportEventL( MCoeControlObserver::EEventStateChanged );
  1365     TRAP_IGNORE(ReportEventL( MCoeControlObserver::EEventStateChanged ));
  1079     }
  1366     }
  1080 
  1367 
  1081 // --------------------------------------------------------------------------
  1368 // --------------------------------------------------------------------------
  1082 // CPbk2NamesListControl::SizeChanged
  1369 // CPbk2NamesListControl::SizeChanged
  1083 // --------------------------------------------------------------------------
  1370 // --------------------------------------------------------------------------
  1329 // --------------------------------------------------------------------------
  1616 // --------------------------------------------------------------------------
  1330 //
  1617 //
  1331 void CPbk2NamesListControl::ClearMarks()
  1618 void CPbk2NamesListControl::ClearMarks()
  1332     {
  1619     {
  1333     iCurrentState->ClearMarks();
  1620     iCurrentState->ClearMarks();
       
  1621 	ClearMarkedContactsInfo();
  1334     }
  1622     }
  1335 
  1623 
  1336 // --------------------------------------------------------------------------
  1624 // --------------------------------------------------------------------------
  1337 // CPbk2NamesListControl::SetSelectedContactL
  1625 // CPbk2NamesListControl::SetSelectedContactL
  1338 // --------------------------------------------------------------------------
  1626 // --------------------------------------------------------------------------
  1666     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
  1954     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
  1667         ("CPbk2NamesListControl::ContactAddedToView()"));
  1955         ("CPbk2NamesListControl::ContactAddedToView()"));
  1668 
  1956 
  1669     if (&aView == iViewStack)
  1957     if (&aView == iViewStack)
  1670         {
  1958         {
  1671         TRAPD(err, DoHandleContactAdditionL(aIndex));
  1959         if( !iCheckMassUpdate->MassUpdateDetected() ) 
  1672         HandleError(err);
  1960             {
       
  1961             TRAPD(err, DoHandleContactAdditionL(aIndex));
       
  1962             HandleError(err);
       
  1963             }
  1673         }
  1964         }
  1674     }
  1965     }
  1675 
  1966 
  1676 // --------------------------------------------------------------------------
  1967 // --------------------------------------------------------------------------
  1677 // CPbk2NamesListControl::ContactRemovedFromView
  1968 // CPbk2NamesListControl::ContactRemovedFromView
  1872     if(iCurrentState->NamesListState() != CPbk2NamesListControl::EStateHidden)
  2163     if(iCurrentState->NamesListState() != CPbk2NamesListControl::EStateHidden)
  1873         {
  2164         {
  1874         SelectAndChangeReadyStateL(); 
  2165         SelectAndChangeReadyStateL(); 
  1875         }        
  2166         }        
  1876 
  2167 
  1877     iCurrentState->HandleContactViewEventL
  2168     if( !iCheckMassUpdate->MassUpdateDetected() )
  1878         ( MPbk2NamesListState::EItemAdded, aIndex );
  2169         {
       
  2170         iCurrentState->HandleContactViewEventL
       
  2171             ( MPbk2NamesListState::EItemAdded, aIndex );
       
  2172         }
  1879 
  2173 
  1880     // At least names list view needs control event about contact addition,
  2174     // At least names list view needs control event about contact addition,
  1881     // so it knows to update CBAs
  2175     // so it knows to update CBAs
  1882     iEventSender->SendEventToObserversL( TPbk2ControlEvent::EItemAdded );
  2176     iEventSender->SendEventToObserversL( TPbk2ControlEvent::EItemAdded );
  1883     }
  2177     }
  2018         {
  2312         {
  2019         // This will reset back to base view
  2313         // This will reset back to base view
  2020         iCurrentState->ResetFindL();
  2314         iCurrentState->ResetFindL();
  2021         });
  2315         });
  2022     HandleError( res );
  2316     HandleError( res );
  2023     Reset();
  2317 
       
  2318     if( !iCheckMassUpdate->MassUpdateCheckThis() )
       
  2319         {
       
  2320         Reset();
       
  2321         }
  2024 
  2322 
  2025     // Do not handle contact addition here (DoHandleContactAdditionL),
  2323     // Do not handle contact addition here (DoHandleContactAdditionL),
  2026     // ContactAddedToView to notification is sent separately
  2324     // ContactAddedToView to notification is sent separately
  2027     }
  2325     }
  2028 
  2326 
  2127 //
  2425 //
  2128 void CPbk2NamesListControl::AdaptiveSearchTextChanged( CAknSearchField* aSearchField )
  2426 void CPbk2NamesListControl::AdaptiveSearchTextChanged( CAknSearchField* aSearchField )
  2129     {
  2427     {
  2130     //send event to current state
  2428     //send event to current state
  2131     //ETrue means that the event came from adaptvie search grid.
  2429     //ETrue means that the event came from adaptvie search grid.
  2132     iCurrentState->HandleControlEventL( aSearchField, MCoeControlObserver::EEventStateChanged, ETrue );
  2430     TRAP_IGNORE(iCurrentState->HandleControlEventL( aSearchField, MCoeControlObserver::EEventStateChanged, ETrue));
  2133     }
  2431     }
  2134 
  2432 
  2135 // --------------------------------------------------------------------------
  2433 // --------------------------------------------------------------------------
  2136 // CPbk2NamesListControl::HandleForegroundEventL
  2434 // CPbk2NamesListControl::HandleForegroundEventL
  2137 //
  2435 //
  2142     if ( iSearchFilter )
  2440     if ( iSearchFilter )
  2143         {
  2441         {
  2144         iSearchFilter->HandleForegroundEventL( aForeground );
  2442         iSearchFilter->HandleForegroundEventL( aForeground );
  2145         }
  2443         }
  2146     }
  2444     }
  2147 
  2445         
       
  2446 // ---------------------------------------------------------------------------
       
  2447 // CPbk2NamesListControl::StoreMarkedContactsAndResetViewL
       
  2448 // ---------------------------------------------------------------------------
       
  2449 //
       
  2450 void CPbk2NamesListControl::StoreMarkedContactsAndResetViewL()
       
  2451     {  
       
  2452     delete iSelectedLinkArray;
       
  2453     iSelectedLinkArray = NULL;
       
  2454     
       
  2455     iSelectedLinkArray = iCurrentState->SelectedContactsL();
       
  2456     }
       
  2457 
       
  2458 
       
  2459 // ---------------------------------------------------------------------------
       
  2460 // CPbk2NamesListControl::RestoreMarkedContactsL
       
  2461 // ---------------------------------------------------------------------------
       
  2462 //
       
  2463 void CPbk2NamesListControl::RestoreMarkedContactsL()
       
  2464     {    
       
  2465     //Set the Marked Contacts
       
  2466     if ( iSelectedLinkArray )
       
  2467         {
       
  2468         for ( TInt index = 0; index<iSelectedLinkArray->Count(); index++ )
       
  2469             {
       
  2470             iCurrentState->SetSelectedContactL( iSelectedLinkArray->At(index), ETrue );
       
  2471             }        
       
  2472         }    
       
  2473     
       
  2474     delete iSelectedLinkArray;
       
  2475     iSelectedLinkArray = NULL;
       
  2476     }
       
  2477 
       
  2478 // ---------------------------------------------------------------------------
       
  2479 // CPbk2NamesListControl::ClearMarkedContactsInfo
       
  2480 // ---------------------------------------------------------------------------
       
  2481 //
       
  2482 void CPbk2NamesListControl::ClearMarkedContactsInfo()
       
  2483     {   
       
  2484     if ( iBgTask )
       
  2485         {
       
  2486         iBgTask->ClearAllEvents();
       
  2487         }
       
  2488     delete iSelectedLinkArray;
       
  2489     iSelectedLinkArray = NULL;
       
  2490     }
       
  2491 
       
  2492 // ---------------------------------------------------------------------------
       
  2493 // CPbk2NamesListControl::HandleViewForegroundEventL
       
  2494 // ---------------------------------------------------------------------------
       
  2495 //
       
  2496 EXPORT_C void CPbk2NamesListControl::HandleViewForegroundEventL( TBool aForeground )
       
  2497     {
       
  2498     if ( aForeground )
       
  2499         {
       
  2500         if ( iBgTask )
       
  2501             {
       
  2502             iBgTask->AddEvent( CPbk2NamesListControl::EStateRestoreMarkedContacts );
       
  2503             }
       
  2504         }
       
  2505     else
       
  2506         {
       
  2507         if ( iBgTask )
       
  2508             {
       
  2509             iBgTask->AddEvent( CPbk2NamesListControl::EStateSaveMarkedContacts );
       
  2510             }
       
  2511         }
       
  2512     }
       
  2513 
       
  2514 // ---------------------------------------------------------------------------
       
  2515 // CPbk2NamesListControlBgTask::CPbk2NamesListControlBgTask
       
  2516 // ---------------------------------------------------------------------------
       
  2517 //
       
  2518 CPbk2NamesListControlBgTask::CPbk2NamesListControlBgTask( CPbk2NamesListControl& aControl ) :
       
  2519     CActive(CActive::EPriorityStandard),
       
  2520     iControl( aControl )
       
  2521     {
       
  2522     CActiveScheduler::Add(this);
       
  2523     iEventQueue.Append(CPbk2NamesListControl::EStateBgTaskEmpty);
       
  2524     }
       
  2525 
       
  2526 // ---------------------------------------------------------------------------
       
  2527 // CPbk2NamesListControlBgTask::~CPbk2NamesListControlBgTask
       
  2528 // ---------------------------------------------------------------------------
       
  2529 //
       
  2530 CPbk2NamesListControlBgTask::~CPbk2NamesListControlBgTask()
       
  2531     {
       
  2532     Cancel();
       
  2533     iEventQueue.Reset();
       
  2534     }
       
  2535 
       
  2536 
       
  2537 // ---------------------------------------------------------------------------
       
  2538 // CPbk2NamesListControlBgTask::DoCancel
       
  2539 // ---------------------------------------------------------------------------
       
  2540 //
       
  2541 void CPbk2NamesListControlBgTask::DoCancel()
       
  2542     {    
       
  2543     }
       
  2544 
       
  2545 // ---------------------------------------------------------------------------
       
  2546 // CPbk2NamesListControlBgTask::RunL
       
  2547 // ---------------------------------------------------------------------------
       
  2548 //
       
  2549 void CPbk2NamesListControlBgTask::RunL()
       
  2550     {
       
  2551     
       
  2552     if ( iEventQueue.Count() )
       
  2553         {
       
  2554         switch ( iEventQueue[0] )
       
  2555             {
       
  2556             case CPbk2NamesListControl::EStateSaveMarkedContacts:
       
  2557                 iControl.StoreMarkedContactsAndResetViewL();
       
  2558                 iEventQueue.Remove( 0 );
       
  2559                 break;
       
  2560                 
       
  2561             case CPbk2NamesListControl::EStateRestoreMarkedContacts:
       
  2562                 iControl.RestoreMarkedContactsL();
       
  2563                 iEventQueue.Remove( 0 );
       
  2564                 break;
       
  2565             
       
  2566             case CPbk2NamesListControl::EStateBgTaskEmpty :    
       
  2567             default:            
       
  2568                 iControl.ClearMarkedContactsInfo();
       
  2569                 break;
       
  2570             }
       
  2571         }
       
  2572     }
       
  2573 
       
  2574 // ---------------------------------------------------------------------------
       
  2575 // CPbk2NamesListControlBgTask::RunError
       
  2576 // ---------------------------------------------------------------------------
       
  2577 //
       
  2578 TInt CPbk2NamesListControlBgTask::RunError(TInt /*aError*/)
       
  2579     {    
       
  2580     return KErrNone;
       
  2581     }
       
  2582 
       
  2583 // ---------------------------------------------------------------------------
       
  2584 // CPbk2NamesListControlBgTask::AddEvent
       
  2585 // ---------------------------------------------------------------------------
       
  2586 //
       
  2587 void CPbk2NamesListControlBgTask::AddEvent( CPbk2NamesListControl::TPbk2NamesListBgEvents aEvent )
       
  2588     {
       
  2589     iEventQueue.Insert( aEvent, iEventQueue.Count() - 1 );
       
  2590     if ( !IsActive() )
       
  2591         {
       
  2592         TRequestStatus* status = &iStatus;
       
  2593         User::RequestComplete(status, KErrNone);
       
  2594         SetActive();
       
  2595         }
       
  2596     }
       
  2597 
       
  2598 
       
  2599 // ---------------------------------------------------------------------------
       
  2600 // CPbk2NamesListControlBgTask::RemoveEvent
       
  2601 // ---------------------------------------------------------------------------
       
  2602 //
       
  2603 void CPbk2NamesListControlBgTask::RemoveEvent( CPbk2NamesListControl::TPbk2NamesListBgEvents aEvent )
       
  2604     {
       
  2605     for ( TInt index = 0; index < iEventQueue.Count(); index++ )
       
  2606         {
       
  2607         if ( aEvent == iEventQueue[index] )
       
  2608             {
       
  2609             iEventQueue.Remove( index );      
       
  2610             if ( 0 == index )
       
  2611                 {
       
  2612                 Cancel(); 
       
  2613                 }
       
  2614             break;
       
  2615             }
       
  2616         }    
       
  2617     }
       
  2618 
       
  2619 
       
  2620 // ---------------------------------------------------------------------------
       
  2621 // CPbk2NamesListControlBgTask::ClearAllEvents
       
  2622 // ---------------------------------------------------------------------------
       
  2623 //
       
  2624 void CPbk2NamesListControlBgTask::ClearAllEvents()
       
  2625     {
       
  2626     iEventQueue.Reset();
       
  2627     iEventQueue.Append( CPbk2NamesListControl::EStateBgTaskEmpty );
       
  2628     Cancel();
       
  2629     }
  2148 
  2630 
  2149 //  End of File
  2631 //  End of File