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