emailuis/emailui/src/FreestyleEmailDownloadInformationMediator.cpp
changeset 2 5253a20d2a1e
parent 1 12c456ceeff2
child 3 a4d6f1ea0416
equal deleted inserted replaced
1:12c456ceeff2 2:5253a20d2a1e
    42 // Default class constructor.
    42 // Default class constructor.
    43 // ----------------------------------------------------
    43 // ----------------------------------------------------
    44 //
    44 //
    45 CFSEmailDownloadInfoMediator::CFSEmailDownloadInfoMediator( CFSMailClient& aMailClient )
    45 CFSEmailDownloadInfoMediator::CFSEmailDownloadInfoMediator( CFSMailClient& aMailClient )
    46     : CActive( EPriorityNormal ), iMailClient(aMailClient),
    46     : CActive( EPriorityNormal ), iMailClient(aMailClient),
    47     iDownloadArray( KArrayGranularity, _FOFF(TDownload, iRequestId) ), iDownloadsStarted ( EFalse )
    47     iDownloadArray( KArrayGranularity, _FOFF(TDownload, iRequestId) ), iDownloadsStarted ( EFalse ),
       
    48     iNotificationsInProgress( 0 ), iObserverDeleted( EFalse )
    48 	{
    49 	{
    49     FUNC_LOG;
    50     FUNC_LOG;
    50 	CActiveScheduler::Add( this );
    51 	CActiveScheduler::Add( this );
    51 	}
    52 	}
    52 
    53 
   381     }
   382     }
   382 
   383 
   383 void CFSEmailDownloadInfoMediator::StopObserving( MFSEmailDownloadInformationObserver* aObserver, TFSMailMsgId aMessageId )
   384 void CFSEmailDownloadInfoMediator::StopObserving( MFSEmailDownloadInformationObserver* aObserver, TFSMailMsgId aMessageId )
   384 	{
   385 	{
   385 	FUNC_LOG;
   386 	FUNC_LOG;
   386     for (TInt i=0; i<iObserverArray.Count(); i++)
   387     for (TInt i=iObserverArray.Count()-1; i>=0; i--)
   387     	{
   388     	{
   388    		if ( iObserverArray[i].iObserver == aObserver && iObserverArray[i].iMessageId == aMessageId )
   389    		if ( iObserverArray[i].iObserver == aObserver && iObserverArray[i].iMessageId == aMessageId )
   389    			{
   390    			{
   390    			iObserverArray.Remove(i);
   391             RemoveObserver(i);
   391    			}
   392    			}
   392     	}
   393     	}
   393 	}
   394 	}
   394 
   395 
   395 void CFSEmailDownloadInfoMediator::StopObserving( MFSEmailDownloadInformationObserver* aObserver )
   396 void CFSEmailDownloadInfoMediator::StopObserving( MFSEmailDownloadInformationObserver* aObserver )
   396 	{
   397 	{
   397 	FUNC_LOG;
   398 	FUNC_LOG;
   398     for (TInt i=0; i<iObserverArray.Count(); i++)
   399     for ( TInt i=iObserverArray.Count()-1; i>=0; i-- )
   399     	{
   400     	{
   400    		if ( iObserverArray[i].iObserver == aObserver )
   401    		if ( iObserverArray[i].iObserver == aObserver )
   401    			{
   402    			{
   402    			iObserverArray.Remove(i);
   403    			RemoveObserver(i);
   403    			}
   404    			}
   404     	}
   405     	}
   405     for (TInt i=0; i<iAllObserverArray.Count(); i++)
   406     for ( TInt i=iAllObserverArray.Count()-1; i>=0; i-- )
   406     	{
   407     	{
   407 		if ( iAllObserverArray[i] == aObserver )
   408 		if ( iAllObserverArray[i] == aObserver )
   408    			{
   409    			{
   409    			iAllObserverArray.Remove(i);
   410    			iAllObserverArray.Remove(i);
   410    			}
   411    			}
   411     	}
   412     	}
   412 	}
   413 	}
       
   414 
       
   415 void CFSEmailDownloadInfoMediator::RemoveObserver( TInt aIdx )
       
   416     {
       
   417     if ( iNotificationsInProgress == 0 )
       
   418         {
       
   419         // If we're not currently iterating over the array, remove the entry
       
   420         // immediately.
       
   421         iObserverArray.Remove( aIdx );
       
   422         }
       
   423     else
       
   424         {
       
   425         // We're currently iterating over the array: mark the entry as
       
   426         // deleted and flag that we've done so.
       
   427         iObserverArray[aIdx].iDeleted = ETrue;
       
   428         iObserverDeleted = ETrue;
       
   429         }
       
   430     }
   413 
   431 
   414 void CFSEmailDownloadInfoMediator::DownloadL( TPartData aPart, TBool aCompleteNote )
   432 void CFSEmailDownloadInfoMediator::DownloadL( TPartData aPart, TBool aCompleteNote )
   415 	{
   433 	{
   416 	FUNC_LOG;
   434 	FUNC_LOG;
   417 	TFileName emptyFileName;
   435 	TFileName emptyFileName;
   723 
   741 
   724 	CleanupStack::PopAndDestroy( popupText );
   742 	CleanupStack::PopAndDestroy( popupText );
   725 		
   743 		
   726 	SetActive();
   744 	SetActive();
   727     }
   745     }
   728 	
   746 
   729 void CFSEmailDownloadInfoMediator::NotifyObserversL( const TFSProgress& aEvent, const TPartData& aPart )
   747 void CFSEmailDownloadInfoMediator::NotifyObserversL( const TFSProgress& aEvent, const TPartData& aPart )
   730     {
   748     {
   731 	FUNC_LOG;
   749 	FUNC_LOG;
       
   750 
       
   751 	// notify observers of this particular message part
       
   752     iNotificationsInProgress++;
       
   753     TRAPD( error, NotifyPartObserversL( aEvent, aPart ) );
       
   754     if ( --iNotificationsInProgress == 0 )
       
   755         {
       
   756         CleanUpObservers();
       
   757         }
       
   758     if ( error )
       
   759         {
       
   760         User::Leave( error );
       
   761         }
       
   762 
       
   763     // send response to every 'all observer'
       
   764     for ( TInt i=iAllObserverArray.Count()-1; i>=0; i-- )
       
   765         {
       
   766         iAllObserverArray[i]->RequestResponseL( aEvent, aPart );
       
   767         }
       
   768     }
       
   769 
       
   770 void CFSEmailDownloadInfoMediator::NotifyPartObserversL( const TFSProgress& aEvent, const TPartData& aPart )
       
   771     {
       
   772 	FUNC_LOG;
   732 	// go through all observers
   773 	// go through all observers
   733     for ( TInt j=iObserverArray.Count()-1; j>=0; j--)
   774     for ( TInt j=iObserverArray.Count()-1; j>=0; j-- )
   734 		{
   775 		{
   735 		// if observer is observing this message
   776 		// if observer is observing this message
   736 		if ( iObserverArray[j].iMessageId == aPart.iMessageId )
   777 		if ( !iObserverArray[j].iDeleted && iObserverArray[j].iMessageId == aPart.iMessageId )
   737 			{
   778 			{
   738 			// send response to observer
   779 			// send response to observer
   739 			iObserverArray[j].iObserver->RequestResponseL( aEvent, aPart );
   780 			iObserverArray[j].iObserver->RequestResponseL( aEvent, aPart );
   740 			}
   781 			}
   741 		}
   782 		}
   742 	// send response to every 'all observer'
   783     }
   743 	for (TInt i=0; i<iAllObserverArray.Count(); i++)
   784 
   744 		{
   785 void CFSEmailDownloadInfoMediator::CleanUpObservers()
   745 		iAllObserverArray[i]->RequestResponseL( aEvent, aPart );
   786     {
   746 		}
   787     FUNC_LOG;
       
   788     // If one or more observers have been marked for deletion, go through
       
   789     // the observer array and remove them.
       
   790     if ( iObserverDeleted )
       
   791         {
       
   792         for ( TInt j=iObserverArray.Count()-1; j>=0; j-- )
       
   793             {
       
   794             if ( iObserverArray[j].iDeleted )
       
   795                 {
       
   796                 iObserverArray.Remove(j);
       
   797                 }
       
   798             }
       
   799         iObserverDeleted = EFalse;
       
   800         }
   747     }
   801     }
   748 
   802 
   749 void CFSEmailDownloadInfoMediator::RunL()
   803 void CFSEmailDownloadInfoMediator::RunL()
   750 	{
   804 	{
   751 	FUNC_LOG;
   805 	FUNC_LOG;