|         |      1 /* | 
|         |      2 * Copyright (c) 2002 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:   | 
|         |     15 *     Phonenumber matching wrapper for contact model MatchPhoneNumberL | 
|         |     16 * | 
|         |     17 */ | 
|         |     18  | 
|         |     19  | 
|         |     20  | 
|         |     21 // INCLUDE FILES | 
|         |     22 #include <e32base.h> | 
|         |     23 #include <CPbkContactEngine.h> | 
|         |     24 #include <CPbkContactItem.h> | 
|         |     25 #include <CPbkFieldsInfo.h> | 
|         |     26 #include <commonphoneparser.h>          // Common phone number validity checker | 
|         |     27  | 
|         |     28  | 
|         |     29 #include <contactmatcher.h> | 
|         |     30 #include <CVPbkContactStoreUriArray.h> | 
|         |     31 #include <MVPbkContactLink.h> | 
|         |     32 #include <CVPbkContactLinkArray.h> | 
|         |     33 #include <MVPbkFieldType.h> | 
|         |     34 #include <TVPbkFieldVersitProperty.h> | 
|         |     35 #include <MVPbkStoreContact.h> | 
|         |     36 #include <CVPbkPhoneNumberMatchStrategy.h> | 
|         |     37 #include <VPbkContactStoreUris.h> | 
|         |     38 #include <TVPbkContactStoreUriPtr.h> | 
|         |     39  | 
|         |     40 #include <centralrepository.h> | 
|         |     41 #include <telconfigcrkeys.h>        // KCRUidTelephonyConfiguration | 
|         |     42 #include <commonphoneparser.h>      // Common phone number validity checker | 
|         |     43  | 
|         |     44  | 
|         |     45  | 
|         |     46 #include "CPhoneNumberMatcher.h" | 
|         |     47  | 
|         |     48 // CONSTANTS | 
|         |     49 const TInt KPhoneNumberDigitsMatch = 7; // max amount of digits in matching | 
|         |     50  | 
|         |     51 // ================= MEMBER FUNCTIONS ======================= | 
|         |     52  | 
|         |     53  | 
|         |     54 CPhoneNumberMatcher::CPhoneNumberMatcher() | 
|         |     55                      | 
|         |     56     { | 
|         |     57     } | 
|         |     58  | 
|         |     59  | 
|         |     60 EXPORT_C CPhoneNumberMatcher* CPhoneNumberMatcher::NewL( | 
|         |     61     RFs& aFsSession ) | 
|         |     62                                          | 
|         |     63     { | 
|         |     64     CPhoneNumberMatcher* self = new ( ELeave ) CPhoneNumberMatcher(); | 
|         |     65     CleanupStack::PushL( self ); | 
|         |     66     self->ConstructL( aFsSession ); | 
|         |     67     CleanupStack::Pop(); | 
|         |     68     return self; | 
|         |     69     } | 
|         |     70  | 
|         |     71 void CPhoneNumberMatcher::ConstructL( | 
|         |     72     RFs& aFsSession ) | 
|         |     73     { | 
|         |     74     // Create contact matcher and open stores | 
|         |     75     iContactMatcher = CContactMatcher::NewL( &aFsSession ); | 
|         |     76  | 
|         |     77     iMatchDigitCount = KPhoneNumberDigitsMatch;  | 
|         |     78  | 
|         |     79     // Read the amount of digits to be used in contact matching | 
|         |     80     // The key is owned by PhoneApp | 
|         |     81     CRepository* repository = CRepository::NewLC(KCRUidTelConfiguration); | 
|         |     82     if ( repository->Get(KTelMatchDigits, iMatchDigitCount) == KErrNone ) | 
|         |     83     { | 
|         |     84         // Min is 7 | 
|         |     85         iMatchDigitCount = | 
|         |     86             Max(iMatchDigitCount, KPhoneNumberDigitsMatch ); | 
|         |     87         } | 
|         |     88     CleanupStack::PopAndDestroy(); // repository | 
|         |     89     } | 
|         |     90  | 
|         |     91  | 
|         |     92 EXPORT_C CPhoneNumberMatcher::~CPhoneNumberMatcher() | 
|         |     93     { | 
|         |     94     delete iContactMatcher; | 
|         |     95     delete iName; | 
|         |     96     } | 
|         |     97  | 
|         |     98  | 
|         |     99 EXPORT_C TPtrC CPhoneNumberMatcher::GetUniqueName() | 
|         |    100     { | 
|         |    101     if( iName ) | 
|         |    102         { | 
|         |    103         return iName->Des(); | 
|         |    104         } | 
|         |    105     return KNullDesC(); | 
|         |    106     } | 
|         |    107  | 
|         |    108 EXPORT_C TInt CPhoneNumberMatcher::GetFieldId() | 
|         |    109     { | 
|         |    110     if( iName ) // if name exists then previous match was succesfull, else return KErrNone | 
|         |    111         { | 
|         |    112         return iFieldId; | 
|         |    113         } | 
|         |    114     return KErrNotFound; | 
|         |    115     } | 
|         |    116  | 
|         |    117 EXPORT_C TInt CPhoneNumberMatcher::GetContactId( TContactItemId& aContactId ) | 
|         |    118     { | 
|         |    119     if( iName ) // if name exists then previous match was succesfull, else return KErrNone | 
|         |    120         { | 
|         |    121         aContactId = iContactId; | 
|         |    122         return KErrNone; | 
|         |    123         } | 
|         |    124     return KErrNotFound; | 
|         |    125     } | 
|         |    126  | 
|         |    127  | 
|         |    128 EXPORT_C TInt CPhoneNumberMatcher::MatchCountL( const TDesC& aNumber ) | 
|         |    129     { | 
|         |    130     TInt result (KErrNone); | 
|         |    131  | 
|         |    132  | 
|         |    133     // Match contacts to the from address | 
|         |    134     CVPbkContactLinkArray* linkArray = CVPbkContactLinkArray::NewLC(); | 
|         |    135     iContactMatcher->MatchPhoneNumberL( | 
|         |    136         aNumber, | 
|         |    137         iMatchDigitCount, | 
|         |    138         CVPbkPhoneNumberMatchStrategy::EVPbkStopOnFirstMatchFlag, | 
|         |    139         *linkArray ); | 
|         |    140  | 
|         |    141     if ( linkArray->Count() > 0 ) | 
|         |    142         { | 
|         |    143  | 
|         |    144         // There should be only one match since EVPbkStopOnFirstMatchFlag was used. | 
|         |    145         // Use first match and read contact from the store. | 
|         |    146         MVPbkStoreContact* contact; | 
|         |    147         iContactMatcher->GetStoreContactL(linkArray->At(0), &contact); | 
|         |    148         contact->PushL(); | 
|         |    149          | 
|         |    150         MVPbkStoreContactFieldCollection& coll = contact->Fields(); | 
|         |    151  | 
|         |    152         iName = iContactMatcher->GetNameL( coll ); | 
|         |    153     //    iName->Copy( alias->Left( 100 ) ); | 
|         |    154     //    delete alias; | 
|         |    155     //    alias = NULL; | 
|         |    156         CleanupStack::PopAndDestroy( contact ); // contact | 
|         |    157         result = 1; | 
|         |    158         } | 
|         |    159     CleanupStack::PopAndDestroy( linkArray ); // linkArray | 
|         |    160     return result; | 
|         |    161     } | 
|         |    162      | 
|         |    163      | 
|         |    164 void CPhoneNumberMatcher::OpenDefaultMatchStoresL( TRequestStatus& aStatus ) | 
|         |    165     { | 
|         |    166     CancelOperation(); | 
|         |    167     iContactMatcher->OpenDefaultMatchStoresL( aStatus ); | 
|         |    168     } | 
|         |    169      | 
|         |    170 void CPhoneNumberMatcher::CancelOperation() | 
|         |    171     { | 
|         |    172     iContactMatcher->CancelOperation(); | 
|         |    173     } | 
|         |    174      | 
|         |    175 // End of File | 
|         |    176  |