|
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: This shall hold all the contact data associated with a |
|
15 * conversation like name, numbers and contact link . |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // SYSTEM INCLUDE FILES |
|
21 #include <miutpars.h> |
|
22 |
|
23 // USER INCLUDE FILES |
|
24 #include "ccsconversation.h" |
|
25 #include "ccsconversationcontact.h" |
|
26 #include "ccsdebug.h" |
|
27 |
|
28 // ============================== MEMBER FUNCTIONS ============================ |
|
29 |
|
30 // ---------------------------------------------------------------------------- |
|
31 // CCsConversationContact::CCsConversationContact |
|
32 // Default constructor |
|
33 // ---------------------------------------------------------------------------- |
|
34 CCsConversationContact::CCsConversationContact() |
|
35 { |
|
36 } |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // CCsConversationContact::ConstructL |
|
40 // Two phase construction |
|
41 // ---------------------------------------------------------------------------- |
|
42 void |
|
43 CCsConversationContact::ConstructL() |
|
44 { |
|
45 iFirstName = NULL; |
|
46 iLastName = NULL; |
|
47 iNickName = NULL; |
|
48 iContactId = KErrNotFound; |
|
49 iPhoneNumberList = new (ELeave) RPointerArray<HBufC> (); |
|
50 } |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // CCsConversationContact::NewL |
|
54 // Two Phase constructor |
|
55 // ---------------------------------------------------------------------------- |
|
56 CCsConversationContact* |
|
57 CCsConversationContact::NewL() |
|
58 { |
|
59 CCsConversationContact* self = new (ELeave) CCsConversationContact(); |
|
60 CleanupStack::PushL(self); |
|
61 self->ConstructL(); |
|
62 CleanupStack::Pop(self); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // CCsConversationContact::~CCsConversationContact |
|
68 // Destructor |
|
69 // ---------------------------------------------------------------------------- |
|
70 CCsConversationContact::~CCsConversationContact() |
|
71 { |
|
72 if(iFirstName) |
|
73 { |
|
74 delete iFirstName; |
|
75 iFirstName = NULL; |
|
76 } |
|
77 |
|
78 if(iLastName) |
|
79 { |
|
80 delete iLastName; |
|
81 iLastName = NULL; |
|
82 } |
|
83 |
|
84 if(iNickName) |
|
85 { |
|
86 delete iNickName; |
|
87 iNickName = NULL; |
|
88 } |
|
89 |
|
90 if (iPhoneNumberList) |
|
91 { |
|
92 iPhoneNumberList->ResetAndDestroy(); |
|
93 iPhoneNumberList->Close(); |
|
94 delete iPhoneNumberList; |
|
95 iPhoneNumberList = NULL; |
|
96 } |
|
97 } |
|
98 |
|
99 // ---------------------------------------------------------------------------- |
|
100 // CCsConversationContact::GetFirstName |
|
101 // get the first name of the conversation |
|
102 // ---------------------------------------------------------------------------- |
|
103 HBufC* |
|
104 CCsConversationContact::GetFirstName() const |
|
105 { |
|
106 return iFirstName; |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // CCsConversationContact::GetLastName |
|
111 // get the last name of the conversation |
|
112 // ---------------------------------------------------------------------------- |
|
113 HBufC* |
|
114 CCsConversationContact::GetLastName() const |
|
115 { |
|
116 return iLastName; |
|
117 } |
|
118 |
|
119 // ---------------------------------------------------------------------------- |
|
120 // CCsConversationContact::GetNickName |
|
121 // get the nick name of the conversation |
|
122 // ---------------------------------------------------------------------------- |
|
123 HBufC* |
|
124 CCsConversationContact::GetNickName() const |
|
125 { |
|
126 return iNickName; |
|
127 } |
|
128 |
|
129 // ---------------------------------------------------------------------------- |
|
130 // CCsConversationContact::SetFirstNameL |
|
131 // Sets the first name of the conversation |
|
132 // ---------------------------------------------------------------------------- |
|
133 void |
|
134 CCsConversationContact::SetFirstNameL( |
|
135 const TDesC& aFirstName) |
|
136 { |
|
137 if( &aFirstName ) |
|
138 { |
|
139 TRAPD(error, iFirstName = aFirstName.AllocL()); |
|
140 if(error != KErrNone) |
|
141 { |
|
142 // handle error |
|
143 // call panic |
|
144 PRINT1 ( _L("CCsConversationContact::SetFirstNameL - Error:%d"), |
|
145 error ); |
|
146 } |
|
147 } |
|
148 } |
|
149 |
|
150 // ---------------------------------------------------------------------------- |
|
151 // CCsConversationContact::SetLastNameL |
|
152 // Sets the first name of the conversation |
|
153 // ---------------------------------------------------------------------------- |
|
154 void |
|
155 CCsConversationContact::SetLastNameL( |
|
156 const TDesC& aLastName) |
|
157 { |
|
158 if( &aLastName ) |
|
159 { |
|
160 TRAPD(error, iLastName = aLastName.AllocL()); |
|
161 if(error != KErrNone) |
|
162 { |
|
163 // handle error |
|
164 // call panic |
|
165 PRINT1 ( _L("CCsConversationContact::SetLastNameL - Error:%d"), |
|
166 error ); |
|
167 } |
|
168 } |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // CCsConversationContact::SetNickNameL |
|
173 // Sets the first name of the conversation |
|
174 // ---------------------------------------------------------------------------- |
|
175 void |
|
176 CCsConversationContact::SetNickNameL( |
|
177 const TDesC& aNickName) |
|
178 { |
|
179 if( &aNickName ) |
|
180 { |
|
181 TRAPD(error, iNickName = aNickName.AllocL()); |
|
182 if(error != KErrNone) |
|
183 { |
|
184 // handle error |
|
185 // call panic |
|
186 PRINT1 ( _L("CCsConversationContact::SetNickNameL - Error:%d"), |
|
187 error ); |
|
188 } |
|
189 } |
|
190 } |
|
191 // ---------------------------------------------------------------------------- |
|
192 // CCsConversationContact::GetContactId |
|
193 // get the phonebook Contact Id link for the conversation |
|
194 // ---------------------------------------------------------------------------- |
|
195 TInt32 |
|
196 CCsConversationContact::GetContactId() const |
|
197 { |
|
198 return iContactId; |
|
199 } |
|
200 |
|
201 // ---------------------------------------------------------------------------- |
|
202 // CCsConversationContact::SetContactLink |
|
203 // Sets the phonebook Contact Id for the conversation |
|
204 // ---------------------------------------------------------------------------- |
|
205 void |
|
206 CCsConversationContact::SetContactId( |
|
207 TInt32 aContactId) |
|
208 { |
|
209 iContactId = aContactId; |
|
210 } |
|
211 |
|
212 // ---------------------------------------------------------------------------- |
|
213 // CCsConversationContact::AddPhoneNumber |
|
214 // Sets the phone number inside contact list |
|
215 // ---------------------------------------------------------------------------- |
|
216 void |
|
217 CCsConversationContact::AddPhoneNumberL( |
|
218 TDesC& aPhoneNumber) |
|
219 { |
|
220 HBufC* phoneNumber = aPhoneNumber.AllocL(); |
|
221 iPhoneNumberList->AppendL(phoneNumber); |
|
222 } |
|
223 |
|
224 // ---------------------------------------------------------------------------- |
|
225 // CCsConversationContact::GetPhoneNumberList |
|
226 // Returns a list of associated phone numbers |
|
227 // ---------------------------------------------------------------------------- |
|
228 void |
|
229 CCsConversationContact::GetPhoneNumberList( |
|
230 RPointerArray<TDesC>& aPhoneNumbers) |
|
231 { |
|
232 for ( int index = 0; index < iPhoneNumberList->Count(); index++ ) |
|
233 { |
|
234 HBufC* value = (*iPhoneNumberList)[index]; |
|
235 aPhoneNumbers.Append(value); |
|
236 } |
|
237 } |
|
238 |
|
239 // ---------------------------------------------------------------------------- |
|
240 // CCsConversationContact::MatchPhoneNumber |
|
241 // Check if the input phone number (aPhoneNumber) is associated with this |
|
242 // contact. Compares for aNumDigits. |
|
243 // ---------------------------------------------------------------------------- |
|
244 TBool |
|
245 CCsConversationContact::MatchPhoneNumber( |
|
246 TDesC& aPhoneNumber, TInt aNumDigits) const |
|
247 { |
|
248 if (aPhoneNumber.Length() == 0) |
|
249 { |
|
250 return EFalse; |
|
251 } |
|
252 |
|
253 TInt useDigits = aNumDigits; |
|
254 |
|
255 // Check if phone number is an email address |
|
256 TImMessageField email; |
|
257 if ( email.ValidInternetEmailAddress(aPhoneNumber) ) |
|
258 { |
|
259 useDigits = aPhoneNumber.Length(); |
|
260 } |
|
261 |
|
262 TInt count = iPhoneNumberList->Count(); |
|
263 for ( TInt i = 0 ; i < count; i++) |
|
264 { |
|
265 HBufC* pno = (*iPhoneNumberList)[i]; |
|
266 |
|
267 // Compare only last useDigits dgits of the number/ address |
|
268 if (aPhoneNumber.Right(useDigits).CompareF(pno->Des(). |
|
269 Right(useDigits)) == 0) |
|
270 { |
|
271 return ETrue; |
|
272 } |
|
273 } |
|
274 return EFalse; |
|
275 } |
|
276 |
|
277 |
|
278 // EOF |