|
1 /* |
|
2 * Copyright (c) 2005-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Phonebook 2 Predictive search view stack. |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef CPBK2PREDICTIVEVIEWSTACK_H |
|
19 #define CPBK2PREDICTIVEVIEWSTACK_H |
|
20 |
|
21 // INCLUDES |
|
22 #include <e32base.h> |
|
23 #include <MVPbkContactViewObserver.h> |
|
24 #include <MVPbkContactViewBase.h> |
|
25 #include <badesca.h> |
|
26 #include "MPbk2FilteredViewStack.h" |
|
27 #include <MPsResultsObserver.h> |
|
28 #include <CPsClientData.h> |
|
29 #include <CPsPattern.h> |
|
30 #include <CVPbkContactLinkArray.h> |
|
31 |
|
32 // FORWARD DECLARATIONS |
|
33 class CVPbkContactFindPolicy; |
|
34 class MVPbkContactBookmarkCollection; |
|
35 class CPSRequestHandler; |
|
36 class CPsSettings; |
|
37 class CVPbkContactIdConverter; |
|
38 class CPsQuery; |
|
39 class CVPbkTopContactManager; |
|
40 class CPbk2ContactPositionInfo; |
|
41 class CPbk2PredictiveSearchFilter; |
|
42 class MPbk2ContactNameFormatter; |
|
43 |
|
44 // CLASS DECLARATION |
|
45 /** |
|
46 * Implements Predictive Searching for Pbk2 UI. Uses Predictive Search Engine. |
|
47 */ |
|
48 NONSHARABLE_CLASS(CPbk2PredictiveViewStack) : public CActive, |
|
49 public MPbk2FilteredViewStack, |
|
50 private MVPbkContactViewObserver, |
|
51 public MPsResultsObserver |
|
52 { |
|
53 public: // Constructors and destructor |
|
54 |
|
55 /** |
|
56 * Creates a new instance of this class. |
|
57 * |
|
58 * @param aBaseView The non-filtered base view. |
|
59 * @param aSearchFilter SearchPane Filter |
|
60 * @param aNameformatter PBk2 contact name formatter interface |
|
61 * @return A new instance of this class. |
|
62 */ |
|
63 static CPbk2PredictiveViewStack* NewL( |
|
64 MVPbkContactViewBase& aBaseView, |
|
65 CPbk2PredictiveSearchFilter& aSearchFilter, |
|
66 MPbk2ContactNameFormatter& aNameformatter ); |
|
67 |
|
68 /** |
|
69 * Destructor. |
|
70 */ |
|
71 ~CPbk2PredictiveViewStack(); |
|
72 |
|
73 public: // From MPbk2FilteredViewStack |
|
74 |
|
75 void UpdateFilterL( |
|
76 const MDesCArray& aFindStrings, |
|
77 const MVPbkContactBookmarkCollection* aAlwaysincluded, |
|
78 TBool aAlwaysIncludedChanged ); |
|
79 |
|
80 void Reset(); |
|
81 |
|
82 MVPbkContactViewBase& BaseView() const; |
|
83 |
|
84 void SetNewBaseViewL( |
|
85 MVPbkContactViewBase& aBaseView ); |
|
86 |
|
87 TInt Level() const; |
|
88 |
|
89 public: // New methods |
|
90 |
|
91 void AddStackObserverL( |
|
92 MPbk2FilteredViewStackObserver& aStackObserver ); |
|
93 |
|
94 void RemoveStackObserver( |
|
95 MPbk2FilteredViewStackObserver& aStackObserver ); |
|
96 |
|
97 |
|
98 public: // From MVPbkContactViewBase |
|
99 TVPbkContactViewType Type() const; |
|
100 void ChangeSortOrderL( |
|
101 const MVPbkFieldTypeList& aSortOrder ); |
|
102 const MVPbkFieldTypeList& SortOrder() const; |
|
103 void RefreshL(); |
|
104 TInt ContactCountL() const; |
|
105 const MVPbkViewContact& ContactAtL( |
|
106 TInt aIndex ) const; |
|
107 MVPbkContactLink* CreateLinkLC( |
|
108 TInt aIndex ) const; |
|
109 TInt IndexOfLinkL( |
|
110 const MVPbkContactLink& aContactLink ) const; |
|
111 void AddObserverL( |
|
112 MVPbkContactViewObserver& aObserver ); |
|
113 void RemoveObserver( |
|
114 MVPbkContactViewObserver& aObserver ); |
|
115 TBool MatchContactStore( |
|
116 const TDesC& aContactStoreUri ) const; |
|
117 TBool MatchContactStoreDomain( |
|
118 const TDesC& aContactStoreDomain ) const; |
|
119 MVPbkContactBookmark* CreateBookmarkLC( |
|
120 TInt aIndex ) const; |
|
121 TInt IndexOfBookmarkL( |
|
122 const MVPbkContactBookmark& aContactBookmark ) const; |
|
123 MVPbkContactViewFiltering* ViewFiltering(); |
|
124 |
|
125 private: // From MVPbkContactViewObserver |
|
126 void ContactViewReady( |
|
127 MVPbkContactViewBase& aView ); |
|
128 void ContactViewUnavailable( |
|
129 MVPbkContactViewBase& aView ); |
|
130 void ContactAddedToView( |
|
131 MVPbkContactViewBase& aView, |
|
132 TInt aIndex, |
|
133 const MVPbkContactLink& aContactLink ); |
|
134 void ContactRemovedFromView( |
|
135 MVPbkContactViewBase& aView, |
|
136 TInt aIndex, |
|
137 const MVPbkContactLink& aContactLink ); |
|
138 void ContactViewError( |
|
139 MVPbkContactViewBase& aView, |
|
140 TInt aError, |
|
141 TBool aErrorNotified ); |
|
142 |
|
143 private: // from MPsResultsObserver |
|
144 |
|
145 void HandlePsResultsUpdate( |
|
146 RPointerArray<CPsClientData>& searchResults, |
|
147 RPointerArray<CPsPattern>& searchSeqs); |
|
148 |
|
149 void HandlePsError(TInt aErrorCode); |
|
150 |
|
151 void CachingStatus(TCachingStatus& aStatus, TInt& aError); |
|
152 |
|
153 private: // From CActive |
|
154 |
|
155 void RunL(); |
|
156 void DoCancel(); |
|
157 TInt RunError( TInt aError ); |
|
158 |
|
159 private: // Implementation |
|
160 CPbk2PredictiveViewStack( CPbk2PredictiveSearchFilter& aSearchFilter, |
|
161 MPbk2ContactNameFormatter& aNameformatter ); |
|
162 |
|
163 void ConstructL( |
|
164 MVPbkContactViewBase& aBaseView ); |
|
165 |
|
166 void InitializePCSEngineL(); |
|
167 void HandleContactDeletionL(MVPbkContactViewBase& aView, TInt aIndex, |
|
168 const MVPbkContactLink& aContactLink); |
|
169 void CalculateSearchResultIndexesL(RPointerArray<CPsClientData>& aSearchResults); |
|
170 |
|
171 TInt BaseViewIndex( TInt aSearchResultIndex ) const; |
|
172 void SendTopViewChangedEvent( MVPbkContactViewBase& aOldTopView ); |
|
173 void SendTopViewUpdatedEvent(); |
|
174 void SendBaseViewChangedEvent(); |
|
175 void ClearSearch(); |
|
176 |
|
177 public: |
|
178 /** |
|
179 * Return last Predictive Search query. |
|
180 * This object is used in underlying and bookmark restoring. |
|
181 * All Predictive Search result is valid only for one query. |
|
182 * @return pointer to the last PCS query object. |
|
183 */ |
|
184 const CPsQuery* LastPCSQuery() const; |
|
185 |
|
186 /** |
|
187 * Returns the instance of the request handler object for the Predicitve Search application |
|
188 * |
|
189 * @return pointer to the CPSRequestHandler. |
|
190 */ |
|
191 CPSRequestHandler* PSHandler() const; |
|
192 |
|
193 /** |
|
194 * Get mathes part from data model object. |
|
195 * Data model uses mathes patterns returned from PCS server. |
|
196 * This method is added for bidirectional languages. |
|
197 |
|
198 * @param aSearchData The input data to be searched. |
|
199 * @param aMatchLocation The list matched index and length of match |
|
200 */ |
|
201 void GetMatchingPartsL( const TDesC& aSearchData, |
|
202 RArray<TPsMatchLocation>& aMatchLocation) const; |
|
203 |
|
204 /** |
|
205 * Sends no matched event of the last predictive search |
|
206 * to the search filter. |
|
207 */ |
|
208 void SendPSNoResultsEventL(); |
|
209 |
|
210 /** |
|
211 * Set the group contact link for curently open group. |
|
212 * |
|
213 * @param aGroupLinktoSet The input group contact link |
|
214 */ |
|
215 void SetCurrentGroupLinkL( MVPbkContactLink* aGroupLinktoSet); |
|
216 private: |
|
217 /** |
|
218 * Create copy of matches patterns from PCS server |
|
219 * Also creates patterns to be used in bidirectional matches functional |
|
220 */ |
|
221 void CreatePatternsL(RPointerArray<CPsPattern>& searchSeqs); |
|
222 |
|
223 |
|
224 // Perform the psengine settings. |
|
225 void SetPsSettingL( RPointerArray<TDesC>& aDatabases); |
|
226 |
|
227 /** |
|
228 * save marked contacts info to iMarkedContactsPositionInfoArray, marked |
|
229 * top contacts are excluded |
|
230 */ |
|
231 void SaveBookmarkContatsInfoL(); |
|
232 |
|
233 /** |
|
234 * move given array to top of searched result |
|
235 * @param aContactInfoArray array to be moved. |
|
236 */ |
|
237 void MoveArrayToSearchedResultTopL( |
|
238 RPointerArray<CPbk2ContactPositionInfo>& aContactInfoArray ); |
|
239 |
|
240 /** |
|
241 * find from iTopContactPositionInfoArray by index of contact in iBaseView |
|
242 * @return KErrNotFound if not found |
|
243 */ |
|
244 TInt MatchingTopContactFind( const TInt aIndexInBaseView ); |
|
245 |
|
246 /** |
|
247 * sort the give array by position in main view. |
|
248 * @param aContactInfoArray array to be sorted. |
|
249 */ |
|
250 void SortbyPositionInMainView( |
|
251 RPointerArray<CPbk2ContactPositionInfo>& aContactInfoArray ); |
|
252 |
|
253 public: |
|
254 |
|
255 /** |
|
256 * @param index of contact |
|
257 * @return true if the contact of index belongs to non matching marked contacts. |
|
258 */ |
|
259 TBool IsNonMatchingMarkedContact( const TInt aIndex ); |
|
260 |
|
261 private: // Data |
|
262 |
|
263 RPointerArray<MVPbkContactViewObserver> iViewObservers;// Ref: View observers |
|
264 |
|
265 RPointerArray<MPbk2FilteredViewStackObserver> iStackObservers;// Ref: Stack observers |
|
266 |
|
267 /**The base view of CPbk2PredictiveViewStack |
|
268 * Not own |
|
269 */ |
|
270 MVPbkContactViewBase* iBaseView; //The base view of CPbk2PredictiveViewStack |
|
271 |
|
272 TBool iViewReady;//ETrue if view is ready |
|
273 |
|
274 TBool iSearchedState; //ETrue if Predictive search view is created |
|
275 |
|
276 /**Contact id converter for DefaultCntDbUri() |
|
277 * own |
|
278 */ |
|
279 CVPbkContactIdConverter* iConverterDefaultStore; |
|
280 |
|
281 /**Predictive search handler |
|
282 * own |
|
283 */ |
|
284 CPSRequestHandler* iPsHandler; //Predictive search handler |
|
285 |
|
286 |
|
287 /** Query passed to PCS engine |
|
288 * own |
|
289 */ |
|
290 CPsQuery* iPsQuery;// |
|
291 |
|
292 /**Contact link of searched contacts |
|
293 * own |
|
294 */ |
|
295 CVPbkContactLinkArray* iPredictiveSearchResultContactLinkArrray; // |
|
296 |
|
297 //Owns : Array that holds the result pattern for predictive search |
|
298 RPointerArray< CPsPattern > iPatternsCollection; |
|
299 |
|
300 /// Own: Array of bidirectional patterns |
|
301 RPointerArray<HBufC> iBidiPatterns; |
|
302 |
|
303 /** |
|
304 * CVPbkTopContactManager used for checking if contact is top contact |
|
305 * own |
|
306 */ |
|
307 CVPbkTopContactManager* iTopContactManager; |
|
308 |
|
309 /** |
|
310 * temporary array contains top contact position infomation from iBaseView, |
|
311 * those top contacts are from PS search results |
|
312 * own |
|
313 */ |
|
314 RPointerArray<CPbk2ContactPositionInfo> iTopContactPositionInfoArray; |
|
315 |
|
316 |
|
317 //Owns : Group contact link for the currently open Group |
|
318 MVPbkContactLink* iCurrentGroupLink; |
|
319 |
|
320 /// Own: True if predictive search is enabled |
|
321 TBool iPredictiveSearch; |
|
322 |
|
323 /// Own: Text from search control |
|
324 RBuf iSearchText; |
|
325 |
|
326 /** |
|
327 * store marked contact's links |
|
328 * not own |
|
329 */ |
|
330 MVPbkContactBookmarkCollection* iBookMarkCollection; |
|
331 |
|
332 /** |
|
333 * temporary array contains marked contact position infomation from iBaseView, |
|
334 * these contacts non matching contacts from search result. |
|
335 * own |
|
336 */ |
|
337 RPointerArray<CPbk2ContactPositionInfo> iMarkedContactsPositionInfoArray; |
|
338 |
|
339 /** |
|
340 * Predictive search filter |
|
341 * ref |
|
342 */ |
|
343 CPbk2PredictiveSearchFilter& iSearchFilter; |
|
344 |
|
345 ///Ref : PBk2 contact name formatter interface |
|
346 MPbk2ContactNameFormatter& iNameformatter; |
|
347 |
|
348 //Flag to indicate Feature manager initilization |
|
349 TBool iFeatureManagerInitilized ; |
|
350 |
|
351 //Stores the Start Index of the Marked Contact that is not |
|
352 //part of our searched contact list |
|
353 TInt iNonMatchedMarkedContactStartIndex; |
|
354 |
|
355 //Stores the End Index of the Marked Contact that is not |
|
356 //part of our searched contact list |
|
357 TInt iNonMatchedMarkedContactEndIndex; |
|
358 }; |
|
359 |
|
360 #endif // CPBK2_PREDICTIVEVIEWSTACK_H |
|
361 |
|
362 // End of File |