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