|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation of contact data container |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CCAContactList.h" |
|
22 #include "CAUtils.h" |
|
23 #include "CCAContact.h" |
|
24 #include "CCAContactSorter.h" |
|
25 #include "MCAStorageInfo.h" |
|
26 #include "MCAStoredContactsObserver.h" |
|
27 #include "TCAStoragePanics.h" |
|
28 |
|
29 #include "ChatDebugPrint.h" |
|
30 #include "ChatDebugAssert.h" |
|
31 |
|
32 // ============================ MEMBER FUNCTIONS =============================== |
|
33 |
|
34 // Compares two contacts |
|
35 TInt CompareUserIdAlphabetically( |
|
36 const MCAStoredContact& aFirst, |
|
37 const MCAStoredContact& aSecond ) |
|
38 { |
|
39 return CAUtils::NeutralCompare( aFirst.UserId(), aSecond.UserId() ); |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CCAContactList::CCAContact |
|
44 // C++ default constructor can NOT contain any code, that |
|
45 // might leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 CCAContactList::CCAContactList( MCAStoredContactsObserver& aObserver, |
|
49 CCAContactSorter& aSorter, |
|
50 MCAStorageInfo& aInfo ) |
|
51 : iSorter( aSorter ), |
|
52 iInfo( aInfo ), |
|
53 iPrimaryCollapsed( ETrue ), |
|
54 iSecondaryCollapsed( ETrue ), |
|
55 iCurrentCollapsed( &iPrimaryCollapsed ), |
|
56 iObserver( aObserver ) |
|
57 { |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CCAContactList::ConstructL |
|
62 // Symbian 2nd phase constructor can leave. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 void CCAContactList::ConstructL( const TDesC& aContactListId, |
|
66 const TDesC& aDisplayName ) |
|
67 { |
|
68 iListId = aContactListId.AllocL(); |
|
69 iDisplayName = aDisplayName.AllocL(); |
|
70 } |
|
71 |
|
72 // ----------------------------------------------------------------------------- |
|
73 // CCAContactList::NewL |
|
74 // Two-phased constructor. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CCAContactList* CCAContactList::NewL( MCAStoredContactsObserver& aObserver, |
|
78 CCAContactSorter& aSorter, |
|
79 MCAStorageInfo& aInfo, |
|
80 const TDesC& aContactListId, |
|
81 const TDesC& aDisplayName ) |
|
82 { |
|
83 CCAContactList* self = NewLC( aObserver, |
|
84 aSorter, |
|
85 aInfo, |
|
86 aContactListId, |
|
87 aDisplayName ); |
|
88 CleanupStack::Pop( self ); |
|
89 return self; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CCAContactList::NewLC |
|
94 // Two-phased constructor. |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 CCAContactList* CCAContactList::NewLC( MCAStoredContactsObserver& aObserver, |
|
98 CCAContactSorter& aSorter, |
|
99 MCAStorageInfo& aInfo, |
|
100 const TDesC& aContactListId, |
|
101 const TDesC& aDisplayName ) |
|
102 { |
|
103 CCAContactList* self = new( ELeave ) CCAContactList( aObserver, aSorter, aInfo ); |
|
104 |
|
105 CleanupStack::PushL( self ); |
|
106 self->ConstructL( aContactListId, aDisplayName ); |
|
107 return self; |
|
108 } |
|
109 |
|
110 |
|
111 // Destructor |
|
112 CCAContactList::~CCAContactList() |
|
113 { |
|
114 iContacts.ResetAndDestroy(); |
|
115 iOrderedContacts.Reset(); |
|
116 delete iListId; |
|
117 delete iDisplayName; |
|
118 } |
|
119 |
|
120 |
|
121 // ----------------------------------------------------------------------------- |
|
122 // CCAContactList::ListId |
|
123 // ----------------------------------------------------------------------------- |
|
124 // |
|
125 const TDesC& CCAContactList::ListId() const |
|
126 { |
|
127 if ( iListId ) |
|
128 { |
|
129 return *iListId; |
|
130 } |
|
131 return KNullDesC; |
|
132 } |
|
133 |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CCAContactList::SetListIdL |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 void CCAContactList::SetListIdL( const TDesC& aListId ) |
|
140 { |
|
141 HBufC* newId = aListId.AllocL(); |
|
142 delete iListId; |
|
143 iListId = newId; |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CCAContactList::DisplayName |
|
148 // ----------------------------------------------------------------------------- |
|
149 // |
|
150 TPtrC CCAContactList::DisplayName() const |
|
151 { |
|
152 if ( iDisplayName ) |
|
153 { |
|
154 if ( iDisplayName->Length() ) |
|
155 { |
|
156 return *iDisplayName; |
|
157 } |
|
158 } |
|
159 return CAUtils::DisplayId( *iListId, ETrue ); |
|
160 } |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CCAContactList::SetDisplayName |
|
164 // ----------------------------------------------------------------------------- |
|
165 // |
|
166 void CCAContactList::SetDisplayNameL( const TDesC& aDisplayName ) |
|
167 { |
|
168 // Check capitalizing is enabled or not |
|
169 // extra checking added here to keep the new Functionality(capitalizing) |
|
170 // added and the original code in seperate parts. |
|
171 // UI CR ID: 101-39727 |
|
172 HBufC* tempName = NULL; |
|
173 if ( CAUtils::CapitalizingEnabled() ) |
|
174 { |
|
175 if ( aDisplayName.Length() ) |
|
176 { |
|
177 tempName = CAUtils::CapitalizeListNameL( aDisplayName );// Newly added capitalization Functionality |
|
178 } |
|
179 else |
|
180 { |
|
181 // when server doesnot send any display name we have to show the listid |
|
182 // the list id to be shown is capitalized.(list id is used as it recieve |
|
183 // from the server.) |
|
184 tempName = CAUtils::CapitalizeListIdL( *iListId ); |
|
185 } |
|
186 } |
|
187 |
|
188 else |
|
189 { |
|
190 tempName = aDisplayName.AllocL(); // Original Functionality |
|
191 } |
|
192 delete iDisplayName; |
|
193 iDisplayName = tempName; |
|
194 iObserver.HandleChange( this, |
|
195 NULL, |
|
196 TStorageManagerGlobals::EStorageEventListChanged, |
|
197 EFalse ); |
|
198 } |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 // CCAContactList::FindContact |
|
202 // ----------------------------------------------------------------------------- |
|
203 // |
|
204 MCAStoredContact* CCAContactList::FindContact( const TDesC& aContactId ) |
|
205 { |
|
206 TInt orderedIndex( 0 ); |
|
207 TInt contactIndex = FindContactIndex( aContactId, orderedIndex ); |
|
208 return ( contactIndex >= 0 ? iContacts[ contactIndex ] : NULL ); |
|
209 } |
|
210 |
|
211 // |
|
212 MCAStoredContact* CCAContactList::FindContact( const MCAStoredContact* aContact ) |
|
213 { |
|
214 TInt indexOfContact( FindIndexOfContact( aContact ) ); |
|
215 if ( indexOfContact == KErrNotFound ) |
|
216 { |
|
217 return NULL; |
|
218 } |
|
219 return iContacts[ indexOfContact ]; |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CCAContactList::FindContactByNick |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 MCAStoredContact* CCAContactList::FindContactByNick( const TDesC& aNick ) |
|
227 { |
|
228 TInt contactIndex = FindContactIndexByNick( aNick ); |
|
229 return ( contactIndex >= 0 ? iContacts[ contactIndex ] : NULL ); |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CCAContactList::RemoveContact |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 TInt CCAContactList::RemoveContact( const TDesC& aContactId ) |
|
237 { |
|
238 TInt orderedIndex( 0 ); |
|
239 TInt contactIndex = FindContactIndex( aContactId, orderedIndex ); |
|
240 if ( KErrNotFound != contactIndex ) |
|
241 { |
|
242 delete iContacts[ contactIndex ]; |
|
243 iContacts.Remove( contactIndex ); |
|
244 iOrderedContacts.Remove( orderedIndex ); |
|
245 return KErrNone; |
|
246 } |
|
247 return KErrNotFound; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CCAContactList::FindContact |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 MCAStoredContact* CCAContactList::AddContactL( MCAStoredContact* aContact ) |
|
255 { |
|
256 // optimize insert for inserting of reverse alphabetical order |
|
257 TInt idIndex( 0 ); |
|
258 TInt count( iOrderedContacts.Count() ); |
|
259 if ( count && |
|
260 0 <= CAUtils::NeutralCompare( aContact->UserId(), |
|
261 iOrderedContacts[ 0 ]->UserId() ) ) |
|
262 { |
|
263 // there are items and the contact should not be inserted to beginning |
|
264 // => find the correct place |
|
265 TLinearOrder< MCAStoredContact > userIdOrder( *CompareUserIdAlphabetically ); |
|
266 if ( KErrNone == iOrderedContacts.FindInOrder( aContact, idIndex, userIdOrder ) ) |
|
267 { |
|
268 // this contact already exists, return it |
|
269 return iOrderedContacts[ idIndex ]; |
|
270 } |
|
271 } |
|
272 |
|
273 // the position is now correct, insert the contact |
|
274 iOrderedContacts.InsertL( aContact, idIndex ); |
|
275 |
|
276 // insert also to list sorted by contact "identification" |
|
277 TInt err( KErrNone ); |
|
278 count = iContacts.Count(); |
|
279 TLinearOrder< MCAStoredContact >& order = iSorter.InsertOrder(); |
|
280 if ( count && 0 > ( *order )( aContact, iContacts[ 0 ] ) ) |
|
281 { |
|
282 // the item should be inserted in the beginning of the array |
|
283 err = iContacts.Insert( aContact, 0 ); |
|
284 } |
|
285 else |
|
286 { |
|
287 // insert in correct position |
|
288 err = iContacts.InsertInOrderAllowRepeats( aContact, order ); |
|
289 } |
|
290 |
|
291 if ( err != KErrNone ) |
|
292 { |
|
293 // appending to second array did not succeed, so remove from first and leave |
|
294 iOrderedContacts.Remove( idIndex ); |
|
295 User::Leave( err ); |
|
296 } |
|
297 |
|
298 return aContact; |
|
299 } |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CCAContactList::FindContact |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 TInt CCAContactList::ContactCount( TBool aSkipOfflineContacts, |
|
306 TBool aSkipBlocekedContacts ) const |
|
307 { |
|
308 if ( !aSkipOfflineContacts && !aSkipBlocekedContacts ) |
|
309 { |
|
310 return iContacts.Count(); |
|
311 } |
|
312 |
|
313 TInt countOfContacts( 0 ); |
|
314 TInt count( iContacts.Count() ); |
|
315 for ( TInt a( 0 ); a < count; ++a ) |
|
316 { |
|
317 TStorageManagerGlobals::TPresenceStatus status( |
|
318 iContacts[ a ]->OnlineStatus() ); |
|
319 if ( status == TStorageManagerGlobals::EOnline || |
|
320 status == TStorageManagerGlobals::EAway || |
|
321 status == TStorageManagerGlobals::EBusy ) |
|
322 { |
|
323 if ( aSkipBlocekedContacts ) |
|
324 { |
|
325 if ( !iContacts[ a ]->IsBlocked() ) |
|
326 { |
|
327 ++countOfContacts; |
|
328 } |
|
329 } |
|
330 else |
|
331 { |
|
332 ++countOfContacts; |
|
333 } |
|
334 } |
|
335 else |
|
336 { |
|
337 if ( aSkipBlocekedContacts ) |
|
338 { |
|
339 if ( !iContacts[ a ]->IsBlocked() ) |
|
340 { |
|
341 ++countOfContacts; |
|
342 } |
|
343 } |
|
344 } |
|
345 } |
|
346 return countOfContacts; |
|
347 } |
|
348 |
|
349 // ----------------------------------------------------------------------------- |
|
350 // CCAContactList::SetCollapsed |
|
351 // ----------------------------------------------------------------------------- |
|
352 // |
|
353 void CCAContactList::SetCollapsed( TBool aCollapsed ) |
|
354 { |
|
355 if ( !iInfo.CollapseLocked() ) |
|
356 { |
|
357 *iCurrentCollapsed = aCollapsed; |
|
358 } |
|
359 } |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // CCAContactList::Collapsed |
|
363 // ----------------------------------------------------------------------------- |
|
364 // |
|
365 TBool CCAContactList::Collapsed() const |
|
366 { |
|
367 return *iCurrentCollapsed; |
|
368 } |
|
369 |
|
370 // ----------------------------------------------------------------------------- |
|
371 // CCAContactList::FindContactIndex |
|
372 // ----------------------------------------------------------------------------- |
|
373 // |
|
374 TInt CCAContactList::FindContactIndex( const TDesC& aContactId, |
|
375 TInt& aOrderedIndex ) const |
|
376 { |
|
377 return FindContactByUserId( aContactId, aOrderedIndex ); |
|
378 } |
|
379 |
|
380 // ----------------------------------------------------------------------------- |
|
381 // CCAContactList::FindContactIndexByNick |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 TInt CCAContactList::FindContactIndexByNick( const TDesC& aNick ) const |
|
385 { |
|
386 return FindContactInArray( aNick, ContactFindByNick ); |
|
387 } |
|
388 |
|
389 // ----------------------------------------------------------------------------- |
|
390 // CCAContactList::FindContactInArray |
|
391 // ----------------------------------------------------------------------------- |
|
392 // |
|
393 TInt CCAContactList::FindContactInArray( |
|
394 const TDesC& aId, |
|
395 TBool ( *aCompare )( const TDesC&, const MCAStoredContact& ) ) const |
|
396 { |
|
397 TInt count( iContacts.Count() ); |
|
398 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
399 { |
|
400 if ( ( *aCompare )( aId, *( iContacts[ x ] ) ) ) |
|
401 { |
|
402 return x; |
|
403 } |
|
404 } |
|
405 return KErrNotFound; |
|
406 } |
|
407 |
|
408 // ----------------------------------------------------------------------------- |
|
409 // CCAContactList::FindContactEntry |
|
410 // ----------------------------------------------------------------------------- |
|
411 // |
|
412 TInt CCAContactList::FindContactEntry( const MCAStoredContact* aContact ) const |
|
413 { |
|
414 TInt index( iContacts.Find( aContact ) ); |
|
415 __ASSERT_DEBUG( index != KErrNotFound , Panic( EContactsArrayOutOfSync ) ); |
|
416 return index; |
|
417 } |
|
418 |
|
419 // ----------------------------------------------------------------------------- |
|
420 // CCAContactList::FindContactByUserId |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 TInt CCAContactList::FindContactByUserId( const TDesC& aUserId, |
|
424 TInt& aIndexOrderedArray ) const |
|
425 { |
|
426 TInt low( 0 ); |
|
427 TInt high( iOrderedContacts.Count() ); |
|
428 while ( high > low ) |
|
429 { |
|
430 TInt m( ( low + high ) / 2 ); |
|
431 TInt compare( CAUtils::NeutralCompare( aUserId, iOrderedContacts[ m ]->UserId() ) ); |
|
432 if ( compare == KErrNone ) |
|
433 { |
|
434 aIndexOrderedArray = m; |
|
435 return FindContactEntry( iOrderedContacts[ m ] ); |
|
436 } |
|
437 else if ( compare > 0 ) |
|
438 { |
|
439 low = m + 1; |
|
440 } |
|
441 else |
|
442 { |
|
443 high = m; |
|
444 } |
|
445 } |
|
446 aIndexOrderedArray = KErrNotFound; |
|
447 return KErrNotFound; |
|
448 } |
|
449 |
|
450 // TIdentityRelation |
|
451 TBool CCAContactList::ContactFindById( const TDesC& aId, |
|
452 const MCAStoredContact& aContact ) |
|
453 { |
|
454 return ( CAUtils::NeutralCompare( aId, |
|
455 aContact.UserId() ) == KErrNone ); |
|
456 } |
|
457 |
|
458 // TIdentityRelation |
|
459 TBool CCAContactList::ContactFindByNick( const TDesC& aId, |
|
460 const MCAStoredContact& aContact ) |
|
461 { |
|
462 // Use folding compare to ignore the case sensitivity, but to retain |
|
463 // the comparision of symbols. |
|
464 return( KErrNone == aId.CompareF( aContact.Nickname() ) ); |
|
465 } |
|
466 |
|
467 TInt CCAContactList::PendingMessages() const |
|
468 { |
|
469 TInt amount( 0 ); |
|
470 for ( TInt a( 0 ); a < iContacts.Count(); ++a ) |
|
471 { |
|
472 amount += iContacts[ a ]->PendingMessages(); |
|
473 } |
|
474 return amount; |
|
475 } |
|
476 |
|
477 void CCAContactList::Sort() |
|
478 { |
|
479 iSorter.Sort( iContacts ); |
|
480 } |
|
481 |
|
482 void CCAContactList::ResortContact( MCAStoredContact* aContact ) |
|
483 { |
|
484 // let it panic, if index is not found, which would be bad |
|
485 TInt index( iContacts.Find( aContact ) ); |
|
486 __ASSERT_DEBUG( index != KErrNotFound , Panic( ESortingCorupted ) ); |
|
487 // Check if resort is even needed for the contact |
|
488 TLinearOrder< MCAStoredContact >& order = iSorter.InsertOrder(); |
|
489 if ( |
|
490 ( |
|
491 ( index == 0 ) |
|
492 || |
|
493 ( 0 >= ( *order )( iContacts[ index - 1], aContact ) ) |
|
494 ) |
|
495 && |
|
496 ( |
|
497 ( index == ( iContacts.Count() - 1 ) ) |
|
498 || |
|
499 ( 0 <= ( *order )( iContacts[ index + 1], aContact ) ) |
|
500 ) |
|
501 ) |
|
502 { |
|
503 // the item is in correct position |
|
504 // => no need to resort |
|
505 return; |
|
506 } |
|
507 |
|
508 iContacts.Remove( index ); |
|
509 // this should alway succeed, since we did not actually add anything to array |
|
510 // no need to add contact to the ordered array, should be there already |
|
511 TInt err( iContacts.InsertInOrderAllowRepeats( aContact, order ) ); |
|
512 __ASSERT_DEBUG( err == KErrNone , Panic( ESortingCorupted ) ); |
|
513 } |
|
514 |
|
515 void CCAContactList::ResortUnKnownContact( MCAStoredContact* aContact ) |
|
516 { |
|
517 TInt index( iContacts.Find( aContact ) ); |
|
518 // Check if resort is even needed for the contact |
|
519 TLinearOrder< MCAStoredContact >& order = iSorter.InsertOrder(); |
|
520 if ( |
|
521 ( KErrNotFound == index ) |
|
522 || |
|
523 ( |
|
524 ( index == 0 ) |
|
525 || |
|
526 ( 0 > ( *order )( iContacts[ index - 1], aContact ) ) |
|
527 ) |
|
528 && |
|
529 ( |
|
530 ( index == ( iContacts.Count() - 1 ) ) |
|
531 || |
|
532 ( 0 < ( *order )( iContacts[ index + 1], aContact ) ) |
|
533 ) |
|
534 ) |
|
535 { |
|
536 // the item is in correct position |
|
537 // no need to resort |
|
538 return; |
|
539 } |
|
540 iContacts.Remove( index ); |
|
541 // this should alway succeed, since we did not actually add anything to array |
|
542 // no need to add contact to the ordered array, should be there already |
|
543 TInt err( iContacts.InsertInOrderAllowRepeats( aContact, order ) ); |
|
544 __ASSERT_DEBUG( err == KErrNone , Panic( ESortingCorupted ) ); |
|
545 } |
|
546 // ----------------------------------------------------------------------------- |
|
547 // CCAContactListList::Selected |
|
548 // From MCAContactList |
|
549 // ----------------------------------------------------------------------------- |
|
550 // |
|
551 TBool CCAContactList::Selected() const |
|
552 { |
|
553 return iSelected; |
|
554 } |
|
555 |
|
556 // ----------------------------------------------------------------------------- |
|
557 // CCAContactList::SetSelected |
|
558 // From MCAContactList |
|
559 // ----------------------------------------------------------------------------- |
|
560 // |
|
561 void CCAContactList::SetSelected( TBool aSelected ) |
|
562 { |
|
563 iSelected = aSelected; |
|
564 } |
|
565 |
|
566 // ----------------------------------------------------------------------------- |
|
567 // CCAContactList::FindIndexOfContact |
|
568 // From MCAContactList |
|
569 // ----------------------------------------------------------------------------- |
|
570 // |
|
571 TInt CCAContactList::FindIndexOfContact( const MCAStoredContact* aContact, |
|
572 TStorageManagerGlobals::TFilterType aFilter ) const |
|
573 { |
|
574 TInt count( iContacts.Count() ); |
|
575 |
|
576 if ( aFilter == TStorageManagerGlobals::EFilterAll ) |
|
577 { |
|
578 for ( TInt a( 0 ); a < count; ++a ) |
|
579 { |
|
580 const MCAStoredContact* contact = iContacts[ a ]; |
|
581 if ( aContact == contact ) |
|
582 { |
|
583 return a; |
|
584 } |
|
585 } |
|
586 } |
|
587 else |
|
588 { |
|
589 TInt filteredIndex( -1 ); |
|
590 |
|
591 for ( TInt i( 0 ); i < count; ++i ) |
|
592 { |
|
593 MCAStoredContact* contact ( iContacts[i] ); |
|
594 |
|
595 if ( FilterAllowsContact( contact, aFilter ) ) |
|
596 { |
|
597 // contact was in the correct state |
|
598 filteredIndex++; |
|
599 |
|
600 if ( contact == aContact ) |
|
601 { |
|
602 // Contact was found, return the index |
|
603 return filteredIndex; |
|
604 } |
|
605 } |
|
606 } |
|
607 } |
|
608 return KErrNotFound; |
|
609 } |
|
610 |
|
611 // ----------------------------------------------------------------------------- |
|
612 // CCAContactList::Count |
|
613 // From MCAContactList |
|
614 // ----------------------------------------------------------------------------- |
|
615 // |
|
616 TInt CCAContactList::Count() const |
|
617 { |
|
618 return ContactCount( EFalse, EFalse ); |
|
619 } |
|
620 |
|
621 // ----------------------------------------------------------------------------- |
|
622 // CCAContactList::OnlineCount |
|
623 // From MCAContactList |
|
624 // ----------------------------------------------------------------------------- |
|
625 // |
|
626 TInt CCAContactList::OnlineCount() const |
|
627 { |
|
628 return FilteredCount( TStorageManagerGlobals::EFilterNonOffline ); |
|
629 } |
|
630 |
|
631 // ----------------------------------------------------------------------------- |
|
632 // CCAContactList::NonBlockedCount |
|
633 // From MCAContactList |
|
634 // ----------------------------------------------------------------------------- |
|
635 // |
|
636 TInt CCAContactList::NonBlockedCount() const |
|
637 { |
|
638 return FilteredCount( TStorageManagerGlobals::EFilterNonBlocked ); |
|
639 } |
|
640 |
|
641 // ----------------------------------------------------------------------------- |
|
642 // CCAContactList::operator[] |
|
643 // From MCAContactList |
|
644 // ----------------------------------------------------------------------------- |
|
645 // |
|
646 MCAStoredContact& CCAContactList::operator[]( TInt aIndex ) const |
|
647 { |
|
648 __CHAT_ASSERT_DEBUG( aIndex < iContacts.Count() ) |
|
649 return *iContacts[ aIndex ]; |
|
650 } |
|
651 |
|
652 // ----------------------------------------------------------------------------- |
|
653 // CCAContactList::OnlineContact |
|
654 // From MCAContactList |
|
655 // ----------------------------------------------------------------------------- |
|
656 // |
|
657 MCAStoredContact& CCAContactList::OnlineContact( TInt aIndex ) const |
|
658 { |
|
659 return FilteredContact( |
|
660 aIndex, TStorageManagerGlobals::EFilterNonOffline ); |
|
661 } |
|
662 |
|
663 // ----------------------------------------------------------------------------- |
|
664 // CCAContactList::NonBlockedContact |
|
665 // From MCAContactList |
|
666 // ----------------------------------------------------------------------------- |
|
667 // |
|
668 MCAStoredContact& CCAContactList::NonBlockedContact( TInt aIndex ) const |
|
669 { |
|
670 return FilteredContact( |
|
671 aIndex, TStorageManagerGlobals::EFilterNonBlocked ); |
|
672 } |
|
673 |
|
674 |
|
675 // ----------------------------------------------------------------------------- |
|
676 // CCAContactList::SetPrimaryInuse |
|
677 // From MCAContactList |
|
678 // ----------------------------------------------------------------------------- |
|
679 // |
|
680 void CCAContactList::SetPrimaryInuse( TBool aPrimaryInUse ) |
|
681 { |
|
682 if ( aPrimaryInUse ) |
|
683 { |
|
684 iCurrentCollapsed = &iPrimaryCollapsed; |
|
685 } |
|
686 else |
|
687 { |
|
688 iCurrentCollapsed = &iSecondaryCollapsed; |
|
689 } |
|
690 } |
|
691 |
|
692 // ----------------------------------------------------------------------------- |
|
693 // CCAContactList::FilteredContact |
|
694 // From MCAContactList |
|
695 // ----------------------------------------------------------------------------- |
|
696 // |
|
697 MCAStoredContact& CCAContactList::FilteredContact( |
|
698 TInt aIndex, TStorageManagerGlobals::TFilterType aFilter ) const |
|
699 { |
|
700 if ( aFilter == TStorageManagerGlobals::EFilterAll ) |
|
701 { |
|
702 return ( *this )[aIndex]; |
|
703 } |
|
704 else |
|
705 { |
|
706 TInt filteredIndex( -1 ); |
|
707 TInt count( iContacts.Count() ); |
|
708 |
|
709 for ( TInt i( 0 ); i < count; ++i ) |
|
710 { |
|
711 MCAStoredContact* contact = iContacts[i]; |
|
712 |
|
713 if ( FilterAllowsContact( contact, aFilter ) ) |
|
714 { |
|
715 // Contact was in correct state |
|
716 filteredIndex++; |
|
717 |
|
718 if ( aIndex == filteredIndex ) |
|
719 { |
|
720 // index was also correct |
|
721 return *iContacts[i]; |
|
722 } |
|
723 } |
|
724 } |
|
725 |
|
726 __CHAT_ASSERT_DEBUG( EFalse ); |
|
727 // prevent compiler warning |
|
728 return ( MCAStoredContact& )KNullDesC; |
|
729 } |
|
730 } |
|
731 |
|
732 // ----------------------------------------------------------------------------- |
|
733 // CCAContactList::FilteredCount |
|
734 // From MCAContactList |
|
735 // ----------------------------------------------------------------------------- |
|
736 // |
|
737 TInt CCAContactList::FilteredCount( |
|
738 TStorageManagerGlobals::TFilterType aFilter ) const |
|
739 { |
|
740 if ( aFilter == TStorageManagerGlobals::EFilterAll ) |
|
741 { |
|
742 return Count(); |
|
743 } |
|
744 else |
|
745 { |
|
746 TInt filtered( 0 ); |
|
747 TInt count( iContacts.Count() ); |
|
748 |
|
749 for ( TInt i( 0 ); i < count; ++i ) |
|
750 { |
|
751 if ( FilterAllowsContact( iContacts[i], aFilter ) ) |
|
752 { |
|
753 filtered++; |
|
754 } |
|
755 } |
|
756 |
|
757 return filtered; |
|
758 } |
|
759 } |
|
760 |
|
761 // ----------------------------------------------------------------------------- |
|
762 // CCAContactList::FilterAllowsContact |
|
763 // ----------------------------------------------------------------------------- |
|
764 // |
|
765 TBool CCAContactList::FilterAllowsContact( const MCAStoredContact* aContact, |
|
766 TStorageManagerGlobals::TFilterType aFilter ) const |
|
767 { |
|
768 TBool showContact( EFalse ); |
|
769 TInt myStatus( KErrNone ); |
|
770 TStorageManagerGlobals::TPresenceStatus status( |
|
771 aContact->OnlineStatus() ); |
|
772 |
|
773 if ( aFilter & TStorageManagerGlobals::EFilterAndOperation ) |
|
774 { |
|
775 myStatus = myStatus | TStorageManagerGlobals::EFilterAndOperation; |
|
776 } |
|
777 |
|
778 if ( status == TStorageManagerGlobals::EOnline ) |
|
779 { |
|
780 myStatus = myStatus | TStorageManagerGlobals::EFilterOnline; |
|
781 } |
|
782 |
|
783 if ( status == TStorageManagerGlobals::EOnline || |
|
784 status == TStorageManagerGlobals::EAway || |
|
785 status == TStorageManagerGlobals::EBusy ) |
|
786 { |
|
787 myStatus = myStatus | TStorageManagerGlobals::EFilterNonOffline; |
|
788 } |
|
789 |
|
790 if ( status == TStorageManagerGlobals::EAway ) |
|
791 { |
|
792 myStatus |= TStorageManagerGlobals::EFilterAway; |
|
793 } |
|
794 |
|
795 if ( !aContact->IsBlocked() ) |
|
796 { |
|
797 myStatus |= TStorageManagerGlobals::EFilterNonBlocked; |
|
798 } |
|
799 |
|
800 if ( aFilter & TStorageManagerGlobals::EFilterAndOperation ) |
|
801 { |
|
802 if ( ( myStatus & aFilter ) == aFilter ) |
|
803 { |
|
804 showContact = ETrue; |
|
805 } |
|
806 } |
|
807 else |
|
808 { |
|
809 if ( myStatus & aFilter ) |
|
810 { |
|
811 showContact = ETrue; |
|
812 } |
|
813 } |
|
814 |
|
815 return showContact; |
|
816 } |
|
817 |
|
818 |
|
819 // ----------------------------------------------------------------------------- |
|
820 // CCAContactList::SetSynchronised |
|
821 // ----------------------------------------------------------------------------- |
|
822 // |
|
823 void CCAContactList::SetSynchronised( |
|
824 MCAContactList::TSynchroniseState aSynchroniseState /*= ESynchroniseDone*/ ) |
|
825 { |
|
826 iSyncState = aSynchroniseState; |
|
827 iObserver.HandleChange( this, |
|
828 NULL, |
|
829 TStorageManagerGlobals::EStorageEventListChanged, |
|
830 EFalse ); |
|
831 } |
|
832 |
|
833 // ----------------------------------------------------------------------------- |
|
834 // CCAContactList::Synchronised |
|
835 // ----------------------------------------------------------------------------- |
|
836 // |
|
837 MCAContactList::TSynchroniseState CCAContactList::Synchronised() const |
|
838 { |
|
839 return iSyncState; |
|
840 } |
|
841 |
|
842 |
|
843 // End of File |