|
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: Client side class to hold the conversation entry. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // SYSTEM INCLUDE FILES |
|
20 #include <ccsconversationentry.h> |
|
21 |
|
22 // USER INCLUDE FILES |
|
23 #include "ccsdebug.h" |
|
24 |
|
25 // CONSTANTS |
|
26 const TInt KMaxDescrSize = 1500; // Message body restricted to this size |
|
27 |
|
28 // ============================== MEMBER FUNCTIONS ============================ |
|
29 |
|
30 // ---------------------------------------------------------------------------- |
|
31 // CCsConEntry::CCsConEntry |
|
32 // Default constructor |
|
33 // ---------------------------------------------------------------------------- |
|
34 CCsConversationEntry::CCsConversationEntry() |
|
35 { |
|
36 } |
|
37 |
|
38 // ---------------------------------------------------------------------------- |
|
39 // CCsConversationEntry::ConstructL |
|
40 // Two phase construction |
|
41 // ---------------------------------------------------------------------------- |
|
42 void CCsConversationEntry::ConstructL() |
|
43 { |
|
44 iEntryID = 0; |
|
45 iTimeStamp = 0; |
|
46 iContact = NULL; |
|
47 iConversationDir = ECsDirectionUnknown; |
|
48 iDescription = NULL; |
|
49 iConversationType = ECsUnknown; |
|
50 iConversationAttrib = ECsAttributeNone; |
|
51 iConversationStatus = ECsSendStateUnknown; |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // CCsConversationEntry::NewL |
|
56 // Two Phase constructor |
|
57 // ---------------------------------------------------------------------------- |
|
58 EXPORT_C CCsConversationEntry* CCsConversationEntry::NewL() |
|
59 { |
|
60 CCsConversationEntry* self = new (ELeave) CCsConversationEntry(); |
|
61 CleanupStack::PushL(self); |
|
62 self->ConstructL(); |
|
63 CleanupStack::Pop(self); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // CCsConversationEntry::~CCsConversationEntry |
|
69 // Destructor |
|
70 // ---------------------------------------------------------------------------- |
|
71 EXPORT_C CCsConversationEntry::~CCsConversationEntry() |
|
72 { |
|
73 // delete the iContact if its allocated |
|
74 if(iContact) |
|
75 { |
|
76 delete iContact; |
|
77 iContact = NULL; |
|
78 } |
|
79 |
|
80 // delete the iDescription if its allocated |
|
81 if(iDescription) |
|
82 { |
|
83 delete iDescription; |
|
84 iDescription = NULL; |
|
85 } |
|
86 } |
|
87 |
|
88 // ---------------------------------------------------------------------------- |
|
89 // CCsConEntry::EntryId |
|
90 // Returns the EntryId of the object |
|
91 // ---------------------------------------------------------------------------- |
|
92 EXPORT_C TInt CCsConversationEntry::EntryId() const |
|
93 { |
|
94 return iEntryID; |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------------------------- |
|
98 // CCsConversationEntry::SetEntryId |
|
99 // Sets the entryID of this object |
|
100 // ---------------------------------------------------------------------------- |
|
101 EXPORT_C void CCsConversationEntry::SetEntryId(const TInt aEnryId) |
|
102 { |
|
103 iEntryID = aEnryId; |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------------------- |
|
107 // CCsConversationEntry::TimeStamp |
|
108 // Provides the Conversation TimeStamp of this object |
|
109 // ---------------------------------------------------------------------------- |
|
110 EXPORT_C TInt64 CCsConversationEntry::TimeStamp() const |
|
111 { |
|
112 return iTimeStamp; |
|
113 } |
|
114 |
|
115 // ---------------------------------------------------------------------------- |
|
116 // CCsConversationEntry::SetTimeStampL |
|
117 // Sets the Conversation TimeStamp of this object |
|
118 // ---------------------------------------------------------------------------- |
|
119 EXPORT_C void CCsConversationEntry::SetTimeStampL(const TInt64 aTimeStamp) |
|
120 { |
|
121 iTimeStamp = aTimeStamp; |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // CCsConversationEntry::Contact |
|
126 // Provides the Conversation contact of this object |
|
127 // ---------------------------------------------------------------------------- |
|
128 EXPORT_C HBufC* CCsConversationEntry::Contact() const |
|
129 { |
|
130 return iContact; |
|
131 } |
|
132 |
|
133 // ---------------------------------------------------------------------------- |
|
134 // CCsConversationEntry::SetContactL |
|
135 // Sets the Conversation contact of this object |
|
136 // ---------------------------------------------------------------------------- |
|
137 EXPORT_C void CCsConversationEntry::SetContactL(const TDesC& aContact) |
|
138 { |
|
139 iContact = aContact.AllocL(); |
|
140 } |
|
141 |
|
142 // ---------------------------------------------------------------------------- |
|
143 // CCsConversationEntry::ConversationDir |
|
144 // Provides the Conversation direction of this object |
|
145 // ---------------------------------------------------------------------------- |
|
146 EXPORT_C TCsDirection CCsConversationEntry::ConversationDir() const |
|
147 { |
|
148 return iConversationDir; |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // CCsConversationEntry::SetConversationDir |
|
153 // Sets the Conversation direction of this object |
|
154 // ---------------------------------------------------------------------------- |
|
155 EXPORT_C void CCsConversationEntry::SetConversationDir( |
|
156 const TCsDirection aConversationDir) |
|
157 { |
|
158 iConversationDir = aConversationDir; |
|
159 } |
|
160 |
|
161 // ---------------------------------------------------------------------------- |
|
162 // CCsConversationEntry::GetType |
|
163 // Provides the conversation flags of the object |
|
164 // ---------------------------------------------------------------------------- |
|
165 EXPORT_C TCsType CCsConversationEntry::GetType() const |
|
166 { |
|
167 return iConversationType; |
|
168 } |
|
169 |
|
170 // ---------------------------------------------------------------------------- |
|
171 // CCsConversationEntry::SetType |
|
172 // Sets the conversation flags of this object |
|
173 // ---------------------------------------------------------------------------- |
|
174 EXPORT_C void CCsConversationEntry::SetType(const TCsType& aCsConversationType) |
|
175 { |
|
176 iConversationType = aCsConversationType; |
|
177 } |
|
178 |
|
179 // ---------------------------------------------------------------------------- |
|
180 // CCsConversationEntry::GetSendState |
|
181 // Provides the conversation status of this object |
|
182 // ---------------------------------------------------------------------------- |
|
183 EXPORT_C TCsSendState CCsConversationEntry::GetSendState() const |
|
184 { |
|
185 return iConversationStatus; |
|
186 } |
|
187 |
|
188 // ---------------------------------------------------------------------------- |
|
189 // CCsConversationEntry::SetSendState |
|
190 // Sets the conversation status of this object |
|
191 // ---------------------------------------------------------------------------- |
|
192 EXPORT_C void CCsConversationEntry::SetSendState(const TCsSendState& aCsConversationStatus) |
|
193 { |
|
194 iConversationStatus = aCsConversationStatus; |
|
195 } |
|
196 |
|
197 // ---------------------------------------------------------------------------- |
|
198 // CCsConversationEntry::Description |
|
199 // Provides the Conversation description(body) of this object |
|
200 // ---------------------------------------------------------------------------- |
|
201 EXPORT_C HBufC* CCsConversationEntry::Description() const |
|
202 { |
|
203 return iDescription; |
|
204 } |
|
205 |
|
206 // ---------------------------------------------------------------------------- |
|
207 // CCsConversationEntry::SetDescriptionL |
|
208 // Sets the Conversation description of this object |
|
209 // ---------------------------------------------------------------------------- |
|
210 EXPORT_C void CCsConversationEntry::SetDescriptionL(const TDesC& aDescription) |
|
211 { |
|
212 |
|
213 TInt descrLength = aDescription.Length(); |
|
214 if (descrLength > KMaxDescrSize) |
|
215 descrLength = KMaxDescrSize; |
|
216 iDescription = HBufC::NewL(descrLength); |
|
217 iDescription->Des().Copy(aDescription.Left(descrLength)); |
|
218 |
|
219 } |
|
220 |
|
221 // ---------------------------------------------------------------------------- |
|
222 // CCsConversationEntry::ChangeAttributes |
|
223 // Sets or Clears the given attribute(s). |
|
224 // ---------------------------------------------------------------------------- |
|
225 EXPORT_C void CCsConversationEntry::ChangeAttributes( TUint16 aSetAttributes, |
|
226 TUint16 aClearAttributes ) |
|
227 { |
|
228 // Set attribute(s) |
|
229 iConversationAttrib |= aSetAttributes; |
|
230 |
|
231 // Clear atttibute(s) |
|
232 iConversationAttrib &= ~aClearAttributes; |
|
233 } |
|
234 |
|
235 // ---------------------------------------------------------------------------- |
|
236 // CCsConversationEntry::IsAttributeSet |
|
237 // Checks if the give attribute is set. |
|
238 // ---------------------------------------------------------------------------- |
|
239 EXPORT_C TBool CCsConversationEntry::IsAttributeSet(TCsAttribute aAttribute ) const |
|
240 { |
|
241 return ( iConversationAttrib & aAttribute ); |
|
242 } |
|
243 |
|
244 // ---------------------------------------------------------------------------- |
|
245 // CCsConversationEntry::CloneL |
|
246 // Provides the clone of this object |
|
247 // ---------------------------------------------------------------------------- |
|
248 EXPORT_C CCsConversationEntry* CCsConversationEntry::CloneL() const |
|
249 { |
|
250 CCsConversationEntry* cloneObject = CCsConversationEntry::NewL(); |
|
251 CleanupStack::PushL(cloneObject); |
|
252 |
|
253 if (iContact) |
|
254 cloneObject->SetContactL(*iContact); |
|
255 |
|
256 cloneObject->SetConversationDir(iConversationDir); |
|
257 cloneObject->SetType(iConversationType); |
|
258 cloneObject->SetEntryId(iEntryID); |
|
259 cloneObject->SetSendState(iConversationStatus); |
|
260 cloneObject->ChangeAttributes(iConversationAttrib, ECsAttributeNone); |
|
261 if(iDescription) |
|
262 cloneObject->SetDescriptionL(*iDescription); |
|
263 cloneObject->SetTimeStampL(iTimeStamp); |
|
264 |
|
265 CleanupStack::Pop(cloneObject); |
|
266 return cloneObject; |
|
267 } |
|
268 |
|
269 //------------------------------------------------------------------------------ |
|
270 // CCsConversationEntry::ExternalizeL |
|
271 // Writes CCsConversationEntry variable to the stream |
|
272 // ---------------------------------------------------------------------------- |
|
273 EXPORT_C void CCsConversationEntry::ExternalizeL(RWriteStream& aStream) const |
|
274 { |
|
275 // write iEntryId into the stream |
|
276 aStream.WriteInt32L(iEntryID); |
|
277 |
|
278 // write iTimeStamp |
|
279 aStream.WriteReal64L(iTimeStamp); |
|
280 |
|
281 // write iConversationAttrib |
|
282 aStream.WriteUint16L(iConversationAttrib); |
|
283 |
|
284 if (iContact) |
|
285 { |
|
286 // write iContact length |
|
287 aStream.WriteInt8L(iContact->Length()); |
|
288 // write iContact |
|
289 aStream << *iContact; |
|
290 } |
|
291 else |
|
292 { |
|
293 // write 0 contact len |
|
294 aStream.WriteInt8L(0); |
|
295 } |
|
296 |
|
297 // write iConDir length |
|
298 aStream.WriteUint8L(iConversationDir); |
|
299 |
|
300 if (iDescription) |
|
301 { |
|
302 // write iDescription length |
|
303 aStream.WriteUint16L(iDescription->Length()); |
|
304 // write iDescription |
|
305 aStream << *iDescription; |
|
306 } |
|
307 else |
|
308 { |
|
309 // write 0 iDescription len |
|
310 aStream.WriteUint16L(0); |
|
311 } |
|
312 |
|
313 // write iConversationType |
|
314 aStream.WriteUint8L(iConversationType); |
|
315 |
|
316 // write iConversationStatus |
|
317 aStream.WriteUint8L(iConversationStatus); |
|
318 } |
|
319 |
|
320 // ---------------------------------------------------------------------------- |
|
321 // CCsConversationEntry::InternalizeL |
|
322 // Initializes CCsConversationEntry from stream |
|
323 // ---------------------------------------------------------------------------- |
|
324 EXPORT_C void CCsConversationEntry::InternalizeL(RReadStream& aStream) |
|
325 { |
|
326 // Read iEntryID length |
|
327 iEntryID = aStream.ReadInt32L(); |
|
328 |
|
329 // read iTimeStamp |
|
330 iTimeStamp = aStream.ReadReal64L(); |
|
331 |
|
332 // read iConversationAttrib |
|
333 iConversationAttrib = aStream.ReadUint16L(); |
|
334 |
|
335 // Read iContact length |
|
336 TInt lenContact = aStream.ReadInt8L(); |
|
337 |
|
338 if (lenContact > 0) |
|
339 { |
|
340 // read iContact |
|
341 iContact = HBufC::NewL(aStream, lenContact); |
|
342 } |
|
343 else |
|
344 iContact = NULL; |
|
345 |
|
346 // Read iConversationDir |
|
347 iConversationDir = |
|
348 static_cast<TCsDirection> (aStream.ReadUint8L()); |
|
349 |
|
350 // Read iDescription length |
|
351 TInt lenDescription = aStream.ReadUint16L(); |
|
352 |
|
353 if (lenDescription > 0) |
|
354 { |
|
355 // read iDescription |
|
356 iDescription = HBufC::NewL(aStream, lenDescription); |
|
357 } |
|
358 |
|
359 // Read iConversationType |
|
360 iConversationType = |
|
361 static_cast<TCsType> (aStream.ReadUint8L()); |
|
362 |
|
363 // Read iConversationStatus |
|
364 iConversationStatus = |
|
365 static_cast<TCsSendState> (aStream.ReadUint8L()); |
|
366 } |
|
367 |
|
368 //----------------------------------------------------------------------------- |
|
369 // CCsConversationEntry::Compare |
|
370 // Compare to conversation entry object based on timestamp |
|
371 //---------------------------------------------------------------------------- |
|
372 EXPORT_C TInt CCsConversationEntry::Compare( |
|
373 const CCsConversationEntry& aFirst, |
|
374 const CCsConversationEntry& aSecond) |
|
375 { |
|
376 |
|
377 if (aFirst.EntryId() < aSecond.EntryId()) |
|
378 return -1; |
|
379 if (aFirst.EntryId() > aSecond.EntryId()) |
|
380 return 1; |
|
381 return 0; |
|
382 } |
|
383 |
|
384 //----------------------------------------------------------------------------- |
|
385 // CCsConversationEntry::CompareById |
|
386 // Compare to conversation entry object based on Entry Ids |
|
387 //---------------------------------------------------------------------------- |
|
388 EXPORT_C TBool CCsConversationEntry::CompareById( |
|
389 const CCsConversationEntry& aFirst, |
|
390 const CCsConversationEntry& aSecond) |
|
391 { |
|
392 if (aFirst.EntryId() == aSecond.EntryId()) |
|
393 return ETrue; |
|
394 |
|
395 return EFalse; |
|
396 } |
|
397 |
|
398 //----------------------------------------------------------------------------- |
|
399 // CCsConversationEntry::CompareByUnreadAttrib |
|
400 // Compare to conversation entry object based on their unread attribute. |
|
401 //---------------------------------------------------------------------------- |
|
402 EXPORT_C TBool CCsConversationEntry::CompareByUnreadAttrib( |
|
403 const CCsConversationEntry& aFirst, |
|
404 const CCsConversationEntry& aSecond) |
|
405 { |
|
406 if (aFirst.IsAttributeSet(ECsAttributeUnread) == |
|
407 aSecond.IsAttributeSet(ECsAttributeUnread)) |
|
408 return ETrue; |
|
409 |
|
410 return EFalse; |
|
411 } |
|
412 |
|
413 //EOF |