messagingfw/msgsrvnstore/server/inc/CMsvPlainBodyText.h
changeset 22 bde600d88860
parent 0 8e480a14352b
equal deleted inserted replaced
21:08008ce8a6df 22:bde600d88860
       
     1 // CMSVPLAINBODYTEXT.H
       
     2 
       
     3 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 // All rights reserved.
       
     5 // This component and the accompanying materials are made available
       
     6 // under the terms of "Eclipse Public License v1.0"
       
     7 // which accompanies this distribution, and is available
       
     8 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     9 //
       
    10 // Initial Contributors:
       
    11 // Nokia Corporation - initial contribution.
       
    12 //
       
    13 // Contributors:
       
    14 //
       
    15 // Description:
       
    16 //
       
    17 
       
    18 #ifndef __CMSVPLAINBODYTEXT_H__
       
    19 #define __CMSVPLAINBODYTEXT_H__
       
    20 
       
    21 
       
    22 #include <msvstore.h>
       
    23 #include <mentact.h>
       
    24 #include <charconv.h>
       
    25 
       
    26 class CMsvStore;
       
    27 class CRichText;
       
    28 class CParaFormatLayer;
       
    29 class CCharFormatLayer;
       
    30 class CCnvCharacterSetConverter;
       
    31 
       
    32 /**
       
    33 This class encapsulates plainbody text information for storage within the
       
    34 Message Store.It also populates a CRichText object with the 8 bit data
       
    35 decoded to the specified character set.If a character set is not specified,
       
    36 then the default character set is used.
       
    37 
       
    38 @publishedAll
       
    39 @released
       
    40 */
       
    41 class CMsvPlainBodyText : public CMsgActive
       
    42 	{
       
    43 public:
       
    44 	static CMsvPlainBodyText* NewL(MMsvStoreManager& aMsvStoreManager, CMsvStore& aStore, TBool aIs8Bit, TUint aCharsetId, TUint aDefaultCharsetId, TMsvId aMessageId, RFs& aFs);
       
    45 	static CMsvPlainBodyText* NewL(MMsvStoreManager& aMsvStoreManager, CMsvStore& aStore, TMsvId aMessageId, RFs& aFs, TInt aChunkLength);
       
    46 
       
    47 	IMPORT_C ~CMsvPlainBodyText();
       
    48 
       
    49 	IMPORT_C void StoreChunkL(const TDesC8& aChunk, TRequestStatus& aStatus);
       
    50 	IMPORT_C void StoreChunkL(const TDesC8& aChunk);
       
    51 
       
    52 	IMPORT_C void StoreChunkL(const TDesC16& aChunk, TRequestStatus& aStatus);
       
    53 	IMPORT_C void StoreChunkL(const TDesC16& aChunk);
       
    54 
       
    55 	IMPORT_C void StoreRichTextAsPlainTextL(CRichText& aRichText);
       
    56 
       
    57 	IMPORT_C void CommitL();
       
    58 
       
    59 	IMPORT_C void NextChunkL(TDes8& aChunk, TRequestStatus& aStatus);
       
    60 	IMPORT_C void NextChunkL(TDes8& aChunk);
       
    61 
       
    62 	IMPORT_C void NextChunkL(TDes16& aChunk, TRequestStatus& aStatus);
       
    63 	IMPORT_C void NextChunkL(TDes16& aChunk);
       
    64 
       
    65 	IMPORT_C void PreviousChunkL(TDes8& aChunk, TRequestStatus& aStatus);
       
    66 	IMPORT_C void PreviousChunkL(TDes8& aChunk);
       
    67 
       
    68 	IMPORT_C void PreviousChunkL(TDes16& aChunk, TRequestStatus& aStatus);
       
    69 	IMPORT_C void PreviousChunkL(TDes16& aChunk);
       
    70 
       
    71 
       
    72 	IMPORT_C void SetCharacterSetL(const TUint aCharset);
       
    73 	IMPORT_C TUint CharacterSet();
       
    74 	IMPORT_C TUint DefaultCharacterSet();
       
    75 
       
    76  	IMPORT_C TInt Size();
       
    77 
       
    78 private:
       
    79 	CMsvPlainBodyText(MMsvStoreManager& aMsvStoreManager, CMsvStore& aStore, TBool aIs8Bit, TUint aCharsetId, TUint aDefaultCharsetId, TMsvId aMessageId, RFs& aFs);
       
    80 	void ConstructWriteL();
       
    81 
       
    82 	CMsvPlainBodyText(MMsvStoreManager& aMsvStoreManager, CMsvStore& aStore,TMsvId aMessageId, RFs& aFs,TInt aChunkLength);
       
    83 	void ConstructReadL();
       
    84 
       
    85 	void PrepareToConvertL();
       
    86 	void ConvertChunkToUnicodeForStoreL(const TDesC8& aChunk);
       
    87 	TInt ConvertChunkToUnicodeForRestoreL();
       
    88 	void ExtractNextChunkFromRichText(TDes16& aChunk);
       
    89 	void ExtractPreviousChunkFromRichText(TDes16& aChunk);
       
    90 	void RevertL();
       
    91 	void DoRunL();
       
    92 	void DoComplete();
       
    93 	void DoCancel();
       
    94 
       
    95 private:
       
    96 	/** To access APIs related to RFile operations.*/
       
    97 	MMsvStoreManager& 			  iMsvStoreManager;
       
    98 	CMsvStore& 					  iStore;
       
    99 	/** Indicates whether to store text as 8 bit or 16 bit.*/
       
   100 	TBool 						  iIs8Bit;
       
   101 	/** The charset of the body text*/
       
   102 	TUint 						  iCharsetId;
       
   103  	TUint 					 	  iDefaultCharsetId;
       
   104 
       
   105  	/** The RFile Path.*/
       
   106 	HBufC*	 					  iFilePath;
       
   107   	TMsvId 						  iMessageId;
       
   108 	RFs& 						  iFSession;
       
   109 
       
   110 	/** The RFile to which body text is written.*/
       
   111 	RFile 						  iFile;
       
   112 	/** Character converter for 8 to 16 bit conversion.*/
       
   113 	CCnvCharacterSetConverter* 	  iConverter;
       
   114 	CRichText* 					  iRichText;
       
   115 	CParaFormatLayer* 			  iParaLayer;
       
   116 	CCharFormatLayer* 			  iCharLayer;
       
   117 	TInt 						  iReadChunkLength;
       
   118 	/** Temporary buffer created to Store chunk while it is being written aynchronously.*/
       
   119 	RBuf16	 					  iTempChunk16;
       
   120 	/** Buffer used to read data from RFile.*/
       
   121 	RBuf8 						  iRfileReadBuf8;
       
   122 	/** Pointer to 8-bit buffer that needs to be written to RFile.*/
       
   123 	TPtrC8 						  iRfileWritePtr8;
       
   124 	/** The position from where to extract data in CRichText*/
       
   125 	TInt 						  iPos;
       
   126 	/** Contains the size of the chunk that will be read or write in the RFile*/
       
   127 	TInt 					 	  iChunkMaxLength;
       
   128 	/** Contains the remaining unconverted Unicode Data*/
       
   129 	HBufC8* 					  iRemainingUnConvertedData;
       
   130 	/** Array that stores the start positions of each chunk,in Rfile*/
       
   131 	RArray<TInt> 			 	  iStartPosOfEachChunkInFile;
       
   132 	/** Contains the start position of the next chunk*/
       
   133 	TInt 						  iStartPosOfNextChunk;
       
   134 	/** Contains the remaining converted Unicode Data*/
       
   135 	RBuf16						  iRemainingConvertedData;
       
   136 	/** Pointer to a 16 bit chunk that is being read from the store.*/
       
   137 	TDes16*	 					  iChunk16;
       
   138 	/** Pointer to a 8 bit chunk that is being read from the store.*/
       
   139 	TDes8* 						  iChunk8;
       
   140 	/** Indicates whether the Rfile is commited or not.*/
       
   141 	TBool 						  iIsCommitted;
       
   142 
       
   143 	/** Indicates whether the chunk being read is last.*/
       
   144 	TBool 						  iIsLastChunk;
       
   145 	/** Indicates whether call to DoRunl was initiated by PreviousChunkL method.*/
       
   146 	TBool 						  iPrevChunk;
       
   147 	/** Indicates whether call to DoRunl was initiated by 8 bit PreviousChunkL and NextChunkL methods.*/
       
   148 	TBool 						  iRetrieving8bit;
       
   149 	/** Enum indicating if RFile is being written or read */
       
   150 	enum {EMsvFileReading, EMsvFileWriting} iMsvFileStatus;
       
   151 	CCnvCharacterSetConverter::TAvailability iAvailable;
       
   152 	//Containes current position of the Rfile
       
   153 	TInt 						 iCurrentFilePos;
       
   154 	};
       
   155 
       
   156 #endif//__CMSVPLAINBODYTEXT_H__