emailuis/emailui/src/FreestyleEmailUiAttachmentsListModel.cpp
changeset 0 8466d47a6819
child 3 a4d6f1ea0416
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implements model for the attachment list view
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDEfS
       
    20 //<cmail>
       
    21 #include "emailtrace.h"
       
    22 #include "CFSMailClient.h"
       
    23 //</cmail>
       
    24 #include <StringLoader.h>
       
    25 #include <FreestyleEmailUi.rsg>
       
    26 
       
    27 // INTERNAL INCLUDES
       
    28 #include "FreestyleEmailUiAppui.h"
       
    29 #include "FreestyleEmailUiAttachmentsListModel.h"
       
    30 #include "FreestyleEmailUiUtilities.h"
       
    31 
       
    32 
       
    33 ////////////////////////////////////
       
    34 // CFSEmailUiAttachmentsModelBase //
       
    35 ////////////////////////////////////
       
    36 CFSEmailUiAttachmentsModelBase::CFSEmailUiAttachmentsModelBase( CFreestyleEmailUiAppUi& aAppUi )
       
    37     : iAppUi( aAppUi )
       
    38     {
       
    39     FUNC_LOG;
       
    40     
       
    41     }
       
    42     
       
    43 void CFSEmailUiAttachmentsModelBase::ConstructL()
       
    44     {
       
    45     FUNC_LOG;
       
    46     }
       
    47 
       
    48 CFSEmailUiAttachmentsModelBase::~CFSEmailUiAttachmentsModelBase()
       
    49     {
       
    50     FUNC_LOG;
       
    51     // iDownloadInfoMediator is singleton and destroyed by AppUi
       
    52     }
       
    53 
       
    54 TBool CFSEmailUiAttachmentsModelBase::StartDownloadL( TFsTreeItemId aTreeId )
       
    55 	{
       
    56 	TAttachmentData& item = GetItemL( aTreeId );
       
    57 	return StartDownloadL( item );
       
    58 	}
       
    59 
       
    60 TBool CFSEmailUiAttachmentsModelBase::StartDownloadL( const TAttachmentData& aAttachment )
       
    61     {
       
    62     FUNC_LOG;
       
    63     TBool retVal = EFalse;
       
    64     if ( iAppUi.DownloadInfoMediator() && iAppUi.DownloadInfoMediator()->IsDownloadableL( aAttachment.partData ) )
       
    65         {
       
    66         iAppUi.DownloadInfoMediator()->DownloadL( aAttachment.partData );
       
    67         retVal = ETrue;
       
    68         }
       
    69     return retVal;
       
    70     }
       
    71 
       
    72 TBool CFSEmailUiAttachmentsModelBase::SaveAttachmentL(
       
    73 	TFsTreeItemId aTreeId, const TDesC& aFileName, TInt& aSavedCount )
       
    74 	{
       
    75     FUNC_LOG;
       
    76 	TBool retVal = EFalse;
       
    77 	TAttachmentData* attData = GetItem( aTreeId );
       
    78 	if ( attData )
       
    79 	    {
       
    80 	    retVal = SaveAttachmentL( *attData, aFileName, aSavedCount );
       
    81 		}
       
    82 	return retVal;
       
    83 	}
       
    84 
       
    85 TBool CFSEmailUiAttachmentsModelBase::SaveAttachmentL(
       
    86         const TAttachmentData& aAttachment, const TDesC& aFileName, TInt& aSavedCount )
       
    87     {
       
    88     FUNC_LOG;
       
    89     TBool retVal = EFalse;
       
    90     if ( iAppUi.DownloadInfoMediator() )
       
    91         {
       
    92         if ( aAttachment.downloadProgress != KComplete &&
       
    93             !iAppUi.DownloadInfoMediator()->IsDownloading( aAttachment.partData.iMessagePartId ) )
       
    94             {
       
    95             iAppUi.DownloadInfoMediator()->DownloadAndSaveL( aAttachment.partData, aFileName );
       
    96             retVal = ETrue;
       
    97             }
       
    98         else if ( aAttachment.downloadProgress == KComplete )
       
    99             {
       
   100             CFSMailMessage* mailMessage =
       
   101                 iAppUi.GetMailClient()->GetMessageByUidL(
       
   102                     aAttachment.partData.iMailBoxId,
       
   103                     aAttachment.partData.iFolderId,
       
   104                     aAttachment.partData.iMessageId,
       
   105                     EFSMsgDataEnvelope );
       
   106             CleanupStack::PushL( mailMessage );
       
   107                 
       
   108             CFSMailMessagePart* attachment = mailMessage->ChildPartL(
       
   109                     aAttachment.partData.iMessagePartId ); 
       
   110             CleanupStack::PushL( attachment );  
       
   111             if ( TFsEmailUiUtility::OkToSaveFileL( aFileName, *attachment ) )       
       
   112                 {
       
   113                 attachment->CopyContentFileL( aFileName  ); 
       
   114                 aSavedCount++;              
       
   115                 }           
       
   116             CleanupStack::PopAndDestroy( attachment );              
       
   117             CleanupStack::PopAndDestroy( mailMessage );         
       
   118             }
       
   119         }
       
   120     return retVal;
       
   121     }
       
   122 
       
   123 void CFSEmailUiAttachmentsModelBase::CancelDownloadL( TFsTreeItemId aTreeId )
       
   124 	{
       
   125     FUNC_LOG;
       
   126 	TAttachmentData& item = GetItemL( aTreeId );
       
   127 	CancelDownloadL( item );
       
   128   	}
       
   129 
       
   130 void CFSEmailUiAttachmentsModelBase::CancelDownloadL( const TAttachmentData& aAttachment )
       
   131     {
       
   132     FUNC_LOG;
       
   133     iAppUi.DownloadInfoMediator()->CancelDownloadL( aAttachment.partData.iMessagePartId );
       
   134     }
       
   135 
       
   136 void CFSEmailUiAttachmentsModelBase::RemoveContentL( TFsTreeItemId aTreeId )
       
   137     {
       
   138     FUNC_LOG;
       
   139     TAttachmentData& item = GetItemL( aTreeId );
       
   140     RemoveContentL( item );
       
   141   	}
       
   142 
       
   143 void CFSEmailUiAttachmentsModelBase::RemoveContentL( const TAttachmentData& aAttachment )
       
   144     {
       
   145     FUNC_LOG;
       
   146     const TPartData& partData = aAttachment.partData;
       
   147 
       
   148     CFSMailMessage* mailMessage = iAppUi.GetMailClient()->GetMessageByUidL(
       
   149         partData.iMailBoxId,
       
   150         partData.iFolderId,
       
   151         partData.iMessageId,
       
   152         EFSMsgDataEnvelope );
       
   153     CleanupStack::PushL( mailMessage );
       
   154 
       
   155     CFSMailMessagePart* attachmentPart = mailMessage->ChildPartL( partData.iMessagePartId );
       
   156     CleanupStack::PushL( attachmentPart );
       
   157     
       
   158     // try to remove attachment contents from the plugin side
       
   159     attachmentPart->RemoveContentL();
       
   160     
       
   161     // Reset download progress if the content was actually removed
       
   162     if ( !IsCompletelyDownloadedL( aAttachment ) )
       
   163         {
       
   164         TAttachmentData& attachment = CONST_CAST( TAttachmentData&, aAttachment );
       
   165         attachment.downloadProgress = KNone;
       
   166         }
       
   167     
       
   168     CleanupStack::PopAndDestroy( attachmentPart );
       
   169     CleanupStack::PopAndDestroy( mailMessage );
       
   170     }
       
   171 
       
   172 TBool CFSEmailUiAttachmentsModelBase::IsDownloading(
       
   173 	const TAttachmentData& aAttachment )
       
   174 	{
       
   175     FUNC_LOG;
       
   176 	TBool retVal = iAppUi.DownloadInfoMediator()->IsDownloading(
       
   177 		aAttachment.partData.iMessagePartId );
       
   178     return retVal;
       
   179 	}
       
   180 
       
   181 TBool CFSEmailUiAttachmentsModelBase::IsCompletelyDownloadedL(
       
   182 	const TAttachmentData& aAttachment )
       
   183     {
       
   184     FUNC_LOG;
       
   185     TBool completed = !IsDownloading( aAttachment ) &&
       
   186                       !iAppUi.DownloadInfoMediator()->IsDownloadableL(
       
   187                       		aAttachment.partData );
       
   188     return completed;
       
   189     }
       
   190     
       
   191 TBool CFSEmailUiAttachmentsModelBase::IsMessage( const TAttachmentData& aAttachment ) const
       
   192     {
       
   193     FUNC_LOG;
       
   194     TBool isMessage = (aAttachment.fileType == EMessageType);
       
   195     return isMessage;
       
   196     }
       
   197 
       
   198 TBool CFSEmailUiAttachmentsModelBase::IsThereAnyCurrentDownloads()
       
   199 	{
       
   200     FUNC_LOG;
       
   201   	TBool ret(EFalse);
       
   202   	if ( iAppUi.DownloadInfoMediator() )
       
   203   		{
       
   204   		ret = iAppUi.DownloadInfoMediator()->IsAnyAttachmentDownloads();
       
   205   		}
       
   206 	return ret;
       
   207 	}
       
   208 
       
   209 HBufC* CFSEmailUiAttachmentsModelBase::CreateSizeDescLC( TInt aSize )
       
   210     {
       
   211     FUNC_LOG;
       
   212     HBufC* sizeDesc = TFsEmailUiUtility::CreateSizeDescLC( aSize );
       
   213     HBufC* decoratedDesc = StringLoader::LoadL( R_FSE_VIEWER_ATTACHMENTS_LIST_SIZE, *sizeDesc );
       
   214     CleanupStack::PopAndDestroy( sizeDesc );
       
   215     CleanupStack::PushL( decoratedDesc );
       
   216     return decoratedDesc;
       
   217     }
       
   218 
       
   219 CFreestyleEmailUiAppUi& CFSEmailUiAttachmentsModelBase::AppUi()
       
   220 	{
       
   221     FUNC_LOG;
       
   222 	return iAppUi;
       
   223 	}
       
   224 
       
   225   	
       
   226 ////////////////////////////////////
       
   227 // CFSEmailUiAttachmentsListModel //
       
   228 ////////////////////////////////////
       
   229 //MODEL CLASS CONSTRUCTION
       
   230 CFSEmailUiAttachmentsListModel* CFSEmailUiAttachmentsListModel::NewL(
       
   231     CFreestyleEmailUiAppUi& aAppUi, MFSEmailUiAttachmentsStatusObserver& aObserver )
       
   232     {
       
   233     FUNC_LOG;
       
   234     CFSEmailUiAttachmentsListModel* self = CFSEmailUiAttachmentsListModel::NewLC( aAppUi, aObserver);
       
   235     CleanupStack::Pop(self);
       
   236     return self;
       
   237     }
       
   238 
       
   239 CFSEmailUiAttachmentsListModel* CFSEmailUiAttachmentsListModel::NewLC( CFreestyleEmailUiAppUi& aAppUi,
       
   240                                                                        MFSEmailUiAttachmentsStatusObserver& aObserver )
       
   241     {
       
   242     FUNC_LOG;
       
   243     CFSEmailUiAttachmentsListModel* self = new (ELeave) CFSEmailUiAttachmentsListModel( aAppUi, aObserver );
       
   244     CleanupStack::PushL(self);
       
   245     self->ConstructL();
       
   246     return self;
       
   247     }
       
   248 
       
   249 void CFSEmailUiAttachmentsListModel::ConstructL()
       
   250     {
       
   251     FUNC_LOG;
       
   252   	CFSEmailUiAttachmentsModelBase::ConstructL();
       
   253     }
       
   254  
       
   255 CFSEmailUiAttachmentsListModel::CFSEmailUiAttachmentsListModel( CFreestyleEmailUiAppUi& aAppUi,
       
   256                                                                 MFSEmailUiAttachmentsStatusObserver& aObserver )
       
   257 	: CFSEmailUiAttachmentsModelBase( aAppUi ), iObserver( aObserver )
       
   258     {
       
   259     FUNC_LOG;
       
   260     }
       
   261 	
       
   262 CFSEmailUiAttachmentsListModel::~CFSEmailUiAttachmentsListModel()
       
   263     {
       
   264     FUNC_LOG;
       
   265     if ( iAppUi.DownloadInfoMediator() )
       
   266         {
       
   267         iAppUi.DownloadInfoMediator()->StopObserving( this );
       
   268         }
       
   269     iAttachments.Reset();
       
   270     }
       
   271 
       
   272 TAttachmentData* CFSEmailUiAttachmentsListModel::GetItem( TFsTreeItemId aTreeId )
       
   273     {
       
   274     FUNC_LOG;
       
   275     TBool found = EFalse;
       
   276     TAttachmentData* returnValue = NULL;
       
   277     const TInt attachmentCount = iAttachments.Count();
       
   278     for ( TInt i = 0; i < attachmentCount && !found; i++ )
       
   279         {
       
   280         if ( iAttachments[i].treeId == aTreeId )
       
   281             {
       
   282             returnValue = &iAttachments[i];
       
   283             found = ETrue;
       
   284             }
       
   285         }
       
   286     return returnValue;
       
   287     }
       
   288 
       
   289 TAttachmentData& CFSEmailUiAttachmentsListModel::GetItemL( TFsTreeItemId aTreeId )
       
   290     {
       
   291     FUNC_LOG;
       
   292     TAttachmentData* returnValue = GetItem( aTreeId );
       
   293     if ( !returnValue )
       
   294         {
       
   295         User::Leave( KErrNotFound );
       
   296         }
       
   297     return *returnValue;
       
   298     }
       
   299 
       
   300 TPartData CFSEmailUiAttachmentsListModel::GetMessageL( TFsTreeItemId /*aTreeId*/ )
       
   301     {
       
   302     FUNC_LOG;
       
   303     // All the items in the attachments list view belong to the same message
       
   304     return iMessage;
       
   305     }
       
   306 
       
   307 const RArray<TAttachmentData>& CFSEmailUiAttachmentsListModel::GetModel()
       
   308 	{
       
   309 	return iAttachments;
       
   310   	}
       
   311 
       
   312 void CFSEmailUiAttachmentsListModel::SetNodeIdL( TInt aAttachmentIndex, TFsTreeItemId aTreeItemId )
       
   313 	{
       
   314     FUNC_LOG;
       
   315 	if ( iAttachments.Count() > aAttachmentIndex )
       
   316 		{
       
   317 		iAttachments[aAttachmentIndex].treeId = aTreeItemId;
       
   318 		}
       
   319 	else
       
   320 		{
       
   321 		User::Leave ( KErrNotFound );
       
   322 		}
       
   323 	}
       
   324 
       
   325 void CFSEmailUiAttachmentsListModel::RequestResponseL(
       
   326 	const TFSProgress& aEvent, const TPartData& aPart )
       
   327 	{
       
   328     FUNC_LOG;
       
   329 
       
   330     TBool downloadCompletedAndListUpdated = EFalse;
       
   331 
       
   332     if ( aEvent.iProgressStatus == TFSProgress::EFSStatus_RequestComplete )
       
   333         {
       
   334         // We may need to update the list here as POP protocol
       
   335         // creates a new entry when redownloading an
       
   336         // attachment (in POP case the whole mail is
       
   337         // downloaded again). Thus, the list might not be 
       
   338         // up-to-date at this point. Similar kind of handling
       
   339         // is done in UI side.
       
   340     	CFSMailMessage* mailMessage =
       
   341     	    iAppUi.GetMailClient()->GetMessageByUidL(
       
   342     		    aPart.iMailBoxId,
       
   343     		    aPart.iFolderId,
       
   344     		    aPart.iMessageId,
       
   345     		    EFSMsgDataEnvelope );
       
   346 
       
   347         CleanupStack::PushL( mailMessage );
       
   348         
       
   349     	RPointerArray<CFSMailMessagePart> mailParts;
       
   350 
       
   351     	CleanupResetAndDestroyClosePushL( mailParts );
       
   352 
       
   353     	mailMessage->AttachmentListL( mailParts );
       
   354     	
       
   355         TBool listNeedsUpdate = ETrue;
       
   356 
       
   357     	TInt count = mailParts.Count();
       
   358 
       
   359         for ( TInt i = 0; i < count && listNeedsUpdate; i++ )
       
   360     	    {
       
   361     	    TInt partId = mailParts[ i ]->GetPartId().Id();
       
   362     	    
       
   363     	    listNeedsUpdate = ( aPart.iMessagePartId.Id() != partId );
       
   364     	    }
       
   365 
       
   366     	CleanupStack::PopAndDestroy( 2, mailMessage );
       
   367 
       
   368         if ( listNeedsUpdate )
       
   369             {
       
   370             UpdateListL( aPart );
       
   371             
       
   372             downloadCompletedAndListUpdated = ETrue;
       
   373             }
       
   374         }
       
   375 
       
   376     if ( downloadCompletedAndListUpdated )
       
   377         {
       
   378         // Giving KErrNotFound causes a refresh to UI
       
   379         iObserver.DownloadStatusChangedL( KErrNotFound );
       
   380         }
       
   381     else
       
   382         {
       
   383         TInt index = KErrNotFound;
       
   384 
       
   385         TInt attaCount = iAttachments.Count();
       
   386 
       
   387     	for ( TInt i = 0; i < attaCount && index == KErrNotFound; i++ )
       
   388     		{
       
   389     	   	if ( iAttachments[i].partData.iMessagePartId ==
       
   390     	   	        aPart.iMessagePartId )
       
   391     	   		{
       
   392     	   		index = i;
       
   393     	   		}
       
   394     		}
       
   395 
       
   396         if ( index != KErrNotFound )
       
   397             {
       
   398        		// Currently, it's not very well defined what should be the values
       
   399        		// of each field of TFSProgressStatus in case the download is
       
   400        		// completed or cancelled. For now, we make the assumption that
       
   401        		// these values are correctly set for status events. In complete 
       
   402        		// event we set the progress to 100% and in cancel event to 0%, 
       
   403        		// regardless of the counter values. These may be subjects to
       
   404        		// change.
       
   405             if ( aEvent.iError )
       
   406        		    {
       
   407        		    iAttachments[index].downloadProgress = KNone;
       
   408        		    }
       
   409        		else if ( aEvent.iProgressStatus ==
       
   410        		            TFSProgress::EFSStatus_Status )
       
   411    		        {
       
   412     	   		if ( aEvent.iMaxCount > 0 && aEvent.iCounter > 0 )
       
   413     	   			{
       
   414     				iAttachments[index].downloadProgress =
       
   415     				    KComplete * aEvent.iCounter / aEvent.iMaxCount;
       
   416     	   			}
       
   417     	   		else
       
   418     	   			{
       
   419     	   			iAttachments[index].downloadProgress = KNone;
       
   420     	   			}
       
   421    		        }
       
   422        		else if ( aEvent.iProgressStatus ==
       
   423        		            TFSProgress::EFSStatus_RequestComplete )
       
   424        		    {
       
   425    		        if ( IsCompletelyDownloadedL( iAttachments[index] ) )
       
   426    		            {
       
   427    		            iAttachments[index].downloadProgress = KComplete;
       
   428    		            }
       
   429    		        }
       
   430        		else if ( aEvent.iProgressStatus ==
       
   431        		            TFSProgress::EFSStatus_RequestCancelled )
       
   432    		        {
       
   433    		        iAttachments[index].downloadProgress = KNone;
       
   434    		        }
       
   435 
       
   436     	    iObserver.DownloadStatusChangedL( index );
       
   437             }
       
   438         }
       
   439 	}
       
   440 
       
   441 void CFSEmailUiAttachmentsListModel::CancelAllDownloadsL()
       
   442 	{
       
   443     FUNC_LOG;
       
   444   	TInt attCount = iAttachments.Count();
       
   445 	for ( TInt i = 0; i < attCount; i++ )
       
   446 		{
       
   447 		if ( iAppUi.DownloadInfoMediator() && iAppUi.DownloadInfoMediator()->IsDownloading(
       
   448 			iAttachments[i].partData.iMessagePartId ) )
       
   449 			{
       
   450 	    	iAppUi.DownloadInfoMediator()->CancelDownloadL(
       
   451 	    		iAttachments[i].partData.iMessagePartId );
       
   452 			}
       
   453 		}
       
   454 	}
       
   455 	
       
   456 TBool CFSEmailUiAttachmentsListModel::IsThereAnyMessageAttachments() const
       
   457     {
       
   458     FUNC_LOG;
       
   459     TBool msgFound = EFalse;
       
   460     TInt attCount = iAttachments.Count();
       
   461     for ( TInt i = 0 ; i < attCount && !msgFound ; i++ )
       
   462         {
       
   463         msgFound = IsMessage( iAttachments[i] );
       
   464         }
       
   465     return msgFound;
       
   466     }
       
   467 
       
   468 void CFSEmailUiAttachmentsListModel::UpdateListL( CFSMailMessage* aEmbeddedMessage )
       
   469 	{
       
   470     FUNC_LOG;
       
   471 	iAttachments.Reset();
       
   472 
       
   473 	CFSMailMessage* mailMessage = aEmbeddedMessage;
       
   474     
       
   475 	RPointerArray<CFSMailMessagePart> mailParts;
       
   476 	CleanupResetAndDestroyClosePushL( mailParts );
       
   477 	mailMessage->AttachmentListL( mailParts );
       
   478 	
       
   479 	TInt mailPartsCount = mailParts.Count();
       
   480 	for ( TInt i = 0; i < mailPartsCount; i++ )
       
   481 		{
       
   482         TFileType fileType = TFsEmailUiUtility::GetFileType(
       
   483         	mailParts[i]->AttachmentNameL(),
       
   484         	mailParts[i]->GetContentType() );
       
   485 		TPartData partData(	aEmbeddedMessage->GetMailBoxId(),
       
   486                             aEmbeddedMessage->GetFolderId(),
       
   487                             aEmbeddedMessage->GetMessageId(),
       
   488 			                mailParts[i]->GetPartId() );
       
   489 		TAttachmentData attachment = 
       
   490 			{
       
   491 			mailParts[i]->ContentSize(),
       
   492 			0,
       
   493 			fileType,
       
   494 			mailParts[i]->AttachmentNameL(),
       
   495 			KFsTreeNoneID,
       
   496 			partData
       
   497 			};
       
   498 		attachment.downloadProgress = KComplete;
       
   499 		iAttachments.Append( attachment );
       
   500 		}
       
   501 	CleanupStack::PopAndDestroy( &mailParts );
       
   502 	}
       
   503 	
       
   504 void CFSEmailUiAttachmentsListModel::UpdateListL( TPartData aMessage )
       
   505 	{
       
   506     FUNC_LOG;
       
   507 	iAttachments.Reset();
       
   508 	
       
   509 	iMessage = aMessage;
       
   510 	iAppUi.DownloadInfoMediator()->StopObserving( this );
       
   511 	iAppUi.DownloadInfoMediator()->AddObserver( this, iMessage.iMessageId );
       
   512 	CFSMailMessage* mailMessage = iAppUi.GetMailClient()->GetMessageByUidL(
       
   513 		iMessage.iMailBoxId,
       
   514 		iMessage.iFolderId,
       
   515 		iMessage.iMessageId,
       
   516 		EFSMsgDataEnvelope );
       
   517     CleanupStack::PushL( mailMessage );
       
   518     
       
   519 	RPointerArray<CFSMailMessagePart> mailParts;
       
   520 	CleanupResetAndDestroyClosePushL( mailParts );
       
   521 	mailMessage->AttachmentListL( mailParts );
       
   522 	
       
   523 	
       
   524     CFSMailMessagePart* calendarPart = 
       
   525         mailMessage->FindBodyPartL( KFSMailContentTypeTextCalendar );
       
   526     CleanupStack::PushL( calendarPart );
       
   527 
       
   528 	TInt mailPartsCount = mailParts.Count();
       
   529 	for ( TInt i = 0; i < mailPartsCount; i++ )
       
   530 		{
       
   531         CFSMailMessagePart* part = mailParts[i];
       
   532 		
       
   533         TFileType fileType = TFsEmailUiUtility::GetFileType(
       
   534         	part->AttachmentNameL(),
       
   535         	part->GetContentType() );
       
   536 		TPartData partData(	iMessage.iMailBoxId,
       
   537 			                iMessage.iFolderId,
       
   538 			                iMessage.iMessageId,
       
   539 			                part->GetPartId() );
       
   540 		
       
   541 		TAttachmentData attachment = 
       
   542 			{
       
   543 			part->ContentSize(),
       
   544 			0,
       
   545 			fileType,
       
   546 			part->AttachmentNameL(),
       
   547 			KFsTreeNoneID,
       
   548 			partData
       
   549 			};
       
   550 
       
   551         // figure out and set download progress
       
   552 		TUint downloadProgress;
       
   553 		if ( IsCompletelyDownloadedL ( attachment ) )
       
   554 		    {
       
   555 		    downloadProgress = KComplete;
       
   556 		    }
       
   557 		else if ( part->ContentSize() > 0 )
       
   558 			{
       
   559 			downloadProgress = KComplete *
       
   560 							   mailParts[i]->FetchedContentSize() /
       
   561 							   mailParts[i]->ContentSize();
       
   562 			}
       
   563 		else
       
   564 			{
       
   565 			downloadProgress = KNone;
       
   566 			}
       
   567 		attachment.downloadProgress = downloadProgress;
       
   568 		
       
   569     	// If MR,do not add ICS file to  attachment list
       
   570 		if (! ( mailMessage->IsFlagSet( EFSMsgFlag_CalendarMsg ) 
       
   571 		     && calendarPart
       
   572 		     && part->GetPartId() == calendarPart->GetPartId() ) )
       
   573 		    {
       
   574     		iAttachments.Append( attachment );
       
   575 		    }
       
   576 		
       
   577 		}
       
   578     CleanupStack::PopAndDestroy( calendarPart );
       
   579 	CleanupStack::PopAndDestroy( &mailParts );
       
   580 	CleanupStack::PopAndDestroy( mailMessage );
       
   581   	}
       
   582 	
       
   583 TBool CFSEmailUiAttachmentsListModel::SaveAllAttachmentsL(
       
   584 	const TDesC& aFileName )
       
   585 	{
       
   586     FUNC_LOG;
       
   587 	TBool retVal = EFalse;
       
   588 	TInt attCount = iAttachments.Count();
       
   589     TInt savedCount( 0 );
       
   590 	for ( TInt i = 0; i < attCount; i++ )
       
   591 		{
       
   592 		TBool downloadStarted = SaveAttachmentL( iAttachments[i], aFileName, savedCount );
       
   593 		retVal = downloadStarted || retVal;
       
   594 		}
       
   595 	if ( savedCount )
       
   596 	    {
       
   597 	    // <cmail>
       
   598 	    TFsEmailUiUtility::ShowFilesSavedToFolderNoteL( savedCount ); 	    
       
   599 	    }
       
   600 	
       
   601 	return retVal;
       
   602 	}
       
   603 
       
   604 TBool CFSEmailUiAttachmentsListModel::DownloadAllAttachmentsL()
       
   605 	{
       
   606     FUNC_LOG;
       
   607   	TBool retVal = EFalse;
       
   608   	TInt attCount = iAttachments.Count();
       
   609 	for ( TInt i = 0; i < attCount; i++ )
       
   610 		{
       
   611 		TBool downloadStarted = StartDownloadL( iAttachments[i] );
       
   612 		retVal = downloadStarted || retVal;
       
   613 		}
       
   614   	return retVal;
       
   615 	}
       
   616 
       
   617 HBufC* CFSEmailUiAttachmentsListModel::CreateMailSubjectTextLC() const
       
   618     {
       
   619     FUNC_LOG;
       
   620 	CFSMailMessage* mailMessage = iAppUi.GetMailClient()->GetMessageByUidL(
       
   621 		iMessage.iMailBoxId,
       
   622 		iMessage.iFolderId,
       
   623 		iMessage.iMessageId,
       
   624 		EFSMsgDataEnvelope );
       
   625     CleanupStack::PushL( mailMessage );
       
   626     
       
   627     HBufC* subjectText = TFsEmailUiUtility::CreateSubjectTextLC( mailMessage );
       
   628 	CleanupStack::Pop( subjectText );
       
   629     CleanupStack::PopAndDestroy( mailMessage );
       
   630     CleanupStack::PushL( subjectText );
       
   631     
       
   632     return subjectText;
       
   633     }
       
   634