|
1 /* |
|
2 * Copyright (c) 2006 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: Various tools for List Library |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 #include "PEngListLibTools.h" |
|
21 #include "PEngContactIdsTools.h" |
|
22 |
|
23 #include "CPEngContactListModBase.h" |
|
24 #include "CPEngContactListModItemContainer.h" |
|
25 #include "CPEngContactListModChangeMonitor.h" |
|
26 #include "CPEngContactListSettings.h" |
|
27 #include "MPEngContactListTransactionManager.h" |
|
28 #include "CPEngTransactionStatus.h" |
|
29 #include "PEngXMLTags.h" |
|
30 #include "MPEngXMLParser.h" |
|
31 #include "MPEngXMLSerializer.h" |
|
32 #include "PEngAttrLibFactory.h" |
|
33 #include "MPEngPresenceAttrManager.h" |
|
34 #include "MPEngPresenceAttrTransactionEnv.h" |
|
35 #include "PEngWVPresenceErrors2.h" |
|
36 #include "PresenceDebugPrint.h" |
|
37 |
|
38 |
|
39 |
|
40 // ============================= LOCAL FUNCTIONS =============================== |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // DoIsContactUpdated() |
|
44 // |
|
45 // Checks if: |
|
46 // - the contact has been updated or is new |
|
47 // - or its Nick name was updated |
|
48 // - or contact was added to the contact list |
|
49 // - or server altered contact id, so its length changed |
|
50 // |
|
51 // @param aContact Contact item container |
|
52 // @param aNewContactId Contact Id as server returned it |
|
53 // @param aNewNickName New nick name returned by server |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 inline TBool DoIsContactUpdated( CPEngContactListModItemContainer& aContact, |
|
57 const TDesC& aNewContactId, |
|
58 HBufC* aNewNickName ) |
|
59 { |
|
60 const HBufC* currentNick = aContact.CurrentNick(); |
|
61 |
|
62 TBool newValid( aNewNickName && aNewNickName->Length() ); |
|
63 TBool curentValid( currentNick && currentNick->Length() ); |
|
64 if ( |
|
65 ( !aContact.RefActive( CPEngContactListModItemContainer::ENetworkRef ) ) |
|
66 || |
|
67 ( aNewContactId.Length() != aContact.Id().Length() ) |
|
68 || |
|
69 ( |
|
70 ( newValid |
|
71 || |
|
72 curentValid |
|
73 ) |
|
74 && |
|
75 ( !newValid |
|
76 || |
|
77 !curentValid |
|
78 || |
|
79 ( KErrNone != aNewNickName->Compare( *currentNick ) ) |
|
80 ) |
|
81 ) |
|
82 ) |
|
83 { |
|
84 return ETrue; |
|
85 } |
|
86 return EFalse; |
|
87 |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // DoInsertContactLX() |
|
92 // Inserts contact item to array of parsed contacts |
|
93 // aContactId and aNickName has to be pushed on the top of the clean up stack. |
|
94 // Order of those two items on clean up stack does not matter, as far as they |
|
95 // are on top. |
|
96 // Ownership of the aContactId and aNickName are tranfered to the function. |
|
97 // Function returns EFalse if contact was existing on server before |
|
98 // and ETrue if contact was just created on the server |
|
99 // ----------------------------------------------------------------------------- |
|
100 // |
|
101 TBool DoInsertContactLX( RPointerArray<CPEngContactListModItemContainer>& aParsedContacts, |
|
102 RPointerArray<CPEngContactListModItemContainer>& aServerOrderContacts, |
|
103 const RPointerArray<CPEngContactListModItemContainer>& aOldServerOrder, |
|
104 CPEngContactListModBase& aContactList, |
|
105 TBool aUpdateNickname, |
|
106 HBufC* aContactId, |
|
107 HBufC* aNickName, |
|
108 TInt& aServerIndex, |
|
109 TInt& aOffset, |
|
110 TInt aOldServerCount ) |
|
111 { |
|
112 // get position for insertion |
|
113 TInt pos( KErrNotFound ); |
|
114 |
|
115 if ( KErrNone == aContactList.DoFindContact( aParsedContacts, |
|
116 *aContactId, |
|
117 pos, |
|
118 ETrue ) ) |
|
119 { |
|
120 // contact is twice in the response, server is blabbering |
|
121 // Such a contact was already parsed and inserted, ignore it |
|
122 CleanupStack::PopAndDestroy( 2 ); // aNickName, aContactId |
|
123 return EFalse; |
|
124 } |
|
125 |
|
126 |
|
127 // does contact already exists? |
|
128 // look firs in the server ordered array |
|
129 CPEngContactListModItemContainer* cnt = NULL; |
|
130 TInt serverIndex( aServerIndex + aOffset ); |
|
131 if ( serverIndex < aOldServerCount ) |
|
132 { |
|
133 if ( KErrNone == NContactIdsTools::CompareContactIds( aOldServerOrder[ serverIndex ]->Id(), |
|
134 *aContactId ) ) |
|
135 { |
|
136 cnt = aOldServerOrder[ serverIndex ]; |
|
137 } |
|
138 else |
|
139 { |
|
140 serverIndex++; |
|
141 // look one ahead, in case some contact was deleted |
|
142 if ( ( serverIndex < aOldServerCount ) && |
|
143 ( KErrNone == NContactIdsTools::CompareContactIds( aOldServerOrder[ serverIndex ]->Id(), |
|
144 *aContactId ) ) ) |
|
145 { |
|
146 // some contact was removed from server array, update offset |
|
147 cnt = aOldServerOrder[ serverIndex ]; |
|
148 aOffset++; |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 |
|
154 if ( !cnt ) |
|
155 { |
|
156 cnt = aContactList.FindContactInAll( *aContactId ); |
|
157 // contact was added to the contact, update offset |
|
158 aOffset--; |
|
159 } |
|
160 |
|
161 |
|
162 if ( cnt ) |
|
163 { |
|
164 // add to the array |
|
165 aParsedContacts.InsertL( cnt, pos ); |
|
166 cnt->Open(); // CSI: 65 # |
|
167 |
|
168 // check if nick name has changed |
|
169 if ( DoIsContactUpdated( *cnt, *aContactId, aNickName ) ) |
|
170 { |
|
171 aContactList.ChangeMonitor().InsertAddedContactIdL( *aContactId ); |
|
172 // current nick will be updated out of this condition with nick parsed |
|
173 // from server response, update New Nick of the Conatct Item container |
|
174 if ( aUpdateNickname ) |
|
175 { |
|
176 cnt->RollBackNickname(); |
|
177 } |
|
178 else |
|
179 { |
|
180 cnt->AdoptCurrentNickAsNew(); |
|
181 } |
|
182 } |
|
183 |
|
184 // update contact id as it is given by the network server |
|
185 cnt->SetCurrentNickname( aNickName ); |
|
186 cnt->UpdateContactId( aContactId ); |
|
187 CleanupStack::Pop( 2 ); // nickName, aContactId |
|
188 aServerOrderContacts.AppendL( cnt ); |
|
189 cnt->SetServerIndex( aServerIndex ); |
|
190 aServerIndex++; |
|
191 return !aContactList.ContactExistsOnServer( *cnt ); |
|
192 } |
|
193 else |
|
194 { |
|
195 CPEngContactListModItemContainer* newCnt = |
|
196 CPEngContactListModItemContainer::NewLC( |
|
197 aContactList, |
|
198 *aContactId, |
|
199 aNickName ); |
|
200 aParsedContacts.InsertL( newCnt, pos ); |
|
201 CleanupStack::Pop(); // newCnt |
|
202 aContactList.ChangeMonitor().InsertAddedContactIdL( *aContactId ); |
|
203 CleanupStack::PopAndDestroy( 2 ); // contactId, nickName |
|
204 aServerOrderContacts.AppendL( newCnt ); |
|
205 newCnt->SetServerIndex( aServerIndex ); |
|
206 aServerIndex++; |
|
207 return ETrue; |
|
208 } |
|
209 } |
|
210 |
|
211 // ----------------------------------------------------------------------------- |
|
212 // DoFillChangeMonitorOfRemovedIdsL() |
|
213 // Fills the monitor of removed contact Ids. |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 void DoFillChangeMonitorOfRemovedIdsL( |
|
217 CPEngContactListModBase& aContactList, |
|
218 const RPointerArray<CPEngContactListModItemContainer>& aNewContacts ) |
|
219 { |
|
220 TInt count( aContactList.Count( EPEngCntListNetworkView ) ); |
|
221 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
222 { |
|
223 CPEngContactListModItemContainer* cnt = |
|
224 static_cast<CPEngContactListModItemContainer*> |
|
225 ( &( aContactList.ContactItem( |
|
226 x, |
|
227 EPEngCntListNetworkView ) ) ); |
|
228 |
|
229 if ( KErrNotFound == aNewContacts.Find( cnt ) ) |
|
230 { |
|
231 aContactList.ChangeMonitor().InsertRemovedContactIdL( cnt->Id() ); |
|
232 } |
|
233 } |
|
234 } |
|
235 |
|
236 |
|
237 |
|
238 // ============================ MEMBER FUNCTIONS =============================== |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // NListLibTools::LeaveIfMajorErrorL() |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 void NListLibTools::LeaveIfMajorErrorL( TInt aError ) |
|
245 { |
|
246 if ( ( aError < 0 ) && |
|
247 ( aError != KErrAlreadyExists ) ) |
|
248 { |
|
249 User::Leave( aError ); |
|
250 } |
|
251 } |
|
252 |
|
253 |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // NListLibTools::ParseContactListNickListL() |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 TBool NListLibTools::ParseContactListNickListL( |
|
260 const TDesC8& aResponse, |
|
261 RPointerArray<CPEngContactListModItemContainer>& aParsedContacts, |
|
262 CPEngContactListModBase& aContactList, |
|
263 MPEngXMLParser& aXMLparser1, |
|
264 MPEngXMLParser& aXMLparser2, |
|
265 TBool aUpdateNickname, |
|
266 TInt* aNewContactCount /* NULL */ ) |
|
267 { |
|
268 // check if there is even nick List |
|
269 PENG_DP( D_PENG_LIT( "NListLibTools::ParseContactListNickListL::Decode(KNickList)-Start" ) ); |
|
270 if ( !aXMLparser1.DecodeL( aResponse, KNickList, ETrue ) ) |
|
271 { |
|
272 return EFalse; |
|
273 } |
|
274 PENG_DP( D_PENG_LIT( "NListLibTools::ParseContactListNickListL::Decode(KNickList)-Done" ) ); |
|
275 |
|
276 TPtrC8 nickListBlock( aXMLparser1.ResultL( ) ); |
|
277 TInt newContactCount( 0 ); |
|
278 |
|
279 RPointerArray<CPEngContactListModItemContainer> serverOrderedContacts; |
|
280 CleanupClosePushL( serverOrderedContacts ); |
|
281 |
|
282 TInt serverOrderIndex( 0 ); |
|
283 TInt offset( 0 ); |
|
284 const RPointerArray<CPEngContactListModItemContainer>& oldServerOrder = |
|
285 aContactList.ServerOrderedContacts(); |
|
286 TInt oldServerCount( oldServerOrder.Count() ); |
|
287 |
|
288 |
|
289 // First parse nicks with nick names |
|
290 PENG_DP( D_PENG_LIT( "NListLibTools::ParseContactListNickListL::Decode(KNickName)-Start" ) ); |
|
291 if ( aXMLparser1.DecodeL( nickListBlock, KNickName, ETrue ) ) |
|
292 { |
|
293 PENG_DP( D_PENG_LIT( "NListLibTools::ParseContactListNickListL::Decode(KNickName)-Done" ) ); |
|
294 |
|
295 // Assume server ordered it alphabeticaly, used for speed up |
|
296 for ( TInt x ( aXMLparser1.Count() - 1 ) ; x >= 0 ; --x ) |
|
297 { |
|
298 HBufC* nickName = NULL; |
|
299 HBufC* contactId = NULL; |
|
300 |
|
301 if ( aXMLparser2.DecodeL( aXMLparser1.ResultL( x ), |
|
302 KUserIDXMLTag, |
|
303 EFalse ) ) |
|
304 { |
|
305 // Get contact Id, does not check if there is wv: prefix |
|
306 contactId = aXMLparser2.ResultAsUnicodeTextL(); |
|
307 CleanupStack::PushL( contactId ); |
|
308 } |
|
309 else |
|
310 { |
|
311 // XML package is not valid |
|
312 User::Leave( KErrGeneral ); |
|
313 } |
|
314 |
|
315 if ( aXMLparser2.DecodeL( aXMLparser1.ResultL( x ), |
|
316 KName, |
|
317 EFalse ) ) |
|
318 { |
|
319 nickName = aXMLparser2.ResultAsUnicodeTextL(); |
|
320 } |
|
321 |
|
322 // both contactId and nickName has to be on cleanup stack |
|
323 // before calling DoInsertContactLX, ownership is transfered |
|
324 CleanupStack::PushL( nickName ); |
|
325 newContactCount += DoInsertContactLX( aParsedContacts, |
|
326 serverOrderedContacts, |
|
327 oldServerOrder, |
|
328 aContactList, |
|
329 aUpdateNickname, |
|
330 contactId, |
|
331 nickName, |
|
332 serverOrderIndex, |
|
333 offset, |
|
334 oldServerCount ); |
|
335 } |
|
336 PENG_DP( D_PENG_LIT( "NListLibTools::ParseContactListNickListL::Decode(KNickName)-End" ) ); |
|
337 } |
|
338 |
|
339 |
|
340 // now parse all nicks, to find which were without nicks |
|
341 PENG_DP( D_PENG_LIT( "NListLibTools::ParseContactListNickListL::Decode(KUserIDXMLTag)-Start" ) ); |
|
342 if ( aXMLparser1.DecodeL( nickListBlock, KUserIDXMLTag, EFalse ) ) |
|
343 { |
|
344 PENG_DP( D_PENG_LIT( "NListLibTools::ParseContactListNickListL::Decode(KUserIDXMLTag)-Done" ) ); |
|
345 |
|
346 TInt count ( aXMLparser1.Count() ); |
|
347 TInt alreadyParsed( serverOrderedContacts.Count() ); |
|
348 |
|
349 for ( TInt x ( aXMLparser1.Count() - 1 ) ; x >= 0 ; --x ) |
|
350 { |
|
351 HBufC* nickName = NULL; |
|
352 HBufC* contactId = aXMLparser1.ResultAsUnicodeTextL( x ); |
|
353 |
|
354 // try to add contact if it does not match one from |
|
355 // already parsed contacts, we can use plain compare->faster |
|
356 if ( alreadyParsed && |
|
357 ( KErrNone == serverOrderedContacts[ 0 ]->Id().Compare( *contactId ) ) ) |
|
358 { |
|
359 delete contactId; |
|
360 serverOrderedContacts.Remove( 0 ); |
|
361 alreadyParsed--; |
|
362 continue; |
|
363 } |
|
364 |
|
365 CleanupStack::PushL( contactId ); |
|
366 CleanupStack::PushL( nickName ); |
|
367 |
|
368 // both contactId and nickName has to be on cleanup stack |
|
369 // before calling DoInsertContactLX, ownership is transfered |
|
370 newContactCount += DoInsertContactLX( |
|
371 aParsedContacts, |
|
372 serverOrderedContacts, |
|
373 oldServerOrder, |
|
374 aContactList, |
|
375 aUpdateNickname, |
|
376 contactId, |
|
377 nickName, |
|
378 serverOrderIndex, |
|
379 offset, |
|
380 oldServerCount ); |
|
381 } |
|
382 |
|
383 PENG_DP( D_PENG_LIT( "NListLibTools::ParseContactListNickListL::Decode(KUserIDXMLTag)-End" ) ); |
|
384 } |
|
385 |
|
386 CleanupStack::PopAndDestroy(); // serverOrderedContacts |
|
387 |
|
388 if ( aNewContactCount ) |
|
389 { |
|
390 *aNewContactCount += newContactCount; |
|
391 } |
|
392 |
|
393 |
|
394 // Fill monitor of removed contacts |
|
395 DoFillChangeMonitorOfRemovedIdsL( aContactList, aParsedContacts ); |
|
396 PENG_DP( D_PENG_LIT( "NListLibTools::ParseContactListNickListL::-End" ) ); |
|
397 return ETrue; |
|
398 } |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 // ----------------------------------------------------------------------------- |
|
404 // NListLibTools::ParseContactListIDsL() |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 TBool NListLibTools::ParseContactListIDsL( |
|
408 const TDesC8& aResponse, |
|
409 RPointerArray<CPEngContactListModItemContainer>& aParsedContacts, |
|
410 CPEngContactListModBase& aContactList, |
|
411 MPEngXMLParser& aXMLparser1, |
|
412 TBool aUpdateNickname, |
|
413 TInt* aNewContactCount /* NULL */ ) |
|
414 { |
|
415 TInt newContactCount( 0 ); |
|
416 |
|
417 RPointerArray<CPEngContactListModItemContainer> serverOrderedContacts; |
|
418 CleanupClosePushL( serverOrderedContacts ); |
|
419 |
|
420 // Parse the list |
|
421 if ( aXMLparser1.DecodeL( aResponse, KUserIDXMLTag, EFalse ) ) |
|
422 { |
|
423 HBufC* nickName = NULL; |
|
424 HBufC* contactId = NULL; |
|
425 TInt serverOrderIndex( 0 ); |
|
426 TInt offset( 0 ); |
|
427 |
|
428 |
|
429 const RPointerArray<CPEngContactListModItemContainer>& oldServerOrder = |
|
430 aContactList.ServerOrderedContacts(); |
|
431 TInt oldServerCount( oldServerOrder.Count() ); |
|
432 |
|
433 |
|
434 for ( TInt x ( aXMLparser1.Count() - 1 ) ; x >= 0 ; --x ) |
|
435 { |
|
436 // Get contact Id |
|
437 contactId = aXMLparser1.ResultAsUnicodeTextL( x ); |
|
438 CleanupStack::PushL( contactId ); |
|
439 CleanupStack::PushL( nickName ); |
|
440 |
|
441 // try to add contact |
|
442 // both contactId and nickName has to be on cleanup stack |
|
443 // before calling DoInsertContactLX, ownership is transfered |
|
444 newContactCount += DoInsertContactLX( aParsedContacts, |
|
445 serverOrderedContacts, |
|
446 oldServerOrder, |
|
447 aContactList, |
|
448 aUpdateNickname, |
|
449 contactId, |
|
450 nickName, |
|
451 serverOrderIndex, |
|
452 offset, |
|
453 oldServerCount ); |
|
454 } |
|
455 } |
|
456 |
|
457 CleanupStack::PopAndDestroy(); // serverOrderedContacts |
|
458 |
|
459 if ( aNewContactCount ) |
|
460 { |
|
461 *aNewContactCount += newContactCount; |
|
462 } |
|
463 |
|
464 //Fill monitor of removed contacts |
|
465 DoFillChangeMonitorOfRemovedIdsL( aContactList, aParsedContacts ); |
|
466 |
|
467 return ETrue; |
|
468 } |
|
469 |
|
470 |
|
471 // ----------------------------------------------------------------------------- |
|
472 // NListLibTools::ParseContactListPropertiesL() |
|
473 // ----------------------------------------------------------------------------- |
|
474 // |
|
475 TBool NListLibTools::ParseContactListPropertiesL( const TDesC8& aResponse, |
|
476 CPEngContactListSettings& aSettings, |
|
477 MPEngXMLParser& aXMLparser1, |
|
478 MPEngXMLParser& aXMLparser2 ) |
|
479 { |
|
480 // get a property - Disp name Nick Name tag - UserName Tag |
|
481 TBool updateNeeded( EFalse ); |
|
482 if ( aXMLparser1.DecodeL( aResponse , KProperty, ETrue ) ) |
|
483 { |
|
484 TInt count ( aXMLparser1.Count() ); |
|
485 for ( TInt y( 0 ) ; y < count ; y++ ) |
|
486 { |
|
487 if ( aXMLparser2.DecodeL( aXMLparser1.ResultL( y ), |
|
488 KName, |
|
489 EFalse ) |
|
490 ) |
|
491 { |
|
492 TBool syncMaster( aSettings.Property( |
|
493 KPEngCntLstSyncMaster, |
|
494 KPEngCntLstPropertyNativePermanent ) ); |
|
495 |
|
496 // name tag is there, get name and setting |
|
497 if ( aXMLparser2.ResultL().CompareF( KDispName ) == KErrNone ) |
|
498 { |
|
499 // good here we have a disp name - get it (value) |
|
500 if ( aXMLparser2.DecodeL( aXMLparser1.ResultL( y ), |
|
501 KValue, |
|
502 EFalse ) ) |
|
503 { |
|
504 HBufC* dispName = aXMLparser2.ResultAsUnicodeTextL(); |
|
505 // check if we need some update |
|
506 if ( syncMaster ) |
|
507 { |
|
508 CleanupStack::PushL( dispName ); |
|
509 // check if disp name is same as at local |
|
510 updateNeeded = ( KErrNone != |
|
511 aSettings.DispName().Compare( |
|
512 *dispName ) ); |
|
513 CleanupStack::PopAndDestroy( dispName ); |
|
514 } |
|
515 else |
|
516 { |
|
517 // slave for sync, just store it, safe like this |
|
518 aSettings.PushUpdateDisplayNameL( dispName ); |
|
519 } |
|
520 } |
|
521 continue; |
|
522 } |
|
523 // parse default flag |
|
524 if ( aXMLparser2.ResultL().CompareF( KDefault ) == KErrNone ) |
|
525 { |
|
526 // OK that is settings of the default list |
|
527 // good here we have a disp name - get it (value) |
|
528 if ( aXMLparser2.DecodeL( aXMLparser1.ResultL( y ), |
|
529 KValue, |
|
530 EFalse ) ) |
|
531 { |
|
532 TBool defValue( aXMLparser2.ResultL().CompareF( |
|
533 KXMLValueTrue ) == KErrNone ); |
|
534 |
|
535 if ( syncMaster ) |
|
536 { |
|
537 updateNeeded = ( defValue != aSettings.Property( |
|
538 KPEngCntLstDefault, |
|
539 KPEngCntLstPropertyNativePermanent ) ); |
|
540 } |
|
541 else |
|
542 { |
|
543 aSettings.SetPropertyL( |
|
544 KPEngCntLstDefault, |
|
545 KPEngCntLstPropertyNativePermanent, |
|
546 defValue ); |
|
547 } |
|
548 } |
|
549 } |
|
550 } |
|
551 } |
|
552 } |
|
553 |
|
554 return updateNeeded; |
|
555 } |
|
556 |
|
557 |
|
558 // ----------------------------------------------------------------------------- |
|
559 // NListLibTools::RemoveBadContactsL() |
|
560 // ----------------------------------------------------------------------------- |
|
561 // |
|
562 void NListLibTools::RemoveBadContactsL( |
|
563 const CPEngTransactionStatus& aTransactionStatus, |
|
564 CPEngContactListModBase& aContactList ) |
|
565 { |
|
566 |
|
567 TInt count ( aTransactionStatus.DetailedResultCount() ); |
|
568 for ( TInt x ( 0 ) ; x < count ; ++x ) |
|
569 { |
|
570 const MPEngDetailedResultEntry2& detailedResult = |
|
571 aTransactionStatus.DetailedResult( x ); |
|
572 |
|
573 TPtrC badContactId; |
|
574 if ( KErrNone == detailedResult.GetDetailedDesc( badContactId, |
|
575 EPEngDTPresenceID ) ) |
|
576 { |
|
577 aContactList.RemoveBadContactL( badContactId ); |
|
578 } |
|
579 } |
|
580 } |
|
581 |
|
582 |
|
583 // ----------------------------------------------------------------------------- |
|
584 // NListLibTools::MarkForRemoveBadContactsL() |
|
585 // ----------------------------------------------------------------------------- |
|
586 // |
|
587 void NListLibTools::MarkForRemoveBadContactsL( |
|
588 const CPEngTransactionStatus& aTransactionStatus, |
|
589 CPEngContactListModBase& aContactList ) |
|
590 { |
|
591 TInt count ( aTransactionStatus.DetailedResultCount() ); |
|
592 for ( TInt i ( 0 ) ; i < count ; i++ ) |
|
593 { |
|
594 const MPEngDetailedResultEntry2& detailedResult = |
|
595 aTransactionStatus.DetailedResult( i ); |
|
596 |
|
597 if ( detailedResult.Error() == KPEngNwErrUnknownUser ) |
|
598 { |
|
599 TPtrC badContact; |
|
600 detailedResult.GetDetailedDesc( badContact, |
|
601 EPEngDTPresenceID ); |
|
602 |
|
603 // set contact to be removed at next transaction |
|
604 aContactList.RemoveContactL( badContact ); |
|
605 } |
|
606 } |
|
607 } |
|
608 |
|
609 |
|
610 // ----------------------------------------------------------------------------- |
|
611 // NListLibTools::HarmonizeDefaultContactListSettingsL() |
|
612 // ----------------------------------------------------------------------------- |
|
613 // |
|
614 void NListLibTools::HarmonizeDefaultContactListSettingsL( |
|
615 CPEngContactListSettings& aCntListSettings, |
|
616 MPEngContactListTransactionManager& aManager ) |
|
617 { |
|
618 // update default list settings if needed |
|
619 if ( aCntListSettings.Property( KPEngNewDefaultContactList, |
|
620 KPEngCntLstPropertyNativeCached ) ) |
|
621 { |
|
622 // original default contact list |
|
623 CPEngContactListSettings* defaultCntList = |
|
624 aManager.DefaultCntListSettingsOrNull(); |
|
625 |
|
626 // update old default contact list |
|
627 if ( defaultCntList ) |
|
628 { |
|
629 defaultCntList->DeletePropertyL( |
|
630 KPEngNewDefaultContactList, |
|
631 KPEngCntLstPropertyNativeCached ); |
|
632 |
|
633 defaultCntList->DeletePropertyL( |
|
634 KPEngCntLstDefault, |
|
635 KPEngCntLstPropertyNativePermanent ); |
|
636 } |
|
637 |
|
638 // new default contact list |
|
639 aCntListSettings.DeletePropertyL( KPEngNewDefaultContactList, |
|
640 KPEngCntLstPropertyNativeCached ); |
|
641 |
|
642 aCntListSettings.SetPropertyL( KPEngCntLstDefault, |
|
643 KPEngCntLstPropertyNativePermanent, |
|
644 ETrue ); |
|
645 } |
|
646 } |
|
647 |
|
648 |
|
649 // ----------------------------------------------------------------------------- |
|
650 // NListLibTools::ActivatePresenceAttributesL() |
|
651 // ----------------------------------------------------------------------------- |
|
652 // |
|
653 void NListLibTools::ActivatePresenceAttributesL( |
|
654 const MDesCArray& aContacts, |
|
655 const CPEngSessionSlotId& aSessionSlotId ) |
|
656 { |
|
657 |
|
658 MPEngPresenceAttrTransactionEnv* attributeManager = |
|
659 PEngAttrLibFactory::AttributeTransEnvInstanceLC( aSessionSlotId ); |
|
660 TInt count( aContacts.MdcaCount() ); |
|
661 for ( TInt x( 0 ); x < count ; x++ ) |
|
662 { |
|
663 attributeManager->AddSubscriptionL( aContacts.MdcaPoint( x ) ); |
|
664 } |
|
665 CleanupStack::PopAndDestroy(); // attributeManager |
|
666 } |
|
667 |
|
668 |
|
669 // ----------------------------------------------------------------------------- |
|
670 // NListLibTools::DeactivatePresenceAttributesL() |
|
671 // ----------------------------------------------------------------------------- |
|
672 // |
|
673 void NListLibTools::DeactivatePresenceAttributesL( |
|
674 const MDesCArray& aContacts, |
|
675 const CPEngSessionSlotId& aSessionSlotId ) |
|
676 { |
|
677 MPEngPresenceAttrTransactionEnv* attributeManager = |
|
678 PEngAttrLibFactory::AttributeTransEnvInstanceLC( aSessionSlotId ); |
|
679 |
|
680 const TInt count( aContacts.MdcaCount() ); |
|
681 for ( TInt x( 0 ); x < count ; x++ ) |
|
682 { |
|
683 attributeManager->RemoveSubscriptionL( aContacts.MdcaPoint( x ) ); |
|
684 } |
|
685 CleanupStack::PopAndDestroy(); // attributeManager |
|
686 } |
|
687 |
|
688 |
|
689 // ----------------------------------------------------------------------------- |
|
690 // NListLibTools::AppendTransactionContentTagXmlL() |
|
691 // ----------------------------------------------------------------------------- |
|
692 // |
|
693 void NListLibTools::AppendTransactionContentTagXmlL( MPEngXMLSerializer& aXMLSerializer, |
|
694 TPEngWVCspVersion& aCSPVersion ) |
|
695 { |
|
696 if ( aCSPVersion == EWVCspV11 ) |
|
697 { |
|
698 aXMLSerializer.StartTagL( KTransactionContent ); |
|
699 aXMLSerializer.AttributeL( KXmlXmlns, KTransactionContentNS ); |
|
700 } |
|
701 else |
|
702 { |
|
703 aXMLSerializer.StartTagL( KTransactionContent ); |
|
704 aXMLSerializer.AttributeL( KXmlXmlns, KTransactionContentNS_CSP12 ); |
|
705 } |
|
706 } |
|
707 |
|
708 |
|
709 |
|
710 // ----------------------------------------------------------------------------- |
|
711 // NListLibTools::AppendContactListNameXmlL() |
|
712 // ----------------------------------------------------------------------------- |
|
713 // |
|
714 void NListLibTools::AppendContactListNameXmlL( MPEngXMLSerializer& aXmlSerializer, |
|
715 const CPEngContactListSettings& aSettings ) |
|
716 { |
|
717 // <ContactList> |
|
718 // Contact list name value |
|
719 // </ContactList> |
|
720 aXmlSerializer.StartTagL( KContactList |
|
721 ).WvAddressL( aSettings.ServerName() |
|
722 ).EndTagL( KContactList ); |
|
723 } |
|
724 |
|
725 |
|
726 // ----------------------------------------------------------------------------- |
|
727 // NListLibTools::AppendAttributesForSubscriptionXmlL() |
|
728 // ----------------------------------------------------------------------------- |
|
729 // |
|
730 void NListLibTools::AppendAttributesForSubscriptionXmlL( |
|
731 const RArray<TUint32> aAttributes, |
|
732 MPEngXMLSerializer& aXmlSerializer, |
|
733 const CPEngSessionSlotId& aSessionSlotId, |
|
734 TPEngWVCspVersion& aCSPVersion ) |
|
735 { |
|
736 // array of attributes for subscribing can be empty |
|
737 TInt count ( aAttributes.Count() ); |
|
738 |
|
739 // <PresenceSubList |
|
740 aXmlSerializer.StartTagL( KPresenceSubList ); |
|
741 |
|
742 // if count is zero append just empty PresenceSubList tag |
|
743 if ( count == 0 ) |
|
744 { |
|
745 if ( aCSPVersion == EWVCspV11 ) |
|
746 { |
|
747 // xmlns="http://www.wirelessvillage.org/PA1.1" |
|
748 aXmlSerializer.AttributeL( KXmlXmlns, KPresenceSubListAttributesNS ); |
|
749 } |
|
750 else |
|
751 { |
|
752 // xmlns="http://www.openmobilealliance.org/DTD/WV-PA1.2" |
|
753 aXmlSerializer.AttributeL( KXmlXmlns, KPresenceSubListAttributesNS_CSP12 ); |
|
754 } |
|
755 } |
|
756 else |
|
757 { |
|
758 // xmlns="Name space" |
|
759 // append attribute's namespace according to attributes on the list |
|
760 MPEngPresenceAttrManager* attributeManager = |
|
761 PEngAttrLibFactory::AttributeManagerInstanceLC( |
|
762 aSessionSlotId ); |
|
763 // Append Attribute name space |
|
764 TPtrC8 attributeName; |
|
765 TPtrC8 attributeNameSpace; |
|
766 User::LeaveIfError( attributeManager->GetAttributeXmlNameAndNameSpace( |
|
767 aAttributes[0], |
|
768 attributeName, |
|
769 attributeNameSpace ) ); |
|
770 |
|
771 aXmlSerializer.AttributeL( KXmlXmlns, attributeNameSpace ); |
|
772 |
|
773 // Append attributes one by one |
|
774 for ( TInt x( 0 ) ; x < count ; x++ ) |
|
775 { |
|
776 User::LeaveIfError( attributeManager->GetAttributeXmlNameAndNameSpace( |
|
777 aAttributes[x], |
|
778 attributeName, |
|
779 attributeNameSpace ) ); |
|
780 |
|
781 aXmlSerializer.StartTagL( attributeName |
|
782 ).EndTagL( attributeName ); |
|
783 } |
|
784 CleanupStack::PopAndDestroy(); // attributeManager |
|
785 } |
|
786 |
|
787 // </PresenceSubList> |
|
788 aXmlSerializer.EndTagL( KPresenceSubList ); |
|
789 } |
|
790 |
|
791 |
|
792 // ----------------------------------------------------------------------------- |
|
793 // NListLibTools::AppendContactListPropertiesXmlL() |
|
794 // ----------------------------------------------------------------------------- |
|
795 // |
|
796 void NListLibTools::AppendContactListPropertiesXmlL( |
|
797 MPEngXMLSerializer& aXmlSerializer, |
|
798 const CPEngContactListSettings& aSettings ) |
|
799 { |
|
800 // <ContactListProperties> |
|
801 // <Property> |
|
802 aXmlSerializer.StartTagL( KContactListProperties ). |
|
803 StartTagL( KProperty ); |
|
804 |
|
805 // <Name> |
|
806 // DisplayName |
|
807 // </Name> |
|
808 aXmlSerializer.StartTagL( KName ). |
|
809 NarrowTextL( KDispName ). |
|
810 EndTagL( KName ); |
|
811 |
|
812 // <Value> |
|
813 // display name value |
|
814 // </Value> |
|
815 aXmlSerializer.StartTagL( KValue ). |
|
816 UnicodeTextL( aSettings.DispName() ). |
|
817 EndTagL( KValue ); |
|
818 // </Property> |
|
819 aXmlSerializer.EndTagL( KProperty ); |
|
820 |
|
821 // <Property> |
|
822 aXmlSerializer.StartTagL( KProperty ); |
|
823 |
|
824 // <Name> |
|
825 // Default |
|
826 // </Name> |
|
827 aXmlSerializer.StartTagL( KName ). |
|
828 NarrowTextL( KDefault ). |
|
829 EndTagL( KName ); |
|
830 |
|
831 // <Value> |
|
832 // property value |
|
833 TInt newDefault( aSettings.Property( KPEngNewDefaultContactList, |
|
834 KPEngCntLstPropertyNativePermanent ) ); |
|
835 |
|
836 TBool defaulList( ( aSettings.Property( KPEngCntLstDefault, KPEngCntLstPropertyNativePermanent ) && |
|
837 ( newDefault != KErrCancel ) ) || |
|
838 newDefault ); |
|
839 // </Value> |
|
840 aXmlSerializer.StartTagL( KValue ). |
|
841 NarrowTextL( defaulList ? KXMLValueTrue : KXMLValueFalse ). |
|
842 EndTagL( KValue ); |
|
843 |
|
844 // </Property> |
|
845 // </ContactListProperties> |
|
846 aXmlSerializer.EndTagL( KProperty ). |
|
847 EndTagL( KContactListProperties ); |
|
848 } |
|
849 |
|
850 |
|
851 // ----------------------------------------------------------------------------- |
|
852 // NListLibTools::AppendContactListPropertiesXmlL() |
|
853 // ----------------------------------------------------------------------------- |
|
854 // |
|
855 void NListLibTools::ApppendReceiveListTagL( |
|
856 MPEngXMLSerializer& aXmlSerializer, |
|
857 TPEngWVCspVersion& aCSPVersion, |
|
858 TBool aValue ) |
|
859 { |
|
860 // Only 1.2 version supports ReceiveList tag |
|
861 if ( aCSPVersion != EWVCspV12 ) |
|
862 { |
|
863 return; |
|
864 } |
|
865 |
|
866 aXmlSerializer.StartTagL( KReceiveList ). |
|
867 NarrowTextL( aValue ? KXMLValueTrue : KXMLValueFalse ). |
|
868 EndTagL( KReceiveList ); |
|
869 |
|
870 } |
|
871 // End of File |
|
872 |