phoneengine/PhoneCntFinder/ContactService/src/cphcntcontactmatchstrategy.cpp
branchRCL_3
changeset 23 40a3f856b14d
parent 14 b8d67d6176f5
equal deleted inserted replaced
22:94dc1107e8b2 23:40a3f856b14d
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 #include <CVPbkContactManager.h>
    19 #include <CVPbkContactManager.h>
    20 #include <centralrepository.h>
       
    21 #include <telconfigcrkeys.h>
       
    22 #include <CVPbkContactStoreUriArray.h>
    20 #include <CVPbkContactStoreUriArray.h>
    23 #include <cntdb.h>  // KBestMatchingPhoneNumbers
    21 #include <cntdb.h>  // KBestMatchingPhoneNumbers
    24 
    22 
    25 #include "cphcntcontactmatchstrategy.h"
    23 #include "cphcntcontactmatchstrategy.h"
    26 #include "cphcntcontactstoreuris.h"
    24 #include "cphcntcontactstoreuris.h"
    27 #include "CPhoneRawMatchNumberExtractor.h"
    25 #include "CPhoneRawMatchNumberExtractor.h"
    28 
    26 
    29 
    27 
    30 // Digit count used to match CS number.
    28 
    31 const TInt KPhCntMatchMin = 7;
       
    32 const TInt KPhCntMatchMax = 11;
       
    33 const TInt KPhCntMatchDefault = KPhCntMatchMin;
       
    34 
    29 
    35 // ======== MEMBER FUNCTIONS ========
    30 // ======== MEMBER FUNCTIONS ========
    36 
    31 
    37 
    32 
    38 CPhCntContactMatchStrategy::CPhCntContactMatchStrategy(
    33 CPhCntContactMatchStrategy::CPhCntContactMatchStrategy(
    53 // Second phase constructor
    48 // Second phase constructor
    54 // ---------------------------------------------------------------------------
    49 // ---------------------------------------------------------------------------
    55 //
    50 //
    56 void CPhCntContactMatchStrategy::ConstructL()
    51 void CPhCntContactMatchStrategy::ConstructL()
    57     {
    52     {
    58     iCenRepSession = CRepository::NewL( KCRUidTelConfiguration );
       
    59     iCenRepNotifyHandler = 
       
    60         CCenRepNotifyHandler::NewL(
       
    61             *this, 
       
    62             *iCenRepSession, 
       
    63             CCenRepNotifyHandler::EIntKey,
       
    64             KTelMatchDigits );
       
    65             
       
    66     iCenRepNotifyHandler->StartListeningL();
       
    67     
       
    68     iNumberOfDigits = KPhCntMatchDefault;
       
    69     TInt sdMatchValue = KErrNotFound;
       
    70 
       
    71     // Find digit count to be used with matching.
       
    72     if ( iCenRepSession->Get( KTelMatchDigits, sdMatchValue )
       
    73          == KErrNone )
       
    74         {
       
    75         // If we can find a proper value from the cenrep, use it.
       
    76         if ( sdMatchValue >= KPhCntMatchMin && sdMatchValue <= KPhCntMatchMax )
       
    77             {
       
    78             iNumberOfDigits = sdMatchValue;
       
    79             }
       
    80         }
       
    81     User::LeaveIfError( CreateContactMatchStrategy() );
    53     User::LeaveIfError( CreateContactMatchStrategy() );
    82     
    54     
    83     iNumberExtractor = new( ELeave )CCntRawPhoneNumberExtractor();
    55     iNumberExtractor = new( ELeave )CCntRawPhoneNumberExtractor();
    84     iNumberExtractor->ConstructL();
    56     iNumberExtractor->ConstructL();
    85     }
    57     }
   115     {
    87     {
   116     if( iNumberExtractor )
    88     if( iNumberExtractor )
   117         {
    89         {
   118         iNumberExtractor->Release();    
    90         iNumberExtractor->Release();    
   119         }
    91         }
   120     
       
   121     if( iCenRepNotifyHandler )
       
   122         {
       
   123         iCenRepNotifyHandler->StopListening();    
       
   124         }
       
   125     delete iCenRepNotifyHandler;
       
   126     delete iCenRepSession;
       
   127     delete iMatchStrategy;
    92     delete iMatchStrategy;
   128     delete iUriArray;
    93     delete iUriArray;
   129     }
    94     }
   130 
    95 
   131 // ---------------------------------------------------------------------------
    96 // ---------------------------------------------------------------------------
   135 //
   100 //
   136 void CPhCntContactMatchStrategy::FindMatchesL( const TDesC& aPhoneNumber )
   101 void CPhCntContactMatchStrategy::FindMatchesL( const TDesC& aPhoneNumber )
   137     {
   102     {
   138     if( iMatchStrategy )
   103     if( iMatchStrategy )
   139         {
   104         {
   140         MatchL( aPhoneNumber );
   105         DoMatchL( aPhoneNumber );
   141         }
   106         }
   142     else
   107     else
   143         {
   108         {
   144         const TInt err( CreateContactMatchStrategy() );
   109         const TInt err( CreateContactMatchStrategy() );
   145         if( !err )
   110         if( !err )
   146             {
   111             {
   147             MatchL( aPhoneNumber );
   112             DoMatchL( aPhoneNumber );
   148             }
   113             }
   149         else
   114         else
   150             {
   115             {
   151             User::Leave( KErrNotFound );            
   116             User::Leave( KErrNotFound );            
   152             }
   117             }
   179     
   144     
   180     return err;                
   145     return err;                
   181     }
   146     }
   182 
   147 
   183 // ---------------------------------------------------------------------------
   148 // ---------------------------------------------------------------------------
   184 // From base class MCenRepNotifyHandlerCallback
       
   185 // Notification from CenRep
       
   186 // ---------------------------------------------------------------------------
       
   187 //  
       
   188 void CPhCntContactMatchStrategy::HandleNotifyString( 
       
   189     TUint32 aUid, 
       
   190     const TDesC16& aValue )
       
   191     {
       
   192     if ( aUid == KTelMatchDigits )
       
   193         {
       
   194         TLex lexer( aValue );
       
   195         TInt value;
       
   196         const TInt err( lexer.Val( value ) );
       
   197         
       
   198         if( !err ) 
       
   199             {
       
   200             if ( value < KPhCntMatchMin || value > KPhCntMatchMax )
       
   201                 {
       
   202                 iNumberOfDigits = KPhCntMatchDefault;
       
   203                 }
       
   204             else
       
   205                 {
       
   206                 iNumberOfDigits = value;
       
   207                 }
       
   208             CreateContactMatchStrategy();
       
   209             }
       
   210      
       
   211         }
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // From base class MPhCntContactStoreEventObserver
   149 // From base class MPhCntContactStoreEventObserver
   216 // Updates match strategy.
   150 // Updates match strategy.
   217 // ---------------------------------------------------------------------------
   151 // ---------------------------------------------------------------------------
   218 //
   152 //
   219 void CPhCntContactMatchStrategy::ContactStoreAvailabilityChanged()
   153 void CPhCntContactMatchStrategy::ContactStoreAvailabilityChanged()
   220     {
   154     {
   221     delete iUriArray;
   155     delete iUriArray;
   222     iUriArray = NULL;
   156     iUriArray = NULL;
   223     CreateContactMatchStrategy();
   157     CreateContactMatchStrategy();
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // Removes extra characters from number and matches with raw number.
       
   228 // ---------------------------------------------------------------------------
       
   229 //         
       
   230 void CPhCntContactMatchStrategy::MatchL( 
       
   231     const TDesC& aPhoneNumber )
       
   232     {
       
   233     HBufC* rawNumber = HBufC::NewLC( aPhoneNumber.Length() );
       
   234     TPtr rawNumberPtr = rawNumber->Des();
       
   235     iNumberExtractor->ExtractRawNumber( aPhoneNumber, rawNumberPtr );
       
   236     DoMatchL( *rawNumber );
       
   237     CleanupStack::PopAndDestroy( rawNumber );
       
   238     }
   158     }
   239 
   159 
   240 // ---------------------------------------------------------------------------
   160 // ---------------------------------------------------------------------------
   241 // Creates contact match strategy
   161 // Creates contact match strategy
   242 // ---------------------------------------------------------------------------
   162 // ---------------------------------------------------------------------------