22 #include "vimpststorageutils.h" |
22 #include "vimpststorageutils.h" |
23 #include "cvimpststoragecontactsorter.h" |
23 #include "cvimpststoragecontactsorter.h" |
24 #include "mvimpststoragecontact.h" |
24 #include "mvimpststoragecontact.h" |
25 #include "mvimpststoragecontactsobserver.h" |
25 #include "mvimpststoragecontactsobserver.h" |
26 #include "tvimpststoragepanics.h" |
26 #include "tvimpststoragepanics.h" |
27 #include "vimpstdebugtrace.h" |
27 #include "uiservicetabtracer.h" |
28 #include "vimpstdebugassert.h" |
28 #include "vimpstdebugassert.h" |
29 #include "cvimpststoragecontact.h" |
29 #include "cvimpststoragecontact.h" |
30 |
30 |
31 #include <MVPbkContactLink.h> //vpbk |
31 #include <MVPbkContactLink.h> //vpbk |
32 |
32 |
86 // |
88 // |
87 CVIMPSTStorageContactList* CVIMPSTStorageContactList::NewLC(CVIMPSTStorageContactSorter& aSorter, |
89 CVIMPSTStorageContactList* CVIMPSTStorageContactList::NewLC(CVIMPSTStorageContactSorter& aSorter, |
88 const TDesC& aContactListId, |
90 const TDesC& aContactListId, |
89 const TDesC& aDisplayName ) |
91 const TDesC& aDisplayName ) |
90 { |
92 { |
|
93 TRACER_AUTO; |
91 CVIMPSTStorageContactList* self = new( ELeave ) CVIMPSTStorageContactList(aSorter ); |
94 CVIMPSTStorageContactList* self = new( ELeave ) CVIMPSTStorageContactList(aSorter ); |
92 CleanupStack::PushL( self ); |
95 CleanupStack::PushL( self ); |
93 self->ConstructL( aContactListId, aDisplayName ); |
96 self->ConstructL( aContactListId, aDisplayName ); |
94 return self; |
97 return self; |
95 } |
98 } |
139 // CVIMPSTStorageContactList::AddStorageContactToCacheL |
142 // CVIMPSTStorageContactList::AddStorageContactToCacheL |
140 // ----------------------------------------------------------------------------- |
143 // ----------------------------------------------------------------------------- |
141 // |
144 // |
142 TInt CVIMPSTStorageContactList::AddStorageContactToCacheL( MVIMPSTStorageContact* aContact, TInt& aIndex ) |
145 TInt CVIMPSTStorageContactList::AddStorageContactToCacheL( MVIMPSTStorageContact* aContact, TInt& aIndex ) |
143 { |
146 { |
144 TRACE( T_LIT("CVIMPSTStorageContactList::AddStorageContactToCacheL begin") ); |
147 TRACER_AUTO; |
145 |
148 |
146 if( !aContact ) |
149 if( !aContact ) |
147 { |
150 { |
148 return KErrArgument; |
151 return KErrArgument; |
149 } |
152 } |
150 TPtrC userID = aContact->UserId(); |
153 TPtrC userID = aContact->UserId(); |
151 TRACE( T_LIT("CVIMPSTStorageContactList::AddStorageContactToCacheL userId = %S"), &userID ); |
154 TRACE( " userId = %S", &userID ); |
152 // optimize insert for inserting of reverse alphabetical order |
155 // optimize insert for inserting of reverse alphabetical order |
153 TInt idIndex( 0 ); |
156 TInt idIndex( 0 ); |
154 TInt count( iOrderedContacts.Count() ); |
157 TInt count( iOrderedContacts.Count() ); |
155 TRACE( T_LIT("CVIMPSTStorageContactList::AddStorageContactToCacheL count = %d"),count ); |
158 TRACE("count = %d",count ); |
156 if( count && aContact->UserId().Length() && |
159 if( count && aContact->UserId().Length() && |
157 ( 0 <= VIMPSTStorageUtils::NeutralCompare( aContact->UserId(), |
160 ( 0 <= VIMPSTStorageUtils::NeutralCompare( aContact->UserId(), |
158 iOrderedContacts[ 0 ]->UserId() ) ) ) |
161 iOrderedContacts[ 0 ]->UserId() ) ) ) |
159 { |
162 { |
160 TRACE( T_LIT("CVIMPSTStorageContactList::AddStorageContactToCacheL inside if") ); |
163 TRACE( "inside if" ); |
161 // there are items and the contact should not be inserted to beginning |
164 // there are items and the contact should not be inserted to beginning |
162 // => find the correct place |
165 // => find the correct place |
163 TLinearOrder< MVIMPSTStorageContact > userIdOrder( *CompareUserIdAlphabetically ); |
166 TLinearOrder< MVIMPSTStorageContact > userIdOrder( *CompareUserIdAlphabetically ); |
164 if( KErrNone == iOrderedContacts.FindInOrder( aContact, idIndex, userIdOrder ) ) |
167 if( KErrNone == iOrderedContacts.FindInOrder( aContact, idIndex, userIdOrder ) ) |
165 { |
168 { |
166 TRACE( T_LIT("CVIMPSTStorageContactList::AddStorageContactToCacheL contact already exists.") ); |
169 TRACE( "contact already exists." ); |
167 // this contact already exists, return it |
170 // this contact already exists, return it |
168 return KErrAlreadyExists; |
171 return KErrAlreadyExists; |
169 } |
172 } |
170 } |
173 } |
171 TRACE( T_LIT("CVIMPSTStorageContactList::AddStorageContactToCacheL inserting the contact") ); |
174 TRACE( "inserting the contact" ); |
172 // the position is now correct, insert the contact |
175 // the position is now correct, insert the contact |
173 iOrderedContacts.InsertL( aContact, idIndex ); |
176 iOrderedContacts.InsertL( aContact, idIndex ); |
174 |
177 |
175 // insert also to list sorted by contact "identification" |
178 // insert also to list sorted by contact "identification" |
176 TInt err( KErrNone ); |
179 TInt err( KErrNone ); |
177 count = iContactArray.Count(); |
180 count = iContactArray.Count(); |
178 TRACE( T_LIT("CVIMPSTStorageContactList::AddStorageContactToCacheL iContactsArray count %d"),count ); |
181 TRACE( "iContactsArray count %d",count ); |
179 TLinearOrder< MVIMPSTStorageContact >& order = iSorter.InsertOrder(); |
182 TLinearOrder< MVIMPSTStorageContact >& order = iSorter.InsertOrder(); |
180 if( count && 0 > (*order)( aContact, iContactArray[ 0 ] ) ) |
183 if( count && 0 > (*order)( aContact, iContactArray[ 0 ] ) ) |
181 { |
184 { |
182 // the item should be inserted in the beginning of the array |
185 // the item should be inserted in the beginning of the array |
183 err = iContactArray.Insert( aContact, 0 ); |
186 err = iContactArray.Insert( aContact, 0 ); |
185 else |
188 else |
186 { |
189 { |
187 // insert in correct position |
190 // insert in correct position |
188 err = iContactArray.InsertInOrderAllowRepeats( aContact, order ); |
191 err = iContactArray.InsertInOrderAllowRepeats( aContact, order ); |
189 } |
192 } |
190 TRACE( T_LIT("CVIMPSTStorageContactList::AddStorageContactToCacheL iContactsArray inserting error %d"),err ); |
193 TRACE( "iContactsArray inserting error %d",err ); |
191 if( err != KErrNone ) |
194 if( err != KErrNone ) |
192 { |
195 { |
193 // appending to second array did not succeed, so remove from first and leave |
196 // appending to second array did not succeed, so remove from first and leave |
194 iOrderedContacts.Remove( idIndex ); |
197 iOrderedContacts.Remove( idIndex ); |
195 User::Leave( err ); |
198 User::Leave( err ); |
196 } |
199 } |
197 aIndex = idIndex; |
200 aIndex = idIndex; |
198 TRACE( T_LIT("CVIMPSTStorageContactList::AddStorageContactToCacheL End") ); |
|
199 return err; |
201 return err; |
200 } |
202 } |
201 |
203 |
202 // ----------------------------------------------------------------------------- |
204 // ----------------------------------------------------------------------------- |
203 // CVIMPSTStorageContactList::RemoveContactFromCacheL |
205 // CVIMPSTStorageContactList::RemoveContactFromCacheL |
204 // ----------------------------------------------------------------------------- |
206 // ----------------------------------------------------------------------------- |
205 // |
207 // |
206 TInt CVIMPSTStorageContactList::RemoveContactFromCacheL( const TDesC& aContactId, TInt& aIndex ) |
208 TInt CVIMPSTStorageContactList::RemoveContactFromCacheL( const TDesC& aContactId, TInt& aIndex ) |
207 { |
209 { |
|
210 TRACER_AUTO; |
208 TInt orderedIndex(0); |
211 TInt orderedIndex(0); |
209 TInt contactIndex = FindContactIndex( aContactId, orderedIndex ); |
212 TInt contactIndex = FindContactIndex( aContactId, orderedIndex ); |
210 aIndex = contactIndex; |
213 aIndex = contactIndex; |
211 if( KErrNotFound != contactIndex ) |
214 if( KErrNotFound != contactIndex ) |
212 { |
215 { |
224 // CVIMPSTStorageContactList::RemoveContactFromCacheL |
227 // CVIMPSTStorageContactList::RemoveContactFromCacheL |
225 // ----------------------------------------------------------------------------- |
228 // ----------------------------------------------------------------------------- |
226 // |
229 // |
227 TInt CVIMPSTStorageContactList::RemoveContactFromCacheL( const MVPbkContactLink& aContactLink, TInt& index ) |
230 TInt CVIMPSTStorageContactList::RemoveContactFromCacheL( const MVPbkContactLink& aContactLink, TInt& index ) |
228 { |
231 { |
|
232 TRACER_AUTO; |
229 TInt error = KErrNotFound; |
233 TInt error = KErrNotFound; |
230 TInt orderedIndex(0); |
234 TInt orderedIndex(0); |
231 TInt contactIndex = FindContactByLinkL( aContactLink, orderedIndex ); |
235 TInt contactIndex = FindContactByLinkL( aContactLink, orderedIndex ); |
232 index = contactIndex; |
236 index = contactIndex; |
233 if( KErrNotFound != contactIndex ) |
237 if( KErrNotFound != contactIndex ) |
324 // CVIMPSTStorageContactList::ResortContact |
330 // CVIMPSTStorageContactList::ResortContact |
325 // ----------------------------------------------------------------------------- |
331 // ----------------------------------------------------------------------------- |
326 // |
332 // |
327 void CVIMPSTStorageContactList::ResortContact( MVIMPSTStorageContact* aContact ) |
333 void CVIMPSTStorageContactList::ResortContact( MVIMPSTStorageContact* aContact ) |
328 { |
334 { |
|
335 TRACER_AUTO; |
329 // let it panic, if index is not found, which would be bad |
336 // let it panic, if index is not found, which would be bad |
330 TInt index( iContactArray.Find( aContact ) ); |
337 TInt index( iContactArray.Find( aContact ) ); |
331 __ASSERT_DEBUG( index != KErrNotFound , Panic( ESortingCorupted )); |
338 __ASSERT_DEBUG( index != KErrNotFound , Panic( ESortingCorupted )); |
332 // Check if resort is even needed for the contact |
339 // Check if resort is even needed for the contact |
333 TLinearOrder< MVIMPSTStorageContact >& order = iSorter.InsertOrder(); |
340 TLinearOrder< MVIMPSTStorageContact >& order = iSorter.InsertOrder(); |
504 // ----------------------------------------------------------------------------- |
515 // ----------------------------------------------------------------------------- |
505 // |
516 // |
506 TBool CVIMPSTStorageContactList::FilterAllowsContact( const MVIMPSTStorageContact* aContact, |
517 TBool CVIMPSTStorageContactList::FilterAllowsContact( const MVIMPSTStorageContact* aContact, |
507 TVIMPSTEnums::TFilterType aFilter ) const |
518 TVIMPSTEnums::TFilterType aFilter ) const |
508 { |
519 { |
|
520 TRACER_AUTO; |
509 TBool showContact( EFalse ); |
521 TBool showContact( EFalse ); |
510 TInt myStatus( KErrNone ); |
522 TInt myStatus( KErrNone ); |
511 TVIMPSTEnums::TOnlineStatus status( |
523 TVIMPSTEnums::TOnlineStatus status( |
512 aContact->OnlineStatus() ); |
524 aContact->OnlineStatus() ); |
513 |
525 |
556 // CVIMPSTStorageContactList::FindContact |
568 // CVIMPSTStorageContactList::FindContact |
557 // ----------------------------------------------------------------------------- |
569 // ----------------------------------------------------------------------------- |
558 // |
570 // |
559 MVIMPSTStorageContact* CVIMPSTStorageContactList::FindContact( const TDesC& aContactId ) |
571 MVIMPSTStorageContact* CVIMPSTStorageContactList::FindContact( const TDesC& aContactId ) |
560 { |
572 { |
|
573 TRACER_AUTO; |
561 TInt orderedIndex(0); |
574 TInt orderedIndex(0); |
562 TInt contactIndex = FindContactIndex( aContactId, orderedIndex ); |
575 TInt contactIndex = FindContactIndex( aContactId, orderedIndex ); |
563 return ( contactIndex >= 0 ? iContactArray[ contactIndex ] : NULL ); |
576 return ( contactIndex >= 0 ? iContactArray[ contactIndex ] : NULL ); |
564 } |
577 } |
565 // ----------------------------------------------------------------------------- |
578 // ----------------------------------------------------------------------------- |
566 // CVIMPSTStorageContactList::FindContactByContactLinkL |
579 // CVIMPSTStorageContactList::FindContactByContactLinkL |
567 // ----------------------------------------------------------------------------- |
580 // ----------------------------------------------------------------------------- |
568 // |
581 // |
569 MVIMPSTStorageContact* CVIMPSTStorageContactList::FindContactByContactLink( const MVPbkContactLink& aContactLink ) |
582 MVIMPSTStorageContact* CVIMPSTStorageContactList::FindContactByContactLink( const MVPbkContactLink& aContactLink ) |
570 { |
583 { |
|
584 TRACER_AUTO; |
571 TInt orderedIndex(0); |
585 TInt orderedIndex(0); |
572 TInt contactIndex = -1; |
586 TInt contactIndex = -1; |
573 TRAP_IGNORE( contactIndex = FindContactByLinkL( aContactLink, orderedIndex );) |
587 TRAP_IGNORE( contactIndex = FindContactByLinkL( aContactLink, orderedIndex );) |
574 return ( contactIndex >= 0 ? iContactArray[ contactIndex ] : NULL ); |
588 return ( contactIndex >= 0 ? iContactArray[ contactIndex ] : NULL ); |
575 } |
589 } |
579 // ----------------------------------------------------------------------------- |
593 // ----------------------------------------------------------------------------- |
580 // |
594 // |
581 TInt CVIMPSTStorageContactList::FindContactByLinkL( const MVPbkContactLink& aContactLink, |
595 TInt CVIMPSTStorageContactList::FindContactByLinkL( const MVPbkContactLink& aContactLink, |
582 TInt& aIndexOrderedArray ) const |
596 TInt& aIndexOrderedArray ) const |
583 { |
597 { |
|
598 TRACER_AUTO; |
584 TInt count( iOrderedContacts.Count() ); |
599 TInt count( iOrderedContacts.Count() ); |
585 TInt contactIndex = KErrNotFound; |
600 TInt contactIndex = KErrNotFound; |
586 //Does a Linear Search |
601 //Does a Linear Search |
587 for (TInt index = 0; index<count; index++) |
602 for (TInt index = 0; index<count; index++) |
588 { |
603 { |