phonebookui/Phonebook2/UIControls/src/CPbk2AdaptiveSearchGridFiller.cpp
branchRCL_3
changeset 39 a6539d1e8e43
parent 35 4ae315f230bc
child 45 34879f5cfc63
equal deleted inserted replaced
35:4ae315f230bc 39:a6539d1e8e43
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include "CPbk2AdaptiveSearchGridFiller.h"
    20 #include "CPbk2AdaptiveSearchGridFiller.h"
    21 #include "MVPbkViewContact.h"
    21 #include "MVPbkViewContact.h"
    22 #include "MVPbkContactViewBase.h"
    22 #include "MVPbkContactViewBase.h"
    23 #include "MPbk2ContactNameFormatter.h"
    23 #include "MPbk2ContactNameFormatter.h"
    24 
    24 #include "MPbk2FilteredViewStack.h"
       
    25 
       
    26 #include <MPbk2ContactViewSupplier.h>
       
    27 #include <MPbk2ApplicationServices.h>
       
    28 #include <MPbk2AppUi.h>
       
    29 #include <CPbk2StoreConfiguration.h>
    25 #include <MPbk2ContactNameFormatter2.h>
    30 #include <MPbk2ContactNameFormatter2.h>
    26 #include <FindUtil.h>
    31 #include <FindUtil.h>
    27 #include <badesca.h>
    32 #include <badesca.h>
    28 #include <featmgr.h>
    33 #include <featmgr.h>
       
    34 
       
    35 #include <CPsRequestHandler.h>
    29 
    36 
    30 const TInt KMaxAdaptiveGridCacheCount = 10;
    37 const TInt KMaxAdaptiveGridCacheCount = 10;
    31 const TInt KAdaptiveSearchKeyMapGranularity = 100;
    38 const TInt KAdaptiveSearchKeyMapGranularity = 100;
    32 const TInt KAdaptiveSearchRefineStep = 25;
    39 const TInt KAdaptiveSearchRefineStep = 25;
    33 const TInt KContactFormattingFlags = MPbk2ContactNameFormatter::EPreserveLeadingSpaces |
    40 const TInt KContactFormattingFlags = MPbk2ContactNameFormatter::EPreserveLeadingSpaces |
    90 // --------------------------------------------------------------------------
    97 // --------------------------------------------------------------------------
    91 //
    98 //
    92 CPbk2AdaptiveSearchGridFiller::~CPbk2AdaptiveSearchGridFiller()
    99 CPbk2AdaptiveSearchGridFiller::~CPbk2AdaptiveSearchGridFiller()
    93     {
   100     {
    94     Cancel();
   101     Cancel();
    95     delete iGridWaiter;
   102     if ( iPsHandler )
       
   103         {
       
   104         iPsHandler->RemoveObserver( this );
       
   105         delete iPsHandler;
       
   106         }
    96 	delete iKeyMap;
   107 	delete iKeyMap;
    97 	delete iCurrentGrid;
   108 	delete iCurrentGrid;
    98 	iAdaptiveGridCache.ResetAndDestroy();
   109 	iAdaptiveGridCache.ResetAndDestroy();
    99 	delete iSearchString;
   110 	delete iSearchString;
   100 	delete iFindUtil;
   111 	delete iFindUtil;
   123 //
   134 //
   124 void CPbk2AdaptiveSearchGridFiller::ConstructL()
   135 void CPbk2AdaptiveSearchGridFiller::ConstructL()
   125     {
   136     {
   126 	iKeyMap = HBufC::NewL( KAdaptiveSearchKeyMapGranularity );
   137 	iKeyMap = HBufC::NewL( KAdaptiveSearchKeyMapGranularity );
   127 	iFindUtil = CFindUtil::NewL();
   138 	iFindUtil = CFindUtil::NewL();
   128 	iGridWaiter = CPbk2AdaptiveSearchGridWaiter::NewL( *this );
   139     // UI Language
   129     }
   140 	TLanguage uiLanguage = User::Language();
   130 
   141 	if ( uiLanguage != ELangJapanese && uiLanguage != ELangPrcChinese && 
   131 void CPbk2AdaptiveSearchGridFiller::StartFilling( const MVPbkContactViewBase& aView, const TDesC& aSearchString )
   142 	        uiLanguage != ELangHongKongChinese && uiLanguage != ELangTaiwanChinese &&
   132 	{
   143 	        uiLanguage != ELangKorean )
   133 	CPbk2AdaptiveGrid* keyMap = KeyMapFromCache( aSearchString );
   144 	    {  
   134 
   145         iPsHandler = CPSRequestHandler::NewL();
   135 	if( keyMap )
   146         iPsHandler->AddObserverL( this );
   136 		{
   147 	    }
   137 		iSearchField.SetAdaptiveGridChars( keyMap->GetKeyMap() );
   148     }
   138 		iGridWaiter->Stop();
   149 
   139 		return;
   150 void CPbk2AdaptiveSearchGridFiller::StartFillingL( const MVPbkContactViewBase& aView,
   140 		}
   151         const TDesC& aSearchString, TBool aClearCache )
   141 
   152 	{
       
   153 	
       
   154     if( aClearCache )
       
   155         {
       
   156         ClearCache();
       
   157         }
       
   158     
       
   159 	if ( IsActive() && iView == &aView && iViewItemCount == aView.ContactCountL() 
       
   160 	        && iSearchString && !iSearchString->Compare( aSearchString ) )
       
   161 	    {
       
   162 	    return;
       
   163 	    }
       
   164 	else
       
   165 	    {
       
   166 	    StopFilling();
       
   167 	    }
       
   168 
       
   169     CPbk2AdaptiveGrid* keyMap = KeyMapFromCache( aSearchString );
       
   170     
       
   171     if( keyMap )
       
   172         {
       
   173         iSearchField.SetAdaptiveGridChars( keyMap->GetKeyMap() );
       
   174         return;
       
   175         }
       
   176     
       
   177 	iViewItemCount = aView.ContactCountL();
   142 	delete iSearchString;
   178 	delete iSearchString;
   143 	iSearchString = NULL;
   179 	iSearchString = NULL;
   144 
   180 
   145 	iSearchString = aSearchString.AllocL();
   181 	iSearchString = aSearchString.AllocL();
   146 
   182 
   154 
   190 
   155 	iKeyMap->Des().Zero();
   191 	iKeyMap->Des().Zero();
   156 
   192 
   157 	iCounter = 0;
   193 	iCounter = 0;
   158 
   194 
       
   195 	if ( iSearchString->Length() <= KPsAdaptiveGridSupportedMaxLen && GridFromPsEngineL( aView ) )
       
   196 	    {
       
   197 	    return;
       
   198 	    }
       
   199 	
   159 	SetActive();
   200 	SetActive();
   160 	TRequestStatus* status = &iStatus;
   201 	TRequestStatus* status = &iStatus;
   161 	User::RequestComplete( status, KErrNone );
   202 	User::RequestComplete( status, KErrNone );
   162 	}
   203 	}
   163 
   204 
   174 		return;
   215 		return;
   175 		}
   216 		}
   176 
   217 
   177 	TInt stopCount = iCounter + KAdaptiveSearchRefineStep;
   218 	TInt stopCount = iCounter + KAdaptiveSearchRefineStep;
   178 	const TInt itemCount = iView->ContactCountL();
   219 	const TInt itemCount = iView->ContactCountL();
       
   220     
   179 	if( stopCount > itemCount )
   221 	if( stopCount > itemCount )
   180 		{
   222 		{
   181 		stopCount = itemCount;
   223 		stopCount = itemCount;
   182 		}
   224 		}
   183 
   225 
   339 	}
   381 	}
   340 
   382 
   341 void CPbk2AdaptiveSearchGridFiller::InvalidateAdaptiveSearchGrid()
   383 void CPbk2AdaptiveSearchGridFiller::InvalidateAdaptiveSearchGrid()
   342 	{
   384 	{
   343 	iInvalidateAdaptiveSearchGrid = ETrue;
   385 	iInvalidateAdaptiveSearchGrid = ETrue;
   344 	iGridWaiter->Start();
       
   345 	}
   386 	}
   346 
   387 
   347 void CPbk2AdaptiveSearchGridFiller::SetFocusToAdaptiveSearchGrid()
   388 void CPbk2AdaptiveSearchGridFiller::SetFocusToAdaptiveSearchGrid()
   348     {
   389     {
   349     iSetFocusToSearchGrid = ETrue;
   390     iSetFocusToSearchGrid = ETrue;
   402 	delete iCurrentGrid;
   443 	delete iCurrentGrid;
   403 	iCurrentGrid = NULL;
   444 	iCurrentGrid = NULL;
   404 	iCurrentGrid = iKeyMap->Des().AllocL();
   445 	iCurrentGrid = iKeyMap->Des().AllocL();
   405 
   446 
   406 	iSearchField.SetAdaptiveGridChars( *iKeyMap );
   447 	iSearchField.SetAdaptiveGridChars( *iKeyMap );
   407 	
       
   408     if( iInvalidateAdaptiveSearchGrid )
       
   409          {
       
   410          iGridWaiter->Stop();
       
   411          }
       
   412     
   448     
   413     iInvalidateAdaptiveSearchGrid = EFalse;
   449     iInvalidateAdaptiveSearchGrid = EFalse;
   414     
   450     
   415 	if ( iSetFocusToSearchGrid )
   451 	if ( iSetFocusToSearchGrid )
   416 	    {
   452 	    {
   606 			}
   642 			}
   607 		}
   643 		}
   608 	return isDigraphic;
   644 	return isDigraphic;
   609 	}
   645 	}
   610 
   646 
   611 void CPbk2AdaptiveSearchGridFiller::GridDelayCompleteL()
   647 void CPbk2AdaptiveSearchGridFiller::HandlePsResultsUpdate(
   612     {
   648         RPointerArray<CPsClientData>& /*searchResults*/,
   613     // simulating pointer event to hide adaptive grid
   649         RPointerArray<CPsPattern>& /*searchSeqs*/ )
   614     TPointerEvent pointerEvent;
   650     {
   615     pointerEvent.iType = TPointerEvent::EButton1Down;
   651     
   616     TPoint position = iSearchField.Rect().iTl;
   652     }
   617     position.iX += 1;
   653 
   618     position.iY += 1;
   654 void CPbk2AdaptiveSearchGridFiller::HandlePsError( TInt /*aErrorCode*/ )
   619     pointerEvent.iPosition = position;
   655     {
   620     iSearchField.HandlePointerEventL( pointerEvent );
   656     
   621     }
   657     }
   622 
   658 
   623 void CPbk2AdaptiveSearchGridFiller::WaitNoteDismissed()
   659 void CPbk2AdaptiveSearchGridFiller::CachingStatus( TCachingStatus& aStatus, TInt& /*aError*/ )
   624     {
   660     {
   625     iSearchField.ShowAdaptiveSearchGrid();
   661     TRAP_IGNORE(
       
   662     MVPbkContactViewBase* allContactsView = Phonebook2::Pbk2AppUi()->ApplicationServices().ViewSupplier().AllContactsViewL();
       
   663     
       
   664     const MPbk2FilteredViewStack* filteredView = dynamic_cast<const MPbk2FilteredViewStack*> ( iView );
       
   665     
       
   666     if ( aStatus >= ECachingComplete && filteredView && filteredView->Level() == 0 && &filteredView->BaseView() == allContactsView )
       
   667         {
       
   668         HBufC* string = iSearchString->AllocL();
       
   669         CleanupStack::PushL( string );
       
   670         StartFillingL( *iView, *string, ETrue );
       
   671         CleanupStack::PopAndDestroy( string  );
       
   672         }
       
   673         );
       
   674     }
       
   675 
       
   676 TBool CPbk2AdaptiveSearchGridFiller::GridFromPsEngineL( const MVPbkContactViewBase& aView )
       
   677     {
       
   678     if ( iPsHandler == NULL )
       
   679         {
       
   680         return EFalse;
       
   681         }
       
   682     MPbk2ApplicationServices& appServices = Phonebook2::Pbk2AppUi()->ApplicationServices();
       
   683     MVPbkContactViewBase* allContactsView = appServices.ViewSupplier().AllContactsViewL();
       
   684     const MPbk2FilteredViewStack* filteredView = dynamic_cast<const MPbk2FilteredViewStack*> ( &aView );
       
   685         
       
   686     if ( filteredView && filteredView->Level() == 0 && &filteredView->BaseView() == allContactsView )
       
   687         {
       
   688         CPbk2StoreConfiguration& config = appServices.StoreConfiguration();
       
   689         CVPbkContactStoreUriArray* stores = NULL;
       
   690         stores = config.CurrentConfigurationL();
       
   691         if ( !stores || stores->Count() == 0 )
       
   692             {
       
   693             delete stores;
       
   694             return EFalse;
       
   695             }
       
   696         
       
   697         TInt count = stores->Count();
       
   698         CleanupStack::PushL(stores);
       
   699         
       
   700         CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( count );
       
   701         CleanupStack::PushL( array );
       
   702         
       
   703         for ( TInt i = 0; i < count; ++i)
       
   704             {
       
   705             TVPbkContactStoreUriPtr uriPtr = stores->operator[](i);
       
   706             array->AppendL( uriPtr.UriDes() );
       
   707             }
       
   708 
       
   709         TBool companyName = EFalse;
       
   710         TBuf<KPsAdaptiveGridStringMaxLen> gridChars;
       
   711         if( FeatureManager::FeatureSupported( KFeatureIdFfContactsCompanyNames ) )
       
   712             {
       
   713             companyName = ETrue;
       
   714             }
       
   715         iPsHandler->GetAdaptiveGridCharactersL( *array, *iSearchString, companyName, gridChars );
       
   716         
       
   717         CleanupStack::PopAndDestroy( array );
       
   718         CleanupStack::PopAndDestroy( stores );
       
   719         
       
   720         if ( !gridChars.Length() && iViewItemCount > 0 )
       
   721             {
       
   722             // grid should be created on standard way
       
   723             return EFalse;
       
   724             }
       
   725         if ( iKeyMap->Des().MaxLength() < gridChars.Length() )
       
   726             {
       
   727             iKeyMap = iKeyMap->ReAllocL( gridChars.Length() );
       
   728             }
       
   729         iKeyMap->Des().Copy( gridChars );
       
   730         
       
   731         delete iCurrentGrid;
       
   732         iCurrentGrid = NULL;
       
   733         iCurrentGrid = iKeyMap->Des().AllocL();
       
   734 
       
   735         iSearchField.SetAdaptiveGridChars( *iKeyMap );
       
   736         
       
   737         iInvalidateAdaptiveSearchGrid = EFalse;
       
   738         
       
   739         if ( iSetFocusToSearchGrid )
       
   740             {
       
   741             // set the focus to findbox
       
   742             iSearchField.DrawDeferred();
       
   743             iSetFocusToSearchGrid = EFalse;
       
   744             }
       
   745         AddKeyMapToCacheL( *iSearchString, *iKeyMap );
       
   746         return ETrue;
       
   747         }
       
   748     else
       
   749         {
       
   750         return EFalse;
       
   751         }
   626     }
   752     }
   627 // End of File
   753 // End of File