|
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 #include "cntphonecontact.h" |
|
17 #include <cntdef.h> |
|
18 #include <cntdb.h> |
|
19 |
|
20 #include <centralrepository.h> // CRepository. |
|
21 #include <e32property.h> |
|
22 #include <phbksync.h> |
|
23 |
|
24 // class CPhonebookContact - a rather simple data wrapper |
|
25 |
|
26 void CContactSyncStaticRepository::WriteIntToCentralRepositoryL(TUint32& aKey, const TInt aValue, CRepository& iRepository) |
|
27 { |
|
28 TRAPD(err, iRepository.Set(aKey++, aValue)); |
|
29 if (err != KErrNone) |
|
30 User::Leave(err); |
|
31 } |
|
32 |
|
33 void CContactSyncStaticRepository::ReadIntFromCentralRepositoryL(TUint32& aKey, TInt& aValue, CRepository& iRepository) |
|
34 { |
|
35 TRAPD(err, iRepository.Get(aKey++, aValue)); |
|
36 if (err != KErrNone) |
|
37 User::Leave(err); |
|
38 } |
|
39 |
|
40 void CContactSyncStaticRepository::WriteStringToCentralRepositoryL(TUint32& aKey, TPtr aString, CRepository& iRepository) |
|
41 { |
|
42 TRAPD(err, iRepository.Set(aKey++, aString)); |
|
43 if (err != KErrNone) |
|
44 User::Leave(err); |
|
45 } |
|
46 |
|
47 void CContactSyncStaticRepository::ReadStringFromCentralRepositoryL(TUint32& aKey, TPtr& aString, CRepository& iRepository) |
|
48 { |
|
49 TRAPD(err, iRepository.Get(aKey++, aString)); |
|
50 if (err != KErrNone) |
|
51 User::Leave(err); |
|
52 } |
|
53 |
|
54 CPhonebookContact* CPhonebookContact::NewLC(const TDesC& aName, const TDesC& aNumber, CRepository* aRepository) |
|
55 { |
|
56 CPhonebookContact* self = new(ELeave) CPhonebookContact(aRepository); |
|
57 CleanupStack::PushL(self); |
|
58 self->ConstructL(aName, aNumber); |
|
59 return self; |
|
60 } |
|
61 |
|
62 CPhonebookContact* CPhonebookContact::NewL(TUint32& aCRKey, CRepository* aRepository) |
|
63 { |
|
64 CPhonebookContact* self = new(ELeave) CPhonebookContact(aRepository); |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL(aCRKey); |
|
67 CleanupStack::Pop(self); |
|
68 return self; |
|
69 } |
|
70 |
|
71 |
|
72 CPhonebookContact::~CPhonebookContact() |
|
73 { |
|
74 delete iName; |
|
75 delete iNumber; |
|
76 } |
|
77 |
|
78 |
|
79 CPhonebookContact::CPhonebookContact(CRepository* aRepository) : iRepository(aRepository) |
|
80 { |
|
81 } |
|
82 |
|
83 |
|
84 void CPhonebookContact::ConstructL(const TDesC& aName, const TDesC& aNumber) |
|
85 { |
|
86 iName = aName.AllocL(); |
|
87 iNumber = aNumber.AllocL(); |
|
88 } |
|
89 |
|
90 void CPhonebookContact::ConstructL(TUint32& aCRKey) |
|
91 { |
|
92 // How to read text from CR, probably the size and then the text |
|
93 TInt nameLength; |
|
94 CContactSyncStaticRepository::ReadIntFromCentralRepositoryL(aCRKey, nameLength, *iRepository); |
|
95 iName = HBufC::NewL(nameLength); |
|
96 TBuf<100> tempBuf1; |
|
97 TPtr tempPtr1 = iName->Des(); |
|
98 CContactSyncStaticRepository::ReadStringFromCentralRepositoryL(aCRKey, tempPtr1, *iRepository); |
|
99 tempPtr1.Append(tempBuf1); |
|
100 TInt numberLength; |
|
101 CContactSyncStaticRepository::ReadIntFromCentralRepositoryL(aCRKey, numberLength, *iRepository); |
|
102 iNumber = HBufC::NewL(numberLength); |
|
103 TBuf<100> tempBuf2; |
|
104 TPtr tempPtr2 = iNumber->Des(); |
|
105 CContactSyncStaticRepository::ReadStringFromCentralRepositoryL(aCRKey, tempPtr2, *iRepository); |
|
106 tempPtr2.Append(tempBuf2); |
|
107 } |
|
108 |
|
109 void CPhonebookContact::WriteToCRL(TUint32& aCRKey) const |
|
110 { |
|
111 CContactSyncStaticRepository::WriteIntToCentralRepositoryL(aCRKey, iName->Des().Length(), *iRepository); |
|
112 CContactSyncStaticRepository::WriteStringToCentralRepositoryL(aCRKey, iName->Des(), *iRepository); |
|
113 CContactSyncStaticRepository::WriteIntToCentralRepositoryL(aCRKey, iNumber->Des().Length(), *iRepository); |
|
114 CContactSyncStaticRepository::WriteStringToCentralRepositoryL(aCRKey, iNumber->Des(), *iRepository); |
|
115 } |
|
116 |
|
117 |
|
118 |
|
119 const HBufC* CPhonebookContact::Name() |
|
120 { |
|
121 return iName; |
|
122 } |
|
123 |
|
124 const HBufC* CPhonebookContact::Number() |
|
125 { |
|
126 return iNumber; |
|
127 } |
|
128 |
|
129 |