phoneengine/PhoneCntFinder/ContactService/src/tphcntcontactselectionstrategy.cpp
branchRCL_3
changeset 81 c26cc2a7c548
parent 73 e30d4a1b8bad
child 82 b49b5af297a7
equal deleted inserted replaced
73:e30d4a1b8bad 81:c26cc2a7c548
     1 /*
       
     2 * Copyright (c)  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:  Implementation of TPhCntContactSelectionStrategy class.
       
    15 *
       
    16 */
       
    17 
       
    18 #include <MVPbkContactLinkArray.h>
       
    19 #include <CVPbkContactStoreUriArray.h>
       
    20 #include <MVPbkContactLink.h>
       
    21 #include <MVPbkContactStore.h>
       
    22 #include <MVPbkContactStoreProperties.h>
       
    23 
       
    24 #include "tphcntcontactselectionstrategy.h"
       
    25 
       
    26 const TInt KFirstContactInList = 0;
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // 
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 TPhCntContactSelectionStrategy::TPhCntContactSelectionStrategy( )
       
    35     {
       
    36     iSeveralMatchesAllowed = TPhCntContactSelectionStrategy::EAllowSingleMatch;
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // 
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 void TPhCntContactSelectionStrategy::SetContactSelectionStrategy( 
       
    44         TAllowSeveralMatches aSeveralMatchesAllowed )
       
    45     {
       
    46     iSeveralMatchesAllowed = aSeveralMatchesAllowed;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // 
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 TInt TPhCntContactSelectionStrategy::ApplyStrategy( 
       
    54     const MVPbkContactLinkArray& aContactLinkArray )
       
    55     {
       
    56     iContactLinkArray = &aContactLinkArray;
       
    57         
       
    58     if ( iSeveralMatchesAllowed == TPhCntContactSelectionStrategy::EAllowSingleMatch )
       
    59         {
       
    60         return ApplySingleMatchStrategy( );
       
    61         }
       
    62     else
       
    63         {
       
    64         return ApplySeveralMatchesStrategy( );
       
    65         }    
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // 
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 TInt TPhCntContactSelectionStrategy::ApplyAdditonalStoreStrategy( 
       
    73     const MVPbkContactLinkArray& aContactLinkArray,
       
    74     const CVPbkContactStoreUriArray& aAdditionalStoreUriArray )
       
    75     {
       
    76     iContactLinkArray = &aContactLinkArray;    
       
    77     
       
    78     TInt ret( KNoContact );
       
    79     TInt contactsFoundFromAdditionalStore(0); 
       
    80     
       
    81     for ( TInt i = 0; i < aContactLinkArray.Count(); i++ )
       
    82         {
       
    83         TVPbkContactStoreUriPtr uri = GetContactStoreUri( i );
       
    84     
       
    85         if ( aAdditionalStoreUriArray.IsIncluded( uri ) )
       
    86             {
       
    87             contactsFoundFromAdditionalStore++;
       
    88             ret = i;
       
    89             }            
       
    90         }
       
    91     
       
    92     if ( contactsFoundFromAdditionalStore > 1 )
       
    93         {
       
    94         // Multiple matches from additional stores -> no match.
       
    95         ret = KManyContacts;
       
    96         }
       
    97             
       
    98     return ret;    
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // 
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 TVPbkContactStoreUriPtr TPhCntContactSelectionStrategy::GetContactStoreUri( 
       
   106         TInt aContactLinkArrayIndex )
       
   107     {
       
   108     return iContactLinkArray->At( aContactLinkArrayIndex ).ContactStore().StoreProperties().Uri();
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // 
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 TInt TPhCntContactSelectionStrategy::ApplySingleMatchStrategy( )
       
   116     {
       
   117     if ( iContactLinkArray->Count() == 1 )
       
   118         {        
       
   119         return KFirstContactInList;
       
   120         }
       
   121     else
       
   122         {
       
   123         return KNoContact;
       
   124         }
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // 
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 TInt TPhCntContactSelectionStrategy::ApplySeveralMatchesStrategy( )
       
   132     {
       
   133     if ( iContactLinkArray->Count() >= 1 )
       
   134         {
       
   135         return KFirstContactInList;
       
   136         }
       
   137     else
       
   138         {
       
   139         return KNoContact;
       
   140         }
       
   141     }