phonebookengines/VirtualPhonebook/VPbkLdapStore/src/ContactLink.cpp
branchRCL_3
changeset 20 f4a778e096c2
parent 0 e686773b3f54
equal deleted inserted replaced
19:5b6f26637ad3 20:f4a778e096c2
       
     1 /*
       
     2 * Copyright (c) 2005-2006 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:  CContactLink - Contact link implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "contactlink.h"
       
    21 #include "contact.h"
       
    22 #include "contactstore.h"
       
    23 #include "contactview.h"
       
    24 #include "viewcontact.h"
       
    25 #include <s32strm.h>            // Streaming
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // LDAP Store namespace
       
    29 // -----------------------------------------------------------------------------
       
    30 namespace LDAPStore {
       
    31 
       
    32 // -----------------------------------------------------------------------------
       
    33 // CContactLink::CContactLink
       
    34 // C++ default constructor can NOT contain any code, that might leave.
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CContactLink::CContactLink(CContactStore& aStore,TInt aIndex,TInt aType)
       
    38 :   iStore(aStore), iIndex(aIndex), iType(aType)
       
    39     {
       
    40     // No implementation required
       
    41     }
       
    42 // -----------------------------------------------------------------------------
       
    43 // CContactLink::NewLC
       
    44 // CContactLink two-phased constructor.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CContactLink* CContactLink::NewLC(CContactStore& aStore,TInt aIndex,TInt aType)
       
    48     {
       
    49     CContactLink* self = new (ELeave) CContactLink(aStore,aIndex,aType);
       
    50     CleanupStack::PushL(self);
       
    51     return self;
       
    52     }
       
    53 // -----------------------------------------------------------------------------
       
    54 // CContactLink::NewL
       
    55 // CContactLink two-phased constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CContactLink* CContactLink::NewL(CContactStore& aStore,TInt aIndex,TInt aType)
       
    59     {
       
    60     CContactLink* self = CContactLink::NewLC(aStore,aIndex,aType);
       
    61     CleanupStack::Pop(self);
       
    62     return self;
       
    63     }
       
    64 // -----------------------------------------------------------------------------
       
    65 // CContactLink::~CContactLink
       
    66 // CContactLink Destructor
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CContactLink::~CContactLink()
       
    70     {
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 //                      MVPbkContactLink implementation
       
    75 // -----------------------------------------------------------------------------
       
    76 // CContactLink::Index
       
    77 // Returns linked contact index.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 TInt CContactLink::Index() const
       
    81     {
       
    82     return iIndex;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CContactLink::Type
       
    87 // Returns linked contact field type id.
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 TInt CContactLink::Type() const
       
    91     {
       
    92     return iIndex;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CContactLink::Store
       
    97 // Returns linked store.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 CContactStore& CContactLink::Store() const
       
   101     {
       
   102     return iStore;
       
   103     }
       
   104 
       
   105 // -----------------------------------------------------------------------------
       
   106 //                      MVPbkContactLink implementation
       
   107 // -----------------------------------------------------------------------------
       
   108 // CContactLink::ContactStore
       
   109 // Returns linked store.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 MVPbkContactStore& CContactLink::ContactStore() const
       
   113     {
       
   114     return iStore;
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CContactLink::IsSame
       
   119 // Returns true if this link refers to passed link contact.
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 TBool CContactLink::IsSame(const MVPbkContactLink& aOther) const
       
   123     {
       
   124     TBool same = EFalse;
       
   125     // From same store
       
   126     if (&ContactStore() == &aOther.ContactStore())
       
   127         {
       
   128         // Cast to contact link
       
   129         const CContactLink& other = static_cast<const CContactLink&>(aOther);
       
   130         // Same index
       
   131         same = (other.Index() == Index());
       
   132         }
       
   133     return same;
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CContactLink::RefersTo
       
   138 // Returns true if this link refers to the contact.
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 TBool CContactLink::RefersTo(const MVPbkBaseContact& aContact) const
       
   142     {
       
   143     TBool same = EFalse;
       
   144     // Contact
       
   145     if (const CContact* contact = dynamic_cast<const CContact*>(&aContact))
       
   146         {
       
   147         // From same store
       
   148         if (&ContactStore() == &contact->ParentStore())
       
   149             {
       
   150             // Same index
       
   151             same = (contact->Index() == Index());
       
   152             }
       
   153         }
       
   154     else
       
   155     // View contact
       
   156     if (const CViewContact* contact = dynamic_cast<const CViewContact*>(&aContact))
       
   157         {
       
   158         // From same store
       
   159         if (&ContactStore() == &contact->ContactView().Store())
       
   160             {
       
   161             // Same index
       
   162             same = (contact->ContactIndex() == Index());
       
   163             }
       
   164         }
       
   165     return same;
       
   166     }
       
   167 
       
   168 // -----------------------------------------------------------------------------
       
   169 // CContactLink::Packing
       
   170 // Returns packing interface
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 const MVPbkContactLinkPacking& CContactLink::Packing() const
       
   174     {
       
   175     return *this;
       
   176     }
       
   177     
       
   178 // -----------------------------------------------------------------------------
       
   179 // CContactLink::CloneLC
       
   180 // Clones this link
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 MVPbkContactLink* CContactLink::CloneLC() const
       
   184     {
       
   185     return CContactLink::NewLC(iStore,iIndex,iType);
       
   186     }
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 //                  MVPbkContactLinkPacking implementation
       
   190 // -----------------------------------------------------------------------------
       
   191 // CContactLink::InternalPackedSize
       
   192 // Returns the packed size of internals.
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 TInt CContactLink::InternalPackedSize() const
       
   196     {
       
   197     // Integer index + integer type
       
   198     return (4 + 4);
       
   199     }
       
   200 // -----------------------------------------------------------------------------
       
   201 // CContactLink::PackInternalsL
       
   202 // Packs internals
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void CContactLink::PackInternalsL(RWriteStream& aStream) const
       
   206     {
       
   207     aStream.WriteInt32L(iIndex);
       
   208     aStream.WriteInt32L(iType);
       
   209     }
       
   210 
       
   211 }  // End of namespace LDAPStore
       
   212 // -----------------------------------------------------------------------------
       
   213 //  End of File
       
   214 // -----------------------------------------------------------------------------