|
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: A store specific field property array |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <CPbk2StoreSpecificFieldPropertyArray.h> |
|
22 |
|
23 // From Phonebook2 |
|
24 #include <CPbk2StoreProperty.h> |
|
25 #include <CPbk2StorePropertyArray.h> |
|
26 #include <MPbk2FieldProperty.h> |
|
27 |
|
28 // From Virtual Phonebook |
|
29 #include <MVPbkContactStore.h> |
|
30 #include <MVPbkContactStoreProperties.h> |
|
31 |
|
32 // Unnamed namespace for local definitions |
|
33 namespace |
|
34 { |
|
35 #ifdef _DEBUG |
|
36 enum TPanicCode |
|
37 { |
|
38 EPanic_At_OOB = 1 |
|
39 }; |
|
40 |
|
41 void Panic( TPanicCode aPanic ) |
|
42 { |
|
43 _LIT( KPanicCat, "CPbk2StoreSpecificFieldPropertyArray" ); |
|
44 User::Panic( KPanicCat(), aPanic ); |
|
45 } |
|
46 #endif // _DEBUG |
|
47 } |
|
48 |
|
49 // CONSTANTS |
|
50 |
|
51 // ============================ MEMBER FUNCTIONS =============================== |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CPbk2StoreSpecificFieldPropertyArray::CPbk2StoreSpecificFieldPropertyArray |
|
55 // C++ default constructor can NOT contain any code, that |
|
56 // might leave. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CPbk2StoreSpecificFieldPropertyArray::CPbk2StoreSpecificFieldPropertyArray( |
|
60 MPbk2FieldPropertyArray& aFieldProperties) |
|
61 : iFieldProperties(aFieldProperties) |
|
62 { |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CPbk2StoreSpecificFieldPropertyArray::ConstructL |
|
67 // Symbian 2nd phase constructor can leave. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CPbk2StoreSpecificFieldPropertyArray::ConstructL( |
|
71 CPbk2StorePropertyArray& aStoreProperties, |
|
72 const MVPbkFieldTypeList& aFieldTypes, |
|
73 const TVPbkContactStoreUriPtr& aStoreUri) |
|
74 { |
|
75 const CPbk2StoreProperty* prop = aStoreProperties.FindProperty(aStoreUri); |
|
76 if (prop) |
|
77 { |
|
78 iSpecificFieldProperties = |
|
79 prop->CreateStoreSpecificFieldPropertiesL(aFieldTypes); |
|
80 } |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CPbk2StoreSpecificFieldPropertyArray::NewL |
|
85 // Two-phased constructor. |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 EXPORT_C CPbk2StoreSpecificFieldPropertyArray* |
|
89 CPbk2StoreSpecificFieldPropertyArray::NewL( |
|
90 MPbk2FieldPropertyArray& aFieldProperties, |
|
91 CPbk2StorePropertyArray& aStoreProperties, |
|
92 const MVPbkFieldTypeList& aFieldTypes, |
|
93 MVPbkContactStore& aStore) |
|
94 { |
|
95 CPbk2StoreSpecificFieldPropertyArray* self = |
|
96 new( ELeave ) CPbk2StoreSpecificFieldPropertyArray(aFieldProperties); |
|
97 CleanupStack::PushL( self ); |
|
98 self->ConstructL( |
|
99 aStoreProperties, |
|
100 aFieldTypes, |
|
101 aStore.StoreProperties().Uri()); |
|
102 CleanupStack::Pop( self ); |
|
103 return self; |
|
104 } |
|
105 |
|
106 // Destructor |
|
107 CPbk2StoreSpecificFieldPropertyArray::~CPbk2StoreSpecificFieldPropertyArray() |
|
108 { |
|
109 delete iSpecificFieldProperties; |
|
110 } |
|
111 |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CPbk2StoreSpecificFieldPropertyArray::FindProperty |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 const MPbk2FieldProperty* CPbk2StoreSpecificFieldPropertyArray::FindProperty( |
|
118 const MVPbkFieldType& aFieldType) const |
|
119 { |
|
120 const MPbk2FieldProperty* prop = NULL; |
|
121 if (iSpecificFieldProperties) |
|
122 { |
|
123 // First looking from store specific properties. |
|
124 prop = iSpecificFieldProperties->FindProperty(aFieldType); |
|
125 } |
|
126 |
|
127 if (!prop) |
|
128 { |
|
129 // Not found from store specific propertis. Looking from base |
|
130 // properties. |
|
131 return iFieldProperties.FindProperty(aFieldType); |
|
132 } |
|
133 return prop; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CPbk2StoreSpecificFieldPropertyArray::Count |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 TInt CPbk2StoreSpecificFieldPropertyArray::Count() const |
|
141 { |
|
142 return iFieldProperties.Count(); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CPbk2StoreSpecificFieldPropertyArray::At |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 const MPbk2FieldProperty& CPbk2StoreSpecificFieldPropertyArray::At( |
|
150 TInt aIndex) const |
|
151 { |
|
152 __ASSERT_DEBUG( iFieldProperties.Count() > aIndex && |
|
153 aIndex >= 0, Panic( EPanic_At_OOB ) ); |
|
154 if ( !iSpecificFieldProperties ) |
|
155 { |
|
156 return iFieldProperties.At(aIndex); |
|
157 } |
|
158 else |
|
159 { |
|
160 const MPbk2FieldProperty& baseProp = iFieldProperties.At( aIndex ); |
|
161 return *FindProperty( baseProp.FieldType() ); |
|
162 } |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CPbk2StoreSpecificFieldPropertyArray::FieldPropertyArrayExtension |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 TAny* CPbk2StoreSpecificFieldPropertyArray::FieldPropertyArrayExtension( |
|
170 TUid aExtensionUid ) |
|
171 { |
|
172 if ( aExtensionUid == KMPbk2FieldPropertyArrayExtension2Uid ) |
|
173 { |
|
174 return static_cast<MPbk2FieldPropertyArray2*>( this ); |
|
175 } |
|
176 return NULL; |
|
177 } |
|
178 |
|
179 // ----------------------------------------------------------------------------- |
|
180 // CPbk2StoreSpecificFieldPropertyArray::FindProperty |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 const MPbk2FieldProperty* CPbk2StoreSpecificFieldPropertyArray::FindProperty( |
|
184 const MVPbkFieldType& aFieldType, |
|
185 const TDesC& aName ) const |
|
186 { |
|
187 const MPbk2FieldProperty* prop = NULL; |
|
188 if (iSpecificFieldProperties) |
|
189 { |
|
190 // First looking from store specific properties. |
|
191 MPbk2FieldPropertyArray2* ext = reinterpret_cast<MPbk2FieldPropertyArray2*>( |
|
192 iSpecificFieldProperties->FieldPropertyArrayExtension( |
|
193 KMPbk2FieldPropertyArrayExtension2Uid ) ); |
|
194 |
|
195 prop = ext->FindProperty(aFieldType, aName); |
|
196 } |
|
197 |
|
198 if (!prop) |
|
199 { |
|
200 // Not found from store specific propertis. Looking from base |
|
201 // properties. |
|
202 MPbk2FieldPropertyArray2* ext = reinterpret_cast<MPbk2FieldPropertyArray2*>( |
|
203 iFieldProperties.FieldPropertyArrayExtension( |
|
204 KMPbk2FieldPropertyArrayExtension2Uid ) ); |
|
205 |
|
206 prop = ext->FindProperty(aFieldType, aName); |
|
207 } |
|
208 return prop; |
|
209 } |
|
210 // End of File |