|
1 /* |
|
2 * Copyright (c) 2002-2005 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: Manager for presence-list handling |
|
15 * (Contact-list updater/ Attribute-list publisher ). |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include "CCAPEngListManager.h" |
|
23 #include "ChatDebugPrint.h" |
|
24 #include "CAPresenceDefinitions.h" |
|
25 #include "MCASettings.h" |
|
26 #include "CAPresenceUtils.h" |
|
27 #include "CCAPresenceErrors.h" |
|
28 #include "CAPresenceConst.h" |
|
29 #include "CCAPEngListObserver.h" |
|
30 #include "ImpsErrors.h" |
|
31 #include "MCAPresenceError.h" |
|
32 |
|
33 #include "CCAStorageManagerFactory.h" |
|
34 #include "MCAStoredContacts.h" |
|
35 #include "MCAStoredContact.h" |
|
36 #include "MCAContactList.h" |
|
37 #include "MCAPresenceUpdater.h" |
|
38 |
|
39 #include "CAUtils.h" |
|
40 #include "impsbuilddefinitions.h" |
|
41 #include "ChatDebugAssert.h" |
|
42 |
|
43 #include <MPEngAttributeList2.h> |
|
44 #include <MPEngContactList2.h> |
|
45 #include <PEngWVPresenceAttributes2.h> |
|
46 #include <CPEngContactListTransaction2.h> |
|
47 #include <CPEngContactListStore2.h> |
|
48 #include <CPEngAttributeListStore2.h> |
|
49 #include <CPEngAttributeListTransaction2.h> |
|
50 #include <CPEngPresenceNotifier2.h> |
|
51 #include <MPEngTransactionStatus2.h> |
|
52 #include <MPEngPresenceObserver2.h> |
|
53 #include <MPEngContactListProperties.h> |
|
54 #include <PEngPresenceEngineConsts2.h> |
|
55 #include <TPEngContactListBaseSettings.h> |
|
56 #include "MCAListInitObserver.h" |
|
57 #include <impspresenceconnectionuiconstsng.h> |
|
58 #include <CPEngNWSessionSlot2.h> |
|
59 #include <CPEngNWSessionSlotID2.h> |
|
60 |
|
61 // =============================== CONSTANTS =================================== |
|
62 |
|
63 const TInt KMaxIdattempts = 50; // max amount of attempts to find unused id |
|
64 |
|
65 |
|
66 // ============================ MEMBER FUNCTIONS =============================== |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CCAPEngListManager::CCAPEngListManager |
|
70 // C++ default constructor can NOT contain any code, that |
|
71 // might leave. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CCAPEngListManager::CCAPEngListManager( RArray<TUint32>& aHandledAttributes, |
|
75 MPEngPresenceObserver2& aNotifierObserver, |
|
76 MCASettings& aApplicationSettings, |
|
77 MCAPresenceUpdater& aUpdater ) |
|
78 : iOperationError( KErrNone ), |
|
79 iIsLoggedIn( EFalse ), |
|
80 iAttributes( aHandledAttributes ), |
|
81 iNotifierObserver( aNotifierObserver ), |
|
82 iApplicationSettings( &aApplicationSettings ), |
|
83 iPresenceUpdater( aUpdater ), |
|
84 iMainViewProcessObserver( NULL ), |
|
85 iContactFetchingComplete( EFalse ) |
|
86 { |
|
87 CHAT_DP_TXT( "CCAPEngListManager::CCAPEngListManager()" ); |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CCAPEngListManager::ConstructL |
|
92 // Symbian 2nd phase constructor can leave. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CCAPEngListManager::ConstructL( CPEngNWSessionSlotID2* aSessionSlotID ) |
|
96 { |
|
97 CHAT_DP_TXT( "CCAPEngListManager::ConstructL()" ); |
|
98 |
|
99 iPEngContactListUpdater = |
|
100 CPEngContactListTransaction2::NewL( *aSessionSlotID ); |
|
101 |
|
102 iPEngAttributeListPublisher = |
|
103 CPEngAttributeListTransaction2::NewL( *aSessionSlotID ); |
|
104 |
|
105 iPEngContactListStore = CPEngContactListStore2::NewL( *aSessionSlotID ); |
|
106 iPEngAttributeListStore = CPEngAttributeListStore2::NewL( *aSessionSlotID ); |
|
107 |
|
108 iPEngAttributeNotifier = CPEngPresenceNotifier2::NewL( *aSessionSlotID ); |
|
109 User::LeaveIfError( iPEngAttributeNotifier->AddObserver( *this ) ); |
|
110 |
|
111 iErrors = CCAPresenceErrors::NewL(); |
|
112 |
|
113 iListObserver = CCAPEngListObserver::NewL( aSessionSlotID, |
|
114 *iPEngAttributeNotifier, iAttributes, iPresenceUpdater ); |
|
115 |
|
116 iAttribListSupported = AttribListsSupportedL( *aSessionSlotID ); |
|
117 |
|
118 #ifndef IMPS_CONTACT_FETCH_BACKGROUND |
|
119 // Start listening for presence events. |
|
120 RestartNotifierL(); |
|
121 #endif //IMPS_CONTACT_FETCH_BACKGROUND |
|
122 iObserver = NULL; |
|
123 iListInitInProcees = ETrue; |
|
124 } |
|
125 |
|
126 |
|
127 // ----------------------------------------------------------------------------- |
|
128 // CCAPEngListManager::NewL |
|
129 // Two-phased constructor. |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 CCAPEngListManager* CCAPEngListManager::NewL( |
|
133 MCASettings& aApplicationSettings, |
|
134 RArray<TUint32>& aHandledAttributes, |
|
135 MPEngPresenceObserver2& aNotifierObserver, |
|
136 CPEngNWSessionSlotID2* aSessionSlotID, |
|
137 MCAPresenceUpdater& aUpdater ) |
|
138 { |
|
139 CHAT_DP_TXT( "CCAPEngListManager::NewL()" ); |
|
140 |
|
141 CCAPEngListManager* self = new( ELeave ) CCAPEngListManager( |
|
142 aHandledAttributes, |
|
143 aNotifierObserver, |
|
144 aApplicationSettings, |
|
145 aUpdater ); |
|
146 |
|
147 CleanupStack::PushL( self ); |
|
148 self->ConstructL( aSessionSlotID ); |
|
149 CleanupStack::Pop(); |
|
150 |
|
151 return self; |
|
152 } |
|
153 |
|
154 |
|
155 // Destructor |
|
156 CCAPEngListManager::~CCAPEngListManager() |
|
157 { |
|
158 CHAT_DP_TXT( "CCAPEngListManager::~CCAPEngListManager()" ); |
|
159 ReleaseListManager( EFalse ); |
|
160 iObserver = NULL; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CCAPEngListManager::ReleaseListManager |
|
165 // |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 void CCAPEngListManager::ReleaseListManager( |
|
169 TBool /*aReleaseContactListModels*/ ) |
|
170 { |
|
171 CHAT_DP_TXT( "CCAPEngListManager::~CCAPEngListManager()" ); |
|
172 |
|
173 delete iPEngAttributeListPublisher; |
|
174 iPEngAttributeListPublisher = NULL; |
|
175 delete iPEngContactListUpdater; |
|
176 iPEngContactListUpdater = NULL; |
|
177 delete iPEngContactListStore; |
|
178 iPEngContactListStore = NULL; |
|
179 delete iPEngAttributeListStore; |
|
180 iPEngAttributeListStore = NULL; |
|
181 delete iPEngAttributeNotifier; |
|
182 iPEngAttributeNotifier = NULL; |
|
183 delete iErrors; |
|
184 iErrors = NULL; |
|
185 |
|
186 delete iListObserver; |
|
187 iListObserver = NULL; |
|
188 |
|
189 delete iIdle; |
|
190 iIdle = NULL; |
|
191 |
|
192 delete iFetchIdle; |
|
193 iFetchIdle = NULL; |
|
194 |
|
195 delete iListIds; |
|
196 iListIds = NULL; |
|
197 |
|
198 iAppendContactsArray.Close(); |
|
199 |
|
200 TInt count = iUpdateListQueue.Count(); |
|
201 iUpdateListQueue.ResetAndDestroy(); |
|
202 |
|
203 iContactFetchStep = MCAContactLists::EBaseSynchronise; |
|
204 |
|
205 // If this assert fails then all changes were not updated to network! |
|
206 // Check the implemententation of DeleteServerContactL |
|
207 __CHAT_ASSERT_DEBUG( count == 0 ) |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // CCAPEngListManager::SetLoggedIn |
|
212 // Sets network state |
|
213 // (other items were commented in a header). |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void CCAPEngListManager::SetLoggedIn( TBool aIsLoggedIn, |
|
217 CPEngNWSessionSlotID2* /*aSessionSlotID*/ ) |
|
218 { |
|
219 if ( iIsLoggedIn && !aIsLoggedIn ) // Logout after login |
|
220 { |
|
221 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::SetLoggedIn: \ |
|
222 Release old lists." ) ); |
|
223 // Release contact storage |
|
224 CancelPendingRequests(); |
|
225 ReleaseListManager( ETrue ); |
|
226 } |
|
227 |
|
228 iIsLoggedIn = aIsLoggedIn; |
|
229 } |
|
230 |
|
231 // ----------------------------------------------------------------------------- |
|
232 // CCAPEngListManager::IsLoggedIn |
|
233 // Returns network state |
|
234 // (other items were commented in a header). |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 TBool CCAPEngListManager::IsLoggedIn() const |
|
238 { |
|
239 return iIsLoggedIn; |
|
240 } |
|
241 |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CCAPEngListManager::FetchContacts |
|
245 // Launch next step of fetchcontacts |
|
246 // (other items were commented in a header). |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 TInt CCAPEngListManager::FetchContacts( TAny *aInstance ) |
|
250 { |
|
251 // called by CIdle to fetch the contacts on background |
|
252 |
|
253 CCAPEngListManager* instance = static_cast<CCAPEngListManager*>( aInstance ); |
|
254 TInt launchAgain = EFalse; |
|
255 TRAPD( error, launchAgain = instance->FetchStateMachineL() ); |
|
256 if ( error != KErrNone ) |
|
257 { |
|
258 switch ( instance->iContactFetchStep ) |
|
259 { |
|
260 case EPublishAttributeLists: |
|
261 { |
|
262 // creating the list of lists failed, sync can't continue |
|
263 CActiveScheduler::Current()->Error( error ); |
|
264 instance->iContactFetchStep = ESynchronizeDone; |
|
265 break; |
|
266 } |
|
267 default: |
|
268 { |
|
269 MCAStoredContacts* storage = NULL; |
|
270 TRAP_IGNORE( storage = CCAStorageManagerFactory::ContactListInterfaceL() ); |
|
271 if ( storage ) |
|
272 { |
|
273 // list fetching failed, try next list |
|
274 if ( storage->SetNextForSynchroniseProcess() != KErrNotFound ) |
|
275 { |
|
276 return ETrue; |
|
277 } |
|
278 } |
|
279 // next list can't be tried, sync can't continue |
|
280 if ( error == KErrNoMemory ) |
|
281 { |
|
282 CActiveScheduler::Current()->Error( error ); |
|
283 } |
|
284 instance->iContactFetchStep = ESynchronizeDone; |
|
285 break; |
|
286 } |
|
287 } |
|
288 } |
|
289 |
|
290 return launchAgain; |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CCAPEngListManager::FetchStateMachineL |
|
295 // Launch next step of FetchStateMachineL |
|
296 // (other items were commented in a header). |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 TInt CCAPEngListManager::FetchStateMachineL() |
|
300 { |
|
301 TBool launchAgain = EFalse; |
|
302 |
|
303 MCAStoredContacts* storage = CCAStorageManagerFactory::ContactListInterfaceL(); |
|
304 switch ( iContactFetchStep ) |
|
305 { |
|
306 case EBaseSynchronise: // -> ContactListTransactionComplete / Error |
|
307 { |
|
308 // Can leave cause first time is called from UI. |
|
309 // Base synchronise for getting lists. |
|
310 TBool autoUpdate = |
|
311 iApplicationSettings->Value( MCASettings::EAutomaticPresenceUpdate ); |
|
312 |
|
313 TBool needToUnSubscribe = EFalse; |
|
314 //Mode is manual or automatic there is no need of sending unsubscribe message.. |
|
315 |
|
316 User::LeaveIfError( |
|
317 iPEngContactListUpdater->BaseSynchronizeContactLists( *this, needToUnSubscribe ) ); |
|
318 |
|
319 iContactFetchStep = EPublishAttributeLists; |
|
320 break; |
|
321 } |
|
322 case EPublishAttributeLists: |
|
323 { |
|
324 iContactFetchStep = EInitializeLists; |
|
325 launchAgain = ETrue; |
|
326 UpdatePresenceAuthorizeL(); |
|
327 break; |
|
328 } |
|
329 case EInitializeLists: |
|
330 { |
|
331 TContactListsWrapper contactLists( iPEngContactListStore->AllContactListsL() ); |
|
332 TInt count( contactLists.MdcaCount() ); |
|
333 if ( count == 0 ) // no action needed cause no lists. |
|
334 { |
|
335 iContactFetchStep = ESynchronizeDone; |
|
336 storage->ResetContactLists(); // Used to send notification to UI |
|
337 |
|
338 iListInitInProcees = EFalse; |
|
339 if ( iObserver ) |
|
340 { |
|
341 iObserver->HandleListInitChange( !iListInitInProcees ); |
|
342 } |
|
343 |
|
344 return KErrNone; |
|
345 } |
|
346 // Append lists to storage. |
|
347 for ( TInt a( 0 ); a < count; ++a ) |
|
348 { |
|
349 TPtrC listId( contactLists.MdcaPoint( a ) ); |
|
350 TPtrC displayName( CAUtils::DisplayId( listId, ETrue ) ); |
|
351 MCAContactList* newCaList = |
|
352 storage->AddContactListIdL( listId, displayName ); |
|
353 } |
|
354 // notify the View to show waiting nore for synch |
|
355 if ( storage->InitSynchroniseProcess() != KErrNotFound ) |
|
356 { |
|
357 iContactFetchStep = ESynchronizeList; |
|
358 launchAgain = ETrue; |
|
359 } |
|
360 else |
|
361 { |
|
362 iContactFetchStep = ESynchronizeDone; |
|
363 } |
|
364 |
|
365 // Reset notifier. |
|
366 iListObserver->ClearListNotifier(); |
|
367 break; |
|
368 } |
|
369 case ERestartSynchronize: |
|
370 { |
|
371 if ( storage->InitSynchroniseProcess() > KErrNotFound ) |
|
372 { |
|
373 iContactFetchStep = ESynchronizeList; |
|
374 launchAgain = ETrue; |
|
375 } |
|
376 else |
|
377 { |
|
378 iContactFetchStep = ESynchronizeDone; |
|
379 } |
|
380 |
|
381 // Reset notifier. |
|
382 iListObserver->ClearListNotifier(); |
|
383 break; |
|
384 } |
|
385 case ESynchronizeList: //-> ContactListTransactionCompleteL / Error |
|
386 { |
|
387 MCAContactList& list = storage->ListInSyncProcessL(); |
|
388 iPEngContactListUpdater->SynchronizeContactList( list.ListId(), *this ); |
|
389 iContactFetchStep = ESubscribeList; |
|
390 // init completed |
|
391 break; |
|
392 } |
|
393 case ESubscribeList: // SubscribeListL / HandleContactListTransactionCompleteL / Error |
|
394 { |
|
395 MCAContactList& list = storage->ListInSyncProcessL(); |
|
396 TBool autoUpdate( iApplicationSettings->Value( MCASettings::EAutomaticPresenceUpdate ) ); |
|
397 TPtrC listId( list.ListId() ); |
|
398 TRAPD( error, |
|
399 MPEngContactList2& cntList = iPEngContactListStore->ContactListL( listId ); |
|
400 // subscribe the list |
|
401 iContactFetchStep = EFetchContacts; |
|
402 SubscribeListL( cntList, listId, autoUpdate, ETrue ); |
|
403 ); |
|
404 |
|
405 if ( error != KErrNone ) |
|
406 { |
|
407 // sync failed, try next list |
|
408 list.SetSynchronised( MCAContactList::ESynchroniseFailed ); |
|
409 User::Leave( error ); |
|
410 } |
|
411 CDesCArray* contactlist = new( ELeave ) CDesCArrayFlat( 1 ); |
|
412 CleanupStack::PushL( contactlist ); |
|
413 contactlist->AppendL( listId ); |
|
414 RestartNotifierL( contactlist ); |
|
415 CleanupStack::PopAndDestroy( contactlist ); |
|
416 iListInitInProcees = EFalse; |
|
417 if ( iObserver ) |
|
418 { |
|
419 iObserver->HandleListInitChange( !iListInitInProcees ); |
|
420 } |
|
421 |
|
422 break; |
|
423 } |
|
424 case EFetchContacts: // DoAppendContacts |
|
425 { |
|
426 MCAContactList& list = storage->ListInSyncProcessL(); |
|
427 TPtrC listId( list.ListId() ); |
|
428 |
|
429 // Make sure we have list in storage |
|
430 TAppendContactsParams appendParams = { |
|
431 NULL, |
|
432 NULL, |
|
433 NULL, |
|
434 storage, |
|
435 0, |
|
436 &list |
|
437 }; |
|
438 TRAPD( error, |
|
439 MPEngContactList2& cntList = iPEngContactListStore->ContactListL( listId ); |
|
440 appendParams.iContactList = &cntList; |
|
441 appendParams.iEntryIndex = ( cntList.Count() - 1 ); |
|
442 User::LeaveIfError( iAppendContactsArray.Append( appendParams ) ); |
|
443 |
|
444 if ( !iIdle ) |
|
445 { |
|
446 iIdle = CIdle::NewL( CActive::EPriorityIdle ); |
|
447 } |
|
448 if ( !iIdle->IsActive() ) |
|
449 { |
|
450 iIdle->Start( TCallBack( AppendContacts, this ) ); |
|
451 } |
|
452 |
|
453 iContactFetchStep = EFinalizeList; |
|
454 ); |
|
455 if ( error != KErrNone ) |
|
456 { |
|
457 // sync failed, try next list |
|
458 list.SetSynchronised( MCAContactList::ESynchroniseFailed ); |
|
459 User::Leave( error ); |
|
460 } |
|
461 break; |
|
462 } |
|
463 case EFinalizeList: |
|
464 { |
|
465 MCAContactList& list = storage->ListInSyncProcessL(); |
|
466 TPtrC listId( list.ListId() ); |
|
467 |
|
468 TRAPD( error, |
|
469 MPEngContactList2& cntList = iPEngContactListStore->ContactListL( listId ); |
|
470 TPtrC displayName; |
|
471 TInt success = ( cntList.ListProperties().DisplayName( displayName ) == KErrNone ); |
|
472 if ( success ) |
|
473 { |
|
474 list.SetDisplayNameL( displayName ); |
|
475 } |
|
476 list.SetSynchronised(); |
|
477 |
|
478 // update list notifier |
|
479 iListObserver->AddL( listId ); |
|
480 ); |
|
481 if ( error != KErrNone ) |
|
482 { |
|
483 list.SetSynchronised( MCAContactList::ESynchroniseFailed ); |
|
484 User::LeaveIfError( error ); |
|
485 } |
|
486 |
|
487 // Keep lists sorted |
|
488 storage->SortContactLists(); |
|
489 if ( storage->SetNextForSynchroniseProcess() > KErrNotFound ) |
|
490 { |
|
491 // Then next one |
|
492 iContactFetchStep = ESynchronizeList; |
|
493 launchAgain = ETrue; |
|
494 } |
|
495 else |
|
496 { |
|
497 // All synchronised |
|
498 // and subscribed to network |
|
499 iContactFetchStep = EPublishListsDone; |
|
500 launchAgain = ETrue; |
|
501 } |
|
502 break; |
|
503 } |
|
504 case EPublishListsDone: |
|
505 { |
|
506 iContactFetchStep = ESynchronizeDone; |
|
507 RestartNotifierL(); |
|
508 launchAgain = iStartFetchAgain; |
|
509 iStartFetchAgain = EFalse; |
|
510 |
|
511 iContactFetchingComplete = ETrue; |
|
512 if ( iMainViewProcessObserver ) |
|
513 { |
|
514 iMainViewProcessObserver->HandleListInitChange( ETrue ); |
|
515 } |
|
516 break; |
|
517 } |
|
518 default: //Should not come here |
|
519 { |
|
520 __CHAT_ASSERT_DEBUG( EFalse ); |
|
521 break; |
|
522 } |
|
523 } |
|
524 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DoFetchContactsL : Done" ) ); |
|
525 return launchAgain; |
|
526 } |
|
527 |
|
528 // ----------------------------------------------------------------------------- |
|
529 // CCAPEngListManager::FetchContactsL |
|
530 // (other items were commented in a header). |
|
531 // ----------------------------------------------------------------------------- |
|
532 // |
|
533 #ifdef IMPS_CONTACT_FETCH_BACKGROUND |
|
534 TInt CCAPEngListManager::FetchContactsL( TBool aBaseSyncDone /*=EFalse*/ ) |
|
535 { |
|
536 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DoFetchContactsL : Enter" ) ); |
|
537 |
|
538 // called from UI to start and restart the fetching of contact lists |
|
539 switch ( iContactFetchStep ) |
|
540 { |
|
541 case EBaseSynchronise: |
|
542 { |
|
543 iBaseSyncDone = aBaseSyncDone; |
|
544 if ( iBaseSyncDone ) |
|
545 { |
|
546 iContactFetchStep = EInitializeLists; |
|
547 } |
|
548 |
|
549 // starting the sync for the first time |
|
550 TBool ret = FetchStateMachineL(); |
|
551 if ( ret ) |
|
552 { |
|
553 StartFetchIdle(); |
|
554 } |
|
555 return ret; |
|
556 } |
|
557 case ESynchronizeDone: |
|
558 { |
|
559 // sync already done once, restart it |
|
560 iContactFetchStep = ERestartSynchronize; |
|
561 StartFetchIdle(); |
|
562 break; |
|
563 } |
|
564 default: |
|
565 { |
|
566 // sync ongoing, needs to be restarted after it has finished the first round |
|
567 iStartFetchAgain = ETrue; |
|
568 break; |
|
569 } |
|
570 } |
|
571 |
|
572 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DoFetchContactsL : Done" ) ); |
|
573 return KErrNone; |
|
574 } |
|
575 |
|
576 #else // IMPS_CONTACT_FETCH_BACKGROUND |
|
577 TInt CCAPEngListManager::FetchContactsL( TBool /*aBaseSyncDone*/ /*=EFalse*/ ) |
|
578 { |
|
579 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DoFetchContactsL : Enter" ) ); |
|
580 |
|
581 TContactListsWrapper contactLists( iPEngContactListStore->AllContactListsL() ); |
|
582 TInt count( contactLists.MdcaCount() ); |
|
583 if ( count == 0 ) |
|
584 { |
|
585 return KErrNone; |
|
586 } |
|
587 // update list notifier |
|
588 iListObserver->SetListIds( contactLists ); |
|
589 |
|
590 MCAStoredContacts* storage = |
|
591 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
592 iOperationError = KErrNone; |
|
593 |
|
594 TBool autoUpdate( iApplicationSettings->Value( |
|
595 MCASettings::EAutomaticPresenceUpdate ) ); |
|
596 |
|
597 RPointerArray<MPEngContactList2> listModels; |
|
598 CleanupClosePushL( listModels ); |
|
599 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
600 { |
|
601 MPEngContactList2& cntList = iPEngContactListStore->ContactListL( contactLists.MdcaPoint( x ) ); |
|
602 listModels.AppendL( &cntList ); |
|
603 } |
|
604 |
|
605 for ( TInt i( 0 ); i < count && iOperationError == KErrNone; ++i ) |
|
606 { |
|
607 MPEngContactList2& list = *( listModels[ i ] ); |
|
608 TPtrC listId( list.ListProperties().Name() ); |
|
609 |
|
610 // subscribe the list |
|
611 SubscribeListL( list, listId, autoUpdate, EFalse ); |
|
612 |
|
613 // Make sure we have list in storage |
|
614 TPtrC displayName; |
|
615 TInt success = ( list.ListProperties().DisplayName( displayName ) |
|
616 == KErrNone ); |
|
617 |
|
618 // do not notify yet |
|
619 MCAContactList* newCaList = storage->AddContactListIdL( listId, |
|
620 success ? displayName : |
|
621 CAUtils::DisplayId( listId, ETrue ), |
|
622 EFalse ); |
|
623 |
|
624 // anb fetch contacts |
|
625 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::FetchContactsL, Get \ |
|
626 contact-list(%S) from store" ), &listId ); |
|
627 |
|
628 TAppendContactsParams appendParams = { |
|
629 &list, |
|
630 NULL, |
|
631 NULL, |
|
632 storage, |
|
633 // we go from the end this time |
|
634 ( list.Count() - 1 ), |
|
635 newCaList |
|
636 }; |
|
637 |
|
638 iAppendContactsParams = appendParams; |
|
639 |
|
640 // Idle loop for storing contacts to local storage |
|
641 CIdle* idle = CIdle::NewL( CActive::EPriorityIdle ); |
|
642 CleanupStack::PushL( idle ); |
|
643 |
|
644 idle->Start( TCallBack( AppendContacts, this ) ); |
|
645 iRequestQueue.WaitForResponseL( TCARequestQueue::EAppendContactsWait ); |
|
646 |
|
647 // notify about new contact list, now when all is added |
|
648 storage->SendContactListUpdatedEvent( *newCaList ); |
|
649 |
|
650 CleanupStack::PopAndDestroy( idle ); |
|
651 } |
|
652 |
|
653 // and subscribe to network |
|
654 iPEngContactListUpdater->PublishContactLists( contactLists, *this ); |
|
655 iRequestQueue.WaitForResponseL( TCARequestQueue::EContactListUpdater ); |
|
656 |
|
657 CleanupStack::PopAndDestroy(); // contactLists |
|
658 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DoFetchContactsL : Exit" ) ); |
|
659 return iOperationError; |
|
660 } |
|
661 |
|
662 #endif //IMPS_CONTACT_FETCH_BACKGROUND |
|
663 |
|
664 // ----------------------------------------------------------------------------- |
|
665 // CCAPEngListManager::SubscribeListsL |
|
666 // (other items were commented in a header). |
|
667 // ----------------------------------------------------------------------------- |
|
668 // |
|
669 void CCAPEngListManager::SubscribeListsL( TBool aSubscribe ) |
|
670 { |
|
671 TContactListsWrapper contactLists( iPEngContactListStore->AllContactListsL() ); |
|
672 TInt count( contactLists.MdcaCount() ); |
|
673 if ( count == 0 ) |
|
674 { |
|
675 return; |
|
676 } |
|
677 |
|
678 for ( TInt i( 0 ); i < count && iOperationError == KErrNone; ++i ) |
|
679 { |
|
680 TPtrC listId( contactLists.MdcaPoint( i ) ); |
|
681 MPEngContactList2& list = iPEngContactListStore->ContactListL( listId ); |
|
682 |
|
683 // subscribe the list |
|
684 // EFalse as fourth parameter to avoid updating to |
|
685 // network at this point |
|
686 SubscribeListL( list, listId, aSubscribe, EFalse ); |
|
687 } |
|
688 |
|
689 // Update all lists to network at once |
|
690 User::LeaveIfError( iPEngContactListUpdater->PublishContactLists( |
|
691 contactLists, *this ) ); |
|
692 // Wait for request to complete |
|
693 iRequestQueue.WaitForResponseL( |
|
694 TCARequestQueue::EContactListUpdater ); |
|
695 |
|
696 if ( aSubscribe ) |
|
697 { |
|
698 RestartNotifierL( &contactLists ); |
|
699 } |
|
700 else |
|
701 { |
|
702 if ( iPEngAttributeNotifier->IsActive() ) |
|
703 { |
|
704 iPEngAttributeNotifier->Stop(); |
|
705 } |
|
706 } |
|
707 } |
|
708 |
|
709 // ----------------------------------------------------------------------------- |
|
710 // CCAPEngListManager::IsContactFetchingCompleted |
|
711 // (other items were commented in a header). |
|
712 // ----------------------------------------------------------------------------- |
|
713 TBool CCAPEngListManager::IsContactFetchingCompleted() |
|
714 { |
|
715 return iContactFetchingComplete; |
|
716 } |
|
717 |
|
718 // ----------------------------------------------------------------------------- |
|
719 // CCAPEngListManager::AddMainViewProcessObserver |
|
720 // (other items were commented in a header). |
|
721 // ----------------------------------------------------------------------------- |
|
722 void CCAPEngListManager::AddMainViewProcessObserver( MCAListInitObserver* aObserver ) |
|
723 { |
|
724 if ( !iMainViewProcessObserver ) |
|
725 { |
|
726 iMainViewProcessObserver = aObserver; |
|
727 } |
|
728 } |
|
729 |
|
730 // ----------------------------------------------------------------------------- |
|
731 // CCAPEngListManager::RemoveMainViewProcessObserver |
|
732 // (other items were commented in a header). |
|
733 // ----------------------------------------------------------------------------- |
|
734 void CCAPEngListManager::RemoveMainViewProcessObserver() |
|
735 { |
|
736 iMainViewProcessObserver = NULL; |
|
737 } |
|
738 |
|
739 // ----------------------------------------------------------------------------- |
|
740 // CCAPEngListManager::FetchServerContactsL |
|
741 // Fetches given server-side contact-list |
|
742 // (other items were commented in a header). |
|
743 // ----------------------------------------------------------------------------- |
|
744 // |
|
745 void CCAPEngListManager::FetchServerContactsL( const TDesC& aContactListId, |
|
746 CPtrCArray& aWVIds ) |
|
747 { |
|
748 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::FetchServerContactsL, Get \ |
|
749 contact-list(%S) from store" ), &aContactListId ); |
|
750 |
|
751 MPEngContactList2& list = |
|
752 iPEngContactListStore->ContactListL( aContactListId ); |
|
753 |
|
754 // Fill arrays |
|
755 TInt count( list.Count() ); |
|
756 MPEngContactItem* contact = NULL; |
|
757 for ( TInt i( 0 ); i < count; ++i ) |
|
758 { |
|
759 contact = &list.ContactItem( i ); |
|
760 aWVIds.AppendL( contact->Id() ); |
|
761 } |
|
762 } |
|
763 |
|
764 |
|
765 // ----------------------------------------------------------------------------- |
|
766 // CCAPEngListManager::AppendContacts |
|
767 // (other items were commented in a header). |
|
768 // ----------------------------------------------------------------------------- |
|
769 // |
|
770 TInt CCAPEngListManager::AppendContacts( TAny *aInstance ) |
|
771 { |
|
772 return static_cast<CCAPEngListManager*>( aInstance )-> |
|
773 DoAppendContacts(); |
|
774 } |
|
775 |
|
776 |
|
777 // ----------------------------------------------------------------------------- |
|
778 // CCAPEngListManager::StartFetchIdle |
|
779 // (other items were commented in a header). |
|
780 // ----------------------------------------------------------------------------- |
|
781 // |
|
782 TInt CCAPEngListManager::StartFetchIdle() |
|
783 { |
|
784 TRAPD( err, |
|
785 if ( !iFetchIdle ) |
|
786 { |
|
787 // if the idle does not exist, create it |
|
788 iFetchIdle = CIdle::NewL( CActive::EPriorityIdle ); |
|
789 } |
|
790 if ( !iFetchIdle->IsActive() ) |
|
791 { |
|
792 // and if it isn't started, do it |
|
793 iFetchIdle->Start( TCallBack( FetchContacts, this ) ); |
|
794 } |
|
795 ); |
|
796 return err; |
|
797 } |
|
798 |
|
799 // ----------------------------------------------------------------------------- |
|
800 // CCAPEngListManager::DoAppendContacts |
|
801 // (other items were commented in a header). |
|
802 // ----------------------------------------------------------------------------- |
|
803 // |
|
804 TInt CCAPEngListManager::DoAppendContacts() |
|
805 { |
|
806 CHAT_DP_TXT( "CCAPEngListManager::DoAppendContacts" ); |
|
807 TBool retval( EFalse ); |
|
808 MCAStoredContacts* contactInterface = NULL; |
|
809 |
|
810 #ifndef IMPS_CONTACT_FETCH_BACKGROUND |
|
811 |
|
812 TRAP( iOperationError, contactInterface = |
|
813 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
814 contactInterface->SetContactListLock( ETrue ); |
|
815 retval = CAPresenceUtils::AppendContactsL( |
|
816 iAppendContactsParams.iContactList, |
|
817 iAppendContactsParams.iWVIds, |
|
818 iAppendContactsParams.iNicknames, |
|
819 iAppendContactsParams.iContactStorage, |
|
820 iAppendContactsParams.iEntryIndex, |
|
821 *( iAppendContactsParams.iCaContactList ), |
|
822 iPresenceUpdater ) ); |
|
823 |
|
824 if ( contactInterface ) |
|
825 { |
|
826 contactInterface->SetContactListLock( EFalse ); |
|
827 } |
|
828 |
|
829 if ( iOperationError != KErrNone || !retval ) |
|
830 { |
|
831 iRequestQueue.ResponseReceived( TCARequestQueue::EAppendContactsWait ); |
|
832 return EFalse; |
|
833 } |
|
834 return retval; |
|
835 #else |
|
836 if ( !iAppendContactsArray.Count() ) // No appendcontacts array to process. |
|
837 { |
|
838 if ( iContactFetchStep == EFinalizeList ) |
|
839 { |
|
840 StartFetchIdle(); |
|
841 } |
|
842 return EFalse; |
|
843 } |
|
844 |
|
845 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DoAppendContacts, \ |
|
846 Count of append packets %d" ), iAppendContactsArray.Count() ); |
|
847 |
|
848 TAppendContactsParams& appendContacts = iAppendContactsArray[ 0 ]; |
|
849 |
|
850 TRAP( iOperationError, contactInterface = |
|
851 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
852 contactInterface->SetContactListLock( ETrue ); |
|
853 retval = CAPresenceUtils::AppendContactsL( |
|
854 appendContacts.iContactList, |
|
855 appendContacts.iWVIds, |
|
856 appendContacts.iNicknames, |
|
857 appendContacts.iContactStorage, |
|
858 appendContacts.iEntryIndex, |
|
859 *( appendContacts.iCaContactList ), |
|
860 iPresenceUpdater ) ); |
|
861 |
|
862 if ( iOperationError != KErrNone || !retval ) |
|
863 { |
|
864 if ( contactInterface ) |
|
865 { |
|
866 contactInterface->SetContactListLock( EFalse ); |
|
867 } |
|
868 iAppendContactsArray.Remove( 0 ); |
|
869 } |
|
870 TBool retVal = TBool( iAppendContactsArray.Count() ); |
|
871 if ( !retVal && iContactFetchStep == EFinalizeList ) |
|
872 { |
|
873 StartFetchIdle(); |
|
874 } |
|
875 return retVal; |
|
876 #endif // IMPS_CONTACT_FETCH_BACKGROUND |
|
877 } |
|
878 |
|
879 // ----------------------------------------------------------------------------- |
|
880 // CCAPEngListManager::SubscribeListL |
|
881 // (other items were commented in a header). |
|
882 // ----------------------------------------------------------------------------- |
|
883 // |
|
884 void CCAPEngListManager::SubscribeListL( MPEngContactList2& aList, |
|
885 const TDesC& aListId, TBool aSubscribe, |
|
886 TBool aUpdate /* = ETrue */ ) |
|
887 { |
|
888 MPEngContactListProperties& contactListProperties = aList.ListProperties(); |
|
889 // setting subscription attributes also sets up the subscription |
|
890 // property |
|
891 TBool update( EFalse ); |
|
892 TBool bgFetch( iContactFetchStep == EFetchContacts ); |
|
893 if ( aSubscribe ) |
|
894 { |
|
895 update = contactListProperties.SetSubscriptionAttributesL( |
|
896 iAttributes.Array() ); |
|
897 CHAT_DP( D_CHAT_LIT( "Subscribe ready" ) ); |
|
898 } |
|
899 else |
|
900 { |
|
901 // set the subscription property |
|
902 update = contactListProperties.DeActivateSubscriptionL(); |
|
903 CHAT_DP( D_CHAT_LIT( "Unsubscribe ready" ) ); |
|
904 } |
|
905 |
|
906 if ( update && aUpdate ) |
|
907 { |
|
908 UpdateToNetworkL( EContactListUpdate, aListId |
|
909 #ifdef IMPS_CONTACT_FETCH_BACKGROUND |
|
910 , !bgFetch // don't wait for response when bg fetch is ongoing |
|
911 #endif //IMPS_CONTACT_FETCH_BACKGROUND |
|
912 ); |
|
913 } |
|
914 #ifdef IMPS_CONTACT_FETCH_BACKGROUND |
|
915 else if ( bgFetch ) |
|
916 { |
|
917 // step to next state if no updating needed |
|
918 FetchStateMachineL(); |
|
919 } |
|
920 #endif //IMPS_CONTACT_FETCH_BACKGROUND |
|
921 |
|
922 CHAT_DP( D_CHAT_LIT( "UpdateL called" ) ); |
|
923 } |
|
924 |
|
925 |
|
926 // ----------------------------------------------------------------------------- |
|
927 // CCAPEngListManager::DeleteServerContactL |
|
928 // Deletes one contact from server side contact list |
|
929 // (other items were commented in a header). |
|
930 // ----------------------------------------------------------------------------- |
|
931 // |
|
932 void CCAPEngListManager::DeleteServerContactL( |
|
933 const TDesC& aContactListId, |
|
934 const TDesC& aWVId, |
|
935 const TBool aUpdateToServer /*ETrue*/ ) |
|
936 { |
|
937 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DeleteServerContactL, Get \ |
|
938 contact-list(%S) from store" ), &aContactListId ); |
|
939 if ( !IsLoggedIn() ) |
|
940 { |
|
941 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DeleteServerContactL, \ |
|
942 Not logged in --> KErrDisconnected" ) ); |
|
943 User::Leave( KErrDisconnected ); |
|
944 } |
|
945 |
|
946 MPEngContactList2& list = |
|
947 iPEngContactListStore->ContactListL( aContactListId ); |
|
948 |
|
949 TRAPD( err, list.RemoveContactL( aWVId ) ); |
|
950 CAPresenceUtils::HandleListErrorsL( err ); |
|
951 |
|
952 // update will destroy wv id descriptor, need to store it localy |
|
953 HBufC* userId = aWVId.AllocLC(); |
|
954 // Update changes to network or append to queue |
|
955 if ( aUpdateToServer ) |
|
956 { |
|
957 UpdateToNetworkL( EContactListUpdate, aContactListId ); |
|
958 } |
|
959 else |
|
960 { |
|
961 HBufC* listId = aContactListId.AllocLC(); |
|
962 iUpdateListQueue.AppendL( listId ); |
|
963 CleanupStack::Pop( listId ); |
|
964 } |
|
965 |
|
966 TContactListsWrapper contactLists = FetchServerContactListsL(); |
|
967 TInt count( contactLists.MdcaCount() ); |
|
968 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
969 { |
|
970 TPtrC listId( contactLists.MdcaPoint( x ) ); |
|
971 if ( KErrNone == listId.CompareF( aContactListId ) ) |
|
972 { |
|
973 // same list as we remove it from, no need to check |
|
974 continue; |
|
975 } |
|
976 // is |
|
977 MPEngContactList2& list = |
|
978 iPEngContactListStore->ContactListL( listId ); |
|
979 if ( KErrNone == list.FindContact( *userId ) ) |
|
980 { |
|
981 // wv id still exists in another contact list |
|
982 CleanupStack::PopAndDestroy(); |
|
983 return; |
|
984 } |
|
985 } |
|
986 // it was not dounf anywhere anymore, remove it from notifier |
|
987 RemoveFromNotifierL( *userId ); |
|
988 CleanupStack::PopAndDestroy(); |
|
989 } |
|
990 |
|
991 // ----------------------------------------------------------------------------- |
|
992 // CCAPEngListManager::DeleteServerContactL |
|
993 // Deletes several contacts from server side contact list |
|
994 // (other items were commented in a header). |
|
995 // ----------------------------------------------------------------------------- |
|
996 // |
|
997 void CCAPEngListManager::DeleteServerContactL( |
|
998 const TDesC& aContactListId, |
|
999 const MDesCArray& aWVIds, |
|
1000 const TBool aUpdateToServer /*ETrue*/ ) |
|
1001 { |
|
1002 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DeleteServerContactL (several), \ |
|
1003 Get contact-list(%S) from store" ), &aContactListId ); |
|
1004 if ( !IsLoggedIn() ) |
|
1005 { |
|
1006 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DeleteServerContactL, \ |
|
1007 Not logged in --> KErrDisconnected" ) ); |
|
1008 User::Leave( KErrDisconnected ); |
|
1009 } |
|
1010 |
|
1011 MPEngContactList2& list = |
|
1012 iPEngContactListStore->ContactListL( aContactListId ); |
|
1013 |
|
1014 TInt count( aWVIds.MdcaCount() ); |
|
1015 for ( TInt i( 0 ); i < count; ++i ) |
|
1016 { |
|
1017 TRAPD( err, list.RemoveContactL( aWVIds.MdcaPoint( i ) ) ); |
|
1018 CAPresenceUtils::HandleListErrorsL( err ); |
|
1019 } |
|
1020 |
|
1021 iListObserver->SkipStorageRemoval(); |
|
1022 |
|
1023 // Update changes to network or append to queue |
|
1024 TInt err; |
|
1025 if ( aUpdateToServer ) |
|
1026 { |
|
1027 TRAP( err, UpdateToNetworkL( EContactListUpdate, aContactListId ) ); |
|
1028 } |
|
1029 else |
|
1030 { |
|
1031 HBufC* listId = aContactListId.AllocLC(); |
|
1032 iUpdateListQueue.AppendL( listId ); |
|
1033 CleanupStack::Pop( listId ); |
|
1034 } |
|
1035 |
|
1036 // restart notifier after the list is really updated |
|
1037 RestartNotifierL(); |
|
1038 |
|
1039 // and propagate the error |
|
1040 User::LeaveIfError( err ); |
|
1041 } |
|
1042 |
|
1043 // ----------------------------------------------------------------------------- |
|
1044 // CCAPEngListManager::CommitDeleteServerContactL |
|
1045 // Updates deleted contacts to server. |
|
1046 // (other items were commented in a header). |
|
1047 // ----------------------------------------------------------------------------- |
|
1048 // |
|
1049 void CCAPEngListManager::CommitDeleteServerContactL() |
|
1050 { |
|
1051 // Check connection |
|
1052 if ( !IsLoggedIn() ) |
|
1053 { |
|
1054 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::CommitDeleteServerContactL, \ |
|
1055 Not logged in --> KErrDisconnected" ) ); |
|
1056 User::Leave( KErrDisconnected ); |
|
1057 } |
|
1058 |
|
1059 if ( iUpdateListQueue.Count() == 0 ) |
|
1060 { |
|
1061 // nothing to update |
|
1062 return; |
|
1063 } |
|
1064 |
|
1065 // construct MDesCArray from RPointerArray |
|
1066 TInt count = iUpdateListQueue.Count(); |
|
1067 CDesCArray* lists = new ( ELeave ) CDesCArrayFlat( count ); |
|
1068 CleanupStack::PushL( lists ); |
|
1069 for ( TInt i = 0; i < count; ++i ) |
|
1070 { |
|
1071 TInt pos; |
|
1072 if ( lists->Find( *iUpdateListQueue[i], pos ) != 0 ) |
|
1073 { |
|
1074 // not already in array |
|
1075 lists->AppendL( *iUpdateListQueue[i] ); |
|
1076 } |
|
1077 } |
|
1078 |
|
1079 // update to network |
|
1080 User::LeaveIfError( iPEngContactListUpdater->PublishContactLists( |
|
1081 *lists, *this ) ); |
|
1082 iRequestQueue.WaitForResponseL( TCARequestQueue::EContactListUpdater ); |
|
1083 |
|
1084 // clean queue |
|
1085 CleanupStack::PopAndDestroy(); |
|
1086 iUpdateListQueue.ResetAndDestroy(); |
|
1087 |
|
1088 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::CommitDeleteServerContactL, \ |
|
1089 contact-list update done (%d)" ), iOperationError ); |
|
1090 } |
|
1091 |
|
1092 // ----------------------------------------------------------------------------- |
|
1093 // CCAPEngListManager::AddServerContactL |
|
1094 // Adds one contact to server side contact list |
|
1095 // (other items were commented in a header). |
|
1096 // ----------------------------------------------------------------------------- |
|
1097 // |
|
1098 MCAStoredContact* CCAPEngListManager::AddServerContactL( const TDesC& aContactListId, |
|
1099 const TDesC& aWVId, |
|
1100 const TDesC& aNickname, |
|
1101 TBool /*aCanRemove = ETrue */, |
|
1102 const TDesC* aOldWVId /* = NULL */ ) |
|
1103 { |
|
1104 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::AddServerContactL, Get \ |
|
1105 contact-list(%S) from store" ), &aContactListId ); |
|
1106 |
|
1107 if ( !IsLoggedIn() ) |
|
1108 { |
|
1109 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::AddServerContactL, \ |
|
1110 Not logged in --> KErrDisconnected" ) ); |
|
1111 User::Leave( KErrDisconnected ); |
|
1112 } |
|
1113 |
|
1114 TPEngContactListBaseSettings baseSettings; |
|
1115 baseSettings.iContactListType = EPEngCachedContactList; |
|
1116 baseSettings.iContactListNameAutoUpdate = ETrue; |
|
1117 |
|
1118 // try to create the contact list |
|
1119 // we don't need to change any properties here, so ignore the returned value |
|
1120 TRAPD( err, iPEngContactListStore->CreateContactListL( aContactListId, |
|
1121 baseSettings ) ); |
|
1122 |
|
1123 // if it's already there we can just start using it |
|
1124 if ( err != KErrAlreadyExists ) |
|
1125 { |
|
1126 User::LeaveIfError( err ); |
|
1127 } |
|
1128 |
|
1129 // get the list |
|
1130 MPEngContactList2& list = |
|
1131 iPEngContactListStore->ContactListL( aContactListId ); |
|
1132 |
|
1133 HBufC* oldNick = NULL; |
|
1134 if ( aOldWVId /*&& ( ! aCanRemove )*/ ) |
|
1135 { |
|
1136 // contact has been changed, so remove it first |
|
1137 // as some servers will not accept same nicknames (yes nicknames) in the |
|
1138 // list at the same time |
|
1139 if ( CAUtils::NeutralCompare( aWVId, *aOldWVId ) != 0 ) |
|
1140 { |
|
1141 |
|
1142 TInt index( list.FindContact( *aOldWVId ) ); |
|
1143 |
|
1144 if ( index != KErrNotFound ) |
|
1145 { |
|
1146 MPEngContactItem& contactItem = list.ContactItem( index ); |
|
1147 oldNick = contactItem.NickName().AllocLC(); |
|
1148 |
|
1149 list.RemoveContactL( *aOldWVId ); |
|
1150 |
|
1151 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::AddServerContactL, \ |
|
1152 Remove old contact..." ) ); |
|
1153 // remove from IM storage too |
|
1154 MCAStoredContacts* storage = |
|
1155 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
1156 storage->RemoveContact( aContactListId, *aOldWVId ); |
|
1157 |
|
1158 TRAPD( removeErr, |
|
1159 UpdateToNetworkL( EContactListUpdate, aContactListId ) ); |
|
1160 if ( removeErr == KErrCancel ) |
|
1161 { |
|
1162 // In this case the network connection was closed and |
|
1163 // the request was cancelled |
|
1164 CHAT_DP( |
|
1165 D_CHAT_LIT( "CCAPEngListManager::AddServerContactL \ |
|
1166 leaving KErrCancel" ) ); |
|
1167 User::Leave( err ); |
|
1168 } |
|
1169 } |
|
1170 } |
|
1171 } |
|
1172 |
|
1173 // add the new one |
|
1174 TRAP( err, list.AddContactL( aWVId, aNickname ) ); |
|
1175 CAPresenceUtils::HandleListErrorsL( err ); |
|
1176 |
|
1177 err = KErrNone; |
|
1178 // Update changes to network |
|
1179 CHAT_DP( D_CHAT_LIT( |
|
1180 "CCAPEngListManager::AddServerContactL, Add new contact..." ) ); |
|
1181 TRAP( err, UpdateToNetworkL( EContactListUpdate, aContactListId ) ); |
|
1182 |
|
1183 if ( err == KErrCancel || ( err == Imps_ERROR_BASE - 601 ) ) |
|
1184 { |
|
1185 // In this case the network connection was closed and the request |
|
1186 // was cancelled |
|
1187 CHAT_DP( D_CHAT_LIT( |
|
1188 "CCAPEngListManager::AddServerContactL leaving KErrCancel" ) ); |
|
1189 User::Leave( err ); |
|
1190 } |
|
1191 |
|
1192 MCAStoredContacts* storage = |
|
1193 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
1194 MCAStoredContact* contact = NULL; |
|
1195 if ( err != KErrNone ) |
|
1196 { |
|
1197 // failed |
|
1198 CHAT_DP( D_CHAT_LIT( " **AddServerContactL failed with %d" ), err ); |
|
1199 |
|
1200 // If partially successfull. |
|
1201 // Take last detailed error as right error code. |
|
1202 if ( err == Imps_ERROR_BASE - 201 ) |
|
1203 { |
|
1204 const RPointerArray< MCAPresenceError >& errorArray = |
|
1205 iErrors->DetailedErrors(); |
|
1206 if ( errorArray.Count() > 0 ) |
|
1207 { |
|
1208 err = errorArray[ 0 ]->ErrorCode(); |
|
1209 } |
|
1210 } |
|
1211 |
|
1212 TRAPD( listErr, list.RemoveContactL( aWVId ) ); |
|
1213 CAPresenceUtils::HandleListErrorsL( listErr ); |
|
1214 |
|
1215 // remove from IM storage too |
|
1216 storage->RemoveContact( aContactListId, aWVId ); |
|
1217 |
|
1218 if ( aOldWVId && oldNick ) |
|
1219 { |
|
1220 TRAPD( error, list.AddContactL( *aOldWVId, *oldNick ) ); |
|
1221 CAPresenceUtils::HandleListErrorsL( error ); |
|
1222 } |
|
1223 |
|
1224 // Update changes to network |
|
1225 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::AddServerContactL \ |
|
1226 Trying to restore previous state" ) ); |
|
1227 TRAPD( restoreErr, |
|
1228 UpdateToNetworkL( EContactListUpdate, aContactListId ) ); |
|
1229 if ( restoreErr == KErrCancel ) |
|
1230 { |
|
1231 // In this case the network connection was closed and the |
|
1232 // request was cancelled |
|
1233 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::AddServerContactL \ |
|
1234 ***Could not restore old contact!" ) ); |
|
1235 User::Leave( restoreErr ); |
|
1236 } |
|
1237 } |
|
1238 else |
|
1239 { |
|
1240 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::AddServerContactL success" ) ); |
|
1241 // successful editing (update storage) |
|
1242 MCAContactList* contactList = NULL; |
|
1243 contact = storage->FindContact( aContactListId, aWVId, contactList ); |
|
1244 if ( contact ) |
|
1245 { |
|
1246 TInt index( list.FindContact( aWVId ) ); |
|
1247 if ( index != KErrNotFound ) |
|
1248 { |
|
1249 // found it, update nick |
|
1250 MPEngContactItem& contactItem = list.ContactItem( index ); |
|
1251 contact->SetNicknameL( contactItem.NickName() ); |
|
1252 // Nick name was updated, resort the contacts |
|
1253 contactList->ResortContact( contact ); |
|
1254 contact->SignalChanges(); |
|
1255 } |
|
1256 } |
|
1257 } |
|
1258 |
|
1259 AddToNotifierL( aWVId ); |
|
1260 if ( oldNick ) |
|
1261 { |
|
1262 CleanupStack::PopAndDestroy( oldNick ); |
|
1263 } |
|
1264 |
|
1265 CHAT_DP( D_CHAT_LIT( " **AddServerContactL leaving with %d" ), err ); |
|
1266 User::LeaveIfError( err ); |
|
1267 return contact; |
|
1268 } |
|
1269 |
|
1270 |
|
1271 // ----------------------------------------------------------------------------- |
|
1272 // CCAPEngListManager::AddServerContactL |
|
1273 // Adds several contacts to server side contact list |
|
1274 // (other items were commented in a header). |
|
1275 // ----------------------------------------------------------------------------- |
|
1276 // |
|
1277 void CCAPEngListManager::AddServerContactL( const TDesC& aContactListId, |
|
1278 const MDesCArray& aWVIds, |
|
1279 const MDesCArray& aNicknames ) |
|
1280 { |
|
1281 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::AddServerContactL (several), \ |
|
1282 Get contact-list(%S) from store" ), &aContactListId ); |
|
1283 |
|
1284 if ( !IsLoggedIn() ) |
|
1285 { |
|
1286 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::AddServerContactL, \ |
|
1287 Not logged in --> KErrDisconnected" ) ); |
|
1288 User::Leave( KErrDisconnected ); |
|
1289 } |
|
1290 |
|
1291 TPEngContactListBaseSettings baseSettings; |
|
1292 baseSettings.iContactListType = EPEngCachedContactList; |
|
1293 baseSettings.iContactListNameAutoUpdate = ETrue; |
|
1294 |
|
1295 // try to create the contact list |
|
1296 // we don't need to change any properties here, so ignore the returned value |
|
1297 TRAPD( err, iPEngContactListStore->CreateContactListL( aContactListId, |
|
1298 baseSettings ) ); |
|
1299 |
|
1300 // if it's already there we can just start using it |
|
1301 if ( err != KErrAlreadyExists ) |
|
1302 { |
|
1303 User::LeaveIfError( err ); |
|
1304 } |
|
1305 |
|
1306 MPEngContactList2& list = |
|
1307 iPEngContactListStore->ContactListL( aContactListId ); |
|
1308 |
|
1309 TInt count( aWVIds.MdcaCount() ); |
|
1310 for ( TInt i( 0 ); i < count; ++i ) |
|
1311 { |
|
1312 TRAPD( err, list.AddContactL( aWVIds.MdcaPoint( i ), |
|
1313 aNicknames.MdcaPoint( i ) ) ); |
|
1314 CAPresenceUtils::HandleListErrorsL( err ); |
|
1315 } |
|
1316 |
|
1317 iListObserver->SkipStorageRemoval(); |
|
1318 |
|
1319 RestartNotifierL(); |
|
1320 |
|
1321 err = KErrNone; |
|
1322 // Update changes to network |
|
1323 TRAP( err, UpdateToNetworkL( EContactListUpdate, aContactListId ) ); |
|
1324 if ( err != KErrNone ) |
|
1325 { |
|
1326 MCAStoredContacts* storage = |
|
1327 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
1328 |
|
1329 for ( TInt i( 0 ); i < count; ++i ) |
|
1330 { |
|
1331 list.RemoveContactL( aWVIds.MdcaPoint( i ) ); |
|
1332 // remove from IM storage too |
|
1333 storage->RemoveContact( aContactListId, aWVIds.MdcaPoint( i ) ); |
|
1334 } |
|
1335 User::Leave( err ); |
|
1336 } |
|
1337 } |
|
1338 |
|
1339 |
|
1340 // ----------------------------------------------------------------------------- |
|
1341 // CCAPEngListManager::UpdateContactNicknameL |
|
1342 // (other items were commented in a header). |
|
1343 // ----------------------------------------------------------------------------- |
|
1344 // |
|
1345 void CCAPEngListManager::UpdateContactNicknameL( const TDesC& aContactListId, |
|
1346 const TDesC& aWVId, |
|
1347 const TDesC& aNickname ) |
|
1348 { |
|
1349 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::UpdateContactNicknameL, Get \ |
|
1350 contact-list(%S) from store" ), &aContactListId ); |
|
1351 |
|
1352 if ( !IsLoggedIn() ) |
|
1353 { |
|
1354 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::UpdateContactNicknameL, \ |
|
1355 Not logged in --> KErrDisconnected" ) ); |
|
1356 User::Leave( KErrDisconnected ); |
|
1357 } |
|
1358 |
|
1359 TPEngContactListBaseSettings baseSettings; |
|
1360 baseSettings.iContactListType = EPEngCachedContactList; |
|
1361 baseSettings.iContactListNameAutoUpdate = ETrue; |
|
1362 |
|
1363 // try to create the contact list |
|
1364 // we don't need to change any properties here, so ignore the returned value |
|
1365 TRAPD( err, iPEngContactListStore->CreateContactListL( |
|
1366 aContactListId, baseSettings ) ); |
|
1367 |
|
1368 // if it's already there we can just start using it |
|
1369 if ( err != KErrAlreadyExists ) |
|
1370 { |
|
1371 User::LeaveIfError( err ); |
|
1372 } |
|
1373 |
|
1374 // get the list |
|
1375 MPEngContactList2& list = |
|
1376 iPEngContactListStore->ContactListL( aContactListId ); |
|
1377 |
|
1378 TInt index = list.FindContact( aWVId ); |
|
1379 User::LeaveIfError( index ); |
|
1380 |
|
1381 MPEngContactItem& item = list.ContactItem( index ); |
|
1382 item.UpdateNickNameL( aNickname ); |
|
1383 |
|
1384 // Update changes to network |
|
1385 UpdateToNetworkL( EContactListUpdate, aContactListId ); |
|
1386 |
|
1387 index = list.FindContact( aWVId ); |
|
1388 User::LeaveIfError( index ); |
|
1389 MPEngContactItem& item2 = list.ContactItem( index ); |
|
1390 |
|
1391 MCAStoredContacts* storage = |
|
1392 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
1393 |
|
1394 // successful editing (update storage) |
|
1395 MCAStoredContact* contact = storage->FindContact( aContactListId, aWVId ); |
|
1396 if ( contact ) |
|
1397 { |
|
1398 contact->SetNicknameL( item2.NickName() ); |
|
1399 contact->SignalChanges(); |
|
1400 } |
|
1401 } |
|
1402 |
|
1403 // ----------------------------------------------------------------------------- |
|
1404 // CCAPEngListManager::UpdateServerContactsL |
|
1405 // Updates given server-side contact-list with given userids/nicknames |
|
1406 // (other items were commented in a header). |
|
1407 // ----------------------------------------------------------------------------- |
|
1408 // |
|
1409 void CCAPEngListManager::UpdateServerContactsL( const TDesC& aContactListId, |
|
1410 const MDesCArray& aWVIds, |
|
1411 const MDesCArray& aNicknames ) |
|
1412 { |
|
1413 CHAT_DP_TXT( "CCAPEngListManager::UpdateServerContactsL()" ); |
|
1414 |
|
1415 if ( aWVIds.MdcaCount() != aNicknames.MdcaCount() ) |
|
1416 { |
|
1417 User::Leave( ECAArraysNotSameSize ); |
|
1418 } |
|
1419 |
|
1420 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::UpdateServerContactsL, Get \ |
|
1421 contact-list(%S) from store" ), &aContactListId ); |
|
1422 |
|
1423 MPEngContactList2& list = |
|
1424 iPEngContactListStore->ContactListL( aContactListId ); |
|
1425 |
|
1426 // Clean the local list |
|
1427 CHAT_DP_TXT( "CCAPEngListManager::UpdateServerContactsL, \ |
|
1428 remove all old IDs" ); |
|
1429 list.RemoveAllContactsL(); |
|
1430 |
|
1431 // Add what was requested |
|
1432 TInt err( KErrNone ); |
|
1433 TInt count( aWVIds.MdcaCount() ); |
|
1434 for ( TInt counter( 0 ); counter < count; ++counter ) |
|
1435 { |
|
1436 #ifdef _DEBUG |
|
1437 TPtrC data1( aWVIds.MdcaPoint( counter ) ); |
|
1438 TPtrC data2( aNicknames.MdcaPoint( counter ) ); |
|
1439 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::UpdateServerContactsL, \ |
|
1440 adding %d: %S (%S)" ), counter, &data1, &data2 ); |
|
1441 #endif |
|
1442 TRAP( err, list.AddContactL( aWVIds.MdcaPoint( counter ), |
|
1443 aNicknames.MdcaPoint( counter ) ) ); |
|
1444 CAPresenceUtils::HandleListErrorsL( err ); |
|
1445 } |
|
1446 |
|
1447 // restart notifier |
|
1448 RestartNotifierL(); |
|
1449 |
|
1450 // Update changes to network |
|
1451 UpdateToNetworkL( EContactListUpdate, aContactListId ); |
|
1452 } |
|
1453 |
|
1454 // ----------------------------------------------------------------------------- |
|
1455 // CCAPEngListManager::FetchServerContactListsL |
|
1456 // Fetches list of server-side contact-lists |
|
1457 // (other items were commented in a header). |
|
1458 // ----------------------------------------------------------------------------- |
|
1459 // |
|
1460 TContactListsWrapper CCAPEngListManager::FetchServerContactListsL() |
|
1461 { |
|
1462 TContactListsWrapper contactLists( iPEngContactListStore->AllContactListsL() ); |
|
1463 return contactLists; |
|
1464 } |
|
1465 |
|
1466 // ----------------------------------------------------------------------------- |
|
1467 // CCAPEngListManager::ReleaseContactListsL |
|
1468 // Releases local resources held by contact-list, except aExcludedContactList |
|
1469 // (other items were commented in a header). |
|
1470 // ----------------------------------------------------------------------------- |
|
1471 // |
|
1472 void CCAPEngListManager::ReleaseContactListsL( |
|
1473 const TDesC& aExcludedContactList ) |
|
1474 { |
|
1475 CHAT_DP_TXT( "CCAPEngListManager::ReleaseContactListsL()" ); |
|
1476 |
|
1477 const MDesCArray& unknownLists = |
|
1478 iPEngContactListStore->UnknownServerContactListsL(); |
|
1479 TInt count( unknownLists.MdcaCount() ); |
|
1480 for ( TInt i( 0 ); i < count; ++i ) |
|
1481 { |
|
1482 if ( unknownLists.MdcaPoint( i ) != aExcludedContactList ) |
|
1483 { |
|
1484 iPEngContactListStore->ReleaseUnknownContactListFromStore( |
|
1485 unknownLists.MdcaPoint( i ) ); |
|
1486 } |
|
1487 } |
|
1488 } |
|
1489 |
|
1490 // ----------------------------------------------------------------------------- |
|
1491 // CCAPEngListManager::DeleteContactListL |
|
1492 // Not supported by 2.1 |
|
1493 // (other items were commented in a header). |
|
1494 // ----------------------------------------------------------------------------- |
|
1495 // |
|
1496 TInt CCAPEngListManager::DeleteContactListL( const TDesC& aContactListID |
|
1497 #ifdef IMPS_CONTACT_FETCH_BACKGROUND |
|
1498 , TBool aFailedList /* = EFalse */ |
|
1499 #endif // IMPS_CONTACT_FETCH_BACKGROUND |
|
1500 ) |
|
1501 { |
|
1502 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DeleteContactListL \ |
|
1503 enter with id %S" ), &aContactListID ); |
|
1504 |
|
1505 if ( !IsLoggedIn() ) |
|
1506 { |
|
1507 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DeleteContactListL, \ |
|
1508 Not logged in --> KErrDisconnected" ) ); |
|
1509 return KErrDisconnected; |
|
1510 } |
|
1511 |
|
1512 TRAPD( err, |
|
1513 // unsubscribe |
|
1514 MPEngContactList2& list = |
|
1515 iPEngContactListStore->ContactListL( aContactListID ); |
|
1516 SubscribeListL( list, aContactListID, EFalse, EFalse ); |
|
1517 ); |
|
1518 |
|
1519 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DeleteContactListL \ |
|
1520 trapped block 1 done err = %d" ), err ); |
|
1521 |
|
1522 TRAPD( err2, |
|
1523 // delete |
|
1524 iPEngContactListStore->ReleaseContactList( aContactListID ); |
|
1525 iPEngContactListStore->DeleteContactListL( aContactListID ); |
|
1526 ); |
|
1527 |
|
1528 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DeleteContactListL \ |
|
1529 trapped block 2 done err2 = %d" ), err2 ); |
|
1530 |
|
1531 #ifdef IMPS_CONTACT_FETCH_BACKGROUND |
|
1532 // When deleting failed list, ignore certain errors in unsubscribing if |
|
1533 // actual deleting went ok |
|
1534 if ( aFailedList ) |
|
1535 { |
|
1536 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DeleteContactListL \ |
|
1537 aFailedList = ETrue" ) ); |
|
1538 if ( err2 == KErrNone && ( err == KErrNotFound || err == KErrNotReady ) ) |
|
1539 { |
|
1540 err = err2; |
|
1541 } |
|
1542 } |
|
1543 else |
|
1544 { |
|
1545 // Take care of both error codes |
|
1546 err += err2; |
|
1547 } |
|
1548 #else |
|
1549 // Take care of both error codes |
|
1550 err += err2; |
|
1551 #endif // IMPS_CONTACT_FETCH_BACKGROUND |
|
1552 |
|
1553 if ( err == KErrNone ) |
|
1554 { |
|
1555 iOperationError = KErrNone; |
|
1556 |
|
1557 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DeleteContactListL \ |
|
1558 synchronizing.." ) ); |
|
1559 iPEngContactListUpdater->PublishContactList( aContactListID, *this ); |
|
1560 iRequestQueue.WaitForResponseL( TCARequestQueue::EContactListUpdater ); |
|
1561 err = iOperationError; |
|
1562 |
|
1563 if ( err == KErrNone ) |
|
1564 { |
|
1565 // update list notifier |
|
1566 iListObserver->Remove( aContactListID ); |
|
1567 |
|
1568 // and attribute notifier |
|
1569 RemoveFromNotifierL( aContactListID ); |
|
1570 |
|
1571 // deletion was successful, remove from storage |
|
1572 MCAStoredContacts* storage = |
|
1573 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
1574 storage->RemoveContactList( aContactListID ); |
|
1575 } |
|
1576 } |
|
1577 |
|
1578 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DeleteContactListL done with \ |
|
1579 error code %d" ), err ); |
|
1580 return err; |
|
1581 } |
|
1582 |
|
1583 // ----------------------------------------------------------------------------- |
|
1584 // CCAPEngListManager::SetDisplayNameL |
|
1585 // (other items were commented in a header). |
|
1586 // ----------------------------------------------------------------------------- |
|
1587 // |
|
1588 TInt CCAPEngListManager::SetDisplayNameL( |
|
1589 const TDesC& aContactListID, |
|
1590 const TDesC& aDisplayName ) |
|
1591 { |
|
1592 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::SetDisplayNameL setting \ |
|
1593 properties.." ) ); |
|
1594 |
|
1595 MPEngContactListProperties* prop = NULL; |
|
1596 TRAPD( err, prop = &iPEngContactListStore->ContactListPropertiesL( |
|
1597 aContactListID ) ); |
|
1598 if ( err == KErrNone && prop ) |
|
1599 { |
|
1600 prop->SetDisplayNameL( aDisplayName ); |
|
1601 |
|
1602 // update to network |
|
1603 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::SetDisplayNameL \ |
|
1604 synchronizing.." ) ); |
|
1605 iOperationError = KErrNone; |
|
1606 iPEngContactListUpdater->PublishContactList( aContactListID, *this ); |
|
1607 iRequestQueue.WaitForResponseL( TCARequestQueue::EContactListUpdater ); |
|
1608 err = iOperationError; |
|
1609 |
|
1610 if ( err == KErrNone ) |
|
1611 { |
|
1612 MCAStoredContacts* storage = |
|
1613 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
1614 MCAContactList* list = storage->FindContactList( aContactListID ); |
|
1615 if ( list ) |
|
1616 { |
|
1617 list->SetDisplayNameL( aDisplayName ); |
|
1618 } |
|
1619 } |
|
1620 } |
|
1621 |
|
1622 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::SetDisplayNameL done with error \ |
|
1623 code %d" ), err ); |
|
1624 return err; |
|
1625 } |
|
1626 |
|
1627 // ----------------------------------------------------------------------------- |
|
1628 // CCAPEngListManager::CreateContactListL |
|
1629 // (other items were commented in a header). |
|
1630 // ----------------------------------------------------------------------------- |
|
1631 // |
|
1632 TInt CCAPEngListManager::CreateContactListL( const TDesC& aDisplayName ) |
|
1633 { |
|
1634 |
|
1635 if ( !IsLoggedIn() ) |
|
1636 { |
|
1637 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::CreateContactListL, \ |
|
1638 Not logged in --> KErrDisconnected" ) ); |
|
1639 return KErrDisconnected; |
|
1640 } |
|
1641 |
|
1642 TPEngContactListBaseSettings baseSettings; |
|
1643 baseSettings.iContactListType = EPEngCachedContactList; |
|
1644 baseSettings.iContactListNameAutoUpdate = ETrue; |
|
1645 |
|
1646 // generate id from displayname |
|
1647 HBufC* id = CAUtils::GenerateIdLC( aDisplayName ); |
|
1648 TPtrC listId( id->Des() ); |
|
1649 |
|
1650 MPEngContactListProperties* prop = NULL; |
|
1651 TInt error = KErrAlreadyExists; |
|
1652 TInt attempt = 1; |
|
1653 |
|
1654 // loop until we find unused id |
|
1655 while ( error == KErrAlreadyExists && attempt < KMaxIdattempts ) |
|
1656 { |
|
1657 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::CreateContactListL %S" ), &listId ); |
|
1658 |
|
1659 // CleanupStack is not needed because ownership is not transferred |
|
1660 TRAP( error, prop = &iPEngContactListStore->CreateContactListL( // CSI: 35 # See comment above |
|
1661 listId, baseSettings ) ); |
|
1662 |
|
1663 if ( error == KErrAlreadyExists ) |
|
1664 { |
|
1665 // we need to generate another id |
|
1666 CleanupStack::PopAndDestroy( id ); |
|
1667 id = NULL; |
|
1668 id = CAUtils::GenerateIdLC( aDisplayName, attempt ); |
|
1669 listId.Set( id->Des() ); |
|
1670 ++attempt; |
|
1671 } |
|
1672 } |
|
1673 |
|
1674 if ( error == KErrNone && prop ) |
|
1675 { |
|
1676 // PEC might have changed the id. |
|
1677 HBufC* realId = prop->Name().AllocL(); |
|
1678 CleanupStack::PushL( realId ); |
|
1679 listId.Set( realId->Des() ); |
|
1680 |
|
1681 iOperationError = KErrNone; |
|
1682 |
|
1683 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::CreateContactListL setting \ |
|
1684 properties.." ) ); |
|
1685 prop->SetDisplayNameL( aDisplayName ); |
|
1686 |
|
1687 // must exist on server |
|
1688 prop->SetPropertyL( KPEngCntLstMustExistOnServer, |
|
1689 KPEngCntLstPropertyNativePermanent, ETrue ); |
|
1690 |
|
1691 // update to network |
|
1692 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::CreateContactListL \ |
|
1693 synchronizing.." ) ); |
|
1694 iPEngContactListUpdater->SynchronizeContactList( listId, *this ); |
|
1695 iRequestQueue.WaitForResponseL( TCARequestQueue::EContactListUpdater ); |
|
1696 error = iOperationError; |
|
1697 |
|
1698 if ( error == KErrNone ) |
|
1699 { |
|
1700 MCAStoredContacts* storage = |
|
1701 CCAStorageManagerFactory::ContactListInterfaceL(); |
|
1702 MCAContactList* newList = storage->AddContactListIdL( listId, aDisplayName ); |
|
1703 |
|
1704 if ( newList ) |
|
1705 { |
|
1706 newList->SetSynchronised(); |
|
1707 storage->SendContactListUpdatedEvent( *newList ); |
|
1708 } |
|
1709 |
|
1710 // subscribed or not? |
|
1711 TBool autoUpdate( iApplicationSettings->Value( |
|
1712 MCASettings::EAutomaticPresenceUpdate ) ); |
|
1713 MPEngContactList2& list = iPEngContactListStore->ContactListL( listId ); |
|
1714 |
|
1715 // update list notifier |
|
1716 iListObserver->AddL( listId ); |
|
1717 |
|
1718 // subscribe the list |
|
1719 SubscribeListL( list, listId, autoUpdate, EFalse ); |
|
1720 |
|
1721 // and attribute notifier |
|
1722 AddToNotifierL( listId ); |
|
1723 } |
|
1724 |
|
1725 CleanupStack::PopAndDestroy( realId ); |
|
1726 } |
|
1727 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::CreateContactListL done with \ |
|
1728 error code %d" ), error ); |
|
1729 CleanupStack::PopAndDestroy( id ); |
|
1730 return error; |
|
1731 } |
|
1732 |
|
1733 // ----------------------------------------------------------------------------- |
|
1734 // CCAPEngListManager::LastOperationResult |
|
1735 // Returns the error results of last operation |
|
1736 // (other items were commented in a header). |
|
1737 // ----------------------------------------------------------------------------- |
|
1738 // |
|
1739 const MCAPresenceErrors& CCAPEngListManager::LastOperationResult() const |
|
1740 { |
|
1741 return *iErrors; |
|
1742 } |
|
1743 |
|
1744 // ----------------------------------------------------------------------------- |
|
1745 // CCAPEngListManager::IdentificationL |
|
1746 // (other items were commented in a header). |
|
1747 // ----------------------------------------------------------------------------- |
|
1748 // |
|
1749 TPtrC CCAPEngListManager::IdentificationL( const TDesC& aUserId ) |
|
1750 { |
|
1751 TContactListsWrapper contactListIds( iPEngContactListStore->AllContactListsL() ); |
|
1752 TInt count( contactListIds.MdcaCount() ); |
|
1753 for ( TInt a( 0 ); a < count; ++a ) |
|
1754 { |
|
1755 MPEngContactList2& list = iPEngContactListStore->ContactListL( |
|
1756 contactListIds.MdcaPoint( a ) ); |
|
1757 TInt index = list.FindContact( aUserId ); |
|
1758 if ( index != KErrNotFound ) |
|
1759 { |
|
1760 MPEngContactItem& contact = list.ContactItem( index ); |
|
1761 if ( contact.NickName().Length() != 0 ) |
|
1762 { |
|
1763 return contact.NickName(); |
|
1764 } |
|
1765 } |
|
1766 } |
|
1767 |
|
1768 return CAUtils::DisplayId( aUserId ); |
|
1769 } |
|
1770 |
|
1771 // ----------------------------------------------------------------------------- |
|
1772 // CCAPEngListManager::IsSyncDone |
|
1773 // (other items were commented in a header). |
|
1774 // ----------------------------------------------------------------------------- |
|
1775 // |
|
1776 TBool CCAPEngListManager::IsSyncDone() |
|
1777 { |
|
1778 return ( iContactFetchStep == ESynchronizeDone ); |
|
1779 } |
|
1780 |
|
1781 // ----------------------------------------------------------------------------- |
|
1782 // CCAPEngListManager::HandleAttributeChangeL |
|
1783 // Handler for attribute change event |
|
1784 // (other items were commented in a header). |
|
1785 // ----------------------------------------------------------------------------- |
|
1786 // |
|
1787 void CCAPEngListManager::HandlePresenceChangeL( |
|
1788 CPEngPresenceNotifier2& aNotifier, |
|
1789 CPEngTrackedPresenceIDs2& aChangedPresenceIDs ) |
|
1790 { |
|
1791 CHAT_DP_TXT( "CCAPEngListManager::HandlePresenceChangeL" ); |
|
1792 iNotifierObserver.HandlePresenceChangeL( aNotifier, aChangedPresenceIDs ); |
|
1793 } |
|
1794 |
|
1795 // ----------------------------------------------------------------------------- |
|
1796 // CCAPEngListManager::HandleAttributeNotifyError |
|
1797 // Handler for attribute notifier errors |
|
1798 // (other items were commented in a header). |
|
1799 // ----------------------------------------------------------------------------- |
|
1800 // |
|
1801 void CCAPEngListManager::HandlePresenceError( TInt aError, |
|
1802 CPEngPresenceNotifier2& aNotifier ) |
|
1803 { |
|
1804 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::HandlePresenceNotifyError: %d" ), |
|
1805 aError ); |
|
1806 iNotifierObserver.HandlePresenceError( aError, aNotifier ); |
|
1807 |
|
1808 if ( ( aError != KErrNoMemory ) && ( aError != KErrCancel ) |
|
1809 && ( aError != KErrServerTerminated ) ) |
|
1810 { |
|
1811 TRAPD( err, RestartNotifierL() ); |
|
1812 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::HandleAttributeNotifyError, \ |
|
1813 RestartNotifierL returned %d" ), err ); |
|
1814 |
|
1815 if ( err != KErrNone ) // Signal user about error |
|
1816 { |
|
1817 CActiveScheduler::Current()->Error( err ); |
|
1818 } |
|
1819 } |
|
1820 } |
|
1821 |
|
1822 // ----------------------------------------------------------------------------- |
|
1823 // CCAPEngListManager::SetAuthorizationToAllL |
|
1824 // Sets presence authorization mode to all |
|
1825 // (other items were commented in a header). |
|
1826 // ----------------------------------------------------------------------------- |
|
1827 // |
|
1828 void CCAPEngListManager::SetAuthorizationToAllL() |
|
1829 { |
|
1830 CHAT_DP_TXT( "CCAPEngListManager::SetAuthorizationToAllL" ); |
|
1831 TInt err( KErrNone ); |
|
1832 |
|
1833 // Add CommCap/IM and OnlineStatus to default attribute list |
|
1834 CHAT_DP_TXT( "CCAPEngListManager::SetAuthorizationToAllL, Associate \ |
|
1835 CommCap&OnlineStatus to default attribute list" ); |
|
1836 MPEngAttributeList2* list = AttributeListLC( iPEngAttributeListStore ); |
|
1837 TRAP( err, list->AddPresenceAttributeL( KUidPrAttrCommCap ) ); |
|
1838 CAPresenceUtils::HandleListErrorsL( err ); |
|
1839 TRAP( err, list->AddPresenceAttributeL( KUidPrAttrOnlineStatus ) ); |
|
1840 CAPresenceUtils::HandleListErrorsL( err ); |
|
1841 TRAP( err, list->AddPresenceAttributeL( KUidPrAttrUserAvailability ) ); |
|
1842 CAPresenceUtils::HandleListErrorsL( err ); |
|
1843 TRAP( err, list->AddPresenceAttributeL( KUidPrAttrClientInfo ) ); |
|
1844 CAPresenceUtils::HandleListErrorsL( err ); |
|
1845 TRAP( err, AddDynamicAttributesToListL( list ) ); |
|
1846 CAPresenceUtils::HandleListErrorsL( err ); |
|
1847 |
|
1848 iPEngAttributeListStore->SetAsDefaultAttributeListL( *list ); |
|
1849 CleanupStack::PopAndDestroy( list ); |
|
1850 |
|
1851 // remove possible authorizations from all contact lists |
|
1852 TContactListsWrapper contactLists( iPEngContactListStore->AllContactListsL() ); |
|
1853 |
|
1854 // Deattach attribute-lists from all our contact-lists |
|
1855 DetachAttributeListL( contactLists ); |
|
1856 |
|
1857 // Update changes to network |
|
1858 UpdateToNetworkL( EAttributeListUpdate ); |
|
1859 CHAT_DP_TXT( "CCAPEngListManager::SetAuthorizationToAllL done" ); |
|
1860 } |
|
1861 |
|
1862 // ----------------------------------------------------------------------------- |
|
1863 // CCAPEngListManager::AddDynamicAttributesToListL |
|
1864 // (other items were commented in a header). |
|
1865 // ----------------------------------------------------------------------------- |
|
1866 // |
|
1867 void CCAPEngListManager::AddDynamicAttributesToListL( |
|
1868 MPEngAttributeList2* aList ) |
|
1869 { |
|
1870 // skip KUidPrAttrCommCap, KUidPrAttrOnlineStatus, KUidPrAttrClientInfo |
|
1871 // KUidPrAttrUserAvailability add all other attributes to the given list |
|
1872 for ( TInt i = iAttributes.Count() - 1; i >= 0; i-- ) |
|
1873 { |
|
1874 if ( ( iAttributes[ i ] != KUidPrAttrCommCap ) |
|
1875 && ( iAttributes[ i ] != KUidPrAttrOnlineStatus ) |
|
1876 && ( iAttributes[ i ] != KUidPrAttrUserAvailability ) |
|
1877 && ( iAttributes[ i ] != KUidPrAttrClientInfo ) ) |
|
1878 { |
|
1879 aList->AddPresenceAttributeL( iAttributes[ i ] ); |
|
1880 } |
|
1881 } |
|
1882 } |
|
1883 |
|
1884 // ----------------------------------------------------------------------------- |
|
1885 // CCAPEngListManager::SetAuthorizationToNoneL |
|
1886 // Sets presence authorization mode to none |
|
1887 // (other items were commented in a header). |
|
1888 // ----------------------------------------------------------------------------- |
|
1889 // |
|
1890 void CCAPEngListManager::SetAuthorizationToNoneL() |
|
1891 { |
|
1892 CHAT_DP_TXT( "CCAPEngListManager::SetAuthorizationToNoneL" ); |
|
1893 |
|
1894 // Remove CommCap/IM from default attribute list |
|
1895 CHAT_DP_TXT( "CCAPEngListManager::SetAuthorizationToNoneL, remove CommCap \ |
|
1896 from default attribute-list" ); |
|
1897 MPEngAttributeList2* list = AttributeListLC( iPEngAttributeListStore ); |
|
1898 list->RemoveAllAttributes(); |
|
1899 iPEngAttributeListStore->SetAsDefaultAttributeListL( *list ); |
|
1900 CleanupStack::PopAndDestroy( list ); |
|
1901 |
|
1902 // remove possible authorizations from all contact lists |
|
1903 TContactListsWrapper contactLists( iPEngContactListStore->AllContactListsL() ); |
|
1904 |
|
1905 // Deattach attribute-lists from all our contact-lists |
|
1906 DetachAttributeListL( contactLists ); |
|
1907 |
|
1908 // Update changes to network |
|
1909 UpdateToNetworkL( EAttributeListUpdate ); |
|
1910 CHAT_DP_TXT( "CCAPEngListManager::SetAuthorizationToNoneL done" ); |
|
1911 } |
|
1912 |
|
1913 // ----------------------------------------------------------------------------- |
|
1914 // CCAPEngListManager::SetAuthorizationToFriendsL |
|
1915 // Sets presence authorization mode to friends |
|
1916 // (other items were commented in a header). |
|
1917 // ----------------------------------------------------------------------------- |
|
1918 // |
|
1919 void CCAPEngListManager::SetAuthorizationToFriendsL() |
|
1920 { |
|
1921 CHAT_DP_TXT( "CCAPEngListManager::SetAuthorizationToFriendsL" ); |
|
1922 |
|
1923 // Remove CommCap/IM from default attribute list |
|
1924 CHAT_DP_TXT( "CCAPEngListManager::SetAuthorizationToFriendsL, \ |
|
1925 Remove CommCap/IM from default attribute list" ); |
|
1926 MPEngAttributeList2* defaultAttrList = |
|
1927 AttributeListLC( iPEngAttributeListStore ); |
|
1928 defaultAttrList->RemoveAllAttributes(); |
|
1929 iPEngAttributeListStore->SetAsDefaultAttributeListL( *defaultAttrList ); |
|
1930 CleanupStack::PopAndDestroy( defaultAttrList ); |
|
1931 |
|
1932 // Create attribute-list with CommCap-attribute |
|
1933 MPEngAttributeList2* attrList = |
|
1934 iPEngAttributeListStore->CreateEmptyAttributeListL(); |
|
1935 CleanupClosePushL( *attrList ); |
|
1936 TRAPD( err, attrList->AddPresenceAttributeL( KUidPrAttrCommCap ) ); |
|
1937 CAPresenceUtils::HandleListErrorsL( err ); |
|
1938 TRAP( err, attrList->AddPresenceAttributeL( KUidPrAttrOnlineStatus ) ); |
|
1939 CAPresenceUtils::HandleListErrorsL( err ); |
|
1940 TRAP( err, attrList->AddPresenceAttributeL( KUidPrAttrUserAvailability ) ); |
|
1941 CAPresenceUtils::HandleListErrorsL( err ); |
|
1942 TRAP( err, attrList->AddPresenceAttributeL( KUidPrAttrClientInfo ) ); |
|
1943 CAPresenceUtils::HandleListErrorsL( err ); |
|
1944 TRAP( err, AddDynamicAttributesToListL( attrList ) ); |
|
1945 CAPresenceUtils::HandleListErrorsL( err ); |
|
1946 |
|
1947 // Fetch all contacts from all lists we have |
|
1948 TContactListsWrapper contactLists( iPEngContactListStore->AllContactListsL() ); |
|
1949 |
|
1950 // Attach created attribute-list to all contact-lists we have |
|
1951 AttachAttributeListL( contactLists, *attrList ); |
|
1952 |
|
1953 CleanupStack::PopAndDestroy( attrList ); // attrList |
|
1954 |
|
1955 // Update changes to network |
|
1956 UpdateToNetworkL( EAttributeListUpdate ); |
|
1957 CHAT_DP_TXT( "CCAPEngListManager::SetAuthorizationToFriendsL done" ); |
|
1958 } |
|
1959 |
|
1960 // ----------------------------------------------------------------------------- |
|
1961 // CCAPEngListManager::RestartNotifierL |
|
1962 // Restarts the presence attribute notifier |
|
1963 // (other items were commented in a header). |
|
1964 // ----------------------------------------------------------------------------- |
|
1965 // |
|
1966 void CCAPEngListManager::RestartNotifierL( |
|
1967 MDesCArray* aListIds /* = NULL */ ) |
|
1968 { |
|
1969 CHAT_DP_TXT( "CCAPEngListManager::RestartNotifierL Enter" ); |
|
1970 if ( iApplicationSettings->Value( MCASettings::EAutomaticPresenceUpdate ) ) |
|
1971 { |
|
1972 |
|
1973 MDesCArray* listIds; |
|
1974 TContactListsWrapper contactLists; |
|
1975 if ( ! aListIds ) |
|
1976 { |
|
1977 // use all lists |
|
1978 contactLists = TContactListsWrapper( iPEngContactListStore->AllContactListsL() ); |
|
1979 listIds = &contactLists; |
|
1980 } |
|
1981 else |
|
1982 { |
|
1983 listIds = aListIds; |
|
1984 } |
|
1985 |
|
1986 TMultiPecListWrapper allContacts; |
|
1987 allContacts.InitializeLC( *listIds, *iPEngContactListStore ); |
|
1988 |
|
1989 CHAT_DP_TXT( "CCAPEngListManager::RestartNotifierL Wrapper done" ); |
|
1990 |
|
1991 if ( iPEngAttributeNotifier->IsActive() ) |
|
1992 { |
|
1993 // run update, since it is already running |
|
1994 CHAT_DP_TXT( "CCAPEngListManager::RestartNotifierL Updating Notifier" ); |
|
1995 User::LeaveIfError( iPEngAttributeNotifier->Update( allContacts ) ); |
|
1996 } |
|
1997 else |
|
1998 { |
|
1999 CHAT_DP_TXT( "CCAPEngListManager::RestartNotifierL Starting notifier" ); |
|
2000 User::LeaveIfError( iPEngAttributeNotifier->Start( allContacts, |
|
2001 iAttributes.Array() ) ); |
|
2002 } |
|
2003 |
|
2004 CleanupStack::PopAndDestroy(); // allContacts |
|
2005 } |
|
2006 CHAT_DP_TXT( "CCAPEngListManager::RestartNotifierL Exit" ); |
|
2007 } |
|
2008 |
|
2009 // ----------------------------------------------------------------------------- |
|
2010 // CCAPEngListManager::RemoveFromNotifierL |
|
2011 // (other items were commented in a header). |
|
2012 // ----------------------------------------------------------------------------- |
|
2013 // |
|
2014 void CCAPEngListManager::RemoveFromNotifierL( const TDesC& aId ) |
|
2015 { |
|
2016 CHAT_DP_TXT( "CCAPEngListManager::RemoveFromNotifierL" ); |
|
2017 if ( iApplicationSettings->Value( MCASettings::EAutomaticPresenceUpdate ) |
|
2018 && |
|
2019 iPEngAttributeNotifier->IsActive() |
|
2020 ) |
|
2021 { |
|
2022 // remove id |
|
2023 TInt err( iPEngAttributeNotifier->Remove( aId ) ); |
|
2024 err = err == KErrNotFound ? KErrNone : err; |
|
2025 User::LeaveIfError( err ); |
|
2026 } |
|
2027 } |
|
2028 |
|
2029 // ----------------------------------------------------------------------------- |
|
2030 // CCAPEngListManager::AddToNotifierL |
|
2031 // (other items were commented in a header). |
|
2032 // ----------------------------------------------------------------------------- |
|
2033 // |
|
2034 void CCAPEngListManager::AddToNotifierL( const TDesC& aId ) |
|
2035 { |
|
2036 CHAT_DP_TXT( "CCAPEngListManager::AddToNotifierL" ); |
|
2037 if ( iApplicationSettings->Value( MCASettings::EAutomaticPresenceUpdate ) ) |
|
2038 { |
|
2039 if ( iPEngAttributeNotifier->IsActive() ) |
|
2040 { |
|
2041 TInt err( iPEngAttributeNotifier->Add( aId, |
|
2042 iAttributes.Array() ) ); |
|
2043 err = err == KErrAlreadyExists ? KErrNone : err; |
|
2044 User::LeaveIfError( err ); |
|
2045 } |
|
2046 else |
|
2047 { |
|
2048 User::LeaveIfError( iPEngAttributeNotifier->Start( aId, |
|
2049 iAttributes.Array() ) ); |
|
2050 } |
|
2051 } |
|
2052 } |
|
2053 |
|
2054 // ----------------------------------------------------------------------------- |
|
2055 // CCAPEngListManager::AttributeListLC |
|
2056 // Gets given attribute list. If listID is empty, then return default list |
|
2057 // (other items were commented in a header). |
|
2058 // ----------------------------------------------------------------------------- |
|
2059 // |
|
2060 MPEngAttributeList2* CCAPEngListManager::AttributeListLC( |
|
2061 CPEngAttributeListStore2* aListStore ) |
|
2062 { |
|
2063 CHAT_DP_TXT( "CCAPEngListManager::AttributeListLC" ); |
|
2064 |
|
2065 MPEngAttributeList2* list = NULL; |
|
2066 TInt err; |
|
2067 TRAP( err, list = aListStore->GetDefaultAttributeListL( |
|
2068 EPEngNetworkAttributeLists ) ); |
|
2069 |
|
2070 // If network list is not available, then create it. |
|
2071 if ( !list ) |
|
2072 { |
|
2073 list = aListStore->CreateEmptyAttributeListL(); |
|
2074 } |
|
2075 |
|
2076 CleanupClosePushL( *list ); |
|
2077 return list; |
|
2078 } |
|
2079 |
|
2080 // ----------------------------------------------------------------------------- |
|
2081 // CCAPEngListManager::HandleAttributeListPublishError |
|
2082 // Handler for attribute-list publisher error event |
|
2083 // (other items were commented in a header). |
|
2084 // ----------------------------------------------------------------------------- |
|
2085 // |
|
2086 void CCAPEngListManager::HandleAttributeListTransactionError( TInt aError, |
|
2087 CPEngAttributeListTransaction2& /*aTransaction*/, |
|
2088 TInt /*aTransactionOperation*/ ) |
|
2089 { |
|
2090 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::HandleAttributeListPublisherError,\ |
|
2091 error %d" ), aError ); |
|
2092 |
|
2093 iRequestQueue.ResponseReceived( TCARequestQueue::EAttributeListUpdater ); |
|
2094 iOperationError = CAPresenceUtils::MapErrorPECtoCSP( aError ); |
|
2095 } |
|
2096 |
|
2097 // ----------------------------------------------------------------------------- |
|
2098 // CCAPEngListManager::HandleAttributeListPublishCompletedL |
|
2099 // Handler for attribute-list publisher complete event |
|
2100 // (other items were commented in a header). |
|
2101 // ----------------------------------------------------------------------------- |
|
2102 // |
|
2103 void CCAPEngListManager::HandleAttributeListTransactionCompleteL( |
|
2104 MPEngTransactionStatus2& aStatus, |
|
2105 CPEngAttributeListTransaction2& /*aTransaction*/, |
|
2106 TInt /*aTransactionOperation*/ ) |
|
2107 { |
|
2108 CHAT_DP_TXT( "CCAPEngListManager::HandleAttributeListPublisherCompletedL" ); |
|
2109 |
|
2110 iRequestQueue.ResponseReceived( TCARequestQueue::EAttributeListUpdater ); |
|
2111 if ( aStatus.Status() ) |
|
2112 { |
|
2113 iOperationError = CAPresenceUtils::MapErrorPECtoCSP( aStatus.Status() ); |
|
2114 CAPresenceUtils::HandleTransactionStatusL( aStatus, *iErrors ); |
|
2115 } |
|
2116 } |
|
2117 |
|
2118 // ----------------------------------------------------------------------------- |
|
2119 // CCAPEngListManager::HandleContactListUpdateError |
|
2120 // Handler for contact-list publisher error event |
|
2121 // (other items were commented in a header). |
|
2122 // ----------------------------------------------------------------------------- |
|
2123 // |
|
2124 void CCAPEngListManager::HandleContactListTransactionError( |
|
2125 TInt aError, |
|
2126 CPEngContactListTransaction2& /*aTransaction*/, |
|
2127 TInt aTransactionOperation ) |
|
2128 { |
|
2129 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::HandleContactListTransactionError,\ |
|
2130 error %d" ), aError ); |
|
2131 |
|
2132 #ifdef IMPS_CONTACT_FETCH_BACKGROUND |
|
2133 if ( ( aTransactionOperation == EPEngTransOpCntListSyncList && |
|
2134 iContactFetchStep == ESubscribeList ) || |
|
2135 ( aTransactionOperation == EPEngTransOpCntListUpdateList && |
|
2136 iContactFetchStep == EFetchContacts ) || |
|
2137 ( aTransactionOperation == EPEngTransOpCntListBaseSync && |
|
2138 iContactFetchStep == EPublishAttributeLists ) || |
|
2139 ( aTransactionOperation == EPEngTransOpCntListUpdateList && |
|
2140 iContactFetchStep == EPublishListsDone ) ) |
|
2141 { |
|
2142 StartFetchIdle(); |
|
2143 } |
|
2144 #endif //IMPS_CONTACT_FETCH_BACKGROUND |
|
2145 |
|
2146 iRequestQueue.ResponseReceived( TCARequestQueue::EContactListUpdater ); |
|
2147 iOperationError = CAPresenceUtils::MapErrorPECtoCSP( aError ); |
|
2148 } |
|
2149 |
|
2150 // ----------------------------------------------------------------------------- |
|
2151 // CCAPEngListManager::HandleContactListsUpdatedL |
|
2152 // Handler for contact-list publisher complete event |
|
2153 // (other items were commented in a header). |
|
2154 // ----------------------------------------------------------------------------- |
|
2155 // |
|
2156 void CCAPEngListManager::HandleContactListTransactionCompleteL( |
|
2157 MPEngTransactionStatus2& aStatus, |
|
2158 CPEngContactListTransaction2& /*aTransaction*/, |
|
2159 TInt aTransactionOperation ) |
|
2160 { |
|
2161 CHAT_DP_TXT( "CCAPEngListManager::HandleContactListTransactionCompleteL" ); |
|
2162 |
|
2163 #ifdef IMPS_CONTACT_FETCH_BACKGROUND |
|
2164 if ( ( aTransactionOperation == EPEngTransOpCntListSyncList && |
|
2165 iContactFetchStep == ESubscribeList ) || |
|
2166 ( aTransactionOperation == EPEngTransOpCntListUpdateList && |
|
2167 iContactFetchStep == EFetchContacts ) || |
|
2168 ( aTransactionOperation == EPEngTransOpCntListBaseSync && |
|
2169 iContactFetchStep == EPublishAttributeLists ) || |
|
2170 ( aTransactionOperation == EPEngTransOpCntListUpdateList && |
|
2171 iContactFetchStep == EPublishListsDone ) ) |
|
2172 { |
|
2173 StartFetchIdle(); |
|
2174 } |
|
2175 #endif //IMPS_CONTACT_FETCH_BACKGROUND |
|
2176 |
|
2177 iRequestQueue.ResponseReceived( TCARequestQueue::EContactListUpdater ); |
|
2178 if ( aStatus.Status() ) |
|
2179 { |
|
2180 iOperationError = CAPresenceUtils::MapErrorPECtoCSP( aStatus.Status() ); |
|
2181 CAPresenceUtils::HandleTransactionStatusL( aStatus, *iErrors ); |
|
2182 } |
|
2183 } |
|
2184 |
|
2185 // ----------------------------------------------------------------------------- |
|
2186 // CCAPEngListManager::UpdateToNetworkL |
|
2187 // (other items were commented in a header). |
|
2188 // ----------------------------------------------------------------------------- |
|
2189 // |
|
2190 void CCAPEngListManager::UpdateToNetworkL( TNetworkOperation aOperation, |
|
2191 const TDesC& aListID, TBool aWait /*= ETrue*/ ) |
|
2192 { |
|
2193 if ( !IsLoggedIn() ) |
|
2194 { |
|
2195 CHAT_DP_TXT( "CCAPEngListManager::UpdateToNetworkL, system is not \ |
|
2196 logged to service, operation request ignored!" ); |
|
2197 return; |
|
2198 } |
|
2199 |
|
2200 iOperationError = KErrNone; |
|
2201 |
|
2202 switch ( aOperation ) |
|
2203 { |
|
2204 case EContactListUpdate: |
|
2205 { |
|
2206 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::UpdateToNetworkL, \ |
|
2207 contact-list update (%S)" ), &aListID ); |
|
2208 |
|
2209 if ( aListID == KNullDesC ) |
|
2210 { |
|
2211 User::Leave( KErrArgument ); |
|
2212 } |
|
2213 |
|
2214 User::LeaveIfError( iPEngContactListUpdater->PublishContactList( |
|
2215 aListID, *this ) ); |
|
2216 |
|
2217 if ( aWait ) |
|
2218 { |
|
2219 iRequestQueue.WaitForResponseL( |
|
2220 TCARequestQueue::EContactListUpdater ); |
|
2221 } |
|
2222 |
|
2223 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::UpdateToNetworkL, \ |
|
2224 contact-list update done (%d)" ), |
|
2225 iOperationError ); |
|
2226 break; |
|
2227 } |
|
2228 case EAttributeListUpdate: |
|
2229 { |
|
2230 if ( iAttribListSupported ) |
|
2231 { |
|
2232 CHAT_DP_TXT( "CCAPEngListManager::UpdateToNetworkL, \ |
|
2233 attribute-list update" ); |
|
2234 User::LeaveIfError( |
|
2235 iPEngAttributeListPublisher->PublishAttributeLists( *this ) ); |
|
2236 |
|
2237 if ( aWait ) |
|
2238 { |
|
2239 iRequestQueue.WaitForResponseL( |
|
2240 TCARequestQueue::EAttributeListUpdater ); |
|
2241 } |
|
2242 |
|
2243 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::UpdateToNetworkL, \ |
|
2244 attribute-list update done (%d)" ), |
|
2245 iOperationError ); |
|
2246 } |
|
2247 else |
|
2248 { |
|
2249 CHAT_DP_TXT( "CCAPEngListManager::UpdateToNetworkL, \ |
|
2250 attribute lists - NOT SUPPORTED" ); |
|
2251 } |
|
2252 break; |
|
2253 } |
|
2254 default: |
|
2255 { |
|
2256 CHAT_DP_TXT( "CCAPEngListManager::UpdateToNetworkL, unknown \ |
|
2257 operation requested!" ); |
|
2258 User::Leave( KErrNotSupported ); |
|
2259 break; |
|
2260 } |
|
2261 } |
|
2262 |
|
2263 User::LeaveIfError( iOperationError ); |
|
2264 } |
|
2265 |
|
2266 // ----------------------------------------------------------------------------- |
|
2267 // CCAPEngListManager::AttachAttributeListL |
|
2268 // Cancels pending requests to network side. |
|
2269 // (other items were commented in a header). |
|
2270 // ----------------------------------------------------------------------------- |
|
2271 // |
|
2272 void CCAPEngListManager::AttachAttributeListL( MDesCArray& aContactLists, |
|
2273 MPEngAttributeList2& aAttributeList ) |
|
2274 { |
|
2275 CHAT_DP_TXT( "CCAPEngListManager::AttachAttributeListL" ); |
|
2276 |
|
2277 TInt count( aContactLists.MdcaCount() ); |
|
2278 |
|
2279 for ( TInt i( 0 ); i < count; ++i ) |
|
2280 { |
|
2281 TPtrC listId( aContactLists.MdcaPoint( i ) ); |
|
2282 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::AttachAttributeListL, \ |
|
2283 attaching attribute-list to %S" ), &listId ); |
|
2284 |
|
2285 // Attach created attribute-list to our given contact-list |
|
2286 TRAPD( err, iPEngAttributeListStore-> |
|
2287 AttachAttributeListToContactListL( listId, aAttributeList ); ); |
|
2288 CAPresenceUtils::HandleListErrorsL( err ); |
|
2289 } |
|
2290 } |
|
2291 |
|
2292 // ----------------------------------------------------------------------------- |
|
2293 // CCAPEngListManager::DetachAttributeListL |
|
2294 // Cancels pending requests to network side. |
|
2295 // (other items were commented in a header). |
|
2296 // ----------------------------------------------------------------------------- |
|
2297 // |
|
2298 void CCAPEngListManager::DetachAttributeListL( MDesCArray& aContactLists ) |
|
2299 { |
|
2300 CHAT_DP_TXT( "CCAPEngListManager::DetachAttributeListL" ); |
|
2301 |
|
2302 TInt count( aContactLists.MdcaCount() ); |
|
2303 |
|
2304 for ( TInt i( 0 ); i < count; ++i ) |
|
2305 { |
|
2306 TPtrC listId( aContactLists.MdcaPoint( i ) ); |
|
2307 CHAT_DP( D_CHAT_LIT( "CCAPEngListManager::DetachAttributeListL, \ |
|
2308 detaching attribute-list from %S" ), &listId ); |
|
2309 |
|
2310 TRAPD( err, iPEngAttributeListStore-> |
|
2311 DeleteAttributeListFromContactListL( listId ) ); |
|
2312 CAPresenceUtils::HandleListErrorsL( err ); |
|
2313 } |
|
2314 } |
|
2315 |
|
2316 // ----------------------------------------------------------------------------- |
|
2317 // CCAPEngListManager::CancelPendingRequests |
|
2318 // Cancels pending requests to network side. |
|
2319 // (other items were commented in a header). |
|
2320 // ----------------------------------------------------------------------------- |
|
2321 // |
|
2322 void CCAPEngListManager::CancelPendingRequests( ) |
|
2323 { |
|
2324 CHAT_DP_FUNC_ENTER( "CancelPendingRequests" ); |
|
2325 |
|
2326 if ( iPEngContactListUpdater ) |
|
2327 { |
|
2328 iPEngContactListUpdater->CancelContactListPubSync(); |
|
2329 } |
|
2330 if ( iPEngAttributeListPublisher && iAttribListSupported ) |
|
2331 { |
|
2332 iPEngAttributeListPublisher->CancelPublishAttributeLists(); |
|
2333 } |
|
2334 |
|
2335 CHAT_DP_FUNC_DONE( "CancelPendingRequests" ); |
|
2336 } |
|
2337 |
|
2338 // ----------------------------------------------------------------------------- |
|
2339 // CCAPEngListManager::ReplaceAttributesL |
|
2340 // (other items were commented in a header). |
|
2341 // ----------------------------------------------------------------------------- |
|
2342 // |
|
2343 void CCAPEngListManager::ReplaceAttributesL( RArray<TUint32>& aAttributes ) |
|
2344 { |
|
2345 iAttributes = aAttributes; |
|
2346 } |
|
2347 |
|
2348 // ----------------------------------------------------------------------------- |
|
2349 // CCAPEngListManager::ServiceTreeL |
|
2350 // (other items were commented in a header). |
|
2351 // ----------------------------------------------------------------------------- |
|
2352 // |
|
2353 TPEngWVCspServicesTree2 CCAPEngListManager::ServiceTreeL( CPEngNWSessionSlotID2& aSessionSlotID ) |
|
2354 { |
|
2355 CPEngNWSessionSlot2* slot = CPEngNWSessionSlot2::NewLC( aSessionSlotID ); |
|
2356 TPEngWVCspServicesTree2 cspTree; |
|
2357 TPckg<TPEngWVCspServicesTree2> cspTreePtr( cspTree ); |
|
2358 TInt err = slot->GetOption( KPEngWVCspServicesTree2, |
|
2359 KPEngNWSessionSlotTransportQuery, |
|
2360 cspTreePtr ); |
|
2361 |
|
2362 CleanupStack::PopAndDestroy( slot ); |
|
2363 return cspTree; |
|
2364 } |
|
2365 |
|
2366 // ----------------------------------------------------------------------------- |
|
2367 // CCAPEngListManager::AttribListsSupported |
|
2368 // (other items were commented in a header). |
|
2369 // ----------------------------------------------------------------------------- |
|
2370 // |
|
2371 TBool CCAPEngListManager::AttribListsSupportedL( CPEngNWSessionSlotID2& aSessionSlotID ) |
|
2372 { |
|
2373 TPEngWVCspServicesTree2 cspTree = ServiceTreeL( aSessionSlotID ); |
|
2374 TBool attribListsSupported = cspTree.iPresenceFeat.FeatureSupported(); |
|
2375 attribListsSupported &= cspTree.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncCALI ); |
|
2376 attribListsSupported &= cspTree.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncDALI ); |
|
2377 attribListsSupported &= cspTree.iPresenceFeat.SubFunctionSupported( KPEngWVSubFuncGALS ); |
|
2378 return attribListsSupported; |
|
2379 } |
|
2380 |
|
2381 // ----------------------------------------------------------------------------- |
|
2382 // CCAPEngListManager::UpdatePresenceAuthorizeL |
|
2383 // (other items were commented in a header). |
|
2384 // ----------------------------------------------------------------------------- |
|
2385 // |
|
2386 void CCAPEngListManager::UpdatePresenceAuthorizeL() |
|
2387 { |
|
2388 if ( !iAttribListSupported ) |
|
2389 { |
|
2390 // nothing to do if not supported |
|
2391 return; |
|
2392 } |
|
2393 |
|
2394 TInt authValue = |
|
2395 iApplicationSettings->Value( MCASettings::EAuthorizeIMPresence ); |
|
2396 switch ( authValue ) |
|
2397 { |
|
2398 case MCASettings::EAll: |
|
2399 { |
|
2400 CHAT_DP_TXT( "Own presence publish: to all" ); |
|
2401 SetAuthorizationToAllL(); |
|
2402 break; |
|
2403 } |
|
2404 case MCASettings::EFriends: |
|
2405 { |
|
2406 CHAT_DP_TXT( "Own presence publish: to friends" ); |
|
2407 SetAuthorizationToFriendsL(); |
|
2408 break; |
|
2409 } |
|
2410 case MCASettings::ENobody: |
|
2411 { |
|
2412 CHAT_DP_TXT( "Own presence publish: to nobody" ); |
|
2413 SetAuthorizationToNoneL(); |
|
2414 break; |
|
2415 } |
|
2416 default: |
|
2417 { |
|
2418 User::Leave( KErrNotSupported ); |
|
2419 break; |
|
2420 } |
|
2421 } |
|
2422 } |
|
2423 // ----------------------------------------------------------------------------- |
|
2424 // CCAPEngListManager::AddObserver |
|
2425 // (other items were commented in a header). |
|
2426 // ----------------------------------------------------------------------------- |
|
2427 void CCAPEngListManager::AddObserver( MCAListInitObserver* aObserver ) |
|
2428 { |
|
2429 iObserver = aObserver; |
|
2430 } |
|
2431 // ----------------------------------------------------------------------------- |
|
2432 // CCAPEngListManager::RemoveObserver |
|
2433 // (other items were commented in a header). |
|
2434 // ----------------------------------------------------------------------------- |
|
2435 // |
|
2436 void CCAPEngListManager::RemoveObserver() |
|
2437 { |
|
2438 iObserver = NULL; |
|
2439 } |
|
2440 // ----------------------------------------------------------------------------- |
|
2441 // CCAPEngListManager::IsListInitialization |
|
2442 // (other items were commented in a header). |
|
2443 // ----------------------------------------------------------------------------- |
|
2444 // |
|
2445 TBool CCAPEngListManager::IsListInitializationCompleted() |
|
2446 { |
|
2447 return iListInitInProcees; |
|
2448 } |
|
2449 |
|
2450 // End of file |