emailuis/emailui/src/FreestyleEmailUiMailListVisualiser.cpp
branchRCL_3
changeset 23 dcf0eedfc1a3
parent 22 d620048b4810
equal deleted inserted replaced
22:d620048b4810 23:dcf0eedfc1a3
    95 // CONST VALUES
    95 // CONST VALUES
    96 const TInt KControlBarTransitionTime = 250;
    96 const TInt KControlBarTransitionTime = 250;
    97 const TInt KMaxPreviewPaneLength = 60;
    97 const TInt KMaxPreviewPaneLength = 60;
    98 const TInt KMsgUpdaterTimerDelay = 2500000; // Time to update list, 2,5sec
    98 const TInt KMsgUpdaterTimerDelay = 2500000; // Time to update list, 2,5sec
    99 const TInt KNewMailTimerDelay = 20; // sleeping timer to start processing new messages
    99 const TInt KNewMailTimerDelay = 20; // sleeping timer to start processing new messages
       
   100 const TInt KSortTimerDelay = 40;    // sleeping timer to start sorting ( delay should be longer than abowe )
       
   101 const TInt KSortCountdown = 5;      // number how many times will be tried do start sorting when it's forbidden
   100 const TInt KNewMailMaxBatch = 7;    // number of new mails inserted into list at once
   102 const TInt KNewMailMaxBatch = 7;    // number of new mails inserted into list at once
   101 static const TInt KMsgDeletionWaitNoteAmount = 5;
   103 static const TInt KMsgDeletionWaitNoteAmount = 5;
   102 _LIT( KMissingPreviewDataMarker, "..." );
   104 _LIT( KMissingPreviewDataMarker, "..." );
   103 
   105 
   104 static const TInt KMaxItemsFethed = 1000;
   106 static const TInt KMaxItemsFethed = 1000;
   484 	iAsyncRedrawer = new (ELeave) CAsyncCallBack( CActive::EPriorityLow );
   486 	iAsyncRedrawer = new (ELeave) CAsyncCallBack( CActive::EPriorityLow );
   485 	iLastFocus = EFalse;
   487 	iLastFocus = EFalse;
   486     iDeleteTask = new (ELeave) TDeleteTask<CFSEmailUiMailListVisualiser> (*this, HandleDeleteTaskL);
   488     iDeleteTask = new (ELeave) TDeleteTask<CFSEmailUiMailListVisualiser> (*this, HandleDeleteTaskL);
   487 
   489 
   488     iNewMailTimer = CFSEmailUiGenericTimer::NewL( this );
   490     iNewMailTimer = CFSEmailUiGenericTimer::NewL( this );
       
   491     iSortTimer = CFSEmailUiGenericTimer::NewL( this );
       
   492     iSortState = ESortNone;
   489 
   493 
   490 	iTouchFeedBack = MTouchFeedback::Instance();
   494 	iTouchFeedBack = MTouchFeedback::Instance();
   491  	}
   495  	}
   492 
   496 
   493 // ---------------------------------------------------------------------------
   497 // ---------------------------------------------------------------------------
   646     delete iModel;
   650     delete iModel;
   647 
   651 
   648     delete iDeleteTask;
   652     delete iDeleteTask;
   649     DeleteSortWaitNote();
   653     DeleteSortWaitNote();
   650     delete iNewMailTimer;
   654     delete iNewMailTimer;
       
   655     delete iSortTimer;
   651     iNewMailIds.Close();
   656     iNewMailIds.Close();
   652     }
   657     }
   653 
   658 
   654 void CFSEmailUiMailListVisualiser::PrepareForExit()
   659 void CFSEmailUiMailListVisualiser::PrepareForExit()
   655     {
   660     {
   691         {
   696         {
   692         // delete also cancels timer
   697         // delete also cancels timer
   693         SafeDelete( iNewMailTimer );
   698         SafeDelete( iNewMailTimer );
   694         }
   699         }
   695 
   700 
       
   701     if ( iSortTimer )
       
   702         {
       
   703         // delete also cancels timer
       
   704         SafeDelete( iSortTimer );
       
   705         }
       
   706     
   696     SafeDelete(iMailFolder);
   707     SafeDelete(iMailFolder);
   697     iTreeItemArray.Reset();
   708     iTreeItemArray.Reset();
   698 	// Reset, not delete to avoid NULL checks.
   709 	// Reset, not delete to avoid NULL checks.
   699     iModel->Reset();
   710     iModel->Reset();
   700     // Resources freed, new start required
   711     // Resources freed, new start required
   763     if ( iSortWaitNote )
   774     if ( iSortWaitNote )
   764         {
   775         {
   765         sorting = ETrue;
   776         sorting = ETrue;
   766         }
   777         }
   767     DeleteSortWaitNote();
   778     DeleteSortWaitNote();
   768     
   779 
   769     if ( !iModel->Count() )
   780     if ( !iModel->Count() )
   770         {
   781         {
   771         iFocusedControl = EControlBarComponent;
   782         iFocusedControl = EControlBarComponent;
   772         }
   783         }
   773     else
   784     else
   819 // ---------------------------------------------------------------------------
   830 // ---------------------------------------------------------------------------
   820 //
   831 //
   821 void CFSEmailUiMailListVisualiser::SortMailListModelAsyncL()
   832 void CFSEmailUiMailListVisualiser::SortMailListModelAsyncL()
   822     {
   833     {
   823     FUNC_LOG;
   834     FUNC_LOG;
   824    
   835 
   825     DeleteSortWaitNote();
   836     DeleteSortWaitNote();
   826   
   837   
   827     TBool ret = UpdateMailListModelAsyncL( KCMsgBlockSort );
   838     TBool ret = UpdateMailListModelAsyncL( KCMsgBlockSort );
   828     
       
   829     if ( ret )
   839     if ( ret )
   830         {
   840         {
   831         TFsEmailUiUtility::ShowWaitNoteL( iSortWaitNote, R_FSE_WAIT_SORTING_TEXT, EFalse, ETrue );
   841         TFsEmailUiUtility::ShowWaitNoteL( iSortWaitNote, R_FSE_WAIT_SORTING_TEXT, EFalse, ETrue );
   832         }
   842         }
   833     }
   843     }
  1234 
  1244 
  1235         // start timer only when all conditions are met:
  1245         // start timer only when all conditions are met:
  1236         //   timer isn`t already active
  1246         //   timer isn`t already active
  1237         //   there are new mails in the array
  1247         //   there are new mails in the array
  1238         //   timer event isn`t processing
  1248         //   timer event isn`t processing
       
  1249         //   sorting timer isn't running
  1239         if ( !iNewMailTimer->IsActive() && iNewMailIds.Count() && 
  1250         if ( !iNewMailTimer->IsActive() && iNewMailIds.Count() && 
  1240              iNewMailTimer->iStatus != KErrInUse )
  1251              iNewMailTimer->iStatus != KErrInUse  && iSortState == ESortNone )
  1241             {
  1252             {
  1242             iNewMailTimer->Start( KNewMailTimerDelay );
  1253             iNewMailTimer->Start( KNewMailTimerDelay );
  1243             }
  1254             }
  1244         }
  1255         }
  1245     }
  1256     }
  1248 // ---------------------------------------------------------------------------
  1259 // ---------------------------------------------------------------------------
  1249 // TimerEventL
  1260 // TimerEventL
  1250 //
  1261 //
  1251 // ---------------------------------------------------------------------------
  1262 // ---------------------------------------------------------------------------
  1252 //
  1263 //
  1253 void CFSEmailUiMailListVisualiser::TimerEventL( CFSEmailUiGenericTimer* /*aTriggeredTimer*/ )
  1264 void CFSEmailUiMailListVisualiser::TimerEventL( CFSEmailUiGenericTimer* aTriggeredTimer )
  1254     {
  1265     {
  1255     TInt count = Min( KNewMailMaxBatch, iNewMailIds.Count() );
  1266 	
  1256     CFSMailClient* mailClient = iAppUi.GetMailClient();
  1267     if( aTriggeredTimer == iSortTimer )
  1257 
  1268         {
  1258     // Enter critical section
  1269         switch ( iSortState )
  1259     // Because CFSMailClient::GetMessageByUidL can use CActiveSchedulerWait
  1270             {
  1260     // to ensure that only one TimerEventL method is processed at time
  1271             case ESortNone:
  1261     // CFSEmailUiGenericTimer`s iStatus will be used as mutex
  1272                 {
  1262     iNewMailTimer->iStatus = KErrInUse;
  1273                 iSortTryCount = 0;
  1263 
  1274                 iSortState = ESortRequested;
  1264     for ( TInt i = 0; i < count; i++ )
  1275                 break;
  1265         {
  1276                 }
  1266         CFSMailMessage* msgPtr = mailClient->GetMessageByUidL( iAppUi.GetActiveMailboxId(),
  1277             case ESortRequested:
       
  1278                 {
       
  1279                 if( !iNewMailTimer->IsActive() && iNewMailTimer->iStatus != KErrInUse )
       
  1280         	{
       
  1281                     // Size sorting does not use nodes, so disable those, otherwise check from CR
       
  1282                     iNodesInUse = iAppUi.GetCRHandler()->TitleDividers();
       
  1283                     SetSortButtonTextAndIconL();
       
  1284 
       
  1285                     iFocusedControl = EControlBarComponent;
       
  1286                     iMailList->SetFocusedL( EFalse );
       
  1287                     iControlBarControl->SetFocusByIdL( iSortButtonId );
       
  1288 
       
  1289                     SortMailListModelAsyncL();  // sort can take long time    
       
  1290                     SetMskL();
       
  1291                     iSortState = ESortStarted;
       
  1292                     }
       
  1293                 else
       
  1294                     {
       
  1295                     iSortTryCount = 0;
       
  1296                     iSortState = ESortPostponed;
       
  1297                     iNewMailTimer->Stop(); // stop mail timer
       
  1298                     }
       
  1299                 break;
       
  1300                 }
       
  1301             case ESortPostponed:
       
  1302                 {
       
  1303                 if ( !iNewMailTimer->IsActive() && iNewMailTimer->iStatus != KErrInUse )
       
  1304                     {
       
  1305                     iSortState = ESortRequested; // start request again
       
  1306                     }
       
  1307                 else
       
  1308                     {
       
  1309                     iSortTryCount++;
       
  1310                     }
       
  1311                 if( iSortTryCount >= KSortCountdown )// repeat a few times
       
  1312                     {
       
  1313                     iSortTryCount = 0; // reset
       
  1314                     iSortState = ESortStartError; // can't start sorting  some error
       
  1315                     }
       
  1316                 break;
       
  1317                 }
       
  1318             case ESortStarted:
       
  1319                 {
       
  1320                 if ( !iSortWaitNote )// it will restart the timer elsewhere (see below)
       
  1321                     {
       
  1322                     iSortState = ESortCompleted;
       
  1323                     }
       
  1324                 break;
       
  1325                 }
       
  1326             case ESortStartError:
       
  1327             case ESortCompleted:
       
  1328                 {
       
  1329             	if( !iNewMailTimer->IsActive() )
       
  1330             	    {
       
  1331             	    // refresh the whole mail list if list was sorted
       
  1332             	    if(iSortState != ESortStartError )
       
  1333             	    	{
       
  1334             	        RefreshL();
       
  1335             	    	}
       
  1336             	    // stop sorting process
       
  1337                     iSortState = ESortNone;
       
  1338                     iSortTimer->Stop();
       
  1339             	    // restart if more messages available
       
  1340             	    if ( iNewMailIds.Count() )
       
  1341                     {
       
  1342                     iNewMailTimer->Start( KNewMailTimerDelay );
       
  1343                     }
       
  1344                 return;
       
  1345             		}
       
  1346                 iNewMailTimer->Stop();
       
  1347             	break;
       
  1348                 }
       
  1349             default :
       
  1350                 {
       
  1351                 // do nothing
       
  1352                 }
       
  1353             }
       
  1354         // start timer again
       
  1355         if ( !iSortTimer->IsActive() )
       
  1356             {
       
  1357             iSortTimer->Start( KSortTimerDelay );
       
  1358             }
       
  1359         }
       
  1360     
       
  1361     if( aTriggeredTimer == iNewMailTimer )
       
  1362         {
       
  1363         TInt count = Min( KNewMailMaxBatch, iNewMailIds.Count() );
       
  1364         CFSMailClient* mailClient = iAppUi.GetMailClient();
       
  1365 
       
  1366         // Enter critical section
       
  1367         // Because CFSMailClient::GetMessageByUidL can use CActiveSchedulerWait
       
  1368         // to ensure that only one TimerEventL method is processed at time
       
  1369         // CFSEmailUiGenericTimer`s iStatus will be used as mutex
       
  1370         iNewMailTimer->iStatus = KErrInUse;
       
  1371         iModel->SetSortCriteria(iCurrentSortCriteria);
       
  1372 
       
  1373         for ( TInt i = 0; i < count; i++ )
       
  1374             {
       
  1375             // stop synchronization if mail list is being sorted
       
  1376             if( iSortState != ESortNone || iSortWaitNote )
       
  1377                 {
       
  1378                 iNewMailTimer->iStatus = KErrNone;
       
  1379                 iNewMailTimer->Stop();
       
  1380                 return; // leave  method
       
  1381                 }
       
  1382     
       
  1383             CFSMailMessage* msgPtr = mailClient->GetMessageByUidL( iAppUi.GetActiveMailboxId(),
  1267                                                                iMailFolder->GetFolderId(),
  1384                                                                iMailFolder->GetFolderId(),
  1268                                                                iNewMailIds[ 0 ],
  1385                                                                iNewMailIds[ 0 ],
  1269                                                                EFSMsgDataEnvelope );
  1386                                                                EFSMsgDataEnvelope );
  1270         if ( msgPtr != NULL )
  1387             if ( msgPtr != NULL )
  1271             {
  1388  {
  1272             CleanupStack::PushL( msgPtr );
  1389                 __ASSERT_DEBUG( FolderId() == msgPtr->GetFolderId(), User::Invariant() );
  1273             //first item - show scrollbar
  1390                 CleanupStack::PushL( msgPtr );
  1274             //last item - update scrollbar
  1391                 //first item - show scrollbar
  1275             TBool allowRefresh = ( i == 0 || i == count - 1 );
  1392                 //last item - update scrollbar
  1276             InsertNewMessageL( msgPtr, allowRefresh );
  1393                 TBool allowRefresh = ( i == 0 || i == count - 1 );
  1277             CleanupStack::Pop( msgPtr ); // ownership transferred to model
  1394                 InsertNewMessageL( msgPtr, allowRefresh );
  1278             }
  1395                 CleanupStack::Pop( msgPtr ); // ownership transferred to model
  1279         // pop processed id from the queue, this is single thread operation
  1396                 }
  1280         iNewMailIds.Remove( 0 ); 
  1397             // pop processed id from the queue, this is single thread operation
  1281         }
  1398             iNewMailIds.Remove( 0 ); 
  1282 
  1399             }
  1283     // End critical section
  1400             
  1284     iNewMailTimer->iStatus = KErrNone;
  1401         // End critical section
  1285 
  1402         iNewMailTimer->iStatus = KErrNone;
  1286     // if timer stoped then restart if more messages available
  1403 
  1287     if ( iNewMailIds.Count() && ! iNewMailTimer->IsActive() )
  1404         // if timer stoped then restart if more messages available
  1288         {
  1405         if ( iNewMailIds.Count() && ! iNewMailTimer->IsActive() && iSortState == ESortNone )
  1289         iNewMailTimer->Start( KNewMailTimerDelay );
  1406             {
  1290         }
  1407             iNewMailTimer->Start( KNewMailTimerDelay );
       
  1408             }
       
  1409         }//iNewMailTimer
  1291     }
  1410     }
  1292 
  1411 
  1293 // ---------------------------------------------------------------------------
  1412 // ---------------------------------------------------------------------------
  1294 // InsertNewMessageL
  1413 // InsertNewMessageL
  1295 // Creates a single new message item to the model and tree list from the given
  1414 // Creates a single new message item to the model and tree list from the given
  1558     iScreenAnchorLayout->SetSize( clientRect.Size() );
  1677     iScreenAnchorLayout->SetSize( clientRect.Size() );
  1559     SetMailListLayoutAnchors();
  1678     SetMailListLayoutAnchors();
  1560     //if the view is already active don't update the icons so they won't "blink" 
  1679     //if the view is already active don't update the icons so they won't "blink" 
  1561     //when the view is activated.
  1680     //when the view is activated.
  1562     if(!iThisViewActive)
  1681     if(!iThisViewActive)
  1563         { 
  1682         {     
  1564         ScaleControlBarL();
  1683         ScaleControlBarL();
       
  1684         
       
  1685         // Set icons on toolbar
       
  1686         iAppUi.FsTextureManager()->ClearTextureByIndex( EListControlBarMailboxDefaultIcon );
       
  1687         iFolderListButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( EListControlBarMailboxDefaultIcon ) );
       
  1688         iAppUi.FsTextureManager()->ClearTextureByIndex( EListTextureCreateNewMessageIcon );
       
  1689         iNewEmailButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( EListTextureCreateNewMessageIcon ) );
       
  1690         iAppUi.FsTextureManager()->ClearTextureByIndex( GetSortButtonTextureIndex() );
       
  1691         iSortButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( GetSortButtonTextureIndex() ) );
       
  1692 
  1565         SetListAndCtrlBarFocusL();
  1693         SetListAndCtrlBarFocusL();
  1566         }
  1694         }
  1567 
  1695 
  1568 	FadeOut(EFalse); // we can show now CAlfVisuals from CurrentView (to show Folders before updating emails)
  1696 	FadeOut(EFalse); // we can show now CAlfVisuals from CurrentView (to show Folders before updating emails)
  1569     
  1697     
  1714 
  1842 
  1715     // if mailbox changed stop timer driven insertion of new mails into list
  1843     // if mailbox changed stop timer driven insertion of new mails into list
  1716     if ( activationData.iMailBoxId != prevMailBoxId )
  1844     if ( activationData.iMailBoxId != prevMailBoxId )
  1717         {
  1845         {
  1718         iNewMailTimer->Cancel();
  1846         iNewMailTimer->Cancel();
       
  1847         iSortTimer->Cancel(); // stop sorting timer
  1719         iNewMailIds.Reset();
  1848         iNewMailIds.Reset();
  1720         }
  1849         }
  1721 
  1850 
  1722     // CHECK IF MODEL NEEDS TO BE UPDATED
  1851     // CHECK IF MODEL NEEDS TO BE UPDATED
  1723     if ( activationData.iMailBoxId != prevMailBoxId ||
  1852     if ( activationData.iMailBoxId != prevMailBoxId ||
  1755     SetMailboxNameToStatusPaneL();
  1884     SetMailboxNameToStatusPaneL();
  1756 
  1885 
  1757     // Set branded watermark and mailbox icon
  1886     // Set branded watermark and mailbox icon
  1758     SetBrandedListWatermarkL();
  1887     SetBrandedListWatermarkL();
  1759     SetBrandedMailBoxIconL();
  1888     SetBrandedMailBoxIconL();
  1760 
  1889     
  1761     // Check sync icon timer and sync status
  1890     // Check sync icon timer and sync status
  1762     ConnectionIconHandling();
  1891     ConnectionIconHandling();
  1763 
  1892 
  1764     // REBUILD TREE LIST IF NECESSARY
  1893     // REBUILD TREE LIST IF NECESSARY
  1765     if ( refreshState == EFullRefreshNeeded )
  1894     if ( refreshState == EFullRefreshNeeded )
  2067 	    // "Clear deleted folder" command is available only in Deleted folder
  2196 	    // "Clear deleted folder" command is available only in Deleted folder
  2068 	    if ( currentFolderType != EFSDeleted || !iModel->Count() )
  2197 	    if ( currentFolderType != EFSDeleted || !iModel->Count() )
  2069 	        {
  2198 	        {
  2070 	        aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsEmptyDeleted, ETrue );
  2199 	        aMenuPane->SetItemDimmed( EFsEmailUiCmdActionsEmptyDeleted, ETrue );
  2071 	        }
  2200 	        }
  2072 		}
  2201 	    
       
  2202 	    CConnectionStatusQueryExtension::TConnectionStatus connetionStatus;
       
  2203         iAppUi.GetConnectionStatusL( connetionStatus );
       
  2204         if ( connetionStatus == CConnectionStatusQueryExtension::ESynchronizing )
       
  2205             {
       
  2206             aMenuPane->SetItemDimmed( EFsEmailUiCmdSync, ETrue );
       
  2207             aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelSync, EFalse );
       
  2208             }
       
  2209         else
       
  2210             {
       
  2211             aMenuPane->SetItemDimmed( EFsEmailUiCmdSync, EFalse );
       
  2212             aMenuPane->SetItemDimmed( EFsEmailUiCmdCancelSync, ETrue );
       
  2213             }
       
  2214 	    }
       
  2215 	
  2073     // MAIN MENU ***************************************************************************
  2216     // MAIN MENU ***************************************************************************
  2074 
  2217 
  2075 
  2218 
  2076 	// ACTIONS SUBMENU *********************************************************************
  2219 	// ACTIONS SUBMENU *********************************************************************
  2077 	if ( aResourceId == R_FSEMAILUI_MAILLIST_SUBMENU_MAIL_ACTIONS  )
  2220 	if ( aResourceId == R_FSEMAILUI_MAILLIST_SUBMENU_MAIL_ACTIONS  )
  3269         UpdateThemeL();
  3412         UpdateThemeL();
  3270         }
  3413         }
  3271     else if ( aType == EScreenLayoutChanged )
  3414     else if ( aType == EScreenLayoutChanged )
  3272         {
  3415         {
  3273         UpdateButtonTextsL();
  3416         UpdateButtonTextsL();
  3274         
       
  3275         iAppUi.FsTextureManager()->ClearTextureByIndex( EListControlBarMailboxDefaultIcon );
       
  3276         iFolderListButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( EListControlBarMailboxDefaultIcon ) );
       
  3277         iAppUi.FsTextureManager()->ClearTextureByIndex( EListTextureCreateNewMessageIcon );
       
  3278         iNewEmailButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( EListTextureCreateNewMessageIcon ) );
       
  3279         iAppUi.FsTextureManager()->ClearTextureByIndex( GetSortButtonTextureIndex() );
       
  3280         iSortButton->SetIconL( iAppUi.FsTextureManager()->TextureByIndex( GetSortButtonTextureIndex() ) );
       
  3281 
       
  3282         ScaleControlBarL();
       
  3283         }
  3417         }
  3284     }
  3418     }
  3285 
  3419 
  3286 // ---------------------------------------------------------------------------
  3420 // ---------------------------------------------------------------------------
  3287 // Update texts for command area buttons
  3421 // Update texts for command area buttons
  4073                 {
  4207                 {
  4074                 DeleteMessagesL();
  4208                 DeleteMessagesL();
  4075                 }
  4209                 }
  4076             }
  4210             }
  4077             break;
  4211             break;
  4078 		case EFsEmailUiCmdCompose:
  4212         case EFsEmailUiCmdCompose:
  4079 			{
  4213             {
  4080 			TIMESTAMP( "Create new message selected from message list" );
  4214             // Switching to another view can take some time and this view
  4081 			CreateNewMsgL();
  4215             // can still receive some commands - so ignore them.
  4082 			}
  4216             if ( iAppUi.CurrentActiveView() == this )
  4083 			break;
  4217                 {
       
  4218                 TIMESTAMP( "Create new message selected from message list" );
       
  4219                 CreateNewMsgL();
       
  4220                 }
       
  4221             }
       
  4222             break;
  4084        	case EFsEmailUiCmdMessageDetails:
  4223        	case EFsEmailUiCmdMessageDetails:
  4085 			{
  4224 			{
  4086             // Message details can be viewed only when there's exactly one message marked or in focus
  4225             // Message details can be viewed only when there's exactly one message marked or in focus
  4087             if ( actionTargetItems.Count() == 1 )
  4226             if ( actionTargetItems.Count() == 1 )
  4088                 {
  4227                 {
  4276 			    //POP3 synchronise
  4415 			    //POP3 synchronise
  4277 				iAppUi.DoAutoConnectL();
  4416 				iAppUi.DoAutoConnectL();
  4278 				}
  4417 				}
  4279 			}
  4418 			}
  4280 			break;
  4419 			break;
       
  4420        	case EFsEmailUiCmdCancelSync:
       
  4421        	    {
       
  4422        	    if ( GetLatestSyncState() )
       
  4423        	        {
       
  4424                 iAppUi.StopActiveMailBoxSyncL();
       
  4425        	        }
       
  4426        	    }
       
  4427        	    break;
  4281        	case EFsEmailUiCmdGoOffline:
  4428        	case EFsEmailUiCmdGoOffline:
  4282         	{
  4429         	{
  4283     	   	iAppUi.GetActiveMailbox()->GoOfflineL();
  4430     	   	iAppUi.GetActiveMailbox()->GoOfflineL();
  4284         	}
  4431         	}
  4285         	break;
  4432         	break;
  5281                     {
  5428                     {
  5282                     MarkItemsUnderSeparatorL( ETrue, index );
  5429                     MarkItemsUnderSeparatorL( ETrue, index );
  5283                     }
  5430                     }
  5284 			    }
  5431 			    }
  5285 			}
  5432 			}
  5286 		else
  5433         else if ( iAppUi.CurrentActiveView() == this )
  5287 			{
  5434             {
  5288 		
  5435 
  5289 			// MAIL ITEM; OPEN MAIL
  5436 			// MAIL ITEM; OPEN MAIL
  5290 			if ( item && item->ModelItemType() == ETypeMailItem )
  5437 			if ( item && item->ModelItemType() == ETypeMailItem )
  5291 				{
  5438 				{
  5292 				CFSMailMessage* messagePtr = &item->MessagePtr();
  5439 				CFSMailMessage* messagePtr = &item->MessagePtr();
  5293 				if ( messagePtr )
  5440 				if ( messagePtr )
  5338             }
  5485             }
  5339         else
  5486         else
  5340             {
  5487             {
  5341             folderType = EFSInbox;
  5488             folderType = EFSInbox;
  5342             }
  5489             }
  5343         if ( iModel->Count() )
  5490         // we can't show sort list when sorting is active
       
  5491         if ( iModel->Count() && iSortState == ESortNone )
  5344             {
  5492             {
  5345             //Set touchmanager not active for preventing getting events.
  5493             //Set touchmanager not active for preventing getting events.
  5346             DisableMailList(ETrue);
  5494             DisableMailList(ETrue);
  5347             iAppUi.ShowSortListInPopupL( iCurrentSortCriteria, folderType, this, iSortButton );
  5495             iAppUi.ShowSortListInPopupL( iCurrentSortCriteria, folderType, this, iSortButton );
  5348             }
  5496             }
  6216             CFSMailMessage* confirmedMsgPtr = NULL;
  6364             CFSMailMessage* confirmedMsgPtr = NULL;
  6217             TRAP_IGNORE( confirmedMsgPtr = iAppUi.GetMailClient()->GetMessageByUidL( iAppUi.GetActiveMailboxId(),
  6365             TRAP_IGNORE( confirmedMsgPtr = iAppUi.GetMailClient()->GetMessageByUidL( iAppUi.GetActiveMailboxId(),
  6218                                                                                      iMailFolder->GetFolderId(),
  6366                                                                                      iMailFolder->GetFolderId(),
  6219                                                                                      modelItem->MessagePtr().GetMessageId() ,
  6367                                                                                      modelItem->MessagePtr().GetMessageId() ,
  6220                                                                                      EFSMsgDataEnvelope ) );
  6368                                                                                      EFSMsgDataEnvelope ) );
  6221             if ( confirmedMsgPtr )
  6369             if( aIndex < iTreeItemArray.Count() )
  6222                 {
  6370                 {
  6223                 // Replace message pointer in model with newly fetched one
  6371                 if ( confirmedMsgPtr )
  6224                 Model()->ReplaceMessagePtr( aIndex, confirmedMsgPtr );
       
  6225 
       
  6226                 const SMailListItem& item = iTreeItemArray[aIndex];
       
  6227 
       
  6228                 // Update the list item contents and formating to match the message pointer
       
  6229                 CFsTreePlainTwoLineItemData* itemData =
       
  6230                     static_cast<CFsTreePlainTwoLineItemData*>( item.iTreeItemData );
       
  6231                 CFsTreePlainTwoLineItemVisualizer* itemVis =
       
  6232                     static_cast<CFsTreePlainTwoLineItemVisualizer*>( item.iTreeItemVisualiser );
       
  6233 
       
  6234                 UpdateItemDataL( itemData, confirmedMsgPtr );
       
  6235                 UpdatePreviewPaneTextForItemL( itemData, confirmedMsgPtr );
       
  6236                 UpdateMsgIconAndBoldingL( itemData, itemVis, confirmedMsgPtr );
       
  6237                 iMailTreeListVisualizer->UpdateItemL( item.iListItemId );
       
  6238                 }
       
  6239             else
       
  6240                 {
       
  6241                 // No confirmed message for highlighted, remove from list also
       
  6242                 iMailList->RemoveL( iTreeItemArray[aIndex].iListItemId ); // remove from list
       
  6243                 iTreeItemArray.Remove( aIndex ); // remove from internal array.
       
  6244                 iModel->RemoveAndDestroy( aIndex ); // Remove from model
       
  6245                 if ( iNodesInUse )
       
  6246                     {
  6372                     {
  6247                     RemoveUnnecessaryNodesL();
  6373                     const SMailListItem& item = iTreeItemArray[aIndex];
       
  6374                     // Replace message pointer in model with newly fetched one
       
  6375                     Model()->ReplaceMessagePtr( aIndex, confirmedMsgPtr );
       
  6376 
       
  6377                     // Update the list item contents and formating to match the message pointer
       
  6378                     CFsTreePlainTwoLineItemData* itemData =
       
  6379                         static_cast<CFsTreePlainTwoLineItemData*>( item.iTreeItemData );
       
  6380                     CFsTreePlainTwoLineItemVisualizer* itemVis =
       
  6381                         static_cast<CFsTreePlainTwoLineItemVisualizer*>( item.iTreeItemVisualiser );
       
  6382 
       
  6383                     UpdateItemDataL( itemData, confirmedMsgPtr );
       
  6384                     UpdatePreviewPaneTextForItemL( itemData, confirmedMsgPtr );
       
  6385                     UpdateMsgIconAndBoldingL( itemData, itemVis, confirmedMsgPtr );
       
  6386                     iMailTreeListVisualizer->UpdateItemL( item.iListItemId );
  6248                     }
  6387                     }
  6249                 }
  6388                 else
       
  6389                     {
       
  6390                     // No confirmed message for highlighted, remove from list also
       
  6391                     iMailList->RemoveL( iTreeItemArray[aIndex].iListItemId ); // remove from list
       
  6392                     iTreeItemArray.Remove( aIndex ); // remove from internal array.
       
  6393                     iModel->RemoveAndDestroy( aIndex ); // Remove from model
       
  6394                     if ( iNodesInUse )
       
  6395                         {
       
  6396                         RemoveUnnecessaryNodesL();
       
  6397                         }
       
  6398                     }
       
  6399             	}
  6250             }
  6400             }
  6251         }
  6401         }
  6252     }
  6402     }
  6253 
  6403 
  6254 // ---------------------------------------------------------------------------
  6404 // ---------------------------------------------------------------------------
  6598     FUNC_LOG;
  6748     FUNC_LOG;
  6599     TFSMailMsgId folderId = FolderId();
  6749     TFSMailMsgId folderId = FolderId();
  6600     TFSMailMsgId mailBox = iAppUi.GetActiveMailboxId();
  6750     TFSMailMsgId mailBox = iAppUi.GetActiveMailboxId();
  6601     RArray<TFSMailMsgId> msgIds;
  6751     RArray<TFSMailMsgId> msgIds;
  6602     CleanupClosePushL( msgIds );
  6752     CleanupClosePushL( msgIds );
  6603     for ( TInt i = 0; i < aEntries.Count(); i++ )
  6753     for ( TInt i = aEntries.Count() - 1; i >= 0; i-- )
  6604         {
  6754         {
  6605         msgIds.AppendL( MsgIdFromListId( aEntries[i] ) );
  6755         msgIds.AppendL( MsgIdFromListId( aEntries[i] ) );
  6606         }
  6756         }
       
  6757 
       
  6758     // Clear the focused item to avoid repeated selection of a new focused
       
  6759     // item, unnecessary scrolling of the viewport, etc.
       
  6760     iMailTreeListVisualizer->SetFocusedItemL( KFsTreeNoneID );
       
  6761 
       
  6762     iMailList->BeginUpdate();
  6607     iAppUi.GetMailClient()->DeleteMessagesByUidL( mailBox, folderId, msgIds );
  6763     iAppUi.GetMailClient()->DeleteMessagesByUidL( mailBox, folderId, msgIds );
  6608     // Remove from mail list if not already removed by mailbox events
  6764     // Remove from mail list if not already removed by mailbox events
  6609     RemoveMsgItemsFromListIfFoundL( msgIds );
  6765     RemoveMsgItemsFromListIfFoundL( msgIds );
       
  6766     iMailList->EndUpdateL();
       
  6767 
  6610     CleanupStack::PopAndDestroy(); // msgIds.Close()
  6768     CleanupStack::PopAndDestroy(); // msgIds.Close()
  6611     }
  6769     }
  6612 
  6770 
  6613 // ---------------------------------------------------------------------------
  6771 // ---------------------------------------------------------------------------
  6614 // ConfirmDeleteL
  6772 // ConfirmDeleteL
  7035 			}
  7193 			}
  7036 
  7194 
  7037 		if ( !iMailFolder || ( iMailFolder && iMailFolder->GetFolderId() != aSelectedFolderId ) )
  7195 		if ( !iMailFolder || ( iMailFolder && iMailFolder->GetFolderId() != aSelectedFolderId ) )
  7038 		    {
  7196 		    {
  7039 		    iMailListModelUpdater->Cancel();
  7197 		    iMailListModelUpdater->Cancel();
       
  7198 		    iNewMailTimer->Cancel();
       
  7199 		    iNewMailIds.Reset();
  7040 		    SafeDelete(iMailFolder);
  7200 		    SafeDelete(iMailFolder);
  7041             iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( iAppUi.GetActiveMailboxId(), aSelectedFolderId );
  7201             iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( iAppUi.GetActiveMailboxId(), aSelectedFolderId );
  7042 
  7202 
  7043             if ( !iMailFolder )
  7203             if ( !iMailFolder )
  7044                 {
  7204                 {
  7187 		{
  7347 		{
  7188 		iCurrentSortCriteria.iOrder = EFSMailDescending;
  7348 		iCurrentSortCriteria.iOrder = EFSMailDescending;
  7189 		}
  7349 		}
  7190 
  7350 
  7191 	iCurrentSortCriteria.iField = aSortField;
  7351 	iCurrentSortCriteria.iField = aSortField;
  7192 
  7352 	iModel->SetSortCriteria(iCurrentSortCriteria);
  7193 	// Size sorting does not use nodes, so disable those, otherwise check from CR
  7353 
  7194 	iNodesInUse = iAppUi.GetCRHandler()->TitleDividers();
  7354 	// rest of the code moved to TimerEventL ( iSortTimer part )
  7195 	SetSortButtonTextAndIconL();
  7355 	// used also in DoHandleControlBarOpenL to prevent SortList reopening
  7196 
  7356 	iSortState = ESortRequested; 
  7197 	iFocusedControl = EControlBarComponent;
  7357 	iSortTimer->Start( KSortTimerDelay );	
  7198 	iMailList->SetFocusedL( EFalse );
       
  7199     iControlBarControl->SetFocusByIdL( iSortButtonId );
       
  7200 
       
  7201     SortMailListModelAsyncL();  // sort can take long time
       
  7202     // <cmail>
       
  7203 	//if ( iMailListUpdater )
       
  7204 	//    {
       
  7205     	// Start updating mail list with sorting parameter.
       
  7206     //	iMailListUpdater->StartL( ETrue );
       
  7207 	//    }
       
  7208     // </cmail>
       
  7209 	SetMskL();
       
  7210 	}
  7358 	}
  7211 
  7359 
  7212 // ---------------------------------------------------------------------------
  7360 // ---------------------------------------------------------------------------
  7213 // SortButtonRect
  7361 // SortButtonRect
  7214 // Getter for sort button rectangle. Sort popup needs to get this
  7362 // Getter for sort button rectangle. Sort popup needs to get this