phonebookengines/VirtualPhonebook/VPbkSimStoreImpl/src/CSharedViewArray.cpp
changeset 0 e686773b3f54
child 26 0d28c1c5b6dd
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2007-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:  An array that manages shared views
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDES
       
    20 #include "CSharedViewArray.h"
       
    21 
       
    22 #include <CVPbkSimContactView.h>
       
    23 
       
    24 // FORWARD DECLARATIONS
       
    25 
       
    26 namespace VPbkSimStoreImpl {
       
    27 
       
    28 // CLASS DECLARATION
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CSharedViewArray::CSharedViewArray
       
    32 // C++ default constructor can NOT contain any code, that
       
    33 // might leave.
       
    34 // -----------------------------------------------------------------------------
       
    35 //
       
    36 CSharedViewArray::CSharedViewArray( 
       
    37         TViewDestructionPolicy aDestructionPolicy )
       
    38         :   iDestructionPolicy( aDestructionPolicy )
       
    39     {
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CSharedViewArray::NewL
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CSharedViewArray* CSharedViewArray::NewL( 
       
    47         TViewDestructionPolicy aDestructionPolicy )
       
    48     {
       
    49     return new (ELeave ) CSharedViewArray( aDestructionPolicy );
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CSharedViewArray::~CSharedViewArray
       
    54 // -----------------------------------------------------------------------------
       
    55 //    
       
    56 CSharedViewArray::~CSharedViewArray()
       
    57     {
       
    58     iSharedViews.ResetAndDestroy();
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CSharedViewArray::CreateNewHandleL
       
    63 // -----------------------------------------------------------------------------
       
    64 //        
       
    65 CViewHandle* CSharedViewArray::CreateNewHandleL(
       
    66         const RVPbkSimFieldTypeArray& aSortOrder,
       
    67         TVPbkSimViewConstructionPolicy aConstructionPolicy, 
       
    68         MVPbkSimCntStore& aParentStore, const TDesC& aViewName )
       
    69     {
       
    70     CSharedViewOwner* viewOwner = FindOwner( aViewName );
       
    71     
       
    72     if ( !viewOwner )
       
    73         {
       
    74         CVPbkSimContactView* sharedView = 
       
    75                 CVPbkSimContactView::NewLC( aSortOrder, aConstructionPolicy,
       
    76                 aParentStore, aViewName, NULL );
       
    77         viewOwner = new (ELeave ) CSharedViewOwner( *this, sharedView );
       
    78         CleanupStack::Pop( sharedView );
       
    79         CleanupStack::PushL( viewOwner );
       
    80         iSharedViews.AppendL( viewOwner );
       
    81         CleanupStack::Pop( viewOwner );
       
    82         }
       
    83     
       
    84     return viewOwner->CreateNewHandleL();
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CSharedViewArray::RemoveHandle
       
    89 // -----------------------------------------------------------------------------
       
    90 //        
       
    91 void CSharedViewArray::RemoveHandle( CViewHandle& aHandle )
       
    92     {
       
    93     CSharedViewOwner* viewOwner = FindOwner( aHandle.SharedView().Name() );
       
    94     if ( viewOwner )
       
    95         {
       
    96         viewOwner->RemoveHandle( aHandle );
       
    97         if ( iDestructionPolicy == EDestroyViewIfNoHandles &&
       
    98              !viewOwner->HasHandles() )
       
    99             {
       
   100             TInt index = iSharedViews.Find( viewOwner );
       
   101             delete iSharedViews[index];
       
   102             iSharedViews.Remove( index );
       
   103             }
       
   104         }
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CSharedViewArray::FindOwner
       
   109 // -----------------------------------------------------------------------------
       
   110 //        
       
   111 CSharedViewOwner* CSharedViewArray::FindOwner( const TDesC& aViewName )
       
   112     {
       
   113     CSharedViewOwner* viewOwner = NULL;
       
   114     const TInt count = iSharedViews.Count();
       
   115     for ( TInt i = 0; i < count && !viewOwner; ++i )
       
   116         {
       
   117         if ( iSharedViews[i]->View().Name().CompareC( aViewName ) == 0 )
       
   118             {
       
   119             viewOwner = iSharedViews[i];
       
   120             }
       
   121         }
       
   122     return viewOwner;
       
   123     }
       
   124     
       
   125 // -----------------------------------------------------------------------------
       
   126 // CViewHandle::CViewHandle
       
   127 // C++ default constructor can NOT contain any code, that
       
   128 // might leave.
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 CViewHandle::CViewHandle( CSharedViewArray& aSharedViewArray, 
       
   132         CVPbkSimContactView& aSharedView )
       
   133         :   iSharedViewArray( aSharedViewArray ),
       
   134             iSharedView( aSharedView )
       
   135     {
       
   136     }
       
   137     
       
   138 // -----------------------------------------------------------------------------
       
   139 // CViewHandle::~CViewHandle
       
   140 // -----------------------------------------------------------------------------
       
   141 //            
       
   142 CViewHandle::~CViewHandle()
       
   143     {
       
   144     iSharedViewArray.RemoveHandle( *this );
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CViewHandle::SharedView
       
   149 // -----------------------------------------------------------------------------
       
   150 //                
       
   151 CVPbkSimContactView& CViewHandle::SharedView()
       
   152     {
       
   153     return iSharedView;
       
   154     }
       
   155     
       
   156 // -----------------------------------------------------------------------------
       
   157 // CViewHandle::Name
       
   158 // -----------------------------------------------------------------------------
       
   159 //                
       
   160 const TDesC& CViewHandle::Name() const
       
   161     {
       
   162     return iSharedView.Name();
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // CViewHandle::ParentStore
       
   167 // -----------------------------------------------------------------------------
       
   168 //                    
       
   169 MVPbkSimCntStore& CViewHandle::ParentStore() const
       
   170     {
       
   171     return iSharedView.ParentStore();
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CViewHandle::OpenL
       
   176 // -----------------------------------------------------------------------------
       
   177 //                    
       
   178 void CViewHandle::OpenL( MVPbkSimViewObserver& aObserver )
       
   179     {
       
   180     iSharedView.OpenL( aObserver );
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CViewHandle::Close
       
   185 // -----------------------------------------------------------------------------
       
   186 //                        
       
   187 void CViewHandle::Close( MVPbkSimViewObserver& aObserver )
       
   188     {
       
   189     iSharedView.Close( aObserver );
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CViewHandle::CountL
       
   194 // -----------------------------------------------------------------------------
       
   195 //                            
       
   196 TInt CViewHandle::CountL() const
       
   197     {
       
   198     return iSharedView.CountL();
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // CViewHandle::ContactAtL
       
   203 // -----------------------------------------------------------------------------
       
   204 //                                
       
   205 MVPbkSimContact& CViewHandle::ContactAtL( TInt aIndex )
       
   206     {
       
   207     return iSharedView.ContactAtL( aIndex );
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CViewHandle::ChangeSortOrderL
       
   212 // -----------------------------------------------------------------------------
       
   213 //                                    
       
   214 void CViewHandle::ChangeSortOrderL( const RVPbkSimFieldTypeArray& aSortOrder )
       
   215     {
       
   216     iSharedView.ChangeSortOrderL( aSortOrder );
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CViewHandle::MapSimIndexToViewIndexL
       
   221 // -----------------------------------------------------------------------------
       
   222 //                                        
       
   223 TInt CViewHandle::MapSimIndexToViewIndexL( TInt aSimIndex )
       
   224     {
       
   225     return iSharedView.MapSimIndexToViewIndexL( aSimIndex );
       
   226     }
       
   227     
       
   228 // -----------------------------------------------------------------------------
       
   229 // CViewHandle::ContactMatchingPrefixL
       
   230 // -----------------------------------------------------------------------------
       
   231 //                                        
       
   232 MVPbkSimStoreOperation* CViewHandle::ContactMatchingPrefixL(
       
   233         const MDesCArray& aFindStrings, 
       
   234         MVPbkSimViewFindObserver& aObserver )
       
   235     {
       
   236     return iSharedView.ContactMatchingPrefixL( aFindStrings, aObserver );
       
   237     }
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CViewHandle::SortOrderL
       
   241 // -----------------------------------------------------------------------------
       
   242 //                                        
       
   243 const RVPbkSimFieldTypeArray& CViewHandle::SortOrderL() const
       
   244     {
       
   245     return iSharedView.SortOrderL();
       
   246     }
       
   247     
       
   248 // -----------------------------------------------------------------------------
       
   249 // CSharedViewOwner::CSharedViewOwner
       
   250 // C++ default constructor can NOT contain any code, that
       
   251 // might leave.
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 CSharedViewOwner::CSharedViewOwner( CSharedViewArray& aSharedViewArray,
       
   255         CVPbkSimContactView* aSharedView )
       
   256         :   iSharedViewArray( aSharedViewArray ),
       
   257             iSharedView( aSharedView )   
       
   258     {
       
   259     }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CSharedViewOwner::~CSharedViewOwner
       
   263 // -----------------------------------------------------------------------------
       
   264 //   
       
   265 CSharedViewOwner::~CSharedViewOwner()
       
   266     {
       
   267     iViewHandles.Close();
       
   268     delete iSharedView;
       
   269     }
       
   270 
       
   271 // -----------------------------------------------------------------------------
       
   272 // CSharedViewOwner::View
       
   273 // -----------------------------------------------------------------------------
       
   274 //   
       
   275 CVPbkSimContactView& CSharedViewOwner::View() const
       
   276     {
       
   277     return *iSharedView;
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CSharedViewOwner::CreateNewHandleL
       
   282 // -----------------------------------------------------------------------------
       
   283 //           
       
   284 CViewHandle* CSharedViewOwner::CreateNewHandleL()
       
   285     {
       
   286     CViewHandle* handle = 
       
   287             new( ELeave ) CViewHandle( iSharedViewArray, *iSharedView );
       
   288     CleanupStack::PushL( handle );
       
   289     iViewHandles.AppendL( handle );
       
   290     CleanupStack::Pop( handle );
       
   291     return handle;
       
   292     }
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CSharedViewOwner::RemoveHandle
       
   296 // -----------------------------------------------------------------------------
       
   297 //           
       
   298 void CSharedViewOwner::RemoveHandle( CViewHandle& aHandle )
       
   299     {
       
   300     TInt index = iViewHandles.Find( &aHandle );
       
   301     if ( index != KErrNotFound )
       
   302         {
       
   303         iViewHandles.Remove( index );
       
   304         }
       
   305     }
       
   306     
       
   307 // -----------------------------------------------------------------------------
       
   308 // CSharedViewOwner::HasHandles
       
   309 // -----------------------------------------------------------------------------
       
   310 //   
       
   311 TBool CSharedViewOwner::HasHandles() const
       
   312     {
       
   313     return iViewHandles.Count() > 0;
       
   314     }    
       
   315 } // namespace VPbkSimStoreImpl
       
   316             
       
   317 // End of File