uiservicetab/vimpststorage/src/cvimpststoragecontactlist.cpp
branchRCL_3
changeset 14 9fdee5e1da30
parent 0 5e5d6b214f4f
equal deleted inserted replaced
13:796276a1bdcc 14:9fdee5e1da30
    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 
    57 // -----------------------------------------------------------------------------
    57 // -----------------------------------------------------------------------------
    58 //
    58 //
    59 void CVIMPSTStorageContactList::ConstructL( const TDesC& aContactListId, 
    59 void CVIMPSTStorageContactList::ConstructL( const TDesC& aContactListId, 
    60                                  const TDesC& aDisplayName )
    60                                  const TDesC& aDisplayName )
    61     {
    61     {
       
    62 	TRACER_AUTO;
    62     iListId = aContactListId.AllocL();  
    63     iListId = aContactListId.AllocL();  
    63     iDisplayName = aDisplayName.AllocL();
    64     iDisplayName = aDisplayName.AllocL();
    64     }
    65     }
    65 
    66 
    66 // -----------------------------------------------------------------------------
    67 // -----------------------------------------------------------------------------
    70 //
    71 //
    71 CVIMPSTStorageContactList* CVIMPSTStorageContactList::NewL(CVIMPSTStorageContactSorter& aSorter,
    72 CVIMPSTStorageContactList* CVIMPSTStorageContactList::NewL(CVIMPSTStorageContactSorter& aSorter,
    72 					                                      const TDesC& aContactListId, 
    73 					                                      const TDesC& aContactListId, 
    73 					                                      const TDesC& aDisplayName )
    74 					                                      const TDesC& aDisplayName )
    74     {
    75     {
       
    76 	TRACER_AUTO;
    75     CVIMPSTStorageContactList* self = NewLC(  aSorter,
    77     CVIMPSTStorageContactList* self = NewLC(  aSorter,
    76 			                                  aContactListId, 
    78 			                                  aContactListId, 
    77 			                                  aDisplayName );
    79 			                                  aDisplayName );
    78     CleanupStack::Pop( self );
    80     CleanupStack::Pop( self );
    79     return self;
    81     return self;
    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 )
   247 // -----------------------------------------------------------------------------
   251 // -----------------------------------------------------------------------------
   248 //
   252 //
   249 TInt CVIMPSTStorageContactList::ContactCount( TBool aSkipOfflineContacts,
   253 TInt CVIMPSTStorageContactList::ContactCount( TBool aSkipOfflineContacts,
   250 						   TBool aSkipBlocekedContacts ) const
   254 						   TBool aSkipBlocekedContacts ) const
   251     {
   255     {
       
   256 	TRACER_AUTO;
   252     if( !aSkipOfflineContacts && !aSkipBlocekedContacts )
   257     if( !aSkipOfflineContacts && !aSkipBlocekedContacts )
   253         {
   258         {
   254         return iContactArray.Count();
   259         return iContactArray.Count();
   255         }
   260         }
   256     TInt countOfContacts( 0 );
   261     TInt countOfContacts( 0 );
   275 // -----------------------------------------------------------------------------
   280 // -----------------------------------------------------------------------------
   276 //
   281 //
   277 TInt CVIMPSTStorageContactList::FindContactIndex( const TDesC& aUserId,
   282 TInt CVIMPSTStorageContactList::FindContactIndex( const TDesC& aUserId,
   278                                        TInt& aOrderedIndex ) const
   283                                        TInt& aOrderedIndex ) const
   279     {
   284     {
       
   285 	TRACER_AUTO;
   280      TInt low( 0 );
   286      TInt low( 0 );
   281     TInt high( iOrderedContacts.Count() );
   287     TInt high( iOrderedContacts.Count() );
   282     while( high > low )
   288     while( high > low )
   283         {
   289         {
   284         TInt m( ( low + high ) / 2 );
   290         TInt m( ( low + high ) / 2 );
   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();
   363 // -----------------------------------------------------------------------------
   370 // -----------------------------------------------------------------------------
   364 //
   371 //
   365 TInt CVIMPSTStorageContactList::FindIndexOfContact( const MVIMPSTStorageContact* aContact,
   372 TInt CVIMPSTStorageContactList::FindIndexOfContact( const MVIMPSTStorageContact* aContact,
   366                             TVIMPSTEnums::TFilterType aFilter  ) const
   373                             TVIMPSTEnums::TFilterType aFilter  ) const
   367     {    
   374     {    
       
   375 	TRACER_AUTO;
   368     TInt count( iContactArray.Count() ); 
   376     TInt count( iContactArray.Count() ); 
   369     if ( aFilter == TVIMPSTEnums::EFilterAll )
   377     if ( aFilter == TVIMPSTEnums::EFilterAll )
   370 		{
   378 		{
   371         for( TInt a( 0 ); a < count; ++a )
   379         for( TInt a( 0 ); a < count; ++a )
   372             {
   380             {
   422 // From MVIMPSTStorageContactList
   430 // From MVIMPSTStorageContactList
   423 // -----------------------------------------------------------------------------
   431 // -----------------------------------------------------------------------------
   424 //
   432 //
   425 MVIMPSTStorageContact& CVIMPSTStorageContactList::operator[]( TInt aIndex ) const
   433 MVIMPSTStorageContact& CVIMPSTStorageContactList::operator[]( TInt aIndex ) const
   426     {
   434     {
       
   435 	TRACER_AUTO;
   427     __CHAT_ASSERT_DEBUG( aIndex < iContactArray.Count() )
   436     __CHAT_ASSERT_DEBUG( aIndex < iContactArray.Count() )
   428     return *iContactArray[ aIndex ];
   437     return *iContactArray[ aIndex ];
   429     }
   438     }
   430     
   439     
   431 // -----------------------------------------------------------------------------
   440 // -----------------------------------------------------------------------------
   445 // -----------------------------------------------------------------------------
   454 // -----------------------------------------------------------------------------
   446 //
   455 //
   447 MVIMPSTStorageContact& CVIMPSTStorageContactList::FilteredContact( 
   456 MVIMPSTStorageContact& CVIMPSTStorageContactList::FilteredContact( 
   448                 TInt aIndex, TVIMPSTEnums::TFilterType aFilter ) const
   457                 TInt aIndex, TVIMPSTEnums::TFilterType aFilter ) const
   449 	{
   458 	{
       
   459 	TRACER_AUTO;
   450     if ( aFilter == TVIMPSTEnums::EFilterAll )
   460     if ( aFilter == TVIMPSTEnums::EFilterAll )
   451 		{
   461 		{
   452 		return (*this)[aIndex];
   462 		return (*this)[aIndex];
   453 		}
   463 		}
   454 	else
   464 	else
   481 // -----------------------------------------------------------------------------
   491 // -----------------------------------------------------------------------------
   482 //
   492 //
   483 TInt CVIMPSTStorageContactList::FilteredCount( 
   493 TInt CVIMPSTStorageContactList::FilteredCount( 
   484                             TVIMPSTEnums::TFilterType aFilter ) const
   494                             TVIMPSTEnums::TFilterType aFilter ) const
   485 	{
   495 	{
       
   496 	TRACER_AUTO;
   486     if ( aFilter == TVIMPSTEnums::EFilterAll )
   497     if ( aFilter == TVIMPSTEnums::EFilterAll )
   487 		{
   498 		{
   488 		return Count();
   499 		return Count();
   489 		}
   500 		}
   490 	TInt filtered( 0 );
   501 	TInt filtered( 0 );
   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 		{