phonebookengines/VirtualPhonebook/VPbkLdapStore/src/TStoreContactFieldCollection.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:  Contact field collection class implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDES
       
    20 #include "tstorecontactfieldcollection.h"
       
    21 #include "contact.h"
       
    22 #include "contactlink.h"
       
    23 #include "ldapcontact.h"
       
    24 #include "ldapcontactfield.h"
       
    25 #include <mvpbkcontactlink.h>
       
    26 // #include <vpbkerror.h>        // Virtual phonebook error handling
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // LDAP Store namespace
       
    30 // -----------------------------------------------------------------------------
       
    31 namespace LDAPStore {
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // TStoreContactFieldCollection::TStoreContactFieldCollection
       
    35 // C++ default constructor can NOT contain any code, that might leave.
       
    36 // -----------------------------------------------------------------------------
       
    37 //
       
    38 TStoreContactFieldCollection::TStoreContactFieldCollection()
       
    39     {
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 //                  TStoreContactFieldCollection public methods
       
    44 // -----------------------------------------------------------------------------
       
    45 // TStoreContactFieldCollection::SetContact
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void TStoreContactFieldCollection::SetContact(CContact& aContact,
       
    49                                               CLDAPContact& aLDAPContact)
       
    50     {
       
    51     iCurrentField.SetContact(aContact);
       
    52     iContact = &aContact;
       
    53     iFields  = &aLDAPContact.Fields();
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // TStoreContactFieldCollection::FieldPointer
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 const MVPbkStoreContactField* TStoreContactFieldCollection::FieldPointer() const
       
    61     {
       
    62     return &iCurrentField;
       
    63     }
       
    64 // -----------------------------------------------------------------------------
       
    65 //              MVPbkBaseContactFieldCollection implemetation
       
    66 // -----------------------------------------------------------------------------
       
    67 // TStoreContactFieldCollection::ParentContact
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 MVPbkBaseContact& TStoreContactFieldCollection::ParentContact() const
       
    71     {
       
    72     return *iContact;
       
    73     }
       
    74 // -----------------------------------------------------------------------------
       
    75 // TStoreContactFieldCollection::FieldCount
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 TInt TStoreContactFieldCollection::FieldCount() const
       
    79     {
       
    80     return iFields->Count();
       
    81     }
       
    82 // -----------------------------------------------------------------------------
       
    83 // TStoreContactFieldCollection::FieldAt
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 const MVPbkStoreContactField& TStoreContactFieldCollection::FieldAt(TInt aIndex) const
       
    87     {
       
    88     iCurrentField.SetField(*(*iFields)[aIndex]);
       
    89     return iCurrentField;
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 //              MVPbkBaseContactFieldCollection implementation
       
    94 // -----------------------------------------------------------------------------
       
    95 // TStoreContactFieldCollection::FieldAt
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 MVPbkStoreContactField& TStoreContactFieldCollection::FieldAt(TInt aIndex)
       
    99     {
       
   100     iCurrentField.SetField(*(*iFields)[aIndex]);
       
   101     return iCurrentField;
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // TStoreContactFieldCollection::FieldAtLC
       
   106 // -----------------------------------------------------------------------------
       
   107 //
       
   108 MVPbkStoreContactField* TStoreContactFieldCollection::FieldAtLC(TInt aIndex) const
       
   109     {
       
   110     TStoreContactField* field = new (ELeave) TStoreContactField;
       
   111     field->SetContact(*iContact);
       
   112     field->SetField(*(*iFields)[aIndex]);
       
   113     CleanupDeletePushL(field);
       
   114     return field;
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // TStoreContactFieldCollection::ParentStoreContact
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 MVPbkStoreContact& TStoreContactFieldCollection::ParentStoreContact() const
       
   122     {
       
   123     return *iContact;
       
   124     }
       
   125     
       
   126 // -----------------------------------------------------------------------------
       
   127 // TStoreContactFieldCollection::RetrieveField
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 MVPbkStoreContactField* TStoreContactFieldCollection::RetrieveField(
       
   131                         const MVPbkContactLink& aContactLink) const
       
   132     {
       
   133     /* Virtual phonebook error handling is not made public yet
       
   134     __ASSERT_ALWAYS(aContactLink.RefersTo(*iContact), 
       
   135                     VPbkError::Panic(VPbkError::EInvalidContactField));    
       
   136     */
       
   137 
       
   138     MVPbkStoreContactField* result = NULL;
       
   139     // From same store
       
   140     if (&aContactLink.ContactStore() == &iContact->ContactStore())
       
   141         {
       
   142         // Cast to our link
       
   143         const CContactLink& link = static_cast<const CContactLink&>(aContactLink);
       
   144         if (link.Type() >= 0)
       
   145             {
       
   146             const TInt count = FieldCount();
       
   147             for (TInt loop = 0;loop < count; loop++)
       
   148                 {
       
   149                 // Same type
       
   150                 if ((*iFields)[loop]->Type() == link.Type())
       
   151                     {
       
   152                     // Set current field
       
   153                     iCurrentField.SetField(*(*iFields)[loop]);
       
   154                     result = &iCurrentField;
       
   155                     break;
       
   156                     }
       
   157                 }
       
   158             }
       
   159         }
       
   160     return result;
       
   161     }
       
   162 
       
   163 } // End of namespace LDAPStore
       
   164 // -----------------------------------------------------------------------------
       
   165 //  End of File
       
   166 // -----------------------------------------------------------------------------