|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @internalComponent |
|
19 @released |
|
20 */ |
|
21 |
|
22 |
|
23 #include <barsc.h> // For resource reading. |
|
24 #include <bautils.h> |
|
25 #include <cntmodel.rsg> // For System template resources. |
|
26 #include <phbksync.h> // For KUidIccGlobalAdnPhonebook. |
|
27 |
|
28 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
29 #include "cntsyncecom.h" |
|
30 #endif |
|
31 |
|
32 #include "persistencelayerimpl.h" |
|
33 #include "clplcontactproperties.h" |
|
34 #include "plplugins.h" |
|
35 |
|
36 |
|
37 CLplContactProperties::CLplContactProperties(RFs& aFs) |
|
38 : |
|
39 iFs(aFs), |
|
40 iDbViewContactType(KUidContactItem) |
|
41 { |
|
42 } |
|
43 |
|
44 |
|
45 CLplContactProperties::~CLplContactProperties() |
|
46 { |
|
47 delete iPhoneParser; |
|
48 if (iSyncPlugin) |
|
49 { |
|
50 iSyncPlugin->Release(); |
|
51 iSyncPlugin = NULL; |
|
52 } |
|
53 delete iSyncDummy; |
|
54 delete iSystemTemplate; |
|
55 delete iGroupIdList; |
|
56 } |
|
57 |
|
58 |
|
59 void CLplContactProperties::SetContactItemManagerL(CPplContactItemManager& aContactItemManager) |
|
60 { |
|
61 __ASSERT_ALWAYS(iSystemTemplate == NULL, User::Leave(KErrArgument)); |
|
62 iContactItemManager = &aContactItemManager; |
|
63 iSystemTemplate = CSystemTemplateManager::NewL(*iContactItemManager, iFs); |
|
64 } |
|
65 |
|
66 |
|
67 void CLplContactProperties::SetDbViewContactType(TUid aDbViewContactType) |
|
68 { |
|
69 iDbViewContactType = aDbViewContactType; |
|
70 } |
|
71 |
|
72 |
|
73 TUid CLplContactProperties::GetDbViewContactType() const |
|
74 { |
|
75 return iDbViewContactType; |
|
76 } |
|
77 |
|
78 CContactPhoneParser& CLplContactProperties::ContactPhoneParserL() |
|
79 { |
|
80 if (!iPhoneParser) |
|
81 { |
|
82 iPhoneParser = CContactPhoneParser::NewL(); |
|
83 } |
|
84 __ASSERT_DEBUG(iPhoneParser != NULL, User::Leave(KErrGeneral)); |
|
85 return *iPhoneParser; |
|
86 } |
|
87 |
|
88 |
|
89 void CLplContactProperties::DisableSynchroniser(TUint aSessionId) |
|
90 { |
|
91 iDisabledPhonebookSessionId = aSessionId; |
|
92 } |
|
93 |
|
94 |
|
95 void CLplContactProperties::SessionDeleted(TUint aSessionId) |
|
96 { |
|
97 if (aSessionId == KIgnorePhbkSync || aSessionId == iDisabledPhonebookSessionId) |
|
98 { |
|
99 iDisabledPhonebookSessionId = 0; |
|
100 } |
|
101 } |
|
102 |
|
103 |
|
104 MContactSynchroniser& CLplContactProperties::ContactSynchroniserL(TUint aSessionId) |
|
105 { |
|
106 // If the caller asked to ignore the plugin the return the dummy plugin. |
|
107 if (aSessionId == KIgnorePhbkSync || aSessionId == iDisabledPhonebookSessionId) |
|
108 { |
|
109 if (!iSyncDummy) |
|
110 { |
|
111 iSyncDummy = new (ELeave) CDummySynchroniser(); |
|
112 } |
|
113 // Return the dummy plugin. |
|
114 return *iSyncDummy; |
|
115 } |
|
116 else |
|
117 { |
|
118 if (!iSyncPlugin) |
|
119 { |
|
120 iSyncPlugin = CContactSynchroniser::NewL(); |
|
121 } |
|
122 __ASSERT_DEBUG(iSyncPlugin != NULL, User::Leave(KErrGeneral)); |
|
123 // Return the real plugin. |
|
124 return *iSyncPlugin; |
|
125 } |
|
126 } |
|
127 |
|
128 |
|
129 CSystemTemplateManager& CLplContactProperties::SystemTemplateManager() const |
|
130 { |
|
131 return *iSystemTemplate; |
|
132 } |
|
133 |
|
134 |
|
135 const CContactTemplate& CLplContactProperties::SystemTemplateL() const |
|
136 { |
|
137 return iSystemTemplate->TemplateL(); |
|
138 } |
|
139 |
|
140 |
|
141 const RArray<TUid>& CLplContactProperties::CustomFilterableFieldsL() |
|
142 { |
|
143 return iSystemTemplate->CustomFilterableFieldsL(); |
|
144 } |
|
145 |
|
146 |
|
147 void CLplContactProperties::RecreateSystemTemplateL() |
|
148 { |
|
149 iSystemTemplate->RecreateSystemTemplateL(); |
|
150 } |
|
151 |
|
152 |
|
153 TInt CLplContactProperties::CardTemplatePrefIdL() const |
|
154 { |
|
155 return iContactItemManager->CardTemplatePrefIdL(); |
|
156 } |
|
157 |
|
158 |
|
159 void CLplContactProperties::SetCardTemplatePrefIdL(TInt aCardTemplatePrefId) |
|
160 { |
|
161 iContactItemManager->SetCardTemplatePrefIdL(aCardTemplatePrefId); |
|
162 } |
|
163 |
|
164 |
|
165 CContactIdArray& CLplContactProperties::CardTemplateIdsL() |
|
166 { |
|
167 return iContactItemManager->CardTemplateIdsL(); |
|
168 } |
|
169 |
|
170 |
|
171 CContactIdArray& CLplContactProperties::GroupIdListL() |
|
172 { |
|
173 delete iGroupIdList; |
|
174 iGroupIdList = NULL; |
|
175 iGroupIdList = iContactItemManager->GroupIdListL(); |
|
176 return *iGroupIdList; |
|
177 } |
|
178 |
|
179 |
|
180 TInt64 CLplContactProperties::MachineIdL() const |
|
181 { |
|
182 return iContactItemManager->PreferencesPersitor().MachineIdL(); |
|
183 } |
|
184 |
|
185 |
|
186 void CLplContactProperties::SetMachineIdL(TInt64 aMachineId) |
|
187 { |
|
188 iContactItemManager->PreferencesPersitor().SetMachineIdL(aMachineId); |
|
189 } |
|
190 |
|
191 |
|
192 TPtrC CLplContactProperties::UniqueIdL() |
|
193 { |
|
194 return iContactItemManager->PreferencesPersitor().DatabaseUidL(); |
|
195 } |
|
196 |
|
197 |
|
198 CContactTemplate* CLplContactProperties::SystemTemplateFromResourceL(const TDesC& aResouceFileName) const |
|
199 { |
|
200 return iSystemTemplate->SystemTemplateFromResourceL(aResouceFileName); |
|
201 } |
|
202 |
|
203 |
|
204 TContactItemId CLplContactProperties::OwnCardIdL() |
|
205 { |
|
206 return iContactItemManager->OwnCardIdL(); |
|
207 } |
|
208 |
|
209 |
|
210 void CLplContactProperties::SetOwnCardIdL(TContactItemId aId) |
|
211 { |
|
212 iContactItemManager->SetOwnCardIdL(aId); |
|
213 } |
|
214 |
|
215 |
|
216 const CArrayFix<CContactDatabase::TSortPref>& CLplContactProperties::SortPrefsL() |
|
217 { |
|
218 return iContactItemManager->PreferencesPersitor().PreferredSortOrderL(); |
|
219 } |
|
220 |
|
221 |
|
222 void CLplContactProperties::SetSortPrefsL(CArrayFix<CContactDatabase::TSortPref>* aPrefs) |
|
223 { |
|
224 iContactItemManager->PreferencesPersitor().SetPreferredSortOrderL(aPrefs); |
|
225 } |
|
226 |
|
227 |
|
228 /** |
|
229 Determines whether or note the given contact type UID complies with one of a |
|
230 set of rules. |
|
231 */ |
|
232 TBool CLplContactProperties::CheckType(TUid aUid) const |
|
233 { |
|
234 // Rule 1: Contact type UID is not the System template UID. |
|
235 if (aUid == KUidContactTemplate) |
|
236 { |
|
237 return EFalse; |
|
238 } |
|
239 |
|
240 // Rule 2: Contact type UID matches current view contact type UID. |
|
241 if (iDbViewContactType == KUidContactItem) |
|
242 { |
|
243 return ETrue; |
|
244 } |
|
245 |
|
246 // Rule 3: Contact type UID is a card or group and current view contact type |
|
247 // UID is cards or groups. |
|
248 if (iDbViewContactType == KUidContactCardOrGroup && |
|
249 (aUid == KUidContactCard || aUid == KUidContactGroup)) |
|
250 { |
|
251 return ETrue; |
|
252 } |
|
253 |
|
254 // Rule 4: Contact type UID is Own Card and current view contact type UID is |
|
255 // cards. |
|
256 if (iDbViewContactType == KUidContactCard && aUid == KUidContactOwnCard) |
|
257 { |
|
258 return ETrue; |
|
259 } |
|
260 // Rule 5: Contact type UID matches current view contact type UID. |
|
261 else if (aUid == iDbViewContactType) |
|
262 { |
|
263 return ETrue; |
|
264 } |
|
265 |
|
266 // Did not comply with any of the rules. |
|
267 return EFalse; |
|
268 } |
|
269 |
|
270 |
|
271 TContactItemId CLplContactProperties::ICCTemplateIdL(TUid aPhonebookUid, TUint aSessionId) |
|
272 { |
|
273 TContactItemId id = ContactSynchroniserL(aSessionId).ICCTemplateIdL(aPhonebookUid); |
|
274 return (aPhonebookUid == KNullUid) ? KNullContactId : id; |
|
275 } |
|
276 |
|
277 |
|
278 TContactItemId CLplContactProperties::PhonebookGroupIdL(TUint aSessionId) |
|
279 { |
|
280 return ContactSynchroniserL(aSessionId).GroupIdL(KUidIccGlobalAdnPhonebook); |
|
281 } |
|
282 |
|
283 |
|
284 CSystemTemplateManager* CSystemTemplateManager::NewL(CPplContactItemManager& aContactItemManager, RFs& aFileSession) |
|
285 { |
|
286 return new(ELeave) CSystemTemplateManager(aContactItemManager, aFileSession); |
|
287 } |
|
288 |
|
289 |
|
290 CSystemTemplateManager::CSystemTemplateManager(CPplContactItemManager& aContactItemManager, RFs& aFileSession) |
|
291 : |
|
292 iContactItemManager(aContactItemManager), |
|
293 iFileSession(aFileSession) |
|
294 { |
|
295 } |
|
296 |
|
297 |
|
298 CSystemTemplateManager::~CSystemTemplateManager() |
|
299 { |
|
300 delete iSystemTemplate; |
|
301 iCustFiltFields.Reset(); |
|
302 iCustFiltFields.Close(); |
|
303 } |
|
304 |
|
305 |
|
306 const CContactTemplate& CSystemTemplateManager::TemplateL() |
|
307 { |
|
308 if (iSystemTemplate) |
|
309 { |
|
310 return *iSystemTemplate; |
|
311 } |
|
312 |
|
313 CContactItemViewDef* vDef = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields, CContactItemViewDef::EIncludeHiddenFields); |
|
314 vDef->AddL(KUidContactFieldMatchAll); |
|
315 iSystemTemplate = static_cast<CContactTemplate*>(iContactItemManager.ReadLC(KGoldenTemplateId, *vDef, EPlAllInfo, KIgnorePhbkSync)); |
|
316 |
|
317 CleanupStack::Pop(); |
|
318 CleanupStack::PopAndDestroy(vDef); |
|
319 |
|
320 return *iSystemTemplate; |
|
321 } |
|
322 |
|
323 RArray<TUid>& CSystemTemplateManager::CustomFilterableFieldsL() |
|
324 { |
|
325 if (iCustFiltFields.Count() == 0) // Array is not yet initialised. |
|
326 { |
|
327 // Field order used to store user defined filter. |
|
328 TInt orderOfPriority = 0; |
|
329 |
|
330 // Initialise custom filterable fields. |
|
331 const TUid KUidCustFilterNullValue = {KNullContactId}; |
|
332 TInt ii = 0; |
|
333 for (; ii < KMaxCustomFilterableFields; ++ii) |
|
334 { |
|
335 iCustFiltFields.InsertL(KUidCustFilterNullValue,ii); |
|
336 } |
|
337 |
|
338 ii = iSystemTemplate->CardFields().Count() - 1; |
|
339 EContactFieldFlags contactFieldFlag = EContactFieldFlagFilterable; |
|
340 |
|
341 // For all the fields of the template find any fields which have one |
|
342 // of the filterable field flags and add them to the custom filterable |
|
343 // fields array. |
|
344 for (; ii>=0; --ii) |
|
345 { |
|
346 // Current template field. |
|
347 CContactItemField& field = iSystemTemplate->CardFields()[ii]; |
|
348 |
|
349 if (field.HasCustomFilter(contactFieldFlag)) |
|
350 { |
|
351 const TFieldType fieldType = (field.ContentType()).FieldType(0); |
|
352 |
|
353 if (contactFieldFlag == EContactFieldFlagFilterable) |
|
354 { |
|
355 if (orderOfPriority > KMaxCustomFilterableFields) |
|
356 { |
|
357 User::Leave(KErrNotSupported); |
|
358 } |
|
359 iCustFiltFields[orderOfPriority++] = fieldType; |
|
360 } |
|
361 else if (contactFieldFlag == EContactFieldFlagFilterable1) |
|
362 { |
|
363 // Store filter value at highest priority position zero. |
|
364 iCustFiltFields[0] = fieldType; |
|
365 } |
|
366 else if (contactFieldFlag == EContactFieldFlagFilterable2) |
|
367 { |
|
368 // Store filter value at next priority position. |
|
369 iCustFiltFields[1] = fieldType; |
|
370 } |
|
371 else if (contactFieldFlag == EContactFieldFlagFilterable3) |
|
372 { |
|
373 iCustFiltFields[2] = fieldType; |
|
374 } |
|
375 else if (contactFieldFlag == EContactFieldFlagFilterable4) |
|
376 { |
|
377 iCustFiltFields[3] = fieldType; |
|
378 } |
|
379 } |
|
380 } |
|
381 |
|
382 // Validate array with customer filterable fields. Leave if highest |
|
383 // priority UID is KUidCustFilterNullValue or if KUidCustFilterNullValue |
|
384 // appears between valid field type UIDs. |
|
385 ii = 0; |
|
386 for(; ii < KMaxCustomFilterableFields - 1; ++ii) |
|
387 { |
|
388 if (iCustFiltFields[ii] == KUidCustFilterNullValue && (iCustFiltFields[ii+1] != KUidCustFilterNullValue)) |
|
389 { |
|
390 User::Leave(KErrNotSupported); |
|
391 } |
|
392 } |
|
393 |
|
394 // Remove KUidCustFilterNullValue values from the end of the array. |
|
395 ii = KMaxCustomFilterableFields - 1; |
|
396 for(; ii >= 0; --ii) |
|
397 { |
|
398 if (iCustFiltFields[ii] == KUidCustFilterNullValue) |
|
399 { |
|
400 iCustFiltFields.Remove(ii); |
|
401 } |
|
402 } |
|
403 } |
|
404 |
|
405 return iCustFiltFields; |
|
406 } |
|
407 |
|
408 |
|
409 void CSystemTemplateManager::RecreateSystemTemplateL() |
|
410 { |
|
411 #if defined(__PROFILE_DEBUG__) |
|
412 RDebug::Print(_L("[CNTMODEL] MTD: CSystemTemplateManager::RecreateSystemTemplateL")); |
|
413 #endif |
|
414 |
|
415 _LIT(KCntSystemTemplate,"z:\\resource\\cntmodel\\cntmodel.rsc"); |
|
416 |
|
417 CContactTemplate* systemTemplate = SystemTemplateFromResourceL(KCntSystemTemplate); |
|
418 CleanupStack::PushL(systemTemplate); |
|
419 |
|
420 if (iContactItemManager.IsDatabaseEmptyL()) |
|
421 { |
|
422 iContactItemManager.CreateL(*systemTemplate, KIgnorePhbkSync); |
|
423 } |
|
424 else |
|
425 { |
|
426 iContactItemManager.UpdateL(*systemTemplate, KIgnorePhbkSync); |
|
427 } |
|
428 |
|
429 CleanupStack::PopAndDestroy(systemTemplate); |
|
430 } |
|
431 |
|
432 |
|
433 void CSystemTemplateManager::DeleteTemplate() |
|
434 { |
|
435 delete iSystemTemplate; |
|
436 iSystemTemplate = NULL; |
|
437 iCustFiltFields.Reset(); |
|
438 iCustFiltFields.Close(); |
|
439 } |
|
440 |
|
441 |
|
442 CContactTemplate* CSystemTemplateManager::SystemTemplateFromResourceL(const TDesC& aResouceFileName) |
|
443 { |
|
444 TFileName fileName(aResouceFileName); |
|
445 BaflUtils::NearestLanguageFile(iFileSession, fileName); |
|
446 |
|
447 RResourceFile resourceFile; |
|
448 resourceFile.OpenL(iFileSession, fileName); |
|
449 CleanupClosePushL(resourceFile); |
|
450 resourceFile.ConfirmSignatureL(4); |
|
451 |
|
452 TResourceReader resReader; |
|
453 resReader.SetBuffer(resourceFile.AllocReadLC(R_CNTUI_NEW_FIELD_DEFNS)); |
|
454 |
|
455 CContactTemplate* templ = CContactTemplate::NewLC(); |
|
456 TInt count = resReader.ReadInt16(); // num fields |
|
457 |
|
458 while(count--) |
|
459 { |
|
460 TStorageType storageType = resReader.ReadInt32(); |
|
461 TUid contactFieldUid = TUid::Uid(resReader.ReadInt32()); |
|
462 TUid vCardMappingUid = TUid::Uid(resReader.ReadInt32()); |
|
463 CContactItemField* field = CContactItemField::NewLC(storageType); |
|
464 |
|
465 field->SetMapping (vCardMappingUid); |
|
466 if (contactFieldUid!=KUidContactFieldNone) |
|
467 { |
|
468 field->AddFieldTypeL (contactFieldUid); |
|
469 } |
|
470 |
|
471 TInt mappingCount = 0; |
|
472 if((mappingCount=resReader.ReadInt16())!=0) |
|
473 { |
|
474 while(mappingCount--) |
|
475 { |
|
476 field->AddFieldTypeL(TUid::Uid(resReader.ReadInt32())); |
|
477 } |
|
478 } |
|
479 |
|
480 field->SetUserFlags(resReader.ReadInt32()); |
|
481 field->SetLabel(resReader.ReadHBufCL()); |
|
482 |
|
483 TUint flags=resReader.ReadInt32(); |
|
484 if (flags&EContactFieldFlagHidden) |
|
485 { |
|
486 field->SetHidden(ETrue); |
|
487 } |
|
488 if (flags&EContactFieldFlagReadOnly) |
|
489 { |
|
490 field->SetReadOnly(ETrue); |
|
491 } |
|
492 if (flags&EContactFieldFlagSynchronize) |
|
493 { |
|
494 field->SetSynchronize(ETrue); |
|
495 } |
|
496 if (flags&EContactFieldFlagDisabled) |
|
497 { |
|
498 field->SetDisabled(ETrue); |
|
499 } |
|
500 |
|
501 // Custom filterable fields. Here we only set field flags, construction |
|
502 // and validation of the custom filterable fields array happens on |
|
503 // demand in CustomFilterableFieldsL() method. |
|
504 if (flags&EContactFieldFlagFilterable) |
|
505 { |
|
506 field->SetCustomFilterable(EContactFieldFlagFilterable); |
|
507 } |
|
508 else if (flags&EContactFieldFlagFilterable1) |
|
509 { |
|
510 field->SetCustomFilterable(EContactFieldFlagFilterable1); |
|
511 } |
|
512 else if (flags&EContactFieldFlagFilterable2) |
|
513 { |
|
514 field->SetCustomFilterable(EContactFieldFlagFilterable2); |
|
515 } |
|
516 else if (flags&EContactFieldFlagFilterable3) |
|
517 { |
|
518 field->SetCustomFilterable(EContactFieldFlagFilterable3); |
|
519 } |
|
520 else if (flags&EContactFieldFlagFilterable4) |
|
521 { |
|
522 field->SetCustomFilterable(EContactFieldFlagFilterable4); |
|
523 } |
|
524 |
|
525 templ->AddFieldL(*field); |
|
526 CleanupStack::Pop(field); |
|
527 } |
|
528 |
|
529 CleanupStack::Pop(templ); |
|
530 CleanupStack::PopAndDestroy(2, &resourceFile); // resRead buf, close res files |
|
531 |
|
532 return templ; |
|
533 } |
|
534 |
|
535 |
|
536 TInt CDummySynchroniser::ValidateContact(TValidateOperation, TContactItemId) |
|
537 { |
|
538 return KErrNone; |
|
539 } |
|
540 |
|
541 |
|
542 TInt CDummySynchroniser::ValidateWriteContact(CContactICCEntry&) |
|
543 { |
|
544 return KErrNone; |
|
545 } |
|
546 |
|
547 |
|
548 TInt CDummySynchroniser::DeleteContact(TContactItemId) |
|
549 { |
|
550 return KErrNone; |
|
551 } |
|
552 |
|
553 |
|
554 void CDummySynchroniser::Release() |
|
555 { |
|
556 } |
|
557 |
|
558 |
|
559 void CDummySynchroniser::UpdatePostWriteL(const CContactICCEntry&) |
|
560 { |
|
561 } |
|
562 |
|
563 |
|
564 TContactItemId CDummySynchroniser::ICCTemplateIdL(TUid) |
|
565 { |
|
566 return KNullContactId; |
|
567 } |
|
568 |
|
569 |
|
570 TContactItemId CDummySynchroniser::GroupIdL(TUid) |
|
571 { |
|
572 return KNullContactId; |
|
573 } |
|
574 |
|
575 |
|
576 void CDummySynchroniser::NotifySyncStateChange(TRequestStatus& aStatus, TUid) |
|
577 { |
|
578 aStatus = KRequestPending; |
|
579 TRequestStatus* stat = &aStatus; |
|
580 User::RequestComplete(stat, KErrNone); |
|
581 } |
|
582 |
|
583 |
|
584 void CDummySynchroniser::CancelNotifyRequest(TUid) |
|
585 { |
|
586 } |
|
587 |
|
588 |
|
589 TBool CDummySynchroniser::IsSynchronisedL(TUid) |
|
590 { |
|
591 return ETrue; |
|
592 } |
|
593 |
|
594 |
|
595 TInt CDummySynchroniser::PhonebookList(RArray<TUid>&) |
|
596 { |
|
597 return KErrNone; |
|
598 } |