messagingfw/msgsrvnstore/server/inc/CMsvAttachmentManager.h
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __CMSVATTACHMENTMANAGER_H__
       
    17 #define __CMSVATTACHMENTMANAGER_H__
       
    18 
       
    19 #include <e32base.h>
       
    20 
       
    21 #include <mmsvattachmentmanager.h>
       
    22 #include <mmsvattachmentmanagersync.h>
       
    23 #include <cmsvattachment.h>
       
    24 
       
    25 class CMsvStore;
       
    26 class MMsvStoreManager;
       
    27 class CCopyOneFile;
       
    28 class RFs;
       
    29 class CMsvAttachmentRename;
       
    30 
       
    31 /**
       
    32 Provides the implementation of the Attachment API.
       
    33 
       
    34 The attachment API interface class manages all the attachment management and
       
    35 uses MMsvStoreManager to provide access to the message store to manage the physical
       
    36 attachment files and manipulate the attachment stream in the message store.
       
    37 
       
    38 @see MMsvAttachmentManager
       
    39 @internalComponent
       
    40 */
       
    41 class CMsvAttachmentManager : public CActive,
       
    42 							  public MMsvAttachmentManager,
       
    43 							  public MMsvAttachmentManagerSync
       
    44 	{
       
    45 public:
       
    46 	static CMsvAttachmentManager* NewL(CMsvStore& aStore, MMsvStoreManager& aStoreManager, const TMsvId aEntryId, RFs& aFs, TBool aReadOnly);
       
    47 	~CMsvAttachmentManager();
       
    48 	
       
    49 	void RestoreL();
       
    50 	void StoreL();
       
    51 	void HandleCommitComplete();
       
    52 	
       
    53 	void CreateShareProtectedAttachmentL(const TDesC& aFileName, RFile& aAttachmentFile, CMsvAttachment* aAttachmentInfo);
       
    54 	
       
    55 private:
       
    56 	CMsvAttachmentManager(CMsvStore& aStore, MMsvStoreManager& aStoreManager, const TMsvId aEntryId, RFs& aFs, TBool aReadOnly);
       
    57 	void ConstructL();
       
    58 	
       
    59 	TMsvAttachmentId GenerateAttachmentId();
       
    60 	TInt IndexPositionOfAttachmentL(TMsvAttachmentId aId) const;
       
    61 	void CompleteSelf();
       
    62 	void CreateAttachmentInStoreLC(TDes& aFileName, RFile& aFile, CMsvAttachment* aAttachmentInfo, TBool aIsShareProtected);
       
    63 	void DoAttachmentRenameL(TInt aIndex, const TDesC& aNewName);
       
    64 	TInt InternaliseRenameLockL();
       
    65 	void ExternaliseRenameLockL();
       
    66 		
       
    67 	// from CActive
       
    68 	void RunL();
       
    69 	void DoCancel();
       
    70 	TInt RunError(TInt aError);
       
    71 	
       
    72 	// from MMsvAttachmentManager
       
    73 	virtual void AddAttachmentL(const TDesC& aFilePath, CMsvAttachment* aAttachmentInfo, TRequestStatus& aStatus);
       
    74 	virtual void AddAttachmentL(RFile& aFileHandle, CMsvAttachment* aAttachmentInfo, TRequestStatus& aStatus);
       
    75 	virtual void AddLinkedAttachmentL(const TDesC& aFilePath, CMsvAttachment* aAttachmentInfo, TRequestStatus& aStatus);
       
    76 	virtual void AddEntryAsAttachmentL(TMsvId aEntryId, CMsvAttachment* aAttachmentInfo, TRequestStatus& aStatus);
       
    77 	virtual void CreateAttachmentL(const TDesC& aFileName, RFile& aAttachmentFile, CMsvAttachment* aAttachmentInfo, TRequestStatus& aStatus);
       
    78 	virtual void RenameAttachmentL(TInt aIndex, const TDesC& aNewName, TRequestStatus& aStatus);
       
    79 	virtual TInt AttachmentCount() const;
       
    80 	virtual CMsvAttachment* GetAttachmentInfoL(TInt aIndex);
       
    81 	virtual CMsvAttachment* GetAttachmentInfoL(TMsvAttachmentId aId);
       
    82 	virtual void ModifyAttachmentInfoL(CMsvAttachment* aAttachmentInfo, TRequestStatus& aStatus);
       
    83 	virtual RFile GetAttachmentFileL(TInt aIndex);
       
    84 	virtual RFile GetAttachmentFileL(TMsvAttachmentId aId);
       
    85 	virtual RFile GetAttachmentFileForWriteL(TInt aIndex);
       
    86 	virtual RFile GetAttachmentFileForWriteL(TMsvAttachmentId aId);
       
    87 	virtual void RemoveAttachmentL(TInt aIndex, TRequestStatus& aStatus);
       
    88 	virtual void RemoveAttachmentL(TMsvAttachmentId aId, TRequestStatus& aStatus);
       
    89 	virtual void CancelRequest();
       
    90 
       
    91 	// from MMsvAttachmentManagerSync
       
    92 	virtual void CreateAttachmentL(const TDesC& aFileName, RFile& aAttachmentFile, CMsvAttachment* aAttachmentInfo);
       
    93 	virtual void RenameAttachmentL(TInt aIndex, const TDesC& aNewName);
       
    94 	virtual void RemoveAttachmentL(TInt aIndex);
       
    95 	virtual void ModifyAttachmentInfoL(CMsvAttachment* aAttachmentInfo);
       
    96 		
       
    97 private:
       
    98 	/** The message store representing the current message entry. */
       
    99 	CMsvStore& iStore;
       
   100 	
       
   101 	/** The store manager providing access to the message store. */
       
   102 	MMsvStoreManager& iStoreManager;
       
   103 	
       
   104 	/** The current message entry that the attachment manages. */
       
   105 	const TMsvId iEntryId;
       
   106 	
       
   107 	/** A connected file server session. */
       
   108 	RFs& iFs;
       
   109 	
       
   110 	/** Array of attachments that are associated with the entry. */
       
   111 	RPointerArray<CMsvAttachment> iAttachments;
       
   112 	
       
   113 	/** A persisted value used to generate attachment Ids to assign to new attachments. */
       
   114 	TUint iIdGenerator;
       
   115 	
       
   116 	/** An array to list the attachments that are due for deletion. */
       
   117 	RPointerArray<HBufC> iDeletedAttachments;
       
   118 	
       
   119 	/** An array to list the attachment files that have been copied into the store
       
   120 		but not yet commited. */
       
   121 	RPointerArray<HBufC> iAddedAttachments;
       
   122 	
       
   123 	/** Utility for copying a single file. */
       
   124 	CCopyOneFile* iCopyOneFile;
       
   125 	
       
   126 	/** Flag indicating whether the store is Read-Only. */
       
   127 	TBool iReadOnly;
       
   128 	
       
   129 	/** Caller's request status to complete. */
       
   130 	TRequestStatus* iReportStatus;
       
   131 	
       
   132 	/** An array to manage the renaming of attachments. */
       
   133 	RPointerArray<CMsvAttachmentRename> iRenamed;
       
   134 	};
       
   135 
       
   136 #endif // __CMSVATTACHMENTMANAGER_H__