phonebookengines/VirtualPhonebook/VPbkEng/src/CVPbkPhoneNumberMatchStrategy.cpp
branchRCL_3
changeset 85 38bb213f60ba
parent 68 9da50d567e3c
equal deleted inserted replaced
74:6b5524b4f673 85:38bb213f60ba
    28 #include <MVPbkContactLink.h>
    28 #include <MVPbkContactLink.h>
    29 #include <MVPbkStoreContact.h>
    29 #include <MVPbkStoreContact.h>
    30 #include <MVPbkSingleContactOperationObserver.h>
    30 #include <MVPbkSingleContactOperationObserver.h>
    31 #include <RLocalizedResourceFile.h>
    31 #include <RLocalizedResourceFile.h>
    32 #include <VPbkDataCaging.hrh>
    32 #include <VPbkDataCaging.hrh>
    33 #include <vpbkeng.rsg>
    33 #include <VPbkEng.rsg>
    34 #include <vpbkfieldtypeselectors.rsg>
    34 #include <VPbkFieldTypeSelectors.rsg>
    35 #include <CVPbkFieldTypeSelector.h>
    35 #include <CVPbkFieldTypeSelector.h>
    36 #include <CVPbkFieldFilter.h>
    36 #include <CVPbkFieldFilter.h>
    37 #include <barsread.h>
    37 #include <barsread.h>
    38 #include <MVPbkContactFieldTextData.h>
    38 #include <MVPbkContactFieldTextData.h>
    39 #include <CVPbkContactStoreUriArray.h>
    39 #include <CVPbkContactStoreUriArray.h>
    78                 CVPbkContactManager& aContactManager,
    78                 CVPbkContactManager& aContactManager,
    79                 MVPbkContactFindObserver& aObserver);
    79                 MVPbkContactFindObserver& aObserver);
    80         ~CVPbkPhoneNumberMatchStrategyImpl();
    80         ~CVPbkPhoneNumberMatchStrategyImpl();
    81 
    81 
    82     public: // Interface
    82     public: // Interface
       
    83         CContactPhoneNumberParser* GetParser();
    83         void MatchL(const TDesC& aPhoneNumber);
    84         void MatchL(const TDesC& aPhoneNumber);
    84         TInt MaxMatchDigits() const;
    85         TInt MaxMatchDigits() const;
    85         TArray<MVPbkContactStore*> StoresToMatch() const;
    86         TArray<MVPbkContactStore*> StoresToMatch() const;
    86         TBool IsSimStore( const MVPbkContactStore& aStore );
    87         TBool IsSimStore( const MVPbkContactStore& aStore );
    87         
    88         
   770         {
   771         {
   771         return KNullDesC();
   772         return KNullDesC();
   772         }
   773         }
   773     }
   774     }
   774 
   775 
       
   776 CContactPhoneNumberParser* CVPbkPhoneNumberMatchStrategyImpl::GetParser()
       
   777     {
       
   778     return iParser;
       
   779     }
       
   780 
   775 // Removes non-digit chars except plus form the beginning
   781 // Removes non-digit chars except plus form the beginning
   776 // Checks if number matches to one of defined types
   782 // Checks if number matches to one of defined types
   777 //
   783 //
   778 TInt CVPbkPhoneNumberMatchStrategyImpl::FormatAndCheckNumberType( TDes& aNumber )
   784 TInt CVPbkPhoneNumberMatchStrategyImpl::FormatAndCheckNumberType( TDes& aNumber )
   779     {
   785     {
   784     const TChar KPlus = TChar('+');
   790     const TChar KPlus = TChar('+');
   785     const TChar KZero = TChar('0');
   791     const TChar KZero = TChar('0');
   786     const TChar KAsterisk = TChar('*');
   792     const TChar KAsterisk = TChar('*');
   787     const TChar KHash = TChar('#');
   793     const TChar KHash = TChar('#');
   788     
   794     
   789     HBufC* numberBuf = HBufC::NewL( aNumber.Length() );
   795     TInt format;
       
   796     
       
   797     HBufC* numberBuf = NULL;
       
   798     TRAPD(err, numberBuf = HBufC::NewL( aNumber.Length() ) );
       
   799     // Error was found when Phone allocated memory for numberBuf
       
   800     if( err != KErrNone )
       
   801         {
       
   802         return ( format = EUnknown );
       
   803         }
   790     TPtr number = numberBuf->Des();
   804     TPtr number = numberBuf->Des();
   791     if ( iParser )
   805     if ( GetParser() )
   792         {
   806         {
   793         iParser->ExtractRawNumber( aNumber, number );
   807         GetParser()->ExtractRawNumber( aNumber, number );
   794         }
   808         }
   795     TInt pos = aNumber.Find( number );
   809     TInt pos = aNumber.Find( number );
   796     
   810     
   797     if ( pos > 0 && aNumber[pos-1] == KPlus )
   811     if ( pos > 0 && aNumber[pos-1] == KPlus )
   798         {
   812         {
   802     if ( number.Length() > 0)
   816     if ( number.Length() > 0)
   803         {
   817         {
   804         aNumber.Copy( number );
   818         aNumber.Copy( number );
   805         }
   819         }
   806     delete numberBuf;
   820     delete numberBuf;
   807     
       
   808 	TInt format;
       
   809 	
   821 	
   810     if ( !aNumber.Match( KTwoZerosPattern ) && aNumber.Length() > 2 && aNumber[2] != KZero )
   822     if ( !aNumber.Match( KTwoZerosPattern ) && aNumber.Length() > 2 && aNumber[2] != KZero )
   811         {
   823         {
   812         format = ETwoZeros;
   824         format = ETwoZeros;
   813         }
   825         }
  1157 EXPORT_C CVPbkPhoneNumberMatchStrategy* CVPbkPhoneNumberMatchStrategy::NewL(
  1169 EXPORT_C CVPbkPhoneNumberMatchStrategy* CVPbkPhoneNumberMatchStrategy::NewL(
  1158         const TConfig& aConfig,
  1170         const TConfig& aConfig,
  1159         CVPbkContactManager& aContactManager,
  1171         CVPbkContactManager& aContactManager,
  1160         MVPbkContactFindObserver& aObserver)
  1172         MVPbkContactFindObserver& aObserver)
  1161     {
  1173     {
  1162     if (aConfig.iMatchMode == EVPbkSequentialMatch)
  1174     // We do not support yet CVPbkPhoneNumberMatchStrategy::EVPbkBestMatchingFlag flag
  1163         {
  1175     // Skip it from the configuration
  1164         return CVPbkPhoneNumberSequentialMatchStrategy::NewL(aConfig, aContactManager, aObserver);
  1176     TConfig config = aConfig;
       
  1177     config.iMatchFlags &= ~CVPbkPhoneNumberMatchStrategy::EVPbkBestMatchingFlag;
       
  1178 
       
  1179     if (config.iMatchMode == EVPbkSequentialMatch)
       
  1180         {
       
  1181         return CVPbkPhoneNumberSequentialMatchStrategy::NewL(config, aContactManager, aObserver);
  1165         }
  1182         }
  1166     else
  1183     else
  1167         {
  1184         {
  1168         return CVPbkPhoneNumberParallelMatchStrategy::NewL(aConfig, aContactManager, aObserver);
  1185         return CVPbkPhoneNumberParallelMatchStrategy::NewL(config, aContactManager, aObserver);
  1169         }
  1186         }
  1170    }
  1187    }
  1171 
  1188 
  1172 CVPbkPhoneNumberMatchStrategy::~CVPbkPhoneNumberMatchStrategy()
  1189 CVPbkPhoneNumberMatchStrategy::~CVPbkPhoneNumberMatchStrategy()
  1173     {
  1190     {
  1176 
  1193 
  1177 EXPORT_C void CVPbkPhoneNumberMatchStrategy::MatchL(const TDesC& aPhoneNumber)
  1194 EXPORT_C void CVPbkPhoneNumberMatchStrategy::MatchL(const TDesC& aPhoneNumber)
  1178     {
  1195     {
  1179     InitMatchingL();
  1196     InitMatchingL();
  1180 
  1197 
  1181     iImpl->MatchL(aPhoneNumber);
  1198     // The client might be using CVPbkPhoneNumberMatchStrategy::EVPbkBestMatchingFlag
       
  1199     // flag, therefore the special chars could not be stripped off from the number
       
  1200     // The flag is not supported yet, therefore we need to strip off the special chars
       
  1201     HBufC* numberBuf = HBufC::NewL( aPhoneNumber.Length() );
       
  1202     CleanupStack::PushL( numberBuf );
       
  1203     TPtr number = numberBuf->Des();
       
  1204     if ( iImpl->GetParser() )
       
  1205         {
       
  1206         iImpl->GetParser()->ExtractRawNumber( aPhoneNumber, number );
       
  1207         }
       
  1208     else
       
  1209         {
       
  1210         number.Copy( aPhoneNumber );
       
  1211         }
       
  1212 
       
  1213     iImpl->MatchL(number);
       
  1214 
       
  1215     CleanupStack::PopAndDestroy(); // numberBuf
  1182     }
  1216     }
  1183 
  1217 
  1184 void CVPbkPhoneNumberMatchStrategy::BaseConstructL(
  1218 void CVPbkPhoneNumberMatchStrategy::BaseConstructL(
  1185         const TConfig& aConfig,
  1219         const TConfig& aConfig,
  1186         CVPbkContactManager& aContactManager,
  1220         CVPbkContactManager& aContactManager,