calendarui/controller/src/calenattachmentui.cpp
branchRCL_3
changeset 12 38571fd2a704
parent 5 42814f902fe6
child 20 21239b3bcd78
equal deleted inserted replaced
5:42814f902fe6 12:38571fd2a704
   346 TBool CCalenAttachmentUi::FetchFileL( 
   346 TBool CCalenAttachmentUi::FetchFileL( 
   347                     CCalenAttachmentUtils::TCalenAttachmentFileType aFetchType)
   347                     CCalenAttachmentUtils::TCalenAttachmentFileType aFetchType)
   348     {
   348     {
   349     TRACE_ENTRY_POINT;       
   349     TRACE_ENTRY_POINT;       
   350     
   350     
   351     TAiwVariant sizeLimit( KCalenAttachmentOverhead );
   351        
   352     TAiwGenericParam sizeLimitParam( EGenericParamMMSSizeLimit, sizeLimit );
       
   353 
       
   354     CAiwGenericParamList* paramList = CAiwGenericParamList::NewLC();
       
   355     paramList->AppendL( sizeLimitParam );
       
   356     
       
   357     CDesCArrayFlat* files = new( ELeave ) CDesC16ArrayFlat(1);
   352     CDesCArrayFlat* files = new( ELeave ) CDesC16ArrayFlat(1);
   358     CleanupStack::PushL(files);
   353     CleanupStack::PushL(files);
   359     
   354     
   360     TBool fetchOk(EFalse);
   355     TBool fetchOk(EFalse);
   361     if(aFetchType == CCalenAttachmentUtils::EUnknown)
   356     if(aFetchType == CCalenAttachmentUtils::EUnknown)
   369         }
   364         }
   370     else
   365     else
   371         {       
   366         {       
   372         // used for fetching media file and notes 
   367         // used for fetching media file and notes 
   373         fetchOk = CCalenAttachmentUtils::FetchFileL( aFetchType, *files,
   368         fetchOk = CCalenAttachmentUtils::FetchFileL( aFetchType, *files,
   374                                         paramList, EFalse, EFalse, this );
   369                                         NULL, EFalse, EFalse, this );
   375     
   370     
   376         
   371         
   377         if(fetchOk && iSelectedCommand == ECalenAddNote)
   372         if(fetchOk && iSelectedCommand == ECalenAddNote)
   378             {         
   373             {         
   379             AddAttachmentL(files->MdcaPoint(0));
   374             AddAttachmentL(files->MdcaPoint(0));
   380             }                
   375             }                
   381         }
   376         }
   382     CleanupStack::PopAndDestroy( 2, paramList );
   377     CleanupStack::PopAndDestroy( files );
   383     
   378     
   384     if(!fetchOk)
   379     if(!fetchOk)
   385         {
   380         {
   386         iController.BroadcastNotification(ECalenNotifyDialogClosed);
   381         iController.BroadcastNotification(ECalenNotifyDialogClosed);
   387         }
   382         }
   657                 // check if attachmentinfo created for new attachment,to avoid adding
   652                 // check if attachmentinfo created for new attachment,to avoid adding
   658                 // the attachments which already exists in the entry
   653                 // the attachments which already exists in the entry
   659                 if(attachmentInfo->StoreType() == CCalenAttachmentInfo::ECalenNewAttachment)
   654                 if(attachmentInfo->StoreType() == CCalenAttachmentInfo::ECalenNewAttachment)
   660                     {
   655                     {
   661                     TParsePtrC fileNameParser(attachmentInfo->SystemFileName());
   656                     TParsePtrC fileNameParser(attachmentInfo->SystemFileName());
   662                     RFile fileHandle;    
   657                     RFile fileHandle = iAttachmentModel->GetAttachmentFileL(index);
   663                     CEikonEnv* eikonEnv = CEikonEnv::Static();
   658                     CleanupClosePushL(fileHandle);
   664                     RFs& fs = eikonEnv->FsSession();
       
   665                     User::LeaveIfError(fs.ShareProtected());
       
   666                     TInt aSize;
   659                     TInt aSize;
   667                     TInt err = fileHandle.Open(fs, attachmentInfo->SystemFileName(), EFileWrite);
       
   668                     TInt error = fileHandle.Size(aSize);
   660                     TInt error = fileHandle.Size(aSize);
   669                     HBufC8* data = HBufC8::NewLC(aSize);
   661                     HBufC8* data = HBufC8::NewLC(aSize);
   670                     TPtr8 fileData = data->Des();
   662                     TPtr8 fileData = data->Des();         
   671                     if (error == KErrNone)
   663                     if (error == KErrNone)
   672                         {                
   664                         {                
   673                         TInt readingError = fileHandle.Read(fileData,aSize);  
   665                         TInt readingError = fileHandle.Read(fileData,aSize);  
   674                         if(readingError == KErrNone)
   666                         if(readingError == KErrNone)
   675                             {
   667                             {
   679                             
   671                             
   680                             // sets the label for the attachment
   672                             // sets the label for the attachment
   681                             attachment->SetLabelL(fileNameParser.NameAndExt());
   673                             attachment->SetLabelL(fileNameParser.NameAndExt());
   682                             // sets mime type for the attachment
   674                             // sets mime type for the attachment
   683                             attachment->SetMimeTypeL(attachmentInfo->DataType().Des8());
   675                             attachment->SetMimeTypeL(attachmentInfo->DataType().Des8());
   684                             
       
   685                             CleanupClosePushL(fileHandle);
       
   686                             CleanupStack::PopAndDestroy(&fileHandle);
       
   687                             entry->AddAttachmentL(*attachment);
   676                             entry->AddAttachmentL(*attachment);
   688                             CleanupStack::Pop(attachment);
   677                             CleanupStack::Pop(attachment);
   689                             }                
   678                             }                
   690                         }
   679                         }
   691                     
   680                         CleanupStack::PopAndDestroy(&fileHandle);
   692                     }
   681                     }
   693                 }
   682                 }
   694                         
   683                         
   695             attachmentInfoList.Close();
   684             attachmentInfoList.Close();
   696             
   685