summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/t_cnttestimplementor.cpp
blob: 1745c96d1d1710adfe14344a020b8aabd5ca6e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
/*
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description: 
*
*/


#include <e32test.h>
#include <coreappstest/testserver.h>

#include "persistencelayer.h"
#include "nbcnttestlib/nbcnttestlib.h"
#include <cntitem.h>
#include <cntdef.h>

#include "t_persistencelayer.h"

#include "t_cnttestimpldefs.h"
#include "t_cnttestimplementor.h"

static const TUint KPlSessionId = 31415926;

// Implementation of CCntTestImplementor protected 
// non virtual member functions.

void CCntTestImplementor::DumpContactL(const CContactItem& aItem, const TDesC& aLabel)
	{
	TFileName fileName;
	const TDesC& type = TesterType();
	fileName.Format(_L("c:\\%S\\%02d.%S.html"), &type, ++iDumpCounter,  &aLabel);

	PrintContactL(fileName, aItem); //todo remove const_cast
	}
	

void CCntTestImplementor::PrintCntForViewL(const TDesC& aFileName, const CContactItemViewDef& aView)
	{
	CContactItem* cntItem = ReadLC(1, aView);
	DumpContactL(*cntItem, aFileName);
	CleanupStack::PopAndDestroy(cntItem);
	}

void CCntTestImplementor::ConstructL()
	{
	TFileName fileName(_L("c:\\"));
	fileName.Append(TesterType());
	fileName.Append(_L("\\"));

	RFs fs;
	fs.Connect();
	CleanupClosePushL(fs);

	CFileMan* fileMan = CFileMan::NewL(fs);
	CleanupStack::PushL(fileMan);

	(void)fileMan->RmDir(fileName); //if we can't delete files - who cares?

	CleanupStack::PopAndDestroy(2); // FileServer, FileManager

	}



	
	
	
	
	
	
	
	
	
	
// Implementation of CCntTestImpl member functions

CCntTestImpl* CCntTestImpl::NewLC()
	{
	CCntTestImpl* self = new (ELeave) CCntTestImpl();
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}

CCntTestImpl::~CCntTestImpl()
	{
	delete iGoldenTemplate;
//	CloseDatabase();
	}	
	
void CCntTestImpl::OpenDatabaseL(const TDesC& aFilename)
	{
	if (iDatabase)
		{
		delete iDatabase;
		iDatabase = NULL;
		}
	iDatabase  = CContactDatabase::OpenL(aFilename);
	}

void CCntTestImpl::CreateDatabaseL(const TDesC& aFilename, TBool aOwerwrite)
	{
	if (iDatabase)
		{
		delete iDatabase;
		iDatabase = NULL;
		}
		
	if (aOwerwrite)
		{
		iDatabase  = CContactDatabase::ReplaceL(aFilename);
		return;
		}
	iDatabase  = CContactDatabase::CreateL(aFilename);
	}

void CCntTestImpl::CloseDatabase()
	{
	delete iDatabase;
	iDatabase  = NULL;
	}


CContactItem* CCntTestImpl::ReadMinimalLC(TContactItemId id)
	{
	CContactItem* cntItem = iDatabase->ReadMinimalContactL(id);
	CleanupStack::PushL(cntItem);

	return cntItem;
	}



CContactItem* CCntTestImpl::OpenLC(TContactItemId id, const CContactItemViewDef& aViewDef)
	{
	CContactItem* cntItem = iDatabase->OpenContactL(id, aViewDef);

	CleanupStack::PushL(cntItem);
	return cntItem;
	}


TContactItemId CCntTestImpl::CreateL(CContactItem& cntItem)
	{
	TContactItemId  cntID = iDatabase->AddNewContactL(cntItem);
	return cntID;
	}


void CCntTestImpl::UpdateL(CContactItem& cntItem)
	{
	iDatabase->CommitContactL(cntItem);
	}


void CCntTestImpl::DeleteL(TContactItemId id)
	{
	iDatabase->DeleteContactL(id);
	}


CContactGroup* CCntTestImpl::CreateGroupLC(const TDesC& aGroupLabel)
	{
	return static_cast<CContactGroup*> (iDatabase->CreateContactGroupLC(aGroupLabel));
	}

CContactItem* CCntTestImpl::CreateContactCardTemplateLC(const TDesC& aLabel)
	{
	return iDatabase->CreateContactCardTemplateLC(aLabel);
	}

CContactItem* CCntTestImpl::ReadLC(TContactItemId id, const CContactItemViewDef& aViewDef) 
	{
	CContactItem* cntItem = iDatabase->ReadContactL(id, aViewDef);
	CleanupStack::PushL(cntItem);
	
	return cntItem;
	}


void CCntTestImpl::GroupAddAndRemove(CContactGroup& aGrp, TContactItemId addId, TContactItemId remId)
	{
	if (remId != -1)
		{
		CContactItem* cnt = ReadMinimalLC(remId);
		iDatabase->RemoveContactFromGroupL(*cnt, aGrp);
		CleanupStack::PopAndDestroy(cnt);
		cnt = NULL;
		}
	if (addId != -1)
		{
		CContactItem* cnt = ReadMinimalLC(addId);
		iDatabase->AddContactToGroupL(*cnt, aGrp);
		CleanupStack::PopAndDestroy(cnt);
		cnt = NULL;
		}

	}



const CContactTemplate&  CCntTestImpl::GetSysTemplate ()
	{
	if (!iGoldenTemplate)
		{
		CContactItemViewDef* matchAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields);
		matchAll->AddL(KUidContactFieldMatchAll);

		iGoldenTemplate = static_cast<CContactTemplate*>(iDatabase->ReadContactL(iDatabase->TemplateId(), *matchAll));

		CleanupStack::PopAndDestroy(matchAll);
		}
	return *iGoldenTemplate;
	}

void CCntTestImpl::CompactL()
	{
		iDatabase->CompactL();
	}

TBool CCntTestImpl::CompressRequired()
	{
	return 	iDatabase->CompressRequired();
	}

TBool CCntTestImpl::IsDamaged() const
	{
	return 	iDatabase->IsDamaged();
	}

TBool CCntTestImpl::DefaultContactDatabaseExistsL()
	{
	return 	iDatabase->DefaultContactDatabaseExistsL();
	}	
	
TBool CCntTestImpl::ContactDatabaseExistsL(const TDesC& aFileName)
	{
	return 	iDatabase->ContactDatabaseExistsL(aFileName);
	}
	
TInt CCntTestImpl::FileSize() const
	{
	return 	iDatabase->FileSize();
	}
	
TInt CCntTestImpl::WastedSpaceInBytes() const
	{
	return 	iDatabase->WastedSpaceInBytes();
	}	
	
void CCntTestImpl::DeleteDefaultFileL()
	{
	iDatabase->DeleteDefaultFileL();
	}	
	
void CCntTestImpl::GetDefaultNameL(TDes &aDes)
	{
	iDatabase->GetDefaultNameL(aDes);
	}	
	
TBool CCntTestImpl::DatabaseDrive(TDriveUnit& aDriveUnit)
	{
	return 	iDatabase->DatabaseDrive(aDriveUnit);
	}
	
CDesCArray* CCntTestImpl::ListDatabasesL(TDriveUnit& aDriveUnit)
	{
	return 	iDatabase->ListDatabasesL(aDriveUnit);
	}	

void CCntTestImpl::SetOwnCard(TContactItemId /*id*/)
	{
	//todo: add implementation
	}

// Implementation of CPlTestImpl member functions

CPlTestImpl* CPlTestImpl::NewLC()
	{
	CPlTestImpl* self = new (ELeave) CPlTestImpl();
	CleanupStack::PushL(self);

	self->ConstructL();
 	
	User::LeaveIfError(self->iFs.Connect());
#ifdef __SYMBIAN_CNTMODEL_USE_SQLITE__
	self->iPersistLayer = CPersistenceLayer::NewLC(self->iFs, NULL, NULL);
#else
	self->iPersistLayer = CPersistenceLayer::NewLC(self->iFs, NULL, NULL, NULL);
#endif//__SYMBIAN_CNTMODEL_USE_SQLITE__
	CleanupStack::Pop(self->iPersistLayer); //It is  a member - don't need it on the cleanup stack
	return self;
	}


CPlTestImpl::~CPlTestImpl()
	{
	CloseDatabase();
	iFs.Close();
	}


void CPlTestImpl::OpenDatabaseL(const TDesC& aFilename)
	{
	MLplContactsFile& cntFile = iPersistLayer->ContactsFileL();

#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__
	TRAPD(err, while(cntFile.OpenStepL(aFilename)){});
	User::LeaveIfError(err);
#else	
	cntFile.OpenL(aFilename);
#endif
	}

void CPlTestImpl::CreateDatabaseL(const TDesC& aFilename, TBool aOwerwrite)
	{
	MLplContactsFile& cntFile = iPersistLayer->ContactsFileL();

	TRAPD(err, cntFile.CreateL(aFilename, aOwerwrite ? MLplContactsFile::EPlOverwrite : MLplContactsFile::EPlLeaveIfExist));
	User::LeaveIfError(err);
#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__	
	TRAP(err, while(cntFile.OpenStepL(aFilename)){});
	User::LeaveIfError(err);
#else
	cntFile.OpenL(aFilename);
#endif
	}

void CPlTestImpl::CloseDatabase()
	{
	delete iPersistLayer;
	iPersistLayer = NULL;
	}


CContactItem* CPlTestImpl::ReadMinimalLC(TContactItemId id)
	{
	MLplPersistenceBroker& perBro = iPersistLayer->PersistenceBroker();

	CContactItemViewDef* noHidden = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields);
	noHidden->AddL(KUidContactFieldMatchAll);
	CContactItem* item = perBro.ReadLC(id, *noHidden, EPlIdentityInfo | EPlEmailInfo, KPlSessionId); 
	CleanupStack::Pop(item);
	CleanupStack::PopAndDestroy(noHidden);
	
	CleanupStack::PushL(item);
	item->SetTemplateRefId(-1); //Wipe the reference to the template.
	//In contacts model this field is never read in ReadMinimal

	return item;
	}


CContactItem* CPlTestImpl::OpenLC(TContactItemId id, const CContactItemViewDef& aViewDef)
	{
	MLplPersistenceBroker& perBro = iPersistLayer->PersistenceBroker();

	CContactItemViewDef* noHidden = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields);
	noHidden->AddL(KUidContactFieldMatchAll);
	CContactItem* cntItem = perBro.ReadLC(id, *noHidden, EPlAllInfo, KPlSessionId); 
	
	CleanupStack::Pop(cntItem);
	CleanupStack::PopAndDestroy(noHidden);
	CleanupStack::PushL(cntItem);

	//todo: not yet supporting contacts dependent on TemplateCards.
	iPersistLayer->PersistenceLayerTestL().MergeContactWithTemplateL(*cntItem, 
				iPersistLayer->ContactProperties().SystemTemplateL(), aViewDef);
		
	return cntItem;
	}
	


TContactItemId CPlTestImpl::CreateL(CContactItem& cntItem)
	{
	return iPersistLayer->PersistenceBroker().CreateL(cntItem, KPlSessionId);
	}


void CPlTestImpl::UpdateL(CContactItem& cntItem)
	{
	iPersistLayer->PersistenceBroker().UpdateL(cntItem, KPlSessionId);
	}


void CPlTestImpl::DeleteL(TContactItemId id)
	{
	CContactItem* cntItem = iPersistLayer->PersistenceBroker().DeleteLC(id, KPlSessionId, ESendEvent);
	CleanupStack::PopAndDestroy(cntItem);
	}


CContactGroup* CPlTestImpl::CreateGroupLC(const TDesC& aGroupLabel)
	{
	CContactGroup* newGroup = CContactGroup::NewLC();
	
	AddLabelField(*newGroup);
	newGroup->SetGroupLabelL(aGroupLabel);

	MLplPersistenceBroker& perBro = iPersistLayer->PersistenceBroker();
	perBro.CreateL(*newGroup, KPlSessionId);

	return newGroup;
	}


void CPlTestImpl::AddLabelField(CContactItem& aItem)
	{
	CContactItemFieldSet& aFieldSet = aItem.CardFields();

	TInt pos = aFieldSet.Find(KUidContactFieldTemplateLabel);
	if (pos==KErrNotFound)	// !HasItemLabelField()
		{
		CContactItemField* labelField = CContactItemField::NewLC(KStorageTypeText);
		labelField->AddFieldTypeL(KUidContactFieldTemplateLabel);
		if (aItem.Type()==KUidContactGroup)
			{
			_LIT(KGroupLabel,"Group Label");
			labelField->SetLabelL(KGroupLabel);
			}
		else if (aItem.Type()==KUidContactCardTemplate)
			{
			_LIT(KTemplateLabel,"Template Label");
			labelField->SetLabelL(KTemplateLabel);
			}
	// field needs to be first in the list
	// bug in stream retrieval of fields
		aItem.InsertFieldL(*labelField,0);
		CleanupStack::Pop(); // labelField
		}
	else	if (pos!=0)
		{
		aFieldSet.Move(pos,0);
		}
	}


CContactItem* CPlTestImpl::CreateContactCardTemplateLC (const TDesC& aLabel)
	{
	CContactItem* newTemplate = CContactItem::NewLC(KUidContactCardTemplate);
//	newTemplate->ClearFieldContent(); // Clear all data from the new template

	// Add label field
	AddLabelField(*newTemplate);
	static_cast<CContactCardTemplate*>(newTemplate)->SetTemplateLabelL(aLabel);

	// Create the contact in the database	
	MLplPersistenceBroker& perBro = iPersistLayer->PersistenceBroker();
	perBro.CreateL(*newTemplate, KPlSessionId);

	return newTemplate;	

	}


CContactItem* CPlTestImpl::ReadLC(TContactItemId id, const CContactItemViewDef& aViewDef) 
	{
	CContactItem* item = iPersistLayer->PersistenceBroker().ReadLC(id, aViewDef, EPlAllInfo, KPlSessionId); 
	
	//todo: not yet supporting contacts dependent on TemplateCards.
	//temporary switched off
	iPersistLayer->PersistenceLayerTestL().MergeContactWithTemplateL(*item, 
				   iPersistLayer->ContactProperties().SystemTemplateL(), aViewDef);
	return item;
	}



void CPlTestImpl::GroupAddAndRemove(CContactGroup& aGrp, TContactItemId addId, TContactItemId remId)
	{
	if (remId != -1)
		{
		aGrp.RemoveContactL(remId);
		}

	if (addId != -1)
		{
		aGrp.AddContactL(addId); 
		}

	UpdateL(aGrp);
	}


const CContactTemplate&  CPlTestImpl::GetSysTemplate ()
	{
	return iPersistLayer->ContactProperties().SystemTemplateL();
	}


void CPlTestImpl::CompactL()
	{
#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__	
	while(iPersistLayer->ContactsFileL().CompactStepL()) 
		{};
#endif
	}

TBool CPlTestImpl::CompressRequired()
	{
#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__	
	TBool theFlag(EFalse);
	TRAP_IGNORE(theFlag = iPersistLayer->ContactsFileL().CompressRequired());
	return theFlag;
#else
	return EFalse;
#endif
	}

TBool CPlTestImpl::IsDamaged() const
	{
#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__	
	TBool theFlag(EFalse);
	TRAP_IGNORE(theFlag = iPersistLayer->ContactsFileL().IsDamaged());
	return theFlag;
#else
	return EFalse;
#endif
	}

TBool CPlTestImpl::DefaultContactDatabaseExistsL()
	{
	// TODO:
	// Need to get default name, this is normally stored in 
	// the server, in FileManagerController.
	return NULL;
	}

TBool CPlTestImpl::ContactDatabaseExistsL(const TDesC& aFileName)
	{
	return iPersistLayer->ContactsFileL().DatabaseExistsL(aFileName);
	}	

TInt CPlTestImpl::FileSize() const
	{
	TBool theFlag(EFalse);
	TRAP_IGNORE(theFlag = iPersistLayer->ContactsFileL().FileSize());
	return theFlag;	
	}
	
TInt CPlTestImpl::WastedSpaceInBytes() const
	{
#ifndef __SYMBIAN_CNTMODEL_USE_SQLITE__	
	TBool theFlag(EFalse);
	TRAP_IGNORE(theFlag = iPersistLayer->ContactsFileL().WastedSpaceInBytes());
	return theFlag;		
#else
	return 0;
#endif
	}	

void CPlTestImpl::DeleteDefaultFileL()
	{
	// TODO?:
	// Default name is normally stored in 
	// the server, in FileManagerController.	
//	return 	iPersistLayer->ContactsFileL().DeleteDefaultFileL();
	}	

void CPlTestImpl::GetDefaultNameL(TDes &aDes)
	{
	aDes = NULL;
	// TODO?:
	// Default name is normally stored in 
	// the server, in FileManagerController.	
//	return 	iDatabase->GetDefaultNameL(aDes);
	}

TBool CPlTestImpl::DatabaseDrive(TDriveUnit& aDriveUnit)
	{
	TRAP_IGNORE(iPersistLayer->ContactsFileL().DatabaseDrive(aDriveUnit));
	return EFalse;
	}
	
CDesCArray* CPlTestImpl::ListDatabasesL(TDriveUnit& aDriveUnit)
	{
	return iPersistLayer->ContactsFileL().ListL(&aDriveUnit);
	}	

void CPlTestImpl::SetOwnCard(TContactItemId anId)
	{
	TContactItemId oldOwnCard = iPersistLayer->ContactProperties().OwnCardIdL();
	if (oldOwnCard > 0)
		{
		iPersistLayer->PersistenceBroker().ChangeTypeL(anId, KUidContactCard);
		}
	iPersistLayer->PersistenceBroker().ChangeTypeL(anId, KUidContactOwnCard);
	}

// Implementation of CPlTestImpl member functions

CClientSvrImpl* CClientSvrImpl::NewLC()
	{
	CClientSvrImpl* self = new (ELeave) CClientSvrImpl();
	CleanupStack::PushL(self);
	// todo - remove pl
	return self;
	}


CClientSvrImpl::~CClientSvrImpl()
	{
	CloseDatabase();
	}


void CClientSvrImpl::OpenDatabaseL(const TDesC& aFilename)
	{
	if (iCntDatabase)
		{
		delete iCntDatabase;
		iCntDatabase = NULL;
		}
	iCntDatabase = CContactDatabase::OpenL(aFilename, CContactDatabase::ESingleThread); 
	}

void CClientSvrImpl::CreateDatabaseL(const TDesC& aFilename, TBool aOwerwrite)
	{
	if (iCntDatabase)
		{
		delete iCntDatabase;
		iCntDatabase = NULL;
		}

	if (aOwerwrite)
		{
		iCntDatabase  = CContactDatabase::ReplaceL(aFilename);
		return;
		}
	iCntDatabase = CContactDatabase::CreateL(aFilename);
	}

void CClientSvrImpl::CloseDatabase()
	{
	delete iCntDatabase;
	iCntDatabase = NULL;
	delete iGoldenTemplate;
	iGoldenTemplate = NULL; 
	}


CContactItem* CClientSvrImpl::ReadMinimalLC(TContactItemId id)
	{
	// TODO: This is not a direct comparison with the old contact model
	// ReadMinimalLC has not been implemented in the pl
	CContactItemViewDef* noHidden = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields);
	noHidden->AddL(KUidContactFieldMatchAll);

	CContactItem* cntItem = iCntDatabase->ReadContactL(id, *noHidden);
	CleanupStack::PushL(cntItem);
	return cntItem;
	}


CContactItem* CClientSvrImpl::OpenLC(TContactItemId id, const CContactItemViewDef& /*aViewDef*/)
	{
	CContactItemViewDef* noHidden = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EMaskHiddenFields);
	noHidden->AddL(KUidContactFieldMatchAll);
	// TODO: replace with ReadLC
	CContactItem* cntItem = iCntDatabase->ReadContactL(id, *noHidden); 
	
	CleanupStack::PopAndDestroy(noHidden);
	CleanupStack::PushL(cntItem);

	return cntItem;
	}
	


TContactItemId CClientSvrImpl::CreateL(CContactItem& cntItem)
	{
	return iCntDatabase->AddNewContactL(cntItem);
	}


void CClientSvrImpl::UpdateL(CContactItem& cntItem)
	{
	CContactItem* cntItem2 = iCntDatabase->UpdateContactLC(cntItem.Id(), &cntItem);
	CleanupStack::PopAndDestroy(cntItem2);
	}


void CClientSvrImpl::DeleteL(TContactItemId id)
	{
	iCntDatabase->DeleteContactL(id);
	}


CContactGroup* CClientSvrImpl::CreateGroupLC(const TDesC& /*aGroupLabel*/)
	{
	// TODO	
	CContactGroup* newGroup = CContactGroup::NewLC();
	return newGroup;
	}

CContactItem* CClientSvrImpl::CreateContactCardTemplateLC(const TDesC& /*aGroupLabel*/)
	{
	return NULL; 	// TODO	
	}

CContactItem* CClientSvrImpl::ReadLC(TContactItemId id, const CContactItemViewDef& aViewDef) 
	{
	return iCntDatabase->ReadContactLC(id, aViewDef); 
	}



void CClientSvrImpl::GroupAddAndRemove(CContactGroup& /*aGrp*/, TContactItemId /*addId*/, TContactItemId /*remId*/)
	{
	// TODO
	}


const CContactTemplate&  CClientSvrImpl::GetSysTemplate ()
	{
	// TODO
	CContactItemViewDef* matchAll = CContactItemViewDef::NewLC(CContactItemViewDef::EIncludeFields,CContactItemViewDef::EIncludeHiddenFields);
	matchAll->AddL(KUidContactFieldMatchAll);

	// TODO - Method call to get the GoldenTemplate ID
	iGoldenTemplate = static_cast<CContactTemplate*>(iCntDatabase->ReadContactL(0, *matchAll));
	CleanupStack::PopAndDestroy(matchAll);

	return *iGoldenTemplate;
	}


void CClientSvrImpl::CompactL()
	{
		iCntDatabase->CompactL();
	}


TBool CClientSvrImpl::CompressRequired()
	{
	return 	iCntDatabase->CompressRequired();
	}
	
TBool CClientSvrImpl::IsDamaged() const
	{
	return 	iCntDatabase->IsDamaged();
	}	
	
TBool CClientSvrImpl::DefaultContactDatabaseExistsL()
	{
	return 	iCntDatabase->DefaultContactDatabaseExistsL();
	}

TBool CClientSvrImpl::ContactDatabaseExistsL(const TDesC& aFileName)
	{
	return 	iCntDatabase->ContactDatabaseExistsL(aFileName);
	}
	
TInt CClientSvrImpl::FileSize() const
	{
	return 	iCntDatabase->FileSize();
	}
	
TInt CClientSvrImpl::WastedSpaceInBytes() const
	{
	return 	iCntDatabase->WastedSpaceInBytes();
	}		
	
void CClientSvrImpl::DeleteDefaultFileL()
	{
	iCntDatabase->DeleteDefaultFileL();
	}		
	
	
void CClientSvrImpl::GetDefaultNameL(TDes &aDes)
	{
	iCntDatabase->GetDefaultNameL(aDes);
	}
	
TBool CClientSvrImpl::DatabaseDrive(TDriveUnit& aDriveUnit)
	{
	return 	iCntDatabase->DatabaseDrive(aDriveUnit);
	}		
	
	
CDesCArray* CClientSvrImpl::ListDatabasesL(TDriveUnit& aDriveUnit)
	{
	return 	iCntDatabase->ListDatabasesL(aDriveUnit);
	}


void CClientSvrImpl::SetOwnCard(TContactItemId /*id*/)
	{
	//todo: add implementation
	}