|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: XML importer |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 #include <CVPbkContactManager.h> // CVPbkContactManager |
|
20 #include <MVPbkContactOperationBase.h> // MVPbkContactOperationBase |
|
21 #include <MVPbkContactLinkArray.h> // MVPbkContactLinkArray |
|
22 #include <CVPbkContactLinkArray.h> // CVPbkContactLinkArray |
|
23 #include <MVPbkContactLink.h> // MVPbkContactLink |
|
24 #include <MVPbkContactOperation.h> // MVPbkContactOperation |
|
25 #include <e32def.h> |
|
26 |
|
27 // User includes |
|
28 #include "pdccontactdeletion.h" // CPdcContactDeletion |
|
29 #include "pdclogger.h" |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // CPdcContactDeletion::NewL |
|
35 // Symbian 1st phase constructor |
|
36 // @param aFs file system |
|
37 // @param aContactDatabase contacts database |
|
38 // @return Self pointer to CPdcContactDeletion pushed to |
|
39 // the cleanup stack. |
|
40 // --------------------------------------------------------------------------- |
|
41 // |
|
42 CPdcContactDeletion* CPdcContactDeletion::NewL( |
|
43 CVPbkContactManager& aContactManager ) |
|
44 { |
|
45 CPdcContactDeletion* self = new( ELeave ) |
|
46 CPdcContactDeletion( aContactManager); |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CPdcContactDeletion::~CPdcContactDeletion |
|
55 // Destructor |
|
56 // --------------------------------------------------------------------------- |
|
57 // |
|
58 CPdcContactDeletion::~CPdcContactDeletion() |
|
59 { |
|
60 delete iDeleteOp; |
|
61 delete iLinkArray; |
|
62 delete iDeleteArray; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CPdcContactDeletion::CPdcContactDeletion |
|
67 // C++ constructor |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 CPdcContactDeletion::CPdcContactDeletion( |
|
71 CVPbkContactManager& aContactManager ) |
|
72 : iContactManager( aContactManager ) |
|
73 { |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CPdcContactDeletion::ConstructL |
|
78 // Second-phase constructor |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 void CPdcContactDeletion::ConstructL() |
|
82 { |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // CPdcContactDeletion::GetXmlContactsL |
|
87 // Starts the asyncronous deletion of existing contacts |
|
88 // @param aLinkArray array of links to contacts to be deleted, |
|
89 // takes ownership |
|
90 // @param aCallerStatus iStatus of caller |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 void CPdcContactDeletion::DeleteContactsL( MVPbkContactLinkArray* aLinkArray, |
|
94 TRequestStatus& aCallerStatus,TBool aDeleteStoredContact ) |
|
95 { |
|
96 LOGTEXT(_L("CPdcContactDeletion::DeleteContactsL")); |
|
97 iDeleteStoredContact = aDeleteStoredContact; |
|
98 |
|
99 // Create the array of links |
|
100 iDeleteArray = CVPbkContactLinkArray::NewL(); |
|
101 |
|
102 // Set the index to the number of contacts in the link array. |
|
103 iLinkArray = aLinkArray; |
|
104 iIndex = iLinkArray->Count(); |
|
105 |
|
106 // Store the caller's request status |
|
107 iCallerStatus = &aCallerStatus; |
|
108 aCallerStatus = KRequestPending; |
|
109 |
|
110 // Delete the contacts |
|
111 DeleteNextContact(); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------------------------- |
|
115 // CPdcContactDeletion::Cancel |
|
116 // Cancels the deletion process |
|
117 // --------------------------------------------------------------------------- |
|
118 // |
|
119 void CPdcContactDeletion::Cancel() |
|
120 { |
|
121 LOGTEXT(_L("CPdcContactDeletion::Cancel")); |
|
122 |
|
123 if( iDeleteOp ) |
|
124 { |
|
125 // The delete operation is cancelled by deleting the operation. |
|
126 MVPbkContactOperation* contactOp = |
|
127 STATIC_CAST( MVPbkContactOperation*, iDeleteOp ); |
|
128 contactOp->Cancel(); |
|
129 } |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CPdcContactDeletion::StepComplete |
|
134 // From MVPbkBatchOperationObserver. |
|
135 // Called when one step of the delete operation is completed. |
|
136 // IGNORED |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CPdcContactDeletion::StepComplete( |
|
140 MVPbkContactOperationBase& /*aOperation*/, TInt /*aStepSize*/ ) |
|
141 { |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------------------------- |
|
145 // CPdcContactDeletion::StepFailed |
|
146 // From MVPbkBatchOperationObserver. |
|
147 // Called when one step of the delete operation fails. |
|
148 // |
|
149 // @return ETrue if the batch operation should continue, |
|
150 // EFalse otherwise |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 TBool CPdcContactDeletion::StepFailed( |
|
154 MVPbkContactOperationBase& /*aOperation*/, |
|
155 TInt /*aStepSize*/, TInt /*aError*/ ) |
|
156 { |
|
157 LOGTEXT(_L("CPdcContactDeletion::StepFailed")); |
|
158 // Attempt to delete the next contact if it exists |
|
159 if( iDeleteStoredContact) |
|
160 { |
|
161 DeleteNextContact(); |
|
162 } |
|
163 else |
|
164 { |
|
165 User::RequestComplete( iCallerStatus, KErrNone ); |
|
166 } |
|
167 return EFalse; |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------------------------- |
|
171 // CPdcContactDeletion::OperationComplete |
|
172 // From MVPbkBatchOperationObserver. |
|
173 // Called when delete operation is completed. |
|
174 // This is called when all steps are executed. |
|
175 // |
|
176 // @param aOperation the completed operation |
|
177 // --------------------------------------------------------------------------- |
|
178 // |
|
179 void CPdcContactDeletion::OperationComplete( |
|
180 MVPbkContactOperationBase& /*aOperation*/ ) |
|
181 { |
|
182 LOGTEXT(_L("CPdcContactDeletion::OperationComplete")); |
|
183 // Attempt to delete the next contact if it exists |
|
184 if( iDeleteStoredContact) |
|
185 { |
|
186 DeleteNextContact(); |
|
187 } |
|
188 else |
|
189 { |
|
190 User::RequestComplete( iCallerStatus, KErrNone ); |
|
191 } |
|
192 } |
|
193 |
|
194 // --------------------------------------------------------------------------- |
|
195 // CPdcContactDeletion::DeleteNextContact() |
|
196 // Traps the leaving function DeleteNextContactL() |
|
197 // |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 void CPdcContactDeletion::DeleteNextContact() |
|
201 { |
|
202 LOGTEXT(_L("CPdcContactDeletion::DeleteNextContact")); |
|
203 TBool nextContact = EFalse; |
|
204 |
|
205 // Attempt to delete the next contact, if there is no |
|
206 // more contacts complete the caller's TRequestStatus |
|
207 TRAP_IGNORE( ( nextContact = DeleteNextContactL() )) |
|
208 if ( !nextContact ) |
|
209 { |
|
210 User::RequestComplete( iCallerStatus, KErrNone ); |
|
211 } |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // CPdcContactDeletion::DeleteNextContactL() |
|
216 // Deletes first contact in the link array, and removes it from the list. |
|
217 // |
|
218 // IMPORTANT NOTE: |
|
219 // Each contact in the link array needs to be deleted individually. Although |
|
220 // CVPbkContactManager::DeleteContactsL can delete an array of contacts if the |
|
221 // deletion process fails for some reason such as the contact has already been |
|
222 // deleted, it does not continue to delete the rest of the elements. ( The |
|
223 // in-code description for the MVPbkBatchOperationObserver callback appear to |
|
224 // be incorrect ). |
|
225 // |
|
226 // @return ETrue if there is a contact to be deleted. |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 TBool CPdcContactDeletion::DeleteNextContactL() |
|
230 { |
|
231 TBool returnValue = EFalse; |
|
232 |
|
233 // Decrement the index |
|
234 --iIndex; |
|
235 if ( iIndex >= 0 ) |
|
236 { |
|
237 // There is a contact to be deleted |
|
238 returnValue = ETrue; |
|
239 |
|
240 // Remove any entries in the delete array |
|
241 if ( iDeleteArray->Count() != 0 ) |
|
242 { |
|
243 iDeleteArray->Delete( 0 ); |
|
244 } |
|
245 |
|
246 // Get the link to be deleted |
|
247 const MVPbkContactLink& link = iLinkArray->At( iIndex ); |
|
248 |
|
249 // Create a copy of the link and add it to |
|
250 // the delete array |
|
251 MVPbkContactLink* copiedLink = link.CloneLC(); |
|
252 iDeleteArray->AppendL( copiedLink ); |
|
253 CleanupStack::Pop(); // copiedLink |
|
254 |
|
255 // delete the existing operation |
|
256 delete iDeleteOp; |
|
257 iDeleteOp = NULL; |
|
258 |
|
259 // Create the delete operation |
|
260 iDeleteOp = iContactManager.DeleteContactsL( *iDeleteArray, *this ); |
|
261 } |
|
262 |
|
263 return returnValue; |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // CPdcContactDeletion::DeleteStoredContactsL |
|
268 // Starts the asyncronous deletion of existing contacts |
|
269 // @param aLinkArray array of links to contacts to be deleted, |
|
270 // takes ownership |
|
271 // @param aCallerStatus iStatus of caller |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 void CPdcContactDeletion::DeleteStoredContactsL( |
|
275 MVPbkContactLinkArray* aLinkArray, |
|
276 TRequestStatus& aCallerStatus, |
|
277 TBool aDeleteStoredContact ) |
|
278 { |
|
279 LOGTEXT(_L("CPdcContactDeletion::DeleteStoredContactsL")); |
|
280 iDeleteStoredContact = aDeleteStoredContact; |
|
281 |
|
282 // Create the array of links |
|
283 delete iDeleteArray; |
|
284 iDeleteArray = NULL; |
|
285 |
|
286 iDeleteArray = CVPbkContactLinkArray::NewL(); |
|
287 |
|
288 // Set the index to the number of contacts in the link array. |
|
289 MVPbkContactLinkArray* linkArray = aLinkArray; |
|
290 |
|
291 iIndex = linkArray->Count(); |
|
292 |
|
293 while(iIndex) |
|
294 { |
|
295 const MVPbkContactLink& link = linkArray->At( iIndex-1 ); |
|
296 |
|
297 // Create a copy of the link and add it to |
|
298 // the delete array |
|
299 MVPbkContactLink* copiedLink = link.CloneLC(); |
|
300 iDeleteArray->AppendL( copiedLink ); |
|
301 CleanupStack::Pop(); // copiedLin |
|
302 iIndex--; |
|
303 } |
|
304 |
|
305 delete iDeleteOp; |
|
306 iDeleteOp = NULL; |
|
307 |
|
308 iDeleteOp = iContactManager.DeleteContactsL( *iDeleteArray, *this ); |
|
309 |
|
310 // Store the caller's request status |
|
311 iCallerStatus = &aCallerStatus; |
|
312 aCallerStatus = KRequestPending; |
|
313 } |
|
314 |
|
315 // End of File |