omads/omadsextensions/adapters/contactsgroup/inc/contactsgrpdatastore.h
branchRCL_3
changeset 25 4f0867e42d62
parent 24 8e7494275d3a
child 26 3e6957da2ff8
equal deleted inserted replaced
24:8e7494275d3a 25:4f0867e42d62
     1 /*
       
     2 * Copyright (c) 2009-2010 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:  Part of ContactGroup DS adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __CONTACTSGRPDATASTORE_H__
       
    20 #define __CONTACTSGRPDATASTORE_H__
       
    21 
       
    22 #include <SmlDataProvider.h>
       
    23 #include <f32file.h>
       
    24 #include <cntdef.h>
       
    25 
       
    26 class CNSmlDataItemUidSet;
       
    27 class CContactsGrpConverter;
       
    28 class CChangeFinder;
       
    29 class TSnapshotItem;
       
    30 class CContactDatabase;
       
    31 
       
    32 class CContactsGrpDataStore : public CSmlDataStore
       
    33 	{
       
    34 private:
       
    35 
       
    36 	CContactsGrpDataStore();
       
    37 	~CContactsGrpDataStore();	
       
    38 	
       
    39 public:
       
    40 
       
    41 	static CContactsGrpDataStore* NewL();
       
    42 	static CContactsGrpDataStore* NewLC();
       
    43 	void ConstructL();	
       
    44 	
       
    45 	// Transactions (optional)
       
    46 	void DoBeginTransactionL();
       
    47 	void DoCommitTransactionL(TRequestStatus& aStatus);
       
    48 	void DoRevertTransaction(TRequestStatus& aStatus);
       
    49 
       
    50 	// Batching (optional)
       
    51 	void DoBeginBatchL();
       
    52 	void DoCommitBatchL(RArray<TInt>& aResultArray, TRequestStatus& aStatus);
       
    53 	void DoCancelBatch();
       
    54 
       
    55 	// Opens data store asynchronously	
       
    56 	void DoOpenL(const TDesC& aStoreName, MSmlSyncRelationship& aContext, TRequestStatus& aStatus);
       
    57 	// Cancels current asynchronous request
       
    58 	void DoCancelRequest();
       
    59 	// Returns the name of open database, empty if OpenL hasn't been called
       
    60 	const TDesC& DoStoreName() const;
       
    61 	// Sets remote server data format
       
    62 	void DoSetRemoteStoreFormatL(const CSmlDataStoreFormat& aServerDataStoreFormat);
       
    63 	// Sets the remote server maximum object size
       
    64 	void DoSetRemoteMaxObjectSize(TInt aServerMaxObjectSize);
       
    65 	// Returns maximum object size, reported by remote server
       
    66 	TInt DoMaxObjectSize() const;
       
    67 
       
    68 	// Opens item for reading
       
    69 	void DoOpenItemL(TSmlDbItemUid aUid, TBool& aFieldChange, TInt& aSize,
       
    70 	    TSmlDbItemUid& aParent, TDes8& aMimeType, TDes8& aMimeVer, TRequestStatus& aStatus);
       
    71 	// Initializes new item to data store
       
    72 	void DoCreateItemL(TSmlDbItemUid& aUid, TInt aSize, TSmlDbItemUid aParent,
       
    73 	    const TDesC8& aMimeType, const TDesC8& aMimeVer, TRequestStatus& aStatus);
       
    74 	// Initializes replace of item in data store
       
    75 	void DoReplaceItemL(TSmlDbItemUid aUid, TInt aSize, TSmlDbItemUid aParent,
       
    76 	    TBool aFieldChange, TRequestStatus& aStatus);
       
    77 	// Reads data from opened item
       
    78 	void DoReadItemL(TDes8& aBuffer);
       
    79 	// Writes data to created or replaced item
       
    80 	void DoWriteItemL(const TDesC8& aData);
       
    81 	// Commits the created or replaced item to database
       
    82 	void DoCommitItemL(TRequestStatus& aStatus);
       
    83 	// Closes the opened item
       
    84 	void DoCloseItem();
       
    85 	// Moves item in the database
       
    86 	void DoMoveItemL(TSmlDbItemUid aUid, TSmlDbItemUid aNewParent, TRequestStatus& aStatus);
       
    87 	// Deletes item from the database
       
    88 	void DoDeleteItemL(TSmlDbItemUid aUid, TRequestStatus& aStatus);
       
    89 	// Soft deletes item (if supported by plugin adapter), can be equal to DoDeleteItemL
       
    90 	void DoSoftDeleteItemL(TSmlDbItemUid aUid, TRequestStatus& aStatus);
       
    91 	// Deletes all items from the database
       
    92 	void DoDeleteAllItemsL(TRequestStatus& aStatus);
       
    93 
       
    94 	// Returns, whether data store has history info. EFalse means slow sync
       
    95 	TBool DoHasSyncHistory() const;
       
    96 	// Returns ids of items, which are added after previous synchronization
       
    97 	const MSmlDataItemUidSet& DoAddedItems() const;
       
    98 	// Returns ids of items, which are deleted after previous synchronization
       
    99 	const MSmlDataItemUidSet& DoDeletedItems() const;
       
   100 	// Returns ids of items, which are soft-deleted after previous synchronization
       
   101 	const MSmlDataItemUidSet& DoSoftDeletedItems() const;
       
   102 	// Returns ids of items, which are modified after previous synchronization
       
   103 	const MSmlDataItemUidSet& DoModifiedItems() const;
       
   104 	// Returns ids of items, which are moved after previous synchronization
       
   105 	const MSmlDataItemUidSet& DoMovedItems() const;
       
   106 	// Resets change information of items (makes all items new from DS point of view)
       
   107 	void DoResetChangeInfoL(TRequestStatus& aStatus);
       
   108 	// Commits the changes, that are sent into the remote server
       
   109 	void DoCommitChangeInfoL(TRequestStatus& aStatus, const MSmlDataItemUidSet& aItems);
       
   110 	// Commits the changes, that are sent into the remote server
       
   111 	void DoCommitChangeInfoL(TRequestStatus& aStatus);
       
   112 	
       
   113 
       
   114 private:
       
   115     TContactItemId CreateNewGroupL( const TDesC& aLabel,
       
   116             const CContactIdArray& aContactArray/*, const TDesC& aRingtone*/ );
       
   117     
       
   118     void ReplaceGroupL( TContactItemId aGroupId, const TDesC& aLabel,
       
   119             const CContactIdArray& aContactArray/*, const TDesC& aRingtone*/ );
       
   120     
       
   121     // Create and save snapshot from items on database
       
   122     void RegisterSnapshotL();
       
   123     
       
   124     void AssignString( TDes8& aDestination, const TDesC8& aSource );
       
   125     
       
   126     // Updates contacts last modified time.
       
   127     void UpdateContactLastMod( TContactItemId aContactId, const TTime& aLastModified );
       
   128     
       
   129     // Checks does group name already exists.
       
   130     TBool GroupNameExistsL( const TDesC& aLabel );
       
   131     
       
   132     // Data store states
       
   133     enum TState
       
   134         {
       
   135         EClosed = 0,
       
   136         EOpenAndWaiting,
       
   137         EContactGrpOpening,
       
   138         EContactGrpCreating,
       
   139         EContactGrpUpdating
       
   140         }; 	
       
   141         
       
   142     TState iCurrentState;    
       
   143 
       
   144     RFs                 iFs;
       
   145 	
       
   146 	CContactDatabase*   iContactsDb;
       
   147 	
       
   148 	TRequestStatus*     iCallerStatus;
       
   149 
       
   150     /**
       
   151 	* Key that is used in sorting snapshot.
       
   152 	*/
       
   153     const TKeyArrayFix  iKey;
       
   154     
       
   155     /**
       
   156 	* Change finder, used to determine db modifications.
       
   157 	*/
       
   158     CChangeFinder*      iChangeFinder;
       
   159 
       
   160     /**
       
   161 	* VCard item converter
       
   162 	*/
       
   163     CContactsGrpConverter* iConverter;
       
   164 	
       
   165     TSmlDbItemUid* iCurrentItem;
       
   166     TSmlDbItemUid  iItemToBeReplaced;
       
   167 	
       
   168 	CBufFlat*  iDataBuffer;
       
   169 	TInt       iWriterPosition;
       
   170 	TInt       iReaderPosition;
       
   171 	
       
   172 	TBool      iHasHistory;
       
   173 	
       
   174 	CNSmlDataItemUidSet* iNewItems;
       
   175     CNSmlDataItemUidSet* iDeletedItems;
       
   176     CNSmlDataItemUidSet* iUpdatedItems;
       
   177     CNSmlDataItemUidSet* iEmptyList;
       
   178 	};
       
   179 
       
   180 #endif // __CONTACTSGRPDATASTORE_H__