emailuis/emailui/src/FreestyleEmailUiMailListVisualiser.cpp
changeset 3 a4d6f1ea0416
parent 2 5253a20d2a1e
child 8 e1b6206813b4
equal deleted inserted replaced
2:5253a20d2a1e 3:a4d6f1ea0416
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Symbian Foundation License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8 *
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    95 const TInt KMsgUpdaterTimerDelay = 2500000; // Time to update list, 2,5sec
    95 const TInt KMsgUpdaterTimerDelay = 2500000; // Time to update list, 2,5sec
    96 static const TInt KMsgDeletionWaitNoteAmount = 5;
    96 static const TInt KMsgDeletionWaitNoteAmount = 5;
    97 _LIT( KMissingPreviewDataMarker, "..." );
    97 _LIT( KMissingPreviewDataMarker, "..." );
    98 
    98 
    99 static const TInt KMaxItemsFethed = 1000;
    99 static const TInt KMaxItemsFethed = 1000;
   100 static const TInt KCMsgBlock = 100;
   100 static const TInt KCMsgBlock = 15;
       
   101 static const TInt KCMsgMaxBlock = 120;
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // Generic method for deleting a pointer and setting it NULL.
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 template <class T> void SafeDelete(T*& ptr)
       
   108     {
       
   109     delete ptr;
       
   110     ptr = NULL;
       
   111     }
       
   112 
       
   113 // CMailListModelUpdater
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // Constructor
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 CMailListModelUpdater::CMailListModelUpdater() : CActive(EPriorityStandard)
       
   120     {
       
   121     CActiveScheduler::Add(this);
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // Destructor
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 CMailListModelUpdater::~CMailListModelUpdater()
       
   129     {
       
   130     iObserver = NULL;
       
   131     Cancel();
       
   132     iSorting.Close();
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // Returns arrays for sorting parameters. Updater owns the arrays because
       
   137 // it has to stay alive as long as the iterator is being used.
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 RArray<TFSMailSortCriteria>& CMailListModelUpdater::Sorting()
       
   141     {
       
   142     iSorting.Reset();
       
   143     return iSorting;
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // Update the mail list model from given iterator. Update progress will be
       
   148 // informed to the observer.
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CMailListModelUpdater::UpdateModelL(MObserver& aObserver, MFSMailIterator* aIterator)
       
   152     {
       
   153     Cancel();
       
   154     iObserver = &aObserver;
       
   155     iIterator = aIterator;
       
   156     Signal(EInitialize);
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // Internal method. Sets new state and signals itself.
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CMailListModelUpdater::Signal(TState aState, TInt aError)
       
   164     {
       
   165     iState = aState;
       
   166     iStatus = KRequestPending;
       
   167     SetActive();
       
   168     TRequestStatus* status = &iStatus;
       
   169     User::RequestComplete(status, aError);
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // Initialization state. Reset update and call UpdateBeginL() for the observer.
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CMailListModelUpdater::InitializeL()
       
   177     {
       
   178     iBlockSize = KCMsgBlock;
       
   179     iParentId = KFsTreeRootID;
       
   180     iId = TFSMailMsgId();
       
   181     iItemsFetched = 0;
       
   182     iObserver->UpdateBeginL();
       
   183     Signal(EFetch);
       
   184     }
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // Fetch state. Fetch next messages and if there is more messages signal
       
   188 // fetch state again OR proceed to finalizing state.
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void CMailListModelUpdater::FetchL()
       
   192     {
       
   193     RPointerArray<CFSMailMessage> messages(iBlockSize);
       
   194     CleanupClosePushL(messages);
       
   195     const TBool moreMessages(iIterator->NextL(iId, iBlockSize, messages));
       
   196     iBlockSize = Min(KCMsgMaxBlock, iBlockSize * 2);
       
   197     if (messages.Count() > 0)
       
   198         {
       
   199         iItemsFetched += messages.Count();
       
   200         iId = messages[messages.Count() - 1]->GetMessageId();
       
   201         iObserver->UpdateProgressL(iParentId, messages);
       
   202         }
       
   203     CleanupStack::PopAndDestroy(); // messages.Close()
       
   204     if (moreMessages && iItemsFetched < KMaxItemsFethed)
       
   205         {
       
   206         Signal(EFetch);
       
   207         }
       
   208     else
       
   209         {
       
   210         Signal(EFinalize);
       
   211         }
       
   212     }
       
   213 
       
   214 // ---------------------------------------------------------------------------
       
   215 // Finalizing state. Notify observer that model update has been done and
       
   216 // free the resources.
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 void CMailListModelUpdater::FinalizeL()
       
   220     {
       
   221     iObserver->UpdateCompleteL();
       
   222     Reset();
       
   223     }
       
   224 
       
   225 // ---------------------------------------------------------------------------
       
   226 // If the state is anything but EIdle, returns ETrue.
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 TBool CMailListModelUpdater::IsUpdating() const
       
   230     {
       
   231     return iState > EIdle;
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // Reset the state to EIdle and free resources.
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 void CMailListModelUpdater::Reset()
       
   239     {
       
   240     iSorting.Reset();
       
   241     SafeDelete(iIterator);
       
   242     iState = EIdle;
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // Active objects RunL()
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 void CMailListModelUpdater::RunL()
       
   250     {
       
   251     const TInt error(iStatus.Int());
       
   252     if (!error)
       
   253         {
       
   254         switch (iState)
       
   255             {
       
   256             case EInitialize:
       
   257                 InitializeL();
       
   258                 break;
       
   259             case EFetch:
       
   260                 FetchL();
       
   261                 break;
       
   262             case EFinalize:
       
   263             default:
       
   264                 FinalizeL();
       
   265                 break;
       
   266             }
       
   267         }
       
   268     else
       
   269         {
       
   270         iObserver->UpdateErrorL(error);
       
   271         }
       
   272     }
       
   273 
       
   274 // ---------------------------------------------------------------------------
       
   275 // Update has been cancelled. Inform the observer and free resources.
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 void CMailListModelUpdater::DoCancel()
       
   279     {
       
   280     if (iObserver)
       
   281         {
       
   282         iObserver->UpdateCancelled(IsUpdating());
       
   283         }
       
   284     Reset();
       
   285     }
   101 
   286 
   102 // ---------------------------------------------------------------------------
   287 // ---------------------------------------------------------------------------
   103 // Static constructor.
   288 // Static constructor.
   104 // ---------------------------------------------------------------------------
   289 // ---------------------------------------------------------------------------
   105 //
   290 //
   136 void CFSEmailUiMailListVisualiser::ConstructL()
   321 void CFSEmailUiMailListVisualiser::ConstructL()
   137 	{
   322 	{
   138     FUNC_LOG;
   323     FUNC_LOG;
   139 
   324 
   140 	BaseConstructL( R_FSEMAILUI_MAIL_LIST_VIEW );
   325 	BaseConstructL( R_FSEMAILUI_MAIL_LIST_VIEW );
       
   326 
       
   327 	iMailListModelUpdater = new (ELeave) CMailListModelUpdater();
   141 
   328 
   142 	// Don't construct this anywhere else than here.
   329 	// Don't construct this anywhere else than here.
   143 	// Don't delete this until in the destructor to avoid NULL checks.
   330 	// Don't delete this until in the destructor to avoid NULL checks.
   144     iModel = CFSEmailUiMailListModel::NewL( &iAppUi );
   331     iModel = CFSEmailUiMailListModel::NewL( &iAppUi );
   145 
   332 
   280 CFSEmailUiMailListVisualiser::CFSEmailUiMailListVisualiser( CAlfEnv& aEnv,
   467 CFSEmailUiMailListVisualiser::CFSEmailUiMailListVisualiser( CAlfEnv& aEnv,
   281     CFreestyleEmailUiAppUi* aAppUi, CAlfControlGroup& aMailListControlGroup )
   468     CFreestyleEmailUiAppUi* aAppUi, CAlfControlGroup& aMailListControlGroup )
   282     : CFsEmailUiViewBase( aMailListControlGroup, *aAppUi ),
   469     : CFsEmailUiViewBase( aMailListControlGroup, *aAppUi ),
   283     iEnv( aEnv ),
   470     iEnv( aEnv ),
   284     iListMarkItemsState( ETrue ), //Initlly list has no markings
   471     iListMarkItemsState( ETrue ), //Initlly list has no markings
   285     iConsumeStdKeyYes_KeyUp( EFalse ), // use to prevent Call application execution if call for contact processed
   472     iMoveToFolderOngoing( EFalse ),
   286     iMoveToFolderOngoing( EFalse )
   473     iConsumeStdKeyYes_KeyUp( EFalse ) // use to prevent Call application execution if call for contact processed
   287 	{
   474 	{
   288     FUNC_LOG;
   475     FUNC_LOG;
   289 	}
   476 	}
   290 
   477 
   291 // ---------------------------------------------------------------------------
   478 // ---------------------------------------------------------------------------
   293 // ---------------------------------------------------------------------------
   480 // ---------------------------------------------------------------------------
   294 //
   481 //
   295 CFSEmailUiMailListVisualiser::~CFSEmailUiMailListVisualiser()
   482 CFSEmailUiMailListVisualiser::~CFSEmailUiMailListVisualiser()
   296     {
   483     {
   297     FUNC_LOG;
   484     FUNC_LOG;
   298     if ( iMailFolder )
   485     SafeDelete(iMailListModelUpdater);
   299         {
   486     SafeDelete(iMailFolder);
   300         delete iMailFolder;
       
   301         iMailFolder = NULL;
       
   302         }
       
   303 
       
   304     delete iTouchManager;
   487     delete iTouchManager;
   305     delete iStylusPopUpMenu;
   488     delete iStylusPopUpMenu;
   306     delete iMailList;
   489     delete iMailList;
   307     delete iNewEmailText;
   490     delete iNewEmailText;
   308 
   491 
   312     }
   495     }
   313 
   496 
   314 void CFSEmailUiMailListVisualiser::PrepareForExit()
   497 void CFSEmailUiMailListVisualiser::PrepareForExit()
   315     {
   498     {
   316     FUNC_LOG;
   499     FUNC_LOG;
       
   500     iMailListModelUpdater->Cancel();
   317     if ( iMsgNoteTimer )
   501     if ( iMsgNoteTimer )
   318         {
   502         {
   319         iMsgNoteTimer->Cancel();
   503         iMsgNoteTimer->Cancel();
   320         delete iMsgNoteTimer;
   504         SafeDelete(iMsgNoteTimer);
   321         iMsgNoteTimer = NULL;
       
   322         }
   505         }
   323     if ( iDateChangeTimer )
   506     if ( iDateChangeTimer )
   324         {
   507         {
   325         iDateChangeTimer->Cancel();
   508         iDateChangeTimer->Cancel();
   326         delete iDateChangeTimer;
   509         SafeDelete(iDateChangeTimer);
   327         iDateChangeTimer = NULL;
       
   328         }
   510         }
   329     if ( iMailListUpdater )
   511     if ( iMailListUpdater )
   330         {
   512         {
   331         iMailListUpdater->Stop();
   513         iMailListUpdater->Stop();
   332         delete iMailListUpdater;
   514         SafeDelete(iMailListUpdater);
   333         iMailListUpdater = NULL;
       
   334         }
   515         }
   335     if ( iAsyncRedrawer )
   516     if ( iAsyncRedrawer )
   336         {
   517         {
   337         iAsyncRedrawer->Cancel();
   518         iAsyncRedrawer->Cancel();
   338         delete iAsyncRedrawer;
   519         SafeDelete(iAsyncRedrawer);
   339         iAsyncRedrawer = NULL;
       
   340         }
   520         }
   341     if ( iAsyncCallback )
   521     if ( iAsyncCallback )
   342         {
   522         {
   343         iAsyncCallback->Cancel();
   523         iAsyncCallback->Cancel();
   344         delete iAsyncCallback;
   524         SafeDelete(iAsyncCallback);
   345         iAsyncCallback = NULL;
       
   346         }
   525         }
   347     if ( iMailList )
   526     if ( iMailList )
   348         {
   527         {
   349         iMailList->RemoveObserver( *this );
   528         iMailList->RemoveObserver( *this );
   350         }
   529         }
   351     if ( iControlBarControl )
   530     if ( iControlBarControl )
   352         {
   531         {
   353         iControlBarControl->RemoveObserver( *this );
   532         iControlBarControl->RemoveObserver( *this );
   354         }
   533         }
   355     // <cmail>
   534     SafeDelete(iMailFolder);
   356     iTreeItemArray.Reset();
   535     iTreeItemArray.Reset();
   357     if ( iMailFolder )
       
   358         {
       
   359         delete iMailFolder;
       
   360         iMailFolder = NULL;
       
   361         }
       
   362 	// Reset, not delete to avoid NULL checks.
   536 	// Reset, not delete to avoid NULL checks.
   363     iModel->Reset();
   537     iModel->Reset();
   364     // </cmail>
       
   365     }
   538     }
   366 
   539 
   367 // ---------------------------------------------------------------------------
   540 // ---------------------------------------------------------------------------
   368 // Returns reference to mail list.
   541 // Returns reference to mail list.
   369 // ---------------------------------------------------------------------------
   542 // ---------------------------------------------------------------------------
   373     FUNC_LOG;
   546     FUNC_LOG;
   374 	return *iMailList;
   547 	return *iMailList;
   375 	}
   548 	}
   376 
   549 
   377 // ---------------------------------------------------------------------------
   550 // ---------------------------------------------------------------------------
       
   551 // @see CMailListModelUpdater::MObserver::UpdateErrorL
       
   552 // ---------------------------------------------------------------------------
       
   553 //
       
   554 void CFSEmailUiMailListVisualiser::UpdateErrorL(TInt aError)
       
   555     {
       
   556     FUNC_LOG;
       
   557     User::Leave(aError);
       
   558     }
       
   559 
       
   560 // ---------------------------------------------------------------------------
       
   561 // @see CMailListModelUpdater::MObserver::UpdateBeginL
       
   562 // ---------------------------------------------------------------------------
       
   563 //
       
   564 void CFSEmailUiMailListVisualiser::UpdateBeginL()
       
   565     {
       
   566     FUNC_LOG;
       
   567     iModel->Reset();
       
   568     iTreeItemArray.Reset();
       
   569     }
       
   570 
       
   571 // ---------------------------------------------------------------------------
       
   572 // @see CMailListModelUpdater::MObserver::UpdateProgressL
       
   573 // ---------------------------------------------------------------------------
       
   574 //
       
   575 void CFSEmailUiMailListVisualiser::UpdateProgressL(TFsTreeItemId& aParentId, RPointerArray<CFSMailMessage>& aMessages)
       
   576     {
       
   577     FUNC_LOG;
       
   578     const TInt itemsInModel(iModel->Count());
       
   579     CreateModelItemsL(aMessages);
       
   580     RefreshListItemsL(aParentId, itemsInModel, iModel->Count());
       
   581     }
       
   582 
       
   583 // ---------------------------------------------------------------------------
       
   584 // @see CMailListModelUpdater::MObserver::UpdateCompleteL
       
   585 // ---------------------------------------------------------------------------
       
   586 //
       
   587 void CFSEmailUiMailListVisualiser::UpdateCompleteL()
       
   588     {
       
   589     FUNC_LOG;
       
   590     if ( !iModel->Count() )
       
   591         {
       
   592         iFocusedControl = EControlBarComponent;
       
   593         }
       
   594     else
       
   595         {
       
   596         iFocusedControl = EMailListComponent;
       
   597         if (iMailList->FocusedItem() == KFsTreeNoneID)
       
   598             {
       
   599             iMailList->SetFocusedItemL( iTreeItemArray[0].iListItemId );
       
   600             }
       
   601         }
       
   602     SetListAndCtrlBarFocusL();
       
   603     iAppUi.StartMonitoringL();
       
   604     }
       
   605 
       
   606 // ---------------------------------------------------------------------------
       
   607 // @see CMailListModelUpdater::MObserver::UpdateCancelled
       
   608 // ---------------------------------------------------------------------------
       
   609 //
       
   610 void CFSEmailUiMailListVisualiser::UpdateCancelled(const TBool aForceRefresh)
       
   611     {
       
   612     FUNC_LOG;
       
   613     iForceRefresh = aForceRefresh;
       
   614     }
       
   615 
       
   616 // ---------------------------------------------------------------------------
       
   617 // Asynchronous mail list model update.
       
   618 // ---------------------------------------------------------------------------
       
   619 //
       
   620 void CFSEmailUiMailListVisualiser::UpdateMailListModelAsyncL()
       
   621     {
       
   622     FUNC_LOG;
       
   623     if ( iMailFolder )
       
   624         {
       
   625         TFSMailDetails details( EFSMsgDataEnvelope );
       
   626         RArray<TFSMailSortCriteria>& sorting(iMailListModelUpdater->Sorting());
       
   627         sorting.AppendL( iCurrentSortCriteria );
       
   628         if ( iCurrentSortCriteria.iField != EFSMailSortByDate )
       
   629             {
       
   630             // Add date+descending as secondary sort criteria if primary field is something else than date
       
   631             TFSMailSortCriteria secondarySortCriteria;
       
   632             secondarySortCriteria.iField = EFSMailSortByDate;
       
   633             secondarySortCriteria.iOrder = EFSMailDescending;
       
   634             sorting.AppendL( secondarySortCriteria );
       
   635             }
       
   636         // List all or maximum number of messages
       
   637         iMailListModelUpdater->UpdateModelL(*this, iMailFolder->ListMessagesL(details, sorting));
       
   638         }
       
   639     else
       
   640         {
       
   641         UpdateCompleteL();
       
   642         }
       
   643     }
       
   644 
       
   645 // ---------------------------------------------------------------------------
   378 //
   646 //
   379 //
   647 //
   380 // ---------------------------------------------------------------------------
   648 // ---------------------------------------------------------------------------
   381 //
   649 //
   382 void CFSEmailUiMailListVisualiser::UpdateMailListModelL()
   650 void CFSEmailUiMailListVisualiser::UpdateMailListModelL()
   383     {
   651     {
   384     FUNC_LOG;
   652     FUNC_LOG;
       
   653     // Make sure asynchronous update is not going on
       
   654     iMailListModelUpdater->Cancel();
   385     // Reset model with each update
   655     // Reset model with each update
   386 	iModel->Reset();
   656 	iModel->Reset();
   387 
       
   388 	if ( iMailFolder )
   657 	if ( iMailFolder )
   389 		{
   658 		{
   390 		// Update folder if provided, otherwise use current folder
   659 		// Update folder if provided, otherwise use current folder
   391 		RPointerArray<CFSMailMessage> folderMessages( KCMsgBlock );
   660 		RPointerArray<CFSMailMessage> folderMessages( KCMsgBlock );
   392 		CleanupClosePushL( folderMessages );
   661 		CleanupClosePushL( folderMessages );
   444 //
   713 //
   445 void CFSEmailUiMailListVisualiser::CreateModelItemsL( RPointerArray<CFSMailMessage>& aMessages )
   714 void CFSEmailUiMailListVisualiser::CreateModelItemsL( RPointerArray<CFSMailMessage>& aMessages )
   446 	{
   715 	{
   447     FUNC_LOG;
   716     FUNC_LOG;
   448 	// New Items
   717 	// New Items
   449 	CFSEmailUiMailListModelItem* newItem = NULL;
   718 	CFSEmailUiMailListModelItem* newItem(NULL);
   450 
   719 
   451 	// Draw first separator if there are messages.
   720 	// Draw first separator if there are messages.
   452 	if ( aMessages.Count() && iNodesInUse == EListControlSeparatorEnabled )
   721 	if ( aMessages.Count() && iNodesInUse == EListControlSeparatorEnabled )
   453 		{
   722 		{
       
   723 		if (iModel->Count())
       
   724 		    {
       
   725 		    CFSMailMessage* nextMessage = aMessages[0];
       
   726 		    CFSEmailUiMailListModelItem* previousMessage(static_cast<CFSEmailUiMailListModelItem*>(iModel->Item(iModel->Count() - 1)));
       
   727             TBool needANewDivider =
       
   728                 !MessagesBelongUnderSameSeparatorL( previousMessage->MessagePtr(), *nextMessage );
       
   729             if ( needANewDivider )
       
   730                 {
       
   731                 newItem = CreateSeparatorModelItemLC( *nextMessage );
       
   732                 iModel->AppendL( newItem );
       
   733                 CleanupStack::Pop( newItem );
       
   734                 }
       
   735             }
       
   736 		else
       
   737 		    {
   454 	    newItem = CreateSeparatorModelItemLC( *aMessages[0] );
   738 	    newItem = CreateSeparatorModelItemLC( *aMessages[0] );
   455 	    iModel->AppendL( newItem );
   739 	    iModel->AppendL( newItem );
   456 		CleanupStack::Pop( newItem );
   740 		CleanupStack::Pop( newItem );
       
   741 		}
   457 		}
   742 		}
   458 
   743 
   459 	// Start appending items
   744 	// Start appending items
   460     for (int i = 0; i < aMessages.Count(); i++)
   745     for (int i = 0; i < aMessages.Count(); i++)
   461 	    {
   746 	    {
   949     // Make sure that pending popup is not displayd
  1234     // Make sure that pending popup is not displayd
   950 	if ( iAppUi.FolderList().IsPopupShown() )
  1235 	if ( iAppUi.FolderList().IsPopupShown() )
   951         {
  1236         {
   952         iAppUi.FolderList().HidePopupL();
  1237         iAppUi.FolderList().HidePopupL();
   953         }
  1238         }
       
  1239     DisableMailList( EFalse );
   954 
  1240 
   955 	// inform baseView if view entered with forward navigation
  1241 	// inform baseView if view entered with forward navigation
   956 	TBool forwardNavigation = EFalse;
  1242 	TBool forwardNavigation = EFalse;
   957 	if ( aCustomMessageId != KStartListReturnToPreviousFolder &&
  1243 	if ( aCustomMessageId != KStartListReturnToPreviousFolder &&
   958 	     aCustomMessageId != TUid::Uid(KMailSettingsReturnFromPluginSettings) )
  1244 	     aCustomMessageId != TUid::Uid(KMailSettingsReturnFromPluginSettings) )
  1114     // NOW WE HAVE A VALID MAILBOX AND FOLDER ID.
  1400     // NOW WE HAVE A VALID MAILBOX AND FOLDER ID.
  1115 
  1401 
  1116     // CHECK IF MODEL NEEDS TO BE UPDATED
  1402     // CHECK IF MODEL NEEDS TO BE UPDATED
  1117     if ( activationData.iMailBoxId != prevMailBoxId ||
  1403     if ( activationData.iMailBoxId != prevMailBoxId ||
  1118          activationData.iFolderId != prevFolderId ||
  1404          activationData.iFolderId != prevFolderId ||
  1119          activationData.iRequestRefresh )
  1405          activationData.iRequestRefresh ||
       
  1406          iForceRefresh )
  1120          {
  1407          {
       
  1408          iForceRefresh = EFalse;
  1121          // Set initial sort criteria when folder is changed
  1409          // Set initial sort criteria when folder is changed
  1122          iCurrentSortCriteria.iField = EFSMailSortByDate;
  1410          iCurrentSortCriteria.iField = EFSMailSortByDate;
  1123          iCurrentSortCriteria.iOrder = EFSMailDescending;
  1411          iCurrentSortCriteria.iOrder = EFSMailDescending;
  1124          SetSortButtonTextAndIconL();
  1412          SetSortButtonTextAndIconL();
  1125 
  1413 
  1126          delete iMailFolder;
  1414          SafeDelete(iMailFolder);
  1127          iMailFolder = NULL;
       
  1128          TRAP_IGNORE( iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL(
  1415          TRAP_IGNORE( iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL(
  1129                  activationData.iMailBoxId, activationData.iFolderId ) );
  1416                  activationData.iMailBoxId, activationData.iFolderId ) );
  1130          if ( !iMailFolder )
  1417          if ( !iMailFolder )
  1131              {
  1418              {
       
  1419              if ( forwardNavigation )
       
  1420                  {
       
  1421                  iAppUi.StartMonitoringL();
       
  1422                  }
  1132              // Safety, try to revert back to standard folder inbox
  1423              // Safety, try to revert back to standard folder inbox
  1133              TFSMailMsgId inboxId = iAppUi.GetActiveMailbox()->GetStandardFolderId( EFSInbox );
  1424              TFSMailMsgId inboxId = iAppUi.GetActiveMailbox()->GetStandardFolderId( EFSInbox );
  1134              iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( activationData.iMailBoxId, inboxId );
  1425              iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( activationData.iMailBoxId, inboxId );
  1135              }
  1426              }
  1136          HBufC* newFolderName = CreateFolderNameLC( iMailFolder );
  1427          HBufC* newFolderName = CreateFolderNameLC( iMailFolder );
  1148     SetBrandedMailBoxIconL();
  1439     SetBrandedMailBoxIconL();
  1149 
  1440 
  1150     // Check sync icon timer and sync status
  1441     // Check sync icon timer and sync status
  1151     ConnectionIconHandling();
  1442     ConnectionIconHandling();
  1152 
  1443 
  1153     iMailList->HideListL();
       
  1154     iMailList->ShowListL();
       
  1155 
       
  1156     // REBUILD TREE LIST IF NECESSARY
  1444     // REBUILD TREE LIST IF NECESSARY
  1157     if ( refreshNeeded )
  1445     if ( refreshNeeded )
  1158         {
  1446         {
  1159         // Try to maintain previously active item if possible.
  1447         // Try to maintain previously active item if possible.
  1160         // This is of course not possible if folder has changed.
  1448         // This is of course not possible if folder has changed.
  1161         TFSMailMsgId focused = MsgIdFromListId( iMailList->FocusedItem() );
  1449         TFSMailMsgId focused = MsgIdFromListId( iMailList->FocusedItem() );
  1162 
  1450 
  1163         // Clear any previous items from the screen and then make the view visible
  1451         // Clear any previous items from the screen and then make the view visible
       
  1452         iMailList->BeginUpdate();
  1164         iMailList->RemoveAllL();
  1453         iMailList->RemoveAllL();
  1165         iTreeItemArray.Reset();
  1454         iTreeItemArray.Reset();
  1166         UpdateMailListModelL();
  1455         iModel->Reset();
  1167         RefreshDeferred( &focused );
  1456         iMailList->EndUpdateL();
  1168         }
  1457         iMailList->ShowListL();
  1169 
  1458 
       
  1459         // If coming from wizard use synchronous list updating
       
  1460         if (activationData.iReturnAfterWizard)
       
  1461             {
       
  1462             UpdateMailListModelL();
       
  1463             }
       
  1464         else
       
  1465             {
       
  1466             UpdateMailListModelAsyncL();
       
  1467             }
       
  1468         }
  1170     // THE CORRECT FOLDER IS ALREADY OPEN. CHECK IF SOME PARTIAL UPDATE IS NEEDED.
  1469     // THE CORRECT FOLDER IS ALREADY OPEN. CHECK IF SOME PARTIAL UPDATE IS NEEDED.
  1171     else
  1470     else
  1172         {
  1471         {
  1173         // hide & show list to force it to adept to changed screen size
  1472         iMailList->ShowListL();
       
  1473         if (forwardNavigation)
       
  1474             {
       
  1475             iAppUi.StartMonitoringL();
       
  1476             }
  1174         SetListAndCtrlBarFocusL(); // ShowListL() makes list focused and this may need to be reverted
  1477         SetListAndCtrlBarFocusL(); // ShowListL() makes list focused and this may need to be reverted
  1175         UnmarkAllItemsL();
  1478         UnmarkAllItemsL();
  1176 
       
  1177         if ( aCustomMessageId == TUid::Uid(KMailSettingsReturnFromPluginSettings) )
  1479         if ( aCustomMessageId == TUid::Uid(KMailSettingsReturnFromPluginSettings) )
  1178             {
  1480             {
  1179             // Better to refresh launcher grid view because mailbox branding might be changed.
  1481             // Better to refresh launcher grid view because mailbox branding might be changed.
  1180             iAppUi.LauncherGrid().SetRefreshNeeded();
  1482             iAppUi.LauncherGrid().SetRefreshNeeded();
  1181             }
  1483             }
  1182 
       
  1183         // Check the validity of focused message, it may be deleted or
  1484         // Check the validity of focused message, it may be deleted or
  1184         // reply/forward, read/unread status might have changed in editor or viewer
  1485         // reply/forward, read/unread status might have changed in editor or viewer
  1185         UpdateItemAtIndexL( HighlightedIndex() );
  1486         UpdateItemAtIndexL( HighlightedIndex() );
  1186         SetMskL();
  1487         SetMskL();
  1187         }
  1488         }
  1238 //
  1539 //
  1239 // ---------------------------------------------------------------------------
  1540 // ---------------------------------------------------------------------------
  1240 //
  1541 //
  1241 void CFSEmailUiMailListVisualiser::ChildDoDeactivate()
  1542 void CFSEmailUiMailListVisualiser::ChildDoDeactivate()
  1242 	{
  1543 	{
  1243   FUNC_LOG;
  1544     FUNC_LOG;
       
  1545     if (iMailListModelUpdater)
       
  1546         {
       
  1547         iMailListModelUpdater->Cancel();
       
  1548         }
  1244 	if ( !iAppUi.AppUiExitOngoing() )
  1549 	if ( !iAppUi.AppUiExitOngoing() )
  1245   		{
  1550   	    {
  1246   	  TRAP_IGNORE( {
  1551   	    TRAP_IGNORE( {
       
  1552             iMailList->HideListL();
  1247             iMailList->SetFocusedL( EFalse );
  1553             iMailList->SetFocusedL( EFalse );
  1248   	        } );
  1554   	        } );
  1249   	  iMailTreeListVisualizer->NotifyControlVisibilityChange( EFalse );
  1555   	    iMailTreeListVisualizer->NotifyControlVisibilityChange( EFalse );
  1250   		}
  1556   	    }
  1251 	iThisViewActive = EFalse;
  1557 	iThisViewActive = EFalse;
  1252 	}
  1558 	}
  1253 
  1559 
  1254 // ---------------------------------------------------------------------------
  1560 // ---------------------------------------------------------------------------
  1255 //
  1561 //
  1759 	// IMPLEMENTATION OF FILLING UP THE LIST
  2065 	// IMPLEMENTATION OF FILLING UP THE LIST
  1760 	TFsTreeItemId latestNodeId = KFsTreeRootID; // items will go under root node if no other nodes found in the model
  2066 	TFsTreeItemId latestNodeId = KFsTreeRootID; // items will go under root node if no other nodes found in the model
  1761     CFSEmailUiMailListModelItem* item( NULL );
  2067     CFSEmailUiMailListModelItem* item( NULL );
  1762     SetMailListItemsExtendedL();
  2068     SetMailListItemsExtendedL();
  1763 
  2069 
  1764     TBool allowRefresh(EFalse);
       
  1765     TInt count(0);
  2070     TInt count(0);
  1766     count = iModel->Count();
  2071     count = iModel->Count();
  1767     for ( TInt i=0; i < count; i++ )
  2072     for ( TInt i=0; i < count; i++ )
  1768 		{
  2073 		{
  1769 		item = static_cast<CFSEmailUiMailListModelItem*>(iModel->Item(i));
  2074 		item = static_cast<CFSEmailUiMailListModelItem*>(iModel->Item(i));
  1770 
  2075 
  1771 		if ( i == 0 || i == count - 1 )
  2076         const TBool allowRefresh(i == 0 || (i == count - 1));
  1772             {//first item - show scrollbar
       
  1773              //last item - update scrollbar
       
  1774             allowRefresh = ETrue;
       
  1775             }
       
  1776         else
       
  1777             {//rest of the messages - insert without updating
       
  1778             allowRefresh = EFalse;
       
  1779             }
       
  1780 
  2077 
  1781 		// Append separator item text into the list
  2078 		// Append separator item text into the list
  1782 		if ( item && item->ModelItemType() == ETypeSeparator )
  2079 		if ( item && item->ModelItemType() == ETypeSeparator )
  1783 			{
  2080 			{
  1784 			latestNodeId = InsertNodeItemL( i, KErrNotFound, allowRefresh );
  2081 			latestNodeId = InsertNodeItemL( i, KErrNotFound, allowRefresh );
  1789 			InsertListItemL( i, latestNodeId, KErrNotFound, allowRefresh );
  2086 			InsertListItemL( i, latestNodeId, KErrNotFound, allowRefresh );
  1790 			}
  2087 			}
  1791 		}
  2088 		}
  1792 	}
  2089 	}
  1793 
  2090 
       
  2091 // ---------------------------------------------------------------------------
       
  2092 //
       
  2093 //
       
  2094 // ---------------------------------------------------------------------------
       
  2095 //
       
  2096 void CFSEmailUiMailListVisualiser::RefreshListItemsL(TFsTreeItemId& aLatestNodeId, const TInt aStartIndex, const TInt aEndIndex)
       
  2097     {
       
  2098     FUNC_LOG;
       
  2099     // IMPLEMENTATION OF FILLING UP THE LIST
       
  2100     iMailList->BeginUpdate();
       
  2101     CFSEmailUiMailListModelItem* item( NULL );
       
  2102     if (aLatestNodeId == KFsTreeRootID && !aStartIndex)
       
  2103         {
       
  2104         iMailList->RemoveAllL();
       
  2105         iTreeItemArray.Reset();
       
  2106         SetMailListItemsExtendedL();
       
  2107         }
       
  2108     for ( TInt i = aStartIndex; i < aEndIndex; i++ )
       
  2109         {
       
  2110         item = static_cast<CFSEmailUiMailListModelItem*>(iModel->Item(i));
       
  2111         // Append separator item text into the list
       
  2112         if ( item && item->ModelItemType() == ETypeSeparator )
       
  2113             {
       
  2114             aLatestNodeId = InsertNodeItemL( i, KErrNotFound, EFalse );
       
  2115             }
       
  2116         // Append mail item into the list
       
  2117         else if ( item && item->ModelItemType() == ETypeMailItem )
       
  2118             {
       
  2119             InsertListItemL( i, aLatestNodeId, KErrNotFound, EFalse );
       
  2120             }
       
  2121         }
       
  2122     iMailList->EndUpdateL();
       
  2123     }
  1794 
  2124 
  1795 void CFSEmailUiMailListVisualiser::SetMailListItemsExtendedL()
  2125 void CFSEmailUiMailListVisualiser::SetMailListItemsExtendedL()
  1796 	{
  2126 	{
  1797     FUNC_LOG;
  2127     FUNC_LOG;
  1798 	// Set items always extended in double line preview on mode.
  2128 	// Set items always extended in double line preview on mode.
  3905         }
  4235         }
  3906 
  4236 
  3907     // MSK label can now be updated when shift key has been handled
  4237     // MSK label can now be updated when shift key has been handled
  3908     SetMskL();
  4238     SetMskL();
  3909     // On KeyUp of EStdKeyYes usually Call application is called - prevent it
  4239     // On KeyUp of EStdKeyYes usually Call application is called - prevent it
  3910     if ( iConsumeStdKeyYes_KeyUp && (aEvent.Code() == EEventKeyUp )) 
  4240     if ( iConsumeStdKeyYes_KeyUp && (aEvent.Code() == EEventKeyUp ))
  3911 		{
  4241 		{
  3912 		iConsumeStdKeyYes_KeyUp = EFalse; // in case call button was consumed elsewhere first key up enables calling Call application
  4242 		iConsumeStdKeyYes_KeyUp = EFalse; // in case call button was consumed elsewhere first key up enables calling Call application
  3913 		if ( EStdKeyYes == scanCode) 
  4243 		if ( EStdKeyYes == scanCode)
  3914 			{
  4244 			{
  3915 			  result = ETrue; // consume not to switch to Call application when call to contact was processed
  4245 			  result = ETrue; // consume not to switch to Call application when call to contact was processed
  3916 			  return result;
  4246 			  return result;
  3917 			}
  4247 			}
  3918 		}
  4248 		}
  5671 	    const TInt modelCount( iModel->Count() );
  6001 	    const TInt modelCount( iModel->Count() );
  5672     	for ( TInt i( 0 ); i < modelCount ; ++i )
  6002     	for ( TInt i( 0 ); i < modelCount ; ++i )
  5673     		{
  6003     		{
  5674     		CFSEmailUiMailListModelItem* item =
  6004     		CFSEmailUiMailListModelItem* item =
  5675                 static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( i ) );
  6005                 static_cast<CFSEmailUiMailListModelItem*>( iModel->Item( i ) );
       
  6006 			// when the item is a separator check whether its MessagePtr is valid (actually it's a reference)    		    		
       
  6007 			if( &(item->MessagePtr()) != NULL) 
       
  6008 				{
  5676     		if ( aMessageId == item->MessagePtr().GetMessageId() )
  6009     		if ( aMessageId == item->MessagePtr().GetMessageId() )
  5677     			{
  6010     			{
  5678     			TModelItemType itemType = item->ModelItemType();
  6011     			TModelItemType itemType = item->ModelItemType();
  5679     			TBool separator( aMessageId.IsSeparator() );
  6012     			TBool separator( aMessageId.IsSeparator() );
  5680 
  6013 
  5690                     break;
  6023                     break;
  5691                     }
  6024                     }
  5692     			}
  6025     			}
  5693     		}
  6026     		}
  5694         }
  6027         }
       
  6028 		}
  5695 	return idx;
  6029 	return idx;
  5696     }
  6030     }
  5697 
  6031 
  5698 // ---------------------------------------------------------------------------
  6032 // ---------------------------------------------------------------------------
  5699 // NextMessageIndex
  6033 // NextMessageIndex
  5842 				break;
  6176 				break;
  5843 			}
  6177 			}
  5844 
  6178 
  5845 		if ( !iMailFolder || ( iMailFolder && iMailFolder->GetFolderId() != aSelectedFolderId ) )
  6179 		if ( !iMailFolder || ( iMailFolder && iMailFolder->GetFolderId() != aSelectedFolderId ) )
  5846 		    {
  6180 		    {
  5847             delete iMailFolder;
  6181 		    iMailListModelUpdater->Cancel();
  5848             iMailFolder = NULL;
  6182 		    SafeDelete(iMailFolder);
  5849             iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( iAppUi.GetActiveMailboxId(), aSelectedFolderId );
  6183             iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( iAppUi.GetActiveMailboxId(), aSelectedFolderId );
  5850 
  6184 
  5851             if ( !iMailFolder )
  6185             if ( !iMailFolder )
  5852                 {
  6186                 {
  5853                 // Do nothing if can't get the folder object
  6187                 // Do nothing if can't get the folder object
  5887     FUNC_LOG;
  6221     FUNC_LOG;
  5888     iControlBarControl->MakeSelectorVisible( IsFocusShown() );
  6222     iControlBarControl->MakeSelectorVisible( IsFocusShown() );
  5889     //Set touchmanager back to active
  6223     //Set touchmanager back to active
  5890     DisableMailList(EFalse);
  6224     DisableMailList(EFalse);
  5891 	iAppUi.SetActiveMailboxL( aSelectedMailboxId );
  6225 	iAppUi.SetActiveMailboxL( aSelectedMailboxId );
  5892 	delete iMailFolder;
  6226 	iMailListModelUpdater->Cancel();
  5893 	iMailFolder = NULL;
  6227 	SafeDelete(iMailFolder);
  5894 	iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( iAppUi.GetActiveMailboxId(), iAppUi.GetActiveBoxInboxId() );
  6228 	iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( iAppUi.GetActiveMailboxId(), iAppUi.GetActiveBoxInboxId() );
  5895 
  6229 
  5896 	// Set initial sort criteria when folder has changed
  6230 	// Set initial sort criteria when folder has changed
  5897     iCurrentSortCriteria.iField = EFSMailSortByDate;
  6231     iCurrentSortCriteria.iField = EFSMailSortByDate;
  5898     iCurrentSortCriteria.iOrder = EFSMailDescending;
  6232     iCurrentSortCriteria.iOrder = EFSMailDescending;
  6303 	}
  6637 	}
  6304 
  6638 
  6305 void CFSEmailUiMailListVisualiser::ReplyL( CFSMailMessage* aMsgPtr )
  6639 void CFSEmailUiMailListVisualiser::ReplyL( CFSMailMessage* aMsgPtr )
  6306 	{
  6640 	{
  6307     FUNC_LOG;
  6641     FUNC_LOG;
  6308     DoReplyForwardL( KEditorCmdReply, aMsgPtr );
  6642     // Replying not possible from drafts folder
       
  6643     if ( iMailFolder && iMailFolder->GetFolderType() != EFSDraftsFolder )
       
  6644         {
       
  6645         DoReplyForwardL( KEditorCmdReply, aMsgPtr );
       
  6646         }
  6309 	}
  6647 	}
  6310 
  6648 
  6311 void CFSEmailUiMailListVisualiser::ReplyAllL(  CFSMailMessage* aMsgPtr )
  6649 void CFSEmailUiMailListVisualiser::ReplyAllL(  CFSMailMessage* aMsgPtr )
  6312 	{
  6650 	{
  6313     FUNC_LOG;
  6651     FUNC_LOG;
  6314 	DoReplyForwardL( KEditorCmdReplyAll, aMsgPtr );
  6652     // Replying all not possible from drafts folder
       
  6653     if ( iMailFolder && iMailFolder->GetFolderType() != EFSDraftsFolder )
       
  6654         {
       
  6655         DoReplyForwardL( KEditorCmdReplyAll, aMsgPtr );
       
  6656         }
  6315 	}
  6657 	}
  6316 
  6658 
  6317 void CFSEmailUiMailListVisualiser::ForwardL( CFSMailMessage* aMsgPtr )
  6659 void CFSEmailUiMailListVisualiser::ForwardL( CFSMailMessage* aMsgPtr )
  6318 	{
  6660 	{
  6319     FUNC_LOG;
  6661     FUNC_LOG;
  6391 					{
  6733 					{
  6392 					TFSMailMsgId entryId = (*removedEntries)[i];
  6734 					TFSMailMsgId entryId = (*removedEntries)[i];
  6393 					if ( entryId == currentFolderId )
  6735 					if ( entryId == currentFolderId )
  6394 						{
  6736 						{
  6395 						// Current folder deleted, try to revert back to standard folder inbox.
  6737 						// Current folder deleted, try to revert back to standard folder inbox.
  6396 						delete iMailFolder;
  6738 						iMailListModelUpdater->Cancel();
  6397 						iMailFolder = NULL;
  6739 						SafeDelete(iMailFolder);
  6398 						TFSMailMsgId inboxId = iAppUi.GetActiveMailbox()->GetStandardFolderId( EFSInbox );
  6740 						TFSMailMsgId inboxId = iAppUi.GetActiveMailbox()->GetStandardFolderId( EFSInbox );
  6399 						if ( !inboxId.IsNullId() )
  6741 						if ( !inboxId.IsNullId() )
  6400 						    {
  6742 						    {
  6401 						    iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, inboxId );
  6743 						    iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, inboxId );
  6402 						    UpdateMailListModelL();
  6744 						    UpdateMailListModelL();
  6431 				TFSMailMsgId* parentFolderId = static_cast<TFSMailMsgId*>( aParam2 );
  6773 				TFSMailMsgId* parentFolderId = static_cast<TFSMailMsgId*>( aParam2 );
  6432 				TFSMailMsgId currentFolderId = iMailFolder->GetFolderId();
  6774 				TFSMailMsgId currentFolderId = iMailFolder->GetFolderId();
  6433 				if ( parentFolderId && ( *parentFolderId == currentFolderId ) )
  6775 				if ( parentFolderId && ( *parentFolderId == currentFolderId ) )
  6434 					{
  6776 					{
  6435 	 				// Refresh mailfolder to get correct actual data
  6777 	 				// Refresh mailfolder to get correct actual data
  6436                     delete iMailFolder;
  6778                     /*
  6437                     iMailFolder = NULL;
  6779                     iMailListModelUpdater->Cancel();
       
  6780 					SafeDelete(iMailFolder);
  6438 					iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, currentFolderId );
  6781 					iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, currentFolderId );
       
  6782 					*/
  6439 					RemoveMsgItemsFromListIfFoundL( *removedEntries );
  6783 					RemoveMsgItemsFromListIfFoundL( *removedEntries );
  6440 					}
  6784 					}
  6441 				}
  6785 				}
  6442 			}
  6786 			}
  6443 		else if ( aEvent == TFSEventNewMail )
  6787 		else if ( aEvent == TFSEventNewMail )
  6445 			// Switch to standardfolder inbox if we have null folderid.
  6789 			// Switch to standardfolder inbox if we have null folderid.
  6446 			// This is usually the case with first time sync.
  6790 			// This is usually the case with first time sync.
  6447 			if ( FolderId().IsNullId() )
  6791 			if ( FolderId().IsNullId() )
  6448 				{
  6792 				{
  6449 				// Refresh mailfolder to standard folder inbox in case of zero id
  6793 				// Refresh mailfolder to standard folder inbox in case of zero id
  6450 				delete iMailFolder;
  6794                 iMailListModelUpdater->Cancel();
  6451 				iMailFolder = NULL;
  6795 				SafeDelete(iMailFolder);
  6452 				TFSMailMsgId inboxId = iAppUi.GetActiveMailbox()->GetStandardFolderId( EFSInbox );
  6796 				TFSMailMsgId inboxId = iAppUi.GetActiveMailbox()->GetStandardFolderId( EFSInbox );
  6453 				if ( !inboxId.IsNullId() )
  6797 				if ( !inboxId.IsNullId() )
  6454 				    {
  6798 				    {
  6455 				    iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, inboxId );
  6799 				    iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, inboxId );
  6456 				    // Check that mailfolder fetching succeeded
  6800 				    // Check that mailfolder fetching succeeded
  6491                 InsertNewMessagesL( *entries );
  6835                 InsertNewMessagesL( *entries );
  6492                 }
  6836                 }
  6493             else if ( fromFolderId && ( currentFolderId == *fromFolderId ) )
  6837             else if ( fromFolderId && ( currentFolderId == *fromFolderId ) )
  6494                 {
  6838                 {
  6495  	 			// Refresh mailfolder to get correct actual data
  6839  	 			// Refresh mailfolder to get correct actual data
  6496 				delete iMailFolder;
  6840                 /*
  6497 				iMailFolder = NULL;
  6841                 iMailListModelUpdater->Cancel();
       
  6842                 SafeDelete(iMailFolder);
  6498 				iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, currentFolderId );
  6843 				iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, currentFolderId );
       
  6844 				*/
  6499 				RemoveMsgItemsFromListIfFoundL( *entries );
  6845 				RemoveMsgItemsFromListIfFoundL( *entries );
  6500                 }
  6846                 }
  6501             else
  6847             else
  6502                 {
  6848                 {
  6503                 // event is not related to the current folder => do nothing
  6849                 // event is not related to the current folder => do nothing
  6510 			TFSMailMsgId* parentFolderId = static_cast<TFSMailMsgId*>( aParam2 );
  6856 			TFSMailMsgId* parentFolderId = static_cast<TFSMailMsgId*>( aParam2 );
  6511 			TFSMailMsgId currentFolderId = iMailFolder->GetFolderId();
  6857 			TFSMailMsgId currentFolderId = iMailFolder->GetFolderId();
  6512 			if ( *parentFolderId == currentFolderId )
  6858 			if ( *parentFolderId == currentFolderId )
  6513 				{
  6859 				{
  6514  	 			// Refresh mailfolder to get correct actual data
  6860  	 			// Refresh mailfolder to get correct actual data
  6515 				delete iMailFolder;
  6861 				/*
  6516 				iMailFolder = NULL;
  6862                 iMailListModelUpdater->Cancel();
       
  6863                 SafeDelete(iMailFolder);
  6517 				iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, currentFolderId );
  6864 				iMailFolder = iAppUi.GetMailClient()->GetFolderByUidL( aMailboxId, currentFolderId );
       
  6865 				*/
  6518 				for ( TInt i=0 ; i<entries->Count() ; i++ )
  6866 				for ( TInt i=0 ; i<entries->Count() ; i++ )
  6519 					{
  6867 					{
  6520 					TFSMailMsgId msgId = (*entries)[i];
  6868 					TFSMailMsgId msgId = (*entries)[i];
  6521 					TInt idx = ItemIndexFromMessageId( msgId );
  6869 					TInt idx = ItemIndexFromMessageId( msgId );
  6522 					if ( idx >= 0 )
  6870 					if ( idx != KErrNotFound )
  6523 					    {
  6871 					    {
  6524 					    UpdateItemAtIndexL( idx );
  6872 					    UpdateItemAtIndexL( idx );
  6525 					    }
  6873 					    }
  6526 					}
  6874 					}
  6527 				}
  6875 				}
  7266 CDateChangeTimer::CDateChangeTimer( CFSEmailUiMailListVisualiser& aMailListVisualiser )
  7614 CDateChangeTimer::CDateChangeTimer( CFSEmailUiMailListVisualiser& aMailListVisualiser )
  7267     : CTimer( EPriorityStandard ), iMailListVisualiser( aMailListVisualiser )
  7615     : CTimer( EPriorityStandard ), iMailListVisualiser( aMailListVisualiser )
  7268     {
  7616     {
  7269     FUNC_LOG;
  7617     FUNC_LOG;
  7270     CActiveScheduler::Add( this );
  7618     CActiveScheduler::Add( this );
       
  7619     iDayCount = DayCount();
  7271     }
  7620     }
  7272 
  7621 
  7273 // -----------------------------------------------------------------------------
  7622 // -----------------------------------------------------------------------------
  7274 // CMsgMovedNoteTimer::~CDateChangeTimer
  7623 // CMsgMovedNoteTimer::~CDateChangeTimer
  7275 // Destructor
  7624 // Destructor
  7313 // -----------------------------------------------------------------------------
  7662 // -----------------------------------------------------------------------------
  7314 //
  7663 //
  7315 void CDateChangeTimer::RunL()
  7664 void CDateChangeTimer::RunL()
  7316     {
  7665     {
  7317     FUNC_LOG;
  7666     FUNC_LOG;
       
  7667     
       
  7668     if (iStatus.Int() != KErrNone)
       
  7669         {
       
  7670         	INFO_1("### CDateChangeTimer::RunL (err=%d) ###", iStatus.Int());
       
  7671         }
       
  7672 
       
  7673     
       
  7674     TBool dayChanged = EFalse;
       
  7675     TInt dayCount = DayCount();
       
  7676     if (dayCount != iDayCount)
       
  7677         {
       
  7678   
       
  7679         iDayCount = dayCount;
       
  7680         dayChanged = ETrue;
       
  7681         }
       
  7682 
       
  7683     
  7318     if ( KErrCancel == iStatus.Int() )
  7684     if ( KErrCancel == iStatus.Int() )
  7319         {
  7685         {
  7320         ;
  7686         ;
  7321         }
  7687         }   
  7322     // System time changed?
  7688     else if ( KErrAbort == iStatus.Int() ) // System time changed
  7323     else if ( KErrAbort == iStatus.Int() )
  7689         {
  7324         {
  7690         if (dayChanged)
       
  7691             {
       
  7692             TRAP_IGNORE( iMailListVisualiser.NotifyDateChangedL() );
       
  7693             }
  7325         Start();
  7694         Start();
  7326         }
  7695         }
  7327     // Interval is over
  7696     else  // interval is over
  7328     else
       
  7329         {
  7697         {
  7330         // Update mail list and reissue the request for timer event
  7698         // Update mail list and reissue the request for timer event
  7331         TRAP_IGNORE( iMailListVisualiser.NotifyDateChangedL() );
  7699         TRAP_IGNORE( iMailListVisualiser.NotifyDateChangedL() );
  7332         Start();
  7700         Start();
  7333         }
  7701         }
  7334     }
  7702     
       
  7703     }
       
  7704 
       
  7705 
       
  7706 TInt CDateChangeTimer::DayCount()
       
  7707     {
       
  7708     TTime now;
       
  7709     now.HomeTime();
       
  7710     TTime minTime = Time::MinTTime();
       
  7711     TTimeIntervalDays days = now.DaysFrom(minTime);
       
  7712     return days.Int();
       
  7713     }
       
  7714 
       
  7715 
       
  7716 
       
  7717 
       
  7718 
       
  7719 
       
  7720 
       
  7721