phonebookengines/contactsmodel/inc/cntviewbase.h
branchRCL_3
changeset 20 f4a778e096c2
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __CNTVIEWBASE_H__
       
    17 #define __CNTVIEWBASE_H__
       
    18 
       
    19 // System includes
       
    20 #include <e32std.h>
       
    21 #include <s32mem.h>
       
    22 
       
    23 #include <cntdb.h>
       
    24 
       
    25 // Classes referenced
       
    26 class CViewContactExtension;
       
    27 class CContactViewBase;
       
    28 class CContactRemoteViewNotifier;
       
    29 class CIdleContactSorter;
       
    30 class CContactViewFindConfigInterface;
       
    31 class CViewContactSortPlugin;
       
    32 class TSortPluginViewParams;
       
    33 
       
    34 /** View preferences for sorted contact views.
       
    35 
       
    36 This is used to specify the types of contact item that should be sorted and 
       
    37 included in the view and the behaviour for items that cannot be sorted because 
       
    38 they do not have content in any of the fields specified in the view's sort 
       
    39 order.
       
    40 
       
    41 The default behaviour is to include contact cards only and to sort contact 
       
    42 cards without content in any of the sort order fields using the first available 
       
    43 field containing any text.
       
    44 
       
    45 The view preferences for all concrete contact view classes can be retrieved 
       
    46 using their implementation of CContactViewBase::ContactViewPreferences(). 
       
    47 The view preferences are set during construction of a CContactLocalView. 
       
    48 
       
    49 @publishedAll
       
    50 @released
       
    51 */
       
    52 enum TContactViewPreferences
       
    53 	{
       
    54 	/** Only contact cards (of type KUidContactCard or KUidContactOwnCard) are included 
       
    55 	in the view. This is the default. */
       
    56 	EContactsOnly					=0x00000000,
       
    57 	/** Only contact groups (of type KUidContactGroup) are included in the view. */
       
    58 	EGroupsOnly						=0x00000001, 
       
    59 	/** Contact groups and contact cards (of type KUidContactGroup, KUidContactCard 
       
    60 	or KUidContactOwnCard) are included in the view. */
       
    61 	EContactAndGroups				=0x00000002, 
       
    62 	/** Excludes contact items from the view which don't have content in any of the 
       
    63 	fields specified in the sort order. */
       
    64 	EIgnoreUnSorted					=0x00000004, 
       
    65 	/** Includes contacts in the view which don't have content in any of the fields 
       
    66 	specified in the sort order. These contacts are placed in an unsorted contact 
       
    67 	list which is located before the sorted list. */
       
    68 	EUnSortedAtBeginning			=0x00000008, 
       
    69 	/** Includes contacts in the view which don't have content in any of the fields 
       
    70 	specified in the sort order. These contacts are placed in an unsorted contact 
       
    71 	list which is located after the sorted list. */
       
    72 	EUnSortedAtEnd					=0x00000010, 
       
    73 	/** Fields containing a single white space only are treated as empty, and therefore 
       
    74 	unsortable. */
       
    75 	ESingleWhiteSpaceIsEmptyField	=0x00000020,
       
    76 	/** Only ICC entries (of type KUidContactICCEntry) are included in the view. */
       
    77 	EICCEntriesOnly					=0x00000040, 
       
    78 	/** Only contact cards and ICC entries (of type KUidContactCard, KUidContactOwnCard 
       
    79 	or KUidContactICCEntry) are included in the view. */
       
    80 	EICCEntriesAndContacts			=0x00000080,
       
    81 	/** Only contact cards (of type KUidContactCard) are included 
       
    82 	in the view. Own card not included. */
       
    83     EContactCardsOnly				=0x00000100
       
    84 	};
       
    85 
       
    86 
       
    87 class TContactViewEvent
       
    88 /** Identifies a contact view event.
       
    89 
       
    90 Sent by contact views when notifying their observers of an event.
       
    91 
       
    92 @see MContactViewObserver::HandleContactViewEvent() 
       
    93 @publishedAll
       
    94 @released
       
    95 */
       
    96 	{
       
    97 public:
       
    98 	/** Identifies the event's type. */
       
    99 	enum TEventType
       
   100 		{
       
   101 		/** The observed view's state has changed from EReady to either ENotReady or EInitializing, 
       
   102 		so is not available for use. */
       
   103 		EUnavailable,
       
   104 		/** The observed view's state has changed from ENotReady or EInitializing to EReady 
       
   105 		so is available for use. */
       
   106 		EReady,
       
   107 		/** The observed view's sort order has changed, so observer views need to update 
       
   108 		themselves. */
       
   109 		ESortOrderChanged,
       
   110 		/** An error occurred when sorting the observed view or when appending an observer 
       
   111 		to its observer array. 
       
   112 	
       
   113 		The error code is provided in iInt. */
       
   114 		ESortError,
       
   115 		/** An error occurred in the contacts server.
       
   116 	
       
   117 		The error code is provided in iInt. */
       
   118 		EServerError,
       
   119 		/** An error occurred when setting the range for a CContactSubView.
       
   120 	
       
   121 		The error code is provided in iInt. */
       
   122 		EIndexingError,
       
   123 		/** An item has been added to the observed view. 
       
   124 	
       
   125 		The ID of the added item is provided in iContactId and the index into the 
       
   126 		observed view of the added item is provided in iInt. 
       
   127 		Exception from this are the first version of CContactFindView, CContactSubView and
       
   128 		CContactGroupView classes.
       
   129 		For these classes, iInt has KErrNone value */
       
   130 
       
   131 		EItemAdded,
       
   132 		/** An item has been removed from the observed view. 
       
   133 	
       
   134 		The ID of the removed item is provided in iContactId and the index into the 
       
   135 		observed view of the item is provided in iInt. 
       
   136 		Exception from this are the first version of CContactFindView and CContactSubView classes.
       
   137 		For these classes, iInt has KErrNone value */
       
   138 
       
   139 		EItemRemoved,
       
   140 		/** A change has occurred in a contact group, for instance a contact item has been 
       
   141 		moved into or out of the group.
       
   142 	
       
   143 		The ID of the group affected is provided in iContactId. */
       
   144 		EGroupChanged
       
   145 		};
       
   146 public:
       
   147 	inline TContactViewEvent();
       
   148 	inline TContactViewEvent(TEventType aEventType,TInt aInt = KErrUnknown,TContactItemId aContactId = KErrUnknown); 
       
   149 public:
       
   150 	/** The type of event. */
       
   151 	TEventType iEventType;
       
   152 	/** The error code (where relevant) or the index of the contact item added to/removed 
       
   153 	from the underlying view. */
       
   154 	TInt iInt; 
       
   155 	/** The ID of the contact item that has been added or removed or the group ID, where 
       
   156 	relevant. */
       
   157 	TContactItemId iContactId;//ContactId that has been added / removed if relevant.
       
   158 	};
       
   159 
       
   160 
       
   161 struct TContactIdWithMapping
       
   162 /** A struct used internally by filtered and group views to pair a contact item 
       
   163 ID and its index into the underlying view. 
       
   164 @publishedAll
       
   165 @released
       
   166 */
       
   167 	{
       
   168 	/** The contact item's ID. */
       
   169 	TContactItemId iId;
       
   170 	/** The index of the item into the view's underlying view. */
       
   171 	TInt iMapping;
       
   172 	};
       
   173 
       
   174 
       
   175 class MContactViewObserver
       
   176 /** The interface for a contact view observer.
       
   177 
       
   178 Objects that need to observe a contact view should implement this interface. 
       
   179 The view observer should be passed to the observed view's OpenL() or Open() 
       
   180 function. This adds the observer to the view's observer array: a view can 
       
   181 have more than one observer. The observers receive notifications when the 
       
   182 observed view becomes ready for use and when changes occur in it.
       
   183 
       
   184 Many contact view classes implement this interface to observe an underlying 
       
   185 view. They in turn send notification to any objects observing them.
       
   186 
       
   187 @see CContactViewBase::NotifyObservers()
       
   188 @see CContactViewBase::NotifyObserverAsync() 
       
   189 @publishedAll
       
   190 @released
       
   191 */
       
   192 	{
       
   193 public:
       
   194 	/** Handles an event in an observed contact view.
       
   195 	
       
   196 	@param aView The contact view causing the notification.
       
   197 	@param aEvent The event. */
       
   198 	virtual void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent)=0;
       
   199 	};
       
   200 
       
   201 
       
   202 class RContactViewSortOrder
       
   203 /** Specifies the sort order for a contact view.
       
   204 
       
   205 It is implemented as an array of TFieldType UIDs, which define the fields 
       
   206 whose contents are used to sort on, and their order.
       
   207 
       
   208 The sort order for all concrete contact view classes can be retrieved using 
       
   209 their implementation of CContactViewBase::SortOrderL(). The sort order is 
       
   210 set during construction of local and remote views. 
       
   211 @publishedAll
       
   212 @released
       
   213 */
       
   214 	{
       
   215 public:
       
   216 	IMPORT_C RContactViewSortOrder();
       
   217 	IMPORT_C void Close();
       
   218 	IMPORT_C void CopyL(const RContactViewSortOrder& aSortOrder);
       
   219 	IMPORT_C void InternalizeL(RReadStream& aStream);
       
   220 	IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
       
   221 	IMPORT_C TInt ExternalizedSize() const;
       
   222 	IMPORT_C TBool operator==(const RContactViewSortOrder& aSortOrder) const;
       
   223 	inline void AppendL(TFieldType aField);
       
   224 	inline TFieldType operator[](TInt aIndex) const;
       
   225 	inline TInt Count() const; 
       
   226 private:
       
   227 	RArray<TFieldType> iFields;
       
   228 	TInt iSpare;
       
   229 	TInt32 iSpare2;
       
   230 	TInt32 iSpare3;
       
   231 	};
       
   232 
       
   233 
       
   234 /**
       
   235 Wrapper around RArray, to container TTextFieldMinimal buffers.
       
   236 
       
   237 Features: minimum size 1, easy resize of array, persistent last counted total.
       
   238 
       
   239 @internalComponent
       
   240 @released
       
   241 */
       
   242 class RFieldBufferArray : public RArray<CContactDatabase::TTextFieldMinimal>
       
   243     {
       
   244 public:
       
   245 	explicit RFieldBufferArray();
       
   246 
       
   247 	void ResizeL(TInt aNewSize);
       
   248 	void ZeroAll();
       
   249 	TInt NewTotal();
       
   250 	TInt LastTotal() const;
       
   251 
       
   252 private:
       
   253 	TInt iTotalLength;
       
   254     };
       
   255 
       
   256 
       
   257 
       
   258 class CViewContact : public CBase
       
   259 /** The representation of a contact item used in contact views.
       
   260 
       
   261 It stores the contact item ID and other information. This includes a buffer 
       
   262 holding the contents of all the item's fields, an array of indexes into the 
       
   263 buffer indicating the start position of each field and a hint bit field (a 
       
   264 combination of CContactDatabase::TContactViewFilter values) which is used 
       
   265 in filtered views.
       
   266 
       
   267 The fields are defined by the view's sort order (RContactViewSortOrder). 
       
   268 @publishedAll
       
   269 @released
       
   270 */
       
   271 	{
       
   272 public:
       
   273 	/** Defines whether the contact view item is a contact group. */
       
   274 	enum TViewContactType
       
   275 		{
       
   276 		/** The contact view item is not a contact group. */
       
   277 		EContactItem,
       
   278 		/** The contact view item is a contact group (CContactGroup). */
       
   279 		EGroup
       
   280 		};
       
   281 	IMPORT_C CViewContact(TContactItemId aId);
       
   282 	IMPORT_C static CViewContact* NewL(const CViewContact& aContact);
       
   283 	IMPORT_C static CViewContact* NewLC(TContactItemId aId);
       
   284 	IMPORT_C static CViewContact* NewL(TContactItemId aId, TInt aLength);
       
   285 	static CViewContact* NewLC(RReadStream& aStream);
       
   286 	
       
   287 	IMPORT_C ~CViewContact();
       
   288 	IMPORT_C void InternalizeL(RReadStream& aStream);
       
   289 	IMPORT_C void ExternalizeL(RWriteStream& aStream) const;
       
   290 	IMPORT_C TInt ExternalizedSize() const;
       
   291 	IMPORT_C TInt FieldCount() const;
       
   292 	IMPORT_C TPtrC Field(TInt aPosition) const;
       
   293 	IMPORT_C TBool ContactMatchesFilter(TInt aFilter) const;
       
   294 	IMPORT_C void AddFieldL(const TDesC& aField);
       
   295 	IMPORT_C TBool IsSortable() const;
       
   296 	IMPORT_C void SetFirstFieldForBlankContactL(const TDesC& aFirstField);
       
   297 	IMPORT_C void Reset();
       
   298 	IMPORT_C TInt ContactHint() const;
       
   299 	IMPORT_C void SetContactHint(TInt aHint);
       
   300 	IMPORT_C TUid ContactTypeUid() const;
       
   301 	IMPORT_C void SetContactTypeUid(TUid aUid);
       
   302 
       
   303 	inline TContactItemId Id() const;
       
   304 	inline TViewContactType ContactType() const;
       
   305 public:
       
   306 	inline void SetId(TContactItemId aId);
       
   307 	inline void SetContactType(CViewContact::TViewContactType aContactType);
       
   308 	static TBool HintFieldMatchesFilter(TInt aHintField, TInt aFilter);
       
   309 	TPtrC FindFirstPopulatedField(TInt aOffset, TInt& aFoundPosition) const;
       
   310 	
       
   311     IMPORT_C void  ChangeToLightweightObject();
       
   312     TBool IsLightweightObject() const;	
       
   313     void  CopyL(const CViewContact& aContact);
       
   314 
       
   315 private: 
       
   316 	void ConstructL(TInt aLength = 0);
       
   317 	void ConstructL(const CViewContact& aContact);
       
   318 	friend class CContactViewBase;
       
   319 private:
       
   320 	TContactItemId iId;
       
   321 	TViewContactType iContactType;
       
   322 	CViewContactExtension* iExtension;
       
   323 	RArray<TInt> iTextIndexes;
       
   324 	};
       
   325 
       
   326 
       
   327 /*
       
   328  * A view can be named or un-named. An un-named view has a fixed sort order - the 
       
   329  * only way to change this is by closing the object and creating a new one with a 
       
   330  * different order. Named views may have their sort order changed. When this is 
       
   331  * done, first all observers will be informed that the view is 'unavailable'. This
       
   332  * notification will be followed by 'sort order changed' and 'ready'. Only once 
       
   333  * the 'ready' notification has been received may the view be used again.
       
   334  */
       
   335 class CContactViewBase : public CBase
       
   336 /** The abstract base class for all contact view classes.
       
   337 
       
   338 All contact views operate asynchronously, so users of the view must observe 
       
   339 it, by implementing the MContactViewObserver interface. Immediately after 
       
   340 construction, views are not in a usable state (the underlying data may be 
       
   341 being sorted, for instance). Only after the user has received a TContactViewEvent::EReady 
       
   342 event may the view be used.
       
   343 
       
   344 View observers are also notified when changes occur, for instance when the 
       
   345 view's state changes (see TState), when an error occurs, or when an item is 
       
   346 added or removed. 
       
   347 @publishedAll
       
   348 @released
       
   349 */
       
   350 	{
       
   351 public:
       
   352 	class CContactViewBaseExtension : public CBase
       
   353 	/** An extension class that holds member data added in v7.0s.
       
   354 
       
   355 	It was created for binary compatibility purposes. 
       
   356 	@internalComponent
       
   357 	@released */
       
   358 		{
       
   359 		public:
       
   360 			static CContactViewBaseExtension* NewL();
       
   361 			~CContactViewBaseExtension();
       
   362 
       
   363 		private:
       
   364 			CContactViewBaseExtension();
       
   365 			void ConstructL();
       
   366 
       
   367 		public:
       
   368 			/** A standard error code that is passed to view observers by NotifyObservers() 
       
   369 			(unless its value is KErrNone). */
       
   370 			TInt iError;
       
   371 			/** The UID of the view's find configuration plug-in.
       
   372 	
       
   373 			On construction, this is initialised to KNullUid.
       
   374 	
       
   375 			The plug-in is loaded when ContactsMatchingCriteriaL(), ContactsMatchingPrefixL() 
       
   376 			or MatchesCriteriaL() is called. */
       
   377 			TUid iFindPluginUid;
       
   378 			/** The UID of the view's sort plug-in. */
       
   379 			TUid iSortPluginUid;
       
   380 		private:
       
   381 			CContactViewFindConfigInterface*	iFindPluginImpl;
       
   382 			CViewContactSortPlugin*				iSortPluginImpl;
       
   383 			TCollationMethod					iCollationMethod;
       
   384 			friend class CContactViewBase;
       
   385 		};
       
   386 	class TVirtualFunction1Params
       
   387 	/** Holds the two parameters passed to the helper method GetContactIdsL() from 
       
   388 	the reserved function CContactViewBase_Reserved_1(). It has an inline constructor 
       
   389 	to initialise the data members. 
       
   390 	@publishedAll
       
   391 	@released */
       
   392 		{
       
   393 		public:
       
   394 		   /** Inline constructor to initialize member data
       
   395 			  @param aIndexes Pointer to an array of indexes in a view
       
   396 	          @param aIdArray Pointer to array of contact IDs  */
       
   397 			inline TVirtualFunction1Params(const CArrayFix<TInt>* aIndexes, CContactIdArray* aIdArray) :iIndexes(aIndexes), iIdArray(aIdArray){};
       
   398 			/** Pointer to an array of indexes in a view  */
       
   399 			const CArrayFix<TInt>* iIndexes;
       
   400 			/** Pointer to array of contact IDs  */
       
   401 			CContactIdArray* iIdArray;
       
   402 		};
       
   403 	class TVirtualFunction2Params
       
   404 	/** Holds the two parameters passed to the method GetContactsMatchingFilterL() 
       
   405 	from the reserved function CContactViewBase_Reserved_1(). It has an inline 
       
   406 	constructor to initialise the data members.
       
   407 	*/
       
   408 		{
       
   409 		public:
       
   410 		   /** Inline constructor to initialize member data.
       
   411 			  @param aFilter Filter for the contacts
       
   412 	          @param aMatchingContacts Contacts matching a particular criterion  */
       
   413 			inline TVirtualFunction2Params(TInt aFilter, RArray<TContactIdWithMapping>& aMatchingContacts) : iFilter(aFilter), iMatchingContacts(aMatchingContacts){};
       
   414 		public:
       
   415 			/** Filter for the contacts. */
       
   416 			TInt iFilter;
       
   417 			/** List of contacts matching the criteria. */
       
   418 			RArray<TContactIdWithMapping>& iMatchingContacts;
       
   419 		};
       
   420 
       
   421 	/** Search type.
       
   422 
       
   423 	This controls whether a search term can occur anywhere in a contact item field, 
       
   424 	or just at the beginning of the field. */
       
   425 	enum TSearchType
       
   426 		{
       
   427 		/** The search uses full wildcard matching so that the search string can occur anywhere 
       
   428 		in the item's fields. */
       
   429 		EFullSearch,
       
   430 		/** The search uses partial wildcard matching so that the search string can only 
       
   431 		occur at the beginning of the item's fields. */
       
   432 		EPrefixSearch
       
   433 		};
       
   434 	/** Identifies the functions that have been added to CContactViewBase, or that 
       
   435 	may be added in the future. This identifier is passed to the reserved virtual 
       
   436 	function CContactViewBase_Reserved_1() and enables the addition of new virtual 
       
   437 	methods without breaking binary compatibility. */
       
   438 	enum TFunction
       
   439 		{
       
   440 		/** Identifies the function CContactViewBase::GetContactIdsL(). */
       
   441 		ECContactViewBaseVirtualFunction1,
       
   442 		/** Identifies the function CContactViewBase::GetContactsMatchingFilterL(). */
       
   443 		ECContactViewBaseVirtualFunction2,
       
   444 		// communication with Sort Plug-in
       
   445 		/** Identifies the function CContactViewBase::InsertContactInView(). */
       
   446 		ECContactViewBaseVirtualFunction3,
       
   447 		};
       
   448 protected:
       
   449 	/** Defines the contact view states. */
       
   450 	enum TState
       
   451 		{
       
   452 		/** The view is initialising.
       
   453 	
       
   454 		This is the view's state immediately after construction or after a significant change 
       
   455 		(e.g CurrentDatabaseChanged or UnknownChanges),	indicating that it can't be used yet. */
       
   456 		EInitializing,
       
   457 		/** The view is ready to be used. */
       
   458 		EReady,
       
   459 		/** The view is not ready to be used, for instance immediately after the sort order 
       
   460 		has changed, or after an error has occurred. */
       
   461 		ENotReady
       
   462 		};
       
   463 	class TVirtualFunction3Params
       
   464 		/** Holds the two parameters passed to the method InsertContactInView() from the 
       
   465 		reserved function CContactViewBase_Reserved_1(). It has an inline 
       
   466 		constructor to initialise the data members.
       
   467 		*/
       
   468 		{
       
   469 		public:
       
   470 			inline TVirtualFunction3Params(RPointerArray<CViewContact>& aContacts, const CViewContact* aNewContact) :iContacts(aContacts), iNewContact(aNewContact){};
       
   471 			RPointerArray<CViewContact>&	iContacts;
       
   472 			const CViewContact*				iNewContact;
       
   473 		};
       
   474 public:
       
   475 	IMPORT_C void OpenL(MContactViewObserver& aObserver);
       
   476 	IMPORT_C TInt Open(MContactViewObserver& aObserver);
       
   477 	IMPORT_C TBool Close(const MContactViewObserver& aObserver);
       
   478 	/** Returns the contact item ID at the specified index into the view.
       
   479 	
       
   480 	@capability ReadUserData
       
   481 	@param aIndex Index of the contact item ID into the view.
       
   482 	@return The contact item ID. */
       
   483 	virtual TContactItemId AtL(TInt aIndex) const=0; 
       
   484 	/** Returns the contact item at the specified index into the view.
       
   485 	
       
   486 	@capability ReadUserData
       
   487 	@param aIndex Index of the contact item into the view.
       
   488 	@return The contact item. */
       
   489 	virtual const CViewContact& ContactAtL(TInt aIndex) const =0;
       
   490 	/** Returns the number of contact items in the view.
       
   491 		
       
   492 	@capability ReadUserData
       
   493 	@return The number of contact items in the view. */
       
   494 	virtual TInt CountL() const=0;
       
   495 	/** Returns the index into the view of the specified contact item.
       
   496 	
       
   497 	@capability ReadUserData
       
   498 	@param aId The contact item ID to search for.
       
   499 	@return The index into the view of the contact item ID, or KErrNotFound if 
       
   500 	no matching ID can be found. */
       
   501 	virtual TInt FindL(TContactItemId aId) const=0;
       
   502 	/** Returns a descriptor containing the contents of all fields for an item in the view.
       
   503 	
       
   504 	The field separator is used to separate the contents of each field. It is 
       
   505 	not appended to the last field.
       
   506 	
       
   507 	@capability ReadUserData
       
   508 	@param aIndex The index of the contact item into the view.
       
   509 	@param aSeparator The string to use to separate the fields.
       
   510 	@return Pointer to the contact item descriptor. */
       
   511 	virtual HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const=0;
       
   512 	IMPORT_C virtual void ContactsMatchingCriteriaL(const MDesCArray& aFindWords,RPointerArray<CViewContact>& aMatchedContacts);
       
   513 	/** Gets the view preferences.
       
   514 	
       
   515 	@capability ReadUserData
       
   516 	@return The view preferences. */
       
   517 	virtual TContactViewPreferences ContactViewPreferences()=0;
       
   518 	/** Gets the view's sort order.
       
   519 	
       
   520 	@capability ReadUserData
       
   521 	@return The sort order. */
       
   522 	virtual const RContactViewSortOrder& SortOrderL() const = 0;
       
   523 	IMPORT_C virtual void ContactsMatchingPrefixL(const MDesCArray& aFindWords, RPointerArray<CViewContact>& aMatchedContacts);
       
   524 	//This is a reserved virtual exported function that is used for BC proofing against present 
       
   525 	//and future additions of new exported virtual functions. Existing exported virtual methods 
       
   526 	//that broke BC are now non-virtual exported helper functions called from this method. 
       
   527 	//All derived classes of CContactViewBase that are public must mandatorily 
       
   528 	//implement this reserved exported virtual method.
       
   529 	IMPORT_C virtual TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams);
       
   530 	//New exported method to set the ECOM plug-in to be used
       
   531 	IMPORT_C void SetViewFindConfigPlugin(TUid aUid);
       
   532 	IMPORT_C TUid GetViewFindConfigPlugin();
       
   533 	IMPORT_C virtual void GetContactIdsL(const CArrayFix<TInt>& aIndexes, CContactIdArray& aContactIds);
       
   534 	IMPORT_C TInt Error() const; 
       
   535 	IMPORT_C TUid GetViewSortPluginImplUid() const;
       
   536 
       
   537 protected:
       
   538 	IMPORT_C ~CContactViewBase();
       
   539 	IMPORT_C void ConstructL();
       
   540 
       
   541 	IMPORT_C CContactViewBase(const CContactDatabase& aDb);
       
   542 	IMPORT_C void NotifyObservers(const TContactViewEvent& aEvent);
       
   543 	IMPORT_C TInt NotifyObserverAsync(MContactViewObserver& aObserver,const TContactViewEvent& aEvent);
       
   544 	IMPORT_C static TBool IdsMatch(const CViewContact& aFirst,const CViewContact& aSecond);
       
   545 	IMPORT_C HBufC* FieldsWithSeparatorLC(const RPointerArray<CViewContact>& aContacts,TInt aIndex,const TDesC& aSeparator) const;
       
   546 	//Find helper functions
       
   547 	IMPORT_C virtual TBool MatchesCriteriaL(const CViewContact& aContact,const MDesCArray& aFindWords);
       
   548 	IMPORT_C static TBool MatchesCriteriaL(const CViewContact& aContact,const MDesCArray& aFindWords, TSearchType aSearchType);
       
   549 	IMPORT_C static TBool MatchesCriteriaL(const CViewContact& aContact,const MDesCArray& aFindWords, TSearchType aSearchType,CContactViewBase::CContactViewBaseExtension* aExtension);
       
   550 	IMPORT_C static TBool IdsEqual(const TContactIdWithMapping& aFirst,const TContactIdWithMapping& aSecond);
       
   551 	IMPORT_C static TBool IndexesEqual(const TContactIdWithMapping& aFirst,const TContactIdWithMapping& aSecond);
       
   552 	IMPORT_C static TInt CompareFieldsL(const CViewContact& aFirst, const CViewContact& aSecond);
       
   553 	// View Sort Plugin changes
       
   554 	IMPORT_C static TInt CompareContactIds(const CViewContact& aFirst, const CViewContact& aSecond);
       
   555 	IMPORT_C static TBool ContactIsSortable(const CViewContact& aContact);
       
   556 	IMPORT_C TInt CompareContactsAndIdsL(const CViewContact& aFirst, const CViewContact& aSecond) const;
       
   557 protected:	// these are needed by CContactLocalView only
       
   558 	TInt InsertContactInView(RPointerArray<CViewContact>& aContacts, const CViewContact* aNewContact, TBool aSortByIdOnly, TInt* aIndex) const;
       
   559 	TBool IsContactSortable(const CViewContact& aContact, TContactViewPreferences& aViewPreferences) const;
       
   560 	CViewContactSortPlugin* SortPluginImpl() const;
       
   561 	TUid FindSortPluginImplL (const TDesC8& aSortPluginName,TBool aWildCard=EFalse) const;
       
   562 	TUid FindDefaultViewSortPluginImplL () const;
       
   563 	void LoadViewSortPluginL (TUid aSortPluginUid,TContactViewPreferences& aViewPreferences);
       
   564 
       
   565 private:
       
   566 	static TInt AsyncNotifyCallBack(TAny* aSelf);
       
   567 	static CDesCArrayFlat* CreateFindWordArrayLC(const MDesCArray& aFindWords, TSearchType aSearchType);
       
   568 	static TBool ContactMatchesCriteriaL(const CViewContact& aContact,const MDesCArray& aFindWords,CContactViewBase::CContactViewBaseExtension* aExtension);
       
   569 	void MatchContactsL(const MDesCArray& aFindWords,RPointerArray<CViewContact>& aMatchedContacts, TSearchType aSearchType);
       
   570 	static TInt CompareFieldsWithCollationLevel(const CViewContact& aFirst, const CViewContact& aSecond, 
       
   571 												TInt aCollationLevel, TCollationMethod* aCollateMethod);
       
   572 	TInt GetErrorValueFromExtensionClass();	
       
   573 	void GetContactsMatchingFilterL(TInt aFilter, RArray<TContactIdWithMapping>& aMatchingContacts);	
       
   574 	TInt TextCompareFieldsL(const CViewContact& aFirst, const CViewContact& aSecond) const;
       
   575 
       
   576 
       
   577 private:
       
   578 	struct TObserverAndEvent
       
   579 		{
       
   580 		TContactViewEvent iAsyncEvent;
       
   581 		MContactViewObserver* iObserverToNotify;
       
   582 		};
       
   583 	
       
   584 protected:
       
   585 	// Reference to CContactDatabase class.
       
   586 	const CContactDatabase& iDb;
       
   587     // Different Contacts view states.
       
   588 	TState iState;
       
   589 	// The pointer to the ContactViewBase BC extension class.
       
   590 	CContactViewBaseExtension* iExtension; 
       
   591 private:
       
   592 	RPointerArray<MContactViewObserver> iObserverArray;
       
   593 	CIdle* iAsyncNotifier;
       
   594 	RArray<TObserverAndEvent> iOutstandingNotifications;
       
   595 	};
       
   596 
       
   597 	
       
   598 class MLplPersistenceLayerFactory;
       
   599 class CViewContactManager;
       
   600 
       
   601 class CContactLocalView : public CContactViewBase, public MContactDbObserver
       
   602 /** An instantiable base class for contact views.
       
   603 
       
   604 The data associated with a local view is allocated within the client's memory 
       
   605 space; CContactRemoteView should be used in preference if the view is likely 
       
   606 to be shared between multiple clients. It is kept up to date by receiving 
       
   607 change events from the underlying CContactDatabase object which it observes. 
       
   608 The view preferences and sort order are specified on construction. 
       
   609 @publishedAll
       
   610 @released
       
   611 */
       
   612 	{
       
   613 public:
       
   614 	IMPORT_C static CContactLocalView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes);
       
   615 	IMPORT_C static CContactLocalView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes,
       
   616 		const TDesC8& aSortPluginName);
       
   617 	IMPORT_C static CContactLocalView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes,
       
   618 		MLplPersistenceLayerFactory* aFactory,const TDesC8& aSortPluginName);
       
   619 
       
   620 	IMPORT_C const RContactViewSortOrder& SortOrder() const;
       
   621 public: // From CContactViewBase.
       
   622 	TContactItemId AtL(TInt aIndex) const;
       
   623 	TInt CountL() const;
       
   624 	TInt FindL(TContactItemId aId) const;
       
   625 	HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const;
       
   626 	const CViewContact&  ContactAtL(TInt aIndex) const;
       
   627 	TContactViewPreferences ContactViewPreferences();
       
   628 	const RContactViewSortOrder& SortOrderL() const;
       
   629 	void NotifySortError(TInt aError);
       
   630 	//All derived classes of CContactViewBase that are public should mandatorily 
       
   631 	//implement this reserved exported virtual method.
       
   632 	IMPORT_C TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams);
       
   633 protected:
       
   634 	IMPORT_C ~CContactLocalView();
       
   635 	IMPORT_C CContactLocalView(const CContactDatabase& aDb,TContactViewPreferences aContactTypes);
       
   636 	CContactLocalView(const CContactDatabase& aDb,TContactViewPreferences aContactTypes,MLplPersistenceLayerFactory* aIterFactory);
       
   637 	IMPORT_C void ConstructL(MContactViewObserver& aObserver,const RContactViewSortOrder& aSortOrder);
       
   638 	void ConstructL(MContactViewObserver& aObserver,const RContactViewSortOrder& aSortOrder, const TBool aUseNamedPlugin, const TDesC8& aSortPluginName);
       
   639 	IMPORT_C virtual void SortL(const RContactViewSortOrder& aSortOrder);
       
   640 	IMPORT_C virtual TInt InsertL(TContactItemId aId);
       
   641 	IMPORT_C virtual TInt RemoveL(TContactItemId aId);
       
   642 protected:
       
   643 	void SetState(TState aState);
       
   644 private: // From MContactDbObserver.
       
   645 	virtual void HandleDatabaseEventL(TContactDbObserverEvent aEvent);
       
   646 	
       
   647 private:
       
   648 	void SortComplete(TInt aSortErr);	
       
   649 	void SetSortOrderL(const RContactViewSortOrder& aSortOrder);
       
   650 	void SortL();
       
   651 	void SafeResort();
       
   652 	friend class CViewContactManager;
       
   653 
       
   654 private: // Metheds for event handling
       
   655 	void HandleOutstandingEvents();
       
   656 	void HandleOutstandingEventL();
       
   657 	friend class CIdleContactSorter;
       
   658 protected:
       
   659 	/** The sort order. 
       
   660 	This is set during construction or when SortL() is called. */
       
   661 	RContactViewSortOrder iSortOrder ;
       
   662 private:
       
   663 	IMPORT_C virtual void CContactLocalView_Reserved_1();
       
   664 	IMPORT_C virtual void CContactLocalView_Reserved_2();
       
   665 
       
   666 private:
       
   667 	MLplPersistenceLayerFactory*	iFactory;
       
   668 	RPointerArray<CViewContact>	iContacts;
       
   669 	RPointerArray<CViewContact>	iUnSortedContacts;
       
   670 	RArray<TContactDbObserverEvent> iOutstandingEvents;
       
   671 	CIdleContactSorter* iAsyncSorter;
       
   672 	CViewContactManager* iViewCntMgr;
       
   673 	CContactTextDef*	iTextDef;
       
   674 	TContactViewPreferences iViewPreferences;
       
   675 	TBool iSpare0;
       
   676 	TInt iSpare;
       
   677 	};
       
   678 
       
   679 class RContactRemoteView : public RSubSessionBase
       
   680 /** This class is used internally by remote contact views as the handle to the 
       
   681 server side view object.
       
   682 
       
   683 @see CContactRemoteViewBase 
       
   684 @publishedAll
       
   685 @released
       
   686 */
       
   687 	{
       
   688 public:
       
   689 	void OpenL(const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes,const TUid& aSortPluginImplUid,const TDesC8& aSortPluginName);
       
   690 	void OpenL(const CContactDatabase& aDb,const TDesC& aName,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes,const TUid& aSortPluginImplUid,const TDesC8& aSortPluginName);
       
   691 	void Close();
       
   692 public: // From CContactViewBase
       
   693 	TContactItemId AtL(TInt aIndex) const;
       
   694 	CViewContact*  ContactAtL(TInt aIndex);
       
   695 	TInt CountL() const;
       
   696 	TInt FindL(TContactItemId aId) const;
       
   697 	HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const;
       
   698 	const RContactViewSortOrder& SortOrderL();
       
   699 public:	
       
   700 	void ContactsMatchingCriteriaL(const MDesCArray& aFindWords,RPointerArray<CViewContact>& aMatchedContacts, TBool aPrefixSearch,TUid aUid);
       
   701 	void ChangeSortOrderL(const RContactViewSortOrder& aSortOrder);
       
   702 	void GetSortOrderL(RContactViewSortOrder& aSortOrder);
       
   703 	TContactViewPreferences ContactViewPreferencesL();
       
   704 
       
   705 	void RequestViewEvent(TPckgBuf<TContactViewEvent>& aEvent,TRequestStatus& aStatus);
       
   706 	TInt CancelRequestViewEvent();
       
   707 	void GetContactIdsL(const CArrayFix<TInt>& aIndexes, CContactIdArray& aContactIds);
       
   708 	void GetContactsMatchingFilterL(TInt aFilter, RArray<TContactIdWithMapping>& aMatchingContacts);
       
   709 	TUid GetViewSortPluginImplUidL() const;
       
   710 private:
       
   711 	HBufC8* PackageSortOrderLC(const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes) const;
       
   712 	HBufC8* PackageSortOrderAndPluginDetailsLC(const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes,const TUid& aSortPluginImplUid,const TDesC8& aSortPluginName) const;
       
   713 private:
       
   714 	CViewContact* iContact;
       
   715 	RContactViewSortOrder iSortOrder ;
       
   716 	};
       
   717 
       
   718 
       
   719 NONSHARABLE_CLASS(CContactRemoteViewBase) : public CContactViewBase
       
   720 /** Base class for all remote contact view classes.
       
   721 
       
   722 It implements all the pure virtual functions in CContactViewBase and additionally 
       
   723 it handles remote view notifications. The data associated with remote views 
       
   724 is allocated within the memory space of the contacts server. This means that 
       
   725 multiple clients can share the same server side view object, thereby reducing 
       
   726 the overhead associated with initial sorting of the view data and keeping 
       
   727 it in sync with the underlying data. Remote views should therefore be used 
       
   728 when the same view is likely to be needed by more than one client. 
       
   729 @internalComponent
       
   730 @released
       
   731 */
       
   732 	{
       
   733 public: // From CContactViewBase.
       
   734 	TContactItemId AtL(TInt aIndex) const;
       
   735 	TInt CountL() const;
       
   736 	TInt FindL(TContactItemId aId) const;
       
   737 	HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const;
       
   738 	const CViewContact&  ContactAtL(TInt aIndex) const;
       
   739 	TContactViewPreferences ContactViewPreferences();
       
   740 	void ContactsMatchingCriteriaL(const MDesCArray& aFindWords,RPointerArray<CViewContact>& aMatchedContacts);
       
   741 	void ContactsMatchingPrefixL(const MDesCArray& aFindWords, RPointerArray<CViewContact>& aMatchedContacts);
       
   742 	const RContactViewSortOrder& SortOrderL() const;
       
   743 	//All derived classes of CContactViewBase that are public should mandatorily 
       
   744 	//implement this reserved exported virtual method.
       
   745 	TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams);
       
   746 	//This function was virtual in a previous release, if you still need to use it
       
   747 	//in a virtual way then you can call it via the Reserved function.
       
   748 	//The functionality of this function ,however,remains the same.
       
   749 	void GetContactIdsL(const CArrayFix<TInt>& aIndexes, CContactIdArray& aContactIds);
       
   750 	void GetContactsMatchingFilterL(TInt aFilter, RArray<TContactIdWithMapping>& aMatchingContacts);
       
   751 protected:
       
   752 	~CContactRemoteViewBase();
       
   753 	CContactRemoteViewBase(const CContactDatabase& aDb);
       
   754 	void ConstructL(MContactViewObserver& aObserver);
       
   755 private:
       
   756 	static TInt NotifierCallBack(TAny* aSelf);
       
   757 	void HandleContactViewEvent(const TContactViewEvent& aEvent);
       
   758 protected:
       
   759 	/** A handle to the server side view. */
       
   760 	RContactRemoteView iView;
       
   761 private:
       
   762 	CContactRemoteViewNotifier* iNotifier;
       
   763 	/** Cached copy of the count of the local view in the contacts server. 
       
   764 		If this is KCachedItemCountInvalid then next time CountL is called
       
   765 		the current count is retrieved from the contacts server. */
       
   766 	mutable TInt iCount;
       
   767 	};
       
   768 
       
   769 
       
   770 class CContactRemoteView : public CContactRemoteViewBase
       
   771 /** An instantiable remote contact view class.
       
   772 
       
   773 Remote views are associated with a CContactLocalView object held in the contacts 
       
   774 server. They provide an efficient means for multiple clients to share the 
       
   775 same underlying view.
       
   776 
       
   777 The view preferences and sort order are specified on construction. 
       
   778 @publishedAll
       
   779 @released
       
   780 */
       
   781 	{
       
   782 public:
       
   783 	IMPORT_C static CContactRemoteView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes);
       
   784 	IMPORT_C static CContactRemoteView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes,
       
   785 		const TDesC8& aSortPluginName);
       
   786 	IMPORT_C void GetSortOrderL(RContactViewSortOrder& aSortOrder);
       
   787 	//All derived classes of CContactViewBase that are public should mandatorily 
       
   788 	//implement this reserved exported virtual method.
       
   789 	TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams);
       
   790 protected:
       
   791 	~CContactRemoteView();
       
   792 	CContactRemoteView(const CContactDatabase& aDb);
       
   793 private:
       
   794 	void ConstructL(MContactViewObserver& aObserver,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes);
       
   795 	void ConstructL(MContactViewObserver& aObserver,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypesconst, const TDesC8& aSortPluginName);
       
   796 	};
       
   797 
       
   798 
       
   799 class CContactNamedRemoteView : public CContactRemoteView
       
   800 /** A named remote contact view.
       
   801 
       
   802 This class enables multiple clients to share a named server side view. It 
       
   803 also provides a function to change the sort order. If the sort order is changed, 
       
   804 a notification is sent to all users of the named view. 
       
   805 @publishedAll
       
   806 @released
       
   807 */
       
   808 	{
       
   809 public:
       
   810 	IMPORT_C static CContactNamedRemoteView* NewL(MContactViewObserver& aObserver,const TDesC& aName,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes);
       
   811 	IMPORT_C static CContactNamedRemoteView* NewL(MContactViewObserver& aObserver,const TDesC& aName,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes,
       
   812 		const TDesC8& aSortPluginName);
       
   813 	IMPORT_C void ChangeSortOrderL(const RContactViewSortOrder& aSortOrder);
       
   814 	//All derived classes of CContactViewBase that are public should mandatorily 
       
   815 	//implement this reserved exported virtual method.
       
   816 	TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams);
       
   817 private:
       
   818 	~CContactNamedRemoteView();
       
   819 	CContactNamedRemoteView(const CContactDatabase& aDb);
       
   820 	void ConstructL(MContactViewObserver& aObserver,const TDesC& aName,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes);
       
   821 	void ConstructL(MContactViewObserver& aObserver,const TDesC& aName,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes, const TDesC8& aSortPluginName);
       
   822 	};
       
   823 
       
   824 inline TContactViewEvent::TContactViewEvent() 
       
   825 /** Empty default constructor. */
       
   826 	{};
       
   827 
       
   828 inline TContactViewEvent::TContactViewEvent(TEventType aEventType,TInt aInt,TContactItemId aContactId) : iEventType(aEventType),iInt(aInt),iContactId(aContactId) 
       
   829 /** Constructor with an event type and an optional error code and contact item ID.
       
   830 
       
   831 @param aEventType The event type.
       
   832 @param aInt Optional standard error code.
       
   833 @param aContactId Optional contact item ID. */
       
   834 	{};
       
   835 
       
   836 inline void RContactViewSortOrder::AppendL(TFieldType aField) 
       
   837 /** Appends a field type to the sort order object.
       
   838 
       
   839 @param aField The field type to append. */
       
   840 	{ User::LeaveIfError(iFields.Append(aField)); }
       
   841 
       
   842 inline TFieldType RContactViewSortOrder::operator[](TInt aIndex) const 
       
   843 /** Gets an indexed field type.
       
   844 
       
   845 @param aIndex Index of the required field type. A panic occurs if this is 
       
   846 invalid.
       
   847 @return The field type located at the indexed position in the array. */
       
   848 	{ return iFields[aIndex]; }
       
   849 
       
   850 inline TInt RContactViewSortOrder::Count() const 
       
   851 /** Gets the number of field types in the sort order array.
       
   852 
       
   853 @return The number of field types in the array. */
       
   854 	{ return iFields.Count(); }
       
   855 
       
   856 inline TContactItemId CViewContact::Id() const 
       
   857 /** Gets the view item's ID.
       
   858 
       
   859 @return The view item's ID. */
       
   860 	{return iId;}
       
   861 
       
   862 inline CViewContact::TViewContactType CViewContact::ContactType() const 
       
   863 /** Gets the view item's type.
       
   864 
       
   865 @return The view item's type. */
       
   866 	{return iContactType;}
       
   867 
       
   868 inline void CViewContact::SetId(TContactItemId aId) 
       
   869 /** Sets the view item's ID.
       
   870 
       
   871 @param aId The contact item ID. */
       
   872 	{iId=aId;}
       
   873 
       
   874 inline void CViewContact::SetContactType(CViewContact::TViewContactType aContactType) 
       
   875 /** Sets the view item's type.
       
   876 
       
   877 @param aContactType The view item's type. */
       
   878 	{iContactType=aContactType;}
       
   879 #endif