|
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: Update handler to remove contacts from contact list |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngContactListMngTransRemoveId.h" |
|
20 #include "CPEngContactListModItemContainer.h" |
|
21 #include "CPEngContactListModChangeMonitor.h" |
|
22 #include "CPEngContactListSettings.h" |
|
23 #include "MPEngXMLParser.h" |
|
24 #include "MPEngXMLSerializer.h" |
|
25 #include "PEngXMLTags.h" |
|
26 |
|
27 #include "CPEngTransactionStatus.h" |
|
28 #include "PEngWVPresenceErrors2.h" |
|
29 |
|
30 #include "PEngAttrLibFactory.h" |
|
31 #include "MPEngPresenceAttrTransactionEnv.h" |
|
32 |
|
33 #include "PresenceDebugPrint.h" |
|
34 |
|
35 |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CPEngContactListMngTransRemoveId::CPEngContactListMngTransRemoveId() |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CPEngContactListMngTransRemoveId::CPEngContactListMngTransRemoveId( |
|
43 CPEngContactListModBase& aContactList, |
|
44 CPEngSessionSlotId& aSessionSlot, |
|
45 TPEngWVCspVersion& aCSPVersion, |
|
46 TInt aOperationId ) |
|
47 : CPEngContactListMngTransBase( aContactList, |
|
48 aSessionSlot, |
|
49 aCSPVersion, |
|
50 aOperationId ) |
|
51 { |
|
52 PENG_DP( D_PENG_LIT( "CPEngContactListMngTransRemoveId::CPEngContactListMngTransRemoveId() [%S]" ), |
|
53 &( iContactList.ListProperties().Name() ) ); |
|
54 |
|
55 |
|
56 // if server supports CSP 1.2 => no need to unsubscribe, it is done automaticaly |
|
57 if ( iContactList.Settings().Property( KPEngCntLstSubscribe , |
|
58 KPEngCntLstPropertyNativePermanent ) && |
|
59 ( iCSPVersion == EWVCspV11 ) ) |
|
60 { |
|
61 iUpdateState = EPEngSubscriptionUpdate; |
|
62 } |
|
63 |
|
64 else |
|
65 { |
|
66 iUpdateState = EPEngListContentUpdate; |
|
67 } |
|
68 } |
|
69 |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CPEngContactListMngTransRemoveId::ConstructL() |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 void CPEngContactListMngTransRemoveId::ConstructL() |
|
76 { |
|
77 CPEngContactListMngTransBase::ConstructL( ); |
|
78 } |
|
79 |
|
80 |
|
81 // ----------------------------------------------------------------------------- |
|
82 // CPEngContactListMngTransRemoveId::NewLC() |
|
83 // ----------------------------------------------------------------------------- |
|
84 // |
|
85 CPEngContactListMngTransRemoveId* CPEngContactListMngTransRemoveId::NewLC( |
|
86 CPEngContactListModBase& aContactList, |
|
87 CPEngSessionSlotId& aSessionSlot, |
|
88 TPEngWVCspVersion& aCSPVersion, |
|
89 TInt aOperationId ) |
|
90 { |
|
91 // first push aContact to cleanUpStack |
|
92 CPEngContactListMngTransRemoveId* self = new ( ELeave ) |
|
93 CPEngContactListMngTransRemoveId( |
|
94 aContactList, |
|
95 aSessionSlot, |
|
96 aCSPVersion, |
|
97 aOperationId ); |
|
98 CleanupStack::PushL( self ); |
|
99 self->ConstructL( ); |
|
100 |
|
101 return self; |
|
102 } |
|
103 |
|
104 |
|
105 // Destructor |
|
106 CPEngContactListMngTransRemoveId::~CPEngContactListMngTransRemoveId() |
|
107 { |
|
108 } |
|
109 |
|
110 |
|
111 |
|
112 // ============================================================================= |
|
113 // =============== Functions from CPEngContactListMngTransBase ================= |
|
114 // ============================================================================= |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CPEngContactListMngTransRemoveId::DoAppendListNickUpdateL() |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CPEngContactListMngTransRemoveId::DoAppendListNickUpdateL( |
|
121 MPEngXMLSerializer& aXmlSerializer ) |
|
122 { |
|
123 // <RemoveNickList> |
|
124 aXmlSerializer.StartTagL( KRemoveNickList ); |
|
125 |
|
126 RPointerArray<CPEngContactListModItemContainer> removeNickList; |
|
127 DoFillNickListLC( removeNickList ); |
|
128 |
|
129 // insert contact Id to remove |
|
130 TInt count( removeNickList.Count() ); |
|
131 |
|
132 for ( TInt x( 0 ); x < count ; x++ ) |
|
133 { |
|
134 // <UserID> |
|
135 // contact Id value |
|
136 // </UserID> |
|
137 aXmlSerializer.StartTagL( KUserIDXMLTag |
|
138 ).WvAddressL( removeNickList[ x ]->Id() |
|
139 ).EndTagL( KUserIDXMLTag ); |
|
140 } |
|
141 CleanupStack::PopAndDestroy(); // removeNickList |
|
142 // </RemoveNickList> |
|
143 aXmlSerializer.EndTagL( KRemoveNickList ); |
|
144 } |
|
145 |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CPEngContactListMngTransRemoveId::DoGetXMLSubscriptionUpdateL() |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 void CPEngContactListMngTransRemoveId::DoGetXMLSubscriptionUpdateL( |
|
152 MPEngXMLSerializer& aXmlSerializer ) |
|
153 { |
|
154 // remove subscription from removed contacts,since server does not |
|
155 // act dynamically and subscription will be removed at next log In |
|
156 |
|
157 // <UnsubscribePresence-Request> |
|
158 aXmlSerializer.StartTagL( KUnsubscribePresence ); |
|
159 |
|
160 RPointerArray<CPEngContactListModItemContainer> removeNickList; |
|
161 DoFillNickListLC( removeNickList ); |
|
162 |
|
163 // add those fellas we do not need anymore te be subscribed |
|
164 TInt count( removeNickList.Count() ); |
|
165 for ( TInt x( 0 ) ; x < count ; x++ ) |
|
166 { |
|
167 // <User> |
|
168 // <UserID> |
|
169 aXmlSerializer.StartTagL( KUser |
|
170 ).StartTagL( KUserIDXMLTag ); |
|
171 |
|
172 // now fella we wanna unsubscribe |
|
173 aXmlSerializer.WvAddressL( removeNickList[ x ]->Id() ); |
|
174 |
|
175 // </UserID> |
|
176 // </User> |
|
177 aXmlSerializer.EndTagL( KUserIDXMLTag |
|
178 ).EndTagL( KUser ); |
|
179 } |
|
180 |
|
181 CleanupStack::PopAndDestroy(); // removeNickList |
|
182 // </UnsubscribePresence-Request> |
|
183 aXmlSerializer.EndTagL( KUnsubscribePresence ); |
|
184 } |
|
185 |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CPEngContactListMngTransRemoveId::DoParseSubscriptionUpdateResponseL() |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CPEngContactListMngTransRemoveId::DoParseSubscriptionUpdateResponseL( |
|
192 const TDesC8& aResponse ) |
|
193 { |
|
194 PENG_DP( D_PENG_LIT( "CPEngContactListMngTransRemoveId::DoParseSubscriptionUpdateResponseL() [%S]" ), |
|
195 &( iContactList.ListProperties().Name() ) ); |
|
196 |
|
197 MPEngXMLParser* XMLparser = CreateXMLParserLC(); |
|
198 // try if there were some errors |
|
199 CPEngTransactionStatus* transactionStatus = CPEngTransactionStatus::NewL(); |
|
200 CleanupClosePushL( *transactionStatus ); |
|
201 TInt err ( XMLparser->ParseContactListResultL( aResponse, |
|
202 iOperationId, |
|
203 iContactList.StorageId(), |
|
204 *transactionStatus ) ); |
|
205 |
|
206 // clean all attribute models for all contacts we are trying to delete |
|
207 RPointerArray<CPEngContactListModItemContainer> removeNickList; |
|
208 DoFillNickListLC( removeNickList ); |
|
209 |
|
210 MPEngPresenceAttrTransactionEnv* attributeManager = |
|
211 PEngAttrLibFactory::AttributeTransEnvInstanceLC( iSessionSlotId ); |
|
212 |
|
213 TInt count ( removeNickList.Count() ); |
|
214 for ( TInt x( 0 ) ; x < count ; ++x ) |
|
215 { |
|
216 attributeManager->RemoveSubscriptionL( removeNickList[ x ]->Id() ); |
|
217 } |
|
218 CleanupStack::PopAndDestroy( 2 ); // attributeManager, removeNickList |
|
219 |
|
220 |
|
221 iTransactionStatus->ImportStatusFrom( *transactionStatus ); |
|
222 CleanupStack::Pop(); // transactionStatus |
|
223 CleanupStack::PopAndDestroy( ); // XMLparser |
|
224 |
|
225 |
|
226 // was it one the errors that we can continue with request? |
|
227 if ( ( err == KErrNone ) |
|
228 || ( err == KPEngNwErrPartiallySuccessful ) |
|
229 || ( err == KPEngNwErrUnknownUser ) |
|
230 || ( err == KPEngNwErrServiceUnavailable ) ) |
|
231 { |
|
232 // Continue with next step |
|
233 DoUpdateTransactionState(); |
|
234 } |
|
235 else |
|
236 { |
|
237 // Error was something bigger, terminate transaction |
|
238 iUpdateState = EPEngTransactionCompleted; |
|
239 } |
|
240 |
|
241 |
|
242 PENG_DP( D_PENG_LIT( "CPEngContactListMngTransRemoveId::DoParseSubscriptionUpdateResponseL() done [%S]" ), |
|
243 &( iContactList.ListProperties().Name() ) ); |
|
244 } |
|
245 |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CPEngContactListMngTransRemoveId::DoUpdateTransactionState() |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 void CPEngContactListMngTransRemoveId::DoUpdateTransactionState() |
|
252 { |
|
253 switch ( iUpdateState ) |
|
254 { |
|
255 case EPEngListContentUpdate: |
|
256 { |
|
257 if ( iContactList.Settings().Property( KPEngCntLstSubscribe, |
|
258 KPEngCntLstPropertyNativePermanent ) |
|
259 && ( iCSPVersion == EWVCspV12 ) ) |
|
260 { |
|
261 iUpdateState = EPEngDeActivateAttributes; |
|
262 } |
|
263 else |
|
264 { |
|
265 iUpdateState = EPEngTransactionCompleted; |
|
266 } |
|
267 break; |
|
268 } |
|
269 |
|
270 |
|
271 case EPEngSubscriptionUpdate: |
|
272 { |
|
273 iUpdateState = EPEngListContentUpdate; |
|
274 break; |
|
275 } |
|
276 |
|
277 |
|
278 case EPEngRollBack: |
|
279 { |
|
280 iUpdateState = EPEngTransactionCompleted; |
|
281 } |
|
282 |
|
283 |
|
284 default: |
|
285 { |
|
286 break; |
|
287 } |
|
288 } |
|
289 } |
|
290 |
|
291 |
|
292 // ----------------------------------------------------------------------------- |
|
293 // CPEngContactListMngTransRemoveId::DoFillNickListLC() |
|
294 // ----------------------------------------------------------------------------- |
|
295 // |
|
296 void CPEngContactListMngTransRemoveId::DoFillNickListLC( |
|
297 RPointerArray<CPEngContactListModItemContainer>& aNickList ) |
|
298 { |
|
299 CleanupClosePushL( aNickList ); |
|
300 iContactList.FillRemoveNickListL( aNickList ); |
|
301 } |
|
302 |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CPEngContactListMngTransRemoveId::DoCompleteContactListUpdateL() |
|
306 // ----------------------------------------------------------------------------- |
|
307 // |
|
308 void CPEngContactListMngTransRemoveId::DoCompleteContactListUpdateL() |
|
309 { |
|
310 iContactList.CommitRemoveContactsL(); |
|
311 } |
|
312 |
|
313 |
|
314 // End of File |
|
315 |