phonebookui/Phonebook2/UIControls/src/CPbk2AdaptiveSearchGridFiller.cpp
branchRCL_3
changeset 21 9da50d567e3c
parent 20 f4a778e096c2
--- a/phonebookui/Phonebook2/UIControls/src/CPbk2AdaptiveSearchGridFiller.cpp	Wed Sep 01 12:29:52 2010 +0100
+++ b/phonebookui/Phonebook2/UIControls/src/CPbk2AdaptiveSearchGridFiller.cpp	Tue Sep 14 20:54:53 2010 +0300
@@ -124,6 +124,12 @@
 	delete iSearchString;
 	delete iFindUtil;
 	iDigraphContactsTitleArray.ResetAndDestroy();
+
+    if (iFeatureManagerInitialized)
+        {
+        // It can be safely called UnInitializeLib as it has been really intialized.
+        FeatureManager::UnInitializeLib();  // Decreases ref.count
+        }
     }
 
 
@@ -150,6 +156,10 @@
     {
 	iKeyMap = HBufC::NewL( KAdaptiveSearchKeyMapGranularity );
 	iFindUtil = CFindUtil::NewL();
+
+    // Initialize feature manager
+    FeatureManager::InitializeLibL();
+    iFeatureManagerInitialized = ETrue;
     // UI Language
 	TLanguage uiLanguage = User::Language();
 	if ( uiLanguage != ELangJapanese && uiLanguage != ELangPrcChinese && 
@@ -414,40 +424,16 @@
 
 void CPbk2AdaptiveSearchGridFiller::SetAdaptiveGridCharsL(
         const TInt aMaxSpacesNumber, const TInt aSearchStringSpacesNumber )
-	{
-	TPtr ptr = iKeyMap->Des();
-
-	// Do upper case for all characters
-	ptr.UpperCase();
-	CDesCArray* array = new (ELeave) CDesCArrayFlat( KAdaptiveSearchKeyMapGranularity );
-	CleanupStack::PushL( array );
-	TInt length = ptr.Length();
-
-	for( TInt ii = 0; ii < length; ii++ )
-	    {
-	    array->AppendL( ptr.Mid( ii, 1 ) );
-	    }
-
-	// Alphabetical sort
-	array->Sort( ECmpCollated );
-	ptr.Zero();
-
+    {
     // Add space character only if:
 	// - user typed already some characters in the find pane,
 	// - and more spaces can be found in contacts than in the current search string,
 	// - and space is not the last character in the search string.
-    if ( iSearchString->Length() > 0 
-         && aMaxSpacesNumber > aSearchStringSpacesNumber
-         && (*iSearchString)[iSearchString->Length() - 1] != TChar( ' ' ) )
-        {
-        ptr.Append( TChar( ' ' ) );
-        }
-     
-	for( TInt ii = 0; ii < length; ii++ )
-	    {
-	    ptr.Append(array->MdcaPoint( ii ));
-	    }
-	CleanupStack::PopAndDestroy();//array
+    TBool addSpace = ( iSearchString->Length() > 0 
+                       && aMaxSpacesNumber > aSearchStringSpacesNumber
+                       && (*iSearchString)[iSearchString->Length() - 1] != TChar( ' ' ) );
+
+    SortGridL( addSpace ); 
 
 	if( iCurrentGrid )
 		{
@@ -479,6 +465,36 @@
 
 	}
 
+void CPbk2AdaptiveSearchGridFiller::SortGridL( TBool aAddSpace )
+    {
+    TPtr ptr = iKeyMap->Des();
+
+    // Do upper case for all characters
+    ptr.UpperCase();
+    CDesCArray* array = new (ELeave) CDesCArrayFlat( KAdaptiveSearchKeyMapGranularity );
+    CleanupStack::PushL( array );
+    TInt length = ptr.Length();
+
+    for( TInt ii = 0; ii < length; ii++ )
+        {
+        array->AppendL( ptr.Mid( ii, 1 ) );
+        }
+
+    // Alphabetical sort
+    array->Sort( ECmpCollated );
+    ptr.Zero();
+
+    if ( aAddSpace )
+        {
+        ptr.Append( TChar( ' ' ) );
+        }
+     
+    for( TInt ii = 0; ii < length; ii++ )
+        {
+        ptr.Append( array->MdcaPoint( ii ) );
+        }
+    CleanupStack::PopAndDestroy();//array
+    }
 
 CDesC16Array* CPbk2AdaptiveSearchGridFiller::SplitContactFieldTextIntoArrayLC(
         const TDesC& aText )
@@ -512,7 +528,23 @@
         // Scan for next word
         beg = end;
         }
-
+    
+    // consonent based adaptive search:
+    if ( FeatureManager::FeatureSupported( KFeatureIdKorean ) )
+       {
+       /*
+       When user has a contact with first name "??" and last name "?",
+       It should be displayed with "? ??" in Korea variant.
+       That means it should be found with search keyword, "?" or "??".
+       Thus, need to put the "? ??" in the item list which is delivered to FindUtil.
+       no need to care about just one word like "???"
+       */       
+       if ( array->MdcaCount() != 1 )
+           {
+           array->AppendL( aText );
+           }
+        }
+	
     return array;
     }
 
@@ -749,6 +781,8 @@
             iKeyMap = iKeyMap->ReAllocL( gridChars.Length() );
             }
         iKeyMap->Des().Copy( gridChars );
+        // Sort the grid, space is not needed
+        SortGridL( EFalse );
         
         delete iCurrentGrid;
         iCurrentGrid = NULL;