omads/omadsextensions/adapters/contacts/inc/NSmlContactsDataStore.h
branchRCL_3
changeset 17 4d5e9526124e
parent 15 3f1ffafb31ec
child 18 a564f66a2339
equal deleted inserted replaced
15:3f1ffafb31ec 17:4d5e9526124e
     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 datastore.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __NSMLCONTACTSDATASTORE_H__
       
    20 #define __NSMLCONTACTSDATASTORE_H__
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <SmlDataProvider.h>
       
    24 #include <SmlDataFormat.h>
       
    25 #include <f32file.h>
       
    26 
       
    27 //vpbk headers
       
    28 #include <CVPbkContactManager.h>
       
    29 #include <MVPbkContactStore.h>
       
    30 #include <MVPbkContactStoreObserver.h>
       
    31 #include <MVPbkBatchOperationObserver.h>
       
    32 #include <MVPbkContactViewObserver.h>
       
    33 #include <CVPbkSortOrder.h>
       
    34 #include <CVPbkContactIdConverter.h>
       
    35 #include <CVPbkContactLinkArray.h>
       
    36 #include <MVPbkContactViewBase.h>
       
    37 #include <MVPbkSingleContactOperationObserver.h>
       
    38 #include <CVPbkVCardEng.h>
       
    39 #include <MVPbkContactCopyObserver.h>
       
    40 #include <MVPbkBatchOperationObserver.h>
       
    41 #include <MVPbkContactViewObserver.h>
       
    42 #include <MVPbkContactOperationBase.h>
       
    43 #include <CVPbkSortOrder.h>
       
    44 #include <s32mem.h>
       
    45 
       
    46 #include "nsmlchangefinder.h"
       
    47 
       
    48 
       
    49 // MACROS
       
    50 #define KNSmlvCard21Version TVersion(2,1,0);
       
    51 #define KNSmlvCard30Version TVersion(3,0,0);
       
    52 
       
    53 // CONSTANTS
       
    54 _LIT(  KNSmlContactStoreNameForDefaultDB, "C:Contacts.cdb" );
       
    55 _LIT(  KNSmlDriveC, "C" );
       
    56 _LIT8( KNSmlvCard30Name, "text/vcard" );
       
    57 _LIT8( KNSmlvCard30Ver, "3.0" );
       
    58 _LIT8( KNSmlvCard21Name, "text/x-vcard" );
       
    59 _LIT8( KNSmlvCard21Ver, "2.1" );
       
    60 
       
    61 _LIT8( KVersitTokenHOME, "HOME"  );
       
    62 _LIT8( KVersitTokenWORK, "WORK"  );
       
    63 _LIT8( KVersitTokenCELL, "CELL"  );
       
    64 _LIT8( KVersitTokenPAGER,"PAGER" );
       
    65 _LIT8( KVersitTokenFAX,  "FAX"   );
       
    66 _LIT8( KVersitTokenVOICE,"VOICE" );
       
    67 _LIT8( KVersitTokenVIDEO,"VIDEO" );
       
    68 
       
    69 //CONSTANTS INTRODUCED FOR HAVING BACKWARD COMPATIBLE PHONE DB SENT TO SERVER
       
    70 //THE CHANGE WAS NEEDED AFTER ADAPTING TO VIRTUAL PHONEBOOK
       
    71 _LIT( KLegacySymbianDatabase,"C:Contacts.cdb");
       
    72 const TInt KOldSymbianDBLength = 20;
       
    73 
       
    74 _LIT( KVPbhkSymbianDBPrefix,"cntdb://");
       
    75 const TInt KVPbhkPrefixLength = 10;
       
    76 
       
    77 //End NEW CONSTANTS
       
    78 const TInt KNSmlContactsGranularity = 8;
       
    79 const TInt KNSmlCompactAfterChanges = 16;
       
    80 const TInt KNSmlDataStoreMaxSize = 102400;		// 100 k
       
    81 const TInt KNSmlDefaultStoreNameMaxSize = 256;
       
    82 const TInt KNSmlItemDataExpandSize = 1024;
       
    83 const TInt KNSmlNoError = 1;
       
    84 
       
    85 _LIT(KNSmlContactsStoreFormatRsc_1_1_2,"NSmlContactsDataStoreFormat_1_1_2.rsc");
       
    86 _LIT(KNSmlContactsStoreFormatRsc_1_2,"NSmlContactsDataStoreFormat_1_2.rsc");
       
    87 
       
    88 // FORWARD DECLARATIONS
       
    89 class CNSmlContactsModsFetcher;
       
    90 class CNSmlDataModBase;
       
    91 
       
    92 	
       
    93 // CLASS DECLARATION
       
    94 
       
    95 // ------------------------------------------------------------------------------------------------
       
    96 // CNSmlContactsDataStore
       
    97 //
       
    98 // @lib nsmlcontactsdataprovider.lib
       
    99 // ------------------------------------------------------------------------------------------------
       
   100 class CNSmlContactsDataStore : public CSmlDataStore,
       
   101 								MVPbkContactStoreObserver,
       
   102 								MVPbkSingleContactOperationObserver,
       
   103 								MVPbkContactCopyObserver,
       
   104 								MVPbkBatchOperationObserver,
       
   105 								MVPbkContactViewObserver,
       
   106 								MVPbkContactOperationBase
       
   107 	{
       
   108 	public:	
       
   109 		/**
       
   110 		* Two-phased constructor.
       
   111 		*/
       
   112 		static CNSmlContactsDataStore* NewL();
       
   113 
       
   114 		/**
       
   115 		* Destructor.
       
   116 		*/
       
   117 		virtual ~CNSmlContactsDataStore();
       
   118 
       
   119 		/**
       
   120 		* Default store name of client.
       
   121 		* @return Default store name.
       
   122 		*/
       
   123 		const TDesC& DefaultStoreNameL() const;
       
   124 
       
   125 		/**
       
   126 		* Gets a list of all contacts databases on client.
       
   127 		* @return List of databases.
       
   128 		*/
       
   129 		CDesCArray* DoListStoresLC();
       
   130 		
       
   131 
       
   132 	private:
       
   133 		/**
       
   134 		* From MVPbkContactStoreListObserver  
       
   135 		* Called when a contact store is ready to use.
       
   136 		*/
       
   137 		 void StoreReady( MVPbkContactStore& aContactStore );
       
   138 		 
       
   139 		/**
       
   140 		* From MVPbkContactStoreListObserver  
       
   141 		* Called when a contact store becomes unavailable.
       
   142 		*/
       
   143 		 void StoreUnavailable(MVPbkContactStore& aContactStore,TInt aReason );
       
   144 	
       
   145 		/**
       
   146 		* From MVPbkContactStoreListObserver  
       
   147 		*  Called when changes occur in the contact store.
       
   148 		*/
       
   149 		 void HandleStoreEventL(MVPbkContactStore& aContactStore,TVPbkContactStoreEvent aStoreEvent );
       
   150 		 
       
   151 		/**
       
   152 		* From MVPbkSingleContactOperationObserver  
       
   153 		* Called when the operation is completed.
       
   154 		*/
       
   155          void VPbkSingleContactOperationComplete(
       
   156          	MVPbkContactOperationBase& aOperation,
       
   157          	MVPbkStoreContact* aContact ); 
       
   158          
       
   159 		/**
       
   160 		* From MVPbkSingleContactOperationObserver  
       
   161 		*  Called if the operation fails.
       
   162 		*/
       
   163  		void VPbkSingleContactOperationFailed(MVPbkContactOperationBase& aOperation, TInt aError );
       
   164  		
       
   165  		/**
       
   166 		* From MVPbkContactCopyObserver  
       
   167 		* Called when the contact has been successfully commited or
       
   168         * copied. Caller takes the ownership of results.
       
   169    		*/
       
   170  		void ContactsSaved( MVPbkContactOperationBase& aOperation,
       
   171             MVPbkContactLinkArray* aResults ) ;
       
   172         
       
   173         /**
       
   174 		* From MVPbkContactCopyObserver  
       
   175 		*Called when there was en error while saving contact(s).
       
   176 		*/
       
   177         void ContactsSavingFailed( 
       
   178                 MVPbkContactOperationBase& aOperation, 
       
   179                 TInt aError );
       
   180         // From MVPbkBatchOperationObserver
       
   181     
       
   182 	    /**
       
   183 	     * Called when one step of the operation is complete.
       
   184 	     * @param aOperation Operation whose step has completed
       
   185 	     * @param aStepSize Size of the performed step
       
   186 	     */     
       
   187 	    void StepComplete( MVPbkContactOperationBase& aOperation, 
       
   188 	        TInt aStepSize );
       
   189 	    
       
   190 	    /**
       
   191 	     * Called when one step of the operation fails
       
   192 	     * @param aOperation Operation whose step has failed
       
   193 	     * @param aStepSize Size of the performed step
       
   194 	     * @param aError Error that occured
       
   195 	     * @return ETrue if the batch operation should continue, 
       
   196 	     *               EFalse otherwise
       
   197 	     */     
       
   198 	    TBool StepFailed(
       
   199 	        MVPbkContactOperationBase& aOperation,
       
   200 	        TInt aStepSize,
       
   201 	        TInt aError );
       
   202 	    
       
   203 	    /**
       
   204 	     * Called when operation is completed
       
   205 	     * @param aOperation the completed operation
       
   206 	     */    
       
   207 	    void OperationComplete( MVPbkContactOperationBase& aOperation );  
       
   208 	    
       
   209 	    /**
       
   210 		* From MVPbkContactViewObserver  
       
   211 		* Called when a view is ready for use. 
       
   212 		*/
       
   213 
       
   214 		void ContactViewReady(
       
   215 		            MVPbkContactViewBase& aView ) ;
       
   216 		/**
       
   217 		* From MVPbkContactViewObserver  
       
   218 		* Called when a view is unavailable for a while. 
       
   219 		*/            
       
   220 		void ContactViewUnavailable(
       
   221 		            MVPbkContactViewBase& aView ) ;
       
   222 		/**
       
   223 		* From MVPbkContactViewObserver  
       
   224 		* Called when a contact has been added to the view.
       
   225 		*/            
       
   226 		void ContactAddedToView(
       
   227 		            MVPbkContactViewBase& aView, 
       
   228 		            TInt aIndex, 
       
   229 		            const MVPbkContactLink& aContactLink );
       
   230 		/**
       
   231 		* From MVPbkContactViewObserver  
       
   232 		* Called when a contact has been removed from a view.
       
   233 		*/            
       
   234 		void ContactRemovedFromView(
       
   235 		            MVPbkContactViewBase& aView, 
       
   236 		            TInt aIndex, 
       
   237 		            const MVPbkContactLink& aContactLink ) ;
       
   238 		/**
       
   239 		* From MVPbkContactViewObserver  
       
   240 		* Called when an error occurs in the view.
       
   241 		*/            
       
   242 		void ContactViewError(
       
   243 		            MVPbkContactViewBase& aView, 
       
   244 		            TInt aError, 
       
   245 		            TBool aErrorNotified ) ;
       
   246 	
       
   247 	private:
       
   248 		/**
       
   249 		* 2nd phase constructor.
       
   250 		*/
       
   251 		void ConstructL();
       
   252 
       
   253 		/**
       
   254 		* DoOpenL() opens the data store specified by aStoreName asynchronously.
       
   255 		* @param		aStoreName			The name of the data store to open.
       
   256 		* @param		aContext			Identifies the specific synchronisation relationship to use for the synchronisation.
       
   257 		* @param		aStatus				On completion of the open, contains the result code.
       
   258 		*/
       
   259 		void DoOpenL(const TDesC& aStoreName, MSmlSyncRelationship& aContext, TRequestStatus& aStatus);
       
   260 
       
   261 		/**
       
   262 		* DoCancelRequest() cancels the current asynchronous request, including open. Only one asynchronous request may be outstanding at any one time.
       
   263 		*/
       
   264 		void DoCancelRequest();
       
   265 
       
   266 		/**
       
   267 		* DoStoreName() returns the name of the open data store.
       
   268 		* @return The name of the currently opened data store.
       
   269 		*/
       
   270 		const TDesC& DoStoreName() const;
       
   271 
       
   272 		/**
       
   273 		* DoBeginTransactionL() starts the transaction mode. During this mode calls to CreateItemL, ReplaceItemL,
       
   274 		* WriteItemL, CommitItemL, MoveItemL, DeleteItemL and SoftDeleteItemL will be part of this transaction.
       
   275 		* Their RequestStatus must be completed, even if the change is not yet really executed in the Data Store.
       
   276 		* If a RequestStatus is completed with an error code, the transaction has failed and a rollback must be
       
   277 		* done. In this case RevertTransaction will be called.
       
   278 		*/
       
   279 		void DoBeginTransactionL();
       
   280 
       
   281 		/**
       
   282 		* DoCommitTransactionL() will be called at the end of a successful transaction. At this point in time the
       
   283 		* operations within the transaction are applied to the Data Store in an atomic way. If all operations
       
   284 		* succeed, the RequestStatus must be completed with KErrNone. If an operation fails, a rollback must be
       
   285 		* done and the RequestStatus must be completed with an appropriate error code.
       
   286 		*/
       
   287 		void DoCommitTransactionL(TRequestStatus& aStatus);
       
   288 
       
   289 		/**
       
   290 		* DoRevertTransaction() will be called to abort an ongoing transaction. None of the operations already
       
   291 		* submitted may be applied to the Data Store. The RequestStatus must be completed with KErrNone as a revert
       
   292 		* cannot fail.
       
   293 		*/
       
   294 		void DoRevertTransaction(TRequestStatus& aStatus);
       
   295 
       
   296 		/**
       
   297 		* DoBeginBatchL() starts the batch mode. During this mode calls to CreateItemL, ReplaceItemL,
       
   298 		* WriteItemL, CommitItemL, MoveItemL, DeleteItemL and SoftDeleteItemL will be part of this batch.
       
   299 		* Their RequestStatus must be completed with KErrNone, which only signals acceptance of the operation
       
   300 		* for batch processing.
       
   301 		*/
       
   302 		void DoBeginBatchL();
       
   303 
       
   304 		/**
       
   305 		* DoCommitBatchL() will be called at the end of the batch mode. This tells the Data Store to
       
   306 		* process the batched operations (in the order they were submitted), and to append the error code
       
   307 		* for each operation to aResultArray.
       
   308 		* The error codes in aResultArray are only valid if the RequestStatus is completed with KErrNone.
       
   309 		* If the RequestStatus is completed with an error code none of the operations in the batch mode
       
   310 		* were applied to the Data Store.
       
   311 		*/
       
   312 		void DoCommitBatchL(RArray<TInt>& aResultArray, TRequestStatus& aStatus);
       
   313 
       
   314 		/**
       
   315 		* DoCancelBatch() will be called to abort an ongoing batch mode. None of the operations already
       
   316 		* submitted may be applied to the Data Store.
       
   317 		*/
       
   318 		void DoCancelBatch();
       
   319 
       
   320 		/**
       
   321 		* DoSetRemoteStoreFormatL() sets the SyncML server Data Format - this may optionally be used by the Data 
       
   322 		* Provider to filter out properties that the server does not support, and should be used to avoid deleting 
       
   323 		* these properties in case the server sends a changed item to the Data Provider
       
   324 		*/
       
   325 		void DoSetRemoteStoreFormatL(const CSmlDataStoreFormat& aServerDataStoreFormat);
       
   326 
       
   327 		/**
       
   328 		* DoSetRemoteMaxObjectSize() sets the SyncML server maximum object size - this may optionally be used by the 
       
   329 		* Data Provider to not send items to the server exceeding its maximum size. 0 means there is no limit.
       
   330 		*/
       
   331 		void DoSetRemoteMaxObjectSize(TInt aServerMaxObjectSize);
       
   332 
       
   333 		/**
       
   334 		* DoMaxObjectSize() gets the Data Store maximum object size which is reported to the SyncML server. 0 means 
       
   335 		* there is no limit.
       
   336 		* @return The maximum object size.
       
   337 		*/
       
   338 		TInt DoMaxObjectSize() const;
       
   339 
       
   340 		/**
       
   341 		* DoOpenItemL() opens the data item specified by aUid asynchronously for reading.
       
   342 		* @param		aUid				Item UID which going to be read.
       
   343 		* @param		aFieldChange		Accept field changes.
       
   344 		* @param		aParent				Parent of the item.
       
   345 		* @param		aSize				Size of the item data.
       
   346 		* @param		aMimeType			MIME type of the item.
       
   347 		* @param		aMimeVer			MIME version used on item.
       
   348 		* @param		aStatus				On completion of the opening of item, contains the result code.
       
   349 		*/
       
   350 		void DoOpenItemL(TSmlDbItemUid aUid, TBool& aFieldChange, TInt& aSize, TSmlDbItemUid& aParent, TDes8& aMimeType, TDes8& aMimeVer, TRequestStatus& aStatus);
       
   351 
       
   352 		/**
       
   353 		* DoCreateItemL() sets the item properties and reference to aUid which will be created.
       
   354 		* @param		aUid				Reference to item UID which going to be created.
       
   355 		* @param		aSize				Size of the item to be created.
       
   356 		* @param		aParent				Parent of the item.
       
   357 		* @param		aMimeType			MIME type of the item.
       
   358 		* @param		aMimeVer			MIME version used on item.
       
   359 		* @param		aStatus				On completion of the creating an item, contains the result code.
       
   360 		*/
       
   361 		void DoCreateItemL(TSmlDbItemUid& aUid, TInt aSize, TSmlDbItemUid aParent, const TDesC8& aMimeType, const TDesC8& aMimeVer, TRequestStatus& aStatus);
       
   362 
       
   363 		/**
       
   364 		* DoReplaceItemL() opens the data item specified by aUid asynchronously to be updated.
       
   365 		* @param		aUid				Item UID which going to be updated.
       
   366 		* @param		aSize				Size of the item data.
       
   367 		* @param		aParent				Parent of the item.
       
   368 		* @param		aFieldChange		Accept field changes.
       
   369 		* @param		aStatus				On completion of the updating of item, contains the result code.
       
   370 		*/
       
   371 		void DoReplaceItemL(TSmlDbItemUid aUid, TInt aSize, TSmlDbItemUid aParent, TBool aFieldChange, TRequestStatus& aStatus);
       
   372 
       
   373 		/**
       
   374 		* DoReadItemL() reads data(or size of aBuffer) of an item opened in DoOpenItemL() to given aBuffer.
       
   375 		* @param		aBuffer				Buffer to item data.
       
   376 		*/
       
   377 		void DoReadItemL(TDes8& aBuffer);
       
   378 
       
   379 		/**
       
   380 		* DoWriteItemL() writes aData of an item opened in DoCreateItemL() or DoReplaceItemL() to be saved on database.
       
   381 		* @param		aData				Item data (or part of data).
       
   382 		*/
       
   383 		void DoWriteItemL(const TDesC8& aData);
       
   384 
       
   385 		/**
       
   386 		* DoCommitItemL() completes an item operation started in DoCreateItemL() or DoReplaceItemL().
       
   387 		* @param		aStatus				On completion of the operation, contains the result code.
       
   388 		*/
       
   389 		void DoCommitItemL(TRequestStatus& aStatus);
       
   390 
       
   391 		/**
       
   392 		* DoCloseItem() completes an item operation started in DoOpenItemL().
       
   393 		*/
       
   394 		void DoCloseItem();
       
   395 
       
   396 		/**
       
   397 		* DoMoveItemL() moves item specified by aUid asynchronously.
       
   398 		* @param		aUid				Item UID which going to be moved.
       
   399 		* @param		aNewParent			A new parent of the item.
       
   400 		* @param		aStatus				On completion of the moving an item, contains the result code.
       
   401 		*/
       
   402 		void DoMoveItemL(TSmlDbItemUid aUid, TSmlDbItemUid aNewParent, TRequestStatus& aStatus);
       
   403 
       
   404 		/**
       
   405 		* DoDeleteItemL() deletes item specified by aUid asynchronously.
       
   406 		* @param		aUid				Item UID which going to be deleted.
       
   407 		* @param		aStatus				On completion of the deleting an item, contains the result code.
       
   408 		*/
       
   409 		void DoDeleteItemL(TSmlDbItemUid aUid, TRequestStatus& aStatus);
       
   410 
       
   411 		/**
       
   412 		* DoSoftDeleteItemL() soft deletes item specified by aUid asynchronously.
       
   413 		* @param		aUid				Item UID which going to be softdeleted.
       
   414 		* @param		aStatus				On completion of the softdeleting an item, contains the result code.
       
   415 		*/
       
   416 		void DoSoftDeleteItemL(TSmlDbItemUid aUid, TRequestStatus& aStatus);
       
   417 
       
   418 		/**
       
   419 		* DoDeleteAllItemsL() deletes all items from opened database asynchronously.
       
   420 		* @param		aStatus				On completion of delete, contains the result code.
       
   421 		*/
       
   422 		void DoDeleteAllItemsL(TRequestStatus& aStatus);
       
   423 
       
   424 		/**
       
   425 		* DoHasSyncHistory() checks if previous sync with opened server and context.
       
   426 		* @return ETrue if there is synchonization history.
       
   427 		*/
       
   428 		TBool DoHasSyncHistory() const;
       
   429 
       
   430 		/**
       
   431 		* DoAddedItems() gets all added items on client since previous synchronization.
       
   432 		* @return Added items.
       
   433 		*/
       
   434 		const MSmlDataItemUidSet& DoAddedItems() const;
       
   435 
       
   436 		/**
       
   437 		* DoDeletedItems() gets all deleted items on client since previous synchronization.
       
   438 		* @return Deleted items.
       
   439 		*/
       
   440 		const MSmlDataItemUidSet& DoDeletedItems() const;
       
   441 
       
   442 		/**
       
   443 		* DoSoftDeletedItems() gets all softdeleted items on client since previous synchronization.
       
   444 		* @return Soft deleted items.
       
   445 		*/
       
   446 		const MSmlDataItemUidSet& DoSoftDeletedItems() const;
       
   447 
       
   448 		/**
       
   449 		* DoModifiedItems() gets all modified items on client since previous synchronization.
       
   450 		* @return Modified items.
       
   451 		*/
       
   452 		const MSmlDataItemUidSet& DoModifiedItems() const;
       
   453 
       
   454 		/**
       
   455 		* DoMovedItems() gets all moved items on client since previous synchronization.
       
   456 		* @return Moved items.
       
   457 		*/
       
   458 		const MSmlDataItemUidSet& DoMovedItems() const;
       
   459 
       
   460 		/**
       
   461 		* DoResetChangeInfoL() resets client synchronization data => next time will be slow sync.
       
   462 		* @param		aStatus				On completion of reset, contains the result code.
       
   463 		*/
       
   464 		void DoResetChangeInfoL(TRequestStatus& aStatus);
       
   465 
       
   466 		/**
       
   467 		* DoCommitChangeInfoL() commits client synchronization changes for given aItems list.
       
   468 		* @param		aStatus				On completion of given items, contains the result code.
       
   469 		* @param		aItems				Item ids to be commited.
       
   470 		*/
       
   471 		void DoCommitChangeInfoL(TRequestStatus& aStatus, const MSmlDataItemUidSet& aItems);
       
   472 
       
   473 		/**
       
   474 		* DoCommitChangeInfoL() commits all client synchronization changes.
       
   475 		* @param		aStatus				On completion of all items, contains the result code.
       
   476 		*/
       
   477 		void DoCommitChangeInfoL(TRequestStatus& aStatus);
       
   478 
       
   479 		/**
       
   480 		* Default constructor.
       
   481 		*/
       
   482 		CNSmlContactsDataStore();
       
   483 
       
   484 		/**
       
   485 		* SetOwnStoreFormatL() Sets dataproviders own storeformat.
       
   486 		*/
       
   487 		void SetOwnStoreFormatL();
       
   488 
       
   489 		/**
       
   490 		* LdoFetchItemL() Fetches item data from database.
       
   491 		* @param		aUid				Items uid for fetching.
       
   492 		* @param		aItem				Items data after fetch.
       
   493 		* 
       
   494 		*/
       
   495 		void LdoFetchItemL( TSmlDbItemUid& aUid, CBufBase& aItem );
       
   496 
       
   497 		/*
       
   498 		* LdoAddItemL() Adds item data to database.
       
   499 		* @param		aItem				Item data to be added.
       
   500 		* @param		aSize				Item data size.
       
   501 		*/
       
   502 		void LdoAddItemL( const TDesC8& aItem,
       
   503 		                  TInt aSize);
       
   504 		/*
       
   505 		* LdoAddItemL() Adds several items to database.
       
   506 		* @param		aItem				Items data to be added.
       
   507 		* @param		aSize				Items data size.
       
   508 		*/
       
   509 		void LdoAddItemsL( CBufBase*& aItems,TInt aSize);
       
   510 		
       
   511 		/**
       
   512 		* LdoUpdateItemL() Updates item data to database.
       
   513 		* 
       
   514 		*/
       
   515 		void LdoUpdateItemL();
       
   516 		
       
   517 		/**
       
   518 		* DriveBelowCriticalLevelL() Checks if there is enough space on client to store added item data.
       
   519 		* @param		aSize				Item size to be added.
       
   520 		* @return ETrue if there isn't enough drive space.
       
   521 		*/
       
   522 		TBool DriveBelowCriticalLevelL( TInt aSize );
       
   523 
       
   524 
       
   525 		/**
       
   526 		* StripPropertyL() Removes aProperty from aItem data.
       
   527 		* @param		aItem				Item data to be stripped.
       
   528 		* @param		aProperty			Property to be removed from aItem.
       
   529 		*/
       
   530 		void StripPropertyL( HBufC8*& aItem, const TDesC8& aProperty ) const;
       
   531 
       
   532 		/**
       
   533 		* StripPropertyL() Remove aPropertys from aItem data.
       
   534 		* @param		aItem				Item(s) data to be stripped.
       
   535 		* @param		aProperty			Property to be removed from aItem.
       
   536 		*/
       
   537 		void StripPropertyL( CBufBase*& aItem, const TDesC8& aProperty ) const;
       
   538 
       
   539 		/**
       
   540 		* ExecuteBufferL() Executes all buffered items from buffer.
       
   541 		* @param		aResultArray		Array to return statuscodes for each command.
       
   542 		*/
       
   543 		void ExecuteBufferL();
       
   544 		
       
   545 		/**
       
   546 		* ExecuteAddL() Executes all the add commands in buffer.
       
   547 		*/
       
   548 		TInt ExecuteAddL();
       
   549 		
       
   550 		/**
       
   551 		* ExecuteDeleteL() Executes all the delete commands in buffer.
       
   552 		*/
       
   553 		void ExecuteDeleteL();
       
   554 		
       
   555 		/**
       
   556 		* ExecuteBufferL() Executes all the update commands in buffer.
       
   557 		*/
       
   558 		void ExecuteUpdateL();
       
   559 		
       
   560 		/**
       
   561 		* ExecuteMoveL() Executes all the move commands in buffer.
       
   562 		*/
       
   563 		void ExecuteMoveL();
       
   564 	
       
   565 		/**
       
   566 		* AddBufferListL()Adds a new item to buffer.
       
   567 		* @param 		aUid 				New item's uid.
       
   568 		* @param 		aSize 				New item's size.
       
   569 		* @param 		aStatus 			New item's status.
       
   570 		* @return Pointer to the buffer.
       
   571 		*/
       
   572 		CBufBase* AddBufferListL(TSmlDbItemUid& aUid, TInt aSize, TInt aStatus);
       
   573 		
       
   574 		/**
       
   575 		* Checks if aItem is confidential or not.
       
   576 		* @param    aItem   Item that is checked.
       
   577 		* @return   TBool   ETrue if item is confidential.
       
   578 		*                   Otherwise EFalse is returned.
       
   579 		*/
       
   580         TBool IsConfidentialL( MVPbkStoreContact& aItem );
       
   581         
       
   582         /**
       
   583 		* Leaving function called when fetch/retrieve 
       
   584 		* operation is complete
       
   585 		* @param    aContact   contact fetched/retrieved
       
   586 		* 
       
   587 		*/
       
   588         void SingleContactOperationCompleteL(MVPbkStoreContact* aContact);
       
   589         
       
   590         /**
       
   591 		* Create a contact view of the store which is opened
       
   592 		*/
       
   593         void CreateViewL();
       
   594         
       
   595         /**
       
   596 		* Delete all the contacts
       
   597 		*/
       
   598         void DoDeleteAllContactsL();
       
   599         /**
       
   600 		* Leaving function called when the operation is complete
       
   601 		*/
       
   602         void OperationCompleteL();
       
   603         /**
       
   604 		* Reset the contacts data buffer
       
   605 		*/
       
   606         void ResetBuffer();
       
   607 	
       
   608 
       
   609 	private: // data
       
   610 	
       
   611 			// MODULE DATA STRUCTURES
       
   612 		enum TNSmlDataStoreStatus  // DataStore status
       
   613 			{
       
   614 			ENSmlClosed = 1,
       
   615 			ENSmlOpenAndWaiting,
       
   616 			ENSmlItemOverflow,
       
   617 			ENSmlItemOpen,
       
   618 			ENSmlItemCreating,
       
   619 			ENSmlItemUpdating
       
   620 			};
       
   621 
       
   622 		enum TNSmlCntCommand		// Modification type
       
   623 			{
       
   624 			ENSmlCntItemAdd = 1,
       
   625 			ENSmlCntItemDelete,
       
   626 			ENSmlCntItemSoftDelete,
       
   627 			ENSmlCntItemRead,
       
   628 			ENSmlCntItemMove,
       
   629 			ENSmlCntItemReplace
       
   630 			};
       
   631 			
       
   632 			enum TNSmlLastOp
       
   633 			{
       
   634 			ENSmlRetrieveOp = 1,
       
   635 			ENSmlAddOp,
       
   636 			ENSmlDeleteOp,
       
   637 			ENSMLFetchOp,
       
   638 			ENSMLDeleteAllOp,
       
   639 			ENSMLUpdateExportOp,
       
   640 			ENSMLUpdateImportOp,
       
   641 			ENSmlNone
       
   642 			};
       
   643 	
       
   644 
       
   645 		// ------------------------------------------------------------------------------------------------
       
   646 		// Buffering Stuff for BatchMode operations
       
   647 		// ------------------------------------------------------------------------------------------------
       
   648 		class CNSmlContactsBufferItem : public CBase
       
   649 			{
       
   650 			public:	
       
   651 				/**
       
   652 				* Destructor.
       
   653 				*/
       
   654 				~CNSmlContactsBufferItem();
       
   655 				
       
   656 			public: // data
       
   657 				TSmlDbItemUid	*iPUid;			// New item ID 
       
   658 				TSmlDbItemUid	iUid;			// Item ID
       
   659 				CBufBase		*iItemData;		// Item data
       
   660 				HBufC8 			*iMimeType;		// Mimetype
       
   661 				HBufC8 			*iMimeVersion;	// Mime version
       
   662 				TNSmlCntCommand iModType;		// Commands type
       
   663 				TInt			iStatus;		// Command status
       
   664 				TInt 			iSize;			// Item size
       
   665 			};
       
   666 		
       
   667 	
       
   668 		CNSmlChangeFinder* iChangeFinder;
       
   669 		TRequestStatus* iCallerStatus;
       
   670 		TBool iSnapshotRegistered;
       
   671 		TBool iBatchMode;
       
   672 		TBool iTransactionMode;
       
   673 		TBool iOpened;
       
   674 		TInt iModificationCount;
       
   675 		TInt64 iOpenedStoreId;
       
   676 
       
   677 		TPtrC8 iMimeTypeItem;
       
   678 		TPtrC8 iMimeVersionItem;
       
   679 		
       
   680 		TPtrC8 iUsedMimeType;
       
   681 		TPtrC8 iUsedMimeVersion;
       
   682 
       
   683 		RStringF iServerMimeType;
       
   684 		RStringF iServerMimeVersion;
       
   685 		
       
   686 		TInt iServerMaxObjectSize;
       
   687 		HBufC* iDefaultStoreName;
       
   688 				
       
   689 		//The symbian Db name that is used for communication with servers
       
   690 		//Changes done to mantain backward compatibility of function
       
   691 		HBufC* iPacketStoreName;
       
   692 
       
   693 		CNSmlDataModBase* iDataMod;
       
   694 		CNSmlContactsModsFetcher* iContactsModsFetcher; 
       
   695 
       
   696 		RFs iRfs;
       
   697 		TInt iDrive;
       
   698 		
       
   699 		
       
   700 		TSmlDbItemUid iUid;
       
   701 		TInt iItemSize;
       
   702 		TInt iItemPos;
       
   703 		TNSmlCntCommand iModType;
       
   704 		
       
   705 		CBufBase* iItemData;
       
   706 		CBufBase* iItemDataAddBatch;
       
   707 		CBufFlat* iMergeItem;
       
   708 
       
   709 		RPointerArray<CNSmlContactsBufferItem> iContactsBufferItemList;
       
   710 
       
   711 		TKeyArrayFix iKey;
       
   712 		TBool iSyncHistory;
       
   713 		HBufC* iStoreName;
       
   714 		
       
   715 		RStringPool iStringPool;
       
   716 		CSmlDataStoreFormat* iStoreFormat;
       
   717 		
       
   718 		CNSmlDataItemUidSet* iNewUids;
       
   719 		CNSmlDataItemUidSet* iDeletedUids;
       
   720 		CNSmlDataItemUidSet* iSoftDeletedUids;
       
   721 		CNSmlDataItemUidSet* iReplacedUids;
       
   722 		CNSmlDataItemUidSet* iMovedUids;
       
   723 
       
   724 		
       
   725 		TNSmlDataStoreStatus iState;
       
   726 		TInt iStateItem;
       
   727 		
       
   728 		RArray<TInt> iAddResultArray; 
       
   729 
       
   730 		CVPbkContactManager* iContactManager;
       
   731         MVPbkContactStore* iStore;
       
   732         CVPbkVCardEng* iVCardEngine ;
       
   733         MVPbkContactLink* iContactLink;
       
   734         CVPbkContactIdConverter* iIdConverter;
       
   735         CVPbkContactLinkArray* iContactLnks;
       
   736         MVPbkContactViewBase* iContactViewBase;
       
   737         
       
   738         TInt *iSize;
       
   739         RBufWriteStream iWriteStream;
       
   740         RDesReadStream iReadStream;
       
   741         HBufC8* iBuf;
       
   742         TInt  iRetCommand;
       
   743         
       
   744         TInt iIndex;
       
   745 		TInt iRetrieveCount;
       
   746 		RArray<TInt> *iResultArray;
       
   747 		TNSmlLastOp iLastOperation;
       
   748 	};
       
   749 
       
   750 
       
   751 #endif // __NSMLCONTACTSDATASTORE_H__
       
   752 
       
   753 // End of File