harvester/harvesterplugins/ImagePlugin/src/harvesterimageplugin.cpp
branchRCL_3
changeset 3 6752808b2036
parent 1 acef663c1218
child 6 646a02f170b9
equal deleted inserted replaced
2:b73a2e62868f 3:6752808b2036
    23 
    23 
    24 #include "harvesterlog.h"
    24 #include "harvesterlog.h"
    25 #include "mdsutils.h"
    25 #include "mdsutils.h"
    26 #include "harvesterexifutil.h"
    26 #include "harvesterexifutil.h"
    27 #include "harvesterimageplugin.h"
    27 #include "harvesterimageplugin.h"
       
    28 #include "harvestercommon.h"
    28 #include "mdeobjectwrapper.h"
    29 #include "mdeobjectwrapper.h"
    29 
    30 
    30 using namespace MdeConstants;
    31 using namespace MdeConstants;
    31 
    32 
    32 // image mime types
    33 // image mime types
   252     User::LeaveIfError( iMimeTypeMappings.InsertInOrder( TMimeTypeMapping<TImageMetadataHandling>(
   253     User::LeaveIfError( iMimeTypeMappings.InsertInOrder( TMimeTypeMapping<TImageMetadataHandling>(
   253     		KExtWmf(), KWmfMime(), EOtherHandling ), cmp ) );
   254     		KExtWmf(), KWmfMime(), EOtherHandling ), cmp ) );
   254     
   255     
   255     User::LeaveIfError( iMimeTypeMappings.InsertInOrder( TMimeTypeMapping<TImageMetadataHandling>(
   256     User::LeaveIfError( iMimeTypeMappings.InsertInOrder( TMimeTypeMapping<TImageMetadataHandling>(
   256             KExtOtb(), KOtbMime(), EOtherHandling ), cmp ) );
   257             KExtOtb(), KOtbMime(), EOtherHandling ), cmp ) );
       
   258     
       
   259     SetPriority( KHarvesterPriorityHarvestingPlugin + 1 );
   257 	}
   260 	}
   258 
   261 
   259 void CHarvesterImagePlugin::HarvestL( CHarvesterData* aHD )
   262 void CHarvesterImagePlugin::HarvestL( CHarvesterData* aHD )
   260 	{
   263 	{
   261 	WRITELOG( "CHarvesterImagePlugin::HarvestL()" );
   264 	WRITELOG( "CHarvesterImagePlugin::HarvestL()" );
   325         }
   328         }
   326 
   329 
   327     // Delete image data.
   330     // Delete image data.
   328     CleanupStack::PopAndDestroy( 2, fileData );
   331     CleanupStack::PopAndDestroy( 2, fileData );
   329 	}
   332 	}
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // CHarvesterImagePlugin::GetMimeType (from CHarvesterPlugin)
       
   336 // ---------------------------------------------------------------------------
       
   337 //    
       
   338 void CHarvesterImagePlugin::GetMimeType( const TDesC& aUri, TDes& aMimeType )
       
   339     {
       
   340     aMimeType.Zero();
       
   341     
       
   342     TPtrC ext;
       
   343     if( !MdsUtils::GetExt( aUri, ext ) )
       
   344         {
       
   345         return;
       
   346         }
       
   347 
       
   348     TMimeTypeMapping<TImageMetadataHandling> finder(ext);
       
   349     TLinearOrder< TMimeTypeMapping<TImageMetadataHandling> > cmp(
       
   350             TMimeTypeMapping<TImageMetadataHandling>::CompareFunction);
       
   351 
       
   352     const TInt pos = iMimeTypeMappings.FindInOrder( finder, cmp );
       
   353 
       
   354     if ( pos == KErrNotFound )
       
   355         {
       
   356         return;
       
   357         }
       
   358 
       
   359     aMimeType = iMimeTypeMappings[pos].iMimeType;
       
   360     }
   330 
   361 
   331 // ---------------------------------------------------------------------------
   362 // ---------------------------------------------------------------------------
   332 // GatherData
   363 // GatherData
   333 // ---------------------------------------------------------------------------
   364 // ---------------------------------------------------------------------------
   334 //    
   365 //    
   415     if( !aFileData.iExifSupported || err != KErrNone )
   446     if( !aFileData.iExifSupported || err != KErrNone )
   416         {
   447         {
   417         // Exif couldn't be found. Open the image with ICL decoder instead.
   448         // Exif couldn't be found. Open the image with ICL decoder instead.
   418         WRITELOG( "CHarvesterImagePlugin::GatherData() - Exif could not be read. Using ICL." );
   449         WRITELOG( "CHarvesterImagePlugin::GatherData() - Exif could not be read. Using ICL." );
   419 
   450 
   420         iDecoder->Reset();
       
   421 
       
   422         TPtr8 imageDataPtr = aFileData.iImageData->Des();
   451         TPtr8 imageDataPtr = aFileData.iImageData->Des();
   423         TRAP( err, iDecoder->OpenL(imageDataPtr, aFileData.iMime8,
   452         TRAP( err, iDecoder->OpenL(imageDataPtr, aFileData.iMime8,
   424                 CImageDecoder::TOptions( CImageDecoder::EPreferFastDecode | CImageDecoder::EOptionIgnoreExifMetaData ) ) );
   453                 CImageDecoder::TOptions( CImageDecoder::EPreferFastDecode | CImageDecoder::EOptionIgnoreExifMetaData ) ) );
   425         WRITELOG( "CHarvesterImagePlugin::GatherData() - Image decoder has opened the file." );
   454         WRITELOG( "CHarvesterImagePlugin::GatherData() - Image decoder has opened the file." );
   426 
   455 
   427         if ( err != KErrNone )
   456         if ( err != KErrNone )
   428             {
   457             {
   429             WRITELOG1( "CHarvesterImagePlugin::GatherData() - ERROR: Decoder could not open image data! Code %d", err );
   458             WRITELOG1( "CHarvesterImagePlugin::GatherData() - ERROR: Decoder could not open image data! Code %d", err );
       
   459             iDecoder->Reset();
   430             return KErrCompletion; // metadata item still can be created, thus KErrCompletion
   460             return KErrCompletion; // metadata item still can be created, thus KErrCompletion
   431             }
   461             }
   432 
   462 
   433         if ( !iDecoder->ValidDecoder() )
   463         if ( !iDecoder->ValidDecoder() )
   434         	{
   464         	{
   446 				TInt readStatus = iFs.ReadFileSection(
   476 				TInt readStatus = iFs.ReadFileSection(
   447 						*aFileData.iUri, aFileData.iImageDataSize, addPtr, additionalDataSize );
   477 						*aFileData.iUri, aFileData.iImageDataSize, addPtr, additionalDataSize );
   448 				if ( readStatus != KErrNone )
   478 				if ( readStatus != KErrNone )
   449 					{
   479 					{
   450 					CleanupStack::PopAndDestroy( additionalData );
   480 					CleanupStack::PopAndDestroy( additionalData );
       
   481 					iDecoder->Reset();
   451 					return KErrCompletion;
   482 					return KErrCompletion;
   452 					}
   483 					}
   453 				
   484 				
   454 				// append all remaining data to image decoder
   485 				// append all remaining data to image decoder
   455 				TRAP( err, iDecoder->AppendDataL( addPtr ) );
   486 				TRAP( err, iDecoder->AppendDataL( addPtr ) );
   461 				}
   492 				}
   462 
   493 
   463             if ( err || !iDecoder->ValidDecoder() )
   494             if ( err || !iDecoder->ValidDecoder() )
   464             	{
   495             	{
   465             	WRITELOG( "CHarvesterImagePlugin::GatherData() - ERROR: no valid decoder" );
   496             	WRITELOG( "CHarvesterImagePlugin::GatherData() - ERROR: no valid decoder" );
       
   497             	iDecoder->Reset();
   466             	return KErrCompletion; // metadata item still can be created, thus KErrCompletion
   498             	return KErrCompletion; // metadata item still can be created, thus KErrCompletion
   467             	}
   499             	}
   468             }
   500             }
   469 
   501 
   470         // Get image width, frame count, height and bits per pixel from image decoder.
   502         // Get image width, frame count, height and bits per pixel from image decoder.
   473         const TInt framecount = iDecoder->FrameCount();
   505         const TInt framecount = iDecoder->FrameCount();
   474         aFileData.iFrameCount = framecount;
   506         aFileData.iFrameCount = framecount;
   475         aFileData.iImageWidth = imageSize.iWidth;
   507         aFileData.iImageWidth = imageSize.iWidth;
   476         aFileData.iImageHeight = imageSize.iHeight;
   508         aFileData.iImageHeight = imageSize.iHeight;
   477         aFileData.iBitsPerPixel = info.iBitsPerPixel;
   509         aFileData.iBitsPerPixel = info.iBitsPerPixel;
       
   510         
       
   511         iDecoder->Reset();
   478         }
   512         }
   479 
   513 
   480     WRITELOG( "CHarvesterImagePlugin::GatherData() - end" );
   514     WRITELOG( "CHarvesterImagePlugin::GatherData() - end" );
   481 
   515 
   482 #ifdef _DEBUG
   516 #ifdef _DEBUG
   502 
   536 
   503 	TMimeTypeMapping<TImageMetadataHandling> finder(ext);
   537 	TMimeTypeMapping<TImageMetadataHandling> finder(ext);
   504 	TLinearOrder< TMimeTypeMapping<TImageMetadataHandling> > cmp(
   538 	TLinearOrder< TMimeTypeMapping<TImageMetadataHandling> > cmp(
   505 			TMimeTypeMapping<TImageMetadataHandling>::CompareFunction);
   539 			TMimeTypeMapping<TImageMetadataHandling>::CompareFunction);
   506 
   540 
   507 	TInt pos = iMimeTypeMappings.FindInOrder( finder, cmp );
   541 	const TInt pos = iMimeTypeMappings.FindInOrder( finder, cmp );
   508 
   542 
   509 	TImageMetadataHandling handler( EOtherHandling ); 
   543 	TImageMetadataHandling handler( EOtherHandling ); 
   510 
   544 
   511 	if ( pos != KErrNotFound )
   545 	if ( pos != KErrNotFound )
   512 		{
   546 		{
   606 
   640 
   607     TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset();
   641     TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset();
   608 
   642 
   609     TTime localModifiedDate = aFileData.iModified + timeOffsetSeconds;
   643     TTime localModifiedDate = aFileData.iModified + timeOffsetSeconds;
   610     
   644     
   611     // Object - Creation date
       
   612     if( ! mdeObject.Placeholder() )
   645     if( ! mdeObject.Placeholder() )
   613     	{
   646     	{
       
   647         // Object - Creation date
   614 	    if ( aFileData.iExifSupported && aHd.iDateOriginal8 )
   648 	    if ( aFileData.iExifSupported && aHd.iDateOriginal8 )
   615 	        {
   649 	        {
   616 	        TTime originalTime = iExifUtil->ConvertExifDateTimeToSymbianTimeL(
   650 	        TTime originalTime = iExifUtil->ConvertExifDateTimeToSymbianTimeL(
   617 	        		aHd.iDateOriginal8->Des() );
   651 	        		aHd.iDateOriginal8->Des() );
   618 	        CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iCreationDatePropertyDef, &originalTime, aIsAdd );
   652 	        CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iCreationDatePropertyDef, &originalTime, aIsAdd );
   619 	        }
   653 	        }
   620 	    else if ( aIsAdd )
   654 	    else if ( aIsAdd )
   621 	        {
   655 	        {
   622 	        CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iCreationDatePropertyDef, &localModifiedDate, aIsAdd );
   656 	        CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iCreationDatePropertyDef, &localModifiedDate, aIsAdd );
   623 	        }
   657 	        }
   624     	}
   658 	    
   625 
   659 	    // Object - last aFileData.iModified date
   626     // Object - last aFileData.iModified date
   660 	    CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iLastModifiedDatePropertyDef, &aFileData.iModified, aIsAdd );
   627     if( ! mdeObject.Placeholder() )
   661 	    
   628     	{
   662 	    // Object - Size
   629     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iLastModifiedDatePropertyDef, &aFileData.iModified, aIsAdd );
   663 	    CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iSizePropertyDef, &aFileData.iFileSize, aIsAdd );
       
   664 	    
       
   665 	    // Item Type
       
   666 	    CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iItemTypePropertyDef, &aFileData.iMime16, aIsAdd );
   630     	}
   667     	}
   631 
   668 
   632     if( aFileData.iJpeg )
   669     if( aFileData.iJpeg )
   633     	{
   670     	{
   634     	// Time offset
   671     	// Time offset
   635     	TInt16 timeOffsetMinutes = timeOffsetSeconds.Int() / 60;
   672     	TInt16 timeOffsetMinutes = timeOffsetSeconds.Int() / 60;
   636     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iTimeOffsetPropertyDef, &timeOffsetMinutes, aIsAdd );
   673     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iTimeOffsetPropertyDef, &timeOffsetMinutes, aIsAdd );
   637     	}
   674     	}
   638 
       
   639     // Object - Size
       
   640     if( ! mdeObject.Placeholder() )
       
   641     	{
       
   642     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iSizePropertyDef, &aFileData.iFileSize, aIsAdd );
       
   643     	}
       
   644     
       
   645     // Item Type
       
   646 	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iItemTypePropertyDef, &aFileData.iMime16, aIsAdd );
       
   647     
   675     
   648     // MediaObject - Width
   676     // MediaObject - Width
   649     if ( aFileData.iExifSupported )
   677     if ( aFileData.iExifSupported )
   650         {
   678         {
   651     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iWidthPropertyDef, &aHd.iImageWidthExif, aIsAdd );
   679     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iWidthPropertyDef, &aHd.iImageWidthExif, aIsAdd );