|
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: The virtual phonebook store field collection implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "TStoreContactFieldCollection.h" |
|
21 |
|
22 #include <MVPbkContactLink.h> |
|
23 #include <VPbkError.h> |
|
24 #include <e32base.h> |
|
25 #include <CVPbkSimContact.h> |
|
26 #include "TStoreContactField.h" |
|
27 #include "CContact.h" |
|
28 #include "CContactLink.h" |
|
29 |
|
30 namespace VPbkSimStore { |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // TStoreContactFieldCollection::TStoreContactFieldCollection |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 TStoreContactFieldCollection::TStoreContactFieldCollection() |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // TStoreContactFieldCollection::SetContact |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 void TStoreContactFieldCollection::SetContact( CContact& aParentContact, |
|
47 CVPbkSimContact& aSimContact ) |
|
48 { |
|
49 iCurrentField.SetParentContact( aParentContact ); |
|
50 iParentContact = &aParentContact; |
|
51 iSimFields = &aSimContact.FieldArray(); |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // TStoreContactFieldCollection::ParentContact |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 MVPbkBaseContact& TStoreContactFieldCollection::ParentContact() const |
|
59 { |
|
60 return *iParentContact; |
|
61 } |
|
62 |
|
63 // ----------------------------------------------------------------------------- |
|
64 // TStoreContactFieldCollection::FieldCount |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 TInt TStoreContactFieldCollection::FieldCount() const |
|
68 { |
|
69 return iSimFields->Count(); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // TStoreContactFieldCollection::FieldAt |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 const MVPbkStoreContactField& TStoreContactFieldCollection::FieldAt( |
|
77 TInt aIndex) const |
|
78 { |
|
79 iCurrentField.SetSimField( *(*iSimFields)[aIndex] ); |
|
80 return iCurrentField; |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // TStoreContactFieldCollection::FieldAt |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 MVPbkStoreContactField& TStoreContactFieldCollection::FieldAt(TInt aIndex) |
|
88 { |
|
89 iCurrentField.SetSimField( *(*iSimFields)[aIndex] ); |
|
90 return iCurrentField; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // TStoreContactFieldCollection::FieldAtLC |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 MVPbkStoreContactField* TStoreContactFieldCollection::FieldAtLC( |
|
98 TInt aIndex ) const |
|
99 { |
|
100 TStoreContactField* field = new( ELeave ) TStoreContactField; |
|
101 field->SetParentContact( *iParentContact ); |
|
102 field->SetSimField( *(*iSimFields)[aIndex] ); |
|
103 CleanupDeletePushL( field ); |
|
104 return field; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // TStoreContactFieldCollection::ParentStoreContact |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 MVPbkStoreContact& TStoreContactFieldCollection::ParentStoreContact() const |
|
112 { |
|
113 return *iParentContact; |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // TStoreContactFieldCollection::RetrieveField |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 MVPbkStoreContactField* TStoreContactFieldCollection::RetrieveField( |
|
121 const MVPbkContactLink& aContactLink) const |
|
122 { |
|
123 __ASSERT_ALWAYS(aContactLink.RefersTo(*iParentContact), |
|
124 VPbkError::Panic(VPbkError::EInvalidContactField)); |
|
125 |
|
126 MVPbkStoreContactField* result = NULL; |
|
127 |
|
128 if (&aContactLink.ContactStore() == &iParentContact->ContactStore()) |
|
129 { |
|
130 const CContactLink& link = static_cast<const CContactLink&>(aContactLink); |
|
131 TInt fieldIndex = link.FieldId(); |
|
132 if ( fieldIndex >= 0 && fieldIndex < iSimFields->Count()) |
|
133 { |
|
134 iCurrentField.SetSimField(*(*iSimFields)[fieldIndex]); |
|
135 result = &iCurrentField; |
|
136 } |
|
137 } |
|
138 |
|
139 return result; |
|
140 } |
|
141 } // namespace VPbkSimStore |
|
142 |