62
|
1 |
/*
|
|
2 |
* Copyright (c) 2006-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: Contact matching strategy
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <CVPbkContactManager.h>
|
|
20 |
#include <CVPbkContactStoreUriArray.h>
|
|
21 |
#include <cntdb.h> // KBestMatchingPhoneNumbers
|
|
22 |
|
|
23 |
#include "cphcntcontactmatchstrategy.h"
|
|
24 |
#include "cphcntcontactstoreuris.h"
|
|
25 |
#include "CPhoneRawMatchNumberExtractor.h"
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
// ======== MEMBER FUNCTIONS ========
|
|
31 |
|
|
32 |
|
|
33 |
CPhCntContactMatchStrategy::CPhCntContactMatchStrategy(
|
|
34 |
CVPbkContactManager& aContactManager,
|
|
35 |
CPhCntContactStoreUris& aContactStoreUris,
|
|
36 |
MVPbkContactFindObserver& aObserver,
|
|
37 |
TUint32 aMatchFlags ) :
|
|
38 |
iContactManager( aContactManager ),
|
|
39 |
iContactStoreUris( aContactStoreUris ),
|
|
40 |
iObserver( aObserver ),
|
|
41 |
iMatchFlags( aMatchFlags )
|
|
42 |
{
|
|
43 |
iContactStoreUris.SetObserver( *this );
|
|
44 |
}
|
|
45 |
|
|
46 |
|
|
47 |
// ---------------------------------------------------------------------------
|
|
48 |
// Second phase constructor
|
|
49 |
// ---------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
void CPhCntContactMatchStrategy::ConstructL()
|
|
52 |
{
|
|
53 |
User::LeaveIfError( CreateContactMatchStrategy() );
|
|
54 |
|
|
55 |
iNumberExtractor = new( ELeave )CCntRawPhoneNumberExtractor();
|
|
56 |
iNumberExtractor->ConstructL();
|
|
57 |
}
|
|
58 |
|
|
59 |
|
|
60 |
// ---------------------------------------------------------------------------
|
|
61 |
// Static constructor.
|
|
62 |
// ---------------------------------------------------------------------------
|
|
63 |
//
|
|
64 |
CPhCntContactMatchStrategy* CPhCntContactMatchStrategy::NewL(
|
|
65 |
CVPbkContactManager& aContactManager,
|
|
66 |
CPhCntContactStoreUris& aContactStoreUris,
|
|
67 |
MVPbkContactFindObserver& aObserver,
|
|
68 |
TUint32 aMatchFlags )
|
|
69 |
{
|
|
70 |
CPhCntContactMatchStrategy* self =
|
|
71 |
new( ELeave ) CPhCntContactMatchStrategy(
|
|
72 |
aContactManager,
|
|
73 |
aContactStoreUris,
|
|
74 |
aObserver,
|
|
75 |
aMatchFlags );
|
|
76 |
CleanupStack::PushL( self );
|
|
77 |
self->ConstructL();
|
|
78 |
CleanupStack::Pop( self );
|
|
79 |
return self;
|
|
80 |
}
|
|
81 |
|
|
82 |
// ---------------------------------------------------------------------------
|
|
83 |
// Destructor.
|
|
84 |
// ---------------------------------------------------------------------------
|
|
85 |
//
|
|
86 |
CPhCntContactMatchStrategy::~CPhCntContactMatchStrategy()
|
|
87 |
{
|
|
88 |
if( iNumberExtractor )
|
|
89 |
{
|
|
90 |
iNumberExtractor->Release();
|
|
91 |
}
|
|
92 |
delete iMatchStrategy;
|
|
93 |
delete iUriArray;
|
|
94 |
}
|
|
95 |
|
|
96 |
// ---------------------------------------------------------------------------
|
|
97 |
// From MPhCntContactMatchStrategy
|
|
98 |
// Starts to find contacts which has aPhoneNumber.
|
|
99 |
// ---------------------------------------------------------------------------
|
|
100 |
//
|
|
101 |
void CPhCntContactMatchStrategy::FindMatchesL( const TDesC& aPhoneNumber )
|
|
102 |
{
|
|
103 |
if( iMatchStrategy )
|
|
104 |
{
|
|
105 |
DoMatchL( aPhoneNumber );
|
|
106 |
}
|
|
107 |
else
|
|
108 |
{
|
|
109 |
const TInt err( CreateContactMatchStrategy() );
|
|
110 |
if( !err )
|
|
111 |
{
|
|
112 |
DoMatchL( aPhoneNumber );
|
|
113 |
}
|
|
114 |
else
|
|
115 |
{
|
|
116 |
User::Leave( KErrNotFound );
|
|
117 |
}
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
// ---------------------------------------------------------------------------
|
|
122 |
// Creates contact match strategy and destroys the old one.
|
|
123 |
// ---------------------------------------------------------------------------
|
|
124 |
//
|
|
125 |
TInt CPhCntContactMatchStrategy::CreateContactMatchStrategy()
|
|
126 |
{
|
|
127 |
TInt err = KErrNone;
|
|
128 |
if( !iUriArray )
|
|
129 |
{
|
|
130 |
TRAP( err, iUriArray = iContactStoreUris.ActiveContactStoresL() );
|
|
131 |
}
|
|
132 |
|
|
133 |
if( iUriArray )
|
|
134 |
{
|
|
135 |
delete iMatchStrategy;
|
|
136 |
iMatchStrategy = NULL;
|
|
137 |
err = DoCreateMatchStrategy();
|
|
138 |
|
|
139 |
}
|
|
140 |
else
|
|
141 |
{
|
|
142 |
err = KErrGeneral;
|
|
143 |
}
|
|
144 |
|
|
145 |
return err;
|
|
146 |
}
|
|
147 |
|
|
148 |
// ---------------------------------------------------------------------------
|
|
149 |
// From base class MPhCntContactStoreEventObserver
|
|
150 |
// Updates match strategy.
|
|
151 |
// ---------------------------------------------------------------------------
|
|
152 |
//
|
|
153 |
void CPhCntContactMatchStrategy::ContactStoreAvailabilityChanged()
|
|
154 |
{
|
|
155 |
delete iUriArray;
|
|
156 |
iUriArray = NULL;
|
|
157 |
CreateContactMatchStrategy();
|
|
158 |
}
|
|
159 |
|
|
160 |
// ---------------------------------------------------------------------------
|
|
161 |
// Creates contact match strategy
|
|
162 |
// ---------------------------------------------------------------------------
|
|
163 |
//
|
|
164 |
TInt CPhCntContactMatchStrategy::DoCreateMatchStrategy()
|
|
165 |
{
|
|
166 |
CVPbkPhoneNumberMatchStrategy::TConfig config(
|
|
167 |
KBestMatchingPhoneNumbers,
|
|
168 |
*iUriArray,
|
|
169 |
CVPbkPhoneNumberMatchStrategy::EVPbkSequentialMatch,
|
|
170 |
iMatchFlags
|
|
171 |
);
|
|
172 |
TRAPD( err, iMatchStrategy = CVPbkPhoneNumberMatchStrategy::NewL(
|
|
173 |
config,
|
|
174 |
iContactManager,
|
|
175 |
iObserver ) );
|
|
176 |
return err;
|
|
177 |
}
|
|
178 |
|
|
179 |
// ---------------------------------------------------------------------------
|
|
180 |
// Makes the actual matching request.
|
|
181 |
// ---------------------------------------------------------------------------
|
|
182 |
//
|
|
183 |
void CPhCntContactMatchStrategy::DoMatchL(
|
|
184 |
const TDesC& aNumber )
|
|
185 |
{
|
|
186 |
iMatchStrategy->MatchL( aNumber );
|
|
187 |
}
|