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