31
|
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 |
iDisplayName = NULL;
|
|
45 |
iContactId = KErrNotFound;
|
|
46 |
iConversationEntry = NULL;
|
|
47 |
iUnreadMessagesCount = 0;
|
|
48 |
}
|
|
49 |
|
|
50 |
// ----------------------------------------------------------------------------
|
|
51 |
// CCsClientConversation::NewL
|
|
52 |
// Two Phase constructor
|
|
53 |
// ----------------------------------------------------------------------------
|
|
54 |
EXPORT_C CCsClientConversation* CCsClientConversation::NewL()
|
|
55 |
{
|
|
56 |
CCsClientConversation* self = new (ELeave) CCsClientConversation();
|
|
57 |
CleanupStack::PushL(self);
|
|
58 |
self->ConstructL();
|
|
59 |
CleanupStack::Pop(self);
|
|
60 |
return self;
|
|
61 |
}
|
|
62 |
|
|
63 |
// ----------------------------------------------------------------------------
|
|
64 |
// CCsClientConversation::~CCsClientConversation
|
|
65 |
// Destructor
|
|
66 |
// ----------------------------------------------------------------------------
|
|
67 |
EXPORT_C CCsClientConversation::~CCsClientConversation()
|
|
68 |
{
|
|
69 |
if (iDisplayName)
|
|
70 |
{
|
|
71 |
delete iDisplayName;
|
|
72 |
iDisplayName = NULL;
|
|
73 |
}
|
|
74 |
if (iConversationEntry)
|
|
75 |
{
|
|
76 |
delete iConversationEntry;
|
|
77 |
iConversationEntry = NULL;
|
|
78 |
}
|
|
79 |
}
|
|
80 |
|
|
81 |
// ----------------------------------------------------------------------------
|
|
82 |
// CCsClientConversation::GetConversationEntryIdList
|
|
83 |
// this shall return the conversation Entry Id
|
|
84 |
// ----------------------------------------------------------------------------
|
|
85 |
EXPORT_C TCsConversationEntryID
|
|
86 |
CCsClientConversation::GetConversationEntryId() const
|
|
87 |
{
|
|
88 |
return iConversationEntryID;
|
|
89 |
}
|
|
90 |
|
|
91 |
// ----------------------------------------------------------------------------
|
|
92 |
// CCsClientConversation::AddConversationEntryId
|
|
93 |
// this function shall set conversation entry ID in the object
|
|
94 |
// ----------------------------------------------------------------------------
|
|
95 |
EXPORT_C void
|
|
96 |
CCsClientConversation::SetConversationEntryId(TCsConversationEntryID aEnryId)
|
|
97 |
{
|
|
98 |
iConversationEntryID = aEnryId;
|
|
99 |
}
|
|
100 |
|
|
101 |
// ----------------------------------------------------------------------------
|
|
102 |
// CCsClientConversation::GetDisplayName
|
|
103 |
// this shall return the conversation name of the object
|
|
104 |
// ----------------------------------------------------------------------------
|
|
105 |
EXPORT_C HBufC* CCsClientConversation::GetDisplayName() const
|
|
106 |
{
|
|
107 |
return iDisplayName;
|
|
108 |
}
|
|
109 |
|
|
110 |
// ----------------------------------------------------------------------------
|
|
111 |
// CCsClientConversation::SetDisplayNameL
|
|
112 |
// this function shall set conversation name in the object
|
|
113 |
// ----------------------------------------------------------------------------
|
|
114 |
EXPORT_C void
|
|
115 |
CCsClientConversation::SetDisplayNameL(
|
|
116 |
const HBufC* aDisplayName)
|
|
117 |
{
|
|
118 |
if (aDisplayName)
|
|
119 |
{
|
|
120 |
iDisplayName = aDisplayName->AllocL();
|
|
121 |
}
|
|
122 |
}
|
|
123 |
|
|
124 |
// ----------------------------------------------------------------------------
|
|
125 |
// CCsClientConversation::GetContactId
|
|
126 |
// this function shall return contact Id of the object
|
|
127 |
// ----------------------------------------------------------------------------
|
|
128 |
EXPORT_C TInt32
|
|
129 |
CCsClientConversation::GetContactId() const
|
|
130 |
{
|
|
131 |
return iContactId;
|
|
132 |
}
|
|
133 |
|
|
134 |
// ----------------------------------------------------------------------------
|
|
135 |
// CCsClientConversation::SetContactId
|
|
136 |
// this function shall set the phonebook contact Id in the object
|
|
137 |
// ----------------------------------------------------------------------------
|
|
138 |
EXPORT_C void
|
|
139 |
CCsClientConversation::SetContactId(const TInt32 aContactId)
|
|
140 |
{
|
|
141 |
iContactId = aContactId;
|
|
142 |
}
|
|
143 |
|
|
144 |
// ----------------------------------------------------------------------------
|
|
145 |
// CCsClientConversation::GetConversationEntry
|
|
146 |
// this function shall return the latest conversation entry by timestamp of
|
|
147 |
// conversation identified by iConversationEntryID of the object
|
|
148 |
// ----------------------------------------------------------------------------
|
|
149 |
EXPORT_C CCsConversationEntry*
|
|
150 |
CCsClientConversation::GetConversationEntry() const
|
|
151 |
{
|
|
152 |
return iConversationEntry;
|
|
153 |
}
|
|
154 |
|
|
155 |
// ----------------------------------------------------------------------------
|
|
156 |
// CCsClientConversation::SetConversationEntryL
|
|
157 |
// this function shall set the latest conversation entry by timestamp of
|
|
158 |
// conversation identified by iConversationEntryID of the object
|
|
159 |
// ----------------------------------------------------------------------------
|
|
160 |
EXPORT_C void
|
|
161 |
CCsClientConversation::SetConversationEntryL(
|
|
162 |
const CCsConversationEntry* aCsConversationEntry)
|
|
163 |
{
|
|
164 |
if (aCsConversationEntry)
|
|
165 |
{
|
|
166 |
iConversationEntry = aCsConversationEntry->CloneL();
|
|
167 |
}
|
|
168 |
}
|
|
169 |
|
|
170 |
// ----------------------------------------------------------------------------
|
|
171 |
// CCsClientConversation::CloneL
|
|
172 |
// This function return the clone of object
|
|
173 |
// ----------------------------------------------------------------------------
|
|
174 |
EXPORT_C CCsClientConversation* CCsClientConversation::CloneL() const
|
|
175 |
{
|
|
176 |
CCsClientConversation* cloneObject = CCsClientConversation::NewL();
|
|
177 |
CleanupStack::PushL(cloneObject);
|
|
178 |
|
|
179 |
cloneObject->SetConversationEntryId(iConversationEntryID);
|
|
180 |
cloneObject->SetDisplayNameL(iDisplayName);
|
|
181 |
cloneObject->SetContactId(iContactId);
|
|
182 |
cloneObject->SetConversationEntryL(iConversationEntry);
|
|
183 |
cloneObject->SetUnreadMessageCount(iUnreadMessagesCount);
|
|
184 |
|
|
185 |
CleanupStack::Pop(cloneObject);
|
|
186 |
|
|
187 |
return cloneObject;
|
|
188 |
}
|
|
189 |
|
|
190 |
// ----------------------------------------------------------------------------
|
|
191 |
// CCsClientConversation::ExternalizeL
|
|
192 |
// Writes CCsClientConversation object to the stream
|
|
193 |
// ----------------------------------------------------------------------------
|
|
194 |
EXPORT_C void CCsClientConversation::ExternalizeL(RWriteStream& aStream) const
|
|
195 |
{
|
|
196 |
// write iConversationEntryID count into the stream
|
|
197 |
aStream.WriteInt32L(iConversationEntryID);
|
|
198 |
aStream.WriteUint16L(iUnreadMessagesCount);
|
|
199 |
|
|
200 |
if (iDisplayName)
|
|
201 |
{
|
|
202 |
// now write the display name
|
|
203 |
aStream.WriteInt8L(iDisplayName->Length());
|
|
204 |
aStream << *iDisplayName;
|
|
205 |
}
|
|
206 |
else
|
|
207 |
{
|
|
208 |
aStream.WriteInt8L(0);
|
|
209 |
}
|
|
210 |
|
|
211 |
// phonebook contactId
|
|
212 |
aStream.WriteInt32L(iContactId);
|
|
213 |
|
|
214 |
// write iConversationEntry count into the stream
|
|
215 |
if (iConversationEntry)
|
|
216 |
{
|
|
217 |
iConversationEntry->ExternalizeL(aStream);
|
|
218 |
}
|
|
219 |
}
|
|
220 |
|
|
221 |
// ----------------------------------------------------------------------------
|
|
222 |
// CCsClientConversation::InternalizeL
|
|
223 |
// Initializes CCsClientConversation from stream
|
|
224 |
// ----------------------------------------------------------------------------
|
|
225 |
EXPORT_C void CCsClientConversation::InternalizeL(
|
|
226 |
RReadStream& aStream)
|
|
227 |
{
|
|
228 |
// now read the conversation id
|
|
229 |
|
|
230 |
iConversationEntryID = aStream.ReadInt32L();
|
|
231 |
iUnreadMessagesCount = aStream.ReadUint16L();
|
|
232 |
// read first name
|
|
233 |
TInt lenName = aStream.ReadInt8L();
|
|
234 |
if (lenName > 0)
|
|
235 |
{
|
|
236 |
iDisplayName = HBufC::NewL(aStream, lenName);
|
|
237 |
}
|
|
238 |
|
|
239 |
// read contact link
|
|
240 |
iContactId = aStream.ReadInt32L();
|
|
241 |
|
|
242 |
//Conversation entry
|
|
243 |
iConversationEntry = CCsConversationEntry::NewL();
|
|
244 |
iConversationEntry->InternalizeL(aStream);
|
|
245 |
}
|
|
246 |
|
|
247 |
// ----------------------------------------------------------------------------
|
|
248 |
// CCsClientConversation::CompareByTimeStamp
|
|
249 |
// Compares 2 CCsClientConversation objects based on the latest
|
|
250 |
// conversation entry by time stamp
|
|
251 |
// ----------------------------------------------------------------------------
|
|
252 |
EXPORT_C TInt CCsClientConversation::CompareByTimeStamp(
|
|
253 |
const CCsClientConversation& obj1,
|
|
254 |
const CCsClientConversation& obj2)
|
|
255 |
{
|
|
256 |
TInt64 timestamp1 = obj1.GetConversationEntry()->TimeStamp();
|
|
257 |
TInt64 timestamp2 = obj2.GetConversationEntry()->TimeStamp();
|
|
258 |
TInt result = -1;
|
|
259 |
|
|
260 |
if ( timestamp1 == timestamp2 )
|
|
261 |
{
|
|
262 |
result = 0;
|
|
263 |
}
|
|
264 |
else if ( timestamp1 < timestamp2 )
|
|
265 |
{
|
|
266 |
result = 1;
|
|
267 |
}
|
|
268 |
|
|
269 |
return result;
|
|
270 |
}
|
|
271 |
|
|
272 |
// ----------------------------------------------------------------------------
|
|
273 |
// CCsClientConversation::CompareByConversationEntryId
|
|
274 |
// Compares 2 CCsClientConversation objects based on ConversationEntryId.
|
|
275 |
// ----------------------------------------------------------------------------
|
|
276 |
EXPORT_C TBool CCsClientConversation::CompareByConversationEntryId(
|
|
277 |
const CCsClientConversation& obj1,
|
|
278 |
const CCsClientConversation& obj2)
|
|
279 |
{
|
|
280 |
TBool result = EFalse;
|
|
281 |
|
|
282 |
if( obj1.GetConversationEntryId() == obj2.GetConversationEntryId() )
|
|
283 |
{
|
|
284 |
result = ETrue;
|
|
285 |
}
|
|
286 |
|
|
287 |
return result;
|
|
288 |
}
|
|
289 |
// ----------------------------------------------------------------------------
|
|
290 |
// CCsClientConversation::GetUnreadMessageCount
|
|
291 |
// returns the unread message count in the conversation
|
|
292 |
// ----------------------------------------------------------------------------
|
|
293 |
EXPORT_C TUint16 CCsClientConversation::GetUnreadMessageCount() const
|
|
294 |
{
|
|
295 |
return iUnreadMessagesCount;
|
|
296 |
}
|
|
297 |
// ----------------------------------------------------------------------------
|
|
298 |
// CCsClientConversation::SetUnreadMessageCount
|
|
299 |
// Sets the unread message count
|
|
300 |
// ----------------------------------------------------------------------------
|
|
301 |
EXPORT_C void CCsClientConversation::SetUnreadMessageCount(TUint16 aCount)
|
|
302 |
{
|
|
303 |
iUnreadMessagesCount = aCount;
|
|
304 |
}
|
|
305 |
// end of file
|