emailuis/emailui/src/FreestyleEmailUiAttachmentsListVisualiser.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implements visualiser for the attachment list view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // SYSTEM INCLUDES
       
    21 #include "emailtrace.h"
       
    22 #include "cfsmailbox.h"
       
    23 #include <e32base.h>
       
    24 #include <freestyleemailui.mbg>
       
    25 #include <AknUtils.h>
       
    26 #include <gulicon.h>
       
    27 #include <StringLoader.h>
       
    28 #include <FreestyleEmailUi.rsg>
       
    29 // <cmail> SF
       
    30 #include <alf/alfframebrush.h>
       
    31 #include "fscontrolbar.h"
       
    32 #include "fscontrolbuttoninterface.h"
       
    33 #include "fstreelist.h"
       
    34 #include "fstreevisualizerbase.h"
       
    35 #include "fstreeplainonelineitemdata.h"
       
    36 #include "fstreeplainonelineitemvisualizer.h"
       
    37 #include "fstreeplaintwolineitemdata.h"
       
    38 #include "fstreeplaintwolineitemvisualizer.h"
       
    39 #include "fstreeplainonelinenodedata.h"
       
    40 #include "fstreeplainonelinenodevisualizer.h"
       
    41 //</cmail>
       
    42 #include <aknlistquerydialog.h>
       
    43 #include <StringLoader.h>
       
    44 #include <aknnotewrappers.h>
       
    45 // <cmail> SF
       
    46 #include <alf/alfanchorlayout.h>
       
    47 #include <alf/alfdecklayout.h>
       
    48 #include <alf/alfcontrolgroup.h>
       
    49 #include <alf/alfevent.h>
       
    50 #include <csxhelp/cmail.hlp.hrh>
       
    51 // </cmail>
       
    52 #include <featmgr.h>
       
    53 //</cmail>
       
    54 
       
    55 // <cmail> Use layout data instead of hard-coded values
       
    56 #include <aknlayoutscalable_apps.cdl.h>
       
    57 #include <layoutmetadata.cdl.h>
       
    58 // </cmail>
       
    59 
       
    60 // INTERNAL INCLUDES
       
    61 #include "FreestyleEmailUiAttachmentsListVisualiser.h"
       
    62 #include "FreestyleEmailUiLayoutHandler.h"
       
    63 #include "FreestyleEmailUiAttachmentsListModel.h"
       
    64 #include "FreestyleEmailUiAttachmentsListControl.h"
       
    65 #include "FreestyleEmailUiFileSystemInfo.h"
       
    66 #include "FreestyleEmailUiScrollbarClet.h"
       
    67 #include "FreestyleEmailUiAppui.h"
       
    68 #include "FreestyleEmailUi.hrh"
       
    69 #include "FreestyleEmailUiTextureManager.h"
       
    70 #include "FreestyleEmailUiShortcutBinding.h"
       
    71 #include "FreestyleEmailUiStatusIndicator.h"
       
    72 #include "FreestyleEmailUiUtilities.h"
       
    73 #include "FreestyleEmailUiLiterals.h"
       
    74 
       
    75 // POP3 has a specific UI for the attachment list: there is no download-option
       
    76 // available. This value should be the UID of the POP3 ECOM plugin.
       
    77 const TUint KFsPop3PluginId = 0x2000e53e;
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // Two-phased constructor.
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CFSEmailUiAttachmentsListVisualiser* CFSEmailUiAttachmentsListVisualiser::NewL(
       
    85     CAlfEnv& aEnv, CFreestyleEmailUiAppUi* aAppUi, CAlfControlGroup& aControlGroup )
       
    86     {
       
    87     FUNC_LOG;
       
    88     CFSEmailUiAttachmentsListVisualiser* self = 
       
    89         CFSEmailUiAttachmentsListVisualiser::NewLC( aEnv, aAppUi, aControlGroup );
       
    90     CleanupStack::Pop( self );
       
    91     return self;
       
    92     }
       
    93 
       
    94 CFSEmailUiAttachmentsListVisualiser* CFSEmailUiAttachmentsListVisualiser::NewLC(
       
    95     CAlfEnv& aEnv, CFreestyleEmailUiAppUi* aAppUi, CAlfControlGroup& aControlGroup )
       
    96     {
       
    97     FUNC_LOG;
       
    98     __ASSERT_DEBUG( aAppUi, User::Invariant() );
       
    99     CFSEmailUiAttachmentsListVisualiser* self =
       
   100         new (ELeave) CFSEmailUiAttachmentsListVisualiser( aEnv, *aAppUi, aControlGroup );
       
   101     CleanupStack::PushL( self );
       
   102     self->ConstructL();
       
   103     return self;
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Second phase constructor.
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 void CFSEmailUiAttachmentsListVisualiser::ConstructL()
       
   111     {
       
   112     FUNC_LOG;
       
   113 	BaseConstructL( R_FSEMAILUI_ATTACHMENTS_VIEW );
       
   114     iFirstStartCompleted = EFalse;	
       
   115  	}
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CFSEmailUiAttachmentsListVisualiser::UpdateSize
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 void CFSEmailUiAttachmentsListVisualiser::UpdateSize()
       
   122     {
       
   123     FUNC_LOG;    
       
   124     TRect screenRect;
       
   125     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, screenRect );
       
   126     screenRect.Move(-screenRect.iTl.iX, -screenRect.iTl.iY);
       
   127     iAnchorLayout->SetRect( screenRect );
       
   128     // Set anchors so that list leaves space for control bar
       
   129     iAnchorLayout->SetAnchor(EAlfAnchorTopLeft, 0,
       
   130         EAlfAnchorOriginLeft, EAlfAnchorOriginTop,
       
   131         EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute,
       
   132         TAlfTimedPoint(0, 0 ));
       
   133     iAnchorLayout->SetAnchor(EAlfAnchorBottomRight, 0,
       
   134         EAlfAnchorOriginLeft, EAlfAnchorOriginTop,
       
   135         EAlfAnchorMetricAbsolute, EAlfAnchorMetricAbsolute,
       
   136         TAlfTimedPoint(screenRect.iBr.iX, screenRect.iBr.iY ));
       
   137     iAnchorLayout->UpdateChildrenLayout();
       
   138     }
       
   139 
       
   140 // ---------------------------------------------------------------------------
       
   141 // CFSEmailUiAttachmentsListVisualiser::DoFirstStartL
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CFSEmailUiAttachmentsListVisualiser::DoFirstStartL()
       
   145     {
       
   146     FUNC_LOG;
       
   147     // Create list screen (list) control and screen anchor layout
       
   148     iScreenControl = CFreestyleEmailUiAttachmentsListControl::NewL( iEnv, this );
       
   149     
       
   150     // Anchor layout
       
   151     iAnchorLayout = CAlfAnchorLayout::AddNewL( *iScreenControl );
       
   152     
       
   153     // Create attachments list layout and set it to fill the main pane
       
   154     iListLayout = CAlfDeckLayout::AddNewL( *iScreenControl, iAnchorLayout );  
       
   155 
       
   156     UpdateSize();
       
   157     
       
   158     // Create attachments list tree list component 
       
   159     iAttachmentsTreeListVisualizer = CFsTreeVisualizerBase::NewL(iScreenControl, *iListLayout);
       
   160     iAttachmentsTreeListVisualizer->SetItemExpansionDelay( iAppUi.LayoutHandler()->ListItemExpansionDelay() );
       
   161     
       
   162     iAttachmentsList = CFsTreeList::NewL(*iAttachmentsTreeListVisualizer, iEnv);   
       
   163     iAttachmentsList->SetScrollbarVisibilityL( EFsScrollbarAuto );
       
   164     iAttachmentsList->SetMarkTypeL( CFsTreeList::EFsTreeListMultiMarkable );
       
   165     iAttachmentsList->SetIndentationL( 0 );
       
   166     iAttachmentsList->AddObserverL( *this );
       
   167 
       
   168     iAppUi.LayoutHandler()->SetListMarqueeBehaviour( iAttachmentsList );
       
   169 
       
   170     //<cmail> Compared to S60 3.2.3 in S60 5.0 Alf offers the key events in
       
   171     // opposite order.
       
   172     ControlGroup().AppendL( iScreenControl );
       
   173   	ControlGroup().AppendL( iAttachmentsList->TreeControl() );
       
   174     //</cmail>
       
   175 
       
   176     // create model
       
   177 	iModel = CFSEmailUiAttachmentsListModel::NewL( iAppUi, *this );
       
   178 
       
   179     //<cmail> S60 skin support
       
   180     //iAttachmentsTreeListVisualizer->SetBackgroundTextureL( iAppUi.FsTextureManager()->TextureByIndex( EBackgroundTextureMailList ) );  
       
   181     //</cmail>
       
   182     iAttachmentsTreeListVisualizer->SetMenuIcon( iAppUi.FsTextureManager()->TextureByIndex( EListControlMenuIcon ) );       
       
   183     iAttachmentsTreeListVisualizer->SetItemsAlwaysExtendedL( ETrue );
       
   184 
       
   185     // Set page up and page down keys
       
   186     iAttachmentsTreeListVisualizer->AddCustomPageUpKey( EStdKeyPageUp );
       
   187     iAttachmentsTreeListVisualizer->AddCustomPageDownKey( EStdKeyPageDown );
       
   188   
       
   189     CAlfBrush* selectorBrush = iAppUi.FsTextureManager()->ListSelectorBrushL();
       
   190     iAttachmentsTreeListVisualizer->SetSelectorPropertiesL( selectorBrush, 1.0, CFsTreeVisualizerBase::EFsSelectorMoveSmoothly );   
       
   191    
       
   192     iFirstStartCompleted = ETrue;
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // C++ constructor.
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 CFSEmailUiAttachmentsListVisualiser::CFSEmailUiAttachmentsListVisualiser(
       
   200     CAlfEnv& aEnv, CFreestyleEmailUiAppUi& aAppUi, CAlfControlGroup& aControlGroup )
       
   201     : CFsEmailUiViewBase( aControlGroup, aAppUi ),
       
   202     iEnv( aEnv )
       
   203 	{
       
   204     FUNC_LOG;
       
   205 	}
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // Destructor.
       
   209 // ---------------------------------------------------------------------------
       
   210 //
       
   211 CFSEmailUiAttachmentsListVisualiser::~CFSEmailUiAttachmentsListVisualiser()
       
   212 	{
       
   213     FUNC_LOG;
       
   214   	delete iModel;
       
   215 	if ( iAttachmentsList )
       
   216 		{
       
   217 		iAttachmentsList->RemoveObserver( *this );
       
   218 		}
       
   219 	//<cmail> removed as not used anywhere.
       
   220 
       
   221 	//</cmail>
       
   222 	delete iAttachmentsList;
       
   223 	}
       
   224 
       
   225 
       
   226 TUid CFSEmailUiAttachmentsListVisualiser::Id() const
       
   227 	{
       
   228     FUNC_LOG;
       
   229 	return AttachmentMngrViewId;
       
   230 	}
       
   231 	
       
   232 
       
   233 // <cmail> Toolbar
       
   234 /*void CFSEmailUiAttachmentsListVisualiser::DoActivateL(const TVwsViewId& aPrevViewId,
       
   235                      TUid aCustomMessageId,
       
   236                      const TDesC8& aCustomMessage)*/
       
   237 void CFSEmailUiAttachmentsListVisualiser::ChildDoActivateL(const TVwsViewId& /*aPrevViewId*/,
       
   238                      TUid /*aCustomMessageId*/,
       
   239                      const TDesC8& aCustomMessage)
       
   240 // </cmail> Toolbar
       
   241 	{
       
   242     FUNC_LOG;
       
   243 
       
   244   	if ( !iFirstStartCompleted )
       
   245   	    {
       
   246   	    DoFirstStartL();
       
   247   	    }
       
   248   	
       
   249     iAttachmentsList->HideListL();
       
   250 
       
   251     // Refresh the view with the given part data.
       
   252   	// If no part data is passed, the view is refreshed with data 
       
   253   	// from previously viewed message.
       
   254   	TAttachmentListActivationData activationData;
       
   255   	if ( aCustomMessage.Length() )
       
   256   	    {
       
   257         TPckgC<TAttachmentListActivationData> pkgPtr( activationData );
       
   258         pkgPtr.Set( aCustomMessage );
       
   259         activationData = pkgPtr();
       
   260         iEmbeddedMsgMode = activationData.iEmbeddedMsgMode;
       
   261   	    }
       
   262   	TPartData part(	activationData.iMailBoxId, activationData.iFolderId, activationData.iMessageId );
       
   263   	RefreshL( part );
       
   264 
       
   265    	iAttachmentsList->ShowListL();
       
   266 	
       
   267 	SetupTitlePaneTextL();    
       
   268 	
       
   269 	iAttachmentsList->SetFocusedL(ETrue);
       
   270 	}
       
   271 
       
   272 // <cmail> Toolbar
       
   273 // ---------------------------------------------------------------------------
       
   274 // OfferToolbarEventL
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 void CFSEmailUiAttachmentsListVisualiser::OfferToolbarEventL( TInt /*aCommand*/ )
       
   278     {
       
   279     
       
   280     }
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // ToolbarResourceId
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 TInt CFSEmailUiAttachmentsListVisualiser::ToolbarResourceId() const
       
   287     {
       
   288     return R_FREESTYLE_EMAIL_UI_TOOLBAR_ATTACHMENT_LIST;
       
   289     }
       
   290 	
       
   291 // </cmail>
       
   292 	             
       
   293 void CFSEmailUiAttachmentsListVisualiser::ChildDoDeactivate()
       
   294 	{
       
   295     FUNC_LOG;
       
   296   	if ( !iAppUi.AppUiExitOngoing() )
       
   297   		{
       
   298         TRAP_IGNORE(iAttachmentsList->SetFocusedL(EFalse));
       
   299     	
       
   300         iAttachmentsTreeListVisualizer->NotifyControlVisibilityChange( EFalse );
       
   301   		}
       
   302 	}	
       
   303 	
       
   304 CFSEmailUiAttachmentsListModel* CFSEmailUiAttachmentsListVisualiser::Model()
       
   305 	{
       
   306     FUNC_LOG;
       
   307 	return iModel;	
       
   308 	}
       
   309 
       
   310 void CFSEmailUiAttachmentsListVisualiser::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
       
   311     {
       
   312     FUNC_LOG;
       
   313 	
       
   314     TAttachmentData* selectedItem = iModel->GetItem( iAttachmentsList->FocusedItem() );
       
   315 
       
   316     if ( aResourceId == R_FSEMAILUI_ATTACHMENTS_SUBMENU_ACTIONS )
       
   317         {
       
   318         aMenuPane->SetItemDimmed( EFsEmailUiCmdOpen, 
       
   319                 !IsCommandAvailableOnItem(EFsEmailUiCmdOpen, selectedItem) );
       
   320 
       
   321         aMenuPane->SetItemDimmed( EFsEmailUiCmdDownload, 
       
   322                 !IsCommandAvailableOnItem(EFsEmailUiCmdDownload, selectedItem) );
       
   323 
       
   324         aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelDownload, 
       
   325                 !IsCommandAvailableOnItem(EFsEmailUiCmdCancelDownload, selectedItem) );
       
   326 
       
   327         aMenuPane->SetItemDimmed( EFsEmailUiCmdSave, 
       
   328                 !IsCommandAvailableOnItem(EFsEmailUiCmdSave, selectedItem) );
       
   329 
       
   330         aMenuPane->SetItemDimmed( EFsEmailUiCmdDownloadAll, 
       
   331                 !IsCommandAvailableOnItem(EFsEmailUiCmdDownloadAll, selectedItem) );
       
   332 
       
   333         aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelAllDownloads, 
       
   334                 !IsCommandAvailableOnItem(EFsEmailUiCmdCancelAllDownloads, selectedItem) );
       
   335 
       
   336         aMenuPane->SetItemDimmed( EFsEmailUiCmdSaveAll, 
       
   337                 !IsCommandAvailableOnItem(EFsEmailUiCmdSaveAll, selectedItem) );
       
   338 
       
   339         aMenuPane->SetItemDimmed( EFsEmailUiCmdClearFetchedAttachment, 
       
   340                 !IsCommandAvailableOnItem(EFsEmailUiCmdClearFetchedAttachment, selectedItem) );
       
   341         
       
   342         aMenuPane->SetItemDimmed( EFsEmailUiCmdRemoveAttachment, ETrue ); // available only in Download Manager
       
   343         }
       
   344     else if ( aResourceId == R_FSEMAILUI_ATTACHMENTS_MENUPANE )
       
   345         {
       
   346         if ( FeatureManager::FeatureSupported( KFeatureIdFfCmailIntegration ) )
       
   347     	   {
       
   348     	   // remove help support in pf5250
       
   349     	   aMenuPane->SetItemDimmed( EFsEmailUiCmdHelp, ETrue);      
       
   350     	   }	
       
   351         
       
   352         aMenuPane->SetItemDimmed( EFsEmailUiCmdMailActions,
       
   353                 !IsCommandAvailableOnItem(EFsEmailUiCmdMailActions, selectedItem) );
       
   354         }
       
   355 
       
   356     // Add shortcut hints
       
   357     iAppUi.ShortcutBinding().AppendShortcutHintsL( *aMenuPane, 
       
   358             CFSEmailUiShortcutBinding::EContextAttachmentList );
       
   359     }
       
   360 
       
   361 void CFSEmailUiAttachmentsListVisualiser::DownloadStatusChangedL( TInt aIndex )
       
   362     {
       
   363     FUNC_LOG;
       
   364     if ( iFirstStartCompleted ) //Safety
       
   365         {
       
   366         const RArray<TAttachmentData>& model = iModel->GetModel();
       
   367 
       
   368         TBool refreshNeeded = ( aIndex == KErrNotFound );
       
   369 
       
   370         if ( iAppUi.CurrentActiveView() == this && 
       
   371                 ( aIndex < model.Count() || refreshNeeded ) &&
       
   372                 !iAppUi.AppUiExitOngoing() )
       
   373             {
       
   374             if ( refreshNeeded )
       
   375                 {
       
   376    		        // We end up here when the model has been changed during the
       
   377    		        // download operation. This happens with POP redownload as POP
       
   378    		        // creates new entries (message parts) after the operation.
       
   379                 RefreshL( TPartData() );
       
   380 
       
   381             	GoToTopL();
       
   382                 }
       
   383             else
       
   384                 {
       
   385                 const TAttachmentData& attachment = model[aIndex];
       
   386 
       
   387                 CFsTreePlainTwoLineItemData& itemData = 
       
   388                     static_cast<CFsTreePlainTwoLineItemData&>(
       
   389                         iAttachmentsList->ItemData( attachment.treeId ) );
       
   390 
       
   391                 itemData.SetDataL( attachment.fileName );
       
   392 
       
   393                 HBufC* secondLine = CreateSecondLineTextLC( attachment );
       
   394 
       
   395                 // Move the attachment under the "Downloaded" node if the 
       
   396                 // download was just completed
       
   397                 if ( attachment.downloadProgress == KComplete && 
       
   398                         iAttachmentsList->Parent( attachment.treeId ) ==
       
   399                             iNotDownloadedNode )
       
   400                     {
       
   401                     itemData.SetSecondaryDataL( *secondLine );
       
   402                     MoveItemToNodeL( attachment.treeId, iDownloadedNode );
       
   403                     }
       
   404                 // Otherwise, just order the list item to be updated in its place
       
   405                 // but only if data has actually changed
       
   406                 else if ( itemData.SecondaryData() != *secondLine )
       
   407                     {
       
   408                     itemData.SetSecondaryDataL( *secondLine );
       
   409                     iAttachmentsTreeListVisualizer->UpdateItemL( attachment.treeId );
       
   410                     }
       
   411                 else
       
   412                     {
       
   413                     // no updating is actually needed => do nothing
       
   414                     }
       
   415                 CleanupStack::PopAndDestroy( secondLine );
       
   416 
       
   417                 // Update the MSK label as the correct function for the
       
   418                 // focused item may have changed.
       
   419                 SetMskL();
       
   420                 }    
       
   421             } 	    
       
   422         }		
       
   423     }
       
   424 	
       
   425 void CFSEmailUiAttachmentsListVisualiser::RefreshL( TPartData aPart )
       
   426     {
       
   427     FUNC_LOG;
       
   428     if ( iFirstStartCompleted ) //Safety
       
   429         {
       
   430         // Update model. Use previous message if no new message has been provided.
       
   431         if ( aPart.iMessageId.IsNullId() )
       
   432             {
       
   433             aPart = iModel->GetMessageL( KFsTreeNoneID );
       
   434             }
       
   435         iModel->UpdateListL( aPart );
       
   436         
       
   437         UpdateSize();
       
   438 
       
   439         CFsTreePlainTwoLineItemData* twoLineItemData;
       
   440         CFsTreePlainTwoLineItemVisualizer* twoLineItemVisualizer;
       
   441 
       
   442         iAttachmentsList->RemoveAllL();
       
   443         CreateHeadersAndSeparatorsL();
       
   444         const RArray<TAttachmentData>& model = iModel->GetModel();
       
   445 
       
   446         TInt modelCount = model.Count();
       
   447         for ( TInt i = 0; i < modelCount; i++ )
       
   448             {
       
   449             const TAttachmentData& attachment = model[i];
       
   450 
       
   451             twoLineItemData = CFsTreePlainTwoLineItemData::NewL();
       
   452             CleanupStack::PushL( twoLineItemData );
       
   453             twoLineItemData->SetDataL( attachment.fileName );
       
   454 
       
   455             HBufC* secondLine = CreateSecondLineTextLC( attachment );
       
   456             twoLineItemData->SetSecondaryDataL( *secondLine );
       
   457             CleanupStack::PopAndDestroy( secondLine );
       
   458 
       
   459             CAlfTexture& itemTexture = TFsEmailUiUtility::GetAttachmentIcon(
       
   460                     attachment.fileType, *iAppUi.FsTextureManager() );
       
   461             twoLineItemData->SetIcon( itemTexture );
       
   462 
       
   463             twoLineItemVisualizer = CFsTreePlainTwoLineItemVisualizer::NewL(
       
   464                     *iAttachmentsList->TreeControl() );
       
   465             CleanupStack::PushL( twoLineItemVisualizer );
       
   466             twoLineItemVisualizer->SetFlags( twoLineItemVisualizer->Flags()
       
   467                     | KFsTreeListItemHasMenu );
       
   468             twoLineItemVisualizer->SetExtendable( ETrue );
       
   469             // <cmail> Platform layout changes
       
   470             /*
       
   471             CAlfTextStyle* textStyle =
       
   472                 iAppUi.LayoutHandler()->FSTextStyleFromIdL( EFSFontTypeSmall );
       
   473             */
       
   474             TInt variety( Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0 );
       
   475             CAlfTextStyle& textStyle =
       
   476                 iAppUi.LayoutHandler()->FSTextStyleFromLayoutL(
       
   477                     AknLayoutScalable_Apps::list_single_dyc_row_text_pane_t1(variety));
       
   478             twoLineItemVisualizer->SetTextStyleId( textStyle.Id() );
       
   479             // Set font height
       
   480            /*
       
   481             twoLineItemVisualizer->SetFontHeight(
       
   482                     iAppUi.LayoutHandler()->ListItemFontHeightInTwips() );      
       
   483 			*/
       
   484             twoLineItemVisualizer->SetFontHeight( textStyle.TextSizeInTwips() );
       
   485             // </cmail> Platform layout changes
       
   486 
       
   487             // Set font bolding
       
   488             twoLineItemVisualizer->SetTextBold( EFalse );
       
   489             // Set correct skin text colors for the list items  
       
   490             TRgb focusedColor =
       
   491             iAppUi.LayoutHandler()->ListFocusedStateTextSkinColor();
       
   492             TRgb normalColor =
       
   493             iAppUi.LayoutHandler()->ListNormalStateTextSkinColor();
       
   494             twoLineItemVisualizer->SetFocusedStateTextColor( focusedColor );
       
   495             twoLineItemVisualizer->SetNormalStateTextColor( normalColor );
       
   496 
       
   497             TFsTreeItemId treeItemId;    
       
   498             CleanupStack::Pop( twoLineItemVisualizer );
       
   499             CleanupStack::Pop( twoLineItemData );
       
   500             if ( attachment.downloadProgress == KComplete )
       
   501                 {
       
   502                 treeItemId = iAttachmentsList->InsertItemL(
       
   503                         *twoLineItemData,
       
   504                         *twoLineItemVisualizer,
       
   505                         iDownloadedNode );
       
   506                 }
       
   507             else
       
   508                 {
       
   509                 treeItemId = iAttachmentsList->InsertItemL(
       
   510                         *twoLineItemData,
       
   511                         *twoLineItemVisualizer,
       
   512                         iNotDownloadedNode );    
       
   513                 }
       
   514             iModel->SetNodeIdL( i, treeItemId );
       
   515             }
       
   516 
       
   517         if ( iAttachmentsList->IsEmpty( iDownloadedNode ) )
       
   518             {
       
   519             iAttachmentsTreeListVisualizer->HideItemL( iDownloadedNode );
       
   520             }
       
   521         if ( iAttachmentsList->IsEmpty( iNotDownloadedNode ) )
       
   522             {
       
   523             iAttachmentsTreeListVisualizer->HideItemL( iNotDownloadedNode );
       
   524             }
       
   525         }
       
   526     }
       
   527 	
       
   528 void CFSEmailUiAttachmentsListVisualiser::ReScaleUiL()
       
   529 	{
       
   530     FUNC_LOG;
       
   531     UpdateSize();
       
   532   	}
       
   533 
       
   534 void CFSEmailUiAttachmentsListVisualiser::ResetColorsL()
       
   535     {
       
   536     FUNC_LOG;
       
   537     if ( iFirstStartCompleted )
       
   538         {
       
   539         TRgb normalTextColor = iAppUi.LayoutHandler()->ListNormalStateTextSkinColor();
       
   540         TRgb focusedTextColor = iAppUi.LayoutHandler()->ListFocusedStateTextSkinColor();
       
   541         TRgb nodeTextColor = iAppUi.LayoutHandler()->ListNodeTextColor();
       
   542    	
       
   543         // Header item
       
   544         TFsTreeItemId headerId = iAttachmentsList->Child( KFsTreeRootID, 0 );
       
   545         MFsTreeItemVisualizer& headerVis = iAttachmentsList->ItemVisualizer( headerId );
       
   546         headerVis.SetNormalStateTextColor( normalTextColor );
       
   547         headerVis.SetFocusedStateTextColor( focusedTextColor );
       
   548    
       
   549         // Dividers
       
   550         iDownloadedVisualiser->SetNormalStateTextColor( nodeTextColor );
       
   551         iDownloadedVisualiser->SetFocusedStateTextColor( focusedTextColor );
       
   552         
       
   553         iNotDownloadedVisualiser->SetNormalStateTextColor( nodeTextColor );
       
   554         iNotDownloadedVisualiser->SetFocusedStateTextColor( focusedTextColor );
       
   555         
       
   556         // Attachment items
       
   557         const RArray<TAttachmentData>& model = iModel->GetModel();
       
   558         for ( TInt i=0; i<model.Count(); i++ )
       
   559             {
       
   560             MFsTreeItemVisualizer& attachmentVis = iAttachmentsList->ItemVisualizer( model[i].treeId );
       
   561             attachmentVis.SetNormalStateTextColor( normalTextColor );
       
   562             attachmentVis.SetFocusedStateTextColor( focusedTextColor );
       
   563             }       
       
   564         }
       
   565     }
       
   566 	
       
   567 void CFSEmailUiAttachmentsListVisualiser::HandleDynamicVariantSwitchL( CFsEmailUiViewBase::TDynamicSwitchType aType )
       
   568 	{
       
   569     FUNC_LOG;
       
   570   	if ( iFirstStartCompleted )
       
   571   	    {
       
   572         iAttachmentsList->HideListL();
       
   573         if ( aType == CFsEmailUiViewBase::EScreenLayoutChanged )
       
   574             {
       
   575             ReScaleUiL();
       
   576             iAttachmentsList->ShowListL();
       
   577             }
       
   578         else if ( aType ==  CFsEmailUiViewBase::ESkinChanged )
       
   579             {
       
   580             ResetColorsL();
       
   581             iAttachmentsList->ShowListL();
       
   582             }	    
       
   583   	    }  	
       
   584 	}
       
   585 
       
   586 void CFSEmailUiAttachmentsListVisualiser::HandleDynamicVariantSwitchOnBackgroundL( CFsEmailUiViewBase::TDynamicSwitchType aType )
       
   587     {
       
   588     FUNC_LOG;
       
   589     if ( iFirstStartCompleted && aType == CFsEmailUiViewBase::ESkinChanged )
       
   590         {
       
   591         ResetColorsL();
       
   592         }
       
   593     }
       
   594 
       
   595 void CFSEmailUiAttachmentsListVisualiser::GetParentLayoutsL( RPointerArray<CAlfVisual>& aLayoutArray ) const
       
   596     {
       
   597     FUNC_LOG;
       
   598     aLayoutArray.AppendL( iListLayout );
       
   599     }
       
   600 
       
   601 void CFSEmailUiAttachmentsListVisualiser::HandleCommandL( TInt aCommand )
       
   602     {
       
   603     FUNC_LOG;
       
   604   	
       
   605   	TFsTreeItemId focusedId = iAttachmentsList->FocusedItem();
       
   606   	            
       
   607     switch(aCommand)
       
   608   		{
       
   609   		case EFsEmailUiCmdEmpty: // this is used when focused item is being downloaded
       
   610   		case EFsEmailUiCmdOpen:
       
   611         case EAknSoftkeyOpen:
       
   612   		    {
       
   613   		    TryToOpenItemL( focusedId );
       
   614   		    }
       
   615   			break;
       
   616   		case EFsEmailUiCmdDownload:
       
   617   		    {
       
   618   		    iModel->StartDownloadL( focusedId );
       
   619   		    }
       
   620   		    break;
       
   621    		case EFsEmailUiCmdCancelDownload:
       
   622    		    {
       
   623    		    TInt reallyCancel = 
       
   624    		        TFsEmailUiUtility::ShowConfirmationQueryL( R_FSE_VIEWER_CANCEL_DOWNLOAD_QUERY );
       
   625 			if ( reallyCancel )
       
   626 				{
       
   627 	   			iModel->CancelDownloadL( focusedId );
       
   628 				}
       
   629    		    }
       
   630    		    break;
       
   631    		case EFsEmailUiCmdCancelAllDownloads:
       
   632    		    {					
       
   633    		    TInt reallyCancel = 
       
   634    		        TFsEmailUiUtility::ShowConfirmationQueryL( R_FSE_VIEWER_CANCEL_DOWNLOADS_QUERY );
       
   635 			if ( reallyCancel )
       
   636 				{
       
   637    				iModel->CancelAllDownloadsL();
       
   638 				}
       
   639    		    }
       
   640    		    break;
       
   641   		case EFsEmailUiCmdSave:
       
   642   			{
       
   643   			TFileName fileName;
       
   644   			if ( TFsEmailUiUtility::ShowSaveFolderDialogL( fileName ) )
       
   645   				{
       
   646   				TInt savedCount( 0 );
       
   647   				iModel->SaveAttachmentL( focusedId, fileName, savedCount );
       
   648 			    if ( savedCount )
       
   649 			        {
       
   650 			        TFsEmailUiUtility::ShowFilesSavedToFolderNoteL( savedCount );        
       
   651 			        }
       
   652   				}
       
   653   			}
       
   654   			break;
       
   655   		case EFsEmailUiCmdSaveAll:
       
   656   			{
       
   657   			TFileName fileName;
       
   658   			if ( TFsEmailUiUtility::ShowSaveFolderDialogL( fileName ) )
       
   659   				{
       
   660 				iModel->SaveAllAttachmentsL( fileName );
       
   661   				}
       
   662   			}
       
   663   			break;
       
   664   		case EFsEmailUiCmdDownloadAll:
       
   665   			{
       
   666   			iModel->DownloadAllAttachmentsL();
       
   667   			}
       
   668   			break;
       
   669   		case EFsEmailUiCmdClearFetchedAttachment:
       
   670   		case EFsEmailUiCmdActionsDelete: // from shortcut key
       
   671   		    {
       
   672   		    RemoveAttachmentContentL( focusedId );
       
   673   		    }
       
   674   		    break;
       
   675         case EFsEmailUiCmdExit:
       
   676             {
       
   677             iAppUi.Exit();
       
   678             }
       
   679             break;
       
   680         case EAknSoftkeyBack:
       
   681         	{
       
   682 	        if ( !iAppUi.ViewSwitchingOngoing() )
       
   683 				{
       
   684   				iAppUi.ReturnToPreviousViewL();
       
   685 				}        	
       
   686         	}
       
   687         	break;
       
   688         case EFsEmailUiCmdCollapse:
       
   689             {
       
   690             iAttachmentsList->CollapseNodeL( focusedId );
       
   691             ChangeMskCommandL( R_FSE_QTN_MSK_EXPAND );
       
   692             }
       
   693             break;
       
   694             
       
   695         case EFsEmailUiCmdExpand:
       
   696             {
       
   697             iAttachmentsList->ExpandNodeL( focusedId );
       
   698             ChangeMskCommandL( R_FSE_QTN_MSK_COLLAPSE );
       
   699             }
       
   700             break;
       
   701             
       
   702         case EFsEmailUiCmdActionsCollapseExpandAllToggle:
       
   703             {
       
   704             ShortcutCollapseExpandAllToggleL();
       
   705             }
       
   706             break;        
       
   707         case EFsEmailUiCmdGoToTop:
       
   708             {
       
   709             GoToTopL();
       
   710             }
       
   711             break;
       
   712         case EFsEmailUiCmdGoToBottom:
       
   713             {
       
   714             GoToBottomL();
       
   715             }
       
   716             break;
       
   717         case EFsEmailUiCmdPageUp:
       
   718             {
       
   719             TKeyEvent simEvent = { EKeyPageUp, EStdKeyPageUp, 0, 0 };
       
   720             iCoeEnv->SimulateKeyEventL( simEvent, EEventKey );
       
   721             }
       
   722             break;
       
   723         case EFsEmailUiCmdPageDown:
       
   724             {
       
   725             TKeyEvent simEvent = { EKeyPageDown, EStdKeyPageDown, 0, 0 };
       
   726             iCoeEnv->SimulateKeyEventL( simEvent, EEventKey );
       
   727             }
       
   728             break;
       
   729        	case EFsEmailUiCmdHelp:
       
   730   			{
       
   731 			TFsEmailUiUtility::LaunchHelpL( KFSE_HLP_LAUNCHER_GRID );
       
   732   			}
       
   733   			break; 
       
   734             
       
   735         default:
       
   736         	break;
       
   737         }
       
   738     }
       
   739     
       
   740 void CFSEmailUiAttachmentsListVisualiser::SetViewSoftkeysL( TInt aResourceId )
       
   741 	{
       
   742     FUNC_LOG;
       
   743     Cba()->SetCommandSetL( aResourceId );
       
   744     Cba()->DrawDeferred();	
       
   745 	}
       
   746 	
       
   747 void CFSEmailUiAttachmentsListVisualiser::SetMskL()
       
   748     {
       
   749     FUNC_LOG;
       
   750     TFsTreeItemId curId = iAttachmentsList->FocusedItem(); 
       
   751 
       
   752     // We end up here when the model has been changed during the
       
   753     // download operation. This happens with POP redownload as POP
       
   754     // creates new entries.
       
   755     if ( iAttachmentsList->IsNode( curId ) )
       
   756         {
       
   757         if ( iAttachmentsList->IsExpanded( curId ) )
       
   758             {
       
   759             ChangeMskCommandL( R_FSE_QTN_MSK_COLLAPSE );
       
   760             } 
       
   761         else
       
   762             {
       
   763             ChangeMskCommandL( R_FSE_QTN_MSK_EXPAND );
       
   764             }
       
   765         }
       
   766     else 
       
   767         {
       
   768         TAttachmentData* selectedItem =
       
   769             iModel->GetItem( iAttachmentsList->FocusedItem() );
       
   770 
       
   771         if ( selectedItem &&
       
   772                 IsCommandAvailableOnItem( EFsEmailUiCmdDownload, selectedItem ) )
       
   773             {
       
   774             ChangeMskCommandL( R_FSE_QTN_MSK_DOWNLOAD );
       
   775             }
       
   776         else if ( selectedItem &&
       
   777                 IsCommandAvailableOnItem( EFsEmailUiCmdOpen, selectedItem ) )
       
   778             {
       
   779             ChangeMskCommandL( R_FSE_QTN_MSK_OPEN );
       
   780             }
       
   781         else
       
   782             {
       
   783             ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
       
   784             }
       
   785         }
       
   786     }
       
   787 TBool CFSEmailUiAttachmentsListVisualiser::OfferEventL(const TAlfEvent& aEvent)
       
   788     {
       
   789     FUNC_LOG;
       
   790     TBool result( EFalse ); 
       
   791     SetMskL();
       
   792     // Handle only key events, no key down or key up events.
       
   793     if ( aEvent.IsKeyEvent() && aEvent.Code() == EEventKey )
       
   794         {
       
   795 	    TInt scanCode = aEvent.KeyEvent().iScanCode;
       
   796 	    // Swap right and left controls in mirrored layout
       
   797 	    if ( AknLayoutUtils::LayoutMirrored() )
       
   798 	        {
       
   799 	        if (scanCode == EStdKeyRightArrow) scanCode = EStdKeyLeftArrow;
       
   800 	        else if (scanCode == EStdKeyLeftArrow ) scanCode = EStdKeyRightArrow;
       
   801 	        }
       
   802 	
       
   803 		if ( scanCode == EStdKeyRightArrow )
       
   804 			{
       
   805 			LaunchActionMenuL();
       
   806 			result = ETrue;
       
   807 			}
       
   808 		else
       
   809 			{
       
   810 	   	    // Check keyboard shortcuts.
       
   811 	   	    TInt shortcutCommand = 
       
   812 	   	        iAppUi.ShortcutBinding().CommandForShortcutKey( aEvent.KeyEvent(),
       
   813 	   	                                                         CFSEmailUiShortcutBinding::EContextAttachmentList );
       
   814 	   	    if ( shortcutCommand != KErrNotFound )
       
   815 	   	        {
       
   816 	            HandleCommandL( shortcutCommand );
       
   817 	   	        result = ETrue;
       
   818 	   	        }
       
   819 			}
       
   820 		}
       
   821     else if (aEvent.IsPointerEvent())
       
   822         {
       
   823         result = iAttachmentsList->TreeControl()->OfferEventL(aEvent);
       
   824         }
       
   825     return result;
       
   826     }
       
   827 
       
   828 CAlfControl* CFSEmailUiAttachmentsListVisualiser::ViewerControl()
       
   829 	{
       
   830     FUNC_LOG;
       
   831 	return iScreenControl;
       
   832 	}
       
   833 
       
   834 void CFSEmailUiAttachmentsListVisualiser::CreateHeadersAndSeparatorsL()
       
   835 	{
       
   836     FUNC_LOG;
       
   837 	TRect screenRect;
       
   838 	AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );
       
   839     // <cmail> Removed attachments row from attachemnts view. New UI
       
   840 	// requirement. Some other lines of code also removed from this function
       
   841 	// because of the modification.
       
   842   
       
   843     //</cmail>
       
   844     //<cmail> Platform layout changes
       
   845 	TInt variety( Layout_Meta_Data::IsLandscapeOrientation() ? 1 : 0 );
       
   846     CAlfTextStyle& textStyle =
       
   847         iAppUi.LayoutHandler()->FSTextStyleFromLayoutL(
       
   848                 AknLayoutScalable_Apps::list_single_dyc_row_text_pane_t1(variety));
       
   849 
       
   850     // </cmail> Platform layout changes
       
   851 
       
   852   	// Set correct skin text colors for the list items
       
   853     TRgb focusedColor = iAppUi.LayoutHandler()->ListFocusedStateTextSkinColor();
       
   854    	TRgb normalColor = iAppUi.LayoutHandler()->ListNormalStateTextSkinColor();
       
   855    	TRgb normalNodeColor = iAppUi.LayoutHandler()->ListNodeTextColor();
       
   856 
       
   857     // <cmail>
       
   858 
       
   859     // </cmail>
       
   860 
       
   861     // <cmail>
       
   862 
       
   863     // </cmail>
       
   864 
       
   865     // <cmail> Platform layout changes
       
   866 
       
   867     // </cmail> Platform layout changes
       
   868 
       
   869 
       
   870 	CFsTreePlainOneLineNodeData* separatorData = CFsTreePlainOneLineNodeData::NewL();
       
   871 	CleanupStack::PushL( separatorData );
       
   872     CFsTreePlainOneLineNodeVisualizer* separatorVisualiser = CFsTreePlainOneLineNodeVisualizer::NewL(*iAttachmentsList->TreeControl());
       
   873     CleanupStack::PushL( separatorVisualiser );
       
   874 
       
   875     HBufC* resourceString = StringLoader::LoadLC( R_FSE_VIEWER_ATTACHMENTS_LIST_DOWNLOADED );
       
   876 	separatorData->SetDataL( *resourceString );
       
   877 	CleanupStack::PopAndDestroy( resourceString );
       
   878     separatorVisualiser->SetSize(TSize(screenRect.Width(), iAppUi.LayoutHandler()->OneLineListNodeHeight()));
       
   879     separatorVisualiser->SetExtendable(EFalse);
       
   880 	// Set font height
       
   881     // <cmail> Platform layout changes
       
   882     //separatorVisualiser->SetFontHeight( iAppUi.LayoutHandler()->ListItemFontHeightInTwips() );
       
   883     separatorVisualiser->SetFontHeight( textStyle.TextSizeInTwips() );
       
   884     // </cmail> Platform layout changes
       
   885 	// Set font bolding
       
   886 	separatorVisualiser->SetTextBold( ETrue );
       
   887 	separatorData->SetIconExpanded( iAppUi.FsTextureManager()->TextureByIndex( EListTextureNodeExpanded ) );
       
   888 	separatorData->SetIconCollapsed( iAppUi.FsTextureManager()->TextureByIndex( EListTextureNodeCollapsed ) );
       
   889 
       
   890     // <cmail> Platform layout changes
       
   891     // textStyle = iAppUi.LayoutHandler()->FSTextStyleFromIdL( EFSFontTypeSmall );
       
   892 	separatorVisualiser->SetTextStyleId( textStyle.Id() );
       
   893     // </cmail> Platform layout changes
       
   894 
       
   895   	// Set correct skin text colors for the list items
       
   896 	separatorVisualiser->SetFocusedStateTextColor( focusedColor );
       
   897 	separatorVisualiser->SetNormalStateTextColor( normalNodeColor );
       
   898 	// <cmail>
       
   899 	//separatorVisualiser->SetBackgroundColor( iAppUi.LayoutHandler()->ListNodeBackgroundColor() );
       
   900 	// </cmail>
       
   901     // Gradient background for headings    
       
   902     CAlfBrush *titleDividerBgBrush = iAppUi.FsTextureManager()->TitleDividerBgBrushL();
       
   903     separatorVisualiser->SetBackgroundBrush( titleDividerBgBrush );
       
   904 
       
   905     iDownloadedVisualiser = separatorVisualiser;
       
   906 	CleanupStack::Pop( separatorVisualiser );
       
   907 	CleanupStack::Pop( separatorData );
       
   908     iDownloadedNode = iAttachmentsList->InsertNodeL(*separatorData, *separatorVisualiser, KFsTreeRootID);
       
   909 
       
   910 	separatorData = CFsTreePlainOneLineNodeData::NewL();
       
   911 	CleanupStack::PushL( separatorData );
       
   912 
       
   913     separatorVisualiser = CFsTreePlainOneLineNodeVisualizer::NewL(*iAttachmentsList->TreeControl());
       
   914     CleanupStack::PushL( separatorVisualiser );
       
   915 	resourceString = StringLoader::LoadLC( R_FSE_VIEWER_ATTACHMENTS_LIST_NOT_YET_DOWNLOADED );
       
   916 	separatorData->SetDataL( *resourceString );
       
   917 	CleanupStack::PopAndDestroy( resourceString );
       
   918     separatorVisualiser->SetSize(TSize(screenRect.Width(), iAppUi.LayoutHandler()->OneLineListNodeHeight()));
       
   919     separatorVisualiser->SetExtendable(EFalse);
       
   920 	// Set font height
       
   921     // <cmail> Platform layout changes
       
   922     //separatorVisualiser->SetFontHeight( iAppUi.LayoutHandler()->ListItemFontHeightInTwips() );
       
   923     separatorVisualiser->SetFontHeight( textStyle.TextSizeInTwips() );
       
   924     // </cmail> Platform layout changes
       
   925 	// Set font bolding
       
   926 	separatorVisualiser->SetTextBold( ETrue );
       
   927 	
       
   928   	// Set correct skin text colors for the list items  
       
   929 	separatorVisualiser->SetFocusedStateTextColor( focusedColor );
       
   930    	separatorVisualiser->SetNormalStateTextColor( normalNodeColor );
       
   931    	// <cmail>
       
   932    	//separatorVisualiser->SetBackgroundColor( iAppUi.LayoutHandler()->ListNodeBackgroundColor() );
       
   933    	// </cmail>
       
   934     separatorVisualiser->SetBackgroundBrush( titleDividerBgBrush );
       
   935    	
       
   936 	separatorData->SetIconExpanded( iAppUi.FsTextureManager()->TextureByIndex( EListTextureNodeExpanded ) );
       
   937 	separatorData->SetIconCollapsed( iAppUi.FsTextureManager()->TextureByIndex( EListTextureNodeCollapsed ) );
       
   938     // <cmail> Platform layout changes
       
   939     // textStyle = iAppUi.LayoutHandler()->FSTextStyleFromIdL( EFSFontTypeSmall );
       
   940 	separatorVisualiser->SetTextStyleId ( textStyle.Id() );
       
   941     // </cmail> Platform layout changes
       
   942     iNotDownloadedNode = iAttachmentsList->InsertNodeL(*separatorData, *separatorVisualiser, KFsTreeRootID);
       
   943 	CleanupStack::Pop( separatorVisualiser );
       
   944 	CleanupStack::Pop( separatorData );    
       
   945 	iNotDownloadedVisualiser = separatorVisualiser;
       
   946 
       
   947 	}
       
   948 
       
   949 void CFSEmailUiAttachmentsListVisualiser::MoveItemToNodeL( TFsTreeItemId aItemId, TFsTreeItemId aTargetNodeId )
       
   950     {
       
   951     FUNC_LOG;
       
   952     TFsTreeItemId origParentNode = iAttachmentsList->Parent( aItemId );
       
   953     
       
   954     // Make the target node visible
       
   955     if ( iAttachmentsList->ItemVisualizer(aTargetNodeId).IsHidden() )
       
   956         {
       
   957         iAttachmentsTreeListVisualizer->UnhideItemL( aTargetNodeId ); 
       
   958         }
       
   959 
       
   960     // Expand the target node if it was collapsed. Otherwise the result would
       
   961     // be a node which has some hidden and some visible children.
       
   962     if ( !iAttachmentsList->IsExpanded(aTargetNodeId) )
       
   963         {
       
   964         iAttachmentsList->ExpandNodeL(aTargetNodeId);
       
   965         }
       
   966 
       
   967     iAttachmentsList->MoveItemL( aItemId, aTargetNodeId );          
       
   968 
       
   969     // Hide the previous parent of the moved item if it became empty
       
   970     if ( iAttachmentsList->IsEmpty(origParentNode) )
       
   971         {
       
   972         iAttachmentsTreeListVisualizer->HideItemL( origParentNode );
       
   973         }
       
   974     }
       
   975 
       
   976 // <cmail> Touch
       
   977 void CFSEmailUiAttachmentsListVisualiser::TreeListEventL( const TFsTreeListEvent aEvent, 
       
   978                                  	const TFsTreeItemId aId,
       
   979                                  	const TPoint& /*aPoint*/ )
       
   980 	{
       
   981     FUNC_LOG;
       
   982 
       
   983     switch(aEvent)
       
   984         {
       
   985         case MFsTreeListObserver::EFsTreeItemSelected: //from original code
       
   986             TryToOpenItemL( aId );
       
   987             break; 
       
   988         case MFsTreeListObserver::EFsTreeListItemTouchAction:
       
   989             DoHandleActionL(); 
       
   990             break; 
       
   991         case MFsTreeListObserver::EFsTreeListItemTouchLongTap:
       
   992             LaunchActionMenuL();  
       
   993             break; 
       
   994         case MFsTreeListObserver::EFsTreeListItemTouchFocused:
       
   995             SetMskL(); 
       
   996             break; 
       
   997         default:
       
   998             //Just ignore rest of events
       
   999             break;             
       
  1000         }                   
       
  1001 	}
       
  1002 
       
  1003 // ---------------------------------------------------------------------------
       
  1004 // CFSEmailUiAttachmentsListVisualiser::DoHandleActionL
       
  1005 // ---------------------------------------------------------------------------
       
  1006 //
       
  1007 void CFSEmailUiAttachmentsListVisualiser::DoHandleActionL( )
       
  1008     {
       
  1009     FUNC_LOG;
       
  1010 
       
  1011     TFsTreeItemId id = iAttachmentsList->FocusedItem(); 
       
  1012         
       
  1013     //Expand / Collapse
       
  1014     if ( iAttachmentsList->IsNode(id) )        
       
  1015         {
       
  1016         if( !iAttachmentsList->IsExpanded( id ) )
       
  1017             {
       
  1018             iAttachmentsList->ExpandNodeL(id);
       
  1019             }
       
  1020         else
       
  1021             {
       
  1022             iAttachmentsList->CollapseNodeL(id);
       
  1023             }
       
  1024         }
       
  1025     else //Open
       
  1026         {
       
  1027         TryToOpenItemL( id );
       
  1028         }
       
  1029   
       
  1030     SetMskL();
       
  1031     }
       
  1032 
       
  1033 //</cmail>
       
  1034 
       
  1035 
       
  1036 void CFSEmailUiAttachmentsListVisualiser::LaunchActionMenuL()
       
  1037 	{
       
  1038     FUNC_LOG;
       
  1039   	
       
  1040 	TAttachmentData* selectedItem = NULL;
       
  1041 	
       
  1042 	TRAPD( err, selectedItem = &iModel->GetItemL( iAttachmentsList->FocusedItem() ) );		
       
  1043 	
       
  1044 	if ( !err )
       
  1045 		{
       
  1046 		// Remove old items from action menu
       
  1047 	    CFSEmailUiActionMenu::RemoveAllL();
       
  1048 		
       
  1049 		// Construct item list
       
  1050 	    RFsEActionMenuIdList itemList;
       
  1051 	    CleanupClosePushL( itemList );
       
  1052 
       
  1053 		if ( IsCommandAvailableOnItem( FsEActionAttachmentOpen, selectedItem ) )
       
  1054 			{
       
  1055 			itemList.AppendL( FsEActionAttachmentOpen );
       
  1056 			}
       
  1057 
       
  1058 		if ( IsCommandAvailableOnItem( FsEActionAttachmentDownload, selectedItem ) )
       
  1059 			{
       
  1060 			itemList.AppendL( FsEActionAttachmentDownload );
       
  1061 			}
       
  1062 
       
  1063         if ( IsCommandAvailableOnItem( FsEActionAttachmentDownloadAll, selectedItem ) )
       
  1064             {
       
  1065             itemList.AppendL( FsEActionAttachmentDownloadAll );
       
  1066             }
       
  1067 
       
  1068 		if ( IsCommandAvailableOnItem( FsEActionAttachmentCancelDownload, selectedItem ) )
       
  1069 			{
       
  1070 			itemList.AppendL( FsEActionAttachmentCancelDownload );
       
  1071 			}
       
  1072 
       
  1073         if ( IsCommandAvailableOnItem( FsEActionAttachmentCancelAllDownloads, selectedItem ) )
       
  1074             {
       
  1075             itemList.AppendL( FsEActionAttachmentCancelAllDownloads );
       
  1076             }
       
  1077             
       
  1078 		if ( IsCommandAvailableOnItem( FsEActionAttachmentSave, selectedItem ) )
       
  1079 			{
       
  1080 			itemList.AppendL( FsEActionAttachmentSave );
       
  1081 			}
       
  1082 
       
  1083 		if ( IsCommandAvailableOnItem( FsEActionAttachmentSaveAll, selectedItem ) )
       
  1084 			{
       
  1085 			itemList.AppendL( FsEActionAttachmentSaveAll );
       
  1086 			}
       
  1087 
       
  1088         if ( IsCommandAvailableOnItem( FsEActionAttachmentClearFetchedContent, selectedItem ) )
       
  1089             {
       
  1090             itemList.AppendL( FsEActionAttachmentClearFetchedContent );
       
  1091             }
       
  1092 		
       
  1093 		// Execute action list and handle the menu command
       
  1094 	    //<cmail> touch
       
  1095         // Execute action list and handle the menu command
       
  1096 	    TActionMenuCustomItemId itemId = CFSEmailUiActionMenu::ExecuteL( itemList, EFscCustom, 0, this );
       
  1097 	    //</cmail>
       
  1098 	   	
       
  1099 	   	CleanupStack::PopAndDestroy( &itemList );
       
  1100 	   	
       
  1101 	  	switch( itemId )
       
  1102 	  		{
       
  1103 			case FsEActionAttachmentOpen:
       
  1104 			    HandleCommandL( EFsEmailUiCmdOpen );
       
  1105 			    break;
       
  1106 			case FsEActionAttachmentDownload:
       
  1107 			    HandleCommandL( EFsEmailUiCmdDownload );
       
  1108 			    break;
       
  1109 			case FsEActionAttachmentCancelDownload:
       
  1110                 HandleCommandL( EFsEmailUiCmdCancelDownload );
       
  1111 				break;
       
  1112 			case FsEActionAttachmentSave:
       
  1113 			    HandleCommandL( EFsEmailUiCmdSave );
       
  1114 			    break;
       
  1115 			case FsEActionAttachmentDownloadAll:
       
  1116 			    HandleCommandL( EFsEmailUiCmdDownloadAll );
       
  1117 	  			break;
       
  1118             case FsEActionAttachmentCancelAllDownloads:
       
  1119                 HandleCommandL( EFsEmailUiCmdCancelAllDownloads );
       
  1120                 break;
       
  1121             case FsEActionAttachmentSaveAll:
       
  1122                 HandleCommandL( EFsEmailUiCmdSaveAll );
       
  1123                 break;
       
  1124             case FsEActionAttachmentClearFetchedContent:
       
  1125                 HandleCommandL( EFsEmailUiCmdClearFetchedAttachment );
       
  1126                 break;
       
  1127 			default:
       
  1128 				break;
       
  1129 	  		}
       
  1130   		}
       
  1131 	}
       
  1132 
       
  1133 // ---------------------------------------------------------------------------
       
  1134 // Tells if the given command is available when the focus is on the given item
       
  1135 // ---------------------------------------------------------------------------
       
  1136 //
       
  1137 TBool CFSEmailUiAttachmentsListVisualiser::IsCommandAvailableOnItem( TInt aCommandId, 
       
  1138                                                                      const TAttachmentData* aFocusedItem /*= NULL*/ ) const
       
  1139     {
       
  1140     FUNC_LOG;
       
  1141     TBool available = EFalse;
       
  1142     
       
  1143     const RArray<TAttachmentData>& model = iModel->GetModel();
       
  1144 
       
  1145     switch ( aCommandId )
       
  1146         {
       
  1147         case EFsEmailUiCmdOpen:
       
  1148         case FsEActionAttachmentOpen:
       
  1149             {
       
  1150     		if ( aFocusedItem && aFocusedItem->downloadProgress == KComplete )
       
  1151     			{
       
  1152     			available = ETrue;
       
  1153     			}
       
  1154             }
       
  1155             break;
       
  1156 
       
  1157         case EFsEmailUiCmdDownload:
       
  1158         case FsEActionAttachmentDownload:
       
  1159             {
       
  1160             if (aFocusedItem)
       
  1161                 {
       
  1162                 TPartData partData = aFocusedItem->partData;
       
  1163                 
       
  1164                 TUint pluginId = partData.iMailBoxId.PluginId().iUid;
       
  1165                 
       
  1166                 TBool isPop3 = ( pluginId == KFsPop3PluginId );
       
  1167     
       
  1168                 if ( aFocusedItem->downloadProgress == KNone && 
       
  1169                      !iModel->IsDownloading( *aFocusedItem ) &&
       
  1170                      !isPop3 )
       
  1171                     {
       
  1172                     available = ETrue;
       
  1173                     }
       
  1174                 }
       
  1175             }
       
  1176             break;
       
  1177 
       
  1178         case EFsEmailUiCmdCancelDownload:
       
  1179         case FsEActionAttachmentCancelDownload:
       
  1180             {
       
  1181     		if ( aFocusedItem && iModel->IsDownloading( *aFocusedItem ) )
       
  1182     			{
       
  1183     			available = ETrue;
       
  1184     			}
       
  1185             }
       
  1186             break;
       
  1187 
       
  1188         // <cmail> Disabled until there is support in plugins.
       
  1189         case FsEActionAttachmentClearFetchedContent:
       
  1190         case EFsEmailUiCmdClearFetchedAttachment:
       
  1191     		if (  !iEmbeddedMsgMode  && aFocusedItem && !iModel->IsDownloading( *aFocusedItem ) )
       
  1192     			{
       
  1193                 available = aFocusedItem->downloadProgress > KNone;
       
  1194     			}
       
  1195     	    else
       
  1196 	            {
       
  1197 	            available = EFalse;
       
  1198 	            }
       
  1199             break;
       
  1200         // </cmail>
       
  1201         case EFsEmailUiCmdSave:
       
  1202         case FsEActionAttachmentSave:
       
  1203             {
       
  1204             // see if mailbox allows saving of embedded messages
       
  1205             CFSMailBox* mailbox = iAppUi.GetActiveMailbox();
       
  1206             
       
  1207             TBool canSaveMessages( mailbox && mailbox->HasCapability(
       
  1208             		EFSMboxCapaSupportsSavingOfEmbeddedMessages ) );
       
  1209             
       
  1210             // saving message type attachments of embedded messages is blocked
       
  1211             // due to limitations of the Activesync plugin
       
  1212     		if ( aFocusedItem && !iModel->IsDownloading( *aFocusedItem ) && 
       
  1213     			 (!iModel->IsMessage(*aFocusedItem) || !iEmbeddedMsgMode && canSaveMessages) )
       
  1214     			{
       
  1215 				available = ETrue;
       
  1216     			}
       
  1217             }
       
  1218             break;
       
  1219 
       
  1220         case EFsEmailUiCmdSaveAll:
       
  1221         case FsEActionAttachmentSaveAll:
       
  1222             {
       
  1223             // Save all is available if there is more than one attachment
       
  1224             // and none of them are currently being downloaded
       
  1225             if ( model.Count() > 1 )
       
  1226                 {
       
  1227                 available = ETrue;
       
  1228         		for ( TInt i=0; i<model.Count(); i++)
       
  1229         			{	
       
  1230         			if ( iModel->IsDownloading( model[i] ) )
       
  1231         				{
       
  1232        					available = EFalse;
       
  1233        					break;
       
  1234         				}
       
  1235         			}
       
  1236                 }
       
  1237            // In embedded message mode, save all needs to be blocked if there
       
  1238            // are any message type attachments. This is due to limitations of Activesync plugin.
       
  1239            if ( available && iEmbeddedMsgMode && iModel->IsThereAnyMessageAttachments() )
       
  1240                {
       
  1241                available = EFalse;
       
  1242                }
       
  1243             }
       
  1244             break;
       
  1245 
       
  1246         case EFsEmailUiCmdCancelAllDownloads:
       
  1247         case FsEActionAttachmentCancelAllDownloads:
       
  1248             {
       
  1249             // Cancel all is available if there is more than one ongoing download
       
  1250             TInt downloads = 0;
       
  1251     		for ( TInt i=0; i<model.Count(); i++)
       
  1252     			{	
       
  1253     			if ( iModel->IsDownloading( model[i] ) )
       
  1254     				{
       
  1255     				downloads++;
       
  1256     				}
       
  1257     			}
       
  1258     		if ( downloads > 1 )
       
  1259     		    {
       
  1260     		    available = ETrue;
       
  1261     		    }
       
  1262             }
       
  1263             break;
       
  1264 
       
  1265         case EFsEmailUiCmdDownloadAll:
       
  1266         case FsEActionAttachmentDownloadAll:
       
  1267             {
       
  1268             // Download all is available there is more than one attachments
       
  1269             // for which "Download" command is available.
       
  1270             // For POP only "Download All" is available due to protocols's
       
  1271             // restrictions.
       
  1272             TInt downloadableFiles = 0;
       
  1273 
       
  1274             TBool popChecked = EFalse;
       
  1275 
       
  1276             TBool isPop3 = EFalse;
       
  1277 
       
  1278             TInt count = model.Count();
       
  1279             
       
  1280             for ( TInt i = 0; i < count; i++ )
       
  1281                 {
       
  1282                 const TAttachmentData& item = model[i];
       
  1283                 
       
  1284                 if ( item.downloadProgress == KNone &&
       
  1285                         !iModel->IsDownloading( item ) )
       
  1286                     {
       
  1287                     downloadableFiles++;
       
  1288                     }
       
  1289 
       
  1290                 if ( !popChecked )
       
  1291                     {
       
  1292                     TPartData partData = item.partData;
       
  1293                     
       
  1294                     TUint pluginId = partData.iMailBoxId.PluginId().iUid;
       
  1295                     
       
  1296                     isPop3 = ( pluginId == KFsPop3PluginId );
       
  1297 
       
  1298                     popChecked = ETrue;
       
  1299                     }
       
  1300                 }
       
  1301 
       
  1302             if ( downloadableFiles > 1 ||
       
  1303                     ( downloadableFiles > 0 && isPop3 ) )
       
  1304                 {
       
  1305                 available = ETrue;
       
  1306                 }
       
  1307             }
       
  1308             break;
       
  1309 
       
  1310         case EFsEmailUiCmdMailActions:
       
  1311             {
       
  1312             // Actions menu is available if any sub item is available
       
  1313             available = 
       
  1314                 IsCommandAvailableOnItem( EFsEmailUiCmdOpen, aFocusedItem ) ||
       
  1315                 IsCommandAvailableOnItem( EFsEmailUiCmdDownload, aFocusedItem ) ||
       
  1316                 IsCommandAvailableOnItem( EFsEmailUiCmdCancelDownload, aFocusedItem ) ||
       
  1317                 IsCommandAvailableOnItem( EFsEmailUiCmdSave, aFocusedItem ) ||
       
  1318                 IsCommandAvailableOnItem( EFsEmailUiCmdDownloadAll, aFocusedItem ) ||
       
  1319                 IsCommandAvailableOnItem( EFsEmailUiCmdCancelAllDownloads, aFocusedItem ) ||
       
  1320                 IsCommandAvailableOnItem( EFsEmailUiCmdSaveAll, aFocusedItem ) ||
       
  1321                 IsCommandAvailableOnItem( EFsEmailUiCmdClearFetchedAttachment, aFocusedItem );
       
  1322             }
       
  1323             break;
       
  1324             
       
  1325         default:
       
  1326             // All commands not separately specified are always available
       
  1327             available = ETrue;
       
  1328             break;
       
  1329         }
       
  1330         
       
  1331     return available;
       
  1332     }
       
  1333 
       
  1334 // ---------------------------------------------------------------------------
       
  1335 // Creates the text shown on the second line of the attachment item
       
  1336 // ---------------------------------------------------------------------------
       
  1337 //
       
  1338 HBufC* CFSEmailUiAttachmentsListVisualiser::CreateSecondLineTextLC( const TAttachmentData& aAttachment ) const
       
  1339     {
       
  1340     FUNC_LOG;
       
  1341     // File extension
       
  1342 	TPtrC extString = TParsePtrC( aAttachment.fileName ).Ext();
       
  1343 	// It seems to vary if preceeding dot is included in the file extension. Remove it if present.
       
  1344 	if ( extString.Length() && extString[0] == '.' )
       
  1345 	    {
       
  1346 	    extString.Set( extString.Mid(1) );
       
  1347 	    }
       
  1348 
       
  1349     // File size	
       
  1350 	HBufC* sizeString = CFSEmailUiAttachmentsListModel::CreateSizeDescLC( aAttachment.fileSize );
       
  1351 
       
  1352     // Download progress
       
  1353     HBufC* progressString = NULL;
       
  1354 	if ( iModel->IsDownloading( aAttachment ) )
       
  1355 		{
       
  1356 		progressString = StringLoader::LoadLC( R_FSE_VIEWER_ATTACHMENTS_LIST_DOWNLOADING, aAttachment.downloadProgress  );
       
  1357 		}
       
  1358 	else
       
  1359 	    {
       
  1360 	    progressString = KNullDesC().AllocLC();
       
  1361 	    }
       
  1362 
       
  1363     // Combine the accumulated data to one buffer
       
  1364     HBufC* result = HBufC::NewL( extString.Length() + 
       
  1365                                  KSpace().Length() + 
       
  1366                                  sizeString->Length() + 
       
  1367                                  KSpace().Length() + 
       
  1368                                  progressString->Length() );
       
  1369     TPtr resultPtr = result->Des();
       
  1370     resultPtr.Append( extString );
       
  1371     resultPtr.Append( KSpace );
       
  1372     resultPtr.Append( *sizeString );
       
  1373     resultPtr.Append( KSpace );
       
  1374     resultPtr.Append( *progressString );
       
  1375     	
       
  1376 	CleanupStack::PopAndDestroy( progressString );
       
  1377 	CleanupStack::PopAndDestroy( sizeString );
       
  1378 	
       
  1379 	CleanupStack::PushL( result );
       
  1380 	return result;
       
  1381     }
       
  1382 
       
  1383 // ---------------------------------------------------------------------------
       
  1384 // Attempt to open the given item. Start downloading if the item is not
       
  1385 // downloaded or show note if it's currently being downloaded.
       
  1386 // ---------------------------------------------------------------------------
       
  1387 //
       
  1388 void CFSEmailUiAttachmentsListVisualiser::TryToOpenItemL( TFsTreeItemId aId )
       
  1389     {
       
  1390     FUNC_LOG;
       
  1391     TAttachmentData* attachment = iModel->GetItem( aId );
       
  1392     
       
  1393     if ( attachment )
       
  1394         {
       
  1395         if ( iModel->IsDownloading( *attachment ) )
       
  1396             {
       
  1397             TFsEmailUiUtility::ShowInfoNoteL( R_FSE_VIEWER_NOTE_ATTACHMENT_DOWNLOADING_PROGRESS );
       
  1398             }
       
  1399         else if ( attachment->downloadProgress != KComplete )
       
  1400             {
       
  1401             iModel->StartDownloadL( aId );
       
  1402             }
       
  1403         else
       
  1404             {
       
  1405             TFsEmailUiUtility::OpenAttachmentL( attachment->partData );
       
  1406             }
       
  1407         }
       
  1408     }
       
  1409 
       
  1410 // ---------------------------------------------------------------------------
       
  1411 // Show confirmation note and remove contents of given attachment item
       
  1412 // if user accepts. Does nothing if given ID doesn't match an attachment item.
       
  1413 // ---------------------------------------------------------------------------
       
  1414 //
       
  1415 void CFSEmailUiAttachmentsListVisualiser::RemoveAttachmentContentL( TFsTreeItemId aId )
       
  1416     {
       
  1417     FUNC_LOG;
       
  1418     TAttachmentData* item = iModel->GetItem( aId );
       
  1419         
       
  1420     if ( IsCommandAvailableOnItem( EFsEmailUiCmdClearFetchedAttachment, item ) )
       
  1421         {
       
  1422         TInt reallyClear = 
       
  1423             TFsEmailUiUtility::ShowConfirmationQueryL( R_FSE_VIEWER_CLEAR_FETCHED_QUERY );
       
  1424         if ( reallyClear )
       
  1425             {
       
  1426             iModel->RemoveContentL( aId );
       
  1427             // Move item back to not-yet-downloaded node only if contents were actually
       
  1428             // removed succesfully
       
  1429             if ( !iModel->IsCompletelyDownloadedL( *item ) )
       
  1430                 {
       
  1431                 MoveItemToNodeL( aId, iNotDownloadedNode );
       
  1432                 }
       
  1433             }
       
  1434         // focused item or proper MSK action for it may have changed
       
  1435         SetMskL();
       
  1436         }
       
  1437     }
       
  1438 
       
  1439 // ---------------------------------------------------------------------------
       
  1440 // If there is one or more expanded nodes, collapses all nodes.
       
  1441 // Otherwise expands all nodes.
       
  1442 // ---------------------------------------------------------------------------
       
  1443 //
       
  1444 void CFSEmailUiAttachmentsListVisualiser::ShortcutCollapseExpandAllToggleL()
       
  1445     {
       
  1446     FUNC_LOG;
       
  1447     TBool collapseAllNodes( EFalse );
       
  1448     TInt count = iAttachmentsList->CountChildren( KFsTreeRootID );
       
  1449     for ( TInt i=0 ; i<count ; i++ )
       
  1450         {
       
  1451         TFsTreeItemId curId = iAttachmentsList->Child(KFsTreeRootID, i);
       
  1452         if ( iAttachmentsList->IsNode( curId ) &&
       
  1453              iAttachmentsList->IsExpanded( curId ) )
       
  1454             {
       
  1455             collapseAllNodes = ETrue;
       
  1456             break;
       
  1457             }	
       
  1458         }
       
  1459 
       
  1460     if ( collapseAllNodes )
       
  1461         {
       
  1462         iAttachmentsTreeListVisualizer->CollapseAllL();        
       
  1463         }
       
  1464     else
       
  1465         {
       
  1466        	TFsTreeItemId prevId = iAttachmentsList->FocusedItem(); // the focus may fall out of the screen unless manually reset
       
  1467         iAttachmentsTreeListVisualizer->ExpandAllL();
       
  1468     	iAttachmentsTreeListVisualizer->SetFocusedItemL( prevId );    
       
  1469         }
       
  1470     }
       
  1471 
       
  1472 // ---------------------------------------------------------------------------
       
  1473 // Moves the focus to the topmost item
       
  1474 // ---------------------------------------------------------------------------
       
  1475 //
       
  1476 void CFSEmailUiAttachmentsListVisualiser::GoToTopL()
       
  1477     {
       
  1478     FUNC_LOG;
       
  1479     TInt topLevelCount = iAttachmentsList->CountChildren( KFsTreeRootID );
       
  1480     if ( topLevelCount > 1)
       
  1481         {
       
  1482         // the item #0 is the non-focusable header item
       
  1483         TInt indexToFocus = 1;
       
  1484         TFsTreeItemId topId = iAttachmentsList->Child(KFsTreeRootID, indexToFocus);
       
  1485         
       
  1486         // If the top item is invisible, move down until we find a visible item
       
  1487         while ( iAttachmentsList->ItemVisualizer(topId).IsHidden() && 
       
  1488                 indexToFocus < iAttachmentsList->CountChildren(KFsTreeRootID)-1 )
       
  1489             {
       
  1490             indexToFocus++;
       
  1491             topId = iAttachmentsList->Child(KFsTreeRootID, indexToFocus);
       
  1492             }
       
  1493 
       
  1494         iAttachmentsTreeListVisualizer->SetFocusedItemL( topId );            
       
  1495         }
       
  1496     }
       
  1497 
       
  1498 // ---------------------------------------------------------------------------
       
  1499 // Moves the focus to the bottommost item
       
  1500 // ---------------------------------------------------------------------------
       
  1501 //
       
  1502 void CFSEmailUiAttachmentsListVisualiser::GoToBottomL()
       
  1503     {
       
  1504     FUNC_LOG;
       
  1505     TInt topLevelCount = iAttachmentsList->CountChildren( KFsTreeRootID );
       
  1506     if ( topLevelCount )
       
  1507         {
       
  1508         TInt lastIndex = topLevelCount-1;
       
  1509         TFsTreeItemId bottomId = iAttachmentsList->Child(KFsTreeRootID, lastIndex);
       
  1510         // If the bottom item is invisible, move up until we find a visible item
       
  1511         while ( iAttachmentsList->ItemVisualizer(bottomId).IsHidden() && 
       
  1512                 lastIndex > 0 )
       
  1513             {
       
  1514             lastIndex--;
       
  1515             bottomId = iAttachmentsList->Child(KFsTreeRootID, lastIndex);
       
  1516             }
       
  1517         
       
  1518         // If the last item on top level is an expanded node, navigate to its last child
       
  1519         if ( iAttachmentsList->IsNode(bottomId) )
       
  1520             {
       
  1521             TInt childCount = iAttachmentsList->CountChildren(bottomId);
       
  1522             if ( childCount && iAttachmentsList->IsExpanded(bottomId) )
       
  1523                 {
       
  1524                 bottomId = iAttachmentsList->Child( bottomId, childCount-1 );
       
  1525                 }
       
  1526             }
       
  1527 
       
  1528         iAttachmentsTreeListVisualizer->SetFocusedItemL( bottomId );            
       
  1529         }
       
  1530     }
       
  1531 
       
  1532 // ---------------------------------------------------------------------------
       
  1533 // Sets up the title pane to show the mail title
       
  1534 // ---------------------------------------------------------------------------
       
  1535 //
       
  1536 void CFSEmailUiAttachmentsListVisualiser::SetupTitlePaneTextL()
       
  1537     {
       
  1538     FUNC_LOG;
       
  1539     // <cmail> UI updates: title text is "Attachments" instead of the mail
       
  1540     //         subject text.
       
  1541 
       
  1542     // </cmail>
       
  1543     HBufC* titleText = StringLoader::LoadLC( R_FSE_VIEWER_ATTACHMENTS_VIEW_TITLE );
       
  1544     iAppUi.SetTitlePaneTextL( *titleText );
       
  1545     CleanupStack::PopAndDestroy( titleText );
       
  1546     }
       
  1547 
       
  1548 // ---------------------------------------------------------------------------
       
  1549 // HandleMailBoxEventL
       
  1550 // Mailbox event handler, responds to events sent by the plugin.
       
  1551 // ---------------------------------------------------------------------------
       
  1552 //
       
  1553 void CFSEmailUiAttachmentsListVisualiser::HandleMailBoxEventL( TFSMailEvent aEvent,
       
  1554     TFSMailMsgId aMailbox, TAny* aParam1, TAny* /*aParam2*/, TAny* /*aParam3*/ )
       
  1555     {
       
  1556     FUNC_LOG;
       
  1557     TFsTreeItemId nullId(0);
       
  1558     TPartData partData = iModel->GetMessageL( nullId );
       
  1559 
       
  1560     if ( iFirstStartCompleted && aMailbox == partData.iMailBoxId && 
       
  1561     	 (aEvent == TFSEventMailDeleted || aEvent == TFSEventMailDeletedFromViewer) && aParam1 && iModel ) // Safety, in list events that only concern active mailbox are handled 
       
  1562         {
       
  1563 		RArray<TFSMailMsgId>* removedEntries = static_cast< RArray<TFSMailMsgId>* >(aParam1);
       
  1564 		for ( TInt i=0 ; i < removedEntries->Count() ; i++ )
       
  1565 			{
       
  1566 			if ( partData.iMessageId == (*removedEntries)[i] )
       
  1567 				{
       
  1568 				TMailListActivationData tmp;	
       
  1569 				tmp.iMailBoxId = iAppUi.GetActiveMailboxId();
       
  1570 				const TPckgBuf<TMailListActivationData> pkgOut( tmp );	
       
  1571 				iAppUi.EnterFsEmailViewL( MailListId, KStartListReturnToPreviousFolder, pkgOut );
       
  1572 				break;
       
  1573 				}			
       
  1574 			}
       
  1575         }
       
  1576     }
       
  1577 
       
  1578 // <cmail>
       
  1579 // ---------------------------------------------------------------------------
       
  1580 // ActionMenuPosition
       
  1581 // ---------------------------------------------------------------------------
       
  1582 //
       
  1583 TPoint CFSEmailUiAttachmentsListVisualiser::ActionMenuPosition()
       
  1584     {
       
  1585     TAlfRealRect focusRect;
       
  1586     TFsTreeItemId listItemId = iAttachmentsList->FocusedItem();    
       
  1587     iAttachmentsList->GetItemDisplayRectTarget(listItemId, focusRect);
       
  1588     return focusRect.iTl;
       
  1589     }
       
  1590 // </cmail>
       
  1591