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: This class encapsulates a contact and list of conversation-entries
|
|
15 |
* from the conatct.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include <ccsconversationentry.h>
|
|
21 |
#include <ccsdefs.h>
|
|
22 |
|
|
23 |
// USER INCLUDE FILES
|
|
24 |
#include "ccsconversationcontact.h"
|
|
25 |
#include "ccsconversation.h"
|
|
26 |
#include "ccsdebug.h"
|
|
27 |
|
|
28 |
//Costant Declaration
|
|
29 |
|
|
30 |
// ============================== MEMBER FUNCTIONS ============================
|
|
31 |
|
|
32 |
// ----------------------------------------------------------------------------
|
|
33 |
// CCsConversation::NewL
|
|
34 |
// Two Phase Construction
|
|
35 |
// ----------------------------------------------------------------------------
|
|
36 |
CCsConversation*
|
|
37 |
CCsConversation::NewL()
|
|
38 |
{
|
|
39 |
PRINT ( _L("Enter CCsConversation::NewL") );
|
|
40 |
|
|
41 |
CCsConversation* self = new (ELeave) CCsConversation;
|
|
42 |
CleanupStack::PushL(self);
|
|
43 |
self->ConstructL();
|
|
44 |
CleanupStack::Pop(self);
|
|
45 |
|
|
46 |
PRINT ( _L("End CCsConversation::NewL") );
|
|
47 |
|
|
48 |
return self;
|
|
49 |
}
|
|
50 |
|
|
51 |
// ----------------------------------------------------------------------------
|
|
52 |
// CCsConversation::CCsConversation
|
|
53 |
// Constructor
|
|
54 |
// ----------------------------------------------------------------------------
|
|
55 |
CCsConversation::CCsConversation()
|
|
56 |
{
|
|
57 |
}
|
|
58 |
|
|
59 |
// ----------------------------------------------------------------------------
|
|
60 |
// CCsConversation::ConstructL
|
|
61 |
// Second phase constructor
|
|
62 |
// ----------------------------------------------------------------------------
|
|
63 |
void
|
|
64 |
CCsConversation::ConstructL()
|
|
65 |
{
|
|
66 |
iConversationID = 0;
|
|
67 |
iUnreadMessagesCount = 0;
|
|
68 |
iContact = CCsConversationContact::NewL();
|
|
69 |
iDeleted = EFalse;
|
|
70 |
|
|
71 |
// initialize the iCsConversationEntryList
|
|
72 |
iEntryList = new (ELeave) RPointerArray<CCsConversationEntry> ();
|
|
73 |
}
|
|
74 |
|
|
75 |
// ----------------------------------------------------------------------------
|
|
76 |
// CCsConversation::~CCsConversation
|
|
77 |
// Destructor
|
|
78 |
// ----------------------------------------------------------------------------
|
|
79 |
CCsConversation::~CCsConversation()
|
|
80 |
{
|
|
81 |
PRINT ( _L("Enter CCsConversation::~CCsConversation") );
|
|
82 |
|
|
83 |
if (iEntryList)
|
|
84 |
{
|
|
85 |
iEntryList->ResetAndDestroy();
|
|
86 |
iEntryList->Close();
|
|
87 |
delete iEntryList;
|
|
88 |
iEntryList = NULL;
|
|
89 |
}
|
|
90 |
// delete the details object
|
|
91 |
if (iContact)
|
|
92 |
{
|
|
93 |
delete iContact;
|
|
94 |
iContact = NULL;
|
|
95 |
}
|
|
96 |
|
|
97 |
PRINT ( _L("End CCsConversation::~CCsConversation") );
|
|
98 |
}
|
|
99 |
|
|
100 |
// ----------------------------------------------------------------------------
|
|
101 |
// CCsConversation::GetEntryId
|
|
102 |
// Constructor
|
|
103 |
// ----------------------------------------------------------------------------
|
|
104 |
TCsConversationEntryID
|
|
105 |
CCsConversation::GetConversationId() const
|
|
106 |
{
|
|
107 |
return iConversationID;
|
|
108 |
}
|
|
109 |
|
|
110 |
// ----------------------------------------------------------------------------
|
|
111 |
// CCsConversation::PluginInterface
|
|
112 |
// ----------------------------------------------------------------------------
|
|
113 |
void
|
|
114 |
CCsConversation::SetConversationId(
|
|
115 |
TCsConversationEntryID aEntryId)
|
|
116 |
{
|
|
117 |
iConversationID = aEntryId;
|
|
118 |
}
|
|
119 |
|
|
120 |
// ----------------------------------------------------------------------------
|
|
121 |
// Get the Conversation Entry Display name from Coversation Detail class
|
|
122 |
// ----------------------------------------------------------------------------
|
|
123 |
HBufC*
|
|
124 |
CCsConversation::GetDisplayName()const
|
|
125 |
{
|
|
126 |
HBufC* fn = iContact->GetDisplayName();
|
|
127 |
if ( fn && fn->Length() > 0 )
|
|
128 |
return fn;
|
|
129 |
|
|
130 |
RPointerArray<TDesC> pnoList;
|
|
131 |
iContact->GetPhoneNumberList(pnoList);
|
|
132 |
if(pnoList.Count())
|
|
133 |
{
|
|
134 |
return static_cast<HBufC*>(pnoList[0]);
|
|
135 |
}
|
|
136 |
|
|
137 |
return NULL;
|
|
138 |
}
|
|
139 |
|
|
140 |
// ----------------------------------------------------------------------------
|
|
141 |
// CCsConversation::GetContactId
|
|
142 |
// Get the Conversation Entry Contact Id from Coversation Detail class
|
|
143 |
// ----------------------------------------------------------------------------
|
|
144 |
TInt32
|
|
145 |
CCsConversation::GetContactId()const
|
|
146 |
{
|
|
147 |
return iContact->GetContactId();
|
|
148 |
}
|
|
149 |
|
|
150 |
// ----------------------------------------------------------------------------
|
|
151 |
// CCsConversation::GetLatestEntryL
|
|
152 |
// TThis function shall return the latest or topmost Conversation Entry
|
|
153 |
// of Conversation class
|
|
154 |
// ----------------------------------------------------------------------------
|
|
155 |
CCsConversationEntry*
|
|
156 |
CCsConversation::GetLatestEntryL()const
|
|
157 |
{
|
|
158 |
CCsConversationEntry* ConversationEntry = NULL;
|
|
159 |
if(iEntryList->Count() > 0)
|
|
160 |
{
|
|
161 |
ConversationEntry =
|
|
162 |
(static_cast<CCsConversationEntry*>((*iEntryList)[iEntryList->Count()-1]));
|
|
163 |
}
|
|
164 |
return ConversationEntry;
|
|
165 |
}
|
|
166 |
|
|
167 |
// ----------------------------------------------------------------------------
|
|
168 |
// CCsConversation::GetEntryL
|
|
169 |
// This function returns the conversation entry at a specified index.
|
|
170 |
// ----------------------------------------------------------------------------
|
|
171 |
CCsConversationEntry* CCsConversation::GetEntryL ( TInt aIndex )
|
|
172 |
{
|
|
173 |
return static_cast<CCsConversationEntry*>((*iEntryList)[aIndex]);
|
|
174 |
}
|
|
175 |
|
|
176 |
// ----------------------------------------------------------------------------
|
|
177 |
// CCsConversation::GetLatestUnreadEntryL
|
|
178 |
// TThis function shall return the latest or topmost Conversation Entry
|
|
179 |
// of Conversation class
|
|
180 |
// ----------------------------------------------------------------------------
|
|
181 |
CCsConversationEntry*
|
|
182 |
CCsConversation::GetLatestUnreadEntryL() const
|
|
183 |
{
|
|
184 |
CCsConversationEntry* ConversationEntry = NULL;
|
|
185 |
if (iEntryList->Count() > 0)
|
|
186 |
{
|
|
187 |
TInt index = KErrNotFound;
|
|
188 |
index = FindUnreadEntry();
|
|
189 |
|
|
190 |
if (index != KErrNotFound)
|
|
191 |
{
|
|
192 |
ConversationEntry = (*iEntryList)[index];
|
|
193 |
}
|
|
194 |
}
|
|
195 |
return ConversationEntry;
|
|
196 |
}
|
|
197 |
|
|
198 |
// ----------------------------------------------------------------------------
|
|
199 |
// CCsConversation::GetEntryListL
|
|
200 |
// This function shall return all the Conversation Entry
|
|
201 |
// of ConversationEntry
|
|
202 |
// ----------------------------------------------------------------------------
|
|
203 |
void
|
|
204 |
CCsConversation::GetEntryListL (
|
|
205 |
RPointerArray<CCsConversationEntry>* aConversationEntryList)
|
|
206 |
{
|
|
207 |
TInt EntryCount = iEntryList->Count();
|
|
208 |
if (EntryCount > 0)
|
|
209 |
{
|
|
210 |
// loop through each entry make a clone and add it to aConversationEntryList class
|
|
211 |
for (TInt index=EntryCount-1 ; index>=0 ; index--)
|
|
212 |
{
|
|
213 |
CCsConversationEntry* conEntry =
|
|
214 |
(static_cast<CCsConversationEntry*>(
|
|
215 |
(*iEntryList)[index]))->CloneL();
|
|
216 |
aConversationEntryList->Append(conEntry);
|
|
217 |
}
|
|
218 |
}
|
|
219 |
}
|
|
220 |
|
|
221 |
// ----------------------------------------------------------------------------
|
|
222 |
// CCsConversation::AddEntryL
|
|
223 |
// Add a entry to this conversation
|
|
224 |
// ----------------------------------------------------------------------------
|
|
225 |
void
|
|
226 |
CCsConversation::AddEntryL(
|
|
227 |
CCsConversationEntry* aCsConversationEntry)
|
|
228 |
{
|
|
229 |
PRINT ( _L("Enter CCsConversation::AddConversationEntryL") );
|
|
230 |
// Update Unread message count
|
|
231 |
if( aCsConversationEntry->IsAttributeSet( ECsAttributeUnread ) )
|
|
232 |
{
|
|
233 |
iUnreadMessagesCount++;
|
|
234 |
}
|
|
235 |
// first add the conversation details and then
|
|
236 |
// add the conversation entry into array
|
|
237 |
|
|
238 |
// get the clone of entry class and then add into
|
|
239 |
// the entry list array
|
|
240 |
CCsConversationEntry* ConversationEntry = aCsConversationEntry->CloneL();
|
|
241 |
|
|
242 |
iEntryList->InsertInOrderAllowRepeats(ConversationEntry,
|
|
243 |
CCsConversationEntry::Compare);
|
|
244 |
|
|
245 |
PRINT ( _L("End CCsConversation::AddConversationEntryL") );
|
|
246 |
}
|
|
247 |
|
|
248 |
// ----------------------------------------------------------------------------
|
|
249 |
// CCsConversation::AddContactDetails
|
|
250 |
// Add contact details for the conversation
|
|
251 |
// this will be display name, number and contact Id
|
|
252 |
// ----------------------------------------------------------------------------
|
|
253 |
void
|
|
254 |
CCsConversation::AddContactDetailsL(
|
|
255 |
TInt32 aContactId,
|
|
256 |
const TDesC& aDisplayName)
|
|
257 |
{
|
|
258 |
iContact->SetDisplayNameL(aDisplayName);
|
|
259 |
iContact->SetContactId (aContactId);
|
|
260 |
}
|
|
261 |
|
|
262 |
// ----------------------------------------------------------------------------
|
|
263 |
// CCsConversation::AddContactDetails
|
|
264 |
// Add contact number for the conversation
|
|
265 |
// ----------------------------------------------------------------------------
|
|
266 |
void
|
|
267 |
CCsConversation::AddContactDetailsL(
|
|
268 |
TDesC& aContactNumber)
|
|
269 |
{
|
|
270 |
iContact->AddPhoneNumberL(aContactNumber);
|
|
271 |
}
|
|
272 |
|
|
273 |
// ----------------------------------------------------------------------------
|
|
274 |
// CCsConversation::UpdateEntryL
|
|
275 |
// Update the existing conversation entry if match found,
|
|
276 |
// otherwise add as new entry
|
|
277 |
// return aEvent as update/new conversation event
|
|
278 |
// ----------------------------------------------------------------------------
|
|
279 |
void
|
|
280 |
CCsConversation::UpdateEntryL(
|
|
281 |
CCsConversationEntry* aCsConversationEntry,
|
|
282 |
TUint32& aEvent)
|
|
283 |
{
|
|
284 |
PRINT ( _L("Enter CCsConversation::UpdateConversationEntryL") );
|
|
285 |
|
|
286 |
TInt index = KErrNotFound;
|
|
287 |
index = FindEntry (aCsConversationEntry);
|
|
288 |
|
|
289 |
if (index != KErrNotFound)
|
|
290 |
{
|
|
291 |
CCsConversationEntry* CoversationEntry =
|
|
292 |
(*iEntryList)[index];
|
|
293 |
// Check if the status flag is changed
|
|
294 |
// When flag is changed from Unread -> Read
|
|
295 |
if(!CoversationEntry->IsAttributeSet(ECsAttributeUnread)
|
|
296 |
&& aCsConversationEntry->IsAttributeSet(ECsAttributeUnread))
|
|
297 |
{
|
|
298 |
iUnreadMessagesCount++;
|
|
299 |
}
|
|
300 |
// When flag is changed from Read -> Unread
|
|
301 |
else if(CoversationEntry->IsAttributeSet(ECsAttributeUnread)
|
|
302 |
&& !aCsConversationEntry->IsAttributeSet(ECsAttributeUnread))
|
|
303 |
{
|
|
304 |
iUnreadMessagesCount--;
|
|
305 |
}
|
|
306 |
iEntryList->Remove(index);
|
|
307 |
delete CoversationEntry;
|
|
308 |
|
|
309 |
// mark aEvent as update
|
|
310 |
aEvent = KConversationEventUpdate;
|
|
311 |
}
|
|
312 |
else
|
|
313 |
{
|
|
314 |
if(aCsConversationEntry->IsAttributeSet(ECsAttributeUnread) )
|
|
315 |
{
|
|
316 |
iUnreadMessagesCount++;
|
|
317 |
}
|
|
318 |
|
|
319 |
aEvent = KConversationEventNew;
|
|
320 |
}
|
|
321 |
|
|
322 |
CCsConversationEntry* CoversationEntry = aCsConversationEntry->CloneL();
|
|
323 |
|
|
324 |
iEntryList->InsertInOrderAllowRepeats(
|
|
325 |
CoversationEntry,CCsConversationEntry::Compare);
|
|
326 |
|
|
327 |
PRINT ( _L("End CCsConversation::UpdateConversationEntryL") );
|
|
328 |
}
|
|
329 |
|
|
330 |
// ----------------------------------------------------------------------------
|
|
331 |
// CCsConversation::DeleteEntryL
|
|
332 |
// Delete an entry at given index
|
|
333 |
// ----------------------------------------------------------------------------
|
|
334 |
void
|
|
335 |
CCsConversation::DeleteEntryL(
|
|
336 |
TInt aindexDeletion)
|
|
337 |
{
|
|
338 |
CCsConversationEntry* CoversationEntry =
|
|
339 |
(*iEntryList)[aindexDeletion];
|
|
340 |
if(CoversationEntry->IsAttributeSet(ECsAttributeUnread))
|
|
341 |
{
|
|
342 |
iUnreadMessagesCount--;
|
|
343 |
}
|
|
344 |
iEntryList->Remove(aindexDeletion);
|
|
345 |
delete CoversationEntry;
|
|
346 |
|
|
347 |
PRINT1 ( _L("End CCsConversation::DeleteConversationEntryL - Unread Count:%d"),
|
|
348 |
iUnreadMessagesCount );
|
|
349 |
}
|
|
350 |
|
|
351 |
// ----------------------------------------------------------------------------
|
|
352 |
// CCsConversation::FindEntry
|
|
353 |
// this function shall find the entry
|
|
354 |
// ----------------------------------------------------------------------------
|
|
355 |
TInt
|
|
356 |
CCsConversation::FindEntry(
|
|
357 |
CCsConversationEntry* aCsConversationEntry)
|
|
358 |
{
|
|
359 |
TInt index = KErrNotFound;
|
|
360 |
|
|
361 |
index = iEntryList->Find(
|
|
362 |
aCsConversationEntry,
|
|
363 |
CCsConversationEntry::CompareById);
|
|
364 |
|
|
365 |
return index;
|
|
366 |
}
|
|
367 |
|
|
368 |
// ----------------------------------------------------------------------------
|
|
369 |
// CCsConversation::FindUnreadEntry
|
|
370 |
// this function shall find an unread entry
|
|
371 |
// ----------------------------------------------------------------------------
|
|
372 |
TInt
|
|
373 |
CCsConversation::FindUnreadEntry() const
|
|
374 |
{
|
|
375 |
TInt index = KErrNotFound;
|
|
376 |
|
|
377 |
CCsConversationEntry *unreadEntry = CCsConversationEntry::NewL();
|
|
378 |
unreadEntry->ChangeAttributes(ECsAttributeUnread, ECsAttributeNone);
|
|
379 |
CleanupStack::PushL(unreadEntry);
|
|
380 |
|
|
381 |
index = iEntryList->FindReverse(
|
|
382 |
unreadEntry,
|
|
383 |
CCsConversationEntry::CompareByUnreadAttrib);
|
|
384 |
|
|
385 |
CleanupStack::PopAndDestroy(unreadEntry);
|
|
386 |
|
|
387 |
return index;
|
|
388 |
}
|
|
389 |
|
|
390 |
// ----------------------------------------------------------------------------
|
|
391 |
// CCsConversation::GetEntryCount
|
|
392 |
// returns Total Conversation Entries
|
|
393 |
// ----------------------------------------------------------------------------
|
|
394 |
TInt
|
|
395 |
CCsConversation::GetEntryCount()
|
|
396 |
{
|
|
397 |
return (iEntryList->Count());
|
|
398 |
}
|
|
399 |
// ----------------------------------------------------------------------------
|
|
400 |
// CCsConversation::GetUnreadMessageCount
|
|
401 |
// returns total count of unread messages
|
|
402 |
// ----------------------------------------------------------------------------
|
|
403 |
TUint16
|
|
404 |
CCsConversation::GetUnreadMessageCount() const
|
|
405 |
{
|
|
406 |
return iUnreadMessagesCount;
|
|
407 |
}
|
|
408 |
|
|
409 |
// ----------------------------------------------------------------------------
|
|
410 |
// CCsConversation::GetContact
|
|
411 |
// Return the contact object associated with this conversation
|
|
412 |
// ----------------------------------------------------------------------------
|
|
413 |
CCsConversationContact*
|
|
414 |
CCsConversation::GetContact()const
|
|
415 |
{
|
|
416 |
return iContact;
|
|
417 |
}
|
|
418 |
|
|
419 |
// ----------------------------------------------------------------------------
|
|
420 |
// CCsConversation::IsSpecialConversation
|
|
421 |
// Returns true if it is a conversation for unknown drafts .
|
|
422 |
// ----------------------------------------------------------------------------
|
|
423 |
TBool
|
|
424 |
CCsConversation::IsSpecialConversation()
|
|
425 |
{
|
|
426 |
if (iConversationID == KUnknownConversationId
|
|
427 |
||iConversationID == KBluetoothMsgsConversationId
|
|
428 |
||iConversationID == KInfraRedMsgsConversationId)
|
|
429 |
{
|
|
430 |
return ETrue;
|
|
431 |
}
|
|
432 |
return EFalse;
|
|
433 |
}
|
|
434 |
|
|
435 |
// ----------------------------------------------------------------------------
|
|
436 |
// CCsConversation::MarkDeleted
|
|
437 |
// ----------------------------------------------------------------------------
|
|
438 |
void CCsConversation::MarkDeleted(TBool aDeleted)
|
|
439 |
{
|
|
440 |
iDeleted = aDeleted;
|
|
441 |
}
|
|
442 |
|
|
443 |
// ----------------------------------------------------------------------------
|
|
444 |
// CCsConversation::IsDeleted
|
|
445 |
// ----------------------------------------------------------------------------
|
|
446 |
TBool CCsConversation::IsDeleted() const
|
|
447 |
{
|
|
448 |
return iDeleted;
|
|
449 |
}
|
|
450 |
|
|
451 |
//EOF
|