emailuis/emailui/src/FreestyleEmailUiMailViewerVisualiser.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 11 0396474f30f5
child 13 8592a65ad3fb
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     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 : FreestyleEmailUi  list implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // SYSTEM INCLUDES
       
    21 #include "emailtrace.h"
       
    22 #include <AknUtils.h>
       
    23 #include <freestyleemailui.mbg>
       
    24 #include <FreestyleEmailUi.rsg>
       
    25 #include <StringLoader.h>
       
    26 #include <AknBidiTextUtils.h>
       
    27 
       
    28 #ifndef FF_CMAIL_INTEGRATION
       
    29 #include <txtclipboard.h>
       
    30 #endif // FF_CMAIL_INTEGRATION
       
    31 
       
    32 //<cmail>
       
    33 #include "fstextviewer.h"
       
    34 #include "fsrichtext.h"
       
    35 ///</cmail>
       
    36 #include <aknlistquerydialog.h>
       
    37 //<cmail>
       
    38 #include "fssmileydictionary.h"
       
    39 ///</cmail>
       
    40 #include <commonphoneparser.h>
       
    41 #include <browserlauncher.h>
       
    42 //<cmail>
       
    43 #include "cfsmailmessagepart.h"
       
    44 #include "cfsmailclient.h"
       
    45 //</cmail>
       
    46 #include <apgcli.h>
       
    47 //<cmail>
       
    48 #include "cfsmailcommon.h"
       
    49 //</cmail>
       
    50 #include <featmgr.h>
       
    51 //</cmail>
       
    52 
       
    53 #include <txtfrmat.h>
       
    54 #include <aknlists.h> // CAknSinglePopupMenuStyleListBox
       
    55 #include <baclipb.h> // for clipboard copy
       
    56 //<cmail>
       
    57 #include "fstextviewerkeys.h"
       
    58 #include "fstextviewerwatermark.h"
       
    59 #include <alf/alfstatic.h>
       
    60 #include <alf/alfroster.h>
       
    61 #include <alf/alfevent.h>
       
    62 #include <alf/alfcontrolgroup.h>
       
    63 // </cmail>
       
    64 //<cmail>
       
    65 #include "AknWaitDialog.h"
       
    66 //</cmail>
       
    67 #include <finditemengine.h>
       
    68 #include <AknGlobalListQuery.h>
       
    69 #include <AknGlobalNote.h>
       
    70 
       
    71 // Meeting request
       
    72 #include <MeetingRequestUids.hrh>
       
    73 //<cmail>
       
    74 #include "cesmricalviewer.h"
       
    75 //</cmail>
       
    76 
       
    77 // for intranet application opening
       
    78 #include <AiwServiceHandler.h>
       
    79 #include <AiwMenu.h>
       
    80 
       
    81 // for opening normal browser
       
    82 #include <browseroverriddensettings.h>
       
    83 #include <browserlauncher.h>
       
    84 
       
    85 // for bookmarks
       
    86 #include <favouriteslimits.h>   // KBrowserBookmarks
       
    87 #include <favouritesdb.h>
       
    88 
       
    89 // for fonts
       
    90 #include <AknFontAccess.h>
       
    91 #include <AknLayoutFont.h>
       
    92 
       
    93 // for action menu
       
    94 #include <CPbkContactEngine.h>
       
    95 #include <CPbkContactItem.h>
       
    96 #include <CPbkContactEditorDlg.h>
       
    97 #include <RPbkViewResourceFile.h>
       
    98 #include <CPbkDataSaveAppUi.h>
       
    99 #include <PbkDataSaveAppUi.hrh>
       
   100 #include <CPbkFieldsInfo.h>
       
   101 
       
   102 // <cmail>
       
   103 #include "cfsccontactactionmenu.h"
       
   104 #include "mfsccontactactionmenumodel.h"
       
   105 #include "cfsccontactactionservice.h"
       
   106 #include "cfsccontactactionmenuitem.h"
       
   107 #include "fsccontactactionmenuuids.hrh"
       
   108 #include "fsccontactactionmenudefines.h"
       
   109 // </cmail>
       
   110 
       
   111 // <cmail>
       
   112 #include "cfsccontactactionservice.h"
       
   113 #include <csxhelp/cmail.hlp.hrh>
       
   114 // </cmail>
       
   115 #include <aknnotewrappers.h>
       
   116 
       
   117 #include <schemehandler.h> // CSchemeHandler
       
   118 
       
   119 // <cmail>
       
   120 #include "FreestyleEmailUiConstants.h"
       
   121 //</cmail>
       
   122 // INTERNAL INCLUDES
       
   123 #include "FreestyleEmailUiAppui.h"
       
   124 #include "FreestyleEmailUiMailViewerControl.h"
       
   125 #include "FreestyleEmailUiMailListVisualiser.h"
       
   126 #include "FreestyleEmailUiFileSystemInfo.h"
       
   127 #include "FreestyleEmailUi.hrh"
       
   128 #include "freestyleemailcenrephandler.h"
       
   129 #include "FreestyleEmailUiLayoutHandler.h"
       
   130 #include "FreestyleEmailUiTextureManager.h"
       
   131 #include "FreestyleEmailUiMsgDetailsVisualiser.h"
       
   132 #include "FreestyleEmailUiFolderListVisualiser.h"
       
   133 #include "FreestyleEmailUiAttachmentsListVisualiser.h"
       
   134 #include "FreestyleEmailUiShortcutBinding.h"
       
   135 #include "FreestyleEmailUiContactHandler.h"
       
   136 #include "FreestyleEmailUiUtilities.h"
       
   137 #include "FreestyleEmailUiStatusIndicator.h"
       
   138 #include "FSEmail.pan"
       
   139 #include "FSDelayedLoader.h"
       
   140 
       
   141 #include "FreestyleEmailUiMailViewerVisualiser.h"
       
   142 #include "FreestyleEmailUiMailViewerRichText.h"
       
   143 #include "FreestyleEmailUiMailViewerConstants.h"
       
   144 
       
   145 #include <aknnavi.h>
       
   146 #include <aknnavide.h>
       
   147 #include <akntoolbar.h>
       
   148 // -----------------------------------------------------------------------------
       
   149 // CFSEmailUiMailViewerVisualiser::NewL
       
   150 // -----------------------------------------------------------------------------
       
   151 CFSEmailUiMailViewerVisualiser* CFSEmailUiMailViewerVisualiser::NewL( CAlfEnv& aEnv, CFreestyleEmailUiAppUi& aAppUi, CAlfControlGroup& aMailViewerControlGroup )
       
   152     {
       
   153     FUNC_LOG;
       
   154     CFSEmailUiMailViewerVisualiser* self = CFSEmailUiMailViewerVisualiser::NewLC( aEnv, aAppUi, aMailViewerControlGroup );
       
   155     CleanupStack::Pop(self);
       
   156     return self;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CFSEmailUiMailViewerVisualiser::NewLC
       
   161 // -----------------------------------------------------------------------------
       
   162 CFSEmailUiMailViewerVisualiser* CFSEmailUiMailViewerVisualiser::NewLC( CAlfEnv& aEnv, CFreestyleEmailUiAppUi& aAppUi, CAlfControlGroup& aMailViewerControlGroup )
       
   163     {
       
   164     FUNC_LOG;
       
   165     CFSEmailUiMailViewerVisualiser* self = new (ELeave) CFSEmailUiMailViewerVisualiser( aEnv, aAppUi, aMailViewerControlGroup );
       
   166     CleanupStack::PushL( self );
       
   167     self->ConstructL();
       
   168     return self;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CFSEmailUiMailViewerVisualiser::ConstructL
       
   173 // -----------------------------------------------------------------------------
       
   174 void CFSEmailUiMailViewerVisualiser::ConstructL()
       
   175     {
       
   176     FUNC_LOG;
       
   177     BaseConstructL( R_FSEMAILUI_MAIL_VIEWER_VIEW );
       
   178     iMessage = NULL;
       
   179     iNextOrPevMessageSelected = EFalse;
       
   180     iFirstStartCompleted = EFalse;
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CFSEmailUiMailViewerVisualiser::DoFirstStartL()
       
   185 // Purpose of this function is to do first start only when viewer is
       
   186 // really needed to be shown. Implemented to make app start up faster.
       
   187 // -----------------------------------------------------------------------------
       
   188 void CFSEmailUiMailViewerVisualiser::DoFirstStartL()
       
   189     {
       
   190     FUNC_LOG;
       
   191     iOpenMessages = new (ELeave) CStack<CFSMailMessage, ETrue>();
       
   192     iEmbeddedMessages = new (ELeave) CStack<CFSMailMessage, EFalse>();
       
   193     iSmDictionary = CFsSmileyDictionary::NewL();
       
   194     iIBServiceHandler = CAiwServiceHandler::NewL();
       
   195     iIBServiceHandler->AttachMenuL( R_FSEMAILUI_MAILVIEWER_SUBMENU_ACTIONS, R_INTRANET_AIW_INTEREST_MENU );
       
   196     iIBServiceHandler->AttachL( R_INTRANET_AIW_INTEREST_BASE );
       
   197 
       
   198     // Initialize browser laucher api
       
   199     iFetchingAnimationTimer = CFSEmailUiGenericTimer::NewL( this );
       
   200     iAsyncCallback = new (ELeave) CAsyncCallBack( CActive::EPriorityLow );
       
   201     iDownloadProgressControlGroup = &iEnv.NewControlGroupL( KDownloadIndicatorControlGroup );
       
   202     iDownloadProgressIndicator = CFSEmailUiStatusIndicator::NewL( iEnv, *iDownloadProgressControlGroup,
       
   203                                                                   &iAppUi );
       
   204 
       
   205     iViewerRichText = CFSEmailUiMailViewerRichText::NewL( iAppUi );
       
   206 
       
   207     //here is set menu for msk
       
   208     MenuBar()->SetContextMenuTitleResourceId( R_FSEMAILUI_MAILVIEWER_MSK_MENUBAR );
       
   209 
       
   210     iFirstStartCompleted = ETrue;
       
   211     }
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CFSEmailUiMailViewerVisualiser::CFSEmailUiMailViewerVisualiser
       
   215 // -----------------------------------------------------------------------------
       
   216 CFSEmailUiMailViewerVisualiser::CFSEmailUiMailViewerVisualiser( CAlfEnv& aEnv,
       
   217     CFreestyleEmailUiAppUi& aAppUi, CAlfControlGroup& aMailViewerControlGroup )
       
   218     : CFsEmailUiViewBase( aMailViewerControlGroup, aAppUi ),
       
   219     iMoveToFolderOngoing( EFalse ),
       
   220     iFetchingMessageStructure( EFalse ),
       
   221     iFetchingPlainTextMessageBody( EFalse ),
       
   222     iFetchingHtmlMessageBody( EFalse ),
       
   223     iAsyncProcessComplete( ETrue ),
       
   224     iEnv( aEnv )
       
   225     {
       
   226     FUNC_LOG;
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CFSEmailUiMailViewerVisualiser::~CFSEmailUiMailViewerVisualiser
       
   231 // -----------------------------------------------------------------------------
       
   232 CFSEmailUiMailViewerVisualiser::~CFSEmailUiMailViewerVisualiser()
       
   233     {
       
   234     FUNC_LOG;
       
   235         //<cmail> notewrapper is replaced by iWaitDialog
       
   236     //delete iAsyncWaitNote;
       
   237         //</cmail>
       
   238     if( iIBServiceHandler )
       
   239         {
       
   240         iIBServiceHandler->Reset();
       
   241         delete iIBServiceHandler;
       
   242         }
       
   243 
       
   244     if ( iAsyncCallback )
       
   245         {
       
   246         iAsyncCallback->Cancel();
       
   247         delete iAsyncCallback;
       
   248         }
       
   249 
       
   250     iDownloadProgressControlGroup = NULL; // owned by AlfEnv
       
   251     }
       
   252 
       
   253 void CFSEmailUiMailViewerVisualiser::PrepareForExit()
       
   254     {
       
   255     FUNC_LOG;
       
   256     delete iSmDictionary;
       
   257     iSmDictionary = NULL;
       
   258     delete iNewMailTempAddress;
       
   259     iNewMailTempAddress = NULL;
       
   260 
       
   261     // Text viewer control need to be removed control group and deleted here,
       
   262     // because akn physics (used by text viewer control) object's destructor
       
   263     // ends up calling CoeEnv->AppUi, so AppUi must be alive when deleting
       
   264     // text viewer control
       
   265     if ( iTextViewerControl )
       
   266         {
       
   267         ControlGroup().Remove( iTextViewerControl );
       
   268         }
       
   269 
       
   270     delete iTextViewer;
       
   271     iTextViewer = NULL;
       
   272 
       
   273     delete iTextViewerControl;
       
   274     iTextViewerControl = NULL;
       
   275 
       
   276     delete iViewerRichText;
       
   277     iViewerRichText = NULL;
       
   278 
       
   279     if ( iFlagSelectionHanler )
       
   280         {
       
   281         iFlagSelectionHanler->Cancel();
       
   282         delete iFlagSelectionHanler;
       
   283         iFlagSelectionHanler = NULL;
       
   284         }
       
   285     if ( iFetchingAnimationTimer )
       
   286         {
       
   287         iFetchingAnimationTimer->Stop();
       
   288         delete iFetchingAnimationTimer;
       
   289         iFetchingAnimationTimer = NULL;
       
   290         }
       
   291     if ( iAppUi.DownloadInfoMediator() && iMessage )
       
   292         {
       
   293         iAppUi.DownloadInfoMediator()->StopObserving( this, iMessage->GetMessageId() );
       
   294         }
       
   295 
       
   296     delete iOpenMessages;
       
   297     iOpenMessages = NULL;
       
   298     delete iEmbeddedMessages;
       
   299     iEmbeddedMessages = NULL;
       
   300     iMessage = NULL;
       
   301 
       
   302     delete iMailBox;
       
   303     iMailBox = NULL;
       
   304     }
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // CFSEmailUiMailViewerVisualiser::HandleForegroundEventL
       
   308 // -----------------------------------------------------------------------------
       
   309 void CFSEmailUiMailViewerVisualiser::HandleForegroundEventL()
       
   310     {
       
   311     FUNC_LOG;
       
   312     if ( iFirstStartCompleted ) //Safety
       
   313         {
       
   314         // Resize the download indicator after returning from the screensaver
       
   315         iDownloadProgressIndicator->HandleForegroundEventL();
       
   316         }
       
   317     }
       
   318 
       
   319 // -----------------------------------------------------------------------------
       
   320 // CFSEmailUiMailViewerVisualiser::RequestResponseL
       
   321 // for MFSEmailDownloadInformationObserver callback
       
   322 // -----------------------------------------------------------------------------
       
   323 void CFSEmailUiMailViewerVisualiser::RequestResponseL( const TFSProgress& aEvent, const TPartData& /*aPart*/ )
       
   324     {
       
   325     FUNC_LOG;
       
   326     if ( iFirstStartCompleted && iAppUi.CurrentActiveView() == this )
       
   327         {
       
   328         UpdateDownloadIndicatorL( aEvent.iProgressStatus );
       
   329 
       
   330         // <cmail> Action menu is dismissed if it's opened on an attachment
       
   331         // and the download has completed (to prevent canceling after completion).
       
   332         SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
   333         CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
   334 
       
   335         THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL(
       
   336             currentHeaderHotSpotData, currentBodyHotSpotData );
       
   337 
       
   338         if( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete &&
       
   339             hotspotType == EHeaderHotspot &&
       
   340             (currentHeaderHotSpotData.iType == ETypeAttachment ||
       
   341             currentHeaderHotSpotData.iType == ETypeAttachments) )
       
   342             {
       
   343             CFSEmailUiActionMenu::Dismiss( ETrue );
       
   344 
       
   345             // close actions menu if open
       
   346             CEikMenuBar* menu = MenuBar();
       
   347 
       
   348             if( menu->IsDisplayed() )
       
   349                 {
       
   350                 menu->MenuPane()->CloseCascadeMenu();
       
   351                 }
       
   352             }
       
   353         // </cmail>
       
   354         }
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CFSEmailUiMailViewerVisualiser::RequestResponseL
       
   359 // for MFSMailRequestObserver callback
       
   360 // -----------------------------------------------------------------------------
       
   361 void CFSEmailUiMailViewerVisualiser::RequestResponseL( TFSProgress aEvent, TInt aRequestId )
       
   362     {
       
   363     FUNC_LOG;
       
   364     if ( iFirstStartCompleted ) // Safety
       
   365         {
       
   366         if ( aRequestId == iCurrentPlainTextBodyFetchRequestId && iFetchingPlainTextMessageBody )
       
   367             {
       
   368             if ( aEvent.iError != KErrNone ||
       
   369                  aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled )
       
   370                 {
       
   371                 iAsyncProcessComplete = ETrue;
       
   372                 iFetchingPlainTextMessageBody = EFalse;
       
   373                 iFetchingAnimationTimer->Stop();
       
   374 
       
   375                 // Clear the "fetching body" text from the end of the message
       
   376                 iViewerRichText->SetEmptyStatusLayoutTextL();
       
   377                 }
       
   378             else if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete )
       
   379                 {
       
   380                 iAsyncProcessComplete = ETrue;
       
   381                 iFetchingPlainTextMessageBody = EFalse;
       
   382                 iFetchingAnimationTimer->Stop();
       
   383 
       
   384                 // get message again, there might be new information (in case of POP protocol)
       
   385                 TFSMailMsgId mailboxId = iMessage->GetMailBoxId();
       
   386                 TFSMailMsgId folderId = iMessage->GetFolderId();
       
   387                 TFSMailMsgId messageId = iMessage->GetMessageId();
       
   388                 UpdateMessagePtrL( mailboxId, folderId, messageId );
       
   389 
       
   390                 // Refresh viewer to show newly fetched content.
       
   391                 // Prevent screen flickering by stopping automatic screen refresh during the update
       
   392                 iEnv.SetRefreshMode( EAlfRefreshModeManual );
       
   393                 // Make sure we don't leave and forget the refresh mode as manual.
       
   394                 TRAP_IGNORE(
       
   395                     // Try to preserve the scroll position on the same line.
       
   396                     iAppUi.Display().Roster().Hide( ControlGroup() );
       
   397                     TInt firstLine = iTextViewer->GetFirstDisplayedLine();
       
   398                     RefreshL();
       
   399                     iTextViewer->FocusLineL( firstLine, ETrue );
       
   400                     iAppUi.Display().Roster().ShowL( ControlGroup() );
       
   401                     );
       
   402                 iEnv.SetRefreshMode( EAlfRefreshModeAutomatic );
       
   403                 }
       
   404             }
       
   405 
       
   406         else if ( aRequestId == iCurrentHtmlBodyFetchRequestId && iFetchingHtmlMessageBody )
       
   407             {
       
   408             if ( aEvent.iError != KErrNone ||
       
   409                  aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled )
       
   410                 {
       
   411                 iAsyncProcessComplete = ETrue;
       
   412                 iFetchingHtmlMessageBody = EFalse;
       
   413                 }
       
   414             else if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete )
       
   415                 {
       
   416                 iAsyncProcessComplete = ETrue;
       
   417                 iFetchingHtmlMessageBody = EFalse;
       
   418                 LaunchHtmlViewerL();
       
   419                 }
       
   420             }
       
   421         else if ( aRequestId == iCurrentStructureFetchRequestId && iFetchingMessageStructure )
       
   422             {
       
   423             if ( aEvent.iError != KErrNone ||
       
   424                  aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled )
       
   425                 {
       
   426                 iAsyncProcessComplete = ETrue;
       
   427                 iFetchingMessageStructure = EFalse;
       
   428                 }
       
   429             else if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete )
       
   430                 {
       
   431                 iAsyncProcessComplete = ETrue;
       
   432                 iFetchingMessageStructure = EFalse;
       
   433 
       
   434                 // get message again, there might be new information
       
   435                 TFSMailMsgId mailboxId = iMessage->GetMailBoxId();
       
   436                 TFSMailMsgId folderId = iMessage->GetFolderId();
       
   437                 TFSMailMsgId messageId = iMessage->GetMessageId();
       
   438 
       
   439                 UpdateMessagePtrL( mailboxId, folderId, messageId );
       
   440                 if ( iMessage )
       
   441                     {
       
   442                     // Stop automatic screen refresh temporarily to prevent flickering
       
   443                     iEnv.SetRefreshMode( EAlfRefreshModeManual );
       
   444                     // we must not leave before the update mode has been restored
       
   445                     TRAP_IGNORE(
       
   446                         iAppUi.Display().Roster().Hide( ControlGroup() );
       
   447                         RefreshL( ETrue );
       
   448                         iAppUi.Display().Roster().ShowL( ControlGroup() );
       
   449                         );
       
   450                     iEnv.SetRefreshMode( EAlfRefreshModeAutomatic );
       
   451                     }
       
   452                 }
       
   453             }
       
   454         }
       
   455     //<cmail>
       
   456     if(iAsyncProcessComplete && iWaitDialog && iDialogNotDismissed)
       
   457         iWaitDialog->ProcessFinishedL(); // deletes the dialog
       
   458     //</cmail>
       
   459     }
       
   460 
       
   461 
       
   462 // -----------------------------------------------------------------------------
       
   463 // CFSEmailUiMailViewerVisualiser::FolderSelectedL
       
   464 // -----------------------------------------------------------------------------
       
   465 void CFSEmailUiMailViewerVisualiser::FolderSelectedL(
       
   466     TFSMailMsgId aSelectedFolderId, TFSEmailUiCtrlBarResponse aResponse )
       
   467     {
       
   468     FUNC_LOG;
       
   469 
       
   470     if ( iMoveToFolderOngoing )
       
   471         {
       
   472         iMoveToFolderOngoing = EFalse;
       
   473         if ( !iMovingMeetingRequest )
       
   474             {
       
   475             switch ( aResponse )
       
   476                 {
       
   477                 case EFSEmailUiCtrlBarResponseSelect:
       
   478                     {
       
   479                     iMoveDestinationFolder = aSelectedFolderId;
       
   480                     iAsyncCallback->Cancel(); // cancel any outstanding callback just to be safe
       
   481                     iAsyncCallback->Set( TCallBack( MoveToFolderAndExitL, this ) );
       
   482                     iAsyncCallback->CallBack();
       
   483                     }
       
   484                     break;
       
   485                 case EFSEmailUiCtrlBarResponseCancel:
       
   486                 default:
       
   487                     break;
       
   488                 }
       
   489             }
       
   490         else
       
   491             {
       
   492             iMovingMeetingRequest = EFalse;
       
   493             switch ( aResponse )
       
   494                 {
       
   495                 case EFSEmailUiCtrlBarResponseCancel:
       
   496                     iOpResult.iResultCode = KErrCancel;
       
   497                     break;
       
   498                 case EFSEmailUiCtrlBarResponseSelect:
       
   499                     {
       
   500                     // Do moving here, do not exit, because mrui exists itself.
       
   501                     iOpResult.iResultCode = KErrNone;
       
   502                     iMoveDestinationFolder = aSelectedFolderId;
       
   503                     RArray<TFSMailMsgId> messageIds;
       
   504                     CleanupClosePushL( messageIds );
       
   505                     messageIds.Append( iMessage->GetMessageId() );
       
   506                     // Trap is needed because protocol might return KErrNotSupported
       
   507                     // if move away from current folder is not supprted
       
   508                     TRAPD(errMove, iAppUi.GetActiveMailbox()->MoveMessagesL( messageIds,
       
   509                                                       iMessage->GetFolderId(), iMoveDestinationFolder ));
       
   510                     if ( errMove != KErrNotSupported )
       
   511                         {
       
   512                         if ( errMove == KErrNone )
       
   513                             {
       
   514                             TFsEmailUiUtility::DisplayMsgsMovedNoteL( 1, iMoveDestinationFolder, ETrue );
       
   515                             }
       
   516                         else
       
   517                             {
       
   518                             User::Leave( errMove );
       
   519                             }
       
   520                         }
       
   521                     CleanupStack::PopAndDestroy( &messageIds );
       
   522                     }
       
   523                     break;
       
   524                 default:
       
   525                     break;
       
   526                 }
       
   527             }
       
   528         }
       
   529 
       
   530     }
       
   531 
       
   532 // ---------------------------------------------------------------------------
       
   533 // From MFSEmailUiContactHandlerObserver
       
   534 // The ownership of the CLS items in the contacts array is transferred to the
       
   535 // observer, and they must be deleted by the observer.
       
   536 // ---------------------------------------------------------------------------
       
   537 //
       
   538 void CFSEmailUiMailViewerVisualiser::OperationCompleteL(
       
   539     TContactHandlerCmd /*aCmd*/, const RPointerArray<CFSEmailUiClsItem>& /*aContacts*/ )
       
   540     {
       
   541     FUNC_LOG;
       
   542     }
       
   543 
       
   544 // ---------------------------------------------------------------------------
       
   545 // From MFSEmailUiContactHandlerObserver
       
   546 // Handles error in contatct handler operation.
       
   547 // ---------------------------------------------------------------------------
       
   548 //
       
   549 void CFSEmailUiMailViewerVisualiser::OperationErrorL(
       
   550     TContactHandlerCmd /*aCmd*/, TInt /*aError*/ )
       
   551     {
       
   552     FUNC_LOG;
       
   553     }
       
   554 
       
   555 // -----------------------------------------------------------------------------
       
   556 // CFSEmailUiMailViewerVisualiser::MoveToFolderAndExitL
       
   557 // -----------------------------------------------------------------------------
       
   558 TInt CFSEmailUiMailViewerVisualiser::MoveToFolderAndExitL( TAny* aMailViewerVisualiser )
       
   559     {
       
   560     FUNC_LOG;
       
   561     CFSEmailUiMailViewerVisualiser* self =
       
   562         static_cast<CFSEmailUiMailViewerVisualiser*>(aMailViewerVisualiser);
       
   563 
       
   564     RArray<TFSMailMsgId> messageIds;
       
   565     CleanupClosePushL( messageIds );
       
   566     messageIds.Append( self->iMessage->GetMessageId() );
       
   567 
       
   568     // Trap is needed because protocol might return KErrNotSupported
       
   569     // if move away from current folder is not supprted
       
   570     TRAPD(errMove, self->iAppUi.GetActiveMailbox()->MoveMessagesL( messageIds,
       
   571                                                      self->iMessage->GetFolderId(),
       
   572                                                      self->iMoveDestinationFolder ) );
       
   573     if ( errMove != KErrNotSupported )
       
   574         {
       
   575         if ( errMove == KErrNone )
       
   576             {
       
   577             // move successfull, display note
       
   578             TFsEmailUiUtility::DisplayMsgsMovedNoteL( 1, self->iMoveDestinationFolder, ETrue );
       
   579             }
       
   580         else
       
   581             {
       
   582             // Leave with any other err code than KErrNone or KErrNotSupported.
       
   583             User::Leave( errMove );
       
   584             }
       
   585         }
       
   586     CleanupStack::PopAndDestroy( &messageIds );
       
   587 
       
   588     // return to previous view
       
   589     self->HandleCommandL( EAknSoftkeyBack );
       
   590 
       
   591     return KErrNone;
       
   592     }
       
   593 
       
   594 // -----------------------------------------------------------------------------
       
   595 // CFSEmailUiMailViewerVisualiser::OpenFolderListForMessageMovingL
       
   596 // -----------------------------------------------------------------------------
       
   597 TBool CFSEmailUiMailViewerVisualiser::OpenFolderListForMessageMovingL()
       
   598     {
       
   599     FUNC_LOG;
       
   600     TBool ret = EFalse;
       
   601     // Ignore if mailbox doesn't support moving or we are viewing embedded message
       
   602     if ( iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaMoveToFolder ) &&
       
   603             !iEmbeddedMessageMode )
       
   604         {
       
   605         // Activate folder selection view and handle moving after callback gets destination
       
   606         iMoveToFolderOngoing = ETrue;
       
   607         TFolderListActivationData folderListData;
       
   608         folderListData.iCallback = this;
       
   609         CFSMailFolder* folder = iAppUi.GetMailClient()->GetFolderByUidL( iMessage->GetMailBoxId(), iMessage->GetFolderId() );
       
   610         folderListData.iSourceFolderType = TFSFolderType( folder->GetFolderType() );
       
   611         delete folder;
       
   612         const TPckgBuf<TFolderListActivationData> pkgOut( folderListData );
       
   613         iAppUi.EnterFsEmailViewL( FolderListId, KFolderListMoveMessage, pkgOut );
       
   614         ret = ETrue;
       
   615         }
       
   616     return ret;
       
   617     }
       
   618 
       
   619 
       
   620 // -----------------------------------------------------------------------------
       
   621 // CFSEmailUiMailViewerVisualiser::ViewerControl
       
   622 // -----------------------------------------------------------------------------
       
   623 CAlfControl* CFSEmailUiMailViewerVisualiser::ViewerControl()
       
   624     {
       
   625     FUNC_LOG;
       
   626     return iTextViewerControl;
       
   627     }
       
   628 
       
   629 // -----------------------------------------------------------------------------
       
   630 // CFSEmailUiMailViewerVisualiser::Id
       
   631 // -----------------------------------------------------------------------------
       
   632 TUid CFSEmailUiMailViewerVisualiser::Id() const
       
   633     {
       
   634     FUNC_LOG;
       
   635     return MailViewerId;
       
   636     }
       
   637 
       
   638 // -----------------------------------------------------------------------------
       
   639 // CFSEmailUiMailViewerVisualiser::ChildDoActivateL
       
   640 // -----------------------------------------------------------------------------
       
   641 // <cmail> Toolbar
       
   642 /*void CFSEmailUiMailViewerVisualiser::DoActivateL(
       
   643     const TVwsViewId& aPrevViewId,
       
   644     TUid aCustomMessageId,
       
   645     const TDesC8& aCustomMessage )*/
       
   646 // </cmail> Toolbar
       
   647 void CFSEmailUiMailViewerVisualiser::ChildDoActivateL(
       
   648     const TVwsViewId& aPrevViewId,
       
   649     TUid aCustomMessageId,
       
   650     const TDesC8& aCustomMessage )
       
   651     {
       
   652     FUNC_LOG;
       
   653 
       
   654     // Read the activation parameters
       
   655     TMsgViewerActivationData activationData;
       
   656     if ( &aCustomMessage && aCustomMessage.Length() )
       
   657         {
       
   658         TPckgBuf<TMsgViewerActivationData> pkgBuf;
       
   659         pkgBuf.Copy( aCustomMessage );
       
   660         activationData = pkgBuf();
       
   661         }
       
   662 
       
   663     // Take ownership of the passed message pointer. No pointer should be passed
       
   664     // in other than embedded message cases.
       
   665     // No leaving functions may be called before this step.
       
   666     if ( aCustomMessageId != KStartViewerWithEmbeddedMsgPtr && activationData.iEmbeddedMessage )
       
   667         {
       
   668         delete activationData.iEmbeddedMessage;
       
   669         activationData.iEmbeddedMessage = NULL;
       
   670         __ASSERT_DEBUG( EFalse, Panic(EFSEmailUiUnexpectedValue) );
       
   671         }
       
   672 
       
   673     CleanupStack::PushL( activationData.iEmbeddedMessage );
       
   674 
       
   675     if ( !iFirstStartCompleted )
       
   676         {
       
   677         DoFirstStartL();
       
   678         }
       
   679     if ( aCustomMessageId == KStartViewerWithEmbeddedMsgPtr )
       
   680         {
       
   681         PushMessageL( activationData.iEmbeddedMessage, ETrue );
       
   682         }
       
   683     CleanupStack::Pop( activationData.iEmbeddedMessage ); // ownership transferred
       
   684 
       
   685     // Clear MSK to prevent unintentional presses before viewer is fully constructed
       
   686     ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
   687 
       
   688     // If returning from view launched by MRUI, just complete the ongoing async process.
       
   689     // This will cause MRUI to be reopened and no other activation actions are needed.
       
   690     if ( iMrObserverToInform && aCustomMessageId == KStartViewerReturnToPreviousMsg )
       
   691         {
       
   692         CompletePendingMrCommand();
       
   693         }
       
   694     // Otherwise go on with the standard view activation
       
   695     else
       
   696         {
       
   697         // Cancel any pending asynchronous MR operation. There may be one at least if we
       
   698         // have navigated from MRUI to Donwload manager and from there to another message
       
   699         // or if external view activation happens while MRUI is open.
       
   700         CancelPendingMrCommandL();
       
   701 
       
   702         // Get message object unless returning to previously shown message.
       
   703         // In KStartViewerReturnToPreviousMsg the UI assumes that iMessage is alive.
       
   704         if ( aCustomMessageId == KStartViewerWithMsgId )
       
   705             {
       
   706             // Inform base view if view has been forward navigated to get correct back
       
   707             // navigation functionality in case of external activation.
       
   708             ViewEntered( aPrevViewId );
       
   709             UpdateMessagePtrL( activationData.iMailBoxId, activationData.iFolderId, activationData.iMessageId );
       
   710             }
       
   711         else if ( aCustomMessageId == KStartViewerWithEmbeddedMsgPtr ||
       
   712                   aCustomMessageId == KStartViewerReturnFromEmbeddedMsg )
       
   713             {
       
   714             if ( !iOpenMessages || iOpenMessages->IsEmpty() )
       
   715                 {
       
   716                 User::Leave( KErrNotFound );
       
   717                 }
       
   718             UpdateMessagePtr( iOpenMessages->Head() );
       
   719             }
       
   720 
       
   721         // Regardless of the activation mode, we should now have a valid message pointer.
       
   722         // Otherwise we cannot go on.
       
   723         User::LeaveIfNull( iMessage );
       
   724 
       
   725         iEmbeddedMessageMode = (iEmbeddedMessages->Head() != NULL);
       
   726 
       
   727         // Update mailbox unless returning to previously open message
       
   728         if ( aCustomMessageId != KStartViewerReturnToPreviousMsg )
       
   729             {
       
   730             delete iMailBox; iMailBox = NULL;
       
   731             iMailBox = iAppUi.GetMailClient()->GetMailBoxByUidL( iMessage->GetMailBoxId() );
       
   732 
       
   733             // Change active mailbox if necessary
       
   734             if ( !iMessage->GetMailBoxId().IsNullId() )
       
   735                 {
       
   736                 iAppUi.SetActiveMailboxL( iMessage->GetMailBoxId(), EFalse );
       
   737                 }
       
   738             }
       
   739 
       
   740         // Check if MSG should be shown in the Meeting Request viewer
       
   741         TBool msgSentToMrUi( EFalse );
       
   742         if ( iMessage->IsFlagSet( EFSMsgFlag_CalendarMsg ) &&
       
   743              iAppUi.MrViewerInstanceL() &&
       
   744              !iEmbeddedMessageMode )
       
   745             {
       
   746             // Resolve meeting requst method
       
   747             TESMRMeetingRequestMethod mrMethod( EESMRMeetingRequestMethodUnknown );
       
   748             mrMethod = iAppUi.MrViewerInstanceL()->ResolveMeetingRequestMethodL( *iMessage );
       
   749             if ( mrMethod == EESMRMeetingRequestMethodRequest ||      // Request is shown in mrui
       
   750                  mrMethod == EESMRMeetingRequestMethodCancellation || // Cancellation is shown in mrui
       
   751                  mrMethod == EESMRMeetingRequestMethodUnknown )       // Unknown MR needs to be to resolved in MRUI (Usually IMAP)
       
   752                 {
       
   753                 // Setting MSK empty. This blocks unwanted MSK keypresses before MrViewer is initialized.
       
   754                 ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
   755 
       
   756                 msgSentToMrUi = ETrue;
       
   757                 ClearMailViewer(); // clear prev message to avoid it becoming visible before MRUI opens
       
   758                 iMrUiActive = ETrue;
       
   759                 // Same navi pane shown in MR viewer
       
   760                 UpdateNaviPaneL( ETrue );
       
   761                 SetMailboxNameToStatusPaneL();
       
   762                 iAppUi.MrViewerInstanceL()->ExecuteViewL( *iMessage, *this );
       
   763                 }
       
   764             }
       
   765 
       
   766         // MSG is not sent to MRUI, display in internal mail viewer
       
   767         // Message is either normal email message or response to meeting request
       
   768         if ( !msgSentToMrUi )
       
   769             {
       
   770             iMrUiActive = EFalse;
       
   771 
       
   772             // Update the viewer if new message has been opened or layout has changed while we were in some other view
       
   773             TBool changeMsg = (aCustomMessageId != KStartViewerReturnToPreviousMsg);
       
   774             if ( changeMsg || iLayoutChangedWhileNotActive )
       
   775                 {
       
   776                 RefreshL( changeMsg );
       
   777                 }
       
   778             else // update MSK anyway as the attachment status may have changed
       
   779                 {
       
   780                 iShowMskDownloadOption = ShowMskDownloadOptionL();
       
   781                 SetMskL();
       
   782                 }
       
   783 
       
   784             SetMailboxNameToStatusPaneL();
       
   785 
       
   786             // Update navipane content
       
   787             UpdateNaviPaneL();
       
   788             }
       
   789 
       
   790         // Set email indicator off.. user has checked the new emails
       
   791         TFsEmailUiUtility::ToggleEmailIconL( EFalse, activationData.iMailBoxId );
       
   792         }
       
   793 
       
   794     iNextOrPevMessageSelected = EFalse;
       
   795     }
       
   796 
       
   797 // -----------------------------------------------------------------------------
       
   798 // CFSEmailUiMailViewerVisualiser::OfferToolbarEventL
       
   799 // -----------------------------------------------------------------------------
       
   800 void CFSEmailUiMailViewerVisualiser::OfferToolbarEventL( TInt aCommand )
       
   801     {
       
   802     FUNC_LOG;
       
   803     switch (aCommand)
       
   804         {
       
   805         case EFsEmailUiTbCmdReply:
       
   806             {
       
   807             HandleCommandL(EFsEmailUiCmdActionsReply);
       
   808             break;
       
   809             }
       
   810 
       
   811         case EFsEmailUiTbCmdForward:
       
   812             {
       
   813             HandleCommandL(EFsEmailUiCmdActionsForward);
       
   814             break;
       
   815             }
       
   816         case EFsEmailUiTbCmdDelete:
       
   817             {
       
   818             HandleCommandL(EFsEmailUiCmdActionsDelete);
       
   819             break;
       
   820             }
       
   821         case EFsEmailUiTbCmdReplyAll:
       
   822             {
       
   823             HandleCommandL(EFsEmailUiCmdActionsReplyAll);
       
   824             break;
       
   825             }
       
   826         default:
       
   827             break;
       
   828         }
       
   829     }
       
   830 
       
   831 // -----------------------------------------------------------------------------
       
   832 // CFSEmailUiMailViewerVisualiser::ToolbarResourceId
       
   833 // -----------------------------------------------------------------------------
       
   834 TInt CFSEmailUiMailViewerVisualiser::ToolbarResourceId() const
       
   835     {
       
   836     return R_FREESTYLE_EMAIL_UI_TOOLBAR_MESSAGE_VIEWER;
       
   837     }
       
   838 
       
   839 // -----------------------------------------------------------------------------
       
   840 // CFSEmailUiMailViewerVisualiser::ChildDoDeactivate
       
   841 // -----------------------------------------------------------------------------
       
   842 void CFSEmailUiMailViewerVisualiser::ChildDoDeactivate()
       
   843     {
       
   844     FUNC_LOG;
       
   845     CancelFetchings();
       
   846     if ( iFetchingAnimationTimer )
       
   847         {
       
   848         iFetchingAnimationTimer->Stop();
       
   849         }
       
   850     if ( iDownloadProgressIndicator )
       
   851         {
       
   852         iDownloadProgressIndicator->HideIndicator();
       
   853         }
       
   854 
       
   855     // Hide this view's navipane
       
   856     HideNaviPane();
       
   857 
       
   858     // set view itself as toolbar observer again (e.g. MRGUI could have been changed it)
       
   859     Toolbar()->SetToolbarObserver( this );
       
   860     }
       
   861 
       
   862 // -----------------------------------------------------------------------------
       
   863 // CFSEmailUiMailViewerVisualiser::HideNaviPane
       
   864 // -----------------------------------------------------------------------------
       
   865 void CFSEmailUiMailViewerVisualiser::HideNaviPane()
       
   866     {
       
   867     FUNC_LOG;
       
   868     CAknNavigationControlContainer* naviPaneContainer = NULL;
       
   869     TRAP_IGNORE( naviPaneContainer = static_cast<CAknNavigationControlContainer*>( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) ) );
       
   870     TRAP_IGNORE( naviPaneContainer->PushDefaultL() );
       
   871 
       
   872     CCustomStatuspaneIndicators* indicators = iAppUi.GetStatusPaneIndicatorContainer();
       
   873     if ( indicators)
       
   874         {
       
   875         indicators->HideStatusPaneIndicators();
       
   876         }
       
   877     }
       
   878 
       
   879 // -----------------------------------------------------------------------------
       
   880 // CFSEmailUiMailViewerVisualiser::ActivateControlGroup
       
   881 // Overriden to make any running download progress bar visible after
       
   882 // control group has been swithced
       
   883 // -----------------------------------------------------------------------------
       
   884 void CFSEmailUiMailViewerVisualiser::ActivateControlGroup( TInt aDelay /*= 0*/ )
       
   885     {
       
   886     CFsEmailUiViewBase::ActivateControlGroup( aDelay );
       
   887     TRAP_IGNORE( UpdateDownloadIndicatorL() );
       
   888     }
       
   889 
       
   890 // -----------------------------------------------------------------------------
       
   891 // CFSEmailUiMailViewerVisualiser::HandleMrCommandL
       
   892 // Handle accept/decline/tentative/remove commands given for meeting request
       
   893 // message directly from list UI.
       
   894 // -----------------------------------------------------------------------------
       
   895 void CFSEmailUiMailViewerVisualiser::HandleMrCommandL(
       
   896     TInt aCommandId,
       
   897     TFSMailMsgId aMailboxId,
       
   898     TFSMailMsgId aFolderId,
       
   899     TFSMailMsgId aMessageId )
       
   900     {
       
   901     FUNC_LOG;
       
   902 
       
   903     // All items should be run
       
   904     if ( !iFirstStartCompleted )
       
   905         {
       
   906         DoFirstStartL();
       
   907         }
       
   908 
       
   909     UpdateMessagePtrL( aMailboxId, aFolderId, aMessageId );
       
   910 
       
   911     if ( aCommandId == EFsEmailUiCmdCalRemoveFromCalendar )
       
   912         {
       
   913         iAppUi.MrViewerInstanceL()->RemoveMeetingRequestFromCalendarL(
       
   914             *iMessage, *this );
       
   915         }
       
   916     else
       
   917         {
       
   918         TESMRAttendeeStatus respondStatus;
       
   919         if ( aCommandId == EFsEmailUiCmdCalActionsAccept )
       
   920             {
       
   921             respondStatus = EESMRAttendeeStatusAccept;
       
   922             }
       
   923         else if ( aCommandId == EFsEmailUiCmdCalActionsTentative )
       
   924             {
       
   925             respondStatus = EESMRAttendeeStatusTentative;
       
   926             }
       
   927         else // ( aCommandId == EFsEmailUiCmdCalActionsDecline )
       
   928             {
       
   929             respondStatus = EESMRAttendeeStatusDecline;
       
   930             }
       
   931         iAppUi.MrViewerInstanceL()->ResponseToMeetingRequestL(
       
   932             respondStatus, *iMessage, *this );
       
   933         }
       
   934     }
       
   935 
       
   936 // -----------------------------------------------------------------------------
       
   937 // CFSEmailUiMailViewerVisualiser::HandleTextViewerEventL
       
   938 // From viewer observer for CFsTextViewer callbacks
       
   939 // -----------------------------------------------------------------------------
       
   940 void CFSEmailUiMailViewerVisualiser::HandleTextViewerEventL( TFsTextViewerEvent aEvent )
       
   941     {
       
   942     FUNC_LOG;
       
   943     if ( iFirstStartCompleted ) // Safety
       
   944         {
       
   945         if ( aEvent == EFsTextViewerHotspotClicked )
       
   946             {
       
   947             // Get currently focused hotspot data
       
   948             SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
   949             CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
   950             THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL(
       
   951                 currentHeaderHotSpotData, currentBodyHotSpotData );
       
   952 
       
   953             // Some header hotspots have some immediate action defined, so
       
   954             // in case of header hotspot, try to handle the action first
       
   955             TBool actionTaken( EFalse );
       
   956             if ( hotspotType == EHeaderHotspot )
       
   957                 {
       
   958                 actionTaken = HandleHeaderHotspotActionL( currentHeaderHotSpotData.iType );
       
   959                 }
       
   960 
       
   961             // If the current item is valid hotspot but it didn't have any
       
   962             // immediate action defined, launch item specific action menu
       
   963             if( ( hotspotType == EHeaderHotspot || hotspotType == EBodyHotspot ) &&
       
   964                 !actionTaken )
       
   965                 {
       
   966                 LaunchActionMenuL();
       
   967                 }
       
   968             }
       
   969         else if ( aEvent == EFsTextViewerHotspotLongTap )
       
   970             {
       
   971             LaunchActionMenuL();
       
   972             }
       
   973         else if ( aEvent == EFsTextViewerScrollDown )
       
   974             {
       
   975             // check if user has scroll to the bottom for start fetching rest of the message.
       
   976             // if whole message has already been fetched, no actions are needed
       
   977             StartFetchingRemaininBodyLinesIfAtBottomL();
       
   978 
       
   979             // Hide action menu icon if current hotspot does not have action menu.
       
   980             // Seems that this needs to be checked also here because "hotspot changed" events
       
   981             // are not received reliably when scrolling down.
       
   982             SetActionMenuIconVisbilityL();
       
   983             }
       
   984 
       
   985         else if ( aEvent == EFsTextViewerHotspotChanged )
       
   986             {
       
   987             // Hide action menu icon if current hotspot does not have action menu.
       
   988             SetActionMenuIconVisbilityL();
       
   989             }
       
   990         }
       
   991     }
       
   992 
       
   993 // -----------------------------------------------------------------------------
       
   994 // CFSEmailUiMailViewerVisualiser::HandleHeaderHotspotActionL
       
   995 // Handle appropriate command for the selected header hotspot, if the currently
       
   996 // focused item has some action specified. Returns ETrue, if current item has
       
   997 // some action defined (and the action is initiated), EFalse if not.
       
   998 // -----------------------------------------------------------------------------
       
   999 TBool CFSEmailUiMailViewerVisualiser::HandleHeaderHotspotActionL(
       
  1000         TViewerHeadingHotspotType aHotspotType )
       
  1001     {
       
  1002     TBool actionTaken( EFalse );
       
  1003 
       
  1004     switch( aHotspotType )
       
  1005         {
       
  1006         case ETypeToNMoreRecipients:
       
  1007         case ETypeCcNMoreRecipients:
       
  1008         case ETypeBccNMoreRecipients:
       
  1009             {
       
  1010             HandleCommandL( EFsEmailUiCmdViewAll );
       
  1011             actionTaken = ETrue;
       
  1012             }
       
  1013             break;
       
  1014         case ETypeAttachment:
       
  1015             {
       
  1016             HandleCommandL( EFsEmailUiCmdOpenAttachment );
       
  1017             actionTaken = ETrue;
       
  1018             }
       
  1019             break;
       
  1020         case ETypeAttachments:
       
  1021             {
       
  1022             HandleCommandL( EFsEmailUiCmdOpenAttachmentList );
       
  1023             actionTaken = ETrue;
       
  1024             }
       
  1025             break;
       
  1026         case ETypeHtml:
       
  1027             {
       
  1028             HandleCommandL( EFsEmailUiCmdActionsOpenHtmlViewer );
       
  1029             actionTaken = ETrue;
       
  1030             }
       
  1031             break;
       
  1032         }
       
  1033 
       
  1034     return actionTaken;
       
  1035     }
       
  1036 
       
  1037 // Helper funcitons to get viewed message ID and Folder id
       
  1038 TFSMailMsgId CFSEmailUiMailViewerVisualiser::ViewedMessageFolderId()
       
  1039     {
       
  1040     FUNC_LOG;
       
  1041     TFSMailMsgId ret;
       
  1042     if ( iMessage )
       
  1043         {
       
  1044         ret = iMessage->GetFolderId();
       
  1045         }
       
  1046     return ret;
       
  1047     }
       
  1048 
       
  1049 TFSMailMsgId CFSEmailUiMailViewerVisualiser::ViewedMessageId()
       
  1050     {
       
  1051     FUNC_LOG;
       
  1052     TFSMailMsgId ret;
       
  1053     if ( iMessage )
       
  1054         {
       
  1055         ret = iMessage->GetMessageId();
       
  1056         }
       
  1057     return ret;
       
  1058     }
       
  1059 
       
  1060 // -----------------------------------------------------------------------------
       
  1061 // CFSEmailUiMailViewerVisualiser::RefreshL
       
  1062 // -----------------------------------------------------------------------------
       
  1063 void CFSEmailUiMailViewerVisualiser::RefreshL( TBool aFirstRefresh /*= EFalse*/ )
       
  1064     {
       
  1065     FUNC_LOG;
       
  1066     if ( iFirstStartCompleted ) // Safety
       
  1067         {
       
  1068         // Show "Opening" wait note if the viewed message is a large one
       
  1069         //<cmail>
       
  1070         //TInt waitNoteId = KErrNotFound;
       
  1071         //</cmail>
       
  1072         if ( TFsEmailUiUtility::IsMessageBodyLargeL( iMessage ) )
       
  1073             {
       
  1074             //<cmail> using normal wait note instead of using global
       
  1075             //waitNoteId = TFsEmailUiUtility::ShowGlobalWaitNoteLC( R_FSE_WAIT_OPENING_TEXT );
       
  1076             iWaitDialogOpening = new(ELeave)CAknWaitDialog(
       
  1077                                 (REINTERPRET_CAST(CEikDialog**,&iWaitDialogOpening)));
       
  1078             HBufC* noteText = StringLoader::LoadLC( R_FSE_WAIT_OPENING_TEXT );
       
  1079             iWaitDialogOpening->SetTextL(*noteText);
       
  1080             //iWaitDialogOpening->DrawableWindow()->SetOrdinalPosition(0);
       
  1081             CleanupStack::PopAndDestroy(noteText);
       
  1082             iWaitDialogOpening->ExecuteLD(R_FSE_WAIT_DIALOG_NO_CANCEL);
       
  1083             //</cmail>
       
  1084             }
       
  1085 
       
  1086         // Do the update
       
  1087         UpdateMailViewerL();
       
  1088         AddBackgroundPicturesL();
       
  1089 
       
  1090         // scroll to Sent line after updating if requested
       
  1091         if ( aFirstRefresh )
       
  1092             {
       
  1093             iTextViewer->FocusLineL( iViewerRichText->SentTextLine(), ETrue );
       
  1094 
       
  1095             iAsyncCallback->Cancel(); // just in case
       
  1096             iAsyncCallback->Set( TCallBack( DoPostRefresh, this ) );
       
  1097             iAsyncCallback->CallBack();
       
  1098             }
       
  1099 
       
  1100         // Close the wait note if it was opened
       
  1101         if ( iWaitDialogOpening )//<cmail>
       
  1102             {
       
  1103             //<cmail>
       
  1104             //CleanupStack::PopAndDestroy( (TAny*)waitNoteId );
       
  1105             iWaitDialogOpening->ProcessFinishedL(); //it destroys the waitnote also
       
  1106             //</cmail>
       
  1107             }
       
  1108         }
       
  1109     }
       
  1110 
       
  1111 // -----------------------------------------------------------------------------
       
  1112 // CFSEmailUiMailViewerVisualiser::DoPostActivation
       
  1113 // Callback function for deferred activation actions
       
  1114 // -----------------------------------------------------------------------------
       
  1115 TInt CFSEmailUiMailViewerVisualiser::DoPostRefresh( TAny* aSelfPtr )
       
  1116     {
       
  1117     FUNC_LOG;
       
  1118     CFSEmailUiMailViewerVisualiser* self =
       
  1119         static_cast<CFSEmailUiMailViewerVisualiser*>( aSelfPtr );
       
  1120     TRAPD( err, self->PostRefreshL() );
       
  1121     return err;
       
  1122     }
       
  1123 
       
  1124 void CFSEmailUiMailViewerVisualiser::PostRefreshL()
       
  1125     {
       
  1126     FUNC_LOG;
       
  1127     // Focus attahcment line if available
       
  1128     TInt attachmentTextLine = iViewerRichText->AttachmentTextLine();
       
  1129     TInt viewHtmlTextLine = iViewerRichText->ViewHtmlTextLine();
       
  1130     if ( attachmentTextLine > 0 )
       
  1131         {
       
  1132         iTextViewer->FocusLineL( attachmentTextLine, EFalse );
       
  1133         iViewerRichText->SetHotspotByIndexL( iViewerRichText->AttachmentHotSpotIndex() );
       
  1134         }
       
  1135     else if ( viewHtmlTextLine > 0 )
       
  1136         {
       
  1137         iTextViewer->FocusLineL( viewHtmlTextLine, EFalse );
       
  1138         iViewerRichText->SetHotspotByIndexL( iViewerRichText->ViewHtmlHotSpotIndex() );
       
  1139         }
       
  1140     SetActionMenuIconVisbilityL();
       
  1141 
       
  1142     // Set initial value for downloaded status for one attachment case
       
  1143     iShowMskDownloadOption = ShowMskDownloadOptionL();
       
  1144     SetMskL();
       
  1145 
       
  1146     // check if we know whole message, starts fetching if structure is unknown
       
  1147     // or body doesn't found
       
  1148     CheckMessageStructureL();
       
  1149     }
       
  1150 
       
  1151 // -----------------------------------------------------------------------------
       
  1152 // CFSEmailUiMailViewerVisualiser::CheckMessageStructureL
       
  1153 // Starts fetching message structure if it is unknown.
       
  1154 // If the structure is known but message body is not fetched yet, start fetching it.
       
  1155 // -----------------------------------------------------------------------------
       
  1156 void CFSEmailUiMailViewerVisualiser::CheckMessageStructureL()
       
  1157     {
       
  1158     FUNC_LOG;
       
  1159     if ( iFirstStartCompleted && iMessage )
       
  1160         {
       
  1161         if ( !MessageStructureKnown( *iMessage ) )
       
  1162             { // fetch structure
       
  1163             StartWaitedFetchingL( EMessageStructure );
       
  1164             }
       
  1165         else if ( StartFetchingBodyAfterOpeningL() )
       
  1166             {
       
  1167             iViewerRichText->AppendFetchingMoreTextL();
       
  1168             StartFetchingMessagePartL( *iMessage, EMessagePlainTextBodyPart );
       
  1169             iFetchingAnimationTimer->Start( KAnimationRefreshTimeIntervalInMilliseconds );
       
  1170             }
       
  1171         }
       
  1172     }
       
  1173 
       
  1174 // -----------------------------------------------------------------------------
       
  1175 // CFSEmailUiMailViewerVisualiser::UpdateDownloadIndicatorL
       
  1176 // Show or hide download progress indicator popup and update its contents if
       
  1177 // necessary.
       
  1178 // -----------------------------------------------------------------------------
       
  1179 void CFSEmailUiMailViewerVisualiser::UpdateDownloadIndicatorL( TFSProgress::TFSProgressStatus aStatus
       
  1180                                                                /*= TFSProgress::EFSStatus_Waiting*/ )
       
  1181     {
       
  1182     FUNC_LOG;
       
  1183     if ( iFirstStartCompleted && iMessage && iTextViewer ) // Safety
       
  1184         {
       
  1185         TFSMailMsgId messId = iMessage->GetMessageId();
       
  1186         HBufC* progressString = NULL;
       
  1187         if ( iAppUi.DownloadInfoMediator() && iAppUi.DownloadInfoMediator()->IsAnyAttachmentDownloads( messId ) )
       
  1188             {
       
  1189             TInt percentage = iAppUi.DownloadInfoMediator()->GetDownloadPercentageL( messId );
       
  1190             progressString = StringLoader::LoadLC( R_FSE_VIEWER_ATTACHMENTS_LIST_DOWNLOADING,
       
  1191                                                           percentage );
       
  1192             }
       
  1193         else if ( aStatus == TFSProgress::EFSStatus_RequestComplete )
       
  1194             {
       
  1195             progressString = StringLoader::LoadLC( R_FSE_VIEWER_ATTACHMENTS_LIST_DOWNLOADED_100 );
       
  1196             }
       
  1197         else if ( aStatus == TFSProgress::EFSStatus_RequestCancelled )
       
  1198             {
       
  1199             progressString = StringLoader::LoadLC( R_FSE_VIEWER_ATTACHMENTS_LIST_DOWNLOADING_CANCELLED );
       
  1200             }
       
  1201         else
       
  1202             {
       
  1203             progressString = KNullDesC().AllocLC();
       
  1204             }
       
  1205 
       
  1206         if ( progressString->Length() )
       
  1207             {
       
  1208             if ( iDownloadProgressIndicator->IsVisible() )
       
  1209                 {
       
  1210                 // pop-up already visible, just reset the text
       
  1211                 iDownloadProgressIndicator->SetContentsL( progressString );
       
  1212                 }
       
  1213             else
       
  1214                 {
       
  1215                 // pop-up should be launched
       
  1216 
       
  1217                 // Create fetching status layout first to ensure there's empty space in the end of the message
       
  1218                 iViewerRichText->CreateStatusLayoutL();
       
  1219 
       
  1220                 iDownloadProgressIndicator->ShowIndicatorL( CFSEmailUiStatusIndicator::EIndicationDownloadProgress,
       
  1221                                                             progressString,
       
  1222                                                             CFSEmailUiStatusIndicator::EIndicationNoAutomaticHiding );
       
  1223                 iShowMskDownloadOption = EFalse;
       
  1224                 }
       
  1225             }
       
  1226         CleanupStack::PopAndDestroy( progressString );
       
  1227 
       
  1228         // Hide the progress popup after small delay if the download was completed or cancelled
       
  1229         if ( iAppUi.DownloadInfoMediator() && !iAppUi.DownloadInfoMediator()->IsAnyAttachmentDownloads( messId ) &&
       
  1230              iDownloadProgressIndicator->IsVisible() )
       
  1231             {
       
  1232             iShowMskDownloadOption = ShowMskDownloadOptionL();
       
  1233             iDownloadProgressIndicator->HideIndicator( KDownloadProgreeNoteHideDelay );
       
  1234             }
       
  1235         }
       
  1236     }
       
  1237 
       
  1238 // -----------------------------------------------------------------------------
       
  1239 // CFSEmailUiMailViewerVisualiser::DynInitMenuPaneL
       
  1240 // For dynamically dimm/undimm menu options according to currect message and focus in the viewer
       
  1241 // -----------------------------------------------------------------------------
       
  1242 void CFSEmailUiMailViewerVisualiser::DynInitMenuPaneL(
       
  1243     TInt aResourceId, CEikMenuPane* aMenuPane )
       
  1244     {
       
  1245     FUNC_LOG;
       
  1246     if ( !iMessage || !iTextViewer )
       
  1247         {
       
  1248         User::Leave( KErrNotReady );
       
  1249         }
       
  1250 
       
  1251     if ( aResourceId == R_FSEMAILUI_MAILVIEWER_MENUPANE )
       
  1252         {
       
  1253         
       
  1254         if ( FeatureManager::FeatureSupported( KFeatureIdFfCmailIntegration ) )
       
  1255            {
       
  1256            // remove help support in pf5250
       
  1257            aMenuPane->SetItemDimmed( EFsEmailUiCmdHelp, ETrue);      
       
  1258            }
       
  1259         
       
  1260         // Folder independent options
       
  1261 
       
  1262         // hide/show MessageReader
       
  1263         TBool hideMessageReader = iEmbeddedMessageMode || !iAppUi.MessageReaderSupportsFreestyle();
       
  1264         aMenuPane->SetItemDimmed( EFsEmailUiCmdReadEmail, hideMessageReader );
       
  1265 
       
  1266         // hide/show actions sub menu
       
  1267         TBool hideActions = !ShowActionsMenuInOptionsL();
       
  1268         aMenuPane->SetItemDimmed( EFsEmailUiCmdMailActions, hideActions );
       
  1269 
       
  1270         // hide/show next and previous message options
       
  1271         TBool hideNext = !ShowNextMessageMenuInOptions();
       
  1272         aMenuPane->SetItemDimmed( EFsEmailUiCmdNextMessage, hideNext );
       
  1273         TBool hidePrev = !ShowPreviousMessageMenuInOptions();
       
  1274         aMenuPane->SetItemDimmed( EFsEmailUiCmdPreviousMessage, hidePrev );
       
  1275 
       
  1276         // hide/show copy to clipboard
       
  1277         TBool hideCopyToClipBoard = !IsCopyToClipBoardAvailableL();
       
  1278         aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsCopyToClipboard, hideCopyToClipBoard );
       
  1279 
       
  1280 
       
  1281         // Folder dependent options
       
  1282         TFSMailMsgId currentMessageFolderId = iMessage->GetFolderId();
       
  1283         CFSMailFolder* currentFolder = NULL;
       
  1284         if ( !iEmbeddedMessageMode )
       
  1285             {
       
  1286             TRAP_IGNORE( currentFolder = iAppUi.GetMailClient()->GetFolderByUidL(
       
  1287                     iMessage->GetMailBoxId(), currentMessageFolderId ) );
       
  1288             }
       
  1289         CleanupStack::PushL( currentFolder );
       
  1290         if ( !currentFolder || currentFolder->GetFolderType() == EFSOutbox )
       
  1291             { // outbox folder or embedded message
       
  1292             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsForward, ETrue );
       
  1293             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsReply, ETrue );
       
  1294             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsReplyAll, ETrue );
       
  1295             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsForward2, ETrue );
       
  1296             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsMoveToDrafts, !currentFolder );
       
  1297             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsDelete, !currentFolder );
       
  1298             }
       
  1299         else
       
  1300             { // other folders
       
  1301             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsMoveToDrafts, ETrue );
       
  1302 
       
  1303             // hide reply all if there's no multiple recipients
       
  1304             TInt numRecipients(0);
       
  1305             if ( iMessage )
       
  1306                 {
       
  1307                 //Get # of recipients
       
  1308                 numRecipients =TFsEmailUiUtility::CountRecepients( iMessage );
       
  1309                 if ( numRecipients == 1 )
       
  1310                     {
       
  1311                     //check if the malbox ownmailaddress is same as the recipients email address. If not, then assume that the
       
  1312                     //email is a distribution list and we need to inc num of Recipients so that "Reply ALL" option appears in UI.
       
  1313                     if ( iMessage->GetToRecipients().Count() )
       
  1314                         {
       
  1315                         if ( iMailBox->OwnMailAddress().GetEmailAddress().Compare(iMessage->GetToRecipients()[0]->GetEmailAddress()) )
       
  1316                             {
       
  1317                             numRecipients++;
       
  1318                             }
       
  1319                         }
       
  1320                     if ( iMessage->GetCCRecipients().Count() )
       
  1321                         {
       
  1322                         if ( iMailBox->OwnMailAddress().GetEmailAddress().Compare(iMessage->GetCCRecipients()[0]->GetEmailAddress()) )
       
  1323                             {
       
  1324                             numRecipients++;
       
  1325                             }
       
  1326                         }
       
  1327                     if( iMessage->GetBCCRecipients().Count() )
       
  1328                         {
       
  1329                         if( iMailBox->OwnMailAddress().GetEmailAddress().Compare(iMessage->GetBCCRecipients()[0]->GetEmailAddress()) )
       
  1330                             {
       
  1331                             numRecipients++;
       
  1332                             }
       
  1333                         }
       
  1334                     }
       
  1335                 }
       
  1336 
       
  1337             TBool hideReplyAll = ( numRecipients <= 1 );
       
  1338             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsReplyAll, hideReplyAll );
       
  1339 
       
  1340             // In Sent folder, option forward is shown above options reply and reply all
       
  1341             TBool forwardAboveReply = ( currentFolder->GetFolderType() == EFSSentFolder );
       
  1342             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsForward, !forwardAboveReply );
       
  1343             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsForward2, forwardAboveReply );
       
  1344             }
       
  1345         CleanupStack::PopAndDestroy( currentFolder );
       
  1346         }
       
  1347 
       
  1348     if ( aResourceId == R_FSEMAILUI_MAILVIEWER_SUBMENU_MORE )
       
  1349         {
       
  1350         TFSMailMsgId currentMessageFolderId = iMessage->GetFolderId();
       
  1351         CFSMailFolder* currentFolder = NULL;
       
  1352         if ( !iEmbeddedMessageMode )
       
  1353             {
       
  1354             TRAP_IGNORE( currentFolder = iAppUi.GetMailClient()->GetFolderByUidL(
       
  1355                     iMessage->GetMailBoxId(), currentMessageFolderId ) );
       
  1356             }
       
  1357         CleanupStack::PushL( currentFolder );
       
  1358         if ( !currentFolder || currentFolder->GetFolderType() == EFSOutbox )
       
  1359             {  // outbox folder or embedded message
       
  1360             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, ETrue );
       
  1361             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsRead, ETrue );
       
  1362             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsMoveMessage, ETrue );
       
  1363             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsFlag, ETrue );
       
  1364 // <cmail> Prevent Download Manager opening with attachments
       
  1365 //          aMenuPane->SetItemDimmed( EFsEmailUiCmdDownloadManager, ETrue );
       
  1366 // </cmail> Prevent Download Manager opening with attachments
       
  1367             }
       
  1368         else // other folders
       
  1369             {
       
  1370             // show read/unread according to current state
       
  1371             TBool messageIsRead = iMessage->IsFlagSet( EFSMsgFlag_Read );
       
  1372             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsRead, messageIsRead );
       
  1373             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, !messageIsRead );
       
  1374 
       
  1375             // show/hide move message
       
  1376             TBool hideMove = !iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaMoveToFolder );
       
  1377             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsMoveMessage, hideMove );
       
  1378 
       
  1379             // show/hide flag for followup
       
  1380             TBool hideFlag = !TFsEmailUiUtility::IsFollowUpSupported( *iMailBox );
       
  1381             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsFlag, hideFlag );
       
  1382 
       
  1383             // hide/show download manager option
       
  1384 // <cmail> Prevent Download Manager opening with attachments
       
  1385 //          TBool hideDownloadMan = !ShowDownloadManagerMenuInOptions();
       
  1386 //          aMenuPane->SetItemDimmed( EFsEmailUiCmdDownloadManager, hideDownloadMan );
       
  1387 // </cmail>
       
  1388             }
       
  1389         CleanupStack::PopAndDestroy( currentFolder );
       
  1390         }
       
  1391 
       
  1392     if ( aResourceId == R_FSEMAILUI_MAILVIEWER_SUBMENU_ACTIONS )
       
  1393         {
       
  1394         // All menu items are hidden by default.
       
  1395         // Undimm items that should be visible in action menu.
       
  1396         SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  1397         CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  1398         THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL(
       
  1399             currentHeaderHotSpotData, currentBodyHotSpotData );
       
  1400 
       
  1401         TBool remoteLookupAvailable =
       
  1402             TFsEmailUiUtility::IsRemoteLookupSupported( *iMailBox );
       
  1403 
       
  1404         if ( ( hotspotType == EHeaderHotspot && (
       
  1405             currentHeaderHotSpotData.iType == ETypeFromAddressDisplayName ||
       
  1406             currentHeaderHotSpotData.iType == ETypeToAddressDisplayName ||
       
  1407             currentHeaderHotSpotData.iType == ETypeCcAddressDisplayName ||
       
  1408             currentHeaderHotSpotData.iType == ETypeBccAddressDisplayName ||
       
  1409             currentHeaderHotSpotData.iType == ETypeEmailAddress )  )
       
  1410             ||
       
  1411             ( hotspotType == EBodyHotspot &&
       
  1412               currentBodyHotSpotData.iItemType ==
       
  1413                 CFindItemEngine::EFindItemSearchMailAddressBin ) )
       
  1414             {
       
  1415             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsCall, EFalse );
       
  1416             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsCreateMessage, EFalse );
       
  1417             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsCreateMail, EFalse );
       
  1418             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsContactDetails, EFalse );
       
  1419             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsAddContact2, EFalse );
       
  1420             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsRemoteLookup, !remoteLookupAvailable );
       
  1421             }
       
  1422         else if ( hotspotType == EHeaderHotspot &&
       
  1423                   currentHeaderHotSpotData.iType == ETypeAttachment )
       
  1424             {
       
  1425             TBool hideOpen = !ShowOpenAttachmentOptionL();
       
  1426             aMenuPane->SetItemDimmed( EFsEmailUiCmdOpenAttachment, hideOpen );
       
  1427             TBool hideDownload = !ShowDownloadOptionL();
       
  1428             aMenuPane->SetItemDimmed( EFsEmailUiCmdDownload, hideDownload );
       
  1429             TBool hideCancel = !ShowCancelDownloadOption();
       
  1430             aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelDownload, hideCancel );
       
  1431             TBool hideSave = !ShowSaveAttachmentOptionL();
       
  1432             aMenuPane->SetItemDimmed( EFsEmailUiCmdSave, hideSave );
       
  1433 
       
  1434             TBool hideRemove = hideOpen;
       
  1435             aMenuPane->SetItemDimmed( EFsEmailUiCmdClearFetchedAttachment, hideRemove );
       
  1436             }
       
  1437         else if ( hotspotType == EHeaderHotspot &&
       
  1438                   currentHeaderHotSpotData.iType == ETypeAttachments )
       
  1439             {
       
  1440             TBool hideOpen = !ShowOpenAttachmentOptionL();
       
  1441             aMenuPane->SetItemDimmed( EFsEmailUiCmdOpenAttachmentList, hideOpen );
       
  1442             TBool hideDownload = !ShowDownloadOptionL();
       
  1443             aMenuPane->SetItemDimmed( EFsEmailUiCmdDownloadAll, hideDownload );
       
  1444             TBool hideCancel = !ShowCancelDownloadOption();
       
  1445             aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelAllDownloads, hideCancel );
       
  1446             TBool hideSave = !ShowSaveAttachmentOptionL();
       
  1447             aMenuPane->SetItemDimmed( EFsEmailUiCmdSaveAll, hideSave );
       
  1448             }
       
  1449         else if ( hotspotType == EBodyHotspot &&
       
  1450                   currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
  1451             {
       
  1452             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsCall, EFalse );
       
  1453             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsAddContact, EFalse );
       
  1454             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsCreateMessage, EFalse );
       
  1455             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsRemoteLookup, !remoteLookupAvailable );
       
  1456             }
       
  1457         else if ( hotspotType == EBodyHotspot &&
       
  1458                   ( currentBodyHotSpotData.iItemType ==
       
  1459                     CFindItemEngine::EFindItemSearchURLBin ||
       
  1460                     currentBodyHotSpotData.iItemType ==
       
  1461                     CFindItemEngine::EFindItemSearchScheme ) )
       
  1462             {
       
  1463             // Handle action menu for different search scheme, e.g mailto: and call:
       
  1464             TInt schemaLinkType = ResolveBodyTextSchemaUrlTypeL( currentBodyHotSpotData );
       
  1465             switch ( schemaLinkType )
       
  1466                 {
       
  1467                 case EFocusOnEMailInBodyText:
       
  1468                     {
       
  1469                     aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsCall, EFalse );
       
  1470                     aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsCreateMessage, EFalse );
       
  1471                     aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsContactDetails, EFalse );
       
  1472                     aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsAddContact2, EFalse );
       
  1473                     aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsRemoteLookup, !remoteLookupAvailable );
       
  1474                     }
       
  1475                     break;
       
  1476                 case EFocusOnNumberWithinMessage:
       
  1477                     {
       
  1478                     aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsCall, EFalse );
       
  1479                     aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsAddContact, EFalse );
       
  1480                     // Drop out "Create message" selection for SIP addresses
       
  1481                     HBufC* schemeText = iViewerRichText->GetHotspotTextLC( currentBodyHotSpotData );
       
  1482                     if ( schemeText && schemeText->FindC( KVoipPrefix ) != 0 )
       
  1483                         {
       
  1484                         aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsCreateMessage, EFalse );
       
  1485                         }
       
  1486                     CleanupStack::PopAndDestroy( schemeText );
       
  1487                     aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsRemoteLookup, !remoteLookupAvailable );
       
  1488                     }
       
  1489                     break;
       
  1490                 default:
       
  1491                     {
       
  1492                     aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsOpenWeb, EFalse );
       
  1493 
       
  1494                     // Handle intranet browsing item by using AIW service
       
  1495                     // handler's InitializeMenuPaneL-function, it will remove
       
  1496                     // the IB menu item if IB is not available, or make the
       
  1497                     // item visible if IB is available
       
  1498                     if ( iIBServiceHandler && iIBServiceHandler->IsAiwMenu( aResourceId ) )
       
  1499                         {
       
  1500                         TAiwGenericParam param( EGenericParamURL );
       
  1501                         CAiwGenericParamList* list = CAiwGenericParamList::NewLC();
       
  1502                         list->AppendL( param );
       
  1503                         iIBServiceHandler->InitializeMenuPaneL( *aMenuPane, aResourceId,
       
  1504                                 EFsEmailUiCmdActionsOpenInIntranetMenu, *list, ETrue );
       
  1505                         CleanupStack::PopAndDestroy( list );
       
  1506                         }
       
  1507 
       
  1508                     aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsAddBookmark, EFalse );
       
  1509                     }
       
  1510                     break;
       
  1511                 }
       
  1512             }
       
  1513         }
       
  1514 
       
  1515     iAppUi.ShortcutBinding().AppendShortcutHintsL( *aMenuPane,
       
  1516         CFSEmailUiShortcutBinding::EContextMailViewer );
       
  1517     }
       
  1518 
       
  1519 
       
  1520 // -----------------------------------------------------------------------------
       
  1521 // CFSEmailUiMailViewerVisualiser::HandleCommandL
       
  1522 // Handles menu selections
       
  1523 // -----------------------------------------------------------------------------
       
  1524 void CFSEmailUiMailViewerVisualiser::HandleCommandL( TInt aCommand )
       
  1525     {
       
  1526     FUNC_LOG;
       
  1527     if ( !iAppUi.ViewSwitchingOngoing() )
       
  1528         {
       
  1529         switch ( aCommand )
       
  1530             {
       
  1531             case EAknSoftkeyBack:
       
  1532                 {
       
  1533                 // Set empty MSK when navigating back
       
  1534                 ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
  1535                 // Cancel MR viewer launching if Back is pressed in the middle
       
  1536                 // of launching process.
       
  1537                 CancelPendingMrCommandL();
       
  1538                 NavigateBackL();
       
  1539                 }
       
  1540                 break;
       
  1541             // top level options
       
  1542             case EFsEmailUiCmdActionsMoveToDrafts:
       
  1543                 {
       
  1544                 TFsEmailUiUtility::MoveMessageToDraftsL(
       
  1545                     *iAppUi.GetActiveMailbox(), *iMessage );
       
  1546                 }
       
  1547                 break;
       
  1548             case EFsEmailUiCmdCalActionsReplyAsMail:
       
  1549             case EFsEmailUiCmdActionsReply:
       
  1550                 {
       
  1551                 if ( !iEmbeddedMessageMode )
       
  1552                     {
       
  1553                     TEditorLaunchParams params;
       
  1554                     params.iMailboxId = iAppUi.GetActiveMailboxId();
       
  1555                     params.iMsgId = iMessage->GetMessageId();
       
  1556                     params.iActivatedExternally = EFalse;
       
  1557                     iAppUi.LaunchEditorL( KEditorCmdReply, params );
       
  1558                     }
       
  1559                 }
       
  1560                 break;
       
  1561             case EFsEmailUiCmdActionsReplyAll:
       
  1562                 {
       
  1563                 if ( !iEmbeddedMessageMode )
       
  1564                     {
       
  1565                     TEditorLaunchParams params;
       
  1566                     params.iMailboxId = iAppUi.GetActiveMailboxId();
       
  1567                     params.iMsgId = iMessage->GetMessageId();
       
  1568                     params.iActivatedExternally = EFalse;
       
  1569                     iAppUi.LaunchEditorL( KEditorCmdReplyAll, params );
       
  1570                     }
       
  1571                 }
       
  1572                 break;
       
  1573             case EFsEmailUiCmdCalActionsForwardAsMail:
       
  1574             case EFsEmailUiCmdActionsForward:
       
  1575             case EFsEmailUiCmdActionsForward2:
       
  1576                 {
       
  1577                 if ( !iEmbeddedMessageMode )
       
  1578                     {
       
  1579                     TEditorLaunchParams params;
       
  1580                     params.iMailboxId = iAppUi.GetActiveMailboxId();
       
  1581                     params.iMsgId = iMessage->GetMessageId();
       
  1582                     params.iActivatedExternally = EFalse;
       
  1583                     iAppUi.LaunchEditorL( KEditorCmdForward, params );
       
  1584                     }
       
  1585                 }
       
  1586                 break;
       
  1587             case EFsEmailUiCmdActionsDelete:
       
  1588                 {
       
  1589                 DeleteMailL( *iMessage, ETrue );
       
  1590                 }
       
  1591                 break;
       
  1592             case EFsEmailUiCmdActionsCopyToClipboard:
       
  1593                 {
       
  1594                 CopyCurrentHotspotToClipBoardL();
       
  1595                 }
       
  1596                 break;
       
  1597             case EFsEmailUiCmdPreviousMessage:
       
  1598                 {
       
  1599                 ShowPreviousMessageL();
       
  1600                 }
       
  1601                 break;
       
  1602             case EFsEmailUiCmdNextMessage:
       
  1603                 {
       
  1604                 ShowNextMessageL();
       
  1605                 }
       
  1606                 break;
       
  1607             case EFsEmailUiCmdHelp:
       
  1608                 {
       
  1609                 TFsEmailUiUtility::LaunchHelpL( KFSE_HLP_LAUNCHER_GRID );
       
  1610                 }
       
  1611                 break;
       
  1612             case EFsEmailUiCmdExit:
       
  1613                 {
       
  1614                 iAppUi.Exit();
       
  1615                 }
       
  1616                 break;
       
  1617             case EFsEmailUiCmdReadEmail:
       
  1618                 {
       
  1619                 iAppUi.StartReadingEmailsL();
       
  1620                 }
       
  1621                 break;
       
  1622 
       
  1623             // "actions" -sub menu options
       
  1624             case EFsEmailUiCmdActionsCall:
       
  1625                 {
       
  1626                 CallHotSpotAddressL();
       
  1627                 }
       
  1628                 break;
       
  1629             case EFsEmailUiCmdActionsCreateMessage:
       
  1630                 {
       
  1631                 CreateMessageL();
       
  1632                 }
       
  1633                 break;
       
  1634             case EFsEmailUiCmdActionsCreateMail:
       
  1635                 {
       
  1636                 ComposeMailL();
       
  1637                 }
       
  1638                 break;
       
  1639             case EFsEmailUiCmdActionsContactDetails:
       
  1640                 {
       
  1641                 OpenContactDetailsL();
       
  1642                 }
       
  1643                 break;
       
  1644             case EFsEmailUiCmdActionsAddContact:
       
  1645             case EFsEmailUiCmdActionsAddContact2:
       
  1646                 {
       
  1647                 SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  1648                 CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  1649                 THotspotType hotspotType =
       
  1650                     iViewerRichText->FindCurrentHotSpotL(
       
  1651                         currentHeaderHotSpotData, currentBodyHotSpotData );
       
  1652                 if ( hotspotType == EHeaderHotspot )
       
  1653                     {
       
  1654                     HBufC* emailAddress =
       
  1655                         iViewerRichText->GetHeaderHotspotEmailAddressLC(
       
  1656                             currentHeaderHotSpotData );
       
  1657                     SaveEmailAsContactL( *emailAddress );
       
  1658                     CleanupStack::PopAndDestroy( emailAddress );
       
  1659                     }
       
  1660                 else if ( hotspotType == EBodyHotspot )
       
  1661                     {
       
  1662                     HBufC* hotspotText = iViewerRichText->GetHotspotTextLC(
       
  1663                         currentBodyHotSpotData );
       
  1664                     if ( currentBodyHotSpotData.iItemType ==
       
  1665                         CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
  1666                         {
       
  1667                         SavePhoneNumberAsContactL( *hotspotText );
       
  1668                         }
       
  1669                     else if ( currentBodyHotSpotData.iItemType ==
       
  1670                         CFindItemEngine::EFindItemSearchMailAddressBin )
       
  1671                         {
       
  1672                         SaveEmailAsContactL( *hotspotText );
       
  1673                         }
       
  1674                     else if ( currentBodyHotSpotData.iItemType ==
       
  1675                             CFindItemEngine::EFindItemSearchScheme)
       
  1676                         {
       
  1677                         if ( hotspotText->FindC( KMailtoPrefix ) == 0 )
       
  1678                             {
       
  1679                             // Save email address, prefix is stripped in SaveEmailAsContactL
       
  1680                             SaveEmailAsContactL( *hotspotText );
       
  1681                             }
       
  1682                         else if ( hotspotText->FindC( KCallPrefix ) == 0 ||
       
  1683                                   hotspotText->FindC( KTelPrefix ) == 0  ||
       
  1684                                   hotspotText->FindC( KSmsPrefix ) == 0 ||
       
  1685                                   hotspotText->FindC( KMmsPrefix ) == 0 )
       
  1686                             {
       
  1687                             // Save phone nukmber, prefix is stripped in SavePhoneNumberAsContactL
       
  1688                             SavePhoneNumberAsContactL( *hotspotText );
       
  1689                             }
       
  1690                         }
       
  1691                     CleanupStack::PopAndDestroy( hotspotText );
       
  1692                     }
       
  1693                 }
       
  1694                 break;
       
  1695             case EFsEmailUiCmdActionsRemoteLookup:
       
  1696                 {
       
  1697                 SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  1698                 CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  1699                 THotspotType hotspotType =
       
  1700                     iViewerRichText->FindCurrentHotSpotL(
       
  1701                         currentHeaderHotSpotData, currentBodyHotSpotData );
       
  1702                 if ( hotspotType == EHeaderHotspot )
       
  1703                     {
       
  1704                     HBufC* emailAddress =
       
  1705                         iViewerRichText->GetHeaderHotspotEmailAddressLC(
       
  1706                             currentHeaderHotSpotData );
       
  1707                     LaunchRemoteLookupL( *emailAddress );
       
  1708                     CleanupStack::PopAndDestroy( emailAddress );
       
  1709                     }
       
  1710                 else if ( hotspotType == EBodyHotspot )
       
  1711                     {
       
  1712                     HBufC* hotspotText = iViewerRichText->GetHotspotTextLC(
       
  1713                         currentBodyHotSpotData );
       
  1714                     LaunchRemoteLookupL( *hotspotText );
       
  1715                     CleanupStack::PopAndDestroy( hotspotText );
       
  1716                     }
       
  1717                 }
       
  1718                 break;
       
  1719             case EFsEmailUiCmdActionsOpenHtmlViewer:
       
  1720                 {
       
  1721                 LaunchHtmlViewerL();
       
  1722                 }
       
  1723                 break;
       
  1724             case EFsEmailUiCmdActionsOpenWeb:
       
  1725                 {
       
  1726                 CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  1727                 TBool bodyHotSpotFound =
       
  1728                     iViewerRichText->FindCurrentBodyHotSpotL(
       
  1729                         currentBodyHotSpotData );
       
  1730                 OpenHotSpotUrlInBrowserL( currentBodyHotSpotData );
       
  1731                 }
       
  1732                 break;
       
  1733             case EFsEmailUiCmdActionsOpenInIntranetMenu:
       
  1734                 {
       
  1735                 OpenLinkInIntranetL( ETrue );
       
  1736                 }
       
  1737                 break;
       
  1738             case EFsEmailUiCmdActionsAddBookmark:
       
  1739                 {
       
  1740                 CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  1741                 TBool bodyHotSpotFound =
       
  1742                     iViewerRichText->FindCurrentBodyHotSpotL(
       
  1743                         currentBodyHotSpotData );
       
  1744                 AddToBookmarksL( currentBodyHotSpotData );
       
  1745                 }
       
  1746                 break;
       
  1747             case EAknSoftkeyOpen:
       
  1748             case EFsEmailUiCmdOpenAttachment:
       
  1749                 {
       
  1750                 OpenAttachmentL();
       
  1751                 }
       
  1752                 break;
       
  1753             case EFsEmailUiCmdOpenAttachmentList:
       
  1754                 {
       
  1755                 OpenAttachmentsViewL();
       
  1756                 }
       
  1757                 break;
       
  1758             case EFsEmailUiCmdDownload:
       
  1759             case EFsEmailUiCmdDownloadAll:
       
  1760                 {
       
  1761                 StartDowloadingAttachmentsL();
       
  1762                 }
       
  1763                 break;
       
  1764             case EFsEmailUiCmdCancelDownload:
       
  1765             case EFsEmailUiCmdCancelAllDownloads:
       
  1766                 {
       
  1767                 CancelDowloadingAttachmentsL();
       
  1768                 }
       
  1769                 break;
       
  1770             case EFsEmailUiCmdSave:
       
  1771             case EFsEmailUiCmdSaveAll:
       
  1772                 {
       
  1773                 SaveAllAttachmentsL();
       
  1774                 }
       
  1775                 break;
       
  1776             case EFsEmailUiCmdClearFetchedAttachment:
       
  1777                 {
       
  1778                 RemoveFetchedAttachmentL();
       
  1779                 }
       
  1780                 break;
       
  1781 
       
  1782             // "more" -sub menu options
       
  1783             case EFsEmailUiCmdMarkAsUnread:
       
  1784                 {
       
  1785                 ChangeMsgReadStatusL( EFalse, EFalse );
       
  1786                 }
       
  1787                 break;
       
  1788             case EFsEmailUiCmdMarkAsRead:
       
  1789                 {
       
  1790                 ChangeMsgReadStatusL( ETrue, EFalse );
       
  1791                 }
       
  1792                 break;
       
  1793             case EFsEmailUiCmdActionsMoveMessage:
       
  1794                 {
       
  1795                 OpenFolderListForMessageMovingL();
       
  1796                 }
       
  1797                 break;
       
  1798             case EFsEmailUiCmdActionsFlag:
       
  1799                 {
       
  1800                 SetMessageFollowupFlagL();
       
  1801                 }
       
  1802                 break;
       
  1803             case EFsEmailUiCmdCompose:
       
  1804                 {
       
  1805                 iAppUi.CreateNewMailL();
       
  1806                 }
       
  1807                 break;
       
  1808             case EFsEmailUiCmdComposeTo:
       
  1809                 {
       
  1810                 ComposeMailL();
       
  1811                 }
       
  1812                 break;
       
  1813             case EFsEmailUiCmdMessageDetails:
       
  1814             case EFsEmailUiCmdViewAll:
       
  1815                 {
       
  1816                 TUid activationCmdId = KStartMsgDetailsToBeginning;
       
  1817                 if ( aCommand == EFsEmailUiCmdViewAll )
       
  1818                     {
       
  1819                     SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  1820                     iViewerRichText->FindCurrentHeaderHotSpotL( currentHeaderHotSpotData );
       
  1821                     if( currentHeaderHotSpotData.iType == ETypeToNMoreRecipients )
       
  1822                         {
       
  1823                         activationCmdId = KStartMsgDetailsToTo;
       
  1824                         }
       
  1825                     else if( currentHeaderHotSpotData.iType == ETypeCcNMoreRecipients )
       
  1826                         {
       
  1827                         activationCmdId = KStartMsgDetailsToCc;
       
  1828                         }
       
  1829                     else if( currentHeaderHotSpotData.iType == ETypeBccNMoreRecipients )
       
  1830                         {
       
  1831                         activationCmdId = KStartMsgDetailsToBcc;
       
  1832                         }
       
  1833                     }
       
  1834 
       
  1835                 TMsgDetailsActivationData msgDetailsData;
       
  1836                 msgDetailsData.iMailBoxId = iMessage->GetMailBoxId();
       
  1837                 msgDetailsData.iFolderId = iMessage->GetFolderId();
       
  1838                 msgDetailsData.iMessageId = iMessage->GetMessageId();
       
  1839                 const TPckgBuf<TMsgDetailsActivationData> pkgOut( msgDetailsData );
       
  1840                 iAppUi.EnterFsEmailViewL(
       
  1841                     MsgDetailsViewId, activationCmdId,  pkgOut );
       
  1842                 }
       
  1843                 break;
       
  1844 // <cmail> Prevent Download Manager opening with attachments
       
  1845 //          case EFsEmailUiCmdDownloadManager:
       
  1846 //              {
       
  1847 //              iAppUi.EnterFsEmailViewL( DownloadManagerViewId );
       
  1848 //              }
       
  1849 //              break;
       
  1850 // </cmail>
       
  1851             case EFsEmailUiCmdMarkAsReadUnreadToggle:
       
  1852                 {
       
  1853                 if ( iMessage && !iEmbeddedMessageMode )
       
  1854                     {
       
  1855                     if ( iMessage->IsFlagSet( EFSMsgFlag_Read ) )
       
  1856                         {
       
  1857                         HandleCommandL( EFsEmailUiCmdMarkAsUnread );
       
  1858                         }
       
  1859                     else
       
  1860                         {
       
  1861                         HandleCommandL( EFsEmailUiCmdMarkAsRead );
       
  1862                         }
       
  1863                     }
       
  1864                 }
       
  1865                 break;
       
  1866 
       
  1867             // Moving to top or to bottom of the text. Zero seems to be
       
  1868             // treated as illegal value in FocusLineL (it is skipped),
       
  1869             // so assuming that line range is [1, total lines count].
       
  1870             // It is not documented anywhere though.
       
  1871             case EFsEmailUiCmdGoToTop:
       
  1872                 {
       
  1873                 // <cmail>
       
  1874                 // Do nothing if focus is already in top
       
  1875                 if ( iTextViewer->GetFirstDisplayedLine() > 1 )
       
  1876                     {
       
  1877                     iTextViewer->FocusLineL( 1 );
       
  1878                     }
       
  1879                 }
       
  1880                 // </cmail>
       
  1881                 break;
       
  1882             case EFsEmailUiCmdGoToBottom:
       
  1883                 {
       
  1884                 iTextViewer->FocusLineL( iTextViewer->GetTotalLines() );
       
  1885                 }
       
  1886                 break;
       
  1887 
       
  1888             // The Generic text viewer API supports setting only one key for scroll up
       
  1889             // and one key for scroll down. To have multiple scroll up/down keys,
       
  1890             // we have set artificial keys for the generic viewer and simulate those
       
  1891             // when one of the shortcut keys is pressed.
       
  1892             // Another reason to use these artificial keys is that the TextViewer identifies
       
  1893             // keys by iCodes. This doesn't fit our concept at least in product where iCode
       
  1894             // of certain keys contains the value of the character found behind Fn on that key,
       
  1895             // and the Fn mappings vary between variants.
       
  1896             // Similar mechanism is used inside AknFep with key codes EKeyF19...EKeyF24,
       
  1897             // so collisions with these must be avoided.
       
  1898             case EFsEmailUiCmdScrollUp:
       
  1899                 {
       
  1900                 TKeyEvent simEvent = { KKeyCodeArtificialScrollUp, EStdKeyNull, 0, 0 };
       
  1901                 iCoeEnv->SimulateKeyEventL( simEvent, EEventKey );
       
  1902                 }
       
  1903                 break;
       
  1904             case EFsEmailUiCmdScrollDown:
       
  1905                 {
       
  1906                 TKeyEvent simEvent = { KKeyCodeArtificialScrollDown, EStdKeyNull, 0, 0 };
       
  1907                 iCoeEnv->SimulateKeyEventL( simEvent, EEventKey );
       
  1908                 }
       
  1909                 break;
       
  1910             case EFsEmailUiCmdPageUp:
       
  1911                 {
       
  1912                 TKeyEvent simEvent = { EKeyPageUp, EStdKeyNull, 0, 0 };
       
  1913                 iCoeEnv->SimulateKeyEventL( simEvent, EEventKey );
       
  1914                 }
       
  1915                 break;
       
  1916             case EFsEmailUiCmdPageDown:
       
  1917                 {
       
  1918                 TKeyEvent simEvent = { EKeyPageDown, EStdKeyNull, 0, 0 };
       
  1919                 iCoeEnv->SimulateKeyEventL( simEvent, EEventKey );
       
  1920                 // Check if we reached the end of truncated message body
       
  1921                 StartFetchingRemaininBodyLinesIfAtBottomL();
       
  1922                 }
       
  1923                 break;
       
  1924 
       
  1925             default:
       
  1926                 break;
       
  1927             }
       
  1928         }
       
  1929     }
       
  1930 
       
  1931 
       
  1932 void CFSEmailUiMailViewerVisualiser::ComposeMailL()
       
  1933     {
       
  1934     SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  1935     CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  1936     THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL( currentHeaderHotSpotData, currentBodyHotSpotData );
       
  1937     if ( hotspotType == EHeaderHotspot )
       
  1938        {
       
  1939        // Regular email address
       
  1940        if ( currentHeaderHotSpotData.iType == ETypeEmailAddress )
       
  1941            {
       
  1942            HBufC* emailAddress = iViewerRichText->GetHeaderHotspotEmailAddressLC( currentHeaderHotSpotData );
       
  1943            if ( emailAddress && emailAddress->Length() )
       
  1944                {
       
  1945                delete iNewMailTempAddress;
       
  1946                iNewMailTempAddress = NULL;
       
  1947                iNewMailTempAddress = CFSMailAddress::NewL();
       
  1948                iNewMailTempAddress->SetEmailAddress( *emailAddress );
       
  1949                iAppUi.LaunchEditorL( iNewMailTempAddress );
       
  1950                }
       
  1951            CleanupStack::PopAndDestroy( emailAddress );
       
  1952            }
       
  1953        // Sender addr with display name
       
  1954        else if ( currentHeaderHotSpotData.iType == ETypeFromAddressDisplayName )
       
  1955            {
       
  1956            CFSMailAddress* senderAddress = iMessage->GetSender(); // not owned
       
  1957            iAppUi.LaunchEditorL( senderAddress );
       
  1958            }
       
  1959        // To addr with display name
       
  1960        else if ( currentHeaderHotSpotData.iType == ETypeToAddressDisplayName )
       
  1961            {
       
  1962            RPointerArray<CFSMailAddress>& toArray = iMessage->GetToRecipients(); // not owned
       
  1963            CFSMailAddress* toAddress = toArray[ currentHeaderHotSpotData.iDisplayNameArrayIndex ];
       
  1964            iAppUi.LaunchEditorL( toAddress );
       
  1965            }
       
  1966        // CC addr with display name
       
  1967        else if ( currentHeaderHotSpotData.iType == ETypeCcAddressDisplayName )
       
  1968            {
       
  1969            RPointerArray<CFSMailAddress>& ccArray = iMessage->GetCCRecipients(); // not owned
       
  1970            CFSMailAddress* ccAddress = ccArray[ currentHeaderHotSpotData.iDisplayNameArrayIndex ];
       
  1971            iAppUi.LaunchEditorL( ccAddress );
       
  1972            }
       
  1973        // BCC addr with display name
       
  1974        else if ( currentHeaderHotSpotData.iType == ETypeBccAddressDisplayName )
       
  1975            {
       
  1976            RPointerArray<CFSMailAddress>& bccArray = iMessage->GetBCCRecipients(); // not owned
       
  1977            CFSMailAddress* bccAddress = bccArray[ currentHeaderHotSpotData.iDisplayNameArrayIndex ];
       
  1978            iAppUi.LaunchEditorL( bccAddress );
       
  1979            }
       
  1980        }
       
  1981     // Email address hotspot in body text clicked
       
  1982     else if ( hotspotType == EBodyHotspot && ( currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchMailAddressBin ||
       
  1983              currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchScheme ) )
       
  1984        {
       
  1985        WriteEmailToHotSpotAddressL( currentBodyHotSpotData );
       
  1986        }
       
  1987     }
       
  1988 
       
  1989 
       
  1990 
       
  1991 
       
  1992 void CFSEmailUiMailViewerVisualiser::ProcessAsyncCommandL( TESMRIcalViewerOperationType aCommandId,
       
  1993                                                          const CFSMailMessage& aMessage,
       
  1994                                                          MESMRIcalViewerObserver* aObserver )
       
  1995     {
       
  1996     FUNC_LOG;
       
  1997     if ( aObserver )
       
  1998         {
       
  1999         iMrObserverToInform = aObserver;
       
  2000         }
       
  2001     // we must cast constness away from message because of flaws in MRUI API
       
  2002     CFSMailMessage* messagePtr = const_cast<CFSMailMessage*>(&aMessage);
       
  2003     if ( messagePtr )
       
  2004         {
       
  2005         // Fill in result struct
       
  2006         iOpResult.iOpType = aCommandId;
       
  2007         iOpResult.iMessage = messagePtr;
       
  2008         iOpResult.iResultCode = KErrNotFound;
       
  2009 
       
  2010         switch ( aCommandId )
       
  2011             {
       
  2012             case EESMRCmdMailMessageDetails:
       
  2013                 {
       
  2014                 iOpResult.iResultCode = KErrNone;
       
  2015                 TMsgDetailsActivationData msgDetailsData;
       
  2016                 msgDetailsData.iMailBoxId = messagePtr->GetMailBoxId();
       
  2017                 msgDetailsData.iFolderId = messagePtr->GetFolderId();
       
  2018                 msgDetailsData.iMessageId = messagePtr->GetMessageId();
       
  2019                 const TPckgBuf<TMsgDetailsActivationData> pkgOut( msgDetailsData );
       
  2020                 iAppUi.EnterFsEmailViewL( MsgDetailsViewId, KStartMsgDetailsToBeginning,  pkgOut);
       
  2021                 }
       
  2022                 break;
       
  2023             case EESMRCmdMailDelete:
       
  2024                 {
       
  2025                 if ( iMessage )
       
  2026                     {
       
  2027                     iDeletedMessageFromMrui = iMessage->GetMessageId(); //<cmail>
       
  2028                     iOpResult.iResultCode = DeleteMailL( *iMessage, EFalse, ETrue );
       
  2029                     }
       
  2030 
       
  2031                 // Information is returned immediately after delete has completed.
       
  2032                 CompletePendingMrCommand();
       
  2033                 }
       
  2034                 break;
       
  2035             case EESMRCmdMailMoveMessage:
       
  2036                 {
       
  2037                 if ( iMessage )
       
  2038                     {
       
  2039                     if ( OpenFolderListForMessageMovingL() )
       
  2040                         {
       
  2041                         iOpResult.iResultCode = KErrNone;
       
  2042                         iMovingMeetingRequest = ETrue;
       
  2043                         }
       
  2044                     }
       
  2045                 }
       
  2046                 break;
       
  2047 // <cmail>
       
  2048             case EESMRCmdOpenAttachment:
       
  2049                 {
       
  2050                 // Check that message has attachments to display
       
  2051                 if ( messagePtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2052                     {
       
  2053                     iOpResult.iResultCode = KErrNone;
       
  2054                     OpenAttachmentL();
       
  2055                     CompletePendingMrCommand();
       
  2056                     }
       
  2057                 }
       
  2058                 break;
       
  2059             case EESMRCmdDownloadAttachment:
       
  2060             case EESMRCmdDownloadAllAttachments:
       
  2061                 {
       
  2062                 // Check that message has attachments to display
       
  2063                 if ( messagePtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2064                     {
       
  2065                     iOpResult.iResultCode = KErrNone;
       
  2066                     StartDowloadingAttachmentsL();
       
  2067                     CompletePendingMrCommand();
       
  2068                     }
       
  2069                 }
       
  2070                 break;
       
  2071             case EESMRCmdSaveAttachment:
       
  2072             case EESMRCmdSaveAllAttachments:
       
  2073                 {
       
  2074                 // Check that message has attachments to display
       
  2075                 if ( messagePtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2076                     {
       
  2077                     iOpResult.iResultCode = KErrNone;
       
  2078                     SaveAllAttachmentsL();
       
  2079                     CompletePendingMrCommand();
       
  2080                     }
       
  2081                 }
       
  2082                 break;
       
  2083 // </cmail>
       
  2084             case EESMRCmdOpenAttachmentView:
       
  2085                 {
       
  2086                 // Check that message has attachments to display
       
  2087                 if ( messagePtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2088                     {
       
  2089                     iOpResult.iResultCode = KErrNone;
       
  2090                     TAttachmentListActivationData params;
       
  2091                     params.iMailBoxId = messagePtr->GetMailBoxId();
       
  2092                     params.iFolderId = messagePtr->GetFolderId();
       
  2093                     params.iMessageId = messagePtr->GetMessageId();
       
  2094                     TPckgBuf<TAttachmentListActivationData> buf( params );
       
  2095                     TUid emptyCustomMessageId = { 0 };
       
  2096                     iAppUi.EnterFsEmailViewL( AttachmentMngrViewId, emptyCustomMessageId, buf );
       
  2097 // <cmail>
       
  2098                     CompletePendingMrCommand();
       
  2099 // </cmail>
       
  2100                     }
       
  2101                 }
       
  2102                 break;
       
  2103             case EESMRCmdDownloadManager:
       
  2104                 {
       
  2105                 // Check that there is something in dwnld manager to show
       
  2106                 if ( ShowDownloadManagerMenuInOptions() )
       
  2107                     {
       
  2108                     iOpResult.iResultCode = KErrNone;
       
  2109                     iAppUi.EnterFsEmailViewL( DownloadManagerViewId );
       
  2110                     }
       
  2111                 }
       
  2112                 break;
       
  2113             case EESMRCmdMailComposeMessage:
       
  2114                 {
       
  2115                 iOpResult.iResultCode = KErrNone;
       
  2116                 iAppUi.CreateNewMailL();
       
  2117                 }
       
  2118                 break;
       
  2119             case EESMRCmdMailReply:
       
  2120             case EESMRCmdMailReplyAll:
       
  2121             case EESMRCmdMailForwardAsMessage:
       
  2122                 {
       
  2123                 // Fill result codes for mrui
       
  2124                 iOpResult.iResultCode = KErrNone;
       
  2125                 // Fill launc params
       
  2126                 TEditorLaunchParams params;
       
  2127                 params.iMailboxId = iAppUi.GetActiveMailboxId();
       
  2128                 params.iActivatedExternally = EFalse;
       
  2129                 params.iMsgId = messagePtr->GetMessageId();
       
  2130                 if ( aCommandId == EESMRCmdMailForwardAsMessage )
       
  2131                     {
       
  2132                     iAppUi.LaunchEditorL( KEditorCmdForward, params );
       
  2133                     }
       
  2134                 else if ( aCommandId == EESMRCmdMailReply )
       
  2135                     {
       
  2136                     iAppUi.LaunchEditorL( KEditorCmdReply, params );
       
  2137                     }
       
  2138                 else if ( aCommandId == EESMRCmdMailReplyAll )
       
  2139                     {
       
  2140                     iAppUi.LaunchEditorL( KEditorCmdReplyAll, params );
       
  2141                     }
       
  2142                 }
       
  2143                 break;
       
  2144             case EESMRCmdMailPreviousMessage:
       
  2145                 {
       
  2146                 iNextOrPevMessageSelected = ETrue; // prevent back navigation when operation completed received
       
  2147                 ShowPreviousMessageL();
       
  2148                 iOpResult.iResultCode = KErrNone;
       
  2149                 CompletePendingMrCommand();
       
  2150                 }
       
  2151                 break;
       
  2152             case EESMRCmdMailNextMessage:
       
  2153                 {
       
  2154                 iNextOrPevMessageSelected = ETrue; // prevent back navigation when operation completed received
       
  2155                 ShowNextMessageL();
       
  2156                 iOpResult.iResultCode = KErrNone;
       
  2157                 CompletePendingMrCommand();
       
  2158                 }
       
  2159                 break;
       
  2160             default:
       
  2161                 break;
       
  2162             }
       
  2163         }
       
  2164 
       
  2165     // Complete immediately if handling command failed. It makes no harm if following
       
  2166     // function gets called several times in some case.
       
  2167     if ( iOpResult.iResultCode < 0 )
       
  2168         {
       
  2169         CompletePendingMrCommand();
       
  2170         }
       
  2171     }
       
  2172 
       
  2173 
       
  2174 void CFSEmailUiMailViewerVisualiser::ProcessSyncCommandL(
       
  2175     TESMRIcalViewerOperationType aCommandId,
       
  2176     const CFSMailMessage& aMessage )
       
  2177     {
       
  2178     FUNC_LOG;
       
  2179     if ( &aMessage )
       
  2180         {
       
  2181         switch ( aCommandId )
       
  2182             {
       
  2183             case EESMRCmdMailMarkUnread:
       
  2184                 {
       
  2185                 ChangeMsgReadStatusL( EFalse, ETrue );
       
  2186                 }
       
  2187                 break;
       
  2188             case EESMRCmdMailMarkRead:
       
  2189                 {
       
  2190                 ChangeMsgReadStatusL( ETrue, ETrue );
       
  2191                 }
       
  2192                 break;
       
  2193             case EESMRCmdMailFlagMessage:
       
  2194                 {
       
  2195                 if ( iMessage )
       
  2196                     {
       
  2197                     if ( !iFlagSelectionHanler )
       
  2198                         {
       
  2199                         // Create when used for the first time
       
  2200                         iFlagSelectionHanler =
       
  2201                             CFlagSelectionGlobalNoteHandler::NewL( *this );
       
  2202                         }
       
  2203                     // Call to LaunchFlagListQueryDialogL will lead
       
  2204                     // to FlagselectionCompleteL
       
  2205                     iFlagSelectionHanler->LaunchFlagListQueryDialogL();
       
  2206                     }
       
  2207                 }
       
  2208                 break;
       
  2209             default:
       
  2210                 break;
       
  2211             }
       
  2212         }
       
  2213     }
       
  2214 
       
  2215 
       
  2216 // ---------------------------------------------------------------------------
       
  2217 // CanProcessCommand
       
  2218 // Callback from meeting request UI. Determines what functionality is provided
       
  2219 // to mrui by this UI
       
  2220 // ---------------------------------------------------------------------------
       
  2221 //
       
  2222 TBool CFSEmailUiMailViewerVisualiser::CanProcessCommand(
       
  2223     TESMRIcalViewerOperationType aCommandId  ) const
       
  2224     {
       
  2225     FUNC_LOG;
       
  2226     TBool ret( EFalse );
       
  2227     TInt numRecipients(0);
       
  2228     switch ( aCommandId )
       
  2229         {
       
  2230         case EESMRCmdMailReply:
       
  2231             ret = ETrue;
       
  2232             break;
       
  2233         case EESMRCmdMailReplyAll:
       
  2234             //Get # of recipients
       
  2235             if ( iMessage )
       
  2236                 {
       
  2237                 numRecipients=TFsEmailUiUtility::CountRecepients( iMessage );
       
  2238                 if ( numRecipients == 1 )
       
  2239                     {
       
  2240                     //check if the malbox ownmailaddress is same as the recipients email address. If not, then assume that the
       
  2241                     //email is a distribution list and we need to inc num of Recipients so that "Reply ALL" option appears in UI.
       
  2242                     if ( iMessage->GetToRecipients().Count() )
       
  2243                         {
       
  2244                         if ( iMailBox->OwnMailAddress().GetEmailAddress().Compare(iMessage->GetToRecipients()[0]->GetEmailAddress()) )
       
  2245                             {
       
  2246                             numRecipients++;
       
  2247                             }
       
  2248                         }
       
  2249                     if ( iMessage->GetCCRecipients().Count() )
       
  2250                         {
       
  2251                         if ( iMailBox->OwnMailAddress().GetEmailAddress().Compare(iMessage->GetCCRecipients()[0]->GetEmailAddress()) )
       
  2252                             {
       
  2253                             numRecipients++;
       
  2254                             }
       
  2255                         }
       
  2256                     if ( iMessage->GetBCCRecipients().Count() )
       
  2257                         {
       
  2258                         if ( iMailBox->OwnMailAddress().GetEmailAddress().Compare(iMessage->GetBCCRecipients()[0]->GetEmailAddress()) )
       
  2259                             {
       
  2260                             numRecipients++;
       
  2261                             }
       
  2262                         }
       
  2263                     }
       
  2264                 }
       
  2265             ret = ( iMessage && numRecipients > 1 );
       
  2266             break;
       
  2267         case EESMRCmdDownloadManager:
       
  2268             ret = ShowDownloadManagerMenuInOptions();
       
  2269             break;
       
  2270 // <cmail>
       
  2271         case EESMRCmdOpenAttachment:
       
  2272         case EESMRCmdSaveAttachment:
       
  2273         case EESMRCmdSaveAllAttachments:
       
  2274         case EESMRCmdDownloadAttachment:
       
  2275         case EESMRCmdDownloadAllAttachments:
       
  2276 // </cmail>
       
  2277         case EESMRCmdOpenAttachmentView:
       
  2278             ret = ETrue;
       
  2279             break;
       
  2280         case EESMRCmdMailComposeMessage:
       
  2281             ret = ETrue;
       
  2282             break;
       
  2283         case EESMRCmdMailMarkUnread:
       
  2284             {
       
  2285             ret = EFalse;
       
  2286             if ( iMessage && iMessage->IsFlagSet(EFSMsgFlag_Read) )
       
  2287                 {
       
  2288                 // Read, unread should be available
       
  2289                 ret = ETrue;
       
  2290                 }
       
  2291             }
       
  2292             break;
       
  2293         case EESMRCmdMailMarkRead:
       
  2294             {
       
  2295             ret = EFalse;
       
  2296             if ( iMessage && !iMessage->IsFlagSet(EFSMsgFlag_Read) )
       
  2297                 {
       
  2298                 // Read, unread should be available
       
  2299                 ret = ETrue;
       
  2300                 }
       
  2301             }
       
  2302             break;
       
  2303         case EESMRCmdMailMoveMessage:
       
  2304             {
       
  2305             ret = EFalse;
       
  2306             if ( iMessage )
       
  2307                 {
       
  2308                 // confirmed pointer exists, check whether mb has capa
       
  2309                 ret = iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaMoveToFolder );
       
  2310                 }
       
  2311             }
       
  2312             break;
       
  2313         case EESMRCmdMailForwardAsMessage:
       
  2314             ret = ETrue;
       
  2315             break;
       
  2316         case EESMRCmdMailFlagMessage:
       
  2317             ret = TFsEmailUiUtility::IsFollowUpSupported( *iMailBox );
       
  2318             break;
       
  2319         case EESMRCmdMailMessageDetails:
       
  2320             ret = ETrue;
       
  2321             break;
       
  2322         case EESMRCmdMailDelete:
       
  2323             ret = ETrue;
       
  2324             break;
       
  2325         case EESMRCmdMailPreviousMessage:
       
  2326             ret = ShowPreviousMessageMenuInOptions();
       
  2327             break;
       
  2328         case EESMRCmdMailNextMessage:
       
  2329             ret = ShowNextMessageMenuInOptions();
       
  2330             break;
       
  2331         default:
       
  2332             ret = EFalse;
       
  2333             break;
       
  2334         }
       
  2335     return ret;
       
  2336     }
       
  2337 
       
  2338 // -----------------------------------------------------------------------------
       
  2339 // CFSEmailUiMailViewerVisualiser::CompletePendingMrCommand()
       
  2340 // -----------------------------------------------------------------------------
       
  2341 //
       
  2342 void CFSEmailUiMailViewerVisualiser::CompletePendingMrCommand()
       
  2343     {
       
  2344     FUNC_LOG;
       
  2345     if ( iMrObserverToInform )
       
  2346         {
       
  2347         iMrObserverToInform->OperationCompleted( iOpResult );
       
  2348         }
       
  2349     iMrObserverToInform = NULL;
       
  2350     }
       
  2351 
       
  2352 // -----------------------------------------------------------------------------
       
  2353 // CFSEmailUiMailViewerVisualiser::CancelPendingMrCommandL()
       
  2354 // -----------------------------------------------------------------------------
       
  2355 //
       
  2356 void CFSEmailUiMailViewerVisualiser::CancelPendingMrCommandL()
       
  2357     {
       
  2358     FUNC_LOG;
       
  2359     // Be sure not to call cancel if the MRUI is not active. This is because
       
  2360     // calling cancel after closing a newly fetched MR causes the MRUI to
       
  2361     // be reopened.
       
  2362     if ( iMrUiActive && iAppUi.MrViewerInstanceL() )
       
  2363         {
       
  2364         iAppUi.MrViewerInstanceL()->CancelOperation();
       
  2365         }
       
  2366     iMrUiActive = EFalse;
       
  2367     iMrObserverToInform = NULL;
       
  2368     }
       
  2369 
       
  2370 // -----------------------------------------------------------------------------
       
  2371 // CFSEmailUiMailViewerVisualiser::OperationCompleted()
       
  2372 // From MRUI observer
       
  2373 // -----------------------------------------------------------------------------
       
  2374 //
       
  2375 void CFSEmailUiMailViewerVisualiser::OperationCompleted( TIcalViewerOperationResult aResult )
       
  2376     {
       
  2377     FUNC_LOG;
       
  2378     if ( aResult.iOpType == EESMRViewLaunch )
       
  2379         {
       
  2380         iMrUiActive = EFalse;
       
  2381         if ( !iNextOrPevMessageSelected && iAppUi.CurrentActiveView() == this )
       
  2382             {
       
  2383             TRAP_IGNORE( NavigateBackL() );
       
  2384             }
       
  2385         if ( aResult.iAttendeeStatus == EESMRAttendeeStatusAccept ||
       
  2386              aResult.iAttendeeStatus == EESMRAttendeeStatusTentative )
       
  2387             {
       
  2388             TInt noteTextId = R_FREESTYLE_EMAIL_CONFIRM_NOTE_MEETING_ON_CALENDAR_AFTER_SYNC;
       
  2389             TRAP_IGNORE( TFsEmailUiUtility::ShowGlobalInfoNoteL( noteTextId ) );
       
  2390             }
       
  2391         }
       
  2392     }
       
  2393 
       
  2394 // -----------------------------------------------------------------------------
       
  2395 // CFSEmailUiMailViewerVisualiser::OperationError()
       
  2396 // -----------------------------------------------------------------------------
       
  2397 //
       
  2398 void CFSEmailUiMailViewerVisualiser::OperationError( TIcalViewerOperationResult aResult )
       
  2399     {
       
  2400     FUNC_LOG;
       
  2401     // Show message in standard mail viewer in case launchin MRUI fails for any
       
  2402     // other reason than viewer being cancelled by calling CancelPendingMrCommand().
       
  2403     if ( aResult.iOpType == EESMRViewLaunch )
       
  2404         {
       
  2405         iMrUiActive = EFalse;
       
  2406         if ( iAppUi.CurrentActiveView() == this && aResult.iResultCode != KErrCancel )
       
  2407             {
       
  2408             TRAP_IGNORE(
       
  2409                 SetMailboxNameToStatusPaneL();
       
  2410                 iAppUi.Display().Roster().Hide( ControlGroup() );
       
  2411                 RefreshL( ETrue );
       
  2412                 iAppUi.Display().Roster().ShowL( ControlGroup() );
       
  2413                 UpdateDownloadIndicatorL();
       
  2414                 );
       
  2415             }
       
  2416         }
       
  2417     }
       
  2418 
       
  2419 // -----------------------------------------------------------------------------
       
  2420 // CFSEmailUiMailViewerVisualiser::SetMskL()
       
  2421 // -----------------------------------------------------------------------------
       
  2422 //
       
  2423 void CFSEmailUiMailViewerVisualiser::SetMskL()
       
  2424     {
       
  2425     FUNC_LOG;
       
  2426     if ( iFirstStartCompleted && iTextViewer ) // Safety
       
  2427         {
       
  2428         TInt ignoreThis( 0 );
       
  2429         TBool visibleHotsSpot =
       
  2430             iTextViewer->GetVisibleFocusedHotspotLine( ignoreThis );
       
  2431         if ( visibleHotsSpot )
       
  2432             {
       
  2433             SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  2434             CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  2435             THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL(
       
  2436                 currentHeaderHotSpotData, currentBodyHotSpotData );
       
  2437 
       
  2438             if ( hotspotType == EHeaderHotspot )
       
  2439                 {
       
  2440                 if ( currentHeaderHotSpotData.iType ==
       
  2441                         ETypeToAddressDisplayName ||
       
  2442                      currentHeaderHotSpotData.iType ==
       
  2443                         ETypeCcAddressDisplayName ||
       
  2444                      currentHeaderHotSpotData.iType ==
       
  2445                         ETypeBccAddressDisplayName ||
       
  2446                      currentHeaderHotSpotData.iType ==
       
  2447                         ETypeEmailAddress )
       
  2448                     {
       
  2449                     ChangeMskCommandL( R_FSE_QTN_MSK_COMPOSE );
       
  2450                     }
       
  2451                 else if ( currentHeaderHotSpotData.iType ==
       
  2452                     ETypeFromAddressDisplayName )
       
  2453                     {
       
  2454                     if ( !iEmbeddedMessageMode )
       
  2455                         {
       
  2456                         ChangeMskCommandL( R_FSE_QTN_MSK_REPLY );
       
  2457                         }
       
  2458                     else
       
  2459                         {
       
  2460                         // Reply option is not available in the embedded mode
       
  2461                         ChangeMskCommandL( R_FSE_QTN_MSK_COMPOSE );
       
  2462                         }
       
  2463                     }
       
  2464                 else if ( currentHeaderHotSpotData.iType == ETypeHtml )
       
  2465                     {
       
  2466                     ChangeMskCommandL( R_FSE_QTN_MSK_OPENHTMLVIEWER );
       
  2467                     }
       
  2468                 else if ( currentHeaderHotSpotData.iType == ETypeAttachment )
       
  2469                     {
       
  2470                     if ( iShowMskDownloadOption )
       
  2471                         { // attachment not yet downloaded
       
  2472                         ChangeMskCommandL( R_FSE_QTN_MSK_DOWNLOAD );
       
  2473                         }
       
  2474                     else if ( ShowCancelDownloadOption() )
       
  2475                         { // attachment is being downloaded
       
  2476                         ChangeMskCommandL( R_FSE_QTN_MSK_OPEN_BLOCKED );
       
  2477                         }
       
  2478                     else // attachment is already downloaded
       
  2479                         {
       
  2480                         ChangeMskCommandL( R_FSE_QTN_MSK_VIEWATTACHMENT );
       
  2481                         }
       
  2482                     }
       
  2483                 else if ( currentHeaderHotSpotData.iType == ETypeAttachments )
       
  2484                     {
       
  2485                     ChangeMskCommandL( R_FSE_QTN_MSK_VIEWATTACHMENTS );
       
  2486                     }
       
  2487                 else if ( currentHeaderHotSpotData.iType ==
       
  2488                             ETypeToNMoreRecipients ||
       
  2489                           currentHeaderHotSpotData.iType ==
       
  2490                             ETypeCcNMoreRecipients ||
       
  2491                           currentHeaderHotSpotData.iType ==
       
  2492                             ETypeBccNMoreRecipients )
       
  2493                     {
       
  2494                     ChangeMskCommandL( R_FSE_QTN_MSK_VIEWALL );
       
  2495                     }
       
  2496                 }
       
  2497              else if ( hotspotType == EBodyHotspot )
       
  2498                 {
       
  2499                 if ( currentBodyHotSpotData.iItemType ==
       
  2500                     CFindItemEngine::EFindItemSearchMailAddressBin )
       
  2501                     {
       
  2502                     ChangeMskCommandL( R_FSE_QTN_MSK_COMPOSE );
       
  2503                     }
       
  2504                 else if ( currentBodyHotSpotData.iItemType ==
       
  2505                     CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
  2506                     {
       
  2507                     ChangeMskCommandL( R_FSE_QTN_MSK_CALL );
       
  2508                     }
       
  2509                 else if ( currentBodyHotSpotData.iItemType ==
       
  2510                             CFindItemEngine::EFindItemSearchURLBin ||
       
  2511                           currentBodyHotSpotData.iItemType ==
       
  2512                             CFindItemEngine::EFindItemSearchScheme )
       
  2513                     {
       
  2514                     TInt schemaLinkType = ResolveBodyTextSchemaUrlTypeL( currentBodyHotSpotData );
       
  2515                     switch ( schemaLinkType )
       
  2516                         {
       
  2517                         case EFocusOnEMailInBodyText:
       
  2518                             ChangeMskCommandL( R_FSE_QTN_MSK_COMPOSE );
       
  2519                             break;
       
  2520                         case EFocusOnNumberWithinMessage:
       
  2521                             ChangeMskCommandL( R_FSE_QTN_MSK_CALL );
       
  2522                             break;
       
  2523                         default:
       
  2524                             ChangeMskCommandL( R_FSE_QTN_MSK_OPENURL );
       
  2525                             break;
       
  2526                         }
       
  2527                     }
       
  2528                 }
       
  2529              else // if hotspot is not known
       
  2530                 {
       
  2531                 //it will set context menu for email (reply, forward, etc.)
       
  2532                 ChangeMskCommandL( R_FSE_QTN_MSK_BODY_MENU );
       
  2533                 }
       
  2534             }
       
  2535         else
       
  2536             {
       
  2537         //it will set context menu for email (reply, forward, etc.)
       
  2538             ChangeMskCommandL( R_FSE_QTN_MSK_BODY_MENU );
       
  2539             }
       
  2540         }
       
  2541     }
       
  2542 
       
  2543 // CFSEmailUiMailViewerVisualiser::OfferEventL
       
  2544 // -----------------------------------------------------------------------------
       
  2545 TBool CFSEmailUiMailViewerVisualiser::OfferEventL(const TAlfEvent& aEvent)
       
  2546     {
       
  2547     FUNC_LOG;
       
  2548     // Consume most keys to be safe. Let only few keys to flow to
       
  2549     // text viewer because text viewer does some unexcepted actions
       
  2550     // with some keys events (at least left arrow and 0 keys)
       
  2551     TBool consumed( ETrue );
       
  2552 
       
  2553     // Handle key presses if we are ready to process them
       
  2554     if ( iAsyncProcessComplete && !iAppUi.ViewSwitchingOngoing() && aEvent.IsKeyEvent() )
       
  2555         {
       
  2556         // Check keyboard shortcuts on key down event since half-QWERTY keyboard
       
  2557         // has shortcuts on keys which do not send key event at all
       
  2558         if ( aEvent.Code() == EEventKeyDown )
       
  2559             {
       
  2560             TInt shortcutCommand =
       
  2561                 iAppUi.ShortcutBinding().CommandForShortcutKey( aEvent.KeyEvent(),
       
  2562                     CFSEmailUiShortcutBinding::EContextMailViewer );
       
  2563             if ( shortcutCommand != KErrNotFound )
       
  2564                 {
       
  2565                 HandleCommandL( shortcutCommand );
       
  2566                 }
       
  2567             }
       
  2568 
       
  2569         // Update MSK label when key released to avoid constant updating
       
  2570         // on fast scrolling
       
  2571         else if ( aEvent.Code() == EEventKeyUp )
       
  2572             {
       
  2573             SetMskL();
       
  2574             }
       
  2575 
       
  2576         // Handle key events
       
  2577         else if ( aEvent.Code() == EEventKey )
       
  2578             {
       
  2579             // Swap right and left controls in mirrored layout
       
  2580             TInt scanCode = aEvent.KeyEvent().iScanCode;
       
  2581             if ( AknLayoutUtils::LayoutMirrored() )
       
  2582                 {
       
  2583                 if ( scanCode == EStdKeyRightArrow ) scanCode = EStdKeyLeftArrow;
       
  2584                 else if ( scanCode == EStdKeyLeftArrow ) scanCode = EStdKeyRightArrow;
       
  2585                 }
       
  2586 
       
  2587             switch ( scanCode )
       
  2588                 {
       
  2589                 case EStdKeyRightArrow:
       
  2590                     {
       
  2591                     // Open action menu if it is available to current hotspot item
       
  2592                     LaunchActionMenuL();
       
  2593                     break;
       
  2594                     }
       
  2595                 case EStdKeyYes:
       
  2596                     {
       
  2597                     // call current header hotspot name or current body hotspot number
       
  2598                     CallHotSpotAddressL();
       
  2599                     break;
       
  2600                     }
       
  2601                 case EStdKeyDownArrow:
       
  2602                 case EStdKeyUpArrow:
       
  2603                 case EStdKeyNull: // simulated keys events
       
  2604                     {
       
  2605                     // These keys are passed on to TextViewer
       
  2606                     consumed = EFalse;
       
  2607                     break;
       
  2608                     }
       
  2609                 default:
       
  2610                     {
       
  2611                     break;
       
  2612                     }
       
  2613                 }
       
  2614             }
       
  2615         }
       
  2616 
       
  2617     return consumed;
       
  2618     }
       
  2619 
       
  2620 // -----------------------------------------------------------------------------
       
  2621 // CFSEmailUiMailViewerVisualiser::ClearMailViewer
       
  2622 // -----------------------------------------------------------------------------
       
  2623 void CFSEmailUiMailViewerVisualiser::ClearMailViewer()
       
  2624     {
       
  2625     FUNC_LOG;
       
  2626     iAppUi.Display().Roster().Hide( ControlGroup() );
       
  2627     if ( iTextViewer )
       
  2628         {
       
  2629         if ( iTextViewerControl )
       
  2630             {
       
  2631             ControlGroup().Remove( iTextViewerControl );
       
  2632             }
       
  2633         if ( iControl )
       
  2634             {
       
  2635             ControlGroup().Remove( iControl );
       
  2636             }
       
  2637         delete iTextViewer; iTextViewer = NULL;
       
  2638         delete iTextViewerControl; iTextViewerControl = NULL;
       
  2639         delete iControl; iControl = NULL;
       
  2640         }
       
  2641     if ( iViewerRichText )
       
  2642         {
       
  2643         iViewerRichText->Reset();
       
  2644         }
       
  2645     }
       
  2646 
       
  2647 // -----------------------------------------------------------------------------
       
  2648 // CFSEmailUiMailViewerVisualiser::UpdateMailViewerL
       
  2649 // -----------------------------------------------------------------------------
       
  2650 void CFSEmailUiMailViewerVisualiser::UpdateMailViewerL()
       
  2651     {
       
  2652     FUNC_LOG;
       
  2653     if ( iFirstStartCompleted ) // Safety
       
  2654         {
       
  2655         ClearMailViewer();
       
  2656 
       
  2657         // Create text viewer and store control pointer
       
  2658         iTextViewer = CFsTextViewer::NewL( iEnv );
       
  2659         iTextViewerControl = iTextViewer->GetControl();
       
  2660         iTextViewer->SetObserver( this );
       
  2661 
       
  2662         // Set the artificial shortcut keys used to command the viewer to scroll up/down.
       
  2663         // These are simulated when corresponding shortcut command is received from the
       
  2664         // standard shortcut binder of FsEmailUI.
       
  2665         CFsTextViewerKeys* keys = CFsTextViewerKeys::NewL();
       
  2666         keys->SetKeyPgUp( EKeyPageUp );
       
  2667         keys->SetKeyPgDown( EKeyPageDown );
       
  2668         keys->SetKeyScrollUp( KKeyCodeArtificialScrollUp );
       
  2669         keys->SetKeyScrollDown( KKeyCodeArtificialScrollDown );
       
  2670         iTextViewer->SetCustomKeys( keys );
       
  2671 
       
  2672         iTextViewer->SetMirroring( AknLayoutUtils::LayoutMirrored() );
       
  2673 
       
  2674         iViewerRichText->RefreshRichTextL( *iTextViewer, *iMessage, *iMailBox );
       
  2675 
       
  2676         // These need to be called before setting text to the viewer.
       
  2677         iTextViewer->SetLeftMargin( iAppUi.LayoutHandler()->ViewerLeftMarginInPixels() );
       
  2678         iTextViewer->SetRightMargin( iAppUi.LayoutHandler()->ViewerRightMarginInPixels() );
       
  2679 
       
  2680         SetActionButtonIconAndHighLight();
       
  2681 
       
  2682         iTextViewer->SetTextL( &iViewerRichText->RichText(), iSmDictionary );
       
  2683 
       
  2684         // ownerships are transfered to AlfEnviroment.
       
  2685         //<cmail> Compared to S60 3.2.3 in S60 5.0 Alf offers the key events in
       
  2686         // opposite order.
       
  2687         // Create control for capturing left and right navigation events
       
  2688         iControl = CFreestyleEmailUiMailViewerControl::NewL( iEnv, *this );
       
  2689         ControlGroup().AppendL( iControl );
       
  2690         ControlGroup().AppendL( iTextViewerControl );
       
  2691         //</cmail>
       
  2692 
       
  2693         iLayoutChangedWhileNotActive = EFalse;
       
  2694         }
       
  2695     }
       
  2696 
       
  2697 // -----------------------------------------------------------------------------
       
  2698 // CFSEmailUiMailViewerVisualiser::SetActionButtonIconAndHighLight
       
  2699 // -----------------------------------------------------------------------------
       
  2700 void CFSEmailUiMailViewerVisualiser::SetActionButtonIconAndHighLight()
       
  2701     {
       
  2702     FUNC_LOG;
       
  2703     CFreestyleEmailUiTextureManager* textureMgr = iAppUi.FsTextureManager();
       
  2704     CFSEmailUiLayoutHandler* layoutMgr = iAppUi.LayoutHandler();
       
  2705 
       
  2706     // get textures from texture manager
       
  2707     CAlfTexture& menuTexture = textureMgr->TextureByIndex( EListControlMenuIcon );
       
  2708     CAlfTexture& selectortexture = textureMgr->TextureByIndex( EViewerHighlightTexture );
       
  2709 
       
  2710     iTextViewer->SetLiteLineBg( selectortexture, layoutMgr->ViewerSelectorOpacity() );
       
  2711 
       
  2712     iTextViewer->SetActionButton( menuTexture, 1  );
       
  2713     iTextViewer->SetActionButtonMargin( layoutMgr->ViewerActionMenuIconMargin() );
       
  2714     TSize btnSize = layoutMgr->ViewerActionMenuIconSize();
       
  2715     iTextViewer->SetActionButtonSize( btnSize.iWidth, btnSize.iHeight );
       
  2716     }
       
  2717 
       
  2718 // -----------------------------------------------------------------------------
       
  2719 // CFSEmailUiMailViewerVisualiser::LaunchActionMenuL
       
  2720 // -----------------------------------------------------------------------------
       
  2721 void CFSEmailUiMailViewerVisualiser::LaunchActionMenuL()
       
  2722     {
       
  2723     FUNC_LOG;
       
  2724     // check that current hotspot is visible
       
  2725     TInt ignoreThis; // not used here. Only return value is used not this mandatory reference parameter
       
  2726     TBool visibleHotsSpot = iTextViewer->GetVisibleFocusedHotspotLine( ignoreThis );
       
  2727     if( visibleHotsSpot )
       
  2728         {
       
  2729         // Remove items
       
  2730         CFSEmailUiActionMenu::RemoveAllL();
       
  2731 
       
  2732         // check which hotspot is active.
       
  2733         SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  2734         CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  2735         THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL( currentHeaderHotSpotData, currentBodyHotSpotData );
       
  2736 
       
  2737         TActionMenuType currentActionMenuType = ENoActionMenuFocused;
       
  2738         if( hotspotType == EHeaderHotspot && (
       
  2739             currentHeaderHotSpotData.iType == ETypeFromAddressDisplayName ||
       
  2740             currentHeaderHotSpotData.iType == ETypeToAddressDisplayName ||
       
  2741             currentHeaderHotSpotData.iType == ETypeCcAddressDisplayName ||
       
  2742             currentHeaderHotSpotData.iType == ETypeBccAddressDisplayName ||
       
  2743             currentHeaderHotSpotData.iType == ETypeEmailAddress ) )
       
  2744             {
       
  2745             currentActionMenuType = EFocusOnNameInAddressField;
       
  2746             }
       
  2747         else if( hotspotType == EHeaderHotspot && (
       
  2748             currentHeaderHotSpotData.iType == ETypeAttachment ) )
       
  2749             {
       
  2750             currentActionMenuType = EFocusOnAttachmentName;
       
  2751             }
       
  2752         else if( hotspotType == EHeaderHotspot && (
       
  2753             currentHeaderHotSpotData.iType == ETypeAttachments ) )
       
  2754             {
       
  2755             currentActionMenuType = EFocusOnAttachmentsText;
       
  2756             }
       
  2757         else if( hotspotType == EBodyHotspot &&
       
  2758                 currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
  2759             {
       
  2760             currentActionMenuType = EFocusOnNumberWithinMessage;
       
  2761             }
       
  2762         else if( hotspotType == EBodyHotspot && ( currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchURLBin ||
       
  2763                  currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchScheme ) )
       
  2764             {
       
  2765             TInt schemaLinkType = ResolveBodyTextSchemaUrlTypeL( currentBodyHotSpotData );
       
  2766             switch ( schemaLinkType )
       
  2767                 {
       
  2768                 case EFocusOnEMailInBodyText:
       
  2769                     currentActionMenuType = EFocusOnEMailInBodyText;
       
  2770                     break;
       
  2771                 case EFocusOnNumberWithinMessage:
       
  2772                     currentActionMenuType = EFocusOnNumberWithinMessage;
       
  2773                     break;
       
  2774                 default:
       
  2775                     currentActionMenuType = EFocusOnHyperLinkWithinMessage;
       
  2776                     break;
       
  2777 
       
  2778                 }
       
  2779             }
       
  2780         else if( hotspotType == EBodyHotspot &&
       
  2781                 currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchMailAddressBin )
       
  2782             {
       
  2783             currentActionMenuType = EFocusOnEMailInBodyText;
       
  2784             }
       
  2785 
       
  2786 
       
  2787         if( currentActionMenuType != ENoActionMenuFocused )
       
  2788             {
       
  2789             CreateActionMenuItemsL( currentActionMenuType );
       
  2790             TActionMenuCustomItemId menuResult = CFSEmailUiActionMenu::ExecuteL( EFscCenter );
       
  2791             if ( menuResult != FsEActionMenuCasItemSelectedAndExecuted &&
       
  2792                     menuResult != FsEActionMenuDismissed    )
       
  2793                 {
       
  2794                 HandleActionMenuCommandL( menuResult, currentActionMenuType );
       
  2795                 }
       
  2796             }
       
  2797         }
       
  2798     }
       
  2799 
       
  2800 // -----------------------------------------------------------------------------
       
  2801 // CFSEmailUiMailViewerVisualiser::ResolveBodyTextSchemaUrlTypeL
       
  2802 // -----------------------------------------------------------------------------
       
  2803 TInt CFSEmailUiMailViewerVisualiser::ResolveBodyTextSchemaUrlTypeL( CFindItemEngine::SFoundItem aHotSpot )
       
  2804     {
       
  2805     FUNC_LOG;
       
  2806     TInt ret( EFocusOnHyperLinkWithinMessage );
       
  2807     HBufC* schemeText = iViewerRichText->GetHotspotTextLC( aHotSpot );
       
  2808     if ( schemeText->FindC( KMailtoPrefix ) == 0 )
       
  2809         {
       
  2810         ret = EFocusOnEMailInBodyText;
       
  2811         }
       
  2812     else if ( schemeText->FindC( KCallPrefix ) == 0 ||
       
  2813               schemeText->FindC( KTelPrefix ) == 0 ||
       
  2814               schemeText->FindC( KSmsPrefix ) == 0 ||
       
  2815               schemeText->FindC( KMmsPrefix ) == 0 ||
       
  2816               schemeText->FindC( KVoipPrefix ) == 0 )
       
  2817         {
       
  2818         ret = EFocusOnNumberWithinMessage;
       
  2819         }
       
  2820     else
       
  2821         {
       
  2822         ret = EFocusOnHyperLinkWithinMessage;
       
  2823         }
       
  2824     CleanupStack::PopAndDestroy( schemeText );
       
  2825     return ret;
       
  2826     }
       
  2827 
       
  2828 // -----------------------------------------------------------------------------
       
  2829 // CFSEmailUiMailViewerVisualiser::SetActionMenuIconVisbilityL
       
  2830 // -----------------------------------------------------------------------------
       
  2831 void CFSEmailUiMailViewerVisualiser::SetActionMenuIconVisbilityL()
       
  2832     {
       
  2833     FUNC_LOG;
       
  2834     if ( iTextViewer )
       
  2835         {
       
  2836         if ( ShowActionsMenuInOptionsL() )
       
  2837             {
       
  2838             iTextViewer->ShowActionButtonForCurrentHighlightedHotspotL();
       
  2839             }
       
  2840         else
       
  2841             {
       
  2842             iTextViewer->HideActionButtonFromCurrentHighlightedHotspot();
       
  2843             }
       
  2844         }
       
  2845     }
       
  2846 
       
  2847 // -----------------------------------------------------------------------------
       
  2848 // CFSEmailUiMailViewerVisualiser::CreateActionMenuItemsL
       
  2849 // -----------------------------------------------------------------------------
       
  2850 void CFSEmailUiMailViewerVisualiser::CreateActionMenuItemsL(
       
  2851     TActionMenuType aActionMenuType )
       
  2852     {
       
  2853     FUNC_LOG;
       
  2854     // See the ui spec for all the right action menus according to
       
  2855     // currently selected hotspot
       
  2856     RArray<TActionMenuCustomItemId> uids;
       
  2857     CleanupClosePushL( uids );
       
  2858     if ( aActionMenuType == EFocusOnNumberWithinMessage )
       
  2859         {
       
  2860         uids.Append( FsEActionMenuCall );
       
  2861         uids.Append( FsEActionMenuAddToContacts );
       
  2862         // Drop FsEActionMenuCreateMessage from sip: addresses
       
  2863         // First check which hotspot is active.
       
  2864         SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  2865         CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  2866         THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL(
       
  2867             currentHeaderHotSpotData, currentBodyHotSpotData );
       
  2868         HBufC* schemeText = iViewerRichText->GetHotspotTextLC( currentBodyHotSpotData );
       
  2869         if ( schemeText &&  schemeText->FindC( KVoipPrefix ) != 0 )
       
  2870             {
       
  2871             uids.Append( FsEActionMenuCreateMessage );
       
  2872             }
       
  2873         CleanupStack::PopAndDestroy( schemeText );
       
  2874         if ( TFsEmailUiUtility::IsRemoteLookupSupported( *iMailBox ) )
       
  2875             {
       
  2876             uids.Append( FsEActionMenuRemoteLookup );
       
  2877             }
       
  2878         }
       
  2879     else if ( aActionMenuType == EFocusOnNameInAddressField ||
       
  2880               aActionMenuType == EFocusOnEMailInBodyText )
       
  2881         {
       
  2882         uids.Append( FsEActionMenuCall );
       
  2883         uids.Append( FsEActionMenuCreateMessage );
       
  2884         uids.Append( FsEActionMenuCreateEmail );
       
  2885         uids.Append( FsEActionMenuContactDetails );
       
  2886         uids.Append( FsEActionMenuAddToContacts );
       
  2887         if ( TFsEmailUiUtility::IsRemoteLookupSupported( *iMailBox ) )
       
  2888             {
       
  2889             uids.Append( FsEActionMenuRemoteLookup );
       
  2890             }
       
  2891         }
       
  2892     else if ( aActionMenuType == EFocusOnHyperLinkWithinMessage )
       
  2893         {
       
  2894         uids.Append( FsEActionMenuOpenInWeb );
       
  2895         uids.Append( FsEActionMenuOpenInIntranet );
       
  2896         uids.Append( FsEActionMenuBookmark );
       
  2897         }
       
  2898     else if ( aActionMenuType == EFocusOnAttachmentName )
       
  2899         {
       
  2900         if ( ShowOpenAttachmentOptionL() )
       
  2901             {
       
  2902             uids.Append( FsEActionAttachmentOpen );
       
  2903             }
       
  2904         if ( ShowDownloadOptionL() )
       
  2905             {
       
  2906             uids.Append( FsEActionAttachmentDownload );
       
  2907             }
       
  2908         if ( ShowCancelDownloadOption() )
       
  2909             {
       
  2910             uids.Append( FsEActionAttachmentCancelDownload );
       
  2911             }
       
  2912         if ( ShowSaveAttachmentOptionL() )
       
  2913             {
       
  2914             uids.Append( FsEActionAttachmentSave );
       
  2915             }
       
  2916         if ( ShowOpenAttachmentOptionL() )
       
  2917             {
       
  2918             uids.Append( FsEActionAttachmentClearFetchedContent );
       
  2919             }
       
  2920         }
       
  2921     else if ( aActionMenuType == EFocusOnAttachmentsText )
       
  2922         {
       
  2923         if ( ShowOpenAttachmentOptionL() )
       
  2924             {
       
  2925             uids.Append( FsEActionAttachmentViewAll );
       
  2926             }
       
  2927         if ( ShowDownloadOptionL() )
       
  2928             {
       
  2929             uids.Append( FsEActionAttachmentDownloadAll );
       
  2930             }
       
  2931         if ( ShowCancelDownloadOption() )
       
  2932             {
       
  2933             uids.Append( FsEActionAttachmentCancelAllDownloads );
       
  2934             }
       
  2935         if ( ShowSaveAttachmentOptionL() )
       
  2936             {
       
  2937             uids.Append( FsEActionAttachmentSaveAll );
       
  2938             }
       
  2939         }
       
  2940 
       
  2941     TInt uidsCount = uids.Count();
       
  2942     for ( TInt i = 0; i <  uidsCount; i++ )
       
  2943         {
       
  2944         CFSEmailUiActionMenu::AddCustomItemL( uids[i] );
       
  2945         }
       
  2946     CleanupStack::PopAndDestroy( &uids );
       
  2947     }
       
  2948 
       
  2949 
       
  2950 // -----------------------------------------------------------------------------
       
  2951 // CFSEmailUiMailViewerVisualiser::HandleActionMenuCommandL
       
  2952 // -----------------------------------------------------------------------------
       
  2953 void CFSEmailUiMailViewerVisualiser::HandleActionMenuCommandL(
       
  2954     TActionMenuCustomItemId aSelectedActionMenuItem,
       
  2955     TActionMenuType aActionMenuType )
       
  2956     {
       
  2957     FUNC_LOG;
       
  2958     // check which hotspot is active.
       
  2959     SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  2960     CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  2961     THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL(
       
  2962         currentHeaderHotSpotData, currentBodyHotSpotData );
       
  2963 
       
  2964     if ( aActionMenuType == EFocusOnNumberWithinMessage )
       
  2965         {
       
  2966         switch ( aSelectedActionMenuItem  )
       
  2967             {
       
  2968             case FsEActionMenuCall: // Call
       
  2969                 {
       
  2970                 CallToBodyHotSpotNumberL( currentBodyHotSpotData );
       
  2971                 }
       
  2972                 break;
       
  2973             case FsEActionMenuAddToContacts: // Add to Contacts
       
  2974                 {
       
  2975                 HBufC* hotspotText = iViewerRichText->GetHotspotTextLC(
       
  2976                     currentBodyHotSpotData );
       
  2977                 SavePhoneNumberAsContactL( *hotspotText );
       
  2978                 CleanupStack::PopAndDestroy( hotspotText );
       
  2979                 }
       
  2980                 break;
       
  2981             case FsEActionMenuCreateMessage: // Create message
       
  2982                 {
       
  2983                 CreateMessageL();
       
  2984                 }
       
  2985                 break;
       
  2986             case FsEActionMenuRemoteLookup: // Remote lookup
       
  2987                 {
       
  2988                 HBufC* hotspotText = iViewerRichText->GetHotspotTextLC(
       
  2989                     currentBodyHotSpotData );
       
  2990                 LaunchRemoteLookupL( *hotspotText );
       
  2991                 CleanupStack::PopAndDestroy( hotspotText );
       
  2992                 }
       
  2993                 break;
       
  2994             }
       
  2995         }
       
  2996     else if ( aActionMenuType == EFocusOnNameInAddressField )
       
  2997         {
       
  2998         switch( aSelectedActionMenuItem )
       
  2999             {
       
  3000             case FsEActionMenuCall: // Call
       
  3001                 {
       
  3002                 CallHotSpotAddressL();
       
  3003                 }
       
  3004                 break;
       
  3005             case FsEActionMenuCreateMessage: // Create message
       
  3006                 {
       
  3007                 CreateMessageL();
       
  3008                 }
       
  3009                 break;
       
  3010             case FsEActionMenuCreateEmail: // Create message
       
  3011                 {
       
  3012                 ComposeMailL();
       
  3013                 }
       
  3014                 break;
       
  3015             case FsEActionMenuContactDetails: // Contact details
       
  3016                 {
       
  3017                 OpenContactDetailsL();
       
  3018                 }
       
  3019                 break;
       
  3020             case FsEActionMenuAddToContacts: // Add to Contacts
       
  3021                 {
       
  3022                 HBufC* emailAddress =
       
  3023                     iViewerRichText->GetHeaderHotspotEmailAddressLC(
       
  3024                         currentHeaderHotSpotData );
       
  3025                 SaveEmailAsContactL( *emailAddress );
       
  3026                 CleanupStack::PopAndDestroy( emailAddress );
       
  3027                 }
       
  3028                 break;
       
  3029             case FsEActionMenuRemoteLookup: // Remote lookup
       
  3030                 {
       
  3031                 HBufC* emailAddress =
       
  3032                     iViewerRichText->GetHeaderHotspotEmailAddressLC(
       
  3033                         currentHeaderHotSpotData );
       
  3034                 LaunchRemoteLookupL( *emailAddress );
       
  3035                 CleanupStack::PopAndDestroy( emailAddress );
       
  3036                 }
       
  3037                 break;
       
  3038             }
       
  3039         }
       
  3040     else if ( aActionMenuType == EFocusOnHyperLinkWithinMessage )
       
  3041         {
       
  3042         switch ( aSelectedActionMenuItem )
       
  3043             {
       
  3044             case FsEActionMenuOpenInWeb: // Open in web
       
  3045                 {
       
  3046                 OpenHotSpotUrlInBrowserL( currentBodyHotSpotData );
       
  3047                 }
       
  3048                 break;
       
  3049             case FsEActionMenuOpenInIntranet: // Open in intranet
       
  3050                 {
       
  3051                 OpenLinkInIntranetL( EFalse );
       
  3052                 }
       
  3053                 break;
       
  3054             case FsEActionMenuBookmark: // Bookmark
       
  3055                 {
       
  3056                 AddToBookmarksL( currentBodyHotSpotData );
       
  3057                 }
       
  3058                 break;
       
  3059             }
       
  3060         }
       
  3061     else if ( aActionMenuType == EFocusOnAttachmentName ||
       
  3062               aActionMenuType == EFocusOnAttachmentsText )
       
  3063         {
       
  3064         switch ( aSelectedActionMenuItem )
       
  3065             {
       
  3066             case FsEActionAttachmentOpen: // Open single attachment
       
  3067                 {
       
  3068                 OpenAttachmentL();
       
  3069                 }
       
  3070                 break;
       
  3071             case FsEActionAttachmentViewAll: // Open attachments list
       
  3072                 {
       
  3073                 OpenAttachmentsViewL();
       
  3074                 }
       
  3075                 break;
       
  3076             case FsEActionAttachmentDownload: // Dowload one
       
  3077             case FsEActionAttachmentDownloadAll : /// all attachments
       
  3078                 {
       
  3079                 StartDowloadingAttachmentsL();
       
  3080                 }
       
  3081                 break;
       
  3082             case FsEActionAttachmentCancelDownload: // Cancel one / all downloads
       
  3083             case FsEActionAttachmentCancelAllDownloads:
       
  3084                 {
       
  3085                 CancelDowloadingAttachmentsL();
       
  3086                 }
       
  3087                 break;
       
  3088             case FsEActionAttachmentSave: // Save one / all attachments
       
  3089             case FsEActionAttachmentSaveAll:
       
  3090                 {
       
  3091                 SaveAllAttachmentsL();
       
  3092                 }
       
  3093                 break;
       
  3094             case FsEActionAttachmentClearFetchedContent:
       
  3095                 {
       
  3096                 RemoveFetchedAttachmentL();
       
  3097                 }
       
  3098                 break;
       
  3099             }
       
  3100         }
       
  3101     else if ( aActionMenuType == EFocusOnEMailInBodyText )
       
  3102         {
       
  3103         switch ( aSelectedActionMenuItem )
       
  3104             {
       
  3105             case FsEActionMenuCall: // Call
       
  3106                 {
       
  3107                 CallHotSpotAddressL();
       
  3108                 }
       
  3109                 break;
       
  3110             case FsEActionMenuCreateMessage: // Create message
       
  3111                 {
       
  3112                 CreateMessageL();
       
  3113                 }
       
  3114                 break;
       
  3115             case FsEActionMenuCreateEmail: // Create message
       
  3116                 {
       
  3117                 ComposeMailL();
       
  3118                 }
       
  3119                 break;
       
  3120             case FsEActionMenuContactDetails: // Contact details
       
  3121                 {
       
  3122                 OpenContactDetailsL();
       
  3123                 }
       
  3124                 break;
       
  3125             case FsEActionMenuAddToContacts: // Add to Contacts
       
  3126                 {
       
  3127                 HBufC* hotspotText = iViewerRichText->GetHotspotTextLC(
       
  3128                     currentBodyHotSpotData );
       
  3129                 if ( currentBodyHotSpotData.iItemType ==
       
  3130                     CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
  3131                     {
       
  3132                     SavePhoneNumberAsContactL( *hotspotText );
       
  3133                     }
       
  3134                 else if ( currentBodyHotSpotData.iItemType ==
       
  3135                     CFindItemEngine::EFindItemSearchMailAddressBin )
       
  3136                     {
       
  3137                     SaveEmailAsContactL( *hotspotText );
       
  3138                     }
       
  3139                 else if ( currentBodyHotSpotData.iItemType ==
       
  3140                     CFindItemEngine::EFindItemSearchScheme )
       
  3141                     {
       
  3142                     if ( hotspotText->FindC( KMailtoPrefix ) == 0 )
       
  3143                         {
       
  3144                         // Save email as contact, address mailto: strip is done in SaveEmailAsContactL
       
  3145                         SaveEmailAsContactL( *hotspotText );
       
  3146                         }
       
  3147                     }
       
  3148                 CleanupStack::PopAndDestroy( hotspotText );
       
  3149                 }
       
  3150                 break;
       
  3151             case FsEActionMenuRemoteLookup: // Remote lookup
       
  3152                 {
       
  3153                 HBufC* hotspotText = iViewerRichText->GetHotspotTextLC(
       
  3154                     currentBodyHotSpotData );
       
  3155                 LaunchRemoteLookupL( *hotspotText );
       
  3156                 CleanupStack::PopAndDestroy( hotspotText );
       
  3157                 }
       
  3158                 break;
       
  3159             }
       
  3160         }
       
  3161     }
       
  3162 
       
  3163 // -----------------------------------------------------------------------------
       
  3164 // CFSEmailUiMailViewerVisualiser::OpenContactDetailsL
       
  3165 // -----------------------------------------------------------------------------
       
  3166 void CFSEmailUiMailViewerVisualiser::OpenContactDetailsL()
       
  3167     {
       
  3168     FUNC_LOG;
       
  3169     SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  3170     CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  3171     THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL( currentHeaderHotSpotData, currentBodyHotSpotData );
       
  3172 
       
  3173     HBufC* emailAddress = NULL;
       
  3174     if ( hotspotType == EHeaderHotspot )
       
  3175         {
       
  3176         emailAddress = iViewerRichText->GetHeaderHotspotEmailAddressLC( currentHeaderHotSpotData );
       
  3177         }
       
  3178     else if ( hotspotType == EBodyHotspot )
       
  3179         {
       
  3180         emailAddress = iViewerRichText->GetHotspotTextLC( currentBodyHotSpotData );
       
  3181         // Delete "mailto:" prefix if found
       
  3182         if ( emailAddress->FindC( KMailtoPrefix ) == 0 )
       
  3183             {
       
  3184             emailAddress->Des().Delete( 0, KMailtoPrefix().Length() );
       
  3185             }
       
  3186         }
       
  3187     else
       
  3188         {
       
  3189         return;
       
  3190         }
       
  3191 
       
  3192     CFsDelayedLoader::InstanceL()->GetContactHandlerL()->ShowContactDetailsL(
       
  3193             *emailAddress, EContactUpdateEmail, NULL );
       
  3194 
       
  3195     CleanupStack::PopAndDestroy( emailAddress );
       
  3196     }
       
  3197 
       
  3198 // -----------------------------------------------------------------------------
       
  3199 // CFSEmailUiMailViewerVisualiser::LaunchHtmlViewerL
       
  3200 // -----------------------------------------------------------------------------
       
  3201 void CFSEmailUiMailViewerVisualiser::LaunchHtmlViewerL()
       
  3202     {
       
  3203     FUNC_LOG;
       
  3204     if ( MessagePartFullyFetchedL( EMessageHtmlBodyPart ) )
       
  3205         {
       
  3206         THtmlViewerActivationData htmlData;
       
  3207         htmlData.iActivationDataType = THtmlViewerActivationData::EMailMessage;
       
  3208         htmlData.iMailBoxId = iMessage->GetMailBoxId();
       
  3209         htmlData.iFolderId = iMessage->GetFolderId();
       
  3210         htmlData.iMessageId = iMessage->GetMessageId();
       
  3211         htmlData.iEmbeddedMessageMode = iEmbeddedMessageMode;
       
  3212         TPckgBuf<THtmlViewerActivationData> pckgData( htmlData );
       
  3213 
       
  3214         iAppUi.EnterFsEmailViewL( HtmlViewerId, KHtmlViewerOpenNew, pckgData );
       
  3215         }
       
  3216     else
       
  3217         {
       
  3218         StartWaitedFetchingL( EMessageHtmlBodyPart );
       
  3219         }
       
  3220     }
       
  3221 
       
  3222 // -----------------------------------------------------------------------------
       
  3223 // CFSEmailUiMailViewerVisualiser::LaunchRemoteLookupL
       
  3224 // -----------------------------------------------------------------------------
       
  3225 void CFSEmailUiMailViewerVisualiser::LaunchRemoteLookupL( const TDesC& aDes ) const
       
  3226     {
       
  3227     FUNC_LOG;
       
  3228     // this method assumes that remote lookup is available with current plugin.
       
  3229     HBufC* textData = HBufC::NewLC( aDes.Length() );
       
  3230     textData->Des().Append( aDes );
       
  3231     if ( textData->FindC( KMailtoPrefix ) == 0 )
       
  3232         {
       
  3233         textData->Des().Delete( 0, KMailtoPrefix().Length() );
       
  3234         }
       
  3235     else if ( textData->FindC( KCallPrefix ) == 0 )
       
  3236         {
       
  3237         textData->Des().Delete( 0, KCallPrefix().Length() );
       
  3238         }
       
  3239     else if ( textData->FindC( KTelPrefix ) == 0 )
       
  3240         {
       
  3241         textData->Des().Delete( 0, KTelPrefix().Length() );
       
  3242         }
       
  3243     else if ( textData->FindC( KSmsPrefix ) == 0 )
       
  3244         {
       
  3245         textData->Des().Delete( 0, KSmsPrefix().Length() );
       
  3246         }
       
  3247     else if ( textData->FindC( KMmsPrefix ) == 0 )
       
  3248         {
       
  3249         textData->Des().Delete( 0, KMmsPrefix().Length() );
       
  3250         }
       
  3251     else if ( textData->FindC( KVoipPrefix ) == 0 )
       
  3252         {
       
  3253         textData->Des().Delete( 0, KVoipPrefix().Length() );
       
  3254         }
       
  3255 
       
  3256     CFsDelayedLoader::InstanceL()->GetContactHandlerL()->LaunchRemoteLookupWithQueryL( *iMailBox, *textData );
       
  3257     CleanupStack::PopAndDestroy( textData );
       
  3258     }
       
  3259 
       
  3260 // -----------------------------------------------------------------------------
       
  3261 // CFSEmailUiMailViewerVisualiser::AddToBookmarksL
       
  3262 // -----------------------------------------------------------------------------
       
  3263 void CFSEmailUiMailViewerVisualiser::AddToBookmarksL(
       
  3264                 const CFindItemEngine::SFoundItem& aBodyHotspotData ) const
       
  3265     {
       
  3266     FUNC_LOG;
       
  3267     HBufC* hotspotText =
       
  3268         iViewerRichText->GetHotspotTextLC( aBodyHotspotData );
       
  3269 
       
  3270     RFavouritesSession fSession;
       
  3271     User::LeaveIfError( fSession.Connect() );
       
  3272     CleanupClosePushL( fSession );
       
  3273 
       
  3274     RFavouritesDb favoris;
       
  3275     User::LeaveIfError( favoris.Open( fSession, KBrowserBookmarks ) );
       
  3276     CleanupClosePushL( favoris );
       
  3277 
       
  3278     CFavouritesItem *favorisItem = CFavouritesItem::NewLC();
       
  3279     favorisItem->SetType( CFavouritesItem::EItem );
       
  3280     favorisItem->SetUrlL( *hotspotText );
       
  3281     // Should be less than KFavouritesMaxName ( 50 )
       
  3282     if ( hotspotText->Length() > KFavouritesMaxName )
       
  3283         {
       
  3284         favorisItem->SetNameL( hotspotText->Left( KFavouritesMaxName ) );
       
  3285         }
       
  3286     else
       
  3287         {
       
  3288         favorisItem->SetNameL( *hotspotText );
       
  3289         }
       
  3290 
       
  3291     favorisItem->SetParentFolder( KFavouritesRootUid );
       
  3292 
       
  3293     TInt error = favoris.Add( *favorisItem, ETrue );
       
  3294 
       
  3295     CleanupStack::PopAndDestroy( favorisItem );
       
  3296     CleanupStack::PopAndDestroy( &favoris );
       
  3297     CleanupStack::PopAndDestroy( &fSession );
       
  3298 
       
  3299     CleanupStack::PopAndDestroy( hotspotText );
       
  3300 
       
  3301     if ( error == KErrNone )
       
  3302         {
       
  3303         TFsEmailUiUtility::ShowInfoNoteL(
       
  3304             R_FREESTYLE_EMAIL_UI_VIEWER_BOOKMARK_ADDED, ETrue );
       
  3305         }
       
  3306     else // Error in bookmark creation, show could not complete message
       
  3307         {
       
  3308         TFsEmailUiUtility::ShowErrorNoteL(
       
  3309             R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE, ETrue );
       
  3310         }
       
  3311     }
       
  3312 
       
  3313 // -----------------------------------------------------------------------------
       
  3314 // CFSEmailUiMailViewerVisualiser::CallHotSpotAddressL
       
  3315 // -----------------------------------------------------------------------------
       
  3316 void CFSEmailUiMailViewerVisualiser::CallHotSpotAddressL()
       
  3317     {
       
  3318     FUNC_LOG;
       
  3319     SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  3320     CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  3321     THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL( currentHeaderHotSpotData, currentBodyHotSpotData );
       
  3322 
       
  3323    if( hotspotType == EHeaderHotspot &&  currentHeaderHotSpotData.iType == ETypeFromAddressDisplayName )
       
  3324         {
       
  3325         HBufC* emailAddress = iViewerRichText->GetHeaderHotspotEmailAddressLC( currentHeaderHotSpotData );
       
  3326            CFsDelayedLoader::InstanceL()->GetContactHandlerL()->FindAndCallToContactByEmailL( *emailAddress,
       
  3327                     iAppUi.GetActiveMailbox(), this, ETrue /*use call sender text*/);
       
  3328            CleanupStack::PopAndDestroy( emailAddress );
       
  3329         }
       
  3330    else if( ( hotspotType == EHeaderHotspot &&
       
  3331             ( currentHeaderHotSpotData.iType == ETypeToAddressDisplayName ||
       
  3332             currentHeaderHotSpotData.iType == ETypeCcAddressDisplayName ||
       
  3333             currentHeaderHotSpotData.iType == ETypeBccAddressDisplayName ||
       
  3334             currentHeaderHotSpotData.iType == ETypeEmailAddress )
       
  3335             )
       
  3336         )
       
  3337         {
       
  3338         HBufC* emailAddress = iViewerRichText->GetHeaderHotspotEmailAddressLC( currentHeaderHotSpotData );
       
  3339         CFsDelayedLoader::InstanceL()->GetContactHandlerL()->FindAndCallToContactByEmailL( *emailAddress,
       
  3340                  iAppUi.GetActiveMailbox(), this, EFalse /*use call sender text*/);
       
  3341         CleanupStack::PopAndDestroy( emailAddress );
       
  3342         }
       
  3343     else if( hotspotType == EBodyHotspot &&
       
  3344                 currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchMailAddressBin  )
       
  3345         {
       
  3346         HBufC* emailAddress = iViewerRichText->GetHotspotTextLC( currentBodyHotSpotData );
       
  3347         CFsDelayedLoader::InstanceL()->GetContactHandlerL()->FindAndCallToContactByEmailL( *emailAddress,
       
  3348                  iAppUi.GetActiveMailbox(), this, EFalse );
       
  3349         CleanupStack::PopAndDestroy( emailAddress );
       
  3350         }
       
  3351     else if( hotspotType == EBodyHotspot &&
       
  3352                 currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
  3353         {
       
  3354         CallToBodyHotSpotNumberL( currentBodyHotSpotData );
       
  3355         }
       
  3356     else if ( currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchScheme )
       
  3357         {
       
  3358         // Get scheme text and make sure there is "mailto:" text or "call:" text
       
  3359         HBufC* schemeText = iViewerRichText->GetHotspotTextLC( currentBodyHotSpotData );
       
  3360         if ( schemeText &&  schemeText->FindC( KMailtoPrefix ) == 0 )
       
  3361             {
       
  3362             schemeText->Des().Delete( 0, KMailtoPrefix().Length() );
       
  3363             CFsDelayedLoader::InstanceL()->GetContactHandlerL()->FindAndCallToContactByEmailL( *schemeText,
       
  3364                  iAppUi.GetActiveMailbox(), this, EFalse);
       
  3365             }
       
  3366         else if ( schemeText->FindC( KCallPrefix ) == 0 ||
       
  3367                   schemeText->FindC( KTelPrefix ) == 0 ||
       
  3368                   schemeText->FindC( KSmsPrefix ) == 0 ||
       
  3369                   schemeText->FindC( KMmsPrefix ) == 0 ||
       
  3370                   schemeText->FindC( KVoipPrefix ) == 0 )
       
  3371             {
       
  3372             CallToBodyHotSpotNumberL( currentBodyHotSpotData );
       
  3373             }
       
  3374         CleanupStack::PopAndDestroy( schemeText );
       
  3375         }
       
  3376 
       
  3377     }
       
  3378 
       
  3379 // -----------------------------------------------------------------------------
       
  3380 // CFSEmailUiMailViewerVisualiser::CreateMessageL
       
  3381 // -----------------------------------------------------------------------------
       
  3382 void CFSEmailUiMailViewerVisualiser::CreateMessageL() const
       
  3383     {
       
  3384     FUNC_LOG;
       
  3385     SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  3386     CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  3387     THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL( currentHeaderHotSpotData, currentBodyHotSpotData );
       
  3388 
       
  3389     if( hotspotType == EHeaderHotspot )
       
  3390         {
       
  3391         HBufC* emailAddress = iViewerRichText->GetHeaderHotspotEmailAddressLC( currentHeaderHotSpotData );
       
  3392         CFSEmailUiContactHandler* cntHandlerInstance = CFsDelayedLoader::InstanceL()->GetContactHandlerL();
       
  3393         cntHandlerInstance->FindAndCreateMsgToContactByEmailL( *emailAddress, iAppUi.GetActiveMailbox() );
       
  3394         CleanupStack::PopAndDestroy( emailAddress );
       
  3395         }
       
  3396     else if( hotspotType == EBodyHotspot )
       
  3397         {
       
  3398         // Sending based on email address, goes to contact handler
       
  3399         if ( currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchMailAddressBin )
       
  3400             {
       
  3401             HBufC* emailAddress = iViewerRichText->GetHotspotTextLC( currentBodyHotSpotData );
       
  3402             CFSEmailUiContactHandler* cntHandlerInstance = CFsDelayedLoader::InstanceL()->GetContactHandlerL();
       
  3403             cntHandlerInstance->FindAndCreateMsgToContactByEmailL( *emailAddress, iAppUi.GetActiveMailbox() );
       
  3404             CleanupStack::PopAndDestroy( emailAddress );
       
  3405             }
       
  3406         // Sending based on found number, goes to utility class
       
  3407         else if ( currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
  3408             {
       
  3409             HBufC* hotspotText = iViewerRichText->GetHotspotTextLC( currentBodyHotSpotData );
       
  3410             TFsEmailUiUtility::ShowCreateMessageQueryL( *hotspotText );
       
  3411             CleanupStack::PopAndDestroy( hotspotText );
       
  3412             }
       
  3413         else if ( currentBodyHotSpotData.iItemType == CFindItemEngine::EFindItemSearchScheme )
       
  3414             {
       
  3415             // Get scheme text and make sure there is "mailto:" text or "call:" text
       
  3416             HBufC* schemeText = iViewerRichText->GetHotspotTextLC( currentBodyHotSpotData );
       
  3417             if ( schemeText && ( schemeText->FindC( KMailtoPrefix ) == 0 ||
       
  3418                  schemeText->FindC( KVoipPrefix ) == 0) )
       
  3419                 {
       
  3420                 schemeText->Des().Delete( 0, KMailtoPrefix().Length() );
       
  3421                 CFSEmailUiContactHandler* cntHandlerInstance = CFsDelayedLoader::InstanceL()->GetContactHandlerL();
       
  3422                 cntHandlerInstance->FindAndCreateMsgToContactByEmailL( *schemeText, iAppUi.GetActiveMailbox() );
       
  3423                 }
       
  3424             else if ( schemeText && schemeText->FindC( KCallPrefix ) == 0 )
       
  3425                 {
       
  3426                 schemeText->Des().Delete( 0, KCallPrefix().Length() );
       
  3427                 TFsEmailUiUtility::ShowCreateMessageQueryL( *schemeText );
       
  3428                 }
       
  3429             else if ( schemeText && schemeText->FindC( KTelPrefix ) == 0 )
       
  3430                 {
       
  3431                 schemeText->Des().Delete( 0, KTelPrefix().Length() );
       
  3432                 TFsEmailUiUtility::ShowCreateMessageQueryL( *schemeText );
       
  3433                 }
       
  3434             else if ( schemeText && schemeText->FindC( KSmsPrefix ) == 0 )
       
  3435                 {
       
  3436                 schemeText->Des().Delete( 0, KSmsPrefix().Length() );
       
  3437                 TFsEmailUiUtility::ShowCreateMessageQueryL( *schemeText );
       
  3438                 }
       
  3439             else if ( schemeText && schemeText->FindC( KMmsPrefix ) == 0 )
       
  3440                 {
       
  3441                 schemeText->Des().Delete( 0, KMmsPrefix().Length() );
       
  3442                 TFsEmailUiUtility::ShowCreateMessageQueryL( *schemeText );
       
  3443                 }
       
  3444             CleanupStack::PopAndDestroy( schemeText );
       
  3445             }
       
  3446         }
       
  3447     }
       
  3448 
       
  3449 TBool CFSEmailUiMailViewerVisualiser::IsCopyToClipBoardAvailableL() const
       
  3450     {
       
  3451     FUNC_LOG;
       
  3452     TBool available = EFalse;
       
  3453     TInt ignoreThis( 0 );
       
  3454     TBool visibleHotsSpot =
       
  3455         iTextViewer->GetVisibleFocusedHotspotLine( ignoreThis );
       
  3456 
       
  3457     // Copy to clipboard is hidden if there's no visible hotspot focus
       
  3458     if ( visibleHotsSpot )
       
  3459         {
       
  3460         // Check the type of focused hotspot
       
  3461         SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  3462         CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  3463         THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL(
       
  3464             currentHeaderHotSpotData, currentBodyHotSpotData );
       
  3465 
       
  3466         if ( hotspotType == EBodyHotspot )
       
  3467             {
       
  3468             // copying is available for all body hotspots
       
  3469             available = ETrue;
       
  3470             }
       
  3471         else if ( hotspotType == EHeaderHotspot )
       
  3472             {
       
  3473             // in header, copying is available for email addresses
       
  3474             switch ( currentHeaderHotSpotData.iType )
       
  3475                 {
       
  3476                 case ETypeFromAddressDisplayName:
       
  3477                 case ETypeToAddressDisplayName:
       
  3478                 case ETypeCcAddressDisplayName:
       
  3479                 case ETypeBccAddressDisplayName:
       
  3480                 case ETypeEmailAddress:
       
  3481                     available = ETrue;
       
  3482                     break;
       
  3483                 default:
       
  3484                     available = EFalse;
       
  3485                     break;
       
  3486                 }
       
  3487             }
       
  3488         else // hotspotType == ENoHotspot
       
  3489             {
       
  3490             available = EFalse;
       
  3491             }
       
  3492         }
       
  3493 
       
  3494     return available;
       
  3495     }
       
  3496 
       
  3497 // -----------------------------------------------------------------------------
       
  3498 // CFSEmailUiMailViewerVisualiser::CopyCurrentHotspotToClipBoardL
       
  3499 // -----------------------------------------------------------------------------
       
  3500 void CFSEmailUiMailViewerVisualiser::CopyCurrentHotspotToClipBoardL() const
       
  3501     {
       
  3502     FUNC_LOG;
       
  3503     TInt ignoreThis( 0 );
       
  3504     TBool visibleHotsSpot =
       
  3505         iTextViewer->GetVisibleFocusedHotspotLine( ignoreThis );
       
  3506 
       
  3507     // Copy to clipboard is disabled if there's no visible hotspot focus
       
  3508     if ( visibleHotsSpot )
       
  3509         {
       
  3510         HBufC* clipBoardText = NULL;
       
  3511         SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  3512         CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  3513         THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL( currentHeaderHotSpotData, currentBodyHotSpotData );
       
  3514 
       
  3515         if ( hotspotType == EHeaderHotspot )
       
  3516             {
       
  3517             switch ( currentHeaderHotSpotData.iType )
       
  3518                 {
       
  3519                 case ETypeFromAddressDisplayName:
       
  3520                 case ETypeToAddressDisplayName:
       
  3521                 case ETypeCcAddressDisplayName:
       
  3522                 case ETypeBccAddressDisplayName:
       
  3523                     {
       
  3524                     // Get email address attachned to display name, cropped display name has no use
       
  3525                     clipBoardText = iViewerRichText->GetEmailAddressLC( currentHeaderHotSpotData );
       
  3526                     }
       
  3527                     break;
       
  3528                 case ETypeEmailAddress:
       
  3529                     {
       
  3530                     clipBoardText = iViewerRichText->GetHotspotTextLC( currentHeaderHotSpotData );
       
  3531                     }
       
  3532                     break;
       
  3533                 }
       
  3534             }
       
  3535         else if ( hotspotType == EBodyHotspot )
       
  3536             {
       
  3537             clipBoardText = iViewerRichText->GetHotspotTextLC( currentBodyHotSpotData );
       
  3538             }
       
  3539 
       
  3540         if ( clipBoardText )
       
  3541             {
       
  3542             CClipboard* cb = CClipboard::NewForWritingLC( CCoeEnv::Static()->FsSession() );
       
  3543             cb->StreamDictionary().At( KClipboardUidTypePlainText );
       
  3544             CPlainText* plainText = CPlainText::NewL();
       
  3545             CleanupStack::PushL( plainText );
       
  3546             plainText->InsertL( 0 , *clipBoardText );
       
  3547             plainText->CopyToStoreL( cb->Store(), cb->StreamDictionary(), 0, plainText->DocumentLength() );
       
  3548             CleanupStack::PopAndDestroy( plainText );
       
  3549             cb->CommitL();
       
  3550             CleanupStack::PopAndDestroy( cb );
       
  3551             CleanupStack::PopAndDestroy( clipBoardText );
       
  3552             }
       
  3553         }
       
  3554     }
       
  3555 
       
  3556 // -----------------------------------------------------------------------------
       
  3557 // CFSEmailUiMailViewerVisualiser::ShowOpenAttachmentOptionL
       
  3558 // -----------------------------------------------------------------------------
       
  3559 TBool CFSEmailUiMailViewerVisualiser::ShowOpenAttachmentOptionL()
       
  3560     {
       
  3561     FUNC_LOG;
       
  3562     TInt ret = EFalse;
       
  3563 
       
  3564     RPointerArray<CFSMailMessagePart> attachments;
       
  3565     CleanupResetAndDestroyClosePushL( attachments );
       
  3566     iMessage->AttachmentListL( attachments );
       
  3567 
       
  3568     // The Open option is always available when focus on the multiple
       
  3569     // attachments item.
       
  3570     if ( attachments.Count() > 1 )
       
  3571         {
       
  3572         ret = ETrue;
       
  3573         }
       
  3574     // When focus on single attachment item, the Open is shown only when the
       
  3575     // attachment is fully downloaded
       
  3576     else if ( attachments.Count() == 1 )
       
  3577         {
       
  3578         TPartData partData = MailData();
       
  3579         partData.iMessagePartId = attachments[0]->GetPartId();
       
  3580         if ( iAppUi.DownloadInfoMediator() && !iAppUi.DownloadInfoMediator()->IsDownloadableL( partData ) &&
       
  3581              !iAppUi.DownloadInfoMediator()->IsDownloading( partData.iMessagePartId ) )
       
  3582             {
       
  3583             ret = ETrue;
       
  3584             }
       
  3585         }
       
  3586     else
       
  3587         {
       
  3588         ret = EFalse;
       
  3589         }
       
  3590 
       
  3591     CleanupStack::PopAndDestroy( &attachments );
       
  3592     return ret;
       
  3593     }
       
  3594 
       
  3595 // -----------------------------------------------------------------------------
       
  3596 // CFSEmailUiMailViewerVisualiser::ShowSaveAttachmentOptionL
       
  3597 // -----------------------------------------------------------------------------
       
  3598 TBool CFSEmailUiMailViewerVisualiser::ShowSaveAttachmentOptionL()
       
  3599     {
       
  3600     FUNC_LOG;
       
  3601     // Save (all) is displayed if there are no ongoing downloads.
       
  3602     TBool saveAvailable = !ShowCancelDownloadOption();
       
  3603 
       
  3604     // When viewing an embedded message object, saving needs to be disabled
       
  3605     // in case there are any attachments of message type. This is due to
       
  3606     // limitations in the Activesync plugin.
       
  3607     if ( saveAvailable && iEmbeddedMessageMode )
       
  3608         {
       
  3609         RPointerArray<CFSMailMessagePart> attachments;
       
  3610         CleanupResetAndDestroyClosePushL( attachments );
       
  3611         iMessage->AttachmentListL( attachments );
       
  3612 
       
  3613         for ( TInt i = 0 ; i < attachments.Count() && saveAvailable ; ++i )
       
  3614             {
       
  3615             const TDesC& attName = attachments[i]->AttachmentNameL();
       
  3616             const TDesC& attMime = attachments[i]->GetContentType();
       
  3617             TFileType attType = TFsEmailUiUtility::GetFileType( attName, attMime );
       
  3618             if ( attType == EMessageType )
       
  3619                 {
       
  3620                 saveAvailable = EFalse;
       
  3621                 }
       
  3622             }
       
  3623 
       
  3624         CleanupStack::PopAndDestroy( &attachments );
       
  3625         }
       
  3626     return saveAvailable;
       
  3627     }
       
  3628 
       
  3629 // -----------------------------------------------------------------------------
       
  3630 // CFSEmailUiMailViewerVisualiser::ShowDownloadOptionL
       
  3631 // -----------------------------------------------------------------------------
       
  3632 TBool CFSEmailUiMailViewerVisualiser::ShowDownloadOptionL()
       
  3633     {
       
  3634     FUNC_LOG;
       
  3635     TBool retVal = EFalse;
       
  3636 
       
  3637     TPartData partData = MailData();
       
  3638 
       
  3639     RPointerArray<CFSMailMessagePart> attachments;
       
  3640     CleanupResetAndDestroyClosePushL( attachments );
       
  3641     iMessage->AttachmentListL( attachments );
       
  3642     TInt attachmentsCount = attachments.Count();
       
  3643     for ( TInt i = 0; i < attachmentsCount; i++ )
       
  3644         {
       
  3645         partData.iMessagePartId = attachments[i]->GetPartId();
       
  3646         if ( iAppUi.DownloadInfoMediator() && iAppUi.DownloadInfoMediator()->IsDownloadableL( partData ) )
       
  3647             {
       
  3648             retVal = ETrue;
       
  3649             break;
       
  3650             }
       
  3651         }
       
  3652     CleanupStack::PopAndDestroy( &attachments );
       
  3653     return retVal;
       
  3654     }
       
  3655 
       
  3656 
       
  3657 // -----------------------------------------------------------------------------
       
  3658 // CFSEmailUiMailViewerVisualiser::ShowDownloadOptionL
       
  3659 // -----------------------------------------------------------------------------
       
  3660 TBool CFSEmailUiMailViewerVisualiser::ShowMskDownloadOptionL()
       
  3661     {
       
  3662     FUNC_LOG;
       
  3663     // Check status only if download status might have changed
       
  3664     TBool ret( EFalse );
       
  3665     if ( iMessage && iMessage->IsFlagSet(EFSMsgFlag_Attachments) )
       
  3666         {
       
  3667         TPartData partData = MailData();
       
  3668         RPointerArray<CFSMailMessagePart> attachments;
       
  3669         CleanupResetAndDestroyClosePushL( attachments );
       
  3670         iMessage->AttachmentListL( attachments );
       
  3671         // Safety, this function should not be called for any other amount than 1
       
  3672         if ( attachments.Count() == 1 )
       
  3673             {
       
  3674             partData.iMessagePartId = attachments[0]->GetPartId();
       
  3675             if ( iAppUi.DownloadInfoMediator() && iAppUi.DownloadInfoMediator()->IsDownloadableL( partData ) )
       
  3676                 {
       
  3677                 ret = ETrue;
       
  3678                 }
       
  3679             }
       
  3680         CleanupStack::PopAndDestroy( &attachments );
       
  3681         }
       
  3682     return ret;
       
  3683     }
       
  3684 
       
  3685 
       
  3686 // -----------------------------------------------------------------------------
       
  3687 // CFSEmailUiMailViewerVisualiser::ShowCancelDownloadOption
       
  3688 // -----------------------------------------------------------------------------
       
  3689 TBool CFSEmailUiMailViewerVisualiser::ShowCancelDownloadOption()
       
  3690     {
       
  3691     FUNC_LOG;
       
  3692     TBool ret( EFalse );
       
  3693     if ( iMessage && iAppUi.DownloadInfoMediator() )
       
  3694         {
       
  3695         ret = iAppUi.DownloadInfoMediator()->IsAnyAttachmentDownloads(
       
  3696                 iMessage->GetMessageId() );
       
  3697         }
       
  3698     return ret;
       
  3699     }
       
  3700 
       
  3701 // -----------------------------------------------------------------------------
       
  3702 // CFSEmailUiMailViewerVisualiser::OpenAttachmentL
       
  3703 // -----------------------------------------------------------------------------
       
  3704 void CFSEmailUiMailViewerVisualiser::OpenAttachmentL()
       
  3705     {
       
  3706     FUNC_LOG;
       
  3707     if ( !iMessage )
       
  3708         {
       
  3709         User::Leave( KErrNotReady );
       
  3710         }
       
  3711 
       
  3712     RPointerArray<CFSMailMessagePart> attachments;
       
  3713     CleanupResetAndDestroyClosePushL( attachments );
       
  3714     iMessage->AttachmentListL( attachments );
       
  3715 
       
  3716     // start downloading if not yet downloaded.
       
  3717     if ( ShowDownloadOptionL() )
       
  3718         {
       
  3719         StartDowloadingAttachmentsL();
       
  3720         }
       
  3721     else if ( ShowCancelDownloadOption() ) // show download ongoing info
       
  3722         {
       
  3723         TFsEmailUiUtility::ShowInfoNoteL(
       
  3724             R_FSE_VIEWER_NOTE_ATTACHMENT_DOWNLOADING_PROGRESS );
       
  3725         }
       
  3726     else // open if attachment is already downloaded
       
  3727         {
       
  3728         TInt attachmentsCount = attachments.Count();
       
  3729         if ( attachmentsCount )
       
  3730             {
       
  3731             // <cmail>
       
  3732             TFsEmailUiUtility::OpenAttachmentL( *attachments[attachmentsCount-1] );
       
  3733             // </cmail>
       
  3734             }
       
  3735         }
       
  3736 
       
  3737     CleanupStack::PopAndDestroy( &attachments );
       
  3738     }
       
  3739 
       
  3740 // -----------------------------------------------------------------------------
       
  3741 // CFSEmailUiMailViewerVisualiser::OpenAttachmentsViewL
       
  3742 // -----------------------------------------------------------------------------
       
  3743 void CFSEmailUiMailViewerVisualiser::OpenAttachmentsViewL()
       
  3744     {
       
  3745     FUNC_LOG;
       
  3746     // give pointer to current for attachments list view
       
  3747     TAttachmentListActivationData params;
       
  3748     params.iMailBoxId = iMessage->GetMailBoxId();
       
  3749     params.iFolderId = iMessage->GetFolderId();
       
  3750     params.iMessageId = iMessage->GetMessageId();
       
  3751     params.iEmbeddedMsgMode = iEmbeddedMessageMode;
       
  3752     // use package buffer to pass the params
       
  3753     TPckgBuf<TAttachmentListActivationData> buf( params );
       
  3754     TUid emptyCustomMessageId = { 0 };
       
  3755     iAppUi.EnterFsEmailViewL(
       
  3756         AttachmentMngrViewId, emptyCustomMessageId, buf );
       
  3757     }
       
  3758 
       
  3759 // -----------------------------------------------------------------------------
       
  3760 // CFSEmailUiMailViewerVisualiser::StartDowloadingAttachmentsL
       
  3761 // -----------------------------------------------------------------------------
       
  3762 void CFSEmailUiMailViewerVisualiser::StartDowloadingAttachmentsL()
       
  3763     {
       
  3764     FUNC_LOG;
       
  3765     TPartData partData = MailData();
       
  3766 
       
  3767     RPointerArray<CFSMailMessagePart> attachments;
       
  3768     CleanupResetAndDestroyClosePushL( attachments );
       
  3769     iMessage->AttachmentListL( attachments );
       
  3770     TInt attachmentsCount = attachments.Count();
       
  3771     for( TInt i = 0; i < attachmentsCount; i++)
       
  3772         {
       
  3773         if ( attachments[i]->FetchLoadState() == EFSNone ||
       
  3774              attachments[i]->FetchLoadState() == EFSPartial )
       
  3775             {
       
  3776             partData.iMessagePartId = attachments[i]->GetPartId();
       
  3777             if ( iAppUi.DownloadInfoMediator() )
       
  3778                 {
       
  3779                 iAppUi.DownloadInfoMediator()->DownloadL( partData );
       
  3780                 }
       
  3781             }
       
  3782         }
       
  3783     CleanupStack::PopAndDestroy( &attachments );
       
  3784     }
       
  3785 
       
  3786 // -----------------------------------------------------------------------------
       
  3787 // CFSEmailUiMailViewerVisualiser::CancelDowloadingAttachmentsL
       
  3788 // -----------------------------------------------------------------------------
       
  3789 void CFSEmailUiMailViewerVisualiser::CancelDowloadingAttachmentsL()
       
  3790     {
       
  3791     FUNC_LOG;
       
  3792     RPointerArray<CFSMailMessagePart> attachments;
       
  3793     CleanupResetAndDestroyClosePushL( attachments );
       
  3794     iMessage->AttachmentListL( attachments );
       
  3795     TInt attachmentsCount = attachments.Count();
       
  3796 
       
  3797     // ask confirmation for cancel
       
  3798     TInt promptTextId = R_FSE_VIEWER_CANCEL_DOWNLOAD_QUERY;
       
  3799     if ( attachmentsCount > 1 )
       
  3800         {
       
  3801         promptTextId = R_FSE_VIEWER_CANCEL_DOWNLOADS_QUERY;
       
  3802         }
       
  3803 
       
  3804     if ( TFsEmailUiUtility::ShowConfirmationQueryL(promptTextId) && iAppUi.DownloadInfoMediator() )
       
  3805         {
       
  3806         for ( TInt i = 0 ; i < attachmentsCount ; i++ )
       
  3807             {
       
  3808             TFSPartFetchState fetchState = attachments[i]->FetchLoadState();
       
  3809             if ( fetchState == EFSPartial || fetchState == EFSNone )
       
  3810                 {
       
  3811                 iAppUi.DownloadInfoMediator()->CancelDownloadL( attachments[i]->GetPartId() );
       
  3812                 }
       
  3813             }
       
  3814         }
       
  3815     CleanupStack::PopAndDestroy( &attachments );
       
  3816     }
       
  3817 
       
  3818 // -----------------------------------------------------------------------------
       
  3819 // CFSEmailUiMailViewerVisualiser::SaveAllAttachmentsL
       
  3820 // -----------------------------------------------------------------------------
       
  3821 void CFSEmailUiMailViewerVisualiser::SaveAllAttachmentsL()
       
  3822     {
       
  3823     FUNC_LOG;
       
  3824     TFileName fileName;
       
  3825     if ( TFsEmailUiUtility::ShowSaveFolderDialogL( fileName ) )
       
  3826         {
       
  3827         // start downloading attachemts which are not downloaded.
       
  3828         // Save all attachment which all already downloaded
       
  3829         TPartData partData = MailData();
       
  3830 
       
  3831         RPointerArray<CFSMailMessagePart> attachments;
       
  3832         CleanupResetAndDestroyClosePushL( attachments );
       
  3833         iMessage->AttachmentListL( attachments );
       
  3834         TInt attachmentsCount = attachments.Count();
       
  3835 
       
  3836         // <cmail> remove the MRUI part of the message so we
       
  3837         // don't save unnecessary .ics file
       
  3838         CFSMailMessagePart* calendarPart = iMessage->FindBodyPartL( KFSMailContentTypeTextCalendar );
       
  3839         CleanupStack::PushL( calendarPart );
       
  3840         // </cmail>
       
  3841 
       
  3842         TInt savedCount( 0 );
       
  3843         for ( TInt i = 0; i < attachmentsCount; i++ )
       
  3844             {
       
  3845             partData.iMessagePartId = attachments[i]->GetPartId();
       
  3846             if ( iAppUi.DownloadInfoMediator() && iAppUi.DownloadInfoMediator()->IsDownloadableL( partData ) )
       
  3847                 { // start download and let mediator do the saving
       
  3848                 iAppUi.DownloadInfoMediator()->DownloadAndSaveL( partData, fileName );
       
  3849                 }
       
  3850             else // save immediately.
       
  3851                 {
       
  3852                 // <cmail>
       
  3853                 if( (calendarPart && partData.iMessagePartId != calendarPart->GetPartId() ||
       
  3854                     !calendarPart) && TFsEmailUiUtility::OkToSaveFileL( fileName, *attachments[i] ) )
       
  3855                     {
       
  3856                     attachments[i]->CopyContentFileL( fileName );
       
  3857                     savedCount++;
       
  3858                     }
       
  3859                 // </cmail>
       
  3860                 }
       
  3861             }
       
  3862         if ( savedCount )
       
  3863             {
       
  3864             TFsEmailUiUtility::ShowFilesSavedToFolderNoteL( savedCount );
       
  3865             }
       
  3866         // <cmail>
       
  3867         CleanupStack::PopAndDestroy( calendarPart );
       
  3868         // </cmail>
       
  3869         CleanupStack::PopAndDestroy( &attachments );
       
  3870         }
       
  3871     }
       
  3872 
       
  3873 // -----------------------------------------------------------------------------
       
  3874 // CFSEmailUiMailViewerVisualiser::RemoveFetchedAttachmentL
       
  3875 // -----------------------------------------------------------------------------
       
  3876 void CFSEmailUiMailViewerVisualiser::RemoveFetchedAttachmentL()
       
  3877     {
       
  3878     FUNC_LOG;
       
  3879     TInt reallyClear =
       
  3880         TFsEmailUiUtility::ShowConfirmationQueryL( R_FSE_VIEWER_CLEAR_FETCHED_QUERY );
       
  3881     if ( reallyClear )
       
  3882         {
       
  3883         RPointerArray<CFSMailMessagePart> attachments;
       
  3884         CleanupResetAndDestroyClosePushL( attachments );
       
  3885         iMessage->AttachmentListL( attachments );
       
  3886         TInt attachmentsCount = attachments.Count();
       
  3887         for ( TInt i = 0; i < attachmentsCount; i++ )
       
  3888             {
       
  3889             attachments[i]->RemoveContentL();
       
  3890             }
       
  3891         CleanupStack::PopAndDestroy( &attachments );
       
  3892         iShowMskDownloadOption = ShowMskDownloadOptionL();
       
  3893         SetMskL();
       
  3894         }
       
  3895     }
       
  3896 
       
  3897 // -----------------------------------------------------------------------------
       
  3898 // CFSEmailUiMailViewerVisualiser::MailData
       
  3899 // -----------------------------------------------------------------------------
       
  3900 TPartData CFSEmailUiMailViewerVisualiser::MailData()
       
  3901     {
       
  3902     FUNC_LOG;
       
  3903     TPartData newPartData;
       
  3904     newPartData.iMailBoxId = iMessage->GetMailBoxId();
       
  3905     newPartData.iFolderId = iMessage->GetFolderId();
       
  3906     newPartData.iMessageId = iMessage->GetMessageId();
       
  3907     return newPartData;
       
  3908     }
       
  3909 
       
  3910 // -----------------------------------------------------------------------------
       
  3911 // CFSEmailUiMailViewerVisualiser::StartFetchingBodyAfterOpeningL
       
  3912 // -----------------------------------------------------------------------------
       
  3913 TBool CFSEmailUiMailViewerVisualiser::StartFetchingBodyAfterOpeningL() const
       
  3914     {
       
  3915     FUNC_LOG;
       
  3916     TBool retVal = EFalse;
       
  3917     CFSMailMessagePart* textPart = iMessage->PlainTextBodyPartL();
       
  3918     if ( textPart )
       
  3919         {
       
  3920         TFSPartFetchState currentPlainTextFetchState = textPart->FetchLoadState();
       
  3921         if ( currentPlainTextFetchState == EFSNone )
       
  3922             {
       
  3923             retVal = ETrue;
       
  3924             }
       
  3925         }
       
  3926     delete textPart;
       
  3927     return retVal;
       
  3928     }
       
  3929 
       
  3930 // -----------------------------------------------------------------------------
       
  3931 // CFSEmailUiMailViewerVisualiser::MessagePartFullyFetchedL
       
  3932 // -----------------------------------------------------------------------------
       
  3933 TBool CFSEmailUiMailViewerVisualiser::MessagePartFullyFetchedL( TFetchedContentType aFetchedContentType ) const
       
  3934     {
       
  3935     FUNC_LOG;
       
  3936     TBool retVal = ETrue;
       
  3937     if( aFetchedContentType == EMessagePlainTextBodyPart )
       
  3938         {
       
  3939         CFSMailMessagePart* textPart = iMessage->PlainTextBodyPartL();
       
  3940         if( textPart )
       
  3941             {
       
  3942             TFSPartFetchState currentPlainTextFetchState = textPart->FetchLoadState();
       
  3943             if( currentPlainTextFetchState != EFSFull )
       
  3944                 {
       
  3945                 retVal = EFalse;
       
  3946                 }
       
  3947             }
       
  3948         delete textPart;
       
  3949         }
       
  3950     else if( aFetchedContentType == EMessageHtmlBodyPart )
       
  3951         {
       
  3952         CFSMailMessagePart* htmlPart = iMessage->HtmlBodyPartL();
       
  3953         if( htmlPart )
       
  3954             {
       
  3955             TFSPartFetchState currentHtmlTextFetchState = htmlPart->FetchLoadState();
       
  3956             if( currentHtmlTextFetchState != EFSFull )
       
  3957                 {
       
  3958                 retVal = EFalse;
       
  3959                 }
       
  3960             }
       
  3961         delete htmlPart;
       
  3962         }
       
  3963     else if( aFetchedContentType == EMessageStructure )
       
  3964         {
       
  3965         retVal = MessageStructureKnown( *iMessage );
       
  3966         }
       
  3967     else
       
  3968         {
       
  3969         User::Leave( KErrNotSupported );
       
  3970         }
       
  3971     return retVal;
       
  3972     }
       
  3973 
       
  3974 // -----------------------------------------------------------------------------
       
  3975 // CFSEmailUiMailViewerVisualiser::StartFetchingMessagePartL
       
  3976 // -----------------------------------------------------------------------------
       
  3977 void CFSEmailUiMailViewerVisualiser::StartFetchingMessagePartL( CFSMailMessage& aMessagePtr,
       
  3978                                             TFetchedContentType aFetchedContentType )
       
  3979     {
       
  3980     FUNC_LOG;
       
  3981     if( aFetchedContentType == EMessagePlainTextBodyPart )
       
  3982         {
       
  3983         CFSMailMessagePart* textPart = aMessagePtr.PlainTextBodyPartL();
       
  3984         CleanupStack::PushL( textPart );
       
  3985         TFSMailMsgId textPartId = textPart->GetPartId();
       
  3986         iFetchingPlainTextMessageBody = ETrue;
       
  3987         iCurrentPlainTextBodyFetchRequestId = textPart->FetchMessagePartL( textPartId, *this, 0 );
       
  3988         CleanupStack::PopAndDestroy( textPart );
       
  3989         }
       
  3990     else if( aFetchedContentType == EMessageHtmlBodyPart )
       
  3991         {
       
  3992         CFSMailMessagePart* htmlPart = aMessagePtr.HtmlBodyPartL();
       
  3993         CleanupStack::PushL( htmlPart );
       
  3994         TFSMailMsgId htmlPartId = htmlPart->GetPartId();
       
  3995         iFetchingHtmlMessageBody = ETrue;
       
  3996         iCurrentHtmlBodyFetchRequestId = htmlPart->FetchMessagePartL( htmlPartId, *this, 0 );
       
  3997         CleanupStack::PopAndDestroy( htmlPart );
       
  3998         }
       
  3999     else if( aFetchedContentType == EMessageStructure )
       
  4000         {
       
  4001         StartFetchingMessageStructureL( aMessagePtr );
       
  4002         }
       
  4003     else
       
  4004         {
       
  4005         User::Leave( KErrNotSupported );
       
  4006         }
       
  4007     }
       
  4008 
       
  4009 // -----------------------------------------------------------------------------
       
  4010 // CFSEmailUiMailViewerVisualiser::CancelFetchings
       
  4011 // -----------------------------------------------------------------------------
       
  4012 void CFSEmailUiMailViewerVisualiser::CancelFetchings()
       
  4013     {
       
  4014     FUNC_LOG;
       
  4015     if( iFetchingPlainTextMessageBody )
       
  4016         {
       
  4017         TRAP_IGNORE( iAppUi.GetMailClient()->CancelL( iCurrentPlainTextBodyFetchRequestId ) );
       
  4018         iFetchingPlainTextMessageBody = EFalse;
       
  4019         }
       
  4020     if( iFetchingHtmlMessageBody )
       
  4021         {
       
  4022         TRAP_IGNORE( iAppUi.GetMailClient()->CancelL( iCurrentHtmlBodyFetchRequestId ) );
       
  4023         iFetchingHtmlMessageBody = EFalse;
       
  4024         }
       
  4025     if( iFetchingMessageStructure )
       
  4026         {
       
  4027         TRAP_IGNORE( iAppUi.GetMailClient()->CancelL( iCurrentStructureFetchRequestId ) );
       
  4028         iFetchingMessageStructure = EFalse;
       
  4029         }
       
  4030     iAsyncProcessComplete = ETrue;
       
  4031     //<cmail>
       
  4032     if(iWaitDialog && iDialogNotDismissed)
       
  4033         TRAP_IGNORE(iWaitDialog->ProcessFinishedL()); // deletes the dialog
       
  4034     //</cmail>
       
  4035     }
       
  4036 
       
  4037 // -----------------------------------------------------------------------------
       
  4038 // CFSEmailUiMailViewerVisualiser::MessageStructureKnownL
       
  4039 // -----------------------------------------------------------------------------
       
  4040 TBool CFSEmailUiMailViewerVisualiser::MessageStructureKnown( CFSMailMessage& aMsg ) const
       
  4041     {
       
  4042     FUNC_LOG;
       
  4043     return TFsEmailUiUtility::IsMessageStructureKnown( aMsg );
       
  4044     }
       
  4045 
       
  4046 // -----------------------------------------------------------------------------
       
  4047 // CFSEmailUiMailViewerVisualiser::StartFetchingMessageStructureL
       
  4048 // -----------------------------------------------------------------------------
       
  4049 void CFSEmailUiMailViewerVisualiser::StartFetchingMessageStructureL( CFSMailMessage& aMsg )
       
  4050     {
       
  4051     FUNC_LOG;
       
  4052     TFSMailMsgId currentMailboxId = aMsg.GetMailBoxId();
       
  4053     TFSMailMsgId currentMessageFolderId = aMsg.GetFolderId();
       
  4054     CFSMailFolder* currentFolder  = iAppUi.GetMailClient()->GetFolderByUidL( currentMailboxId, currentMessageFolderId );
       
  4055     CleanupStack::PushL( currentFolder );
       
  4056     RArray<TFSMailMsgId> messageIds;
       
  4057     CleanupClosePushL( messageIds );
       
  4058     messageIds.Append( aMsg.GetMessageId() );
       
  4059     iFetchingMessageStructure = ETrue;
       
  4060     iCurrentStructureFetchRequestId = currentFolder->FetchMessagesL( messageIds, EFSMsgDataStructure, *this );
       
  4061     CleanupStack::PopAndDestroy( &messageIds );
       
  4062     CleanupStack::PopAndDestroy( currentFolder );
       
  4063     }
       
  4064 
       
  4065 // -----------------------------------------------------------------------------
       
  4066 // CFSEmailUiMailViewerVisualiser::StartWaitedFetchingL
       
  4067 // -----------------------------------------------------------------------------
       
  4068 void CFSEmailUiMailViewerVisualiser::StartWaitedFetchingL( TFetchedContentType aFetchedContentType )
       
  4069     {
       
  4070     FUNC_LOG;
       
  4071     iAsyncProcessComplete = EFalse;
       
  4072     iFetchingAlready = EFalse;
       
  4073     iStartAsyncFetchType = aFetchedContentType;
       
  4074     //<cmail> in cmail we are using different wait dialog, since this wrapper dialog gives
       
  4075     // problems in red key exit, when its active
       
  4076     //delete iAsyncWaitNote; iAsyncWaitNote = NULL;
       
  4077     //iAsyncWaitNote = CAknWaitNoteWrapper::NewL();
       
  4078     // surpress start delay to prevent situation where wait note gets visible
       
  4079     // only after the structure has been fetched
       
  4080     //iAsyncWaitNote->ExecuteL( R_FSE_FETCHING_WAIT_DIALOG, *this, ETrue );
       
  4081     //</cmail>
       
  4082 
       
  4083     //<cmail>
       
  4084     iWaitDialog = new(ELeave)CAknWaitDialog(
       
  4085                    (REINTERPRET_CAST(CEikDialog**,&iWaitDialog)), ETrue);
       
  4086     iWaitDialog->SetCallback(this);
       
  4087     iDialogNotDismissed = ETrue;
       
  4088     iWaitDialog->ExecuteLD(R_FSE_FETCHING_WAIT_DIALOG);
       
  4089         StartFetchingMessagePartL( *iMessage, iStartAsyncFetchType );
       
  4090         iFetchingAlready = ETrue;
       
  4091     //</cmail>
       
  4092     }
       
  4093 
       
  4094 // -----------------------------------------------------------------------------
       
  4095 // CFSEmailUiMailViewerVisualiser::StartFetchingRemaininBodyLinesIfAtBottomL
       
  4096 // -----------------------------------------------------------------------------
       
  4097 void CFSEmailUiMailViewerVisualiser::StartFetchingRemaininBodyLinesIfAtBottomL()
       
  4098     {
       
  4099     FUNC_LOG;
       
  4100     TInt totalLines = iTextViewer->GetTotalLines();
       
  4101     TInt currentLastDisplayedLine = iTextViewer->GetLastDisplayedLine();
       
  4102 
       
  4103     if ( totalLines == currentLastDisplayedLine )
       
  4104         {
       
  4105         // check if there is something to be fetched
       
  4106         if ( !MessagePartFullyFetchedL( EMessagePlainTextBodyPart ) && !iFetchingPlainTextMessageBody )
       
  4107             {
       
  4108             iViewerRichText->AppendFetchingMoreTextL();
       
  4109             // ensure the status layout in the bottom of the screen is visible
       
  4110             iTextViewer->FocusLineL( iTextViewer->GetTotalLines() );
       
  4111             // start fetching
       
  4112             StartFetchingMessagePartL( *iMessage, EMessagePlainTextBodyPart );
       
  4113             iFetchingAnimationTimer->Start( KAnimationRefreshTimeIntervalInMilliseconds );
       
  4114             }
       
  4115         }
       
  4116     }
       
  4117 
       
  4118 // -----------------------------------------------------------------------------
       
  4119 // CFSEmailUiMailViewerVisualiser::TimerEventL
       
  4120 // -----------------------------------------------------------------------------
       
  4121 void CFSEmailUiMailViewerVisualiser::TimerEventL( CFSEmailUiGenericTimer* aTriggeredTimer )
       
  4122     {
       
  4123     FUNC_LOG;
       
  4124     if ( aTriggeredTimer == iFetchingAnimationTimer )
       
  4125         {
       
  4126         iViewerRichText->AppendFetchingMoreTextL();
       
  4127         iFetchingAnimationTimer->Start( KAnimationRefreshTimeIntervalInMilliseconds );
       
  4128         }
       
  4129     }
       
  4130 
       
  4131 // MAknBackgroundProcess methods
       
  4132 //
       
  4133 // -----------------------------------------------------------------------------
       
  4134 // CFSEmailUiMailViewerVisualiser::StepL
       
  4135 // -----------------------------------------------------------------------------
       
  4136 //<cmail>
       
  4137 /*
       
  4138 void CFSEmailUiMailViewerVisualiser::StepL()
       
  4139     {
       
  4140     FUNC_LOG;
       
  4141     if( !iFetchingAlready )
       
  4142         {
       
  4143         StartFetchingMessagePartL( *iMessage, iStartAsyncFetchType );
       
  4144         iFetchingAlready = ETrue;
       
  4145         }
       
  4146     }*/
       
  4147 //</cmail>
       
  4148 
       
  4149 // -----------------------------------------------------------------------------
       
  4150 // CFSEmailUiMailViewerVisualiser::IsProcessDone
       
  4151 // -----------------------------------------------------------------------------
       
  4152 //<cmail>
       
  4153 /*
       
  4154 TBool CFSEmailUiMailViewerVisualiser::IsProcessDone() const
       
  4155     {
       
  4156     FUNC_LOG;
       
  4157     return iAsyncProcessComplete;
       
  4158     }*/
       
  4159 //</cmail>
       
  4160 
       
  4161 // -----------------------------------------------------------------------------
       
  4162 // CFSEmailUiMailViewerVisualiser::ProcessFinished
       
  4163 // -----------------------------------------------------------------------------
       
  4164 //<cmail>
       
  4165 //void CFSEmailUiMailViewerVisualiser::ProcessFinished() {/* nothing here */ }
       
  4166 //</cmail>
       
  4167 
       
  4168 // -----------------------------------------------------------------------------
       
  4169 // CFSEmailUiMailViewerVisualiser::DialogDismissedL
       
  4170 // -----------------------------------------------------------------------------
       
  4171 void CFSEmailUiMailViewerVisualiser::DialogDismissedL( TInt aButtonId )
       
  4172     {
       
  4173     FUNC_LOG;
       
  4174     iDialogNotDismissed = EFalse;
       
  4175     if( aButtonId == EAknSoftkeyCancel )
       
  4176         {
       
  4177         CancelFetchings();
       
  4178         }
       
  4179     }
       
  4180 
       
  4181 // -----------------------------------------------------------------------------
       
  4182 // CFSEmailUiMailViewerVisualiser::CycleError
       
  4183 // -----------------------------------------------------------------------------
       
  4184 //<cmail>
       
  4185 //TInt CFSEmailUiMailViewerVisualiser::CycleError( TInt /*aError*/ )
       
  4186 /*
       
  4187     {
       
  4188     FUNC_LOG;
       
  4189     iAsyncProcessComplete = ETrue;
       
  4190     CancelFetchings();
       
  4191     return KErrNone;
       
  4192     }*/
       
  4193 //</cmail>
       
  4194 
       
  4195 // -----------------------------------------------------------------------------
       
  4196 // CFSEmailUiMailViewerVisualiser::AddBackgroundPicturesL
       
  4197 // -----------------------------------------------------------------------------
       
  4198 void CFSEmailUiMailViewerVisualiser::AddBackgroundPicturesL()
       
  4199     {
       
  4200     CAlfTexture& headerTexture = iAppUi.FsTextureManager()->TextureByIndex( EViewerTextureHeaderBackGround );
       
  4201     CAlfTexture& backgroundTexture = iAppUi.FsTextureManager()->TextureByIndex( EBackgroundTextureMailList );
       
  4202 
       
  4203     // add header texture
       
  4204     // -1 is here for to bottom space icon
       
  4205     // // <cmail> S60 Skin support
       
  4206     //  iTextViewer->SetPartBgImageL( 0, iViewerRichText->HeaderLengthInCharacters()-2, headerTexture );
       
  4207     // </cmail>
       
  4208 
       
  4209     // add bg texture
       
  4210     //<cmail> S60 skin support
       
  4211     //iTextViewer->SetBackgroundImageL( backgroundTexture );
       
  4212     //</cmail>
       
  4213     }
       
  4214 
       
  4215 // -----------------------------------------------------------------------------
       
  4216 // CFSEmailUiMailViewerVisualiser::SetMessageFollowupFlagL
       
  4217 // -----------------------------------------------------------------------------
       
  4218 void CFSEmailUiMailViewerVisualiser::SetMessageFollowupFlagL()
       
  4219     {
       
  4220     FUNC_LOG;
       
  4221     if ( iMessage &&
       
  4222          iTextViewer &&
       
  4223          iViewerRichText &&
       
  4224          TFsEmailUiUtility::IsFollowUpSupported( *iMailBox ) &&
       
  4225          !iEmbeddedMessageMode )
       
  4226         {
       
  4227         TFollowUpNewState newState = TFsEmailUiUtility::SetMessageFollowupFlagL( *iMessage );
       
  4228 
       
  4229         switch ( newState )
       
  4230             {
       
  4231             case EFollowUp:
       
  4232                 {
       
  4233                 iViewerRichText->UpdateIconL( CFSEmailUiMailViewerRichText::EViewerIconFollowUp );
       
  4234                 }
       
  4235                 break;
       
  4236             case EFollowUpComplete:
       
  4237                 {
       
  4238                 iViewerRichText->UpdateIconL( CFSEmailUiMailViewerRichText::EViewerIconFollowUpComplete );
       
  4239                 }
       
  4240                 break;
       
  4241             case EFollowUpClear:
       
  4242                 {
       
  4243                 iViewerRichText->UpdateIconL( CFSEmailUiMailViewerRichText::EViewerIconFollowUpNone );
       
  4244                 }
       
  4245                 break;
       
  4246             case EFollowUpNoChanges:
       
  4247             default:
       
  4248                 {
       
  4249                 // do nothing.
       
  4250                 }
       
  4251                 break;
       
  4252             }
       
  4253 
       
  4254         if ( newState != EFollowUpNoChanges )
       
  4255             {
       
  4256             // Update icon in viewer
       
  4257             TInt iconLine = iViewerRichText->FollowupIconLine();
       
  4258             iTextViewer->ReloadPicturesL( iconLine );
       
  4259             // Notify appui of changed mail item
       
  4260             SendEventToAppUiL( TFSEventMailChanged );
       
  4261             }
       
  4262         }
       
  4263     }
       
  4264 
       
  4265 // -----------------------------------------------------------------------------
       
  4266 // CFSEmailUiMailViewerVisualiser::DeleteMailL
       
  4267 // -----------------------------------------------------------------------------
       
  4268 TInt CFSEmailUiMailViewerVisualiser::DeleteMailL( CFSMailMessage& aMessagePtr, TBool aReturnPreviousView, TBool aDisableNote )
       
  4269     {
       
  4270     FUNC_LOG;
       
  4271     TInt ret( KErrCancel );
       
  4272 
       
  4273     if ( iEmbeddedMessageMode )
       
  4274         {
       
  4275         // embedded messages can't be deleted
       
  4276         ret = KErrNotSupported;
       
  4277         }
       
  4278     else
       
  4279         {
       
  4280         TInt okToDelete( ETrue );
       
  4281         if ( !aDisableNote )
       
  4282             {
       
  4283             if(iAppUi.GetCRHandler()->WarnBeforeDelete())
       
  4284                 {
       
  4285                 okToDelete = TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_UI_DELETE_MESSAGE_CONFIRMATION );
       
  4286                 }
       
  4287             }
       
  4288         if ( okToDelete )
       
  4289             {
       
  4290             CFSMailMessage* confirmedMsgPtr = NULL;
       
  4291             TRAP_IGNORE( confirmedMsgPtr = iAppUi.GetMailClient()->GetMessageByUidL( iAppUi.GetActiveMailboxId(),
       
  4292                                                                                      aMessagePtr.GetFolderId(),
       
  4293                                                                                      aMessagePtr.GetMessageId() ,
       
  4294                                                                                      EFSMsgDataEnvelope ) );
       
  4295             if ( confirmedMsgPtr )
       
  4296                 {
       
  4297                 CleanupStack::PushL( confirmedMsgPtr );
       
  4298                 RArray<TFSMailMsgId> msgIds;
       
  4299                 CleanupClosePushL( msgIds );
       
  4300                 msgIds.Append( confirmedMsgPtr->GetMessageId() );
       
  4301                 TFSMailMsgId mailBox = iAppUi.GetActiveMailbox()->GetId();
       
  4302                 iAppUi.GetMailClient()->DeleteMessagesByUidL( mailBox, confirmedMsgPtr->GetFolderId(), msgIds );
       
  4303                 // Notify appui of deleted mail item
       
  4304                 SendEventToAppUiL( TFSEventMailDeleted );
       
  4305                 CleanupStack::PopAndDestroy( &msgIds );
       
  4306                 CleanupStack::PopAndDestroy( confirmedMsgPtr );
       
  4307                 }
       
  4308 
       
  4309             // return to previous view
       
  4310             if ( aReturnPreviousView )
       
  4311                 {
       
  4312                 // return only if we are in mail viewer
       
  4313                 if ( iAppUi.CurrentActiveView()->Id() == MailViewerId )
       
  4314                     {
       
  4315                     HandleCommandL( EAknSoftkeyBack );
       
  4316                     }
       
  4317                 }
       
  4318             }
       
  4319         if ( okToDelete )
       
  4320             {
       
  4321             ret = KErrNone;
       
  4322             }
       
  4323         }
       
  4324     return ret;
       
  4325     }
       
  4326 
       
  4327 // -----------------------------------------------------------------------------
       
  4328 // CFSEmailUiMailViewerVisualiser::ShowActionsMenuInOptionsL
       
  4329 // -----------------------------------------------------------------------------
       
  4330 TBool CFSEmailUiMailViewerVisualiser::ShowActionsMenuInOptionsL() const
       
  4331     {
       
  4332     FUNC_LOG;
       
  4333     TBool retVal = ETrue;
       
  4334 
       
  4335     SViewerHeadingHotSpotData currentHeaderHotSpotData;
       
  4336     CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  4337     THotspotType hotspotType = iViewerRichText->FindCurrentHotSpotL( currentHeaderHotSpotData, currentBodyHotSpotData );
       
  4338 
       
  4339     if( hotspotType == ENoHotspot || ( hotspotType == EHeaderHotspot && (
       
  4340         currentHeaderHotSpotData.iType == ETypeToNMoreRecipients ||
       
  4341         currentHeaderHotSpotData.iType == ETypeCcNMoreRecipients ||
       
  4342         currentHeaderHotSpotData.iType == ETypeBccNMoreRecipients ||
       
  4343         currentHeaderHotSpotData.iType == ETypeHtml ) ) )
       
  4344         {
       
  4345         retVal = EFalse;
       
  4346         }
       
  4347     return retVal;
       
  4348     }
       
  4349 
       
  4350 // -----------------------------------------------------------------------------
       
  4351 // CFSEmailUiMailViewerVisualiser::ShowDownloadManagerMenuInOptions
       
  4352 // -----------------------------------------------------------------------------
       
  4353 TBool CFSEmailUiMailViewerVisualiser::ShowDownloadManagerMenuInOptions() const
       
  4354     {
       
  4355     FUNC_LOG;
       
  4356     TBool ret(EFalse);
       
  4357 /* <cmail> Download Manager blocked
       
  4358     if ( iAppUi.DownloadInfoMediator() )
       
  4359         {
       
  4360         ret = iAppUi.DownloadInfoMediator()->IsAnyAttachmentDownloads();
       
  4361         }
       
  4362 </cmail> */
       
  4363     return ret;
       
  4364     }
       
  4365 
       
  4366 // -----------------------------------------------------------------------------
       
  4367 // CFSEmailUiMailViewerVisualiser::ShowNextMessageMenuInOptions
       
  4368 // -----------------------------------------------------------------------------
       
  4369 TBool CFSEmailUiMailViewerVisualiser::ShowNextMessageMenuInOptions() const
       
  4370     {
       
  4371     FUNC_LOG;
       
  4372     TBool available = EFalse;
       
  4373     // Next/previous message options are inavailable in the embedded mode
       
  4374     if ( iMessage && !iEmbeddedMessageMode )
       
  4375         {
       
  4376         TFSMailMsgId currentMsgId = iMessage->GetMessageId();
       
  4377         TFSMailMsgId nextMsgId;
       
  4378         TFSMailMsgId nextMsgFolderId;
       
  4379         available = iAppUi.IsNextMsgAvailable( currentMsgId, nextMsgId, nextMsgFolderId );
       
  4380         }
       
  4381     return available;
       
  4382     }
       
  4383 
       
  4384 // -----------------------------------------------------------------------------
       
  4385 // CFSEmailUiMailViewerVisualiser::ShowPreviousMessageMenuInOptions
       
  4386 // -----------------------------------------------------------------------------
       
  4387 TBool CFSEmailUiMailViewerVisualiser::ShowPreviousMessageMenuInOptions() const
       
  4388     {
       
  4389     FUNC_LOG;
       
  4390     TBool available = EFalse;
       
  4391     // Next/previous message options are inavailable in the embedded mode
       
  4392     if ( iMessage && !iEmbeddedMessageMode )
       
  4393         {
       
  4394         TFSMailMsgId currentMsgId = iMessage->GetMessageId();
       
  4395         TFSMailMsgId prevMsgId;
       
  4396         TFSMailMsgId prevMsgFolderId;
       
  4397         available = iAppUi.IsPreviousMsgAvailable( currentMsgId, prevMsgId, prevMsgFolderId );
       
  4398         }
       
  4399     return available;
       
  4400     }
       
  4401 
       
  4402 
       
  4403 // -----------------------------------------------------------------------------
       
  4404 // CFSEmailUiMailViewerVisualiser::ShowNextMessageL
       
  4405 // -----------------------------------------------------------------------------
       
  4406 void CFSEmailUiMailViewerVisualiser::ShowNextMessageL()
       
  4407     {
       
  4408     FUNC_LOG;
       
  4409     if ( iMessage && !iEmbeddedMessageMode )
       
  4410         {
       
  4411         TFSMailMsgId currentMsgId = iMessage->GetMessageId();
       
  4412         TFSMailMsgId nextMsgId;
       
  4413         TFSMailMsgId nextMsgFolderId;
       
  4414         if ( iAppUi.IsNextMsgAvailable( currentMsgId, nextMsgId, nextMsgFolderId ) )
       
  4415             {
       
  4416             // Stop timer and cancel fetchings before showing next message
       
  4417             iFetchingAnimationTimer->Stop();
       
  4418             CancelFetchings();
       
  4419 
       
  4420             // Change empty msk when moving to next
       
  4421             ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
  4422 
       
  4423             iAppUi.MoveToNextMsgL( currentMsgId, nextMsgId );
       
  4424             // Next message is displayed in this view through doactivate, because view is re-activate by mail list
       
  4425             }
       
  4426         }
       
  4427     }
       
  4428 // -----------------------------------------------------------------------------
       
  4429 // CFSEmailUiMailViewerVisualiser::ShowPreviousMessageL
       
  4430 // -----------------------------------------------------------------------------
       
  4431 void CFSEmailUiMailViewerVisualiser::ShowPreviousMessageL()
       
  4432     {
       
  4433     FUNC_LOG;
       
  4434     if ( iMessage && !iEmbeddedMessageMode )
       
  4435         {
       
  4436         TFSMailMsgId currentMsgId = iMessage->GetMessageId();
       
  4437         TFSMailMsgId prevMsgId;
       
  4438         TFSMailMsgId prevMsgFolderId;
       
  4439         if ( iAppUi.IsPreviousMsgAvailable( currentMsgId, prevMsgId, prevMsgFolderId ) )
       
  4440             {
       
  4441             // Stop timer and cancel fetchings before showing prev message
       
  4442             iFetchingAnimationTimer->Stop();
       
  4443             CancelFetchings();
       
  4444 
       
  4445             // Change empty msk when moving to previous
       
  4446             ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
  4447 
       
  4448             iAppUi.MoveToPreviousMsgL( currentMsgId, prevMsgId );
       
  4449             // Previous message is displayed in this view through doactivate, because view is re-activate by mail list
       
  4450             }
       
  4451         }
       
  4452     }
       
  4453 
       
  4454 // -----------------------------------------------------------------------------
       
  4455 // CFSEmailUiMailViewerVisualiser::UpdateMessagePtrL
       
  4456 // -----------------------------------------------------------------------------
       
  4457 void CFSEmailUiMailViewerVisualiser::UpdateMessagePtrL( TFSMailMsgId aNewMailboxId,
       
  4458                                                         TFSMailMsgId aNewFolderId,
       
  4459                                                         TFSMailMsgId aNewMessageId )
       
  4460     {
       
  4461     FUNC_LOG;
       
  4462     TBool messageChanged = ETrue;
       
  4463 
       
  4464     if ( iMessage )
       
  4465         {
       
  4466         // Check is the message going to be changed or are we just updating the
       
  4467         // same message object which has been previously shown.
       
  4468         messageChanged = ( iMessage->GetMessageId() != aNewMessageId );
       
  4469 
       
  4470         // stop observing downloads from the previous message in case the message was changed
       
  4471         if ( iAppUi.DownloadInfoMediator() && messageChanged )
       
  4472             {
       
  4473             iAppUi.DownloadInfoMediator()->StopObserving( this, iMessage->GetMessageId() );
       
  4474             }
       
  4475         delete iMessage;
       
  4476         iMessage = NULL;
       
  4477         PopMessage();
       
  4478         }
       
  4479 
       
  4480     iMessage = iAppUi.GetMailClient()->GetMessageByUidL( aNewMailboxId,
       
  4481                                                          aNewFolderId,
       
  4482                                                          aNewMessageId,
       
  4483                                                          EFSMsgDataEnvelope  );
       
  4484     if ( iMessage )
       
  4485         {
       
  4486 
       
  4487         UpdateMessagePtr( iMessage );
       
  4488         // Update the open messages stack.
       
  4489         EraseMessageStack(); // takes care of deallocating any previous messages
       
  4490         PushMessageL( iMessage, EFalse ); // this is non-embedded message
       
  4491         // Opened to viewer -> set message as read
       
  4492         if ( !iMessage->IsFlagSet( EFSMsgFlag_Read ) )
       
  4493             {
       
  4494             iMessage->SetFlag( EFSMsgFlag_Read );
       
  4495             iMessage->SaveMessageL(); // Save read status
       
  4496             // Notify appui of changed mail item, it seems that protocols don't do this
       
  4497             SendEventToAppUiL( TFSEventMailChanged );
       
  4498             }
       
  4499         // Start observing attachment downloads from the new message
       
  4500         if ( iAppUi.DownloadInfoMediator() && messageChanged )
       
  4501             {
       
  4502             iAppUi.DownloadInfoMediator()->AddObserver( this, iMessage->GetMessageId() );
       
  4503             }
       
  4504         }
       
  4505     }
       
  4506 
       
  4507 // -----------------------------------------------------------------------------
       
  4508 // CFSEmailUiMailViewerVisualiser::UpdateMessagePtr
       
  4509 // -----------------------------------------------------------------------------
       
  4510 void CFSEmailUiMailViewerVisualiser::UpdateMessagePtr( CFSMailMessage* aNewMessagePtr )
       
  4511     {
       
  4512     ASSERT( aNewMessagePtr );
       
  4513 
       
  4514     TBool messageChanged = ETrue;
       
  4515 
       
  4516     // Stop observing any previous message and update iMessage pointer
       
  4517     if ( iMessage )
       
  4518         {
       
  4519         // Check is the message going to be changed or are we just updating the
       
  4520         // same message object which has been previously shown.
       
  4521         messageChanged = ( iMessage->GetMessageId() != aNewMessagePtr->GetMessageId() );
       
  4522 
       
  4523         // stop observing downloads from the previous message in case the message was changed
       
  4524         if ( iAppUi.DownloadInfoMediator() && messageChanged )
       
  4525             {
       
  4526             iAppUi.DownloadInfoMediator()->StopObserving( this, iMessage->GetMessageId() );
       
  4527             }
       
  4528         }
       
  4529     iMessage = aNewMessagePtr;
       
  4530 
       
  4531     // Start observing attachment downloads from the new message
       
  4532     if ( iAppUi.DownloadInfoMediator() && messageChanged )
       
  4533         {
       
  4534         iAppUi.DownloadInfoMediator()->AddObserver( this, iMessage->GetMessageId() );
       
  4535         }
       
  4536     }
       
  4537 
       
  4538 // -----------------------------------------------------------------------------
       
  4539 // CFSEmailUiMailViewerVisualiser::PushMessageL
       
  4540 // Message stack handling. Ownership of message is transferred when succesful.
       
  4541 // -----------------------------------------------------------------------------
       
  4542 //
       
  4543 void CFSEmailUiMailViewerVisualiser::PushMessageL( CFSMailMessage* aMessage, TBool aIsEmbedded )
       
  4544     {
       
  4545     if ( !iOpenMessages || !iEmbeddedMessages )
       
  4546         {
       
  4547         User::Leave( KErrNotReady );
       
  4548         }
       
  4549 
       
  4550     // We must ensure that push is done succesfully either to both stacks or to neither one.
       
  4551     if ( aIsEmbedded )
       
  4552         {
       
  4553         iEmbeddedMessages->PushL( aMessage );
       
  4554         }
       
  4555     else
       
  4556         {
       
  4557         iEmbeddedMessages->PushL( NULL );
       
  4558         }
       
  4559     TRAPD( err, iOpenMessages->PushL( aMessage ) );
       
  4560     if ( err )
       
  4561         {
       
  4562         iEmbeddedMessages->Pop();
       
  4563         User::Leave( err );
       
  4564         }
       
  4565     }
       
  4566 
       
  4567 // -----------------------------------------------------------------------------
       
  4568 // CFSEmailUiMailViewerVisualiser::PopMessage
       
  4569 // Message stack handling. Ownership of message is returned.
       
  4570 // -----------------------------------------------------------------------------
       
  4571 //
       
  4572 CFSMailMessage* CFSEmailUiMailViewerVisualiser::PopMessage()
       
  4573     {
       
  4574     ASSERT( iOpenMessages && iEmbeddedMessages );
       
  4575     ASSERT( iOpenMessages->Count() == iEmbeddedMessages->Count() );
       
  4576 
       
  4577     CFSMailMessage* msg = NULL;
       
  4578     if ( !iOpenMessages->IsEmpty() )
       
  4579         {
       
  4580         msg = iOpenMessages->Pop();
       
  4581         }
       
  4582     if ( !iEmbeddedMessages->IsEmpty() )
       
  4583         {
       
  4584         iEmbeddedMessages->Pop();
       
  4585         }
       
  4586     return msg;
       
  4587     }
       
  4588 
       
  4589 // -----------------------------------------------------------------------------
       
  4590 // CFSEmailUiMailViewerVisualiser::EraseMessageStack
       
  4591 // Message stack handling. All messages in stack are deallocated
       
  4592 // -----------------------------------------------------------------------------
       
  4593 //
       
  4594 void CFSEmailUiMailViewerVisualiser::EraseMessageStack()
       
  4595     {
       
  4596     ASSERT( iOpenMessages && iEmbeddedMessages );
       
  4597     ASSERT( iOpenMessages->Count() == iEmbeddedMessages->Count() );
       
  4598 
       
  4599     iOpenMessages->ResetAndDestroy();
       
  4600     iEmbeddedMessages->Reset();
       
  4601     }
       
  4602 // CFSEmailUiMailViewerVisualiser::NavigateBackL
       
  4603 // Overriden from base class
       
  4604 // -----------------------------------------------------------------------------
       
  4605 void CFSEmailUiMailViewerVisualiser::NavigateBackL()
       
  4606     {
       
  4607     FUNC_LOG;
       
  4608     // clean up current message
       
  4609     if ( iMessage && iAppUi.DownloadInfoMediator() )
       
  4610         {
       
  4611         iAppUi.DownloadInfoMediator()->StopObserving( this, iMessage->GetMessageId() );
       
  4612         }
       
  4613     delete iMessage;
       
  4614     iMessage = NULL;
       
  4615     PopMessage();
       
  4616     // Return to previous message in the stack if there is still some left
       
  4617     if ( !iOpenMessages->IsEmpty() )
       
  4618         {
       
  4619         iAppUi.EnterFsEmailViewL( MailViewerId, KStartViewerReturnFromEmbeddedMsg, KNullDesC8 );
       
  4620         }
       
  4621     // In usual case we use the base view implementation
       
  4622     else
       
  4623         {
       
  4624         CFsEmailUiViewBase::NavigateBackL();
       
  4625         }
       
  4626     }
       
  4627 
       
  4628 // -----------------------------------------------------------------------------
       
  4629 // CFSEmailUiMailViewerVisualiser::HandleDynamicVariantSwitchL
       
  4630 // -----------------------------------------------------------------------------
       
  4631 void CFSEmailUiMailViewerVisualiser::HandleDynamicVariantSwitchL( CFsEmailUiViewBase::TDynamicSwitchType /*aType*/ )
       
  4632     {
       
  4633     FUNC_LOG;
       
  4634     // Set scroll offset to match screen height
       
  4635     if ( iFirstStartCompleted && iTextViewer && iMessage )
       
  4636         {
       
  4637         // <cmail>
       
  4638         TInt firstLine = iTextViewer->GetFirstDisplayedLine();        // get first line number
       
  4639         TInt firstChar = iTextViewer->GetFirstCharInLine(firstLine);  // get first char offset
       
  4640         // </cmail>
       
  4641 
       
  4642         iAppUi.Display().Roster().Hide( ControlGroup() );
       
  4643         RefreshL();
       
  4644 
       
  4645         // <cmail>
       
  4646         TInt newLine = iTextViewer->GetLineNumber(firstChar);   // get the new line number for this offset
       
  4647         if(newLine<0) newLine = firstLine;                       // in case of error go to the prev. line number
       
  4648         iTextViewer->FocusLineL(newLine,ETrue);                  // focus on the found line number
       
  4649         // </cmail>
       
  4650         // <cmail>
       
  4651         SetActionMenuIconVisbilityL();
       
  4652             // </cmail>
       
  4653             iAppUi.Display().Roster().ShowL( ControlGroup() );
       
  4654         iDownloadProgressIndicator->NotifyLayoutChange();
       
  4655         }
       
  4656     }
       
  4657 
       
  4658 // -----------------------------------------------------------------------------
       
  4659 // CFSEmailUiMailViewerVisualiser::HandleDynamicVariantSwitchOnBackgroundL
       
  4660 // -----------------------------------------------------------------------------
       
  4661 void CFSEmailUiMailViewerVisualiser::HandleDynamicVariantSwitchOnBackgroundL( CFsEmailUiViewBase::TDynamicSwitchType /*aType*/ )
       
  4662     {
       
  4663     FUNC_LOG;
       
  4664     iLayoutChangedWhileNotActive = ETrue;
       
  4665     }
       
  4666 
       
  4667 // -----------------------------------------------------------------------------
       
  4668 // CFSEmailUiMailViewerVisualiser::OpenLinkInIntranetL
       
  4669 // -----------------------------------------------------------------------------
       
  4670 void CFSEmailUiMailViewerVisualiser::OpenLinkInIntranetL( TBool aMenuSelection )
       
  4671     {
       
  4672     FUNC_LOG;
       
  4673     CFindItemEngine::SFoundItem currentBodyHotSpotData;
       
  4674     TBool bodyHotSpotFound = iViewerRichText->FindCurrentBodyHotSpotL( currentBodyHotSpotData );
       
  4675     if ( bodyHotSpotFound )
       
  4676         {
       
  4677         HBufC* intranetUrl = iViewerRichText->GetHotspotTextLC( currentBodyHotSpotData );
       
  4678         TInt len = intranetUrl->Length();
       
  4679         HBufC8* eightBitUrl = HBufC8::NewLC( len );
       
  4680         eightBitUrl->Des().Copy( *intranetUrl );
       
  4681 
       
  4682         TAiwGenericParam param( EGenericParamURL, TAiwVariant(*eightBitUrl) );
       
  4683         CAiwGenericParamList& paramList = iIBServiceHandler->InParamListL();
       
  4684         paramList.AppendL( param );
       
  4685         if ( aMenuSelection )
       
  4686             {
       
  4687             iIBServiceHandler->ExecuteMenuCmdL( EFsEmailUiCmdActionsOpenInIntranetMenu,
       
  4688                 paramList, iIBServiceHandler->OutParamListL() );
       
  4689             }
       
  4690         else
       
  4691             {
       
  4692             iIBServiceHandler->ExecuteServiceCmdL( KAiwCmdView,
       
  4693                 paramList, iIBServiceHandler->OutParamListL() );
       
  4694             }
       
  4695         CleanupStack::PopAndDestroy( eightBitUrl );
       
  4696         CleanupStack::PopAndDestroy( intranetUrl );
       
  4697         }
       
  4698     }
       
  4699 
       
  4700 // -----------------------------------------------------------------------------
       
  4701 // CFSEmailUiMailViewerVisualiser::ChangeMsgReadStatusL
       
  4702 // -----------------------------------------------------------------------------
       
  4703 void CFSEmailUiMailViewerVisualiser::ChangeMsgReadStatusL(
       
  4704     TBool aRead, TBool aCmdFromMrui )
       
  4705     {
       
  4706     FUNC_LOG;
       
  4707     if ( iMessage && !iEmbeddedMessageMode )
       
  4708         {
       
  4709         if ( aRead )
       
  4710             {
       
  4711             // Send flags, local and server
       
  4712             iMessage->SetFlag( EFSMsgFlag_Read );
       
  4713             }
       
  4714         else
       
  4715             {
       
  4716             // Send flags, local and server
       
  4717             iMessage->ResetFlag( EFSMsgFlag_Read );
       
  4718             }
       
  4719         iMessage->SaveMessageL(); // Save read status
       
  4720         SendEventToAppUiL( TFSEventMailChanged );
       
  4721 
       
  4722         if ( !aCmdFromMrui && iViewerRichText && iTextViewer )
       
  4723             {
       
  4724             iViewerRichText->UpdateIconL(
       
  4725                 CFSEmailUiMailViewerRichText::EViewerEmailStatus );
       
  4726             TInt iconLine = iViewerRichText->EmailStatusIconLine();
       
  4727             iTextViewer->ReloadPicturesL( iconLine );
       
  4728             }
       
  4729         }
       
  4730     }
       
  4731 
       
  4732 // -----------------------------------------------------------------------------
       
  4733 // CFSEmailUiMailViewerVisualiser::OpenHotSpotUrlInBrowserL
       
  4734 // -----------------------------------------------------------------------------
       
  4735 void CFSEmailUiMailViewerVisualiser::OpenHotSpotUrlInBrowserL(  CFindItemEngine::SFoundItem& aHotSpot  )
       
  4736     {
       
  4737     FUNC_LOG;
       
  4738     if ( aHotSpot.iItemType == CFindItemEngine::EFindItemSearchURLBin ||
       
  4739          aHotSpot.iItemType == CFindItemEngine::EFindItemSearchScheme ) // Scheme is needed also
       
  4740         {
       
  4741         // use browser launcher API here
       
  4742         HBufC* urlToOpen = iViewerRichText->GetHotspotTextLC( aHotSpot );
       
  4743         // Check if the address is rtsp url and send it media player
       
  4744         if ( aHotSpot.iItemType == CFindItemEngine::EFindItemSearchScheme &&
       
  4745              urlToOpen->FindC( KRtspUrlPrefix ) == 0 )
       
  4746             {
       
  4747             RApaLsSession appArcSession;
       
  4748             User::LeaveIfError( appArcSession.Connect() );
       
  4749             TThreadId id;
       
  4750             appArcSession.StartDocument( urlToOpen->Des(), KUidMediaPlayer , id );
       
  4751             appArcSession.Close();
       
  4752             }
       
  4753         else
       
  4754             {
       
  4755             // Check wheter the url text has some prefix (http, https, ftp, etc.).
       
  4756             // If no prefix found, try with the default prefix http.
       
  4757             TInt urlPos = urlToOpen->Find( KUrlPrefixIdentifier );
       
  4758             if ( urlPos == KErrNotFound )
       
  4759                 {
       
  4760                 HBufC* newBuf = urlToOpen->ReAllocL( urlToOpen->Length() + KHttpUrlPrefix().Length() );
       
  4761                 CleanupStack::Pop( urlToOpen );
       
  4762                 urlToOpen = newBuf;
       
  4763                 CleanupStack::PushL( urlToOpen );
       
  4764                 TPtr urlToOpenPtr = urlToOpen->Des();
       
  4765                 urlToOpenPtr.Insert( 0, KHttpUrlPrefix );
       
  4766                 }
       
  4767 
       
  4768             // Use scheme handler to launch the browser as a stand alone application
       
  4769             CSchemeHandler* handler = CSchemeHandler::NewL( *urlToOpen );
       
  4770             CleanupStack::PushL( handler );
       
  4771             handler->HandleUrlStandaloneL();
       
  4772             CleanupStack::PopAndDestroy( handler );
       
  4773             }
       
  4774 
       
  4775         CleanupStack::PopAndDestroy( urlToOpen );
       
  4776         }
       
  4777     }
       
  4778 
       
  4779 // -----------------------------------------------------------------------------
       
  4780 // CFSEmailUiMailViewerVisualiser::CallToBodyHotSpotNumberL
       
  4781 // -----------------------------------------------------------------------------
       
  4782 void CFSEmailUiMailViewerVisualiser::CallToBodyHotSpotNumberL( CFindItemEngine::SFoundItem& aHotSpot )
       
  4783     {
       
  4784     FUNC_LOG;
       
  4785 
       
  4786     if ( aHotSpot.iItemType == CFindItemEngine::EFindItemSearchPhoneNumberBin )
       
  4787         {
       
  4788         HBufC* phoneNumber = iViewerRichText->GetHotspotTextLC( aHotSpot );
       
  4789         TInt answer = TFsEmailUiUtility::ShowConfirmationQueryL(
       
  4790                 R_FREESTYLE_EMAIL_UI_VIEWER_CALL_HOTSPOT, *phoneNumber );
       
  4791         if ( answer )
       
  4792             {
       
  4793             TPtr numberPtr = phoneNumber->Des();
       
  4794             CommonPhoneParser::ParsePhoneNumber( numberPtr,
       
  4795                                   CommonPhoneParser::EPhoneClientNumber);
       
  4796 
       
  4797             CFsDelayedLoader::InstanceL()->GetContactHandlerL()->MakeAiwCallL( NULL, *phoneNumber );
       
  4798             }
       
  4799         CleanupStack::PopAndDestroy( phoneNumber );
       
  4800         }
       
  4801     else if ( aHotSpot.iItemType == CFindItemEngine::EFindItemSearchScheme )
       
  4802         {
       
  4803         TBool voipCall( EFalse );
       
  4804         HBufC* schemeText = iViewerRichText->GetHotspotTextLC( aHotSpot );
       
  4805         // Strip scheme prefix text if found
       
  4806         if ( schemeText && schemeText->FindC( KCallPrefix ) == 0 )
       
  4807             {
       
  4808             schemeText->Des().Delete( 0, KCallPrefix().Length() );
       
  4809             }
       
  4810         else if ( schemeText && schemeText->FindC( KTelPrefix ) == 0 )
       
  4811             {
       
  4812             schemeText->Des().Delete( 0, KTelPrefix().Length() );
       
  4813             }
       
  4814         else if ( schemeText && schemeText->FindC( KSmsPrefix ) == 0 )
       
  4815             {
       
  4816             schemeText->Des().Delete( 0, KSmsPrefix().Length() );
       
  4817             }
       
  4818         else if ( schemeText && schemeText->FindC( KMmsPrefix ) == 0 )
       
  4819             {
       
  4820             schemeText->Des().Delete( 0, KMmsPrefix().Length() );
       
  4821             }
       
  4822         else if ( schemeText && schemeText->FindC( KVoipPrefix ) == 0 )
       
  4823             {
       
  4824             voipCall = ETrue;
       
  4825             schemeText->Des().Delete( 0, KVoipPrefix().Length() );
       
  4826             }
       
  4827 
       
  4828         TInt answer = TFsEmailUiUtility::ShowConfirmationQueryL(
       
  4829                 R_FREESTYLE_EMAIL_UI_VIEWER_CALL_HOTSPOT, *schemeText );
       
  4830         if ( answer )
       
  4831             {
       
  4832             if ( !voipCall )
       
  4833                 {
       
  4834                 // use common phone parser for other than voip numbers
       
  4835                 TPtr numberPtr = schemeText->Des();
       
  4836                 CommonPhoneParser::ParsePhoneNumber( numberPtr,
       
  4837                                  CommonPhoneParser::EPhoneClientNumber );
       
  4838                 }
       
  4839             CFsDelayedLoader::InstanceL()->GetContactHandlerL()->MakeAiwCallL( NULL, *schemeText, voipCall );
       
  4840             }
       
  4841         CleanupStack::PopAndDestroy( schemeText );
       
  4842         }
       
  4843     }
       
  4844 
       
  4845 // -----------------------------------------------------------------------------
       
  4846 // CFSEmailUiMailViewerVisualiser::WriteEmailToHotSpotAddressL
       
  4847 // -----------------------------------------------------------------------------
       
  4848 void CFSEmailUiMailViewerVisualiser::WriteEmailToHotSpotAddressL( CFindItemEngine::SFoundItem& aHotSpot )
       
  4849     {
       
  4850     FUNC_LOG;
       
  4851     if ( aHotSpot.iItemType == CFindItemEngine::EFindItemSearchMailAddressBin )
       
  4852         {
       
  4853         delete iNewMailTempAddress; iNewMailTempAddress = NULL;
       
  4854         iNewMailTempAddress = CFSMailAddress::NewL();
       
  4855         HBufC* mailAddress = iViewerRichText->GetHotspotTextLC( aHotSpot );
       
  4856         iNewMailTempAddress->SetEmailAddress( *mailAddress );
       
  4857         CleanupStack::PopAndDestroy( mailAddress );
       
  4858         iAppUi.LaunchEditorL( iNewMailTempAddress );
       
  4859         }
       
  4860     else if ( aHotSpot.iItemType == CFindItemEngine::EFindItemSearchScheme )
       
  4861         {
       
  4862         HBufC* schemeText = iViewerRichText->GetHotspotTextLC( aHotSpot );
       
  4863         if ( schemeText && schemeText->FindC( KMailtoPrefix ) == 0)
       
  4864             {
       
  4865             schemeText->Des().Delete( 0, KMailtoPrefix().Length() );
       
  4866             delete iNewMailTempAddress; iNewMailTempAddress = NULL;
       
  4867             iNewMailTempAddress = CFSMailAddress::NewL();
       
  4868             iNewMailTempAddress->SetEmailAddress( *schemeText );
       
  4869             iAppUi.LaunchEditorL( iNewMailTempAddress );
       
  4870             }
       
  4871         CleanupStack::PopAndDestroy( schemeText );
       
  4872         }
       
  4873     }
       
  4874 
       
  4875 void CFSEmailUiMailViewerVisualiser::SaveEmailAsContactL(
       
  4876     const TDesC& aEmailAddress )
       
  4877     {
       
  4878     FUNC_LOG;
       
  4879     TAddToContactsType type;
       
  4880     // Query to "update existing" or "Create new"
       
  4881     // --> EFALSE = user chose "cancel"
       
  4882     if ( CFsDelayedLoader::InstanceL()->GetContactHandlerL()->
       
  4883         AddtoContactsQueryL( type ) )
       
  4884         {
       
  4885         // Create buffer and strip scheme data such as mailto: and call:
       
  4886         HBufC* textData = aEmailAddress.AllocLC();
       
  4887         if ( textData->FindC( KMailtoPrefix ) == 0 )
       
  4888             {
       
  4889             textData->Des().Delete( 0, KMailtoPrefix().Length() );
       
  4890             }
       
  4891         CFsDelayedLoader::InstanceL()->GetContactHandlerL()->AddToContactL(
       
  4892                 *textData, EContactUpdateEmail, type, this );
       
  4893         CleanupStack::PopAndDestroy( textData );
       
  4894         }
       
  4895     }
       
  4896 
       
  4897 void CFSEmailUiMailViewerVisualiser::SavePhoneNumberAsContactL(
       
  4898     const TDesC& aPhoneNumber )
       
  4899     {
       
  4900     FUNC_LOG;
       
  4901     TAddToContactsType type;
       
  4902     // Query to "update existing" or "Create new"
       
  4903     // --> EFALSE = user chose "cancel"
       
  4904     if ( CFsDelayedLoader::InstanceL()->GetContactHandlerL()->
       
  4905         AddtoContactsQueryL( type ) )
       
  4906         {
       
  4907         // Create buffer and strip scheme data such as mailto: and call:
       
  4908         HBufC* textData = aPhoneNumber.AllocLC();
       
  4909         // Strip scheme prefix text if found
       
  4910         if ( textData && textData->FindC( KCallPrefix ) == 0 )
       
  4911             {
       
  4912             textData->Des().Delete( 0, KCallPrefix().Length() );
       
  4913             }
       
  4914         else if ( textData && textData->FindC( KTelPrefix ) == 0 )
       
  4915             {
       
  4916             textData->Des().Delete( 0, KTelPrefix().Length() );
       
  4917             }
       
  4918         else if ( textData && textData->FindC( KSmsPrefix ) == 0 )
       
  4919             {
       
  4920             textData->Des().Delete( 0, KSmsPrefix().Length() );
       
  4921             }
       
  4922         else if ( textData && textData->FindC( KMmsPrefix ) == 0 )
       
  4923             {
       
  4924             textData->Des().Delete( 0, KMmsPrefix().Length() );
       
  4925             }
       
  4926         CFsDelayedLoader::InstanceL()->GetContactHandlerL()->AddToContactL(
       
  4927             *textData, EContactUpdateNumber, type, this );
       
  4928         CleanupStack::PopAndDestroy( textData );
       
  4929         }
       
  4930     }
       
  4931 
       
  4932 
       
  4933 void CFSEmailUiMailViewerVisualiser::FlagselectionCompleteL( TInt aSelection )
       
  4934     {
       
  4935     FUNC_LOG;
       
  4936     // Set message follow up flag
       
  4937     if ( iMessage && aSelection != KErrNotFound )
       
  4938         {
       
  4939         switch ( aSelection )
       
  4940             {
       
  4941             case EFollowUp:
       
  4942                 {
       
  4943                 iMessage->SetFlag( EFSMsgFlag_FollowUp );
       
  4944                 iMessage->ResetFlag( EFSMsgFlag_FollowUpComplete );
       
  4945                 iMessage->SaveMessageL();
       
  4946                 }
       
  4947                 break;
       
  4948             case EFollowUpComplete:
       
  4949                 {
       
  4950                 iMessage->SetFlag( EFSMsgFlag_FollowUpComplete );
       
  4951                 iMessage->ResetFlag( EFSMsgFlag_FollowUp );
       
  4952                 iMessage->SaveMessageL();
       
  4953                 }
       
  4954                 break;
       
  4955             case EFollowUpClear:
       
  4956                 {
       
  4957                 iMessage->ResetFlag( EFSMsgFlag_FollowUp | EFSMsgFlag_FollowUpComplete );
       
  4958                 iMessage->SaveMessageL();
       
  4959                 }
       
  4960                 break;
       
  4961             default:
       
  4962                 break;
       
  4963             }
       
  4964         }
       
  4965     }
       
  4966 
       
  4967 
       
  4968 void CFSEmailUiMailViewerVisualiser::SetMailboxNameToStatusPaneL()
       
  4969     {
       
  4970     FUNC_LOG;
       
  4971     iAppUi.SetActiveMailboxNameToStatusPaneL();
       
  4972     }
       
  4973 
       
  4974 void CFSEmailUiMailViewerVisualiser::GetParentLayoutsL( RPointerArray<CAlfVisual>& aLayoutArray ) const
       
  4975     {
       
  4976     if ( iTextViewer )
       
  4977         {
       
  4978         aLayoutArray.AppendL( iTextViewer->RootLayout() );
       
  4979         }
       
  4980     }
       
  4981 
       
  4982 // ---------------------------------------------------------------------------
       
  4983 //
       
  4984 // ---------------------------------------------------------------------------
       
  4985 //
       
  4986 void CFSEmailUiMailViewerVisualiser::UpdateNaviPaneL( TBool aForESMR )
       
  4987     {
       
  4988     FUNC_LOG;
       
  4989     // Get navigation decorator for mail viewer
       
  4990     CAknNavigationDecorator* naviDecorator = iAppUi.NaviDecoratorL( MailViewerId );
       
  4991     if ( naviDecorator )
       
  4992         {
       
  4993         // Check if there's next and previous message available, and set
       
  4994         // the navipane arrows accordingly
       
  4995         TFSMailMsgId currentMsgId = iMessage->GetMessageId();
       
  4996         TFSMailMsgId tmpMsgId;
       
  4997         TFSMailMsgId tmpMsgFolderId;
       
  4998         if ( iAppUi.IsNextMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId ) )
       
  4999             {
       
  5000             naviDecorator->SetScrollButtonDimmed( CAknNavigationDecorator::ERightButton, EFalse );
       
  5001             }
       
  5002         else
       
  5003             {
       
  5004             naviDecorator->SetScrollButtonDimmed( CAknNavigationDecorator::ERightButton, ETrue );
       
  5005             }
       
  5006         if ( iAppUi.IsPreviousMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId ) )
       
  5007             {
       
  5008             naviDecorator->SetScrollButtonDimmed( CAknNavigationDecorator::ELeftButton, EFalse );
       
  5009             }
       
  5010         else
       
  5011             {
       
  5012             naviDecorator->SetScrollButtonDimmed( CAknNavigationDecorator::ELeftButton, ETrue );
       
  5013             }
       
  5014 
       
  5015         // Set this view's navipane to the top of the navipane control stack
       
  5016         CAknNavigationControlContainer* naviPaneContainer =
       
  5017             static_cast<CAknNavigationControlContainer*>(
       
  5018             StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
  5019         naviPaneContainer->PushL( *naviDecorator );
       
  5020         naviDecorator->SetNaviDecoratorObserver( aForESMR ? NULL : this );
       
  5021         }
       
  5022 
       
  5023     // Set priority and follow-up flags
       
  5024     CCustomStatuspaneIndicators* indicators = iAppUi.GetStatusPaneIndicatorContainer();
       
  5025     if ( indicators)
       
  5026         {
       
  5027         indicators->ShowStatusPaneIndicators();
       
  5028 
       
  5029         if ( iMessage->IsFlagSet( EFSMsgFlag_Low ) )
       
  5030             {
       
  5031             indicators->SetPriorityFlag( EMsgPriorityLow );
       
  5032             }
       
  5033         else if ( iMessage->IsFlagSet( EFSMsgFlag_Important ) )
       
  5034             {
       
  5035             indicators->SetPriorityFlag( EMsgPriorityHigh );
       
  5036             }
       
  5037         else
       
  5038             {
       
  5039             indicators->SetPriorityFlag( EMsgPriorityNormal );
       
  5040             }
       
  5041 
       
  5042         CCustomStatuspaneIndicators::TFollowUpFlagType flagType = CCustomStatuspaneIndicators::EFollowUpNone;
       
  5043         if (iMessage->IsFlagSet(EFSMsgFlag_FollowUp))
       
  5044             {
       
  5045             flagType = CCustomStatuspaneIndicators::EFollowUp;
       
  5046             }
       
  5047         if (iMessage->IsFlagSet(EFSMsgFlag_FollowUpComplete))
       
  5048             {
       
  5049             flagType = CCustomStatuspaneIndicators::EFollowUpComplete;
       
  5050             }
       
  5051         indicators->SetFollowUpFlag( flagType );
       
  5052         
       
  5053         indicators->DrawNow();
       
  5054         }
       
  5055 
       
  5056     }
       
  5057 
       
  5058 // ---------------------------------------------------------------------------
       
  5059 //
       
  5060 // ---------------------------------------------------------------------------
       
  5061 //
       
  5062 void CFSEmailUiMailViewerVisualiser::HandleNaviDecoratorEventL( TInt aEventID )
       
  5063     {
       
  5064     FUNC_LOG;
       
  5065     CAknNavigationDecorator* naviDecorator = iAppUi.NaviDecoratorL( MailViewerId );
       
  5066     if ( naviDecorator )
       
  5067         {
       
  5068         naviDecorator->SetNaviDecoratorObserver( NULL );
       
  5069         }
       
  5070     if( aEventID == MAknNaviDecoratorObserver::EAknNaviDecoratorEventRightTabArrow )
       
  5071         {
       
  5072         ShowNextMessageL();
       
  5073         }
       
  5074     else
       
  5075         {
       
  5076         ShowPreviousMessageL();
       
  5077         }
       
  5078     }
       
  5079 
       
  5080 // ---------------------------------------------------------------------------
       
  5081 // HandleMailBoxEventL
       
  5082 // Mailbox event handler, responds to events sent by the plugin.
       
  5083 // ---------------------------------------------------------------------------
       
  5084 //
       
  5085 void CFSEmailUiMailViewerVisualiser::HandleMailBoxEventL( TFSMailEvent aEvent,
       
  5086     TFSMailMsgId aMailbox, TAny* aParam1, TAny* /*aParam2*/, TAny* /*aParam3*/ )
       
  5087     {
       
  5088     FUNC_LOG;
       
  5089     if ( iFirstStartCompleted && iMessage && aMailbox.Id() == iAppUi.GetActiveMailboxId().Id() &&
       
  5090          aEvent == TFSEventMailDeleted && aParam1 ) // Safety, in list events that only concern active mailbox are handled
       
  5091         {
       
  5092         TFSMailMsgId curMsgId = iMessage->GetMessageId();
       
  5093         RArray<TFSMailMsgId>* removedEntries = static_cast<RArray<TFSMailMsgId>*>(aParam1);
       
  5094         for ( TInt i=0 ; i < removedEntries->Count() ; i++ )
       
  5095             {
       
  5096             //<cmail>
       
  5097             if ( (curMsgId == (*removedEntries)[i]) &&
       
  5098                     (iDeletedMessageFromMrui != curMsgId) )
       
  5099                 {
       
  5100                 //</cmail>
       
  5101                 ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
  5102                 NavigateBackL();
       
  5103                 break;
       
  5104                 }
       
  5105             }
       
  5106         }
       
  5107     }
       
  5108 
       
  5109 void CFSEmailUiMailViewerVisualiser::SendEventToAppUiL( TFSMailEvent aEventType )
       
  5110     {
       
  5111     RArray<TFSMailMsgId> msgIdArray;
       
  5112     CleanupClosePushL( msgIdArray );
       
  5113     msgIdArray.AppendL( iMessage->GetMessageId() );
       
  5114     TFSMailMsgId folderId = iMessage->GetFolderId();
       
  5115     iAppUi.EventL( aEventType,
       
  5116                    iAppUi.GetActiveMailboxId(),
       
  5117                    &msgIdArray, &folderId, NULL );
       
  5118     CleanupStack::PopAndDestroy( &msgIdArray );
       
  5119     }
       
  5120 
       
  5121 //////////////////////////////////////////////////////////////////////////////////////
       
  5122 // CLASS IMPLEMENTATION CHANGE TO FLAG DIALOG GLOBAL NOTE
       
  5123 ///////////////////////////////////////////////////////////////////////////////////
       
  5124 CFlagSelectionGlobalNoteHandler* CFlagSelectionGlobalNoteHandler::NewL( CFSEmailUiMailViewerVisualiser& aViewerVisualiser )
       
  5125     {
       
  5126     FUNC_LOG;
       
  5127     CFlagSelectionGlobalNoteHandler* self =
       
  5128          new (ELeave) CFlagSelectionGlobalNoteHandler( aViewerVisualiser );
       
  5129     return self;
       
  5130     }
       
  5131 
       
  5132 
       
  5133 CFlagSelectionGlobalNoteHandler::~CFlagSelectionGlobalNoteHandler()
       
  5134     {
       
  5135     FUNC_LOG;
       
  5136     delete iPrompt;
       
  5137     delete iGlobalFlagQuery;
       
  5138     }
       
  5139 
       
  5140 void CFlagSelectionGlobalNoteHandler::Cancel()
       
  5141     {
       
  5142     FUNC_LOG;
       
  5143     }
       
  5144 
       
  5145 void CFlagSelectionGlobalNoteHandler::LaunchFlagListQueryDialogL()
       
  5146     {
       
  5147     FUNC_LOG;
       
  5148     iSelection = 0;
       
  5149     if ( !iPrompt )
       
  5150         {
       
  5151         iPrompt = StringLoader::LoadL( R_FREESTYLE_EMAIL_UI_VIEWER_FLAG_DIALOG_HEADER );
       
  5152         }
       
  5153     if ( !iGlobalFlagQuery )
       
  5154         {
       
  5155         iGlobalFlagQuery = CAknGlobalListQuery::NewL();
       
  5156         iGlobalFlagQuery->SetHeadingL( *iPrompt ); // Set query heading.
       
  5157         }
       
  5158 
       
  5159     CDesCArrayFlat* array = new (ELeave) CDesCArrayFlat( 3 );
       
  5160     CleanupStack::PushL( array );
       
  5161     // Add follow up text
       
  5162     HBufC* followUp = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FLAG_FOLLOW_UP );
       
  5163     array->AppendL( *followUp );
       
  5164     CleanupStack::PopAndDestroy( followUp );
       
  5165 
       
  5166     // Add flag complete text
       
  5167     HBufC* completeFlag = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FLAG_COMPLETE );
       
  5168     array->AppendL( *completeFlag );
       
  5169     CleanupStack::PopAndDestroy( completeFlag );
       
  5170 
       
  5171     // Add clear flag text
       
  5172     HBufC* clearFlag = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FLAG_CLEAR );
       
  5173     array->AppendL( *clearFlag );
       
  5174     CleanupStack::PopAndDestroy( clearFlag );
       
  5175 
       
  5176     // Show query
       
  5177     iGlobalFlagQuery->ShowListQueryL( array, iStatus, iSelection );
       
  5178     CleanupStack::PopAndDestroy( array );
       
  5179 
       
  5180     // Set active
       
  5181     SetActive();
       
  5182     }
       
  5183 
       
  5184 void CFlagSelectionGlobalNoteHandler::RunL()
       
  5185     {
       
  5186     FUNC_LOG;
       
  5187     TInt status = iStatus.Int();
       
  5188     iViewerVisualiser.FlagselectionCompleteL( status );
       
  5189     }
       
  5190 
       
  5191 void CFlagSelectionGlobalNoteHandler::DoCancel()
       
  5192     {
       
  5193     FUNC_LOG;
       
  5194     }
       
  5195 
       
  5196 TInt CFlagSelectionGlobalNoteHandler::RunError( TInt /*aError*/ )
       
  5197     {
       
  5198     FUNC_LOG;
       
  5199     TInt err( KErrNone );
       
  5200     return err;
       
  5201     }
       
  5202 
       
  5203 CFlagSelectionGlobalNoteHandler::CFlagSelectionGlobalNoteHandler(  CFSEmailUiMailViewerVisualiser& aViewerVisualiser )
       
  5204     : CActive ( EPriorityHigh ),
       
  5205     iViewerVisualiser( aViewerVisualiser )
       
  5206     {
       
  5207     FUNC_LOG;
       
  5208     CActiveScheduler::Add( this );
       
  5209     iSelection = 0;
       
  5210     }
       
  5211