emailuis/emailui/src/FreestyleEmailUiHtmlViewerContainer.cpp
branchRCL_3
changeset 10 f5907b1a1053
parent 8 e1b6206813b4
child 11 0396474f30f5
equal deleted inserted replaced
8:e1b6206813b4 10:f5907b1a1053
    42 #include "FreestyleEmailUiHtmlViewerView.h"
    42 #include "FreestyleEmailUiHtmlViewerView.h"
    43 #include "FreestyleEmailUiShortcutBinding.h"
    43 #include "FreestyleEmailUiShortcutBinding.h"
    44 
    44 
    45 #include "FreestyleMessageHeaderHTML.h"
    45 #include "FreestyleMessageHeaderHTML.h"
    46 #include "FreestyleMessageHeaderURLEventHandler.h"
    46 #include "FreestyleMessageHeaderURLEventHandler.h"
    47 #include "FreestyleEmailUiAknStatusIndicator.h"
       
    48 #include "FreestyleEmailUiAttachmentsListModel.h"
    47 #include "FreestyleEmailUiAttachmentsListModel.h"
    49 
    48 
    50 _LIT( KContentIdPrefix, "cid:" );
    49 _LIT( KContentIdPrefix, "cid:" );
    51 _LIT( KCDrive, "c:" );
    50 _LIT( KCDrive, "c:" );
    52 _LIT( KHtmlPath, "HtmlFile\\" );
    51 _LIT( KHtmlPath, "HtmlFile\\" );
    83 _LIT8( KHtmlLinkTag, "<a href=\"%S\">" );
    82 _LIT8( KHtmlLinkTag, "<a href=\"%S\">" );
    84 _LIT8( KHtmlLinkTagWWW, "<a href=\"%S%S\">" );
    83 _LIT8( KHtmlLinkTagWWW, "<a href=\"%S%S\">" );
    85 _LIT8( KHtmlLinkEndTag, "</a>" );
    84 _LIT8( KHtmlLinkEndTag, "</a>" );
    86 _LIT( KURLTypeBody, "body");
    85 _LIT( KURLTypeBody, "body");
    87 
    86 
       
    87 _LIT( KURLDisplayImages, "cmail://displayImages/" );
       
    88 _LIT( KURLLoadImages, "cmail://loadImages/" );
       
    89 _LIT( KURLCollapseHeader, "cmail://collapseHeader/" );
       
    90 _LIT( KURLExpandHeader, "cmail://expandHeader/" );
       
    91 
    88 const TText8 KGreaterThan = 0x3e;
    92 const TText8 KGreaterThan = 0x3e;
    89 const TText8 KLessThan = 0x3c;
    93 const TText8 KLessThan = 0x3c;
    90 const TText8 KAmpersand = 0x26;
    94 const TText8 KAmpersand = 0x26;
    91 const TText8 KQuotation = 0x22;
    95 const TText8 KQuotation = 0x22;
    92 const TText8 KCharacterSpace = 0x20;
    96 const TText8 KCharacterSpace = 0x20;
   101 
   105 
   102 
   106 
   103 const TInt KStatusIndicatorHeight = 50;
   107 const TInt KStatusIndicatorHeight = 50;
   104 const TInt KStatusIndicatorXMargin = 50;
   108 const TInt KStatusIndicatorXMargin = 50;
   105 
   109 
       
   110 // CEUiHtmlViewerSettingsKeyListener
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 CEUiHtmlViewerSettingsKeyListener::CEUiHtmlViewerSettingsKeyListener( MObserver& aObserver, TUint32 aKey )
       
   117     : CActive( EPriorityStandard ), iObserver( aObserver ), iKey( aKey )
       
   118     {
       
   119     CActiveScheduler::Add(this);
       
   120     StartListening();
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 CEUiHtmlViewerSettingsKeyListener::~CEUiHtmlViewerSettingsKeyListener()
       
   128     {
       
   129     Cancel();
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 //
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CEUiHtmlViewerSettingsKeyListener::StartListening()
       
   137     {
       
   138     SetActive();
       
   139     iObserver.Repository().NotifyRequest(iKey, iStatus);
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CEUiHtmlViewerSettingsKeyListener::RunL()
       
   147     {
       
   148     iObserver.KeyValueChangedL(iKey);
       
   149     StartListening();
       
   150     }
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 void CEUiHtmlViewerSettingsKeyListener::DoCancel()
       
   157     {
       
   158     iObserver.Repository().NotifyCancel(iKey);
       
   159     }
       
   160 
       
   161 // CEUiHtmlViewerSettings
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 CEUiHtmlViewerSettings* CEUiHtmlViewerSettings::NewL( MObserver& aObserver )
       
   168     {
       
   169     CEUiHtmlViewerSettings* self = new (ELeave) CEUiHtmlViewerSettings(aObserver);
       
   170     CleanupStack::PushL(self);
       
   171     self->ConstructL();
       
   172     CleanupStack::Pop(); // self
       
   173     return self;
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 CEUiHtmlViewerSettings::~CEUiHtmlViewerSettings()
       
   181     {
       
   182     iKeyListeners.ResetAndDestroy();
       
   183     delete iRepository;
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 CEUiHtmlViewerSettings::CEUiHtmlViewerSettings( MObserver& aObserver ) : iObserver( aObserver )
       
   191     {
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CEUiHtmlViewerSettings::ConstructL()
       
   199     {
       
   200     iRepository = CRepository::NewL(KFreestyleEmailCenRep);
       
   201     AddKeyListenerL(KFreestyleEmailDownloadHTMLImages);
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void CEUiHtmlViewerSettings::AddKeyListenerL( TUint32 aKey )
       
   209     {
       
   210     CEUiHtmlViewerSettingsKeyListener* listener = new (ELeave) CEUiHtmlViewerSettingsKeyListener(*this, aKey);
       
   211     CleanupStack::PushL(listener);
       
   212     iKeyListeners.AppendL(listener);
       
   213     CleanupStack::Pop(); // listener
       
   214     UpdateValue(aKey);
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 void CEUiHtmlViewerSettings::UpdateValue( TUint32 aKey )
       
   222     {
       
   223     TInt value;
       
   224     iRepository->Get(aKey, value);
       
   225     switch (aKey)
       
   226         {
       
   227         case KFreestyleEmailDownloadHTMLImages:
       
   228             // 0 = automatic, 1 = ask always
       
   229             iFlags.Assign(aKey, value == 0);
       
   230             break;
       
   231         default:
       
   232             iFlags.Assign(aKey, value);
       
   233             break;
       
   234         }
       
   235     }
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 //
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CEUiHtmlViewerSettings::KeyValueChangedL( TUint32 aKey )
       
   242     {
       
   243     UpdateValue(aKey);
       
   244     iObserver.ViewerSettingsChangedL(aKey);
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 CRepository& CEUiHtmlViewerSettings::Repository()
       
   252     {
       
   253     return *iRepository;
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 TBool CEUiHtmlViewerSettings::AutoLoadImages() const
       
   261     {
       
   262     return iFlags.IsSet(EAutoLoadImages);
       
   263     }
       
   264 
   106 // ---------------------------------------------------------------------------
   265 // ---------------------------------------------------------------------------
   107 // Two-phased constructor.
   266 // Two-phased constructor.
   108 // ---------------------------------------------------------------------------
   267 // ---------------------------------------------------------------------------
   109 //
   268 //
   110 CFsEmailUiHtmlViewerContainer* CFsEmailUiHtmlViewerContainer::NewL(
   269 CFsEmailUiHtmlViewerContainer* CFsEmailUiHtmlViewerContainer::NewL(
   126 CFsEmailUiHtmlViewerContainer::CFsEmailUiHtmlViewerContainer(
   285 CFsEmailUiHtmlViewerContainer::CFsEmailUiHtmlViewerContainer(
   127     CFreestyleEmailUiAppUi& aAppUi, CFsEmailUiHtmlViewerView& aView )
   286     CFreestyleEmailUiAppUi& aAppUi, CFsEmailUiHtmlViewerView& aView )
   128     :
   287     :
   129     iAppUi( aAppUi ),
   288     iAppUi( aAppUi ),
   130     iView( aView ),
   289     iView( aView ),
   131     iFs( CCoeEnv::Static()->FsSession() ),
   290     iFs( iCoeEnv->FsSession() ),
   132     iFirstTime( ETrue )
   291     iFirstTime( ETrue )
   133     {
   292     {
   134     FUNC_LOG;
   293     FUNC_LOG;
   135     }
   294     }
   136 
   295 
   139 // ---------------------------------------------------------------------------
   298 // ---------------------------------------------------------------------------
   140 //
   299 //
   141 CFsEmailUiHtmlViewerContainer::~CFsEmailUiHtmlViewerContainer()
   300 CFsEmailUiHtmlViewerContainer::~CFsEmailUiHtmlViewerContainer()
   142     {
   301     {
   143     FUNC_LOG;
   302     FUNC_LOG;
       
   303     delete iViewerSettings;
   144     if ( iObservingDownload && iAppUi.DownloadInfoMediator() )
   304     if ( iObservingDownload && iAppUi.DownloadInfoMediator() )
   145         {
   305         {
   146         iAppUi.DownloadInfoMediator()->StopObserving( this );
   306         iAppUi.DownloadInfoMediator()->StopObserving( this );
   147         }
   307         }
   148     iFile.Close();
   308     iFile.Close();
   155     delete iStatusIndicator;
   315     delete iStatusIndicator;
   156     delete iOverlayControlNext;
   316     delete iOverlayControlNext;
   157     delete iOverlayControlPrev;
   317     delete iOverlayControlPrev;
   158     }
   318     }
   159 
   319 
   160 // <cmail> Because of browser changes, followings must be performed before iAppUi.exit()
       
   161 void CFsEmailUiHtmlViewerContainer::PrepareForExit()
   320 void CFsEmailUiHtmlViewerContainer::PrepareForExit()
   162     {
   321     {
   163     FUNC_LOG;
   322     FUNC_LOG;
       
   323     HideDownloadStatus();
   164     if ( iObservingDownload && iAppUi.DownloadInfoMediator() )
   324     if ( iObservingDownload && iAppUi.DownloadInfoMediator() )
   165         {
   325         {
   166         iAppUi.DownloadInfoMediator()->StopObserving( this );
   326         iAppUi.DownloadInfoMediator()->StopObserving( this );
   167         iObservingDownload = EFalse;
   327         iObservingDownload = EFalse;
   168         }
   328         }
   169     delete iBrCtlInterface;
   329     delete iBrCtlInterface;
   170     iBrCtlInterface = NULL;
   330     iBrCtlInterface = NULL;
   171     iConnection.Close();
   331     iConnection.Close();
   172     iSocketServer.Close();
   332     iSocketServer.Close();
   173     }
   333     }
   174 // </cmail>
   334 
       
   335 void CFsEmailUiHtmlViewerContainer::PrepareForMessageNavigation()
       
   336     {
       
   337     FUNC_LOG;
       
   338     ResetContent();
       
   339     }
   175 
   340 
   176 void CFsEmailUiHtmlViewerContainer::ConstructL()
   341 void CFsEmailUiHtmlViewerContainer::ConstructL()
   177     {
   342     {
   178     FUNC_LOG;
   343     FUNC_LOG;
   179     
   344     iViewerSettings = CEUiHtmlViewerSettings::NewL(*this);
       
   345 
   180     SetHtmlFolderPathL();
   346     SetHtmlFolderPathL();
   181     BaflUtils::EnsurePathExistsL( iFs, iHtmlFolderPath );
   347     BaflUtils::EnsurePathExistsL( iFs, iHtmlFolderPath );
   182     SetTempHtmlFolderPath();
   348     SetTempHtmlFolderPath();
   183     BaflUtils::EnsurePathExistsL( iFs, iTempHtmlFolderPath );
   349     BaflUtils::EnsurePathExistsL( iFs, iTempHtmlFolderPath );
   184     SetHTMLResourceFlagFullName();
   350     SetHTMLResourceFlagFullName();
   193                               TBrCtlDefs::ECapabilityLoadHttpFw |
   359                               TBrCtlDefs::ECapabilityLoadHttpFw |
   194                               TBrCtlDefs::ECapabilityCursorNavigation;
   360                               TBrCtlDefs::ECapabilityCursorNavigation;
   195 
   361 
   196     // Set browsercontrol to whole screen
   362     // Set browsercontrol to whole screen
   197     TRect rect( TPoint(), Size() );
   363     TRect rect( TPoint(), Size() );
   198 
   364    
   199     iBrCtlInterface = CreateBrowserControlL( this, rect, brCtlCapabilities,
   365     iBrCtlInterface = CreateBrowserControlL( 
   200         TBrCtlDefs::ECommandIdBase, NULL, this, this, NULL, NULL, this, NULL );
   366             this, // aParent 
       
   367             rect,  // aRect
       
   368             brCtlCapabilities, // aBrCtlCapabilities
       
   369             TBrCtlDefs::ECommandIdBase, // aCommandIdBase
       
   370             NULL, // aBrCtlSoftkeysObserver
       
   371             this, // aBrCtlLinkResolver
       
   372             this, // aBrCtlSpecialLoadObserver
       
   373             NULL, // aBrCtlLayoutObserver
       
   374             NULL, // aBrCtlDialogsProvider
       
   375             this, // aBrCtlWindowObserver
       
   376             NULL // aBrCtlDownloadObserver 
       
   377             );
   201 
   378 
   202     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsEmbedded, ETrue );
   379     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsEmbedded, ETrue );
   203     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages, ETrue );
   380     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsAutoLoadImages, iViewerSettings->AutoLoadImages() );
   204     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsPageOverview, EFalse );
   381     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsPageOverview, EFalse );
   205     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsTextWrapEnabled, ETrue );
   382     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsTextWrapEnabled, ETrue );
   206     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsFontSize, TBrCtlDefs::EFontSizeLevelLarger );
   383     iBrCtlInterface->SetBrowserSettingL( TBrCtlDefs::ESettingsFontSize, TBrCtlDefs::EFontSizeLevelLarger );
   207 
   384     
   208     iEventHandler = CFreestyleMessageHeaderURLEventHandler::NewL( iAppUi, iView );
   385     iEventHandler = CFreestyleMessageHeaderURLEventHandler::NewL( iAppUi, iView );
   209     
   386     
   210     TRect nextButtonRect = OverlayButtonRect( EFalse );
   387     TRect nextButtonRect = OverlayButtonRect( EFalse );
   211     iOverlayControlNext = COverlayControl::NewL( this, this, nextButtonRect, 
   388     iOverlayControlNext = COverlayControl::NewL( this, this, nextButtonRect, 
   212             EMbmFreestyleemailuiQgn_indi_cmail_arrow_next, 
   389             EMbmFreestyleemailuiQgn_indi_cmail_arrow_next, 
   216     iOverlayControlPrev = COverlayControl::NewL( this, this, prevButtonRect,
   393     iOverlayControlPrev = COverlayControl::NewL( this, this, prevButtonRect,
   217             EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous,
   394             EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous,
   218             EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous_mask );
   395             EMbmFreestyleemailuiQgn_indi_cmail_arrow_previous_mask );
   219     iScrollPosition = 0;
   396     iScrollPosition = 0;
   220     iAttachmentDownloadImageHandle = 0;
   397     iAttachmentDownloadImageHandle = 0;
       
   398 
       
   399     iTouchFeedBack = MTouchFeedback::Instance();
       
   400     iTouchFeedBack->EnableFeedbackForControl(this, ETrue);
       
   401 
   221     ActivateL();
   402     ActivateL();
   222     }
   403     }
   223 
   404 
   224 void CFsEmailUiHtmlViewerContainer::MakeVisible( TBool aVisible )
   405 void CFsEmailUiHtmlViewerContainer::MakeVisible( TBool aVisible )
   225     {
   406     {
   347     headerHtmlFile.Append( KHeaderHtmlFile );
   528     headerHtmlFile.Append( KHeaderHtmlFile );
   348     
   529     
   349     // insert email header into email.html file
   530     // insert email header into email.html file
   350     // CFreestyleMessageHeaderHTML will replace contents of email.html
   531     // CFreestyleMessageHeaderHTML will replace contents of email.html
   351     // So, no need to clear the contents
   532     // So, no need to clear the contents
   352     TLanguage language = User::Language();
       
   353     TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language );    
       
   354     if(aResetScrollPos)
   533     if(aResetScrollPos)
   355         {
   534         {
   356         iScrollPosition = 0; 
   535         iScrollPosition = 0; 
   357         }
   536         }
   358     if ( AknLayoutUtils::LayoutMirrored() )
   537     const TInt visibleWidth(iAppUi.ClientRect().Width());
   359         {
   538     CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, visibleWidth, iScrollPosition,
   360         direction = TBidiText::ERightToLeft;
   539                                             iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage),
   361         }
   540                                             iHeaderExpanded );
   362     else
       
   363         {
       
   364         direction = TBidiText::ELeftToRight;
       
   365         }
       
   366     CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, iAppUi.ClientRect().Width(), 
       
   367                                             iScrollPosition,
       
   368                                             direction);
       
   369     
   541     
   370     // Remove all previously created files from temporary HTML folder
   542     // Remove all previously created files from temporary HTML folder
   371     EmptyTempHtmlFolderL();
   543     EmptyTempHtmlFolderL();
   372 
   544 
   373     TRAPD( error, PrepareBodyHtmlL( KBodyHtmlFile ) );
   545     TRAPD( error, PrepareBodyHtmlL( KBodyHtmlFile ) );
   394 
   566 
   395 // ---------------------------------------------------------------------------
   567 // ---------------------------------------------------------------------------
   396 // Reset content
   568 // Reset content
   397 // ---------------------------------------------------------------------------
   569 // ---------------------------------------------------------------------------
   398 //
   570 //
   399 void CFsEmailUiHtmlViewerContainer::ResetContent()
   571 void CFsEmailUiHtmlViewerContainer::ResetContent(const TBool aDisconnect)
   400     {
   572     {
   401     FUNC_LOG;
   573     FUNC_LOG;
   402     if ( iBrCtlInterface )
   574     if ( iBrCtlInterface )
   403         {
   575         {
   404         TRAP_IGNORE( iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase + 
   576         TRAP_IGNORE( 
   405                                                       ( TInt )TBrCtlDefs::ECommandFreeMemory ) );
   577                 iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
       
   578                         ( TInt )TBrCtlDefs::ECommandFreeMemory ) );
       
   579         if (aDisconnect)
       
   580             {
       
   581             TRAP_IGNORE( 
       
   582                     iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
       
   583                                                       ( TInt )TBrCtlDefs::ECommandDisconnect ) );
       
   584             }
   406         }
   585         }
   407     iFile.Close();
   586     iFile.Close();
   408     iLinkContents.Reset();
   587     iLinkContents.Reset();
   409     iMessageParts.Reset();
   588     iMessageParts.Reset();
   410     iMessage = NULL;
   589     iMessage = NULL;
       
   590     iHeaderExpanded = EFalse;
       
   591     iScrollPosition = 0;
   411     }
   592     }
   412 
   593 
   413 // ---------------------------------------------------------------------------
   594 // ---------------------------------------------------------------------------
   414 // From CCoeControl.
   595 // From CCoeControl.
   415 // ---------------------------------------------------------------------------
   596 // ---------------------------------------------------------------------------
   490 
   671 
   491     TRect rect = Rect();
   672     TRect rect = Rect();
   492     if ( iBrCtlInterface )
   673     if ( iBrCtlInterface )
   493         {
   674         {
   494         iBrCtlInterface->SetRect( rect );
   675         iBrCtlInterface->SetRect( rect );
   495         }
       
   496 
       
   497     if ( iMessage )
       
   498         {
       
   499         // update the width in header part and reload
       
   500         TPath headerHtmlFile;
       
   501         headerHtmlFile.Copy( iHtmlFolderPath );
       
   502         headerHtmlFile.Append( KHeaderHtmlFile );
       
   503 
       
   504         TLanguage language = User::Language();
       
   505         TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language );
       
   506         
       
   507         if ( AknLayoutUtils::LayoutMirrored() )
       
   508             {
       
   509             direction = TBidiText::ERightToLeft;
       
   510             }
       
   511         else
       
   512             {
       
   513             direction = TBidiText::ELeftToRight;
       
   514             }
       
   515         TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, 
       
   516             rect.Width(), iScrollPosition, direction ) ) 
       
   517         
       
   518         TPath emailHtmlFile;
       
   519         emailHtmlFile.Copy( iHtmlFolderPath );
       
   520         if ( AknLayoutUtils::LayoutMirrored() )
       
   521             {
       
   522             emailHtmlFile.Append( KMessageHtmlRTLFile );
       
   523             }
       
   524         else
       
   525             {
       
   526             emailHtmlFile.Append( KMessageHtmlFile );
       
   527             }
       
   528         }
   676         }
   529     
   677     
   530     UpdateOverlayButtons( IsVisible() );
   678     UpdateOverlayButtons( IsVisible() );
   531     
   679     
   532     if ( iStatusIndicator )
   680     if ( iStatusIndicator )
   736 //
   884 //
   737 TBool CFsEmailUiHtmlViewerContainer::ResolveLinkL( const TDesC& aUrl,
   885 TBool CFsEmailUiHtmlViewerContainer::ResolveLinkL( const TDesC& aUrl,
   738     const TDesC& /*aCurrentUrl*/, MBrCtlLinkContent& /*aBrCtlLinkContent*/ )
   886     const TDesC& /*aCurrentUrl*/, MBrCtlLinkContent& /*aBrCtlLinkContent*/ )
   739     {
   887     {
   740     FUNC_LOG;
   888     FUNC_LOG;
   741     if (IsMessageBodyURL(aUrl))
   889     if ( IsMessageBodyURLL(aUrl) )
   742         {
   890         {
   743         iView.StartFetchingMessageL();
   891         if ( iMessage )
       
   892             {
       
   893             iView.StartFetchingMessageL();
       
   894             }
   744         return ETrue;
   895         return ETrue;
   745         }
   896         }
   746     else
   897     else
   747         {
   898         {
   748         if ( NeedToLaunchBrowserL( aUrl ) )
   899         if ( NeedToLaunchBrowserL( aUrl ) )
  1199 // Writes buffer content to given file after adding tags
  1350 // Writes buffer content to given file after adding tags
  1200 // ---------------------------------------------------------------------------
  1351 // ---------------------------------------------------------------------------
  1201 //
  1352 //
  1202 // <cmail>
  1353 // <cmail>
  1203 void CFsEmailUiHtmlViewerContainer::ConvertToHTML( const TDesC8& aContent,
  1354 void CFsEmailUiHtmlViewerContainer::ConvertToHTML( const TDesC8& aContent,
  1204     const TDesC& aFileName, CFSMailMessagePart& aTextBodyPart )
  1355     const TDesC& aFileName, CFSMailMessagePart& /*aTextBodyPart*/ )
  1205     {
  1356     {
  1206     FUNC_LOG;
  1357     FUNC_LOG;
  1207     const TInt KBodyTextChunkSizeBytes = 1024;
  1358     const TInt KBodyTextChunkSizeBytes = 1024;
  1208     
  1359     
  1209     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, aContent.Size(), EDriveC ) )
  1360     if ( SysUtil::DiskSpaceBelowCriticalLevelL( &iFs, aContent.Size(), EDriveC ) )
  1595     CDesCArray& contentTypeArray( aHtmlBodyPart.ContentTypeParameters() );
  1746     CDesCArray& contentTypeArray( aHtmlBodyPart.ContentTypeParameters() );
  1596     HBufC8* charSet = KNullDesC8().AllocLC();   
  1747     HBufC8* charSet = KNullDesC8().AllocLC();   
  1597     
  1748     
  1598     for ( TInt i = 0; i < contentTypeArray.Count(); i++ )
  1749     for ( TInt i = 0; i < contentTypeArray.Count(); i++ )
  1599         {
  1750         {
  1600         if ( ( contentTypeArray.MdcaPoint( i ).Find( KCharsetTag ) != KErrNotFound ) &&
  1751         TPtrC contentEntry( contentTypeArray.MdcaPoint( i ) );
       
  1752         if ( ( contentEntry.FindF( KCharsetTag ) != KErrNotFound ) &&
  1601                 contentTypeArray.Count() >= ( i+1) )  
  1753                 contentTypeArray.Count() >= ( i+1) )  
  1602             {
  1754             {
  1603             TPtrC value( contentTypeArray.MdcaPoint( i+1 ) );
  1755             TPtrC value( contentTypeArray.MdcaPoint( i+1 ) );
  1604             if ( value.Length() )
  1756             if ( value.Length() )
  1605                 {
  1757                 {
  1651     }
  1803     }
  1652 
  1804 
  1653 void CFsEmailUiHtmlViewerContainer::HandleResourceChange( TInt aType )
  1805 void CFsEmailUiHtmlViewerContainer::HandleResourceChange( TInt aType )
  1654     {
  1806     {
  1655     CCoeControl::HandleResourceChange( aType );
  1807     CCoeControl::HandleResourceChange( aType );
       
  1808     if ( aType == CFsEmailUiViewBase::EScreenLayoutChanged )
       
  1809         {
       
  1810         RefreshCurrentMailHeader();
       
  1811         }
  1656     }
  1812     }
  1657 
  1813 
  1658 void CFsEmailUiHtmlViewerContainer::RefreshCurrentMailHeader()
  1814 void CFsEmailUiHtmlViewerContainer::RefreshCurrentMailHeader()
  1659     {
  1815     {
  1660     if ( iMessage )
  1816     if ( iMessage )
  1662         // Update the width in header part and reload
  1818         // Update the width in header part and reload
  1663         TPath headerHtmlFile;
  1819         TPath headerHtmlFile;
  1664         headerHtmlFile.Copy( iHtmlFolderPath );
  1820         headerHtmlFile.Copy( iHtmlFolderPath );
  1665         headerHtmlFile.Append( KHeaderHtmlFile );
  1821         headerHtmlFile.Append( KHeaderHtmlFile );
  1666         
  1822         
  1667         TLanguage language = User::Language();
  1823             TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs,
  1668         TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language );    
  1824                 headerHtmlFile, iAppUi.ClientRect().Width(), iScrollPosition,
  1669         TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, iAppUi.ClientRect().Width(), direction ) )
  1825                 iViewerSettings->AutoLoadImages() || iAppUi.DisplayImagesCache().Contains(*iMessage),
       
  1826                 iHeaderExpanded ) )
  1670         
  1827         
  1671         TPath emailHtmlFile;
       
  1672         emailHtmlFile.Copy( iHtmlFolderPath );
       
  1673         emailHtmlFile.Append( KMessageHtmlFile );
       
  1674         
  1828         
  1675         if ( direction == TBidiText::ELeftToRight )
  1829         if(!iEventHandler->IsMenuVisible())
  1676             {
  1830             {
  1677             emailHtmlFile.Append( KMessageHtmlFile );
  1831             TRAP_IGNORE( ReloadPageL() );
  1678             }
  1832             }
  1679         else
  1833         else
  1680             {
  1834             {
  1681             emailHtmlFile.Append( KMessageHtmlRTLFile );
  1835             //Load page asynchronously after dismissing menu    
  1682             }
       
  1683         
       
  1684         //Load page synchronously if menu invisible
       
  1685         if(!iEventHandler->IsMenuVisible())
       
  1686             {
       
  1687             TRAP_IGNORE( LoadContentFromFileL( emailHtmlFile ) );
       
  1688             SetRect( iAppUi.ClientRect() );
       
  1689             }
       
  1690         //Load page asynchronously after dismissing menu    
       
  1691         else
       
  1692             {
       
  1693             iEventHandler->DismissMenuAndReload();
  1836             iEventHandler->DismissMenuAndReload();
  1694             }       
  1837             }
  1695         }
  1838         }
  1696     }
  1839     }
  1697 
  1840 
  1698 void CFsEmailUiHtmlViewerContainer::ReloadPageL()
  1841 void CFsEmailUiHtmlViewerContainer::ReloadPageL()
  1699     {
  1842     {
  1700     TLanguage language = User::Language();
  1843     TRAP_IGNORE( iBrCtlInterface->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
  1701     TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language );    
  1844             ( TInt )TBrCtlDefs::ECommandReload ) );
  1702     TPath emailHtmlFile;
       
  1703     emailHtmlFile.Copy( iHtmlFolderPath );
       
  1704     if( !AknLayoutUtils::LayoutMirrored() )
       
  1705         {
       
  1706         emailHtmlFile.Append( KMessageHtmlFile );
       
  1707         }
       
  1708     else
       
  1709         {
       
  1710         emailHtmlFile.Append( KMessageHtmlRTLFile );
       
  1711         }
       
  1712     TRAP_IGNORE( LoadContentFromFileL( emailHtmlFile ) );
       
  1713     SetRect( iAppUi.ClientRect() );
       
  1714     }
  1845     }
  1715 
  1846 
  1716 void CFsEmailUiHtmlViewerContainer::ShowAttachmentDownloadStatusL( 
  1847 void CFsEmailUiHtmlViewerContainer::ShowAttachmentDownloadStatusL( 
  1717         TFSProgress::TFSProgressStatus aProgressStatus, 
  1848         TFSProgress::TFSProgressStatus aProgressStatus, 
  1718         const TAttachmentData& aAttachmentData )
  1849         const TAttachmentData& aAttachmentData )
  1827     else
  1958     else
  1828         {
  1959         {
  1829         return EFalse;
  1960         return EFalse;
  1830         }
  1961         }
  1831     }
  1962     }
       
  1963 void CFsEmailUiHtmlViewerContainer::ViewerSettingsChangedL( const TUint32 aKey )
       
  1964     {
       
  1965     FUNC_LOG;
       
  1966     if (aKey == KFreestyleEmailDownloadHTMLImages)
       
  1967         {
       
  1968         if (iBrCtlInterface)
       
  1969             {
       
  1970             iBrCtlInterface->SetBrowserSettingL(
       
  1971                 TBrCtlDefs::ESettingsAutoLoadImages,
       
  1972                     iViewerSettings->AutoLoadImages() );
       
  1973             if (iViewerSettings->AutoLoadImages() && iMessage)
       
  1974                 {
       
  1975                 LoadContentFromMailMessageL(iMessage, EFalse);
       
  1976                 }
       
  1977             }
       
  1978         }
       
  1979     }
  1832 
  1980 
  1833 void CFsEmailUiHtmlViewerContainer::HideDownloadStatus()
  1981 void CFsEmailUiHtmlViewerContainer::HideDownloadStatus()
  1834     {
  1982     {
  1835     if ( iStatusIndicator )
  1983     if ( iStatusIndicator )
  1836         {
  1984         {
  1845     TPoint bottomRight = rect.iBr;
  1993     TPoint bottomRight = rect.iBr;
  1846     
  1994     
  1847     TPoint statusTopLeft( topLeft.iX + KStatusIndicatorXMargin, bottomRight.iY - KStatusIndicatorHeight + 1 );
  1995     TPoint statusTopLeft( topLeft.iX + KStatusIndicatorXMargin, bottomRight.iY - KStatusIndicatorHeight + 1 );
  1848     TPoint statusBottomRight( bottomRight.iX - KStatusIndicatorXMargin, bottomRight.iY );
  1996     TPoint statusBottomRight( bottomRight.iX - KStatusIndicatorXMargin, bottomRight.iY );
  1849     return TRect( statusTopLeft, statusBottomRight );
  1997     return TRect( statusTopLeft, statusBottomRight );
       
  1998     }
       
  1999 
       
  2000 void CFsEmailUiHtmlViewerContainer::TouchFeedback()
       
  2001     {
       
  2002     iTouchFeedBack->InstantFeedback(this, ETouchFeedbackBasic);  
  1850     }
  2003     }
  1851 
  2004 
  1852 /**
  2005 /**
  1853  * The body fetch link is cmail://body/fetch. Look for the URL separator
  2006  * The body fetch link is cmail://body/fetch. Look for the URL separator
  1854  * and the presence of cmail and body on the url.
  2007  * and the presence of cmail and body on the url.
  1855  * @param aUrl 
  2008  * @param aUrl 
  1856  * return ETrue for  a valid body URL
  2009  * return ETrue for  a valid body URL
  1857  */
  2010  */
  1858 TBool CFsEmailUiHtmlViewerContainer::IsMessageBodyURL(const TDesC& aUrl)
  2011 TBool CFsEmailUiHtmlViewerContainer::IsMessageBodyURLL(const TDesC& aUrl)
  1859     {
  2012     {
  1860     TInt index = aUrl.Find(KURLSchemeSeparator);
  2013     TInt index = aUrl.Find(KURLSchemeSeparator);
  1861     if (index == KErrNotFound)
  2014     if (index == KErrNotFound)
  1862         {
  2015         {
  1863         return EFalse;
  2016         return EFalse;
  1864         }
  2017         }
  1865     else
  2018     else
  1866         {
  2019         {
  1867         if (aUrl.Left(index).CompareF(KURLSchemeCmail) == 0)
  2020         if (aUrl.Compare(KURLLoadImages()) == 0)
       
  2021             {
       
  2022             iBrCtlInterface->HandleCommandL(TBrCtlDefs::ECommandLoadImages + TBrCtlDefs::ECommandIdBase);
       
  2023             return ETrue;
       
  2024             }
       
  2025         else if (aUrl.Compare(KURLDisplayImages()) == 0)
       
  2026             {
       
  2027             DisplayStatusIndicatorL(KStatusIndicatorAutomaticHidingDuration);
       
  2028             iAppUi.DisplayImagesCache().AddMessageL(*iMessage);
       
  2029             iBrCtlInterface->HandleCommandL(TBrCtlDefs::ECommandLoadImages + TBrCtlDefs::ECommandIdBase);
       
  2030             return ETrue;
       
  2031             }
       
  2032         else if (aUrl.Compare(KURLCollapseHeader()) == 0)
       
  2033             {
       
  2034             TouchFeedback();
       
  2035             iHeaderExpanded = EFalse;
       
  2036             return ETrue;
       
  2037             }
       
  2038         else if (aUrl.Compare(KURLExpandHeader()) == 0)
       
  2039             {
       
  2040             TouchFeedback();
       
  2041             iHeaderExpanded = ETrue;
       
  2042             return ETrue;        
       
  2043             }
       
  2044         else if (aUrl.Left(index).CompareF(KURLSchemeCmail) == 0)
  1868             {
  2045             {
  1869             TInt bodyIndex = aUrl.Find(KURLTypeBody);                      
  2046             TInt bodyIndex = aUrl.Find(KURLTypeBody);                      
  1870             if (bodyIndex == KErrNotFound)
  2047             if (bodyIndex == KErrNotFound)
  1871                 {
  2048                 {
  1872                 return EFalse;
  2049                 return EFalse;
  1893             {
  2070             {
  1894             return EFalse;
  2071             return EFalse;
  1895             }
  2072             }
  1896         }
  2073         }
  1897     } 
  2074     } 
       
  2075 
  1898 // ---------------------------------------------------------------------------
  2076 // ---------------------------------------------------------------------------
  1899 // From MBrCtlWindowObserver
  2077 // From MBrCtlWindowObserver
  1900 // ---------------------------------------------------------------------------
  2078 // ---------------------------------------------------------------------------
  1901 //
  2079 //
  1902 CBrCtlInterface* CFsEmailUiHtmlViewerContainer::OpenWindowL( TDesC& /*aUrl*/, TDesC* /*aTargetName*/, 
  2080 CBrCtlInterface* CFsEmailUiHtmlViewerContainer::OpenWindowL( TDesC& /*aUrl*/, TDesC* /*aTargetName*/, 
  1931 TBool CFsEmailUiHtmlViewerContainer::NeedToLaunchBrowserL( const TDesC& aUrl )
  2109 TBool CFsEmailUiHtmlViewerContainer::NeedToLaunchBrowserL( const TDesC& aUrl )
  1932     {
  2110     {
  1933     TBool launchBrowser( ETrue );
  2111     TBool launchBrowser( ETrue );
  1934     // look for file:///
  2112     // look for file:///
  1935     _LIT( KFileLink, "file:///");
  2113     _LIT( KFileLink, "file:///");
       
  2114     _LIT( KUrlLink, "http");
  1936     
  2115     
  1937     // This might be linking to header.html or body.html frames
  2116     // This might be linking to header.html or body.html frames
  1938     // Ignore them.
  2117     // Ignore them.
  1939     if ( aUrl.Left( KFileLink().Length() ).CompareF( KFileLink ) == 0 )
  2118     if ( aUrl.Left( KFileLink().Length() ).CompareF( KFileLink ) == 0 )
  1940         {
  2119         {
  1957     // Ignore links starting with cmail://
  2136     // Ignore links starting with cmail://
  1958     else if ( aUrl.Left( KURLSchemeCmail().Length() ).CompareF( KURLSchemeCmail ) == 0 )
  2137     else if ( aUrl.Left( KURLSchemeCmail().Length() ).CompareF( KURLSchemeCmail ) == 0 )
  1959         {
  2138         {
  1960         launchBrowser = EFalse;
  2139         launchBrowser = EFalse;
  1961         }
  2140         }
       
  2141     //    THAA-82BEAZ - show popup first 
       
  2142     else if ( aUrl.Left(KUrlLink().Length() ).CompareF( KUrlLink ) == 0 )
       
  2143         {
       
  2144         launchBrowser = EFalse;
       
  2145         }
       
  2146     // end THAA-82BEAZ
  1962 
  2147 
  1963     return launchBrowser;
  2148     return launchBrowser;
  1964     }
  2149     }
  1965 
  2150 
  1966 // ---------------------------------------------------------------------------
  2151 // ---------------------------------------------------------------------------
  2016     User::LeaveIfError( targetFile.Replace( iFs, targetFileName, EFileWrite ) );
  2201     User::LeaveIfError( targetFile.Replace( iFs, targetFileName, EFileWrite ) );
  2017     User::LeaveIfError( targetFile.Write( KHTMLEmptyContent ) );   
  2202     User::LeaveIfError( targetFile.Write( KHTMLEmptyContent ) );   
  2018     CleanupStack::PopAndDestroy( &targetFile );    
  2203     CleanupStack::PopAndDestroy( &targetFile );    
  2019     }
  2204     }
  2020 
  2205 
  2021 void CFsEmailUiHtmlViewerContainer::DisplayStatusIndicatorL()
  2206 void CFsEmailUiHtmlViewerContainer::DisplayStatusIndicatorL(TInt aDuration)
  2022     {
  2207     {
  2023     TRect rect = CalcAttachmentStatusRect();  
  2208     FUNC_LOG;
       
  2209     TRect rect = CalcAttachmentStatusRect();
  2024     if(!iStatusIndicator)
  2210     if(!iStatusIndicator)
  2025         {
  2211         {
  2026         iStatusIndicator  = CFreestyleEmailUiAknStatusIndicator::NewL( rect, this );
  2212         iStatusIndicator  = CFreestyleEmailUiAknStatusIndicator::NewL( rect, this );
  2027         }  
  2213         }  
  2028     CFbsBitmap* image = NULL;
  2214     CFbsBitmap* image = NULL;
  2029     CFbsBitmap* imageMask = NULL;
  2215     CFbsBitmap* imageMask = NULL;
  2030     TInt duration = KStatusIndicatorDefaultDuration;
       
  2031     HBufC* statusText = NULL;
  2216     HBufC* statusText = NULL;
  2032     statusText = StringLoader::LoadL(R_FREESTYLE_EMAIL_UI_VIEWER_FETCHING_CONTENT_TEXT);
  2217     statusText = StringLoader::LoadL(R_FREESTYLE_EMAIL_UI_VIEWER_FETCHING_CONTENT_TEXT);
  2033     iAppUi.FsTextureManager()->ProvideBitmapL(EStatusTextureSynchronising, image, imageMask );
  2218     iAppUi.FsTextureManager()->ProvideBitmapL(EStatusTextureSynchronising, image, imageMask );
  2034     iStatusIndicator->ShowIndicatorL( image, imageMask, statusText, duration );
  2219     iStatusIndicator->ShowIndicatorL( image, imageMask, statusText, aDuration );
  2035     }
  2220     }
       
  2221