|
1 /* |
|
2 * Copyright (c) 2007 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: Implementation of the MNcsEmailAddressObject |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "emailtrace.h" |
|
21 #include "ncsemailaddressobject.h" |
|
22 #include "ncsconstants.h" |
|
23 |
|
24 |
|
25 // CONSTRUCTION AND DESTRUCTION |
|
26 |
|
27 CNcsEmailAddressObject* CNcsEmailAddressObject::NewL( TBool aUserAdded ) |
|
28 { |
|
29 FUNC_LOG; |
|
30 CNcsEmailAddressObject* self = new( ELeave ) CNcsEmailAddressObject( aUserAdded ); |
|
31 CleanupStack::PushL( self ); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop( self ); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CNcsEmailAddressObject* CNcsEmailAddressObject::NewL( |
|
38 const CNcsEmailAddressObject& aAddress ) |
|
39 { |
|
40 FUNC_LOG; |
|
41 CNcsEmailAddressObject* self = new( ELeave ) CNcsEmailAddressObject( aAddress ); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL( aAddress ); |
|
44 CleanupStack::Pop( self ); |
|
45 return self; |
|
46 } |
|
47 |
|
48 CNcsEmailAddressObject* CNcsEmailAddressObject::NewL( |
|
49 const TDesC& aDisplayName, |
|
50 const TDesC& aEmailAddress ) |
|
51 { |
|
52 FUNC_LOG; |
|
53 CNcsEmailAddressObject* self = new( ELeave ) CNcsEmailAddressObject( ETrue ); |
|
54 CleanupStack::PushL( self ); |
|
55 self->ConstructL( aDisplayName, aEmailAddress ); |
|
56 CleanupStack::Pop( self ); |
|
57 return self; |
|
58 } |
|
59 |
|
60 CNcsEmailAddressObject::~CNcsEmailAddressObject() |
|
61 { |
|
62 FUNC_LOG; |
|
63 delete iEmailAddress; |
|
64 delete iDisplayName; |
|
65 delete iFormattedAddress; |
|
66 } |
|
67 |
|
68 CNcsEmailAddressObject::CNcsEmailAddressObject( TBool aUserAdded ) |
|
69 : iDirtyFlag( ETrue ), |
|
70 iUserAdded( aUserAdded ), |
|
71 iDisplayFull( EFalse ) |
|
72 { |
|
73 FUNC_LOG; |
|
74 } |
|
75 |
|
76 CNcsEmailAddressObject::CNcsEmailAddressObject( const CNcsEmailAddressObject& aAddress ) |
|
77 : iDirtyFlag( ETrue ), |
|
78 iUserAdded( aAddress.IsUserAdded() ), |
|
79 iDisplayFull( aAddress.DisplayFull() ) |
|
80 { |
|
81 FUNC_LOG; |
|
82 } |
|
83 |
|
84 void CNcsEmailAddressObject::ConstructL() |
|
85 { |
|
86 FUNC_LOG; |
|
87 iEmailAddress = HBufC::NewL( 0 ); |
|
88 iDisplayName = HBufC::NewL( 0 ); |
|
89 iFormattedAddress = HBufC::NewL( 0 ); |
|
90 } |
|
91 |
|
92 void CNcsEmailAddressObject::ConstructL( |
|
93 const CNcsEmailAddressObject& aAddress ) |
|
94 { |
|
95 FUNC_LOG; |
|
96 ConstructL( aAddress.DisplayName(), aAddress.EmailAddress() ); |
|
97 } |
|
98 |
|
99 void CNcsEmailAddressObject::ConstructL( |
|
100 const TDesC& aDisplayName, |
|
101 const TDesC& aEmailAddress ) |
|
102 { |
|
103 FUNC_LOG; |
|
104 iEmailAddress = aEmailAddress.AllocL(); |
|
105 TPtr ptr = iEmailAddress->Des(); |
|
106 ptr.Trim(); |
|
107 |
|
108 iDisplayName = aDisplayName.AllocL(); |
|
109 |
|
110 iFormattedAddress = HBufC::NewL( 0 ); |
|
111 } |
|
112 |
|
113 |
|
114 // METHODS |
|
115 |
|
116 void CNcsEmailAddressObject::SetEmailAddressL( const TDesC& aEmailAddress ) |
|
117 { |
|
118 FUNC_LOG; |
|
119 HBufC* buf = aEmailAddress.AllocL(); |
|
120 delete iEmailAddress; |
|
121 iEmailAddress = buf; |
|
122 |
|
123 TPtr ptr = iEmailAddress->Des(); |
|
124 ptr.Trim(); |
|
125 |
|
126 iDirtyFlag = ETrue; |
|
127 } |
|
128 |
|
129 void CNcsEmailAddressObject::SetDisplayNameL( |
|
130 const TDesC& aGivenName, |
|
131 const TDesC& aFamilyName ) |
|
132 { |
|
133 FUNC_LOG; |
|
134 TInt len = aGivenName.Length() + aFamilyName.Length() + KLastNameFirstNameSeparator().Length(); |
|
135 delete iDisplayName; |
|
136 iDisplayName = NULL; |
|
137 iDisplayName = HBufC::NewL( len ); |
|
138 TPtr ptr = iDisplayName->Des(); |
|
139 ptr.Append( aFamilyName ); |
|
140 ptr.Append( KLastNameFirstNameSeparator ); |
|
141 ptr.Append( aGivenName ); |
|
142 |
|
143 iDirtyFlag = ETrue; |
|
144 } |
|
145 |
|
146 void CNcsEmailAddressObject::SetDisplayNameL( const TDesC& aName ) |
|
147 { |
|
148 FUNC_LOG; |
|
149 HBufC* buf = aName.AllocL(); |
|
150 delete iDisplayName; |
|
151 iDisplayName = buf; |
|
152 |
|
153 TPtr ptr = iEmailAddress->Des(); |
|
154 ptr.Trim(); |
|
155 |
|
156 iDirtyFlag = ETrue; |
|
157 } |
|
158 |
|
159 const TDesC& CNcsEmailAddressObject::FormattedAddressL() |
|
160 { |
|
161 FUNC_LOG; |
|
162 if( iDirtyFlag ) |
|
163 { |
|
164 GenerateFormattedAddressL(); |
|
165 iDirtyFlag = EFalse; |
|
166 } |
|
167 |
|
168 return *iFormattedAddress; |
|
169 } |
|
170 |
|
171 void CNcsEmailAddressObject::GenerateFormattedAddressL() |
|
172 { |
|
173 FUNC_LOG; |
|
174 TInt length = 0; |
|
175 HBufC* buf = NULL; |
|
176 |
|
177 TInt dispNameLength = iDisplayName->Length(); |
|
178 TInt emailLength = iEmailAddress->Length(); |
|
179 |
|
180 if( dispNameLength > 0 ) |
|
181 { |
|
182 // format is "Name Lastname <name.lastnamemiumaudot.com>" |
|
183 length = dispNameLength + emailLength + |
|
184 KSpace().Length() + |
|
185 KEmailAddressDecorationHead().Length() + |
|
186 KEmailAddressDecorationTail().Length() + |
|
187 KEmailAddressSeparator().Length(); |
|
188 |
|
189 buf = HBufC::NewL( length ); |
|
190 TPtr ptr = buf->Des(); |
|
191 |
|
192 ptr.Append( *iDisplayName ); |
|
193 ptr.Append( KSpace ); |
|
194 ptr.Append( KEmailAddressDecorationHead ); |
|
195 ptr.Append( *iEmailAddress ); |
|
196 ptr.Append( KEmailAddressDecorationTail ); |
|
197 ptr.Append( KEmailAddressSeparator ); |
|
198 } |
|
199 else |
|
200 { |
|
201 buf = iEmailAddress->AllocL(); |
|
202 } |
|
203 |
|
204 delete iFormattedAddress; |
|
205 iFormattedAddress = buf; |
|
206 } |
|
207 |
|
208 // End of file |
|
209 |