emailuis/emailui/src/ncscomposeview.cpp
changeset 2 5253a20d2a1e
parent 1 12c456ceeff2
child 3 a4d6f1ea0416
equal deleted inserted replaced
1:12c456ceeff2 2:5253a20d2a1e
    19 #include "emailtrace.h"
    19 #include "emailtrace.h"
    20 #include <aknnotewrappers.h>
    20 #include <aknnotewrappers.h>
    21 #include <NpdApi.h>
    21 #include <NpdApi.h>
    22 #include <StringLoader.h>
    22 #include <StringLoader.h>
    23 #include <txtrich.h>
    23 #include <txtrich.h>
    24 #include <AknWaitDialog.h> //<cmail>
    24 #include <AknWaitDialog.h>
    25 #include <MsgAttachmentUtils.h>//<cmail>
    25 #include <MsgAttachmentUtils.h>
    26 //<cmail>
       
    27 #include <featmgr.h>
    26 #include <featmgr.h>
    28 #include "CFSMailBox.h"
    27 #include "CFSMailBox.h"
    29 #include "CFSMailMessage.h"
    28 #include "CFSMailMessage.h"
    30 #include "CFSMailAddress.h"
    29 #include "CFSMailAddress.h"
    31 #include "CFSMailClient.h"
    30 #include "CFSMailClient.h"
    32 #include "CFSMailCommon.h"
    31 #include "CFSMailCommon.h"
    33 #include <csxhelp/cmail.hlp.hrh>
    32 #include <csxhelp/cmail.hlp.hrh>
    34 //</cmail>
       
    35 //<cmail> Touch
       
    36 #include <akntoolbar.h>
    33 #include <akntoolbar.h>
    37 #include <akntoolbarextension.h>
    34 #include <akntoolbarextension.h>
    38 #include <AknUtils.h>
    35 #include <AknUtils.h>
    39 //</cmail> Touch
       
    40 #include <FreestyleEmailUi.rsg>
    36 #include <FreestyleEmailUi.rsg>
    41 #include <freestyleemailui.mbg>
    37 #include <freestyleemailui.mbg>
       
    38 #include <aknstyluspopupmenu.h>
    42 
    39 
    43 #include "ncscomposeview.h"
    40 #include "ncscomposeview.h"
    44 #include "ncscomposeviewcontainer.h"
    41 #include "ncscomposeviewcontainer.h"
    45 #include "ncsconstants.h"
    42 #include "ncsconstants.h"
    46 #include "ncsutility.h"
    43 #include "ncsutility.h"
    83 CNcsComposeView::CNcsComposeView( CFreestyleEmailUiAppUi& aAppUi,
    80 CNcsComposeView::CNcsComposeView( CFreestyleEmailUiAppUi& aAppUi,
    84     CAlfEnv& aEnv, CAlfControlGroup& aSendAttachmentControlGroup,
    81     CAlfEnv& aEnv, CAlfControlGroup& aSendAttachmentControlGroup,
    85     CFSMailClient& aMailClient, CMsvSession& aMsvSession )
    82     CFSMailClient& aMailClient, CMsvSession& aMsvSession )
    86     : CFsEmailUiViewBase( aSendAttachmentControlGroup, aAppUi ),
    83     : CFsEmailUiViewBase( aSendAttachmentControlGroup, aAppUi ),
    87      iMailClient( aMailClient ), iOrigMessage( NULL ), iNewMessage( NULL ),
    84      iMailClient( aMailClient ), iOrigMessage( NULL ), iNewMessage( NULL ),
    88      iMsvSession( aMsvSession ), iEnv( aEnv )
    85      iMsvSession( aMsvSession ), iEnv( aEnv ),
    89      ,iFakeSyncGoingOn(EFalse), iFetchDialogCancelled(EFalse),iExecutingDoExitL(EFalse)//<cmail>
    86      iFakeSyncGoingOn(EFalse), iFetchDialogCancelled(EFalse),
       
    87      iExecutingDoExitL( EFalse )
    90     {
    88     {
    91     FUNC_LOG;
    89     FUNC_LOG;
    92 
    90 
    93     iAttachmentListSaveDraft = EFalse;
    91     iAttachmentListSaveDraft = EFalse;
    94 
    92 
    97 // -----------------------------------------------------------------------------
    95 // -----------------------------------------------------------------------------
    98 // CNcsComposeView::NewL()
    96 // CNcsComposeView::NewL()
    99 // Two-phased constructor.
    97 // Two-phased constructor.
   100 // -----------------------------------------------------------------------------
    98 // -----------------------------------------------------------------------------
   101 //
    99 //
   102 CNcsComposeView* CNcsComposeView::NewL( CFSMailClient& aMailClient, CAlfEnv& aEnv,
   100 CNcsComposeView* CNcsComposeView::NewL( 
   103                                         CFreestyleEmailUiAppUi* aAppUi, CAlfControlGroup& aControlGroup,
   101         CFSMailClient& aMailClient, CAlfEnv& aEnv,
   104                                         CMsvSession& aMsvSession )
   102         CFreestyleEmailUiAppUi* aAppUi, CAlfControlGroup& aControlGroup,
   105     {
   103         CMsvSession& aMsvSession )
   106     FUNC_LOG;
   104     {
   107 
   105     FUNC_LOG;
   108     CNcsComposeView* self = CNcsComposeView::NewLC( aMailClient, aEnv, 	aAppUi,
   106 
   109                                                     aControlGroup, aMsvSession );
   107     CNcsComposeView* self = 
       
   108         CNcsComposeView::NewLC( aMailClient, aEnv, 	aAppUi,
       
   109                                 aControlGroup, aMsvSession );
   110     CleanupStack::Pop( self );
   110     CleanupStack::Pop( self );
   111 
   111 
   112     return self;
   112     return self;
   113     }
   113     }
   114 
   114 
   124     CAlfControlGroup& aControlGroup,
   124     CAlfControlGroup& aControlGroup,
   125     CMsvSession& aMsvSession )
   125     CMsvSession& aMsvSession )
   126     {
   126     {
   127     FUNC_LOG;
   127     FUNC_LOG;
   128 
   128 
   129     CNcsComposeView* self = new ( ELeave ) CNcsComposeView( *aAppUi, aEnv, aControlGroup, aMailClient, aMsvSession );
   129     CNcsComposeView* self = new ( ELeave ) CNcsComposeView( 
       
   130             *aAppUi, aEnv, aControlGroup, aMailClient, aMsvSession );
   130     CleanupStack::PushL( self );
   131     CleanupStack::PushL( self );
   131     self->ConstructL();
   132     self->ConstructL();
   132 
   133 
   133     return self;
   134     return self;
   134     }
   135     }
   144 
   145 
   145     BaseConstructL( R_NCS_COMPOSE_VIEW );
   146     BaseConstructL( R_NCS_COMPOSE_VIEW );
   146     iFirstStartCompleted = EFalse;
   147     iFirstStartCompleted = EFalse;
   147     }
   148     }
   148 
   149 
   149 // CFSEmailUiMsgDetailsVisualiser::DoFirstStartL()
   150 // -----------------------------------------------------------------------------
       
   151 // CNcsComposeView::DoFirstStartL()
   150 // Purpose of this function is to do first start only when msg details is
   152 // 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.
   153 // really needed to be shown. Implemented to make app startuo faster.
       
   154 // -----------------------------------------------------------------------------
       
   155 //
   152 void CNcsComposeView::DoFirstStartL()
   156 void CNcsComposeView::DoFirstStartL()
   153     {
   157     {
   154     FUNC_LOG;
   158     FUNC_LOG;
   155     // Attachment list for compose screen
   159     // Attachment list for compose screen, owned by AlfEnv
   156     CAlfControlGroup& attListControlGroup = iEnv.NewControlGroupL( KSendAttachmentManagerDisplayGroup ); // owned by AlfEnv
   160     CAlfControlGroup& attListControlGroup = 
       
   161         iEnv.NewControlGroupL( KSendAttachmentManagerDisplayGroup );
   157     CFSEmailUiSendAttachmentsListVisualiser* sendAttachmentVisualiser =
   162     CFSEmailUiSendAttachmentsListVisualiser* sendAttachmentVisualiser =
   158 		CFSEmailUiSendAttachmentsListVisualiser::NewLC(
   163 		CFSEmailUiSendAttachmentsListVisualiser::NewLC(
   159             iEnv, &iAppUi, attListControlGroup );
   164             iEnv, &iAppUi, attListControlGroup );
   160     iAppUi.AddViewL( sendAttachmentVisualiser );
   165     iAppUi.AddViewL( sendAttachmentVisualiser );
   161     CleanupStack::Pop( sendAttachmentVisualiser );
   166     CleanupStack::Pop( sendAttachmentVisualiser );
   169     iFirstStartCompleted = ETrue;
   174     iFirstStartCompleted = ETrue;
   170     iCheckQuery = EFalse;
   175     iCheckQuery = EFalse;
   171     iAsyncCallback = new (ELeave) CAsyncCallBack( CActive::EPriorityLow );
   176     iAsyncCallback = new (ELeave) CAsyncCallBack( CActive::EPriorityLow );
   172     // msk context menu added into composer
   177     // msk context menu added into composer
   173     MenuBar()->SetContextMenuTitleResourceId( R_NCS_COMPOSE_BODY_MSK_MENUBAR );
   178     MenuBar()->SetContextMenuTitleResourceId( R_NCS_COMPOSE_BODY_MSK_MENUBAR );
   174     iActiveHelper = CActiveHelper::NewL(this);
   179     iActiveHelper = CActiveHelper::NewL( this );
   175 
   180 
   176     iAsyncAttachmentAdd = new (ELeave) CAsyncCallBack( CActive::EPriorityStandard );
   181     iAsyncAttachmentAdd = 
       
   182         new (ELeave) CAsyncCallBack( CActive::EPriorityStandard );
       
   183     
       
   184     // Initializing the default stylus long tap popup menu
       
   185 	if( !iStylusPopUpMenu )
       
   186 		{
       
   187 		TPoint point( 0, 0 );
       
   188 		iStylusPopUpMenu = CAknStylusPopUpMenu::NewL( this, point );
       
   189 		TResourceReader reader;
       
   190 		iCoeEnv->CreateResourceReaderLC( reader,
       
   191 				R_STYLUS_POPUP_MENU_COMPOSE_VIEW_ATTACHMENT );
       
   192 		iStylusPopUpMenu->ConstructFromResourceL( reader );
       
   193 		CleanupStack::PopAndDestroy(); // reader
       
   194 		}
   177     }
   195     }
   178 
   196 
   179 // -----------------------------------------------------------------------------
   197 // -----------------------------------------------------------------------------
   180 // CNcsComposeView::~CNcsComposeView()
   198 // CNcsComposeView::~CNcsComposeView()
   181 // Destructor.
   199 // Destructor.
   189 	    {
   207 	    {
   190 	    iAsyncCallback->Cancel();
   208 	    iAsyncCallback->Cancel();
   191 	    delete iAsyncCallback;
   209 	    delete iAsyncCallback;
   192 	    }
   210 	    }
   193     delete iFetchLogic;
   211     delete iFetchLogic;
   194     if(iActiveHelper)
   212     if( iActiveHelper )
   195         {
   213         {
   196         iActiveHelper->Cancel();
   214         iActiveHelper->Cancel();
   197         delete iActiveHelper;
   215         delete iActiveHelper;
   198         }
   216         }
   199     if (iAsyncAttachmentAdd)
   217     if ( iAsyncAttachmentAdd )
   200         {
   218         {
   201         iAsyncAttachmentAdd->Cancel();
   219         iAsyncAttachmentAdd->Cancel();
   202         delete iAsyncAttachmentAdd;
   220         delete iAsyncAttachmentAdd;
   203         }
   221         }
       
   222     delete iStylusPopUpMenu;
   204     }
   223     }
   205 
   224 
   206 void CNcsComposeView::PrepareForExit()
   225 void CNcsComposeView::PrepareForExit()
   207     {
   226     {
   208     FUNC_LOG;
   227     FUNC_LOG;
   210         {
   229         {
   211         TKeyEvent check = { EKeyEscape, EStdKeyNull, 0, 0 };
   230         TKeyEvent check = { EKeyEscape, EStdKeyNull, 0, 0 };
   212         TRAP_IGNORE( iDlg->OfferKeyEventL( check, EEventKey ) );
   231         TRAP_IGNORE( iDlg->OfferKeyEventL( check, EEventKey ) );
   213         iDlg = NULL;
   232         iDlg = NULL;
   214 
   233 
   215         iAsyncCallback->Cancel(); // cancel any outstanding callback just to be safe
   234         iAsyncCallback->Cancel(); // cancel any outstanding callback
   216         iAsyncCallback->Set( TCallBack( AsyncExit, this ) );
   235         iAsyncCallback->Set( TCallBack( AsyncExit, this ) );
   217         iAsyncCallback->CallBack();
   236         iAsyncCallback->CallBack();
   218         }
   237         }
   219     else if(iFakeSyncGoingOn || iExecutingDoExitL) //we starts this low priority active obj so that iwait in plugins finish
   238     else if( iFakeSyncGoingOn || iExecutingDoExitL )
   220         {
   239         {
       
   240         // low priority active obj so that iwait in plugins finish
   221         iActiveHelper->Cancel();
   241         iActiveHelper->Cancel();
   222         iActiveHelper->Start();
   242         iActiveHelper->Start();
   223         }
   243         }
   224     else
   244     else
   225         {
   245         {
   226         DoSafeExit( ESaveDraft );
   246         DoSafeExit( ESaveDraft );
   227         //iAppUi.Exit();
   247         }
   228         }
   248 
   229 
   249     if( iFetchLogic )
   230     if(iFetchLogic)
       
   231         {
   250         {
   232         iFetchLogic->CancelFetchings();
   251         iFetchLogic->CancelFetchings();
   233         }
   252         }
   234 
       
   235     //ResetComposer(); // already done in DoExitL
       
   236     }
   253     }
   237 
   254 
   238 // -----------------------------------------------------------------------------
   255 // -----------------------------------------------------------------------------
   239 // CNcsComposeView::Id()
   256 // CNcsComposeView::Id()
   240 // Returns View's ID.
   257 // Returns View's ID.
   249 // -----------------------------------------------------------------------------
   266 // -----------------------------------------------------------------------------
   250 // CNcsComposeView::ChildDoActivateL()
   267 // CNcsComposeView::ChildDoActivateL()
   251 // Activate the Compose view
   268 // Activate the Compose view
   252 // -----------------------------------------------------------------------------
   269 // -----------------------------------------------------------------------------
   253 //
   270 //
   254 // <cmail> Toolbar
       
   255 /*void CNcsComposeView::DoActivateL( const TVwsViewId& aPrevViewId,
       
   256     TUid aCustomMessageId, const TDesC8& aCustomMessage )*/
       
   257 void CNcsComposeView::ChildDoActivateL( const TVwsViewId& aPrevViewId,
   271 void CNcsComposeView::ChildDoActivateL( const TVwsViewId& aPrevViewId,
   258     TUid aCustomMessageId, const TDesC8& aCustomMessage )
   272     TUid aCustomMessageId, const TDesC8& aCustomMessage )
   259 // </cmail> Toolbar
       
   260     {
   273     {
   261     FUNC_LOG;
   274     FUNC_LOG;
   262     if ( !iFirstStartCompleted )
   275     if ( !iFirstStartCompleted )
   263         {
   276         {
   264         DoFirstStartL();
   277         DoFirstStartL();
   265         }
   278         }
   266     Toolbar()->SetDimmed(ETrue);
   279     Toolbar()->SetDimmed( ETrue );
   267     // Set status pane indicators
   280     // Set status pane indicators
   268     iStatusPaneIndicators = iAppUi.GetStatusPaneIndicatorContainer();
   281     iStatusPaneIndicators = iAppUi.GetStatusPaneIndicatorContainer();
   269     iStatusPaneIndicators->ShowStatusPaneIndicators();
   282     iStatusPaneIndicators->ShowStatusPaneIndicators();
   270 
   283 
   271     // Notify base class about view being entered unless we returned from another view
   284     // Notify base class about view being entered unless 
       
   285     // returned from another view
   272     if ( aCustomMessageId.iUid != KEditorCmdReturnToPrevious )
   286     if ( aCustomMessageId.iUid != KEditorCmdReturnToPrevious )
   273         {
   287         {
   274         ViewEntered( aPrevViewId );
   288         ViewEntered( aPrevViewId );
   275         }
   289         }
   276 
   290 
   278     SaveAndCleanPreviousMessage();
   292     SaveAndCleanPreviousMessage();
   279 
   293 
   280     // Get the launch parameters
   294     // Get the launch parameters
   281     if ( aCustomMessageId.iUid == KEditorCmdReturnToPrevious )
   295     if ( aCustomMessageId.iUid == KEditorCmdReturnToPrevious )
   282         {
   296         {
   283         // Use previous launch parameters when returning to previously open message
   297         // Use previous launch parameters when returning to previously 
       
   298         // opened message
   284         iMailBox = iMailClient.GetMailBoxByUidL( iLaunchParams.iMailboxId );
   299         iMailBox = iMailClient.GetMailBoxByUidL( iLaunchParams.iMailboxId );
   285         }
   300         }
   286     else if ( aCustomMessage.Length() > 0 )
   301     else if ( aCustomMessage.Length() > 0 )
   287         {
   302         {
   288 
   303 
   295     else
   310     else
   296         {
   311         {
   297         iLaunchParams.iActivatedExternally = ETrue;
   312         iLaunchParams.iActivatedExternally = ETrue;
   298         }
   313         }
   299 
   314 
   300     // Inform the AppUi about external view activation to fix the view stack. Normally
   315     // Inform the AppUi about external view activation to fix the view stack.
   301     // this happens based on the previous view AppUid in the BaseView but in case
   316     // Normally this happens based on the previous view AppUid in the BaseView
   302     // contacts action menu was used within FsEmail, this doesn' work. It doesn't
   317     // but in case contacts action menu was used within FsEmail, this doesn' 
   303     // hurt to call this again even if it was already called once from BaseView.
   318     // work. It doesn't hurt to call this again even if it was already called
       
   319     // once from BaseView.
   304     if ( iLaunchParams.iActivatedExternally )
   320     if ( iLaunchParams.iActivatedExternally )
   305         {
   321         {
   306         iAppUi.ViewActivatedExternallyL( Id() );
   322         iAppUi.ViewActivatedExternallyL( Id() );
   307         }
   323         }
   308 
   324 
   313 
   329 
   314         // can we get it from MSV Id
   330         // can we get it from MSV Id
   315         // MSV id is passed to us when account is defined email key settings
   331         // MSV id is passed to us when account is defined email key settings
   316         if ( aCustomMessageId != TUid::Null() )
   332         if ( aCustomMessageId != TUid::Null() )
   317             {
   333             {
   318             TRAP( error, iMailBox = TFsEmailUiUtility::GetMailboxForMtmIdL( iMailClient, iMsvSession, aCustomMessageId.iUid ) );
   334             TRAP( error, iMailBox = TFsEmailUiUtility::GetMailboxForMtmIdL( 
       
   335                     iMailClient, iMsvSession, aCustomMessageId.iUid ) );
   319             }
   336             }
   320 
   337 
   321         error = KErrNone;
   338         error = KErrNone;
   322 
   339 
   323         // try to use mailbox set as default in MCE
   340         // try to use mailbox set as default in MCE
   324         if ( !iMailBox )
   341         if ( !iMailBox )
   325             {
   342             {
   326             TRAP( error, iMailBox = TFsEmailUiUtility::GetMceDefaultMailboxL( iMailClient, iMsvSession ) );
   343             TRAP( error, iMailBox = TFsEmailUiUtility::GetMceDefaultMailboxL(
       
   344                     iMailClient, iMsvSession ) );
   327             }
   345             }
   328 
   346 
   329         // use first mail account from the list
   347         // use first mail account from the list
   330         if ( !iMailBox )
   348         if ( !iMailBox )
   331             {
   349             {
   333             RPointerArray<CFSMailBox> mailboxes;
   351             RPointerArray<CFSMailBox> mailboxes;
   334             CleanupResetAndDestroyClosePushL( mailboxes );
   352             CleanupResetAndDestroyClosePushL( mailboxes );
   335             iMailClient.ListMailBoxes( id, mailboxes );
   353             iMailClient.ListMailBoxes( id, mailboxes );
   336             if ( mailboxes.Count() > 0 )
   354             if ( mailboxes.Count() > 0 )
   337                 {
   355                 {
   338                 iMailBox = iMailClient.GetMailBoxByUidL( mailboxes[0]->GetId() );
   356                 iMailBox = 
       
   357                     iMailClient.GetMailBoxByUidL( mailboxes[0]->GetId() );
   339                 }
   358                 }
   340             CleanupStack::PopAndDestroy( &mailboxes );
   359             CleanupStack::PopAndDestroy( &mailboxes );
   341             }
   360             }
   342 
   361 
   343         // could not get mailbox so leave
   362         // could not get mailbox so leave
   360     if ( !err )
   379     if ( !err )
   361         {
   380         {
   362         err = iMailFetchingErrCode;
   381         err = iMailFetchingErrCode;
   363         }
   382         }
   364 
   383 
   365     if ( err == KErrCancel || err == KErrCouldNotConnect || err == KErrConnectionTerminated )
   384     if ( err == KErrCancel || 
   366         {
   385          err == KErrCouldNotConnect || 
   367         // Just close composer without any notes if operation was cancelled. For connection
   386          err == KErrConnectionTerminated )
   368         // errors, DownloadInfoMediator already shows error message, so no need to show another one.
   387         {
       
   388         // Just close composer without any notes if operation was cancelled.
       
   389         // For connection errors, DownloadInfoMediator already shows error 
       
   390         // message, so no need to show another one.
   369         ExitComposer();
   391         ExitComposer();
   370         }
   392         }
   371     else if ( err )
   393     else if ( err )
   372         {
   394         {
   373         // some other error => show generic error note and close composer
   395         // some other error => show generic error note and close composer
   374         if(!iAppUi.AppUiExitOngoing()) //<cmail>
   396         if( !iAppUi.AppUiExitOngoing() )
   375             TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE, ETrue );
   397             TFsEmailUiUtility::ShowErrorNoteL( 
       
   398                 R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE, ETrue );
   376         ExitComposer();
   399         ExitComposer();
   377         }
   400         }
   378     else
   401     else
   379         {
   402         {
   380         // everything went fine => do rest of the generic initialization
   403         // everything went fine => do rest of the generic initialization
   381         InitUiGeneralL();
   404         InitUiGeneralL();
   382         iAppUi.StartEndKeyCapture();
   405         iAppUi.StartEndKeyCapture();
   383         iContainer->SetMskL();
   406         iContainer->SetMskL();
   384         iViewReady = ETrue;
   407         iViewReady = ETrue;
   385         Toolbar()->SetDimmed(EFalse);
   408         Toolbar()->SetDimmed( EFalse );
   386         RefreshToolbar();
   409         RefreshToolbar();
   387         }
   410         }
   388     }
   411     }
   389 
   412 
   390 
   413 
   393 // -----------------------------------------------------------------------------
   416 // -----------------------------------------------------------------------------
   394 void CNcsComposeView::OfferToolbarEventL( TInt aCommand )
   417 void CNcsComposeView::OfferToolbarEventL( TInt aCommand )
   395     {
   418     {
   396     FUNC_LOG;
   419     FUNC_LOG;
   397     bool attachmentAddition = EFalse;
   420     bool attachmentAddition = EFalse;
   398     switch (aCommand)
   421     switch ( aCommand )
   399         {
   422         {
   400         case EFsEmailUiTbCmdSend:
   423         case EFsEmailUiTbCmdSend:
   401             if (iContainer && iContainer->AreAddressFieldsEmpty())
   424             if ( iContainer && iContainer->AreAddressFieldsEmpty() )
   402                 {
   425                 {
   403                 RefreshToolbar();
   426                 RefreshToolbar();
   404                 }
   427                 }
   405             else
   428             else
   406                 {
   429                 {
   407                 HandleCommandL( ENcsCmdSend );
   430                 HandleCommandL( ENcsCmdSend );
   408                 }
   431                 }
   409             break;
   432             break;
   410         case EFsEmailUiTbCmdAddRecipient:
   433         case EFsEmailUiTbCmdAddRecipient:
   411             if (iContainer)
   434             if ( iContainer )
   412                 {
   435                 {
   413                 iContainer->AppendAddressesL();
   436                 iContainer->AppendAddressesL();
   414                 }
   437                 }
   415             break;
   438             break;
   416         case EFsEmailUiTbCmdInsertAudio:
   439         case EFsEmailUiTbCmdInsertAudio:
   438             attachmentAddition = ETrue;
   461             attachmentAddition = ETrue;
   439             break;
   462             break;
   440         default:
   463         default:
   441             break;
   464             break;
   442         }
   465         }
   443     if (attachmentAddition)
   466     if ( attachmentAddition )
   444         {
   467         {
   445         iAsyncAttachmentAdd->Cancel(); // cancel any outstanding callback just to be safe
   468         iAsyncAttachmentAdd->Cancel(); // cancel any outstanding callback
   446         iAsyncAttachmentAdd->Set( TCallBack( AsyncAddAttachment, this ) );
   469         iAsyncAttachmentAdd->Set( TCallBack( AsyncAddAttachment, this ) );
   447         iAsyncAttachmentAdd->CallBack();
   470         iAsyncAttachmentAdd->CallBack();
   448         }
   471         }
   449     }
   472     }
   450 
   473 
   451 // <cmail> Toolbar
       
   452 // -----------------------------------------------------------------------------
   474 // -----------------------------------------------------------------------------
   453 // CNcsComposeView::ToolbarResourceId()
   475 // CNcsComposeView::ToolbarResourceId()
   454 // -----------------------------------------------------------------------------
   476 // -----------------------------------------------------------------------------
   455 //
   477 //
   456 TInt CNcsComposeView::ToolbarResourceId() const
   478 TInt CNcsComposeView::ToolbarResourceId() const
   466 void CNcsComposeView::GetInitiallyDimmedItemsL( const TInt aResourceId,
   488 void CNcsComposeView::GetInitiallyDimmedItemsL( const TInt aResourceId,
   467         RArray<TInt>& aDimmedItems ) const
   489         RArray<TInt>& aDimmedItems ) const
   468     {
   490     {
   469     FUNC_LOG;
   491     FUNC_LOG;
   470     aDimmedItems.Reset();
   492     aDimmedItems.Reset();
   471     switch (aResourceId)
   493     switch ( aResourceId )
   472         {
   494         {
   473         case R_FREESTYLE_EMAIL_UI_TOOLBAR_MESSAGE_EDITOR:
   495         case R_FREESTYLE_EMAIL_UI_TOOLBAR_MESSAGE_EDITOR:
   474             aDimmedItems.AppendL(EFsEmailUiTbCmdSend);
   496             aDimmedItems.AppendL( EFsEmailUiTbCmdSend );
   475             break;
   497             break;
   476         default:
   498         default:
   477             break;
   499             break;
   478         }
   500         }
   479     }
   501     }
   483 // -----------------------------------------------------------------------------
   505 // -----------------------------------------------------------------------------
   484 //
   506 //
   485 void CNcsComposeView::RefreshToolbar()
   507 void CNcsComposeView::RefreshToolbar()
   486     {
   508     {
   487     FUNC_LOG;
   509     FUNC_LOG;
   488     if (iContainer)
   510     if ( iContainer )
   489         {
   511         {
   490         // DimAllOptions if remotesearch is in progress, cos it takes you in a different view
   512         // DimAllOptions if remotesearch is in progress, 
       
   513         // because it takes you into a different view
   491         TBool dimAllOptions = iContainer->IsRemoteSearchInprogress();
   514         TBool dimAllOptions = iContainer->IsRemoteSearchInprogress();
   492         SetToolbarItemDimmed( EFsEmailUiTbCmdExpandInsert, dimAllOptions );
   515         SetToolbarItemDimmed( EFsEmailUiTbCmdExpandInsert, dimAllOptions );
   493         SetToolbarItemDimmed( EFsEmailUiTbCmdSend,
   516         SetToolbarItemDimmed( EFsEmailUiTbCmdSend,
   494                 iContainer->AreAddressFieldsEmpty() );
   517                 iContainer->AreAddressFieldsEmpty() );
   495         if ( (iContainer->IsFocusBcc() || iContainer->IsFocusCc() || iContainer->IsFocusTo()) && !dimAllOptions )
   518         if ( (iContainer->IsFocusBcc() || 
       
   519               iContainer->IsFocusCc() || 
       
   520               iContainer->IsFocusTo() ) && !dimAllOptions )
   496             {
   521             {
   497             SetToolbarItemDimmed( EFsEmailUiTbCmdAddRecipient, EFalse );
   522             SetToolbarItemDimmed( EFsEmailUiTbCmdAddRecipient, EFalse );
   498             }
   523             }
   499         else
   524         else
   500             {
   525             {
   501             SetToolbarItemDimmed( EFsEmailUiTbCmdAddRecipient, ETrue );
   526             SetToolbarItemDimmed( EFsEmailUiTbCmdAddRecipient, ETrue );
   502             }
   527             }
   503         }
   528         }
   504     }
   529     }
   505 // </cmail> Toolbar
       
   506 
   530 
   507 
   531 
   508 // -----------------------------------------------------------------------------
   532 // -----------------------------------------------------------------------------
   509 // CNcsComposeView::ChildDoDeactivate()
   533 // CNcsComposeView::ChildDoDeactivate()
   510 // Deactivate the Compose view
   534 // Deactivate the Compose view
   545 
   569 
   546     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
   570     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
   547     __ASSERT_DEBUG( iMailBox, Panic( ENcsBasicUi ) );
   571     __ASSERT_DEBUG( iMailBox, Panic( ENcsBasicUi ) );
   548     __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
   572     __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
   549 
   573 
   550     //<cmail>
   574     //we are forbiding to change MSK label, because popup will be opened 
   551     //we are forbiding to change MSK label, cause popup will be opend 
   575     iContainer->SwitchChangeMskOff( ETrue );
   552     iContainer->SwitchChangeMskOff(ETrue);
       
   553     //</cmail>
       
   554     
   576     
   555     if ( aResourceId == R_NCS_COMPOSE_MENU )
   577     if ( aResourceId == R_NCS_COMPOSE_MENU )
   556         {
   578         {
   557 	    if (FeatureManager::FeatureSupported( KFeatureIdFfCmailIntegration ))
   579 	    if ( FeatureManager::FeatureSupported( 
       
   580 	            KFeatureIdFfCmailIntegration ) )
   558 		   {
   581 		   {
   559 		   // remove help support in pf5250
   582 		   // remove help support in pf5250
   560 		   aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue);      
   583 		   aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue);      
   561 		   }     
   584 		   }     
   562         
   585         
   564     	if ( iContainer->AreAddressFieldsEmpty() )
   587     	if ( iContainer->AreAddressFieldsEmpty() )
   565 		    {
   588 		    {
   566 	    	aMenuPane->DeleteMenuItem( ENcsCmdSend );
   589 	    	aMenuPane->DeleteMenuItem( ENcsCmdSend );
   567 		    }
   590 		    }
   568 
   591 
   569 	    // If no attachments currently, delete the remove attachments menu item
   592 	    // If no attachments, delete the remove attachments menu item
   570 		CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
   593 		CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
   571 		attachmentControl = AttachmentsListControl();
   594 		attachmentControl = AttachmentsListControl();
   572 		TInt count = attachmentControl->Model()->Count();
   595 		TInt count = attachmentControl->Model()->Count();
   573 
   596 
   574         // if mail has remote attachments then attachments can't be removed via options menu
   597         // if mail has remote attachments then attachments can't be 
   575 		if ( count <= 0 || AttachmentsListControl()->Model()->HasReadOnlyAttachments() )
   598 		// removed via options menu
       
   599 		if ( count <= 0 || 
       
   600 		     AttachmentsListControl()->Model()->HasReadOnlyAttachments() )
   576 	    	{
   601 	    	{
   577     		aMenuPane->DeleteMenuItem( ENcsCmdRemoveAttachment );
   602     		aMenuPane->DeleteMenuItem( ENcsCmdRemoveAttachment );
   578     		aMenuPane->DeleteMenuItem( ENcsCmdRemoveAllAttachments );
   603     		aMenuPane->DeleteMenuItem( ENcsCmdRemoveAllAttachments );
   579 	    	}
   604 	    	}
   580         else if ( count == 1 )
   605         else if ( count == 1 )
   657 //
   682 //
   658 void CNcsComposeView::HandleCommandL( TInt aCommand )
   683 void CNcsComposeView::HandleCommandL( TInt aCommand )
   659     {
   684     {
   660     FUNC_LOG;
   685     FUNC_LOG;
   661 
   686 
   662     // Attempt to handle commands only after view is fully activated and exit has not yet been initiated.
   687     // Attempt to handle commands only after view is fully activated and exit
       
   688     // has not yet been initiated.
   663     if ( iViewReady && !iAppUi.ViewSwitchingOngoing() )
   689     if ( iViewReady && !iAppUi.ViewSwitchingOngoing() )
   664         {
   690         {
   665         __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
   691         __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
   666         __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
   692         __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
   667         __ASSERT_DEBUG( iCrHandler, Panic( ENcsBasicUi ) );
   693         __ASSERT_DEBUG( iCrHandler, Panic( ENcsBasicUi ) );
   668 
   694 
   669         switch( aCommand )
   695         switch( aCommand )
   670             {
   696             {
   671             case ENcsCmdSend:
   697             case ENcsCmdSend:
   672                 {
   698                 {
   673                 // Show query if the Subject field is empty (default text is as subject)
   699                 // Show query if the Subject field is empty
   674                 if ( iContainer->IsSubjectFieldEmpty() )
   700                 if ( iContainer->IsSubjectFieldEmpty() )
   675                     {
   701                     {
   676                     TInt answer = TFsEmailUiUtility::ShowConfirmationQueryL( R_FREESTYLE_EMAIL_QUERY_NO_SUBJECT );
   702                     TInt answer = TFsEmailUiUtility::ShowConfirmationQueryL(
       
   703                             R_FREESTYLE_EMAIL_QUERY_NO_SUBJECT );
   677                     if ( !answer )
   704                     if ( !answer )
   678                         {
   705                         {
   679                         // user didn't want to send yet -> go back to the message
   706                         // user didn't want to send yet
       
   707                         // -> go back to the message
   680                         return;
   708                         return;
   681                         }
   709                         }
   682                     }
   710                     }
   683 
   711 
   684                 TRAPD( error, DoSendL() );
   712                 TRAPD( error, DoSendL() );
   687                     // Sending successful
   715                     // Sending successful
   688                     HBufC* confMessage = NULL;
   716                     HBufC* confMessage = NULL;
   689                     if ( !TFsEmailUiUtility::IsOfflineModeL() )
   717                     if ( !TFsEmailUiUtility::IsOfflineModeL() )
   690                         {
   718                         {
   691                         // when sync status is currently ONLINE
   719                         // when sync status is currently ONLINE
   692                         confMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_CONFIRM_NOTE_SENDING_QUEUED );
   720                         confMessage = StringLoader::LoadLC( 
       
   721                                 R_FREESTYLE_EMAIL_CONFIRM_NOTE_SENDING_QUEUED );
   693                         }
   722                         }
   694                     else
   723                     else
   695                         {
   724                         {
   696                         // when sync status is currently OFFLINE
   725                         // when sync status is currently OFFLINE
   697                         confMessage = StringLoader::LoadLC( R_FREESTYLE_EMAIL_CONFIRM_NOTE_QUEUED_UNTIL_ONLINE );
   726                         confMessage = StringLoader::LoadLC( 
       
   727                                 R_FREESTYLE_EMAIL_CONFIRM_NOTE_QUEUED_UNTIL_ONLINE );
   698                         }
   728                         }
   699                     CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote( ETrue ); //waiting
   729                     CAknConfirmationNote* note = 
       
   730                         new (ELeave) CAknConfirmationNote( ETrue ); //waiting
   700                     note->SetTimeout( CAknNoteDialog::ELongTimeout );
   731                     note->SetTimeout( CAknNoteDialog::ELongTimeout );
   701                     note->ExecuteLD( *confMessage );
   732                     note->ExecuteLD( *confMessage );
   702                     CleanupStack::PopAndDestroy( confMessage );
   733                     CleanupStack::PopAndDestroy( confMessage );
   703                     DoSafeExit(); // Exit after successful sending
   734                     DoSafeExit(); // Exit after successful sending
   704                     }
   735                     }
   705                 else if ( error == KErrBadName )
   736                 else if ( error == KErrBadName )
   706                 	{
   737                 	{
   707                   	// sending failed because recipient address was invalid
   738                   	// sending failed because recipient address was invalid
   708                 	TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_CONFIRM_NOTE_INVALID_EMAIL_ADDRESS, ETrue );
   739                 	TFsEmailUiUtility::ShowErrorNoteL( 
       
   740                         R_FREESTYLE_EMAIL_CONFIRM_NOTE_INVALID_EMAIL_ADDRESS,
       
   741                         ETrue );
   709                 	}
   742                 	}
   710                 else
   743                 else
   711                 	{
   744                 	{
   712                 	// sending failed for some other reason
   745                 	// sending failed for some other reason
   713                     TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_CONFIRM_NOTE_MESSAGE_NOT_SENT, ETrue );
   746                     TFsEmailUiUtility::ShowErrorNoteL( 
   714                 	DoSafeExit(); // Exit after sending failed for other reason than KErrBadName
   747                         R_FREESTYLE_EMAIL_CONFIRM_NOTE_MESSAGE_NOT_SENT,
       
   748                         ETrue );
       
   749                     // Exit after sending failed for other reason for other
       
   750                     // reason than KErrBadName
       
   751                 	DoSafeExit();
   715                 	}
   752                 	}
   716                 }
   753                 }
   717                 break;
   754                 break;
   718             case ENcsCmdAddAttachment:
   755             case ENcsCmdAddAttachment:
   719            	 	{
   756            	 	{
   720            	 	//<cmail> Touch
       
   721                 if ( AknLayoutUtils::PenEnabled() )
   757                 if ( AknLayoutUtils::PenEnabled() )
   722                     {
   758                     {
   723                     // show the toolbar
   759                     // show the toolbar
   724                     UpdateToolbarL();
   760                     UpdateToolbarL();
   725                     if ( Toolbar() && Toolbar()->ToolbarExtension() )
   761                     if ( Toolbar() && Toolbar()->ToolbarExtension() )
   727                         Toolbar()->ToolbarExtension()->SetShown( ETrue );
   763                         Toolbar()->ToolbarExtension()->SetShown( ETrue );
   728                         }
   764                         }
   729                     }
   765                     }
   730                 else
   766                 else
   731                     {
   767                     {
   732                     //</cmail>
       
   733                     iAttachmentAddType = MsgAttachmentUtils::EUnknown;
   768                     iAttachmentAddType = MsgAttachmentUtils::EUnknown;
   734                     iAsyncAttachmentAdd->Cancel(); // cancel any outstanding callback just to be safe
   769                     iAsyncAttachmentAdd->Cancel();
   735                     iAsyncAttachmentAdd->Set( TCallBack( AsyncAddAttachment, this ) );
   770                     iAsyncAttachmentAdd->Set( 
       
   771                             TCallBack( AsyncAddAttachment, this ) );
   736                     iAsyncAttachmentAdd->CallBack();
   772                     iAsyncAttachmentAdd->CallBack();
   737                     iContainer->SetMskL();
   773                     iContainer->SetMskL();
   738                     //<cmail> Touch
       
   739                     }                
   774                     }                
   740                 //</cmail>
       
   741            	 	}
   775            	 	}
   742                 break;
   776                 break;
   743             case EFsEmailUiCmdOpenAttachment:
   777             case EFsEmailUiCmdOpenAttachment:
   744             case EFsEmailUiCmdOpenAttachmentList:
   778             case EFsEmailUiCmdOpenAttachmentList:
   745                 {
   779                 {
   746                 DoOpenAttachmentListL();
   780                 DoOpenAttachmentListL();
   747                 }
   781                 }
   748                 break;
   782                 break;
   749             case ENcsCmdRemoveAttachment: // remove one and only attachment
   783             case ENcsCmdRemoveAttachment:
       
   784             case EFsEmailUiCmdRemoveAttachment:
       
   785                 {
       
   786                 TInt index( iContainer->FocusedAttachmentLabelIndex() );
       
   787                 CFreestyleEmailUiSendAttachmentsListControl* ctrl =
       
   788                     AttachmentsListControl();
       
   789                 if ( ctrl && KNoAttachmentLabelFocused != index )
       
   790                     {
       
   791                     ctrl->RemoveAttachmentFromListL( index );
       
   792                     }
       
   793                 SetAttachmentLabelContentL();
       
   794                 }
       
   795                 break;
   750             case ENcsCmdRemoveAllAttachments:
   796             case ENcsCmdRemoveAllAttachments:
   751            	 	{
   797            	 	{
   752            	 	AttachmentsListControl()->RemoveAllAttachmentsL();
   798            	 	CFreestyleEmailUiSendAttachmentsListControl* ctrl =
       
   799                     AttachmentsListControl();
       
   800            	 	if ( ctrl )
       
   801            	 	    {
       
   802            	 	    ctrl->RemoveAllAttachmentsL();
       
   803            	 	    }
   753            	 	SetAttachmentLabelContentL();
   804            	 	SetAttachmentLabelContentL();
   754             	}
   805             	}
   755                 break;
   806                 break;
   756             case ENcsCmdPriorityHigh:
   807             case ENcsCmdPriorityHigh:
   757             	{
   808             	{
   758             	iNewMessage->ResetFlag( EFSMsgFlag_Low );
   809             	iNewMessage->ResetFlag( EFSMsgFlag_Low );
   759             	iNewMessage->SetFlag( EFSMsgFlag_Important );
   810             	iNewMessage->SetFlag( EFSMsgFlag_Important );
   760             	iNewMessage->SaveMessageL();
   811             	iNewMessage->SaveMessageL();
   761             	iStatusPaneIndicators->SetPriorityFlag(EMsgPriorityHigh);
   812             	iStatusPaneIndicators->SetPriorityFlag( EMsgPriorityHigh );
   762             	}
   813             	}
   763                 break;
   814                 break;
   764         	case ENcsCmdPriorityNormal:
   815         	case ENcsCmdPriorityNormal:
   765     	    	{
   816     	    	{
   766             	iNewMessage->ResetFlag( EFSMsgFlag_Low );
   817             	iNewMessage->ResetFlag( EFSMsgFlag_Low );
   767             	iNewMessage->ResetFlag( EFSMsgFlag_Important );
   818             	iNewMessage->ResetFlag( EFSMsgFlag_Important );
   768             	iNewMessage->SaveMessageL();
   819             	iNewMessage->SaveMessageL();
   769             	iStatusPaneIndicators->SetPriorityFlag(EMsgPriorityNormal);
   820             	iStatusPaneIndicators->SetPriorityFlag( EMsgPriorityNormal );
   770     	    	}
   821     	    	}
   771                 break;
   822                 break;
   772         	case ENcsCmdPriorityLow:
   823         	case ENcsCmdPriorityLow:
   773     	    	{
   824     	    	{
   774             	iNewMessage->ResetFlag( EFSMsgFlag_Important );
   825             	iNewMessage->ResetFlag( EFSMsgFlag_Important );
   775             	iNewMessage->SetFlag( EFSMsgFlag_Low );
   826             	iNewMessage->SetFlag( EFSMsgFlag_Low );
   776             	iNewMessage->SaveMessageL();
   827             	iNewMessage->SaveMessageL();
   777             	iStatusPaneIndicators->SetPriorityFlag(EMsgPriorityLow);
   828             	iStatusPaneIndicators->SetPriorityFlag( EMsgPriorityLow );
   778     	    	}
   829     	    	}
   779                 break;
   830                 break;
   780             case ENcsCmdShowCc:
   831             case ENcsCmdShowCc:
   781                 {
   832                 {
   782                 iContainer->SetCcFieldVisibleL( ETrue );
   833                 iContainer->SetCcFieldVisibleL( ETrue );
   825 
   876 
   826             	TRAPD( saveDraftError, DoSaveDraftL( EFalse ) );
   877             	TRAPD( saveDraftError, DoSaveDraftL( EFalse ) );
   827                 if ( saveDraftError == KErrNone )
   878                 if ( saveDraftError == KErrNone )
   828                 	{
   879                 	{
   829                     // Saving successful
   880                     // Saving successful
   830                 	if(!iAppUi.AppUiExitOngoing()) //<cmail>
   881                 	if( !iAppUi.AppUiExitOngoing() )
   831                 	TFsEmailUiUtility::ShowInfoNoteL( R_FREESTYLE_EMAIL_CONFIRM_NOTE_SAVED_TO_DRAFTS, ETrue );
   882                 	TFsEmailUiUtility::ShowInfoNoteL( 
       
   883                         R_FREESTYLE_EMAIL_CONFIRM_NOTE_SAVED_TO_DRAFTS,
       
   884                         ETrue );
   832                     }
   885                     }
   833             	else
   886             	else
   834                     {
   887                     {
   835                     // error occured in saving -> show an error message
   888                     // error occured in saving -> show an error message
   836                     if(!iAppUi.AppUiExitOngoing()) //<cmail>
   889                     if( !iAppUi.AppUiExitOngoing() )
   837                         TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE, ETrue );
   890                         TFsEmailUiUtility::ShowErrorNoteL( 
       
   891                             R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE,
       
   892                             ETrue );
   838                     }
   893                     }
   839 
   894 
   840             	DoSafeExit( ENoSave );
   895             	DoSafeExit( ENoSave );
   841             	}
   896             	}
   842                 break;
   897                 break;
   860                 DoSafeExit();
   915                 DoSafeExit();
   861                 }
   916                 }
   862                 break;
   917                 break;
   863             case ENcsCmdExit:
   918             case ENcsCmdExit:
   864                 {
   919                 {
   865                 // This is for a special case when SaveDeleteQuery appears and user presses immediately End key
   920                 iAppUi.Exit();
   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                 }
   921                 }
   887                 break;
   922                 break;
   888             default:
   923             default:
   889                 {
   924                 {
   890                 // empty implementation
   925                 // empty implementation
   918         {
   953         {
   919         iMailSendFailed = ETrue;
   954         iMailSendFailed = ETrue;
   920         User::Leave( r );
   955         User::Leave( r );
   921         }
   956         }
   922 
   957 
   923     // <cmail> prevent sending failure if original message is
   958     // prevent sending failure if original message is
   924     // removed from server while replying/forwarding
   959     // removed from server while replying/forwarding
   925 	TRAPD( flagError, SetReplyForwardFlagL() );
   960 	TRAPD( flagError, SetReplyForwardFlagL() );
   926 
   961 
   927     if ( KErrNone != flagError && KErrNotFound != flagError )
   962     if ( KErrNone != flagError && KErrNotFound != flagError )
   928         {
   963         {
   929         iMailSendFailed = ETrue;
   964         iMailSendFailed = ETrue;
   930         User::Leave( flagError );
   965         User::Leave( flagError );
   931         }
   966         }
   932     // </cmail>
       
   933 
   967 
   934     iMailSent = ETrue;
   968     iMailSent = ETrue;
   935 
   969 
   936     }
   970     }
   937 
   971 
   965         array->AppendL( *deleteItem );
   999         array->AppendL( *deleteItem );
   966 		CleanupStack::PopAndDestroy( deleteItem );
  1000 		CleanupStack::PopAndDestroy( deleteItem );
   967 
  1001 
   968 		iDlg = new (ELeave) CAknListQueryDialog( &selectedOption );
  1002 		iDlg = new (ELeave) CAknListQueryDialog( &selectedOption );
   969     	iDlg->PrepareLC( R_DRAFT_QUERY_DIALOG );
  1003     	iDlg->PrepareLC( R_DRAFT_QUERY_DIALOG );
   970     	// CleanupStack::Pop(iDlg);
       
   971     	iDlg->SetItemTextArray( array );
  1004     	iDlg->SetItemTextArray( array );
   972     	iDlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
  1005     	iDlg->SetOwnershipType( ELbmDoesNotOwnItemArray );
   973 
  1006 
   974         iCheckQuery = ETrue;
  1007         iCheckQuery = ETrue;
   975         //we are forbiding to change MSK label, cause popup will be opend 
  1008         //we are forbiding to change MSK label, cause popup will be opend 
   976         iContainer->SwitchChangeMskOff(ETrue);
  1009         iContainer->SwitchChangeMskOff( ETrue );
   977         TInt ret = iDlg->RunLD();
  1010         TInt ret = iDlg->RunLD();
   978         iDlg = NULL;
  1011         iDlg = NULL;
   979 
  1012 
   980         iCheckQuery = EFalse; 
  1013         iCheckQuery = EFalse; 
   981         iContainer->SwitchChangeMskOff(EFalse);
  1014         iContainer->SwitchChangeMskOff( EFalse );
   982 
  1015 
   983     	if ( !ret )
  1016     	if ( !ret )
   984     	    {
  1017     	    {
   985     	    selectedOption = KErrCancel;
  1018     	    selectedOption = KErrCancel;
   986     	    }
  1019     	    }
   992 				TRAPD( saveError, SaveToDraftsL( ETrue ) );
  1025 				TRAPD( saveError, SaveToDraftsL( ETrue ) );
   993 
  1026 
   994 				if ( saveError == KErrNone )
  1027 				if ( saveError == KErrNone )
   995 				    {
  1028 				    {
   996 				    // User wanted to save to Drafts and saving was successful
  1029 				    // User wanted to save to Drafts and saving was successful
   997 				    if(!iAppUi.AppUiExitOngoing()) //<cmail>
  1030 				    if( !iAppUi.AppUiExitOngoing() )
   998 				        TFsEmailUiUtility::ShowInfoNoteL( R_FREESTYLE_EMAIL_CONFIRM_NOTE_SAVED_TO_DRAFTS, ETrue );
  1031 				        TFsEmailUiUtility::ShowInfoNoteL( 
       
  1032                             R_FREESTYLE_EMAIL_CONFIRM_NOTE_SAVED_TO_DRAFTS, 
       
  1033                             ETrue );
   999 				    }
  1034 				    }
  1000 				else
  1035 				else
  1001 				    {
  1036 				    {
  1002 
  1037 
  1003 				    // error occured in saving -> show an error message
  1038 				    // error occured in saving -> show an error message
  1004 				    if(!iAppUi.AppUiExitOngoing()) //<cmail>
  1039 				    if( !iAppUi.AppUiExitOngoing() )
  1005 				        TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE, ETrue );
  1040 				        TFsEmailUiUtility::ShowErrorNoteL( 
       
  1041                             R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE,
       
  1042                             ETrue );
  1006 
  1043 
  1007 				    // let's return EFalse so after completing this query
  1044 				    // 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 )
  1045 				    // so the focus would stay in compose view (same behaviour
       
  1046 				    // as if Cancel was pressed )
  1009 				    result = EFalse;
  1047 				    result = EFalse;
  1010 				    }
  1048 				    }
  1011 				}
  1049 				}
  1012                 break;
  1050                 break;
  1013     		case 1:
  1051     		case 1:
  1014     			{
  1052     			{
  1015 				TRAPD( error, SaveToDraftsL( ETrue ) );
  1053 				TRAPD( error, SaveToDraftsL( ETrue ) );
  1016     			if ( KErrNone != error )
  1054     			if ( KErrNone != error )
  1017     			    {
  1055     			    {
  1018     			    }
  1056     			    }
  1019     	        iFakeSyncGoingOn = ETrue; //<cmail> for delete messages fake sync callscalls
  1057     			// for delete messages fake sync calls
       
  1058     	        iFakeSyncGoingOn = ETrue;
  1020                 error = NcsUtility::DeleteMessage( iMailClient,
  1059                 error = NcsUtility::DeleteMessage( iMailClient,
  1021             		iMailBox->GetId(),
  1060             		iMailBox->GetId(),
  1022             		iNewMessage->GetFolderId(),
  1061             		iNewMessage->GetFolderId(),
  1023             		iNewMessage->GetMessageId() );
  1062             		iNewMessage->GetMessageId() );
  1024 
  1063 
  1025     			if ( KErrNone == error && iMailBox->HasCapability( EFSMBoxCapaSupportsDeletedItemsFolder ) )
  1064     			if ( KErrNone == error && 
       
  1065     			     iMailBox->HasCapability( 
       
  1066     			             EFSMBoxCapaSupportsDeletedItemsFolder ) )
  1026     			    {
  1067     			    {
  1027                     error = NcsUtility::DeleteMessage( iMailClient,
  1068                     error = NcsUtility::DeleteMessage( iMailClient,
  1028                 		iMailBox->GetId(),
  1069                 		iMailBox->GetId(),
  1029                 		iMailBox->GetStandardFolderId( EFSDeleted ),
  1070                 		iMailBox->GetStandardFolderId( EFSDeleted ),
  1030                 		iNewMessage->GetMessageId() );
  1071                 		iNewMessage->GetMessageId() );
  1031     			    }
  1072     			    }
  1032     		     iFakeSyncGoingOn = EFalse; //<cmail>
  1073     		     iFakeSyncGoingOn = EFalse;
  1033 
  1074 
  1034                 if( !iAppUi.AppUiExitOngoing() )
  1075                 if( !iAppUi.AppUiExitOngoing() )
  1035                     {
  1076                     {
  1036                     if ( KErrNone != error )
  1077                     if ( KErrNone != error )
  1037                         {
  1078                         {
  1038                         // error occured in saving -> show an error message
  1079                         // error occured in saving -> show an error message
  1039                         TFsEmailUiUtility::ShowErrorNoteL( 
  1080                         TFsEmailUiUtility::ShowErrorNoteL( 
  1040                             R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE, ETrue );
  1081                             R_FREESTYLE_EMAIL_ERROR_GENERAL_UNABLE_TO_COMPLETE,
       
  1082                             ETrue );
  1041                         }
  1083                         }
  1042                     else
  1084                     else
  1043                         {
  1085                         {
  1044                         // Simulate delete event so that drafts folder is
  1086                         // Simulate delete event so that drafts folder is
  1045                         // updated correctly.
  1087                         // updated correctly.
  1059     			{
  1101     			{
  1060     			result = EFalse;
  1102     			result = EFalse;
  1061     			}
  1103     			}
  1062                 break;
  1104                 break;
  1063     		}
  1105     		}
  1064 
       
  1065     	//iCheckQuery = EFalse; //<cmail>
       
  1066     	CleanupStack::PopAndDestroy( array );
  1106     	CleanupStack::PopAndDestroy( array );
  1067         }
  1107         }
  1068     else  // no question from user
  1108     else  // no question from user
  1069         {
  1109         {
  1070         SaveToDraftsL( ETrue );
  1110         SaveToDraftsL( ETrue );
  1091 //
  1131 //
  1092 TInt CNcsComposeView::AsyncAddAttachment( TAny* aSelfPtr )
  1132 TInt CNcsComposeView::AsyncAddAttachment( TAny* aSelfPtr )
  1093     {
  1133     {
  1094     FUNC_LOG;
  1134     FUNC_LOG;
  1095 
  1135 
  1096     CNcsComposeView* self = static_cast<CNcsComposeView*>(aSelfPtr);
  1136     CNcsComposeView* self = static_cast<CNcsComposeView*>( aSelfPtr );
  1097 
  1137 
  1098     // get pointer to attachment list view
  1138     // get pointer to attachment list view
  1099 	CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
  1139 	CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
  1100 	attachmentControl = self->AttachmentsListControl();
  1140 	attachmentControl = self->AttachmentsListControl();
  1101 
  1141 
  1102    	// show file dialog and get file name
  1142    	// show file dialog and get file name
  1103 	TBool ok = EFalse;
  1143 	TBool ok = EFalse;
  1104 	TRAPD( error, ok = attachmentControl->AppendAttachmentToListL(self->iAttachmentAddType) );
  1144 	TRAPD( error, ok = attachmentControl->AppendAttachmentToListL(
       
  1145                 self->iAttachmentAddType) );
  1105 	if ( ok && error == KErrNone )
  1146 	if ( ok && error == KErrNone )
  1106 	    {
  1147 	    {
  1107 	    TRAPD( error, self->SetAttachmentLabelContentL() );
  1148 	    TRAPD( error, self->SetAttachmentLabelContentL() );
  1108 	    return error;
  1149 	    return error;
  1109 	    }
  1150 	    }
  1119     {
  1160     {
  1120     FUNC_LOG;
  1161     FUNC_LOG;
  1121     if ( iNewMessage && TFsEmailUiUtility::IsFollowUpSupported( *iMailBox ) )
  1162     if ( iNewMessage && TFsEmailUiUtility::IsFollowUpSupported( *iMailBox ) )
  1122         {
  1163         {
  1123         TFollowUpNewState newState =
  1164         TFollowUpNewState newState =
  1124             TFsEmailUiUtility::SetMessageFollowupFlagL( *iNewMessage, EFalse );
  1165             TFsEmailUiUtility::SetMessageFollowupFlagL( 
       
  1166                     *iNewMessage, EFalse );
  1125 
  1167 
  1126         switch ( newState )
  1168         switch ( newState )
  1127             {
  1169             {
  1128             case EFollowUp:
  1170             case EFollowUp:
  1129                 {
  1171                 {
  1130                 iStatusPaneIndicators->SetFollowUpFlag( CCustomStatuspaneIndicators::EFollowUp );
  1172                 iStatusPaneIndicators->SetFollowUpFlag( 
       
  1173                         CCustomStatuspaneIndicators::EFollowUp );
  1131                 }
  1174                 }
  1132                 break;
  1175                 break;
  1133             case EFollowUpComplete:
  1176             case EFollowUpComplete:
  1134                 {
  1177                 {
  1135                 iStatusPaneIndicators->SetFollowUpFlag( CCustomStatuspaneIndicators::EFollowUpComplete );
  1178                 iStatusPaneIndicators->SetFollowUpFlag( 
       
  1179                         CCustomStatuspaneIndicators::EFollowUpComplete );
  1136                 }
  1180                 }
  1137                 break;
  1181                 break;
  1138             case EFollowUpClear:
  1182             case EFollowUpClear:
  1139                 {
  1183                 {
  1140                 iStatusPaneIndicators->SetFollowUpFlag( CCustomStatuspaneIndicators::EFollowUpNone );
  1184                 iStatusPaneIndicators->SetFollowUpFlag( 
       
  1185                         CCustomStatuspaneIndicators::EFollowUpNone );
  1141                 }
  1186                 }
  1142                 break;
  1187                 break;
  1143             default:
  1188             default:
  1144                 {
  1189                 {
  1145                 // do nothing.
  1190                 // do nothing.
  1155 // -----------------------------------------------------------------------------
  1200 // -----------------------------------------------------------------------------
  1156 //
  1201 //
  1157 void CNcsComposeView::SetAttachmentLabelContentL()
  1202 void CNcsComposeView::SetAttachmentLabelContentL()
  1158     {
  1203     {
  1159     FUNC_LOG;
  1204     FUNC_LOG;
  1160     if ( iFirstStartCompleted ) // Safety
  1205     if ( iFirstStartCompleted && iContainer )
  1161         {
  1206         {
  1162         CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
  1207         CFreestyleEmailUiSendAttachmentsListControl* 
  1163         attachmentControl = AttachmentsListControl();
  1208             attachmentControl = AttachmentsListControl();
  1164 
  1209         if ( !( attachmentControl && attachmentControl->Model() ) )
       
  1210             {
       
  1211             return;
       
  1212             }
       
  1213         
  1165         // read number of attachments
  1214         // read number of attachments
  1166         TInt count = attachmentControl->Model()->Count();
  1215         TInt count = attachmentControl->Model()->Count();
  1167 
  1216         if ( count > 0 )
  1168         if ( count > 1 )
  1217             {
  1169             {
  1218             // Fill in the name and size descriptor arrays
  1170             TInt totalSizeInBytes = attachmentControl->Model()->TotalAttachmentSize();
  1219             CDesCArrayFlat* nameArray = new (ELeave) CDesCArrayFlat( count );
  1171             HBufC* stringBuf = NULL;
  1220             CleanupStack::PushL( nameArray );
  1172 
  1221             CDesCArrayFlat* sizeArray = new (ELeave) CDesCArrayFlat( count );
  1173             HBufC* sizeDesc = TFsEmailUiUtility::CreateSizeDescLC( totalSizeInBytes );
  1222             CleanupStack::PushL( sizeArray );
  1174             stringBuf = StringLoader::LoadL( R_NCS_ATTACHMENTS_FIELD_TEXT,
  1223 
  1175                                              *sizeDesc, count );
  1224             for ( TInt i(0); i<count; ++i )
  1176             CleanupStack::PopAndDestroy( sizeDesc );
  1225                 {
  1177 
  1226                 CFSEmailUiSendAttachmentsListModelItem* item =
  1178             CleanupStack::PushL( stringBuf );
  1227                     static_cast<CFSEmailUiSendAttachmentsListModelItem*>
  1179             iContainer->SetAttachmentLabelTextL( *stringBuf );
  1228                     ( attachmentControl->Model()->Item( i ) );
  1180             CleanupStack::PopAndDestroy( stringBuf );
  1229                 if ( item )
       
  1230                     {
       
  1231                     nameArray->AppendL( item->FileName() );
       
  1232                     HBufC* sizeDesc = 
       
  1233                         TFsEmailUiUtility::CreateSizeDescLC( 
       
  1234                                 item->FileSize() );
       
  1235                     sizeArray->AppendL( *sizeDesc );
       
  1236                     CleanupStack::PopAndDestroy( sizeDesc );
       
  1237                     }
       
  1238                 }
       
  1239             iContainer->SetAttachmentLabelTextsLD( nameArray, sizeArray );
  1181             iContainer->SetFocusToAttachmentField();
  1240             iContainer->SetFocusToAttachmentField();
  1182             }
  1241             
  1183         else if ( count == 1 )
  1242             CleanupStack::Pop( sizeArray );
  1184             {
  1243             CleanupStack::Pop( nameArray );
  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             }
  1244             }
  1195         else
  1245         else
  1196             {
  1246             {
  1197             iContainer->SetAttachmentLabelTextL( KNullDesC );
  1247             iContainer->SetAttachmentLabelTextsLD( NULL, NULL );
  1198             iContainer->HideAttachmentLabel();
  1248             iContainer->HideAttachmentLabel();
  1199             }
  1249             }
  1200         }
  1250         }
  1201 
       
  1202     }
  1251     }
  1203 
  1252 
  1204 
  1253 
  1205 // -----------------------------------------------------------------------------
  1254 // -----------------------------------------------------------------------------
  1206 // CNcsComposeView::AttachmentsListControl()
  1255 // CNcsComposeView::AttachmentsListControl()
  1207 //
  1256 //
  1208 // -----------------------------------------------------------------------------
  1257 // -----------------------------------------------------------------------------
  1209 //
  1258 //
  1210 CFreestyleEmailUiSendAttachmentsListControl* CNcsComposeView::AttachmentsListControl()
  1259 CFreestyleEmailUiSendAttachmentsListControl* 
       
  1260 CNcsComposeView::AttachmentsListControl()
  1211 	{
  1261 	{
  1212     FUNC_LOG;
  1262     FUNC_LOG;
  1213     CFreestyleEmailUiSendAttachmentsListControl* attachmentControl(0);
  1263     CFreestyleEmailUiSendAttachmentsListControl* attachmentControl( NULL );
  1214     if ( iFirstStartCompleted ) // Safety
  1264     if ( iFirstStartCompleted ) // Safety
  1215         {
  1265         {
  1216         CFSEmailUiSendAttachmentsListVisualiser* attachmentView =
  1266         CFSEmailUiSendAttachmentsListVisualiser* attachmentView =
  1217             static_cast<CFSEmailUiSendAttachmentsListVisualiser*>(
  1267             static_cast<CFSEmailUiSendAttachmentsListVisualiser*>(
  1218                 iAvkonViewAppUi->View( SendAttachmentMngrViewId ) );
  1268                 iAvkonViewAppUi->View( SendAttachmentMngrViewId ) );
  1219         attachmentControl = static_cast<CFreestyleEmailUiSendAttachmentsListControl*>(
  1269         if ( attachmentView )
  1220             attachmentView->ViewerControl() );
  1270             {
       
  1271             attachmentControl = 
       
  1272                 static_cast<CFreestyleEmailUiSendAttachmentsListControl*>(
       
  1273                     attachmentView->ViewerControl() );
       
  1274             }
  1221         }
  1275         }
  1222 	return attachmentControl;
  1276 	return attachmentControl;
  1223 	}
  1277 	}
  1224 
  1278 
  1225 // -----------------------------------------------------------------------------
  1279 // -----------------------------------------------------------------------------
  1249     iMailFetchingErrCode = KErrNone;
  1303     iMailFetchingErrCode = KErrNone;
  1250 
  1304 
  1251     if ( aCustomMessageId == TUid::Uid( KEditorCmdCreateNew ) )
  1305     if ( aCustomMessageId == TUid::Uid( KEditorCmdCreateNew ) )
  1252         {
  1306         {
  1253         iOrigMessage = NULL;
  1307         iOrigMessage = NULL;
  1254         iFakeSyncGoingOn = ETrue;//<cmail> this is actually a waited async method
  1308         iFakeSyncGoingOn = ETrue;
  1255         iNewMessage = iMailBox->CreateMessageToSend();
  1309         iNewMessage = iMailBox->CreateMessageToSend();
  1256         iFakeSyncGoingOn = EFalse;
  1310         iFakeSyncGoingOn = EFalse;
  1257         if ( !iNewMessage )
  1311         if ( !iNewMessage )
  1258             {
  1312             {
  1259             User::Leave( KErrGeneral );
  1313             User::Leave( KErrGeneral );
  1260             }
  1314             }
  1261         iFakeSyncGoingOn = ETrue;
  1315         iFakeSyncGoingOn = ETrue;
  1262         TFsEmailUiUtility::MoveMessageToDraftsL( *iMailBox, *iNewMessage );
  1316         TFsEmailUiUtility::MoveMessageToDraftsL( *iMailBox, *iNewMessage );
  1263         iFakeSyncGoingOn = EFalse;//<cmail>
  1317         iFakeSyncGoingOn = EFalse;
  1264         
  1318         
  1265         if ( iNewMessage->GetContentType() != KFSMailContentTypeMultipartMixed )
  1319         if ( iNewMessage->GetContentType() != 
       
  1320              KFSMailContentTypeMultipartMixed )
  1266             {
  1321             {
  1267             iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1322             iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1268             iNewMessage->SaveMessageL();
  1323             iNewMessage->SaveMessageL();
  1269             }
  1324             }
  1270         
  1325         
  1271         TFsEmailUiUtility::CreatePlainTextPartL( *iNewMessage, iNewMessageTextPart );
  1326         TFsEmailUiUtility::CreatePlainTextPartL( 
       
  1327                 *iNewMessage, iNewMessageTextPart );
  1272         IncludeMessageTextL( ETrue );
  1328         IncludeMessageTextL( ETrue );
  1273         AttachmentsListControl()->Model()->Clear();
  1329         AttachmentsListControl()->Model()->Clear();
  1274         iContainer->SelectAllToFieldTextL();
  1330         iContainer->SelectAllToFieldTextL();
  1275         }
  1331         }
  1276     else if ( aCustomMessageId == TUid::Uid( KEditorCmdReply ) ||
  1332     else if ( aCustomMessageId == TUid::Uid( KEditorCmdReply ) ||
  1277               aCustomMessageId == TUid::Uid( KEditorCmdReplyAll ) )
  1333               aCustomMessageId == TUid::Uid( KEditorCmdReplyAll ) )
  1278         {
  1334         {
  1279 
  1335 
  1280         iOrigMessage = iMailClient.GetMessageByUidL( iLaunchParams.iMailboxId, iLaunchParams.iFolderId, iLaunchParams.iMsgId, EFSMsgDataStructure );
  1336         iOrigMessage = iMailClient.GetMessageByUidL( 
       
  1337                 iLaunchParams.iMailboxId, iLaunchParams.iFolderId,
       
  1338                 iLaunchParams.iMsgId, EFSMsgDataStructure );
  1281         if ( !iOrigMessage )
  1339         if ( !iOrigMessage )
  1282             {
  1340             {
  1283             User::Leave( KErrNotFound );
  1341             User::Leave( KErrNotFound );
  1284             }
  1342             }
  1285 
  1343 
  1286         SafeDelete( iFetchLogic );
  1344         SafeDelete( iFetchLogic );
  1287         iFetchLogic = CFsComposerFetchLogic::NewL( iMailClient, iLaunchParams.iMailboxId,
  1345         iFetchLogic = CFsComposerFetchLogic::NewL( 
  1288                 iOrigMessage->GetFolderId(), iLaunchParams.iMsgId, *this, iAppUi );
  1346                 iMailClient, iLaunchParams.iMailboxId,
       
  1347                 iOrigMessage->GetFolderId(), iLaunchParams.iMsgId, 
       
  1348                 *this, iAppUi );
  1289         ShowFetchingWaitNoteL();
  1349         ShowFetchingWaitNoteL();
  1290         iFetchLogic->RunReplyLogicL();
  1350         iFetchLogic->RunReplyLogicL();
  1291 
  1351 
  1292         // now fetch logic object runs its tasks and gives callback
  1352         // now fetch logic object runs its tasks and gives callback
  1293         // to CNcsComposeView::FetchLogicComplete when it is finished
  1353         // to CNcsComposeView::FetchLogicComplete when it is finished
  1294         }
  1354         }
  1295     else if ( aCustomMessageId == TUid::Uid( KEditorCmdForward ) )
  1355     else if ( aCustomMessageId == TUid::Uid( KEditorCmdForward ) )
  1296         {
  1356         {
  1297 
  1357 
  1298         iOrigMessage = iMailClient.GetMessageByUidL( iLaunchParams.iMailboxId, iLaunchParams.iFolderId, iLaunchParams.iMsgId, EFSMsgDataStructure );
  1358         iOrigMessage = iMailClient.GetMessageByUidL( 
       
  1359                 iLaunchParams.iMailboxId, iLaunchParams.iFolderId, 
       
  1360                 iLaunchParams.iMsgId, EFSMsgDataStructure );
  1299         if ( !iOrigMessage )
  1361         if ( !iOrigMessage )
  1300             {
  1362             {
  1301             User::Leave( KErrNotFound );
  1363             User::Leave( KErrNotFound );
  1302             }
  1364             }
  1303 
  1365 
  1304         SafeDelete( iFetchLogic );
  1366         SafeDelete( iFetchLogic );
  1305         iFetchLogic = CFsComposerFetchLogic::NewL( iMailClient, iLaunchParams.iMailboxId,
  1367         iFetchLogic = CFsComposerFetchLogic::NewL( 
  1306                                                    iOrigMessage->GetFolderId(), iLaunchParams.iMsgId, *this, iAppUi );
  1368                 iMailClient, iLaunchParams.iMailboxId,
       
  1369                 iOrigMessage->GetFolderId(), iLaunchParams.iMsgId, 
       
  1370                 *this, iAppUi );
  1307         ShowFetchingWaitNoteL();
  1371         ShowFetchingWaitNoteL();
  1308         iFetchLogic->RunForwardLogicL();
  1372         iFetchLogic->RunForwardLogicL();
  1309 
  1373 
  1310         // now fetch logic object runs its tasks and gives callback
  1374         // now fetch logic object runs its tasks and gives callback
  1311         // to CNcsComposeView::FetchLogicComplete when it is finished
  1375         // to CNcsComposeView::FetchLogicComplete when it is finished
  1312         }
  1376         }
  1313     else if ( aCustomMessageId == TUid::Uid( KEditorCmdOpen ) ||
  1377     else if ( aCustomMessageId == TUid::Uid( KEditorCmdOpen ) ||
  1314               aCustomMessageId == TUid::Uid( KEditorCmdReturnToPrevious ) ) // for now, we handle returning from attachments list just like any message opening
  1378               aCustomMessageId == TUid::Uid( KEditorCmdReturnToPrevious ) )
  1315         {
  1379         {
  1316 
  1380         // for now, we handle returning from attachments list just like 
  1317         iNewMessage = iMailClient.GetMessageByUidL( iLaunchParams.iMailboxId, iLaunchParams.iFolderId, iLaunchParams.iMsgId, EFSMsgDataStructure );
  1381         // any message opening
       
  1382         iNewMessage = iMailClient.GetMessageByUidL( 
       
  1383                 iLaunchParams.iMailboxId, iLaunchParams.iFolderId, 
       
  1384                 iLaunchParams.iMsgId, EFSMsgDataStructure );
  1318         if ( !iNewMessage )
  1385         if ( !iNewMessage )
  1319             {
  1386             {
  1320             User::Leave( KErrNotFound );
  1387             User::Leave( KErrNotFound );
  1321             }
  1388             }
  1322 
  1389 
  1323         // Show "Opening" wait note if the message body is large
  1390         // Show "Opening" wait note if the message body is large
  1324         TInt waitNoteId = KErrNotFound;
  1391         TInt waitNoteId = KErrNotFound;
  1325         if ( TFsEmailUiUtility::IsMessageBodyLargeL(iNewMessage) )
  1392         if ( TFsEmailUiUtility::IsMessageBodyLargeL(iNewMessage) )
  1326             {
  1393             {
  1327             waitNoteId = TFsEmailUiUtility::ShowGlobalWaitNoteLC( R_FSE_WAIT_OPENING_TEXT );
  1394             waitNoteId = TFsEmailUiUtility::ShowGlobalWaitNoteLC( 
       
  1395                     R_FSE_WAIT_OPENING_TEXT );
  1328             }
  1396             }
  1329 
  1397 
  1330         iOrigMessage = NULL;
  1398         iOrigMessage = NULL;
  1331         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1399         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1332         iNewMessage->SaveMessageL();
  1400         iNewMessage->SaveMessageL();
  1333         TFsEmailUiUtility::CreatePlainTextPartL( *iNewMessage, iNewMessageTextPart );
  1401         TFsEmailUiUtility::CreatePlainTextPartL( 
       
  1402                 *iNewMessage, iNewMessageTextPart );
  1334         InitFieldsL();
  1403         InitFieldsL();
  1335         IncludeMessageTextL();
  1404         IncludeMessageTextL();
  1336         AttachmentsListControl()->Model()->Clear();
  1405         AttachmentsListControl()->Model()->Clear();
  1337         GetAttachmentsFromMailL();
  1406         GetAttachmentsFromMailL();
  1338         SetAttachmentLabelContentL();
  1407         SetAttachmentLabelContentL();
  1347     else if ( aCustomMessageId == TUid::Uid( KEditorCmdInternalMailto ) )
  1416     else if ( aCustomMessageId == TUid::Uid( KEditorCmdInternalMailto ) )
  1348         {
  1417         {
  1349         FUNC_LOG;
  1418         FUNC_LOG;
  1350 
  1419 
  1351         iOrigMessage = NULL;
  1420         iOrigMessage = NULL;
  1352         //<cmail> this is actually a waited async method
       
  1353         iFakeSyncGoingOn = ETrue;
  1421         iFakeSyncGoingOn = ETrue;
  1354         iNewMessage = iMailBox->CreateMessageToSend();
  1422         iNewMessage = iMailBox->CreateMessageToSend();
  1355         iFakeSyncGoingOn = EFalse;
  1423         iFakeSyncGoingOn = EFalse;
  1356         //</cmail>
       
  1357         if ( !iNewMessage )
  1424         if ( !iNewMessage )
  1358             {
  1425             {
  1359             User::Leave( KErrGeneral );
  1426             User::Leave( KErrGeneral );
  1360             }
  1427             }
  1361         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1428         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  1362         iNewMessage->SaveMessageL();
  1429         iNewMessage->SaveMessageL();
  1363 
  1430 
  1364         TFsEmailUiUtility::CreatePlainTextPartL( *iNewMessage, iNewMessageTextPart );
  1431         TFsEmailUiUtility::CreatePlainTextPartL( 
       
  1432                 *iNewMessage, iNewMessageTextPart );
  1365 
  1433 
  1366         IncludeMessageTextL( ETrue );
  1434         IncludeMessageTextL( ETrue );
  1367 
  1435 
  1368         CFSMailAddress* toAddress = static_cast<CFSMailAddress*>( iLaunchParams.iExtra ); // not owned
  1436         CFSMailAddress* toAddress = 
       
  1437             static_cast<CFSMailAddress*>( iLaunchParams.iExtra ); // not owned
  1369         RPointerArray<CNcsEmailAddressObject> toRecipients;
  1438         RPointerArray<CNcsEmailAddressObject> toRecipients;
  1370         CleanupResetAndDestroyClosePushL( toRecipients );
  1439         CleanupResetAndDestroyClosePushL( toRecipients );
  1371         CNcsEmailAddressObject* ncsToAddress = NcsUtility::CreateNcsAddressL( *toAddress );
  1440         CNcsEmailAddressObject* ncsToAddress = 
       
  1441             NcsUtility::CreateNcsAddressL( *toAddress );
  1372         CleanupStack::PushL( ncsToAddress );
  1442         CleanupStack::PushL( ncsToAddress );
  1373         toRecipients.AppendL( ncsToAddress );
  1443         toRecipients.AppendL( ncsToAddress );
  1374         CleanupStack::Pop( ncsToAddress ); // owned by toRecipients now
  1444         CleanupStack::Pop( ncsToAddress ); // owned by toRecipients now
  1375         iContainer->SetToFieldAddressesL( toRecipients );
  1445         iContainer->SetToFieldAddressesL( toRecipients );
  1376         CleanupStack::PopAndDestroy( &toRecipients );
  1446         CleanupStack::PopAndDestroy( &toRecipients );
  1388     {
  1458     {
  1389     FUNC_LOG;
  1459     FUNC_LOG;
  1390 
  1460 
  1391     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
  1461     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
  1392 
  1462 
  1393 	HBufC* title = iEikonEnv->AllocReadResourceLC( R_NCS_QUICK_TEXT_TITLE_TEXT );
  1463 	HBufC* title = 
  1394 	HBufC* buf(0);
  1464         iEikonEnv->AllocReadResourceLC( R_NCS_QUICK_TEXT_TITLE_TEXT );
       
  1465 	HBufC* buf( 0 );
  1395 	TRAPD( err, buf = CNotepadApi::FetchTemplateL( title ) );
  1466 	TRAPD( err, buf = CNotepadApi::FetchTemplateL( title ) );
  1396 	if (err == KLeaveExit)
  1467 	if ( err == KLeaveExit )
  1397 		{ //If end key was pressed the dialog leaves with the above error code.
  1468 	    { 
  1398 			//In that case we must leave as well or the application will become stuck
  1469 		// If end key was pressed the dialog leaves with the above error code.
  1399 			//as the exit will be incomplete.
  1470 	    // In that case we must leave as well or the application will become
  1400 			User::Leave(err);
  1471 	    // stuck as the exit will be incomplete.
  1401 		}
  1472 	    User::Leave( err );
       
  1473 	    }
  1402 		
  1474 		
  1403 	if ( buf && err == KErrNone ) // Safety check, 0 if user cancel
  1475 	if ( buf && err == KErrNone ) // Safety check, 0 if user cancel
  1404 		{
  1476 		{
  1405 		CleanupStack::PushL( buf );
  1477 		CleanupStack::PushL( buf );
  1406 		iContainer->AddQuickTextL( *buf );
  1478 		iContainer->AddQuickTextL( *buf );
  1447     FUNC_LOG;
  1519     FUNC_LOG;
  1448 
  1520 
  1449     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
  1521     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
  1450 
  1522 
  1451     // Get TO recipients
  1523     // Get TO recipients
  1452     RPointerArray<CFSMailAddress>& toRecipients = iNewMessage->GetToRecipients();
  1524     RPointerArray<CFSMailAddress>& toRecipients = 
       
  1525         iNewMessage->GetToRecipients();
  1453     RPointerArray<CNcsEmailAddressObject> recipients;
  1526     RPointerArray<CNcsEmailAddressObject> recipients;
  1454     CleanupResetAndDestroyClosePushL( recipients );
  1527     CleanupResetAndDestroyClosePushL( recipients );
  1455     NcsUtility::ConvertAddressArrayL( toRecipients, recipients );
  1528     NcsUtility::ConvertAddressArrayL( toRecipients, recipients );
  1456     iContainer->SetToFieldAddressesL( recipients );
  1529     iContainer->SetToFieldAddressesL( recipients );
  1457     CleanupStack::PopAndDestroy( &recipients );
  1530     CleanupStack::PopAndDestroy( &recipients );
  1458 
  1531 
  1459     // Get CC recipients
  1532     // Get CC recipients
  1460     RPointerArray<CFSMailAddress>& ccRecipients = iNewMessage->GetCCRecipients();
  1533     RPointerArray<CFSMailAddress>& ccRecipients = 
       
  1534         iNewMessage->GetCCRecipients();
  1461     NcsUtility::ConvertAddressArrayL( ccRecipients, recipients );
  1535     NcsUtility::ConvertAddressArrayL( ccRecipients, recipients );
  1462     iContainer->SetCcFieldAddressesL( recipients );
  1536     iContainer->SetCcFieldAddressesL( recipients );
  1463     recipients.ResetAndDestroy();
  1537     recipients.ResetAndDestroy();
  1464 
  1538 
  1465     // Get BCC recipients
  1539     // Get BCC recipients
  1466     RPointerArray<CFSMailAddress>& bccRecipients = iNewMessage->GetBCCRecipients();
  1540     RPointerArray<CFSMailAddress>& bccRecipients = 
       
  1541         iNewMessage->GetBCCRecipients();
  1467     NcsUtility::ConvertAddressArrayL( bccRecipients, recipients );
  1542     NcsUtility::ConvertAddressArrayL( bccRecipients, recipients );
  1468     iContainer->SetBccFieldAddressesL( recipients );
  1543     iContainer->SetBccFieldAddressesL( recipients );
  1469     recipients.ResetAndDestroy();
  1544     recipients.ResetAndDestroy();
  1470 
  1545 
  1471     // Get subject line from original message
  1546     // Get subject line from original message
  1485 // -----------------------------------------------------------------------------
  1560 // -----------------------------------------------------------------------------
  1486 // CNcsComposeView::RemoveOwnAddress()
  1561 // CNcsComposeView::RemoveOwnAddress()
  1487 //
  1562 //
  1488 // -----------------------------------------------------------------------------
  1563 // -----------------------------------------------------------------------------
  1489 //
  1564 //
  1490 void CNcsComposeView::RemoveOwnAddress( RPointerArray<CNcsEmailAddressObject>& aAddressList )
  1565 void CNcsComposeView::RemoveOwnAddress( 
       
  1566         RPointerArray<CNcsEmailAddressObject>& aAddressList )
  1491     {
  1567     {
  1492     FUNC_LOG;
  1568     FUNC_LOG;
  1493     TInt index = 0;
  1569     TInt index = 0;
  1494     TDesC& ownAddress( iMailBox->OwnMailAddress().GetEmailAddress() );
  1570     TDesC& ownAddress( iMailBox->OwnMailAddress().GetEmailAddress() );
  1495 	while ( index < aAddressList.Count() )
  1571 	while ( index < aAddressList.Count() )
  1507 // -----------------------------------------------------------------------------
  1583 // -----------------------------------------------------------------------------
  1508 // CNcsComposeView::IncludeMessageTextL()
  1584 // CNcsComposeView::IncludeMessageTextL()
  1509 //
  1585 //
  1510 // -----------------------------------------------------------------------------
  1586 // -----------------------------------------------------------------------------
  1511 //
  1587 //
  1512 void CNcsComposeView::IncludeMessageTextL( TBool aEnsureSpaceInBegin /*= EFalse*/ )
  1588 void CNcsComposeView::IncludeMessageTextL( 
       
  1589         TBool aEnsureSpaceInBegin /*= EFalse*/ )
  1513 	{
  1590 	{
  1514     FUNC_LOG;
  1591     FUNC_LOG;
  1515 
  1592 
  1516     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
  1593     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
  1517 
  1594 
  1534             CleanupStack::PopAndDestroy( rawBody );
  1611             CleanupStack::PopAndDestroy( rawBody );
  1535             rawBody = NULL;
  1612             rawBody = NULL;
  1536             CleanupStack::PushL( body );
  1613             CleanupStack::PushL( body );
  1537             }
  1614             }
  1538         }
  1615         }
  1539     // If no modifications were needed, then just set body pointer to point the rawBody
  1616     // If no modifications were needed, then just set body pointer to point
       
  1617     // the rawBody
  1540     if ( !body )
  1618     if ( !body )
  1541         {
  1619         {
  1542         body = rawBody;
  1620         body = rawBody;
  1543         rawBody = NULL;
  1621         rawBody = NULL;
  1544         }
  1622         }
  1545     // Now we have possibly decorated message text in body pointer and in cleanup stack
  1623     // Now we have possibly decorated message text in body pointer and
  1546 
  1624     // in cleanup stack
  1547     // Divide the contents into normal body field and the read-only quote field
  1625 
  1548     TInt readOnlyLength = iNewMessageTextPart->ReadOnlyPartSize() / 2; // convert bytes to words
  1626     // Divide the contents into normal body and the read-only quote fields
  1549     TInt modifiableLength = body->Length() - readOnlyLength;
  1627     // Convert bytes length to words length
  1550 
  1628     TInt readOnlyLength = iNewMessageTextPart->ReadOnlyPartSize() / 2;
  1551     // Remove one newline from the end of the modifiable body if there's read-only quote present.
  1629     if ( body )
  1552     // This is because the field boundary appears as newline on the screen. This newline
  1630     	{
  1553     // is added back when saving the message.
  1631 		TInt modifiableLength = body->Length() - readOnlyLength;
  1554     TInt lfLength = KIMSLineFeed().Length();
  1632 	
  1555     if ( readOnlyLength && modifiableLength >= lfLength &&
  1633 		// Remove one newline from the end of the modifiable body if there's
  1556          body->Mid( modifiableLength-lfLength, lfLength ) == KIMSLineFeed )
  1634 		// read-only quote present. This is because the field boundary appears
  1557         {
  1635 		// as newline on the screen. This newline is added back when saving
  1558         modifiableLength -= lfLength;
  1636 		// the message.
  1559         }
  1637 		TInt lfLength = KIMSLineFeed().Length();
  1560 
  1638 		if ( readOnlyLength && modifiableLength >= lfLength &&
  1561     iContainer->SetBodyContentL( body->Left( modifiableLength ),
  1639 			 body->Mid( modifiableLength-lfLength, lfLength ) == 
  1562         body->Right( readOnlyLength ) );
  1640 			 KIMSLineFeed )
       
  1641 			{
       
  1642 			modifiableLength -= lfLength;
       
  1643 			}
       
  1644 	
       
  1645 		iContainer->SetBodyContentL( body->Left( modifiableLength ),
       
  1646 			body->Right( readOnlyLength ) );
       
  1647     	}
  1563 
  1648 
  1564     CleanupStack::PopAndDestroy( body );
  1649     CleanupStack::PopAndDestroy( body );
  1565     }
  1650     }
  1566 
  1651 
  1567 // -----------------------------------------------------------------------------
  1652 // -----------------------------------------------------------------------------
  1575 
  1660 
  1576     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
  1661     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
  1577 
  1662 
  1578 	// set subject
  1663 	// set subject
  1579 	HBufC* prefix = StringLoader::LoadLC( R_NCS_ENGINE_EMAIL_FORWARD_PREFIX );
  1664 	HBufC* prefix = StringLoader::LoadLC( R_NCS_ENGINE_EMAIL_FORWARD_PREFIX );
  1580 	HBufC* formattedSubject = NcsUtility::FormatSubjectLineL( iOrigMessage->GetSubject(), *prefix );
  1665 	HBufC* formattedSubject = NcsUtility::FormatSubjectLineL( 
       
  1666 	        iOrigMessage->GetSubject(), *prefix );
  1581 	CleanupStack::PushL( formattedSubject );
  1667 	CleanupStack::PushL( formattedSubject );
  1582 	iContainer->SetSubjectL( *formattedSubject );
  1668 	iContainer->SetSubjectL( *formattedSubject );
  1583 	CleanupStack::PopAndDestroy( formattedSubject );
  1669 	CleanupStack::PopAndDestroy( formattedSubject );
  1584 	CleanupStack::PopAndDestroy( prefix );
  1670 	CleanupStack::PopAndDestroy( prefix );
  1585 
  1671 
  1645     FUNC_LOG;
  1731     FUNC_LOG;
  1646 
  1732 
  1647     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
  1733     __ASSERT_DEBUG( iContainer, Panic( ENcsBasicUi ) );
  1648 
  1734 
  1649 	// to
  1735 	// to
  1650  	RPointerArray<CFSMailAddress>& toRecipients = iNewMessage->GetToRecipients();
  1736  	RPointerArray<CFSMailAddress>& toRecipients = 
       
  1737         iNewMessage->GetToRecipients();
  1651 	RPointerArray<CNcsEmailAddressObject> ncsToRecipients;
  1738 	RPointerArray<CNcsEmailAddressObject> ncsToRecipients;
  1652 	CleanupResetAndDestroyClosePushL( ncsToRecipients );
  1739 	CleanupResetAndDestroyClosePushL( ncsToRecipients );
  1653 	NcsUtility::ConvertAddressArrayL( toRecipients, ncsToRecipients );
  1740 	NcsUtility::ConvertAddressArrayL( toRecipients, ncsToRecipients );
  1654  	iContainer->SetToFieldAddressesL( ncsToRecipients );
  1741  	iContainer->SetToFieldAddressesL( ncsToRecipients );
  1655     CleanupStack::PopAndDestroy( &ncsToRecipients );
  1742     CleanupStack::PopAndDestroy( &ncsToRecipients );
  1656 
  1743 
  1657 	// cc
  1744 	// cc
  1658  	RPointerArray<CFSMailAddress>& ccRecipients = iNewMessage->GetCCRecipients();
  1745  	RPointerArray<CFSMailAddress>& ccRecipients = 
       
  1746         iNewMessage->GetCCRecipients();
  1659 	RPointerArray<CNcsEmailAddressObject> ncsCcRecipients;
  1747 	RPointerArray<CNcsEmailAddressObject> ncsCcRecipients;
  1660     CleanupResetAndDestroyClosePushL( ncsCcRecipients );
  1748     CleanupResetAndDestroyClosePushL( ncsCcRecipients );
  1661 	NcsUtility::ConvertAddressArrayL( ccRecipients, ncsCcRecipients );
  1749 	NcsUtility::ConvertAddressArrayL( ccRecipients, ncsCcRecipients );
  1662  	iContainer->SetCcFieldAddressesL( ncsCcRecipients );
  1750  	iContainer->SetCcFieldAddressesL( ncsCcRecipients );
  1663     CleanupStack::PopAndDestroy( &ncsCcRecipients );
  1751     CleanupStack::PopAndDestroy( &ncsCcRecipients );
  1664 
  1752 
  1665 	// bcc
  1753 	// bcc
  1666  	RPointerArray<CFSMailAddress>& bccRecipients = iNewMessage->GetBCCRecipients();
  1754  	RPointerArray<CFSMailAddress>& bccRecipients = 
       
  1755         iNewMessage->GetBCCRecipients();
  1667 	RPointerArray<CNcsEmailAddressObject> ncsBccRecipients;
  1756 	RPointerArray<CNcsEmailAddressObject> ncsBccRecipients;
  1668     CleanupResetAndDestroyClosePushL( ncsBccRecipients );
  1757     CleanupResetAndDestroyClosePushL( ncsBccRecipients );
  1669 	NcsUtility::ConvertAddressArrayL( bccRecipients, ncsBccRecipients );
  1758 	NcsUtility::ConvertAddressArrayL( bccRecipients, ncsBccRecipients );
  1670  	iContainer->SetBccFieldAddressesL( ncsBccRecipients );
  1759  	iContainer->SetBccFieldAddressesL( ncsBccRecipients );
  1671     CleanupStack::PopAndDestroy( &ncsBccRecipients );
  1760     CleanupStack::PopAndDestroy( &ncsBccRecipients );
  1709 // -----------------------------------------------------------------------------
  1798 // -----------------------------------------------------------------------------
  1710 // CNcsComposeView::CommitL()
  1799 // CNcsComposeView::CommitL()
  1711 //
  1800 //
  1712 // -----------------------------------------------------------------------------
  1801 // -----------------------------------------------------------------------------
  1713 //
  1802 //
  1714 void CNcsComposeView::CommitL( TBool aParseAddresses, TFieldToCommit aFieldToCommit )
  1803 void CNcsComposeView::CommitL( 
       
  1804         TBool aParseAddresses, TFieldToCommit aFieldToCommit )
  1715     {
  1805     {
  1716     FUNC_LOG;
  1806     FUNC_LOG;
  1717     __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
  1807     __ASSERT_DEBUG( iNewMessage, Panic( ENcsBasicUi ) );
  1718 	__ASSERT_DEBUG( iNewMessageTextPart, Panic( ENcsBasicUi ) );
  1808 	__ASSERT_DEBUG( iNewMessageTextPart, Panic( ENcsBasicUi ) );
  1719 
  1809 
  1754 	if ( commitToField )
  1844 	if ( commitToField )
  1755 		{
  1845 		{
  1756 	    // get addresses from UI to MSG object
  1846 	    // get addresses from UI to MSG object
  1757 	    RPointerArray<CFSMailAddress> toAddresses;
  1847 	    RPointerArray<CFSMailAddress> toAddresses;
  1758 	    CleanupResetAndDestroyClosePushL( toAddresses );
  1848 	    CleanupResetAndDestroyClosePushL( toAddresses );
  1759 	    NcsUtility::ConvertAddressArrayL( iContainer->GetToFieldAddressesL( aParseAddresses ), toAddresses );
  1849 	    NcsUtility::ConvertAddressArrayL( 
       
  1850 	            iContainer->GetToFieldAddressesL( aParseAddresses ), 
       
  1851 	            toAddresses );
  1760 	    iNewMessage->GetToRecipients().ResetAndDestroy();
  1852 	    iNewMessage->GetToRecipients().ResetAndDestroy();
  1761 	    for ( TInt i = 0 ; i < toAddresses.Count() ; i++ )
  1853 	    for ( TInt i = 0 ; i < toAddresses.Count() ; i++ )
  1762 	    	{
  1854 	    	{
  1763 	    	iNewMessage->AppendToRecipient( toAddresses[i] );
  1855 	    	iNewMessage->AppendToRecipient( toAddresses[i] );
  1764 	        // Ownership of the message pointer was transferred from our array to iNewMessage
  1856 	        // Ownership of the message pointer was transferred from our array
       
  1857 	    	// to iNewMessage
  1765 	        toAddresses[i] = NULL;
  1858 	        toAddresses[i] = NULL;
  1766 	    	}
  1859 	    	}
  1767 	    CleanupStack::PopAndDestroy( &toAddresses );
  1860 	    CleanupStack::PopAndDestroy( &toAddresses );
  1768 		}
  1861 		}
  1769 
  1862 
  1770 	if ( commitCcField )
  1863 	if ( commitCcField )
  1771 		{
  1864 		{
  1772 	    RPointerArray<CFSMailAddress> ccAddresses;
  1865 	    RPointerArray<CFSMailAddress> ccAddresses;
  1773 	    CleanupResetAndDestroyClosePushL( ccAddresses );
  1866 	    CleanupResetAndDestroyClosePushL( ccAddresses );
  1774 	    NcsUtility::ConvertAddressArrayL( iContainer->GetCcFieldAddressesL( aParseAddresses ), ccAddresses );
  1867 	    NcsUtility::ConvertAddressArrayL( 
       
  1868 	            iContainer->GetCcFieldAddressesL( aParseAddresses ), 
       
  1869 	            ccAddresses );
  1775 	    iNewMessage->GetCCRecipients().ResetAndDestroy();
  1870 	    iNewMessage->GetCCRecipients().ResetAndDestroy();
  1776 	    for ( TInt i = 0 ; i < ccAddresses.Count() ; i++ )
  1871 	    for ( TInt i = 0 ; i < ccAddresses.Count() ; i++ )
  1777 	    	{
  1872 	    	{
  1778 	    	iNewMessage->AppendCCRecipient( ccAddresses[i] );
  1873 	    	iNewMessage->AppendCCRecipient( ccAddresses[i] );
  1779 	        // Ownership of the message pointer was transferred from our array to iNewMessage
  1874 	        // Ownership of the message pointer was transferred from 
       
  1875 	    	// our array to iNewMessage
  1780 	        ccAddresses[i] = NULL;
  1876 	        ccAddresses[i] = NULL;
  1781 	    	}
  1877 	    	}
  1782 	    CleanupStack::PopAndDestroy( &ccAddresses );
  1878 	    CleanupStack::PopAndDestroy( &ccAddresses );
  1783 		}
  1879 		}
  1784 
  1880 
  1785 	if ( commitBccField )
  1881 	if ( commitBccField )
  1786 		{
  1882 		{
  1787 	    RPointerArray<CFSMailAddress> bccAddresses;
  1883 	    RPointerArray<CFSMailAddress> bccAddresses;
  1788 	    CleanupResetAndDestroyClosePushL( bccAddresses );
  1884 	    CleanupResetAndDestroyClosePushL( bccAddresses );
  1789 	    NcsUtility::ConvertAddressArrayL( iContainer->GetBccFieldAddressesL( aParseAddresses ), bccAddresses );
  1885 	    NcsUtility::ConvertAddressArrayL( 
       
  1886 	            iContainer->GetBccFieldAddressesL( aParseAddresses ), 
       
  1887 	            bccAddresses );
  1790 	    iNewMessage->GetBCCRecipients().ResetAndDestroy();
  1888 	    iNewMessage->GetBCCRecipients().ResetAndDestroy();
  1791 	    for ( TInt i = 0; i < bccAddresses.Count() ; i++ )
  1889 	    for ( TInt i = 0; i < bccAddresses.Count() ; i++ )
  1792 	    	{
  1890 	    	{
  1793 	    	iNewMessage->AppendBCCRecipient( bccAddresses[i] );
  1891 	    	iNewMessage->AppendBCCRecipient( bccAddresses[i] );
  1794 	        // Ownership of the message pointer was transferred from our array to iNewMessage
  1892 	        // Ownership of the message pointer was transferred from 
       
  1893 	    	// our array to iNewMessage
  1795 	        bccAddresses[i] = NULL;
  1894 	        bccAddresses[i] = NULL;
  1796 	    	}
  1895 	    	}
  1797 	    CleanupStack::PopAndDestroy( &bccAddresses );
  1896 	    CleanupStack::PopAndDestroy( &bccAddresses );
  1798 		}
  1897 		}
  1799 
  1898 
  1800 	if ( commitSubjectField )
  1899 	if ( commitSubjectField )
  1801 	    {
  1900 	    {
  1802 	    // get subject from UI to MSG object
  1901 	    // get subject from UI to MSG object
  1803 	    HBufC* subject = iContainer->GetSubjectLC();
  1902 	    HBufC* subject = iContainer->GetSubjectLC();
  1804 	    TPtr ptr = subject->Des();
  1903 	    TPtr ptr = subject->Des();
  1805 		// replace new line characters with spaces as Subject is normally one line only
  1904 		// replace new line characters with spaces as Subject is normally
  1806 	    AknTextUtils::ReplaceCharacters( ptr, KLineSeparators, KReplacementChar );
  1905 	    // one line only
       
  1906 	    AknTextUtils::ReplaceCharacters( 
       
  1907 	            ptr, KLineSeparators, KReplacementChar );
  1807 	    iNewMessage->SetSubject( *subject );
  1908 	    iNewMessage->SetSubject( *subject );
  1808 	    CleanupStack::PopAndDestroy( subject );
  1909 	    CleanupStack::PopAndDestroy( subject );
  1809 	    }
  1910 	    }
  1810 
  1911 
  1811     if ( commitBodyField )
  1912     if ( commitBodyField )
  1812         {
  1913         {
  1813         HBufC* body = iContainer->GetBodyContentLC();
  1914         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
  1915         TPtr bodyPtr = body->Des(); // this TPtr is needed only because of
       
  1916         // incorrect argument type in FW API, can be removed when API fixed
  1815         iNewMessageTextPart->SetContent( bodyPtr );
  1917         iNewMessageTextPart->SetContent( bodyPtr );
  1816         CleanupStack::PopAndDestroy( body );
  1918         CleanupStack::PopAndDestroy( body );
  1817 
  1919 
  1818         TInt error = KErrNone;
  1920         TInt error = KErrNone;
  1819         if ( iNewMessageTextPart )
  1921         if ( iNewMessageTextPart )
  1853 // -----------------------------------------------------------------------------
  1955 // -----------------------------------------------------------------------------
  1854 void CNcsComposeView::DoExitL( TExitMode aMode )
  1956 void CNcsComposeView::DoExitL( TExitMode aMode )
  1855     {
  1957     {
  1856     FUNC_LOG;
  1958     FUNC_LOG;
  1857 
  1959 
  1858     //<cmail>
       
  1859     TBool emptyMessage = ETrue;
  1960     TBool emptyMessage = ETrue;
  1860 
  1961 
  1861     if ( iAutoSaver && iContainer )
  1962     if ( iAutoSaver && iContainer )
  1862         {
  1963         {
  1863         iAutoSaver->Enable( EFalse );
  1964         iAutoSaver->Enable( EFalse );
  1864 
  1965 
  1865         // check that there's some user input in some header field or in message body
  1966         // check for some user input in some header field or in message body
  1866     	TInt attaCount = AttachmentsListControl()->Model()->Count();
  1967     	TInt attaCount = AttachmentsListControl()->Model()->Count();
  1867         emptyMessage =  iContainer->AreAddressFieldsEmpty() &&
  1968         emptyMessage =  iContainer->AreAddressFieldsEmpty() &&
  1868             iContainer->IsSubjectFieldEmpty() &&
  1969             iContainer->IsSubjectFieldEmpty() &&
  1869             iContainer->GetMessageFieldLength() < 1 &&
  1970             iContainer->GetMessageFieldLength() < 1 &&
  1870             attaCount <= 0;
  1971             attaCount <= 0;
  1871 	    }
  1972 	    }
  1872     //</cmail>
       
  1873 
  1973 
  1874     // Consider saving the draft if the message is not completely empty
  1974     // Consider saving the draft if the message is not completely empty
  1875     if ( !emptyMessage )
  1975     if ( !emptyMessage )
  1876         {
  1976         {
  1877         if ( aMode == ESaveDraftQuery && !iMailSent && !iMailSendFailed )
  1977         if ( aMode == ESaveDraftQuery && !iMailSent && !iMailSendFailed )
  1878             {
  1978             {
  1879             TBool actionSucceeded = EFalse;
  1979             TBool actionSucceeded = EFalse;
  1880 
  1980 
  1881             // DoSaveDraftL returns EFalse if the user query was cancelled or saving to Drafts failed
  1981             // DoSaveDraftL returns EFalse if the user query was cancelled
       
  1982             // or saving to Drafts failed
  1882             TRAPD( saveDraftError, actionSucceeded = DoSaveDraftL( ETrue ) );
  1983             TRAPD( saveDraftError, actionSucceeded = DoSaveDraftL( ETrue ) );
  1883             if ( saveDraftError == KErrNone )
  1984             if ( saveDraftError == KErrNone )
  1884                 {
  1985                 {
  1885                 if ( !actionSucceeded )
  1986                 if ( !actionSucceeded )
  1886                     {
  1987                     {
  1887                     // return to normal action (cancel was pressed in the query)
  1988                     // return to normal action 
       
  1989                     // (cancel was pressed in the query)
  1888                     iAutoSaver->Enable( ETrue );
  1990                     iAutoSaver->Enable( ETrue );
  1889                     return;
  1991                     return;
  1890                     }
  1992                     }
  1891                 }
  1993                 }
  1892             else
  1994             else
  1896         else if ( aMode == ESaveDraft )
  1998         else if ( aMode == ESaveDraft )
  1897             {
  1999             {
  1898             DoSaveDraftL( EFalse );
  2000             DoSaveDraftL( EFalse );
  1899             }
  2001             }
  1900         }
  2002         }
  1901     else if ( iNewMessage ) // <cmail> message is empty; delete the draft if it has been already saved earlier
  2003     else if ( iNewMessage ) // message is empty 
  1902         {
  2004         {
       
  2005         // delete the draft if it has been already saved earlier
  1903         TInt err = NcsUtility::DeleteMessage( iMailClient, iMailBox->GetId(),
  2006         TInt err = NcsUtility::DeleteMessage( iMailClient, iMailBox->GetId(),
  1904             iNewMessage->GetFolderId(), iNewMessage->GetMessageId() );
  2007             iNewMessage->GetFolderId(), iNewMessage->GetMessageId() );
  1905         if ( !err && iMailBox->HasCapability( EFSMBoxCapaSupportsDeletedItemsFolder ) )
  2008         if ( !err && iMailBox->HasCapability( 
       
  2009                 EFSMBoxCapaSupportsDeletedItemsFolder ) )
  1906             {
  2010             {
  1907             err = NcsUtility::DeleteMessage( iMailClient, iMailBox->GetId(),
  2011             err = NcsUtility::DeleteMessage( iMailClient, iMailBox->GetId(),
  1908                 iMailBox->GetStandardFolderId( EFSDeleted ),
  2012                 iMailBox->GetStandardFolderId( EFSDeleted ),
  1909                 iNewMessage->GetMessageId() );
  2013                 iNewMessage->GetMessageId() );
  1910             }
  2014             }
  1922                 mailboxId, &messageIds, &folderId, NULL );
  2026                 mailboxId, &messageIds, &folderId, NULL );
  1923             CleanupStack::PopAndDestroy( &messageIds );
  2027             CleanupStack::PopAndDestroy( &messageIds );
  1924             }
  2028             }
  1925         }
  2029         }
  1926 
  2030 
  1927     // <cmail>
       
  1928     // Clear attachment control now that message has been sent
  2031     // Clear attachment control now that message has been sent
  1929     // othewise this will kind of leak memory by leaving attachments
  2032     // othewise this will kind of leak memory by leaving attachments
  1930     // in the list, even if they have been sent.
  2033     // in the list, even if they have been sent.
  1931     CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
  2034     CFreestyleEmailUiSendAttachmentsListControl* attachmentControl;
  1932     attachmentControl = AttachmentsListControl();
  2035     attachmentControl = AttachmentsListControl();
  1933     if ( attachmentControl && attachmentControl->Model() )
  2036     if ( attachmentControl && attachmentControl->Model() )
  1934         {
  2037         {
  1935         attachmentControl->Model()->Clear();
  2038         attachmentControl->Model()->Clear();
  1936         }
  2039         }
  1937     // </cmail>
       
  1938 
       
  1939     ExitComposer();
  2040     ExitComposer();
  1940 
       
  1941     }
  2041     }
  1942 
  2042 
  1943 // -----------------------------------------------------------------------------
  2043 // -----------------------------------------------------------------------------
  1944 // CNcsComposeView::DoOpenAttachmentList
  2044 // CNcsComposeView::DoOpenAttachmentList
  1945 // Saves current editor message to drafts and opens attachment list view
  2045 // Opens the currently focused attachment
  1946 // -----------------------------------------------------------------------------
  2046 // -----------------------------------------------------------------------------
  1947 void CNcsComposeView::DoOpenAttachmentListL()
  2047 void CNcsComposeView::DoOpenAttachmentListL()
  1948 	{
  2048 	{
  1949     FUNC_LOG;
  2049     FUNC_LOG;
  1950 
  2050 
  1951     CFreestyleEmailUiSendAttachmentsListControl* attachmentControl
  2051     CFreestyleEmailUiSendAttachmentsListControl* attachmentControl
  1952    		= AttachmentsListControl();
  2052    		= AttachmentsListControl();
  1953 
  2053 
  1954    	if ( attachmentControl->Model()->Count() == 1 )
  2054     TInt index( iContainer ? iContainer->FocusedAttachmentLabelIndex() 
  1955    		{
  2055             : KNoAttachmentLabelFocused );
  1956 		CFSEmailUiSendAttachmentsListModelItem* item =
  2056     if ( KNoAttachmentLabelFocused != index && 
  1957 			static_cast<CFSEmailUiSendAttachmentsListModelItem*>(
  2057          attachmentControl && attachmentControl->Model() )
  1958 					attachmentControl->Model()->Item( 0 ) );
  2058         {
  1959 		if ( !item->IsRemote() ) // we cannot open remote attachments
  2059         CFSEmailUiSendAttachmentsListModelItem* item =
  1960 		    {
  2060             static_cast<CFSEmailUiSendAttachmentsListModelItem*>(
  1961     		CFSMailMessagePart* msgPart = iNewMessage->ChildPartL( item->MailMsgPartId() );
  2061                     attachmentControl->Model()->Item( index ) );
  1962     		CleanupStack::PushL( msgPart );
  2062             
       
  2063         if ( item && !item->IsRemote() ) // cannot open remote attachments
       
  2064             {
       
  2065             CFSMailMessagePart* msgPart = 
       
  2066                 iNewMessage->ChildPartL( item->MailMsgPartId() );
       
  2067             CleanupStack::PushL( msgPart );
  1963             TFsEmailUiUtility::OpenAttachmentL( *msgPart );
  2068             TFsEmailUiUtility::OpenAttachmentL( *msgPart );
  1964     		CleanupStack::PopAndDestroy( msgPart );
  2069             CleanupStack::PopAndDestroy( msgPart );
  1965 		    }
  2070             }
  1966    		}
  2071         }
  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 	}
  2072 	}
  1997 
  2073 
  1998 // -----------------------------------------------------------------------------
  2074 // -----------------------------------------------------------------------------
  1999 // CNcsComposeView::LaunchAttachmentActionMenuL
  2075 // CNcsComposeView::LaunchStylusPopupMenu
  2000 // Show action menu for the attachments line
  2076 // Show stylus popup menu for the attachments line
  2001 // -----------------------------------------------------------------------------
  2077 // -----------------------------------------------------------------------------
  2002 //
  2078 //
  2003 void CNcsComposeView::LaunchAttachmentActionMenuL()
  2079 void CNcsComposeView::LaunchStylusPopupMenu( const TPoint& aPenEventScreenLocation )
  2004     {
  2080     {
  2005     FUNC_LOG;
  2081     FUNC_LOG;
  2006 
  2082     
  2007     // Remove old items from action menu
  2083     CFSEmailUiSendAttachmentsListModel* attachmentModel =
  2008     CFSEmailUiActionMenu::RemoveAllL();
  2084         ( AttachmentsListControl() ? 
  2009 
  2085                 AttachmentsListControl()->Model() : NULL ); 
  2010     // Construct item list
  2086     TInt count( attachmentModel ? attachmentModel->Count() : 0 );
  2011     RFsEActionMenuIdList itemList;
  2087     TBool attachmentsInModel( count > 0 );
  2012     CleanupClosePushL( itemList );
  2088     CFSEmailUiSendAttachmentsListModelItem* item( NULL );
  2013 
  2089    
  2014     CFreestyleEmailUiSendAttachmentsListControl* attachmentControl =
  2090     if ( attachmentsInModel )
  2015         AttachmentsListControl();
  2091         {
  2016     TInt count = attachmentControl->Model()->Count();
  2092         item = static_cast<CFSEmailUiSendAttachmentsListModelItem*>( 
  2017     TBool remoteAtt = AttachmentsListControl()->Model()->HasRemoteAttachments();
  2093                 attachmentModel->Item( 
  2018     TBool readOnlyAtt = AttachmentsListControl()->Model()->HasReadOnlyAttachments();
  2094                     iContainer->FocusedAttachmentLabelIndex() ) );
  2019 
  2095         if ( !item || item->IsRemote() )
  2020     // Open/View all
  2096             {
  2021     if ( count == 1 && !remoteAtt )
  2097             // Only non-remote attachments can be opened
  2022         {
  2098             iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdOpenAttachment, ETrue );
  2023         itemList.AppendL( FsEActionAttachmentOpen );
  2099             }
  2024         }
  2100         }
  2025     else if ( count > 1 )
  2101 
  2026         {
  2102     if ( !item || item->IsReadOnly() )
  2027         itemList.AppendL( FsEActionAttachmentViewAll );
  2103         {
  2028         }
  2104         // Only non-readonly attachments can be removed
  2029 
  2105         iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdRemoveAttachment, ETrue );
  2030     // Add
  2106         }
  2031     itemList.AppendL( FsEActionAttachmentAdd );
  2107 
  2032 
  2108     // Set the position for the popup
  2033     // Remove/Remove all
  2109 	iStylusPopUpMenu->SetPosition( aPenEventScreenLocation );
  2034     if ( !readOnlyAtt )
  2110 
  2035         {
  2111 	// Display the popup.
  2036         if ( count == 1 )
  2112 	iStylusPopUpMenu->ShowMenu();
  2037             {
  2113     }
  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 
  2114 
  2087 // -----------------------------------------------------------------------------
  2115 // -----------------------------------------------------------------------------
  2088 // CNcsComposeView::GetAttachmentsFromMail
  2116 // CNcsComposeView::GetAttachmentsFromMail
  2089 // -----------------------------------------------------------------------------
  2117 // -----------------------------------------------------------------------------
  2090 void CNcsComposeView::GetAttachmentsFromMailL()
  2118 void CNcsComposeView::GetAttachmentsFromMailL()
  2098 	TRAP( error, iNewMessage->AttachmentListL( attachments ) );
  2126 	TRAP( error, iNewMessage->AttachmentListL( attachments ) );
  2099 	User::LeaveIfError( error );
  2127 	User::LeaveIfError( error );
  2100 
  2128 
  2101 	for ( TInt i=0; i<attachments.Count(); ++i )
  2129 	for ( TInt i=0; i<attachments.Count(); ++i )
  2102 		{
  2130 		{
  2103         TFileType fileType = TFsEmailUiUtility::GetFileType( attachments[i]->AttachmentNameL(),
  2131         TFileType fileType = TFsEmailUiUtility::GetFileType( 
  2104                                                              attachments[i]->GetContentType() );
  2132                 attachments[i]->AttachmentNameL(),
       
  2133                 attachments[i]->GetContentType() );
  2105 
  2134 
  2106         TBool isReadOnly = ( attachments[i]->ReadOnlyPartSize() > 0 );
  2135         TBool isReadOnly = ( attachments[i]->ReadOnlyPartSize() > 0 );
  2107         TBool isRemote = EFalse;
  2136         TBool isRemote = EFalse;
  2108 
  2137 
  2109 		if ( attachments[i]->FetchedContentSize() < attachments[i]->ContentSize() )
  2138 		if ( attachments[i]->FetchedContentSize() < 
       
  2139 		     attachments[i]->ContentSize() )
  2110 			{
  2140 			{
  2111 			if ( iMailBox->HasCapability( EFSMBoxCapaSmartForward ) )
  2141 			if ( iMailBox->HasCapability( EFSMBoxCapaSmartForward ) )
  2112 			    {
  2142 			    {
  2113 			    isRemote = ETrue;
  2143 			    isRemote = ETrue;
  2114 			    }
  2144 			    }
  2164     FUNC_LOG;
  2194     FUNC_LOG;
  2165 
  2195 
  2166     __ASSERT_DEBUG( iOrigMessage, Panic( ENcsBasicUi ) );
  2196     __ASSERT_DEBUG( iOrigMessage, Panic( ENcsBasicUi ) );
  2167 
  2197 
  2168 	// separator line
  2198 	// separator line
  2169 	HBufC* separator = StringLoader::LoadLC( R_NCS_ENGINE_EMAIL_MESSAGE_LINE_SEPARATOR ); //1
  2199 	HBufC* separator = 
       
  2200         StringLoader::LoadLC( R_NCS_ENGINE_EMAIL_MESSAGE_LINE_SEPARATOR ); //1
  2170 
  2201 
  2171 	// from line
  2202 	// from line
  2172 	RPointerArray<CNcsEmailAddressObject> senderArray;
  2203 	RPointerArray<CNcsEmailAddressObject> senderArray;
  2173 	CleanupResetAndDestroyClosePushL( senderArray );
  2204 	CleanupResetAndDestroyClosePushL( senderArray );
  2174     CFSMailAddress* sender = iOrigMessage->GetSender();
  2205     CFSMailAddress* sender = iOrigMessage->GetSender();
  2175     if ( sender )
  2206     if ( sender )
  2176         {
  2207         {
  2177     	CNcsEmailAddressObject* ncsSender = NcsUtility::CreateNcsAddressL( *sender );
  2208     	CNcsEmailAddressObject* ncsSender = 
       
  2209             NcsUtility::CreateNcsAddressL( *sender );
  2178     	CleanupStack::PushL( ncsSender );
  2210     	CleanupStack::PushL( ncsSender );
  2179 	    senderArray.AppendL( ncsSender );
  2211 	    senderArray.AppendL( ncsSender );
  2180 	    CleanupStack::Pop( ncsSender ); // now owned by senderArray
  2212 	    CleanupStack::Pop( ncsSender ); // now owned by senderArray
  2181         }
  2213         }
  2182 	HBufC* fromLine = NcsUtility::GenerateFromLineToMessageBodyL( senderArray );
  2214 	HBufC* fromLine = 
       
  2215         NcsUtility::GenerateFromLineToMessageBodyL( senderArray );
  2183 	CleanupStack::PopAndDestroy( &senderArray );
  2216 	CleanupStack::PopAndDestroy( &senderArray );
  2184 	CleanupStack::PushL( fromLine ); //2
  2217 	CleanupStack::PushL( fromLine ); //2
  2185 
  2218 
  2186 	// sent line
  2219 	// sent line
  2187 	HBufC* sentLine = NcsUtility::GenerateSentLineToMessageBodyL( *iOrigMessage );
  2220 	HBufC* sentLine = 
       
  2221         NcsUtility::GenerateSentLineToMessageBodyL( *iOrigMessage );
  2188 	CleanupStack::PushL( sentLine ); //3
  2222 	CleanupStack::PushL( sentLine ); //3
  2189 
  2223 
  2190 	// to line
  2224 	// to line
  2191 	RPointerArray<CNcsEmailAddressObject> ncsToRecipients;
  2225 	RPointerArray<CNcsEmailAddressObject> ncsToRecipients;
  2192 	CleanupResetAndDestroyClosePushL( ncsToRecipients );
  2226 	CleanupResetAndDestroyClosePushL( ncsToRecipients );
  2193 	RPointerArray<CFSMailAddress>& toRecipients = iOrigMessage->GetToRecipients();
  2227 	RPointerArray<CFSMailAddress>& toRecipients = 
       
  2228         iOrigMessage->GetToRecipients();
  2194 	NcsUtility::ConvertAddressArrayL( toRecipients, ncsToRecipients );
  2229 	NcsUtility::ConvertAddressArrayL( toRecipients, ncsToRecipients );
  2195 	HBufC* toLine = NcsUtility::GenerateAddressLineToMessageBodyL( ncsToRecipients, NcsUtility::ERecipientTypeTo );
  2230 	HBufC* toLine = NcsUtility::GenerateAddressLineToMessageBodyL( 
       
  2231                 ncsToRecipients, NcsUtility::ERecipientTypeTo );
  2196     CleanupStack::PopAndDestroy( &ncsToRecipients );
  2232     CleanupStack::PopAndDestroy( &ncsToRecipients );
  2197 	CleanupStack::PushL( toLine ); //4
  2233 	CleanupStack::PushL( toLine ); //4
  2198 
  2234 
  2199 	// cc line
  2235 	// cc line
  2200 	RPointerArray<CFSMailAddress>& ccRecipients = iOrigMessage->GetCCRecipients();
  2236 	RPointerArray<CFSMailAddress>& ccRecipients = 
       
  2237         iOrigMessage->GetCCRecipients();
  2201 	TBool hasCcLine = ( ccRecipients.Count() > 0 );
  2238 	TBool hasCcLine = ( ccRecipients.Count() > 0 );
  2202     HBufC* ccLine = NULL;
  2239     HBufC* ccLine = NULL;
  2203 	if ( hasCcLine )
  2240 	if ( hasCcLine )
  2204 		{
  2241 		{
  2205 	    RPointerArray<CNcsEmailAddressObject> ncsCcRecipients;
  2242 	    RPointerArray<CNcsEmailAddressObject> ncsCcRecipients;
  2206 	    CleanupResetAndDestroyClosePushL( ncsCcRecipients );
  2243 	    CleanupResetAndDestroyClosePushL( ncsCcRecipients );
  2207 		NcsUtility::ConvertAddressArrayL( ccRecipients, ncsCcRecipients );
  2244 		NcsUtility::ConvertAddressArrayL( ccRecipients, ncsCcRecipients );
  2208 		ccLine = NcsUtility::GenerateAddressLineToMessageBodyL( ncsCcRecipients, NcsUtility::ERecipientTypeCc );
  2245 		ccLine = NcsUtility::GenerateAddressLineToMessageBodyL( 
       
  2246 		        ncsCcRecipients, NcsUtility::ERecipientTypeCc );
  2209 	    CleanupStack::PopAndDestroy( &ncsCcRecipients );
  2247 	    CleanupStack::PopAndDestroy( &ncsCcRecipients );
  2210 		CleanupStack::PushL( ccLine ); //5
  2248 		CleanupStack::PushL( ccLine ); //5
  2211 		}
  2249 		}
  2212 
  2250 
  2213 	// subject line
  2251 	// subject line
  2214 	HBufC* subjectLine = NcsUtility::GenerateSubjectLineToMessageBodyL( iOrigMessage->GetSubject() );
  2252 	HBufC* subjectLine = NcsUtility::GenerateSubjectLineToMessageBodyL( 
       
  2253 	        iOrigMessage->GetSubject() );
  2215 	CleanupStack::PushL( subjectLine ); //6
  2254 	CleanupStack::PushL( subjectLine ); //6
  2216 
  2255 
  2217     // Body
  2256     // Body
  2218     HBufC* body = NULL;
  2257     HBufC* body = NULL;
  2219     TBool hasBody = EFalse;
  2258     TBool hasBody = EFalse;
  2230         CFSMailMessagePart* htmlBodyPart = iOrigMessage->HtmlBodyPartL();
  2269         CFSMailMessagePart* htmlBodyPart = iOrigMessage->HtmlBodyPartL();
  2231         if ( htmlBodyPart )
  2270         if ( htmlBodyPart )
  2232             {
  2271             {
  2233             CleanupStack::PushL( htmlBodyPart );
  2272             CleanupStack::PushL( htmlBodyPart );
  2234 
  2273 
  2235             HBufC* htmlData = HBufC::NewLC( htmlBodyPart->FetchedContentSize() );
  2274             HBufC* htmlData = 
       
  2275                 HBufC::NewLC( htmlBodyPart->FetchedContentSize() );
  2236             TPtr pointer = htmlData->Des();
  2276             TPtr pointer = htmlData->Des();
  2237             htmlBodyPart->GetContentToBufferL( pointer, 0 );
  2277             htmlBodyPart->GetContentToBufferL( pointer, 0 );
  2238 
  2278 
  2239             body = TFsEmailUiUtility::ConvertHtmlToTxtL( *htmlData );
  2279             body = TFsEmailUiUtility::ConvertHtmlToTxtL( *htmlData );
  2240 
  2280 
  2336     FUNC_LOG;
  2376     FUNC_LOG;
  2337     // Show "Opening" wait note if the message body is large
  2377     // Show "Opening" wait note if the message body is large
  2338     TInt waitNoteId = KErrNotFound;
  2378     TInt waitNoteId = KErrNotFound;
  2339     if ( TFsEmailUiUtility::IsMessageBodyLargeL(iOrigMessage) )
  2379     if ( TFsEmailUiUtility::IsMessageBodyLargeL(iOrigMessage) )
  2340         {
  2380         {
  2341         waitNoteId = TFsEmailUiUtility::ShowGlobalWaitNoteLC( R_FSE_WAIT_OPENING_TEXT );
  2381         waitNoteId = TFsEmailUiUtility::ShowGlobalWaitNoteLC( 
       
  2382                 R_FSE_WAIT_OPENING_TEXT );
  2342         }
  2383         }
  2343 
  2384 
  2344     if ( iCustomMessageId == TUid::Uid( KEditorCmdReply ) )
  2385     if ( iCustomMessageId == TUid::Uid( KEditorCmdReply ) )
  2345         {
  2386         {
  2346         GenerateReplyMessageL( EFalse );
  2387         GenerateReplyMessageL( EFalse );
  2386 	HBufC* temp = HBufC::NewLC( buf.Length() );
  2427 	HBufC* temp = HBufC::NewLC( buf.Length() );
  2387 	temp->Des().Copy( buf );
  2428 	temp->Des().Copy( buf );
  2388 
  2429 
  2389 	//<cmail> this is actually a waited async method
  2430 	//<cmail> this is actually a waited async method
  2390 	iFakeSyncGoingOn = ETrue;
  2431 	iFakeSyncGoingOn = ETrue;
  2391     iNewMessage = iMailBox->CreateReplyMessage( iLaunchParams.iMsgId, aReplyAll, *temp );
  2432     iNewMessage = iMailBox->CreateReplyMessage( 
       
  2433             iLaunchParams.iMsgId, aReplyAll, *temp );
  2392     iFakeSyncGoingOn = EFalse;
  2434     iFakeSyncGoingOn = EFalse;
  2393     //</cmail>
  2435     //</cmail>
  2394    	// Compose screen does not send cal messages, make sure
  2436    	// Compose screen does not send cal messages, make sure
  2395 	// that cal event flag is not left active by some protocol
  2437 	// that cal event flag is not left active by some protocol
  2396 	if ( iNewMessage )
  2438 	if ( iNewMessage )
  2403     if ( !iNewMessage )
  2445     if ( !iNewMessage )
  2404     	{
  2446     	{
  2405     	User::Leave( KErrGeneral );
  2447     	User::Leave( KErrGeneral );
  2406     	}
  2448     	}
  2407     iFakeSyncGoingOn = ETrue; //<cmail>
  2449     iFakeSyncGoingOn = ETrue; //<cmail>
  2408     TRAPD( error, TFsEmailUiUtility::MoveMessageToDraftsL( *iMailBox, *iNewMessage ) );
  2450     TRAPD( error, TFsEmailUiUtility::MoveMessageToDraftsL( 
       
  2451             *iMailBox, *iNewMessage ) );
  2409     iFakeSyncGoingOn = EFalse; //</cmail>
  2452     iFakeSyncGoingOn = EFalse; //</cmail>
  2410     User::LeaveIfError( error );
  2453     User::LeaveIfError( error );
  2411 
  2454 
  2412     if ( iNewMessage->GetContentType() != KFSMailContentTypeMultipartMixed )
  2455     if ( iNewMessage->GetContentType() != KFSMailContentTypeMultipartMixed )
  2413         {
  2456         {
  2453     if ( !iNewMessage )
  2496     if ( !iNewMessage )
  2454     	{
  2497     	{
  2455     	User::Leave( KErrGeneral );
  2498     	User::Leave( KErrGeneral );
  2456     	}
  2499     	}
  2457     iFakeSyncGoingOn = ETrue; //<cmail>
  2500     iFakeSyncGoingOn = ETrue; //<cmail>
  2458     TRAPD( error, TFsEmailUiUtility::MoveMessageToDraftsL( *iMailBox, *iNewMessage ) );
  2501     TRAPD( error, TFsEmailUiUtility::MoveMessageToDraftsL( 
       
  2502             *iMailBox, *iNewMessage ) );
  2459     iFakeSyncGoingOn = EFalse; //<cmail>
  2503     iFakeSyncGoingOn = EFalse; //<cmail>
  2460     User::LeaveIfError( error );
  2504     User::LeaveIfError( error );
  2461 
  2505 
  2462     if ( iNewMessage->GetContentType() != KFSMailContentTypeMultipartMixed )
  2506     if ( iNewMessage->GetContentType() != KFSMailContentTypeMultipartMixed )
  2463         {
  2507         {
  2464         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  2508         iNewMessage->SetContentType( KFSMailContentTypeMultipartMixed );
  2465         iNewMessage->SaveMessageL();
  2509         iNewMessage->SaveMessageL();
  2466 	    }
  2510 	    }
  2467     
  2511     
  2468 	TFsEmailUiUtility::CreatePlainTextPartL( *iNewMessage, iNewMessageTextPart );
  2512 	TFsEmailUiUtility::CreatePlainTextPartL( 
       
  2513 	        *iNewMessage, iNewMessageTextPart );
  2469 
  2514 
  2470     }
  2515     }
  2471 
  2516 
  2472 // -----------------------------------------------------------------------------
  2517 // -----------------------------------------------------------------------------
  2473 // CNcsComposeView::InitReplyUiL
  2518 // CNcsComposeView::InitReplyUiL
  2493     FUNC_LOG;
  2538     FUNC_LOG;
  2494     if ( iFirstStartCompleted ) // Safety check
  2539     if ( iFirstStartCompleted ) // Safety check
  2495         {
  2540         {
  2496         AppUi()->AddToStackL( iContainer );
  2541         AppUi()->AddToStackL( iContainer );
  2497         iContainer->SetMenuBar( Cba() );
  2542         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();
  2543         iContainer->UpdateScrollBarL();
  2507 
  2544 
  2508         // Set title pane text
  2545         // Set title pane text
  2509         const TDesC& mbName = iMailBox->GetName();
  2546         const TDesC& mbName = iMailBox->GetName();
  2510         iAppUi.SetTitlePaneTextL( mbName );
  2547         iAppUi.SetTitlePaneTextL( mbName );
  2648         iFakeSyncGoingOn = EFalse;
  2685         iFakeSyncGoingOn = EFalse;
  2649         User::LeaveIfError( error );
  2686         User::LeaveIfError( error );
  2650 
  2687 
  2651         if ( !iAppUi.AppUiExitOngoing() )
  2688         if ( !iAppUi.AppUiExitOngoing() )
  2652             {
  2689             {
  2653             // Simulate a new mail event to ensure that saved message becomes visible in the
  2690             // Simulate a new mail event to ensure that saved message becomes
  2654             // mail list. All protocols do not send event automatically in this case.
  2691             // visible in the mail list. 
       
  2692             // All protocols do not send event automatically in this case.
  2655             RArray<TFSMailMsgId> messageIdArray;
  2693             RArray<TFSMailMsgId> messageIdArray;
  2656             CleanupClosePushL( messageIdArray );
  2694             CleanupClosePushL( messageIdArray );
  2657             messageIdArray.Append( iNewMessage->GetMessageId() );
  2695             messageIdArray.Append( iNewMessage->GetMessageId() );
  2658             TFSMailMsgId folderId = iNewMessage->GetFolderId();
  2696             TFSMailMsgId folderId = iNewMessage->GetFolderId();
  2659             TFSMailMsgId mailboxId = iNewMessage->GetMailBoxId();
  2697             TFSMailMsgId mailboxId = iNewMessage->GetMailBoxId();
  2660             iAppUi.EventL(
  2698             iAppUi.EventL(
  2661                 TFSEventNewMail, mailboxId, &messageIdArray, &folderId, NULL );
  2699                 TFSEventNewMail, mailboxId, &messageIdArray, &folderId, NULL );
  2662             // Update displayed mail info if the mail was already created sooner
  2700             // Update displayed mail info if the mail was created previously
  2663             iAppUi.EventL(
  2701             iAppUi.EventL(
  2664                 TFSEventMailChanged, mailboxId, &messageIdArray, &folderId, NULL );
  2702                 TFSEventMailChanged, mailboxId, &messageIdArray, 
       
  2703                 &folderId, NULL );
  2665             CleanupStack::PopAndDestroy( &messageIdArray );
  2704             CleanupStack::PopAndDestroy( &messageIdArray );
  2666             }
  2705             }
  2667         }
  2706         }
  2668 	}
  2707 	}
  2669 
  2708 
  2670 // -----------------------------------------------------------------------------
  2709 // -----------------------------------------------------------------------------
  2671 // CNcsComposeView::FetchLogicComplete
  2710 // CNcsComposeView::FetchLogicComplete
  2672 // -----------------------------------------------------------------------------
  2711 // -----------------------------------------------------------------------------
  2673 //
  2712 //
  2674 TBool CNcsComposeView::FetchLogicComplete( TComposerFetchState /*aState*/, TInt aError )
  2713 TBool CNcsComposeView::FetchLogicComplete( 
       
  2714         TComposerFetchState /*aState*/, TInt aError )
  2675 	{
  2715 	{
  2676     FUNC_LOG;
  2716     FUNC_LOG;
  2677     TBool result = EFalse;
  2717     TBool result = EFalse;
  2678     if ( iFirstStartCompleted ) // Safety
  2718     if ( iFirstStartCompleted ) // Safety
  2679         {
  2719         {
  2683             iAutoSaver->Enable( ETrue );
  2723             iAutoSaver->Enable( ETrue );
  2684             }
  2724             }
  2685         else
  2725         else
  2686             {
  2726             {
  2687             // something went wrong
  2727             // something went wrong
  2688             DoSafeExit(ENoSave);
  2728             DoSafeExit( ENoSave );
  2689             iMailFetchingErrCode = aError;
  2729             iMailFetchingErrCode = aError;
  2690             result = ETrue;
  2730             result = ETrue;
  2691             }
  2731             }
  2692         }
  2732         }
  2693     if ( iFetchWaitDialog && !iFetchDialogCancelled )
  2733     if ( iFetchWaitDialog && !iFetchDialogCancelled )
  2694         {
  2734         {
  2695         TRAP_IGNORE(iFetchWaitDialog->ProcessFinishedL());
  2735         TRAP_IGNORE( iFetchWaitDialog->ProcessFinishedL() );
  2696         iFetchWaitDialog = NULL;
  2736         iFetchWaitDialog = NULL;
  2697         }
  2737         }
  2698     return result;
  2738     return result;
  2699 	}
  2739 	}
  2700 
  2740 
  2709     if ( iStatusPaneIndicators )
  2749     if ( iStatusPaneIndicators )
  2710         {
  2750         {
  2711         iStatusPaneIndicators->HideStatusPaneIndicators();
  2751         iStatusPaneIndicators->HideStatusPaneIndicators();
  2712         }
  2752         }
  2713     
  2753     
  2714     // lower flag to indicate that view is no longer able to handle user commands
  2754     // lower flag to indicate that view is no longer 
       
  2755     // able to handle user commands
  2715     iViewReady = EFalse;
  2756     iViewReady = EFalse;
  2716 
  2757 
  2717 	// view switching and alfred operations should be avoided
  2758 	// view switching and alfred operations should be avoided
  2718 	// when Appui exit has been initialised
  2759 	// when Appui exit has been initialised
  2719 	if ( !iAppUi.AppUiExitOngoing() )
  2760 	if ( !iAppUi.AppUiExitOngoing() )
  2720 		{
  2761 		{
  2721         // change to previous view
  2762         // change to previous view
  2722         TRAP_IGNORE( NavigateBackL() );
  2763         TRAP_IGNORE( NavigateBackL() );
  2723         }
  2764         }
  2724 
  2765 
  2725     // Cleanup message contents to prevent ChildDoDeactivate() from saving the message to drafts again
  2766     // Cleanup message contents to prevent ChildDoDeactivate() 
       
  2767 	// from saving the message to drafts again
  2726     ResetComposer();
  2768     ResetComposer();
  2727 
  2769 
  2728     SafeDelete( iFetchLogic );
  2770     SafeDelete( iFetchLogic );
  2729     }
  2771     }
  2730 
  2772 
  2789 
  2831 
  2790         TBool noAddrOrNoMesBody = iContainer->AreAddressFieldsEmpty() &&
  2832         TBool noAddrOrNoMesBody = iContainer->AreAddressFieldsEmpty() &&
  2791             iContainer->IsSubjectFieldEmpty() &&
  2833             iContainer->IsSubjectFieldEmpty() &&
  2792             (iContainer->GetMessageFieldLength() < 1);
  2834             (iContainer->GetMessageFieldLength() < 1);
  2793 
  2835 
  2794         // save to Drafts if there's some user input in some header field or in message body
  2836         // save to Drafts if there's some user input in some header field 
       
  2837         // or in message body
  2795         if ( !noAddrOrNoMesBody )
  2838         if ( !noAddrOrNoMesBody )
  2796             {
  2839             {
  2797             TRAPD( error, DoSaveDraftL( EFalse ) );
  2840             TRAPD( error, DoSaveDraftL( EFalse ) );
  2798             if ( error )
  2841             if ( error )
  2799                 {
  2842                 {
  2800                 }
  2843                 }
  2801             }
  2844             }
  2802 
  2845 
  2803         // store the message IDs to launch parameters to be able to return to same message if desired
  2846         // store the message IDs to launch parameters to be able to return 
       
  2847         // to same message if desired
  2804         iLaunchParams.iMsgId = iNewMessage->GetMessageId();
  2848         iLaunchParams.iMsgId = iNewMessage->GetMessageId();
  2805         iLaunchParams.iFolderId = iNewMessage->GetFolderId();
  2849         iLaunchParams.iFolderId = iNewMessage->GetFolderId();
  2806         iLaunchParams.iMailboxId = iMailBox->GetId();
  2850         iLaunchParams.iMailboxId = iMailBox->GetId();
  2807         }
  2851         }
  2808     ResetComposer();
  2852     ResetComposer();
  2827 // -----------------------------------------------------------------------------
  2871 // -----------------------------------------------------------------------------
  2828 //
  2872 //
  2829 void CNcsComposeView::AsyncExitL()
  2873 void CNcsComposeView::AsyncExitL()
  2830     {
  2874     {
  2831     FUNC_LOG;
  2875     FUNC_LOG;
  2832     if ( iFakeSyncGoingOn || iExecutingDoExitL ) // if some sync method is still going on, we continue waiting
  2876     if ( iFakeSyncGoingOn || iExecutingDoExitL )
  2833         {
  2877         {
       
  2878         // if some sync method is still going on, we continue waiting
  2834         iActiveHelper->Cancel();
  2879         iActiveHelper->Cancel();
  2835         iActiveHelper->Start();
  2880         iActiveHelper->Start();
  2836         }
  2881         }
  2837     else
  2882     else
  2838         {
  2883         {
  2839         ExitComposer();
  2884         ExitComposer();
  2840         // for some strange reason composer view is stuck and only option was to call ProcessCommandL with EAknCmdExit
  2885         // for some strange reason composer view is stuck and only option 
       
  2886         // was to call ProcessCommandL with EAknCmdExit
  2841         ProcessCommandL( EAknCmdExit );
  2887         ProcessCommandL( EAknCmdExit );
  2842         }
  2888         }
  2843     }
  2889     }
  2844 
  2890 
  2845 // -----------------------------------------------------------------------------
  2891 // -----------------------------------------------------------------------------
  2860     FUNC_LOG;
  2906     FUNC_LOG;
  2861     if ( !iAppUi.AppUiExitOngoing() )
  2907     if ( !iAppUi.AppUiExitOngoing() )
  2862         {
  2908         {
  2863         if ( !iFetchWaitDialog )
  2909         if ( !iFetchWaitDialog )
  2864             {
  2910             {
  2865             iFetchWaitDialog = new(ELeave)CAknWaitDialog(
  2911             iFetchWaitDialog = new (ELeave) CAknWaitDialog(
  2866                        (REINTERPRET_CAST(CEikDialog**,&iFetchWaitDialog)), EFalse);
  2912                 reinterpret_cast<CEikDialog**>( &iFetchWaitDialog ), EFalse);
  2867             iFetchWaitDialog->SetCallback(this);
  2913             iFetchWaitDialog->SetCallback( this );
  2868             iFetchDialogCancelled = EFalse;
  2914             iFetchDialogCancelled = EFalse;
  2869             iFetchWaitDialog->ExecuteLD(R_FSE_FETCHING_WAIT_DIALOG);
  2915             iFetchWaitDialog->ExecuteLD( R_FSE_FETCHING_WAIT_DIALOG );
  2870             }
  2916             }
  2871         }
  2917         }
  2872     }
  2918     }
  2873 
  2919 
  2874 // -----------------------------------------------------------------------------
  2920 // -----------------------------------------------------------------------------
  2876 // -----------------------------------------------------------------------------
  2922 // -----------------------------------------------------------------------------
  2877 //
  2923 //
  2878 void CNcsComposeView::DialogDismissedL( TInt aButtonId )
  2924 void CNcsComposeView::DialogDismissedL( TInt aButtonId )
  2879     {
  2925     {
  2880     FUNC_LOG;
  2926     FUNC_LOG;
  2881     if ( (aButtonId == EAknSoftkeyCancel) && iFetchLogic )
  2927     if ( aButtonId == EAknSoftkeyCancel && iFetchLogic )
  2882         {
  2928         {
  2883         iFetchDialogCancelled = ETrue;
  2929         iFetchDialogCancelled = ETrue;
  2884         iFetchLogic->CancelFetchings();
  2930         iFetchLogic->CancelFetchings();
  2885         }
  2931         }
  2886     }
  2932     }
  2887 
  2933 
  2888 TBool CNcsComposeView::IsPreparedForExit()
  2934 TBool CNcsComposeView::IsPreparedForExit()
  2889     {
  2935     {
  2890     return !(iFakeSyncGoingOn ||iExecutingDoExitL);
  2936     return !( iFakeSyncGoingOn ||iExecutingDoExitL );
  2891     }
  2937     }
  2892 
  2938 
  2893 // ---------------------------------------------------------------------------
  2939 // ---------------------------------------------------------------------------
  2894 // CActiveHelper::NewL()
  2940 // CActiveHelper::NewL()
  2895 // ---------------------------------------------------------------------------
  2941 // ---------------------------------------------------------------------------
  2896 //
  2942 //
  2897 CActiveHelper* CActiveHelper::NewL(CNcsComposeView* aSession )
  2943 CActiveHelper* CActiveHelper::NewL( CNcsComposeView* aSession )
  2898     {
  2944     {
  2899     CActiveHelper* self = new(ELeave) CActiveHelper(aSession);
  2945     CActiveHelper* self = new(ELeave) CActiveHelper( aSession );
  2900     CleanupStack::PushL( self );
  2946     CleanupStack::PushL( self );
  2901     self->ConstructL( );
  2947     self->ConstructL( );
  2902     CleanupStack::Pop( self );
  2948     CleanupStack::Pop( self );
  2903     return self;
  2949     return self;
  2904     }
  2950     }
  2917 // ---------------------------------------------------------------------------
  2963 // ---------------------------------------------------------------------------
  2918 //
  2964 //
  2919 void CActiveHelper::Start()
  2965 void CActiveHelper::Start()
  2920     {
  2966     {
  2921     TRequestStatus* status = &iStatus;
  2967     TRequestStatus* status = &iStatus;
  2922     User::RequestComplete(status,KErrNone);
  2968     User::RequestComplete( status, KErrNone );
  2923     SetActive();
  2969     SetActive();
  2924     }
  2970     }
  2925 
  2971 
  2926 // ---------------------------------------------------------------------------
  2972 // ---------------------------------------------------------------------------
  2927 // CActiveHelper::CActiveHelper()
  2973 // CActiveHelper::CActiveHelper()
  2928 // ---------------------------------------------------------------------------
  2974 // ---------------------------------------------------------------------------
  2929 //
  2975 //
  2930 CActiveHelper::CActiveHelper(CNcsComposeView* aSession ) : CActive(EPriorityLow)
  2976 CActiveHelper::CActiveHelper( CNcsComposeView* aSession ) 
       
  2977     : CActive( EPriorityLow )
  2931     {
  2978     {
  2932     iComposeView = aSession;
  2979     iComposeView = aSession;
  2933     }
  2980     }
  2934 
  2981 
  2935 // ---------------------------------------------------------------------------
  2982 // ---------------------------------------------------------------------------
  2936 // CActiveHelper::RunL()
  2983 // CActiveHelper::RunL()
  2937 // ---------------------------------------------------------------------------
  2984 // ---------------------------------------------------------------------------
  2938 //
  2985 //
  2939 void CActiveHelper::RunL()
  2986 void CActiveHelper::RunL()
  2940     {
  2987     {
  2941     if(iComposeView)
  2988     if( iComposeView )
  2942         iComposeView->AsyncExitL();
  2989         iComposeView->AsyncExitL();
  2943     }
  2990     }
  2944 
  2991 
  2945 // ---------------------------------------------------------------------------
  2992 // ---------------------------------------------------------------------------
  2946 // CActiveHelper::DoCancel()
  2993 // CActiveHelper::DoCancel()
  2955 // CActiveHelper::ConstructL()
  3002 // CActiveHelper::ConstructL()
  2956 // ---------------------------------------------------------------------------
  3003 // ---------------------------------------------------------------------------
  2957 //
  3004 //
  2958 void CActiveHelper::ConstructL()
  3005 void CActiveHelper::ConstructL()
  2959     {
  3006     {
  2960     CActiveScheduler::Add(this);
  3007     CActiveScheduler::Add( this );
  2961     }
  3008     }
  2962 
  3009 
  2963 //</cmail>