messagingapp/msgutils/unidatamodel/unimmsdataplugin/inc/UniTextObject.h
changeset 25 84d9eb65b26f
parent 23 238255e8b033
child 27 e4592d119491
child 37 518b245aa84c
child 79 2981cb3aa489
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
     1 /*
       
     2 * Copyright (c) 2005 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: 
       
    15 *       CUniTextObject, Storage for single text attachment in presentation.
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef __UNITEXTOBJECT_H
       
    22 #define __UNITEXTOBJECT_H
       
    23 
       
    24 // INCLUDES
       
    25 
       
    26 #include <e32std.h>
       
    27 #include <cmsvattachment.h>
       
    28 #include <UniObject.h>
       
    29 
       
    30 // CONSTANTS
       
    31 
       
    32 // MACROS
       
    33 
       
    34 // FORWARD DECLARATIONS
       
    35 class CUniMimeInfo;
       
    36 class CMsgTextInfo;
       
    37 class CBaseMtm;
       
    38 class CUniDataUtils;
       
    39 class CEikRichTextEditor;
       
    40 
       
    41 // DATA TYPES
       
    42 
       
    43 // FUNCTION PROTOTYPES
       
    44 
       
    45 // CLASS DECLARATION
       
    46 
       
    47 /**
       
    48 * CUniTextObject, Storage for single text attachment in presentation.
       
    49 *
       
    50 * @lib UniDataModel.lib
       
    51 * @since 3.1
       
    52 */
       
    53 class CUniTextObject : public CUniObject
       
    54     {
       
    55     public:  // New methods
       
    56 
       
    57         /**
       
    58         * Factory method that creates this object
       
    59         * from an attachment.
       
    60         *
       
    61         * @since    3.1
       
    62         * @param    aMtm    IN reference to client mtm
       
    63         * @param    aMedia  IN initialized media info object - takes ownership!
       
    64         * @param    aManager        IN reference to attachment manager
       
    65         * @param    aAttachmentId   IN id of the attachment from
       
    66         *                           which to create the object
       
    67         * @return   Pointer to instance in cleanup stack
       
    68         */
       
    69         static CUniTextObject* NewLC(
       
    70             RFs& aFs,
       
    71             CBaseMtm& aMtm,
       
    72             CUniDataUtils& aData,
       
    73             CMsgTextInfo* aMedia,
       
    74             MMsvAttachmentManager& aManager,
       
    75             CMsvAttachment& aAttachment );
       
    76 
       
    77         /**
       
    78         * Factory method that creates this object
       
    79         * from an attachment.
       
    80         *
       
    81         * @since    3.1
       
    82         * @param    aMtm    IN reference to client mtm
       
    83         * @param    aMedia  IN initialized media info object - takes ownership!
       
    84         * @param    aManager        IN reference to attachment manager
       
    85         * @param    aAttachmentId   IN id of the attachment from
       
    86         *                           which to create the object
       
    87         * @return   Pointer to instance
       
    88         */
       
    89         static CUniTextObject* NewL(
       
    90             RFs& aFs,
       
    91             CBaseMtm& aMtm,
       
    92             CUniDataUtils& aData,
       
    93             CMsgTextInfo* aMedia,
       
    94             MMsvAttachmentManager& aManager,
       
    95             CMsvAttachment& aAttachment );
       
    96 
       
    97         /**
       
    98         * Factory method that creates this object
       
    99         * from a file.
       
   100         *
       
   101         * @since    3.1
       
   102         * @param    aData   IN reference to MsgData object
       
   103         * @param    aMedia  IN initialized media info object - takes ownership!
       
   104         * @return   Pointer to instance in cleanup stack
       
   105         */
       
   106         static CUniTextObject* NewLC(
       
   107             RFs& aFs,
       
   108             CBaseMtm& aMtm,
       
   109             CUniDataUtils& aData,
       
   110             CMsgTextInfo* aMedia );
       
   111 
       
   112         /**
       
   113         * Factory method that creates this object
       
   114         * from a file.
       
   115         *
       
   116         * @since    3.1
       
   117         * @param    aData   IN reference to MsgData object
       
   118         * @param    aMedia  IN initialized media info object - takes ownership!
       
   119         * @return   Pointer to instance
       
   120         */
       
   121         static CUniTextObject* NewL(
       
   122             RFs& aFs,
       
   123             CBaseMtm& aMtm,
       
   124             CUniDataUtils& aData,
       
   125             CMsgTextInfo* aMedia );
       
   126 
       
   127         /**
       
   128         * Factory method that creates this object
       
   129         * from a text buffer.
       
   130         *
       
   131         * @since    3.1
       
   132         * @param    aData   IN reference to MsgData object
       
   133         * @param    aTextEditor IN text buffer from
       
   134         *                       which to create the object
       
   135         * @return   Pointer to instance in cleanup stack
       
   136         */
       
   137         static CUniTextObject* NewLC(
       
   138             RFs& aFs,
       
   139             CBaseMtm& aMtm,
       
   140             CUniDataUtils& aData,
       
   141             CEikRichTextEditor* aTextEditor );
       
   142 
       
   143         /**
       
   144         * Factory method that creates this object
       
   145         * from a text buffer.
       
   146         *
       
   147         * @since    3.1
       
   148         * @param    aData   IN reference to MsgData object
       
   149         * @param    aTextEditor IN text buffer from
       
   150         *                       which to create the object
       
   151         * @return   Pointer to instance
       
   152         */
       
   153         static CUniTextObject* NewL(
       
   154             RFs& aFs,
       
   155             CBaseMtm& aMtm,
       
   156             CUniDataUtils& aData,
       
   157             CEikRichTextEditor* aTextEditor );
       
   158 
       
   159         /**
       
   160         * Destructor
       
   161         *
       
   162         * @since    3.1
       
   163         */
       
   164         virtual ~CUniTextObject();
       
   165 
       
   166         /*
       
   167         * Size
       
   168         * Inherited from CUniObject
       
   169         *
       
   170         * @since    3.1
       
   171         * @param    aWithoutHeaders IN if ETrue include MIME headers' sizes
       
   172         *                           if EFalse count only file sizes
       
   173         * @return   Size of the object in bytes
       
   174         */
       
   175         virtual TInt Size( TBool aWithoutHeaders = ETrue );
       
   176 
       
   177         /*
       
   178         * SynchronizeSize
       
   179         * Count the accurate size of the text object if it would
       
   180         * be saved as a file.
       
   181         * Useful for UTF-8 text
       
   182         *
       
   183         *
       
   184         * @since    3.1
       
   185         * @return   Size of the object in bytes
       
   186         */
       
   187         TInt SynchronizeSize();
       
   188 
       
   189         /*
       
   190         * Text
       
   191         *
       
   192         * @since    3.1
       
   193         * @return   Pointer to text editor.
       
   194         */
       
   195         inline CEikRichTextEditor* Text() const;
       
   196 
       
   197         /*
       
   198         * SetText
       
   199         * Set text to save
       
   200         *
       
   201         * @since    3.1
       
   202         * @param    aTextEditor     IN pointer to text editor
       
   203         */
       
   204         inline void SetText( CEikRichTextEditor* aTextEditor );
       
   205 
       
   206     protected:
       
   207 
       
   208         /**
       
   209         * Constructor.
       
   210         *
       
   211         * @since    3.1
       
   212         */
       
   213         CUniTextObject(
       
   214             RFs& aFs,
       
   215             CBaseMtm& aMtm,
       
   216             CUniDataUtils& aData,
       
   217             CMsgTextInfo* aMedia );
       
   218 
       
   219         /**
       
   220         * 2nd phase constructor.
       
   221         *
       
   222         * @since    3.1
       
   223         */
       
   224         void ConstructL();
       
   225 
       
   226         /**
       
   227         * 2nd phase constructor.
       
   228         *
       
   229         * @since    3.1
       
   230         * @param    aData   IN reference to MsgData object
       
   231         * @param    aTextEditor IN text buffer from
       
   232         *                       which to create the object
       
   233         */
       
   234         void ConstructFromTextL( CEikRichTextEditor* aTextEditor );
       
   235 
       
   236         /**
       
   237         * Create file name for the object
       
   238         *
       
   239         * @since    3.1
       
   240         * @param    aBuffer IN text buffer from which to create file name
       
   241         * @param    aFileName   OUT created file name (without path)
       
   242         * @param    aData   IN reference to MsgData object
       
   243         */
       
   244         void CreateFileName( TFileName& aFileName );
       
   245 
       
   246         void InitializeTextSaveL();
       
   247         void CreateTextAttachmentL();
       
   248         void WriteToFileL();
       
   249 
       
   250         /**
       
   251         * Save
       
   252         * Inherited from CUniObject
       
   253         */
       
   254         virtual void Save(
       
   255             MUniObjectSaveObserver& aObserver,
       
   256             CMsvAttachment::TMsvAttachmentType aSaveType );
       
   257 
       
   258         /**
       
   259         * DoSaveL
       
   260         * Inherited from CUniObject
       
   261         */
       
   262         virtual void DoSaveL();
       
   263 
       
   264     protected: // data
       
   265 
       
   266         enum TMsgTextObjectSaveState
       
   267             {
       
   268             ETextSavingIdle,
       
   269             ETextCreatingAttachment,
       
   270             ETextWritingToFile
       
   271             };
       
   272 
       
   273         CEikRichTextEditor* iTextEditor;
       
   274         TInt iSyncCounter;
       
   275         TInt iSyncSize;
       
   276         TInt iSyncLength;
       
   277         TInt iPrevLength;
       
   278 
       
   279         TInt iTextSaveState;
       
   280         RFile* iEditFile;
       
   281     };
       
   282 
       
   283 #include <UniTextObject.inl>
       
   284 
       
   285 #endif // __UNITEXTOBJECT_H