emailuis/emailui/src/FreestyleEmailUiMailListVisualiser.cpp
branchRCL_3
changeset 10 f5907b1a1053
parent 8 e1b6206813b4
child 11 0396474f30f5
equal deleted inserted replaced
8:e1b6206813b4 10:f5907b1a1053
    86 #include "FreestyleEmailUiContactHandler.h"
    86 #include "FreestyleEmailUiContactHandler.h"
    87 #include "FreestyleEmailUiLauncherGridVisualiser.h"
    87 #include "FreestyleEmailUiLauncherGridVisualiser.h"
    88 #include "FreestyleEmailUiHtmlViewerView.h"
    88 #include "FreestyleEmailUiHtmlViewerView.h"
    89 #include "FSDelayedLoader.h"
    89 #include "FSDelayedLoader.h"
    90 #include "FSEmail.pan"
    90 #include "FSEmail.pan"
       
    91 #include "fsemailstatuspaneindicatorhandler.h"
    91 
    92 
    92 // CONST VALUES
    93 // CONST VALUES
    93 const TInt KControlBarTransitionTime = 250;
    94 const TInt KControlBarTransitionTime = 250;
    94 const TInt KMaxPreviewPaneLength = 60;
    95 const TInt KMaxPreviewPaneLength = 60;
    95 const TInt KMsgUpdaterTimerDelay = 2500000; // Time to update list, 2,5sec
    96 const TInt KMsgUpdaterTimerDelay = 2500000; // Time to update list, 2,5sec
   108     {
   109     {
   109     delete ptr;
   110     delete ptr;
   110     ptr = NULL;
   111     ptr = NULL;
   111     }
   112     }
   112 
   113 
       
   114 // TDeleteTask
       
   115 // Task class for deleting mail
       
   116 // ---------------------------------------------------------------------------
       
   117 // Class definition
       
   118 // ---------------------------------------------------------------------------
       
   119 template <class T> struct TDeleteTask
       
   120     {
       
   121     
       
   122 public:
       
   123     
       
   124     typedef void ( T::*TDeleteMethod )( const RFsTreeItemIdList& aEntries );
       
   125     
       
   126 public:    
       
   127     
       
   128     TDeleteTask(T& aObject, TDeleteMethod aMethod);    
       
   129     ~TDeleteTask();
       
   130     void ExecuteL();
       
   131     RFsTreeItemIdList& Entries();
       
   132     void Reset();
       
   133     
       
   134 private:
       
   135 
       
   136     T& iObject;
       
   137     TDeleteMethod iMethod;    
       
   138     RFsTreeItemIdList iEntries;
       
   139     
       
   140     };
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // TDeleteTask<T>::TDeleteTask
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 template <class T> TDeleteTask<T>::TDeleteTask( T& aObject, TDeleteMethod aMethod )
       
   147     : iObject(aObject), iMethod(aMethod)
       
   148     {    
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // TDeleteTask<T>::~TDeleteTask
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 template <class T> TDeleteTask<T>::~TDeleteTask()
       
   156     {
       
   157     iEntries.Close();
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // TDeleteTask<T>::ExecuteL
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 template <class T> void TDeleteTask<T>::ExecuteL()
       
   165     {
       
   166     (iObject.*iMethod)(iEntries);
       
   167     Reset();
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // TDeleteTask<T>::Entries
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 template <class T> RFsTreeItemIdList& TDeleteTask<T>::Entries()
       
   175     {
       
   176     return iEntries;
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // TDeleteTask<T>::Reset
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 template <class T> void TDeleteTask<T>::Reset()
       
   184     {
       
   185     iEntries.Reset();
       
   186     }
   113 // CMailListModelUpdater
   187 // CMailListModelUpdater
   114 
   188 
   115 // ---------------------------------------------------------------------------
   189 // ---------------------------------------------------------------------------
   116 // Constructor
   190 // Constructor
   117 // ---------------------------------------------------------------------------
   191 // ---------------------------------------------------------------------------
   338 	iFirstStartCompleted = EFalse;
   412 	iFirstStartCompleted = EFalse;
   339 
   413 
   340 	iAsyncCallback = new (ELeave) CAsyncCallBack( CActive::EPriorityStandard );
   414 	iAsyncCallback = new (ELeave) CAsyncCallBack( CActive::EPriorityStandard );
   341 	iAsyncRedrawer = new (ELeave) CAsyncCallBack( CActive::EPriorityLow );
   415 	iAsyncRedrawer = new (ELeave) CAsyncCallBack( CActive::EPriorityLow );
   342 	iLastFocus = EFalse;
   416 	iLastFocus = EFalse;
       
   417     iDeleteTask = new (ELeave) TDeleteTask<CFSEmailUiMailListVisualiser> (*this, HandleDeleteTaskL);
       
   418 
       
   419 	iTouchFeedBack = MTouchFeedback::Instance();
   343  	}
   420  	}
   344 
   421 
   345 // CFSEmailUiMailListVisualiser::DoFirstStartL()
   422 // CFSEmailUiMailListVisualiser::DoFirstStartL()
   346 // Purpose of this function is to do first start things only when list is
   423 // Purpose of this function is to do first start things only when list is
   347 // really needed to be shown. Implemented to make app startuo faster.
   424 // really needed to be shown. Implemented to make app startuo faster.
   481 // ---------------------------------------------------------------------------
   558 // ---------------------------------------------------------------------------
   482 //
   559 //
   483 CFSEmailUiMailListVisualiser::~CFSEmailUiMailListVisualiser()
   560 CFSEmailUiMailListVisualiser::~CFSEmailUiMailListVisualiser()
   484     {
   561     {
   485     FUNC_LOG;
   562     FUNC_LOG;
       
   563     if (iExtension)
       
   564         {
       
   565         iAppUi.GetMailClient()->ReleaseExtension(iExtension);
       
   566         }
   486     SafeDelete(iMailListModelUpdater);
   567     SafeDelete(iMailListModelUpdater);
   487     SafeDelete(iMailFolder);
   568     SafeDelete(iMailFolder);
   488     delete iTouchManager;
   569     delete iTouchManager;
   489     delete iStylusPopUpMenu;
   570     delete iStylusPopUpMenu;
   490     delete iMailList;
   571     delete iMailList;
   491     delete iNewEmailText;
   572     delete iNewEmailText;
   492 
   573 
   493 	// Don't construct this anywhere else than in constructor.
   574 	// Don't construct this anywhere else than in constructor.
   494 	// Don't delete anywhere else thatn here to avoid NULL checks.
   575 	// Don't delete anywhere else thatn here to avoid NULL checks.
   495     delete iModel;
   576     delete iModel;
       
   577     
       
   578     delete iDeleteTask;
   496     }
   579     }
   497 
   580 
   498 void CFSEmailUiMailListVisualiser::PrepareForExit()
   581 void CFSEmailUiMailListVisualiser::PrepareForExit()
   499     {
   582     {
   500     FUNC_LOG;
   583     FUNC_LOG;
   534         }
   617         }
   535     SafeDelete(iMailFolder);
   618     SafeDelete(iMailFolder);
   536     iTreeItemArray.Reset();
   619     iTreeItemArray.Reset();
   537 	// Reset, not delete to avoid NULL checks.
   620 	// Reset, not delete to avoid NULL checks.
   538     iModel->Reset();
   621     iModel->Reset();
       
   622     // Resources freed, new start required
       
   623     iFirstStartCompleted = EFalse;
   539     }
   624     }
   540 
   625 
   541 // ---------------------------------------------------------------------------
   626 // ---------------------------------------------------------------------------
   542 // Returns reference to mail list.
   627 // Returns reference to mail list.
   543 // ---------------------------------------------------------------------------
   628 // ---------------------------------------------------------------------------
   600             iMailList->SetFocusedItemL( iTreeItemArray[0].iListItemId );
   685             iMailList->SetFocusedItemL( iTreeItemArray[0].iListItemId );
   601             }
   686             }
   602         }
   687         }
   603     SetListAndCtrlBarFocusL();
   688     SetListAndCtrlBarFocusL();
   604     iAppUi.StartMonitoringL();
   689     iAppUi.StartMonitoringL();
   605     TIMESTAMP( "Locally stored messages fetched for message list" );    
   690     TIMESTAMP( "Locally stored messages fetched for message list" );
   606     }
   691     }
   607 
   692 
   608 // ---------------------------------------------------------------------------
   693 // ---------------------------------------------------------------------------
   609 // @see CMailListModelUpdater::MObserver::UpdateCancelled
   694 // @see CMailListModelUpdater::MObserver::UpdateCancelled
   610 // ---------------------------------------------------------------------------
   695 // ---------------------------------------------------------------------------
  1080                     static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(idx) );
  1165                     static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(idx) );
  1081                 TFsTreeItemId nextNodeId = nextNode->CorrespondingListId();
  1166                 TFsTreeItemId nextNodeId = nextNode->CorrespondingListId();
  1082                 TInt nodeIdxUnderRoot = iMailList->ChildIndex( KFsTreeRootID, nextNodeId );
  1167                 TInt nodeIdxUnderRoot = iMailList->ChildIndex( KFsTreeRootID, nextNodeId );
  1083                 InsertNodeItemL( idx-1, nodeIdxUnderRoot, aAllowRefresh );
  1168                 InsertNodeItemL( idx-1, nodeIdxUnderRoot, aAllowRefresh );
  1084                 }
  1169                 }
  1085             moveViewPortPosition += iAppUi.LayoutHandler()->OneLineListItemHeight(); 
  1170             moveViewPortPosition += iAppUi.LayoutHandler()->OneLineListItemHeight();
  1086             }
  1171             }
  1087         else
  1172         else
  1088             {
  1173             {
  1089             // Suitable parent node exists and was found
  1174             // Suitable parent node exists and was found
  1090             parentNode = static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(parentIdx) );
  1175             parentNode = static_cast<CFSEmailUiMailListModelItem*>( iModel->Item(parentIdx) );
  1099     // Insert the tree list item
  1184     // Insert the tree list item
  1100     TPoint viewPortCenterPos = iMailTreeListVisualizer->ViewPosition();
  1185     TPoint viewPortCenterPos = iMailTreeListVisualizer->ViewPosition();
  1101     TPoint viewPortTopPos = iMailTreeListVisualizer->ViewPortTopPosition();
  1186     TPoint viewPortTopPos = iMailTreeListVisualizer->ViewPortTopPosition();
  1102     TInt itemPos = iMailTreeListVisualizer->GetItemWorldPosition( idx );
  1187     TInt itemPos = iMailTreeListVisualizer->GetItemWorldPosition( idx );
  1103     TBool refresh = viewPortTopPos.iY != 0 && itemPos < viewPortCenterPos.iY;
  1188     TBool refresh = viewPortTopPos.iY != 0 && itemPos < viewPortCenterPos.iY;
  1104      
  1189 
  1105     if( refresh )
  1190     if( refresh )
  1106     	{
  1191     	{
  1107 		InsertListItemL( idx, parentId, childIdx, EFalse );
  1192 		InsertListItemL( idx, parentId, childIdx, EFalse );
  1108 		// viewPort update needed
  1193 		// viewPort update needed
  1109 		moveViewPortPosition += iAppUi.LayoutHandler()->TwoLineListItemHeight(); // add mail item height
  1194 		moveViewPortPosition += iAppUi.LayoutHandler()->TwoLineListItemHeight(); // add mail item height
  1249 
  1334 
  1250 	if ( !iFirstStartCompleted )
  1335 	if ( !iFirstStartCompleted )
  1251 	    {
  1336 	    {
  1252 	    DoFirstStartL();
  1337 	    DoFirstStartL();
  1253 	    }
  1338 	    }
       
  1339     // set when editor was called so reset is needed i.e. here (Called by DoActivate)
       
  1340    	iMailOpened = EFalse; 
  1254 
  1341 
  1255     // Make sure that pending popup is not displayd
  1342     // Make sure that pending popup is not displayd
  1256 	if ( iAppUi.FolderList().IsPopupShown() )
  1343 	if ( iAppUi.FolderList().IsPopupShown() )
  1257         {
  1344         {
  1258         iAppUi.FolderList().HidePopupL();
  1345         iAppUi.FolderList().HidePopupL();
  1275 
  1362 
  1276     // Set control bar and list layout size always in activation
  1363     // Set control bar and list layout size always in activation
  1277     TRect clientRect = iAppUi.ClientRect();
  1364     TRect clientRect = iAppUi.ClientRect();
  1278     iScreenAnchorLayout->SetSize( clientRect.Size() );
  1365     iScreenAnchorLayout->SetSize( clientRect.Size() );
  1279     SetMailListLayoutAnchors();
  1366     SetMailListLayoutAnchors();
  1280     TInt listHeight = clientRect.Height() - iAppUi.LayoutHandler()->ControlBarHeight();
       
  1281     iListLayout->SetSize( TSize( clientRect.Width(), listHeight ) ); // needs to be set separately to avoid layout problems in some special cases
       
  1282     ScaleControlBarL();
  1367     ScaleControlBarL();
  1283     SetListAndCtrlBarFocusL();
  1368     SetListAndCtrlBarFocusL();
  1284 
  1369 
  1285 	// Update mail list settings and date formats, is done every time
  1370 	// Update mail list settings and date formats, is done every time
  1286 	// the user might have changed these in settings, so the list needs to refresh
  1371 	// the user might have changed these in settings, so the list needs to refresh
  1295 	UpdateMailListSettingsL();
  1380 	UpdateMailListSettingsL();
  1296 	UpdateMailListTimeDateSettings();
  1381 	UpdateMailListTimeDateSettings();
  1297 
  1382 
  1298 	// Check for changed settings, in that case a complete list refresh is needed
  1383 	// Check for changed settings, in that case a complete list refresh is needed
  1299 	TBool refreshNeeded(EFalse);
  1384 	TBool refreshNeeded(EFalse);
  1300 	if ( iSkinChanged
  1385 	if ( aCustomMessageId == KStartListWithFolderIdFromHomeScreen
       
  1386 	     || iSkinChanged
  1301 	     || iDateChanged
  1387 	     || iDateChanged
  1302 	     || iListMode != prevListMode
  1388 	     || iListMode != prevListMode
  1303 		 || iNodesInUse != prevNodesmode
  1389 		 || iNodesInUse != prevNodesmode
  1304 		 || iCurrentZoomLevel != prevZoomLevel
  1390 		 || iCurrentZoomLevel != prevZoomLevel
  1305 		 || prevDateFormats.iDateFormat != iDateFormats.iDateFormat
  1391 		 || prevDateFormats.iDateFormat != iDateFormats.iDateFormat
  1306 		 || prevDateFormats.iTimeFormat != iDateFormats.iTimeFormat
  1392 		 || prevDateFormats.iTimeFormat != iDateFormats.iTimeFormat
  1307 		 || prevDateFormats.iAmPmPosition != iDateFormats.iAmPmPosition
  1393 		 || prevDateFormats.iAmPmPosition != iDateFormats.iAmPmPosition
  1308 		 || prevDateFormats.iDateSeparator != iDateFormats.iDateSeparator
  1394 		 || prevDateFormats.iDateSeparator.GetNumericValue() != iDateFormats.iDateSeparator.GetNumericValue()
  1309 		 || prevDateFormats.iTimeSeparator != iDateFormats.iTimeSeparator )
  1395 		 || prevDateFormats.iTimeSeparator.GetNumericValue() != iDateFormats.iTimeSeparator.GetNumericValue() )
  1310 		{
  1396 		{
  1311 		refreshNeeded = ETrue;
  1397 		refreshNeeded = ETrue;
  1312 		iSkinChanged = EFalse;
  1398 		iSkinChanged = EFalse;
  1313 		iDateChanged = EFalse;
  1399 		iDateChanged = EFalse;
  1314 		}
  1400 		}
  1417             activationData.iFolderId = iAppUi.GetActiveBoxInboxId();
  1503             activationData.iFolderId = iAppUi.GetActiveBoxInboxId();
  1418             }
  1504             }
  1419         }
  1505         }
  1420 
  1506 
  1421     // NOW WE HAVE A VALID MAILBOX AND FOLDER ID.
  1507     // NOW WE HAVE A VALID MAILBOX AND FOLDER ID.
       
  1508     // Tries to create an extension for the Ozone plugin
       
  1509     CreateExtensionL();
  1422 
  1510 
  1423     // CHECK IF MODEL NEEDS TO BE UPDATED
  1511     // CHECK IF MODEL NEEDS TO BE UPDATED
  1424     if ( activationData.iMailBoxId != prevMailBoxId ||
  1512     if ( activationData.iMailBoxId != prevMailBoxId ||
  1425          activationData.iFolderId != prevFolderId ||
  1513          activationData.iFolderId != prevFolderId ||
  1426          activationData.iRequestRefresh ||
  1514          activationData.iRequestRefresh ||
  1508         SetMskL();
  1596         SetMskL();
  1509         }
  1597         }
  1510 
  1598 
  1511     iCurrentClientRect = clientRect;
  1599     iCurrentClientRect = clientRect;
  1512 	iThisViewActive = ETrue;
  1600 	iThisViewActive = ETrue;
  1513 
  1601 	//emailindicator handling, we dont care if something goes wrong in the mailindicator update. User can still open the mailbox
  1514 	// Set email indicator off.. user has checked the new emails
  1602 	TRAP_IGNORE(TFsEmailStatusPaneIndicatorHandler::StatusPaneMailIndicatorHandlingL( activationData.iMailBoxId.Id()));
  1515 	TFsEmailUiUtility::ToggleEmailIconL(EFalse, activationData.iMailBoxId );
  1603 	    
       
  1604     //Update mailbox widget index status in homescreen
       
  1605     TFsEmailUiUtility::ToggleEmailIconL(EFalse, activationData.iMailBoxId );
  1516 
  1606 
  1517 	iShiftDepressed = EFalse; // clear state just in case
  1607 	iShiftDepressed = EFalse; // clear state just in case
  1518 
  1608 
  1519 	// Inform MR observer if needed, special MR case, returning from attachment list
  1609 	// Inform MR observer if needed, special MR case, returning from attachment list
  1520 	iAppUi.MailViewer().CompletePendingMrCommand();
  1610 	iAppUi.MailViewer().CompletePendingMrCommand();
  1634 	if ( aResourceId == R_FSEMAILUI_MAILLIST_MENUPANE )
  1724 	if ( aResourceId == R_FSEMAILUI_MAILLIST_MENUPANE )
  1635 	    {
  1725 	    {
  1636             // Sync/cancel sync
  1726             // Sync/cancel sync
  1637 	    CFSMailBox* activeMailbox = iAppUi.GetActiveMailbox();
  1727 	    CFSMailBox* activeMailbox = iAppUi.GetActiveMailbox();
  1638 	    TBool supportsSync = activeMailbox->HasCapability( EFSMBoxCapaSupportsSync );
  1728 	    TBool supportsSync = activeMailbox->HasCapability( EFSMBoxCapaSupportsSync );
  1639                 
  1729 
  1640             // flag to hide or show SyncButton
  1730             // flag to hide or show SyncButton
  1641             TBool hideSync = GetLatestSyncState();
  1731             TBool hideSync = GetLatestSyncState();
  1642             if(activeMailbox->CurrentSyncState()==StartingSync) hideSync=EFalse;
  1732             if(activeMailbox->CurrentSyncState()==StartingSync) hideSync=EFalse;
  1643         
  1733 
  1644             // hide or show options: Sync/cancel sync
  1734             // hide or show options: Sync/cancel sync
  1645             if ( !supportsSync )
  1735         if ( !supportsSync )
  1646                 {
  1736         {
  1647                 aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelSync, ETrue );
  1737 				// POP3 behaviour
  1648                 aMenuPane->SetItemDimmed( EFsEmailUiCmdSync, ETrue );
  1738 				TFSMailBoxStatus onlineStatus = activeMailbox->GetMailBoxStatus();
  1649                 }
  1739 				if( onlineStatus == EFSMailBoxOnline || iMailListModelUpdater->IsUpdating() )
  1650              else if ( hideSync || iMailListModelUpdater->IsUpdating() )
  1740 				  {
  1651                 {
  1741 					aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelSync, EFalse );
  1652                 aMenuPane->SetItemDimmed( EFsEmailUiCmdSync, ETrue );
  1742 					aMenuPane->SetItemDimmed( EFsEmailUiCmdSync, ETrue );
  1653                 }
  1743 				  }
  1654              else
  1744 				else
  1655                 {
  1745 					{
  1656                 aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelSync, ETrue );
  1746 					aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelSync, ETrue );
  1657                 }
  1747 					aMenuPane->SetItemDimmed( EFsEmailUiCmdSync, EFalse );
  1658  	
  1748 					}
       
  1749         }
       
  1750       else if ( hideSync || iMailListModelUpdater->IsUpdating() )
       
  1751         {
       
  1752         aMenuPane->SetItemDimmed( EFsEmailUiCmdSync, ETrue );
       
  1753         }
       
  1754       else
       
  1755         {
       
  1756         aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelSync, ETrue );
       
  1757         }
       
  1758 
  1659 		// Saves a focus visibility.
  1759 		// Saves a focus visibility.
  1660 		iLastFocus = EFalse;
  1760 		iLastFocus = EFalse;
  1661 		if( iFocusedControl == EMailListComponent && IsFocusShown() )
  1761 		if( iFocusedControl == EMailListComponent && IsFocusShown() )
  1662 		    {
  1762 		    {
  1663 		    iLastFocus = ETrue;
  1763 		    iLastFocus = ETrue;
  1945 	{
  2045 	{
  1946     FUNC_LOG;
  2046     FUNC_LOG;
  1947 	iMailList->RemoveAllL();
  2047 	iMailList->RemoveAllL();
  1948 	iTreeItemArray.Reset();
  2048 	iTreeItemArray.Reset();
  1949 
  2049 
  1950     // when we get refresh mail list updates should be fully enabled	
  2050     // when we get refresh mail list updates should be fully enabled
  1951     iMailOpened = EFalse;
  2051     iMailOpened = EFalse;
  1952 	
  2052 
  1953 	RefreshListItemsL();
  2053 	RefreshListItemsL();
  1954 
  2054 
  1955 	if ( !iModel->Count() )
  2055 	if ( !iModel->Count() )
  1956 		{
  2056 		{
  1957 		iFocusedControl = EControlBarComponent;
  2057 		iFocusedControl = EControlBarComponent;
  3021 
  3121 
  3022 // ---------------------------------------------------------------------------
  3122 // ---------------------------------------------------------------------------
  3023 //
  3123 //
  3024 // ---------------------------------------------------------------------------
  3124 // ---------------------------------------------------------------------------
  3025 //
  3125 //
  3026 void CFSEmailUiMailListVisualiser::UpdateTheme()
  3126 void CFSEmailUiMailListVisualiser::UpdateTheme(const TBool aSystemUpdate)
  3027     {
  3127     {
  3028     iSkinChanged = ETrue;
  3128     iSkinChanged = aSystemUpdate;
  3029 
  3129 
  3030     TRgb focusedTextColor = iAppUi.LayoutHandler()->ListFocusedStateTextSkinColor();
  3130     TRgb focusedTextColor = iAppUi.LayoutHandler()->ListFocusedStateTextSkinColor();
  3031     TRgb normalTextColor = iAppUi.LayoutHandler()->ListNormalStateTextSkinColor();
  3131     TRgb normalTextColor = iAppUi.LayoutHandler()->ListNormalStateTextSkinColor();
  3032 
  3132 
  3033     iNewEmailButton->SetNormalTextColor( normalTextColor );
  3133     iNewEmailButton->SetNormalTextColor( normalTextColor );
  3047 // ---------------------------------------------------------------------------
  3147 // ---------------------------------------------------------------------------
  3048 //
  3148 //
  3049 void CFSEmailUiMailListVisualiser::HandleForegroundEventL( TBool aForeground )
  3149 void CFSEmailUiMailListVisualiser::HandleForegroundEventL( TBool aForeground )
  3050 	{
  3150 	{
  3051     FUNC_LOG;
  3151     FUNC_LOG;
  3052     if( iMailFolder ) 
  3152     if( iMailFolder )
  3053         {
  3153         {
       
  3154         //emailindicator handling, we dont care if something goes wrong in the mailindicator update. User can still open the mailbox
       
  3155         TRAP_IGNORE(TFsEmailStatusPaneIndicatorHandler::StatusPaneMailIndicatorHandlingL( iMailFolder->GetMailBoxId().Id()));
       
  3156         //Update mailbox widget index status in homescreen
  3054         TFsEmailUiUtility::ToggleEmailIconL(EFalse, iMailFolder->GetMailBoxId() );
  3157         TFsEmailUiUtility::ToggleEmailIconL(EFalse, iMailFolder->GetMailBoxId() );
  3055         }
  3158         }
  3056     if ( aForeground && iFirstStartCompleted ) // Safety
  3159     
       
  3160 	if ( iFirstStartCompleted ) // Safety
  3057 	    {
  3161 	    {
  3058 	    // Update mail list settings and date formats, is done every time
  3162 	    // Update mail list settings and date formats, is done every time
  3059 	    // the user might have changed these in settings, so the list needs to refresh
  3163 	    // the user might have changed these in settings, so the list needs to refresh
  3060 	    // Store previous modes
  3164 	    // Store previous modes
  3061 	    TInt prevListMode = iListMode;
  3165 	    TInt prevListMode = iListMode;
  3193                 break;
  3297                 break;
  3194                 }
  3298                 }
  3195             }
  3299             }
  3196        	case EAknSoftkeySelect:
  3300        	case EAknSoftkeySelect:
  3197        	    {
  3301        	    {
  3198        	    TIMESTAMP( "Open email selected from message list" );    
  3302        	    TIMESTAMP( "Open email selected from message list" );
  3199        	    if ( iFocusedControl == EMailListComponent )
  3303        	    if ( iFocusedControl == EMailListComponent )
  3200        	        {
  3304        	        {
  3201        	        CFSEmailUiMailListModelItem* item = dynamic_cast<CFSEmailUiMailListModelItem*>(iModel->Item(HighlightedIndex()));
  3305        	        CFSEmailUiMailListModelItem* item = dynamic_cast<CFSEmailUiMailListModelItem*>(iModel->Item(HighlightedIndex()));
  3202        	        // MAIL ITEM; OPEN MAIL
  3306        	        // MAIL ITEM; OPEN MAIL
  3203        	        if ( item && item->ModelItemType() == ETypeMailItem )
  3307        	        if ( item && item->ModelItemType() == ETypeMailItem )
  3403             }
  3507             }
  3404             break;
  3508             break;
  3405        	case EFsEmailUiCmdActionsDeleteCalEvent:
  3509        	case EFsEmailUiCmdActionsDeleteCalEvent:
  3406 		case EFsEmailUiCmdActionsDelete:
  3510 		case EFsEmailUiCmdActionsDelete:
  3407 			{
  3511 			{
  3408 			TIMESTAMP( "Delete to selected from message list" );    
  3512 			TIMESTAMP( "Delete to selected from message list" );
  3409 			TInt index = HighlightedIndex();
  3513 			TInt index = HighlightedIndex();
  3410 			CFSEmailUiMailListModelItem* item =
  3514 			CFSEmailUiMailListModelItem* item =
  3411 				dynamic_cast<CFSEmailUiMailListModelItem*>(
  3515 				dynamic_cast<CFSEmailUiMailListModelItem*>(
  3412 						iModel->Item( index ) );
  3516 						iModel->Item( index ) );
  3413 
  3517 
  3414 			// If selected item is separator (divider) mark/unmark all messages
  3518 			// If selected item is separator (divider) mark/unmark all messages
  3415 			// under it.
  3519 			// under it.
  3416 			if ( item && item->ModelItemType() == ETypeSeparator )
       
  3417 				{
       
  3418 				MarkItemsUnderSeparatorL( ETrue, index );
       
  3419 				}
       
  3420 
  3520 
  3421 			// Delete message only if mail list component is focused
  3521 			// Delete message only if mail list component is focused
  3422 			// or if there are some marked items
  3522 			// or if there are some marked items
  3423 			TInt markedItems( CountMarkedItemsL() );
  3523 			TInt markedItems( CountMarkedItemsL() );
  3424 
  3524             const TBool isNode(iMailList->IsNode(iMailList->FocusedItem()));
  3425 			if ( iFocusedControl == EMailListComponent || markedItems )
  3525             if (iFocusedControl == EMailListComponent || markedItems
  3426 				{
  3526                     || isNode)
  3427 				DeleteMessagesL();
  3527                 {
  3428 				}
  3528                 DeleteMessagesL();
  3429 			}
  3529                 }
       
  3530             }
  3430             break;
  3531             break;
  3431 		case EFsEmailUiCmdCompose:
  3532 		case EFsEmailUiCmdCompose:
  3432 			{
  3533 			{
  3433 			TIMESTAMP( "Create new message selected from message list" );    
  3534 			TIMESTAMP( "Create new message selected from message list" );
  3434 			CreateNewMsgL();
  3535 			CreateNewMsgL();
  3435 			}
  3536 			}
  3436 			break;
  3537 			break;
  3437        	case EFsEmailUiCmdMessageDetails:
  3538        	case EFsEmailUiCmdMessageDetails:
  3438 			{
  3539 			{
  3480        		}
  3581        		}
  3481        		break;
  3582        		break;
  3482        	case EFsEmailUiCmdOpen:
  3583        	case EFsEmailUiCmdOpen:
  3483         case EFsEmailUiCmdActionsOpen:
  3584         case EFsEmailUiCmdActionsOpen:
  3484         	{
  3585         	{
  3485         	TIMESTAMP( "Open email selected from message list" );        
  3586         	TIMESTAMP( "Open email selected from message list" );
  3486 	        if ( iFocusedControl == EMailListComponent )
  3587 	        if ( iFocusedControl == EMailListComponent )
  3487 	            {
  3588 	            {
  3488 	            // Opening can happen only when there's exactly one message marked or in focus
  3589 	            // Opening can happen only when there's exactly one message marked or in focus
  3489 	            if ( actionTargetItems.Count() == 1 )
  3590 	            if ( actionTargetItems.Count() == 1 )
  3490 	                {
  3591 	                {
  3596 			    if(!GetLatestSyncState())
  3697 			    if(!GetLatestSyncState())
  3597 			        {
  3698 			        {
  3598 			        iAppUi.SyncActiveMailBoxL();
  3699 			        iAppUi.SyncActiveMailBoxL();
  3599 			        // Sync was started by the user
  3700 			        // Sync was started by the user
  3600 			        ManualMailBoxSync(ETrue);
  3701 			        ManualMailBoxSync(ETrue);
  3601                                 iAppUi.ManualMailBoxSync( ETrue );
  3702                     iAppUi.ManualMailBoxSync( ETrue );
  3602 			        }
  3703 			        }
  3603 			    }
  3704 			    }
       
  3705 			  else
       
  3706 			    {
       
  3707 			    //POP3 synchronise
       
  3708 				iAppUi.DoAutoConnectL();
       
  3709 				}
  3604 			}
  3710 			}
  3605 			break;
  3711 			break;
  3606        	case EFsEmailUiCmdCancelSync:
  3712        	case EFsEmailUiCmdCancelSync:
  3607        		{
  3713        		{
  3608 		TBool supportsSync = iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaSupportsSync );
  3714             TBool supportsSync = iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaSupportsSync );
  3609 		if ( supportsSync )
  3715             if ( supportsSync )
  3610 		    {
  3716 		       {
  3611 	            iAppUi.StopActiveMailBoxSyncL();
  3717 	            iAppUi.StopActiveMailBoxSyncL();
  3612 	            // Sync was started by the user
  3718 	            // Sync was started by the user
  3613 	            ManualMailBoxSync(ETrue);
  3719 	            ManualMailBoxSync(ETrue);
  3614 	            iAppUi.ManualMailBoxSync( ETrue );
  3720 	            iAppUi.ManualMailBoxSync( ETrue );
  3615 		    }
  3721                 }
       
  3722 		     else
       
  3723 		        {
       
  3724 		         //POP3
       
  3725                  iAppUi.GetActiveMailbox()->GoOfflineL();
       
  3726                 }
  3616        		}
  3727        		}
  3617        		break;
  3728        		break;
  3618         case EFsEmailUiCmdGoOffline:
  3729         case EFsEmailUiCmdGoOffline:
  3619         	{
  3730         	{
  3620     	   	iAppUi.GetActiveMailbox()->GoOfflineL();
  3731     	   	iAppUi.GetActiveMailbox()->GoOfflineL();
  3844 
  3955 
  3845 	    default:
  3956 	    default:
  3846         	break;
  3957         	break;
  3847         } // switch ( aCommand )
  3958         } // switch ( aCommand )
  3848     CleanupStack::PopAndDestroy( &actionTargetItems );
  3959     CleanupStack::PopAndDestroy( &actionTargetItems );
  3849     TIMESTAMP( "Message list selected operation done" );    
  3960     TIMESTAMP( "Message list selected operation done" );
  3850     }
  3961     }
  3851 
  3962 
  3852 // ---------------------------------------------------------------------------
  3963 // ---------------------------------------------------------------------------
  3853 //
  3964 //
  3854 //
  3965 //
  4403                             if ( item && item->ModelItemType() == ETypeMailItem )
  4514                             if ( item && item->ModelItemType() == ETypeMailItem )
  4404                                 {
  4515                                 {
  4405                                 CFSMailMessage* messagePtr = &item->MessagePtr();
  4516                                 CFSMailMessage* messagePtr = &item->MessagePtr();
  4406                                 if ( messagePtr )
  4517                                 if ( messagePtr )
  4407                                     {
  4518                                     {
  4408                                     TIMESTAMP( "Open email selected from message list" );    
  4519                                     TIMESTAMP( "Open email selected from message list" );
  4409                                     OpenHighlightedMailL();
  4520                                     OpenHighlightedMailL();
  4410                                     return EKeyWasConsumed;
  4521                                     return EKeyWasConsumed;
  4411                                     }
  4522                                     }
  4412                                 }
  4523                                 }
  4413                             // SEPARAOR ITEM; COLLAPSE / EXPAND NODE
  4524                             // SEPARAOR ITEM; COLLAPSE / EXPAND NODE
  4619             if ( messagePtr )
  4730             if ( messagePtr )
  4620                 {
  4731                 {
  4621                 TIMESTAMP( "Open email selected from message list" );
  4732                 TIMESTAMP( "Open email selected from message list" );
  4622                 OpenHighlightedMailL();
  4733                 OpenHighlightedMailL();
  4623                 }
  4734                 }
       
  4735 
       
  4736             // Give feedback to user (vibration)
       
  4737             iTouchFeedBack->InstantFeedback(ETouchFeedbackBasic);
  4624             }
  4738             }
  4625         // SEPARATOR ITEM; COLLAPSE / EXPAND NODE
  4739         // SEPARATOR ITEM; COLLAPSE / EXPAND NODE
  4626         else if ( item && item->ModelItemType() == ETypeSeparator )
  4740         else if ( item && item->ModelItemType() == ETypeSeparator )
  4627             {
  4741             {
  4628                 ExpandOrCollapseL();
  4742                 ExpandOrCollapseL();
  5124 	textLayout.LayoutText(TRect(0,0,0,0), AknLayoutScalable_Apps::main_sp_fs_ctrlbar_ddmenu_pane_t1(var));
  5238 	textLayout.LayoutText(TRect(0,0,0,0), AknLayoutScalable_Apps::main_sp_fs_ctrlbar_ddmenu_pane_t1(var));
  5125 	iNewEmailButton->SetTextFontL( textLayout.Font()->FontSpecInTwips() );
  5239 	iNewEmailButton->SetTextFontL( textLayout.Font()->FontSpecInTwips() );
  5126  	iFolderListButton->SetTextFontL( textLayout.Font()->FontSpecInTwips() );
  5240  	iFolderListButton->SetTextFontL( textLayout.Font()->FontSpecInTwips() );
  5127  	iSortButton->SetTextFontL( textLayout.Font()->FontSpecInTwips() );
  5241  	iSortButton->SetTextFontL( textLayout.Font()->FontSpecInTwips() );
  5128 
  5242 
  5129  	UpdateTheme();
  5243  	UpdateTheme(EFalse);
  5130 
  5244 
  5131 	iNewEmailButton->ShowButtonL();
  5245 	iNewEmailButton->ShowButtonL();
  5132   	iFolderListButton->ShowButtonL();
  5246   	iFolderListButton->ShowButtonL();
  5133 	iSortButton->ShowButtonL();
  5247 	iSortButton->ShowButtonL();
  5134 	}
  5248 	}
  5420 // ---------------------------------------------------------------------------
  5534 // ---------------------------------------------------------------------------
  5421 //
  5535 //
  5422 void CFSEmailUiMailListVisualiser::DeleteMessagesL()
  5536 void CFSEmailUiMailListVisualiser::DeleteMessagesL()
  5423 	{
  5537 	{
  5424     FUNC_LOG;
  5538     FUNC_LOG;
  5425 	TInt markedCount = CountMarkedItemsL();
  5539     const TInt markedCount(CountMarkedItemsL());
  5426 
  5540     const TFsTreeItemId focusedId(iMailList->FocusedItem());
  5427 	// Delete either marked items or the focused one
  5541 
  5428 	if ( markedCount )
  5542     // Delete either marked items or the focused one
  5429 		{
  5543     if (markedCount)
  5430 		DeleteMarkedMessagesL();
  5544         {
  5431 		}
  5545         DeleteMarkedMessagesL();
  5432 	else
  5546         }
  5433 		{
  5547     else if (iMailList->IsNode(focusedId))
  5434 		DeleteFocusedMessageL();
  5548         {
  5435 		}
  5549         DeleteMessagesUnderNodeL(focusedId);
       
  5550         }
       
  5551     else
       
  5552         {
       
  5553         DeleteFocusedMessageL();
       
  5554         }
  5436 
  5555 
  5437 	// Set highlight to control bar if no items after delete
  5556 	// Set highlight to control bar if no items after delete
  5438     // <cmail>
  5557     // <cmail>
  5439 	if ( iModel->Count() == 0 )
  5558 	if ( iModel->Count() == 0 )
  5440     // </cmail>
  5559     // </cmail>
  5772 			}
  5891 			}
  5773 		}
  5892 		}
  5774 	}
  5893 	}
  5775 
  5894 
  5776 // ---------------------------------------------------------------------------
  5895 // ---------------------------------------------------------------------------
       
  5896 // DeleteMessagesUnderNodeL
       
  5897 //
       
  5898 // ---------------------------------------------------------------------------
       
  5899 //
       
  5900 void CFSEmailUiMailListVisualiser::DeleteMessagesUnderNodeL(
       
  5901         const TFsTreeItemId aNodeId)
       
  5902     {
       
  5903     FUNC_LOG;
       
  5904     iModel->GetItemIdsUnderNodeL(aNodeId, iDeleteTask->Entries());
       
  5905     ConfirmAndStartDeleteTaskL(iDeleteTask);
       
  5906     }
       
  5907 
       
  5908 // ---------------------------------------------------------------------------
  5777 // DeleteMarkedMessagesL
  5909 // DeleteMarkedMessagesL
  5778 //
  5910 //
  5779 // ---------------------------------------------------------------------------
  5911 // ---------------------------------------------------------------------------
  5780 //
  5912 //
  5781 void CFSEmailUiMailListVisualiser::DeleteMarkedMessagesL()
  5913 void CFSEmailUiMailListVisualiser::DeleteMarkedMessagesL()
  5782 	{
  5914     {
  5783     FUNC_LOG;
  5915     FUNC_LOG;
  5784 	RFsTreeItemIdList markedEntries;
  5916     iMailList->GetMarkedItemsL(iDeleteTask->Entries());
  5785 	CleanupClosePushL( markedEntries );
  5917     ConfirmAndStartDeleteTaskL(iDeleteTask);
  5786 	iMailList->GetMarkedItemsL( markedEntries );
  5918     }
  5787 	TInt okToDelete( ETrue );
  5919 
  5788 
  5920 // ---------------------------------------------------------------------------
  5789     if ( iAppUi.GetCRHandler()->WarnBeforeDelete() )
  5921 // ConfirmAndStartDeleteTaskL
  5790         {
  5922 //
  5791         HBufC* noteText( NULL );
  5923 // ---------------------------------------------------------------------------
       
  5924 //
       
  5925 void CFSEmailUiMailListVisualiser::ConfirmAndStartDeleteTaskL(
       
  5926         TDeleteTask<CFSEmailUiMailListVisualiser>* aTask )
       
  5927     {
       
  5928     FUNC_LOG;
       
  5929     const RFsTreeItemIdList& entries(aTask->Entries());
       
  5930     if (entries.Count())
       
  5931         {
       
  5932         if (ConfirmDeleteL(entries.Count(), entries[0]))
       
  5933             {
       
  5934             if (entries.Count() > KMsgDeletionWaitNoteAmount)
       
  5935                 {
       
  5936                 TFsEmailUiUtility::ShowWaitNoteL(iDeletingWaitNote,
       
  5937                         R_FSE_WAIT_DELETING_TEXT, EFalse, ETrue);
       
  5938                 }
       
  5939             if (iAsyncCallback)
       
  5940                 {
       
  5941                 // Call actual deletion asynchronously because we must give wait
       
  5942                 // note time to show up before deletion begins.
       
  5943                 iAsyncCallback->Cancel();
       
  5944                 iAsyncCallback->Set(TCallBack(DoExecuteDeleteTask, aTask));
       
  5945                 iAsyncCallback->CallBack();
       
  5946                 }
       
  5947             }
       
  5948         else
       
  5949             {
       
  5950             aTask->Reset();
       
  5951             }
       
  5952         }
       
  5953     }
       
  5954 
       
  5955 // ---------------------------------------------------------------------------
       
  5956 // DoExecuteDeleteTask
       
  5957 //
       
  5958 // ---------------------------------------------------------------------------
       
  5959 //
       
  5960 TInt CFSEmailUiMailListVisualiser::DoExecuteDeleteTask( TAny* aSelfPtr )
       
  5961     {
       
  5962     FUNC_LOG;
       
  5963     TRAPD( error, 
       
  5964             reinterpret_cast<TDeleteTask<CFSEmailUiMailListVisualiser>*>(aSelfPtr)->ExecuteL() );
       
  5965     return error;
       
  5966     }
       
  5967 
       
  5968 // ---------------------------------------------------------------------------
       
  5969 // HandleDeleteTaskL
       
  5970 // This is called asynchronously by ConfirmAndStartDeleteTaskL
       
  5971 // ---------------------------------------------------------------------------
       
  5972 //
       
  5973 void CFSEmailUiMailListVisualiser::HandleDeleteTaskL( const RFsTreeItemIdList& aEntries )
       
  5974     {
       
  5975     FUNC_LOG;
       
  5976     // Close wait note if it was used
       
  5977     if ( iDeletingWaitNote )
       
  5978         {
       
  5979         TRAPD( result, HandleDeleteTaskLeavingCodeL(aEntries) );
       
  5980         // closing the "Deleting" dialog message should not be skipped by leaving
       
  5981         TRAP_IGNORE( iDeletingWaitNote->ProcessFinishedL() ); 
       
  5982         if ( KErrNone != result )
       
  5983             {
       
  5984             // Handle error.
       
  5985             User::Leave( result );
       
  5986             }
       
  5987         }
       
  5988     else
       
  5989         {
       
  5990         HandleDeleteTaskLeavingCodeL( aEntries );
       
  5991         }
       
  5992     }
       
  5993 
       
  5994 // ---------------------------------------------------------------------------
       
  5995 // original code HandleDeleteTaskL which may leave - help function to enable 
       
  5996 // calling iDeletingWaitNote->ProcessFinishedL() 
       
  5997 // ---------------------------------------------------------------------------
       
  5998 //
       
  5999 void CFSEmailUiMailListVisualiser::HandleDeleteTaskLeavingCodeL( const RFsTreeItemIdList& aEntries )
       
  6000     {
       
  6001     FUNC_LOG;
       
  6002     TFSMailMsgId folderId = FolderId();
       
  6003     TFSMailMsgId mailBox = iAppUi.GetActiveMailboxId();
       
  6004     RArray<TFSMailMsgId> msgIds;
       
  6005     CleanupClosePushL( msgIds );
       
  6006     for ( TInt i = 0; i < aEntries.Count(); i++ )
       
  6007         {
       
  6008         msgIds.AppendL( MsgIdFromListId( aEntries[i] ) );
       
  6009         }
       
  6010     iAppUi.GetMailClient()->DeleteMessagesByUidL( mailBox, folderId, msgIds );
       
  6011     // Remove from mail list if not already removed by mailbox events
       
  6012     RemoveMsgItemsFromListIfFoundL( msgIds );
       
  6013     CleanupStack::PopAndDestroy(); // msgIds.Close()
       
  6014     }
       
  6015 
       
  6016 // ---------------------------------------------------------------------------
       
  6017 // ConfirmDeleteL
       
  6018 //
       
  6019 // ---------------------------------------------------------------------------
       
  6020 //
       
  6021 TBool CFSEmailUiMailListVisualiser::ConfirmDeleteL(const TInt aItemCount,
       
  6022         const TFsTreeItemId aItemId) const
       
  6023     {
       
  6024     FUNC_LOG;
       
  6025     TBool result(ETrue);
       
  6026     if (iAppUi.GetCRHandler()->WarnBeforeDelete())
       
  6027         {
       
  6028         HBufC* noteText(NULL);
  5792         // The note depends on the amount and type of message(s)
  6029         // The note depends on the amount and type of message(s)
  5793         if ( markedEntries.Count() == 1 )
  6030         if (aItemCount == 1)
  5794             {
  6031             {
  5795             CFSMailMessage& msgPtr = MsgPtrFromListIdL( markedEntries[0] );
  6032             const CFSMailMessage& msgPtr(MsgPtrFromListIdL(aItemId));
  5796 
  6033             HBufC* msgSubject = TFsEmailUiUtility::CreateSubjectTextLC(
  5797             HBufC* msgSubject = TFsEmailUiUtility::CreateSubjectTextLC( &msgPtr );
  6034                     &msgPtr);
  5798             if ( msgPtr.IsFlagSet( EFSMsgFlag_CalendarMsg ))
  6035             if (msgPtr.IsFlagSet(EFSMsgFlag_CalendarMsg))
  5799                 {
  6036                 {
  5800                 noteText = StringLoader::LoadL( R_FREESTYLE_EMAIL_DELETE_CALEVENT_NOTE, *msgSubject );
  6037                 noteText = StringLoader::LoadL(
       
  6038                         R_FREESTYLE_EMAIL_DELETE_CALEVENT_NOTE, *msgSubject);
  5801                 }
  6039                 }
  5802             else
  6040             else
  5803                 {
  6041                 {
  5804                 noteText = StringLoader::LoadL( R_FREESTYLE_EMAIL_DELETE_MAIL_NOTE, *msgSubject );
  6042                 noteText = StringLoader::LoadL(
  5805                 }
  6043                         R_FREESTYLE_EMAIL_DELETE_MAIL_NOTE, *msgSubject);
  5806             CleanupStack::PopAndDestroy( msgSubject );
  6044                 }
  5807             CleanupStack::PushL( noteText );
  6045             CleanupStack::PopAndDestroy(msgSubject);
       
  6046             CleanupStack::PushL(noteText);
  5808             }
  6047             }
  5809         else // markedEntries.Count() > 1
  6048         else // markedEntries.Count() > 1
  5810             {
  6049             {
  5811             noteText = StringLoader::LoadLC( R_FREESTYLE_EMAIL_DELETE_N_MAILS_NOTE, markedEntries.Count() );
  6050             noteText = StringLoader::LoadLC(
       
  6051                     R_FREESTYLE_EMAIL_DELETE_N_MAILS_NOTE, aItemCount);
  5812             }
  6052             }
  5813 
  6053 
  5814         // Show the note
  6054         // Show the note
  5815         okToDelete = TFsEmailUiUtility::ShowConfirmationQueryL( *noteText );
  6055         result = TFsEmailUiUtility::ShowConfirmationQueryL(*noteText);
  5816         CleanupStack::PopAndDestroy( noteText );
  6056         CleanupStack::PopAndDestroy(noteText);
  5817         }
  6057         }
  5818 
  6058     return result;
  5819     if ( okToDelete )
       
  5820         {
       
  5821         if ( markedEntries.Count() > KMsgDeletionWaitNoteAmount )
       
  5822             {
       
  5823             TFsEmailUiUtility::ShowWaitNoteL( iDeletingWaitNote, R_FSE_WAIT_DELETING_TEXT, EFalse, ETrue );
       
  5824             }
       
  5825 
       
  5826         // <cmail>
       
  5827         if ( iAsyncCallback )
       
  5828             {
       
  5829             // Call actual deletion asynchronously because we must give wait
       
  5830             // note time to show up before deletion begins.
       
  5831             iAsyncCallback->Cancel();
       
  5832             iAsyncCallback->Set( TCallBack(DoDeleteMarkedMessages, this) );
       
  5833             iAsyncCallback->CallBack();
       
  5834             }
       
  5835         // </cmail>
       
  5836         }
       
  5837     else
       
  5838     	{
       
  5839 		UnmarkAllItemsL();
       
  5840     	}
       
  5841 
       
  5842     CleanupStack::PopAndDestroy( &markedEntries );
       
  5843 	}
       
  5844 
       
  5845 // ---------------------------------------------------------------------------
       
  5846 // DoDeleteMarkedMessages
       
  5847 //
       
  5848 // ---------------------------------------------------------------------------
       
  5849 //
       
  5850 TInt CFSEmailUiMailListVisualiser::DoDeleteMarkedMessages( TAny* aSelfPtr )
       
  5851     {
       
  5852     FUNC_LOG;
       
  5853     CFSEmailUiMailListVisualiser* self =
       
  5854         static_cast<CFSEmailUiMailListVisualiser*>( aSelfPtr );
       
  5855 
       
  5856     TRAPD( err,
       
  5857         RFsTreeItemIdList markedEntries;
       
  5858         CleanupClosePushL( markedEntries );
       
  5859         self->iMailList->GetMarkedItemsL( markedEntries );
       
  5860 
       
  5861         // Delete from FW first
       
  5862         RArray<TFSMailMsgId> msgIds;
       
  5863         CleanupClosePushL( msgIds );
       
  5864         for ( TInt i=0 ; i<markedEntries.Count() ; i++ )
       
  5865             {
       
  5866             msgIds.Append( self->MsgIdFromListId( markedEntries[i] ) );
       
  5867             }
       
  5868         TFSMailMsgId folderId = self->FolderId();
       
  5869         TFSMailMsgId mailBox = self->iAppUi.GetActiveMailboxId();
       
  5870         self->iAppUi.GetMailClient()->DeleteMessagesByUidL( mailBox, folderId, msgIds );
       
  5871 
       
  5872         // Remove from mail list if not already removed by mailbox events
       
  5873         self->RemoveMsgItemsFromListIfFoundL( msgIds );
       
  5874 
       
  5875         CleanupStack::PopAndDestroy( &msgIds );
       
  5876         CleanupStack::PopAndDestroy( &markedEntries );
       
  5877         );
       
  5878 
       
  5879     // Close wait note if it was used
       
  5880     if ( self->iDeletingWaitNote )
       
  5881         {
       
  5882         TRAP_IGNORE( self->iDeletingWaitNote->ProcessFinishedL() );
       
  5883         }
       
  5884 
       
  5885     return err;
       
  5886     }
  6059     }
  5887 
  6060 
  5888 // ---------------------------------------------------------------------------
  6061 // ---------------------------------------------------------------------------
  5889 // RemoveUnnecessaryNodesL
  6062 // RemoveUnnecessaryNodesL
  5890 //
  6063 //
  6083 	    const TInt modelCount( iModel->Count() );
  6256 	    const TInt modelCount( iModel->Count() );
  6084     	for ( TInt i( 0 ); i < modelCount ; ++i )
  6257     	for ( TInt i( 0 ); i < modelCount ; ++i )
  6085     		{
  6258     		{
  6086     		CFSEmailUiMailListModelItem* item =
  6259     		CFSEmailUiMailListModelItem* item =
  6087                 static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( i ) );
  6260                 static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( i ) );
  6088 			// when the item is a separator check whether its MessagePtr is valid (actually it's a reference)    		    		
  6261 			// when the item is a separator check whether its MessagePtr is valid (actually it's a reference)
  6089 			if( &(item->MessagePtr()) != NULL) 
  6262 			if( &(item->MessagePtr()) != NULL)
  6090 				{
  6263 				{
  6091     		if ( aMessageId == item->MessagePtr().GetMessageId() )
  6264     		if ( aMessageId == item->MessagePtr().GetMessageId() )
  6092     			{
  6265     			{
  6093     			TModelItemType itemType = item->ModelItemType();
  6266     			TModelItemType itemType = item->ModelItemType();
  6094     			TBool separator( aMessageId.IsSeparator() );
  6267     			TBool separator( aMessageId.IsSeparator() );
  6481 	        confirmedMsgPtr = iAppUi.GetMailClient()->GetMessageByUidL(iAppUi.GetActiveMailboxId(),
  6654 	        confirmedMsgPtr = iAppUi.GetMailClient()->GetMessageByUidL(iAppUi.GetActiveMailboxId(),
  6482 	                iMailFolder->GetFolderId(), item->MessagePtr().GetMessageId(), EFSMsgDataEnvelope );
  6655 	                iMailFolder->GetFolderId(), item->MessagePtr().GetMessageId(), EFSMsgDataEnvelope );
  6483 	        if ( confirmedMsgPtr )
  6656 	        if ( confirmedMsgPtr )
  6484 	            {
  6657 	            {
  6485 	            iMailOpened = ETrue;
  6658 	            iMailOpened = ETrue;
  6486 	            
  6659 
  6487 	            ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
  6660 	            ChangeMskCommandL( R_FSE_QTN_MSK_EMPTY );
  6488 	            // Pointer confirmed, store Id and delete not needed anymore
  6661 	            // Pointer confirmed, store Id and delete not needed anymore
  6489 	            TFSMailMsgId confirmedId = confirmedMsgPtr->GetMessageId();
  6662 	            TFSMailMsgId confirmedId = confirmedMsgPtr->GetMessageId();
  6490 	      		TBool isCalMessage = confirmedMsgPtr->IsFlagSet( EFSMsgFlag_CalendarMsg );
  6663 	      		TBool isCalMessage = confirmedMsgPtr->IsFlagSet( EFSMsgFlag_CalendarMsg );
  6491 	      		TBool isReadMessage = confirmedMsgPtr->IsFlagSet( EFSMsgFlag_Read );
  6664 	      		TBool isReadMessage = confirmedMsgPtr->IsFlagSet( EFSMsgFlag_Read );
  6655 		if ( item->ModelItemType() == ETypeMailItem )
  6828 		if ( item->ModelItemType() == ETypeMailItem )
  6656 			{
  6829 			{
  6657 			// Add mark as read / unread options
  6830 			// Add mark as read / unread options
  6658 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, !IsMarkAsUnreadAvailableL() );
  6831 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, !IsMarkAsUnreadAvailableL() );
  6659 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsRead, !IsMarkAsReadAvailableL() );
  6832 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsRead, !IsMarkAsReadAvailableL() );
  6660 	
  6833 
  6661 			// Check support for object mail iten moving
  6834 			// Check support for object mail iten moving
  6662 			TBool supportsMoving = iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaMoveToFolder );
  6835 			TBool supportsMoving = iAppUi.GetActiveMailbox()->HasCapability( EFSMBoxCapaMoveToFolder );
  6663 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsMoveMessage, !supportsMoving );
  6836 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsMoveMessage, !supportsMoving );
  6664 	
  6837 
  6665 			// Hide / show follow up
  6838 			// Hide / show follow up
  6666 			TBool supportsFlag = TFsEmailUiUtility::IsFollowUpSupported( *iAppUi.GetActiveMailbox() );
  6839 			TBool supportsFlag = TFsEmailUiUtility::IsFollowUpSupported( *iAppUi.GetActiveMailbox() );
  6667 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsFlag, !supportsFlag );
  6840 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsFlag, !supportsFlag );
  6668 	
  6841 
  6669 			// Hide mark if applicable
  6842 			// Hide mark if applicable
  6670 			if ( iMailList->IsMarked( iMailList->FocusedItem() ) )
  6843 			if ( iMailList->IsMarked( iMailList->FocusedItem() ) )
  6671 				{
  6844 				{
  6672 				iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMark, ETrue );
  6845 				iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMark, ETrue );
  6673 				}
  6846 				}
  6674 	
  6847 
  6675 			// Hide collapse / expand all
  6848 			// Hide collapse / expand all
  6676 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsCollapseAll, ETrue );
  6849 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsCollapseAll, ETrue );
  6677 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsExpandAll, ETrue );
  6850 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsExpandAll, ETrue );
  6678 			}
  6851 			}
  6679 		else if ( item->ModelItemType() == ETypeSeparator )
  6852 		else if ( item->ModelItemType() == ETypeSeparator )
  6680 			{
  6853 			{
  6681 			// Hide mark as read / unread options
  6854 			// Hide mark as read / unread options
  6682 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, ETrue );
  6855 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsUnread, ETrue );
  6683 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsRead, ETrue );
  6856 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdMarkAsRead, ETrue );
  6684 	
  6857 
  6685 			// Hide move & follow up
  6858 			// Hide move & follow up
  6686 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsMoveMessage, ETrue );
  6859 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsMoveMessage, ETrue );
  6687 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsFlag, ETrue );
  6860 			iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsFlag, ETrue );
  6688 	
  6861 
  6689 			// Hide collapse / expand all when applicable
  6862 			// Hide collapse / expand all when applicable
  6690 			if ( iNodesInUse == EListControlSeparatorDisabled || !iModel->Count() )
  6863 			if ( iNodesInUse == EListControlSeparatorDisabled || !iModel->Count() )
  6691 				{
  6864 				{
  6692 				iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsCollapseAll, ETrue );
  6865 				iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsCollapseAll, ETrue );
  6693 				iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsExpandAll, ETrue );
  6866 				iStylusPopUpMenu->SetItemDimmed( EFsEmailUiCmdActionsExpandAll, ETrue );
  6978 	   			        {
  7151 	   			        {
  6979 			   		ManualMailBoxSync(EFalse);
  7152 			   		ManualMailBoxSync(EFalse);
  6980 	   				}
  7153 	   				}
  6981 		   		    }
  7154 		   		    }
  6982 				    break;
  7155 				    break;
  6983 						
  7156 
  6984 	    			case SyncCancelled:
  7157 	    			case SyncCancelled:
  6985 	    			    {
  7158 	    			    {
  6986 	    			    //If sync was started by user, show the synchronisation indicator
  7159 	    			    //If sync was started by user, show the synchronisation indicator
  6987 	    			    if ( iManualMailBoxSync )
  7160 	    			    if ( iManualMailBoxSync )
  6988 	    			        {
  7161 	    			        {
  6989 	    			        ManualMailBoxSync(EFalse);
  7162 	    			        ManualMailBoxSync(EFalse);
  6990 	    			        }
  7163 	    			        }
  6991 	    			    }
  7164 	    			    }
  6992 	    			    break;
  7165 	    			    break;
  6993 						
  7166 
  6994 	    			}
  7167 	    			}
  6995     			}
  7168     			}
  6996 			}
  7169 			}
  6997 		}
  7170 		}
  6998 	}
  7171 	}
  7439     {
  7612     {
  7440     aLayoutArray.AppendL( iScreenAnchorLayout );
  7613     aLayoutArray.AppendL( iScreenAnchorLayout );
  7441     aLayoutArray.AppendL( iControlBarControl->Visual() );
  7614     aLayoutArray.AppendL( iControlBarControl->Visual() );
  7442     }
  7615     }
  7443 
  7616 
       
  7617 // Sets aActiveMailboxId and aActiveFolderId from iMailFolder if available
       
  7618 TInt CFSEmailUiMailListVisualiser::GetActiveFolderId(TFSMailMsgId& aActiveMailboxId, TFSMailMsgId& aActiveFolderId) const
       
  7619     {
       
  7620     if (iMailFolder != NULL)
       
  7621         {
       
  7622         aActiveMailboxId = iMailFolder->GetMailBoxId();
       
  7623         aActiveFolderId = iMailFolder->GetFolderId();
       
  7624         return KErrNone;
       
  7625         }
       
  7626     else
       
  7627         {
       
  7628          return KErrNotFound;
       
  7629         }
       
  7630     }
       
  7631 
       
  7632 void CFSEmailUiMailListVisualiser::CreateExtensionL()
       
  7633     {
       
  7634     CFSMailBox* box = iAppUi.GetActiveMailbox();
       
  7635     CEmailExtension* ext;
       
  7636     if (box)
       
  7637         {
       
  7638         ext = box->ExtensionL( KEmailMailboxStateExtensionUid );
       
  7639         }
       
  7640     if (ext)
       
  7641         {
       
  7642         iExtension = reinterpret_cast<CMailboxStateExtension*>( ext );
       
  7643         iExtension->SetStateDataProvider( this );
       
  7644         }
       
  7645     }
  7444 
  7646 
  7445 //////////////////////////////////////////////////////////////////
  7647 //////////////////////////////////////////////////////////////////
  7446 // Class implementation CMailListUpdater
  7648 // Class implementation CMailListUpdater
  7447 ///////////////////////////////////////////////////////////////////
  7649 ///////////////////////////////////////////////////////////////////
  7448 
  7650 
  7763 // -----------------------------------------------------------------------------
  7965 // -----------------------------------------------------------------------------
  7764 //
  7966 //
  7765 void CDateChangeTimer::RunL()
  7967 void CDateChangeTimer::RunL()
  7766     {
  7968     {
  7767     FUNC_LOG;
  7969     FUNC_LOG;
  7768     
  7970 
  7769     if (iStatus.Int() != KErrNone)
  7971     if (iStatus.Int() != KErrNone)
  7770         {
  7972         {
  7771         	INFO_1("### CDateChangeTimer::RunL (err=%d) ###", iStatus.Int());
  7973         	INFO_1("### CDateChangeTimer::RunL (err=%d) ###", iStatus.Int());
  7772         }
  7974         }
  7773 
  7975 
  7774     
  7976 
  7775     TBool dayChanged = EFalse;
  7977     TBool dayChanged = EFalse;
  7776     TInt dayCount = DayCount();
  7978     TInt dayCount = DayCount();
  7777     if (dayCount != iDayCount)
  7979     if (dayCount != iDayCount)
  7778         {
  7980         {
  7779   
  7981 
  7780         iDayCount = dayCount;
  7982         iDayCount = dayCount;
  7781         dayChanged = ETrue;
  7983         dayChanged = ETrue;
  7782         }
  7984         }
  7783 
  7985 
  7784     
  7986 
  7785     if ( KErrCancel == iStatus.Int() )
  7987     if ( KErrCancel == iStatus.Int() )
  7786         {
  7988         {
  7787         ;
  7989         ;
  7788         }   
  7990         }
  7789     else if ( KErrAbort == iStatus.Int() ) // System time changed
  7991     else if ( KErrAbort == iStatus.Int() ) // System time changed
  7790         {
  7992         {
  7791         if (dayChanged)
  7993         if (dayChanged)
  7792             {
  7994             {
  7793             TRAP_IGNORE( iMailListVisualiser.NotifyDateChangedL() );
  7995             TRAP_IGNORE( iMailListVisualiser.NotifyDateChangedL() );
  7798         {
  8000         {
  7799         // Update mail list and reissue the request for timer event
  8001         // Update mail list and reissue the request for timer event
  7800         TRAP_IGNORE( iMailListVisualiser.NotifyDateChangedL() );
  8002         TRAP_IGNORE( iMailListVisualiser.NotifyDateChangedL() );
  7801         Start();
  8003         Start();
  7802         }
  8004         }
  7803     
  8005 
  7804     }
  8006     }
  7805 
  8007 
  7806 
  8008 
  7807 TInt CDateChangeTimer::DayCount()
  8009 TInt CDateChangeTimer::DayCount()
  7808     {
  8010     {