|
1 /* |
|
2 * Copyright (c) 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: Contact list add contact handler. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPEngContactListMngTransAddId.h" |
|
21 |
|
22 #include "CPEngContactListModChangeMonitor.h" |
|
23 #include "CPEngContactListSettings.h" |
|
24 #include "CPEngTransactionStatus.h" |
|
25 |
|
26 #include "PEngListLibTools.h" |
|
27 #include "MPEngXMLSerializer.h" |
|
28 #include "MPEngXMLParser.h" |
|
29 |
|
30 #include "PEngWVPresenceErrors2.h" |
|
31 |
|
32 #include "PresenceDebugPrint.h" |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // CPEngContactListMngTransAddId::CPEngContactListMngTransAddId() |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CPEngContactListMngTransAddId::CPEngContactListMngTransAddId( |
|
41 CPEngContactListModBase& aContactList, |
|
42 CPEngSessionSlotId& aSessionSlotId, |
|
43 TPEngWVCspVersion& aCSPVersion, |
|
44 TInt aOperationId ) |
|
45 : CPEngContactListMngTransBase( aContactList, |
|
46 aSessionSlotId, |
|
47 aCSPVersion, |
|
48 aOperationId ) |
|
49 |
|
50 { |
|
51 PENG_DP( D_PENG_LIT( "CPEngContactListMngTransAddId::CPEngContactListMngTransAddId() [%S]" ), |
|
52 &( iContactList.ListProperties().Name() ) ); |
|
53 |
|
54 iUpdateState = EPEngListContentUpdate; |
|
55 } |
|
56 |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CPEngContactListMngTransAddId::ConstructL() |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 void CPEngContactListMngTransAddId::ConstructL() |
|
63 { |
|
64 CPEngContactListMngTransBase::ConstructL( ); |
|
65 } |
|
66 |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CPEngContactListMngTransAddId::NewLC() |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CPEngContactListMngTransAddId* CPEngContactListMngTransAddId::NewLC( |
|
73 CPEngContactListModBase& aContactList, |
|
74 CPEngSessionSlotId& aSessionSlotId, |
|
75 TPEngWVCspVersion& aCSPVersion, |
|
76 TInt aOperationId ) |
|
77 { |
|
78 CPEngContactListMngTransAddId* self = |
|
79 new ( ELeave ) CPEngContactListMngTransAddId( aContactList, |
|
80 aSessionSlotId, |
|
81 aCSPVersion, |
|
82 aOperationId ); |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL( ); |
|
85 return self; |
|
86 } |
|
87 |
|
88 |
|
89 // Destructor |
|
90 CPEngContactListMngTransAddId::~CPEngContactListMngTransAddId() |
|
91 { |
|
92 } |
|
93 |
|
94 |
|
95 // ============================================================================= |
|
96 // =============== Functions from CPEngContactListMngTransBase ================= |
|
97 // ============================================================================= |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CPEngContactListMngTransAddId::DoAppendListNickUpdateL() |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 void CPEngContactListMngTransAddId::DoAppendListNickUpdateL( |
|
104 MPEngXMLSerializer& aXmlSerializer ) |
|
105 { |
|
106 // <AddNickList> |
|
107 aXmlSerializer.StartTagL( KAddNickList ); |
|
108 |
|
109 // fill add nick array |
|
110 RPointerArray<CPEngContactListModItemContainer> addNickList; |
|
111 DoFillNickListLC( addNickList ); |
|
112 |
|
113 TInt count( addNickList.Count() ); |
|
114 for ( TInt x( 0 ); x < count ; ++x ) |
|
115 { |
|
116 // <NickName> |
|
117 // <Name> |
|
118 aXmlSerializer.StartTagL( KNickName |
|
119 ).StartTagL( KName ); |
|
120 // Nick name value |
|
121 // </Name> |
|
122 aXmlSerializer.UnicodeTextL( addNickList[ x ]->NickName() |
|
123 ).EndTagL( KName ); |
|
124 |
|
125 // <UserID> |
|
126 // contact Id value |
|
127 // </UserID> |
|
128 // </NickName> |
|
129 aXmlSerializer.StartTagL( KUserIDXMLTag |
|
130 ).WvAddressL( addNickList[ x ]->Id() |
|
131 ).EndTagL( KUserIDXMLTag |
|
132 ).EndTagL( KNickName ); |
|
133 } |
|
134 CleanupStack::PopAndDestroy(); // addNickList |
|
135 // </AddNickList> |
|
136 aXmlSerializer.EndTagL( KAddNickList ); |
|
137 } |
|
138 |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CPEngContactListMngTransAddId::DoGetXMLSubscriptionUpdateL() |
|
142 // ----------------------------------------------------------------------------- |
|
143 // |
|
144 void CPEngContactListMngTransAddId::DoGetXMLSubscriptionUpdateL( |
|
145 MPEngXMLSerializer& aXmlSerializer ) |
|
146 { |
|
147 // update subscription for new contacts,since server does not |
|
148 // act dynamically and subscription will be updated at next log In |
|
149 |
|
150 // <SubscribePresence-Request> |
|
151 aXmlSerializer.StartTagL( KSubscribePresence ); |
|
152 |
|
153 const MDesCArray& addedNicks = iContactList.ChangeMonitor().AddedContactIds(); |
|
154 |
|
155 // add contacts who needs to be subscribed |
|
156 TInt listCount( addedNicks.MdcaCount() ); |
|
157 for ( TInt x( 0 ) ; x < listCount ; x++ ) |
|
158 { |
|
159 // <User> |
|
160 // <UserID> |
|
161 aXmlSerializer.StartTagL( KUser |
|
162 ).StartTagL( KUserIDXMLTag ); |
|
163 |
|
164 // subscribed contact |
|
165 aXmlSerializer.WvAddressL( addedNicks.MdcaPoint( x ) ); |
|
166 |
|
167 // </UserID> |
|
168 // </User> |
|
169 aXmlSerializer.EndTagL( KUserIDXMLTag |
|
170 ).EndTagL( KUser ); |
|
171 } |
|
172 |
|
173 // append set of presence attributes to be subscribed |
|
174 NListLibTools::AppendAttributesForSubscriptionXmlL( |
|
175 iContactList.Settings().SubscriptionAttributes(), |
|
176 aXmlSerializer, |
|
177 iSessionSlotId, |
|
178 iCSPVersion ); |
|
179 |
|
180 // </SubscribePresence-Request> |
|
181 aXmlSerializer.EndTagL( KSubscribePresence ); |
|
182 } |
|
183 |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CPEngContactListMngTransAddId::DoParseSubscriptionUpdateResponseL() |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CPEngContactListMngTransAddId::DoParseSubscriptionUpdateResponseL( |
|
190 const TDesC8& aResponse ) |
|
191 { |
|
192 PENG_DP( D_PENG_LIT( "CPEngContactListMngTransAddId::ParseSubscriptionUpdateResponseL() [%S]" ), |
|
193 &( iContactList.ListProperties().Name() ) ); |
|
194 |
|
195 // new added contact are in the monitor |
|
196 CPEngContactListModChangeMonitor& changeMonitor = iContactList.ChangeMonitor(); |
|
197 |
|
198 CPEngTransactionStatus* transactionStatus = CPEngTransactionStatus::NewL(); |
|
199 CleanupClosePushL( *transactionStatus ); |
|
200 |
|
201 MPEngXMLParser* xMLparser = CreateXMLParserLC(); |
|
202 TInt err ( xMLparser->ParseContactListResultL( aResponse, |
|
203 iOperationId, |
|
204 iContactList.StorageId(), |
|
205 *transactionStatus ) ); |
|
206 |
|
207 CleanupStack::PopAndDestroy(); // xMLparser |
|
208 |
|
209 switch ( err ) |
|
210 { |
|
211 case KErrNone: |
|
212 { |
|
213 // transaction was successful |
|
214 DoUpdateTransactionState(); |
|
215 break; |
|
216 } |
|
217 |
|
218 |
|
219 case KPEngNwErrPartiallySuccessful: |
|
220 { |
|
221 // partial success |
|
222 // check just wrong contact WV IDs |
|
223 TInt count ( transactionStatus->DetailedResultCount() ); |
|
224 for ( TInt i ( 0 ) ; i < count ; i++ ) |
|
225 { |
|
226 const MPEngDetailedResultEntry2& detailedResult = |
|
227 transactionStatus->DetailedResult( i ); |
|
228 |
|
229 // what ever error, rollback that WV ID |
|
230 if ( !iRollBackIDsArray ) // create rollback array if needed |
|
231 { |
|
232 iRollBackIDsArray = new ( ELeave ) CDesCArrayFlat( count ); |
|
233 } |
|
234 |
|
235 // if contact Id was not subscribed, then remove it |
|
236 iUpdateState = EPEngRollBack; // rollback will be needed |
|
237 TPtrC badContactId; |
|
238 if ( KErrNone == detailedResult.GetDetailedDesc( badContactId, EPEngDTPresenceID ) ) |
|
239 { |
|
240 // mark bad contact Id for rollback |
|
241 iRollBackIDsArray->AppendL( badContactId ); |
|
242 changeMonitor.RemoveAddedContactId( badContactId ); |
|
243 iContactList.RemoveContactL( badContactId ); |
|
244 iUpdateState = EPEngRollBack; |
|
245 } |
|
246 } |
|
247 break; |
|
248 } |
|
249 |
|
250 |
|
251 case KPEngNwErrUnknownUser: |
|
252 default: // any other error means something wrong, need of rollback |
|
253 { |
|
254 // all contacts are bad, mark contacts for removing |
|
255 TInt idCount ( changeMonitor.CountAddedContactIds() ); |
|
256 if ( !idCount ) |
|
257 { |
|
258 // nothing to roll back, completed |
|
259 iUpdateState = EPEngTransactionCompleted; |
|
260 break; |
|
261 } |
|
262 |
|
263 |
|
264 // create rollback array if needed |
|
265 if ( !iRollBackIDsArray ) |
|
266 { |
|
267 iRollBackIDsArray = new ( ELeave ) CDesCArrayFlat( idCount ); |
|
268 } |
|
269 |
|
270 |
|
271 for ( TInt ii ( 0 ) ; ii < idCount ; ii++ ) |
|
272 { |
|
273 // store wrong contact ids to the container |
|
274 TPtrC badContactId ( changeMonitor.AddedContactIds().MdcaPoint( ii ) ); |
|
275 iTransactionStatus->AddDetailedResultL( iOperationId, |
|
276 KPEngNwErrUnknownUser, |
|
277 NULL, |
|
278 &badContactId, |
|
279 &( iContactList.StorageId() ), |
|
280 NULL ); |
|
281 |
|
282 // mark bad contact Id for rollback |
|
283 iRollBackIDsArray->AppendL( badContactId ); |
|
284 changeMonitor.RemoveAddedContactId( badContactId ); |
|
285 iContactList.RemoveContactL( badContactId ); |
|
286 } |
|
287 iUpdateState = EPEngRollBack; |
|
288 } |
|
289 } |
|
290 |
|
291 |
|
292 // import transaction status, takes ownership |
|
293 iTransactionStatus->ImportStatusFrom( *transactionStatus ); |
|
294 CleanupStack::Pop(); // transactionStatus |
|
295 |
|
296 PENG_DP( D_PENG_LIT( "CPEngContactListMngTransAddId::ParseSubscriptionUpdateResponseL() done [%S]" ), |
|
297 &( iContactList.ListProperties().Name() ) ); |
|
298 } |
|
299 |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CPEngContactListMngTransAddId::DoUpdateTransactionState() |
|
303 // ----------------------------------------------------------------------------- |
|
304 // |
|
305 void CPEngContactListMngTransAddId::DoUpdateTransactionState() |
|
306 { |
|
307 switch ( iUpdateState ) |
|
308 { |
|
309 case EPEngListContentUpdate: |
|
310 { |
|
311 // in CSP version 1.2 auto subscribe is enabled |
|
312 if ( iContactList.Settings().Property( KPEngCntLstSubscribe, |
|
313 KPEngCntLstPropertyNativePermanent ) |
|
314 && iNewIdsCount |
|
315 && ( iCSPVersion == EWVCspV11 ) ) |
|
316 { |
|
317 iUpdateState = EPEngSubscriptionUpdate; |
|
318 } |
|
319 else |
|
320 { |
|
321 iUpdateState = EPEngActivateAttributes; |
|
322 } |
|
323 break; |
|
324 } |
|
325 |
|
326 |
|
327 // Subscription and rollback both are treated same |
|
328 case EPEngSubscriptionUpdate: |
|
329 case EPEngRollBack: |
|
330 { |
|
331 iUpdateState = EPEngTransactionCompleted; |
|
332 break; |
|
333 } |
|
334 |
|
335 default: |
|
336 { |
|
337 break; |
|
338 } |
|
339 } |
|
340 } |
|
341 |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CPEngContactListMngTransAddId::DoFillNickListLC() |
|
345 // ----------------------------------------------------------------------------- |
|
346 // |
|
347 void CPEngContactListMngTransAddId::DoFillNickListLC( |
|
348 RPointerArray<CPEngContactListModItemContainer>& aNickList ) |
|
349 { |
|
350 CleanupClosePushL( aNickList ); |
|
351 iContactList.FillAddNickListL( aNickList ); |
|
352 } |
|
353 |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // CPEngContactListMngTransAddId::DoCompleteContactListUpdateL() |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 void CPEngContactListMngTransAddId::DoCompleteContactListUpdateL() |
|
360 { |
|
361 iContactList.CommitAddContactsL(); |
|
362 } |
|
363 |
|
364 // End of File |