|
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::GetEntryListL |
|
223 // This function shall return segment of Conversation Entry |
|
224 // of ConversationEntry based on aStartIndex and aEndIndex |
|
225 // ---------------------------------------------------------------------------- |
|
226 void |
|
227 CCsConversation::GetEntryListL ( |
|
228 RPointerArray<CCsConversationEntry>* aConversationEntryList, |
|
229 TInt aStartIndex, |
|
230 TInt aEndIndex) |
|
231 { |
|
232 TInt EntryCount = iEntryList->Count(); |
|
233 if (EntryCount > 0 && aStartIndex>=0 && aEndIndex<=EntryCount) |
|
234 { |
|
235 // loop through each entry make a clone and add |
|
236 // it to aConversationEntryList class |
|
237 for (TInt index=aEndIndex-1 ; index>=aStartIndex ; index--) |
|
238 { |
|
239 CCsConversationEntry* conEntry = |
|
240 (static_cast<CCsConversationEntry*>( |
|
241 (*iEntryList)[index]))->CloneL(); |
|
242 aConversationEntryList->Append(conEntry); |
|
243 } |
|
244 } |
|
245 } |
|
246 |
|
247 |
|
248 // ---------------------------------------------------------------------------- |
|
249 // CCsConversation::AddEntryL |
|
250 // Add a entry to this conversation |
|
251 // ---------------------------------------------------------------------------- |
|
252 void |
|
253 CCsConversation::AddEntryL( |
|
254 CCsConversationEntry* aCsConversationEntry) |
|
255 { |
|
256 PRINT ( _L("Enter CCsConversation::AddConversationEntryL") ); |
|
257 // Update Unread message count |
|
258 if( aCsConversationEntry->IsAttributeSet( ECsAttributeUnread ) ) |
|
259 { |
|
260 iUnreadMessagesCount++; |
|
261 } |
|
262 // first add the conversation details and then |
|
263 // add the conversation entry into array |
|
264 |
|
265 // get the clone of entry class and then add into |
|
266 // the entry list array |
|
267 CCsConversationEntry* ConversationEntry = aCsConversationEntry->CloneL(); |
|
268 |
|
269 iEntryList->InsertInOrderAllowRepeats(ConversationEntry, |
|
270 CCsConversationEntry::Compare); |
|
271 |
|
272 PRINT ( _L("End CCsConversation::AddConversationEntryL") ); |
|
273 } |
|
274 |
|
275 // ---------------------------------------------------------------------------- |
|
276 // CCsConversation::AddContactDetails |
|
277 // Add contact details for the conversation |
|
278 // this will be display name, number and contact Id |
|
279 // ---------------------------------------------------------------------------- |
|
280 void |
|
281 CCsConversation::AddContactDetailsL( |
|
282 TInt32 aContactId, |
|
283 const HBufC* aDisplayName) |
|
284 { |
|
285 if(aDisplayName) |
|
286 { |
|
287 iContact->SetDisplayNameL(*aDisplayName); |
|
288 } |
|
289 iContact->SetContactId (aContactId); |
|
290 } |
|
291 |
|
292 // ---------------------------------------------------------------------------- |
|
293 // CCsConversation::AddContactDetails |
|
294 // Add contact number for the conversation |
|
295 // ---------------------------------------------------------------------------- |
|
296 void |
|
297 CCsConversation::AddContactDetailsL( |
|
298 TDesC& aContactNumber) |
|
299 { |
|
300 iContact->AddPhoneNumberL(aContactNumber); |
|
301 } |
|
302 |
|
303 // ---------------------------------------------------------------------------- |
|
304 // CCsConversation::UpdateEntryL |
|
305 // Update the existing conversation entry if match found, |
|
306 // otherwise add as new entry |
|
307 // return aEvent as update/new conversation event |
|
308 // ---------------------------------------------------------------------------- |
|
309 void |
|
310 CCsConversation::UpdateEntryL( |
|
311 CCsConversationEntry* aCsConversationEntry, |
|
312 TUint32& aEvent) |
|
313 { |
|
314 PRINT ( _L("Enter CCsConversation::UpdateConversationEntryL") ); |
|
315 |
|
316 TInt index = KErrNotFound; |
|
317 index = FindEntry (aCsConversationEntry); |
|
318 |
|
319 if (index != KErrNotFound) |
|
320 { |
|
321 CCsConversationEntry* CoversationEntry = |
|
322 (*iEntryList)[index]; |
|
323 // Check if the status flag is changed |
|
324 // When flag is changed from Unread -> Read |
|
325 if(!CoversationEntry->IsAttributeSet(ECsAttributeUnread) |
|
326 && aCsConversationEntry->IsAttributeSet(ECsAttributeUnread)) |
|
327 { |
|
328 iUnreadMessagesCount++; |
|
329 } |
|
330 // When flag is changed from Read -> Unread |
|
331 else if(CoversationEntry->IsAttributeSet(ECsAttributeUnread) |
|
332 && !aCsConversationEntry->IsAttributeSet(ECsAttributeUnread)) |
|
333 { |
|
334 iUnreadMessagesCount--; |
|
335 } |
|
336 iEntryList->Remove(index); |
|
337 delete CoversationEntry; |
|
338 |
|
339 // mark aEvent as update |
|
340 aEvent = KConversationEventUpdate; |
|
341 } |
|
342 else |
|
343 { |
|
344 if(aCsConversationEntry->IsAttributeSet(ECsAttributeUnread) ) |
|
345 { |
|
346 iUnreadMessagesCount++; |
|
347 } |
|
348 |
|
349 aEvent = KConversationEventNew; |
|
350 } |
|
351 |
|
352 CCsConversationEntry* CoversationEntry = aCsConversationEntry->CloneL(); |
|
353 |
|
354 iEntryList->InsertInOrderAllowRepeats( |
|
355 CoversationEntry,CCsConversationEntry::Compare); |
|
356 |
|
357 PRINT ( _L("End CCsConversation::UpdateConversationEntryL") ); |
|
358 } |
|
359 |
|
360 // ---------------------------------------------------------------------------- |
|
361 // CCsConversation::DeleteEntryL |
|
362 // Delete an entry at given index |
|
363 // ---------------------------------------------------------------------------- |
|
364 void |
|
365 CCsConversation::DeleteEntryL( |
|
366 TInt aindexDeletion) |
|
367 { |
|
368 CCsConversationEntry* CoversationEntry = |
|
369 (*iEntryList)[aindexDeletion]; |
|
370 if(CoversationEntry->IsAttributeSet(ECsAttributeUnread)) |
|
371 { |
|
372 iUnreadMessagesCount--; |
|
373 } |
|
374 iEntryList->Remove(aindexDeletion); |
|
375 delete CoversationEntry; |
|
376 |
|
377 PRINT1 ( _L("End CCsConversation::DeleteConversationEntryL - Unread Count:%d"), |
|
378 iUnreadMessagesCount ); |
|
379 } |
|
380 |
|
381 // ---------------------------------------------------------------------------- |
|
382 // CCsConversation::FindEntry |
|
383 // this function shall find the entry |
|
384 // ---------------------------------------------------------------------------- |
|
385 TInt |
|
386 CCsConversation::FindEntry( |
|
387 CCsConversationEntry* aCsConversationEntry) |
|
388 { |
|
389 TInt index = KErrNotFound; |
|
390 |
|
391 index = iEntryList->Find( |
|
392 aCsConversationEntry, |
|
393 CCsConversationEntry::CompareById); |
|
394 |
|
395 return index; |
|
396 } |
|
397 |
|
398 // ---------------------------------------------------------------------------- |
|
399 // CCsConversation::FindUnreadEntry |
|
400 // this function shall find an unread entry |
|
401 // ---------------------------------------------------------------------------- |
|
402 TInt |
|
403 CCsConversation::FindUnreadEntry() const |
|
404 { |
|
405 TInt index = KErrNotFound; |
|
406 |
|
407 CCsConversationEntry *unreadEntry = CCsConversationEntry::NewL(); |
|
408 unreadEntry->ChangeAttributes(ECsAttributeUnread, ECsAttributeNone); |
|
409 CleanupStack::PushL(unreadEntry); |
|
410 |
|
411 index = iEntryList->FindReverse( |
|
412 unreadEntry, |
|
413 CCsConversationEntry::CompareByUnreadAttrib); |
|
414 |
|
415 CleanupStack::PopAndDestroy(unreadEntry); |
|
416 |
|
417 return index; |
|
418 } |
|
419 |
|
420 // ---------------------------------------------------------------------------- |
|
421 // CCsConversation::GetEntryCount |
|
422 // returns Total Conversation Entries |
|
423 // ---------------------------------------------------------------------------- |
|
424 TInt |
|
425 CCsConversation::GetEntryCount() |
|
426 { |
|
427 return (iEntryList->Count()); |
|
428 } |
|
429 // ---------------------------------------------------------------------------- |
|
430 // CCsConversation::GetUnreadMessageCount |
|
431 // returns total count of unread messages |
|
432 // ---------------------------------------------------------------------------- |
|
433 TUint16 |
|
434 CCsConversation::GetUnreadMessageCount() const |
|
435 { |
|
436 return iUnreadMessagesCount; |
|
437 } |
|
438 |
|
439 // ---------------------------------------------------------------------------- |
|
440 // CCsConversation::GetContact |
|
441 // Return the contact object associated with this conversation |
|
442 // ---------------------------------------------------------------------------- |
|
443 CCsConversationContact* |
|
444 CCsConversation::GetContact()const |
|
445 { |
|
446 return iContact; |
|
447 } |
|
448 |
|
449 // ---------------------------------------------------------------------------- |
|
450 // CCsConversation::IsSpecialConversation |
|
451 // Returns true if it is a conversation for unknown drafts . |
|
452 // ---------------------------------------------------------------------------- |
|
453 TBool |
|
454 CCsConversation::IsSpecialConversation() |
|
455 { |
|
456 if (iConversationID == KUnknownConversationId |
|
457 ||iConversationID == KBluetoothMsgsConversationId |
|
458 ||iConversationID == KInfraRedMsgsConversationId) |
|
459 { |
|
460 return ETrue; |
|
461 } |
|
462 return EFalse; |
|
463 } |
|
464 |
|
465 // ---------------------------------------------------------------------------- |
|
466 // CCsConversation::MarkDeleted |
|
467 // ---------------------------------------------------------------------------- |
|
468 void CCsConversation::MarkDeleted(TBool aDeleted) |
|
469 { |
|
470 iDeleted = aDeleted; |
|
471 } |
|
472 |
|
473 // ---------------------------------------------------------------------------- |
|
474 // CCsConversation::IsDeleted |
|
475 // ---------------------------------------------------------------------------- |
|
476 TBool CCsConversation::IsDeleted() const |
|
477 { |
|
478 return iDeleted; |
|
479 } |
|
480 |
|
481 //EOF |