emailuis/emailui/src/FreestyleEmailUiHtmlViewerContainer.cpp
branchRCL_3
changeset 64 3533d4323edc
child 70 968773a0b6ef
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CFsEmailUiHtmlViewerContainer class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <AknsDrawUtils.h>
       
    21 #include <coemain.h>
       
    22 #include <commdbconnpref.h>
       
    23 #include <bautils.h>
       
    24 #include <biditext.h>
       
    25 #include <StringLoader.h>
       
    26 #include <e32base.h>
       
    27 #include <badesca.h>
       
    28 #include <utf.h>
       
    29 #include <finditemengine.h>
       
    30 
       
    31 //<cmail>
       
    32 #include "cfsmailmessage.h"
       
    33 //</cmail>
       
    34 #include <brctlinterface.h>
       
    35 #include <sysutil.h>
       
    36 #include <schemehandler.h>
       
    37 
       
    38 #include <FreestyleEmailUi.rsg>
       
    39 
       
    40 #include "FreestyleEmailUiAppui.h"
       
    41 #include "FreestyleEmailUiUtilities.h"
       
    42 #include "FreestyleEmailUiHtmlViewerContainer.h"
       
    43 #include "FreestyleEmailUiHtmlViewerView.h"
       
    44 #include "FreestyleEmailUiShortcutBinding.h"
       
    45 
       
    46 #include "FreestyleMessageHeaderHTML.h"
       
    47 #include "FreestyleMessageHeaderURLEventHandler.h"
       
    48 #include "FreestyleEmailUiAttachmentsListModel.h"
       
    49 
       
    50 _LIT( KContentIdPrefix, "cid:" );
       
    51 _LIT( KCDrive, "c:" );
       
    52 _LIT( KHtmlPath, "HtmlFile\\" );
       
    53 _LIT( KTempHtmlPath, "temp\\" );
       
    54 _LIT( KAllFiles, "*" );
       
    55 
       
    56 _LIT( KHeaderHtmlFile, "header.html" );
       
    57 _LIT( KBodyHtmlFile, "body.html" );
       
    58 _LIT( KMessageHtmlFile, "email.html" );
       
    59 _LIT( KMessageHtmlRTLFile, "email_rtl.html" );
       
    60 _LIT( KZDrive, "z:" );
       
    61 _LIT( KHtmlFlagFile, "html.flag" );
       
    62 _LIT( KURLSlash, "/");
       
    63 // Constants used in html content modification
       
    64 const TInt KMaxCharsToSearch( 200 );
       
    65 _LIT8( KStartTag, "<html" );
       
    66 _LIT8( KHeadTag, "<head>");
       
    67 _LIT8( KHtmlHeader1, "<html><head><title></title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=");
       
    68 _LIT8( KHtmlHeader2, "\"/></head><body bgcolor=\"#ECECEC\">\xD\xA");
       
    69 _LIT8( KHtmlHeader3, "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=%S\">\n");
       
    70 _LIT8( KHtmlEndTags, "\xD\xA</body></html>\xD\xA");
       
    71 _LIT8( KCharsetTag8, "charset");
       
    72 _LIT( KCharsetTag, "charset");
       
    73 _LIT8( KHTMLEmptyContent, "<html><body></body></html>");
       
    74 _LIT( KHTMLDataScheme, "data:0");
       
    75 
       
    76 
       
    77 _LIT( KHtmlLineBreak, "<br>" );
       
    78 _LIT( KHtmlLineBreakCRLF, "<br>\xD\xA" );
       
    79 _LIT( KHtmlLessThan, "&lt;" );
       
    80 _LIT( KHtmlGreaterThan, "&gt;" );
       
    81 _LIT( KHtmlAmpersand, "&amp;" );
       
    82 _LIT( KHtmlQuotation, "&quot;" );
       
    83 _LIT( KURLTypeBody, "body");
       
    84 
       
    85 _LIT( KURLDisplayImages, "cmail://displayImages/" );
       
    86 _LIT( KURLLoadImages, "cmail://loadImages/" );
       
    87 _LIT( KURLCollapseHeader, "cmail://collapseHeader/" );
       
    88 _LIT( KURLExpandHeader, "cmail://expandHeader/" );
       
    89 _LIT( KURLExpandItem, "cmail://expand_" );
       
    90 _LIT( KURLItemTo, "to" );
       
    91 _LIT( KURLItemCc, "cc" );
       
    92 _LIT( KURLItemBcc, "bcc" );
       
    93 _LIT( KURLItemAttachments, "attachments" );
       
    94 
       
    95 const TText KGreaterThan = 0x3e;
       
    96 const TText KLessThan = 0x3c;
       
    97 const TText KAmpersand = 0x26;
       
    98 const TText KQuotation = 0x22;
       
    99 const TText KSOH = 0x01; // Start Of Heading
       
   100 const TText KLF = 0x0a; // Line Feed
       
   101 const TText KUnicodeNewLineCharacter = 0x2028;
       
   102 const TText KUnicodeParagraphCharacter = 0x2029;
       
   103 const TReal KOverlayButtonMarginX = 0.01; // 1%
       
   104 const TReal KOverlayButtonMarginY = 0.01; // 1%
       
   105 const TReal KOverlayButtonSizeP = 0.15; // 15%
       
   106 const TReal KOverlayButtonSizeLs = 0.20; // 25%
       
   107 
       
   108 
       
   109 const TInt KStatusIndicatorHeight = 55;
       
   110 const TInt KStatusIndicatorXMargin = 58;
       
   111 const TInt KStatusIndicatorBottomMargin = 6;
       
   112 
       
   113 // CONSTANTS
       
   114 // Zoom levels available on the UI
       
   115 const TInt KZoomLevels[] = { 75, 100, 125, 150 };
       
   116 const TInt KZoomLevelCount = sizeof( KZoomLevels ) / sizeof( TInt );
       
   117 const TInt KZoomLevelIndex100 = 1; // 100 in array KZoomLevels
       
   118 
       
   119 // CEUiHtmlViewerSettingsKeyListener
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 CEUiHtmlViewerSettingsKeyListener::CEUiHtmlViewerSettingsKeyListener( MObserver& aObserver, TUint32 aKey )
       
   126     : CActive( EPriorityStandard ), iObserver( aObserver ), iKey( aKey )
       
   127     {
       
   128     CActiveScheduler::Add(this);
       
   129     StartListening();
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 CEUiHtmlViewerSettingsKeyListener::~CEUiHtmlViewerSettingsKeyListener()
       
   137     {
       
   138     Cancel();
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 //
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CEUiHtmlViewerSettingsKeyListener::StartListening()
       
   146     {
       
   147     SetActive();
       
   148     iObserver.Repository().NotifyRequest(iKey, iStatus);
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 //
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CEUiHtmlViewerSettingsKeyListener::RunL()
       
   156     {
       
   157     iObserver.KeyValueChangedL(iKey);
       
   158     StartListening();
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 void CEUiHtmlViewerSettingsKeyListener::DoCancel()
       
   166     {
       
   167     iObserver.Repository().NotifyCancel(iKey);
       
   168     }
       
   169 
       
   170 // CEUiHtmlViewerSettings
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 CEUiHtmlViewerSettings* CEUiHtmlViewerSettings::NewL( MObserver& aObserver )
       
   177     {
       
   178     CEUiHtmlViewerSettings* self = new (ELeave) CEUiHtmlViewerSettings(aObserver);
       
   179     CleanupStack::PushL( self );
       
   180     self->ConstructL();
       
   181     CleanupStack::Pop( self );
       
   182     return self;
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 CEUiHtmlViewerSettings::~CEUiHtmlViewerSettings()
       
   190     {
       
   191     iKeyListeners.ResetAndDestroy();
       
   192     delete iRepository;
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 CEUiHtmlViewerSettings::CEUiHtmlViewerSettings( MObserver& aObserver ) : iObserver( aObserver )
       
   200     {
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 //
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 void CEUiHtmlViewerSettings::ConstructL()
       
   208     {
       
   209     iRepository = CRepository::NewL(KFreestyleEmailCenRep);
       
   210     AddKeyListenerL(KFreestyleEmailDownloadHTMLImages);
       
   211     }
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 //
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 void CEUiHtmlViewerSettings::AddKeyListenerL( TUint32 aKey )
       
   218     {
       
   219     CEUiHtmlViewerSettingsKeyListener* listener = 
       
   220         new (ELeave) CEUiHtmlViewerSettingsKeyListener( *this, aKey );
       
   221     CleanupStack::PushL( listener );
       
   222     iKeyListeners.AppendL( listener );
       
   223     CleanupStack::Pop( listener );
       
   224     UpdateValue( aKey );
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 // ---------------------------------------------------------------------------
       
   230 //
       
   231 void CEUiHtmlViewerSettings::UpdateValue( TUint32 aKey )
       
   232     {
       
   233     TInt value;
       
   234     iRepository->Get(aKey, value);
       
   235     switch (aKey)
       
   236         {
       
   237         case KFreestyleEmailDownloadHTMLImages:
       
   238             // 0 = automatic, 1 = ask always
       
   239             iFlags.Assign(aKey, value == 0);
       
   240             break;
       
   241         default:
       
   242             iFlags.Assign(aKey, value);
       
   243             break;
       
   244         }
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 void CEUiHtmlViewerSettings::KeyValueChangedL( TUint32 aKey )
       
   252     {
       
   253     UpdateValue(aKey);
       
   254     iObserver.ViewerSettingsChangedL(aKey);
       
   255     }
       
   256 
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 CRepository& CEUiHtmlViewerSettings::Repository()
       
   262     {
       
   263     return *iRepository;
       
   264     }
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 //
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 TBool CEUiHtmlViewerSettings::AutoLoadImages() const
       
   271     {
       
   272     return iFlags.IsSet(EAutoLoadImages);
       
   273     }
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // Two-phased constructor.
       
   277 // ---------------------------------------------------------------------------
       
   278 //
       
   279 CFsEmailUiHtmlViewerContainer* CFsEmailUiHtmlViewerContainer::NewL(
       
   280     CFreestyleEmailUiAppUi& aAppUi, CFsEmailUiHtmlViewerView& aView )
       
   281     {
       
   282     FUNC_LOG;
       
   283     CFsEmailUiHtmlViewerContainer* self =
       
   284         new (ELeave) CFsEmailUiHtmlViewerContainer( aAppUi, aView );
       
   285     CleanupStack::PushL( self );
       
   286     self->ConstructL();
       
   287     CleanupStack::Pop( self );
       
   288     return self;
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------------------------
       
   292 // C++ constructor.
       
   293 // ---------------------------------------------------------------------------
       
   294 //
       
   295 CFsEmailUiHtmlViewerContainer::CFsEmailUiHtmlViewerContainer(
       
   296     CFreestyleEmailUiAppUi& aAppUi, CFsEmailUiHtmlViewerView& aView )
       
   297     :
       
   298     iAppUi( aAppUi ),
       
   299     iView( aView ),
       
   300     iFs( iCoeEnv->FsSession() ),
       
   301     iFirstTime( ETrue ),
       
   302     iZoomLevel( KZoomLevelIndex100 )
       
   303     {
       
   304     FUNC_LOG;
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // Destructor.
       
   309 // ---------------------------------------------------------------------------
       
   310 //
       
   311 CFsEmailUiHtmlViewerContainer::~CFsEmailUiHtmlViewerContainer()
       
   312     {
       
   313     FUNC_LOG;
       
   314     delete iViewerSettings;
       
   315     if ( iObservingDownload && iAppUi.DownloadInfoMediator() )
       
   316         {
       
   317         iAppUi.DownloadInfoMediator()->StopObserving( this );
       
   318         }
       
   319     iFile.Close();
       
   320     iLinkContents.Close();
       
   321     iMessageParts.Close();
       
   322     delete iEventHandler;
       
   323     delete iBrCtlInterface;
       
   324     iConnection.Close();
       
   325     iSocketServer.Close();
       
   326     delete iStatusIndicator;
       
   327     delete iOverlayControlNext;
       
   328     delete iOverlayControlPrev;
       
   329     }
       
   330 
       
   331 void CFsEmailUiHtmlViewerContainer::PrepareForExit()
       
   332     {
       
   333     FUNC_LOG;
       
   334     HideDownloadStatus();
       
   335     if ( iObservingDownload && iAppUi.DownloadInfoMediator() )
       
   336         {
       
   337         iAppUi.DownloadInfoMediator()->StopObserving( this );
       
   338         iObservingDownload = EFalse;
       
   339         }
       
   340     delete iBrCtlInterface;
       
   341     iBrCtlInterface = NULL;
       
   342     iConnection.Close();
       
   343     iSocketServer.Close();
       
   344     }
       
   345 
       
   346 void CFsEmailUiHtmlViewerContainer::PrepareForMessageNavigation()
       
   347     {
       
   348     FUNC_LOG;
       
   349     ResetContent();
       
   350     }
       
   351 
       
   352 void CFsEmailUiHtmlViewerContainer::ZoomInL()
       
   353     {
       
   354     SetZoomLevelL( ZoomLevelL() + 1 );
       
   355     }
       
   356 
       
   357 void CFsEmailUiHtmlViewerContainer::ZoomOutL()
       
   358     {
       
   359     SetZoomLevelL( ZoomLevelL() - 1 );
       
   360     }
       
   361 
       
   362 TInt CFsEmailUiHtmlViewerContainer::ZoomLevelL() const
       
   363     {
       
   364     FUNC_LOG;
       
   365     TInt zoomLevelIdx = iBrCtlInterface->BrowserSettingL(
       
   366             TBrCtlDefs::ESettingsCurrentZoomLevelIndex );
       
   367 
       
   368     // Behaviour of zooming in Browser Control Interface is different in version 7.1
       
   369     // than in previous versions and we need to support both. In older versions there
       
   370     // are 4 preset zoom levels while version 7.1 can zoom to any percent.
       
   371     RArray<TUint>* zoomLevels = iBrCtlInterface->ZoomLevels();
       
   372 
       
   373     if ( !zoomLevels || !zoomLevels->Count() || ( *zoomLevels )[0] != KZoomLevels[0] )
       
   374         {
       
   375         // new browser:
       
   376         // BrowserControlIf gives zoom level percentage insted of index to array
       
   377         TBool found = EFalse;
       
   378 
       
   379         for ( TInt i = 0 ; i < KZoomLevelCount && !found ; ++i )
       
   380             {
       
   381             if ( zoomLevelIdx == KZoomLevels[i] )
       
   382                 {
       
   383                 zoomLevelIdx = i;
       
   384                 found = ETrue;
       
   385                 }
       
   386             }
       
   387 
       
   388         if ( !found )
       
   389             {
       
   390             zoomLevelIdx = KErrNotFound;
       
   391             }
       
   392         }
       
   393     return zoomLevelIdx;
       
   394     }
       
   395 
       
   396 void CFsEmailUiHtmlViewerContainer::SetZoomLevelL( const TInt aZoomLevel )
       
   397     {
       
   398     FUNC_LOG;
       
   399     TInt newValue = KMinTInt;
       
   400 
       
   401     // Behaviour of zooming in Browser Control Interface is different in version 7.1
       
   402     // than in previous versions and we need to support both. In older versions there
       
   403     // are 4 preset zoom levels while version 7.1 can zoom to any percent.
       
   404     RArray<TUint>* zoomLevels = iBrCtlInterface->ZoomLevels();
       
   405 
       
   406     if ( !zoomLevels || !zoomLevels->Count() || ( *zoomLevels )[0] != KZoomLevels[0] )
       
   407         {
       
   408         // new browser:
       
   409         // BrowserControlIf takes zoom level percentage insted of index to array
       
   410         if ( aZoomLevel >= 0 && aZoomLevel < KZoomLevelCount )
       
   411             {
       
   412             newValue = KZoomLevels[aZoomLevel];
       
   413             }
       
   414         }
       
   415     else
       
   416         {
       
   417         // old browser
       
   418         newValue = aZoomLevel;
       
   419         }
       
   420 
       
   421     iZoomLevel = ( newValue > KMinTInt ) ? newValue : aZoomLevel;
       
   422     iBrCtlInterface->SetBrowserSettingL(
       
   423         TBrCtlDefs::ESettingsCurrentZoomLevelIndex, iZoomLevel );
       
   424     }
       
   425 
       
   426 TInt CFsEmailUiHtmlViewerContainer::DoZoom( TAny* aPtr  )
       
   427     {
       
   428     TRAPD( error, reinterpret_cast<CFsEmailUiHtmlViewerContainer*>( aPtr )->DoZoomL() );
       
   429     return error;
       
   430     }
       
   431 
       
   432 void CFsEmailUiHtmlViewerContainer::DoZoomL()
       
   433     {
       
   434     iBrCtlInterface->SetBrowserSettingL(
       
   435         TBrCtlDefs::ESettingsCurrentZoomLevelIndex, iZoomLevel );
       
   436     }
       
   437 
       
   438 TInt CFsEmailUiHtmlViewerContainer::MaxZoomLevel() const
       
   439     {
       
   440     return KZoomLevelCount;
       
   441     }
       
   442 
       
   443 
       
   444 void CFsEmailUiHtmlViewerContainer::CreateBrowserControlInterfaceL()
       
   445     {
       
   446     FUNC_LOG;
       
   447 
       
   448     if ( iBrCtlInterface )
       
   449         {
       
   450        	SetZoomLevelL(100);
       
   451 		iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages, iViewerSettings->AutoLoadImages() );
       
   452        	return;
       
   453         }
       
   454 
       
   455     TUint brCtlCapabilities = TBrCtlDefs::ECapabilityClientResolveEmbeddedURL |
       
   456                               TBrCtlDefs::ECapabilityDisplayScrollBar |
       
   457                               TBrCtlDefs::ECapabilityClientNotifyURL |
       
   458                               TBrCtlDefs::ECapabilityLoadHttpFw |
       
   459                               TBrCtlDefs::ECapabilityCursorNavigation |
       
   460                               TBrCtlDefs::ECapabilityPinchZoom |
       
   461                               TBrCtlDefs::ECapabilityFitToScreen;
       
   462 
       
   463     // Set browsercontrol to whole screen
       
   464     TRect rect( TPoint(), Size() );
       
   465 
       
   466     iBrCtlInterface = CreateBrowserControlL(
       
   467             this, // aParent
       
   468             rect,  // aRect
       
   469             brCtlCapabilities, // aBrCtlCapabilities
       
   470             TBrCtlDefs::ECommandIdBase, // aCommandIdBase
       
   471             NULL, // aBrCtlSoftkeysObserver
       
   472             this, // aBrCtlLinkResolver
       
   473             this, // aBrCtlSpecialLoadObserver
       
   474             NULL, // aBrCtlLayoutObserver
       
   475             NULL, // aBrCtlDialogsProvider
       
   476             this, // aBrCtlWindowObserver
       
   477             NULL // aBrCtlDownloadObserver
       
   478             );
       
   479 
       
   480     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsEmbedded, ETrue );
       
   481     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages, iViewerSettings->AutoLoadImages() );
       
   482     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsPageOverview, EFalse );
       
   483     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsTextWrapEnabled, ETrue );
       
   484     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsFontSize, TBrCtlDefs::EFontSizeLevelLarger );
       
   485     }
       
   486 
       
   487 void CFsEmailUiHtmlViewerContainer::ConstructL()
       
   488     {
       
   489     FUNC_LOG;
       
   490     iViewerSettings = CEUiHtmlViewerSettings::NewL(*this);
       
   491 
       
   492     SetHtmlFolderPathL();
       
   493     BaflUtils::EnsurePathExistsL( iFs, iHtmlFolderPath );
       
   494     SetTempHtmlFolderPath();
       
   495     BaflUtils::EnsurePathExistsL( iFs, iTempHtmlFolderPath );
       
   496     SetHTMLResourceFlagFullName();
       
   497     EnsureHTMLResourceL();
       
   498 
       
   499     CreateWindowL();
       
   500     
       
   501 #if defined( BRDO_MULTITOUCH_ENABLED_FF ) && !defined ( __WINSCW__ )   
       
   502     //Enable advance pointer info for multi-touch.
       
   503     Window().EnableAdvancedPointers();
       
   504 #endif 
       
   505 
       
   506     
       
   507     iEventHandler = CFreestyleMessageHeaderURLEventHandler::NewL( iAppUi, iView );
       
   508 
       
   509     TRect nextButtonRect = OverlayButtonRect( EFalse );
       
   510     iOverlayControlNext = COverlayControl::NewL( this, this, nextButtonRect,
       
   511             EMbmFreestyleemailuiQgn_indi_cmail_arrow_next,
       
   512             EMbmFreestyleemailuiQgn_indi_cmail_arrow_next_mask );
       
   513 
       
   514     TRect prevButtonRect = OverlayButtonRect( ETrue );
       
   515     iOverlayControlPrev = COverlayControl::NewL( this, this, prevButtonRect,
       
   516             EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous,
       
   517             EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous_mask );
       
   518     iScrollPosition = 0;
       
   519     iAttachmentDownloadImageHandle = 0;
       
   520 
       
   521     iTouchFeedBack = MTouchFeedback::Instance();
       
   522     iTouchFeedBack->EnableFeedbackForControl(this, ETrue);
       
   523 
       
   524     CreateBrowserControlInterfaceL();
       
   525     SetRect( iView.ContainerRect() );
       
   526 
       
   527     ActivateL();
       
   528     }
       
   529 
       
   530 void CFsEmailUiHtmlViewerContainer::MakeVisible( TBool aVisible )
       
   531     {
       
   532     UpdateOverlayButtons( aVisible );
       
   533     CCoeControl::MakeVisible( aVisible );
       
   534     }
       
   535 
       
   536 void CFsEmailUiHtmlViewerContainer::HandleOverlayPointerEventL( COverlayControl* aControl,
       
   537         const TPointerEvent& aEvent )
       
   538     {
       
   539     if( aEvent.iType == TPointerEvent::EButton1Up )
       
   540         {
       
   541         if( aControl == iOverlayControlNext )
       
   542             {
       
   543             iView.HandleCommandL( EFsEmailUiCmdNextMessage );
       
   544             }
       
   545         else if( aControl == iOverlayControlPrev )
       
   546             {
       
   547             iView.HandleCommandL( EFsEmailUiCmdPreviousMessage );
       
   548             }
       
   549         }
       
   550     }
       
   551 
       
   552 void CFsEmailUiHtmlViewerContainer::UpdateOverlayButtons( TBool aVisible )
       
   553     {
       
   554     TBool nextAvailable = EFalse;
       
   555     TBool prevAvailable = EFalse;
       
   556     if( iMessage )
       
   557         {
       
   558         TFSMailMsgId currentMsgId = iMessage->GetMessageId();
       
   559         TFSMailMsgId tmpMsgId;
       
   560         TFSMailMsgId tmpMsgFolderId;
       
   561         nextAvailable = iAppUi.IsNextMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId );
       
   562         prevAvailable = iAppUi.IsPreviousMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId );
       
   563         }
       
   564 
       
   565     if( iOverlayControlPrev )
       
   566         {
       
   567         iOverlayControlPrev->SetRect( OverlayButtonRect( ETrue ) );
       
   568         iOverlayControlPrev->MakeVisible( aVisible && prevAvailable );
       
   569         }
       
   570     if( iOverlayControlNext )
       
   571         {
       
   572         iOverlayControlNext->SetRect( OverlayButtonRect( EFalse ) );
       
   573         iOverlayControlNext->MakeVisible( aVisible && nextAvailable );
       
   574         }
       
   575     }
       
   576 
       
   577 // Get rect for button
       
   578 TRect CFsEmailUiHtmlViewerContainer::OverlayButtonRect( TBool aLeft )
       
   579     {
       
   580     TRect rect = Rect();
       
   581     TSize size = rect.Size();
       
   582 
       
   583     TBool landscape = size.iWidth > size.iHeight;
       
   584     TInt buttonSize;
       
   585 
       
   586     if( landscape )
       
   587         {
       
   588         buttonSize = size.iHeight * KOverlayButtonSizeLs;
       
   589         }
       
   590     else
       
   591         {
       
   592         buttonSize = size.iWidth * KOverlayButtonSizeP;
       
   593         }
       
   594 
       
   595     rect.iBr.iY = size.iHeight * (1-KOverlayButtonMarginY);
       
   596 
       
   597     if( aLeft )
       
   598         {
       
   599         rect.iTl.iX = size.iWidth * KOverlayButtonMarginX;
       
   600         rect.iBr.iX = rect.iTl.iX + buttonSize;
       
   601         }
       
   602     else
       
   603         {
       
   604         rect.iBr.iX = size.iWidth * (1 - KOverlayButtonMarginX);
       
   605         rect.iTl.iX = rect.iBr.iX - buttonSize;
       
   606         }
       
   607 
       
   608     rect.iTl.iY = rect.iBr.iY - buttonSize;
       
   609     return rect;
       
   610     }
       
   611 
       
   612 // Getter for br contro, interface
       
   613 CBrCtlInterface* CFsEmailUiHtmlViewerContainer::BrowserControlIf()
       
   614     {
       
   615     FUNC_LOG;
       
   616     return iBrCtlInterface;
       
   617     }
       
   618 
       
   619 void CFsEmailUiHtmlViewerContainer::LoadContentFromFileL( const TDesC& aFileName )
       
   620     {
       
   621     FUNC_LOG;
       
   622     iBrCtlInterface->LoadFileL( aFileName );
       
   623     }
       
   624 
       
   625 void CFsEmailUiHtmlViewerContainer::LoadContentFromFileL( RFile& aFile )
       
   626     {
       
   627     FUNC_LOG;
       
   628     iBrCtlInterface->LoadFileL( aFile );
       
   629     }
       
   630 
       
   631 void CFsEmailUiHtmlViewerContainer::LoadContentFromUrlL( const TDesC& aUrl )
       
   632     {
       
   633     FUNC_LOG;
       
   634     iBrCtlInterface->LoadUrlL( aUrl );
       
   635     }
       
   636 
       
   637 // ---------------------------------------------------------------------------
       
   638 // Loads content from given mail message.
       
   639 // ---------------------------------------------------------------------------
       
   640 //
       
   641 void CFsEmailUiHtmlViewerContainer::LoadContentFromMailMessageL(
       
   642         CFSMailMessage* aMailMessage, TBool aResetScrollPos )
       
   643     {
       
   644     FUNC_LOG;
       
   645     ASSERT( aMailMessage );
       
   646     iMessage = aMailMessage;
       
   647     // Cancel any browser fetch operation, just in case the browser is still
       
   648     // loading a previous message (since we are about to overwrite it).
       
   649     CancelFetch();
       
   650 
       
   651     TPath headerHtmlFile;
       
   652     headerHtmlFile.Copy( iHtmlFolderPath );
       
   653     headerHtmlFile.Append( KHeaderHtmlFile );
       
   654 
       
   655     // insert email header into email.html file
       
   656     // CFreestyleMessageHeaderHTML will replace contents of email.html
       
   657     // So, no need to clear the contents
       
   658     if(aResetScrollPos)
       
   659         {
       
   660         iScrollPosition = 0;
       
   661         }
       
   662     const TInt visibleWidth(iAppUi.ClientRect().Width());
       
   663     CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, visibleWidth, iScrollPosition,
       
   664             iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage), iFlags );
       
   665     
       
   666     // Remove all previously created files from temporary HTML folder
       
   667     EmptyTempHtmlFolderL();
       
   668 
       
   669     TRAPD( error, PrepareBodyHtmlL( KBodyHtmlFile ) );
       
   670     if ( error != KErrNone )
       
   671         {
       
   672         WriteEmptyBodyHtmlL( KBodyHtmlFile );
       
   673         }
       
   674 
       
   675     // pass the emailHtmlFile to the browser for it to load
       
   676     TPath emailHtmlFile;
       
   677     emailHtmlFile.Copy( iHtmlFolderPath );
       
   678     if ( !AknLayoutUtils::LayoutMirrored() )
       
   679         {
       
   680         emailHtmlFile.Append( KMessageHtmlFile );
       
   681         }
       
   682     else
       
   683         {
       
   684         emailHtmlFile.Append( KMessageHtmlRTLFile );
       
   685         }
       
   686 
       
   687     // If scroll position is not to be reset, re-creation of browser control
       
   688     // interface object is skipped (we're just reloading the page with new
       
   689     // content)
       
   690     if ( aResetScrollPos )
       
   691         {
       
   692         CreateBrowserControlInterfaceL();
       
   693         }
       
   694     
       
   695     LoadContentFromFileL( emailHtmlFile );
       
   696 
       
   697     UpdateOverlayButtons( ETrue );
       
   698     }
       
   699 
       
   700 // ---------------------------------------------------------------------------
       
   701 // Reset content
       
   702 // ---------------------------------------------------------------------------
       
   703 //
       
   704 void CFsEmailUiHtmlViewerContainer::ResetContent( TBool aDisconnect,
       
   705     TBool aClearFlags )
       
   706     {
       
   707     FUNC_LOG;
       
   708     if ( iBrCtlInterface )
       
   709         {
       
   710         TRAP_IGNORE(
       
   711                 iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
       
   712                         ( TInt )TBrCtlDefs::ECommandFreeMemory ) );
       
   713         if (aDisconnect)
       
   714             {
       
   715             TRAP_IGNORE(
       
   716                     iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
       
   717                                                       ( TInt )TBrCtlDefs::ECommandDisconnect ) );
       
   718             }
       
   719         }
       
   720     iFile.Close();
       
   721     iLinkContents.Reset();
       
   722     iMessageParts.Reset();
       
   723     iMessage = NULL;
       
   724     if ( aClearFlags )
       
   725         {
       
   726         iFlags.ClearAll();
       
   727         }
       
   728     iScrollPosition = 0;
       
   729     }
       
   730 
       
   731 // ---------------------------------------------------------------------------
       
   732 // From CCoeControl.
       
   733 // ---------------------------------------------------------------------------
       
   734 //
       
   735 CCoeControl* CFsEmailUiHtmlViewerContainer::ComponentControl( TInt aIndex ) const
       
   736     {
       
   737     FUNC_LOG;
       
   738     switch ( aIndex )
       
   739         {
       
   740         case 0:
       
   741             {
       
   742             return iBrCtlInterface;
       
   743             }
       
   744         case 1:
       
   745             {
       
   746             return iOverlayControlNext;
       
   747             }
       
   748         case 2:
       
   749             {
       
   750             return iOverlayControlPrev;
       
   751             }
       
   752         case 3:
       
   753             {
       
   754             if ( iStatusIndicator )
       
   755                 return iStatusIndicator;
       
   756             else
       
   757                 return NULL;
       
   758             }
       
   759         default:
       
   760             {
       
   761             return NULL;
       
   762             }
       
   763         }
       
   764     }
       
   765 
       
   766 // ---------------------------------------------------------------------------
       
   767 // From CCoeControl.
       
   768 // ---------------------------------------------------------------------------
       
   769 //
       
   770 TInt CFsEmailUiHtmlViewerContainer::CountComponentControls() const
       
   771     {
       
   772     FUNC_LOG;
       
   773     if ( iStatusIndicator )
       
   774         {
       
   775         return 4;
       
   776         }
       
   777     else
       
   778         {
       
   779         return 3;
       
   780         }
       
   781     }
       
   782 
       
   783 // ---------------------------------------------------------------------------
       
   784 // From CCoeControl.
       
   785 // Draw this application's view to the screen
       
   786 // ---------------------------------------------------------------------------
       
   787 //
       
   788 void CFsEmailUiHtmlViewerContainer::Draw( const TRect& /*aRect*/ ) const
       
   789     {
       
   790     FUNC_LOG;
       
   791     // Get the standard graphics context
       
   792     CWindowGc& gc = SystemGc();
       
   793 
       
   794     // Gets the control's extent
       
   795     TRect rect = Rect();
       
   796 
       
   797     // Clears the screen
       
   798     gc.Clear( rect );
       
   799     }
       
   800 
       
   801 // ---------------------------------------------------------------------------
       
   802 // From CCoeControl.
       
   803 // ---------------------------------------------------------------------------
       
   804 //
       
   805 void CFsEmailUiHtmlViewerContainer::SizeChanged()
       
   806     {
       
   807     FUNC_LOG;
       
   808 
       
   809     TRect rect = Rect();
       
   810     if ( iBrCtlInterface )
       
   811         {
       
   812         iBrCtlInterface->SetRect( rect );
       
   813         }
       
   814 
       
   815     UpdateOverlayButtons( IsVisible() );
       
   816 
       
   817     if ( iStatusIndicator )
       
   818         {
       
   819         TRect rect = CalcAttachmentStatusRect();
       
   820         iStatusIndicator->SetRect( rect );
       
   821         }
       
   822     }
       
   823 
       
   824 // ---------------------------------------------------------------------------
       
   825 // From CCoeControl.
       
   826 // ---------------------------------------------------------------------------
       
   827 //
       
   828 TKeyResponse CFsEmailUiHtmlViewerContainer::OfferKeyEventL(
       
   829     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   830     {
       
   831     FUNC_LOG;
       
   832 
       
   833     TKeyResponse retVal = EKeyWasNotConsumed;
       
   834 
       
   835     // Handle keyboard shortcuts already on key down event as all keys
       
   836     // do not necessarily send the key event at all.
       
   837     if ( aType == EEventKeyDown )
       
   838         {
       
   839         // Check keyboard shortcuts
       
   840         TInt shortcutCommand = iAppUi.ShortcutBinding().CommandForShortcutKey(
       
   841             aKeyEvent, CFSEmailUiShortcutBinding::EContextHtmlViewer );
       
   842 
       
   843         if ( shortcutCommand != KErrNotFound )
       
   844             {
       
   845             iView.HandleCommandL( shortcutCommand );
       
   846             retVal = EKeyWasConsumed;
       
   847             }
       
   848         }
       
   849 
       
   850     if ( iBrCtlInterface && retVal == EKeyWasNotConsumed )
       
   851         {
       
   852         TKeyEvent event = aKeyEvent;
       
   853         if ( iBrCtlInterface->FocusedElementType() == TBrCtlDefs::EElementButton
       
   854              && ( aKeyEvent.iScanCode == EStdKeyNkpEnter 
       
   855                   || aKeyEvent.iScanCode == EStdKeyEnter ) )
       
   856             {
       
   857             // Enter key events are converted to selection key event in
       
   858             // order to get browser to handle them in similar way.
       
   859             event.iScanCode = EStdKeyDevice3;
       
   860             event.iCode = aKeyEvent.iCode ? EKeyDevice3 : 0;
       
   861             }
       
   862         retVal = iBrCtlInterface->OfferKeyEventL( event, aType );
       
   863         }
       
   864 
       
   865     iView.SetMskL();
       
   866 
       
   867     return retVal;
       
   868     }
       
   869 
       
   870 // ---------------------------------------------------------------------------
       
   871 // From MBrCtlSpecialLoadObserver.
       
   872 // ---------------------------------------------------------------------------
       
   873 //
       
   874 void CFsEmailUiHtmlViewerContainer::NetworkConnectionNeededL(
       
   875         TInt* aConnectionPtr,
       
   876         TInt* aSockSvrHandle,
       
   877         TBool* aNewConn,
       
   878         TApBearerType* aBearerType )
       
   879     {
       
   880     FUNC_LOG;
       
   881     *aBearerType = EApBearerTypeAllBearers;
       
   882 
       
   883     if ( iFirstTime )
       
   884         {
       
   885         User::LeaveIfError( iSocketServer.Connect( KESockDefaultMessageSlots ) );
       
   886         User::LeaveIfError( iConnection.Open( iSocketServer, KConnectionTypeDefault ) );
       
   887         TCommDbConnPref prefs;
       
   888         prefs.SetDialogPreference( ECommDbDialogPrefDoNotPrompt );
       
   889         prefs.SetDirection( ECommDbConnectionDirectionOutgoing );
       
   890         prefs.SetIapId( 0 ); // Ask for access point
       
   891         User::LeaveIfError( iConnection.Start( prefs ) );
       
   892         *aNewConn = ETrue;
       
   893         iFirstTime = EFalse;
       
   894         }
       
   895     else
       
   896         {
       
   897         *aNewConn = EFalse;
       
   898         }
       
   899 
       
   900     *aConnectionPtr = reinterpret_cast<TInt>(&iConnection);
       
   901     *aSockSvrHandle = iSocketServer.Handle();
       
   902     }
       
   903 
       
   904 // ---------------------------------------------------------------------------
       
   905 // From MBrCtlSpecialLoadObserver.
       
   906 // ---------------------------------------------------------------------------
       
   907 //
       
   908 TBool CFsEmailUiHtmlViewerContainer::HandleRequestL(
       
   909     RArray<TUint>* /*aTypeArray*/, CDesCArrayFlat* /*aDesArray*/ )
       
   910     {
       
   911     FUNC_LOG;
       
   912     // Let browser control handle these
       
   913     return EFalse;
       
   914     }
       
   915 
       
   916 // ---------------------------------------------------------------------------
       
   917 // From MBrCtlSpecialLoadObserver.
       
   918 // ---------------------------------------------------------------------------
       
   919 //
       
   920 TBool CFsEmailUiHtmlViewerContainer::HandleDownloadL(
       
   921     RArray<TUint>* /*aTypeArray*/, CDesCArrayFlat* /*aDesArray*/ )
       
   922     {
       
   923     FUNC_LOG;
       
   924     // Let browser control handle these
       
   925     return EFalse;
       
   926     }
       
   927 
       
   928 // ---------------------------------------------------------------------------
       
   929 // From MFSEmailDownloadInformationObserver.
       
   930 // ---------------------------------------------------------------------------
       
   931 //
       
   932 void CFsEmailUiHtmlViewerContainer::RequestResponseL( const TFSProgress& aEvent,
       
   933     const TPartData& aPart )
       
   934     {
       
   935     FUNC_LOG;
       
   936     if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete )
       
   937         {
       
   938         MBrCtlLinkContent* linkContent = NULL;
       
   939         for ( TInt ii = iMessageParts.Count() - 1; ii >= 0 && !linkContent; --ii )
       
   940             {
       
   941             if ( iMessageParts[ii] == aPart )
       
   942                 {
       
   943                 iMessageParts.Remove( ii );
       
   944                 linkContent = iLinkContents[ii];
       
   945                 iLinkContents.Remove( ii );
       
   946                 }
       
   947             }
       
   948 
       
   949         if ( !iMessageParts.Count() && iAppUi.DownloadInfoMediator() )
       
   950             {
       
   951             iAppUi.DownloadInfoMediator()->StopObserving( this );
       
   952             }
       
   953 
       
   954         if ( iMessage && linkContent )
       
   955             {
       
   956             CFSMailMessagePart* part = iMessage->ChildPartL( aPart.iMessagePartId );
       
   957             CleanupStack::PushL( part );
       
   958             RFile contentFile = part->GetContentFileL();
       
   959             CleanupClosePushL( contentFile );
       
   960             HBufC8* content = ReadContentFromFileLC( contentFile, *part );
       
   961             linkContent->HandleResolveComplete(
       
   962                 part->GetContentType(), KNullDesC(), content );
       
   963             CleanupStack::PopAndDestroy( content );
       
   964             CleanupStack::PopAndDestroy( &contentFile );
       
   965             CleanupStack::PopAndDestroy( part );
       
   966             }
       
   967 
       
   968         if ( iMessage )
       
   969             {
       
   970             LoadContentFromMailMessageL( iMessage, EFalse );
       
   971             UpdateOverlayButtons( ETrue );
       
   972             }
       
   973         }
       
   974     else if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled ||
       
   975             aEvent.iProgressStatus < 0 )
       
   976         {
       
   977         if ( iAppUi.DownloadInfoMediator() )
       
   978             {
       
   979             iAppUi.DownloadInfoMediator()->StopObserving( this, aPart.iMessageId );
       
   980             }
       
   981         }
       
   982     }
       
   983 
       
   984 // ---------------------------------------------------------------------------
       
   985 // From MBrCtlLinkResolver.
       
   986 // ---------------------------------------------------------------------------
       
   987 //
       
   988 TBool CFsEmailUiHtmlViewerContainer::ResolveEmbeddedLinkL(
       
   989     const TDesC& aEmbeddedUrl, const TDesC& /*aCurrentUrl*/,
       
   990     TBrCtlLoadContentType /*aLoadContentType*/,
       
   991     MBrCtlLinkContent& aEmbeddedLinkContent )
       
   992     {
       
   993     FUNC_LOG;
       
   994     TBool linkResolved = EFalse;
       
   995 
       
   996     // Check if given link contains content ID
       
   997     if ( aEmbeddedUrl.Left( KContentIdPrefix().Length() ).CompareF( KContentIdPrefix ) == 0 )
       
   998         {
       
   999         TPtrC cid = aEmbeddedUrl.Mid( KContentIdPrefix().Length() );
       
  1000         linkResolved = ResolveLinkL( cid, ETrue, aEmbeddedLinkContent );
       
  1001         }
       
  1002     else
       
  1003         {
       
  1004         // Replace all slash character with backslash characters
       
  1005         HBufC* embeddedUrl = aEmbeddedUrl.AllocLC();
       
  1006         TPtr ptr = embeddedUrl->Des();
       
  1007         _LIT( KBackslash, "\\" );
       
  1008         for ( TInt pos = ptr.Locate('/'); pos >= 0; pos = ptr.Locate('/') )
       
  1009             {
       
  1010             ptr.Replace( pos, 1, KBackslash );
       
  1011             }
       
  1012 
       
  1013         // Check whether given url refers to file in the temporary html folder
       
  1014         TInt pos = embeddedUrl->FindF( iTempHtmlFolderPath );
       
  1015         if ( pos >= 0 )
       
  1016             {
       
  1017             TPtrC filename = embeddedUrl->Mid( pos + iTempHtmlFolderPath.Length() );
       
  1018             linkResolved = ResolveLinkL( filename, EFalse, aEmbeddedLinkContent );
       
  1019             }
       
  1020 
       
  1021         CleanupStack::PopAndDestroy( embeddedUrl );
       
  1022         }
       
  1023 
       
  1024     // Return whether link is resolved by host application.
       
  1025     return linkResolved;
       
  1026     }
       
  1027 
       
  1028 // ---------------------------------------------------------------------------
       
  1029 // From MBrCtlLinkResolver.
       
  1030 // ---------------------------------------------------------------------------
       
  1031 //
       
  1032 TBool CFsEmailUiHtmlViewerContainer::ResolveLinkL( const TDesC& aUrl,
       
  1033     const TDesC& /*aCurrentUrl*/, MBrCtlLinkContent& /*aBrCtlLinkContent*/ )
       
  1034     {
       
  1035     FUNC_LOG;
       
  1036     if ( IsMessageBodyURLL(aUrl) )
       
  1037         {
       
  1038         if ( iMessage )
       
  1039             {
       
  1040             iView.StartFetchingMessageL();
       
  1041             }
       
  1042         return ETrue;
       
  1043         }
       
  1044     else
       
  1045         {
       
  1046         if ( NeedToLaunchBrowserL( aUrl ) )
       
  1047             {
       
  1048             LaunchBrowserL( aUrl );
       
  1049             return ETrue;
       
  1050             }
       
  1051         else
       
  1052             {
       
  1053             return iEventHandler->HandleEventL( aUrl );
       
  1054             }
       
  1055         }
       
  1056     }
       
  1057 
       
  1058 // ---------------------------------------------------------------------------
       
  1059 // From MBrCtlLinkResolver.
       
  1060 // ---------------------------------------------------------------------------
       
  1061 //
       
  1062 void CFsEmailUiHtmlViewerContainer::CancelAll()
       
  1063     {
       
  1064     FUNC_LOG;
       
  1065     }
       
  1066 
       
  1067 // ---------------------------------------------------------------------------
       
  1068 // From MBrCtlSoftkeysObserver
       
  1069 // ---------------------------------------------------------------------------
       
  1070 //
       
  1071 void CFsEmailUiHtmlViewerContainer::UpdateSoftkeyL(
       
  1072     TBrCtlKeySoftkey /*aKeySoftkey*/, const TDesC& /*aLabel*/,
       
  1073     TUint32 /*aCommandId*/,
       
  1074     TBrCtlSoftkeyChangeReason /*aBrCtlSoftkeyChangeReason*/ )
       
  1075     {
       
  1076     FUNC_LOG;
       
  1077     }
       
  1078 
       
  1079 // ---------------------------------------------------------------------------
       
  1080 // Set HTML folder path name
       
  1081 // ---------------------------------------------------------------------------
       
  1082 //
       
  1083 void CFsEmailUiHtmlViewerContainer::SetHtmlFolderPathL()
       
  1084     {
       
  1085     FUNC_LOG;
       
  1086     iHtmlFolderPath.Copy( KCDrive );
       
  1087 
       
  1088     TFileName privatePath;
       
  1089     User::LeaveIfError( iFs.PrivatePath( privatePath ) );
       
  1090     iHtmlFolderPath.Append( privatePath );
       
  1091 
       
  1092     iHtmlFolderPath.Append( KHtmlPath );
       
  1093     }
       
  1094 
       
  1095 // ---------------------------------------------------------------------------
       
  1096 // Sets temporary HTML folder path name
       
  1097 // ---------------------------------------------------------------------------
       
  1098 //
       
  1099 void CFsEmailUiHtmlViewerContainer::SetTempHtmlFolderPath()
       
  1100     {
       
  1101     FUNC_LOG;
       
  1102     iTempHtmlFolderPath.Copy( iHtmlFolderPath );
       
  1103     iTempHtmlFolderPath.Append( KTempHtmlPath );
       
  1104     }
       
  1105 
       
  1106 // ---------------------------------------------------------------------------
       
  1107 // Remove all previously created files from temporary HTML folder
       
  1108 // ---------------------------------------------------------------------------
       
  1109 //
       
  1110 void CFsEmailUiHtmlViewerContainer::EmptyTempHtmlFolderL()
       
  1111     {
       
  1112     FUNC_LOG;
       
  1113     // Delete all files from temp folder
       
  1114     TFileName allFiles;
       
  1115     allFiles.Append( iTempHtmlFolderPath );
       
  1116     allFiles.Append( KAllFiles );
       
  1117     TInt err = BaflUtils::DeleteFile( iFs, allFiles );
       
  1118     if ( err != KErrNotFound && err != KErrNone )
       
  1119         {
       
  1120         User::LeaveIfError( err );
       
  1121         }
       
  1122     }
       
  1123 
       
  1124 // ---------------------------------------------------------------------------
       
  1125 // Copies given read-only file to HTML file
       
  1126 // ---------------------------------------------------------------------------
       
  1127 //
       
  1128 // <cmail>
       
  1129 void CFsEmailUiHtmlViewerContainer::CopyToHtmlFileL( CFSMailMessagePart& aHtmlBodyPart, const TDesC& aFileName )
       
  1130     {
       
  1131     FUNC_LOG;
       
  1132     TFileName targetFileName;
       
  1133     targetFileName.Copy( iTempHtmlFolderPath );
       
  1134     targetFileName.Append( aFileName );
       
  1135 
       
  1136     RFile htmlFile = aHtmlBodyPart.GetContentFileL();
       
  1137     CleanupClosePushL( htmlFile );
       
  1138 
       
  1139     // Read content from given source file
       
  1140     HBufC8* content = ReadContentFromFileLC( htmlFile, aHtmlBodyPart );
       
  1141 
       
  1142     // Write content to target file
       
  1143     WriteContentToFileL( *content, targetFileName, aHtmlBodyPart );
       
  1144 
       
  1145     CleanupStack::PopAndDestroy( content );
       
  1146     CleanupStack::PopAndDestroy( &htmlFile );
       
  1147     }
       
  1148 // </cmail>
       
  1149 
       
  1150 // ---------------------------------------------------------------------------
       
  1151 // Copies given buffer to HTML file
       
  1152 // ---------------------------------------------------------------------------
       
  1153 //
       
  1154 // <cmail>
       
  1155 void CFsEmailUiHtmlViewerContainer::ConvertToHtmlFileL( CFSMailMessagePart& aTextBodyPart, const TDesC& aHtmlFileName )
       
  1156     {
       
  1157     FUNC_LOG;
       
  1158     TFileName targetFileName;
       
  1159     targetFileName.Copy( iTempHtmlFolderPath );
       
  1160     targetFileName.Append( aHtmlFileName );
       
  1161 
       
  1162     TInt contentsize = aTextBodyPart.FetchedContentSize();
       
  1163       
       
  1164     TInt limit(0);
       
  1165     TInt err = iViewerSettings->Repository().Get( KFreestyleMaxBodySize , limit );
       
  1166     limit *= KKilo; // cenrep value is in kB, 0 means unlimited
       
  1167 
       
  1168     if ( limit == 0 || err )
       
  1169         {
       
  1170         limit = KMaxTInt;
       
  1171         }
       
  1172     
       
  1173     TInt size = Min(limit,contentsize);
       
  1174     HBufC* content = HBufC::NewLC( size );
       
  1175     TPtr contentPtr( content->Des() );
       
  1176 
       
  1177     aTextBodyPart.GetContentToBufferL( contentPtr, 0 );
       
  1178     //When we found EFSMsgFlag_BodyTruncated was set, add "--Message too long--" in the end of plain html view
       
  1179     if ( limit < contentsize )
       
  1180         {
       
  1181         // Disable this is PS1 until we have translations available             
       
  1182 //		 HBufC* addingText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEW_ADDITIONAL_INFO , limit/KKilo );
       
  1183 //		 TInt pos = contentPtr.Length() - addingText->Length();
       
  1184 //		 contentPtr.Replace(pos,addingText->Length(),*addingText);
       
  1185 //         CleanupStack::PopAndDestroy( addingText );
       
  1186          aTextBodyPart.SetFlag(EFSMsgFlag_BodyTruncated);
       
  1187         }
       
  1188     
       
  1189     ConvertToHTML( *content, targetFileName, aTextBodyPart );
       
  1190     CleanupStack::PopAndDestroy( content );
       
  1191     }
       
  1192 
       
  1193 // ---------------------------------------------------------------------------
       
  1194 // Reads given file content to buffer and return pointer to it
       
  1195 // ---------------------------------------------------------------------------
       
  1196 //
       
  1197 HBufC8* CFsEmailUiHtmlViewerContainer::ReadContentFromFileLC( RFile& aFile, 
       
  1198    CFSMailMessagePart& aBodyPart )
       
  1199     {
       
  1200     FUNC_LOG;
       
  1201     TInt fileSize = 0;
       
  1202     User::LeaveIfError( aFile.Size( fileSize ) );
       
  1203  
       
  1204     HBufC* contentType = aBodyPart.GetContentType().AllocLC();
       
  1205     TInt length = contentType->Locate(';');
       
  1206     if( length >= 0 )
       
  1207         {
       
  1208         contentType->Des().SetLength( length );
       
  1209         }
       
  1210     TBool body = KFSMailContentTypeTextPlain().CompareF( contentType->Des() ) == 0 ||
       
  1211                  KFSMailContentTypeTextHtml().CompareF( contentType->Des() ) == 0; 
       
  1212     CleanupStack::PopAndDestroy( contentType );
       
  1213     
       
  1214     if ( body )
       
  1215         {
       
  1216         // limit message size if not done already by plugins
       
  1217         TInt limit(0);
       
  1218         TInt err = iViewerSettings->Repository().Get( KFreestyleMaxBodySize , limit );
       
  1219         limit *= KKilo; // cenrep value is in kB, 0 means unlimited
       
  1220  
       
  1221         if ( limit == 0 || err )
       
  1222            {
       
  1223            limit = KMaxTInt;
       
  1224            }
       
  1225         fileSize = Min( limit, fileSize ); // read no more than limit bytes..
       
  1226      
       
  1227         TInt contentSize = aBodyPart.ContentSize();
       
  1228         TInt fetchedSize = aBodyPart.FetchedContentSize();
       
  1229         
       
  1230         if ( ( limit!=KMaxTInt && fileSize < contentSize ) 
       
  1231           || ( fetchedSize < contentSize ) ) 
       
  1232             {
       
  1233             aBodyPart.SetFlag( EFSMsgFlag_BodyTruncated );
       
  1234             }
       
  1235         }
       
  1236     HBufC8* buffer = HBufC8::NewLC( fileSize );
       
  1237     TPtr8 ptr = buffer->Des();
       
  1238     User::LeaveIfError( aFile.Read( ptr, fileSize ) );
       
  1239     return buffer;
       
  1240     }
       
  1241 
       
  1242 // ---------------------------------------------------------------------------
       
  1243 // Writes buffer content to given file
       
  1244 // ---------------------------------------------------------------------------
       
  1245 //
       
  1246 // <cmail>
       
  1247 void CFsEmailUiHtmlViewerContainer::WriteContentToFileL( const TDesC8& aContent,
       
  1248     const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart )
       
  1249     {
       
  1250     FUNC_LOG;
       
  1251 
       
  1252     RBuf8 buffer;
       
  1253     buffer.CreateL( aContent );
       
  1254     buffer.CleanupClosePushL();
       
  1255 
       
  1256     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, buffer.Size(), EDriveC ) )
       
  1257          {
       
  1258          // Can not write the data, there's not enough free space on disk.
       
  1259          User::Leave( KErrDiskFull );
       
  1260         }
       
  1261     else
       
  1262         {
       
  1263         RFile targetFile;
       
  1264         CleanupClosePushL( targetFile );
       
  1265 
       
  1266         User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) );
       
  1267 
       
  1268         // Try to find initial html tag (both '<html' and '<HTML' versions are searched)
       
  1269         TInt startTagOffset = buffer.Left( KMaxCharsToSearch ).FindF( KStartTag );
       
  1270 
       
  1271         // Modifying text/html atta IF there's no '<html>' tag anywhere in
       
  1272         // the begining of file (KMaxCharsToSearch) AND there is charset
       
  1273         // parameter available
       
  1274         TBool modificationNeeded( EFalse );
       
  1275         if( startTagOffset == KErrNotFound )
       
  1276             {
       
  1277             modificationNeeded = ETrue;
       
  1278             }
       
  1279 
       
  1280         // Write starting metadata if needed
       
  1281         if ( modificationNeeded )
       
  1282             {
       
  1283             HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart );
       
  1284             CleanupStack::PushL( charSet );
       
  1285 
       
  1286             User::LeaveIfError( targetFile.Write( KHtmlHeader1 ) );
       
  1287             User::LeaveIfError( targetFile.Write( *charSet ) );
       
  1288             User::LeaveIfError( targetFile.Write( KHtmlHeader2 ) );
       
  1289             CleanupStack::PopAndDestroy( charSet );
       
  1290             }
       
  1291         else
       
  1292             {
       
  1293             // Charset tag not found in html body
       
  1294 
       
  1295             if ( buffer.Left( KMaxCharsToSearch ).FindF( KCharsetTag8 ) == KErrNotFound )
       
  1296                 {
       
  1297                 TInt startPos(0);
       
  1298                 if ( ( startPos = buffer.Left( KMaxCharsToSearch ).FindF( KHeadTag ) ) != KErrNotFound )
       
  1299                     {
       
  1300 
       
  1301                     HBufC8* charSet = GetCharacterSetL( aHtmlBodyPart );
       
  1302                     CleanupStack::PushL( charSet );
       
  1303 
       
  1304                     HBufC8* metaBuffer = HBufC8::NewLC( charSet->Des().Length() + KHtmlHeader3().Length() );
       
  1305                     TPtr8 metaHeader( metaBuffer->Des() );
       
  1306                     metaHeader.AppendFormat( KHtmlHeader3, charSet );
       
  1307                     TInt maxLength = buffer.Length() + metaHeader.Length();
       
  1308                     buffer.ReAllocL( maxLength );
       
  1309 
       
  1310                     startPos += KHeadTag().Length();
       
  1311                     buffer.Insert( startPos, metaHeader );
       
  1312 
       
  1313                     CleanupStack::PopAndDestroy( metaBuffer );
       
  1314                     CleanupStack::PopAndDestroy( charSet );
       
  1315                     }
       
  1316                 }
       
  1317             }
       
  1318 
       
  1319         // Write the original content
       
  1320         User::LeaveIfError( targetFile.Write( buffer ) );
       
  1321         if( aHtmlBodyPart.GetFlags() & EFSMsgFlag_BodyTruncated )
       
  1322         	{
       
  1323             //When we found EFSMsgFlag_BodyTruncated was set, add "--- Message limited to %N kB ---" in the end of html view
       
  1324              TInt limit(0);
       
  1325              TInt err = iViewerSettings->Repository().Get( KFreestyleMaxBodySize , limit );
       
  1326              limit *= KKilo; // cenrep value is in kB, 0 means unlimited
       
  1327              if ( limit == 0 || err )
       
  1328                  {
       
  1329                  limit = KMaxTInt;
       
  1330                  }
       
  1331 
       
  1332 // Disable this is PS1 until we have translations available             
       
  1333 //          HBufC* addingText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_VIEW_ADDITIONAL_INFO, limit/KKilo );
       
  1334 //			HBufC8* addingText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *addingText );       
       
  1335 //			CleanupStack::PopAndDestroy( addingText );
       
  1336 //			CleanupStack::PushL( addingText8 );
       
  1337 //			User::LeaveIfError( targetFile.Write( *addingText8 ) );
       
  1338 //			CleanupStack::PopAndDestroy( addingText8 );
       
  1339         	}
       
  1340         // Write ending metadata if needed
       
  1341         if ( modificationNeeded || (aHtmlBodyPart.GetFlags()&EFSMsgFlag_BodyTruncated) )
       
  1342             {
       
  1343             INFO("Add end tags");
       
  1344             User::LeaveIfError( targetFile.Write( KHtmlEndTags ) );
       
  1345             }
       
  1346 
       
  1347         CleanupStack::PopAndDestroy( &targetFile );
       
  1348         }
       
  1349     CleanupStack::PopAndDestroy( &buffer );
       
  1350 // </cmail>
       
  1351     }
       
  1352 
       
  1353 // ---------------------------------------------------------------------------
       
  1354 // Finds the attachment from the list that matches the given content ID
       
  1355 // ---------------------------------------------------------------------------
       
  1356 //
       
  1357 CFSMailMessagePart* CFsEmailUiHtmlViewerContainer::MatchingAttacmentL(
       
  1358     const TDesC& aContentId,
       
  1359     const RPointerArray<CFSMailMessagePart>& aAttachments ) const
       
  1360     {
       
  1361     FUNC_LOG;
       
  1362     TBool contentFound = EFalse;
       
  1363     CFSMailMessagePart* attachment = NULL;
       
  1364     TInt attachmentCount = aAttachments.Count();
       
  1365 
       
  1366     // Check whether one of the attachments has the given conten ID
       
  1367     for ( TInt i = 0; i < attachmentCount && !contentFound; i++ )
       
  1368         {
       
  1369         attachment = aAttachments[i];
       
  1370         const TDesC& contentId = attachment->ContentID();
       
  1371         if ( contentId.Compare( aContentId ) == 0 )
       
  1372             {
       
  1373             contentFound = ETrue;
       
  1374             }
       
  1375         }
       
  1376 
       
  1377     // If attacment with given content ID was not found, check whether
       
  1378     // the given content ID contains the name of one of the attachments
       
  1379     for ( TInt i = 0; i < attachmentCount && !contentFound; ++i )
       
  1380         {
       
  1381         attachment = aAttachments[i];
       
  1382         const TDesC& name = attachment->AttachmentNameL();
       
  1383         if ( aContentId.FindF( name ) >= 0 )
       
  1384             {
       
  1385             contentFound = ETrue;
       
  1386             }
       
  1387         }
       
  1388 
       
  1389     if ( !contentFound )
       
  1390         {
       
  1391         attachment = NULL;
       
  1392         }
       
  1393     return attachment;
       
  1394     }
       
  1395 
       
  1396 // ---------------------------------------------------------------------------
       
  1397 // Resolves link referring to file in temporary HTML folder
       
  1398 // ---------------------------------------------------------------------------
       
  1399 //
       
  1400 TBool CFsEmailUiHtmlViewerContainer::ResolveLinkL( const TDesC& aLink,
       
  1401     TBool aContentId, MBrCtlLinkContent& aEmbeddedLinkContent  )
       
  1402     {
       
  1403     FUNC_LOG;
       
  1404     TBool linkResolved = EFalse;
       
  1405     CFSMailMessagePart* attachment = NULL;
       
  1406 
       
  1407     RPointerArray<CFSMailMessagePart> attachments;
       
  1408     CleanupResetAndDestroyClosePushL( attachments );
       
  1409     iMessage->AttachmentListL( attachments );
       
  1410 
       
  1411     if ( aContentId )
       
  1412         {
       
  1413         attachment = MatchingAttacmentL( aLink, attachments );
       
  1414         }
       
  1415     else
       
  1416         {
       
  1417         const TInt attachmentCount = attachments.Count();
       
  1418         for ( TInt ii = 0; ii < attachmentCount && !attachment; ++ii )
       
  1419             {
       
  1420             if ( aLink.CompareF( attachments[ii]->AttachmentNameL() ) == 0 )
       
  1421                 {
       
  1422                 attachment = attachments[ii];
       
  1423                 }
       
  1424             }
       
  1425         }
       
  1426 
       
  1427     if ( attachment )
       
  1428         {
       
  1429         DownloadAttachmentL( *attachment, aEmbeddedLinkContent );
       
  1430         linkResolved = ETrue;
       
  1431         }
       
  1432 
       
  1433     CleanupStack::PopAndDestroy( &attachments );
       
  1434     return linkResolved;
       
  1435     }
       
  1436 
       
  1437 // ---------------------------------------------------------------------------
       
  1438 // Download attachment and return the content via MBrCtlLinkContent interface
       
  1439 // ---------------------------------------------------------------------------
       
  1440 //
       
  1441 void CFsEmailUiHtmlViewerContainer::DownloadAttachmentL(
       
  1442     CFSMailMessagePart& aAttachment, MBrCtlLinkContent& aEmbeddedLinkContent )
       
  1443     {
       
  1444     FUNC_LOG;
       
  1445     if ( aAttachment.FetchLoadState() == EFSFull )
       
  1446         {
       
  1447         RFile attachmentFile = aAttachment.GetContentFileL();
       
  1448         CleanupClosePushL( attachmentFile );
       
  1449         HBufC8* content = ReadContentFromFileLC( attachmentFile, aAttachment );
       
  1450         aEmbeddedLinkContent.HandleResolveComplete(
       
  1451             aAttachment.GetContentType(), KNullDesC(), content );
       
  1452         CleanupStack::PopAndDestroy( content );
       
  1453         CleanupStack::PopAndDestroy( &attachmentFile );
       
  1454         }
       
  1455     else
       
  1456         {
       
  1457         TPartData partData;
       
  1458         if( iMessage )
       
  1459             {
       
  1460             partData.iMailBoxId = iMessage->GetMailBoxId();
       
  1461             partData.iFolderId = iMessage->GetFolderId();
       
  1462             partData.iMessageId = iMessage->GetMessageId();
       
  1463 
       
  1464             partData.iMessagePartId = aAttachment.GetPartId();
       
  1465 
       
  1466             if ( iAppUi.DownloadInfoMediator() &&
       
  1467                  iAppUi.DownloadInfoMediator()->IsDownloadableL( partData ) )
       
  1468                 {
       
  1469                 ASSERT( iLinkContents.Count() == iMessageParts.Count() );
       
  1470 
       
  1471                 // Append message part details and embedded link content interface
       
  1472                 // to corresponding arrays so that the content can be returned
       
  1473                 // when the download is completed.
       
  1474                 iLinkContents.AppendL( &aEmbeddedLinkContent );
       
  1475                 if ( iMessageParts.Append( partData ) != KErrNone )
       
  1476                     {
       
  1477                     iLinkContents.Remove( iLinkContents.Count() - 1 );
       
  1478                     }
       
  1479 
       
  1480                 ASSERT( iLinkContents.Count() == iMessageParts.Count() );
       
  1481                 if(!iView.GetAsyncFetchStatus())
       
  1482                     {
       
  1483                     iAppUi.DownloadInfoMediator()->AddObserver( this, aAttachment.GetMessageId() );
       
  1484                     iObservingDownload=ETrue;
       
  1485                     iAppUi.DownloadInfoMediator()->DownloadL( partData, EFalse );
       
  1486                     }
       
  1487                 }
       
  1488             }
       
  1489         }
       
  1490     }
       
  1491 
       
  1492 void CFsEmailUiHtmlViewerContainer::SetHTMLResourceFlagFullName()
       
  1493     {
       
  1494     FUNC_LOG;
       
  1495     iHtmlResourceFlagPath.Copy( iHtmlFolderPath );
       
  1496     iHtmlResourceFlagPath.Append( KHtmlFlagFile );
       
  1497     }
       
  1498 
       
  1499 void CFsEmailUiHtmlViewerContainer::EnableHTMLResourceFlagL()
       
  1500     {
       
  1501     FUNC_LOG;
       
  1502     RFile flag;
       
  1503     User::LeaveIfError( flag.Replace(iFs, iHtmlResourceFlagPath, EFileWrite) );
       
  1504     flag.Close();
       
  1505     }
       
  1506 
       
  1507 TBool CFsEmailUiHtmlViewerContainer::HTMLResourceFlagEnabled()
       
  1508     {
       
  1509     FUNC_LOG;
       
  1510     return BaflUtils::FileExists( iFs, iHtmlResourceFlagPath );
       
  1511     }
       
  1512 
       
  1513 void CFsEmailUiHtmlViewerContainer::CopyHTMLResourceL()
       
  1514     {
       
  1515     FUNC_LOG;
       
  1516 
       
  1517     TPath htmlFolderPathInZ;
       
  1518     htmlFolderPathInZ.Copy( KZDrive );
       
  1519 
       
  1520     TFileName privatePath;
       
  1521     User::LeaveIfError( iFs.PrivatePath( privatePath ) );
       
  1522     htmlFolderPathInZ.Append( privatePath );
       
  1523 
       
  1524     htmlFolderPathInZ.Append( KHtmlPath );
       
  1525 
       
  1526     CDir* dirList;
       
  1527     TPath listSpec;
       
  1528     listSpec.Copy( htmlFolderPathInZ );
       
  1529 
       
  1530     listSpec.Append( _L("*.*") );
       
  1531     User::LeaveIfError( iFs.GetDir( listSpec,  KEntryAttMaskSupported, ESortByName, dirList ) );
       
  1532     CleanupStack::PushL( dirList );
       
  1533     for ( TInt i=0; i < dirList->Count(); i++)
       
  1534         {
       
  1535         TPath sourceFileFullName;
       
  1536         sourceFileFullName.Copy( htmlFolderPathInZ );
       
  1537         sourceFileFullName.Append( (*dirList)[i].iName );
       
  1538 
       
  1539         TBool isFolder( EFalse );
       
  1540         BaflUtils::IsFolder( iFs, sourceFileFullName, isFolder);
       
  1541         if ( isFolder )
       
  1542             {
       
  1543             break;
       
  1544             }
       
  1545 
       
  1546         TPath targetFileFullName;
       
  1547         targetFileFullName.Copy( iHtmlFolderPath );
       
  1548         targetFileFullName.Append( (*dirList)[i].iName );
       
  1549         BaflUtils::DeleteFile( iFs, targetFileFullName );
       
  1550 
       
  1551         BaflUtils::CopyFile( iFs, sourceFileFullName, targetFileFullName);
       
  1552         }
       
  1553     CleanupStack::PopAndDestroy( dirList );
       
  1554     }
       
  1555 
       
  1556 void CFsEmailUiHtmlViewerContainer::EnsureHTMLResourceL()
       
  1557     {
       
  1558     FUNC_LOG;
       
  1559 
       
  1560     if ( !HTMLResourceFlagEnabled() )
       
  1561         {
       
  1562         CopyHTMLResourceL();
       
  1563         EnableHTMLResourceFlagL();
       
  1564         }
       
  1565     }
       
  1566 
       
  1567 // ---------------------------------------------------------------------------
       
  1568 // Writes buffer content to given file after adding tags
       
  1569 // ---------------------------------------------------------------------------
       
  1570 //
       
  1571 void CFsEmailUiHtmlViewerContainer::ConvertToHTML( const TDesC& aContent,
       
  1572     const TDesC& aFileName, CFSMailMessagePart& /*aTextBodyPart*/ )
       
  1573     {
       
  1574     FUNC_LOG;
       
  1575    
       
  1576     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, aContent.Size(), EDriveC ) )
       
  1577         {
       
  1578         // Can not write the data, there's not enough free space on disk.
       
  1579         User::Leave( KErrDiskFull );
       
  1580         }
       
  1581 
       
  1582     RBuf htmlText;
       
  1583     CleanupClosePushL( htmlText );
       
  1584         
       
  1585     PlainTextToHtmlConverter::PlainTextToHtmlL( aContent, htmlText );
       
  1586     WriteToFileL( aFileName, htmlText );
       
  1587         
       
  1588     CleanupStack::PopAndDestroy( &htmlText );
       
  1589     }
       
  1590 
       
  1591 
       
  1592 TInt CFsEmailUiHtmlViewerContainer::TotalLengthOfItems( CFindItemEngine& aItemEngine ) const
       
  1593     {
       
  1594     TInt totalLength( 0 );
       
  1595     CFindItemEngine::SFoundItem item;
       
  1596     aItemEngine.ResetPosition();
       
  1597     for ( TBool available( aItemEngine.Item( item ) ); available; available = aItemEngine.NextItem( item ) )
       
  1598         {
       
  1599         totalLength += item.iLength;
       
  1600         }
       
  1601     aItemEngine.ResetPosition();
       
  1602     return totalLength;
       
  1603     }
       
  1604 
       
  1605 // ---------------------------------------------------------------------------
       
  1606 // Get Character set from CFSMailMessagePart
       
  1607 // ---------------------------------------------------------------------------
       
  1608 //
       
  1609 // <cmail>
       
  1610 HBufC8* CFsEmailUiHtmlViewerContainer::GetCharacterSetL( CFSMailMessagePart& aHtmlBodyPart )
       
  1611     {
       
  1612     FUNC_LOG;
       
  1613 
       
  1614     CDesCArray& contentTypeArray( aHtmlBodyPart.ContentTypeParameters() );
       
  1615     HBufC8* charSet = KNullDesC8().AllocLC();
       
  1616 
       
  1617     for ( TInt i = 0; i < contentTypeArray.Count(); i++ )
       
  1618         {
       
  1619         TPtrC contentEntry( contentTypeArray.MdcaPoint( i ) );
       
  1620         if ( ( contentEntry.FindF( KCharsetTag ) != KErrNotFound ) &&
       
  1621                 contentTypeArray.Count() >= ( i+1) )
       
  1622             {
       
  1623             TPtrC value( contentTypeArray.MdcaPoint( i+1 ) );
       
  1624             if ( value.Length() )
       
  1625                 {
       
  1626                 CleanupStack::PopAndDestroy( charSet );
       
  1627                 charSet = NULL;
       
  1628                 charSet = HBufC8::NewLC( value.Length() );
       
  1629                 charSet->Des().Copy( value );
       
  1630                 break;
       
  1631                 }
       
  1632             }
       
  1633         i++;
       
  1634         }
       
  1635 
       
  1636     CleanupStack::Pop( charSet );
       
  1637     return charSet;
       
  1638     }
       
  1639 
       
  1640 void CFsEmailUiHtmlViewerContainer::StopObserving()
       
  1641     {
       
  1642     if( iObservingDownload )
       
  1643         {
       
  1644         if ( iMessage && iAppUi.DownloadInfoMediator() )
       
  1645             {
       
  1646             iAppUi.DownloadInfoMediator()->StopObserving( this, iMessage->GetMessageId() );
       
  1647             }
       
  1648         iObservingDownload=EFalse;
       
  1649         }
       
  1650     }
       
  1651 
       
  1652 void CFsEmailUiHtmlViewerContainer::CancelFetch()
       
  1653     {
       
  1654     FUNC_LOG;
       
  1655     if ( iBrCtlInterface )
       
  1656         {
       
  1657         TRAP_IGNORE( iBrCtlInterface->HandleCommandL( (TInt)TBrCtlDefs::ECommandCancelFetch + (TInt)TBrCtlDefs::ECommandIdBase ));
       
  1658         }
       
  1659     }
       
  1660 
       
  1661 void CFsEmailUiHtmlViewerContainer::ClearCacheAndLoadEmptyContent()
       
  1662     {
       
  1663     FUNC_LOG;
       
  1664     if ( iBrCtlInterface )
       
  1665         {
       
  1666         iBrCtlInterface->ClearCache();
       
  1667         TUid uid;
       
  1668         uid.iUid = KCharacterSetIdentifierUtf8;
       
  1669         TRAP_IGNORE( iBrCtlInterface->LoadDataL(KHTMLDataScheme, KHTMLEmptyContent, _L8("text/html"), uid) );
       
  1670         }
       
  1671     }
       
  1672 
       
  1673 void CFsEmailUiHtmlViewerContainer::HandleResourceChange( TInt aType )
       
  1674     {
       
  1675     CCoeControl::HandleResourceChange( aType );
       
  1676     if ( aType == CFsEmailUiViewBase::EScreenLayoutChanged )
       
  1677         {
       
  1678         RefreshCurrentMailHeader();
       
  1679 	    SetRect( iView.ContainerRect() );
       
  1680         }
       
  1681    }
       
  1682 
       
  1683 void CFsEmailUiHtmlViewerContainer::RefreshCurrentMailHeader()
       
  1684     {
       
  1685     if ( iMessage )
       
  1686         {
       
  1687         // Update the width in header part and reload
       
  1688         TPath headerHtmlFile;
       
  1689         headerHtmlFile.Copy( iHtmlFolderPath );
       
  1690         headerHtmlFile.Append( KHeaderHtmlFile );
       
  1691 
       
  1692             TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs,
       
  1693                 headerHtmlFile, iAppUi.ClientRect().Width(), iScrollPosition,
       
  1694                 iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage),
       
  1695                 iFlags ) )
       
  1696         
       
  1697         
       
  1698         if(!iEventHandler->IsMenuVisible())
       
  1699             {
       
  1700             TRAP_IGNORE( ReloadPageL() );
       
  1701             }
       
  1702         else
       
  1703             {
       
  1704             //Load page asynchronously after dismissing menu
       
  1705             //this is outdated call because it cancels Action menu which is no longer used in 9.2
       
  1706            // iEventHandler->DismissMenuAndReload();
       
  1707             }
       
  1708         }
       
  1709     }
       
  1710 
       
  1711 void CFsEmailUiHtmlViewerContainer::ReloadPageL()
       
  1712     {
       
  1713     TRAP_IGNORE( iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
       
  1714             ( TInt )TBrCtlDefs::ECommandReload ) );
       
  1715     }
       
  1716 
       
  1717 void CFsEmailUiHtmlViewerContainer::ShowAttachmentDownloadStatusL(
       
  1718         TFSProgress::TFSProgressStatus aProgressStatus,
       
  1719         const TAttachmentData& aAttachmentData )
       
  1720     {
       
  1721     TBool freshDraw = EFalse;
       
  1722     //If the indicator was displaying fetching body then we will be displaying a different indicator
       
  1723     //this is just to make sure the image is updated
       
  1724     if(iStatusIndicator)
       
  1725         {
       
  1726         if (iStatusIndicator->Image())
       
  1727             {
       
  1728             if(iStatusIndicator->Image()->Handle() != iAttachmentDownloadImageHandle)
       
  1729                 {
       
  1730                 freshDraw = ETrue;
       
  1731                 }
       
  1732             }
       
  1733         }
       
  1734     if ( !iStatusIndicator )
       
  1735         {
       
  1736         TRect rect = CalcAttachmentStatusRect();
       
  1737         iStatusIndicator = CFreestyleEmailUiAknStatusIndicator::NewL( rect, this );
       
  1738         freshDraw = ETrue;
       
  1739         }
       
  1740 
       
  1741     if ( !iStatusIndicator->IsVisible()
       
  1742          || ( aAttachmentData.downloadProgress == KNone )
       
  1743          || ( aProgressStatus == TFSProgress::EFSStatus_RequestCancelled ) )
       
  1744         {
       
  1745         freshDraw = ETrue;
       
  1746         }
       
  1747 
       
  1748     TInt duration = KStatusIndicatorDefaultDuration;
       
  1749     if ( ( aAttachmentData.downloadProgress == TFSProgress::EFSStatus_RequestComplete )
       
  1750          || ( aProgressStatus == TFSProgress::EFSStatus_RequestCancelled )
       
  1751          || ( aAttachmentData.downloadProgress == KComplete ) )
       
  1752         {
       
  1753         duration = KStatusIndicatorAutomaticHidingDuration;
       
  1754         }
       
  1755 
       
  1756     HBufC* statusText = NULL;
       
  1757     switch ( aProgressStatus )
       
  1758         {
       
  1759         case TFSProgress::EFSStatus_Status:
       
  1760         case TFSProgress::EFSStatus_RequestComplete:
       
  1761             {
       
  1762             CDesCArray* descArray = new (ELeave) CDesCArrayFlat( 1 );
       
  1763             CleanupStack::PushL( descArray );
       
  1764             descArray->AppendL( aAttachmentData.fileName );
       
  1765             CArrayFix<TInt>* intArray = new (ELeave) CArrayFixFlat<TInt>( 1 );
       
  1766             CleanupStack::PushL( intArray );
       
  1767             intArray->AppendL( aAttachmentData.downloadProgress );
       
  1768 
       
  1769             statusText = StringLoader::LoadL( R_FSE_VIEWER_ATTACHMENTS_LIST_DOWNLOAD,
       
  1770                                               *descArray,
       
  1771                                               *intArray );
       
  1772             CleanupStack::PopAndDestroy( intArray );
       
  1773             CleanupStack::PopAndDestroy( descArray );
       
  1774             CleanupStack::PushL( statusText );
       
  1775             }
       
  1776         break;
       
  1777 
       
  1778         case TFSProgress::EFSStatus_RequestCancelled:
       
  1779             {
       
  1780             statusText = aAttachmentData.fileName.AllocLC();
       
  1781             }
       
  1782         break;
       
  1783 
       
  1784         default:
       
  1785             statusText = KNullDesC().AllocLC();
       
  1786             break;
       
  1787         }
       
  1788 
       
  1789     if ( statusText->Length() > 0 )
       
  1790         {
       
  1791         if ( freshDraw )
       
  1792             {
       
  1793             CFbsBitmap* image = NULL;
       
  1794             CFbsBitmap* imageMask = NULL;
       
  1795             if ( aProgressStatus == TFSProgress::EFSStatus_RequestCancelled )
       
  1796                 {
       
  1797                 iAppUi.FsTextureManager()->ProvideBitmapL(EAttachmentsCancelDownload, image, imageMask );
       
  1798                 }
       
  1799             else
       
  1800                 {
       
  1801                 iAppUi.FsTextureManager()->ProvideBitmapL(EAttachmentsDownload, image, imageMask );
       
  1802                 }
       
  1803             if(image)
       
  1804                 {
       
  1805                 iAttachmentDownloadImageHandle = image->Handle();
       
  1806                 }
       
  1807             iStatusIndicator->ShowIndicatorL( image, imageMask, statusText, duration );
       
  1808             }
       
  1809         else
       
  1810             {
       
  1811             iStatusIndicator->SetTextL( statusText );
       
  1812             if ( duration > -1 )
       
  1813                 {
       
  1814                 iStatusIndicator->HideIndicator( duration );
       
  1815                 }
       
  1816             }
       
  1817         }
       
  1818 
       
  1819     CleanupStack::Pop( statusText );
       
  1820     }
       
  1821 
       
  1822 TBool CFsEmailUiHtmlViewerContainer::AttachmentDownloadStatusVisible()
       
  1823     {
       
  1824     if ( iStatusIndicator )
       
  1825         {
       
  1826         return iStatusIndicator->IsVisible();
       
  1827         }
       
  1828     else
       
  1829         {
       
  1830         return EFalse;
       
  1831         }
       
  1832     }
       
  1833 void CFsEmailUiHtmlViewerContainer::ViewerSettingsChangedL( const TUint32 aKey )
       
  1834     {
       
  1835     FUNC_LOG;
       
  1836     if (aKey == KFreestyleEmailDownloadHTMLImages)
       
  1837         {
       
  1838         if (iBrCtlInterface)
       
  1839             {
       
  1840             iBrCtlInterface->SetBrowserSettingL(
       
  1841                 TBrCtlDefs::ESettingsAutoLoadImages,
       
  1842                     iViewerSettings->AutoLoadImages() );
       
  1843             if (iViewerSettings->AutoLoadImages() && iMessage)
       
  1844                 {
       
  1845                 LoadContentFromMailMessageL(iMessage, EFalse);
       
  1846                 }
       
  1847             }
       
  1848         }
       
  1849     }
       
  1850 
       
  1851 void CFsEmailUiHtmlViewerContainer::HideDownloadStatus()
       
  1852     {
       
  1853     if ( iStatusIndicator )
       
  1854         {
       
  1855         iStatusIndicator->MakeVisible( EFalse );
       
  1856         }
       
  1857     }
       
  1858 
       
  1859 TRect CFsEmailUiHtmlViewerContainer::CalcAttachmentStatusRect()
       
  1860     {
       
  1861     TRect rect( Rect() );
       
  1862     TPoint topLeft = rect.iTl;
       
  1863     TPoint bottomRight = rect.iBr;
       
  1864     TPoint statusTopLeft( topLeft.iX + KStatusIndicatorXMargin, bottomRight.iY - KStatusIndicatorHeight + 1 );
       
  1865     TPoint statusBottomRight( bottomRight.iX - KStatusIndicatorXMargin, bottomRight.iY );
       
  1866     rect = TRect(statusTopLeft, statusBottomRight);
       
  1867     rect.Move(0, -KStatusIndicatorBottomMargin);
       
  1868     return rect;
       
  1869     }
       
  1870 
       
  1871 void CFsEmailUiHtmlViewerContainer::TouchFeedback()
       
  1872     {
       
  1873     iTouchFeedBack->InstantFeedback(this, ETouchFeedbackBasic);
       
  1874     }
       
  1875 
       
  1876 /**
       
  1877  * The body fetch link is cmail://body/fetch. Look for the URL separator
       
  1878  * and the presence of cmail and body on the url.
       
  1879  * @param aUrl
       
  1880  * return ETrue for  a valid body URL
       
  1881  */
       
  1882 TBool CFsEmailUiHtmlViewerContainer::IsMessageBodyURLL(const TDesC& aUrl)
       
  1883     {
       
  1884     TInt index = aUrl.Find(KURLSchemeSeparator);
       
  1885     if (index == KErrNotFound)
       
  1886         {
       
  1887         return EFalse;
       
  1888         }
       
  1889     else
       
  1890         {
       
  1891         if (aUrl.Compare(KURLLoadImages()) == 0)
       
  1892             {
       
  1893             iBrCtlInterface->HandleCommandL(TBrCtlDefs::ECommandLoadImages + TBrCtlDefs::ECommandIdBase);
       
  1894             return ETrue;
       
  1895             }
       
  1896         else if (aUrl.Compare(KURLDisplayImages()) == 0)
       
  1897             {
       
  1898             DisplayStatusIndicatorL(KStatusIndicatorAutomaticHidingDuration);
       
  1899 			if( iMessage )
       
  1900 			{
       
  1901             iAppUi.DisplayImagesCache().AddMessageL(*iMessage);
       
  1902 			}
       
  1903             iBrCtlInterface->HandleCommandL(TBrCtlDefs::ECommandLoadImages + TBrCtlDefs::ECommandIdBase);
       
  1904             return ETrue;
       
  1905             }
       
  1906         else if (aUrl.Compare(KURLCollapseHeader()) == 0)
       
  1907             {
       
  1908             TouchFeedback();
       
  1909             iFlags.ClearAll();
       
  1910             return ETrue;
       
  1911             }
       
  1912         else if (aUrl.Compare(KURLExpandHeader()) == 0)
       
  1913             {
       
  1914             TouchFeedback();
       
  1915             iFlags.Set( CFreestyleMessageHeaderHTML::EHeaderExpanded );
       
  1916             return ETrue;        
       
  1917             }
       
  1918         else if ( aUrl.Find( KURLExpandItem() ) == 0 ) {
       
  1919             const TPtrC item( aUrl.Mid( KURLExpandItem().Length() ) );
       
  1920             if ( item.Find( KURLItemTo() ) == 0 )
       
  1921                 {
       
  1922                 iFlags.Assign( CFreestyleMessageHeaderHTML::EToExpanded, ETrue );
       
  1923                 }
       
  1924             else if ( item.Find( KURLItemCc() ) == 0 )
       
  1925                 {
       
  1926                 iFlags.Assign( CFreestyleMessageHeaderHTML::ECcExpanded, ETrue );
       
  1927                 }
       
  1928             else if ( item.Find( KURLItemBcc() ) == 0 )
       
  1929                 {
       
  1930                 iFlags.Assign( CFreestyleMessageHeaderHTML::EBccExpanded, ETrue );
       
  1931                 }
       
  1932             else if ( item.Find( KURLItemAttachments() ) == 0 )
       
  1933                 {
       
  1934                 iFlags.Assign( CFreestyleMessageHeaderHTML::EAttachmentExpanded, ETrue );
       
  1935                 }            
       
  1936             return ETrue;        
       
  1937         } else if (aUrl.Left(index).CompareF(KURLSchemeCmail) == 0)
       
  1938             {
       
  1939             TInt bodyIndex = aUrl.Find(KURLTypeBody);
       
  1940             if (bodyIndex == KErrNotFound)
       
  1941                 {
       
  1942                 return EFalse;
       
  1943                 }
       
  1944             else
       
  1945                 {
       
  1946                 TPtrC16 data= aUrl.Mid(bodyIndex);
       
  1947                 TInt separator = data.Find(KURLSlash);
       
  1948                 if(separator == KErrNotFound)
       
  1949                     {
       
  1950                     return EFalse;
       
  1951                     }
       
  1952                 else
       
  1953                     {
       
  1954                     TPtrC16 temp = data.Mid(separator+1);
       
  1955                     TLex lex(temp);
       
  1956                     lex.Val(iScrollPosition);
       
  1957                     }
       
  1958                 return ETrue;
       
  1959                 }
       
  1960 
       
  1961             }
       
  1962         else
       
  1963             {
       
  1964             return EFalse;
       
  1965             }
       
  1966         }
       
  1967     }
       
  1968 
       
  1969 // ---------------------------------------------------------------------------
       
  1970 // From MBrCtlWindowObserver
       
  1971 // ---------------------------------------------------------------------------
       
  1972 //
       
  1973 CBrCtlInterface* CFsEmailUiHtmlViewerContainer::OpenWindowL( TDesC& /*aUrl*/, TDesC* /*aTargetName*/,
       
  1974                                                              TBool /*aUserInitiated*/, TAny* /*aReserved*/ )
       
  1975     {
       
  1976     return iBrCtlInterface;
       
  1977     }
       
  1978 
       
  1979 // ---------------------------------------------------------------------------
       
  1980 // From MBrCtlWindowObserver
       
  1981 // ---------------------------------------------------------------------------
       
  1982 //
       
  1983 CBrCtlInterface* CFsEmailUiHtmlViewerContainer::FindWindowL( const TDesC& /*aTargetName*/ ) const
       
  1984     {
       
  1985     return NULL;
       
  1986     }
       
  1987 
       
  1988 // ---------------------------------------------------------------------------
       
  1989 // From MBrCtlWindowObserver
       
  1990 // ---------------------------------------------------------------------------
       
  1991 //
       
  1992 void CFsEmailUiHtmlViewerContainer::HandleWindowCommandL( const TDesC& /*aTargetName*/,
       
  1993                                                           TBrCtlWindowCommand /*aCommand*/ )
       
  1994     {
       
  1995 
       
  1996     }
       
  1997 
       
  1998 // ---------------------------------------------------------------------------
       
  1999 // Check if a tap on the URL requires browser(standalone) to be launched
       
  2000 // ---------------------------------------------------------------------------
       
  2001 //
       
  2002 TBool CFsEmailUiHtmlViewerContainer::NeedToLaunchBrowserL( const TDesC& aUrl )
       
  2003     {
       
  2004     TBool launchBrowser( ETrue );
       
  2005     // look for file:///
       
  2006     _LIT( KFileLink, "file:///");
       
  2007     _LIT( KUrlLink, "http");
       
  2008 
       
  2009     // This might be linking to header.html or body.html frames
       
  2010     // Ignore them.
       
  2011     if ( aUrl.Left( KFileLink().Length() ).CompareF( KFileLink ) == 0 )
       
  2012         {
       
  2013         //Now there is a chance that this could be from HTML folder
       
  2014         // Replace all slash character with backslash characters
       
  2015         HBufC* embeddedUrl = aUrl.AllocLC();
       
  2016         TPtr ptr = embeddedUrl->Des();
       
  2017 
       
  2018         _LIT( KBackslash, "\\" );
       
  2019         for ( TInt pos = ptr.Locate('/'); pos >= 0; pos = ptr.Locate('/') )
       
  2020             {
       
  2021             ptr.Replace( pos, 1, KBackslash );
       
  2022             }
       
  2023 
       
  2024         // Check whether given url refers to file in the html folder
       
  2025         TInt pos = embeddedUrl->FindF( iHtmlFolderPath );
       
  2026         CleanupStack::PopAndDestroy( embeddedUrl );
       
  2027         pos >= 0 ? launchBrowser = EFalse : ETrue;
       
  2028         }
       
  2029     // Ignore links starting with cmail://
       
  2030     else if ( aUrl.Left( KURLSchemeCmail().Length() ).CompareF( KURLSchemeCmail ) == 0 )
       
  2031         {
       
  2032         launchBrowser = EFalse;
       
  2033         }
       
  2034     //    THAA-82BEAZ - show popup first
       
  2035     else if ( aUrl.Left(KUrlLink().Length() ).CompareF( KUrlLink ) == 0 )
       
  2036         {
       
  2037         launchBrowser = EFalse;
       
  2038         }
       
  2039     // end THAA-82BEAZ
       
  2040 
       
  2041     return launchBrowser;
       
  2042     }
       
  2043 
       
  2044 // ---------------------------------------------------------------------------
       
  2045 // Launch the browser as a standalone app
       
  2046 // ---------------------------------------------------------------------------
       
  2047 //
       
  2048 void CFsEmailUiHtmlViewerContainer::LaunchBrowserL( const TDesC& aUrl )
       
  2049     {
       
  2050     CSchemeHandler* handler = CSchemeHandler::NewL( aUrl );
       
  2051     CleanupStack::PushL( handler );
       
  2052     handler->HandleUrlStandaloneL();
       
  2053     CleanupStack::PopAndDestroy( handler );
       
  2054     }
       
  2055 
       
  2056 void CFsEmailUiHtmlViewerContainer::PrepareBodyHtmlL( const TDesC& aFileName )
       
  2057     {
       
  2058 
       
  2059     if( iMessage )
       
  2060         {
       
  2061         CFSMailMessagePart* htmlBodyPart = iMessage->HtmlBodyPartL();
       
  2062 
       
  2063         if ( htmlBodyPart )
       
  2064             {
       
  2065             CleanupStack::PushL( htmlBodyPart );
       
  2066             // Copy html body part to email html file
       
  2067             CopyToHtmlFileL( *htmlBodyPart, aFileName );
       
  2068             CleanupStack::PopAndDestroy( htmlBodyPart );
       
  2069             }
       
  2070         else
       
  2071             {
       
  2072             CFSMailMessagePart* textBodyPart = iMessage->PlainTextBodyPartL();
       
  2073 
       
  2074             if ( textBodyPart )
       
  2075                 {
       
  2076                 CleanupStack::PushL( textBodyPart );
       
  2077                 // Copy html body part to email html file
       
  2078                 ConvertToHtmlFileL( *textBodyPart, aFileName );
       
  2079                 CleanupStack::PopAndDestroy( textBodyPart );
       
  2080                 }
       
  2081             else
       
  2082                 {
       
  2083                 User::Leave( KErrNotFound );
       
  2084                 }
       
  2085             }
       
  2086         }
       
  2087     }
       
  2088 
       
  2089 void CFsEmailUiHtmlViewerContainer::WriteEmptyBodyHtmlL( const TDesC& aFileName )
       
  2090     {
       
  2091     FUNC_LOG;
       
  2092     TFileName targetFileName;
       
  2093     targetFileName.Copy( iTempHtmlFolderPath );
       
  2094     targetFileName.Append( aFileName );
       
  2095     
       
  2096     RFile targetFile;
       
  2097     CleanupClosePushL( targetFile );
       
  2098     User::LeaveIfError( targetFile.Replace( iFs, targetFileName, EFileWrite ) );
       
  2099     User::LeaveIfError( targetFile.Write( KHTMLEmptyContent ) );   
       
  2100     CleanupStack::PopAndDestroy( &targetFile );    
       
  2101     }
       
  2102 
       
  2103 void CFsEmailUiHtmlViewerContainer::DisplayStatusIndicatorL(TInt aDuration)
       
  2104     {
       
  2105     FUNC_LOG;
       
  2106     TRect rect = CalcAttachmentStatusRect();
       
  2107     if(!iStatusIndicator)
       
  2108         {
       
  2109         iStatusIndicator  = CFreestyleEmailUiAknStatusIndicator::NewL( rect, this );
       
  2110         }  
       
  2111     CFbsBitmap* image = NULL;
       
  2112     CFbsBitmap* imageMask = NULL;
       
  2113     HBufC* statusText = NULL;
       
  2114     statusText = StringLoader::LoadL(R_FREESTYLE_EMAIL_UI_VIEWER_FETCHING_CONTENT_TEXT);
       
  2115     iAppUi.FsTextureManager()->ProvideBitmapL(EStatusTextureSynchronising, image, imageMask );
       
  2116     iStatusIndicator->ShowIndicatorL( image, imageMask, statusText, aDuration, ETrue );
       
  2117     }
       
  2118 
       
  2119 void CFsEmailUiHtmlViewerContainer::MailListModelUpdatedL()
       
  2120     {
       
  2121     FUNC_LOG;
       
  2122     UpdateOverlayButtons( IsVisible() );    
       
  2123     }
       
  2124 
       
  2125 
       
  2126 void CFsEmailUiHtmlViewerContainer::WriteToFileL(const TDesC& aFileName, RBuf& aHtmlText)
       
  2127     {
       
  2128     _LIT( KCharsetUtf8, "UTF-8" );
       
  2129 
       
  2130     HBufC8* content8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aHtmlText );
       
  2131     CleanupStack::PushL( content8 );        
       
  2132         
       
  2133     RFile targetFile;
       
  2134     CleanupClosePushL( targetFile );
       
  2135     User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) );
       
  2136         
       
  2137     RBuf8 messageHeader;
       
  2138     TInt bufSize = KHtmlHeader1().Length() + KCharsetUtf8().Length() + KHtmlHeader2().Length();
       
  2139     messageHeader.CreateL( bufSize );
       
  2140     messageHeader.CleanupClosePushL();
       
  2141         
       
  2142     messageHeader.Append( KHtmlHeader1 );
       
  2143     messageHeader.Append( KCharsetUtf8 );
       
  2144     messageHeader.Append( KHtmlHeader2 );
       
  2145 
       
  2146     RFileWriteStream fileStream( targetFile );
       
  2147     fileStream.PushL();
       
  2148     fileStream.WriteL( messageHeader.Ptr(), messageHeader.Length() );
       
  2149 
       
  2150     TInt bufPos( 0 );
       
  2151     TInt bufTotalSize = content8->Size();
       
  2152 
       
  2153     while ( bufPos < bufTotalSize )
       
  2154         {
       
  2155         TInt segmentLength = content8->Mid( bufPos ).Length();
       
  2156         fileStream.WriteL( content8->Mid( bufPos ).Ptr(), segmentLength );
       
  2157         bufPos += segmentLength;
       
  2158         }
       
  2159 
       
  2160     fileStream.CommitL();
       
  2161 
       
  2162     CleanupStack::PopAndDestroy( &fileStream );
       
  2163     CleanupStack::PopAndDestroy( &messageHeader );
       
  2164     CleanupStack::PopAndDestroy( &targetFile );
       
  2165     CleanupStack::PopAndDestroy( content8 );
       
  2166     }
       
  2167 
       
  2168 
       
  2169 
       
  2170 /******************************************************************************
       
  2171  * class PlainTextToHtmlConverter
       
  2172  ******************************************************************************/
       
  2173 
       
  2174 
       
  2175 
       
  2176 // -----------------------------------------------------------------------------
       
  2177 // PlainTextToHtmlConverter::PlainTextToHtmlL
       
  2178 // 
       
  2179 // -----------------------------------------------------------------------------
       
  2180 //
       
  2181 void PlainTextToHtmlConverter::PlainTextToHtmlL(const TDesC& aPlainText, RBuf& aHtmlText)
       
  2182     {
       
  2183     const TInt KAllocSize = 1024;
       
  2184     
       
  2185     aHtmlText.Close();
       
  2186     aHtmlText.Create( aPlainText.Length() + KAllocSize );
       
  2187     
       
  2188     const TInt searhCases( CFindItemEngine::EFindItemSearchURLBin );
       
  2189     CFindItemEngine* itemEngine = CFindItemEngine::NewL( aPlainText, CFindItemEngine::TFindItemSearchCase( searhCases ) );
       
  2190     CleanupStack::PushL ( itemEngine );
       
  2191     
       
  2192     TInt currentPos = 0;
       
  2193     CFindItemEngine::SFoundItem item;
       
  2194     for ( TBool available(itemEngine->Item(item)); available; available=itemEngine->NextItem(item) )
       
  2195         {
       
  2196         if ( item.iStartPos < currentPos )
       
  2197             {
       
  2198             break; 
       
  2199             }
       
  2200         
       
  2201         TPtrC textPtr = aPlainText.Mid( currentPos, item.iStartPos-currentPos );
       
  2202         ConvertTextL( textPtr, aHtmlText );
       
  2203         
       
  2204         TPtrC urlPtr = aPlainText.Mid( item.iStartPos, item.iLength );
       
  2205         ConvertUrlL( urlPtr, aHtmlText);
       
  2206         
       
  2207         currentPos = item.iStartPos + item.iLength;
       
  2208         }
       
  2209     
       
  2210     TInt len = aPlainText.Length();
       
  2211     if ( currentPos < len )
       
  2212         {
       
  2213         TPtrC textPtr = aPlainText.Mid( currentPos );
       
  2214         ConvertTextL( textPtr, aHtmlText );
       
  2215         }
       
  2216     
       
  2217     CleanupStack::PopAndDestroy( itemEngine );
       
  2218     }
       
  2219 
       
  2220 
       
  2221 // -----------------------------------------------------------------------------
       
  2222 // PlainTextToHtmlConverter::ConvertTextL
       
  2223 // 
       
  2224 // -----------------------------------------------------------------------------
       
  2225 //
       
  2226 void PlainTextToHtmlConverter::ConvertTextL(const TDesC& aSource, RBuf& aTarget)
       
  2227     {
       
  2228     const TInt KAllocSize = 1024;
       
  2229     const TInt KEntitySize = 32;
       
  2230     
       
  2231     TInt count = aSource.Length();
       
  2232     for ( TInt i=0; i<count; i++ )
       
  2233         {
       
  2234         if ( aTarget.Length() + KEntitySize >= aTarget.MaxLength() )
       
  2235             {
       
  2236             aTarget.ReAllocL( aTarget.MaxLength() + KAllocSize );
       
  2237             }
       
  2238         
       
  2239         TText ch = aSource[i];
       
  2240         switch( ch )
       
  2241             {
       
  2242             case KSOH:  // end of line for IMAP and POP
       
  2243                 aTarget.Append( KHtmlLineBreakCRLF );
       
  2244                 break;
       
  2245             case KLF: // line feed
       
  2246             case KUnicodeNewLineCharacter:
       
  2247             case KUnicodeParagraphCharacter:
       
  2248                 aTarget.Append(KHtmlLineBreak);
       
  2249                 break;  
       
  2250             case KQuotation:
       
  2251                 aTarget.Append( KHtmlQuotation );
       
  2252                 break;
       
  2253             case KAmpersand:
       
  2254                 aTarget.Append( KHtmlAmpersand );
       
  2255                 break;
       
  2256             case KGreaterThan:
       
  2257                 aTarget.Append( KHtmlGreaterThan );
       
  2258                 break;
       
  2259             case KLessThan:
       
  2260                 aTarget.Append( KHtmlLessThan );
       
  2261                 break;
       
  2262             default:
       
  2263                 aTarget.Append( ch );
       
  2264                 break;
       
  2265             }
       
  2266         }
       
  2267     }
       
  2268 
       
  2269 
       
  2270 // -----------------------------------------------------------------------------
       
  2271 // PlainTextToHtmlConverter::ConvertUrlL
       
  2272 // 
       
  2273 // -----------------------------------------------------------------------------
       
  2274 //
       
  2275 void PlainTextToHtmlConverter::ConvertUrlL(const TDesC& aSource, RBuf& aTarget)
       
  2276     {
       
  2277     _LIT( KSchemeDelimiter, "://" );
       
  2278     _LIT( KUrlFormat, "<a href=\"%S\">%S</a>" );
       
  2279     _LIT( KUrlFormatWithHttp, "<a href=\"http://%S\">%S</a>" );
       
  2280         
       
  2281     TPtrC format( KUrlFormat() );
       
  2282     if ( aSource.FindF( KSchemeDelimiter() ) == KErrNotFound ) 
       
  2283         {
       
  2284         format.Set( KUrlFormatWithHttp() );
       
  2285         }
       
  2286     
       
  2287     HBufC* formatBuffer = HBufC::NewLC( format.Length() + aSource.Length() * 2 );
       
  2288     formatBuffer->Des().Format( format, &aSource, &aSource );            
       
  2289     
       
  2290     TInt len = formatBuffer->Des().Length();
       
  2291     if ( aTarget.Length() + len >= aTarget.MaxLength() )
       
  2292         {
       
  2293         aTarget.ReAllocL( aTarget.MaxLength() + len );
       
  2294         }
       
  2295 
       
  2296     aTarget.Append( *formatBuffer );
       
  2297         
       
  2298     CleanupStack::PopAndDestroy( formatBuffer );
       
  2299     }