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