|
1 /* |
|
2 * Copyright (c) 2005-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: VPbk store contact analyzer. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "TVPbkStoreContactAnalyzer.h" |
|
20 |
|
21 // Virtual Phonebook |
|
22 #include <CVPbkContactManager.h> |
|
23 #include <CVPbkFieldTypeSelector.h> |
|
24 #include <MVPbkStoreContactFieldCollection.h> |
|
25 #include <MVPbkStoreContact.h> |
|
26 #include <MVPbkContactStore.h> |
|
27 #include <MVPbkFieldType.h> |
|
28 #include <MVPbkContactStoreProperties.h> |
|
29 #include <VPbkUtils.h> |
|
30 |
|
31 // System includes |
|
32 #include <barsread.h> |
|
33 #include <coemain.h> |
|
34 |
|
35 // non-class function declarations |
|
36 template<typename T> TInt t_HasFieldL( T aSelector, |
|
37 TInt aStartIndex, |
|
38 const MVPbkStoreContact* aContact, |
|
39 const MVPbkStoreContact* aClassContact, |
|
40 const CVPbkContactManager& aClassContactManager ); |
|
41 |
|
42 template<typename T> TBool t_IsFieldTypeSupportedL( T aSelector, |
|
43 const MVPbkStoreContact* aContact, |
|
44 const MVPbkStoreContact* aClassContact, |
|
45 const CVPbkContactManager& aClassContactManager ); |
|
46 |
|
47 template<typename T> TBool t_IsFieldTypeIncludedL( |
|
48 const MVPbkFieldType& aFieldType, |
|
49 T aSelector, |
|
50 const CVPbkContactManager& aClassContactManager ); |
|
51 |
|
52 template<typename T> TBool t_IsFieldTypeIncludedL( |
|
53 const MVPbkBaseContactField& aField, |
|
54 T aSelector, |
|
55 const CVPbkContactManager& aClassContactManager ); |
|
56 |
|
57 CVPbkFieldTypeSelector* CreateSelectorLC( |
|
58 VPbkFieldTypeSelectorFactory::TVPbkFieldTypeSelector aType, |
|
59 const CVPbkContactManager& aContactManager ); |
|
60 |
|
61 CVPbkFieldTypeSelector* CreateSelectorLC( |
|
62 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aType, |
|
63 const CVPbkContactManager& aContactManager ); |
|
64 |
|
65 TBool IsFieldTypeIncluded |
|
66 ( const MVPbkFieldTypeList& aFieldTypes, |
|
67 const MVPbkFieldTypeSelector& aFieldTypeSelector ); |
|
68 |
|
69 TInt IsFieldIncluded |
|
70 (const MVPbkBaseContactFieldCollection& aFields, |
|
71 TInt aStartIndex, |
|
72 const MVPbkContactFieldSelector& aFieldTypeSelector); |
|
73 |
|
74 |
|
75 // -------------------------------------------------------------------------- |
|
76 // TVPbkStoreContactAnalyzer::TVPbkStoreContactAnalyzer |
|
77 // -------------------------------------------------------------------------- |
|
78 // |
|
79 EXPORT_C TVPbkStoreContactAnalyzer::TVPbkStoreContactAnalyzer |
|
80 ( const CVPbkContactManager& aContactManager, |
|
81 const MVPbkStoreContact* aContact ) : |
|
82 iContactManager( aContactManager ), |
|
83 iContact( aContact ) |
|
84 { |
|
85 } |
|
86 |
|
87 // -------------------------------------------------------------------------- |
|
88 // TVPbkStoreContactAnalyzer::HasFieldL |
|
89 // -------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C TInt TVPbkStoreContactAnalyzer::HasFieldL |
|
92 ( VPbkFieldTypeSelectorFactory::TVPbkFieldTypeSelector aFieldTypeSelector, |
|
93 TInt aStartIndex/* = 0*/, |
|
94 const MVPbkStoreContact* aContact/* = NULL*/ ) const |
|
95 { |
|
96 return t_HasFieldL<VPbkFieldTypeSelectorFactory::TVPbkFieldTypeSelector> |
|
97 (aFieldTypeSelector,aStartIndex,aContact, |
|
98 iContact, iContactManager); |
|
99 } |
|
100 |
|
101 // -------------------------------------------------------------------------- |
|
102 // TVPbkStoreContactAnalyzer::HasFieldL |
|
103 // -------------------------------------------------------------------------- |
|
104 // |
|
105 EXPORT_C TInt TVPbkStoreContactAnalyzer::HasFieldL |
|
106 ( VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aActionTypeSelector, |
|
107 TInt aStartIndex/* = 0*/, |
|
108 const MVPbkStoreContact* aContact/* = NULL*/ ) const |
|
109 { |
|
110 return t_HasFieldL<VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector> |
|
111 (aActionTypeSelector,aStartIndex,aContact, |
|
112 iContact, iContactManager); |
|
113 } |
|
114 |
|
115 // -------------------------------------------------------------------------- |
|
116 // TVPbkStoreContactAnalyzer::IsFieldTypeSupportedL |
|
117 // -------------------------------------------------------------------------- |
|
118 // |
|
119 EXPORT_C TBool TVPbkStoreContactAnalyzer::IsFieldTypeSupportedL |
|
120 ( VPbkFieldTypeSelectorFactory::TVPbkFieldTypeSelector aFieldTypeSelector, |
|
121 const MVPbkStoreContact* aContact /*= NULL*/ ) const |
|
122 { |
|
123 return t_IsFieldTypeSupportedL<VPbkFieldTypeSelectorFactory::TVPbkFieldTypeSelector> |
|
124 ( aFieldTypeSelector, aContact, iContact, iContactManager); |
|
125 } |
|
126 |
|
127 // -------------------------------------------------------------------------- |
|
128 // TVPbkStoreContactAnalyzer::IsFieldTypeSupportedL |
|
129 // -------------------------------------------------------------------------- |
|
130 // |
|
131 EXPORT_C TBool TVPbkStoreContactAnalyzer::IsFieldTypeSupportedL |
|
132 ( VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aActionTypeSelector, |
|
133 const MVPbkStoreContact* aContact /*= NULL*/ ) const |
|
134 { |
|
135 return t_IsFieldTypeSupportedL<VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector> |
|
136 ( aActionTypeSelector, aContact, iContact, iContactManager); |
|
137 } |
|
138 |
|
139 // -------------------------------------------------------------------------- |
|
140 // TVPbkStoreContactAnalyzer::IsFieldTypeIncludedL |
|
141 // -------------------------------------------------------------------------- |
|
142 // |
|
143 EXPORT_C TBool TVPbkStoreContactAnalyzer::IsFieldTypeIncludedL |
|
144 ( const MVPbkFieldType& aFieldType, |
|
145 VPbkFieldTypeSelectorFactory::TVPbkFieldTypeSelector aFieldTypeSelector ) const |
|
146 { |
|
147 return t_IsFieldTypeIncludedL<VPbkFieldTypeSelectorFactory::TVPbkFieldTypeSelector> |
|
148 ( aFieldType, aFieldTypeSelector, iContactManager ); |
|
149 } |
|
150 |
|
151 // -------------------------------------------------------------------------- |
|
152 // TVPbkStoreContactAnalyzer::IsFieldTypeIncludedL |
|
153 // -------------------------------------------------------------------------- |
|
154 // |
|
155 EXPORT_C TBool TVPbkStoreContactAnalyzer::IsFieldTypeIncludedL |
|
156 ( const MVPbkFieldType& aFieldType, |
|
157 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aActionTypeSelector ) const |
|
158 { |
|
159 return t_IsFieldTypeIncludedL<VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector> |
|
160 ( aFieldType, aActionTypeSelector, iContactManager ); |
|
161 } |
|
162 |
|
163 // -------------------------------------------------------------------------- |
|
164 // TVPbkStoreContactAnalyzer::IsFieldTypeIncludedL |
|
165 // -------------------------------------------------------------------------- |
|
166 // |
|
167 EXPORT_C TBool TVPbkStoreContactAnalyzer::IsFieldTypeIncludedL |
|
168 ( const MVPbkBaseContactField& aField, |
|
169 VPbkFieldTypeSelectorFactory::TVPbkFieldTypeSelector aFieldTypeSelector ) const |
|
170 { |
|
171 return t_IsFieldTypeIncludedL<VPbkFieldTypeSelectorFactory::TVPbkFieldTypeSelector> |
|
172 ( aField, aFieldTypeSelector, iContactManager ); |
|
173 } |
|
174 |
|
175 // -------------------------------------------------------------------------- |
|
176 // TVPbkStoreContactAnalyzer::IsFieldTypeIncludedL |
|
177 // -------------------------------------------------------------------------- |
|
178 // |
|
179 EXPORT_C TBool TVPbkStoreContactAnalyzer::IsFieldTypeIncludedL |
|
180 ( const MVPbkBaseContactField& aField, |
|
181 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aActionTypeSelector ) const |
|
182 { |
|
183 return t_IsFieldTypeIncludedL<VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector> |
|
184 ( aField, aActionTypeSelector, iContactManager ); |
|
185 } |
|
186 |
|
187 // -------------------------------------------------------------------------- |
|
188 // t_HasFieldL |
|
189 // -------------------------------------------------------------------------- |
|
190 // |
|
191 template<class T> TInt t_HasFieldL( T aSelector, TInt aStartIndex, |
|
192 const MVPbkStoreContact* aContact, |
|
193 const MVPbkStoreContact* aClassContact, |
|
194 const CVPbkContactManager& aClassContactManager ) |
|
195 { |
|
196 TInt ret = KErrNotFound; |
|
197 const MVPbkStoreContact* tempContact = aClassContact; |
|
198 |
|
199 if ( aContact ) |
|
200 { |
|
201 tempContact = aContact; |
|
202 } |
|
203 |
|
204 // Check that there is contact to analyze |
|
205 if ( tempContact ) |
|
206 { |
|
207 // Read the contact field selector from resource |
|
208 MVPbkContactFieldSelector* fieldTypeSelector = |
|
209 static_cast<MVPbkContactFieldSelector*> |
|
210 ( CreateSelectorLC( aSelector, aClassContactManager ) ); |
|
211 |
|
212 // Check if the specified field is included to contact |
|
213 const MVPbkStoreContactFieldCollection& fields = |
|
214 tempContact->Fields(); |
|
215 ret = IsFieldIncluded( fields, aStartIndex, *fieldTypeSelector ); |
|
216 CleanupStack::PopAndDestroy( ); // fieldTypeSelector; |
|
217 } |
|
218 |
|
219 return ret; |
|
220 } |
|
221 |
|
222 // -------------------------------------------------------------------------- |
|
223 // t_IsFieldTypeSupportedL |
|
224 // -------------------------------------------------------------------------- |
|
225 // |
|
226 template<class T> TBool t_IsFieldTypeSupportedL( T aSelector, |
|
227 const MVPbkStoreContact* aContact, |
|
228 const MVPbkStoreContact* aClassContact, |
|
229 const CVPbkContactManager& aClassContactManager ) |
|
230 { |
|
231 TBool ret = EFalse; |
|
232 const MVPbkStoreContact* tempContact = aClassContact; |
|
233 |
|
234 if (aContact) |
|
235 { |
|
236 tempContact = aContact; |
|
237 } |
|
238 |
|
239 // Check that there is contact to analyze |
|
240 if ( tempContact ) |
|
241 { |
|
242 // Read the field type selector from resource |
|
243 MVPbkFieldTypeSelector* fieldTypeSelector = |
|
244 static_cast<MVPbkFieldTypeSelector*> |
|
245 ( CreateSelectorLC( aSelector, aClassContactManager ) ); |
|
246 |
|
247 // Check if the specified field type is supported by contact |
|
248 const MVPbkFieldTypeList& fieldTypes = |
|
249 tempContact->ParentStore().StoreProperties().SupportedFields(); |
|
250 ret = IsFieldTypeIncluded( fieldTypes, *fieldTypeSelector ); |
|
251 CleanupStack::PopAndDestroy( ); // fieldTypeSelector; |
|
252 } |
|
253 |
|
254 return ret; |
|
255 } |
|
256 |
|
257 // -------------------------------------------------------------------------- |
|
258 // t_IsFieldTypeIncludedL |
|
259 // -------------------------------------------------------------------------- |
|
260 // |
|
261 template<class T> TBool t_IsFieldTypeIncludedL( |
|
262 const MVPbkFieldType& aFieldType, |
|
263 T aSelector, |
|
264 const CVPbkContactManager& aClassContactManager ) |
|
265 { |
|
266 CVPbkFieldTypeSelector* selector = CreateSelectorLC( aSelector, aClassContactManager ); |
|
267 TBool ret = selector->IsFieldTypeIncluded( aFieldType ); |
|
268 CleanupStack::PopAndDestroy( selector ); |
|
269 return ret; |
|
270 } |
|
271 |
|
272 template<class T> TBool t_IsFieldTypeIncludedL( |
|
273 const MVPbkBaseContactField& aField, |
|
274 T aSelector, |
|
275 const CVPbkContactManager& aClassContactManager ) |
|
276 { |
|
277 // Get the field type |
|
278 const MVPbkFieldType* fieldType = |
|
279 VPbkUtils::MatchFieldType( aClassContactManager.FieldTypes(), aField ); |
|
280 CVPbkFieldTypeSelector* selector = CreateSelectorLC( aSelector, aClassContactManager ); |
|
281 TBool ret = selector->IsFieldTypeIncluded( *fieldType ); |
|
282 CleanupStack::PopAndDestroy( ); |
|
283 return ret; |
|
284 } |
|
285 |
|
286 // -------------------------------------------------------------------------- |
|
287 // CreateSelectorLC |
|
288 // -------------------------------------------------------------------------- |
|
289 // |
|
290 CVPbkFieldTypeSelector* CreateSelectorLC( |
|
291 VPbkFieldTypeSelectorFactory::TVPbkFieldTypeSelector aType, |
|
292 const CVPbkContactManager& aContactManager ) |
|
293 { |
|
294 CVPbkFieldTypeSelector* fieldTypeSelector = VPbkFieldTypeSelectorFactory::BuildFieldTypeSelectorL( |
|
295 aType, aContactManager.FieldTypes() ); |
|
296 |
|
297 CleanupStack::PushL( fieldTypeSelector ); |
|
298 return fieldTypeSelector; |
|
299 } |
|
300 |
|
301 // -------------------------------------------------------------------------- |
|
302 // CreateSelectorLC |
|
303 // -------------------------------------------------------------------------- |
|
304 // |
|
305 CVPbkFieldTypeSelector* CreateSelectorLC( |
|
306 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aType, |
|
307 const CVPbkContactManager& aContactManager ) |
|
308 { |
|
309 CVPbkFieldTypeSelector* fieldTypeSelector = VPbkFieldTypeSelectorFactory::BuildContactActionTypeSelectorL( |
|
310 aType, aContactManager.FieldTypes() ); |
|
311 |
|
312 CleanupStack::PushL( fieldTypeSelector ); |
|
313 return fieldTypeSelector; |
|
314 } |
|
315 |
|
316 // -------------------------------------------------------------------------- |
|
317 // IsFieldTypeIncluded |
|
318 // -------------------------------------------------------------------------- |
|
319 // |
|
320 TBool IsFieldTypeIncluded |
|
321 ( const MVPbkFieldTypeList& aFieldTypes, |
|
322 const MVPbkFieldTypeSelector& aFieldTypeSelector ) |
|
323 { |
|
324 TBool ret( EFalse ); |
|
325 TInt fieldTypeCount( aFieldTypes.FieldTypeCount() ); |
|
326 |
|
327 for ( TInt i = 0; i < fieldTypeCount && !ret; ++i ) |
|
328 { |
|
329 const MVPbkFieldType& fieldType = aFieldTypes.FieldTypeAt( i ); |
|
330 if ( aFieldTypeSelector.IsFieldTypeIncluded( fieldType ) ) |
|
331 { |
|
332 ret = ETrue; |
|
333 } |
|
334 } |
|
335 |
|
336 return ret; |
|
337 } |
|
338 |
|
339 // -------------------------------------------------------------------------- |
|
340 // IsFieldTypeIncluded |
|
341 // -------------------------------------------------------------------------- |
|
342 // |
|
343 TInt IsFieldIncluded |
|
344 (const MVPbkBaseContactFieldCollection& aFields, |
|
345 TInt aStartIndex, |
|
346 const MVPbkContactFieldSelector& aFieldTypeSelector) |
|
347 { |
|
348 TInt ret( KErrNotFound ); |
|
349 TInt fieldCount( aFields.FieldCount() ); |
|
350 |
|
351 for ( TInt i = aStartIndex; i < fieldCount && ret == KErrNotFound; ++i ) |
|
352 { |
|
353 const MVPbkBaseContactField& field = aFields.FieldAt( i ); |
|
354 if ( aFieldTypeSelector.IsFieldIncluded( field ) ) |
|
355 { |
|
356 ret = i; |
|
357 } |
|
358 } |
|
359 |
|
360 return ret; |
|
361 } |
|
362 |
|
363 // End of File |