calendarui/commonutils/src/calenattachmentmodel.cpp
branchRCL_3
changeset 12 38571fd2a704
parent 0 f979ecb2b13e
child 21 9711e452b5e9
equal deleted inserted replaced
5:42814f902fe6 12:38571fd2a704
   279 EXPORT_C void CCalenAttachmentModel::AddAttachmentL( 
   279 EXPORT_C void CCalenAttachmentModel::AddAttachmentL( 
   280                                                     const TDesC& aFullName,
   280                                                     const TDesC& aFullName,
   281                                                     const TDesC& aSystemFileName,
   281                                                     const TDesC& aSystemFileName,
   282                                                     TInt aSize,
   282                                                     TInt aSize,
   283                                                     TBool aFetched,
   283                                                     TBool aFetched,
   284                                                     const TDataType& aDataType )
   284                                                     const TDataType& aDataType,
       
   285                                                     RFile& aFile)
   285 	{
   286 	{
   286 	
   287 	
   287 	TRACE_ENTRY_POINT;
   288 	TRACE_ENTRY_POINT;
   288 
   289 
   289 	CCalenAttachmentInfo* info = 
   290 	CCalenAttachmentInfo* info = 
   292 	                aSize, 
   293 	                aSize, 
   293 	                aFetched, 
   294 	                aFetched, 
   294 	                aDataType, 
   295 	                aDataType, 
   295 	                CCalenAttachmentInfo::ECalenAttachmentFetchedFromEntry );
   296 	                CCalenAttachmentInfo::ECalenAttachmentFetchedFromEntry );
   296 	CleanupStack::PushL(info);
   297 	CleanupStack::PushL(info);
       
   298 	info->SetFileHandle( aFile );
   297 	iAttachInfoArray.AppendL(info);
   299 	iAttachInfoArray.AppendL(info);
   298 	CleanupStack::Pop();
   300 	CleanupStack::Pop();
   299 	isAttachmentModelCleared = EFalse;
   301 	isAttachmentModelCleared = EFalse;
   300 
   302 
   301 	TRACE_EXIT_POINT;
   303 	TRACE_EXIT_POINT;
   339 		attachmentInfo = iAttachInfoArray[ aIndex ];
   341 		attachmentInfo = iAttachInfoArray[ aIndex ];
   340 		
   342 		
   341 		// Get the attachment file name
   343 		// Get the attachment file name
   342 		TFileName fileName( attachmentInfo->FileName() );
   344 		TFileName fileName( attachmentInfo->FileName() );
   343 		
   345 		
       
   346 		TParsePtrC fileNameParser(fileName);
       
   347 		TPtrC parsedFileName = fileNameParser.NameAndExt();
       
   348 		
   344 		// Confirm if needs to be deleted.
   349 		// Confirm if needs to be deleted.
   345 		CAknQueryDialog* confirmQuery = NULL;
   350 		CAknQueryDialog* confirmQuery = NULL;
   346 		confirmQuery = CAknQueryDialog::NewL();
   351 		confirmQuery = CAknQueryDialog::NewL();
   347 		HBufC* stringBuf = NULL;
   352 		HBufC* stringBuf = NULL;
   348 		stringBuf = StringLoader::LoadLC( 
   353 		stringBuf = StringLoader::LoadLC( 
   349 		                                  R_QTN_QUERY_COMMON_CONF_REMOVE, 
   354 		                                  R_QTN_QUERY_COMMON_CONF_REMOVE, 
   350 		                                  fileName,
   355 		                                  parsedFileName,
   351 		                                  CEikonEnv::Static() );
   356 		                                  CEikonEnv::Static() );
   352 		confirmQuery->SetPromptL( *stringBuf );
   357 		confirmQuery->SetPromptL( *stringBuf );
   353 		if( EAknSoftkeyYes != 
   358 		if( EAknSoftkeyYes != 
   354 		confirmQuery->ExecuteLD( R_CALEN_ATTACHMENT_DELETE_QUERY ) )
   359 		confirmQuery->ExecuteLD( R_CALEN_ATTACHMENT_DELETE_QUERY ) )
   355 			{
   360 			{
   480     {
   485     {
   481     TRACE_ENTRY_POINT;
   486     TRACE_ENTRY_POINT;
   482     
   487     
   483     RFile file;
   488     RFile file;
   484     CCalenAttachmentInfo* attachmentInfo = iAttachInfoArray[aIndex];
   489     CCalenAttachmentInfo* attachmentInfo = iAttachInfoArray[aIndex];
   485     TParsePtrC fileNameParser(attachmentInfo->SystemFileName());
   490     if( attachmentInfo->IsFileHandleSet() )
   486     CEikonEnv* eikonEnv = CEikonEnv::Static();
   491         {
   487     RFs& fs = eikonEnv->FsSession();
   492 		attachmentInfo->FileHandle(file);
   488     User::LeaveIfError(fs.ShareProtected());
   493         }
   489     TInt err = file.Open( fs, attachmentInfo->SystemFileName(), 
   494     else
   490                           EFileRead|EFileShareReadersOnly);
   495         {
   491     if(err == KErrInUse)
   496         TParsePtrC fileNameParser(attachmentInfo->SystemFileName());
   492         {
   497         CEikonEnv* eikonEnv = CEikonEnv::Static();
   493         file.Close();
   498         RFs& fs = eikonEnv->FsSession();
   494         User::LeaveIfError( file.Open( fs, attachmentInfo->SystemFileName(),
   499         User::LeaveIfError(fs.ShareProtected());
   495                             EFileRead|EFileShareReadersOnly) );
   500         TInt err = file.Open( fs, attachmentInfo->SystemFileName(), 
       
   501                               EFileRead|EFileShareReadersOnly);
       
   502         if(err == KErrInUse)
       
   503             {
       
   504             file.Close();
       
   505             User::LeaveIfError( file.Open( fs, attachmentInfo->SystemFileName(),
       
   506                                 EFileRead|EFileShareReadersOnly) );
       
   507             }    
   496         }
   508         }
   497     
   509     
   498     TRACE_EXIT_POINT;
   510     TRACE_EXIT_POINT;
   499     return file;
   511     return file;
   500     }
   512     }
   591 					TDataType fileMimeType(attachment->MimeType());
   603 					TDataType fileMimeType(attachment->MimeType());
   592 					TInt fileSize(0);
   604 					TInt fileSize(0);
   593 					fileHandle.Size(fileSize);
   605 					fileHandle.Size(fileSize);
   594 
   606 
   595 					AddAttachmentL( fileName, systemFileName, fileSize,
   607 					AddAttachmentL( fileName, systemFileName, fileSize,
   596 					                ETrue, fileMimeType );
   608 					                ETrue, fileMimeType, fileHandle);
   597 					CleanupStack::PopAndDestroy(&fileHandle);
   609 					CleanupStack::PopAndDestroy(&fileHandle);
   598 					}
   610 					}
   599 				}
   611 				}
   600 			}
   612 			}
   601 		}
   613 		}