emailuis/emailui/src/FreestyleEmailUiAppui.cpp
changeset 0 8466d47a6819
child 1 12c456ceeff2
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  FreestyleEmailUi main application UI control implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // SYSTEM INCLUDE FILES
       
    19 #include "emailtrace.h"
       
    20 #include <avkon.hrh>
       
    21 #include <eikmenup.h>
       
    22 #include <AvkonInternalCRKeys.h>
       
    23 #include <AknDef.h>
       
    24 #include <aknnotewrappers.h>
       
    25 #include <AknUtils.h>
       
    26 #include <aknnavide.h>
       
    27 // <cmail> SF
       
    28 #include <alf/alfcontrolgroup.h>
       
    29 // </cmail>
       
    30 #include <apgcli.h>
       
    31 #include <FreestyleEmailUi.rsg>
       
    32 #include <fsmailserver.rsg>
       
    33 #include <StringLoader.h>
       
    34 //<cmail>
       
    35 #include "CFSMailClient.h"
       
    36 #include "CFSMailBox.h"
       
    37 #include "CFSMailFolder.h"
       
    38 #include "CFSMailMessage.h"
       
    39 #include "CFSMailAddress.h"
       
    40 #include "CFSMailCommon.h"
       
    41 //</cmail>
       
    42 #include <freestyleemailui.mbg>
       
    43 #include <AknQueryDialog.h>
       
    44 #include <AknBidiTextUtils.h>
       
    45 #include <gdi.h>
       
    46 #include <s32file.h>
       
    47 #include <AknInfoPopupNoteController.h>
       
    48 //<cmail>
       
    49 // #include <AGMDATE.H>
       
    50 //</cmail>
       
    51 #include <CPbkContactItem.h>
       
    52 #include <CPbkContactEngine.h>
       
    53 #include <CPbkFieldInfo.h>
       
    54 #include <cntviewbase.h>
       
    55 #include <cntdef.h>
       
    56 #include <CVPbkContactManager.h>
       
    57 #include <CVPbkContactStoreUriArray.h>
       
    58 #include <VPbkContactStoreUris.h>       // VPbkContactStoreUris
       
    59 #include <TVPbkContactStoreUriPtr.h>    // TVPbkContactStoreUriPtr
       
    60 #include <e32uid.h>	// For dynamic library UID
       
    61 // Meeting request
       
    62 #include <MeetingRequestUids.hrh>
       
    63 //<cmail>
       
    64 #include "cesmricalviewer.h"
       
    65 #include "fslayoutmanager.h"
       
    66 //</cmail>
       
    67 #include <etelmm.h>
       
    68 
       
    69 #include "FSEmailBuildFlags.h"
       
    70 
       
    71 #include <CPbkPhoneNumberSelect.h>
       
    72 #include <RPbkViewResourceFile.h>
       
    73 #include <commonphoneparser.h>
       
    74 #include <bautils.h>
       
    75 #include <hlplch.h>
       
    76 #include <DocumentHandler.h>
       
    77 #include <centralrepository.h>
       
    78 #include <cstack.h>
       
    79 #include <akntitle.h>
       
    80 #include <eikspane.h>
       
    81 #include <fbs.h>
       
    82 #include <iaupdate.h>                   // For IAD
       
    83 #include <iaupdateparameters.h>         // For IAD
       
    84 #include <iaupdateresult.h>             // For IAD
       
    85 #include <featmgr.h>                    // For FeatureManager
       
    86 //<cmail>
       
    87 #include <data_caging_path_literals.hrh> // hardcoded paths removal from cmail
       
    88 #include "cfsccontactactionmenu.h"
       
    89 //</cmail>
       
    90 
       
    91 // INTERNAL INCLUDE FILES
       
    92 #include "FreestyleEmailUiContactHandler.h"
       
    93 #include "FreestyleEmailUiAppui.h"
       
    94 #include "FreestyleEmailUi.hrh"
       
    95 #include "FreestyleEmailUiLauncherGrid.h"
       
    96 #include "FreestyleEmailUiLayoutHandler.h"
       
    97 #include "FreestyleEmailUiMailViewerVisualiser.h"
       
    98 #include "FreestyleEmailUiMailListControl.h"
       
    99 #include "FreestyleEmailUiMailListModel.h"
       
   100 #include "FreestyleEmailUiMailListVisualiser.h"
       
   101 #include "FreestyleEmailUiTextureManager.h"
       
   102 #include "FreestyleEmailUiMsgDetailsVisualiser.h"
       
   103 #include "FreestyleEmailUiFolderListVisualiser.h"
       
   104 #include "ncsconstants.h"
       
   105 #include "ncscomposeview.h"
       
   106 #include "FreestyleEmailUiAttachmentsListModel.h"
       
   107 #include "FreestyleEmailUiAttachmentsListVisualiser.h"
       
   108 #include "FreestyleEmailUiAttachmentsListControl.h"
       
   109 #include "FreestyleEmailCenRepHandler.h"
       
   110 #include "FreestyleEmailUiSettingsListView.h"
       
   111 #include "FreestyleEmailUiGlobalSettingsListView.h"
       
   112 #include "FreestyleEmailUiDownloadManagerModel.h"
       
   113 #include "FreestyleEmailUiDownloadManagerVisualiser.h"
       
   114 #include "FreestyleEmailUiDownloadManagerControl.h"
       
   115 #include "FreestyleEmailUiSendAttachmentsListModel.h"
       
   116 #include "FreestyleEmailUiSendAttachmentsListVisualiser.h"
       
   117 #include "FreestyleEmailUiSearchListVisualiser.h"
       
   118 #include "FreestyleEmailUiStatusIndicator.h"
       
   119 #include "FreestyleEmailUiHtmlViewerView.h"
       
   120 #include "FreestyleEmailDownloadInformationMediator.h"
       
   121 #include "FreestyleEmailUiUtilities.h"
       
   122 #include "FreestyleEmailUiShortcutBinding.h"
       
   123 #include "FSDelayedLoader.h"
       
   124 #include "FreestyleEmailUiWizardObserver.h"
       
   125 #include "FSEmail.pan"
       
   126 #include "ceuiexitguardian.h"
       
   127 
       
   128 #include "FreestyleEmailUiNaviPaneControl2MailViewer.h"
       
   129 
       
   130 // CONSTANT VALUES
       
   131 //<cmail> //hard coded paths removed
       
   132 _LIT( KETelCallEngPhCltResourceFile, "PhoneClient.rsc" );
       
   133 //</cmail>
       
   134 _LIT( KMsgReaderFsDll,"freestylemessagescanner.dll"); // DLL provided by msg reader.
       
   135 _LIT( KPhoneModuleName, "Phonetsy.tsy");
       
   136 _LIT( KPhoneName, "DefaultPhone");
       
   137 // Message editor resources
       
   138 _LIT( KMsgEditorAppUiResourceFileName, "z:msgeditorappui.rsc" );
       
   139 // FSMailServer resources
       
   140 _LIT( KFSMailServerResourceFileName, "z:fsmailserver.rsc" );
       
   141 
       
   142 // 6 seconds
       
   143 const TTimeIntervalMicroSeconds32 KIdleTimeInterval = 6000000;
       
   144 
       
   145 static TBool g_ApplicationExitOnGoing = EFalse;
       
   146 
       
   147 TInt DelayedViewLoaderCallBackL( TAny* aObject )
       
   148     {
       
   149     return static_cast<CFreestyleEmailUiAppUi*>
       
   150     	( aObject )->ViewLoadIdleCallbackFunctionL();
       
   151     }
       
   152 
       
   153 const TUint KConnectionStatusIconRotationInterval = 100;
       
   154 const TInt KConnectionStatusIconRotationAmount = 18;
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // C++ constructor.
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 CFreestyleEmailUiAppUi::CFreestyleEmailUiAppUi( CAlfEnv& aEnv )
       
   161     : CAknViewAppUi(),
       
   162     iIsForeground( EFalse ), // init foreground flag to "not on foreground"
       
   163     iIsCaptured( EFalse ), // init "end key captured" to false
       
   164     iAutomatedMailBoxOnline( EFalse ),
       
   165     iMsgReaderIsSupported( KErrGeneral ),
       
   166     iSwitchingToBackground( EFalse )
       
   167     {
       
   168     FUNC_LOG;
       
   169     iEnv = &aEnv;
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // ConstructL is called by the application framework
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CFreestyleEmailUiAppUi::ConstructL()
       
   177     {
       
   178     FUNC_LOG;
       
   179 
       
   180     // for debug builds create log file directory automatically
       
   181 #ifdef _DEBUG
       
   182     _LIT( KDebugLogDir, "c:\\logs\\FreestyleEmailUi\\" );
       
   183     BaflUtils::EnsurePathExistsL( iEikonEnv->FsSession(), KDebugLogDir );
       
   184 #endif
       
   185 
       
   186     // Add message editor resources (needed for ENote fetch)
       
   187     TParse parse;
       
   188     parse.Set( KMsgEditorAppUiResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
   189     TFileName fileName( parse.FullName() );
       
   190     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName );
       
   191     iMsgEditorResourceOffset = iEikonEnv->AddResourceFileL( fileName );
       
   192     // Add FSMailServer resources
       
   193     parse.Set( KFSMailServerResourceFileName, &KDC_APP_RESOURCE_DIR, NULL );
       
   194     fileName = parse.FullName();
       
   195     BaflUtils::NearestLanguageFile( iCoeEnv->FsSession(), fileName );
       
   196     iFSMailServerResourceOffset = iEikonEnv->AddResourceFileL( fileName );
       
   197     
       
   198 	// flag indicating whether we are in AppUi::ConstructL
       
   199 	// workaround for compose view loadbackgroundcontext sending skin changed events
       
   200 	// and causing texture manager to be reconstructed many times
       
   201 	iConstructComplete = EFalse;
       
   202 
       
   203 	// <cmail>
       
   204 	iIADUpdateCompleted = !FeatureManager::FeatureSupported( KFeatureIdIAUpdate );
       
   205 	// </cmail>
       
   206 
       
   207     // Create the 'Back' stack
       
   208     iNavigationHistory = new (ELeave) CStack<CFsEmailUiViewBase, EFalse>();
       
   209 
       
   210     // Enable Avkon skins.
       
   211     BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible );
       
   212     // Create instance for Central repository handler
       
   213     iCRHandler = CFSEmailCRHandler::InstanceL();
       
   214 
       
   215     // Initialize the flip state and the observer for listening to the flip
       
   216     // state changed events. The initial state will be reported in construction
       
   217     iPropertySubscriber =
       
   218         CFreestyleEmailUiPropertySubscriber::NewL( KPSUidHWRM, KHWRMFlipStatus, *this );
       
   219     
       
   220     // Create Document Handler instance
       
   221     iDocumentHandler = CDocumentHandler::NewL();
       
   222     iFileHandleShutter = CFsEmailFileHandleShutter::NewL(*iDocumentHandler);
       
   223 
       
   224     CAlfDisplay& disp = iEnv->NewDisplayL( ClientRect(), CAlfEnv::ENewDisplayAsCoeControl ); // aAppUi->
       
   225 
       
   226  	// SET to use skin bakcground if needed
       
   227     disp.SetClearBackgroundL(CAlfDisplay::EClearWithSkinBackground);
       
   228 
       
   229     // Create and load fs generci layout
       
   230     //<cmail>
       
   231     //iLayoutManager = new( ELeave )CFsLayoutManager();
       
   232     //iLayoutManager->LoadLayoutL();
       
   233     //<cmail>
       
   234 
       
   235     // Set up layouthandler
       
   236     iLayoutHandler = CFSEmailUiLayoutHandler::NewL( *iEnv );
       
   237 	iLayoutHandler->ScreenResolutionChanged();
       
   238     
       
   239     // Create mail client, list mailboxes
       
   240     iMailClient = CFSMailClient::NewL();
       
   241 
       
   242 	// Connect to messaging server
       
   243 	iMsvSession = CMsvSession::OpenSyncL( *this );
       
   244 
       
   245  	// Create freestyle texture manager
       
   246 	iFsTextureManager = CFreestyleEmailUiTextureManager::NewL( *iEnv, this );
       
   247 	CFsDelayedLoader::InstanceL()->Start();
       
   248 
       
   249 	// New mailbox query async callback
       
   250  	iNewBoxQueryAsyncCallback = new (ELeave) CAsyncCallBack( CActive::EPriorityStandard );
       
   251 	iNewBoxQueryAsyncCallback->Set( TCallBack( DisplayCreateQueryL, this ) ); 
       
   252 
       
   253     iActionMenuHandler = CFSEmailUiActionMenu::NewL( this );
       
   254 
       
   255   	// Create download info mediator
       
   256   	iDwnldMediator = CFSEmailDownloadInfoMediator::NewL( *iMailClient );
       
   257 
       
   258     // Create a control groups
       
   259     iGridControlGroup = &iEnv->NewControlGroupL( KGridDisplayGroup );
       
   260 
       
   261 	// Create main UI grid and append it to control group
       
   262     TInt gridRows = iLayoutHandler->GridRowsInThisResolution();
       
   263 	TInt gridColumns = iLayoutHandler->GridColumnsInThisResolution();
       
   264     iMainUiGrid = CFSEmailUiLauncherGrid::NewL(*iEnv, this );
       
   265     iMainUiGridVisualiser = CFSEmailUiLauncherGridVisualiser::NewL( *iEnv, iMainUiGrid, this,
       
   266     	*iGridControlGroup, gridRows, gridColumns );
       
   267    	iMainUiGrid->SetVisualiserL( iMainUiGridVisualiser );
       
   268     iGridControlGroup->AppendL(iMainUiGrid);
       
   269     //disp.iVisibleAreaObservers.AppendL(*iMainUiGridVisualiser); // Commented out as (hopefully) unnecessary, can't be accessed directly in Alfred anyway
       
   270     AddViewL( iMainUiGridVisualiser );
       
   271 
       
   272     // Create control groups
       
   273 	iMailListControlGroup = &iEnv->NewControlGroupL( KMailListDisplayGroup );
       
   274 	iEmailViewerControlGroup = &iEnv->NewControlGroupL( KEmailViewerDisplayGroup );
       
   275 	iFolderListControlGroup = &iEnv->NewControlGroupL( KFolderListDisplayGroup );
       
   276 	iSettingsListControlGroup = &iEnv->NewControlGroupL( KSettingsListDisplayGroup );
       
   277 	iComposerControlGroup = &iEnv->NewControlGroupL( KEmailEditorDisplayGroup );
       
   278 	iStatusIndicatorControlGroup = &iEnv->NewControlGroupL( KStatusIndicatorDisplayGroup );
       
   279 
       
   280 	// Create settings list views
       
   281 	CFsEmailSettingsListView* settingsListView = CFsEmailSettingsListView::NewLC( *iMailClient, this, *iSettingsListControlGroup );
       
   282 	AddViewL( settingsListView );
       
   283 	CleanupStack::Pop( settingsListView );
       
   284 	CFsEmailUiGlobalSettingsListView* globalSettingsView = CFsEmailUiGlobalSettingsListView::NewLC( this, *iSettingsListControlGroup );
       
   285 	AddViewL( globalSettingsView );
       
   286 	CleanupStack::Pop( globalSettingsView );
       
   287 
       
   288 	// Create and start view load in idle. Loads rest of the views when in idle.
       
   289   	iViewLoadIdle = CIdle::NewL( CActive::EPriorityIdle );
       
   290 	iViewLoadIdleCallback = new (ELeave) TCallBack( DelayedViewLoaderCallBackL, this );
       
   291   	iViewLoadIdle->Start( *iViewLoadIdleCallback );
       
   292 
       
   293 	// Create mail viewer
       
   294 	iViewerVisualiser = CFSEmailUiMailViewerVisualiser::NewL( *iEnv, *this, *iEmailViewerControlGroup );
       
   295 	AddViewL( iViewerVisualiser );
       
   296 	// Create html viewer
       
   297 	iHtmlViewerControlGroup = &iEnv->NewControlGroupL( KHtmlViewerDisplayGroup );
       
   298     iHtmlViewerView = CFsEmailUiHtmlViewerView::NewL( *iEnv, *this, *iHtmlViewerControlGroup );
       
   299     AddViewL( iHtmlViewerView );
       
   300 
       
   301 	// Create mail list
       
   302     iMailListVisualiser = CFSEmailUiMailListVisualiser::NewL(*iEnv, this, *iMailListControlGroup );
       
   303  	AddViewL( iMailListVisualiser );
       
   304 
       
   305   	// Create mail composing view
       
   306 	iComposeView = CNcsComposeView::NewL( *iMailClient, *iEnv, this,
       
   307 						*iComposerControlGroup, *iMsvSession );
       
   308 	AddViewL( iComposeView );
       
   309 
       
   310 	// Create folder list view
       
   311 	iFolderListVisualiser = CFSEmailUiFolderListVisualiser::NewL( *iEnv, *iFolderListControlGroup, *this );
       
   312 	AddViewL( iFolderListVisualiser );
       
   313 
       
   314 	// Create status indicator
       
   315 	iStatusIndicator = CFSEmailUiStatusIndicator::NewL( *iEnv,
       
   316                                                  		*iStatusIndicatorControlGroup,
       
   317                                                  		this );
       
   318 
       
   319 
       
   320  	iCurrentActiveView = iMainUiGridVisualiser;
       
   321     SetDefaultViewL( *iMainUiGridVisualiser );
       
   322 
       
   323 
       
   324     // add this class to listen mail events, e.g. TFSEventNewMailbox
       
   325     iMailClient->AddObserverL( *this );
       
   326 
       
   327     iShortcutBinder = CFSEmailUiShortcutBinding::NewL();
       
   328 
       
   329     // Try to ensure that FSMailServer is running before creating the mailbox
       
   330     TFsEmailUiUtility::EnsureFsMailServerIsRunning( iEikonEnv->WsSession() );
       
   331 
       
   332     // If we have no mailboxes yet start a setup wizard. Else, if this app has been launched
       
   333 	// by a setup wizard then handle the mailbox data in central repository
       
   334 	iWizardObserver = CFSEmailUiWizardObserver::NewL( this, iMainUiGridVisualiser );
       
   335 	iConstructComplete = ETrue;
       
   336 
       
   337     // this includes a wait note where code running will be pending
       
   338     // until a certain callback event is received
       
   339     // -> thus keep this last in this method!
       
   340     iWizardObserver->DoWizardStartupActionsL();
       
   341 
       
   342     iExitGuardian = CEUiExitGuardian::NewL( *this );
       
   343     
       
   344     iConnectionStatusVisible = ETrue;
       
   345     // Create custom statuspane indicators object, which shows priority and followup flags
       
   346     CreateStatusPaneIndicatorsL();
       
   347     iConnectionStatusIconAnimTimer = CFSEmailUiGenericTimer::NewL(this, CActive::EPriorityLow);
       
   348     iFocusTimer = CPeriodic::New(CActive::EPriorityIdle);
       
   349    	}
       
   350 
       
   351 // Functions loads some views as delayed to reduce startup time
       
   352 TInt CFreestyleEmailUiAppUi::ViewLoadIdleCallbackFunctionL()
       
   353 	{
       
   354     FUNC_LOG;
       
   355     // Load the phone resources into this process
       
   356 	//<cmail> hard coded paths removal
       
   357 	TFileName phCltResPath(KDC_RESOURCE_FILES_DIR);
       
   358     phCltResPath.Append(KETelCallEngPhCltResourceFile);
       
   359     //</cmail>
       
   360     BaflUtils::NearestLanguageFile( iEikonEnv->FsSession(), phCltResPath );
       
   361     iPhCltResHandle = CCoeEnv::Static()->AddResourceFileL( phCltResPath );
       
   362 
       
   363 	// Create attachment list visualiser and control
       
   364 	iAttachmentControlGroup = &iEnv->NewControlGroupL( KAttachmentManagerDisplayGroup );
       
   365 	iAttachmentListVisualiser = CFSEmailUiAttachmentsListVisualiser::NewL( *iEnv, this, *iAttachmentControlGroup );
       
   366 	AddViewL( iAttachmentListVisualiser );
       
   367 
       
   368     // Download manager removed.
       
   369 
       
   370 	// Create search list view
       
   371 	iSearchResultControlGroup = &iEnv->NewControlGroupL( KSearchResultDisplayGroup );
       
   372 	iSearchListVisualiser = CFSEmailUiSearchListVisualiser::NewL( *iEnv, this, *iSearchResultControlGroup );
       
   373 	AddViewL( iSearchListVisualiser );
       
   374 
       
   375 	// Create message details view
       
   376 	iMsgDetailsControlGroup = &iEnv->NewControlGroupL( KMsgDetailsViewerControlGroup );
       
   377 	iMsgDetailsVisualiser = CFSEmailUiMsgDetailsVisualiser::NewL( *iEnv, *iMsgDetailsControlGroup, *this );
       
   378 	AddViewL( iMsgDetailsVisualiser );
       
   379 
       
   380     // Check updates from IAD, continue UI launching even if something fails there
       
   381     TRAP_IGNORE( CheckUpdatesL() );
       
   382 
       
   383     // Make sure there's no temp files left from previous sessions
       
   384     TFsEmailUiUtility::EraseTempDir();
       
   385 
       
   386 	return KErrNone;
       
   387 	}
       
   388 
       
   389 CFreestyleEmailUiAppUi::~CFreestyleEmailUiAppUi()
       
   390     {
       
   391     FUNC_LOG;
       
   392     
       
   393     if ( iMsgEditorResourceOffset )
       
   394         {
       
   395         iEikonEnv->DeleteResourceFile( iMsgEditorResourceOffset );
       
   396         }
       
   397     if ( iFSMailServerResourceOffset )
       
   398         {
       
   399         iEikonEnv->DeleteResourceFile( iFSMailServerResourceOffset );
       
   400         }
       
   401     // Make sure we don't leave any temp files
       
   402     TFsEmailUiUtility::EraseTempDir();
       
   403 
       
   404     delete iExitGuardian;
       
   405     delete iUpdateClient;
       
   406     delete iUpdateParameters;
       
   407     delete iNewBoxQueryAsyncCallback;
       
   408     delete iVpkContactManager;
       
   409 	delete iPropertySubscriber;
       
   410 
       
   411     DeleteStatusPaneIndicators();
       
   412     
       
   413 	if ( iAutoSyncMonitor )
       
   414 		{
       
   415 		iAutoSyncMonitor->StopMonitoring();
       
   416 		delete iAutoSyncMonitor;
       
   417 		}
       
   418 
       
   419     if ( iViewLoadIdle )
       
   420         {
       
   421         iViewLoadIdle->Cancel();
       
   422         delete iViewLoadIdle;
       
   423         }
       
   424     if ( iViewLoadIdleCallback )
       
   425         {
       
   426         delete iViewLoadIdleCallback;
       
   427         }
       
   428 
       
   429     CCoeEnv::Static()->DeleteResourceFile( iPhCltResHandle );
       
   430 
       
   431     delete iLayoutHandler;
       
   432     iLayoutHandler = NULL;
       
   433 
       
   434     delete iMsvSession;
       
   435     iMsvSession = NULL;
       
   436 
       
   437     delete iWizardObserver;
       
   438     iWizardObserver = NULL;
       
   439 
       
   440     if ( iCRHandler )
       
   441     	{
       
   442     	// just to make sure:
       
   443     	// clears the two centrep keys that were passed as parameters to plugins
       
   444         iCRHandler->ClearWizardParams();
       
   445     	delete iCRHandler;
       
   446     	iCRHandler = NULL;
       
   447     	}
       
   448 
       
   449     if (iCustomMessageToMessageReader)
       
   450     	{
       
   451     	delete iCustomMessageToMessageReader;
       
   452     	}
       
   453 
       
   454    	delete iActionMenuHandler;
       
   455    	iActionMenuHandler = NULL;
       
   456 
       
   457     delete iShortcutBinder;
       
   458     iShortcutBinder = NULL;
       
   459 
       
   460     delete iDocumentHandler;
       
   461     iDocumentHandler = NULL;
       
   462 
       
   463     delete iFileHandleShutter;
       
   464 
       
   465 	delete iFsTextureManager;
       
   466 	iFsTextureManager = NULL;
       
   467     //<cmail> layout manager deltion removed </cmail>
       
   468     if ( iFeatureManagerInitialized )
       
   469         {
       
   470         // We can safely call UnInitializeLib as we have really intialized it!
       
   471         FeatureManager::UnInitializeLib();  // Decreases ref.count
       
   472         iFeatureManagerInitialized = EFalse;
       
   473         }
       
   474 
       
   475     delete iNavigationHistory;
       
   476     iNavigationHistory = NULL;
       
   477 
       
   478 	// CAlfEnv creation and deletion was moved from here to Document class
       
   479 	// because of cross-dependency between alf and S60 view architecture ->
       
   480 	// AlfEnv must still exist when AppUI is destructed.
       
   481 	// However, CAlfDisplay's destructor has a dependency to AppUI. That's
       
   482 	// why display must be deleted explicitly here, when AppUI still exists.
       
   483 	// Otherwise "delete env" in CDocument panics.
       
   484     CAlfDisplay *disp = &iEnv->PrimaryDisplay();
       
   485  	if ( disp )
       
   486  		{
       
   487  		delete disp;
       
   488  		}
       
   489 
       
   490  	TFsEmailUiUtility::DeleteStaticData();
       
   491 
       
   492     // destroys the Download Information mediator
       
   493     // Destruction must be done here as other Tls data depends on it.
       
   494     CFSEmailDownloadInfoMediator::Destroy();
       
   495     
       
   496     delete iNaviDecorator2MailViewer;
       
   497     
       
   498     delete iConnectionStatusIconAnimTimer;
       
   499     
       
   500     if (iFocusTimer)
       
   501     	{
       
   502 		CancelFocusRemovalTimer();
       
   503 		delete iFocusTimer;
       
   504     	}
       
   505     
       
   506     }
       
   507 
       
   508 
       
   509 void CFreestyleEmailUiAppUi::EnterFsEmailViewL( TUid aViewId )
       
   510     {
       
   511     FUNC_LOG;
       
   512     if ( AppUiExitOngoing() )
       
   513         {
       
   514         return;
       
   515         }
       
   516 
       
   517     iPreviousActiveView = iCurrentActiveView;
       
   518 
       
   519     // First check if the view to be activated is the current view. In that case,
       
   520     // the view history stack is not altered.
       
   521     if ( iCurrentActiveView->Id() == aViewId )
       
   522         {
       
   523         ActivateLocalViewL( aViewId );
       
   524         }
       
   525 
       
   526     // Then check if the view is in the history stack. In that case, we don't
       
   527     // actually navigate forward but backward.
       
   528     else if ( IsViewInHistoryStack( aViewId ) )
       
   529         {
       
   530         ReturnToViewL( aViewId );
       
   531         }
       
   532 
       
   533     // Otherwise this is just the normal case of entering some new view
       
   534     else
       
   535         {
       
   536     	iNavigationHistory->PushL( iCurrentActiveView );
       
   537         ActivateLocalViewL( aViewId );
       
   538         iCurrentActiveView = static_cast<CFsEmailUiViewBase*>( View(aViewId) );
       
   539         }
       
   540     }
       
   541 
       
   542 void CFreestyleEmailUiAppUi::EnterFsEmailViewL( TUid aViewId, TUid aCustomMessageId, const TDesC8& aCustomMessage )
       
   543     {
       
   544     FUNC_LOG;
       
   545     if ( AppUiExitOngoing() )
       
   546         {
       
   547         return;
       
   548         }
       
   549 
       
   550     iPreviousActiveView = iCurrentActiveView;
       
   551 
       
   552     // First check if the view to be activated is the current view. In that case,
       
   553     // the view history stack is not altered.
       
   554     if ( iCurrentActiveView->Id() == aViewId )
       
   555         {
       
   556         ActivateLocalViewL( aViewId, aCustomMessageId, aCustomMessage );
       
   557         }
       
   558 
       
   559     // Then check if the view is in the history stack. In that case, we don't
       
   560     // actually navigate forward but backward.
       
   561     else if ( IsViewInHistoryStack( aViewId ) )
       
   562         {
       
   563         ReturnToViewL( aViewId, aCustomMessageId, aCustomMessage );
       
   564         }
       
   565 
       
   566     // Otherwise this is just the normal case of entering some new view
       
   567     else
       
   568         {
       
   569     	iNavigationHistory->PushL( iCurrentActiveView );
       
   570         ActivateLocalViewL( aViewId, aCustomMessageId, aCustomMessage );
       
   571         iCurrentActiveView = static_cast<CFsEmailUiViewBase*>( View(aViewId) );
       
   572         }
       
   573     }
       
   574 
       
   575 void CFreestyleEmailUiAppUi::EnterPluginSettingsViewL( TUid aViewId, TUid aCustomMessageId, const TDesC8& aCustomMessage )
       
   576     {
       
   577     FUNC_LOG;
       
   578     // Plugin settings views need to be handled as special cases, as returning from them does not happen with our
       
   579     // ReturnToPreviousViewL() and they are not iherited from our BaseView.
       
   580     iNavigationHistory->PushL( iCurrentActiveView );
       
   581     ActivateLocalViewL( aViewId, aCustomMessageId, aCustomMessage );
       
   582 	iSettingsViewActive = ETrue;
       
   583 
       
   584 	// Fade out the current view here as it doesn't happen when activating the plugin settings view
       
   585 	iCurrentActiveView->DoTransition( ETrue );
       
   586     }
       
   587 
       
   588 void CFreestyleEmailUiAppUi::ReturnFromPluginSettingsView()
       
   589     {
       
   590     FUNC_LOG;
       
   591     // Check if we just returned from a plugin settings view. In that case, the current active view
       
   592     // and view history must be updated here (because RetrunToPreviousViewL() has not been used).
       
   593     if ( iSettingsViewActive ) 
       
   594         {
       
   595         iSettingsViewActive = EFalse;
       
   596         
       
   597         // Set the iCurrentActiveView pointer
       
   598         if ( iNavigationHistory->IsEmpty() )
       
   599             {
       
   600             // Activate grid view if the view history stack is empty. This happens only
       
   601             // if something has gone wrong.
       
   602             iCurrentActiveView = static_cast<CFsEmailUiViewBase*>( View(AppGridId) );
       
   603             }
       
   604         else
       
   605             {
       
   606             iCurrentActiveView = iNavigationHistory->Pop();
       
   607             }
       
   608         }
       
   609     }
       
   610 
       
   611 void CFreestyleEmailUiAppUi::ViewActivatedExternallyL( TUid aViewId )
       
   612     {
       
   613     FUNC_LOG;
       
   614     if ( AppUiExitOngoing() )
       
   615         {
       
   616         return;
       
   617         }
       
   618 
       
   619     // Do nothing if the externally activated view was already active
       
   620     if ( iCurrentActiveView->Id() != aViewId )
       
   621         {
       
   622         iPreviousActiveView = iCurrentActiveView;
       
   623 
       
   624         // Check if the view is in the history stack. In that case, we don't
       
   625         // actually navigate forward but backward.
       
   626         if ( IsViewInHistoryStack( aViewId ) )
       
   627             {
       
   628             // Remove views from the stack until the desired one is found or the stack becomes empty
       
   629             do
       
   630                 {
       
   631                 iCurrentActiveView = iNavigationHistory->Pop();
       
   632                 }
       
   633             while ( !iNavigationHistory->IsEmpty() && iCurrentActiveView->Id() != aViewId );
       
   634             }
       
   635 
       
   636         // Otherwise this is just the normal case of entering some new view
       
   637         else
       
   638             {
       
   639             iNavigationHistory->PushL( iCurrentActiveView );
       
   640             iCurrentActiveView = static_cast<CFsEmailUiViewBase*>( View(aViewId) );
       
   641             }
       
   642         }
       
   643 
       
   644     }
       
   645 
       
   646 void CFreestyleEmailUiAppUi::SetSwitchingToBackground( TBool aValue )
       
   647     {
       
   648     FUNC_LOG;
       
   649     iSwitchingToBackground = aValue;
       
   650     }
       
   651 
       
   652 TBool CFreestyleEmailUiAppUi::SwitchingToBackground() const
       
   653     {
       
   654     FUNC_LOG;
       
   655     return iSwitchingToBackground;
       
   656     }
       
   657 
       
   658 void CFreestyleEmailUiAppUi::ReturnFromHtmlViewerL( TBool aMessageWasDeleted )
       
   659 	{
       
   660     FUNC_LOG;
       
   661 	if ( aMessageWasDeleted )
       
   662 	    {
       
   663         // Message deleted, remove mail viewer from the stack
       
   664         // => view returns directly mail list (or any other view where the viewer was started from)
       
   665         
       
   666 		TMailListActivationData tmp;
       
   667 		tmp.iRequestRefresh = ETrue;
       
   668 		const TPckgBuf<TMailListActivationData> pkgOut( tmp );
       
   669 		ReturnToPreviousViewL(pkgOut);
       
   670 	    }
       
   671 	else
       
   672 	    {
       
   673        	ReturnToPreviousViewL();
       
   674 	    }
       
   675 	}
       
   676 
       
   677 TUid CFreestyleEmailUiAppUi::ReturnToPreviousViewL( const TDesC8& aCustomMessage /*= KNullDesC8*/ )
       
   678     {
       
   679     FUNC_LOG;
       
   680     iPreviousActiveView = iCurrentActiveView;  
       
   681     CFsDelayedLoader::InstanceL()->GetContactHandlerL()->Reset();
       
   682     // Set the iCurrentActiveView pointer
       
   683     if ( iNavigationHistory->IsEmpty() )
       
   684         {
       
   685         // Activate grid view if the view history stack is empty. This happens only
       
   686         // if something has gone wrong.
       
   687         iCurrentActiveView = static_cast<CFsEmailUiViewBase*>( View(AppGridId) );
       
   688         }
       
   689     else
       
   690         {
       
   691         iCurrentActiveView = iNavigationHistory->Pop();
       
   692         }
       
   693 
       
   694     TUid viewId = iCurrentActiveView->Id();
       
   695 
       
   696     // Activate the proper view
       
   697 	if ( viewId == AppGridId )
       
   698 		{
       
   699 		ActivateLocalViewL( AppGridId );
       
   700 		}
       
   701 	else if ( viewId == MailListId )
       
   702 		{
       
   703 		if ( aCustomMessage.Length() )
       
   704 		    {
       
   705 		    ActivateLocalViewL( MailListId, KStartListReturnToPreviousFolder, aCustomMessage );
       
   706 		    }
       
   707 		else
       
   708 		    {
       
   709     		const TPckgBuf<TMailListActivationData> pkgOut;
       
   710     		ActivateLocalViewL( MailListId, KStartListReturnToPreviousFolder, pkgOut );
       
   711 		    }
       
   712 		}
       
   713 	else if ( viewId == SearchListViewId )
       
   714 		{
       
   715 		TSearchListActivationData tmp;
       
   716 		tmp.iMailBoxId = GetActiveMailbox()->GetId();
       
   717 		const TPckgBuf<TSearchListActivationData> pkgOut( tmp );
       
   718 		ActivateLocalViewL( SearchListViewId, KStartWithPreviousResults, pkgOut );
       
   719 		}
       
   720 	else if ( viewId == MailViewerId )
       
   721 		{
       
   722 		const TPckgBuf<TMsgViewerActivationData> pkgOut;
       
   723 		ActivateLocalViewL( MailViewerId, KStartViewerReturnToPreviousMsg,  pkgOut);
       
   724 		}
       
   725 	else if ( viewId == HtmlViewerId )
       
   726 	    {
       
   727 	    // launch html viewer
       
   728 		const TPckgBuf<THtmlViewerActivationData> pkgOut;
       
   729 		ActivateLocalViewL( HtmlViewerId, KHtmlViewerReturnToPrevious, pkgOut );
       
   730 	    }
       
   731 	else if ( viewId == MailEditorId )
       
   732 		{
       
   733 		ActivateLocalViewL( MailEditorId, TUid::Uid(KEditorCmdReturnToPrevious), aCustomMessage );
       
   734 		}
       
   735 	else if ( viewId == MsgDetailsViewId )
       
   736 		{
       
   737 		ActivateLocalViewL( MsgDetailsViewId, KStartMsgDetailsReturnToPrevious, aCustomMessage );
       
   738 		}
       
   739 	else if ( viewId == SettingsViewId )
       
   740 	    {
       
   741 	    ActivateLocalViewL( SettingsViewId, TUid::Uid(KMailSettingsReturnToPrevious), aCustomMessage );
       
   742 	    }
       
   743 	else
       
   744 		{
       
   745 		// Generic case where the view does not need any startup parameters
       
   746 		ActivateLocalViewL( viewId );
       
   747 		}
       
   748 
       
   749 	return viewId;
       
   750     }
       
   751 
       
   752 void CFreestyleEmailUiAppUi::EraseViewHistory()
       
   753     {
       
   754     FUNC_LOG;
       
   755     iNavigationHistory->Clear();
       
   756     }
       
   757 
       
   758 TBool CFreestyleEmailUiAppUi::IsViewInHistoryStack( TUid aViewId ) const
       
   759     {
       
   760     FUNC_LOG;
       
   761     for ( TInt i=0 ; i<iNavigationHistory->Count() ; ++i )
       
   762         {
       
   763         if ( (*iNavigationHistory)[i]->Id() == aViewId )
       
   764             {
       
   765             return ETrue;
       
   766             }
       
   767         }
       
   768     return EFalse;
       
   769     }
       
   770 
       
   771 void CFreestyleEmailUiAppUi::ReturnToViewL( TUid aViewId,
       
   772                                             TUid aCustomMessageId /*= TUid::Null()*/,
       
   773                                             const TDesC8& aCustomMessage /*= KNullDesC8*/ )
       
   774     {
       
   775     FUNC_LOG;
       
   776     iPreviousActiveView = iCurrentActiveView;
       
   777 
       
   778     // Remove views from the stack until the desired one is found or the stack becomes empty
       
   779     iCurrentActiveView = iNavigationHistory->Pop();
       
   780     while ( !iNavigationHistory->IsEmpty() && iCurrentActiveView->Id() != aViewId )
       
   781         {
       
   782         iCurrentActiveView = iNavigationHistory->Pop();
       
   783         }
       
   784 
       
   785     // Return to grid in case the desired view was not found
       
   786     if ( iCurrentActiveView->Id() != aViewId )
       
   787         {
       
   788         iCurrentActiveView = static_cast<CFsEmailUiViewBase*>( View(AppGridId) );
       
   789         }
       
   790 
       
   791     if ( aCustomMessageId != TUid::Null() || aCustomMessage.Length() )
       
   792         {
       
   793         ActivateLocalViewL( iCurrentActiveView->Id(), aCustomMessageId, aCustomMessage );
       
   794         }
       
   795     else
       
   796         {
       
   797         ActivateLocalViewL( iCurrentActiveView->Id() );
       
   798         }
       
   799     }
       
   800 
       
   801 void CFreestyleEmailUiAppUi::ShowFolderListInPopupL(
       
   802         const TFSMailMsgId aFolderId,
       
   803         MFSEmailUiFolderListCallback* aCallback,
       
   804         MFsControlButtonInterface* aButton )
       
   805     {
       
   806     FUNC_LOG;
       
   807     iFolderListVisualiser->ShowInPopupL( aFolderId, aCallback, aButton );
       
   808 
       
   809     iCurrentActiveView->ControlGroup().SetAcceptInput( EFalse );
       
   810     iEnv->Send( TAlfGroupCommand(*iFolderListControlGroup, EAlfOpShow, &Display()), 0 );
       
   811     iFolderListControlGroup->SetAcceptInput( ETrue );
       
   812     }
       
   813 
       
   814 void CFreestyleEmailUiAppUi::ShowSortListInPopupL(
       
   815         const TFSMailSortField aCurrentSortOrder,
       
   816         const TFSFolderType aFolderType,
       
   817         MFSEmailUiSortListCallback* aCallback,
       
   818         MFsControlButtonInterface* aButton )
       
   819     {
       
   820     FUNC_LOG;
       
   821     iFolderListVisualiser->ShowSortListPopupL( aCurrentSortOrder, aFolderType, aCallback, aButton );
       
   822 
       
   823     iCurrentActiveView->ControlGroup().SetAcceptInput( EFalse );
       
   824     iEnv->Send( TAlfGroupCommand(*iFolderListControlGroup, EAlfOpShow, &Display()), 0 );
       
   825     iFolderListControlGroup->SetAcceptInput( ETrue );
       
   826     }
       
   827 
       
   828 void CFreestyleEmailUiAppUi::FolderPopupClosed()
       
   829     {
       
   830     FUNC_LOG;
       
   831     iFolderListControlGroup->SetAcceptInput( EFalse );
       
   832     iEnv->Send( TAlfGroupCommand(*iFolderListControlGroup, EAlfOpHide, &Display()), 0 );
       
   833     iCurrentActiveView->ControlGroup().SetAcceptInput( ETrue );
       
   834     }
       
   835 
       
   836 void CFreestyleEmailUiAppUi::ProcessCommandL( TInt aCommand )
       
   837     {
       
   838     FUNC_LOG;
       
   839     
       
   840     // For a reason unknown compose view propagates a leave when the options
       
   841     // menu open -command is sent to it during the time when it has started
       
   842     // the view deactivation but not yet completed that. It causes unnecessay
       
   843     // leave notes in a complete normal use cases in the emulator. To remove 
       
   844     // the notes but keep the regression risk at minimum (ie. not do any major
       
   845     // refactoring) trap the leave here. Propagate other leaves normally.
       
   846     TRAPD( err, CAknViewAppUi::ProcessCommandL( aCommand ) );
       
   847     
       
   848     if ( err != KErrNcsComposeViewNotReady )
       
   849         {
       
   850         User::LeaveIfError( err );
       
   851         }
       
   852     }
       
   853 
       
   854 void CFreestyleEmailUiAppUi::HandleCommandL( TInt aCommand )
       
   855     {
       
   856     FUNC_LOG;
       
   857     switch(aCommand)
       
   858         {
       
   859         case EEikCmdExit:
       
   860         case EAknSoftkeyExit:
       
   861         case EFsEmailUiCmdExit:
       
   862             Exit();
       
   863             break;
       
   864         default:
       
   865             break;
       
   866         }
       
   867     }
       
   868 
       
   869 void CFreestyleEmailUiAppUi::Exit()
       
   870     {
       
   871     FUNC_LOG;
       
   872     g_ApplicationExitOnGoing = ETrue;
       
   873     if ( iExitGuardian->ExitApplication() == KRequestPending )
       
   874         {
       
   875         SendToBackground();
       
   876         }
       
   877     }
       
   878 
       
   879 void CFreestyleEmailUiAppUi::ExitNow()
       
   880 	{
       
   881 		FUNC_LOG;
       
   882 
       
   883 		//<cmail>
       
   884     if ( iCurrentActiveView )
       
   885         {
       
   886         // Let active view prepare itself for exit. This may be needed
       
   887         // if view's destructor is too late to do certain cleanup.
       
   888         TRAP_IGNORE( iCurrentActiveView->PrepareExitL() );
       
   889         }
       
   890 //</cmail>
       
   891     // Closing of mail client (and also unsubscribing of mailbox events)
       
   892     // was moved from destructor to here to avoid panic in case of pressing
       
   893     // end key during attachment download. Panic arises because of
       
   894     // MailClient->Close makes plugins to cancel all requests, which means
       
   895     // also notifying observers -> UI gets DownloadStatusChangedL call and
       
   896     // tries to e.g. update layout. However, CEikonEnv is needed there but it
       
   897     // was already destoyed in this phase. Here in Exit() MailClient->Close
       
   898     // can finish safely before the environment gets destroyed.
       
   899 
       
   900     // First, prepare viewer, search list and composer for exit, destroys mailbox object before
       
   901     // This exit preparation should be moved to base class in the future.
       
   902     if ( iMsgDetailsVisualiser ) 
       
   903         {
       
   904         iMsgDetailsVisualiser->PrepareForExit();
       
   905         }
       
   906     if ( iMailListVisualiser )
       
   907         {
       
   908         iMailListVisualiser->PrepareForExit();
       
   909         }
       
   910     if ( iViewerVisualiser )
       
   911         {
       
   912         iViewerVisualiser->PrepareForExit();
       
   913         }
       
   914     if ( iHtmlViewerView )
       
   915         {
       
   916         iHtmlViewerView->PrepareForExit();
       
   917         }
       
   918     if ( iSearchListVisualiser )
       
   919         {
       
   920         iSearchListVisualiser->PrepareForExit();
       
   921         }
       
   922     if ( iComposeView )
       
   923         {
       
   924         iComposeView->PrepareForExit();
       
   925         //<cmail>
       
   926         //if compose view is not prepared, it will exit app by itself
       
   927         if(!iComposeView->IsPreparedForExit())
       
   928             {
       
   929             return;
       
   930             }
       
   931         //</cmail>
       
   932         }
       
   933 
       
   934     delete iMRViewer;
       
   935     iMRViewer = NULL;
       
   936 
       
   937     // Unsubscribe active mailbox events from list visualiser
       
   938     if ( iActiveMailbox )
       
   939         {
       
   940         iMailClient->UnsubscribeMailboxEvents( iActiveMailboxId, *this );
       
   941         delete iActiveMailbox;
       
   942         iActiveMailbox = NULL;
       
   943         }
       
   944 
       
   945     // Unsubscribe events from mailboxes from appui
       
   946     for ( TInt i = 0; i < iSubscribedMailBoxes.Count(); i++ )
       
   947         {
       
   948         iMailClient->UnsubscribeMailboxEvents( iSubscribedMailBoxes[i], *this );
       
   949         }
       
   950     iSubscribedMailBoxesIds.Reset();
       
   951     iSubscribedMailBoxes.Reset();
       
   952 	
       
   953 	if ( iMailClient )
       
   954         {
       
   955         iMailClient->RemoveObserver( *this );
       
   956         iMailClient->Close();
       
   957         iMailClient = NULL;
       
   958         }
       
   959 
       
   960     CAknViewAppUi::Exit();
       
   961     }
       
   962 
       
   963 void CFreestyleEmailUiAppUi::CreateNewMailL()
       
   964 	{
       
   965     FUNC_LOG;
       
   966 	// Fill params
       
   967 	TEditorLaunchParams params;
       
   968 	params.iMailboxId = iActiveMailbox->GetId();
       
   969 	params.iActivatedExternally = EFalse;
       
   970 	LaunchEditorL( KEditorCmdCreateNew, params );
       
   971 	}
       
   972 
       
   973 CFsEmailUiViewBase* CFreestyleEmailUiAppUi::CurrentActiveView()
       
   974     {
       
   975     FUNC_LOG;
       
   976     return iCurrentActiveView;
       
   977     }
       
   978 
       
   979 CFsEmailUiViewBase* CFreestyleEmailUiAppUi::PreviousActiveView()
       
   980     {
       
   981     FUNC_LOG;
       
   982     return iPreviousActiveView;
       
   983     }
       
   984 
       
   985 TBool CFreestyleEmailUiAppUi::IsPluginSettingsViewActive()
       
   986     {
       
   987     FUNC_LOG;
       
   988     return iSettingsViewActive;
       
   989     }
       
   990 
       
   991 TInt CFreestyleEmailUiAppUi::NewEmailsInModelL()
       
   992 	{
       
   993     FUNC_LOG;
       
   994 	TInt ret(0);
       
   995 	if ( iMailListVisualiser )
       
   996 		{
       
   997 		ret = iMailListVisualiser->NewEmailsInModelL();
       
   998 		}
       
   999 	return ret;
       
  1000 	}
       
  1001 
       
  1002 TInt CFreestyleEmailUiAppUi::EmailsInModelL()
       
  1003 	{
       
  1004     FUNC_LOG;
       
  1005 	TInt ret(0);
       
  1006 	if ( iMailListVisualiser )
       
  1007 		{
       
  1008 		ret = iMailListVisualiser->EmailsInModelL();
       
  1009 		}
       
  1010 	return ret;
       
  1011 	}
       
  1012 
       
  1013 TInt CFreestyleEmailUiAppUi::EmailIndexInModel()
       
  1014 	{
       
  1015     FUNC_LOG;
       
  1016 	TInt currentInboxListIndex = iMailListVisualiser->HighlightedIndex();
       
  1017 	TInt ret=0;
       
  1018 	for ( TInt i=0;i<currentInboxListIndex;i++ )
       
  1019 		{
       
  1020 		CFSEmailUiMailListModelItem* item =
       
  1021 			static_cast<CFSEmailUiMailListModelItem*>(iMailListVisualiser->Model()->Item(i+1));
       
  1022 		if ( item->ModelItemType() == ETypeMailItem )
       
  1023 			{
       
  1024 			ret++;
       
  1025 			}
       
  1026 		}
       
  1027 	return ret; // Plus 1 for the first index, because it is always separator
       
  1028 	}
       
  1029 
       
  1030 
       
  1031 TKeyResponse CFreestyleEmailUiAppUi::HandleKeyEventL( const TKeyEvent& /*aKeyEvent*/,
       
  1032 												      TEventCode /*aType*/)
       
  1033     {
       
  1034     FUNC_LOG;
       
  1035 	return EKeyWasNotConsumed;
       
  1036 	}
       
  1037 
       
  1038 void CFreestyleEmailUiAppUi::HandleWsEventL(const TWsEvent &aEvent, CCoeControl* aDestination)
       
  1039 	{
       
  1040     FUNC_LOG;
       
  1041 	#ifndef KAknFullOrPartialForegroundGained
       
  1042 	const TInt KAknFullOrPartialForegroundGained = 0x10281F36;
       
  1043 	const TInt KAknFullOrPartialForegroundLost   = 0x10281F37;
       
  1044 	#endif
       
  1045     
       
  1046     TBool closeMenu = EFalse;
       
  1047     
       
  1048 	// Let folder list visualizer to handle event first because if the popup
       
  1049 	// is showed, that needs to be closed when pointer click happens outside of the
       
  1050 	// popup rect and also following pointer up event has to be consumed
       
  1051     if ( iFolderListVisualiser && iFolderListVisualiser->HandleWsEventL( aEvent ) )
       
  1052         {
       
  1053         return;
       
  1054         }
       
  1055 	
       
  1056 	TInt key = aEvent.Key()->iScanCode;
       
  1057     // <cmail>
       
  1058     // to disable voice commands during creating new mail message
       
  1059     if (EStdKeyYes == key && aEvent.Type() == EEventKeyDown  && iCurrentActiveView == iComposeView )
       
  1060 	    {
       
  1061 	    return; //"consume" event
       
  1062 	    }
       
  1063 	//</cmail>
       
  1064 	if ( EStdKeyNo == key && aEvent.Type() == EEventKeyDown )
       
  1065 		{
       
  1066 		// composeview needs this info when exiting
       
  1067 		//iAppUiExitOngoing = ETrue;<cmail> set to true in Exit() method
       
  1068 
       
  1069                 //<cmail> unnecessary exceptions removed from cmail
       
  1070 		/*if ( iCurrentActiveView == iComposeView )
       
  1071 			{
       
  1072 			iComposeView->HandleCommandL( ENcsCmdExit );
       
  1073 			}
       
  1074 		else
       
  1075 		    {*/
       
  1076 		if ( !AppUiExitOngoing() ) //avoid multiple red key presses during exiting
       
  1077 		    {
       
  1078             HandleCommandL( EEikCmdExit );
       
  1079             }
       
  1080 		    //} //<cmail>
       
  1081 		}
       
  1082     
       
  1083     TInt keyCode = aEvent.Key()->iCode;
       
  1084     
       
  1085     if ( EKeyQwertyOn == keyCode || 
       
  1086          EKeyQwertyOff == keyCode )
       
  1087         {
       
  1088         // Close menu when keyboard is opened or closed.  
       
  1089         closeMenu = ETrue;
       
  1090         }
       
  1091     
       
  1092     switch ( aEvent.Type() )
       
  1093         {
       
  1094         case KAknFullOrPartialForegroundLost:
       
  1095             break;
       
  1096         case KAknFullOrPartialForegroundGained:
       
  1097             {
       
  1098             if ( iCurrentActiveView && !iSettingsViewActive )
       
  1099                 {
       
  1100                 iCurrentActiveView->HandleAppForegroundEventL( ETrue );
       
  1101                 if ( iPendingLayoutSwitch )
       
  1102                     {
       
  1103                     iCurrentActiveView->HandleDynamicVariantSwitchL( CFsEmailUiViewBase::EScreenLayoutChanged );
       
  1104                     iPendingLayoutSwitch = EFalse;
       
  1105                     }
       
  1106                 }
       
  1107 
       
  1108     		// Call status indicator's foreground event to resize the connection screen after the screensaver
       
  1109     		if ( iStatusIndicator )
       
  1110                 {
       
  1111                 iStatusIndicator->HandleForegroundEventL();
       
  1112                 }
       
  1113     		}
       
  1114         	break;
       
  1115         default:
       
  1116             break;
       
  1117     	}
       
  1118     
       
  1119     // Close menu
       
  1120     if ( closeMenu && iCurrentActiveView != NULL )
       
  1121         {
       
  1122         CEikMenuBar* menu = iCurrentActiveView->MenuBar();
       
  1123         
       
  1124         if ( menu != NULL )
       
  1125             {
       
  1126             if ( menu->IsDisplayed() )
       
  1127                 {
       
  1128                 menu->StopDisplayingMenuBar();
       
  1129                 }
       
  1130             }
       
  1131         }
       
  1132     
       
  1133     CAknAppUi::HandleWsEventL(aEvent, aDestination);
       
  1134 	}
       
  1135 
       
  1136 CAlfDisplay& CFreestyleEmailUiAppUi::Display()
       
  1137 	{
       
  1138     FUNC_LOG;
       
  1139 	// Note: Alf doesn't need iCoeDisplay anymore, was return iCoeDisplay->Display();
       
  1140 	return iEnv->PrimaryDisplay();
       
  1141 	}
       
  1142 
       
  1143 CAlfEnv& CFreestyleEmailUiAppUi::AlfEnv()
       
  1144     {
       
  1145     FUNC_LOG;
       
  1146     return *iEnv;
       
  1147     }
       
  1148 
       
  1149 void CFreestyleEmailUiAppUi::HandleResourceChangeL( TInt aType )
       
  1150     {
       
  1151     FUNC_LOG;
       
  1152     // Workaround fix for JWIS-7KAEFD
       
  1153     // Dismiss action menu before doing dynamic variant switch, as it causes
       
  1154     // a phone reset if theme special effects are used.
       
  1155     // <cmail>
       
  1156     /*
       
  1157     if( aType == KEikDynamicLayoutVariantSwitch )
       
  1158         {
       
  1159         CFscContactActionMenu* actionMenu = CFSEmailUiActionMenu::GetActionMenu();
       
  1160         if( actionMenu )
       
  1161             {
       
  1162             actionMenu->Dismiss( EFalse );
       
  1163             }
       
  1164         }
       
  1165     */
       
  1166     // </cmail>
       
  1167     CAknAppUi::HandleResourceChangeL( aType );
       
  1168 
       
  1169     // Refresh mode is changed to manual to avoid any flickering during
       
  1170     // resource change handling in list views. Trap any leaves so that we set
       
  1171     // the automatic refresh mode back on even in case of error.
       
  1172     iEnv->SetRefreshMode( EAlfRefreshModeManual );
       
  1173     TRAPD( error, DoHandleResourceChangeL( aType ) );
       
  1174     iEnv->SetRefreshMode( EAlfRefreshModeAutomatic );
       
  1175     User::LeaveIfError( error );
       
  1176     }
       
  1177 
       
  1178 void CFreestyleEmailUiAppUi::DoHandleResourceChangeL( TInt aType )
       
  1179     {
       
  1180     FUNC_LOG;
       
  1181     // on skin change recreate the texture manager
       
  1182     // ignore skin change events during appui::constructL
       
  1183     // compose screen loadbackgroundcontext sends 2 skin change events
       
  1184     //if( aType == KAknsMessageSkinChange && iConstructComplete )
       
  1185     //    {
       
  1186     //    CAlfEnv::Static()->NotifySkinChangedL();
       
  1187     //    }
       
  1188     
       
  1189     
       
  1190     if( aType == KEikDynamicLayoutVariantSwitch || aType == KAknsMessageSkinChange)
       
  1191         {
       
  1192 	  	TRect screenRect;
       
  1193 	 	AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, screenRect );
       
  1194         //<cmail> layout manager call removed </cmail>
       
  1195         // Notify layouthandler of changed screen resolution.
       
  1196         iLayoutHandler->ScreenResolutionChanged();
       
  1197   		StatusPane()->DrawNow();
       
  1198         TRect rect;
       
  1199         AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, rect);
       
  1200         if(iEnv)
       
  1201             {
       
  1202 			Display().SetVisibleArea( screenRect );
       
  1203             }
       
  1204          }
       
  1205 
       
  1206     // Notify appropriate views
       
  1207     if ( iCurrentActiveView )
       
  1208         {
       
  1209         CFsEmailUiViewBase::TDynamicSwitchType type = CFsEmailUiViewBase::EOther;
       
  1210 
       
  1211         switch (aType)
       
  1212             {
       
  1213             case KAknsMessageSkinChange:
       
  1214                 type = CFsEmailUiViewBase::ESkinChanged;
       
  1215                 break;
       
  1216             case KEikDynamicLayoutVariantSwitch:
       
  1217                 type = CFsEmailUiViewBase::EScreenLayoutChanged;
       
  1218                 break;
       
  1219             default:
       
  1220                 break;
       
  1221             }
       
  1222 
       
  1223         // Report only events of known types
       
  1224         if ( type != CFsEmailUiViewBase::EOther )
       
  1225             {
       
  1226             // In case the FsEmail app is on background, relaying the layout change event to the active view
       
  1227             // is postponed until brought to foreground. This is done because otherwise it doesn't seem to work
       
  1228             // correctly in views which use Generic List component.
       
  1229 
       
  1230             if ( !iIsForeground && type == CFsEmailUiViewBase::EScreenLayoutChanged )
       
  1231                 {
       
  1232                 iPendingLayoutSwitch = ETrue;
       
  1233                 }
       
  1234 
       
  1235             if ( iCurrentActiveView && !iSettingsViewActive )
       
  1236                 {
       
  1237                 iCurrentActiveView->HandleDynamicVariantSwitchL( type );
       
  1238                 }
       
  1239 
       
  1240             // Notify status indicator about layout change
       
  1241             if ( iStatusIndicator )
       
  1242                 {
       
  1243                 iStatusIndicator->NotifyLayoutChange();
       
  1244                 }
       
  1245 
       
  1246             // All visible views are notified about resource change, so let's
       
  1247             // change refresh mode back to automatic
       
  1248             iEnv->SetRefreshMode( EAlfRefreshModeAutomatic );
       
  1249 
       
  1250             // In addition to the current view, the change is notified to all
       
  1251             // the previous views because returning to them often does not
       
  1252             // lead to complete redraw
       
  1253             for ( TInt i = 0; i < iNavigationHistory->Count(); ++i )
       
  1254                 {
       
  1255                 CFsEmailUiViewBase* view = (*iNavigationHistory)[i];
       
  1256                 view->HandleDynamicVariantSwitchOnBackgroundL( type );
       
  1257                 }
       
  1258             }
       
  1259         }
       
  1260     }
       
  1261 
       
  1262 void CFreestyleEmailUiAppUi::HandleActionL(const TAlfActionCommand& aActionCommand)
       
  1263     {
       
  1264     FUNC_LOG;
       
  1265     switch(aActionCommand.Id())
       
  1266         {
       
  1267        	case EFsEmailUiCmdHide:
       
  1268 			{
       
  1269 			TApaTaskList taskList( iEikonEnv->WsSession() );
       
  1270 			TApaTask task = taskList.FindApp( KFSEmailUiUid );
       
  1271 			if ( task.Exists() )
       
  1272 			    {
       
  1273 			    task.SendToBackground(); // Send self to background
       
  1274 			    }
       
  1275 			}
       
  1276        		break;
       
  1277         case EAknSoftkeyExit:
       
  1278             RunAppShutter();
       
  1279             break;
       
  1280         }
       
  1281     }
       
  1282 
       
  1283 void CFreestyleEmailUiAppUi::ManualMailBoxSync( TBool aManualMailBoxSync )
       
  1284     {
       
  1285     FUNC_LOG;
       
  1286     iManualMailBoxSync = aManualMailBoxSync;
       
  1287     }
       
  1288 
       
  1289 void CFreestyleEmailUiAppUi::ManualMailBoxSyncAll( TBool aManualMailBoxSyncAll )
       
  1290     {
       
  1291     FUNC_LOG;
       
  1292     iManualMailBoxSyncAll = aManualMailBoxSyncAll;
       
  1293     }
       
  1294 
       
  1295 void CFreestyleEmailUiAppUi::ManualMailBoxConnectAll( TBool aManualMailBoxConnectAll )
       
  1296     {
       
  1297     FUNC_LOG;
       
  1298     iManualMailBoxConnectAll = aManualMailBoxConnectAll;
       
  1299     }
       
  1300 
       
  1301 void CFreestyleEmailUiAppUi::ManualMailBoxDisconnectAll( TBool aManualMailBoxDisconnectAll )
       
  1302     {
       
  1303     FUNC_LOG;
       
  1304     iManualMailBoxDisconnectAll = aManualMailBoxDisconnectAll;
       
  1305     }
       
  1306 
       
  1307 CFSEmailUiLayoutHandler* CFreestyleEmailUiAppUi::LayoutHandler()
       
  1308 	{
       
  1309     FUNC_LOG;
       
  1310 	return iLayoutHandler;
       
  1311 	}
       
  1312 
       
  1313 CFreestyleEmailUiTextureManager* CFreestyleEmailUiAppUi::FsTextureManager()
       
  1314 	{
       
  1315     FUNC_LOG;
       
  1316 	return iFsTextureManager;
       
  1317 	}
       
  1318 
       
  1319 /*CFSEmailUiStatusIndicator* CFreestyleEmailUiAppUi::StatusIndicator()
       
  1320 	{
       
  1321     FUNC_LOG;
       
  1322 	return iStatusIndicator;
       
  1323 	}*/
       
  1324 
       
  1325 void CFreestyleEmailUiAppUi::LaunchEditorL( TEditorLaunchMode aMode, const TEditorLaunchParams& aParams )
       
  1326 	{
       
  1327     FUNC_LOG;
       
  1328 	// launch editor view with the given set of parameters
       
  1329 	TUid editorCommand = TUid::Uid( aMode );
       
  1330 	TPckgBuf<TEditorLaunchParams> buf( aParams );
       
  1331 	EnterFsEmailViewL( MailEditorId, editorCommand, buf );
       
  1332 	}
       
  1333 
       
  1334 CFSMailClient* CFreestyleEmailUiAppUi::GetMailClient()
       
  1335 	{
       
  1336     FUNC_LOG;
       
  1337 	return iMailClient;
       
  1338 	}
       
  1339 
       
  1340 // Returns pointer to download info mediator, ownership is not transferred
       
  1341 CFSEmailDownloadInfoMediator* CFreestyleEmailUiAppUi::DownloadInfoMediator()
       
  1342 	{
       
  1343     FUNC_LOG;
       
  1344 	return iDwnldMediator;
       
  1345 	}
       
  1346 
       
  1347 // ---------------------------------------------------------------------------
       
  1348 // Returns current screen display mode
       
  1349 // ---------------------------------------------------------------------------
       
  1350 //
       
  1351 TDisplayMode CFreestyleEmailUiAppUi::DisplayMode() const
       
  1352     {
       
  1353     FUNC_LOG;
       
  1354     return iEikonEnv->ScreenDevice()->DisplayMode();
       
  1355     }
       
  1356 
       
  1357 
       
  1358 // ---------------------------------------------------------------------------
       
  1359 // Returns the current flip status.
       
  1360 // ---------------------------------------------------------------------------
       
  1361 //
       
  1362 TBool CFreestyleEmailUiAppUi::IsFlipOpen() const
       
  1363 	{
       
  1364 	FUNC_LOG;
       
  1365 	return iFlipOpen;
       
  1366 	}
       
  1367 
       
  1368 
       
  1369 // ---------------------------------------------------------------------------
       
  1370 // Meeting request viewer instance
       
  1371 // ---------------------------------------------------------------------------
       
  1372 //
       
  1373 CESMRIcalViewer* CFreestyleEmailUiAppUi::MrViewerInstanceL()
       
  1374 	{
       
  1375     FUNC_LOG;
       
  1376 	if ( !iMRViewer )
       
  1377 		{
       
  1378 	  	// Create meeting request viewer
       
  1379 	    RImplInfoPtrArray implementations;
       
  1380 		CleanupResetAndDestroyClosePushL( implementations );
       
  1381 
       
  1382 	    REComSession::ListImplementationsL(
       
  1383 	        TUid::Uid( KESMRIcalViewerInterfaceUid ), implementations );
       
  1384 		if ( implementations.Count() && iHtmlViewerView )
       
  1385 			{
       
  1386 			// Found implementation of meeting request viewer
       
  1387 	        TRAPD( err, iMRViewer = CESMRIcalViewer::NewL( *iHtmlViewerView ) );
       
  1388 	        if ( err != KErrNone )
       
  1389 				{
       
  1390 				}
       
  1391 			}
       
  1392 	    CleanupStack::PopAndDestroy( &implementations );
       
  1393 		}
       
  1394 	return iMRViewer;
       
  1395 	}
       
  1396 /*Changing this since we now use HTML viewer*/
       
  1397 CFsEmailUiHtmlViewerView& CFreestyleEmailUiAppUi::MailViewer()
       
  1398     {
       
  1399     FUNC_LOG;
       
  1400     return *iHtmlViewerView;
       
  1401     }
       
  1402 
       
  1403 CFSEmailUiFolderListVisualiser& CFreestyleEmailUiAppUi::FolderList()
       
  1404     {
       
  1405     FUNC_LOG;
       
  1406     return *iFolderListVisualiser;
       
  1407     }
       
  1408 
       
  1409 CFSEmailUiLauncherGridVisualiser& CFreestyleEmailUiAppUi::LauncherGrid()
       
  1410     {
       
  1411     FUNC_LOG;
       
  1412     return *iMainUiGridVisualiser;
       
  1413     }
       
  1414 
       
  1415 CFSEmailCRHandler* CFreestyleEmailUiAppUi::GetCRHandler()
       
  1416 	{
       
  1417     FUNC_LOG;
       
  1418 	return iCRHandler;
       
  1419 	}
       
  1420 
       
  1421 CFSMailBox* CFreestyleEmailUiAppUi::GetActiveMailbox()
       
  1422 	{
       
  1423     FUNC_LOG;
       
  1424 	return iActiveMailbox;
       
  1425 	}
       
  1426 
       
  1427 
       
  1428 TFSMailMsgId CFreestyleEmailUiAppUi::GetActiveBoxInboxId()
       
  1429 	{
       
  1430     FUNC_LOG;
       
  1431 	return iActiveBoxInboxId;
       
  1432 	}
       
  1433 
       
  1434 TFSMailMsgId CFreestyleEmailUiAppUi::GetActiveMailboxId()
       
  1435 	{
       
  1436     FUNC_LOG;
       
  1437 	return iActiveMailboxId;
       
  1438 	}
       
  1439 
       
  1440 CMsvSession* CFreestyleEmailUiAppUi::GetMsvSession()
       
  1441 	{
       
  1442     FUNC_LOG;
       
  1443 	return iMsvSession;
       
  1444 	}
       
  1445 
       
  1446 CVPbkContactManager& CFreestyleEmailUiAppUi::GetVPbkManagerL()
       
  1447 	{
       
  1448     FUNC_LOG;
       
  1449 	CVPbkContactManager* temp = CFsDelayedLoader::InstanceL()->
       
  1450 		GetContactHandlerL()->GetContactManager();
       
  1451 	return *(temp);
       
  1452 	}
       
  1453 
       
  1454 // ---------------------------------------------------------------------------
       
  1455 // Launch editor with new message and one address in TO-field
       
  1456 // Address object ownership is not transferred
       
  1457 // ---------------------------------------------------------------------------
       
  1458 //
       
  1459 void CFreestyleEmailUiAppUi::LaunchEditorL( CFSMailAddress* aToAddress )
       
  1460 	{
       
  1461     FUNC_LOG;
       
  1462 	// launch editor view with the given set of parameters
       
  1463 	TUid editorCommand = TUid::Uid( KEditorCmdInternalMailto );
       
  1464 	TEditorLaunchParams params;
       
  1465 	params.iMailboxId = GetActiveMailboxId();
       
  1466 	params.iActivatedExternally = EFalse;
       
  1467 	params.iExtra = aToAddress;
       
  1468 	TPckgBuf<TEditorLaunchParams> buf( params );
       
  1469 	EnterFsEmailViewL( MailEditorId, editorCommand, buf );
       
  1470 	}
       
  1471 
       
  1472 // ---------------------------------------------------------------------------
       
  1473 // Handle APPUI to subscribe events also for connection info
       
  1474 // Once mailbox has been active, it's events will be handled
       
  1475 // Add mailbox to subscribed array if not already
       
  1476 // ---------------------------------------------------------------------------
       
  1477 void CFreestyleEmailUiAppUi::SubscribeMailboxL( TFSMailMsgId aActiveMailboxId )
       
  1478     {
       
  1479     FUNC_LOG;
       
  1480     if ( iSubscribedMailBoxesIds.Find( aActiveMailboxId.Id() ) == KErrNotFound )
       
  1481         {
       
  1482         iSubscribedMailBoxesIds.Append( aActiveMailboxId.Id() );
       
  1483         iMailClient->SubscribeMailboxEventsL( aActiveMailboxId, *this  );
       
  1484         }
       
  1485     }
       
  1486 
       
  1487 void CFreestyleEmailUiAppUi::SetActiveMailboxL( TFSMailMsgId aActiveMailboxId, TBool aAutoSync )
       
  1488 	{
       
  1489     FUNC_LOG;
       
  1490  	// Set flag
       
  1491 	iAutomatedMailBoxOnline = EFalse;
       
  1492 	
       
  1493 	// Try to get the mailbox
       
  1494 	CFSMailBox* newActiveBox = iMailClient->GetMailBoxByUidL( aActiveMailboxId );
       
  1495 	User::LeaveIfNull( newActiveBox );
       
  1496 	
       
  1497     // Replace active mailbox of the application if getting the mailbox was succesful
       
  1498     delete iActiveMailbox;
       
  1499     iActiveMailbox = newActiveBox;
       
  1500 
       
  1501     iActiveMailboxId = iActiveMailbox->GetId();                 
       
  1502     iActiveBoxInboxId = iActiveMailbox->GetStandardFolderId( EFSInbox ); 
       
  1503 
       
  1504 	SubscribeMailboxL( iActiveMailboxId );
       
  1505 
       
  1506 	// Start connect automatically if asked by the caller
       
  1507 	// Disabled if offline or roaming
       
  1508 	if ( aAutoSync && !TFsEmailUiUtility::IsOfflineModeL() )
       
  1509 		{
       
  1510 		// Create at first auto-connect, autosync monitor will check whether
       
  1511 		// it is ok to start auto-connect, e.g. phone is not roaming, searching for net, etc
       
  1512 		if ( !iAutoSyncMonitor )
       
  1513 			{
       
  1514 			// TRAP following since failing to create auto sync monitor should not prevent user
       
  1515 			// from opening mail list, leave only in OOM case.
       
  1516 			TRAPD( err, iAutoSyncMonitor = CFSEmailUiAutosyncMonitor::NewL( *this ) );
       
  1517 			if ( err == KErrNoMemory )
       
  1518 				{
       
  1519 				User::Leave( err );
       
  1520 				}
       
  1521 			}
       
  1522 		// Request auto sync if allowed in the current network mode and
       
  1523 		// autosyncmonitor has been succesfully created
       
  1524 		if ( iAutoSyncMonitor )
       
  1525 			{
       
  1526 			iAutoSyncMonitor->StartMonitoring();
       
  1527 			}
       
  1528 		}
       
  1529 	}
       
  1530 
       
  1531 
       
  1532 void CFreestyleEmailUiAppUi::DoAutoConnectL()
       
  1533 	{
       
  1534     FUNC_LOG;
       
  1535 	if ( iActiveMailbox && iActiveMailbox->HasCapability( EFSMBoxCapaSupportsSync ) )
       
  1536  		{
       
  1537 		// Start sync automatically if not syncing already
       
  1538 		TSSMailSyncState latestSyncstate = iActiveMailbox->CurrentSyncState();
       
  1539 		if( latestSyncstate != InboxSyncing && latestSyncstate != StartingSync &&
       
  1540 			latestSyncstate != EmailSyncing )
       
  1541 			{
       
  1542 			if ( iActiveMailbox->GetMailBoxStatus() != EFSMailBoxOnline )
       
  1543 				{
       
  1544 				iActiveMailbox->GoOnlineL();
       
  1545 				}
       
  1546 			}
       
  1547 		}
       
  1548 	else if ( iActiveMailbox )// Go online automatically, e.g, refresh
       
  1549 		{
       
  1550 		// Check if non sync support mailbox is already online
       
  1551 		// Typically this is for Pop
       
  1552 		if ( iActiveMailbox->GetMailBoxStatus() == EFSMailBoxOnline )
       
  1553 			{
       
  1554 			// Already online, disable next note
       
  1555 			iAutomatedMailBoxOnline = ETrue;
       
  1556 			}
       
  1557 		iActiveMailbox->GoOnlineL();
       
  1558 		}
       
  1559 	}
       
  1560 
       
  1561 TBool CFreestyleEmailUiAppUi::AppUiExitOngoing()
       
  1562 	{
       
  1563     FUNC_LOG;
       
  1564 	return g_ApplicationExitOnGoing;
       
  1565 	}
       
  1566 
       
  1567 TBool CFreestyleEmailUiAppUi::MessageReaderSupportsFreestyle()
       
  1568 	{
       
  1569     FUNC_LOG;
       
  1570 	// Check availability of Reader if necessary. Msg reader cannot be installed 
       
  1571 	// from sisx so checking is done only once. KErrGeneral at startup.
       
  1572 	if ( iMsgReaderIsSupported == KErrGeneral )
       
  1573 		{
       
  1574 		RLibrary freestyleMessageScannerLibrary;
       
  1575         TUidType uidType( KDynamicLibraryUid, KSharedLibraryUid, TUid::Uid( 0x10281C61 ) );
       
  1576 		iMsgReaderIsSupported = freestyleMessageScannerLibrary.Load( KMsgReaderFsDll, uidType );
       
  1577         if ( iMsgReaderIsSupported == KErrNone)
       
  1578         	{
       
  1579         	freestyleMessageScannerLibrary.Close();
       
  1580         	}
       
  1581 		}
       
  1582 	TBool ret(EFalse);
       
  1583 	if ( iMsgReaderIsSupported == KErrNone )
       
  1584 		{
       
  1585 		ret = ETrue;
       
  1586 		}
       
  1587 	return ret;
       
  1588 	}
       
  1589 
       
  1590 void CFreestyleEmailUiAppUi::StartReadingEmailsL()
       
  1591 	{
       
  1592     FUNC_LOG;
       
  1593 	TVwsViewId viewId( TUid::Uid( 0x10201B00 ), TUid::Uid( 1 ) );
       
  1594 	TUid customMessageId( TUid::Uid( 2 ) );
       
  1595 	CFSMailBox* mb = GetActiveMailbox();
       
  1596 
       
  1597 	// Check if view is in mail list
       
  1598 	if ( mb && View(MailListId)->IsForeground() )
       
  1599 		{
       
  1600 		RArray<TFSMailMsgId> markedMsgIdArray;
       
  1601 		CleanupClosePushL(markedMsgIdArray);
       
  1602 		iMailListVisualiser->GetMarkedMessagesL(markedMsgIdArray);
       
  1603 		// Read marked items
       
  1604         if (markedMsgIdArray.Count() != 0 )
       
  1605 			{
       
  1606             delete iCustomMessageToMessageReader;
       
  1607             iCustomMessageToMessageReader = NULL;
       
  1608 			iCustomMessageToMessageReader = HBufC8::NewL(markedMsgIdArray.Count() * 16);
       
  1609 			TPtr8 msgPtr = iCustomMessageToMessageReader->Des();
       
  1610 			RDesWriteStream outStream( msgPtr );
       
  1611 			CleanupClosePushL( outStream );
       
  1612 
       
  1613 			for (int i = 0; i < markedMsgIdArray.Count(); i++)
       
  1614 				{
       
  1615 			    outStream.WriteInt32L( mb->GetId().PluginId().iUid );
       
  1616 			    outStream.WriteUint32L( mb->GetId().Id() );
       
  1617 			    outStream.WriteUint32L( iMailListVisualiser->FolderId().Id() );
       
  1618 			    outStream.WriteUint32L( (markedMsgIdArray.operator[](i)).Id());
       
  1619 				}
       
  1620 			CleanupStack::PopAndDestroy( &outStream );
       
  1621 
       
  1622             ActivateViewL( viewId, customMessageId,
       
  1623                 *iCustomMessageToMessageReader ) ;
       
  1624 			}
       
  1625 		else //Read focused item
       
  1626 			{
       
  1627             delete iCustomMessageToMessageReader;
       
  1628             iCustomMessageToMessageReader = NULL;
       
  1629 			iCustomMessageToMessageReader = HBufC8::NewL(16);
       
  1630 			TPtr8 msgPtr = iCustomMessageToMessageReader->Des();
       
  1631 		    RDesWriteStream outStream( msgPtr );
       
  1632 			CleanupClosePushL( outStream );
       
  1633 
       
  1634 		    outStream.WriteInt32L( mb->GetId().PluginId().iUid );
       
  1635 		    outStream.WriteUint32L( mb->GetId().Id() );
       
  1636 		    outStream.WriteUint32L( iMailListVisualiser->FolderId().Id() );
       
  1637 		    outStream.WriteUint32L( (iMailListVisualiser->MsgIdFromListId(iMailListVisualiser->GetMailList().FocusedItem())).Id() );
       
  1638 
       
  1639 		    CleanupStack::PopAndDestroy( &outStream );
       
  1640 
       
  1641             if ((iMailListVisualiser->MsgIdFromListId(iMailListVisualiser->GetMailList().FocusedItem())).Id() != NULL)
       
  1642                 {
       
  1643                 ActivateViewL( viewId, customMessageId,
       
  1644                     *iCustomMessageToMessageReader ) ;
       
  1645                 }
       
  1646 			}
       
  1647 		CleanupStack::PopAndDestroy( &markedMsgIdArray );
       
  1648 		}
       
  1649 	// Check if view is in mail viewer
       
  1650 	else if ( mb && ( View(MailViewerId)->IsForeground() || View(SearchListViewId)->IsForeground() ) )
       
  1651 		{
       
  1652         delete iCustomMessageToMessageReader;
       
  1653         iCustomMessageToMessageReader = NULL;
       
  1654 		iCustomMessageToMessageReader = HBufC8::NewL(16);
       
  1655 		TPtr8 msgPtr = iCustomMessageToMessageReader->Des();
       
  1656 	    RDesWriteStream outStream( msgPtr );
       
  1657 		CleanupClosePushL( outStream );
       
  1658 	    outStream.WriteInt32L( mb->GetId().PluginId().iUid );
       
  1659 	    outStream.WriteUint32L( mb->GetId().Id() );
       
  1660 		TFSMailMsgId folderId;
       
  1661 	   	TFSMailMsgId msgId;
       
  1662 	   	if ( View(MailViewerId)->IsForeground() && iHtmlViewerView )
       
  1663 	   		{
       
  1664 	   		folderId = iHtmlViewerView->ViewedMessageFolderId();
       
  1665 	   		msgId = iHtmlViewerView->ViewedMessageId();
       
  1666 	   		}
       
  1667 	   	else if ( View(SearchListViewId)->IsForeground() && iSearchListVisualiser )
       
  1668 	   		{
       
  1669 	   		folderId = iSearchListVisualiser->HighlightedMessageFolderId();
       
  1670 	   		msgId = iSearchListVisualiser->HighlightedMessageId();
       
  1671 	   		}
       
  1672 
       
  1673 	    outStream.WriteUint32L( folderId.Id() );
       
  1674 	    outStream.WriteUint32L( msgId.Id() );
       
  1675 
       
  1676 	    CleanupStack::PopAndDestroy( &outStream );
       
  1677 
       
  1678         if ( msgId.Id() )
       
  1679             {
       
  1680             ActivateViewL( viewId, customMessageId,
       
  1681                 *iCustomMessageToMessageReader ) ;
       
  1682             }
       
  1683 		}
       
  1684 	}
       
  1685 
       
  1686 TBool CFreestyleEmailUiAppUi::ViewSwitchingOngoing()
       
  1687 	{
       
  1688     FUNC_LOG;
       
  1689 	return EFalse;
       
  1690 	}
       
  1691 
       
  1692 void CFreestyleEmailUiAppUi::RequestResponseL( TFSProgress /*aEvent*/, TInt /*aRequestId*/ )
       
  1693 	{
       
  1694     FUNC_LOG;
       
  1695 
       
  1696 	}
       
  1697 
       
  1698 // Force Sync on active mailbox.
       
  1699 void CFreestyleEmailUiAppUi::SyncActiveMailBoxL()
       
  1700 	{
       
  1701     FUNC_LOG;
       
  1702 	if ( iActiveMailbox )
       
  1703 		{
       
  1704     	iSyncStatusReqId = iActiveMailbox->RefreshNowL( *this );
       
  1705 		}
       
  1706 	}
       
  1707 
       
  1708 void CFreestyleEmailUiAppUi::StopActiveMailBoxSyncL()
       
  1709 	{
       
  1710     FUNC_LOG;
       
  1711     if ( iActiveMailbox )
       
  1712         {
       
  1713         iActiveMailbox->CancelSyncL();
       
  1714         }
       
  1715 	}
       
  1716 
       
  1717 
       
  1718 MCoeMessageObserver::TMessageResponse CFreestyleEmailUiAppUi::HandleMessageL(
       
  1719     TUint32 aClientHandleOfTargetWindowGroup,
       
  1720     TUid aMessageUid,
       
  1721     const TDesC8& aMessageParameters )
       
  1722     {
       
  1723     FUNC_LOG;
       
  1724 
       
  1725     if ( iWizardObserver )
       
  1726         {
       
  1727         iWizardObserver->HandleMessage( aClientHandleOfTargetWindowGroup,
       
  1728                                         aMessageUid,
       
  1729                                         aMessageParameters);
       
  1730         }
       
  1731 
       
  1732     return CAknViewAppUi::HandleMessageL( aClientHandleOfTargetWindowGroup,
       
  1733                                           aMessageUid,
       
  1734                                           aMessageParameters);
       
  1735     }
       
  1736 
       
  1737 void CFreestyleEmailUiAppUi::HandleForegroundEventL( TBool aForeground )
       
  1738     {
       
  1739     FUNC_LOG;
       
  1740 
       
  1741     // store flag indicating whether we are foreground
       
  1742     iIsForeground = aForeground;
       
  1743 
       
  1744     if ( iIsForeground )
       
  1745         {
       
  1746         if ( View( MailEditorId )->IsForeground() )
       
  1747             {
       
  1748             StartEndKeyCapture();
       
  1749             }
       
  1750         }
       
  1751     else
       
  1752         {
       
  1753         StopEndKeyCapture();
       
  1754         }
       
  1755 
       
  1756     if ( iWizardObserver )
       
  1757         {
       
  1758         iWizardObserver->HandleForegroundEventL( aForeground );
       
  1759         }
       
  1760 
       
  1761     CAknViewAppUi::HandleForegroundEventL( aForeground );
       
  1762     }
       
  1763 
       
  1764 
       
  1765 void CFreestyleEmailUiAppUi::EventL( TFSMailEvent aEvent, TFSMailMsgId aMailbox,
       
  1766                                      TAny* aParam1, TAny* aParam2, TAny* aParam3 )
       
  1767     {
       
  1768     FUNC_LOG;
       
  1769     
       
  1770     if (iExitGuardian)
       
  1771         {
       
  1772         iExitGuardian->EnterLC();
       
  1773         }
       
  1774 
       
  1775     TBool gridContentsChanged = EFalse;
       
  1776 
       
  1777     switch ( aEvent )
       
  1778     	{
       
  1779     	case TFSEventMailboxDeleted:
       
  1780     		{
       
  1781     		gridContentsChanged = ETrue;
       
  1782     		if ( iActiveMailbox && iActiveMailbox->GetId().Id() == aMailbox.Id() &&
       
  1783     			 iCurrentActiveView->Id() != SettingsViewId )
       
  1784     			{
       
  1785 				EnterFsEmailViewL( AppGridId );
       
  1786 				EraseViewHistory(); // the previous views probably no longer exist if we've got here
       
  1787     			}
       
  1788 			}
       
  1789 			break;
       
  1790    		case TFSEventMailboxOnline:
       
  1791    		case TFSEventMailboxOffline:
       
  1792    			{
       
  1793    			if (aEvent == TFSEventMailboxOnline)
       
  1794    			    {
       
  1795    			    UpdateTitlePaneConnectionStatus(EForceToConnected);
       
  1796    			    }
       
  1797    			else if (aEvent == TFSEventMailboxOffline)
       
  1798    			    {
       
  1799    			    UpdateTitlePaneConnectionStatus(EForceToDisconnected);
       
  1800    			    }
       
  1801             // Cancel all ongoing downloads for the disconnected mailbox
       
  1802             if (iDwnldMediator && aEvent == TFSEventMailboxOffline)
       
  1803               {
       
  1804               iDwnldMediator->CancelAllDownloadsL(aMailbox);
       
  1805               }
       
  1806 			if ( !iAutomatedMailBoxOnline )
       
  1807 				{
       
  1808 	   			CFSMailBox* mb = iMailClient->GetMailBoxByUidL( aMailbox );
       
  1809 				CleanupStack::PushL( mb );
       
  1810 				TDesC* mbName = &mb->GetName();
       
  1811 		     	if ( aEvent == TFSEventMailboxOffline )
       
  1812 		     		{
       
  1813 			     	if ( !(mbName && mbName->Length() && !iManualMailBoxDisconnectAll) )
       
  1814 			     		{
       
  1815                         ManualMailBoxDisconnectAll(EFalse);
       
  1816 				     	}
       
  1817 		     		}
       
  1818 		     	else if ( aEvent == TFSEventMailboxOnline )
       
  1819 		     		{
       
  1820 			     	if ( !(mbName && mbName->Length() && !iManualMailBoxConnectAll) )
       
  1821 			     	    {
       
  1822 				     	ManualMailBoxConnectAll(EFalse);
       
  1823 			     		}
       
  1824 		     		}
       
  1825 	  			CleanupStack::PopAndDestroy( mb );
       
  1826 				}
       
  1827 			else
       
  1828 				{
       
  1829 				iAutomatedMailBoxOnline = EFalse;
       
  1830 				}
       
  1831    			}
       
  1832   			break;
       
  1833     	case TFSEventMailboxSyncStateChanged:
       
  1834     		{
       
  1835     		TSSMailSyncState* newSyncState = static_cast<TSSMailSyncState*>( aParam1 );
       
  1836     		if ( newSyncState !=0 && *newSyncState )
       
  1837     			{
       
  1838         		switch ( *newSyncState )
       
  1839         			{
       
  1840                     case StartingSync:
       
  1841                         {
       
  1842                         //If syncs were started by user, show the synchoronisation indicator
       
  1843                         if(iManualMailBoxSyncAll)
       
  1844                             {
       
  1845                             ManualMailBoxSyncAll(EFalse);
       
  1846                             }
       
  1847                         else if (iManualMailBoxSync)
       
  1848                             {
       
  1849                             TDesC* mbName(0);
       
  1850                             CFSMailBox* mb = GetActiveMailbox();
       
  1851                             if ( mb )
       
  1852                                 {
       
  1853                                 mbName = &mb->GetName();
       
  1854                                 }
       
  1855                             }
       
  1856                         }
       
  1857                         break;                      
       
  1858                     case SyncError:
       
  1859                         {
       
  1860                         // error occured during "Connect" or "Send and receive" operation
       
  1861                         // check if user needs to be notified
       
  1862                         if ( iManualMailBoxSync )
       
  1863                             {
       
  1864                             // since error id is not provided by plugin, lets popup general note
       
  1865                             HBufC* text = StringLoader::LoadL( R_FS_MSERVER_TEXT_UNABLE_TO_COMPLETE );
       
  1866                             CleanupStack::PushL( text );
       
  1867                             CAknInformationNote* infoNote = new ( ELeave ) CAknInformationNote;
       
  1868                             infoNote->ExecuteLD( *text );
       
  1869                             CleanupStack::PopAndDestroy( text );
       
  1870                             ManualMailBoxSync( EFalse );
       
  1871                             }
       
  1872                         }
       
  1873                         break;                      
       
  1874                     case FinishedSuccessfully:
       
  1875                     case SyncCancelled:
       
  1876                     case Idle:
       
  1877                         {
       
  1878                         ManualMailBoxSync( EFalse );
       
  1879                         }
       
  1880                         break;
       
  1881 
       
  1882        				case PushChannelOffBecauseBatteryIsLow:
       
  1883     					{
       
  1884      					CFSMailBox* mb = iMailClient->GetMailBoxByUidL( aMailbox );
       
  1885     					CleanupStack::PushL( mb );
       
  1886     					TDesC* mbName = &mb->GetName();
       
  1887     		  			CleanupStack::PopAndDestroy( mb );
       
  1888     					}
       
  1889     					break;
       
  1890         			} //switch
       
  1891     			}
       
  1892     		UpdateTitlePaneConnectionStatus();
       
  1893     		} //case
       
  1894     		break;
       
  1895 
       
  1896 		case TFSEventNewMailbox:
       
  1897 		    {
       
  1898             gridContentsChanged = ETrue;
       
  1899             iMailClient->GetBrandManagerL().UpdateMailboxNamesL( aMailbox );
       
  1900 		    }
       
  1901             // fall through
       
  1902 		case TFSEventMailboxCreationFailure:
       
  1903 		    {
       
  1904 		    if ( iWizardObserver )
       
  1905                 {
       
  1906                 iWizardObserver->EventL( aEvent, aMailbox, aParam1, aParam2, aParam3 );
       
  1907                 }
       
  1908             }
       
  1909             break;
       
  1910         case TFSEventMailboxRenamed:
       
  1911             {
       
  1912             gridContentsChanged = ETrue;
       
  1913             if ( aMailbox == iActiveMailboxId )
       
  1914                 {
       
  1915                 // Update active mailbox
       
  1916                 delete iActiveMailbox;
       
  1917                 iActiveMailbox = NULL;
       
  1918                 iActiveMailbox = iMailClient->GetMailBoxByUidL( aMailbox );
       
  1919                 }
       
  1920             }
       
  1921             break;
       
  1922    		case TFSEventMailboxSettingsChanged:
       
  1923 			// Refresh grid if mailbox settings are changed,
       
  1924 			// name/branding might have changed.
       
  1925 	   	 	gridContentsChanged = ETrue;
       
  1926 			break;
       
  1927         default:
       
  1928             {
       
  1929             }
       
  1930         }
       
  1931 	// Forward events to mail list
       
  1932     if ( iMailListVisualiser )
       
  1933     	{
       
  1934     	iMailListVisualiser->HandleMailBoxEventL( aEvent, aMailbox, aParam1, aParam2, aParam3 );
       
  1935     	}
       
  1936 	// Forward events to Search list
       
  1937     if ( iSearchListVisualiser )
       
  1938     	{
       
  1939     	iSearchListVisualiser->HandleMailBoxEventL( aEvent, aMailbox, aParam1, aParam2, aParam3 );
       
  1940     	}
       
  1941     if ( gridContentsChanged && iMainUiGridVisualiser )
       
  1942         {
       
  1943         iMainUiGridVisualiser->HandleContentChangeL();
       
  1944         }
       
  1945     // <cmail> forward online/offline events also to folder list
       
  1946     if ( iFolderListVisualiser )
       
  1947     	{
       
  1948     	iFolderListVisualiser->HandleMailBoxEventL( aEvent, aMailbox, aParam1, aParam2, aParam3 );
       
  1949     	}
       
  1950     // </cmail>
       
  1951 
       
  1952 	// MAIL DELETED EVENT HANDLING BASED ON VIEW ACTIVE STATE.
       
  1953     // Handle mail deleted event in mail viewer, as viewed mail could be open
       
  1954     if ( iViewerVisualiser && aEvent == TFSEventMailDeleted &&
       
  1955     	 iCurrentActiveView->Id() == MailViewerId )
       
  1956     	{
       
  1957     	iViewerVisualiser->HandleMailBoxEventL( aEvent, aMailbox, aParam1, aParam2, aParam3 );
       
  1958     	}
       
  1959     // Handle mail deleted event in attachment list, as the viewed mail could be open
       
  1960     else if ( iAttachmentListVisualiser && aEvent == TFSEventMailDeleted  &&
       
  1961     	 iCurrentActiveView->Id() == AttachmentMngrViewId)
       
  1962     	{
       
  1963     	iAttachmentListVisualiser->HandleMailBoxEventL( aEvent, aMailbox, aParam1, aParam2, aParam3 );
       
  1964     	}
       
  1965     // Handle mail deleted event in Html view list, as the mails might become obsolete
       
  1966     else if ( iHtmlViewerView && (aEvent == TFSEventMailDeleted || aEvent == TFSEventNewMail) &&
       
  1967     	 iCurrentActiveView->Id() == HtmlViewerId)
       
  1968     	{
       
  1969     	iHtmlViewerView->HandleMailBoxEventL( aEvent, aMailbox, aParam1, aParam2, aParam3 );
       
  1970     	}
       
  1971     // Download manager removed
       
  1972 
       
  1973     if (iExitGuardian)
       
  1974         {
       
  1975         CleanupStack::PopAndDestroy(); // iExitGuardian->EnterLC()
       
  1976         }
       
  1977     }
       
  1978 
       
  1979 void CFreestyleEmailUiAppUi::LaunchWizardL()
       
  1980     {
       
  1981     FUNC_LOG;
       
  1982     TRAPD( err, iMainUiGridVisualiser->LaunchWizardL() );
       
  1983 	if ( err != KErrNone )
       
  1984 		{
       
  1985 		}
       
  1986     if ( err == KErrNoMemory )
       
  1987     	{
       
  1988     	User::Leave( err ); // Leave in OOM, otherwise ignore
       
  1989     	}
       
  1990     }
       
  1991 
       
  1992 const CFSEmailUiShortcutBinding& CFreestyleEmailUiAppUi::ShortcutBinding() const
       
  1993     {
       
  1994     FUNC_LOG;
       
  1995     return *iShortcutBinder;
       
  1996     }
       
  1997 
       
  1998 void CFreestyleEmailUiAppUi::HandleSessionEventL( TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/ )
       
  1999 	{
       
  2000     FUNC_LOG;
       
  2001 	// handle events
       
  2002 	}
       
  2003 
       
  2004 // For checking whether next msg is available
       
  2005 TBool CFreestyleEmailUiAppUi::IsNextMsgAvailable( TFSMailMsgId aCurrentMsgId,
       
  2006 												  TFSMailMsgId& aFoundNextMsgId,
       
  2007 												  TFSMailMsgId& aFoundNextMsgFolder )
       
  2008 	{
       
  2009     FUNC_LOG;
       
  2010 	TBool ret(EFalse);
       
  2011 	if ( !iNavigationHistory->IsEmpty() )
       
  2012 	    {
       
  2013 	    ret = iNavigationHistory->Head()->IsNextMsgAvailable( aCurrentMsgId, aFoundNextMsgId, aFoundNextMsgFolder );
       
  2014 	    }
       
  2015 	return ret;
       
  2016 	}
       
  2017 
       
  2018 // For checking whether previous msg is available
       
  2019 TBool CFreestyleEmailUiAppUi::IsPreviousMsgAvailable( TFSMailMsgId aCurrentMsgId,
       
  2020 													  TFSMailMsgId& aFoundPreviousMsgId,
       
  2021 													  TFSMailMsgId& aFoundPrevMsgFolder )
       
  2022 	{
       
  2023     FUNC_LOG;
       
  2024 	TBool ret(EFalse);
       
  2025 	if ( !iNavigationHistory->IsEmpty() )
       
  2026 	    {
       
  2027 	    ret = iNavigationHistory->Head()->IsPreviousMsgAvailable( aCurrentMsgId, aFoundPreviousMsgId, aFoundPrevMsgFolder );
       
  2028 	    }
       
  2029 	return ret;
       
  2030 	}
       
  2031 
       
  2032 // Move to next msg
       
  2033 TInt CFreestyleEmailUiAppUi::MoveToNextMsgL( TFSMailMsgId aCurrentMsgId,
       
  2034     TFSMailMsgId& aFoundNextMsgId )
       
  2035 	{
       
  2036     FUNC_LOG;
       
  2037 	TInt ret(KErrNotFound);
       
  2038 	if ( !iNavigationHistory->IsEmpty() )
       
  2039 	    {
       
  2040 	    iNavigationHistory->Head()->MoveToNextMsgL( aCurrentMsgId, aFoundNextMsgId );
       
  2041 	    }
       
  2042 	return ret;
       
  2043 	}
       
  2044 
       
  2045 // Move to previous msg
       
  2046 TInt CFreestyleEmailUiAppUi::MoveToPreviousMsgL( TFSMailMsgId aCurrentMsgId,
       
  2047     TFSMailMsgId& aFoundPreviousMsgId )
       
  2048 	{
       
  2049     FUNC_LOG;
       
  2050 	TInt ret(KErrNotFound);
       
  2051 	if ( !iNavigationHistory->IsEmpty() )
       
  2052 	    {
       
  2053 	    iNavigationHistory->Head()->MoveToPreviousMsgL( aCurrentMsgId, aFoundPreviousMsgId );
       
  2054 	    }
       
  2055 	return ret;
       
  2056 	}
       
  2057 
       
  2058 CDocumentHandler& CFreestyleEmailUiAppUi::DocumentHandler()
       
  2059 	{
       
  2060     FUNC_LOG;
       
  2061 	return *iDocumentHandler;
       
  2062 	}
       
  2063 
       
  2064 CFsEmailFileHandleShutter& CFreestyleEmailUiAppUi::FileHandleShutter()
       
  2065     {
       
  2066     FUNC_LOG;
       
  2067     return *iFileHandleShutter;
       
  2068     }
       
  2069 
       
  2070 const TDesC& CFreestyleEmailUiAppUi::TitlePaneTextL()
       
  2071     {
       
  2072     FUNC_LOG;
       
  2073 	TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
       
  2074 	CEikStatusPaneBase::TPaneCapabilities subPaneTitle =
       
  2075 		StatusPane()->PaneCapabilities( titlePaneUid );
       
  2076 
       
  2077 	if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
       
  2078 		{
       
  2079 		CAknTitlePane* titlePane = static_cast< CAknTitlePane* >(
       
  2080 				StatusPane()->ControlL( titlePaneUid ) );
       
  2081 		return *titlePane->Text();
       
  2082 		}
       
  2083 	return KNullDesC;
       
  2084     }
       
  2085 
       
  2086 void CFreestyleEmailUiAppUi::SetTitlePaneTextL( const TDesC& aText )
       
  2087     {
       
  2088     FUNC_LOG;
       
  2089 	TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
       
  2090 	CEikStatusPaneBase::TPaneCapabilities subPaneTitle =
       
  2091 		StatusPane()->PaneCapabilities( titlePaneUid );
       
  2092 
       
  2093 	if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
       
  2094 		{
       
  2095 		CAknTitlePane* titlePane = static_cast< CAknTitlePane* >(
       
  2096 				StatusPane()->ControlL( titlePaneUid ) );
       
  2097 		titlePane->SetTextL( aText, ETrue );
       
  2098 		}
       
  2099     }
       
  2100 
       
  2101 void CFreestyleEmailUiAppUi::ResetTitlePaneTextL()
       
  2102     {
       
  2103     FUNC_LOG;
       
  2104 	TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
       
  2105 	CEikStatusPaneBase::TPaneCapabilities subPaneTitle =
       
  2106 		StatusPane()->PaneCapabilities( titlePaneUid );
       
  2107 
       
  2108 	if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
       
  2109 		{
       
  2110 		CAknTitlePane* titlePane = static_cast<CAknTitlePane*>(
       
  2111 				StatusPane()->ControlL( titlePaneUid ) );
       
  2112 		titlePane->SetTextToDefaultL();
       
  2113 		}
       
  2114     }
       
  2115 
       
  2116 void CFreestyleEmailUiAppUi::SetActiveMailboxNameToStatusPaneL()
       
  2117     {
       
  2118     FUNC_LOG;
       
  2119     // Branded mailbox name is nowadays set in new mailbox event
       
  2120     // handling, so we don't need to use brand manager here anymore.
       
  2121 
       
  2122     // Get pointer to updated mb
       
  2123     CFSMailBox* confirmedMailBox = GetMailClient()->GetMailBoxByUidL( GetActiveMailboxId() );
       
  2124     CleanupStack::PushL( confirmedMailBox );
       
  2125     TDesC* mbName(0);
       
  2126     if ( confirmedMailBox )
       
  2127         {
       
  2128         mbName = &confirmedMailBox->GetName();
       
  2129 
       
  2130         if ( mbName && mbName->Length() )
       
  2131             {
       
  2132             SetTitlePaneTextL( *mbName );
       
  2133             }
       
  2134         }
       
  2135     CleanupStack::PopAndDestroy( confirmedMailBox );
       
  2136     }
       
  2137 
       
  2138 void CFreestyleEmailUiAppUi::ShowTitlePaneConnectionStatus()
       
  2139     {
       
  2140     FUNC_LOG;
       
  2141     iConnectionStatusVisible = ETrue;
       
  2142     UpdateTitlePaneConnectionStatus(iForcedConnectionStatus);
       
  2143     }
       
  2144 
       
  2145 void CFreestyleEmailUiAppUi::HideTitlePaneConnectionStatus()
       
  2146     {
       
  2147     FUNC_LOG;
       
  2148     iConnectionStatusVisible = EFalse;
       
  2149 	TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
       
  2150 	CEikStatusPaneBase::TPaneCapabilities subPaneTitle =
       
  2151 		StatusPane()->PaneCapabilities( titlePaneUid );
       
  2152 
       
  2153 	if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
       
  2154 		{
       
  2155 		CAknTitlePane* titlePane = NULL;
       
  2156 		TRAP_IGNORE( titlePane =
       
  2157 			(CAknTitlePane*)StatusPane()->ControlL( titlePaneUid ) );
       
  2158 		TRAP_IGNORE( FsTextureManager()->ProvideBitmapL(
       
  2159 		                        EStatusTextureDisconnectedGeneral, iConnectionIconBitmap, iConnectionIconMask ) );
       
  2160 		if ( iConnectionIconBitmap )
       
  2161             {
       
  2162             TSize iconSize = LayoutHandler()->statusPaneIconSize();
       
  2163             AknIconUtils::SetSize( iConnectionIconBitmap, iconSize, EAspectRatioNotPreserved );
       
  2164             }
       
  2165 		titlePane->SetSmallPicture( iConnectionIconBitmap, iConnectionIconMask, iConnectionIconBitmap && iConnectionIconMask);
       
  2166 		}
       
  2167 	iConnectionStatusIconAnimTimer->Stop();
       
  2168     }
       
  2169 
       
  2170 void CFreestyleEmailUiAppUi::UpdateTitlePaneConnectionStatus(
       
  2171 		TForcedStatus aForcedStatus /*= ENoForce*/ )
       
  2172     {
       
  2173     FUNC_LOG;
       
  2174     iForcedConnectionStatus = aForcedStatus;
       
  2175         
       
  2176     if ( iConnectionStatusVisible )
       
  2177     	{
       
  2178     	// Get connection status of the current mailbox
       
  2179     	TFSMailBoxStatus connectionStatus = EFSMailBoxOffline;
       
  2180     	TSSMailSyncState syncState = Idle;
       
  2181 		CFSMailBox* mb = GetActiveMailbox();
       
  2182 		if ( mb )
       
  2183 			{
       
  2184 			connectionStatus = mb->GetMailBoxStatus();
       
  2185 			syncState = mb->CurrentSyncState();
       
  2186 			}
       
  2187 		TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
       
  2188 		CEikStatusPaneBase::TPaneCapabilities subPaneTitle =
       
  2189 			StatusPane()->PaneCapabilities( titlePaneUid );
       
  2190 
       
  2191 		if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
       
  2192 			{
       
  2193 			CAknTitlePane* titlePane = NULL;
       
  2194 			TRAP_IGNORE( titlePane =
       
  2195 				(CAknTitlePane*)StatusPane()->ControlL( titlePaneUid ) );
       
  2196 		
       
  2197 			// Set connection icon
       
  2198 			iConnectionStatusIconAnimTimer->Stop();
       
  2199 			iConnectionIconBitmap = 0;
       
  2200 			iConnectionIconMask = 0;
       
  2201 			TSize iconSize = LayoutHandler()->statusPaneIconSize();
       
  2202 			TBool startTimer = EFalse;
       
  2203 			if ( ( connectionStatus == EFSMailBoxOnline && iForcedConnectionStatus != EForceToDisconnected ) ||
       
  2204 					(iForcedConnectionStatus == EForceToConnected || iForcedConnectionStatus == EForceToSync) )
       
  2205 				{
       
  2206 				if (syncState == EmailSyncing || syncState == InboxSyncing ||
       
  2207 				        syncState == OutboxSyncing || syncState == SentItemsSyncing ||
       
  2208 				        syncState == DraftsSyncing || syncState == CalendarSyncing ||
       
  2209 				        syncState == ContactsSyncing || syncState == TasksSyncing ||
       
  2210 				        syncState == FilesSyncing || iForcedConnectionStatus == EForceToSync )
       
  2211 				    {
       
  2212 				    TRAP_IGNORE( FsTextureManager()->ProvideBitmapL(
       
  2213                         EStatusTextureSynchronising, iConnectionIconBitmap, iConnectionIconMask ) );
       
  2214 				    startTimer = ETrue;
       
  2215 				    }
       
  2216 				else
       
  2217 				    {
       
  2218 				    TRAP_IGNORE( FsTextureManager()->ProvideBitmapL(
       
  2219                         EStatusTextureConnected, iConnectionIconBitmap, iConnectionIconMask ) );
       
  2220 				    }				
       
  2221 				}
       
  2222 			else // EFSMailBoxOffline
       
  2223 				{
       
  2224 				TRAP_IGNORE( FsTextureManager()->ProvideBitmapL(
       
  2225 						EStatusTextureDisconnectedGeneral, iConnectionIconBitmap, iConnectionIconMask ) );
       
  2226 				}
       
  2227 		
       
  2228 			if ( iConnectionIconBitmap )
       
  2229 				{
       
  2230 				AknIconUtils::SetSize( iConnectionIconBitmap, iconSize, EAspectRatioNotPreserved );
       
  2231 				}
       
  2232 			titlePane->SetSmallPicture( iConnectionIconBitmap, iConnectionIconMask, iConnectionIconMask && iConnectionIconBitmap );
       
  2233 			if (startTimer)
       
  2234 			    {
       
  2235 			    iConnectionStatusIconAnimTimer->Start(KConnectionStatusIconRotationInterval);
       
  2236 			    }
       
  2237             titlePane->DrawNow();
       
  2238 			}
       
  2239     	}
       
  2240     }
       
  2241 
       
  2242 void CFreestyleEmailUiAppUi::CreateStatusPaneIndicatorsL()
       
  2243 	{
       
  2244     FUNC_LOG;
       
  2245     // Create custom statuspane with priority and followup indicator support for email editor
       
  2246 	iStatusPaneIndicators = CCustomStatuspaneIndicators::NewL( StatusPane() );
       
  2247     AddToStackL( iStatusPaneIndicators,
       
  2248 				 ECoeStackPriorityDefault,
       
  2249     		     ECoeStackFlagRefusesAllKeys | ECoeStackFlagRefusesFocus );
       
  2250 	}
       
  2251 
       
  2252 void CFreestyleEmailUiAppUi::DeleteStatusPaneIndicators()
       
  2253 	{
       
  2254     FUNC_LOG;
       
  2255 	if ( iStatusPaneIndicators )
       
  2256 		{
       
  2257 		RemoveFromStack( iStatusPaneIndicators );
       
  2258 		delete iStatusPaneIndicators;
       
  2259 		iStatusPaneIndicators = NULL;
       
  2260 		}
       
  2261 	}
       
  2262 
       
  2263 CCustomStatuspaneIndicators* CFreestyleEmailUiAppUi::GetStatusPaneIndicatorContainer()
       
  2264 	{
       
  2265     FUNC_LOG;
       
  2266 	return iStatusPaneIndicators;
       
  2267 	}
       
  2268 
       
  2269 void CFreestyleEmailUiAppUi::StartEndKeyCapture()
       
  2270     {
       
  2271     FUNC_LOG;
       
  2272     if ( !iIsCaptured )
       
  2273         {
       
  2274     	iEndCaptureHandle = iEikonEnv->RootWin().CaptureKey( EStdKeyNo, 0, 0 );
       
  2275     	iEndUpDownCaptureHandle = iEikonEnv->RootWin().CaptureKeyUpAndDowns( EStdKeyNo, 0, 0 );
       
  2276         }
       
  2277 	iIsCaptured = ETrue;
       
  2278     }
       
  2279 
       
  2280 void CFreestyleEmailUiAppUi::StopEndKeyCapture()
       
  2281     {
       
  2282     FUNC_LOG;
       
  2283     if ( iIsCaptured )
       
  2284         {
       
  2285     	iEikonEnv->RootWin().CancelCaptureKey( iEndCaptureHandle );
       
  2286     	iEikonEnv->RootWin().CancelCaptureKeyUpAndDowns( iEndUpDownCaptureHandle );
       
  2287         }
       
  2288 	iIsCaptured = EFalse;
       
  2289     }
       
  2290 
       
  2291 void CFreestyleEmailUiAppUi::CheckUpdatesL()
       
  2292     {
       
  2293     FUNC_LOG;
       
  2294     // Initialize feature manager, if not yet initialized
       
  2295     if( !iFeatureManagerInitialized )
       
  2296         {
       
  2297         FeatureManager::InitializeLibL();  // Successfull call increases reference count!
       
  2298         iFeatureManagerInitialized = ETrue;  // We can now call UnInitializeLib()
       
  2299         }
       
  2300 
       
  2301     // Simple test to check whether we run against API stub or "real" IAD
       
  2302     // implementation. Normal applications should use FeatureManager to check
       
  2303     // whether KFeatureIdIAUpdate is on before using any IAUpdate API function.
       
  2304     if( FeatureManager::FeatureSupported( KFeatureIdIAUpdate ) )
       
  2305         {
       
  2306         TRAP_IGNORE( iUpdateClient = CIAUpdate::NewL( *this ) );
       
  2307         if ( iUpdateClient ) // IAUpdate is supported in the phone
       
  2308             {
       
  2309             iUpdateParameters = CIAUpdateParameters::NewL();
       
  2310             // Search for updates to IAUpdateExampleClient, We know that the
       
  2311             // SIS package uid is KIAParamUid, so let's use that as a
       
  2312             // search criteria.
       
  2313             iUpdateParameters->SetUid( KFSEmailUiUid );
       
  2314             // Free-form search criteria is not supported in
       
  2315             // IAUpdateExampleClient packages.
       
  2316             //iUpdateParameters->SetSearchCriteriaL( KIAParamSearch );
       
  2317             // We want iaupdateexampleclient.exe to be started after update is
       
  2318             // finished
       
  2319             iUpdateParameters->SetCommandLineExecutableL( KFSEmailUiExec );
       
  2320             //iUpdateParameters->SetCommandLineArgumentsL( KIAParamArg );
       
  2321             // We don't want any wait dialog to be shown, let's keep everything
       
  2322             // silent.
       
  2323             // EFalse is the default, so no need to call this.
       
  2324             //iUpdateParameters->SetShowProgress( EFalse );
       
  2325             // Check the updates
       
  2326             iUpdateClient->CheckUpdates( *iUpdateParameters );
       
  2327             }
       
  2328         }
       
  2329     }
       
  2330 
       
  2331 void CFreestyleEmailUiAppUi::CheckUpdatesComplete( TInt aErrorCode, TInt aAvailableUpdates )
       
  2332     {
       
  2333     FUNC_LOG;
       
  2334     if ( aErrorCode == KErrNone )
       
  2335         {
       
  2336         if ( aAvailableUpdates > 0 )
       
  2337             {
       
  2338             // There were some updates available. Let's ask if the user wants to update them.
       
  2339             iUpdateClient->UpdateQuery();
       
  2340             }
       
  2341         else
       
  2342             {
       
  2343             // No updates available. CIAUpdate object should be deleted already now, since we are not
       
  2344             // going to call anything else from the API. This will also close down the IAUpdate server.
       
  2345             AllUpdateActivitiesCompleted();
       
  2346             }
       
  2347          }
       
  2348     }
       
  2349 
       
  2350 void CFreestyleEmailUiAppUi::UpdateQueryComplete( TInt aErrorCode, TBool aUpdateNow )
       
  2351     {
       
  2352     FUNC_LOG;
       
  2353     if ( aErrorCode == KErrNone )
       
  2354         {
       
  2355         if ( aUpdateNow )
       
  2356             {
       
  2357             // User choosed to update now, so let's launch the IAUpdate UI.
       
  2358             iUpdateClient->ShowUpdates( *iUpdateParameters );
       
  2359             }
       
  2360         else
       
  2361             {
       
  2362             // The answer was 'Later'. CIAUpdate object could be deleted already now, since we are not
       
  2363             // going to call anything else from the API. This will also close down the IAUpdate server.
       
  2364             AllUpdateActivitiesCompleted();
       
  2365             }
       
  2366         }
       
  2367     }
       
  2368 
       
  2369 void CFreestyleEmailUiAppUi::UpdateComplete( TInt aErrorCode, CIAUpdateResult* aResult )
       
  2370     {
       
  2371     FUNC_LOG;
       
  2372     if ( aErrorCode == KErrNone )
       
  2373         {
       
  2374         // The update process that the user started from IAUpdate UI is now completed.
       
  2375         // If the client application itself was updated in the update process, this callback
       
  2376         // is never called, since the client is not running anymore.
       
  2377         TInt successCount = aResult->SuccessCount();
       
  2378 
       
  2379         // Should we restart our application somehow if we come here?
       
  2380         // Basically this can happen only when not doing a whole
       
  2381         // update, so e.g. if only some plugin is updated.
       
  2382         }
       
  2383 
       
  2384     delete aResult; // Ownership was transferred, so this must be deleted by the client
       
  2385     // We do not need the client-server session anymore, let's delete the object to close the session
       
  2386     AllUpdateActivitiesCompleted();
       
  2387     }
       
  2388 
       
  2389 void CFreestyleEmailUiAppUi::AllUpdateActivitiesCompleted()
       
  2390     {
       
  2391     FUNC_LOG;
       
  2392     delete iUpdateClient;
       
  2393     iUpdateClient = NULL;
       
  2394     delete iUpdateParameters;
       
  2395     iUpdateParameters = NULL;
       
  2396     iIADUpdateCompleted = ETrue;
       
  2397 
       
  2398     // After completed all update activities, check is there any mailboxes
       
  2399     // defined. If not, show a query to ask if user wants to create one.
       
  2400     TRAP_IGNORE( ShowMailboxQueryL() );
       
  2401     }
       
  2402 
       
  2403 
       
  2404 void CFreestyleEmailUiAppUi::GridStarted( TBool aStartedFromOds )
       
  2405 	{
       
  2406     FUNC_LOG;
       
  2407 	iGridStarted = ETrue;
       
  2408 	if ( aStartedFromOds )
       
  2409 		{
       
  2410 		iGridFirstStartFromOds = ETrue;
       
  2411 		}
       
  2412 	}
       
  2413 
       
  2414 // This is combined show mailbox query that can be displayed either when
       
  2415 // upcate client has finished or when laucnher grid has completed its construction
       
  2416 // Launches async callback so that wizard will not block UI creation.
       
  2417 void CFreestyleEmailUiAppUi::ShowMailboxQueryL()
       
  2418 	{
       
  2419     FUNC_LOG;
       
  2420 	if ( !iStartupQueryShown && iGridStarted && !iGridFirstStartFromOds && iIADUpdateCompleted )
       
  2421 		{
       
  2422 	    RPointerArray<CFSMailBox> mailboxes;
       
  2423 	    CleanupResetAndDestroyClosePushL( mailboxes );
       
  2424 	    TFSMailMsgId id;
       
  2425 	    GetMailClient()->ListMailBoxes( id, mailboxes );
       
  2426 	    if( mailboxes.Count() == 0 && iNewBoxQueryAsyncCallback )
       
  2427 	        {
       
  2428 			iNewBoxQueryAsyncCallback->CallBack();
       
  2429 	        }
       
  2430 	    CleanupStack::PopAndDestroy( &mailboxes );
       
  2431 
       
  2432 		// NULL FLAG, not to be shown again
       
  2433 		iStartupQueryShown = ETrue;
       
  2434 		}
       
  2435 	}
       
  2436 
       
  2437 
       
  2438 // -----------------------------------------------------------------------------
       
  2439 // CFreestyleEmailUiAppUi::DisplayCreateQueryL
       
  2440 // Async callback is needed since the UI and launcher grid construction cannot jam
       
  2441 // if wizard is launched
       
  2442 // -----------------------------------------------------------------------------
       
  2443 TInt CFreestyleEmailUiAppUi::DisplayCreateQueryL( TAny* aSelfPtr )
       
  2444     {
       
  2445     FUNC_LOG;
       
  2446     CFreestyleEmailUiAppUi* self = static_cast<CFreestyleEmailUiAppUi*>( aSelfPtr );
       
  2447     
       
  2448     if (self->AppUiExitOngoing())
       
  2449         {
       
  2450         return KErrNone;
       
  2451         }
       
  2452 
       
  2453     if (self->iMainUiGridVisualiser)
       
  2454         {
       
  2455         if (self->iMainUiGridVisualiser->UiOperationLaunched())
       
  2456             {
       
  2457             return KErrNone;
       
  2458             }
       
  2459         }
       
  2460     
       
  2461     TRAPD( err, self->DisplayCreateMailboxQueryL() );
       
  2462     
       
  2463     if (err == KLeaveExit)
       
  2464         {
       
  2465         User::Leave(err);
       
  2466         }
       
  2467     
       
  2468     return err;
       
  2469     }
       
  2470 
       
  2471 void CFreestyleEmailUiAppUi::DisplayCreateMailboxQueryL()
       
  2472 	{
       
  2473     FUNC_LOG;
       
  2474     if ( TFsEmailUiUtility::ShowConfirmationQueryL( R_FS_EMAIL_SETTINGS_ADD_MAILBOX_TXT ) )
       
  2475     	{
       
  2476         // Launch wizard if user selected Yes to create new mailbox query
       
  2477         LaunchWizardL();
       
  2478 	    }
       
  2479 	}
       
  2480 
       
  2481 // -----------------------------------------------------------------------------
       
  2482 // CFreestyleEmailUiAppUi::SendToBackgroundL
       
  2483 // Send self to background.
       
  2484 // -----------------------------------------------------------------------------
       
  2485 void CFreestyleEmailUiAppUi::SendToBackground()
       
  2486     {
       
  2487     FUNC_LOG;
       
  2488 
       
  2489     TApaTaskList taskList( iEikonEnv->WsSession() );
       
  2490     TApaTask task = taskList.FindApp( KFSEmailUiUid );
       
  2491     if ( task.Exists() )
       
  2492         {
       
  2493         // Send self to background
       
  2494         task.SendToBackground(); 
       
  2495         }
       
  2496 
       
  2497     iSwitchingToBackground = EFalse;
       
  2498     }
       
  2499 
       
  2500 // -----------------------------------------------------------------------------
       
  2501 // 
       
  2502 // -----------------------------------------------------------------------------
       
  2503 void CFreestyleEmailUiAppUi::ConstructNaviPaneL()
       
  2504     {
       
  2505     FUNC_LOG;
       
  2506 
       
  2507     CAknNavigationControlContainer* naviPaneContainer = 
       
  2508         static_cast<CAknNavigationControlContainer*>( 
       
  2509         StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
  2510 
       
  2511     // Following navipane is for mailviewer view
       
  2512     if ( !iNaviDecorator2MailViewer )
       
  2513         {
       
  2514         // Constructing a decorator with own decorated control,
       
  2515         // which is (currently an empty) container.
       
  2516         CFreestyleEmailUiNaviPaneControlContainer2MailViewer* c = 
       
  2517             CFreestyleEmailUiNaviPaneControlContainer2MailViewer::NewL();
       
  2518         c->SetContainerWindowL( *naviPaneContainer );
       
  2519         iNaviDecorator2MailViewer = CAknNavigationDecorator::NewL(
       
  2520             naviPaneContainer,
       
  2521             c, 
       
  2522             CAknNavigationDecorator::ENotSpecified );
       
  2523         
       
  2524         // In order to get navi arrows visible, they must be set visible AND not dimmed...
       
  2525         iNaviDecorator2MailViewer->SetContainerWindowL( *naviPaneContainer );
       
  2526         iNaviDecorator2MailViewer->MakeScrollButtonVisible( ETrue );
       
  2527         iNaviDecorator2MailViewer->SetScrollButtonDimmed( CAknNavigationDecorator::ELeftButton, EFalse );
       
  2528         iNaviDecorator2MailViewer->SetScrollButtonDimmed( CAknNavigationDecorator::ERightButton, EFalse );
       
  2529         
       
  2530         iNaviDecorator2MailViewer->SetComponentsToInheritVisibility( ETrue );
       
  2531         naviPaneContainer->PushL( *iNaviDecorator2MailViewer );
       
  2532         }
       
  2533     }
       
  2534 
       
  2535 // -----------------------------------------------------------------------------
       
  2536 // 
       
  2537 // -----------------------------------------------------------------------------
       
  2538 CAknNavigationDecorator* CFreestyleEmailUiAppUi::NaviDecoratorL(  const TUid aViewId  )
       
  2539     {
       
  2540     FUNC_LOG;
       
  2541     CAknNavigationDecorator* decorator( NULL );
       
  2542     // Depending on who's asking, return proper navipane instance
       
  2543     if ( aViewId.iUid == MailViewerId.iUid )
       
  2544         {
       
  2545         if ( !iNaviDecorator2MailViewer )
       
  2546             {
       
  2547             ConstructNaviPaneL();
       
  2548             }
       
  2549         decorator = iNaviDecorator2MailViewer;
       
  2550         }
       
  2551     return decorator;
       
  2552     }
       
  2553 
       
  2554 void CFreestyleEmailUiAppUi::TimerEventL( CFSEmailUiGenericTimer* aTriggeredTimer )
       
  2555     {
       
  2556     if (aTriggeredTimer == iConnectionStatusIconAnimTimer)
       
  2557         {
       
  2558         if ( iConnectionStatusVisible )
       
  2559             {
       
  2560             TUid titlePaneUid = TUid::Uid( EEikStatusPaneUidTitle );
       
  2561             CEikStatusPaneBase::TPaneCapabilities subPaneTitle =
       
  2562                 StatusPane()->PaneCapabilities( titlePaneUid );
       
  2563 
       
  2564             if ( subPaneTitle.IsPresent() && subPaneTitle.IsAppOwned() )
       
  2565                 {
       
  2566                 CAknTitlePane* titlePane = NULL;
       
  2567                 TRAP_IGNORE( titlePane =
       
  2568                     (CAknTitlePane*)StatusPane()->ControlL( titlePaneUid ) );
       
  2569                 
       
  2570                 TSize iconSize = LayoutHandler()->statusPaneIconSize();
       
  2571                 iConnectionStatusIconAngle += KConnectionStatusIconRotationAmount;
       
  2572                 AknIconUtils::SetSizeAndRotation(iConnectionIconBitmap, iconSize, EAspectRatioNotPreserved, iConnectionStatusIconAngle);
       
  2573                 titlePane->DrawNow();
       
  2574                 iConnectionStatusIconAnimTimer->Start(KConnectionStatusIconRotationInterval);
       
  2575                 }
       
  2576             }
       
  2577         }
       
  2578     }
       
  2579 
       
  2580 // -----------------------------------------------------------------------------
       
  2581 // CFreestyleEmailUiAppUi::CancelFocusRemovalTimer
       
  2582 // -----------------------------------------------------------------------------
       
  2583 
       
  2584 void CFreestyleEmailUiAppUi::CancelFocusRemovalTimer()
       
  2585 	{
       
  2586 	TBool wasActive = iFocusTimer->IsActive();
       
  2587 	iFocusTimer->Cancel();
       
  2588 
       
  2589 	CFsEmailUiViewBase* activeView = CurrentActiveView();
       
  2590 	if( wasActive && activeView )
       
  2591 		{
       
  2592 		activeView->HandleTimerFocusStateChange( EFalse );
       
  2593 		}
       
  2594 	}
       
  2595 
       
  2596 // -----------------------------------------------------------------------------
       
  2597 // CFreestyleEmailUiAppUi::StartFocusRemovalTimer
       
  2598 // -----------------------------------------------------------------------------
       
  2599 
       
  2600 TBool CFreestyleEmailUiAppUi::StartFocusRemovalTimer()
       
  2601 	{
       
  2602 	TBool wasActive = iFocusTimer->IsActive();
       
  2603 	iFocusTimer->Cancel();
       
  2604 	// Start the timer and calls FocusTimerCallBack when the timer expires
       
  2605 	iFocusTimer->Start(KIdleTimeInterval, KIdleTimeInterval,
       
  2606 			TCallBack(FocusTimerCallBack, this));
       
  2607 	
       
  2608 	CFsEmailUiViewBase* activeView = CurrentActiveView();
       
  2609 	if ( !wasActive && activeView )
       
  2610 		{
       
  2611 		activeView->HandleTimerFocusStateChange( ETrue );
       
  2612 		}
       
  2613 	
       
  2614 	return wasActive;
       
  2615 	}
       
  2616 
       
  2617 // -----------------------------------------------------------------------------
       
  2618 // 
       
  2619 // -----------------------------------------------------------------------------
       
  2620 TInt CFreestyleEmailUiAppUi::FocusTimerCallBack(TAny* aAny)
       
  2621 	{
       
  2622 	CFreestyleEmailUiAppUi* self = 
       
  2623 		static_cast<CFreestyleEmailUiAppUi*>( aAny );
       
  2624  
       
  2625 	return self->DoFocusTimerCallBack();
       
  2626 	}
       
  2627 // -----------------------------------------------------------------------------
       
  2628 // 
       
  2629 // -----------------------------------------------------------------------------
       
  2630 TInt CFreestyleEmailUiAppUi::DoFocusTimerCallBack()
       
  2631 	{
       
  2632 	iFocusTimer->Cancel();
       
  2633 	CFsEmailUiViewBase* activeView = CurrentActiveView();
       
  2634 		
       
  2635 	// Call the HandleTimerFocusStateChange of currently active so that it hides
       
  2636 	// its focus.
       
  2637 	if ( activeView )
       
  2638 		{
       
  2639 		activeView->HandleTimerFocusStateChange( EFalse );
       
  2640 		}
       
  2641 	
       
  2642 	return KErrNone;
       
  2643 	}
       
  2644 
       
  2645 // -----------------------------------------------------------------------------
       
  2646 // 
       
  2647 // -----------------------------------------------------------------------------
       
  2648 TBool CFreestyleEmailUiAppUi::IsTimerFocusShown() const
       
  2649 	{
       
  2650 	return iFocusTimer->IsActive();
       
  2651 	}
       
  2652 
       
  2653 
       
  2654 // PUBLIC METHODS FROM MFREESTYLEEMAILUIPROPERTYCHANGEDOBSERVER 
       
  2655 
       
  2656 // -----------------------------------------------------------------------------
       
  2657 // From MFreestyleEmailUiPropertyChangedObserver.
       
  2658 // -----------------------------------------------------------------------------
       
  2659 //
       
  2660 void CFreestyleEmailUiAppUi::PropertyChangedL( TInt aValue )
       
  2661 	{
       
  2662 	EPSHWRMFlipStatus flipStatus = ( EPSHWRMFlipStatus )aValue;
       
  2663 
       
  2664     if( flipStatus == EPSHWRMFlipOpen )
       
  2665          {
       
  2666          iFlipOpen = ETrue;
       
  2667          }
       
  2668      else
       
  2669          {
       
  2670          iFlipOpen = EFalse;
       
  2671          }
       
  2672 	
       
  2673 	CFsEmailUiViewBase* activeView = CurrentActiveView();
       
  2674 	if ( activeView )
       
  2675 		{
       
  2676 		activeView->FlipStateChangedL( iFlipOpen );
       
  2677 		}
       
  2678 	}
       
  2679 
       
  2680 
       
  2681 
       
  2682 ////////////////////////////////////////////////////////////////////////////////
       
  2683 //
       
  2684 /////////////////////////////////////////////////////////////////////////////////
       
  2685 // -----------------------------------------------------------------------------
       
  2686 // CFSEmailUiAutosyncMonitor::CFSEmailUiAutosyncMonitor
       
  2687 // C++ default constructor can NOT contain any code, that
       
  2688 // might leave.
       
  2689 // -----------------------------------------------------------------------------
       
  2690 //
       
  2691 CFSEmailUiAutosyncMonitor::CFSEmailUiAutosyncMonitor( CFreestyleEmailUiAppUi& aAppUi ) :
       
  2692     CActive( CActive::EPriorityStandard ),
       
  2693     iMonitoringStatus( EInactive ),
       
  2694     iAppUi( aAppUi ),
       
  2695     iRegisterationStatus( RMobilePhone::ERegistrationUnknown )
       
  2696     {
       
  2697     FUNC_LOG;
       
  2698     }
       
  2699 
       
  2700 
       
  2701 // -----------------------------------------------------------------------------
       
  2702 // CCMRegistrationMonitor::ConstructL
       
  2703 // Symbian 2nd phase constructor can leave.
       
  2704 // -----------------------------------------------------------------------------
       
  2705 //
       
  2706 void CFSEmailUiAutosyncMonitor::ConstructL()
       
  2707     {
       
  2708     FUNC_LOG;
       
  2709     User::LeaveIfError( iServer.Connect() );
       
  2710     User::LeaveIfError( iServer.LoadPhoneModule( KPhoneModuleName ) );
       
  2711     iServer.SetExtendedErrorGranularity( RTelServer::EErrorBasic );
       
  2712     User::LeaveIfError( iPhone.Open( iServer, KPhoneName ) );
       
  2713     CActiveScheduler::Add(this);
       
  2714     }
       
  2715 
       
  2716 // -----------------------------------------------------------------------------
       
  2717 // CFSEmailUiAutosyncMonitor::NewL
       
  2718 // Two-phased constructor.
       
  2719 // -----------------------------------------------------------------------------
       
  2720 //
       
  2721 CFSEmailUiAutosyncMonitor* CFSEmailUiAutosyncMonitor::NewL( CFreestyleEmailUiAppUi& aAppUi )
       
  2722     {
       
  2723     FUNC_LOG;
       
  2724     CFSEmailUiAutosyncMonitor* self = new( ELeave ) CFSEmailUiAutosyncMonitor( aAppUi );
       
  2725     CleanupStack::PushL( self );
       
  2726     self->ConstructL();
       
  2727     CleanupStack::Pop();
       
  2728     return self;
       
  2729     }
       
  2730 
       
  2731 // Destructor
       
  2732 CFSEmailUiAutosyncMonitor::~CFSEmailUiAutosyncMonitor()
       
  2733     {
       
  2734     FUNC_LOG;
       
  2735     if( IsActive() )
       
  2736         {
       
  2737         Cancel();
       
  2738         }
       
  2739     iPhone.Close();
       
  2740     iServer.Close();
       
  2741     }
       
  2742 
       
  2743 
       
  2744 // -----------------------------------------------------------------------------
       
  2745 // CCMRegistrationMonitor::StartMonitoring()
       
  2746 // Starts monitoring of the network registeration status
       
  2747 // (other items were commented in a header).
       
  2748 // -----------------------------------------------------------------------------
       
  2749 //
       
  2750 void CFSEmailUiAutosyncMonitor::StartMonitoring()
       
  2751     {
       
  2752     FUNC_LOG;
       
  2753     if ( IsActive() )
       
  2754         {
       
  2755         Cancel();
       
  2756         }
       
  2757 #ifdef __WINS__ // do not try to connect on the emulator
       
  2758     iRegisterationStatus = RMobilePhone::ERegisteredOnHomeNetwork;
       
  2759     TRequestStatus* status = &iStatus;
       
  2760     User::RequestComplete( status, KErrNone );
       
  2761 #else
       
  2762     iPhone.GetNetworkRegistrationStatus( iStatus, iRegisterationStatus );
       
  2763 #endif
       
  2764     iMonitoringStatus = ERequestingNetworkStatus;
       
  2765     SetActive();
       
  2766     }
       
  2767 
       
  2768 // -----------------------------------------------------------------------------
       
  2769 // CFSEmailUiAutosyncMonitor::StopMonitoring()
       
  2770 // Stops the registeration monitor
       
  2771 // (other items were commented in a header).
       
  2772 // -----------------------------------------------------------------------------
       
  2773 //
       
  2774 void CFSEmailUiAutosyncMonitor::StopMonitoring()
       
  2775     {
       
  2776     FUNC_LOG;
       
  2777     if ( IsActive() )
       
  2778         {
       
  2779         Cancel();
       
  2780         }
       
  2781     }
       
  2782 
       
  2783 // -----------------------------------------------------------------------------
       
  2784 // CFSEmailUiAutosyncMonitor::DoCancel()
       
  2785 // Cancels the monitoring
       
  2786 // (other items were commented in a header).
       
  2787 // -----------------------------------------------------------------------------
       
  2788 //
       
  2789 void CFSEmailUiAutosyncMonitor::DoCancel()
       
  2790     {
       
  2791     FUNC_LOG;
       
  2792     iPhone.CancelAsyncRequest( EMobilePhoneGetNetworkRegistrationStatus );
       
  2793     }
       
  2794 
       
  2795 TInt CFSEmailUiAutosyncMonitor::RunError( TInt /*aError*/ )
       
  2796     {
       
  2797     FUNC_LOG;
       
  2798     return KErrNone;
       
  2799     }
       
  2800 
       
  2801 // -----------------------------------------------------------------------------
       
  2802 // CFSEmailUiAutosyncMonitor::RunL()
       
  2803 // Handles object’s request completion event
       
  2804 // (other items were commented in a header).
       
  2805 // -----------------------------------------------------------------------------
       
  2806 //
       
  2807 void CFSEmailUiAutosyncMonitor::RunL()
       
  2808     {
       
  2809     FUNC_LOG;
       
  2810     switch ( iMonitoringStatus )
       
  2811         {
       
  2812         case ERequestingNetworkStatus:
       
  2813            {
       
  2814             switch( iRegisterationStatus )
       
  2815                 {
       
  2816                 // Not Ok cases
       
  2817                 case RMobilePhone::ERegistrationUnknown:
       
  2818                 case RMobilePhone::ENotRegisteredNoService:
       
  2819                 case RMobilePhone::ENotRegisteredEmergencyOnly:
       
  2820                 case RMobilePhone::ENotRegisteredSearching:
       
  2821                 case RMobilePhone::ERegisteredBusy:
       
  2822                 case RMobilePhone::ERegistrationDenied:
       
  2823                 case RMobilePhone::ERegisteredRoaming:
       
  2824                 	// No autoconnect in these cases
       
  2825                     break;
       
  2826                 // This is ok
       
  2827                 case RMobilePhone::ERegisteredOnHomeNetwork:
       
  2828 					// TRAP autoconnect, because list UI must open regardless success
       
  2829 					// or failure of the auto-connect
       
  2830                 	TRAP_IGNORE( iAppUi.DoAutoConnectL() );
       
  2831                     break;
       
  2832                 default:
       
  2833                     break;
       
  2834                 }
       
  2835             break;
       
  2836             }
       
  2837         default:
       
  2838             break;
       
  2839         }
       
  2840     }
       
  2841 
       
  2842 // End of file
       
  2843