emailuis/emailui/src/FreestyleEmailUiMailListVisualiser.cpp
branchRCL_3
changeset 25 3533d4323edc
child 26 968773a0b6ef
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2009 - 2010 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: This file implements classes CFSEmailUiMailListVisualiser, CMailListUpdater, CMsgMovedNoteTimer, CDateChangeTimer.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDES
       
    20 #include "emailtrace.h"
       
    21 #include <freestyleemailui.mbg>
       
    22 #include <AknUtils.h>
       
    23 #include <gulicon.h>
       
    24 #include <StringLoader.h>
       
    25 #include <FreestyleEmailUi.rsg>
       
    26 #include <featmgr.h>
       
    27 #include "cfsmailclient.h"
       
    28 #include "cfsmailbox.h"
       
    29 #include "cfsmailfolder.h"
       
    30 #include "fscontrolbar.h"
       
    31 #include "fscontrolbuttoninterface.h"
       
    32 #include "fstreelist.h"
       
    33 #include "fstreevisualizerbase.h"
       
    34 #include "fstreeplainonelinenodedata.h"
       
    35 #include "fstreeplainonelinenodevisualizer.h"
       
    36 #include "fstreeplaintwolineitemdata.h"
       
    37 #include "fstreeplaintwolineitemvisualizer.h"
       
    38 #include "cfsmailcommon.h"
       
    39 #include "ceuiemaillisttouchmanager.h"
       
    40 #include "FSEmailBuildFlags.h"
       
    41 #include "cfsccontactactionmenu.h"
       
    42 #include "mfsccontactactionmenumodel.h"
       
    43 
       
    44 #include <hlplch.h>
       
    45 #include <AknIconArray.h>
       
    46 #include <alf/alfdecklayout.h>
       
    47 #include <alf/alfcontrolgroup.h>
       
    48 #include <alf/alfframebrush.h>
       
    49 #include <alf/alfevent.h>
       
    50 #include <alf/alfstatic.h>
       
    51 
       
    52 #include <aknnotewrappers.h>
       
    53 #include <msvapi.h>
       
    54 #include <akntitle.h>
       
    55 #include "esmailsettingspluginuids.hrh"
       
    56 #include "esmailsettingsplugin.h"
       
    57 #include "mfsmailbrandmanager.h"
       
    58 #include <AknWaitDialog.h>
       
    59 #include <aknlayoutscalable_apps.cdl.h>
       
    60 #include <aknlayoutscalable_avkon.cdl.h>
       
    61 #include <layoutmetadata.cdl.h>
       
    62 #include <csxhelp/cmail.hlp.hrh>
       
    63 // Meeting request
       
    64 #include <MeetingRequestUids.hrh>
       
    65 #include "cesmricalviewer.h"
       
    66 #include <aknstyluspopupmenu.h>
       
    67 #include <akntoolbar.h>
       
    68 
       
    69 // INTERNAL INCLUDES
       
    70 #include "FreestyleEmailUiUtilities.h"
       
    71 #include "FreestyleEmailUiLiterals.h"
       
    72 #include "FreestyleEmailUiLayoutHandler.h"
       
    73 #include "FreestyleEmailUiMailListModel.h"
       
    74 #include "FreestyleEmailUiMailListVisualiser.h"
       
    75 #include "FreestyleEmailUiFileSystemInfo.h"
       
    76 #include "FreestyleEmailUiAppui.h"
       
    77 #include "FreestyleEmailUi.hrh"
       
    78 #include "FreestyleEmailUiTextureManager.h"
       
    79 #include "FreestyleEmailUiMailListControl.h"
       
    80 #include "FreestyleEmailUiStatusIndicator.h"
       
    81 #include "freestyleemailcenrephandler.h"
       
    82 #include "FreestyleEmailUiFolderListVisualiser.h"
       
    83 #include "FreestyleEmailUiShortcutBinding.h"
       
    84 #include "FreestyleEmailUiMsgDetailsVisualiser.h"
       
    85 #include "FreestyleEmailDownloadInformationMediator.h"
       
    86 #include "FreestyleEmailUiContactHandler.h"
       
    87 #include "FreestyleEmailUiLauncherGridVisualiser.h"
       
    88 #include "FreestyleEmailUiHtmlViewerView.h"
       
    89 #include "FSDelayedLoader.h"
       
    90 #include "FSEmail.pan"
       
    91 
       
    92 #include "ipsplgcommon.h"
       
    93 #include "cemailsettingsextension.h"
       
    94 
       
    95 // CONST VALUES
       
    96 const TInt KControlBarTransitionTime = 250;
       
    97 const TInt KMaxPreviewPaneLength = 60;
       
    98 const TInt KMsgUpdaterTimerDelay = 2500000; // Time to update list, 2,5sec
       
    99 const TInt KNewMailTimerDelay = 20; // sleeping timer to start processing new messages
       
   100 const TInt KSortTimerDelay = 40;    // sleeping timer to start sorting ( delay should be longer than abowe )
       
   101 const TInt KSortCountdown = 5;      // number how many times will be tried do start sorting when it's forbidden
       
   102 const TInt KNewMailMaxBatch = 7;    // number of new mails inserted into list at once
       
   103 static const TInt KMsgDeletionWaitNoteAmount = 5;
       
   104 _LIT( KMissingPreviewDataMarker, "..." );
       
   105 
       
   106 static const TInt KMaxItemsFethed = 1000;
       
   107 static const TInt KCMsgBlock = 15;
       
   108 static const TInt KCMsgBlockSort = 50;
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // Generic method for deleting a pointer and setting it NULL.
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 template <class T> void SafeDelete(T*& ptr)
       
   115     {
       
   116     delete ptr;
       
   117     ptr = NULL;
       
   118     }
       
   119 
       
   120 // TDeleteTask
       
   121 // Task class for deleting mail
       
   122 // ---------------------------------------------------------------------------
       
   123 // Class definition
       
   124 // ---------------------------------------------------------------------------
       
   125 template <class T> struct TDeleteTask
       
   126     {
       
   127     
       
   128 public:
       
   129     
       
   130     typedef void ( T::*TDeleteMethod )( const RFsTreeItemIdList& aEntries );
       
   131     
       
   132 public:    
       
   133     
       
   134     TDeleteTask(T& aObject, TDeleteMethod aMethod);    
       
   135     ~TDeleteTask();
       
   136     void ExecuteL();
       
   137     RFsTreeItemIdList& Entries();
       
   138     void Reset();
       
   139     
       
   140 private:
       
   141 
       
   142     T& iObject;
       
   143     TDeleteMethod iMethod;    
       
   144     RFsTreeItemIdList iEntries;
       
   145     
       
   146     };
       
   147 
       
   148 // ---------------------------------------------------------------------------
       
   149 // TDeleteTask<T>::TDeleteTask
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 template <class T> TDeleteTask<T>::TDeleteTask( T& aObject, TDeleteMethod aMethod )
       
   153     : iObject(aObject), iMethod(aMethod)
       
   154     {    
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // TDeleteTask<T>::~TDeleteTask
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 template <class T> TDeleteTask<T>::~TDeleteTask()
       
   162     {
       
   163     iEntries.Close();
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // TDeleteTask<T>::ExecuteL
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 template <class T> void TDeleteTask<T>::ExecuteL()
       
   171     {
       
   172     (iObject.*iMethod)(iEntries);
       
   173     Reset();
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // TDeleteTask<T>::Entries
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 template <class T> RFsTreeItemIdList& TDeleteTask<T>::Entries()
       
   181     {
       
   182     return iEntries;
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // TDeleteTask<T>::Reset
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 template <class T> void TDeleteTask<T>::Reset()
       
   190     {
       
   191     iEntries.Reset();
       
   192     }
       
   193 
       
   194 
       
   195 // CMailListModelUpdater
       
   196 
       
   197 
       
   198 // ---------------------------------------------------------------------------
       
   199 // CMailListModelUpdater::NewL
       
   200 // ---------------------------------------------------------------------------
       
   201 //
       
   202 CMailListModelUpdater* CMailListModelUpdater::NewL()
       
   203     {
       
   204     CMailListModelUpdater* self = new (ELeave) CMailListModelUpdater();
       
   205     CleanupStack::PushL( self );
       
   206     self->ConstructL();
       
   207     CleanupStack::Pop( self );
       
   208 
       
   209     return self;
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CMailListModelUpdater::ConstructL
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CMailListModelUpdater::ConstructL()
       
   217     {
       
   218     User::LeaveIfError( iTimer.CreateLocal() );
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CMailListModelUpdater::CMailListModelUpdater
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 CMailListModelUpdater::CMailListModelUpdater() : CActive(EPriorityStandard)
       
   226     {
       
   227     CActiveScheduler::Add(this);
       
   228     iBlockSize = KCMsgBlock;
       
   229     }
       
   230 
       
   231 // ---------------------------------------------------------------------------
       
   232 // CMailListModelUpdater::~CMailListModelUpdater
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 CMailListModelUpdater::~CMailListModelUpdater()
       
   236     {
       
   237     iObserver = NULL;
       
   238     Cancel();
       
   239     iSorting.Close();
       
   240     iTimer.Close();
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // Returns arrays for sorting parameters. Updater owns the arrays because
       
   245 // it has to stay alive as long as the iterator is being used.
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 RArray<TFSMailSortCriteria>& CMailListModelUpdater::Sorting()
       
   249     {
       
   250     iSorting.Reset();
       
   251     return iSorting;
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // Update the mail list model from given iterator. Update progress will be
       
   256 // informed to the observer.
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 void CMailListModelUpdater::UpdateModelL(MObserver& aObserver, 
       
   260                                          MFSMailIterator* aIterator, TInt aBlockSize)
       
   261     {
       
   262     Cancel();
       
   263     iObserver = &aObserver;
       
   264     iIterator = aIterator;
       
   265     Signal(EInitialize);
       
   266     iBlockSize = aBlockSize;
       
   267     }
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // Internal method. Sets new state and signals itself.
       
   271 // ---------------------------------------------------------------------------
       
   272 //
       
   273 void CMailListModelUpdater::Signal(TState aState, TInt /*aError*/)
       
   274     {
       
   275     const TInt KDelayInMicroSeconds = 5 * 1000; // 5 ms
       
   276     
       
   277     // timer used to get CAknWaitDialog animation working
       
   278     iState = aState;
       
   279     iTimer.After(iStatus, KDelayInMicroSeconds);
       
   280     SetActive();
       
   281     
       
   282     
       
   283     //iState = aState;
       
   284     //iStatus = KRequestPending;
       
   285     //SetActive();
       
   286     //TRequestStatus* status = &iStatus;
       
   287     //User::RequestComplete(status, aError);
       
   288     }
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // Initialization state. Reset update and call UpdateBeginL() for the observer.
       
   292 // ---------------------------------------------------------------------------
       
   293 //
       
   294 void CMailListModelUpdater::InitializeL()
       
   295     {
       
   296     iParentId = KFsTreeRootID;
       
   297     iId = TFSMailMsgId();
       
   298     iItemsFetched = 0;
       
   299     iObserver->UpdateBeginL();
       
   300     Signal(EFetch);
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // Fetch state. Fetch next messages and if there is more messages signal
       
   305 // fetch state again OR proceed to finalizing state.
       
   306 // ---------------------------------------------------------------------------
       
   307 //
       
   308 void CMailListModelUpdater::FetchL()
       
   309     {
       
   310     TInt blockSize = iBlockSize;
       
   311     if ( iItemsFetched == 0 )
       
   312         {
       
   313         blockSize = KCMsgBlock;
       
   314         }
       
   315 
       
   316     RPointerArray<CFSMailMessage> messages(blockSize);
       
   317     CleanupClosePushL(messages);
       
   318    
       
   319     const TBool moreMessages(iIterator->NextL(iId, blockSize, messages));
       
   320 
       
   321     if (messages.Count() > 0)
       
   322         {
       
   323         iItemsFetched += messages.Count();
       
   324         iId = messages[messages.Count() - 1]->GetMessageId();
       
   325         iObserver->UpdateProgressL(iParentId, messages);
       
   326         }
       
   327     
       
   328     CleanupStack::PopAndDestroy(); // messages.Close()
       
   329     
       
   330     if (moreMessages && iItemsFetched < KMaxItemsFethed)
       
   331         {
       
   332         Signal(EFetch);
       
   333         }
       
   334     else
       
   335         {
       
   336         Signal(EFinalize);
       
   337         }
       
   338     }
       
   339 
       
   340 // ---------------------------------------------------------------------------
       
   341 // Finalizing state. Notify observer that model update has been done and
       
   342 // free the resources.
       
   343 // ---------------------------------------------------------------------------
       
   344 //
       
   345 void CMailListModelUpdater::FinalizeL()
       
   346     {
       
   347     iObserver->UpdateCompleteL();
       
   348     Reset();
       
   349     }
       
   350 
       
   351 // ---------------------------------------------------------------------------
       
   352 // If the state is anything but EIdle, returns ETrue.
       
   353 // ---------------------------------------------------------------------------
       
   354 //
       
   355 TBool CMailListModelUpdater::IsUpdating() const
       
   356     {
       
   357     return iState > EIdle;
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // Reset the state to EIdle and free resources.
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 void CMailListModelUpdater::Reset()
       
   365     {
       
   366     iSorting.Reset();
       
   367     SafeDelete(iIterator);
       
   368     iState = EIdle;
       
   369     }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // Active objects RunL()
       
   373 // ---------------------------------------------------------------------------
       
   374 //
       
   375 void CMailListModelUpdater::RunL()
       
   376     {
       
   377     const TInt error(iStatus.Int());
       
   378     if (!error)
       
   379         {
       
   380         switch (iState)
       
   381             {
       
   382             case EInitialize:
       
   383                 InitializeL();
       
   384                 break;
       
   385             case EFetch:
       
   386                 FetchL();
       
   387                 break;
       
   388             case EFinalize:
       
   389             default:
       
   390                 FinalizeL();
       
   391                 break;
       
   392             }
       
   393         }
       
   394     else
       
   395         {
       
   396         User::Leave(error);  // causes RunError to be called
       
   397         }
       
   398     }
       
   399 
       
   400 // ---------------------------------------------------------------------------
       
   401 // Update has been cancelled. Inform the observer and free resources.
       
   402 // ---------------------------------------------------------------------------
       
   403 //
       
   404 void CMailListModelUpdater::DoCancel()
       
   405     {
       
   406     if (iObserver)
       
   407         {
       
   408         iObserver->UpdateCancelled(IsUpdating());
       
   409         }
       
   410     Reset();
       
   411     
       
   412     iTimer.Cancel();
       
   413     }
       
   414 // ---------------------------------------------------------------------------
       
   415 // CMailListModelUpdater::RunError
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 TInt CMailListModelUpdater::RunError(TInt aError)
       
   419     {
       
   420     if ( aError != KErrNone )
       
   421         {
       
   422         TRAP_IGNORE( iObserver->UpdateErrorL( aError ) );
       
   423         }
       
   424     
       
   425     return aError;
       
   426     }
       
   427 
       
   428 
       
   429 
       
   430 
       
   431 
       
   432 // ---------------------------------------------------------------------------
       
   433 // Static constructor.
       
   434 // ---------------------------------------------------------------------------
       
   435 //
       
   436 CFSEmailUiMailListVisualiser* CFSEmailUiMailListVisualiser::NewL(CAlfEnv& aEnv,
       
   437 																 CFreestyleEmailUiAppUi* aAppUi,
       
   438 																 CAlfControlGroup& aMailListControlGroup )
       
   439     {
       
   440     FUNC_LOG;
       
   441     CFSEmailUiMailListVisualiser* self = CFSEmailUiMailListVisualiser::NewLC(aEnv, aAppUi, aMailListControlGroup );
       
   442     CleanupStack::Pop(self);
       
   443     return self;
       
   444     }
       
   445 
       
   446 // ---------------------------------------------------------------------------
       
   447 // Static constructor.
       
   448 // ---------------------------------------------------------------------------
       
   449 //
       
   450 CFSEmailUiMailListVisualiser* CFSEmailUiMailListVisualiser::NewLC(CAlfEnv& aEnv,
       
   451 																  CFreestyleEmailUiAppUi* aAppUi,
       
   452 																  CAlfControlGroup& aMailListControlGroup)
       
   453     {
       
   454     FUNC_LOG;
       
   455     CFSEmailUiMailListVisualiser* self =
       
   456         new (ELeave) CFSEmailUiMailListVisualiser( aEnv, aAppUi, aMailListControlGroup );
       
   457     CleanupStack::PushL( self );
       
   458     self->ConstructL();
       
   459     return self;
       
   460     }
       
   461 
       
   462 // ---------------------------------------------------------------------------
       
   463 // Second phase constructor.
       
   464 // ---------------------------------------------------------------------------
       
   465 //
       
   466 void CFSEmailUiMailListVisualiser::ConstructL()
       
   467 	{
       
   468     FUNC_LOG;
       
   469 
       
   470 	BaseConstructL( R_FSEMAILUI_MAIL_LIST_VIEW );
       
   471 
       
   472 	iMailListModelUpdater = CMailListModelUpdater::NewL();
       
   473 
       
   474 	// Don't construct this anywhere else than here.
       
   475 	// Don't delete this until in the destructor to avoid NULL checks.
       
   476     iModel = CFSEmailUiMailListModel::NewL( &iAppUi );
       
   477 
       
   478 	// Set list as initial focused control
       
   479 	iFocusedControl = EMailListComponent;
       
   480 	iThisViewActive = EFalse;
       
   481 	iSkinChanged = EFalse;
       
   482 
       
   483 	iFirstStartCompleted = EFalse;
       
   484 
       
   485 	iAsyncCallback = new (ELeave) CAsyncCallBack( CActive::EPriorityStandard );
       
   486 	iAsyncRedrawer = new (ELeave) CAsyncCallBack( CActive::EPriorityLow );
       
   487 	iLastFocus = EFalse;
       
   488     iDeleteTask = new (ELeave) TDeleteTask<CFSEmailUiMailListVisualiser> (*this, HandleDeleteTaskL);
       
   489 
       
   490     iNewMailTimer = CFSEmailUiGenericTimer::NewL( this );
       
   491     iSortTimer = CFSEmailUiGenericTimer::NewL( this );
       
   492     iSortState = ESortNone;
       
   493 
       
   494 	iTouchFeedBack = MTouchFeedback::Instance();
       
   495  	}
       
   496 
       
   497 // ---------------------------------------------------------------------------
       
   498 // Second phase constructor.
       
   499 // ---------------------------------------------------------------------------
       
   500 //
       
   501 // CFSEmailUiMailListVisualiser::DoFirstStartL()
       
   502 // Purpose of this function is to do first start things only when list is
       
   503 // really needed to be shown. Implemented to make app startuo faster.
       
   504 void CFSEmailUiMailListVisualiser::DoFirstStartL()
       
   505     {
       
   506     FUNC_LOG;
       
   507     // Create mail list updater timer
       
   508     iMailListUpdater = CMailListUpdater::NewL( this );
       
   509 
       
   510     // Set initial sort criteria
       
   511     iCurrentSortCriteria.iField = EFSMailSortByDate;
       
   512     iCurrentSortCriteria.iOrder = EFSMailDescending;
       
   513 
       
   514     // Create screen control and anchor layout
       
   515     iMailListControl = CFreestyleEmailUiMailListControl::NewL( iEnv, this );
       
   516     iScreenAnchorLayout = CAlfAnchorLayout::AddNewL( *iMailListControl );
       
   517     iScreenAnchorLayout->SetFlags(EAlfVisualFlagAutomaticLocaleMirroringEnabled);
       
   518 
       
   519     iTouchManager = CEUiEmailListTouchManager::NewL(*this);
       
   520 
       
   521     // Create control bar control and append to control group and anchor layout
       
   522     iControlBarControl = CFsControlBar::NewL( iEnv );
       
   523     iControlBarControl->AddObserverL( *this );
       
   524     iControlBarControl->AddObserverL( *iTouchManager );
       
   525 
       
   526     CreateControlBarLayoutL();
       
   527     SetMailListLayoutAnchors();
       
   528 
       
   529     iControlBarControl->SetSelectorTransitionTimeL( KControlBarTransitionTime );
       
   530     iControlBarControl->ClearBackgroundColor();
       
   531     iControlBarLayout = CAlfDeckLayout::AddNewL( *iControlBarControl, iScreenAnchorLayout );
       
   532     iControlBarVisual = iControlBarControl->Visual();
       
   533 
       
   534     // Create list and append to control group and anchor layout
       
   535 
       
   536     iListLayout = CAlfDeckLayout::AddNewL( *iMailListControl, iScreenAnchorLayout );
       
   537     iMailTreeListVisualizer = CFsTreeVisualizerBase::NewL(iMailListControl, *iListLayout);
       
   538     iMailTreeListVisualizer->SetFlipState( iKeyboardFlipOpen );
       
   539     iMailTreeListVisualizer->SetFocusVisibility( iFocusVisible );
       
   540     iMailList = CFsTreeList::NewL(*iMailTreeListVisualizer, iEnv );
       
   541 
       
   542     // Set mark type and icon
       
   543     iMailList->SetMarkTypeL( CFsTreeList::EFsTreeListMultiMarkable );
       
   544     iMailList->SetIndentationL(0);
       
   545 
       
   546     ControlGroup().AppendL( iMailListControl );
       
   547     ControlGroup().AppendL( iControlBarControl );
       
   548     ControlGroup().AppendL( iMailList->TreeControl() );
       
   549 
       
   550     iTreeItemArray.Reset();
       
   551 
       
   552     // Set empty text
       
   553     HBufC* emptyText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_EMPTY_MSG_LIST_TEXT );
       
   554     iMailTreeListVisualizer->SetEmptyListTextL( *emptyText );
       
   555     CleanupStack::PopAndDestroy( emptyText );
       
   556 
       
   557     iFocusedTextColor = iAppUi.LayoutHandler()->ListFocusedStateTextSkinColor();
       
   558     iNormalTextColor = iAppUi.LayoutHandler()->ListNormalStateTextSkinColor();
       
   559     iNodeTextColor = iAppUi.LayoutHandler()->ListNodeTextColor();
       
   560     iMailTreeListVisualizer->RootNodeVisualizer()->SetNormalStateTextColor( iNormalTextColor );
       
   561 
       
   562     // Set page up and page down keys
       
   563     iMailTreeListVisualizer->AddCustomPageUpKey( EStdKeyPageUp );
       
   564     iMailTreeListVisualizer->AddCustomPageDownKey( EStdKeyPageDown );
       
   565 
       
   566     // Set selector brushes
       
   567     CAlfBrush* listSelectorBrush = iAppUi.FsTextureManager()->ListSelectorBrushL(); // not owned
       
   568     iMailTreeListVisualizer->SetSelectorPropertiesL( listSelectorBrush, 1.0, CFsTreeVisualizerBase::EFsSelectorMoveSmoothly );
       
   569 
       
   570     CAlfBrush* cbSelectorBrush = iAppUi.FsTextureManager()->NewCtrlBarSelectorBrushLC();
       
   571     iControlBarControl->SetSelectorImageL( cbSelectorBrush );
       
   572     CleanupStack::Pop( cbSelectorBrush ); // ownership transferred to control bar
       
   573 
       
   574     iNewEmailText = StringLoader::LoadL( R_COMMAND_AREA_NEW_EMAIL );
       
   575 
       
   576     // Set menu, mark and background icons
       
   577     iMailTreeListVisualizer->SetMarkIcon( iAppUi.FsTextureManager()->TextureByIndex( EListControlMarkIcon ) );
       
   578     iMailTreeListVisualizer->SetMenuIcon( iAppUi.FsTextureManager()->TextureByIndex( EListControlMenuIcon ) );
       
   579     iMailList->AddObserverL( *this );
       
   580     iMailList->AddObserverL( *iTouchManager );
       
   581     // Initializing the default stylus long tap popup menu
       
   582     if( !iStylusPopUpMenu )
       
   583         {
       
   584         TPoint point( 0, 0 );
       
   585         iStylusPopUpMenu = CAknStylusPopUpMenu::NewL( this , point );
       
   586 		TResourceReader reader;
       
   587 		iCoeEnv->CreateResourceReaderLC( reader,
       
   588 				R_STYLUS_POPUP_MENU_MESSAGE_LIST_VIEW );
       
   589 		iStylusPopUpMenu->ConstructFromResourceL( reader );
       
   590 		CleanupStack::PopAndDestroy(); // reader
       
   591         }
       
   592 
       
   593     iAppUi.LayoutHandler()->SetListMarqueeBehaviour( iMailList );
       
   594 
       
   595     iDateChangeTimer = CDateChangeTimer::NewL( *this );
       
   596     iDateChangeTimer->Start();
       
   597 
       
   598     UpdateMailListSettingsL();
       
   599 
       
   600     iMailList->SetIndentationL(0);
       
   601     iMailList->SetLoopingType( EFsTreeListLoopingDisabled );
       
   602     iMailTreeListVisualizer->SetItemExpansionDelay( iAppUi.LayoutHandler()->ListItemExpansionDelay() );
       
   603     iMailList->SetScrollTime( iAppUi.LayoutHandler()->ListScrollingTime(), 0.5 );
       
   604 
       
   605     iFirstStartCompleted = ETrue;
       
   606     }
       
   607 
       
   608 
       
   609 // ---------------------------------------------------------------------------
       
   610 // Constructor.
       
   611 // ---------------------------------------------------------------------------
       
   612 //
       
   613 CFSEmailUiMailListVisualiser::CFSEmailUiMailListVisualiser( CAlfEnv& aEnv,
       
   614     CFreestyleEmailUiAppUi* aAppUi, CAlfControlGroup& aMailListControlGroup )
       
   615     : CFsEmailUiViewBase( aMailListControlGroup, *aAppUi ),
       
   616     iEnv( aEnv ),
       
   617     iListMarkItemsState( ETrue ), //Initlly list has no markings
       
   618     iMoveToFolderOngoing( EFalse ),
       
   619     iConsumeStdKeyYes_KeyUp( EFalse ), // use to prevent Call application execution if call for contact processed
       
   620     iMailOpened( EFalse ),
       
   621 	iMarkingMode( EFalse ),
       
   622     iMarkingModeWaitingToExit( EFalse ),
       
   623     iMarkingModeTextVisual( NULL )
       
   624 	{
       
   625     FUNC_LOG;
       
   626 	}
       
   627 
       
   628 // ---------------------------------------------------------------------------
       
   629 // Destructor.
       
   630 // ---------------------------------------------------------------------------
       
   631 //
       
   632 CFSEmailUiMailListVisualiser::~CFSEmailUiMailListVisualiser()
       
   633     {
       
   634     FUNC_LOG;
       
   635 /*
       
   636     if (iExtension)
       
   637         {
       
   638         iAppUi.GetMailClient()->ReleaseExtension(iExtension);
       
   639         }
       
   640 */
       
   641     SafeDelete(iMailListModelUpdater);
       
   642     SafeDelete(iMailFolder);
       
   643     delete iTouchManager;
       
   644     delete iStylusPopUpMenu;
       
   645     delete iMailList;
       
   646     delete iNewEmailText;
       
   647 
       
   648 	// Don't construct this anywhere else than in constructor.
       
   649 	// Don't delete anywhere else thatn here to avoid NULL checks.
       
   650     delete iModel;
       
   651 
       
   652     delete iDeleteTask;
       
   653     DeleteSortWaitNote();
       
   654     delete iNewMailTimer;
       
   655     delete iSortTimer;
       
   656     iNewMailIds.Close();
       
   657     }
       
   658 
       
   659 void CFSEmailUiMailListVisualiser::PrepareForExit()
       
   660     {
       
   661     FUNC_LOG;
       
   662     iMailListModelUpdater->Cancel();
       
   663     if ( iMsgNoteTimer )
       
   664         {
       
   665         // delete also cancels timer
       
   666         SafeDelete(iMsgNoteTimer);
       
   667         }
       
   668     if ( iDateChangeTimer )
       
   669         {
       
   670         // delete also cancels timer
       
   671         SafeDelete(iDateChangeTimer);
       
   672         }
       
   673     if ( iMailListUpdater )
       
   674         {
       
   675         // delete also cancels timer
       
   676         SafeDelete(iMailListUpdater);
       
   677         }
       
   678     if ( iAsyncRedrawer )
       
   679         {
       
   680         SafeDelete(iAsyncRedrawer);
       
   681         }
       
   682     if ( iAsyncCallback )
       
   683         {
       
   684         SafeDelete(iAsyncCallback);
       
   685         }
       
   686     if ( iMailList )
       
   687         {
       
   688         iMailList->RemoveObserver( *this );
       
   689         }
       
   690     if ( iControlBarControl )
       
   691         {
       
   692         iControlBarControl->RemoveObserver( *this );
       
   693         }
       
   694 
       
   695     if ( iNewMailTimer )
       
   696         {
       
   697         // delete also cancels timer
       
   698         SafeDelete( iNewMailTimer );
       
   699         }
       
   700 
       
   701     if ( iSortTimer )
       
   702         {
       
   703         // delete also cancels timer
       
   704         SafeDelete( iSortTimer );
       
   705         }
       
   706     
       
   707     SafeDelete(iMailFolder);
       
   708     iTreeItemArray.Reset();
       
   709 	// Reset, not delete to avoid NULL checks.
       
   710     iModel->Reset();
       
   711     // Resources freed, new start required
       
   712     iFirstStartCompleted = EFalse;
       
   713     }
       
   714 
       
   715 // ---------------------------------------------------------------------------
       
   716 // Returns reference to mail list.
       
   717 // ---------------------------------------------------------------------------
       
   718 //
       
   719 CFsTreeList& CFSEmailUiMailListVisualiser::GetMailList()
       
   720 	{
       
   721     FUNC_LOG;
       
   722 	return *iMailList;
       
   723 	}
       
   724 
       
   725 // ---------------------------------------------------------------------------
       
   726 // @see CMailListModelUpdater::MObserver::UpdateErrorL
       
   727 // ---------------------------------------------------------------------------
       
   728 //
       
   729 void CFSEmailUiMailListVisualiser::UpdateErrorL(TInt aError)
       
   730     {
       
   731     FUNC_LOG;
       
   732     
       
   733     DeleteSortWaitNote();
       
   734     User::Leave(aError);
       
   735     }
       
   736 
       
   737 // ---------------------------------------------------------------------------
       
   738 // @see CMailListModelUpdater::MObserver::UpdateBeginL
       
   739 // ---------------------------------------------------------------------------
       
   740 //
       
   741 void CFSEmailUiMailListVisualiser::UpdateBeginL()
       
   742     {
       
   743     FUNC_LOG;
       
   744     iMailList->BeginUpdate();
       
   745     iMailList->RemoveAllL();
       
   746     iTreeItemArray.Reset();
       
   747     iModel->Reset();
       
   748     iMailList->EndUpdateL();
       
   749 
       
   750     SetListAndCtrlBarFocusL();
       
   751     }
       
   752 
       
   753 // ---------------------------------------------------------------------------
       
   754 // @see CMailListModelUpdater::MObserver::UpdateProgressL
       
   755 // ---------------------------------------------------------------------------
       
   756 //
       
   757 void CFSEmailUiMailListVisualiser::UpdateProgressL(TFsTreeItemId& aParentId, RPointerArray<CFSMailMessage>& aMessages)
       
   758     {
       
   759     FUNC_LOG;
       
   760     
       
   761     const TInt itemsInModel(iModel->Count());
       
   762     CreateModelItemsL(aMessages);
       
   763     RefreshListItemsL(aParentId, itemsInModel, iModel->Count());
       
   764     }
       
   765 
       
   766 // ---------------------------------------------------------------------------
       
   767 // @see CMailListModelUpdater::MObserver::UpdateCompleteL
       
   768 // ---------------------------------------------------------------------------
       
   769 //
       
   770 void CFSEmailUiMailListVisualiser::UpdateCompleteL()
       
   771     {
       
   772     FUNC_LOG;
       
   773     TBool sorting = EFalse;
       
   774     if ( iSortWaitNote )
       
   775         {
       
   776         sorting = ETrue;
       
   777         }
       
   778     DeleteSortWaitNote();
       
   779 
       
   780     if ( !iModel->Count() )
       
   781         {
       
   782         iFocusedControl = EControlBarComponent;
       
   783         }
       
   784     else
       
   785         {
       
   786         iFocusedControl = EMailListComponent;
       
   787         if (iMailList->FocusedItem() == KFsTreeNoneID)
       
   788             {
       
   789             iMailList->SetFocusedItemL( iTreeItemArray[0].iListItemId );
       
   790             }
       
   791         }
       
   792     SetListAndCtrlBarFocusL();
       
   793     
       
   794     if( !CheckAutoSyncSettingL() && !sorting )
       
   795         {
       
   796         iAppUi.StartMonitoringL();
       
   797         }
       
   798     
       
   799     TIMESTAMP( "Locally stored messages fetched for message list" );
       
   800     }
       
   801 
       
   802 // ---------------------------------------------------------------------------
       
   803 // @see CMailListModelUpdater::MObserver::UpdateCancelled
       
   804 // ---------------------------------------------------------------------------
       
   805 //
       
   806 void CFSEmailUiMailListVisualiser::UpdateCancelled(const TBool aForceRefresh)
       
   807     {
       
   808     FUNC_LOG;
       
   809     
       
   810     iForceRefresh = aForceRefresh;
       
   811     DeleteSortWaitNote();
       
   812     }
       
   813 
       
   814 // ---------------------------------------------------------------------------
       
   815 // CFSEmailUiMailListVisualiser::DeleteSortWaitNote
       
   816 // ---------------------------------------------------------------------------
       
   817 //
       
   818 void CFSEmailUiMailListVisualiser::DeleteSortWaitNote()
       
   819     {
       
   820     if ( iSortWaitNote )
       
   821         {
       
   822         TRAP_IGNORE( iSortWaitNote->ProcessFinishedL() );
       
   823         iSortWaitNote = NULL;
       
   824         }
       
   825     }
       
   826 
       
   827 
       
   828 // ---------------------------------------------------------------------------
       
   829 // Asynchronous mail list model sort.
       
   830 // ---------------------------------------------------------------------------
       
   831 //
       
   832 void CFSEmailUiMailListVisualiser::SortMailListModelAsyncL()
       
   833     {
       
   834     FUNC_LOG;
       
   835 
       
   836     DeleteSortWaitNote();
       
   837   
       
   838     TBool ret = UpdateMailListModelAsyncL( KCMsgBlockSort );
       
   839     if ( ret )
       
   840         {
       
   841         TFsEmailUiUtility::ShowWaitNoteL( iSortWaitNote, R_FSE_WAIT_SORTING_TEXT, EFalse, ETrue );
       
   842         }
       
   843     }
       
   844 
       
   845 // ---------------------------------------------------------------------------
       
   846 // Asynchronous mail list model update.
       
   847 // ---------------------------------------------------------------------------
       
   848 //
       
   849 TBool CFSEmailUiMailListVisualiser::UpdateMailListModelAsyncL(TInt aBlockSize)
       
   850     {
       
   851     FUNC_LOG;
       
   852     TBool ret = EFalse;
       
   853     if ( iMailFolder )
       
   854         {
       
   855         TFSMailDetails details( EFSMsgDataEnvelope );
       
   856         RArray<TFSMailSortCriteria>& sorting(iMailListModelUpdater->Sorting());
       
   857         sorting.AppendL( iCurrentSortCriteria );
       
   858         if ( iCurrentSortCriteria.iField != EFSMailSortByDate )
       
   859             {
       
   860             // Add date+descending as secondary sort criteria if primary field is something else than date
       
   861             TFSMailSortCriteria secondarySortCriteria;
       
   862             secondarySortCriteria.iField = EFSMailSortByDate;
       
   863             secondarySortCriteria.iOrder = EFSMailDescending;
       
   864             sorting.AppendL( secondarySortCriteria );
       
   865             }
       
   866         // List all or maximum number of messages
       
   867         iMailListModelUpdater->UpdateModelL(*this, iMailFolder->ListMessagesL(details, sorting), aBlockSize);
       
   868         ret = ETrue;
       
   869         }
       
   870     else
       
   871         {
       
   872         UpdateCompleteL();
       
   873         }
       
   874     
       
   875     return ret;
       
   876     }
       
   877 
       
   878 // ---------------------------------------------------------------------------
       
   879 //
       
   880 //
       
   881 // ---------------------------------------------------------------------------
       
   882 //
       
   883 void CFSEmailUiMailListVisualiser::UpdateMailListModelL()
       
   884     {
       
   885     FUNC_LOG;
       
   886     // Make sure asynchronous update is not going on
       
   887     iMailListModelUpdater->Cancel();
       
   888     // Reset model with each update
       
   889 	iModel->Reset();
       
   890 	if ( iMailFolder )
       
   891 		{
       
   892 		// Update folder if provided, otherwise use current folder
       
   893 		RPointerArray<CFSMailMessage> folderMessages( KCMsgBlock );
       
   894 		CleanupClosePushL( folderMessages );
       
   895 
       
   896 		RPointerArray<CFSMailMessage> tempFolderMessages( KCMsgBlock );
       
   897         CleanupClosePushL( tempFolderMessages );
       
   898 
       
   899 	 	TFSMailDetails details( EFSMsgDataEnvelope );
       
   900 	    RArray<TFSMailSortCriteria> sorting;
       
   901 		CleanupClosePushL( sorting );
       
   902 	    sorting.Append( iCurrentSortCriteria );
       
   903 	    if ( iCurrentSortCriteria.iField != EFSMailSortByDate )
       
   904 	    	{
       
   905             // Add date+descending as secondary sort criteria if primary field is something else than date
       
   906             TFSMailSortCriteria secondarySortCriteria;
       
   907             secondarySortCriteria.iField = EFSMailSortByDate;
       
   908             secondarySortCriteria.iOrder = EFSMailDescending;
       
   909             sorting.Append( secondarySortCriteria );
       
   910 	    	}
       
   911 
       
   912 	    // List all or maximum number of messages
       
   913 	    MFSMailIterator* iterator = iMailFolder->ListMessagesL( details, sorting );
       
   914 		CleanupDeletePushL( iterator ); // standard CleanupStack::PushL does not work with non-C-class pointer
       
   915 
       
   916 		// Use iterator to get messages in peaces of KCMsgBlock to avoid OOM in FSStore
       
   917 		TFSMailMsgId dummy;
       
   918         TBool moreMessagesToFollow = iterator->NextL( dummy, KCMsgBlock, folderMessages  );
       
   919         for ( TInt i = KCMsgBlock; i < KMaxItemsFethed && moreMessagesToFollow ; i += KCMsgBlock )
       
   920             {
       
   921             tempFolderMessages.Reset();
       
   922             moreMessagesToFollow = iterator->NextL( folderMessages[i-1]->GetMessageId(), KCMsgBlock, tempFolderMessages  );
       
   923             for ( TInt a=0 ; a<tempFolderMessages.Count() ; a++)
       
   924                 {
       
   925                 folderMessages.Append(tempFolderMessages[a]);
       
   926                 }
       
   927             }
       
   928 
       
   929 		CleanupStack::PopAndDestroy( iterator );
       
   930 		CleanupStack::PopAndDestroy( &sorting );
       
   931 
       
   932 		// Update mail list model based on sorting criteria
       
   933 		CreateModelItemsL( folderMessages );
       
   934 
       
   935 		CleanupStack::PopAndDestroy( &tempFolderMessages );
       
   936 		CleanupStack::PopAndDestroy( &folderMessages );
       
   937 		}
       
   938     }
       
   939 
       
   940 
       
   941 // ---------------------------------------------------------------------------
       
   942 // CreateModelItemsL
       
   943 // This function creates model items for the given messages and appends them
       
   944 // to the model. Also title divider items are created when necessary.
       
   945 // ---------------------------------------------------------------------------
       
   946 //
       
   947 void CFSEmailUiMailListVisualiser::CreateModelItemsL( RPointerArray<CFSMailMessage>& aMessages )
       
   948 	{
       
   949     FUNC_LOG;
       
   950 	// New Items
       
   951 	CFSEmailUiMailListModelItem* newItem(NULL);
       
   952 
       
   953 	// Draw first separator if there are messages.
       
   954 	if ( aMessages.Count() && iNodesInUse == EListControlSeparatorEnabled )
       
   955 		{
       
   956 		if (iModel->Count())
       
   957 		    {
       
   958 		    CFSMailMessage* nextMessage = aMessages[0];
       
   959 		    CFSEmailUiMailListModelItem* previousMessage(static_cast<CFSEmailUiMailListModelItem*>(iModel->Item(iModel->Count() - 1)));
       
   960             if ( previousMessage ) // Safety
       
   961                 {
       
   962                 TBool needANewDivider =
       
   963                     !MessagesBelongUnderSameSeparatorL( previousMessage->MessagePtr(), *nextMessage );
       
   964                 if ( needANewDivider )
       
   965                     {
       
   966                     newItem = CreateSeparatorModelItemLC( *nextMessage );
       
   967                     iModel->AppendL( newItem );
       
   968                     CleanupStack::Pop( newItem );
       
   969                     }
       
   970                 }
       
   971             }
       
   972 		else
       
   973 		    {
       
   974 	    newItem = CreateSeparatorModelItemLC( *aMessages[0] );
       
   975 	    iModel->AppendL( newItem );
       
   976 		CleanupStack::Pop( newItem );
       
   977 		}
       
   978 		}
       
   979 
       
   980 	// Start appending items
       
   981     for (int i = 0; i < aMessages.Count(); i++)
       
   982 	    {
       
   983 	    CFSMailMessage* curMessage = aMessages[i];
       
   984 	    if ( curMessage )
       
   985 	        {
       
   986 	        newItem = CFSEmailUiMailListModelItem::NewL( curMessage, ETypeMailItem );
       
   987 	        CleanupStack::PushL( newItem );
       
   988 	        iModel->AppendL( newItem );
       
   989 	        CleanupStack::Pop( newItem );
       
   990 
       
   991 	        // Append new separator if needed
       
   992 	        if ( i != aMessages.Count()-1 && iNodesInUse == EListControlSeparatorEnabled )
       
   993 	            {
       
   994 	            CFSMailMessage* nextMessage = aMessages[i+1];   // This msg is next in the list
       
   995 
       
   996 	            if ( nextMessage )
       
   997 	                {
       
   998 	                TBool needANewDivider =
       
   999 	                    !MessagesBelongUnderSameSeparatorL( *curMessage, *nextMessage );
       
  1000 	                if ( needANewDivider )
       
  1001 	                    {
       
  1002 	                    newItem = CreateSeparatorModelItemLC( *nextMessage );
       
  1003 	                    iModel->AppendL( newItem );
       
  1004 	                    CleanupStack::Pop( newItem );
       
  1005 	                    }
       
  1006 	                }
       
  1007 	            }
       
  1008 	        }
       
  1009 	    }
       
  1010 	}
       
  1011 
       
  1012 // ---------------------------------------------------------------------------
       
  1013 // CreateSeparatorModelItemLC
       
  1014 // Create separator model item for the given message. Separator text depends
       
  1015 // on active sorting mode.
       
  1016 // ---------------------------------------------------------------------------
       
  1017 //
       
  1018 CFSEmailUiMailListModelItem* CFSEmailUiMailListVisualiser::CreateSeparatorModelItemLC( CFSMailMessage& aMessage ) const
       
  1019     {
       
  1020     FUNC_LOG;
       
  1021     CFSEmailUiMailListModelItem* separator =
       
  1022         CFSEmailUiMailListModelItem::NewL( &aMessage, ETypeSeparator );
       
  1023     CleanupStack::PushL( separator );
       
  1024 
       
  1025     HBufC* separatorText = NULL;
       
  1026 
       
  1027     switch ( iCurrentSortCriteria.iField )
       
  1028         {
       
  1029         case EFSMailSortByFlagStatus:
       
  1030             {
       
  1031             if ( aMessage.IsFlagSet( EFSMsgFlag_FollowUp ) )
       
  1032                 {
       
  1033                 separatorText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SEPARATOR_FOLLOW_UP );
       
  1034                 }
       
  1035             else if ( aMessage.IsFlagSet( EFSMsgFlag_FollowUpComplete ) )
       
  1036                 {
       
  1037                 separatorText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SEPARATOR_FLAG_COMPLETE );
       
  1038                 }
       
  1039             else
       
  1040                 {
       
  1041                 separatorText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SEPARATOR_NO_FLAG );
       
  1042                 }
       
  1043             }
       
  1044             break;
       
  1045         case EFSMailSortByPriority:
       
  1046             {
       
  1047             if ( aMessage.IsFlagSet( EFSMsgFlag_Important ) )
       
  1048                 {
       
  1049                 separatorText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SEPARATOR_PRIO_HIGH );
       
  1050                 }
       
  1051             else if ( aMessage.IsFlagSet( EFSMsgFlag_Low ) )
       
  1052                 {
       
  1053                 separatorText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SEPARATOR_PRIO_LOW );
       
  1054                 }
       
  1055             else
       
  1056                 {
       
  1057                 separatorText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SEPARATOR_PRIO_NORMAL );
       
  1058                 }
       
  1059             }
       
  1060             break;
       
  1061         case EFSMailSortByRecipient:
       
  1062         case EFSMailSortBySender:
       
  1063             {
       
  1064             TInt folderType(EFSInbox);
       
  1065             if( iMailFolder )
       
  1066                 {
       
  1067                 folderType = iMailFolder->GetFolderType();
       
  1068                 }
       
  1069             TBool useRecipient = ( folderType == EFSSentFolder ||
       
  1070                                    folderType == EFSDraftsFolder ||
       
  1071                                    folderType == EFSOutbox );
       
  1072 
       
  1073             CFSMailAddress* fromAddress(0);
       
  1074             // Check address based on whether we are using recipient or sender sort
       
  1075             if ( useRecipient )
       
  1076                 {
       
  1077                 RPointerArray<CFSMailAddress>& toArray = aMessage.GetToRecipients();
       
  1078                 if ( toArray.Count() )
       
  1079                     {
       
  1080                     fromAddress = toArray[0];
       
  1081                     }
       
  1082                 }
       
  1083             else
       
  1084                 {
       
  1085                 fromAddress = aMessage.GetSender();
       
  1086                 }
       
  1087             TDesC* diplayName(0);
       
  1088             if ( fromAddress )
       
  1089                 {
       
  1090                 diplayName = &fromAddress->GetDisplayName();
       
  1091                 }
       
  1092 
       
  1093             if ( fromAddress && diplayName && diplayName->Length() != 0 )
       
  1094                 {
       
  1095                 separatorText = diplayName->AllocLC();
       
  1096                 }
       
  1097             else if ( fromAddress && fromAddress->GetEmailAddress().Length() != 0 )
       
  1098                 {
       
  1099                 separatorText = fromAddress->GetEmailAddress().AllocLC();
       
  1100                 }
       
  1101             else
       
  1102                 {
       
  1103                 if ( useRecipient )
       
  1104                     {
       
  1105                     separatorText = KNullDesC().AllocLC();
       
  1106                     }
       
  1107                 else
       
  1108                     {
       
  1109                     separatorText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_MSG_DETAILS_NO_SENDER_INFO_AVAILABLE );
       
  1110                     }
       
  1111                 }
       
  1112 			// Get rid of possible unwanted characters in display name
       
  1113            	if ( separatorText )
       
  1114            		{
       
  1115 	           	TFsEmailUiUtility::StripDisplayName( *separatorText );
       
  1116            		}
       
  1117             }
       
  1118             break;
       
  1119         case EFSMailSortByAttachment:
       
  1120             {
       
  1121             if ( aMessage.IsFlagSet( EFSMsgFlag_Attachments ) )
       
  1122                 {
       
  1123                 separatorText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SEPARATOR_ATTACHMENTS );
       
  1124                 }
       
  1125             else
       
  1126                 {
       
  1127                 separatorText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SEPARATOR_NO_ATTACHMENTS );
       
  1128                 }
       
  1129             }
       
  1130             break;
       
  1131         case EFSMailSortByUnread:
       
  1132             {
       
  1133             if ( aMessage.IsFlagSet( EFSMsgFlag_Read ) )
       
  1134                 {
       
  1135                 separatorText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SEPARATOR_READ_MSGS );
       
  1136                 }
       
  1137             else
       
  1138                 {
       
  1139                 separatorText = StringLoader::LoadLC(R_FREESTYLE_EMAIL_UI_SEPARATOR_UNREAD_MSGS);
       
  1140                 }
       
  1141             }
       
  1142             break;
       
  1143         case EFSMailSortBySubject:
       
  1144             {
       
  1145             separatorText = TFsEmailUiUtility::CreateSubjectWithoutLocalisedPrefixLC( &aMessage );
       
  1146             }
       
  1147             break;
       
  1148         case EFSMailSortByDate:
       
  1149             {
       
  1150             TBool eventToday = EFalse;
       
  1151             TBool eventYesterday = EFalse;
       
  1152             HBufC* weekDay = TFsEmailUiUtility::WeekDayTextFromMsgLC( &aMessage, ETrue, EFalse, eventToday, eventYesterday );
       
  1153             if ( eventToday || eventYesterday )
       
  1154                 {
       
  1155                 separatorText = weekDay;
       
  1156                 }
       
  1157             else
       
  1158                 {
       
  1159                 HBufC* dateTextFromMsg = TFsEmailUiUtility::DateTextFromMsgLC( &aMessage );
       
  1160                 separatorText = HBufC::NewL( weekDay->Length() +
       
  1161                                              KSpace().Length() +
       
  1162                                              dateTextFromMsg->Length() );
       
  1163                 separatorText->Des().Append( *weekDay );
       
  1164                 separatorText->Des().Append( KSpace );
       
  1165                 separatorText->Des().Append( *dateTextFromMsg );
       
  1166                 CleanupStack::PopAndDestroy( dateTextFromMsg );
       
  1167                 CleanupStack::PopAndDestroy( weekDay );
       
  1168                 CleanupStack::PushL( separatorText );
       
  1169                 }
       
  1170             }
       
  1171             break;
       
  1172         default:
       
  1173             {
       
  1174             separatorText = KNullDesC().AllocLC();
       
  1175             }
       
  1176             break;
       
  1177         }
       
  1178 
       
  1179     separator->SetSeparatorTextL( *separatorText );
       
  1180     CleanupStack::PopAndDestroy( separatorText );
       
  1181 
       
  1182     return separator;
       
  1183     }
       
  1184 
       
  1185 // ---------------------------------------------------------------------------
       
  1186 // MessagesBelongUnderSameSeparatorL
       
  1187 // Checks if the given messages belong under the same title divider. This
       
  1188 // depends on the currect sorting mode.
       
  1189 // ---------------------------------------------------------------------------
       
  1190 //
       
  1191 TBool CFSEmailUiMailListVisualiser::MessagesBelongUnderSameSeparatorL(
       
  1192                                             const CFSMailMessage& aMessage1,
       
  1193                                             const CFSMailMessage& aMessage2 ) const
       
  1194     {
       
  1195     FUNC_LOG;
       
  1196     return CFSEmailUiMailListModel::MessagesBelongUnderSameSeparatorL( aMessage1,
       
  1197                                                                        aMessage2,
       
  1198                                                                        iCurrentSortCriteria.iField );
       
  1199     }
       
  1200 
       
  1201 // ---------------------------------------------------------------------------
       
  1202 // InsertNewMessagesL
       
  1203 // Gets new message items from the framework using the given IDs and inserts
       
  1204 // them in the correct place within the mail list. Both model and tree list
       
  1205 // are updated during this function.
       
  1206 // ---------------------------------------------------------------------------
       
  1207 //
       
  1208 void CFSEmailUiMailListVisualiser::InsertNewMessagesL( const RArray<TFSMailMsgId>& aMessages )
       
  1209     {
       
  1210     FUNC_LOG;
       
  1211     iModel->SetSortCriteria( iCurrentSortCriteria );
       
  1212 
       
  1213     // Do complete refresh in case the list is not currently correctly ordered
       
  1214     // (alternatively, we could first reorder the existing items and then insert
       
  1215     // the new ones)
       
  1216     if ( iListOrderMayBeOutOfDate )
       
  1217         {
       
  1218         if ( iMailListUpdater )
       
  1219             {
       
  1220             if ( iMailListUpdater->IsActive() )
       
  1221                 {
       
  1222                 iMailListUpdater->Stop();
       
  1223                 }
       
  1224             iMailListUpdater->StartL();
       
  1225             }
       
  1226         }
       
  1227     // Otherwise, just add the new items to correct places.
       
  1228     else
       
  1229         {
       
  1230         // Set extended status before inserting messages
       
  1231         SetMailListItemsExtendedL();
       
  1232         TInt count(0);
       
  1233         count = aMessages.Count();
       
  1234 
       
  1235         for ( TInt i = 0 ; i < count ; ++i )
       
  1236             {
       
  1237             // Make sure we don't add duplicate items.
       
  1238             TInt existingIdx = ItemIndexFromMessageId( aMessages[i] );
       
  1239             if ( existingIdx < 0 )
       
  1240                 {
       
  1241                 iNewMailIds.Append( aMessages[ i ] );
       
  1242                 }
       
  1243             }
       
  1244 
       
  1245         // start timer only when all conditions are met:
       
  1246         //   timer isn`t already active
       
  1247         //   there are new mails in the array
       
  1248         //   timer event isn`t processing
       
  1249         //   sorting timer isn't running
       
  1250         if ( !iNewMailTimer->IsActive() && iNewMailIds.Count() && 
       
  1251              iNewMailTimer->iStatus != KErrInUse  && iSortState == ESortNone )
       
  1252             {
       
  1253             iNewMailTimer->Start( KNewMailTimerDelay );
       
  1254             }
       
  1255         }
       
  1256     }
       
  1257 
       
  1258 
       
  1259 // ---------------------------------------------------------------------------
       
  1260 // TimerEventL
       
  1261 //
       
  1262 // ---------------------------------------------------------------------------
       
  1263 //
       
  1264 void CFSEmailUiMailListVisualiser::TimerEventL( CFSEmailUiGenericTimer* aTriggeredTimer )
       
  1265     {
       
  1266 	
       
  1267     if( aTriggeredTimer == iSortTimer )
       
  1268         {
       
  1269         switch ( iSortState )
       
  1270             {
       
  1271             case ESortNone:
       
  1272                 {
       
  1273                 iSortTryCount = 0;
       
  1274                 iSortState = ESortRequested;
       
  1275                 break;
       
  1276                 }
       
  1277             case ESortRequested:
       
  1278                 {
       
  1279                 if( !iNewMailTimer->IsActive() && iNewMailTimer->iStatus != KErrInUse )
       
  1280         	{
       
  1281                     // Size sorting does not use nodes, so disable those, otherwise check from CR
       
  1282                     iNodesInUse = iAppUi.GetCRHandler()->TitleDividers();
       
  1283                     SetSortButtonTextAndIconL();
       
  1284 
       
  1285                     iFocusedControl = EControlBarComponent;
       
  1286                     iMailList->SetFocusedL( EFalse );
       
  1287                     iControlBarControl->SetFocusByIdL( iSortButtonId );
       
  1288 
       
  1289                     SortMailListModelAsyncL();  // sort can take long time    
       
  1290                     SetMskL();
       
  1291                     iSortState = ESortStarted;
       
  1292                     }
       
  1293                 else
       
  1294                     {
       
  1295                     iSortTryCount = 0;
       
  1296                     iSortState = ESortPostponed;
       
  1297                     iNewMailTimer->Stop(); // stop mail timer
       
  1298                     }
       
  1299                 break;
       
  1300                 }
       
  1301             case ESortPostponed:
       
  1302                 {
       
  1303                 if ( !iNewMailTimer->IsActive() && iNewMailTimer->iStatus != KErrInUse )
       
  1304                     {
       
  1305                     iSortState = ESortRequested; // start request again
       
  1306                     }
       
  1307                 else
       
  1308                     {
       
  1309                     iSortTryCount++;
       
  1310                     }
       
  1311                 if( iSortTryCount >= KSortCountdown )// repeat a few times
       
  1312                     {
       
  1313                     iSortTryCount = 0; // reset
       
  1314                     iSortState = ESortStartError; // can't start sorting  some error
       
  1315                     }
       
  1316                 break;
       
  1317                 }
       
  1318             case ESortStarted:
       
  1319                 {
       
  1320                 if ( !iSortWaitNote )// it will restart the timer elsewhere (see below)
       
  1321                     {
       
  1322                     iSortState = ESortCompleted;
       
  1323                     }
       
  1324                 break;
       
  1325                 }
       
  1326             case ESortStartError:
       
  1327             case ESortCompleted:
       
  1328                 {
       
  1329             	if( !iNewMailTimer->IsActive() )
       
  1330             	    {
       
  1331             	    // refresh the whole mail list if list was sorted
       
  1332             	    if(iSortState != ESortStartError )
       
  1333             	    	{
       
  1334             	        RefreshL();
       
  1335             	    	}
       
  1336             	    // stop sorting process
       
  1337                     iSortState = ESortNone;
       
  1338                     iSortTimer->Stop();
       
  1339             	    // restart if more messages available
       
  1340             	    if ( iNewMailIds.Count() )
       
  1341                     {
       
  1342                     iNewMailTimer->Start( KNewMailTimerDelay );
       
  1343                     }
       
  1344                 return;
       
  1345             		}
       
  1346                 iNewMailTimer->Stop();
       
  1347             	break;
       
  1348                 }
       
  1349             default :
       
  1350                 {
       
  1351                 // do nothing
       
  1352                 }
       
  1353             }
       
  1354         // start timer again
       
  1355         if ( !iSortTimer->IsActive() )
       
  1356             {
       
  1357             iSortTimer->Start( KSortTimerDelay );
       
  1358             }
       
  1359         }
       
  1360     
       
  1361     if( aTriggeredTimer == iNewMailTimer )
       
  1362         {
       
  1363         TInt count = Min( KNewMailMaxBatch, iNewMailIds.Count() );
       
  1364         CFSMailClient* mailClient = iAppUi.GetMailClient();
       
  1365 
       
  1366         // Enter critical section
       
  1367         // Because CFSMailClient::GetMessageByUidL can use CActiveSchedulerWait
       
  1368         // to ensure that only one TimerEventL method is processed at time
       
  1369         // CFSEmailUiGenericTimer`s iStatus will be used as mutex
       
  1370         iNewMailTimer->iStatus = KErrInUse;
       
  1371         iModel->SetSortCriteria(iCurrentSortCriteria);
       
  1372 
       
  1373         for ( TInt i = 0; i < count; i++ )
       
  1374             {
       
  1375             // stop synchronization if mail list is being sorted
       
  1376             if( iSortState != ESortNone || iSortWaitNote )
       
  1377                 {
       
  1378                 iNewMailTimer->iStatus = KErrNone;
       
  1379                 iNewMailTimer->Stop();
       
  1380                 return; // leave  method
       
  1381                 }
       
  1382     
       
  1383             CFSMailMessage* msgPtr = mailClient->GetMessageByUidL( iAppUi.GetActiveMailboxId(),
       
  1384                                                                iMailFolder->GetFolderId(),
       
  1385                                                                iNewMailIds[ 0 ],
       
  1386                                                                EFSMsgDataEnvelope );
       
  1387             if ( msgPtr != NULL )
       
  1388  {
       
  1389                 __ASSERT_DEBUG( FolderId() == msgPtr->GetFolderId(), User::Invariant() );
       
  1390                 CleanupStack::PushL( msgPtr );
       
  1391                 //first item - show scrollbar
       
  1392                 //last item - update scrollbar
       
  1393                 TBool allowRefresh = ( i == 0 || i == count - 1 );
       
  1394                 InsertNewMessageL( msgPtr, allowRefresh );
       
  1395                 CleanupStack::Pop( msgPtr ); // ownership transferred to model
       
  1396                 }
       
  1397             // pop processed id from the queue, this is single thread operation
       
  1398             iNewMailIds.Remove( 0 ); 
       
  1399             }
       
  1400             
       
  1401         // End critical section
       
  1402         iNewMailTimer->iStatus = KErrNone;
       
  1403 
       
  1404         // if timer stoped then restart if more messages available
       
  1405         if ( iNewMailIds.Count() && ! iNewMailTimer->IsActive() && iSortState == ESortNone )
       
  1406             {
       
  1407             iNewMailTimer->Start( KNewMailTimerDelay );
       
  1408             }
       
  1409         }//iNewMailTimer
       
  1410     }
       
  1411 
       
  1412 // ---------------------------------------------------------------------------
       
  1413 // InsertNewMessageL
       
  1414 // Creates a single new message item to the model and tree list from the given
       
  1415 // message pointer. Ownership of the message is transferred. Also new
       
  1416 // separator item is created if necessary.
       
  1417 // ---------------------------------------------------------------------------
       
  1418 //
       
  1419 void CFSEmailUiMailListVisualiser::InsertNewMessageL( CFSMailMessage* aNewMessage, const TBool aAllowRefresh )
       
  1420     {
       
  1421     FUNC_LOG;
       
  1422     // Use simple heuristic rule: if the first item is highlighted before the new
       
  1423     // item is added, the highlight is forced to remain on the (possibly new) first
       
  1424     // item. Otherwise the highligh stays on the same item as before.
       
  1425     TBool firstItemWasFocused =
       
  1426         ( iTreeItemArray.Count() && iTreeItemArray[0].iListItemId == iMailList->FocusedItem() );
       
  1427 
       
  1428     CFSEmailUiMailListModelItem* newItem =
       
  1429         CFSEmailUiMailListModelItem::NewLC( aNewMessage, ETypeMailItem );
       
  1430     TInt idx = KErrNotFound;
       
  1431     TFsTreeItemId parentId = KFsTreeRootID;
       
  1432     TInt childIdx = KErrNotFound;
       
  1433     TInt moveViewPortPosition = 0;
       
  1434 
       
  1435     if ( !iNodesInUse )
       
  1436         {
       
  1437         // Simple case: nodes are not in use. Just insert to correct place under root node.
       
  1438         idx = iModel->GetInsertionPointL( *newItem );
       
  1439         childIdx = idx;
       
  1440         }
       
  1441     else
       
  1442         {
       
  1443         // More complicated case: nodes are in use.
       
  1444         TInt parentIdx = KErrNotFound;
       
  1445         idx = iModel->GetInsertionPointL( *newItem, childIdx, parentIdx );
       
  1446 
       
  1447         CFSEmailUiMailListModelItem* parentNode = NULL;
       
  1448         if ( parentIdx < 0 )
       
  1449             {
       
  1450             // Suitable parent node for the new item was not found and has to be created.
       
  1451             parentNode = CreateSeparatorModelItemLC( *aNewMessage );
       
  1452             iModel->InsertL( parentNode, idx );
       
  1453             CleanupStack::Pop( parentNode );
       
  1454             idx++; // The originally found index was used for the new node and the new item will reside in the next index
       
  1455 
       
  1456             // To insert the node item to the tree list, we need to figure out the index of the
       
  1457             // new node under the root node. If the new item is not the last item in the list,
       
  1458             // then the insertion location currently contains the node in front of which the new
       
  1459             // node is inserted.
       
  1460             if ( idx == iModel->Count() )
       
  1461                 {
       
  1462                 InsertNodeItemL( idx-1, KErrNotFound, aAllowRefresh ); // append
       
  1463                 }
       
  1464             else
       
  1465                 {
       
  1466                 CFSEmailUiMailListModelItem* nextNode =
       
  1467                     static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(idx) );
       
  1468                 TFsTreeItemId nextNodeId = nextNode->CorrespondingListId();
       
  1469                 TInt nodeIdxUnderRoot = iMailList->ChildIndex( KFsTreeRootID, nextNodeId );
       
  1470                 InsertNodeItemL( idx-1, nodeIdxUnderRoot, aAllowRefresh );
       
  1471                 }
       
  1472             moveViewPortPosition += iAppUi.LayoutHandler()->OneLineListItemHeight();
       
  1473             }
       
  1474         else
       
  1475             {
       
  1476             // Suitable parent node exists and was found
       
  1477             parentNode = static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(parentIdx) );
       
  1478             }
       
  1479         parentId = parentNode->CorrespondingListId();
       
  1480         }
       
  1481 
       
  1482     // Insert the model item
       
  1483     iModel->InsertL( newItem, idx );
       
  1484     CleanupStack::Pop( newItem );
       
  1485 
       
  1486     // Insert the tree list item
       
  1487     TPoint viewPortCenterPos = iMailTreeListVisualizer->ViewPosition();
       
  1488     TPoint viewPortTopPos = iMailTreeListVisualizer->ViewPortTopPosition();
       
  1489     TInt itemPos = iMailTreeListVisualizer->GetItemWorldPosition( idx );
       
  1490     TBool refresh = viewPortTopPos.iY != 0 && itemPos < viewPortCenterPos.iY;
       
  1491 
       
  1492     if( refresh )
       
  1493     	{
       
  1494 		InsertListItemL( idx, parentId, childIdx, EFalse );
       
  1495 		// viewPort update needed
       
  1496 		moveViewPortPosition += iAppUi.LayoutHandler()->TwoLineListItemHeight(); // add mail item height
       
  1497 		viewPortCenterPos.iY += moveViewPortPosition;
       
  1498 		iMailTreeListVisualizer->ViewPositionChanged( viewPortCenterPos, EFalse, 1 );
       
  1499     	}
       
  1500     else
       
  1501     	{
       
  1502     	InsertListItemL( idx, parentId, childIdx, aAllowRefresh );
       
  1503     	}
       
  1504 
       
  1505     // Move focus after insertion if necessary
       
  1506     if ( firstItemWasFocused )
       
  1507         {
       
  1508         TFsTreeItemId firstItemId = iMailList->Child( KFsTreeRootID, 0 );
       
  1509         TFsTreeItemId focusedId = iMailList->FocusedItem();
       
  1510 
       
  1511         if ( firstItemId != focusedId )
       
  1512             {
       
  1513             // Set the first item as focused and set
       
  1514             // list/ctrl bar focus according iFocusedControl
       
  1515             // <cmail>
       
  1516             //iMailList->SetFocusedItemL( firstItemId );
       
  1517             iMailTreeListVisualizer->SetFocusedItemL( firstItemId, EFalse );
       
  1518             // </cmail>
       
  1519             SetListAndCtrlBarFocusL();
       
  1520             }
       
  1521         }
       
  1522     }
       
  1523 
       
  1524 // ---------------------------------------------------------------------------
       
  1525 // HighlightedIndex
       
  1526 // This function return highlighted inxed
       
  1527 // ---------------------------------------------------------------------------
       
  1528 //
       
  1529 TInt CFSEmailUiMailListVisualiser::HighlightedIndex() const
       
  1530     {
       
  1531     FUNC_LOG;
       
  1532     TFsTreeItemId focusedId = static_cast<TFsTreeItemId>( iMailList->FocusedItem() );
       
  1533     // Map id to the index in model
       
  1534     TInt ret( KErrNotFound );
       
  1535     if ( focusedId != KFsTreeNoneID )
       
  1536         {
       
  1537         for ( TInt i=0; i<iTreeItemArray.Count();i++ )
       
  1538             {
       
  1539             if ( focusedId == iTreeItemArray[i].iListItemId )
       
  1540                 {
       
  1541                 ret = i;
       
  1542                 break;
       
  1543                 }
       
  1544             }
       
  1545         }
       
  1546     return ret;
       
  1547     }
       
  1548 
       
  1549 // ---------------------------------------------------------------------------
       
  1550 // HighlightedIndex
       
  1551 // Use this function to set highlighted inxed
       
  1552 // ---------------------------------------------------------------------------
       
  1553 //
       
  1554 void CFSEmailUiMailListVisualiser::SetHighlightedIndexL( TInt aWantedIndex )
       
  1555 	{
       
  1556     FUNC_LOG;
       
  1557 	if ( aWantedIndex >= 0 )
       
  1558 		{
       
  1559 		iMailTreeListVisualizer->SetFocusedItemL( iTreeItemArray[aWantedIndex].iListItemId );
       
  1560 		}
       
  1561 	}
       
  1562 
       
  1563 // ---------------------------------------------------------------------------
       
  1564 //
       
  1565 //
       
  1566 // ---------------------------------------------------------------------------
       
  1567 //
       
  1568 TInt CFSEmailUiMailListVisualiser::NewEmailsInModelL() const
       
  1569 	{
       
  1570     FUNC_LOG;
       
  1571     // <cmail>
       
  1572 	TInt newCount(0);
       
  1573 	for ( TInt i=0; i<iModel->Count();i++)
       
  1574 		{
       
  1575 		CFSEmailUiMailListModelItem* item =
       
  1576 			static_cast<CFSEmailUiMailListModelItem*>(iModel->Item(i));
       
  1577 		if ( item && item->ModelItemType() == ETypeMailItem )
       
  1578 			{
       
  1579 			if ( !item->MessagePtr().IsFlagSet(EFSMsgFlag_Read) )
       
  1580 				{
       
  1581 				newCount++;
       
  1582 				}
       
  1583 			}
       
  1584 		}
       
  1585 	return newCount;
       
  1586     // </cmail>
       
  1587 	}
       
  1588 
       
  1589 // ---------------------------------------------------------------------------
       
  1590 //
       
  1591 //
       
  1592 // ---------------------------------------------------------------------------
       
  1593 //
       
  1594 TInt CFSEmailUiMailListVisualiser::EmailsInModelL() const
       
  1595 	{
       
  1596     FUNC_LOG;
       
  1597     // <cmail>
       
  1598 	TInt ret(0);
       
  1599 	for ( TInt i=0; i<iModel->Count(); i++ )
       
  1600 		{
       
  1601 		CFSEmailUiMailListModelItem* item =
       
  1602 			static_cast<CFSEmailUiMailListModelItem*>(iModel->Item(i));
       
  1603 		if ( item && item->ModelItemType() == ETypeMailItem )
       
  1604 			{
       
  1605 			ret++;
       
  1606 			}
       
  1607 		}
       
  1608 	return ret;
       
  1609 	// </cmail>
       
  1610 	}
       
  1611 
       
  1612 
       
  1613 // ---------------------------------------------------------------------------
       
  1614 //
       
  1615 //
       
  1616 // ---------------------------------------------------------------------------
       
  1617 //
       
  1618 TUid CFSEmailUiMailListVisualiser::Id() const
       
  1619 	{
       
  1620     FUNC_LOG;
       
  1621 	return MailListId;
       
  1622 	}
       
  1623 
       
  1624 // ---------------------------------------------------------------------------
       
  1625 //
       
  1626 //
       
  1627 // ---------------------------------------------------------------------------
       
  1628 //
       
  1629 void CFSEmailUiMailListVisualiser::ChildDoActivateL(const TVwsViewId& aPrevViewId,
       
  1630                      TUid aCustomMessageId,
       
  1631                      const TDesC8& aCustomMessage)
       
  1632 	{
       
  1633     FUNC_LOG;
       
  1634     TIMESTAMP( "Opening message list view" );
       
  1635     
       
  1636     if (iMarkingModeWaitingToExit)
       
  1637         {
       
  1638         if ( iAppUi.CurrentActiveView()->Id() == MailListId )
       
  1639             {
       
  1640             iMarkingModeWaitingToExit = EFalse;
       
  1641             TRAP_IGNORE( ExitMarkingModeL() );
       
  1642             }
       
  1643         }
       
  1644 
       
  1645     iShowReplyAll = EFalse;
       
  1646 
       
  1647 	if ( !iFirstStartCompleted )
       
  1648 	    {
       
  1649 	    DoFirstStartL();
       
  1650 	    }
       
  1651     // set when editor was called so reset is needed i.e. here (Called by DoActivate)
       
  1652    	iMailOpened = EFalse; 
       
  1653 
       
  1654     // Make sure that pending popup is not displayd
       
  1655 	if ( iAppUi.FolderList().IsPopupShown() )
       
  1656         {
       
  1657         iAppUi.FolderList().HidePopupL();
       
  1658         }
       
  1659     DisableMailList( EFalse );
       
  1660 
       
  1661 	// inform baseView if view entered with forward navigation
       
  1662 	TBool forwardNavigation = EFalse;
       
  1663 	if ( aCustomMessageId != KStartListReturnToPreviousFolder &&
       
  1664 	     aCustomMessageId != TUid::Uid(KMailSettingsReturnFromPluginSettings) )
       
  1665 	    {
       
  1666 	    ViewEntered( aPrevViewId );
       
  1667 	    forwardNavigation = ETrue;
       
  1668 	    }
       
  1669 
       
  1670 	if( iAppUi.CurrentFixedToolbar() )
       
  1671 	    {
       
  1672         iAppUi.CurrentFixedToolbar()->SetToolbarVisibility( EFalse );
       
  1673 	    }
       
  1674 
       
  1675     // Set control bar and list layout size always in activation
       
  1676     TRect clientRect = iAppUi.ClientRect();
       
  1677     iScreenAnchorLayout->SetSize( clientRect.Size() );
       
  1678     SetMailListLayoutAnchors();
       
  1679     //if the view is already active don't update the icons so they won't "blink" 
       
  1680     //when the view is activated.
       
  1681     if(!iThisViewActive)
       
  1682         {     
       
  1683         ScaleControlBarL();
       
  1684         
       
  1685         // Set icons on toolbar
       
  1686         iAppUi.FsTextureManager()->ClearTextureByIndex( EListControlBarMailboxDefaultIcon );
       
  1687         iFolderListButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( EListControlBarMailboxDefaultIcon ) );
       
  1688         iAppUi.FsTextureManager()->ClearTextureByIndex( EListTextureCreateNewMessageIcon );
       
  1689         iNewEmailButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( EListTextureCreateNewMessageIcon ) );
       
  1690         iAppUi.FsTextureManager()->ClearTextureByIndex( GetSortButtonTextureIndex() );
       
  1691         iSortButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( GetSortButtonTextureIndex() ) );
       
  1692 
       
  1693         SetListAndCtrlBarFocusL();
       
  1694         }
       
  1695 
       
  1696 	FadeOut(EFalse); // we can show now CAlfVisuals from CurrentView (to show Folders before updating emails)
       
  1697     
       
  1698 	// Update mail list settings and date formats, is done every time
       
  1699 	// the user might have changed these in settings, so the list needs to refresh
       
  1700 	// Store previous modes
       
  1701 	TInt prevListMode = iListMode;
       
  1702 	TInt prevNodesmode = iNodesInUse;
       
  1703 	TAknUiZoom prevZoomLevel = iCurrentZoomLevel;
       
  1704 	STimeDateFormats prevDateFormats = MailListTimeDateSettings();
       
  1705 
       
  1706 	// Get new settings and list drawing modes
       
  1707     CAknEnv::Static()->GetCurrentGlobalUiZoom( iCurrentZoomLevel );
       
  1708 	UpdateMailListSettingsL();
       
  1709 	UpdateMailListTimeDateSettings();
       
  1710 
       
  1711 	// Check for changed settings, in that case a complete list refresh is needed
       
  1712 	TRefreshState refreshState = ERefreshNone;
       
  1713 	if (aCustomMessageId == KStartListWithFolderIdFromHomeScreen)
       
  1714 	    {
       
  1715             refreshState = EFocusChangeNeeded;
       
  1716 	    }
       
  1717 	
       
  1718 	if ( iSkinChanged
       
  1719 	     || iDateChanged
       
  1720 	     || iListMode != prevListMode
       
  1721 		 || iNodesInUse != prevNodesmode
       
  1722 		 || iCurrentZoomLevel != prevZoomLevel
       
  1723 		 || prevDateFormats.iDateFormat != iDateFormats.iDateFormat
       
  1724 		 || prevDateFormats.iTimeFormat != iDateFormats.iTimeFormat
       
  1725 		 || prevDateFormats.iAmPmPosition != iDateFormats.iAmPmPosition
       
  1726 		 || prevDateFormats.iDateSeparator.GetNumericValue() != iDateFormats.iDateSeparator.GetNumericValue()
       
  1727 		 || prevDateFormats.iTimeSeparator.GetNumericValue() != iDateFormats.iTimeSeparator.GetNumericValue() )
       
  1728 		{
       
  1729         refreshState = EFullRefreshNeeded;
       
  1730 		iSkinChanged = EFalse;
       
  1731 		iDateChanged = EFalse;
       
  1732 		}
       
  1733 
       
  1734 	// Store previously used mailbox and folder IDs
       
  1735 	TFSMailMsgId prevMailBoxId = iAppUi.GetActiveMailboxId();
       
  1736 	TFSMailMsgId prevFolderId = FolderId();
       
  1737 
       
  1738     CFSMailClient* mailClient = iAppUi.GetMailClient();
       
  1739     User::LeaveIfNull( mailClient ); // we can't go on if no mail client is available
       
  1740 
       
  1741 	// FIGURE OUT WHICH FOLDER TO ACTIVATE
       
  1742     TMailListActivationData activationData;
       
  1743 
       
  1744     // Opening folder given in custom message
       
  1745     if ( aCustomMessage.Length() )
       
  1746         {
       
  1747         TPckgBuf<TMailListActivationData> viewData;
       
  1748         viewData.Copy( aCustomMessage );
       
  1749         activationData = viewData();
       
  1750         }
       
  1751 
       
  1752     // Returning to previous folder
       
  1753     if ( aCustomMessageId == KStartListReturnToPreviousFolder ||
       
  1754          aCustomMessageId == TUid::Uid(KMailSettingsReturnFromPluginSettings) )
       
  1755         {
       
  1756         activationData.iMailBoxId = prevMailBoxId;
       
  1757         activationData.iFolderId = prevFolderId;
       
  1758         }
       
  1759 
       
  1760     // Proper mailbox ID is not given in custom message. Try using MSV session.
       
  1761     if ( activationData.iMailBoxId.IsNullId() )
       
  1762         {
       
  1763         CMsvSession* msvSession = iAppUi.GetMsvSession();
       
  1764         CFSMailBox* mailBox = NULL;
       
  1765 
       
  1766         if ( msvSession )
       
  1767             {
       
  1768             // MSV id is passed to us in aCustomMessageId when activation happens by email key
       
  1769             if ( aCustomMessageId != TUid::Null() )
       
  1770                 {
       
  1771                 // <cmail>
       
  1772                 TInt error = KErrNone;
       
  1773                 TRAP( error, mailBox = TFsEmailUiUtility::GetMailboxForMtmIdL( *mailClient, *msvSession, aCustomMessageId.iUid ) );
       
  1774                 // </cmail>
       
  1775                 if ( mailBox )
       
  1776                     {
       
  1777                     activationData.iMailBoxId = mailBox->GetId();
       
  1778                     delete mailBox;
       
  1779                     mailBox = NULL;
       
  1780                     }
       
  1781                 }
       
  1782 
       
  1783             // Try to get MCE default mailbox if we still haven't got any other box
       
  1784             if ( activationData.iMailBoxId.IsNullId() )
       
  1785                 {
       
  1786                 // <cmail>
       
  1787                 TInt error = KErrNone;
       
  1788                 TRAP( error, mailBox = TFsEmailUiUtility::GetMceDefaultMailboxL( *mailClient, *msvSession ) );
       
  1789                 // </cmail>
       
  1790                 if ( mailBox )
       
  1791                     {
       
  1792                     activationData.iMailBoxId = mailBox->GetId();
       
  1793                     delete mailBox;
       
  1794                     mailBox = NULL;
       
  1795                     }
       
  1796                 }
       
  1797             }
       
  1798 
       
  1799         }
       
  1800 
       
  1801     // If still no mailbox then use first from the list of the framework
       
  1802     if ( activationData.iMailBoxId.IsNullId() )
       
  1803         {
       
  1804         TFSMailMsgId id;
       
  1805         RPointerArray<CFSMailBox> mailboxes;
       
  1806         CleanupResetAndDestroyClosePushL( mailboxes );
       
  1807         mailClient->ListMailBoxes( id, mailboxes );
       
  1808         if ( mailboxes.Count() > 0 )
       
  1809             {
       
  1810             activationData.iMailBoxId = mailboxes[0]->GetId();
       
  1811             }
       
  1812         CleanupStack::PopAndDestroy( &mailboxes );
       
  1813         }
       
  1814 
       
  1815 
       
  1816     // Check if we got any mailbox
       
  1817     if ( activationData.iMailBoxId.IsNullId() )
       
  1818         {
       
  1819         // could not get mailbox so leave
       
  1820         User::Leave( KErrGeneral );
       
  1821         }
       
  1822     else
       
  1823         {
       
  1824         // Set the active mailbox of AppUi. Do this also when mailbox hasn't actually
       
  1825         // changed to do the autoconnect when necessary and to verify that the previously
       
  1826         // active mailbox is still valid.
       
  1827         // Leave is caused if mailbox is no longer available, and BaseView will take care
       
  1828         // of the error handling.
       
  1829         iAppUi.SetActiveMailboxL( activationData.iMailBoxId, forwardNavigation );
       
  1830 
       
  1831         // we got mailbox but no folder has been given => use Inbox
       
  1832         if ( activationData.iFolderId.IsNullId() ||
       
  1833              activationData.iFolderId.Id() == 0 )
       
  1834             {
       
  1835             activationData.iFolderId = iAppUi.GetActiveBoxInboxId();
       
  1836             }
       
  1837         }
       
  1838 
       
  1839     // NOW WE HAVE A VALID MAILBOX AND FOLDER ID.
       
  1840     // Tries to create an extension for the Ozone plugin
       
  1841     CreateExtensionL();
       
  1842 
       
  1843     // if mailbox changed stop timer driven insertion of new mails into list
       
  1844     if ( activationData.iMailBoxId != prevMailBoxId )
       
  1845         {
       
  1846         iNewMailTimer->Cancel();
       
  1847         iSortTimer->Cancel(); // stop sorting timer
       
  1848         iNewMailIds.Reset();
       
  1849         }
       
  1850 
       
  1851     // CHECK IF MODEL NEEDS TO BE UPDATED
       
  1852     if ( activationData.iMailBoxId != prevMailBoxId ||
       
  1853          activationData.iFolderId != prevFolderId ||
       
  1854          activationData.iRequestRefresh ||
       
  1855          iForceRefresh )
       
  1856          {
       
  1857          iForceRefresh = EFalse;
       
  1858          // Set initial sort criteria when folder is changed
       
  1859          iCurrentSortCriteria.iField = EFSMailSortByDate;
       
  1860          iCurrentSortCriteria.iOrder = EFSMailDescending;
       
  1861          SetSortButtonTextAndIconL();
       
  1862 
       
  1863          SafeDelete(iMailFolder);
       
  1864          TRAP_IGNORE( iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL(
       
  1865                  activationData.iMailBoxId, activationData.iFolderId ) );
       
  1866          if ( !iMailFolder )
       
  1867              {
       
  1868              if ( forwardNavigation )
       
  1869                  {
       
  1870                  iAppUi.StartMonitoringL();
       
  1871                  }
       
  1872              // Safety, try to revert back to standard folder inbox
       
  1873              TFSMailMsgId inboxId = iAppUi.GetActiveMailbox()->GetStandardFolderId( EFSInbox );
       
  1874              iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( activationData.iMailBoxId, inboxId );
       
  1875              }
       
  1876          HBufC* newFolderName = CreateFolderNameLC( iMailFolder );
       
  1877          iFolderListButton->SetTextL( *newFolderName );
       
  1878          CleanupStack::PopAndDestroy( newFolderName );
       
  1879          iMailList->SetFocusedItemL( KFsTreeNoneID );
       
  1880          refreshState = EFullRefreshNeeded;
       
  1881          }
       
  1882 
       
  1883     // Set mailbox name to status pane
       
  1884     SetMailboxNameToStatusPaneL();
       
  1885 
       
  1886     // Set branded watermark and mailbox icon
       
  1887     SetBrandedListWatermarkL();
       
  1888     SetBrandedMailBoxIconL();
       
  1889     
       
  1890     // Check sync icon timer and sync status
       
  1891     ConnectionIconHandling();
       
  1892 
       
  1893     // REBUILD TREE LIST IF NECESSARY
       
  1894     if ( refreshState == EFullRefreshNeeded )
       
  1895         {
       
  1896         // Try to maintain previously active item if possible.
       
  1897         // This is of course not possible if folder has changed.
       
  1898         TFSMailMsgId focused = MsgIdFromListId( iMailList->FocusedItem() );
       
  1899 
       
  1900         // Clear any previous items from the screen and then make the view visible
       
  1901         iMailList->BeginUpdate();
       
  1902         iMailList->RemoveAllL();
       
  1903         iTreeItemArray.Reset();
       
  1904         iModel->Reset();
       
  1905         iMailList->EndUpdateL();
       
  1906         iMailList->ShowListL();
       
  1907 
       
  1908         // If coming from wizard use synchronous list updating
       
  1909         if (activationData.iReturnAfterWizard)
       
  1910             {
       
  1911             UpdateMailListModelL();
       
  1912             }
       
  1913         else
       
  1914             {
       
  1915             UpdateMailListModelAsyncL( KCMsgBlockSort );
       
  1916             }
       
  1917         }
       
  1918     else if(refreshState == EFocusChangeNeeded)
       
  1919         {//Move focus to the beginning of the list
       
  1920         TInt firstIndex(0);
       
  1921         TFsTreeItemId firstItemId(KFsTreeNoneID);
       
  1922         if ( iMailList->CountChildren( KFsTreeRootID ) )
       
  1923             {
       
  1924             firstItemId = iMailList->Child( KFsTreeRootID, firstIndex );
       
  1925             }
       
  1926         iMailTreeListVisualizer->SetFocusedItemL( firstItemId, EFalse );
       
  1927         //if the view is already active don't update the list so it won't "blink" 
       
  1928         //when the view is activated.
       
  1929         if(!iThisViewActive)
       
  1930             {
       
  1931             iMailList->ShowListL();
       
  1932             }
       
  1933         }
       
  1934     // THE CORRECT FOLDER IS ALREADY OPEN. CHECK IF SOME PARTIAL UPDATE IS NEEDED.
       
  1935     else
       
  1936         {
       
  1937         iMailList->ShowListL();
       
  1938         TBool manualSync = CheckAutoSyncSettingL();
       
  1939         if (forwardNavigation && !manualSync)
       
  1940             {
       
  1941             iAppUi.StartMonitoringL();
       
  1942             }
       
  1943         SetListAndCtrlBarFocusL(); // ShowListL() makes list focused and this may need to be reverted
       
  1944         if ( aCustomMessageId == TUid::Uid(KMailSettingsReturnFromPluginSettings) )
       
  1945             {
       
  1946             // Better to refresh launcher grid view because mailbox branding might be changed.
       
  1947             iAppUi.LauncherGrid().SetRefreshNeeded();
       
  1948             }
       
  1949         // Check the validity of focused message, it may be deleted or
       
  1950         // reply/forward, read/unread status might have changed in editor or viewer
       
  1951         UpdateItemAtIndexL( HighlightedIndex() );
       
  1952         SetMskL();
       
  1953         }
       
  1954 
       
  1955     iCurrentClientRect = clientRect;
       
  1956 	iThisViewActive = ETrue;
       
  1957 	
       
  1958 	//emailindicator handling, is removed from 9.2
       
  1959 	//TRAP_IGNORE(TFsEmailStatusPaneIndicatorHandler::StatusPaneMailIndicatorHandlingL( activationData.iMailBoxId.Id()));
       
  1960 	    
       
  1961     //Update mailbox widget index status in homescreen
       
  1962     TFsEmailUiUtility::ToggleEmailIconL(EFalse, activationData.iMailBoxId );
       
  1963 
       
  1964 	iShiftDepressed = EFalse; // clear state just in case
       
  1965 
       
  1966 	// Inform MR observer if needed, special MR case, returning from attachment list
       
  1967 	iAppUi.MailViewer().CompletePendingMrCommand();
       
  1968 
       
  1969 	// Make sure that correct component is set to focused.
       
  1970 	if ( iFocusedControl == EMailListComponent )
       
  1971 	    {
       
  1972 	    SetTreeListFocusedL();
       
  1973 	    }
       
  1974 	else
       
  1975 	    {
       
  1976 	    SetControlBarFocusedL();
       
  1977 	    iControlBarControl->MakeSelectorVisible( iAppUi.IsFocusShown() );
       
  1978 	    }
       
  1979 	UpdateButtonTextsL();
       
  1980 	FocusVisibilityChange( iAppUi.IsFocusShown() );
       
  1981 	iAppUi.ShowTitlePaneConnectionStatus();
       
  1982 	TIMESTAMP( "Message list view opened" );
       
  1983 	}
       
  1984 
       
  1985 // ---------------------------------------------------------------------------
       
  1986 // Sets status bar layout
       
  1987 // ---------------------------------------------------------------------------
       
  1988 //
       
  1989 void CFSEmailUiMailListVisualiser::SetStatusBarLayout()
       
  1990 	{
       
  1991     TInt res = R_AVKON_STATUS_PANE_LAYOUT_USUAL_FLAT;
       
  1992     if( Layout_Meta_Data::IsLandscapeOrientation() )
       
  1993         {
       
  1994         // landscape must use different layout
       
  1995 		res = R_AVKON_STATUS_PANE_LAYOUT_USUAL_EXT;
       
  1996         }
       
  1997 
       
  1998 	if ( StatusPane()->CurrentLayoutResId() != res )
       
  1999 		{
       
  2000 		TRAP_IGNORE(
       
  2001 			StatusPane()->SwitchLayoutL( res ));
       
  2002 		}
       
  2003 	}
       
  2004 
       
  2005 
       
  2006 // ---------------------------------------------------------------------------
       
  2007 //
       
  2008 //
       
  2009 // ---------------------------------------------------------------------------
       
  2010 //
       
  2011 void CFSEmailUiMailListVisualiser::ChildDoDeactivate()
       
  2012 	{
       
  2013     FUNC_LOG;
       
  2014     if (iMailListModelUpdater)
       
  2015         {
       
  2016         iMailListModelUpdater->Cancel();
       
  2017         }
       
  2018 	if ( !iAppUi.AppUiExitOngoing() )
       
  2019   	    {
       
  2020   	    TRAP_IGNORE( {
       
  2021             iMailList->HideListL();
       
  2022             iMailList->SetFocusedL( EFalse );
       
  2023   	        } );
       
  2024   	    iMailTreeListVisualizer->NotifyControlVisibilityChange( EFalse );
       
  2025   	    }
       
  2026 	iThisViewActive = EFalse;
       
  2027 	}
       
  2028 
       
  2029 // ---------------------------------------------------------------------------
       
  2030 //
       
  2031 //
       
  2032 // ---------------------------------------------------------------------------
       
  2033 //
       
  2034 CFSEmailUiMailListModel* CFSEmailUiMailListVisualiser::Model()
       
  2035 	{
       
  2036     FUNC_LOG;
       
  2037 	return iModel;
       
  2038 	}
       
  2039 
       
  2040 // ---------------------------------------------------------------------------
       
  2041 //
       
  2042 //
       
  2043 // ---------------------------------------------------------------------------
       
  2044 //
       
  2045 TFSMailMsgId CFSEmailUiMailListVisualiser::FolderId()
       
  2046 	{
       
  2047     FUNC_LOG;
       
  2048 	TFSMailMsgId folderId; // constructs null ID
       
  2049 	if ( iMailFolder )
       
  2050 	    {
       
  2051 	    folderId = iMailFolder->GetFolderId();
       
  2052 	    }
       
  2053 	return folderId;
       
  2054 	}
       
  2055 
       
  2056 // ---------------------------------------------------------------------------
       
  2057 //
       
  2058 //
       
  2059 // ---------------------------------------------------------------------------
       
  2060 //
       
  2061 void CFSEmailUiMailListVisualiser::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
       
  2062 	{
       
  2063     FUNC_LOG;
       
  2064 	CompletePendingRefresh();
       
  2065 
       
  2066 	// Get the list of items which will be targetted by the actions menu commands
       
  2067 	RFsTreeItemIdList targetEntries;
       
  2068 	CleanupClosePushL( targetEntries );
       
  2069 	GetActionsTargetEntriesL( targetEntries );
       
  2070 
       
  2071 	TBool supportsMoving = iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaMoveToFolder );
       
  2072 	TBool supportsFlag = TFsEmailUiUtility::IsFollowUpSupported( *iAppUi.GetActiveMailbox() );
       
  2073 
       
  2074 	TInt currentFolderType = KErrNotFound;
       
  2075 	if ( iMailFolder )
       
  2076 	    {
       
  2077 	    currentFolderType = iMailFolder->GetFolderType();
       
  2078 	    }
       
  2079 
       
  2080 	if ( aResourceId == R_FSEMAILUI_MAILLIST_MARKING_MODE_MENUPANE )
       
  2081 	    {
       
  2082         if (!CountMarkedItemsL())
       
  2083             {
       
  2084             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeDelete, ETrue );
       
  2085             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeUnread, ETrue );
       
  2086             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeRead, ETrue );
       
  2087             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeMove, ETrue );
       
  2088             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeFollowUp, ETrue );
       
  2089             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeMarkAll, EFalse );
       
  2090             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeUnmarkAll, ETrue );
       
  2091             }
       
  2092         else
       
  2093             {
       
  2094             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeDelete, EFalse );
       
  2095             if ( AreAllMarkedItemsUnreadL() )
       
  2096                 {
       
  2097                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeUnread, ETrue );
       
  2098                 }
       
  2099             else
       
  2100                 {
       
  2101                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeUnread, EFalse );
       
  2102                 }
       
  2103             if ( AreAllMarkedItemsReadL() )
       
  2104                 {            
       
  2105                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeRead, ETrue );
       
  2106                 }
       
  2107             else
       
  2108                 {
       
  2109                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeRead, EFalse );
       
  2110                 }
       
  2111             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeMove, !supportsMoving );
       
  2112             aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeFollowUp, !supportsFlag );            
       
  2113             if ( AreAllItemsMarked() )
       
  2114                 {
       
  2115                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeMarkAll, ETrue );
       
  2116                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeUnmarkAll, EFalse );
       
  2117                 }
       
  2118             else if ( AreAllItemsUnmarked() )
       
  2119                 {
       
  2120                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeMarkAll, EFalse );
       
  2121                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeUnmarkAll, ETrue );
       
  2122                 }
       
  2123             else
       
  2124                 {
       
  2125                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeMarkAll, EFalse );
       
  2126                 aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingModeUnmarkAll, EFalse );
       
  2127                 }                
       
  2128             }
       
  2129 	    }
       
  2130 	
       
  2131     // MAIN MENU ***************************************************************************
       
  2132 	if ( aResourceId == R_FSEMAILUI_MAILLIST_MENUPANE )
       
  2133 	    {
       
  2134 		// Saves a focus visibility.
       
  2135 		iLastFocus = EFalse;
       
  2136 		if( iFocusedControl == EMailListComponent && IsFocusShown() )
       
  2137 		    {
       
  2138 		    iLastFocus = ETrue;
       
  2139 		    }
       
  2140 	    if (FeatureManager::FeatureSupported( KFeatureIdFfCmailIntegration ))
       
  2141 		   {
       
  2142 		   // remove help support in pf5250
       
  2143 		   aMenuPane->SetItemDimmed( EFsEmailUiCmdHelp, ETrue);
       
  2144 		   }
       
  2145 
       
  2146 	    // Checks if a device has a keyboard or not.
       
  2147 		if( !iLastFocus )
       
  2148     	    {
       
  2149             // Hide all the normal email message specific actions
       
  2150             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsReply, ETrue );
       
  2151             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsReplyAll, ETrue );
       
  2152             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsForward, ETrue );
       
  2153             aMenuPane->SetItemDimmed( EFsEmailUiCmdMailActions, ETrue);
       
  2154             }
       
  2155         else
       
  2156     	    {
       
  2157     		CFSMailMessage* targetMessage = NULL;
       
  2158             if ( targetEntries.Count() == 1 )
       
  2159                 {
       
  2160                 targetMessage = &MsgPtrFromListIdL( targetEntries[0] );
       
  2161                 }
       
  2162 
       
  2163             // Hide the irrelevant reply / reply all / forward commands
       
  2164             TInt numRecipients(0);
       
  2165             if ( targetMessage )
       
  2166                 {
       
  2167                 //Get # of recipients
       
  2168                 numRecipients = TFsEmailUiUtility::CountRecipientsSmart( iAppUi, targetMessage );
       
  2169                 }
       
  2170             // All reply/forward options are hidden when multiple marked messages or folder is outbox or drafts
       
  2171             if ( targetEntries.Count() != 1 ||
       
  2172                  currentFolderType == EFSOutbox ||
       
  2173                  currentFolderType == EFSDraftsFolder )
       
  2174                 {
       
  2175                 aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsReply, ETrue );
       
  2176                 aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsReplyAll, ETrue );
       
  2177                 aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsForward, ETrue );
       
  2178                 }
       
  2179 
       
  2180             // Reply all is hidden also when the single target message has multiple recipients
       
  2181             else if ( !targetMessage || numRecipients <= 1 )
       
  2182                 {
       
  2183                 aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsReplyAll, ETrue );
       
  2184                 }
       
  2185             }
       
  2186 
       
  2187 	    // EMPTY LIST, MOST OPTIONS ARE HIDDEN
       
  2188 	    if ( !iModel->Count() || !iMailFolder )
       
  2189 	        {
       
  2190 	        aMenuPane->SetItemDimmed( EFsEmailUiCmdMailActions, ETrue );
       
  2191 	        aMenuPane->SetItemDimmed( EFsEmailUiCmdSearch, ETrue );
       
  2192 	        aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkingMode, ETrue );
       
  2193 	        }
       
  2194 
       
  2195 	    // FOLDER SPECIFIC COMMAND HIDING
       
  2196 	    // "Clear deleted folder" command is available only in Deleted folder
       
  2197 	    if ( currentFolderType != EFSDeleted || !iModel->Count() )
       
  2198 	        {
       
  2199 	        aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsEmptyDeleted, ETrue );
       
  2200 	        }
       
  2201 	    
       
  2202 	    CConnectionStatusQueryExtension::TConnectionStatus connetionStatus;
       
  2203         iAppUi.GetConnectionStatusL( connetionStatus );
       
  2204         if ( connetionStatus == CConnectionStatusQueryExtension::ESynchronizing )
       
  2205             {
       
  2206             aMenuPane->SetItemDimmed( EFsEmailUiCmdSync, ETrue );
       
  2207             aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelSync, EFalse );
       
  2208             }
       
  2209         else
       
  2210             {
       
  2211             aMenuPane->SetItemDimmed( EFsEmailUiCmdSync, EFalse );
       
  2212             aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelSync, ETrue );
       
  2213             }
       
  2214 	    }
       
  2215 	
       
  2216     // MAIN MENU ***************************************************************************
       
  2217 
       
  2218 
       
  2219 	// ACTIONS SUBMENU *********************************************************************
       
  2220 	if ( aResourceId == R_FSEMAILUI_MAILLIST_SUBMENU_MAIL_ACTIONS  )
       
  2221 		{
       
  2222         // COMMON PART OF ACTIONS SUBMENU
       
  2223 		aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsRead, !IsMarkAsReadAvailableL() );
       
  2224         aMenuPane->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, !IsMarkAsUnreadAvailableL() );
       
  2225 
       
  2226 		if ( !supportsMoving || !iMailFolder ) // Hide move from actions if not supported
       
  2227 			{
       
  2228 			aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsMove, ETrue );
       
  2229 			}
       
  2230 		else
       
  2231 			{
       
  2232 			// Moving supported, show/hide moving options depending on the current folder
       
  2233 			// Check for outbox case
       
  2234 			if ( currentFolderType == EFSOutbox )
       
  2235 				{
       
  2236 				// moving from outbox is not allowed otherwise
       
  2237 				aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsMove, ETrue );
       
  2238 				}
       
  2239 			// Handle rest of the folders
       
  2240 			else
       
  2241 				{
       
  2242 				aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsMove, EFalse );
       
  2243 				}
       
  2244 			}
       
  2245 
       
  2246 		TInt markedCount = CountMarkedItemsL();
       
  2247 
       
  2248 	    // Hide expand/collapse all when not applicable
       
  2249 		if ( iNodesInUse == EListControlSeparatorDisabled || !iModel->Count() )
       
  2250 			{
       
  2251 			aMenuPane->SetItemDimmed(EFsEmailUiCmdActionsCollapseAll, ETrue);
       
  2252 			aMenuPane->SetItemDimmed(EFsEmailUiCmdActionsExpandAll, ETrue);
       
  2253 			}
       
  2254 		else
       
  2255 			{
       
  2256 			aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsCollapseAll, AllNodesCollapsed() );
       
  2257 			aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsExpandAll, AllNodesExpanded() );
       
  2258 			}
       
  2259 
       
  2260 		// Hide followup flagging if not applicable
       
  2261 		if ( !supportsFlag || !targetEntries.Count() )
       
  2262 		    {
       
  2263 		    aMenuPane->SetItemDimmed(EFsEmailUiCmdActionsFlag, ETrue);
       
  2264 		    }
       
  2265 
       
  2266 	    // Some commands are hidden in the outbox and drafts folders
       
  2267         if ( currentFolderType == EFSOutbox ||
       
  2268              currentFolderType == EFSDraftsFolder )
       
  2269             {
       
  2270             aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsFlag, ETrue );
       
  2271             }
       
  2272 		}
       
  2273     // ACTIONS SUBMENU *********************************************************************
       
  2274 
       
  2275 	CleanupStack::PopAndDestroy( &targetEntries );
       
  2276 
       
  2277 	// Add shortcut hints
       
  2278 	iAppUi.ShortcutBinding().AppendShortcutHintsL( *aMenuPane,
       
  2279 	                             CFSEmailUiShortcutBinding::EContextMailList );
       
  2280 	}
       
  2281 
       
  2282 // ---------------------------------------------------------------------------
       
  2283 //
       
  2284 //
       
  2285 // ---------------------------------------------------------------------------
       
  2286 //
       
  2287 void CFSEmailUiMailListVisualiser::MarkAllItemsL()
       
  2288 	{
       
  2289     FUNC_LOG;
       
  2290 	if ( iTreeItemArray.Count() )
       
  2291 		{
       
  2292 		for ( TInt i=0;i<iTreeItemArray.Count(); i++ )
       
  2293 			{
       
  2294 			if ( !iMailList->IsNode(iTreeItemArray[i].iListItemId ) )
       
  2295 				{
       
  2296 		       	iMailList->MarkItemL( iTreeItemArray[i].iListItemId, ETrue );
       
  2297 				}
       
  2298 			}
       
  2299 		}
       
  2300 	}
       
  2301 
       
  2302 // ---------------------------------------------------------------------------
       
  2303 //
       
  2304 //
       
  2305 // ---------------------------------------------------------------------------
       
  2306 //
       
  2307 void CFSEmailUiMailListVisualiser::UnmarkAllItemsL()
       
  2308 	{
       
  2309     FUNC_LOG;
       
  2310 	for ( TInt i=0 ; i<iTreeItemArray.Count() ; i++ )
       
  2311 	    {
       
  2312 	    if ( !iMailList->IsNode(iTreeItemArray[i].iListItemId) )
       
  2313 	        {
       
  2314 	        iMailList->MarkItemL( iTreeItemArray[i].iListItemId, EFalse );
       
  2315 	        }
       
  2316 	    }
       
  2317 	}
       
  2318 
       
  2319 // ---------------------------------------------------------------------------
       
  2320 //
       
  2321 //
       
  2322 // ---------------------------------------------------------------------------
       
  2323 //
       
  2324 TInt CFSEmailUiMailListVisualiser::CountMarkedItemsL()
       
  2325     {
       
  2326     FUNC_LOG;
       
  2327     RFsTreeItemIdList markedEntries;
       
  2328     CleanupClosePushL( markedEntries );
       
  2329     iMailList->GetMarkedItemsL( markedEntries );
       
  2330     TInt count = markedEntries.Count();
       
  2331     CleanupStack::PopAndDestroy( &markedEntries );
       
  2332     return count;
       
  2333     }
       
  2334 
       
  2335 // ---------------------------------------------------------------------------
       
  2336 //
       
  2337 //
       
  2338 // ---------------------------------------------------------------------------
       
  2339 //
       
  2340 TBool CFSEmailUiMailListVisualiser::AreAllItemsMarked()
       
  2341     {
       
  2342     FUNC_LOG;
       
  2343 
       
  2344     TBool ret(ETrue);
       
  2345     
       
  2346 	if ( iTreeItemArray.Count() )
       
  2347 		{
       
  2348 		for ( TInt i=0;i<iTreeItemArray.Count(); i++ )
       
  2349 			{
       
  2350 			if ( !iMailList->IsNode(iTreeItemArray[i].iListItemId ) &&
       
  2351 			     !iMailList->IsMarked( iTreeItemArray[i].iListItemId ))
       
  2352                 {
       
  2353 				ret = EFalse;
       
  2354 				break;    
       
  2355 				}
       
  2356 			}
       
  2357 		}
       
  2358     return ret;
       
  2359     }
       
  2360 
       
  2361 // ---------------------------------------------------------------------------
       
  2362 //
       
  2363 //
       
  2364 // ---------------------------------------------------------------------------
       
  2365 //
       
  2366 TBool CFSEmailUiMailListVisualiser::AreAllItemsUnmarked()
       
  2367     {
       
  2368     FUNC_LOG;
       
  2369 
       
  2370     TBool ret(ETrue);
       
  2371     
       
  2372 	if ( iTreeItemArray.Count() )
       
  2373 		{
       
  2374 		for ( TInt i=0;i<iTreeItemArray.Count(); i++ )
       
  2375 			{
       
  2376 			if ( !iMailList->IsNode(iTreeItemArray[i].iListItemId ) &&
       
  2377 			     iMailList->IsMarked( iTreeItemArray[i].iListItemId ))
       
  2378                 {
       
  2379 				ret = EFalse;
       
  2380 				break;    
       
  2381 				}
       
  2382 			}
       
  2383 		}
       
  2384     return ret;
       
  2385     }
       
  2386 
       
  2387 // ---------------------------------------------------------------------------
       
  2388 //
       
  2389 //
       
  2390 // ---------------------------------------------------------------------------
       
  2391 //
       
  2392 TBool CFSEmailUiMailListVisualiser::AreAllMarkedItemsReadL()
       
  2393     {
       
  2394     FUNC_LOG;
       
  2395 
       
  2396     TBool ret(ETrue);
       
  2397     
       
  2398 	if ( iTreeItemArray.Count() )
       
  2399 		{
       
  2400         for ( TInt i=0;i<iTreeItemArray.Count(); i++ )
       
  2401             {
       
  2402             if ( !iMailList->IsNode(iTreeItemArray[i].iListItemId ) &&
       
  2403                 iMailList->IsMarked( iTreeItemArray[i].iListItemId ))
       
  2404                 {
       
  2405                 CFSEmailUiMailListModelItem* item =
       
  2406                         static_cast<CFSEmailUiMailListModelItem*>( Model()->Item(i) );
       
  2407                 if ( item ) // Safety
       
  2408                     {
       
  2409                     CFSMailMessage* confirmedMsgPtr(0);
       
  2410                     confirmedMsgPtr = iAppUi.GetMailClient()->GetMessageByUidL(iAppUi.GetActiveMailboxId(),
       
  2411                     iMailFolder->GetFolderId(), item->MessagePtr().GetMessageId(), EFSMsgDataEnvelope );
       
  2412                     TBool isReadMessage = confirmedMsgPtr->IsFlagSet( EFSMsgFlag_Read );
       
  2413                     delete confirmedMsgPtr;
       
  2414                     if ( !isReadMessage )
       
  2415                         {
       
  2416                         ret = EFalse;
       
  2417                         break;
       
  2418                         }
       
  2419                     }
       
  2420                 }
       
  2421             }
       
  2422 		}
       
  2423     return ret;
       
  2424     }
       
  2425 
       
  2426 // ---------------------------------------------------------------------------
       
  2427 //
       
  2428 //
       
  2429 // ---------------------------------------------------------------------------
       
  2430 //
       
  2431 TBool CFSEmailUiMailListVisualiser::AreAllMarkedItemsUnreadL()
       
  2432     {
       
  2433     FUNC_LOG;
       
  2434 
       
  2435     TBool ret(ETrue);
       
  2436     
       
  2437     if ( iTreeItemArray.Count() )
       
  2438         {
       
  2439         for ( TInt i=0;i<iTreeItemArray.Count(); i++ )
       
  2440             {
       
  2441             if ( !iMailList->IsNode(iTreeItemArray[i].iListItemId ) &&
       
  2442                 iMailList->IsMarked( iTreeItemArray[i].iListItemId ))
       
  2443                 {
       
  2444                 CFSEmailUiMailListModelItem* item =
       
  2445                         static_cast<CFSEmailUiMailListModelItem*>( Model()->Item(i) );
       
  2446                 if ( item ) // Safety
       
  2447                     {
       
  2448                     CFSMailMessage* confirmedMsgPtr(0);
       
  2449                     confirmedMsgPtr = iAppUi.GetMailClient()->GetMessageByUidL(iAppUi.GetActiveMailboxId(),
       
  2450                     iMailFolder->GetFolderId(), item->MessagePtr().GetMessageId(), EFSMsgDataEnvelope );
       
  2451                     TBool isReadMessage = confirmedMsgPtr->IsFlagSet( EFSMsgFlag_Read );
       
  2452                     delete confirmedMsgPtr;
       
  2453                     if ( isReadMessage )
       
  2454                         {
       
  2455                         ret = EFalse;
       
  2456                         break;
       
  2457                         }
       
  2458                     }
       
  2459                 }
       
  2460             }
       
  2461         }
       
  2462     return ret;
       
  2463     }
       
  2464 
       
  2465 // ---------------------------------------------------------------------------
       
  2466 //
       
  2467 //
       
  2468 // ---------------------------------------------------------------------------
       
  2469 //
       
  2470 void CFSEmailUiMailListVisualiser::GetMarkedMessagesL( RArray<TFSMailMsgId>& aMessageIDs ) const
       
  2471     {
       
  2472     FUNC_LOG;
       
  2473     aMessageIDs.Reset();
       
  2474 
       
  2475 	RFsTreeItemIdList markedEntries;
       
  2476 	CleanupClosePushL( markedEntries );
       
  2477 	iMailList->GetMarkedItemsL( markedEntries );
       
  2478 
       
  2479 	for ( TInt i=0 ; i<markedEntries.Count() ; ++i )
       
  2480 	    {
       
  2481 	    // This could be optimized if we could be certain that the order of the
       
  2482 	    // marked entries is the same as the order in the message list. This is
       
  2483 	    // probably true, but the interface does not guarantee that. Now the
       
  2484 	    // time counsumption is Theta(n*m) while Theta(n+m) could be possible
       
  2485 	    TFSMailMsgId messageId = MsgIdFromListId( markedEntries[i] );
       
  2486 	    if ( !messageId.IsNullId() )
       
  2487 	        {
       
  2488 	        aMessageIDs.Append( messageId );
       
  2489 	        }
       
  2490 	    }
       
  2491 
       
  2492 	CleanupStack::PopAndDestroy( &markedEntries );
       
  2493     }
       
  2494 
       
  2495 // ---------------------------------------------------------------------------
       
  2496 //
       
  2497 //
       
  2498 // ---------------------------------------------------------------------------
       
  2499 //
       
  2500 void CFSEmailUiMailListVisualiser::MarkMessagesIfFoundL( const RArray<TFSMailMsgId>& aMessageIDs )
       
  2501     {
       
  2502     FUNC_LOG;
       
  2503     for ( TInt i=0 ; i<aMessageIDs.Count() ; ++i )
       
  2504         {
       
  2505         // Same performance tweaking possibility is here that is commented in GetMarkedMessagesL().
       
  2506         TInt index = ItemIndexFromMessageId( aMessageIDs[i] );
       
  2507         if ( index >= 0 )
       
  2508             {
       
  2509             iMailList->MarkItemL( iTreeItemArray[index].iListItemId, ETrue );
       
  2510             }
       
  2511         }
       
  2512     }
       
  2513 
       
  2514 // ---------------------------------------------------------------------------
       
  2515 //
       
  2516 //
       
  2517 // ---------------------------------------------------------------------------
       
  2518 //
       
  2519 void CFSEmailUiMailListVisualiser::ExitMarkingModeL()
       
  2520     {
       
  2521     FUNC_LOG;	
       
  2522     // Hide marking mode text on the place of drop down menus
       
  2523     RemoveMarkingModeTitleTextL();	
       
  2524     iMarkingMode = EFalse;
       
  2525     UnmarkAllItemsL();
       
  2526     // Change softkeys back to normal
       
  2527     SetViewSoftkeysL( R_FREESTYLE_EMAUIL_UI_SK_OPTIONS_BACK );
       
  2528     // Change options menu back to normal
       
  2529     CEikMenuBar* menu = iAppUi.CurrentActiveView()->MenuBar();
       
  2530     menu->StopDisplayingMenuBar();
       
  2531     menu->SetMenuTitleResourceId(R_FSEMAILUI_MAILLIST_MENUBAR);
       
  2532     // Change background back to normal
       
  2533     DisplayMarkingModeBgL( EFalse );   
       
  2534     // Display drop down menu buttons
       
  2535     iControlBarControl->SetRectL( iAppUi.LayoutHandler()->GetControlBarRect() );
       
  2536     iNewEmailButton->SetDimmed( EFalse );
       
  2537     iFolderListButton->SetDimmed( EFalse );   
       
  2538     iSortButton->SetDimmed( EFalse );
       
  2539     ScaleControlBarL();
       
  2540     }
       
  2541 
       
  2542 // ---------------------------------------------------------------------------
       
  2543 //
       
  2544 //
       
  2545 // ---------------------------------------------------------------------------
       
  2546 //
       
  2547 void CFSEmailUiMailListVisualiser::EnterMarkingModeL()
       
  2548     {
       
  2549     FUNC_LOG;	
       
  2550     iMarkingMode = ETrue;
       
  2551 	iListMarkItemsState = ETrue; // shift-scrolling does marking after one item is marked
       
  2552     HandleCommandL( EFsEmailUiCmdActionsExpandAll );
       
  2553     // Change softkeys for marking mode
       
  2554     SetViewSoftkeysL( R_FREESTYLE_EMAUIL_UI_SK_OPTIONS_CANCEL );
       
  2555     // Change options menu for marking mode
       
  2556     CEikMenuBar* menu = iAppUi.CurrentActiveView()->MenuBar();
       
  2557     menu->StopDisplayingMenuBar();
       
  2558     menu->SetMenuTitleResourceId(R_FSEMAILUI_MAILLIST_MENUBAR_MARKING_MODE);
       
  2559     // Change background to marking mode
       
  2560     DisplayMarkingModeBgL( ETrue );       
       
  2561     // Hide drop down menu buttons
       
  2562     iNewEmailButton->SetDimmed();
       
  2563     iFolderListButton->SetDimmed();   
       
  2564     iSortButton->SetDimmed();
       
  2565     if( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  2566         {
       
  2567         TRect rect(0,0,0,0);
       
  2568         iControlBarControl->SetRectL( rect );
       
  2569         // Display marking mode text on the place of drop down menus   
       
  2570         DisplayMarkingModeTitleTextL();
       
  2571         }
       
  2572     }
       
  2573 
       
  2574 // ---------------------------------------------------------------------------
       
  2575 //
       
  2576 //
       
  2577 // ---------------------------------------------------------------------------
       
  2578 //
       
  2579 void CFSEmailUiMailListVisualiser::RefreshMarkingModeL()
       
  2580     {
       
  2581     FUNC_LOG;
       
  2582     if ( iMarkingMode )
       
  2583         {
       
  2584         // Hide drop down menu buttons    
       
  2585         if( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  2586             {
       
  2587             TRect rect(0,0,0,0);
       
  2588             iControlBarControl->SetRectL( rect );
       
  2589             DisplayMarkingModeTitleTextL();
       
  2590             }
       
  2591         else
       
  2592             {
       
  2593             iControlBarControl->SetRectL( iAppUi.LayoutHandler()->GetControlBarRect() );
       
  2594             iNewEmailButton->SetDimmed();
       
  2595             iFolderListButton->SetDimmed();
       
  2596             iSortButton->SetDimmed();
       
  2597             RemoveMarkingModeTitleTextL();
       
  2598             }
       
  2599         }
       
  2600     }
       
  2601 
       
  2602 // ---------------------------------------------------------------------------
       
  2603 //
       
  2604 //
       
  2605 // ---------------------------------------------------------------------------
       
  2606 //
       
  2607 void CFSEmailUiMailListVisualiser::DisplayMarkingModeTitleTextL()
       
  2608     {
       
  2609     FUNC_LOG;     
       
  2610     if (!iMarkingModeTextVisual)
       
  2611         {
       
  2612         const TRect sortButtonRect( iAppUi.LayoutHandler()->GetControlBarSortButtonRect() );
       
  2613         const TRect newMailButtonRect( iAppUi.LayoutHandler()->GetControlBarNewEmailButtonRect() );
       
  2614 
       
  2615         iMarkingModeTextRect = TRect( newMailButtonRect.iTl, sortButtonRect.iBr );
       
  2616         iMarkingModeTextParentLayout = CAlfDeckLayout::AddNewL( *iMailListControl );
       
  2617         iMarkingModeTextParentLayout->SetFlags( EAlfVisualFlagManualLayout );
       
  2618         iMarkingModeTextParentLayout->SetRect( iMarkingModeTextRect );
       
  2619 
       
  2620         iMarkingModeTextContentLayout = CAlfAnchorLayout::AddNewL( *iMailListControl, iMarkingModeTextParentLayout );
       
  2621 
       
  2622         iMarkingModeTextVisual = CAlfTextVisual::AddNewL( *iMailListControl, iMarkingModeTextContentLayout );
       
  2623         iMarkingModeTextVisual->SetWrapping( CAlfTextVisual::ELineWrapTruncate );
       
  2624         if ( AknLayoutUtils::LayoutMirrored() )
       
  2625             {
       
  2626             iMarkingModeTextVisual->SetAlign( EAlfAlignHRight, EAlfAlignVCenter );
       
  2627             }
       
  2628         else
       
  2629             {
       
  2630             iMarkingModeTextVisual->SetAlign( EAlfAlignHLeft, EAlfAlignVCenter );
       
  2631             }    
       
  2632         iMarkingModeTextVisual->SetStyle( EAlfTextStyleTitle );
       
  2633         TRgb color = iAppUi.LayoutHandler()->ListNodeTextColor();
       
  2634         iMarkingModeTextVisual->SetColor ( color );
       
  2635         if( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  2636             {
       
  2637             HBufC* msg = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_MARKINGMODE );
       
  2638             iMarkingModeTextVisual->SetTextL( *msg );
       
  2639             CleanupStack::PopAndDestroy( msg );
       
  2640             }
       
  2641         else
       
  2642             {
       
  2643             iMarkingModeTextVisual->SetTextL( KNullDesC );
       
  2644             }
       
  2645         }        
       
  2646     }
       
  2647 
       
  2648 // ---------------------------------------------------------------------------
       
  2649 //
       
  2650 //
       
  2651 // ---------------------------------------------------------------------------
       
  2652 //
       
  2653 void CFSEmailUiMailListVisualiser::RemoveMarkingModeTitleTextL()
       
  2654     {
       
  2655     FUNC_LOG;
       
  2656     if (iMarkingModeTextVisual)
       
  2657         {
       
  2658         iMarkingModeTextVisual->SetTextL( KNullDesC );
       
  2659         iMarkingModeTextVisual->RemoveAndDestroyAllD();
       
  2660         iMarkingModeTextVisual = NULL;
       
  2661         iMarkingModeTextContentLayout->RemoveAndDestroyAllD();
       
  2662         iMarkingModeTextContentLayout = NULL;
       
  2663         iMarkingModeTextParentLayout->RemoveAndDestroyAllD();
       
  2664         iMarkingModeTextParentLayout = NULL;
       
  2665         }
       
  2666     }
       
  2667 
       
  2668 // ---------------------------------------------------------------------------
       
  2669 //
       
  2670 //
       
  2671 // ---------------------------------------------------------------------------
       
  2672 //
       
  2673 void CFSEmailUiMailListVisualiser::DisplayMarkingModeBgL( TBool aDisplay )
       
  2674     {
       
  2675     FUNC_LOG;
       
  2676     if (aDisplay)
       
  2677         {
       
  2678         CAlfBrush* brush = iAppUi.FsTextureManager()->NewMailListMarkingModeBgBrushLC();
       
  2679         iMailTreeListVisualizer->SetBackgroundBrushL( brush );
       
  2680         CleanupStack::Pop( brush );
       
  2681         }
       
  2682     else
       
  2683         {
       
  2684         iMailTreeListVisualizer->ClearBackground();
       
  2685         }
       
  2686     }
       
  2687 
       
  2688 // ---------------------------------------------------------------------------
       
  2689 //
       
  2690 //
       
  2691 // ---------------------------------------------------------------------------
       
  2692 //
       
  2693 void CFSEmailUiMailListVisualiser::RefreshL( TFSMailMsgId* aFocusToMessage )
       
  2694 	{
       
  2695     FUNC_LOG;
       
  2696 	iMailList->RemoveAllL();
       
  2697 	iTreeItemArray.Reset();
       
  2698 
       
  2699     // when we get refresh mail list updates should be fully enabled
       
  2700     iMailOpened = EFalse;
       
  2701 
       
  2702 	RefreshListItemsL();
       
  2703 
       
  2704 	if ( !iModel->Count() )
       
  2705 		{
       
  2706 		iFocusedControl = EControlBarComponent;
       
  2707 		// If focus is not visible, hide selector
       
  2708 		iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  2709 		}
       
  2710 	else
       
  2711 	    {
       
  2712         // Try to keep the previous list item if focused message ptr is given,
       
  2713 	    // and it's not NULL id
       
  2714         if ( aFocusToMessage && !aFocusToMessage->IsNullId() )
       
  2715             {
       
  2716             TInt idx = ItemIndexFromMessageId( *aFocusToMessage );
       
  2717             if ( idx >= 0 )
       
  2718                 {
       
  2719                 TFsTreeItemId itemId = iTreeItemArray[idx].iListItemId;
       
  2720                 iMailList->SetFocusedItemL( itemId );
       
  2721                 // If contorl bar is focused, we need to hide
       
  2722                 // focus then.
       
  2723                 if( iFocusedControl == EControlBarComponent )
       
  2724                     {
       
  2725                     iMailTreeListVisualizer->UpdateItemL( itemId );
       
  2726                     }
       
  2727                 }
       
  2728             }
       
  2729 	    }
       
  2730 
       
  2731     SetListAndCtrlBarFocusL();
       
  2732     SetMskL();
       
  2733 
       
  2734     iListOrderMayBeOutOfDate = EFalse;
       
  2735 	}
       
  2736 
       
  2737 void CFSEmailUiMailListVisualiser::RefreshOrderL()
       
  2738     {
       
  2739     FUNC_LOG;
       
  2740     if ( iTreeItemArray.Count() )
       
  2741         {
       
  2742         TInt itemIdxUnderNode = -1;
       
  2743         TInt nodeIdx = -1;
       
  2744         TFsTreeItemId parentNodeId = KFsTreeRootID;
       
  2745 
       
  2746         //iMailList->HideListL( EFalse, EFalse );
       
  2747         TFsTreeItemId prevFocus = iMailList->FocusedItem();
       
  2748         iMailList->SetFocusedItemL( iTreeItemArray[0].iListItemId ); // Try to prevent over indexing in generic list
       
  2749 
       
  2750         // iTreeItemArray is recreated on reordering.
       
  2751         iTreeItemArray.Reset();
       
  2752         SMailListItem mailListItem;
       
  2753 
       
  2754         for ( TInt i = 0 ; i < iModel->Count() ; ++i )
       
  2755             {
       
  2756             CFSEmailUiMailListModelItem* item = static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(i) );
       
  2757             TFsTreeItemId itemId = item->CorrespondingListId();
       
  2758 
       
  2759             if ( item->ModelItemType() == ETypeSeparator )
       
  2760                 {
       
  2761                 nodeIdx++;
       
  2762                 itemIdxUnderNode = -1;
       
  2763                 parentNodeId = itemId;
       
  2764                 if ( iMailList->ChildIndex( itemId, KFsTreeRootID ) != nodeIdx )
       
  2765                     {
       
  2766                     iMailList->MoveItemL( itemId, KFsTreeRootID, nodeIdx );
       
  2767                     }
       
  2768                 }
       
  2769             else
       
  2770                 {
       
  2771                 itemIdxUnderNode++;
       
  2772                 if ( iMailList->Parent(itemId) != parentNodeId ||
       
  2773                      iMailList->ChildIndex( parentNodeId, itemId ) != itemIdxUnderNode )
       
  2774                     {
       
  2775                     iMailList->MoveItemL( itemId, parentNodeId, itemIdxUnderNode );
       
  2776                     }
       
  2777                 }
       
  2778 
       
  2779             mailListItem.iListItemId = itemId;
       
  2780             mailListItem.iTreeItemData = &iMailList->ItemData(itemId);
       
  2781             mailListItem.iTreeItemVisualiser = &iMailList->ItemVisualizer(itemId);
       
  2782             iTreeItemArray.AppendL( mailListItem );
       
  2783             }
       
  2784 
       
  2785         iMailList->SetFocusedItemL( prevFocus );
       
  2786         //iMailList->ShowListL( EFalse, EFalse );
       
  2787         }
       
  2788     iListOrderMayBeOutOfDate = EFalse;
       
  2789     }
       
  2790 
       
  2791 // ---------------------------------------------------------------------------
       
  2792 // Start refresh list items asynchronously
       
  2793 //
       
  2794 // ---------------------------------------------------------------------------
       
  2795 //
       
  2796 //
       
  2797 void CFSEmailUiMailListVisualiser::RefreshDeferred( TFSMailMsgId* aFocusToMessage /*= NULL*/ )
       
  2798     {
       
  2799     FUNC_LOG;
       
  2800     if ( aFocusToMessage )
       
  2801         {
       
  2802         iMsgToFocusAfterRedraw = *aFocusToMessage;
       
  2803         }
       
  2804     else
       
  2805         {
       
  2806         // SetNullId sets just the null id flag,
       
  2807         // so we need to null the actual id manually
       
  2808         iMsgToFocusAfterRedraw.SetId( 0 );
       
  2809         iMsgToFocusAfterRedraw.SetNullId();
       
  2810         }
       
  2811 
       
  2812     if ( iAsyncRedrawer )
       
  2813         {
       
  2814         TCallBack asyncRefresh( DoRefresh, this );
       
  2815         iAsyncRedrawer->Cancel();
       
  2816         iAsyncRedrawer->Set( asyncRefresh );
       
  2817         iAsyncRedrawer->CallBack();
       
  2818         }
       
  2819     }
       
  2820 
       
  2821 // ---------------------------------------------------------------------------
       
  2822 // Static wrapper function for RefreshL() to enable asynchronous calling
       
  2823 //
       
  2824 // ---------------------------------------------------------------------------
       
  2825 //
       
  2826 //
       
  2827 TInt CFSEmailUiMailListVisualiser::DoRefresh( TAny* aSelfPtr )
       
  2828     {
       
  2829     FUNC_LOG;
       
  2830     CFSEmailUiMailListVisualiser* self =
       
  2831         static_cast< CFSEmailUiMailListVisualiser* >( aSelfPtr );
       
  2832     TRAPD( err, self->RefreshL( &self->iMsgToFocusAfterRedraw ) );
       
  2833     return err;
       
  2834     }
       
  2835 
       
  2836 // ---------------------------------------------------------------------------
       
  2837 // Force any pending refresh event to be completed immediately
       
  2838 //
       
  2839 // ---------------------------------------------------------------------------
       
  2840 //
       
  2841 //
       
  2842 void CFSEmailUiMailListVisualiser::CompletePendingRefresh()
       
  2843     {
       
  2844     FUNC_LOG;
       
  2845 
       
  2846     if ( iAsyncRedrawer && iAsyncRedrawer->IsActive() )
       
  2847         {
       
  2848         iAsyncRedrawer->Cancel();
       
  2849         DoRefresh( this );
       
  2850         }
       
  2851     }
       
  2852 
       
  2853 // ---------------------------------------------------------------------------
       
  2854 //
       
  2855 //
       
  2856 // ---------------------------------------------------------------------------
       
  2857 //
       
  2858 void CFSEmailUiMailListVisualiser::RefreshListItemsL()
       
  2859 	{
       
  2860     FUNC_LOG;
       
  2861 	// IMPLEMENTATION OF FILLING UP THE LIST
       
  2862 	TFsTreeItemId latestNodeId = KFsTreeRootID; // items will go under root node if no other nodes found in the model
       
  2863     CFSEmailUiMailListModelItem* item( NULL );
       
  2864     SetMailListItemsExtendedL();
       
  2865 
       
  2866     TInt count(0);
       
  2867     count = iModel->Count();
       
  2868     for ( TInt i=0; i < count; i++ )
       
  2869 		{
       
  2870 		item = static_cast<CFSEmailUiMailListModelItem*>(iModel->Item(i));
       
  2871 
       
  2872         const TBool allowRefresh(i == 0 || (i == count - 1));
       
  2873 
       
  2874 		// Append separator item text into the list
       
  2875 		if ( item && item->ModelItemType() == ETypeSeparator )
       
  2876 			{
       
  2877 			latestNodeId = InsertNodeItemL( i, KErrNotFound, allowRefresh );
       
  2878 			}
       
  2879 		// Append mail item into the list
       
  2880 		else if ( item && item->ModelItemType() == ETypeMailItem )
       
  2881 			{
       
  2882 			InsertListItemL( i, latestNodeId, KErrNotFound, allowRefresh );
       
  2883 			}
       
  2884 		}
       
  2885 	}
       
  2886 
       
  2887 // ---------------------------------------------------------------------------
       
  2888 //
       
  2889 //
       
  2890 // ---------------------------------------------------------------------------
       
  2891 //
       
  2892 void CFSEmailUiMailListVisualiser::RefreshListItemsL(TFsTreeItemId& aLatestNodeId, const TInt aStartIndex, const TInt aEndIndex)
       
  2893     {
       
  2894     FUNC_LOG;
       
  2895     // IMPLEMENTATION OF FILLING UP THE LIST
       
  2896     iMailList->BeginUpdate();
       
  2897     CFSEmailUiMailListModelItem* item( NULL );
       
  2898     if (aLatestNodeId == KFsTreeRootID && !aStartIndex)
       
  2899         {
       
  2900         iMailList->RemoveAllL();
       
  2901         iTreeItemArray.Reset();
       
  2902         SetMailListItemsExtendedL();
       
  2903         }
       
  2904     for ( TInt i = aStartIndex; i < aEndIndex; i++ )
       
  2905         {
       
  2906         item = static_cast<CFSEmailUiMailListModelItem*>(iModel->Item(i));
       
  2907         // Append separator item text into the list
       
  2908         if ( item && item->ModelItemType() == ETypeSeparator )
       
  2909             {
       
  2910             aLatestNodeId = InsertNodeItemL( i, KErrNotFound, EFalse );
       
  2911             }
       
  2912         // Append mail item into the list
       
  2913         else if ( item && item->ModelItemType() == ETypeMailItem )
       
  2914             {
       
  2915             InsertListItemL( i, aLatestNodeId, KErrNotFound, EFalse );
       
  2916             }
       
  2917         }
       
  2918     iMailList->EndUpdateL();
       
  2919     }
       
  2920 
       
  2921 void CFSEmailUiMailListVisualiser::SetMailListItemsExtendedL()
       
  2922 	{
       
  2923     FUNC_LOG;
       
  2924 	// Set items always extended in double line preview on mode.
       
  2925 	if ( iListMode == EListControlTypeDoubleLinePreviewOn ||
       
  2926 		 iListMode == EListControlTypeDoubleLinePreviewOff )
       
  2927 		{
       
  2928 		if ( iMailTreeListVisualizer )
       
  2929 			{
       
  2930 	        iMailTreeListVisualizer->SetItemsAlwaysExtendedL( ETrue );
       
  2931 			}
       
  2932  		}
       
  2933 	else
       
  2934 		{
       
  2935 		// Set the extendedability and extended size
       
  2936 		if ( iMailTreeListVisualizer )
       
  2937 			{
       
  2938   			iMailTreeListVisualizer->SetItemsAlwaysExtendedL( EFalse );
       
  2939 			}
       
  2940  		}
       
  2941 	}
       
  2942 
       
  2943 
       
  2944 // ---------------------------------------------------------------------------
       
  2945 // Create and insert one list node item according to given model item.
       
  2946 // Omitting the argument aChildIdx causes the new node to be appended as last
       
  2947 // child of the root node.
       
  2948 // ---------------------------------------------------------------------------
       
  2949 //
       
  2950 TFsTreeItemId CFSEmailUiMailListVisualiser::InsertNodeItemL( TInt aModelIndex,
       
  2951                                                              TInt aChildIndex,
       
  2952                                                              const TBool aAllowRefresh )
       
  2953     {
       
  2954     FUNC_LOG;
       
  2955     TFsTreeItemId nodeId;
       
  2956     CFsTreePlainOneLineNodeData* plainNodeData(0);
       
  2957     CFsTreePlainOneLineNodeVisualizer* plainNodeVisualizer(0);
       
  2958 
       
  2959     CFSEmailUiMailListModelItem* item =
       
  2960         static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(aModelIndex) );
       
  2961 
       
  2962     CreatePlainNodeL( item->SeparatorText(), plainNodeData, plainNodeVisualizer );
       
  2963     CleanupStack::PushL( plainNodeData );
       
  2964     CleanupStack::PushL( plainNodeVisualizer );
       
  2965     // Set text aling for western or A&H layout
       
  2966    	plainNodeVisualizer->SetTextAlign( EAlfAlignHLocale  );
       
  2967    	//new node is expanded
       
  2968    	plainNodeVisualizer->SetExpanded( ETrue );
       
  2969 
       
  2970     // In mail list, scrollbar does not need to be updated after node, since node is always followed by item
       
  2971     if ( aChildIndex >= 0 )
       
  2972         {
       
  2973         nodeId = iMailList->InsertNodeL( *plainNodeData, *plainNodeVisualizer, KFsTreeRootID, aChildIndex, aAllowRefresh );
       
  2974         }
       
  2975     else
       
  2976         {
       
  2977         nodeId = iMailList->InsertNodeL( *plainNodeData, *plainNodeVisualizer, KFsTreeRootID, KErrNotFound, aAllowRefresh );
       
  2978         }
       
  2979 
       
  2980     CleanupStack::Pop( 2, plainNodeData );
       
  2981 
       
  2982     SMailListItem mailListItem;
       
  2983     mailListItem.iListItemId = nodeId;
       
  2984     mailListItem.iTreeItemData = plainNodeData;
       
  2985     mailListItem.iTreeItemVisualiser = plainNodeVisualizer;
       
  2986     iTreeItemArray.InsertL( mailListItem, aModelIndex );
       
  2987     item->AddCorrespondingListId( nodeId );
       
  2988 
       
  2989     return nodeId;
       
  2990     }
       
  2991 
       
  2992 // ---------------------------------------------------------------------------
       
  2993 // Create and insert one list item according the given model item. The item is
       
  2994 // added under the given node. Omitting the argument aChildIdx causes the new
       
  2995 // item to be appended as last child of the node.
       
  2996 // ---------------------------------------------------------------------------
       
  2997 //
       
  2998 TFsTreeItemId CFSEmailUiMailListVisualiser::InsertListItemL( TInt aModelIndex,
       
  2999                                                              TFsTreeItemId aParentNodeId,
       
  3000                                                              TInt aChildIdx, /*= KErrNotFound*/
       
  3001                                                              TBool aAllowRefresh /*= ETrue*/ )
       
  3002     {
       
  3003     FUNC_LOG;
       
  3004     CFsTreePlainTwoLineItemData* itemData = NULL;
       
  3005     CFsTreePlainTwoLineItemVisualizer* itemVisualizer = NULL;
       
  3006     CFSEmailUiMailListModelItem* item =
       
  3007         static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(aModelIndex) );
       
  3008 
       
  3009     // Create data
       
  3010     itemData = CFsTreePlainTwoLineItemData::NewL();
       
  3011     CleanupStack::PushL(itemData);
       
  3012 
       
  3013     // Read the data from the message
       
  3014     UpdateItemDataL( itemData, &item->MessagePtr() );
       
  3015 
       
  3016     // Set placeholder for body preview
       
  3017     itemData->SetPreviewPaneDataL( KMissingPreviewDataMarker );
       
  3018 
       
  3019     // Create item visualiser
       
  3020     itemVisualizer = CFsTreePlainTwoLineItemVisualizer::NewL(
       
  3021             *iMailList->TreeControl() );
       
  3022     CleanupStack::PushL( itemVisualizer );
       
  3023 
       
  3024    	itemVisualizer->SetTextAlign( EAlfAlignHLocale );
       
  3025 
       
  3026    	TBool previewOn = ( iListMode == EListControlTypeDoubleLinePreviewOn ||
       
  3027                         iListMode == EListControlTypeSingleLinePreviewOn );
       
  3028    	itemVisualizer->SetPreviewPaneOn( previewOn );
       
  3029    	itemVisualizer->SetExtendable( ETrue );
       
  3030 
       
  3031    	// Set correct skin text colors for the list items
       
  3032    	itemVisualizer->SetFocusedStateTextColor( iFocusedTextColor );
       
  3033     itemVisualizer->SetNormalStateTextColor( iNormalTextColor );
       
  3034 
       
  3035     // Set font height
       
  3036     itemVisualizer->SetFontHeight( iAppUi.LayoutHandler()->ListItemFontHeightInTwips() );
       
  3037 
       
  3038     //Update icons and text bolding
       
  3039     //DOES NOT update the item - will be drawn automatically (if needed) during InsertItemL
       
  3040     UpdateMsgIconAndBoldingL( itemData, itemVisualizer, &item->MessagePtr() );
       
  3041 
       
  3042     // Insert or append under the given node
       
  3043     TFsTreeItemId itemId(0);
       
  3044     itemId = iMailList->InsertItemL( *itemData, *itemVisualizer, aParentNodeId, aChildIdx, aAllowRefresh );
       
  3045 
       
  3046     // The visualizer and data are now owned by the iMailList and should be removed from
       
  3047     // the cleanup stack
       
  3048     CleanupStack::Pop( itemVisualizer );
       
  3049     CleanupStack::Pop( itemData );
       
  3050 
       
  3051     // Insert corresponding item to iTreeItemArray
       
  3052     SMailListItem mailListItem;
       
  3053     mailListItem.iListItemId = itemId;
       
  3054     mailListItem.iTreeItemData = itemData;
       
  3055     mailListItem.iTreeItemVisualiser = itemVisualizer;
       
  3056     iTreeItemArray.InsertL( mailListItem, aModelIndex );
       
  3057     item->AddCorrespondingListId( itemId );
       
  3058 
       
  3059     // Updating the preview pane must be handled separately in this case;
       
  3060     // generic logic in TreeListEvent handler doesn't work while we are
       
  3061     // still in the middle of adding the item.
       
  3062     if ( iMailList->FocusedItem() == itemId )
       
  3063         {
       
  3064         UpdatePreviewPaneTextIfNecessaryL( itemId, ETrue );
       
  3065         }
       
  3066 
       
  3067     return itemId;
       
  3068     }
       
  3069 
       
  3070 // ---------------------------------------------------------------------------
       
  3071 //
       
  3072 //
       
  3073 // ---------------------------------------------------------------------------
       
  3074 //
       
  3075 HBufC* CFSEmailUiMailListVisualiser::GetListFirstTextLineL( const CFSMailMessage* aMsgPtr )
       
  3076 	{
       
  3077     FUNC_LOG;
       
  3078 	HBufC* ret( NULL );
       
  3079 
       
  3080 	TDesC* displayName( NULL );
       
  3081 	TDesC* emailAddress( NULL );
       
  3082 
       
  3083 	TInt folderType( EFSInbox );
       
  3084     if( iMailFolder )
       
  3085      {
       
  3086      folderType = iMailFolder->GetFolderType();
       
  3087      }
       
  3088 
       
  3089 	// Use sender in all other folders than outbox, sent, and drafts
       
  3090 	if ( folderType != EFSOutbox &&
       
  3091 		 folderType != EFSSentFolder &&
       
  3092 		 folderType != EFSDraftsFolder )
       
  3093 		{
       
  3094 		CFSMailAddress* fromAddress = aMsgPtr->GetSender();
       
  3095 	    if ( fromAddress )
       
  3096 		    {
       
  3097 		    displayName = &fromAddress->GetDisplayName();
       
  3098 		    emailAddress = &fromAddress->GetEmailAddress();
       
  3099 
       
  3100 		    if ( displayName && displayName->Length() != 0 )
       
  3101                 {
       
  3102                 ret = displayName->AllocL();
       
  3103                 }
       
  3104             else if ( emailAddress && emailAddress->Length() != 0 )
       
  3105                 {
       
  3106                 ret = emailAddress->AllocL();
       
  3107                 }
       
  3108 		    }
       
  3109 		else // no fromAddress in that case we show "(No sender info available)",
       
  3110 		    // in case sender sends MR to himself/herself
       
  3111 		    {
       
  3112 		    ret = StringLoader::LoadL( R_FREESTYLE_EMAIL_UI_MSG_DETAILS_NO_SENDER_INFO_AVAILABLE);
       
  3113 		    }
       
  3114 	    }
       
  3115 	// Use first recipient in case of outgoing folders
       
  3116 	else // folderType == EFSOutbox || folderType == EFSSentFolder || folderType == EFSDraftsFolder
       
  3117 		{
       
  3118 		CFSMailMessage* msgPtr = const_cast<CFSMailMessage*>( aMsgPtr ); // there's no const function in FW to get recipient data
       
  3119 		RPointerArray<CFSMailAddress>& toArray = msgPtr->GetToRecipients();
       
  3120 		if ( toArray.Count() )
       
  3121 			{
       
  3122 			CFSMailAddress* toAddress = toArray[0]; // Use first
       
  3123 			if ( toAddress )
       
  3124 				{
       
  3125 				displayName = &toAddress->GetDisplayName();
       
  3126 				emailAddress = &toAddress->GetEmailAddress();
       
  3127 
       
  3128 	            if ( displayName && displayName->Length() )
       
  3129 	                {
       
  3130 	                ret = displayName->AllocL();
       
  3131 	                }
       
  3132 	            else if ( emailAddress && emailAddress->Length() )
       
  3133 	                {
       
  3134 	                ret = emailAddress->AllocL();
       
  3135 	                }
       
  3136 				}
       
  3137 			}
       
  3138 		}
       
  3139 
       
  3140 	// Allocate empty string if everything else fails
       
  3141     if ( !ret )
       
  3142          {
       
  3143          ret = KNullDesC().AllocL();
       
  3144          }
       
  3145 
       
  3146 	// Drop out unwanted characters from display name such as <> and ""
       
  3147 	TFsEmailUiUtility::StripDisplayName( *ret );
       
  3148 
       
  3149 	return ret;
       
  3150 	}
       
  3151 
       
  3152 // ---------------------------------------------------------------------------
       
  3153 //
       
  3154 //
       
  3155 // ---------------------------------------------------------------------------
       
  3156 //
       
  3157 void CFSEmailUiMailListVisualiser::UpdateItemDataL( CFsTreePlainTwoLineItemData* aData, const CFSMailMessage* aMsgPtr )
       
  3158     {
       
  3159     FUNC_LOG;
       
  3160     // Set first line of data
       
  3161     HBufC* firstLineText = GetListFirstTextLineL( aMsgPtr );
       
  3162     if ( firstLineText )
       
  3163         {
       
  3164         CleanupStack::PushL( firstLineText );
       
  3165         aData->SetDataL( *firstLineText );
       
  3166         CleanupStack::PopAndDestroy( firstLineText );
       
  3167         }
       
  3168     else
       
  3169         {
       
  3170         aData->SetDataL( KNullDesC );
       
  3171         }
       
  3172 
       
  3173     // Set second line of data
       
  3174     HBufC* subjectText = TFsEmailUiUtility::CreateSubjectTextLC( aMsgPtr );
       
  3175     aData->SetSecondaryDataL( *subjectText );
       
  3176     CleanupStack::PopAndDestroy( subjectText );
       
  3177 
       
  3178     // Set time item in mail
       
  3179     HBufC* timeText = NULL;
       
  3180     if ( iCurrentSortCriteria.iField == EFSMailSortByDate )
       
  3181         {
       
  3182         timeText = TFsEmailUiUtility::ListMsgTimeTextFromMsgLC( aMsgPtr, iNodesInUse );
       
  3183         }
       
  3184     else
       
  3185         {
       
  3186         // Use dates also in other sort criterias that sort by date.
       
  3187         timeText = TFsEmailUiUtility::ListMsgTimeTextFromMsgLC( aMsgPtr, EFalse );
       
  3188         }
       
  3189     aData->SetDateTimeDataL( *timeText );
       
  3190     CleanupStack::PopAndDestroy( timeText );
       
  3191     }
       
  3192 
       
  3193 // ---------------------------------------------------------------------------
       
  3194 //
       
  3195 //
       
  3196 // ---------------------------------------------------------------------------
       
  3197 //
       
  3198 void CFSEmailUiMailListVisualiser::UpdatePreviewPaneTextForItemL( TInt aListItemId, CFSMailMessage* aMsgPtr )
       
  3199 	{
       
  3200     FUNC_LOG;
       
  3201 	if ( aMsgPtr && ( iListMode == EListControlTypeSingleLinePreviewOn ||
       
  3202          iListMode == EListControlTypeDoubleLinePreviewOn ) )
       
  3203         {
       
  3204         CFsTreePlainTwoLineItemData* twoLineItemData = static_cast<CFsTreePlainTwoLineItemData*>( ItemDataFromItemId( aListItemId ) );
       
  3205         UpdatePreviewPaneTextForItemL( twoLineItemData, aMsgPtr  );
       
  3206         }
       
  3207 	}
       
  3208 
       
  3209 // ---------------------------------------------------------------------------
       
  3210 //
       
  3211 //
       
  3212 // ---------------------------------------------------------------------------
       
  3213 //
       
  3214 void CFSEmailUiMailListVisualiser::UpdatePreviewPaneTextForItemL(
       
  3215         CFsTreePlainTwoLineItemData* aTwoLineItemData, CFSMailMessage* aMsgPtr )
       
  3216     {
       
  3217     FUNC_LOG;
       
  3218 	// Preview pane data update
       
  3219 	if ( aTwoLineItemData && aMsgPtr && ( iListMode == EListControlTypeSingleLinePreviewOn ||
       
  3220 		 iListMode == EListControlTypeDoubleLinePreviewOn ) )
       
  3221 		{
       
  3222 		TBool previewSet = EFalse;
       
  3223 		CFSMailMessagePart* textPart = aMsgPtr->PlainTextBodyPartL();
       
  3224 		CleanupStack::PushL( textPart );
       
  3225 		if ( textPart && ( textPart->FetchLoadState() == EFSPartial ||
       
  3226 			 textPart->FetchLoadState() == EFSFull ) )
       
  3227 			{
       
  3228 			TInt previewSize = Min( KMaxPreviewPaneLength, textPart->FetchedContentSize() );
       
  3229 			HBufC* plainTextData16 = HBufC::NewLC( previewSize );
       
  3230 			TPtr textPtr = plainTextData16->Des();
       
  3231 
       
  3232 			// Getting the content needs to be trapped as it seems to leave in some error cases
       
  3233 			// at least with IMAP
       
  3234 			TRAP_IGNORE( textPart->GetContentToBufferL( textPtr, 0 ) ); // Zero is start offset
       
  3235             // Crop out line feed, paragraph break, and tabulator
       
  3236             TFsEmailUiUtility::FilterListItemTextL( textPtr );
       
  3237 
       
  3238             if ( textPtr.Length() )
       
  3239                 {
       
  3240                 aTwoLineItemData->SetPreviewPaneDataL( *plainTextData16 );
       
  3241                 previewSet = ETrue;
       
  3242                 }
       
  3243 
       
  3244 			CleanupStack::PopAndDestroy( plainTextData16 );
       
  3245 			}
       
  3246 
       
  3247 		// Display message size in preview pane if we got no body content
       
  3248 		if ( !previewSet )
       
  3249 			{
       
  3250 			TUint contentSize = aMsgPtr->ContentSize();
       
  3251 			HBufC* sizeDesc = TFsEmailUiUtility::CreateSizeDescLC( contentSize );
       
  3252 			HBufC* msgSizeText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_PREV_PANE_MSG_SIZE, *sizeDesc );
       
  3253 			aTwoLineItemData->SetPreviewPaneDataL( *msgSizeText );
       
  3254 			CleanupStack::PopAndDestroy( msgSizeText );
       
  3255 			CleanupStack::PopAndDestroy( sizeDesc );
       
  3256 			}
       
  3257 		CleanupStack::PopAndDestroy( textPart );
       
  3258 		}
       
  3259 	}
       
  3260 
       
  3261 // ---------------------------------------------------------------------------
       
  3262 //
       
  3263 //
       
  3264 // ---------------------------------------------------------------------------
       
  3265 //
       
  3266 void CFSEmailUiMailListVisualiser::UpdatePreviewPaneTextIfNecessaryL( TFsTreeItemId aListItemId, TBool aUpdateItem )
       
  3267     {
       
  3268     FUNC_LOG;
       
  3269     if ( iFirstStartCompleted && aListItemId != KFsTreeNoneID )
       
  3270         {
       
  3271         if ( iListMode == EListControlTypeSingleLinePreviewOn ||
       
  3272              iListMode == EListControlTypeDoubleLinePreviewOn )
       
  3273             {
       
  3274             if ( !iMailList->IsNode( aListItemId ) )
       
  3275                 {
       
  3276                 TInt idx = ModelIndexFromListId( aListItemId );
       
  3277                 if ( idx != KErrNotFound )
       
  3278                     {
       
  3279                     CFsTreePlainTwoLineItemData* data =
       
  3280                         static_cast<CFsTreePlainTwoLineItemData*>( iTreeItemArray[idx].iTreeItemData );
       
  3281                     if ( data->PreviewPaneData() == KMissingPreviewDataMarker )
       
  3282                         {
       
  3283                         CFSEmailUiMailListModelItem* modelItem =
       
  3284                             static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(idx) );
       
  3285                         if ( modelItem ) // For safety
       
  3286                             {
       
  3287                             CFSMailMessage& msgRef = modelItem->MessagePtr();
       
  3288                             UpdatePreviewPaneTextForItemL( aListItemId, &msgRef );
       
  3289                             if ( aUpdateItem )
       
  3290                                 {
       
  3291                                 iMailTreeListVisualizer->UpdateItemL( aListItemId );
       
  3292                                 }
       
  3293                             }
       
  3294                         }
       
  3295                     }
       
  3296                 }
       
  3297             }
       
  3298         }
       
  3299     }
       
  3300 
       
  3301 // ---------------------------------------------------------------------------
       
  3302 //
       
  3303 //
       
  3304 // ---------------------------------------------------------------------------
       
  3305 //
       
  3306 void CFSEmailUiMailListVisualiser::CreatePlainNodeL( const TDesC* aItemDataBuff,
       
  3307                                                      CFsTreePlainOneLineNodeData* &aItemData,
       
  3308                                                      CFsTreePlainOneLineNodeVisualizer* &aNodeVisualizer ) const
       
  3309     {
       
  3310     FUNC_LOG;
       
  3311     aItemData = CFsTreePlainOneLineNodeData::NewL();
       
  3312     CleanupStack::PushL( aItemData );
       
  3313 
       
  3314     aItemData->SetDataL( *aItemDataBuff );
       
  3315     aItemData->SetIconExpanded( iAppUi.FsTextureManager()->TextureByIndex( EListTextureNodeExpanded ));
       
  3316     aItemData->SetIconCollapsed( iAppUi.FsTextureManager()->TextureByIndex( EListTextureNodeCollapsed ));
       
  3317     aNodeVisualizer = CFsTreePlainOneLineNodeVisualizer::NewL(*iMailList->TreeControl());
       
  3318     CleanupStack::PushL( aNodeVisualizer );
       
  3319     TInt nodeHeight = iAppUi.LayoutHandler()->OneLineListNodeHeight();
       
  3320     // use cached client rect instead of iAppUi.ClientRect() to save time
       
  3321     // ASSERT in debug to be sure that rects are these same
       
  3322     __ASSERT_DEBUG( iAppUi.ClientRect() == iCurrentClientRect, User::Invariant() );
       
  3323     aNodeVisualizer->SetSize( TSize(iCurrentClientRect.Width(), nodeHeight) );
       
  3324     aNodeVisualizer->SetExtendable(EFalse);
       
  3325     // Set correct skin text colors for the list items
       
  3326     aNodeVisualizer->SetFocusedStateTextColor( iFocusedTextColor );
       
  3327     aNodeVisualizer->SetNormalStateTextColor( iNodeTextColor );
       
  3328     // Set font height
       
  3329     aNodeVisualizer->SetFontHeight( iAppUi.LayoutHandler()->ListItemFontHeightInTwips() );
       
  3330     // Set font always bolded in nodes
       
  3331     aNodeVisualizer->SetTextBold( ETrue );
       
  3332 
       
  3333     //<cmail>
       
  3334     CAlfBrush* titleDividerBgBrush =
       
  3335         iAppUi.FsTextureManager()->TitleDividerBgBrushL();
       
  3336     // ownership is not transfered
       
  3337     aNodeVisualizer->SetBackgroundBrush( titleDividerBgBrush );
       
  3338     //</cmail>
       
  3339 
       
  3340     CleanupStack::Pop( aNodeVisualizer );
       
  3341     CleanupStack::Pop( aItemData );
       
  3342     }
       
  3343 
       
  3344 // ---------------------------------------------------------------------------
       
  3345 //
       
  3346 //
       
  3347 // ---------------------------------------------------------------------------
       
  3348 //
       
  3349 void CFSEmailUiMailListVisualiser::HandleDynamicVariantSwitchL(
       
  3350     CFsEmailUiViewBase::TDynamicSwitchType aType )
       
  3351 	{
       
  3352     FUNC_LOG;
       
  3353     CFsEmailUiViewBase::HandleDynamicVariantSwitchL( aType );
       
  3354 
       
  3355     if ( iFirstStartCompleted ) // Safety
       
  3356         {
       
  3357         if ( aType == EScreenLayoutChanged )
       
  3358         	{
       
  3359             SetStatusBarLayout();
       
  3360             UpdateButtonTextsL();
       
  3361         	}
       
  3362 
       
  3363         if ( aType == ESkinChanged )
       
  3364             {
       
  3365             UpdateThemeL();
       
  3366             }
       
  3367         else
       
  3368             {
       
  3369             iAppUi.FsTextureManager()->ClearTextureByIndex( EListControlBarMailboxDefaultIcon );
       
  3370             iFolderListButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( EListControlBarMailboxDefaultIcon ) );
       
  3371             iAppUi.FsTextureManager()->ClearTextureByIndex( EListTextureCreateNewMessageIcon );
       
  3372             iNewEmailButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( EListTextureCreateNewMessageIcon ) );
       
  3373             iAppUi.FsTextureManager()->ClearTextureByIndex( GetSortButtonTextureIndex() );
       
  3374             iSortButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( GetSortButtonTextureIndex() ) );
       
  3375            
       
  3376             iMailTreeListVisualizer->HideList();
       
  3377             // screen layout changed
       
  3378             iCurrentClientRect = iAppUi.ClientRect();
       
  3379             iScreenAnchorLayout->SetSize( iCurrentClientRect.Size() );
       
  3380             SetMailListLayoutAnchors();
       
  3381             // Set branded watermark
       
  3382             SetBrandedListWatermarkL();
       
  3383             iMailTreeListVisualizer->ShowListL();
       
  3384 
       
  3385             ScaleControlBarL();
       
  3386             SetBrandedMailBoxIconL();
       
  3387             }
       
  3388         // Update the folder/sort popup layout in case it happened to be open
       
  3389         if ( iAppUi.FolderList().IsPopupShown() )
       
  3390             {
       
  3391             iAppUi.FolderList().HandleDynamicVariantSwitchL( aType );
       
  3392             }
       
  3393         }
       
  3394     if (iMarkingMode)
       
  3395         {
       
  3396         RefreshMarkingModeL();
       
  3397         }    
       
  3398 	}
       
  3399 
       
  3400 // ---------------------------------------------------------------------------
       
  3401 //
       
  3402 //
       
  3403 // ---------------------------------------------------------------------------
       
  3404 //
       
  3405 void CFSEmailUiMailListVisualiser::HandleDynamicVariantSwitchOnBackgroundL(
       
  3406         CFsEmailUiViewBase::TDynamicSwitchType aType )
       
  3407     {
       
  3408     FUNC_LOG;
       
  3409     CFsEmailUiViewBase::HandleDynamicVariantSwitchOnBackgroundL( aType );
       
  3410     if ( aType == ESkinChanged )
       
  3411         {
       
  3412         UpdateThemeL();
       
  3413         }
       
  3414     else if ( aType == EScreenLayoutChanged )
       
  3415         {
       
  3416         UpdateButtonTextsL();
       
  3417         }
       
  3418     }
       
  3419 
       
  3420 // ---------------------------------------------------------------------------
       
  3421 // Update texts for command area buttons
       
  3422 // ---------------------------------------------------------------------------
       
  3423 //
       
  3424 void CFSEmailUiMailListVisualiser::UpdateButtonTextsL()
       
  3425     {
       
  3426     if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  3427         {
       
  3428         // No texts in portrait mode
       
  3429         iNewEmailButton->SetTextL( KNullDesC() );
       
  3430         iSortButton->SetTextL( KNullDesC() );
       
  3431         }
       
  3432     else
       
  3433         {
       
  3434         // Set button text if necessary
       
  3435         HBufC* buttonText = GetSortButtonTextLC();
       
  3436         if ( buttonText )
       
  3437             {
       
  3438             iSortButton->SetTextL( *buttonText );
       
  3439             CleanupStack::PopAndDestroy( buttonText );
       
  3440             }
       
  3441 
       
  3442         iNewEmailButton->SetTextL( *iNewEmailText );
       
  3443         }
       
  3444     }
       
  3445 
       
  3446 // ---------------------------------------------------------------------------
       
  3447 //
       
  3448 // ---------------------------------------------------------------------------
       
  3449 //
       
  3450 TBool CFSEmailUiMailListVisualiser::HitTest(
       
  3451         const CAlfControl& aControl, const TPoint& aPoint ) const
       
  3452     {
       
  3453     FUNC_LOG;
       
  3454     TBool contains( EFalse );
       
  3455     const TInt visualCount( aControl.VisualCount() );
       
  3456     for( TInt index( 0 ); index < visualCount && !contains; ++index )
       
  3457         {
       
  3458         TRect rect( aControl.Visual( index ).DisplayRectTarget() );
       
  3459         if( rect.Contains( aPoint ) )
       
  3460             {
       
  3461             contains = ETrue;
       
  3462             }
       
  3463         }
       
  3464     return contains;
       
  3465     }
       
  3466 
       
  3467 // ---------------------------------------------------------------------------
       
  3468 //
       
  3469 // ---------------------------------------------------------------------------
       
  3470 //
       
  3471 TBool CFSEmailUiMailListVisualiser::HandleArrowEventInPortraitL(
       
  3472         const TInt aScancode,
       
  3473         const TAlfEvent& aEvent,
       
  3474         const TBool aShiftState )
       
  3475     {
       
  3476     FUNC_LOG;
       
  3477     TBool result( EFalse );
       
  3478 
       
  3479     if( aScancode == EStdKeyLeftArrow )
       
  3480         {
       
  3481         if( ( iControlBarControl ) &&
       
  3482             ( iFocusedControl == EMailListComponent ) )
       
  3483             {
       
  3484             // Move focus to control bar (focused button is
       
  3485             // sort button).
       
  3486             HandleCommandL( EFsEmailUiCmdGoToSwitchSorting );
       
  3487             result = ETrue;
       
  3488             }
       
  3489         else if( ( iControlBarControl ) &&
       
  3490                  ( iFocusedControl == EControlBarComponent  ) )
       
  3491             {
       
  3492             TInt focusedButtonId( iControlBarControl->GetFocusedButton()->Id() );
       
  3493             if ( focusedButtonId == iNewEmailButtonId )
       
  3494                 {
       
  3495                 // Change focus to mail list if there are any
       
  3496                 // emails in it.
       
  3497                 if( iModel->Count() )
       
  3498                     {
       
  3499                     iFocusedControl = EMailListComponent;
       
  3500                     result = EFalse;
       
  3501                     }
       
  3502                 // Leave focus to control bar because there are no
       
  3503                 // mails in mail list.
       
  3504                 else
       
  3505                     {
       
  3506                     iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  3507                     iFocusedControl = EControlBarComponent;
       
  3508                     result = ETrue; // Do not set focus to empty list
       
  3509                     }
       
  3510                 }
       
  3511             else
       
  3512                 {
       
  3513                 iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  3514                 iFocusedControl = EControlBarComponent;
       
  3515                 result = EFalse;
       
  3516                 }
       
  3517             }
       
  3518         else
       
  3519             {
       
  3520             iFocusedControl = EMailListComponent;
       
  3521             result = EFalse;
       
  3522             }
       
  3523         SetMskL();
       
  3524         }
       
  3525     else if( aScancode == EStdKeyRightArrow )
       
  3526         {
       
  3527         // Show toolbar if there is data on the list
       
  3528         const TInt modelCount( iModel->Count() );
       
  3529         TBool focusShown( IsFocusShown() );
       
  3530 
       
  3531         // If control bar is focused.
       
  3532         if( ( iControlBarControl ) &&
       
  3533             ( iFocusedControl == EControlBarComponent ) )
       
  3534             {
       
  3535             TInt focusedButtonId( iControlBarControl->GetFocusedButton()->Id() );
       
  3536 
       
  3537             // If sort button is focused and there are mails in mail
       
  3538             // list then focus is moved to mail list, otherwise
       
  3539             // leave focus to control bar
       
  3540             if( focusedButtonId == iSortButtonId )
       
  3541                 {
       
  3542                 if ( modelCount > 0 ) // Check for empty folder
       
  3543                     {
       
  3544                     iFocusedControl = EMailListComponent;
       
  3545                     result = EFalse;
       
  3546                     }
       
  3547                 else
       
  3548                     {
       
  3549                     iFocusedControl = EControlBarComponent;
       
  3550                     iControlBarControl->MakeSelectorVisible( focusShown );
       
  3551                     result = ETrue; // Do not set focus to empty list
       
  3552                     }
       
  3553                 }
       
  3554             else
       
  3555                 {
       
  3556                 iFocusedControl = EControlBarComponent;
       
  3557                 iControlBarControl->MakeSelectorVisible( focusShown );
       
  3558                 result = EFalse;
       
  3559                 }
       
  3560             }
       
  3561         else if( ( iControlBarControl ) &&
       
  3562                  ( iFocusedControl == EMailListComponent ) )
       
  3563             {
       
  3564             HandleCommandL( EFsEmailUiCmdGoToSwitchNewEmail );
       
  3565             result = ETrue;
       
  3566             }
       
  3567         else
       
  3568             {
       
  3569             iFocusedControl = EMailListComponent;
       
  3570             result = EFalse;
       
  3571             }
       
  3572         SetMskL();
       
  3573         }
       
  3574     else if( aScancode ==  EStdKeyDownArrow )
       
  3575         {
       
  3576         const TInt itemCount( iModel->Count() );
       
  3577         if ( iFocusedControl == EMailListComponent )
       
  3578             {
       
  3579             result = iMailList->TreeControl()->OfferEventL( aEvent );
       
  3580             if ( aShiftState )
       
  3581                 {
       
  3582                 DoScrollMarkUnmarkL(); // marking is done after moving the cursor
       
  3583                 }
       
  3584             }
       
  3585         else if( ( iFocusedControl == EControlBarComponent ) &&
       
  3586                  ( itemCount == 0 ) )
       
  3587             {
       
  3588             result = ETrue; // Do not set focus to empty list
       
  3589             }
       
  3590         else if( ( iFocusedControl == EControlBarComponent ) &&
       
  3591                  ( itemCount > 0 ) )
       
  3592             {
       
  3593             iFocusedControl = EMailListComponent;
       
  3594 
       
  3595             result = iMailList->TreeControl()->OfferEventL(aEvent);
       
  3596             if ( aShiftState )
       
  3597                 {
       
  3598                 DoScrollMarkUnmarkL(); // marking is done after moving the cursor
       
  3599                 }
       
  3600             }
       
  3601         else
       
  3602             {
       
  3603             result = EFalse;
       
  3604             }
       
  3605         SetMskL();
       
  3606         }
       
  3607     else if( aScancode == EStdKeyUpArrow )
       
  3608         {
       
  3609         iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  3610         if ( iFocusedControl == EMailListComponent )
       
  3611             {
       
  3612             if ( HighlightedIndex() == 0 )
       
  3613                 {
       
  3614                 HandleCommandL( EFsEmailUiCmdGoToSwitchFolder );
       
  3615                 result = ETrue;
       
  3616                 }
       
  3617             else
       
  3618                 {
       
  3619                 result = iMailList->TreeControl()->OfferEventL( aEvent );
       
  3620                 if ( aShiftState )
       
  3621                     {
       
  3622                     // marking is done after moving the cursor
       
  3623                     DoScrollMarkUnmarkL();
       
  3624                     }
       
  3625                 SetMskL();
       
  3626                 }
       
  3627             }
       
  3628         else if( iFocusedControl == EControlBarComponent )
       
  3629             {
       
  3630             result = ETrue;
       
  3631             }
       
  3632         else
       
  3633             {
       
  3634             result = EFalse;
       
  3635             }
       
  3636         }
       
  3637 
       
  3638     return result;
       
  3639     }
       
  3640 
       
  3641 // ---------------------------------------------------------------------------
       
  3642 //
       
  3643 // ---------------------------------------------------------------------------
       
  3644 //
       
  3645 TBool CFSEmailUiMailListVisualiser::HandleArrowEventInLandscapeL(
       
  3646         const TInt aScancode,
       
  3647         const TAlfEvent& aEvent,
       
  3648         const TBool aShiftState )
       
  3649     {
       
  3650     FUNC_LOG;
       
  3651     TBool result( EFalse );
       
  3652     if( aScancode == EStdKeyRightArrow )
       
  3653         {
       
  3654         if ( iFocusedControl == EMailListComponent )
       
  3655             {
       
  3656             HandleCommandL( EFsEmailUiCmdGoToSwitchFolder );
       
  3657             result = ETrue;
       
  3658             }
       
  3659         else if( iFocusedControl == EControlBarComponent )
       
  3660             {
       
  3661             iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  3662             result = ETrue;
       
  3663             }
       
  3664         }
       
  3665     else if( aScancode == EStdKeyLeftArrow )
       
  3666         {
       
  3667         if ( iFocusedControl == EControlBarComponent )
       
  3668             {
       
  3669             const TInt modelCount( iModel->Count() );
       
  3670             if( modelCount > 0 )
       
  3671                 {
       
  3672                 iFocusedControl = EMailListComponent;
       
  3673                 result = iMailList->TreeControl()->OfferEventL( aEvent );
       
  3674                 if( aShiftState )
       
  3675                     {
       
  3676                     // marking is done after moving the cursor
       
  3677                     DoScrollMarkUnmarkL();
       
  3678                     }
       
  3679                 }
       
  3680             else
       
  3681                 {
       
  3682                 iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  3683                 // Do not set focus to empty list
       
  3684                 result = ETrue;
       
  3685                 }
       
  3686             }
       
  3687         else if( iFocusedControl == EMailListComponent )
       
  3688             {
       
  3689             result = iMailList->TreeControl()->OfferEventL( aEvent );
       
  3690             if ( aShiftState )
       
  3691                 {
       
  3692                 // marking is done after moving the cursor
       
  3693                 DoScrollMarkUnmarkL();
       
  3694                 }
       
  3695            }
       
  3696         SetMskL();
       
  3697         }
       
  3698     if( aScancode == EStdKeyUpArrow )
       
  3699         {
       
  3700         if( iFocusedControl == EMailListComponent )
       
  3701             {
       
  3702             result = iMailList->TreeControl()->OfferEventL( aEvent );
       
  3703             if ( aShiftState )
       
  3704                 {
       
  3705                 // marking is done after moving the cursor
       
  3706                 DoScrollMarkUnmarkL();
       
  3707                 }
       
  3708             }
       
  3709         else if( iFocusedControl == EControlBarComponent )
       
  3710             {
       
  3711             TInt focusedButtonId( iControlBarControl->GetFocusedButton()->Id() );
       
  3712             if ( focusedButtonId == iNewEmailButtonId )
       
  3713                 {
       
  3714                 // Change focus to mail list if there are any
       
  3715                 // mails in it.
       
  3716                 if( iModel->Count() > 0 )
       
  3717                     {
       
  3718                     iFocusedControl = EMailListComponent;
       
  3719                     result = EFalse;
       
  3720                     }
       
  3721                 // Leave focus to control bar because there are no
       
  3722                 // mails in mail list.
       
  3723                 else
       
  3724                     {
       
  3725                     // Do not set focus to empty list
       
  3726                     iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  3727                     result = ETrue;
       
  3728                     }
       
  3729                 }
       
  3730             else
       
  3731                 {
       
  3732                 iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  3733                 result = static_cast<CAlfControl*>( iControlBarControl )->OfferEventL( aEvent );
       
  3734                 }
       
  3735             }
       
  3736         SetMskL();
       
  3737         }
       
  3738     else if( aScancode == EStdKeyDownArrow )
       
  3739         {
       
  3740         if( iFocusedControl == EMailListComponent )
       
  3741             {
       
  3742             result = iMailList->TreeControl()->OfferEventL( aEvent );
       
  3743             if( aShiftState )
       
  3744                 {
       
  3745                 // marking is done after moving the cursor
       
  3746                 DoScrollMarkUnmarkL();
       
  3747                 }
       
  3748             }
       
  3749         else if( iFocusedControl == EControlBarComponent )
       
  3750             {
       
  3751             const TInt modelCount( iModel->Count() );
       
  3752             TInt focusedButtonId( iControlBarControl->GetFocusedButton()->Id() );
       
  3753             // If sort button is focused and there are mails in mail
       
  3754             // list then focus is moved to mail list, otherwise
       
  3755             // leave focus to control bar
       
  3756             if( focusedButtonId == iSortButtonId )
       
  3757                 {
       
  3758                 if ( modelCount > 0 ) // Check for empty folder
       
  3759                     {
       
  3760                     iFocusedControl = EMailListComponent;
       
  3761                     result = EFalse;
       
  3762                     }
       
  3763                 else
       
  3764                     {
       
  3765                     iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  3766                     result = ETrue; // Do not set focus to empty list
       
  3767                     }
       
  3768                 }
       
  3769             else
       
  3770                 {
       
  3771                 iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  3772                 result = static_cast<CAlfControl*>( iControlBarControl )->OfferEventL( aEvent );
       
  3773                 }
       
  3774             }
       
  3775         SetMskL();
       
  3776         }
       
  3777 
       
  3778     return result;
       
  3779     }
       
  3780 
       
  3781 // ---------------------------------------------------------------------------
       
  3782 //
       
  3783 // ---------------------------------------------------------------------------
       
  3784 //
       
  3785 void CFSEmailUiMailListVisualiser::UpdateThemeL(const TBool aSystemUpdate)
       
  3786     {
       
  3787     iSkinChanged = iSkinChanged || aSystemUpdate;
       
  3788 
       
  3789     iFocusedTextColor = iAppUi.LayoutHandler()->ListFocusedStateTextSkinColor();
       
  3790     iNormalTextColor = iAppUi.LayoutHandler()->ListNormalStateTextSkinColor();
       
  3791     iNodeTextColor = iAppUi.LayoutHandler()->ListNodeTextColor();
       
  3792 
       
  3793     iNewEmailButton->SetNormalTextColor( iNormalTextColor );
       
  3794     iNewEmailButton->SetFocusedTextColor( iFocusedTextColor );
       
  3795 
       
  3796     iFolderListButton->SetNormalTextColor( iNormalTextColor );
       
  3797     iFolderListButton->SetFocusedTextColor( iFocusedTextColor );
       
  3798 
       
  3799     iSortButton->SetNormalTextColor( iNormalTextColor );
       
  3800     iSortButton->SetFocusedTextColor( iFocusedTextColor );
       
  3801 
       
  3802     //sometimes theme wasn't properly refreshed on buttons, this helps
       
  3803     iNewEmailButton->HideButton();
       
  3804     iNewEmailButton->ShowButtonL();
       
  3805 
       
  3806     iFolderListButton->HideButton();
       
  3807     iFolderListButton->ShowButtonL();
       
  3808 
       
  3809     iSortButton->HideButton();
       
  3810     iSortButton->ShowButtonL();
       
  3811     }
       
  3812 
       
  3813 // ---------------------------------------------------------------------------
       
  3814 // HandleForegroundEventL
       
  3815 // Function checks in foregroundevent that whether settings have changed and
       
  3816 // If there is a need to refresh the list.
       
  3817 // ---------------------------------------------------------------------------
       
  3818 //
       
  3819 void CFSEmailUiMailListVisualiser::HandleForegroundEventL( TBool aForeground )
       
  3820 	{
       
  3821     FUNC_LOG;
       
  3822     if( iMailFolder )
       
  3823         {
       
  3824         //emailindicator handling, is removed  from 9.2
       
  3825         //TRAP_IGNORE(TFsEmailStatusPaneIndicatorHandler::StatusPaneMailIndicatorHandlingL( iMailFolder->GetMailBoxId().Id()));
       
  3826         //Update mailbox widget index status in homescreen
       
  3827         TFsEmailUiUtility::ToggleEmailIconL(EFalse, iMailFolder->GetMailBoxId() );
       
  3828         }
       
  3829     
       
  3830 	if ( aForeground && iFirstStartCompleted ) // Safety
       
  3831 	    {
       
  3832 	    // Update mail list settings and date formats, is done every time
       
  3833 	    // the user might have changed these in settings, so the list needs to refresh
       
  3834 	    // Store previous modes
       
  3835 	    TInt prevListMode = iListMode;
       
  3836 	    TInt prevNodesmode = iNodesInUse;
       
  3837 	    TAknUiZoom prevZoomLevel = iCurrentZoomLevel;
       
  3838 	    STimeDateFormats prevDateFormats = MailListTimeDateSettings();
       
  3839 
       
  3840 	    // Get new settings and list drawing modes
       
  3841 	    CAknEnv::Static()->GetCurrentGlobalUiZoom( iCurrentZoomLevel );
       
  3842 	    UpdateMailListSettingsL();
       
  3843 	    UpdateMailListTimeDateSettings();
       
  3844 
       
  3845 	    // Check sync icon timer and sync status
       
  3846 	    ConnectionIconHandling();
       
  3847 
       
  3848 	    // Updates the folder list's size after the screensaver
       
  3849 	    iAppUi.FolderList().HandleForegroundEventL();
       
  3850 
       
  3851 	    // Check for changed settings, in that case a complete list refresh is needed
       
  3852 	    if ( iSkinChanged
       
  3853 	         || iDateChanged
       
  3854 	         || iListMode != prevListMode
       
  3855 	         || iNodesInUse != prevNodesmode
       
  3856 	         || iCurrentZoomLevel != prevZoomLevel
       
  3857 	         || prevDateFormats.iDateFormat != iDateFormats.iDateFormat
       
  3858 	         || prevDateFormats.iTimeFormat != iDateFormats.iTimeFormat
       
  3859 	         || prevDateFormats.iAmPmPosition != iDateFormats.iAmPmPosition
       
  3860 	         || prevDateFormats.iDateSeparator != iDateFormats.iDateSeparator
       
  3861 	         || prevDateFormats.iTimeSeparator != iDateFormats.iTimeSeparator )
       
  3862 	        {
       
  3863 	        // Store the list of marked items. The markings are erased when the list
       
  3864 	        // is repopulated and, hence, the markings need to be reset after the
       
  3865 	        // refreshing is done. The marked items must be identified by the message
       
  3866 	        // ID rather than with the list ID because refreshing may change the list IDs.
       
  3867 	        RArray<TFSMailMsgId> markedMessages;
       
  3868 	        CleanupClosePushL( markedMessages );
       
  3869 	        GetMarkedMessagesL( markedMessages );
       
  3870 	        // Store the message ID of the focused item
       
  3871 	        TFSMailMsgId msgIdBeforeRefresh = MsgIdFromListId( iMailList->FocusedItem() );
       
  3872 	        TFsTreeItemId firstVisibleListId = iMailTreeListVisualizer->FirstVisibleItem();
       
  3873 	        TInt modelFirstIndexBeforeUpdate = ModelIndexFromListId( firstVisibleListId );
       
  3874 	        TInt highlightedIndexBeforeUpdate = HighlightedIndex();
       
  3875 	        TInt modelCountBeforeUpdate = iModel->Count();
       
  3876 
       
  3877 	        UpdateMailListModelL();
       
  3878 	        if ( markedMessages.Count() )
       
  3879 	            {
       
  3880 	            RefreshL( &msgIdBeforeRefresh );
       
  3881 	            // Restore the marking status
       
  3882 	            MarkMessagesIfFoundL( markedMessages );
       
  3883 	            }
       
  3884 	        else
       
  3885 	            {
       
  3886 	            RefreshDeferred( &msgIdBeforeRefresh );
       
  3887 	            }
       
  3888 	        CleanupStack::PopAndDestroy( &markedMessages );
       
  3889 	        iSkinChanged = EFalse; // Toggle handled
       
  3890 	        iDateChanged = EFalse; // Toggle handled
       
  3891 	        }
       
  3892         if (iMarkingMode)
       
  3893             {
       
  3894             RefreshMarkingModeL();
       
  3895             }
       
  3896 	    }
       
  3897 	}
       
  3898 
       
  3899 
       
  3900 // ---------------------------------------------------------------------------
       
  3901 //
       
  3902 //
       
  3903 // ---------------------------------------------------------------------------
       
  3904 //
       
  3905 void CFSEmailUiMailListVisualiser::HandleCommandL( TInt aCommand )
       
  3906     {
       
  3907     FUNC_LOG;
       
  3908     TIMESTAMP( "Message list command for handling" );
       
  3909     CompletePendingRefresh();
       
  3910 
       
  3911     // custom command handling for launching plugin settings
       
  3912    	if ( EFsEmailUiCmdSettingsBaseCommandId <= aCommand
       
  3913    		 && EFsEmailUiCmdSettingsBaseCommandIdMax > aCommand )
       
  3914    		{
       
  3915 		CESMailSettingsPlugin::TSubViewActivationData activationData;
       
  3916 		activationData.iAccount = iAppUi.GetActiveMailbox()->GetId();
       
  3917 		// which settings plugin subview will be activated
       
  3918 		TInt selectedCommand = aCommand - EFsEmailUiCmdSettingsBaseCommandId;
       
  3919 		activationData.iSubviewId = selectedCommand;
       
  3920 
       
  3921 		TUid pluginUid = iAppUi.GetActiveMailbox()->GetSettingsUid();
       
  3922 
       
  3923         // If plugin view does not exist, create and register it to app ui.
       
  3924         if ( !iAppUi.View( pluginUid ) )
       
  3925             {
       
  3926             CESMailSettingsPlugin* plugin = CESMailSettingsPlugin::NewL( pluginUid );
       
  3927             CleanupStack::PushL( plugin );
       
  3928             iAppUi.AddViewL( plugin ); // Ownership is transferred.
       
  3929             CleanupStack::Pop( plugin );
       
  3930             }
       
  3931    		TUid messageId = TUid::Uid( CESMailSettingsPlugin::EActivateMailSettingsSubview );
       
  3932 		const TPckgBuf<CESMailSettingsPlugin::TSubViewActivationData> pluginMessagePkg( activationData );
       
  3933 
       
  3934         StatusPane()->SwitchLayoutL( R_AVKON_STATUS_PANE_LAYOUT_USUAL );
       
  3935         iAppUi.EnterPluginSettingsViewL( pluginUid, messageId, pluginMessagePkg );
       
  3936    		}
       
  3937 
       
  3938    	// Many commands may be targetted either to the focused item or to the marked item(s).
       
  3939    	// Get list of marked or focused items.
       
  3940     RFsTreeItemIdList actionTargetItems;
       
  3941     CleanupClosePushL( actionTargetItems );
       
  3942     GetActionsTargetEntriesL( actionTargetItems );
       
  3943 
       
  3944     // Check if the focus needs to be removed.
       
  3945     if ( ( iStylusPopUpMenuVisible ) &&
       
  3946          ( aCommand == KErrCancel ||
       
  3947            aCommand == EFsEmailUiCmdActionsDelete ||
       
  3948     	   aCommand == EFsEmailUiCmdMarkAsRead ||
       
  3949     	   aCommand == EFsEmailUiCmdMarkAsUnread ||
       
  3950     	   aCommand == EFsEmailUiCmdActionsMove ||
       
  3951     	   aCommand == EFsEmailUiCmdActionsMoveMessage ||
       
  3952     	   aCommand == EFsEmailUiCmdMarkingModeFromPopUp ||
       
  3953     	   aCommand == EFsEmailUiCmdActionsCollapseAll ||
       
  3954     	   aCommand == EFsEmailUiCmdActionsExpandAll ) )
       
  3955     	{
       
  3956    		// We end up here if the user selects an option from the pop up menu
       
  3957     	// or exits the menu by tapping outside of it's area.
       
  3958     	// Remove the focus from a list item if an item is focused.
       
  3959     	iStylusPopUpMenuVisible = EFalse;
       
  3960     	iAppUi.SetFocusVisibility( EFalse );
       
  3961     	}
       
  3962 
       
  3963     switch( aCommand )
       
  3964         {
       
  3965     	case EAknSoftkeyOpen:
       
  3966             {
       
  3967             TIMESTAMP( "Open email selected from message list" );
       
  3968             if( !iAppUi.IsFocusShown() )
       
  3969                 {
       
  3970                 iAppUi.SetFocusVisibility( ETrue );
       
  3971                 break;
       
  3972                 }
       
  3973             }
       
  3974        	case EAknSoftkeySelect:
       
  3975        	    {
       
  3976        	    TIMESTAMP( "Open email selected from message list" );
       
  3977        	    if ( iFocusedControl == EMailListComponent )
       
  3978        	        {
       
  3979        	        CFSEmailUiMailListModelItem* item = dynamic_cast<CFSEmailUiMailListModelItem*>(iModel->Item(HighlightedIndex()));
       
  3980        	        // MAIL ITEM; OPEN MAIL
       
  3981        	        if ( item && item->ModelItemType() == ETypeMailItem )
       
  3982        	            {
       
  3983        	            CFSMailMessage* messagePtr = &item->MessagePtr();
       
  3984        	            if ( messagePtr )
       
  3985        	                {
       
  3986        	                OpenHighlightedMailL();
       
  3987        	                }
       
  3988        	            }
       
  3989        	        }
       
  3990        	    }
       
  3991        	    break;
       
  3992        	case EAknSoftkeyChange:
       
  3993        	    {
       
  3994     		if( !iAppUi.IsFocusShown() )
       
  3995     			{
       
  3996     			iAppUi.SetFocusVisibility( ETrue );
       
  3997     			break;
       
  3998     			}
       
  3999        	    if( iFocusedControl == EControlBarComponent )
       
  4000        	        {
       
  4001        	        TInt focusedButtonId = iControlBarControl->GetFocusedButton()->Id();
       
  4002        	        if ( focusedButtonId == iFolderListButtonId )
       
  4003        	            {
       
  4004                     //<cmail>
       
  4005                     //Set touchmanager not active for preventing getting events.
       
  4006                     DisableMailList(ETrue);
       
  4007                     //</cmail>
       
  4008        	            iAppUi.ShowFolderListInPopupL( FolderId(), this, iFolderListButton );
       
  4009        	            }
       
  4010        	        else if( focusedButtonId == iSortButtonId )
       
  4011        	            {
       
  4012        	            TFSFolderType folderType;
       
  4013        	            if( iMailFolder )
       
  4014        	                {
       
  4015        	                folderType = iMailFolder->GetFolderType();
       
  4016        	                }
       
  4017        	            else
       
  4018        	                {
       
  4019        	                folderType = EFSInbox;
       
  4020        	                }
       
  4021                     // <cmail> Sorting set possible even for empty mailbox
       
  4022                     // Show sort if model has data.
       
  4023                     //if ( iModel->Count() )
       
  4024                     //    {
       
  4025                     // </cmail>
       
  4026                         //<cmail>
       
  4027                         //Set touchmanager not active for preventing getting events.
       
  4028                         DisableMailList(ETrue);
       
  4029                         //</cmail>
       
  4030                         iAppUi.ShowSortListInPopupL( iCurrentSortCriteria, folderType, this, iSortButton );
       
  4031                     // <cmail>
       
  4032                     //    }
       
  4033                     // </cmail>
       
  4034        	            }
       
  4035        	        }
       
  4036        	    }
       
  4037        	    break;
       
  4038         case EAknSoftkeyBack:
       
  4039        		if ( !iAppUi.ViewSwitchingOngoing() )
       
  4040 				{
       
  4041 				NavigateBackL();
       
  4042 				}
       
  4043         	break;
       
  4044         case EAknSoftkeyCancel:
       
  4045             if (iMarkingMode)
       
  4046                 {
       
  4047                 ExitMarkingModeL();
       
  4048                 }
       
  4049             break;
       
  4050         case EEikCmdExit:
       
  4051         case EAknSoftkeyExit:
       
  4052         case EFsEmailUiCmdExit:
       
  4053             TIMESTAMP( "Exit selected from message list" );
       
  4054             iAppUi.Exit();
       
  4055             break;
       
  4056        	case EFsEmailUiCmdCalActionsReplyAsMail:
       
  4057 		case EFsEmailUiCmdActionsReply:
       
  4058 			{
       
  4059 			TIMESTAMP( "Reply to selected from message list" );
       
  4060    	   	 	ReplyL( NULL ); // Function will check marked/highlighted msg
       
  4061 			}
       
  4062             break;
       
  4063 		case EFsEmailUiCmdActionsReplyAll:
       
  4064 			{
       
  4065 			TIMESTAMP( "Reply to all selected from message list" );
       
  4066 			ReplyAllL( NULL ); // Function will check marked/highlighted msg
       
  4067 			}
       
  4068             break;
       
  4069        	case EFsEmailUiCmdCalActionsForwardAsMail:
       
  4070 		case EFsEmailUiCmdActionsForward:
       
  4071 			{
       
  4072 			TIMESTAMP( "Forward selected from message list" );
       
  4073            	ForwardL( NULL ); // Function will check marked/highlighted msg
       
  4074 			}
       
  4075             break;
       
  4076        	case EFsEmailUiCmdActionsCallSender:
       
  4077 			{
       
  4078        		if ( !iAppUi.ViewSwitchingOngoing() )
       
  4079 				{
       
  4080 				if ( iMailFolder && iMailFolder->GetFolderType() != EFSOutbox &&
       
  4081 					 iMailFolder->GetFolderType() != EFSDraftsFolder )
       
  4082 					{
       
  4083 					// Calling can happen only when there's exactly one message marked or in focus
       
  4084 					if ( actionTargetItems.Count() == 1 )
       
  4085 						{
       
  4086 						CFSMailMessage& message = MsgPtrFromListIdL( actionTargetItems[0] );
       
  4087 						CFSMailAddress* fromAddress = message.GetSender();
       
  4088 						TDesC* mailAddress(0);
       
  4089 						if ( fromAddress )
       
  4090 						    {
       
  4091 						    mailAddress = &fromAddress->GetEmailAddress();
       
  4092 						    }
       
  4093 						if ( mailAddress && mailAddress->Length() )
       
  4094 						    {
       
  4095 						    if ( iMailFolder->GetFolderType() == EFSSentFolder )
       
  4096 						        {
       
  4097 	                            CFsDelayedLoader::InstanceL()->GetContactHandlerL()->FindAndCallToContactByEmailL(
       
  4098 	                                    *mailAddress, iAppUi.GetActiveMailbox(), this, EFalse );
       
  4099 						        }
       
  4100 						    else
       
  4101 						        {
       
  4102                                 CFsDelayedLoader::InstanceL()->GetContactHandlerL()->FindAndCallToContactByEmailL(
       
  4103                                         *mailAddress, iAppUi.GetActiveMailbox(), this, ETrue );
       
  4104 						        }
       
  4105 						    }
       
  4106 						}
       
  4107 					}
       
  4108 				}
       
  4109 			}
       
  4110 			break;
       
  4111         case EFsEmailUiCmdMarkAsRead:
       
  4112         	{
       
  4113 			// Change status of marked or highlighted
       
  4114 			if ( CountMarkedItemsL() )
       
  4115 				{
       
  4116 				ChangeReadStatusOfMarkedL( ETrue );
       
  4117 				}
       
  4118 			else
       
  4119 				{
       
  4120                 ChangeReadStatusOfHighlightedL( ETrue );
       
  4121 				}
       
  4122         	}
       
  4123         	break;
       
  4124         case EFsEmailUiCmdMarkAsUnread:
       
  4125         	{
       
  4126             // Change status of marked or highlighted
       
  4127 			if ( CountMarkedItemsL() )
       
  4128 				{
       
  4129 				ChangeReadStatusOfMarkedL( EFalse );
       
  4130 				}
       
  4131 			else
       
  4132 				{
       
  4133                 ChangeReadStatusOfHighlightedL( EFalse );
       
  4134 				}
       
  4135         	}
       
  4136 			break;
       
  4137 		case EFsEmailUiCmdGoToTop:
       
  4138 			{
       
  4139 			// Safety check, ignore command if the list is empty
       
  4140 			if( iTreeItemArray.Count() )
       
  4141 			    {
       
  4142 	            if ( iFocusedControl != EMailListComponent )
       
  4143 	                {
       
  4144 	                iFocusedControl = EMailListComponent;
       
  4145 	                iMailList->SetFocusedL( ETrue );
       
  4146 	                iControlBarControl->SetFocusL( EFalse );
       
  4147 	                }
       
  4148 	            // No need to check for nodes as in move to bottom.
       
  4149 	            iMailTreeListVisualizer->SetFocusedItemL( iTreeItemArray[0].iListItemId );
       
  4150 			    }
       
  4151             }
       
  4152             break;
       
  4153 		case EFsEmailUiCmdGoToBottom:
       
  4154 			{
       
  4155 	         // Safety check, ignore command if the list is empty
       
  4156             if( iTreeItemArray.Count() )
       
  4157                 {
       
  4158              	if ( iFocusedControl != EMailListComponent )
       
  4159             		{
       
  4160             		iFocusedControl = EMailListComponent;
       
  4161             		iMailList->SetFocusedL( ETrue );
       
  4162             		iControlBarControl->SetFocusL( EFalse );
       
  4163             		}
       
  4164 
       
  4165     		 	TFsTreeItemId bottomItem = iTreeItemArray[iTreeItemArray.Count()-1].iListItemId;
       
  4166     		 	TFsTreeItemId parentItem = ParentNode( bottomItem ); // parent node of the bottom item
       
  4167 
       
  4168     			// Check whether the parent is node and is collapsed
       
  4169     			if ( parentItem>0 && !iMailList->IsExpanded( parentItem ) )
       
  4170     				{
       
  4171     				bottomItem = parentItem;
       
  4172     				}
       
  4173     	       	iMailTreeListVisualizer->SetFocusedItemL( bottomItem );
       
  4174                 }
       
  4175    			}
       
  4176             break;
       
  4177         case EFsEmailUiCmdPageUp:
       
  4178             {
       
  4179             TKeyEvent simEvent = { EKeyPageUp, EStdKeyPageUp, 0, 0 };
       
  4180             iCoeEnv->SimulateKeyEventL( simEvent, EEventKey );
       
  4181             }
       
  4182             break;
       
  4183         case EFsEmailUiCmdPageDown:
       
  4184             {
       
  4185             TKeyEvent simEvent = { EKeyPageDown, EStdKeyPageDown, 0, 0 };
       
  4186             iCoeEnv->SimulateKeyEventL( simEvent, EEventKey );
       
  4187             }
       
  4188             break;
       
  4189        	case EFsEmailUiCmdActionsDeleteCalEvent:
       
  4190 		case EFsEmailUiCmdActionsDelete:
       
  4191 			{
       
  4192 			TIMESTAMP( "Delete to selected from message list" );
       
  4193 			TInt index = HighlightedIndex();
       
  4194 			CFSEmailUiMailListModelItem* item =
       
  4195 				dynamic_cast<CFSEmailUiMailListModelItem*>(
       
  4196 						iModel->Item( index ) );
       
  4197 
       
  4198 			// If selected item is separator (divider) mark/unmark all messages
       
  4199 			// under it.
       
  4200 
       
  4201 			// Delete message only if mail list component is focused
       
  4202 			// or if there are some marked items
       
  4203 			TInt markedItems( CountMarkedItemsL() );
       
  4204             const TBool isNode(iMailList->IsNode(iMailList->FocusedItem()));
       
  4205             if (iFocusedControl == EMailListComponent || markedItems
       
  4206                     || isNode)
       
  4207                 {
       
  4208                 DeleteMessagesL();
       
  4209                 }
       
  4210             }
       
  4211             break;
       
  4212         case EFsEmailUiCmdCompose:
       
  4213             {
       
  4214             // Switching to another view can take some time and this view
       
  4215             // can still receive some commands - so ignore them.
       
  4216             if ( iAppUi.CurrentActiveView() == this )
       
  4217                 {
       
  4218                 TIMESTAMP( "Create new message selected from message list" );
       
  4219                 CreateNewMsgL();
       
  4220                 }
       
  4221             }
       
  4222             break;
       
  4223        	case EFsEmailUiCmdMessageDetails:
       
  4224 			{
       
  4225             // Message details can be viewed only when there's exactly one message marked or in focus
       
  4226             if ( actionTargetItems.Count() == 1 )
       
  4227                 {
       
  4228                 CFSMailMessage& message = MsgPtrFromListIdL( actionTargetItems[0] );
       
  4229 	  			TMsgDetailsActivationData msgDetailsData;
       
  4230 	  			msgDetailsData.iMailBoxId = iAppUi.GetActiveMailboxId();
       
  4231 	  			msgDetailsData.iFolderId = FolderId();
       
  4232 	  			msgDetailsData.iMessageId = message.GetMessageId();
       
  4233 				const TPckgBuf<TMsgDetailsActivationData> pkgOut( msgDetailsData );
       
  4234 				iAppUi.EnterFsEmailViewL( MsgDetailsViewId, KStartMsgDetailsToBeginning, pkgOut );
       
  4235 				}
       
  4236 			}
       
  4237 			break;
       
  4238        	case EFsEmailUiCmdSettingsGlobal:
       
  4239        		{
       
  4240   			iAppUi.EnterFsEmailViewL( GlobalSettingsViewId );
       
  4241        		}
       
  4242        		break;
       
  4243        	case EFsEmailUiCmdSettingsService:
       
  4244        	case EFsEmailUiCmdSettingsMailbox:
       
  4245        		{
       
  4246 			CESMailSettingsPlugin::TSubViewActivationData activationData;
       
  4247 			activationData.iAccount = iAppUi.GetActiveMailbox()->GetId();
       
  4248 			activationData.iSubviewId = 0;
       
  4249 			if ( EFsEmailUiCmdSettingsService == aCommand )
       
  4250 		 		{
       
  4251 				activationData.iSubviewId = 1;
       
  4252 				}
       
  4253 
       
  4254 			TUid pluginUid = iAppUi.GetActiveMailbox()->GetSettingsUid();
       
  4255 			// register plugin view if not exists so that activation can be made
       
  4256 			if ( !iAppUi.View( pluginUid ) )
       
  4257 				{
       
  4258 				CESMailSettingsPlugin* plugin = CESMailSettingsPlugin::NewL( pluginUid );
       
  4259 				CleanupStack::PushL( plugin );
       
  4260 				iAppUi.AddViewL( plugin );
       
  4261 				CleanupStack::Pop( plugin );
       
  4262 				}
       
  4263        		TUid messageId = TUid::Uid( CESMailSettingsPlugin::EActivateMailSettingsSubview );
       
  4264 			const TPckgBuf<CESMailSettingsPlugin::TSubViewActivationData> pluginMessagePkg( activationData );
       
  4265 			iAppUi.EnterPluginSettingsViewL( pluginUid, messageId, pluginMessagePkg );
       
  4266        		}
       
  4267        		break;
       
  4268        	case EFsEmailUiCmdOpen:
       
  4269         case EFsEmailUiCmdActionsOpen:
       
  4270         	{
       
  4271         	TIMESTAMP( "Open email selected from message list" );
       
  4272 	        if ( iFocusedControl == EMailListComponent )
       
  4273 	            {
       
  4274 	            // Opening can happen only when there's exactly one message marked or in focus
       
  4275 	            if ( actionTargetItems.Count() == 1 )
       
  4276 	                {
       
  4277 	                OpenMailItemL( actionTargetItems[0] );
       
  4278 	                }
       
  4279 	            }
       
  4280 			}
       
  4281         	break;
       
  4282         case EFsEmailUiCmdActionsFlag:
       
  4283 	        {
       
  4284             SetMessageFollowupFlagL();
       
  4285 	        }
       
  4286 	        break;
       
  4287         case EFsEmailUiCmdActionsCollapseAll:
       
  4288             // Safety check, ignore command if the list is empty
       
  4289             if( iMailList->Count() )
       
  4290                 {
       
  4291             	CollapseAllNodesL();
       
  4292                 }
       
  4293         	break;
       
  4294        	case EFsEmailUiCmdActionsExpandAll:
       
  4295        	    // Safety check, ignore command if the list is empty
       
  4296        	    if( iMailList->Count() )
       
  4297        	        {
       
  4298            		ExpandAllNodesL();
       
  4299                 }
       
  4300 			break;
       
  4301         case EFsEmailUiCmdCollapse:
       
  4302     		if( !iAppUi.IsFocusShown() )
       
  4303     			{
       
  4304     			iAppUi.SetFocusVisibility( ETrue );
       
  4305     			break;
       
  4306     			}
       
  4307             // Safety check, ignore command if the list is empty
       
  4308             if( iMailList->Count() )
       
  4309                 {
       
  4310                 ExpandOrCollapseL();
       
  4311                 }
       
  4312             break;
       
  4313         case EFsEmailUiCmdExpand:
       
  4314     		if( !iAppUi.IsFocusShown() )
       
  4315     			{
       
  4316     			iAppUi.SetFocusVisibility( ETrue );
       
  4317     			break;
       
  4318     			}
       
  4319             // Safety check, ignore command if the list is empty
       
  4320             if( iMailList->Count() )
       
  4321                 {
       
  4322                 ExpandOrCollapseL();
       
  4323                 }
       
  4324             break;
       
  4325         case EFsEmailUiCmdSearch:
       
  4326         	{
       
  4327 			TSearchListActivationData tmp;
       
  4328 			tmp.iMailBoxId = iAppUi.GetActiveMailbox()->GetId();
       
  4329 			const TPckgBuf<TSearchListActivationData> pkgOut( tmp );
       
  4330 			iAppUi.EnterFsEmailViewL( SearchListViewId, KStartNewSearch, pkgOut );
       
  4331         	}
       
  4332         	break;
       
  4333 // <cmail> Prevent Download Manager opening with attachments
       
  4334 //       	case EFsEmailUiCmdDownloadManager:
       
  4335 //  			iAppUi.EnterFsEmailViewL( DownloadManagerViewId );
       
  4336 //			break;
       
  4337 // </cmail>
       
  4338         case EFsEmailUiCmdMarkingModeFromPopUp:
       
  4339             {
       
  4340             EnterMarkingModeL();
       
  4341             // Mark current item first
       
  4342             TInt focusedItem = iMailList->FocusedItem();
       
  4343             if ( focusedItem > 0 && iFocusedControl == EMailListComponent )
       
  4344                 {
       
  4345                 CFSEmailUiMailListModelItem* item = dynamic_cast<CFSEmailUiMailListModelItem*>(iModel->Item(HighlightedIndex()));
       
  4346 				if ( item && item->ModelItemType() == ETypeMailItem )
       
  4347 				    {
       
  4348                     iMailList->MarkItemL( iMailList->FocusedItem(), ETrue );
       
  4349 					}
       
  4350 				else if ( item && item->ModelItemType() == ETypeSeparator )
       
  4351 					{
       
  4352 					TInt index = HighlightedIndex();
       
  4353 					MarkItemsUnderSeparatorL( ETrue, index );
       
  4354 					}
       
  4355                 }
       
  4356             }
       
  4357             break;        
       
  4358         case EFsEmailUiCmdMarkingMode:
       
  4359             {
       
  4360             EnterMarkingModeL();
       
  4361             }
       
  4362             break;
       
  4363         case EFsEmailUiCmdMarkingModeDelete:
       
  4364             {
       
  4365             DeleteMessagesL();
       
  4366             }
       
  4367             break;
       
  4368         case EFsEmailUiCmdMarkingModeUnread:
       
  4369             {
       
  4370             ChangeReadStatusOfMarkedL( EFalse );
       
  4371             ExitMarkingModeL();
       
  4372             }
       
  4373             break;
       
  4374         case EFsEmailUiCmdMarkingModeRead:
       
  4375             {
       
  4376             ChangeReadStatusOfMarkedL( ETrue );
       
  4377             ExitMarkingModeL();
       
  4378             }
       
  4379             break;            
       
  4380         case EFsEmailUiCmdMarkingModeFollowUp:
       
  4381             {
       
  4382             SetMessageFollowupFlagL();
       
  4383             }
       
  4384             break;            
       
  4385         case EFsEmailUiCmdMarkingModeMarkAll:
       
  4386             {
       
  4387             MarkAllItemsL();
       
  4388             }
       
  4389             break;
       
  4390         case EFsEmailUiCmdMarkingModeUnmarkAll:
       
  4391             {
       
  4392             UnmarkAllItemsL();
       
  4393             }
       
  4394             break;
       
  4395 		case EFsEmailUiCmdReadEmail:
       
  4396 			{
       
  4397 			iAppUi.StartReadingEmailsL();
       
  4398 			}
       
  4399 			break;
       
  4400        	case EFsEmailUiCmdSync:
       
  4401 			{
       
  4402 			TBool supportsSync = iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaSupportsSync );
       
  4403 			if ( supportsSync )
       
  4404 			    {
       
  4405 			    // If synchronizing is ongoing and a new sync is started we ignore it
       
  4406 			    if( !GetLatestSyncState() )
       
  4407 			        {
       
  4408 			        iAppUi.SyncActiveMailBoxL();
       
  4409 			        // Sync was started by the user
       
  4410 			        ManualMailBoxSync( ETrue );
       
  4411 			        }
       
  4412 			    }
       
  4413 			  else
       
  4414 			    {
       
  4415 			    //POP3 synchronise
       
  4416 				iAppUi.DoAutoConnectL();
       
  4417 				}
       
  4418 			}
       
  4419 			break;
       
  4420        	case EFsEmailUiCmdCancelSync:
       
  4421        	    {
       
  4422        	    if ( GetLatestSyncState() )
       
  4423        	        {
       
  4424                 iAppUi.StopActiveMailBoxSyncL();
       
  4425        	        }
       
  4426        	    }
       
  4427        	    break;
       
  4428        	case EFsEmailUiCmdGoOffline:
       
  4429         	{
       
  4430     	   	iAppUi.GetActiveMailbox()->GoOfflineL();
       
  4431         	}
       
  4432         	break;
       
  4433         case EFsEmailUiCmdGoOnline:
       
  4434         	{
       
  4435 			CFSMailBox* mb = iAppUi.GetActiveMailbox();
       
  4436         	mb->GoOnlineL();
       
  4437         	}
       
  4438         	break;
       
  4439        	case EFsEmailUiCmdHelp:
       
  4440 			{
       
  4441 
       
  4442 			TFsEmailUiUtility::LaunchHelpL( KFSE_HLP_LAUNCHER_GRID );
       
  4443 			}
       
  4444 			break;
       
  4445 
       
  4446 
       
  4447     	case EFsEmailUiCmdActionsAddContact:
       
  4448     		{
       
  4449     		// contact can be got from message only when there's exactly one target message
       
  4450     		if ( actionTargetItems.Count() == 1 && iMailFolder )
       
  4451 				{
       
  4452 				CFSMailMessage& message = MsgPtrFromListIdL( actionTargetItems[0] );
       
  4453 
       
  4454 				CFSMailAddress* addressToBeStored(0);
       
  4455 				TInt folderType = iMailFolder->GetFolderType();
       
  4456 				// Use first to recepient in outbox, drafts and sent if found.
       
  4457 				if ( folderType == EFSOutbox || folderType == EFSDraftsFolder || folderType == EFSSentFolder )
       
  4458 				    {
       
  4459 				    RPointerArray<CFSMailAddress>& toArray = message.GetToRecipients();
       
  4460 				    if ( toArray.Count() )
       
  4461 				        {
       
  4462 				        addressToBeStored = toArray[0];
       
  4463 				        }
       
  4464 				    }
       
  4465 				// Use sender in all other "normal" folders
       
  4466 				else
       
  4467 				    {
       
  4468 				    addressToBeStored = message.GetSender();
       
  4469 				    }
       
  4470 				TDesC* emailAddressText(0);
       
  4471 				if ( addressToBeStored )
       
  4472 				    {
       
  4473 				    emailAddressText = &addressToBeStored->GetEmailAddress();
       
  4474 				    }
       
  4475 				if ( emailAddressText && emailAddressText->Length() )
       
  4476 				    {
       
  4477 				    TAddToContactsType type;
       
  4478 				    //Query to "update existing" or "Create new" --> EFALSE = user choosed "cancel"
       
  4479 				    if ( CFsDelayedLoader::InstanceL()->GetContactHandlerL()->AddtoContactsQueryL( type ) )
       
  4480 				        {
       
  4481 				        CFsDelayedLoader::InstanceL()->GetContactHandlerL()->AddToContactL(
       
  4482 				                *emailAddressText, EContactUpdateEmail, type, this );
       
  4483 				        }
       
  4484 				    }
       
  4485 				}
       
  4486     		}
       
  4487 			break;
       
  4488     	case EFsEmailUiCmdMarkingModeMove:
       
  4489             {
       
  4490 			iMarkingModeWaitingToExit = ETrue;
       
  4491 			}
       
  4492 			// Flow through			
       
  4493        	case EFsEmailUiCmdActionsMove:
       
  4494        	case EFsEmailUiCmdActionsMoveMessage:
       
  4495 			{
       
  4496 			TFSMailMsgId folderID;
       
  4497 			folderID.SetNullId(); // Selection is popped up with NULL
       
  4498 			MoveMsgsToFolderL( folderID );
       
  4499 			}
       
  4500 			break;
       
  4501        	case EFsEmailUiCmdActionsMoveToDrafts:
       
  4502 			{
       
  4503 			MoveMessagesToDraftsL();
       
  4504 			}
       
  4505 			break;
       
  4506         case EFsEmailUiCmdActionsCopyMessage:
       
  4507             {
       
  4508             }
       
  4509             break;
       
  4510         case EFsEmailUiCmdActionsCollapseExpandAllToggle:
       
  4511             {
       
  4512            	ShortcutCollapseExpandAllToggleL();
       
  4513             }
       
  4514             break;
       
  4515         case EFsEmailUiCmdMarkAsReadUnreadToggle:
       
  4516             {
       
  4517 			ShortcutReadUnreadToggleL();
       
  4518             }
       
  4519             break;
       
  4520         case EFsEmailUiCmdGoToSwitchFolder:
       
  4521             {
       
  4522             iControlBarControl->SetFocusByIdL( iFolderListButtonId );
       
  4523             iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  4524             iFocusedControl = EControlBarComponent;
       
  4525             iMailList->SetFocusedL( EFalse );
       
  4526             }
       
  4527             break;
       
  4528         case EFsEmailUiCmdGoToSwitchSorting:
       
  4529             {
       
  4530             iControlBarControl->SetFocusByIdL( iSortButtonId );
       
  4531             iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  4532             iFocusedControl = EControlBarComponent;
       
  4533            	iMailList->SetFocusedL( EFalse );
       
  4534             }
       
  4535             break;
       
  4536         case EFsEmailUiCmdGoToSwitchNewEmail:
       
  4537             {
       
  4538             iControlBarControl->SetFocusByIdL( iNewEmailButtonId );
       
  4539             iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  4540             iFocusedControl = EControlBarComponent;
       
  4541             iMailList->SetFocusedL( EFalse );
       
  4542             break;
       
  4543             }
       
  4544         case EFsEmailUiCmdCalActionsAccept:
       
  4545         case EFsEmailUiCmdCalActionsTentative:
       
  4546         case EFsEmailUiCmdCalActionsDecline:
       
  4547         case EFsEmailUiCmdCalRemoveFromCalendar:
       
  4548 			{
       
  4549 			if ( actionTargetItems.Count() == 1 )
       
  4550                 {
       
  4551                 TInt mrItemIdx = ModelIndexFromListId( actionTargetItems[0] );
       
  4552                 CFSEmailUiMailListModelItem* item =
       
  4553                     dynamic_cast<CFSEmailUiMailListModelItem*>( iModel->Item(mrItemIdx) );
       
  4554                 if ( item && item->MessagePtr().IsFlagSet( EFSMsgFlag_CalendarMsg ) )
       
  4555                     {
       
  4556                     // Respond to meeting request
       
  4557                     if (  iAppUi.MrViewerInstanceL() &&  iAppUi.MrViewerInstanceL()->CanViewMessage( item->MessagePtr() ) )
       
  4558                         {
       
  4559                         ChangeReadStatusOfHighlightedL( ETrue );
       
  4560                         iAppUi.MailViewer().HandleMrCommandL( aCommand,
       
  4561                                                               iAppUi.GetActiveMailbox()->GetId(),
       
  4562                                                               FolderId(),
       
  4563                                                               item->MessagePtr().GetMessageId() );
       
  4564                         }
       
  4565                     }
       
  4566 			    }
       
  4567 			}
       
  4568 			break;
       
  4569        	case EFsEmailUiCmdActionsEmptyDeleted:
       
  4570        		{
       
  4571        		// <cmail>
       
  4572             if ( iMailFolder && iMailFolder->GetFolderType() == EFSDeleted &&
       
  4573        			 iModel->Count() != 0 )
       
  4574        		// </cmail>
       
  4575        			{
       
  4576     			TBool okToDelete( EFalse );
       
  4577 				HBufC* msg = StringLoader::LoadLC( R_FREESTYLE_EMAIL_QUERY_NOTE_PERMANENTLY_DELETE );
       
  4578  	    		CAknQueryDialog *queryNote = new ( ELeave ) CAknQueryDialog();
       
  4579 				CleanupStack::PushL( queryNote );
       
  4580 				queryNote->SetPromptL( *msg );
       
  4581 				CleanupStack::Pop( queryNote );
       
  4582 				CleanupStack::PopAndDestroy( msg );
       
  4583 				okToDelete = queryNote->ExecuteLD( R_FSEMAIL_QUERY_DIALOG );
       
  4584 				if ( okToDelete )
       
  4585  					{
       
  4586 					// Empty deleted items folder
       
  4587 					RArray<TFSMailMsgId> msgIds;
       
  4588 					CleanupClosePushL( msgIds );
       
  4589 					for ( TInt i=0 ; i<iModel->Count();i++ )
       
  4590 						{
       
  4591 						CFSEmailUiMailListModelItem* item =
       
  4592 	    					static_cast<CFSEmailUiMailListModelItem*>(iModel->Item(i));
       
  4593 	    				if ( item && item->ModelItemType() == ETypeMailItem )
       
  4594 	    					{
       
  4595 							msgIds.Append( item->MessagePtr().GetMessageId() );
       
  4596 	    					}
       
  4597 						}
       
  4598 					TFSMailMsgId folderId = FolderId();
       
  4599 					TFSMailMsgId mailBox = iAppUi.GetActiveMailbox()->GetId();
       
  4600 					iAppUi.GetMailClient()->DeleteMessagesByUidL( mailBox, folderId, msgIds );
       
  4601 		            RemoveMsgItemsFromListIfFoundL( msgIds );
       
  4602 					CleanupStack::PopAndDestroy( &msgIds );
       
  4603  					}
       
  4604        			}
       
  4605        		}
       
  4606 			break;
       
  4607         case EFsEmailUiCmdSettings:
       
  4608             {
       
  4609             TInt tmp = 0;
       
  4610             const TPckgBuf<TInt> pkgBuf( tmp );
       
  4611             iAppUi.EnterFsEmailViewL( SettingsViewId,
       
  4612                                       TUid::Uid(KMailSettingsOpenMainList), pkgBuf );
       
  4613             }
       
  4614             break;
       
  4615 
       
  4616 
       
  4617 	    default:
       
  4618         	break;
       
  4619         } // switch ( aCommand )
       
  4620     CleanupStack::PopAndDestroy( &actionTargetItems );
       
  4621     TIMESTAMP( "Message list selected operation done" );
       
  4622     }
       
  4623 
       
  4624 // ---------------------------------------------------------------------------
       
  4625 //
       
  4626 //
       
  4627 // ---------------------------------------------------------------------------
       
  4628 //
       
  4629 TInt CFSEmailUiMailListVisualiser::MoveMsgsToFolderL( const TFSMailMsgId& aDestinationFolderId )
       
  4630     {
       
  4631     FUNC_LOG;
       
  4632     TInt ret(KErrGeneral);
       
  4633     RFsTreeItemIdList targetEntries;
       
  4634     CleanupClosePushL( targetEntries );
       
  4635     GetActionsTargetEntriesL( targetEntries );
       
  4636     TBool supportsMove = iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaMoveToFolder );
       
  4637     // Moving is not possible, if there are no items or the focus is on separator and
       
  4638     // there are no marked items. In outbox, moving is allowed only to the drafts folder;
       
  4639     // folder selection popup is not allowed.
       
  4640     // These have to be checked before launching the folder view.
       
  4641     if ( targetEntries.Count() && supportsMove )
       
  4642         {
       
  4643         TBool outbox = (iMailFolder && iMailFolder->GetFolderType() == EFSOutbox);
       
  4644 
       
  4645         if ( !(outbox && aDestinationFolderId.IsNullId()) )
       
  4646             {
       
  4647             // If destination folder is not set, it needs to be asked messages are moved after callbak
       
  4648             if ( aDestinationFolderId.IsNullId() )
       
  4649                 {
       
  4650                 // Activate folder selection view and handle moving after callback gets destination
       
  4651                 RemoveMarkingModeTitleTextL();    
       
  4652                 iMoveToFolderOngoing = ETrue;
       
  4653                 TFolderListActivationData folderListData;
       
  4654                 folderListData.iCallback = this;
       
  4655                 if(iMailFolder) // Coverity error fix , assuming that inbox is best bet for safe data. 
       
  4656                     {
       
  4657                     folderListData.iSourceFolderType = iMailFolder->GetFolderType();
       
  4658                     }
       
  4659                 else
       
  4660                     {
       
  4661                     folderListData.iSourceFolderType = EFSInbox;
       
  4662                     }
       
  4663                 const TPckgBuf<TFolderListActivationData> pkgOut( folderListData );
       
  4664                 if ( targetEntries.Count() == 1 )
       
  4665                     {
       
  4666                     iAppUi.EnterFsEmailViewL( FolderListId, KFolderListMoveMessage, pkgOut );
       
  4667                     }
       
  4668                 else
       
  4669                     {
       
  4670                     iAppUi.EnterFsEmailViewL( FolderListId, KFolderListMoveMessages, pkgOut );
       
  4671                     }
       
  4672                 ret = KErrNotReady;
       
  4673                 }
       
  4674             // Destination folder is set, move message(s) immediately
       
  4675             else
       
  4676                 {
       
  4677                 iMoveToFolderOngoing = EFalse;
       
  4678                 // Get message IDs from target list IDs
       
  4679                 RArray<TFSMailMsgId> msgIds;
       
  4680                 CleanupClosePushL( msgIds );
       
  4681                 for ( TInt i = 0 ; i < targetEntries.Count() ; i++)
       
  4682                     {
       
  4683                     msgIds.Append( MsgIdFromListId( targetEntries[i] ) );
       
  4684                     }
       
  4685 
       
  4686                 if ( iMailFolder && msgIds.Count() ) // Something to move
       
  4687                     {
       
  4688                     // check that source and destination are different
       
  4689                     if( iMailFolder->GetFolderId() != aDestinationFolderId )
       
  4690                         {
       
  4691                         // Trap is needed because protocol might return KErrNotSupported
       
  4692                         // If move away from current folder is not supprted
       
  4693                         TRAPD( errMove, iAppUi.GetActiveMailbox()->MoveMessagesL( msgIds, iMailFolder->GetFolderId(), aDestinationFolderId ) );
       
  4694                         if ( errMove != KErrNotSupported )
       
  4695                             {
       
  4696                             if ( errMove == KErrNone )
       
  4697                                 {
       
  4698                                 RemoveMsgItemsFromListIfFoundL( msgIds );
       
  4699                                 if ( !iMsgNoteTimer )
       
  4700                                     {
       
  4701                                     iMsgNoteTimer = CMsgMovedNoteTimer::NewL( &iAppUi, this );
       
  4702                                     }
       
  4703                                 iMsgNoteTimer->Cancel();
       
  4704                                 iMsgNoteTimer->Start( msgIds.Count(), aDestinationFolderId );
       
  4705                                 ret = KErrNone;
       
  4706                                 }
       
  4707                             else
       
  4708                                 {
       
  4709                                 User::Leave(errMove);
       
  4710                                 }
       
  4711                             }
       
  4712                         }
       
  4713                     }
       
  4714                 CleanupStack::PopAndDestroy( &msgIds );
       
  4715                 }
       
  4716             }
       
  4717         }
       
  4718     CleanupStack::PopAndDestroy( &targetEntries );
       
  4719     return ret;
       
  4720     }
       
  4721 
       
  4722 // ---------------------------------------------------------------------------
       
  4723 //
       
  4724 //
       
  4725 // ---------------------------------------------------------------------------
       
  4726 //
       
  4727 void CFSEmailUiMailListVisualiser::MoveMessagesToDraftsL()
       
  4728 	{
       
  4729     FUNC_LOG;
       
  4730 	if ( iMailFolder && iMailFolder->GetFolderType() == EFSOutbox ) // Move to drafts should only be available from outbox, safety
       
  4731 		{
       
  4732 		MoveMsgsToFolderL( iAppUi.GetActiveMailbox()->GetStandardFolderId( EFSDraftsFolder ) );
       
  4733 		}
       
  4734 	}
       
  4735 
       
  4736 // ---------------------------------------------------------------------------
       
  4737 //
       
  4738 //
       
  4739 // ---------------------------------------------------------------------------
       
  4740 //
       
  4741 void CFSEmailUiMailListVisualiser::CollapseAllNodesL()
       
  4742 	{
       
  4743     FUNC_LOG;
       
  4744     // Safety check, ignore command if the list is empty
       
  4745     if ( iMailList->Count() > 0 )
       
  4746         {
       
  4747     	iMailTreeListVisualizer->CollapseAllL();
       
  4748         }
       
  4749     }
       
  4750 
       
  4751 // ---------------------------------------------------------------------------
       
  4752 //
       
  4753 // ---------------------------------------------------------------------------
       
  4754 //
       
  4755 void CFSEmailUiMailListVisualiser::ExpandAllNodesL()
       
  4756 	{
       
  4757     FUNC_LOG;
       
  4758     // Safety check, ignore command if the list is empty
       
  4759 	if ( iMailList->Count() > 0 )
       
  4760 	    {
       
  4761     	TFsTreeItemId prevId = iMailList->FocusedItem();
       
  4762     	iMailTreeListVisualizer->ExpandAllL();
       
  4763     	iMailTreeListVisualizer->SetFocusedItemL( prevId );
       
  4764         }
       
  4765 	}
       
  4766 
       
  4767 // ---------------------------------------------------------------------------
       
  4768 //
       
  4769 // ---------------------------------------------------------------------------
       
  4770 //
       
  4771 void CFSEmailUiMailListVisualiser::ExpandOrCollapseL()
       
  4772     {
       
  4773     FUNC_LOG;
       
  4774     CFSEmailUiMailListModelItem* item =
       
  4775         dynamic_cast<CFSEmailUiMailListModelItem*>( iModel->Item( HighlightedIndex() ) );
       
  4776     if ( item && item->ModelItemType() == ETypeSeparator )
       
  4777         {
       
  4778         if ( iMailList->IsExpanded( iMailList->FocusedItem() ) )
       
  4779             {
       
  4780             //ChangeMskCommandL( R_FSE_QTN_MSK_COLLAPSE );
       
  4781             iMailList->CollapseNodeL( iMailList->FocusedItem() );
       
  4782             }
       
  4783         else
       
  4784             {
       
  4785             //ChangeMskCommandL( R_FSE_QTN_MSK_EXPAND );
       
  4786             iMailList->ExpandNodeL( iMailList->FocusedItem() );
       
  4787             }
       
  4788         }
       
  4789     }
       
  4790 
       
  4791 // ---------------------------------------------------------------------------
       
  4792 //
       
  4793 //
       
  4794 // ---------------------------------------------------------------------------
       
  4795 //
       
  4796 void CFSEmailUiMailListVisualiser::SetMessageFollowupFlagL()
       
  4797 	{
       
  4798     FUNC_LOG;
       
  4799 	if ( TFsEmailUiUtility::IsFollowUpSupported( *iAppUi.GetActiveMailbox() ) )
       
  4800 		{
       
  4801 	    RFsTreeItemIdList targetItems;
       
  4802 	    CleanupClosePushL( targetItems );
       
  4803 	    GetActionsTargetEntriesL( targetItems );
       
  4804 
       
  4805 		// If there are marked or focused item(s)
       
  4806 		if ( targetItems.Count() )
       
  4807 			{
       
  4808 			// Convert list IDs to message IDs because it's possible that list refresh
       
  4809 			// causes list IDs to change while the flag dialog is open
       
  4810 			RArray< TFSMailMsgId > targetMsgIds;
       
  4811 			CleanupClosePushL( targetMsgIds );
       
  4812 			for ( TInt i = 0 ; i < targetItems.Count() ; ++i )
       
  4813 			    {
       
  4814 			    TFSMailMsgId msgId = MsgIdFromIndex( ModelIndexFromListId( targetItems[i] ) );
       
  4815 			    targetMsgIds.AppendL( msgId );
       
  4816 			    }
       
  4817 
       
  4818 			TFollowUpNewState newFollowUpState = EFollowUpNoChanges;
       
  4819 			if ( TFsEmailUiUtility::RunFollowUpListDialogL( newFollowUpState ) )
       
  4820 				{
       
  4821 				// Update the target messages
       
  4822 				for ( TInt i = 0 ; i < targetMsgIds.Count() ; ++i )
       
  4823 				    {
       
  4824 	                // Confirm that message is still in the list after selection has closed
       
  4825 				    TInt itemIndex = ItemIndexFromMessageId( targetMsgIds[i] );
       
  4826 				    CFSEmailUiMailListModelItem* modelItem =
       
  4827 				        static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( itemIndex ) );
       
  4828 	                CFSMailMessage* confirmedPtr = NULL; // owned by the model
       
  4829 	                if ( modelItem )
       
  4830 	                    {
       
  4831 	                    confirmedPtr = &modelItem->MessagePtr();
       
  4832 	                    }
       
  4833 	                if ( confirmedPtr )
       
  4834 	                    {
       
  4835 	                    // Store flags to confirmed pointer for saving
       
  4836 	                    TInt currentFlags = confirmedPtr->GetFlags();
       
  4837 	                    switch ( newFollowUpState )
       
  4838 	                        {
       
  4839 	                        case EFollowUp:
       
  4840 	                            {
       
  4841 	                            confirmedPtr->SetFlag( EFSMsgFlag_FollowUp );
       
  4842 	                            confirmedPtr->ResetFlag( EFSMsgFlag_FollowUpComplete );
       
  4843 	                            }
       
  4844 	                            break;
       
  4845 	                        case EFollowUpComplete:
       
  4846 	                            {
       
  4847 	                            confirmedPtr->SetFlag( EFSMsgFlag_FollowUpComplete );
       
  4848 	                            confirmedPtr->ResetFlag( EFSMsgFlag_FollowUp );
       
  4849 	                            }
       
  4850 	                            break;
       
  4851 	                        case EFollowUpClear:
       
  4852 	                            {
       
  4853 	                            confirmedPtr->ResetFlag( EFSMsgFlag_FollowUp | EFSMsgFlag_FollowUpComplete );
       
  4854 	                            }
       
  4855 	                            break;
       
  4856 	                        }
       
  4857 
       
  4858 	                    TInt newFlags = confirmedPtr->GetFlags();
       
  4859 	                    if ( newFlags != currentFlags )
       
  4860 	                        {
       
  4861 	                        // Save confirmed message
       
  4862 	                        confirmedPtr->SaveMessageL();
       
  4863 
       
  4864 	                        // Update flag icon
       
  4865                             UpdateMsgIconAndBoldingL( itemIndex );
       
  4866 
       
  4867                             // In case we are in flag sort mode, resetting the flag may cause the list order to be out of date.
       
  4868                             if ( iCurrentSortCriteria.iField == EFSMailSortByFlagStatus )
       
  4869 	                            {
       
  4870 	                            iListOrderMayBeOutOfDate = ETrue;
       
  4871 	                            }
       
  4872 	                        }
       
  4873 	                    }
       
  4874 				    }
       
  4875                 if ( iMarkingMode ) 
       
  4876                     {
       
  4877                     ExitMarkingModeL();
       
  4878                     }
       
  4879 				}
       
  4880 			CleanupStack::PopAndDestroy( &targetMsgIds );
       
  4881 			}
       
  4882 		CleanupStack::PopAndDestroy( &targetItems );
       
  4883 		}
       
  4884 	}
       
  4885 
       
  4886 // ---------------------------------------------------------------------------
       
  4887 //
       
  4888 //
       
  4889 // ---------------------------------------------------------------------------
       
  4890 //
       
  4891 void CFSEmailUiMailListVisualiser::SetViewSoftkeysL( TInt aResourceId )
       
  4892 	{
       
  4893     FUNC_LOG;
       
  4894     Cba()->SetCommandSetL( aResourceId );
       
  4895     Cba()->DrawDeferred();
       
  4896 	}
       
  4897 
       
  4898 // ---------------------------------------------------------------------------
       
  4899 // Method to set Middle SoftKey
       
  4900 // ---------------------------------------------------------------------------
       
  4901 //
       
  4902 void CFSEmailUiMailListVisualiser::SetMskL()
       
  4903     {
       
  4904     FUNC_LOG;
       
  4905     // If there is no keyboard present, than Msk buttom must not be shown
       
  4906     if ( iAppUi.ShortcutBinding().KeyBoardType() == 
       
  4907                                     CFSEmailUiShortcutBinding::ENoKeyboard )
       
  4908         {
       
  4909         return;
       
  4910         }
       
  4911     // Get the mail list count
       
  4912     TInt listCount(0);
       
  4913     if ( iMailList )
       
  4914         {
       
  4915         listCount = iMailList->Count();
       
  4916         }
       
  4917 
       
  4918     if ( iFocusedControl == EControlBarComponent )
       
  4919         {
       
  4920         ChangeMskCommandL( R_FSE_QTN_MSK_CHANGE ); // change - switch focus on
       
  4921         }
       
  4922     else  if ( iFocusedControl == EMailListComponent )
       
  4923         {
       
  4924         if ( listCount ) // Safety check
       
  4925             {
       
  4926             CFSEmailUiMailListModelItem* item =
       
  4927                 dynamic_cast<CFSEmailUiMailListModelItem*>( iModel->Item(HighlightedIndex()) );
       
  4928             // SHIFT DEPRESSED. SELECTION KEY DOES MARK/UNMARK
       
  4929             if ( iShiftDepressed )
       
  4930                 {
       
  4931                 // Nodes may not be marked
       
  4932                 if ( iMailList->IsNode( iMailList->FocusedItem() ) )
       
  4933                     {
       
  4934                     ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY ); // nothing
       
  4935                     }
       
  4936                 else
       
  4937                     {
       
  4938                     if ( iMailList->IsMarked( iMailList->FocusedItem() ) )
       
  4939                         {
       
  4940                         ChangeMskCommandL( R_FSE_QTN_MSK_UNMARK ); // unmark item
       
  4941                         }
       
  4942                     else
       
  4943                         {
       
  4944                         ChangeMskCommandL( R_FSE_QTN_MSK_MARK ); // mark item
       
  4945                         }
       
  4946                     }
       
  4947                 }
       
  4948             else
       
  4949                 {
       
  4950                 // MAIL ITEM; OPEN MAIL
       
  4951                 if ( item && item->ModelItemType() == ETypeMailItem )
       
  4952                     {
       
  4953                     CFSMailMessage* messagePtr = &item->MessagePtr();
       
  4954                     if ( messagePtr )
       
  4955                         {
       
  4956                         if ( iMailFolder && iMailFolder->GetFolderType() == EFSOutbox )
       
  4957                             {
       
  4958                             ChangeMskCommandL( R_FSE_QTN_MSK_OPEN_BLOCKED ); // blocked email opening 
       
  4959                             }
       
  4960                         else
       
  4961                             {
       
  4962                             ChangeMskCommandL( R_FSE_QTN_MSK_OPEN ); // open email
       
  4963                             }
       
  4964                         }
       
  4965                     }
       
  4966 
       
  4967                 // SEPARAOR ITEM; COLLAPSE / EXPAND NODE
       
  4968                 else if ( item && item->ModelItemType() == ETypeSeparator )
       
  4969                     {
       
  4970                     if( iMailList->IsNode( iMailList->FocusedItem() ) )
       
  4971                         {
       
  4972                         if ( iMailList->IsExpanded( iMailList->FocusedItem() ) )
       
  4973                             {
       
  4974                             ChangeMskCommandL( R_FSE_QTN_MSK_COLLAPSE ); // collapse folder
       
  4975                             }
       
  4976                         else
       
  4977                             {
       
  4978                             ChangeMskCommandL( R_FSE_QTN_MSK_EXPAND ); // expand folder
       
  4979                             }
       
  4980                         }
       
  4981                     }
       
  4982                 }
       
  4983             }
       
  4984         }
       
  4985     }
       
  4986 
       
  4987 // ---------------------------------------------------------------------------
       
  4988 //
       
  4989 //
       
  4990 // ---------------------------------------------------------------------------
       
  4991 //
       
  4992 TBool CFSEmailUiMailListVisualiser::OfferEventL( const TAlfEvent& aEvent )
       
  4993     {
       
  4994     FUNC_LOG;
       
  4995     TBool result( EFalse );
       
  4996 
       
  4997     if ( !aEvent.IsKeyEvent() )
       
  4998         {
       
  4999         // Only handle key events
       
  5000         if ( aEvent.IsPointerEvent() )
       
  5001             {
       
  5002             if( aEvent.PointerDown() )
       
  5003                 {
       
  5004                 // If pointer down event was made on control bar area
       
  5005                 // focus needs to be changed to control bar control, if it
       
  5006                 // didn't already have focus.
       
  5007                if( HitTest( *iControlBarControl, aEvent.PointerEvent().iPosition ) )
       
  5008                     {
       
  5009                     if( iFocusedControl != EControlBarComponent )
       
  5010                         {
       
  5011                         SetControlBarFocusedL();
       
  5012                         }
       
  5013                     }
       
  5014                 else
       
  5015                     {
       
  5016                     // If pointer down event was not made on control bar area
       
  5017                     // then focus need to be set to mail list component, if it
       
  5018                     // didn't already have focus. If mail list is empty, then
       
  5019                     // focus is hidden and control bar stays as a focused item.
       
  5020                     if( ( iFocusedControl != EMailListComponent ) &&
       
  5021                         ( iMailList->Count() > 0 ) )
       
  5022                         {
       
  5023                         SetTreeListFocusedL();
       
  5024                         }
       
  5025                     else
       
  5026                         {
       
  5027                         iAppUi.SetFocusVisibility( EFalse );
       
  5028                         }
       
  5029                     }
       
  5030                 }
       
  5031 
       
  5032             // Offer event to focused control.
       
  5033             if( iFocusedControl == EMailListComponent )
       
  5034                 {
       
  5035                 result = iMailList->TreeControl()->OfferEventL( aEvent );
       
  5036                 }
       
  5037             else // iFocusedControl == EControlBarComponent
       
  5038                 {
       
  5039                 result = static_cast<CAlfControl*>(
       
  5040                     iControlBarControl )->OfferEventL( aEvent );
       
  5041                 }
       
  5042             }
       
  5043         return result;
       
  5044         }
       
  5045 
       
  5046     TInt scanCode = aEvent.KeyEvent().iScanCode;
       
  5047     // Swap right and left controls in mirrored layout
       
  5048     if ( AknLayoutUtils::LayoutMirrored() )
       
  5049         {
       
  5050         if ( scanCode == EStdKeyRightArrow )
       
  5051             {
       
  5052             scanCode = EStdKeyLeftArrow;
       
  5053             }
       
  5054         else if ( scanCode == EStdKeyLeftArrow )
       
  5055             {
       
  5056             scanCode = EStdKeyRightArrow;
       
  5057             }
       
  5058         }
       
  5059 
       
  5060     // Toggle mark items state when shift key is pressed or released
       
  5061     if ( iFocusedControl == EMailListComponent &&
       
  5062     	 ( scanCode == EStdKeyLeftShift ||
       
  5063     	   scanCode == EStdKeyRightShift ||
       
  5064     	   scanCode == EStdKeyHash ) )
       
  5065         {
       
  5066         if ( aEvent.Code() == EEventKeyDown )
       
  5067             {
       
  5068             iShiftDepressed = ETrue;
       
  5069             iOtherKeyPressedWhileShiftDepressed = EFalse;
       
  5070             if ( iModel->Count() && iMailList->IsMarked( iMailList->FocusedItem() ) )
       
  5071                 {
       
  5072                 iListMarkItemsState = EFalse; // Unmark state
       
  5073                 }
       
  5074             else
       
  5075                 {
       
  5076                 iListMarkItemsState = ETrue; // Mark items state
       
  5077                 }
       
  5078             }
       
  5079         else if ( aEvent.Code() == EEventKeyUp )
       
  5080             {
       
  5081             iShiftDepressed = EFalse;
       
  5082             }
       
  5083         }
       
  5084 
       
  5085     // If any other key event is gained while hash is depressed, the hash key is used only
       
  5086     // as shift and not as individual key.
       
  5087     if ( iShiftDepressed && scanCode &&
       
  5088             scanCode != EStdKeyHash && scanCode != EStdKeyLeftShift && scanCode != EStdKeyRightShift )
       
  5089         {
       
  5090         iOtherKeyPressedWhileShiftDepressed = ETrue;
       
  5091         }
       
  5092 
       
  5093     // MSK label can now be updated when shift key has been handled
       
  5094     SetMskL();
       
  5095     // On KeyUp of EStdKeyYes usually Call application is called - prevent it
       
  5096     if ( iConsumeStdKeyYes_KeyUp && (aEvent.Code() == EEventKeyUp ))
       
  5097 		{
       
  5098 		iConsumeStdKeyYes_KeyUp = EFalse; // in case call button was consumed elsewhere first key up enables calling Call application
       
  5099 		if ( EStdKeyYes == scanCode)
       
  5100 			{
       
  5101 			  result = ETrue; // consume not to switch to Call application when call to contact was processed
       
  5102 			  return result;
       
  5103 			}
       
  5104 		}
       
  5105 
       
  5106     if ( aEvent.IsKeyEvent() && aEvent.Code() == EEventKey )
       
  5107         {
       
  5108         TBool shiftState = ( aEvent.KeyEvent().iModifiers & EModifierShift );
       
  5109 
       
  5110         // Do the (un)marking if in shift state and suitable key is received
       
  5111         if ( shiftState )
       
  5112             {
       
  5113             switch ( aEvent.KeyEvent().iScanCode )
       
  5114                 {
       
  5115                 case EStdKeyDownArrow:
       
  5116                 case EStdKeyUpArrow:
       
  5117                     {
       
  5118                     DoScrollMarkUnmarkL();
       
  5119                     result = EFalse; // event is not consumed yet, because it must also move the cursor
       
  5120                     }
       
  5121                     break;
       
  5122                 case EStdKeyEnter:
       
  5123                 case EStdKeyDevice3:
       
  5124                     {
       
  5125                     if ( !aEvent.KeyEvent().iRepeats ) // no repeated (un)marking by holding selection key depressed
       
  5126                         {
       
  5127                         // The selection key always toggles the marking state of the current item.
       
  5128                         // It also toggles the scroll marking/unmarking state.
       
  5129                         if ( iModel->Count() )
       
  5130                             {
       
  5131                             CFSEmailUiMailListModelItem* item =
       
  5132                                 static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( HighlightedIndex() ) );
       
  5133 
       
  5134                             if ( item && item->ModelItemType() == ETypeMailItem )  // Separators are not markable
       
  5135                                 {
       
  5136                                 if ( iMailList->IsMarked( iMailList->FocusedItem() ) )
       
  5137                                     {
       
  5138                                     iMailList->MarkItemL( iMailList->FocusedItem(), EFalse );
       
  5139                                     iListMarkItemsState = EFalse;
       
  5140                                     }
       
  5141                                 else
       
  5142                                     {
       
  5143                                     iMailList->MarkItemL( iMailList->FocusedItem(), ETrue );
       
  5144                                     iListMarkItemsState = ETrue;
       
  5145                                     }
       
  5146                                 }
       
  5147                             }
       
  5148                         }
       
  5149                     result = ETrue; // shift + selection is always consumed
       
  5150                     }
       
  5151                     break;
       
  5152                 default:
       
  5153                     break;
       
  5154                 }
       
  5155 
       
  5156             }
       
  5157 
       
  5158         // If event not handled by now
       
  5159         if ( !result )
       
  5160             {
       
  5161             // Handle possible focus visibility change
       
  5162             if ( ( scanCode == EStdKeyRightArrow ) ||
       
  5163                  ( scanCode == EStdKeyLeftArrow ) ||
       
  5164                  ( scanCode == EStdKeyUpArrow ) ||
       
  5165                  ( scanCode == EStdKeyDownArrow ) ||
       
  5166                  ( scanCode == EStdKeyEnter ) ||
       
  5167                  ( scanCode == EStdKeyDeviceA ) ||
       
  5168                  ( scanCode ==EStdKeyDevice3 ) )
       
  5169                 {
       
  5170                 // If the focus was not active already, ignore the key press
       
  5171                 if( !iAppUi.SetFocusVisibility( ETrue ) )
       
  5172                     {
       
  5173                     return ETrue;
       
  5174                     }
       
  5175                 }
       
  5176 
       
  5177             switch ( scanCode )
       
  5178                 {
       
  5179                 case EStdKeyDevice3: // CENTER CLICK
       
  5180                 case EStdKeyEnter:  // ENTER EITHER SELECTS ITEM IN TOOLBAR OR OPENS MAIL
       
  5181                 case EStdKeyNkpEnter:
       
  5182                 case EAknSoftkeySelect:
       
  5183                     {
       
  5184                     SetMskL();
       
  5185                     if ( iFocusedControl == EMailListComponent )
       
  5186                         {
       
  5187                         TInt modelCount( modelCount = iModel->Count() );
       
  5188                         if ( modelCount ) // Safety check
       
  5189                             {
       
  5190                             if (iMarkingMode)
       
  5191                                 {
       
  5192                                 //Do not open mail or expand/collapse separator in marking mode
       
  5193                                 DoHandleListItemOpenL();
       
  5194                                 }
       
  5195                             else
       
  5196                                 {
       
  5197                                 CFSEmailUiMailListModelItem* item =
       
  5198                                         dynamic_cast<CFSEmailUiMailListModelItem*>( iModel->Item( HighlightedIndex() ) );
       
  5199                                 // MAIL ITEM; OPEN MAIL
       
  5200                                 if ( item && item->ModelItemType() == ETypeMailItem )
       
  5201                                     {
       
  5202                                     CFSMailMessage* messagePtr = &item->MessagePtr();
       
  5203                                     if ( messagePtr )
       
  5204                                         {
       
  5205                                         TIMESTAMP( "Open email selected from message list" );
       
  5206                                         OpenHighlightedMailL();
       
  5207                                         return EKeyWasConsumed;
       
  5208                                         }
       
  5209                                     }
       
  5210                                 // SEPARAOR ITEM; COLLAPSE / EXPAND NODE
       
  5211                                 else if ( item && item->ModelItemType() == ETypeSeparator )
       
  5212                                     {
       
  5213                                     ExpandOrCollapseL();
       
  5214                                     return EKeyWasConsumed;
       
  5215                                     }
       
  5216                                 }
       
  5217                             }
       
  5218                         }
       
  5219                     else
       
  5220                         {
       
  5221                         TInt focusedButtonId( iControlBarControl->GetFocusedButton()->Id() );
       
  5222                         if ( focusedButtonId == iNewEmailButtonId )
       
  5223                             {
       
  5224                             HandleCommandL(EFsEmailUiCmdCompose);
       
  5225                             }
       
  5226                         else if ( focusedButtonId == iFolderListButtonId )
       
  5227                             {
       
  5228                             // Set touchmanager not active for preventing getting events.
       
  5229                             DisableMailList( ETrue );
       
  5230                             iAppUi.ShowFolderListInPopupL( FolderId(), this, iFolderListButton );
       
  5231                             }
       
  5232                         else if ( focusedButtonId == iSortButtonId )
       
  5233                             {
       
  5234                             TFSFolderType folderType;
       
  5235                             if( iMailFolder )
       
  5236                                 {
       
  5237                                 folderType = iMailFolder->GetFolderType();
       
  5238                                 }
       
  5239                             else
       
  5240                                 {
       
  5241                                 folderType = EFSInbox;
       
  5242                                 }
       
  5243                             // Show sort if model has data.
       
  5244                             if ( iModel->Count() )
       
  5245                                 {
       
  5246                                 // Set touchmanager not active for preventing getting events.
       
  5247                                 DisableMailList(ETrue);
       
  5248                                 iAppUi.ShowSortListInPopupL( iCurrentSortCriteria, folderType, this, iSortButton );
       
  5249                                 }
       
  5250                             else
       
  5251                                 {
       
  5252                                 // hide selector focus if popup is not opened
       
  5253                                 // and selection was not made via HW-keys
       
  5254                                 iControlBarControl->MakeSelectorVisible(
       
  5255                                     IsFocusShown() );
       
  5256                                 }
       
  5257                             }
       
  5258                         return ETrue; // iControlBar->OfferEventL( aEvent );
       
  5259                         }
       
  5260                     }
       
  5261                     break;
       
  5262                 case EStdKeyLeftArrow:
       
  5263                 case EStdKeyRightArrow:
       
  5264                 case EStdKeyDownArrow:
       
  5265                 case EStdKeyUpArrow:
       
  5266                     {
       
  5267                     if( Layout_Meta_Data::IsLandscapeOrientation() )
       
  5268                         {
       
  5269                         result = HandleArrowEventInLandscapeL( scanCode,
       
  5270                                     aEvent, shiftState );
       
  5271                         }
       
  5272                     else
       
  5273                         {
       
  5274                         result = HandleArrowEventInPortraitL( scanCode,
       
  5275                                     aEvent, shiftState );
       
  5276                         }
       
  5277                     break;
       
  5278                     }
       
  5279                 case EStdKeyYes:
       
  5280                     {
       
  5281                     if ( !iAppUi.ViewSwitchingOngoing() )
       
  5282                         {
       
  5283                         if ( iMailFolder && iMailFolder->GetFolderType() != EFSOutbox &&
       
  5284                                 iMailFolder->GetFolderType() != EFSDraftsFolder )
       
  5285                             {
       
  5286                             TInt modelCount = iModel->Count();
       
  5287                             if ( modelCount ) // Safety check
       
  5288                                 {
       
  5289                                 CFSEmailUiMailListModelItem* item =
       
  5290                                     dynamic_cast<CFSEmailUiMailListModelItem*>( iModel->Item( HighlightedIndex() ) );
       
  5291                                 if ( item && item->ModelItemType() == ETypeMailItem )
       
  5292                                     {
       
  5293                                     CFSMailAddress* fromAddress = item->MessagePtr().GetSender();
       
  5294                                     TDesC* mailAddress(0);
       
  5295                                     if ( fromAddress )
       
  5296                                         {
       
  5297                                         mailAddress = &fromAddress->GetEmailAddress();
       
  5298                                         }
       
  5299                                     if ( mailAddress && mailAddress->Length() )
       
  5300                                         {
       
  5301                                         if ( iMailFolder->GetFolderType() == EFSSentFolder )
       
  5302                                             {
       
  5303                                             CFsDelayedLoader::InstanceL()->GetContactHandlerL()->FindAndCallToContactByEmailL(
       
  5304                                                     *mailAddress, iAppUi.GetActiveMailbox(), this, EFalse );
       
  5305                                             }
       
  5306                                         else
       
  5307                                             {
       
  5308                                             CFsDelayedLoader::InstanceL()->GetContactHandlerL()->FindAndCallToContactByEmailL(
       
  5309                                                     *mailAddress, iAppUi.GetActiveMailbox(), this, ETrue );
       
  5310                                             }
       
  5311 // consume following KyUp event to prevent execution of Call application when call to contact processing
       
  5312                                         iConsumeStdKeyYes_KeyUp = result = ETrue;
       
  5313                                         }
       
  5314                                     }
       
  5315                                 }
       
  5316                             }
       
  5317                         }
       
  5318                     }
       
  5319                     break;
       
  5320                 case EStdKeyHash:
       
  5321                     {
       
  5322                     // Consume hash key events before they go to our shortcut framework. We do not want
       
  5323                     // to react to those until the in the key up event. There hash key works as mark/unmark shortcut only
       
  5324                     // if it hasn't been used as shift modifier.
       
  5325                     result = ETrue;
       
  5326                     }
       
  5327                     break;
       
  5328                // Backspace (C key) must be handled on Key-Down instead of Key-Up
       
  5329                // ( this was the reason that deleted two emails from opened mail in viewer )
       
  5330                case EStdKeyBackspace:
       
  5331                    {
       
  5332                    TInt shortcutCommand = iAppUi.ShortcutBinding().CommandForShortcutKey( aEvent.KeyEvent(),
       
  5333                                   CFSEmailUiShortcutBinding::EContextMailList );
       
  5334 
       
  5335                    if ( shortcutCommand != KErrNotFound )
       
  5336                        {
       
  5337                        HandleCommandL( shortcutCommand );
       
  5338                        result = ETrue;
       
  5339                        }
       
  5340                    else result = EFalse;
       
  5341                    }
       
  5342                    break;
       
  5343                 default:
       
  5344                     {
       
  5345                     if ( iFocusedControl == EMailListComponent )
       
  5346                         {
       
  5347                         result = iMailList->TreeControl()->OfferEventL(aEvent);
       
  5348                         }
       
  5349                     else
       
  5350                         {
       
  5351                         result = EFalse;
       
  5352                         }
       
  5353                     }
       
  5354                     break;
       
  5355                 }
       
  5356             }
       
  5357         }
       
  5358     else if ( aEvent.IsKeyEvent() && aEvent.Code() == EEventKeyUp )
       
  5359         {
       
  5360         // Check keyboard shortcuts on key up events. These can't be checked on key event
       
  5361         // because half-QWERTY keyboad has shortcuts also on shift and chr keys which do
       
  5362         // no send any key events, only key down and key up.
       
  5363         TInt shortcutCommand =
       
  5364             iAppUi.ShortcutBinding().CommandForShortcutKey( aEvent.KeyEvent(),
       
  5365                 CFSEmailUiShortcutBinding::EContextMailList );
       
  5366 
       
  5367         // Hash/shift key of ITU-T and half-QWERTY keyboards is an exception case to other
       
  5368         // shortcuts: it is handled only if it hasn't been used as shift modifier
       
  5369         if ( (scanCode == EStdKeyHash || scanCode == EStdKeyLeftShift || scanCode == EStdKeyRightShift) &&
       
  5370              iOtherKeyPressedWhileShiftDepressed )
       
  5371             {
       
  5372             shortcutCommand = KErrNotFound;
       
  5373             }
       
  5374 
       
  5375         // block Backspace (C key) handle on Key-Up
       
  5376         if ( scanCode == EStdKeyBackspace )
       
  5377             {
       
  5378             shortcutCommand = KErrNotFound; // handled on Key-Down, see above
       
  5379             }
       
  5380 
       
  5381         if ( shortcutCommand != KErrNotFound )
       
  5382             {
       
  5383             HandleCommandL( shortcutCommand );
       
  5384             result = ETrue;
       
  5385             }
       
  5386         else
       
  5387             {
       
  5388             result = EFalse;
       
  5389             }
       
  5390         }
       
  5391 
       
  5392     return result;
       
  5393     }
       
  5394 
       
  5395 // ---------------------------------------------------------------------------
       
  5396 // CFSEmailUiMailListVisualiser::DoHandleListItemOpenL
       
  5397 // ---------------------------------------------------------------------------
       
  5398 //
       
  5399 void CFSEmailUiMailListVisualiser::DoHandleListItemOpenL()
       
  5400     {
       
  5401     FUNC_LOG;
       
  5402     if ( 0 < iModel->Count() ) // Safety check
       
  5403         {
       
  5404         CFSEmailUiMailListModelItem* item =
       
  5405             dynamic_cast<CFSEmailUiMailListModelItem*>( iModel->Item( HighlightedIndex() ) );
       
  5406         if ( iMarkingMode )
       
  5407 			{
       
  5408             // In marking mode. Mark/unmark it instead of opening it.
       
  5409 			if ( item && item->ModelItemType() == ETypeMailItem )
       
  5410 				{
       
  5411 				if (iMailList->IsMarked( iMailList->FocusedItem() ))
       
  5412                     {
       
  5413 				    iMailList->MarkItemL( iMailList->FocusedItem(), EFalse );
       
  5414                     }
       
  5415 				else
       
  5416 				    {
       
  5417                     iMailList->MarkItemL( iMailList->FocusedItem(), ETrue );
       
  5418 				    }
       
  5419 				}
       
  5420 			else if ( item && item->ModelItemType() == ETypeSeparator )
       
  5421 			    {
       
  5422                 TInt index = HighlightedIndex();
       
  5423                 if ( AreAllItemsMarkedUnderSeparatorL( index ) )
       
  5424                     {
       
  5425                     MarkItemsUnderSeparatorL( EFalse, index );
       
  5426                     }
       
  5427                 else
       
  5428                     {
       
  5429                     MarkItemsUnderSeparatorL( ETrue, index );
       
  5430                     }
       
  5431 			    }
       
  5432 			}
       
  5433         else if ( iAppUi.CurrentActiveView() == this )
       
  5434             {
       
  5435 
       
  5436 			// MAIL ITEM; OPEN MAIL
       
  5437 			if ( item && item->ModelItemType() == ETypeMailItem )
       
  5438 				{
       
  5439 				CFSMailMessage* messagePtr = &item->MessagePtr();
       
  5440 				if ( messagePtr )
       
  5441 					{
       
  5442 					TIMESTAMP( "Open email selected from message list" );
       
  5443 					OpenHighlightedMailL();
       
  5444 					}
       
  5445 
       
  5446 				// Give feedback to user (vibration)
       
  5447 				iTouchFeedBack->InstantFeedback(ETouchFeedbackBasic);
       
  5448 				}
       
  5449 			// SEPARATOR ITEM; COLLAPSE / EXPAND NODE
       
  5450 			else if ( item && item->ModelItemType() == ETypeSeparator )
       
  5451 				{
       
  5452 					ExpandOrCollapseL();
       
  5453 					SetMskL();
       
  5454 				}
       
  5455 			}
       
  5456         }
       
  5457     }
       
  5458 
       
  5459 // ---------------------------------------------------------------------------
       
  5460 // CFSEmailUiMailListVisualiser::DoHandleControlBarOpenL
       
  5461 // ---------------------------------------------------------------------------
       
  5462 //
       
  5463 void CFSEmailUiMailListVisualiser::DoHandleControlBarOpenL( TInt aControlBarButtonId )
       
  5464     {
       
  5465     FUNC_LOG;
       
  5466 
       
  5467     if ( aControlBarButtonId == iNewEmailButtonId )
       
  5468         {
       
  5469         HandleCommandL(EFsEmailUiCmdCompose);
       
  5470         }
       
  5471     else if ( aControlBarButtonId == iFolderListButtonId )
       
  5472         {
       
  5473         //FOLDERLIST
       
  5474         //Set touchmanager not active for preventing getting events.
       
  5475         DisableMailList(ETrue);
       
  5476         iAppUi.ShowFolderListInPopupL( FolderId(), this, iFolderListButton );
       
  5477         }
       
  5478     else if ( aControlBarButtonId == iSortButtonId )
       
  5479         {
       
  5480         //SORTLIST
       
  5481         TFSFolderType folderType;
       
  5482         if ( iMailFolder )
       
  5483             {
       
  5484             folderType = iMailFolder->GetFolderType();
       
  5485             }
       
  5486         else
       
  5487             {
       
  5488             folderType = EFSInbox;
       
  5489             }
       
  5490         // we can't show sort list when sorting is active
       
  5491         if ( iModel->Count() && iSortState == ESortNone )
       
  5492             {
       
  5493             //Set touchmanager not active for preventing getting events.
       
  5494             DisableMailList(ETrue);
       
  5495             iAppUi.ShowSortListInPopupL( iCurrentSortCriteria, folderType, this, iSortButton );
       
  5496             }
       
  5497         else
       
  5498             {
       
  5499             // hide selector focus if popup is not opened and selection was not
       
  5500             // made via HW-keys
       
  5501             iControlBarControl->MakeSelectorVisible(  IsFocusShown() );
       
  5502             }
       
  5503         }
       
  5504     }
       
  5505 
       
  5506 // ---------------------------------------------------------------------------
       
  5507 // CFSEmailUiMailListVisualiser::DoHandleListItemLongTapL
       
  5508 // ---------------------------------------------------------------------------
       
  5509 //
       
  5510 void CFSEmailUiMailListVisualiser::DoHandleListItemLongTapL( const TPoint& aPoint )
       
  5511     {
       
  5512     FUNC_LOG;
       
  5513 
       
  5514     if ( 0 < iModel->Count() ) // Safety check
       
  5515         {
       
  5516         if ( iMarkingMode )
       
  5517 			{
       
  5518             iMailTreeListVisualizer->SetFocusVisibility( EFalse );
       
  5519             TInt currentFocusState = iMailList->IsFocused();
       
  5520             iMailList->SetFocusedL( EFalse );
       
  5521             iMailList->SetFocusedL( currentFocusState );
       
  5522 			CFSEmailUiMailListModelItem* item =
       
  5523                 dynamic_cast<CFSEmailUiMailListModelItem*>( iModel->Item( HighlightedIndex() ) );
       
  5524             // In marking mode. Mark/unmark it instead of open popup.
       
  5525 			if ( item && item->ModelItemType() == ETypeMailItem )
       
  5526 				{
       
  5527 				if (iMailList->IsMarked( iMailList->FocusedItem() ))
       
  5528                     {
       
  5529 				    iMailList->MarkItemL( iMailList->FocusedItem(), EFalse );
       
  5530                     }
       
  5531 				else
       
  5532 				    {
       
  5533                     iMailList->MarkItemL( iMailList->FocusedItem(), ETrue );
       
  5534 				    }
       
  5535 				}
       
  5536 			else if ( item && item->ModelItemType() == ETypeSeparator )
       
  5537 			    {
       
  5538                 TInt index = HighlightedIndex();
       
  5539                 if ( AreAllItemsMarkedUnderSeparatorL( index ) )
       
  5540                     {
       
  5541                     MarkItemsUnderSeparatorL( EFalse, index );
       
  5542                     }
       
  5543                 else
       
  5544                     {
       
  5545                     MarkItemsUnderSeparatorL( ETrue, index );
       
  5546                     }
       
  5547 			    }
       
  5548 			}
       
  5549 		else
       
  5550 		    {
       
  5551             LaunchStylusPopupMenuL( aPoint );
       
  5552             }
       
  5553         }
       
  5554     }
       
  5555 
       
  5556 // ---------------------------------------------------------------------------
       
  5557 // CFSEmailUiMailListVisualiser::GetFocusedControl
       
  5558 // ---------------------------------------------------------------------------
       
  5559 //
       
  5560 TInt CFSEmailUiMailListVisualiser::GetFocusedControl() const
       
  5561     {
       
  5562     FUNC_LOG;
       
  5563     return iFocusedControl;
       
  5564     }
       
  5565 
       
  5566 // ---------------------------------------------------------------------------
       
  5567 // CFSEmailUiMailListVisualiser::SetControlBarFocusedL
       
  5568 // ---------------------------------------------------------------------------
       
  5569 //
       
  5570 void CFSEmailUiMailListVisualiser::SetControlBarFocusedL()
       
  5571     {
       
  5572     FUNC_LOG;
       
  5573     iFocusedControl = EControlBarComponent;
       
  5574     iMailList->SetFocusedL( EFalse );
       
  5575     SetMskL();
       
  5576     }
       
  5577 
       
  5578 // ---------------------------------------------------------------------------
       
  5579 // CFSEmailUiMailListVisualiser::SetTreeListFocusedL
       
  5580 // ---------------------------------------------------------------------------
       
  5581 //
       
  5582 void CFSEmailUiMailListVisualiser::SetTreeListFocusedL()
       
  5583     {
       
  5584     FUNC_LOG;
       
  5585     iFocusedControl = EMailListComponent;
       
  5586     iMailList->SetFocusedL( ETrue );
       
  5587     iControlBarControl->SetFocusL( EFalse );
       
  5588     SetMskL();
       
  5589     }
       
  5590 
       
  5591 // -----------------------------------------------------------------------------
       
  5592 // CFSEmailUiMailListVisualiser::FlipStateChangedL
       
  5593 // -----------------------------------------------------------------------------
       
  5594 //
       
  5595 void CFSEmailUiMailListVisualiser::FlipStateChangedL( TBool aKeyboardFlipOpen )
       
  5596     {
       
  5597     FUNC_LOG;
       
  5598     CFsEmailUiViewBase::FlipStateChangedL( aKeyboardFlipOpen );
       
  5599     iMailTreeListVisualizer->SetFlipState( iKeyboardFlipOpen );
       
  5600     }
       
  5601 
       
  5602 // -----------------------------------------------------------------------------
       
  5603 //  CFSEmailUiMailListVisualiser::HandleTimerFocusStateChange
       
  5604 // -----------------------------------------------------------------------------
       
  5605 //
       
  5606 void CFSEmailUiMailListVisualiser::FocusVisibilityChange( TBool aVisible )
       
  5607     {
       
  5608     FUNC_LOG;
       
  5609 
       
  5610     CFsEmailUiViewBase::FocusVisibilityChange( aVisible );
       
  5611 
       
  5612     if( iFocusedControl == EControlBarComponent )
       
  5613         {
       
  5614         iControlBarControl->MakeSelectorVisible( aVisible );
       
  5615         }
       
  5616 
       
  5617     if ( iStylusPopUpMenuVisible && !aVisible )
       
  5618     	{
       
  5619     	// Do not allow to remove the focus from a list element if the pop up
       
  5620     	// menu was just launched.
       
  5621     	return;
       
  5622     	}
       
  5623 
       
  5624     iMailTreeListVisualizer->SetFocusVisibility( aVisible );
       
  5625     }
       
  5626 
       
  5627 // ---------------------------------------------------------------------------
       
  5628 // CFSEmailUiMailListVisualiser::DisableMailList
       
  5629 // ---------------------------------------------------------------------------
       
  5630 //
       
  5631 void CFSEmailUiMailListVisualiser::DisableMailList( TBool aValue )
       
  5632     {
       
  5633     FUNC_LOG;
       
  5634     iTouchManager->SetDisabled( aValue );
       
  5635     iControlBarControl->EnableTouch( (aValue) ? EFalse : ETrue  );
       
  5636     }
       
  5637 //</cmail>
       
  5638 
       
  5639 // ---------------------------------------------------------------------------
       
  5640 //
       
  5641 //
       
  5642 // ---------------------------------------------------------------------------
       
  5643 //
       
  5644 void CFSEmailUiMailListVisualiser::ShortcutCollapseExpandAllToggleL()
       
  5645 	{
       
  5646     FUNC_LOG;
       
  5647 	if ( !AllNodesCollapsed() )
       
  5648 		{
       
  5649 		CollapseAllNodesL();
       
  5650 		}
       
  5651 	else
       
  5652 		{
       
  5653 		ExpandAllNodesL();
       
  5654 		}
       
  5655 	}
       
  5656 
       
  5657 // ---------------------------------------------------------------------------
       
  5658 //
       
  5659 //
       
  5660 // ---------------------------------------------------------------------------
       
  5661 //
       
  5662 TBool CFSEmailUiMailListVisualiser::AllNodesCollapsed() const
       
  5663     {
       
  5664     FUNC_LOG;
       
  5665 	for ( TInt i=0;i<iTreeItemArray.Count();i++)
       
  5666 		{
       
  5667 		if ( iMailList->IsNode( iTreeItemArray[i].iListItemId ) )
       
  5668 			{
       
  5669 			if ( iMailList->IsExpanded( iTreeItemArray[i].iListItemId ) )
       
  5670 				{
       
  5671 				return EFalse;
       
  5672 				}
       
  5673 			}
       
  5674 		}
       
  5675 
       
  5676 	return ETrue;
       
  5677     }
       
  5678 
       
  5679 // ---------------------------------------------------------------------------
       
  5680 //
       
  5681 //
       
  5682 // ---------------------------------------------------------------------------
       
  5683 //
       
  5684 TBool CFSEmailUiMailListVisualiser::AllNodesExpanded() const
       
  5685     {
       
  5686     FUNC_LOG;
       
  5687 	for ( TInt i=0;i<iTreeItemArray.Count();i++)
       
  5688 		{
       
  5689 		if ( iMailList->IsNode( iTreeItemArray[i].iListItemId ) )
       
  5690 			{
       
  5691 			if ( !iMailList->IsExpanded( iTreeItemArray[i].iListItemId ) )
       
  5692 				{
       
  5693 				return EFalse;
       
  5694 				}
       
  5695 			}
       
  5696 		}
       
  5697 
       
  5698 	return ETrue;
       
  5699     }
       
  5700 
       
  5701 // ---------------------------------------------------------------------------
       
  5702 // CFSEmailUiMailListVisualiser::IsMarkAsReadAvailableL()
       
  5703 // Function checks if mark as read option should be available for user
       
  5704 // ---------------------------------------------------------------------------
       
  5705 //
       
  5706 TBool CFSEmailUiMailListVisualiser::IsMarkAsReadAvailableL() const
       
  5707     {
       
  5708     FUNC_LOG;
       
  5709     TBool available = EFalse;
       
  5710 
       
  5711     // In outbox the mark as read is always inavailable
       
  5712     if ( iMailFolder && iMailFolder->GetFolderType() != EFSOutbox )
       
  5713         {
       
  5714         RFsTreeItemIdList targetEntries;
       
  5715         CleanupClosePushL( targetEntries );
       
  5716         GetActionsTargetEntriesL( targetEntries );
       
  5717 
       
  5718         // Mark as read is available if at least one of the target entries is unread
       
  5719         for ( TInt i = 0 ; i < targetEntries.Count() ; ++i )
       
  5720             {
       
  5721             const CFSMailMessage& message = MsgPtrFromListIdL( targetEntries[i] );
       
  5722             if ( !message.IsFlagSet(EFSMsgFlag_Read) )
       
  5723                 {
       
  5724                 available = ETrue;
       
  5725                 break;
       
  5726                 }
       
  5727             }
       
  5728 
       
  5729         CleanupStack::PopAndDestroy( &targetEntries );
       
  5730         }
       
  5731 
       
  5732     return available;
       
  5733     }
       
  5734 
       
  5735 // ---------------------------------------------------------------------------
       
  5736 // CFSEmailUiMailListVisualiser::IsMarkAsUnreadAvailableL()
       
  5737 // Function checks if mark as unread option should be available for user
       
  5738 // ---------------------------------------------------------------------------
       
  5739 //
       
  5740 TBool CFSEmailUiMailListVisualiser::IsMarkAsUnreadAvailableL() const
       
  5741     {
       
  5742     FUNC_LOG;
       
  5743     TBool available = EFalse;
       
  5744 
       
  5745     // In outbox the mark as unread is always inavailable
       
  5746     if ( iMailFolder && iMailFolder->GetFolderType() != EFSOutbox )
       
  5747         {
       
  5748         RFsTreeItemIdList targetEntries;
       
  5749         CleanupClosePushL( targetEntries );
       
  5750         GetActionsTargetEntriesL( targetEntries );
       
  5751 
       
  5752         // Mark as unread is available if at least one of the target entries is read
       
  5753         for ( TInt i = 0 ; i < targetEntries.Count() ; ++i )
       
  5754             {
       
  5755             const CFSMailMessage& message = MsgPtrFromListIdL( targetEntries[i] );
       
  5756             if ( message.IsFlagSet(EFSMsgFlag_Read) )
       
  5757                 {
       
  5758                 available = ETrue;
       
  5759                 break;
       
  5760                 }
       
  5761             }
       
  5762 
       
  5763         CleanupStack::PopAndDestroy( &targetEntries );
       
  5764         }
       
  5765 
       
  5766     return available;
       
  5767     }
       
  5768 
       
  5769 // ---------------------------------------------------------------------------
       
  5770 // Utility function to get list of entries which will be targeted by the
       
  5771 // Actions menu commands. The list contains either marked entries or the
       
  5772 // focused message entry or is empty.
       
  5773 // ---------------------------------------------------------------------------
       
  5774 void CFSEmailUiMailListVisualiser::GetActionsTargetEntriesL( RFsTreeItemIdList& aListItems ) const
       
  5775     {
       
  5776     FUNC_LOG;
       
  5777     if ( iMailList )
       
  5778         {
       
  5779         iMailList->GetMarkedItemsL( aListItems );
       
  5780 
       
  5781         // If there are no marked entries the command target is the focused item.
       
  5782         if ( !aListItems.Count() )
       
  5783             {
       
  5784             TFsTreeItemId focusedId = iMailList->FocusedItem();
       
  5785             if ( iFocusedControl == EMailListComponent &&
       
  5786                  focusedId != KFsTreeNoneID &&
       
  5787                  !iMailList->IsNode( focusedId ) )
       
  5788                 {
       
  5789                 aListItems.AppendL( focusedId );
       
  5790                 }
       
  5791             }
       
  5792         }
       
  5793     }
       
  5794 
       
  5795 // ---------------------------------------------------------------------------
       
  5796 //
       
  5797 //
       
  5798 // ---------------------------------------------------------------------------
       
  5799 //
       
  5800 void CFSEmailUiMailListVisualiser::ShortcutReadUnreadToggleL()
       
  5801     {
       
  5802     FUNC_LOG;
       
  5803     // Setting the read status is not possible in outbox
       
  5804     // <cmail>
       
  5805     if ( iModel->Count() && iMailFolder && iMailFolder->GetFolderType() != EFSOutbox )
       
  5806     // </cmail>
       
  5807         {
       
  5808         RFsTreeItemIdList targetEntries;
       
  5809         CleanupClosePushL( targetEntries );
       
  5810         GetActionsTargetEntriesL( targetEntries );
       
  5811         TInt targetCount = targetEntries.Count();
       
  5812 
       
  5813         // figure out are we marking items as read or unread
       
  5814         TBool toggleAsRead(ETrue);
       
  5815         for ( TInt i=0 ; i<targetCount ; i++ )
       
  5816             {
       
  5817             CFSMailMessage& msgPtr = MsgPtrFromListIdL( targetEntries[i] );
       
  5818             if ( msgPtr.IsFlagSet(EFSMsgFlag_Read) )
       
  5819                 {
       
  5820                 toggleAsRead = EFalse;
       
  5821                 break;
       
  5822                 }
       
  5823             }
       
  5824 
       
  5825         // change the status of the target items
       
  5826         for ( TInt i=0 ; i<targetCount ; i++ )
       
  5827             {
       
  5828             TInt msgIndex = ModelIndexFromListId( targetEntries[i] );
       
  5829             ChangeReadStatusOfIndexL( toggleAsRead, msgIndex );
       
  5830             }
       
  5831 
       
  5832         CleanupStack::PopAndDestroy( &targetEntries );
       
  5833         }
       
  5834     }
       
  5835 
       
  5836 // ---------------------------------------------------------------------------
       
  5837 //
       
  5838 //
       
  5839 // ---------------------------------------------------------------------------
       
  5840 //
       
  5841 void CFSEmailUiMailListVisualiser::HandleControlBarEvent( TFsControlBarEvent aEvent, TInt aData )
       
  5842 	{
       
  5843     FUNC_LOG;
       
  5844 
       
  5845     switch( aEvent )
       
  5846         {
       
  5847         case EEventFocusLostAtBottom:
       
  5848         case EEventFocusLostAtSide:
       
  5849             {
       
  5850             iFocusedControl = EMailListComponent;
       
  5851             TRAP_IGNORE( iMailList->SetFocusedL( ETrue ) );
       
  5852             break;
       
  5853             }
       
  5854         case EEventFocusGained:
       
  5855             {
       
  5856             break;
       
  5857             }
       
  5858         case EEventButtonPressed:
       
  5859             {
       
  5860             // Handle 2 control buttons
       
  5861             if ( aData == iFolderListButtonId )
       
  5862                 {
       
  5863                 }
       
  5864             else if ( aData == iSortButtonId )
       
  5865                 {
       
  5866                 }
       
  5867             break;
       
  5868             }
       
  5869         case EEventFocusVisibilityChanged:
       
  5870             {
       
  5871             // Hide focus after button release
       
  5872             iAppUi.SetFocusVisibility( EFalse );
       
  5873             break;
       
  5874             }
       
  5875         default:
       
  5876             {
       
  5877             // No need to handle other events
       
  5878             break;
       
  5879             }
       
  5880         }
       
  5881 	}
       
  5882 
       
  5883 // ---------------------------------------------------------------------------
       
  5884 //
       
  5885 //
       
  5886 // ---------------------------------------------------------------------------
       
  5887 //
       
  5888 void CFSEmailUiMailListVisualiser::CreateControlBarLayoutL()
       
  5889 	{
       
  5890     FUNC_LOG;
       
  5891     iControlBarControl->SetRectL( iAppUi.LayoutHandler()->GetControlBarRect() );
       
  5892 
       
  5893     // New email button
       
  5894     iNewEmailButtonId = iControlBarControl->AddButtonL( ECBTypeOneLineLabelIconA );
       
  5895     iNewEmailButton = iControlBarControl->ButtonById( iNewEmailButtonId );
       
  5896     const TRect mailButtonRect( iAppUi.LayoutHandler()->GetControlBarNewEmailButtonRect() );
       
  5897     iNewEmailButton->SetPos( mailButtonRect.iTl );
       
  5898     iNewEmailButton->SetSize( mailButtonRect.Size() );
       
  5899     ControlGroup().AppendL(iNewEmailButton->AsAlfControl());
       
  5900 
       
  5901     // Folder list button
       
  5902     iFolderListButtonId = iControlBarControl->AddButtonL( ECBTypeOneLineLabelIconA );
       
  5903     iFolderListButton = iControlBarControl->ButtonById( iFolderListButtonId );
       
  5904     const TRect folderButtonRect( iAppUi.LayoutHandler()->GetControlBarFolderListButtonRect() );
       
  5905     iFolderListButton->SetPos( folderButtonRect.iTl );
       
  5906     iFolderListButton->SetSize( folderButtonRect.Size() );
       
  5907     ControlGroup().AppendL(iFolderListButton->AsAlfControl());
       
  5908 
       
  5909     // Sort order button
       
  5910     iSortButtonId = iControlBarControl->AddButtonL( ECBTypeOneLineLabelIconA );
       
  5911     iSortButton = iControlBarControl->ButtonById( iSortButtonId );
       
  5912     const TRect sortButtonRect( iAppUi.LayoutHandler()->GetControlBarSortButtonRect() );
       
  5913     iSortButton->SetPos( sortButtonRect.iTl );
       
  5914     iSortButton->SetSize( sortButtonRect.Size() );
       
  5915     ControlGroup().AppendL(iSortButton->AsAlfControl());
       
  5916 // </cmail>
       
  5917 
       
  5918     // Set the text alignment according the layout
       
  5919     TAlfAlignHorizontal horizontalAlign = EAlfAlignHLeft;
       
  5920     if ( AknLayoutUtils::LayoutMirrored() )
       
  5921         {
       
  5922         horizontalAlign = EAlfAlignHRight;
       
  5923         }
       
  5924 
       
  5925     // Icons and sort button text
       
  5926     iFolderListButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( EListControlBarMailboxDefaultIcon ) );
       
  5927     iNewEmailButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( EListTextureCreateNewMessageIcon ) );
       
  5928     SetSortButtonTextAndIconL();
       
  5929 
       
  5930     iNewEmailButton->SetElemAlignL(
       
  5931         ECBElemIconA,
       
  5932         EAlfAlignHCenter,
       
  5933         EAlfAlignVCenter );
       
  5934 
       
  5935     iFolderListButton->SetElemAlignL(
       
  5936         ECBElemLabelFirstLine,
       
  5937         horizontalAlign,
       
  5938         EAlfAlignVCenter );
       
  5939     iSortButton->SetElemAlignL(
       
  5940         ECBElemLabelFirstLine,
       
  5941         horizontalAlign,
       
  5942         EAlfAlignVCenter );
       
  5943     iSortButton->SetElemAlignL(
       
  5944         ECBElemIconA,
       
  5945         EAlfAlignHCenter,
       
  5946         EAlfAlignVCenter );
       
  5947 
       
  5948 	// Show the buttons
       
  5949   	iNewEmailButton->ShowButtonL();
       
  5950     iFolderListButton->ShowButtonL();
       
  5951     iSortButton->ShowButtonL();
       
  5952 	}
       
  5953 
       
  5954 // ---------------------------------------------------------------------------
       
  5955 //
       
  5956 //
       
  5957 // ---------------------------------------------------------------------------
       
  5958 //
       
  5959 void CFSEmailUiMailListVisualiser::ScaleControlBarL()
       
  5960 	{
       
  5961     FUNC_LOG;
       
  5962     
       
  5963     if( !Layout_Meta_Data::IsLandscapeOrientation() && iMarkingMode)
       
  5964         {
       
  5965         // No control bar buttons in portrait marking mode
       
  5966         return;    
       
  5967         }    
       
  5968     
       
  5969     TRect screenRect = iAppUi.ClientRect();
       
  5970 
       
  5971 	// First set pos, widht and height
       
  5972   	iControlBarControl->SetRectL( iAppUi.LayoutHandler()->GetControlBarRect() );
       
  5973 
       
  5974     const TRect newEmailButtonRect( iAppUi.LayoutHandler()->GetControlBarNewEmailButtonRect() );
       
  5975 	//Add comments by luo gen(e0645320)
       
  5976 	//The position of button should be set according to the size of button, so set size first
       
  5977     iNewEmailButton->SetSize( newEmailButtonRect.Size() );
       
  5978     iNewEmailButton->SetPos( newEmailButtonRect.iTl );
       
  5979 
       
  5980     const TRect folderButtonRect( iAppUi.LayoutHandler()->GetControlBarFolderListButtonRect() );
       
  5981     iFolderListButton->SetSize( folderButtonRect.Size() );
       
  5982   	iFolderListButton->SetPos( folderButtonRect.iTl );
       
  5983 
       
  5984     const TRect sortButtonRect( iAppUi.LayoutHandler()->GetControlBarSortButtonRect() );
       
  5985     iSortButton->SetSize( sortButtonRect.Size() );
       
  5986    	iSortButton->SetPos( sortButtonRect.iTl );
       
  5987 
       
  5988 	TInt var = Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0;
       
  5989 	TAknLayoutText textLayout;
       
  5990 	if ( Layout_Meta_Data::IsLandscapeOrientation() )
       
  5991 		{
       
  5992 	    textLayout.LayoutText(TRect(0,0,0,0), AknLayoutScalable_Apps::cmail_ddmenu_btn02_pane_t2(0));
       
  5993 		}
       
  5994 	else
       
  5995 		{
       
  5996 	    textLayout.LayoutText(TRect(0,0,0,0), AknLayoutScalable_Apps::main_sp_fs_ctrlbar_ddmenu_pane_t1(var));
       
  5997 		}
       
  5998 	iNewEmailButton->SetTextFontL( textLayout.Font()->FontSpecInTwips() );
       
  5999  	iFolderListButton->SetTextFontL( textLayout.Font()->FontSpecInTwips() );
       
  6000  	iSortButton->SetTextFontL( textLayout.Font()->FontSpecInTwips() );
       
  6001 
       
  6002  	UpdateThemeL(EFalse);
       
  6003 
       
  6004     iNewEmailButton->ShowButtonL();
       
  6005     iFolderListButton->ShowButtonL();
       
  6006     iSortButton->ShowButtonL();
       
  6007 	}
       
  6008 
       
  6009 // ---------------------------------------------------------------------------
       
  6010 //
       
  6011 //
       
  6012 // ---------------------------------------------------------------------------
       
  6013 //
       
  6014 void CFSEmailUiMailListVisualiser::SetSortButtonTextAndIconL()
       
  6015 	{
       
  6016     FUNC_LOG;
       
  6017 
       
  6018     // Set button text if necessary
       
  6019     HBufC* buttonText = GetSortButtonTextLC();
       
  6020 
       
  6021 	if ( !Layout_Meta_Data::IsLandscapeOrientation() )
       
  6022 		{
       
  6023 		if ( buttonText )
       
  6024 			{
       
  6025 			buttonText->Des().Zero();
       
  6026 			}
       
  6027 		}
       
  6028 
       
  6029 	if ( buttonText )
       
  6030 		{
       
  6031 		iSortButton->SetTextL( *buttonText );
       
  6032 		}
       
  6033 	CleanupStack::PopAndDestroy( buttonText );
       
  6034 
       
  6035 	iSortButton->SetIconL(
       
  6036 			iAppUi.FsTextureManager()->TextureByIndex( GetSortButtonTextureIndex() ),
       
  6037 			ECBElemIconA );
       
  6038 
       
  6039 	}
       
  6040     
       
  6041 // ---------------------------------------------------------------------------
       
  6042 //
       
  6043 //
       
  6044 // ---------------------------------------------------------------------------
       
  6045 //
       
  6046 TFSEmailUiTextures CFSEmailUiMailListVisualiser::GetSortButtonTextureIndex()
       
  6047     {
       
  6048     FUNC_LOG;
       
  6049     
       
  6050     TFSEmailUiTextures textureIndex( ETextureFirst );
       
  6051     switch ( iCurrentSortCriteria.iField )
       
  6052 		{
       
  6053 		case EFSMailSortBySubject:
       
  6054 			{
       
  6055 			textureIndex = iCurrentSortCriteria.iOrder == EFSMailAscending ?
       
  6056 						   ESortListSubjectDescTexture :
       
  6057 						   ESortListSubjectAscTexture;
       
  6058 			}
       
  6059 			break;
       
  6060 		case EFSMailSortByAttachment:
       
  6061 			{
       
  6062 			textureIndex = iCurrentSortCriteria.iOrder == EFSMailAscending ?
       
  6063 						   ESortListAttachmentDescTexture :
       
  6064 						   ESortListAttachmentAscTexture;
       
  6065 			}
       
  6066 			break;
       
  6067 		case EFSMailSortByFlagStatus:
       
  6068 			{
       
  6069 			textureIndex = iCurrentSortCriteria.iOrder == EFSMailAscending ?
       
  6070 						   ESortListFollowDescTexture :
       
  6071 						   ESortListFollowAscTexture;
       
  6072 			}
       
  6073 			break;
       
  6074 		case EFSMailSortByRecipient:
       
  6075 		case EFSMailSortBySender:
       
  6076 			{
       
  6077 			textureIndex = iCurrentSortCriteria.iOrder == EFSMailAscending ?
       
  6078 						   ESortListSenderDescTexture :
       
  6079 						   ESortListSenderAscTexture;
       
  6080 			}
       
  6081 			break;
       
  6082 		case EFSMailSortByPriority:
       
  6083 			{
       
  6084 			textureIndex = iCurrentSortCriteria.iOrder == EFSMailAscending ?
       
  6085 						   ESortListPriorityDescTexture :
       
  6086 						   ESortListPriorityAscTexture;
       
  6087 			}
       
  6088 			break;
       
  6089 		case EFSMailSortByUnread:
       
  6090 			{
       
  6091 			textureIndex = iCurrentSortCriteria.iOrder == EFSMailAscending ?
       
  6092 						   ESortListUnreadDescTexture :
       
  6093 						   ESortListUnreadAscTexture;
       
  6094 			}
       
  6095 			break;
       
  6096 		case EFSMailSortByDate:
       
  6097 		default:
       
  6098 			{
       
  6099 			textureIndex = iCurrentSortCriteria.iOrder == EFSMailAscending ?
       
  6100 						   ESortListDateDescTexture :
       
  6101 						   ESortListDateAscTexture;
       
  6102 			}
       
  6103 			break;
       
  6104   		}
       
  6105     return textureIndex;
       
  6106 	}
       
  6107 
       
  6108 // ---------------------------------------------------------------------------
       
  6109 //
       
  6110 //
       
  6111 // ---------------------------------------------------------------------------
       
  6112 //
       
  6113 HBufC* CFSEmailUiMailListVisualiser::GetSortButtonTextLC()
       
  6114 	{
       
  6115     FUNC_LOG;
       
  6116 	HBufC* buttonText( 0 );
       
  6117 
       
  6118 	switch ( iCurrentSortCriteria.iField )
       
  6119 		{
       
  6120 		case EFSMailSortBySubject:
       
  6121 			{
       
  6122 			buttonText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SORT_BY_SUBJECT );
       
  6123 			}
       
  6124 			break;
       
  6125 		case EFSMailSortByAttachment:
       
  6126 			{
       
  6127 			buttonText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SORT_BY_ATTACHMENT );
       
  6128 			}
       
  6129 			break;
       
  6130 		case EFSMailSortByFlagStatus:
       
  6131 			{
       
  6132 			buttonText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SORT_BY_FLAG );
       
  6133 			}
       
  6134 			break;
       
  6135 		case EFSMailSortByRecipient:
       
  6136 		case EFSMailSortBySender:
       
  6137 			{
       
  6138 			TFSFolderType folderType( EFSInbox );
       
  6139             if( iMailFolder )
       
  6140                {
       
  6141                folderType = iMailFolder->GetFolderType();
       
  6142                }
       
  6143 			switch( folderType )
       
  6144 				{
       
  6145 				case EFSSentFolder:
       
  6146 				case EFSDraftsFolder:
       
  6147 				case EFSOutbox:
       
  6148 					{
       
  6149 					buttonText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SORT_BY_RECIPIENT );
       
  6150 					}
       
  6151 					break;
       
  6152 				default:
       
  6153 					buttonText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SORT_BY_SENDER );
       
  6154 					break;
       
  6155 				}
       
  6156 			}
       
  6157 			break;
       
  6158 		case EFSMailSortByPriority:
       
  6159 			{
       
  6160 			buttonText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SORT_BY_PRIORITY );
       
  6161 			}
       
  6162 			break;
       
  6163 		case EFSMailSortByUnread:
       
  6164 			{
       
  6165 			buttonText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SORT_BY_UNREAD );
       
  6166 			}
       
  6167 			break;
       
  6168 		case EFSMailSortByDate:
       
  6169 		default:
       
  6170 			{
       
  6171 			buttonText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_UI_SORT_BY_DATE );
       
  6172 			}
       
  6173 			break;
       
  6174 		}
       
  6175 	return buttonText;
       
  6176 	}
       
  6177 
       
  6178 // ---------------------------------------------------------------------------
       
  6179 //
       
  6180 //
       
  6181 // ---------------------------------------------------------------------------
       
  6182 //
       
  6183 void CFSEmailUiMailListVisualiser::SetMailListLayoutAnchors()
       
  6184 	{
       
  6185     FUNC_LOG;
       
  6186  	// Set anchors so that list leaves space for control bar
       
  6187     iScreenAnchorLayout->SetAnchor(EAlfAnchorTopLeft, 0,
       
  6188         EAlfAnchorOriginLeft, EAlfAnchorOriginTop,
       
  6189         EAlfAnchorMetricRelativeToSize, EAlfAnchorMetricRelativeToSize,
       
  6190         TAlfTimedPoint(0, 0 ));
       
  6191     iScreenAnchorLayout->SetAnchor(EAlfAnchorBottomRight, 0,
       
  6192         EAlfAnchorOriginLeft, EAlfAnchorOriginTop,
       
  6193         EAlfAnchorMetricRelativeToSize, EAlfAnchorMetricAbsolute,
       
  6194         TAlfTimedPoint(1, iAppUi.LayoutHandler()->ControlBarHeight() ));
       
  6195 
       
  6196     // <cmail> Platform layout changes
       
  6197     TRect listRect = iAppUi.LayoutHandler()->GetListRect();
       
  6198 	// Set anchors so that list leaves space for control bar
       
  6199     if( Layout_Meta_Data::IsMirrored() ) 
       
  6200         { 
       
  6201         TInt tlX = listRect.iTl.iX; 
       
  6202         TInt brX = listRect.iBr.iX;
       
  6203         
       
  6204         listRect.iTl.iX = AknLayoutScalable_Avkon::Screen().LayoutLine().iW - brX; 
       
  6205         listRect.iBr.iX = AknLayoutScalable_Avkon::Screen().LayoutLine().iW - tlX; 
       
  6206         } 
       
  6207     iScreenAnchorLayout->SetAnchor(EAlfAnchorTopLeft, 1,
       
  6208         EAlfAnchorOriginLeft, EAlfAnchorOriginTop,
       
  6209         EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute,
       
  6210         TAlfTimedPoint(listRect.iTl.iX, listRect.iTl.iY));
       
  6211     iScreenAnchorLayout->SetAnchor(EAlfAnchorBottomRight, 1,
       
  6212         EAlfAnchorOriginLeft, EAlfAnchorOriginTop,
       
  6213         EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute,
       
  6214         TAlfTimedPoint(listRect.iBr.iX, listRect.iBr.iY));
       
  6215     // </cmail> Platform layout changes
       
  6216 
       
  6217  	// Set anchors for connection icon
       
  6218 
       
  6219     // <cmail> Platform layout changes
       
  6220     TRect connectionIconRect( iAppUi.LayoutHandler()->GetControlBarConnectionIconRect() );
       
  6221     const TPoint& tl( connectionIconRect.iTl );
       
  6222  	iScreenAnchorLayout->SetAnchor(EAlfAnchorTopLeft, 2,
       
  6223         EAlfAnchorOriginLeft, EAlfAnchorOriginTop,
       
  6224         EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute,
       
  6225         TAlfTimedPoint( tl.iX, tl.iY ));
       
  6226     const TPoint& br( connectionIconRect.iBr );
       
  6227     iScreenAnchorLayout->SetAnchor(EAlfAnchorBottomRight, 2,
       
  6228         EAlfAnchorOriginLeft, EAlfAnchorOriginTop,
       
  6229         EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute,
       
  6230         TAlfTimedPoint( br.iX, br.iY ));
       
  6231     // </cmail> Platform layout changes
       
  6232 
       
  6233     iScreenAnchorLayout->UpdateChildrenLayout();
       
  6234     }
       
  6235 
       
  6236 // ---------------------------------------------------------------------------
       
  6237 //
       
  6238 //
       
  6239 // ---------------------------------------------------------------------------
       
  6240 //
       
  6241 void CFSEmailUiMailListVisualiser::ChangeReadStatusOfHighlightedL( TBool aRead )
       
  6242 	{
       
  6243     FUNC_LOG;
       
  6244 	ChangeReadStatusOfIndexL( aRead, HighlightedIndex() );
       
  6245 	}
       
  6246 
       
  6247 // ---------------------------------------------------------------------------
       
  6248 // ChangeReadStatusOfMarkedL
       
  6249 //
       
  6250 // ---------------------------------------------------------------------------
       
  6251 //
       
  6252 void CFSEmailUiMailListVisualiser::ChangeReadStatusOfMarkedL( TBool aRead )
       
  6253 	{
       
  6254     FUNC_LOG;
       
  6255 	RFsTreeItemIdList markedEntries;
       
  6256 	CleanupClosePushL( markedEntries );
       
  6257 	iMailList->GetMarkedItemsL( markedEntries );
       
  6258 	for ( TInt i=0; i<markedEntries.Count();i++ )
       
  6259 		{
       
  6260 		TInt msgIndex = ModelIndexFromListId( markedEntries[i] );
       
  6261 		ChangeReadStatusOfIndexL( aRead, msgIndex );
       
  6262 		}
       
  6263 	UnmarkAllItemsL();
       
  6264 	CleanupStack::PopAndDestroy( &markedEntries );
       
  6265 	}
       
  6266 
       
  6267 void CFSEmailUiMailListVisualiser::ChangeReadStatusOfIndexL( TBool aRead, TInt aIndex )
       
  6268     {
       
  6269     FUNC_LOG;
       
  6270     // <cmail>
       
  6271     if ( iModel->Count() )
       
  6272     // </cmail>
       
  6273         {
       
  6274         CFSEmailUiMailListModelItem* selectedItem =
       
  6275             static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( aIndex ));
       
  6276         if ( selectedItem ) // Safety
       
  6277             {
       
  6278             CFSMailMessage& msgPtr = selectedItem->MessagePtr();
       
  6279             TBool msgWasReadBefore = msgPtr.IsFlagSet( EFSMsgFlag_Read );
       
  6280             if ( aRead != msgWasReadBefore )
       
  6281                 {
       
  6282                 if ( aRead )
       
  6283                     {
       
  6284                     // Send flags, local and server
       
  6285                     msgPtr.SetFlag( EFSMsgFlag_Read );
       
  6286                     }
       
  6287                 else
       
  6288                     {
       
  6289                     // Send flags, local and server
       
  6290                     msgPtr.ResetFlag( EFSMsgFlag_Read );
       
  6291                     }
       
  6292                 msgPtr.SaveMessageL();  // Save flag
       
  6293 
       
  6294                 // Switch icon to correct one if mail list is visible
       
  6295                 TBool needRefresh = ( iAppUi.CurrentActiveView()->Id() == MailListId );
       
  6296                 UpdateMsgIconAndBoldingL( aIndex, needRefresh);
       
  6297 
       
  6298                 if ( iCurrentSortCriteria.iField == EFSMailSortByUnread )
       
  6299                     {
       
  6300                     // Attribute affecting the current sorting order has been changed.
       
  6301                     // Thus, the list order may now be incorrect.
       
  6302                     iListOrderMayBeOutOfDate = ETrue;
       
  6303                     }
       
  6304                 }
       
  6305             }
       
  6306         }
       
  6307     }
       
  6308 
       
  6309 // ---------------------------------------------------------------------------
       
  6310 // DeleteMessagesL
       
  6311 //
       
  6312 // ---------------------------------------------------------------------------
       
  6313 //
       
  6314 void CFSEmailUiMailListVisualiser::DeleteMessagesL()
       
  6315 	{
       
  6316     FUNC_LOG;
       
  6317     const TInt markedCount(CountMarkedItemsL());
       
  6318     const TFsTreeItemId focusedId(iMailList->FocusedItem());
       
  6319 
       
  6320     // Delete either marked items or the focused one
       
  6321     if (markedCount)
       
  6322         {
       
  6323         DeleteMarkedMessagesL();
       
  6324         }
       
  6325     else if (iMailList->IsNode(focusedId))
       
  6326         {
       
  6327         DeleteMessagesUnderNodeL(focusedId);
       
  6328         }
       
  6329     else
       
  6330         {
       
  6331         DeleteFocusedMessageL();
       
  6332         }
       
  6333 
       
  6334 	// Set highlight to control bar if no items after delete
       
  6335     // <cmail>
       
  6336 	if ( iModel->Count() == 0 )
       
  6337     // </cmail>
       
  6338 		{
       
  6339 		iFocusedControl = EControlBarComponent;
       
  6340 		iMailList->SetFocusedL( EFalse );
       
  6341 		iControlBarControl->SetFocusL();
       
  6342 		}
       
  6343 	}
       
  6344 
       
  6345 // ---------------------------------------------------------------------------
       
  6346 // UpdateItemAtIndexL
       
  6347 // Reload message pointer from mail client and update list item contents to
       
  6348 // match it. Item is removed if it isn't valid anymore.
       
  6349 // ---------------------------------------------------------------------------
       
  6350 //
       
  6351 void CFSEmailUiMailListVisualiser::UpdateItemAtIndexL( TInt aIndex )
       
  6352     {
       
  6353     FUNC_LOG;
       
  6354     // <cmail>
       
  6355 
       
  6356     if ( aIndex >= 0 && aIndex < iModel->Count() )
       
  6357     // </cmail>
       
  6358         {
       
  6359         CFSEmailUiMailListModelItem* modelItem =
       
  6360             static_cast<CFSEmailUiMailListModelItem*>( Model()->Item( aIndex ) );
       
  6361         if ( modelItem && modelItem->ModelItemType() == ETypeMailItem )
       
  6362             {
       
  6363             // This is beacause message deleted event migh have occured.
       
  6364             CFSMailMessage* confirmedMsgPtr = NULL;
       
  6365             TRAP_IGNORE( confirmedMsgPtr = iAppUi.GetMailClient()->GetMessageByUidL( iAppUi.GetActiveMailboxId(),
       
  6366                                                                                      iMailFolder->GetFolderId(),
       
  6367                                                                                      modelItem->MessagePtr().GetMessageId() ,
       
  6368                                                                                      EFSMsgDataEnvelope ) );
       
  6369             if( aIndex < iTreeItemArray.Count() )
       
  6370                 {
       
  6371                 if ( confirmedMsgPtr )
       
  6372                     {
       
  6373                     const SMailListItem& item = iTreeItemArray[aIndex];
       
  6374                     // Replace message pointer in model with newly fetched one
       
  6375                     Model()->ReplaceMessagePtr( aIndex, confirmedMsgPtr );
       
  6376 
       
  6377                     // Update the list item contents and formating to match the message pointer
       
  6378                     CFsTreePlainTwoLineItemData* itemData =
       
  6379                         static_cast<CFsTreePlainTwoLineItemData*>( item.iTreeItemData );
       
  6380                     CFsTreePlainTwoLineItemVisualizer* itemVis =
       
  6381                         static_cast<CFsTreePlainTwoLineItemVisualizer*>( item.iTreeItemVisualiser );
       
  6382 
       
  6383                     UpdateItemDataL( itemData, confirmedMsgPtr );
       
  6384                     UpdatePreviewPaneTextForItemL( itemData, confirmedMsgPtr );
       
  6385                     UpdateMsgIconAndBoldingL( itemData, itemVis, confirmedMsgPtr );
       
  6386                     iMailTreeListVisualizer->UpdateItemL( item.iListItemId );
       
  6387                     }
       
  6388                 else
       
  6389                     {
       
  6390                     // No confirmed message for highlighted, remove from list also
       
  6391                     iMailList->RemoveL( iTreeItemArray[aIndex].iListItemId ); // remove from list
       
  6392                     iTreeItemArray.Remove( aIndex ); // remove from internal array.
       
  6393                     iModel->RemoveAndDestroy( aIndex ); // Remove from model
       
  6394                     if ( iNodesInUse )
       
  6395                         {
       
  6396                         RemoveUnnecessaryNodesL();
       
  6397                         }
       
  6398                     }
       
  6399             	}
       
  6400             }
       
  6401         }
       
  6402     }
       
  6403 
       
  6404 // ---------------------------------------------------------------------------
       
  6405 // CheckValidityOfHighlightedMsgL
       
  6406 // Check validity of highlighted msg, and remove from list if needed
       
  6407 // Typically called after view is returned from editot or viewer.
       
  6408 // ---------------------------------------------------------------------------
       
  6409 //
       
  6410 TBool CFSEmailUiMailListVisualiser::CheckValidityOfHighlightedMsgL()
       
  6411 	{
       
  6412     FUNC_LOG;
       
  6413 	TBool ret(EFalse);
       
  6414     // <cmail>
       
  6415 	if ( iModel->Count() )
       
  6416     // </cmail>
       
  6417 		{
       
  6418 		CFSEmailUiMailListModelItem* item =
       
  6419 			static_cast<CFSEmailUiMailListModelItem*>( Model()->Item( HighlightedIndex() ) );
       
  6420 		if ( item && item->ModelItemType() == ETypeMailItem )
       
  6421 			{
       
  6422 			// This is beacause message deleted event migh have occured.
       
  6423 			CFSMailMessage* confirmedMsgPtr = NULL;
       
  6424 			TRAP_IGNORE( confirmedMsgPtr = iAppUi.GetMailClient()->GetMessageByUidL( iAppUi.GetActiveMailboxId(),
       
  6425 								                                                     iMailFolder->GetFolderId(),
       
  6426 								                                                     item->MessagePtr().GetMessageId() ,
       
  6427 								                                                     EFSMsgDataEnvelope ) );
       
  6428 			if ( confirmedMsgPtr )
       
  6429 				{
       
  6430 			   	ret = ETrue;
       
  6431 				delete confirmedMsgPtr;
       
  6432 				confirmedMsgPtr = NULL;
       
  6433 				}
       
  6434 			else
       
  6435 				{
       
  6436 				// No confirmed message for highlighted, remove from list also
       
  6437 				ret = EFalse;
       
  6438 				SMailListItem item;
       
  6439 				item.iListItemId = iMailList->FocusedItem();
       
  6440 				TInt IndexToBeDestroyed = iTreeItemArray.Find( item );
       
  6441 				iTreeItemArray.Remove( IndexToBeDestroyed ); // remove from internal array.
       
  6442 		 		iModel->RemoveAndDestroy( IndexToBeDestroyed ); // Remove from model
       
  6443 				iMailList->RemoveL( iMailList->FocusedItem() );		// remove from list
       
  6444 				if ( iNodesInUse )
       
  6445 					{
       
  6446 					RemoveUnnecessaryNodesL();
       
  6447 					}
       
  6448 				}
       
  6449 			}
       
  6450 		}
       
  6451 	return ret;
       
  6452 	}
       
  6453 
       
  6454 // ---------------------------------------------------------------------------
       
  6455 // UpdateMsgIconAndBoldingL
       
  6456 // Updates our own message object with the data from a given message object.
       
  6457 // The messages are matched with the message ID.
       
  6458 // ---------------------------------------------------------------------------
       
  6459 void CFSEmailUiMailListVisualiser::UpdateMsgIconAndBoldingL( CFSMailMessage* aMsgPtr )
       
  6460 	{
       
  6461     FUNC_LOG;
       
  6462     // <cmail>
       
  6463 	if ( aMsgPtr && iModel->Count() )
       
  6464     // </cmail>
       
  6465 		{
       
  6466 		TInt mailItemIdx = ItemIndexFromMessageId( aMsgPtr->GetMessageId() );
       
  6467 		if ( mailItemIdx >= 0 )
       
  6468 			{
       
  6469 			CFSEmailUiMailListModelItem* item =
       
  6470 				static_cast<CFSEmailUiMailListModelItem*>( Model()->Item( mailItemIdx ) );
       
  6471 
       
  6472             if ( item ) // For safety
       
  6473                 {
       
  6474                 // Update all flags
       
  6475                 TUint32 prevFlags = item->MessagePtr().GetFlags();
       
  6476                 TUint32 newFlags = aMsgPtr->GetFlags();
       
  6477                 if ( prevFlags != newFlags )
       
  6478                     {
       
  6479                     item->MessagePtr().ResetFlag( prevFlags );
       
  6480                     item->MessagePtr().SetFlag( newFlags );
       
  6481 
       
  6482                     // Save changed flags in internal model array
       
  6483                     item->MessagePtr().SaveMessageL();
       
  6484                     }
       
  6485 
       
  6486                 // Update the list item graphics
       
  6487                 UpdateMsgIconAndBoldingL( mailItemIdx );
       
  6488                 }
       
  6489             }
       
  6490 		}
       
  6491 	}
       
  6492 
       
  6493 // ---------------------------------------------------------------------------
       
  6494 // UpdateMsgIconAndBoldingL
       
  6495 // Updates list item at given index to match the state of the message object
       
  6496 // ---------------------------------------------------------------------------
       
  6497 //
       
  6498 void CFSEmailUiMailListVisualiser::UpdateMsgIconAndBoldingL( TInt aListIndex, TBool aRefreshItem )
       
  6499     {
       
  6500     FUNC_LOG;
       
  6501     CFSEmailUiMailListModelItem* item =
       
  6502         static_cast<CFSEmailUiMailListModelItem*>( Model()->Item(aListIndex) );
       
  6503     if ( item && item->ModelItemType() == ETypeMailItem )
       
  6504         {
       
  6505         CFSMailMessage* msgPtr = &item->MessagePtr();
       
  6506         CFsTreePlainTwoLineItemData* itemData =
       
  6507             static_cast<CFsTreePlainTwoLineItemData*>( iTreeItemArray[aListIndex].iTreeItemData );
       
  6508         CFsTreePlainTwoLineItemVisualizer* itemVis =
       
  6509             static_cast<CFsTreePlainTwoLineItemVisualizer*>( iTreeItemArray[aListIndex].iTreeItemVisualiser );
       
  6510 
       
  6511         UpdateMsgIconAndBoldingL( itemData, itemVis, msgPtr );
       
  6512 
       
  6513         //refresh item if requested
       
  6514         if ( aRefreshItem )
       
  6515             {
       
  6516             iMailTreeListVisualizer->UpdateItemL( iTreeItemArray[aListIndex].iListItemId );
       
  6517             }
       
  6518         }
       
  6519     }
       
  6520 
       
  6521 // ---------------------------------------------------------------------------
       
  6522 // UpdateMsgIconAndBoldingL
       
  6523 // Updates list item at given index to match the state of the message object
       
  6524 // ---------------------------------------------------------------------------
       
  6525 //
       
  6526 void CFSEmailUiMailListVisualiser::UpdateMsgIconAndBoldingL( CFsTreePlainTwoLineItemData* aItemData,
       
  6527                                                              CFsTreePlainTwoLineItemVisualizer* aItemVis,
       
  6528                                                              CFSMailMessage* aMsgPtr )
       
  6529     {
       
  6530     FUNC_LOG;
       
  6531 
       
  6532     if ( aItemData && aItemVis && aMsgPtr )
       
  6533         {
       
  6534         CAlfTexture* itemTexture = &TFsEmailUiUtility::GetMsgIcon( aMsgPtr, *iAppUi.FsTextureManager() );
       
  6535         aItemData->SetIcon( *itemTexture );
       
  6536         TInt variety( Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0 );
       
  6537         CAlfTextStyle& textStyle =
       
  6538             iAppUi.LayoutHandler()->FSTextStyleFromLayoutL(
       
  6539                 AknLayoutScalable_Apps::list_single_dyc_row_text_pane_t1( variety ) );
       
  6540         const TBool isNotRead( !aMsgPtr->IsFlagSet( EFSMsgFlag_Read ) );
       
  6541         textStyle.SetBold( isNotRead );
       
  6542         aItemVis->SetTextBold( isNotRead );
       
  6543         aItemVis->SetTextStyleId ( textStyle.Id() );
       
  6544         // Set follow up flag icon
       
  6545         if ( aMsgPtr->IsFlagSet( EFSMsgFlag_FollowUp ) )
       
  6546             {
       
  6547             aItemData->SetFlagIcon( iAppUi.FsTextureManager()->TextureByIndex( EFollowUpFlagList ) );
       
  6548             aItemVis->SetFlagIconVisible( ETrue );
       
  6549             }
       
  6550         else if ( aMsgPtr->IsFlagSet( EFSMsgFlag_FollowUpComplete ) )
       
  6551             {
       
  6552             aItemData->SetFlagIcon( iAppUi.FsTextureManager()->TextureByIndex( EFollowUpFlagCompleteList ) );
       
  6553             aItemVis->SetFlagIconVisible( ETrue );
       
  6554             }
       
  6555         else
       
  6556             {
       
  6557             aItemVis->SetFlagIconVisible( EFalse );
       
  6558             }
       
  6559         }
       
  6560     }
       
  6561 
       
  6562 // ---------------------------------------------------------------------------
       
  6563 // RemoveMsgItemsFromListIfFoundL
       
  6564 // Message removing from list if found. Does not panic or return found status.
       
  6565 // ---------------------------------------------------------------------------
       
  6566 //
       
  6567 void CFSEmailUiMailListVisualiser::RemoveMsgItemsFromListIfFoundL( const RArray<TFSMailMsgId>& aEntryIds )
       
  6568 	{
       
  6569     FUNC_LOG;
       
  6570     
       
  6571 	TBool itemFound = EFalse;
       
  6572     for ( TInt i=0 ; i<aEntryIds.Count() ; ++i )
       
  6573 	    {
       
  6574 	    const TFSMailMsgId& entryId = aEntryIds[i];
       
  6575     	if ( !entryId.IsNullId() )
       
  6576     		{
       
  6577         	TInt idx = ItemIndexFromMessageId( entryId );
       
  6578         	if ( idx >= 0 )
       
  6579         	    {
       
  6580     			iMailList->RemoveL( iTreeItemArray[idx].iListItemId ); // remove from list
       
  6581     			iTreeItemArray.Remove( idx ); // remove from internal array.
       
  6582     	 		iModel->RemoveAndDestroy( idx ); // Remove from model
       
  6583     	 		itemFound = ETrue;
       
  6584         	    }
       
  6585     		}
       
  6586 	    }
       
  6587 	
       
  6588     if ( !itemFound )
       
  6589         {
       
  6590         return;  // no items to be removed
       
  6591         }
       
  6592 		
       
  6593 	if ( iNodesInUse )
       
  6594 		{
       
  6595 		RemoveUnnecessaryNodesL();
       
  6596 		}
       
  6597 
       
  6598 	// Set highligh to control bar if no items left after
       
  6599 	// deleted items have been revoved from the list
       
  6600 	// Otherwise mail list takes care of highlight
       
  6601     // <cmail>
       
  6602 	if ( iModel->Count() == 0 )
       
  6603     // </cmail>
       
  6604 		{
       
  6605 		iFocusedControl = EControlBarComponent;
       
  6606 		iMailList->SetFocusedL( EFalse );
       
  6607 		iControlBarControl->SetFocusL();
       
  6608 		}
       
  6609 	}
       
  6610 
       
  6611 // ---------------------------------------------------------------------------
       
  6612 // DeleteFocusedMessageL
       
  6613 //
       
  6614 // ---------------------------------------------------------------------------
       
  6615 //
       
  6616 void CFSEmailUiMailListVisualiser::DeleteFocusedMessageL()
       
  6617 	{
       
  6618     FUNC_LOG;
       
  6619 	TInt currentItemIndex = HighlightedIndex();
       
  6620 	if ( Model()->Count() )
       
  6621 		{
       
  6622 		CFSEmailUiMailListModelItem* item =
       
  6623 			static_cast<CFSEmailUiMailListModelItem*>( Model()->Item(currentItemIndex) );
       
  6624 		if ( item && item->ModelItemType() == ETypeMailItem )
       
  6625 			{
       
  6626 			CFSMailMessage& messagePtr = item->MessagePtr();
       
  6627             // Delete message from framework, and perform internal housekeeping
       
  6628             TFSMailMsgId msgId = messagePtr.GetMessageId();
       
  6629             RArray<TFSMailMsgId> msgIds;
       
  6630             CleanupClosePushL( msgIds );
       
  6631             msgIds.Append( msgId );
       
  6632             TFSMailMsgId folderId = FolderId();
       
  6633             TFSMailMsgId mailBox = iAppUi.GetActiveMailbox()->GetId();
       
  6634             iAppUi.GetMailClient()->DeleteMessagesByUidL( mailBox, folderId, msgIds );
       
  6635             RemoveMsgItemsFromListIfFoundL( msgIds );
       
  6636             CleanupStack::PopAndDestroy( &msgIds );
       
  6637 			}
       
  6638 		}
       
  6639 	}
       
  6640 
       
  6641 // ---------------------------------------------------------------------------
       
  6642 // DeleteMessagesUnderNodeL
       
  6643 //
       
  6644 // ---------------------------------------------------------------------------
       
  6645 //
       
  6646 void CFSEmailUiMailListVisualiser::DeleteMessagesUnderNodeL(
       
  6647         const TFsTreeItemId aNodeId)
       
  6648     {
       
  6649     FUNC_LOG;
       
  6650     iModel->GetItemIdsUnderNodeL(aNodeId, iDeleteTask->Entries());
       
  6651     ConfirmAndStartDeleteTaskL(iDeleteTask);
       
  6652     }
       
  6653 
       
  6654 // ---------------------------------------------------------------------------
       
  6655 // DeleteMarkedMessagesL
       
  6656 //
       
  6657 // ---------------------------------------------------------------------------
       
  6658 //
       
  6659 void CFSEmailUiMailListVisualiser::DeleteMarkedMessagesL()
       
  6660     {
       
  6661     FUNC_LOG;
       
  6662     iMailList->GetMarkedItemsL(iDeleteTask->Entries());
       
  6663     ConfirmAndStartDeleteTaskL(iDeleteTask);
       
  6664     }
       
  6665 
       
  6666 // ---------------------------------------------------------------------------
       
  6667 // ConfirmAndStartDeleteTaskL
       
  6668 //
       
  6669 // ---------------------------------------------------------------------------
       
  6670 //
       
  6671 void CFSEmailUiMailListVisualiser::ConfirmAndStartDeleteTaskL(
       
  6672         TDeleteTask<CFSEmailUiMailListVisualiser>* aTask )
       
  6673     {
       
  6674     FUNC_LOG;
       
  6675     const RFsTreeItemIdList& entries(aTask->Entries());
       
  6676     if (entries.Count())
       
  6677         {
       
  6678         if (ConfirmDeleteL(entries.Count(), entries[0]))
       
  6679             {
       
  6680             ExitMarkingModeL();
       
  6681             if (entries.Count() > KMsgDeletionWaitNoteAmount)
       
  6682                 {
       
  6683                 TFsEmailUiUtility::ShowWaitNoteL(iDeletingWaitNote,
       
  6684                         R_FSE_WAIT_DELETING_TEXT, EFalse, ETrue);
       
  6685                 }
       
  6686             if (iAsyncCallback)
       
  6687                 {
       
  6688                 // Call actual deletion asynchronously because we must give wait
       
  6689                 // note time to show up before deletion begins.
       
  6690                 iAsyncCallback->Cancel();
       
  6691                 iAsyncCallback->Set(TCallBack(DoExecuteDeleteTask, aTask));
       
  6692                 iAsyncCallback->CallBack();
       
  6693                 }
       
  6694             }
       
  6695         else
       
  6696             {
       
  6697             aTask->Reset();
       
  6698             }
       
  6699         }
       
  6700     }
       
  6701 
       
  6702 // ---------------------------------------------------------------------------
       
  6703 // DoExecuteDeleteTask
       
  6704 //
       
  6705 // ---------------------------------------------------------------------------
       
  6706 //
       
  6707 TInt CFSEmailUiMailListVisualiser::DoExecuteDeleteTask( TAny* aSelfPtr )
       
  6708     {
       
  6709     FUNC_LOG;
       
  6710     TRAPD( error, 
       
  6711             reinterpret_cast<TDeleteTask<CFSEmailUiMailListVisualiser>*>(aSelfPtr)->ExecuteL() );
       
  6712     return error;
       
  6713     }
       
  6714 
       
  6715 // ---------------------------------------------------------------------------
       
  6716 // HandleDeleteTaskL
       
  6717 // This is called asynchronously by ConfirmAndStartDeleteTaskL
       
  6718 // ---------------------------------------------------------------------------
       
  6719 //
       
  6720 void CFSEmailUiMailListVisualiser::HandleDeleteTaskL( const RFsTreeItemIdList& aEntries )
       
  6721     {
       
  6722     FUNC_LOG;
       
  6723     // Close wait note if it was used
       
  6724     if ( iDeletingWaitNote )
       
  6725         {
       
  6726         TRAPD( result, HandleDeleteTaskLeavingCodeL(aEntries) );
       
  6727         // closing the "Deleting" dialog message should not be skipped by leaving
       
  6728         TRAP_IGNORE( iDeletingWaitNote->ProcessFinishedL() ); 
       
  6729         if ( KErrNone != result )
       
  6730             {
       
  6731             // Handle error.
       
  6732             User::Leave( result );
       
  6733             }
       
  6734         }
       
  6735     else
       
  6736         {
       
  6737         HandleDeleteTaskLeavingCodeL( aEntries );
       
  6738         }
       
  6739     }
       
  6740 
       
  6741 // ---------------------------------------------------------------------------
       
  6742 // original code HandleDeleteTaskL which may leave - help function to enable 
       
  6743 // calling iDeletingWaitNote->ProcessFinishedL() 
       
  6744 // ---------------------------------------------------------------------------
       
  6745 //
       
  6746 void CFSEmailUiMailListVisualiser::HandleDeleteTaskLeavingCodeL( const RFsTreeItemIdList& aEntries )
       
  6747     {
       
  6748     FUNC_LOG;
       
  6749     TFSMailMsgId folderId = FolderId();
       
  6750     TFSMailMsgId mailBox = iAppUi.GetActiveMailboxId();
       
  6751     RArray<TFSMailMsgId> msgIds;
       
  6752     CleanupClosePushL( msgIds );
       
  6753     for ( TInt i = aEntries.Count() - 1; i >= 0; i-- )
       
  6754         {
       
  6755         msgIds.AppendL( MsgIdFromListId( aEntries[i] ) );
       
  6756         }
       
  6757 
       
  6758     // Clear the focused item to avoid repeated selection of a new focused
       
  6759     // item, unnecessary scrolling of the viewport, etc.
       
  6760     iMailTreeListVisualizer->SetFocusedItemL( KFsTreeNoneID );
       
  6761 
       
  6762     iMailList->BeginUpdate();
       
  6763     iAppUi.GetMailClient()->DeleteMessagesByUidL( mailBox, folderId, msgIds );
       
  6764     // Remove from mail list if not already removed by mailbox events
       
  6765     RemoveMsgItemsFromListIfFoundL( msgIds );
       
  6766     iMailList->EndUpdateL();
       
  6767 
       
  6768     CleanupStack::PopAndDestroy(); // msgIds.Close()
       
  6769     }
       
  6770 
       
  6771 // ---------------------------------------------------------------------------
       
  6772 // ConfirmDeleteL
       
  6773 //
       
  6774 // ---------------------------------------------------------------------------
       
  6775 //
       
  6776 TBool CFSEmailUiMailListVisualiser::ConfirmDeleteL(const TInt aItemCount,
       
  6777         const TFsTreeItemId aItemId) const
       
  6778     {
       
  6779     FUNC_LOG;
       
  6780     TBool result(ETrue);
       
  6781     if (iAppUi.GetCRHandler()->WarnBeforeDelete())
       
  6782         {
       
  6783         HBufC* noteText(NULL);
       
  6784         // The note depends on the amount and type of message(s)
       
  6785         if (aItemCount == 1)
       
  6786             {
       
  6787             const CFSMailMessage& msgPtr(MsgPtrFromListIdL(aItemId));
       
  6788             HBufC* msgSubject = TFsEmailUiUtility::CreateSubjectTextLC(
       
  6789                     &msgPtr);
       
  6790             if (msgPtr.IsFlagSet(EFSMsgFlag_CalendarMsg))
       
  6791                 {
       
  6792                 noteText = StringLoader::LoadL(
       
  6793                         R_FREESTYLE_EMAIL_DELETE_CALEVENT_NOTE, *msgSubject);
       
  6794                 }
       
  6795             else
       
  6796                 {
       
  6797                 noteText = StringLoader::LoadL(
       
  6798                         R_FREESTYLE_EMAIL_DELETE_MAIL_NOTE, *msgSubject);
       
  6799                 }
       
  6800             CleanupStack::PopAndDestroy(msgSubject);
       
  6801             CleanupStack::PushL(noteText);
       
  6802             }
       
  6803         else // markedEntries.Count() > 1
       
  6804             {
       
  6805             noteText = StringLoader::LoadLC(
       
  6806                     R_FREESTYLE_EMAIL_DELETE_N_MAILS_NOTE, aItemCount);
       
  6807             }
       
  6808 
       
  6809         // Show the note
       
  6810         result = TFsEmailUiUtility::ShowConfirmationQueryL(*noteText);
       
  6811         CleanupStack::PopAndDestroy(noteText);
       
  6812         }
       
  6813     return result;
       
  6814     }
       
  6815 
       
  6816 // ---------------------------------------------------------------------------
       
  6817 // RemoveUnnecessaryNodesL
       
  6818 //
       
  6819 // ---------------------------------------------------------------------------
       
  6820 //
       
  6821 void CFSEmailUiMailListVisualiser::RemoveUnnecessaryNodesL()
       
  6822 	{
       
  6823     FUNC_LOG;
       
  6824 	RArray<TInt> nodesToBeRemoved;
       
  6825 	CleanupClosePushL( nodesToBeRemoved );
       
  6826 	for ( TInt i=0;i<iTreeItemArray.Count();i++)
       
  6827 		{
       
  6828 		if ( iMailList->IsNode( iTreeItemArray[i].iListItemId ) )
       
  6829 			{
       
  6830 			if ( iMailList->CountChildren( iTreeItemArray[i].iListItemId ) == 0)
       
  6831 				{
       
  6832 				nodesToBeRemoved.Append( iTreeItemArray[i].iListItemId );
       
  6833 				}
       
  6834 			}
       
  6835 		}
       
  6836 	// Remove from the list itself and from iTreeItemArray
       
  6837 	for ( TInt a = 0; a < nodesToBeRemoved.Count(); a++ )
       
  6838 		{
       
  6839 		iMailList->RemoveL( nodesToBeRemoved[a] );
       
  6840 		SMailListItem item;
       
  6841 		item.iListItemId = nodesToBeRemoved[a];
       
  6842 		TInt IndexToBeDestroyed = iTreeItemArray.Find( item );
       
  6843 		iTreeItemArray.Remove( IndexToBeDestroyed ); // remove from internal array.
       
  6844 		// Remove from model
       
  6845  		iModel->RemoveAndDestroy( IndexToBeDestroyed );
       
  6846 		}
       
  6847 	CleanupStack::PopAndDestroy( &nodesToBeRemoved );
       
  6848 	}
       
  6849 
       
  6850 // ---------------------------------------------------------------------------
       
  6851 // MsgIdFromIndex
       
  6852 // Helper function to get message id from list index
       
  6853 // ---------------------------------------------------------------------------
       
  6854 //
       
  6855 TFSMailMsgId CFSEmailUiMailListVisualiser::MsgIdFromIndex( TInt aItemIdx ) const
       
  6856     {
       
  6857     FUNC_LOG;
       
  6858 	TFSMailMsgId msgId; // constructs null ID
       
  6859     // <cmail>
       
  6860     if ( 0 <= aItemIdx && aItemIdx < iModel->Count() )
       
  6861     // </cmail>
       
  6862         {
       
  6863         CFSEmailUiMailListModelItem* item =
       
  6864     			static_cast<CFSEmailUiMailListModelItem*>(iModel->Item(aItemIdx));
       
  6865     	if ( item && item->ModelItemType() == ETypeMailItem )
       
  6866     	    {
       
  6867     	    msgId = item->MessagePtr().GetMessageId();
       
  6868     	    }
       
  6869         }
       
  6870 
       
  6871     return msgId;
       
  6872     }
       
  6873 
       
  6874 // ---------------------------------------------------------------------------
       
  6875 // MsgIdFromListId
       
  6876 // Get message ID corresponding given list ID. If the list ID is for a node,
       
  6877 // the message ID of its first child is returned
       
  6878 // ---------------------------------------------------------------------------
       
  6879 //
       
  6880 TFSMailMsgId CFSEmailUiMailListVisualiser::MsgIdFromListId( TFsTreeItemId aListId ) const
       
  6881 	{
       
  6882     FUNC_LOG;
       
  6883     TFSMailMsgId msgId; // constructs null ID
       
  6884 
       
  6885     if ( aListId != KFsTreeNoneID )
       
  6886         {
       
  6887         // Find corresponding message from the model
       
  6888         const TInt modelCount( iModel->Count() );
       
  6889         for( TInt i( 0 ) ; i < modelCount ; ++i )
       
  6890             {
       
  6891             CFSEmailUiMailListModelItem* item =
       
  6892                 static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( i ) );
       
  6893             if ( item && aListId == item->CorrespondingListId() )
       
  6894                 {
       
  6895                 msgId = item->MessagePtr().GetMessageId();
       
  6896                 // if list id points to separator
       
  6897                 // set flag on. This is made for improving focus handling.
       
  6898                 if( item->ModelItemType() == ETypeSeparator )
       
  6899                     {
       
  6900                     msgId.SetSeparator( ETrue );
       
  6901                     }
       
  6902                 break;
       
  6903                 }
       
  6904             }
       
  6905         }
       
  6906 
       
  6907 	return msgId;
       
  6908 	}
       
  6909 
       
  6910 // ---------------------------------------------------------------------------
       
  6911 // MsgPtrFromListIdL
       
  6912 //
       
  6913 // ---------------------------------------------------------------------------
       
  6914 //
       
  6915 CFSMailMessage& CFSEmailUiMailListVisualiser::MsgPtrFromListIdL( TFsTreeItemId aListId )
       
  6916 	{
       
  6917     FUNC_LOG;
       
  6918 	TInt index = ModelIndexFromListId( aListId );
       
  6919 	if ( index >= 0 )
       
  6920 	    {
       
  6921     	CFSEmailUiMailListModelItem* item =
       
  6922     		static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(index) );
       
  6923     	return item->MessagePtr();
       
  6924 	    }
       
  6925 	else
       
  6926 	    {
       
  6927     	// Leave if no message found. As the function returns a reference, it is not
       
  6928     	// possible to return any meaningful null value.
       
  6929     	User::Leave( KErrNotFound );
       
  6930 	    }
       
  6931 
       
  6932 	CFSMailMessage* dummy = NULL;
       
  6933 	return *dummy; // to surpress warning about missing return value; this is not really ever run
       
  6934 	}
       
  6935 
       
  6936 // ---------------------------------------------------------------------------
       
  6937 // MsgPtrFromListIdL
       
  6938 //
       
  6939 // ---------------------------------------------------------------------------
       
  6940 //
       
  6941 const CFSMailMessage& CFSEmailUiMailListVisualiser::MsgPtrFromListIdL( TFsTreeItemId aListId ) const
       
  6942     {
       
  6943     FUNC_LOG;
       
  6944     TInt index = ModelIndexFromListId( aListId );
       
  6945     if ( index >= 0 )
       
  6946         {
       
  6947         CFSEmailUiMailListModelItem* item =
       
  6948             static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(index) );
       
  6949         return item->MessagePtr();
       
  6950         }
       
  6951     else
       
  6952         {
       
  6953         // Leave if no message found. As the function returns a reference, it is not
       
  6954         // possible to return any meaningful null value.
       
  6955         User::Leave( KErrNotFound );
       
  6956         }
       
  6957 
       
  6958     const CFSMailMessage* dummy = NULL;
       
  6959     return *dummy; // to surpress warning about missing return value; this is not really ever run
       
  6960     }
       
  6961 
       
  6962 // ---------------------------------------------------------------------------
       
  6963 // ItemDataFromItemId
       
  6964 // Function returns a valid pointer to list item data based on item id
       
  6965 // ---------------------------------------------------------------------------
       
  6966 //
       
  6967 MFsTreeItemData* CFSEmailUiMailListVisualiser::ItemDataFromItemId( TFsTreeItemId aItemId )
       
  6968 	{
       
  6969     FUNC_LOG;
       
  6970 	MFsTreeItemData* itemData = NULL;
       
  6971 	if ( aItemId != KFsTreeNoneID )
       
  6972 	    {
       
  6973 	    itemData = &iMailList->ItemData( aItemId );
       
  6974 	    }
       
  6975 	return itemData;
       
  6976 	}
       
  6977 
       
  6978 // ---------------------------------------------------------------------------
       
  6979 // ItemVisualiserFromItemId
       
  6980 // Function returns a valid pointer to list item visualiser based on item id
       
  6981 // ---------------------------------------------------------------------------
       
  6982 //
       
  6983 MFsTreeItemVisualizer* CFSEmailUiMailListVisualiser::ItemVisualiserFromItemId( TFsTreeItemId aItemId )
       
  6984 	{
       
  6985     FUNC_LOG;
       
  6986 	MFsTreeItemVisualizer* itemVis = NULL;
       
  6987     if ( aItemId != KFsTreeNoneID )
       
  6988         {
       
  6989         itemVis = &iMailList->ItemVisualizer( aItemId );
       
  6990         }
       
  6991 	return itemVis;
       
  6992 	}
       
  6993 
       
  6994 // ---------------------------------------------------------------------------
       
  6995 // ItemIndexFromMessageId
       
  6996 // Function returns list index based on message pointer. KErrNotFound if
       
  6997 // ID is not included in the list
       
  6998 // ---------------------------------------------------------------------------
       
  6999 //
       
  7000 TInt CFSEmailUiMailListVisualiser::ItemIndexFromMessageId( const TFSMailMsgId& aMessageId ) const
       
  7001     {
       
  7002     FUNC_LOG;
       
  7003 	TInt idx = KErrNotFound;
       
  7004 
       
  7005 	// Check first the special case; if searched id is null id, there's no
       
  7006 	// point to loop the whole list. There shouldn't be any null id's in
       
  7007 	// the model anyway. There is currently also an error in FW's equality
       
  7008 	// operator implementation; it doesn't check the iNullId flag at all.
       
  7009 	if( !aMessageId.IsNullId() )
       
  7010 	    {
       
  7011 	    const TInt modelCount( iModel->Count() );
       
  7012     	for ( TInt i( 0 ); i < modelCount ; ++i )
       
  7013     		{
       
  7014     		CFSEmailUiMailListModelItem* item =
       
  7015                 static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( i ) );
       
  7016 			// when the item is a separator check whether its MessagePtr is valid (actually it's a reference)
       
  7017             if( item && &(item->MessagePtr()) != NULL)
       
  7018                 {
       
  7019                 if ( aMessageId == item->MessagePtr().GetMessageId() )
       
  7020                     {
       
  7021                     TModelItemType itemType = item->ModelItemType();
       
  7022                     TBool separator( aMessageId.IsSeparator() );
       
  7023 
       
  7024                     // Because separator and the first message after separator
       
  7025                     // have same message id, we need to separate these cases
       
  7026                     // and that is made with separator flag which is stored to
       
  7027                     // TFSMailMsgId object. If separator flag is on item need to be
       
  7028                     // separator if it is not on item needs to be mail item.
       
  7029                     if( ( separator && itemType == ETypeSeparator ) ||
       
  7030                         ( !separator && itemType == ETypeMailItem ) )
       
  7031                         {
       
  7032                         idx = i;
       
  7033                         break;
       
  7034                         }
       
  7035                     }
       
  7036                 }
       
  7037             }
       
  7038 		}
       
  7039 	return idx;
       
  7040     }
       
  7041 
       
  7042 // ---------------------------------------------------------------------------
       
  7043 // NextMessageIndex
       
  7044 // Function returns next message index from highlighted index
       
  7045 // KErrNotFound if there is no next message
       
  7046 // ---------------------------------------------------------------------------
       
  7047 //
       
  7048 TInt CFSEmailUiMailListVisualiser::NextMessageIndex( TInt aCurMsgIdx ) const
       
  7049     {
       
  7050     FUNC_LOG;
       
  7051 	TInt idx = KErrNotFound;
       
  7052 	for ( TInt i=aCurMsgIdx+1 ; i<iModel->Count() ; i++ )
       
  7053 		{
       
  7054 		CFSEmailUiMailListModelItem* item =
       
  7055 			static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(i) );
       
  7056 		if ( item && item->ModelItemType() == ETypeMailItem )
       
  7057 			{
       
  7058 			idx = i;
       
  7059 			break;
       
  7060 			}
       
  7061 		}
       
  7062 
       
  7063 	return idx;
       
  7064     }
       
  7065 
       
  7066 // ---------------------------------------------------------------------------
       
  7067 // PreviousMessageIndex
       
  7068 // Function returns previous message index from highlighted index
       
  7069 // KErrNotFound if there is no previous message
       
  7070 // ---------------------------------------------------------------------------
       
  7071 //
       
  7072 TInt CFSEmailUiMailListVisualiser::PreviousMessageIndex( TInt aCurMsgIdx ) const
       
  7073     {
       
  7074     FUNC_LOG;
       
  7075 	TInt idx( KErrNotFound );
       
  7076 	if ( aCurMsgIdx < iModel->Count() )
       
  7077 	    {
       
  7078     	for ( TInt i=aCurMsgIdx-1 ; i>=0 ; i-- )
       
  7079     		{
       
  7080     		CFSEmailUiMailListModelItem* item =
       
  7081     			static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(i) );
       
  7082     		if ( item && item->ModelItemType() == ETypeMailItem )
       
  7083     			{
       
  7084     			idx = i;
       
  7085     			break;
       
  7086     			}
       
  7087     		}
       
  7088 	    }
       
  7089 	return idx;
       
  7090     }
       
  7091 
       
  7092 // ---------------------------------------------------------------------------
       
  7093 // ModelIndexFromListId
       
  7094 // Function returns a model index corresponding the given tree list item ID
       
  7095 // ---------------------------------------------------------------------------
       
  7096 //
       
  7097 TInt CFSEmailUiMailListVisualiser::ModelIndexFromListId( TFsTreeItemId aItemId ) const
       
  7098 	{
       
  7099     FUNC_LOG;
       
  7100     TInt ret = KErrNotFound;
       
  7101     const TInt count = iModel->Count();
       
  7102     for ( TInt i=0; i < count; i++ )
       
  7103     	{
       
  7104     	const CFSEmailUiMailListModelItem* item =
       
  7105 		    static_cast<const CFSEmailUiMailListModelItem*>( iModel->Item(i) );
       
  7106     	if ( item && aItemId == item->CorrespondingListId() )
       
  7107     		{
       
  7108     		ret = i;
       
  7109     		break;
       
  7110     		}
       
  7111     	}
       
  7112     return ret;
       
  7113 	}
       
  7114 
       
  7115 // ---------------------------------------------------------------------------
       
  7116 // FolderSelectedL
       
  7117 // Folder list selection callback. Function updates list when folder is changed
       
  7118 // ---------------------------------------------------------------------------
       
  7119 //
       
  7120 void CFSEmailUiMailListVisualiser::FolderSelectedL(
       
  7121 	TFSMailMsgId aSelectedFolderId,
       
  7122 	TFSEmailUiCtrlBarResponse aResponse )
       
  7123 	{
       
  7124     FUNC_LOG;
       
  7125     // hide selector if keys are not pressed
       
  7126     iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  7127 	if ( iMoveToFolderOngoing )
       
  7128 		{
       
  7129 		iMoveToFolderOngoing = EFalse;
       
  7130 		switch ( aResponse )
       
  7131 			{
       
  7132 			case EFSEmailUiCtrlBarResponseCancel:
       
  7133 			    if ( iMarkingMode )
       
  7134 			        {
       
  7135                     DisplayMarkingModeTitleTextL();
       
  7136 			        }
       
  7137 			    iMarkingModeWaitingToExit = EFalse;
       
  7138 			    SetMskL();
       
  7139 				return;
       
  7140 			case EFSEmailUiCtrlBarResponseSelect:
       
  7141 			    {
       
  7142 				MoveMsgsToFolderL( aSelectedFolderId );
       
  7143 				SetMskL();
       
  7144 			    }
       
  7145 				break;
       
  7146 			default:
       
  7147 				break;
       
  7148 			}
       
  7149 		}
       
  7150 	else
       
  7151 		{
       
  7152 		// Ignore if cancel selected
       
  7153 		switch ( aResponse )
       
  7154 			{
       
  7155 			case EFSEmailUiCtrlBarResponseSwitchList:
       
  7156 				{
       
  7157 				TFSFolderType folderType;
       
  7158 				if ( iMailFolder )
       
  7159 					{
       
  7160 					folderType = iMailFolder->GetFolderType();
       
  7161 					}
       
  7162 				else
       
  7163 					{
       
  7164 					folderType = EFSInbox;
       
  7165 					}
       
  7166 			    iControlBarControl->SetFocusByIdL( iSortButtonId );
       
  7167 			    iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  7168 
       
  7169 			    // Sorting empty mail list disabled
       
  7170                 // Show sort list only if mail list is not empty
       
  7171                 if ( iModel->Count() )
       
  7172                     {
       
  7173                     iAppUi.ShowSortListInPopupL( iCurrentSortCriteria, folderType, this, iSortButton );
       
  7174                     }
       
  7175 				}
       
  7176 				return;
       
  7177 			case EFSEmailUiCtrlBarResponseCancel:
       
  7178 			    iMarkingModeWaitingToExit = EFalse;
       
  7179 			    SetMskL();
       
  7180 			    // <cmail> Touch
       
  7181                 //Set touchmanager back to active
       
  7182                 DisableMailList(EFalse);
       
  7183                 // </cmail>
       
  7184 				return;
       
  7185 			case EFSEmailUiCtrlBarResponseSelect:
       
  7186 			    SetMskL();
       
  7187 			    // <cmail> Touch
       
  7188                 //Set touchmanager back to active
       
  7189                 DisableMailList(EFalse);
       
  7190                 // </cmail>
       
  7191 			default:
       
  7192 				break;
       
  7193 			}
       
  7194 
       
  7195 		if ( !iMailFolder || ( iMailFolder && iMailFolder->GetFolderId() != aSelectedFolderId ) )
       
  7196 		    {
       
  7197 		    iMailListModelUpdater->Cancel();
       
  7198 		    iNewMailTimer->Cancel();
       
  7199 		    iNewMailIds.Reset();
       
  7200 		    SafeDelete(iMailFolder);
       
  7201             iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( iAppUi.GetActiveMailboxId(), aSelectedFolderId );
       
  7202 
       
  7203             if ( !iMailFolder )
       
  7204                 {
       
  7205                 // Do nothing if can't get the folder object
       
  7206                 return;
       
  7207                 }
       
  7208 
       
  7209             // Set new text to folder button in control bar
       
  7210             HBufC* newFolderName = CreateFolderNameLC( iMailFolder );
       
  7211             iFolderListButton->SetTextL( *newFolderName );
       
  7212             CleanupStack::PopAndDestroy( newFolderName );
       
  7213 
       
  7214             // Set initial sort criteria when folder has changed
       
  7215             iCurrentSortCriteria.iField = EFSMailSortByDate;
       
  7216             iCurrentSortCriteria.iOrder = EFSMailDescending;
       
  7217             // reload node state because in file sort mode this is disabled even when globally enabled
       
  7218             iNodesInUse = iAppUi.GetCRHandler()->TitleDividers();
       
  7219             SetSortButtonTextAndIconL();
       
  7220 
       
  7221             // Update the mail list contents
       
  7222             UpdateMailListModelL();
       
  7223             RefreshL();
       
  7224 		    }
       
  7225         iFocusedControl = EControlBarComponent;
       
  7226         SetListAndCtrlBarFocusL();
       
  7227         iMoveToFolderOngoing = EFalse;
       
  7228 		}
       
  7229 	SetMskL();
       
  7230 	}
       
  7231 
       
  7232 // ---------------------------------------------------------------------------
       
  7233 // MailboxSelectedL
       
  7234 // Mailbox selection callback. Function updates list when mailbox is changed
       
  7235 // ---------------------------------------------------------------------------
       
  7236 //
       
  7237 void CFSEmailUiMailListVisualiser::MailboxSelectedL( TFSMailMsgId aSelectedMailboxId )
       
  7238 	{
       
  7239     FUNC_LOG;
       
  7240     iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  7241     //Set touchmanager back to active
       
  7242     DisableMailList(EFalse);
       
  7243 	iAppUi.SetActiveMailboxL( aSelectedMailboxId );
       
  7244 	iMailListModelUpdater->Cancel();
       
  7245 	SafeDelete(iMailFolder);
       
  7246 	iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( iAppUi.GetActiveMailboxId(), iAppUi.GetActiveBoxInboxId() );
       
  7247 
       
  7248 	// Set initial sort criteria when folder has changed
       
  7249     iCurrentSortCriteria.iField = EFSMailSortByDate;
       
  7250     iCurrentSortCriteria.iOrder = EFSMailDescending;
       
  7251     // reload node state because in file sort mode this is disabled even when globally enabled
       
  7252     iNodesInUse = iAppUi.GetCRHandler()->TitleDividers();
       
  7253     SetSortButtonTextAndIconL();
       
  7254 
       
  7255     // Set folder name to the control bar button
       
  7256     HBufC* newFolderName = CreateFolderNameLC( iMailFolder );
       
  7257     iFolderListButton->SetTextL( *newFolderName );
       
  7258     CleanupStack::PopAndDestroy( newFolderName );
       
  7259 
       
  7260     // Set mailbox name and icons
       
  7261     SetMailboxNameToStatusPaneL();
       
  7262     SetBrandedListWatermarkL();
       
  7263     SetBrandedMailBoxIconL();
       
  7264 
       
  7265     // Update model
       
  7266     UpdateMailListModelL();
       
  7267     iMailList->RemoveAllL();
       
  7268     RefreshDeferred();
       
  7269 
       
  7270 	// Check sync icon timer and sync status
       
  7271     ConnectionIconHandling();
       
  7272 	iFocusedControl = EControlBarComponent;
       
  7273 	}
       
  7274 
       
  7275 // ---------------------------------------------------------------------------
       
  7276 // FolderButtonRect
       
  7277 // Getter for folder button rectangle. Folder popup needs to get this
       
  7278 // information when screen layout changes.
       
  7279 // ---------------------------------------------------------------------------
       
  7280 //
       
  7281 TRect CFSEmailUiMailListVisualiser::FolderButtonRect()
       
  7282     {
       
  7283     FUNC_LOG;
       
  7284     const TPoint& buttonPos = iFolderListButton->Pos().Target();
       
  7285     const TPoint& buttonSize = iFolderListButton->Size().Target();
       
  7286     TRect buttonRect( buttonPos, buttonSize.AsSize() );
       
  7287     return buttonRect;
       
  7288     }
       
  7289 
       
  7290 // ---------------------------------------------------------------------------
       
  7291 // SortOrderChangedL
       
  7292 // Sort order selection callback. Function updates list when sorting is changed
       
  7293 // ---------------------------------------------------------------------------
       
  7294 //
       
  7295 void CFSEmailUiMailListVisualiser::SortOrderChangedL(
       
  7296 	TFSMailSortField aSortField, TFSEmailUiCtrlBarResponse aResponse )
       
  7297 	{
       
  7298     FUNC_LOG;
       
  7299 	// Ignore if cancel selected
       
  7300 	switch( aResponse )
       
  7301 		{
       
  7302 		case EFSEmailUiCtrlBarResponseSwitchList:
       
  7303 			{
       
  7304 			iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  7305 		    iControlBarControl->SetFocusByIdL( iFolderListButtonId );
       
  7306 	   		iAppUi.ShowFolderListInPopupL( FolderId(), this, iFolderListButton );
       
  7307 			}
       
  7308             return;
       
  7309 		case EFSEmailUiCtrlBarResponseCancel:
       
  7310 		    iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  7311 		    SetMskL();
       
  7312 		    // <cmail> Touch
       
  7313             //Set touchmanager back to active
       
  7314             DisableMailList(EFalse);
       
  7315             return;
       
  7316 
       
  7317 		case EFSEmailUiCtrlBarResponseSelect:
       
  7318 		    iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  7319             //Set touchmanager back to active
       
  7320             DisableMailList(EFalse);
       
  7321             // </cmail>
       
  7322 		default:
       
  7323 			break;
       
  7324 		}
       
  7325 
       
  7326 	// Check is the selected sort field same as the previous one
       
  7327 	if( iCurrentSortCriteria.iField == aSortField )
       
  7328 		{
       
  7329 		// If same sort field selected, switch the sorting order
       
  7330 		if( iCurrentSortCriteria.iOrder == EFSMailAscending )
       
  7331 			{
       
  7332 			iCurrentSortCriteria.iOrder = EFSMailDescending;
       
  7333 			}
       
  7334 		else
       
  7335 			{
       
  7336 			iCurrentSortCriteria.iOrder = EFSMailAscending;
       
  7337 			}
       
  7338 		}
       
  7339 	else if ( aSortField == EFSMailSortBySubject ||
       
  7340 			  aSortField == EFSMailSortBySender ||
       
  7341 			  aSortField == EFSMailSortByUnread || // <cmail>
       
  7342 			  aSortField == EFSMailSortByRecipient )
       
  7343 		{
       
  7344 		iCurrentSortCriteria.iOrder = EFSMailAscending;
       
  7345 		}
       
  7346 	else
       
  7347 		{
       
  7348 		iCurrentSortCriteria.iOrder = EFSMailDescending;
       
  7349 		}
       
  7350 
       
  7351 	iCurrentSortCriteria.iField = aSortField;
       
  7352 	iModel->SetSortCriteria(iCurrentSortCriteria);
       
  7353 
       
  7354 	// rest of the code moved to TimerEventL ( iSortTimer part )
       
  7355 	// used also in DoHandleControlBarOpenL to prevent SortList reopening
       
  7356 	iSortState = ESortRequested; 
       
  7357 	iSortTimer->Start( KSortTimerDelay );	
       
  7358 	}
       
  7359 
       
  7360 // ---------------------------------------------------------------------------
       
  7361 // SortButtonRect
       
  7362 // Getter for sort button rectangle. Sort popup needs to get this
       
  7363 // information when screen layout changes.
       
  7364 // ---------------------------------------------------------------------------
       
  7365 //
       
  7366 TRect CFSEmailUiMailListVisualiser::SortButtonRect()
       
  7367     {
       
  7368     FUNC_LOG;
       
  7369     const TPoint& buttonPos = iSortButton->Pos().Target();
       
  7370     const TPoint& buttonSize = iSortButton->Size().Target();
       
  7371     TRect buttonRect( buttonPos, buttonSize.AsSize() );
       
  7372     return buttonRect;
       
  7373     }
       
  7374 
       
  7375 // ---------------------------------------------------------------------------
       
  7376 // OpenHighlightedMailL
       
  7377 // Function opens highlighted mail either to internal viewer or to mrui if
       
  7378 // message type is meeting
       
  7379 // ---------------------------------------------------------------------------
       
  7380 //
       
  7381 void CFSEmailUiMailListVisualiser::OpenHighlightedMailL()
       
  7382     {
       
  7383     FUNC_LOG;
       
  7384     OpenMailItemL( iMailList->FocusedItem() );
       
  7385     }
       
  7386 
       
  7387 // ---------------------------------------------------------------------------
       
  7388 // OpenHighlightedMailL
       
  7389 // Function opens given mail item either to internal viewer or to mrui if
       
  7390 // message type is meeting
       
  7391 // ---------------------------------------------------------------------------
       
  7392 //
       
  7393 void CFSEmailUiMailListVisualiser::OpenMailItemL( TFsTreeItemId aMailItem )
       
  7394 	{
       
  7395     FUNC_LOG;
       
  7396 	TInt idx = ModelIndexFromListId( aMailItem );
       
  7397 	if ( idx >= 0 )
       
  7398 	    {
       
  7399 	    CFSEmailUiMailListModelItem* item =
       
  7400 	        static_cast<CFSEmailUiMailListModelItem*>( Model()->Item(idx) );
       
  7401 	    if ( item && item->ModelItemType() == ETypeMailItem )
       
  7402 	        {
       
  7403 	        // First make sure that the highlighted message really exists in the store
       
  7404 	        // Get confirmed msg ptr
       
  7405 	        CFSMailMessage* confirmedMsgPtr(0);
       
  7406 	        confirmedMsgPtr = iAppUi.GetMailClient()->GetMessageByUidL(iAppUi.GetActiveMailboxId(),
       
  7407 	                iMailFolder->GetFolderId(), item->MessagePtr().GetMessageId(), EFSMsgDataEnvelope );
       
  7408 	        if ( confirmedMsgPtr )
       
  7409 	            {
       
  7410 	            iMailOpened = ETrue;
       
  7411 
       
  7412 	            ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
  7413 	            // Pointer confirmed, store Id and delete not needed anymore
       
  7414 	            TFSMailMsgId confirmedId = confirmedMsgPtr->GetMessageId();
       
  7415 	      		TBool isCalMessage = confirmedMsgPtr->IsFlagSet( EFSMsgFlag_CalendarMsg );
       
  7416 	      		TBool isReadMessage = confirmedMsgPtr->IsFlagSet( EFSMsgFlag_Read );
       
  7417 	            delete confirmedMsgPtr;
       
  7418 	            // Open to editor from drafts
       
  7419 	            if ( iMailFolder->GetFolderType() == EFSDraftsFolder )
       
  7420 	                {
       
  7421 	                if ( !isCalMessage ) // Open only normal messages for now
       
  7422 	                	{
       
  7423 		                TEditorLaunchParams params;
       
  7424 		                params.iMailboxId = iAppUi.GetActiveMailboxId();
       
  7425 		                params.iActivatedExternally = EFalse;
       
  7426 		                params.iMsgId = confirmedId;
       
  7427 		                params.iFolderId = iMailFolder->GetFolderId();
       
  7428 		                iAppUi.LaunchEditorL( KEditorCmdOpen, params );
       
  7429 	                	}
       
  7430 	                else
       
  7431 	               	 	{
       
  7432 	                	//Try to open to editor if support for that is needed
       
  7433 	                	}
       
  7434 	                }
       
  7435 	            else if ( iMailFolder->GetFolderType() == EFSOutbox )
       
  7436 	                {
       
  7437 	                TFsEmailUiUtility::ShowErrorNoteL( R_FREESTYLE_EMAIL_UI_OPEN_FROM_OUTBOX_NOTE, ETrue );
       
  7438 	                }
       
  7439 	            else
       
  7440 	                {
       
  7441                     THtmlViewerActivationData htmlData;
       
  7442                     htmlData.iActivationDataType = THtmlViewerActivationData::EMailMessage;
       
  7443                     htmlData.iMailBoxId = iAppUi.GetActiveMailbox()->GetId();
       
  7444                     htmlData.iFolderId = FolderId();
       
  7445                     htmlData.iMessageId = confirmedId;
       
  7446                     TPckgBuf<THtmlViewerActivationData> pckgData( htmlData );
       
  7447 
       
  7448                     // Change read status only if needed
       
  7449                     if ( !isReadMessage )
       
  7450                         {
       
  7451                         ChangeReadStatusOfHighlightedL( ETrue );
       
  7452                         }
       
  7453 
       
  7454                     // Opening viewer seems to take more time than other views,
       
  7455                     // so we do longer fade out in this case
       
  7456                     SetNextTransitionOutLong( ETrue );
       
  7457 
       
  7458                     iAppUi.EnterFsEmailViewL( HtmlViewerId, KHtmlViewerOpenNew, pckgData );
       
  7459 	                }
       
  7460 	            }
       
  7461 	        }
       
  7462 	    }
       
  7463 	}
       
  7464 
       
  7465 // ---------------------------------------------------------------------------
       
  7466 // From MFSEmailUiContactHandlerObserver
       
  7467 // The ownership of the CLS items in the contacts array is transferred to the
       
  7468 // observer, and they must be deleted by the observer.
       
  7469 // ---------------------------------------------------------------------------
       
  7470 //
       
  7471 void CFSEmailUiMailListVisualiser::OperationCompleteL(
       
  7472     TContactHandlerCmd /*aCmd*/, const RPointerArray<CFSEmailUiClsItem>& /*aContacts*/ )
       
  7473     {
       
  7474     FUNC_LOG;
       
  7475     }
       
  7476 
       
  7477 // ---------------------------------------------------------------------------
       
  7478 // From MFSEmailUiContactHandlerObserver
       
  7479 // Handles error in contact handler operation.
       
  7480 // ---------------------------------------------------------------------------
       
  7481 //
       
  7482 void CFSEmailUiMailListVisualiser::OperationErrorL( TContactHandlerCmd /*aCmd*/,
       
  7483     TInt /*aError*/ )
       
  7484     {
       
  7485     FUNC_LOG;
       
  7486     }
       
  7487 
       
  7488 // ---------------------------------------------------------------------------
       
  7489 // NotifyDateChangedL
       
  7490 // Called when CDateChangeTimer completes. This happens when either when date
       
  7491 // changes or when user alters the system time. Redraws the list to ensure
       
  7492 // that time stamp texts in emails and nodes are up-to-date.
       
  7493 // ---------------------------------------------------------------------------
       
  7494 //
       
  7495 void CFSEmailUiMailListVisualiser::NotifyDateChangedL()
       
  7496     {
       
  7497     FUNC_LOG;
       
  7498     iDateChanged = ETrue;
       
  7499     if ( iAppUi.IsForeground() )
       
  7500         {
       
  7501         HandleForegroundEventL(ETrue);
       
  7502         }
       
  7503     }
       
  7504 
       
  7505 // ---------------------------------------------------------------------------
       
  7506 // CreateFolderNameLC
       
  7507 // Creates folder name from folder ptr. Localised if standard folder.
       
  7508 // ---------------------------------------------------------------------------
       
  7509 //
       
  7510 HBufC* CFSEmailUiMailListVisualiser::CreateFolderNameLC( const CFSMailFolder* aFolder ) const
       
  7511 	{
       
  7512     FUNC_LOG;
       
  7513 	TInt resourceId(0);
       
  7514 	HBufC* ret(0);
       
  7515 	if ( !aFolder || aFolder->GetFolderId().IsNullId() )
       
  7516 		{
       
  7517 		// INBOX FOR NULL ID
       
  7518 		resourceId = R_FREESTYLE_EMAIL_UI_DROPDOWN_LIST_INBOX;
       
  7519 		}
       
  7520 	else
       
  7521 		{
       
  7522 		TInt folderType = aFolder->GetFolderType();
       
  7523 		switch ( folderType )
       
  7524 			{
       
  7525 			case EFSInbox:
       
  7526 				{
       
  7527 				resourceId = R_FREESTYLE_EMAIL_UI_DROPDOWN_LIST_INBOX;
       
  7528 				}
       
  7529 				break;
       
  7530 			case EFSOutbox:
       
  7531 				{
       
  7532 				resourceId = R_FREESTYLE_EMAIL_UI_DROPDOWN_LIST_OUTBOX;
       
  7533 				}
       
  7534 				break;
       
  7535 			case EFSDraftsFolder:
       
  7536 				{
       
  7537 				resourceId = R_FREESTYLE_EMAIL_UI_DROPDOWN_LIST_DRAFTS;
       
  7538 				}
       
  7539 				break;
       
  7540 			case EFSSentFolder:
       
  7541 				{
       
  7542 				resourceId = R_FREESTYLE_EMAIL_UI_DROPDOWN_LIST_SENT;
       
  7543 				}
       
  7544 				break;
       
  7545 			case EFSDeleted:
       
  7546 				{
       
  7547 				resourceId = R_FREESTYLE_EMAIL_UI_DROPDOWN_LIST_DELETED;
       
  7548 				}
       
  7549 				break;
       
  7550 			default:
       
  7551 				// Not a standard folder
       
  7552 				break;
       
  7553 			}
       
  7554 		}
       
  7555 	if ( resourceId )
       
  7556 		{
       
  7557 		ret = StringLoader::LoadLC( resourceId );
       
  7558 		}
       
  7559 	else
       
  7560 		{
       
  7561 		ret = aFolder->GetFolderName().AllocLC();
       
  7562 		}
       
  7563 	return ret;
       
  7564 	}
       
  7565 
       
  7566 // ---------------------------------------------------------------------------
       
  7567 // LaunchStylusPopupMenuL
       
  7568 // Function launches avkon stylus popup menu based on the selected message item/items
       
  7569 // ---------------------------------------------------------------------------
       
  7570 //
       
  7571 void CFSEmailUiMailListVisualiser::LaunchStylusPopupMenuL( const TPoint& aPoint )
       
  7572 	{
       
  7573 	// Irrelevant items for focused mail list item get dimmed at runtime
       
  7574 
       
  7575 	// Check mail list item's type
       
  7576 	CFSEmailUiMailListModelItem* item =
       
  7577 		static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( HighlightedIndex() ) );
       
  7578 	if ( item )
       
  7579 		{
       
  7580 		if ( item->ModelItemType() == ETypeMailItem )
       
  7581 			{
       
  7582 			// Add mark as read / unread options
       
  7583 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, !IsMarkAsUnreadAvailableL() );
       
  7584 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsRead, !IsMarkAsReadAvailableL() );
       
  7585 
       
  7586 			// Check support for object mail iten moving
       
  7587 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsMoveMessage,
       
  7588          !(iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaMoveToFolder )
       
  7589          && iMailFolder->SupportsMoveFromL( iMailFolder->GetFolderType() ) ) );
       
  7590 
       
  7591 			// Hide / show follow up
       
  7592 			TBool supportsFlag = TFsEmailUiUtility::IsFollowUpSupported( *iAppUi.GetActiveMailbox() );
       
  7593 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsFlag, !supportsFlag );
       
  7594 
       
  7595 			// Hide collapse / expand all
       
  7596 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsCollapseAll, ETrue );
       
  7597 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsExpandAll, ETrue );
       
  7598 			}
       
  7599 		else if ( item->ModelItemType() == ETypeSeparator )
       
  7600 			{
       
  7601 			// Hide mark as read / unread options
       
  7602 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, ETrue );
       
  7603 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsRead, ETrue );
       
  7604 
       
  7605 			// Hide move & follow up
       
  7606 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsMoveMessage, ETrue );
       
  7607 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsFlag, ETrue );
       
  7608 
       
  7609 			// Hide collapse / expand all when applicable
       
  7610 			if ( iNodesInUse == EListControlSeparatorDisabled || !iModel->Count() )
       
  7611 				{
       
  7612 				iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsCollapseAll, ETrue );
       
  7613 				iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsExpandAll, ETrue );
       
  7614 				}
       
  7615 			else
       
  7616 				{
       
  7617 				iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsCollapseAll, AllNodesCollapsed() );
       
  7618 				iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsExpandAll, AllNodesExpanded() );
       
  7619 				}
       
  7620 			}
       
  7621 		}
       
  7622 
       
  7623 	// Set the position for the popup
       
  7624 	TPoint point(aPoint.iX, aPoint.iY + 45);
       
  7625 	iStylusPopUpMenu->SetPosition( point, CAknStylusPopUpMenu::EPositionTypeRightBottom );
       
  7626 
       
  7627 	// Display the popup and set the flag to indicate that the menu was
       
  7628 	// launched.
       
  7629 	iStylusPopUpMenu->ShowMenu();
       
  7630 	iStylusPopUpMenuVisible = ETrue;
       
  7631 	}
       
  7632 
       
  7633 // ---------------------------------------------------------------------------
       
  7634 // CreateNewMsgL
       
  7635 // Launches editor.
       
  7636 // ---------------------------------------------------------------------------
       
  7637 //
       
  7638 void CFSEmailUiMailListVisualiser::CreateNewMsgL()
       
  7639 	{
       
  7640     FUNC_LOG;
       
  7641 	TEditorLaunchParams params;
       
  7642 	params.iMailboxId = iAppUi.GetActiveMailboxId();
       
  7643 	params.iActivatedExternally = EFalse;
       
  7644     iAppUi.LaunchEditorL( KEditorCmdCreateNew, params );
       
  7645 	}
       
  7646 
       
  7647 void CFSEmailUiMailListVisualiser::ReplyL( CFSMailMessage* aMsgPtr )
       
  7648 	{
       
  7649     FUNC_LOG;
       
  7650     // Replying not possible from drafts folder
       
  7651     if ( iMailFolder && iMailFolder->GetFolderType() != EFSDraftsFolder )
       
  7652         {
       
  7653         DoReplyForwardL( KEditorCmdReply, aMsgPtr );
       
  7654         }
       
  7655 	}
       
  7656 
       
  7657 void CFSEmailUiMailListVisualiser::ReplyAllL(  CFSMailMessage* aMsgPtr )
       
  7658 	{
       
  7659     FUNC_LOG;
       
  7660     // Replying all not possible from drafts folder
       
  7661     if ( iMailFolder && iMailFolder->GetFolderType() != EFSDraftsFolder )
       
  7662         {
       
  7663         DoReplyForwardL( KEditorCmdReplyAll, aMsgPtr );
       
  7664         }
       
  7665 	}
       
  7666 
       
  7667 void CFSEmailUiMailListVisualiser::ForwardL( CFSMailMessage* aMsgPtr )
       
  7668 	{
       
  7669     FUNC_LOG;
       
  7670     DoReplyForwardL( KEditorCmdForward, aMsgPtr );
       
  7671 	}
       
  7672 
       
  7673 // ---------------------------------------------------------------------------
       
  7674 // DoReplyForwardL
       
  7675 // Launches editor with either reply all forward command
       
  7676 // ---------------------------------------------------------------------------
       
  7677 //
       
  7678 void CFSEmailUiMailListVisualiser::DoReplyForwardL( TEditorLaunchMode aMode, CFSMailMessage* aMsgPtr )
       
  7679     {
       
  7680     FUNC_LOG;
       
  7681     // Reply, reply all, and forward commands are inavailable in the outbox
       
  7682     // <cmail>
       
  7683     if ( iModel->Count() && iMailFolder && iMailFolder->GetFolderType() != EFSOutbox )
       
  7684     // </cmail>
       
  7685         {
       
  7686         CFSMailMessage* messagePointer = aMsgPtr;
       
  7687     	if ( !messagePointer  )
       
  7688     		{
       
  7689     		RFsTreeItemIdList targetEntries;
       
  7690     		CleanupClosePushL( targetEntries );
       
  7691     		GetActionsTargetEntriesL( targetEntries );
       
  7692     		// action is possible only when there's exactly one marked or focused mail item
       
  7693     		if ( targetEntries.Count() == 1 )
       
  7694     			{
       
  7695     			messagePointer = &MsgPtrFromListIdL( targetEntries[0] );
       
  7696     			}
       
  7697     		CleanupStack::PopAndDestroy( &targetEntries );
       
  7698     		}
       
  7699     	if ( messagePointer )
       
  7700     		{
       
  7701             // Opening editor is slower than opening most other views.
       
  7702     		// Use longer transition effect to mask this.
       
  7703             SetNextTransitionOutLong( ETrue );
       
  7704 
       
  7705     		TEditorLaunchParams params;
       
  7706     		params.iMailboxId = iAppUi.GetActiveMailboxId();
       
  7707     		params.iActivatedExternally = EFalse;
       
  7708     		params.iMsgId = messagePointer->GetMessageId();
       
  7709     		iAppUi.LaunchEditorL( aMode, params );
       
  7710     		}
       
  7711         }
       
  7712     }
       
  7713 
       
  7714 // ---------------------------------------------------------------------------
       
  7715 // HandleMailBoxEventL
       
  7716 // Mailbox event handler, responds to events sent by the plugin.
       
  7717 // ---------------------------------------------------------------------------
       
  7718 //
       
  7719 void CFSEmailUiMailListVisualiser::HandleMailBoxEventL( TFSMailEvent aEvent,
       
  7720     TFSMailMsgId aMailboxId, TAny* aParam1, TAny* aParam2, TAny* aParam3 )
       
  7721     {
       
  7722     FUNC_LOG;
       
  7723 
       
  7724     // Complete any pending asynchronous redrawing before handling the event
       
  7725     // to make sure that all the arrays are in consistent state
       
  7726     CompletePendingRefresh();
       
  7727 
       
  7728     // Handle the event
       
  7729     if ( iFirstStartCompleted &&
       
  7730          aMailboxId == iAppUi.GetActiveMailboxId() ) // Safety, in list events that only concern active mailbox are handled
       
  7731         {
       
  7732 		if ( aEvent == TFSEventFoldersDeleted )
       
  7733             {
       
  7734 			// Check whether the current folder gets deleted
       
  7735 			// Change mail item icon or read status
       
  7736 			RArray<TFSMailMsgId>* removedEntries = static_cast<RArray<TFSMailMsgId>*>( aParam1 );
       
  7737 			if ( iMailFolder && removedEntries && removedEntries->Count() )
       
  7738 				{
       
  7739 				TFSMailMsgId currentFolderId = iMailFolder->GetFolderId();
       
  7740 				for ( TInt i = 0; i < removedEntries->Count(); i++ )
       
  7741 					{
       
  7742 					TFSMailMsgId entryId = (*removedEntries)[i];
       
  7743 					if ( entryId == currentFolderId )
       
  7744 						{
       
  7745 						// Current folder deleted, try to revert back to standard folder inbox.
       
  7746 						iMailListModelUpdater->Cancel();
       
  7747 						SafeDelete(iMailFolder);
       
  7748 						TFSMailMsgId inboxId = iAppUi.GetActiveMailbox()->GetStandardFolderId( EFSInbox );
       
  7749 						if ( !inboxId.IsNullId() )
       
  7750 						    {
       
  7751 						    iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, inboxId );
       
  7752 						    UpdateMailListModelL();
       
  7753 					        RefreshL();
       
  7754 							HBufC* newFolderName = CreateFolderNameLC( iMailFolder );
       
  7755 						    iFolderListButton->SetTextL( *newFolderName );
       
  7756 							CleanupStack::PopAndDestroy( newFolderName );
       
  7757 						    }
       
  7758 						else
       
  7759 							{
       
  7760 							// No standard folder inbox, go back to grid as a last option
       
  7761 							HandleCommandL( EAknSoftkeyBack );
       
  7762 							}
       
  7763 						break;
       
  7764 						}
       
  7765 					}
       
  7766 				}
       
  7767 			}
       
  7768 		else if ( aEvent == TFSEventMailboxRenamed )
       
  7769             {
       
  7770 			if ( iThisViewActive )
       
  7771 				{
       
  7772 				SetMailboxNameToStatusPaneL();
       
  7773 				}
       
  7774 			}
       
  7775 	 	else if ( (aEvent == TFSEventMailDeleted || aEvent == TFSEventMailDeletedFromViewer) && iMailFolder ) // <cmail> Added iMailFolder null safety check </cmail>
       
  7776 			{
       
  7777 			// Change mail item icon or read status
       
  7778 			RArray<TFSMailMsgId>* removedEntries = static_cast<RArray<TFSMailMsgId>*>(aParam1);
       
  7779 			if ( removedEntries && removedEntries->Count() )
       
  7780 				{
       
  7781 				TFSMailMsgId* parentFolderId = static_cast<TFSMailMsgId*>( aParam2 );
       
  7782 				TFSMailMsgId currentFolderId = iMailFolder->GetFolderId();
       
  7783 				if ( parentFolderId && ( *parentFolderId == currentFolderId ) )
       
  7784 					{
       
  7785 	 				// Refresh mailfolder to get correct actual data
       
  7786                     /*
       
  7787                     iMailListModelUpdater->Cancel();
       
  7788 					SafeDelete(iMailFolder);
       
  7789 					iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, currentFolderId );
       
  7790 					*/
       
  7791 					RemoveMsgItemsFromListIfFoundL( *removedEntries );
       
  7792 					}
       
  7793 				}
       
  7794 			}
       
  7795 		else if ( aEvent == TFSEventNewMail )
       
  7796 		    {
       
  7797 			// Switch to standardfolder inbox if we have null folderid.
       
  7798 			// This is usually the case with first time sync.
       
  7799 			if ( FolderId().IsNullId() )
       
  7800 				{
       
  7801 				// Refresh mailfolder to standard folder inbox in case of zero id
       
  7802                 iMailListModelUpdater->Cancel();
       
  7803 				SafeDelete(iMailFolder);
       
  7804 				TFSMailMsgId inboxId = iAppUi.GetActiveMailbox()->GetStandardFolderId( EFSInbox );
       
  7805 				if ( !inboxId.IsNullId() )
       
  7806 				    {
       
  7807 				    iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, inboxId );
       
  7808 				    // Check that mailfolder fetching succeeded
       
  7809 				    if ( iMailFolder )
       
  7810 				    	{
       
  7811 						HBufC* newFolderName = CreateFolderNameLC( iMailFolder );
       
  7812 					    iFolderListButton->SetTextL( *newFolderName );
       
  7813 						CleanupStack::PopAndDestroy( newFolderName );
       
  7814 				    	}
       
  7815 				    }
       
  7816 				}
       
  7817 			// Null pointer check is needed here because of special cases such as new mail
       
  7818 			// creation in POP/IMAP before first sync where folder does not exists
       
  7819 			if ( iMailFolder )
       
  7820 				{
       
  7821 	            RArray<TFSMailMsgId>* newMessages = static_cast< RArray<TFSMailMsgId>* >( aParam1 );
       
  7822 				TFSMailMsgId* parentFolderId = static_cast<TFSMailMsgId*>( aParam2 );
       
  7823 				TFSMailMsgId currentFolderId = iMailFolder->GetFolderId();
       
  7824 				// Update the mail list only if the event is related to the currently open folder
       
  7825 				if ( *parentFolderId == currentFolderId )
       
  7826 				    {
       
  7827 				    InsertNewMessagesL( *newMessages );
       
  7828 				    }
       
  7829 				}
       
  7830 		    }
       
  7831 		else if ( aEvent == TFSEventMailMoved && iMailFolder )	// Added iMailFolder null safety check
       
  7832 			{
       
  7833             // If message was moved FROM this folder, just remove the entry from the list.
       
  7834             // If message is moved TO this folder, update the list completely.
       
  7835             // Otherwise, the event does not have an influence on the current folder.
       
  7836 			RArray<TFSMailMsgId>* entries = static_cast< RArray<TFSMailMsgId>* >( aParam1 );
       
  7837 			TFSMailMsgId* toFolderId = static_cast<TFSMailMsgId*>( aParam2 );
       
  7838 			TFSMailMsgId* fromFolderId = static_cast<TFSMailMsgId*>( aParam3 );
       
  7839 			TFSMailMsgId currentFolderId = iMailFolder->GetFolderId();
       
  7840 
       
  7841             if ( toFolderId && ( currentFolderId == *toFolderId ) )
       
  7842                 {
       
  7843                 InsertNewMessagesL( *entries );
       
  7844                 }
       
  7845             else if ( fromFolderId && ( currentFolderId == *fromFolderId ) )
       
  7846                 {
       
  7847  	 			// Refresh mailfolder to get correct actual data
       
  7848                 /*
       
  7849                 iMailListModelUpdater->Cancel();
       
  7850                 SafeDelete(iMailFolder);
       
  7851 				iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, currentFolderId );
       
  7852 				*/
       
  7853 				RemoveMsgItemsFromListIfFoundL( *entries );
       
  7854                 }
       
  7855             else
       
  7856                 {
       
  7857                 // event is not related to the current folder => do nothing
       
  7858                 }
       
  7859 			}
       
  7860 		else if ( aEvent == TFSEventMailChanged && iMailFolder ) // Added iMailFolder null safety check
       
  7861 			{
       
  7862 			//if ( !iMailOpened ) // do not handle mail changed while viewer/editor is open. This may cause flickering
       
  7863 			    {
       
  7864     			// Change mail item icon or read status
       
  7865     			RArray<TFSMailMsgId>* entries = static_cast<RArray<TFSMailMsgId>*>( aParam1 );
       
  7866     			TFSMailMsgId* parentFolderId = static_cast<TFSMailMsgId*>( aParam2 );
       
  7867     			TFSMailMsgId currentFolderId = iMailFolder->GetFolderId();
       
  7868     			if ( *parentFolderId == currentFolderId )
       
  7869     				{
       
  7870      	 			// Refresh mailfolder to get correct actual data
       
  7871     				/*
       
  7872                     iMailListModelUpdater->Cancel();
       
  7873                     SafeDelete(iMailFolder);
       
  7874     				iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, currentFolderId );
       
  7875     				*/
       
  7876     				for ( TInt i=0 ; i<entries->Count() ; i++ )
       
  7877     					{
       
  7878     					TFSMailMsgId msgId = (*entries)[i];
       
  7879     					TInt idx = ItemIndexFromMessageId( msgId );
       
  7880     					if ( idx != KErrNotFound )
       
  7881     					    {
       
  7882     					    UpdateItemAtIndexL( idx );
       
  7883     					    }
       
  7884     					}
       
  7885     				}
       
  7886 			    }
       
  7887 			}
       
  7888    		else if ( aEvent == TFSEventMailboxSyncStateChanged )
       
  7889    			{
       
  7890 	  		TSSMailSyncState* newSyncState = static_cast<TSSMailSyncState*>( aParam1 );
       
  7891     		if ( newSyncState != 0 && *newSyncState != 0 )
       
  7892     			{
       
  7893 	    		switch ( *newSyncState )
       
  7894 	    			{
       
  7895 	    			case StartingSync:
       
  7896 	   			    {
       
  7897 	   			    //If sync was started by user, show the synchronisation indicator
       
  7898 	   			    if ( iManualMailBoxSync )
       
  7899 	   			        {
       
  7900 			   		ManualMailBoxSync(EFalse);
       
  7901 	   				}
       
  7902 		   		    }
       
  7903 				    break;
       
  7904 
       
  7905 	    			case SyncCancelled:
       
  7906 	    			    {
       
  7907 	    			    //If sync was started by user, show the synchronisation indicator
       
  7908 	    			    if ( iManualMailBoxSync )
       
  7909 	    			        {
       
  7910 	    			        ManualMailBoxSync(EFalse);
       
  7911 	    			        }
       
  7912 	    			    }
       
  7913 	    			    break;
       
  7914 
       
  7915 	    			}
       
  7916     			}
       
  7917 			}
       
  7918 		}
       
  7919 	}
       
  7920 
       
  7921 // ---------------------------------------------------------------------------
       
  7922 //
       
  7923 // ---------------------------------------------------------------------------
       
  7924 //
       
  7925 void CFSEmailUiMailListVisualiser::TreeListEventL( const TFsTreeListEvent aEvent,
       
  7926                                                    const TFsTreeItemId aId,
       
  7927                                                    const TPoint& /*aPoint*/ )
       
  7928 	{
       
  7929     FUNC_LOG;
       
  7930     switch( aEvent )
       
  7931         {
       
  7932         case EFsTreeListItemWillGetFocused:
       
  7933             {
       
  7934             if( aId != KFsTreeNoneID )
       
  7935                 {
       
  7936                 UpdatePreviewPaneTextIfNecessaryL( aId, EFalse );
       
  7937                 }
       
  7938             break;
       
  7939             }
       
  7940         case EFsTreeListItemTouchFocused:
       
  7941             {
       
  7942             break;
       
  7943             }
       
  7944         case EFsFocusVisibilityChange:
       
  7945             {
       
  7946             iAppUi.SetFocusVisibility( EFalse );
       
  7947             break;
       
  7948             }
       
  7949         default:
       
  7950             {
       
  7951             // Do not handle other events
       
  7952             break;
       
  7953             }
       
  7954 
       
  7955         }
       
  7956 	}
       
  7957 
       
  7958 // ---------------------------------------------------------------------------
       
  7959 // UpdateMailListSettingsL
       
  7960 // Function reads and updates mail list specific settings from the cen rep
       
  7961 // ---------------------------------------------------------------------------
       
  7962 //
       
  7963 void CFSEmailUiMailListVisualiser::UpdateMailListSettingsL()
       
  7964 	{
       
  7965     FUNC_LOG;
       
  7966 	if ( iAppUi.GetCRHandler() )
       
  7967 		{
       
  7968 		iNodesInUse = iAppUi.GetCRHandler()->TitleDividers();
       
  7969 		TInt lineValue = iAppUi.GetCRHandler()->MessageListLayout();
       
  7970 		TInt bodyPreviewValue = iAppUi.GetCRHandler()->BodyPreview();
       
  7971 		if ( lineValue == 1 ) // 1-line layouts
       
  7972 			{
       
  7973 			if ( bodyPreviewValue == 0 )
       
  7974 				{
       
  7975 				iListMode = EListControlTypeSingleLinePreviewOff;
       
  7976 				}
       
  7977 			else
       
  7978 				{
       
  7979 				iListMode = EListControlTypeSingleLinePreviewOn;
       
  7980 				}
       
  7981 			}
       
  7982 		else //
       
  7983 			{
       
  7984 			if ( bodyPreviewValue == 0 )
       
  7985 				{
       
  7986 				iListMode = EListControlTypeDoubleLinePreviewOff;
       
  7987 				}
       
  7988 			else
       
  7989 				{
       
  7990 				iListMode = EListControlTypeDoubleLinePreviewOn;
       
  7991 				}
       
  7992 			}
       
  7993 		}
       
  7994 	else
       
  7995 		{
       
  7996 		iNodesInUse = EListControlSeparatorDisabled;
       
  7997 		iListMode = EListControlTypeDoubleLinePreviewOff;
       
  7998 		}
       
  7999 	}
       
  8000 
       
  8001 void CFSEmailUiMailListVisualiser::UpdateMailListTimeDateSettings()
       
  8002 	{
       
  8003     FUNC_LOG;
       
  8004     TLocale currentLocaleSettings;
       
  8005 	iDateFormats.iTimeFormat = currentLocaleSettings.TimeFormat();
       
  8006 	iDateFormats.iDateFormat = currentLocaleSettings.DateFormat();
       
  8007 	iDateFormats.iAmPmPosition = currentLocaleSettings.AmPmSymbolPosition();
       
  8008 	// Second time separartor
       
  8009 	iDateFormats.iTimeSeparator = currentLocaleSettings.TimeSeparator( 1 );
       
  8010 	// Second date separartor
       
  8011 	iDateFormats.iDateSeparator = currentLocaleSettings.DateSeparator( 1 );
       
  8012 	}
       
  8013 
       
  8014 STimeDateFormats CFSEmailUiMailListVisualiser::MailListTimeDateSettings()
       
  8015 	{
       
  8016     FUNC_LOG;
       
  8017 	return iDateFormats;
       
  8018 	}
       
  8019 
       
  8020 
       
  8021 void CFSEmailUiMailListVisualiser::SetMailboxNameToStatusPaneL()
       
  8022 	{
       
  8023     FUNC_LOG;
       
  8024     iAppUi.SetActiveMailboxNameToStatusPaneL();
       
  8025 	}
       
  8026 
       
  8027 void CFSEmailUiMailListVisualiser::SetBrandedMailBoxIconL()
       
  8028 	{
       
  8029     FUNC_LOG;
       
  8030 	// Get and draw branded mailbox icon
       
  8031 	MFSMailBrandManager& brandManager = iAppUi.GetMailClient()->GetBrandManagerL();
       
  8032 	CGulIcon* mailBoxIcon(0);
       
  8033 	TRAPD( err, mailBoxIcon = brandManager.GetGraphicL( EFSMailboxIcon,  iAppUi.GetActiveMailboxId() ) );
       
  8034 	if ( err == KErrNone && mailBoxIcon )
       
  8035 		{
       
  8036 		CleanupStack::PushL( mailBoxIcon );
       
  8037         //<cmail>
       
  8038 		TInt iconSize( iAppUi.LayoutHandler()->GetControlBarMailboxIconRect().Width() );
       
  8039 		TSize defaultIconSize ( iconSize, iconSize );
       
  8040         //</cmail>
       
  8041     	AknIconUtils::SetSize(mailBoxIcon->Bitmap(), defaultIconSize);
       
  8042 	    AknIconUtils::SetSize(mailBoxIcon->Mask(), defaultIconSize);
       
  8043 		// Create texture into TextureManager, If not already existing
       
  8044 	    iAppUi.FsTextureManager()->CreateBrandedMailboxTexture( mailBoxIcon,
       
  8045 	    		                                                iAppUi.GetActiveMailboxId().PluginId(),
       
  8046 	    		                                                iAppUi.GetActiveMailboxId().Id(),
       
  8047 	    		                                                defaultIconSize );
       
  8048 	    // Get branded mailbox icon
       
  8049 	    iMailBoxIconTexture = &iAppUi.FsTextureManager()->TextureByMailboxIdL( iAppUi.GetActiveMailboxId().PluginId(),
       
  8050 	    		                                                               iAppUi.GetActiveMailboxId().Id(),
       
  8051 	    		                                                               defaultIconSize );
       
  8052 		iFolderListButton->SetIconL( *iMailBoxIconTexture );
       
  8053 		CleanupStack::PopAndDestroy( mailBoxIcon );
       
  8054 		}
       
  8055 	else
       
  8056 		{
       
  8057 		iFolderListButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( EListControlBarMailboxDefaultIcon ) );
       
  8058 		}
       
  8059 	}
       
  8060 
       
  8061 
       
  8062 void CFSEmailUiMailListVisualiser::SetBrandedListWatermarkL()
       
  8063 	{
       
  8064     FUNC_LOG;
       
  8065 	MFSMailBrandManager& brandManager = iAppUi.GetMailClient()->GetBrandManagerL();
       
  8066 	CGulIcon* mailBoxWatermarkIcon(0);
       
  8067 	TRAPD( err, mailBoxWatermarkIcon = brandManager.GetGraphicL( EFSWatermark,  iAppUi.GetActiveMailboxId() ) );
       
  8068 	if ( err == KErrNone && mailBoxWatermarkIcon )
       
  8069 		{
       
  8070 		CleanupStack::PushL( mailBoxWatermarkIcon );
       
  8071 		TRect mainPaneRect;
       
  8072 	 	AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
  8073 		TInt xPos = mainPaneRect.iBr.iX/100*40; // 40% of main pane width
       
  8074 		TInt yPos = mainPaneRect.iBr.iY/100*40; // 40% of main pane height
       
  8075 	    TSize defaultWaterMarkSize(xPos,yPos);
       
  8076     	AknIconUtils::SetSize(mailBoxWatermarkIcon->Bitmap(), defaultWaterMarkSize);
       
  8077 	    AknIconUtils::SetSize(mailBoxWatermarkIcon->Mask(), defaultWaterMarkSize);
       
  8078 		if ( !iMailBoxWatermarkTexture )
       
  8079 			{
       
  8080 			// iMailBoxWatermarkTexture = CAlfTexture::NewL( *iEnv, Id() ); // DOLATER - Replaced by line below, creates blank texture until UploadL's replaced by something
       
  8081 			iMailBoxWatermarkTexture = &CAlfStatic::Env().TextureManager().BlankTexture();
       
  8082 			}
       
  8083 		// DOLATER - Gone from Alfred, needs to be replaced with something
       
  8084 		//iMailBoxWatermarkTexture->UploadL( *mailBoxWatermarkIcon->Bitmap(), mailBoxWatermarkIcon->Mask() );
       
  8085 		CleanupStack::PopAndDestroy( mailBoxWatermarkIcon );
       
  8086 		TPoint watermarkPosition( mainPaneRect.iBr.iX-xPos-20, mainPaneRect.iBr.iY-yPos-20  );
       
  8087    		iMailTreeListVisualizer->SetWatermarkPos( watermarkPosition );
       
  8088 		iMailTreeListVisualizer->SetWatermarkSize( defaultWaterMarkSize );
       
  8089 		iMailTreeListVisualizer->SetWatermarkOpacity( 0.3 );
       
  8090 		iMailTreeListVisualizer->SetWatermarkL( iMailBoxWatermarkTexture );
       
  8091 		}
       
  8092 	else
       
  8093 		{
       
  8094 		// Not found, hide watermark
       
  8095 		iMailTreeListVisualizer->SetWatermarkOpacity( 0 );
       
  8096 		}
       
  8097 	}
       
  8098 
       
  8099 TFsTreeItemId CFSEmailUiMailListVisualiser::ParentNode( TFsTreeItemId aItemId ) const
       
  8100     {
       
  8101     FUNC_LOG;
       
  8102 	if ( iNodesInUse )
       
  8103 		{
       
  8104 		TFsTreeItemId parentNodeId = iMailList->Parent( aItemId );
       
  8105 		if ( iMailList->IsNode( parentNodeId ) )
       
  8106 			{
       
  8107 			return parentNodeId;
       
  8108 			}
       
  8109 		}
       
  8110 	return KErrNotFound;
       
  8111     }
       
  8112 
       
  8113 TBool CFSEmailUiMailListVisualiser::DoScrollMarkUnmarkL()
       
  8114     {
       
  8115     FUNC_LOG;
       
  8116     TBool ret = EFalse;
       
  8117 
       
  8118     if ( !iMarkingMode )
       
  8119         {
       
  8120         EnterMarkingModeL();   
       
  8121         }
       
  8122 
       
  8123     // <cmail>
       
  8124     if ( iFocusedControl == EMailListComponent && iModel->Count() )
       
  8125     // </cmail>
       
  8126         {
       
  8127 		CFSEmailUiMailListModelItem* item =
       
  8128 			static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( HighlightedIndex() ) );
       
  8129 
       
  8130 		if ( item && item->ModelItemType() == ETypeMailItem )  // Separators are not markable
       
  8131 		    {
       
  8132 			if ( !iListMarkItemsState )
       
  8133 				{
       
  8134        			iMailList->MarkItemL( iMailList->FocusedItem(), EFalse );
       
  8135 				}
       
  8136 			else
       
  8137 				{
       
  8138        			iMailList->MarkItemL( iMailList->FocusedItem(), ETrue );
       
  8139 				}
       
  8140 			ret = ETrue;
       
  8141            	}
       
  8142         }
       
  8143 
       
  8144     return ret;
       
  8145     }
       
  8146 
       
  8147 // Mark / unmark all items under current separator
       
  8148 void CFSEmailUiMailListVisualiser::MarkItemsUnderSeparatorL( TBool aMarked, TInt aSeparatorId )
       
  8149 	{
       
  8150 	FUNC_LOG;
       
  8151 
       
  8152 	if ( iTreeItemArray.Count() )
       
  8153 		{
       
  8154 		// Find all items under wanted separator.
       
  8155 		for ( TInt i = aSeparatorId + 1; i < iTreeItemArray.Count(); i++ )
       
  8156 			{
       
  8157 			CFSEmailUiMailListModelItem* item =
       
  8158 						static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( i ) );
       
  8159 
       
  8160 			// Mark / unmark mail items.
       
  8161 			if ( item &&
       
  8162 				 item->ModelItemType() == ETypeMailItem &&
       
  8163 				 !iMailList->IsNode( iTreeItemArray[i].iListItemId ) )
       
  8164 				{
       
  8165 				iMailList->MarkItemL( iTreeItemArray[i].iListItemId, aMarked );
       
  8166 				}
       
  8167 			else
       
  8168 				{
       
  8169 				// Stop iteration since another iterator was reached.
       
  8170 				break;
       
  8171 				}
       
  8172 			}
       
  8173 		}
       
  8174 	}
       
  8175 
       
  8176 // Check if all items under current separator are marked
       
  8177 TBool CFSEmailUiMailListVisualiser::AreAllItemsMarkedUnderSeparatorL( TInt aSeparatorId )
       
  8178     {
       
  8179     FUNC_LOG;
       
  8180 
       
  8181     TBool ret(ETrue);
       
  8182     
       
  8183     if ( iTreeItemArray.Count() )
       
  8184         {
       
  8185         // Find all items under wanted separator.
       
  8186         for ( TInt i = aSeparatorId + 1; i < iTreeItemArray.Count(); i++ )
       
  8187             {
       
  8188             CFSEmailUiMailListModelItem* item =
       
  8189                         static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( i ) );
       
  8190 
       
  8191             // Mark / unmark mail items.
       
  8192             if ( item &&
       
  8193                  item->ModelItemType() == ETypeMailItem &&
       
  8194                  !iMailList->IsNode( iTreeItemArray[i].iListItemId ) )
       
  8195                 {
       
  8196                 if ( !iMailList->IsMarked( iTreeItemArray[i].iListItemId ))
       
  8197                     {
       
  8198                     // Att least one unmarked item found
       
  8199                     ret = EFalse;
       
  8200                     break;
       
  8201                     }
       
  8202                 }
       
  8203             else
       
  8204                 {
       
  8205                 // Stop iteration since another iterator was reached.
       
  8206                 break;
       
  8207                 }
       
  8208             }
       
  8209         }
       
  8210     return ret;
       
  8211     }
       
  8212 
       
  8213 // Navigation functions, used mainly from viewer
       
  8214 TBool CFSEmailUiMailListVisualiser::IsNextMsgAvailable( TFSMailMsgId aCurrentMsgId,
       
  8215 														TFSMailMsgId& aFoundNextMsgId,
       
  8216 														TFSMailMsgId& aFoundNextMsgFolder ) const
       
  8217 	{
       
  8218     FUNC_LOG;
       
  8219 	TBool ret(EFalse);
       
  8220 	TInt curIdx = ItemIndexFromMessageId( aCurrentMsgId );
       
  8221 	if ( curIdx >= 0 )
       
  8222 	    {
       
  8223 	    TInt nextIdx = NextMessageIndex(curIdx);
       
  8224 	    if ( nextIdx >= 0 )
       
  8225 	        {
       
  8226 	        ret = ETrue;
       
  8227 	        aFoundNextMsgId = MsgIdFromIndex(nextIdx);
       
  8228 	        aFoundNextMsgFolder = iMailFolder->GetFolderId();
       
  8229 	        }
       
  8230 	    }
       
  8231 
       
  8232 	return ret;
       
  8233 	}
       
  8234 
       
  8235 TBool CFSEmailUiMailListVisualiser::IsPreviousMsgAvailable( TFSMailMsgId aCurrentMsgId,
       
  8236 															TFSMailMsgId& aFoundPreviousMsgId,
       
  8237 															TFSMailMsgId& aFoundPrevMsgFolder ) const
       
  8238 	{
       
  8239     FUNC_LOG;
       
  8240 	TBool ret(EFalse);
       
  8241 	TInt curIdx = ItemIndexFromMessageId( aCurrentMsgId );
       
  8242 	if ( curIdx >= 0 )
       
  8243 	    {
       
  8244 	    TInt prevIdx = PreviousMessageIndex(curIdx);
       
  8245 	    if ( prevIdx >= 0 )
       
  8246 	        {
       
  8247 	        ret = ETrue;
       
  8248 	        aFoundPreviousMsgId = MsgIdFromIndex(prevIdx);
       
  8249 	        aFoundPrevMsgFolder = iMailFolder->GetFolderId();
       
  8250 	        }
       
  8251 	    }
       
  8252 
       
  8253 	return ret;
       
  8254 	}
       
  8255 
       
  8256 TInt CFSEmailUiMailListVisualiser::MoveToNextMsgL( TFSMailMsgId aCurrentMsgId, TFSMailMsgId& aFoundNextMsgId )
       
  8257 	{
       
  8258     FUNC_LOG;
       
  8259 	TInt ret(KErrNotFound);
       
  8260 
       
  8261 	TInt curIdx = ItemIndexFromMessageId( aCurrentMsgId );
       
  8262 	TInt nextIdx = NextMessageIndex( curIdx );
       
  8263 
       
  8264 	if ( curIdx >= 0 && nextIdx >= 0 )
       
  8265 	    {
       
  8266 	    // Focus the new message
       
  8267 	    // <cmail>
       
  8268 	    iMailTreeListVisualizer->SetFocusedItemL( iTreeItemArray[nextIdx].iListItemId, EFalse );
       
  8269 	    // </cmail>
       
  8270 	    ChangeReadStatusOfHighlightedL( ETrue );
       
  8271 
       
  8272         aFoundNextMsgId = MsgIdFromIndex( nextIdx );
       
  8273 	    ret = KErrNone;
       
  8274 	    }
       
  8275 	if ( ret == KErrNone )
       
  8276 		{
       
  8277 		OpenHighlightedMailL();
       
  8278 		}
       
  8279 	return ret;
       
  8280 	}
       
  8281 
       
  8282 TInt CFSEmailUiMailListVisualiser::MoveToPreviousMsgL( TFSMailMsgId aCurrentMsgId, TFSMailMsgId& aFoundPreviousMsgId )
       
  8283 	{
       
  8284     FUNC_LOG;
       
  8285 	TInt ret(KErrNotFound);
       
  8286 
       
  8287 	TInt curIdx = ItemIndexFromMessageId( aCurrentMsgId );
       
  8288 	TInt prevIdx = PreviousMessageIndex( curIdx );
       
  8289 
       
  8290 	if ( curIdx >= 0 && prevIdx >= 0 )
       
  8291 	    {
       
  8292 	    // Focus the new message
       
  8293 	    // <cmail>
       
  8294 	    iMailTreeListVisualizer->SetFocusedItemL( iTreeItemArray[prevIdx].iListItemId, EFalse );
       
  8295 	    // </cmail>
       
  8296 	    ChangeReadStatusOfHighlightedL( ETrue );
       
  8297         aFoundPreviousMsgId = MsgIdFromIndex( prevIdx );
       
  8298 	    ret = KErrNone;
       
  8299 	    }
       
  8300 
       
  8301 	if ( ret == KErrNone )
       
  8302 		{
       
  8303 		OpenHighlightedMailL();
       
  8304 		}
       
  8305 	return ret;
       
  8306 	}
       
  8307 
       
  8308 TInt CFSEmailUiMailListVisualiser::MoveToPreviousMsgAfterDeleteL( TFSMailMsgId aFoundPreviousMsgId )
       
  8309 	{
       
  8310 	FUNC_LOG;
       
  8311 	TInt ret(KErrNotFound);
       
  8312 
       
  8313 	TInt idx = ItemIndexFromMessageId( aFoundPreviousMsgId );
       
  8314 	if ( idx >= 0 )
       
  8315 		{
       
  8316 		// Focus the previous message
       
  8317 		iMailTreeListVisualizer->SetFocusedItemL( iTreeItemArray[idx].iListItemId, EFalse );
       
  8318 		ChangeReadStatusOfHighlightedL( ETrue );
       
  8319 		ret = KErrNone;
       
  8320 		}
       
  8321 
       
  8322 	if ( ret == KErrNone )
       
  8323 		{
       
  8324 		OpenHighlightedMailL();
       
  8325 		}
       
  8326 
       
  8327 	return ret;
       
  8328 	}
       
  8329 
       
  8330 void CFSEmailUiMailListVisualiser::ManualMailBoxSync( TBool aManualMailBoxSync )
       
  8331 	{
       
  8332     FUNC_LOG;
       
  8333 	iManualMailBoxSync = aManualMailBoxSync;
       
  8334 	}
       
  8335 
       
  8336 TBool CFSEmailUiMailListVisualiser::GetLatestSyncState()
       
  8337 	{
       
  8338     FUNC_LOG;
       
  8339 	CFSMailBox* activeMailbox = iAppUi.GetActiveMailbox();
       
  8340 
       
  8341     TBool ret = EFalse;
       
  8342 
       
  8343     if ( activeMailbox )
       
  8344         {
       
  8345     	TSSMailSyncState latestSyncstate = activeMailbox->CurrentSyncState();
       
  8346     	if(latestSyncstate == InboxSyncing ||
       
  8347     	   latestSyncstate == StartingSync ||
       
  8348     	   latestSyncstate == EmailSyncing ||
       
  8349     	   latestSyncstate == OutboxSyncing ||
       
  8350     	   latestSyncstate == SentItemsSyncing ||
       
  8351     	   latestSyncstate == DraftsSyncing ||
       
  8352     	   latestSyncstate == CalendarSyncing ||
       
  8353     	   latestSyncstate == ContactsSyncing ||
       
  8354     	   latestSyncstate == TasksSyncing ||
       
  8355     	   latestSyncstate == NotesSyncing ||
       
  8356     	   latestSyncstate == FilesSyncing ||
       
  8357     	   latestSyncstate == DataSyncStarting )
       
  8358     		{
       
  8359     		ret = ETrue;
       
  8360     		}
       
  8361         }
       
  8362 
       
  8363 	return ret;
       
  8364 	}
       
  8365 
       
  8366 void CFSEmailUiMailListVisualiser::ConnectionIconHandling()
       
  8367     {
       
  8368     FUNC_LOG;
       
  8369     iAppUi.UpdateTitlePaneConnectionStatus();
       
  8370     }
       
  8371 
       
  8372 void CFSEmailUiMailListVisualiser::SetListAndCtrlBarFocusL()
       
  8373     {
       
  8374     FUNC_LOG;
       
  8375     if ( iFocusedControl == EMailListComponent )
       
  8376         {
       
  8377         iMailList->SetFocusedL( ETrue );
       
  8378         iControlBarControl->SetFocusL( EFalse );
       
  8379         }
       
  8380     else
       
  8381         {
       
  8382         if( iStylusPopUpMenuVisible )
       
  8383         	{
       
  8384         	return;
       
  8385         	}
       
  8386 
       
  8387         iMailList->SetFocusedL( EFalse );
       
  8388         TInt focusedBtnId = KErrNotFound;
       
  8389         MFsControlButtonInterface* focusedBtn = iControlBarControl->GetFocusedButton();
       
  8390         if ( focusedBtn )
       
  8391             {
       
  8392             focusedBtnId = focusedBtn->Id();
       
  8393             }
       
  8394         iControlBarControl->SetFocusL( ETrue );
       
  8395         if ( focusedBtnId != KErrNotFound )
       
  8396             {
       
  8397             iControlBarControl->SetFocusByIdL( focusedBtnId );
       
  8398             }
       
  8399         iControlBarControl->MakeSelectorVisible( IsFocusShown() );
       
  8400         }
       
  8401     }
       
  8402 
       
  8403 void CFSEmailUiMailListVisualiser::GetParentLayoutsL( RPointerArray<CAlfVisual>& aLayoutArray ) const
       
  8404     {
       
  8405     aLayoutArray.AppendL( iScreenAnchorLayout );
       
  8406     aLayoutArray.AppendL( iControlBarControl->Visual() );
       
  8407     }
       
  8408 
       
  8409 // hide or show CAlfVisuals ( used for activation or deactivation )
       
  8410 void CFSEmailUiMailListVisualiser::FadeOut(TBool aDirectionOut)
       
  8411 	{
       
  8412     FUNC_LOG;
       
  8413 	TAlfTimedValue timedValue( 0, 0 );
       
  8414 	if ( !aDirectionOut )
       
  8415         {
       
  8416 		timedValue.SetTarget( 1, 0 );
       
  8417 		}
       
  8418 	if ( iScreenAnchorLayout != NULL )
       
  8419 		{
       
  8420 	    iScreenAnchorLayout->SetOpacity( timedValue );
       
  8421 		}
       
  8422 	if (iControlBarControl && iControlBarControl->Visual() != NULL )
       
  8423         {
       
  8424 	    iControlBarControl->Visual()->SetOpacity( timedValue );
       
  8425         }  
       
  8426 	}
       
  8427 
       
  8428 // Sets aActiveMailboxId and aActiveFolderId from iMailFolder if available
       
  8429 TInt CFSEmailUiMailListVisualiser::GetActiveFolderId(TFSMailMsgId& aActiveMailboxId, TFSMailMsgId& aActiveFolderId) const
       
  8430     {
       
  8431     if (iMailFolder != NULL)
       
  8432         {
       
  8433         aActiveMailboxId = iMailFolder->GetMailBoxId();
       
  8434         aActiveFolderId = iMailFolder->GetFolderId();
       
  8435         return KErrNone;
       
  8436         }
       
  8437     else
       
  8438         {
       
  8439          return KErrNotFound;
       
  8440         }
       
  8441     }
       
  8442 
       
  8443 void CFSEmailUiMailListVisualiser::CreateExtensionL()
       
  8444     {
       
  8445     CFSMailBox* box = iAppUi.GetActiveMailbox();
       
  8446     CEmailExtension* ext=NULL;
       
  8447     if (box)
       
  8448         {
       
  8449         ext = box->ExtensionL( KEmailMailboxStateExtensionUid );
       
  8450         }
       
  8451     if (ext)
       
  8452         {
       
  8453         iExtension = reinterpret_cast<CMailboxStateExtension*>( ext );
       
  8454         iExtension->SetStateDataProvider( this );
       
  8455         }
       
  8456     }
       
  8457 
       
  8458 TBool CFSEmailUiMailListVisualiser::CheckAutoSyncSettingL()
       
  8459     {
       
  8460     CEmailExtension* ext=NULL;
       
  8461     TBool manualSync = EFalse;
       
  8462     CFSMailBox* box = iAppUi.GetActiveMailbox();
       
  8463     if (box)
       
  8464         {
       
  8465         ext = box->ExtensionL( KEmailSettingExtensionUid );
       
  8466         if (ext)
       
  8467             {
       
  8468             CEmailSettingsExtension* extension = reinterpret_cast<CEmailSettingsExtension*>( ext );
       
  8469             extension->SetMailBoxId(box->GetId());
       
  8470             manualSync = extension->IsSetL(EmailSyncInterval);
       
  8471             box->ReleaseExtension(extension);
       
  8472             }
       
  8473         }
       
  8474     return manualSync;
       
  8475     }
       
  8476 
       
  8477 //////////////////////////////////////////////////////////////////
       
  8478 // Class implementation CMailListUpdater
       
  8479 ///////////////////////////////////////////////////////////////////
       
  8480 
       
  8481 
       
  8482 // -----------------------------------------------------------------------------
       
  8483 // CMailListUpdater::NewL
       
  8484 // NewL function. Returns timer object.
       
  8485 // -----------------------------------------------------------------------------
       
  8486 //
       
  8487 CMailListUpdater* CMailListUpdater::NewL( CFSEmailUiMailListVisualiser* aMailListVisualiser )
       
  8488     {
       
  8489     FUNC_LOG;
       
  8490     CMailListUpdater* self = new (ELeave) CMailListUpdater( aMailListVisualiser );
       
  8491     CleanupStack::PushL( self );
       
  8492     self->ConstructL();
       
  8493     CleanupStack::Pop( self );
       
  8494     return self;
       
  8495     }
       
  8496 
       
  8497 // -----------------------------------------------------------------------------
       
  8498 // CMailListUpdater::~CMailListUpdater
       
  8499 // D'tor
       
  8500 // -----------------------------------------------------------------------------
       
  8501 //
       
  8502 CMailListUpdater::~CMailListUpdater()
       
  8503     {
       
  8504     FUNC_LOG;
       
  8505     Cancel();
       
  8506     }
       
  8507 
       
  8508 // -----------------------------------------------------------------------------
       
  8509 // CMailListUpdater::CMailListUpdater
       
  8510 // C'tor
       
  8511 // -----------------------------------------------------------------------------
       
  8512 //
       
  8513 CMailListUpdater::CMailListUpdater( CFSEmailUiMailListVisualiser* aMailListVisualiser  )
       
  8514 	: CTimer( EPriorityStandard ),
       
  8515 	iMailListVisualiser( aMailListVisualiser )
       
  8516     {
       
  8517     FUNC_LOG;
       
  8518     CActiveScheduler::Add( this );
       
  8519     }
       
  8520 
       
  8521 // -----------------------------------------------------------------------------
       
  8522 // CMailListUpdater::RunL
       
  8523 // Timer trigger function.
       
  8524 // -----------------------------------------------------------------------------
       
  8525 //
       
  8526 void CMailListUpdater::RunL()
       
  8527     {
       
  8528     FUNC_LOG;
       
  8529     if ( iIsSorting )
       
  8530     	{
       
  8531 	   	iMailListVisualiser->UpdateMailListModelL();
       
  8532 	   	iMailListVisualiser->RefreshL();
       
  8533 		// Sorting is completed
       
  8534 		iIsSorting = EFalse;
       
  8535 	   	// Dismiss wait note.
       
  8536 	   	if ( iWaitNote )
       
  8537 	   		{
       
  8538 		   	iWaitNote->ProcessFinishedL();
       
  8539 	   		}
       
  8540     	}
       
  8541     else
       
  8542     	{
       
  8543 		// Store the list of marked items. The markings are erased when the list
       
  8544 		// is repopulated and, hence, the markings need to be reset after the
       
  8545 		// refreshing is done. The marked items must be identified by the message
       
  8546 		// ID rather than with the list ID because refreshing may change the list IDs.
       
  8547 		RArray<TFSMailMsgId> markedMessages;
       
  8548 		CleanupClosePushL( markedMessages );
       
  8549 		iMailListVisualiser->GetMarkedMessagesL( markedMessages );
       
  8550 
       
  8551 		// Store the message ID of the focused item
       
  8552 	    TFSMailMsgId msgIdBeforeRefresh;
       
  8553 	   	TFsTreeItemId firstVisibleListId = iMailListVisualiser->iMailTreeListVisualizer->FirstVisibleItem();
       
  8554 	    TInt modelFirstIndexBeforeUpdate = iMailListVisualiser->ModelIndexFromListId( firstVisibleListId );
       
  8555 	  	TInt highlightedIndexBeforeUpdate = iMailListVisualiser->HighlightedIndex();
       
  8556 	    TInt modelCountBeforeUpdate = iMailListVisualiser->iModel->Count();
       
  8557 	    if ( iMailListVisualiser->iModel->Count() )
       
  8558 	    	{
       
  8559 	  		CFSEmailUiMailListModelItem* item =
       
  8560 				static_cast<CFSEmailUiMailListModelItem*>(iMailListVisualiser->iModel->Item( highlightedIndexBeforeUpdate ) );
       
  8561 			if ( item && item->ModelItemType() == ETypeMailItem )
       
  8562 				{
       
  8563 			    msgIdBeforeRefresh = item->MessagePtr().GetMessageId();
       
  8564 				}
       
  8565 	    	}
       
  8566 
       
  8567 	   	iMailListVisualiser->UpdateMailListModelL();
       
  8568 	   	iMailListVisualiser->RefreshL( &msgIdBeforeRefresh );
       
  8569 
       
  8570 		// Focus is set to last focused item. After this, try to keep the same first item that previous
       
  8571 		// Check how many messages have been added
       
  8572 	  	TInt modelIndexDifference = highlightedIndexBeforeUpdate-modelFirstIndexBeforeUpdate; // 0 or more
       
  8573 		if ( modelIndexDifference < 0 )
       
  8574 			{
       
  8575 			modelIndexDifference = 0; // safety
       
  8576 			}
       
  8577 		TInt toBeFirstIdx = iMailListVisualiser->HighlightedIndex() - modelIndexDifference;
       
  8578 		CFSEmailUiMailListModelItem* toBeFirstVisItem =
       
  8579 			static_cast<CFSEmailUiMailListModelItem*>( iMailListVisualiser->iModel->Item(toBeFirstIdx) );
       
  8580 		if ( toBeFirstVisItem )
       
  8581 			{
       
  8582 			// <cmail>
       
  8583 			iMailListVisualiser->iMailTreeListVisualizer->SetFirstVisibleItemL( toBeFirstVisItem->CorrespondingListId() );
       
  8584 			// </cmail>
       
  8585 			}
       
  8586 
       
  8587 		// Restore the marking status
       
  8588 		iMailListVisualiser->MarkMessagesIfFoundL( markedMessages );
       
  8589 		CleanupStack::PopAndDestroy( &markedMessages );
       
  8590     	}
       
  8591     Cancel();
       
  8592    }
       
  8593 
       
  8594 // -----------------------------------------------------------------------------
       
  8595 // CMailListUpdater::Start
       
  8596 // Timer starting function.
       
  8597 // -----------------------------------------------------------------------------
       
  8598 //
       
  8599 void CMailListUpdater::StartL( TBool aIsSorting )
       
  8600     {
       
  8601     FUNC_LOG;
       
  8602     if ( iWaitNote )
       
  8603     	{
       
  8604     	iWaitNote->ProcessFinishedL();
       
  8605     	}
       
  8606 
       
  8607     iIsSorting = aIsSorting;
       
  8608     Cancel();
       
  8609     if ( iIsSorting )
       
  8610     	{
       
  8611 		// Start wait note
       
  8612     	TFsEmailUiUtility::ShowWaitNoteL( iWaitNote, R_FSE_WAIT_SORTING_TEXT, EFalse, ETrue );
       
  8613 	 	After( 10 ); // Update shortly after selection has been made.
       
  8614     	}
       
  8615     else
       
  8616     	{
       
  8617     	 // Mail added update
       
  8618 	 	After( KMsgUpdaterTimerDelay ); // Update after 1,5 seconds
       
  8619     	}
       
  8620    	}
       
  8621 
       
  8622 // -----------------------------------------------------------------------------
       
  8623 // CMailListUpdater::Stop
       
  8624 // Timer stopping function
       
  8625 // -----------------------------------------------------------------------------
       
  8626 //
       
  8627 void CMailListUpdater::Stop()
       
  8628     {
       
  8629     FUNC_LOG;
       
  8630     Cancel();
       
  8631     }
       
  8632 
       
  8633 
       
  8634 
       
  8635 //////////////////////////////////////////////////////////////////
       
  8636 // Class implementation CMsgMovedNoteTimer
       
  8637 ///////////////////////////////////////////////////////////////////
       
  8638 
       
  8639 
       
  8640 // -----------------------------------------------------------------------------
       
  8641 // CMsgMovedNoteTimer::NewL
       
  8642 // NewL function. Returns timer object.
       
  8643 // -----------------------------------------------------------------------------
       
  8644 //
       
  8645 CMsgMovedNoteTimer* CMsgMovedNoteTimer::NewL(  CFreestyleEmailUiAppUi* aAppUi, CFSEmailUiMailListVisualiser* aMailListVisualiser  )
       
  8646     {
       
  8647     FUNC_LOG;
       
  8648     CMsgMovedNoteTimer* self = new (ELeave) CMsgMovedNoteTimer( aAppUi, aMailListVisualiser );
       
  8649     CleanupStack::PushL( self );
       
  8650     self->ConstructL();
       
  8651     CleanupStack::Pop( self );
       
  8652     return self;
       
  8653     }
       
  8654 
       
  8655 // -----------------------------------------------------------------------------
       
  8656 // CMsgMovedNoteTimer::CMsgMovedNoteTimer
       
  8657 // D'tor
       
  8658 // -----------------------------------------------------------------------------
       
  8659 //
       
  8660 CMsgMovedNoteTimer::~CMsgMovedNoteTimer()
       
  8661     {
       
  8662     FUNC_LOG;
       
  8663     Cancel();
       
  8664     }
       
  8665 
       
  8666 // -----------------------------------------------------------------------------
       
  8667 // CMailListUpdater::CMailListUpdater
       
  8668 // C'tor
       
  8669 // -----------------------------------------------------------------------------
       
  8670 //
       
  8671 CMsgMovedNoteTimer::CMsgMovedNoteTimer(  CFreestyleEmailUiAppUi* aAppUi, CFSEmailUiMailListVisualiser* aMailListVisualiser   )
       
  8672 	: CTimer( EPriorityStandard ),
       
  8673 	iAppUi( aAppUi),
       
  8674 	iMailListVisualiser( aMailListVisualiser )
       
  8675     {
       
  8676     FUNC_LOG;
       
  8677     CActiveScheduler::Add( this );
       
  8678     }
       
  8679 
       
  8680 // -----------------------------------------------------------------------------
       
  8681 // CMsgMovedNoteTimer::RunL
       
  8682 // Timer trigger function.
       
  8683 // -----------------------------------------------------------------------------
       
  8684 //
       
  8685 void CMsgMovedNoteTimer::RunL()
       
  8686     {
       
  8687     FUNC_LOG;
       
  8688  	TFsEmailUiUtility::DisplayMsgsMovedNoteL( iMsgCount, iDestinationFolderId, EFalse );
       
  8689     Cancel();
       
  8690     }
       
  8691 
       
  8692 // -----------------------------------------------------------------------------
       
  8693 // CMsgMovedNoteTimer::Start
       
  8694 // Timer starting function.
       
  8695 // -----------------------------------------------------------------------------
       
  8696 //
       
  8697 void CMsgMovedNoteTimer::Start(  TInt aMsgCount, const TFSMailMsgId aDestinationFolderId  )
       
  8698     {
       
  8699     FUNC_LOG;
       
  8700     Cancel();
       
  8701 	iMsgCount = aMsgCount,
       
  8702 	iDestinationFolderId = aDestinationFolderId;
       
  8703 	TInt viewSlideinTime = iAppUi->LayoutHandler()->ViewSlideEffectTime();
       
  8704 	if ( viewSlideinTime == 0 )
       
  8705 		{
       
  8706 		viewSlideinTime = 100;
       
  8707 		}
       
  8708  	After( viewSlideinTime );
       
  8709    	}
       
  8710 
       
  8711 // -----------------------------------------------------------------------------
       
  8712 // CMsgMovedNoteTimer::Stop
       
  8713 // Timer stopping function
       
  8714 // -----------------------------------------------------------------------------
       
  8715 //
       
  8716 void CMsgMovedNoteTimer::Stop()
       
  8717     {
       
  8718     FUNC_LOG;
       
  8719     Cancel();
       
  8720     }
       
  8721 
       
  8722 
       
  8723 //////////////////////////////////////////////////////////////////
       
  8724 // Class implementation CDateChnageTimer
       
  8725 ///////////////////////////////////////////////////////////////////
       
  8726 
       
  8727 // -----------------------------------------------------------------------------
       
  8728 // CMsgMovedNoteTimer::NewL
       
  8729 // Two phased constructor
       
  8730 // -----------------------------------------------------------------------------
       
  8731 //
       
  8732 CDateChangeTimer* CDateChangeTimer::NewL( CFSEmailUiMailListVisualiser& aMailListVisualiser )
       
  8733     {
       
  8734     FUNC_LOG;
       
  8735     CDateChangeTimer* self = new ( ELeave ) CDateChangeTimer( aMailListVisualiser );
       
  8736     CleanupStack::PushL( self );
       
  8737     self->ConstructL();
       
  8738     CleanupStack::Pop( self );
       
  8739     return self;
       
  8740     }
       
  8741 
       
  8742 // -----------------------------------------------------------------------------
       
  8743 // CMsgMovedNoteTimer::CDateChangeTimer
       
  8744 // First phase constructor
       
  8745 // -----------------------------------------------------------------------------
       
  8746 //
       
  8747 CDateChangeTimer::CDateChangeTimer( CFSEmailUiMailListVisualiser& aMailListVisualiser )
       
  8748     : CTimer( EPriorityStandard ), iMailListVisualiser( aMailListVisualiser )
       
  8749     {
       
  8750     FUNC_LOG;
       
  8751     CActiveScheduler::Add( this );
       
  8752     iDayCount = DayCount();
       
  8753     }
       
  8754 
       
  8755 // -----------------------------------------------------------------------------
       
  8756 // CMsgMovedNoteTimer::~CDateChangeTimer
       
  8757 // Destructor
       
  8758 // -----------------------------------------------------------------------------
       
  8759 //
       
  8760 CDateChangeTimer::~CDateChangeTimer()
       
  8761     {
       
  8762     FUNC_LOG;
       
  8763     // no implementation needed
       
  8764     }
       
  8765 
       
  8766 // -----------------------------------------------------------------------------
       
  8767 // CMsgMovedNoteTimer::Start
       
  8768 // Request event at 00:00 tomorrow
       
  8769 // -----------------------------------------------------------------------------
       
  8770 //
       
  8771 void CDateChangeTimer::Start()
       
  8772     {
       
  8773     FUNC_LOG;
       
  8774     TTime now;
       
  8775     now.HomeTime();
       
  8776 
       
  8777     // Construct target time
       
  8778     TTime eventTime = now + TTimeIntervalDays( 1 );
       
  8779     TDateTime eventDateTime = eventTime.DateTime();
       
  8780     eventDateTime.SetHour(0);
       
  8781     eventDateTime.SetMinute(0);
       
  8782     eventDateTime.SetSecond(0);
       
  8783     eventDateTime.SetMicroSecond(0);
       
  8784     eventTime = TTime( eventDateTime );
       
  8785 
       
  8786     // Issue the request
       
  8787     At( eventTime );
       
  8788     }
       
  8789 
       
  8790 // -----------------------------------------------------------------------------
       
  8791 // CMsgMovedNoteTimer::RunL
       
  8792 // Function gets called when system time reaches the 00:00 in the next day or
       
  8793 // when the system time has been changed by the user. Both cases can be handled
       
  8794 // in the same way.
       
  8795 // -----------------------------------------------------------------------------
       
  8796 //
       
  8797 void CDateChangeTimer::RunL()
       
  8798     {
       
  8799     FUNC_LOG;
       
  8800 
       
  8801     if (iStatus.Int() != KErrNone)
       
  8802         {
       
  8803         	INFO_1("### CDateChangeTimer::RunL (err=%d) ###", iStatus.Int());
       
  8804         }
       
  8805 
       
  8806 
       
  8807     TBool dayChanged = EFalse;
       
  8808     TInt dayCount = DayCount();
       
  8809     if (dayCount != iDayCount)
       
  8810         {
       
  8811 
       
  8812         iDayCount = dayCount;
       
  8813         dayChanged = ETrue;
       
  8814         }
       
  8815 
       
  8816 
       
  8817     if ( KErrCancel == iStatus.Int() )
       
  8818         {
       
  8819         ;
       
  8820         }
       
  8821     else if ( KErrAbort == iStatus.Int() ) // System time changed
       
  8822         {
       
  8823         if (dayChanged)
       
  8824             {
       
  8825             TRAP_IGNORE( iMailListVisualiser.NotifyDateChangedL() );
       
  8826             }
       
  8827         Start();
       
  8828         }
       
  8829     else  // interval is over
       
  8830         {
       
  8831         // Update mail list and reissue the request for timer event
       
  8832         TRAP_IGNORE( iMailListVisualiser.NotifyDateChangedL() );
       
  8833         Start();
       
  8834         }
       
  8835 
       
  8836     }
       
  8837 
       
  8838 
       
  8839 TInt CDateChangeTimer::DayCount()
       
  8840     {
       
  8841     TTime now;
       
  8842     now.HomeTime();
       
  8843     TTime minTime = Time::MinTTime();
       
  8844     TTimeIntervalDays days = now.DaysFrom(minTime);
       
  8845     return days.Int();
       
  8846     }
       
  8847 
       
  8848 
       
  8849 
       
  8850 
       
  8851 
       
  8852 
       
  8853 
       
  8854