62
|
1 |
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
|
|
17 |
#include <e32std.h>
|
|
18 |
|
|
19 |
#include "MSVSTD.H"
|
|
20 |
#include "MSVSTORE.H"
|
|
21 |
#include "MSVIDS.H"
|
|
22 |
|
|
23 |
#include "MSVENTRY.H"
|
|
24 |
#include "MSVSERV.H"
|
|
25 |
#include "MSVLOPS.H"
|
|
26 |
#include "MSVMOVE.H"
|
|
27 |
#include "MSVCOPY.H"
|
|
28 |
#include "MSVDELET.H"
|
|
29 |
#include "MSVPANIC.H"
|
|
30 |
#include <tmsvsystemprogress.h>
|
|
31 |
#include "msvindexadapter.h"
|
|
32 |
|
|
33 |
//**********************************
|
|
34 |
// CMsvLocalOperation
|
|
35 |
//**********************************
|
|
36 |
|
|
37 |
CMsvLocalOperation::CMsvLocalOperation(const RMessage2& aMessage, TMsvOp aId, CMsvServer& aMsvServer)
|
|
38 |
: CMsvServerOperation(aMessage, aId, KUidMsvLocalServiceMtm, KMsvLocalServiceIndexEntryId, -1), iMsvServer(aMsvServer)
|
|
39 |
{
|
|
40 |
__DECLARE_NAME(_S("CMsvLocalOperation"));
|
|
41 |
}
|
|
42 |
|
|
43 |
const TDesC8& CMsvLocalOperation::Progress()
|
|
44 |
{
|
|
45 |
return iProgress;
|
|
46 |
}
|
|
47 |
|
|
48 |
/**
|
|
49 |
Obtain the local progress information
|
|
50 |
@param aOutSysProg The TMsvSystemProgress structure to be populated
|
|
51 |
@return system wide error code
|
|
52 |
*/
|
|
53 |
TInt CMsvLocalOperation::SystemProgress(TMsvSystemProgress& aSysProgress)
|
|
54 |
{
|
|
55 |
aSysProgress.iErrorCode = iProgress().iError;
|
|
56 |
aSysProgress.iId = iProgress().iId;
|
|
57 |
return KErrNone; // This method will not fail
|
|
58 |
}
|
|
59 |
|
|
60 |
//**********************************
|
|
61 |
// CMsvLocalCopyOperation
|
|
62 |
//**********************************
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
CMsvLocalCopyOperation::CMsvLocalCopyOperation(const RMessage2& aMessage, TMsvOp aId, CMsvEntrySelection* aSelection, TMsvId aTarget, CMsvServer& aMsvServer)
|
|
67 |
: CMsvLocalOperation(aMessage, aId, aMsvServer), iOrigEntries(aSelection), iTarget(aTarget)
|
|
68 |
//
|
|
69 |
//
|
|
70 |
//
|
|
71 |
{
|
|
72 |
__DECLARE_NAME(_S("CMsvLocalCopyOperation"));
|
|
73 |
// set up the progress
|
|
74 |
iProgress().iType = TMsvLocalOperationProgress::ELocalCopy;
|
|
75 |
iProgress().iTotalNumberOfEntries = iOrigEntries->Count();
|
|
76 |
iProgress().iNumberRemaining = iProgress().iTotalNumberOfEntries;
|
|
77 |
CActiveScheduler::Add(this);
|
|
78 |
}
|
|
79 |
|
|
80 |
|
|
81 |
CMsvLocalCopyOperation::~CMsvLocalCopyOperation()
|
|
82 |
//
|
|
83 |
//
|
|
84 |
//
|
|
85 |
{
|
|
86 |
Cancel();
|
|
87 |
delete iOrigEntries;
|
|
88 |
delete iNewEntries;
|
|
89 |
delete iCopy;
|
|
90 |
}
|
|
91 |
|
|
92 |
|
|
93 |
void CMsvLocalCopyOperation::DoCancel()
|
|
94 |
//
|
|
95 |
//
|
|
96 |
//
|
|
97 |
{
|
|
98 |
iCopy->Cancel();
|
|
99 |
iProgress().iError = KErrCancel;
|
|
100 |
Completed();
|
|
101 |
}
|
|
102 |
|
|
103 |
|
|
104 |
void CMsvLocalCopyOperation::RunL()
|
|
105 |
//
|
|
106 |
//
|
|
107 |
//
|
|
108 |
{
|
|
109 |
// sort out descendent copying
|
|
110 |
if (iDescendentCopying && iDescendentId == KMsvNullIndexEntryId)
|
|
111 |
iDescendentId = iCopy->NewEntryId();
|
|
112 |
|
|
113 |
// record details of the previous move
|
|
114 |
iProgress().iNumberRemaining--;
|
|
115 |
if (iStatus!=KErrNone)
|
|
116 |
{
|
|
117 |
iProgress().iNumberFailed++;
|
|
118 |
iProgress().iError=iStatus.Int();
|
|
119 |
}
|
|
120 |
else
|
|
121 |
{
|
|
122 |
iNewEntries->AppendL(iCopy->NewEntryId()); // will not fail, as space has been reserved
|
|
123 |
iProgress().iNumberCompleted++;
|
|
124 |
}
|
|
125 |
|
|
126 |
if (iIndex < iOrigEntries->Count())
|
|
127 |
{
|
|
128 |
// start the next move
|
|
129 |
TInt error = CopyNextEntry();
|
|
130 |
if (error==KErrNone)
|
|
131 |
return; // doing another move
|
|
132 |
__ASSERT_DEBUG(iProgress().iNumberRemaining==0, PanicServer(EMsvCopyingOperationInvariant));
|
|
133 |
}
|
|
134 |
|
|
135 |
// complete the operation
|
|
136 |
Completed();
|
|
137 |
}
|
|
138 |
|
|
139 |
|
|
140 |
void CMsvLocalCopyOperation::StartL()
|
|
141 |
//
|
|
142 |
//
|
|
143 |
//
|
|
144 |
{
|
|
145 |
iNewEntries = new(ELeave) CMsvEntrySelection;
|
|
146 |
iCopy = CMsvCopy::NewL(iMsvServer);
|
|
147 |
|
|
148 |
iIndex = 0;
|
|
149 |
iNewEntries->SetReserveL(iOrigEntries->Count());
|
|
150 |
iDescendentId = KMsvNullIndexEntryId;
|
|
151 |
|
|
152 |
// check for copying into a descedent
|
|
153 |
TInt count = iOrigEntries->Count();
|
|
154 |
while (count--)
|
|
155 |
{
|
|
156 |
TMsvId id = iOrigEntries->At(count);
|
|
157 |
iDescendentCopying = (id==iTarget);
|
|
158 |
if (!iDescendentCopying)
|
|
159 |
{
|
|
160 |
iMsvServer.IndexAdapter().IsADescendent(id, iTarget, iDescendentCopying); // error ignored
|
|
161 |
}
|
|
162 |
|
|
163 |
if (iDescendentCopying)
|
|
164 |
{
|
|
165 |
// has to be done first
|
|
166 |
iOrigEntries->Delete(count);
|
|
167 |
iOrigEntries->InsertL(0, id);
|
|
168 |
break;
|
|
169 |
}
|
|
170 |
}
|
|
171 |
|
|
172 |
|
|
173 |
TInt error = CopyNextEntry();
|
|
174 |
if (error==KErrNone)
|
|
175 |
SetState(EMsvOperationRunning);
|
|
176 |
else
|
|
177 |
{
|
|
178 |
iProgress().iNumberFailed = iProgress().iTotalNumberOfEntries;
|
|
179 |
iProgress().iNumberRemaining = 0;
|
|
180 |
iProgress().iError=error;
|
|
181 |
Completed();
|
|
182 |
}
|
|
183 |
}
|
|
184 |
|
|
185 |
|
|
186 |
TInt CMsvLocalCopyOperation::CopyNextEntry()
|
|
187 |
//
|
|
188 |
//
|
|
189 |
//
|
|
190 |
{
|
|
191 |
FOREVER
|
|
192 |
{
|
|
193 |
TRAPD(error, iCopy->StartL(iOrigEntries->At(iIndex++), iTarget, iStatus, iDescendentCopying));
|
|
194 |
if (error)
|
|
195 |
{
|
|
196 |
iProgress().iNumberRemaining--;
|
|
197 |
iProgress().iNumberFailed++;
|
|
198 |
iProgress().iError=error;
|
|
199 |
if (iIndex==iOrigEntries->Count())
|
|
200 |
return error;
|
|
201 |
}
|
|
202 |
else
|
|
203 |
{
|
|
204 |
SetActive();
|
|
205 |
break;
|
|
206 |
}
|
|
207 |
}
|
|
208 |
return KErrNone;
|
|
209 |
}
|
|
210 |
|
|
211 |
|
|
212 |
void CMsvLocalCopyOperation::Completed()
|
|
213 |
//
|
|
214 |
//
|
|
215 |
//
|
|
216 |
{
|
|
217 |
SetState(EMsvOperationCompleted);
|
|
218 |
if (iNewEntries->Count())
|
|
219 |
{
|
|
220 |
iProgress().iId = iNewEntries->At(0);
|
|
221 |
iMsvServer.NotifyChanged(EMsvEntriesCreated, *iNewEntries, iTarget);
|
|
222 |
}
|
|
223 |
iMessage.Complete(KErrNone);
|
|
224 |
}
|
|
225 |
|
|
226 |
|
|
227 |
|
|
228 |
|
|
229 |
//**********************************
|
|
230 |
// CMsvLocalMoveOperation
|
|
231 |
//**********************************
|
|
232 |
|
|
233 |
|
|
234 |
CMsvLocalMoveOperation::CMsvLocalMoveOperation(const RMessage2& aMessage, TMsvOp aId, CMsvEntrySelection* aSelection, TMsvId aTarget, CMsvServer& aMsvServer)
|
|
235 |
: CMsvLocalOperation(aMessage, aId, aMsvServer), iTarget(aTarget), iParent(KMsvNullIndexEntryId), iOrigEntries(aSelection)
|
|
236 |
{
|
|
237 |
__DECLARE_NAME(_S("CMsvLocalMoveOperation"));
|
|
238 |
// set up the progress
|
|
239 |
iProgress().iType = TMsvLocalOperationProgress::ELocalMove;
|
|
240 |
iProgress().iTotalNumberOfEntries = iOrigEntries->Count();
|
|
241 |
iProgress().iNumberRemaining = iProgress().iTotalNumberOfEntries;
|
|
242 |
CActiveScheduler::Add(this);
|
|
243 |
}
|
|
244 |
|
|
245 |
|
|
246 |
CMsvLocalMoveOperation::~CMsvLocalMoveOperation()
|
|
247 |
{
|
|
248 |
Cancel();
|
|
249 |
delete iOrigEntries;
|
|
250 |
delete iMove;
|
|
251 |
}
|
|
252 |
|
|
253 |
void CMsvLocalMoveOperation::DoCancel()
|
|
254 |
{
|
|
255 |
iMove->Cancel();
|
|
256 |
iOrigEntries->Delete(0,iNextEntry);
|
|
257 |
iProgress().iError = KErrCancel;
|
|
258 |
Completed();
|
|
259 |
}
|
|
260 |
|
|
261 |
void CMsvLocalMoveOperation::RunL()
|
|
262 |
//
|
|
263 |
//
|
|
264 |
//
|
|
265 |
{
|
|
266 |
// record details of the previous move
|
|
267 |
iProgress().iNumberRemaining--;
|
|
268 |
if (iStatus!=KErrNone)
|
|
269 |
{
|
|
270 |
iProgress().iNumberFailed++;
|
|
271 |
iProgress().iError=iStatus.Int();
|
|
272 |
iOrigEntries->Delete(iNextEntry);
|
|
273 |
}
|
|
274 |
else
|
|
275 |
iProgress().iNumberCompleted++;
|
|
276 |
|
|
277 |
TInt error=KErrNone;
|
|
278 |
if (iNextEntry) // will be zero when completed
|
|
279 |
{
|
|
280 |
// start the next move
|
|
281 |
error = MoveNextEntry();
|
|
282 |
if (error==KErrNone)
|
|
283 |
return; // doing another move
|
|
284 |
__ASSERT_DEBUG(iProgress().iNumberRemaining==0, PanicServer(EMsvMovingOperationInvariant));
|
|
285 |
}
|
|
286 |
|
|
287 |
// complete the operation
|
|
288 |
Completed();
|
|
289 |
}
|
|
290 |
|
|
291 |
void CMsvLocalMoveOperation::Completed()
|
|
292 |
//
|
|
293 |
//
|
|
294 |
//
|
|
295 |
{
|
|
296 |
SetState(EMsvOperationCompleted);
|
|
297 |
if (iOrigEntries->Count())
|
|
298 |
{
|
|
299 |
iProgress().iId = iOrigEntries->At(0);
|
|
300 |
iMsvServer.NotifyChanged(EMsvEntriesMoved, *iOrigEntries, iTarget, iParent);
|
|
301 |
}
|
|
302 |
iMessage.Complete(KErrNone);
|
|
303 |
}
|
|
304 |
|
|
305 |
void CMsvLocalMoveOperation::StartFailed(TInt aError)
|
|
306 |
//
|
|
307 |
//
|
|
308 |
//
|
|
309 |
{
|
|
310 |
iProgress().iNumberFailed = iProgress().iTotalNumberOfEntries;
|
|
311 |
iProgress().iNumberRemaining = 0;
|
|
312 |
iProgress().iError=aError;
|
|
313 |
iOrigEntries->Reset();
|
|
314 |
Completed();
|
|
315 |
}
|
|
316 |
|
|
317 |
void CMsvLocalMoveOperation::StartL()
|
|
318 |
//
|
|
319 |
//
|
|
320 |
//
|
|
321 |
{
|
|
322 |
// check if the target exists
|
|
323 |
TMsvEntry* entry;
|
|
324 |
TInt err = KErrNone;
|
|
325 |
err = iMsvServer.IndexAdapter().GetEntry(iTarget, entry);
|
|
326 |
if (err !=KErrNone)
|
|
327 |
{
|
|
328 |
StartFailed(KErrPathNotFound);
|
|
329 |
return;
|
|
330 |
}
|
|
331 |
|
|
332 |
// find the current parent
|
|
333 |
TInt count=iOrigEntries->Count();
|
|
334 |
while (count--)
|
|
335 |
{
|
|
336 |
TInt error = KErrNone;
|
|
337 |
error = iMsvServer.IndexAdapter().GetEntry(iOrigEntries->At(count), entry);
|
|
338 |
if (error ==KErrNone)
|
|
339 |
{
|
|
340 |
iParent=entry->Parent();
|
|
341 |
break;
|
|
342 |
}
|
|
343 |
}
|
|
344 |
|
|
345 |
// nothing to copy
|
|
346 |
if (count==KErrNotFound)
|
|
347 |
{
|
|
348 |
StartFailed(count);
|
|
349 |
return;
|
|
350 |
}
|
|
351 |
|
|
352 |
#if defined(_DEBUG)
|
|
353 |
// check all the entries are local
|
|
354 |
TInt dCount=iOrigEntries->Count();
|
|
355 |
while (dCount--)
|
|
356 |
{
|
|
357 |
TInt dSourceLocal;
|
|
358 |
TInt dError = KErrNone;
|
|
359 |
dError = iMsvServer.IndexAdapter().IsLocal(iOrigEntries->At(count), dSourceLocal);
|
|
360 |
__ASSERT_DEBUG(dError!=KErrNone || dSourceLocal, PanicServer(EMsvMovingLocalEntryIsRemote));
|
|
361 |
}
|
|
362 |
#endif
|
|
363 |
|
|
364 |
// start the copying
|
|
365 |
iMove = CMsvMove::NewL(iMsvServer);
|
|
366 |
iNextEntry=iOrigEntries->Count();
|
|
367 |
TInt error = MoveNextEntry();
|
|
368 |
if (error==KErrNone)
|
|
369 |
SetState(EMsvOperationRunning);
|
|
370 |
else
|
|
371 |
StartFailed(error);
|
|
372 |
}
|
|
373 |
|
|
374 |
|
|
375 |
TInt CMsvLocalMoveOperation::MoveNextEntry()
|
|
376 |
//
|
|
377 |
//
|
|
378 |
//
|
|
379 |
{
|
|
380 |
TInt error=KErrGeneral;
|
|
381 |
while (error!=KErrNone && iNextEntry)
|
|
382 |
{
|
|
383 |
iMove->Reset();
|
|
384 |
error=KErrNone;
|
|
385 |
TRAP(error, iMove->StartL(iOrigEntries->At(--iNextEntry), iTarget, iStatus));
|
|
386 |
if (error)
|
|
387 |
{
|
|
388 |
iProgress().iNumberRemaining--;
|
|
389 |
iProgress().iNumberFailed++;
|
|
390 |
iProgress().iError=error;
|
|
391 |
iOrigEntries->Delete(iNextEntry);
|
|
392 |
}
|
|
393 |
}
|
|
394 |
if (error==KErrNone)
|
|
395 |
SetActive();
|
|
396 |
return error;
|
|
397 |
}
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
//**********************************
|
|
402 |
// CMsvLocalDeleteOperation
|
|
403 |
//**********************************
|
|
404 |
|
|
405 |
|
|
406 |
CMsvLocalDeleteOperation::CMsvLocalDeleteOperation(const RMessage2& aMessage, TMsvOp aId, CMsvEntrySelection* aSelection, CMsvServer& aMsvServer)
|
|
407 |
: CMsvLocalOperation(aMessage, aId, aMsvServer), iSelection(aSelection)
|
|
408 |
{
|
|
409 |
__DECLARE_NAME(_S("CMsvLocalDeleteOperation"));
|
|
410 |
// set up the progress
|
|
411 |
iProgress().iType = TMsvLocalOperationProgress::ELocalDelete;
|
|
412 |
iProgress().iTotalNumberOfEntries = iSelection->Count();
|
|
413 |
iProgress().iNumberRemaining = iProgress().iTotalNumberOfEntries;
|
|
414 |
CActiveScheduler::Add(this);
|
|
415 |
}
|
|
416 |
|
|
417 |
|
|
418 |
CMsvLocalDeleteOperation::~CMsvLocalDeleteOperation()
|
|
419 |
{
|
|
420 |
Cancel();
|
|
421 |
delete iSelection;
|
|
422 |
delete iDeletedEntries;
|
|
423 |
delete iMovedEntries;
|
|
424 |
delete iDelete;
|
|
425 |
delete iWorkSelection1;
|
|
426 |
delete iWorkSelection2;
|
|
427 |
}
|
|
428 |
|
|
429 |
|
|
430 |
void CMsvLocalDeleteOperation::DoCancel()
|
|
431 |
//
|
|
432 |
//
|
|
433 |
//
|
|
434 |
{
|
|
435 |
iDelete->Cancel();
|
|
436 |
iProgress().iError = KErrCancel;
|
|
437 |
Completed();
|
|
438 |
// if the last entry was removed, update the notification selections
|
|
439 |
TRAP_IGNORE(PartialCompletionNotificationL());
|
|
440 |
}
|
|
441 |
|
|
442 |
|
|
443 |
void CMsvLocalDeleteOperation::PartialCompletionNotificationL()
|
|
444 |
//
|
|
445 |
//
|
|
446 |
//
|
|
447 |
{
|
|
448 |
TMsvId id=iSelection->At(iIndex-1);
|
|
449 |
TBool entryExists = EFalse;
|
|
450 |
entryExists = iMsvServer.IndexAdapter().EntryExists(id);
|
|
451 |
if (!entryExists)
|
|
452 |
id = iParent;
|
|
453 |
|
|
454 |
if (iWorkSelection1->Count())
|
|
455 |
{
|
|
456 |
iDeletedEntries->Reset();
|
|
457 |
iDeletedEntries->AppendL(iWorkSelection1->Back(0), iWorkSelection1->Count());
|
|
458 |
iMsvServer.NotifyChanged(EMsvEntriesDeleted, *iDeletedEntries, id);
|
|
459 |
}
|
|
460 |
|
|
461 |
if (iWorkSelection2->Count())
|
|
462 |
{
|
|
463 |
iDeletedEntries->Reset();
|
|
464 |
iMovedEntries->AppendL(iWorkSelection2->Back(0), iWorkSelection2->Count());
|
|
465 |
iMsvServer.NotifyChanged(EMsvEntriesMoved, *iMovedEntries, KMsvDeletedEntryFolderEntryId, id);
|
|
466 |
}
|
|
467 |
}
|
|
468 |
|
|
469 |
|
|
470 |
void CMsvLocalDeleteOperation::RunL()
|
|
471 |
//
|
|
472 |
// Attempts the next delete
|
|
473 |
//
|
|
474 |
{
|
|
475 |
TRAPD(leave, DoRunL());
|
|
476 |
if (leave)
|
|
477 |
{
|
|
478 |
// probably OOM so complete the operation
|
|
479 |
iProgress().iError = leave;
|
|
480 |
Completed();
|
|
481 |
}
|
|
482 |
}
|
|
483 |
|
|
484 |
|
|
485 |
void CMsvLocalDeleteOperation::DoRunL()
|
|
486 |
//
|
|
487 |
//
|
|
488 |
//
|
|
489 |
{
|
|
490 |
// record the result of the last delete
|
|
491 |
iProgress().iNumberRemaining--;
|
|
492 |
if (iStatus.Int()==KErrNone)
|
|
493 |
{
|
|
494 |
iProgress().iNumberCompleted++;
|
|
495 |
iDeletedEntries->AppendL(iWorkSelection1->Back(0), iWorkSelection1->Count());
|
|
496 |
iMovedEntries->AppendL(iWorkSelection2->Back(0), iWorkSelection2->Count());
|
|
497 |
}
|
|
498 |
else
|
|
499 |
{
|
|
500 |
iProgress().iNumberFailed++;
|
|
501 |
if (iProgress().iError==KErrNone)
|
|
502 |
iProgress().iError = iStatus.Int();
|
|
503 |
}
|
|
504 |
|
|
505 |
// start thje next delete or complete the operation
|
|
506 |
if (iProgress().iNumberRemaining)
|
|
507 |
{
|
|
508 |
iWorkSelection1->Reset();
|
|
509 |
iWorkSelection2->Reset();
|
|
510 |
iDelete->StartL(iSelection->At(iIndex++), *iWorkSelection1, *iWorkSelection2, iStatus);
|
|
511 |
SetActive();
|
|
512 |
}
|
|
513 |
else
|
|
514 |
{
|
|
515 |
__ASSERT_DEBUG(iIndex==iSelection->Count(), PanicServer(EMsvLocalDeletionMisCount));
|
|
516 |
Completed();
|
|
517 |
}
|
|
518 |
}
|
|
519 |
|
|
520 |
|
|
521 |
void CMsvLocalDeleteOperation::Completed()
|
|
522 |
//
|
|
523 |
// The operation has completed
|
|
524 |
//
|
|
525 |
{
|
|
526 |
/**
|
|
527 |
Added code to commit transaction for bulk deletion.
|
|
528 |
*/
|
|
529 |
TRAP_IGNORE(iMsvServer.IndexAdapter().GetDbAdapter()->CommitTransactionL());
|
|
530 |
|
|
531 |
// notify server of any deletions or moves to the deleted folder
|
|
532 |
if (iDeletedEntries->Count())
|
|
533 |
iMsvServer.NotifyChanged(EMsvEntriesDeleted, *iDeletedEntries, iParent);
|
|
534 |
if (iMovedEntries->Count())
|
|
535 |
iMsvServer.NotifyChanged(EMsvEntriesMoved, *iMovedEntries, KMsvDeletedEntryFolderEntryId, iParent);
|
|
536 |
|
|
537 |
// complete the request
|
|
538 |
SetState(EMsvOperationCompleted);
|
|
539 |
iMessage.Complete(KErrNone);
|
|
540 |
}
|
|
541 |
|
|
542 |
void CMsvLocalDeleteOperation::StartL()
|
|
543 |
{
|
|
544 |
// reserve space so we don't manage to delete the entries but run
|
|
545 |
// out of memory when trying to report the fact.
|
|
546 |
iDeletedEntries = new(ELeave)CMsvEntrySelection;
|
|
547 |
iDeletedEntries->SetReserveL(iSelection->Count());
|
|
548 |
iMovedEntries = new(ELeave)CMsvEntrySelection;
|
|
549 |
iMovedEntries->SetReserveL(iSelection->Count());
|
|
550 |
iWorkSelection1 = new(ELeave)CMsvEntrySelection;
|
|
551 |
iWorkSelection2 = new(ELeave)CMsvEntrySelection;
|
|
552 |
iDelete = CMsvDelete::NewL(iMsvServer);
|
|
553 |
|
|
554 |
// find the parent
|
|
555 |
TInt count=iSelection->Count();
|
|
556 |
while (count--)
|
|
557 |
{
|
|
558 |
TMsvEntry* entry;
|
|
559 |
TInt error = KErrNone;
|
|
560 |
error = iMsvServer.IndexAdapter().GetEntry(iSelection->At(count),entry);
|
|
561 |
if (error)
|
|
562 |
{
|
|
563 |
iSelection->Delete(count);
|
|
564 |
iProgress().iNumberRemaining--;
|
|
565 |
iProgress().iNumberCompleted++;
|
|
566 |
}
|
|
567 |
else
|
|
568 |
iParent = entry->Parent();
|
|
569 |
}
|
|
570 |
|
|
571 |
if (iSelection->Count())
|
|
572 |
{
|
|
573 |
// start deleting the first entry
|
|
574 |
iDelete->StartL(iSelection->At(iIndex++), *iWorkSelection1, *iWorkSelection2, iStatus);
|
|
575 |
SetActive();
|
|
576 |
SetState(EMsvOperationRunning);
|
|
577 |
}
|
|
578 |
else
|
|
579 |
Completed();
|
|
580 |
}
|
|
581 |
|
|
582 |
|
|
583 |
|
|
584 |
|
|
585 |
|
|
586 |
//**********************************
|
|
587 |
// CMsvLocalChangeOperation
|
|
588 |
//**********************************
|
|
589 |
|
|
590 |
|
|
591 |
CMsvLocalChangeOperation::CMsvLocalChangeOperation(const RMessage2& aMessage, TMsvOp aId, const TMsvEntry& aEntry, CMsvServer& aMsvServer)
|
|
592 |
: CMsvLocalOperation(aMessage, aId, aMsvServer), iEntry(aEntry)
|
|
593 |
{
|
|
594 |
__DECLARE_NAME(_S("CMsvLocalChangeOperation"));
|
|
595 |
// set up the progress
|
|
596 |
iProgress().iType = TMsvLocalOperationProgress::ELocalChanged;
|
|
597 |
iProgress().iTotalNumberOfEntries = 1;
|
|
598 |
iProgress().iId = iEntry.Id();
|
|
599 |
CActiveScheduler::Add(this);
|
|
600 |
}
|
|
601 |
|
|
602 |
CMsvLocalChangeOperation::~CMsvLocalChangeOperation()
|
|
603 |
//
|
|
604 |
//
|
|
605 |
//
|
|
606 |
{
|
|
607 |
Cancel();
|
|
608 |
delete iDelete;
|
|
609 |
delete iWorkSelection1;
|
|
610 |
delete iWorkSelection2;
|
|
611 |
}
|
|
612 |
|
|
613 |
void CMsvLocalChangeOperation::DoCancel()
|
|
614 |
//
|
|
615 |
//
|
|
616 |
//
|
|
617 |
{
|
|
618 |
__ASSERT_DEBUG(iDelete!=NULL, PanicServer(EMsvChangeEntryBadState));
|
|
619 |
iDelete->Cancel();
|
|
620 |
iProgress().iError = KErrCancel;
|
|
621 |
Completed();
|
|
622 |
}
|
|
623 |
|
|
624 |
void CMsvLocalChangeOperation::RunL()
|
|
625 |
//
|
|
626 |
//
|
|
627 |
//
|
|
628 |
{
|
|
629 |
if (iStatus.Int()==KErrNone)
|
|
630 |
{
|
|
631 |
iProgress().iNumberCompleted++;
|
|
632 |
}
|
|
633 |
else
|
|
634 |
{
|
|
635 |
iProgress().iNumberFailed++;
|
|
636 |
iProgress().iError = iStatus.Int();
|
|
637 |
}
|
|
638 |
Completed();
|
|
639 |
}
|
|
640 |
|
|
641 |
void CMsvLocalChangeOperation::StartL(TSecureId aOwnerId, TBool aForcedUpdate)
|
|
642 |
//
|
|
643 |
//
|
|
644 |
//
|
|
645 |
{
|
|
646 |
iId = iEntry.Id();
|
|
647 |
iParent = iEntry.Parent();
|
|
648 |
// check if this is actually a deletion
|
|
649 |
if (iEntry.Deleted() && iEntry.PcSyncCount()==0)
|
|
650 |
{
|
|
651 |
iDelete = CMsvDelete::NewL(iMsvServer);
|
|
652 |
iWorkSelection1 = new(ELeave)CMsvEntrySelection;
|
|
653 |
iWorkSelection2 = new(ELeave)CMsvEntrySelection;
|
|
654 |
iDelete->StartL(iEntry.Id(), *iWorkSelection1, *iWorkSelection2, iStatus, ETrue);
|
|
655 |
SetActive();
|
|
656 |
return;
|
|
657 |
}
|
|
658 |
|
|
659 |
// otherwise just changing it
|
|
660 |
TInt error = KErrNone;
|
|
661 |
error = iMsvServer.IndexAdapter().LockEntry(iId);
|
|
662 |
if (error==KErrNone)
|
|
663 |
{
|
|
664 |
error = iMsvServer.ChangeEntry(iEntry, aOwnerId, aForcedUpdate);
|
|
665 |
iMsvServer.IndexAdapter().ReleaseEntry(iId); // error ignored
|
|
666 |
}
|
|
667 |
|
|
668 |
if (error==KErrNone)
|
|
669 |
iProgress().iNumberCompleted++;
|
|
670 |
else
|
|
671 |
{
|
|
672 |
iProgress().iNumberFailed++;
|
|
673 |
iProgress().iError = error;
|
|
674 |
}
|
|
675 |
Completed();
|
|
676 |
}
|
|
677 |
|
|
678 |
|
|
679 |
void CMsvLocalChangeOperation::Completed()
|
|
680 |
//
|
|
681 |
//
|
|
682 |
//
|
|
683 |
{
|
|
684 |
if (iProgress().iError==KErrNone)
|
|
685 |
iMsvServer.NotifyChanged(iDelete==NULL ? EMsvEntriesChanged : EMsvEntriesDeleted, iId, iParent);
|
|
686 |
SetState(EMsvOperationCompleted);
|
|
687 |
iMessage.Complete(KErrNone);
|
|
688 |
}
|
|
689 |
//**********************************
|
|
690 |
// CMsvLocalChangeEntriesOperation
|
|
691 |
//**********************************
|
|
692 |
|
|
693 |
|
|
694 |
CMsvLocalChangeEntriesOperation::CMsvLocalChangeEntriesOperation(const RMessage2& aMessage, TMsvOp aId, CMsvEntrySelection* aSelection, CMsvServer& aMsvServer, TInt aMark)
|
|
695 |
: CMsvLocalOperation(aMessage, aId, aMsvServer), iSelection(aSelection), iMark(aMark)
|
|
696 |
{
|
|
697 |
__DECLARE_NAME(_S("CMsvLocalChangeEntriesOperation"));
|
|
698 |
// set up the progress
|
|
699 |
iProgress().iType = TMsvLocalOperationProgress::ELocalChanged;
|
|
700 |
iProgress().iTotalNumberOfEntries = iSelection->Count();;
|
|
701 |
iProgress().iNumberRemaining = iProgress().iTotalNumberOfEntries;
|
|
702 |
CActiveScheduler::Add(this);
|
|
703 |
}
|
|
704 |
|
|
705 |
CMsvLocalChangeEntriesOperation::~CMsvLocalChangeEntriesOperation()
|
|
706 |
//
|
|
707 |
//
|
|
708 |
//
|
|
709 |
{
|
|
710 |
Cancel();
|
|
711 |
delete iSelection;
|
|
712 |
delete iDelete;
|
|
713 |
delete iWorkSelection1;
|
|
714 |
delete iWorkSelection2;
|
|
715 |
}
|
|
716 |
|
|
717 |
void CMsvLocalChangeEntriesOperation::DoCancel()
|
|
718 |
//
|
|
719 |
//
|
|
720 |
//
|
|
721 |
{
|
|
722 |
__ASSERT_DEBUG(iDelete!=NULL, PanicServer(EMsvChangeEntryBadState));
|
|
723 |
iDelete->Cancel();
|
|
724 |
iProgress().iError = KErrCancel;
|
|
725 |
Completed();
|
|
726 |
}
|
|
727 |
|
|
728 |
void CMsvLocalChangeEntriesOperation::RunL()
|
|
729 |
//
|
|
730 |
//
|
|
731 |
//
|
|
732 |
{
|
|
733 |
if (iStatus.Int()==KErrNone)
|
|
734 |
{
|
|
735 |
iProgress().iNumberCompleted++;
|
|
736 |
}
|
|
737 |
else
|
|
738 |
{
|
|
739 |
iProgress().iNumberFailed++;
|
|
740 |
iProgress().iError = iStatus.Int();
|
|
741 |
}
|
|
742 |
|
|
743 |
Completed();
|
|
744 |
}
|
|
745 |
|
|
746 |
|
|
747 |
void CMsvLocalChangeEntriesOperation::StartL(TSecureId aOwnerId, TBool aForcedUpdate)
|
|
748 |
//
|
|
749 |
//
|
|
750 |
//
|
|
751 |
{
|
|
752 |
TMsvEntry* entry1;
|
|
753 |
|
|
754 |
TInt count = iSelection->Count();
|
|
755 |
while (count--)
|
|
756 |
{
|
|
757 |
iMsvServer.IndexAdapter().GetEntry(iSelection->At(count),entry1);
|
|
758 |
iId = entry1->Id();
|
|
759 |
iParent = entry1->Parent();
|
|
760 |
// check if this is actually a deletion
|
|
761 |
if (entry1->Deleted() && entry1->PcSyncCount()==0)
|
|
762 |
{
|
|
763 |
iDelete = CMsvDelete::NewL(iMsvServer);
|
|
764 |
iWorkSelection1 = new(ELeave)CMsvEntrySelection;
|
|
765 |
iWorkSelection2 = new(ELeave)CMsvEntrySelection;
|
|
766 |
|
|
767 |
iDelete->StartL(entry1->Id(), *iWorkSelection1, *iWorkSelection2, iStatus, ETrue);
|
|
768 |
SetActive();
|
|
769 |
return;
|
|
770 |
}
|
|
771 |
}
|
|
772 |
|
|
773 |
TInt error = KErrNone;
|
|
774 |
TMsvEntry* entry;
|
|
775 |
count = iSelection->Count();
|
|
776 |
while (count--)
|
|
777 |
{
|
|
778 |
error = iMsvServer.IndexAdapter().GetEntry(iSelection->At(count),entry);
|
|
779 |
if (error==KErrNone)
|
|
780 |
{
|
|
781 |
error = iMsvServer.IndexAdapter().LockEntry(iSelection->At(count));
|
|
782 |
error = iMsvServer.ChangeEntry(*entry, aOwnerId, aForcedUpdate);
|
|
783 |
error = iMsvServer.IndexAdapter().ReleaseEntry(iSelection->At(count)); // error ignored
|
|
784 |
}
|
|
785 |
}
|
|
786 |
|
|
787 |
if (error==KErrNone)
|
|
788 |
iProgress().iNumberCompleted++;
|
|
789 |
else
|
|
790 |
{
|
|
791 |
iProgress().iNumberFailed++;
|
|
792 |
iProgress().iError = error;
|
|
793 |
}
|
|
794 |
Completed();
|
|
795 |
}
|
|
796 |
|
|
797 |
void CMsvLocalChangeEntriesOperation::Completed()
|
|
798 |
//
|
|
799 |
//
|
|
800 |
//
|
|
801 |
{
|
|
802 |
|
|
803 |
if (iProgress().iError==KErrNone)
|
|
804 |
iMsvServer.NotifyChanged(iDelete==NULL ? EMsvEntriesChanged : EMsvEntriesDeleted, iId, iParent);
|
|
805 |
SetState(EMsvOperationCompleted);
|
|
806 |
iMessage.Complete(KErrNone);
|
|
807 |
}
|
|
808 |
|
|
809 |
|
|
810 |
//**********************************
|
|
811 |
// CMsvLocalCreateOperation
|
|
812 |
//**********************************
|
|
813 |
|
|
814 |
CMsvLocalCreateOperation::CMsvLocalCreateOperation(const RMessage2& aMessage, TMsvOp aId, const TMsvEntry& aEntry, CMsvServer& aMsvServer)
|
|
815 |
: CMsvLocalOperation(aMessage, aId, aMsvServer), iEntry(aEntry)
|
|
816 |
{
|
|
817 |
__DECLARE_NAME(_S("CMsvLocalCreateOperation"));
|
|
818 |
// set up the progress
|
|
819 |
iProgress().iType = TMsvLocalOperationProgress::ELocalNew;
|
|
820 |
iProgress().iTotalNumberOfEntries = 1;
|
|
821 |
CActiveScheduler::Add(this);
|
|
822 |
}
|
|
823 |
|
|
824 |
|
|
825 |
CMsvLocalCreateOperation::~CMsvLocalCreateOperation()
|
|
826 |
{}
|
|
827 |
|
|
828 |
void CMsvLocalCreateOperation::DoCancel()
|
|
829 |
{}
|
|
830 |
|
|
831 |
void CMsvLocalCreateOperation::RunL()
|
|
832 |
{}
|
|
833 |
|
|
834 |
void CMsvLocalCreateOperation::Start(TSecureId aOwnerId)
|
|
835 |
{
|
|
836 |
TMsvEntry entry = iEntry;
|
|
837 |
TInt error = iMsvServer.AddEntry(entry, aOwnerId, ETrue);
|
|
838 |
|
|
839 |
if (error)
|
|
840 |
{
|
|
841 |
iProgress().iNumberFailed++;
|
|
842 |
iProgress().iError = error;
|
|
843 |
}
|
|
844 |
else
|
|
845 |
{
|
|
846 |
iProgress().iNumberCompleted++;
|
|
847 |
iProgress().iId = entry.Id();
|
|
848 |
iMsvServer.NotifyChanged(EMsvEntriesCreated, entry.Id(), entry.Parent());
|
|
849 |
}
|
|
850 |
|
|
851 |
SetState(EMsvOperationCompleted);
|
|
852 |
iMessage.Complete(KErrNone);
|
|
853 |
}
|
|
854 |
|
|
855 |
//**********************************
|
|
856 |
// CMsvChangeDriveOperation
|
|
857 |
//**********************************
|
|
858 |
CMsvChangeDriveOperation::CMsvChangeDriveOperation(const RMessage2& aMessage, TMsvOp aId, TInt aDrive, CMsvServer& aServer)
|
|
859 |
: CMsvServerOperation(aMessage, aId, KUidMsvLocalServiceMtm, KMsvLocalServiceIndexEntryId, -1), iDrive(aDrive), iServer(aServer)
|
|
860 |
{
|
|
861 |
CActiveScheduler::Add(this);
|
|
862 |
}
|
|
863 |
|
|
864 |
CMsvChangeDriveOperation::~CMsvChangeDriveOperation()
|
|
865 |
{
|
|
866 |
Cancel();
|
|
867 |
}
|
|
868 |
|
|
869 |
const TDesC8& CMsvChangeDriveOperation::Progress()
|
|
870 |
{
|
|
871 |
if (iServer.NewContext())
|
|
872 |
iProgress() = iServer.NewContext()->Progress();
|
|
873 |
|
|
874 |
return iProgress;
|
|
875 |
}
|
|
876 |
|
|
877 |
void CMsvChangeDriveOperation::DoCancel()
|
|
878 |
{
|
|
879 |
if (iServer.NewContext())
|
|
880 |
iServer.NewContext()->Cancel();
|
|
881 |
|
|
882 |
iProgress().iError = KErrCancel;
|
|
883 |
Completed();
|
|
884 |
}
|
|
885 |
|
|
886 |
void CMsvChangeDriveOperation::RunL()
|
|
887 |
{
|
|
888 |
Completed();
|
|
889 |
}
|
|
890 |
|
|
891 |
void CMsvChangeDriveOperation::Completed()
|
|
892 |
{
|
|
893 |
// Get progress
|
|
894 |
if (iServer.NewContext())
|
|
895 |
{
|
|
896 |
iProgress() = iServer.NewContext()->Progress();
|
|
897 |
|
|
898 |
// If an error occurs we have to delete the new context
|
|
899 |
iServer.DeleteNewContext();
|
|
900 |
}
|
|
901 |
else
|
|
902 |
iProgress() = iServer.Context().Progress();
|
|
903 |
|
|
904 |
SetState(EMsvOperationCompleted);
|
|
905 |
iMessage.Complete(KErrNone);
|
|
906 |
}
|
|
907 |
|
|
908 |
TInt CMsvChangeDriveOperation::Start()
|
|
909 |
{
|
|
910 |
TInt error = iServer.ChangeDrive(iDrive, &iStatus);
|
|
911 |
if (!error)
|
|
912 |
SetActive();
|
|
913 |
return error;
|
|
914 |
}
|
|
915 |
|