meetingrequest/mrgui/mrfieldbuilderplugin/src/cmrattachmentcommandhandler.cpp
branchRCL_3
changeset 80 726fba06891a
parent 64 3533d4323edc
equal deleted inserted replaced
73:c8382f7b54ef 80:726fba06891a
   162 void CMRAttachmentCommandHandler::ConstructL()
   162 void CMRAttachmentCommandHandler::ConstructL()
   163     {
   163     {
   164     FUNC_LOG;
   164     FUNC_LOG;
   165 
   165 
   166     iDocHandler = CDocumentHandler::NewL();
   166     iDocHandler = CDocumentHandler::NewL();
       
   167     
       
   168     iAttachmentIndex = KErrNotFound;
   167     }
   169     }
   168 
   170 
   169 // ---------------------------------------------------------------------------
   171 // ---------------------------------------------------------------------------
   170 // CMRAttachmentCommandHandler::HandleAttachmentCommandL
   172 // CMRAttachmentCommandHandler::HandleAttachmentCommandL
   171 // ---------------------------------------------------------------------------
   173 // ---------------------------------------------------------------------------
   174         TInt aCommandId,
   176         TInt aCommandId,
   175         const CESMRRichTextLink& aSelectedLink )
   177         const CESMRRichTextLink& aSelectedLink )
   176     {
   178     {
   177     FUNC_LOG;
   179     FUNC_LOG;
   178 
   180 
   179     TInt attachmentIndex( ResolveAttachmentIndexL( aSelectedLink.Value() ) );
   181     // If attachment index is not found, we must resolve it
   180     HandleAttachmentCommandInternalL( aCommandId, attachmentIndex );
   182     if( iAttachmentIndex == KErrNotFound )
   181     }
   183 		{
       
   184 		iAttachmentIndex = ResolveAttachmentIndexL( aSelectedLink.Value() );
       
   185 		}
       
   186 	
       
   187 	HandleAttachmentCommandInternalL( aCommandId, iAttachmentIndex );
       
   188 	
       
   189 	// Attachment index can be cleared after the command is executed.
       
   190 	iAttachmentIndex = KErrNotFound;
       
   191 	
       
   192 	// If save all attachments command is in progress ... 
       
   193 	if( iSaveAllAttachmentsCommand )
       
   194 		{
       
   195 		if ( iAttachmentInfo->AttachmentCount() > 0 )
       
   196 		   {
       
   197 		   // ... Let's continue the download process by starting the 
       
   198 		   // next download
       
   199 		   SaveNextRemoteAttachmentL();
       
   200 		   }
       
   201 		else
       
   202 		   {
       
   203 		   // ... Or show a note if all remote attachments have been saved.
       
   204 		   ShowInfoNoteL( iEntry.AttachmentCountL() );
       
   205 		   iSaveAllAttachmentsCommand = EFalse;
       
   206 		   }
       
   207 		}
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // CMRAttachmentCommandHandler::IsSaveAllAttachmentsInProgress
       
   212 // ---------------------------------------------------------------------------
       
   213 //
       
   214 TBool CMRAttachmentCommandHandler::IsSaveAllAttachmentsInProgress( )
       
   215 	{
       
   216 	return iSaveAllAttachmentsCommand;// return the flag state
       
   217 	}
   182 
   218 
   183 // ---------------------------------------------------------------------------
   219 // ---------------------------------------------------------------------------
   184 // CMRAttachmentCommandHandler::IsRemoteAttachmentL
   220 // CMRAttachmentCommandHandler::IsRemoteAttachmentL
   185 // ---------------------------------------------------------------------------
   221 // ---------------------------------------------------------------------------
   186 //
   222 //
   302     FUNC_LOG;
   338     FUNC_LOG;
   303 
   339 
   304     // Operation failed or cancelled, hide download indicator
   340     // Operation failed or cancelled, hide download indicator
   305     TRAP_IGNORE( HideDownloadIndicatorL() );
   341     TRAP_IGNORE( HideDownloadIndicatorL() );
   306 	iCommandInProgress = 0;
   342 	iCommandInProgress = 0;
       
   343 	iSaveAllAttachmentsCommand = EFalse;
   307 
   344 
   308 	if ( aErrorCode != KErrCancel )
   345 	if ( aErrorCode != KErrCancel )
   309         {
   346         {
   310         // Operation failed, show error note
   347         // Operation failed, show error note
   311         CCoeEnv::Static()->HandleError( aErrorCode );
   348         CCoeEnv::Static()->HandleError( aErrorCode );
   461             HandleAttachmentCommandInternalL(
   498             HandleAttachmentCommandInternalL(
   462                     EESMRViewerOpenAndSaveAttachment, attachmentIndex );
   499                     EESMRViewerOpenAndSaveAttachment, attachmentIndex );
   463 
   500 
   464             iCommandInProgress = 0;
   501             iCommandInProgress = 0;
   465             }
   502             }
   466         else
   503         else // Save and Save All attachments commands
   467             {
   504             {
   468             HandleAttachmentCommandInternalL(
   505         	// Let's keep in mind, if save all attachments command
   469                     EESMRViewerSaveAttachment, attachmentIndex );
   506         	// is in progress.
   470 
   507         	if( EESMRViewerSaveAllAttachments == iCommandInProgress )
   471             if ( EESMRViewerSaveAllAttachments == iCommandInProgress )
   508         		{
   472                 {
   509         		iSaveAllAttachmentsCommand = ETrue;
   473                 iCommandInProgress = 0;
   510         		}
   474 
   511 
   475                 if ( iAttachmentInfo->AttachmentCount() > 0 )
   512         	// Send asynchronous event, that attachment with 
   476                     {
   513         	// given index is saved. This command will return to
   477                     // There are more attachments to be downloaded --> Download next
   514         	// HandleAttachmentCommandL in this class. Async command
   478                     SaveNextRemoteAttachmentL();
   515         	// is used to avoid system caused error where memory selection
   479                     }
   516         	// query in document handler does not receive key events 
   480                 else
   517         	// correctly.
   481                     {
   518 			CESMRFieldCommandEvent* event = CESMRFieldCommandEvent::NewLC(
   482                     // All remote attachments have been saved. Show info note.
   519 					NULL,
   483                     ShowInfoNoteL( iEntry.AttachmentCountL() );
   520 					EESMRViewerSaveAttachment );
   484                     }
   521 			
   485                 }
   522 			// Record attachment index
   486             else
   523          	iAttachmentIndex = attachmentIndex;
   487                 {
   524          	
   488                 iCommandInProgress = 0;
   525          	// Send async event
   489                 }
   526 			iEventQueue.NotifyEventAsyncL( event );
       
   527 			CleanupStack::Pop( event );
       
   528 
       
   529 			// Set to zero for the duration of the saving.
       
   530             iCommandInProgress = 0;
   490             }
   531             }
   491         }
   532         }
   492 
   533 
   493     CleanupStack::PopAndDestroy( operation );
   534     CleanupStack::PopAndDestroy( operation );
   494     }
   535     }
   749                         iDownloadOperations[remoteCommand];
   790                         iDownloadOperations[remoteCommand];
   750 
   791 
   751                 iDownloadOperations.Remove( remoteCommand );
   792                 iDownloadOperations.Remove( remoteCommand );
   752                 delete command;
   793                 delete command;
   753                 }
   794                 }
       
   795             
       
   796             iSaveAllAttachmentsCommand = EFalse;
   754             }
   797             }
   755             break;
   798             break;
   756         case EESMRViewerSaveAllAttachments:
   799         case EESMRViewerSaveAllAttachments:
   757             {
   800             {
   758             SaveAllAttachmentsL();
   801             SaveAllAttachmentsL();