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 | |
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 |
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 |