|
1 |
|
2 // Copyright (c) 2005-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 #include <e32test.h> |
|
18 #include <coreappstest/testserver.h> |
|
19 |
|
20 #include "persistencelayer.h" |
|
21 #include "NbCntTestLib/NbCntTestLib.h" |
|
22 #include <cntitem.h> |
|
23 #include <cntdef.h> |
|
24 |
|
25 #include "T_PersistenceLayer.h" |
|
26 |
|
27 #include "T_CntTestImplDefs.h" |
|
28 #include "T_CntTestImplementor.h" |
|
29 |
|
30 static const TUint KPlSessionId = 31415926; |
|
31 |
|
32 // Implementation of CCntTestImplementor protected |
|
33 // non virtual member functions. |
|
34 |
|
35 void CCntTestImplementor::DumpContactL(const CContactItem& aItem, const TDesC& aLabel) |
|
36 { |
|
37 TFileName fileName; |
|
38 const TDesC& type = TesterType(); |
|
39 fileName.Format(_L("c:\\%S\\%02d.%S.html"), &type, ++iDumpCounter, &aLabel); |
|
40 |
|
41 PrintContactL(fileName, aItem); //todo remove const_cast |
|
42 } |
|
43 |
|
44 |
|
45 void CCntTestImplementor::PrintCntForViewL(const TDesC& aFileName, const CContactItemViewDef& aView) |
|
46 { |
|
47 CContactItem* cntItem = ReadLC(1, aView); |
|
48 DumpContactL(*cntItem, aFileName); |
|
49 CleanupStack::PopAndDestroy(cntItem); |
|
50 } |
|
51 |
|
52 void CCntTestImplementor::ConstructL() |
|
53 { |
|
54 TFileName fileName(_L("c:\\")); |
|
55 fileName.Append(TesterType()); |
|
56 fileName.Append(_L("\\")); |
|
57 |
|
58 RFs fs; |
|
59 fs.Connect(); |
|
60 CleanupClosePushL(fs); |
|
61 |
|
62 CFileMan* fileMan = CFileMan::NewL(fs); |
|
63 CleanupStack::PushL(fileMan); |
|
64 |
|
65 (void)fileMan->RmDir(fileName); //if we can't delete files - who cares? |
|
66 |
|
67 CleanupStack::PopAndDestroy(2); // FileServer, FileManager |
|
68 |
|
69 } |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 // Implementation of CCntTestImpl member functions |
|
84 |
|
85 CCntTestImpl* CCntTestImpl::NewLC() |
|
86 { |
|
87 CCntTestImpl* self = new (ELeave) CCntTestImpl(); |
|
88 CleanupStack::PushL(self); |
|
89 self->ConstructL(); |
|
90 return self; |
|
91 } |
|
92 |
|
93 CCntTestImpl::~CCntTestImpl() |
|
94 { |
|
95 delete iGoldenTemplate; |
|
96 // CloseDatabase(); |
|
97 } |
|
98 |
|
99 void CCntTestImpl::OpenDatabaseL(const TDesC& aFilename) |
|
100 { |
|
101 if (iDatabase) |
|
102 { |
|
103 delete iDatabase; |
|
104 iDatabase = NULL; |
|
105 } |
|
106 iDatabase = CContactDatabase::OpenL(aFilename); |
|
107 } |
|
108 |
|
109 void CCntTestImpl::CreateDatabaseL(const TDesC& aFilename, TBool aOwerwrite) |
|
110 { |
|
111 if (iDatabase) |
|
112 { |
|
113 delete iDatabase; |
|
114 iDatabase = NULL; |
|
115 } |
|
116 |
|
117 if (aOwerwrite) |
|
118 { |
|
119 iDatabase = CContactDatabase::ReplaceL(aFilename); |
|
120 return; |
|
121 } |
|
122 iDatabase = CContactDatabase::CreateL(aFilename); |
|
123 } |
|
124 |
|
125 void CCntTestImpl::CloseDatabase() |
|
126 { |
|
127 delete iDatabase; |
|
128 iDatabase = NULL; |
|
129 } |
|
130 |
|
131 |
|
132 CContactItem* CCntTestImpl::ReadMinimalLC(TContactItemId id) |
|
133 { |
|
134 CContactItem* cntItem = iDatabase->ReadMinimalContactL(id); |
|
135 CleanupStack::PushL(cntItem); |
|
136 |
|
137 return cntItem; |
|
138 } |
|
139 |
|
140 |
|
141 |
|
142 CContactItem* CCntTestImpl::OpenLC(TContactItemId id, const CContactItemViewDef& aViewDef) |
|
143 { |
|
144 CContactItem* cntItem = iDatabase->OpenContactL(id, aViewDef); |
|
145 |
|
146 CleanupStack::PushL(cntItem); |
|
147 return cntItem; |
|
148 } |
|
149 |
|
150 |
|
151 TContactItemId CCntTestImpl::CreateL(CContactItem& cntItem) |
|
152 { |
|
153 TContactItemId cntID = iDatabase->AddNewContactL(cntItem); |
|
154 return cntID; |
|
155 } |
|
156 |
|
157 |
|
158 void CCntTestImpl::UpdateL(CContactItem& cntItem) |
|
159 { |
|
160 iDatabase->CommitContactL(cntItem); |
|
161 } |
|
162 |
|
163 |
|
164 void CCntTestImpl::DeleteL(TContactItemId id) |
|
165 { |
|
166 iDatabase->DeleteContactL(id); |
|
167 } |
|
168 |
|
169 |
|
170 CContactGroup* CCntTestImpl::CreateGroupLC(const TDesC& aGroupLabel) |
|
171 { |
|
172 return static_cast<CContactGroup*> (iDatabase->CreateContactGroupLC(aGroupLabel)); |
|
173 } |
|
174 |
|
175 CContactItem* CCntTestImpl::CreateContactCardTemplateLC(const TDesC& aLabel) |
|
176 { |
|
177 return iDatabase->CreateContactCardTemplateLC(aLabel); |
|
178 } |
|
179 |
|
180 CContactItem* CCntTestImpl::ReadLC(TContactItemId id, const CContactItemViewDef& aViewDef) |
|
181 { |
|
182 CContactItem* cntItem = iDatabase->ReadContactL(id, aViewDef); |
|
183 CleanupStack::PushL(cntItem); |
|
184 |
|
185 return cntItem; |
|
186 } |
|
187 |
|
188 |
|
189 void CCntTestImpl::GroupAddAndRemove(CContactGroup& aGrp, TContactItemId addId, TContactItemId remId) |
|
190 { |
|
191 if (remId != -1) |
|
192 { |
|
193 CContactItem* cnt = ReadMinimalLC(remId); |
|
194 iDatabase->RemoveContactFromGroupL(*cnt, aGrp); |
|
195 CleanupStack::PopAndDestroy(cnt); |
|
196 cnt = NULL; |
|
197 } |
|
198 if (addId != -1) |
|
199 { |
|
200 CContactItem* cnt = ReadMinimalLC(addId); |
|
201 iDatabase->AddContactToGroupL(*cnt, aGrp); |
|
202 CleanupStack::PopAndDestroy(cnt); |
|
203 cnt = NULL; |
|
204 } |
|
205 |
|
206 } |
|
207 |
|
208 |
|
209 |
|
210 const CContactTemplate& CCntTestImpl::GetSysTemplate () |
|
211 { |
|
212 if (!iGoldenTemplate) |
|
213 { |
|
214 CContactItemViewDef* matchAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields); |
|
215 matchAll->AddL(KUidContactFieldMatchAll); |
|
216 |
|
217 iGoldenTemplate = static_cast<CContactTemplate*>(iDatabase->ReadContactL(iDatabase->TemplateId(), *matchAll)); |
|
218 |
|
219 CleanupStack::PopAndDestroy(matchAll); |
|
220 } |
|
221 return *iGoldenTemplate; |
|
222 } |
|
223 |
|
224 void CCntTestImpl::CompactL() |
|
225 { |
|
226 iDatabase->CompactL(); |
|
227 } |
|
228 |
|
229 TBool CCntTestImpl::CompressRequired() |
|
230 { |
|
231 return iDatabase->CompressRequired(); |
|
232 } |
|
233 |
|
234 TBool CCntTestImpl::IsDamaged() const |
|
235 { |
|
236 return iDatabase->IsDamaged(); |
|
237 } |
|
238 |
|
239 TBool CCntTestImpl::DefaultContactDatabaseExistsL() |
|
240 { |
|
241 return iDatabase->DefaultContactDatabaseExistsL(); |
|
242 } |
|
243 |
|
244 TBool CCntTestImpl::ContactDatabaseExistsL(const TDesC& aFileName) |
|
245 { |
|
246 return iDatabase->ContactDatabaseExistsL(aFileName); |
|
247 } |
|
248 |
|
249 TInt CCntTestImpl::FileSize() const |
|
250 { |
|
251 return iDatabase->FileSize(); |
|
252 } |
|
253 |
|
254 TInt CCntTestImpl::WastedSpaceInBytes() const |
|
255 { |
|
256 return iDatabase->WastedSpaceInBytes(); |
|
257 } |
|
258 |
|
259 void CCntTestImpl::DeleteDefaultFileL() |
|
260 { |
|
261 iDatabase->DeleteDefaultFileL(); |
|
262 } |
|
263 |
|
264 void CCntTestImpl::GetDefaultNameL(TDes &aDes) |
|
265 { |
|
266 iDatabase->GetDefaultNameL(aDes); |
|
267 } |
|
268 |
|
269 TBool CCntTestImpl::DatabaseDrive(TDriveUnit& aDriveUnit) |
|
270 { |
|
271 return iDatabase->DatabaseDrive(aDriveUnit); |
|
272 } |
|
273 |
|
274 CDesCArray* CCntTestImpl::ListDatabasesL(TDriveUnit& aDriveUnit) |
|
275 { |
|
276 return iDatabase->ListDatabasesL(aDriveUnit); |
|
277 } |
|
278 |
|
279 void CCntTestImpl::SetOwnCard(TContactItemId /*id*/) |
|
280 { |
|
281 //todo: add implementation |
|
282 } |
|
283 |
|
284 // Implementation of CPlTestImpl member functions |
|
285 |
|
286 CPlTestImpl* CPlTestImpl::NewLC() |
|
287 { |
|
288 CPlTestImpl* self = new (ELeave) CPlTestImpl(); |
|
289 CleanupStack::PushL(self); |
|
290 |
|
291 self->ConstructL(); |
|
292 |
|
293 User::LeaveIfError(self->iFs.Connect()); |
|
294 #ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
295 self->iPersistLayer = CPersistenceLayer::NewLC(self->iFs, NULL, NULL); |
|
296 #else |
|
297 self->iPersistLayer = CPersistenceLayer::NewLC(self->iFs, NULL, NULL, NULL); |
|
298 #endif//__SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
299 CleanupStack::Pop(self->iPersistLayer); //It is a member - don't need it on the cleanup stack |
|
300 return self; |
|
301 } |
|
302 |
|
303 |
|
304 CPlTestImpl::~CPlTestImpl() |
|
305 { |
|
306 CloseDatabase(); |
|
307 iFs.Close(); |
|
308 } |
|
309 |
|
310 |
|
311 void CPlTestImpl::OpenDatabaseL(const TDesC& aFilename) |
|
312 { |
|
313 MLplContactsFile& cntFile = iPersistLayer->ContactsFileL(); |
|
314 |
|
315 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
316 TRAPD(err, while(cntFile.OpenStepL(aFilename)){}); |
|
317 User::LeaveIfError(err); |
|
318 #else |
|
319 cntFile.OpenL(aFilename); |
|
320 #endif |
|
321 } |
|
322 |
|
323 void CPlTestImpl::CreateDatabaseL(const TDesC& aFilename, TBool aOwerwrite) |
|
324 { |
|
325 MLplContactsFile& cntFile = iPersistLayer->ContactsFileL(); |
|
326 |
|
327 TRAPD(err, cntFile.CreateL(aFilename, aOwerwrite ? MLplContactsFile::EPlOverwrite : MLplContactsFile::EPlLeaveIfExist)); |
|
328 User::LeaveIfError(err); |
|
329 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
330 TRAP(err, while(cntFile.OpenStepL(aFilename)){}); |
|
331 User::LeaveIfError(err); |
|
332 #else |
|
333 cntFile.OpenL(aFilename); |
|
334 #endif |
|
335 } |
|
336 |
|
337 void CPlTestImpl::CloseDatabase() |
|
338 { |
|
339 delete iPersistLayer; |
|
340 iPersistLayer = NULL; |
|
341 } |
|
342 |
|
343 |
|
344 CContactItem* CPlTestImpl::ReadMinimalLC(TContactItemId id) |
|
345 { |
|
346 MLplPersistenceBroker& perBro = iPersistLayer->PersistenceBroker(); |
|
347 |
|
348 CContactItemViewDef* noHidden = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields); |
|
349 noHidden->AddL(KUidContactFieldMatchAll); |
|
350 CContactItem* item = perBro.ReadLC(id, *noHidden, EPlIdentityInfo | EPlEmailInfo, KPlSessionId); |
|
351 CleanupStack::Pop(item); |
|
352 CleanupStack::PopAndDestroy(noHidden); |
|
353 |
|
354 CleanupStack::PushL(item); |
|
355 item->SetTemplateRefId(-1); //Wipe the reference to the template. |
|
356 //In contacts model this field is never read in ReadMinimal |
|
357 |
|
358 return item; |
|
359 } |
|
360 |
|
361 |
|
362 CContactItem* CPlTestImpl::OpenLC(TContactItemId id, const CContactItemViewDef& aViewDef) |
|
363 { |
|
364 MLplPersistenceBroker& perBro = iPersistLayer->PersistenceBroker(); |
|
365 |
|
366 CContactItemViewDef* noHidden = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields); |
|
367 noHidden->AddL(KUidContactFieldMatchAll); |
|
368 CContactItem* cntItem = perBro.ReadLC(id, *noHidden, EPlAllInfo, KPlSessionId); |
|
369 |
|
370 CleanupStack::Pop(cntItem); |
|
371 CleanupStack::PopAndDestroy(noHidden); |
|
372 CleanupStack::PushL(cntItem); |
|
373 |
|
374 //todo: not yet supporting contacts dependent on TemplateCards. |
|
375 iPersistLayer->PersistenceLayerTestL().MergeContactWithTemplateL(*cntItem, |
|
376 iPersistLayer->ContactProperties().SystemTemplateL(), aViewDef); |
|
377 |
|
378 return cntItem; |
|
379 } |
|
380 |
|
381 |
|
382 |
|
383 TContactItemId CPlTestImpl::CreateL(CContactItem& cntItem) |
|
384 { |
|
385 return iPersistLayer->PersistenceBroker().CreateL(cntItem, KPlSessionId); |
|
386 } |
|
387 |
|
388 |
|
389 void CPlTestImpl::UpdateL(CContactItem& cntItem) |
|
390 { |
|
391 iPersistLayer->PersistenceBroker().UpdateL(cntItem, KPlSessionId); |
|
392 } |
|
393 |
|
394 |
|
395 void CPlTestImpl::DeleteL(TContactItemId id) |
|
396 { |
|
397 CContactItem* cntItem = iPersistLayer->PersistenceBroker().DeleteLC(id, KPlSessionId, ESendEvent); |
|
398 CleanupStack::PopAndDestroy(cntItem); |
|
399 } |
|
400 |
|
401 |
|
402 CContactGroup* CPlTestImpl::CreateGroupLC(const TDesC& aGroupLabel) |
|
403 { |
|
404 CContactGroup* newGroup = CContactGroup::NewLC(); |
|
405 |
|
406 AddLabelField(*newGroup); |
|
407 newGroup->SetGroupLabelL(aGroupLabel); |
|
408 |
|
409 MLplPersistenceBroker& perBro = iPersistLayer->PersistenceBroker(); |
|
410 perBro.CreateL(*newGroup, KPlSessionId); |
|
411 |
|
412 return newGroup; |
|
413 } |
|
414 |
|
415 |
|
416 void CPlTestImpl::AddLabelField(CContactItem& aItem) |
|
417 { |
|
418 CContactItemFieldSet& aFieldSet = aItem.CardFields(); |
|
419 |
|
420 TInt pos = aFieldSet.Find(KUidContactFieldTemplateLabel); |
|
421 if (pos==KErrNotFound) // !HasItemLabelField() |
|
422 { |
|
423 CContactItemField* labelField = CContactItemField::NewLC(KStorageTypeText); |
|
424 labelField->AddFieldTypeL(KUidContactFieldTemplateLabel); |
|
425 if (aItem.Type()==KUidContactGroup) |
|
426 { |
|
427 _LIT(KGroupLabel,"Group Label"); |
|
428 labelField->SetLabelL(KGroupLabel); |
|
429 } |
|
430 else if (aItem.Type()==KUidContactCardTemplate) |
|
431 { |
|
432 _LIT(KTemplateLabel,"Template Label"); |
|
433 labelField->SetLabelL(KTemplateLabel); |
|
434 } |
|
435 // field needs to be first in the list |
|
436 // bug in stream retrieval of fields |
|
437 aItem.InsertFieldL(*labelField,0); |
|
438 CleanupStack::Pop(); // labelField |
|
439 } |
|
440 else if (pos!=0) |
|
441 { |
|
442 aFieldSet.Move(pos,0); |
|
443 } |
|
444 } |
|
445 |
|
446 |
|
447 CContactItem* CPlTestImpl::CreateContactCardTemplateLC (const TDesC& aLabel) |
|
448 { |
|
449 CContactItem* newTemplate = CContactItem::NewLC(KUidContactCardTemplate); |
|
450 // newTemplate->ClearFieldContent(); // Clear all data from the new template |
|
451 |
|
452 // Add label field |
|
453 AddLabelField(*newTemplate); |
|
454 static_cast<CContactCardTemplate*>(newTemplate)->SetTemplateLabelL(aLabel); |
|
455 |
|
456 // Create the contact in the database |
|
457 MLplPersistenceBroker& perBro = iPersistLayer->PersistenceBroker(); |
|
458 perBro.CreateL(*newTemplate, KPlSessionId); |
|
459 |
|
460 return newTemplate; |
|
461 |
|
462 } |
|
463 |
|
464 |
|
465 CContactItem* CPlTestImpl::ReadLC(TContactItemId id, const CContactItemViewDef& aViewDef) |
|
466 { |
|
467 CContactItem* item = iPersistLayer->PersistenceBroker().ReadLC(id, aViewDef, EPlAllInfo, KPlSessionId); |
|
468 |
|
469 //todo: not yet supporting contacts dependent on TemplateCards. |
|
470 //temporary switched off |
|
471 iPersistLayer->PersistenceLayerTestL().MergeContactWithTemplateL(*item, |
|
472 iPersistLayer->ContactProperties().SystemTemplateL(), aViewDef); |
|
473 return item; |
|
474 } |
|
475 |
|
476 |
|
477 |
|
478 void CPlTestImpl::GroupAddAndRemove(CContactGroup& aGrp, TContactItemId addId, TContactItemId remId) |
|
479 { |
|
480 if (remId != -1) |
|
481 { |
|
482 aGrp.RemoveContactL(remId); |
|
483 } |
|
484 |
|
485 if (addId != -1) |
|
486 { |
|
487 aGrp.AddContactL(addId); |
|
488 } |
|
489 |
|
490 UpdateL(aGrp); |
|
491 } |
|
492 |
|
493 |
|
494 const CContactTemplate& CPlTestImpl::GetSysTemplate () |
|
495 { |
|
496 return iPersistLayer->ContactProperties().SystemTemplateL(); |
|
497 } |
|
498 |
|
499 |
|
500 void CPlTestImpl::CompactL() |
|
501 { |
|
502 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
503 while(iPersistLayer->ContactsFileL().CompactStepL()) |
|
504 {}; |
|
505 #endif |
|
506 } |
|
507 |
|
508 TBool CPlTestImpl::CompressRequired() |
|
509 { |
|
510 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
511 TBool theFlag(EFalse); |
|
512 TRAP_IGNORE(theFlag = iPersistLayer->ContactsFileL().CompressRequired()); |
|
513 return theFlag; |
|
514 #else |
|
515 return EFalse; |
|
516 #endif |
|
517 } |
|
518 |
|
519 TBool CPlTestImpl::IsDamaged() const |
|
520 { |
|
521 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
522 TBool theFlag(EFalse); |
|
523 TRAP_IGNORE(theFlag = iPersistLayer->ContactsFileL().IsDamaged()); |
|
524 return theFlag; |
|
525 #else |
|
526 return EFalse; |
|
527 #endif |
|
528 } |
|
529 |
|
530 TBool CPlTestImpl::DefaultContactDatabaseExistsL() |
|
531 { |
|
532 // TODO: |
|
533 // Need to get default name, this is normally stored in |
|
534 // the server, in FileManagerController. |
|
535 return NULL; |
|
536 } |
|
537 |
|
538 TBool CPlTestImpl::ContactDatabaseExistsL(const TDesC& aFileName) |
|
539 { |
|
540 return iPersistLayer->ContactsFileL().DatabaseExistsL(aFileName); |
|
541 } |
|
542 |
|
543 TInt CPlTestImpl::FileSize() const |
|
544 { |
|
545 TBool theFlag(EFalse); |
|
546 TRAP_IGNORE(theFlag = iPersistLayer->ContactsFileL().FileSize()); |
|
547 return theFlag; |
|
548 } |
|
549 |
|
550 TInt CPlTestImpl::WastedSpaceInBytes() const |
|
551 { |
|
552 #ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__ |
|
553 TBool theFlag(EFalse); |
|
554 TRAP_IGNORE(theFlag = iPersistLayer->ContactsFileL().WastedSpaceInBytes()); |
|
555 return theFlag; |
|
556 #else |
|
557 return 0; |
|
558 #endif |
|
559 } |
|
560 |
|
561 void CPlTestImpl::DeleteDefaultFileL() |
|
562 { |
|
563 // TODO?: |
|
564 // Default name is normally stored in |
|
565 // the server, in FileManagerController. |
|
566 // return iPersistLayer->ContactsFileL().DeleteDefaultFileL(); |
|
567 } |
|
568 |
|
569 void CPlTestImpl::GetDefaultNameL(TDes &aDes) |
|
570 { |
|
571 aDes = NULL; |
|
572 // TODO?: |
|
573 // Default name is normally stored in |
|
574 // the server, in FileManagerController. |
|
575 // return iDatabase->GetDefaultNameL(aDes); |
|
576 } |
|
577 |
|
578 TBool CPlTestImpl::DatabaseDrive(TDriveUnit& aDriveUnit) |
|
579 { |
|
580 TRAP_IGNORE(iPersistLayer->ContactsFileL().DatabaseDrive(aDriveUnit)); |
|
581 return EFalse; |
|
582 } |
|
583 |
|
584 CDesCArray* CPlTestImpl::ListDatabasesL(TDriveUnit& aDriveUnit) |
|
585 { |
|
586 return iPersistLayer->ContactsFileL().ListL(&aDriveUnit); |
|
587 } |
|
588 |
|
589 void CPlTestImpl::SetOwnCard(TContactItemId anId) |
|
590 { |
|
591 TContactItemId oldOwnCard = iPersistLayer->ContactProperties().OwnCardIdL(); |
|
592 if (oldOwnCard > 0) |
|
593 { |
|
594 iPersistLayer->PersistenceBroker().ChangeTypeL(anId, KUidContactCard); |
|
595 } |
|
596 iPersistLayer->PersistenceBroker().ChangeTypeL(anId, KUidContactOwnCard); |
|
597 } |
|
598 |
|
599 // Implementation of CPlTestImpl member functions |
|
600 |
|
601 CClientSvrImpl* CClientSvrImpl::NewLC() |
|
602 { |
|
603 CClientSvrImpl* self = new (ELeave) CClientSvrImpl(); |
|
604 CleanupStack::PushL(self); |
|
605 // todo - remove pl |
|
606 return self; |
|
607 } |
|
608 |
|
609 |
|
610 CClientSvrImpl::~CClientSvrImpl() |
|
611 { |
|
612 CloseDatabase(); |
|
613 } |
|
614 |
|
615 |
|
616 void CClientSvrImpl::OpenDatabaseL(const TDesC& aFilename) |
|
617 { |
|
618 if (iCntDatabase) |
|
619 { |
|
620 delete iCntDatabase; |
|
621 iCntDatabase = NULL; |
|
622 } |
|
623 iCntDatabase = CContactDatabase::OpenL(aFilename, CContactDatabase::ESingleThread); |
|
624 } |
|
625 |
|
626 void CClientSvrImpl::CreateDatabaseL(const TDesC& aFilename, TBool aOwerwrite) |
|
627 { |
|
628 if (iCntDatabase) |
|
629 { |
|
630 delete iCntDatabase; |
|
631 iCntDatabase = NULL; |
|
632 } |
|
633 |
|
634 if (aOwerwrite) |
|
635 { |
|
636 iCntDatabase = CContactDatabase::ReplaceL(aFilename); |
|
637 return; |
|
638 } |
|
639 iCntDatabase = CContactDatabase::CreateL(aFilename); |
|
640 } |
|
641 |
|
642 void CClientSvrImpl::CloseDatabase() |
|
643 { |
|
644 delete iCntDatabase; |
|
645 iCntDatabase = NULL; |
|
646 delete iGoldenTemplate; |
|
647 iGoldenTemplate = NULL; |
|
648 } |
|
649 |
|
650 |
|
651 CContactItem* CClientSvrImpl::ReadMinimalLC(TContactItemId id) |
|
652 { |
|
653 // TODO: This is not a direct comparison with the old contact model |
|
654 // ReadMinimalLC has not been implemented in the pl |
|
655 CContactItemViewDef* noHidden = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields); |
|
656 noHidden->AddL(KUidContactFieldMatchAll); |
|
657 |
|
658 CContactItem* cntItem = iCntDatabase->ReadContactL(id, *noHidden); |
|
659 CleanupStack::PushL(cntItem); |
|
660 return cntItem; |
|
661 } |
|
662 |
|
663 |
|
664 CContactItem* CClientSvrImpl::OpenLC(TContactItemId id, const CContactItemViewDef& /*aViewDef*/) |
|
665 { |
|
666 CContactItemViewDef* noHidden = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields); |
|
667 noHidden->AddL(KUidContactFieldMatchAll); |
|
668 // TODO: replace with ReadLC |
|
669 CContactItem* cntItem = iCntDatabase->ReadContactL(id, *noHidden); |
|
670 |
|
671 CleanupStack::PopAndDestroy(noHidden); |
|
672 CleanupStack::PushL(cntItem); |
|
673 |
|
674 return cntItem; |
|
675 } |
|
676 |
|
677 |
|
678 |
|
679 TContactItemId CClientSvrImpl::CreateL(CContactItem& cntItem) |
|
680 { |
|
681 return iCntDatabase->AddNewContactL(cntItem); |
|
682 } |
|
683 |
|
684 |
|
685 void CClientSvrImpl::UpdateL(CContactItem& cntItem) |
|
686 { |
|
687 CContactItem* cntItem2 = iCntDatabase->UpdateContactLC(cntItem.Id(), &cntItem); |
|
688 CleanupStack::PopAndDestroy(cntItem2); |
|
689 } |
|
690 |
|
691 |
|
692 void CClientSvrImpl::DeleteL(TContactItemId id) |
|
693 { |
|
694 iCntDatabase->DeleteContactL(id); |
|
695 } |
|
696 |
|
697 |
|
698 CContactGroup* CClientSvrImpl::CreateGroupLC(const TDesC& /*aGroupLabel*/) |
|
699 { |
|
700 // TODO |
|
701 CContactGroup* newGroup = CContactGroup::NewLC(); |
|
702 return newGroup; |
|
703 } |
|
704 |
|
705 CContactItem* CClientSvrImpl::CreateContactCardTemplateLC(const TDesC& /*aGroupLabel*/) |
|
706 { |
|
707 return NULL; // TODO |
|
708 } |
|
709 |
|
710 CContactItem* CClientSvrImpl::ReadLC(TContactItemId id, const CContactItemViewDef& aViewDef) |
|
711 { |
|
712 return iCntDatabase->ReadContactLC(id, aViewDef); |
|
713 } |
|
714 |
|
715 |
|
716 |
|
717 void CClientSvrImpl::GroupAddAndRemove(CContactGroup& /*aGrp*/, TContactItemId /*addId*/, TContactItemId /*remId*/) |
|
718 { |
|
719 // TODO |
|
720 } |
|
721 |
|
722 |
|
723 const CContactTemplate& CClientSvrImpl::GetSysTemplate () |
|
724 { |
|
725 // TODO |
|
726 CContactItemViewDef* matchAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields); |
|
727 matchAll->AddL(KUidContactFieldMatchAll); |
|
728 |
|
729 // TODO - Method call to get the GoldenTemplate ID |
|
730 iGoldenTemplate = static_cast<CContactTemplate*>(iCntDatabase->ReadContactL(0, *matchAll)); |
|
731 CleanupStack::PopAndDestroy(matchAll); |
|
732 |
|
733 return *iGoldenTemplate; |
|
734 } |
|
735 |
|
736 |
|
737 void CClientSvrImpl::CompactL() |
|
738 { |
|
739 iCntDatabase->CompactL(); |
|
740 } |
|
741 |
|
742 |
|
743 TBool CClientSvrImpl::CompressRequired() |
|
744 { |
|
745 return iCntDatabase->CompressRequired(); |
|
746 } |
|
747 |
|
748 TBool CClientSvrImpl::IsDamaged() const |
|
749 { |
|
750 return iCntDatabase->IsDamaged(); |
|
751 } |
|
752 |
|
753 TBool CClientSvrImpl::DefaultContactDatabaseExistsL() |
|
754 { |
|
755 return iCntDatabase->DefaultContactDatabaseExistsL(); |
|
756 } |
|
757 |
|
758 TBool CClientSvrImpl::ContactDatabaseExistsL(const TDesC& aFileName) |
|
759 { |
|
760 return iCntDatabase->ContactDatabaseExistsL(aFileName); |
|
761 } |
|
762 |
|
763 TInt CClientSvrImpl::FileSize() const |
|
764 { |
|
765 return iCntDatabase->FileSize(); |
|
766 } |
|
767 |
|
768 TInt CClientSvrImpl::WastedSpaceInBytes() const |
|
769 { |
|
770 return iCntDatabase->WastedSpaceInBytes(); |
|
771 } |
|
772 |
|
773 void CClientSvrImpl::DeleteDefaultFileL() |
|
774 { |
|
775 iCntDatabase->DeleteDefaultFileL(); |
|
776 } |
|
777 |
|
778 |
|
779 void CClientSvrImpl::GetDefaultNameL(TDes &aDes) |
|
780 { |
|
781 iCntDatabase->GetDefaultNameL(aDes); |
|
782 } |
|
783 |
|
784 TBool CClientSvrImpl::DatabaseDrive(TDriveUnit& aDriveUnit) |
|
785 { |
|
786 return iCntDatabase->DatabaseDrive(aDriveUnit); |
|
787 } |
|
788 |
|
789 |
|
790 CDesCArray* CClientSvrImpl::ListDatabasesL(TDriveUnit& aDriveUnit) |
|
791 { |
|
792 return iCntDatabase->ListDatabasesL(aDriveUnit); |
|
793 } |
|
794 |
|
795 |
|
796 void CClientSvrImpl::SetOwnCard(TContactItemId /*id*/) |
|
797 { |
|
798 //todo: add implementation |
|
799 } |