author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 13 Oct 2010 14:15:33 +0300 | |
branch | RCL_3 |
changeset 85 | 38bb213f60ba |
parent 68 | 9da50d567e3c |
permissions | -rw-r--r-- |
63 | 1 |
/* |
2 |
* Copyright (c) 2005-2007 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: A high level class for matching phone numbers from stores. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
// INCLUDES |
|
20 |
#include <CVPbkPhoneNumberMatchStrategy.h> |
|
21 |
||
22 |
#include <CVPbkContactManager.h> |
|
23 |
#include <CVPbkContactLinkArray.h> |
|
24 |
#include <MVPbkContactOperation.h> |
|
25 |
#include <MVPbkContactStoreList.h> |
|
26 |
#include <MVPbkContactStore.h> |
|
27 |
#include <MVPbkContactStoreProperties.h> |
|
28 |
#include <MVPbkContactLink.h> |
|
29 |
#include <MVPbkStoreContact.h> |
|
30 |
#include <MVPbkSingleContactOperationObserver.h> |
|
31 |
#include <RLocalizedResourceFile.h> |
|
32 |
#include <VPbkDataCaging.hrh> |
|
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
33 |
#include <VPbkEng.rsg> |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
34 |
#include <VPbkFieldTypeSelectors.rsg> |
63 | 35 |
#include <CVPbkFieldTypeSelector.h> |
36 |
#include <CVPbkFieldFilter.h> |
|
37 |
#include <barsread.h> |
|
38 |
#include <MVPbkContactFieldTextData.h> |
|
39 |
#include <CVPbkContactStoreUriArray.h> |
|
40 |
#include <centralrepository.h> |
|
41 |
#include <VPbkStoreUriLiterals.h> |
|
42 |
||
43 |
#include "CVPbkPhoneNumberSequentialMatchStrategy.h" |
|
44 |
#include "CVPbkPhoneNumberParallelMatchStrategy.h" |
|
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 |
|
53 |
// CONSTANTS |
|
54 |
// Unnamed namespace for local definitions |
|
55 |
namespace { |
|
56 |
// -------------------------------------------------------------------------- |
|
57 |
// Phonebook Central Repository UIDs |
|
58 |
// Copied from sf\app\contacts\phonebookui\Phonebook2\inc\Phonebook2InternalCRKeys.h |
|
59 |
// -------------------------------------------------------------------------- |
|
60 |
// |
|
61 |
const TUint32 KCRUidPhonebookStoreConfiguration = 0x1020727f; |
|
62 |
const TUint32 KPhonebookCurrentConfigurationPartialKey = 0x00000100; |
|
63 |
const TUint32 KPhonebookCurrentConfigurationMask = 0xffffff00; |
|
64 |
||
65 |
const TInt KInitialStoreUriSize = 22; // length of KVPbkDefaultCntDbURI |
|
66 |
const TInt KMagicNumber = -1; |
|
67 |
} // namespace |
|
68 |
||
69 |
NONSHARABLE_CLASS(CVPbkPhoneNumberMatchStrategyImpl) : |
|
70 |
public CActive, |
|
71 |
public MVPbkContactFindObserver, |
|
72 |
public MVPbkSingleContactOperationObserver |
|
73 |
{ |
|
74 |
public: // Construction |
|
75 |
static CVPbkPhoneNumberMatchStrategyImpl* NewL( |
|
76 |
CVPbkPhoneNumberMatchStrategy& aParent, |
|
77 |
const CVPbkPhoneNumberMatchStrategy::TConfig& aConfig, |
|
78 |
CVPbkContactManager& aContactManager, |
|
79 |
MVPbkContactFindObserver& aObserver); |
|
80 |
~CVPbkPhoneNumberMatchStrategyImpl(); |
|
81 |
||
82 |
public: // Interface |
|
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
83 |
CContactPhoneNumberParser* GetParser(); |
63 | 84 |
void MatchL(const TDesC& aPhoneNumber); |
85 |
TInt MaxMatchDigits() const; |
|
86 |
TArray<MVPbkContactStore*> StoresToMatch() const; |
|
87 |
TBool IsSimStore( const MVPbkContactStore& aStore ); |
|
88 |
||
89 |
private: // From CActive |
|
90 |
void RunL(); |
|
91 |
void DoCancel(); |
|
92 |
TInt RunError(TInt aError); |
|
93 |
||
94 |
private: // From MVPbkContactFindObserver |
|
95 |
void FindCompleteL(MVPbkContactLinkArray* aResults); |
|
96 |
void FindFailed(TInt aError); |
|
97 |
||
98 |
private: // From MVPbkSingleContactOperationObserver |
|
99 |
void VPbkSingleContactOperationComplete( |
|
100 |
MVPbkContactOperationBase& aOperation, |
|
101 |
MVPbkStoreContact* aContact); |
|
102 |
void VPbkSingleContactOperationFailed( |
|
103 |
MVPbkContactOperationBase& aOperation, |
|
104 |
TInt aError); |
|
105 |
||
106 |
private: |
|
107 |
/// Phone number types |
|
108 |
enum TNumberType { ENotInitialized, EUnknown, EDigit, EPlus, EOneZero, ETwoZeros }; |
|
109 |
||
110 |
private: // Implementation |
|
111 |
CVPbkPhoneNumberMatchStrategyImpl(CVPbkPhoneNumberMatchStrategy& aParent); |
|
112 |
void ConstructL( |
|
113 |
const CVPbkPhoneNumberMatchStrategy::TConfig& aConfig, |
|
114 |
CVPbkContactManager& aContactManager, |
|
115 |
MVPbkContactFindObserver& aObserver); |
|
116 |
||
117 |
/** |
|
118 |
* Searches for a store that has given URI from the list of |
|
119 |
* stores that the contact manager has. |
|
120 |
* @param aUriPtr URI of the store to search for. |
|
121 |
* @return The store with aUriPtr, or NULL if store was not found. |
|
122 |
*/ |
|
123 |
MVPbkContactStore* FindStoreL( |
|
124 |
const TVPbkContactStoreUriPtr& aUriPtr); |
|
125 |
||
126 |
/** |
|
127 |
* Issues new request to be handled in RunL. |
|
128 |
*/ |
|
129 |
void IssueRequest(); |
|
130 |
||
131 |
MVPbkContactLink* IsValidResultLC(MVPbkStoreContact* aContact); |
|
132 |
||
133 |
/** |
|
134 |
* Creates name tokens array |
|
135 |
* @param aContact which is checking, RPointerArray reference |
|
136 |
*/ |
|
137 |
void CreateNameTokensArrayL( MVPbkStoreContact* aContact, RPointerArray <HBufC>& aNameTokensArray ); |
|
138 |
||
139 |
/** |
|
140 |
* Check if contact already exists in results array |
|
141 |
* @param aContact which is checking |
|
142 |
* @return True if contact exist or if array was empty. |
|
143 |
*/ |
|
144 |
TBool CheckContactDuplicationL( MVPbkStoreContact* aContact ); |
|
145 |
||
146 |
/** |
|
147 |
* Gets contact's field value |
|
148 |
* @param aContact to get field's value from |
|
149 |
* @param aFieldType: EVPbkVersitNameN for Last Name |
|
150 |
* EVPbkVersitNameFN for First Name |
|
151 |
* @return Pointer descriptor with field's value. |
|
152 |
*/ |
|
153 |
TPtrC NameFieldValueL( MVPbkStoreContact* aContact, TVPbkFieldTypeName aFieldType ); |
|
154 |
||
155 |
TBool ValidateBestMatchingRulesL( const TDesC& aNumber ); |
|
156 |
TBool CheckBestMatchingRules( const TDesC& aNumberA, TNumberType aNumberAType, |
|
157 |
const TDesC& aNumberB, TNumberType aNumberBType ); |
|
158 |
TInt FormatAndCheckNumberType( TDes& aNumber ); |
|
159 |
||
160 |
/** |
|
161 |
* Reads current store configuration from central repositiry |
|
162 |
* @return Array of stores or NULL if error during reading form cenrep. |
|
163 |
*/ |
|
164 |
CVPbkContactStoreUriArray* GetCurrentStoreConfigurationL(); |
|
165 |
||
166 |
/** |
|
167 |
* If there is in the results at least one contact |
|
168 |
* from currently used stores in Phonebook2 it removes from results |
|
169 |
* contacts from other stores |
|
170 |
*/ |
|
171 |
void RefineDuplicatedNumbersL(); |
|
172 |
||
173 |
/** |
|
174 |
* Load number parser plugin. |
|
175 |
*/ |
|
176 |
void LoadNumberParserPluginL(); |
|
177 |
||
178 |
private: // Data |
|
179 |
CVPbkPhoneNumberMatchStrategy& iParent; |
|
180 |
/// Ref: The contact manager instance to be used for searching. |
|
181 |
CVPbkContactManager* iContactManager; |
|
182 |
/// Ref: Observer for the searching process. |
|
183 |
MVPbkContactFindObserver* iObserver; |
|
184 |
/// Own: The find operation that is currently ongoing. |
|
185 |
MVPbkContactOperationBase* iOperation; |
|
186 |
/// Maximum number of matched digits. |
|
187 |
TInt iMaxMatchDigits; |
|
188 |
/// Flags to configure matching process, @see TVPbkPhoneNumberMatchFlags |
|
189 |
TUint32 iMatchFlags; |
|
190 |
||
191 |
/// Own: Array of stores that are used in matching. |
|
192 |
RPointerArray<MVPbkContactStore> iStoresToMatch; |
|
193 |
/// Own: Phone number that is being matched. |
|
194 |
HBufC* iPhoneNumber; |
|
195 |
/// Own: Intermediate results of the matching process. |
|
196 |
CVPbkContactLinkArray* iWorkingResults; |
|
197 |
/// Own: Final results of the matching process. |
|
198 |
CVPbkContactLinkArray* iResults; |
|
199 |
/// iWorkingResults index of current contact retrieval |
|
200 |
TInt iCurrentContact; |
|
201 |
||
202 |
/// Own: Currently retrieved contact |
|
203 |
MVPbkStoreContact* iStoreContact; |
|
204 |
/// Own: Field type selector |
|
205 |
CVPbkFieldTypeSelector* iFieldTypeSelector; |
|
206 |
/// Own: A filtered and sorted collection of Virtual Phonebook contact fields. |
|
207 |
CVPbkFieldFilter* iFieldFilter; |
|
208 |
||
209 |
/// Active object states |
|
210 |
enum TState { EMatch, ERemoveDuplicates, ERefineSearch, EComplete }; |
|
211 |
/// Active object current state |
|
212 |
TState iState; |
|
213 |
||
214 |
/// Own: First Name field type selector |
|
215 |
CVPbkFieldTypeSelector* iFirstNameSelector; |
|
216 |
/// Own: Last Name field type selector |
|
217 |
CVPbkFieldTypeSelector* iLastNameSelector; |
|
218 |
/// Own: Array of tokens gotten from first and last name fields of first matched contact |
|
219 |
RPointerArray <HBufC> iNameTokensArray; |
|
220 |
/// Own: Array of tokens gotten from first and last name fields of contact |
|
221 |
RPointerArray <HBufC> iTempNameTokensArray; |
|
222 |
/// Indicates if all contact in iResult are the same |
|
223 |
TBool iDoubledContacts; |
|
224 |
/// type of iPhoneNumber |
|
225 |
TNumberType iPhoneNumberType; |
|
226 |
// Own: parser |
|
227 |
CContactPhoneNumberParser* iParser; |
|
228 |
}; |
|
229 |
||
230 |
CVPbkPhoneNumberMatchStrategyImpl::CVPbkPhoneNumberMatchStrategyImpl( |
|
231 |
CVPbkPhoneNumberMatchStrategy& aParent) : |
|
232 |
CActive(CActive::EPriorityIdle), |
|
233 |
iParent(aParent) |
|
234 |
{ |
|
235 |
CActiveScheduler::Add(this); |
|
236 |
} |
|
237 |
||
238 |
inline void CVPbkPhoneNumberMatchStrategyImpl::ConstructL( |
|
239 |
const CVPbkPhoneNumberMatchStrategy::TConfig& aConfig, |
|
240 |
CVPbkContactManager& aContactManager, |
|
241 |
MVPbkContactFindObserver& aObserver) |
|
242 |
{ |
|
243 |
iContactManager = &aContactManager; |
|
244 |
iObserver = &aObserver; |
|
245 |
||
246 |
iMaxMatchDigits = aConfig.iMaxMatchDigits; |
|
247 |
iMatchFlags = aConfig.iMatchFlags; |
|
248 |
||
249 |
const TInt uriCount = aConfig.iUriPriorities.Count(); |
|
250 |
for (TInt i = 0; i < uriCount; ++i) |
|
251 |
{ |
|
252 |
MVPbkContactStore* store = FindStoreL(aConfig.iUriPriorities[i]); |
|
253 |
if (store) |
|
254 |
{ |
|
255 |
iStoresToMatch.AppendL(store); |
|
256 |
} |
|
257 |
} |
|
258 |
||
259 |
VPbkEngUtils::RLocalizedResourceFile resFile; |
|
260 |
resFile.OpenLC(iContactManager->FsSession(), |
|
261 |
KVPbkRomFileDrive, |
|
262 |
KDC_RESOURCE_FILES_DIR, |
|
263 |
KVPbkFieldTypeSelectorsResFileName); |
|
264 |
HBufC8* selectorBuf = resFile.AllocReadLC(R_VPBK_PHONE_NUMBER_SELECTOR); |
|
265 |
TResourceReader resReader; |
|
266 |
resReader.SetBuffer(selectorBuf); |
|
267 |
||
268 |
iFieldTypeSelector = CVPbkFieldTypeSelector::NewL(resReader, iContactManager->FieldTypes()); |
|
269 |
||
270 |
CleanupStack::PopAndDestroy( selectorBuf ); |
|
271 |
||
272 |
if ( iMatchFlags & CVPbkPhoneNumberMatchStrategy::EVPbkDuplicatedContactsMatchFlag ) |
|
273 |
{ |
|
274 |
HBufC8* firstNameSelectorBuf = resFile.AllocReadLC( R_VPBK_FIRST_NAME_SELECTOR ); |
|
275 |
resReader.SetBuffer( firstNameSelectorBuf ); |
|
276 |
iFirstNameSelector = CVPbkFieldTypeSelector::NewL( resReader, iContactManager->FieldTypes() ); |
|
277 |
CleanupStack::PopAndDestroy( firstNameSelectorBuf ); |
|
278 |
||
279 |
HBufC8* lastNameSelectorBuf = resFile.AllocReadLC( R_VPBK_LAST_NAME_SELECTOR ); |
|
280 |
resReader.SetBuffer( lastNameSelectorBuf ); |
|
281 |
iLastNameSelector = CVPbkFieldTypeSelector::NewL( resReader, iContactManager->FieldTypes() ); |
|
282 |
CleanupStack::PopAndDestroy( lastNameSelectorBuf ); |
|
283 |
} |
|
284 |
||
285 |
CleanupStack::PopAndDestroy( &resFile ); |
|
286 |
||
287 |
LoadNumberParserPluginL(); |
|
288 |
} |
|
289 |
||
290 |
CVPbkPhoneNumberMatchStrategyImpl* CVPbkPhoneNumberMatchStrategyImpl::NewL( |
|
291 |
CVPbkPhoneNumberMatchStrategy& aParent, |
|
292 |
const CVPbkPhoneNumberMatchStrategy::TConfig& aConfig, |
|
293 |
CVPbkContactManager& aContactManager, |
|
294 |
MVPbkContactFindObserver& aObserver) |
|
295 |
{ |
|
296 |
CVPbkPhoneNumberMatchStrategyImpl* self = |
|
297 |
new(ELeave) CVPbkPhoneNumberMatchStrategyImpl(aParent); |
|
298 |
CleanupStack::PushL(self); |
|
299 |
self->ConstructL(aConfig, aContactManager, aObserver); |
|
300 |
CleanupStack::Pop(self); |
|
301 |
return self; |
|
302 |
} |
|
303 |
||
304 |
CVPbkPhoneNumberMatchStrategyImpl::~CVPbkPhoneNumberMatchStrategyImpl() |
|
305 |
{ |
|
306 |
Cancel(); |
|
307 |
||
308 |
delete iFieldFilter; |
|
309 |
delete iFieldTypeSelector; |
|
310 |
delete iWorkingResults; |
|
311 |
delete iResults; |
|
312 |
delete iStoreContact; |
|
313 |
delete iPhoneNumber; |
|
314 |
delete iOperation; |
|
315 |
delete iFirstNameSelector; |
|
316 |
delete iLastNameSelector; |
|
317 |
iNameTokensArray.ResetAndDestroy(); |
|
318 |
iTempNameTokensArray.ResetAndDestroy(); |
|
319 |
iStoresToMatch.Close(); |
|
320 |
delete iParser; |
|
321 |
REComSession::FinalClose(); |
|
322 |
} |
|
323 |
||
324 |
void CVPbkPhoneNumberMatchStrategyImpl::MatchL(const TDesC& aPhoneNumber) |
|
325 |
{ |
|
326 |
HBufC* phoneNumber = aPhoneNumber.AllocL(); |
|
327 |
delete iPhoneNumber; |
|
328 |
iPhoneNumber = phoneNumber; |
|
329 |
iPhoneNumberType = ENotInitialized; |
|
330 |
||
331 |
if ( iWorkingResults ) |
|
332 |
{ |
|
333 |
iWorkingResults->ResetAndDestroy(); |
|
334 |
} |
|
335 |
if ( iResults ) |
|
336 |
{ |
|
337 |
iResults->ResetAndDestroy(); |
|
338 |
} |
|
339 |
iCurrentContact = KMagicNumber; |
|
340 |
||
341 |
if ( iMatchFlags & CVPbkPhoneNumberMatchStrategy::EVPbkDuplicatedContactsMatchFlag ) |
|
342 |
{ |
|
343 |
iDoubledContacts = ETrue; |
|
344 |
} |
|
345 |
else |
|
346 |
{ |
|
347 |
iDoubledContacts = EFalse; |
|
348 |
} |
|
349 |
iState = EMatch; |
|
350 |
IssueRequest(); |
|
351 |
} |
|
352 |
||
353 |
||
354 |
void CVPbkPhoneNumberMatchStrategyImpl::IssueRequest() |
|
355 |
{ |
|
356 |
TRequestStatus* status = &iStatus; |
|
357 |
User::RequestComplete(status, KErrNone); |
|
358 |
SetActive(); |
|
359 |
} |
|
360 |
||
361 |
void CVPbkPhoneNumberMatchStrategyImpl::RunL() |
|
362 |
{ |
|
363 |
switch (iState) |
|
364 |
{ |
|
365 |
case EMatch: |
|
366 |
{ |
|
367 |
MVPbkContactOperation* operation = iParent.CreateFindOperationLC(*iPhoneNumber); |
|
368 |
if (operation) |
|
369 |
{ |
|
370 |
operation->StartL(); |
|
371 |
CleanupStack::Pop(); // operation |
|
372 |
delete iOperation; |
|
373 |
iOperation = operation; |
|
374 |
} |
|
375 |
else |
|
376 |
{ |
|
377 |
// all needed operations are done if any |
|
378 |
iState = ERemoveDuplicates; |
|
379 |
IssueRequest(); |
|
380 |
} |
|
381 |
break; |
|
382 |
} |
|
383 |
case ERemoveDuplicates: |
|
384 |
{ |
|
385 |
const TInt count = iWorkingResults ? iWorkingResults->Count() : 0; |
|
386 |
CVPbkContactLinkArray* results = CVPbkContactLinkArray::NewLC(); |
|
387 |
for (TInt i = 0; i < count; ++i) |
|
388 |
{ |
|
389 |
MVPbkContactLink* link = iWorkingResults->At(i).CloneLC(); |
|
390 |
if (results->Find(*link) == KErrNotFound) |
|
391 |
{ |
|
392 |
results->AppendL(link); |
|
393 |
CleanupStack::Pop(); // link |
|
394 |
} |
|
395 |
else |
|
396 |
{ |
|
397 |
CleanupStack::PopAndDestroy(); // link |
|
398 |
} |
|
399 |
} |
|
400 |
CleanupStack::Pop(results); |
|
401 |
delete iWorkingResults; |
|
402 |
iWorkingResults = results; |
|
403 |
iState = ERefineSearch; |
|
404 |
iCurrentContact = 0; |
|
405 |
IssueRequest(); |
|
406 |
break; |
|
407 |
} |
|
408 |
case ERefineSearch: |
|
409 |
{ |
|
410 |
if (!iResults) |
|
411 |
{ |
|
412 |
iResults = CVPbkContactLinkArray::NewL(); |
|
413 |
} |
|
414 |
||
415 |
MVPbkContactLink* result = IsValidResultLC( iStoreContact ); |
|
416 |
if ( result ) |
|
417 |
{ |
|
418 |
iResults->AppendL( result ); |
|
419 |
CleanupStack::Pop(); // MVPbkContactLink |
|
420 |
||
421 |
if ( iDoubledContacts ) |
|
422 |
{ |
|
423 |
iDoubledContacts = CheckContactDuplicationL( iStoreContact ); |
|
424 |
} |
|
425 |
} |
|
426 |
||
427 |
delete iStoreContact; |
|
428 |
iStoreContact = NULL; |
|
429 |
||
430 |
const TInt count = iWorkingResults ? iWorkingResults->Count() : 0; |
|
431 |
if (iCurrentContact < count && |
|
432 |
!( iResults->Count() > 0 && |
|
433 |
(iMatchFlags & CVPbkPhoneNumberMatchStrategy::EVPbkStopOnFirstMatchFlag))) |
|
434 |
{ |
|
435 |
const MVPbkContactLink& link = iWorkingResults->At(iCurrentContact); |
|
436 |
delete iOperation; |
|
437 |
iOperation = NULL; |
|
438 |
iOperation = iContactManager->RetrieveContactL(link, *this); |
|
439 |
++iCurrentContact; |
|
440 |
} |
|
441 |
else |
|
442 |
{ |
|
443 |
iState = EComplete; |
|
444 |
IssueRequest(); |
|
445 |
} |
|
446 |
break; |
|
447 |
} |
|
448 |
case EComplete: |
|
449 |
{ |
|
450 |
iNameTokensArray.ResetAndDestroy(); |
|
451 |
iTempNameTokensArray.ResetAndDestroy(); |
|
452 |
if ( iDoubledContacts && iResults->Count() ) |
|
453 |
{ |
|
454 |
CVPbkContactLinkArray* results = CVPbkContactLinkArray::NewLC(); |
|
455 |
MVPbkContactLink* link = iResults->At(0).CloneLC(); // first element |
|
456 |
results->AppendL( link ); |
|
457 |
CleanupStack::Pop( 2, results ); // results, link |
|
458 |
delete iResults; |
|
459 |
iResults = results; |
|
460 |
} |
|
461 |
||
462 |
if ( iResults->Count() > 1 ) |
|
463 |
{ |
|
464 |
RefineDuplicatedNumbersL(); |
|
465 |
} |
|
466 |
||
467 |
CVPbkContactLinkArray* results = iResults; |
|
468 |
iResults = NULL; |
|
469 |
iObserver->FindCompleteL( results ); |
|
470 |
break; |
|
471 |
} |
|
472 |
default: |
|
473 |
{ |
|
474 |
// This case should not be possible |
|
475 |
User::Leave( KErrArgument ); |
|
476 |
break; |
|
477 |
} |
|
478 |
} |
|
479 |
} |
|
480 |
||
481 |
void CVPbkPhoneNumberMatchStrategyImpl::DoCancel() |
|
482 |
{ |
|
483 |
} |
|
484 |
||
485 |
TInt CVPbkPhoneNumberMatchStrategyImpl::RunError(TInt aError) |
|
486 |
{ |
|
487 |
iObserver->FindFailed(aError); |
|
488 |
return KErrNone; |
|
489 |
} |
|
490 |
||
491 |
inline MVPbkContactStore* CVPbkPhoneNumberMatchStrategyImpl::FindStoreL( |
|
492 |
const TVPbkContactStoreUriPtr& aUriPtr) |
|
493 |
{ |
|
494 |
const TInt storeCount = iContactManager->ContactStoresL().Count(); |
|
495 |
for (TInt i = 0; i < storeCount; ++i) |
|
496 |
{ |
|
497 |
MVPbkContactStore& store = iContactManager->ContactStoresL().At(i); |
|
498 |
if (store.StoreProperties().Uri().Compare( |
|
499 |
aUriPtr, |
|
500 |
TVPbkContactStoreUriPtr::EContactStoreUriAllComponents) == 0) |
|
501 |
{ |
|
502 |
return &store; |
|
503 |
} |
|
504 |
} |
|
505 |
return NULL; |
|
506 |
} |
|
507 |
||
508 |
void CVPbkPhoneNumberMatchStrategyImpl::FindCompleteL(MVPbkContactLinkArray* aResults) |
|
509 |
{ |
|
510 |
// This function called by operation which is created in |
|
511 |
// iParent.CreateFindOperationLC |
|
512 |
if (aResults) |
|
513 |
{ |
|
514 |
CleanupDeletePushL( aResults ); // Take ownership |
|
515 |
||
516 |
if (!iWorkingResults) |
|
517 |
{ |
|
518 |
iWorkingResults = CVPbkContactLinkArray::NewL(); |
|
519 |
} |
|
520 |
const TInt count = aResults->Count(); |
|
521 |
for (TInt i = 0; i < count; ++i) |
|
522 |
{ |
|
523 |
MVPbkContactLink* link = aResults->At(i).CloneLC(); |
|
524 |
iWorkingResults->AppendL(link); |
|
525 |
CleanupStack::Pop(); // link |
|
526 |
} |
|
527 |
||
528 |
CleanupStack::PopAndDestroy(); // aResults |
|
529 |
} |
|
530 |
IssueRequest(); |
|
531 |
} |
|
532 |
||
533 |
void CVPbkPhoneNumberMatchStrategyImpl::FindFailed(TInt aError) |
|
534 |
{ |
|
535 |
iObserver->FindFailed(aError); |
|
536 |
} |
|
537 |
||
538 |
void CVPbkPhoneNumberMatchStrategyImpl::VPbkSingleContactOperationComplete( |
|
539 |
MVPbkContactOperationBase& aOperation, |
|
540 |
MVPbkStoreContact* aContact) |
|
541 |
{ |
|
542 |
if (iOperation == &aOperation) |
|
543 |
{ |
|
544 |
delete iOperation; |
|
545 |
iOperation = NULL; |
|
546 |
||
547 |
iStoreContact = aContact; |
|
548 |
IssueRequest(); |
|
549 |
} |
|
550 |
} |
|
551 |
||
552 |
void CVPbkPhoneNumberMatchStrategyImpl::VPbkSingleContactOperationFailed( |
|
553 |
MVPbkContactOperationBase& aOperation, |
|
554 |
TInt aError) |
|
555 |
{ |
|
556 |
if (iOperation == &aOperation) |
|
557 |
{ |
|
558 |
delete iOperation; |
|
559 |
iOperation = NULL; |
|
560 |
||
561 |
iObserver->FindFailed(aError); |
|
562 |
} |
|
563 |
} |
|
564 |
||
565 |
TInt CVPbkPhoneNumberMatchStrategyImpl::MaxMatchDigits() const |
|
566 |
{ |
|
567 |
return iMaxMatchDigits; |
|
568 |
} |
|
569 |
||
570 |
TArray<MVPbkContactStore*> CVPbkPhoneNumberMatchStrategyImpl::StoresToMatch() const |
|
571 |
{ |
|
572 |
return iStoresToMatch.Array(); |
|
573 |
} |
|
574 |
||
575 |
MVPbkContactLink* CVPbkPhoneNumberMatchStrategyImpl::IsValidResultLC( |
|
576 |
MVPbkStoreContact* aContact) |
|
577 |
{ |
|
578 |
MVPbkContactLink* result = NULL; |
|
579 |
||
580 |
if (!(iMatchFlags & CVPbkPhoneNumberMatchStrategy::EVPbkExactMatchFlag) |
|
581 |
&& !(iMatchFlags & CVPbkPhoneNumberMatchStrategy::EVPbkBestMatchingFlag)) |
|
582 |
{ |
|
583 |
// If exact match is not needed we will accept the contact as valid |
|
584 |
// if it is not NULL |
|
585 |
if ( aContact ) |
|
586 |
{ |
|
587 |
result = aContact->CreateLinkLC(); |
|
588 |
} |
|
589 |
} |
|
590 |
else if (aContact) |
|
591 |
{ |
|
592 |
TPtrC matchedNumber = iPhoneNumber->Des(). |
|
593 |
Right(Min(iPhoneNumber->Length(), iMaxMatchDigits)); |
|
594 |
||
595 |
CVPbkFieldFilter::TConfig config(aContact->Fields(), iFieldTypeSelector); |
|
596 |
if (!iFieldFilter) |
|
597 |
{ |
|
598 |
iFieldFilter = CVPbkFieldFilter::NewL(config); |
|
599 |
} |
|
600 |
else |
|
601 |
{ |
|
602 |
iFieldFilter->ResetL(config); |
|
603 |
} |
|
604 |
const TInt count = iFieldFilter->FieldCount(); |
|
605 |
for (TInt i = 0; i < count; ++i) |
|
606 |
{ |
|
607 |
MVPbkContactFieldData& data = iFieldFilter->FieldAt(i).FieldData(); |
|
608 |
if (data.DataType() == EVPbkFieldStorageTypeText) |
|
609 |
{ |
|
610 |
const TDesC& dataText = MVPbkContactFieldTextData::Cast(data).Text(); |
|
611 |
if (iMatchFlags & CVPbkPhoneNumberMatchStrategy::EVPbkExactMatchFlag) |
|
612 |
{ |
|
613 |
TPtrC dataTextPtr = dataText.Right(Min(dataText.Length(), iMaxMatchDigits)); |
|
614 |
if (dataTextPtr == matchedNumber) |
|
615 |
{ |
|
616 |
result = iFieldFilter->FieldAt(i).CreateLinkLC(); |
|
617 |
break; |
|
618 |
} |
|
619 |
} |
|
620 |
else if (iMatchFlags & CVPbkPhoneNumberMatchStrategy::EVPbkBestMatchingFlag |
|
621 |
&& ValidateBestMatchingRulesL(dataText)) |
|
622 |
{ |
|
623 |
result = aContact->CreateLinkLC(); |
|
624 |
break; |
|
625 |
} |
|
626 |
} |
|
627 |
} |
|
628 |
} |
|
629 |
return result; |
|
630 |
} |
|
631 |
||
632 |
TBool CVPbkPhoneNumberMatchStrategyImpl::CheckContactDuplicationL( |
|
633 |
MVPbkStoreContact* aContact ) |
|
634 |
{ |
|
635 |
||
636 |
if ( !aContact ) |
|
637 |
{ |
|
638 |
return ETrue; |
|
639 |
} |
|
640 |
||
641 |
if ( aContact && iCurrentContact == 1 ) |
|
642 |
{ |
|
643 |
CreateNameTokensArrayL( aContact, iNameTokensArray ); |
|
644 |
return ETrue; |
|
645 |
} |
|
646 |
else |
|
647 |
{ |
|
648 |
iTempNameTokensArray.ResetAndDestroy(); |
|
649 |
CreateNameTokensArrayL( aContact, iTempNameTokensArray ); |
|
650 |
TInt count = iNameTokensArray.Count(); |
|
651 |
if ( iNameTokensArray.Count() != iTempNameTokensArray.Count() ) |
|
652 |
{ |
|
653 |
return EFalse; |
|
654 |
} |
|
655 |
else |
|
656 |
{ |
|
657 |
TInt result = 0; |
|
658 |
for ( TInt i = 0; i < count; i++ ) |
|
659 |
{ |
|
660 |
HBufC* token = iNameTokensArray[i]; |
|
661 |
TInt tempCount = iTempNameTokensArray.Count(); |
|
662 |
for ( TInt j = 0; j < tempCount; j++ ) |
|
663 |
{ |
|
664 |
result = token->Compare( *( iTempNameTokensArray[j] ) ); |
|
665 |
if ( !result ) |
|
666 |
{ |
|
667 |
HBufC* removedToken = iTempNameTokensArray[j]; |
|
668 |
iTempNameTokensArray.Remove( j ); |
|
669 |
delete removedToken; |
|
670 |
break; |
|
671 |
} |
|
672 |
} |
|
673 |
if ( result ) |
|
674 |
{ |
|
675 |
return EFalse; |
|
676 |
} |
|
677 |
} |
|
678 |
} |
|
679 |
return ETrue; |
|
680 |
} |
|
681 |
} |
|
682 |
||
683 |
void CVPbkPhoneNumberMatchStrategyImpl::CreateNameTokensArrayL( MVPbkStoreContact* aContact, |
|
684 |
RPointerArray <HBufC>& aNameTokensArray ) |
|
685 |
{ |
|
686 |
TPtrC firstName = NameFieldValueL( aContact, EVPbkVersitNameFN ); |
|
687 |
TLex lexer; |
|
688 |
lexer.Assign( firstName ); |
|
689 |
||
690 |
TPtrC ptr; |
|
691 |
TInt len = 0; |
|
692 |
while( ETrue ) |
|
693 |
{ |
|
694 |
ptr.Set( lexer.NextToken() ); |
|
695 |
||
696 |
len = ptr.Length(); |
|
697 |
if ( len ) |
|
698 |
{ |
|
699 |
HBufC* token = ptr.AllocLC(); |
|
700 |
aNameTokensArray.AppendL( token ); |
|
701 |
CleanupStack::Pop( token ); |
|
702 |
} |
|
703 |
else |
|
704 |
{ |
|
705 |
break; |
|
706 |
} |
|
707 |
} |
|
708 |
||
709 |
TPtrC lastName = NameFieldValueL( aContact, EVPbkVersitNameN ); |
|
710 |
||
711 |
lexer.Assign( lastName ); |
|
712 |
||
713 |
len = 0; |
|
714 |
while( ETrue ) |
|
715 |
{ |
|
716 |
ptr.Set( lexer.NextToken() ); |
|
717 |
||
718 |
len = ptr.Length(); |
|
719 |
if ( len ) |
|
720 |
{ |
|
721 |
HBufC* token = ptr.AllocLC(); |
|
722 |
aNameTokensArray.AppendL( token ); |
|
723 |
CleanupStack::Pop( token ); |
|
724 |
} |
|
725 |
else |
|
726 |
{ |
|
727 |
break; |
|
728 |
} |
|
729 |
} |
|
730 |
} |
|
731 |
||
732 |
TPtrC CVPbkPhoneNumberMatchStrategyImpl::NameFieldValueL( |
|
733 |
MVPbkStoreContact* aContact, TVPbkFieldTypeName aFieldType ) |
|
734 |
{ |
|
735 |
if ( aContact ) |
|
736 |
{ |
|
737 |
CVPbkFieldFilter::TConfig config( aContact->Fields() ); |
|
738 |
if ( aFieldType == EVPbkVersitNameFN ) |
|
739 |
{ |
|
740 |
config.iFieldSelector = iFirstNameSelector; |
|
741 |
} |
|
742 |
else if ( aFieldType == EVPbkVersitNameN ) |
|
743 |
{ |
|
744 |
config.iFieldSelector = iLastNameSelector; |
|
745 |
} |
|
746 |
else |
|
747 |
{ |
|
748 |
return KNullDesC(); |
|
749 |
} |
|
750 |
||
751 |
if (!iFieldFilter) |
|
752 |
{ |
|
753 |
iFieldFilter = CVPbkFieldFilter::NewL(config); |
|
754 |
} |
|
755 |
else |
|
756 |
{ |
|
757 |
iFieldFilter->ResetL(config); |
|
758 |
} |
|
759 |
const TInt count = iFieldFilter->FieldCount(); |
|
760 |
for (TInt i = 0; i < count; ++i) |
|
761 |
{ |
|
762 |
MVPbkContactFieldData& data = iFieldFilter->FieldAt(i).FieldData(); |
|
763 |
if (data.DataType() == EVPbkFieldStorageTypeText) |
|
764 |
{ |
|
765 |
return MVPbkContactFieldTextData::Cast(data).Text(); |
|
766 |
} |
|
767 |
} |
|
768 |
return KNullDesC(); |
|
769 |
} |
|
770 |
else |
|
771 |
{ |
|
772 |
return KNullDesC(); |
|
773 |
} |
|
774 |
} |
|
775 |
||
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
776 |
CContactPhoneNumberParser* CVPbkPhoneNumberMatchStrategyImpl::GetParser() |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
777 |
{ |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
778 |
return iParser; |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
779 |
} |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
780 |
|
63 | 781 |
// Removes non-digit chars except plus form the beginning |
782 |
// Checks if number matches to one of defined types |
|
783 |
// |
|
784 |
TInt CVPbkPhoneNumberMatchStrategyImpl::FormatAndCheckNumberType( TDes& aNumber ) |
|
785 |
{ |
|
786 |
_LIT( KOneZeroPattern, "0*" ); |
|
787 |
_LIT( KTwoZerosPattern, "00*" ); |
|
788 |
_LIT( KPlusPattern, "+*" ); |
|
789 |
_LIT( KPlusString, "+" ); |
|
790 |
const TChar KPlus = TChar('+'); |
|
791 |
const TChar KZero = TChar('0'); |
|
792 |
const TChar KAsterisk = TChar('*'); |
|
793 |
const TChar KHash = TChar('#'); |
|
794 |
||
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
795 |
TInt format; |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
796 |
|
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
797 |
HBufC* numberBuf = NULL; |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
798 |
TRAPD(err, numberBuf = HBufC::NewL( aNumber.Length() ) ); |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
799 |
// Error was found when Phone allocated memory for numberBuf |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
800 |
if( err != KErrNone ) |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
801 |
{ |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
802 |
return ( format = EUnknown ); |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
803 |
} |
63 | 804 |
TPtr number = numberBuf->Des(); |
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
805 |
if ( GetParser() ) |
63 | 806 |
{ |
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
807 |
GetParser()->ExtractRawNumber( aNumber, number ); |
63 | 808 |
} |
809 |
TInt pos = aNumber.Find( number ); |
|
810 |
||
811 |
if ( pos > 0 && aNumber[pos-1] == KPlus ) |
|
812 |
{ |
|
813 |
number.Insert( 0, KPlusString ); |
|
814 |
} |
|
815 |
||
816 |
if ( number.Length() > 0) |
|
817 |
{ |
|
818 |
aNumber.Copy( number ); |
|
819 |
} |
|
820 |
delete numberBuf; |
|
821 |
||
822 |
if ( !aNumber.Match( KTwoZerosPattern ) && aNumber.Length() > 2 && aNumber[2] != KZero ) |
|
823 |
{ |
|
824 |
format = ETwoZeros; |
|
825 |
} |
|
826 |
else if ( !aNumber.Match( KOneZeroPattern )&& aNumber.Length() > 1 && aNumber[1] != KZero ) |
|
827 |
{ |
|
828 |
format = EOneZero; |
|
829 |
} |
|
830 |
else if ( !aNumber.Match( KPlusPattern ) && aNumber.Length() > 1 && aNumber[1] != KZero ) |
|
831 |
{ |
|
832 |
format = EPlus; |
|
833 |
} |
|
834 |
else if ( aNumber.Length() > 0 && aNumber[0] != KZero && ( ( TChar ) aNumber[0] ).IsDigit() ) |
|
835 |
{ |
|
836 |
format = EDigit; |
|
837 |
} |
|
838 |
else |
|
839 |
{ |
|
840 |
format = EUnknown; |
|
841 |
} |
|
842 |
||
843 |
return format; |
|
844 |
} |
|
845 |
||
846 |
TBool CVPbkPhoneNumberMatchStrategyImpl::ValidateBestMatchingRulesL( const TDesC& aNumber ) |
|
847 |
{ |
|
848 |
if ( iPhoneNumberType == ENotInitialized ) |
|
849 |
{ |
|
850 |
TPtr16 phoneNumber = iPhoneNumber->Des(); |
|
851 |
iPhoneNumberType = ( TNumberType ) FormatAndCheckNumberType( phoneNumber ); |
|
852 |
} |
|
853 |
||
854 |
HBufC* number = aNumber.AllocLC(); |
|
855 |
TPtr16 phoneNumber = number->Des(); |
|
856 |
TNumberType numberType = ( TNumberType ) FormatAndCheckNumberType( phoneNumber ); |
|
857 |
||
858 |
TBool match = ( !phoneNumber.Compare( *iPhoneNumber ) || |
|
859 |
CheckBestMatchingRules( *iPhoneNumber, iPhoneNumberType, *number, numberType ) || |
|
860 |
CheckBestMatchingRules( *number, numberType, *iPhoneNumber, iPhoneNumberType ) ); |
|
861 |
||
862 |
CleanupStack::PopAndDestroy( number ); |
|
863 |
||
864 |
return match; |
|
865 |
} |
|
866 |
||
867 |
TBool CVPbkPhoneNumberMatchStrategyImpl::CheckBestMatchingRules( |
|
868 |
const TDesC& aNumberA, TNumberType aNumberAType, |
|
869 |
const TDesC& aNumberB, TNumberType aNumberBType ) |
|
870 |
{ |
|
871 |
TBool result = EFalse; |
|
872 |
||
873 |
// Rules for matching not identical numbers |
|
874 |
// Rules details are presented in Best_Number_Matching_Algorithm_Description.doc |
|
875 |
||
876 |
// rule International-International 1 |
|
877 |
if ( !result && aNumberAType == EPlus && aNumberBType == ETwoZeros ) |
|
878 |
{ |
|
879 |
TPtrC numberA = aNumberA.Right( aNumberA.Length() - 1 ); |
|
880 |
TPtrC numberB = aNumberB.Right( aNumberB.Length() - 2 ); |
|
881 |
result = !( numberA.Compare( numberB ) ); |
|
882 |
if ( result ) |
|
883 |
{ |
|
884 |
return result; |
|
885 |
} |
|
886 |
} |
|
887 |
||
888 |
// rule International-International 2 |
|
889 |
if ( aNumberAType == EPlus && aNumberBType == EDigit ) |
|
890 |
{ |
|
891 |
TPtrC numberA = aNumberA.Right( aNumberA.Length() - 1 ); |
|
892 |
if ( numberA.Length() < aNumberB.Length() ) |
|
893 |
{ |
|
894 |
TPtrC numberB = aNumberB.Right( numberA.Length() ); |
|
895 |
result = !( numberA.Compare( numberB ) ); |
|
896 |
if ( result ) |
|
897 |
{ |
|
898 |
return result; |
|
899 |
} |
|
900 |
} |
|
901 |
} |
|
902 |
||
903 |
// rule International-International 3 |
|
904 |
if ( aNumberAType == ETwoZeros && aNumberBType == EDigit ) |
|
905 |
{ |
|
906 |
TPtrC numberA = aNumberA.Right( aNumberA.Length() - 2 ); |
|
907 |
if ( numberA.Length() < aNumberB.Length() ) |
|
908 |
{ |
|
909 |
TPtrC numberB = aNumberB.Right( numberA.Length() ); |
|
910 |
result = !( numberA.Compare( numberB ) ); |
|
911 |
if ( result ) |
|
912 |
{ |
|
913 |
return result; |
|
914 |
} |
|
915 |
} |
|
916 |
} |
|
917 |
||
918 |
// rule International-Operator 1 |
|
919 |
if ( aNumberAType == EOneZero && aNumberBType == EPlus |
|
920 |
|| aNumberAType == EDigit && aNumberBType == EPlus ) |
|
921 |
{ |
|
922 |
TPtrC numberA; |
|
923 |
if ( aNumberAType == EOneZero ) |
|
924 |
{ |
|
925 |
numberA.Set( aNumberA.Right( aNumberA.Length() - 1 ) ); |
|
926 |
} |
|
927 |
else |
|
928 |
{ |
|
929 |
numberA.Set( aNumberA ); |
|
930 |
} |
|
931 |
if ( numberA.Length() < aNumberB.Length() - 1 ) |
|
932 |
{ |
|
933 |
TPtrC numberB = aNumberB.Right( numberA.Length() ); |
|
934 |
result = !( numberA.Compare( numberB ) ); |
|
935 |
if ( result ) |
|
936 |
{ |
|
937 |
return result; |
|
938 |
} |
|
939 |
} |
|
940 |
} |
|
941 |
||
942 |
// rule International-Operator 2 |
|
943 |
if ( aNumberAType == EOneZero && aNumberBType == ETwoZeros |
|
944 |
|| aNumberAType == EDigit && aNumberBType == ETwoZeros ) |
|
945 |
{ |
|
946 |
TPtrC numberA; |
|
947 |
if ( aNumberAType == EOneZero ) |
|
948 |
{ |
|
949 |
numberA.Set( aNumberA.Right( aNumberA.Length() - 1 ) ); |
|
950 |
} |
|
951 |
else |
|
952 |
{ |
|
953 |
numberA.Set( aNumberA ); |
|
954 |
} |
|
955 |
if ( numberA.Length() < aNumberB.Length() - 2 ) |
|
956 |
{ |
|
957 |
TPtrC numberB = aNumberB.Right( numberA.Length() ); |
|
958 |
result = !( numberA.Compare( numberB ) ); |
|
959 |
if ( result ) |
|
960 |
{ |
|
961 |
return result; |
|
962 |
} |
|
963 |
} |
|
964 |
} |
|
965 |
||
966 |
// rule International-Operator 3 |
|
967 |
if ( aNumberAType == EOneZero && aNumberBType == EDigit |
|
968 |
|| aNumberAType == EDigit && aNumberBType == EDigit ) |
|
969 |
{ |
|
970 |
TPtrC numberA; |
|
971 |
if ( aNumberAType == EOneZero ) |
|
972 |
{ |
|
973 |
numberA.Set( aNumberA.Right( aNumberA.Length() - 1 ) ); |
|
974 |
} |
|
975 |
else |
|
976 |
{ |
|
977 |
numberA.Set( aNumberA ); |
|
978 |
} |
|
979 |
if ( numberA.Length() < aNumberB.Length() ) |
|
980 |
{ |
|
981 |
TPtrC numberB = aNumberB.Right( numberA.Length() ); |
|
982 |
result = !( numberA.Compare( numberB ) ); |
|
983 |
if ( result ) |
|
984 |
{ |
|
985 |
return result; |
|
986 |
} |
|
987 |
} |
|
988 |
} |
|
989 |
||
990 |
// rule Operator-Operator 1 |
|
991 |
if ( aNumberAType == EOneZero && aNumberBType == EDigit ) |
|
992 |
{ |
|
993 |
TPtrC numberA = aNumberA.Right( aNumberA.Length() - 1 ); |
|
994 |
result = !( numberA.Compare( aNumberB ) ); |
|
995 |
{ |
|
996 |
if ( result ) |
|
997 |
{ |
|
998 |
return result; |
|
999 |
} |
|
1000 |
} |
|
1001 |
} |
|
1002 |
||
1003 |
// rule North America Numbering Plan 1 |
|
1004 |
if ( aNumberAType == EDigit && aNumberBType == EPlus ) |
|
1005 |
{ |
|
1006 |
TPtrC numberB = aNumberB.Right( aNumberB.Length() - 1 ); |
|
1007 |
result = !( aNumberA.Compare( numberB ) ); |
|
1008 |
{ |
|
1009 |
if ( result ) |
|
1010 |
{ |
|
1011 |
return result; |
|
1012 |
} |
|
1013 |
} |
|
1014 |
} |
|
1015 |
||
1016 |
// More exceptional acceptance rules can be added here |
|
1017 |
// Keep rules updated in the document Best_Number_Matching_Algorithm_Description.doc |
|
1018 |
||
1019 |
return result; |
|
1020 |
} |
|
1021 |
||
1022 |
CVPbkContactStoreUriArray* CVPbkPhoneNumberMatchStrategyImpl::GetCurrentStoreConfigurationL() |
|
1023 |
{ |
|
1024 |
CRepository* repository = CRepository::NewL( TUid::Uid( KCRUidPhonebookStoreConfiguration ) ); |
|
1025 |
CleanupStack::PushL( repository ); |
|
1026 |
CVPbkContactStoreUriArray* result = CVPbkContactStoreUriArray::NewLC(); |
|
1027 |
||
1028 |
RArray<TUint32> configurationKeys; |
|
1029 |
CleanupClosePushL( configurationKeys ); |
|
1030 |
||
1031 |
repository->FindL( KPhonebookCurrentConfigurationPartialKey, |
|
1032 |
KPhonebookCurrentConfigurationMask, configurationKeys ); |
|
1033 |
||
1034 |
HBufC* buffer = HBufC::NewLC( KInitialStoreUriSize ); |
|
1035 |
const TInt keyCount = configurationKeys.Count(); |
|
1036 |
TInt ret = KErrNone; |
|
1037 |
for ( TInt i = 0; i < keyCount; ++i ) |
|
1038 |
{ |
|
1039 |
TPtr ptr = buffer->Des(); |
|
1040 |
ptr.Zero(); |
|
1041 |
TInt actualSize = 0; |
|
1042 |
ret = repository->Get( configurationKeys[i], ptr, actualSize ); |
|
1043 |
if ( ret == KErrOverflow ) |
|
1044 |
{ |
|
1045 |
CleanupStack::PopAndDestroy(); // buffer |
|
1046 |
buffer = HBufC::NewLC( actualSize ); |
|
1047 |
ptr.Set( buffer->Des() ); |
|
1048 |
ret = repository->Get( configurationKeys[i], ptr ); |
|
1049 |
} |
|
1050 |
||
1051 |
if ( ret != KErrNone ) |
|
1052 |
{ |
|
1053 |
break; |
|
1054 |
} |
|
1055 |
||
1056 |
if( !result->IsIncluded( TVPbkContactStoreUriPtr( ptr ) ) ) // Only append if the uri is not yet included |
|
1057 |
{ |
|
1058 |
result->AppendL( ptr ); |
|
1059 |
} |
|
1060 |
} |
|
1061 |
CleanupStack::PopAndDestroy( buffer ); |
|
1062 |
CleanupStack::PopAndDestroy( &configurationKeys ); |
|
1063 |
CleanupStack::Pop( result ); |
|
1064 |
CleanupStack::PopAndDestroy( repository ); |
|
1065 |
||
1066 |
if ( ret != KErrNone ) |
|
1067 |
{ |
|
1068 |
delete result; |
|
1069 |
result = NULL; |
|
1070 |
} |
|
1071 |
return result; |
|
1072 |
} |
|
1073 |
||
1074 |
void CVPbkPhoneNumberMatchStrategyImpl::RefineDuplicatedNumbersL() |
|
1075 |
{ |
|
1076 |
CVPbkContactStoreUriArray* stores = GetCurrentStoreConfigurationL(); |
|
1077 |
if ( !stores ) |
|
1078 |
{ |
|
1079 |
return; |
|
1080 |
} |
|
1081 |
CleanupStack::PushL( stores ); |
|
1082 |
||
1083 |
TInt storesCount = stores->Count(); |
|
1084 |
if ( storesCount ) |
|
1085 |
{ |
|
1086 |
TInt linksCount = iResults->Count(); |
|
1087 |
// check if there is in the results at least one contact |
|
1088 |
// from currently used stores |
|
1089 |
TBool isFromUsedStore = EFalse; |
|
1090 |
for ( TInt i = 0; i < linksCount; i++ ) |
|
1091 |
{ |
|
1092 |
const MVPbkContactStoreProperties& linkStoreProp = |
|
1093 |
iResults->At( i ).ContactStore().StoreProperties(); |
|
1094 |
||
1095 |
for ( TInt j = 0; j < storesCount; j++ ) |
|
1096 |
{ |
|
1097 |
if ( !linkStoreProp.Uri().UriDes().Compare( ( *stores )[j].UriDes() ) ) |
|
1098 |
{ |
|
1099 |
isFromUsedStore = ETrue; |
|
1100 |
break; |
|
1101 |
} |
|
1102 |
} |
|
1103 |
if ( isFromUsedStore ) |
|
1104 |
{ |
|
1105 |
break; |
|
1106 |
} |
|
1107 |
} |
|
1108 |
// remove from results contacts from not used stores |
|
1109 |
if ( isFromUsedStore ) |
|
1110 |
{ |
|
1111 |
for ( TInt i = 0; i < linksCount; i++ ) |
|
1112 |
{ |
|
1113 |
TBool remove = ETrue; |
|
1114 |
const MVPbkContactStoreProperties& linkStoreProp = |
|
1115 |
iResults->At( i ).ContactStore().StoreProperties(); |
|
1116 |
||
1117 |
for ( TInt j = 0; j < storesCount; j++ ) |
|
1118 |
{ |
|
1119 |
if ( !linkStoreProp.Uri().UriDes().Compare( ( *stores )[j].UriDes() ) ) |
|
1120 |
{ |
|
1121 |
remove = EFalse; |
|
1122 |
break; |
|
1123 |
} |
|
1124 |
} |
|
1125 |
if ( remove ) |
|
1126 |
{ |
|
1127 |
iResults->Delete( i ); |
|
1128 |
linksCount--; |
|
1129 |
i--; |
|
1130 |
} |
|
1131 |
} |
|
1132 |
} |
|
1133 |
} |
|
1134 |
CleanupStack::PopAndDestroy( stores ); |
|
1135 |
} |
|
1136 |
||
1137 |
TBool CVPbkPhoneNumberMatchStrategyImpl::IsSimStore( const MVPbkContactStore& aStore ) |
|
1138 |
{ |
|
1139 |
TVPbkContactStoreUriPtr uriPtr = aStore.StoreProperties().Uri(); |
|
1140 |
if ( !uriPtr.UriDes().Compare( KVPbkSimGlobalAdnURI ) |
|
1141 |
|| !uriPtr.UriDes().Compare( KVPbkSimGlobalFdnURI ) |
|
1142 |
|| !uriPtr.UriDes().Compare( KVPbkSimGlobalSdnURI ) |
|
1143 |
|| !uriPtr.UriDes().Compare( KVPbkSimGlobalOwnNumberURI ) ) |
|
1144 |
{ |
|
1145 |
return ETrue; |
|
1146 |
} |
|
1147 |
return EFalse; |
|
1148 |
} |
|
1149 |
||
1150 |
void CVPbkPhoneNumberMatchStrategyImpl::LoadNumberParserPluginL() |
|
1151 |
{ |
|
1152 |
RImplInfoPtrArray implInfoArray; |
|
1153 |
CleanupResetAndDestroyPushL( implInfoArray ); |
|
1154 |
REComSession::ListImplementationsL( KUidEcomCntPhoneNumberParserInterface, |
|
1155 |
implInfoArray ); |
|
1156 |
// Load the first implementation found for KUidEcomCntPhoneNumberParserInterface |
|
1157 |
const TInt count = implInfoArray.Count(); |
|
1158 |
__ASSERT_ALWAYS( count > 0, User::Leave( KErrNotFound ) ); |
|
1159 |
const TUid firstImplementationFound = implInfoArray[0]->ImplementationUid(); |
|
1160 |
iParser = reinterpret_cast<CContactPhoneNumberParser*> |
|
1161 |
( CContactEcomPhoneNumberParser::NewL( firstImplementationFound ) ); |
|
1162 |
CleanupStack::PopAndDestroy( &implInfoArray ); |
|
1163 |
} |
|
1164 |
||
1165 |
CVPbkPhoneNumberMatchStrategy::CVPbkPhoneNumberMatchStrategy() |
|
1166 |
{ |
|
1167 |
} |
|
1168 |
||
1169 |
EXPORT_C CVPbkPhoneNumberMatchStrategy* CVPbkPhoneNumberMatchStrategy::NewL( |
|
1170 |
const TConfig& aConfig, |
|
1171 |
CVPbkContactManager& aContactManager, |
|
1172 |
MVPbkContactFindObserver& aObserver) |
|
1173 |
{ |
|
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1174 |
// We do not support yet CVPbkPhoneNumberMatchStrategy::EVPbkBestMatchingFlag flag |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1175 |
// Skip it from the configuration |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1176 |
TConfig config = aConfig; |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1177 |
config.iMatchFlags &= ~CVPbkPhoneNumberMatchStrategy::EVPbkBestMatchingFlag; |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1178 |
|
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1179 |
if (config.iMatchMode == EVPbkSequentialMatch) |
63 | 1180 |
{ |
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1181 |
return CVPbkPhoneNumberSequentialMatchStrategy::NewL(config, aContactManager, aObserver); |
63 | 1182 |
} |
1183 |
else |
|
1184 |
{ |
|
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1185 |
return CVPbkPhoneNumberParallelMatchStrategy::NewL(config, aContactManager, aObserver); |
63 | 1186 |
} |
1187 |
} |
|
1188 |
||
1189 |
CVPbkPhoneNumberMatchStrategy::~CVPbkPhoneNumberMatchStrategy() |
|
1190 |
{ |
|
1191 |
delete iImpl; |
|
1192 |
} |
|
1193 |
||
1194 |
EXPORT_C void CVPbkPhoneNumberMatchStrategy::MatchL(const TDesC& aPhoneNumber) |
|
1195 |
{ |
|
1196 |
InitMatchingL(); |
|
1197 |
||
85
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1198 |
// The client might be using CVPbkPhoneNumberMatchStrategy::EVPbkBestMatchingFlag |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1199 |
// flag, therefore the special chars could not be stripped off from the number |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1200 |
// The flag is not supported yet, therefore we need to strip off the special chars |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1201 |
HBufC* numberBuf = HBufC::NewL( aPhoneNumber.Length() ); |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1202 |
CleanupStack::PushL( numberBuf ); |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1203 |
TPtr number = numberBuf->Des(); |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1204 |
if ( iImpl->GetParser() ) |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1205 |
{ |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1206 |
iImpl->GetParser()->ExtractRawNumber( aPhoneNumber, number ); |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1207 |
} |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1208 |
else |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1209 |
{ |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1210 |
number.Copy( aPhoneNumber ); |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1211 |
} |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1212 |
|
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1213 |
iImpl->MatchL(number); |
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1214 |
|
38bb213f60ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
68
diff
changeset
|
1215 |
CleanupStack::PopAndDestroy(); // numberBuf |
63 | 1216 |
} |
1217 |
||
1218 |
void CVPbkPhoneNumberMatchStrategy::BaseConstructL( |
|
1219 |
const TConfig& aConfig, |
|
1220 |
CVPbkContactManager& aContactManager, |
|
1221 |
MVPbkContactFindObserver& aObserver) |
|
1222 |
{ |
|
1223 |
iImpl = CVPbkPhoneNumberMatchStrategyImpl::NewL( |
|
1224 |
*this, aConfig, aContactManager, aObserver); |
|
1225 |
} |
|
1226 |
||
1227 |
MVPbkContactFindObserver& CVPbkPhoneNumberMatchStrategy::FindObserver() const |
|
1228 |
{ |
|
1229 |
return *iImpl; |
|
1230 |
} |
|
1231 |
||
1232 |
TInt CVPbkPhoneNumberMatchStrategy::MaxMatchDigits() const |
|
1233 |
{ |
|
1234 |
return iImpl->MaxMatchDigits(); |
|
1235 |
} |
|
1236 |
||
1237 |
TArray<MVPbkContactStore*> CVPbkPhoneNumberMatchStrategy::StoresToMatch() const |
|
1238 |
{ |
|
1239 |
return iImpl->StoresToMatch(); |
|
1240 |
} |
|
1241 |
||
1242 |
TBool CVPbkPhoneNumberMatchStrategy::IsSimStore( const MVPbkContactStore& aStore ) |
|
1243 |
{ |
|
1244 |
return iImpl->IsSimStore( aStore ); |
|
1245 |
} |
|
1246 |
// End of File |