uiservicetab/vimpststorage/src/cvimpststoragecontactlist.cpp
branchRCL_3
changeset 22 3104fc151679
parent 21 2b7283837edb
child 23 9a48e301e94b
equal deleted inserted replaced
21:2b7283837edb 22:3104fc151679
     1 /*
       
     2 * Copyright (c) 2008 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:  Contact list container implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "cvimpststoragecontactlist.h"
       
    22 #include "vimpststorageutils.h"
       
    23 #include "cvimpststoragecontactsorter.h"
       
    24 #include "mvimpststoragecontact.h"
       
    25 #include "mvimpststoragecontactsobserver.h"
       
    26 #include "tvimpststoragepanics.h"
       
    27 #include "uiservicetabtracer.h"
       
    28 #include "vimpstdebugassert.h"
       
    29 #include "cvimpststoragecontact.h"
       
    30 
       
    31 #include <MVPbkContactLink.h> //vpbk
       
    32 
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // Compares two contacts
       
    36 TInt CompareUserIdAlphabetically(
       
    37                            const MVIMPSTStorageContact& aFirst,
       
    38                            const MVIMPSTStorageContact& aSecond )
       
    39     {
       
    40     return VIMPSTStorageUtils::NeutralCompare( aFirst.UserId(), aSecond.UserId() );
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CVIMPSTStorageContactList::CVIMPSTStorageContactList
       
    45 // C++ default constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CVIMPSTStorageContactList::CVIMPSTStorageContactList( CVIMPSTStorageContactSorter& aSorter ) 
       
    50 : iSorter( aSorter )
       
    51     {
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CVIMPSTStorageContactList::ConstructL
       
    56 // Symbian 2nd phase constructor can leave.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 void CVIMPSTStorageContactList::ConstructL( const TDesC& aContactListId, 
       
    60                                  const TDesC& aDisplayName )
       
    61     {
       
    62 	TRACER_AUTO;
       
    63     iListId = aContactListId.AllocL();  
       
    64     iDisplayName = aDisplayName.AllocL();
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CVIMPSTStorageContactList::NewL
       
    69 // Two-phased constructor.
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CVIMPSTStorageContactList* CVIMPSTStorageContactList::NewL(CVIMPSTStorageContactSorter& aSorter,
       
    73 					                                      const TDesC& aContactListId, 
       
    74 					                                      const TDesC& aDisplayName )
       
    75     {
       
    76 	TRACER_AUTO;
       
    77     CVIMPSTStorageContactList* self = NewLC(  aSorter,
       
    78 			                                  aContactListId, 
       
    79 			                                  aDisplayName );
       
    80     CleanupStack::Pop( self );
       
    81     return self;
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CVIMPSTStorageContactList::NewLC
       
    86 // Two-phased constructor.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 CVIMPSTStorageContactList* CVIMPSTStorageContactList::NewLC(CVIMPSTStorageContactSorter& aSorter,
       
    90 					                                       const TDesC& aContactListId, 
       
    91 					                                       const TDesC& aDisplayName )
       
    92     {
       
    93 	TRACER_AUTO;
       
    94     CVIMPSTStorageContactList* self = new( ELeave ) CVIMPSTStorageContactList(aSorter );
       
    95     CleanupStack::PushL( self );
       
    96     self->ConstructL( aContactListId, aDisplayName );
       
    97     return self;
       
    98     }
       
    99 
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CVIMPSTStorageContactList::destructor
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 CVIMPSTStorageContactList::~CVIMPSTStorageContactList()
       
   106     {
       
   107     iContactArray.ResetAndDestroy();
       
   108     iContactArray.Close();
       
   109     iOrderedContacts.Reset();
       
   110     delete iListId;
       
   111     delete iDisplayName;
       
   112     }
       
   113     
       
   114     
       
   115 // -----------------------------------------------------------------------------
       
   116 // CVIMPSTStorageContactList::ListId
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 const TDesC& CVIMPSTStorageContactList::ListId() const
       
   120     {
       
   121     if( iListId )
       
   122         {
       
   123         return *iListId;
       
   124         }
       
   125     return KNullDesC;        
       
   126     }
       
   127     
       
   128        
       
   129 // -----------------------------------------------------------------------------
       
   130 // CVIMPSTStorageContactList::DisplayName
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 TPtrC CVIMPSTStorageContactList::DisplayName() const
       
   134     {
       
   135     if( iDisplayName )
       
   136         {
       
   137         return *iDisplayName;
       
   138         }
       
   139     return KNullDesC();
       
   140     }
       
   141 // -----------------------------------------------------------------------------
       
   142 // CVIMPSTStorageContactList::AddStorageContactToCacheL
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 TInt CVIMPSTStorageContactList::AddStorageContactToCacheL( MVIMPSTStorageContact* aContact, TInt& aIndex )
       
   146     {
       
   147 	TRACER_AUTO;
       
   148     
       
   149     if( !aContact )
       
   150 	    {
       
   151 	    return KErrArgument;	
       
   152 	    }
       
   153     TPtrC userID = aContact->UserId();
       
   154     TRACE( " userId = %S", &userID ); 
       
   155     // optimize insert for inserting of reverse alphabetical order
       
   156     TInt idIndex( 0 );
       
   157     TInt count( iOrderedContacts.Count() );
       
   158     TRACE("count = %d",count ); 
       
   159     if( count && aContact->UserId().Length() &&
       
   160     	 ( 0 <= VIMPSTStorageUtils::NeutralCompare( aContact->UserId(),
       
   161     								  iOrderedContacts[ 0 ]->UserId() ) ) )
       
   162     	{
       
   163     TRACE( "inside if" );
       
   164     	// there are items and the contact should not be inserted to beginning
       
   165     	// => find the correct place
       
   166 	    TLinearOrder< MVIMPSTStorageContact > userIdOrder( *CompareUserIdAlphabetically );
       
   167 	    if( KErrNone == iOrderedContacts.FindInOrder( aContact, idIndex, userIdOrder ) )
       
   168     	    {
       
   169 	    TRACE( "contact already exists." ); 
       
   170             // this contact already exists, return it
       
   171             return KErrAlreadyExists;
       
   172             }
       
   173     	}
       
   174     TRACE( "inserting the contact" ); 
       
   175     // the position is now correct, insert the contact
       
   176     iOrderedContacts.InsertL( aContact, idIndex );
       
   177 
       
   178     // insert also to list sorted by contact "identification"
       
   179     TInt err( KErrNone );
       
   180     count = iContactArray.Count();  
       
   181     TRACE( "iContactsArray count %d",count ); 
       
   182     TLinearOrder< MVIMPSTStorageContact >& order = iSorter.InsertOrder();
       
   183     if( count &&  0 > (*order)( aContact, iContactArray[ 0 ] ) )
       
   184     	{
       
   185     	// the item should be inserted in the beginning of the array
       
   186 		err = iContactArray.Insert( aContact, 0 );
       
   187     	}
       
   188     else
       
   189        	{
       
   190        	// insert in correct position
       
   191        	err = iContactArray.InsertInOrderAllowRepeats( aContact, order );
       
   192        	}
       
   193     TRACE( "iContactsArray inserting error %d",err ); 
       
   194     if( err != KErrNone )
       
   195         {
       
   196         // appending to second array did not succeed, so remove from first and leave
       
   197         iOrderedContacts.Remove( idIndex );
       
   198         User::Leave( err );
       
   199         }
       
   200     aIndex = idIndex;
       
   201     return err;
       
   202     }
       
   203  
       
   204 // -----------------------------------------------------------------------------
       
   205 // CVIMPSTStorageContactList::RemoveContactFromCacheL
       
   206 // -----------------------------------------------------------------------------
       
   207 //
       
   208 TInt CVIMPSTStorageContactList::RemoveContactFromCacheL( const TDesC& aContactId, TInt& aIndex )
       
   209     {
       
   210 	TRACER_AUTO;
       
   211     TInt orderedIndex(0);
       
   212     TInt contactIndex = FindContactIndex( aContactId, orderedIndex );
       
   213 	aIndex = contactIndex;
       
   214     if( KErrNotFound != contactIndex )
       
   215         {
       
   216         delete iContactArray[ contactIndex ];
       
   217         iContactArray.Remove( contactIndex );
       
   218         iOrderedContacts.Remove( orderedIndex );
       
   219         iContactArray.Compress();
       
   220         iOrderedContacts.Compress();
       
   221         return KErrNone;
       
   222         }
       
   223     return KErrNotFound;
       
   224     }
       
   225 
       
   226 // -----------------------------------------------------------------------------
       
   227 // CVIMPSTStorageContactList::RemoveContactFromCacheL
       
   228 // -----------------------------------------------------------------------------
       
   229 //
       
   230 TInt CVIMPSTStorageContactList::RemoveContactFromCacheL( const MVPbkContactLink& aContactLink, TInt& index )
       
   231     {
       
   232 	TRACER_AUTO;
       
   233     TInt error = KErrNotFound;
       
   234     TInt orderedIndex(0);
       
   235     TInt contactIndex = FindContactByLinkL( aContactLink, orderedIndex );
       
   236 	index = contactIndex;
       
   237     if( KErrNotFound != contactIndex )
       
   238         {
       
   239         MVIMPSTStorageContact* contact = iContactArray[ contactIndex ];
       
   240         iContactArray.Remove( contactIndex );
       
   241         iOrderedContacts.Remove( orderedIndex );
       
   242         delete contact;
       
   243         iContactArray.Compress();
       
   244         iOrderedContacts.Compress();
       
   245         error = KErrNone;
       
   246         }
       
   247     return error;
       
   248     }    
       
   249  // -----------------------------------------------------------------------------
       
   250 // CVIMPSTStorageContactList::FindContact
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 TInt CVIMPSTStorageContactList::ContactCount( TBool aSkipOfflineContacts,
       
   254 						   TBool aSkipBlocekedContacts ) const
       
   255     {
       
   256 	TRACER_AUTO;
       
   257     if( !aSkipOfflineContacts && !aSkipBlocekedContacts )
       
   258         {
       
   259         return iContactArray.Count();
       
   260         }
       
   261     TInt countOfContacts( 0 );
       
   262     TInt count( iContactArray.Count() );
       
   263     for( TInt a( 0 ); a < count; ++a )
       
   264         {
       
   265         TVIMPSTEnums::TOnlineStatus status(
       
   266                                     iContactArray[ a ]->OnlineStatus() );
       
   267         if( status == TVIMPSTEnums::EOnline ||
       
   268             status == TVIMPSTEnums::EAway ||
       
   269             status == TVIMPSTEnums::EBusy ||
       
   270             status == TVIMPSTEnums::EDoNotDisturb )
       
   271             {
       
   272 	        ++countOfContacts;
       
   273             }
       
   274         }
       
   275     return countOfContacts;
       
   276     }
       
   277             
       
   278 // -----------------------------------------------------------------------------
       
   279 // CVIMPSTStorageContactList::FindContactIndex
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 TInt CVIMPSTStorageContactList::FindContactIndex( const TDesC& aUserId,
       
   283                                        TInt& aOrderedIndex ) const
       
   284     {
       
   285 	TRACER_AUTO;
       
   286      TInt low( 0 );
       
   287     TInt high( iOrderedContacts.Count() );
       
   288     while( high > low )
       
   289         {
       
   290         TInt m( ( low + high ) / 2 );
       
   291         TInt compare( VIMPSTStorageUtils::NeutralCompare( aUserId, iOrderedContacts[ m ]->UserId() ) );
       
   292         if ( compare == KErrNone )
       
   293             {
       
   294             aOrderedIndex = m;
       
   295             return FindContactEntry( iOrderedContacts[ m ] );
       
   296             }
       
   297         else if ( compare > 0 )
       
   298             {
       
   299             low = m + 1;
       
   300             }
       
   301         else
       
   302             {
       
   303             high = m;
       
   304             }
       
   305         }
       
   306     aOrderedIndex = KErrNotFound;
       
   307     return KErrNotFound;
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // CVIMPSTStorageContactList::FindContactEntry
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 TInt CVIMPSTStorageContactList::FindContactEntry( const MVIMPSTStorageContact* aContact ) const
       
   315     {
       
   316     TInt index( iContactArray.Find( aContact ) );
       
   317     __ASSERT_DEBUG( index != KErrNotFound , Panic( EContactsArrayOutOfSync ));
       
   318     return index;
       
   319     }
       
   320 // -----------------------------------------------------------------------------
       
   321 // CVIMPSTStorageContactList::Sort
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 void CVIMPSTStorageContactList::Sort()
       
   325     {
       
   326     iSorter.Sort( iContactArray );
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // CVIMPSTStorageContactList::ResortContact
       
   331 // -----------------------------------------------------------------------------
       
   332 //
       
   333 void CVIMPSTStorageContactList::ResortContact( MVIMPSTStorageContact* aContact )
       
   334     {
       
   335 	TRACER_AUTO;
       
   336     // let it panic, if index is not found, which would be bad
       
   337     TInt index( iContactArray.Find( aContact ) );
       
   338     __ASSERT_DEBUG( index != KErrNotFound , Panic( ESortingCorupted ));
       
   339     // Check if resort is even needed for the contact
       
   340     TLinearOrder< MVIMPSTStorageContact >& order = iSorter.InsertOrder();
       
   341     if(
       
   342         (
       
   343           ( index == 0 )
       
   344           ||
       
   345           ( 0 >= (*order)( iContactArray[ index - 1], aContact ) )
       
   346         )
       
   347         &&
       
   348         (
       
   349           ( index == ( iContactArray.Count() - 1 ) )
       
   350           ||
       
   351           ( 0 <= (*order)( iContactArray[ index + 1], aContact ) )
       
   352         )
       
   353       )
       
   354         {
       
   355         // the item is in correct position
       
   356         // => no need to resort
       
   357         return;
       
   358         }
       
   359     
       
   360     iContactArray.Remove( index );
       
   361     // this should alway succeed, since we did not actually add anything to array
       
   362     // no need to add contact to the ordered array, should be there already
       
   363     TInt err( iContactArray.InsertInOrderAllowRepeats( aContact, order ) );
       
   364     __ASSERT_DEBUG( err == KErrNone , Panic( ESortingCorupted ));
       
   365     }
       
   366    
       
   367 // -----------------------------------------------------------------------------
       
   368 // CVIMPSTStorageContactList::FindIndexOfContact
       
   369 // From MVIMPSTContactList
       
   370 // -----------------------------------------------------------------------------
       
   371 //
       
   372 TInt CVIMPSTStorageContactList::FindIndexOfContact( const MVIMPSTStorageContact* aContact,
       
   373                             TVIMPSTEnums::TFilterType aFilter  ) const
       
   374     {    
       
   375 	TRACER_AUTO;
       
   376     TInt count( iContactArray.Count() ); 
       
   377     if ( aFilter == TVIMPSTEnums::EFilterAll )
       
   378 		{
       
   379         for( TInt a( 0 ); a < count; ++a )
       
   380             {
       
   381             const MVIMPSTStorageContact* contact = iContactArray[ a ];
       
   382             if( aContact == contact )
       
   383                 {
       
   384                 return a;
       
   385                 }
       
   386             }		
       
   387 		}
       
   388 	else
       
   389 	    {
       
   390 	    TInt filteredIndex( -1 );
       
   391 	    for( TInt i( 0 ); i < count; ++i )
       
   392             {
       
   393             MVIMPSTStorageContact* contact ( iContactArray[i] );
       
   394             if ( FilterAllowsContact( contact, aFilter ) )
       
   395                 {
       
   396                 // contact was in the correct state
       
   397                 filteredIndex++; 
       
   398                 if( contact == aContact)
       
   399                     {
       
   400                     // Contact was found, return the index
       
   401                     return filteredIndex;
       
   402                     }                  
       
   403                 }        
       
   404             }    
       
   405 	    }
       
   406     return KErrNotFound;
       
   407     }
       
   408        
       
   409 // -----------------------------------------------------------------------------
       
   410 // CVIMPSTStorageContactList::Count
       
   411 // From MVIMPSTStorageContactList
       
   412 // -----------------------------------------------------------------------------
       
   413 //
       
   414 TInt CVIMPSTStorageContactList::Count() const
       
   415     {
       
   416     return ContactCount( EFalse, EFalse );
       
   417     }
       
   418     
       
   419 // -----------------------------------------------------------------------------
       
   420 // CVIMPSTStorageContactList::OnlineCount
       
   421 // From MVIMPSTStorageContactList
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 TInt CVIMPSTStorageContactList::OnlineCount() const
       
   425     {
       
   426     return FilteredCount( TVIMPSTEnums::EFilterNonOffline );
       
   427     }
       
   428 // -----------------------------------------------------------------------------
       
   429 // CVIMPSTStorageContactList::operator[]
       
   430 // From MVIMPSTStorageContactList
       
   431 // -----------------------------------------------------------------------------
       
   432 //
       
   433 MVIMPSTStorageContact& CVIMPSTStorageContactList::operator[]( TInt aIndex ) const
       
   434     {
       
   435 	TRACER_AUTO;
       
   436     __CHAT_ASSERT_DEBUG( aIndex < iContactArray.Count() )
       
   437     return *iContactArray[ aIndex ];
       
   438     }
       
   439     
       
   440 // -----------------------------------------------------------------------------
       
   441 // CVIMPSTStorageContactList::OnlineContact
       
   442 // From MVIMPSTContactList
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 MVIMPSTStorageContact& CVIMPSTStorageContactList::OnlineContact( TInt aIndex ) const
       
   446     {
       
   447     return FilteredContact( 
       
   448                 aIndex, TVIMPSTEnums::EFilterNonOffline );
       
   449     }
       
   450  
       
   451 // -----------------------------------------------------------------------------
       
   452 // CVIMPSTStorageContactList::FilteredContact
       
   453 // From MVIMPSTContactList
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 MVIMPSTStorageContact& CVIMPSTStorageContactList::FilteredContact( 
       
   457                 TInt aIndex, TVIMPSTEnums::TFilterType aFilter ) const
       
   458 	{
       
   459 	TRACER_AUTO;
       
   460     if ( aFilter == TVIMPSTEnums::EFilterAll )
       
   461 		{
       
   462 		return (*this)[aIndex];
       
   463 		}
       
   464 	else
       
   465         {      
       
   466         TInt filteredIndex( -1 );
       
   467         TInt count( iContactArray.Count() );
       
   468         for( TInt i(0); i < count; ++i )
       
   469             {
       
   470             MVIMPSTStorageContact* contact = iContactArray[i];
       
   471             if ( FilterAllowsContact( contact, aFilter ) )
       
   472                 {
       
   473                 // Contact was in correct state
       
   474                 filteredIndex++;
       
   475                 if ( aIndex == filteredIndex )
       
   476                     {
       
   477                     // index was also correct
       
   478                     return *iContactArray[i];                   
       
   479                     } 
       
   480                 }
       
   481             }
       
   482 	    __CHAT_ASSERT_DEBUG( EFalse );
       
   483         // prevent compiler warning
       
   484         return ( MVIMPSTStorageContact& )KNullDesC;
       
   485         }
       
   486 	}
       
   487 
       
   488 // -----------------------------------------------------------------------------
       
   489 // CVIMPSTStorageContactList::FilteredCount
       
   490 // From MVIMPSTContactList
       
   491 // -----------------------------------------------------------------------------
       
   492 //
       
   493 TInt CVIMPSTStorageContactList::FilteredCount( 
       
   494                             TVIMPSTEnums::TFilterType aFilter ) const
       
   495 	{
       
   496 	TRACER_AUTO;
       
   497     if ( aFilter == TVIMPSTEnums::EFilterAll )
       
   498 		{
       
   499 		return Count();
       
   500 		}
       
   501 	TInt filtered( 0 );
       
   502 	TInt count( iContactArray.Count() );
       
   503 	for( TInt i( 0 ); i<count; ++i )
       
   504 		{
       
   505 		if ( FilterAllowsContact( iContactArray[i], aFilter ) )
       
   506 			{
       
   507 			filtered++;                
       
   508 			}
       
   509 		}
       
   510 	return filtered;
       
   511   	}
       
   512 
       
   513 // -----------------------------------------------------------------------------
       
   514 // CVIMPSTStorageContactList::FilterAllowsContact
       
   515 // -----------------------------------------------------------------------------
       
   516 //
       
   517 TBool CVIMPSTStorageContactList::FilterAllowsContact( const MVIMPSTStorageContact* aContact,
       
   518                              TVIMPSTEnums::TFilterType aFilter ) const
       
   519     {
       
   520 	TRACER_AUTO;
       
   521     TBool showContact( EFalse );
       
   522     TInt myStatus( KErrNone );          
       
   523     TVIMPSTEnums::TOnlineStatus status(
       
   524                             aContact->OnlineStatus() );                                          
       
   525 
       
   526     if( aFilter & TVIMPSTEnums::EFilterAndOperation )
       
   527         {                
       
   528         myStatus = myStatus | TVIMPSTEnums::EFilterAndOperation;
       
   529         }
       
   530      
       
   531     if ( status == TVIMPSTEnums::EOnline )
       
   532         {
       
   533         myStatus = myStatus | TVIMPSTEnums::EFilterOnline;
       
   534         }
       
   535 
       
   536     if ( status == TVIMPSTEnums::EOnline || 
       
   537          status == TVIMPSTEnums::EAway ||
       
   538          status == TVIMPSTEnums::EBusy ||
       
   539          status == TVIMPSTEnums::EDoNotDisturb)
       
   540         {
       
   541         myStatus = myStatus | TVIMPSTEnums::EFilterNonOffline;
       
   542         }
       
   543 
       
   544     if ( status == TVIMPSTEnums::EAway)
       
   545         {
       
   546         myStatus |= TVIMPSTEnums::EFilterAway;
       
   547         }
       
   548     
       
   549     if( aFilter & TVIMPSTEnums::EFilterAndOperation )
       
   550         {
       
   551         if( ( myStatus & aFilter ) == aFilter )
       
   552             {
       
   553             showContact = ETrue;
       
   554             }
       
   555         }
       
   556     else
       
   557         {
       
   558         if( myStatus & aFilter )
       
   559             {
       
   560             showContact = ETrue;
       
   561             }
       
   562         } 
       
   563        
       
   564     return showContact;   
       
   565     }
       
   566 
       
   567 // -----------------------------------------------------------------------------
       
   568 // CVIMPSTStorageContactList::FindContact
       
   569 // -----------------------------------------------------------------------------
       
   570 //
       
   571 MVIMPSTStorageContact* CVIMPSTStorageContactList::FindContact( const TDesC& aContactId )
       
   572     {
       
   573 	TRACER_AUTO;
       
   574     TInt orderedIndex(0);
       
   575     TInt contactIndex = FindContactIndex( aContactId, orderedIndex );
       
   576     return ( contactIndex >= 0 ? iContactArray[ contactIndex ] : NULL );
       
   577     }
       
   578 // -----------------------------------------------------------------------------
       
   579 // CVIMPSTStorageContactList::FindContactByContactLinkL
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 MVIMPSTStorageContact* CVIMPSTStorageContactList::FindContactByContactLink( const MVPbkContactLink& aContactLink )
       
   583     {
       
   584 	TRACER_AUTO;
       
   585     TInt orderedIndex(0);
       
   586     TInt contactIndex = -1;
       
   587     TRAP_IGNORE( contactIndex = FindContactByLinkL( aContactLink, orderedIndex );)
       
   588     return ( contactIndex >= 0 ? iContactArray[ contactIndex ] : NULL );
       
   589     }
       
   590     
       
   591 // -----------------------------------------------------------------------------
       
   592 // CVIMPSTStorageContactList::FindContactByLinkL
       
   593 // -----------------------------------------------------------------------------
       
   594 //
       
   595 TInt CVIMPSTStorageContactList::FindContactByLinkL( const MVPbkContactLink& aContactLink,
       
   596                                           TInt& aIndexOrderedArray ) const
       
   597     {
       
   598 	TRACER_AUTO;
       
   599     TInt count( iOrderedContacts.Count() );
       
   600     TInt contactIndex = KErrNotFound;
       
   601      //Does a Linear Search
       
   602     for (TInt index = 0; index<count; index++)
       
   603 		{
       
   604 		MVPbkContactLink* contactLink = iOrderedContacts[ index ]->ContactLink();
       
   605 		if( contactLink && contactLink->IsSame( aContactLink ) )
       
   606 			{
       
   607 			aIndexOrderedArray = index;
       
   608 		    contactIndex =  FindContactEntry( iOrderedContacts[ index ] );
       
   609 		    break;	
       
   610 			}
       
   611 		} 
       
   612     return contactIndex;
       
   613     }        
       
   614     
       
   615 //  End of File