phonebookengines/VirtualPhonebook/VPbkEng/src/CVPbkPhoneNumberMatchStrategy.cpp
branchRCL_3
changeset 18 d4f567ce2e7c
parent 15 34879f5cfc63
equal deleted inserted replaced
17:2666d9724c76 18:d4f567ce2e7c
    40 #include <centralrepository.h>
    40 #include <centralrepository.h>
    41 #include <VPbkStoreUriLiterals.h>
    41 #include <VPbkStoreUriLiterals.h>
    42 
    42 
    43 #include "CVPbkPhoneNumberSequentialMatchStrategy.h"
    43 #include "CVPbkPhoneNumberSequentialMatchStrategy.h"
    44 #include "CVPbkPhoneNumberParallelMatchStrategy.h"
    44 #include "CVPbkPhoneNumberParallelMatchStrategy.h"
    45 
    45 #include "CVPbkETelCntConverter.h"
       
    46 
       
    47 #include <cntdb.h>
       
    48 #include <ecom/ecom.h>
       
    49 
       
    50 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS
       
    51 #include <cntphonenumparser.h>
       
    52 #endif
    46 // CONSTANTS
    53 // CONSTANTS
    47 // Unnamed namespace for local definitions
    54 // Unnamed namespace for local definitions
    48 namespace {
    55 namespace {
    49 // --------------------------------------------------------------------------
    56 // --------------------------------------------------------------------------
    50 // Phonebook Central Repository UIDs
    57 // Phonebook Central Repository UIDs
   159          * If there is in the results at least one contact
   166          * If there is in the results at least one contact
   160          * from currently used stores in Phonebook2 it removes from results 
   167          * from currently used stores in Phonebook2 it removes from results 
   161          * contacts from other stores
   168          * contacts from other stores
   162         */
   169         */
   163         void RefineDuplicatedNumbersL();
   170         void RefineDuplicatedNumbersL();
       
   171         
       
   172         /**
       
   173          * Load number parser plugin.
       
   174         */
       
   175         void LoadNumberParserPluginL();
   164         
   176         
   165     private: // Data
   177     private: // Data
   166         CVPbkPhoneNumberMatchStrategy& iParent;
   178         CVPbkPhoneNumberMatchStrategy& iParent;
   167         /// Ref: The contact manager instance to be used for searching.
   179         /// Ref: The contact manager instance to be used for searching.
   168         CVPbkContactManager* iContactManager;
   180         CVPbkContactManager* iContactManager;
   208         RPointerArray <HBufC> iTempNameTokensArray;
   220         RPointerArray <HBufC> iTempNameTokensArray;
   209         /// Indicates if all contact in iResult are the same
   221         /// Indicates if all contact in iResult are the same
   210         TBool iDoubledContacts;
   222         TBool iDoubledContacts;
   211         /// type of iPhoneNumber
   223         /// type of iPhoneNumber
   212         TNumberType iPhoneNumberType;
   224         TNumberType iPhoneNumberType;
       
   225         // Own: parser
       
   226         CContactPhoneNumberParser* iParser;
   213     };
   227     };
   214 
   228 
   215 CVPbkPhoneNumberMatchStrategyImpl::CVPbkPhoneNumberMatchStrategyImpl(
   229 CVPbkPhoneNumberMatchStrategyImpl::CVPbkPhoneNumberMatchStrategyImpl(
   216         CVPbkPhoneNumberMatchStrategy& aParent) :
   230         CVPbkPhoneNumberMatchStrategy& aParent) :
   217     CActive(CActive::EPriorityIdle),
   231     CActive(CActive::EPriorityIdle),
   266 	    iLastNameSelector = CVPbkFieldTypeSelector::NewL( resReader, iContactManager->FieldTypes() );
   280 	    iLastNameSelector = CVPbkFieldTypeSelector::NewL( resReader, iContactManager->FieldTypes() );
   267 	    CleanupStack::PopAndDestroy( lastNameSelectorBuf );
   281 	    CleanupStack::PopAndDestroy( lastNameSelectorBuf );
   268     	}
   282     	}
   269 
   283 
   270     CleanupStack::PopAndDestroy( &resFile );
   284     CleanupStack::PopAndDestroy( &resFile );
       
   285     
       
   286     LoadNumberParserPluginL();
   271     }
   287     }
   272 
   288 
   273 CVPbkPhoneNumberMatchStrategyImpl* CVPbkPhoneNumberMatchStrategyImpl::NewL(
   289 CVPbkPhoneNumberMatchStrategyImpl* CVPbkPhoneNumberMatchStrategyImpl::NewL(
   274         CVPbkPhoneNumberMatchStrategy& aParent,
   290         CVPbkPhoneNumberMatchStrategy& aParent,
   275         const CVPbkPhoneNumberMatchStrategy::TConfig& aConfig,
   291         const CVPbkPhoneNumberMatchStrategy::TConfig& aConfig,
   298     delete iFirstNameSelector;
   314     delete iFirstNameSelector;
   299     delete iLastNameSelector;
   315     delete iLastNameSelector;
   300     iNameTokensArray.ResetAndDestroy();
   316     iNameTokensArray.ResetAndDestroy();
   301     iTempNameTokensArray.ResetAndDestroy();
   317     iTempNameTokensArray.ResetAndDestroy();
   302     iStoresToMatch.Close();
   318     iStoresToMatch.Close();
       
   319     delete iParser;
       
   320     REComSession::FinalClose();
   303     }
   321     }
   304 
   322 
   305 void CVPbkPhoneNumberMatchStrategyImpl::MatchL(const TDesC& aPhoneNumber)
   323 void CVPbkPhoneNumberMatchStrategyImpl::MatchL(const TDesC& aPhoneNumber)
   306     {
   324     {
   307     HBufC* phoneNumber = aPhoneNumber.AllocL();
   325     HBufC* phoneNumber = aPhoneNumber.AllocL();
   760 TInt CVPbkPhoneNumberMatchStrategyImpl::FormatAndCheckNumberType( TDes& aNumber )
   778 TInt CVPbkPhoneNumberMatchStrategyImpl::FormatAndCheckNumberType( TDes& aNumber )
   761     {
   779     {
   762     _LIT( KOneZeroPattern, "0*" );
   780     _LIT( KOneZeroPattern, "0*" );
   763     _LIT( KTwoZerosPattern, "00*" );
   781     _LIT( KTwoZerosPattern, "00*" );
   764     _LIT( KPlusPattern, "+*" );
   782     _LIT( KPlusPattern, "+*" );
       
   783     _LIT( KPlusString, "+" );
   765     const TChar KPlus = TChar('+');
   784     const TChar KPlus = TChar('+');
   766     const TChar KZero = TChar('0');
   785     const TChar KZero = TChar('0');
   767     const TChar KAsterisk = TChar('*');
   786     const TChar KAsterisk = TChar('*');
   768     const TChar KHash = TChar('#');
   787     const TChar KHash = TChar('#');
   769     
   788     
   770     for( TInt pos = 0; pos < aNumber.Length(); ++pos )
   789     HBufC* numberBuf = HBufC::NewL( aNumber.Length() );
   771         {
   790     TPtr number = numberBuf->Des();
   772         TChar chr = aNumber[pos];
   791     if ( iParser )
   773         if ( !chr.IsDigit() && !( pos == 0 && chr == KPlus  )
   792         {
   774                 && !( chr == KAsterisk ) && !( chr == KHash ) )
   793         iParser->ExtractRawNumber( aNumber, number );
   775             {
   794         }
   776             aNumber.Delete( pos, 1 );
   795     TInt pos = aNumber.Find( number );
   777             --pos;
   796     
   778             }
   797     if ( pos > 0 && aNumber[pos-1] == KPlus )
   779         }
   798         {
       
   799         number.Insert( 0, KPlusString );
       
   800         }
       
   801     
       
   802     if ( number.Length() > 0)
       
   803         {
       
   804         aNumber.Copy( number );
       
   805         }
       
   806     delete numberBuf;
   780     
   807     
   781 	TInt format;
   808 	TInt format;
   782 	
   809 	
   783     if ( !aNumber.Match( KTwoZerosPattern ) && aNumber.Length() > 2 && aNumber[2] != KZero )
   810     if ( !aNumber.Match( KTwoZerosPattern ) && aNumber.Length() > 2 && aNumber[2] != KZero )
   784         {
   811         {
  1106         return ETrue;
  1133         return ETrue;
  1107         }
  1134         }
  1108     return EFalse;
  1135     return EFalse;
  1109     }
  1136     }
  1110 
  1137 
       
  1138 void CVPbkPhoneNumberMatchStrategyImpl::LoadNumberParserPluginL()
       
  1139     {    
       
  1140     RImplInfoPtrArray   implInfoArray;
       
  1141     CleanupResetAndDestroyPushL( implInfoArray );
       
  1142     REComSession::ListImplementationsL( KUidEcomCntPhoneNumberParserInterface, 
       
  1143                                         implInfoArray );
       
  1144     // Load the first implementation found for KUidEcomCntPhoneNumberParserInterface 
       
  1145     const TInt count = implInfoArray.Count();
       
  1146     __ASSERT_ALWAYS( count > 0, User::Leave( KErrNotFound ) );
       
  1147     const TUid firstImplementationFound = implInfoArray[0]->ImplementationUid();
       
  1148     iParser = reinterpret_cast<CContactPhoneNumberParser*> 
       
  1149         ( CContactEcomPhoneNumberParser::NewL( firstImplementationFound ) );
       
  1150     CleanupStack::PopAndDestroy( &implInfoArray );
       
  1151     }
       
  1152 
  1111 CVPbkPhoneNumberMatchStrategy::CVPbkPhoneNumberMatchStrategy()
  1153 CVPbkPhoneNumberMatchStrategy::CVPbkPhoneNumberMatchStrategy()
  1112     {
  1154     {
  1113     }
  1155     }
  1114 
  1156 
  1115 EXPORT_C CVPbkPhoneNumberMatchStrategy* CVPbkPhoneNumberMatchStrategy::NewL(
  1157 EXPORT_C CVPbkPhoneNumberMatchStrategy* CVPbkPhoneNumberMatchStrategy::NewL(