emailuis/emailui/src/FreestyleEmailUiHtmlViewerContainer.cpp
branchRCL_3
changeset 16 b5fbb9b25d57
parent 14 b13141f05c3d
child 20 efd4f1afd43e
equal deleted inserted replaced
14:b13141f05c3d 16:b5fbb9b25d57
    24 #include <biditext.h>
    24 #include <biditext.h>
    25 #include <StringLoader.h>
    25 #include <StringLoader.h>
    26 #include <e32base.h>
    26 #include <e32base.h>
    27 #include <badesca.h>
    27 #include <badesca.h>
    28 #include <utf.h>
    28 #include <utf.h>
       
    29 #include <finditemengine.h>
    29 
    30 
    30 //<cmail>
    31 //<cmail>
    31 #include "cfsmailmessage.h"
    32 #include "cfsmailmessage.h"
    32 //</cmail>
    33 //</cmail>
    33 #include <brctlinterface.h>
    34 #include <brctlinterface.h>
    77 _LIT( KHtmlLineBreakCRLF, "<br>\xD\xA" );
    78 _LIT( KHtmlLineBreakCRLF, "<br>\xD\xA" );
    78 _LIT( KHtmlLessThan, "&lt;" );
    79 _LIT( KHtmlLessThan, "&lt;" );
    79 _LIT( KHtmlGreaterThan, "&gt;" );
    80 _LIT( KHtmlGreaterThan, "&gt;" );
    80 _LIT( KHtmlAmpersand, "&amp;" );
    81 _LIT( KHtmlAmpersand, "&amp;" );
    81 _LIT( KHtmlQuotation, "&quot;" );
    82 _LIT( KHtmlQuotation, "&quot;" );
    82 // _LIT( KHtmlLinkTag, "<a href=\"%S\">" );
       
    83 // _LIT( KHtmlLinkTagWWW, "<a href=\"%S%S\">" );
       
    84 // _LIT( KHtmlLinkEndTag, "</a>" );
       
    85 _LIT( KURLTypeBody, "body");
    83 _LIT( KURLTypeBody, "body");
    86 
    84 
    87 _LIT( KURLDisplayImages, "cmail://displayImages/" );
    85 _LIT( KURLDisplayImages, "cmail://displayImages/" );
    88 _LIT( KURLLoadImages, "cmail://loadImages/" );
    86 _LIT( KURLLoadImages, "cmail://loadImages/" );
    89 _LIT( KURLCollapseHeader, "cmail://collapseHeader/" );
    87 _LIT( KURLCollapseHeader, "cmail://collapseHeader/" );
    91 
    89 
    92 const TText KGreaterThan = 0x3e;
    90 const TText KGreaterThan = 0x3e;
    93 const TText KLessThan = 0x3c;
    91 const TText KLessThan = 0x3c;
    94 const TText KAmpersand = 0x26;
    92 const TText KAmpersand = 0x26;
    95 const TText KQuotation = 0x22;
    93 const TText KQuotation = 0x22;
    96 // const TText KCharacterSpace = 0x20;
       
    97 const TText KSOH = 0x01; // Start Of Heading
    94 const TText KSOH = 0x01; // Start Of Heading
    98 // const TText KCR = 0x0d; // Carriage Return
       
    99 const TText KLF = 0x0a; // Line Feed
    95 const TText KLF = 0x0a; // Line Feed
   100 // const TText KHT = 0x09; // Horizontal Tab
       
   101 const TText KUnicodeNewLineCharacter = 0x2028;
    96 const TText KUnicodeNewLineCharacter = 0x2028;
   102 const TText KUnicodeParagraphCharacter = 0x2029;        
    97 const TText KUnicodeParagraphCharacter = 0x2029;
   103 const TReal KOverlayButtonMarginX = 0.01; // 1%
    98 const TReal KOverlayButtonMarginX = 0.01; // 1%
   104 const TReal KOverlayButtonMarginY = 0.01; // 1%
    99 const TReal KOverlayButtonMarginY = 0.01; // 1%
   105 const TReal KOverlayButtonSizeP = 0.15; // 15%
   100 const TReal KOverlayButtonSizeP = 0.15; // 15%
   106 const TReal KOverlayButtonSizeLs = 0.20; // 25%
   101 const TReal KOverlayButtonSizeLs = 0.20; // 25%
   107 
   102 
   108 
   103 
   109 const TInt KStatusIndicatorHeight = 50;
   104 const TInt KStatusIndicatorHeight = 50;
   110 const TInt KStatusIndicatorXMargin = 50;
   105 const TInt KStatusIndicatorXMargin = 50;
       
   106 
       
   107 // CONSTANTS
       
   108 // Zoom levels available on the UI
       
   109 const TInt KZoomLevels[] = { 75, 100, 125, 150 };
       
   110 const TInt KZoomLevelCount = sizeof( KZoomLevels ) / sizeof( TInt );
       
   111 const TInt KZoomLevelIndex100 = 100; // 100 in array KZoomLevels
   111 
   112 
   112 // CEUiHtmlViewerSettingsKeyListener
   113 // CEUiHtmlViewerSettingsKeyListener
   113 
   114 
   114 // ---------------------------------------------------------------------------
   115 // ---------------------------------------------------------------------------
   115 //
   116 //
   288     CFreestyleEmailUiAppUi& aAppUi, CFsEmailUiHtmlViewerView& aView )
   289     CFreestyleEmailUiAppUi& aAppUi, CFsEmailUiHtmlViewerView& aView )
   289     :
   290     :
   290     iAppUi( aAppUi ),
   291     iAppUi( aAppUi ),
   291     iView( aView ),
   292     iView( aView ),
   292     iFs( iCoeEnv->FsSession() ),
   293     iFs( iCoeEnv->FsSession() ),
   293     iFirstTime( ETrue )
   294     iFirstTime( ETrue ),
       
   295     iZoomLevel( KZoomLevelIndex100 )
   294     {
   296     {
   295     FUNC_LOG;
   297     FUNC_LOG;
   296     }
   298     }
   297 
   299 
   298 // ---------------------------------------------------------------------------
   300 // ---------------------------------------------------------------------------
   338     {
   340     {
   339     FUNC_LOG;
   341     FUNC_LOG;
   340     ResetContent();
   342     ResetContent();
   341     }
   343     }
   342 
   344 
   343 void CFsEmailUiHtmlViewerContainer::ConstructL()
   345 void CFsEmailUiHtmlViewerContainer::ZoomInL()
   344     {
   346     {
   345     FUNC_LOG;
   347     SetZoomLevelL( ZoomLevelL() + 1 );
   346     iViewerSettings = CEUiHtmlViewerSettings::NewL(*this);
   348     }
   347 
   349 
   348     SetHtmlFolderPathL();
   350 void CFsEmailUiHtmlViewerContainer::ZoomOutL()
   349     BaflUtils::EnsurePathExistsL( iFs, iHtmlFolderPath );
   351     {
   350     SetTempHtmlFolderPath();
   352     SetZoomLevelL( ZoomLevelL() - 1 );
   351     BaflUtils::EnsurePathExistsL( iFs, iTempHtmlFolderPath );
   353     }
   352     SetHTMLResourceFlagFullName();
   354 
   353     EnsureHTMLResourceL();
   355 TInt CFsEmailUiHtmlViewerContainer::ZoomLevelL() const
   354     
   356     {
   355     CreateWindowL();
   357     FUNC_LOG;
   356     SetRect( iView.ContainerRect() );
   358     TInt zoomLevelIdx = iBrCtlInterface->BrowserSettingL(
       
   359             TBrCtlDefs::ESettingsCurrentZoomLevelIndex );
       
   360 
       
   361     // Behaviour of zooming in Browser Control Interface is different in version 7.1
       
   362     // than in previous versions and we need to support both. In older versions there
       
   363     // are 4 preset zoom levels while version 7.1 can zoom to any percent.
       
   364     RArray<TUint>* zoomLevels = iBrCtlInterface->ZoomLevels();
       
   365 
       
   366     if ( !zoomLevels || !zoomLevels->Count() || ( *zoomLevels )[0] != KZoomLevels[0] )
       
   367         {
       
   368         // new browser:
       
   369         // BrowserControlIf gives zoom level percentage insted of index to array
       
   370         TBool found = EFalse;
       
   371 
       
   372         for ( TInt i = 0 ; i < KZoomLevelCount && !found ; ++i )
       
   373             {
       
   374             if ( zoomLevelIdx == KZoomLevels[i] )
       
   375                 {
       
   376                 zoomLevelIdx = i;
       
   377                 found = ETrue;
       
   378                 }
       
   379             }
       
   380 
       
   381         if ( !found )
       
   382             {
       
   383             zoomLevelIdx = KErrNotFound;
       
   384             }
       
   385         }
       
   386     return zoomLevelIdx;
       
   387     }
       
   388 
       
   389 void CFsEmailUiHtmlViewerContainer::SetZoomLevelL( const TInt aZoomLevel )
       
   390     {
       
   391     FUNC_LOG;
       
   392     TInt newValue = KMinTInt;
       
   393 
       
   394     // Behaviour of zooming in Browser Control Interface is different in version 7.1
       
   395     // than in previous versions and we need to support both. In older versions there
       
   396     // are 4 preset zoom levels while version 7.1 can zoom to any percent.
       
   397     RArray<TUint>* zoomLevels = iBrCtlInterface->ZoomLevels();
       
   398 
       
   399     if ( !zoomLevels || !zoomLevels->Count() || ( *zoomLevels )[0] != KZoomLevels[0] )
       
   400         {
       
   401         // new browser:
       
   402         // BrowserControlIf takes zoom level percentage insted of index to array
       
   403         if ( aZoomLevel >= 0 && aZoomLevel < KZoomLevelCount )
       
   404             {
       
   405             newValue = KZoomLevels[aZoomLevel];
       
   406             }
       
   407         }
       
   408     else
       
   409         {
       
   410         // old browser
       
   411         newValue = aZoomLevel;
       
   412         }
       
   413 
       
   414     iZoomLevel = ( newValue > KMinTInt ) ? newValue : aZoomLevel;
       
   415     iBrCtlInterface->SetBrowserSettingL(
       
   416         TBrCtlDefs::ESettingsCurrentZoomLevelIndex, iZoomLevel );
       
   417     }
       
   418 
       
   419 TInt CFsEmailUiHtmlViewerContainer::DoZoom( TAny* aPtr  )
       
   420     {
       
   421     TRAPD( error, reinterpret_cast<CFsEmailUiHtmlViewerContainer*>( aPtr )->DoZoomL() );
       
   422     return error;
       
   423     }
       
   424 
       
   425 void CFsEmailUiHtmlViewerContainer::DoZoomL()
       
   426     {
       
   427     iBrCtlInterface->SetBrowserSettingL(
       
   428         TBrCtlDefs::ESettingsCurrentZoomLevelIndex, iZoomLevel );
       
   429     }
       
   430 
       
   431 TInt CFsEmailUiHtmlViewerContainer::MaxZoomLevel() const
       
   432     {
       
   433     return KZoomLevelCount;
       
   434     }
       
   435 
       
   436 
       
   437 void CFsEmailUiHtmlViewerContainer::CreateBrowserControlInterfaceL()
       
   438     {
       
   439     FUNC_LOG;
       
   440 
       
   441     if ( iBrCtlInterface )
       
   442         {
       
   443         delete iBrCtlInterface;
       
   444         iBrCtlInterface = NULL;
       
   445         }
   357 
   446 
   358     TUint brCtlCapabilities = TBrCtlDefs::ECapabilityClientResolveEmbeddedURL |
   447     TUint brCtlCapabilities = TBrCtlDefs::ECapabilityClientResolveEmbeddedURL |
   359                               TBrCtlDefs::ECapabilityDisplayScrollBar |
   448                               TBrCtlDefs::ECapabilityDisplayScrollBar |
   360                               TBrCtlDefs::ECapabilityClientNotifyURL |
   449                               TBrCtlDefs::ECapabilityClientNotifyURL |
   361                               TBrCtlDefs::ECapabilityLoadHttpFw |
   450                               TBrCtlDefs::ECapabilityLoadHttpFw |
   362                               TBrCtlDefs::ECapabilityCursorNavigation |
   451                               TBrCtlDefs::ECapabilityCursorNavigation |
   363                               TBrCtlDefs::ECapabilityPinchZoom;
   452                               TBrCtlDefs::ECapabilityPinchZoom |
       
   453                               TBrCtlDefs::ECapabilityFitToScreen;
   364 
   454 
   365     // Set browsercontrol to whole screen
   455     // Set browsercontrol to whole screen
   366     TRect rect( TPoint(), Size() );
   456     TRect rect( TPoint(), Size() );
   367    
   457 
   368     iBrCtlInterface = CreateBrowserControlL( 
   458     iBrCtlInterface = CreateBrowserControlL(
   369             this, // aParent 
   459             this, // aParent
   370             rect,  // aRect
   460             rect,  // aRect
   371             brCtlCapabilities, // aBrCtlCapabilities
   461             brCtlCapabilities, // aBrCtlCapabilities
   372             TBrCtlDefs::ECommandIdBase, // aCommandIdBase
   462             TBrCtlDefs::ECommandIdBase, // aCommandIdBase
   373             NULL, // aBrCtlSoftkeysObserver
   463             NULL, // aBrCtlSoftkeysObserver
   374             this, // aBrCtlLinkResolver
   464             this, // aBrCtlLinkResolver
   375             this, // aBrCtlSpecialLoadObserver
   465             this, // aBrCtlSpecialLoadObserver
   376             NULL, // aBrCtlLayoutObserver
   466             NULL, // aBrCtlLayoutObserver
   377             NULL, // aBrCtlDialogsProvider
   467             NULL, // aBrCtlDialogsProvider
   378             this, // aBrCtlWindowObserver
   468             this, // aBrCtlWindowObserver
   379             NULL // aBrCtlDownloadObserver 
   469             NULL // aBrCtlDownloadObserver
   380             );
   470             );
   381 
   471 
   382     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsEmbedded, ETrue );
   472     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsEmbedded, ETrue );
   383     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages, iViewerSettings->AutoLoadImages() );
   473     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages, iViewerSettings->AutoLoadImages() );
   384     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsPageOverview, EFalse );
   474     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsPageOverview, EFalse );
   385     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsTextWrapEnabled, ETrue );
   475     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsTextWrapEnabled, ETrue );
   386     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsFontSize, TBrCtlDefs::EFontSizeLevelLarger );
   476     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsFontSize, TBrCtlDefs::EFontSizeLevelLarger );
       
   477     }
       
   478 
       
   479 void CFsEmailUiHtmlViewerContainer::ConstructL()
       
   480     {
       
   481     FUNC_LOG;
       
   482     iViewerSettings = CEUiHtmlViewerSettings::NewL(*this);
       
   483 
       
   484     SetHtmlFolderPathL();
       
   485     BaflUtils::EnsurePathExistsL( iFs, iHtmlFolderPath );
       
   486     SetTempHtmlFolderPath();
       
   487     BaflUtils::EnsurePathExistsL( iFs, iTempHtmlFolderPath );
       
   488     SetHTMLResourceFlagFullName();
       
   489     EnsureHTMLResourceL();
       
   490 
       
   491     CreateWindowL();
   387     
   492     
       
   493 #if defined( BRDO_MULTITOUCH_ENABLED_FF ) && !defined ( __WINSCW__ )   
       
   494     //Enable advance pointer info for multi-touch.
       
   495     Window().EnableAdvancedPointers();
       
   496 #endif 
       
   497 
       
   498     
       
   499     SetRect( iView.ContainerRect() );
       
   500     CreateBrowserControlInterfaceL();
       
   501 
   388     iEventHandler = CFreestyleMessageHeaderURLEventHandler::NewL( iAppUi, iView );
   502     iEventHandler = CFreestyleMessageHeaderURLEventHandler::NewL( iAppUi, iView );
   389     
   503 
   390     TRect nextButtonRect = OverlayButtonRect( EFalse );
   504     TRect nextButtonRect = OverlayButtonRect( EFalse );
   391     iOverlayControlNext = COverlayControl::NewL( this, this, nextButtonRect, 
   505     iOverlayControlNext = COverlayControl::NewL( this, this, nextButtonRect,
   392             EMbmFreestyleemailuiQgn_indi_cmail_arrow_next, 
   506             EMbmFreestyleemailuiQgn_indi_cmail_arrow_next,
   393             EMbmFreestyleemailuiQgn_indi_cmail_arrow_next_mask );
   507             EMbmFreestyleemailuiQgn_indi_cmail_arrow_next_mask );
   394 
   508 
   395     TRect prevButtonRect = OverlayButtonRect( ETrue );
   509     TRect prevButtonRect = OverlayButtonRect( ETrue );
   396     iOverlayControlPrev = COverlayControl::NewL( this, this, prevButtonRect,
   510     iOverlayControlPrev = COverlayControl::NewL( this, this, prevButtonRect,
   397             EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous,
   511             EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous,
   409     {
   523     {
   410     UpdateOverlayButtons( aVisible );
   524     UpdateOverlayButtons( aVisible );
   411     CCoeControl::MakeVisible( aVisible );
   525     CCoeControl::MakeVisible( aVisible );
   412     }
   526     }
   413 
   527 
   414 void CFsEmailUiHtmlViewerContainer::HandleOverlayPointerEventL( COverlayControl* aControl, 
   528 void CFsEmailUiHtmlViewerContainer::HandleOverlayPointerEventL( COverlayControl* aControl,
   415         const TPointerEvent& aEvent )
   529         const TPointerEvent& aEvent )
   416     {
   530     {
   417     if( aEvent.iType == TPointerEvent::EButton1Up )
   531     if( aEvent.iType == TPointerEvent::EButton1Up )
   418         {
   532         {
   419         if( aControl == iOverlayControlNext )
   533         if( aControl == iOverlayControlNext )
   437         TFSMailMsgId tmpMsgId;
   551         TFSMailMsgId tmpMsgId;
   438         TFSMailMsgId tmpMsgFolderId;
   552         TFSMailMsgId tmpMsgFolderId;
   439         nextAvailable = iAppUi.IsNextMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId );
   553         nextAvailable = iAppUi.IsNextMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId );
   440         prevAvailable = iAppUi.IsPreviousMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId );
   554         prevAvailable = iAppUi.IsPreviousMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId );
   441         }
   555         }
   442     
   556 
   443     if( iOverlayControlPrev )
   557     if( iOverlayControlPrev )
   444         {
   558         {
   445         iOverlayControlPrev->SetRect( OverlayButtonRect( ETrue ) );
   559         iOverlayControlPrev->SetRect( OverlayButtonRect( ETrue ) );
   446         iOverlayControlPrev->MakeVisible( aVisible && prevAvailable );
   560         iOverlayControlPrev->MakeVisible( aVisible && prevAvailable );
   447         }
   561         }
   455 // Get rect for button
   569 // Get rect for button
   456 TRect CFsEmailUiHtmlViewerContainer::OverlayButtonRect( TBool aLeft )
   570 TRect CFsEmailUiHtmlViewerContainer::OverlayButtonRect( TBool aLeft )
   457     {
   571     {
   458     TRect rect = Rect();
   572     TRect rect = Rect();
   459     TSize size = rect.Size();
   573     TSize size = rect.Size();
   460     
   574 
   461     TBool landscape = size.iWidth > size.iHeight;
   575     TBool landscape = size.iWidth > size.iHeight;
   462     TInt buttonSize;
   576     TInt buttonSize;
   463 
   577 
   464     if( landscape )
   578     if( landscape )
   465         {
   579         {
   469         {
   583         {
   470         buttonSize = size.iWidth * KOverlayButtonSizeP;
   584         buttonSize = size.iWidth * KOverlayButtonSizeP;
   471         }
   585         }
   472 
   586 
   473     rect.iBr.iY = size.iHeight * (1-KOverlayButtonMarginY);
   587     rect.iBr.iY = size.iHeight * (1-KOverlayButtonMarginY);
   474     
   588 
   475     if( aLeft )
   589     if( aLeft )
   476         {
   590         {
   477         rect.iTl.iX = size.iWidth * KOverlayButtonMarginX;
   591         rect.iTl.iX = size.iWidth * KOverlayButtonMarginX;
   478         rect.iBr.iX = rect.iTl.iX + buttonSize;
   592         rect.iBr.iX = rect.iTl.iX + buttonSize;
   479         }
   593         }
   480     else
   594     else
   481         {
   595         {
   482         rect.iBr.iX = size.iWidth * (1 - KOverlayButtonMarginX);
   596         rect.iBr.iX = size.iWidth * (1 - KOverlayButtonMarginX);
   483         rect.iTl.iX = rect.iBr.iX - buttonSize;
   597         rect.iTl.iX = rect.iBr.iX - buttonSize;
   484         }
   598         }
   485     
   599 
   486     rect.iTl.iY = rect.iBr.iY - buttonSize;
   600     rect.iTl.iY = rect.iBr.iY - buttonSize;
   487     return rect;
   601     return rect;
   488     }
   602     }
   489 
   603 
   490 // Getter for br contro, interface
   604 // Getter for br contro, interface
   523     ASSERT( aMailMessage );
   637     ASSERT( aMailMessage );
   524     iMessage = aMailMessage;
   638     iMessage = aMailMessage;
   525     // Cancel any browser fetch operation, just in case the browser is still
   639     // Cancel any browser fetch operation, just in case the browser is still
   526     // loading a previous message (since we are about to overwrite it).
   640     // loading a previous message (since we are about to overwrite it).
   527     CancelFetch();
   641     CancelFetch();
   528     
   642 
   529     TPath headerHtmlFile;
   643     TPath headerHtmlFile;
   530     headerHtmlFile.Copy( iHtmlFolderPath );
   644     headerHtmlFile.Copy( iHtmlFolderPath );
   531     headerHtmlFile.Append( KHeaderHtmlFile );
   645     headerHtmlFile.Append( KHeaderHtmlFile );
   532     
   646 
   533     // insert email header into email.html file
   647     // insert email header into email.html file
   534     // CFreestyleMessageHeaderHTML will replace contents of email.html
   648     // CFreestyleMessageHeaderHTML will replace contents of email.html
   535     // So, no need to clear the contents
   649     // So, no need to clear the contents
   536     if(aResetScrollPos)
   650     if(aResetScrollPos)
   537         {
   651         {
   538         iScrollPosition = 0; 
   652         iScrollPosition = 0;
   539         }
   653         }
   540     const TInt visibleWidth(iAppUi.ClientRect().Width());
   654     const TInt visibleWidth(iAppUi.ClientRect().Width());
   541     CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, visibleWidth, iScrollPosition,
   655     CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, visibleWidth, iScrollPosition,
   542                                             iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage),
   656                                             iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage),
   543                                             iHeaderExpanded );
   657                                             iHeaderExpanded );
   544     
   658 
   545     // Remove all previously created files from temporary HTML folder
   659     // Remove all previously created files from temporary HTML folder
   546     EmptyTempHtmlFolderL();
   660     EmptyTempHtmlFolderL();
   547 
   661 
   548     TRAPD( error, PrepareBodyHtmlL( KBodyHtmlFile ) );
   662     TRAPD( error, PrepareBodyHtmlL( KBodyHtmlFile ) );
   549     if ( error != KErrNone )
   663     if ( error != KErrNone )
   560         }
   674         }
   561     else
   675     else
   562         {
   676         {
   563         emailHtmlFile.Append( KMessageHtmlRTLFile );
   677         emailHtmlFile.Append( KMessageHtmlRTLFile );
   564         }
   678         }
       
   679 
       
   680     CreateBrowserControlInterfaceL();
       
   681 
   565     LoadContentFromFileL( emailHtmlFile );
   682     LoadContentFromFileL( emailHtmlFile );
   566     
   683 
   567     UpdateOverlayButtons( ETrue );
   684     UpdateOverlayButtons( ETrue );
   568     }
   685     }
   569 
   686 
   570 // ---------------------------------------------------------------------------
   687 // ---------------------------------------------------------------------------
   571 // Reset content
   688 // Reset content
   574 void CFsEmailUiHtmlViewerContainer::ResetContent(const TBool aDisconnect)
   691 void CFsEmailUiHtmlViewerContainer::ResetContent(const TBool aDisconnect)
   575     {
   692     {
   576     FUNC_LOG;
   693     FUNC_LOG;
   577     if ( iBrCtlInterface )
   694     if ( iBrCtlInterface )
   578         {
   695         {
   579         TRAP_IGNORE( 
   696         TRAP_IGNORE(
   580                 iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
   697                 iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
   581                         ( TInt )TBrCtlDefs::ECommandFreeMemory ) );
   698                         ( TInt )TBrCtlDefs::ECommandFreeMemory ) );
   582         if (aDisconnect)
   699         if (aDisconnect)
   583             {
   700             {
   584             TRAP_IGNORE( 
   701             TRAP_IGNORE(
   585                     iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
   702                     iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
   586                                                       ( TInt )TBrCtlDefs::ECommandDisconnect ) );
   703                                                       ( TInt )TBrCtlDefs::ECommandDisconnect ) );
   587             }
   704             }
   588         }
   705         }
   589     iFile.Close();
   706     iFile.Close();
   638     FUNC_LOG;
   755     FUNC_LOG;
   639     if ( iStatusIndicator )
   756     if ( iStatusIndicator )
   640         {
   757         {
   641         return 4;
   758         return 4;
   642         }
   759         }
   643     else 
   760     else
   644         {
   761         {
   645         return 3;
   762         return 3;
   646         }
   763         }
   647     }
   764     }
   648 
   765 
   675     TRect rect = Rect();
   792     TRect rect = Rect();
   676     if ( iBrCtlInterface )
   793     if ( iBrCtlInterface )
   677         {
   794         {
   678         iBrCtlInterface->SetRect( rect );
   795         iBrCtlInterface->SetRect( rect );
   679         }
   796         }
   680     
   797 
   681     UpdateOverlayButtons( IsVisible() );
   798     UpdateOverlayButtons( IsVisible() );
   682     
   799 
   683     if ( iStatusIndicator )
   800     if ( iStatusIndicator )
   684         {
   801         {
   685         TRect rect = CalcAttachmentStatusRect();
   802         TRect rect = CalcAttachmentStatusRect();
   686         iStatusIndicator->SetRect( rect );
   803         iStatusIndicator->SetRect( rect );
   687         }
   804         }
   693 //
   810 //
   694 TKeyResponse CFsEmailUiHtmlViewerContainer::OfferKeyEventL(
   811 TKeyResponse CFsEmailUiHtmlViewerContainer::OfferKeyEventL(
   695     const TKeyEvent& aKeyEvent, TEventCode aType )
   812     const TKeyEvent& aKeyEvent, TEventCode aType )
   696     {
   813     {
   697     FUNC_LOG;
   814     FUNC_LOG;
   698     
   815 
   699     TKeyResponse retVal = EKeyWasNotConsumed;
   816     TKeyResponse retVal = EKeyWasNotConsumed;
   700 
   817 
   701     // Handle keyboard shortcuts already on key down event as all keys
   818     // Handle keyboard shortcuts already on key down event as all keys
   702     // do not necessarily send the key event at all.
   819     // do not necessarily send the key event at all.
   703     if ( aType == EEventKeyDown )
   820     if ( aType == EEventKeyDown )
   711             iView.HandleCommandL( shortcutCommand );
   828             iView.HandleCommandL( shortcutCommand );
   712             retVal = EKeyWasConsumed;
   829             retVal = EKeyWasConsumed;
   713             }
   830             }
   714         }
   831         }
   715 
   832 
   716     else if ( iBrCtlInterface && retVal == EKeyWasNotConsumed )
   833     if ( iBrCtlInterface && retVal == EKeyWasNotConsumed )
   717         {
   834         {
   718         retVal = iBrCtlInterface->OfferKeyEventL( aKeyEvent, aType );
   835         TKeyEvent event = aKeyEvent;
       
   836         if ( iBrCtlInterface->FocusedElementType() == TBrCtlDefs::EElementButton
       
   837              && ( aKeyEvent.iScanCode == EStdKeyNkpEnter 
       
   838                   || aKeyEvent.iScanCode == EStdKeyEnter ) )
       
   839             {
       
   840             // Enter key events are converted to selection key event in
       
   841             // order to get browser to handle them in similar way.
       
   842             event.iScanCode = EStdKeyDevice3;
       
   843             event.iCode = aKeyEvent.iCode ? EKeyDevice3 : 0;
       
   844             }
       
   845         retVal = iBrCtlInterface->OfferKeyEventL( event, aType );
   719         }
   846         }
   720 
   847 
   721     iView.SetMskL();
   848     iView.SetMskL();
   722 
   849 
   723     return retVal;
   850     return retVal;
   804 
   931 
   805         if ( !iMessageParts.Count() && iAppUi.DownloadInfoMediator() )
   932         if ( !iMessageParts.Count() && iAppUi.DownloadInfoMediator() )
   806             {
   933             {
   807             iAppUi.DownloadInfoMediator()->StopObserving( this );
   934             iAppUi.DownloadInfoMediator()->StopObserving( this );
   808             }
   935             }
   809                
   936 
   810         if ( iMessage && linkContent )
   937         if ( iMessage && linkContent )
   811             {
   938             {
   812             CFSMailMessagePart* part = iMessage->ChildPartL( aPart.iMessagePartId );
   939             CFSMailMessagePart* part = iMessage->ChildPartL( aPart.iMessagePartId );
   813             CleanupStack::PushL( part );
   940             CleanupStack::PushL( part );
   814             RFile contentFile = part->GetContentFileL();
   941             RFile contentFile = part->GetContentFileL();
   818                 part->GetContentType(), KNullDesC(), content );
   945                 part->GetContentType(), KNullDesC(), content );
   819             CleanupStack::PopAndDestroy( content );
   946             CleanupStack::PopAndDestroy( content );
   820             CleanupStack::PopAndDestroy( &contentFile );
   947             CleanupStack::PopAndDestroy( &contentFile );
   821             CleanupStack::PopAndDestroy( part );
   948             CleanupStack::PopAndDestroy( part );
   822             }
   949             }
   823         
   950 
   824         if ( iMessage )
   951         if ( iMessage )
   825             {
   952             {
   826             LoadContentFromMailMessageL( iMessage, EFalse );            
   953             LoadContentFromMailMessageL( iMessage, EFalse );
   827             UpdateOverlayButtons( ETrue );
   954             UpdateOverlayButtons( ETrue );
   828             }
   955             }
   829         }
   956         }
   830     else if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled ||
   957     else if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled ||
   831             aEvent.iProgressStatus < 0 )
   958             aEvent.iProgressStatus < 0 )
   905             return ETrue;
  1032             return ETrue;
   906             }
  1033             }
   907         else
  1034         else
   908             {
  1035             {
   909             return iEventHandler->HandleEventL( aUrl );
  1036             return iEventHandler->HandleEventL( aUrl );
   910             }     
  1037             }
   911         }
  1038         }
   912     }
  1039     }
   913 
  1040 
   914 // ---------------------------------------------------------------------------
  1041 // ---------------------------------------------------------------------------
   915 // From MBrCtlLinkResolver.
  1042 // From MBrCtlLinkResolver.
   952 // Sets temporary HTML folder path name
  1079 // Sets temporary HTML folder path name
   953 // ---------------------------------------------------------------------------
  1080 // ---------------------------------------------------------------------------
   954 //
  1081 //
   955 void CFsEmailUiHtmlViewerContainer::SetTempHtmlFolderPath()
  1082 void CFsEmailUiHtmlViewerContainer::SetTempHtmlFolderPath()
   956     {
  1083     {
   957     FUNC_LOG;    
  1084     FUNC_LOG;
   958     iTempHtmlFolderPath.Copy( iHtmlFolderPath );
  1085     iTempHtmlFolderPath.Copy( iHtmlFolderPath );
   959     iTempHtmlFolderPath.Append( KTempHtmlPath );
  1086     iTempHtmlFolderPath.Append( KTempHtmlPath );
   960     }
  1087     }
   961 
  1088 
   962 // ---------------------------------------------------------------------------
  1089 // ---------------------------------------------------------------------------
   989     targetFileName.Copy( iTempHtmlFolderPath );
  1116     targetFileName.Copy( iTempHtmlFolderPath );
   990     targetFileName.Append( aFileName );
  1117     targetFileName.Append( aFileName );
   991 
  1118 
   992     RFile htmlFile = aHtmlBodyPart.GetContentFileL();
  1119     RFile htmlFile = aHtmlBodyPart.GetContentFileL();
   993     CleanupClosePushL( htmlFile );
  1120     CleanupClosePushL( htmlFile );
   994     
  1121 
   995     // Read content from given source file
  1122     // Read content from given source file
   996     HBufC8* content = ReadContentFromFileLC( htmlFile );
  1123     HBufC8* content = ReadContentFromFileLC( htmlFile );
   997 
  1124 
   998     // Write content to target file
  1125     // Write content to target file
   999     WriteContentToFileL( *content, targetFileName, aHtmlBodyPart );
  1126     WriteContentToFileL( *content, targetFileName, aHtmlBodyPart );
  1012     {
  1139     {
  1013     FUNC_LOG;
  1140     FUNC_LOG;
  1014     TFileName targetFileName;
  1141     TFileName targetFileName;
  1015     targetFileName.Copy( iTempHtmlFolderPath );
  1142     targetFileName.Copy( iTempHtmlFolderPath );
  1016     targetFileName.Append( aHtmlFileName );
  1143     targetFileName.Append( aHtmlFileName );
  1017     
  1144 
  1018     HBufC* content = HBufC::NewLC( aTextBodyPart.FetchedContentSize() );
  1145     HBufC* content = HBufC::NewLC( aTextBodyPart.FetchedContentSize() );
  1019     TPtr contentPtr( content->Des() );
  1146     TPtr contentPtr( content->Des() );
  1020     
  1147 
  1021     aTextBodyPart.GetContentToBufferL( contentPtr, 0 );
  1148     aTextBodyPart.GetContentToBufferL( contentPtr, 0 );
  1022     
  1149 
  1023     ConvertToHTML( *content, targetFileName, aTextBodyPart );
  1150     ConvertToHTML( *content, targetFileName, aTextBodyPart );
  1024     
  1151 
  1025     CleanupStack::PopAndDestroy( content );
  1152     CleanupStack::PopAndDestroy( content );
  1026 
  1153 
  1027     }
  1154     }
  1028 
  1155 
  1029 // ---------------------------------------------------------------------------
  1156 // ---------------------------------------------------------------------------
  1048 // <cmail>
  1175 // <cmail>
  1049 void CFsEmailUiHtmlViewerContainer::WriteContentToFileL( const TDesC8& aContent,
  1176 void CFsEmailUiHtmlViewerContainer::WriteContentToFileL( const TDesC8& aContent,
  1050     const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart )
  1177     const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart )
  1051     {
  1178     {
  1052     FUNC_LOG;
  1179     FUNC_LOG;
  1053     
  1180 
  1054     RBuf8 buffer;
  1181     RBuf8 buffer;
  1055     buffer.CreateL( aContent );
  1182     buffer.CreateL( aContent );
  1056     buffer.CleanupClosePushL();
  1183     buffer.CleanupClosePushL();
  1057     
  1184 
  1058     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, buffer.Size(), EDriveC ) )
  1185     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, buffer.Size(), EDriveC ) )
  1059          {
  1186          {
  1060          // Can not write the data, there's not enough free space on disk.
  1187          // Can not write the data, there's not enough free space on disk.
  1061          User::Leave( KErrDiskFull );
  1188          User::Leave( KErrDiskFull );
  1062         }
  1189         }
  1063     else
  1190     else
  1064         {
  1191         {
  1065         RFile targetFile;
  1192         RFile targetFile;
  1066         CleanupClosePushL( targetFile );
  1193         CleanupClosePushL( targetFile );
  1067         
  1194 
  1068         User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) );
  1195         User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) );
  1069 
  1196 
  1070         // Try to find initial html tag (both '<html' and '<HTML' versions are searched)
  1197         // Try to find initial html tag (both '<html' and '<HTML' versions are searched)
  1071         TInt startTagOffset = buffer.Left( KMaxCharsToSearch ).FindF( KStartTag );
  1198         TInt startTagOffset = buffer.Left( KMaxCharsToSearch ).FindF( KStartTag );
  1072         
  1199 
  1073         // Modifying text/html atta IF there's no '<html>' tag anywhere in
  1200         // Modifying text/html atta IF there's no '<html>' tag anywhere in
  1074         // the begining of file (KMaxCharsToSearch) AND there is charset
  1201         // the begining of file (KMaxCharsToSearch) AND there is charset
  1075         // parameter available
  1202         // parameter available
  1076         TBool modificationNeeded( EFalse );
  1203         TBool modificationNeeded( EFalse );
  1077         if( startTagOffset == KErrNotFound )
  1204         if( startTagOffset == KErrNotFound )
  1082         // Write starting metadata if needed
  1209         // Write starting metadata if needed
  1083         if ( modificationNeeded )
  1210         if ( modificationNeeded )
  1084             {
  1211             {
  1085             HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart );
  1212             HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart );
  1086             CleanupStack::PushL( charSet );
  1213             CleanupStack::PushL( charSet );
  1087             
  1214 
  1088             User::LeaveIfError( targetFile.Write( KHtmlHeader1 ) );
  1215             User::LeaveIfError( targetFile.Write( KHtmlHeader1 ) );
  1089             User::LeaveIfError( targetFile.Write( *charSet ) );
  1216             User::LeaveIfError( targetFile.Write( *charSet ) );
  1090             User::LeaveIfError( targetFile.Write( KHtmlHeader2 ) );
  1217             User::LeaveIfError( targetFile.Write( KHtmlHeader2 ) );
  1091             CleanupStack::PopAndDestroy( charSet );
  1218             CleanupStack::PopAndDestroy( charSet );
  1092             }
  1219             }
  1093         else 
  1220         else
  1094             {
  1221             {
  1095             // Charset tag not found in html body
  1222             // Charset tag not found in html body
  1096             
  1223 
  1097             if ( buffer.Left( KMaxCharsToSearch ).FindF( KCharsetTag8 ) == KErrNotFound )
  1224             if ( buffer.Left( KMaxCharsToSearch ).FindF( KCharsetTag8 ) == KErrNotFound )
  1098                 {
  1225                 {
  1099                 TInt startPos(0);
  1226                 TInt startPos(0);
  1100                 if ( ( startPos = buffer.Left( KMaxCharsToSearch ).FindF( KHeadTag ) ) != KErrNotFound )
  1227                 if ( ( startPos = buffer.Left( KMaxCharsToSearch ).FindF( KHeadTag ) ) != KErrNotFound )
  1101                     { 
  1228                     {
  1102                     
  1229 
  1103                     HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart );
  1230                     HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart );
  1104                     CleanupStack::PushL( charSet );
  1231                     CleanupStack::PushL( charSet );
  1105                     
  1232 
  1106                     HBufC8* metaBuffer = HBufC8::NewLC( charSet->Des().Length() + KHtmlHeader3().Length() );
  1233                     HBufC8* metaBuffer = HBufC8::NewLC( charSet->Des().Length() + KHtmlHeader3().Length() );
  1107                     TPtr8 metaHeader( metaBuffer->Des() );
  1234                     TPtr8 metaHeader( metaBuffer->Des() );
  1108                     metaHeader.AppendFormat( KHtmlHeader3, charSet );                
  1235                     metaHeader.AppendFormat( KHtmlHeader3, charSet );
  1109                     TInt maxLength = buffer.Length() + metaHeader.Length();         
  1236                     TInt maxLength = buffer.Length() + metaHeader.Length();
  1110                     buffer.ReAllocL( maxLength );
  1237                     buffer.ReAllocL( maxLength );
  1111                    
  1238 
  1112                     startPos += KHeadTag().Length();
  1239                     startPos += KHeadTag().Length();
  1113                     buffer.Insert( startPos, metaHeader );
  1240                     buffer.Insert( startPos, metaHeader );
  1114                     
  1241 
  1115                     CleanupStack::PopAndDestroy( metaBuffer );
  1242                     CleanupStack::PopAndDestroy( metaBuffer );
  1116                     CleanupStack::PopAndDestroy( charSet );
  1243                     CleanupStack::PopAndDestroy( charSet );
  1117                     }
  1244                     }
  1118                 }
  1245                 }
  1119             }
  1246             }
  1242         if( iMessage )
  1369         if( iMessage )
  1243             {
  1370             {
  1244             partData.iMailBoxId = iMessage->GetMailBoxId();
  1371             partData.iMailBoxId = iMessage->GetMailBoxId();
  1245             partData.iFolderId = iMessage->GetFolderId();
  1372             partData.iFolderId = iMessage->GetFolderId();
  1246             partData.iMessageId = iMessage->GetMessageId();
  1373             partData.iMessageId = iMessage->GetMessageId();
  1247             
  1374 
  1248             partData.iMessagePartId = aAttachment.GetPartId();
  1375             partData.iMessagePartId = aAttachment.GetPartId();
  1249 
  1376 
  1250             if ( iAppUi.DownloadInfoMediator() &&
  1377             if ( iAppUi.DownloadInfoMediator() &&
  1251                  iAppUi.DownloadInfoMediator()->IsDownloadableL( partData ) )
  1378                  iAppUi.DownloadInfoMediator()->IsDownloadableL( partData ) )
  1252                 {
  1379                 {
  1253                 ASSERT( iLinkContents.Count() == iMessageParts.Count() );
  1380                 ASSERT( iLinkContents.Count() == iMessageParts.Count() );
  1254     
  1381 
  1255                 // Append message part details and embedded link content interface
  1382                 // Append message part details and embedded link content interface
  1256                 // to corresponding arrays so that the content can be returned
  1383                 // to corresponding arrays so that the content can be returned
  1257                 // when the download is completed.
  1384                 // when the download is completed.
  1258                 iLinkContents.AppendL( &aEmbeddedLinkContent );
  1385                 iLinkContents.AppendL( &aEmbeddedLinkContent );
  1259                 if ( iMessageParts.Append( partData ) != KErrNone )
  1386                 if ( iMessageParts.Append( partData ) != KErrNone )
  1260                     {
  1387                     {
  1261                     iLinkContents.Remove( iLinkContents.Count() - 1 );
  1388                     iLinkContents.Remove( iLinkContents.Count() - 1 );
  1262                     }
  1389                     }
  1263     
  1390 
  1264                 ASSERT( iLinkContents.Count() == iMessageParts.Count() );
  1391                 ASSERT( iLinkContents.Count() == iMessageParts.Count() );
  1265                 if(!iView.GetAsyncFetchStatus())
  1392                 if(!iView.GetAsyncFetchStatus())
  1266                     {
  1393                     {
  1267                     iAppUi.DownloadInfoMediator()->AddObserver( this, aAttachment.GetMessageId() );
  1394                     iAppUi.DownloadInfoMediator()->AddObserver( this, aAttachment.GetMessageId() );
  1268                     iObservingDownload=ETrue;
  1395                     iObservingDownload=ETrue;
  1275 
  1402 
  1276 void CFsEmailUiHtmlViewerContainer::SetHTMLResourceFlagFullName()
  1403 void CFsEmailUiHtmlViewerContainer::SetHTMLResourceFlagFullName()
  1277     {
  1404     {
  1278     FUNC_LOG;
  1405     FUNC_LOG;
  1279     iHtmlResourceFlagPath.Copy( iHtmlFolderPath );
  1406     iHtmlResourceFlagPath.Copy( iHtmlFolderPath );
  1280     iHtmlResourceFlagPath.Append( KHtmlFlagFile );    
  1407     iHtmlResourceFlagPath.Append( KHtmlFlagFile );
  1281     }
  1408     }
  1282 
  1409 
  1283 void CFsEmailUiHtmlViewerContainer::EnableHTMLResourceFlagL()
  1410 void CFsEmailUiHtmlViewerContainer::EnableHTMLResourceFlagL()
  1284     {
  1411     {
  1285     FUNC_LOG;
  1412     FUNC_LOG;
  1304     TFileName privatePath;
  1431     TFileName privatePath;
  1305     User::LeaveIfError( iFs.PrivatePath( privatePath ) );
  1432     User::LeaveIfError( iFs.PrivatePath( privatePath ) );
  1306     htmlFolderPathInZ.Append( privatePath );
  1433     htmlFolderPathInZ.Append( privatePath );
  1307 
  1434 
  1308     htmlFolderPathInZ.Append( KHtmlPath );
  1435     htmlFolderPathInZ.Append( KHtmlPath );
  1309     
  1436 
  1310     CDir* dirList;
  1437     CDir* dirList;
  1311     TPath listSpec;
  1438     TPath listSpec;
  1312     listSpec.Copy( htmlFolderPathInZ );
  1439     listSpec.Copy( htmlFolderPathInZ );
  1313      
  1440 
  1314     listSpec.Append( _L("*.*") );
  1441     listSpec.Append( _L("*.*") );
  1315     User::LeaveIfError( iFs.GetDir( listSpec,  KEntryAttMaskSupported, ESortByName, dirList ) );
  1442     User::LeaveIfError( iFs.GetDir( listSpec,  KEntryAttMaskSupported, ESortByName, dirList ) );
  1316     CleanupStack::PushL( dirList );
  1443     CleanupStack::PushL( dirList );
  1317     for ( TInt i=0; i < dirList->Count(); i++)
  1444     for ( TInt i=0; i < dirList->Count(); i++)
  1318         {
  1445         {
  1319         TPath sourceFileFullName;
  1446         TPath sourceFileFullName;
  1320         sourceFileFullName.Copy( htmlFolderPathInZ );
  1447         sourceFileFullName.Copy( htmlFolderPathInZ );
  1321         sourceFileFullName.Append( (*dirList)[i].iName );
  1448         sourceFileFullName.Append( (*dirList)[i].iName );
  1322         
  1449 
  1323         TBool isFolder( EFalse );
  1450         TBool isFolder( EFalse );
  1324         BaflUtils::IsFolder( iFs, sourceFileFullName, isFolder);
  1451         BaflUtils::IsFolder( iFs, sourceFileFullName, isFolder);
  1325         if ( isFolder )
  1452         if ( isFolder )
  1326             {
  1453             {
  1327             break;            
  1454             break;
  1328             }
  1455             }
  1329         
  1456 
  1330         TPath targetFileFullName;
  1457         TPath targetFileFullName;
  1331         targetFileFullName.Copy( iHtmlFolderPath );
  1458         targetFileFullName.Copy( iHtmlFolderPath );
  1332         targetFileFullName.Append( (*dirList)[i].iName );
  1459         targetFileFullName.Append( (*dirList)[i].iName );
  1333         BaflUtils::DeleteFile( iFs, targetFileFullName );        
  1460         BaflUtils::DeleteFile( iFs, targetFileFullName );
  1334         
  1461 
  1335         BaflUtils::CopyFile( iFs, sourceFileFullName, targetFileFullName);
  1462         BaflUtils::CopyFile( iFs, sourceFileFullName, targetFileFullName);
  1336         }    
  1463         }
  1337     CleanupStack::PopAndDestroy( dirList );
  1464     CleanupStack::PopAndDestroy( dirList );
  1338     }
  1465     }
  1339 
  1466 
  1340 void CFsEmailUiHtmlViewerContainer::EnsureHTMLResourceL()
  1467 void CFsEmailUiHtmlViewerContainer::EnsureHTMLResourceL()
  1341     {
  1468     {
  1342     FUNC_LOG;
  1469     FUNC_LOG;
  1343     
  1470 
  1344     if ( !HTMLResourceFlagEnabled() )
  1471     if ( !HTMLResourceFlagEnabled() )
  1345         {
  1472         {
  1346         CopyHTMLResourceL();
  1473         CopyHTMLResourceL();
  1347         EnableHTMLResourceFlagL();
  1474         EnableHTMLResourceFlagL();
  1348         }
  1475         }
  1350 
  1477 
  1351 // ---------------------------------------------------------------------------
  1478 // ---------------------------------------------------------------------------
  1352 // Writes buffer content to given file after adding tags
  1479 // Writes buffer content to given file after adding tags
  1353 // ---------------------------------------------------------------------------
  1480 // ---------------------------------------------------------------------------
  1354 //
  1481 //
  1355 // <cmail>
       
  1356 void CFsEmailUiHtmlViewerContainer::ConvertToHTML( const TDesC& aContent,
  1482 void CFsEmailUiHtmlViewerContainer::ConvertToHTML( const TDesC& aContent,
  1357     const TDesC& aFileName, CFSMailMessagePart& /*aTextBodyPart*/ )
  1483     const TDesC& aFileName, CFSMailMessagePart& /*aTextBodyPart*/ )
  1358     {
  1484     {
  1359     FUNC_LOG;
  1485     FUNC_LOG;
  1360     const TInt KBodyTextChunkSize = 2048;
  1486    
  1361     
       
  1362     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, aContent.Size(), EDriveC ) )
  1487     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, aContent.Size(), EDriveC ) )
  1363          {
  1488         {
  1364          // Can not write the data, there's not enough free space on disk.
  1489         // Can not write the data, there's not enough free space on disk.
  1365          User::Leave( KErrDiskFull );
  1490         User::Leave( KErrDiskFull );
  1366         }
  1491         }
  1367     else
  1492 
  1368         {
  1493     RBuf htmlText;
  1369         RBuf bodyBuf;
  1494     CleanupClosePushL( htmlText );
  1370         bodyBuf.CreateL( aContent.Size() + KBodyTextChunkSize );
       
  1371         bodyBuf.CleanupClosePushL();
       
  1372         bodyBuf.Insert( 0, aContent);
       
  1373         TInt maxlength = bodyBuf.MaxSize();
       
  1374         
  1495         
  1375         TInt position( 0 );
  1496     PlainTextToHtmlConverter::PlainTextToHtmlL( aContent, htmlText );
  1376         TBool EndOfString( EFalse );
  1497     WriteToFileL( aFileName, htmlText );
  1377         
  1498         
  1378         while ( !EndOfString )
  1499     CleanupStack::PopAndDestroy( &htmlText );
  1379             {
       
  1380             TInt startPosition = position;
       
  1381             TPtr segment( bodyBuf.MidTPtr( startPosition ) );
       
  1382             TInt i = 0;
       
  1383             
       
  1384             while(i < segment.Length())
       
  1385                 {
       
  1386                 TInt currentPos = position + i;
       
  1387                 TText ch = segment[i];
       
  1388                 
       
  1389                 switch( ch )
       
  1390                     {
       
  1391                     case KSOH:  // end of line for IMAP and POP
       
  1392                         bodyBuf.Delete( currentPos, 1 );
       
  1393                         maxlength = maxlength + KHtmlLineBreakCRLF().Length();
       
  1394                         bodyBuf.ReAlloc( maxlength );
       
  1395                         bodyBuf.Insert( currentPos, KHtmlLineBreakCRLF );
       
  1396                         i += KHtmlLineBreakCRLF().Length();
       
  1397                         segment.Set( bodyBuf.MidTPtr( startPosition ) );
       
  1398                         break;
       
  1399                     case KLF: // line feed
       
  1400                     case KUnicodeNewLineCharacter:
       
  1401                     case KUnicodeParagraphCharacter:
       
  1402                             maxlength = maxlength + KHtmlLineBreak().Length();
       
  1403                             bodyBuf.ReAlloc( maxlength );
       
  1404                             bodyBuf.Insert( currentPos, KHtmlLineBreak );
       
  1405                             i += KHtmlLineBreak().Length() + 1;
       
  1406                             segment.Set( bodyBuf.MidTPtr( startPosition ) );
       
  1407                         break;  
       
  1408                     case KQuotation:
       
  1409                         bodyBuf.Delete( currentPos, 1 );
       
  1410                         maxlength = maxlength + KHtmlQuotation().Length();
       
  1411                         bodyBuf.ReAlloc( maxlength );
       
  1412                         bodyBuf.Insert( currentPos, KHtmlQuotation );
       
  1413                         i += KHtmlQuotation().Length();
       
  1414                         segment.Set( bodyBuf.MidTPtr( startPosition ) );
       
  1415                         break;
       
  1416                     case KAmpersand:
       
  1417                         bodyBuf.Delete( currentPos, 1 );
       
  1418                         maxlength = maxlength + KHtmlAmpersand().Length();
       
  1419                         bodyBuf.ReAlloc( maxlength  );
       
  1420                         bodyBuf.Insert( currentPos, KHtmlAmpersand );
       
  1421                         i += KHtmlAmpersand().Length();
       
  1422                         segment.Set( bodyBuf.MidTPtr( startPosition ) );
       
  1423                         break;
       
  1424                     case KGreaterThan:
       
  1425                         bodyBuf.Delete( currentPos, 1 );
       
  1426                         maxlength = maxlength + KHtmlGreaterThan().Length();
       
  1427                         bodyBuf.ReAlloc( maxlength );
       
  1428                         bodyBuf.Insert( currentPos, KHtmlGreaterThan );
       
  1429                         i += KHtmlGreaterThan().Length();
       
  1430                         segment.Set( bodyBuf.MidTPtr( startPosition ) );
       
  1431                         break;
       
  1432                     case KLessThan:
       
  1433                         bodyBuf.Delete( currentPos, 1 );
       
  1434                         maxlength =  maxlength + KHtmlLessThan().Length();
       
  1435                         bodyBuf.ReAlloc( maxlength );
       
  1436                         bodyBuf.Insert( currentPos, KHtmlLessThan );
       
  1437                         i += KHtmlLessThan().Length();
       
  1438                         segment.Set( bodyBuf.MidTPtr( startPosition ) );
       
  1439                         break;
       
  1440                     default:
       
  1441                         i++;
       
  1442                         break;
       
  1443                     }
       
  1444                 }
       
  1445             position += segment.Length();
       
  1446             if ( ( bodyBuf.Length() - position ) <= 0 )
       
  1447                 {
       
  1448                 EndOfString = ETrue;
       
  1449                 }
       
  1450             }
       
  1451         
       
  1452         CreateHyperlinksFromUrlsL( bodyBuf );
       
  1453         
       
  1454         HBufC8* content8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( bodyBuf );
       
  1455         CleanupStack::PushL( content8 );        
       
  1456         
       
  1457         RFile targetFile;
       
  1458         CleanupClosePushL( targetFile );
       
  1459         User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) );
       
  1460         
       
  1461         RBuf8 messageHeader;
       
  1462         _LIT( KCharsetUtf8, "UTF-8" );
       
  1463         TInt bufSize = KHtmlHeader1().Length() + KCharsetUtf8().Length() + KHtmlHeader2().Length();
       
  1464         messageHeader.CreateL( bufSize );
       
  1465         messageHeader.CleanupClosePushL();
       
  1466         
       
  1467         messageHeader.Append( KHtmlHeader1 );
       
  1468         messageHeader.Append( KCharsetUtf8 );
       
  1469         messageHeader.Append( KHtmlHeader2 );
       
  1470 
       
  1471         RFileWriteStream fileStream( targetFile );
       
  1472         fileStream.PushL();
       
  1473         fileStream.WriteL( messageHeader.Ptr(), messageHeader.Length() );
       
  1474 
       
  1475         TInt bufPos( 0 );
       
  1476         TInt bufTotalSize = content8->Size();
       
  1477 
       
  1478         while ( bufPos < bufTotalSize )
       
  1479             {
       
  1480             TInt segmentLength = content8->Mid( bufPos ).Length();
       
  1481             fileStream.WriteL( content8->Mid( bufPos ).Ptr(), segmentLength );
       
  1482             bufPos += segmentLength;
       
  1483             }
       
  1484 
       
  1485         fileStream.CommitL();
       
  1486 
       
  1487         CleanupStack::PopAndDestroy( &fileStream );
       
  1488         CleanupStack::PopAndDestroy( &messageHeader );
       
  1489         CleanupStack::PopAndDestroy( &targetFile );
       
  1490         CleanupStack::PopAndDestroy( content8 );
       
  1491         CleanupStack::PopAndDestroy( &bodyBuf ); // calls bodyBuf.Close();
       
  1492 
       
  1493 // </cmail>
       
  1494         }
       
  1495     }
       
  1496 
       
  1497 // ---------------------------------------------------------------------------
       
  1498 // Finds and html formats hyperlinks in a document
       
  1499 // ---------------------------------------------------------------------------
       
  1500 //
       
  1501 // <cmail>
       
  1502 void CFsEmailUiHtmlViewerContainer::CreateHyperlinksFromUrlsL( RBuf& aSource )
       
  1503     {
       
  1504     FUNC_LOG;
       
  1505     const TInt searhCases( CFindItemEngine::EFindItemSearchURLBin );
       
  1506     CFindItemEngine* itemEngine = CFindItemEngine::NewL( aSource, CFindItemEngine::TFindItemSearchCase( searhCases ) );
       
  1507     CleanupStack::PushL ( itemEngine );
       
  1508     if ( itemEngine->ItemCount() > 0 )
       
  1509         {
       
  1510         _LIT( KSchemeDelimiter, "://" );
       
  1511         _LIT( KUrlFormat, "<a href=\"%S\">%S</a>" );
       
  1512         _LIT( KUrlFormatWithHttp, "<a href=\"http://%S\">%S</a>" );
       
  1513         
       
  1514         const TInt sourceLength( aSource.Length() );
       
  1515         // Allocate enough space for the final result
       
  1516         aSource.ReAllocL( sourceLength + TotalLengthOfItems( *itemEngine ) + KUrlFormatWithHttp().Length() * itemEngine->ItemCount() );
       
  1517         aSource.SetMax();
       
  1518         // Organize buffer so that original data is in the back of the aSource
       
  1519         aSource.RightTPtr( sourceLength ).Copy( aSource.Left( sourceLength ) );
       
  1520         // Set source to new original data's position
       
  1521         const TPtrC source( aSource.RightTPtr( sourceLength ) );
       
  1522         // Set target to aSource's beginning
       
  1523         TPtr target( aSource.MidTPtr( 0 ) );
       
  1524         // Reset length, we now have an empty buffer to fill
       
  1525         target.SetLength( 0 );
       
  1526         
       
  1527         TInt currentSourcePosition( 0 );
       
  1528         CFindItemEngine::SFoundItem item;
       
  1529         for ( TBool available( itemEngine->Item( item ) ); available; available = itemEngine->NextItem( item ) )
       
  1530             {
       
  1531             target.Append( source.Mid( currentSourcePosition, item.iStartPos - currentSourcePosition ) );
       
  1532             const TPtrC url( source.Mid( item.iStartPos, item.iLength ) );
       
  1533             TPtrC format( KUrlFormat() );
       
  1534             if ( url.FindF( KSchemeDelimiter() ) == KErrNotFound ) 
       
  1535                 {
       
  1536                 format.Set( KUrlFormatWithHttp() );
       
  1537                 }
       
  1538             HBufC* formatBuffer = HBufC::NewLC( format.Length() + url.Length() * 2 );
       
  1539             formatBuffer->Des().Format( format, &url, &url );            
       
  1540             target.Append( *formatBuffer );
       
  1541             CleanupStack::PopAndDestroy(); // formatBuffer
       
  1542             currentSourcePosition = item.iStartPos + item.iLength;
       
  1543             }        
       
  1544         // Append characters that are left in buffer
       
  1545         if ( currentSourcePosition < sourceLength )
       
  1546             {
       
  1547             target.Append( source.Mid( currentSourcePosition, sourceLength - currentSourcePosition ) );
       
  1548             }
       
  1549         aSource.SetLength( target.Length() );
       
  1550         }
       
  1551     CleanupStack::PopAndDestroy(); // itemEngine
       
  1552     }
  1500     }
  1553 
  1501 
  1554 
  1502 
  1555 TInt CFsEmailUiHtmlViewerContainer::TotalLengthOfItems( CFindItemEngine& aItemEngine ) const
  1503 TInt CFsEmailUiHtmlViewerContainer::TotalLengthOfItems( CFindItemEngine& aItemEngine ) const
  1556     {
  1504     {
  1571 //
  1519 //
  1572 // <cmail>
  1520 // <cmail>
  1573 HBufC8* CFsEmailUiHtmlViewerContainer::GetCharacterSetL( CFSMailMessagePart& aHtmlBodyPart )
  1521 HBufC8* CFsEmailUiHtmlViewerContainer::GetCharacterSetL( CFSMailMessagePart& aHtmlBodyPart )
  1574     {
  1522     {
  1575     FUNC_LOG;
  1523     FUNC_LOG;
  1576     
  1524 
  1577     CDesCArray& contentTypeArray( aHtmlBodyPart.ContentTypeParameters() );
  1525     CDesCArray& contentTypeArray( aHtmlBodyPart.ContentTypeParameters() );
  1578     HBufC8* charSet = KNullDesC8().AllocLC();   
  1526     HBufC8* charSet = KNullDesC8().AllocLC();
  1579     
  1527 
  1580     for ( TInt i = 0; i < contentTypeArray.Count(); i++ )
  1528     for ( TInt i = 0; i < contentTypeArray.Count(); i++ )
  1581         {
  1529         {
  1582         TPtrC contentEntry( contentTypeArray.MdcaPoint( i ) );
  1530         TPtrC contentEntry( contentTypeArray.MdcaPoint( i ) );
  1583         if ( ( contentEntry.FindF( KCharsetTag ) != KErrNotFound ) &&
  1531         if ( ( contentEntry.FindF( KCharsetTag ) != KErrNotFound ) &&
  1584                 contentTypeArray.Count() >= ( i+1) )  
  1532                 contentTypeArray.Count() >= ( i+1) )
  1585             {
  1533             {
  1586             TPtrC value( contentTypeArray.MdcaPoint( i+1 ) );
  1534             TPtrC value( contentTypeArray.MdcaPoint( i+1 ) );
  1587             if ( value.Length() )
  1535             if ( value.Length() )
  1588                 {
  1536                 {
  1589                 CleanupStack::PopAndDestroy( charSet );
  1537                 CleanupStack::PopAndDestroy( charSet );
  1593                 break;
  1541                 break;
  1594                 }
  1542                 }
  1595             }
  1543             }
  1596         i++;
  1544         i++;
  1597         }
  1545         }
  1598     
  1546 
  1599     CleanupStack::Pop( charSet );
  1547     CleanupStack::Pop( charSet );
  1600     return charSet;
  1548     return charSet;
  1601     }
  1549     }
  1602 
  1550 
  1603 void CFsEmailUiHtmlViewerContainer::StopObserving()
  1551 void CFsEmailUiHtmlViewerContainer::StopObserving()
  1615 void CFsEmailUiHtmlViewerContainer::CancelFetch()
  1563 void CFsEmailUiHtmlViewerContainer::CancelFetch()
  1616     {
  1564     {
  1617     FUNC_LOG;
  1565     FUNC_LOG;
  1618     if ( iBrCtlInterface )
  1566     if ( iBrCtlInterface )
  1619         {
  1567         {
  1620         TRAP_IGNORE( iBrCtlInterface->HandleCommandL( (TInt)TBrCtlDefs::ECommandCancelFetch + (TInt)TBrCtlDefs::ECommandIdBase )); 
  1568         TRAP_IGNORE( iBrCtlInterface->HandleCommandL( (TInt)TBrCtlDefs::ECommandCancelFetch + (TInt)TBrCtlDefs::ECommandIdBase ));
  1621         }   
  1569         }
  1622     }
  1570     }
  1623 
  1571 
  1624 void CFsEmailUiHtmlViewerContainer::ClearCacheAndLoadEmptyContent()
  1572 void CFsEmailUiHtmlViewerContainer::ClearCacheAndLoadEmptyContent()
  1625     {
  1573     {
  1626     FUNC_LOG;
  1574     FUNC_LOG;
  1627     if ( iBrCtlInterface )
  1575     if ( iBrCtlInterface )
  1628         {
  1576         {
  1629         iBrCtlInterface->ClearCache(); 
  1577         iBrCtlInterface->ClearCache();
  1630         TUid uid;
  1578         TUid uid;
  1631         uid.iUid = KCharacterSetIdentifierUtf8;
  1579         uid.iUid = KCharacterSetIdentifierUtf8;
  1632         TRAP_IGNORE( iBrCtlInterface->LoadDataL(KHTMLDataScheme, KHTMLEmptyContent, _L8("text/html"), uid) );
  1580         TRAP_IGNORE( iBrCtlInterface->LoadDataL(KHTMLDataScheme, KHTMLEmptyContent, _L8("text/html"), uid) );
  1633         }   
  1581         }
  1634     }
  1582     }
  1635 
  1583 
  1636 void CFsEmailUiHtmlViewerContainer::HandleResourceChange( TInt aType )
  1584 void CFsEmailUiHtmlViewerContainer::HandleResourceChange( TInt aType )
  1637     {
  1585     {
  1638     CCoeControl::HandleResourceChange( aType );
  1586     CCoeControl::HandleResourceChange( aType );
  1649         {
  1597         {
  1650         // Update the width in header part and reload
  1598         // Update the width in header part and reload
  1651         TPath headerHtmlFile;
  1599         TPath headerHtmlFile;
  1652         headerHtmlFile.Copy( iHtmlFolderPath );
  1600         headerHtmlFile.Copy( iHtmlFolderPath );
  1653         headerHtmlFile.Append( KHeaderHtmlFile );
  1601         headerHtmlFile.Append( KHeaderHtmlFile );
  1654         
  1602 
  1655             TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs,
  1603             TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs,
  1656                 headerHtmlFile, iAppUi.ClientRect().Width(), iScrollPosition,
  1604                 headerHtmlFile, iAppUi.ClientRect().Width(), iScrollPosition,
  1657                 iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage),
  1605                 iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage),
  1658                 iHeaderExpanded ) )
  1606                 iHeaderExpanded ) )
  1659         
  1607 
  1660         
  1608 
  1661         if(!iEventHandler->IsMenuVisible())
  1609         if(!iEventHandler->IsMenuVisible())
  1662             {
  1610             {
  1663             TRAP_IGNORE( ReloadPageL() );
  1611             TRAP_IGNORE( ReloadPageL() );
  1664             }
  1612             }
  1665         else
  1613         else
  1666             {
  1614             {
  1667             //Load page asynchronously after dismissing menu 
  1615             //Load page asynchronously after dismissing menu
  1668             //this is outdated call because it cancels Action menu which is no longer used in 9.2
  1616             //this is outdated call because it cancels Action menu which is no longer used in 9.2
  1669            // iEventHandler->DismissMenuAndReload();
  1617            // iEventHandler->DismissMenuAndReload();
  1670             }
  1618             }
  1671         }
  1619         }
  1672     }
  1620     }
  1675     {
  1623     {
  1676     TRAP_IGNORE( iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
  1624     TRAP_IGNORE( iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
  1677             ( TInt )TBrCtlDefs::ECommandReload ) );
  1625             ( TInt )TBrCtlDefs::ECommandReload ) );
  1678     }
  1626     }
  1679 
  1627 
  1680 void CFsEmailUiHtmlViewerContainer::ShowAttachmentDownloadStatusL( 
  1628 void CFsEmailUiHtmlViewerContainer::ShowAttachmentDownloadStatusL(
  1681         TFSProgress::TFSProgressStatus aProgressStatus, 
  1629         TFSProgress::TFSProgressStatus aProgressStatus,
  1682         const TAttachmentData& aAttachmentData )
  1630         const TAttachmentData& aAttachmentData )
  1683     {
  1631     {
  1684     TBool freshDraw = EFalse;
  1632     TBool freshDraw = EFalse;
  1685     //If the indicator was displaying fetching body then we will be displaying a different indicator
  1633     //If the indicator was displaying fetching body then we will be displaying a different indicator
  1686     //this is just to make sure the image is updated
  1634     //this is just to make sure the image is updated
  1697     if ( !iStatusIndicator )
  1645     if ( !iStatusIndicator )
  1698         {
  1646         {
  1699         TRect rect = CalcAttachmentStatusRect();
  1647         TRect rect = CalcAttachmentStatusRect();
  1700         iStatusIndicator = CFreestyleEmailUiAknStatusIndicator::NewL( rect, this );
  1648         iStatusIndicator = CFreestyleEmailUiAknStatusIndicator::NewL( rect, this );
  1701         freshDraw = ETrue;
  1649         freshDraw = ETrue;
  1702         }    
  1650         }
  1703     
  1651 
  1704     if ( !iStatusIndicator->IsVisible() 
  1652     if ( !iStatusIndicator->IsVisible()
  1705          || ( aAttachmentData.downloadProgress == KNone ) 
  1653          || ( aAttachmentData.downloadProgress == KNone )
  1706          || ( aProgressStatus == TFSProgress::EFSStatus_RequestCancelled ) )
  1654          || ( aProgressStatus == TFSProgress::EFSStatus_RequestCancelled ) )
  1707         {
  1655         {
  1708         freshDraw = ETrue;
  1656         freshDraw = ETrue;
  1709         }
  1657         }
  1710     
  1658 
  1711     TInt duration = KStatusIndicatorDefaultDuration;
  1659     TInt duration = KStatusIndicatorDefaultDuration;
  1712     if ( ( aAttachmentData.downloadProgress == TFSProgress::EFSStatus_RequestComplete ) 
  1660     if ( ( aAttachmentData.downloadProgress == TFSProgress::EFSStatus_RequestComplete )
  1713          || ( aProgressStatus == TFSProgress::EFSStatus_RequestCancelled ) 
  1661          || ( aProgressStatus == TFSProgress::EFSStatus_RequestCancelled )
  1714          || ( aAttachmentData.downloadProgress == KComplete ) )
  1662          || ( aAttachmentData.downloadProgress == KComplete ) )
  1715         {
  1663         {
  1716         duration = KStatusIndicatorAutomaticHidingDuration;
  1664         duration = KStatusIndicatorAutomaticHidingDuration;
  1717         }
  1665         }
  1718 
  1666 
  1726             CleanupStack::PushL( descArray );
  1674             CleanupStack::PushL( descArray );
  1727             descArray->AppendL( aAttachmentData.fileName );
  1675             descArray->AppendL( aAttachmentData.fileName );
  1728             CArrayFix<TInt>* intArray = new (ELeave) CArrayFixFlat<TInt>( 1 );
  1676             CArrayFix<TInt>* intArray = new (ELeave) CArrayFixFlat<TInt>( 1 );
  1729             CleanupStack::PushL( intArray );
  1677             CleanupStack::PushL( intArray );
  1730             intArray->AppendL( aAttachmentData.downloadProgress );
  1678             intArray->AppendL( aAttachmentData.downloadProgress );
  1731             
  1679 
  1732             statusText = StringLoader::LoadL( R_FSE_VIEWER_ATTACHMENTS_LIST_DOWNLOAD,
  1680             statusText = StringLoader::LoadL( R_FSE_VIEWER_ATTACHMENTS_LIST_DOWNLOAD,
  1733                                               *descArray, 
  1681                                               *descArray,
  1734                                               *intArray );
  1682                                               *intArray );
  1735             CleanupStack::PopAndDestroy( intArray );
  1683             CleanupStack::PopAndDestroy( intArray );
  1736             CleanupStack::PopAndDestroy( descArray );
  1684             CleanupStack::PopAndDestroy( descArray );
  1737             CleanupStack::PushL( statusText );
  1685             CleanupStack::PushL( statusText );
  1738             }
  1686             }
  1739         break;
  1687         break;
  1740         
  1688 
  1741         case TFSProgress::EFSStatus_RequestCancelled:
  1689         case TFSProgress::EFSStatus_RequestCancelled:
  1742             {
  1690             {
  1743             statusText = aAttachmentData.fileName.AllocLC();
  1691             statusText = aAttachmentData.fileName.AllocLC();
  1744             }
  1692             }
  1745         break;
  1693         break;
  1746         
  1694 
  1747         default:
  1695         default:
  1748             statusText = KNullDesC().AllocLC();
  1696             statusText = KNullDesC().AllocLC();
  1749             break;
  1697             break;
  1750         }
  1698         }
  1751 
  1699 
  1776                 {
  1724                 {
  1777                 iStatusIndicator->HideIndicator( duration );
  1725                 iStatusIndicator->HideIndicator( duration );
  1778                 }
  1726                 }
  1779             }
  1727             }
  1780         }
  1728         }
  1781     
  1729 
  1782     CleanupStack::Pop( statusText );
  1730     CleanupStack::Pop( statusText );
  1783     }
  1731     }
  1784 
  1732 
  1785 TBool CFsEmailUiHtmlViewerContainer::AttachmentDownloadStatusVisible()
  1733 TBool CFsEmailUiHtmlViewerContainer::AttachmentDownloadStatusVisible()
  1786     {
  1734     {
  1822 TRect CFsEmailUiHtmlViewerContainer::CalcAttachmentStatusRect()
  1770 TRect CFsEmailUiHtmlViewerContainer::CalcAttachmentStatusRect()
  1823     {
  1771     {
  1824     TRect rect = Rect();
  1772     TRect rect = Rect();
  1825     TPoint topLeft = rect.iTl;
  1773     TPoint topLeft = rect.iTl;
  1826     TPoint bottomRight = rect.iBr;
  1774     TPoint bottomRight = rect.iBr;
  1827     
  1775 
  1828     TPoint statusTopLeft( topLeft.iX + KStatusIndicatorXMargin, bottomRight.iY - KStatusIndicatorHeight + 1 );
  1776     TPoint statusTopLeft( topLeft.iX + KStatusIndicatorXMargin, bottomRight.iY - KStatusIndicatorHeight + 1 );
  1829     TPoint statusBottomRight( bottomRight.iX - KStatusIndicatorXMargin, bottomRight.iY );
  1777     TPoint statusBottomRight( bottomRight.iX - KStatusIndicatorXMargin, bottomRight.iY );
  1830     return TRect( statusTopLeft, statusBottomRight );
  1778     return TRect( statusTopLeft, statusBottomRight );
  1831     }
  1779     }
  1832 
  1780 
  1833 void CFsEmailUiHtmlViewerContainer::TouchFeedback()
  1781 void CFsEmailUiHtmlViewerContainer::TouchFeedback()
  1834     {
  1782     {
  1835     iTouchFeedBack->InstantFeedback(this, ETouchFeedbackBasic);  
  1783     iTouchFeedBack->InstantFeedback(this, ETouchFeedbackBasic);
  1836     }
  1784     }
  1837 
  1785 
  1838 /**
  1786 /**
  1839  * The body fetch link is cmail://body/fetch. Look for the URL separator
  1787  * The body fetch link is cmail://body/fetch. Look for the URL separator
  1840  * and the presence of cmail and body on the url.
  1788  * and the presence of cmail and body on the url.
  1841  * @param aUrl 
  1789  * @param aUrl
  1842  * return ETrue for  a valid body URL
  1790  * return ETrue for  a valid body URL
  1843  */
  1791  */
  1844 TBool CFsEmailUiHtmlViewerContainer::IsMessageBodyURLL(const TDesC& aUrl)
  1792 TBool CFsEmailUiHtmlViewerContainer::IsMessageBodyURLL(const TDesC& aUrl)
  1845     {
  1793     {
  1846     TInt index = aUrl.Find(KURLSchemeSeparator);
  1794     TInt index = aUrl.Find(KURLSchemeSeparator);
  1873             }
  1821             }
  1874         else if (aUrl.Compare(KURLExpandHeader()) == 0)
  1822         else if (aUrl.Compare(KURLExpandHeader()) == 0)
  1875             {
  1823             {
  1876             TouchFeedback();
  1824             TouchFeedback();
  1877             iHeaderExpanded = ETrue;
  1825             iHeaderExpanded = ETrue;
  1878             return ETrue;        
  1826             return ETrue;
  1879             }
  1827             }
  1880         else if (aUrl.Left(index).CompareF(KURLSchemeCmail) == 0)
  1828         else if (aUrl.Left(index).CompareF(KURLSchemeCmail) == 0)
  1881             {
  1829             {
  1882             TInt bodyIndex = aUrl.Find(KURLTypeBody);                      
  1830             TInt bodyIndex = aUrl.Find(KURLTypeBody);
  1883             if (bodyIndex == KErrNotFound)
  1831             if (bodyIndex == KErrNotFound)
  1884                 {
  1832                 {
  1885                 return EFalse;
  1833                 return EFalse;
  1886                 }
  1834                 }
  1887             else
  1835             else
  1894                     }
  1842                     }
  1895                 else
  1843                 else
  1896                     {
  1844                     {
  1897                     TPtrC16 temp = data.Mid(separator+1);
  1845                     TPtrC16 temp = data.Mid(separator+1);
  1898                     TLex lex(temp);
  1846                     TLex lex(temp);
  1899                     lex.Val(iScrollPosition);                  
  1847                     lex.Val(iScrollPosition);
  1900                     }
  1848                     }
  1901                 return ETrue;
  1849                 return ETrue;
  1902                 }
  1850                 }
  1903             
  1851 
  1904             }
  1852             }
  1905         else
  1853         else
  1906             {
  1854             {
  1907             return EFalse;
  1855             return EFalse;
  1908             }
  1856             }
  1909         }
  1857         }
  1910     } 
  1858     }
  1911 
  1859 
  1912 // ---------------------------------------------------------------------------
  1860 // ---------------------------------------------------------------------------
  1913 // From MBrCtlWindowObserver
  1861 // From MBrCtlWindowObserver
  1914 // ---------------------------------------------------------------------------
  1862 // ---------------------------------------------------------------------------
  1915 //
  1863 //
  1916 CBrCtlInterface* CFsEmailUiHtmlViewerContainer::OpenWindowL( TDesC& /*aUrl*/, TDesC* /*aTargetName*/, 
  1864 CBrCtlInterface* CFsEmailUiHtmlViewerContainer::OpenWindowL( TDesC& /*aUrl*/, TDesC* /*aTargetName*/,
  1917                                                              TBool /*aUserInitiated*/, TAny* /*aReserved*/ )
  1865                                                              TBool /*aUserInitiated*/, TAny* /*aReserved*/ )
  1918     {
  1866     {
  1919     return iBrCtlInterface;
  1867     return iBrCtlInterface;
  1920     }
  1868     }
  1921 
  1869 
  1930 
  1878 
  1931 // ---------------------------------------------------------------------------
  1879 // ---------------------------------------------------------------------------
  1932 // From MBrCtlWindowObserver
  1880 // From MBrCtlWindowObserver
  1933 // ---------------------------------------------------------------------------
  1881 // ---------------------------------------------------------------------------
  1934 //
  1882 //
  1935 void CFsEmailUiHtmlViewerContainer::HandleWindowCommandL( const TDesC& /*aTargetName*/, 
  1883 void CFsEmailUiHtmlViewerContainer::HandleWindowCommandL( const TDesC& /*aTargetName*/,
  1936                                                           TBrCtlWindowCommand /*aCommand*/ )
  1884                                                           TBrCtlWindowCommand /*aCommand*/ )
  1937     {
  1885     {
  1938     
  1886 
  1939     }
  1887     }
  1940 
  1888 
  1941 // ---------------------------------------------------------------------------
  1889 // ---------------------------------------------------------------------------
  1942 // Check if a tap on the URL requires browser(standalone) to be launched
  1890 // Check if a tap on the URL requires browser(standalone) to be launched
  1943 // ---------------------------------------------------------------------------
  1891 // ---------------------------------------------------------------------------
  1946     {
  1894     {
  1947     TBool launchBrowser( ETrue );
  1895     TBool launchBrowser( ETrue );
  1948     // look for file:///
  1896     // look for file:///
  1949     _LIT( KFileLink, "file:///");
  1897     _LIT( KFileLink, "file:///");
  1950     _LIT( KUrlLink, "http");
  1898     _LIT( KUrlLink, "http");
  1951     
  1899 
  1952     // This might be linking to header.html or body.html frames
  1900     // This might be linking to header.html or body.html frames
  1953     // Ignore them.
  1901     // Ignore them.
  1954     if ( aUrl.Left( KFileLink().Length() ).CompareF( KFileLink ) == 0 )
  1902     if ( aUrl.Left( KFileLink().Length() ).CompareF( KFileLink ) == 0 )
  1955         {
  1903         {
  1956         //Now there is a chance that this could be from HTML folder
  1904         //Now there is a chance that this could be from HTML folder
  1957         // Replace all slash character with backslash characters
  1905         // Replace all slash character with backslash characters
  1958         HBufC* embeddedUrl = aUrl.AllocLC();
  1906         HBufC* embeddedUrl = aUrl.AllocLC();
  1959         TPtr ptr = embeddedUrl->Des();
  1907         TPtr ptr = embeddedUrl->Des();
  1960         
  1908 
  1961         _LIT( KBackslash, "\\" );
  1909         _LIT( KBackslash, "\\" );
  1962         for ( TInt pos = ptr.Locate('/'); pos >= 0; pos = ptr.Locate('/') )
  1910         for ( TInt pos = ptr.Locate('/'); pos >= 0; pos = ptr.Locate('/') )
  1963             {
  1911             {
  1964             ptr.Replace( pos, 1, KBackslash );
  1912             ptr.Replace( pos, 1, KBackslash );
  1965             }
  1913             }
  1966 
  1914 
  1967         // Check whether given url refers to file in the html folder
  1915         // Check whether given url refers to file in the html folder
  1968         TInt pos = embeddedUrl->FindF( iHtmlFolderPath );
  1916         TInt pos = embeddedUrl->FindF( iHtmlFolderPath );
  1969         CleanupStack::PopAndDestroy( embeddedUrl );
  1917         CleanupStack::PopAndDestroy( embeddedUrl );
  1970         pos >= 0 ? launchBrowser = EFalse : ETrue;        
  1918         pos >= 0 ? launchBrowser = EFalse : ETrue;
  1971         }
  1919         }
  1972     // Ignore links starting with cmail://
  1920     // Ignore links starting with cmail://
  1973     else if ( aUrl.Left( KURLSchemeCmail().Length() ).CompareF( KURLSchemeCmail ) == 0 )
  1921     else if ( aUrl.Left( KURLSchemeCmail().Length() ).CompareF( KURLSchemeCmail ) == 0 )
  1974         {
  1922         {
  1975         launchBrowser = EFalse;
  1923         launchBrowser = EFalse;
  1976         }
  1924         }
  1977     //    THAA-82BEAZ - show popup first 
  1925     //    THAA-82BEAZ - show popup first
  1978     else if ( aUrl.Left(KUrlLink().Length() ).CompareF( KUrlLink ) == 0 )
  1926     else if ( aUrl.Left(KUrlLink().Length() ).CompareF( KUrlLink ) == 0 )
  1979         {
  1927         {
  1980         launchBrowser = EFalse;
  1928         launchBrowser = EFalse;
  1981         }
  1929         }
  1982     // end THAA-82BEAZ
  1930     // end THAA-82BEAZ
  1996     CleanupStack::PopAndDestroy( handler );
  1944     CleanupStack::PopAndDestroy( handler );
  1997     }
  1945     }
  1998 
  1946 
  1999 void CFsEmailUiHtmlViewerContainer::PrepareBodyHtmlL( const TDesC& aFileName )
  1947 void CFsEmailUiHtmlViewerContainer::PrepareBodyHtmlL( const TDesC& aFileName )
  2000     {
  1948     {
  2001     
  1949 
  2002     if( iMessage )
  1950     if( iMessage )
  2003         {
  1951         {
  2004         CFSMailMessagePart* htmlBodyPart = iMessage->HtmlBodyPartL();
  1952         CFSMailMessagePart* htmlBodyPart = iMessage->HtmlBodyPartL();
  2005 
  1953 
  2006         if ( htmlBodyPart )
  1954         if ( htmlBodyPart )
  2011             CleanupStack::PopAndDestroy( htmlBodyPart );
  1959             CleanupStack::PopAndDestroy( htmlBodyPart );
  2012             }
  1960             }
  2013         else
  1961         else
  2014             {
  1962             {
  2015             CFSMailMessagePart* textBodyPart = iMessage->PlainTextBodyPartL();
  1963             CFSMailMessagePart* textBodyPart = iMessage->PlainTextBodyPartL();
  2016     
  1964 
  2017             if ( textBodyPart )
  1965             if ( textBodyPart )
  2018                 {
  1966                 {
  2019                 CleanupStack::PushL( textBodyPart );
  1967                 CleanupStack::PushL( textBodyPart );
  2020                 // Copy html body part to email html file
  1968                 // Copy html body part to email html file
  2021                 ConvertToHtmlFileL( *textBodyPart, aFileName );
  1969                 ConvertToHtmlFileL( *textBodyPart, aFileName );
  2063     {
  2011     {
  2064     FUNC_LOG;
  2012     FUNC_LOG;
  2065     UpdateOverlayButtons( IsVisible() );    
  2013     UpdateOverlayButtons( IsVisible() );    
  2066     }
  2014     }
  2067 
  2015 
       
  2016 
       
  2017 void CFsEmailUiHtmlViewerContainer::WriteToFileL(const TDesC& aFileName, RBuf& aHtmlText)
       
  2018     {
       
  2019     _LIT( KCharsetUtf8, "UTF-8" );
       
  2020 
       
  2021     HBufC8* content8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aHtmlText );
       
  2022     CleanupStack::PushL( content8 );        
       
  2023         
       
  2024     RFile targetFile;
       
  2025     CleanupClosePushL( targetFile );
       
  2026     User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) );
       
  2027         
       
  2028     RBuf8 messageHeader;
       
  2029     TInt bufSize = KHtmlHeader1().Length() + KCharsetUtf8().Length() + KHtmlHeader2().Length();
       
  2030     messageHeader.CreateL( bufSize );
       
  2031     messageHeader.CleanupClosePushL();
       
  2032         
       
  2033     messageHeader.Append( KHtmlHeader1 );
       
  2034     messageHeader.Append( KCharsetUtf8 );
       
  2035     messageHeader.Append( KHtmlHeader2 );
       
  2036 
       
  2037     RFileWriteStream fileStream( targetFile );
       
  2038     fileStream.PushL();
       
  2039     fileStream.WriteL( messageHeader.Ptr(), messageHeader.Length() );
       
  2040 
       
  2041     TInt bufPos( 0 );
       
  2042     TInt bufTotalSize = content8->Size();
       
  2043 
       
  2044     while ( bufPos < bufTotalSize )
       
  2045         {
       
  2046         TInt segmentLength = content8->Mid( bufPos ).Length();
       
  2047         fileStream.WriteL( content8->Mid( bufPos ).Ptr(), segmentLength );
       
  2048         bufPos += segmentLength;
       
  2049         }
       
  2050 
       
  2051     fileStream.CommitL();
       
  2052 
       
  2053     CleanupStack::PopAndDestroy( &fileStream );
       
  2054     CleanupStack::PopAndDestroy( &messageHeader );
       
  2055     CleanupStack::PopAndDestroy( &targetFile );
       
  2056     CleanupStack::PopAndDestroy( content8 );
       
  2057     }
       
  2058 
       
  2059 
       
  2060 
       
  2061 /******************************************************************************
       
  2062  * class PlainTextToHtmlConverter
       
  2063  ******************************************************************************/
       
  2064 
       
  2065 
       
  2066 
       
  2067 // -----------------------------------------------------------------------------
       
  2068 // PlainTextToHtmlConverter::PlainTextToHtmlL
       
  2069 // 
       
  2070 // -----------------------------------------------------------------------------
       
  2071 //
       
  2072 void PlainTextToHtmlConverter::PlainTextToHtmlL(const TDesC& aPlainText, RBuf& aHtmlText)
       
  2073     {
       
  2074     const TInt KAllocSize = 1024;
       
  2075     
       
  2076     aHtmlText.Close();
       
  2077     aHtmlText.Create( aPlainText.Length() + KAllocSize );
       
  2078     
       
  2079     const TInt searhCases( CFindItemEngine::EFindItemSearchURLBin );
       
  2080     CFindItemEngine* itemEngine = CFindItemEngine::NewL( aPlainText, CFindItemEngine::TFindItemSearchCase( searhCases ) );
       
  2081     CleanupStack::PushL ( itemEngine );
       
  2082     
       
  2083     TInt currentPos = 0;
       
  2084     CFindItemEngine::SFoundItem item;
       
  2085     for ( TBool available(itemEngine->Item(item)); available; available=itemEngine->NextItem(item) )
       
  2086         {
       
  2087         if ( item.iStartPos < currentPos )
       
  2088             {
       
  2089             break; 
       
  2090             }
       
  2091         
       
  2092         TPtrC textPtr = aPlainText.Mid( currentPos, item.iStartPos-currentPos );
       
  2093         ConvertTextL( textPtr, aHtmlText );
       
  2094         
       
  2095         TPtrC urlPtr = aPlainText.Mid( item.iStartPos, item.iLength );
       
  2096         ConvertUrlL( urlPtr, aHtmlText);
       
  2097         
       
  2098         currentPos = item.iStartPos + item.iLength;
       
  2099         }
       
  2100     
       
  2101     TInt len = aPlainText.Length();
       
  2102     if ( currentPos < len )
       
  2103         {
       
  2104         TPtrC textPtr = aPlainText.Mid( currentPos );
       
  2105         ConvertTextL( textPtr, aHtmlText );
       
  2106         }
       
  2107     
       
  2108     CleanupStack::PopAndDestroy( itemEngine );
       
  2109     }
       
  2110 
       
  2111 
       
  2112 // -----------------------------------------------------------------------------
       
  2113 // PlainTextToHtmlConverter::ConvertTextL
       
  2114 // 
       
  2115 // -----------------------------------------------------------------------------
       
  2116 //
       
  2117 void PlainTextToHtmlConverter::ConvertTextL(const TDesC& aSource, RBuf& aTarget)
       
  2118     {
       
  2119     const TInt KAllocSize = 1024;
       
  2120     const TInt KEntitySize = 32;
       
  2121     
       
  2122     TInt count = aSource.Length();
       
  2123     for ( TInt i=0; i<count; i++ )
       
  2124         {
       
  2125         if ( aTarget.Length() + KEntitySize >= aTarget.MaxLength() )
       
  2126             {
       
  2127             aTarget.ReAllocL( aTarget.MaxLength() + KAllocSize );
       
  2128             }
       
  2129         
       
  2130         TText ch = aSource[i];
       
  2131         switch( ch )
       
  2132             {
       
  2133             case KSOH:  // end of line for IMAP and POP
       
  2134                 aTarget.Append( KHtmlLineBreakCRLF );
       
  2135                 break;
       
  2136             case KLF: // line feed
       
  2137             case KUnicodeNewLineCharacter:
       
  2138             case KUnicodeParagraphCharacter:
       
  2139                 aTarget.Append(KHtmlLineBreak);
       
  2140                 break;  
       
  2141             case KQuotation:
       
  2142                 aTarget.Append( KHtmlQuotation );
       
  2143                 break;
       
  2144             case KAmpersand:
       
  2145                 aTarget.Append( KHtmlAmpersand );
       
  2146                 break;
       
  2147             case KGreaterThan:
       
  2148                 aTarget.Append( KHtmlGreaterThan );
       
  2149                 break;
       
  2150             case KLessThan:
       
  2151                 aTarget.Append( KHtmlLessThan );
       
  2152                 break;
       
  2153             default:
       
  2154                 aTarget.Append( ch );
       
  2155                 break;
       
  2156             }
       
  2157         }
       
  2158     }
       
  2159 
       
  2160 
       
  2161 // -----------------------------------------------------------------------------
       
  2162 // PlainTextToHtmlConverter::ConvertUrlL
       
  2163 // 
       
  2164 // -----------------------------------------------------------------------------
       
  2165 //
       
  2166 void PlainTextToHtmlConverter::ConvertUrlL(const TDesC& aSource, RBuf& aTarget)
       
  2167     {
       
  2168     _LIT( KSchemeDelimiter, "://" );
       
  2169     _LIT( KUrlFormat, "<a href=\"%S\">%S</a>" );
       
  2170     _LIT( KUrlFormatWithHttp, "<a href=\"http://%S\">%S</a>" );
       
  2171         
       
  2172     TPtrC format( KUrlFormat() );
       
  2173     if ( aSource.FindF( KSchemeDelimiter() ) == KErrNotFound ) 
       
  2174         {
       
  2175         format.Set( KUrlFormatWithHttp() );
       
  2176         }
       
  2177     
       
  2178     HBufC* formatBuffer = HBufC::NewLC( format.Length() + aSource.Length() * 2 );
       
  2179     formatBuffer->Des().Format( format, &aSource, &aSource );            
       
  2180     
       
  2181     TInt len = formatBuffer->Des().Length();
       
  2182     if ( aTarget.Length() + len >= aTarget.MaxLength() )
       
  2183         {
       
  2184         aTarget.ReAllocL( aTarget.MaxLength() + len );
       
  2185         }
       
  2186 
       
  2187     aTarget.Append( *formatBuffer );
       
  2188         
       
  2189     CleanupStack::PopAndDestroy( formatBuffer );
       
  2190     }