phoneengine/PhoneCntFinder/ContactService/src/cphcntfoundcontacts.cpp
changeset 0 5f000ab63145
equal deleted inserted replaced
-1:000000000000 0:5f000ab63145
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Stores found contacts and keeps track of the references.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <MVPbkContactLink.h>
       
    20 
       
    21 #include "cphcntfoundcontacts.h"
       
    22 #include "CPhCntContact.h"
       
    23 #include <talogger.h>
       
    24 
       
    25 
       
    26 // ======== MEMBER FUNCTIONS ========
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 // Constructor
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 CPhCntFoundContacts::CPhCntFoundContacts() 
       
    33     {
       
    34     }
       
    35 
       
    36 // ---------------------------------------------------------------------------
       
    37 // Secondphase constructor.
       
    38 // ---------------------------------------------------------------------------
       
    39 //
       
    40 void CPhCntFoundContacts::ConstructL()
       
    41     {
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // Static constructor
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CPhCntFoundContacts* CPhCntFoundContacts::NewL()
       
    50     {
       
    51     CPhCntFoundContacts* self = CPhCntFoundContacts::NewLC();
       
    52     CleanupStack::Pop( self );
       
    53     return self;
       
    54     }
       
    55 
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // Static constructor
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CPhCntFoundContacts* CPhCntFoundContacts::NewLC()
       
    62     {
       
    63     CPhCntFoundContacts* self = new( ELeave ) CPhCntFoundContacts;
       
    64     CleanupStack::PushL( self );
       
    65     self->ConstructL();
       
    66     return self;
       
    67     }
       
    68 
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // Destructor
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CPhCntFoundContacts::~CPhCntFoundContacts()
       
    75     {
       
    76     iFoundContacts.ResetAndDestroy();
       
    77     }
       
    78 
       
    79 // ---------------------------------------------------------------------------
       
    80 // Adds contact-
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 void CPhCntFoundContacts::AddL( 
       
    84     CPhCntContact* aContact,
       
    85     const TDesC& aMatchingNumber )
       
    86     {
       
    87     aContact->SetOriginalNumberL( aMatchingNumber );
       
    88     iFoundContacts.AppendL( aContact );
       
    89     aContact->SetOwner( this );
       
    90     // There is already reference to aContact, because it is added.
       
    91     aContact->IncreaseReferenceCount();
       
    92     }
       
    93     
       
    94 // ---------------------------------------------------------------------------
       
    95 // Removes contact from array and deletes the contact.
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CPhCntFoundContacts::Remove( CPhCntContact* aContact )
       
    99     {
       
   100     const TInt errorOrIndex( iFoundContacts.Find( aContact ) );
       
   101     if( errorOrIndex >= 0 ) 
       
   102         {
       
   103         iFoundContacts.Remove( errorOrIndex );
       
   104         }
       
   105     delete aContact;
       
   106     }
       
   107     
       
   108 // ---------------------------------------------------------------------------
       
   109 // Finds contact, which number is same as aTelNumber
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 CPhCntContact* CPhCntFoundContacts::FindContact( const TDesC& aTelNumber )
       
   113     {
       
   114     TEFLOGSTRING( KTAOBJECT, "CNT CPhCntFoundContacts::FindContact" );
       
   115     const TInt foundContactCount( iFoundContacts.Count() );
       
   116     CPhCntContact* foundContact = NULL;
       
   117     for( TInt i = 0; i < foundContactCount && !foundContact; i++ )
       
   118         {
       
   119         CPhCntContact* contact = iFoundContacts[i];
       
   120         if( aTelNumber.Compare( contact->OriginalNumber() ) == KErrNone )
       
   121             {
       
   122             foundContact = contact;
       
   123             foundContact->IncreaseReferenceCount();
       
   124             }
       
   125         }
       
   126     return foundContact;
       
   127     }
       
   128     
       
   129 // ---------------------------------------------------------------------------
       
   130 // Finds contact, which number and contact link are same.
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 CPhCntContact* CPhCntFoundContacts::FindContact( 
       
   134     const TDesC& aTelNumber,
       
   135     const MVPbkContactLink& aContactLink )
       
   136     {
       
   137     CPhCntContact* foundContact = FindContact( aContactLink );
       
   138     if( foundContact )
       
   139         {
       
   140         if( aTelNumber.Compare( foundContact->OriginalNumber() ) != KErrNone )
       
   141             {
       
   142             // contact did not match with the number, so release.
       
   143             foundContact->Release();
       
   144             foundContact = NULL;
       
   145             }
       
   146         }
       
   147     return foundContact;
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // Finds contact, which contact link matches with aContactLink
       
   152 // ---------------------------------------------------------------------------
       
   153 //    
       
   154 CPhCntContact* CPhCntFoundContacts::FindContact(
       
   155     const MVPbkContactLink& aContactLink )
       
   156     {
       
   157     const TInt foundContactCount( iFoundContacts.Count() );
       
   158     CPhCntContact* foundContact = NULL;
       
   159     for( TInt i = 0; i < foundContactCount && !foundContact; i++ )
       
   160         {
       
   161         CPhCntContact* contact = iFoundContacts[i];
       
   162         if( aContactLink.IsSame( *contact->ContactLink() ) )
       
   163             {
       
   164             foundContact = contact;
       
   165             foundContact->IncreaseReferenceCount();
       
   166             }
       
   167         }
       
   168     return foundContact;
       
   169     }
       
   170 
       
   171     
       
   172 
       
   173