|
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: CS Utils side class to hold latest conversation entry |
|
15 * by timestamp |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // SYSTEM INCLUDE FILES |
|
21 #include <ccsconversationentry.h> |
|
22 #include <ccsclientconversation.h> |
|
23 |
|
24 // USER INCLUDE FILES |
|
25 #include "ccsdebug.h" |
|
26 |
|
27 // ============================== MEMBER FUNCTIONS ============================ |
|
28 |
|
29 // ---------------------------------------------------------------------------- |
|
30 // CCsClientConversation::CCsClientConversation |
|
31 // Default constructor |
|
32 // ---------------------------------------------------------------------------- |
|
33 CCsClientConversation::CCsClientConversation() |
|
34 { |
|
35 } |
|
36 |
|
37 // ---------------------------------------------------------------------------- |
|
38 // CCsClientConversation::ConstructL |
|
39 // Two phase construction |
|
40 // ---------------------------------------------------------------------------- |
|
41 void CCsClientConversation::ConstructL() |
|
42 { |
|
43 iConversationEntryID = 0; |
|
44 iFirstName = NULL; |
|
45 iLastName = NULL; |
|
46 iContactId = KErrNotFound; |
|
47 iConversationEntry = NULL; |
|
48 iUnreadMessagesCount = 0; |
|
49 } |
|
50 |
|
51 // ---------------------------------------------------------------------------- |
|
52 // CCsClientConversation::NewL |
|
53 // Two Phase constructor |
|
54 // ---------------------------------------------------------------------------- |
|
55 EXPORT_C CCsClientConversation* CCsClientConversation::NewL() |
|
56 { |
|
57 CCsClientConversation* self = new (ELeave) CCsClientConversation(); |
|
58 CleanupStack::PushL(self); |
|
59 self->ConstructL(); |
|
60 CleanupStack::Pop(self); |
|
61 return self; |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 // CCsClientConversation::~CCsClientConversation |
|
66 // Destructor |
|
67 // ---------------------------------------------------------------------------- |
|
68 EXPORT_C CCsClientConversation::~CCsClientConversation() |
|
69 { |
|
70 if (iNickName) |
|
71 { |
|
72 delete iNickName; |
|
73 iNickName = NULL; |
|
74 } |
|
75 |
|
76 if (iLastName) |
|
77 { |
|
78 delete iLastName; |
|
79 iLastName = NULL; |
|
80 } |
|
81 if (iFirstName) |
|
82 { |
|
83 delete iFirstName; |
|
84 iFirstName = NULL; |
|
85 } |
|
86 if (iConversationEntry) |
|
87 { |
|
88 delete iConversationEntry; |
|
89 iConversationEntry = NULL; |
|
90 } |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------------------------- |
|
94 // CCsClientConversation::GetConversationEntryIdList |
|
95 // this shall return the conversation Entry Id |
|
96 // ---------------------------------------------------------------------------- |
|
97 EXPORT_C TCsConversationEntryID |
|
98 CCsClientConversation::GetConversationEntryId() const |
|
99 { |
|
100 return iConversationEntryID; |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------------------------------- |
|
104 // CCsClientConversation::AddConversationEntryId |
|
105 // this function shall set conversation entry ID in the object |
|
106 // ---------------------------------------------------------------------------- |
|
107 EXPORT_C void |
|
108 CCsClientConversation::SetConversationEntryId(TCsConversationEntryID aEnryId) |
|
109 { |
|
110 iConversationEntryID = aEnryId; |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // CCsClientConversation::GetFirstName |
|
115 // this shall return the conversation first name of the object |
|
116 // ---------------------------------------------------------------------------- |
|
117 EXPORT_C HBufC* CCsClientConversation::GetFirstName() const |
|
118 { |
|
119 return iFirstName; |
|
120 } |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // CCsClientConversation::SetFirstNameL |
|
124 // this function shall set conversation first name in the object |
|
125 // ---------------------------------------------------------------------------- |
|
126 EXPORT_C void |
|
127 CCsClientConversation::SetFirstNameL(const HBufC* aFirstName) |
|
128 { |
|
129 if (aFirstName) |
|
130 { |
|
131 iFirstName = aFirstName->AllocL(); |
|
132 } |
|
133 } |
|
134 |
|
135 // ---------------------------------------------------------------------------- |
|
136 // CCsClientConversation::GetLastName |
|
137 // this shall return the conversation Last name of the object |
|
138 // ---------------------------------------------------------------------------- |
|
139 EXPORT_C HBufC* CCsClientConversation::GetLastName() const |
|
140 { |
|
141 return iLastName; |
|
142 } |
|
143 |
|
144 // ---------------------------------------------------------------------------- |
|
145 // CCsClientConversation::SetLastNameL |
|
146 // this function shall set conversation Last name in the object |
|
147 // ---------------------------------------------------------------------------- |
|
148 EXPORT_C void |
|
149 CCsClientConversation::SetLastNameL(const HBufC* aLastName) |
|
150 { |
|
151 if (aLastName) |
|
152 { |
|
153 iLastName = aLastName->AllocL(); |
|
154 } |
|
155 } |
|
156 |
|
157 // ---------------------------------------------------------------------------- |
|
158 // CCsClientConversation::GetNickName |
|
159 // this shall return the conversation nick name of the object |
|
160 // ---------------------------------------------------------------------------- |
|
161 EXPORT_C HBufC* CCsClientConversation::GetNickName() const |
|
162 { |
|
163 return iNickName; |
|
164 } |
|
165 |
|
166 // ---------------------------------------------------------------------------- |
|
167 // CCsClientConversation::SetNickNameL |
|
168 // this function shall set conversation nick name in the object |
|
169 // ---------------------------------------------------------------------------- |
|
170 EXPORT_C void |
|
171 CCsClientConversation::SetNickNameL(const HBufC* aNickName) |
|
172 { |
|
173 if (aNickName) |
|
174 { |
|
175 iNickName = aNickName->AllocL(); |
|
176 } |
|
177 } |
|
178 |
|
179 // ---------------------------------------------------------------------------- |
|
180 // CCsClientConversation::GetContactId |
|
181 // this function shall return contact Id of the object |
|
182 // ---------------------------------------------------------------------------- |
|
183 EXPORT_C TInt32 |
|
184 CCsClientConversation::GetContactId() const |
|
185 { |
|
186 return iContactId; |
|
187 } |
|
188 |
|
189 // ---------------------------------------------------------------------------- |
|
190 // CCsClientConversation::SetContactId |
|
191 // this function shall set the phonebook contact Id in the object |
|
192 // ---------------------------------------------------------------------------- |
|
193 EXPORT_C void |
|
194 CCsClientConversation::SetContactId(const TInt32 aContactId) |
|
195 { |
|
196 iContactId = aContactId; |
|
197 } |
|
198 |
|
199 // ---------------------------------------------------------------------------- |
|
200 // CCsClientConversation::GetConversationEntry |
|
201 // this function shall return the latest conversation entry by timestamp of |
|
202 // conversation identified by iConversationEntryID of the object |
|
203 // ---------------------------------------------------------------------------- |
|
204 EXPORT_C CCsConversationEntry* |
|
205 CCsClientConversation::GetConversationEntry() const |
|
206 { |
|
207 return iConversationEntry; |
|
208 } |
|
209 |
|
210 // ---------------------------------------------------------------------------- |
|
211 // CCsClientConversation::SetConversationEntryL |
|
212 // this function shall set the latest conversation entry by timestamp of |
|
213 // conversation identified by iConversationEntryID of the object |
|
214 // ---------------------------------------------------------------------------- |
|
215 EXPORT_C void |
|
216 CCsClientConversation::SetConversationEntryL( |
|
217 const CCsConversationEntry* aCsConversationEntry) |
|
218 { |
|
219 if (aCsConversationEntry) |
|
220 { |
|
221 iConversationEntry = aCsConversationEntry->CloneL(); |
|
222 } |
|
223 } |
|
224 |
|
225 // ---------------------------------------------------------------------------- |
|
226 // CCsClientConversation::CloneL |
|
227 // This function return the clone of object |
|
228 // ---------------------------------------------------------------------------- |
|
229 EXPORT_C CCsClientConversation* CCsClientConversation::CloneL() const |
|
230 { |
|
231 CCsClientConversation* cloneObject = CCsClientConversation::NewL(); |
|
232 CleanupStack::PushL(cloneObject); |
|
233 |
|
234 cloneObject->SetConversationEntryId(iConversationEntryID); |
|
235 cloneObject->SetFirstNameL(iFirstName); |
|
236 cloneObject->SetLastNameL(iLastName); |
|
237 cloneObject->SetContactId(iContactId); |
|
238 cloneObject->SetConversationEntryL(iConversationEntry); |
|
239 cloneObject->SetUnreadMessageCount(iUnreadMessagesCount); |
|
240 |
|
241 CleanupStack::Pop(cloneObject); |
|
242 |
|
243 return cloneObject; |
|
244 } |
|
245 |
|
246 // ---------------------------------------------------------------------------- |
|
247 // CCsClientConversation::ExternalizeL |
|
248 // Writes CCsClientConversation object to the stream |
|
249 // ---------------------------------------------------------------------------- |
|
250 EXPORT_C void CCsClientConversation::ExternalizeL(RWriteStream& aStream) const |
|
251 { |
|
252 // write iConversationEntryID count into the stream |
|
253 aStream.WriteInt32L(iConversationEntryID); |
|
254 aStream.WriteUint16L(iUnreadMessagesCount); |
|
255 |
|
256 if (iFirstName) |
|
257 { |
|
258 // now write the display name |
|
259 aStream.WriteInt8L(iFirstName->Length()); |
|
260 aStream << *iFirstName; |
|
261 } |
|
262 else |
|
263 { |
|
264 aStream.WriteInt8L(0); |
|
265 } |
|
266 |
|
267 if (iLastName) |
|
268 { |
|
269 // now write the display name |
|
270 aStream.WriteInt8L(iLastName->Length()); |
|
271 aStream << *iLastName; |
|
272 } |
|
273 else |
|
274 { |
|
275 aStream.WriteInt8L(0); |
|
276 } |
|
277 |
|
278 if (iNickName) |
|
279 { |
|
280 // now write the display name |
|
281 aStream.WriteInt8L(iNickName->Length()); |
|
282 aStream << *iNickName; |
|
283 } |
|
284 else |
|
285 { |
|
286 aStream.WriteInt8L(0); |
|
287 } |
|
288 |
|
289 // phonebook contactId |
|
290 aStream.WriteInt32L(iContactId); |
|
291 |
|
292 // write iConversationEntry count into the stream |
|
293 if (iConversationEntry) |
|
294 { |
|
295 iConversationEntry->ExternalizeL(aStream); |
|
296 } |
|
297 } |
|
298 |
|
299 // ---------------------------------------------------------------------------- |
|
300 // CCsClientConversation::InternalizeL |
|
301 // Initializes CCsClientConversation from stream |
|
302 // ---------------------------------------------------------------------------- |
|
303 EXPORT_C void CCsClientConversation::InternalizeL( |
|
304 RReadStream& aStream) |
|
305 { |
|
306 // now read the conversation id |
|
307 |
|
308 iConversationEntryID = aStream.ReadInt32L(); |
|
309 iUnreadMessagesCount = aStream.ReadUint16L(); |
|
310 // read first name |
|
311 TInt lenFirstname = aStream.ReadInt8L(); |
|
312 if (lenFirstname > 0) |
|
313 { |
|
314 iFirstName = HBufC::NewL(aStream, lenFirstname); |
|
315 } |
|
316 // read last name |
|
317 TInt lenLastname = aStream.ReadInt8L(); |
|
318 if (lenLastname > 0) |
|
319 { |
|
320 iLastName = HBufC::NewL(aStream, lenLastname); |
|
321 } |
|
322 |
|
323 //read nick name |
|
324 TInt lenNickname = aStream.ReadInt8L(); |
|
325 if (lenNickname > 0) |
|
326 { |
|
327 iNickName = HBufC::NewL(aStream, lenNickname); |
|
328 } |
|
329 |
|
330 // read contact link |
|
331 iContactId = aStream.ReadInt32L(); |
|
332 |
|
333 //Conversation entry |
|
334 iConversationEntry = CCsConversationEntry::NewL(); |
|
335 iConversationEntry->InternalizeL(aStream); |
|
336 } |
|
337 |
|
338 // ---------------------------------------------------------------------------- |
|
339 // CCsClientConversation::CompareByTimeStamp |
|
340 // Compares 2 CCsClientConversation objects based on the latest |
|
341 // conversation entry by time stamp |
|
342 // ---------------------------------------------------------------------------- |
|
343 EXPORT_C TInt CCsClientConversation::CompareByTimeStamp( |
|
344 const CCsClientConversation& obj1, |
|
345 const CCsClientConversation& obj2) |
|
346 { |
|
347 TInt64 timestamp1 = obj1.GetConversationEntry()->TimeStamp(); |
|
348 TInt64 timestamp2 = obj2.GetConversationEntry()->TimeStamp(); |
|
349 TInt result = -1; |
|
350 |
|
351 if ( timestamp1 == timestamp2 ) |
|
352 { |
|
353 result = 0; |
|
354 } |
|
355 else if ( timestamp1 < timestamp2 ) |
|
356 { |
|
357 result = 1; |
|
358 } |
|
359 |
|
360 return result; |
|
361 } |
|
362 |
|
363 // ---------------------------------------------------------------------------- |
|
364 // CCsClientConversation::CompareByConversationEntryId |
|
365 // Compares 2 CCsClientConversation objects based on ConversationEntryId. |
|
366 // ---------------------------------------------------------------------------- |
|
367 EXPORT_C TBool CCsClientConversation::CompareByConversationEntryId( |
|
368 const CCsClientConversation& obj1, |
|
369 const CCsClientConversation& obj2) |
|
370 { |
|
371 TBool result = EFalse; |
|
372 |
|
373 if( obj1.GetConversationEntryId() == obj2.GetConversationEntryId() ) |
|
374 { |
|
375 result = ETrue; |
|
376 } |
|
377 |
|
378 return result; |
|
379 } |
|
380 // ---------------------------------------------------------------------------- |
|
381 // CCsClientConversation::GetUnreadMessageCount |
|
382 // returns the unread message count in the conversation |
|
383 // ---------------------------------------------------------------------------- |
|
384 EXPORT_C TUint16 CCsClientConversation::GetUnreadMessageCount() const |
|
385 { |
|
386 return iUnreadMessagesCount; |
|
387 } |
|
388 // ---------------------------------------------------------------------------- |
|
389 // CCsClientConversation::SetUnreadMessageCount |
|
390 // Sets the unread message count |
|
391 // ---------------------------------------------------------------------------- |
|
392 EXPORT_C void CCsClientConversation::SetUnreadMessageCount(TUint16 aCount) |
|
393 { |
|
394 iUnreadMessagesCount = aCount; |
|
395 } |
|
396 // end of file |