emailuis/emailui/src/FreestyleMessageHeaderHTML.cpp
branchRCL_3
changeset 8 e1b6206813b4
parent 3 a4d6f1ea0416
child 12 f5907b1a1053
equal deleted inserted replaced
4:e7aa27f58ae1 8:e1b6206813b4
    21 #include <e32cmn.h>
    21 #include <e32cmn.h>
    22 #include <utf.h>
    22 #include <utf.h>
    23 #include <StringLoader.h>
    23 #include <StringLoader.h>
    24 
    24 
    25 #include <FreestyleEmailUi.rsg>
    25 #include <FreestyleEmailUi.rsg>
    26 
    26 #include <finditemengine.h>
    27 #include "FreestyleMessageHeaderHTML.h"
    27 #include "FreestyleMessageHeaderHTML.h"
    28 #include "FreestyleEmailUiUtilities.h"
    28 #include "FreestyleEmailUiUtilities.h"
    29 #include "ncsconstants.h"
    29 #include "ncsconstants.h"
    30 
    30 
    31 
    31 
   154                                                           TBidiText::TDirectionality aDirectionality )
   154                                                           TBidiText::TDirectionality aDirectionality )
   155     : iMailMessage( aMailMessage ),
   155     : iMailMessage( aMailMessage ),
   156     iWriteStream( aWriteStream ),
   156     iWriteStream( aWriteStream ),
   157     iVisibleWidth( aVisibleWidth - KFreestyleMessageHeaderHTMLRightMarginInPx ),
   157     iVisibleWidth( aVisibleWidth - KFreestyleMessageHeaderHTMLRightMarginInPx ),
   158     iScrollPosition(aScrollPosition),
   158     iScrollPosition(aScrollPosition),
   159     iDirectionality( aDirectionality )
   159     iDirectionality( aDirectionality ),
       
   160     iMirrorLayout( EFalse )
   160     {
   161     {
   161     }
   162     }
   162 
   163 
   163 void CFreestyleMessageHeaderHTML::ConstructL()
   164 void CFreestyleMessageHeaderHTML::ConstructL()
   164     {
   165     {
   165     iMailMessage.AttachmentListL( iAttachments );
   166     iMailMessage.AttachmentListL( iAttachments );
       
   167     if ( AknLayoutUtils::LayoutMirrored() )
       
   168         {
       
   169         iMirrorLayout = ETrue;
       
   170         }
   166     }
   171     }
   167 
   172 
   168 void CFreestyleMessageHeaderHTML::HTMLStartL() const
   173 void CFreestyleMessageHeaderHTML::HTMLStartL() const
   169     {
   174     {
   170     iWriteStream.WriteL(_L8("<html"));
   175     iWriteStream.WriteL(_L8("<html"));
   171     if ( iDirectionality == TBidiText::ERightToLeft )
   176     if ( iMirrorLayout )
   172         {
   177         {
   173         iWriteStream.WriteL(_L8(" dir=\"rtl\""));
   178         iWriteStream.WriteL(_L8(" dir=\"rtl\""));
   174         }    
   179         }
       
   180     else
       
   181         {
       
   182         iWriteStream.WriteL(_L8(" dir=\"ltr\""));
       
   183         }
   175     iWriteStream.WriteL(_L8(" xmlns=\"http://www.w3.org/1999/xhtml\">\n"));
   184     iWriteStream.WriteL(_L8(" xmlns=\"http://www.w3.org/1999/xhtml\">\n"));
   176     iWriteStream.CommitL();
   185     iWriteStream.CommitL();
   177     }
   186     }
   178 
   187 
   179 void CFreestyleMessageHeaderHTML::HTMLEndL() const
   188 void CFreestyleMessageHeaderHTML::HTMLEndL() const
   256     
   265     
   257     iWriteStream.WriteL(_L8("<tr>\n"));
   266     iWriteStream.WriteL(_L8("<tr>\n"));
   258     
   267     
   259     // add Sent time and date
   268     // add Sent time and date
   260     iWriteStream.WriteL(_L8("<td id=\"sent_initial\""));
   269     iWriteStream.WriteL(_L8("<td id=\"sent_initial\""));
   261     if ( iDirectionality == TBidiText::ELeftToRight )
   270 
       
   271     if ( !iMirrorLayout )
   262         {
   272         {
   263         iWriteStream.WriteL(_L8(" align=\"left\""));
   273         iWriteStream.WriteL(_L8(" align=\"left\""));
   264         }
   274         }
   265     else
   275     else
   266         {
   276         {
   287     
   297     
   288     iWriteStream.WriteL(_L8("</td>\n"));
   298     iWriteStream.WriteL(_L8("</td>\n"));
   289     
   299     
   290     // add "show details" image on the same line as Sent time and date
   300     // add "show details" image on the same line as Sent time and date
   291     iWriteStream.WriteL(_L8("<td width=\"1\" valign=\"top\""));
   301     iWriteStream.WriteL(_L8("<td width=\"1\" valign=\"top\""));
   292     if ( iDirectionality == TBidiText::ELeftToRight )
   302     if ( !iMirrorLayout )
   293         {
   303         {
   294         iWriteStream.WriteL(_L8(" align=\"right\""));
   304         iWriteStream.WriteL(_L8(" align=\"right\""));
   295         }
   305         }
   296     else
   306     else
   297         {
   307         {
   306 
   316 
   307     //=============================
   317     //=============================
   308     // start second row which contains subject
   318     // start second row which contains subject
   309     iWriteStream.WriteL(_L8("<tr>\n"));
   319     iWriteStream.WriteL(_L8("<tr>\n"));
   310     iWriteStream.WriteL(_L8("<td id=\"subject_initial\""));
   320     iWriteStream.WriteL(_L8("<td id=\"subject_initial\""));
   311     if ( iDirectionality == TBidiText::ELeftToRight )
   321     if ( !iMirrorLayout )
   312         {
   322         {
   313         iWriteStream.WriteL(_L8(" align=\"left\""));
   323         iWriteStream.WriteL(_L8(" align=\"left\""));
   314         }
   324         }
   315     else
   325     else
   316         {
   326         {
   317         iWriteStream.WriteL(_L8(" align=\"right\""));
   327         iWriteStream.WriteL(_L8(" align=\"right\""));
   318         }
   328         }
   319     iWriteStream.WriteL(_L8("><b>"));
   329     iWriteStream.WriteL(_L8("><b>"));
   320 
   330 
   321     HBufC8* subject8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( iMailMessage.GetSubject() );
   331 	HBufC* subject = iMailMessage.GetSubject().Alloc();
   322     CleanupStack::PushL( subject8 );
   332 	/*
   323     iWriteStream.WriteL( *subject8 );
   333      * Writes the subject to iWriteStream and also
   324     CleanupStack::PopAndDestroy( subject8 );
   334      * takes care of the urls and marks them as hotspots
       
   335      */
       
   336     WriteSubjectL(*subject);
       
   337 
   325     iWriteStream.WriteL(_L8("</b>"));
   338     iWriteStream.WriteL(_L8("</b>"));
   326         
   339         
   327     // Write icons (if necessary).
   340     // Write icons (if necessary).
   328     HBufC8* followUp = HTMLHeaderFollowUpIconLC( EFalse );
   341     HBufC8* followUp = HTMLHeaderFollowUpIconLC( EFalse );
   329     HBufC8* priority = HTMLHeaderPriorityIconLC( EFalse );
   342     HBufC8* priority = HTMLHeaderPriorityIconLC( EFalse );
   344     
   357     
   345     // end table_initial
   358     // end table_initial
   346     iWriteStream.WriteL(_L8("</table>\n"));
   359     iWriteStream.WriteL(_L8("</table>\n"));
   347         
   360         
   348     iWriteStream.CommitL();
   361     iWriteStream.CommitL();
       
   362     }
       
   363 // -----------------------------------------------------------------------------
       
   364 // CFreestyleMessageHeaderHTML::WriteSubjectL
       
   365 // Writes the subject to iWriteStream and also
       
   366 // takes care of the urls and marks them as hotspots
       
   367 // -----------------------------------------------------------------------------
       
   368 //
       
   369 void CFreestyleMessageHeaderHTML::WriteSubjectL(TDesC& aText ) const
       
   370     {
       
   371     /* 
       
   372     * Add these to searchcases to make it also search 
       
   373     * for emailaddress and phonenumber :
       
   374     * CFindItemEngine::EFindItemSearchMailAddressBin |
       
   375     * CFindItemEngine::EFindItemSearchPhoneNumberBin |
       
   376     */
       
   377     // Search for urls    
       
   378     TInt searchCases = CFindItemEngine::EFindItemSearchURLBin;
       
   379                        
       
   380     CFindItemEngine* itemEngine =
       
   381               CFindItemEngine::NewL ( aText,
       
   382                        ( CFindItemEngine::TFindItemSearchCase ) searchCases );
       
   383     CleanupStack::PushL (itemEngine );
       
   384 
       
   385     const CArrayFixFlat<CFindItemEngine::SFoundItem>
       
   386             * foundItems = itemEngine->ItemArray ( );
       
   387     
       
   388     TInt index = 0;
       
   389     // For each found item
       
   390     for (TInt i=0; i<foundItems->Count ( ); ++i )
       
   391         {
       
   392         // iItemType, iStartPos, iLength
       
   393         const CFindItemEngine::SFoundItem& item = foundItems->At (i );
       
   394         HBufC* valueBuf = aText.Mid (item.iStartPos, item.iLength ).AllocL ( );
       
   395         CleanupStack::PushL (valueBuf );
       
   396         // We write the normal text to iWriteStream before and between the links in the header subject field
       
   397         if(item.iStartPos > 0)
       
   398             {
       
   399             TInt itemstart = item.iStartPos;
       
   400             HBufC* normalText = aText.Mid(index, itemstart-index).Alloc();
       
   401             CleanupStack::PushL( normalText );
       
   402             HBufC8* normalText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *normalText );
       
   403             CleanupStack::PushL( normalText8 );
       
   404             iWriteStream.WriteL( *normalText8 );
       
   405             CleanupStack::PopAndDestroy( 2 ); //normalText8m, normalText
       
   406             }        
       
   407         switch (item.iItemType )
       
   408             {
       
   409             /* To make header subjectfield to recognise also phonenumber and emailadress just 
       
   410              * add CFindItemEngine::EFindItemSearchMailAddressBin & 
       
   411              * CFindItemEngine::EFindItemSearchPhoneNumberBin cases here.
       
   412              */
       
   413             case CFindItemEngine::EFindItemSearchURLBin:
       
   414                 {
       
   415                 HBufC8* url8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *valueBuf );
       
   416                 FreestyleMessageHeaderURLFactory::CreateEmailSubjectUrlL(*valueBuf);
       
   417                 CleanupStack::PushL( url8 );
       
   418                 StartHyperlinkL(*url8);
       
   419                 iWriteStream.WriteL(*url8);
       
   420                 EndHyperlinkL();
       
   421                 CleanupStack::PopAndDestroy( url8 );
       
   422 
       
   423                 break;
       
   424                 }
       
   425             default:
       
   426                 {
       
   427                 break;
       
   428                 }
       
   429             }        
       
   430         index = item.iStartPos+item.iLength;
       
   431         CleanupStack::PopAndDestroy (valueBuf );
       
   432         }
       
   433         //Write the rest of the subject to subject field if we are not 
       
   434         //at the end of the subject already, or if there wasn't any
       
   435         //url items write the whole subject field here
       
   436         if(index < aText.Length() )
       
   437             {
       
   438             HBufC* normalText = aText.Mid(index, aText.Length()-index).Alloc();
       
   439             CleanupStack::PushL( normalText );
       
   440             HBufC8* normalText8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( *normalText );
       
   441             CleanupStack::PushL( normalText8 );
       
   442             iWriteStream.WriteL( *normalText8 );
       
   443             CleanupStack::PopAndDestroy( 2 ); //normalText8m, normalText
       
   444             }
       
   445     CleanupStack::PopAndDestroy (itemEngine );
   349     }
   446     }
   350 
   447 
   351 HBufC8* CFreestyleMessageHeaderHTML::HTMLHeaderFollowUpIconLC( TBool aShowText ) const
   448 HBufC8* CFreestyleMessageHeaderHTML::HTMLHeaderFollowUpIconLC( TBool aShowText ) const
   352     {
   449     {
   353     HBufC8* followUpText8( NULL );
   450     HBufC8* followUpText8( NULL );
   565     iWriteStream.WriteL( _L8("</tr>\n") );
   662     iWriteStream.WriteL( _L8("</tr>\n") );
   566     
   663     
   567     // subject text
   664     // subject text
   568     iWriteStream.WriteL( _L8("<tr>") );
   665     iWriteStream.WriteL( _L8("<tr>") );
   569     iWriteStream.WriteL( _L8("<td>") );
   666     iWriteStream.WriteL( _L8("<td>") );
   570 
   667 	HBufC* subject = iMailMessage.GetSubject().Alloc();
   571     HBufC8* subject8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( iMailMessage.GetSubject() );
   668     /*
   572     CleanupStack::PushL( subject8 );
   669      * Writes the subject to iWriteStream and also
   573     iWriteStream.WriteL( *subject8 );
   670      * takes care of the urls and marks them as hotspots
   574     CleanupStack::PopAndDestroy( subject8 );
   671      */
       
   672     WriteSubjectL(*subject);
   575 
   673 
   576     iWriteStream.WriteL( _L8("</td>") );
   674     iWriteStream.WriteL( _L8("</td>") );
   577     iWriteStream.WriteL( _L8("</tr>\n") );
   675     iWriteStream.WriteL( _L8("</tr>\n") );
   578     // Write icons (if necessary).
   676     // Write icons (if necessary).
   579     HBufC8* followUp = HTMLHeaderFollowUpIconLC( ETrue );
   677     HBufC8* followUp = HTMLHeaderFollowUpIconLC( ETrue );
   694         // start row
   792         // start row
   695         iWriteStream.WriteL( _L8("<tr>\n") );
   793         iWriteStream.WriteL( _L8("<tr>\n") );
   696           
   794           
   697         // add attachment icon
   795         // add attachment icon
   698         iWriteStream.WriteL( _L8("<td width=\"1\" valign=\"top\"") );
   796         iWriteStream.WriteL( _L8("<td width=\"1\" valign=\"top\"") );
   699         if ( iDirectionality == TBidiText::ELeftToRight )
   797         if ( !iMirrorLayout )
       
   798             {
       
   799             iWriteStream.WriteL(_L8(" align=\"left\""));
       
   800             }
       
   801         else
   700             {
   802             {
   701             iWriteStream.WriteL(_L8(" align=\"right\""));
   803             iWriteStream.WriteL(_L8(" align=\"right\""));
   702             }
       
   703         else
       
   704             {
       
   705             iWriteStream.WriteL(_L8(" align=\"left\""));
       
   706             }
   804             }
   707         iWriteStream.WriteL( _L8("><image src=\"") );
   805         iWriteStream.WriteL( _L8("><image src=\"") );
   708         
   806         
   709         iWriteStream.WriteL( KAttachementIconGeneral );
   807         iWriteStream.WriteL( KAttachementIconGeneral );
   710         iWriteStream.WriteL( _L8("\" ></td>\n") );
   808         iWriteStream.WriteL( _L8("\" ></td>\n") );
   773     StartHyperlinkL( *url8 );
   871     StartHyperlinkL( *url8 );
   774     CleanupStack::PopAndDestroy( url8 );
   872     CleanupStack::PopAndDestroy( url8 );
   775     CleanupStack::PopAndDestroy( url );
   873     CleanupStack::PopAndDestroy( url );
   776 
   874 
   777     HBufC8* displayName8 = NULL;
   875     HBufC8* displayName8 = NULL;
   778     if ( aEmailAddress.GetDisplayName().Length() > 0 )
   876     //  ENLN-7ZVBES
       
   877     //  Display name not shown in From:, instead, email address is shown
       
   878     if ( (aEmailAddress.GetDisplayName().Length() > 0) && aEmailAddressType != FreestyleMessageHeaderURLFactory::EEmailAddressTypeFrom )
   779         {
   879         {
   780         displayName8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aEmailAddress.GetDisplayName() );
   880         displayName8 = CnvUtfConverter::ConvertFromUnicodeToUtf8L( aEmailAddress.GetDisplayName() );
   781         }
   881         }
   782     else
   882     else
   783         {
   883         {
   902     iWriteStream.WriteL( tableWidth );
  1002     iWriteStream.WriteL( tableWidth );
   903     iWriteStream.WriteL( _L8("px\">\n"));
  1003     iWriteStream.WriteL( _L8("px\">\n"));
   904     iWriteStream.WriteL( _L8("<tr>\n"));
  1004     iWriteStream.WriteL( _L8("<tr>\n"));
   905     
  1005     
   906     iWriteStream.WriteL( _L8("<td valign=\"top\""));
  1006     iWriteStream.WriteL( _L8("<td valign=\"top\""));
   907     if ( iDirectionality == TBidiText::ELeftToRight )
  1007     if ( !iMirrorLayout )
   908         {
  1008         {
   909         iWriteStream.WriteL(_L8(" align=\"right\""));
  1009         iWriteStream.WriteL(_L8(" align=\"right\""));
   910         }
  1010         }
   911     else
  1011     else
   912         {
  1012         {