|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: DS agenda data store |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __NSMLAGENDADATASTORE_H__ |
|
20 #define __NSMLAGENDADATASTORE_H__ |
|
21 |
|
22 |
|
23 // INCLUDES |
|
24 #include "nsmlconstants.h" |
|
25 #include "nsmlchangefinder.h" |
|
26 #include "NSmlDataModBase.h" |
|
27 #include "nsmlagendadefines.hrh" |
|
28 #include <calentry.h> |
|
29 #include <calsession.h> |
|
30 #include <caldataexchange.h> |
|
31 #include <calentryview.h> |
|
32 #include <f32file.h> |
|
33 #include <SmlDataProvider.h> |
|
34 #include <SmlDataFormat.h> |
|
35 #include <calprogresscallback.h> |
|
36 #include <msvapi.h> |
|
37 #include <CalenImporter.h> |
|
38 #include <CalenExporter.h> |
|
39 #include <CalenInterimUtils2.h> |
|
40 #include <versittls.h> |
|
41 |
|
42 // CONSTANTS |
|
43 const TInt KNSmlAgendaCompressLimit = 20; |
|
44 const TInt KNSmlAgendaLittleArraySize = 4; |
|
45 const TInt KNSmlAgendaSmallArraySize = 8; |
|
46 const TInt KNSmlAgendaLargeArraySize = 128; |
|
47 const TInt KNSmlAgendaOwnMaxObjectSize = 1048576; |
|
48 const TInt KNSmlCompactAfterChanges = 30; |
|
49 const TInt KNSmlDefaultStoreNameMaxSize = 256; |
|
50 const TInt KNSmlItemDataExpandSize = 1024; |
|
51 _LIT( KNSmlDriveC, "C" ); |
|
52 _LIT( KNSmlAgendaStoreNameForDefaultDB, "Calendar" ); |
|
53 _LIT8( KNSmlMRUtilitiesEComPlugInUID, "AgnEntryUi" ); |
|
54 _LIT8( KNSmlVersitTokenRecurrenceID, "RECURRENCE-ID"); |
|
55 _LIT8( KNSmlVersitTokenXRecurrenceID, "X-RECURRENCE-ID"); |
|
56 _LIT8(KNSmlVersitTokenGeoID,"GEO"); |
|
57 |
|
58 |
|
59 // DATA TYPES |
|
60 enum TNSmlDataStoreStatus |
|
61 { |
|
62 ENSmlClosed = 0, |
|
63 ENSmlOpenAndWaiting, |
|
64 ENSmlItemOpen, |
|
65 ENSmlItemCreating, |
|
66 ENSmlItemUpdating |
|
67 }; |
|
68 |
|
69 enum TNSmlDataEntryType |
|
70 { |
|
71 ENSmlVCal = 1, |
|
72 ENSmlICal, |
|
73 ENSmlNotSet |
|
74 }; |
|
75 |
|
76 // CLASS DECLARATIONS |
|
77 // ---------------------------------------------------------------------------- |
|
78 // CNSmlAgendaProgressview provides progress observations for some calendar |
|
79 // classes. |
|
80 // @lib nsmlagendadataprovider.dll |
|
81 // ---------------------------------------------------------------------------- |
|
82 class CNSmlAgendaProgressview : public CBase , public MCalProgressCallBack |
|
83 { |
|
84 public: |
|
85 /** |
|
86 * Two-phased constructor. |
|
87 */ |
|
88 static CNSmlAgendaProgressview* NewL(); |
|
89 |
|
90 /** |
|
91 * Destructor. |
|
92 */ |
|
93 ~CNSmlAgendaProgressview(); |
|
94 |
|
95 /** |
|
96 * This calls the observing class with the percentage complete |
|
97 * of the current operation. |
|
98 * @param aPercentageCompleted The percentage complete |
|
99 */ |
|
100 void Progress( TInt aPercentageCompleted ); |
|
101 |
|
102 /** |
|
103 * This calls the observing class when the current operation is |
|
104 * finished. |
|
105 * @param aError The error if the operation failed, |
|
106 * or KErrNone if successful. |
|
107 */ |
|
108 void Completed( TInt aError ); |
|
109 |
|
110 /** |
|
111 * This method returns status of Completed method (see above). |
|
112 * @return Value based on status of Completed method. |
|
113 * KErrNotReady is returned if Completed method is not |
|
114 * called or same value is Completed status. |
|
115 */ |
|
116 TInt GetCompletedStatus(); |
|
117 |
|
118 /** |
|
119 * Asks the observing class whether progress callbacks are required. |
|
120 * @return If the observing class returns EFalse, then the Progress() |
|
121 * function will not be called. |
|
122 */ |
|
123 TBool NotifyProgress(); |
|
124 |
|
125 private: |
|
126 /** |
|
127 * C++ default constructor. |
|
128 */ |
|
129 CNSmlAgendaProgressview(); |
|
130 |
|
131 /** |
|
132 * Second phase constructor. |
|
133 */ |
|
134 void ConstructL(); |
|
135 |
|
136 private: |
|
137 TInt iCompletedStatus; |
|
138 }; |
|
139 |
|
140 // ---------------------------------------------------------------------------- |
|
141 // CNSmlAgendaDataStore provides services to cope with calendar database access |
|
142 // for calendar events manipulation. |
|
143 // @lib nsmlagendadataprovider.dll |
|
144 // ---------------------------------------------------------------------------- |
|
145 class CNSmlAgendaDataStore : public CSmlDataStore |
|
146 { |
|
147 public: |
|
148 |
|
149 /** |
|
150 * Two-phased constructor. |
|
151 */ |
|
152 static CNSmlAgendaDataStore* NewL(); |
|
153 |
|
154 /** |
|
155 * Destructor. |
|
156 */ |
|
157 virtual ~CNSmlAgendaDataStore(); |
|
158 |
|
159 public: // New functions |
|
160 |
|
161 /** |
|
162 * Returns a pointer to array of all possible Calendar database names |
|
163 * which are provited by Symbian OS Calendar API. |
|
164 * @param none |
|
165 * @return Pointer to array of all possible Calendar database names |
|
166 */ |
|
167 CDesCArray *DoListAgendaFilesLC() const; |
|
168 |
|
169 /** |
|
170 * Returns a reference to default calendar file name which is provited |
|
171 * by Symbian OS Calendar API. |
|
172 * @param none |
|
173 * @return Reference to default calendar file name |
|
174 */ |
|
175 const TDesC& DoGetDefaultFileNameL() const; |
|
176 |
|
177 private: |
|
178 |
|
179 /** |
|
180 * C++ default constructor. |
|
181 */ |
|
182 CNSmlAgendaDataStore(); |
|
183 |
|
184 /** |
|
185 * Returns the used store format. |
|
186 */ |
|
187 CSmlDataStoreFormat* DoOwnStoreFormatL(); |
|
188 |
|
189 /** |
|
190 * Opens the data store specified by aStoreName asynchronously. |
|
191 * @param aStoreName The name of the data store to open. |
|
192 * @param aContext Identifies the specific synchronisation |
|
193 * relationship to use for the |
|
194 * synchronisation. |
|
195 * @param aStatus On completion of the open, |
|
196 * contains the result code. |
|
197 */ |
|
198 void DoOpenL( const TDesC& aStoreName, MSmlSyncRelationship& aContext, |
|
199 TRequestStatus& aStatus ); |
|
200 |
|
201 /** |
|
202 * Cancel the current asynchronous request, including open. |
|
203 * Only one asynchronous request may be outstanding at any one time. |
|
204 */ |
|
205 void DoCancelRequest(); |
|
206 |
|
207 /** |
|
208 * Returns the name of the open data store. |
|
209 */ |
|
210 const TDesC& DoStoreName() const; |
|
211 |
|
212 /** |
|
213 * BeginTransactionL() starts the transaction mode. During this mode |
|
214 * calls to CreateItemL, ReplaceItemL, WriteItemL, CommitItemL, |
|
215 * MoveItemL, DeleteItemL and SoftDeleteItemL will be part of this |
|
216 * transaction. |
|
217 * Their RequestStatus must be completed, even if the change is not |
|
218 * yet really executed in the Data Store. |
|
219 * If a RequestStatus is completed with an error code, the transaction |
|
220 * has failed and a rollback must be done. In this case |
|
221 * RevertTransaction will be called. |
|
222 */ |
|
223 void DoBeginTransactionL(); |
|
224 |
|
225 /** |
|
226 * CommitTransactionL() will be called at the end of a successful |
|
227 * transaction. At this point in time the operations within the |
|
228 * transaction are applied to the Data Store in an atomic way. |
|
229 * If all operations succeed, the RequestStatus must be completed |
|
230 * with KErrNone. If an operation fails, a rollback must be done and |
|
231 * the RequestStatus must be completed with an appropriate error code. |
|
232 */ |
|
233 void DoCommitTransactionL( TRequestStatus& aStatus ); |
|
234 |
|
235 /** |
|
236 * RevertTransaction() will be called to abort an ongoing transaction. |
|
237 * None of the operations already submitted may be applied to the Data |
|
238 * Store. The RequestStatus must be completed with KErrNone as a revert |
|
239 * cannot fail. |
|
240 */ |
|
241 void DoRevertTransaction( TRequestStatus& aStatus ); |
|
242 |
|
243 /** |
|
244 * BeginBatchL() starts the batch mode. During this mode calls to |
|
245 * CreateItemL, ReplaceItemL, WriteItemL, CommitItemL, MoveItemL, |
|
246 * DeleteItemL and SoftDeleteItemL will be part of this batch. |
|
247 * Their RequestStatus must be completed with KErrNone, which only |
|
248 * signals acceptance of the operation for batch processing. |
|
249 */ |
|
250 void DoBeginBatchL(); |
|
251 |
|
252 /** |
|
253 * CommitBatchL() will be called at the end of the batch mode. This |
|
254 * tells the Data Store to process the batched operations (in the |
|
255 * order they were submitted), and to append the error code for each |
|
256 * operation to aResultArray. |
|
257 * The error codes in aResultArray are only valid if the RequestStatus |
|
258 * is completed with KErrNone. |
|
259 * If the RequestStatus is completed with an error code none of the |
|
260 * operations in the batch mode were applied to the Data Store. |
|
261 */ |
|
262 void DoCommitBatchL( RArray<TInt>& aResultArray, |
|
263 TRequestStatus& aStatus ); |
|
264 |
|
265 /** |
|
266 * CancelBatch() will be called to abort an ongoing batch mode. |
|
267 * None of the operations already submitted may be applied to |
|
268 * the Data Store. |
|
269 */ |
|
270 void DoCancelBatch(); |
|
271 |
|
272 /** |
|
273 * Sets the SyncML server Data Format - this may optionally be used |
|
274 * by the Data Provider to filter out properties that the server does |
|
275 * not support, and should be used to avoid deleting these properties |
|
276 * in case the server sends a changed item to the Data Provider |
|
277 */ |
|
278 void DoSetRemoteStoreFormatL( |
|
279 const CSmlDataStoreFormat& aServerDataStoreFormat ); |
|
280 |
|
281 /** |
|
282 * Sets the SyncML server maximum object size - this may optionally |
|
283 * be used by the Data Provider to not send items to the server |
|
284 * exceeding its maximum size. 0 means there is no limit. |
|
285 */ |
|
286 void DoSetRemoteMaxObjectSize( TInt aServerMaxObjectSize ); |
|
287 |
|
288 /** |
|
289 * Gets the Data Store maximum object size which is reported to |
|
290 * the SyncML server. 0 means there is no limit. |
|
291 */ |
|
292 TInt DoMaxObjectSize() const; |
|
293 |
|
294 /** |
|
295 * Opens the data item specified by aUid asynchronously for reading. |
|
296 * @param aUid Item UID which going to be read. |
|
297 * @param aFieldChange Accept field changes. |
|
298 * @param aParent Parent of the item. |
|
299 * @param aSize Size of the item data. |
|
300 * @param aMimeType MIME type of the item. |
|
301 * @param aMimeVer MIME version used on item. |
|
302 * @param aStatus On completion of the opening of |
|
303 * item, contains the result code. |
|
304 */ |
|
305 void DoOpenItemL( TSmlDbItemUid aUid, TBool& aFieldChange, TInt& aSize, |
|
306 TSmlDbItemUid& aParent, TDes8& aMimeType, |
|
307 TDes8& aMimeVer, TRequestStatus& aStatus ); |
|
308 |
|
309 /** |
|
310 * Sets the item properties and reference to aUid which will be created. |
|
311 * @param aUid Reference to item UID which going |
|
312 * to be created. |
|
313 * @param aSize Size of the item to be created. |
|
314 * @param aParent Parent of the item. |
|
315 * @param aMimeType MIME type of the item. |
|
316 * @param aMimeVer MIME version used on item. |
|
317 * @param aStatus On completion of the creating an |
|
318 * item, contains the result code. |
|
319 */ |
|
320 void DoCreateItemL( TSmlDbItemUid& aUid, TInt aSize, |
|
321 TSmlDbItemUid aParent, const TDesC8& aMimeType, |
|
322 const TDesC8& aMimeVer, TRequestStatus& aStatus ); |
|
323 |
|
324 /** |
|
325 * Opens the data item specified by aUid asynchronously to be updated. |
|
326 * @param aUid Item UID which going to be updated. |
|
327 * @param aSize Size of the item data. |
|
328 * @param aParent Parent of the item. |
|
329 * @param aFieldChange Accept field changes. |
|
330 * @param aStatus On completion of the updating of |
|
331 * item, contains the result code. |
|
332 */ |
|
333 void DoReplaceItemL( TSmlDbItemUid aUid, TInt aSize, |
|
334 TSmlDbItemUid aParent, TBool aFieldChange, |
|
335 TRequestStatus& aStatus ); |
|
336 |
|
337 /** |
|
338 * Reads data(or size of aBuffer) of an item opened in DoOpenItemL() |
|
339 * to given aBuffer. |
|
340 * @param aBuffer Buffer to item data. |
|
341 */ |
|
342 void DoReadItemL( TDes8& aBuffer ); |
|
343 |
|
344 /** |
|
345 * Writes aData of an item opened in DoCreateItemL() or DoReplaceItemL() |
|
346 * to be saved on database. |
|
347 * @param aData Item data (or part of data). |
|
348 */ |
|
349 void DoWriteItemL( const TDesC8& aData ); |
|
350 |
|
351 /** |
|
352 * Completes an item operation started in DoCreateItemL() or |
|
353 * DoReplaceItemL(). |
|
354 * @param aStatus On completion of the operation, |
|
355 * contains the result code. |
|
356 */ |
|
357 void DoCommitItemL( TRequestStatus& aStatus ); |
|
358 |
|
359 /** |
|
360 * Completes an item operation started in DoOpenItemL(). |
|
361 */ |
|
362 void DoCloseItem(); |
|
363 |
|
364 /** |
|
365 * Moves item specified by aUid asynchronously. |
|
366 * @param aUid Item UID which going to be moved. |
|
367 * @param aNewParent A new parent of the item. |
|
368 * @param aStatus On completion of the moving an |
|
369 * item, contains the result code. |
|
370 */ |
|
371 void DoMoveItemL( TSmlDbItemUid aUid, TSmlDbItemUid aNewParent, TRequestStatus& aStatus ); |
|
372 |
|
373 /** |
|
374 * Deletes item specified by aUid asynchronously. |
|
375 * @param aUid Item UID which going to be deleted. |
|
376 * @param aStatus On completion of the deleting an |
|
377 * item, contains the result code. |
|
378 */ |
|
379 void DoDeleteItemL( TSmlDbItemUid aUid, TRequestStatus& aStatus ); |
|
380 |
|
381 /** |
|
382 * Softdeletes item specified by aUid asynchronously. |
|
383 * @param aUid Item UID which going to be |
|
384 * softdeleted. |
|
385 * @param aStatus On completion of the softdeleting |
|
386 * an item, contains the result code. |
|
387 */ |
|
388 void DoSoftDeleteItemL( TSmlDbItemUid aUid, TRequestStatus& aStatus ); |
|
389 |
|
390 /** |
|
391 * Deletes all items from opened database asynchronously. |
|
392 * @param aStatus On completion of delete, contains |
|
393 * the result code. |
|
394 */ |
|
395 void DoDeleteAllItemsL( TRequestStatus& aStatus ); |
|
396 |
|
397 /** |
|
398 * Check if previous sync with opened server and context. |
|
399 */ |
|
400 TBool DoHasSyncHistory() const; |
|
401 |
|
402 /** |
|
403 * Get all added items on client since previous synchronization. |
|
404 */ |
|
405 const MSmlDataItemUidSet& DoAddedItems() const; |
|
406 |
|
407 /** |
|
408 * Get all deleted items on client since previous synchronization. |
|
409 */ |
|
410 const MSmlDataItemUidSet& DoDeletedItems() const; |
|
411 |
|
412 /** |
|
413 * Get all softdeleted items on client since previous synchronization. |
|
414 */ |
|
415 const MSmlDataItemUidSet& DoSoftDeletedItems() const; |
|
416 |
|
417 /** |
|
418 * Get all modified items on client since previous synchronization. |
|
419 */ |
|
420 const MSmlDataItemUidSet& DoModifiedItems() const; |
|
421 |
|
422 /** |
|
423 * Get all moved items on client since previous synchronization. |
|
424 */ |
|
425 const MSmlDataItemUidSet& DoMovedItems() const; |
|
426 |
|
427 /** |
|
428 * Resets client synchronization data => next time will be slow sync. |
|
429 * @param aStatus On completion of reset, contains |
|
430 * the result code. |
|
431 */ |
|
432 void DoResetChangeInfoL( TRequestStatus& aStatus ); |
|
433 |
|
434 /** |
|
435 * Commits client synchronization changes for given aItems list. |
|
436 * @param aStatus On completion of given items, |
|
437 * contains the result code. |
|
438 * @param aItems Item ids to be commited. |
|
439 */ |
|
440 void DoCommitChangeInfoL( TRequestStatus& aStatus, |
|
441 const MSmlDataItemUidSet& aItems ); |
|
442 |
|
443 /** |
|
444 * Commits all client synchronization changes. |
|
445 * @param aStatus On completion of all items, |
|
446 * contains the result code. |
|
447 */ |
|
448 void DoCommitChangeInfoL( TRequestStatus& aStatus ); |
|
449 |
|
450 /** |
|
451 * Registers current snapshot. |
|
452 */ |
|
453 void RegisterSnapshotL(); |
|
454 |
|
455 /** |
|
456 * Creates new snapshot. Method gets data from database. |
|
457 * @param aUid UID of item. |
|
458 * @return New snapshot based on item with given UID |
|
459 */ |
|
460 TNSmlSnapshotItem CreateSnapshotItemL( const TCalLocalUid& aUid ); |
|
461 |
|
462 /** |
|
463 * Second phase constructor. |
|
464 */ |
|
465 void ConstructL(); |
|
466 |
|
467 /** |
|
468 * Returns ETrue if indicated entry can be syncronized. |
|
469 */ |
|
470 TBool CanBeSynchronized( |
|
471 const CCalEntry::TReplicationStatus& aReplicationStatus ) const; |
|
472 |
|
473 /** |
|
474 * Completes an item operation started in DoCreateItemL(). |
|
475 */ |
|
476 void DoCommitCreateItemL(); |
|
477 |
|
478 /** |
|
479 * Completes an item operation started in DoReplaceItemL(). |
|
480 */ |
|
481 void DoCommitReplaceItemL(); |
|
482 |
|
483 /** |
|
484 * Gets property from old item. |
|
485 * @param aOldItem Data of old item. |
|
486 * @param aValue Value of searched property. |
|
487 * @param aProperty Property that is searched. |
|
488 */ |
|
489 void GetPropertiesFromDataL( CBufFlat* aOldItem, |
|
490 HBufC8*& aValue, |
|
491 const TDesC8& aProperty ); |
|
492 |
|
493 /** |
|
494 * Adds property and it's value to new item. |
|
495 * This method also removes original property and it's value. |
|
496 * @param aValue Value of added property. |
|
497 * @param aProperty Property that is added. |
|
498 */ |
|
499 void SetPropertiesToDataL( HBufC8*& aValue, |
|
500 const TDesC8& aProperty ); |
|
501 |
|
502 |
|
503 private: // Data |
|
504 // Key |
|
505 TKeyArrayFix iKey; |
|
506 // Position of buffer |
|
507 TInt iPos; |
|
508 // Flag if Synchronization history is available or not |
|
509 TBool iHasHistory; |
|
510 // Modification count |
|
511 TInt iModificationCount; |
|
512 // Internal state of this class |
|
513 TNSmlDataStoreStatus iState; |
|
514 // Flag if SnapshotRegistered is registered or not |
|
515 TBool iSnapshotRegistered; |
|
516 // Drive letter |
|
517 TInt iDrive; |
|
518 // Item's ID that is to be replaced |
|
519 TInt iReplaceItemId; |
|
520 // Internal entry type for received item |
|
521 TNSmlDataEntryType iRXEntryType; |
|
522 // Internal entry type for transmitted item |
|
523 TNSmlDataEntryType iTXEntryType; |
|
524 // ChangeFinder |
|
525 CNSmlChangeFinder* iChangeFinder; |
|
526 // DataModel |
|
527 CNSmlDataModBase* iDataMod; |
|
528 // Status code from functions |
|
529 TRequestStatus* iCallerStatus; |
|
530 // A handle to a file server session |
|
531 RFs iRfs; |
|
532 // ServerMaxObjectSize |
|
533 TInt iServerMaxObjectSize; |
|
534 // Name of the opened database |
|
535 HBufC* iOpenedStoreName; |
|
536 // Default name of the database |
|
537 HBufC* iDefaultStoreName; |
|
538 // Opened database ID |
|
539 TInt64 iOpenedStoreId; |
|
540 // Item's ID that is to be added |
|
541 TInt* iAddItemId; |
|
542 // Item's data that is to be written |
|
543 CBufBase* iItemData; |
|
544 // Own store format |
|
545 CSmlDataStoreFormat* iOwnFormat; |
|
546 // StringPool |
|
547 RStringPool iStringPool; |
|
548 // Uids of new items |
|
549 CNSmlDataItemUidSet* iNewUids; |
|
550 // Uids of deleted items |
|
551 CNSmlDataItemUidSet* iDeletedUids; |
|
552 // Uids of softdeleted items |
|
553 CNSmlDataItemUidSet* iSoftDeletedUids; |
|
554 // Uids of replaced items |
|
555 CNSmlDataItemUidSet* iReplacedUids; |
|
556 // Uids of moved items |
|
557 CNSmlDataItemUidSet* iMovedUids; |
|
558 // Session to calendar server |
|
559 CCalSession* iVCalSession; |
|
560 // Internal progress notifier |
|
561 CNSmlAgendaProgressview* iAgendaProgressview; |
|
562 // Interim Utility |
|
563 CCalenInterimUtils2* iInterimUtils; |
|
564 |
|
565 // Importer |
|
566 CCalenImporter* iImporter; |
|
567 // Exporter |
|
568 CCalenExporter* iExporter; |
|
569 |
|
570 // Entry view |
|
571 CCalEntryView* iEntryView; |
|
572 CVersitTlsData *iVersitTlsData; // for better performance |
|
573 }; |
|
574 |
|
575 #endif // __NSMLAGENDADATASTORE_H__ |
|
576 |
|
577 // End of File |