20 #include <AknsDrawUtils.h> |
20 #include <AknsDrawUtils.h> |
21 #include <coemain.h> |
21 #include <coemain.h> |
22 #include <commdbconnpref.h> |
22 #include <commdbconnpref.h> |
23 #include <bautils.h> |
23 #include <bautils.h> |
24 #include <biditext.h> |
24 #include <biditext.h> |
25 #include <stringloader.h> |
25 #include <StringLoader.h> |
26 #include <e32base.h> |
26 #include <e32base.h> |
27 #include <badesca.h> |
27 #include <badesca.h> |
|
28 #include <utf.h> |
28 |
29 |
29 //<cmail> |
30 //<cmail> |
30 #include "CFSMailMessage.h" |
31 #include "cfsmailmessage.h" |
31 //</cmail> |
32 //</cmail> |
32 #include <brctlinterface.h> |
33 #include <brctlinterface.h> |
33 #include <sysutil.h> |
34 #include <sysutil.h> |
34 #include <SchemeHandler.h> |
35 #include <schemehandler.h> |
35 |
36 |
36 #include <FreestyleEmailUi.rsg> |
37 #include <FreestyleEmailUi.rsg> |
37 |
38 |
38 #include "FreestyleEmailUiAppui.h" |
39 #include "FreestyleEmailUiAppui.h" |
39 #include "FreestyleEmailUiUtilities.h" |
40 #include "FreestyleEmailUiUtilities.h" |
352 TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language ); |
353 TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language ); |
353 if(aResetScrollPos) |
354 if(aResetScrollPos) |
354 { |
355 { |
355 iScrollPosition = 0; |
356 iScrollPosition = 0; |
356 } |
357 } |
|
358 if ( AknLayoutUtils::LayoutMirrored() ) |
|
359 { |
|
360 direction = TBidiText::ERightToLeft; |
|
361 } |
|
362 else |
|
363 { |
|
364 direction = TBidiText::ELeftToRight; |
|
365 } |
357 CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, iAppUi.ClientRect().Width(), |
366 CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, iAppUi.ClientRect().Width(), |
358 iScrollPosition, |
367 iScrollPosition, |
359 direction); |
368 direction); |
360 |
369 |
361 // Remove all previously created files from temporary HTML folder |
370 // Remove all previously created files from temporary HTML folder |
362 EmptyTempHtmlFolderL(); |
371 EmptyTempHtmlFolderL(); |
363 |
372 |
364 CFSMailMessagePart* htmlBodyPart = iMessage->HtmlBodyPartL(); |
373 TRAPD( error, PrepareBodyHtmlL( KBodyHtmlFile ) ); |
365 |
374 if ( error != KErrNone ) |
366 if ( htmlBodyPart ) |
375 { |
367 { |
376 WriteEmptyBodyHtmlL( KBodyHtmlFile ); |
368 CleanupStack::PushL( htmlBodyPart ); |
|
369 |
|
370 RFile htmlFile = htmlBodyPart->GetContentFileL(); |
|
371 CleanupClosePushL( htmlFile ); |
|
372 |
|
373 // Copy html body part to email html file |
|
374 CopyFileToHtmlFileL( htmlFile, KBodyHtmlFile, *htmlBodyPart ); |
|
375 |
|
376 CleanupStack::PopAndDestroy( &htmlFile ); |
|
377 CleanupStack::PopAndDestroy( htmlBodyPart ); |
|
378 } |
|
379 else |
|
380 { |
|
381 CFSMailMessagePart* textBodyPart = iMessage->PlainTextBodyPartL(); |
|
382 |
|
383 if ( textBodyPart ) |
|
384 { |
|
385 CleanupStack::PushL( textBodyPart ); |
|
386 //For now do not do any conversion just add start and end..Let browser display plain text as is |
|
387 //Later need to refine this and add conversions |
|
388 //htmlFile = textBodyPart->GetContentFileL(); |
|
389 //Need to get buffer in this case, file does not work |
|
390 //HBufC* contentBuffer=HBufC::NewLC(textBodyPart->ContentSize()); |
|
391 |
|
392 HBufC* contentBuffer=HBufC::NewLC(textBodyPart->FetchedContentSize()); |
|
393 TPtr bufPtr(contentBuffer->Des()); |
|
394 |
|
395 textBodyPart->GetContentToBufferL(bufPtr,0); |
|
396 HBufC8* contentBuffer8=HBufC8::NewLC(contentBuffer->Length()); |
|
397 |
|
398 contentBuffer8->Des().Copy(*contentBuffer); |
|
399 CopyFileToHtmlFileL( *contentBuffer8, KBodyHtmlFile, *textBodyPart ); |
|
400 |
|
401 CleanupStack::PopAndDestroy( contentBuffer8 ); |
|
402 CleanupStack::PopAndDestroy( contentBuffer ); |
|
403 CleanupStack::PopAndDestroy( textBodyPart ); |
|
404 } |
|
405 else |
|
406 { |
|
407 WriteEmptyBodyHtmlL( KBodyHtmlFile ); |
|
408 } |
|
409 } |
377 } |
410 |
378 |
411 // pass the emailHtmlFile to the browser for it to load |
379 // pass the emailHtmlFile to the browser for it to load |
412 TPath emailHtmlFile; |
380 TPath emailHtmlFile; |
413 emailHtmlFile.Copy( iHtmlFolderPath ); |
381 emailHtmlFile.Copy( iHtmlFolderPath ); |
414 if ( direction == TBidiText::ELeftToRight ) |
382 if ( !AknLayoutUtils::LayoutMirrored() ) |
415 { |
383 { |
416 emailHtmlFile.Append( KMessageHtmlFile ); |
384 emailHtmlFile.Append( KMessageHtmlFile ); |
417 } |
385 } |
418 else |
386 else |
419 { |
387 { |
513 TRect rect = Rect(); |
491 TRect rect = Rect(); |
514 if ( iBrCtlInterface ) |
492 if ( iBrCtlInterface ) |
515 { |
493 { |
516 iBrCtlInterface->SetRect( rect ); |
494 iBrCtlInterface->SetRect( rect ); |
517 } |
495 } |
518 |
496 |
519 if ( iMessage ) |
497 if ( iMessage ) |
520 { |
498 { |
521 // update the width in header part and reload |
499 // update the width in header part and reload |
522 TPath headerHtmlFile; |
500 TPath headerHtmlFile; |
523 headerHtmlFile.Copy( iHtmlFolderPath ); |
501 headerHtmlFile.Copy( iHtmlFolderPath ); |
524 headerHtmlFile.Append( KHeaderHtmlFile ); |
502 headerHtmlFile.Append( KHeaderHtmlFile ); |
525 |
503 |
526 TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, |
504 TLanguage language = User::Language(); |
527 rect.Width(), iScrollPosition ) ) |
505 TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language ); |
528 |
506 |
529 TPath emailHtmlFile; |
507 if ( AknLayoutUtils::LayoutMirrored() ) |
530 emailHtmlFile.Copy( iHtmlFolderPath ); |
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 { |
531 emailHtmlFile.Append( KMessageHtmlFile ); |
526 emailHtmlFile.Append( KMessageHtmlFile ); |
532 TRAP_IGNORE( LoadContentFromFileL( emailHtmlFile ) ) |
527 } |
533 } |
528 } |
534 |
529 |
535 UpdateOverlayButtons( IsVisible() ); |
530 UpdateOverlayButtons( IsVisible() ); |
536 |
531 |
537 if ( iStatusIndicator ) |
532 if ( iStatusIndicator ) |
538 { |
533 { |
831 // --------------------------------------------------------------------------- |
826 // --------------------------------------------------------------------------- |
832 // Copies given read-only file to HTML file |
827 // Copies given read-only file to HTML file |
833 // --------------------------------------------------------------------------- |
828 // --------------------------------------------------------------------------- |
834 // |
829 // |
835 // <cmail> |
830 // <cmail> |
836 void CFsEmailUiHtmlViewerContainer::CopyFileToHtmlFileL( RFile& aFile, |
831 void CFsEmailUiHtmlViewerContainer::CopyToHtmlFileL( CFSMailMessagePart& aHtmlBodyPart, const TDesC& aFileName ) |
837 const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart ) |
|
838 { |
832 { |
839 FUNC_LOG; |
833 FUNC_LOG; |
840 TFileName targetFileName; |
834 TFileName targetFileName; |
841 targetFileName.Copy( iTempHtmlFolderPath ); |
835 targetFileName.Copy( iTempHtmlFolderPath ); |
842 targetFileName.Append( aFileName ); |
836 targetFileName.Append( aFileName ); |
843 |
837 |
|
838 RFile htmlFile = aHtmlBodyPart.GetContentFileL(); |
|
839 CleanupClosePushL( htmlFile ); |
|
840 |
844 // Read content from given source file |
841 // Read content from given source file |
845 HBufC8* content = ReadContentFromFileLC( aFile ); |
842 HBufC8* content = ReadContentFromFileLC( htmlFile ); |
846 |
843 |
847 // Write content to target file |
844 // Write content to target file |
848 WriteContentToFileL( *content, targetFileName, aHtmlBodyPart ); |
845 WriteContentToFileL( *content, targetFileName, aHtmlBodyPart ); |
849 |
846 |
850 CleanupStack::PopAndDestroy( content ); |
847 CleanupStack::PopAndDestroy( content ); |
|
848 CleanupStack::PopAndDestroy( &htmlFile ); |
851 } |
849 } |
852 // </cmail> |
850 // </cmail> |
853 |
851 |
854 // --------------------------------------------------------------------------- |
852 // --------------------------------------------------------------------------- |
855 // Copies given buffer to HTML file |
853 // Copies given buffer to HTML file |
856 // --------------------------------------------------------------------------- |
854 // --------------------------------------------------------------------------- |
857 // |
855 // |
858 // <cmail> |
856 // <cmail> |
859 void CFsEmailUiHtmlViewerContainer::CopyFileToHtmlFileL( const TDesC8& aBuffer, |
857 void CFsEmailUiHtmlViewerContainer::ConvertToHtmlFileL( CFSMailMessagePart& aTextBodyPart, const TDesC& aHtmlFileName ) |
860 const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart ) |
|
861 { |
858 { |
862 FUNC_LOG; |
859 FUNC_LOG; |
863 TFileName targetFileName; |
860 TFileName targetFileName; |
864 targetFileName.Copy( iTempHtmlFolderPath ); |
861 targetFileName.Copy( iTempHtmlFolderPath ); |
865 targetFileName.Append( aFileName ); |
862 targetFileName.Append( aHtmlFileName ); |
866 |
863 |
867 // Write content to target file |
864 HBufC* content = HBufC::NewLC( aTextBodyPart.FetchedContentSize() ); |
868 ConvertToHTML( aBuffer, targetFileName, aHtmlBodyPart ); |
865 TPtr contentPtr( content->Des() ); |
|
866 |
|
867 aTextBodyPart.GetContentToBufferL( contentPtr, 0 ); |
|
868 |
|
869 HBufC8* content8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *content ); |
|
870 |
|
871 CleanupStack::PopAndDestroy( content ); |
|
872 CleanupStack::PushL( content8 ); |
|
873 |
|
874 ConvertToHTML( *content8, targetFileName, aTextBodyPart ); |
|
875 |
|
876 CleanupStack::PopAndDestroy( content8 ); |
|
877 |
869 } |
878 } |
870 |
879 |
871 // --------------------------------------------------------------------------- |
880 // --------------------------------------------------------------------------- |
872 // Reads given file content to buffer and return pointer to it |
881 // Reads given file content to buffer and return pointer to it |
873 // --------------------------------------------------------------------------- |
882 // --------------------------------------------------------------------------- |
1285 |
1294 |
1286 RFile targetFile; |
1295 RFile targetFile; |
1287 CleanupClosePushL( targetFile ); |
1296 CleanupClosePushL( targetFile ); |
1288 User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) ); |
1297 User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) ); |
1289 |
1298 |
1290 HBufC8* charSet = GetCharacterSetL( aTextBodyPart ); |
|
1291 CleanupStack::PushL( charSet ); |
|
1292 |
|
1293 RBuf8 messageHeader; |
1299 RBuf8 messageHeader; |
1294 TInt bufSize = KHtmlHeader1().Length() + charSet->Length() + KHtmlHeader2().Length(); |
1300 _LIT8( KCharsetUtf8, "UTF-8" ); |
|
1301 TInt bufSize = KHtmlHeader1().Length() + KCharsetUtf8().Length() + KHtmlHeader2().Length(); |
1295 messageHeader.CreateL( bufSize ); |
1302 messageHeader.CreateL( bufSize ); |
1296 messageHeader.CleanupClosePushL(); |
1303 messageHeader.CleanupClosePushL(); |
1297 |
1304 |
1298 messageHeader.Append( KHtmlHeader1 ); |
1305 messageHeader.Append( KHtmlHeader1 ); |
1299 messageHeader.Append( *charSet ); |
1306 messageHeader.Append( KCharsetUtf8 ); |
1300 messageHeader.Append( KHtmlHeader2 ); |
1307 messageHeader.Append( KHtmlHeader2 ); |
1301 |
1308 |
1302 RFileWriteStream fileStream( targetFile ); |
1309 RFileWriteStream fileStream( targetFile ); |
1303 fileStream.PushL(); |
1310 fileStream.PushL(); |
1304 fileStream.WriteL( messageHeader.Ptr(), messageHeader.Length() ); |
1311 fileStream.WriteL( messageHeader.Ptr(), messageHeader.Length() ); |
1305 |
1312 |
1306 TInt bufPos( 0 ); |
1313 TInt bufPos( 0 ); |
1307 TInt bufTotalSize = bodyBuf->Size(); |
1314 TInt bufTotalSize = bodyBuf->Size(); |
1308 |
1315 |
1309 while ( bufPos < bufTotalSize ) |
1316 while ( bufPos < bufTotalSize ) |
1310 { |
1317 { |
1311 TInt segmentLength = bodyBuf->Ptr( bufPos ).Length(); |
1318 TInt segmentLength = bodyBuf->Ptr( bufPos ).Length(); |
1312 fileStream.WriteL( bodyBuf->Ptr( bufPos ).Ptr(), segmentLength ); |
1319 fileStream.WriteL( bodyBuf->Ptr( bufPos ).Ptr(), segmentLength ); |
1313 bufPos += segmentLength; |
1320 bufPos += segmentLength; |
1314 } |
1321 } |
1315 |
1322 |
1316 fileStream.CommitL(); |
1323 fileStream.CommitL(); |
1317 |
1324 |
1318 CleanupStack::PopAndDestroy( &fileStream ); |
1325 CleanupStack::PopAndDestroy( &fileStream ); |
1319 CleanupStack::PopAndDestroy( &messageHeader ); |
1326 CleanupStack::PopAndDestroy( &messageHeader ); |
1320 CleanupStack::PopAndDestroy( charSet ); |
|
1321 CleanupStack::PopAndDestroy( &targetFile ); |
1327 CleanupStack::PopAndDestroy( &targetFile ); |
1322 CleanupStack::PopAndDestroy( bodyBuf ); |
1328 CleanupStack::PopAndDestroy( bodyBuf ); |
1323 |
1329 |
1324 // </cmail> |
1330 // </cmail> |
1325 } |
1331 } |
1643 TRAP_IGNORE( iBrCtlInterface->LoadDataL(KHTMLDataScheme, KHTMLEmptyContent, _L8("text/html"), uid) ); |
1649 TRAP_IGNORE( iBrCtlInterface->LoadDataL(KHTMLDataScheme, KHTMLEmptyContent, _L8("text/html"), uid) ); |
1644 } |
1650 } |
1645 } |
1651 } |
1646 |
1652 |
1647 void CFsEmailUiHtmlViewerContainer::HandleResourceChange( TInt aType ) |
1653 void CFsEmailUiHtmlViewerContainer::HandleResourceChange( TInt aType ) |
1648 { |
1654 { |
1649 CCoeControl::HandleResourceChange( aType ); |
1655 CCoeControl::HandleResourceChange( aType ); |
1650 |
1656 } |
1651 if ( aType == CFsEmailUiViewBase::EScreenLayoutChanged ) |
|
1652 { |
|
1653 // only update header if we get a layout change from email ui |
|
1654 RefreshCurrentMailHeader(); |
|
1655 } |
|
1656 } |
|
1657 |
1657 |
1658 void CFsEmailUiHtmlViewerContainer::RefreshCurrentMailHeader() |
1658 void CFsEmailUiHtmlViewerContainer::RefreshCurrentMailHeader() |
1659 { |
1659 { |
1660 if ( iMessage ) |
1660 if ( iMessage ) |
1661 { |
1661 { |
1662 // Update the width in header part and reload |
1662 // Update the width in header part and reload |
1663 TPath headerHtmlFile; |
1663 TPath headerHtmlFile; |
1664 headerHtmlFile.Copy( iHtmlFolderPath ); |
1664 headerHtmlFile.Copy( iHtmlFolderPath ); |
1665 headerHtmlFile.Append( KHeaderHtmlFile ); |
1665 headerHtmlFile.Append( KHeaderHtmlFile ); |
1666 |
1666 |
1667 TLanguage language = User::Language(); |
1667 TLanguage language = User::Language(); |
1668 TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language ); |
1668 TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language ); |
1669 TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, iAppUi.ClientRect().Width(), direction ) ) |
1669 TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, iAppUi.ClientRect().Width(), direction ) ) |
1670 |
1670 |
1671 TPath emailHtmlFile; |
1671 TPath emailHtmlFile; |
1672 emailHtmlFile.Copy( iHtmlFolderPath ); |
1672 emailHtmlFile.Copy( iHtmlFolderPath ); |
|
1673 emailHtmlFile.Append( KMessageHtmlFile ); |
|
1674 |
1673 if ( direction == TBidiText::ELeftToRight ) |
1675 if ( direction == TBidiText::ELeftToRight ) |
1674 { |
1676 { |
1675 emailHtmlFile.Append( KMessageHtmlFile ); |
1677 emailHtmlFile.Append( KMessageHtmlFile ); |
1676 } |
1678 } |
1677 else |
1679 else |
1678 { |
1680 { |
1679 emailHtmlFile.Append( KMessageHtmlRTLFile ); |
1681 emailHtmlFile.Append( KMessageHtmlRTLFile ); |
1680 } |
1682 } |
1681 |
1683 |
1682 //Load page synchronously if menu invisible |
1684 //Load page synchronously if menu invisible |
1683 if(!iEventHandler->IsMenuVisible()) |
1685 if(!iEventHandler->IsMenuVisible()) |
1684 { |
1686 { |
1685 TRAP_IGNORE( LoadContentFromFileL( emailHtmlFile ) ); |
1687 TRAP_IGNORE( LoadContentFromFileL( emailHtmlFile ) ); |
1686 SetRect( iAppUi.ClientRect() ); |
1688 SetRect( iAppUi.ClientRect() ); |
1687 } |
1689 } |
1688 //Load page asynchronously after dismissing menu |
1690 //Load page asynchronously after dismissing menu |
1689 else |
1691 else |
1690 { |
1692 { |
1691 iEventHandler->DismissMenuAndReload(); |
1693 iEventHandler->DismissMenuAndReload(); |
1692 } |
1694 } |
1693 } |
1695 } |
1694 } |
1696 } |
1695 |
1697 |
1696 void CFsEmailUiHtmlViewerContainer::ReloadPageL() |
1698 void CFsEmailUiHtmlViewerContainer::ReloadPageL() |
1697 { |
1699 { |
1698 TLanguage language = User::Language(); |
1700 TLanguage language = User::Language(); |
1699 TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language ); |
1701 TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language ); |
1700 TPath emailHtmlFile; |
1702 TPath emailHtmlFile; |
1701 emailHtmlFile.Copy( iHtmlFolderPath ); |
1703 emailHtmlFile.Copy( iHtmlFolderPath ); |
1702 if ( direction == TBidiText::ELeftToRight ) |
1704 if( !AknLayoutUtils::LayoutMirrored() ) |
1703 { |
1705 { |
1704 emailHtmlFile.Append( KMessageHtmlFile ); |
1706 emailHtmlFile.Append( KMessageHtmlFile ); |
1705 } |
1707 } |
1706 else |
1708 else |
1707 { |
1709 { |
1708 emailHtmlFile.Append( KMessageHtmlRTLFile ); |
1710 emailHtmlFile.Append( KMessageHtmlRTLFile ); |
1971 CleanupStack::PushL( handler ); |
1973 CleanupStack::PushL( handler ); |
1972 handler->HandleUrlStandaloneL(); |
1974 handler->HandleUrlStandaloneL(); |
1973 CleanupStack::PopAndDestroy( handler ); |
1975 CleanupStack::PopAndDestroy( handler ); |
1974 } |
1976 } |
1975 |
1977 |
|
1978 void CFsEmailUiHtmlViewerContainer::PrepareBodyHtmlL( const TDesC& aFileName ) |
|
1979 { |
|
1980 CFSMailMessagePart* htmlBodyPart = iMessage->HtmlBodyPartL(); |
|
1981 |
|
1982 if ( htmlBodyPart ) |
|
1983 { |
|
1984 CleanupStack::PushL( htmlBodyPart ); |
|
1985 // Copy html body part to email html file |
|
1986 CopyToHtmlFileL( *htmlBodyPart, aFileName ); |
|
1987 CleanupStack::PopAndDestroy( htmlBodyPart ); |
|
1988 } |
|
1989 else |
|
1990 { |
|
1991 CFSMailMessagePart* textBodyPart = iMessage->PlainTextBodyPartL(); |
|
1992 |
|
1993 if ( textBodyPart ) |
|
1994 { |
|
1995 CleanupStack::PushL( textBodyPart ); |
|
1996 // Copy html body part to email html file |
|
1997 ConvertToHtmlFileL( *textBodyPart, aFileName ); |
|
1998 CleanupStack::PopAndDestroy( textBodyPart ); |
|
1999 } |
|
2000 else |
|
2001 { |
|
2002 User::Leave( KErrNotFound ); |
|
2003 } |
|
2004 } |
|
2005 } |
|
2006 |
1976 void CFsEmailUiHtmlViewerContainer::WriteEmptyBodyHtmlL( const TDesC& aFileName ) |
2007 void CFsEmailUiHtmlViewerContainer::WriteEmptyBodyHtmlL( const TDesC& aFileName ) |
1977 { |
2008 { |
1978 FUNC_LOG; |
2009 FUNC_LOG; |
1979 TFileName targetFileName; |
2010 TFileName targetFileName; |
1980 targetFileName.Copy( iTempHtmlFolderPath ); |
2011 targetFileName.Copy( iTempHtmlFolderPath ); |