phonebookengines/VirtualPhonebook/VPbkEng/src/CVPbkCompositeContactView.cpp
branchRCL_3
changeset 6 e8e3147d53eb
parent 0 e686773b3f54
child 15 34879f5cfc63
equal deleted inserted replaced
5:81f8547efd4f 6:e8e3147d53eb
    34 #ifdef _DEBUG
    34 #ifdef _DEBUG
    35     enum TPanic
    35     enum TPanic
    36         {
    36         {
    37         EPanicLogic_CreateBookmarkLC = 3
    37         EPanicLogic_CreateBookmarkLC = 3
    38         };
    38         };
    39         
    39 
    40     void Panic(TPanic aPanic)
    40     void Panic(TPanic aPanic)
    41         {
    41         {
    42         _LIT(KPanicCat, "CVPbkCompositeContactView");
    42         _LIT(KPanicCat, "CVPbkCompositeContactView");
    43         User::Panic(KPanicCat, aPanic);
    43         User::Panic(KPanicCat, aPanic);
    44         }
    44         }
    54 // --------------------------------------------------------------------------
    54 // --------------------------------------------------------------------------
    55 // SendEventToObservers
    55 // SendEventToObservers
    56 // --------------------------------------------------------------------------
    56 // --------------------------------------------------------------------------
    57 //
    57 //
    58 template <class NotifyFunc>
    58 template <class NotifyFunc>
    59 void SendEventToObservers( MVPbkContactViewBase& aView, 
    59 void SendEventToObservers( MVPbkContactViewBase& aView,
    60         RPointerArray<MVPbkContactViewObserver>& aObservers,
    60         RPointerArray<MVPbkContactViewObserver>& aObservers,
    61         NotifyFunc aNotifyFunc )
    61         NotifyFunc aNotifyFunc )
    62     {
    62     {
    63     const TInt count = aObservers.Count();
    63     const TInt count = aObservers.Count();
    64     for (TInt i = count - 1; i >= 0; --i)
    64     for (TInt i = count - 1; i >= 0; --i)
    71 // --------------------------------------------------------------------------
    71 // --------------------------------------------------------------------------
    72 // SendEventToObservers
    72 // SendEventToObservers
    73 // --------------------------------------------------------------------------
    73 // --------------------------------------------------------------------------
    74 //
    74 //
    75 template <class NotifyFunc, class ParamType1, class ParamType2>
    75 template <class NotifyFunc, class ParamType1, class ParamType2>
    76 void SendEventToObservers( MVPbkContactViewBase& aView, 
    76 void SendEventToObservers( MVPbkContactViewBase& aView,
    77         RPointerArray<MVPbkContactViewObserver>& aObservers,
    77         RPointerArray<MVPbkContactViewObserver>& aObservers,
    78         NotifyFunc aNotifyFunc, ParamType1 aParam1, const ParamType2& aParam2 )
    78         NotifyFunc aNotifyFunc, ParamType1 aParam1, const ParamType2& aParam2 )
    79     {
    79     {
    80     const TInt count = aObservers.Count();
    80     const TInt count = aObservers.Count();
    81     for (TInt i = count - 1; i >= 0; --i)
    81     for (TInt i = count - 1; i >= 0; --i)
   109 // --------------------------------------------------------------------------
   109 // --------------------------------------------------------------------------
   110 // CVPbkCompositeContactView::~CVPbkCompositeContactView
   110 // CVPbkCompositeContactView::~CVPbkCompositeContactView
   111 // --------------------------------------------------------------------------
   111 // --------------------------------------------------------------------------
   112 //
   112 //
   113 CVPbkCompositeContactView::~CVPbkCompositeContactView()
   113 CVPbkCompositeContactView::~CVPbkCompositeContactView()
   114     {    
   114     {
   115     delete iCompositePolicy;
   115     delete iCompositePolicy;
   116     delete iSortOrder;
   116     delete iSortOrder;
   117     iSubViews.ResetAndDestroy();
   117     iSubViews.ResetAndDestroy();
   118     iObservers.Close();
   118     iObservers.Close();
   119     iContactMapping.Reset();
   119     iContactMapping.Reset();
   128     {
   128     {
   129     // Create sort order
   129     // Create sort order
   130     iSortOrder = CVPbkSortOrder::NewL(aSortOrder);
   130     iSortOrder = CVPbkSortOrder::NewL(aSortOrder);
   131 
   131 
   132     // Always apply internal policy
   132     // Always apply internal policy
   133     iCompositePolicy = 
   133     iCompositePolicy =
   134             CVPbkInternalCompositeViewPolicy::NewL( *this, iObservers );
   134             CVPbkInternalCompositeViewPolicy::NewL( *this, iObservers );
   135 
   135 
   136     // External policy's view event buffering mechanism does not work when
   136     // External policy's view event buffering mechanism does not work when
   137     // native contact views reside in a separate process, therefore we
   137     // native contact views reside in a separate process, therefore we
   138     // always apply internal policy.
   138     // always apply internal policy.
   152     CleanupStack::Pop(subViewData);
   152     CleanupStack::Pop(subViewData);
   153 
   153 
   154     subViewData->iView = aSubView;
   154     subViewData->iView = aSubView;
   155     subViewData->iViewId = aViewId;
   155     subViewData->iViewId = aViewId;
   156     }
   156     }
   157         
   157 
   158 // --------------------------------------------------------------------------
   158 // --------------------------------------------------------------------------
   159 // CVPbkCompositeContactView::ActualContactCountL
   159 // CVPbkCompositeContactView::ActualContactCountL
   160 // --------------------------------------------------------------------------
   160 // --------------------------------------------------------------------------
   161 //        
   161 //
   162 TInt CVPbkCompositeContactView::ActualContactCountL() const
   162 TInt CVPbkCompositeContactView::ActualContactCountL() const
   163     {
   163     {
   164     const TInt subViewCount = iSubViews.Count();
   164     const TInt subViewCount = iSubViews.Count();
   165     TInt contactCount = 0;
   165     TInt contactCount = 0;
   166     for (TInt i = 0; i < subViewCount; ++i)
   166     for (TInt i = 0; i < subViewCount; ++i)
   171                 {
   171                 {
   172                 // The view can be safely casted because
   172                 // The view can be safely casted because
   173                 // CVPbkCompositeContactView is VPbkEng internal
   173                 // CVPbkCompositeContactView is VPbkEng internal
   174                 // and EVPbkCompositeView type view is always
   174                 // and EVPbkCompositeView type view is always
   175                 // derived from CVPbkCompositeContactView.
   175                 // derived from CVPbkCompositeContactView.
   176                 contactCount += static_cast<CVPbkCompositeContactView*>( 
   176                 contactCount += static_cast<CVPbkCompositeContactView*>(
   177                     iSubViews[i]->iView )->ActualContactCountL();
   177                     iSubViews[i]->iView )->ActualContactCountL();
   178                 }
   178                 }
   179             else
   179             else
   180                 {
   180                 {
   181                 contactCount += iSubViews[i]->iView->ContactCountL();
   181                 contactCount += iSubViews[i]->iView->ContactCountL();
   186     }
   186     }
   187 
   187 
   188 // --------------------------------------------------------------------------
   188 // --------------------------------------------------------------------------
   189 // CVPbkCompositeContactView::ApplyInternalCompositePolicyL
   189 // CVPbkCompositeContactView::ApplyInternalCompositePolicyL
   190 // --------------------------------------------------------------------------
   190 // --------------------------------------------------------------------------
   191 //        
   191 //
   192 void CVPbkCompositeContactView::ApplyInternalCompositePolicyL()
   192 void CVPbkCompositeContactView::ApplyInternalCompositePolicyL()
   193     {
   193     {
   194     if ( !iCompositePolicy || !iCompositePolicy->InternalPolicy() )
   194     if ( !iCompositePolicy || !iCompositePolicy->InternalPolicy() )
   195         {
   195         {
   196         MVPbkCompositeContactViewPolicy* newPolicy = 
   196         MVPbkCompositeContactViewPolicy* newPolicy =
   197                 CVPbkInternalCompositeViewPolicy::NewL( *this, iObservers );
   197                 CVPbkInternalCompositeViewPolicy::NewL( *this, iObservers );
   198         delete iCompositePolicy;
   198         delete iCompositePolicy;
   199         iCompositePolicy = newPolicy;
   199         iCompositePolicy = newPolicy;
   200         }
   200         }
   201     }
   201     }
   202     
   202 
   203 // --------------------------------------------------------------------------
   203 // --------------------------------------------------------------------------
   204 // CVPbkCompositeContactView::Type
   204 // CVPbkCompositeContactView::Type
   205 // Returns view type.
   205 // Returns view type.
   206 // --------------------------------------------------------------------------
   206 // --------------------------------------------------------------------------
   207 //
   207 //
   228             {
   228             {
   229             iSubViews[i]->iState = CSubViewData::ENotKnown;
   229             iSubViews[i]->iState = CSubViewData::ENotKnown;
   230             iSubViews[i]->iView->ChangeSortOrderL(aSortOrder);
   230             iSubViews[i]->iView->ChangeSortOrderL(aSortOrder);
   231             }
   231             }
   232         }
   232         }
   233     
   233 
   234     // Create new sort order and take it in use
   234     // Create new sort order and take it in use
   235     MVPbkFieldTypeList* sortOrder = CVPbkSortOrder::NewL(aSortOrder);
   235     MVPbkFieldTypeList* sortOrder = CVPbkSortOrder::NewL(aSortOrder);
   236     delete iSortOrder;
   236     delete iSortOrder;
   237     iSortOrder = sortOrder;
   237     iSortOrder = sortOrder;
   238     }
   238     }
   328         {
   328         {
   329         // Check that the view is ready before using it.
   329         // Check that the view is ready before using it.
   330         TInt index = KErrNotFound;
   330         TInt index = KErrNotFound;
   331         if (iSubViews[i]->iState == CSubViewData::EReady)
   331         if (iSubViews[i]->iState == CSubViewData::EReady)
   332             {
   332             {
   333             index = iSubViews[i]->iView->IndexOfLinkL(aContactLink);        
   333             index = iSubViews[i]->iView->IndexOfLinkL(aContactLink);
   334             }        
   334             }
   335             
   335 
   336         if (index != KErrNotFound)
   336         if (index != KErrNotFound)
   337             {
   337             {
   338             // Establish contact mapping for view and contact index
   338             // Establish contact mapping for view and contact index
   339             TContactMapping mapping;
   339             TContactMapping mapping;
   340             mapping.iViewIndex = i;
   340             mapping.iViewIndex = i;
   359     if ( err != KErrNone && err != KErrAlreadyExists)
   359     if ( err != KErrNone && err != KErrAlreadyExists)
   360         {
   360         {
   361         User::Leave( err );
   361         User::Leave( err );
   362         }
   362         }
   363 
   363 
   364     TRAP(err, 
   364     TRAP(err,
   365         {
   365         {
   366         VPbkEngUtils::MAsyncCallback* notifyObserver =
   366         VPbkEngUtils::MAsyncCallback* notifyObserver =
   367             VPbkEngUtils::CreateAsyncCallbackLC(
   367             VPbkEngUtils::CreateAsyncCallbackLC(
   368                 *this, 
   368                 *this,
   369                 &CVPbkCompositeContactView::DoAddObserverL, 
   369                 &CVPbkCompositeContactView::DoAddObserverL,
   370                 &CVPbkCompositeContactView::AddObserverError, 
   370                 &CVPbkCompositeContactView::AddObserverError,
   371                 aObserver);
   371                 aObserver);
   372         iAsyncOperation.CallbackL(notifyObserver);
   372         iAsyncOperation.CallbackL(notifyObserver);
   373         CleanupStack::Pop(notifyObserver);
   373         CleanupStack::Pop(notifyObserver);
   374         });
   374         });
   375 
   375 
   408         {
   408         {
   409         result = iSubViews[i]->iView->MatchContactStore(aContactStoreUri);
   409         result = iSubViews[i]->iView->MatchContactStore(aContactStoreUri);
   410         }
   410         }
   411     return result;
   411     return result;
   412     }
   412     }
   413     
   413 
   414 // --------------------------------------------------------------------------
   414 // --------------------------------------------------------------------------
   415 // CVPbkCompositeContactView::MatchContactStoreDomain
   415 // CVPbkCompositeContactView::MatchContactStoreDomain
   416 // Check does any of the subviews match given contact store domain.
   416 // Check does any of the subviews match given contact store domain.
   417 // --------------------------------------------------------------------------
   417 // --------------------------------------------------------------------------
   418 //
   418 //
   436 // --------------------------------------------------------------------------
   436 // --------------------------------------------------------------------------
   437 //
   437 //
   438 MVPbkContactBookmark* CVPbkCompositeContactView::CreateBookmarkLC
   438 MVPbkContactBookmark* CVPbkCompositeContactView::CreateBookmarkLC
   439         (TInt aIndex) const
   439         (TInt aIndex) const
   440     {
   440     {
   441     __ASSERT_ALWAYS( aIndex >= 0, 
   441     __ASSERT_ALWAYS( aIndex >= 0,
   442         VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
   442         VPbkError::Panic( VPbkError::EInvalidContactIndex ) );
   443     __ASSERT_DEBUG(ContactCountL() > aIndex, 
   443     __ASSERT_DEBUG(ContactCountL() > aIndex,
   444             Panic(EPanicLogic_CreateBookmarkLC));
   444             Panic(EPanicLogic_CreateBookmarkLC));
   445 
   445 
   446     const TContactMapping& mapping = iContactMapping[aIndex];
   446     const TContactMapping& mapping = iContactMapping[aIndex];
   447     MVPbkContactViewBase* view = iSubViews[mapping.iViewIndex]->iView;
   447     MVPbkContactViewBase* view = iSubViews[mapping.iViewIndex]->iView;
   448     return view->CreateBookmarkLC( mapping.iContactIndex );
   448     return view->CreateBookmarkLC( mapping.iContactIndex );
   457         (const MVPbkContactBookmark& aContactBookmark) const
   457         (const MVPbkContactBookmark& aContactBookmark) const
   458     {
   458     {
   459     TIdentityRelation<TContactMapping> comparisonOperator(
   459     TIdentityRelation<TContactMapping> comparisonOperator(
   460         &CVPbkCompositeContactView::CompareMappings);
   460         &CVPbkCompositeContactView::CompareMappings);
   461     TInt result = KErrNotFound;
   461     TInt result = KErrNotFound;
   462     
   462 
   463     // Search the bookmark from all the subviews
   463     // Search the bookmark from all the subviews
   464     const TInt subViewCount = iSubViews.Count();
   464     const TInt subViewCount = iSubViews.Count();
   465     for (TInt i = 0; i < subViewCount; ++i)
   465     for (TInt i = 0; i < subViewCount; ++i)
   466         {
   466         {
   467         // Check that the view is ready before using it.
   467         // Check that the view is ready before using it.
   468         TInt index(KErrNotFound);
   468         TInt index(KErrNotFound);
   469         if (iSubViews[i]->iState == CSubViewData::EReady)
   469         if (iSubViews[i]->iState == CSubViewData::EReady)
   470             {
   470             {
   471             index = iSubViews[i]->iView->IndexOfBookmarkL(aContactBookmark);
   471             index = iSubViews[i]->iView->IndexOfBookmarkL(aContactBookmark);
   472             }
   472             }
   473             
   473 
   474         if (index != KErrNotFound)
   474         if (index != KErrNotFound)
   475             {
   475             {
   476             // Establish contact mapping for view and contact index
   476             // Establish contact mapping for view and contact index
   477             TContactMapping mapping;
   477             TContactMapping mapping;
   478             mapping.iViewIndex = i;
   478             mapping.iViewIndex = i;
   549         (MVPbkContactViewBase& aView, TInt aIndex,
   549         (MVPbkContactViewBase& aView, TInt aIndex,
   550         const MVPbkContactLink& aContactLink)
   550         const MVPbkContactLink& aContactLink)
   551     {
   551     {
   552     TInt compositeIndex = HandleContactAddition(aView, aIndex);
   552     TInt compositeIndex = HandleContactAddition(aView, aIndex);
   553 
   553 
   554     TRAPD( error, iCompositePolicy->HandleViewEventsL( 
   554     TRAPD( error, iCompositePolicy->HandleViewEventsL(
   555         CVPbkEventArrayItem::EAdded, aView, compositeIndex, aContactLink ) );
   555         CVPbkEventArrayItem::EAdded, aView, compositeIndex, aContactLink ) );
   556     if ( error != KErrNone )
   556     if ( error != KErrNone )
   557         {
   557         {
   558         // If error occurs reset policy
   558         // If error occurs reset policy
   559         iCompositePolicy->Reset();
   559         iCompositePolicy->Reset();
   569         (MVPbkContactViewBase& aView, TInt aIndex,
   569         (MVPbkContactViewBase& aView, TInt aIndex,
   570         const MVPbkContactLink& aContactLink)
   570         const MVPbkContactLink& aContactLink)
   571     {
   571     {
   572     TInt compositeIndex( KErrNotFound );
   572     TInt compositeIndex( KErrNotFound );
   573     compositeIndex = HandleContactRemoval(aView, aIndex);
   573     compositeIndex = HandleContactRemoval(aView, aIndex);
   574     TRAPD( error, iCompositePolicy->HandleViewEventsL( 
   574     TRAPD( error, iCompositePolicy->HandleViewEventsL(
   575         CVPbkEventArrayItem::ERemoved, aView, compositeIndex, 
   575         CVPbkEventArrayItem::ERemoved, aView, compositeIndex,
   576             aContactLink ) );
   576             aContactLink ) );
   577     if ( error != KErrNone )
   577     if ( error != KErrNone )
   578         {
   578         {
   579         // If error occurs reset policy
   579         // If error occurs reset policy
   580         iCompositePolicy->Reset();
   580         iCompositePolicy->Reset();
   591     {
   591     {
   592     SendViewErrorEvent( aError, aErrorNotified );
   592     SendViewErrorEvent( aError, aErrorNotified );
   593     }
   593     }
   594 
   594 
   595 // --------------------------------------------------------------------------
   595 // --------------------------------------------------------------------------
       
   596 // CVPbkCompositeContactView::ContactViewObserverExtension
       
   597 // --------------------------------------------------------------------------
       
   598 //
       
   599 TAny* CVPbkCompositeContactView::ContactViewObserverExtension( TUid aExtensionUid )
       
   600     {
       
   601     if( aExtensionUid == KVPbkContactViewObserverExtension2Uid )
       
   602         {
       
   603         return static_cast<MVPbkContactViewObserverExtension*>( this );
       
   604         }
       
   605     return NULL;
       
   606     }
       
   607 
       
   608 // --------------------------------------------------------------------------
       
   609 // CVPbkCompositeContactView::FilteredContactRemovedFromView
       
   610 // --------------------------------------------------------------------------
       
   611 //
       
   612 void CVPbkCompositeContactView::FilteredContactRemovedFromView(
       
   613 		MVPbkContactViewBase& aView )
       
   614     {
       
   615     const TInt count = iObservers.Count();
       
   616 
       
   617     for( TInt i = 0; i < count; i++ )
       
   618         {
       
   619         MVPbkContactViewObserver* observer = iObservers[i];
       
   620 
       
   621         TAny* extension = observer->ContactViewObserverExtension(
       
   622               KVPbkContactViewObserverExtension2Uid );
       
   623 
       
   624         if( extension )
       
   625             {
       
   626             MVPbkContactViewObserverExtension* contactViewExtension =
       
   627                   static_cast<MVPbkContactViewObserverExtension*>( extension );
       
   628 
       
   629             if( contactViewExtension )
       
   630                 {
       
   631                 contactViewExtension->FilteredContactRemovedFromView( aView );
       
   632                 }
       
   633             }
       
   634         }
       
   635     }
       
   636 
       
   637 // --------------------------------------------------------------------------
   596 // CVPbkCompositeContactView::UpdateFilterL
   638 // CVPbkCompositeContactView::UpdateFilterL
   597 // --------------------------------------------------------------------------
   639 // --------------------------------------------------------------------------
   598 //    
   640 //
   599 void CVPbkCompositeContactView::UpdateFilterL( 
   641 void CVPbkCompositeContactView::UpdateFilterL(
   600         const MDesCArray& aFindWords,
   642         const MDesCArray& aFindWords,
   601         const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts )
   643         const MVPbkContactBookmarkCollection* aAlwaysIncludedContacts )
   602     {
   644     {
   603     const TInt count = iSubViews.Count();
   645     const TInt count = iSubViews.Count();
   604     for( TInt i = 0; i < count; ++i )
   646     for( TInt i = 0; i < count; ++i )
   605         {
   647         {
   606         MVPbkContactViewFiltering* filtering = 
   648         MVPbkContactViewFiltering* filtering =
   607             iSubViews[i]->iView->ViewFiltering();
   649             iSubViews[i]->iView->ViewFiltering();
   608         // Check if the subview supports filtering.
   650         // Check if the subview supports filtering.
   609         if ( filtering )
   651         if ( filtering )
   610             {
   652             {
   611             // Filtering supported
   653             // Filtering supported
   616             // time a subview notifies composite. This is not wanted because
   658             // time a subview notifies composite. This is not wanted because
   617             // client must get only one notification after update.
   659             // client must get only one notification after update.
   618             // On the other hand a client can still use this view while it's
   660             // On the other hand a client can still use this view while it's
   619             // updating itself so in that point of view the composite is not
   661             // updating itself so in that point of view the composite is not
   620             // in unknown state but in update state.
   662             // in unknown state but in update state.
   621             iSubViews[i]->iState = CSubViewData::ENotKnown;            
   663             iSubViews[i]->iState = CSubViewData::ENotKnown;
   622             }
   664             }
   623         }
   665         }
   624     }
   666     }
   625 
   667 
   626 TInt CVPbkCompositeContactView::ChildViewCount() const
   668 TInt CVPbkCompositeContactView::ChildViewCount() const
   637     {
   679     {
   638     MVPbkContactViewBase* view = NULL;
   680     MVPbkContactViewBase* view = NULL;
   639     const TInt count = iSubViews.Count();
   681     const TInt count = iSubViews.Count();
   640     for (TInt i = 0; i < count; ++i)
   682     for (TInt i = 0; i < count; ++i)
   641         {
   683         {
   642         view=iSubViews[i]->iView; 
   684         view=iSubViews[i]->iView;
   643         if (iSubViews[i]->iViewId == aId)
   685         if (iSubViews[i]->iViewId == aId)
   644            {
   686            {
   645            return view;
   687            return view;
   646            }
   688            }
   647         }
   689         }
   653      return iViewId;
   695      return iViewId;
   654     }
   696     }
   655 // --------------------------------------------------------------------------
   697 // --------------------------------------------------------------------------
   656 // CVPbkCompositeContactView::SendViewReadyEvent
   698 // CVPbkCompositeContactView::SendViewReadyEvent
   657 // --------------------------------------------------------------------------
   699 // --------------------------------------------------------------------------
   658 //         
   700 //
   659 void CVPbkCompositeContactView::SendViewReadyEvent()
   701 void CVPbkCompositeContactView::SendViewReadyEvent()
   660     {
   702     {
   661     VPBK_DEBUG_PRINT( VPBK_DEBUG_STRING(
   703     VPBK_DEBUG_PRINT( VPBK_DEBUG_STRING(
   662         "CVPbkCompositeContactView::SendViewReadyEvent(0x%x)"), this );
   704         "CVPbkCompositeContactView::SendViewReadyEvent(0x%x)"), this );
   663     // Cancel operation to avoid unnecessary event sending in DoAddObserverL
   705     // Cancel operation to avoid unnecessary event sending in DoAddObserverL
   667     }
   709     }
   668 
   710 
   669 // --------------------------------------------------------------------------
   711 // --------------------------------------------------------------------------
   670 // CVPbkCompositeContactView::SendViewUnavailableEvent
   712 // CVPbkCompositeContactView::SendViewUnavailableEvent
   671 // --------------------------------------------------------------------------
   713 // --------------------------------------------------------------------------
   672 //        
   714 //
   673 void CVPbkCompositeContactView::SendViewUnavailableEvent()
   715 void CVPbkCompositeContactView::SendViewUnavailableEvent()
   674     {
   716     {
   675     VPBK_DEBUG_PRINT( VPBK_DEBUG_STRING(
   717     VPBK_DEBUG_PRINT( VPBK_DEBUG_STRING(
   676         "CVPbkCompositeContactView::SendViewUnavailableEvent(0x%x)"), this );
   718         "CVPbkCompositeContactView::SendViewUnavailableEvent(0x%x)"), this );
   677     // Cancel operation to avoid unnecessary event sending in DoAddObserverL
   719     // Cancel operation to avoid unnecessary event sending in DoAddObserverL
   682 
   724 
   683 // --------------------------------------------------------------------------
   725 // --------------------------------------------------------------------------
   684 // CVPbkCompositeContactView::SendViewErrorEvent
   726 // CVPbkCompositeContactView::SendViewErrorEvent
   685 // --------------------------------------------------------------------------
   727 // --------------------------------------------------------------------------
   686 //
   728 //
   687 void CVPbkCompositeContactView::SendViewErrorEvent( TInt aError, 
   729 void CVPbkCompositeContactView::SendViewErrorEvent( TInt aError,
   688         TBool aErrorNotified )
   730         TBool aErrorNotified )
   689     {
   731     {
   690     SendEventToObservers(*this, iObservers, 
   732     SendEventToObservers(*this, iObservers,
   691         &MVPbkContactViewObserver::ContactViewError, aError, aErrorNotified);
   733         &MVPbkContactViewObserver::ContactViewError, aError, aErrorNotified);
   692     }
   734     }
   693     
   735 
   694 // --------------------------------------------------------------------------
   736 // --------------------------------------------------------------------------
   695 // CVPbkCompositeContactView::CompareMappings
   737 // CVPbkCompositeContactView::CompareMappings
   696 // --------------------------------------------------------------------------
   738 // --------------------------------------------------------------------------
   697 //
   739 //
   698 TBool CVPbkCompositeContactView::CompareMappings
   740 TBool CVPbkCompositeContactView::CompareMappings
   715     }
   757     }
   716 
   758 
   717 // --------------------------------------------------------------------------
   759 // --------------------------------------------------------------------------
   718 // CVPbkCompositeContactView::CompositePolicy
   760 // CVPbkCompositeContactView::CompositePolicy
   719 // --------------------------------------------------------------------------
   761 // --------------------------------------------------------------------------
   720 //        
   762 //
   721 MVPbkCompositeContactViewPolicy& 
   763 MVPbkCompositeContactViewPolicy&
   722         CVPbkCompositeContactView::CompositePolicy() const
   764         CVPbkCompositeContactView::CompositePolicy() const
   723     {
   765     {
   724     return *iCompositePolicy;
   766     return *iCompositePolicy;
   725     }
   767     }
   726 
   768 
   786     }
   828     }
   787 
   829 
   788 // --------------------------------------------------------------------------
   830 // --------------------------------------------------------------------------
   789 // CVPbkCompositeContactView::ResetContactMapping
   831 // CVPbkCompositeContactView::ResetContactMapping
   790 // --------------------------------------------------------------------------
   832 // --------------------------------------------------------------------------
   791 //    
   833 //
   792 void CVPbkCompositeContactView::ResetContactMapping()
   834 void CVPbkCompositeContactView::ResetContactMapping()
   793     {
   835     {
   794     iContactMapping.Reset();
   836     iContactMapping.Reset();
   795     }
   837     }
   796 
   838 
   797 // --------------------------------------------------------------------------
   839 // --------------------------------------------------------------------------
   798 // CVPbkCompositeContactView::RemoveContactMappingsFromView
   840 // CVPbkCompositeContactView::RemoveContactMappingsFromView
   799 // --------------------------------------------------------------------------
   841 // --------------------------------------------------------------------------
   800 //
   842 //
   801 void CVPbkCompositeContactView::RemoveContactMappingsFromView( 
   843 void CVPbkCompositeContactView::RemoveContactMappingsFromView(
   802         MVPbkContactViewBase& aView )
   844         MVPbkContactViewBase& aView )
   803     {
   845     {
   804     TInt subviewIndex = FindSubViewIndex( aView );
   846     TInt subviewIndex = FindSubViewIndex( aView );
   805     if ( subviewIndex != KErrNotFound )
   847     if ( subviewIndex != KErrNotFound )
   806         {
   848         {
   817 
   859 
   818 // --------------------------------------------------------------------------
   860 // --------------------------------------------------------------------------
   819 // CVPbkCompositeContactView::HandleContactViewReadyL
   861 // CVPbkCompositeContactView::HandleContactViewReadyL
   820 // --------------------------------------------------------------------------
   862 // --------------------------------------------------------------------------
   821 //
   863 //
   822 void CVPbkCompositeContactView::HandleContactViewReadyL( 
   864 void CVPbkCompositeContactView::HandleContactViewReadyL(
   823         MVPbkContactViewBase& aView )
   865         MVPbkContactViewBase& aView )
   824     {
   866     {
   825     VPBK_DEBUG_PRINT( VPBK_DEBUG_STRING(
   867     VPBK_DEBUG_PRINT( VPBK_DEBUG_STRING(
   826         "CVPbkCompositeContactView::HandleContactViewReadyL(0x%x)"), this );
   868         "CVPbkCompositeContactView::HandleContactViewReadyL(0x%x)"), this );
   827     
   869 
   828     // Find matching subview and set its state to ready
   870     // Find matching subview and set its state to ready
   829     TInt subViewIndex = FindSubViewIndex(aView);
   871     TInt subViewIndex = FindSubViewIndex(aView);
   830     if (subViewIndex != KErrNotFound)
   872     if (subViewIndex != KErrNotFound)
   831         {
   873         {
   832         iSubViews[subViewIndex]->iState = CSubViewData::EReady;
   874         iSubViews[subViewIndex]->iState = CSubViewData::EReady;
   833         }
   875         }
   834 
   876 
   835     // Check that composite's sort order up to date with subviews.
   877     // Check that composite's sort order up to date with subviews.
   836     UpdateSortOrderL();
   878     UpdateSortOrderL();
   837     
   879 
   838     // If composite is ready, build view mapping and notify observers
   880     // If composite is ready, build view mapping and notify observers
   839     if ( IsCompositeReady() )
   881     if ( IsCompositeReady() )
   840         {
   882         {
   841         VPBK_PROFILE_START(VPbkProfile::ECompositeContactViewMapping);
   883         VPBK_PROFILE_START(VPbkProfile::ECompositeContactViewMapping);
   842         DoBuildContactMappingL();
   884         DoBuildContactMappingL();
   843         VPBK_PROFILE_END(VPbkProfile::ECompositeContactViewMapping);
   885         VPBK_PROFILE_END(VPbkProfile::ECompositeContactViewMapping);
   844         SendViewReadyEvent();
   886         SendViewReadyEvent();
   845         }    
   887         }
   846     }
   888     }
   847 
   889 
   848 // --------------------------------------------------------------------------
   890 // --------------------------------------------------------------------------
   849 // CVPbkCompositeContactView::HandleContactViewUnavailableL
   891 // CVPbkCompositeContactView::HandleContactViewUnavailableL
   850 // --------------------------------------------------------------------------
   892 // --------------------------------------------------------------------------
   851 //
   893 //
   852 void CVPbkCompositeContactView::HandleContactViewUnavailableL( 
   894 void CVPbkCompositeContactView::HandleContactViewUnavailableL(
   853         MVPbkContactViewBase& aView )
   895         MVPbkContactViewBase& aView )
   854     {
   896     {
   855     VPBK_DEBUG_PRINT( VPBK_DEBUG_STRING(
   897     VPBK_DEBUG_PRINT( VPBK_DEBUG_STRING(
   856         "CVPbkCompositeContactView::ContactViewUnavailable(0x%x)"), this );
   898         "CVPbkCompositeContactView::ContactViewUnavailable(0x%x)"), this );
   857     
   899 
   858     // Find matching subview and set its state
   900     // Find matching subview and set its state
   859     TInt subViewIndex = FindSubViewIndex(aView);
   901     TInt subViewIndex = FindSubViewIndex(aView);
   860     if (subViewIndex != KErrNotFound)
   902     if (subViewIndex != KErrNotFound)
   861         {
   903         {
   862         iSubViews[subViewIndex]->iState = CSubViewData::EUnavailable;
   904         iSubViews[subViewIndex]->iState = CSubViewData::EUnavailable;
   879             SendViewUnavailableEvent();
   921             SendViewUnavailableEvent();
   880             }
   922             }
   881         else
   923         else
   882             {
   924             {
   883             // Composite is still under construction.
   925             // Composite is still under construction.
   884             
   926 
   885             // Dont't send event here because the state of the composite is
   927             // Dont't send event here because the state of the composite is
   886             // not yet known and sending event can cause problems for client
   928             // not yet known and sending event can cause problems for client
   887             // e.g unwanted changes in the UI state.
   929             // e.g unwanted changes in the UI state.
   888             RemoveContactMappingsFromView( aView );
   930             RemoveContactMappingsFromView( aView );
   889             }
   931             }
   890         }
   932         }
   891     }
   933     }
   892     
   934 
   893 // --------------------------------------------------------------------------
   935 // --------------------------------------------------------------------------
   894 // CVPbkCompositeContactView::CVPbkCompositeContactView
   936 // CVPbkCompositeContactView::CVPbkCompositeContactView
   895 // --------------------------------------------------------------------------
   937 // --------------------------------------------------------------------------
   896 //
   938 //
   897 TInt CVPbkCompositeContactView::HandleContactRemoval
   939 TInt CVPbkCompositeContactView::HandleContactRemoval
   898         ( MVPbkContactViewBase& aView, TInt aIndex )
   940         ( MVPbkContactViewBase& aView, TInt aIndex )
   899     {
   941     {
   900     TInt index = KErrNotFound;
   942     TInt index = KErrNotFound;
   901     
   943 
   902     // Find correct subview
   944     // Find correct subview
   903     TInt subViewIndex = FindSubViewIndex( aView );
   945     TInt subViewIndex = FindSubViewIndex( aView );
   904     if ( subViewIndex != KErrNotFound )
   946     if ( subViewIndex != KErrNotFound )
   905         {
   947         {
   906         TIdentityRelation<TContactMapping> comparisonOperator
   948         TIdentityRelation<TContactMapping> comparisonOperator
   909         TContactMapping mapping;
   951         TContactMapping mapping;
   910         mapping.iViewIndex = subViewIndex;
   952         mapping.iViewIndex = subViewIndex;
   911         mapping.iContactIndex = aIndex;
   953         mapping.iContactIndex = aIndex;
   912         // Find the composite index by comparing the two mappings
   954         // Find the composite index by comparing the two mappings
   913         index = iContactMapping.Find( mapping, comparisonOperator );
   955         index = iContactMapping.Find( mapping, comparisonOperator );
   914         
   956 
   915         if ( index > KErrNotFound )
   957         if ( index > KErrNotFound )
   916             {            
   958             {
   917             // Loop through the rest of the contacts of the subview
   959             // Loop through the rest of the contacts of the subview
   918             // and modify their global contact mapping information
   960             // and modify their global contact mapping information
   919             for (TInt i = index; i < iContactMapping.Count(); ++i)
   961             for (TInt i = index; i < iContactMapping.Count(); ++i)
   920                 {
   962                 {
   921                 if (iContactMapping[i].iViewIndex == subViewIndex)
   963                 if (iContactMapping[i].iViewIndex == subViewIndex)
   934             DoBuildContactMappingL();
   976             DoBuildContactMappingL();
   935             }
   977             }
   936         }
   978         }
   937     return index;
   979     return index;
   938     }
   980     }
   939         
   981 
   940 // --------------------------------------------------------------------------
   982 // --------------------------------------------------------------------------
   941 // CVPbkCompositeContactView::HandleContactAddition
   983 // CVPbkCompositeContactView::HandleContactAddition
   942 // --------------------------------------------------------------------------
   984 // --------------------------------------------------------------------------
   943 //
   985 //
   944 TInt CVPbkCompositeContactView::HandleContactAddition
   986 TInt CVPbkCompositeContactView::HandleContactAddition
   945         (MVPbkContactViewBase& aView, TInt aIndex)
   987         (MVPbkContactViewBase& aView, TInt aIndex)
   946     {
   988     {
   947     TInt index = KErrNotFound;
   989     TInt index = KErrNotFound;
   948     
   990 
   949     // Find correct subview
   991     // Find correct subview
   950     TInt subViewIndex = FindSubViewIndex(aView);
   992     TInt subViewIndex = FindSubViewIndex(aView);
   951     if (subViewIndex != KErrNotFound)
   993     if (subViewIndex != KErrNotFound)
   952         {
   994         {
   953         TRAPD( err, index = DoHandleContactAdditionL
   995         TRAPD( err, index = DoHandleContactAdditionL
   954             ( subViewIndex, aIndex ) );
   996             ( subViewIndex, aIndex ) );
   955         if (err != KErrNone)
   997         if (err != KErrNone)
   956             {
   998             {
   957             index = err;
   999             index = err;
   958             }
  1000             }
   959         else 
  1001         else
   960         	{
  1002         	{
   961         	// We have to fix the indexes of all the succeeding
  1003         	// We have to fix the indexes of all the succeeding
   962             // contacts in the view where the contact addition took place
  1004             // contacts in the view where the contact addition took place
   963             for ( TInt i = index + 1; i < iContactMapping.Count(); ++i )
  1005             for ( TInt i = index + 1; i < iContactMapping.Count(); ++i )
   964                 {
  1006                 {
   969                 }
  1011                 }
   970         	}
  1012         	}
   971         }
  1013         }
   972     return index;
  1014     return index;
   973     }
  1015     }
   974     
  1016 
   975 // --------------------------------------------------------------------------
  1017 // --------------------------------------------------------------------------
   976 // CVPbkCompositeContactView::DoAddObserverL
  1018 // CVPbkCompositeContactView::DoAddObserverL
   977 // Notifies composite view readiness to observer.
  1019 // Notifies composite view readiness to observer.
   978 // --------------------------------------------------------------------------
  1020 // --------------------------------------------------------------------------
   979 //
  1021 //
   984     // View is considered to be ready if all subviews are ready (iIsReady)
  1026     // View is considered to be ready if all subviews are ready (iIsReady)
   985     // or if there are no subviews
  1027     // or if there are no subviews
   986     if ( iObservers.FindInAddressOrder( &aObserver ) != KErrNotFound )
  1028     if ( iObservers.FindInAddressOrder( &aObserver ) != KErrNotFound )
   987         {
  1029         {
   988         if( IsCompositeReady() )
  1030         if( IsCompositeReady() )
   989             {            
  1031             {
   990             // If this view is ready and there was no error tell it to the observer            
  1032             // If this view is ready and there was no error tell it to the observer
   991             aObserver.ContactViewReady(*this);            
  1033             aObserver.ContactViewReady(*this);
   992             }
  1034             }
   993         else if ( AllSubViewsKnown() )
  1035         else if ( AllSubViewsKnown() )
   994             {
  1036             {
   995             // All subviews are known but the composite is not ready ->
  1037             // All subviews are known but the composite is not ready ->
   996             // view is unavailable.
  1038             // view is unavailable.
  1021 // --------------------------------------------------------------------------
  1063 // --------------------------------------------------------------------------
  1022 //
  1064 //
  1023 void CVPbkCompositeContactView::UpdateSortOrderL()
  1065 void CVPbkCompositeContactView::UpdateSortOrderL()
  1024     {
  1066     {
  1025     const MVPbkFieldTypeList* sortOrder = NULL;
  1067     const MVPbkFieldTypeList* sortOrder = NULL;
  1026     
  1068 
  1027     // Inspect the sort order of subviews. If all ready subviews have
  1069     // Inspect the sort order of subviews. If all ready subviews have
  1028     // same sort order then update composite's sort order.
  1070     // same sort order then update composite's sort order.
  1029     // This is done because subviews can be shared views whose sort order
  1071     // This is done because subviews can be shared views whose sort order
  1030     // is not changed to client's sort order when a new handle is created.
  1072     // is not changed to client's sort order when a new handle is created.
  1031     TBool subViewsHaveSameOrder = ETrue;
  1073     TBool subViewsHaveSameOrder = ETrue;
  1032     const TInt count = iSubViews.Count();
  1074     const TInt count = iSubViews.Count();
  1033     for ( TInt i = 0; i < count && subViewsHaveSameOrder; ++i )
  1075     for ( TInt i = 0; i < count && subViewsHaveSameOrder; ++i )
  1034         {
  1076         {
  1035         if ( iSubViews[i]->iState == CSubViewData::EReady )
  1077         if ( iSubViews[i]->iState == CSubViewData::EReady )
  1036             {
  1078             {
  1037             const MVPbkFieldTypeList& curViewsOrder = 
  1079             const MVPbkFieldTypeList& curViewsOrder =
  1038                     iSubViews[i]->iView->SortOrder();
  1080                     iSubViews[i]->iView->SortOrder();
  1039             if ( sortOrder )
  1081             if ( sortOrder )
  1040                 {
  1082                 {
  1041                 subViewsHaveSameOrder = 
  1083                 subViewsHaveSameOrder =
  1042                     VPbkFieldTypeList::IsSame( *sortOrder, curViewsOrder );
  1084                     VPbkFieldTypeList::IsSame( *sortOrder, curViewsOrder );
  1043                 }
  1085                 }
  1044             sortOrder = &curViewsOrder;
  1086             sortOrder = &curViewsOrder;
  1045             }
  1087             }
  1046         }
  1088         }
  1047         
  1089 
  1048     if ( subViewsHaveSameOrder && sortOrder && 
  1090     if ( subViewsHaveSameOrder && sortOrder &&
  1049          !VPbkFieldTypeList::IsSame( *sortOrder, *iSortOrder ) )
  1091          !VPbkFieldTypeList::IsSame( *sortOrder, *iSortOrder ) )
  1050         {
  1092         {
  1051         CVPbkSortOrder* newOrder = CVPbkSortOrder::NewL( *sortOrder );
  1093         CVPbkSortOrder* newOrder = CVPbkSortOrder::NewL( *sortOrder );
  1052         delete iSortOrder;
  1094         delete iSortOrder;
  1053         iSortOrder = newOrder;
  1095         iSortOrder = newOrder;
  1054         }
  1096         }
  1055     }
  1097     }
  1056     
  1098 
  1057 void CVPbkCompositeContactView::SetViewId(TInt aViewId)
  1099 void CVPbkCompositeContactView::SetViewId(TInt aViewId)
  1058     {
  1100     {
  1059     iViewId = aViewId;
  1101     iViewId = aViewId;
  1060     }   
  1102     }
  1061 // --------------------------------------------------------------------------
  1103 // --------------------------------------------------------------------------
  1062 // CVPbkExternalCompositeViewPolicy::CVPbkExternalCompositeViewPolicy
  1104 // CVPbkExternalCompositeViewPolicy::CVPbkExternalCompositeViewPolicy
  1063 // --------------------------------------------------------------------------
  1105 // --------------------------------------------------------------------------
  1064 //
  1106 //
  1065 CVPbkExternalCompositeViewPolicy::CVPbkExternalCompositeViewPolicy( 
  1107 CVPbkExternalCompositeViewPolicy::CVPbkExternalCompositeViewPolicy(
  1066         CVPbkCompositeContactView& aCompositeView,
  1108         CVPbkCompositeContactView& aCompositeView,
  1067         RPointerArray<MVPbkContactViewObserver>& aObservers )
  1109         RPointerArray<MVPbkContactViewObserver>& aObservers )
  1068         :   iCompositeView( aCompositeView ),
  1110         :   iCompositeView( aCompositeView ),
  1069             iObservers( aObservers )
  1111             iObservers( aObservers )
  1070     {
  1112     {
  1071     }
  1113     }
  1072     
  1114 
  1073 // --------------------------------------------------------------------------
  1115 // --------------------------------------------------------------------------
  1074 // CVPbkExternalCompositeViewPolicy::NewL
  1116 // CVPbkExternalCompositeViewPolicy::NewL
  1075 // --------------------------------------------------------------------------
  1117 // --------------------------------------------------------------------------
  1076 //
  1118 //
  1077 CVPbkExternalCompositeViewPolicy* CVPbkExternalCompositeViewPolicy::NewL(
  1119 CVPbkExternalCompositeViewPolicy* CVPbkExternalCompositeViewPolicy::NewL(
  1078         CVPbkCompositeContactView& aCompositeView,
  1120         CVPbkCompositeContactView& aCompositeView,
  1079         RPointerArray<MVPbkContactViewObserver>& aObservers )
  1121         RPointerArray<MVPbkContactViewObserver>& aObservers )
  1080     {
  1122     {
  1081     CVPbkExternalCompositeViewPolicy* self = 
  1123     CVPbkExternalCompositeViewPolicy* self =
  1082         new ( ELeave ) CVPbkExternalCompositeViewPolicy( aCompositeView, 
  1124         new ( ELeave ) CVPbkExternalCompositeViewPolicy( aCompositeView,
  1083             aObservers );
  1125             aObservers );
  1084     return self;
  1126     return self;
  1085     }
  1127     }
  1086 
  1128 
  1087 // --------------------------------------------------------------------------
  1129 // --------------------------------------------------------------------------
  1088 // CVPbkExternalCompositeViewPolicy::~CVPbkExternalCompositeViewPolicy
  1130 // CVPbkExternalCompositeViewPolicy::~CVPbkExternalCompositeViewPolicy
  1089 // --------------------------------------------------------------------------
  1131 // --------------------------------------------------------------------------
  1090 //    
  1132 //
  1091 CVPbkExternalCompositeViewPolicy::~CVPbkExternalCompositeViewPolicy()
  1133 CVPbkExternalCompositeViewPolicy::~CVPbkExternalCompositeViewPolicy()
  1092     {
  1134     {
  1093     iEventArray.ResetAndDestroy();
  1135     iEventArray.ResetAndDestroy();
  1094     }
  1136     }
  1095 
  1137 
  1096 // --------------------------------------------------------------------------
  1138 // --------------------------------------------------------------------------
  1097 // CVPbkExternalCompositeViewPolicy::HandleViewEventsL
  1139 // CVPbkExternalCompositeViewPolicy::HandleViewEventsL
  1098 // --------------------------------------------------------------------------
  1140 // --------------------------------------------------------------------------
  1099 //    
  1141 //
  1100 void CVPbkExternalCompositeViewPolicy::HandleViewEventsL( 
  1142 void CVPbkExternalCompositeViewPolicy::HandleViewEventsL(
  1101         CVPbkEventArrayItem::TViewEventType aEvent,
  1143         CVPbkEventArrayItem::TViewEventType aEvent,
  1102         MVPbkContactViewBase& /*aSubview*/,
  1144         MVPbkContactViewBase& /*aSubview*/,
  1103         TInt aIndex, const 
  1145         TInt aIndex, const
  1104         MVPbkContactLink& aContactLink )
  1146         MVPbkContactLink& aContactLink )
  1105     {        
  1147     {
  1106     // Append all view events to proper event array.
  1148     // Append all view events to proper event array.
  1107     CVPbkEventArrayItem* item = 
  1149     CVPbkEventArrayItem* item =
  1108         CVPbkEventArrayItem::NewLC( aIndex, aContactLink, aEvent );
  1150         CVPbkEventArrayItem::NewLC( aIndex, aContactLink, aEvent );
  1109             
  1151 
  1110     iEventArray.AppendL( item );
  1152     iEventArray.AppendL( item );
  1111     CleanupStack::Pop(); // item
  1153     CleanupStack::Pop(); // item
  1112     
  1154 
  1113     // Check if the composite is up to date. Note that if the underlying
  1155     // Check if the composite is up to date. Note that if the underlying
  1114     // native store view resides in a separate process or thread,
  1156     // native store view resides in a separate process or thread,
  1115     // this check may "accidentally" pass whilst the native view is still
  1157     // this check may "accidentally" pass whilst the native view is still
  1116     // updating itself. This means that the composite might fall out of sync
  1158     // updating itself. This means that the composite might fall out of sync
  1117     // anytime after this check and it will then mean severe problems to the
  1159     // anytime after this check and it will then mean severe problems to the
  1119     // be zero, as the sync check is implemented in
  1161     // be zero, as the sync check is implemented in
  1120     // CVPbkExternalCompositeViewPolicy::ContactCountL too.
  1162     // CVPbkExternalCompositeViewPolicy::ContactCountL too.
  1121     // The count of zero might be in severe contradiction with the
  1163     // The count of zero might be in severe contradiction with the
  1122     // view events the client just received.
  1164     // view events the client just received.
  1123     // If the native view resides in the  same process, there are no risks.
  1165     // If the native view resides in the  same process, there are no risks.
  1124     if (iCompositeView.CompositeContactCountL() == 
  1166     if (iCompositeView.CompositeContactCountL() ==
  1125             iCompositeView.ActualContactCountL() )
  1167             iCompositeView.ActualContactCountL() )
  1126         {
  1168         {
  1127         // Composite mapping is valid according to contact counts. Flush
  1169         // Composite mapping is valid according to contact counts. Flush
  1128         // the event cache.
  1170         // the event cache.
  1129         TInt eventCount( iEventArray.Count() );
  1171         TInt eventCount( iEventArray.Count() );
  1130                           
  1172 
  1131         for( TInt i = 0; i < eventCount; ++i )
  1173         for( TInt i = 0; i < eventCount; ++i )
  1132             {
  1174             {
  1133             if ( iEventArray[ i ]->Event() == CVPbkEventArrayItem::ERemoved )
  1175             if ( iEventArray[ i ]->Event() == CVPbkEventArrayItem::ERemoved )
  1134                 {
  1176                 {
  1135                 SendEventToObservers( iCompositeView, iObservers,
  1177                 SendEventToObservers( iCompositeView, iObservers,
  1136                     &MVPbkContactViewObserver::ContactRemovedFromView,
  1178                     &MVPbkContactViewObserver::ContactRemovedFromView,
  1137                     iEventArray[ i ]->Index(), 
  1179                     iEventArray[ i ]->Index(),
  1138                     *iEventArray[ i ]->Link() ); 
  1180                     *iEventArray[ i ]->Link() );
  1139                 }
  1181                 }
  1140             else
  1182             else
  1141                 {
  1183                 {
  1142                 SendEventToObservers( iCompositeView, iObservers,
  1184                 SendEventToObservers( iCompositeView, iObservers,
  1143                     &MVPbkContactViewObserver::ContactAddedToView,
  1185                     &MVPbkContactViewObserver::ContactAddedToView,
  1144                     iEventArray[ i ]->Index(), 
  1186                     iEventArray[ i ]->Index(),
  1145                     *iEventArray[ i ]->Link() );                                                
  1187                     *iEventArray[ i ]->Link() );
  1146                 }            
  1188                 }
  1147             }                   
  1189             }
  1148         iEventArray.ResetAndDestroy();
  1190         iEventArray.ResetAndDestroy();
  1149         }
  1191         }
  1150     }
  1192     }
  1151 
  1193 
  1152 // --------------------------------------------------------------------------
  1194 // --------------------------------------------------------------------------
  1153 // CVPbkExternalCompositeViewPolicy::Reset
  1195 // CVPbkExternalCompositeViewPolicy::Reset
  1154 // --------------------------------------------------------------------------
  1196 // --------------------------------------------------------------------------
  1155 //    
  1197 //
  1156 void CVPbkExternalCompositeViewPolicy::Reset()
  1198 void CVPbkExternalCompositeViewPolicy::Reset()
  1157     {
  1199     {
  1158     iEventArray.ResetAndDestroy();
  1200     iEventArray.ResetAndDestroy();
  1159     }
  1201     }
  1160 
  1202 
  1161 // --------------------------------------------------------------------------
  1203 // --------------------------------------------------------------------------
  1162 // CVPbkExternalCompositeViewPolicy::ContactCountL
  1204 // CVPbkExternalCompositeViewPolicy::ContactCountL
  1163 // --------------------------------------------------------------------------
  1205 // --------------------------------------------------------------------------
  1164 //    
  1206 //
  1165 TInt CVPbkExternalCompositeViewPolicy::ContactCountL() const
  1207 TInt CVPbkExternalCompositeViewPolicy::ContactCountL() const
  1166     {
  1208     {
  1167     TInt compositeCount = iCompositeView.CompositeContactCountL();
  1209     TInt compositeCount = iCompositeView.CompositeContactCountL();
  1168     
  1210 
  1169     if ( compositeCount != iCompositeView.ActualContactCountL() )
  1211     if ( compositeCount != iCompositeView.ActualContactCountL() )
  1170         {
  1212         {
  1171         // If composite count is different as the contact count in subviews
  1213         // If composite count is different as the contact count in subviews
  1172         // it means that composite hasn't got all view events yet and its
  1214         // it means that composite hasn't got all view events yet and its
  1173         // contact mapping is not in valid state. It's too heavy to build
  1215         // contact mapping is not in valid state. It's too heavy to build
  1179     }
  1221     }
  1180 
  1222 
  1181 // --------------------------------------------------------------------------
  1223 // --------------------------------------------------------------------------
  1182 // CVPbkExternalCompositeViewPolicy::InternalPolicy
  1224 // CVPbkExternalCompositeViewPolicy::InternalPolicy
  1183 // --------------------------------------------------------------------------
  1225 // --------------------------------------------------------------------------
  1184 //    
  1226 //
  1185 TBool CVPbkExternalCompositeViewPolicy::InternalPolicy() const
  1227 TBool CVPbkExternalCompositeViewPolicy::InternalPolicy() const
  1186     {
  1228     {
  1187     return EFalse;
  1229     return EFalse;
  1188     }
  1230     }
  1189 
  1231 
  1190 // --------------------------------------------------------------------------
  1232 // --------------------------------------------------------------------------
  1191 // CVPbkInternalCompositeViewPolicy::CVPbkInternalCompositeViewPolicy
  1233 // CVPbkInternalCompositeViewPolicy::CVPbkInternalCompositeViewPolicy
  1192 // --------------------------------------------------------------------------
  1234 // --------------------------------------------------------------------------
  1193 //
  1235 //
  1194 CVPbkInternalCompositeViewPolicy::CVPbkInternalCompositeViewPolicy( 
  1236 CVPbkInternalCompositeViewPolicy::CVPbkInternalCompositeViewPolicy(
  1195         CVPbkCompositeContactView& aCompositeView,
  1237         CVPbkCompositeContactView& aCompositeView,
  1196         RPointerArray<MVPbkContactViewObserver>& aObservers )
  1238         RPointerArray<MVPbkContactViewObserver>& aObservers )
  1197         :   iCompositeView( aCompositeView ),
  1239         :   iCompositeView( aCompositeView ),
  1198             iObservers( aObservers )
  1240             iObservers( aObservers )
  1199     {
  1241     {
  1200     }
  1242     }
  1201     
  1243 
  1202 // --------------------------------------------------------------------------
  1244 // --------------------------------------------------------------------------
  1203 // CVPbkInternalCompositeViewPolicy::NewL
  1245 // CVPbkInternalCompositeViewPolicy::NewL
  1204 // --------------------------------------------------------------------------
  1246 // --------------------------------------------------------------------------
  1205 //
  1247 //
  1206 CVPbkInternalCompositeViewPolicy* CVPbkInternalCompositeViewPolicy::NewL(
  1248 CVPbkInternalCompositeViewPolicy* CVPbkInternalCompositeViewPolicy::NewL(
  1207         CVPbkCompositeContactView& aCompositeView,
  1249         CVPbkCompositeContactView& aCompositeView,
  1208         RPointerArray<MVPbkContactViewObserver>& aObservers )
  1250         RPointerArray<MVPbkContactViewObserver>& aObservers )
  1209     {
  1251     {
  1210     CVPbkInternalCompositeViewPolicy* self = 
  1252     CVPbkInternalCompositeViewPolicy* self =
  1211         new ( ELeave ) CVPbkInternalCompositeViewPolicy( aCompositeView, 
  1253         new ( ELeave ) CVPbkInternalCompositeViewPolicy( aCompositeView,
  1212             aObservers );
  1254             aObservers );
  1213     return self;
  1255     return self;
  1214     }
  1256     }
  1215 
  1257 
  1216 // --------------------------------------------------------------------------
  1258 // --------------------------------------------------------------------------
  1217 // CVPbkInternalCompositeViewPolicy::HandleViewEventsL
  1259 // CVPbkInternalCompositeViewPolicy::HandleViewEventsL
  1218 // --------------------------------------------------------------------------
  1260 // --------------------------------------------------------------------------
  1219 //
  1261 //
  1220 void CVPbkInternalCompositeViewPolicy::HandleViewEventsL( 
  1262 void CVPbkInternalCompositeViewPolicy::HandleViewEventsL(
  1221         CVPbkEventArrayItem::TViewEventType aEvent,
  1263         CVPbkEventArrayItem::TViewEventType aEvent,
  1222         MVPbkContactViewBase& /*aSubview*/,
  1264         MVPbkContactViewBase& /*aSubview*/,
  1223         TInt aIndex, const 
  1265         TInt aIndex, const
  1224         MVPbkContactLink& aContactLink )
  1266         MVPbkContactLink& aContactLink )
  1225     {
  1267     {
  1226     if ( aEvent == CVPbkEventArrayItem::ERemoved )
  1268     if ( aEvent == CVPbkEventArrayItem::ERemoved )
  1227         {
  1269         {
  1228         SendEventToObservers( iCompositeView, iObservers,
  1270         SendEventToObservers( iCompositeView, iObservers,
  1229             &MVPbkContactViewObserver::ContactRemovedFromView,
  1271             &MVPbkContactViewObserver::ContactRemovedFromView,
  1230             aIndex, 
  1272             aIndex,
  1231             aContactLink ); 
  1273             aContactLink );
  1232         }
  1274         }
  1233     else
  1275     else
  1234         {
  1276         {
  1235         SendEventToObservers( iCompositeView, iObservers,
  1277         SendEventToObservers( iCompositeView, iObservers,
  1236             &MVPbkContactViewObserver::ContactAddedToView,
  1278             &MVPbkContactViewObserver::ContactAddedToView,
  1237             aIndex, 
  1279             aIndex,
  1238             aContactLink ); 
  1280             aContactLink );
  1239         }            
  1281         }
  1240     }
  1282     }
  1241 
  1283 
  1242 // --------------------------------------------------------------------------
  1284 // --------------------------------------------------------------------------
  1243 // CVPbkInternalCompositeViewPolicy::Reset
  1285 // CVPbkInternalCompositeViewPolicy::Reset
  1244 // --------------------------------------------------------------------------
  1286 // --------------------------------------------------------------------------
  1245 //    
  1287 //
  1246 void CVPbkInternalCompositeViewPolicy::Reset()
  1288 void CVPbkInternalCompositeViewPolicy::Reset()
  1247     {
  1289     {
  1248     // No cached data to reset
  1290     // No cached data to reset
  1249     }
  1291     }
  1250     
  1292 
  1251 // --------------------------------------------------------------------------
  1293 // --------------------------------------------------------------------------
  1252 // CVPbkInternalCompositeViewPolicy::ContactCountL
  1294 // CVPbkInternalCompositeViewPolicy::ContactCountL
  1253 // --------------------------------------------------------------------------
  1295 // --------------------------------------------------------------------------
  1254 //    
  1296 //
  1255 TInt CVPbkInternalCompositeViewPolicy::ContactCountL() const
  1297 TInt CVPbkInternalCompositeViewPolicy::ContactCountL() const
  1256     {
  1298     {
  1257     return iCompositeView.CompositeContactCountL();
  1299     return iCompositeView.CompositeContactCountL();
  1258     }
  1300     }
  1259 
  1301 
  1260 // --------------------------------------------------------------------------
  1302 // --------------------------------------------------------------------------
  1261 // CVPbkInternalCompositeViewPolicy::InternalPolicy
  1303 // CVPbkInternalCompositeViewPolicy::InternalPolicy
  1262 // --------------------------------------------------------------------------
  1304 // --------------------------------------------------------------------------
  1263 //    
  1305 //
  1264 TBool CVPbkInternalCompositeViewPolicy::InternalPolicy() const
  1306 TBool CVPbkInternalCompositeViewPolicy::InternalPolicy() const
  1265     {
  1307     {
  1266     return ETrue;
  1308     return ETrue;
  1267     }
  1309     }
  1268     
  1310 
  1269 // End of File
  1311 // End of File