122 delete iCurrentGrid; |
122 delete iCurrentGrid; |
123 iAdaptiveGridCache.ResetAndDestroy(); |
123 iAdaptiveGridCache.ResetAndDestroy(); |
124 delete iSearchString; |
124 delete iSearchString; |
125 delete iFindUtil; |
125 delete iFindUtil; |
126 iDigraphContactsTitleArray.ResetAndDestroy(); |
126 iDigraphContactsTitleArray.ResetAndDestroy(); |
|
127 |
|
128 if (iFeatureManagerInitialized) |
|
129 { |
|
130 // It can be safely called UnInitializeLib as it has been really intialized. |
|
131 FeatureManager::UnInitializeLib(); // Decreases ref.count |
|
132 } |
127 } |
133 } |
128 |
134 |
129 |
135 |
130 // -------------------------------------------------------------------------- |
136 // -------------------------------------------------------------------------- |
131 // CPbk2ContactEditorDlg::NewL |
137 // CPbk2ContactEditorDlg::NewL |
148 // |
154 // |
149 void CPbk2AdaptiveSearchGridFiller::ConstructL() |
155 void CPbk2AdaptiveSearchGridFiller::ConstructL() |
150 { |
156 { |
151 iKeyMap = HBufC::NewL( KAdaptiveSearchKeyMapGranularity ); |
157 iKeyMap = HBufC::NewL( KAdaptiveSearchKeyMapGranularity ); |
152 iFindUtil = CFindUtil::NewL(); |
158 iFindUtil = CFindUtil::NewL(); |
|
159 |
|
160 // Initialize feature manager |
|
161 FeatureManager::InitializeLibL(); |
|
162 iFeatureManagerInitialized = ETrue; |
153 // UI Language |
163 // UI Language |
154 TLanguage uiLanguage = User::Language(); |
164 TLanguage uiLanguage = User::Language(); |
155 if ( uiLanguage != ELangJapanese && uiLanguage != ELangPrcChinese && |
165 if ( uiLanguage != ELangJapanese && uiLanguage != ELangPrcChinese && |
156 uiLanguage != ELangHongKongChinese && uiLanguage != ELangTaiwanChinese && |
166 uiLanguage != ELangHongKongChinese && uiLanguage != ELangTaiwanChinese && |
157 uiLanguage != ELangKorean ) |
167 uiLanguage != ELangKorean ) |
412 iSetFocusToSearchGrid = ETrue; |
422 iSetFocusToSearchGrid = ETrue; |
413 } |
423 } |
414 |
424 |
415 void CPbk2AdaptiveSearchGridFiller::SetAdaptiveGridCharsL( |
425 void CPbk2AdaptiveSearchGridFiller::SetAdaptiveGridCharsL( |
416 const TInt aMaxSpacesNumber, const TInt aSearchStringSpacesNumber ) |
426 const TInt aMaxSpacesNumber, const TInt aSearchStringSpacesNumber ) |
417 { |
427 { |
418 TPtr ptr = iKeyMap->Des(); |
|
419 |
|
420 // Do upper case for all characters |
|
421 ptr.UpperCase(); |
|
422 CDesCArray* array = new (ELeave) CDesCArrayFlat( KAdaptiveSearchKeyMapGranularity ); |
|
423 CleanupStack::PushL( array ); |
|
424 TInt length = ptr.Length(); |
|
425 |
|
426 for( TInt ii = 0; ii < length; ii++ ) |
|
427 { |
|
428 array->AppendL( ptr.Mid( ii, 1 ) ); |
|
429 } |
|
430 |
|
431 // Alphabetical sort |
|
432 array->Sort( ECmpCollated ); |
|
433 ptr.Zero(); |
|
434 |
|
435 // Add space character only if: |
428 // Add space character only if: |
436 // - user typed already some characters in the find pane, |
429 // - user typed already some characters in the find pane, |
437 // - and more spaces can be found in contacts than in the current search string, |
430 // - and more spaces can be found in contacts than in the current search string, |
438 // - and space is not the last character in the search string. |
431 // - and space is not the last character in the search string. |
439 if ( iSearchString->Length() > 0 |
432 TBool addSpace = ( iSearchString->Length() > 0 |
440 && aMaxSpacesNumber > aSearchStringSpacesNumber |
433 && aMaxSpacesNumber > aSearchStringSpacesNumber |
441 && (*iSearchString)[iSearchString->Length() - 1] != TChar( ' ' ) ) |
434 && (*iSearchString)[iSearchString->Length() - 1] != TChar( ' ' ) ); |
442 { |
435 |
443 ptr.Append( TChar( ' ' ) ); |
436 SortGridL( addSpace ); |
444 } |
|
445 |
|
446 for( TInt ii = 0; ii < length; ii++ ) |
|
447 { |
|
448 ptr.Append(array->MdcaPoint( ii )); |
|
449 } |
|
450 CleanupStack::PopAndDestroy();//array |
|
451 |
437 |
452 if( iCurrentGrid ) |
438 if( iCurrentGrid ) |
453 { |
439 { |
454 if( !iCurrentGrid->Des().Compare( *iKeyMap ) ) |
440 if( !iCurrentGrid->Des().Compare( *iKeyMap ) ) |
455 { |
441 { |
477 iSetFocusToSearchGrid = EFalse; |
463 iSetFocusToSearchGrid = EFalse; |
478 } |
464 } |
479 |
465 |
480 } |
466 } |
481 |
467 |
|
468 void CPbk2AdaptiveSearchGridFiller::SortGridL( TBool aAddSpace ) |
|
469 { |
|
470 TPtr ptr = iKeyMap->Des(); |
|
471 |
|
472 // Do upper case for all characters |
|
473 ptr.UpperCase(); |
|
474 CDesCArray* array = new (ELeave) CDesCArrayFlat( KAdaptiveSearchKeyMapGranularity ); |
|
475 CleanupStack::PushL( array ); |
|
476 TInt length = ptr.Length(); |
|
477 |
|
478 for( TInt ii = 0; ii < length; ii++ ) |
|
479 { |
|
480 array->AppendL( ptr.Mid( ii, 1 ) ); |
|
481 } |
|
482 |
|
483 // Alphabetical sort |
|
484 array->Sort( ECmpCollated ); |
|
485 ptr.Zero(); |
|
486 |
|
487 if ( aAddSpace ) |
|
488 { |
|
489 ptr.Append( TChar( ' ' ) ); |
|
490 } |
|
491 |
|
492 for( TInt ii = 0; ii < length; ii++ ) |
|
493 { |
|
494 ptr.Append( array->MdcaPoint( ii ) ); |
|
495 } |
|
496 CleanupStack::PopAndDestroy();//array |
|
497 } |
482 |
498 |
483 CDesC16Array* CPbk2AdaptiveSearchGridFiller::SplitContactFieldTextIntoArrayLC( |
499 CDesC16Array* CPbk2AdaptiveSearchGridFiller::SplitContactFieldTextIntoArrayLC( |
484 const TDesC& aText ) |
500 const TDesC& aText ) |
485 { |
501 { |
486 // Attempt to minimize the allocations considering 3 words for the search fields: |
502 // Attempt to minimize the allocations considering 3 words for the search fields: |
510 array->AppendL( aText.Mid( beg, end - beg) ); |
526 array->AppendL( aText.Mid( beg, end - beg) ); |
511 |
527 |
512 // Scan for next word |
528 // Scan for next word |
513 beg = end; |
529 beg = end; |
514 } |
530 } |
515 |
531 |
|
532 // consonent based adaptive search: |
|
533 if ( FeatureManager::FeatureSupported( KFeatureIdKorean ) ) |
|
534 { |
|
535 /* |
|
536 When user has a contact with first name "??" and last name "?", |
|
537 It should be displayed with "? ??" in Korea variant. |
|
538 That means it should be found with search keyword, "?" or "??". |
|
539 Thus, need to put the "? ??" in the item list which is delivered to FindUtil. |
|
540 no need to care about just one word like "???" |
|
541 */ |
|
542 if ( array->MdcaCount() != 1 ) |
|
543 { |
|
544 array->AppendL( aText ); |
|
545 } |
|
546 } |
|
547 |
516 return array; |
548 return array; |
517 } |
549 } |
518 |
550 |
519 CDesC16Array* CPbk2AdaptiveSearchGridFiller::SplitSearchFieldTextIntoArrayLC( |
551 CDesC16Array* CPbk2AdaptiveSearchGridFiller::SplitSearchFieldTextIntoArrayLC( |
520 const TDesC& aText ) |
552 const TDesC& aText ) |
747 if ( iKeyMap->Des().MaxLength() < gridChars.Length() ) |
779 if ( iKeyMap->Des().MaxLength() < gridChars.Length() ) |
748 { |
780 { |
749 iKeyMap = iKeyMap->ReAllocL( gridChars.Length() ); |
781 iKeyMap = iKeyMap->ReAllocL( gridChars.Length() ); |
750 } |
782 } |
751 iKeyMap->Des().Copy( gridChars ); |
783 iKeyMap->Des().Copy( gridChars ); |
|
784 // Sort the grid, space is not needed |
|
785 SortGridL( EFalse ); |
752 |
786 |
753 delete iCurrentGrid; |
787 delete iCurrentGrid; |
754 iCurrentGrid = NULL; |
788 iCurrentGrid = NULL; |
755 iCurrentGrid = iKeyMap->Des().AllocL(); |
789 iCurrentGrid = iKeyMap->Des().AllocL(); |
756 |
790 |