// MSVENTRY.H
//
// Copyright (c) 1998 Symbian Ltd.  All rights reserved.
//

#if !defined(__MSVENTRY_H__)
#define __MSVENTRY_H__

#if !defined(__E32BASE_H__)
#include <e32base.h>
#endif

#if !defined(__MSVSTORE_H__)
#include <msvstore.h>
#endif

//////////////////////////////////////
// Forward declarations
class CMsvStore;

//**********************************
// CMsvServerEntry
//**********************************
//
//
//

class CMsvServerEntry : public CBase, public MMsvStoreObserver
	{
public:
	IMPORT_C static CMsvServerEntry* NewL(CMsvServer& aServer, TMsvId aId);
	~CMsvServerEntry();
	//
	// Set and get the current context
	IMPORT_C TInt SetEntry(TMsvId aId);
	inline const TMsvEntry& Entry() const;
	IMPORT_C TMsvId OwningService() const;
	//
	// current entry only functions
	IMPORT_C TInt ChangeEntry(const TMsvEntry& aEntry);
	IMPORT_C TInt GetFilePath(TFileName& aFilePath);
	//
	// child entry only functions
	IMPORT_C TInt CreateEntry(TMsvEntry& aEntry);
	IMPORT_C TInt DeleteEntry(TMsvId aId);
	IMPORT_C TInt DeleteEntry(TMsvId aId, CMsvEntrySelection& aDeletedEntries);
	IMPORT_C TInt MoveEntry(TMsvId aId, TMsvId aDestination); // only works moving within a service
	IMPORT_C TInt ChangeAttributes(const CMsvEntrySelection& aSelection, TUint aSetAttributes, TUint aClearAttributes);
	//
	// read and write the store associated with the context
	IMPORT_C CMsvStore* ReadStoreL();
	IMPORT_C CMsvStore* EditStoreL();
	//
	// List the children of the context 
	inline const TMsvSelectionOrdering& Sort();
	inline void SetSort(TMsvSelectionOrdering& aOrdering);
	inline void SetMtm(TUid aMtm);
	IMPORT_C TInt GetChildren(CMsvEntrySelection& aSelection);
	//
	// Spawns a new CMsvServerEntry object
	IMPORT_C CMsvServerEntry* NewEntryL(TMsvId aId);
	// 
	// from MMsvStoreObserver
	void HandleStoreEvent(MMsvStoreObserver::TMsvStoreEvent aEvent, TMsvId aId);
	//
	IMPORT_C void MoveEntryL(TMsvId aId, TMsvId aDestination, TRequestStatus& aObserverStatus);
	IMPORT_C void MoveEntryCompleted(TInt aError);
	IMPORT_C void CancelMoveEntry();
protected:
	CMsvServerEntry(CMsvServer& aIndex);
	void ConstructL(TMsvId aId);
	//
private:
	TInt IncreaseBufferSizes(TInt aNewDescriptionSize, TInt aNewDetailsSize);
	TBool IsAChild(TMsvId aId);
	void DoMoveEntryL(TMsvId aId, TMsvId aDestination);
	void DoChangeAttributesL(const CMsvEntrySelection& aSelection, TUint aSetAttributes, TUint aClearAttributes, CMsvEntrySelection*& aChangedEntries);
	void DoDeleteEntryL(TMsvId aId, CMsvEntrySelection& aDeletedEntries, CMsvEntrySelection*& aMovedEntries);
	//
private:
	TBool iLockedStore;
	TMsvSelectionOrdering iOrdering;
	TMsvEntry iEntry;
	HBufC* iDescription;
	HBufC* iDetails;
	CMsvServer& iServer;
	CMsvStore* iStore;
	TUid iMtm;
	TBool iMandatoryStore;
	CMsvMove* iMove;
	TMsvId iMoveSource;
	TMsvId iMoveTarget;
	};


#include "msventry.inl"

#endif