|
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: |
|
15 * Field property array for Phonebook 2 field types. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "CPbk2FieldPropertyArray.h" |
|
21 |
|
22 // Phonebook 2 |
|
23 #include "Pbk2PresentationUtils.h" |
|
24 #include "CPbk2FieldProperty.h" |
|
25 #include "CPbk2FieldOrderingManager.h" |
|
26 #include <CPbk2ServiceManager.h> |
|
27 #include <RPbk2LocalizedResourceFile.h> |
|
28 #include <Pbk2Presentation.rsg> |
|
29 #include <CPbk2FieldPropertyGroup.h> |
|
30 #include <Pbk2DataCaging.hrh> |
|
31 |
|
32 // Virtual Phonebook |
|
33 #include <MVPbkFieldType.h> |
|
34 #include <TVPbkFieldVersitProperty.h> |
|
35 #include <CVPbkFieldTypeSelector.h> |
|
36 #include <VPbkEng.rsg> |
|
37 |
|
38 // System includes |
|
39 #include <barsc.h> |
|
40 #include <barsread.h> |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CPbk2FieldPropertyArray::CPbk2FieldPropertyArray |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 inline CPbk2FieldPropertyArray::CPbk2FieldPropertyArray() |
|
47 { |
|
48 } |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // CPbk2FieldPropertyArray::ConstructL |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 inline void CPbk2FieldPropertyArray::ConstructL( |
|
55 const MVPbkFieldTypeList& aSupportedFieldTypeList, RFs& aRFs, |
|
56 CPbk2ServiceManager* aServMan) |
|
57 { |
|
58 RPbk2LocalizedResourceFile resFile( &aRFs ); |
|
59 resFile.OpenLC(KPbk2RomFileDrive, |
|
60 KDC_RESOURCE_FILES_DIR, |
|
61 Pbk2PresentationUtils::PresentationResourceFile()); |
|
62 |
|
63 // Read field type presentation order information |
|
64 TResourceReader reader; |
|
65 reader.SetBuffer( resFile.AllocReadLC( |
|
66 R_PBK2_FIELDTYPE_PRESENTATION_ORDERS ) ); |
|
67 CPbk2FieldOrderingManager* orderings = |
|
68 CPbk2FieldOrderingManager::NewL( reader ); |
|
69 CleanupStack::PopAndDestroy(); // R_PBK2_FIELDTYPE_PRESENTATION_ORDERS |
|
70 CleanupStack::PushL( orderings ); |
|
71 |
|
72 // Read field property resource strucutre array |
|
73 reader.SetBuffer( resFile.AllocReadLC( R_PHONEBOOK_FIELD_PROPERTIES ) ); |
|
74 ReadFieldPropertiesL( reader, aSupportedFieldTypeList, *orderings ); |
|
75 |
|
76 MultiplyImppFieldPropertyL( aServMan, aRFs ); |
|
77 |
|
78 // orderings R_PHONEBOOK_FIELD_PROPERTIES, resFile |
|
79 CleanupStack::PopAndDestroy(3); |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CPbk2FieldPropertyArray::NewL |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 EXPORT_C CPbk2FieldPropertyArray* CPbk2FieldPropertyArray::NewL |
|
87 (const MVPbkFieldTypeList& aSupportedFieldTypeList, RFs& aRFs ) |
|
88 { |
|
89 CPbk2FieldPropertyArray* self = new(ELeave) CPbk2FieldPropertyArray; |
|
90 CleanupStack::PushL(self); |
|
91 self->ConstructL( aSupportedFieldTypeList, aRFs, NULL ); |
|
92 CleanupStack::Pop(self); |
|
93 return self; |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 // CPbk2FieldPropertyArray::NewL |
|
98 // --------------------------------------------------------------------------- |
|
99 // |
|
100 EXPORT_C CPbk2FieldPropertyArray* CPbk2FieldPropertyArray::NewL |
|
101 (const MVPbkFieldTypeList& aSupportedFieldTypeList, RFs& aRFs, |
|
102 CPbk2ServiceManager* aServMan) |
|
103 { |
|
104 CPbk2FieldPropertyArray* self = new(ELeave) CPbk2FieldPropertyArray; |
|
105 CleanupStack::PushL(self); |
|
106 self->ConstructL( aSupportedFieldTypeList, aRFs, aServMan ); |
|
107 CleanupStack::Pop(self); |
|
108 return self; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CPbk2FieldPropertyArray::NewL |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 EXPORT_C CPbk2FieldPropertyArray* CPbk2FieldPropertyArray::NewL( |
|
116 const MVPbkFieldTypeList& aSupportedFieldTypeList, |
|
117 TResourceReader& aReader, |
|
118 RFs& aRFs ) |
|
119 { |
|
120 CPbk2FieldPropertyArray* self = new(ELeave) CPbk2FieldPropertyArray; |
|
121 CleanupStack::PushL(self); |
|
122 CPbk2FieldOrderingManager* orderings = |
|
123 self->CreateFieldOrderingsLC( aRFs ); |
|
124 self->ReadFieldPropertiesL( aReader, aSupportedFieldTypeList, *orderings ); |
|
125 CleanupStack::PopAndDestroy( orderings ); |
|
126 |
|
127 self->MultiplyImppFieldPropertyL( NULL, aRFs ); |
|
128 |
|
129 CleanupStack::Pop(self); |
|
130 return self; |
|
131 } |
|
132 |
|
133 // --------------------------------------------------------------------------- |
|
134 // CPbk2FieldPropertyArray::~CPbk2FieldPropertyArray |
|
135 // --------------------------------------------------------------------------- |
|
136 // |
|
137 CPbk2FieldPropertyArray::~CPbk2FieldPropertyArray() |
|
138 { |
|
139 iFieldProperties.ResetAndDestroy(); |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CPbk2FieldPropertyArray::FindProperty |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 const MPbk2FieldProperty* CPbk2FieldPropertyArray::FindProperty |
|
147 (const MVPbkFieldType& aFieldType) const |
|
148 { |
|
149 const CPbk2FieldProperty* result = NULL; |
|
150 const TInt count = iFieldProperties.Count(); |
|
151 for (TInt i = 0; i < count; ++i) |
|
152 { |
|
153 const CPbk2FieldProperty* property = iFieldProperties[i]; |
|
154 if (property->FieldType().IsSame(aFieldType)) |
|
155 { |
|
156 result = property; |
|
157 break; |
|
158 } |
|
159 } |
|
160 |
|
161 return result; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // CPbk2FieldPropertyArray::Count |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 TInt CPbk2FieldPropertyArray::Count() const |
|
169 { |
|
170 return iFieldProperties.Count(); |
|
171 } |
|
172 |
|
173 // --------------------------------------------------------------------------- |
|
174 // CPbk2FieldPropertyArray::At |
|
175 // --------------------------------------------------------------------------- |
|
176 // |
|
177 const MPbk2FieldProperty& CPbk2FieldPropertyArray::At |
|
178 (TInt aIndex) const |
|
179 { |
|
180 return *iFieldProperties[aIndex]; |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // CPbk2FieldPropertyArray::FieldPropertyArrayExtension |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 TAny* CPbk2FieldPropertyArray::FieldPropertyArrayExtension( |
|
188 TUid aExtensionUid ) |
|
189 { |
|
190 if ( aExtensionUid == KMPbk2FieldPropertyArrayExtension2Uid ) |
|
191 { |
|
192 return static_cast<MPbk2FieldPropertyArray2*>( this ); |
|
193 } |
|
194 return NULL; |
|
195 } |
|
196 |
|
197 // --------------------------------------------------------------------------- |
|
198 // CPbk2FieldPropertyArray::FindProperty |
|
199 // --------------------------------------------------------------------------- |
|
200 // |
|
201 const MPbk2FieldProperty* CPbk2FieldPropertyArray::FindProperty |
|
202 (const MVPbkFieldType& aFieldType, const TDesC& aName) const |
|
203 { |
|
204 const CPbk2FieldProperty* result = NULL; |
|
205 const TInt count = iFieldProperties.Count(); |
|
206 for (TInt i = 0; i < count; ++i) |
|
207 { |
|
208 const CPbk2FieldProperty* property = iFieldProperties[i]; |
|
209 if (property->FieldType().IsSame(aFieldType)) |
|
210 { |
|
211 if (!aName.CompareF(property->XSpName())) |
|
212 { |
|
213 result = property; |
|
214 break; |
|
215 } |
|
216 else if (property->XSpName() == KNullDesC) |
|
217 { |
|
218 result = property; //if field has name but there is not |
|
219 //the proper property take the one with empty name |
|
220 } |
|
221 } |
|
222 } |
|
223 |
|
224 return result; |
|
225 } |
|
226 |
|
227 // --------------------------------------------------------------------------- |
|
228 // CPbk2FieldPropertyArray::ReadFieldPropertiesL |
|
229 // --------------------------------------------------------------------------- |
|
230 // |
|
231 void CPbk2FieldPropertyArray::ReadFieldPropertiesL( |
|
232 TResourceReader& aReader, |
|
233 const MVPbkFieldTypeList& aSupportedFieldTypeList, |
|
234 CPbk2FieldOrderingManager& aOrderingManager ) |
|
235 { |
|
236 // aSupportedFieldTypeList is a list of the supported field type of the used store |
|
237 const TInt count = aReader.ReadInt16(); |
|
238 for (TInt i = 0; i < count; ++i) |
|
239 { |
|
240 CPbk2FieldProperty* property = CPbk2FieldProperty::NewLC( aReader, |
|
241 aSupportedFieldTypeList, aOrderingManager ); |
|
242 TBool doNotAdd = EFalse; |
|
243 if (property->IsSupported()) |
|
244 { |
|
245 // Non-Japanese variants use all the other properties but |
|
246 // Japanese reading fields |
|
247 const MVPbkFieldType* lastNameReading = |
|
248 aSupportedFieldTypeList.Find( |
|
249 R_VPBK_FIELD_TYPE_LASTNAMEREADING ); |
|
250 const MVPbkFieldType* firstNameReading = |
|
251 aSupportedFieldTypeList.Find( |
|
252 R_VPBK_FIELD_TYPE_FIRSTNAMEREADING ); |
|
253 const MVPbkFieldType& type = property->FieldType(); |
|
254 if ( ( lastNameReading && |
|
255 lastNameReading->IsSame( type ) ) || |
|
256 firstNameReading && |
|
257 firstNameReading->IsSame( type ) ) |
|
258 { |
|
259 doNotAdd = ETrue; |
|
260 } |
|
261 } |
|
262 else |
|
263 { |
|
264 doNotAdd = ETrue; |
|
265 } |
|
266 |
|
267 if (doNotAdd) |
|
268 { |
|
269 CleanupStack::PopAndDestroy(property); |
|
270 } |
|
271 else |
|
272 { |
|
273 iFieldProperties.AppendL(property); |
|
274 CleanupStack::Pop(property); |
|
275 } |
|
276 } |
|
277 } |
|
278 |
|
279 // --------------------------------------------------------------------------- |
|
280 // CPbk2FieldPropertyArray::CreateFieldOrderingsLC |
|
281 // --------------------------------------------------------------------------- |
|
282 // |
|
283 CPbk2FieldOrderingManager* CPbk2FieldPropertyArray::CreateFieldOrderingsLC( |
|
284 RFs& aRFs ) |
|
285 { |
|
286 RPbk2LocalizedResourceFile resFile( &aRFs ); |
|
287 resFile.OpenLC(KPbk2RomFileDrive, KDC_RESOURCE_FILES_DIR, |
|
288 Pbk2PresentationUtils::PresentationResourceFile()); |
|
289 |
|
290 // Read field type presentation order information |
|
291 TResourceReader reader; |
|
292 reader.SetBuffer( resFile.AllocReadLC( |
|
293 R_PBK2_FIELDTYPE_PRESENTATION_ORDERS ) ); |
|
294 CPbk2FieldOrderingManager* orderings = |
|
295 CPbk2FieldOrderingManager::NewL( reader ); |
|
296 // R_PBK2_FIELDTYPE_PRESENTATION_ORDERS, resFile |
|
297 CleanupStack::PopAndDestroy(2); |
|
298 CleanupStack::PushL( orderings ); |
|
299 return orderings; |
|
300 } |
|
301 |
|
302 // --------------------------------------------------------------------------- |
|
303 // CPbk2FieldPropertyArray::MultiplyImppFieldPropertyL |
|
304 // --------------------------------------------------------------------------- |
|
305 // |
|
306 void CPbk2FieldPropertyArray::MultiplyImppFieldPropertyL( |
|
307 CPbk2ServiceManager* aServMan, RFs& aRFs ) |
|
308 { |
|
309 TVPbkFieldVersitProperty prop; |
|
310 prop.SetName(EVPbkVersitNameIMPP); |
|
311 TInt i = 0; |
|
312 for (; i < iFieldProperties.Count(); i++) |
|
313 { |
|
314 if (iFieldProperties[i]->FieldType().Matches(prop, 0)) |
|
315 { |
|
316 break; |
|
317 } |
|
318 } |
|
319 if (i == iFieldProperties.Count()) |
|
320 { |
|
321 return; |
|
322 } |
|
323 CPbk2FieldProperty* imppProp = (CPbk2FieldProperty*)iFieldProperties[i]; |
|
324 |
|
325 CPbk2ServiceManager* servMan = aServMan; |
|
326 if ( !aServMan ) |
|
327 { |
|
328 servMan = CPbk2ServiceManager::NewL( aRFs ); |
|
329 CleanupStack::PushL(servMan); |
|
330 } |
|
331 |
|
332 //Below call to refresh the brand data. |
|
333 //RefreshDataL is needed because currently branding server |
|
334 //does not notify any brand updates (e.g. installation of |
|
335 //new brand packages). When notifications in future are |
|
336 //provided, this function can be removed from Phonebook. |
|
337 servMan->RefreshDataL(); |
|
338 const CPbk2ServiceManager::RServicesArray& services = servMan->Services(); |
|
339 |
|
340 for (TInt j = 0; j < services.Count(); j++) |
|
341 { |
|
342 CPbk2FieldProperty* prop = new (ELeave) CPbk2FieldProperty; |
|
343 CleanupStack::PushL(prop); |
|
344 prop->iFieldType = imppProp->iFieldType; |
|
345 prop->iFlags = imppProp->iFlags; |
|
346 if (!(services[j].iFlags & CPbk2ServiceManager::EInstalled)) |
|
347 { |
|
348 prop->iFlags &= ~KPbk2FieldFlagTemplateField; |
|
349 } |
|
350 prop->iMaxLength = imppProp->iMaxLength; |
|
351 prop->iMultiplicity = imppProp->iMultiplicity; |
|
352 prop->iEditMode = imppProp->iEditMode; |
|
353 prop->iDefaultCase = imppProp->iDefaultCase; |
|
354 prop->iCtrlType = imppProp->iCtrlType; |
|
355 prop->iOrderingItem = imppProp->iOrderingItem + j; |
|
356 prop->iAddItemOrdering = imppProp->iAddItemOrdering + j; |
|
357 prop->iGroupId = imppProp->iGroupId; |
|
358 prop->iLocation = imppProp->iLocation; |
|
359 prop->iDefaultLabel = services[j].iDisplayName.AllocL(); |
|
360 prop->iXSpName = services[j].iName.AllocL(); |
|
361 if (services[j].iBitmapId) |
|
362 { |
|
363 TUid uid; |
|
364 uid.iUid = KPbk2ServManId; |
|
365 prop->iIconId = TPbk2IconId(uid, services[j].iBitmapId); |
|
366 } |
|
367 else |
|
368 { |
|
369 prop->iIconId = imppProp->iIconId; |
|
370 } |
|
371 iFieldProperties.InsertL(prop, i); |
|
372 CleanupStack::Pop(prop); |
|
373 } |
|
374 |
|
375 imppProp->iFlags &= ~(KPbk2FieldFlagTemplateField | |
|
376 KPbk2FieldFlagUserCanAddField); |
|
377 for (i = 0; i < iFieldProperties.Count(); i++) |
|
378 { |
|
379 CPbk2FieldProperty* fProp = iFieldProperties[i]; |
|
380 if (!fProp->FieldType().Matches(prop, 0)) |
|
381 { |
|
382 if (fProp->iOrderingItem > imppProp->iOrderingItem) |
|
383 { |
|
384 fProp->iOrderingItem += services.Count(); |
|
385 } |
|
386 if (fProp->iAddItemOrdering > imppProp->iAddItemOrdering) |
|
387 { |
|
388 fProp->iAddItemOrdering += services.Count(); |
|
389 } |
|
390 } |
|
391 } |
|
392 imppProp->iOrderingItem += services.Count(); |
|
393 imppProp->iAddItemOrdering += services.Count(); |
|
394 |
|
395 if ( !aServMan ) |
|
396 { |
|
397 CleanupStack::PopAndDestroy(servMan); |
|
398 } |
|
399 } |
|
400 |
|
401 // End of File |