messagingappbase/sendui/mmsdirectupload/inc/MDUCreateAndSend.h
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:   Creates and sends as many MMS messages as there are files
       
    15 *                to be send. Oversize JPEG images are compressed to fit into
       
    16 *                message.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #ifndef MDUCREATEANDSEND_H
       
    24 #define MDUCREATEANDSEND_H
       
    25 
       
    26 //  INCLUDES
       
    27 #include    <e32base.h>
       
    28 #include    <badesca.h>
       
    29 #include    <AknProgressDialog.h>
       
    30 #include    <apmstd.h>
       
    31 #include    <sendas2.h>
       
    32 #include    <txtmrtsr.h>
       
    33 
       
    34 #include    <UniImageProcessor.h>
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 // MACROS
       
    39 
       
    40 // DATA TYPES
       
    41 
       
    42 // FUNCTION PROTOTYPES
       
    43 class TMsvSessionEvent;
       
    44 class CSendUiDataUtils;
       
    45 class CSendUiAttachment;
       
    46 class CSendUiSingleton;
       
    47 
       
    48 // CLASS DECLARATION
       
    49 /**
       
    50 *  Callback mixin class used by CMDUCreateAndSend
       
    51 *  @lib MmsDirectUpload
       
    52 *  @since Series 60 2.8
       
    53 */
       
    54 class MMDUCreateAndSendCallback
       
    55     {
       
    56     public:
       
    57     
       
    58         /**
       
    59         * Callback function called when message creation is completed.
       
    60         * If an error occured, it can be queried with
       
    61         * CMDUCreateAndSend::Error() function.
       
    62         * @since Series 60 2.8
       
    63         * @return None.
       
    64         */
       
    65         virtual void MessagesReady() = 0;
       
    66     };
       
    67 
       
    68 /**
       
    69 *  Creates and sends as many MMS messages as there are files to be send.
       
    70 *  Oversize JPEG images are compressed to fit into message.
       
    71 *
       
    72 *  @lib MmsDirectUpload
       
    73 *  @since Series 60 2.8
       
    74 */
       
    75 class CMDUCreateAndSend : public CActive,
       
    76                           public MProgressDialogCallback,
       
    77                           public MUniImageProcessorCallback
       
    78 
       
    79     {
       
    80 
       
    81     public:  // Constructor and destructor
       
    82 
       
    83         /**
       
    84         * Two-phased constructor.
       
    85         * @param aCallback Callback implementation.
       
    86         */
       
    87         static CMDUCreateAndSend* NewL( 
       
    88             CCoeEnv& aCoeEnv,
       
    89             CSendUiSingleton& aSingleton,
       
    90             MMDUCreateAndSendCallback* aCallback );
       
    91 
       
    92         /**
       
    93         * Two-phased constructor.
       
    94         * @param aCallback Callback implementation.
       
    95         */
       
    96         static CMDUCreateAndSend* NewLC(
       
    97             CCoeEnv& aCoeEnv,
       
    98             CSendUiSingleton& aSingleton,
       
    99             MMDUCreateAndSendCallback* aCallback );
       
   100 
       
   101         /**
       
   102         * Destructor.
       
   103         */
       
   104         virtual~CMDUCreateAndSend();
       
   105 
       
   106     public: // New functions
       
   107 
       
   108         /**
       
   109         * Creates and sends as many MMS messages as there are files
       
   110         * to be send. Oversize JPEG images are compressed to fit into
       
   111         * message. Asynchronous operation.
       
   112         *
       
   113         * @since Series 60 2.8
       
   114         * @param aAttachments, Files to be send.
       
   115         * @param aToAddress, Recipient address.
       
   116         * @param aToAlias, Alias for recipient.
       
   117         * @param aMaxMsgSize, Maximum size of the created MMS.
       
   118         * @return None.
       
   119         */
       
   120         void CreateAndSendL(
       
   121             CArrayPtrFlat<CSendUiAttachment>* aAttachments,
       
   122             const TDesC& aToAddress,
       
   123             const TDesC& aToAlias,
       
   124             TInt aMaxMsgSize );
       
   125         
       
   126         /**
       
   127         * Error.
       
   128         * @since Series 60 2.8
       
   129         * @return Symbian wide error code.
       
   130         */
       
   131         inline TInt Error() const;
       
   132         
       
   133         /**
       
   134         * Can be used to query compression results.
       
   135         * Oversized JPEG images are compressed to fit in MMS.
       
   136         * @since Series 60 2.8
       
   137         *
       
   138         * @param aCompressionOk, Return value contains amount of succesfully
       
   139         *        compressed JPEG images.
       
   140         * @param aCompressionFail, Return value contains amount of failed
       
   141         *        compression attempts.              
       
   142         * @return None.
       
   143         */
       
   144         inline void CompressionResults(
       
   145             TInt& aCompressionOk,
       
   146             TInt& aCompressionFail ) const;
       
   147             
       
   148     private: // Constructor
       
   149 
       
   150         /**
       
   151         * C++ default constructor.
       
   152         */
       
   153         CMDUCreateAndSend( CCoeEnv& aCoeEnv, CSendUiSingleton& aSingleton, MMDUCreateAndSendCallback* aCallback );
       
   154 
       
   155         /**
       
   156         * By default Symbian 2nd phase constructor is private.
       
   157         */
       
   158         void ConstructL();
       
   159 
       
   160     private:  // Functions from base classes
       
   161 
       
   162         /**
       
   163         * From CActive
       
   164         * @since Series 60 2.8
       
   165         * @return None.
       
   166         */ 
       
   167         void RunL();
       
   168         
       
   169         /**
       
   170         * From CActive
       
   171         * @since Series 60 2.8
       
   172         * @return None.
       
   173         */        
       
   174         void DoCancel();
       
   175     
       
   176         /**
       
   177         * From CActive
       
   178         * Handles a leave occurring in the request completion
       
   179         * event handler RunL().
       
   180         * @since Series 60 2.8
       
   181         * @param aError Leave code.
       
   182         * @return 
       
   183         */   
       
   184         TInt RunError( TInt aError );
       
   185 
       
   186         /**
       
   187         * From MProgressDialogCallback
       
   188         * Callback method
       
   189         * Get's called when a dialog is dismissed.
       
   190         * @since Series 60 2.8
       
   191         * @return None.
       
   192         */
       
   193         void DialogDismissedL( TInt aButtonId );
       
   194         
       
   195         /**
       
   196         * From MUniImageProcessorCallback.
       
   197         * Callback to tell that compression is ready.
       
   198         * @since 3.2
       
   199         * @param aBitmapSize Dimensions of result bitmap - not interested.
       
   200         * @param aFileSize   Size of the compressed image
       
   201         * @param aCompressed ETrue if compressed, EFalse if only scaled - not interested.
       
   202         * @return None.
       
   203         */
       
   204         void ImageProcessingReady( TSize aBitmapSize, TInt aFileSize, TBool aCompressed );
       
   205 
       
   206     private:  // New functions
       
   207 
       
   208         /**
       
   209         * Starts message entry creation.
       
   210         * @since Series 60 3.0
       
   211         * @return None.
       
   212         */
       
   213         void CreateMessageAndSetDataL();
       
   214 
       
   215         /**
       
   216         * Checks if file is oversized JPEG image.
       
   217         * @since Series 60 2.8
       
   218         * @return ETrue if image should be compress, otherwise EFalse.
       
   219         */
       
   220         TBool IsCompressionNeededL();
       
   221 
       
   222         /**
       
   223         * Compress oversized JPEG image.
       
   224         * @since Series 60 2.8
       
   225         * @return None.
       
   226         */
       
   227         void CompressImageL();
       
   228 
       
   229         /**
       
   230         * Add attachment to message.
       
   231         * @since Series 60 2.8
       
   232         * @return None.
       
   233         */
       
   234         void AddAttachmentL();
       
   235 
       
   236         /**
       
   237         * Sends message.
       
   238         * @since Series 60 2.8
       
   239         * @return None.
       
   240         */
       
   241         void SendMessage();
       
   242 
       
   243         /**
       
   244         * Deletes temporary compressed image file if needed and 
       
   245         * updates progress bar.
       
   246         * @since Series 60 2.8
       
   247         * @return None.
       
   248         */
       
   249         void FinalizeL();
       
   250             
       
   251         /**
       
   252         * Creates temp file to ram drive d:\. Original filename is used.
       
   253         * Note: handle to created file is left open.
       
   254         * @since Series 60 3.0
       
   255         * @param aSourceFile File handle to the original file.
       
   256         * @param aTargetFile Return value contains the target file handle.
       
   257         * @return None.
       
   258         */
       
   259         void CreateTempFileL(
       
   260             RFile& aSourceFile,
       
   261             RFile& aTargetFile );
       
   262 
       
   263         /**
       
   264         * Shows progress bar to user. Progress bar indicates the total amount
       
   265         * of messages to be created and the current situation.
       
   266         * @since Series 60 2.8
       
   267         * @param aFinalValue Final value for the progress bar.
       
   268         * @return None.
       
   269         */
       
   270         void CreateProgressNoteL( TInt aFinalValue );
       
   271 
       
   272         /**
       
   273         * Updates the progress bar text.
       
   274         * @since Series 60 2.8
       
   275         * @param aFinalValue Final value for the progress bar.
       
   276         * @return None.
       
   277         */
       
   278         void UpdateProgressTextL( TInt aFinalValue );
       
   279 
       
   280         /**
       
   281         * Checks that message server is up and running.
       
   282         * Also checks that message store is available.
       
   283         * @since Series 60 2.8
       
   284         * @return TBool ETrue if session to message server is ok and message
       
   285         *         store is available, otherwise EFalse.
       
   286         */
       
   287         TBool CheckMmsServiceAvailabilityL();
       
   288         
       
   289         /**
       
   290         * Shows requested information note.
       
   291         * @since Series 60 3.2
       
   292         */
       
   293         //void ShowInformationNoteL( TUint aTextResourceId ) const;
       
   294 
       
   295         /**
       
   296         * Resets the internal state.
       
   297         * @return None.
       
   298         */
       
   299         void Reset();
       
   300         
       
   301         /**
       
   302         * Complete request.
       
   303         * @return None.
       
   304         */
       
   305         void CompleteSelf();
       
   306 
       
   307     private: //Data
       
   308     
       
   309         enum TInternalState
       
   310             {
       
   311             EStateIdle       = 0,
       
   312             EStateCreateMessage,
       
   313             EStateImageCompression,
       
   314             EStateAddAttachment,
       
   315             EStateSendMessage,
       
   316             EStateFinalize,
       
   317             EStateReady
       
   318             };
       
   319 
       
   320         // Session to SendAs server. Owned.
       
   321         RSendAs                                 iSendAsSession;
       
   322 
       
   323         // Offers message creation and sending services. Owned.
       
   324         RSendAsMessage                          iSendAsMessage;
       
   325 
       
   326         // Progress dialog for creating messages. Owned.
       
   327         CAknProgressDialog*                     iProgressDialog;
       
   328 
       
   329         // Progress info.
       
   330         CEikProgressInfo*                       iProgressInfo;
       
   331 
       
   332         // Attachments for the messages. Not owned.
       
   333         const CArrayPtrFlat<CSendUiAttachment>* iAttachments;
       
   334 
       
   335         CCoeEnv&                                iCoeEnv;
       
   336 
       
   337         CSendUiSingleton&                       iSingleton;
       
   338 
       
   339         // Reference to an open fileserver session
       
   340         RFs& iFs;
       
   341 
       
   342         MMDUCreateAndSendCallback*              iCallback;
       
   343 
       
   344         // Image compressor. Owned.
       
   345         CUniImageProcessor*                     iCompressor;
       
   346 
       
   347         HBufC*                                  iToAddress;
       
   348 
       
   349         HBufC*                                  iToAlias;
       
   350 
       
   351         RFile                                   iCompressedImage;
       
   352         TFileName                               iCompressedImagePath;
       
   353         TDataType                               iAttachmentType;
       
   354         TInt                                    iState;
       
   355         TInt                                    iError;
       
   356         TInt                                    iProgressCount;
       
   357         TInt                                    iMessageCount;
       
   358         TInt                                    iMaxMsgSize;
       
   359         TInt                                    iAttachmentSize;
       
   360         TInt                                    iCompressionOk;
       
   361         TInt                                    iCompressionFail;        
       
   362         TBool                                   iImageCompressed;
       
   363         TBool                                   iMessageCreated;
       
   364         
       
   365     };
       
   366 
       
   367 // ==========================================================
       
   368 
       
   369 inline TInt CMDUCreateAndSend::Error() const
       
   370     {
       
   371     return iError;
       
   372     }
       
   373 
       
   374 inline void CMDUCreateAndSend::CompressionResults(
       
   375     TInt& aCompressionOk,
       
   376     TInt& aCompressionFail ) const
       
   377     {
       
   378     aCompressionOk = iCompressionOk;
       
   379     aCompressionFail = iCompressionFail;
       
   380     }
       
   381 
       
   382 #endif      // MDUCREATEANDSEND_H