phonebookengines/VirtualPhonebook/VPbkSimStore/src/CContactLink.cpp
changeset 0 e686773b3f54
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:  Implements a contact link to sim contact
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CContactLink.h"
       
    22 
       
    23 #include "CContactStore.h"
       
    24 #include "CContact.h"
       
    25 #include "CViewContact.h"
       
    26 #include "CContactView.h"
       
    27 #include "CVPbkSimContact.h"
       
    28 
       
    29 #include <MVPbkContactStoreProperties.h>
       
    30 #include <s32mem.h>
       
    31 
       
    32 
       
    33 namespace VPbkSimStore {
       
    34 
       
    35 const TInt KBytesToWord( 4 );
       
    36 const TInt KBytesToFieldId( 4 );
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CContactLink::CContactLink
       
    42 // C++ default constructor can NOT contain any code, that
       
    43 // might leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CContactLink::CContactLink(CContactStore& aStore )
       
    47 :   iStore( aStore )
       
    48     {
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CContactLink::ConstructL
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CContactLink::ConstructL( TInt aSimIndex, TInt aFieldId )
       
    57     {
       
    58     iSimIndex = aSimIndex;
       
    59     iFieldId = aFieldId;
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CContactLink::ConstructL
       
    64 // Symbian 2nd phase constructor can leave.
       
    65 // -----------------------------------------------------------------------------
       
    66 //
       
    67 void CContactLink::ConstructL( RReadStream& aReadStream )
       
    68     {
       
    69     iSimIndex = aReadStream.ReadInt32L();
       
    70     iFieldId = aReadStream.ReadInt32L();
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CContactLink::NewLC
       
    75 // Two-phased constructor.
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CContactLink* CContactLink::NewLC( CContactStore& aStore, 
       
    79     TInt aSimIndex, TInt aFieldId )
       
    80     {
       
    81     CContactLink* self = new( ELeave ) CContactLink( aStore );
       
    82     CleanupStack::PushL( self );
       
    83     self->ConstructL( aSimIndex, aFieldId );
       
    84     return self;
       
    85     }
       
    86 
       
    87 // -----------------------------------------------------------------------------
       
    88 // CContactLink::NewLC
       
    89 // Two-phased constructor.
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 CContactLink* CContactLink::NewLC( CContactStore& aStore, 
       
    93     RReadStream& aReadStream )
       
    94     {
       
    95     CContactLink* self = new( ELeave ) CContactLink( aStore );
       
    96     CleanupStack::PushL( self );
       
    97     self->ConstructL( aReadStream );
       
    98     return self;
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CContactLink::IsValid
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 TBool CContactLink::IsValid( const MVPbkContactStore& aStore,
       
   106     const MVPbkContactLink& aLink )
       
   107     {
       
   108     return &aStore == &aLink.ContactStore();
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CContactLink::ContactStore
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 MVPbkContactStore& CContactLink::ContactStore() const
       
   116     {
       
   117     return iStore;
       
   118     }
       
   119   
       
   120 // -----------------------------------------------------------------------------
       
   121 // CContactLink::IsSame
       
   122 // -----------------------------------------------------------------------------
       
   123 //  
       
   124 TBool CContactLink::IsSame( const MVPbkContactLink& aOther ) const
       
   125     {
       
   126     TBool result = EFalse;
       
   127     if ( &ContactStore() == &aOther.ContactStore() )
       
   128         {
       
   129         const CContactLink& other = 
       
   130             static_cast<const CContactLink&>(aOther);
       
   131         result = ( other.SimIndex() == SimIndex() && other.FieldId() == FieldId() );
       
   132         }
       
   133     return result;
       
   134     }
       
   135     
       
   136 // -----------------------------------------------------------------------------
       
   137 // CContactLink::RefersTo
       
   138 // -----------------------------------------------------------------------------
       
   139 //    
       
   140 TBool CContactLink::RefersTo( const MVPbkBaseContact& aContact ) const
       
   141     {
       
   142     TBool result = EFalse;
       
   143     const CContact* contact = dynamic_cast<const CContact*>(&aContact);
       
   144     if ( contact )
       
   145         {
       
   146         if ( &ContactStore() == &contact->ParentStore() )
       
   147             {
       
   148             result = ( SimIndex() == contact->SimContact().SimIndex() );
       
   149             }
       
   150         }
       
   151     else 
       
   152         {
       
   153         const CViewContact* contact = dynamic_cast<const CViewContact*>(&aContact);
       
   154         if ( contact && (&ContactStore() == &contact->View().ContactStore()) )
       
   155             {
       
   156             result = ( SimIndex() == contact->SimIndex() );
       
   157             }
       
   158         }
       
   159     return result;
       
   160     }
       
   161 
       
   162 const MVPbkContactLinkPacking& CContactLink::Packing() const
       
   163     {
       
   164     return *this;
       
   165     }
       
   166     
       
   167 MVPbkContactLink* CContactLink::CloneLC() const
       
   168     {
       
   169     return CContactLink::NewLC( iStore, iSimIndex, iFieldId );
       
   170     }
       
   171 
       
   172 TInt CContactLink::InternalPackedSize() const
       
   173     {
       
   174     return ( KBytesToWord + KBytesToFieldId );                        
       
   175     }
       
   176 
       
   177 void CContactLink::PackInternalsL( RWriteStream& aStream ) const
       
   178     {
       
   179     aStream.WriteInt32L( iSimIndex ); // SIM index
       
   180     aStream.WriteInt32L( iFieldId ); // Field id
       
   181     }
       
   182 
       
   183 
       
   184 } // namespace VPbkSimStore
       
   185 
       
   186 //  End of File