williamr@2: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@2: // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: #ifndef __CNTVIEWBASE_H__ williamr@2: #define __CNTVIEWBASE_H__ williamr@2: williamr@2: // System includes williamr@2: #include williamr@2: #include williamr@2: williamr@2: #include williamr@2: williamr@2: // Classes referenced williamr@2: class CViewContactExtension; williamr@2: class CContactViewBase; williamr@2: class CContactRemoteViewNotifier; williamr@2: class CIdleContactSorter; williamr@2: class CContactViewFindConfigInterface; williamr@2: class CViewContactSortPlugin; williamr@2: class TSortPluginViewParams; williamr@2: williamr@2: /** View preferences for sorted contact views. williamr@2: williamr@2: This is used to specify the types of contact item that should be sorted and williamr@2: included in the view and the behaviour for items that cannot be sorted because williamr@2: they do not have content in any of the fields specified in the view's sort williamr@2: order. williamr@2: williamr@2: The default behaviour is to include contact cards only and to sort contact williamr@2: cards without content in any of the sort order fields using the first available williamr@2: field containing any text. williamr@2: williamr@2: The view preferences for all concrete contact view classes can be retrieved williamr@2: using their implementation of CContactViewBase::ContactViewPreferences(). williamr@2: The view preferences are set during construction of a CContactLocalView. williamr@2: williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: enum TContactViewPreferences williamr@2: { williamr@2: /** Only contact cards (of type KUidContactCard or KUidContactOwnCard) are included williamr@2: in the view. This is the default. */ williamr@2: EContactsOnly =0x00000000, williamr@2: /** Only contact groups (of type KUidContactGroup) are included in the view. */ williamr@2: EGroupsOnly =0x00000001, williamr@2: /** Contact groups and contact cards (of type KUidContactGroup, KUidContactCard williamr@2: or KUidContactOwnCard) are included in the view. */ williamr@2: EContactAndGroups =0x00000002, williamr@2: /** Excludes contact items from the view which don't have content in any of the williamr@2: fields specified in the sort order. */ williamr@2: EIgnoreUnSorted =0x00000004, williamr@2: /** Includes contacts in the view which don't have content in any of the fields williamr@2: specified in the sort order. These contacts are placed in an unsorted contact williamr@2: list which is located before the sorted list. */ williamr@2: EUnSortedAtBeginning =0x00000008, williamr@2: /** Includes contacts in the view which don't have content in any of the fields williamr@2: specified in the sort order. These contacts are placed in an unsorted contact williamr@2: list which is located after the sorted list. */ williamr@2: EUnSortedAtEnd =0x00000010, williamr@2: /** Fields containing a single white space only are treated as empty, and therefore williamr@2: unsortable. */ williamr@2: ESingleWhiteSpaceIsEmptyField =0x00000020, williamr@2: /** Only ICC entries (of type KUidContactICCEntry) are included in the view. */ williamr@2: EICCEntriesOnly =0x00000040, williamr@2: /** Only contact cards and ICC entries (of type KUidContactCard, KUidContactOwnCard williamr@2: or KUidContactICCEntry) are included in the view. */ williamr@2: EICCEntriesAndContacts =0x00000080 williamr@2: }; williamr@2: williamr@2: williamr@2: class TContactViewEvent williamr@2: /** Identifies a contact view event. williamr@2: williamr@2: Sent by contact views when notifying their observers of an event. williamr@2: williamr@2: @see MContactViewObserver::HandleContactViewEvent() williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: /** Identifies the event's type. */ williamr@2: enum TEventType williamr@2: { williamr@2: /** The observed view's state has changed from EReady to either ENotReady or EInitializing, williamr@2: so is not available for use. */ williamr@2: EUnavailable, williamr@2: /** The observed view's state has changed from ENotReady or EInitializing to EReady williamr@2: so is available for use. */ williamr@2: EReady, williamr@2: /** The observed view's sort order has changed, so observer views need to update williamr@2: themselves. */ williamr@2: ESortOrderChanged, williamr@2: /** An error occurred when sorting the observed view or when appending an observer williamr@2: to its observer array. williamr@2: williamr@2: The error code is provided in iInt. */ williamr@2: ESortError, williamr@2: /** An error occurred in the contacts server. williamr@2: williamr@2: The error code is provided in iInt. */ williamr@2: EServerError, williamr@2: /** An error occurred when setting the range for a CContactSubView. williamr@2: williamr@2: The error code is provided in iInt. */ williamr@2: EIndexingError, williamr@2: /** An item has been added to the observed view. williamr@2: williamr@2: The ID of the added item is provided in iContactId and the index into the williamr@2: observed view of the added item is provided in iInt. williamr@2: Exception from this are the first version of CContactFindView, CContactSubView and williamr@2: CContactGroupView classes. williamr@2: For these classes, iInt has KErrNone value */ williamr@2: williamr@2: EItemAdded, williamr@2: /** An item has been removed from the observed view. williamr@2: williamr@2: The ID of the removed item is provided in iContactId and the index into the williamr@2: observed view of the item is provided in iInt. williamr@2: Exception from this are the first version of CContactFindView and CContactSubView classes. williamr@2: For these classes, iInt has KErrNone value */ williamr@2: williamr@2: EItemRemoved, williamr@2: /** A change has occurred in a contact group, for instance a contact item has been williamr@2: moved into or out of the group. williamr@2: williamr@2: The ID of the group affected is provided in iContactId. */ williamr@2: EGroupChanged williamr@2: }; williamr@2: public: williamr@2: inline TContactViewEvent(); williamr@2: inline TContactViewEvent(TEventType aEventType,TInt aInt = KErrUnknown,TContactItemId aContactId = KErrUnknown); williamr@2: public: williamr@2: /** The type of event. */ williamr@2: TEventType iEventType; williamr@2: /** The error code (where relevant) or the index of the contact item added to/removed williamr@2: from the underlying view. */ williamr@2: TInt iInt; williamr@2: /** The ID of the contact item that has been added or removed or the group ID, where williamr@2: relevant. */ williamr@2: TContactItemId iContactId;//ContactId that has been added / removed if relevant. williamr@2: }; williamr@2: williamr@2: williamr@2: struct TContactIdWithMapping williamr@2: /** A struct used internally by filtered and group views to pair a contact item williamr@2: ID and its index into the underlying view. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: /** The contact item's ID. */ williamr@2: TContactItemId iId; williamr@2: /** The index of the item into the view's underlying view. */ williamr@2: TInt iMapping; williamr@2: }; williamr@2: williamr@2: williamr@2: class MContactViewObserver williamr@2: /** The interface for a contact view observer. williamr@2: williamr@2: Objects that need to observe a contact view should implement this interface. williamr@2: The view observer should be passed to the observed view's OpenL() or Open() williamr@2: function. This adds the observer to the view's observer array: a view can williamr@2: have more than one observer. The observers receive notifications when the williamr@2: observed view becomes ready for use and when changes occur in it. williamr@2: williamr@2: Many contact view classes implement this interface to observe an underlying williamr@2: view. They in turn send notification to any objects observing them. williamr@2: williamr@2: @see CContactViewBase::NotifyObservers() williamr@2: @see CContactViewBase::NotifyObserverAsync() williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: /** Handles an event in an observed contact view. williamr@2: williamr@2: @param aView The contact view causing the notification. williamr@2: @param aEvent The event. */ williamr@2: virtual void HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent)=0; williamr@2: }; williamr@2: williamr@2: williamr@2: class RContactViewSortOrder williamr@2: /** Specifies the sort order for a contact view. williamr@2: williamr@2: It is implemented as an array of TFieldType UIDs, which define the fields williamr@2: whose contents are used to sort on, and their order. williamr@2: williamr@2: The sort order for all concrete contact view classes can be retrieved using williamr@2: their implementation of CContactViewBase::SortOrderL(). The sort order is williamr@2: set during construction of local and remote views. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C RContactViewSortOrder(); williamr@2: IMPORT_C void Close(); williamr@2: IMPORT_C void CopyL(const RContactViewSortOrder& aSortOrder); williamr@2: IMPORT_C void InternalizeL(RReadStream& aStream); williamr@2: IMPORT_C void ExternalizeL(RWriteStream& aStream) const; williamr@2: IMPORT_C TInt ExternalizedSize() const; williamr@2: IMPORT_C TBool operator==(const RContactViewSortOrder& aSortOrder) const; williamr@2: inline void AppendL(TFieldType aField); williamr@2: inline TFieldType operator[](TInt aIndex) const; williamr@2: inline TInt Count() const; williamr@2: private: williamr@2: RArray iFields; williamr@2: TInt iSpare; williamr@2: TInt32 iSpare2; williamr@2: TInt32 iSpare3; williamr@2: }; williamr@2: williamr@2: williamr@2: /** williamr@2: Wrapper around RArray, to container TTextFieldMinimal buffers. williamr@2: williamr@2: Features: minimum size 1, easy resize of array, persistent last counted total. williamr@2: williamr@2: @internalComponent williamr@2: @released williamr@2: */ williamr@2: class RFieldBufferArray : public RArray williamr@2: { williamr@2: public: williamr@2: explicit RFieldBufferArray(); williamr@2: williamr@2: void ResizeL(TInt aNewSize); williamr@2: void ZeroAll(); williamr@2: TInt NewTotal(); williamr@2: TInt LastTotal() const; williamr@2: williamr@2: private: williamr@2: TInt iTotalLength; williamr@2: }; williamr@2: williamr@2: williamr@2: williamr@2: class CViewContact : public CBase williamr@2: /** The representation of a contact item used in contact views. williamr@2: williamr@2: It stores the contact item ID and other information. This includes a buffer williamr@2: holding the contents of all the item's fields, an array of indexes into the williamr@2: buffer indicating the start position of each field and a hint bit field (a williamr@2: combination of CContactDatabase::TContactViewFilter values) which is used williamr@2: in filtered views. williamr@2: williamr@2: The fields are defined by the view's sort order (RContactViewSortOrder). williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: /** Defines whether the contact view item is a contact group. */ williamr@2: enum TViewContactType williamr@2: { williamr@2: /** The contact view item is not a contact group. */ williamr@2: EContactItem, williamr@2: /** The contact view item is a contact group (CContactGroup). */ williamr@2: EGroup williamr@2: }; williamr@2: IMPORT_C CViewContact(TContactItemId aId); williamr@2: IMPORT_C static CViewContact* NewL(const CViewContact& aContact); williamr@2: IMPORT_C static CViewContact* NewLC(TContactItemId aId); williamr@2: IMPORT_C static CViewContact* NewL(TContactItemId aId, TInt aLength); williamr@2: static CViewContact* NewLC(RReadStream& aStream); williamr@2: williamr@2: IMPORT_C ~CViewContact(); williamr@2: IMPORT_C void InternalizeL(RReadStream& aStream); williamr@2: IMPORT_C void ExternalizeL(RWriteStream& aStream) const; williamr@2: IMPORT_C TInt ExternalizedSize() const; williamr@2: IMPORT_C TInt FieldCount() const; williamr@2: IMPORT_C TPtrC Field(TInt aPosition) const; williamr@2: IMPORT_C TBool ContactMatchesFilter(TInt aFilter) const; williamr@2: IMPORT_C void AddFieldL(const TDesC& aField); williamr@2: IMPORT_C TBool IsSortable() const; williamr@2: IMPORT_C void SetFirstFieldForBlankContactL(const TDesC& aFirstField); williamr@2: IMPORT_C void Reset(); williamr@2: IMPORT_C TInt ContactHint() const; williamr@2: IMPORT_C void SetContactHint(TInt aHint); williamr@2: IMPORT_C TUid ContactTypeUid() const; williamr@2: IMPORT_C void SetContactTypeUid(TUid aUid); williamr@2: williamr@2: inline TContactItemId Id() const; williamr@2: inline TViewContactType ContactType() const; williamr@2: public: williamr@2: inline void SetId(TContactItemId aId); williamr@2: inline void SetContactType(CViewContact::TViewContactType aContactType); williamr@2: static TBool HintFieldMatchesFilter(TInt aHintField, TInt aFilter); williamr@2: TPtrC FindFirstPopulatedField(TInt aOffset, TInt& aFoundPosition) const; williamr@2: williamr@2: #ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__ williamr@2: IMPORT_C void ChangeToLightweightObject(); williamr@2: TBool IsLightweightObject() const; williamr@2: void CopyL(const CViewContact& aContact); williamr@2: #endif //__SYMBIAN_CNTMODEL_USE_SQLITE__ williamr@2: williamr@2: private: williamr@2: void ConstructL(TInt aLength = 0); williamr@2: void ConstructL(const CViewContact& aContact); williamr@2: friend class CContactViewBase; williamr@2: private: williamr@2: TContactItemId iId; williamr@2: TViewContactType iContactType; williamr@2: CViewContactExtension* iExtension; williamr@2: RArray iTextIndexes; williamr@2: }; williamr@2: williamr@2: williamr@2: /* williamr@2: * A view can be named or un-named. An un-named view has a fixed sort order - the williamr@2: * only way to change this is by closing the object and creating a new one with a williamr@2: * different order. Named views may have their sort order changed. When this is williamr@2: * done, first all observers will be informed that the view is 'unavailable'. This williamr@2: * notification will be followed by 'sort order changed' and 'ready'. Only once williamr@2: * the 'ready' notification has been received may the view be used again. williamr@2: */ williamr@2: class CContactViewBase : public CBase williamr@2: /** The abstract base class for all contact view classes. williamr@2: williamr@2: All contact views operate asynchronously, so users of the view must observe williamr@2: it, by implementing the MContactViewObserver interface. Immediately after williamr@2: construction, views are not in a usable state (the underlying data may be williamr@2: being sorted, for instance). Only after the user has received a TContactViewEvent::EReady williamr@2: event may the view be used. williamr@2: williamr@2: View observers are also notified when changes occur, for instance when the williamr@2: view's state changes (see TState), when an error occurs, or when an item is williamr@2: added or removed. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: class CContactViewBaseExtension : public CBase williamr@2: /** An extension class that holds member data added in v7.0s. williamr@2: williamr@2: It was created for binary compatibility purposes. williamr@2: @internalComponent williamr@2: @released */ williamr@2: { williamr@2: public: williamr@2: static CContactViewBaseExtension* NewL(); williamr@2: ~CContactViewBaseExtension(); williamr@2: williamr@2: private: williamr@2: CContactViewBaseExtension(); williamr@2: void ConstructL(); williamr@2: williamr@2: public: williamr@2: /** A standard error code that is passed to view observers by NotifyObservers() williamr@2: (unless its value is KErrNone). */ williamr@2: TInt iError; williamr@2: /** The UID of the view's find configuration plug-in. williamr@2: williamr@2: On construction, this is initialised to KNullUid. williamr@2: williamr@2: The plug-in is loaded when ContactsMatchingCriteriaL(), ContactsMatchingPrefixL() williamr@2: or MatchesCriteriaL() is called. */ williamr@2: TUid iFindPluginUid; williamr@2: /** The UID of the view's sort plug-in. */ williamr@2: TUid iSortPluginUid; williamr@2: private: williamr@2: CContactViewFindConfigInterface* iFindPluginImpl; williamr@2: CViewContactSortPlugin* iSortPluginImpl; williamr@2: TCollationMethod iCollationMethod; williamr@2: friend class CContactViewBase; williamr@2: }; williamr@2: class TVirtualFunction1Params williamr@2: /** Holds the two parameters passed to the helper method GetContactIdsL() from williamr@2: the reserved function CContactViewBase_Reserved_1(). It has an inline constructor williamr@2: to initialise the data members. williamr@2: @publishedAll williamr@2: @released */ williamr@2: { williamr@2: public: williamr@2: /** Inline constructor to initialize member data williamr@2: @param aIndexes Pointer to an array of indexes in a view williamr@2: @param aIdArray Pointer to array of contact IDs */ williamr@2: inline TVirtualFunction1Params(const CArrayFix* aIndexes, CContactIdArray* aIdArray) :iIndexes(aIndexes), iIdArray(aIdArray){}; williamr@2: /** Pointer to an array of indexes in a view */ williamr@2: const CArrayFix* iIndexes; williamr@2: /** Pointer to array of contact IDs */ williamr@2: CContactIdArray* iIdArray; williamr@2: }; williamr@2: class TVirtualFunction2Params williamr@2: /** Holds the two parameters passed to the method GetContactsMatchingFilterL() williamr@2: from the reserved function CContactViewBase_Reserved_1(). It has an inline williamr@2: constructor to initialise the data members. williamr@2: */ williamr@2: { williamr@2: public: williamr@2: /** Inline constructor to initialize member data. williamr@2: @param aFilter Filter for the contacts williamr@2: @param aMatchingContacts Contacts matching a particular criterion */ williamr@2: inline TVirtualFunction2Params(TInt aFilter, RArray& aMatchingContacts) : iFilter(aFilter), iMatchingContacts(aMatchingContacts){}; williamr@2: public: williamr@2: /** Filter for the contacts. */ williamr@2: TInt iFilter; williamr@2: /** List of contacts matching the criteria. */ williamr@2: RArray& iMatchingContacts; williamr@2: }; williamr@2: class TVirtualFunction3Params williamr@2: /** Holds the two parameters passed to the method InsertContactInView() from the williamr@2: reserved function CContactViewBase_Reserved_1(). It has an inline williamr@2: constructor to initialise the data members. williamr@2: williamr@2: @internalAll */ williamr@2: { williamr@2: public: williamr@2: inline TVirtualFunction3Params(RPointerArray& aContacts, const CViewContact* aNewContact) :iContacts(aContacts), iNewContact(aNewContact){}; williamr@2: RPointerArray& iContacts; williamr@2: const CViewContact* iNewContact; williamr@2: }; williamr@2: /** Search type. williamr@2: williamr@2: This controls whether a search term can occur anywhere in a contact item field, williamr@2: or just at the beginning of the field. */ williamr@2: enum TSearchType williamr@2: { williamr@2: /** The search uses full wildcard matching so that the search string can occur anywhere williamr@2: in the item's fields. */ williamr@2: EFullSearch, williamr@2: /** The search uses partial wildcard matching so that the search string can only williamr@2: occur at the beginning of the item's fields. */ williamr@2: EPrefixSearch williamr@2: }; williamr@2: /** Identifies the functions that have been added to CContactViewBase, or that williamr@2: may be added in the future. This identifier is passed to the reserved virtual williamr@2: function CContactViewBase_Reserved_1() and enables the addition of new virtual williamr@2: methods without breaking binary compatibility. */ williamr@2: enum TFunction williamr@2: { williamr@2: /** Identifies the function CContactViewBase::GetContactIdsL(). */ williamr@2: ECContactViewBaseVirtualFunction1, williamr@2: /** Identifies the function CContactViewBase::GetContactsMatchingFilterL(). */ williamr@2: ECContactViewBaseVirtualFunction2, williamr@2: // communication with Sort Plug-in williamr@2: /** Identifies the function CContactViewBase::InsertContactInView(). */ williamr@2: ECContactViewBaseVirtualFunction3, williamr@2: }; williamr@2: protected: williamr@2: /** Defines the contact view states. */ williamr@2: enum TState williamr@2: { williamr@2: /** The view is initialising. williamr@2: williamr@2: This is the view's state immediately after construction or after a significant change williamr@2: (e.g CurrentDatabaseChanged or UnknownChanges), indicating that it can't be used yet. */ williamr@2: EInitializing, williamr@2: /** The view is ready to be used. */ williamr@2: EReady, williamr@2: /** The view is not ready to be used, for instance immediately after the sort order williamr@2: has changed, or after an error has occurred. */ williamr@2: ENotReady williamr@2: }; williamr@2: public: williamr@2: IMPORT_C void OpenL(MContactViewObserver& aObserver); williamr@2: IMPORT_C TInt Open(MContactViewObserver& aObserver); williamr@2: IMPORT_C TBool Close(const MContactViewObserver& aObserver); williamr@2: /** Returns the contact item ID at the specified index into the view. williamr@2: williamr@2: @capability ReadUserData williamr@2: @param aIndex Index of the contact item ID into the view. williamr@2: @return The contact item ID. */ williamr@2: virtual TContactItemId AtL(TInt aIndex) const=0; williamr@2: /** Returns the contact item at the specified index into the view. williamr@2: williamr@2: @capability ReadUserData williamr@2: @param aIndex Index of the contact item into the view. williamr@2: @return The contact item. */ williamr@2: virtual const CViewContact& ContactAtL(TInt aIndex) const =0; williamr@2: /** Returns the number of contact items in the view. williamr@2: williamr@2: @capability ReadUserData williamr@2: @return The number of contact items in the view. */ williamr@2: virtual TInt CountL() const=0; williamr@2: /** Returns the index into the view of the specified contact item. williamr@2: williamr@2: @capability ReadUserData williamr@2: @param aId The contact item ID to search for. williamr@2: @return The index into the view of the contact item ID, or KErrNotFound if williamr@2: no matching ID can be found. */ williamr@2: virtual TInt FindL(TContactItemId aId) const=0; williamr@2: /** Returns a descriptor containing the contents of all fields for an item in the view. williamr@2: williamr@2: The field separator is used to separate the contents of each field. It is williamr@2: not appended to the last field. williamr@2: williamr@2: @capability ReadUserData williamr@2: @param aIndex The index of the contact item into the view. williamr@2: @param aSeparator The string to use to separate the fields. williamr@2: @return Pointer to the contact item descriptor. */ williamr@2: virtual HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const=0; williamr@2: IMPORT_C virtual void ContactsMatchingCriteriaL(const MDesCArray& aFindWords,RPointerArray& aMatchedContacts); williamr@2: /** Gets the view preferences. williamr@2: williamr@2: @capability ReadUserData williamr@2: @return The view preferences. */ williamr@2: virtual TContactViewPreferences ContactViewPreferences()=0; williamr@2: /** Gets the view's sort order. williamr@2: williamr@2: @capability ReadUserData williamr@2: @return The sort order. */ williamr@2: virtual const RContactViewSortOrder& SortOrderL() const = 0; williamr@2: IMPORT_C virtual void ContactsMatchingPrefixL(const MDesCArray& aFindWords, RPointerArray& aMatchedContacts); williamr@2: //This is a reserved virtual exported function that is used for BC proofing against present williamr@2: //and future additions of new exported virtual functions. Existing exported virtual methods williamr@2: //that broke BC are now non-virtual exported helper functions called from this method. williamr@2: //All derived classes of CContactViewBase that are public must mandatorily williamr@2: //implement this reserved exported virtual method. williamr@2: IMPORT_C virtual TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams); williamr@2: //New exported method to set the ECOM plug-in to be used williamr@2: IMPORT_C void SetViewFindConfigPlugin(TUid aUid); williamr@2: IMPORT_C TUid GetViewFindConfigPlugin(); williamr@2: IMPORT_C virtual void GetContactIdsL(const CArrayFix& aIndexes, CContactIdArray& aContactIds); williamr@2: IMPORT_C TInt Error() const; williamr@2: IMPORT_C TUid GetViewSortPluginImplUid() const; williamr@2: williamr@2: protected: williamr@2: IMPORT_C ~CContactViewBase(); williamr@2: IMPORT_C void ConstructL(); williamr@2: williamr@2: IMPORT_C CContactViewBase(const CContactDatabase& aDb); williamr@2: IMPORT_C void NotifyObservers(const TContactViewEvent& aEvent); williamr@2: IMPORT_C TInt NotifyObserverAsync(MContactViewObserver& aObserver,const TContactViewEvent& aEvent); williamr@2: IMPORT_C static TBool IdsMatch(const CViewContact& aFirst,const CViewContact& aSecond); williamr@2: IMPORT_C HBufC* FieldsWithSeparatorLC(const RPointerArray& aContacts,TInt aIndex,const TDesC& aSeparator) const; williamr@2: //Find helper functions williamr@2: IMPORT_C virtual TBool MatchesCriteriaL(const CViewContact& aContact,const MDesCArray& aFindWords); williamr@2: IMPORT_C static TBool MatchesCriteriaL(const CViewContact& aContact,const MDesCArray& aFindWords, TSearchType aSearchType); williamr@2: IMPORT_C static TBool MatchesCriteriaL(const CViewContact& aContact,const MDesCArray& aFindWords, TSearchType aSearchType,CContactViewBase::CContactViewBaseExtension* aExtension); williamr@2: IMPORT_C static TBool IdsEqual(const TContactIdWithMapping& aFirst,const TContactIdWithMapping& aSecond); williamr@2: IMPORT_C static TBool IndexesEqual(const TContactIdWithMapping& aFirst,const TContactIdWithMapping& aSecond); williamr@2: IMPORT_C static TInt CompareFieldsL(const CViewContact& aFirst, const CViewContact& aSecond); williamr@2: // View Sort Plugin changes williamr@2: IMPORT_C static TInt CompareContactIds(const CViewContact& aFirst, const CViewContact& aSecond); williamr@2: IMPORT_C static TBool ContactIsSortable(const CViewContact& aContact); williamr@2: IMPORT_C TInt CompareContactsAndIdsL(const CViewContact& aFirst, const CViewContact& aSecond) const; williamr@2: protected: // these are needed by CContactLocalView only williamr@2: TInt InsertContactInView(RPointerArray& aContacts, const CViewContact* aNewContact, TBool aSortByIdOnly, TInt* aIndex) const; williamr@2: TBool IsContactSortable(const CViewContact& aContact, TContactViewPreferences& aViewPreferences) const; williamr@2: CViewContactSortPlugin* SortPluginImpl() const; williamr@2: TUid FindSortPluginImplL (const TDesC8& aSortPluginName,TBool aWildCard=EFalse) const; williamr@2: TUid FindDefaultViewSortPluginImplL () const; williamr@2: void LoadViewSortPluginL (TUid aSortPluginUid,TContactViewPreferences& aViewPreferences); williamr@2: williamr@2: private: williamr@2: static TInt AsyncNotifyCallBack(TAny* aSelf); williamr@2: static CDesCArrayFlat* CreateFindWordArrayLC(const MDesCArray& aFindWords, TSearchType aSearchType); williamr@2: static TBool ContactMatchesCriteriaL(const CViewContact& aContact,const MDesCArray& aFindWords,CContactViewBase::CContactViewBaseExtension* aExtension); williamr@2: void MatchContactsL(const MDesCArray& aFindWords,RPointerArray& aMatchedContacts, TSearchType aSearchType); williamr@2: static TInt CompareFieldsWithCollationLevel(const CViewContact& aFirst, const CViewContact& aSecond, williamr@2: TInt aCollationLevel, TCollationMethod* aCollateMethod); williamr@2: TInt GetErrorValueFromExtensionClass(); williamr@2: void GetContactsMatchingFilterL(TInt aFilter, RArray& aMatchingContacts); williamr@2: TInt TextCompareFieldsL(const CViewContact& aFirst, const CViewContact& aSecond) const; williamr@2: williamr@2: williamr@2: private: williamr@2: struct TObserverAndEvent williamr@2: { williamr@2: TContactViewEvent iAsyncEvent; williamr@2: MContactViewObserver* iObserverToNotify; williamr@2: }; williamr@2: protected: williamr@2: // Reference to CContactDatabase class. williamr@2: const CContactDatabase& iDb; williamr@2: // Different Contacts view states. williamr@2: TState iState; williamr@2: // The pointer to the ContactViewBase BC extension class. williamr@2: CContactViewBaseExtension* iExtension; williamr@2: private: williamr@2: RPointerArray iObserverArray; williamr@2: CIdle* iAsyncNotifier; williamr@2: RArray iOutstandingNotifications; williamr@2: }; williamr@2: williamr@2: inline TInt CContactViewBase::GetErrorValueFromExtensionClass() williamr@2: { williamr@2: return iExtension->iError; williamr@2: } williamr@2: williamr@2: class MLplPersistenceLayerFactory; williamr@2: williamr@2: #ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__ williamr@2: williamr@2: class CViewContactManager; williamr@2: williamr@2: #else //__SYMBIAN_CNTMODEL_USE_SQLITE__ williamr@2: williamr@2: class CViewIterator; williamr@2: williamr@2: #endif //__SYMBIAN_CNTMODEL_USE_SQLITE__ williamr@2: williamr@2: class CContactLocalView : public CContactViewBase, public MContactDbObserver williamr@2: /** An instantiable base class for contact views. williamr@2: williamr@2: The data associated with a local view is allocated within the client's memory williamr@2: space; CContactRemoteView should be used in preference if the view is likely williamr@2: to be shared between multiple clients. It is kept up to date by receiving williamr@2: change events from the underlying CContactDatabase object which it observes. williamr@2: The view preferences and sort order are specified on construction. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C static CContactLocalView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes); williamr@2: IMPORT_C static CContactLocalView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes, williamr@2: const TDesC8& aSortPluginName); williamr@2: IMPORT_C static CContactLocalView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes, williamr@2: MLplPersistenceLayerFactory* aFactory,const TDesC8& aSortPluginName); williamr@2: williamr@2: IMPORT_C const RContactViewSortOrder& SortOrder() const; williamr@2: public: // From CContactViewBase. williamr@2: TContactItemId AtL(TInt aIndex) const; williamr@2: TInt CountL() const; williamr@2: TInt FindL(TContactItemId aId) const; williamr@2: HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const; williamr@2: const CViewContact& ContactAtL(TInt aIndex) const; williamr@2: TContactViewPreferences ContactViewPreferences(); williamr@2: const RContactViewSortOrder& SortOrderL() const; williamr@2: void NotifySortError(TInt aError); williamr@2: //All derived classes of CContactViewBase that are public should mandatorily williamr@2: //implement this reserved exported virtual method. williamr@2: IMPORT_C TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams); williamr@2: protected: williamr@2: IMPORT_C ~CContactLocalView(); williamr@2: IMPORT_C CContactLocalView(const CContactDatabase& aDb,TContactViewPreferences aContactTypes); williamr@2: CContactLocalView(const CContactDatabase& aDb,TContactViewPreferences aContactTypes,MLplPersistenceLayerFactory* aIterFactory); williamr@2: IMPORT_C void ConstructL(MContactViewObserver& aObserver,const RContactViewSortOrder& aSortOrder); williamr@2: void ConstructL(MContactViewObserver& aObserver,const RContactViewSortOrder& aSortOrder, const TBool aUseNamedPlugin, const TDesC8& aSortPluginName); williamr@2: IMPORT_C virtual void SortL(const RContactViewSortOrder& aSortOrder); williamr@2: IMPORT_C virtual TInt InsertL(TContactItemId aId); williamr@2: IMPORT_C virtual TInt RemoveL(TContactItemId aId); williamr@2: protected: williamr@2: void SetState(TState aState); williamr@2: private: // From MContactDbObserver. williamr@2: virtual void HandleDatabaseEventL(TContactDbObserverEvent aEvent); williamr@2: williamr@2: private: williamr@2: williamr@2: #ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__ williamr@2: void SortComplete(TInt aSortErr); williamr@2: void SetSortOrderL(const RContactViewSortOrder& aSortOrder); williamr@2: void SortL(); williamr@2: void SafeResort(); williamr@2: friend class CViewContactManager; williamr@2: #else //__SYMBIAN_CNTMODEL_USE_SQLITE__ williamr@2: TInt SortCallBack(); williamr@2: TInt DoReadIncrementL(); williamr@2: void ResetSortL(); williamr@2: void InitialiseSortL(const RContactViewSortOrder& aSortOrder, TBool aChangingSortOrder); williamr@2: void SortL(); williamr@2: void SafeResort(); williamr@2: void ContactsArraySortL(); williamr@2: TBool ContactCorrectType(TUid aType,TContactViewPreferences aTypeToInclude); williamr@2: #endif //__SYMBIAN_CNTMODEL_USE_SQLITE__ williamr@2: williamr@2: private: // Metheds for event handling williamr@2: void HandleOutstandingEvents(); williamr@2: void HandleOutstandingEventL(); williamr@2: friend class CIdleContactSorter; williamr@2: protected: williamr@2: /** The sort order. williamr@2: This is set during construction or when SortL() is called. */ williamr@2: RContactViewSortOrder iSortOrder ; williamr@2: private: williamr@2: IMPORT_C virtual void CContactLocalView_Reserved_1(); williamr@2: IMPORT_C virtual void CContactLocalView_Reserved_2(); williamr@2: williamr@2: private: williamr@2: MLplPersistenceLayerFactory* iFactory; williamr@2: RPointerArray iContacts; williamr@2: RPointerArray iUnSortedContacts; williamr@2: RArray iOutstandingEvents; williamr@2: CIdleContactSorter* iAsyncSorter; williamr@2: williamr@2: #ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__ williamr@2: CViewContactManager* iViewCntMgr; williamr@2: #else //__SYMBIAN_CNTMODEL_USE_SQLITE__ williamr@2: CViewIterator* iViewIterator; williamr@2: #endif //__SYMBIAN_CNTMODEL_USE_SQLITE__ williamr@2: williamr@2: CContactTextDef* iTextDef; williamr@2: TContactViewPreferences iViewPreferences; williamr@2: TBool iSpare0; williamr@2: TInt iSpare; williamr@2: }; williamr@2: williamr@2: class RContactRemoteView : public RSubSessionBase williamr@2: /** This class is used internally by remote contact views as the handle to the williamr@2: server side view object. williamr@2: williamr@2: @see CContactRemoteViewBase williamr@2: @internalComponent williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: void OpenL(const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes,const TUid& aSortPluginImplUid,const TDesC8& aSortPluginName); williamr@2: void OpenL(const CContactDatabase& aDb,const TDesC& aName,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes,const TUid& aSortPluginImplUid,const TDesC8& aSortPluginName); williamr@2: void Close(); williamr@2: public: // From CContactViewBase williamr@2: TContactItemId AtL(TInt aIndex) const; williamr@2: CViewContact* ContactAtL(TInt aIndex); williamr@2: TInt CountL() const; williamr@2: TInt FindL(TContactItemId aId) const; williamr@2: HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const; williamr@2: const RContactViewSortOrder& SortOrderL(); williamr@2: public: williamr@2: void ContactsMatchingCriteriaL(const MDesCArray& aFindWords,RPointerArray& aMatchedContacts, TBool aPrefixSearch,TUid aUid); williamr@2: void ChangeSortOrderL(const RContactViewSortOrder& aSortOrder); williamr@2: void GetSortOrderL(RContactViewSortOrder& aSortOrder); williamr@2: TContactViewPreferences ContactViewPreferencesL(); williamr@2: williamr@2: void RequestViewEvent(TPckgBuf& aEvent,TRequestStatus& aStatus); williamr@2: TInt CancelRequestViewEvent(); williamr@2: void GetContactIdsL(const CArrayFix& aIndexes, CContactIdArray& aContactIds); williamr@2: void GetContactsMatchingFilterL(TInt aFilter, RArray& aMatchingContacts); williamr@2: TUid GetViewSortPluginImplUidL() const; williamr@2: private: williamr@2: HBufC8* PackageSortOrderLC(const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes) const; williamr@2: HBufC8* PackageSortOrderAndPluginDetailsLC(const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes,const TUid& aSortPluginImplUid,const TDesC8& aSortPluginName) const; williamr@2: private: williamr@2: CViewContact* iContact; williamr@2: RContactViewSortOrder iSortOrder ; williamr@2: }; williamr@2: williamr@2: williamr@2: NONSHARABLE_CLASS(CContactRemoteViewBase) : public CContactViewBase williamr@2: /** Base class for all remote contact view classes. williamr@2: williamr@2: It implements all the pure virtual functions in CContactViewBase and additionally williamr@2: it handles remote view notifications. The data associated with remote views williamr@2: is allocated within the memory space of the contacts server. This means that williamr@2: multiple clients can share the same server side view object, thereby reducing williamr@2: the overhead associated with initial sorting of the view data and keeping williamr@2: it in sync with the underlying data. Remote views should therefore be used williamr@2: when the same view is likely to be needed by more than one client. williamr@2: @internalComponent williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: // From CContactViewBase. williamr@2: TContactItemId AtL(TInt aIndex) const; williamr@2: TInt CountL() const; williamr@2: TInt FindL(TContactItemId aId) const; williamr@2: HBufC* AllFieldsLC(TInt aIndex,const TDesC& aSeparator) const; williamr@2: const CViewContact& ContactAtL(TInt aIndex) const; williamr@2: TContactViewPreferences ContactViewPreferences(); williamr@2: void ContactsMatchingCriteriaL(const MDesCArray& aFindWords,RPointerArray& aMatchedContacts); williamr@2: void ContactsMatchingPrefixL(const MDesCArray& aFindWords, RPointerArray& aMatchedContacts); williamr@2: const RContactViewSortOrder& SortOrderL() const; williamr@2: //All derived classes of CContactViewBase that are public should mandatorily williamr@2: //implement this reserved exported virtual method. williamr@2: TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams); williamr@2: //This function was virtual in a previous release, if you still need to use it williamr@2: //in a virtual way then you can call it via the Reserved function. williamr@2: //The functionality of this function ,however,remains the same. williamr@2: void GetContactIdsL(const CArrayFix& aIndexes, CContactIdArray& aContactIds); williamr@2: void GetContactsMatchingFilterL(TInt aFilter, RArray& aMatchingContacts); williamr@2: protected: williamr@2: ~CContactRemoteViewBase(); williamr@2: CContactRemoteViewBase(const CContactDatabase& aDb); williamr@2: void ConstructL(MContactViewObserver& aObserver); williamr@2: private: williamr@2: static TInt NotifierCallBack(TAny* aSelf); williamr@2: void HandleContactViewEvent(const TContactViewEvent& aEvent); williamr@2: protected: williamr@2: /** A handle to the server side view. */ williamr@2: RContactRemoteView iView; williamr@2: private: williamr@2: CContactRemoteViewNotifier* iNotifier; williamr@2: /** Cached copy of the count of the local view in the contacts server. williamr@2: If this is KCachedItemCountInvalid then next time CountL is called williamr@2: the current count is retrieved from the contacts server. */ williamr@2: mutable TInt iCount; williamr@2: }; williamr@2: williamr@2: williamr@2: class CContactRemoteView : public CContactRemoteViewBase williamr@2: /** An instantiable remote contact view class. williamr@2: williamr@2: Remote views are associated with a CContactLocalView object held in the contacts williamr@2: server. They provide an efficient means for multiple clients to share the williamr@2: same underlying view. williamr@2: williamr@2: The view preferences and sort order are specified on construction. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C static CContactRemoteView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes); williamr@2: IMPORT_C static CContactRemoteView* NewL(MContactViewObserver& aObserver,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes, williamr@2: const TDesC8& aSortPluginName); williamr@2: IMPORT_C void GetSortOrderL(RContactViewSortOrder& aSortOrder); williamr@2: //All derived classes of CContactViewBase that are public should mandatorily williamr@2: //implement this reserved exported virtual method. williamr@2: TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams); williamr@2: protected: williamr@2: ~CContactRemoteView(); williamr@2: CContactRemoteView(const CContactDatabase& aDb); williamr@2: private: williamr@2: void ConstructL(MContactViewObserver& aObserver,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes); williamr@2: void ConstructL(MContactViewObserver& aObserver,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypesconst, const TDesC8& aSortPluginName); williamr@2: }; williamr@2: williamr@2: williamr@2: class CContactNamedRemoteView : public CContactRemoteView williamr@2: /** A named remote contact view. williamr@2: williamr@2: This class enables multiple clients to share a named server side view. It williamr@2: also provides a function to change the sort order. If the sort order is changed, williamr@2: a notification is sent to all users of the named view. williamr@2: @publishedAll williamr@2: @released williamr@2: */ williamr@2: { williamr@2: public: williamr@2: IMPORT_C static CContactNamedRemoteView* NewL(MContactViewObserver& aObserver,const TDesC& aName,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes); williamr@2: IMPORT_C static CContactNamedRemoteView* NewL(MContactViewObserver& aObserver,const TDesC& aName,const CContactDatabase& aDb,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes, williamr@2: const TDesC8& aSortPluginName); williamr@2: IMPORT_C void ChangeSortOrderL(const RContactViewSortOrder& aSortOrder); williamr@2: //All derived classes of CContactViewBase that are public should mandatorily williamr@2: //implement this reserved exported virtual method. williamr@2: TAny* CContactViewBase_Reserved_1(TFunction aFunction,TAny* aParams); williamr@2: private: williamr@2: ~CContactNamedRemoteView(); williamr@2: CContactNamedRemoteView(const CContactDatabase& aDb); williamr@2: void ConstructL(MContactViewObserver& aObserver,const TDesC& aName,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes); williamr@2: void ConstructL(MContactViewObserver& aObserver,const TDesC& aName,const RContactViewSortOrder& aSortOrder,TContactViewPreferences aContactTypes, const TDesC8& aSortPluginName); williamr@2: }; williamr@2: williamr@2: inline TContactViewEvent::TContactViewEvent() williamr@2: /** Empty default constructor. */ williamr@2: {}; williamr@2: williamr@2: inline TContactViewEvent::TContactViewEvent(TEventType aEventType,TInt aInt,TContactItemId aContactId) : iEventType(aEventType),iInt(aInt),iContactId(aContactId) williamr@2: /** Constructor with an event type and an optional error code and contact item ID. williamr@2: williamr@2: @param aEventType The event type. williamr@2: @param aInt Optional standard error code. williamr@2: @param aContactId Optional contact item ID. */ williamr@2: {}; williamr@2: williamr@2: inline void RContactViewSortOrder::AppendL(TFieldType aField) williamr@2: /** Appends a field type to the sort order object. williamr@2: williamr@2: @param aField The field type to append. */ williamr@2: { User::LeaveIfError(iFields.Append(aField)); } williamr@2: williamr@2: inline TFieldType RContactViewSortOrder::operator[](TInt aIndex) const williamr@2: /** Gets an indexed field type. williamr@2: williamr@2: @param aIndex Index of the required field type. A panic occurs if this is williamr@2: invalid. williamr@2: @return The field type located at the indexed position in the array. */ williamr@2: { return iFields[aIndex]; } williamr@2: williamr@2: inline TInt RContactViewSortOrder::Count() const williamr@2: /** Gets the number of field types in the sort order array. williamr@2: williamr@2: @return The number of field types in the array. */ williamr@2: { return iFields.Count(); } williamr@2: williamr@2: inline TContactItemId CViewContact::Id() const williamr@2: /** Gets the view item's ID. williamr@2: williamr@2: @return The view item's ID. */ williamr@2: {return iId;} williamr@2: williamr@2: inline CViewContact::TViewContactType CViewContact::ContactType() const williamr@2: /** Gets the view item's type. williamr@2: williamr@2: @return The view item's type. */ williamr@2: {return iContactType;} williamr@2: williamr@2: inline void CViewContact::SetId(TContactItemId aId) williamr@2: /** Sets the view item's ID. williamr@2: williamr@2: @param aId The contact item ID. */ williamr@2: {iId=aId;} williamr@2: williamr@2: inline void CViewContact::SetContactType(CViewContact::TViewContactType aContactType) williamr@2: /** Sets the view item's type. williamr@2: williamr@2: @param aContactType The view item's type. */ williamr@2: {iContactType=aContactType;} williamr@2: #endif