1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #include <cntviewbase.h>
21 /** The maximum length of the string used by contact sub view ranges to find the
22 item at the upper or lower limit of the range.
24 In practice, only the first character in the string is used and this value
26 const TInt KMaxBoundaryMatchLength=8;
28 class CContactGroupView: public CContactViewBase, public MContactViewObserver
29 /** Provides a view of a group of contact items.
31 The view uses an underlying view. For items to appear in the group view, they
32 must exist in the underlying view.
34 The TGroupType enumeration defines whether the view displays items that belong
35 to the group, items that do not belong to the group, or items that do not
38 The group view observes its underlying view so that it is kept up to date
39 if the contents of the underlying view change.
41 The group can be identified by a contact item ID or by a label, e.g. "family",
49 friend class CGroupViewTester;
51 /** Defines the types of contact group view. */
54 /** The view contains contact items in the group. */
56 /** The view contains contact items not in the group. */
57 EShowContactsNotInGroup,
58 /** The view contains contact items not in any group. */
59 EShowContactsNotInAnyGroup
62 IMPORT_C static CContactGroupView* NewL(const CContactDatabase& aDb,CContactViewBase& aView,MContactViewObserver& aObserver,const TContactItemId aGroupId,const TGroupType aGroupType);
63 IMPORT_C static CContactGroupView* NewL(const CContactDatabase& aDb,CContactViewBase& aView,MContactViewObserver& aObserver, const TDesC& aGroupName,const TGroupType aGroupType);
65 // Factory constructor for version 2 behaviour
66 IMPORT_C static CContactGroupView* NewL(CContactViewBase& aView,const CContactDatabase& aDb, MContactViewObserver& aObserver,const TContactItemId aGroupId,const TGroupType aGroupType);
67 // Factory constructor for version 2 behaviour
68 IMPORT_C static CContactGroupView* NewL(CContactViewBase& aView,const CContactDatabase& aDb, MContactViewObserver& aObserver, const TDesC& aGroupName,const TGroupType aGroupType);
69 //All CContactViewBase derived classes in public headers,
70 //should mandatorily implement this reserved function.
71 TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams);
73 public: // From CContactViewBase
74 TContactItemId AtL(TInt aIndex) const;
76 TInt FindL(TContactItemId aId) const;
77 HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const;
78 const CViewContact& ContactAtL(TInt aIndex) const;
79 TContactViewPreferences ContactViewPreferences();
80 const RContactViewSortOrder& SortOrderL() const;
82 IMPORT_C virtual void UpdateGroupViewL();
83 private: // From MContactViewObserver.
84 void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent);
86 void ConstructL(MContactViewObserver& aObserver,TContactItemId aGroupId);
87 void UpdateForContactsInGroupL();
88 void UpdateForContactsNotInThisGroupL();
89 void UpdateForUnfiledContactsL();
90 void UpdateForContactListL(const CContactIdArray* aArray);
91 TContactItemId GetGroupIdbyNameL(const TDesC& aGroupName);
92 TBool HandleRemoveEventL(TContactViewEvent& aEvent);
93 TBool HandleAddEventL(TContactViewEvent& aEvent);
94 TBool HandleAddEventForUnfiledContactsL(const TContactViewEvent& aEvent );
95 static TInt CompareMappingsL(const TContactIdWithMapping& aFirst,const TContactIdWithMapping& aSecond);
96 TInt static CompareIndexesAllowingDuplicates(const TContactIdWithMapping& aFirst, const TContactIdWithMapping& aSecond);
98 CContactGroupView(const CContactDatabase& aDb,CContactViewBase& aView,TGroupType aGroupType);
99 void UpdateMappingsL();
100 void NotifyRemovedMembersL(const CContactIdArray* aArray);
102 RArray<TContactIdWithMapping> iGroupContacts;
103 TContactItemId iGroupId;
104 CContactViewBase& iView;
105 TGroupType iGroupType;
106 TUint iClassVersion; //version class - used for TContactViewEvent dispatching
110 class CContactFindView: public CContactViewBase, public MContactViewObserver
111 /** Provides a view of an existing CContactViewBase-derived object, populated using
114 The find view only contains contact items from the underlying view that match
117 The find view observes its underlying view so that it is kept up to date if
118 the contents of the underlying view change.
120 The search criteria (one or more words) are held in an MDesCArray object.
121 The fields involved in the search are those that have been used to sort the
128 IMPORT_C static CContactFindView* NewL(const CContactDatabase& aDb,CContactViewBase& aView,MContactViewObserver& aObserver,MDesCArray* aFindWords);
129 IMPORT_C static CContactFindView* NewL(const CContactDatabase& aDb,CContactViewBase& aView,MContactViewObserver& aObserver,MDesCArray* aFindWords, TSearchType aSearchType);
131 // Factory constructor for version 2 behaviour
132 IMPORT_C static CContactFindView* NewL(CContactViewBase& aView,const CContactDatabase& aDb,MContactViewObserver& aObserver,MDesCArray* aFindWords);
133 // Factory constructor for version 2 behaviour
134 IMPORT_C static CContactFindView* NewL(CContactViewBase& aView,const CContactDatabase& aDb,MContactViewObserver& aObserver,MDesCArray* aFindWords, TSearchType aSearchType);
137 public: // From CContactViewBase
138 TContactItemId AtL(TInt aIndex) const;
140 TInt FindL(TContactItemId aId) const;
141 HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const;
142 const CViewContact& ContactAtL(TInt aIndex) const;
143 TContactViewPreferences ContactViewPreferences();
144 const RContactViewSortOrder& SortOrderL() const;
146 IMPORT_C virtual void UpdateFindViewL();
148 IMPORT_C void RefineFindViewL(MDesCArray* aFindWords);
149 //All CContactViewBase derived classes in public headers,
150 //should mandatorily implement this reserved function.
151 TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams);
152 private: // From MContactViewObserver.
153 virtual void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent);
155 void ConstructL(MContactViewObserver& aObserver,MDesCArray* aFindWords);
156 void DeleteFindContacts();
157 void TightenFindViewCriteriaL();
158 void HandleRemoveEventL(TContactViewEvent& aEvent);
159 void HandleAddEventL(TContactViewEvent& aEvent);
160 void CopyNewFindWordsL(MDesCArray* aFindWords);
161 void DestroyFindWordsArray();
162 TInt InsertContact(const CViewContact* aNewContact);
164 CContactFindView(const CContactDatabase& aDb,CContactViewBase& aView, TSearchType aSearchType);
166 RPointerArray<CViewContact> iFindContacts;
167 CPtrCArray* iFindWords;
168 CContactViewBase& iView;
169 const TSearchType iSearchType;
170 TUint iClassVersion; //version class - used for TContactViewEvent dispatching
174 class CContactFilteredView : public CContactViewBase, public MContactViewObserver
175 /** Provides a filtered view over an existing CContactViewBase derived object.
177 For example, it might provide a view containing only contacts that have an
178 email address. For efficiency reasons there are a limited set of filters available
179 (defined in CContactDatabase::TContactViewFilter).
181 The filtered view observes its underlying view so that it is kept up to date
182 if the contents of the underlying view change. It will, in turn, notify its
185 Filters only apply to non-hidden contact fields with content.
191 IMPORT_C static CContactFilteredView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,CContactViewBase& aView,TInt aFilter);
192 // Factory constructor for version 2 behaviour
193 IMPORT_C static CContactFilteredView* NewL(CContactViewBase& aView,const CContactDatabase& aDb,MContactViewObserver& aObserver,TInt aFilter);
195 //All CContactViewBase derived classes in public headers,
196 //should mandatorily implement this reserved function.
197 TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams);
198 ~CContactFilteredView();
199 public: // From CContactViewBase.
200 TContactItemId AtL(TInt aIndex) const;
202 TInt FindL(TContactItemId aId) const;
203 HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const;
204 const CViewContact& ContactAtL(TInt aIndex) const;
205 TContactViewPreferences ContactViewPreferences();
206 const RContactViewSortOrder& SortOrderL() const;
207 virtual void ContactsMatchingCriteriaL(const MDesCArray& aFindWords,RPointerArray<CViewContact>& aMatchedContacts);
208 virtual void ContactsMatchingPrefixL(const MDesCArray& aFindWords, RPointerArray<CViewContact>& aMatchedContacts);
209 private: // From MContactViewObserver.
210 virtual void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent);
212 CContactFilteredView(const CContactDatabase& aDb,TInt aFilter,CContactViewBase& aView);
213 void ConstructL(MContactViewObserver& aObserver);
214 void CreateFilteredIdArray();
215 void UpdateFilteredIdArrayL(TContactViewEvent& aEvent, TBool& aViewModified);
216 void HandleAddEventL(TContactViewEvent& aEvent, TBool& aViewModified);
217 void HandleRemoveEventL(TContactViewEvent& aEvent, TBool& aViewModified);
218 TInt BinaryInsertL(TContactIdWithMapping aId);
219 static TInt FilterCallBack(TAny* aSelf);
220 static TBool CompareMappings(const TContactIdWithMapping& aFirst,const TContactIdWithMapping& aSecond);
221 void FilterResultsArray(RPointerArray<CViewContact>& aMatchedContacts);
222 TInt DoFilterIncrementL();
223 void UpdateMappingsL();
226 CContactViewBase& iView;
227 RArray<TContactIdWithMapping> iFilteredIdArray;
228 TUint iClassVersion; //version class - used for TContactViewEvent dispatching
232 class CContactViewRangeBase : public CBase
233 /** The abstract base class for all contact view range classes.
235 Range classes are used by contact sub views to specify the upper and lower
236 range boundaries and for searching their underlying view.
244 /** Defines the range criteria. */
249 /** Less than or equal to. */
253 /** Greater than or equal to. */
254 EGreaterThanOrEqualTo
257 ~CContactViewRangeBase();
258 inline TInt LowIndex() const;
259 inline TInt HighIndex() const;
260 /** Sets the iLow and iHigh members. */
261 virtual void SetL()=0;
262 IMPORT_C TBool IndicesValid() const;
264 CContactViewRangeBase(const CContactViewBase& aView);
266 TInt FindIndexL(const TDesC& aMatch,TCriteria aCriteria) const;
267 TBool MatchesCriteriaL(TCriteria aCriteria,const TDesC& aMatch,TInt aIndex) const;
268 void ValidateIndices();
270 /** The sub view's underlying view. */
271 const CContactViewBase& iView;
272 /** The index into the sub view's underlying view of the item at the lower limit
275 /** The index into the sub view's underlying view of the item at the upper limit
278 //ChrisD: contain by value not ptr
279 /** The collation method used to sort the strings.
281 By default, this is the standard collation method for the current locale. */
282 TCollationMethod* iCollateMethod;
286 class CContactViewRange : public CContactViewRangeBase
287 /** A sub view range with both a lower and upper limit.
289 This is used by sub views when lower and upper boundary criteria are specified.
297 ~CContactViewRange();
298 IMPORT_C static CContactViewRange* NewL(const CContactViewBase& aView,const TDesC& aLowMatch,TCriteria aLowCriteria,const TDesC& aHighMatch,TCriteria aHighCriteria);
299 private: // From CContactViewRangeBase.
302 CContactViewRange(const CContactViewBase& aView,const TDesC& aLowMatch,TCriteria aLowCriteria,const TDesC& aHighMatch,TCriteria aHighCriteria);
305 TBuf<KMaxBoundaryMatchLength> iLowMatch;
306 TCriteria iLowCriteria;
307 TBuf<KMaxBoundaryMatchLength> iHighMatch;
308 TCriteria iHighCriteria;
312 class CContactViewLowRange : public CContactViewRangeBase
313 /** A sub view range with an upper limit only.
315 This is used by sub views when the range criteria are CContactViewRangeBase::ELessThan
316 or CContactViewRangeBase::ELessThanOrEqualTo.
324 IMPORT_C static CContactViewLowRange* NewL(const CContactViewBase& aView,const TDesC& aMatch,TCriteria aCriteria);
325 private: // From CContactViewRangeBase.
328 CContactViewLowRange(const CContactViewBase& aView,const TDesC& aMatch,TCriteria aCriteria);
329 //ChrisD: why private d'tor
330 ~CContactViewLowRange();
332 TBuf<KMaxBoundaryMatchLength> iMatch;
337 class CContactViewHighRange : public CContactViewRangeBase
338 /** A sub view range with a lower limit only.
340 This is used by sub views when the range criteria are CContactViewRangeBase::EGreaterThan
341 or CContactViewRangeBase::EGreaterThanOrEqualTo.
349 IMPORT_C static CContactViewHighRange* NewL(const CContactViewBase& aView,const TDesC& aMatch,TCriteria aCriteria);
350 private: // From CContactViewRangeBase.
353 CContactViewHighRange(const CContactViewBase& aView,const TDesC& aMatch,TCriteria aCriteria);
354 //ChrisD: why private d'tor
355 ~CContactViewHighRange();
357 TBuf<KMaxBoundaryMatchLength> iMatch;
362 class CContactSubView : public CContactViewBase, public MContactViewObserver
363 /** Provides a view of a range of contact items from a potentially larger underlying
364 view (another CContactViewBase-derived object).
366 All contact items between a lower and upper boundary in the underlying view
367 are included in the sub view. For example, the sub view might contain all
368 items whose name begins with a character between 'd' and 'f'.
370 The sub view observes its underlying view so that as the underlying view changes,
371 the sub view is kept up to date.
377 IMPORT_C static CContactSubView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,CContactViewBase& aView,const TDesC& aBoundary);//>= > is infinity <= < =0;
378 IMPORT_C static CContactSubView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,CContactViewBase& aView,const TDesC& aLowBoundary,const TDesC& aHighBoundary);
380 // Factory constructor for version 2 behaviour
381 IMPORT_C static CContactSubView* NewL(CContactViewBase& aView,const CContactDatabase& aDb,MContactViewObserver& aObserver,const TDesC& aBoundary);//>= > is infinity <= < =0;
382 // Factory constructor for version 2 behaviour
383 IMPORT_C static CContactSubView* NewL(CContactViewBase& aView,const CContactDatabase& aDb,MContactViewObserver& aObserver,const TDesC& aLowBoundary,const TDesC& aHighBoundary);
385 //All CContactViewBase derived classes in public headers,
386 //should mandatorily implement this reserved function.
387 TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams);
388 public: // From CContactViewBase.
389 TContactItemId AtL(TInt aIndex) const;
391 TInt FindL(TContactItemId aId) const;
392 HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const;
393 const CViewContact& ContactAtL(TInt aIndex) const;
394 TContactViewPreferences ContactViewPreferences();
395 const RContactViewSortOrder& SortOrderL() const;
396 private: // From MContactViewObserver.
397 virtual void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent);
399 //ChrisD: why private d'tor
401 CContactSubView(const CContactDatabase& aDb,CContactViewBase& aView);
402 CContactSubView(const CContactDatabase& aDb,const CContactSubView& aView);
403 void CommonConstructL(MContactViewObserver& aObserver);
404 void ConstructL(MContactViewObserver& aObserver,const TDesC& aBoundary);
405 void ConstructL(MContactViewObserver& aObserver,const CContactSubView& aView);
406 void ConstructL(MContactViewObserver& aObserver,const CContactSubView& aView,const TDesC& aBoundary);
407 void ConstructL(MContactViewObserver& aObserver,const TDesC& aLowBoundary,const TDesC& aHighBoundary);
408 CContactViewRangeBase::TCriteria DecodeBoundary(TDes& aBoundary) const;
409 TInt MapToUnderlyingViewIndex(TInt aSubViewIndex) const;
410 TInt MapToSubViewIndex(TInt aUnderlyingViewIndex) const;
412 CContactViewBase& iView;
413 CContactViewRangeBase* iRange;
414 TUint iClassVersion; //version class - used for TContactViewEvent dispatching
418 class CContactConcatenatedView : public CContactViewBase, public MContactViewObserver
419 /** Concatenates multiple contact views into a single contiguous view.
421 The component views are ordered according to their order in the array passed
428 IMPORT_C static CContactConcatenatedView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,RPointerArray<CContactViewBase>& aComponentViews);
429 //All CContactViewBase derived classes in public headers,
430 //should mandatorily implement this reserved function.
431 TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams);
432 public: // From CContactViewBase.
433 TContactItemId AtL(TInt aIndex) const;
435 TInt FindL(TContactItemId aId) const;
436 HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const;
437 const CViewContact& ContactAtL(TInt aIndex) const;
438 TContactViewPreferences ContactViewPreferences();
439 const RContactViewSortOrder& SortOrderL() const;
440 private: // From MContactViewObserver.
441 virtual void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent);
443 struct TComponentView
445 TComponentView(CContactViewBase& aView,TState aState);
446 CContactViewBase& iView;
450 ~CContactConcatenatedView();
451 CContactConcatenatedView(const CContactDatabase& aDb);
452 void ConstructL(MContactViewObserver& aObserver,RPointerArray<CContactViewBase>& aComponentViews);
453 void CopyComponentViewsL(RPointerArray<CContactViewBase>& aComponentViews);
454 void OpenComponentViewsL();
455 void CloseComponentViews();
456 TBool ComponentViewsReady();
457 void SetComponentViewReady(const CContactViewBase& aView);
458 TInt OffsetL(const CContactViewBase& aView);
459 static TBool ComponentViewsEqual(const TComponentView& aFirst,const TComponentView& aSecond);
460 TInt FindComponentView(const CContactViewBase& aView);
462 RArray<TComponentView> iComponentView;
466 inline TInt CContactViewRangeBase::LowIndex() const
467 /** Gets the index into the sub view's underlying view of the item at the bottom
470 @return The index of the item at the bottom of the range. */
473 inline TInt CContactViewRangeBase::HighIndex() const
474 /** Gets the index into the sub view's underlying view of the item at the top of
477 @return The index of the item at the top of the range. */