summaryrefslogtreecommitdiffstats
path: root/plugins/contacts/symbian/contactsmodel/tsrc/testsyncplugin/cntphonecontact.cpp
blob: 36bc8af51aeac7c59f6e13c5754d47f58e26a5b2 (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
/*
* Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
* Contact: http://www.qt-project.org/legal
* 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 "cntphonecontact.h"
#include <cntdef.h>
#include <cntdb.h>

#include <centralrepository.h>  // crepository.
#include <e32property.h>
#include <phbksync.h>

// class CPhonebookContact - a rather simple data wrapper

void CContactSyncStaticRepository::WriteIntToCentralRepositoryL(TUint32& aKey, const TInt aValue, CRepository& iRepository)
{
	TRAPD(err, iRepository.Set(aKey++, aValue));
	if (err != KErrNone)
		User::Leave(err);	
}

void CContactSyncStaticRepository::ReadIntFromCentralRepositoryL(TUint32& aKey, TInt& aValue, CRepository& iRepository)
{
	TRAPD(err, iRepository.Get(aKey++, aValue));
	if (err != KErrNone)
		User::Leave(err);	
}

void CContactSyncStaticRepository::WriteStringToCentralRepositoryL(TUint32& aKey, TPtr aString, CRepository& iRepository)
{
	TRAPD(err, iRepository.Set(aKey++, aString));
	if (err != KErrNone)
		User::Leave(err);	
}

void CContactSyncStaticRepository::ReadStringFromCentralRepositoryL(TUint32& aKey, TPtr& aString, CRepository& iRepository)
{
	TRAPD(err, iRepository.Get(aKey++, aString));
	if (err != KErrNone)
		User::Leave(err);	
}

CPhonebookContact* CPhonebookContact::NewLC(const TDesC& aName, const TDesC& aNumber, CRepository* aRepository)
	{
	CPhonebookContact* self = new(ELeave) CPhonebookContact(aRepository);
	CleanupStack::PushL(self);
	self->ConstructL(aName, aNumber);
	return self;
	}

CPhonebookContact* CPhonebookContact::NewL(TUint32& aCRKey, CRepository* aRepository)
	{
	CPhonebookContact* self = new(ELeave) CPhonebookContact(aRepository);
	CleanupStack::PushL(self);
	self->ConstructL(aCRKey);
	CleanupStack::Pop(self);
	return self;
	}


CPhonebookContact::~CPhonebookContact()
	{
	delete iName;
	delete iNumber;
	}


CPhonebookContact::CPhonebookContact(CRepository* aRepository) : iRepository(aRepository)
	{
	}
	
	
void CPhonebookContact::ConstructL(const TDesC& aName, const TDesC& aNumber)
	{
	iName = aName.AllocL();
	iNumber = aNumber.AllocL();
	}
	
void CPhonebookContact::ConstructL(TUint32& aCRKey) 
	{
	//	How to read text from CR, probably the size and then the text
	TInt nameLength;
	CContactSyncStaticRepository::ReadIntFromCentralRepositoryL(aCRKey, nameLength, *iRepository);
	iName = HBufC::NewL(nameLength);
	TBuf<100> tempBuf1;
	TPtr tempPtr1 = iName->Des();
	CContactSyncStaticRepository::ReadStringFromCentralRepositoryL(aCRKey, tempPtr1, *iRepository);
	tempPtr1.Append(tempBuf1);
	TInt numberLength;
	CContactSyncStaticRepository::ReadIntFromCentralRepositoryL(aCRKey, numberLength, *iRepository);
	iNumber = HBufC::NewL(numberLength);
	TBuf<100> tempBuf2;
	TPtr tempPtr2 = iNumber->Des();
	CContactSyncStaticRepository::ReadStringFromCentralRepositoryL(aCRKey, tempPtr2, *iRepository);
	tempPtr2.Append(tempBuf2);	
	}
	
void CPhonebookContact::WriteToCRL(TUint32& aCRKey) const
	{
	CContactSyncStaticRepository::WriteIntToCentralRepositoryL(aCRKey, iName->Des().Length(), *iRepository);
	CContactSyncStaticRepository::WriteStringToCentralRepositoryL(aCRKey, iName->Des(), *iRepository);
 	CContactSyncStaticRepository::WriteIntToCentralRepositoryL(aCRKey, iNumber->Des().Length(), *iRepository);
	CContactSyncStaticRepository::WriteStringToCentralRepositoryL(aCRKey, iNumber->Des(), *iRepository);
	}



const HBufC* CPhonebookContact::Name()
	{
	return iName;
	}

const HBufC* CPhonebookContact::Number()
	{
	return iNumber;
	}