harvester/harvesterplugins/AudioPlugin/src/harvesteraudioplugin.cpp
changeset 54 a3cc46f37772
parent 28 c461c7fa72c2
equal deleted inserted replaced
36:aa5a574040a4 54:a3cc46f37772
    23 #include <mdeobject.h>
    23 #include <mdeobject.h>
    24 #include <centralrepository.h>
    24 #include <centralrepository.h>
    25 #include <caf/caf.h>
    25 #include <caf/caf.h>
    26 #include <pathinfo.h>
    26 #include <pathinfo.h>
    27 
    27 
       
    28 #include "harvestercommon.h"
    28 #include "harvesteraudioplugin.h"
    29 #include "harvesteraudioplugin.h"
    29 #include "harvesteraudiopluginutils.h"
    30 #include "harvesteraudiopluginutils.h"
    30 #include "mdsutils.h"
    31 #include "mdsutils.h"
    31 #include "mdscommoninternal.h"
    32 #include "mdscommoninternal.h"
    32 
    33 
    34 
    35 
    35 const TInt KMimeLength( 10 );
    36 const TInt KMimeLength( 10 );
    36 const TUid KHarvesterRepoUid = { 0x200009FE };
    37 const TUid KHarvesterRepoUid = { 0x200009FE };
    37 const TUint32 KEnableAlbumArtHarvest = 0x00090001;
    38 const TUint32 KEnableAlbumArtHarvest = 0x00090001;
    38 
    39 
    39 CHarvesterAudioPluginPropertyDefs::CHarvesterAudioPluginPropertyDefs() : CBase()
    40 CHarvesterAudioPluginPropertyDefs::CHarvesterAudioPluginPropertyDefs() : CBase(),
       
    41     iCreationDatePropertyDef( NULL )
    40 	{
    42 	{
    41 	}
    43 	}
    42 
    44 
    43 void CHarvesterAudioPluginPropertyDefs::ConstructL(CMdEObjectDef& aObjectDef)
    45 void CHarvesterAudioPluginPropertyDefs::ConstructL(CMdEObjectDef& aObjectDef)
    44 	{
    46 	{
    45 	CMdENamespaceDef& nsDef = aObjectDef.NamespaceDef();
    47     SetByObjectDefL( aObjectDef );
    46 
    48 	}
    47 	// Common property definitions
    49 
    48 	CMdEObjectDef& objectDef = nsDef.GetObjectDefL( MdeConstants::Object::KBaseObject );
    50 CHarvesterAudioPluginPropertyDefs* CHarvesterAudioPluginPropertyDefs::NewL()
    49 	iCreationDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KCreationDateProperty );
    51     {
    50 	iLastModifiedDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty );
    52     CHarvesterAudioPluginPropertyDefs* self = 
    51 	iSizePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty );
    53         new (ELeave) CHarvesterAudioPluginPropertyDefs();
    52 	iItemTypePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty );
    54     return self;
    53 	iTitlePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty );
    55     }
       
    56 
       
    57 void CHarvesterAudioPluginPropertyDefs::SetByObjectDefL(CMdEObjectDef& aObjectDef)
       
    58     {
       
    59     CMdENamespaceDef& nsDef = aObjectDef.NamespaceDef();
       
    60 
       
    61     // Common property definitions
       
    62     CMdEObjectDef& objectDef = nsDef.GetObjectDefL( MdeConstants::Object::KBaseObject );
       
    63     iCreationDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KCreationDateProperty );
       
    64     iLastModifiedDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty );
       
    65     iSizePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty );
       
    66     iItemTypePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty );
       
    67     iTitlePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty );
    54     iTimeOffsetPropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KTimeOffsetProperty );
    68     iTimeOffsetPropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KTimeOffsetProperty );
    55     iDefaultFolderPropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KInDefaultFolder );
    69     iDefaultFolderPropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KInDefaultFolder );
    56 
    70 
    57 	// Media property definitions
    71     // Media property definitions
    58 	CMdEObjectDef& mediaDef = nsDef.GetObjectDefL( MdeConstants::MediaObject::KMediaObject );
    72     CMdEObjectDef& mediaDef = nsDef.GetObjectDefL( MdeConstants::MediaObject::KMediaObject );
    59 	iRatingPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KRatingProperty );
    73     iRatingPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KRatingProperty );
    60 	iGenrePropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KGenreProperty );
    74     iGenrePropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KGenreProperty );
    61 	iArtistPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KArtistProperty );
    75     iArtistPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KArtistProperty );
    62 	iDurationPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDurationProperty );
    76     iDurationPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDurationProperty );
    63 	iCopyrightPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KCopyrightProperty );
    77     iCopyrightPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KCopyrightProperty );
    64 	iTrackPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KTrackProperty );
    78     iTrackPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KTrackProperty );
    65 	iThumbnailPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KThumbnailPresentProperty );
    79     iThumbnailPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KThumbnailPresentProperty );
    66 	iDatePropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KReleaseDateProperty );
    80     iDatePropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KReleaseDateProperty );
    67     iDrmPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDRMProperty );
    81     iDrmPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDRMProperty );
    68 
    82 
    69 	// Audio property definitions
    83     // Audio property definitions
    70 	CMdEObjectDef& audioDef = nsDef.GetObjectDefL( MdeConstants::Audio::KAudioObject );
    84     CMdEObjectDef& audioDef = nsDef.GetObjectDefL( MdeConstants::Audio::KAudioObject );
    71 	iAlbumPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KAlbumProperty );
    85     iAlbumPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KAlbumProperty );
    72 	iComposerPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KComposerProperty );
    86     iComposerPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KComposerProperty );
    73 	iOriginalArtistPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KOriginalArtistProperty );
    87     iOriginalArtistPropertyDef = &audioDef.GetPropertyDefL( MdeConstants::Audio::KOriginalArtistProperty );
    74 	}
    88     }
    75 
       
    76 CHarvesterAudioPluginPropertyDefs* CHarvesterAudioPluginPropertyDefs::NewL(CMdEObjectDef& aObjectDef)
       
    77 	{
       
    78 	CHarvesterAudioPluginPropertyDefs* self = 
       
    79 		new (ELeave) CHarvesterAudioPluginPropertyDefs();
       
    80 	CleanupStack::PushL( self );
       
    81 	self->ConstructL( aObjectDef );
       
    82 	CleanupStack::Pop( self );
       
    83 	return self;
       
    84 	}
       
    85 
    89 
    86 using namespace MdeConstants;
    90 using namespace MdeConstants;
    87 
    91 
    88 // ---------------------------------------------------------------------------
    92 // ---------------------------------------------------------------------------
    89 // CHarvesterAudioPlugin::CHarvesterAudioPlugin
    93 // CHarvesterAudioPlugin::CHarvesterAudioPlugin
   116 CHarvesterAudioPlugin::~CHarvesterAudioPlugin()
   120 CHarvesterAudioPlugin::~CHarvesterAudioPlugin()
   117 	{
   121 	{
   118 	WRITELOG( "CHarvesterAudioPlugin::~CHarvesterAudioPlugin()" );
   122 	WRITELOG( "CHarvesterAudioPlugin::~CHarvesterAudioPlugin()" );
   119 	
   123 	
   120 	delete iAudioParser;
   124 	delete iAudioParser;
       
   125 	iAudioParser = NULL;
   121 	delete iPropDefs;
   126 	delete iPropDefs;
       
   127 	iPropDefs = NULL;
   122 	delete iTNM;
   128 	delete iTNM;
       
   129 	iTNM = NULL;
   123 	
   130 	
   124 	delete iPhoneSoundsPath;
   131 	delete iPhoneSoundsPath;
       
   132 	iPhoneSoundsPath = NULL;
   125 	delete iMmcSoundsPath;
   133 	delete iMmcSoundsPath;
       
   134 	iMmcSoundsPath = NULL;
   126 	}
   135 	}
   127 
   136 
   128 // ---------------------------------------------------------------------------
   137 // ---------------------------------------------------------------------------
   129 // CHarvesterAudioPlugin::ConstructL
   138 // CHarvesterAudioPlugin::ConstructL
   130 // ---------------------------------------------------------------------------
   139 // ---------------------------------------------------------------------------
   142     
   151     
   143     if( iHarvestAlbumArt )
   152     if( iHarvestAlbumArt )
   144         {
   153         {
   145         TRAP_IGNORE( iTNM = CThumbnailManager::NewL( *this ) );
   154         TRAP_IGNORE( iTNM = CThumbnailManager::NewL( *this ) );
   146         }
   155         }
   147     
   156 		
       
   157     iPropDefs = CHarvesterAudioPluginPropertyDefs::NewL();
       
   158     
       
   159     SetPriority( KHarvesterPriorityHarvestingPlugin - 2 );
   148 	
   160 	
   149     TFileName sounds = PathInfo::SoundsPath();
   161     TFileName sounds = PathInfo::SoundsPath();
   150     
   162     
   151     TFileName phonePath = PathInfo::PhoneMemoryRootPath();
   163     TFileName phonePath = PathInfo::PhoneMemoryRootPath();
   152     phonePath.Append( sounds );
   164     phonePath.Append( sounds );
   285         }
   297         }
   286     
   298     
   287     TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset();
   299     TTimeIntervalSeconds timeOffsetSeconds = User::UTCOffset();
   288     TTime localModifiedDate = entry.iModified + timeOffsetSeconds;
   300     TTime localModifiedDate = entry.iModified + timeOffsetSeconds;
   289 	
   301 	
   290 	if( !iPropDefs )
   302 	InitPropDefsL( mdeObject.Def() );
   291 		{
       
   292 		CMdEObjectDef& objectDef = mdeObject.Def();
       
   293 		iPropDefs = CHarvesterAudioPluginPropertyDefs::NewL( objectDef );
       
   294 		// Prefetch max text lengt for validity checking
       
   295 		iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
       
   296 		}
       
   297 	
   303 	
   298 	CMdeObjectWrapper::HandleObjectPropertyL(
   304 	CMdeObjectWrapper::HandleObjectPropertyL(
   299                  mdeObject, *iPropDefs->iCreationDatePropertyDef, &localModifiedDate, aIsAdd );
   305                  mdeObject, *iPropDefs->iCreationDatePropertyDef, &localModifiedDate, aIsAdd );
   300 
   306 
   301 	CMdeObjectWrapper::HandleObjectPropertyL(
   307 	CMdeObjectWrapper::HandleObjectPropertyL(
   320     const TMimeTypeMapping<TAudioMetadataHandling>* mapping = 
   326     const TMimeTypeMapping<TAudioMetadataHandling>* mapping = 
   321     	iAudioParser->ParseMimeType( mdeObject.Uri() );
   327     	iAudioParser->ParseMimeType( mdeObject.Uri() );
   322     
   328     
   323     if ( mapping && !mdeObject.Placeholder() )
   329     if ( mapping && !mdeObject.Placeholder() )
   324         {
   330         {
   325     	if( !iPropDefs )
   331         InitPropDefsL( mdeObject.Def() );
   326     		{
       
   327     		CMdEObjectDef& objectDef = mdeObject.Def();
       
   328     		iPropDefs = CHarvesterAudioPluginPropertyDefs::NewL( objectDef );
       
   329     		// Prefetch max text lengt for validity checking
       
   330     		iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
       
   331     		}
       
   332         
   332         
   333     	CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
   333     	CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
   334     			*iPropDefs->iItemTypePropertyDef, (TAny*)&(mapping->iMimeType), aIsAdd );
   334     			*iPropDefs->iItemTypePropertyDef, (TAny*)&(mapping->iMimeType), aIsAdd );
   335         }
   335         }
   336     
   336     
   352 #endif
   352 #endif
   353     
   353     
   354     CMdEObject& mdeObject = aHD->MdeObject();
   354     CMdEObject& mdeObject = aHD->MdeObject();
   355     const TDesC& uri = mdeObject.Uri();
   355     const TDesC& uri = mdeObject.Uri();
   356  
   356  
   357     if( !iPropDefs )
   357     InitPropDefsL( mdeObject.Def() );
   358         {
       
   359         CMdEObjectDef& audioObjectDef = mdeObject.Def();
       
   360         iPropDefs = CHarvesterAudioPluginPropertyDefs::NewL( audioObjectDef );
       
   361         // Prefetch max text lengt for validity checking
       
   362         iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
       
   363         }
       
   364 
   358 
   365     TBool possiblyProtectedContent( EFalse );
   359     TBool possiblyProtectedContent( EFalse );
   366     if( aMimeType.Length() > 0 )
   360     if( aMimeType.Length() > 0 )
   367         {
   361         {
   368         if( aMimeType == KMimeTypeWma )
   362         if( aMimeType == KMimeTypeWma )
   532         CThumbnailObjectSource* tnmSource = CThumbnailObjectSource::NewL( jpegBuf, mimeType, uri );
   526         CThumbnailObjectSource* tnmSource = CThumbnailObjectSource::NewL( jpegBuf, mimeType, uri );
   533         // Ownership of buffer is transferred to Thumbnail Manager
   527         // Ownership of buffer is transferred to Thumbnail Manager
   534         CleanupStack::Pop(); // jpegBuf
   528         CleanupStack::Pop(); // jpegBuf
   535         iTNM->CreateThumbnails( *tnmSource );
   529         iTNM->CreateThumbnails( *tnmSource );
   536         delete tnmSource;
   530         delete tnmSource;
       
   531         tnmSource = NULL;
   537         TBool thumbnailPresent( ETrue );
   532         TBool thumbnailPresent( ETrue );
   538         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
   533         CMdeObjectWrapper::HandleObjectPropertyL( mdeObject, 
   539                           *iPropDefs->iThumbnailPropertyDef, &thumbnailPresent, aIsAdd );
   534                           *iPropDefs->iThumbnailPropertyDef, &thumbnailPresent, aIsAdd );
   540         }
   535         }
   541     else if( iHarvestAlbumArt && iTNM )
   536     else if( iHarvestAlbumArt && iTNM )
   551     dStop.UniversalTime();
   546     dStop.UniversalTime();
   552     WRITELOG1( "CHarvesterAudioPlugin::GetMusicPropertiesL start %d us", (TInt)dStop.MicroSecondsFrom(dStart).Int64() );
   547     WRITELOG1( "CHarvesterAudioPlugin::GetMusicPropertiesL start %d us", (TInt)dStop.MicroSecondsFrom(dStart).Int64() );
   553 #endif   
   548 #endif   
   554     }
   549     }
   555 
   550 
       
   551 void CHarvesterAudioPlugin::InitPropDefsL(CMdEObjectDef& aObjectDef)
       
   552     {
       
   553     if( !iPropDefs->iCreationDatePropertyDef )
       
   554         {
       
   555         iPropDefs->SetByObjectDefL( aObjectDef );
       
   556         // Prefetch max text lengt for validity checking
       
   557         iMaxTextLength = iPropDefs->iCopyrightPropertyDef->MaxTextLengthL();
       
   558         }
       
   559     }
       
   560 
   556 // End of file
   561 // End of file
   557 
   562