|
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 <centralrepository.h> |
|
21 #include <telconfigcrkeys.h> |
|
22 #include <CVPbkContactStoreUriArray.h> |
|
23 |
|
24 #include "cphcntcontactmatchstrategy.h" |
|
25 #include "cphcntcontactstoreuris.h" |
|
26 #include "CPhoneRawMatchNumberExtractor.h" |
|
27 |
|
28 // Digit count used to match CS number. |
|
29 const TInt KPhCntMatchMin = 7; |
|
30 const TInt KPhCntMatchMax = 11; |
|
31 const TInt KPhCntMatchDefault = KPhCntMatchMin; |
|
32 |
|
33 // ======== MEMBER FUNCTIONS ======== |
|
34 |
|
35 |
|
36 CPhCntContactMatchStrategy::CPhCntContactMatchStrategy( |
|
37 CVPbkContactManager& aContactManager, |
|
38 CPhCntContactStoreUris& aContactStoreUris, |
|
39 MVPbkContactFindObserver& aObserver, |
|
40 CVPbkPhoneNumberMatchStrategy::TVPbkPhoneNumberMatchFlags aMatchFlag ) : |
|
41 iContactManager( aContactManager ), |
|
42 iContactStoreUris( aContactStoreUris ), |
|
43 iObserver( aObserver ), |
|
44 iMatchFlag( aMatchFlag ) |
|
45 { |
|
46 iContactStoreUris.SetObserver( *this ); |
|
47 } |
|
48 |
|
49 |
|
50 // --------------------------------------------------------------------------- |
|
51 // Second phase constructor |
|
52 // --------------------------------------------------------------------------- |
|
53 // |
|
54 void CPhCntContactMatchStrategy::ConstructL() |
|
55 { |
|
56 iCenRepSession = CRepository::NewL( KCRUidTelConfiguration ); |
|
57 iCenRepNotifyHandler = |
|
58 CCenRepNotifyHandler::NewL( |
|
59 *this, |
|
60 *iCenRepSession, |
|
61 CCenRepNotifyHandler::EIntKey, |
|
62 KTelMatchDigits ); |
|
63 |
|
64 iCenRepNotifyHandler->StartListeningL(); |
|
65 |
|
66 iNumberOfDigits = KPhCntMatchDefault; |
|
67 TInt sdMatchValue = KErrNotFound; |
|
68 |
|
69 // Find digit count to be used with matching. |
|
70 if ( iCenRepSession->Get( KTelMatchDigits, sdMatchValue ) |
|
71 == KErrNone ) |
|
72 { |
|
73 // If we can find a proper value from the cenrep, use it. |
|
74 if ( sdMatchValue >= KPhCntMatchMin && sdMatchValue <= KPhCntMatchMax ) |
|
75 { |
|
76 iNumberOfDigits = sdMatchValue; |
|
77 } |
|
78 } |
|
79 User::LeaveIfError( CreateContactMatchStrategy() ); |
|
80 |
|
81 iNumberExtractor = new( ELeave )CCntRawPhoneNumberExtractor(); |
|
82 iNumberExtractor->ConstructL(); |
|
83 } |
|
84 |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // Static constructor. |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 CPhCntContactMatchStrategy* CPhCntContactMatchStrategy::NewL( |
|
91 CVPbkContactManager& aContactManager, |
|
92 CPhCntContactStoreUris& aContactStoreUris, |
|
93 MVPbkContactFindObserver& aObserver, |
|
94 CVPbkPhoneNumberMatchStrategy::TVPbkPhoneNumberMatchFlags aMatchFlag ) |
|
95 { |
|
96 CPhCntContactMatchStrategy* self = |
|
97 new( ELeave ) CPhCntContactMatchStrategy( |
|
98 aContactManager, |
|
99 aContactStoreUris, |
|
100 aObserver, |
|
101 aMatchFlag ); |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL(); |
|
104 CleanupStack::Pop( self ); |
|
105 return self; |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // Destructor. |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 CPhCntContactMatchStrategy::~CPhCntContactMatchStrategy() |
|
113 { |
|
114 if( iNumberExtractor ) |
|
115 { |
|
116 iNumberExtractor->Release(); |
|
117 } |
|
118 |
|
119 if( iCenRepNotifyHandler ) |
|
120 { |
|
121 iCenRepNotifyHandler->StopListening(); |
|
122 } |
|
123 delete iCenRepNotifyHandler; |
|
124 delete iCenRepSession; |
|
125 delete iMatchStrategy; |
|
126 delete iUriArray; |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // From MPhCntContactMatchStrategy |
|
131 // Starts to find contacts which has aPhoneNumber. |
|
132 // --------------------------------------------------------------------------- |
|
133 // |
|
134 void CPhCntContactMatchStrategy::FindMatchesL( const TDesC& aPhoneNumber ) |
|
135 { |
|
136 if( iMatchStrategy ) |
|
137 { |
|
138 MatchL( aPhoneNumber ); |
|
139 } |
|
140 else |
|
141 { |
|
142 const TInt err( CreateContactMatchStrategy() ); |
|
143 if( !err ) |
|
144 { |
|
145 MatchL( aPhoneNumber ); |
|
146 } |
|
147 else |
|
148 { |
|
149 User::Leave( KErrNotFound ); |
|
150 } |
|
151 } |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // Creates contact match strategy and destroys the old one. |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 TInt CPhCntContactMatchStrategy::CreateContactMatchStrategy() |
|
159 { |
|
160 TInt err = KErrNone; |
|
161 if( !iUriArray ) |
|
162 { |
|
163 TRAP( err, iUriArray = iContactStoreUris.ActiveContactStoresL() ); |
|
164 } |
|
165 |
|
166 if( iUriArray ) |
|
167 { |
|
168 delete iMatchStrategy; |
|
169 iMatchStrategy = NULL; |
|
170 err = DoCreateMatchStrategy(); |
|
171 |
|
172 } |
|
173 else |
|
174 { |
|
175 err = KErrGeneral; |
|
176 } |
|
177 |
|
178 return err; |
|
179 } |
|
180 |
|
181 // --------------------------------------------------------------------------- |
|
182 // From base class MCenRepNotifyHandlerCallback |
|
183 // Notification from CenRep |
|
184 // --------------------------------------------------------------------------- |
|
185 // |
|
186 void CPhCntContactMatchStrategy::HandleNotifyString( |
|
187 TUint32 aUid, |
|
188 const TDesC16& aValue ) |
|
189 { |
|
190 if ( aUid == KTelMatchDigits ) |
|
191 { |
|
192 TLex lexer( aValue ); |
|
193 TInt value; |
|
194 const TInt err( lexer.Val( value ) ); |
|
195 |
|
196 if( !err ) |
|
197 { |
|
198 if ( value < KPhCntMatchMin || value > KPhCntMatchMax ) |
|
199 { |
|
200 iNumberOfDigits = KPhCntMatchDefault; |
|
201 } |
|
202 else |
|
203 { |
|
204 iNumberOfDigits = value; |
|
205 } |
|
206 CreateContactMatchStrategy(); |
|
207 } |
|
208 |
|
209 } |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // From base class MPhCntContactStoreEventObserver |
|
214 // Updates match strategy. |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void CPhCntContactMatchStrategy::ContactStoreAvailabilityChanged() |
|
218 { |
|
219 delete iUriArray; |
|
220 iUriArray = NULL; |
|
221 CreateContactMatchStrategy(); |
|
222 } |
|
223 |
|
224 // --------------------------------------------------------------------------- |
|
225 // Removes extra characters from number and matches with raw number. |
|
226 // --------------------------------------------------------------------------- |
|
227 // |
|
228 void CPhCntContactMatchStrategy::MatchL( |
|
229 const TDesC& aPhoneNumber ) |
|
230 { |
|
231 HBufC* rawNumber = HBufC::NewLC( aPhoneNumber.Length() ); |
|
232 TPtr rawNumberPtr = rawNumber->Des(); |
|
233 iNumberExtractor->ExtractRawNumber( aPhoneNumber, rawNumberPtr ); |
|
234 DoMatchL( *rawNumber ); |
|
235 CleanupStack::PopAndDestroy( rawNumber ); |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------------------------- |
|
239 // Creates contact match strategy |
|
240 // --------------------------------------------------------------------------- |
|
241 // |
|
242 TInt CPhCntContactMatchStrategy::DoCreateMatchStrategy() |
|
243 { |
|
244 CVPbkPhoneNumberMatchStrategy::TConfig config( |
|
245 iNumberOfDigits, |
|
246 *iUriArray, |
|
247 CVPbkPhoneNumberMatchStrategy::EVPbkSequentialMatch, |
|
248 iMatchFlag |
|
249 ); |
|
250 TRAPD( err, iMatchStrategy = CVPbkPhoneNumberMatchStrategy::NewL( |
|
251 config, |
|
252 iContactManager, |
|
253 iObserver ) ); |
|
254 return err; |
|
255 } |
|
256 |
|
257 // --------------------------------------------------------------------------- |
|
258 // Makes the actual matching request. |
|
259 // --------------------------------------------------------------------------- |
|
260 // |
|
261 void CPhCntContactMatchStrategy::DoMatchL( |
|
262 const TDesC& aNumber ) |
|
263 { |
|
264 iMatchStrategy->MatchL( aNumber ); |
|
265 } |