emailuis/emailui/inc/FreestyleEmailUiHtmlViewerContainer.h
branchRCL_3
changeset 64 3533d4323edc
child 70 968773a0b6ef
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2007 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:  CFsEmailUiHtmlViewerContainer class definition
       
    15 *
       
    16 */
       
    17  
       
    18 
       
    19 
       
    20 #ifndef __FREESTYLEEMAILUI_HTML_VIEWER_CONTAINER_H__
       
    21 #define __FREESTYLEEMAILUI_HTML_VIEWER_CONTAINER_H__
       
    22 
       
    23 
       
    24 #include <coecntrl.h>
       
    25 #include <brctlspecialloadobserver.h>
       
    26 #include <brctllinkresolver.h>
       
    27 
       
    28 #include "FreestyleEmailUiAknStatusIndicator.h"
       
    29 #include "FreestyleEmailDownloadInformationMediator.h"
       
    30 #include "freestyleemailcenrepkeys.h"
       
    31 #include "OverlayControl.h"
       
    32 
       
    33 class CFSMailMessage;
       
    34 class CFreestyleEmailUiAppUi;
       
    35 class CFreestyleMessageHeaderURLEventHandler;
       
    36 struct TAttachmentData;
       
    37 class CFsEmailUiHtmlViewerContainer;
       
    38 class MTouchFeedback;
       
    39 class CFindItemEngine;
       
    40 
       
    41 /**
       
    42  * Single key listener
       
    43  */
       
    44 class CEUiHtmlViewerSettingsKeyListener : public CActive
       
    45     {
       
    46 public:
       
    47     /**
       
    48      * Observer interface for key value changes
       
    49      */
       
    50     class MObserver
       
    51         {
       
    52     public:
       
    53         /**
       
    54          * Called when key value changes
       
    55          */
       
    56         virtual void KeyValueChangedL( TUint32 aKey ) = 0;
       
    57 
       
    58         /**
       
    59          * Listener can query repository instance using this method. No need
       
    60          * to create own repository instance OR to store repository reference.
       
    61          */
       
    62         virtual CRepository& Repository() = 0;
       
    63         };
       
    64 public:
       
    65     /**
       
    66      * Constructor
       
    67      */
       
    68     CEUiHtmlViewerSettingsKeyListener( MObserver& aObserver, TUint32 aKey );
       
    69 
       
    70     /**
       
    71      * Destructor
       
    72      */
       
    73     ~CEUiHtmlViewerSettingsKeyListener();
       
    74 
       
    75 private:
       
    76     /**
       
    77      * Start listening value changes
       
    78      */
       
    79     void StartListening();
       
    80 
       
    81 private: // from CActive
       
    82     /**
       
    83      * @see CActive::RunL
       
    84      */
       
    85     void RunL();
       
    86 
       
    87     /**
       
    88      * @see CActive::DoCancel
       
    89      */
       
    90     void DoCancel();
       
    91 
       
    92 private:
       
    93     /**
       
    94      * Key observer
       
    95      */
       
    96     MObserver& iObserver;
       
    97 
       
    98     /**
       
    99      * Key id
       
   100      */
       
   101     TUint32 iKey;
       
   102     };
       
   103 
       
   104 
       
   105 /**
       
   106  * HTML viewer settings class.
       
   107  */
       
   108 class CEUiHtmlViewerSettings : public CBase, public CEUiHtmlViewerSettingsKeyListener::MObserver
       
   109     {
       
   110 
       
   111 public:
       
   112 
       
   113     /**
       
   114      * Settings observer interface
       
   115      */
       
   116     class MObserver
       
   117         {
       
   118     public:
       
   119         /**
       
   120          * Called when a setting value has changed.
       
   121          */
       
   122         virtual void ViewerSettingsChangedL( const TUint32 aKey ) = 0;
       
   123         };
       
   124 
       
   125 public:
       
   126 
       
   127     /**
       
   128      * Static constructor
       
   129      */
       
   130     static CEUiHtmlViewerSettings* NewL( MObserver& aObserver );
       
   131 
       
   132     /**
       
   133      * Destructor
       
   134      */
       
   135     ~CEUiHtmlViewerSettings();
       
   136 
       
   137     /**
       
   138      * Boolean value for auto load image setting
       
   139      */
       
   140     TBool AutoLoadImages() const;
       
   141 
       
   142 private:
       
   143 
       
   144     CEUiHtmlViewerSettings( MObserver& aObserver );
       
   145     void ConstructL();
       
   146     void AddKeyListenerL( TUint32 aKey );
       
   147     void UpdateValue( TUint32 aKey );
       
   148 
       
   149 private: // from CEUiHtmlViewerSettingsKeyListener::MObserver
       
   150 
       
   151     /**
       
   152      * @see CEUiHtmlViewerSettingsKeyListener::MObserver::KeyValueChangedL
       
   153      */
       
   154     void KeyValueChangedL( TUint32 aKey );
       
   155 
       
   156 public:    
       
   157     /**
       
   158      * @see CEUiHtmlViewerSettingsKeyListener::MObserver::Repository
       
   159      */
       
   160     CRepository& Repository();
       
   161 
       
   162 private:
       
   163 
       
   164     enum TFlag
       
   165         {
       
   166         EAutoLoadImages = KFreestyleEmailDownloadHTMLImages
       
   167         };
       
   168 
       
   169     MObserver& iObserver;
       
   170     CRepository* iRepository;
       
   171     TBitFlags iFlags;
       
   172     RPointerArray<CEUiHtmlViewerSettingsKeyListener> iKeyListeners;
       
   173     };
       
   174 
       
   175 /**
       
   176  * Html viewer container.
       
   177  */
       
   178 class CFsEmailUiHtmlViewerContainer : public CCoeControl,
       
   179                                       public MBrCtlSpecialLoadObserver,
       
   180                                       public MBrCtlLinkResolver,
       
   181                                       public MBrCtlSoftkeysObserver,
       
   182                                       public MFSEmailDownloadInformationObserver,
       
   183                                       public MOverlayControlObserver,
       
   184                                       public MBrCtlWindowObserver,
       
   185                                       public CEUiHtmlViewerSettings::MObserver
       
   186     {
       
   187 public:
       
   188 
       
   189     /** Two-phased constructor. */
       
   190     static CFsEmailUiHtmlViewerContainer* NewL( CFreestyleEmailUiAppUi& aAppUi,
       
   191         CFsEmailUiHtmlViewerView& aView );
       
   192     /** Destrcutor. */
       
   193     ~CFsEmailUiHtmlViewerContainer();
       
   194 
       
   195     CBrCtlInterface* BrowserControlIf();
       
   196     void LoadContentFromFileL( const TDesC& aFileName );
       
   197     void LoadContentFromFileL( RFile& aFile );
       
   198     void LoadContentFromUrlL( const TDesC& aUrl );
       
   199     void LoadContentFromMailMessageL( CFSMailMessage* aMailMessage, TBool aResetScrollPos=ETrue );
       
   200     void ResetContent( TBool aDisconnect = EFalse, TBool aClearFlags = ETrue );
       
   201     void CancelFetch();
       
   202     void ClearCacheAndLoadEmptyContent();
       
   203     void PrepareForExit();
       
   204     void PrepareForMessageNavigation();
       
   205 
       
   206 // from base class CCoeControl
       
   207 
       
   208     CCoeControl* ComponentControl( TInt aIndex ) const;
       
   209     TInt CountComponentControls() const;
       
   210     void Draw( const TRect& aRect ) const;
       
   211     void SizeChanged();
       
   212     TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType );
       
   213     void HandleResourceChange(TInt aType);
       
   214     void MakeVisible( TBool aVisible );
       
   215 
       
   216 // from base class MBrCtlSpecialLoadObserver
       
   217 
       
   218     void NetworkConnectionNeededL( TInt* aConnectionPtr, TInt* aSockSvrHandle,
       
   219         TBool* aNewConn, TApBearerType* aBearerType );
       
   220     TBool HandleRequestL( RArray<TUint>* aTypeArray, CDesCArrayFlat* aDesArray );
       
   221     TBool HandleDownloadL( RArray<TUint>* aTypeArray, CDesCArrayFlat* aDesArray );
       
   222 
       
   223 // from base class MFSEmailDownloadInformationObserver
       
   224 
       
   225     void RequestResponseL( const TFSProgress& aEvent, const TPartData& aPart );
       
   226 
       
   227 // from base class MBrCtlLinkResolver
       
   228 
       
   229     TBool ResolveEmbeddedLinkL( const TDesC& aEmbeddedUrl,
       
   230         const TDesC& aCurrentUrl, TBrCtlLoadContentType aLoadContentType, 
       
   231         MBrCtlLinkContent& aEmbeddedLinkContent ); 
       
   232     TBool ResolveLinkL( const TDesC& aUrl, const TDesC& aCurrentUrl,
       
   233         MBrCtlLinkContent& aBrCtlLinkContent );
       
   234     void CancelAll();
       
   235 
       
   236 // from base class MBrCtlSoftkeysObserver
       
   237 
       
   238     void UpdateSoftkeyL( TBrCtlKeySoftkey aKeySoftkey, const TDesC& aLabel,
       
   239         TUint32 aCommandId, TBrCtlSoftkeyChangeReason aBrCtlSoftkeyChangeReason );
       
   240     void StopObserving();
       
   241     
       
   242 // from MOverlayControlObserver
       
   243     void HandleOverlayPointerEventL( COverlayControl* aControl, const TPointerEvent& aEvent );
       
   244 
       
   245     /*
       
   246      * Reloads the header of the opened mail.
       
   247      */
       
   248     void RefreshCurrentMailHeader();
       
   249     /** Handles asynchronous reload of page for case when orientation
       
   250      * changed
       
   251      */
       
   252     void ReloadPageL();
       
   253     
       
   254     void ShowAttachmentDownloadStatusL( TFSProgress::TFSProgressStatus aProgressStatus, const TAttachmentData& aAttachmentData );
       
   255     TBool AttachmentDownloadStatusVisible();
       
   256     void HideDownloadStatus();
       
   257     void DisplayStatusIndicatorL(TInt aDuration = KStatusIndicatorDefaultDuration);
       
   258     
       
   259     // Inform that maillist model has updated
       
   260     void MailListModelUpdatedL();
       
   261     
       
   262     // Zoom handling
       
   263     void ZoomInL();
       
   264     void ZoomOutL();
       
   265     TInt ZoomLevelL() const;
       
   266     void SetZoomLevelL( const TInt aZoomLevel );
       
   267     TInt MaxZoomLevel() const;
       
   268 
       
   269 private:
       
   270     
       
   271     static TInt DoZoom( TAny* aPtr  );
       
   272     void DoZoomL();
       
   273     
       
   274 private: // from CEUiHtmlViewerSettings::MObserver
       
   275 
       
   276     /**
       
   277      * @see CEUiHtmlViewerSettings::MObserver::ViewerSettingsChangedL
       
   278      */
       
   279     void ViewerSettingsChangedL( const TUint32 aKey );
       
   280 
       
   281 private:
       
   282 
       
   283     void CreateBrowserControlInterfaceL();
       
   284     
       
   285     // Second phase constructor.
       
   286     void ConstructL();
       
   287     // C++ constructor.
       
   288     CFsEmailUiHtmlViewerContainer( CFreestyleEmailUiAppUi& aAppUi,
       
   289         CFsEmailUiHtmlViewerView& aView );
       
   290 
       
   291     // Set HTML folder path name
       
   292     void SetHtmlFolderPathL();
       
   293     // Sets temporary HTML folder path name
       
   294     void SetTempHtmlFolderPath();
       
   295     // Remove all previously created files from temporary HTML folder
       
   296     void EmptyTempHtmlFolderL();
       
   297     // Copies given file to temporary HTML folder and returns an open file
       
   298     // handle to the created copy.
       
   299 // <cmail>
       
   300     void CopyToHtmlFileL( CFSMailMessagePart& aHtmlBodyPart, const TDesC& aFileName );
       
   301     void ConvertToHtmlFileL( CFSMailMessagePart& aTextBodyPart, const TDesC& aHtmlFileName );
       
   302 
       
   303     // Reads given file content to buffer and return pointer to it
       
   304     HBufC8* ReadContentFromFileLC( RFile& aFile, CFSMailMessagePart& aBodyPart );
       
   305     // Writes buffer to given file
       
   306     void WriteContentToFileL( const TDesC8& aContent, const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart );
       
   307 
       
   308     void PrepareBodyHtmlL(  const TDesC& aFileName  );
       
   309     void WriteEmptyBodyHtmlL( const TDesC& aFileName );
       
   310     
       
   311 // </cmail>
       
   312     // Finds the attachment from the list that matches the given content ID 
       
   313     CFSMailMessagePart* MatchingAttacmentL( const TDesC& aContentId,
       
   314         const RPointerArray<CFSMailMessagePart>& aAttachments ) const;
       
   315     // Resolves embedded link referring to file in temporary HTML folder
       
   316     TBool ResolveLinkL( const TDesC& aLink, TBool aContentId,
       
   317         MBrCtlLinkContent& aEmbeddedLinkContent );
       
   318     // Downloads and return attachment content via MBrCtlLinkContent interface
       
   319     void DownloadAttachmentL( CFSMailMessagePart& aAttachment,
       
   320         MBrCtlLinkContent& aEmbeddedLinkContent );
       
   321     
       
   322     // Get area for overlay button
       
   323     TRect OverlayButtonRect( TBool aLeft );
       
   324     
       
   325     // Update overlay button position and visibility
       
   326     void UpdateOverlayButtons( TBool aVisible );
       
   327     
       
   328     void SetHTMLResourceFlagFullName();
       
   329     void EnableHTMLResourceFlagL();
       
   330     TBool HTMLResourceFlagEnabled();
       
   331     void CopyHTMLResourceL();
       
   332     // Ensure all resource files (eg. images) required by HTML display to be ready in C:\[private]\HtmlFile
       
   333     void EnsureHTMLResourceL(); 
       
   334     void ConvertToHTML( const TDesC& aContent,
       
   335             const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart );
       
   336     HBufC8* GetCharacterSetL( CFSMailMessagePart& aHtmlBodyPart );
       
   337     TBool IsMessageBodyURLL(const TDesC& aUrl);
       
   338 	TInt TotalLengthOfItems( CFindItemEngine& aItemEngine ) const;
       
   339 	
       
   340     //Returns ETrue of clicking on a link requires a browser to be launched
       
   341     TBool NeedToLaunchBrowserL( const TDesC& aUrl );
       
   342     //Launch the browser as a standalone app
       
   343     void LaunchBrowserL( const TDesC& aUrl );
       
   344     
       
   345     //from MBrCtlWindowObserver    
       
   346     CBrCtlInterface* OpenWindowL( TDesC& aUrl, TDesC* aTargetName, 
       
   347                                   TBool aUserInitiated, TAny* aReserved );
       
   348     CBrCtlInterface* FindWindowL( const TDesC& aTargetName ) const;  
       
   349     void HandleWindowCommandL( const TDesC& aTargetName, TBrCtlWindowCommand aCommand ); 
       
   350        
       
   351     TRect CalcAttachmentStatusRect();
       
   352     void TouchFeedback();
       
   353     
       
   354     void WriteToFileL( const TDesC& aFileName, RBuf& aHtmlText );
       
   355 
       
   356 private: // data
       
   357 
       
   358     // Reference to AppUi.
       
   359     CFreestyleEmailUiAppUi& iAppUi;
       
   360     // Reference to Html viewer view.
       
   361     CFsEmailUiHtmlViewerView& iView;
       
   362     // Browser control interface. Own.
       
   363     CBrCtlInterface* iBrCtlInterface;
       
   364     // Message. Not own.
       
   365     CFSMailMessage*  iMessage;
       
   366     RFile            iFile;
       
   367     RFs              iFs;
       
   368     RSocketServ      iSocketServer;
       
   369     RConnection      iConnection;
       
   370     TBool            iFirstTime;
       
   371     
       
   372     // HTML folder path.
       
   373     TPath iHtmlFolderPath;
       
   374     // Temporary HTML folder path.
       
   375     TPath iTempHtmlFolderPath;
       
   376     // HTML resource flag file path
       
   377     TPath iHtmlResourceFlagPath;
       
   378     
       
   379     // Interfaces waiting for embedded link content.
       
   380     RPointerArray<MBrCtlLinkContent> iLinkContents;
       
   381     // Message parts being downloaded as embedded link content.
       
   382     RArray<TPartData> iMessageParts;
       
   383     CFreestyleMessageHeaderURLEventHandler* iEventHandler;
       
   384     TBool iObservingDownload;
       
   385     TInt iScrollPosition;
       
   386     COverlayControl* iOverlayControlNext;
       
   387     COverlayControl* iOverlayControlPrev;
       
   388     //way to keep track of the current image being displayed by the indicator
       
   389     TInt iAttachmentDownloadImageHandle;
       
   390     CFreestyleEmailUiAknStatusIndicator* iStatusIndicator;
       
   391     CEUiHtmlViewerSettings* iViewerSettings;
       
   392     
       
   393     TBool iHeaderExpanded;
       
   394     // tactile feed back -- not owned
       
   395     MTouchFeedback* iTouchFeedBack;
       
   396     TBitFlags iFlags;
       
   397     TInt iZoomLevel;
       
   398     };
       
   399 
       
   400 
       
   401 /**
       
   402 * PlainTextToHtmlConverter
       
   403 * 
       
   404 * PlainTextToHtmlConverter converts plain text to html. It adds html entities
       
   405 * and hyperlinks.
       
   406 */
       
   407 NONSHARABLE_CLASS (PlainTextToHtmlConverter)
       
   408     {
       
   409     private:
       
   410         PlainTextToHtmlConverter();
       
   411         
       
   412     public:
       
   413         static void PlainTextToHtmlL(const TDesC& aPlainText, RBuf& aHtmlText);
       
   414         
       
   415     private:
       
   416         static void ConvertTextL(const TDesC& aSource, RBuf& aTarget);
       
   417         static void ConvertUrlL(const TDesC& aSource, RBuf& aTarget);
       
   418     };
       
   419 #endif // __FREESTYLEEMAILUI_HTML_VIEWER_CONTAINER_H__