|
1 /* |
|
2 * Copyright (c) 2007-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: Wrapper for CMS contact fetching |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ccapputilheaders.h" |
|
20 |
|
21 // ======== MEMBER FUNCTIONS ======== |
|
22 |
|
23 // -------------------------------------------------------------------------- |
|
24 // CCCAppCmsContactFetcherWrapper::CCCAppCmsContactFetcherWrapper |
|
25 // -------------------------------------------------------------------------- |
|
26 // |
|
27 CCCAppCmsContactFetcherWrapper::CCCAppCmsContactFetcherWrapper( |
|
28 CCCAParameter* aParameter, TWrapperParam aWrapperParam ): |
|
29 CActive( EPriorityStandard ), |
|
30 iParameter( aParameter ), |
|
31 iHandlerState( EInitial ), |
|
32 iErrorsOccured( KErrNone ), |
|
33 iRefCount( 1 ), |
|
34 iWrapperParam( aWrapperParam ) |
|
35 { |
|
36 CCA_DP(KCCAppUtilLogFile, CCA_L("CCCAppCmsContactFetcherWrapper()")); |
|
37 CActiveScheduler::Add( this ); |
|
38 } |
|
39 |
|
40 // -------------------------------------------------------------------------- |
|
41 // CCCAppCmsContactFetcherWrapper::~CCCAppCmsContactFetcherWrapper |
|
42 // -------------------------------------------------------------------------- |
|
43 // |
|
44 CCCAppCmsContactFetcherWrapper::~CCCAppCmsContactFetcherWrapper() |
|
45 { |
|
46 CCA_DP(KCCAppUtilLogFile, CCA_L("~CCCAppCmsContactFetcherWrapper()")); |
|
47 Cancel(); |
|
48 iCmsContactDataFetcher.Close(); |
|
49 iCmsSession.Close(); |
|
50 iContactFieldsArray.ResetAndDestroy(); |
|
51 iContactFieldsArray.Close(); |
|
52 iObservers.Close(); |
|
53 delete iContactInfo; |
|
54 //iParameter, iObservers taken care elsewhere |
|
55 } |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CCCAppCmsContactFetcherWrapper::Release() |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 EXPORT_C void CCCAppCmsContactFetcherWrapper::Release() |
|
62 { |
|
63 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::Release")); |
|
64 |
|
65 TAny* tlsPtr = Dll::Tls(); |
|
66 |
|
67 CCCAppCmsContactFetcherWrapper* self = static_cast<CCCAppCmsContactFetcherWrapper*>( tlsPtr ); |
|
68 if ( 0 == --self->iRefCount ) |
|
69 { |
|
70 CCA_DP(KCCAppUtilLogFile, CCA_L("::Release - last instance, will be deleted")); |
|
71 Dll::FreeTls(); |
|
72 delete self; |
|
73 } |
|
74 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::Release")); |
|
75 } |
|
76 |
|
77 // -------------------------------------------------------------------------- |
|
78 // CCCAppCmsContactFetcherWrapper::CreateInstanceL |
|
79 // -------------------------------------------------------------------------- |
|
80 // |
|
81 EXPORT_C CCCAppCmsContactFetcherWrapper* CCCAppCmsContactFetcherWrapper::CreateInstanceL( |
|
82 CCCAParameter* aParameter, TWrapperParam aWrapperParam ) |
|
83 { |
|
84 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::CreateInstanceL")); |
|
85 |
|
86 CCCAppCmsContactFetcherWrapper* self = NULL; |
|
87 TAny* tlsPtr = Dll::Tls(); |
|
88 if ( NULL == tlsPtr ) |
|
89 { |
|
90 CCA_DP(KCCAppUtilLogFile, CCA_L("::CreateInstanceL - not found, create new")); |
|
91 self = new( ELeave ) CCCAppCmsContactFetcherWrapper( aParameter, aWrapperParam ); |
|
92 CleanupStack::PushL( self ); |
|
93 self->ConstructL( ); |
|
94 User::LeaveIfError( Dll::SetTls( self ) ); |
|
95 CleanupStack::Pop( self ); |
|
96 } |
|
97 else |
|
98 { |
|
99 CCA_DP(KCCAppUtilLogFile, CCA_L("::CreateInstanceL - already existing")); |
|
100 User::Leave( KErrAlreadyExists ); |
|
101 } |
|
102 |
|
103 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::CreateInstanceL")); |
|
104 return self; |
|
105 } |
|
106 |
|
107 // -------------------------------------------------------------------------- |
|
108 // CCCAppCmsContactFetcherWrapper::ConstructL |
|
109 // -------------------------------------------------------------------------- |
|
110 // |
|
111 void CCCAppCmsContactFetcherWrapper::ConstructL() |
|
112 { |
|
113 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::ConstructL()")); |
|
114 |
|
115 // The setting of default number is disabled when opening CCA for better performance |
|
116 TRAPD( err, StartFetcherL( EFalse )); |
|
117 // problem can either be with connecting to CMS or with opening the contact |
|
118 iErrorsOccured = err; |
|
119 |
|
120 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::ConstructL()")); |
|
121 } |
|
122 |
|
123 // -------------------------------------------------------------------------- |
|
124 // CCCAppCmsContactFetcherWrapper::InstanceL |
|
125 // -------------------------------------------------------------------------- |
|
126 // |
|
127 EXPORT_C CCCAppCmsContactFetcherWrapper* CCCAppCmsContactFetcherWrapper::InstanceL() |
|
128 { |
|
129 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::InstanceL()")); |
|
130 |
|
131 CCCAppCmsContactFetcherWrapper* self = NULL; |
|
132 TAny* tlsPtr = Dll::Tls(); |
|
133 if ( NULL == tlsPtr ) |
|
134 { |
|
135 CCA_DP(KCCAppUtilLogFile, CCA_L("::HandleL() - singleton not created yet!")); |
|
136 User::Leave( KErrNotFound ); |
|
137 } |
|
138 else |
|
139 { |
|
140 self = static_cast<CCCAppCmsContactFetcherWrapper*>( tlsPtr ); |
|
141 ++self->iRefCount; |
|
142 } |
|
143 |
|
144 CCA_DP(KCCAppUtilLogFile, CCA_L("::InstanceL - iRefCount: %d"), self->iRefCount ); |
|
145 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::InstanceL()")); |
|
146 return self; |
|
147 } |
|
148 |
|
149 // -------------------------------------------------------------------------- |
|
150 // CCCAppCmsContactFetcherWrapper::StartFetcherL |
|
151 // -------------------------------------------------------------------------- |
|
152 // |
|
153 void CCCAppCmsContactFetcherWrapper::StartFetcherL( TBool aSetDefault ) |
|
154 { |
|
155 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::StartFetcherL()")); |
|
156 User::LeaveIfError( iCmsSession.Connect() ); |
|
157 |
|
158 OpenContactL(); |
|
159 |
|
160 if ( aSetDefault ) |
|
161 { |
|
162 SetDefaultForVoiceCallL(); |
|
163 } |
|
164 else |
|
165 { |
|
166 StartAsyncFetchingL(); |
|
167 } |
|
168 |
|
169 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::StartFetcherL()")); |
|
170 } |
|
171 |
|
172 // -------------------------------------------------------------------------- |
|
173 // CCCAppCmsContactFetcherWrapper::StartAsyncFetchingL |
|
174 // -------------------------------------------------------------------------- |
|
175 // |
|
176 void CCCAppCmsContactFetcherWrapper::StartAsyncFetchingL() |
|
177 { |
|
178 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::StartAsyncFetchingL()")); |
|
179 |
|
180 if ( iWrapperParam & EFindContactFromOtherStores ) |
|
181 FindFromOtherStoresL(); |
|
182 else |
|
183 FetchContactInfoL(); |
|
184 |
|
185 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::StartAsyncFetchingL()")); |
|
186 } |
|
187 |
|
188 // -------------------------------------------------------------------------- |
|
189 // CCCAppCmsContactFetcherWrapper::AddObserverL |
|
190 // -------------------------------------------------------------------------- |
|
191 // |
|
192 EXPORT_C void CCCAppCmsContactFetcherWrapper::AddObserverL( |
|
193 MCCAppContactFieldDataObserver& aObserver ) |
|
194 { |
|
195 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::AddObserverL()")); |
|
196 const TInt index = iObservers.Find( &aObserver ); |
|
197 if ( KErrNotFound == index ) |
|
198 { |
|
199 iObservers.AppendL( &aObserver ); |
|
200 } |
|
201 |
|
202 if ( iErrorsOccured ) |
|
203 {// errors happened already |
|
204 aObserver.ContactFieldDataObserverHandleErrorL( |
|
205 iHandlerState, iErrorsOccured ); |
|
206 } |
|
207 |
|
208 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::AddObserverL()")); |
|
209 } |
|
210 |
|
211 // -------------------------------------------------------------------------- |
|
212 // CCCAppCmsContactFetcherWrapper::RemoveObserver |
|
213 // -------------------------------------------------------------------------- |
|
214 // |
|
215 EXPORT_C void CCCAppCmsContactFetcherWrapper::RemoveObserver( |
|
216 MCCAppContactFieldDataObserver& aObserver ) |
|
217 { |
|
218 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::RemoveObserverL()")); |
|
219 CCA_DP(KCCAppUtilLogFile, CCA_L("::RemoveObserverL - amount of observers: %d"), iObservers.Count() ); |
|
220 const TInt index = iObservers.Find( &aObserver ); |
|
221 if ( KErrNotFound != index ) |
|
222 { |
|
223 iObservers.Remove( index ); |
|
224 CCA_DP( KCCAppUtilLogFile, CCA_L("::RemoveObserverL - observer found & removed: %d"), index ); |
|
225 } |
|
226 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::RemoveObserverL()")); |
|
227 } |
|
228 |
|
229 // -------------------------------------------------------------------------- |
|
230 // CCCAppCmsContactFetcherWrapper::IsServiceAvailable |
|
231 // -------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C TInt CCCAppCmsContactFetcherWrapper::IsServiceAvailable( |
|
234 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aContactAction ) |
|
235 { |
|
236 return iCmsContactDataFetcher.IsServiceAvailable( aContactAction ); |
|
237 } |
|
238 |
|
239 // -------------------------------------------------------------------------- |
|
240 // CCCAppCmsContactFetcherWrapper::ContactStore |
|
241 // -------------------------------------------------------------------------- |
|
242 // |
|
243 EXPORT_C TCmsContactStore CCCAppCmsContactFetcherWrapper::ContactStore() const |
|
244 { |
|
245 return iCmsContactDataFetcher.ContactStore(); |
|
246 } |
|
247 |
|
248 // -------------------------------------------------------------------------- |
|
249 // CCCAppCmsContactFetcherWrapper::GetContactActionFieldCount |
|
250 // -------------------------------------------------------------------------- |
|
251 // |
|
252 EXPORT_C TInt CCCAppCmsContactFetcherWrapper::GetContactActionFieldCount( |
|
253 VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aContactAction) |
|
254 { |
|
255 return iCmsContactDataFetcher.GetContactActionFieldCount(aContactAction); |
|
256 } |
|
257 |
|
258 // -------------------------------------------------------------------------- |
|
259 // CCCAppCmsContactFetcherWrapper::OpenContactL |
|
260 // -------------------------------------------------------------------------- |
|
261 // |
|
262 void CCCAppCmsContactFetcherWrapper::OpenContactL() |
|
263 { |
|
264 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::OpenContactL()")); |
|
265 iHandlerState = EOpeningContact; |
|
266 switch( iParameter->ContactDataFlag()) |
|
267 { |
|
268 case MCCAParameter::EContactId: |
|
269 { |
|
270 CCA_DP(KCCAppUtilLogFile, CCA_L("::OpenContactL() EContactId")); |
|
271 User::LeaveIfError( iCmsContactDataFetcher.Open( |
|
272 iCmsSession, iParameter->ContactIdL())); |
|
273 } |
|
274 break; |
|
275 case MCCAParameter::EContactLink: |
|
276 { |
|
277 CCA_DP(KCCAppUtilLogFile, CCA_L("::OpenContactL() EContactLink")); |
|
278 HBufC8* contactlink = iParameter->ContactLinkL(); |
|
279 CleanupStack::PushL( contactlink ); |
|
280 User::LeaveIfError( iCmsContactDataFetcher.Open( |
|
281 iCmsSession, *contactlink)); |
|
282 CleanupStack::PopAndDestroy( contactlink ); |
|
283 } |
|
284 break; |
|
285 case MCCAParameter::EContactMSISDN: |
|
286 { |
|
287 CCA_DP(KCCAppUtilLogFile, CCA_L("::OpenContactL() EContactMSISDN")); |
|
288 User::LeaveIfError( iCmsContactDataFetcher.Open( |
|
289 iCmsSession, iParameter->ContactDataL())); |
|
290 } |
|
291 break; |
|
292 //case MCCAParameter::EContactEmail:// fallthrough |
|
293 default: |
|
294 { |
|
295 CCA_DP(KCCAppUtilLogFile, CCA_L("::OpenContactL() unknown type, will leave..")); |
|
296 User::Leave( KErrNotSupported ); |
|
297 } |
|
298 break; |
|
299 } |
|
300 iCmsContactDataFetcher.OrderNotificationsL(this, CCmsContactFieldItem::ECmsPhonebookNotification); |
|
301 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::OpenContactL()")); |
|
302 } |
|
303 |
|
304 // -------------------------------------------------------------------------- |
|
305 // CCCAppCmsContactFetcherWrapper::RunL |
|
306 // -------------------------------------------------------------------------- |
|
307 // |
|
308 void CCCAppCmsContactFetcherWrapper::RunL() |
|
309 { |
|
310 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::RunL()")); |
|
311 CCA_DP(KCCAppUtilLogFile, CCA_L("::RunL: iStatus: %d"), iStatus.Int() ); |
|
312 |
|
313 switch( iHandlerState ) |
|
314 { |
|
315 case ESettingVoiceCallDefault: |
|
316 { |
|
317 CCA_DP(KCCAppUtilLogFile, CCA_L("::RunL() iHandlerState == ESettingVoiceCallDefault")); |
|
318 StartAsyncFetchingL(); |
|
319 CCA_DP(KCCAppUtilLogFile, CCA_L("::RunL() ESettingVoiceCallDefault completed")); |
|
320 } |
|
321 break; |
|
322 case EFindingFromOtherStores: |
|
323 { |
|
324 CCA_DP(KCCAppUtilLogFile, CCA_L("::RunL() iHandlerState == EFindingFromOtherStores")); |
|
325 FetchContactInfoL(); |
|
326 CCA_DP(KCCAppUtilLogFile, CCA_L("::RunL() EFindingFromOtherStores completed")); |
|
327 } |
|
328 break; |
|
329 case ELoadingEnabledFields: |
|
330 { |
|
331 CCA_DP(KCCAppUtilLogFile, CCA_L("::RunL() iHandlerState == ELoadingEnabledFields")); |
|
332 HandleContactInfoUpdateL(); |
|
333 CCA_DP(KCCAppUtilLogFile, CCA_L("::RunL() ELoadingEnabledFields completed")); |
|
334 } |
|
335 break; |
|
336 case ELoadingFields: |
|
337 { |
|
338 CCA_DP(KCCAppUtilLogFile, CCA_L("::RunL() iHandlerState == ELoadingField")); |
|
339 HandleContactDataFieldUpdateL(); |
|
340 CCA_DP(KCCAppUtilLogFile, CCA_L("::RunL() ELoadingField completed")); |
|
341 } |
|
342 break; |
|
343 default: |
|
344 { |
|
345 // error situation - should not come here |
|
346 CCA_DP(KCCAppUtilLogFile, CCA_L("::RunL() iHandlerState not found, will leave..")); |
|
347 // error notification done in RunError |
|
348 User::Leave( KErrGeneral ); |
|
349 } |
|
350 break; |
|
351 } |
|
352 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::RunL()")); |
|
353 } |
|
354 |
|
355 // -------------------------------------------------------------------------- |
|
356 // CCCAppCmsContactFetcherWrapper::RunError |
|
357 // -------------------------------------------------------------------------- |
|
358 // |
|
359 TInt CCCAppCmsContactFetcherWrapper::RunError( TInt aError ) |
|
360 { |
|
361 CCA_DP(KCCAppUtilLogFile, CCA_L("CCCAppCmsContactFetcherWrapper::RunError: aError: %d"), aError ); |
|
362 iErrorsOccured = aError; |
|
363 TRAP_IGNORE( NotifyErrorL() ); |
|
364 return KErrNone; |
|
365 } |
|
366 |
|
367 // -------------------------------------------------------------------------- |
|
368 // CCCAppCmsContactFetcherWrapper::NotifyErrorL |
|
369 // -------------------------------------------------------------------------- |
|
370 // |
|
371 void CCCAppCmsContactFetcherWrapper::NotifyErrorL() |
|
372 { |
|
373 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::NotifyErrorL()")); |
|
374 const TInt count = iObservers.Count(); |
|
375 CCA_DP( KCCAppUtilLogFile, CCA_L("::NotifyErrorL - amount of observers: %d"), count ); |
|
376 for ( TInt i = 0; i < count; i++ ) |
|
377 { |
|
378 TRAP_IGNORE( iObservers[ i ]->ContactFieldDataObserverHandleErrorL( |
|
379 iHandlerState, iErrorsOccured )); |
|
380 } |
|
381 |
|
382 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::NotifyErrorL()")); |
|
383 } |
|
384 // -------------------------------------------------------------------------- |
|
385 // CCCAppCmsContactFetcherWrapper::SetDefaultForVoiceCallL |
|
386 // -------------------------------------------------------------------------- |
|
387 // |
|
388 void CCCAppCmsContactFetcherWrapper::SetDefaultForVoiceCallL() |
|
389 { |
|
390 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::SetDefaultForVoiceCallL()")); |
|
391 |
|
392 iHandlerState = ESettingVoiceCallDefault; |
|
393 iStatus = KRequestPending; |
|
394 |
|
395 iCmsContactDataFetcher.SetVoiceCallDefault( iStatus ); |
|
396 SetActive(); |
|
397 |
|
398 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::SetDefaultForVoiceCallL()")); |
|
399 } |
|
400 // -------------------------------------------------------------------------- |
|
401 // CCCAppCmsContactFetcherWrapper::DoCancel |
|
402 // -------------------------------------------------------------------------- |
|
403 // |
|
404 void CCCAppCmsContactFetcherWrapper::DoCancel() |
|
405 { |
|
406 if( IsActive() ) |
|
407 {// CMS Client doesn't know the operation to be cancelled |
|
408 if ( EFindingFromOtherStores == iHandlerState ) |
|
409 { |
|
410 iCmsContactDataFetcher.CancelExternalContactFind(); |
|
411 } |
|
412 else if ( ELoadingEnabledFields == iHandlerState && iContactInfo ) |
|
413 { |
|
414 iCmsContactDataFetcher.Cancel( *iContactInfo ); |
|
415 delete iContactInfo; |
|
416 iContactInfo = NULL; |
|
417 } |
|
418 else if ( ELoadingFields == iHandlerState && iContactField ) |
|
419 { |
|
420 iCmsContactDataFetcher.Cancel( *iContactField ); |
|
421 delete iContactField; |
|
422 iContactField = NULL; |
|
423 } |
|
424 } |
|
425 } |
|
426 |
|
427 // -------------------------------------------------------------------------- |
|
428 // CCCAppCmsContactFetcherWrapper::FindFromOtherStoresL |
|
429 // -------------------------------------------------------------------------- |
|
430 // |
|
431 void CCCAppCmsContactFetcherWrapper::FindFromOtherStoresL() |
|
432 { |
|
433 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::FindFromOtherStoresL()")); |
|
434 |
|
435 iHandlerState = EFindingFromOtherStores; |
|
436 iStatus = KRequestPending; |
|
437 |
|
438 iCmsContactDataFetcher.FindExternalContact( iStatus ); |
|
439 SetActive(); |
|
440 |
|
441 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::FindFromOtherStoresL()")); |
|
442 }; |
|
443 |
|
444 // -------------------------------------------------------------------------- |
|
445 // CCCAppCmsContactFetcherWrapper::FetchContactInfoL |
|
446 // -------------------------------------------------------------------------- |
|
447 // |
|
448 void CCCAppCmsContactFetcherWrapper::FetchContactInfoL() |
|
449 { |
|
450 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::FetchEnabledFieldsL()")); |
|
451 |
|
452 iHandlerState = ELoadingEnabledFields; |
|
453 iStatus = KRequestPending; |
|
454 |
|
455 iContactInfo = iCmsContactDataFetcher.EnabledFieldsL( iStatus ); |
|
456 SetActive(); |
|
457 |
|
458 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::FetchEnabledFieldsL()")); |
|
459 }; |
|
460 |
|
461 // -------------------------------------------------------------------------- |
|
462 // CCCAppCmsContactFetcherWrapper::HandleContactInfoUpdateL |
|
463 // -------------------------------------------------------------------------- |
|
464 // |
|
465 void CCCAppCmsContactFetcherWrapper::HandleContactInfoUpdateL() |
|
466 { |
|
467 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::HandleContactInfoUpdateL()")); |
|
468 |
|
469 //error check |
|
470 const TInt err = iStatus.Int(); |
|
471 if ( KErrNone != err ) |
|
472 { |
|
473 // cleanup |
|
474 delete iContactInfo; |
|
475 iContactInfo = NULL; |
|
476 User::Leave( err ); |
|
477 } |
|
478 |
|
479 const TInt count = iObservers.Count(); |
|
480 CCA_DP( KCCAppUtilLogFile, CCA_L("::HandleContactInfoUpdateL - amount of observers: %d"), count ); |
|
481 MCCAppContactFieldDataObserver::TParameter param = MCCAppContactFieldDataObserver::TParameter(); |
|
482 param.iType = MCCAppContactFieldDataObserver::TParameter::EContactInfoAvailable; |
|
483 param.iContactInfo = iContactInfo; |
|
484 for ( TInt i = 0; i < count; i++ ) |
|
485 { |
|
486 TRAP_IGNORE( iObservers[ i ]->ContactFieldDataObserverNotifyL( param )); |
|
487 } |
|
488 |
|
489 iHandlerState = ELoadingFields; |
|
490 iContactDataFetchingIndex = 0; |
|
491 StartContactDataFieldFetchingL(); |
|
492 |
|
493 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::HandleContactInfoUpdateL()")); |
|
494 } |
|
495 |
|
496 // -------------------------------------------------------------------------- |
|
497 // CCCAppCmsContactFetcherWrapper::StartContactDataFieldFetchingL |
|
498 // -------------------------------------------------------------------------- |
|
499 // |
|
500 void CCCAppCmsContactFetcherWrapper::StartContactDataFieldFetchingL() |
|
501 { |
|
502 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::StartContactDataFieldFetchingL()")); |
|
503 TInt dataFieldCount = iContactInfo->Fields().Count(); |
|
504 CCA_DP(KCCAppUtilLogFile, CCA_L("::StartContactDataFieldFetchingL amount of fields to be fetched = %d"), dataFieldCount ); |
|
505 |
|
506 if ( dataFieldCount ) |
|
507 {// start fetching |
|
508 FetchContactDataFieldL(); |
|
509 } |
|
510 else |
|
511 {// nothing to fetch |
|
512 iHandlerState = EOperationsCompleted; |
|
513 //todo; do we need a error-callback to notify the error cases? |
|
514 } |
|
515 |
|
516 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::StartContactDataFieldFetchingL()")); |
|
517 } |
|
518 |
|
519 // -------------------------------------------------------------------------- |
|
520 // CCCAppCmsContactFetcherWrapper::FetchContactDataFieldL |
|
521 // -------------------------------------------------------------------------- |
|
522 // |
|
523 void CCCAppCmsContactFetcherWrapper::FetchContactDataFieldL() |
|
524 { |
|
525 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::FetchContactDataFieldL()")); |
|
526 iStatus = KRequestPending; |
|
527 |
|
528 const RArray<CCmsContactFieldItem::TCmsContactField>& enabledFields = |
|
529 iContactInfo->Fields();//not owned |
|
530 |
|
531 iContactField = NULL; |
|
532 iContactField = iCmsContactDataFetcher.FieldDataL( |
|
533 iStatus, enabledFields[ iContactDataFetchingIndex ]); |
|
534 |
|
535 SetActive(); |
|
536 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::FetchContactDataFieldL()")); |
|
537 } |
|
538 |
|
539 // -------------------------------------------------------------------------- |
|
540 // CCCAppCmsContactFetcherWrapper::HandleContactDataFieldUpdateL |
|
541 // -------------------------------------------------------------------------- |
|
542 // |
|
543 void CCCAppCmsContactFetcherWrapper::HandleContactDataFieldUpdateL() |
|
544 { |
|
545 CCA_DP(KCCAppUtilLogFile, CCA_L("->CCCAppCmsContactFetcherWrapper::HandleContactDataFieldUpdateL()")); |
|
546 CCA_DP(KCCAppUtilLogFile, CCA_L("::HandleContactDataFieldUpdateL fetched field type: %d"), (TInt)iContactField->Type() ); |
|
547 |
|
548 TBool moreToFetch = iContactDataFetchingIndex < iContactInfo->Fields().Count() - 1; |
|
549 |
|
550 // error check |
|
551 if ( KErrNone == iStatus.Int() ) |
|
552 {// update observers only if fetch was succesful |
|
553 iContactFieldsArray.AppendL( iContactField ); |
|
554 const TInt count = iObservers.Count(); |
|
555 CCA_DP( KCCAppUtilLogFile, CCA_L("::HandleContactDataFieldUpdateL - amount of observers: %d"), count ); |
|
556 |
|
557 MCCAppContactFieldDataObserver::TParameter param = MCCAppContactFieldDataObserver::TParameter(); |
|
558 param.iType = MCCAppContactFieldDataObserver::TParameter::EContactDataFieldAvailable; |
|
559 param.iContactField = iContactField; |
|
560 param.iStatusFlag = ( moreToFetch ? 0 : CCCAppCmsContactFetcherWrapper::EOperationsCompleted ); |
|
561 |
|
562 for ( TInt i = 0; i < count; i++ ) |
|
563 { |
|
564 TRAP_IGNORE( iObservers[ i ]->ContactFieldDataObserverNotifyL( param )); |
|
565 } |
|
566 } |
|
567 else |
|
568 {// ..otherwise cleanup |
|
569 delete iContactField; |
|
570 iContactField = NULL; |
|
571 // Notify error, but do not leave |
|
572 // since there might be other fetchable |
|
573 // fields.. |
|
574 TRAP_IGNORE( NotifyErrorL() ); |
|
575 } |
|
576 |
|
577 // more fields to fetch or all already fetched? |
|
578 if ( moreToFetch ) |
|
579 { |
|
580 CCA_DP(KCCAppUtilLogFile, CCA_L("::HandleContactDataFieldUpdateL() continue, fetch next field")); |
|
581 iContactDataFetchingIndex++; |
|
582 FetchContactDataFieldL(); |
|
583 } |
|
584 else |
|
585 { |
|
586 CCA_DP(KCCAppUtilLogFile, CCA_L("::HandleContactDataFieldUpdateL() complete, all fields fetched")); |
|
587 iContactDataFetchingIndex = KErrNotFound; |
|
588 iHandlerState = EOperationsCompleted; |
|
589 iCmsContactDataFetcher.OrderNotificationsL(this, CCmsContactFieldItem::ECmsPresenceAllNotification); |
|
590 } |
|
591 CCA_DP(KCCAppUtilLogFile, CCA_L("<-CCCAppCmsContactFetcherWrapper::HandleContactDataFieldUpdateL()")); |
|
592 } |
|
593 |
|
594 // --------------------------------------------------------------------------- |
|
595 // CCCAppCmsContactFetcherWrapper::ContactFieldDataArray |
|
596 // --------------------------------------------------------------------------- |
|
597 // |
|
598 EXPORT_C RPointerArray<CCmsContactField>& CCCAppCmsContactFetcherWrapper::ContactFieldDataArray() |
|
599 { |
|
600 CCA_DP(KCCAppUtilLogFile, CCA_L("CCCAppCmsContactFetcherWrapper::ContactFieldDataArray()")); |
|
601 return iContactFieldsArray; |
|
602 } |
|
603 |
|
604 // --------------------------------------------------------------------------- |
|
605 // CCCAppCmsContactFetcherWrapper::ContactInfo |
|
606 // --------------------------------------------------------------------------- |
|
607 // |
|
608 EXPORT_C const CCmsContactFieldInfo* CCCAppCmsContactFetcherWrapper::ContactInfo() |
|
609 { |
|
610 CCA_DP(KCCAppUtilLogFile, CCA_L("CCCAppCmsContactFetcherWrapper::ContactInfo()")); |
|
611 |
|
612 if ( ELoadingEnabledFields == iHandlerState || EInitial == iHandlerState ) |
|
613 return NULL; |
|
614 else |
|
615 return iContactInfo; |
|
616 } |
|
617 |
|
618 // --------------------------------------------------------------------------- |
|
619 // CCCAppCmsContactFetcherWrapper::ContactIdentifierLC |
|
620 // --------------------------------------------------------------------------- |
|
621 // |
|
622 EXPORT_C HBufC8* CCCAppCmsContactFetcherWrapper::ContactIdentifierLC() |
|
623 { |
|
624 HBufC8* buf8 = iCmsContactDataFetcher.GetContactIdentifierL(); |
|
625 CleanupStack::PushL( buf8 ); |
|
626 return buf8; |
|
627 } |
|
628 |
|
629 // --------------------------------------------------------------------------- |
|
630 // CCCAppCmsContactFetcherWrapper::HandlePresenceNotificationL |
|
631 // --------------------------------------------------------------------------- |
|
632 // |
|
633 void CCCAppCmsContactFetcherWrapper::HandlePresenceNotificationL( CCmsContactField* aField ) |
|
634 { |
|
635 CleanupStack::PushL(aField); |
|
636 MCCAppContactFieldDataObserver::TParameter param = MCCAppContactFieldDataObserver::TParameter(); |
|
637 param.iType = MCCAppContactFieldDataObserver::TParameter::EContactPresenceChanged; |
|
638 param.iContactField = aField; |
|
639 const TInt count = iObservers.Count(); |
|
640 for ( TInt i = 0; i < count; i++ ) |
|
641 { |
|
642 TRAP_IGNORE( iObservers[ i ]->ContactFieldDataObserverNotifyL( param )); |
|
643 } |
|
644 if (iContactFieldsArray.Find(aField) == KErrNotFound) |
|
645 { |
|
646 iContactFieldsArray.Append(aField); |
|
647 } |
|
648 CleanupStack::Pop(aField); |
|
649 } |
|
650 |
|
651 // --------------------------------------------------------------------------- |
|
652 // CCCAppCmsContactFetcherWrapper::HandlePhonebookNotificationL |
|
653 // --------------------------------------------------------------------------- |
|
654 // |
|
655 void CCCAppCmsContactFetcherWrapper::HandlePhonebookNotificationL( TCmsPhonebookEvent aNotificationType ) |
|
656 { |
|
657 if (aNotificationType == ECmsContactModified) |
|
658 { |
|
659 MCCAppContactFieldDataObserver::TParameter param = MCCAppContactFieldDataObserver::TParameter(); |
|
660 param.iType = MCCAppContactFieldDataObserver::TParameter::EContactsChanged; |
|
661 const TInt count = iObservers.Count(); |
|
662 for ( TInt i = 0; i < count; i++ ) |
|
663 { |
|
664 TRAP_IGNORE( iObservers[ i ]->ContactFieldDataObserverNotifyL( param )); |
|
665 } |
|
666 Cancel(); |
|
667 iCmsContactDataFetcher.CancelNotifications(CCmsContactFieldItem::ECmsPresenceAllNotification); |
|
668 iContactFieldsArray.ResetAndDestroy(); |
|
669 delete iContactInfo; |
|
670 iContactInfo = NULL; |
|
671 StartAsyncFetchingL(); |
|
672 } |
|
673 else if (aNotificationType == ECmsContactDeleted) |
|
674 { |
|
675 MCCAppContactFieldDataObserver::TParameter param = MCCAppContactFieldDataObserver::TParameter(); |
|
676 param.iType = MCCAppContactFieldDataObserver::TParameter::EContactDeleted; |
|
677 const TInt count = iObservers.Count(); |
|
678 for ( TInt i = 0; i < count; i++ ) |
|
679 { |
|
680 TRAP_IGNORE( iObservers[ i ]->ContactFieldDataObserverNotifyL( param )); |
|
681 } |
|
682 } |
|
683 } |
|
684 |
|
685 // --------------------------------------------------------------------------- |
|
686 // CCCAppCmsContactFetcherWrapper::CmsNotificationTerminatedL |
|
687 // --------------------------------------------------------------------------- |
|
688 // |
|
689 void CCCAppCmsContactFetcherWrapper::CmsNotificationTerminatedL( TInt /*aStatus*/, |
|
690 CCmsContactFieldItem::TCmsContactNotification /*aNotificationType*/ ) |
|
691 { |
|
692 |
|
693 } |
|
694 |
|
695 void CCCAppCmsContactFetcherWrapper::RefetchContactL() |
|
696 { |
|
697 Cancel(); |
|
698 iContactFieldsArray.ResetAndDestroy(); |
|
699 if (iContactInfo) |
|
700 { |
|
701 delete iContactInfo; |
|
702 iContactInfo = NULL; |
|
703 } |
|
704 iCmsContactDataFetcher.Close(); |
|
705 iWrapperParam = EFindContactFromOtherStores; |
|
706 |
|
707 StartFetcherL(); |
|
708 } |
|
709 |
|
710 // --------------------------------------------------------------------------- |
|
711 // CCCAppCmsContactFetcherWrapper::IsTopContact |
|
712 // --------------------------------------------------------------------------- |
|
713 // |
|
714 EXPORT_C TBool CCCAppCmsContactFetcherWrapper::IsTopContact() |
|
715 { |
|
716 return iCmsContactDataFetcher.IsTopContact(); |
|
717 } |
|
718 |
|
719 // End of file |