emailuis/emailui/src/FreestyleEmailUiHtmlViewerView.cpp
changeset 0 8466d47a6819
child 1 12c456ceeff2
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     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:  CFsEmailUiHtmlViewerView class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <coemain.h>
       
    21 #include <aknconsts.h>
       
    22 #include <AknsUtils.h>
       
    23 #include <StringLoader.h>
       
    24 #include <AknWaitDialog.h>
       
    25 #include <AknGlobalListQuery.h>
       
    26 #include <AknGlobalNote.h>
       
    27 #include <aknnavi.h>
       
    28 #include <aknnavide.h>
       
    29 //<cmail>
       
    30 #include <featmgr.h>
       
    31 #include "CFSMailMessage.h"
       
    32 #include "CFSMailClient.h"
       
    33 #include <FreestyleEmailUi.rsg>
       
    34 #include <SchemeHandler.h> // CSchemeHandler
       
    35 #include <brctlinterface.h>
       
    36 #include <csxhelp/cmail.hlp.hrh>
       
    37 // Meeting request
       
    38 #include <MeetingRequestUids.hrh>
       
    39 //<cmail>
       
    40 #include "cesmricalviewer.h"
       
    41 #include "FreestyleEmailUiHtmlViewerView.h"
       
    42 #include "FreestyleEmailUi.hrh"
       
    43 #include "FreestyleEmailUiAppui.h"
       
    44 #include "FreestyleEmailUiHtmlViewerContainer.h"
       
    45 #include "FreestyleEmailUiUtilities.h"
       
    46 #include "FreestyleEmailUiShortcutBinding.h"
       
    47 #include "FreestyleEmailCenRepHandler.h"
       
    48 #include "FreestyleEmailUiAttachmentsListModel.h"
       
    49 #include "FreestyleEmailUiConstants.h"
       
    50 #include "FreestyleAttachmentDownloadProgressBar.h"
       
    51 #include "FSEmail.pan"
       
    52 #include "CFSMailCommon.h"
       
    53 
       
    54 #include "FreestyleEmailUiMailViewerConstants.h"
       
    55 #include "FSDelayedLoader.h"
       
    56 #include "FreestyleMessageHeaderURL.h"
       
    57 #include <akntoolbar.h>
       
    58 // CONSTANTS
       
    59 // Zoom levels available on the UI
       
    60 const TInt KZoomLevels[] = { 50, 75, 100, 125 };
       
    61 const TInt KZoomLevelCount = sizeof( KZoomLevels ) / sizeof( TInt );
       
    62 
       
    63 CFsEmailUiHtmlViewerView* CFsEmailUiHtmlViewerView::NewL( 
       
    64     CAlfEnv& aEnv,
       
    65     CFreestyleEmailUiAppUi& aAppUi, 
       
    66     CAlfControlGroup& aControlGroup )
       
    67     {
       
    68     FUNC_LOG;
       
    69     CFsEmailUiHtmlViewerView* self = new ( ELeave ) CFsEmailUiHtmlViewerView( aEnv, aAppUi, aControlGroup );
       
    70     CleanupStack::PushL( self );
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop( self );
       
    73     return self;
       
    74     }
       
    75 
       
    76 CFsEmailUiHtmlViewerView::CFsEmailUiHtmlViewerView( CAlfEnv& aEnv,
       
    77         CFreestyleEmailUiAppUi& aAppUi, 
       
    78         CAlfControlGroup& aControlGroup )
       
    79         : CFsEmailUiViewBase( aControlGroup, aAppUi ),
       
    80         iEnv( aEnv )
       
    81     {
       
    82     FUNC_LOG;
       
    83     }
       
    84 
       
    85 CFsEmailUiHtmlViewerView::~CFsEmailUiHtmlViewerView()
       
    86     {
       
    87     FUNC_LOG;
       
    88     CancelFetchings();
       
    89     if ( iAppUi.DownloadInfoMediator() && iMessage )
       
    90         {
       
    91         iAppUi.DownloadInfoMediator()->StopObserving( this, iMessage->GetMessageId() );
       
    92         }
       
    93 
       
    94     // <cmail>
       
    95     if ( iContainer )
       
    96         {
       
    97         iContainer->PrepareForExit();
       
    98         }
       
    99 
       
   100     delete iNewMailTempAddress;
       
   101     // </cmail>
       
   102     if ( iContainer )
       
   103         {
       
   104         iContainer->CancelFetch();
       
   105         }
       
   106     delete iContainer;
       
   107     delete iAttachmentsListModel;
       
   108     delete iProgressBar;
       
   109 
       
   110     delete iOpenMessages;
       
   111     iOpenMessages = NULL;
       
   112     delete iEmbeddedMessages;
       
   113     iEmbeddedMessages = NULL;
       
   114     iMessage = NULL;
       
   115     
       
   116     delete iMailBox; 
       
   117     iMailBox = NULL;
       
   118     delete iAsyncCallback;
       
   119 
       
   120 
       
   121    
       
   122     }
       
   123 
       
   124 void CFsEmailUiHtmlViewerView::ConstructL()
       
   125     {
       
   126     FUNC_LOG;
       
   127     BaseConstructL( R_FSEMAILUI_HTML_VIEW );
       
   128     iAsyncCallback = new (ELeave) CAsyncCallBack( CActive::EPriorityLow );
       
   129     iOpenMessages = new (ELeave) CStack<CFSMailMessage, ETrue>();
       
   130     iEmbeddedMessages = new (ELeave) CStack<CFSMailMessage, EFalse>();
       
   131     iNextOrPrevMessageSelected = EFalse; 
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CFsEmailUiHtmlViewerView::Id()
       
   136 // Returns View's ID.
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 TUid CFsEmailUiHtmlViewerView::Id() const
       
   140     {
       
   141     FUNC_LOG;
       
   142     return HtmlViewerId;
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CFsEmailUiHtmlViewerView::HandleCommandL()
       
   147 // Takes care of Command handling.
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 void CFsEmailUiHtmlViewerView::HandleCommandL( TInt aCommand )
       
   151     {
       
   152     FUNC_LOG;
       
   153 
       
   154     if ( !iAppUi.ViewSwitchingOngoing() )
       
   155         {
       
   156         switch ( aCommand )
       
   157             {
       
   158                 // Open MSK handling
       
   159             case EFsEmailUiCmdActionsCall:
       
   160             case EFsEmailUiCmdActionsOpenWeb:
       
   161             case EFsEmailUiCmdComposeTo:
       
   162                 {
       
   163                 TBrCtlDefs::TBrCtlElementType elementType = iContainer->BrowserControlIf()->FocusedElementType();
       
   164 
       
   165                 switch ( elementType )
       
   166                     {
       
   167                     case TBrCtlDefs::EElementTelAnchor:
       
   168                     case TBrCtlDefs::EElementSmartLinkTel:
       
   169                         {
       
   170                         iContainer->BrowserControlIf()->HandleCommandL( ( TInt )TBrCtlDefs::ECommandIdBase +
       
   171                                 ( TInt )TBrCtlDefs::ECommandMakeCall );
       
   172                         }
       
   173                     break;
       
   174                     case TBrCtlDefs::EElementMailtoAnchor:
       
   175                     case TBrCtlDefs::EElementSmartLinkEmail:
       
   176                         {
       
   177                         // <cmail> change made because the functionality of
       
   178                         // sending email is not present in the browser control
       
   179                         // anymore
       
   180 
       
   181                         // Create buffer and strip scheme data "mailto:"
       
   182                         HBufC* mailAddress =
       
   183                             iContainer->BrowserControlIf()->PageInfoLC(
       
   184                                 TBrCtlDefs::EPageInfoFocusedNodeUrl );
       
   185 
       
   186                         if ( mailAddress->FindC( KMailtoPrefix ) == 0 )
       
   187                             {
       
   188                             mailAddress->Des().Delete( 0,
       
   189                                                        KMailtoPrefix().Length() );
       
   190                             }
       
   191 
       
   192                         delete iNewMailTempAddress;
       
   193                         iNewMailTempAddress = NULL;
       
   194                         iNewMailTempAddress = CFSMailAddress::NewL();
       
   195                         iNewMailTempAddress->SetEmailAddress( *mailAddress );
       
   196                         CleanupStack::PopAndDestroy( mailAddress );
       
   197                         iAppUi.LaunchEditorL( iNewMailTempAddress );
       
   198 
       
   199                         /*iContainer->BrowserControlIf()->HandleCommandL( (TInt)TBrCtlDefs::ECommandIdBase +
       
   200                                                                         (TInt)TBrCtlDefs::ECommandSmartLinkSendEmail );*/
       
   201                         // </cmail>
       
   202                         }
       
   203                     break;
       
   204                     case TBrCtlDefs::EElementAnchor:
       
   205                         {
       
   206                         // OPEN url in standalone browser UI
       
   207                         /*                         HBufC* url = iContainer->BrowserControlIf()->PageInfoLC(TBrCtlDefs::EPageInfoFocusedNodeUrl);
       
   208                                                // Use scheme handler to launch the browser as a stand alone application
       
   209                                                TInt urlPos = url->Find( KUrlPrefixIdentifier );
       
   210                                                if( urlPos == KErrNotFound )
       
   211                                                    {
       
   212                                                    HBufC* newBuf = url->ReAllocL( url->Length() + KHttpUrlPrefix().Length() );
       
   213                                                    CleanupStack::Pop( url );
       
   214                                                    url = newBuf;
       
   215                                                    CleanupStack::PushL( url );
       
   216                                                    TPtr urlPtr = url->Des();
       
   217                                                    urlPtr.Insert( 0, KHttpUrlPrefix );
       
   218                                                    }
       
   219                                                CSchemeHandler* handler = CSchemeHandler::NewL( *url );
       
   220                                                CleanupStack::PushL( handler );
       
   221                                                handler->HandleUrlStandaloneL();
       
   222                                                CleanupStack::PopAndDestroy( handler );
       
   223                                                CleanupStack::PopAndDestroy( url );                                     */
       
   224                         }
       
   225                     break;
       
   226                     case TBrCtlDefs::EElementNone:
       
   227                     default:
       
   228                         break;
       
   229                     }
       
   230                 }
       
   231             break;
       
   232             case EAknSoftkeyBack:
       
   233                 {
       
   234                 CancelPendingMrCommandL();
       
   235                 NavigateBackL();
       
   236                 }
       
   237             break;
       
   238             case EFsEmailUiCmdActionsOpen:
       
   239             case EFsEmailUiCmdActionsReply:
       
   240                 {
       
   241                 if ( iMessage && !iActivationData.iEmbeddedMessageMode )
       
   242                     {
       
   243                     TEditorLaunchParams params;
       
   244 
       
   245                     params.iMailboxId = iAppUi.GetActiveMailboxId();
       
   246                     params.iMsgId = iMessage->GetMessageId();
       
   247                     params.iActivatedExternally = EFalse;
       
   248 
       
   249                     if ( iContainer )
       
   250                         {
       
   251                         HideContainer();
       
   252                         iContainer->ResetContent();
       
   253                         }
       
   254 
       
   255                     iAppUi.LaunchEditorL( KEditorCmdReply, params );
       
   256                     }
       
   257                 }
       
   258             break;
       
   259             case EFsEmailUiCmdActionsReplyAll:
       
   260                 {
       
   261                 if ( iMessage && !iActivationData.iEmbeddedMessageMode )
       
   262                     {
       
   263                     TEditorLaunchParams params;
       
   264                     params.iMailboxId = iAppUi.GetActiveMailboxId();
       
   265                     params.iMsgId = iMessage->GetMessageId();
       
   266                     params.iActivatedExternally = EFalse;
       
   267 
       
   268                     if ( iContainer )
       
   269                         {
       
   270                         HideContainer();
       
   271                         iContainer->ResetContent();
       
   272                         }
       
   273 
       
   274                     iAppUi.LaunchEditorL( KEditorCmdReplyAll, params );
       
   275                     }
       
   276                 }
       
   277             break;
       
   278             case EFsEmailUiCmdActionsForward:
       
   279                 {
       
   280                 if ( iMessage && !iActivationData.iEmbeddedMessageMode )
       
   281                     {
       
   282                     TEditorLaunchParams params;
       
   283                     params.iMailboxId = iAppUi.GetActiveMailboxId();
       
   284                     params.iMsgId = iMessage->GetMessageId();
       
   285                     params.iActivatedExternally = EFalse;
       
   286 
       
   287                     if ( iContainer )
       
   288                         {
       
   289                         HideContainer();
       
   290                         iContainer->ResetContent();
       
   291                         }
       
   292 
       
   293                     iAppUi.LaunchEditorL( KEditorCmdForward, params );
       
   294                     }
       
   295                 }
       
   296             break;
       
   297             case EFsEmailUiCmdActionsDelete:
       
   298                 {
       
   299                 DeleteMailL();
       
   300                 }
       
   301             break;
       
   302             case EFsEmailUiCmdZoomIn:
       
   303                 {
       
   304                 TUint zoomLevelIdx = ZoomLevelIndexL();
       
   305                 SetZoomLevelIndexL( zoomLevelIdx + 1 );
       
   306                 }
       
   307             break;
       
   308             case EFsEmailUiCmdZoomOut:
       
   309                 {
       
   310                 TUint zoomLevelIdx = ZoomLevelIndexL();
       
   311                 SetZoomLevelIndexL( zoomLevelIdx - 1 );
       
   312                 }
       
   313             break;
       
   314             case EFsEmailUiCmdHelp:
       
   315                 {
       
   316                 TFsEmailUiUtility::LaunchHelpL( KFSE_HLP_LAUNCHER_GRID );
       
   317                 }
       
   318             break;
       
   319             case EFsEmailUiCmdExit:
       
   320                 {
       
   321                 // <cmail>
       
   322                 iContainer->PrepareForExit();
       
   323                 // </cmail>
       
   324                 iAppUi.Exit();
       
   325                 }
       
   326             break;
       
   327             case EFsEmailUiCmdOpenAttachmentList:
       
   328                 {
       
   329                 TAttachmentListActivationData params;
       
   330                 params.iMailBoxId = iMessage->GetMailBoxId();
       
   331                 params.iFolderId = iMessage->GetFolderId();
       
   332                 params.iMessageId = iMessage->GetMessageId();
       
   333                 // use package buffer to pass the params
       
   334                 TPckgBuf<TAttachmentListActivationData> buf( params );
       
   335                 TUid emptyCustomMessageId = { 0 };
       
   336                 iAppUi.EnterFsEmailViewL( AttachmentMngrViewId, emptyCustomMessageId, buf );
       
   337 
       
   338                 }
       
   339             break;
       
   340              case EFsEmailUiCmdPreviousMessage:
       
   341                  {
       
   342                  ShowPreviousMessageL();
       
   343                  }
       
   344                  break;
       
   345              case EFsEmailUiCmdNextMessage:
       
   346                  {
       
   347                  ShowNextMessageL();
       
   348                  }
       
   349                  break;
       
   350              case EFsEmailUiCmdMarkAsUnread:
       
   351                  {
       
   352                  ChangeMsgReadStatusL( EFalse, EFalse );
       
   353                  }
       
   354                  break;
       
   355              case EFsEmailUiCmdMarkAsRead:
       
   356                  {
       
   357                  ChangeMsgReadStatusL( ETrue, EFalse );
       
   358                  }
       
   359                  break;
       
   360              case EFsEmailUiCmdActionsMoveMessage:
       
   361                  {
       
   362                  OpenFolderListForMessageMovingL();
       
   363                  }
       
   364                  break;
       
   365              case EFsEmailUiCmdActionsFlag:
       
   366                  {
       
   367                  SetMessageFollowupFlagL();
       
   368                  }
       
   369                  break;
       
   370              case EFsEmailUiCmdMessageDetails:
       
   371                  {
       
   372                  }
       
   373              case EFsEmailUiCmdCompose:
       
   374                  {
       
   375                  if ( iMessage )
       
   376                      {
       
   377                      
       
   378                      if ( iActivationData.iEmbeddedMessageMode )
       
   379                          {
       
   380                          iCreateNewMsgFromEmbeddedMsg = ETrue;
       
   381                          }
       
   382                      
       
   383                      HBufC* mailAddress=iMessage->GetSender()->GetEmailAddress().AllocLC();
       
   384                      delete iNewMailTempAddress;
       
   385                      iNewMailTempAddress = NULL;
       
   386                      iNewMailTempAddress = CFSMailAddress::NewL();
       
   387                      iNewMailTempAddress->SetEmailAddress( *mailAddress );
       
   388                      CleanupStack::PopAndDestroy( mailAddress );
       
   389                      iAppUi.LaunchEditorL( iNewMailTempAddress );
       
   390                      }
       
   391                  }
       
   392                  break;
       
   393             default:
       
   394                 {
       
   395                 if ( aCommand >= EFsEmailUiCmdZoomSmallest )
       
   396                     {
       
   397                     TUint zoomLevelIndex = aCommand - EFsEmailUiCmdZoomSmallest;
       
   398                     SetZoomLevelIndexL( zoomLevelIndex );
       
   399                     }
       
   400                 }
       
   401             break;
       
   402             }
       
   403         }
       
   404     }
       
   405 
       
   406 // ---------------------------------------------------------------------------
       
   407 // Changes the MSK command depending on the focused element.
       
   408 // ---------------------------------------------------------------------------
       
   409 //
       
   410 void CFsEmailUiHtmlViewerView::SetMskL()
       
   411     {
       
   412     FUNC_LOG;
       
   413     TBrCtlDefs::TBrCtlElementType elementType = iContainer->BrowserControlIf()->FocusedElementType();
       
   414 
       
   415     switch ( elementType )
       
   416         {
       
   417         case TBrCtlDefs::EElementTelAnchor:
       
   418         case TBrCtlDefs::EElementSmartLinkTel:
       
   419             ChangeMskCommandL( R_FSE_QTN_MSK_CALL );
       
   420             break;
       
   421         case TBrCtlDefs::EElementMailtoAnchor:
       
   422         case TBrCtlDefs::EElementSmartLinkEmail:
       
   423             ChangeMskCommandL( R_FSE_QTN_MSK_COMPOSE );
       
   424             break;
       
   425         case TBrCtlDefs::EElementAnchor:
       
   426             ChangeMskCommandL( R_FSE_QTN_MSK_OPENURL );
       
   427             break;
       
   428         case TBrCtlDefs::EElementNone:
       
   429         default:
       
   430             ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
   431             break;
       
   432         }
       
   433     }
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 // Hides the container and removes it from control stack.
       
   437 // -----------------------------------------------------------------------------
       
   438 //
       
   439 void CFsEmailUiHtmlViewerView::HideContainer()
       
   440     {
       
   441     FUNC_LOG;
       
   442 
       
   443     if ( iContainer )
       
   444         {
       
   445         iContainer->MakeVisible( EFalse );
       
   446         iAppUi.RemoveFromStack( iContainer );
       
   447         }
       
   448     }
       
   449 
       
   450 // -----------------------------------------------------------------------------
       
   451 // Add the container to control stack and sets it visible.
       
   452 // -----------------------------------------------------------------------------
       
   453 //
       
   454 void CFsEmailUiHtmlViewerView::ShowContainerL()
       
   455     {
       
   456     FUNC_LOG;
       
   457 
       
   458     if ( iContainer )
       
   459         {
       
   460         iAppUi.AddToStackL( iContainer );
       
   461         iContainer->MakeVisible( ETrue );
       
   462         }
       
   463     }
       
   464 
       
   465 // -----------------------------------------------------------------------------
       
   466 // CFsEmailUiHtmlViewerView::DoActivateL()
       
   467 // Activate an Compose view
       
   468 // -----------------------------------------------------------------------------
       
   469 //
       
   470 void CFsEmailUiHtmlViewerView::ChildDoActivateL( const TVwsViewId& /*aPrevViewId*/,
       
   471         TUid aCustomMessageId, const TDesC8& aCustomMessage )
       
   472     {
       
   473     FUNC_LOG;
       
   474     
       
   475     TBool bodypartNotFound ( EFalse );
       
   476     
       
   477     if ( iMrObserverToInform && 
       
   478          aCustomMessageId == KStartViewerReturnToPreviousMsg )
       
   479         {
       
   480         // If returning from view launched by MRUI, complete the ongoing
       
   481         // async process.
       
   482         // Exception is the move message operation as it is not done through
       
   483         // normal async process for MR.
       
   484         if ( iOpResult.iOpType != EESMRCmdMailMoveMessage )
       
   485             {
       
   486             CompletePendingMrCommand();
       
   487             }
       
   488         else
       
   489             {
       
   490             CancelPendingMrCommandL();
       
   491             }
       
   492         }
       
   493     else if ( aCustomMessageId != KStartViewerReturnFromEmbeddedMsg )
       
   494         {
       
   495         // Cancel any pending asynchronous MR operation.
       
   496         CancelPendingMrCommandL();
       
   497         }
       
   498 
       
   499     // When returning from another view, we use previous activation data.
       
   500     // Otherwise it's read from the custom message.
       
   501     if ( aCustomMessageId != KHtmlViewerReturnToPrevious )
       
   502         {
       
   503         TPckgBuf<THtmlViewerActivationData> pckgData;
       
   504         pckgData.Copy( aCustomMessage );
       
   505         iActivationData = pckgData();
       
   506         }
       
   507 
       
   508     CleanupClosePushL( iActivationData.iFile );
       
   509     
       
   510     if ( !iMessage && iContainer )
       
   511         {
       
   512         iAppUi.RemoveFromStack( iContainer );
       
   513         iContainer->CancelFetch();
       
   514         iContainer->ClearCacheAndLoadEmptyContent();
       
   515         }
       
   516     
       
   517     if ( !iContainer )
       
   518         {
       
   519         iContainer = CFsEmailUiHtmlViewerContainer::NewL( iAppUi, *this );
       
   520         }
       
   521     else if ( iContainer ) // Container exists, make sure that it has a correct rect
       
   522         {
       
   523         iContainer->SetRect( ClientRect() );
       
   524         }
       
   525 
       
   526     // Check whether this activation is actually for a meeting request
       
   527     TBool openedInMrViewer( EFalse );    
       
   528     if ( THtmlViewerActivationData::EMailMessage == iActivationData.iActivationDataType )
       
   529         {
       
   530         openedInMrViewer = IsOpenedInMRViewerL();
       
   531         }
       
   532 
       
   533     if ( openedInMrViewer )
       
   534         {
       
   535         // The previous contents are cleared (otherwise they are shown just
       
   536         // before the meeting request viewer kicks in, especially annoying 
       
   537         // when navigating between prev/next meeting requests by using navi
       
   538         // decorator array buttons.
       
   539         iContainer->ClearCacheAndLoadEmptyContent();
       
   540         ClearMailViewer();
       
   541         }
       
   542     
       
   543     ShowContainerL();
       
   544         
       
   545     switch ( iActivationData.iActivationDataType )
       
   546         {
       
   547         case THtmlViewerActivationData::EMailMessage:
       
   548             {
       
   549                 
       
   550             if ( iMessage && iAppUi.DownloadInfoMediator() )
       
   551                 {
       
   552                 iAppUi.DownloadInfoMediator()->StopObserving( this, iMessage->GetMessageId() );
       
   553                 }
       
   554             
       
   555             //clean message stack which owns object iMessage
       
   556             EraseMessageStack();
       
   557             iMessage = NULL;
       
   558             iMessage = iAppUi.GetMailClient()->GetMessageByUidL(
       
   559             iActivationData.iMailBoxId,
       
   560             iActivationData.iFolderId,
       
   561             iActivationData.iMessageId,
       
   562             EFSMsgDataEnvelope  );
       
   563             
       
   564             UpdateToolbarL();
       
   565 
       
   566             if ( iMessage && iAppUi.DownloadInfoMediator() )
       
   567                 {
       
   568                 iAppUi.DownloadInfoMediator()->AddObserver( this, iMessage->GetMessageId() );
       
   569                 }
       
   570             
       
   571             delete iAttachmentsListModel;
       
   572             iAttachmentsListModel = NULL;
       
   573 
       
   574             if ( iMessage )
       
   575                 {
       
   576                 if ( !( iMrObserverToInform && aCustomMessageId == KStartViewerReturnToPreviousMsg )
       
   577                      && aCustomMessageId != KStartViewerReturnFromEmbeddedMsg )
       
   578                     {
       
   579                     //take ownership of iMessage
       
   580                     PushMessageL( iMessage, EFalse );
       
   581                     }
       
   582 
       
   583                 if ( openedInMrViewer )       
       
   584                     {
       
   585                     // Setting MSK empty. This blocks unwanted MSK keypresses before MrViewer is initialized.
       
   586                     ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
   587                     iMrUiActive = ETrue;
       
   588                     iAppUi.MrViewerInstanceL()->ExecuteViewL( *iMessage, *this );  
       
   589                     }                              
       
   590                 else
       
   591             		{
       
   592 		            iAttachmentsListModel = CFSEmailUiAttachmentsListModel::NewL( iAppUi, *this );
       
   593 		            TPartData msgPartData( iActivationData.iMailBoxId, iActivationData.iFolderId, iActivationData.iMessageId);
       
   594 		            iAttachmentsListModel->UpdateListL( msgPartData );
       
   595                        
       
   596             		TRAPD( error, LoadContentFromMailMessageL( iMessage ) );
       
   597             		if ( error == KErrNotFound || error == KErrInUse || error == KErrLocked )
       
   598             		    {
       
   599             		    bodypartNotFound = ETrue;
       
   600             		    }
       
   601             		else if ( error != KErrNone)
       
   602             		    {
       
   603             		    User::Leave( error );
       
   604             		    }
       
   605             		}
       
   606                 
       
   607                 }
       
   608             else
       
   609                 {
       
   610                 User::Leave( KErrNotFound );
       
   611                 }
       
   612             
       
   613             if ( aCustomMessageId != KStartViewerReturnToPreviousMsg )
       
   614                 {
       
   615                 delete iMailBox; iMailBox = NULL;
       
   616                 iMailBox = iAppUi.GetMailClient()->GetMailBoxByUidL( iMessage->GetMailBoxId() );
       
   617                 
       
   618                 // Change active mailbox if necessary
       
   619                 if ( !iMessage->GetMailBoxId().IsNullId() )
       
   620                     {
       
   621                     iAppUi.SetActiveMailboxL( iMessage->GetMailBoxId(), EFalse );
       
   622                     }
       
   623                 }
       
   624 
       
   625             }
       
   626         break;
       
   627         case THtmlViewerActivationData::EmbeddedEmailMessage:
       
   628             {
       
   629             if ( aCustomMessageId != KStartViewerReturnFromEmbeddedMsg && !iCreateNewMsgFromEmbeddedMsg )
       
   630                 {
       
   631                 PushMessageL(iActivationData.iEmbeddedMessage, ETrue);
       
   632                 }
       
   633             
       
   634             iMessage = iOpenMessages->Head();
       
   635             iCreateNewMsgFromEmbeddedMsg = EFalse;
       
   636             
       
   637             delete iAttachmentsListModel;
       
   638             iAttachmentsListModel = NULL;
       
   639             iAttachmentsListModel = CFSEmailUiAttachmentsListModel::NewL( iAppUi, *this );
       
   640             
       
   641             if ( iOpenMessages->Head()== iOpenMessages->Last() )
       
   642                 {
       
   643                 TPartData msgPartData( iActivationData.iMailBoxId, iActivationData.iFolderId, iActivationData.iMessageId);
       
   644                 iAttachmentsListModel->UpdateListL( msgPartData );
       
   645                                 
       
   646                 }
       
   647             else{
       
   648                 iAttachmentsListModel->UpdateListL( iOpenMessages->Head() );         
       
   649                 }                
       
   650                 
       
   651     
       
   652             TRAPD( error, LoadContentFromMailMessageL( iOpenMessages->Head() ) );
       
   653             if ( error == KErrNotFound || error == KErrInUse || error == KErrLocked )
       
   654                 {
       
   655                 bodypartNotFound = ETrue;
       
   656                 }
       
   657             else if ( error != KErrNone)
       
   658                 {
       
   659                 User::Leave( error );
       
   660                 }
       
   661             
       
   662             // update tool bar as some action menu boton should not appear in embbeded messages.
       
   663             UpdateToolbarL();
       
   664             
       
   665             }
       
   666         break;
       
   667         case THtmlViewerActivationData::EFile:
       
   668             {
       
   669             LoadContentFromFileL( iActivationData.iFile );
       
   670             }
       
   671         break;
       
   672         case THtmlViewerActivationData::EFileName:
       
   673             {
       
   674             LoadContentFromFileL( iActivationData.iFileName );
       
   675             }
       
   676         break;
       
   677         case THtmlViewerActivationData::EUrl:
       
   678             {
       
   679             LoadContentFromUrlL( iActivationData.iUrl );
       
   680             }
       
   681         break;
       
   682         }
       
   683     
       
   684     UpdateNaviPaneL();
       
   685 
       
   686     CleanupStack::PopAndDestroy( &iActivationData.iFile );
       
   687     SetMskL();
       
   688     
       
   689     if(iMessage)
       
   690         {
       
   691         CFSMailAddress* address = iMessage->GetSender();
       
   692         if ( address )
       
   693             {
       
   694             HBufC* displayName = address->GetDisplayName().AllocLC();
       
   695             
       
   696             if ( displayName->Length() )
       
   697                 {
       
   698                 iAppUi.SetTitlePaneTextL( *displayName );
       
   699                 }
       
   700             else
       
   701                 {
       
   702                 HBufC* emailAddress = address->GetEmailAddress().AllocLC();
       
   703                 iAppUi.SetTitlePaneTextL(*emailAddress);
       
   704                 CleanupStack::PopAndDestroy(emailAddress);
       
   705                 }
       
   706             CleanupStack::PopAndDestroy( displayName );      
       
   707             }
       
   708         }
       
   709     
       
   710     if ( !openedInMrViewer )
       
   711         {
       
   712         CFSMailMessagePart* htmlBodyPart = iMessage->HtmlBodyPartL();
       
   713         TFetchedType type;
       
   714         if( htmlBodyPart )
       
   715             {
       
   716             type = EMessageHtmlBodyPart;
       
   717             }
       
   718         else
       
   719             {
       
   720             type = EMessagePlainTextBodyPart;
       
   721             }
       
   722         if( !MessageStructureKnown(*iMessage) )
       
   723             {
       
   724             StartWaitedFetchingL(EMessageStructure);
       
   725             iFetchingAlready = ETrue;
       
   726             }
       
   727         else if ( !MessagePartFullyFetchedL( type ) || bodypartNotFound )
       
   728             {
       
   729             iAsyncProcessComplete = EFalse;
       
   730             iFetchingAlready = EFalse;
       
   731             iStartAsyncFetchType = type;
       
   732             if(iMessage)
       
   733                 {
       
   734                 StartFetchingMessagePartL( *iMessage, type );
       
   735                 }
       
   736             }
       
   737        }
       
   738     iNextOrPrevMessageSelected = EFalse;
       
   739     }
       
   740 
       
   741 // -----------------------------------------------------------------------------
       
   742 // CFsEmailUiHtmlViewerView::OfferToolbarEventL
       
   743 // -----------------------------------------------------------------------------
       
   744 void CFsEmailUiHtmlViewerView::OfferToolbarEventL( TInt aCommand )
       
   745     {
       
   746     FUNC_LOG;
       
   747     switch (aCommand)
       
   748         {
       
   749         case EFsEmailUiTbCmdReply:
       
   750             {
       
   751             HandleCommandL(EFsEmailUiCmdActionsReply);
       
   752             break;
       
   753             }
       
   754 
       
   755         case EFsEmailUiTbCmdForward:
       
   756             {
       
   757             HandleCommandL(EFsEmailUiCmdActionsForward);
       
   758             break;
       
   759             }
       
   760         case EFsEmailUiTbCmdDelete:
       
   761             {
       
   762             HandleCommandL(EFsEmailUiCmdActionsDelete);
       
   763             break;
       
   764             }
       
   765         case EFsEmailUiTbCmdReplyAll:
       
   766             {
       
   767             HandleCommandL(EFsEmailUiCmdActionsReplyAll);
       
   768             break;
       
   769             }
       
   770         default:
       
   771             break;
       
   772         }
       
   773     }
       
   774 
       
   775 // -----------------------------------------------------------------------------
       
   776 // CFsEmailUiHtmlViewerView::ToolbarResourceId
       
   777 // -----------------------------------------------------------------------------
       
   778 TInt CFsEmailUiHtmlViewerView::ToolbarResourceId() const
       
   779     {
       
   780     TInt resourceId( R_FREESTYLE_EMAIL_UI_TOOLBAR_HTML_MESSAGE_VIEWER_NO_REPLY_ALL );
       
   781     if (iMessage)
       
   782         {
       
   783         if (!iActivationData.iEmbeddedMessageMode && 
       
   784                 TFsEmailUiUtility::CountRecipientsSmart( iAppUi, iMessage ) > 1)
       
   785             {            
       
   786             resourceId = R_FREESTYLE_EMAIL_UI_TOOLBAR_HTML_MESSAGE_VIEWER;
       
   787             }
       
   788         }    
       
   789     return resourceId;
       
   790     }
       
   791 
       
   792 // -----------------------------------------------------------------------------
       
   793 // CFsEmailUiHtmlViewerView::GetInitiallyDimmedItemsL
       
   794 // -----------------------------------------------------------------------------
       
   795 void CFsEmailUiHtmlViewerView::GetInitiallyDimmedItemsL( const TInt aResourceId,
       
   796                 RArray<TInt>& aDimmedItems ) const
       
   797     {
       
   798     if ( R_FREESTYLE_EMAIL_UI_TOOLBAR_HTML_MESSAGE_VIEWER == aResourceId || 
       
   799          R_FREESTYLE_EMAIL_UI_TOOLBAR_HTML_MESSAGE_VIEWER_NO_REPLY_ALL == aResourceId )
       
   800         {
       
   801         if ( iActivationData.iEmbeddedMessageMode )
       
   802             {
       
   803             aDimmedItems.AppendL(EFsEmailUiTbCmdActions);
       
   804             aDimmedItems.AppendL(EFsEmailUiTbCmdDelete);
       
   805             }
       
   806         }
       
   807     }
       
   808 
       
   809 // -----------------------------------------------------------------------------
       
   810 // CFsEmailUiHtmlViewerView::ChildDoDeactivate()
       
   811 // Deactivate the HTML view
       
   812 // -----------------------------------------------------------------------------
       
   813 //
       
   814 void CFsEmailUiHtmlViewerView::ChildDoDeactivate()
       
   815     {
       
   816     FUNC_LOG;
       
   817     CancelFetchings();
       
   818    
       
   819     if ( iContainer )
       
   820         {
       
   821         HideContainer();
       
   822         iContainer->ResetContent();
       
   823         iAppUi.RemoveFromStack(iContainer);
       
   824         iContainer->CancelFetch();
       
   825         iContainer->ClearCacheAndLoadEmptyContent();
       
   826         }
       
   827     Toolbar()->SetToolbarObserver( this );
       
   828     iMessage = NULL;
       
   829     HideNaviPane();
       
   830     }
       
   831 
       
   832 void CFsEmailUiHtmlViewerView::DoExitL()
       
   833     {
       
   834     FUNC_LOG;
       
   835     delete iMessage;
       
   836     iMessage = NULL;
       
   837     CancelFetchings();
       
   838     
       
   839     if ( iFlagSelectionHandler )
       
   840         {
       
   841         iFlagSelectionHandler->Cancel();
       
   842         delete iFlagSelectionHandler;
       
   843         iFlagSelectionHandler = NULL;
       
   844         }
       
   845     iAppUi.ReturnFromHtmlViewerL();
       
   846     }
       
   847 
       
   848 // CFsEmailUiHtmlViewerView::NavigateBackL
       
   849 // Overriden from base class
       
   850 // -----------------------------------------------------------------------------
       
   851 void CFsEmailUiHtmlViewerView::NavigateBackL()
       
   852     {
       
   853     FUNC_LOG;
       
   854     // clean up current message 
       
   855     if ( iMessage && iAppUi.DownloadInfoMediator() )
       
   856         {
       
   857         iAppUi.DownloadInfoMediator()->StopObserving( this, iMessage->GetMessageId() );
       
   858         }
       
   859     iContainer->StopObserving();
       
   860     CFSMailMessage* tmp = PopMessage();
       
   861     if( tmp )
       
   862         {
       
   863         delete tmp;
       
   864         tmp = NULL;
       
   865         }
       
   866     
       
   867     if ( iFlagSelectionHandler )
       
   868         {
       
   869         iFlagSelectionHandler->Cancel();
       
   870         delete iFlagSelectionHandler;
       
   871         iFlagSelectionHandler = NULL;
       
   872         }
       
   873 
       
   874     // Return to previous message in the stack if there is still some left
       
   875     if ( !iOpenMessages->IsEmpty() )
       
   876         {
       
   877        
       
   878         THtmlViewerActivationData htmlData; 
       
   879         if ( iOpenMessages->Head()!= iOpenMessages->Last() )
       
   880             {
       
   881             htmlData.iActivationDataType = THtmlViewerActivationData::EmbeddedEmailMessage;
       
   882             htmlData.iEmbeddedMessageMode = ETrue;
       
   883            
       
   884             }
       
   885         else
       
   886             {
       
   887             htmlData.iActivationDataType = THtmlViewerActivationData::EmbeddedEmailMessage;
       
   888             htmlData.iMailBoxId = iOpenMessages->Head()->GetMailBoxId();
       
   889             htmlData.iFolderId  = iOpenMessages->Head()->GetFolderId();
       
   890             htmlData.iMessageId = iOpenMessages->Head()->GetMessageId();
       
   891             }
       
   892         
       
   893         TPckgBuf<THtmlViewerActivationData> pckgData( htmlData );
       
   894         iAppUi.EnterFsEmailViewL( HtmlViewerId, KStartViewerReturnFromEmbeddedMsg, pckgData );
       
   895       
       
   896         }
       
   897     // In usual case we use the base view implementation
       
   898     else
       
   899         {
       
   900         
       
   901         iMessage = NULL;
       
   902         
       
   903         CancelFetchings();
       
   904              
       
   905         CFsEmailUiViewBase::NavigateBackL();
       
   906         }
       
   907     }
       
   908 
       
   909 void CFsEmailUiHtmlViewerView::DynInitMenuPaneL( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   910     {
       
   911     FUNC_LOG;
       
   912 
       
   913     if ( aResourceId == R_FSEMAILUI_HTMLVIEWER_MENUPANE )
       
   914         {
       
   915         
       
   916         if ( FeatureManager::FeatureSupported( KFeatureIdFfCmailIntegration ) )
       
   917             {
       
   918             // remove help support in pf5250
       
   919             aMenuPane->SetItemDimmed( EFsEmailUiCmdHelp, ETrue);      
       
   920             }   
       
   921         
       
   922         // Some commands are blocked when viewing embedded message object
       
   923         // or separate HTML file.
       
   924         const TBool blockCmds( !iMessage || iActivationData.iEmbeddedMessageMode );
       
   925         const TBool blockReplyALLCmd( !iMessage || iActivationData.iEmbeddedMessageMode ||
       
   926                 TFsEmailUiUtility::CountRecipientsSmart( iAppUi, iMessage ) < 2 );       
       
   927         aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsReply, blockCmds );
       
   928         aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsReplyAll, blockReplyALLCmd );
       
   929         aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsForward, blockCmds );
       
   930         aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsDelete, blockCmds );
       
   931         
       
   932         TBool hideNext = !ShowNextMessageMenuInOptions();
       
   933         TBool blockNextCmd = !iMessage || iActivationData.iEmbeddedMessageMode || hideNext;
       
   934         aMenuPane->SetItemDimmed( EFsEmailUiCmdNextMessage, blockNextCmd );
       
   935         TBool hidePrev = !ShowPreviousMessageMenuInOptions();
       
   936         TBool blockPrevCmd = !iMessage || iActivationData.iEmbeddedMessageMode || hidePrev;
       
   937         aMenuPane->SetItemDimmed( EFsEmailUiCmdPreviousMessage, blockPrevCmd );
       
   938         }
       
   939     else if ( aResourceId == R_FSEMAILUI_HTMLVIEWER_SUBMENU_ZOOM_LEVEL &&
       
   940               iContainer && iContainer->BrowserControlIf() )
       
   941         {
       
   942         DynInitZoomMenuL( aMenuPane );
       
   943         }
       
   944     else if ( aResourceId == R_FSEMAILUI_MAILVIEWER_SUBMENU_MORE )
       
   945         {
       
   946         if( iActivationData.iEmbeddedMessageMode )
       
   947             {
       
   948             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsRead, ETrue );
       
   949             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, ETrue );
       
   950             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsMoveMessage, ETrue );
       
   951             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsFlag, ETrue );
       
   952             }
       
   953         else
       
   954             {
       
   955             CFSMailFolder* currentFolder = NULL;
       
   956             if ( iMessage )
       
   957                 {
       
   958                 TRAP_IGNORE( currentFolder = 
       
   959                     iAppUi.GetMailClient()->GetFolderByUidL(
       
   960                             iMessage->GetMailBoxId(), 
       
   961                             iMessage->GetFolderId() ) );
       
   962                 }
       
   963           
       
   964             if ( currentFolder &&
       
   965                  currentFolder->GetFolderType() != EFSOutbox )
       
   966                 {
       
   967                 // Mark as read/unread options
       
   968                 TBool messageIsRead( iMessage->IsFlagSet( EFSMsgFlag_Read ) );
       
   969                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsRead, messageIsRead );
       
   970                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, !messageIsRead );
       
   971                 
       
   972                 // Move to another folder option
       
   973                 aMenuPane->SetItemDimmed( 
       
   974                         EFsEmailUiCmdActionsMoveMessage, 
       
   975                         !iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaMoveToFolder ) );
       
   976 
       
   977                 // Follow-up flag option
       
   978                 aMenuPane->SetItemDimmed( 
       
   979                         EFsEmailUiCmdActionsFlag,
       
   980                         !( iMailBox && TFsEmailUiUtility::IsFollowUpSupported( *iMailBox ) ) );
       
   981                 }
       
   982             else
       
   983                 {
       
   984                 // In case of outbox, all these are dimmed
       
   985                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, ETrue );
       
   986                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsRead, ETrue );
       
   987                 aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsMoveMessage, ETrue );
       
   988                 aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsFlag, ETrue );
       
   989                 }
       
   990             delete currentFolder;
       
   991             }
       
   992         aMenuPane->SetItemDimmed( EFsEmailUiCmdMessageDetails, ETrue );
       
   993         }
       
   994     iAppUi.ShortcutBinding().AppendShortcutHintsL( *aMenuPane,
       
   995             CFSEmailUiShortcutBinding::EContextHtmlViewer );
       
   996     }
       
   997     
       
   998 // -----------------------------------------------------------------------------
       
   999 // CFsEmailUiHtmlViewerView::HandleMrCommandL
       
  1000 // Handle accept/decline/tentative/remove commands given for meeting request
       
  1001 // message directly from list UI.
       
  1002 // -----------------------------------------------------------------------------
       
  1003 void CFsEmailUiHtmlViewerView::HandleMrCommandL(
       
  1004     TInt aCommandId,
       
  1005     TFSMailMsgId aMailboxId,
       
  1006     TFSMailMsgId aFolderId,
       
  1007     TFSMailMsgId aMessageId )
       
  1008     {
       
  1009     FUNC_LOG;
       
  1010     ///any init required? 
       
  1011     UpdateMessagePtrL( aMailboxId, aFolderId, aMessageId );
       
  1012 
       
  1013     if ( aCommandId == EFsEmailUiCmdCalRemoveFromCalendar )
       
  1014         {
       
  1015         iAppUi.MrViewerInstanceL()->RemoveMeetingRequestFromCalendarL(
       
  1016             *iMessage, *this );
       
  1017         }
       
  1018     else
       
  1019         {
       
  1020         TESMRAttendeeStatus respondStatus;
       
  1021         if ( aCommandId == EFsEmailUiCmdCalActionsAccept )
       
  1022             {
       
  1023             respondStatus = EESMRAttendeeStatusAccept;
       
  1024             }
       
  1025         else if ( aCommandId == EFsEmailUiCmdCalActionsTentative )
       
  1026             {
       
  1027             respondStatus = EESMRAttendeeStatusTentative;
       
  1028             }
       
  1029         else // ( aCommandId == EFsEmailUiCmdCalActionsDecline )
       
  1030             {
       
  1031             respondStatus = EESMRAttendeeStatusDecline;
       
  1032             }
       
  1033         iAppUi.MrViewerInstanceL()->ResponseToMeetingRequestL(
       
  1034             respondStatus, *iMessage, *this );
       
  1035         }
       
  1036     }
       
  1037 
       
  1038 
       
  1039 void CFsEmailUiHtmlViewerView::HandleDynamicVariantSwitchL( CFsEmailUiViewBase::TDynamicSwitchType /*aType*/ )
       
  1040     {
       
  1041     FUNC_LOG;
       
  1042 
       
  1043     if ( iContainer )
       
  1044         {
       
  1045         iContainer->SetRect( ClientRect() );
       
  1046         }
       
  1047     }
       
  1048 
       
  1049 void CFsEmailUiHtmlViewerView::LoadContentFromFileL( const TDesC& aFileName )
       
  1050     {
       
  1051     FUNC_LOG;
       
  1052 
       
  1053     if ( iContainer )
       
  1054         {
       
  1055         iContainer->LoadContentFromFileL( aFileName );
       
  1056         }
       
  1057     }
       
  1058 
       
  1059 void CFsEmailUiHtmlViewerView::LoadContentFromFileL( RFile& aFile )
       
  1060     {
       
  1061     FUNC_LOG;
       
  1062 
       
  1063     if ( iContainer )
       
  1064         {
       
  1065         iContainer->LoadContentFromFileL( aFile );
       
  1066         }
       
  1067     }
       
  1068 
       
  1069 void CFsEmailUiHtmlViewerView::LoadContentFromUrlL( const TDesC& aUrl )
       
  1070     {
       
  1071     FUNC_LOG;
       
  1072 
       
  1073     if ( iContainer )
       
  1074         {
       
  1075         iContainer->LoadContentFromUrlL( aUrl );
       
  1076         }
       
  1077     }
       
  1078 
       
  1079 void CFsEmailUiHtmlViewerView::LoadContentFromMailMessageL( CFSMailMessage* aMailMessage )
       
  1080     {
       
  1081     FUNC_LOG;
       
  1082 
       
  1083     if ( iContainer )
       
  1084         {
       
  1085         iContainer->LoadContentFromMailMessageL( aMailMessage );
       
  1086         }
       
  1087     }
       
  1088 
       
  1089 void CFsEmailUiHtmlViewerView::DeleteMailL()
       
  1090     {
       
  1091     FUNC_LOG;
       
  1092 
       
  1093     if ( !iMessage || iActivationData.iEmbeddedMessageMode )
       
  1094         {
       
  1095         return;
       
  1096         }
       
  1097 
       
  1098     TInt reallyDelete( ETrue );
       
  1099 
       
  1100     if ( iAppUi.GetCRHandler()->WarnBeforeDelete() && 
       
  1101          !iMessage->IsFlagSet( EFSMsgFlag_CalendarMsg ) )
       
  1102         {
       
  1103         reallyDelete = TFsEmailUiUtility::ShowConfirmationQueryL(
       
  1104                            R_FREESTYLE_EMAIL_UI_DELETE_MESSAGE_CONFIRMATION );
       
  1105         }
       
  1106 
       
  1107     if ( reallyDelete )
       
  1108         {
       
  1109         // Reset container content, so that plugins may really delete files
       
  1110         if ( iContainer )
       
  1111             {
       
  1112             HideContainer();
       
  1113             iContainer->ResetContent();
       
  1114             }
       
  1115 
       
  1116         RArray<TFSMailMsgId> msgIds;
       
  1117         CleanupClosePushL( msgIds );
       
  1118         msgIds.Append( iMessage->GetMessageId() );
       
  1119         TFSMailMsgId mailBox = iMessage->GetMailBoxId();
       
  1120         TFSMailMsgId folderId = iMessage->GetFolderId();
       
  1121         iAppUi.GetMailClient()->DeleteMessagesByUidL( mailBox, folderId, msgIds );
       
  1122         CleanupStack::PopAndDestroy( &msgIds );
       
  1123 
       
  1124         // Notify appui of deleted mail item
       
  1125         SendEventToAppUiL( TFSEventMailDeleted );
       
  1126 
       
  1127         if ( iAppUi.CurrentActiveView()->Id() == HtmlViewerId )
       
  1128             {
       
  1129             NavigateBackL();
       
  1130             }
       
  1131         }
       
  1132     }
       
  1133 
       
  1134 // ---------------------------------------------------------------------------
       
  1135 // HandleMailBoxEventL
       
  1136 // Mailbox event handler, responds to events sent by the plugin.
       
  1137 // ---------------------------------------------------------------------------
       
  1138 //
       
  1139 void CFsEmailUiHtmlViewerView::HandleMailBoxEventL( TFSMailEvent aEvent,
       
  1140         TFSMailMsgId aMailbox, TAny* aParam1, TAny* /*aParam2*/, TAny* /*aParam3*/ )
       
  1141     {
       
  1142     FUNC_LOG;
       
  1143 
       
  1144     if ( /*iFirstStartCompleted &&*/ iMessage && aMailbox.Id() == iAppUi.GetActiveMailboxId().Id() &&
       
  1145                                      aEvent == TFSEventMailDeleted && aParam1 ) // Safety, in list events that only concern active mailbox are handled
       
  1146         {
       
  1147         TFSMailMsgId curMsgId = iMessage->GetMessageId();
       
  1148         RArray<TFSMailMsgId>* removedEntries = static_cast<RArray<TFSMailMsgId>*>( aParam1 );
       
  1149         // <cmail> break-keyword should be used only in switch-clauses
       
  1150         TBool cont = ETrue;
       
  1151 
       
  1152         for ( TInt i = 0 ; i < removedEntries->Count() && cont; i++ )
       
  1153             {
       
  1154             if ( curMsgId == ( *removedEntries )[i] )
       
  1155                 {
       
  1156                 ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
  1157                 NavigateBackL();
       
  1158                 cont = EFalse;
       
  1159                 }
       
  1160             }
       
  1161         }
       
  1162     if (iMessage && aMailbox.Id() == iAppUi.GetActiveMailboxId().Id() && aEvent == TFSEventNewMail)
       
  1163         {
       
  1164         UpdateNaviPaneL();
       
  1165         }
       
  1166     // </cmail>
       
  1167     }
       
  1168 
       
  1169 void CFsEmailUiHtmlViewerView::DynInitZoomMenuL( CEikMenuPane* aMenuPane )
       
  1170     {
       
  1171     FUNC_LOG;
       
  1172     TInt zoomLevelIdx = ZoomLevelIndexL();
       
  1173 
       
  1174     // Set the radio button state to match current zoom level
       
  1175     if ( zoomLevelIdx >= 0 && zoomLevelIdx < KZoomLevelCount )
       
  1176         {
       
  1177         TInt curZoomLevel = zoomLevelIdx + EFsEmailUiCmdZoomSmallest;
       
  1178         aMenuPane->SetItemButtonState( curZoomLevel, EEikMenuItemSymbolOn );
       
  1179         }
       
  1180     }
       
  1181 
       
  1182 TInt CFsEmailUiHtmlViewerView::ZoomLevelIndexL()
       
  1183     {
       
  1184     FUNC_LOG;
       
  1185     TInt zoomLevelIdx = iContainer->BrowserControlIf()->BrowserSettingL(
       
  1186                             TBrCtlDefs::ESettingsCurrentZoomLevelIndex );
       
  1187 
       
  1188     // Behaviour of zooming in Browser Control Interface is different in version 7.1
       
  1189     // than in previous versions and we need to support both. In older versions there
       
  1190     // are 4 preset zoom levels while version 7.1 can zoom to any percent.
       
  1191     RArray<TUint>* zoomLevels = iContainer->BrowserControlIf()->ZoomLevels();
       
  1192 
       
  1193     if ( !zoomLevels || !zoomLevels->Count() || ( *zoomLevels )[0] != KZoomLevels[0] )
       
  1194         {
       
  1195         // new browser:
       
  1196         // BrowserControlIf gives zoom level percentage insted of index to array
       
  1197         TBool found = EFalse;
       
  1198 
       
  1199         for ( TInt i = 0 ; i < KZoomLevelCount && !found ; ++i )
       
  1200             {
       
  1201             if ( zoomLevelIdx == KZoomLevels[i] )
       
  1202                 {
       
  1203                 zoomLevelIdx = i;
       
  1204                 found = ETrue;
       
  1205                 }
       
  1206             }
       
  1207 
       
  1208         if ( !found )
       
  1209             {
       
  1210             zoomLevelIdx = KErrNotFound;
       
  1211             }
       
  1212         }
       
  1213 
       
  1214     return zoomLevelIdx;
       
  1215     }
       
  1216 
       
  1217 void CFsEmailUiHtmlViewerView::SetZoomLevelIndexL( TInt aIndex )
       
  1218     {
       
  1219     FUNC_LOG;
       
  1220     TInt newValue = KMinTInt;
       
  1221 
       
  1222     // Behaviour of zooming in Browser Control Interface is different in version 7.1
       
  1223     // than in previous versions and we need to support both. In older versions there
       
  1224     // are 4 preset zoom levels while version 7.1 can zoom to any percent.
       
  1225     RArray<TUint>* zoomLevels = iContainer->BrowserControlIf()->ZoomLevels();
       
  1226 
       
  1227     if ( !zoomLevels || !zoomLevels->Count() || ( *zoomLevels )[0] != KZoomLevels[0] )
       
  1228         {
       
  1229         // new browser:
       
  1230         // BrowserControlIf takes zoom level percentage insted of index to array
       
  1231         if ( aIndex >= 0 && aIndex < KZoomLevelCount )
       
  1232             {
       
  1233             newValue = KZoomLevels[aIndex];
       
  1234             }
       
  1235         }
       
  1236     else
       
  1237         {
       
  1238         // old browser
       
  1239         newValue = aIndex;
       
  1240         }
       
  1241 
       
  1242     if ( newValue > KMinTInt )
       
  1243         {
       
  1244         iContainer->BrowserControlIf()->SetBrowserSettingL(
       
  1245             TBrCtlDefs::ESettingsCurrentZoomLevelIndex, newValue );
       
  1246         }
       
  1247     }
       
  1248 
       
  1249 // -----------------------------------------------------------------------------
       
  1250 // CFsEmailUiHtmlViewerView::HandleEmailAddressCommandL()
       
  1251 // -----------------------------------------------------------------------------
       
  1252 //
       
  1253 void CFsEmailUiHtmlViewerView::HandleEmailAddressCommandL( TInt aCommand, const TDesC& aEmailAddress )
       
  1254     {
       
  1255     FUNC_LOG;
       
  1256 
       
  1257     if ( !iAppUi.ViewSwitchingOngoing() )
       
  1258         {
       
  1259         switch ( aCommand )
       
  1260             {
       
  1261             case EFsEmailUiCmdActionsReply:
       
  1262                 {
       
  1263                 if ( iMessage && !iActivationData.iEmbeddedMessageMode )
       
  1264                     {
       
  1265                     delete iNewMailTempAddress;
       
  1266                     iNewMailTempAddress = NULL;
       
  1267                     iNewMailTempAddress = CFSMailAddress::NewL();
       
  1268                     iNewMailTempAddress->SetEmailAddress( aEmailAddress );
       
  1269                     iAppUi.LaunchEditorL( iNewMailTempAddress );
       
  1270                     }
       
  1271                 }
       
  1272             break;
       
  1273             case FsEActionMenuAddToContacts:
       
  1274                 {
       
  1275                 SaveEmailAsContactL( aEmailAddress );
       
  1276                 }
       
  1277             break;
       
  1278             case EFsEmailUiCmdActionsCall:
       
  1279                 {
       
  1280                 CallAdressL( aEmailAddress, EFalse );
       
  1281                 }
       
  1282             break;
       
  1283             case EFsEmailUiCmdActionsCreateMessage:
       
  1284                 {
       
  1285                 CreateMessageL( aEmailAddress );
       
  1286                 }
       
  1287             break;
       
  1288             case EFsEmailUiCmdActionsContactDetails:
       
  1289                 {
       
  1290                 OpenContactDetailsL( aEmailAddress );
       
  1291                 }
       
  1292             break;
       
  1293             case EFsEmailUiCmdActionsRemoteLookup:
       
  1294                 {
       
  1295                 LaunchRemoteLookupL( aEmailAddress );
       
  1296                 }
       
  1297             break;
       
  1298             default:
       
  1299                 //nothing right now?
       
  1300                 break;
       
  1301             }
       
  1302         }
       
  1303     }
       
  1304 
       
  1305 void CFsEmailUiHtmlViewerView::SaveEmailAsContactL(
       
  1306     const TDesC& aEmailAddress )
       
  1307     {
       
  1308     TAddToContactsType type;
       
  1309 
       
  1310     // Query to "update existing" or "Create new"
       
  1311     // --> EFALSE = user chose "cancel"
       
  1312     if ( CFsDelayedLoader::InstanceL()->GetContactHandlerL()->
       
  1313             AddtoContactsQueryL( type ) )
       
  1314         {
       
  1315         // Create buffer and strip scheme data such as mailto: and call:
       
  1316         HBufC* textData = aEmailAddress.AllocLC();
       
  1317         CFsDelayedLoader::InstanceL()->GetContactHandlerL()->AddToContactL(
       
  1318             *textData, EContactUpdateEmail, type, this );
       
  1319         CleanupStack::PopAndDestroy( textData );
       
  1320         }
       
  1321     }
       
  1322 
       
  1323 // ---------------------------------------------------------------------------
       
  1324 // From MFSEmailUiContactHandlerObserver
       
  1325 // The ownership of the CLS items in the contacts array is transferred to the
       
  1326 // observer, and they must be deleted by the observer.
       
  1327 // ---------------------------------------------------------------------------
       
  1328 //
       
  1329 void CFsEmailUiHtmlViewerView::OperationCompleteL(
       
  1330     TContactHandlerCmd /*aCmd*/, const RPointerArray<CFSEmailUiClsItem>& /*aContacts*/ )
       
  1331     {
       
  1332     FUNC_LOG;
       
  1333     }
       
  1334 
       
  1335 // ---------------------------------------------------------------------------
       
  1336 // From MFSEmailUiContactHandlerObserver
       
  1337 // Handles error in contatct handler operation.
       
  1338 // ---------------------------------------------------------------------------
       
  1339 //
       
  1340 void CFsEmailUiHtmlViewerView::OperationErrorL(
       
  1341     TContactHandlerCmd /*aCmd*/, TInt /*aError*/ )
       
  1342     {
       
  1343     FUNC_LOG;
       
  1344     }
       
  1345 
       
  1346 
       
  1347 TBool CFsEmailUiHtmlViewerView::IsRemoteLookupSupportedL()
       
  1348     {
       
  1349     CFSMailBox* mailBox = iAppUi.GetMailClient()->GetMailBoxByUidL( iMessage->GetMailBoxId() );
       
  1350     CleanupStack::PushL( mailBox );
       
  1351     TBool isSupported = ( TFsEmailUiUtility::IsRemoteLookupSupported( *mailBox ) );
       
  1352     CleanupStack::PopAndDestroy( mailBox );
       
  1353     return isSupported;
       
  1354     }
       
  1355 
       
  1356 void CFsEmailUiHtmlViewerView::CallAdressL( const TDesC& aEmailAddress, TBool aVideoCall )
       
  1357     {
       
  1358     HBufC* emailAddress = aEmailAddress.AllocLC();
       
  1359 
       
  1360     if ( aVideoCall )
       
  1361         {
       
  1362         CFsDelayedLoader::InstanceL()->GetContactHandlerL()->SetVideoCall(
       
  1363             ETrue );
       
  1364         }
       
  1365 
       
  1366     CFsDelayedLoader::InstanceL()->GetContactHandlerL()->FindAndCallToContactByEmailL( *emailAddress,
       
  1367             iAppUi.GetActiveMailbox(), this, EFalse );
       
  1368     CleanupStack::PopAndDestroy( emailAddress );
       
  1369     }
       
  1370 
       
  1371 // -----------------------------------------------------------------------------
       
  1372 // CFsEmailUiHtmlViewerView::OpenContactDetailsL
       
  1373 // -----------------------------------------------------------------------------
       
  1374 void CFsEmailUiHtmlViewerView::OpenContactDetailsL( const TDesC& aEmailAddress )
       
  1375     {
       
  1376     HBufC* emailAddress = aEmailAddress.AllocLC();
       
  1377     CFsDelayedLoader::InstanceL()->GetContactHandlerL()->ShowContactDetailsL(
       
  1378         *emailAddress, EContactUpdateEmail, NULL );
       
  1379 
       
  1380     CleanupStack::PopAndDestroy( emailAddress );
       
  1381     }
       
  1382 
       
  1383 // -----------------------------------------------------------------------------
       
  1384 // CFsEmailUiHtmlViewerView::LaunchRemoteLookupL
       
  1385 // -----------------------------------------------------------------------------
       
  1386 void CFsEmailUiHtmlViewerView::LaunchRemoteLookupL( const TDesC& aEmailAddress )
       
  1387     {
       
  1388     // this method assumes that remote lookup is available with current plugin.
       
  1389     HBufC* textData = aEmailAddress.AllocLC();
       
  1390     CFSMailBox* mailBox = iAppUi.GetMailClient()->GetMailBoxByUidL( iMessage->GetMailBoxId() );
       
  1391     CleanupStack::PushL( mailBox );
       
  1392     CFsDelayedLoader::InstanceL()->GetContactHandlerL()->LaunchRemoteLookupWithQueryL( *mailBox, *textData );
       
  1393     CleanupStack::PopAndDestroy( mailBox );
       
  1394     CleanupStack::PopAndDestroy( textData );
       
  1395     }
       
  1396 
       
  1397 // -----------------------------------------------------------------------------
       
  1398 // CFsEmailUiHtmlViewerView::LaunchRemoteLookupL
       
  1399 // -----------------------------------------------------------------------------
       
  1400 void CFsEmailUiHtmlViewerView::CreateMessageL( const TDesC& aEmailAddress )
       
  1401     {
       
  1402     HBufC* emailAddress = aEmailAddress.AllocLC();
       
  1403     CFSEmailUiContactHandler* cntHandlerInstance = CFsDelayedLoader::InstanceL()->GetContactHandlerL();
       
  1404     cntHandlerInstance->FindAndCreateMsgToContactByEmailL( *emailAddress, iAppUi.GetActiveMailbox() );
       
  1405     CleanupStack::PopAndDestroy( emailAddress );
       
  1406     }
       
  1407 
       
  1408 CFSMailMessage* CFsEmailUiHtmlViewerView::CurrentMessage()
       
  1409     {
       
  1410     return iMessage;
       
  1411     }
       
  1412 
       
  1413 CFSEmailUiAttachmentsListModel* CFsEmailUiHtmlViewerView::CurrentAttachmentsListModel()
       
  1414     {
       
  1415     return iAttachmentsListModel;
       
  1416     }
       
  1417 
       
  1418 void CFsEmailUiHtmlViewerView::DownloadStatusChangedL( TInt /*aIndex*/ )
       
  1419     {
       
  1420     }
       
  1421 
       
  1422 void CFsEmailUiHtmlViewerView::DownloadAttachmentL( const TAttachmentData& aAttachment )
       
  1423     {
       
  1424     iAttachmentsListModel->StartDownloadL(aAttachment);
       
  1425     }
       
  1426 
       
  1427 void CFsEmailUiHtmlViewerView::DownloadAllAttachmentsL()
       
  1428     {
       
  1429     iAttachmentsListModel->DownloadAllAttachmentsL();
       
  1430     }
       
  1431 
       
  1432 void CFsEmailUiHtmlViewerView::CancelAttachmentL( const TAttachmentData& aAttachment )
       
  1433     {
       
  1434     TInt reallyCancel = 
       
  1435         TFsEmailUiUtility::ShowConfirmationQueryL( R_FSE_VIEWER_CANCEL_DOWNLOAD_QUERY );
       
  1436     if ( reallyCancel )
       
  1437         {
       
  1438         iAttachmentsListModel->CancelDownloadL(aAttachment);
       
  1439         }
       
  1440     }
       
  1441 
       
  1442 void CFsEmailUiHtmlViewerView::OpenAttachmentL( const TAttachmentData& aAttachment )
       
  1443     {
       
  1444     if ( iAppUi.DownloadInfoMediator()->IsDownloading( aAttachment.partData.iMessagePartId ) )
       
  1445         {
       
  1446         TFsEmailUiUtility::ShowInfoNoteL( R_FSE_VIEWER_NOTE_ATTACHMENT_DOWNLOADING_PROGRESS );
       
  1447         }
       
  1448     else if ( aAttachment.downloadProgress != KComplete )
       
  1449         {
       
  1450         DownloadAttachmentL( aAttachment );
       
  1451         }
       
  1452     else
       
  1453         {
       
  1454         TFsEmailUiUtility::OpenAttachmentL( aAttachment.partData );
       
  1455         }
       
  1456     }
       
  1457 
       
  1458 void CFsEmailUiHtmlViewerView::SaveAttachmentL( const TAttachmentData& aAttachment )
       
  1459     {
       
  1460     TFileName fileName;
       
  1461     if ( TFsEmailUiUtility::ShowSaveFolderDialogL( fileName ) )
       
  1462         {
       
  1463         TInt savedCount( 0 );
       
  1464         TBool downloadRequired = iAttachmentsListModel->SaveAttachmentL( aAttachment, fileName, savedCount );
       
  1465         if ( savedCount )
       
  1466             {
       
  1467             TFsEmailUiUtility::ShowFilesSavedToFolderNoteL( savedCount );        
       
  1468             }
       
  1469         }
       
  1470     }
       
  1471 
       
  1472 void CFsEmailUiHtmlViewerView::SaveAllAttachmentsL()
       
  1473     {
       
  1474     TFileName fileName;
       
  1475     if ( TFsEmailUiUtility::ShowSaveFolderDialogL( fileName ) )
       
  1476         {
       
  1477         TBool downloadRequired = iAttachmentsListModel->SaveAllAttachmentsL( fileName );
       
  1478         }
       
  1479     }
       
  1480 
       
  1481 void CFsEmailUiHtmlViewerView::RemoveAttachmentContentL( const TAttachmentData& aAttachment )
       
  1482     {
       
  1483     FUNC_LOG;
       
  1484     TInt reallyClear = TFsEmailUiUtility::ShowConfirmationQueryL( R_FSE_VIEWER_CLEAR_FETCHED_QUERY );
       
  1485     if ( reallyClear )
       
  1486         {
       
  1487         iAttachmentsListModel->RemoveContentL( aAttachment );
       
  1488         }
       
  1489     }
       
  1490 
       
  1491 void CFsEmailUiHtmlViewerView::OpenAttachmentsListViewL()
       
  1492     {
       
  1493     HandleCommandL( EFsEmailUiCmdOpenAttachmentList );
       
  1494     }
       
  1495 
       
  1496 TBool CFsEmailUiHtmlViewerView::IsEmbeddedMsgView()
       
  1497     {
       
  1498     return iActivationData.iEmbeddedMessageMode;
       
  1499     }
       
  1500 
       
  1501 TBool CFsEmailUiHtmlViewerView::IsEmbeddedMsgSavingAllowed()
       
  1502     {
       
  1503     return iMailBox->HasCapability( 
       
  1504 				EFSMboxCapaSupportsSavingOfEmbeddedMessages );
       
  1505     }
       
  1506 
       
  1507 void CFsEmailUiHtmlViewerView::UpdateDownloadIndicatorL( 
       
  1508         const TPartData& aPart, 
       
  1509         const TFSProgress& aEvent )
       
  1510     {
       
  1511     FUNC_LOG;
       
  1512     
       
  1513     if ( iMessage )
       
  1514         {
       
  1515         if ( !iProgressBar )
       
  1516             {
       
  1517             iProgressBar = CFreestyleAttachmentDownloadProgressBar::NewL();
       
  1518             }
       
  1519         
       
  1520         for ( TInt i=0; i < iAttachmentsListModel->GetModel().Count(); i++ )
       
  1521             {
       
  1522             if ( iAttachmentsListModel->GetModel()[i].partData == aPart )
       
  1523                 {
       
  1524                 TAttachmentData& attachment = CONST_CAST( TAttachmentData&, iAttachmentsListModel->GetModel()[i] );
       
  1525                 
       
  1526                 if ( aEvent.iError )
       
  1527                     {
       
  1528                     iProgressBar->HideL();
       
  1529                     }
       
  1530                 else
       
  1531                     {
       
  1532                     switch ( aEvent.iProgressStatus )
       
  1533                         {
       
  1534                         case TFSProgress::EFSStatus_Status:
       
  1535                             {
       
  1536                             if ( aEvent.iMaxCount > 0 && aEvent.iCounter > 0 )
       
  1537                                 {
       
  1538                                 attachment.downloadProgress = KComplete * aEvent.iCounter / aEvent.iMaxCount;
       
  1539                                 }
       
  1540                             else
       
  1541                                 {
       
  1542                                 attachment.downloadProgress = KNone;
       
  1543                                 }
       
  1544                             iProgressBar->UpdateL( attachment );
       
  1545                             }
       
  1546                         break;
       
  1547                         
       
  1548                         case TFSProgress::EFSStatus_RequestComplete:
       
  1549                             {
       
  1550                             attachment.downloadProgress = KComplete;
       
  1551                             iProgressBar->UpdateL( attachment );
       
  1552                             }
       
  1553                         break;
       
  1554                         
       
  1555                         case TFSProgress::EFSStatus_RequestCancelled:
       
  1556                             {
       
  1557                             iProgressBar->HideL();
       
  1558                             }
       
  1559                         break;
       
  1560                         
       
  1561                         default:                            
       
  1562                             break;
       
  1563                         }
       
  1564                     }
       
  1565                 break;
       
  1566                 }
       
  1567             }
       
  1568         }
       
  1569     }
       
  1570 
       
  1571 void CFsEmailUiHtmlViewerView::RequestResponseL( const TFSProgress& aEvent, const TPartData& aPart )
       
  1572     {
       
  1573     FUNC_LOG;
       
  1574     if ( iAppUi.CurrentActiveView() == this )
       
  1575         {
       
  1576         if ( iMessage && ( iMessage->GetMessageId().Id() == aPart.iMessageId.Id() ) )
       
  1577             {
       
  1578             UpdateDownloadIndicatorL( aPart, aEvent );
       
  1579             }
       
  1580         }
       
  1581     }
       
  1582 
       
  1583 
       
  1584 // -----------------------------------------------------------------------------
       
  1585 // CFsEmailUiHtmlViewerView::PushMessageL
       
  1586 // Message stack handling. Ownership of message is transferred when succesful.
       
  1587 // -----------------------------------------------------------------------------
       
  1588 // 
       
  1589 void CFsEmailUiHtmlViewerView::PushMessageL( CFSMailMessage* aMessage, TBool aIsEmbedded )
       
  1590     {
       
  1591     if ( !iOpenMessages || !iEmbeddedMessages )
       
  1592         {
       
  1593         User::Leave( KErrNotReady );
       
  1594         }
       
  1595 
       
  1596     // We must ensure that push is done succesfully either to both stacks or to neither one.
       
  1597     if ( aIsEmbedded )
       
  1598         {
       
  1599         iEmbeddedMessages->PushL( aMessage );
       
  1600         }
       
  1601     else
       
  1602         {
       
  1603         iEmbeddedMessages->PushL( NULL );
       
  1604         }
       
  1605     TRAPD( err, iOpenMessages->PushL( aMessage ) );
       
  1606     if ( err )
       
  1607         {
       
  1608         iEmbeddedMessages->Pop();
       
  1609         User::Leave( err );
       
  1610         }
       
  1611     }
       
  1612 
       
  1613 // -----------------------------------------------------------------------------
       
  1614 // CFsEmailUiHtmlViewerView::PopMessage
       
  1615 // Message stack handling. Ownership of message is returned.
       
  1616 // -----------------------------------------------------------------------------
       
  1617 // 
       
  1618 CFSMailMessage* CFsEmailUiHtmlViewerView::PopMessage()
       
  1619     {
       
  1620     ASSERT( iOpenMessages && iEmbeddedMessages );
       
  1621     ASSERT( iOpenMessages->Count() == iEmbeddedMessages->Count() );
       
  1622     
       
  1623     CFSMailMessage* msg = NULL;
       
  1624     if ( !iOpenMessages->IsEmpty() )
       
  1625         {
       
  1626         msg = iOpenMessages->Pop();
       
  1627         }
       
  1628     if ( !iEmbeddedMessages->IsEmpty() )
       
  1629         {
       
  1630         iEmbeddedMessages->Pop();
       
  1631         }
       
  1632     return msg;
       
  1633     }
       
  1634 
       
  1635 // -----------------------------------------------------------------------------
       
  1636 // CFsEmailUiHtmlViewerView::EraseMessageStack
       
  1637 // Message stack handling. All messages in stack are deallocated
       
  1638 // -----------------------------------------------------------------------------
       
  1639 // 
       
  1640 void CFsEmailUiHtmlViewerView::EraseMessageStack()
       
  1641     {
       
  1642     ASSERT( iOpenMessages && iEmbeddedMessages );
       
  1643     ASSERT( iOpenMessages->Count() == iEmbeddedMessages->Count() );
       
  1644 
       
  1645     iOpenMessages->ResetAndDestroy();
       
  1646     iEmbeddedMessages->Reset();
       
  1647     }
       
  1648 
       
  1649 // -----------------------------------------------------------------------------
       
  1650 // CFsEmailUiHtmlViewerView::SetMessageFollowupFlagL
       
  1651 // -----------------------------------------------------------------------------
       
  1652 void CFsEmailUiHtmlViewerView::SetMessageFollowupFlagL()
       
  1653     {
       
  1654     FUNC_LOG;
       
  1655     if ( iMessage && TFsEmailUiUtility::IsFollowUpSupported( *iMailBox ) )
       
  1656         {
       
  1657         TFollowUpNewState newState = TFsEmailUiUtility::SetMessageFollowupFlagL( *iMessage );
       
  1658         if ( newState != EFollowUpNoChanges )
       
  1659             {
       
  1660             // Notify appui of changed mail item
       
  1661             UpdateNaviPaneL();
       
  1662             SendEventToAppUiL( TFSEventMailChanged );
       
  1663             }
       
  1664         }
       
  1665     }
       
  1666 void CFsEmailUiHtmlViewerView::SendEventToAppUiL( TFSMailEvent aEventType )
       
  1667     {
       
  1668     if ( iMessage )
       
  1669     	{
       
  1670 		RArray<TFSMailMsgId> msgIdArray;
       
  1671 		CleanupClosePushL( msgIdArray );
       
  1672 		msgIdArray.AppendL( iMessage->GetMessageId() );
       
  1673 		TFSMailMsgId folderId = iMessage->GetFolderId();
       
  1674 		iAppUi.EventL( aEventType,
       
  1675 					   iAppUi.GetActiveMailboxId(),
       
  1676 					   &msgIdArray, &folderId, NULL );
       
  1677 		CleanupStack::PopAndDestroy( &msgIdArray );
       
  1678     	}
       
  1679     }
       
  1680 // -----------------------------------------------------------------------------
       
  1681 // CFsEmailUiHtmlViewerView::ChangeMsgReadStatusL
       
  1682 // -----------------------------------------------------------------------------
       
  1683 void CFsEmailUiHtmlViewerView::ChangeMsgReadStatusL(
       
  1684     TBool aRead, TBool /*aCmdFromMrui*/ )
       
  1685     {
       
  1686     FUNC_LOG;
       
  1687     if ( iMessage && !iActivationData.iEmbeddedMessageMode )
       
  1688         {
       
  1689         if ( aRead )
       
  1690             {
       
  1691             // Send flags, local and server
       
  1692             iMessage->SetFlag( EFSMsgFlag_Read );
       
  1693             }
       
  1694         else
       
  1695             {
       
  1696             // Send flags, local and server
       
  1697             iMessage->ResetFlag( EFSMsgFlag_Read );
       
  1698             }
       
  1699         iMessage->SaveMessageL(); // Save read status
       
  1700         SendEventToAppUiL( TFSEventMailChanged );
       
  1701     
       
  1702         }
       
  1703     }
       
  1704 
       
  1705 // -----------------------------------------------------------------------------
       
  1706 // CFsEmailUiHtmlViewerView::ShowNextMessageMenuInOptions
       
  1707 // -----------------------------------------------------------------------------
       
  1708 TBool CFsEmailUiHtmlViewerView::ShowNextMessageMenuInOptions() const
       
  1709     {
       
  1710     FUNC_LOG;
       
  1711     TBool available = EFalse;
       
  1712     // Next/previous message options are inavailable in the embedded mode
       
  1713     if ( iMessage && !iActivationData.iEmbeddedMessageMode )    
       
  1714         {
       
  1715         TFSMailMsgId currentMsgId = iMessage->GetMessageId();
       
  1716         TFSMailMsgId nextMsgId;
       
  1717         TFSMailMsgId nextMsgFolderId;
       
  1718         available = iAppUi.IsNextMsgAvailable( currentMsgId, nextMsgId, nextMsgFolderId );
       
  1719         }
       
  1720     return available;
       
  1721     }
       
  1722 
       
  1723 // -----------------------------------------------------------------------------
       
  1724 // CFsEmailUiHtmlViewerView::ShowNextMessageL
       
  1725 // -----------------------------------------------------------------------------
       
  1726 void CFsEmailUiHtmlViewerView::ShowNextMessageL()
       
  1727     {
       
  1728     FUNC_LOG;
       
  1729     if ( iMessage && !iActivationData.iEmbeddedMessageMode )
       
  1730         {
       
  1731         TFSMailMsgId currentMsgId = iMessage->GetMessageId();
       
  1732         TFSMailMsgId nextMsgId;
       
  1733         TFSMailMsgId nextMsgFolderId;
       
  1734         if ( iAppUi.IsNextMsgAvailable( currentMsgId, nextMsgId, nextMsgFolderId ) )
       
  1735             {
       
  1736             // Stop timer and cancel fetchings before showing next message
       
  1737             //iFetchingAnimationTimer->Stop();
       
  1738             CancelFetchings();
       
  1739            
       
  1740             // Change empty msk when moving to next
       
  1741             ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
  1742 
       
  1743             iAppUi.MoveToNextMsgL( currentMsgId, nextMsgId );
       
  1744             // Next message is displayed in this view through doactivate, because view is re-activate by mail list
       
  1745             }
       
  1746         }
       
  1747     }
       
  1748 // -----------------------------------------------------------------------------
       
  1749 // CFsEmailUiHtmlViewerView::ShowPreviousMessageMenuInOptions
       
  1750 // -----------------------------------------------------------------------------
       
  1751 TBool CFsEmailUiHtmlViewerView::ShowPreviousMessageMenuInOptions() const
       
  1752     {
       
  1753     FUNC_LOG;
       
  1754     TBool available = EFalse;
       
  1755     // Next/previous message options are inavailable in the embedded mode
       
  1756     if ( iMessage && !iActivationData.iEmbeddedMessageMode )
       
  1757         {
       
  1758         TFSMailMsgId currentMsgId = iMessage->GetMessageId();
       
  1759         TFSMailMsgId prevMsgId;
       
  1760         TFSMailMsgId prevMsgFolderId;
       
  1761         available = iAppUi.IsPreviousMsgAvailable( currentMsgId, prevMsgId, prevMsgFolderId );
       
  1762         }
       
  1763     return available;
       
  1764     }
       
  1765 
       
  1766 // -----------------------------------------------------------------------------
       
  1767 // CFsEmailUiHtmlViewerView::ShowPreviousMessageL
       
  1768 // -----------------------------------------------------------------------------
       
  1769 void CFsEmailUiHtmlViewerView::ShowPreviousMessageL()
       
  1770     {
       
  1771     FUNC_LOG;
       
  1772     if ( iMessage && !iActivationData.iEmbeddedMessageMode )
       
  1773         {
       
  1774         TFSMailMsgId currentMsgId = iMessage->GetMessageId();
       
  1775         TFSMailMsgId prevMsgId;
       
  1776         TFSMailMsgId prevMsgFolderId;
       
  1777         if ( iAppUi.IsPreviousMsgAvailable( currentMsgId, prevMsgId, prevMsgFolderId ) )
       
  1778             {
       
  1779             // Stop timer and cancel fetchings before showing prev message
       
  1780             CancelFetchings();
       
  1781            
       
  1782             // Change empty msk when moving to previous
       
  1783             ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
  1784 
       
  1785             iAppUi.MoveToPreviousMsgL( currentMsgId, prevMsgId );
       
  1786             // Previous message is displayed in this view through doactivate, because view is re-activate by mail list
       
  1787             }
       
  1788         }
       
  1789     }
       
  1790 
       
  1791 
       
  1792 // -----------------------------------------------------------------------------
       
  1793 // CFsEmailUiHtmlViewerView::OpenFolderListForMessageMovingL
       
  1794 // -----------------------------------------------------------------------------
       
  1795 TBool CFsEmailUiHtmlViewerView::OpenFolderListForMessageMovingL()
       
  1796     {
       
  1797     FUNC_LOG;
       
  1798     TBool ret = EFalse;
       
  1799     // Ignore if mailbox doesn't support moving or we are viewing embedded message
       
  1800     if ( iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaMoveToFolder ) &&
       
  1801     !iActivationData.iEmbeddedMessageMode )
       
  1802         {
       
  1803         // Activate folder selection view and handle moving after callback gets destination
       
  1804         iMoveToFolderOngoing = ETrue;
       
  1805         TFolderListActivationData folderListData;
       
  1806         folderListData.iCallback = this;
       
  1807         CFSMailFolder* folder = iAppUi.GetMailClient()->GetFolderByUidL( iMessage->GetMailBoxId(), iMessage->GetFolderId() );
       
  1808         folderListData.iSourceFolderType = TFSFolderType( folder->GetFolderType() );
       
  1809         delete folder;
       
  1810         const TPckgBuf<TFolderListActivationData> pkgOut( folderListData );
       
  1811         iAppUi.EnterFsEmailViewL( FolderListId, KFolderListMoveMessage, pkgOut );
       
  1812         ret = ETrue;
       
  1813         }
       
  1814     return ret;
       
  1815     }
       
  1816 
       
  1817 // -----------------------------------------------------------------------------
       
  1818 // CFsEmailUiHtmlViewerView::FolderSelectedL
       
  1819 // -----------------------------------------------------------------------------
       
  1820 void CFsEmailUiHtmlViewerView::FolderSelectedL(
       
  1821     TFSMailMsgId aSelectedFolderId, TFSEmailUiCtrlBarResponse aResponse )
       
  1822     {
       
  1823     FUNC_LOG;
       
  1824 
       
  1825     if ( iMoveToFolderOngoing )
       
  1826         {
       
  1827         iMoveToFolderOngoing = EFalse;
       
  1828         if ( !iMovingMeetingRequest )
       
  1829             {
       
  1830             switch ( aResponse )
       
  1831                 {
       
  1832                 case EFSEmailUiCtrlBarResponseSelect:
       
  1833                     {
       
  1834                     iMoveDestinationFolder = aSelectedFolderId;
       
  1835                     iAsyncCallback->Cancel(); // cancel any outstanding callback just to be safe
       
  1836                     iAsyncCallback->Set( TCallBack( MoveToFolderAndExitL, this ) );
       
  1837                     iAsyncCallback->CallBack();
       
  1838                     }
       
  1839                     break;
       
  1840                 case EFSEmailUiCtrlBarResponseCancel:
       
  1841                 default:
       
  1842                     break;
       
  1843                 }
       
  1844             }
       
  1845         else
       
  1846             {
       
  1847             iMovingMeetingRequest = EFalse;
       
  1848             switch ( aResponse )
       
  1849                 {
       
  1850                 case EFSEmailUiCtrlBarResponseCancel:
       
  1851                     iOpResult.iResultCode = KErrCancel;
       
  1852                     break;
       
  1853                 case EFSEmailUiCtrlBarResponseSelect:
       
  1854                     {
       
  1855                     // Do moving here, do not exit, because mrui exists itself.
       
  1856                     iOpResult.iResultCode = KErrNone;
       
  1857                     iMoveDestinationFolder = aSelectedFolderId;
       
  1858                     RArray<TFSMailMsgId> messageIds;
       
  1859                     CleanupClosePushL( messageIds );
       
  1860                     messageIds.Append( iActivationData.iMessageId );
       
  1861                     // Trap is needed because protocol might return KErrNotSupported
       
  1862                     // if move away from current folder is not supported
       
  1863                     TRAPD(errMove, iAppUi.GetActiveMailbox()->MoveMessagesL( messageIds,
       
  1864                             iActivationData.iFolderId, iMoveDestinationFolder ));
       
  1865                     if ( errMove != KErrNotSupported )
       
  1866                         {
       
  1867                         if ( errMove == KErrNone )
       
  1868                             {
       
  1869                             TFsEmailUiUtility::DisplayMsgsMovedNoteL( 1, iMoveDestinationFolder, ETrue );
       
  1870                             }
       
  1871                         else
       
  1872                             {
       
  1873                             User::Leave( errMove );
       
  1874                             }
       
  1875                         }
       
  1876                     CleanupStack::PopAndDestroy( &messageIds );
       
  1877                     }
       
  1878                     break;
       
  1879 
       
  1880                 default:
       
  1881                     break;
       
  1882                 }
       
  1883             }
       
  1884         }
       
  1885     }
       
  1886 
       
  1887 // -----------------------------------------------------------------------------
       
  1888 // CFsEmailUiHtmlViewerView::MoveToFolderAndExitL
       
  1889 // -----------------------------------------------------------------------------
       
  1890 TInt CFsEmailUiHtmlViewerView::MoveToFolderAndExitL( TAny* aMailViewerVisualiser )
       
  1891     {
       
  1892     FUNC_LOG;
       
  1893     CFsEmailUiHtmlViewerView* self =
       
  1894         static_cast<CFsEmailUiHtmlViewerView*>(aMailViewerVisualiser);
       
  1895 
       
  1896     RArray<TFSMailMsgId> messageIds;
       
  1897     CleanupClosePushL( messageIds );
       
  1898     messageIds.Append( self->iMessage->GetMessageId() );
       
  1899 
       
  1900     // Trap is needed because protocol might return KErrNotSupported
       
  1901     // if move away from current folder is not supprted
       
  1902     TRAPD(errMove, self->iAppUi.GetActiveMailbox()->MoveMessagesL( messageIds,
       
  1903                                                      self->iMessage->GetFolderId(),
       
  1904                                                      self->iMoveDestinationFolder ) );
       
  1905     if ( errMove != KErrNotSupported )
       
  1906         {
       
  1907         if ( errMove == KErrNone )
       
  1908             {
       
  1909             // move successfull, display note
       
  1910             TFsEmailUiUtility::DisplayMsgsMovedNoteL( 1, self->iMoveDestinationFolder, ETrue );
       
  1911             }
       
  1912         else
       
  1913             {
       
  1914             // Leave with any other err code than KErrNone or KErrNotSupported.
       
  1915             User::Leave( errMove );
       
  1916             }
       
  1917         }
       
  1918     CleanupStack::PopAndDestroy( &messageIds );
       
  1919 
       
  1920     // return to previous view
       
  1921     self->HandleCommandL( EAknSoftkeyBack );
       
  1922 
       
  1923     return KErrNone;
       
  1924     }
       
  1925 
       
  1926 // -----------------------------------------------------------------------------
       
  1927 // CFsEmailUiHtmlViewerView::MessagePartFullyFetchedL
       
  1928 // -----------------------------------------------------------------------------
       
  1929 TBool CFsEmailUiHtmlViewerView::MessagePartFullyFetchedL( TFetchedType aFetchedContentType ) const
       
  1930     {
       
  1931     FUNC_LOG;
       
  1932     TBool retVal = ETrue;
       
  1933     if( aFetchedContentType == EMessagePlainTextBodyPart )
       
  1934         {
       
  1935         CFSMailMessagePart* textPart = iMessage->PlainTextBodyPartL();
       
  1936         if( textPart )
       
  1937             {
       
  1938             TFSPartFetchState currentPlainTextFetchState = textPart->FetchLoadState();
       
  1939             if( currentPlainTextFetchState != EFSFull )
       
  1940                 {
       
  1941                 retVal = EFalse;
       
  1942                 }
       
  1943             }
       
  1944         delete textPart;
       
  1945         }
       
  1946     else if( aFetchedContentType == EMessageHtmlBodyPart )
       
  1947         {
       
  1948         CFSMailMessagePart* htmlPart = iMessage->HtmlBodyPartL();
       
  1949         if( htmlPart )
       
  1950             {
       
  1951             TFSPartFetchState currentHtmlTextFetchState = htmlPart->FetchLoadState();
       
  1952             if( currentHtmlTextFetchState != EFSFull )
       
  1953                 {
       
  1954                 retVal = EFalse;
       
  1955                 }
       
  1956             }
       
  1957         delete htmlPart;
       
  1958         }
       
  1959     else if( aFetchedContentType == EMessageStructure )
       
  1960         {
       
  1961         retVal = MessageStructureKnown( *iMessage );
       
  1962         }
       
  1963     else
       
  1964         {
       
  1965         User::Leave( KErrNotSupported );
       
  1966         }
       
  1967     return retVal;
       
  1968     }
       
  1969 
       
  1970 //-----------------------------------------------------------------------------
       
  1971 // CFsEmailUiHtmlViewerView::StartFetchingMessagePartL
       
  1972 // -----------------------------------------------------------------------------
       
  1973 void CFsEmailUiHtmlViewerView::StartFetchingMessagePartL( CFSMailMessage& aMessagePtr,
       
  1974                                             TFetchedType aFetchedContentType )
       
  1975     {
       
  1976     FUNC_LOG;
       
  1977     if( aFetchedContentType == EMessagePlainTextBodyPart )
       
  1978         {
       
  1979         CFSMailMessagePart* textPart = aMessagePtr.PlainTextBodyPartL();
       
  1980         CleanupStack::PushL( textPart );
       
  1981         TFSMailMsgId textPartId = textPart->GetPartId();
       
  1982         iCurrentPlainTextBodyFetchRequestId = textPart->FetchMessagePartL( textPartId, *this, 0 );
       
  1983         iFetchingPlainTextMessageBody = ETrue;
       
  1984         CleanupStack::PopAndDestroy( textPart );
       
  1985         }
       
  1986     else if( aFetchedContentType == EMessageHtmlBodyPart )
       
  1987         {
       
  1988         CFSMailMessagePart* htmlPart = aMessagePtr.HtmlBodyPartL();
       
  1989         CleanupStack::PushL( htmlPart );
       
  1990         TFSMailMsgId htmlPartId = htmlPart->GetPartId();
       
  1991         iCurrentHtmlBodyFetchRequestId = htmlPart->FetchMessagePartL( htmlPartId, *this, 0 );
       
  1992         iFetchingHtmlMessageBody = ETrue;
       
  1993         CleanupStack::PopAndDestroy( htmlPart );
       
  1994         }
       
  1995     else if( aFetchedContentType == EMessageStructure )
       
  1996         {
       
  1997         StartFetchingMessageStructureL( aMessagePtr );
       
  1998         }
       
  1999     else
       
  2000         {
       
  2001         User::Leave( KErrNotSupported );
       
  2002         }
       
  2003     }
       
  2004 
       
  2005 // -----------------------------------------------------------------------------
       
  2006 // CFsEmailUiHtmlViewerView::RequestResponseL
       
  2007 // for MFSMailRequestObserver callback
       
  2008 // -----------------------------------------------------------------------------
       
  2009 void CFsEmailUiHtmlViewerView::RequestResponseL( TFSProgress aEvent, TInt aRequestId )
       
  2010     {
       
  2011     FUNC_LOG;
       
  2012     
       
  2013     TBool reloadContent ( EFalse );
       
  2014     
       
  2015     if ( aRequestId == iCurrentPlainTextBodyFetchRequestId && iFetchingPlainTextMessageBody )
       
  2016         {
       
  2017         if ( aEvent.iError != KErrNone ||
       
  2018              aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled )
       
  2019             {
       
  2020             iAsyncProcessComplete = ETrue;
       
  2021             iFetchingPlainTextMessageBody = EFalse;
       
  2022             //iFetchingAnimationTimer->Stop();
       
  2023 
       
  2024             // Clear the "fetching body" text from the end of the message
       
  2025             //iViewerRichText->SetEmptyStatusLayoutTextL();
       
  2026             }
       
  2027         else if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete )
       
  2028             {
       
  2029             iAsyncProcessComplete = ETrue;
       
  2030             iFetchingPlainTextMessageBody = EFalse;
       
  2031             //iFetchingAnimationTimer->Stop();
       
  2032 
       
  2033             // get message again, there might be new information (in case of POP protocol)
       
  2034             if( iMessage )
       
  2035                 {
       
  2036                 TFSMailMsgId mailboxId = iMessage->GetMailBoxId();
       
  2037                 TFSMailMsgId folderId = iMessage->GetFolderId();
       
  2038                 TFSMailMsgId messageId = iMessage->GetMessageId();
       
  2039                 UpdateMessagePtrL( mailboxId, folderId, messageId );
       
  2040                 reloadContent = ETrue;
       
  2041                 }
       
  2042                           
       
  2043             }
       
  2044         }
       
  2045 
       
  2046     else if ( aRequestId == iCurrentHtmlBodyFetchRequestId && iFetchingHtmlMessageBody )
       
  2047         {
       
  2048         if ( aEvent.iError != KErrNone ||
       
  2049              aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled )
       
  2050             {
       
  2051             iAsyncProcessComplete = ETrue;
       
  2052             iFetchingHtmlMessageBody = EFalse;
       
  2053             }
       
  2054         else if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete )
       
  2055             {
       
  2056             iAsyncProcessComplete = ETrue;
       
  2057             iFetchingHtmlMessageBody = EFalse;           
       
  2058             
       
  2059             reloadContent = ETrue;
       
  2060             
       
  2061             }
       
  2062         }
       
  2063     else if ( aRequestId == iCurrentStructureFetchRequestId && iFetchingMessageStructure )
       
  2064         {
       
  2065         if ( aEvent.iError != KErrNone ||
       
  2066              aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestCancelled )
       
  2067             {
       
  2068             iAsyncProcessComplete = ETrue;
       
  2069             iFetchingMessageStructure = EFalse;
       
  2070             }
       
  2071         else if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete )
       
  2072             {
       
  2073             iAsyncProcessComplete = ETrue;
       
  2074             iFetchingMessageStructure = EFalse;
       
  2075 
       
  2076             // get message again, there might be new information
       
  2077             if( iMessage )
       
  2078                 {
       
  2079                 TFSMailMsgId mailboxId = iMessage->GetMailBoxId();
       
  2080                 TFSMailMsgId folderId = iMessage->GetFolderId();
       
  2081                 TFSMailMsgId messageId = iMessage->GetMessageId();
       
  2082                 UpdateMessagePtrL( mailboxId, folderId, messageId );
       
  2083                 reloadContent = ETrue;
       
  2084                 }
       
  2085             }
       
  2086         }
       
  2087     
       
  2088     if ( reloadContent )
       
  2089         {
       
  2090     
       
  2091         if (  iContainer )
       
  2092             {
       
  2093             iContainer->ResetContent();
       
  2094             }
       
  2095                 
       
  2096         if( iMessage )
       
  2097             {
       
  2098             LoadContentFromMailMessageL( iMessage );  
       
  2099             SetMskL();
       
  2100             }
       
  2101         }
       
  2102             
       
  2103     
       
  2104     if(iAsyncProcessComplete && iWaitDialog && iDialogNotDismissed)
       
  2105         {
       
  2106         iWaitDialog->ProcessFinishedL(); // deletes the dialog
       
  2107         }
       
  2108 
       
  2109     }
       
  2110 
       
  2111 // -----------------------------------------------------------------------------
       
  2112 // CFsEmailUiHtmlViewerView::DialogDismissedL
       
  2113 // -----------------------------------------------------------------------------
       
  2114 void CFsEmailUiHtmlViewerView::DialogDismissedL( TInt aButtonId )
       
  2115     {
       
  2116     FUNC_LOG;
       
  2117     iDialogNotDismissed = EFalse;
       
  2118     if( aButtonId == EAknSoftkeyCancel )
       
  2119         {
       
  2120         CancelFetchings();
       
  2121         }
       
  2122 
       
  2123     }
       
  2124 
       
  2125 // -----------------------------------------------------------------------------
       
  2126 // CFsEmailUiHtmlViewerView::UpdateMessagePtrL
       
  2127 // -----------------------------------------------------------------------------
       
  2128 void CFsEmailUiHtmlViewerView::UpdateMessagePtrL( TFSMailMsgId aNewMailboxId,
       
  2129                                                         TFSMailMsgId aNewFolderId,
       
  2130                                                         TFSMailMsgId aNewMessageId )
       
  2131     {
       
  2132     FUNC_LOG;
       
  2133     TBool messageChanged = ETrue;
       
  2134 
       
  2135     if ( iMessage )
       
  2136         {
       
  2137         // Check is the message going to be changed or are we just updating the
       
  2138         // same message object which has been previously shown.
       
  2139         messageChanged = ( iMessage->GetMessageId() != aNewMessageId );
       
  2140 
       
  2141         // stop observing downloads from the previous message in case the message was changed
       
  2142         if ( iAppUi.DownloadInfoMediator() && messageChanged )
       
  2143             {
       
  2144             iAppUi.DownloadInfoMediator()->StopObserving( this, iMessage->GetMessageId() );
       
  2145             }
       
  2146         delete iMessage;
       
  2147         iMessage = NULL;
       
  2148         PopMessage();
       
  2149         }
       
  2150 
       
  2151     iMessage = iAppUi.GetMailClient()->GetMessageByUidL( aNewMailboxId,
       
  2152                                                          aNewFolderId,
       
  2153                                                          aNewMessageId,
       
  2154                                                          EFSMsgDataEnvelope  );
       
  2155     if ( iMessage )
       
  2156         {
       
  2157         // Opened to viewer -> set message as read
       
  2158         if ( !iMessage->IsFlagSet( EFSMsgFlag_Read ) )
       
  2159             {
       
  2160             iMessage->SetFlag( EFSMsgFlag_Read );
       
  2161             iMessage->SaveMessageL(); // Save read status
       
  2162             // Notify appui of changed mail item, it seems that protocols don't do this
       
  2163             SendEventToAppUiL( TFSEventMailChanged );
       
  2164             }
       
  2165         // Start observing attachment downloads from the new message
       
  2166         if ( iAppUi.DownloadInfoMediator() && messageChanged )
       
  2167             {
       
  2168             iAppUi.DownloadInfoMediator()->AddObserver( this, iMessage->GetMessageId() );
       
  2169             }
       
  2170         }
       
  2171     
       
  2172     UpdateToolbarL();
       
  2173     }
       
  2174 
       
  2175 // -----------------------------------------------------------------------------
       
  2176 // CFsEmailUiHtmlViewerView::CancelFetchings
       
  2177 // -----------------------------------------------------------------------------
       
  2178 void CFsEmailUiHtmlViewerView::CancelFetchings()
       
  2179     {
       
  2180     FUNC_LOG;
       
  2181     if( iFetchingPlainTextMessageBody )
       
  2182         {
       
  2183         TRAP_IGNORE( iAppUi.GetMailClient()->CancelL( iCurrentPlainTextBodyFetchRequestId ) );
       
  2184         iFetchingPlainTextMessageBody = EFalse;
       
  2185         }
       
  2186     if( iFetchingHtmlMessageBody )
       
  2187         {
       
  2188         TRAP_IGNORE( iAppUi.GetMailClient()->CancelL( iCurrentHtmlBodyFetchRequestId ) );
       
  2189         iFetchingHtmlMessageBody = EFalse;
       
  2190         }
       
  2191     if( iFetchingMessageStructure )
       
  2192         {
       
  2193         TRAP_IGNORE( iAppUi.GetMailClient()->CancelL( iCurrentStructureFetchRequestId ) );
       
  2194         iFetchingMessageStructure = EFalse;
       
  2195         }
       
  2196     iAsyncProcessComplete = ETrue;
       
  2197     
       
  2198     //also cancel embedded images download in DownloadInfoMediator
       
  2199     if ( iMailBox )
       
  2200         {
       
  2201         TRAP_IGNORE( iAppUi.DownloadInfoMediator()->CancelAllDownloadsL( iMailBox->GetId() ) );    
       
  2202         }
       
  2203     
       
  2204 
       
  2205     //<cmail>
       
  2206     if(iWaitDialog && iDialogNotDismissed)
       
  2207         TRAP_IGNORE(iWaitDialog->ProcessFinishedL()); // deletes the dialog
       
  2208     //</cmail>
       
  2209     }
       
  2210 // -----------------------------------------------------------------------------
       
  2211 // CFsEmailUiHtmlViewerView::StartFetchingMessageStructureL
       
  2212 // -----------------------------------------------------------------------------
       
  2213 void CFsEmailUiHtmlViewerView::StartFetchingMessageStructureL( CFSMailMessage& aMsg )
       
  2214     {
       
  2215     FUNC_LOG;
       
  2216     TFSMailMsgId currentMailboxId = aMsg.GetMailBoxId();
       
  2217     TFSMailMsgId currentMessageFolderId = aMsg.GetFolderId();
       
  2218     CFSMailFolder* currentFolder  = iAppUi.GetMailClient()->GetFolderByUidL( currentMailboxId, currentMessageFolderId );
       
  2219     CleanupStack::PushL( currentFolder );
       
  2220     RArray<TFSMailMsgId> messageIds;
       
  2221     CleanupClosePushL( messageIds );
       
  2222     messageIds.Append( aMsg.GetMessageId() );
       
  2223     iCurrentStructureFetchRequestId = currentFolder->FetchMessagesL( messageIds, EFSMsgDataStructure, *this );
       
  2224     iFetchingMessageStructure = ETrue;
       
  2225     CleanupStack::PopAndDestroy( &messageIds );
       
  2226     CleanupStack::PopAndDestroy( currentFolder );
       
  2227     }
       
  2228 
       
  2229 // -----------------------------------------------------------------------------
       
  2230 // CFsEmailUiHtmlViewerView::MessageStructureKnownL
       
  2231 // -----------------------------------------------------------------------------
       
  2232 TBool CFsEmailUiHtmlViewerView::MessageStructureKnown( CFSMailMessage& aMsg ) const
       
  2233     {
       
  2234     FUNC_LOG;
       
  2235     return TFsEmailUiUtility::IsMessageStructureKnown( aMsg );
       
  2236     }
       
  2237 
       
  2238 // -----------------------------------------------------------------------------
       
  2239 // CFsEmailUiHtmlViewerView::StartWaitedFetchingL
       
  2240 // -----------------------------------------------------------------------------
       
  2241 void CFsEmailUiHtmlViewerView::StartWaitedFetchingL( TFetchedType aFetchedContentType )
       
  2242     {
       
  2243     FUNC_LOG;
       
  2244     iAsyncProcessComplete = EFalse;
       
  2245     //iFetchingAlready = EFalse;
       
  2246     iStartAsyncFetchType = aFetchedContentType;
       
  2247     //<cmail> in cmail we are using different wait dialog, since this wrapper dialog gives
       
  2248     // problems in red key exit, when its active
       
  2249     //delete iAsyncWaitNote; iAsyncWaitNote = NULL;
       
  2250     //iAsyncWaitNote = CAknWaitNoteWrapper::NewL();
       
  2251     // surpress start delay to prevent situation where wait note gets visible
       
  2252     // only after the structure has been fetched
       
  2253     //iAsyncWaitNote->ExecuteL( R_FSE_FETCHING_WAIT_DIALOG, *this, ETrue );
       
  2254     //</cmail>
       
  2255 
       
  2256     //<cmail>
       
  2257     /*iWaitDialog = new(ELeave)CAknWaitDialog(
       
  2258                    (REINTERPRET_CAST(CEikDialog**,&iWaitDialog)), ETrue);
       
  2259     iWaitDialog->SetCallback(this);
       
  2260     iDialogNotDismissed = ETrue;
       
  2261     iWaitDialog->ExecuteLD(R_FSE_FETCHING_WAIT_DIALOG);
       
  2262     */
       
  2263         StartFetchingMessagePartL( *iMessage, iStartAsyncFetchType );
       
  2264       //  iFetchingAlready = ETrue;
       
  2265     //</cmail>
       
  2266     }
       
  2267 
       
  2268 // ---------------------------------------------------------------------------
       
  2269 // CanProcessCommand
       
  2270 // Callback from meeting request UI. Determines what functionality is provided
       
  2271 // to mrui by this UI
       
  2272 // ---------------------------------------------------------------------------
       
  2273 //
       
  2274 TBool CFsEmailUiHtmlViewerView::CanProcessCommand(
       
  2275     TESMRIcalViewerOperationType aCommandId  ) const
       
  2276     {
       
  2277     FUNC_LOG;
       
  2278     TBool ret( EFalse );
       
  2279     TInt numRecipients(0);
       
  2280     switch ( aCommandId )
       
  2281         {
       
  2282         case EESMRCmdMailReply:
       
  2283             ret = ETrue;
       
  2284             break;
       
  2285         case EESMRCmdMailReplyAll:
       
  2286             //Get # of recipients
       
  2287             if ( iMessage )
       
  2288                 {
       
  2289                 numRecipients=TFsEmailUiUtility::CountRecepients( iMessage );
       
  2290                 if ( numRecipients == 1 )
       
  2291                     {
       
  2292                     //check if the malbox ownmailaddress is same as the recipients email address. If not, then assume that the
       
  2293                     //email is a distribution list and we need to inc num of Recipients so that "Reply ALL" option appears in UI.
       
  2294                     if ( iMessage->GetToRecipients().Count() )
       
  2295                         {
       
  2296                         if ( iMailBox->OwnMailAddress().GetEmailAddress().Compare(iMessage->GetToRecipients()[0]->GetEmailAddress()) )
       
  2297                             {
       
  2298                             numRecipients++;
       
  2299                             }
       
  2300                         }
       
  2301                     if ( iMessage->GetCCRecipients().Count() )
       
  2302                         {
       
  2303                         if ( iMailBox->OwnMailAddress().GetEmailAddress().Compare(iMessage->GetCCRecipients()[0]->GetEmailAddress()) )
       
  2304                             {
       
  2305                             numRecipients++;
       
  2306                             }
       
  2307                         }
       
  2308                     if ( iMessage->GetBCCRecipients().Count() )
       
  2309                         {
       
  2310                         if ( iMailBox->OwnMailAddress().GetEmailAddress().Compare(iMessage->GetBCCRecipients()[0]->GetEmailAddress()) )
       
  2311                             {
       
  2312                             numRecipients++;
       
  2313                             }
       
  2314                         }
       
  2315                     }
       
  2316                 }
       
  2317             ret = ( iMessage && numRecipients > 1 );
       
  2318             break;
       
  2319         case EESMRCmdDownloadManager:
       
  2320             //ret = ShowDownloadManagerMenuInOptions();
       
  2321             break;
       
  2322 // <cmail>
       
  2323         case EESMRCmdOpenAttachment:
       
  2324         case EESMRCmdSaveAttachment:
       
  2325         case EESMRCmdSaveAllAttachments:
       
  2326         case EESMRCmdDownloadAttachment:
       
  2327         case EESMRCmdDownloadAllAttachments:
       
  2328 // </cmail>
       
  2329         case EESMRCmdOpenAttachmentView:
       
  2330             ret = ETrue;
       
  2331             break;
       
  2332         case EESMRCmdMailComposeMessage:
       
  2333             ret = ETrue;
       
  2334             break;
       
  2335         case EESMRCmdMailMarkUnread:
       
  2336             {
       
  2337             ret = EFalse;
       
  2338             if ( iMessage && iMessage->IsFlagSet(EFSMsgFlag_Read) )
       
  2339                 {
       
  2340                 // Read, unread should be available
       
  2341                 ret = ETrue;
       
  2342                 }
       
  2343             }
       
  2344             break;
       
  2345         case EESMRCmdMailMarkRead:
       
  2346             {
       
  2347             ret = EFalse;
       
  2348             if ( iMessage && !iMessage->IsFlagSet(EFSMsgFlag_Read) )
       
  2349                 {
       
  2350                 // Read, unread should be available
       
  2351                 ret = ETrue;
       
  2352                 }
       
  2353             }
       
  2354             break;
       
  2355         case EESMRCmdMailMoveMessage:
       
  2356             {
       
  2357             ret = EFalse;
       
  2358             if ( iMessage )
       
  2359                 {
       
  2360                 // confirmed pointer exists, check whether mb has capa
       
  2361                 ret = iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaMoveToFolder );
       
  2362                 }
       
  2363             }
       
  2364             break;
       
  2365         case EESMRCmdMailForwardAsMessage:
       
  2366             ret = ETrue;
       
  2367             break;
       
  2368         case EESMRCmdMailFlagMessage:
       
  2369             ret = TFsEmailUiUtility::IsFollowUpSupported( *iMailBox );
       
  2370             break;
       
  2371         case EESMRCmdMailMessageDetails:
       
  2372             ret = ETrue;
       
  2373             break;
       
  2374         case EESMRCmdMailDelete:
       
  2375             ret = ETrue;
       
  2376             break;
       
  2377         case EESMRCmdMailPreviousMessage:
       
  2378             ret = ShowPreviousMessageMenuInOptions();
       
  2379             break;
       
  2380         case EESMRCmdMailNextMessage:
       
  2381             ret = ShowNextMessageMenuInOptions();
       
  2382             break;
       
  2383         default:
       
  2384             ret = EFalse;
       
  2385             break;
       
  2386         }
       
  2387     return ret;
       
  2388     }
       
  2389 
       
  2390     
       
  2391 void CFsEmailUiHtmlViewerView::ProcessAsyncCommandL( TESMRIcalViewerOperationType aCommandId,
       
  2392                                                      const CFSMailMessage& aMessage,
       
  2393                                                      MESMRIcalViewerObserver* aObserver )
       
  2394 {
       
  2395 FUNC_LOG;
       
  2396 if ( aObserver )
       
  2397     {
       
  2398     iMrObserverToInform = aObserver;
       
  2399     }
       
  2400 // we must cast constness away from message because of flaws in MRUI API
       
  2401 CFSMailMessage* messagePtr = const_cast<CFSMailMessage*>(&aMessage);
       
  2402 if ( messagePtr )
       
  2403     {
       
  2404     // Fill in result struct
       
  2405     iOpResult.iOpType = aCommandId;
       
  2406     iOpResult.iMessage = messagePtr;
       
  2407     iOpResult.iResultCode = KErrNotFound;
       
  2408 
       
  2409     switch ( aCommandId )
       
  2410         {
       
  2411         case EESMRCmdMailMessageDetails:
       
  2412             {
       
  2413             iOpResult.iResultCode = KErrNone;
       
  2414             TMsgDetailsActivationData msgDetailsData;
       
  2415             msgDetailsData.iMailBoxId = messagePtr->GetMailBoxId();
       
  2416             msgDetailsData.iFolderId = messagePtr->GetFolderId();
       
  2417             msgDetailsData.iMessageId = messagePtr->GetMessageId();
       
  2418             const TPckgBuf<TMsgDetailsActivationData> pkgOut( msgDetailsData );
       
  2419             iAppUi.EnterFsEmailViewL( MsgDetailsViewId, KStartMsgDetailsToBeginning,  pkgOut);
       
  2420             }
       
  2421             break;
       
  2422         case EESMRCmdMailDelete:
       
  2423             {
       
  2424             if ( iMessage )
       
  2425                 {
       
  2426                 iDeletedMessageFromMrui = iMessage->GetMessageId(); //<cmail>
       
  2427                 DeleteMailL();
       
  2428                 iOpResult.iResultCode = KErrNone; //???? what to pass here
       
  2429                 }
       
  2430 
       
  2431             // Information is returned immediately after delete has completed.
       
  2432             CompletePendingMrCommand();
       
  2433             }
       
  2434             break;
       
  2435         case EESMRCmdMailMoveMessage:
       
  2436             {
       
  2437             if ( iMessage )
       
  2438                 {
       
  2439                 if ( OpenFolderListForMessageMovingL() )
       
  2440                     {
       
  2441                     iOpResult.iResultCode = KErrNone;
       
  2442                     iMovingMeetingRequest = ETrue;
       
  2443                     }
       
  2444                 }
       
  2445             }
       
  2446             break;
       
  2447 // <cmail>
       
  2448         case EESMRCmdOpenAttachment:
       
  2449             {
       
  2450             // Check that message has attachments to display
       
  2451             if ( messagePtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2452                 {
       
  2453                 iOpResult.iResultCode = KErrNone;
       
  2454                 //OpenAttachmentL();
       
  2455                 CompletePendingMrCommand();
       
  2456                 }
       
  2457             }
       
  2458             break;
       
  2459         case EESMRCmdDownloadAttachment:
       
  2460         case EESMRCmdDownloadAllAttachments:
       
  2461             {
       
  2462             // Check that message has attachments to display
       
  2463             if ( messagePtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2464                 {
       
  2465                 iOpResult.iResultCode = KErrNone;
       
  2466                 //StartDowloadingAttachmentsL();
       
  2467                 CompletePendingMrCommand();
       
  2468                 }
       
  2469             }
       
  2470             break;
       
  2471         case EESMRCmdSaveAttachment:
       
  2472         case EESMRCmdSaveAllAttachments:
       
  2473             {
       
  2474             // Check that message has attachments to display
       
  2475             if ( messagePtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2476                 {
       
  2477                 iOpResult.iResultCode = KErrNone;
       
  2478                 SaveAllAttachmentsL();
       
  2479                 CompletePendingMrCommand();
       
  2480                 }
       
  2481             }
       
  2482             break;
       
  2483 // </cmail>
       
  2484         case EESMRCmdOpenAttachmentView:
       
  2485             {
       
  2486             // Check that message has attachments to display
       
  2487             if ( messagePtr->IsFlagSet( EFSMsgFlag_Attachments ) )
       
  2488                 {
       
  2489                 iOpResult.iResultCode = KErrNone;
       
  2490                 TAttachmentListActivationData params;
       
  2491                 params.iMailBoxId = messagePtr->GetMailBoxId();
       
  2492                 params.iFolderId = messagePtr->GetFolderId();
       
  2493                 params.iMessageId = messagePtr->GetMessageId();
       
  2494                 TPckgBuf<TAttachmentListActivationData> buf( params );
       
  2495                 TUid emptyCustomMessageId = { 0 };
       
  2496                 iAppUi.EnterFsEmailViewL( AttachmentMngrViewId, emptyCustomMessageId, buf );
       
  2497 // <cmail>
       
  2498                 CompletePendingMrCommand();
       
  2499 // </cmail>
       
  2500                 }
       
  2501             }
       
  2502             break;
       
  2503         case EESMRCmdDownloadManager:
       
  2504             {
       
  2505             // Check that there is something in dwnld manager to show
       
  2506             //if ( ShowDownloadManagerMenuInOptions() )
       
  2507               //  {
       
  2508               //  iOpResult.iResultCode = KErrNone;
       
  2509                // iAppUi.EnterFsEmailViewL( DownloadManagerViewId );
       
  2510                 //}
       
  2511             }
       
  2512             break;
       
  2513         case EESMRCmdMailComposeMessage:
       
  2514             {           
       
  2515             iAppUi.CreateNewMailL();
       
  2516             iOpResult.iResultCode = KErrNone;
       
  2517             }
       
  2518             break;
       
  2519         case EESMRCmdMailReply:
       
  2520         case EESMRCmdMailReplyAll:
       
  2521         case EESMRCmdMailForwardAsMessage:
       
  2522             {
       
  2523             // Fill result codes for mrui
       
  2524             iOpResult.iResultCode = KErrNone;
       
  2525             // Fill launc params
       
  2526             TEditorLaunchParams params;
       
  2527             params.iMailboxId = iAppUi.GetActiveMailboxId();
       
  2528             params.iActivatedExternally = EFalse;
       
  2529             params.iMsgId = messagePtr->GetMessageId();
       
  2530             if ( aCommandId == EESMRCmdMailForwardAsMessage )
       
  2531                 {
       
  2532                 iAppUi.LaunchEditorL( KEditorCmdForward, params );
       
  2533                 }
       
  2534             else if ( aCommandId == EESMRCmdMailReply )
       
  2535                 {
       
  2536                 iAppUi.LaunchEditorL( KEditorCmdReply, params );
       
  2537                 }
       
  2538             else if ( aCommandId == EESMRCmdMailReplyAll )
       
  2539                 {
       
  2540                 iAppUi.LaunchEditorL( KEditorCmdReplyAll, params );
       
  2541                 }
       
  2542             }
       
  2543             break;
       
  2544         case EESMRCmdMailPreviousMessage:
       
  2545             {
       
  2546             iNextOrPrevMessageSelected = ETrue; // prevent back navigation when operation completed received
       
  2547             ShowPreviousMessageL();
       
  2548             iOpResult.iResultCode = KErrNone;
       
  2549             CompletePendingMrCommand();
       
  2550             }
       
  2551             break;
       
  2552         case EESMRCmdMailNextMessage:
       
  2553             {
       
  2554             iNextOrPrevMessageSelected = ETrue; // prevent back navigation when operation completed received
       
  2555             ShowNextMessageL();
       
  2556             iOpResult.iResultCode = KErrNone;
       
  2557             CompletePendingMrCommand();
       
  2558             }
       
  2559             break;
       
  2560         default:
       
  2561             break;
       
  2562         }
       
  2563     }
       
  2564 
       
  2565     // Complete immediately if handling command failed. It makes no harm if following
       
  2566     // function gets called several times in some case.
       
  2567     if ( iOpResult.iResultCode < 0 )
       
  2568         {
       
  2569         CompletePendingMrCommand();
       
  2570         }
       
  2571     }
       
  2572 void CFsEmailUiHtmlViewerView::ProcessSyncCommandL(
       
  2573     TESMRIcalViewerOperationType aCommandId,
       
  2574     const CFSMailMessage& aMessage )
       
  2575     {
       
  2576     FUNC_LOG;
       
  2577     if ( &aMessage )
       
  2578         {
       
  2579         switch ( aCommandId )
       
  2580             {
       
  2581             case EESMRCmdMailMarkUnread:
       
  2582                 {
       
  2583                 ChangeMsgReadStatusL( EFalse, ETrue );
       
  2584                 }
       
  2585                 break;
       
  2586             case EESMRCmdMailMarkRead:
       
  2587                 {
       
  2588                 ChangeMsgReadStatusL( ETrue, ETrue );
       
  2589                 }
       
  2590                 break;
       
  2591             case EESMRCmdMailFlagMessage:
       
  2592                 {
       
  2593                 if ( iMessage )
       
  2594                     {
       
  2595                     if ( !iFlagSelectionHandler )
       
  2596                         {
       
  2597                         // Create when used for the first time
       
  2598                         iFlagSelectionHandler =
       
  2599                         CFlagSelectionNoteHandler::NewL( *this );
       
  2600                         }
       
  2601                     // Call to LaunchFlagListQueryDialogL will lead
       
  2602                     // to CFlagSelectionNoteHandler::RunL() for handling the
       
  2603                     // user's selection.
       
  2604                     iFlagSelectionHandler->LaunchFlagListQueryDialogL();
       
  2605                     }
       
  2606                 }
       
  2607                 break;
       
  2608             default:
       
  2609                 break;
       
  2610             }
       
  2611         }
       
  2612     }
       
  2613 
       
  2614 // -----------------------------------------------------------------------------
       
  2615 // CFsEmailUiHtmlViewerView::OperationCompleted()
       
  2616 // From MRUI observer
       
  2617 // -----------------------------------------------------------------------------
       
  2618 //
       
  2619 void CFsEmailUiHtmlViewerView::OperationCompleted( TIcalViewerOperationResult aResult )
       
  2620     {
       
  2621     FUNC_LOG;
       
  2622     if ( aResult.iOpType == EESMRViewLaunch )
       
  2623         {
       
  2624         iMrUiActive = EFalse;
       
  2625         if ( !iNextOrPrevMessageSelected && iAppUi.CurrentActiveView() == this )
       
  2626             {
       
  2627             TRAP_IGNORE( NavigateBackL() );
       
  2628             }
       
  2629         if ( aResult.iAttendeeStatus == EESMRAttendeeStatusAccept ||
       
  2630              aResult.iAttendeeStatus == EESMRAttendeeStatusTentative )
       
  2631             {
       
  2632             TInt noteTextId = R_FREESTYLE_EMAIL_CONFIRM_NOTE_MEETING_ON_CALENDAR_AFTER_SYNC;
       
  2633             TRAP_IGNORE( TFsEmailUiUtility::ShowGlobalInfoNoteL( noteTextId ) );
       
  2634             }
       
  2635         }
       
  2636     }
       
  2637 
       
  2638 // -----------------------------------------------------------------------------
       
  2639 // CFsEmailUiHtmlViewerView::OperationError()
       
  2640 // -----------------------------------------------------------------------------
       
  2641 //
       
  2642 void CFsEmailUiHtmlViewerView::OperationError( TIcalViewerOperationResult aResult )
       
  2643     {
       
  2644     FUNC_LOG;
       
  2645     // Show message in standard mail viewer in case launchin MRUI fails for any
       
  2646     // other reason than viewer being cancelled by calling CancelPendingMrCommand().
       
  2647     if ( aResult.iOpType == EESMRViewLaunch )
       
  2648         {
       
  2649         iMrUiActive = EFalse;
       
  2650         
       
  2651         // load mr content to viewer so we don't end up with empty view
       
  2652         if (  iContainer )
       
  2653              {
       
  2654              iContainer->ResetContent();
       
  2655              }
       
  2656                  
       
  2657          if( iMessage )
       
  2658              {
       
  2659              TRAP_IGNORE( LoadContentFromMailMessageL( iMessage ) );  
       
  2660              TRAP_IGNORE( SetMskL() );
       
  2661              }
       
  2662         }
       
  2663     }
       
  2664 
       
  2665 // -----------------------------------------------------------------------------
       
  2666 // CFsEmailUiHtmlViewerView::CompletePendingMrCommand()
       
  2667 // -----------------------------------------------------------------------------
       
  2668 //
       
  2669 void CFsEmailUiHtmlViewerView::CompletePendingMrCommand()
       
  2670     {
       
  2671     FUNC_LOG;
       
  2672     if ( iMrObserverToInform )
       
  2673         {
       
  2674         iMrObserverToInform->OperationCompleted( iOpResult );
       
  2675         }
       
  2676     iMrObserverToInform = NULL;
       
  2677     }
       
  2678 
       
  2679 // -----------------------------------------------------------------------------
       
  2680 // CFsEmailUiHtmlViewerView::CancelPendingMrCommandL()
       
  2681 // -----------------------------------------------------------------------------
       
  2682 //
       
  2683 void CFsEmailUiHtmlViewerView::CancelPendingMrCommandL()
       
  2684     {
       
  2685     FUNC_LOG;
       
  2686     // Be sure not to call cancel if the MRUI is not active. This is because
       
  2687     // calling cancel after closing a newly fetched MR causes the MRUI to
       
  2688     // be reopened.
       
  2689     if ( iMrUiActive && iAppUi.MrViewerInstanceL() )
       
  2690         {
       
  2691         iAppUi.MrViewerInstanceL()->CancelOperation();
       
  2692         }
       
  2693     iMrUiActive = EFalse;
       
  2694     iMrObserverToInform = NULL;
       
  2695     }
       
  2696     
       
  2697 // -----------------------------------------------------------------------------
       
  2698 // CFsEmailUiHtmlViewerView::ClearMailViewer
       
  2699 // -----------------------------------------------------------------------------
       
  2700 void CFsEmailUiHtmlViewerView::ClearMailViewer()
       
  2701     {
       
  2702     FUNC_LOG;
       
  2703     if ( iContainer )
       
  2704         {
       
  2705         iContainer->ResetContent();
       
  2706         }
       
  2707     }
       
  2708 
       
  2709 // Helper funcitons to get viewed message ID and Folder id
       
  2710 TFSMailMsgId CFsEmailUiHtmlViewerView::ViewedMessageFolderId()
       
  2711     {
       
  2712     FUNC_LOG;
       
  2713     TFSMailMsgId ret;
       
  2714     if ( iMessage )
       
  2715         {
       
  2716         ret = iMessage->GetFolderId();
       
  2717         }
       
  2718     return ret;
       
  2719     }
       
  2720 
       
  2721 TFSMailMsgId CFsEmailUiHtmlViewerView::ViewedMessageId()
       
  2722     {
       
  2723     FUNC_LOG;
       
  2724     TFSMailMsgId ret;
       
  2725     if ( iMessage )
       
  2726         {
       
  2727         ret = iMessage->GetMessageId();
       
  2728         }
       
  2729     return ret;
       
  2730     }
       
  2731 
       
  2732 void CFsEmailUiHtmlViewerView::PrepareForExit()
       
  2733     {
       
  2734     FUNC_LOG;
       
  2735     delete iNewMailTempAddress;
       
  2736     iNewMailTempAddress = NULL;
       
  2737 
       
  2738     if ( iFlagSelectionHandler )
       
  2739         {
       
  2740         iFlagSelectionHandler->Cancel();
       
  2741         delete iFlagSelectionHandler;
       
  2742         iFlagSelectionHandler = NULL;
       
  2743         }
       
  2744     if ( iAppUi.DownloadInfoMediator() && iMessage )
       
  2745         {
       
  2746         iAppUi.DownloadInfoMediator()->StopObserving( this, iMessage->GetMessageId() );
       
  2747         }
       
  2748     delete iOpenMessages;
       
  2749     iOpenMessages = NULL;
       
  2750     delete iEmbeddedMessages;
       
  2751     iEmbeddedMessages = NULL;
       
  2752     iMessage = NULL;
       
  2753     CancelFetchings();
       
  2754    
       
  2755     delete iMailBox;
       
  2756     iMailBox = NULL;
       
  2757     }
       
  2758 
       
  2759 TBool CFsEmailUiHtmlViewerView::GetAsyncFetchStatus()
       
  2760     {
       
  2761     return ( iFetchingHtmlMessageBody || iFetchingMessageStructure || iFetchingPlainTextMessageBody );
       
  2762     }
       
  2763     
       
  2764 // ---------------------------------------------------------------------------
       
  2765 // CFsEmailUiHtmlViewerView::UpdateNaviPaneL
       
  2766 // ---------------------------------------------------------------------------
       
  2767 //
       
  2768 void CFsEmailUiHtmlViewerView::UpdateNaviPaneL( TBool aForESMR )
       
  2769     {
       
  2770     FUNC_LOG;
       
  2771     // Get navigation decorator for mail viewer
       
  2772     CAknNavigationDecorator* naviDecorator = iAppUi.NaviDecoratorL( MailViewerId );
       
  2773     if ( naviDecorator )
       
  2774         {
       
  2775         // Check if there's next and previous message available, and set
       
  2776         // the navipane arrows accordingly
       
  2777         TFSMailMsgId currentMsgId = iMessage->GetMessageId();
       
  2778         TFSMailMsgId tmpMsgId;
       
  2779         TFSMailMsgId tmpMsgFolderId;
       
  2780         if ( iAppUi.IsNextMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId ) )
       
  2781             {
       
  2782             naviDecorator->SetScrollButtonDimmed( CAknNavigationDecorator::ERightButton, EFalse );
       
  2783             }
       
  2784         else
       
  2785             {
       
  2786             naviDecorator->SetScrollButtonDimmed( CAknNavigationDecorator::ERightButton, ETrue );
       
  2787             }
       
  2788         if ( iAppUi.IsPreviousMsgAvailable( currentMsgId, tmpMsgId, tmpMsgFolderId ) )
       
  2789             {
       
  2790             naviDecorator->SetScrollButtonDimmed( CAknNavigationDecorator::ELeftButton, EFalse );
       
  2791             }
       
  2792         else
       
  2793             {
       
  2794             naviDecorator->SetScrollButtonDimmed( CAknNavigationDecorator::ELeftButton, ETrue );
       
  2795             }
       
  2796 
       
  2797         // Set this view's navipane to the top of the navipane control stack
       
  2798         CAknNavigationControlContainer* naviPaneContainer =
       
  2799             static_cast<CAknNavigationControlContainer*>(
       
  2800             StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
  2801         naviPaneContainer->PushL( *naviDecorator );
       
  2802         naviDecorator->SetNaviDecoratorObserver( aForESMR ? NULL : this );
       
  2803         }
       
  2804 
       
  2805     // Set priority and follow-up flags
       
  2806     CCustomStatuspaneIndicators* indicators = iAppUi.GetStatusPaneIndicatorContainer();
       
  2807     if ( indicators)
       
  2808         {
       
  2809         indicators->ShowStatusPaneIndicators();
       
  2810 
       
  2811         if ( iMessage->IsFlagSet( EFSMsgFlag_Low ) )
       
  2812             {
       
  2813             indicators->SetPriorityFlag( EMsgPriorityLow );
       
  2814             }
       
  2815         else if ( iMessage->IsFlagSet( EFSMsgFlag_Important ) )
       
  2816             {
       
  2817             indicators->SetPriorityFlag( EMsgPriorityHigh );
       
  2818             }
       
  2819         else
       
  2820             {
       
  2821             indicators->SetPriorityFlag( EMsgPriorityNormal );
       
  2822             }
       
  2823 
       
  2824         CCustomStatuspaneIndicators::TFollowUpFlagType flagType = CCustomStatuspaneIndicators::EFollowUpNone;
       
  2825         if (iMessage->IsFlagSet(EFSMsgFlag_FollowUp))
       
  2826             {
       
  2827             flagType = CCustomStatuspaneIndicators::EFollowUp;
       
  2828             }
       
  2829         if (iMessage->IsFlagSet(EFSMsgFlag_FollowUpComplete))
       
  2830             {
       
  2831             flagType = CCustomStatuspaneIndicators::EFollowUpComplete;
       
  2832             }
       
  2833         indicators->SetFollowUpFlag( flagType );
       
  2834         }
       
  2835 
       
  2836     }
       
  2837 
       
  2838 // ---------------------------------------------------------------------------
       
  2839 // CFsEmailUiHtmlViewerView::HandleNaviDecoratorEventL
       
  2840 // ---------------------------------------------------------------------------
       
  2841 //
       
  2842 void CFsEmailUiHtmlViewerView::HandleNaviDecoratorEventL( TInt aEventID )
       
  2843     {
       
  2844     FUNC_LOG;
       
  2845     CAknNavigationDecorator* naviDecorator = iAppUi.NaviDecoratorL( MailViewerId );
       
  2846     if ( naviDecorator )
       
  2847         {
       
  2848         naviDecorator->SetNaviDecoratorObserver( NULL );
       
  2849         }
       
  2850     if( aEventID == MAknNaviDecoratorObserver::EAknNaviDecoratorEventRightTabArrow )
       
  2851         {
       
  2852         ShowNextMessageL();
       
  2853         }
       
  2854     else
       
  2855         {
       
  2856         ShowPreviousMessageL();
       
  2857         }
       
  2858     }
       
  2859 
       
  2860 // -----------------------------------------------------------------------------
       
  2861 // CFsEmailUiHtmlViewerView::HideNaviPane
       
  2862 // -----------------------------------------------------------------------------
       
  2863 void CFsEmailUiHtmlViewerView::HideNaviPane()
       
  2864     {
       
  2865     FUNC_LOG;
       
  2866     CAknNavigationControlContainer* naviPaneContainer = NULL;
       
  2867     TRAP_IGNORE( naviPaneContainer = static_cast<CAknNavigationControlContainer*>(StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) ) );
       
  2868     TRAP_IGNORE( naviPaneContainer->PushDefaultL() );
       
  2869 
       
  2870     CCustomStatuspaneIndicators* indicators = iAppUi.GetStatusPaneIndicatorContainer();
       
  2871     if ( indicators)
       
  2872         {
       
  2873         indicators->HideStatusPaneIndicators();
       
  2874         }
       
  2875     }
       
  2876 
       
  2877 // -----------------------------------------------------------------------------
       
  2878 // CFsEmailUiHtmlViewerView::IsOpenedInMRViewerL
       
  2879 // ---------------------------------------------------------------------------
       
  2880 //
       
  2881 TBool CFsEmailUiHtmlViewerView::IsOpenedInMRViewerL()
       
  2882     {
       
  2883     FUNC_LOG;
       
  2884     TBool retVal( EFalse );
       
  2885     CFSMailMessage* msg = iAppUi.GetMailClient()->GetMessageByUidL( 
       
  2886             iActivationData.iMailBoxId, iActivationData.iFolderId,
       
  2887             iActivationData.iMessageId, EFSMsgDataEnvelope );
       
  2888             
       
  2889     if ( msg )
       
  2890         {
       
  2891         CleanupStack::PushL( msg );
       
  2892         if ( msg->IsFlagSet( EFSMsgFlag_CalendarMsg ) && 
       
  2893             iAppUi.MrViewerInstanceL() )
       
  2894             {
       
  2895             TESMRMeetingRequestMethod mrMethod( EESMRMeetingRequestMethodUnknown );
       
  2896             mrMethod = iAppUi.MrViewerInstanceL()->ResolveMeetingRequestMethodL( *msg );
       
  2897             // Opened in MR viewer if request/cancellation or unknown MR
       
  2898             retVal = 
       
  2899                 mrMethod == EESMRMeetingRequestMethodRequest ||
       
  2900                 mrMethod == EESMRMeetingRequestMethodCancellation ||
       
  2901                 mrMethod == EESMRMeetingRequestMethodUnknown;
       
  2902             }
       
  2903         CleanupStack::PopAndDestroy( msg );
       
  2904         }
       
  2905     return retVal;
       
  2906     }
       
  2907 
       
  2908 
       
  2909 //////////////////////////////////////////////////////////////////////////////////////
       
  2910 // CLASS IMPLEMENTATION CHANGE TO FLAG DIALOG GLOBAL NOTE
       
  2911 ///////////////////////////////////////////////////////////////////////////////////
       
  2912 CFlagSelectionNoteHandler* CFlagSelectionNoteHandler::NewL( CFsEmailUiHtmlViewerView& aViewerVisualiser )
       
  2913     {
       
  2914     FUNC_LOG;
       
  2915     CFlagSelectionNoteHandler* self =
       
  2916          new (ELeave) CFlagSelectionNoteHandler( aViewerVisualiser );
       
  2917     return self;
       
  2918     }
       
  2919 
       
  2920 
       
  2921 CFlagSelectionNoteHandler::~CFlagSelectionNoteHandler()
       
  2922     {
       
  2923     FUNC_LOG;
       
  2924     delete iPrompt;
       
  2925     delete iGlobalFlagQuery;
       
  2926     }
       
  2927 
       
  2928 void CFlagSelectionNoteHandler::Cancel()
       
  2929     {
       
  2930     FUNC_LOG;
       
  2931     }
       
  2932 
       
  2933 void CFlagSelectionNoteHandler::LaunchFlagListQueryDialogL()
       
  2934     {
       
  2935     FUNC_LOG;
       
  2936     iSelection = 0;
       
  2937     if ( !iPrompt )
       
  2938         {
       
  2939         iPrompt = StringLoader::LoadL( R_FREESTYLE_EMAIL_UI_VIEWER_FLAG_DIALOG_HEADER );
       
  2940         }
       
  2941     if ( !iGlobalFlagQuery )
       
  2942         {
       
  2943         iGlobalFlagQuery = CAknGlobalListQuery::NewL();
       
  2944         iGlobalFlagQuery->SetHeadingL( *iPrompt ); // Set query heading.
       
  2945         }
       
  2946 
       
  2947     CDesCArrayFlat* array = new (ELeave) CDesCArrayFlat( 3 );
       
  2948     CleanupStack::PushL( array );
       
  2949     // Add follow up text
       
  2950     HBufC* followUp = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FLAG_FOLLOW_UP );
       
  2951     array->AppendL( *followUp );
       
  2952     CleanupStack::PopAndDestroy( followUp );
       
  2953 
       
  2954     // Add flag complete text
       
  2955     HBufC* completeFlag = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FLAG_COMPLETE );
       
  2956     array->AppendL( *completeFlag );
       
  2957     CleanupStack::PopAndDestroy( completeFlag );
       
  2958 
       
  2959     // Add clear flag text
       
  2960     HBufC* clearFlag = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_FLAG_CLEAR );
       
  2961     array->AppendL( *clearFlag );
       
  2962     CleanupStack::PopAndDestroy( clearFlag );
       
  2963 
       
  2964     // Show query
       
  2965     iGlobalFlagQuery->ShowListQueryL( array, iStatus, iSelection );
       
  2966     CleanupStack::PopAndDestroy( array );
       
  2967 
       
  2968     // Set active
       
  2969     SetActive();
       
  2970     }
       
  2971 
       
  2972 void CFlagSelectionNoteHandler::RunL()
       
  2973     {
       
  2974     FUNC_LOG;
       
  2975     // Convert the selected index to enumeration.
       
  2976     TFollowUpNewState newState = static_cast<TFollowUpNewState>( iStatus.Int() );
       
  2977     // Update the message based on the new state.
       
  2978     CFSMailMessage* message = iViewerView.CurrentMessage();
       
  2979     if ( message )
       
  2980         {
       
  2981         TFsEmailUiUtility::SetMessageFollowupStateL( *message, newState );
       
  2982         }
       
  2983     }
       
  2984 
       
  2985 void CFlagSelectionNoteHandler::DoCancel()
       
  2986     {
       
  2987     FUNC_LOG;
       
  2988     }
       
  2989 
       
  2990 TInt CFlagSelectionNoteHandler::RunError( TInt /*aError*/ )
       
  2991     {
       
  2992     FUNC_LOG;
       
  2993     TInt err( KErrNone );
       
  2994     return err;
       
  2995     }
       
  2996 
       
  2997 CFlagSelectionNoteHandler::CFlagSelectionNoteHandler(  CFsEmailUiHtmlViewerView& aViewerVisualiser )
       
  2998     : CActive ( EPriorityHigh ),
       
  2999     iViewerView( aViewerVisualiser )
       
  3000     {
       
  3001     FUNC_LOG;
       
  3002     CActiveScheduler::Add( this );
       
  3003     iSelection = 0;
       
  3004     }