diff -r e7aa27f58ae1 -r e1b6206813b4 emailuis/emailui/src/FreestyleEmailUiHtmlViewerContainer.cpp --- a/emailuis/emailui/src/FreestyleEmailUiHtmlViewerContainer.cpp Tue Feb 02 00:02:40 2010 +0200 +++ b/emailuis/emailui/src/FreestyleEmailUiHtmlViewerContainer.cpp Fri Feb 19 22:37:30 2010 +0200 @@ -22,16 +22,17 @@ #include #include #include -#include +#include #include #include +#include // -#include "CFSMailMessage.h" +#include "cfsmailmessage.h" // #include #include -#include +#include #include @@ -354,6 +355,14 @@ { iScrollPosition = 0; } + if ( AknLayoutUtils::LayoutMirrored() ) + { + direction = TBidiText::ERightToLeft; + } + else + { + direction = TBidiText::ELeftToRight; + } CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, iAppUi.ClientRect().Width(), iScrollPosition, direction); @@ -361,57 +370,16 @@ // Remove all previously created files from temporary HTML folder EmptyTempHtmlFolderL(); - CFSMailMessagePart* htmlBodyPart = iMessage->HtmlBodyPartL(); - - if ( htmlBodyPart ) - { - CleanupStack::PushL( htmlBodyPart ); - - RFile htmlFile = htmlBodyPart->GetContentFileL(); - CleanupClosePushL( htmlFile ); - - // Copy html body part to email html file - CopyFileToHtmlFileL( htmlFile, KBodyHtmlFile, *htmlBodyPart ); - - CleanupStack::PopAndDestroy( &htmlFile ); - CleanupStack::PopAndDestroy( htmlBodyPart ); - } - else + TRAPD( error, PrepareBodyHtmlL( KBodyHtmlFile ) ); + if ( error != KErrNone ) { - CFSMailMessagePart* textBodyPart = iMessage->PlainTextBodyPartL(); - - if ( textBodyPart ) - { - CleanupStack::PushL( textBodyPart ); - //For now do not do any conversion just add start and end..Let browser display plain text as is - //Later need to refine this and add conversions - //htmlFile = textBodyPart->GetContentFileL(); - //Need to get buffer in this case, file does not work - //HBufC* contentBuffer=HBufC::NewLC(textBodyPart->ContentSize()); - - HBufC* contentBuffer=HBufC::NewLC(textBodyPart->FetchedContentSize()); - TPtr bufPtr(contentBuffer->Des()); - - textBodyPart->GetContentToBufferL(bufPtr,0); - HBufC8* contentBuffer8=HBufC8::NewLC(contentBuffer->Length()); - - contentBuffer8->Des().Copy(*contentBuffer); - CopyFileToHtmlFileL( *contentBuffer8, KBodyHtmlFile, *textBodyPart ); - - CleanupStack::PopAndDestroy( contentBuffer8 ); - CleanupStack::PopAndDestroy( contentBuffer ); - CleanupStack::PopAndDestroy( textBodyPart ); - } - else - { - WriteEmptyBodyHtmlL( KBodyHtmlFile ); - } + WriteEmptyBodyHtmlL( KBodyHtmlFile ); } // pass the emailHtmlFile to the browser for it to load TPath emailHtmlFile; emailHtmlFile.Copy( iHtmlFolderPath ); - if ( direction == TBidiText::ELeftToRight ) + if ( !AknLayoutUtils::LayoutMirrored() ) { emailHtmlFile.Append( KMessageHtmlFile ); } @@ -456,10 +424,20 @@ return iBrCtlInterface; } case 1: + { + return iOverlayControlNext; + } + case 2: + { + return iOverlayControlPrev; + } + case 3: + { if ( iStatusIndicator ) return iStatusIndicator; else return NULL; + } default: { return NULL; @@ -476,11 +454,11 @@ FUNC_LOG; if ( iStatusIndicator ) { - return 2; + return 4; } else { - return 1; + return 3; } } @@ -515,22 +493,39 @@ { iBrCtlInterface->SetRect( rect ); } - - if ( iMessage ) + + if ( iMessage ) + { + // update the width in header part and reload + TPath headerHtmlFile; + headerHtmlFile.Copy( iHtmlFolderPath ); + headerHtmlFile.Append( KHeaderHtmlFile ); + + TLanguage language = User::Language(); + TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language ); + + if ( AknLayoutUtils::LayoutMirrored() ) + { + direction = TBidiText::ERightToLeft; + } + else { - // update the width in header part and reload - TPath headerHtmlFile; - headerHtmlFile.Copy( iHtmlFolderPath ); - headerHtmlFile.Append( KHeaderHtmlFile ); - - TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, - rect.Width(), iScrollPosition ) ) - - TPath emailHtmlFile; - emailHtmlFile.Copy( iHtmlFolderPath ); + direction = TBidiText::ELeftToRight; + } + TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, + rect.Width(), iScrollPosition, direction ) ) + + TPath emailHtmlFile; + emailHtmlFile.Copy( iHtmlFolderPath ); + if ( AknLayoutUtils::LayoutMirrored() ) + { + emailHtmlFile.Append( KMessageHtmlRTLFile ); + } + else + { emailHtmlFile.Append( KMessageHtmlFile ); - TRAP_IGNORE( LoadContentFromFileL( emailHtmlFile ) ) } + } UpdateOverlayButtons( IsVisible() ); @@ -567,7 +562,7 @@ } } - if ( iBrCtlInterface && retVal == EKeyWasNotConsumed ) + else if ( iBrCtlInterface && retVal == EKeyWasNotConsumed ) { retVal = iBrCtlInterface->OfferKeyEventL( aKeyEvent, aType ); } @@ -833,21 +828,24 @@ // --------------------------------------------------------------------------- // // -void CFsEmailUiHtmlViewerContainer::CopyFileToHtmlFileL( RFile& aFile, - const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart ) +void CFsEmailUiHtmlViewerContainer::CopyToHtmlFileL( CFSMailMessagePart& aHtmlBodyPart, const TDesC& aFileName ) { FUNC_LOG; TFileName targetFileName; targetFileName.Copy( iTempHtmlFolderPath ); targetFileName.Append( aFileName ); + RFile htmlFile = aHtmlBodyPart.GetContentFileL(); + CleanupClosePushL( htmlFile ); + // Read content from given source file - HBufC8* content = ReadContentFromFileLC( aFile ); + HBufC8* content = ReadContentFromFileLC( htmlFile ); // Write content to target file WriteContentToFileL( *content, targetFileName, aHtmlBodyPart ); CleanupStack::PopAndDestroy( content ); + CleanupStack::PopAndDestroy( &htmlFile ); } // @@ -856,16 +854,27 @@ // --------------------------------------------------------------------------- // // -void CFsEmailUiHtmlViewerContainer::CopyFileToHtmlFileL( const TDesC8& aBuffer, - const TDesC& aFileName, CFSMailMessagePart& aHtmlBodyPart ) +void CFsEmailUiHtmlViewerContainer::ConvertToHtmlFileL( CFSMailMessagePart& aTextBodyPart, const TDesC& aHtmlFileName ) { FUNC_LOG; TFileName targetFileName; targetFileName.Copy( iTempHtmlFolderPath ); - targetFileName.Append( aFileName ); + targetFileName.Append( aHtmlFileName ); + + HBufC* content = HBufC::NewLC( aTextBodyPart.FetchedContentSize() ); + TPtr contentPtr( content->Des() ); + + aTextBodyPart.GetContentToBufferL( contentPtr, 0 ); - // Write content to target file - ConvertToHTML( aBuffer, targetFileName, aHtmlBodyPart ); + HBufC8* content8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *content ); + + CleanupStack::PopAndDestroy( content ); + CleanupStack::PushL( content8 ); + + ConvertToHTML( *content8, targetFileName, aTextBodyPart ); + + CleanupStack::PopAndDestroy( content8 ); + } // --------------------------------------------------------------------------- @@ -1287,25 +1296,23 @@ CleanupClosePushL( targetFile ); User::LeaveIfError( targetFile.Replace( iFs, aFileName, EFileWrite ) ); - HBufC8* charSet = GetCharacterSetL( aTextBodyPart ); - CleanupStack::PushL( charSet ); - RBuf8 messageHeader; - TInt bufSize = KHtmlHeader1().Length() + charSet->Length() + KHtmlHeader2().Length(); + _LIT8( KCharsetUtf8, "UTF-8" ); + TInt bufSize = KHtmlHeader1().Length() + KCharsetUtf8().Length() + KHtmlHeader2().Length(); messageHeader.CreateL( bufSize ); messageHeader.CleanupClosePushL(); messageHeader.Append( KHtmlHeader1 ); - messageHeader.Append( *charSet ); + messageHeader.Append( KCharsetUtf8 ); messageHeader.Append( KHtmlHeader2 ); - + RFileWriteStream fileStream( targetFile ); fileStream.PushL(); fileStream.WriteL( messageHeader.Ptr(), messageHeader.Length() ); - + TInt bufPos( 0 ); TInt bufTotalSize = bodyBuf->Size(); - + while ( bufPos < bufTotalSize ) { TInt segmentLength = bodyBuf->Ptr( bufPos ).Length(); @@ -1314,10 +1321,9 @@ } fileStream.CommitL(); - + CleanupStack::PopAndDestroy( &fileStream ); CleanupStack::PopAndDestroy( &messageHeader ); - CleanupStack::PopAndDestroy( charSet ); CleanupStack::PopAndDestroy( &targetFile ); CleanupStack::PopAndDestroy( bodyBuf ); @@ -1645,31 +1651,27 @@ } void CFsEmailUiHtmlViewerContainer::HandleResourceChange( TInt aType ) - { - CCoeControl::HandleResourceChange( aType ); - - if ( aType == CFsEmailUiViewBase::EScreenLayoutChanged ) - { - // only update header if we get a layout change from email ui - RefreshCurrentMailHeader(); - } - } + { + CCoeControl::HandleResourceChange( aType ); + } void CFsEmailUiHtmlViewerContainer::RefreshCurrentMailHeader() - { - if ( iMessage ) - { - // Update the width in header part and reload - TPath headerHtmlFile; - headerHtmlFile.Copy( iHtmlFolderPath ); - headerHtmlFile.Append( KHeaderHtmlFile ); - - TLanguage language = User::Language(); - TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language ); - TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, iAppUi.ClientRect().Width(), direction ) ) - + { + if ( iMessage ) + { + // Update the width in header part and reload + TPath headerHtmlFile; + headerHtmlFile.Copy( iHtmlFolderPath ); + headerHtmlFile.Append( KHeaderHtmlFile ); + + TLanguage language = User::Language(); + TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language ); + TRAP_IGNORE( CFreestyleMessageHeaderHTML::ExportL( *iMessage, iFs, headerHtmlFile, iAppUi.ClientRect().Width(), direction ) ) + TPath emailHtmlFile; emailHtmlFile.Copy( iHtmlFolderPath ); + emailHtmlFile.Append( KMessageHtmlFile ); + if ( direction == TBidiText::ELeftToRight ) { emailHtmlFile.Append( KMessageHtmlFile ); @@ -1678,7 +1680,7 @@ { emailHtmlFile.Append( KMessageHtmlRTLFile ); } - + //Load page synchronously if menu invisible if(!iEventHandler->IsMenuVisible()) { @@ -1689,9 +1691,9 @@ else { iEventHandler->DismissMenuAndReload(); - } - } - } + } + } + } void CFsEmailUiHtmlViewerContainer::ReloadPageL() { @@ -1699,8 +1701,8 @@ TBidiText::TDirectionality direction = TBidiText::ScriptDirectionality( language ); TPath emailHtmlFile; emailHtmlFile.Copy( iHtmlFolderPath ); - if ( direction == TBidiText::ELeftToRight ) - { + if( !AknLayoutUtils::LayoutMirrored() ) + { emailHtmlFile.Append( KMessageHtmlFile ); } else @@ -1973,6 +1975,35 @@ CleanupStack::PopAndDestroy( handler ); } +void CFsEmailUiHtmlViewerContainer::PrepareBodyHtmlL( const TDesC& aFileName ) + { + CFSMailMessagePart* htmlBodyPart = iMessage->HtmlBodyPartL(); + + if ( htmlBodyPart ) + { + CleanupStack::PushL( htmlBodyPart ); + // Copy html body part to email html file + CopyToHtmlFileL( *htmlBodyPart, aFileName ); + CleanupStack::PopAndDestroy( htmlBodyPart ); + } + else + { + CFSMailMessagePart* textBodyPart = iMessage->PlainTextBodyPartL(); + + if ( textBodyPart ) + { + CleanupStack::PushL( textBodyPart ); + // Copy html body part to email html file + ConvertToHtmlFileL( *textBodyPart, aFileName ); + CleanupStack::PopAndDestroy( textBodyPart ); + } + else + { + User::Leave( KErrNotFound ); + } + } + } + void CFsEmailUiHtmlViewerContainer::WriteEmptyBodyHtmlL( const TDesC& aFileName ) { FUNC_LOG;