20
|
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 sorted field collection for phonebook2 fields
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include "CPbk2PresentationContactFieldCollection.h"
|
|
22 |
|
|
23 |
// From Phonebook2
|
|
24 |
#include <MPbk2FieldProperty.h>
|
|
25 |
#include <CPbk2FieldPropertyGroup.h>
|
|
26 |
#include <MPbk2FieldPropertyArray.h>
|
|
27 |
#include <MPbk2FieldPropertyArray2.h>
|
|
28 |
#include <CPbk2PresentationContactField.h>
|
|
29 |
|
|
30 |
// From Virtual Phonebook
|
|
31 |
#include <MVPbkContactStore.h>
|
|
32 |
#include <MVPbkStoreContact.h>
|
|
33 |
#include <MVPbkStoreContactFieldCollection.h>
|
|
34 |
#include <MVPbkContactStoreProperties.h>
|
|
35 |
#include <MVPbkFieldType.h>
|
|
36 |
#include <TVPbkFieldVersitProperty.h>
|
|
37 |
#include <MVPbkContactFieldUriData.h>
|
|
38 |
|
|
39 |
// ============================= LOCAL FUNCTIONS ============================
|
|
40 |
|
|
41 |
namespace {
|
|
42 |
|
|
43 |
#ifdef _DEBUG
|
|
44 |
enum TPanicCode
|
|
45 |
{
|
|
46 |
EGetStoreContactIndex_PreCond,
|
|
47 |
EGetStoreContactIndex_PostCond,
|
|
48 |
EPanic_FieldAtLC_OOB
|
|
49 |
};
|
|
50 |
|
|
51 |
void Panic(TInt aReason)
|
|
52 |
{
|
|
53 |
_LIT(KPanicText, "CPbk2PresentationContactFieldCollection");
|
|
54 |
User::Panic(KPanicText, aReason);
|
|
55 |
}
|
|
56 |
#endif // _DEBUG
|
|
57 |
|
|
58 |
// --------------------------------------------------------------------------
|
|
59 |
// CompareFields
|
|
60 |
// Returns:
|
|
61 |
// 1) zero, if the two objects are equal.
|
|
62 |
// 2) a negative value, if the first object is less than the second.
|
|
63 |
// 3) a positive value, if the first object is greater than the second.
|
|
64 |
// --------------------------------------------------------------------------
|
|
65 |
//
|
|
66 |
TInt CompareFields(const CPbk2PresentationContactField& aFirst,
|
|
67 |
const CPbk2PresentationContactField& aSecond)
|
|
68 |
{
|
|
69 |
return aFirst.FieldProperty().OrderingItem() -
|
|
70 |
aSecond.FieldProperty().OrderingItem();
|
|
71 |
}
|
|
72 |
|
|
73 |
// --------------------------------------------------------------------------
|
|
74 |
// SupportedFieldTypes
|
|
75 |
// Returns the supported field type list of the parent contact
|
|
76 |
// of the collection
|
|
77 |
// --------------------------------------------------------------------------
|
|
78 |
//
|
|
79 |
inline const MVPbkFieldTypeList& SupportedFieldTypes(
|
|
80 |
MVPbkStoreContactFieldCollection& aFieldCollection)
|
|
81 |
{
|
|
82 |
return aFieldCollection.ParentStoreContact().
|
|
83 |
ContactStore().StoreProperties().SupportedFields();
|
|
84 |
}
|
|
85 |
|
|
86 |
// --------------------------------------------------------------------------
|
|
87 |
// MatchProperty
|
|
88 |
// --------------------------------------------------------------------------
|
|
89 |
//
|
|
90 |
inline const MPbk2FieldProperty* MatchProperty
|
|
91 |
(const MPbk2FieldPropertyArray& aFieldProperties,
|
|
92 |
const MVPbkStoreContactField& aField, TInt aMaxMatchPriority,
|
|
93 |
const TDesC& aName)
|
|
94 |
{
|
|
95 |
for (TInt i = 0; i < aMaxMatchPriority; ++i)
|
|
96 |
{
|
|
97 |
const MVPbkFieldType* type = aField.MatchFieldType(i);
|
|
98 |
if (type)
|
|
99 |
{
|
|
100 |
TVPbkFieldVersitProperty prop;
|
|
101 |
prop.SetName(EVPbkVersitNameIMPP);
|
|
102 |
if (type->Matches(prop, 0))
|
|
103 |
{
|
|
104 |
TPtrC name = MVPbkContactFieldUriData::Cast(aField.FieldData()).
|
|
105 |
Scheme();
|
|
106 |
if (name == KNullDesC)
|
|
107 |
{
|
|
108 |
name.Set(aName);
|
|
109 |
}
|
|
110 |
|
|
111 |
MPbk2FieldPropertyArray2* fieldPropertyExtension =
|
|
112 |
reinterpret_cast<MPbk2FieldPropertyArray2*>(
|
|
113 |
const_cast<MPbk2FieldPropertyArray&>( aFieldProperties ).
|
|
114 |
FieldPropertyArrayExtension(
|
|
115 |
KMPbk2FieldPropertyArrayExtension2Uid ) );
|
|
116 |
return fieldPropertyExtension->FindProperty(*type, name);
|
|
117 |
}
|
|
118 |
return aFieldProperties.FindProperty(*type);
|
|
119 |
}
|
|
120 |
}
|
|
121 |
return NULL;
|
|
122 |
}
|
|
123 |
|
|
124 |
}
|
|
125 |
|
|
126 |
// ============================ MEMBER FUNCTIONS ============================
|
|
127 |
|
|
128 |
// --------------------------------------------------------------------------
|
|
129 |
// CPbk2PresentationContactFieldCollection::
|
|
130 |
// CPbk2PresentationContactFieldCollection
|
|
131 |
// C++ default constructor can NOT contain any code, that
|
|
132 |
// might leave.
|
|
133 |
// --------------------------------------------------------------------------
|
|
134 |
//
|
|
135 |
inline CPbk2PresentationContactFieldCollection::
|
|
136 |
CPbk2PresentationContactFieldCollection(
|
|
137 |
const MPbk2FieldPropertyArray& aFieldProperties,
|
|
138 |
MVPbkStoreContactFieldCollection& aFieldCollection,
|
|
139 |
MVPbkStoreContact& aParentContact)
|
|
140 |
: iFieldProperties(aFieldProperties),
|
|
141 |
iFieldCollection(aFieldCollection),
|
|
142 |
iParentContact(aParentContact)
|
|
143 |
{
|
|
144 |
}
|
|
145 |
|
|
146 |
// --------------------------------------------------------------------------
|
|
147 |
// CPbk2PresentationContactFieldCollection::ConstructL
|
|
148 |
// Symbian 2nd phase constructor can leave.
|
|
149 |
// --------------------------------------------------------------------------
|
|
150 |
//
|
|
151 |
inline void CPbk2PresentationContactFieldCollection::ConstructL()
|
|
152 |
{
|
|
153 |
const TInt count = iFieldCollection.FieldCount();
|
|
154 |
for (TInt i = 0; i < count; ++i)
|
|
155 |
{
|
|
156 |
const MVPbkStoreContactField& field = iFieldCollection.FieldAt(i);
|
|
157 |
AddFieldMappingL(field, KNullDesC);
|
|
158 |
}
|
|
159 |
}
|
|
160 |
|
|
161 |
// --------------------------------------------------------------------------
|
|
162 |
// CPbk2PresentationContactFieldCollection::NewL
|
|
163 |
// Two-phased constructor.
|
|
164 |
// --------------------------------------------------------------------------
|
|
165 |
//
|
|
166 |
EXPORT_C CPbk2PresentationContactFieldCollection*
|
|
167 |
CPbk2PresentationContactFieldCollection::NewL(
|
|
168 |
const MPbk2FieldPropertyArray& aFieldProperties,
|
|
169 |
MVPbkStoreContactFieldCollection& aFieldCollection,
|
|
170 |
MVPbkStoreContact& aParentContact)
|
|
171 |
{
|
|
172 |
CPbk2PresentationContactFieldCollection* self =
|
|
173 |
new( ELeave ) CPbk2PresentationContactFieldCollection(aFieldProperties,
|
|
174 |
aFieldCollection, aParentContact);
|
|
175 |
CleanupStack::PushL( self );
|
|
176 |
self->ConstructL();
|
|
177 |
CleanupStack::Pop( self );
|
|
178 |
return self;
|
|
179 |
}
|
|
180 |
|
|
181 |
// Destructor
|
|
182 |
CPbk2PresentationContactFieldCollection::
|
|
183 |
~CPbk2PresentationContactFieldCollection()
|
|
184 |
{
|
|
185 |
iFields.ResetAndDestroy();
|
|
186 |
}
|
|
187 |
|
|
188 |
// --------------------------------------------------------------------------
|
|
189 |
// CPbk2PresentationContactFieldCollection::At
|
|
190 |
// --------------------------------------------------------------------------
|
|
191 |
//
|
|
192 |
EXPORT_C CPbk2PresentationContactField&
|
|
193 |
CPbk2PresentationContactFieldCollection::At(TInt aIndex) const
|
|
194 |
{
|
|
195 |
return *iFields[aIndex];
|
|
196 |
}
|
|
197 |
|
|
198 |
// --------------------------------------------------------------------------
|
|
199 |
// CPbk2PresentationContactFieldCollection::ContainsField
|
|
200 |
// --------------------------------------------------------------------------
|
|
201 |
//
|
|
202 |
EXPORT_C TInt CPbk2PresentationContactFieldCollection::ContainsField(
|
|
203 |
const MPbk2FieldProperty& aProperty) const
|
|
204 |
{
|
|
205 |
const TInt count = iFields.Count();
|
|
206 |
for (TInt i = 0; i < count; ++i)
|
|
207 |
{
|
|
208 |
if (iFields[i]->FieldProperty().IsSame(aProperty))
|
|
209 |
{
|
|
210 |
return i;
|
|
211 |
}
|
|
212 |
}
|
|
213 |
return KErrNotFound;
|
|
214 |
}
|
|
215 |
|
|
216 |
// --------------------------------------------------------------------------
|
|
217 |
// CPbk2PresentationContactFieldCollection::ContainsFieldFromGroup
|
|
218 |
// --------------------------------------------------------------------------
|
|
219 |
//
|
|
220 |
EXPORT_C TBool
|
|
221 |
CPbk2PresentationContactFieldCollection::ContainsFieldFromGroup(
|
|
222 |
const CPbk2FieldPropertyGroup& aPropertyGroup) const
|
|
223 |
{
|
|
224 |
const TInt count = aPropertyGroup.Count();
|
|
225 |
for (TInt i = 0; i < count; ++i)
|
|
226 |
{
|
|
227 |
if (ContainsField(aPropertyGroup.At(i)) != KErrNotFound)
|
|
228 |
{
|
|
229 |
return ETrue;
|
|
230 |
}
|
|
231 |
}
|
|
232 |
return EFalse;
|
|
233 |
}
|
|
234 |
|
|
235 |
// --------------------------------------------------------------------------
|
|
236 |
// CPbk2PresentationContactFieldCollection::FindFieldIndex
|
|
237 |
// --------------------------------------------------------------------------
|
|
238 |
//
|
|
239 |
EXPORT_C TInt CPbk2PresentationContactFieldCollection::FindFieldIndex(
|
|
240 |
const MVPbkStoreContactField& aField) const
|
|
241 |
{
|
|
242 |
const TInt count = iFields.Count();
|
|
243 |
for(TInt i = 0; i < count; ++i)
|
|
244 |
{
|
|
245 |
if (iFields[i]->IsSame(aField))
|
|
246 |
{
|
|
247 |
return i;
|
|
248 |
}
|
|
249 |
}
|
|
250 |
return KErrNotFound;
|
|
251 |
}
|
|
252 |
|
|
253 |
// --------------------------------------------------------------------------
|
|
254 |
// CPbk2PresentationContactFieldCollection::AddFieldMappingL
|
|
255 |
// --------------------------------------------------------------------------
|
|
256 |
//
|
|
257 |
void CPbk2PresentationContactFieldCollection::AddFieldMappingL(
|
|
258 |
const MVPbkStoreContactField& aField, const TDesC& aName)
|
|
259 |
{
|
|
260 |
TLinearOrder<CPbk2PresentationContactField> compareFunc(CompareFields);
|
|
261 |
const TInt maxMatchPriority =
|
|
262 |
SupportedFieldTypes(iFieldCollection).MaxMatchPriority();
|
|
263 |
const MPbk2FieldProperty* prop =
|
|
264 |
MatchProperty(iFieldProperties, aField, maxMatchPriority, aName);
|
|
265 |
if (prop)
|
|
266 |
{
|
|
267 |
CPbk2PresentationContactField* pbk2Field =
|
|
268 |
CPbk2PresentationContactField::NewLC(*prop, aField, iParentContact);
|
|
269 |
iFields.InsertInOrderAllowRepeatsL(pbk2Field, compareFunc);
|
|
270 |
CleanupStack::Pop(); // pbk2Field
|
|
271 |
}
|
|
272 |
}
|
|
273 |
|
|
274 |
// --------------------------------------------------------------------------
|
|
275 |
// CPbk2PresentationContactFieldCollection::RemoveFieldMapping
|
|
276 |
// --------------------------------------------------------------------------
|
|
277 |
//
|
|
278 |
void CPbk2PresentationContactFieldCollection::RemoveFieldMapping(TInt aIndex)
|
|
279 |
{
|
|
280 |
if (aIndex >= 0 && aIndex < iFields.Count())
|
|
281 |
{
|
|
282 |
delete iFields[aIndex];
|
|
283 |
iFields.Remove(aIndex);
|
|
284 |
}
|
|
285 |
}
|
|
286 |
|
|
287 |
// --------------------------------------------------------------------------
|
|
288 |
// CPbk2PresentationContactFieldCollection::ResetFieldMappings
|
|
289 |
// --------------------------------------------------------------------------
|
|
290 |
//
|
|
291 |
void CPbk2PresentationContactFieldCollection::ResetFieldMappings()
|
|
292 |
{
|
|
293 |
iFields.ResetAndDestroy();
|
|
294 |
}
|
|
295 |
|
|
296 |
// --------------------------------------------------------------------------
|
|
297 |
// CPbk2PresentationContactFieldCollection::StoreIndexOfField
|
|
298 |
// --------------------------------------------------------------------------
|
|
299 |
//
|
|
300 |
EXPORT_C TInt CPbk2PresentationContactFieldCollection::StoreIndexOfField(
|
|
301 |
TInt aFieldIndex) const
|
|
302 |
{
|
|
303 |
__ASSERT_DEBUG(aFieldIndex >= 0 && aFieldIndex < iFields.Count(),
|
|
304 |
Panic(EGetStoreContactIndex_PreCond));
|
|
305 |
const TInt count = iFieldCollection.FieldCount();
|
|
306 |
MVPbkStoreContactField* field = &iFields[aFieldIndex]->StoreField();
|
|
307 |
for (TInt i = 0; i < count; ++i)
|
|
308 |
{
|
|
309 |
if (iFieldCollection.FieldAt(i).IsSame(*field))
|
|
310 |
{
|
|
311 |
return i;
|
|
312 |
}
|
|
313 |
}
|
|
314 |
__ASSERT_DEBUG(EFalse, Panic(EGetStoreContactIndex_PostCond));
|
|
315 |
return KErrNotFound;
|
|
316 |
}
|
|
317 |
|
|
318 |
// --------------------------------------------------------------------------
|
|
319 |
// CPbk2PresentationContactFieldCollection::FieldIndexOfStoreField
|
|
320 |
// --------------------------------------------------------------------------
|
|
321 |
//
|
|
322 |
EXPORT_C TInt CPbk2PresentationContactFieldCollection::FieldIndexOfStoreField(
|
|
323 |
TInt aStoreFieldIndex) const
|
|
324 |
{
|
|
325 |
__ASSERT_DEBUG(aStoreFieldIndex >= 0 &&
|
|
326 |
aStoreFieldIndex < iFieldCollection.FieldCount(),
|
|
327 |
Panic(EGetStoreContactIndex_PreCond));
|
|
328 |
|
|
329 |
const TInt count = iFields.Count();
|
|
330 |
const MVPbkStoreContactField& collectionField = iFieldCollection.FieldAt( aStoreFieldIndex );
|
|
331 |
for (TInt i = 0; i < count; ++i)
|
|
332 |
{
|
|
333 |
MVPbkStoreContactField& field = iFields[i]->StoreField();
|
|
334 |
if ( field.IsSame( collectionField ) )
|
|
335 |
{
|
|
336 |
return i;
|
|
337 |
}
|
|
338 |
}
|
|
339 |
__ASSERT_DEBUG(EFalse, Panic(EGetStoreContactIndex_PostCond));
|
|
340 |
return KErrNotFound;
|
|
341 |
}
|
|
342 |
|
|
343 |
|
|
344 |
// --------------------------------------------------------------------------
|
|
345 |
// CPbk2PresentationContactFieldCollection::ParentContact
|
|
346 |
// --------------------------------------------------------------------------
|
|
347 |
//
|
|
348 |
MVPbkBaseContact&
|
|
349 |
CPbk2PresentationContactFieldCollection::ParentContact() const
|
|
350 |
{
|
|
351 |
return iParentContact;
|
|
352 |
}
|
|
353 |
|
|
354 |
// --------------------------------------------------------------------------
|
|
355 |
// CPbk2PresentationContactFieldCollection::FieldCount
|
|
356 |
// --------------------------------------------------------------------------
|
|
357 |
//
|
|
358 |
TInt CPbk2PresentationContactFieldCollection::FieldCount() const
|
|
359 |
{
|
|
360 |
return iFields.Count();
|
|
361 |
}
|
|
362 |
|
|
363 |
// --------------------------------------------------------------------------
|
|
364 |
// CPbk2PresentationContactFieldCollection::FieldAt
|
|
365 |
// --------------------------------------------------------------------------
|
|
366 |
//
|
|
367 |
const MVPbkStoreContactField&
|
|
368 |
CPbk2PresentationContactFieldCollection::FieldAt(TInt aIndex) const
|
|
369 |
{
|
|
370 |
return *iFields[aIndex];
|
|
371 |
}
|
|
372 |
|
|
373 |
// --------------------------------------------------------------------------
|
|
374 |
// CPbk2PresentationContactFieldCollection::FieldAt
|
|
375 |
// --------------------------------------------------------------------------
|
|
376 |
//
|
|
377 |
MVPbkStoreContactField& CPbk2PresentationContactFieldCollection::FieldAt
|
|
378 |
(TInt aIndex)
|
|
379 |
{
|
|
380 |
return *iFields[aIndex];
|
|
381 |
}
|
|
382 |
|
|
383 |
// --------------------------------------------------------------------------
|
|
384 |
// CPbk2PresentationContactFieldCollection::FieldAtLC
|
|
385 |
// --------------------------------------------------------------------------
|
|
386 |
//
|
|
387 |
MVPbkStoreContactField*
|
|
388 |
CPbk2PresentationContactFieldCollection::FieldAtLC(TInt aIndex) const
|
|
389 |
{
|
|
390 |
__ASSERT_DEBUG( iFields.Count() > aIndex &&
|
|
391 |
aIndex >= 0, Panic( EPanic_FieldAtLC_OOB ) );
|
|
392 |
|
|
393 |
TInt storeIndex = StoreIndexOfField(aIndex);
|
|
394 |
const MVPbkStoreContactField& field =
|
|
395 |
iFieldCollection.FieldAt(storeIndex);
|
|
396 |
|
|
397 |
MVPbkStoreContactField* pbk2Field = CPbk2PresentationContactField::NewLC
|
|
398 |
(iFields[aIndex]->FieldProperty(), field, iParentContact);
|
|
399 |
return pbk2Field;
|
|
400 |
}
|
|
401 |
|
|
402 |
// --------------------------------------------------------------------------
|
|
403 |
// CPbk2PresentationContactFieldCollection::ParentStoreContact
|
|
404 |
// --------------------------------------------------------------------------
|
|
405 |
//
|
|
406 |
MVPbkStoreContact&
|
|
407 |
CPbk2PresentationContactFieldCollection::ParentStoreContact() const
|
|
408 |
{
|
|
409 |
return iParentContact;
|
|
410 |
}
|
|
411 |
|
|
412 |
// --------------------------------------------------------------------------
|
|
413 |
// CPbk2PresentationContactFieldCollection::ParentStoreContact
|
|
414 |
// --------------------------------------------------------------------------
|
|
415 |
//
|
|
416 |
MVPbkStoreContactField* CPbk2PresentationContactFieldCollection::RetrieveField(
|
|
417 |
const MVPbkContactLink& aContactLink) const
|
|
418 |
{
|
|
419 |
return iFieldCollection.RetrieveField(aContactLink);
|
|
420 |
}
|
|
421 |
|
|
422 |
// End of File
|