phonebookengines/VirtualPhonebook/VPbkEng/inc/CVPbkCompositeContactView.h
changeset 0 e686773b3f54
child 15 e8e3147d53eb
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Composite contact view.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CVPBKCOMPOSITECONTACTVIEW_H
       
    20 #define CVPBKCOMPOSITECONTACTVIEW_H
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <e32base.h>
       
    24 #include <MVPbkContactViewBase.h>
       
    25 #include <MVPbkContactViewObserver.h>
       
    26 #include <MVPbkContactViewFiltering.h>
       
    27 #include <MVPbkContactViewBaseChildAccessExtension.h>
       
    28 #include <VPbkContactView.hrh>
       
    29 #include <CVPbkAsyncOperation.h>
       
    30 #include "CVPbkEventArrayItem.h"
       
    31 
       
    32 // FORWARD DECLARATIONS
       
    33 class MVPbkContactViewSortPolicy;
       
    34 class CVPbkEventArrayItem;
       
    35 class MVPbkCompositeContactViewPolicy;
       
    36 
       
    37 
       
    38 /**
       
    39  * Virtual Phonebook abstract composite contact view.
       
    40  * Composite contact views can be used to compose a view from
       
    41  * multiple sub views.
       
    42  */
       
    43 NONSHARABLE_CLASS(CVPbkCompositeContactView) : 
       
    44         public CBase,
       
    45         public MVPbkContactViewBase,
       
    46         public MVPbkContactViewObserver,
       
    47         protected MVPbkContactViewFiltering,
       
    48         public MVPbkContactViewBaseChildAccessExtension
       
    49 	{
       
    50     public: // Constructors and destructor
       
    51         /**
       
    52          * Destructor.
       
    53          */
       
    54         ~CVPbkCompositeContactView();
       
    55 
       
    56     public: // Interface
       
    57         /**
       
    58          * Adds subview to this composite view. Ownership is transferred
       
    59          * if leave does not occur.
       
    60          * NOTE: This composite view must already be an observer of aSubView
       
    61          *       when calling this function.
       
    62          *
       
    63          * @param aSubView Subview to add to this composite view.
       
    64          * @param aViewId ViewId of added subview
       
    65          */
       
    66         void AddSubViewL(
       
    67                 MVPbkContactViewBase* aSubView, TInt  aViewId = KVPbkDefaultViewId);
       
    68         
       
    69         /**
       
    70          * ActualContactCountL returns the number of contact's in subviews.
       
    71          * It might be that all subview events haven't
       
    72          * arrived yet to this composite so ActualContactCountL is not always
       
    73          * same as CompositeContactCountL
       
    74          *
       
    75          * @return the contact count calculated from subviews.
       
    76          */
       
    77         TInt ActualContactCountL() const;
       
    78         
       
    79         /**
       
    80          * @return The number of contacts in iContactMapping
       
    81          */
       
    82         inline TInt CompositeContactCountL() const;
       
    83         
       
    84         /**
       
    85          * If the parent of this view is also a composite view
       
    86          * it calls this to configure this view as an internal view
       
    87          * that has no external observers.
       
    88          */
       
    89         void ApplyInternalCompositePolicyL();
       
    90         
       
    91         void SetViewId(TInt aViewId);
       
    92         
       
    93     private: // Abstract interface for composite implementations
       
    94         /**
       
    95          * Builds view mapping.
       
    96          */
       
    97         virtual void DoBuildContactMappingL() = 0;
       
    98 
       
    99         /**
       
   100          * Handles contact addition to the view.
       
   101          *
       
   102          * @param aSubViewIndex     Sub view index.
       
   103          * @param aIndex            Index of the contact in the sub view.
       
   104          * @return  Composite contact view index of the added contact.
       
   105          */
       
   106         virtual TInt DoHandleContactAdditionL(
       
   107                 TInt aSubViewIndex,
       
   108                 TInt aIndex ) = 0;
       
   109 
       
   110     public: // From MVPbkContactViewBase
       
   111         TVPbkContactViewType Type() const;
       
   112         void ChangeSortOrderL(
       
   113                 const MVPbkFieldTypeList& aSortOrder );
       
   114         const MVPbkFieldTypeList& SortOrder() const;
       
   115         void RefreshL();
       
   116         TInt ContactCountL() const;
       
   117         const MVPbkViewContact& ContactAtL(
       
   118                 TInt aIndex ) const;
       
   119         MVPbkContactLink* CreateLinkLC(
       
   120                 TInt aIndex ) const;
       
   121         TInt IndexOfLinkL(
       
   122                 const MVPbkContactLink& aContactLink ) const;
       
   123         void AddObserverL(
       
   124                 MVPbkContactViewObserver& aObserver );
       
   125         void RemoveObserver(
       
   126                 MVPbkContactViewObserver& aObserver );
       
   127         TBool MatchContactStore(
       
   128                 const TDesC& aContactStoreUri ) const;
       
   129         TBool MatchContactStoreDomain(
       
   130                 const TDesC& aContactStoreDomain ) const;
       
   131         MVPbkContactBookmark* CreateBookmarkLC(
       
   132                 TInt aIndex ) const;
       
   133         TInt IndexOfBookmarkL(
       
   134                 const MVPbkContactBookmark& aContactBookmark ) const;
       
   135         MVPbkContactViewFiltering* ViewFiltering();
       
   136         TAny* ContactViewBaseExtension(TUid aExtensionUid); 
       
   137             
       
   138     private: // From MVPbkContactViewObserver
       
   139         void ContactViewReady(
       
   140                 MVPbkContactViewBase& aView );
       
   141         void ContactViewUnavailable(
       
   142                 MVPbkContactViewBase& aView );
       
   143         void ContactAddedToView(
       
   144                 MVPbkContactViewBase& aView,
       
   145                 TInt aIndex,
       
   146                 const MVPbkContactLink& aContactLink );
       
   147         void ContactRemovedFromView(
       
   148                 MVPbkContactViewBase& aView,
       
   149                 TInt aIndex,
       
   150                 const MVPbkContactLink& aContactLink );
       
   151         void ContactViewError(
       
   152                 MVPbkContactViewBase& aView,
       
   153                 TInt aError,
       
   154                 TBool aErrorNotified);
       
   155 
       
   156     private: // From MVPbkContactViewFiltering
       
   157         /// Composite implementations must implement this
       
   158         virtual MVPbkContactViewBase* CreateFilteredViewLC(
       
   159             MVPbkContactViewObserver& aObserver,
       
   160             const MDesCArray& aFindWords,
       
   161             const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts ) = 0;
       
   162         void UpdateFilterL( 
       
   163             const MDesCArray& aFindWords,
       
   164             const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts );
       
   165 
       
   166     private: // From MVPbkContactViewBaseChildAccessExtension
       
   167         TInt ChildViewCount() const;
       
   168         MVPbkContactViewBase& ChildViewAt(TInt aIndex);
       
   169         MVPbkContactViewBase* GetChildViewById(TInt aId);
       
   170         TInt GetViewId();
       
   171 
       
   172     protected: // Types
       
   173         class CSubViewData;
       
   174                 
       
   175         /**
       
   176          * Contact mapping structure. Mapping supports 128 subviews
       
   177          * and over 8 million contacts per sub view.
       
   178          */
       
   179         struct TContactMapping
       
   180             {
       
   181             /// Own: View index
       
   182             TInt iViewIndex: 8;
       
   183             /// Own: Contact index
       
   184             TInt iContactIndex: 24;
       
   185             };                          
       
   186 
       
   187     protected: // Implementation
       
   188         CVPbkCompositeContactView();
       
   189         void BaseConstructL(
       
   190                 const MVPbkFieldTypeList& aSortOrder );
       
   191         static TBool CompareMappings(
       
   192                 const TContactMapping& aLhs,
       
   193                 const TContactMapping& aRhs );
       
   194         TBool IsCompositeReady() const;
       
   195         /// Returns the composite's view policy.
       
   196         MVPbkCompositeContactViewPolicy& CompositePolicy() const;
       
   197         
       
   198     private: // Implementation
       
   199         TInt FindSubViewIndex(MVPbkContactViewBase& aView) const;
       
   200         TBool AllSubViewsKnown() const;
       
   201         TBool AnySubViewReady() const;
       
   202         void ResetContactMapping();
       
   203         void RemoveContactMappingsFromView(MVPbkContactViewBase& aView);
       
   204         void HandleContactViewReadyL( MVPbkContactViewBase& aView );
       
   205         void HandleContactViewUnavailableL( MVPbkContactViewBase& aView );
       
   206         TInt HandleContactRemoval(
       
   207                 MVPbkContactViewBase& aView,
       
   208                 TInt aIndex );
       
   209         TInt HandleContactAddition(
       
   210                 MVPbkContactViewBase& aView,
       
   211                 TInt aIndex );
       
   212         void DoAddObserverL(MVPbkContactViewObserver& aObserver);
       
   213         void AddObserverError(
       
   214                 MVPbkContactViewObserver& aObserver,
       
   215                 TInt aError );
       
   216         void SendViewReadyEvent();
       
   217         void SendViewUnavailableEvent();
       
   218         void SendViewErrorEvent( TInt aError, TBool aErrorNotified );
       
   219         void UpdateSortOrderL();
       
   220             
       
   221     protected: // Data
       
   222         /// Own: Array of subviews
       
   223         RPointerArray<CSubViewData> iSubViews;
       
   224         /// Own: Array of contact mappings
       
   225         RArray<TContactMapping> iContactMapping;
       
   226 
       
   227     private: // Data
       
   228         /// Ref: Async operation
       
   229         VPbkEngUtils::CVPbkAsyncOperation iAsyncOperation;
       
   230         /// Own: Sort order
       
   231         MVPbkFieldTypeList* iSortOrder;
       
   232         /// Own: Array of observers
       
   233         RPointerArray<MVPbkContactViewObserver> iObservers;
       
   234         /// Own: A policy for composite's internal functionality
       
   235         MVPbkCompositeContactViewPolicy* iCompositePolicy;
       
   236         /// Current view identifier
       
   237         TInt iViewId;
       
   238     };
       
   239 
       
   240 inline TInt CVPbkCompositeContactView::CompositeContactCountL() const
       
   241     {
       
   242     return iContactMapping.Count();
       
   243     }
       
   244 
       
   245 /**
       
   246  * Class to hold subview data.
       
   247  */
       
   248 NONSHARABLE_CLASS( CVPbkCompositeContactView::CSubViewData ):
       
   249         public CBase
       
   250     {
       
   251     public: // Types
       
   252         /**
       
   253          * View state enumeration.
       
   254          */
       
   255         enum TViewState
       
   256             {
       
   257             ENotKnown,
       
   258             EUnavailable,
       
   259             EReady
       
   260             };
       
   261 
       
   262     public: // Constructors and destructor
       
   263         /**
       
   264          * Constructor.
       
   265          *
       
   266          * @param aState    View state.
       
   267          */
       
   268         CSubViewData(TViewState aState) : iState( aState ) {}
       
   269             
       
   270         /**
       
   271          * Destructor.
       
   272          */
       
   273         ~CSubViewData();
       
   274 
       
   275     public: // Data
       
   276         /// Ref: Contact view
       
   277         MVPbkContactViewBase* iView;
       
   278         /// Own: View state
       
   279         TViewState iState;
       
   280         /// Ref: Cursor pointer, used when merging
       
   281         const MVPbkViewContact* iContactCursor;
       
   282         /// Own: Cursor
       
   283         TInt iCursor;
       
   284         /// view identifier of iView member variable
       
   285         TInt  iViewId;
       
   286     };
       
   287 
       
   288 /**
       
   289  * Internal interface for different behavior of exterior and interior
       
   290  * composite views.
       
   291  */ 
       
   292 NONSHARABLE_CLASS(MVPbkCompositeContactViewPolicy)
       
   293     {
       
   294     public: 
       
   295         /**
       
   296          * Destructor
       
   297          */
       
   298         virtual ~MVPbkCompositeContactViewPolicy() {}
       
   299         
       
   300         /**
       
   301          * Handles contact added & removed events.
       
   302          */
       
   303         virtual void HandleViewEventsL( 
       
   304             CVPbkEventArrayItem::TViewEventType aEvent,
       
   305             MVPbkContactViewBase& aSubview,
       
   306             TInt aIndex, const 
       
   307             MVPbkContactLink& aContactLink ) = 0;
       
   308         
       
   309         /** 
       
   310          * Reset policy if it has cached data.
       
   311          */
       
   312         virtual void Reset() = 0;
       
   313         
       
   314         /**
       
   315          * Returns the contact count in composite or 0 if
       
   316          * composite is not up to date with leaf views.
       
   317          * @param aCompositeCount The count according to composite view.
       
   318          * @return aCompositeCount or 0.
       
   319          */
       
   320         virtual TInt ContactCountL() const = 0;
       
   321         
       
   322         /**
       
   323          * Returns ETrue if this is an internal composite policy
       
   324          * @return ETrue if this is an internal composite policy
       
   325          */ 
       
   326         virtual TBool InternalPolicy() const = 0;
       
   327     };
       
   328 
       
   329 /**
       
   330  * An implementation for exterior composite view
       
   331  */
       
   332 NONSHARABLE_CLASS(CVPbkExternalCompositeViewPolicy) :
       
   333         public CBase,
       
   334         public MVPbkCompositeContactViewPolicy
       
   335     {
       
   336     public: // Construction and destruction
       
   337         static CVPbkExternalCompositeViewPolicy* NewL(
       
   338                 CVPbkCompositeContactView& aCompositeView,
       
   339                 RPointerArray<MVPbkContactViewObserver>& aObservers );
       
   340         ~CVPbkExternalCompositeViewPolicy();
       
   341         
       
   342     private: // From MVPbkCompositeContactViewPolicy
       
   343         void HandleViewEventsL( 
       
   344             CVPbkEventArrayItem::TViewEventType aEvent,
       
   345             MVPbkContactViewBase& aSubview,
       
   346             TInt aIndex, const 
       
   347             MVPbkContactLink& aContactLink );
       
   348         void Reset();
       
   349         TInt ContactCountL() const;
       
   350         TBool InternalPolicy() const;
       
   351     
       
   352     private: // Implementation
       
   353         CVPbkExternalCompositeViewPolicy(
       
   354             CVPbkCompositeContactView& aCompositeView,
       
   355             RPointerArray<MVPbkContactViewObserver>& aObservers );
       
   356         
       
   357     private: // Data
       
   358         /// Ref: The parent of this policy
       
   359         CVPbkCompositeContactView& iCompositeView;
       
   360         /// Ref: Array of observers
       
   361         RPointerArray<MVPbkContactViewObserver>& iObservers;
       
   362         /// Own: Event array for 'Contact added or removed' events
       
   363         RPointerArray<CVPbkEventArrayItem> iEventArray;
       
   364     };
       
   365 
       
   366 /**
       
   367  * An implementation for interior composite view
       
   368  */
       
   369 NONSHARABLE_CLASS(CVPbkInternalCompositeViewPolicy) :
       
   370         public CBase,
       
   371         public MVPbkCompositeContactViewPolicy
       
   372     {
       
   373     public: // Construction and destruction
       
   374         static CVPbkInternalCompositeViewPolicy* NewL(
       
   375                 CVPbkCompositeContactView& aCompositeView,
       
   376                 RPointerArray<MVPbkContactViewObserver>& aObservers );
       
   377         
       
   378     private: // From MVPbkCompositeContactViewPolicy
       
   379         void HandleViewEventsL( 
       
   380             CVPbkEventArrayItem::TViewEventType aEvent,
       
   381             MVPbkContactViewBase& aSubview,
       
   382             TInt aIndex, const 
       
   383             MVPbkContactLink& aContactLink );
       
   384         void Reset();
       
   385         TInt ContactCountL() const;
       
   386         TBool InternalPolicy() const;
       
   387     
       
   388     private: // Implementation
       
   389         CVPbkInternalCompositeViewPolicy(
       
   390             CVPbkCompositeContactView& aCompositeView,
       
   391             RPointerArray<MVPbkContactViewObserver>& aObservers );
       
   392         
       
   393     private: // Data
       
   394         /// Ref: The parent of this policy
       
   395         CVPbkCompositeContactView& iCompositeView;
       
   396         /// Ref: Array of observers
       
   397         RPointerArray<MVPbkContactViewObserver>& iObservers;
       
   398     };
       
   399 
       
   400 #endif // CVPBKCOMPOSITECONTACTVIEW_H
       
   401 
       
   402 // End of File