|
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 First name from Coversation Detail class |
|
122 // ---------------------------------------------------------------------------- |
|
123 HBufC* |
|
124 CCsConversation::GetFirstName()const |
|
125 { |
|
126 HBufC* fn = iContact->GetFirstName(); |
|
127 if ( fn && fn->Length() > 0 ) |
|
128 return fn; |
|
129 |
|
130 // If last name is present don't promote phone number as first name |
|
131 HBufC* ln = iContact->GetLastName(); |
|
132 if ( ln && ln->Length() > 0 ) |
|
133 return NULL; |
|
134 |
|
135 RPointerArray<TDesC> pnoList; |
|
136 iContact->GetPhoneNumberList(pnoList); |
|
137 if(pnoList.Count()) |
|
138 { |
|
139 return static_cast<HBufC*>(pnoList[0]); |
|
140 } |
|
141 |
|
142 return NULL; |
|
143 } |
|
144 |
|
145 // ---------------------------------------------------------------------------- |
|
146 // Get the Conversation Entry Last name from Coversation Detail class |
|
147 // ---------------------------------------------------------------------------- |
|
148 HBufC* |
|
149 CCsConversation::GetLastName() const |
|
150 { |
|
151 return iContact->GetLastName(); |
|
152 } |
|
153 |
|
154 // ---------------------------------------------------------------------------- |
|
155 // Get the Conversation Entry Nick name from Coversation Detail class |
|
156 // ---------------------------------------------------------------------------- |
|
157 HBufC* |
|
158 CCsConversation::GetNickName() const |
|
159 { |
|
160 return iContact->GetNickName(); |
|
161 } |
|
162 |
|
163 // ---------------------------------------------------------------------------- |
|
164 // CCsConversation::GetContactId |
|
165 // Get the Conversation Entry Contact Id from Coversation Detail class |
|
166 // ---------------------------------------------------------------------------- |
|
167 TInt32 |
|
168 CCsConversation::GetContactId()const |
|
169 { |
|
170 return iContact->GetContactId(); |
|
171 } |
|
172 |
|
173 // ---------------------------------------------------------------------------- |
|
174 // CCsConversation::GetLatestEntryL |
|
175 // TThis function shall return the latest or topmost Conversation Entry |
|
176 // of Conversation class |
|
177 // ---------------------------------------------------------------------------- |
|
178 CCsConversationEntry* |
|
179 CCsConversation::GetLatestEntryL()const |
|
180 { |
|
181 CCsConversationEntry* ConversationEntry = NULL; |
|
182 if(iEntryList->Count() > 0) |
|
183 { |
|
184 ConversationEntry = |
|
185 (static_cast<CCsConversationEntry*>((*iEntryList)[iEntryList->Count()-1])); |
|
186 } |
|
187 return ConversationEntry; |
|
188 } |
|
189 |
|
190 // ---------------------------------------------------------------------------- |
|
191 // CCsConversation::GetEntryL |
|
192 // This function returns the conversation entry at a specified index. |
|
193 // ---------------------------------------------------------------------------- |
|
194 CCsConversationEntry* CCsConversation::GetEntryL ( TInt aIndex ) |
|
195 { |
|
196 return static_cast<CCsConversationEntry*>((*iEntryList)[aIndex]); |
|
197 } |
|
198 |
|
199 // ---------------------------------------------------------------------------- |
|
200 // CCsConversation::GetLatestUnreadEntryL |
|
201 // TThis function shall return the latest or topmost Conversation Entry |
|
202 // of Conversation class |
|
203 // ---------------------------------------------------------------------------- |
|
204 CCsConversationEntry* |
|
205 CCsConversation::GetLatestUnreadEntryL() const |
|
206 { |
|
207 CCsConversationEntry* ConversationEntry = NULL; |
|
208 if (iEntryList->Count() > 0) |
|
209 { |
|
210 TInt index = KErrNotFound; |
|
211 index = FindUnreadEntry(); |
|
212 |
|
213 if (index != KErrNotFound) |
|
214 { |
|
215 ConversationEntry = (*iEntryList)[index]; |
|
216 } |
|
217 } |
|
218 return ConversationEntry; |
|
219 } |
|
220 |
|
221 // ---------------------------------------------------------------------------- |
|
222 // CCsConversation::GetEntryListL |
|
223 // This function shall return all the Conversation Entry |
|
224 // of ConversationEntry |
|
225 // ---------------------------------------------------------------------------- |
|
226 void |
|
227 CCsConversation::GetEntryListL ( |
|
228 RPointerArray<CCsConversationEntry>* aConversationEntryList) |
|
229 { |
|
230 TInt EntryCount = iEntryList->Count(); |
|
231 if (EntryCount > 0) |
|
232 { |
|
233 // loop through each entry make a clone and add it to aConversationEntryList class |
|
234 for (TInt index=EntryCount-1 ; index>=0 ; index--) |
|
235 { |
|
236 CCsConversationEntry* conEntry = |
|
237 (static_cast<CCsConversationEntry*>( |
|
238 (*iEntryList)[index]))->CloneL(); |
|
239 aConversationEntryList->Append(conEntry); |
|
240 } |
|
241 } |
|
242 } |
|
243 |
|
244 // ---------------------------------------------------------------------------- |
|
245 // CCsConversation::AddEntryL |
|
246 // Add a entry to this conversation |
|
247 // ---------------------------------------------------------------------------- |
|
248 void |
|
249 CCsConversation::AddEntryL( |
|
250 CCsConversationEntry* aCsConversationEntry) |
|
251 { |
|
252 PRINT ( _L("Enter CCsConversation::AddConversationEntryL") ); |
|
253 // Update Unread message count |
|
254 if( aCsConversationEntry->IsAttributeSet( ECsAttributeUnread ) ) |
|
255 { |
|
256 iUnreadMessagesCount++; |
|
257 } |
|
258 // first add the conversation details and then |
|
259 // add the conversation entry into array |
|
260 |
|
261 // get the clone of entry class and then add into |
|
262 // the entry list array |
|
263 CCsConversationEntry* ConversationEntry = aCsConversationEntry->CloneL(); |
|
264 |
|
265 iEntryList->InsertInOrderAllowRepeats(ConversationEntry, |
|
266 CCsConversationEntry::Compare); |
|
267 |
|
268 PRINT ( _L("End CCsConversation::AddConversationEntryL") ); |
|
269 } |
|
270 |
|
271 // ---------------------------------------------------------------------------- |
|
272 // CCsConversation::AddContactDetails |
|
273 // Add contact details for the conversation |
|
274 // this will be display name, number and contact Id |
|
275 // ---------------------------------------------------------------------------- |
|
276 void |
|
277 CCsConversation::AddContactDetailsL( |
|
278 TInt32 aContactId, |
|
279 const TDesC& aFirstName, |
|
280 const TDesC& aLastName, |
|
281 const TDesC& aNickName) |
|
282 { |
|
283 iContact->SetFirstNameL(aFirstName); |
|
284 iContact->SetLastNameL(aLastName); |
|
285 iContact->SetContactId (aContactId); |
|
286 iContact->SetNickNameL(aNickName); |
|
287 } |
|
288 |
|
289 // ---------------------------------------------------------------------------- |
|
290 // CCsConversation::AddContactDetails |
|
291 // Add contact number for the conversation |
|
292 // ---------------------------------------------------------------------------- |
|
293 void |
|
294 CCsConversation::AddContactDetailsL( |
|
295 TDesC& aContactNumber) |
|
296 { |
|
297 iContact->AddPhoneNumberL(aContactNumber); |
|
298 } |
|
299 |
|
300 // ---------------------------------------------------------------------------- |
|
301 // CCsConversation::UpdateEntryL |
|
302 // Update the existing conversation entry if match found, |
|
303 // otherwise add as new entry |
|
304 // return aEvent as update/new conversation event |
|
305 // ---------------------------------------------------------------------------- |
|
306 void |
|
307 CCsConversation::UpdateEntryL( |
|
308 CCsConversationEntry* aCsConversationEntry, |
|
309 TUint32& aEvent) |
|
310 { |
|
311 PRINT ( _L("Enter CCsConversation::UpdateConversationEntryL") ); |
|
312 |
|
313 TInt index = KErrNotFound; |
|
314 index = FindEntry (aCsConversationEntry); |
|
315 |
|
316 if (index != KErrNotFound) |
|
317 { |
|
318 CCsConversationEntry* CoversationEntry = |
|
319 (*iEntryList)[index]; |
|
320 // Check if the status flag is changed |
|
321 // When flag is changed from Unread -> Read |
|
322 if(!CoversationEntry->IsAttributeSet(ECsAttributeUnread) |
|
323 && aCsConversationEntry->IsAttributeSet(ECsAttributeUnread)) |
|
324 { |
|
325 iUnreadMessagesCount++; |
|
326 } |
|
327 // When flag is changed from Read -> Unread |
|
328 else if(CoversationEntry->IsAttributeSet(ECsAttributeUnread) |
|
329 && !aCsConversationEntry->IsAttributeSet(ECsAttributeUnread)) |
|
330 { |
|
331 iUnreadMessagesCount--; |
|
332 } |
|
333 iEntryList->Remove(index); |
|
334 delete CoversationEntry; |
|
335 |
|
336 // mark aEvent as update |
|
337 aEvent = KConversationEventUpdate; |
|
338 } |
|
339 else |
|
340 { |
|
341 if(aCsConversationEntry->IsAttributeSet(ECsAttributeUnread) ) |
|
342 { |
|
343 iUnreadMessagesCount++; |
|
344 } |
|
345 |
|
346 aEvent = KConversationEventNew; |
|
347 } |
|
348 |
|
349 CCsConversationEntry* CoversationEntry = aCsConversationEntry->CloneL(); |
|
350 |
|
351 iEntryList->InsertInOrderAllowRepeats( |
|
352 CoversationEntry,CCsConversationEntry::Compare); |
|
353 |
|
354 PRINT ( _L("End CCsConversation::UpdateConversationEntryL") ); |
|
355 } |
|
356 |
|
357 // ---------------------------------------------------------------------------- |
|
358 // CCsConversation::DeleteEntryL |
|
359 // Delete an entry at given index |
|
360 // ---------------------------------------------------------------------------- |
|
361 void |
|
362 CCsConversation::DeleteEntryL( |
|
363 TInt aindexDeletion) |
|
364 { |
|
365 CCsConversationEntry* CoversationEntry = |
|
366 (*iEntryList)[aindexDeletion]; |
|
367 if(CoversationEntry->IsAttributeSet(ECsAttributeUnread)) |
|
368 { |
|
369 iUnreadMessagesCount--; |
|
370 } |
|
371 iEntryList->Remove(aindexDeletion); |
|
372 delete CoversationEntry; |
|
373 |
|
374 PRINT1 ( _L("End CCsConversation::DeleteConversationEntryL - Unread Count:%d"), |
|
375 iUnreadMessagesCount ); |
|
376 } |
|
377 |
|
378 // ---------------------------------------------------------------------------- |
|
379 // CCsConversation::FindEntry |
|
380 // this function shall find the entry |
|
381 // ---------------------------------------------------------------------------- |
|
382 TInt |
|
383 CCsConversation::FindEntry( |
|
384 CCsConversationEntry* aCsConversationEntry) |
|
385 { |
|
386 TInt index = KErrNotFound; |
|
387 |
|
388 index = iEntryList->Find( |
|
389 aCsConversationEntry, |
|
390 CCsConversationEntry::CompareById); |
|
391 |
|
392 return index; |
|
393 } |
|
394 |
|
395 // ---------------------------------------------------------------------------- |
|
396 // CCsConversation::FindUnreadEntry |
|
397 // this function shall find an unread entry |
|
398 // ---------------------------------------------------------------------------- |
|
399 TInt |
|
400 CCsConversation::FindUnreadEntry() const |
|
401 { |
|
402 TInt index = KErrNotFound; |
|
403 |
|
404 CCsConversationEntry *unreadEntry = CCsConversationEntry::NewL(); |
|
405 unreadEntry->ChangeAttributes(ECsAttributeUnread, ECsAttributeNone); |
|
406 CleanupStack::PushL(unreadEntry); |
|
407 |
|
408 index = iEntryList->FindReverse( |
|
409 unreadEntry, |
|
410 CCsConversationEntry::CompareByUnreadAttrib); |
|
411 |
|
412 CleanupStack::PopAndDestroy(unreadEntry); |
|
413 |
|
414 return index; |
|
415 } |
|
416 |
|
417 // ---------------------------------------------------------------------------- |
|
418 // CCsConversation::GetEntryCount |
|
419 // returns Total Conversation Entries |
|
420 // ---------------------------------------------------------------------------- |
|
421 TInt |
|
422 CCsConversation::GetEntryCount() |
|
423 { |
|
424 return (iEntryList->Count()); |
|
425 } |
|
426 // ---------------------------------------------------------------------------- |
|
427 // CCsConversation::GetUnreadMessageCount |
|
428 // returns total count of unread messages |
|
429 // ---------------------------------------------------------------------------- |
|
430 TUint16 |
|
431 CCsConversation::GetUnreadMessageCount() const |
|
432 { |
|
433 return iUnreadMessagesCount; |
|
434 } |
|
435 |
|
436 // ---------------------------------------------------------------------------- |
|
437 // CCsConversation::GetContact |
|
438 // Return the contact object associated with this conversation |
|
439 // ---------------------------------------------------------------------------- |
|
440 CCsConversationContact* |
|
441 CCsConversation::GetContact()const |
|
442 { |
|
443 return iContact; |
|
444 } |
|
445 |
|
446 // ---------------------------------------------------------------------------- |
|
447 // CCsConversation::IsSpecialConversation |
|
448 // Returns true if it is a conversation for unknown drafts . |
|
449 // ---------------------------------------------------------------------------- |
|
450 TBool |
|
451 CCsConversation::IsSpecialConversation() |
|
452 { |
|
453 if (iConversationID == KUnknownConversationId |
|
454 ||iConversationID == KBluetoothMsgsConversationId |
|
455 ||iConversationID == KInfraRedMsgsConversationId) |
|
456 { |
|
457 return ETrue; |
|
458 } |
|
459 return EFalse; |
|
460 } |
|
461 |
|
462 // ---------------------------------------------------------------------------- |
|
463 // CCsConversation::MarkDeleted |
|
464 // ---------------------------------------------------------------------------- |
|
465 void CCsConversation::MarkDeleted(TBool aDeleted) |
|
466 { |
|
467 iDeleted = aDeleted; |
|
468 } |
|
469 |
|
470 // ---------------------------------------------------------------------------- |
|
471 // CCsConversation::IsDeleted |
|
472 // ---------------------------------------------------------------------------- |
|
473 TBool CCsConversation::IsDeleted() const |
|
474 { |
|
475 return iDeleted; |
|
476 } |
|
477 |
|
478 //EOF |