emailuis/emailui/src/ncscomposeview.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 : Compose view class
       
    15 *
       
    16 */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include "emailtrace.h"
       
    20 #include <aknnotewrappers.h>
       
    21 #include <NpdApi.h>
       
    22 #include <StringLoader.h>
       
    23 #include <txtrich.h>
       
    24 #include <AknWaitDialog.h> //<cmail>
       
    25 #include <MsgAttachmentUtils.h>//<cmail>
       
    26 //<cmail>
       
    27 #include <featmgr.h>
       
    28 #include "CFSMailBox.h"
       
    29 #include "CFSMailMessage.h"
       
    30 #include "CFSMailAddress.h"
       
    31 #include "CFSMailClient.h"
       
    32 #include "CFSMailCommon.h"
       
    33 #include <csxhelp/cmail.hlp.hrh>
       
    34 //</cmail>
       
    35 //<cmail> Touch
       
    36 #include <akntoolbar.h>
       
    37 #include <akntoolbarextension.h>
       
    38 #include <AknUtils.h>
       
    39 //</cmail> Touch
       
    40 #include <FreestyleEmailUi.rsg>
       
    41 #include <freestyleemailui.mbg>
       
    42 
       
    43 #include "ncscomposeview.h"
       
    44 #include "ncscomposeviewcontainer.h"
       
    45 #include "ncsconstants.h"
       
    46 #include "ncsutility.h"
       
    47 #include "ncsemailaddressobject.h"
       
    48 #include "FreestyleEmailCenRepHandler.h"
       
    49 #include "FreestyleEmailUi.hrh"
       
    50 #include "FreestyleEmailUiConstants.h"
       
    51 #include "FreestyleEmailUiSendAttachmentsListControl.h"
       
    52 #include "FreestyleEmailUiSendAttachmentsListVisualiser.h"
       
    53 #include "FreestyleEmailUiSendAttachmentsListModel.h"
       
    54 #include "FreestyleEmailUiUtilities.h"
       
    55 #include "FreestyleEmailUiConstants.h"
       
    56 #include "FSAutoSaver.h"
       
    57 #include "FSEmail.pan"
       
    58 
       
    59 
       
    60 // line separators that should not appear in Subject
       
    61 _LIT(KLineSeparators, "\u2029");
       
    62 const TChar KReplacementChar = ' ';
       
    63 
       
    64 
       
    65 #pragma mark +++COMPOSE VIEW - CONSTRUCTORS AND DESTRUCTORS
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // Safe pointer deletion
       
    69 //
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 template <class T> void SafeDelete( T*& aPtr )
       
    73     {
       
    74     delete aPtr;
       
    75     aPtr = NULL;
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CNcsComposeView::CNcsComposeView()
       
    80 // C++ default constructor can NOT contain any code, that might leave.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CNcsComposeView::CNcsComposeView( CFreestyleEmailUiAppUi& aAppUi,
       
    84     CAlfEnv& aEnv, CAlfControlGroup& aSendAttachmentControlGroup,
       
    85     CFSMailClient& aMailClient, CMsvSession& aMsvSession )
       
    86     : CFsEmailUiViewBase( aSendAttachmentControlGroup, aAppUi ),
       
    87      iMailClient( aMailClient ), iOrigMessage( NULL ), iNewMessage( NULL ),
       
    88      iMsvSession( aMsvSession ), iEnv( aEnv )
       
    89      ,iFakeSyncGoingOn(EFalse), iFetchDialogCancelled(EFalse),iExecutingDoExitL(EFalse)//<cmail>
       
    90     {
       
    91     FUNC_LOG;
       
    92 
       
    93     iAttachmentListSaveDraft = EFalse;
       
    94 
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CNcsComposeView::NewL()
       
    99 // Two-phased constructor.
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 CNcsComposeView* CNcsComposeView::NewL( CFSMailClient& aMailClient, CAlfEnv& aEnv,
       
   103                                         CFreestyleEmailUiAppUi* aAppUi, CAlfControlGroup& aControlGroup,
       
   104                                         CMsvSession& aMsvSession )
       
   105     {
       
   106     FUNC_LOG;
       
   107 
       
   108     CNcsComposeView* self = CNcsComposeView::NewLC( aMailClient, aEnv, 	aAppUi,
       
   109                                                     aControlGroup, aMsvSession );
       
   110     CleanupStack::Pop( self );
       
   111 
       
   112     return self;
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CNcsComposeView::NewLC()
       
   117 // Two-phased constructor.
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 CNcsComposeView* CNcsComposeView::NewLC(
       
   121     CFSMailClient& aMailClient,
       
   122     CAlfEnv& aEnv,
       
   123     CFreestyleEmailUiAppUi* aAppUi,
       
   124     CAlfControlGroup& aControlGroup,
       
   125     CMsvSession& aMsvSession )
       
   126     {
       
   127     FUNC_LOG;
       
   128 
       
   129     CNcsComposeView* self = new ( ELeave ) CNcsComposeView( *aAppUi, aEnv, aControlGroup, aMailClient, aMsvSession );
       
   130     CleanupStack::PushL( self );
       
   131     self->ConstructL();
       
   132 
       
   133     return self;
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // CNcsComposeView::ConstructL()
       
   138 // Symbian 2nd phase constructor can leave.
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CNcsComposeView::ConstructL()
       
   142     {
       
   143     FUNC_LOG;
       
   144 
       
   145     BaseConstructL( R_NCS_COMPOSE_VIEW );
       
   146     iFirstStartCompleted = EFalse;
       
   147     }
       
   148 
       
   149 // CFSEmailUiMsgDetailsVisualiser::DoFirstStartL()
       
   150 // Purpose of this function is to do first start only when msg details is
       
   151 // really needed to be shown. Implemented to make app startuo faster.
       
   152 void CNcsComposeView::DoFirstStartL()
       
   153     {
       
   154     FUNC_LOG;
       
   155     // Attachment list for compose screen
       
   156     CAlfControlGroup& attListControlGroup = iEnv.NewControlGroupL( KSendAttachmentManagerDisplayGroup ); // owned by AlfEnv
       
   157     CFSEmailUiSendAttachmentsListVisualiser* sendAttachmentVisualiser =
       
   158 		CFSEmailUiSendAttachmentsListVisualiser::NewLC(
       
   159             iEnv, &iAppUi, attListControlGroup );
       
   160     iAppUi.AddViewL( sendAttachmentVisualiser );
       
   161     CleanupStack::Pop( sendAttachmentVisualiser );
       
   162 
       
   163     iCrHandler = CFSEmailCRHandler::InstanceL(); // singleton, not owned
       
   164 
       
   165     iEnv.AddActionObserverL( this );
       
   166 
       
   167     iAutoSaver = CFsAutoSaver::NewL( iEnv, KAutoSaveTimeDelayMs );
       
   168     iAutoSaver->Enable( EFalse );
       
   169     iFirstStartCompleted = ETrue;
       
   170     iCheckQuery = EFalse;
       
   171     iAsyncCallback = new (ELeave) CAsyncCallBack( CActive::EPriorityLow );
       
   172     // msk context menu added into composer
       
   173     MenuBar()->SetContextMenuTitleResourceId( R_NCS_COMPOSE_BODY_MSK_MENUBAR );
       
   174     iActiveHelper = CActiveHelper::NewL(this);
       
   175 
       
   176     iAsyncAttachmentAdd = new (ELeave) CAsyncCallBack( CActive::EPriorityStandard );
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CNcsComposeView::~CNcsComposeView()
       
   181 // Destructor.
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 CNcsComposeView::~CNcsComposeView()
       
   185     {
       
   186     FUNC_LOG;
       
   187 	delete iAutoSaver;
       
   188 	if ( iAsyncCallback )
       
   189 	    {
       
   190 	    iAsyncCallback->Cancel();
       
   191 	    delete iAsyncCallback;
       
   192 	    }
       
   193     delete iFetchLogic;
       
   194     if(iActiveHelper)
       
   195         {
       
   196         iActiveHelper->Cancel();
       
   197         delete iActiveHelper;
       
   198         }
       
   199     if (iAsyncAttachmentAdd)
       
   200         {
       
   201         iAsyncAttachmentAdd->Cancel();
       
   202         delete iAsyncAttachmentAdd;
       
   203         }
       
   204     }
       
   205 
       
   206 void CNcsComposeView::PrepareForExit()
       
   207     {
       
   208     FUNC_LOG;
       
   209     if ( iCheckQuery && iDlg )
       
   210         {
       
   211         TKeyEvent check = { EKeyEscape, EStdKeyNull, 0, 0 };
       
   212         TRAP_IGNORE( iDlg->OfferKeyEventL( check, EEventKey ) );
       
   213         iDlg = NULL;
       
   214 
       
   215         iAsyncCallback->Cancel(); // cancel any outstanding callback just to be safe
       
   216         iAsyncCallback->Set( TCallBack( AsyncExit, this ) );
       
   217         iAsyncCallback->CallBack();
       
   218         }
       
   219     else if(iFakeSyncGoingOn || iExecutingDoExitL) //we starts this low priority active obj so that iwait in plugins finish
       
   220         {
       
   221         iActiveHelper->Cancel();
       
   222         iActiveHelper->Start();
       
   223         }
       
   224     else
       
   225         {
       
   226         DoSafeExit( ESaveDraft );
       
   227         //iAppUi.Exit();
       
   228         }
       
   229 
       
   230     if(iFetchLogic)
       
   231         {
       
   232         iFetchLogic->CancelFetchings();
       
   233         }
       
   234 
       
   235     //ResetComposer(); // already done in DoExitL
       
   236     }
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // CNcsComposeView::Id()
       
   240 // Returns View's ID.
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 TUid CNcsComposeView::Id() const
       
   244     {
       
   245     FUNC_LOG;
       
   246     return MailEditorId;
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CNcsComposeView::ChildDoActivateL()
       
   251 // Activate the Compose view
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 // <cmail> Toolbar
       
   255 /*void CNcsComposeView::DoActivateL( const TVwsViewId& aPrevViewId,
       
   256     TUid aCustomMessageId, const TDesC8& aCustomMessage )*/
       
   257 void CNcsComposeView::ChildDoActivateL( const TVwsViewId& aPrevViewId,
       
   258     TUid aCustomMessageId, const TDesC8& aCustomMessage )
       
   259 // </cmail> Toolbar
       
   260     {
       
   261     FUNC_LOG;
       
   262     if ( !iFirstStartCompleted )
       
   263         {
       
   264         DoFirstStartL();
       
   265         }
       
   266     Toolbar()->SetDimmed(ETrue);
       
   267     // Set status pane indicators
       
   268     iStatusPaneIndicators = iAppUi.GetStatusPaneIndicatorContainer();
       
   269     iStatusPaneIndicators->ShowStatusPaneIndicators();
       
   270 
       
   271     // Notify base class about view being entered unless we returned from another view
       
   272     if ( aCustomMessageId.iUid != KEditorCmdReturnToPrevious )
       
   273         {
       
   274         ViewEntered( aPrevViewId );
       
   275         }
       
   276 
       
   277     // Cleanup the previous message before opening a new one
       
   278     SaveAndCleanPreviousMessage();
       
   279 
       
   280     // Get the launch parameters
       
   281     if ( aCustomMessageId.iUid == KEditorCmdReturnToPrevious )
       
   282         {
       
   283         // Use previous launch parameters when returning to previously open message
       
   284         iMailBox = iMailClient.GetMailBoxByUidL( iLaunchParams.iMailboxId );
       
   285         }
       
   286     else if ( aCustomMessage.Length() > 0 )
       
   287         {
       
   288 
       
   289         TPckgBuf<TEditorLaunchParams> buf( iLaunchParams );
       
   290         buf.Copy( aCustomMessage );
       
   291         iLaunchParams = buf();
       
   292         iMailBox = iMailClient.GetMailBoxByUidL( iLaunchParams.iMailboxId );
       
   293 
       
   294         }
       
   295     else
       
   296         {
       
   297         iLaunchParams.iActivatedExternally = ETrue;
       
   298         }
       
   299 
       
   300     // Inform the AppUi about external view activation to fix the view stack. Normally
       
   301     // this happens based on the previous view AppUid in the BaseView but in case
       
   302     // contacts action menu was used within FsEmail, this doesn' work. It doesn't
       
   303     // hurt to call this again even if it was already called once from BaseView.
       
   304     if ( iLaunchParams.iActivatedExternally )
       
   305         {
       
   306         iAppUi.ViewActivatedExternallyL( Id() );
       
   307         }
       
   308 
       
   309     // Try to get the mailbox by other means if using launch parameters failed
       
   310     if ( !iMailBox )
       
   311         {
       
   312         TInt error( KErrNone );
       
   313 
       
   314         // can we get it from MSV Id
       
   315         // MSV id is passed to us when account is defined email key settings
       
   316         if ( aCustomMessageId != TUid::Null() )
       
   317             {
       
   318             TRAP( error, iMailBox = TFsEmailUiUtility::GetMailboxForMtmIdL( iMailClient, iMsvSession, aCustomMessageId.iUid ) );
       
   319             }
       
   320 
       
   321         error = KErrNone;
       
   322 
       
   323         // try to use mailbox set as default in MCE
       
   324         if ( !iMailBox )
       
   325             {
       
   326             TRAP( error, iMailBox = TFsEmailUiUtility::GetMceDefaultMailboxL( iMailClient, iMsvSession ) );
       
   327             }
       
   328 
       
   329         // use first mail account from the list
       
   330         if ( !iMailBox )
       
   331             {
       
   332             TFSMailMsgId id;
       
   333             RPointerArray<CFSMailBox> mailboxes;
       
   334             CleanupResetAndDestroyClosePushL( mailboxes );
       
   335             iMailClient.ListMailBoxes( id, mailboxes );
       
   336             if ( mailboxes.Count() > 0 )
       
   337                 {
       
   338                 iMailBox = iMailClient.GetMailBoxByUidL( mailboxes[0]->GetId() );
       
   339                 }
       
   340             CleanupStack::PopAndDestroy( &mailboxes );
       
   341             }
       
   342 
       
   343         // could not get mailbox so leave
       
   344         if ( !iMailBox )
       
   345             {
       
   346             User::Leave( KErrGeneral );
       
   347             }
       
   348 
       
   349         aCustomMessageId = TUid::Uid( KEditorCmdCreateNew );
       
   350         }
       
   351 
       
   352 
       
   353     iMailSent = EFalse;
       
   354     iMailSendFailed = EFalse;
       
   355     iCustomMessageId = aCustomMessageId;
       
   356 
       
   357     CreateContainerL();
       
   358 
       
   359     TRAPD( err, HandleActivationCommandL( aCustomMessageId ) );
       
   360     if ( !err )
       
   361         {
       
   362         err = iMailFetchingErrCode;
       
   363         }
       
   364 
       
   365     if ( err == KErrCancel || err == KErrCouldNotConnect || err == KErrConnectionTerminated )
       
   366         {
       
   367         // Just close composer without any notes if operation was cancelled. For connection
       
   368         // errors, DownloadInfoMediator already shows error message, so no need to show another one.
       
   369         ExitComposer();
       
   370         }
       
   371     else if ( err )
       
   372         {
       
   373         // some other error => show generic error note and close composer
       
   374         if(!iAppUi.AppUiExitOngoing()) //<cmail>
       
   375             TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE, ETrue );
       
   376         ExitComposer();
       
   377         }
       
   378     else
       
   379         {
       
   380         // everything went fine => do rest of the generic initialization
       
   381         InitUiGeneralL();
       
   382         iAppUi.StartEndKeyCapture();
       
   383         iContainer->SetMskL();
       
   384         iViewReady = ETrue;
       
   385         Toolbar()->SetDimmed(EFalse);
       
   386         RefreshToolbar();
       
   387         }
       
   388     }
       
   389 
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CNcsComposeView::OfferToolbarEventL
       
   393 // -----------------------------------------------------------------------------
       
   394 void CNcsComposeView::OfferToolbarEventL( TInt aCommand )
       
   395     {
       
   396     FUNC_LOG;
       
   397     bool attachmentAddition = EFalse;
       
   398     switch (aCommand)
       
   399         {
       
   400         case EFsEmailUiTbCmdSend:
       
   401             if (iContainer && iContainer->AreAddressFieldsEmpty())
       
   402                 {
       
   403                 RefreshToolbar();
       
   404                 }
       
   405             else
       
   406                 {
       
   407                 HandleCommandL( ENcsCmdSend );
       
   408                 }
       
   409             break;
       
   410         case EFsEmailUiTbCmdAddRecipient:
       
   411             if (iContainer)
       
   412                 {
       
   413                 iContainer->AppendAddressesL();
       
   414                 }
       
   415             break;
       
   416         case EFsEmailUiTbCmdInsertAudio:
       
   417             iAttachmentAddType = MsgAttachmentUtils::EAudio;
       
   418             attachmentAddition = ETrue;
       
   419             break;
       
   420         case EFsEmailUiTbCmdInsertImage:
       
   421             iAttachmentAddType = MsgAttachmentUtils::EImage;
       
   422             attachmentAddition = ETrue;
       
   423             break;
       
   424         case EFsEmailUiTbCmdInsertVideo:
       
   425             iAttachmentAddType = MsgAttachmentUtils::EVideo;
       
   426             attachmentAddition = ETrue;
       
   427             break;
       
   428         case EFsEmailUiTbCmdInsertNote:
       
   429             iAttachmentAddType = MsgAttachmentUtils::ENote;
       
   430             attachmentAddition = ETrue;
       
   431             break;
       
   432         case EFsEmailUiTbCmdInsertPresentation:
       
   433             iAttachmentAddType = MsgAttachmentUtils::ESVG;
       
   434             attachmentAddition = ETrue;
       
   435             break;
       
   436         case EFsEmailUiTbCmdInsertOther:
       
   437             iAttachmentAddType = MsgAttachmentUtils::EUnknown;
       
   438             attachmentAddition = ETrue;
       
   439             break;
       
   440         default:
       
   441             break;
       
   442         }
       
   443     if (attachmentAddition)
       
   444         {
       
   445         iAsyncAttachmentAdd->Cancel(); // cancel any outstanding callback just to be safe
       
   446         iAsyncAttachmentAdd->Set( TCallBack( AsyncAddAttachment, this ) );
       
   447         iAsyncAttachmentAdd->CallBack();
       
   448         }
       
   449     }
       
   450 
       
   451 // <cmail> Toolbar
       
   452 // -----------------------------------------------------------------------------
       
   453 // CNcsComposeView::ToolbarResourceId()
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 TInt CNcsComposeView::ToolbarResourceId() const
       
   457     {
       
   458     FUNC_LOG;
       
   459     return R_FREESTYLE_EMAIL_UI_TOOLBAR_MESSAGE_EDITOR;
       
   460     }
       
   461 
       
   462 // -----------------------------------------------------------------------------
       
   463 // CNcsComposeView::GetInitiallyDimmedItemsL()
       
   464 // -----------------------------------------------------------------------------
       
   465 //
       
   466 void CNcsComposeView::GetInitiallyDimmedItemsL( const TInt aResourceId,
       
   467         RArray<TInt>& aDimmedItems ) const
       
   468     {
       
   469     FUNC_LOG;
       
   470     aDimmedItems.Reset();
       
   471     switch (aResourceId)
       
   472         {
       
   473         case R_FREESTYLE_EMAIL_UI_TOOLBAR_MESSAGE_EDITOR:
       
   474             aDimmedItems.AppendL(EFsEmailUiTbCmdSend);
       
   475             break;
       
   476         default:
       
   477             break;
       
   478         }
       
   479     }
       
   480 
       
   481 // -----------------------------------------------------------------------------
       
   482 // CNcsComposeView::RefreshToolbar()
       
   483 // -----------------------------------------------------------------------------
       
   484 //
       
   485 void CNcsComposeView::RefreshToolbar()
       
   486     {
       
   487     FUNC_LOG;
       
   488     if (iContainer)
       
   489         {
       
   490         // DimAllOptions if remotesearch is in progress, cos it takes you in a different view
       
   491         TBool dimAllOptions = iContainer->IsRemoteSearchInprogress();
       
   492         SetToolbarItemDimmed( EFsEmailUiTbCmdExpandInsert, dimAllOptions );
       
   493         SetToolbarItemDimmed( EFsEmailUiTbCmdSend,
       
   494                 iContainer->AreAddressFieldsEmpty() );
       
   495         if ( (iContainer->IsFocusBcc() || iContainer->IsFocusCc() || iContainer->IsFocusTo()) && !dimAllOptions )
       
   496             {
       
   497             SetToolbarItemDimmed( EFsEmailUiTbCmdAddRecipient, EFalse );
       
   498             }
       
   499         else
       
   500             {
       
   501             SetToolbarItemDimmed( EFsEmailUiTbCmdAddRecipient, ETrue );
       
   502             }
       
   503         }
       
   504     }
       
   505 // </cmail> Toolbar
       
   506 
       
   507 
       
   508 // -----------------------------------------------------------------------------
       
   509 // CNcsComposeView::ChildDoDeactivate()
       
   510 // Deactivate the Compose view
       
   511 // -----------------------------------------------------------------------------
       
   512 //
       
   513 void CNcsComposeView::ChildDoDeactivate()
       
   514     {
       
   515     FUNC_LOG;
       
   516 
       
   517     iAppUi.StopEndKeyCapture();
       
   518 
       
   519     SafeDelete( iFetchLogic );
       
   520 
       
   521     // Normally Comopser state has been already cleaned by now but in special
       
   522     // cases (like external view activation while in Composer) this may not be
       
   523     // the case. In those cases the message needs to be saved before the view
       
   524     // is deactivated.
       
   525     if ( !iAppUi.AppUiExitOngoing() )
       
   526         {
       
   527         SaveAndCleanPreviousMessage();
       
   528         }
       
   529 
       
   530     }
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // CNcsComposeView::DynInitMenuPaneL()
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 void CNcsComposeView::DynInitMenuPaneL( TInt aResourceId,
       
   537                                         CEikMenuPane* aMenuPane )
       
   538     {
       
   539     FUNC_LOG;
       
   540 
       
   541     if ( !iViewReady )
       
   542         {
       
   543         User::Leave( KErrNcsComposeViewNotReady );
       
   544         }
       
   545 
       
   546     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
       
   547     __ASSERT_DEBUG( iMailBox, Panic( ENcsBasicUi ) );
       
   548     __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
       
   549 
       
   550     //<cmail>
       
   551     //we are forbiding to change MSK label, cause popup will be opend 
       
   552     iContainer->SwitchChangeMskOff(ETrue);
       
   553     //</cmail>
       
   554     
       
   555     if ( aResourceId == R_NCS_COMPOSE_MENU )
       
   556         {
       
   557 	    if (FeatureManager::FeatureSupported( KFeatureIdFfCmailIntegration ))
       
   558 		   {
       
   559 		   // remove help support in pf5250
       
   560 		   aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue);      
       
   561 		   }     
       
   562         
       
   563     	// Disable send if there are no addresses in any of the AIF fields,
       
   564     	if ( iContainer->AreAddressFieldsEmpty() )
       
   565 		    {
       
   566 	    	aMenuPane->DeleteMenuItem( ENcsCmdSend );
       
   567 		    }
       
   568 
       
   569 	    // If no attachments currently, delete the remove attachments menu item
       
   570 		CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
       
   571 		attachmentControl = AttachmentsListControl();
       
   572 		TInt count = attachmentControl->Model()->Count();
       
   573 
       
   574         // if mail has remote attachments then attachments can't be removed via options menu
       
   575 		if ( count <= 0 || AttachmentsListControl()->Model()->HasReadOnlyAttachments() )
       
   576 	    	{
       
   577     		aMenuPane->DeleteMenuItem( ENcsCmdRemoveAttachment );
       
   578     		aMenuPane->DeleteMenuItem( ENcsCmdRemoveAllAttachments );
       
   579 	    	}
       
   580         else if ( count == 1 )
       
   581 	     	{
       
   582     		aMenuPane->DeleteMenuItem( ENcsCmdRemoveAllAttachments );
       
   583 	     	}
       
   584         else
       
   585 	     	{
       
   586     		aMenuPane->DeleteMenuItem( ENcsCmdRemoveAttachment );
       
   587 	     	}
       
   588 
       
   589         if ( iContainer->GetCcFieldLength() > 0 &&
       
   590              iContainer->GetBccFieldLength() > 0 )
       
   591         	{
       
   592             aMenuPane->DeleteMenuItem( ENcsCmdMore );
       
   593         	}
       
   594 
       
   595         if ( !TFsEmailUiUtility::IsFollowUpSupported( *iMailBox ) )
       
   596         	{
       
   597     		aMenuPane->DeleteMenuItem( ENcsCmdFlag );
       
   598         	}
       
   599         }
       
   600 
       
   601     if ( aResourceId == R_NCS_MORE_MENU )
       
   602         {
       
   603 		// Select which View->CC menu items to show
       
   604 		if ( iContainer->IsCcFieldVisible() )
       
   605             {
       
   606             aMenuPane->DeleteMenuItem( ENcsCmdShowCc );
       
   607             // if there is text in Cc field do not show "hide Cc" menu item
       
   608             if ( iContainer->GetCcFieldLength() > 0 )
       
   609             	{
       
   610             	aMenuPane->DeleteMenuItem( ENcsCmdHideCc );
       
   611             	}
       
   612             }
       
   613         else
       
   614             {
       
   615         	aMenuPane->DeleteMenuItem( ENcsCmdHideCc );
       
   616             }
       
   617 
       
   618 		// Select which View->BCC menu items to show
       
   619         if ( iContainer->IsBccFieldVisible() )
       
   620             {
       
   621             aMenuPane->DeleteMenuItem( ENcsCmdShowBcc );
       
   622             // if there is text in Bcc field do not show "hide Bcc" menu item
       
   623             if ( iContainer->GetBccFieldLength() > 0 )
       
   624             	{
       
   625             	aMenuPane->DeleteMenuItem( ENcsCmdHideBcc );
       
   626             	}
       
   627             }
       
   628         else
       
   629             {
       
   630             aMenuPane->DeleteMenuItem( ENcsCmdHideBcc );
       
   631             }
       
   632         }
       
   633 
       
   634 	if ( aResourceId == R_NCS_PRIORITY_MENU )
       
   635     	{
       
   636 
       
   637         if ( iNewMessage->IsFlagSet( EFSMsgFlag_Important ) )
       
   638             {
       
   639             aMenuPane->DeleteMenuItem( ENcsCmdPriorityHigh );
       
   640             }
       
   641         else if ( iNewMessage->IsFlagSet( EFSMsgFlag_Low ) )
       
   642             {
       
   643             aMenuPane->DeleteMenuItem( ENcsCmdPriorityLow );
       
   644             }
       
   645         else
       
   646             {
       
   647             aMenuPane->DeleteMenuItem( ENcsCmdPriorityNormal );
       
   648             }
       
   649     	}
       
   650 
       
   651     }
       
   652 
       
   653 // -----------------------------------------------------------------------------
       
   654 // CNcsComposeView::HandleCommandL()
       
   655 // Takes care of Command handling.
       
   656 // -----------------------------------------------------------------------------
       
   657 //
       
   658 void CNcsComposeView::HandleCommandL( TInt aCommand )
       
   659     {
       
   660     FUNC_LOG;
       
   661 
       
   662     // Attempt to handle commands only after view is fully activated and exit has not yet been initiated.
       
   663     if ( iViewReady && !iAppUi.ViewSwitchingOngoing() )
       
   664         {
       
   665         __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
       
   666         __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
       
   667         __ASSERT_DEBUG( iCrHandler, Panic( ENcsBasicUi ) );
       
   668 
       
   669         switch( aCommand )
       
   670             {
       
   671             case ENcsCmdSend:
       
   672                 {
       
   673                 // Show query if the Subject field is empty (default text is as subject)
       
   674                 if ( iContainer->IsSubjectFieldEmpty() )
       
   675                     {
       
   676                     TInt answer = TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_QUERY_NO_SUBJECT );
       
   677                     if ( !answer )
       
   678                         {
       
   679                         // user didn't want to send yet -> go back to the message
       
   680                         return;
       
   681                         }
       
   682                     }
       
   683 
       
   684                 TRAPD( error, DoSendL() );
       
   685                 if ( !error )
       
   686                     {
       
   687                     // Sending successful
       
   688                     HBufC* confMessage = NULL;
       
   689                     if ( !TFsEmailUiUtility::IsOfflineModeL() )
       
   690                         {
       
   691                         // when sync status is currently ONLINE
       
   692                         confMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_CONFIRM_NOTE_SENDING_QUEUED );
       
   693                         }
       
   694                     else
       
   695                         {
       
   696                         // when sync status is currently OFFLINE
       
   697                         confMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_CONFIRM_NOTE_QUEUED_UNTIL_ONLINE );
       
   698                         }
       
   699                     CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote( ETrue ); //waiting
       
   700                     note->SetTimeout( CAknNoteDialog::ELongTimeout );
       
   701                     note->ExecuteLD( *confMessage );
       
   702                     CleanupStack::PopAndDestroy( confMessage );
       
   703                     DoSafeExit(); // Exit after successful sending
       
   704                     }
       
   705                 else if ( error == KErrBadName )
       
   706                 	{
       
   707                   	// sending failed because recipient address was invalid
       
   708                 	TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_CONFIRM_NOTE_INVALID_EMAIL_ADDRESS, ETrue );
       
   709                 	}
       
   710                 else
       
   711                 	{
       
   712                 	// sending failed for some other reason
       
   713                     TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_CONFIRM_NOTE_MESSAGE_NOT_SENT, ETrue );
       
   714                 	DoSafeExit(); // Exit after sending failed for other reason than KErrBadName
       
   715                 	}
       
   716                 }
       
   717                 break;
       
   718             case ENcsCmdAddAttachment:
       
   719            	 	{
       
   720            	 	//<cmail> Touch
       
   721                 if ( AknLayoutUtils::PenEnabled() )
       
   722                     {
       
   723                     // show the toolbar
       
   724                     UpdateToolbarL();
       
   725                     if ( Toolbar() && Toolbar()->ToolbarExtension() )
       
   726                         {
       
   727                         Toolbar()->ToolbarExtension()->SetShown( ETrue );
       
   728                         }
       
   729                     }
       
   730                 else
       
   731                     {
       
   732                     //</cmail>
       
   733                     iAttachmentAddType = MsgAttachmentUtils::EUnknown;
       
   734                     iAsyncAttachmentAdd->Cancel(); // cancel any outstanding callback just to be safe
       
   735                     iAsyncAttachmentAdd->Set( TCallBack( AsyncAddAttachment, this ) );
       
   736                     iAsyncAttachmentAdd->CallBack();
       
   737                     iContainer->SetMskL();
       
   738                     //<cmail> Touch
       
   739                     }                
       
   740                 //</cmail>
       
   741            	 	}
       
   742                 break;
       
   743             case EFsEmailUiCmdOpenAttachment:
       
   744             case EFsEmailUiCmdOpenAttachmentList:
       
   745                 {
       
   746                 DoOpenAttachmentListL();
       
   747                 }
       
   748                 break;
       
   749             case ENcsCmdRemoveAttachment: // remove one and only attachment
       
   750             case ENcsCmdRemoveAllAttachments:
       
   751            	 	{
       
   752            	 	AttachmentsListControl()->RemoveAllAttachmentsL();
       
   753            	 	SetAttachmentLabelContentL();
       
   754             	}
       
   755                 break;
       
   756             case ENcsCmdPriorityHigh:
       
   757             	{
       
   758             	iNewMessage->ResetFlag( EFSMsgFlag_Low );
       
   759             	iNewMessage->SetFlag( EFSMsgFlag_Important );
       
   760             	iNewMessage->SaveMessageL();
       
   761             	iStatusPaneIndicators->SetPriorityFlag(EMsgPriorityHigh);
       
   762             	}
       
   763                 break;
       
   764         	case ENcsCmdPriorityNormal:
       
   765     	    	{
       
   766             	iNewMessage->ResetFlag( EFSMsgFlag_Low );
       
   767             	iNewMessage->ResetFlag( EFSMsgFlag_Important );
       
   768             	iNewMessage->SaveMessageL();
       
   769             	iStatusPaneIndicators->SetPriorityFlag(EMsgPriorityNormal);
       
   770     	    	}
       
   771                 break;
       
   772         	case ENcsCmdPriorityLow:
       
   773     	    	{
       
   774             	iNewMessage->ResetFlag( EFSMsgFlag_Important );
       
   775             	iNewMessage->SetFlag( EFSMsgFlag_Low );
       
   776             	iNewMessage->SaveMessageL();
       
   777             	iStatusPaneIndicators->SetPriorityFlag(EMsgPriorityLow);
       
   778     	    	}
       
   779                 break;
       
   780             case ENcsCmdShowCc:
       
   781                 {
       
   782                 iContainer->SetCcFieldVisibleL( ETrue );
       
   783                 iCrHandler->SetEditorCCVisible( 1 );
       
   784                 }
       
   785                 break;
       
   786             case ENcsCmdHideCc:
       
   787                 {
       
   788                 iContainer->SetCcFieldVisibleL( EFalse );
       
   789                 iCrHandler->SetEditorCCVisible( 0 );
       
   790                 }
       
   791                 break;
       
   792             case ENcsCmdShowBcc:
       
   793                 {
       
   794                 iContainer->SetBccFieldVisibleL( ETrue );
       
   795                 iCrHandler->SetEditorBCVisible( 1 );
       
   796                 }
       
   797                 break;
       
   798             case ENcsCmdHideBcc:
       
   799                 {
       
   800                 iContainer->SetBccFieldVisibleL( EFalse );
       
   801                 iCrHandler->SetEditorBCVisible( 0 );
       
   802                 }
       
   803                 break;
       
   804             case ENcsCmdFlag:
       
   805     	        {
       
   806     	        RunFollowUpFlagDlgL();
       
   807     	        }
       
   808                 break;
       
   809             case ENcsCmdQuickText:
       
   810     	        {
       
   811     	        DoQuickTextL();
       
   812     	        }
       
   813                 break;
       
   814             case ENcsCmdInsertContact:
       
   815             case ENcsInsertContact:
       
   816             	{
       
   817             	iContainer->AppendAddressesL();
       
   818             	}
       
   819                 break;
       
   820             case ENcsCmdSaveDraft:
       
   821             	{
       
   822 
       
   823                 iContainer->FixSemicolonL();
       
   824 
       
   825 
       
   826             	TRAPD( saveDraftError, DoSaveDraftL( EFalse ) );
       
   827                 if ( saveDraftError == KErrNone )
       
   828                 	{
       
   829                     // Saving successful
       
   830                 	if(!iAppUi.AppUiExitOngoing()) //<cmail>
       
   831                 	TFsEmailUiUtility::ShowInfoNoteL( R_FREESTYLE_EMAIL_CONFIRM_NOTE_SAVED_TO_DRAFTS, ETrue );
       
   832                     }
       
   833             	else
       
   834                     {
       
   835                     // error occured in saving -> show an error message
       
   836                     if(!iAppUi.AppUiExitOngoing()) //<cmail>
       
   837                         TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE, ETrue );
       
   838                     }
       
   839 
       
   840             	DoSafeExit( ENoSave );
       
   841             	}
       
   842                 break;
       
   843             case EAknCmdHelp:
       
   844             	{
       
   845             	TFsEmailUiUtility::LaunchHelpL( KFSE_HLP_LAUNCHER_GRID );
       
   846     	        }
       
   847             	break;
       
   848             case EAknSoftkeySelect:
       
   849                 {
       
   850                 iContainer->DoPopupSelectL();
       
   851                 }
       
   852                 break;
       
   853        	    case EAknSoftkeyCancel:
       
   854         	    {
       
   855     	 		iContainer->ClosePopupContactListL();
       
   856                 }
       
   857                 break;
       
   858             case EAknSoftkeyClose:
       
   859                 {
       
   860                 DoSafeExit();
       
   861                 }
       
   862                 break;
       
   863             case ENcsCmdExit:
       
   864                 {
       
   865                 // This is for a special case when SaveDeleteQuery appears and user presses immediately End key
       
   866                 // we are first checking if Queryexists ,if yes then we forward event to iDlg->offerkeyEventL and
       
   867                 // then call Asynchronously Exit method so that iDlg->OfferkeyEventL gets some time before calling
       
   868                 // Async Exit method
       
   869                 // <cmail> these things are now handeled in prepare for exit
       
   870                 /*if ( iCheckQuery )
       
   871                     {
       
   872                     TKeyEvent check = { EKeyEscape, EStdKeyNull, 0, 0 };
       
   873                     TKeyResponse ret = iDlg->OfferKeyEventL(check, EEventKey );
       
   874                     iDlg = NULL;
       
   875 
       
   876                     iAsyncCallback->Cancel(); // cancel any outstanding callback just to be safe
       
   877                     iAsyncCallback->Set( TCallBack( AsyncExit, this ) );
       
   878                     iAsyncCallback->CallBack();
       
   879                     }
       
   880                 else
       
   881                     {
       
   882                     DoSafeExit( ESaveDraft );*/
       
   883                     iAppUi.Exit();
       
   884                     //}
       
   885                  //</cmail>
       
   886                 }
       
   887                 break;
       
   888             default:
       
   889                 {
       
   890                 // empty implementation
       
   891                 // these commands are passed next to FEP for processing
       
   892                 }
       
   893                 break;
       
   894             }
       
   895         }
       
   896 
       
   897     }
       
   898 
       
   899 // -----------------------------------------------------------------------------
       
   900 // CNcsComposeView::DoSendL()
       
   901 // Send message
       
   902 // -----------------------------------------------------------------------------
       
   903 //
       
   904 void CNcsComposeView::DoSendL()
       
   905     {
       
   906     FUNC_LOG;
       
   907 
       
   908     // check that addresses exist
       
   909     if ( iContainer->AreAddressFieldsEmpty() )
       
   910         {
       
   911         User::Leave( KErrNotFound );
       
   912         }
       
   913 
       
   914 	CommitL();
       
   915 
       
   916     TRAPD(r, iMailBox->SendMessageL( *iNewMessage ) );
       
   917     if ( KErrNone != r )
       
   918         {
       
   919         iMailSendFailed = ETrue;
       
   920         User::Leave( r );
       
   921         }
       
   922 
       
   923     // <cmail> prevent sending failure if original message is
       
   924     // removed from server while replying/forwarding
       
   925 	TRAPD( flagError, SetReplyForwardFlagL() );
       
   926 
       
   927     if ( KErrNone != flagError && KErrNotFound != flagError )
       
   928         {
       
   929         iMailSendFailed = ETrue;
       
   930         User::Leave( flagError );
       
   931         }
       
   932     // </cmail>
       
   933 
       
   934     iMailSent = ETrue;
       
   935 
       
   936     }
       
   937 
       
   938 
       
   939 // -----------------------------------------------------------------------------
       
   940 // CNcsComposeView::DoSaveDraftL()
       
   941 // Saves message to Drafts
       
   942 // Displays dialog asking user choice if preferred
       
   943 // Pressing cancel in the query dialog causes Leave with code KErrCancel
       
   944 // -----------------------------------------------------------------------------
       
   945 //
       
   946 TBool CNcsComposeView::DoSaveDraftL( TBool aAskUser )
       
   947     {
       
   948     FUNC_LOG;
       
   949 
       
   950     __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
       
   951 
       
   952     TBool result( ETrue );
       
   953 
       
   954     if ( aAskUser )
       
   955         {
       
   956     	TInt selectedOption( -1 );
       
   957     	CDesCArrayFlat* array = new (ELeave) CDesCArrayFlat( 2 );
       
   958     	CleanupStack::PushL( array );
       
   959 
       
   960     	HBufC* saveItem = StringLoader::LoadLC( R_NCS_DRAFT_SAVE );
       
   961         array->AppendL( *saveItem );
       
   962 		CleanupStack::PopAndDestroy( saveItem );
       
   963 
       
   964     	HBufC* deleteItem = StringLoader::LoadLC( R_NCS_DRAFT_DELETE );
       
   965         array->AppendL( *deleteItem );
       
   966 		CleanupStack::PopAndDestroy( deleteItem );
       
   967 
       
   968 		iDlg = new (ELeave) CAknListQueryDialog( &selectedOption );
       
   969     	iDlg->PrepareLC( R_DRAFT_QUERY_DIALOG );
       
   970     	// CleanupStack::Pop(iDlg);
       
   971     	iDlg->SetItemTextArray( array );
       
   972     	iDlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   973 
       
   974         iCheckQuery = ETrue;
       
   975         //we are forbiding to change MSK label, cause popup will be opend 
       
   976         iContainer->SwitchChangeMskOff(ETrue);
       
   977         TInt ret = iDlg->RunLD();
       
   978         iDlg = NULL;
       
   979 
       
   980         iCheckQuery = EFalse; 
       
   981         iContainer->SwitchChangeMskOff(EFalse);
       
   982 
       
   983     	if ( !ret )
       
   984     	    {
       
   985     	    selectedOption = KErrCancel;
       
   986     	    }
       
   987 
       
   988     	switch ( selectedOption )
       
   989     		{
       
   990     		case 0:
       
   991     			{
       
   992 				TRAPD( saveError, SaveToDraftsL( ETrue ) );
       
   993 
       
   994 				if ( saveError == KErrNone )
       
   995 				    {
       
   996 				    // User wanted to save to Drafts and saving was successful
       
   997 				    if(!iAppUi.AppUiExitOngoing()) //<cmail>
       
   998 				        TFsEmailUiUtility::ShowInfoNoteL( R_FREESTYLE_EMAIL_CONFIRM_NOTE_SAVED_TO_DRAFTS, ETrue );
       
   999 				    }
       
  1000 				else
       
  1001 				    {
       
  1002 
       
  1003 				    // error occured in saving -> show an error message
       
  1004 				    if(!iAppUi.AppUiExitOngoing()) //<cmail>
       
  1005 				        TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE, ETrue );
       
  1006 
       
  1007 				    // let's return EFalse so after completing this query
       
  1008 				    // so the focus would stay in compose view (same behaviour as if Cancel was pressed )
       
  1009 				    result = EFalse;
       
  1010 				    }
       
  1011 				}
       
  1012                 break;
       
  1013     		case 1:
       
  1014     			{
       
  1015 				TRAPD( error, SaveToDraftsL( ETrue ) );
       
  1016     			if ( KErrNone != error )
       
  1017     			    {
       
  1018     			    }
       
  1019     	        iFakeSyncGoingOn = ETrue; //<cmail> for delete messages fake sync callscalls
       
  1020                 error = NcsUtility::DeleteMessage( iMailClient,
       
  1021             		iMailBox->GetId(),
       
  1022             		iNewMessage->GetFolderId(),
       
  1023             		iNewMessage->GetMessageId() );
       
  1024 
       
  1025     			if ( KErrNone == error && iMailBox->HasCapability( EFSMBoxCapaSupportsDeletedItemsFolder ) )
       
  1026     			    {
       
  1027                     error = NcsUtility::DeleteMessage( iMailClient,
       
  1028                 		iMailBox->GetId(),
       
  1029                 		iMailBox->GetStandardFolderId( EFSDeleted ),
       
  1030                 		iNewMessage->GetMessageId() );
       
  1031     			    }
       
  1032     		     iFakeSyncGoingOn = EFalse; //<cmail>
       
  1033 
       
  1034                 if( !iAppUi.AppUiExitOngoing() )
       
  1035                     {
       
  1036                     if ( KErrNone != error )
       
  1037                         {
       
  1038                         // error occured in saving -> show an error message
       
  1039                         TFsEmailUiUtility::ShowErrorNoteL( 
       
  1040                             R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE, ETrue );
       
  1041                         }
       
  1042                     else
       
  1043                         {
       
  1044                         // Simulate delete event so that drafts folder is
       
  1045                         // updated correctly.
       
  1046                         RArray<TFSMailMsgId> messageIds;
       
  1047                         CleanupClosePushL( messageIds );
       
  1048                         messageIds.AppendL( iNewMessage->GetMessageId() );
       
  1049                         TFSMailMsgId folderId = iNewMessage->GetFolderId();
       
  1050                         TFSMailMsgId mailboxId = iNewMessage->GetMailBoxId();
       
  1051                         iAppUi.EventL( TFSEventMailDeleted,
       
  1052                             mailboxId, &messageIds, &folderId, NULL );
       
  1053                         CleanupStack::PopAndDestroy( &messageIds );
       
  1054                         }
       
  1055                     }
       
  1056                 }
       
  1057                 break;
       
  1058     		default:
       
  1059     			{
       
  1060     			result = EFalse;
       
  1061     			}
       
  1062                 break;
       
  1063     		}
       
  1064 
       
  1065     	//iCheckQuery = EFalse; //<cmail>
       
  1066     	CleanupStack::PopAndDestroy( array );
       
  1067         }
       
  1068     else  // no question from user
       
  1069         {
       
  1070         SaveToDraftsL( ETrue );
       
  1071         }
       
  1072 
       
  1073     return result;
       
  1074     }
       
  1075 
       
  1076 // -----------------------------------------------------------------------------
       
  1077 // CNcsComposeView::NewMessage()
       
  1078 // Returns pointer to currently composed mail message
       
  1079 // -----------------------------------------------------------------------------
       
  1080 //
       
  1081 CFSMailMessage* CNcsComposeView::NewMessage()
       
  1082     {
       
  1083     FUNC_LOG;
       
  1084 	return iNewMessage;
       
  1085     }
       
  1086 
       
  1087 // -----------------------------------------------------------------------------
       
  1088 // CNcsComposeView::AsyncAddAttachmentL()
       
  1089 // Open file dialog and add selected file as an attachment
       
  1090 // -----------------------------------------------------------------------------
       
  1091 //
       
  1092 TInt CNcsComposeView::AsyncAddAttachment( TAny* aSelfPtr )
       
  1093     {
       
  1094     FUNC_LOG;
       
  1095 
       
  1096     CNcsComposeView* self = static_cast<CNcsComposeView*>(aSelfPtr);
       
  1097 
       
  1098     // get pointer to attachment list view
       
  1099 	CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
       
  1100 	attachmentControl = self->AttachmentsListControl();
       
  1101 
       
  1102    	// show file dialog and get file name
       
  1103 	TBool ok = EFalse;
       
  1104 	TRAPD( error, ok = attachmentControl->AppendAttachmentToListL(self->iAttachmentAddType) );
       
  1105 	if ( ok && error == KErrNone )
       
  1106 	    {
       
  1107 	    TRAPD( error, self->SetAttachmentLabelContentL() );
       
  1108 	    return error;
       
  1109 	    }
       
  1110 	return error;
       
  1111     }
       
  1112 
       
  1113 // -----------------------------------------------------------------------------
       
  1114 // RunFollowUpFlagDlgL()
       
  1115 // Query user for followup flag
       
  1116 // -----------------------------------------------------------------------------
       
  1117 //
       
  1118 void CNcsComposeView::RunFollowUpFlagDlgL()
       
  1119     {
       
  1120     FUNC_LOG;
       
  1121     if ( iNewMessage && TFsEmailUiUtility::IsFollowUpSupported( *iMailBox ) )
       
  1122         {
       
  1123         TFollowUpNewState newState =
       
  1124             TFsEmailUiUtility::SetMessageFollowupFlagL( *iNewMessage, EFalse );
       
  1125 
       
  1126         switch ( newState )
       
  1127             {
       
  1128             case EFollowUp:
       
  1129                 {
       
  1130                 iStatusPaneIndicators->SetFollowUpFlag( CCustomStatuspaneIndicators::EFollowUp );
       
  1131                 }
       
  1132                 break;
       
  1133             case EFollowUpComplete:
       
  1134                 {
       
  1135                 iStatusPaneIndicators->SetFollowUpFlag( CCustomStatuspaneIndicators::EFollowUpComplete );
       
  1136                 }
       
  1137                 break;
       
  1138             case EFollowUpClear:
       
  1139                 {
       
  1140                 iStatusPaneIndicators->SetFollowUpFlag( CCustomStatuspaneIndicators::EFollowUpNone );
       
  1141                 }
       
  1142                 break;
       
  1143             default:
       
  1144                 {
       
  1145                 // do nothing.
       
  1146                 }
       
  1147                 break;
       
  1148             }
       
  1149         }
       
  1150     }
       
  1151 
       
  1152 // -----------------------------------------------------------------------------
       
  1153 // CNcsComposeView::SetAttachmentLabelContentL()
       
  1154 // Open file dialog and add selected file as an attachment
       
  1155 // -----------------------------------------------------------------------------
       
  1156 //
       
  1157 void CNcsComposeView::SetAttachmentLabelContentL()
       
  1158     {
       
  1159     FUNC_LOG;
       
  1160     if ( iFirstStartCompleted ) // Safety
       
  1161         {
       
  1162         CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
       
  1163         attachmentControl = AttachmentsListControl();
       
  1164 
       
  1165         // read number of attachments
       
  1166         TInt count = attachmentControl->Model()->Count();
       
  1167 
       
  1168         if ( count > 1 )
       
  1169             {
       
  1170             TInt totalSizeInBytes = attachmentControl->Model()->TotalAttachmentSize();
       
  1171             HBufC* stringBuf = NULL;
       
  1172 
       
  1173             HBufC* sizeDesc = TFsEmailUiUtility::CreateSizeDescLC( totalSizeInBytes );
       
  1174             stringBuf = StringLoader::LoadL( R_NCS_ATTACHMENTS_FIELD_TEXT,
       
  1175                                              *sizeDesc, count );
       
  1176             CleanupStack::PopAndDestroy( sizeDesc );
       
  1177 
       
  1178             CleanupStack::PushL( stringBuf );
       
  1179             iContainer->SetAttachmentLabelTextL( *stringBuf );
       
  1180             CleanupStack::PopAndDestroy( stringBuf );
       
  1181             iContainer->SetFocusToAttachmentField();
       
  1182             }
       
  1183         else if ( count == 1 )
       
  1184             {
       
  1185             CFSEmailUiSendAttachmentsListModelItem* item =
       
  1186                 static_cast<CFSEmailUiSendAttachmentsListModelItem*>(
       
  1187                     attachmentControl->Model()->Item( 0 ) );
       
  1188 
       
  1189             HBufC* sizeBuf = TFsEmailUiUtility::CreateSizeDescLC( item->FileSize() );
       
  1190             iContainer->SetAttachmentLabelTextL( item->FileName(), *sizeBuf );
       
  1191             CleanupStack::PopAndDestroy( sizeBuf );
       
  1192 
       
  1193             iContainer->SetFocusToAttachmentField();
       
  1194             }
       
  1195         else
       
  1196             {
       
  1197             iContainer->SetAttachmentLabelTextL( KNullDesC );
       
  1198             iContainer->HideAttachmentLabel();
       
  1199             }
       
  1200         }
       
  1201 
       
  1202     }
       
  1203 
       
  1204 
       
  1205 // -----------------------------------------------------------------------------
       
  1206 // CNcsComposeView::AttachmentsListControl()
       
  1207 //
       
  1208 // -----------------------------------------------------------------------------
       
  1209 //
       
  1210 CFreestyleEmailUiSendAttachmentsListControl* CNcsComposeView::AttachmentsListControl()
       
  1211 	{
       
  1212     FUNC_LOG;
       
  1213     CFreestyleEmailUiSendAttachmentsListControl* attachmentControl(0);
       
  1214     if ( iFirstStartCompleted ) // Safety
       
  1215         {
       
  1216         CFSEmailUiSendAttachmentsListVisualiser* attachmentView =
       
  1217             static_cast<CFSEmailUiSendAttachmentsListVisualiser*>(
       
  1218                 iAvkonViewAppUi->View( SendAttachmentMngrViewId ) );
       
  1219         attachmentControl = static_cast<CFreestyleEmailUiSendAttachmentsListControl*>(
       
  1220             attachmentView->ViewerControl() );
       
  1221         }
       
  1222 	return attachmentControl;
       
  1223 	}
       
  1224 
       
  1225 // -----------------------------------------------------------------------------
       
  1226 // CNcsComposeView::ProcessCommandL()
       
  1227 // -----------------------------------------------------------------------------
       
  1228 //
       
  1229 void CNcsComposeView::ProcessCommandL( TInt aCommand )
       
  1230     {
       
  1231     FUNC_LOG;
       
  1232 
       
  1233     // Block all the commands while we are exiting
       
  1234     if ( !iExecutingDoExitL )
       
  1235         {
       
  1236         CFsEmailUiViewBase::ProcessCommandL( aCommand );
       
  1237         }
       
  1238     }
       
  1239 
       
  1240 // -----------------------------------------------------------------------------
       
  1241 // CNcsComposeView::HandleActivationCommandL()
       
  1242 //
       
  1243 // -----------------------------------------------------------------------------
       
  1244 //
       
  1245 void CNcsComposeView::HandleActivationCommandL( TUid aCustomMessageId )
       
  1246     {
       
  1247     FUNC_LOG;
       
  1248     // Called from doactivate in which case first start is completed
       
  1249     iMailFetchingErrCode = KErrNone;
       
  1250 
       
  1251     if ( aCustomMessageId == TUid::Uid( KEditorCmdCreateNew ) )
       
  1252         {
       
  1253         iOrigMessage = NULL;
       
  1254         iFakeSyncGoingOn = ETrue;//<cmail> this is actually a waited async method
       
  1255         iNewMessage = iMailBox->CreateMessageToSend();
       
  1256         iFakeSyncGoingOn = EFalse;
       
  1257         if ( !iNewMessage )
       
  1258             {
       
  1259             User::Leave( KErrGeneral );
       
  1260             }
       
  1261         iFakeSyncGoingOn = ETrue;
       
  1262         TFsEmailUiUtility::MoveMessageToDraftsL( *iMailBox, *iNewMessage );
       
  1263         iFakeSyncGoingOn = EFalse;//<cmail>
       
  1264         
       
  1265         if ( iNewMessage->GetContentType() != KFSMailContentTypeMultipartMixed )
       
  1266             {
       
  1267             iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
       
  1268             iNewMessage->SaveMessageL();
       
  1269             }
       
  1270         
       
  1271         TFsEmailUiUtility::CreatePlainTextPartL( *iNewMessage, iNewMessageTextPart );
       
  1272         IncludeMessageTextL( ETrue );
       
  1273         AttachmentsListControl()->Model()->Clear();
       
  1274         iContainer->SelectAllToFieldTextL();
       
  1275         }
       
  1276     else if ( aCustomMessageId == TUid::Uid( KEditorCmdReply ) ||
       
  1277               aCustomMessageId == TUid::Uid( KEditorCmdReplyAll ) )
       
  1278         {
       
  1279 
       
  1280         iOrigMessage = iMailClient.GetMessageByUidL( iLaunchParams.iMailboxId, iLaunchParams.iFolderId, iLaunchParams.iMsgId, EFSMsgDataStructure );
       
  1281         if ( !iOrigMessage )
       
  1282             {
       
  1283             User::Leave( KErrNotFound );
       
  1284             }
       
  1285 
       
  1286         SafeDelete( iFetchLogic );
       
  1287         iFetchLogic = CFsComposerFetchLogic::NewL( iMailClient, iLaunchParams.iMailboxId,
       
  1288                 iOrigMessage->GetFolderId(), iLaunchParams.iMsgId, *this, iAppUi );
       
  1289         ShowFetchingWaitNoteL();
       
  1290         iFetchLogic->RunReplyLogicL();
       
  1291 
       
  1292         // now fetch logic object runs its tasks and gives callback
       
  1293         // to CNcsComposeView::FetchLogicComplete when it is finished
       
  1294         }
       
  1295     else if ( aCustomMessageId == TUid::Uid( KEditorCmdForward ) )
       
  1296         {
       
  1297 
       
  1298         iOrigMessage = iMailClient.GetMessageByUidL( iLaunchParams.iMailboxId, iLaunchParams.iFolderId, iLaunchParams.iMsgId, EFSMsgDataStructure );
       
  1299         if ( !iOrigMessage )
       
  1300             {
       
  1301             User::Leave( KErrNotFound );
       
  1302             }
       
  1303 
       
  1304         SafeDelete( iFetchLogic );
       
  1305         iFetchLogic = CFsComposerFetchLogic::NewL( iMailClient, iLaunchParams.iMailboxId,
       
  1306                                                    iOrigMessage->GetFolderId(), iLaunchParams.iMsgId, *this, iAppUi );
       
  1307         ShowFetchingWaitNoteL();
       
  1308         iFetchLogic->RunForwardLogicL();
       
  1309 
       
  1310         // now fetch logic object runs its tasks and gives callback
       
  1311         // to CNcsComposeView::FetchLogicComplete when it is finished
       
  1312         }
       
  1313     else if ( aCustomMessageId == TUid::Uid( KEditorCmdOpen ) ||
       
  1314               aCustomMessageId == TUid::Uid( KEditorCmdReturnToPrevious ) ) // for now, we handle returning from attachments list just like any message opening
       
  1315         {
       
  1316 
       
  1317         iNewMessage = iMailClient.GetMessageByUidL( iLaunchParams.iMailboxId, iLaunchParams.iFolderId, iLaunchParams.iMsgId, EFSMsgDataStructure );
       
  1318         if ( !iNewMessage )
       
  1319             {
       
  1320             User::Leave( KErrNotFound );
       
  1321             }
       
  1322 
       
  1323         // Show "Opening" wait note if the message body is large
       
  1324         TInt waitNoteId = KErrNotFound;
       
  1325         if ( TFsEmailUiUtility::IsMessageBodyLargeL(iNewMessage) )
       
  1326             {
       
  1327             waitNoteId = TFsEmailUiUtility::ShowGlobalWaitNoteLC( R_FSE_WAIT_OPENING_TEXT );
       
  1328             }
       
  1329 
       
  1330         iOrigMessage = NULL;
       
  1331         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
       
  1332         iNewMessage->SaveMessageL();
       
  1333         TFsEmailUiUtility::CreatePlainTextPartL( *iNewMessage, iNewMessageTextPart );
       
  1334         InitFieldsL();
       
  1335         IncludeMessageTextL();
       
  1336         AttachmentsListControl()->Model()->Clear();
       
  1337         GetAttachmentsFromMailL();
       
  1338         SetAttachmentLabelContentL();
       
  1339         iAttachmentListSaveDraft = ETrue;
       
  1340 
       
  1341         // Close the "Opening" wait note if it was shown
       
  1342         if ( waitNoteId != KErrNotFound )
       
  1343             {
       
  1344             CleanupStack::PopAndDestroy( (TAny*)waitNoteId );
       
  1345             }
       
  1346         }
       
  1347     else if ( aCustomMessageId == TUid::Uid( KEditorCmdInternalMailto ) )
       
  1348         {
       
  1349         FUNC_LOG;
       
  1350 
       
  1351         iOrigMessage = NULL;
       
  1352         //<cmail> this is actually a waited async method
       
  1353         iFakeSyncGoingOn = ETrue;
       
  1354         iNewMessage = iMailBox->CreateMessageToSend();
       
  1355         iFakeSyncGoingOn = EFalse;
       
  1356         //</cmail>
       
  1357         if ( !iNewMessage )
       
  1358             {
       
  1359             User::Leave( KErrGeneral );
       
  1360             }
       
  1361         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
       
  1362         iNewMessage->SaveMessageL();
       
  1363 
       
  1364         TFsEmailUiUtility::CreatePlainTextPartL( *iNewMessage, iNewMessageTextPart );
       
  1365 
       
  1366         IncludeMessageTextL( ETrue );
       
  1367 
       
  1368         CFSMailAddress* toAddress = static_cast<CFSMailAddress*>( iLaunchParams.iExtra ); // not owned
       
  1369         RPointerArray<CNcsEmailAddressObject> toRecipients;
       
  1370         CleanupResetAndDestroyClosePushL( toRecipients );
       
  1371         CNcsEmailAddressObject* ncsToAddress = NcsUtility::CreateNcsAddressL( *toAddress );
       
  1372         CleanupStack::PushL( ncsToAddress );
       
  1373         toRecipients.AppendL( ncsToAddress );
       
  1374         CleanupStack::Pop( ncsToAddress ); // owned by toRecipients now
       
  1375         iContainer->SetToFieldAddressesL( toRecipients );
       
  1376         CleanupStack::PopAndDestroy( &toRecipients );
       
  1377 
       
  1378         iContainer->SetFocusToMessageFieldL();
       
  1379         }
       
  1380     }
       
  1381 
       
  1382 // -----------------------------------------------------------------------------
       
  1383 // CNcsComposeView::DoQuickTextL()
       
  1384 //
       
  1385 // -----------------------------------------------------------------------------
       
  1386 //
       
  1387 void CNcsComposeView::DoQuickTextL()
       
  1388     {
       
  1389     FUNC_LOG;
       
  1390 
       
  1391     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
       
  1392 
       
  1393 	HBufC* title = iEikonEnv->AllocReadResourceLC( R_NCS_QUICK_TEXT_TITLE_TEXT );
       
  1394 	HBufC* buf(0);
       
  1395 	TRAPD( err, buf = CNotepadApi::FetchTemplateL( title ) );
       
  1396 	if (err == KLeaveExit)
       
  1397 		{ //If end key was pressed the dialog leaves with the above error code.
       
  1398 			//In that case we must leave as well or the application will become stuck
       
  1399 			//as the exit will be incomplete.
       
  1400 			User::Leave(err);
       
  1401 		}
       
  1402 		
       
  1403 	if ( buf && err == KErrNone ) // Safety check, 0 if user cancel
       
  1404 		{
       
  1405 		CleanupStack::PushL( buf );
       
  1406 		iContainer->AddQuickTextL( *buf );
       
  1407 		CleanupStack::PopAndDestroy( buf );
       
  1408 		}
       
  1409 	CleanupStack::PopAndDestroy( title );
       
  1410 
       
  1411     }
       
  1412 
       
  1413 // -----------------------------------------------------------------------------
       
  1414 // CNcsComposeView::HandleDynamicVariantSwitchL()
       
  1415 //
       
  1416 // -----------------------------------------------------------------------------
       
  1417 //
       
  1418 void CNcsComposeView::HandleDynamicVariantSwitchL(
       
  1419     CFsEmailUiViewBase::TDynamicSwitchType aType )
       
  1420 	{
       
  1421     FUNC_LOG;
       
  1422 
       
  1423     if ( iFirstStartCompleted && iContainer )
       
  1424         {
       
  1425         if ( aType == CFsEmailUiViewBase::EScreenLayoutChanged )
       
  1426             {
       
  1427             iContainer->HandleLayoutChangeL();
       
  1428             }
       
  1429         else if ( aType == CFsEmailUiViewBase::ESkinChanged )
       
  1430             {
       
  1431             iContainer->HandleSkinChangeL();
       
  1432             }
       
  1433         else
       
  1434             {
       
  1435             }
       
  1436         }
       
  1437 
       
  1438 	}
       
  1439 
       
  1440 // -----------------------------------------------------------------------------
       
  1441 // CNcsComposeView::InitReplyFieldsL()
       
  1442 // Initialises the reply fields from the reply message created by the plug-in.
       
  1443 // -----------------------------------------------------------------------------
       
  1444 //
       
  1445 void CNcsComposeView::InitReplyFieldsL( TBool /*aReplyAll*/ )
       
  1446     {
       
  1447     FUNC_LOG;
       
  1448 
       
  1449     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
       
  1450 
       
  1451     // Get TO recipients
       
  1452     RPointerArray<CFSMailAddress>& toRecipients = iNewMessage->GetToRecipients();
       
  1453     RPointerArray<CNcsEmailAddressObject> recipients;
       
  1454     CleanupResetAndDestroyClosePushL( recipients );
       
  1455     NcsUtility::ConvertAddressArrayL( toRecipients, recipients );
       
  1456     iContainer->SetToFieldAddressesL( recipients );
       
  1457     CleanupStack::PopAndDestroy( &recipients );
       
  1458 
       
  1459     // Get CC recipients
       
  1460     RPointerArray<CFSMailAddress>& ccRecipients = iNewMessage->GetCCRecipients();
       
  1461     NcsUtility::ConvertAddressArrayL( ccRecipients, recipients );
       
  1462     iContainer->SetCcFieldAddressesL( recipients );
       
  1463     recipients.ResetAndDestroy();
       
  1464 
       
  1465     // Get BCC recipients
       
  1466     RPointerArray<CFSMailAddress>& bccRecipients = iNewMessage->GetBCCRecipients();
       
  1467     NcsUtility::ConvertAddressArrayL( bccRecipients, recipients );
       
  1468     iContainer->SetBccFieldAddressesL( recipients );
       
  1469     recipients.ResetAndDestroy();
       
  1470 
       
  1471     // Get subject line from original message
       
  1472     HBufC* prefix = StringLoader::LoadLC( R_NCS_ENGINE_EMAIL_REPLY_PREFIX );
       
  1473     HBufC* formattedSubject = NcsUtility::FormatSubjectLineL(
       
  1474         iOrigMessage->GetSubject(), *prefix );
       
  1475     CleanupStack::PushL( formattedSubject );
       
  1476     iContainer->SetSubjectL( *formattedSubject );
       
  1477     CleanupStack::PopAndDestroy( formattedSubject );
       
  1478     CleanupStack::PopAndDestroy( prefix );
       
  1479 
       
  1480     // clear attachments
       
  1481     AttachmentsListControl()->Model()->Clear();
       
  1482 
       
  1483     }
       
  1484 
       
  1485 // -----------------------------------------------------------------------------
       
  1486 // CNcsComposeView::RemoveOwnAddress()
       
  1487 //
       
  1488 // -----------------------------------------------------------------------------
       
  1489 //
       
  1490 void CNcsComposeView::RemoveOwnAddress( RPointerArray<CNcsEmailAddressObject>& aAddressList )
       
  1491     {
       
  1492     FUNC_LOG;
       
  1493     TInt index = 0;
       
  1494     TDesC& ownAddress( iMailBox->OwnMailAddress().GetEmailAddress() );
       
  1495 	while ( index < aAddressList.Count() )
       
  1496         {
       
  1497         if ( !aAddressList[index]->EmailAddress().CompareC(ownAddress) )
       
  1498             {
       
  1499             // The entry will be removed from the arry.
       
  1500             aAddressList.Remove(index);
       
  1501             break;
       
  1502             }
       
  1503         index++;
       
  1504         }
       
  1505     }
       
  1506 
       
  1507 // -----------------------------------------------------------------------------
       
  1508 // CNcsComposeView::IncludeMessageTextL()
       
  1509 //
       
  1510 // -----------------------------------------------------------------------------
       
  1511 //
       
  1512 void CNcsComposeView::IncludeMessageTextL( TBool aEnsureSpaceInBegin /*= EFalse*/ )
       
  1513 	{
       
  1514     FUNC_LOG;
       
  1515 
       
  1516     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
       
  1517 
       
  1518     HBufC* body = NULL;
       
  1519     HBufC* rawBody = GetMessageBodyL();
       
  1520     CleanupStack::PushL( rawBody );
       
  1521 
       
  1522     // Ensure there's free space in the beginning of the message if required
       
  1523     if ( aEnsureSpaceInBegin && rawBody->Length() )
       
  1524         {
       
  1525         TText firstChar = (*rawBody)[0];
       
  1526         _LIT( KNewLines, "\r\n\x2028\x2029" );
       
  1527         if ( KNewLines().Locate( firstChar ) == KErrNotFound )
       
  1528             {
       
  1529             // First character is not a new line character. Insert one.
       
  1530             body = HBufC::NewL( rawBody->Length() + KIMSLineFeed().Length() );
       
  1531             TPtr ptr = body->Des();
       
  1532             ptr.Append( KIMSLineFeed );
       
  1533             ptr.Append( *rawBody );
       
  1534             CleanupStack::PopAndDestroy( rawBody );
       
  1535             rawBody = NULL;
       
  1536             CleanupStack::PushL( body );
       
  1537             }
       
  1538         }
       
  1539     // If no modifications were needed, then just set body pointer to point the rawBody
       
  1540     if ( !body )
       
  1541         {
       
  1542         body = rawBody;
       
  1543         rawBody = NULL;
       
  1544         }
       
  1545     // Now we have possibly decorated message text in body pointer and in cleanup stack
       
  1546 
       
  1547     // Divide the contents into normal body field and the read-only quote field
       
  1548     TInt readOnlyLength = iNewMessageTextPart->ReadOnlyPartSize() / 2; // convert bytes to words
       
  1549     TInt modifiableLength = body->Length() - readOnlyLength;
       
  1550 
       
  1551     // Remove one newline from the end of the modifiable body if there's read-only quote present.
       
  1552     // This is because the field boundary appears as newline on the screen. This newline
       
  1553     // is added back when saving the message.
       
  1554     TInt lfLength = KIMSLineFeed().Length();
       
  1555     if ( readOnlyLength && modifiableLength >= lfLength &&
       
  1556          body->Mid( modifiableLength-lfLength, lfLength ) == KIMSLineFeed )
       
  1557         {
       
  1558         modifiableLength -= lfLength;
       
  1559         }
       
  1560 
       
  1561     iContainer->SetBodyContentL( body->Left( modifiableLength ),
       
  1562         body->Right( readOnlyLength ) );
       
  1563 
       
  1564     CleanupStack::PopAndDestroy( body );
       
  1565     }
       
  1566 
       
  1567 // -----------------------------------------------------------------------------
       
  1568 // CNcsComposeView::InitForwardFieldsL()
       
  1569 //
       
  1570 // -----------------------------------------------------------------------------
       
  1571 //
       
  1572 void CNcsComposeView::InitForwardFieldsL()
       
  1573 	{
       
  1574     FUNC_LOG;
       
  1575 
       
  1576     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
       
  1577 
       
  1578 	// set subject
       
  1579 	HBufC* prefix = StringLoader::LoadLC( R_NCS_ENGINE_EMAIL_FORWARD_PREFIX );
       
  1580 	HBufC* formattedSubject = NcsUtility::FormatSubjectLineL( iOrigMessage->GetSubject(), *prefix );
       
  1581 	CleanupStack::PushL( formattedSubject );
       
  1582 	iContainer->SetSubjectL( *formattedSubject );
       
  1583 	CleanupStack::PopAndDestroy( formattedSubject );
       
  1584 	CleanupStack::PopAndDestroy( prefix );
       
  1585 
       
  1586     // attachments
       
  1587 	AttachmentsListControl()->Model()->Clear();
       
  1588 	// <cmail>
       
  1589 	TInt error = KErrNone;
       
  1590 	TRAP( error, GetAttachmentsFromMailL() );
       
  1591 	// </cmail>
       
  1592 	SetAttachmentLabelContentL();
       
  1593 
       
  1594 	}
       
  1595 
       
  1596 // -----------------------------------------------------------------------------
       
  1597 // CNcsComposeView::SetPriority()
       
  1598 //
       
  1599 // -----------------------------------------------------------------------------
       
  1600 //
       
  1601 void CNcsComposeView::SetPriority()
       
  1602     {
       
  1603     FUNC_LOG;
       
  1604 
       
  1605     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
       
  1606 
       
  1607     if ( iNewMessage && iNewMessage->IsFlagSet( EFSMsgFlag_Important ) )
       
  1608         {
       
  1609         iStatusPaneIndicators->SetPriorityFlag( EMsgPriorityHigh );
       
  1610         }
       
  1611     else if ( iNewMessage && iNewMessage->IsFlagSet( EFSMsgFlag_Low ) )
       
  1612         {
       
  1613         iStatusPaneIndicators->SetPriorityFlag( EMsgPriorityLow );
       
  1614         }
       
  1615     }
       
  1616 
       
  1617 // -----------------------------------------------------------------------------
       
  1618 // Sets follow-up flags to status pane indicators
       
  1619 // -----------------------------------------------------------------------------
       
  1620 //
       
  1621 void CNcsComposeView::SetFollowUp()
       
  1622     {
       
  1623     if ( iNewMessage && iStatusPaneIndicators )
       
  1624         {
       
  1625         if ( iNewMessage->IsFlagSet( EFSMsgFlag_FollowUp ) )
       
  1626             {
       
  1627             iStatusPaneIndicators->SetFollowUpFlag(
       
  1628                 CCustomStatuspaneIndicators::EFollowUp );
       
  1629             }
       
  1630         else if ( iNewMessage->IsFlagSet( EFSMsgFlag_FollowUpComplete ) )
       
  1631             {
       
  1632             iStatusPaneIndicators->SetFollowUpFlag(
       
  1633                 CCustomStatuspaneIndicators::EFollowUpComplete );
       
  1634             }
       
  1635         }
       
  1636     }
       
  1637 
       
  1638 // -----------------------------------------------------------------------------
       
  1639 // CNcsComposeView::InitFieldsL()
       
  1640 //
       
  1641 // -----------------------------------------------------------------------------
       
  1642 //
       
  1643 void CNcsComposeView::InitFieldsL()
       
  1644 	{
       
  1645     FUNC_LOG;
       
  1646 
       
  1647     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
       
  1648 
       
  1649 	// to
       
  1650  	RPointerArray<CFSMailAddress>& toRecipients = iNewMessage->GetToRecipients();
       
  1651 	RPointerArray<CNcsEmailAddressObject> ncsToRecipients;
       
  1652 	CleanupResetAndDestroyClosePushL( ncsToRecipients );
       
  1653 	NcsUtility::ConvertAddressArrayL( toRecipients, ncsToRecipients );
       
  1654  	iContainer->SetToFieldAddressesL( ncsToRecipients );
       
  1655     CleanupStack::PopAndDestroy( &ncsToRecipients );
       
  1656 
       
  1657 	// cc
       
  1658  	RPointerArray<CFSMailAddress>& ccRecipients = iNewMessage->GetCCRecipients();
       
  1659 	RPointerArray<CNcsEmailAddressObject> ncsCcRecipients;
       
  1660     CleanupResetAndDestroyClosePushL( ncsCcRecipients );
       
  1661 	NcsUtility::ConvertAddressArrayL( ccRecipients, ncsCcRecipients );
       
  1662  	iContainer->SetCcFieldAddressesL( ncsCcRecipients );
       
  1663     CleanupStack::PopAndDestroy( &ncsCcRecipients );
       
  1664 
       
  1665 	// bcc
       
  1666  	RPointerArray<CFSMailAddress>& bccRecipients = iNewMessage->GetBCCRecipients();
       
  1667 	RPointerArray<CNcsEmailAddressObject> ncsBccRecipients;
       
  1668     CleanupResetAndDestroyClosePushL( ncsBccRecipients );
       
  1669 	NcsUtility::ConvertAddressArrayL( bccRecipients, ncsBccRecipients );
       
  1670  	iContainer->SetBccFieldAddressesL( ncsBccRecipients );
       
  1671     CleanupStack::PopAndDestroy( &ncsBccRecipients );
       
  1672 
       
  1673 	// set subject line
       
  1674 	iContainer->SetSubjectL( iNewMessage->GetSubject() );
       
  1675 
       
  1676 	}
       
  1677 
       
  1678 // -----------------------------------------------------------------------------
       
  1679 // CNcsComposeView::GetMessageBodyL()
       
  1680 //
       
  1681 // -----------------------------------------------------------------------------
       
  1682 //
       
  1683 HBufC* CNcsComposeView::GetMessageBodyL()
       
  1684 	{
       
  1685     FUNC_LOG;
       
  1686 
       
  1687     __ASSERT_DEBUG( iNewMessageTextPart, Panic( ENcsBasicUi ) );
       
  1688 
       
  1689     TInt messageSize = iNewMessageTextPart->FetchedContentSize();
       
  1690 
       
  1691     HBufC* data = NULL;
       
  1692 
       
  1693     if ( messageSize > 0 )
       
  1694         {
       
  1695         // fetch message body if there is something to fetch
       
  1696         data = HBufC::NewLC( messageSize );
       
  1697         TPtr dataPtr = data->Des();
       
  1698         iNewMessageTextPart->GetContentToBufferL( dataPtr, 0 );
       
  1699         CleanupStack::Pop( data );
       
  1700         }
       
  1701     else
       
  1702         {
       
  1703         data = KNullDesC().AllocL();
       
  1704         }
       
  1705 
       
  1706 	return data;
       
  1707 	}
       
  1708 
       
  1709 // -----------------------------------------------------------------------------
       
  1710 // CNcsComposeView::CommitL()
       
  1711 //
       
  1712 // -----------------------------------------------------------------------------
       
  1713 //
       
  1714 void CNcsComposeView::CommitL( TBool aParseAddresses, TFieldToCommit aFieldToCommit )
       
  1715     {
       
  1716     FUNC_LOG;
       
  1717     __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
       
  1718 	__ASSERT_DEBUG( iNewMessageTextPart, Panic( ENcsBasicUi ) );
       
  1719 
       
  1720 	TBool commitToField = EFalse;
       
  1721 	TBool commitCcField = EFalse;
       
  1722 	TBool commitBccField = EFalse;
       
  1723 	TBool commitSubjectField = EFalse;
       
  1724 	TBool commitBodyField = EFalse;
       
  1725 
       
  1726 	switch ( aFieldToCommit )
       
  1727 	    {
       
  1728 	    case EAllFields:
       
  1729 	        commitToField = ETrue;
       
  1730 	        commitCcField = ETrue;
       
  1731 	        commitBccField = ETrue;
       
  1732 	        commitSubjectField = ETrue;
       
  1733 	        commitBodyField = ETrue;
       
  1734 	        break;
       
  1735 	    case EToField:
       
  1736             commitToField = ETrue;
       
  1737 	        break;
       
  1738 	    case ECcField:
       
  1739             commitCcField = ETrue;
       
  1740 	        break;
       
  1741 	    case EBccField:
       
  1742             commitBccField = ETrue;
       
  1743 	        break;
       
  1744         case EBodyField:
       
  1745             commitBodyField = ETrue;
       
  1746             break;
       
  1747         case ESubjectField:
       
  1748             commitSubjectField = ETrue;
       
  1749             break;
       
  1750 	    default:
       
  1751 	        break;
       
  1752 	    }
       
  1753 
       
  1754 	if ( commitToField )
       
  1755 		{
       
  1756 	    // get addresses from UI to MSG object
       
  1757 	    RPointerArray<CFSMailAddress> toAddresses;
       
  1758 	    CleanupResetAndDestroyClosePushL( toAddresses );
       
  1759 	    NcsUtility::ConvertAddressArrayL( iContainer->GetToFieldAddressesL( aParseAddresses ), toAddresses );
       
  1760 	    iNewMessage->GetToRecipients().ResetAndDestroy();
       
  1761 	    for ( TInt i = 0 ; i < toAddresses.Count() ; i++ )
       
  1762 	    	{
       
  1763 	    	iNewMessage->AppendToRecipient( toAddresses[i] );
       
  1764 	        // Ownership of the message pointer was transferred from our array to iNewMessage
       
  1765 	        toAddresses[i] = NULL;
       
  1766 	    	}
       
  1767 	    CleanupStack::PopAndDestroy( &toAddresses );
       
  1768 		}
       
  1769 
       
  1770 	if ( commitCcField )
       
  1771 		{
       
  1772 	    RPointerArray<CFSMailAddress> ccAddresses;
       
  1773 	    CleanupResetAndDestroyClosePushL( ccAddresses );
       
  1774 	    NcsUtility::ConvertAddressArrayL( iContainer->GetCcFieldAddressesL( aParseAddresses ), ccAddresses );
       
  1775 	    iNewMessage->GetCCRecipients().ResetAndDestroy();
       
  1776 	    for ( TInt i = 0 ; i < ccAddresses.Count() ; i++ )
       
  1777 	    	{
       
  1778 	    	iNewMessage->AppendCCRecipient( ccAddresses[i] );
       
  1779 	        // Ownership of the message pointer was transferred from our array to iNewMessage
       
  1780 	        ccAddresses[i] = NULL;
       
  1781 	    	}
       
  1782 	    CleanupStack::PopAndDestroy( &ccAddresses );
       
  1783 		}
       
  1784 
       
  1785 	if ( commitBccField )
       
  1786 		{
       
  1787 	    RPointerArray<CFSMailAddress> bccAddresses;
       
  1788 	    CleanupResetAndDestroyClosePushL( bccAddresses );
       
  1789 	    NcsUtility::ConvertAddressArrayL( iContainer->GetBccFieldAddressesL( aParseAddresses ), bccAddresses );
       
  1790 	    iNewMessage->GetBCCRecipients().ResetAndDestroy();
       
  1791 	    for ( TInt i = 0; i < bccAddresses.Count() ; i++ )
       
  1792 	    	{
       
  1793 	    	iNewMessage->AppendBCCRecipient( bccAddresses[i] );
       
  1794 	        // Ownership of the message pointer was transferred from our array to iNewMessage
       
  1795 	        bccAddresses[i] = NULL;
       
  1796 	    	}
       
  1797 	    CleanupStack::PopAndDestroy( &bccAddresses );
       
  1798 		}
       
  1799 
       
  1800 	if ( commitSubjectField )
       
  1801 	    {
       
  1802 	    // get subject from UI to MSG object
       
  1803 	    HBufC* subject = iContainer->GetSubjectLC();
       
  1804 	    TPtr ptr = subject->Des();
       
  1805 		// replace new line characters with spaces as Subject is normally one line only
       
  1806 	    AknTextUtils::ReplaceCharacters( ptr, KLineSeparators, KReplacementChar );
       
  1807 	    iNewMessage->SetSubject( *subject );
       
  1808 	    CleanupStack::PopAndDestroy( subject );
       
  1809 	    }
       
  1810 
       
  1811     if ( commitBodyField )
       
  1812         {
       
  1813         HBufC* body = iContainer->GetBodyContentLC();
       
  1814         TPtr bodyPtr = body->Des(); // this TPtr is needed only because of incorrect argument type in FW API, can be removed when API fixed
       
  1815         iNewMessageTextPart->SetContent( bodyPtr );
       
  1816         CleanupStack::PopAndDestroy( body );
       
  1817 
       
  1818         TInt error = KErrNone;
       
  1819         if ( iNewMessageTextPart )
       
  1820             {
       
  1821             TRAP( error, iNewMessageTextPart->SaveL() );
       
  1822             }
       
  1823         }
       
  1824 
       
  1825 	// Save message if at least one field committed
       
  1826     if ( iNewMessage || commitToField || commitCcField || commitBccField
       
  1827         || commitSubjectField || commitBodyField )
       
  1828         {
       
  1829         TInt error = KErrNone;
       
  1830         TRAP( error, iNewMessage->SaveMessageL() );
       
  1831         RefreshToolbar();
       
  1832         }
       
  1833     }
       
  1834 
       
  1835 // -----------------------------------------------------------------------------
       
  1836 // CNcsComposeView::DoSafeExit
       
  1837 // -----------------------------------------------------------------------------
       
  1838 void CNcsComposeView::DoSafeExit( TExitMode aMode )
       
  1839     {
       
  1840     FUNC_LOG;
       
  1841 
       
  1842     if ( !iExecutingDoExitL )
       
  1843         {
       
  1844         iExecutingDoExitL = ETrue;
       
  1845         TRAP_IGNORE( DoExitL( aMode ) );
       
  1846         iExecutingDoExitL = EFalse;
       
  1847         }
       
  1848     }
       
  1849 
       
  1850 
       
  1851 // -----------------------------------------------------------------------------
       
  1852 // CNcsComposeView::DoExitL
       
  1853 // -----------------------------------------------------------------------------
       
  1854 void CNcsComposeView::DoExitL( TExitMode aMode )
       
  1855     {
       
  1856     FUNC_LOG;
       
  1857 
       
  1858     //<cmail>
       
  1859     TBool emptyMessage = ETrue;
       
  1860 
       
  1861     if ( iAutoSaver && iContainer )
       
  1862         {
       
  1863         iAutoSaver->Enable( EFalse );
       
  1864 
       
  1865         // check that there's some user input in some header field or in message body
       
  1866     	TInt attaCount = AttachmentsListControl()->Model()->Count();
       
  1867         emptyMessage =  iContainer->AreAddressFieldsEmpty() &&
       
  1868             iContainer->IsSubjectFieldEmpty() &&
       
  1869             iContainer->GetMessageFieldLength() < 1 &&
       
  1870             attaCount <= 0;
       
  1871 	    }
       
  1872     //</cmail>
       
  1873 
       
  1874     // Consider saving the draft if the message is not completely empty
       
  1875     if ( !emptyMessage )
       
  1876         {
       
  1877         if ( aMode == ESaveDraftQuery && !iMailSent && !iMailSendFailed )
       
  1878             {
       
  1879             TBool actionSucceeded = EFalse;
       
  1880 
       
  1881             // DoSaveDraftL returns EFalse if the user query was cancelled or saving to Drafts failed
       
  1882             TRAPD( saveDraftError, actionSucceeded = DoSaveDraftL( ETrue ) );
       
  1883             if ( saveDraftError == KErrNone )
       
  1884                 {
       
  1885                 if ( !actionSucceeded )
       
  1886                     {
       
  1887                     // return to normal action (cancel was pressed in the query)
       
  1888                     iAutoSaver->Enable( ETrue );
       
  1889                     return;
       
  1890                     }
       
  1891                 }
       
  1892             else
       
  1893                 {
       
  1894                 }
       
  1895             }
       
  1896         else if ( aMode == ESaveDraft )
       
  1897             {
       
  1898             DoSaveDraftL( EFalse );
       
  1899             }
       
  1900         }
       
  1901     else if ( iNewMessage ) // <cmail> message is empty; delete the draft if it has been already saved earlier
       
  1902         {
       
  1903         TInt err = NcsUtility::DeleteMessage( iMailClient, iMailBox->GetId(),
       
  1904             iNewMessage->GetFolderId(), iNewMessage->GetMessageId() );
       
  1905         if ( !err && iMailBox->HasCapability( EFSMBoxCapaSupportsDeletedItemsFolder ) )
       
  1906             {
       
  1907             err = NcsUtility::DeleteMessage( iMailClient, iMailBox->GetId(),
       
  1908                 iMailBox->GetStandardFolderId( EFSDeleted ),
       
  1909                 iNewMessage->GetMessageId() );
       
  1910             }
       
  1911 
       
  1912         if ( !err && !iAppUi.AppUiExitOngoing() )
       
  1913             {
       
  1914             // Simulate delete event so that drafts folder is
       
  1915             // updated correctly.
       
  1916             RArray<TFSMailMsgId> messageIds;
       
  1917             CleanupClosePushL( messageIds );
       
  1918             messageIds.AppendL( iNewMessage->GetMessageId() );
       
  1919             TFSMailMsgId folderId = iNewMessage->GetFolderId();
       
  1920             TFSMailMsgId mailboxId = iNewMessage->GetMailBoxId();
       
  1921             iAppUi.EventL( TFSEventMailDeleted,
       
  1922                 mailboxId, &messageIds, &folderId, NULL );
       
  1923             CleanupStack::PopAndDestroy( &messageIds );
       
  1924             }
       
  1925         }
       
  1926 
       
  1927     // <cmail>
       
  1928     // Clear attachment control now that message has been sent
       
  1929     // othewise this will kind of leak memory by leaving attachments
       
  1930     // in the list, even if they have been sent.
       
  1931     CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
       
  1932     attachmentControl = AttachmentsListControl();
       
  1933     if ( attachmentControl && attachmentControl->Model() )
       
  1934         {
       
  1935         attachmentControl->Model()->Clear();
       
  1936         }
       
  1937     // </cmail>
       
  1938 
       
  1939     ExitComposer();
       
  1940 
       
  1941     }
       
  1942 
       
  1943 // -----------------------------------------------------------------------------
       
  1944 // CNcsComposeView::DoOpenAttachmentList
       
  1945 // Saves current editor message to drafts and opens attachment list view
       
  1946 // -----------------------------------------------------------------------------
       
  1947 void CNcsComposeView::DoOpenAttachmentListL()
       
  1948 	{
       
  1949     FUNC_LOG;
       
  1950 
       
  1951     CFreestyleEmailUiSendAttachmentsListControl* attachmentControl
       
  1952    		= AttachmentsListControl();
       
  1953 
       
  1954    	if ( attachmentControl->Model()->Count() == 1 )
       
  1955    		{
       
  1956 		CFSEmailUiSendAttachmentsListModelItem* item =
       
  1957 			static_cast<CFSEmailUiSendAttachmentsListModelItem*>(
       
  1958 					attachmentControl->Model()->Item( 0 ) );
       
  1959 		if ( !item->IsRemote() ) // we cannot open remote attachments
       
  1960 		    {
       
  1961     		CFSMailMessagePart* msgPart = iNewMessage->ChildPartL( item->MailMsgPartId() );
       
  1962     		CleanupStack::PushL( msgPart );
       
  1963             TFsEmailUiUtility::OpenAttachmentL( *msgPart );
       
  1964     		CleanupStack::PopAndDestroy( msgPart );
       
  1965 		    }
       
  1966    		}
       
  1967    	// open attachment list
       
  1968    	else
       
  1969    		{
       
  1970    		// set current email parameters to package buffer
       
  1971    		TEditorLaunchParams editorParams;
       
  1972    		editorParams.iMailboxId = iNewMessage->GetMailBoxId();
       
  1973    		editorParams.iMsgId = iNewMessage->GetMessageId();
       
  1974    		editorParams.iFolderId = iNewMessage->GetFolderId();
       
  1975    		editorParams.iActivatedExternally = EFalse;
       
  1976    		TPckgBuf<TEditorLaunchParams> buf( editorParams );
       
  1977 
       
  1978    		// save email to drafts
       
  1979    		iAttachmentListSaveDraft = ETrue;
       
  1980    		TRAPD( saveDraftError, DoSaveDraftL( EFalse ) );
       
  1981    		if ( saveDraftError != KErrNone )
       
  1982    		    {
       
  1983    		    // error occured in saving -> show an error message
       
  1984    		    if ( !iAppUi.AppUiExitOngoing() ) //<cmail>
       
  1985    		        TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE, ETrue );
       
  1986    		    return;
       
  1987    		    }
       
  1988 
       
  1989    		// open attachment list view
       
  1990    		iAppUi.EnterFsEmailViewL(
       
  1991             SendAttachmentMngrViewId,
       
  1992             TUid::Uid( KEditorCmdOpenAttachmentsList ),
       
  1993             buf );
       
  1994    		}
       
  1995 
       
  1996 	}
       
  1997 
       
  1998 // -----------------------------------------------------------------------------
       
  1999 // CNcsComposeView::LaunchAttachmentActionMenuL
       
  2000 // Show action menu for the attachments line
       
  2001 // -----------------------------------------------------------------------------
       
  2002 //
       
  2003 void CNcsComposeView::LaunchAttachmentActionMenuL()
       
  2004     {
       
  2005     FUNC_LOG;
       
  2006 
       
  2007     // Remove old items from action menu
       
  2008     CFSEmailUiActionMenu::RemoveAllL();
       
  2009 
       
  2010     // Construct item list
       
  2011     RFsEActionMenuIdList itemList;
       
  2012     CleanupClosePushL( itemList );
       
  2013 
       
  2014     CFreestyleEmailUiSendAttachmentsListControl* attachmentControl =
       
  2015         AttachmentsListControl();
       
  2016     TInt count = attachmentControl->Model()->Count();
       
  2017     TBool remoteAtt = AttachmentsListControl()->Model()->HasRemoteAttachments();
       
  2018     TBool readOnlyAtt = AttachmentsListControl()->Model()->HasReadOnlyAttachments();
       
  2019 
       
  2020     // Open/View all
       
  2021     if ( count == 1 && !remoteAtt )
       
  2022         {
       
  2023         itemList.AppendL( FsEActionAttachmentOpen );
       
  2024         }
       
  2025     else if ( count > 1 )
       
  2026         {
       
  2027         itemList.AppendL( FsEActionAttachmentViewAll );
       
  2028         }
       
  2029 
       
  2030     // Add
       
  2031     itemList.AppendL( FsEActionAttachmentAdd );
       
  2032 
       
  2033     // Remove/Remove all
       
  2034     if ( !readOnlyAtt )
       
  2035         {
       
  2036         if ( count == 1 )
       
  2037             {
       
  2038             itemList.AppendL( FsEActionAttachmentRemove );
       
  2039             }
       
  2040         else if ( count > 1 )
       
  2041             {
       
  2042             itemList.AppendL( FsEActionAttachmentRemoveAll );
       
  2043             }
       
  2044         }
       
  2045 
       
  2046     // Execute action list
       
  2047     TActionMenuCustomItemId itemId = CFSEmailUiActionMenu::ExecuteL( itemList );
       
  2048     CleanupStack::PopAndDestroy( &itemList );
       
  2049 
       
  2050     // Handle action menu selection
       
  2051     switch ( itemId )
       
  2052         {
       
  2053         case FsEActionAttachmentOpen:
       
  2054             HandleCommandL( EFsEmailUiCmdOpenAttachment );
       
  2055             break;
       
  2056         case FsEActionAttachmentViewAll:
       
  2057             HandleCommandL( EFsEmailUiCmdOpenAttachmentList );
       
  2058             break;
       
  2059         case FsEActionAttachmentRemove:
       
  2060             HandleCommandL( ENcsCmdRemoveAttachment );
       
  2061             break;
       
  2062         case FsEActionAttachmentRemoveAll:
       
  2063             HandleCommandL( ENcsCmdRemoveAllAttachments );
       
  2064             break;
       
  2065         case FsEActionAttachmentAdd:
       
  2066             HandleCommandL( ENcsCmdAddAttachment );
       
  2067             break;
       
  2068         default:
       
  2069             break;
       
  2070         }
       
  2071 
       
  2072     }
       
  2073 
       
  2074 //<cmail>
       
  2075 // -----------------------------------------------------------------------------
       
  2076 // CNcsComposeView::DismissAttachmentActionMenuL
       
  2077 //
       
  2078 // -----------------------------------------------------------------------------
       
  2079 //
       
  2080 void CNcsComposeView::DismissAttachmentActionMenuL()
       
  2081     {
       
  2082     FUNC_LOG;
       
  2083     CFSEmailUiActionMenu::Dismiss( ETrue );
       
  2084     }
       
  2085 //</cmail>
       
  2086 
       
  2087 // -----------------------------------------------------------------------------
       
  2088 // CNcsComposeView::GetAttachmentsFromMail
       
  2089 // -----------------------------------------------------------------------------
       
  2090 void CNcsComposeView::GetAttachmentsFromMailL()
       
  2091 	{
       
  2092     FUNC_LOG;
       
  2093 
       
  2094     TInt error( KErrNone );
       
  2095 
       
  2096 	RPointerArray<CFSMailMessagePart> attachments;
       
  2097     CleanupResetAndDestroyClosePushL( attachments );
       
  2098 	TRAP( error, iNewMessage->AttachmentListL( attachments ) );
       
  2099 	User::LeaveIfError( error );
       
  2100 
       
  2101 	for ( TInt i=0; i<attachments.Count(); ++i )
       
  2102 		{
       
  2103         TFileType fileType = TFsEmailUiUtility::GetFileType( attachments[i]->AttachmentNameL(),
       
  2104                                                              attachments[i]->GetContentType() );
       
  2105 
       
  2106         TBool isReadOnly = ( attachments[i]->ReadOnlyPartSize() > 0 );
       
  2107         TBool isRemote = EFalse;
       
  2108 
       
  2109 		if ( attachments[i]->FetchedContentSize() < attachments[i]->ContentSize() )
       
  2110 			{
       
  2111 			if ( iMailBox->HasCapability( EFSMBoxCapaSmartForward ) )
       
  2112 			    {
       
  2113 			    isRemote = ETrue;
       
  2114 			    }
       
  2115 			else
       
  2116 			    {
       
  2117 	            __ASSERT_DEBUG( EFalse, Panic(EFSEmailUiUnexpectedValue) );
       
  2118 	            User::Leave( KErrNotFound );
       
  2119 	            continue;
       
  2120 			    }
       
  2121 			}
       
  2122 
       
  2123 		AttachmentsListControl()->AppendFileToModelL(
       
  2124 		        attachments[i]->GetPartId(),
       
  2125 		        attachments[i]->AttachmentNameL(),
       
  2126 		        attachments[i]->ContentSize(),
       
  2127 		        fileType,
       
  2128 		        isReadOnly,
       
  2129 		        isRemote );
       
  2130 		}
       
  2131 
       
  2132 	CleanupStack::PopAndDestroy( &attachments );
       
  2133 
       
  2134 	}
       
  2135 
       
  2136 // -----------------------------------------------------------------------------
       
  2137 // CNcsComposeView::FileExistsInModel
       
  2138 // -----------------------------------------------------------------------------
       
  2139 TBool CNcsComposeView::FileExistsInModel( TFSMailMsgId aAttachmentId )
       
  2140 	{
       
  2141     FUNC_LOG;
       
  2142 
       
  2143 	TInt count( AttachmentsListControl()->Model()->Count() );
       
  2144 
       
  2145 	for ( TInt i=0; i < count; ++i )
       
  2146 		{
       
  2147 		CFSEmailUiSendAttachmentsListModelItem* item =
       
  2148 			static_cast<CFSEmailUiSendAttachmentsListModelItem*>(
       
  2149                 AttachmentsListControl()->Model()->Item(i) );
       
  2150 		if ( aAttachmentId.Id() == item->MailMsgPartId().Id() )
       
  2151 			{
       
  2152 			return ETrue;
       
  2153 			}
       
  2154 		}
       
  2155 
       
  2156 	return EFalse;
       
  2157 	}
       
  2158 
       
  2159 // -----------------------------------------------------------------------------
       
  2160 // CNcsComposeView::GenerateReplyHeaderLC
       
  2161 // -----------------------------------------------------------------------------
       
  2162 HBufC* CNcsComposeView::GenerateReplyHeaderLC()
       
  2163 	{
       
  2164     FUNC_LOG;
       
  2165 
       
  2166     __ASSERT_DEBUG( iOrigMessage, Panic( ENcsBasicUi ) );
       
  2167 
       
  2168 	// separator line
       
  2169 	HBufC* separator = StringLoader::LoadLC( R_NCS_ENGINE_EMAIL_MESSAGE_LINE_SEPARATOR ); //1
       
  2170 
       
  2171 	// from line
       
  2172 	RPointerArray<CNcsEmailAddressObject> senderArray;
       
  2173 	CleanupResetAndDestroyClosePushL( senderArray );
       
  2174     CFSMailAddress* sender = iOrigMessage->GetSender();
       
  2175     if ( sender )
       
  2176         {
       
  2177     	CNcsEmailAddressObject* ncsSender = NcsUtility::CreateNcsAddressL( *sender );
       
  2178     	CleanupStack::PushL( ncsSender );
       
  2179 	    senderArray.AppendL( ncsSender );
       
  2180 	    CleanupStack::Pop( ncsSender ); // now owned by senderArray
       
  2181         }
       
  2182 	HBufC* fromLine = NcsUtility::GenerateFromLineToMessageBodyL( senderArray );
       
  2183 	CleanupStack::PopAndDestroy( &senderArray );
       
  2184 	CleanupStack::PushL( fromLine ); //2
       
  2185 
       
  2186 	// sent line
       
  2187 	HBufC* sentLine = NcsUtility::GenerateSentLineToMessageBodyL( *iOrigMessage );
       
  2188 	CleanupStack::PushL( sentLine ); //3
       
  2189 
       
  2190 	// to line
       
  2191 	RPointerArray<CNcsEmailAddressObject> ncsToRecipients;
       
  2192 	CleanupResetAndDestroyClosePushL( ncsToRecipients );
       
  2193 	RPointerArray<CFSMailAddress>& toRecipients = iOrigMessage->GetToRecipients();
       
  2194 	NcsUtility::ConvertAddressArrayL( toRecipients, ncsToRecipients );
       
  2195 	HBufC* toLine = NcsUtility::GenerateAddressLineToMessageBodyL( ncsToRecipients, NcsUtility::ERecipientTypeTo );
       
  2196     CleanupStack::PopAndDestroy( &ncsToRecipients );
       
  2197 	CleanupStack::PushL( toLine ); //4
       
  2198 
       
  2199 	// cc line
       
  2200 	RPointerArray<CFSMailAddress>& ccRecipients = iOrigMessage->GetCCRecipients();
       
  2201 	TBool hasCcLine = ( ccRecipients.Count() > 0 );
       
  2202     HBufC* ccLine = NULL;
       
  2203 	if ( hasCcLine )
       
  2204 		{
       
  2205 	    RPointerArray<CNcsEmailAddressObject> ncsCcRecipients;
       
  2206 	    CleanupResetAndDestroyClosePushL( ncsCcRecipients );
       
  2207 		NcsUtility::ConvertAddressArrayL( ccRecipients, ncsCcRecipients );
       
  2208 		ccLine = NcsUtility::GenerateAddressLineToMessageBodyL( ncsCcRecipients, NcsUtility::ERecipientTypeCc );
       
  2209 	    CleanupStack::PopAndDestroy( &ncsCcRecipients );
       
  2210 		CleanupStack::PushL( ccLine ); //5
       
  2211 		}
       
  2212 
       
  2213 	// subject line
       
  2214 	HBufC* subjectLine = NcsUtility::GenerateSubjectLineToMessageBodyL( iOrigMessage->GetSubject() );
       
  2215 	CleanupStack::PushL( subjectLine ); //6
       
  2216 
       
  2217     // Body
       
  2218     HBufC* body = NULL;
       
  2219     TBool hasBody = EFalse;
       
  2220     CFSMailMessagePart* textBodyPart = iOrigMessage->PlainTextBodyPartL();
       
  2221     if ( textBodyPart )
       
  2222         {
       
  2223         // Plain text body part present, no need
       
  2224         // to generate it from HTML body part
       
  2225         delete textBodyPart;
       
  2226         }
       
  2227     else
       
  2228         {
       
  2229         // Generate body part for reply
       
  2230         CFSMailMessagePart* htmlBodyPart = iOrigMessage->HtmlBodyPartL();
       
  2231         if ( htmlBodyPart )
       
  2232             {
       
  2233             CleanupStack::PushL( htmlBodyPart );
       
  2234 
       
  2235             HBufC* htmlData = HBufC::NewLC( htmlBodyPart->FetchedContentSize() );
       
  2236             TPtr pointer = htmlData->Des();
       
  2237             htmlBodyPart->GetContentToBufferL( pointer, 0 );
       
  2238 
       
  2239             body = TFsEmailUiUtility::ConvertHtmlToTxtL( *htmlData );
       
  2240 
       
  2241             CleanupStack::PopAndDestroy( htmlData );
       
  2242             CleanupStack::PopAndDestroy( htmlBodyPart );
       
  2243 
       
  2244             CleanupStack::PushL( body ); //7
       
  2245 
       
  2246             hasBody = ETrue;
       
  2247             }
       
  2248         }
       
  2249 	// calculate total length
       
  2250 	TInt length = 0;
       
  2251 	length += separator->Length();
       
  2252 	length += KIMSLineFeed().Length();
       
  2253 	length += fromLine->Length();
       
  2254 	length += KIMSLineFeed().Length();
       
  2255 	length += sentLine->Length();
       
  2256 	length += KIMSLineFeed().Length();
       
  2257 	length += toLine->Length();
       
  2258 	if ( hasCcLine )
       
  2259 		{
       
  2260 		length += KIMSLineFeed().Length();
       
  2261 		length += ccLine->Length();
       
  2262 		}
       
  2263 	length += KIMSLineFeed().Length();
       
  2264 	length += subjectLine->Length();
       
  2265 	length += KIMSLineFeed().Length();
       
  2266     if ( hasBody )
       
  2267         {
       
  2268         length += body->Length();
       
  2269         }
       
  2270 	length += KIMSLineFeed().Length();
       
  2271 	length += KIMSLineFeed().Length();
       
  2272 
       
  2273 	// create buffer and write contents
       
  2274 	HBufC* header = HBufC::NewL( length );
       
  2275 	TPtr ptr = header->Des();
       
  2276 	ptr.Append( *separator );
       
  2277 	ptr.Append( KIMSLineFeed );
       
  2278 	ptr.Append( *fromLine );
       
  2279 	ptr.Append( KIMSLineFeed );
       
  2280 	ptr.Append( *sentLine );
       
  2281 	ptr.Append( KIMSLineFeed );
       
  2282 	ptr.Append( *toLine );
       
  2283 	if ( hasCcLine )
       
  2284 		{
       
  2285 		ptr.Append( KIMSLineFeed );
       
  2286 		ptr.Append( *ccLine );
       
  2287 		}
       
  2288 	ptr.Append( KIMSLineFeed );
       
  2289 	ptr.Append( *subjectLine );
       
  2290 	ptr.Append( KIMSLineFeed );
       
  2291     if ( hasBody )
       
  2292         {
       
  2293         ptr.Append( *body );
       
  2294         }
       
  2295 	ptr.Append( KIMSLineFeed );
       
  2296 	ptr.Append( KIMSLineFeed );
       
  2297 
       
  2298 	// leave header on the cleanup stack
       
  2299     if ( hasBody )
       
  2300         {
       
  2301         CleanupStack::PopAndDestroy( body ); //-7
       
  2302         }
       
  2303 	CleanupStack::PopAndDestroy( subjectLine ); //-6
       
  2304 	if ( hasCcLine )
       
  2305 		{
       
  2306 		CleanupStack::PopAndDestroy( ccLine ); //-5
       
  2307 		}
       
  2308 	CleanupStack::PopAndDestroy( toLine ); //-4
       
  2309 	CleanupStack::PopAndDestroy( sentLine ); //-3
       
  2310 	CleanupStack::PopAndDestroy( fromLine ); //-2
       
  2311 	CleanupStack::PopAndDestroy( separator ); //-1
       
  2312 
       
  2313 	CleanupStack::PushL( header );
       
  2314 
       
  2315 	return header;
       
  2316 	}
       
  2317 
       
  2318 // -----------------------------------------------------------------------------
       
  2319 // CNcsComposeView::GenerateSmartTagLC
       
  2320 // -----------------------------------------------------------------------------
       
  2321 HBufC* CNcsComposeView::GenerateSmartTagLC()
       
  2322 	{
       
  2323     FUNC_LOG;
       
  2324 
       
  2325 	HBufC* tag = StringLoader::LoadLC( R_FSE_EDITOR_SMART_TAG );
       
  2326 
       
  2327 	return tag;
       
  2328 	}
       
  2329 
       
  2330 // -----------------------------------------------------------------------------
       
  2331 // CNcsComposeView::InitReplyOrForwardUiL
       
  2332 // -----------------------------------------------------------------------------
       
  2333 //
       
  2334 void CNcsComposeView::InitReplyOrForwardUiL()
       
  2335     {
       
  2336     FUNC_LOG;
       
  2337     // Show "Opening" wait note if the message body is large
       
  2338     TInt waitNoteId = KErrNotFound;
       
  2339     if ( TFsEmailUiUtility::IsMessageBodyLargeL(iOrigMessage) )
       
  2340         {
       
  2341         waitNoteId = TFsEmailUiUtility::ShowGlobalWaitNoteLC( R_FSE_WAIT_OPENING_TEXT );
       
  2342         }
       
  2343 
       
  2344     if ( iCustomMessageId == TUid::Uid( KEditorCmdReply ) )
       
  2345         {
       
  2346         GenerateReplyMessageL( EFalse );
       
  2347         InitReplyUiL( EFalse );
       
  2348         }
       
  2349     else if ( iCustomMessageId == TUid::Uid( KEditorCmdReplyAll ) )
       
  2350         {
       
  2351         GenerateReplyMessageL( ETrue );
       
  2352         InitReplyUiL( ETrue );
       
  2353         }
       
  2354     else if ( iCustomMessageId == TUid::Uid( KEditorCmdForward ) )
       
  2355         {
       
  2356         GenerateForwardMessageL();
       
  2357         InitForwardUiL();
       
  2358         }
       
  2359     else
       
  2360         {
       
  2361         // This shouldn't ever happen. Panic in debug builds.
       
  2362         ASSERT( EFalse );
       
  2363         }
       
  2364 
       
  2365     // Close the "Opening" wait note if it was shown
       
  2366     if ( waitNoteId != KErrNotFound )
       
  2367         {
       
  2368         CleanupStack::PopAndDestroy( (TAny*)waitNoteId );
       
  2369         }
       
  2370     }
       
  2371 
       
  2372 // -----------------------------------------------------------------------------
       
  2373 // CNcsComposeView::GenerateReplyMessageL
       
  2374 // -----------------------------------------------------------------------------
       
  2375 //
       
  2376 void CNcsComposeView::GenerateReplyMessageL( TBool aReplyAll )
       
  2377 	{
       
  2378     FUNC_LOG;
       
  2379 
       
  2380     __ASSERT_DEBUG( iMailBox, Panic( ENcsBasicUi ) );
       
  2381 
       
  2382 	TReplyForwardParams params;
       
  2383 	params.iHeader = GenerateReplyHeaderLC();
       
  2384 	params.iSmartTag = GenerateSmartTagLC();
       
  2385 	TPckgBuf<TReplyForwardParams> buf( params );
       
  2386 	HBufC* temp = HBufC::NewLC( buf.Length() );
       
  2387 	temp->Des().Copy( buf );
       
  2388 
       
  2389 	//<cmail> this is actually a waited async method
       
  2390 	iFakeSyncGoingOn = ETrue;
       
  2391     iNewMessage = iMailBox->CreateReplyMessage( iLaunchParams.iMsgId, aReplyAll, *temp );
       
  2392     iFakeSyncGoingOn = EFalse;
       
  2393     //</cmail>
       
  2394    	// Compose screen does not send cal messages, make sure
       
  2395 	// that cal event flag is not left active by some protocol
       
  2396 	if ( iNewMessage )
       
  2397 		{
       
  2398 		iNewMessage->ResetFlag( EFSMsgFlag_CalendarMsg );
       
  2399 		}
       
  2400     CleanupStack::PopAndDestroy( temp );
       
  2401     CleanupStack::PopAndDestroy( params.iSmartTag );
       
  2402     CleanupStack::PopAndDestroy( params.iHeader );
       
  2403     if ( !iNewMessage )
       
  2404     	{
       
  2405     	User::Leave( KErrGeneral );
       
  2406     	}
       
  2407     iFakeSyncGoingOn = ETrue; //<cmail>
       
  2408     TRAPD( error, TFsEmailUiUtility::MoveMessageToDraftsL( *iMailBox, *iNewMessage ) );
       
  2409     iFakeSyncGoingOn = EFalse; //</cmail>
       
  2410     User::LeaveIfError( error );
       
  2411 
       
  2412     if ( iNewMessage->GetContentType() != KFSMailContentTypeMultipartMixed )
       
  2413         {
       
  2414         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
       
  2415         iNewMessage->SaveMessageL();
       
  2416 	    }
       
  2417 	
       
  2418 	TFsEmailUiUtility::CreatePlainTextPartL( *iNewMessage, iNewMessageTextPart );
       
  2419 
       
  2420 	}
       
  2421 
       
  2422 // -----------------------------------------------------------------------------
       
  2423 // CNcsComposeView::GenerateForwardMessageL
       
  2424 // -----------------------------------------------------------------------------
       
  2425 //
       
  2426 void CNcsComposeView::GenerateForwardMessageL()
       
  2427 	{
       
  2428     FUNC_LOG;
       
  2429 
       
  2430     __ASSERT_DEBUG( iMailBox, Panic( ENcsBasicUi ) );
       
  2431 
       
  2432 	TReplyForwardParams params;
       
  2433 	params.iHeader = GenerateReplyHeaderLC();
       
  2434 	params.iSmartTag = GenerateSmartTagLC();
       
  2435 	TPckgBuf<TReplyForwardParams> buf( params );
       
  2436 	HBufC* temp = HBufC::NewLC( buf.Length() );
       
  2437 	temp->Des().Copy( buf );
       
  2438 
       
  2439 	//<cmail> this is actually a waited async call
       
  2440 	iFakeSyncGoingOn = ETrue;
       
  2441     iNewMessage = iMailBox->CreateForwardMessage( iLaunchParams.iMsgId, *temp );
       
  2442     iFakeSyncGoingOn = EFalse;
       
  2443     //</cmail>
       
  2444  	// Compose screen does not send cal messages, make sure
       
  2445 	// that cal event flag is not left active by some protocol
       
  2446 	if ( iNewMessage )
       
  2447 		{
       
  2448 		iNewMessage->ResetFlag( EFSMsgFlag_CalendarMsg );
       
  2449 		}
       
  2450     CleanupStack::PopAndDestroy( temp );
       
  2451     CleanupStack::PopAndDestroy( params.iSmartTag );
       
  2452     CleanupStack::PopAndDestroy( params.iHeader );
       
  2453     if ( !iNewMessage )
       
  2454     	{
       
  2455     	User::Leave( KErrGeneral );
       
  2456     	}
       
  2457     iFakeSyncGoingOn = ETrue; //<cmail>
       
  2458     TRAPD( error, TFsEmailUiUtility::MoveMessageToDraftsL( *iMailBox, *iNewMessage ) );
       
  2459     iFakeSyncGoingOn = EFalse; //<cmail>
       
  2460     User::LeaveIfError( error );
       
  2461 
       
  2462     if ( iNewMessage->GetContentType() != KFSMailContentTypeMultipartMixed )
       
  2463         {
       
  2464         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
       
  2465         iNewMessage->SaveMessageL();
       
  2466 	    }
       
  2467     
       
  2468 	TFsEmailUiUtility::CreatePlainTextPartL( *iNewMessage, iNewMessageTextPart );
       
  2469 
       
  2470     }
       
  2471 
       
  2472 // -----------------------------------------------------------------------------
       
  2473 // CNcsComposeView::InitReplyUiL
       
  2474 // -----------------------------------------------------------------------------
       
  2475 //
       
  2476 void CNcsComposeView::InitReplyUiL( TBool aReplyAll )
       
  2477 	{
       
  2478     FUNC_LOG;
       
  2479     if ( iFirstStartCompleted ) // Safety check
       
  2480         {
       
  2481         InitReplyFieldsL( aReplyAll );
       
  2482         IncludeMessageTextL( ETrue );
       
  2483         iContainer->SetFocusToMessageFieldL();
       
  2484         }
       
  2485 	}
       
  2486 
       
  2487 // -----------------------------------------------------------------------------
       
  2488 // CNcsComposeView::InitUiGeneralL
       
  2489 // -----------------------------------------------------------------------------
       
  2490 //
       
  2491 void CNcsComposeView::InitUiGeneralL()
       
  2492 	{
       
  2493     FUNC_LOG;
       
  2494     if ( iFirstStartCompleted ) // Safety check
       
  2495         {
       
  2496         AppUi()->AddToStackL( iContainer );
       
  2497         iContainer->SetMenuBar( Cba() );
       
  2498 
       
  2499     	// <cmail>
       
  2500     	// TInt ccVisible = iCrHandler->EditorCCVisible();
       
  2501     	// iContainer->SetCcFieldVisibleL( ccVisible == 1, EFalse );
       
  2502     	// TInt bccVisible = iCrHandler->EditorBCVisible();
       
  2503     	// iContainer->SetBccFieldVisibleL( bccVisible == 1, EFalse );
       
  2504     	// </cmail>
       
  2505 
       
  2506         iContainer->UpdateScrollBarL();
       
  2507 
       
  2508         // Set title pane text
       
  2509         const TDesC& mbName = iMailBox->GetName();
       
  2510         iAppUi.SetTitlePaneTextL( mbName );
       
  2511 
       
  2512         // Set priority flag
       
  2513         SetPriority();
       
  2514 
       
  2515         // Set follow-up flag
       
  2516         SetFollowUp();
       
  2517         }
       
  2518     }
       
  2519 
       
  2520 // -----------------------------------------------------------------------------
       
  2521 // CNcsComposeView::InitForwardUiL
       
  2522 // -----------------------------------------------------------------------------
       
  2523 //
       
  2524 void CNcsComposeView::InitForwardUiL()
       
  2525 	{
       
  2526     FUNC_LOG;
       
  2527     if ( iFirstStartCompleted ) // Safety check
       
  2528         {
       
  2529         InitForwardFieldsL();
       
  2530         IncludeMessageTextL( ETrue );
       
  2531         iContainer->SetFocusToToField();
       
  2532         iContainer->SelectAllToFieldTextL();
       
  2533         }
       
  2534 	}
       
  2535 
       
  2536 // -----------------------------------------------------------------------------
       
  2537 // CNcsComposeView::SetReplyForwardFlag
       
  2538 // -----------------------------------------------------------------------------
       
  2539 //
       
  2540 void CNcsComposeView::SetReplyForwardFlagL()
       
  2541 	{
       
  2542     FUNC_LOG;
       
  2543 
       
  2544 	if ( iFirstStartCompleted && iOrigMessage )
       
  2545 		{
       
  2546 		if ( iCustomMessageId == TUid::Uid( KEditorCmdReply ) ||
       
  2547              iCustomMessageId == TUid::Uid( KEditorCmdReplyAll ) )
       
  2548 			{
       
  2549 			iOrigMessage->SetFlag( EFSMsgFlag_Answered );
       
  2550 			iOrigMessage->SaveMessageL();
       
  2551 			}
       
  2552 		else if ( iCustomMessageId == TUid::Uid( KEditorCmdForward ) )
       
  2553 			{
       
  2554 			iOrigMessage->SetFlag( EFSMsgFlag_Forwarded );
       
  2555 			iOrigMessage->SaveMessageL();
       
  2556 			}
       
  2557 		}
       
  2558 
       
  2559 	}
       
  2560 
       
  2561 // -----------------------------------------------------------------------------
       
  2562 // CNcsComposeView::MailBoxSupportsSmartReply
       
  2563 // -----------------------------------------------------------------------------
       
  2564 //
       
  2565 TBool CNcsComposeView::MailBoxSupportsSmartReply()
       
  2566 	{
       
  2567     FUNC_LOG;
       
  2568 
       
  2569     __ASSERT_DEBUG( iMailBox, Panic( ENcsBasicUi ) );
       
  2570 
       
  2571 	return iMailBox->HasCapability( EFSMBoxCapaSmartReply );
       
  2572 	}
       
  2573 
       
  2574 // -----------------------------------------------------------------------------
       
  2575 // CNcsComposeView::MailBoxSupportsSmartForward
       
  2576 // -----------------------------------------------------------------------------
       
  2577 //
       
  2578 TBool CNcsComposeView::MailBoxSupportsSmartForward()
       
  2579 	{
       
  2580     FUNC_LOG;
       
  2581     __ASSERT_DEBUG( iMailBox, Panic( ENcsBasicUi ) );
       
  2582 
       
  2583 	return iMailBox->HasCapability( EFSMBoxCapaSmartForward );
       
  2584 	}
       
  2585 
       
  2586 // -----------------------------------------------------------------------------
       
  2587 // CNcsComposeView::HasUnfetchedAttachmentsL
       
  2588 // -----------------------------------------------------------------------------
       
  2589 //
       
  2590 TBool CNcsComposeView::HasUnfetchedAttachmentsL( CFSMailMessage& aMsg )
       
  2591 	{
       
  2592     FUNC_LOG;
       
  2593 
       
  2594     __ASSERT_DEBUG( &aMsg, Panic( ENcsBasicUi ) );
       
  2595 
       
  2596     TBool ret = EFalse;
       
  2597 
       
  2598 	RPointerArray<CFSMailMessagePart> attachments;
       
  2599 	CleanupResetAndDestroyClosePushL( attachments );
       
  2600 	aMsg.AttachmentListL( attachments );
       
  2601 	for ( TInt i=0; i<attachments.Count(); i++ )
       
  2602 		{
       
  2603 		if ( EFSFull != attachments[i]->FetchLoadState() )
       
  2604 			{
       
  2605 			ret = ETrue;
       
  2606 			break;
       
  2607 			}
       
  2608 		}
       
  2609 	CleanupStack::PopAndDestroy( &attachments );
       
  2610 
       
  2611 	return ret;
       
  2612 	}
       
  2613 
       
  2614 // -----------------------------------------------------------------------------
       
  2615 // CNcsComposeView::HandleActionL
       
  2616 // -----------------------------------------------------------------------------
       
  2617 //
       
  2618 void CNcsComposeView::HandleActionL( const TAlfActionCommand& aActionCommand )
       
  2619     {
       
  2620     FUNC_LOG;
       
  2621     if ( iFirstStartCompleted && iNewMessage && iMailBox 
       
  2622          && aActionCommand.Id() == KCmdEditorAutoSave )
       
  2623         {
       
  2624         CommitL( EFalse );
       
  2625         }
       
  2626     }
       
  2627 
       
  2628 // -----------------------------------------------------------------------------
       
  2629 // CNcsComposeView::SaveToDraftsL
       
  2630 // -----------------------------------------------------------------------------
       
  2631 //
       
  2632 void CNcsComposeView::SaveToDraftsL( TBool aParseAddresses )
       
  2633 	{
       
  2634     FUNC_LOG;
       
  2635     if ( iFirstStartCompleted ) // Safety
       
  2636         {
       
  2637         __ASSERT_DEBUG( iMailBox, Panic( ENcsBasicUi ) );
       
  2638         __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
       
  2639 
       
  2640         iFakeSyncGoingOn = ETrue;
       
  2641         TRAPD( error, CommitL( aParseAddresses ) );
       
  2642         iFakeSyncGoingOn = EFalse;
       
  2643         User::LeaveIfError( error );
       
  2644 
       
  2645         iFakeSyncGoingOn = ETrue;
       
  2646         TRAP( error, TFsEmailUiUtility::MoveMessageToDraftsL(
       
  2647             *iMailBox, *iNewMessage ) );
       
  2648         iFakeSyncGoingOn = EFalse;
       
  2649         User::LeaveIfError( error );
       
  2650 
       
  2651         if ( !iAppUi.AppUiExitOngoing() )
       
  2652             {
       
  2653             // Simulate a new mail event to ensure that saved message becomes visible in the
       
  2654             // mail list. All protocols do not send event automatically in this case.
       
  2655             RArray<TFSMailMsgId> messageIdArray;
       
  2656             CleanupClosePushL( messageIdArray );
       
  2657             messageIdArray.Append( iNewMessage->GetMessageId() );
       
  2658             TFSMailMsgId folderId = iNewMessage->GetFolderId();
       
  2659             TFSMailMsgId mailboxId = iNewMessage->GetMailBoxId();
       
  2660             iAppUi.EventL(
       
  2661                 TFSEventNewMail, mailboxId, &messageIdArray, &folderId, NULL );
       
  2662             // Update displayed mail info if the mail was already created sooner
       
  2663             iAppUi.EventL(
       
  2664                 TFSEventMailChanged, mailboxId, &messageIdArray, &folderId, NULL );
       
  2665             CleanupStack::PopAndDestroy( &messageIdArray );
       
  2666             }
       
  2667         }
       
  2668 	}
       
  2669 
       
  2670 // -----------------------------------------------------------------------------
       
  2671 // CNcsComposeView::FetchLogicComplete
       
  2672 // -----------------------------------------------------------------------------
       
  2673 //
       
  2674 void CNcsComposeView::FetchLogicComplete( TComposerFetchState /*aState*/, TInt aError )
       
  2675 	{
       
  2676     FUNC_LOG;
       
  2677     if ( iFirstStartCompleted ) // Safety
       
  2678         {
       
  2679         if ( !aError )
       
  2680             {
       
  2681             TRAP( aError, InitReplyOrForwardUiL() );
       
  2682             iAutoSaver->Enable( ETrue );
       
  2683             }
       
  2684         else
       
  2685             {
       
  2686             // something went wrong
       
  2687             DoSafeExit(ENoSave);
       
  2688             iMailFetchingErrCode = aError;
       
  2689             }
       
  2690         }
       
  2691     if ( iFetchWaitDialog && !iFetchDialogCancelled )
       
  2692         {
       
  2693         TRAP_IGNORE(iFetchWaitDialog->ProcessFinishedL());
       
  2694         iFetchWaitDialog = NULL;
       
  2695         }
       
  2696 	}
       
  2697 
       
  2698 // -----------------------------------------------------------------------------
       
  2699 // CNcsComposeView::ExitComposer
       
  2700 // -----------------------------------------------------------------------------
       
  2701 //
       
  2702 void CNcsComposeView::ExitComposer()
       
  2703     {
       
  2704     FUNC_LOG;
       
  2705 
       
  2706     if ( iStatusPaneIndicators )
       
  2707         {
       
  2708         iStatusPaneIndicators->HideStatusPaneIndicators();
       
  2709         }
       
  2710     
       
  2711     // lower flag to indicate that view is no longer able to handle user commands
       
  2712     iViewReady = EFalse;
       
  2713 
       
  2714 	// view switching and alfred operations should be avoided
       
  2715 	// when Appui exit has been initialised
       
  2716 	if ( !iAppUi.AppUiExitOngoing() )
       
  2717 		{
       
  2718         // change to previous view
       
  2719         TRAP_IGNORE( NavigateBackL() );
       
  2720         }
       
  2721 
       
  2722     // Cleanup message contents to prevent ChildDoDeactivate() from saving the message to drafts again
       
  2723     ResetComposer();
       
  2724 
       
  2725     SafeDelete( iFetchLogic );
       
  2726     }
       
  2727 
       
  2728 // -----------------------------------------------------------------------------
       
  2729 // CNcsComposeView::CreateContainerL
       
  2730 // -----------------------------------------------------------------------------
       
  2731 //
       
  2732 void CNcsComposeView::CreateContainerL()
       
  2733     {
       
  2734     FUNC_LOG;
       
  2735     TInt flags = NULL;
       
  2736     if ( iCrHandler->EditorCCVisible() )
       
  2737         {
       
  2738         flags |= CNcsComposeViewContainer::ECcFieldVisible;
       
  2739         }
       
  2740     if ( iCrHandler->EditorBCVisible() )
       
  2741         {
       
  2742         flags |= CNcsComposeViewContainer::EBccFieldVisible;
       
  2743         }
       
  2744     TRect rect = ClientRect();
       
  2745     iContainer = CNcsComposeViewContainer::NewL( *this, rect, *iMailBox,
       
  2746         *iAutoSaver, flags );
       
  2747     }
       
  2748 
       
  2749 // -----------------------------------------------------------------------------
       
  2750 // CNcsComposeView::ResetComposer
       
  2751 // -----------------------------------------------------------------------------
       
  2752 //
       
  2753 void CNcsComposeView::ResetComposer()
       
  2754     {
       
  2755     FUNC_LOG;
       
  2756 
       
  2757     delete iMailBox;
       
  2758     iMailBox = NULL;
       
  2759     delete iOrigMessage;
       
  2760     iOrigMessage = NULL;
       
  2761     delete iNewMessageTextPart;
       
  2762     iNewMessageTextPart = NULL;
       
  2763     delete iNewMessage;
       
  2764     iNewMessage = NULL;
       
  2765     iDlg = NULL;
       
  2766 
       
  2767     if ( iContainer )
       
  2768         {
       
  2769         AppUi()->RemoveFromStack( iContainer );
       
  2770         delete iContainer;
       
  2771         iContainer = NULL;
       
  2772         }
       
  2773 
       
  2774     }
       
  2775 
       
  2776 // -----------------------------------------------------------------------------
       
  2777 // CNcsComposeView::SaveAndCleanPreviousMessage
       
  2778 // -----------------------------------------------------------------------------
       
  2779 //
       
  2780 void CNcsComposeView::SaveAndCleanPreviousMessage()
       
  2781     {
       
  2782     FUNC_LOG;
       
  2783 
       
  2784     if ( iFirstStartCompleted && iContainer && iNewMessage && iMailBox )
       
  2785         {
       
  2786 
       
  2787         TBool noAddrOrNoMesBody = iContainer->AreAddressFieldsEmpty() &&
       
  2788             iContainer->IsSubjectFieldEmpty() &&
       
  2789             (iContainer->GetMessageFieldLength() < 1);
       
  2790 
       
  2791         // save to Drafts if there's some user input in some header field or in message body
       
  2792         if ( !noAddrOrNoMesBody )
       
  2793             {
       
  2794             TRAPD( error, DoSaveDraftL( EFalse ) );
       
  2795             if ( error )
       
  2796                 {
       
  2797                 }
       
  2798             }
       
  2799 
       
  2800         // store the message IDs to launch parameters to be able to return to same message if desired
       
  2801         iLaunchParams.iMsgId = iNewMessage->GetMessageId();
       
  2802         iLaunchParams.iFolderId = iNewMessage->GetFolderId();
       
  2803         iLaunchParams.iMailboxId = iMailBox->GetId();
       
  2804         }
       
  2805     ResetComposer();
       
  2806     }
       
  2807 
       
  2808 // -----------------------------------------------------------------------------
       
  2809 // CNcsComposeView::AsyncExit
       
  2810 // -----------------------------------------------------------------------------
       
  2811 //
       
  2812 TInt CNcsComposeView::AsyncExit( TAny* aSelfPtr )
       
  2813     {
       
  2814     FUNC_LOG;
       
  2815     CNcsComposeView* self =
       
  2816         static_cast<CNcsComposeView*>( aSelfPtr );
       
  2817 
       
  2818     TRAPD( err,self->AsyncExitL() );
       
  2819     return err;
       
  2820     }
       
  2821 
       
  2822 // -----------------------------------------------------------------------------
       
  2823 // CNcsComposeView::AsyncExitL
       
  2824 // -----------------------------------------------------------------------------
       
  2825 //
       
  2826 void CNcsComposeView::AsyncExitL()
       
  2827     {
       
  2828     FUNC_LOG;
       
  2829     if ( iFakeSyncGoingOn || iExecutingDoExitL ) // if some sync method is still going on, we continue waiting
       
  2830         {
       
  2831         iActiveHelper->Cancel();
       
  2832         iActiveHelper->Start();
       
  2833         }
       
  2834     else
       
  2835         {
       
  2836         ExitComposer();
       
  2837         // for some strange reason composer view is stuck and only option was to call ProcessCommandL with EAknCmdExit
       
  2838         ProcessCommandL( EAknCmdExit );
       
  2839         }
       
  2840     }
       
  2841 
       
  2842 // -----------------------------------------------------------------------------
       
  2843 // CNcsComposeView::HandleContainerChangeRequiringToolbarRefresh
       
  2844 // -----------------------------------------------------------------------------
       
  2845 //
       
  2846 void CNcsComposeView::HandleContainerChangeRequiringToolbarRefresh()
       
  2847     {
       
  2848     RefreshToolbar();
       
  2849     }
       
  2850 
       
  2851 // -----------------------------------------------------------------------------
       
  2852 // CNcsComposeView::ShowFetchingWaitNoteL
       
  2853 // -----------------------------------------------------------------------------
       
  2854 //
       
  2855 void CNcsComposeView::ShowFetchingWaitNoteL()
       
  2856     {
       
  2857     FUNC_LOG;
       
  2858     if ( !iAppUi.AppUiExitOngoing() )
       
  2859         {
       
  2860         if ( !iFetchWaitDialog )
       
  2861             {
       
  2862             iFetchWaitDialog = new(ELeave)CAknWaitDialog(
       
  2863                        (REINTERPRET_CAST(CEikDialog**,&iFetchWaitDialog)), EFalse);
       
  2864             iFetchWaitDialog->SetCallback(this);
       
  2865             iFetchDialogCancelled = EFalse;
       
  2866             iFetchWaitDialog->ExecuteLD(R_FSE_FETCHING_WAIT_DIALOG);
       
  2867             }
       
  2868         }
       
  2869     }
       
  2870 
       
  2871 // -----------------------------------------------------------------------------
       
  2872 // CNcsComposeView::DialogDismissedL
       
  2873 // -----------------------------------------------------------------------------
       
  2874 //
       
  2875 void CNcsComposeView::DialogDismissedL( TInt aButtonId )
       
  2876     {
       
  2877     FUNC_LOG;
       
  2878     if ( (aButtonId == EAknSoftkeyCancel) && iFetchLogic )
       
  2879         {
       
  2880         iFetchDialogCancelled = ETrue;
       
  2881         iFetchLogic->CancelFetchings();
       
  2882         }
       
  2883     }
       
  2884 
       
  2885 TBool CNcsComposeView::IsPreparedForExit()
       
  2886     {
       
  2887     return !(iFakeSyncGoingOn ||iExecutingDoExitL);
       
  2888     }
       
  2889 
       
  2890 // ---------------------------------------------------------------------------
       
  2891 // CActiveHelper::NewL()
       
  2892 // ---------------------------------------------------------------------------
       
  2893 //
       
  2894 CActiveHelper* CActiveHelper::NewL(CNcsComposeView* aSession )
       
  2895     {
       
  2896     CActiveHelper* self = new(ELeave) CActiveHelper(aSession);
       
  2897     CleanupStack::PushL( self );
       
  2898     self->ConstructL( );
       
  2899     CleanupStack::Pop( self );
       
  2900     return self;
       
  2901     }
       
  2902 
       
  2903 // ---------------------------------------------------------------------------
       
  2904 // CActiveHelper::~CActiveHelper()
       
  2905 // ---------------------------------------------------------------------------
       
  2906 //
       
  2907 CActiveHelper::~CActiveHelper( )
       
  2908     {
       
  2909     Cancel();
       
  2910     }
       
  2911 
       
  2912 // ---------------------------------------------------------------------------
       
  2913 // CActiveHelper::Start()
       
  2914 // ---------------------------------------------------------------------------
       
  2915 //
       
  2916 void CActiveHelper::Start()
       
  2917     {
       
  2918     TRequestStatus* status = &iStatus;
       
  2919     User::RequestComplete(status,KErrNone);
       
  2920     SetActive();
       
  2921     }
       
  2922 
       
  2923 // ---------------------------------------------------------------------------
       
  2924 // CActiveHelper::CActiveHelper()
       
  2925 // ---------------------------------------------------------------------------
       
  2926 //
       
  2927 CActiveHelper::CActiveHelper(CNcsComposeView* aSession ) : CActive(EPriorityLow)
       
  2928     {
       
  2929     iComposeView = aSession;
       
  2930     }
       
  2931 
       
  2932 // ---------------------------------------------------------------------------
       
  2933 // CActiveHelper::RunL()
       
  2934 // ---------------------------------------------------------------------------
       
  2935 //
       
  2936 void CActiveHelper::RunL()
       
  2937     {
       
  2938     if(iComposeView)
       
  2939         iComposeView->AsyncExitL();
       
  2940     }
       
  2941 
       
  2942 // ---------------------------------------------------------------------------
       
  2943 // CActiveHelper::DoCancel()
       
  2944 // ---------------------------------------------------------------------------
       
  2945 //
       
  2946 void CActiveHelper::DoCancel()
       
  2947     {
       
  2948     // Empty
       
  2949     }
       
  2950 
       
  2951 // ---------------------------------------------------------------------------
       
  2952 // CActiveHelper::ConstructL()
       
  2953 // ---------------------------------------------------------------------------
       
  2954 //
       
  2955 void CActiveHelper::ConstructL()
       
  2956     {
       
  2957     CActiveScheduler::Add(this);
       
  2958     }
       
  2959 
       
  2960 //</cmail>