diff -r 5b6f26637ad3 -r f4a778e096c2 phonebookengines/VirtualPhonebook/VPbkLdapStore/src/ContactLink.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/phonebookengines/VirtualPhonebook/VPbkLdapStore/src/ContactLink.cpp Wed Sep 01 12:29:52 2010 +0100 @@ -0,0 +1,214 @@ +/* +* Copyright (c) 2005-2006 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: CContactLink - Contact link implementation +* +*/ + + +// INCLUDE FILES +#include "contactlink.h" +#include "contact.h" +#include "contactstore.h" +#include "contactview.h" +#include "viewcontact.h" +#include // Streaming + +// ----------------------------------------------------------------------------- +// LDAP Store namespace +// ----------------------------------------------------------------------------- +namespace LDAPStore { + +// ----------------------------------------------------------------------------- +// CContactLink::CContactLink +// C++ default constructor can NOT contain any code, that might leave. +// ----------------------------------------------------------------------------- +// +CContactLink::CContactLink(CContactStore& aStore,TInt aIndex,TInt aType) +: iStore(aStore), iIndex(aIndex), iType(aType) + { + // No implementation required + } +// ----------------------------------------------------------------------------- +// CContactLink::NewLC +// CContactLink two-phased constructor. +// ----------------------------------------------------------------------------- +// +CContactLink* CContactLink::NewLC(CContactStore& aStore,TInt aIndex,TInt aType) + { + CContactLink* self = new (ELeave) CContactLink(aStore,aIndex,aType); + CleanupStack::PushL(self); + return self; + } +// ----------------------------------------------------------------------------- +// CContactLink::NewL +// CContactLink two-phased constructor. +// ----------------------------------------------------------------------------- +// +CContactLink* CContactLink::NewL(CContactStore& aStore,TInt aIndex,TInt aType) + { + CContactLink* self = CContactLink::NewLC(aStore,aIndex,aType); + CleanupStack::Pop(self); + return self; + } +// ----------------------------------------------------------------------------- +// CContactLink::~CContactLink +// CContactLink Destructor +// ----------------------------------------------------------------------------- +// +CContactLink::~CContactLink() + { + } + +// ----------------------------------------------------------------------------- +// MVPbkContactLink implementation +// ----------------------------------------------------------------------------- +// CContactLink::Index +// Returns linked contact index. +// ----------------------------------------------------------------------------- +// +TInt CContactLink::Index() const + { + return iIndex; + } + +// ----------------------------------------------------------------------------- +// CContactLink::Type +// Returns linked contact field type id. +// ----------------------------------------------------------------------------- +// +TInt CContactLink::Type() const + { + return iIndex; + } + +// ----------------------------------------------------------------------------- +// CContactLink::Store +// Returns linked store. +// ----------------------------------------------------------------------------- +// +CContactStore& CContactLink::Store() const + { + return iStore; + } + +// ----------------------------------------------------------------------------- +// MVPbkContactLink implementation +// ----------------------------------------------------------------------------- +// CContactLink::ContactStore +// Returns linked store. +// ----------------------------------------------------------------------------- +// +MVPbkContactStore& CContactLink::ContactStore() const + { + return iStore; + } + +// ----------------------------------------------------------------------------- +// CContactLink::IsSame +// Returns true if this link refers to passed link contact. +// ----------------------------------------------------------------------------- +// +TBool CContactLink::IsSame(const MVPbkContactLink& aOther) const + { + TBool same = EFalse; + // From same store + if (&ContactStore() == &aOther.ContactStore()) + { + // Cast to contact link + const CContactLink& other = static_cast(aOther); + // Same index + same = (other.Index() == Index()); + } + return same; + } + +// ----------------------------------------------------------------------------- +// CContactLink::RefersTo +// Returns true if this link refers to the contact. +// ----------------------------------------------------------------------------- +// +TBool CContactLink::RefersTo(const MVPbkBaseContact& aContact) const + { + TBool same = EFalse; + // Contact + if (const CContact* contact = dynamic_cast(&aContact)) + { + // From same store + if (&ContactStore() == &contact->ParentStore()) + { + // Same index + same = (contact->Index() == Index()); + } + } + else + // View contact + if (const CViewContact* contact = dynamic_cast(&aContact)) + { + // From same store + if (&ContactStore() == &contact->ContactView().Store()) + { + // Same index + same = (contact->ContactIndex() == Index()); + } + } + return same; + } + +// ----------------------------------------------------------------------------- +// CContactLink::Packing +// Returns packing interface +// ----------------------------------------------------------------------------- +// +const MVPbkContactLinkPacking& CContactLink::Packing() const + { + return *this; + } + +// ----------------------------------------------------------------------------- +// CContactLink::CloneLC +// Clones this link +// ----------------------------------------------------------------------------- +// +MVPbkContactLink* CContactLink::CloneLC() const + { + return CContactLink::NewLC(iStore,iIndex,iType); + } + +// ----------------------------------------------------------------------------- +// MVPbkContactLinkPacking implementation +// ----------------------------------------------------------------------------- +// CContactLink::InternalPackedSize +// Returns the packed size of internals. +// ----------------------------------------------------------------------------- +// +TInt CContactLink::InternalPackedSize() const + { + // Integer index + integer type + return (4 + 4); + } +// ----------------------------------------------------------------------------- +// CContactLink::PackInternalsL +// Packs internals +// ----------------------------------------------------------------------------- +// +void CContactLink::PackInternalsL(RWriteStream& aStream) const + { + aStream.WriteInt32L(iIndex); + aStream.WriteInt32L(iType); + } + +} // End of namespace LDAPStore +// ----------------------------------------------------------------------------- +// End of File +// -----------------------------------------------------------------------------