email/mail/EditorSrc/MsgMailEditorAppUi.cpp
branchRCL_3
changeset 60 7fdbb852d323
parent 0 72b543305e3a
equal deleted inserted replaced
57:ebe688cedc25 60:7fdbb852d323
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implements UI class for Mail application
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // Mail includes
       
    20 #include "MsgMailEditorAppUi.h"
       
    21 #include "MsgMailEditorDocument.h"
       
    22 #include "msgmaileditor.hrh"
       
    23 #include "cmsgmailsendop.h"
       
    24 #include "cmsgmaillaunchop.h"
       
    25 #include "cmsgmailfetchfileop.h"
       
    26 #include <MsgMailUIDs.h>            // Application UIDs
       
    27 #include "MsgMailViewAttachmentsDlg.h"
       
    28 #include <MsgEditorAppUi.rsg>       // resource identifiers
       
    29 #include <MsgMailEditor.rsg>
       
    30 #include "MailLog.h"
       
    31 #include "MailUtils.h"
       
    32 #include "cmsgmaileditorheader.h"
       
    33 #include "cmsgmailnavipaneutils.h"
       
    34 #include <hlplch.h>
       
    35 #include <csxhelp/mail.hlp.hrh>
       
    36 #include <bldvariant.hrh>
       
    37 
       
    38 // ui includes
       
    39 #include <avkon.hrh>
       
    40 #include <eikmop.h> // for SupplyMopObject
       
    41 #include <eikrted.h>
       
    42 #include <aknenv.h>         // AppShutter
       
    43 #include <barsread.h>       // TResourceReader
       
    44 #include <aknnotewrappers.h>
       
    45 #include <AknWaitDialog.h>
       
    46 #include <akntitle.h>
       
    47 #include <akntoolbar.h>
       
    48 #include <akntoolbarextension.h>
       
    49 #include <aknclearer.h>     // CAknLocalScreenClearer
       
    50 // Editor base classes:
       
    51 #include <MsgAttachmentInfo.h>
       
    52 #include <MsgAttachmentModel.h>
       
    53 #include <MsgEditorView.h>
       
    54 #include <MsgBodyControl.h>
       
    55 #include <MsgExpandableControl.h>
       
    56 #include <MsgAddressControl.h>
       
    57 #include <MsgCheckNames.h>
       
    58 
       
    59 #include <Muiumsginfo.hrh>
       
    60 #include <mtmuibas.h>                   // CBaseMtmUi
       
    61 #include <MuiuMsvUiServiceUtilities.h>  // MUIU MTM utils
       
    62 #include <MtmExtendedCapabilities.hrh>
       
    63 #include <cemailaccounts.h>				// CEmailAccounts
       
    64 #include <StringLoader.h>               // for StringLoader
       
    65 #include "MsgMailOptionsDlg.h"
       
    66 #include "CMsgAddMailHeadersDlg.h"      // Additional headers dialog
       
    67 
       
    68 #include <fepbase.h>
       
    69 #include <aknedsts.h>
       
    70 #include <akninputblock.h>              // CAknInputBlock
       
    71 
       
    72 // mail central repository handler
       
    73 #include "CMailCRHandler.h"
       
    74 #include <MailInternalCRKeys.h>
       
    75 #include <ImumInHealthServices.h>
       
    76 #include <ImumInMailboxServices.h>
       
    77 
       
    78 #include <SendUiConsts.h>
       
    79 
       
    80 #include <MsgEditorAppUiExtension.h>// for iMsgEditorAppUiExtension
       
    81 #include <MsgEditorSettingCacheUpdatePlugin.h>
       
    82 
       
    83 // LOCAL CONSTANTS
       
    84 const TInt KMessageSizeMaxLength(15);
       
    85 const TInt KMSKControlID(3);
       
    86 
       
    87 // ================= MEMBER FUNCTIONS =======================
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CMsgMailEditorAppUi::CMsgMailEditorAppUi()
       
    91 // A default constructor
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 CMsgMailEditorAppUi::CMsgMailEditorAppUi()
       
    95     {
       
    96     }
       
    97 
       
    98 //
       
    99 // -----------------------------------------------------------------------------
       
   100 // CMsgMailEditorAppUi::ConstructL()
       
   101 // Constructs new mail editor and calls PrepareToLaunchL
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 void CMsgMailEditorAppUi::ConstructL()
       
   105     {
       
   106     LOG( "ConstructL" );
       
   107     CMsgMailAppUi::ConstructL();
       
   108     
       
   109     // Screen is cleared so that user can't press softkeys before the view is
       
   110     // properly constructed. Softkeys become visible again in 
       
   111     // DelegateFinalizeLaunch() after the editor is properly constructed. 
       
   112     iScreenClearer = CAknLocalScreenClearer::NewLC( EFalse );
       
   113     CleanupStack::Pop( iScreenClearer ); 
       
   114     
       
   115 #ifdef RD_SCALABLE_UI_V2    
       
   116         if ( AknLayoutUtils::PenEnabled() )
       
   117         	{
       
   118     		//Set us as an observer for the toolbar
       
   119     		if ( PopupToolbar() )
       
   120     			{
       
   121     			PopupToolbar()->SetToolbarObserver( this );
       
   122     			PopupToolbar()->SetToolbarVisibility( ETrue, EFalse );
       
   123     			}
       
   124         	}        	
       
   125 #endif // RD_SCALABLE_UI_V2
       
   126 
       
   127     // Disable task swapper from options menu during launch
       
   128     MenuBar()->SetMenuType( CEikMenuBar::EMenuOptionsNoTaskSwapper );
       
   129     
       
   130     MenuBar()->SetContextMenuTitleResourceId(R_MSGMAILEDITOR_CONTEXT_MENUBAR);           
       
   131     
       
   132     iNaviPaneUtils = CMsgMailNaviPaneUtils::NewL();
       
   133     
       
   134     iSendOp = CMsgMailSendOp::NewL( *Document(), *this );
       
   135                                     
       
   136     iLaunchOp = CMsgMailLaunchOp::NewL( *Document(), *this );
       
   137 
       
   138     // Dialer is always disabled in editor
       
   139     SetDialerEnabled( EFalse );
       
   140     }
       
   141 
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CMsgMailEditorAppUi::~CMsgMailEditorAppUi()
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 CMsgMailEditorAppUi::~CMsgMailEditorAppUi()
       
   148     {
       
   149     delete iCheckNames;
       
   150     delete iWaitNote;
       
   151     delete iMailEditorHeader;
       
   152     delete iFetchFileOp;
       
   153     delete iSendOp;
       
   154     delete iLaunchOp;
       
   155     delete iNaviPaneUtils;
       
   156     delete iScreenClearer;
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 //  void CMsgMailEditorAppUi::LaunchViewL
       
   161 //  Opens a message, either a new or an old one.
       
   162 //  Sets send options in CMsgMailPreferences object.
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CMsgMailEditorAppUi::LaunchViewL()
       
   166     {
       
   167     LOG( "LaunchViewL" );
       
   168     
       
   169     if ( !Document()->HasModel() )
       
   170         {
       
   171         // Format restarts editor without proper context
       
   172         // and this extra check is needed with.
       
   173         // Leave with KErrGeneral.
       
   174         User::Leave( KErrGeneral );
       
   175         }    
       
   176 
       
   177     CMsgEditorAppUi::SetCloseWithEndKey( EFalse );
       
   178      
       
   179     iLaunchOp->StartOp( *this );
       
   180 
       
   181     LOG( "LaunchViewL end" );
       
   182     }
       
   183 
       
   184 
       
   185 // ----------------------------------------------------------------------------
       
   186 //  CMsgMailEditorAppUi::DelegateInitLaunchL()
       
   187 //  Called from CMsgMailLaunchOp
       
   188 // ----------------------------------------------------------------------------
       
   189 //
       
   190 CMsgBodyControl& CMsgMailEditorAppUi::DelegateInitLaunchL()
       
   191     {
       
   192     LOG("CMsgMailEditorAppUi::DelegateInitLaunchL()");
       
   193     CMsgMailEditorDocument& doc = *Document();
       
   194     
       
   195     iMessageID = doc.Entry().Id();
       
   196 
       
   197     DoCreateControlsL();
       
   198     doc.SetConfirmation( ETrue );
       
   199     doc.ReadSendOptionsL();
       
   200     
       
   201     // Checks which kind of the message is.
       
   202     if( doc.IsForwardMessage() || doc.IsReplyMessage() )
       
   203     	{
       
   204     	HandleSubjectL();
       
   205     	}
       
   206     else
       
   207     	{
       
   208     	SetSubjectL( doc.HeaderL().Subject() );
       
   209     	}
       
   210     
       
   211     LOG("CMsgMailEditorAppUi::DelegateInitLaunchL() end");
       
   212     return *( BodyControl() );  
       
   213     }
       
   214 
       
   215 // ----------------------------------------------------------------------------
       
   216 //  CMsgMailEditorAppUi::HandleSubjectL()
       
   217 // ----------------------------------------------------------------------------
       
   218 //
       
   219 void CMsgMailEditorAppUi::HandleSubjectL()
       
   220 	{
       
   221 	CMsgMailEditorDocument& doc = *Document();
       
   222 	// base editor provides a service which removes unneeded prefixes
       
   223 	HBufC* newSubject = CreateSubjectPrefixStringL( 
       
   224 			doc.HeaderL().Subject(), doc.IsReplyMessage() );
       
   225 	CleanupStack::PushL( newSubject );
       
   226 	SetSubjectL( *newSubject );
       
   227 	CleanupStack::PopAndDestroy( newSubject );
       
   228 	}
       
   229 
       
   230 // ----------------------------------------------------------------------------
       
   231 //  CMsgMailEditorAppUi::DelegateExecuteViewL()
       
   232 //  Called from CMsgMailLaunchOp
       
   233 // ----------------------------------------------------------------------------
       
   234 //
       
   235 void CMsgMailEditorAppUi::DelegateExecuteViewL()
       
   236     {
       
   237     LOG("CMsgMailEditorAppUi::DelegateExecuteViewL ");
       
   238     DoGetRecipientsL();
       
   239     LockEntryL();    
       
   240     UpdateMessageSizeL();    
       
   241     iView->ExecuteL( ClientRect(), EMsgComponentIdNull );    
       
   242     LOG("CMsgMailEditorAppUi::DelegateExecuteViewL end");
       
   243     }    
       
   244 
       
   245 // ----------------------------------------------------------------------------
       
   246 //  CMsgMailEditorAppUi::DelegateFinalizeLaunchL()
       
   247 //  Called from CMsgMailLaunchOp
       
   248 // ----------------------------------------------------------------------------
       
   249 //
       
   250 void CMsgMailEditorAppUi::DelegateFinalizeLaunchL()
       
   251     {
       
   252     LOG("CMsgMailEditorAppUi::DelegateFinalizeLaunchL");
       
   253     CMsgMailEditorDocument& doc = *Document();
       
   254         
       
   255     UpdatePriorityIndicatorL();
       
   256 
       
   257     // Check recipients' addresses    
       
   258     TBool highlight(EFalse);
       
   259 
       
   260     if ( doc.IsNewMessage() && !CheckRecipientsL( highlight ) )
       
   261         {
       
   262         // Wrong address via Send As, CheckRecipientsL shows error note
       
   263         // so don't ShowSelectedMailboxL
       
   264         }
       
   265     else
       
   266         {
       
   267         SetFocusToFirstFreeFieldL();
       
   268         ShowSelectedMailboxL();
       
   269         }
       
   270 
       
   271         
       
   272 	CImHeader& header = doc.HeaderL();
       
   273 	
       
   274 	//Check if there is old reply to value saved.
       
   275 	//We don't want to write over local reply-to setting if there is one.
       
   276 	//If the reply-to is empty it must be replaced by the value
       
   277 	//in global smtp settings.
       
   278 	if(header.ReplyTo().Length() == 0)
       
   279 		{
       
   280 		TBool retVal = CheckGlobalReplyToSettingL();        
       
   281 		LOG1("CheckGlobalReplyToSettingL retVal=%d", retVal);
       
   282 		}
       
   283         
       
   284 	
       
   285 	// Enable task swapper to options menu after launch has been completed.
       
   286     MenuBar()->SetMenuType( CEikMenuBar::EMenuOptions );
       
   287 
       
   288     doc.SetChanged( EFalse );   
       
   289     
       
   290     // Make softkeys visible again.
       
   291     delete iScreenClearer;
       
   292     iScreenClearer = NULL;
       
   293     
       
   294     LOG("CMsgMailEditorAppUi::DelegateFinalizeLaunchL end");
       
   295     }
       
   296 
       
   297 // ----------------------------------------------------------------------------
       
   298 //  CMsgMailEditorAppUi::SetTitlePaneL()
       
   299 // ----------------------------------------------------------------------------
       
   300 //
       
   301 void CMsgMailEditorAppUi::SetTitlePaneL( TInt aResourceId )    
       
   302     {
       
   303     CAknTitlePane* titlePane =
       
   304         static_cast<CAknTitlePane *>(StatusPane()->ControlL(
       
   305         TUid::Uid(EEikStatusPaneUidTitle)));
       
   306 
       
   307     TResourceReader reader;
       
   308     iCoeEnv->CreateResourceReaderLC( reader, aResourceId );
       
   309     titlePane->SetFromResourceL( reader );
       
   310     CleanupStack::PopAndDestroy(); // CSI: 12 # CreateResourceReaderLC
       
   311     }
       
   312 
       
   313 // ----------------------------------------------------------------------------
       
   314 //  CMsgMailEditorAppUi::::DynInitMenuPaneL()
       
   315 //  This function is called by the framework just before it displays
       
   316 //  a menu pane.
       
   317 // ----------------------------------------------------------------------------
       
   318 //
       
   319 void CMsgMailEditorAppUi::DynInitMenuPaneL(
       
   320 	TInt aResourceId, CEikMenuPane* aMenuPane)
       
   321     {
       
   322     ASSERT( aMenuPane );
       
   323     // Confirm app is running properly (needed atleast now)
       
   324     if ( !Document()->IsLaunched() )
       
   325         {
       
   326         // If not, hide everything and return
       
   327         TInt amountOfItems = aMenuPane->NumberOfItemsInPane();
       
   328         if ( amountOfItems )
       
   329             {
       
   330             aMenuPane->DeleteBetweenMenuItems( 0, amountOfItems-1 );
       
   331             }
       
   332         return;
       
   333         }
       
   334     switch (aResourceId)
       
   335         {
       
   336         case R_MSGMAILEDITOR_OPTIONS_MENU1:
       
   337             // FALLTHROUGH
       
   338         case R_MSGMAILEDITOR_CONTEXT_MENUPANE:
       
   339 
       
   340             if ( Document()->MailCRHandler()->MailInsertToolBar() )
       
   341                 {
       
   342                 aMenuPane->SetItemDimmed(
       
   343                     EMsgMailEditorCmdInsertMenu, EFalse );
       
   344                 }
       
   345             else
       
   346                 {
       
   347                 aMenuPane->SetItemDimmed(
       
   348                     EMsgMailEditorCmdInsertSubMenu, EFalse );
       
   349                 }
       
   350             break;
       
   351         case R_MSGMAILEDITOR_OPTIONS_MENU2:
       
   352             // Remove attachment option if no attachments
       
   353 	        aMenuPane->SetItemDimmed(
       
   354 	        	EMsgMailEditorCmdAttachments,
       
   355 	        	(Document()->AttachmentModel().NumberOfItems() <= 0));
       
   356             break;
       
   357         case R_SEND_OPTIONS_MENU:
       
   358             // FALLTHROUGH
       
   359         case R_MSGMAILEDITOR_OPTIONS_MENU3:
       
   360             if (!(iCommonFlags & EHelpSupported))
       
   361                 {
       
   362                 aMenuPane->DeleteMenuItem(EAknCmdHelp);
       
   363                 }
       
   364             break;
       
   365         case R_MSGMAILEDITOR_INSERT_MENU:
       
   366         	aMenuPane->SetItemDimmed(
       
   367         		EMsgMailEditorCmdInsertTemplate,
       
   368         		EFalse );
       
   369         	break;
       
   370         case R_MSGMAILEDITOR_ZOOM_SUBMENU:
       
   371             {
       
   372             TInt zoomLevel = KErrGeneral;
       
   373             iMsgEditorAppUiExtension->
       
   374                 iSettingCachePlugin.GetValue( KAknLocalZoomLayoutSwitch, zoomLevel );
       
   375             switch ( zoomLevel )
       
   376                 {
       
   377                 case EAknUiZoomAutomatic:
       
   378                     aMenuPane->SetItemButtonState( EMsgDispSizeAutomatic,
       
   379                                      EEikMenuItemSymbolOn );
       
   380                     break;
       
   381                 case EAknUiZoomNormal:
       
   382                     aMenuPane->SetItemButtonState( EMsgDispSizeNormal,
       
   383                                      EEikMenuItemSymbolOn );
       
   384                     break;
       
   385                 case EAknUiZoomSmall:
       
   386                     aMenuPane->SetItemButtonState( EMsgDispSizeSmall,
       
   387                                      EEikMenuItemSymbolOn );
       
   388                     break;
       
   389                 case EAknUiZoomLarge:
       
   390                     aMenuPane->SetItemButtonState( EMsgDispSizeLarge,
       
   391                                      EEikMenuItemSymbolOn );
       
   392                     break;
       
   393                 default:
       
   394                     ASSERT(0);
       
   395                     break;
       
   396                 }
       
   397             }
       
   398             break;
       
   399         default:
       
   400             break;
       
   401         }
       
   402     }
       
   403 
       
   404 // -----------------------------------------------------------------------------
       
   405 //  CMsgMailEditorAppUi::::EditorObserver
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 void CMsgMailEditorAppUi::EditorObserver(
       
   409             TMsgEditorObserverFunc aFunc,
       
   410             TAny* aArg1,
       
   411             TAny* aArg2,
       
   412             TAny* aArg3 )
       
   413 	{
       
   414 	TRAP_IGNORE( EditorObserverL(aFunc, aArg1, aArg2, aArg3) );
       
   415 	}
       
   416 
       
   417 // -----------------------------------------------------------------------------
       
   418 // CMsgMailEditorAppUi::HandleKeyEventL()
       
   419 // Handles received key events
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 TKeyResponse CMsgMailEditorAppUi::HandleKeyEventL(
       
   423     const TKeyEvent& aKeyEvent,TEventCode aType)
       
   424     {
       
   425     // still launching application
       
   426     if (!Document()->IsLaunched())
       
   427         {
       
   428         return EKeyWasConsumed;
       
   429         }
       
   430     TKeyResponse keyResp = CMsgEditorAppUi::HandleKeyEventL(
       
   431             aKeyEvent, aType);
       
   432     if (iView)
       
   433         {
       
   434         // By befault the send key is not functional when dialogs or menus
       
   435         // are displaying.
       
   436         if (!IsDisplayingMenuOrDialog())
       
   437         	{
       
   438         	if (aKeyEvent.iCode == EKeyPhoneSend)
       
   439         		{
       
   440         		if ( AreAddressFieldsEmptyL() )
       
   441         			{
       
   442         			DoAddRecipientL();
       
   443         			}
       
   444         		else
       
   445         			{
       
   446         			DoSendMessageL();
       
   447         			}
       
   448         		keyResp = EKeyWasConsumed;
       
   449         		}
       
   450         	}
       
   451         if ( aKeyEvent.iCode == EKeyEnter )
       
   452 			{
       
   453 			HandleEnterKeyL();
       
   454 			keyResp = EKeyWasConsumed;
       
   455 			}
       
   456         
       
   457     	switch (aKeyEvent.iScanCode)
       
   458     		{
       
   459     		case EStdKeyUpArrow:
       
   460     		case EStdKeyDownArrow:
       
   461     			{
       
   462     			if( aType == EEventKeyUp &&
       
   463     					SpecialScrolling( aKeyEvent.iScanCode ) )
       
   464     				{
       
   465     				keyResp = EKeyWasConsumed;
       
   466     				break;
       
   467     				}
       
   468     			// FALLTHROUGH
       
   469     			}
       
   470     		case EStdKeyLeftArrow:
       
   471     		case EStdKeyRightArrow:
       
   472     		case EStdKeyDevice0:        // Options menu
       
   473     		case EStdKeyDevice1:        // Done key
       
   474     		case EStdKeyDevice2:        // Ok
       
   475     		case EStdKeyDevice3:        // Ok
       
   476     		case EStdKeyRightShift:     // Shift
       
   477     		case EStdKeyApplication0:   // Task switching
       
   478     			break;
       
   479     		default:
       
   480     			{
       
   481     			//something is written to header or to body
       
   482     			if (aType == EEventKeyUp)
       
   483     				{
       
   484     				Document()->SetChanged(ETrue);
       
   485     				UpdateMessageSizeL();
       
   486     				}
       
   487     			break;
       
   488     			}
       
   489     		}
       
   490         }
       
   491     return keyResp;
       
   492     }
       
   493 
       
   494 // -----------------------------------------------------------------------------
       
   495 // CMsgMailEditorAppUi::HandleCommandL(TInt aCommand)
       
   496 // Processes menu selections
       
   497 // -----------------------------------------------------------------------------
       
   498 //
       
   499 void CMsgMailEditorAppUi::HandleCommandL(TInt aCommand)
       
   500     {
       
   501     MAIL_ALLOC_TEST( DoHandleCommandL( aCommand ) );
       
   502     } 
       
   503 
       
   504 
       
   505 // -----------------------------------------------------------------------------
       
   506 // CMsgMailEditorAppUi::DoMsgSaveExitL()
       
   507 // Because this method is inherited from MsgEditor method signature is leaving,
       
   508 // but leaves are really trapped to ensure that exiting succeeds always.
       
   509 // -----------------------------------------------------------------------------
       
   510 //
       
   511 void CMsgMailEditorAppUi::DoMsgSaveExitL()
       
   512 	{    
       
   513     LOG( "CMsgMailEditorAppUi::DoMsgSaveExit" );
       
   514     
       
   515 #ifdef _DEBUG
       
   516     TRAPD( err, PrepereToExitL() );
       
   517     LOG1( "CMsgMailEditorAppUi::DoMsgSaveExit @ err:%d", err );
       
   518 #else
       
   519     TRAP_IGNORE( PrepereToExitL() );
       
   520 #endif
       
   521     
       
   522     Exit();    
       
   523     }
       
   524     
       
   525 // -----------------------------------------------------------------------------
       
   526 // CMsgMailEditorAppUi::PrepereToExitL()
       
   527 // Called by DoMsgSaveExit
       
   528 // -----------------------------------------------------------------------------
       
   529 //
       
   530 void CMsgMailEditorAppUi::PrepereToExitL()
       
   531     {
       
   532     LOG( "CMsgMailEditorAppUi::PrepereToExitL" );
       
   533     CMsgMailEditorDocument* doc = Document();    
       
   534     
       
   535     // Make sure that possibly running asynchronous operations are canceled.
       
   536     // If their progress note isn't closed before actual destruction, then it
       
   537     // will cause an access violation.
       
   538     iLaunchOp->Cancel();
       
   539     iSendOp->Cancel();
       
   540     if ( iFetchFileOp )
       
   541         {
       
   542         iFetchFileOp->Cancel();
       
   543         }
       
   544         
       
   545     LOG( "PrepereToExitL, operations cancelled" );
       
   546 
       
   547     // check that document is launched and view has been created
       
   548     if (doc->IsLaunched() && iView )
       
   549     	{
       
   550     	LOG( "PrepereToExitL, has been fully launched" );
       
   551 	    if (IsEmptyL())
       
   552 	        {
       
   553 	        LOG( "PrepereToExitL, calling DeleteCurrentEntryL" );
       
   554 	        DeleteCurrentEntryL();
       
   555 	        LOG( "PrepereToExitL, DeleteCurrentEntryL returned" );
       
   556 	        return;
       
   557 	        }
       
   558 
       
   559 	    // save the document if it has been changed or if it is a new message
       
   560 	    if (doc->HasChanged() || !doc->CurrentEntry().Entry().Visible() ||
       
   561 	        iView->IsAnyControlModified())
       
   562 	        {
       
   563 	        LOG( "PrepereToExitL, check app shutter" );
       
   564 	        // Do this some time before starting the active sheduler
       
   565 	        // Restarting the active scheduler will stop the app shutter,
       
   566 	        // so record if an app is running a shutter
       
   567 	        CAknAppUi* shuttingApp = CAknEnv::AppWithShutterRunning();
       
   568 
       
   569 	        TBool isVisible(Document()->CurrentEntry().Entry().Visible());
       
   570 	        LOG( "PrepereToExitL, start wait note" );
       
   571 	        StartWaitNoteLC( isVisible ?
       
   572                 R_WAIT_SAVE_NOTE :
       
   573                 R_WAIT_SAVE_NEW_NOTE,
       
   574                 !isVisible );
       
   575 
       
   576             LOG( "PrepereToExitL, saving message" );
       
   577 	        MsgSaveL( EFalse );
       
   578             LOG( "PrepereToExitL, saving finished" );	        
       
   579 			CleanupStack::PopAndDestroy(); // CSI: 12 # StartWaitNoteLC
       
   580 
       
   581 	        if (shuttingApp)
       
   582 	            {
       
   583 	            shuttingApp->RunAppShutter();
       
   584 	            }
       
   585 	        }
       
   586     	}        	
       
   587     }
       
   588 
       
   589 // -----------------------------------------------------------------------------
       
   590 // Checks addresses of all recipients
       
   591 // -----------------------------------------------------------------------------
       
   592 TBool CMsgMailEditorAppUi::CheckRecipientsL(TBool aHighlight)
       
   593     {
       
   594     TBool result(ETrue);
       
   595     CMsgAddressControl* addressField = AddressControl(EMsgComponentIdTo);
       
   596     if (addressField)
       
   597         {
       
   598         CheckRecipientsInFieldL(addressField, aHighlight, result);
       
   599         }
       
   600 
       
   601     if ( result )
       
   602         {
       
   603         addressField = AddressControl(EMsgComponentIdCc);
       
   604         if (addressField)
       
   605             {
       
   606             CheckRecipientsInFieldL(addressField, aHighlight, result);
       
   607             }
       
   608         }
       
   609 
       
   610     if ( result )
       
   611         {
       
   612         addressField = AddressControl(EMsgComponentIdBcc);
       
   613         if (addressField)
       
   614             {
       
   615             CheckRecipientsInFieldL(addressField, aHighlight, result);
       
   616             }
       
   617         }
       
   618 
       
   619     return result;
       
   620     }
       
   621 
       
   622 // -----------------------------------------------------------------------------
       
   623 // Checks addresses of all recipients in given field
       
   624 // -----------------------------------------------------------------------------
       
   625 //
       
   626 void CMsgMailEditorAppUi::CheckRecipientsInFieldL(
       
   627     CMsgAddressControl* aAddressField, TBool& aHighLight, TBool& aResult)
       
   628     {
       
   629     ASSERT( aAddressField );
       
   630     CAknInputBlock::NewLC(); // block key events
       
   631     aResult = ETrue;
       
   632 
       
   633     CMsgRecipientArray& recs = *aAddressField->GetRecipientsL();
       
   634     TInt count(recs.Count());
       
   635 
       
   636     for (TInt i = 0; i < count; i++)
       
   637         {
       
   638         if (aResult)
       
   639             {
       
   640             HBufC* address = recs.At(i)->Address();
       
   641 
       
   642             if ( IsValidAddress(*address) )
       
   643                 {
       
   644                 recs.At(i)->SetValidated(ETrue);
       
   645                 }
       
   646 
       
   647             else // Not valid email address , Search from Phonebook
       
   648                 {
       
   649                 InitPhoneBookL();
       
   650                 //approx 3 recipients
       
   651                 CMsgRecipientArray* rcptArray =
       
   652                     new (ELeave) CArrayPtrFlat<CMsgRecipientItem>(3);		// CSI: 47 # See a comment above.
       
   653                 CleanupStack::PushL( rcptArray );
       
   654 		        if ( iCheckNames->FindAndCheckByNameL(
       
   655 		                *address, CMsgCheckNames::EMsgTypeMail, *rcptArray, -1 ) ) //-1 add
       
   656                     {
       
   657                     LOG( "CMsgMailEditorAppUi::CheckRecipientsInFieldL" );
       
   658                     }
       
   659 
       
   660                 const TInt contacts(rcptArray->Count());
       
   661 
       
   662                 if ( contacts > 0)
       
   663                     {
       
   664                     // Validate addresses found from phonebook
       
   665                     TInt index;
       
   666                     for (index = 0; index < contacts; ++index)
       
   667                         {
       
   668                         HBufC* rcptAddress = rcptArray->At(index)->Address();
       
   669                         if ( !IsValidAddress(*rcptAddress) )
       
   670                             {
       
   671                             aResult = EFalse;
       
   672                             ShowIncorrectAddressErrorL(
       
   673                                 *(rcptArray->At(index)->Name()),
       
   674                                 *rcptAddress);
       
   675 
       
   676                             // highlight only first invalid address
       
   677                             if (!aHighLight)
       
   678                                 {
       
   679                                 SearchUnverifiedStringL(
       
   680                                     *address, aAddressField);
       
   681                                 aAddressField->HighlightUnverifiedStringL();
       
   682                                 aHighLight = ETrue;
       
   683                                 }
       
   684 
       
   685                             }
       
   686                         else
       
   687                             {
       
   688                             // Valid address from phonebook
       
   689                             rcptArray->At(index)->SetValidated(ETrue);
       
   690                             rcptArray->At(index)->SetVerified(ETrue);
       
   691                             }
       
   692                         }
       
   693 
       
   694                     // replace array only if all addresses were valid
       
   695                     if ( aResult && contacts > 0)
       
   696                         {
       
   697                         // Replace alias text and set flags
       
   698                         recs.At(i)->SetNameL( *rcptArray->At(0)->Name() );
       
   699                         recs.At(i)->SetAddressL(
       
   700                             *rcptArray->At(0)->Address() );
       
   701                         recs.At(i)->SetValidated(ETrue);
       
   702                         recs.At(i)->SetVerified(ETrue);
       
   703 
       
   704                         // ownership not changed so delete
       
   705                         delete rcptArray->At( 0 );
       
   706                         rcptArray->Delete( 0 );
       
   707 
       
   708                         while ( rcptArray->Count() )
       
   709                             {
       
   710                             //Add the selected address items
       
   711                             i++;
       
   712                             count++;
       
   713                             // takes ownership
       
   714                             recs.InsertL( i, rcptArray->At( 0 ));
       
   715                             rcptArray->Delete( 0 );
       
   716                             }
       
   717                         }
       
   718 
       
   719                     }
       
   720                 else // incorrect address
       
   721                     {
       
   722                     aResult = EFalse;
       
   723                     ShowIncorrectAddressErrorL(*(recs.At(i)->Name()),
       
   724                         *address);
       
   725                     if (!aHighLight) // highlight only first invalid address
       
   726                         {
       
   727                         SearchUnverifiedStringL( *address, aAddressField);
       
   728                         aAddressField->HighlightUnverifiedStringL();
       
   729                         aHighLight = ETrue;
       
   730                         }
       
   731 
       
   732                     }
       
   733                 CleanupStack::PopAndDestroy( rcptArray );
       
   734                 }
       
   735             }
       
   736         }
       
   737 
       
   738     if (aResult)
       
   739         {
       
   740         // refresh addresscontrol
       
   741         User::LeaveIfError( aAddressField->RefreshL( recs ));
       
   742         }
       
   743     CleanupStack::PopAndDestroy(); // CSI: 12 # CAknInputBlocker
       
   744     }
       
   745 
       
   746 // -----------------------------------------------------------------------------
       
   747 // Show invalid address error note
       
   748 // -----------------------------------------------------------------------------
       
   749 void CMsgMailEditorAppUi::ShowIncorrectAddressErrorL(const TDesC& aTitle,
       
   750     const TDesC& aAddress) const
       
   751     {
       
   752     HBufC* stringholder = NULL;
       
   753 
       
   754     if (aTitle.Length())
       
   755         {
       
   756         // 2 for title & address
       
   757         CDesCArrayFlat* strings = new(ELeave) CDesCArrayFlat(2);		// CSI: 47 # See a comment above.
       
   758         CleanupStack::PushL( strings );
       
   759         strings->AppendL(aAddress);
       
   760         strings->AppendL(aTitle);
       
   761         stringholder = StringLoader::LoadL(
       
   762             R_MAIL_EDITOR_INCORRECT_ADDRESS, *strings, iEikonEnv);
       
   763         CleanupStack::PopAndDestroy( strings ); // strings
       
   764         CleanupStack::PushL(stringholder);
       
   765         }
       
   766     else
       
   767         {
       
   768         stringholder = StringLoader::LoadLC(
       
   769             R_MAIL_EDITOR_INCORRECT_ADDRESS_NO_ALIAS,
       
   770             aAddress, iEikonEnv );
       
   771         }
       
   772 
       
   773     // This is a waiting dialog
       
   774     CAknInformationNote* note = new(ELeave) CAknInformationNote(ETrue);
       
   775     note->ExecuteLD(*stringholder);
       
   776     CleanupStack::PopAndDestroy( stringholder ); // stringholder
       
   777     }
       
   778 
       
   779 // ----------------------------------------------------------------------------
       
   780 // CMsgMailEditorAppUi::DoSendMessageL()
       
   781 // Saves message to outbox and tries to send it immediately,
       
   782 // if Sending schedule in Send options is
       
   783 // CMsgMailPreferences::EMsgMailSchedulingNow.
       
   784 // ----------------------------------------------------------------------------
       
   785 void CMsgMailEditorAppUi::DoSendMessageL()
       
   786     {
       
   787     CMsgMailEditorDocument* doc = Document();    
       
   788     UnlockEntry();
       
   789 
       
   790     // Force FEP commit the current word
       
   791     BodyControl()->SetFocus( EFalse );
       
   792     iCoeEnv->SyncNotifyFocusObserversOfChangeInFocus();
       
   793 
       
   794     // check that recipients are valid
       
   795     TBool highlight( EFalse );
       
   796     if ( CheckRecipientsL( highlight ) )
       
   797         {
       
   798         DoRemoveDuplicatesL();
       
   799         
       
   800         iSendOp->StartOp( *this );
       
   801         }
       
   802     }
       
   803 
       
   804 // ----------------------------------------------------------------------------
       
   805 // CMsgMailEditorAppUi::DelegateSaveMsgL()
       
   806 // called from send operation
       
   807 // ----------------------------------------------------------------------------
       
   808 void CMsgMailEditorAppUi::DelegateSaveMsgL()
       
   809     {
       
   810     MsgSaveL( EFalse );
       
   811     }
       
   812 
       
   813 // ----------------------------------------------------------------------------
       
   814 // CMsgMailEditorAppUi::DelegateMoveMsgToOutboxL()
       
   815 // called from send operation
       
   816 // ----------------------------------------------------------------------------
       
   817 TMsvId CMsgMailEditorAppUi::DelegateMoveMsgToOutboxL()
       
   818     {    
       
   819     return MoveMessageEntryL( KMsvGlobalOutBoxIndexEntryId );
       
   820     }    
       
   821 
       
   822 // ----------------------------------------------------------------------------
       
   823 // CMsgMailEditorAppUi::HandleOpCompleted()
       
   824 // ----------------------------------------------------------------------------
       
   825 void CMsgMailEditorAppUi::HandleOpCompleted(
       
   826     const CMsgMailBaseOp& aOp,
       
   827     TInt aResult )
       
   828     {
       
   829     LOG( "CMsgMailEditorAppUi::HandleOpCompleted" );
       
   830     if ( &aOp == iSendOp )
       
   831         {
       
   832         LOG1( "HandleOpCompleted, send op @ aResult:%d", aResult );
       
   833         if ( aResult == KErrNone || aResult == KErrNoMemory )
       
   834             {
       
   835             Exit( EAknSoftkeyBack );
       
   836             }
       
   837         // this is a special error case -  mailbox wasn't found
       
   838         else if ( aResult == KErrNotFound )
       
   839             {
       
   840             //Try to step back
       
   841             //Trapped to avoid possible problems in operation side
       
   842             //and to keep function as non-leaving.
       
   843             TRAPD(err, DoBackstepL() );
       
   844             
       
   845             //DoBackStep can leave with KLeaveExit and since it call is trapped
       
   846             //mail editor isn't closed like it should. That is why we have to make additional
       
   847             //call to Exit().
       
   848             
       
   849             if(err == KLeaveExit)
       
   850                 {
       
   851                 Exit( EAknSoftkeyBack );    
       
   852                 }
       
   853             
       
   854             
       
   855             }
       
   856         }
       
   857     if ( &aOp == iFetchFileOp )
       
   858         {
       
   859         LOG1( "HandleOpCompleted, fetch file op @ aResult:%d", aResult );
       
   860         // try to update message size and lock the entry
       
   861         TRAP_IGNORE( LockEntryL() );
       
   862         if ( aResult == KErrNone )
       
   863             {
       
   864             TRAP_IGNORE( HandleAttaAddedL() );
       
   865             }                     
       
   866         }    
       
   867     }
       
   868 
       
   869 // ----------------------------------------------------------------------------
       
   870 // CMsgMailEditorAppUi::HandleAttaAddedL()
       
   871 // ----------------------------------------------------------------------------
       
   872 void CMsgMailEditorAppUi::HandleAttaAddedL()
       
   873     {
       
   874     if ( iAttachmentDlg )
       
   875         {
       
   876         iAttachmentDlg->ItemAddedL();
       
   877         }
       
   878     else
       
   879         {
       
   880         UpdateMessageSizeL();
       
   881         }
       
   882     }
       
   883 
       
   884 // ----------------------------------------------------------------------------
       
   885 // CMsgMailEditorAppUi::UpdateHeaderVisibilityL()
       
   886 // ----------------------------------------------------------------------------
       
   887 void CMsgMailEditorAppUi::UpdateHeaderVisibilityL(
       
   888         	RPointerArray<TAdditionalHeaderStatus>& aHeaders)
       
   889 	{
       
   890 	ASSERT( iMailEditorHeader );
       
   891 	iMailEditorHeader->UpdateHeaderVisibilityL( aHeaders );
       
   892 	}
       
   893 
       
   894 // ----------------------------------------------------------------------------
       
   895 // CMsgMailEditorAppUi::UpdatePriorityIndicatorL()
       
   896 // ----------------------------------------------------------------------------
       
   897 void CMsgMailEditorAppUi::UpdatePriorityIndicatorL()
       
   898 	{
       
   899     TMsvId service;
       
   900     TMsvEntry entry;
       
   901     User::LeaveIfError(
       
   902         Document()->Session().GetEntry( iMessageID, service, entry ) );
       
   903     iNaviPaneUtils->SetPriorityIndicator( entry.Priority() );
       
   904 	}
       
   905 
       
   906 // ----------------------------------------------------------------------------
       
   907 // CMsgMailEditorAppUi::DoSendOptionsL()
       
   908 // ----------------------------------------------------------------------------
       
   909 void CMsgMailEditorAppUi::DoSendOptionsL()
       
   910     {
       
   911     // Enable dialer
       
   912     SetDialerEnabled( ETrue );
       
   913     UnlockEntry();
       
   914     CMsgMailOptionsDlg* sendOptionsDlg
       
   915         = CMsgMailOptionsDlg::NewL(
       
   916             Document(), (iCommonFlags & EHelpSupported) );
       
   917     sendOptionsDlg->SetMopParent(this);
       
   918 
       
   919 #ifdef RD_SCALABLE_UI_V2    
       
   920     //Hide toolbar
       
   921     if ( PopupToolbar() )
       
   922         {
       
   923 		CAknToolbarExtension* extension = PopupToolbar()->ToolbarExtension();
       
   924     	extension->SetShown( EFalse );
       
   925     	DoHideToolbar( ETrue );
       
   926         }
       
   927     
       
   928 #endif // RD_SCALABLE_UI_V2
       
   929     
       
   930     if (sendOptionsDlg->ExecuteLD(R_MAIL_EDITOR_SEND_OPTIONS))
       
   931         {
       
   932         // exit was chosen in dialog
       
   933         CAknAppUi::ProcessCommandL( EAknCmdExit );
       
   934         }
       
   935 
       
   936 #ifdef RD_SCALABLE_UI_V2    
       
   937     //Show toolbar
       
   938     if ( PopupToolbar() )
       
   939         {
       
   940         DoHideToolbar( EFalse );
       
   941          }
       
   942 #endif // RD_SCALABLE_UI_V2
       
   943 
       
   944 	ASSERT( iMailEditorHeader );
       
   945     iMailEditorHeader->UpdateReplyToControlL();
       
   946 
       
   947     if ( Document()->MailCRHandler()->MailEncodingSetting() )
       
   948         {
       
   949         DoCheckEncodingL();
       
   950         }
       
   951 
       
   952     LockEntryL();
       
   953     UpdatePriorityIndicatorL();
       
   954     // Disable dialer
       
   955     SetDialerEnabled( EFalse );
       
   956     }
       
   957 
       
   958 // ----------------------------------------------------------------------------
       
   959 //  CMsgMailEditorAppUi::SetSubjectL()
       
   960 //  Sets subject text from CImHeader.
       
   961 // ----------------------------------------------------------------------------
       
   962 //
       
   963 void CMsgMailEditorAppUi::SetSubjectL
       
   964     (const TDesC& aText) const    //in: subject from CImHeader
       
   965     {
       
   966     CMsgExpandableControl* subjectControl = SubjectControl();
       
   967     if (subjectControl)
       
   968     	{
       
   969 	    CEikRichTextEditor& subject = subjectControl->Editor();
       
   970 	    subject.SetTextL(&aText);
       
   971 	    subject.SetCursorPosL(subject.TextLength(), EFalse);
       
   972     	}
       
   973     }
       
   974 
       
   975 // ----------------------------------------------------------------------------
       
   976 // CMsgMailEditorAppUi::DoHidetoolbar( const TBool aHide )
       
   977 // ----------------------------------------------------------------------------
       
   978 //
       
   979 void CMsgMailEditorAppUi::DoHideToolbar( const TBool aHide )
       
   980 	{
       
   981     if ( PopupToolbar() )
       
   982         {
       
   983 #ifdef RD_SCALABLE_UI_V2    
       
   984         if ( AknLayoutUtils::PenEnabled() )
       
   985         	{
       
   986     		PopupToolbar()->HideItemsAndDrawOnlyBackground( aHide );
       
   987         	}        	
       
   988 #endif // RD_SCALABLE_UI_V2
       
   989 		}
       
   990 	}
       
   991 
       
   992 // ----------------------------------------------------------------------------
       
   993 // CMsgMailEditorAppUi::DoShowSelectionListL()
       
   994 // ----------------------------------------------------------------------------
       
   995 //
       
   996 void CMsgMailEditorAppUi::DoShowSelectionListL()
       
   997 	{
       
   998 	TInt selection( 0 );
       
   999 	
       
  1000 	CAknListQueryDialog* dlg = new ( ELeave ) CAknListQueryDialog( &selection );
       
  1001 	dlg->PrepareLC( R_MAILEDITOR_INSERT_SELECTIONLIST );
       
  1002 	
       
  1003 	if ( dlg->RunLD() )
       
  1004 		{
       
  1005 		TInt commandId( EMsgMailFirstFreeCmdId );
       
  1006 		switch( selection )
       
  1007 			{
       
  1008 			case 0:
       
  1009 				commandId = EMsgMailEditorCmdInsertImage;
       
  1010 				break;
       
  1011 			case 1:
       
  1012 				commandId = EMsgMailEditorCmdInsertVideo;
       
  1013 				break;
       
  1014 			case 2:	// CSI: 47 # switch case
       
  1015 				commandId = EMsgMailEditorCmdInsertAudio;
       
  1016 				break;
       
  1017 			case 3:	// CSI: 47 # switch case
       
  1018 				commandId = EMsgMailEditorCmdInsertNote;
       
  1019 				break;
       
  1020 			case 4:	// CSI: 47 # switch case
       
  1021 				commandId = EMsgMailEditorCmdInsertTemplate;
       
  1022 				break;
       
  1023 #ifdef EMAIL_PRESENTATION_SUPPORT
       
  1024 			case 5:	// CSI: 47 # switch case
       
  1025 				commandId = EMsgMailEditorCmdInsertPresentation;
       
  1026 				break;
       
  1027 			case 6:	// CSI: 47 # switch case
       
  1028 				commandId = EMsgMailEditorCmdInsertOther;
       
  1029 				break;
       
  1030 #else
       
  1031 			case 5:	// CSI: 47 # switch case
       
  1032 				commandId = EMsgMailEditorCmdInsertOther;
       
  1033 				break;
       
  1034 #endif //EMAIL_PRESENTATION_SUPPORT
       
  1035 			}
       
  1036 		
       
  1037 		HandleCommandL( commandId );
       
  1038 		}
       
  1039 	}
       
  1040 
       
  1041 // ----------------------------------------------------------------------------
       
  1042 // CMsgMailEditorAppUi::DoShowExtensionToolBar()
       
  1043 // ----------------------------------------------------------------------------
       
  1044 //
       
  1045 void CMsgMailEditorAppUi::DoShowExtensionToolBar()
       
  1046 	{
       
  1047     if ( PopupToolbar() )
       
  1048         {
       
  1049 #ifdef RD_SCALABLE_UI_V2    
       
  1050         if ( AknLayoutUtils::PenEnabled() )
       
  1051         	{
       
  1052         	CAknToolbarExtension* extension = PopupToolbar()->ToolbarExtension();
       
  1053         	extension->SetShown( ETrue );
       
  1054         	}        	
       
  1055 #endif // RD_SCALABLE_UI_V2
       
  1056 		}
       
  1057 	}
       
  1058 
       
  1059 // ----------------------------------------------------------------------------
       
  1060 // CMsgMailEditorAppUi::DoShowToolBarOtherL()
       
  1061 // ----------------------------------------------------------------------------
       
  1062 //
       
  1063 void CMsgMailEditorAppUi::DoShowToolBarOtherL()
       
  1064 	{
       
  1065     TInt selection( 0 );
       
  1066     
       
  1067     CAknListQueryDialog* dlg =
       
  1068         new ( ELeave ) CAknListQueryDialog( &selection );
       
  1069     
       
  1070     if(!AknLayoutUtils::PenEnabled())
       
  1071         { //For non-touch devices
       
  1072         dlg->PrepareLC(R_MAILEDITOR_TOOLBAR_CHOICELIST);
       
  1073         
       
  1074         if ( dlg->RunLD() )
       
  1075             {
       
  1076             TInt command;
       
  1077             // See r_maileditor_toolbar_choicelist_items
       
  1078             command = ( selection == 0 ) ?
       
  1079                 EMsgMailEditorCmdInsertNote :
       
  1080                 EMsgMailEditorCmdInsertOther;
       
  1081             
       
  1082             DoFetchFileL(command);
       
  1083             }
       
  1084         }
       
  1085 #ifdef RD_SCALABLE_UI_V2
       
  1086     //For touch devices toolbar and submenus are different.
       
  1087     else 
       
  1088         {
       
  1089         dlg->PrepareLC( R_MAILEDITOR_TOOLBAR_TOUCH_CHOICELIST );
       
  1090         
       
  1091         if ( dlg->RunLD() )
       
  1092             {
       
  1093             // See r_maileditor_toolbar_choicelist_touch_items.
       
  1094             //Order of this switch-case is based on 
       
  1095             //that resource array.
       
  1096             switch(selection)
       
  1097                 {
       
  1098                 case 0: 
       
  1099                     HandleCommandL( EMsgMailEditorCmdInsertTemplate );
       
  1100                     break;
       
  1101                 case 1:
       
  1102                     HandleCommandL( EMsgMailEditorCmdInsertTemplateNote );
       
  1103                     break;
       
  1104                 case 2:														// CSI: 47 # See a comment above.
       
  1105                     DoFetchFileL(EMsgMailEditorCmdInsertNote);
       
  1106                     break;
       
  1107 #ifdef EMAIL_PRESENTATION_SUPPORT
       
  1108                 case 3:														// CSI: 47 # See a comment above.
       
  1109                     HandleCommandL( EMsgMailEditorCmdInsertPresentation );
       
  1110                     break;
       
  1111                 case 4:														// CSI: 47 # See a comment above.
       
  1112                     DoFetchFileL(EMsgMailEditorCmdInsertOther);
       
  1113                     break;
       
  1114 #else
       
  1115                 case 3:														// CSI: 47 # See a comment above.
       
  1116                     DoFetchFileL(EMsgMailEditorCmdInsertOther);
       
  1117                     break;
       
  1118                     
       
  1119 #endif //EMAIL_PRESENTATION_SUPPORT
       
  1120                 default:
       
  1121                     //unknown selection
       
  1122                     ASSERT( 0 );
       
  1123                     return;
       
  1124                 }
       
  1125             }
       
  1126         }
       
  1127 #endif  //RD_SCALABLE_UI_V2
       
  1128    	}
       
  1129 	
       
  1130 
       
  1131 // ----------------------------------------------------------------------------
       
  1132 // CMsgMailEditorAppUi::DoShowToolBarTextL()
       
  1133 // ----------------------------------------------------------------------------
       
  1134 //
       
  1135 void CMsgMailEditorAppUi::DoShowToolBarTextL()
       
  1136     {
       
  1137     TInt selection( 0 );
       
  1138     CAknListQueryDialog* dlg =
       
  1139         new ( ELeave ) CAknListQueryDialog( &selection );
       
  1140     dlg->PrepareLC( R_MAILEDITOR_TOOLBAR_TEXT_CHOICELIST );
       
  1141     if ( dlg->RunLD() )
       
  1142         {
       
  1143         TInt command;
       
  1144         // See r_maileditor_toolbar_choicelist_items
       
  1145         command = ( selection == 0 ) ?
       
  1146             EMsgMailEditorCmdInsertTemplate :
       
  1147             EMsgMailEditorCmdInsertTemplateNote;
       
  1148         HandleCommandL( command );
       
  1149         }
       
  1150     }
       
  1151 
       
  1152 // ----------------------------------------------------------------------------
       
  1153 // CMsgMailEditorAppUi::DoFetchFileL()
       
  1154 // Fetch from other application.
       
  1155 // ----------------------------------------------------------------------------
       
  1156 //
       
  1157 void CMsgMailEditorAppUi::DoFetchFileL( TInt aCommand )
       
  1158     {
       
  1159     MsgAttachmentUtils::TMsgAttachmentFetchType fetchType;
       
  1160     switch( aCommand )
       
  1161     	{
       
  1162         case EMsgMailEditorCmdInsertImage:
       
  1163             fetchType = MsgAttachmentUtils::EImage;
       
  1164             break;
       
  1165         case EMsgMailEditorCmdInsertAudio:
       
  1166             fetchType = MsgAttachmentUtils::EAudio;
       
  1167             break;
       
  1168         case EMsgMailEditorCmdInsertVideo:
       
  1169             fetchType = MsgAttachmentUtils::EVideo;
       
  1170             break;
       
  1171         case EMsgMailEditorCmdInsertNote:
       
  1172         	fetchType = MsgAttachmentUtils::ENote;
       
  1173         	break;
       
  1174     	case EMsgMailEditorCmdInsertPresentation:
       
  1175     		fetchType = MsgAttachmentUtils::ESVG;
       
  1176     		break;
       
  1177     		
       
  1178     		// Falltrough
       
  1179         case EMsgMailEditorCmdInsertOther:
       
  1180             // unknown
       
  1181             fetchType = MsgAttachmentUtils::EUnknown;
       
  1182             break;
       
  1183         default:
       
  1184         	// not our command, just return
       
  1185     		return;
       
  1186     	}
       
  1187     	
       
  1188     UnlockEntry();
       
  1189     
       
  1190     delete iFetchFileOp; // re-instantiate each time with proper fetch type
       
  1191     iFetchFileOp = NULL;
       
  1192     iFetchFileOp = CMsgMailFetchFileOp::NewL( fetchType, *Document() );        
       
  1193 
       
  1194     iFetchFileOp->StartOp( *this );
       
  1195     }
       
  1196 
       
  1197 // ----------------------------------------------------------------------------
       
  1198 // TBool CMsgMailEditorAppUi::IsEmptyL()
       
  1199 // Returns ETrue if document contains no data, EFalse otherwise
       
  1200 // ----------------------------------------------------------------------------
       
  1201 //
       
  1202 TBool CMsgMailEditorAppUi::IsEmptyL() const
       
  1203     {
       
  1204     if (!AreAddressFieldsEmptyL())
       
  1205         {
       
  1206         return EFalse;
       
  1207         }
       
  1208 
       
  1209     if ( (SubjectControl() && SubjectControl()->TextContent().DocumentLength() > 0) ||
       
  1210         BodyControl()->TextContent().DocumentLength() > 0 ||
       
  1211         Document()->AttachmentModel().NumberOfItems())
       
  1212         {
       
  1213         return EFalse;
       
  1214         }
       
  1215 
       
  1216     return ETrue;
       
  1217     }
       
  1218 
       
  1219 // ----------------------------------------------------------------------------
       
  1220 // CMsgEditorAppUi::HelpContextL
       
  1221 // ----------------------------------------------------------------------------
       
  1222 //
       
  1223 CArrayFix<TCoeHelpContext>* CMsgMailEditorAppUi::HelpContextL( ) const
       
  1224     {
       
  1225     CArrayFix<TCoeHelpContext>* help =
       
  1226                     new( ELeave ) CArrayFixFlat<TCoeHelpContext>( 1 );
       
  1227     CleanupStack::PushL( help );
       
  1228     help->AppendL( TCoeHelpContext( TUid::Uid( KUidMsgMailEditor ),
       
  1229         KMAIL_HLP_MAIL_EDITOR() ) );
       
  1230     CleanupStack::Pop( help );
       
  1231     return help;
       
  1232     }
       
  1233     
       
  1234 // ----------------------------------------------------------------------------
       
  1235 // CMsgEditorAppUi::DynInitToolbarL
       
  1236 // ----------------------------------------------------------------------------
       
  1237 //
       
  1238 void CMsgMailEditorAppUi::DynInitToolbarL( TInt aResourceId, CAknToolbar* aToolbar )
       
  1239 	{
       
  1240     if ( aResourceId == R_MAILEDITOR_TOOLBAR )
       
  1241         {
       
  1242         //Attachment dialog might have hided this so make sure it is visible
       
  1243 	    aToolbar->HideItem( EMsgMailEditorCmdInsertText, EFalse, EFalse );
       
  1244 	    aToolbar->SetInitialFocusedItem( EMsgMailEditorCmdInsertImage );
       
  1245 	    
       
  1246 #ifdef RD_SCALABLE_UI_V2
       
  1247 	    if(AknLayoutUtils::PenEnabled())
       
  1248 	        {
       
  1249 	        //Less items shown if touch device.
       
  1250 #ifdef RD_SVGT_IN_MESSAGING
       
  1251 	        aToolbar->HideItem( EMsgMailEditorCmdInsertPresentation, ETrue, EFalse );
       
  1252 #endif //RD_SVGT_IN_MESSAGING
       
  1253 	        aToolbar->HideItem( EMsgMailEditorCmdInsertText, ETrue, EFalse );
       
  1254 	        }
       
  1255 #endif //RD_SCALABLE_UI_V2
       
  1256 
       
  1257         }		
       
  1258 	}
       
  1259 
       
  1260 // ----------------------------------------------------------------------------
       
  1261 // CMsgEditorAppUi::OfferToolbarEventL
       
  1262 // ----------------------------------------------------------------------------
       
  1263 //
       
  1264 void CMsgMailEditorAppUi::OfferToolbarEventL( TInt aCommand )
       
  1265 	{
       
  1266     if ( PopupToolbar() )
       
  1267         {
       
  1268 #ifdef RD_SCALABLE_UI_V2    
       
  1269         // These commands create the list over the toolbar
       
  1270         // and reason of that list the toolbar must be hidden.
       
  1271     	if ( aCommand == EMsgMailEditorCmdInsertTemplate ||
       
  1272     		 aCommand == EMsgMailEditorCmdInsertOther )
       
  1273     		{
       
  1274     		CAknToolbarExtension* extension = PopupToolbar()->ToolbarExtension();
       
  1275     		extension->SetShown( EFalse );
       
  1276     		}        
       
  1277 
       
  1278     	PopupToolbar()->SetToolbarVisibility( ETrue, EFalse );
       
  1279 
       
  1280 #else  // RD_SCALABLE_UI_V2
       
  1281 	PopupToolbar()->SetToolbarVisibility( EFalse );    	
       
  1282 #endif // RD_SCALABLE_UI_V2
       
  1283         }
       
  1284 		
       
  1285 	if ( aCommand == EMsgMailEditorCmdInsertOther )
       
  1286 	    {
       
  1287 	    // If user chooses Cancel while selecting template text or note
       
  1288         // DoShowToolBarTextL leaves. This is ok so leave is catched here.
       
  1289         TRAPD(err, DoShowToolBarOtherL() );
       
  1290 	    if( err != KErrCancel )
       
  1291             {
       
  1292             User::LeaveIfError( err );
       
  1293             }
       
  1294 	    
       
  1295 	    }
       
  1296     else if ( aCommand == EMsgMailEditorCmdInsertText )
       
  1297         {
       
  1298     	// If user chooses Cancel while selecting template text or note
       
  1299         // DoShowToolBarTextL leaves. This is ok so leave is catched here.
       
  1300         TRAPD( err, DoShowToolBarTextL() );
       
  1301         if( err != KErrCancel )
       
  1302             {
       
  1303             User::LeaveIfError( err );
       
  1304             }
       
  1305         }
       
  1306     else
       
  1307         {
       
  1308 	    HandleCommandL( aCommand );
       
  1309 	    
       
  1310         }
       
  1311 	}
       
  1312 
       
  1313 // ----------------------------------------------------------------------------
       
  1314 // CMsgEditorAppUi::DoCreateControlsL
       
  1315 // ----------------------------------------------------------------------------
       
  1316 //
       
  1317 void CMsgMailEditorAppUi::DoCreateControlsL()
       
  1318 	{
       
  1319 	// Create Base view
       
  1320 	iView = CMsgEditorView::NewL(*this, CMsgEditorView::EMsgEditorModeNormal);
       
  1321 	ASSERT( iView );
       
  1322 	iMailEditorHeader = CMsgMailEditorHeader::NewL( *Document(), *iView );
       
  1323 	}
       
  1324 
       
  1325 // ----------------------------------------------------------------------------
       
  1326 // void CMsgMailEditorAppUi::DoAttachmentL()
       
  1327 // ----------------------------------------------------------------------------
       
  1328 //
       
  1329 void CMsgMailEditorAppUi::DoAttachmentL()
       
  1330     {
       
  1331     HBufC* title = iCoeEnv->AllocReadResourceLC(R_TITLE_ATTACHMENTS);
       
  1332 
       
  1333     CMsgAttachmentModel& attmodel = Document()->AttachmentModel();
       
  1334 
       
  1335     iAttachmentDlg = CMsgMailViewAttachmentsDlg::NewL(*title,
       
  1336         attmodel, *this, (iCommonFlags & EHelpSupported));
       
  1337     iAttachmentDlg->SetMopParent(this);
       
  1338 
       
  1339 
       
  1340 #ifdef RD_SCALABLE_UI_V2    
       
  1341     //Hide toolbar
       
  1342     if ( PopupToolbar() )
       
  1343         {
       
  1344 		CAknToolbarExtension* extension = PopupToolbar()->ToolbarExtension();
       
  1345     	extension->SetShown( EFalse );
       
  1346         DoHideToolbar( ETrue );
       
  1347         }
       
  1348 #endif // RD_SCALABLE_UI_V2
       
  1349     
       
  1350     // safe to call LD even as a member variable, since
       
  1351     // framework always takes care of deleting the dialog
       
  1352     if (iAttachmentDlg->ExecuteLD(R_MEB_VIEW_ATTACHMENT_DIALOG)) // CSI: 50 # see comment above
       
  1353         {
       
  1354         iAttachmentDlg = NULL;
       
  1355         // exit was chosen in dialog
       
  1356         CAknAppUi::ProcessCommandL( EAknCmdExit );
       
  1357         }
       
  1358     else
       
  1359         {
       
  1360         //Attachment dialog has exited. Make sure we are the observers for toolbar
       
  1361         if ( PopupToolbar() )
       
  1362 	        {
       
  1363 			PopupToolbar()->SetToolbarObserver( this );
       
  1364 #ifdef RD_SCALABLE_UI_V2    
       
  1365 			CAknToolbarExtension* extension = PopupToolbar()->ToolbarExtension();
       
  1366         	extension->SetShown( EFalse );
       
  1367         	DoHideToolbar( EFalse );
       
  1368 #endif // RD_SCALABLE_UI_V2
       
  1369 			}
       
  1370 	        
       
  1371         iAttachmentDlg = NULL;
       
  1372         UpdateMessageSizeL();
       
  1373         }
       
  1374 
       
  1375     CleanupStack::PopAndDestroy( title ); // title
       
  1376     }
       
  1377 
       
  1378 // ----------------------------------------------------------------------------
       
  1379 // void CMsgMailEditorAppUi::DoCheckEncodingL()
       
  1380 // ----------------------------------------------------------------------------
       
  1381 //
       
  1382 void CMsgMailEditorAppUi::DoCheckEncodingL()
       
  1383 	{
       
  1384 	CMsgMailPreferences& prefs = Document()->SendOptions();
       
  1385     TUint charsetId = prefs.SendingCharacterSet().iUid;
       
  1386     LOG1( "CMsgMailEditorAppUi::DoCheckEncodingL CharsetId:%08x", charsetId );
       
  1387 	if (charsetId)
       
  1388 		{
       
  1389 	    CCnvCharacterSetConverter* charConv =
       
  1390 	        CCnvCharacterSetConverter::NewLC();
       
  1391 
       
  1392 	    TInt error = charConv->PrepareToConvertToOrFromL(
       
  1393 	    	charsetId, iEikonEnv->FsSession());
       
  1394 		TInt unconverted(0);
       
  1395 		if (error == CCnvCharacterSetConverter::EAvailable)
       
  1396 			{
       
  1397 			// Try to convert body text
       
  1398 		    CRichText& rtf = BodyControl()->TextContent();
       
  1399 		    HBufC* buf = HBufC::NewLC(rtf.DocumentLength());
       
  1400 		    TPtr bufPtr = buf->Des();
       
  1401 		    rtf.Extract(bufPtr);
       
  1402 
       
  1403 		    HBufC8* foreing = HBufC8::NewLC(rtf.DocumentLength());
       
  1404 		    TPtr8 ptr = foreing->Des();
       
  1405 		    error = charConv->ConvertFromUnicode(ptr, *buf, unconverted);
       
  1406 		    CleanupStack::PopAndDestroy(2, buf);							// CSI: 47,12 #  buf, foreing
       
  1407 			}
       
  1408 	    // Show note if can't convert to selected character set.
       
  1409 	    if (error != KErrNone || unconverted > 0)
       
  1410 	    	{
       
  1411 	    	MailUtils::ConfirmationNoteL(R_MAIL_SETTINGS_ENCODE_FALSE_NOTE);
       
  1412 	    	}
       
  1413 
       
  1414 	    CleanupStack::PopAndDestroy( charConv );
       
  1415 		}
       
  1416 	}
       
  1417 
       
  1418 // ----------------------------------------------------------------------------
       
  1419 // void CMsgMailEditorAppUi::DoBackstepL()
       
  1420 // Implements backstep functionality
       
  1421 // ----------------------------------------------------------------------------
       
  1422 //
       
  1423 void CMsgMailEditorAppUi::DoBackstepL()
       
  1424     {
       
  1425     CMsgMailEditorDocument* doc = Document();
       
  1426 
       
  1427     // if document contains no data, message and entry is deleted
       
  1428     if ( IsEmptyL() )
       
  1429         {
       
  1430         if (doc->CurrentEntry().Entry().Visible())
       
  1431             {
       
  1432             HBufC* text = iEikonEnv->AllocReadResourceLC(
       
  1433                 R_MAIL_EDITOR_MESSAGE_DELETED_TEXT);
       
  1434             // waiting dialog, so it is not left into screen when
       
  1435             // application is exited
       
  1436             CAknInformationNote* note = new(ELeave) CAknInformationNote(ETrue);
       
  1437             note->ExecuteLD(*text);
       
  1438             CleanupStack::PopAndDestroy( text ); // text
       
  1439             }
       
  1440         DeleteAndExitL();
       
  1441         return;
       
  1442         }
       
  1443 
       
  1444     switch ( ShowCloseQueryL() )
       
  1445         {
       
  1446         case EMsgCloseDelete:
       
  1447             {
       
  1448             DeleteAndExitL();
       
  1449             }
       
  1450         case EMsgCloseCancel:
       
  1451             {
       
  1452             return;
       
  1453             }
       
  1454         default:
       
  1455             {
       
  1456             // Normal save
       
  1457             if ( !doc->CurrentEntry().Entry().Visible() ||
       
  1458                 doc->HasChanged() ||
       
  1459                 iView->IsAnyControlModified() )
       
  1460                 {
       
  1461                 const TBool newMessage(
       
  1462                     !doc->CurrentEntry().Entry().Visible() );
       
  1463                 StartWaitNoteLC( newMessage ?
       
  1464                     R_WAIT_SAVE_NEW_NOTE :
       
  1465                     R_WAIT_SAVE_NOTE,
       
  1466                     newMessage );
       
  1467 
       
  1468 			    TRAPD( err, MsgSaveL( EFalse ) );
       
  1469 
       
  1470 			    CleanupStack::PopAndDestroy(); // CSI: 12 # StartWaitNoteLC
       
  1471 				User::LeaveIfError(err);
       
  1472                 }
       
  1473             }
       
  1474         }
       
  1475     Exit( EAknSoftkeyBack );
       
  1476     }
       
  1477 
       
  1478 
       
  1479 // ----------------------------------------------------------------------------
       
  1480 // void CMsgMailEditorAppUi::DoAddRecipientL()
       
  1481 // Fetch an address from phonebook
       
  1482 // ----------------------------------------------------------------------------
       
  1483 //
       
  1484 void CMsgMailEditorAppUi::DoAddRecipientL()
       
  1485     {
       
  1486     TMsgControlId uiCompId =
       
  1487     	(TMsgControlId)iView->FocusedControl()->ControlId();
       
  1488 
       
  1489 	//Remember original focused control
       
  1490 	TMsgControlId uiOriginalCompId = uiCompId;
       
  1491 	
       
  1492     // Add recipient into To field if focus is not in address field
       
  1493     if ( !(uiCompId == EMsgComponentIdTo ||
       
  1494     	uiCompId == EMsgComponentIdCc ||
       
  1495     	uiCompId == EMsgComponentIdBcc) )
       
  1496     	{
       
  1497     	uiCompId = EMsgComponentIdTo;
       
  1498     	}
       
  1499 
       
  1500     InitPhoneBookL();
       
  1501     CMsgRecipientList* recipientList = CMsgRecipientList::NewL();
       
  1502     CleanupStack::PushL( recipientList );
       
  1503 
       
  1504     CMsgRecipientArray* recipients =
       
  1505         new (ELeave) CArrayPtrFlat<CMsgRecipientItem>(3);			// CSI: 47 # approx 3
       
  1506     CleanupStack::PushL( recipients );
       
  1507 
       
  1508 #ifdef RD_SCALABLE_UI_V2    
       
  1509     //Hide toolbar
       
  1510     if ( PopupToolbar() )
       
  1511         {
       
  1512 		CAknToolbarExtension* extension = PopupToolbar()->ToolbarExtension();
       
  1513     	extension->SetShown( EFalse );
       
  1514     	DoHideToolbar( ETrue );
       
  1515         }    
       
  1516 #endif // RD_SCALABLE_UI_V2
       
  1517 
       
  1518     //multiple entry fetch to get the contact
       
  1519     iCheckNames->FetchRecipientsL( *recipients, CMsgCheckNames::EMsgTypeMail );
       
  1520 
       
  1521 #ifdef RD_SCALABLE_UI_V2    
       
  1522     DoHideToolbar( EFalse );
       
  1523 #endif // RD_SCALABLE_UI_V2
       
  1524     
       
  1525     //contacts now fetched, verify each contact
       
  1526     for ( TInt i(0); i < recipients->Count(); i++ )
       
  1527         {
       
  1528         CMsgRecipientItem* recipient = (*recipients)[ i ];
       
  1529         HBufC* name = recipient->Name();
       
  1530         HBufC* address = recipient->Address();
       
  1531 
       
  1532         // Don't parse away chars here so this is consistent with
       
  1533         // addresses that user writes "-()" are saved to draft
       
  1534         // but removed when sending
       
  1535         if ( IsValidAddress( *address ) )
       
  1536             {
       
  1537             //  add it to the list of valid addresses
       
  1538             recipient->SetVerified( ( name->Length() > 0 ? ETrue : EFalse ) );
       
  1539             recipientList->AppendL( recipient );
       
  1540             }
       
  1541         else
       
  1542             {
       
  1543             ShowIncorrectAddressErrorL( *address, *name );
       
  1544             }
       
  1545         }
       
  1546     // if valid recipients were selected, add them to control
       
  1547     // and set focus to right component
       
  1548     if ( recipientList->Count() )
       
  1549         {
       
  1550         //Add to control
       
  1551         AddressControl(uiCompId)->AddRecipientsL( *recipientList );
       
  1552         
       
  1553         //Set focus
       
  1554     	SetFocusAfterAddRecipientL( uiOriginalCompId );
       
  1555         }
       
  1556 
       
  1557     // recipientList, recipients
       
  1558     CleanupStack::PopAndDestroy( 2, recipientList );				// CSI: 47,12 # See a comment above.
       
  1559     }
       
  1560 // -----------------------------------------------------------------------------
       
  1561 // void CMsgMailEditorAppUi::AreAddressFieldsEmptyL()
       
  1562 // -----------------------------------------------------------------------------
       
  1563 //
       
  1564 TBool CMsgMailEditorAppUi::AreAddressFieldsEmptyL() const
       
  1565     {
       
  1566     TBool result( ETrue );
       
  1567 
       
  1568     CMsgAddressControl* addressField = AddressControl(EMsgComponentIdTo);
       
  1569     if (addressField)
       
  1570         {
       
  1571         CMsgRecipientArray& recs = *addressField->GetRecipientsL();
       
  1572         if( recs.Count() > 0 )
       
  1573             {
       
  1574             result = EFalse;
       
  1575             }
       
  1576         }
       
  1577 
       
  1578     addressField = AddressControl(EMsgComponentIdCc);
       
  1579     if (addressField)
       
  1580         {
       
  1581         CMsgRecipientArray& recs = *addressField->GetRecipientsL();
       
  1582         if( recs.Count() > 0 )
       
  1583             {
       
  1584             result = EFalse;
       
  1585             }
       
  1586         }
       
  1587 
       
  1588     addressField = AddressControl(EMsgComponentIdBcc);
       
  1589     if (addressField)
       
  1590         {
       
  1591         CMsgRecipientArray& recs = *addressField->GetRecipientsL();
       
  1592         if( recs.Count() > 0 )
       
  1593             {
       
  1594             result = EFalse;
       
  1595             }
       
  1596         }
       
  1597 
       
  1598     return result;
       
  1599     }
       
  1600 
       
  1601 // -----------------------------------------------------------------------------
       
  1602 // void CMsgMailEditorAppUi::UpdateMessageSizeL()
       
  1603 // -----------------------------------------------------------------------------
       
  1604 //
       
  1605 void CMsgMailEditorAppUi::UpdateMessageSizeL()
       
  1606     {
       
  1607     //If attachment dialog is visible we don't want to update navipane,
       
  1608     //because dialogs navi pane should be empty.
       
  1609     if(!iAttachmentDlg)
       
  1610         {
       
  1611         TInt docSize = MessageSizeL( ETrue ); // Count also attachments
       
  1612         LOG1( "CMsgMailEditorAppUi::UpdateMessageSizeL:%d", docSize );
       
  1613         iNaviPaneUtils->SetMessageSizeIndicatorL( docSize );
       
  1614             
       
  1615         // attachment indicator may be shown in navi pane only if local variation
       
  1616         // flag is enabled (by default disabled in common code). Remove this
       
  1617         // code and SetAttachmentIndicator() method when CR key gets obsolete.
       
  1618         if ( !Document()->MailCRHandler()->MailAttachmentField() )
       
  1619             {
       
  1620             CMsgAttachmentModel& attModel = Document()->AttachmentModel();
       
  1621             const TInt attCount( attModel.NumberOfItems() );    
       
  1622             iNaviPaneUtils->SetAttachmentIndicator( attCount > 0 );
       
  1623             }    
       
  1624         }
       
  1625                 
       
  1626     }
       
  1627 
       
  1628 // -----------------------------------------------------------------------------
       
  1629 // void CMsgMailEditorAppUi::DoMessageInfoL()
       
  1630 // -----------------------------------------------------------------------------
       
  1631 //
       
  1632 void CMsgMailEditorAppUi::DoMessageInfoL()
       
  1633     {
       
  1634     CMsgMailDocument* doc = Document();
       
  1635     CMsvEntrySelection* sel = new (ELeave) CMsvEntrySelection;
       
  1636     CleanupStack::PushL(sel);
       
  1637     TMsvId id(doc->Entry().Id());
       
  1638     sel->AppendL(id);
       
  1639 
       
  1640     // save the message so the fields in message info dialog will be up to date
       
  1641     // this is a "hidden" save, so we preserve values of
       
  1642     // preparation and visible flags
       
  1643     const TBool visible(doc->CurrentEntry().Entry().Visible());
       
  1644     CAknWaitDialog* dlg = new(ELeave) CAknWaitDialog(NULL);
       
  1645     CleanupStack::PushL(dlg);
       
  1646     dlg->PrepareLC(R_MEB_WAIT_NOTE);
       
  1647     HBufC* text = StringLoaderLoadLC( R_WAIT_OPENING );
       
  1648     dlg->SetTextL(*text);
       
  1649     CleanupStack::PopAndDestroy( text ); // text
       
  1650     dlg->RunLD();
       
  1651     UnlockEntry();
       
  1652     MsgSaveL(!visible);
       
  1653     CleanupStack::Pop( dlg ); // dlg
       
  1654     dlg->ProcessFinishedL();
       
  1655 
       
  1656     TBuf8<KMessageSizeMaxLength> infoParams(KMessageInfoEditor);
       
  1657     CMsvSingleOpWatcher* watch=CMsvSingleOpWatcher::NewLC(*doc);
       
  1658     CMsvOperation* op= doc->MtmUi().InvokeAsyncFunctionL(
       
  1659         KMtmUiFunctionMessageInfo,
       
  1660         *sel,
       
  1661         watch->iStatus,
       
  1662         infoParams
       
  1663         );
       
  1664     // watch owns op before leave can occur
       
  1665     doc->AddSingleOperationL(op, watch);
       
  1666     CleanupStack::Pop( watch ); // watch
       
  1667     LockEntryL();
       
  1668 
       
  1669     CleanupStack::PopAndDestroy( sel ); // sel
       
  1670 
       
  1671     // this is done, so message will be saved visible,
       
  1672     // when editor is exited
       
  1673     if (!visible)
       
  1674         {
       
  1675         doc->SetChanged(ETrue);
       
  1676         }
       
  1677     }
       
  1678 
       
  1679 // -----------------------------------------------------------------------------
       
  1680 // void CMsgMailEditorAppUi::DoAdditionalHeadersL()
       
  1681 // -----------------------------------------------------------------------------
       
  1682 //
       
  1683 void CMsgMailEditorAppUi::DoAdditionalHeadersL()
       
  1684     {
       
  1685 	// Cc field
       
  1686     TAdditionalHeaderStatus header_status_cc(EMsgComponentIdCc);
       
  1687     CMsgAddressControl* ccControl =  AddressControl(EMsgComponentIdCc);
       
  1688     if (ccControl)
       
  1689     	{
       
  1690     	header_status_cc.iHasContent = ccControl->Editor().TextLength() > 0;
       
  1691     	header_status_cc.iStatus = EHeaderVisible;
       
  1692     	}
       
  1693     // Bcc field
       
  1694     TAdditionalHeaderStatus header_status_bcc(EMsgComponentIdBcc);
       
  1695     // Check if bcc field is allowed
       
  1696     if ( Document()->MailCRHandler()->MailAdditionalHeaders() )
       
  1697         {
       
  1698         CMsgAddressControl* bccControl =  AddressControl(EMsgComponentIdBcc);
       
  1699         if (bccControl)
       
  1700         	{
       
  1701         	header_status_bcc.iHasContent =
       
  1702         	    bccControl->Editor().TextLength() > 0;
       
  1703         	header_status_bcc.iStatus = EHeaderVisible;
       
  1704         	}
       
  1705         }
       
  1706 	// Subject
       
  1707     TAdditionalHeaderStatus header_status_subject(EMsgComponentIdSubject);
       
  1708     CMsgExpandableControl* subjectControl = SubjectControl();
       
  1709     if (subjectControl)
       
  1710     	{
       
  1711     	header_status_subject.iHasContent =
       
  1712     		subjectControl->Editor().TextLength() > 0;
       
  1713     	header_status_subject.iStatus = EHeaderVisible;
       
  1714     	}
       
  1715 
       
  1716     RPointerArray<TAdditionalHeaderStatus> headers;
       
  1717     CleanupClosePushL(headers);
       
  1718 
       
  1719     headers.Append(&header_status_cc);
       
  1720     // Check if bcc field is allowed
       
  1721     if ( Document()->MailCRHandler()->MailAdditionalHeaders() )
       
  1722         {
       
  1723         headers.Append(&header_status_bcc);
       
  1724         }
       
  1725     headers.Append(&header_status_subject);
       
  1726 
       
  1727     CMsgAddMailHeadersDlg* addHeadersDlg =
       
  1728     	CMsgAddMailHeadersDlg::NewLC(headers);
       
  1729 
       
  1730     if( addHeadersDlg->ExecuteDialogL() )
       
  1731         {
       
  1732         TUint headersvalue(0);
       
  1733         for (TInt index(0); index < headers.Count(); ++index)
       
  1734             {
       
  1735             switch( headers[index]->iHeaderValue )
       
  1736                 {
       
  1737                 case EMsgComponentIdCc:
       
  1738                     if ( headers[index]->iStatus == EHeaderVisible )
       
  1739                         {
       
  1740                         headersvalue += KBit0;
       
  1741                         }
       
  1742                     break;
       
  1743                 case EMsgComponentIdBcc:
       
  1744                     if ( headers[index]->iStatus == EHeaderVisible )
       
  1745                         {
       
  1746                         headersvalue += KBit1;
       
  1747                         }
       
  1748                     break;
       
  1749                 case EMsgComponentIdSubject:
       
  1750                     if ( headers[index]->iStatus == EHeaderVisible )
       
  1751                         {
       
  1752                         headersvalue += KBit2;
       
  1753                         }
       
  1754                     break;
       
  1755                 default:
       
  1756                     // Unknown header field
       
  1757                     ASSERT( 0 );
       
  1758                 }
       
  1759             }
       
  1760 		// remember user selection
       
  1761         Document()->MailCRHandler()->SetCRInt(
       
  1762         	KCRUidMail,KMailAdditionalHeaderSettings,headersvalue);
       
  1763 
       
  1764         // set headers
       
  1765         UpdateHeaderVisibilityL(headers);
       
  1766         }
       
  1767     CleanupStack::PopAndDestroy(2);				// CSI: 47,12 # headers, addHeadersDlg
       
  1768     }
       
  1769 
       
  1770 // ----------------------------------------------------------------------------
       
  1771 // void CMsgMailEditorAppUi::DoGetRecipientsL()
       
  1772 // ----------------------------------------------------------------------------
       
  1773 //
       
  1774 void CMsgMailEditorAppUi::DoGetRecipientsL()
       
  1775 	{
       
  1776     CImHeader& header = Document()->HeaderL();
       
  1777     CMsgAddressControl* addressField = NULL;
       
  1778 
       
  1779     addressField = AddressControl(EMsgComponentIdTo);
       
  1780     AddRecipientArrayL(addressField,
       
  1781     	header.ToRecipients());
       
  1782 
       
  1783     addressField = AddressControl(EMsgComponentIdCc);
       
  1784         AddRecipientArrayL(addressField,
       
  1785             header.CcRecipients());
       
  1786 
       
  1787     addressField = AddressControl(EMsgComponentIdBcc);
       
  1788     	AddRecipientArrayL(addressField,
       
  1789             header.BccRecipients());
       
  1790 	}
       
  1791 
       
  1792 // ----------------------------------------------------------------------------
       
  1793 // void CMsgMailEditorAppUi::DoRemoveDuplicatesL()
       
  1794 // ----------------------------------------------------------------------------
       
  1795 //
       
  1796 void CMsgMailEditorAppUi::DoRemoveDuplicatesL()
       
  1797 	{
       
  1798     // Remove duplicate addresses
       
  1799     CMsgAddressControl* addressField(NULL);
       
  1800     addressField = AddressControl(EMsgComponentIdTo);
       
  1801     RemoveDuplicatesL(addressField);
       
  1802 
       
  1803     addressField = AddressControl(EMsgComponentIdCc);
       
  1804     RemoveDuplicatesL(addressField);
       
  1805 
       
  1806     addressField = AddressControl(EMsgComponentIdBcc);
       
  1807     RemoveDuplicatesL(addressField);
       
  1808     
       
  1809     //After each control is cleaned remove rest duplicates by comparing different controls
       
  1810     RemoveDuplicatesL(AddressControl(EMsgComponentIdTo), AddressControl(EMsgComponentIdCc));
       
  1811     RemoveDuplicatesL(AddressControl(EMsgComponentIdTo), AddressControl(EMsgComponentIdBcc));
       
  1812     RemoveDuplicatesL(AddressControl(EMsgComponentIdCc), AddressControl(EMsgComponentIdBcc));
       
  1813 	}
       
  1814 
       
  1815 // -----------------------------------------------------------------------------
       
  1816 // CMsgEditorAppUi::RemoveDuplicatesL
       
  1817 //
       
  1818 // Compares two address controls and removes duplicate
       
  1819 // address from later one.
       
  1820 // -----------------------------------------------------------------------------
       
  1821 //
       
  1822 void CMsgMailEditorAppUi::RemoveDuplicatesL(CMsgAddressControl* aAddressField, 
       
  1823 		CMsgAddressControl* aLaterAddressField)
       
  1824     {
       
  1825     
       
  1826     //Symbian also removes duplicate addresses (CImHeader::IsRecipientPresent), 
       
  1827     //but it ignores BCC field for some reason.
       
  1828     
       
  1829     if(aAddressField && aLaterAddressField)
       
  1830         {
       
  1831         CMsgRecipientArray& recs = *aAddressField->GetRecipientsL();
       
  1832         CMsgRecipientArray& laterRecs = *aLaterAddressField->GetRecipientsL();
       
  1833     	    
       
  1834     	TInt laterCount(laterRecs.Count());
       
  1835     	TInt count(recs.Count());
       
  1836 
       
  1837     	for(TInt i=0; i<count; i++)
       
  1838     	    {
       
  1839     	  
       
  1840         	for(TInt j=0; j<laterCount; j++)
       
  1841         	    {
       
  1842     	        if( recs[i]->Address()->FindF(*(laterRecs[j]->Address())) >= 0 )
       
  1843                     {
       
  1844                     //Remove duplicate from later control 
       
  1845                     //and update count of that
       
  1846                     delete laterRecs.At(j);
       
  1847                     laterRecs.Delete(j);    
       
  1848                     
       
  1849                     laterCount = laterRecs.Count();
       
  1850                     
       
  1851                     //Now we can break and move to next item in aAddressField.
       
  1852                     //Duplicates in the same row should have been removed earlier.
       
  1853                     break;
       
  1854                     }
       
  1855                 }
       
  1856 	        }
       
  1857 	
       
  1858 	    aLaterAddressField->RefreshL(laterRecs);    
       
  1859         }
       
  1860     
       
  1861     
       
  1862     }
       
  1863 
       
  1864 
       
  1865 // ----------------------------------------------------------------------------
       
  1866 // void CMsgMailEditorAppUi::DoHandleCommandL()
       
  1867 // ----------------------------------------------------------------------------
       
  1868 //
       
  1869 void CMsgMailEditorAppUi::DoHandleCommandL( TInt aCommand )
       
  1870     {
       
  1871     //Still launching application.
       
  1872     //IsLaunched() can be true even if iView
       
  1873     //isn't created yet.
       
  1874     if( !Document()->IsLaunched() || !iView )
       
  1875     	{
       
  1876 		if ( aCommand != EEikCmdExit )
       
  1877 			{
       
  1878 			return;
       
  1879 			}
       
  1880     	}
       
  1881     
       
  1882 	DoFetchFileL( aCommand );
       
  1883     switch ( aCommand )
       
  1884         {
       
  1885         case EEikCmdExit:
       
  1886             if( iForceDeleteDocument )
       
  1887                 {
       
  1888                 DeleteAndExitL();
       
  1889                 }
       
  1890             else
       
  1891                 {
       
  1892                 DoMsgSaveExitL();
       
  1893                 }
       
  1894             break;
       
  1895         case EMsgMailEditorCmdSend:
       
  1896             if (AreAddressFieldsEmptyL())
       
  1897                 {
       
  1898                 DoAddRecipientL();
       
  1899                 }
       
  1900             else
       
  1901                 {
       
  1902                 DoSendMessageL();
       
  1903                 }
       
  1904             break;
       
  1905         case EMsgMailEditorCmdSendingOptions:
       
  1906             DoSendOptionsL();
       
  1907             break;
       
  1908         case EAknSoftkeyClose:
       
  1909             TRAPD(error, DoBackstepL());
       
  1910             if ( error == KErrDiskFull )
       
  1911                 {
       
  1912                 // No memory to save changes
       
  1913                 if ( MailUtils::ConfirmationQueryL(
       
  1914                     R_QTN_MAIL_CLOSE_NOSAVE, R_MAIL_EDITOR_DELETE_MESSAGE) )
       
  1915                     {
       
  1916                     Exit();
       
  1917                     }
       
  1918                 }
       
  1919             else
       
  1920                 {
       
  1921                 User::LeaveIfError( error );
       
  1922                 }
       
  1923             break;
       
  1924         case EMsgMailEditorCmdMskAddRecipient:
       
  1925             if(!AreAddressFieldsEmptyL() && !AllAddressValidL())
       
  1926                 {
       
  1927                 CheckRecipientsL(EFalse);
       
  1928                 }
       
  1929             else
       
  1930                 {
       
  1931                 DoAddRecipientL();    
       
  1932                 }
       
  1933              break;
       
  1934         case EMsgMailEditorCmdAddRecipient:
       
  1935             DoAddRecipientL();
       
  1936             break;
       
  1937         case EMsgMailEditorCmdAttachments:
       
  1938             DoAttachmentL();
       
  1939             break;
       
  1940         case EMsgMailEditorCmdInsertMenu:
       
  1941         	DoShowSelectionListL();
       
  1942            	break;
       
  1943         case EMsgMailEditorCmdInsertTemplate:
       
  1944 	    // If user chooses Cancel while selecting template text
       
  1945         // DoShowToolBarTextL leaves. This is ok so leave is catched here.
       
  1946         	TRAPD(err, InsertTemplateL() );
       
  1947 		    if( err != KErrCancel )
       
  1948 	            {
       
  1949 	            User::LeaveIfError( err );
       
  1950 	            }
       
  1951             UpdateMessageSizeL();
       
  1952             break;
       
  1953         case EMsgMailEditorCmdInsertTemplateNote:
       
  1954             User::LeaveIfError( InsertTextMemoL() );
       
  1955             UpdateMessageSizeL();
       
  1956             break;
       
  1957         case EMsgMailEditorCmdMessageInfo:
       
  1958             DoMessageInfoL();
       
  1959             break;
       
  1960         case EMsgMailEditorCmdAddHeaders:
       
  1961             DoAdditionalHeadersL();
       
  1962             break;
       
  1963         // general options:
       
  1964         case EEikCmdEditCut:
       
  1965             iView->FocusedControl()->ClipboardL(EMsgCut);
       
  1966             UpdateMessageSizeL();
       
  1967             break;
       
  1968         case EEikCmdEditCopy:
       
  1969             iView->FocusedControl()->ClipboardL(EMsgCopy);
       
  1970             break;
       
  1971         case EEikCmdEditPaste:
       
  1972             iView->FocusedControl()->ClipboardL(EMsgPaste);
       
  1973             UpdateMessageSizeL();
       
  1974             break;
       
  1975         case EMsgMailEditorCmdExpandInsert:
       
  1976 			break;
       
  1977         case EAknCmdHelp:
       
  1978             {
       
  1979             if ((iCommonFlags & EHelpSupported))
       
  1980                 {
       
  1981                 // Launch help
       
  1982                 HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
  1983                     iEikonEnv->EikAppUi()->AppHelpContextL() );
       
  1984                 }
       
  1985             break;
       
  1986             }
       
  1987         case EMsgDispSizeAutomatic:
       
  1988         // FALLTHROUGH
       
  1989         case EMsgDispSizeLarge:
       
  1990         // FALLTHROUGH
       
  1991         case EMsgDispSizeNormal:
       
  1992         // FALLTHROUGH
       
  1993         case EMsgDispSizeSmall:
       
  1994             HandleLocalZoomChangeL( (TMsgCommonCommands)aCommand );
       
  1995             break;
       
  1996         default:
       
  1997             CMsgMailAppUi::HandleCommandL(aCommand);
       
  1998             break;
       
  1999         }                       
       
  2000     }
       
  2001 
       
  2002 // ----------------------------------------------------------------------------
       
  2003 // void CMsgMailEditorAppUi::EditorObserverL()
       
  2004 // ----------------------------------------------------------------------------
       
  2005 //
       
  2006 void CMsgMailEditorAppUi::EditorObserverL(
       
  2007     TMsgEditorObserverFunc aFunc,
       
  2008     TAny* aArg1,
       
  2009     TAny* aArg2,
       
  2010     TAny* /*aArg3*/ )
       
  2011 	{
       
  2012 	if ( aFunc == MMsgEditorObserver::EMsgHandleFocusChange )
       
  2013 		{
       
  2014 		ASSERT( aArg1 );
       
  2015 		ASSERT( aArg2 );
       
  2016 
       
  2017 		TMsgFocusEvent event = *(static_cast<TMsgFocusEvent*>( aArg1 ) );    		
       
  2018 		TInt controlId = *(static_cast<TInt*>( aArg2 ) );
       
  2019     		                  
       
  2020         switch( event )
       
  2021             {
       
  2022             case EMsgFocusMovingFrom:
       
  2023                 {
       
  2024                 if ( controlId == EMsgComponentIdAttachment )
       
  2025                     {                        
       
  2026                     iNaviPaneUtils->EnableOwnNaviPaneL( EFalse );
       
  2027                     }
       
  2028                      
       
  2029                 // Set input mode (e.g. number mode)to other address fields too
       
  2030 				CMsgAddressControl* ctrl = AddressControl( controlId );
       
  2031                 if ( ctrl )
       
  2032                 	{
       
  2033                 	TInt mode( ctrl->Editor().AknEditorCurrentInputMode() );
       
  2034                     SetInputModeToAddressFields( mode );
       
  2035                 	}
       
  2036                 }// EMsgFocusMovingFrom
       
  2037                 break;
       
  2038             case EMsgFocusMovedTo:
       
  2039                 {
       
  2040                 CheckFocusForMskL( controlId );
       
  2041                 if ( controlId == EMsgComponentIdAttachment )
       
  2042                     {     
       
  2043                     iNaviPaneUtils->EnableOwnNaviPaneL( ETrue );
       
  2044                     }
       
  2045                 } // EMsgFocusMovingTo
       
  2046                 break;
       
  2047             } // switch
       
  2048 		}
       
  2049 #ifdef RD_SCALABLE_UI_V2
       
  2050 	else if( aFunc == MMsgEditorObserver::EMsgButtonEvent )
       
  2051 		{
       
  2052 		ASSERT( aArg1 );
       
  2053 		
       
  2054 		//Get the parameter
       
  2055 		CMsgBaseControl* control = static_cast<CMsgBaseControl*>( aArg1 );
       
  2056         
       
  2057         //Attachment handling is mostly done in pointer event branch.
       
  2058 		//Here we tackle situation where focus is not in attachment row
       
  2059 		//and the button is pressed. 
       
  2060 		//Also other button events go this way, but attachment handling
       
  2061 		//is a special case.
       
  2062 		if ( control && ( control->ControlId() != EMsgComponentIdAttachment ||
       
  2063 		        iFocusedControl != control ) )
       
  2064 			{
       
  2065 			//Summon touch functionality
       
  2066 			ControlTouchedL( *control );	
       
  2067         	}
       
  2068 		}
       
  2069 	else if( aFunc == MMsgEditorObserver::EMsgControlPointerEvent )
       
  2070 		{
       
  2071 		if( aArg1 && aArg2 )
       
  2072 			{
       
  2073             TPointerEvent* event = static_cast<TPointerEvent*>( aArg2 );
       
  2074             CMsgBaseControl* control = static_cast<CMsgBaseControl*>( aArg1 );
       
  2075 
       
  2076             if ( event->iType == TPointerEvent::EButton1Down )
       
  2077                 {
       
  2078                 //This is done to check if control is already focused.
       
  2079                 //When attachment row is clicked and it has focus
       
  2080                 //attachment dialog is opened. Otherwise row just gains focus.                
       
  2081                 iFocusedControl = control && control->IsFocused() ? control : NULL;
       
  2082                 }
       
  2083             else if ( event->iType == TPointerEvent::EButton1Up )
       
  2084                 {
       
  2085 				if( control && iFocusedControl == control && 
       
  2086 					control->ControlId() == EMsgComponentIdAttachment )        
       
  2087 					{			
       
  2088 					//Summon touch functionality
       
  2089 					ControlTouchedL( *control );
       
  2090 					}
       
  2091                 }
       
  2092 			}
       
  2093 		}
       
  2094 #endif
       
  2095 	}
       
  2096 
       
  2097 // ---------------------------------------------------------------------------
       
  2098 // CMsgMailEditorAppUi::CheckFocusForMSK
       
  2099 // ---------------------------------------------------------------------------
       
  2100 //
       
  2101 void CMsgMailEditorAppUi::CheckFocusForMskL(TInt aControl)
       
  2102     {
       
  2103 
       
  2104     RemoveMSKCommands();
       
  2105     switch(aControl)
       
  2106         {
       
  2107         case EMsgComponentIdTo:
       
  2108         // FALLTHROUGH
       
  2109         case EMsgComponentIdCc:
       
  2110         // FALLTHROUGH
       
  2111         case EMsgComponentIdBcc:
       
  2112              SetMiddleSoftKeyLabelL(R_QTN_MSK_ADD,
       
  2113                 EMsgMailEditorCmdMskAddRecipient);
       
  2114              break;
       
  2115 
       
  2116         case EMsgComponentIdAttachment:
       
  2117             SetMiddleSoftKeyLabelL(R_QTN_MSK_ATTACHMENT,
       
  2118                 EMsgMailEditorCmdAttachments);
       
  2119             break;
       
  2120 
       
  2121         default:
       
  2122             //Change msk label back to normal (context sensitive menu icon)
       
  2123             SetMiddleSoftKeyLabelL(R_TEXT_SOFTKEY_OPTION,
       
  2124                 EAknSoftkeyContextOptions);
       
  2125         }
       
  2126 
       
  2127     }
       
  2128 
       
  2129 // ---------------------------------------------------------------------------
       
  2130 // CMsgMailEditorAppUi::SetMiddleSoftKeyLabelL
       
  2131 // ---------------------------------------------------------------------------
       
  2132 //
       
  2133 void CMsgMailEditorAppUi::SetMiddleSoftKeyLabelL(
       
  2134     const TInt aResourceId, const TInt aCommandId )
       
  2135     {
       
  2136     CEikButtonGroupContainer* cbaGroup = Cba();
       
  2137     if ( cbaGroup )
       
  2138         {
       
  2139         HBufC* middleSKText = StringLoader::LoadLC( aResourceId );
       
  2140         TPtr mskPtr = middleSKText->Des();
       
  2141         cbaGroup->AddCommandToStackL(
       
  2142             KMSKControlID,
       
  2143             aCommandId,
       
  2144             mskPtr );
       
  2145         CleanupStack::PopAndDestroy( middleSKText );
       
  2146         }
       
  2147     }
       
  2148 
       
  2149 // -----------------------------------------------------------------------------
       
  2150 // CMsgMailEditorAppUi::RemoveMSKCommands
       
  2151 // -----------------------------------------------------------------------------
       
  2152 //
       
  2153 void CMsgMailEditorAppUi::RemoveMSKCommands()
       
  2154     {
       
  2155     if ( Cba() )
       
  2156         {
       
  2157         Cba()->RemoveCommandFromStack( KMSKControlID,
       
  2158             EMsgMailEditorCmdMskAddRecipient);
       
  2159         Cba()->RemoveCommandFromStack( KMSKControlID,
       
  2160             EMsgMailEditorCmdAttachments );
       
  2161         Cba()->RemoveCommandFromStack( KMSKControlID,
       
  2162             EAknSoftkeyContextOptions );
       
  2163         }
       
  2164     }
       
  2165 
       
  2166 // -----------------------------------------------------------------------------
       
  2167 // CMsgEditorAppUi::InitPhoneBookL
       
  2168 // -----------------------------------------------------------------------------
       
  2169 //
       
  2170 void CMsgMailEditorAppUi::InitPhoneBookL()
       
  2171     {
       
  2172     // initialize pb
       
  2173     if ( !iCheckNames )
       
  2174         {
       
  2175         TRAP_IGNORE( iCheckNames = CMsgCheckNames::NewL() );
       
  2176         }
       
  2177     ASSERT( iCheckNames );
       
  2178     }
       
  2179 
       
  2180 // -----------------------------------------------------------------------------
       
  2181 // CMsgEditorAppUi::SearchUnverifiedStringL
       
  2182 // -----------------------------------------------------------------------------
       
  2183 //
       
  2184 void CMsgMailEditorAppUi::SearchUnverifiedStringL(
       
  2185     const TDesC& aText, CMsgAddressControl* aControl )
       
  2186     {
       
  2187     ASSERT( aControl );
       
  2188     HBufC* buf = NULL;
       
  2189     iView->SetFocus(aControl->ControlId());
       
  2190     aControl->GetFirstUnverifiedStringL(buf);
       
  2191     while (buf && buf->Compare(aText) != 0)
       
  2192         {
       
  2193         delete buf;
       
  2194         buf = NULL;
       
  2195         aControl->GetNextUnverifiedStringL(buf);
       
  2196         }
       
  2197     delete buf;
       
  2198     buf = NULL;
       
  2199     }
       
  2200 
       
  2201 // -----------------------------------------------------------------------------
       
  2202 // CMsgEditorAppUi::AllAddressValidL
       
  2203 // -----------------------------------------------------------------------------
       
  2204 //
       
  2205 TBool CMsgMailEditorAppUi::AllAddressValidL()
       
  2206     {
       
  2207     TInt i(0);
       
  2208     TBool ret(ETrue);
       
  2209 
       
  2210     CMsgAddressControl* addressField = AddressControl(EMsgComponentIdTo);
       
  2211     CMsgRecipientArray* rcpt = addressField->GetRecipientsL();
       
  2212 
       
  2213     while (i < rcpt->Count() && ret)
       
  2214         {
       
  2215         ret = IsValidAddress (*rcpt->At(i)->Address());
       
  2216         i++;
       
  2217         }
       
  2218 
       
  2219     if (ret)
       
  2220         {
       
  2221         addressField = AddressControl(EMsgComponentIdCc);
       
  2222         if(addressField)
       
  2223             {
       
  2224             rcpt = addressField->GetRecipientsL();
       
  2225             i=0;
       
  2226             while (i < rcpt->Count() && ret)
       
  2227                 {
       
  2228                 ret = IsValidAddress (*rcpt->At(i)->Address());
       
  2229                 i++;
       
  2230                 }
       
  2231             }
       
  2232         }
       
  2233 
       
  2234     if (ret)
       
  2235         {
       
  2236         addressField = AddressControl(EMsgComponentIdBcc);
       
  2237 
       
  2238         if(addressField)
       
  2239             {
       
  2240             rcpt = addressField->GetRecipientsL();
       
  2241             i=0;
       
  2242             while (i < rcpt->Count() && ret)
       
  2243                 {
       
  2244                 ret = IsValidAddress (*rcpt->At(i)->Address());
       
  2245                 i++;
       
  2246                 }
       
  2247             }
       
  2248         }
       
  2249 
       
  2250     return ret;
       
  2251     }
       
  2252 
       
  2253 // -----------------------------------------------------------------------------
       
  2254 // CMsgEditorAppUi::SetFocusToFirstFreeFieldL
       
  2255 // -----------------------------------------------------------------------------
       
  2256 //
       
  2257 void CMsgMailEditorAppUi::SetFocusToFirstFreeFieldL()
       
  2258     {
       
  2259     // Set focus at begining of the message when replying
       
  2260     if ( Document()->IsReplyMessage() )
       
  2261         {
       
  2262         iView->SetFocus(EMsgComponentIdBody);
       
  2263         }
       
  2264     // set focus at first free field
       
  2265     else
       
  2266         {
       
  2267         if(AddressControl(EMsgComponentIdTo))
       
  2268             {
       
  2269             if (!AddressControl(EMsgComponentIdTo)->Editor().TextLength())
       
  2270                 {
       
  2271                 iView->SetFocus(EMsgComponentIdTo);
       
  2272                 return;
       
  2273                 }
       
  2274             }
       
  2275         if (AddressControl(EMsgComponentIdCc))
       
  2276             {
       
  2277             if (!AddressControl(EMsgComponentIdCc)->Editor().TextLength())
       
  2278                 {
       
  2279                 iView->SetFocus(EMsgComponentIdCc);
       
  2280                 return;
       
  2281                 }
       
  2282             }
       
  2283         if (AddressControl(EMsgComponentIdBcc))
       
  2284             {
       
  2285             if (!AddressControl(EMsgComponentIdBcc)->Editor().TextLength())
       
  2286                 {
       
  2287                 iView->SetFocus(EMsgComponentIdBcc);
       
  2288                 return;
       
  2289                 }
       
  2290             }
       
  2291         if (SubjectControl())
       
  2292             {
       
  2293             if (!SubjectControl()->Editor().TextLength())
       
  2294                 {
       
  2295                 iView->SetFocus(EMsgComponentIdSubject);
       
  2296                 return;
       
  2297                 }
       
  2298             }
       
  2299         iView->SetFocus(EMsgComponentIdBody);
       
  2300         CEikRichTextEditor& editor = BodyControl()->Editor();
       
  2301         editor.SetCursorPosL(editor.TextLength(), EFalse);
       
  2302         }
       
  2303     }
       
  2304 
       
  2305 // -----------------------------------------------------------------------------
       
  2306 // CMsgEditorAppUi::ShowSelectedMailboxL
       
  2307 // -----------------------------------------------------------------------------
       
  2308 //
       
  2309 void CMsgMailEditorAppUi::ShowSelectedMailboxL()
       
  2310     {
       
  2311     const CMsgMailEditorDocument* doc = Document();
       
  2312     CMsvEntry* rootEntry = doc->Session().GetEntryL(KMsvRootIndexEntryId);
       
  2313     CleanupStack::PushL(rootEntry);
       
  2314 
       
  2315     TInt noteResource(0);
       
  2316     TInt64 flags = MImumInHealthServices::EFlagSetHealthyReceiving;
       
  2317     
       
  2318 	noteResource = R_MAIL_EDITOR_MAILBOX_IN_USE_TEXT;
       
  2319         
       
  2320 
       
  2321     // if more than one box defined, show its name
       
  2322     if ( Document()->GetHealthyMailboxListL( flags ).Count() > 1 )
       
  2323         {
       
  2324         const TMsvId service(doc->SendOptions().ServiceId());
       
  2325         TMsvSelectionOrdering ordering(rootEntry->SortType());
       
  2326         ordering.SetShowInvisibleEntries(ETrue);
       
  2327         rootEntry->SetSortTypeL(ordering);
       
  2328         const TMsvEntry child = rootEntry->ChildDataL(service);
       
  2329         HBufC* stringholder = StringLoader::LoadLC(
       
  2330             noteResource, child.iDetails, iEikonEnv );
       
  2331 
       
  2332         CAknInformationNote* note = new(ELeave) CAknInformationNote(ETrue);
       
  2333         note->ExecuteLD(*stringholder);
       
  2334         CleanupStack::PopAndDestroy( stringholder ); // stringholder
       
  2335         }
       
  2336     CleanupStack::PopAndDestroy( rootEntry ); // rootEntry
       
  2337     }
       
  2338 
       
  2339 // -----------------------------------------------------------------------------
       
  2340 // CMsgEditorAppUi::RemoveDuplicatesL
       
  2341 // -----------------------------------------------------------------------------
       
  2342 //
       
  2343 void CMsgMailEditorAppUi::RemoveDuplicatesL(CMsgAddressControl* aAddressField)
       
  2344     {
       
  2345     if ( aAddressField )
       
  2346     	{
       
  2347 	    CMsgRecipientArray& recs = *aAddressField->GetRecipientsL();
       
  2348 	    TInt count(recs.Count());
       
  2349 	    for (TInt i=0; i < count; i++)
       
  2350 	        {
       
  2351 	        for (TInt j = i + 1; j < count; )
       
  2352 	            {
       
  2353 	            if (recs[i]->Address()->Compare(*(recs[j]->Address())) == 0)
       
  2354 	                {
       
  2355 	                if (recs[i]->Name()->Length())
       
  2356 	                    {
       
  2357 	                    delete recs.At(j);
       
  2358 	                    recs.Delete(j);
       
  2359 	                    }
       
  2360 	                else
       
  2361 	                    {
       
  2362 	                    delete recs.At(i);
       
  2363 	                    recs.Delete(i);
       
  2364 	                    }
       
  2365 	                count = recs.Count();
       
  2366 	                }
       
  2367 	            else
       
  2368 	                {
       
  2369 	                // increase j if something wasn't deleted. if j is
       
  2370 	                // increased when nothing is deleted, elements are skipped
       
  2371 	                j++;
       
  2372 	                }
       
  2373 	            }
       
  2374 	        }
       
  2375 	    aAddressField->RefreshL(recs);
       
  2376     	}
       
  2377     }
       
  2378 
       
  2379 // ----------------------------------------------------------------------------
       
  2380 // CMsgMailEditorAppUi::MopSupplyObject(TTypeUid aId)
       
  2381 // Returns a pointer to popup menu.
       
  2382 // ----------------------------------------------------------------------------
       
  2383 //
       
  2384 TTypeUid::Ptr CMsgMailEditorAppUi::MopSupplyObject(TTypeUid aId)
       
  2385     {
       
  2386     return SupplyMopObject(aId);
       
  2387     }
       
  2388 
       
  2389 // ----------------------------------------------------------------------------
       
  2390 // CMsgMailEditorAppUi::StopWaitNote
       
  2391 // ----------------------------------------------------------------------------
       
  2392 //
       
  2393 void CMsgMailEditorAppUi::StopWaitNote()
       
  2394 	{
       
  2395     delete iWaitNote;
       
  2396     iWaitNote = NULL;
       
  2397 	}
       
  2398 
       
  2399 // ----------------------------------------------------------------------------
       
  2400 // CMsgMailEditorAppUi::StartWaitNoteLC
       
  2401 // ----------------------------------------------------------------------------
       
  2402 //
       
  2403 void CMsgMailEditorAppUi::StartWaitNoteLC(
       
  2404     TInt aStringResourceId, TBool aDelayOff )
       
  2405     {
       
  2406     StartWaitNoteLC( aStringResourceId, aDelayOff, R_MEB_WAIT_NOTE );
       
  2407     }
       
  2408 
       
  2409 // ----------------------------------------------------------------------------
       
  2410 // CMsgMailEditorAppUi::StartWaitNoteLC
       
  2411 // ----------------------------------------------------------------------------
       
  2412 //
       
  2413 void CMsgMailEditorAppUi::StartWaitNoteLC(
       
  2414     TInt aStringResourceId, TBool aDelayOff, TInt aResouceID )
       
  2415     {
       
  2416     StopWaitNote();
       
  2417     iWaitNote = new(ELeave) CAknWaitDialog(
       
  2418             reinterpret_cast <CEikDialog**>(&iWaitNote), aDelayOff );
       
  2419     CleanupStack::PushL(TCleanupItem(CleanupWaitDialog, (TAny**)&iWaitNote));
       
  2420     iWaitNote->PrepareLC( aResouceID );
       
  2421     HBufC* text = StringLoaderLoadLC( aStringResourceId );
       
  2422     iWaitNote->SetTextL(*text);
       
  2423     CleanupStack::PopAndDestroy( text ); // text
       
  2424     
       
  2425 	// safe to call LD even as a member variable, since sets itself to NULL when deleting
       
  2426     iWaitNote->RunLD(); // CSI: 50 # see comment above
       
  2427     }
       
  2428 
       
  2429 // ----------------------------------------------------------------------------
       
  2430 // CMsgMailEditorAppUi::StringLoaderLoadLC
       
  2431 // ----------------------------------------------------------------------------
       
  2432 //
       
  2433 HBufC* CMsgMailEditorAppUi::StringLoaderLoadLC( TInt aTextResource )
       
  2434     {
       
  2435     return StringLoader::LoadLC( aTextResource, iEikonEnv );
       
  2436     }
       
  2437 
       
  2438 // -----------------------------------------------------------------------------
       
  2439 // CMsgMailEditorAppUi::SpecialScrolling
       
  2440 // -----------------------------------------------------------------------------
       
  2441 //
       
  2442 TBool CMsgMailEditorAppUi::SpecialScrolling( TUint aKeyCode )
       
  2443     {
       
  2444     TBool keyConsumed( EFalse );
       
  2445     if ( aKeyCode == EStdKeyUpArrow || aKeyCode == EStdKeyDownArrow )
       
  2446         {
       
  2447         CMsgBaseControl* focusedControl = iView->FocusedControl();
       
  2448         if ( focusedControl )
       
  2449             {
       
  2450             TInt focused( focusedControl->ControlId() );
       
  2451             if ( aKeyCode == EStdKeyDownArrow )
       
  2452                 {
       
  2453                 // Focus on Reply-to field??
       
  2454                 if (  focused == EMailEditorControlReplyTo )
       
  2455                     {
       
  2456                     // jump directly to atta control
       
  2457                     LOG( "CMsgMailEditorAppUi::SpecialScrolling - Down" );
       
  2458                     RotateFocus( ETrue, EMailEditorControlReplyTo );
       
  2459                     keyConsumed = ETrue;
       
  2460                     }
       
  2461                 }
       
  2462             else
       
  2463                 {
       
  2464                 // scroll up, and focus is top of the body part
       
  2465                 if ( focused == EMailEditorControlReplyTo )
       
  2466                         {
       
  2467                         LOG( "CMsgMailEditorAppUi::SpecialScrolling - Up" );
       
  2468                         RotateFocus( EFalse, EMailEditorControlReplyTo );
       
  2469                         keyConsumed = ETrue;
       
  2470                         }
       
  2471                 }
       
  2472             }
       
  2473         }
       
  2474 
       
  2475     return keyConsumed;
       
  2476     }
       
  2477 
       
  2478 // -----------------------------------------------------------------------------
       
  2479 // CMsgMailEditorAppUi::RotateFocus
       
  2480 // -----------------------------------------------------------------------------
       
  2481 //
       
  2482 void CMsgMailEditorAppUi::RotateFocus( TBool aDirection, TInt aCurrentFocus )
       
  2483     {
       
  2484     // Mail editor control order
       
  2485     const TInt TControls[] =
       
  2486         {
       
  2487         EMsgComponentIdTo,
       
  2488         EMsgComponentIdCc,
       
  2489         EMsgComponentIdBcc,
       
  2490         EMailEditorControlReplyTo,
       
  2491         EMsgComponentIdSubject,
       
  2492         EMsgComponentIdAttachment,
       
  2493         EMsgComponentIdBody
       
  2494         };
       
  2495 
       
  2496     const TInt count( sizeof(TControls) / sizeof(TInt) );
       
  2497     TInt index(0); // index starts from 0
       
  2498 	for(; index<count; ++index)
       
  2499 	    {
       
  2500 	    __ASSERT_DEBUG( index >= 0 && index < count, User::Invariant() );
       
  2501 	    
       
  2502 	    if ( aCurrentFocus == TControls[ index ] )	// CSI: 2 # This is checked above in the assert macro.
       
  2503 	        {
       
  2504 	        // locate currently focused item
       
  2505 	        break;
       
  2506 	        }
       
  2507 	    }
       
  2508     CMsgBaseControl* control(NULL);
       
  2509 	while ( !control )
       
  2510 	    {
       
  2511         // Then find next control for current position
       
  2512         aDirection ? ++index : --index;
       
  2513         ASSERT( index >= 0 && index < count );
       
  2514         control = iView->ControlById( TControls[ index ] );	// CSI: 2 # This is checked above in the assert macro.
       
  2515 	    }
       
  2516 
       
  2517 	LOG( "CMsgMailEditorAppUi::RotateFocus" );
       
  2518     iView->SetFocus( control->ControlId() );
       
  2519     }
       
  2520 
       
  2521 // ----------------------------------------------------------------------------
       
  2522 // CMsgMailEditorAppUi::AddRecipientArrayL
       
  2523 // ----------------------------------------------------------------------------
       
  2524 //
       
  2525 void CMsgMailEditorAppUi::AddRecipientArrayL(CMsgAddressControl* aControl,
       
  2526     const CDesCArray& aArray)
       
  2527     {
       
  2528     const TInt count(aArray.Count());
       
  2529     if ( aControl && count>0 )
       
  2530     	{
       
  2531     	CMsgRecipientList* recipientList = CMsgRecipientList::NewL();
       
  2532     	CleanupStack::PushL(recipientList);
       
  2533 
       
  2534 	    for ( TInt index=0; index<count; ++index )
       
  2535 	    	{
       
  2536 	    	TBool aliasFound( EFalse );
       
  2537 	    	TImMessageField msgField;
       
  2538 		    HBufC* address = msgField.GetValidInternetEmailAddressFromString(
       
  2539 		        aArray[index]).AllocLC();
       
  2540 			address->Des().Trim();
       
  2541 
       
  2542             TInt found(KErrNone);
       
  2543             TPtrC16 aliasPtr = msgField.GetValidAlias(
       
  2544 		        aArray[index], found );
       
  2545 		    HBufC* alias;
       
  2546 		    if ( found  == KErrNone )
       
  2547 		        {
       
  2548 		        alias = aliasPtr.AllocLC();
       
  2549 		        aliasFound = ETrue;
       
  2550 		        }
       
  2551 		    else
       
  2552 		        {
       
  2553 		        alias = KNullDesC().AllocLC();
       
  2554 		        }
       
  2555 
       
  2556 		    CMsgRecipientItem* reci =
       
  2557 		    	CMsgRecipientItem::NewLC(*alias, *address);
       
  2558 		    	
       
  2559 			//verified is set according to alias found status
       
  2560 			//as editorbase uses the alias only if verified == ETrue
       
  2561 		    reci->SetVerified( aliasFound );
       
  2562 			
       
  2563 		    recipientList->AppendL(reci);
       
  2564 		    // Ownership transferred just pop
       
  2565 		    CleanupStack::Pop( reci );  // reci
       
  2566 		    CleanupStack::PopAndDestroy( 2, address ); 			// CSI: 47,12 # alias, address
       
  2567 	    	}
       
  2568 
       
  2569         if ( recipientList->Count() )
       
  2570             {
       
  2571             aControl->AddRecipientsL(*recipientList);
       
  2572             }
       
  2573 	    CleanupStack::PopAndDestroy( recipientList ); // recipientList
       
  2574     	}
       
  2575     }
       
  2576 
       
  2577 //---------------------------------------------------------------------------
       
  2578 //  CMsgMailEditorAppUi::CheckGlobalReplyToSettingL()
       
  2579 //  Gets mailbox reply to address from smtp settings
       
  2580 //  and adds it to mail header if address is different
       
  2581 //  than address of mailbox. Returns ETrue if new value is
       
  2582 //  set.
       
  2583 //---------------------------------------------------------------------------
       
  2584 TBool CMsgMailEditorAppUi::CheckGlobalReplyToSettingL()
       
  2585     {
       
  2586     TBool retVal = EFalse;
       
  2587 
       
  2588     CMsgMailEditorDocument& doc = *Document();
       
  2589 
       
  2590     //Get smtp account and load smtp settings
       
  2591 	CEmailAccounts* smtpAccount = CEmailAccounts::NewLC();
       
  2592     CImSmtpSettings* smtpSet=new(ELeave)CImSmtpSettings();
       
  2593     CleanupStack::PushL(smtpSet);
       
  2594     const TMsvId smtpSetId = doc.CurrentEntry().Entry().iServiceId;
       
  2595 
       
  2596     TSmtpAccount accountParams;
       
  2597     smtpAccount->GetSmtpAccountL( smtpSetId, accountParams );
       
  2598 	smtpAccount->LoadSmtpSettingsL(accountParams, *smtpSet);
       
  2599 
       
  2600     //Check that if reply to address is same as mailbox address
       
  2601     //do not add "reply to" field for header. Otherwise "reply to" field
       
  2602     //would be always visible.
       
  2603     if(smtpSet->ReplyToAddress().Compare(smtpSet->EmailAddress() ) != 0)
       
  2604         {
       
  2605         CImHeader& header = doc.HeaderL();
       
  2606         
       
  2607         header.SetReplyToL( smtpSet->ReplyToAddress() );
       
  2608 
       
  2609         ASSERT( iMailEditorHeader );
       
  2610         iMailEditorHeader->UpdateReplyToControlL();
       
  2611 
       
  2612         retVal = ETrue;
       
  2613         }
       
  2614     else
       
  2615         {
       
  2616         retVal = EFalse;
       
  2617         }
       
  2618 
       
  2619     CleanupStack::PopAndDestroy(2, smtpAccount);			// CSI: 47,12 # smtpSet
       
  2620 
       
  2621     return retVal;
       
  2622     }
       
  2623 
       
  2624 // ---------------------------------------------------------
       
  2625 // CMsgMailEditorAppUi::SetInputModeToAddressFields
       
  2626 // ---------------------------------------------------------
       
  2627 void CMsgMailEditorAppUi::SetInputModeToAddressFields( TInt aInputMode )
       
  2628     {
       
  2629     CMsgAddressControl* ctrl( NULL );
       
  2630     for ( TInt ctrlId( EMsgComponentIdTo );
       
  2631           ctrlId <= EMsgComponentIdBcc; ctrlId++ )
       
  2632         {
       
  2633         ctrl = AddressControl( ctrlId );
       
  2634         if ( ctrl )
       
  2635             {
       
  2636             ctrl->Editor().SetAknEditorCurrentInputMode( aInputMode );
       
  2637             }
       
  2638         }
       
  2639     }
       
  2640 
       
  2641 // ---------------------------------------------------------
       
  2642 // CMsgMailEditorAppUi::SetFocusAfterAddRecipientL
       
  2643 // ---------------------------------------------------------
       
  2644 void CMsgMailEditorAppUi::SetFocusAfterAddRecipientL( TMsgControlId aFocusBeforeAdd )
       
  2645     {    
       
  2646 	//If the  cursor is in some other place than the address fields when "Add recipient"
       
  2647 	//is selected the cursor remains in this same address field (do nothing). 
       
  2648      if ( aFocusBeforeAdd == EMsgComponentIdTo ||
       
  2649     	aFocusBeforeAdd == EMsgComponentIdCc ||
       
  2650     	aFocusBeforeAdd == EMsgComponentIdBcc )
       
  2651     	{
       
  2652     	//Set the cursor to the next empty address field if there is one. 
       
  2653     	
       
  2654     	//From "To" to "CC" if available
       
  2655         if( aFocusBeforeAdd < EMsgComponentIdCc && 
       
  2656         	AddressControl(EMsgComponentIdCc) &&
       
  2657         	!AddressControl(EMsgComponentIdCc)->Editor().TextLength() )
       
  2658             {
       
  2659             iView->SetFocus(EMsgComponentIdCc);
       
  2660             }
       
  2661 
       
  2662     	//From "To" or "CC" to "BCC" if available
       
  2663         else if( aFocusBeforeAdd < EMsgComponentIdBcc && 
       
  2664         	AddressControl(EMsgComponentIdBcc) &&
       
  2665         	!AddressControl(EMsgComponentIdBcc)->Editor().TextLength() )
       
  2666             {
       
  2667             iView->SetFocus(EMsgComponentIdBcc);
       
  2668             }
       
  2669             
       
  2670     	//To "Subject" if CC and BCC have not been available           
       
  2671         else if( SubjectControl() && !SubjectControl()->Editor().TextLength() )
       
  2672             {
       
  2673 			iView->SetFocus(EMsgComponentIdSubject);
       
  2674             }            
       
  2675             
       
  2676 	    //In other case cursor is placed into the text body
       
  2677 	    //1) the beginning of the text body if it is empty, or 
       
  2678 	    //2) the end of text body if there is text already.
       
  2679 	    else
       
  2680 	    	{
       
  2681 			iView->SetFocus(EMsgComponentIdBody);
       
  2682 			CEikRichTextEditor& editor = BodyControl()->Editor();
       
  2683 			editor.SetCursorPosL(editor.TextLength(), EFalse);  	    		
       
  2684 	    	}	
       
  2685     	}
       
  2686     }
       
  2687     
       
  2688 // ---------------------------------------------------------------------------
       
  2689 // CMsgMailEditorAppUi::ControlTouchedL
       
  2690 //
       
  2691 // Control has been touched. Invoke appopriate actions
       
  2692 // ---------------------------------------------------------------------------
       
  2693 //
       
  2694 #ifdef RD_SCALABLE_UI_V2
       
  2695 void CMsgMailEditorAppUi::ControlTouchedL( const CMsgBaseControl& aControl )
       
  2696 	{
       
  2697     //Check the control id
       
  2698     TInt touchedControlId = aControl.ControlId();
       
  2699 	switch( touchedControlId )
       
  2700 		{
       
  2701 		//Touch in address fields
       
  2702 		case EMsgComponentIdTo:
       
  2703 		case EMsgComponentIdCc:
       
  2704 		case EMsgComponentIdBcc:
       
  2705 		    {
       
  2706 			//Set focus to touched control (if needed)
       
  2707 			TInt focusedControlId = iView->FocusedControl()->ControlId(); 
       
  2708 			
       
  2709 			if ( focusedControlId != touchedControlId )
       
  2710 				{
       
  2711 				iView->SetFocus( touchedControlId );	
       
  2712 				}
       
  2713 
       
  2714             if(!AreAddressFieldsEmptyL() && !AllAddressValidL())
       
  2715                 {
       
  2716                 CheckRecipientsL(EFalse);
       
  2717                 }
       
  2718             else
       
  2719                 {
       
  2720                 DoAddRecipientL();    
       
  2721                 }
       
  2722 			break;
       
  2723 		    }
       
  2724 		//Touch in attachment button
       
  2725 		case EMsgComponentIdAttachment:
       
  2726 		    {
       
  2727 		    //Open attachment view
       
  2728 			DoAttachmentL();
       
  2729 			break;
       
  2730 		    }
       
  2731 		default:
       
  2732 			{
       
  2733 			LOG1( "CMsgMailEditorAppUi::ControlTouchedL - Unhandled control! id %d",  touchedControlId );	
       
  2734 			}
       
  2735 		} // switch   		
       
  2736 	}
       
  2737 #endif
       
  2738 
       
  2739 // --------------------------------------------------------------------------
       
  2740 // CMsgMailEditorAppUi::HandleEnterKeyL
       
  2741 // Handles enter key events.
       
  2742 // --------------------------------------------------------------------------
       
  2743 //
       
  2744 void CMsgMailEditorAppUi::HandleEnterKeyL()
       
  2745     {
       
  2746     if( iView )
       
  2747         {
       
  2748         CMsgBaseControl* focusedCtrl = iView->FocusedControl();
       
  2749         if( focusedCtrl )
       
  2750             {
       
  2751             switch( focusedCtrl->ControlId() )
       
  2752                 {
       
  2753                 case EMsgComponentIdAttachment:
       
  2754                     {
       
  2755                     // Open attachment view
       
  2756                     DoAttachmentL();
       
  2757                     break;
       
  2758                     }
       
  2759                 default:
       
  2760                     {
       
  2761                     // event ignored for other controls.
       
  2762                     break;
       
  2763                     }
       
  2764                 }
       
  2765             }
       
  2766         }
       
  2767     }
       
  2768 
       
  2769 // --------------------------------------------------------------------------
       
  2770 // CMsgMailEditorAppUi::HandleSystemEventL
       
  2771 // Handles system events
       
  2772 // --------------------------------------------------------------------------
       
  2773 //
       
  2774 void CMsgMailEditorAppUi::HandleSystemEventL( const TWsEvent& aEvent )
       
  2775     {
       
  2776     TApaSystemEvent* event = ( TApaSystemEvent* )aEvent.EventData();
       
  2777     if( *event == EApaSystemEventSecureShutdown )
       
  2778         {
       
  2779         // When the user is writing a mail while the used memory drive is 
       
  2780         // removed from the phone, the mail editor is closed and the mail is
       
  2781         // not saved.
       
  2782         iForceDeleteDocument = ETrue;
       
  2783         }
       
  2784 
       
  2785     CMsgMailAppUi::HandleSystemEventL( aEvent );
       
  2786     }
       
  2787 
       
  2788 // End of File