|
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: DS contacts dataprovider |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <barsc.h> |
|
21 #include <bautils.h> |
|
22 #include <e32base.h> |
|
23 #include <s32strm.h> |
|
24 #include <e32cmn.h> |
|
25 #include <e32des16.h> |
|
26 #include <s32mem.h> |
|
27 #include <implementationproxy.h> |
|
28 #include <vtoken.h> |
|
29 #include <sysutil.h> |
|
30 #include <NSmlContactsDataStoreFormat_1_1_2.rsg> |
|
31 #include <NSmlContactsDataStoreFormat_1_2.rsg> |
|
32 #include <data_caging_path_literals.hrh> |
|
33 #include <SmlDataFormat.h> |
|
34 #include <SmlDataProvider.h> |
|
35 #include <e32property.h> |
|
36 #include <DataSyncInternalPSKeys.h> |
|
37 #include <e32hashtab.h> |
|
38 |
|
39 #include <CVPbkContactStoreUriArray.h> |
|
40 #include <VPbkContactStoreUris.h> |
|
41 #include <TVPbkContactStoreUriPtr.h> |
|
42 #include <MVPbkContactStoreList.h> |
|
43 #include <MVPbkContactStoreProperties.h> |
|
44 #include <MVPbkStoreContactProperties.h> |
|
45 #include <MVPbkViewContact.h> |
|
46 #include <MVPbkStoreContact.h> |
|
47 #include <MVPbkStoreContact2.h> |
|
48 #include <MVPbkFieldType.h> |
|
49 #include <MVPbkContactFieldTextData.h> |
|
50 #include <CVPbkContactFieldIterator.h> |
|
51 #include <CVPbkContactViewDefinition.h> |
|
52 |
|
53 #include <MVPbkContactLink.h> |
|
54 #include <s32mem.h> |
|
55 |
|
56 #include "NSmlContactsDataStore.h" |
|
57 #include "NSmlContactsModsFetcher.h" |
|
58 #include "nsmldebug.h" |
|
59 #include "nsmlconstants.h" |
|
60 #include "NSmlDataModBase.h" |
|
61 #include "nsmlcontactsdefs.h" |
|
62 #include "nsmldsimpluids.h" |
|
63 #include "nsmlsnapshotitem.h" |
|
64 #include "nsmlchangefinder.h" |
|
65 #include <VPbkEng.rsg> |
|
66 |
|
67 #ifndef __WINS__ |
|
68 // This lowers the unnecessary compiler warning (armv5) to remark. |
|
69 // "Warning: #174-D: expression has no effect..." is caused by |
|
70 // DBG_ARGS8 macro in no-debug builds. |
|
71 #pragma diag_remark 174 |
|
72 #endif |
|
73 |
|
74 |
|
75 // ---------------------------------------------------------------------------- |
|
76 // CNSmlContactsDataStore::CNSmlContactsBufferItem::~CNSmlContactsBufferItem |
|
77 // ---------------------------------------------------------------------------- |
|
78 CNSmlContactsDataStore::CNSmlContactsBufferItem::~CNSmlContactsBufferItem() |
|
79 { |
|
80 delete iItemData; |
|
81 delete iMimeType; |
|
82 delete iMimeVersion; |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CNSmlContactsDataStore::NewL |
|
87 // ---------------------------------------------------------------------------- |
|
88 CNSmlContactsDataStore* CNSmlContactsDataStore::NewL() |
|
89 { |
|
90 _DBG_FILE("CNSmlContactsDataStore::NewL: BEGIN"); |
|
91 CNSmlContactsDataStore* self = new ( ELeave ) CNSmlContactsDataStore(); |
|
92 CleanupStack::PushL(self); |
|
93 |
|
94 self->ConstructL(); |
|
95 CleanupStack::Pop(self); // self |
|
96 |
|
97 _DBG_FILE("CNSmlContactsDataStore::NewL: END"); |
|
98 return self; |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------------------------------- |
|
102 // CNSmlContactsDataStore::CNSmlContactsDataStore() |
|
103 // ---------------------------------------------------------------------------- |
|
104 CNSmlContactsDataStore::CNSmlContactsDataStore() : |
|
105 iKey( TKeyArrayFix( _FOFF( TNSmlSnapshotItem,ItemId() ),ECmpTInt )), |
|
106 iContactManager(NULL), |
|
107 iStore(NULL), |
|
108 iVCardEngine(NULL), |
|
109 iIdConverter(NULL), |
|
110 iContactLnks(NULL), |
|
111 iContactViewBase(NULL), |
|
112 iSize(NULL), |
|
113 iBuf(NULL) |
|
114 { |
|
115 _DBG_FILE("CNSmlContactsDataStore::CNSmlContactsDataStore(): begin"); |
|
116 |
|
117 iSyncHistory = EFalse; |
|
118 iSnapshotRegistered = EFalse; |
|
119 |
|
120 iServerMaxObjectSize = 0; // Maximum size default value |
|
121 iItemPos = -1; |
|
122 iModificationCount = KNSmlCompactAfterChanges; |
|
123 |
|
124 iState = ENSmlClosed; |
|
125 iStoreName = NULL; |
|
126 iRetCommand = KErrNone; |
|
127 iLastOperation = ENSmlNone; |
|
128 |
|
129 _DBG_FILE("CNSmlContactsDataStore::CNSmlContactsDataStore(): end"); |
|
130 } |
|
131 |
|
132 // ---------------------------------------------------------------------------- |
|
133 // CNSmlContactsDataStore::ConstructL() |
|
134 // ---------------------------------------------------------------------------- |
|
135 void CNSmlContactsDataStore::ConstructL() |
|
136 { |
|
137 _DBG_FILE("CNSmlContactsDataStore::CNSmlContactsDataStore(): begin"); |
|
138 |
|
139 User::LeaveIfError( iRfs.Connect() ); |
|
140 |
|
141 iUsedMimeType.Set( KNSmlvCard21Name() ); |
|
142 iUsedMimeVersion.Set( KNSmlvCard21Ver() ); |
|
143 iStringPool.OpenL(); |
|
144 |
|
145 // Uid Sets |
|
146 iNewUids = new (ELeave) CNSmlDataItemUidSet(); |
|
147 iDeletedUids = new (ELeave) CNSmlDataItemUidSet(); |
|
148 iSoftDeletedUids = new (ELeave) CNSmlDataItemUidSet(); |
|
149 iMovedUids = new (ELeave) CNSmlDataItemUidSet(); |
|
150 iReplacedUids = new (ELeave) CNSmlDataItemUidSet(); |
|
151 |
|
152 // Create iDataMod |
|
153 // This should be done after OpenL if there are more than one database |
|
154 iDataMod = new (ELeave) CNSmlVCardMod(); |
|
155 |
|
156 SetOwnStoreFormatL(); |
|
157 // open contact database |
|
158 CVPbkContactStoreUriArray* uriArray = CVPbkContactStoreUriArray::NewLC(); |
|
159 uriArray->AppendL( TVPbkContactStoreUriPtr(VPbkContactStoreUris::DefaultCntDbUri())); |
|
160 |
|
161 iContactManager = CVPbkContactManager::NewL(*uriArray); |
|
162 CleanupStack::PopAndDestroy(uriArray); |
|
163 //Default store name |
|
164 iDefaultStoreName = (VPbkContactStoreUris::DefaultCntDbUri()).AllocL(); |
|
165 |
|
166 //Fill iPacketStoreName buffer with KLegacySymbianDatabase |
|
167 TBuf<KOldSymbianDBLength> dataBase(KLegacySymbianDatabase); |
|
168 iPacketStoreName = HBufC::NewL(dataBase.Length()); |
|
169 TPtr pktStorePtr(iPacketStoreName->Des()); |
|
170 pktStorePtr.Copy(dataBase); |
|
171 |
|
172 _DBG_FILE("CNSmlContactsDataStore::ConstructL(): end"); |
|
173 } |
|
174 |
|
175 // ---------------------------------------------------------------------------- |
|
176 // CNSmlContactsDataStore::~CNSmlContactsDataStore() |
|
177 // ---------------------------------------------------------------------------- |
|
178 CNSmlContactsDataStore::~CNSmlContactsDataStore() |
|
179 { |
|
180 _DBG_FILE("CNSmlContactsDataStore::~CNSmlContactsDataStore(): begin"); |
|
181 |
|
182 delete iStoreFormat; // SetOwnStoreFormatL creates |
|
183 iStringPool.Close(); |
|
184 |
|
185 iRfs.Close(); |
|
186 iWriteStream.Close(); |
|
187 iReadStream.Close(); |
|
188 delete iBuf; |
|
189 |
|
190 if ( iChangeFinder ) |
|
191 { |
|
192 TRAP_IGNORE( iChangeFinder->CloseL() ); |
|
193 delete iChangeFinder; |
|
194 } |
|
195 |
|
196 if(iIdConverter) |
|
197 { |
|
198 delete iIdConverter; |
|
199 } |
|
200 if(iContactLnks) |
|
201 { |
|
202 delete iContactLnks; |
|
203 } |
|
204 if(iContactLink) |
|
205 { |
|
206 delete iContactLink; |
|
207 } |
|
208 delete iContactViewBase; |
|
209 if ( iContactsModsFetcher ) |
|
210 { |
|
211 iContactsModsFetcher->Cancel(); |
|
212 delete iContactsModsFetcher; |
|
213 } |
|
214 if ( iContactManager ) |
|
215 { |
|
216 if(iStore) |
|
217 { |
|
218 iStore->Close( *this ); |
|
219 } |
|
220 delete iContactManager; |
|
221 } |
|
222 |
|
223 |
|
224 delete iVCardEngine; |
|
225 // Delete UidSets |
|
226 // |
|
227 delete iNewUids; |
|
228 delete iDeletedUids; |
|
229 delete iSoftDeletedUids; |
|
230 delete iMovedUids; |
|
231 delete iReplacedUids; |
|
232 |
|
233 // |
|
234 // Empty BufferItemList if any |
|
235 // |
|
236 if ( iContactsBufferItemList.Count() > 0 ) |
|
237 { |
|
238 if ( iContactsBufferItemList[iContactsBufferItemList.Count() - 1]->iItemData == iItemData ) |
|
239 { |
|
240 iItemData = NULL; |
|
241 } |
|
242 } |
|
243 iContactsBufferItemList.ResetAndDestroy(); |
|
244 delete iDataMod; |
|
245 delete iMergeItem; |
|
246 |
|
247 if(iItemData) |
|
248 { |
|
249 if(iItemData->Size() > 0 ) |
|
250 { |
|
251 delete iItemData; |
|
252 } |
|
253 } |
|
254 |
|
255 if(iItemDataAddBatch != iItemData) |
|
256 { |
|
257 delete iItemDataAddBatch; |
|
258 } |
|
259 |
|
260 delete iDefaultStoreName; |
|
261 delete iPacketStoreName; |
|
262 |
|
263 delete iStoreName; |
|
264 |
|
265 iAddResultArray.Close(); |
|
266 |
|
267 } |
|
268 |
|
269 // ---------------------------------------------------------------------------- |
|
270 // void CNSmlContactsDataStore::DoOpenL(const TDesC& aStoreName, |
|
271 // MSmlSyncRelationship& aContext, |
|
272 // TRequestStatus& aStatus) |
|
273 // ---------------------------------------------------------------------------- |
|
274 void CNSmlContactsDataStore::DoOpenL( const TDesC& aStoreName, |
|
275 MSmlSyncRelationship& aContext, |
|
276 TRequestStatus& aStatus ) |
|
277 { |
|
278 DBG_ARGS(_S("CNSmlContactsDataStore::DoOpenL(): '%S' begin"), &aStoreName); |
|
279 |
|
280 iCallerStatus = &aStatus; |
|
281 *iCallerStatus = KRequestPending; |
|
282 |
|
283 if( iState != ENSmlClosed ) |
|
284 { |
|
285 User::RequestComplete( iCallerStatus, KErrInUse ); |
|
286 return; |
|
287 } |
|
288 |
|
289 if( RFs::CharToDrive(aStoreName[0], iDrive) != KErrNone ) |
|
290 { |
|
291 RFs::CharToDrive( KNSmlDriveC()[0], iDrive ); |
|
292 } |
|
293 iOpened = EFalse; |
|
294 |
|
295 if( iStoreName ) |
|
296 { |
|
297 delete iStoreName; |
|
298 iStoreName = NULL; |
|
299 } |
|
300 |
|
301 if ( iChangeFinder ) |
|
302 { |
|
303 iChangeFinder->CloseL(); |
|
304 delete iChangeFinder; |
|
305 iChangeFinder = NULL; |
|
306 } |
|
307 // The Change finder maintains a list of all changes to the database. |
|
308 iChangeFinder = CNSmlChangeFinder::NewL( |
|
309 aContext, iKey, iSyncHistory, KNSmlContactsAdapterImplUid ); |
|
310 |
|
311 iState = ENSmlOpenAndWaiting; |
|
312 |
|
313 //find and open the store |
|
314 if ( aStoreName == KNSmlContactStoreNameForDefaultDB ) |
|
315 { |
|
316 iStore = iContactManager->ContactStoresL().Find( |
|
317 TVPbkContactStoreUriPtr(*iDefaultStoreName)); |
|
318 } |
|
319 else |
|
320 { |
|
321 iStore = iContactManager->ContactStoresL().Find( |
|
322 TVPbkContactStoreUriPtr(aStoreName)); |
|
323 } |
|
324 iStore->OpenL(*this); |
|
325 |
|
326 iStoreName = aStoreName.AllocL(); |
|
327 |
|
328 iVCardEngine = CVPbkVCardEng::NewL( *iContactManager ); |
|
329 iIdConverter = CVPbkContactIdConverter::NewL(*iStore ); |
|
330 if ( iContactsModsFetcher ) |
|
331 { |
|
332 iContactsModsFetcher->Cancel(); |
|
333 delete iContactsModsFetcher; |
|
334 iContactsModsFetcher = NULL; |
|
335 } |
|
336 |
|
337 iContactsModsFetcher = new (ELeave) CNSmlContactsModsFetcher( |
|
338 iSnapshotRegistered, *iContactManager,*iStore, iKey, *iChangeFinder ); |
|
339 iContactsModsFetcher->ConstructL(); |
|
340 |
|
341 #ifdef __NSML_MODULETEST__ |
|
342 CActiveScheduler::Start(); |
|
343 #endif |
|
344 |
|
345 _DBG_FILE("CNSmlContactsDataStore::DoOpenL(): end"); |
|
346 } |
|
347 |
|
348 // ---------------------------------------------------------------------------- |
|
349 // void CNSmlContactsDataStore::DoCancelRequest() |
|
350 // ---------------------------------------------------------------------------- |
|
351 void CNSmlContactsDataStore::DoCancelRequest() |
|
352 { |
|
353 _DBG_FILE("CNSmlContactsDataStore::DoCancelRequest(): begin"); |
|
354 if(iContactsModsFetcher) |
|
355 { |
|
356 iContactsModsFetcher->Cancel(); |
|
357 } |
|
358 |
|
359 _DBG_FILE("CNSmlContactsDataStore::DoCancelRequest(): NOT NEEDED end"); |
|
360 } |
|
361 |
|
362 // ---------------------------------------------------------------------------- |
|
363 // void CNSmlContactsDataStore::DoStoreName() |
|
364 // ---------------------------------------------------------------------------- |
|
365 const TDesC& CNSmlContactsDataStore::DoStoreName() const |
|
366 { |
|
367 _DBG_FILE("CNSmlContactsDataStore::DoStoreName(): begin"); |
|
368 _DBG_FILE("CNSmlContactsDataStore::DoStoreName(): end"); |
|
369 return *iStoreName; |
|
370 } |
|
371 |
|
372 // ---------------------------------------------------------------------------- |
|
373 // void CNSmlContactsDataStore::DefaultStoreNameL() |
|
374 // ---------------------------------------------------------------------------- |
|
375 const TDesC& CNSmlContactsDataStore::DefaultStoreNameL() const |
|
376 { |
|
377 _DBG_FILE("CNSmlContactsDataStore::DefaultStoreNameL(): begin"); |
|
378 |
|
379 if ( !iDefaultStoreName ) |
|
380 { |
|
381 return KNullDesC; |
|
382 } |
|
383 |
|
384 _DBG_FILE("CNSmlContactsDataStore::DefaultStoreNameL(): end"); |
|
385 //The engine methods that create syncml packet, use this information in Database fields |
|
386 return *iPacketStoreName; |
|
387 } |
|
388 |
|
389 // ---------------------------------------------------------------------------- |
|
390 // void CNSmlContactsDataStore::DoBeginTransactionL() |
|
391 // ---------------------------------------------------------------------------- |
|
392 void CNSmlContactsDataStore::DoBeginTransactionL() |
|
393 { |
|
394 _DBG_FILE("CNSmlContactsDataStore::DoBeginTransactionL(): begin"); |
|
395 User::Leave( KErrNotSupported ); |
|
396 _DBG_FILE("CNSmlContactsDataStore::DoBeginTransactionL(): end"); |
|
397 } |
|
398 |
|
399 // ---------------------------------------------------------------------------- |
|
400 // void CNSmlContactsDataStore::DoCommitTransactionL() |
|
401 // ---------------------------------------------------------------------------- |
|
402 void CNSmlContactsDataStore::DoCommitTransactionL(TRequestStatus& aStatus) |
|
403 { |
|
404 _DBG_FILE("CNSmlContactsDataStore::DoCommitTransactionL(): begin"); |
|
405 |
|
406 iCallerStatus = &aStatus; |
|
407 *iCallerStatus = KRequestPending; |
|
408 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
|
409 |
|
410 _DBG_FILE("CNSmlContactsDataStore::DoCommitTransactionL(): end"); |
|
411 } |
|
412 |
|
413 // ---------------------------------------------------------------------------- |
|
414 // void CNSmlContactsDataStore::DoRevertTransaction() |
|
415 // ---------------------------------------------------------------------------- |
|
416 void CNSmlContactsDataStore::DoRevertTransaction(TRequestStatus& aStatus) |
|
417 { |
|
418 _DBG_FILE("CNSmlContactsDataStore::DoRevertTransaction(): begin"); |
|
419 |
|
420 iCallerStatus = &aStatus; |
|
421 *iCallerStatus = KRequestPending; |
|
422 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
|
423 |
|
424 _DBG_FILE("CNSmlContactsDataStore::DoRevertTransaction(): end"); |
|
425 } |
|
426 |
|
427 // ---------------------------------------------------------------------------- |
|
428 // void CNSmlContactsDataStore::DoBeginBatchL() |
|
429 // ---------------------------------------------------------------------------- |
|
430 void CNSmlContactsDataStore::DoBeginBatchL() |
|
431 { |
|
432 _DBG_FILE("CNSmlContactsDataStore::DoBeginBatchL(): begin"); |
|
433 |
|
434 iBatchMode = ETrue; // SUPPORTED on Contacts |
|
435 |
|
436 _DBG_FILE("CNSmlContactsDataStore::DoBeginBatchL(): end"); |
|
437 } |
|
438 |
|
439 // ---------------------------------------------------------------------------- |
|
440 // void CNSmlContactsDataStore::DoCommitBatchL() |
|
441 // ---------------------------------------------------------------------------- |
|
442 void CNSmlContactsDataStore::DoCommitBatchL( RArray<TInt>& aResultArray, TRequestStatus& aStatus ) |
|
443 { |
|
444 _DBG_FILE("CNSmlContactsDataStore::DoCommitBatchL(): begin"); |
|
445 |
|
446 iCallerStatus = &aStatus; |
|
447 *iCallerStatus = KRequestPending; |
|
448 |
|
449 if( !iBatchMode ) |
|
450 { |
|
451 User::RequestComplete( iCallerStatus, KErrNotReady ); |
|
452 _DBG_FILE("CNSmlContactsDataStore::DoCommitBatchL(): NOT ON BATCH MODE end"); |
|
453 return; |
|
454 } |
|
455 // |
|
456 // Go through Buffer and execute all commands return aResultArray |
|
457 // |
|
458 |
|
459 iResultArray = &aResultArray; |
|
460 |
|
461 iIndex = 0; |
|
462 TRAPD( leavecode,ExecuteBufferL() ); |
|
463 |
|
464 if( leavecode != KErrNone ) |
|
465 { |
|
466 User::RequestComplete( iCallerStatus, leavecode ); |
|
467 } |
|
468 |
|
469 _DBG_FILE("CNSmlContactsDataStore::DoCommitBatchL(): end"); |
|
470 } |
|
471 |
|
472 // ---------------------------------------------------------------------------- |
|
473 // void CNSmlContactsDataStore::ExecuteBufferL() |
|
474 // ---------------------------------------------------------------------------- |
|
475 void CNSmlContactsDataStore::ExecuteBufferL() |
|
476 { |
|
477 _DBG_FILE("CNSmlContactsDataStore::ExecuteBufferL(): begin"); |
|
478 |
|
479 TInt retCommand( KErrNone ); |
|
480 |
|
481 // |
|
482 // Loop through buffered commands |
|
483 // |
|
484 if( iIndex < iContactsBufferItemList.Count()) |
|
485 { |
|
486 |
|
487 if( iContactsBufferItemList[iIndex]->iStatus!= KNSmlNoError ) |
|
488 { |
|
489 retCommand = iContactsBufferItemList[iIndex]->iStatus; |
|
490 } |
|
491 else if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemAdd ) |
|
492 { |
|
493 retCommand = ExecuteAddL(); |
|
494 } |
|
495 else if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemReplace ) |
|
496 { |
|
497 ExecuteUpdateL(); |
|
498 } |
|
499 else if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemMove ) |
|
500 { |
|
501 ExecuteMoveL(); |
|
502 } |
|
503 else if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemDelete || |
|
504 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemSoftDelete ) |
|
505 { |
|
506 ExecuteDeleteL(); |
|
507 } |
|
508 // |
|
509 // Set allready set commands from iContactsBufferItemList |
|
510 // |
|
511 if( ( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemAdd || |
|
512 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemReplace || |
|
513 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemDelete || |
|
514 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemSoftDelete ) && |
|
515 iContactsBufferItemList[iIndex]->iStatus != KNSmlNoError ) |
|
516 { |
|
517 retCommand = iContactsBufferItemList[iIndex]->iStatus; |
|
518 } |
|
519 |
|
520 |
|
521 //if an error occurs when performing any operation |
|
522 //return the error status |
|
523 else if(retCommand!=KErrNone) |
|
524 { |
|
525 User::RequestComplete( iCallerStatus, retCommand ); |
|
526 } |
|
527 |
|
528 iRetCommand = retCommand; |
|
529 } |
|
530 } |
|
531 |
|
532 // ---------------------------------------------------------------------------- |
|
533 // void CNSmlContactsDataStore::ExecuteAddL() |
|
534 // ---------------------------------------------------------------------------- |
|
535 |
|
536 TInt CNSmlContactsDataStore::ExecuteAddL() |
|
537 { |
|
538 TInt retCommand( KErrNone ); |
|
539 StripPropertyL( iItemDataAddBatch, KVersitTokenUID() ); // Remove UID's from data |
|
540 |
|
541 TInt err( KErrNone ); |
|
542 if(iBatchMode) |
|
543 { |
|
544 TRAP( err,LdoAddItemsL( iItemDataAddBatch, |
|
545 iItemDataAddBatch->Ptr(0).Length()) ); |
|
546 if(err!=KErrNone) |
|
547 { |
|
548 retCommand = err; |
|
549 TInt j = iIndex; |
|
550 while( j < iContactsBufferItemList.Count() ) |
|
551 { |
|
552 if( iContactsBufferItemList[j]->iModType == ENSmlCntItemAdd && |
|
553 iContactsBufferItemList[j]->iStatus == KNSmlNoError ) |
|
554 { |
|
555 iContactsBufferItemList[j]->iStatus = KErrNotSupported; |
|
556 iResultArray->AppendL(KErrNotSupported); |
|
557 } |
|
558 j++; |
|
559 } |
|
560 } |
|
561 } |
|
562 else |
|
563 { |
|
564 const TPtr8 dataPtr = iItemDataAddBatch->Ptr(0); |
|
565 TRAP( err, LdoAddItemL( dataPtr, |
|
566 iContactsBufferItemList[iIndex]->iSize)); |
|
567 if(err!=KErrNone) |
|
568 { |
|
569 retCommand = err; |
|
570 } |
|
571 } |
|
572 return retCommand; |
|
573 } |
|
574 |
|
575 // ---------------------------------------------------------------------------- |
|
576 // void CNSmlContactsDataStore::ExecuteDeleteL() |
|
577 // ---------------------------------------------------------------------------- |
|
578 |
|
579 void CNSmlContactsDataStore:: ExecuteDeleteL() |
|
580 { |
|
581 |
|
582 if(iBatchMode) |
|
583 { |
|
584 iContactLnks = CVPbkContactLinkArray::NewL(); |
|
585 |
|
586 TInt j=iIndex; |
|
587 while( j < iContactsBufferItemList.Count() ) |
|
588 { |
|
589 if( (iContactsBufferItemList[j]->iModType == ENSmlCntItemDelete || |
|
590 iContactsBufferItemList[j]->iModType == ENSmlCntItemSoftDelete) && |
|
591 iContactsBufferItemList[j]->iStatus == KNSmlNoError ) |
|
592 { |
|
593 TContactItemId id = iContactsBufferItemList[j]->iUid; |
|
594 |
|
595 if( id != 0 ) |
|
596 { |
|
597 MVPbkContactLink* contactLink = iIdConverter->IdentifierToLinkLC(id); |
|
598 //check if the contact link is valid |
|
599 TInt index = iContactViewBase->IndexOfLinkL(*contactLink); |
|
600 if(index != KErrNotFound) |
|
601 { |
|
602 iContactLnks->AppendL(contactLink); |
|
603 } |
|
604 else |
|
605 { |
|
606 iContactsBufferItemList[j]->iStatus = KErrNotFound; |
|
607 } |
|
608 |
|
609 CleanupStack::Pop();//contactLink |
|
610 } |
|
611 else |
|
612 { |
|
613 iContactsBufferItemList[j]->iStatus = KErrNotFound; |
|
614 } |
|
615 } |
|
616 j++; |
|
617 } |
|
618 |
|
619 delete iContactViewBase; |
|
620 iContactViewBase = NULL; |
|
621 |
|
622 iContactManager->DeleteContactsL( *iContactLnks, *this ); |
|
623 iLastOperation = ENSmlDeleteOp; |
|
624 } |
|
625 |
|
626 } |
|
627 |
|
628 // ---------------------------------------------------------------------------- |
|
629 // void CNSmlContactsDataStore::ExecuteUpdateL() |
|
630 // ---------------------------------------------------------------------------- |
|
631 |
|
632 void CNSmlContactsDataStore::ExecuteUpdateL() |
|
633 { |
|
634 iUid = iContactsBufferItemList[iIndex]->iUid; |
|
635 |
|
636 iDataMod->SetUsedMimeType( iServerMimeType, iServerMimeVersion ); |
|
637 |
|
638 // Check whether merging is needed or not. |
|
639 if( iDataMod->NeedsMerge() ) |
|
640 { |
|
641 iMergeItem = CBufFlat::NewL(64); |
|
642 iWriteStream.Open(*iMergeItem); |
|
643 |
|
644 MVPbkContactLink* contactLink = iIdConverter->IdentifierToLinkLC(iUid); |
|
645 |
|
646 iVCardEngine->ExportVCardForSyncL(iWriteStream,*contactLink,*this); |
|
647 CleanupStack::PopAndDestroy(); |
|
648 |
|
649 iLastOperation = ENSMLUpdateExportOp; |
|
650 } |
|
651 else |
|
652 { |
|
653 LdoUpdateItemL(); |
|
654 } |
|
655 } |
|
656 |
|
657 // ---------------------------------------------------------------------------- |
|
658 // void CNSmlContactsDataStore::ExecuteMoveL |
|
659 // ---------------------------------------------------------------------------- |
|
660 |
|
661 void CNSmlContactsDataStore::ExecuteMoveL() |
|
662 { |
|
663 // move command is not supported |
|
664 if(!iBatchMode) |
|
665 { |
|
666 ResetBuffer(); |
|
667 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
|
668 } |
|
669 else |
|
670 { |
|
671 iResultArray->AppendL(KErrNotSupported); |
|
672 iIndex++; |
|
673 if(iIndex == iContactsBufferItemList.Count() ) |
|
674 { |
|
675 ResetBuffer(); |
|
676 User::RequestComplete( iCallerStatus, KErrNone ); |
|
677 } |
|
678 else |
|
679 { |
|
680 ExecuteBufferL(); |
|
681 } |
|
682 } |
|
683 } |
|
684 // ---------------------------------------------------------------------------- |
|
685 // void CNSmlContactsDataStore::DoCancelBatch() |
|
686 // ---------------------------------------------------------------------------- |
|
687 void CNSmlContactsDataStore::DoCancelBatch() |
|
688 { |
|
689 _DBG_FILE("CNSmlContactsDataStore::DoCancelBatch(): begin"); |
|
690 if( iBatchMode ) |
|
691 { |
|
692 iBatchMode = EFalse; |
|
693 // |
|
694 // Empty BufferItemList if any |
|
695 // |
|
696 iContactsBufferItemList.ResetAndDestroy(); |
|
697 iItemData = NULL; |
|
698 } |
|
699 |
|
700 _DBG_FILE("CNSmlContactsDataStore::DoCancelBatch(): end"); |
|
701 } |
|
702 |
|
703 // ---------------------------------------------------------------------------- |
|
704 // void CNSmlContactsDataStore::DoSetRemoteStoreFormatL() |
|
705 // ---------------------------------------------------------------------------- |
|
706 void CNSmlContactsDataStore::DoSetRemoteStoreFormatL( const CSmlDataStoreFormat& aServerDataStoreFormat ) |
|
707 { |
|
708 _DBG_FILE("CNSmlContactsDataStore::DoSetRemoteStoreFormatL(): begin"); |
|
709 |
|
710 TBool foundMime = EFalse; |
|
711 |
|
712 // |
|
713 // KErrNotSupported is returned if server does not support same mime type |
|
714 // and same mime type version as Data Provider. |
|
715 |
|
716 TInt i=0; |
|
717 while( i< aServerDataStoreFormat.MimeFormatCount() && !foundMime ) |
|
718 { |
|
719 if( iUsedMimeType.MatchF(aServerDataStoreFormat.MimeFormat(i).MimeType().DesC()) ==0 && |
|
720 iUsedMimeVersion.MatchF(aServerDataStoreFormat.MimeFormat(i).MimeVersion().DesC())==0 ) |
|
721 { |
|
722 foundMime = ETrue; |
|
723 iServerMimeType = aServerDataStoreFormat.MimeFormat(i).MimeType(); |
|
724 iServerMimeVersion = aServerDataStoreFormat.MimeFormat(i).MimeVersion(); |
|
725 } |
|
726 i++; |
|
727 } |
|
728 |
|
729 if( !foundMime ) |
|
730 { |
|
731 _DBG_FILE("CNSmlContactsDataStore::DoSetRemoteStoreFormatL(): SERVER MIMETYPE NOTSUPPORTED end"); |
|
732 User::Leave( KErrNotSupported ); |
|
733 } |
|
734 |
|
735 iDataMod->SetPartnerStoreFormat( (CSmlDataStoreFormat&) aServerDataStoreFormat ); |
|
736 |
|
737 SetOwnStoreFormatL(); |
|
738 |
|
739 TInt error = iDataMod->SetUsedMimeType( iServerMimeType, iServerMimeVersion ); |
|
740 |
|
741 User::LeaveIfError( error ); |
|
742 |
|
743 _DBG_FILE("CNSmlContactsDataStore::DoSetRemoteStoreFormatL(): end"); |
|
744 return; |
|
745 } |
|
746 |
|
747 // ---------------------------------------------------------------------------- |
|
748 // void CNSmlContactsDataStore::SetOwnStoreFormatL() |
|
749 // ---------------------------------------------------------------------------- |
|
750 void CNSmlContactsDataStore::SetOwnStoreFormatL() |
|
751 { |
|
752 _DBG_FILE("CNSmlContactsDataStore::SetOwnStoreFormatL(): begin"); |
|
753 |
|
754 if( !iStoreFormat ) |
|
755 { |
|
756 TFileName fileName; |
|
757 TParse parse; |
|
758 |
|
759 // Check correct Data Sync protocol |
|
760 TInt value( EDataSyncNotRunning ); |
|
761 TInt error = RProperty::Get( KPSUidDataSynchronizationInternalKeys, |
|
762 KDataSyncStatus, |
|
763 value ); |
|
764 if ( error == KErrNone && |
|
765 value == EDataSyncRunning ) |
|
766 { |
|
767 parse.Set( KNSmlContactsStoreFormatRsc_1_1_2, &KDC_RESOURCE_FILES_DIR, NULL ); |
|
768 } |
|
769 else // error or protocol version 1.2 |
|
770 { |
|
771 parse.Set( KNSmlContactsStoreFormatRsc_1_2, &KDC_RESOURCE_FILES_DIR, NULL ); |
|
772 } |
|
773 |
|
774 fileName = parse.FullName(); |
|
775 |
|
776 RResourceFile resourceFile; |
|
777 BaflUtils::NearestLanguageFile( iRfs, fileName ); |
|
778 |
|
779 resourceFile.OpenL( iRfs, fileName ); |
|
780 CleanupClosePushL( resourceFile ); |
|
781 |
|
782 HBufC8* contactsDataFormat = resourceFile.AllocReadLC( NSML_CONTACTS_DATA_STORE_FORMAT ); |
|
783 |
|
784 TResourceReader reader; |
|
785 reader.SetBuffer( contactsDataFormat ); |
|
786 |
|
787 iStoreFormat = CSmlDataStoreFormat::NewLC( iStringPool, reader ); |
|
788 CleanupStack::Pop(iStoreFormat); // iStoreFormat |
|
789 |
|
790 CleanupStack::PopAndDestroy(2); // contactsDataFormat, resourceFile |
|
791 } |
|
792 |
|
793 iDataMod->SetOwnStoreFormat( *iStoreFormat ); |
|
794 |
|
795 _DBG_FILE("CNSmlContactsDataStore::SetOwnStoreFormatL(): end"); |
|
796 return; |
|
797 } |
|
798 |
|
799 // ---------------------------------------------------------------------------- |
|
800 // void CNSmlContactsDataStore::DoSetRemoteMaxObjectSize() |
|
801 // ---------------------------------------------------------------------------- |
|
802 void CNSmlContactsDataStore::DoSetRemoteMaxObjectSize( TInt aServerMaxObjectSize ) |
|
803 { |
|
804 _DBG_FILE("CNSmlContactsDataStore::DoSetRemoteMaxObjectSize(): begin"); |
|
805 |
|
806 iServerMaxObjectSize = aServerMaxObjectSize; |
|
807 |
|
808 _DBG_FILE("CNSmlContactsDataStore::DoSetRemoteMaxObjectSize(): end"); |
|
809 } |
|
810 |
|
811 // ---------------------------------------------------------------------------- |
|
812 // void CNSmlContactsDataStore::DoMaxObjectSize() |
|
813 // ---------------------------------------------------------------------------- |
|
814 TInt CNSmlContactsDataStore::DoMaxObjectSize() const |
|
815 { |
|
816 _DBG_FILE("CNSmlContactsDataStore::DoMaxObjectSize(): begin"); |
|
817 _DBG_FILE("CNSmlContactsDataStore::DoMaxObjectSize() 100 k: end"); |
|
818 return KNSmlDataStoreMaxSize; // 100 k |
|
819 } |
|
820 |
|
821 // ---------------------------------------------------------------------------- |
|
822 // void CNSmlContactsDataStore::DoOpenItemL() |
|
823 // ---------------------------------------------------------------------------- |
|
824 void CNSmlContactsDataStore::DoOpenItemL( TSmlDbItemUid aUid, |
|
825 TBool& aFieldChange, |
|
826 TInt& aSize, |
|
827 TSmlDbItemUid& aParent, |
|
828 TDes8& aMimeType, |
|
829 TDes8& aMimeVer, |
|
830 TRequestStatus& aStatus ) |
|
831 { |
|
832 _DBG_FILE("CNSmlContactsDataStore::DoOpenItemL(): begin"); |
|
833 |
|
834 iCallerStatus = &aStatus; |
|
835 *iCallerStatus = KRequestPending; |
|
836 |
|
837 if ( iState != ENSmlOpenAndWaiting ) |
|
838 { |
|
839 User::RequestComplete( iCallerStatus, KErrNotReady ); |
|
840 return; |
|
841 } |
|
842 |
|
843 iItemPos = 0; |
|
844 |
|
845 aFieldChange = EFalse; // Whole item sent NOT SUPPORT ON FIELDCHANGE |
|
846 |
|
847 aMimeType = iStoreFormat->MimeFormat( 0 ).MimeType().DesC(); |
|
848 aMimeVer = iStoreFormat->MimeFormat( 0 ).MimeVersion().DesC(); |
|
849 aParent = KNullDataItemId; |
|
850 |
|
851 iModType = ENSmlCntItemRead; |
|
852 |
|
853 if( !iItemData ) |
|
854 { |
|
855 iItemData= CBufFlat::NewL( KNSmlItemDataExpandSize ); |
|
856 } |
|
857 else |
|
858 { |
|
859 iItemData->Reset(); |
|
860 } |
|
861 |
|
862 LdoFetchItemL( aUid, *iItemData ); |
|
863 iSize = &aSize; |
|
864 |
|
865 _DBG_FILE("CNSmlContactsDataStore::DoOpenItemL(): end"); |
|
866 } |
|
867 |
|
868 // ---------------------------------------------------------------------------- |
|
869 // void CNSmlContactsDataStore::DoCreateItemL() |
|
870 // ---------------------------------------------------------------------------- |
|
871 void CNSmlContactsDataStore::DoCreateItemL( TSmlDbItemUid& aUid, |
|
872 TInt aSize, |
|
873 TSmlDbItemUid /*aParent*/, |
|
874 const TDesC8& aMimeType, |
|
875 const TDesC8& aMimeVer, |
|
876 TRequestStatus& aStatus ) |
|
877 { |
|
878 _DBG_FILE("CNSmlContactsDataStore::DoCreateItemL(): begin"); |
|
879 |
|
880 iCallerStatus = &aStatus; |
|
881 *iCallerStatus = KRequestPending; |
|
882 |
|
883 TInt err = KErrNone; |
|
884 |
|
885 if ( iState != ENSmlOpenAndWaiting ) |
|
886 { |
|
887 User::RequestComplete( iCallerStatus, KErrNotReady ); |
|
888 _DBG_FILE("CNSmlContactsDataStore::DoCreateItemL - KErrNotReady: END"); |
|
889 return; |
|
890 } |
|
891 |
|
892 iItemSize = aSize; // Size sent from server |
|
893 iModType = ENSmlCntItemAdd; |
|
894 |
|
895 iMimeTypeItem.Set( aMimeType ); |
|
896 iMimeVersionItem.Set( aMimeVer ); |
|
897 |
|
898 if ( iItemPos == -1 || !iBatchMode ) |
|
899 { |
|
900 iItemPos = 0; |
|
901 } |
|
902 |
|
903 |
|
904 if( iItemData ) |
|
905 { |
|
906 iItemData->Reset(); |
|
907 } |
|
908 |
|
909 if( !iItemDataAddBatch ) |
|
910 { |
|
911 iItemDataAddBatch= CBufFlat::NewL( KNSmlItemDataExpandSize ); |
|
912 } |
|
913 |
|
914 // Check MimeType and MimeVersion |
|
915 if( ( aMimeType.MatchF( KNSmlvCard21Name ) < 0 ) && |
|
916 ( aMimeType.MatchF( KNSmlvCard30Name ) < 0 )) |
|
917 { |
|
918 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
|
919 _DBG_FILE("CNSmlContactsDataStore::DoCreateItemL - KErrNotSupported: END"); |
|
920 return; |
|
921 } |
|
922 |
|
923 // Is there enough space on drive |
|
924 if( DriveBelowCriticalLevelL( aSize ) ) |
|
925 { |
|
926 err = KErrDiskFull; |
|
927 } |
|
928 |
|
929 iItemData = AddBufferListL( aUid,aSize, err ); |
|
930 |
|
931 if( iBatchMode ) |
|
932 { |
|
933 iState = ENSmlItemCreating; |
|
934 User::RequestComplete( iCallerStatus, KErrNone ); |
|
935 _DBG_FILE("CNSmlContactsDataStore::DoCreateItemL(): begin BATCH"); |
|
936 return ; // Put into buffer |
|
937 } |
|
938 |
|
939 if ( err == KErrNone ) |
|
940 { |
|
941 iState = ENSmlItemCreating; |
|
942 } |
|
943 |
|
944 User::RequestComplete( iCallerStatus, err ); |
|
945 |
|
946 _DBG_FILE("CNSmlContactsDataStore::DoCreateItemL(): end"); |
|
947 } |
|
948 |
|
949 // ---------------------------------------------------------------------------- |
|
950 // void CNSmlContactsDataStore::DoReplaceItemL() |
|
951 // ---------------------------------------------------------------------------- |
|
952 void CNSmlContactsDataStore::DoReplaceItemL( TSmlDbItemUid aUid, |
|
953 TInt aSize, |
|
954 TSmlDbItemUid /*aParent*/, |
|
955 TBool aFieldChange, |
|
956 TRequestStatus& aStatus ) |
|
957 { |
|
958 _DBG_FILE("CNSmlContactsDataStore::DoReplaceItemL(): begin"); |
|
959 |
|
960 iCallerStatus = &aStatus; |
|
961 *iCallerStatus = KRequestPending; |
|
962 |
|
963 TInt err = KErrNone; |
|
964 |
|
965 iUid = aUid; |
|
966 iItemSize = aSize; |
|
967 iModType = ENSmlCntItemReplace; |
|
968 |
|
969 if ( iItemPos == -1 || !iBatchMode ) |
|
970 { |
|
971 iItemPos = 0; |
|
972 } |
|
973 |
|
974 if ( iItemData ) |
|
975 { |
|
976 iItemData->Reset(); |
|
977 } |
|
978 |
|
979 // Field change not supported |
|
980 if( aFieldChange ) |
|
981 { |
|
982 err = KErrNotSupported; |
|
983 if( !iBatchMode ) |
|
984 { |
|
985 User::RequestComplete( iCallerStatus, err ); |
|
986 return; |
|
987 } |
|
988 } |
|
989 |
|
990 iItemData = AddBufferListL( aUid, aSize, err ); |
|
991 |
|
992 if( iBatchMode ) |
|
993 { |
|
994 iState = ENSmlItemUpdating; |
|
995 _DBG_FILE("CNSmlContactsDataStore::DoReplaceItemL(): BATCHMODE end"); |
|
996 User::RequestComplete( iCallerStatus, KErrNone ); |
|
997 return; |
|
998 } |
|
999 if ( err == KErrNone ) |
|
1000 { |
|
1001 iState = ENSmlItemUpdating; |
|
1002 } |
|
1003 |
|
1004 User::RequestComplete( iCallerStatus, err ); |
|
1005 |
|
1006 _DBG_FILE("CNSmlContactsDataStore::DoReplaceItemL(): end"); |
|
1007 } |
|
1008 |
|
1009 // ---------------------------------------------------------------------------- |
|
1010 // void CNSmlContactsDataStore::DoReadItemL() |
|
1011 // ---------------------------------------------------------------------------- |
|
1012 void CNSmlContactsDataStore::DoReadItemL( TDes8& aBuffer ) |
|
1013 { |
|
1014 _DBG_FILE("CNSmlContactsDataStore::DoReadItemL(): begin"); |
|
1015 |
|
1016 if ( iState != ENSmlItemOpen || !iItemData ) |
|
1017 { |
|
1018 iItemPos = -1; |
|
1019 User::Leave( KErrNotReady ); |
|
1020 } |
|
1021 |
|
1022 if ( iItemPos == -1 ) |
|
1023 { |
|
1024 User::Leave( KErrEof ); |
|
1025 } |
|
1026 |
|
1027 if ( aBuffer.Size() < iItemData->Size() - iItemPos ) |
|
1028 { |
|
1029 iItemData->Read( iItemPos, aBuffer ); |
|
1030 iItemPos += aBuffer.Size(); |
|
1031 } |
|
1032 else |
|
1033 { |
|
1034 iItemData->Read( iItemPos, aBuffer, iItemData->Size() - iItemPos ); |
|
1035 iItemPos = -1; |
|
1036 } |
|
1037 |
|
1038 _DBG_FILE("CNSmlContactsDataStore::DoReadItemL(): end"); |
|
1039 } |
|
1040 |
|
1041 // ---------------------------------------------------------------------------- |
|
1042 // void CNSmlContactsDataStore::DoWriteItemL() |
|
1043 // ---------------------------------------------------------------------------- |
|
1044 void CNSmlContactsDataStore::DoWriteItemL( const TDesC8& aData ) |
|
1045 { |
|
1046 _DBG_FILE("CNSmlContactsDataStore::DoWriteItemL(): begin"); |
|
1047 |
|
1048 /* Data must be accumulated from pieces of information */ |
|
1049 if ( iState == ENSmlItemCreating || iState == ENSmlItemUpdating ) |
|
1050 { |
|
1051 if ( iItemData ) |
|
1052 { |
|
1053 if ( iItemPos == -1 ) |
|
1054 { |
|
1055 iStateItem = KErrEof; |
|
1056 if( iBatchMode ) |
|
1057 { |
|
1058 return; |
|
1059 } |
|
1060 User::Leave( KErrEof ); |
|
1061 } |
|
1062 iItemData->InsertL( iItemData->Size(), aData ); |
|
1063 iItemPos += aData.Size(); |
|
1064 |
|
1065 if ( aData.Size() > iItemSize ) |
|
1066 { |
|
1067 iState = ENSmlItemOverflow; |
|
1068 iStateItem = KErrOverflow; |
|
1069 _DBG_FILE("CNSmlContactsDataStore::DoWriteItemL(): KErrOverflow End"); |
|
1070 DBG_ARGS(_S("CNSmlContactsDataStore::DoWriteItemL(): Server sent=(%d) Item=(%d)"), |
|
1071 iItemSize, aData.Size()); |
|
1072 if( iBatchMode ) |
|
1073 { |
|
1074 return; |
|
1075 } |
|
1076 User::Leave( KErrOverflow ); |
|
1077 } |
|
1078 if ( aData.Size() == iItemSize ) |
|
1079 { |
|
1080 iStateItem = KErrNone; |
|
1081 } |
|
1082 return; |
|
1083 } |
|
1084 } |
|
1085 |
|
1086 iStateItem = KErrNotReady; |
|
1087 |
|
1088 if( iBatchMode ) |
|
1089 { |
|
1090 _DBG_FILE("CNSmlContactsDataStore::DoWriteItemL(): KErrNotReady End"); |
|
1091 return; |
|
1092 } |
|
1093 |
|
1094 User::Leave( KErrNotReady ); |
|
1095 |
|
1096 _DBG_FILE("CNSmlContactsDataStore::DoWriteItemL(): end"); |
|
1097 } |
|
1098 |
|
1099 // ---------------------------------------------------------------------------- |
|
1100 // void CNSmlContactsDataStore::DoCommitItemL() |
|
1101 // ---------------------------------------------------------------------------- |
|
1102 void CNSmlContactsDataStore::DoCommitItemL( TRequestStatus& aStatus ) |
|
1103 { |
|
1104 iCallerStatus = &aStatus; |
|
1105 *iCallerStatus = KRequestPending; |
|
1106 |
|
1107 _DBG_FILE("CNSmlContactsDataStore::DoCommitItemL(): begin"); |
|
1108 |
|
1109 // Data OK => insert to total buffer |
|
1110 if (iModType == ENSmlCntItemAdd && |
|
1111 iStateItem == KErrNone ) |
|
1112 { |
|
1113 iItemDataAddBatch->InsertL( iItemDataAddBatch->Size(),iItemData->Ptr(0), iItemData->Size() ); |
|
1114 iItemDataAddBatch->InsertL( iItemDataAddBatch->Size(), KVersitTokenCRLF() ); |
|
1115 if( iContactsBufferItemList.Count() > 0 ) |
|
1116 { |
|
1117 iContactsBufferItemList[iContactsBufferItemList.Count()-1]->iStatus = KNSmlNoError; |
|
1118 } |
|
1119 } |
|
1120 else if ((iModType == ENSmlCntItemAdd || // If some write problems |
|
1121 iModType == ENSmlCntItemReplace) && |
|
1122 iStateItem != KErrNone && |
|
1123 iContactsBufferItemList.Count() > 0) |
|
1124 { |
|
1125 iContactsBufferItemList[iContactsBufferItemList.Count()-1]->iStatus = iStateItem; |
|
1126 } |
|
1127 |
|
1128 if( iBatchMode ) |
|
1129 { |
|
1130 iItemData = NULL; |
|
1131 iState = ENSmlOpenAndWaiting; |
|
1132 User::RequestComplete( iCallerStatus, KErrNone ); |
|
1133 return; |
|
1134 } |
|
1135 |
|
1136 |
|
1137 iIndex = 0; |
|
1138 ExecuteBufferL(); |
|
1139 |
|
1140 iItemData = NULL; |
|
1141 iState = ENSmlOpenAndWaiting; |
|
1142 |
|
1143 _DBG_FILE("CNSmlContactsDataStore::DoCommitItemL(): end"); |
|
1144 } |
|
1145 |
|
1146 // ---------------------------------------------------------------------------- |
|
1147 // void CNSmlContactsDataStore::DoCloseItem() |
|
1148 // ---------------------------------------------------------------------------- |
|
1149 void CNSmlContactsDataStore::DoCloseItem() |
|
1150 { |
|
1151 _DBG_FILE("CNSmlContactsDataStore::DoCloseItem(): begin"); |
|
1152 |
|
1153 if ( iState == ENSmlItemOpen ) |
|
1154 { |
|
1155 iItemPos = -1; |
|
1156 if ( iItemData ) |
|
1157 { |
|
1158 delete iItemData; |
|
1159 iItemData = NULL; |
|
1160 } |
|
1161 iState = ENSmlOpenAndWaiting; |
|
1162 } |
|
1163 |
|
1164 _DBG_FILE("CNSmlContactsDataStore::DoCloseItem(): end"); |
|
1165 } |
|
1166 |
|
1167 // ---------------------------------------------------------------------------- |
|
1168 // void CNSmlContactsDataStore::DoMoveItemL() |
|
1169 // ---------------------------------------------------------------------------- |
|
1170 void CNSmlContactsDataStore::DoMoveItemL( TSmlDbItemUid aUid, TSmlDbItemUid /*aNewParent*/, TRequestStatus& aStatus ) |
|
1171 { |
|
1172 _DBG_FILE("CNSmlContactsDataStore::DoMoveItemL(): begin"); |
|
1173 |
|
1174 iCallerStatus = &aStatus; |
|
1175 *iCallerStatus = KRequestPending; |
|
1176 |
|
1177 if( iBatchMode ) |
|
1178 { |
|
1179 iModType = ENSmlCntItemMove; |
|
1180 TInt fSize = 0; |
|
1181 AddBufferListL( aUid, fSize, KErrNotSupported ); |
|
1182 User::RequestComplete( iCallerStatus, KErrNone ); |
|
1183 return; |
|
1184 } |
|
1185 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
|
1186 |
|
1187 _DBG_FILE("CNSmlContactsDataStore::DoMoveItemL(): end"); |
|
1188 } |
|
1189 |
|
1190 // ---------------------------------------------------------------------------- |
|
1191 // void CNSmlContactsDataStore::DoDeleteItemL() |
|
1192 // ---------------------------------------------------------------------------- |
|
1193 void CNSmlContactsDataStore::DoDeleteItemL( TSmlDbItemUid aUid, TRequestStatus& aStatus ) |
|
1194 { |
|
1195 _DBG_FILE("CNSmlContactsDataStore::DoDeleteItemL(): begin"); |
|
1196 iCallerStatus = &aStatus; |
|
1197 *iCallerStatus = KRequestPending; |
|
1198 |
|
1199 if( iBatchMode ) |
|
1200 { |
|
1201 if(iContactViewBase ==NULL) |
|
1202 { |
|
1203 CreateViewL(); |
|
1204 } |
|
1205 if( iModType != ENSmlCntItemSoftDelete ) // Treated like deletes |
|
1206 { |
|
1207 iModType = ENSmlCntItemDelete; |
|
1208 } |
|
1209 |
|
1210 TInt fSize = 0; |
|
1211 AddBufferListL( aUid, fSize, KErrNone ); |
|
1212 User::RequestComplete( iCallerStatus, KErrNone ); |
|
1213 return; |
|
1214 } |
|
1215 iUid = aUid; |
|
1216 |
|
1217 //add the contactlink to CVPbkContactLinkArray |
|
1218 MVPbkContactLink* contactLink = iIdConverter->IdentifierToLinkLC(aUid); |
|
1219 CleanupStack::Pop(); |
|
1220 CVPbkContactLinkArray* contactLnks = CVPbkContactLinkArray::NewLC(); |
|
1221 contactLnks->AppendL( contactLink ); |
|
1222 |
|
1223 iContactManager->DeleteContactsL( *contactLnks, *this ); |
|
1224 CleanupStack::PopAndDestroy(); |
|
1225 iLastOperation = ENSmlDeleteOp; |
|
1226 |
|
1227 _DBG_FILE("CNSmlContactsDataStore::DoDeleteItemL(): end"); |
|
1228 } |
|
1229 |
|
1230 // ---------------------------------------------------------------------------- |
|
1231 // void CNSmlContactsDataStore::DoSoftDeleteItemL() |
|
1232 // ---------------------------------------------------------------------------- |
|
1233 void CNSmlContactsDataStore::DoSoftDeleteItemL( TSmlDbItemUid /*aUid*/, TRequestStatus& aStatus ) |
|
1234 { |
|
1235 _DBG_FILE("CNSmlContactsDataStore::DoSoftDeleteItemL(): begin"); |
|
1236 iCallerStatus = &aStatus; |
|
1237 *iCallerStatus = KRequestPending; |
|
1238 User::RequestComplete( iCallerStatus, KErrNotSupported ); |
|
1239 _DBG_FILE("CNSmlContactsDataStore::DoSoftDeleteItemL(): end"); |
|
1240 } |
|
1241 |
|
1242 // ---------------------------------------------------------------------------- |
|
1243 // void CNSmlContactsDataStore::DoDeleteAllItemsL() |
|
1244 // ---------------------------------------------------------------------------- |
|
1245 void CNSmlContactsDataStore::DoDeleteAllItemsL( TRequestStatus& aStatus ) |
|
1246 { |
|
1247 _DBG_FILE("CNSmlContactsDataStore::DoDeleteAllItemsL(): begin"); |
|
1248 |
|
1249 iCallerStatus = &aStatus; |
|
1250 *iCallerStatus = KRequestPending; |
|
1251 |
|
1252 //create view to get all the contactlinks to delete |
|
1253 if(iContactViewBase ==NULL) |
|
1254 { |
|
1255 CreateViewL(); |
|
1256 } |
|
1257 |
|
1258 iLastOperation = ENSMLDeleteAllOp; |
|
1259 |
|
1260 _DBG_FILE("CNSmlContactsDataStore::DoDeleteAllItemsL(): end"); |
|
1261 } |
|
1262 |
|
1263 // ---------------------------------------------------------------------------- |
|
1264 // TBool CNSmlContactsDataStore::DoHasSyncHistory() |
|
1265 // ---------------------------------------------------------------------------- |
|
1266 TBool CNSmlContactsDataStore::DoHasSyncHistory() const |
|
1267 { |
|
1268 _DBG_FILE("CNSmlContactsDataStore::DoHasSyncHistory(): begin"); |
|
1269 |
|
1270 TBool doHasSyncHistory = EFalse; |
|
1271 |
|
1272 if( !iOpened ) |
|
1273 { |
|
1274 _DBG_FILE("CNSmlContactsDataStore::DoHasSyncHistory(): NOT OPEN end"); |
|
1275 return doHasSyncHistory; |
|
1276 } |
|
1277 |
|
1278 if( iSyncHistory ) |
|
1279 { |
|
1280 if ( iOpenedStoreId != iChangeFinder->DataStoreUid() ) |
|
1281 { |
|
1282 iChangeFinder->SetDataStoreUid( iOpenedStoreId ); |
|
1283 doHasSyncHistory = EFalse; |
|
1284 } |
|
1285 else |
|
1286 { |
|
1287 doHasSyncHistory = ETrue; |
|
1288 } |
|
1289 } |
|
1290 else |
|
1291 { |
|
1292 iChangeFinder->SetDataStoreUid( iOpenedStoreId ); |
|
1293 } |
|
1294 |
|
1295 _DBG_FILE("CNSmlContactsDataStore::DoHasSyncHistory(): end"); |
|
1296 return doHasSyncHistory; |
|
1297 } |
|
1298 |
|
1299 // ---------------------------------------------------------------------------- |
|
1300 // void CNSmlContactsDataStore::DoAddedItems() |
|
1301 // ---------------------------------------------------------------------------- |
|
1302 const MSmlDataItemUidSet& CNSmlContactsDataStore::DoAddedItems() const |
|
1303 { |
|
1304 _DBG_FILE("CNSmlContactsDataStore::DoAddedItems(): begin"); |
|
1305 if ( iState == ENSmlOpenAndWaiting ) |
|
1306 { |
|
1307 iNewUids->Reset(); |
|
1308 |
|
1309 if( iChangeFinder ) |
|
1310 { |
|
1311 TRAPD( err,iChangeFinder->FindNewItemsL( *iNewUids ) ); |
|
1312 if( err != KErrNone ) |
|
1313 { |
|
1314 _DBG_FILE("CNSmlContactsDataStore::DoAddedItems(): LEAVE end"); |
|
1315 } |
|
1316 } |
|
1317 } |
|
1318 _DBG_FILE("CNSmlContactsDataStore::DoAddedItems(): end"); |
|
1319 |
|
1320 return *iNewUids; |
|
1321 } |
|
1322 |
|
1323 // ---------------------------------------------------------------------------- |
|
1324 // void CNSmlContactsDataStore::DoDeletedItems() |
|
1325 // ---------------------------------------------------------------------------- |
|
1326 const MSmlDataItemUidSet& CNSmlContactsDataStore::DoDeletedItems() const |
|
1327 { |
|
1328 _DBG_FILE("CNSmlContactsDataStore::DoDeletedItems(): begin"); |
|
1329 if ( iState == ENSmlOpenAndWaiting ) |
|
1330 { |
|
1331 iDeletedUids->Reset(); |
|
1332 |
|
1333 if( iChangeFinder ) |
|
1334 { |
|
1335 TRAPD(err,iChangeFinder->FindDeletedItemsL( *iDeletedUids ) ); |
|
1336 if( err != KErrNone ) |
|
1337 { |
|
1338 _DBG_FILE("CNSmlContactsDataStore::DoDeletedItems(): LEAVE end"); |
|
1339 } |
|
1340 } |
|
1341 } |
|
1342 _DBG_FILE("CNSmlContactsDataStore::DoDeletedItems(): end"); |
|
1343 |
|
1344 return *iDeletedUids; |
|
1345 } |
|
1346 |
|
1347 // ---------------------------------------------------------------------------- |
|
1348 // void CNSmlContactsDataStore::DoSoftDeletedItems() |
|
1349 // ---------------------------------------------------------------------------- |
|
1350 const MSmlDataItemUidSet& CNSmlContactsDataStore::DoSoftDeletedItems() const |
|
1351 { |
|
1352 _DBG_FILE("CNSmlContactsDataStore::DoSoftDeletedItems(): begin"); |
|
1353 if ( iState == ENSmlOpenAndWaiting ) |
|
1354 { |
|
1355 iSoftDeletedUids->Reset(); |
|
1356 |
|
1357 if( iChangeFinder ) |
|
1358 { |
|
1359 TRAPD( err, iChangeFinder->FindSoftDeletedItemsL( *iSoftDeletedUids ) ); |
|
1360 if( err != KErrNone ) |
|
1361 { |
|
1362 _DBG_FILE("CNSmlContactsDataStore::DoSoftDeletedItems(): LEAVE end"); |
|
1363 } |
|
1364 } |
|
1365 } |
|
1366 _DBG_FILE("CNSmlContactsDataStore::DoSoftDeletedItems: END"); |
|
1367 |
|
1368 return *iSoftDeletedUids; |
|
1369 } |
|
1370 |
|
1371 // ---------------------------------------------------------------------------- |
|
1372 // void CNSmlContactsDataStore::DoModifiedItems() |
|
1373 // ---------------------------------------------------------------------------- |
|
1374 const MSmlDataItemUidSet& CNSmlContactsDataStore::DoModifiedItems() const |
|
1375 { |
|
1376 _DBG_FILE("CNSmlContactsDataStore::DoModifiedItems(): begin"); |
|
1377 if ( iState == ENSmlOpenAndWaiting ) |
|
1378 { |
|
1379 iReplacedUids->Reset(); |
|
1380 |
|
1381 if( iChangeFinder ) |
|
1382 { |
|
1383 TRAPD( err, iChangeFinder->FindChangedItemsL( *iReplacedUids ) ); |
|
1384 if( err != KErrNone ) |
|
1385 { |
|
1386 _DBG_FILE("CNSmlContactsDataStore::DoModifiedItems(): LEAVE end"); |
|
1387 } |
|
1388 } |
|
1389 } |
|
1390 _DBG_FILE("CNSmlContactsDataStore::DoModifiedItems: END"); |
|
1391 |
|
1392 return *iReplacedUids; |
|
1393 } |
|
1394 |
|
1395 // ---------------------------------------------------------------------------- |
|
1396 // void CNSmlContactsDataStore::DoMovedItems() |
|
1397 // ---------------------------------------------------------------------------- |
|
1398 const MSmlDataItemUidSet& CNSmlContactsDataStore::DoMovedItems() const |
|
1399 { |
|
1400 _DBG_FILE("CNSmlContactsDataStore::DoMovedItems(): begin"); |
|
1401 |
|
1402 if ( iState == ENSmlOpenAndWaiting ) |
|
1403 { |
|
1404 iMovedUids->Reset(); |
|
1405 |
|
1406 if( iChangeFinder ) |
|
1407 { |
|
1408 TRAPD( err, iChangeFinder->FindMovedItemsL( *iMovedUids ) ); |
|
1409 if( err != KErrNone ) |
|
1410 { |
|
1411 _DBG_FILE("CNSmlContactsDataStore::DoMovedItems(): LEAVE end"); |
|
1412 } |
|
1413 } |
|
1414 } |
|
1415 _DBG_FILE("CNSmlContactsDataStore::DoMovedItems: END"); |
|
1416 |
|
1417 return *iMovedUids; |
|
1418 } |
|
1419 |
|
1420 // ---------------------------------------------------------------------------- |
|
1421 // void CNSmlContactsDataStore::DoResetChangeInfoL() |
|
1422 // ---------------------------------------------------------------------------- |
|
1423 void CNSmlContactsDataStore::DoResetChangeInfoL( TRequestStatus& aStatus ) |
|
1424 { |
|
1425 _DBG_FILE("CNSmlContactsDataStore::DoResetChangeInfoL(): begin"); |
|
1426 iCallerStatus = &aStatus; |
|
1427 *iCallerStatus = KRequestPending; |
|
1428 |
|
1429 if( iChangeFinder ) |
|
1430 { |
|
1431 iChangeFinder->ResetL(); |
|
1432 } |
|
1433 |
|
1434 iSnapshotRegistered = EFalse; |
|
1435 |
|
1436 if ( iContactsModsFetcher ) |
|
1437 { |
|
1438 iContactsModsFetcher->FetchModificationsL( aStatus ); |
|
1439 #ifdef __NSML_MODULETEST__ |
|
1440 CActiveScheduler::Start(); |
|
1441 #endif |
|
1442 } |
|
1443 else |
|
1444 { |
|
1445 User::RequestComplete( iCallerStatus, KErrNone ); |
|
1446 } |
|
1447 |
|
1448 _DBG_FILE("CNSmlContactsDataStore::DoResetChangeInfoL(): end"); |
|
1449 } |
|
1450 |
|
1451 // ---------------------------------------------------------------------------- |
|
1452 // void CNSmlContactsDataStore::DoCommitChangeInfoL() |
|
1453 // ---------------------------------------------------------------------------- |
|
1454 void CNSmlContactsDataStore::DoCommitChangeInfoL( TRequestStatus& aStatus, |
|
1455 const MSmlDataItemUidSet& aItems ) |
|
1456 { |
|
1457 _DBG_FILE("CNSmlContactsDataStore::DoCommitChangeInfoL(aItems): begin"); |
|
1458 iCallerStatus = &aStatus; |
|
1459 *iCallerStatus = KRequestPending; |
|
1460 |
|
1461 if( iChangeFinder ) |
|
1462 { |
|
1463 iChangeFinder->CommitChangesL( aItems ); |
|
1464 User::RequestComplete( iCallerStatus, KErrNone ); |
|
1465 return; |
|
1466 } |
|
1467 |
|
1468 User::RequestComplete( iCallerStatus, KErrNotReady ); |
|
1469 |
|
1470 _DBG_FILE("CNSmlContactsDataStore::DoCommitChangeInfoL(aItems): end"); |
|
1471 } |
|
1472 |
|
1473 // ---------------------------------------------------------------------------- |
|
1474 // void CNSmlContactsDataStore::DoCommitChangeInfoL() |
|
1475 // ---------------------------------------------------------------------------- |
|
1476 void CNSmlContactsDataStore::DoCommitChangeInfoL( TRequestStatus& aStatus ) |
|
1477 { |
|
1478 _DBG_FILE("CNSmlContactsDataStore::DoCommitChangeInfoL(): begin"); |
|
1479 iCallerStatus = &aStatus; |
|
1480 *iCallerStatus = KRequestPending; |
|
1481 |
|
1482 if( iChangeFinder ) |
|
1483 { |
|
1484 iChangeFinder->CommitChangesL(); |
|
1485 User::RequestComplete( iCallerStatus, KErrNone ); |
|
1486 return; |
|
1487 } |
|
1488 |
|
1489 User::RequestComplete( iCallerStatus, KErrNotReady ); |
|
1490 |
|
1491 _DBG_FILE("CNSmlContactsDataStore::DoCommitChangeInfoL(): end"); |
|
1492 } |
|
1493 |
|
1494 // ---------------------------------------------------------------------------- |
|
1495 // CDesCArray* CNSmlContactsDataStore::DoListStoresLC() |
|
1496 // ---------------------------------------------------------------------------- |
|
1497 CDesCArray* CNSmlContactsDataStore::DoListStoresLC() |
|
1498 { |
|
1499 _DBG_FILE("CNSmlContactsDataStore::DoListStoresLC(): begin"); |
|
1500 |
|
1501 MVPbkContactStoreList& storeList = iContactManager->ContactStoresL(); |
|
1502 CDesCArrayFlat* stores = new (ELeave) CDesCArrayFlat(storeList.Count()); |
|
1503 CleanupStack::PushL( stores ); |
|
1504 |
|
1505 TBuf<KVPbhkPrefixLength> phoneDataBasePrefix(KVPbhkSymbianDBPrefix); |
|
1506 |
|
1507 for(TInt i=0 ; i< storeList.Count(); i++) |
|
1508 { |
|
1509 TBuf<KNSmlDefaultStoreNameMaxSize> currentStore(storeList.At(i).StoreProperties().Uri().UriDes()); |
|
1510 |
|
1511 if(currentStore.Find(phoneDataBasePrefix) == 0)//Check if Symbian Database |
|
1512 { |
|
1513 //For backward compatability with local and remote servers |
|
1514 //The Symbian Db name remains unchanged |
|
1515 //The engine methods that create syncml packet, use this information in Database fields |
|
1516 stores->AppendL(*iPacketStoreName); |
|
1517 } |
|
1518 else//End Symbian Database check |
|
1519 { |
|
1520 stores->AppendL(storeList.At(i).StoreProperties().Uri().UriDes()); |
|
1521 } |
|
1522 } |
|
1523 |
|
1524 _DBG_FILE("CNSmlContactsDataStore::DoListStoresLC(): end"); |
|
1525 |
|
1526 return stores; |
|
1527 } |
|
1528 |
|
1529 // ------------------------------------------------------------------------------------------------ |
|
1530 // TInt CNSmlContactsDataStore::LdoFetchItemL( TSmlDbItemUid& aUid, CBufBase& aItem ) |
|
1531 // ------------------------------------------------------------------------------------------------ |
|
1532 void CNSmlContactsDataStore::LdoFetchItemL( TSmlDbItemUid& aUid, CBufBase& aItem ) |
|
1533 { |
|
1534 _DBG_FILE("CNSmlContactsDataStore::LdoFetchItemL(): begin"); |
|
1535 |
|
1536 iWriteStream.Open(aItem); |
|
1537 |
|
1538 MVPbkContactLink* contactLink = iIdConverter->IdentifierToLinkLC(aUid); |
|
1539 iVCardEngine->ExportVCardForSyncL(iWriteStream,*contactLink,*this); |
|
1540 CleanupStack::PopAndDestroy(); |
|
1541 |
|
1542 iLastOperation = ENSMLFetchOp; |
|
1543 |
|
1544 _DBG_FILE("CNSmlContactsDataStore::LdoFetchItemL(): end"); |
|
1545 |
|
1546 } |
|
1547 |
|
1548 // ------------------------------------------------------------------------------------------------ |
|
1549 // TInt CNSmlContactsDataStore::LdoAddItemL( TSmlDbItemUid& aUid, |
|
1550 // const TDesC8& aItem, |
|
1551 // TInt aSize, |
|
1552 // TTime& aLastModified, |
|
1553 // TBool& aConfidential ) |
|
1554 // ------------------------------------------------------------------------------------------------ |
|
1555 void CNSmlContactsDataStore::LdoAddItemL( const TDesC8& aItem, |
|
1556 TInt aSize) |
|
1557 { |
|
1558 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemL(): begin"); |
|
1559 |
|
1560 if( !iOpened ) |
|
1561 { |
|
1562 User::Leave( KErrNotReady ); |
|
1563 } |
|
1564 |
|
1565 // Is there enough space on drive |
|
1566 if( DriveBelowCriticalLevelL( aSize ) ) |
|
1567 { |
|
1568 User::Leave( KErrDiskFull ); |
|
1569 } |
|
1570 |
|
1571 iBuf = aItem.AllocLC(); |
|
1572 StripPropertyL( iBuf, KVersitTokenUID() ); |
|
1573 |
|
1574 iReadStream.Open( *iBuf ); |
|
1575 // import a vcard without checking for duplicates |
|
1576 iVCardEngine->ImportVCardForSyncL(*iStore,iReadStream,*this); |
|
1577 iLastOperation = ENSmlAddOp; |
|
1578 CleanupStack::Pop(iBuf); |
|
1579 |
|
1580 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemL(): end"); |
|
1581 |
|
1582 } |
|
1583 // ------------------------------------------------------------------------------------------------ |
|
1584 // TInt CNSmlContactsDataStore::LdoAddItemsL( CBufBase*& aItems, |
|
1585 // TInt aSize) |
|
1586 // ------------------------------------------------------------------------------------------------ |
|
1587 void CNSmlContactsDataStore::LdoAddItemsL( CBufBase*& aItems, |
|
1588 TInt aSize) |
|
1589 { |
|
1590 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemL(): begin"); |
|
1591 |
|
1592 if( !iOpened ) |
|
1593 { |
|
1594 User::Leave( KErrNotReady ); |
|
1595 } |
|
1596 |
|
1597 // Is there enough space on drive |
|
1598 if( DriveBelowCriticalLevelL( aSize ) ) |
|
1599 { |
|
1600 User::Leave( KErrDiskFull ); |
|
1601 } |
|
1602 |
|
1603 iReadStream.Open( aItems->Ptr(0) ); |
|
1604 // import vcards without checking for duplicates |
|
1605 iVCardEngine->ImportVCardForSyncL(*iStore,iReadStream,*this); |
|
1606 iLastOperation = ENSmlAddOp; |
|
1607 _DBG_FILE("CNSmlContactsDataStore::LdoAddItemL(): end"); |
|
1608 |
|
1609 } |
|
1610 |
|
1611 // ------------------------------------------------------------------------------------------------ |
|
1612 // TInt CNSmlContactsDataStore::LdoUpdateItemL(TSmlDbItemUid aUid, |
|
1613 // const TDesC8& aItem, |
|
1614 // TInt aSize, |
|
1615 // TTime& aLastModified ) |
|
1616 // ------------------------------------------------------------------------------------------------ |
|
1617 void CNSmlContactsDataStore::LdoUpdateItemL() |
|
1618 { |
|
1619 _DBG_FILE("CNSmlContactsDataStore::LdoUpdateItemL(): begin"); |
|
1620 |
|
1621 iBuf = iContactsBufferItemList[iIndex]->iItemData->Ptr(0).AllocLC(); |
|
1622 // Remove UID's from data |
|
1623 StripPropertyL( iBuf, KVersitTokenUID() ); |
|
1624 |
|
1625 iReadStream.Open( *iBuf ); |
|
1626 MVPbkContactLink* contactLink = iIdConverter->IdentifierToLinkLC(iUid); |
|
1627 iVCardEngine->ImportVCardMergeL(*contactLink,*iStore,iReadStream,*this); |
|
1628 |
|
1629 CleanupStack::Pop(); |
|
1630 iLastOperation = ENSMLUpdateImportOp; |
|
1631 CleanupStack::Pop(iBuf); |
|
1632 |
|
1633 _DBG_FILE("CNSmlContactsDataStore::LdoUpdateItemL(): end"); |
|
1634 |
|
1635 } |
|
1636 |
|
1637 |
|
1638 // ------------------------------------------------------------------------------------------------ |
|
1639 // CNSmlContactsDataStore::DriveBelowCriticalLevelL() |
|
1640 // ------------------------------------------------------------------------------------------------ |
|
1641 TBool CNSmlContactsDataStore::DriveBelowCriticalLevelL( TInt aSize ) |
|
1642 { |
|
1643 return SysUtil::DiskSpaceBelowCriticalLevelL( &iRfs, aSize, iDrive ); |
|
1644 } |
|
1645 |
|
1646 // ---------------------------------------------------------------------------- |
|
1647 // CBufBase* CNSmlContactsDataStore::AddBufferListL() |
|
1648 // ---------------------------------------------------------------------------- |
|
1649 CBufBase* CNSmlContactsDataStore::AddBufferListL( TSmlDbItemUid& aUid, TInt aSize, TInt aStatus ) |
|
1650 { |
|
1651 _DBG_FILE("CNSmlContactsDataStore::AddBufferListL(): begin"); |
|
1652 |
|
1653 CNSmlContactsBufferItem* newBufferItem = new (ELeave) CNSmlContactsBufferItem; |
|
1654 CleanupStack::PushL( newBufferItem ); |
|
1655 |
|
1656 if( iModType == ENSmlCntItemAdd ) |
|
1657 { |
|
1658 newBufferItem->iPUid = &aUid; |
|
1659 newBufferItem->iItemData = CBufFlat::NewL( KNSmlItemDataExpandSize ); |
|
1660 newBufferItem->iStatus = KErrGeneral; // Default for add |
|
1661 } |
|
1662 else |
|
1663 { |
|
1664 newBufferItem->iPUid = &aUid; |
|
1665 newBufferItem->iUid = aUid; |
|
1666 newBufferItem->iItemData = CBufFlat::NewL( KNSmlItemDataExpandSize ); |
|
1667 newBufferItem->iStatus = KNSmlNoError; // Default if not handled |
|
1668 } |
|
1669 |
|
1670 newBufferItem->iModType = iModType; |
|
1671 newBufferItem->iMimeType = iMimeTypeItem.AllocL(); |
|
1672 newBufferItem->iMimeVersion = iMimeVersionItem.AllocL(); |
|
1673 newBufferItem->iSize = aSize; |
|
1674 |
|
1675 if( aStatus != KErrNone ) |
|
1676 { |
|
1677 newBufferItem->iStatus = aStatus; |
|
1678 } |
|
1679 |
|
1680 iContactsBufferItemList.AppendL( newBufferItem ); |
|
1681 |
|
1682 iMimeTypeItem.Set( KNullDesC8 ); |
|
1683 iMimeVersionItem.Set( KNullDesC8 ); |
|
1684 |
|
1685 |
|
1686 CleanupStack::Pop(); |
|
1687 |
|
1688 if( iModType == ENSmlCntItemAdd && |
|
1689 aStatus == KErrNotSupported ) |
|
1690 { |
|
1691 iStateItem = KErrNotSupported; |
|
1692 } |
|
1693 |
|
1694 _DBG_FILE("CNSmlContactsDataStore::AddBufferListL(): end"); |
|
1695 |
|
1696 return newBufferItem->iItemData; |
|
1697 |
|
1698 } |
|
1699 |
|
1700 // ------------------------------------------------------------------------------------------------ |
|
1701 // void CNSmlContactsDataStore::StripPropertyL( HBufC8*& aItem, const TDesC8& aProperty ) |
|
1702 // ------------------------------------------------------------------------------------------------ |
|
1703 void CNSmlContactsDataStore::StripPropertyL( HBufC8*& aItem, const TDesC8& aProperty ) const |
|
1704 { |
|
1705 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): begin"); |
|
1706 |
|
1707 if( !aItem ) |
|
1708 { |
|
1709 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): NULL pointer"); |
|
1710 return; |
|
1711 } |
|
1712 |
|
1713 TPtr8 hItemPtr( aItem->Des() ); |
|
1714 HBufC8* propBuf = HBufC8::NewLC( aProperty.Length() + 2 ); |
|
1715 TPtr8 propPtr( propBuf->Des() ); |
|
1716 |
|
1717 propPtr.Append( KVersitTokenCRLF() ); |
|
1718 propPtr.Append( aProperty ); |
|
1719 TInt propPos = hItemPtr.Find( propPtr ); |
|
1720 if( propPos != KErrNotFound ) |
|
1721 { |
|
1722 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): property found in item data -> removing it"); |
|
1723 _DBG_FILE( aProperty.Ptr() ); |
|
1724 TPtrC8 propPosPtr( hItemPtr.Mid( propPos + KVersitTokenCRLF().Length() ) ); |
|
1725 TInt propEndPos = propPosPtr.Find( KVersitTokenCRLF() ); |
|
1726 hItemPtr.Delete( propPos, propEndPos + KVersitTokenCRLF().Length() ); |
|
1727 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): property removed"); |
|
1728 } |
|
1729 CleanupStack::PopAndDestroy(); // propBuf |
|
1730 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): end"); |
|
1731 } |
|
1732 |
|
1733 // ------------------------------------------------------------------------------------------------ |
|
1734 // void CNSmlContactsDataStore::StripPropertyL( CBufBase*& aItem, const TDesC8& aProperty ) |
|
1735 // ------------------------------------------------------------------------------------------------ |
|
1736 void CNSmlContactsDataStore::StripPropertyL( CBufBase*& aItem, const TDesC8& aProperty ) const |
|
1737 { |
|
1738 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): begin"); |
|
1739 |
|
1740 if( !aItem ) |
|
1741 { |
|
1742 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): NULL pointer"); |
|
1743 return; |
|
1744 } |
|
1745 |
|
1746 HBufC8* propBuf = HBufC8::NewLC( aProperty.Length() + 2 ); |
|
1747 TPtr8 propPtr( propBuf->Des() ); |
|
1748 propPtr.Append( KVersitTokenCRLF() ); |
|
1749 propPtr.Append( aProperty ); |
|
1750 TInt propPos = aItem->Ptr(0).Find( propPtr ); |
|
1751 |
|
1752 while( propPos != KErrNotFound ) |
|
1753 { |
|
1754 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): property found in item data -> removing it"); |
|
1755 _DBG_FILE( aProperty.Ptr() ); |
|
1756 TInt propEndPos = aItem->Ptr( propPos + KVersitTokenCRLF().Length()).Find(KVersitTokenCRLF() ); |
|
1757 if( propEndPos != KErrNotFound ) |
|
1758 { |
|
1759 aItem->Delete( propPos + KVersitTokenCRLF().Length(), propEndPos ); |
|
1760 } |
|
1761 |
|
1762 propPos = aItem->Ptr(0).Find( propPtr ); |
|
1763 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): property removed"); |
|
1764 } |
|
1765 CleanupStack::PopAndDestroy(); // propBuf |
|
1766 _DBG_FILE("CNSmlContactsDataStore::StripPropertyL(): end"); |
|
1767 } |
|
1768 |
|
1769 // ---------------------------------------------------------------------------- |
|
1770 // CNSmlContactsDataStore::IsConfidentialL |
|
1771 // ---------------------------------------------------------------------------- |
|
1772 // |
|
1773 TBool CNSmlContactsDataStore::IsConfidentialL( MVPbkStoreContact& aItem ) |
|
1774 { |
|
1775 _DBG_FILE("CNSmlContactsDataStore::IsConfidentialL(): begin"); |
|
1776 TBool ret( EFalse ); |
|
1777 |
|
1778 //find X-CLASS field type |
|
1779 const MVPbkFieldType* syncclass = |
|
1780 iContactManager->FieldTypes().Find(R_VPBK_FIELD_TYPE_SYNCCLASS ); |
|
1781 CVPbkBaseContactFieldTypeIterator* itr = |
|
1782 CVPbkBaseContactFieldTypeIterator::NewLC( *syncclass, |
|
1783 aItem.Fields() ); |
|
1784 while ( itr->HasNext() ) |
|
1785 { |
|
1786 const MVPbkBaseContactField* field = itr->Next(); |
|
1787 const MVPbkContactFieldTextData& data = MVPbkContactFieldTextData::Cast(field->FieldData()); |
|
1788 TPtrC ptr = data.Text(); |
|
1789 //compare the sync type |
|
1790 if ( ptr.Compare( KNSmlContactSyncNoSync ) == 0 ) |
|
1791 { |
|
1792 _DBG_FILE("CNSmlContactsModsFetcher::IsConfidentialL(): \ |
|
1793 find confidential"); |
|
1794 ret = ETrue; |
|
1795 } |
|
1796 |
|
1797 } |
|
1798 CleanupStack::PopAndDestroy( itr ); |
|
1799 |
|
1800 _DBG_FILE("CNSmlContactsDataStore::IsConfidentialL(): end"); |
|
1801 return ret; |
|
1802 } |
|
1803 |
|
1804 // ---------------------------------------------------------------------------- |
|
1805 // CNSmlContactsDataStore::ResetBuffer |
|
1806 // ---------------------------------------------------------------------------- |
|
1807 // |
|
1808 void CNSmlContactsDataStore:: ResetBuffer() |
|
1809 { |
|
1810 if( iItemDataAddBatch ) |
|
1811 { |
|
1812 iItemDataAddBatch->Reset(); |
|
1813 } |
|
1814 iContactsBufferItemList.ResetAndDestroy(); |
|
1815 } |
|
1816 // ----------------------------------------------------------------------------- |
|
1817 // From MVPbkContactStoreListObserver |
|
1818 // Called when a contact store is ready to use. |
|
1819 // ----------------------------------------------------------------------------- |
|
1820 |
|
1821 void CNSmlContactsDataStore::StoreReady( MVPbkContactStore& /*aContactStore*/ ) |
|
1822 { |
|
1823 _DBG_FILE("CNSmlContactsDataStore::StoreReady(): begin"); |
|
1824 //The contact data base opened successfully |
|
1825 iOpened = ETrue; |
|
1826 //id to uniquely identify the opened store |
|
1827 iOpenedStoreId = DefaultHash::Des16( |
|
1828 iStore->StoreProperties().Uri().UriDes()); |
|
1829 |
|
1830 TRAPD(error,iContactsModsFetcher->FetchModificationsL( *iCallerStatus )); |
|
1831 if(error != KErrNone) |
|
1832 { |
|
1833 User::RequestComplete( iCallerStatus, error ); |
|
1834 } |
|
1835 _DBG_FILE("CNSmlContactsDataStore::StoreReady(): end"); |
|
1836 } |
|
1837 |
|
1838 |
|
1839 // --------------------------------------------------------------------------- |
|
1840 // From MVPbkContactStoreListObserver |
|
1841 // Called when a contact store becomes unavailable. |
|
1842 // --------------------------------------------------------------------------- |
|
1843 // |
|
1844 void CNSmlContactsDataStore::StoreUnavailable( |
|
1845 MVPbkContactStore& /*aContactStore*/, |
|
1846 TInt aReason ) |
|
1847 { |
|
1848 _DBG_FILE("CNSmlContactsDataStore::StoreUnavailable(): begin"); |
|
1849 |
|
1850 //Unable open the default contact data base |
|
1851 iOpened = EFalse; |
|
1852 delete iStoreName; |
|
1853 iStoreName = NULL; |
|
1854 iOpenedStoreId = 0; |
|
1855 User::RequestComplete( iCallerStatus, aReason ); |
|
1856 _DBG_FILE("CNSmlContactsDataStore::StoreUnavailable(): end"); |
|
1857 return; |
|
1858 |
|
1859 } |
|
1860 |
|
1861 // --------------------------------------------------------------------------- |
|
1862 // From MVPbkContactStoreListObserver |
|
1863 // --------------------------------------------------------------------------- |
|
1864 // |
|
1865 void CNSmlContactsDataStore::HandleStoreEventL( |
|
1866 MVPbkContactStore& /*aContactStore*/, |
|
1867 TVPbkContactStoreEvent /*aStoreEvent*/ ) |
|
1868 { |
|
1869 //Indication not needed. |
|
1870 } |
|
1871 |
|
1872 // --------------------------------------------------------------------------- |
|
1873 // CNSmlContactsDataStore::VPbkSingleContactOperationComplete |
|
1874 // --------------------------------------------------------------------------- |
|
1875 // |
|
1876 |
|
1877 void CNSmlContactsDataStore::VPbkSingleContactOperationComplete( |
|
1878 MVPbkContactOperationBase& aOperation, |
|
1879 MVPbkStoreContact* aContact ) |
|
1880 { |
|
1881 MVPbkContactOperationBase* operation = &aOperation; |
|
1882 if ( operation ) |
|
1883 { |
|
1884 delete operation; |
|
1885 operation = NULL; |
|
1886 } |
|
1887 TRAPD(error ,SingleContactOperationCompleteL(aContact)); |
|
1888 delete aContact; |
|
1889 if(error!= KErrNone) |
|
1890 { |
|
1891 User::RequestComplete( iCallerStatus, error ); |
|
1892 } |
|
1893 } |
|
1894 |
|
1895 // --------------------------------------------------------------------------- |
|
1896 // CNSmlContactsDataStore::VPbkSingleContactOperationFailed |
|
1897 // --------------------------------------------------------------------------- |
|
1898 // |
|
1899 void CNSmlContactsDataStore::VPbkSingleContactOperationFailed( |
|
1900 MVPbkContactOperationBase& aOperation, |
|
1901 TInt aError ) |
|
1902 { |
|
1903 MVPbkContactOperationBase* operation = &aOperation; |
|
1904 if ( operation ) |
|
1905 { |
|
1906 delete operation; |
|
1907 operation = NULL; |
|
1908 } |
|
1909 if(iLastOperation == ENSMLFetchOp) |
|
1910 { |
|
1911 iWriteStream.Close(); |
|
1912 User::RequestComplete( iCallerStatus, aError ); |
|
1913 } |
|
1914 else if(iLastOperation == ENSmlRetrieveOp) |
|
1915 { |
|
1916 User::RequestComplete( iCallerStatus, aError ); |
|
1917 } |
|
1918 } |
|
1919 // --------------------------------------------------------------------------- |
|
1920 // CNSmlContactsDataStore::VPbkSingleContactOperationFailed |
|
1921 // --------------------------------------------------------------------------- |
|
1922 // |
|
1923 void CNSmlContactsDataStore::SingleContactOperationCompleteL( |
|
1924 MVPbkStoreContact* aContact) |
|
1925 { |
|
1926 if(iLastOperation == ENSMLFetchOp) |
|
1927 { |
|
1928 iWriteStream.Close(); |
|
1929 |
|
1930 iItemData->Compress(); |
|
1931 //strip the fields not supported by server |
|
1932 iDataMod->StripTxL( *iItemData ); |
|
1933 *iSize = iItemData->Size(); |
|
1934 iState = ENSmlItemOpen; |
|
1935 if ( iServerMaxObjectSize == 0 || *iSize <= iServerMaxObjectSize ) |
|
1936 { |
|
1937 User::RequestComplete( iCallerStatus, KErrNone ); |
|
1938 } |
|
1939 else |
|
1940 { |
|
1941 User::RequestComplete( iCallerStatus, KErrTooBig ); |
|
1942 } |
|
1943 } |
|
1944 else if (iLastOperation == ENSMLUpdateExportOp) |
|
1945 { |
|
1946 iDataMod->MergeRxL( *iContactsBufferItemList[iIndex]->iItemData, *iMergeItem ); |
|
1947 iWriteStream.Close(); |
|
1948 delete iMergeItem; |
|
1949 iMergeItem = NULL; |
|
1950 LdoUpdateItemL(); |
|
1951 } |
|
1952 else if (iLastOperation == ENSMLUpdateImportOp) |
|
1953 { |
|
1954 if(!IsConfidentialL(*aContact)) |
|
1955 { |
|
1956 TInt32 id = iIdConverter->LinkToIdentifier(*aContact->CreateLinkLC()); |
|
1957 |
|
1958 TNSmlSnapshotItem item(id); |
|
1959 |
|
1960 MVPbkStoreContact2* tempContact = |
|
1961 reinterpret_cast<MVPbkStoreContact2*> (aContact->StoreContactExtension (KMVPbkStoreContactExtension2Uid)); |
|
1962 |
|
1963 MVPbkStoreContactProperties *contactProterties |
|
1964 = tempContact ->PropertiesL();; |
|
1965 CleanupDeletePushL(contactProterties); |
|
1966 item.SetLastChangedDate(contactProterties->LastModifiedL()); |
|
1967 CleanupStack::PopAndDestroy(); |
|
1968 |
|
1969 item.SetSoftDelete( EFalse ); |
|
1970 |
|
1971 TRAP_IGNORE(iChangeFinder->ItemUpdatedL( item )); |
|
1972 |
|
1973 CleanupStack::PopAndDestroy(); |
|
1974 if(iBatchMode) |
|
1975 { |
|
1976 iResultArray->Append(KErrNone); |
|
1977 } |
|
1978 |
|
1979 |
|
1980 delete iBuf; |
|
1981 iBuf = NULL; |
|
1982 iReadStream.Close(); |
|
1983 |
|
1984 |
|
1985 iIndex++; |
|
1986 if(iIndex == iContactsBufferItemList.Count() ) |
|
1987 { |
|
1988 ResetBuffer(); |
|
1989 User::RequestComplete( iCallerStatus, iRetCommand ); |
|
1990 } |
|
1991 else |
|
1992 { |
|
1993 ExecuteBufferL(); |
|
1994 } |
|
1995 } |
|
1996 |
|
1997 } |
|
1998 else if(iLastOperation == ENSmlRetrieveOp) |
|
1999 { |
|
2000 iRetrieveCount--; |
|
2001 if(!IsConfidentialL(*aContact)) |
|
2002 { |
|
2003 TInt32 id = iIdConverter->LinkToIdentifier(*aContact->CreateLinkLC()); |
|
2004 *iContactsBufferItemList[iIndex]->iPUid = id; |
|
2005 |
|
2006 TNSmlSnapshotItem item(id); |
|
2007 |
|
2008 MVPbkStoreContact2* tempContact = |
|
2009 reinterpret_cast<MVPbkStoreContact2*> (aContact->StoreContactExtension (KMVPbkStoreContactExtension2Uid)); |
|
2010 |
|
2011 MVPbkStoreContactProperties *contactProterties |
|
2012 = tempContact ->PropertiesL();; |
|
2013 CleanupDeletePushL(contactProterties); |
|
2014 item.SetLastChangedDate(contactProterties->LastModifiedL()); |
|
2015 CleanupStack::PopAndDestroy(); |
|
2016 |
|
2017 item.SetSoftDelete( EFalse ); |
|
2018 // Add the snapshot item to the Change Finder. |
|
2019 TRAP_IGNORE(iChangeFinder->ItemAddedL( item )); |
|
2020 |
|
2021 CleanupStack::PopAndDestroy(); |
|
2022 } |
|
2023 if(iBatchMode) |
|
2024 { |
|
2025 iResultArray->AppendL(iRetCommand); |
|
2026 } |
|
2027 |
|
2028 iIndex++; |
|
2029 if(iIndex == iContactsBufferItemList.Count() ) |
|
2030 { |
|
2031 ResetBuffer(); |
|
2032 User::RequestComplete( iCallerStatus, iRetCommand ); |
|
2033 } |
|
2034 else if(!iRetrieveCount) |
|
2035 { |
|
2036 ExecuteBufferL(); |
|
2037 } |
|
2038 |
|
2039 } |
|
2040 } |
|
2041 // --------------------------------------------------------------------------- |
|
2042 // CNSmlContactsDataStore::ContactsSaved. |
|
2043 // --------------------------------------------------------------------------- |
|
2044 // |
|
2045 void CNSmlContactsDataStore::ContactsSaved( |
|
2046 MVPbkContactOperationBase& aOperation, |
|
2047 MVPbkContactLinkArray* aResults ) |
|
2048 { |
|
2049 MVPbkContactOperationBase* operation = &aOperation; |
|
2050 if ( operation ) |
|
2051 { |
|
2052 delete operation; |
|
2053 operation = NULL; |
|
2054 } |
|
2055 |
|
2056 if(iLastOperation == ENSmlAddOp) |
|
2057 { |
|
2058 //Count of contacts to be added from server to client |
|
2059 TInt cntAddCount( 0 ); |
|
2060 TInt i(iIndex); |
|
2061 while( i<iContactsBufferItemList.Count() ) |
|
2062 { |
|
2063 if ( iContactsBufferItemList[i]->iModType == ENSmlCntItemAdd && |
|
2064 iContactsBufferItemList[i]->iStatus == KNSmlNoError ) |
|
2065 { |
|
2066 cntAddCount++; |
|
2067 } |
|
2068 i++; |
|
2069 } |
|
2070 |
|
2071 //Count of contacts successfully added to client |
|
2072 iRetrieveCount = aResults->Count(); |
|
2073 |
|
2074 //Count of contacts which could not be added |
|
2075 TInt cntAddFailedCount(0); |
|
2076 cntAddFailedCount = cntAddCount-iRetrieveCount; |
|
2077 while(cntAddFailedCount > 0) |
|
2078 { |
|
2079 iContactsBufferItemList[iIndex++]->iStatus = KErrGeneral; |
|
2080 iResultArray->Append(KErrGeneral); |
|
2081 cntAddFailedCount--; |
|
2082 } |
|
2083 |
|
2084 if ( aResults->Count() > 0 ) |
|
2085 { |
|
2086 for(TInt i=0;i<aResults->Count();i++) |
|
2087 { |
|
2088 //retrieve the contact |
|
2089 TRAPD(error,iContactManager->RetrieveContactL( aResults->At(i), *this )); |
|
2090 if(error != KErrNone) |
|
2091 { |
|
2092 User::RequestComplete( iCallerStatus, error ); |
|
2093 } |
|
2094 iLastOperation = ENSmlRetrieveOp; |
|
2095 } |
|
2096 } |
|
2097 delete iBuf; |
|
2098 delete aResults; |
|
2099 iBuf = NULL; |
|
2100 iReadStream.Close(); |
|
2101 } |
|
2102 |
|
2103 } |
|
2104 |
|
2105 // --------------------------------------------------------------------------- |
|
2106 // CNSmlContactsDataStore::ContactsSavingFailed |
|
2107 // --------------------------------------------------------------------------- |
|
2108 // |
|
2109 void CNSmlContactsDataStore::ContactsSavingFailed( |
|
2110 MVPbkContactOperationBase& aOperation, TInt aError ) |
|
2111 { |
|
2112 MVPbkContactOperationBase* operation = &aOperation; |
|
2113 if ( operation ) |
|
2114 { |
|
2115 delete operation; |
|
2116 operation = NULL; |
|
2117 } |
|
2118 |
|
2119 if(iLastOperation == ENSmlAddOp) |
|
2120 { |
|
2121 if(iBatchMode) |
|
2122 { |
|
2123 while( iIndex < iContactsBufferItemList.Count() && |
|
2124 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemAdd ) |
|
2125 { |
|
2126 iContactsBufferItemList[iIndex++]->iStatus = KErrGeneral; |
|
2127 iResultArray->Append(KErrGeneral); |
|
2128 } |
|
2129 } |
|
2130 else |
|
2131 { |
|
2132 iIndex++; |
|
2133 } |
|
2134 |
|
2135 if(iIndex == iContactsBufferItemList.Count()) |
|
2136 { |
|
2137 User::RequestComplete( iCallerStatus, aError ); |
|
2138 ResetBuffer(); |
|
2139 delete iBuf; |
|
2140 iBuf = NULL; |
|
2141 iReadStream.Close(); |
|
2142 } |
|
2143 //Execute the remaining commands in batch |
|
2144 else |
|
2145 { |
|
2146 TRAPD(error,ExecuteBufferL()); |
|
2147 if(error != KErrNone) |
|
2148 { |
|
2149 User::RequestComplete( iCallerStatus, error ); |
|
2150 } |
|
2151 } |
|
2152 } |
|
2153 } |
|
2154 // --------------------------------------------------------------------------- |
|
2155 // CNSmlContactsDataStore::StepComplete |
|
2156 // --------------------------------------------------------------------------- |
|
2157 // |
|
2158 void CNSmlContactsDataStore::StepComplete( |
|
2159 MVPbkContactOperationBase& /*aOperation*/, |
|
2160 TInt aStepSize ) |
|
2161 { |
|
2162 if(iLastOperation == ENSmlDeleteOp) |
|
2163 { |
|
2164 if(iBatchMode) |
|
2165 { |
|
2166 for(TInt i = 0 ; i<aStepSize && iIndex < iContactsBufferItemList.Count() ;i++) |
|
2167 { |
|
2168 iResultArray->Append(KErrNone); |
|
2169 if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemDelete && |
|
2170 iContactsBufferItemList[iIndex]->iStatus == KNSmlNoError ) |
|
2171 { |
|
2172 iContactsBufferItemList[iIndex]->iStatus = KErrNone; |
|
2173 iUid = iContactsBufferItemList[iIndex]->iUid; |
|
2174 iChangeFinder->ItemDeleted( TNSmlSnapshotItem( iUid )); |
|
2175 } |
|
2176 else if( iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemSoftDelete && |
|
2177 iContactsBufferItemList[iIndex]->iStatus == KNSmlNoError ) |
|
2178 { |
|
2179 |
|
2180 iContactsBufferItemList[iIndex]->iStatus = KErrNone; |
|
2181 iUid = iContactsBufferItemList[iIndex]->iUid; |
|
2182 TRAP_IGNORE(iChangeFinder->ItemSoftDeletedL( TNSmlSnapshotItem( iUid ) )); |
|
2183 } |
|
2184 iIndex++; |
|
2185 } |
|
2186 } |
|
2187 else |
|
2188 { |
|
2189 iChangeFinder->ItemDeleted( TNSmlSnapshotItem( iUid ) ); |
|
2190 User::RequestComplete( iCallerStatus, KErrNone ); |
|
2191 } |
|
2192 } |
|
2193 } |
|
2194 // --------------------------------------------------------------------------- |
|
2195 // CNSmlContactsDataStore::StepFailed |
|
2196 // --------------------------------------------------------------------------- |
|
2197 // |
|
2198 TBool CNSmlContactsDataStore::StepFailed( |
|
2199 MVPbkContactOperationBase& /*aOperation*/, |
|
2200 TInt /*aStepSize*/, |
|
2201 TInt aError ) |
|
2202 { |
|
2203 if(iLastOperation == ENSmlDeleteOp) |
|
2204 { |
|
2205 if(iBatchMode) |
|
2206 { |
|
2207 if( iIndex < iContactsBufferItemList.Count() && |
|
2208 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemDelete ) |
|
2209 { |
|
2210 iContactsBufferItemList[iIndex++]->iStatus = KErrGeneral; |
|
2211 iResultArray->Append(KErrGeneral); |
|
2212 } |
|
2213 |
|
2214 } |
|
2215 else |
|
2216 { |
|
2217 User::RequestComplete( iCallerStatus, aError ); |
|
2218 } |
|
2219 } |
|
2220 return ETrue; |
|
2221 } |
|
2222 // --------------------------------------------------------------------------- |
|
2223 // CNSmlContactsDataStore::OperationComplete |
|
2224 // --------------------------------------------------------------------------- |
|
2225 // |
|
2226 void CNSmlContactsDataStore::OperationComplete |
|
2227 ( MVPbkContactOperationBase& aOperation ) |
|
2228 { |
|
2229 MVPbkContactOperationBase* operation = &aOperation; |
|
2230 if ( operation ) |
|
2231 { |
|
2232 delete operation; |
|
2233 operation = NULL; |
|
2234 } |
|
2235 |
|
2236 TRAPD(error ,OperationCompleteL()); |
|
2237 if(error != KErrNone) |
|
2238 { |
|
2239 User::RequestComplete( iCallerStatus, error ); |
|
2240 } |
|
2241 } |
|
2242 |
|
2243 // --------------------------------------------------------------------------- |
|
2244 // CNSmlContactsDataStore::OperationCompleteL |
|
2245 // --------------------------------------------------------------------------- |
|
2246 // |
|
2247 |
|
2248 void CNSmlContactsDataStore::OperationCompleteL() |
|
2249 { |
|
2250 if(iLastOperation == ENSmlDeleteOp) |
|
2251 { |
|
2252 if(iBatchMode ) |
|
2253 { |
|
2254 if(iResultArray->Count() != iContactsBufferItemList.Count()) |
|
2255 { |
|
2256 while( iIndex < iContactsBufferItemList.Count() && |
|
2257 iContactsBufferItemList[iIndex]->iModType == ENSmlCntItemDelete |
|
2258 && iContactsBufferItemList[iIndex]->iStatus == KErrNotFound ) |
|
2259 { |
|
2260 iResultArray->Append(KErrNotFound); |
|
2261 iIndex++; |
|
2262 } |
|
2263 } |
|
2264 |
|
2265 if(iIndex == iContactsBufferItemList.Count()) |
|
2266 { |
|
2267 if(iItemData) |
|
2268 { |
|
2269 iItemData->Reset(); |
|
2270 } |
|
2271 |
|
2272 ResetBuffer(); |
|
2273 User::RequestComplete( iCallerStatus, KErrNone ); |
|
2274 } |
|
2275 else |
|
2276 { |
|
2277 ExecuteBufferL(); |
|
2278 } |
|
2279 } |
|
2280 else |
|
2281 { |
|
2282 |
|
2283 if(iItemData) |
|
2284 { |
|
2285 iItemData->Reset(); |
|
2286 } |
|
2287 |
|
2288 ResetBuffer(); |
|
2289 } |
|
2290 } |
|
2291 else |
|
2292 { |
|
2293 if( iChangeFinder ) |
|
2294 { |
|
2295 iChangeFinder->ResetL(); |
|
2296 } |
|
2297 iSnapshotRegistered = EFalse; |
|
2298 |
|
2299 delete iContactLnks; |
|
2300 iContactLnks = NULL; |
|
2301 iContactLink = NULL; |
|
2302 |
|
2303 delete iContactViewBase; |
|
2304 iContactViewBase = NULL; |
|
2305 User::RequestComplete( iCallerStatus, KErrNone ); |
|
2306 |
|
2307 } |
|
2308 |
|
2309 } |
|
2310 |
|
2311 // --------------------------------------------------------------------------- |
|
2312 // CNSmlContactsDataStore::ContactViewReady |
|
2313 // Implements the view ready function of MVPbkContactViewObserver |
|
2314 // --------------------------------------------------------------------------- |
|
2315 void CNSmlContactsDataStore::ContactViewReady( |
|
2316 MVPbkContactViewBase& /*aView*/ ) |
|
2317 { |
|
2318 if(iLastOperation == ENSMLDeleteAllOp) |
|
2319 { |
|
2320 TRAPD(error,DoDeleteAllContactsL()); |
|
2321 if(error != KErrNone) |
|
2322 { |
|
2323 User::RequestComplete( iCallerStatus, error ); |
|
2324 } |
|
2325 } |
|
2326 } |
|
2327 // --------------------------------------------------------------------------- |
|
2328 // CNSmlContactsDataStore::PrepareForContactsDeleteL() |
|
2329 // Delete all the contacts at client |
|
2330 // --------------------------------------------------------------------------- |
|
2331 void CNSmlContactsDataStore::DoDeleteAllContactsL() |
|
2332 { |
|
2333 iContactLnks = CVPbkContactLinkArray::NewL(); |
|
2334 TInt contactCount = iContactViewBase->ContactCountL(); |
|
2335 //add all the contact links to ContactLinkArray |
|
2336 for( TInt i = 0; i < contactCount; i++ ) |
|
2337 { |
|
2338 const MVPbkViewContact& contact = |
|
2339 iContactViewBase->ContactAtL(i); |
|
2340 iContactLink = contact.CreateLinkLC(); |
|
2341 iContactLnks->AppendL(iContactLink); |
|
2342 CleanupStack::Pop(); |
|
2343 } |
|
2344 |
|
2345 iContactManager->DeleteContactsL( *iContactLnks, *this ); |
|
2346 |
|
2347 } |
|
2348 |
|
2349 // --------------------------------------------------------------------------- |
|
2350 // CNSmlContactsDataStore::ContactViewUnavailable |
|
2351 // Implements the view unavailable function of MVPbkContactViewObserver |
|
2352 // --------------------------------------------------------------------------- |
|
2353 void CNSmlContactsDataStore::ContactViewUnavailable( |
|
2354 MVPbkContactViewBase& /*aView*/ ) |
|
2355 { |
|
2356 |
|
2357 } |
|
2358 |
|
2359 // --------------------------------------------------------------------------- |
|
2360 // CNSmlContactsDataStore::ContactAddedToView |
|
2361 // Implements the add contact function of MVPbkContactViewObserver |
|
2362 // --------------------------------------------------------------------------- |
|
2363 void CNSmlContactsDataStore::ContactAddedToView( |
|
2364 MVPbkContactViewBase& /*aView*/, |
|
2365 TInt /*aIndex*/, |
|
2366 const MVPbkContactLink& /*aContactLink*/ ) |
|
2367 { |
|
2368 } |
|
2369 |
|
2370 // --------------------------------------------------------------------------- |
|
2371 // CNSmlContactsDataStore::ContactRemovedFromView |
|
2372 // Implements the remove contact function of MVPbkContactViewObserver |
|
2373 // --------------------------------------------------------------------------- |
|
2374 void CNSmlContactsDataStore::ContactRemovedFromView( |
|
2375 MVPbkContactViewBase& /*aView*/, |
|
2376 TInt /*aIndex*/, |
|
2377 const MVPbkContactLink& /*aContactLink*/ ) |
|
2378 { |
|
2379 } |
|
2380 |
|
2381 // --------------------------------------------------------------------------- |
|
2382 // CNSmlContactsDataStore::ContactViewError |
|
2383 // Implements the view error function of MVPbkContactViewObserver |
|
2384 // --------------------------------------------------------------------------- |
|
2385 void CNSmlContactsDataStore::ContactViewError( |
|
2386 MVPbkContactViewBase& /*aView*/, |
|
2387 TInt /*aError*/, |
|
2388 TBool /*aErrorNotified*/ ) |
|
2389 { |
|
2390 |
|
2391 } |
|
2392 |
|
2393 // ----------------------------------------------------------------------------- |
|
2394 // CNSmlContactsDataStore::CreateViewL() |
|
2395 // Create a contact view |
|
2396 // ----------------------------------------------------------------------------- |
|
2397 |
|
2398 void CNSmlContactsDataStore::CreateViewL() |
|
2399 { |
|
2400 |
|
2401 CVPbkContactViewDefinition* viewDef = CVPbkContactViewDefinition::NewL(); |
|
2402 CleanupStack::PushL( viewDef ); |
|
2403 viewDef->SetType( EVPbkContactsView ); |
|
2404 |
|
2405 viewDef->SetUriL(iStore->StoreProperties().Uri().UriDes()); |
|
2406 |
|
2407 iContactViewBase = iContactManager->CreateContactViewLC( |
|
2408 *this, |
|
2409 *viewDef, |
|
2410 iContactManager->FieldTypes() ); |
|
2411 CleanupStack::Pop(); |
|
2412 CleanupStack::PopAndDestroy(viewDef); |
|
2413 |
|
2414 } |
|
2415 |
|
2416 // End of File |