20
|
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 |
TBool ret = EFalse;
|
|
278 |
// Get the field type
|
|
279 |
const MVPbkFieldType* fieldType =
|
|
280 |
VPbkUtils::MatchFieldType( aClassContactManager.FieldTypes(), aField );
|
|
281 |
|
|
282 |
if ( fieldType )
|
|
283 |
{
|
|
284 |
CVPbkFieldTypeSelector* selector = CreateSelectorLC( aSelector,
|
|
285 |
aClassContactManager );
|
|
286 |
ret = selector->IsFieldTypeIncluded( *fieldType );
|
|
287 |
CleanupStack::PopAndDestroy();
|
|
288 |
}
|
|
289 |
return ret;
|
|
290 |
}
|
|
291 |
|
|
292 |
// --------------------------------------------------------------------------
|
|
293 |
// CreateSelectorLC
|
|
294 |
// --------------------------------------------------------------------------
|
|
295 |
//
|
|
296 |
CVPbkFieldTypeSelector* CreateSelectorLC(
|
|
297 |
VPbkFieldTypeSelectorFactory::TVPbkFieldTypeSelector aType,
|
|
298 |
const CVPbkContactManager& aContactManager )
|
|
299 |
{
|
|
300 |
CVPbkFieldTypeSelector* fieldTypeSelector = VPbkFieldTypeSelectorFactory::BuildFieldTypeSelectorL(
|
|
301 |
aType, aContactManager.FieldTypes() );
|
|
302 |
|
|
303 |
CleanupStack::PushL( fieldTypeSelector );
|
|
304 |
return fieldTypeSelector;
|
|
305 |
}
|
|
306 |
|
|
307 |
// --------------------------------------------------------------------------
|
|
308 |
// CreateSelectorLC
|
|
309 |
// --------------------------------------------------------------------------
|
|
310 |
//
|
|
311 |
CVPbkFieldTypeSelector* CreateSelectorLC(
|
|
312 |
VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aType,
|
|
313 |
const CVPbkContactManager& aContactManager )
|
|
314 |
{
|
|
315 |
CVPbkFieldTypeSelector* fieldTypeSelector = VPbkFieldTypeSelectorFactory::BuildContactActionTypeSelectorL(
|
|
316 |
aType, aContactManager.FieldTypes() );
|
|
317 |
|
|
318 |
CleanupStack::PushL( fieldTypeSelector );
|
|
319 |
return fieldTypeSelector;
|
|
320 |
}
|
|
321 |
|
|
322 |
// --------------------------------------------------------------------------
|
|
323 |
// IsFieldTypeIncluded
|
|
324 |
// --------------------------------------------------------------------------
|
|
325 |
//
|
|
326 |
TBool IsFieldTypeIncluded
|
|
327 |
( const MVPbkFieldTypeList& aFieldTypes,
|
|
328 |
const MVPbkFieldTypeSelector& aFieldTypeSelector )
|
|
329 |
{
|
|
330 |
TBool ret( EFalse );
|
|
331 |
TInt fieldTypeCount( aFieldTypes.FieldTypeCount() );
|
|
332 |
|
|
333 |
for ( TInt i = 0; i < fieldTypeCount && !ret; ++i )
|
|
334 |
{
|
|
335 |
const MVPbkFieldType& fieldType = aFieldTypes.FieldTypeAt( i );
|
|
336 |
if ( aFieldTypeSelector.IsFieldTypeIncluded( fieldType ) )
|
|
337 |
{
|
|
338 |
ret = ETrue;
|
|
339 |
}
|
|
340 |
}
|
|
341 |
|
|
342 |
return ret;
|
|
343 |
}
|
|
344 |
|
|
345 |
// --------------------------------------------------------------------------
|
|
346 |
// IsFieldTypeIncluded
|
|
347 |
// --------------------------------------------------------------------------
|
|
348 |
//
|
|
349 |
TInt IsFieldIncluded
|
|
350 |
(const MVPbkBaseContactFieldCollection& aFields,
|
|
351 |
TInt aStartIndex,
|
|
352 |
const MVPbkContactFieldSelector& aFieldTypeSelector)
|
|
353 |
{
|
|
354 |
TInt ret( KErrNotFound );
|
|
355 |
TInt fieldCount( aFields.FieldCount() );
|
|
356 |
|
|
357 |
for ( TInt i = aStartIndex; i < fieldCount && ret == KErrNotFound; ++i )
|
|
358 |
{
|
|
359 |
const MVPbkBaseContactField& field = aFields.FieldAt( i );
|
|
360 |
if ( aFieldTypeSelector.IsFieldIncluded( field ) )
|
|
361 |
{
|
|
362 |
ret = i;
|
|
363 |
}
|
|
364 |
}
|
|
365 |
|
|
366 |
return ret;
|
|
367 |
}
|
|
368 |
|
|
369 |
// End of File
|