harvester/harvesterplugins/OMADRMPlugin/src/harvesteromadrmplugin.cpp
changeset 0 c53acadfccc6
child 8 6752808b2036
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Harvests meta data from oma drm file.*
       
    15 */
       
    16 
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <caf/caf.h>
       
    20 
       
    21 #include "mdsutils.h"
       
    22 #include "harvesteromadrmplugin.h"
       
    23 #include "harvesterlog.h"
       
    24 #include "mdeobjectwrapper.h"
       
    25 #include <harvesterdata.h>
       
    26 
       
    27 #include <mdenamespacedef.h>
       
    28 #include <mdeobjectdef.h>
       
    29 #include <mdeobject.h>
       
    30 #include <mdetextproperty.h>
       
    31 #include <mdenamespacedef.h>
       
    32 #include <mdeconstants.h>
       
    33 
       
    34 _LIT(KImage, "Image");
       
    35 _LIT(KVideo, "Video");
       
    36 _LIT(KAudio, "Audio");
       
    37 _LIT(KRmMimetype, "realmedia");
       
    38 
       
    39 _LIT( KSvgMime, "image/svg+xml" );
       
    40 
       
    41 CHarvesterOmaDrmPluginPropertyDefs::CHarvesterOmaDrmPluginPropertyDefs() : CBase()
       
    42 	{
       
    43 	}
       
    44 
       
    45 void CHarvesterOmaDrmPluginPropertyDefs::ConstructL(CMdEObjectDef& aObjectDef)
       
    46 	{
       
    47 	CMdENamespaceDef& nsDef = aObjectDef.NamespaceDef();
       
    48 	
       
    49 	// Common property definitions
       
    50 	CMdEObjectDef& objectDef = nsDef.GetObjectDefL( MdeConstants::Object::KBaseObject );
       
    51 	iCreationDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KCreationDateProperty );
       
    52 	iLastModifiedDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty );
       
    53 	iSizePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty );
       
    54 	iItemTypePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty );
       
    55 	iTitlePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty );
       
    56 
       
    57 	CMdEObjectDef& mediaDef = nsDef.GetObjectDefL( MdeConstants::MediaObject::KMediaObject );
       
    58 	iDrmPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDRMProperty );
       
    59 	iDescriptionPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDescriptionProperty );
       
    60 	iAuthorPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KAuthorProperty );
       
    61 	}
       
    62 
       
    63 CHarvesterOmaDrmPluginPropertyDefs* CHarvesterOmaDrmPluginPropertyDefs::NewL(CMdEObjectDef& aObjectDef)
       
    64 	{
       
    65 	CHarvesterOmaDrmPluginPropertyDefs* self = 
       
    66 		new (ELeave) CHarvesterOmaDrmPluginPropertyDefs();
       
    67 	CleanupStack::PushL( self );
       
    68 	self->ConstructL( aObjectDef );
       
    69 	CleanupStack::Pop( self );
       
    70 	return self;
       
    71 	}
       
    72 
       
    73 /**
       
    74 * Default constructor
       
    75 */
       
    76 CHarvesterOMADRMPlugin::CHarvesterOMADRMPlugin() : CHarvesterPlugin()
       
    77 	{
       
    78 	WRITELOG("CHarvesterOMADRMPlugin::CHarvesterOMADRMPlugin()");
       
    79 	}
       
    80 
       
    81 /**
       
    82 * Construction
       
    83 * @return Harvester image plugin
       
    84 */
       
    85 CHarvesterOMADRMPlugin* CHarvesterOMADRMPlugin::NewL()
       
    86 	{
       
    87 	WRITELOG("CHarvesterOMADRMPlugin::NewL()");
       
    88 	CHarvesterOMADRMPlugin* self = new(ELeave) CHarvesterOMADRMPlugin();
       
    89 	CleanupStack::PushL(self);
       
    90 	self->ConstructL();
       
    91 	CleanupStack::Pop(self);
       
    92 	
       
    93 	return self;
       
    94 	}
       
    95 
       
    96 /**
       
    97 * Destruction
       
    98 */
       
    99 CHarvesterOMADRMPlugin::~CHarvesterOMADRMPlugin()
       
   100 	{
       
   101 	WRITELOG("CHarvesterOMADRMPlugin::~CHarvesterOMADRMPlugin()");
       
   102 	
       
   103 	delete iPropDefs;
       
   104 	}
       
   105 
       
   106 /**
       
   107 * 2nd phase constructor
       
   108 */
       
   109 void CHarvesterOMADRMPlugin::ConstructL()
       
   110 	{
       
   111 	WRITELOG( "CHarvesterOMADRMPlugin::ConstructL()" );
       
   112 	}
       
   113 
       
   114 void CHarvesterOMADRMPlugin::HarvestL( CHarvesterData* aHD )
       
   115 	{
       
   116     CMdEObject& mdeObject = aHD->MdeObject();
       
   117     CDRMHarvestData* fileData = CDRMHarvestData::NewL();
       
   118     CleanupStack::PushL( fileData );
       
   119 
       
   120     TRAPD( error, GatherDataL( mdeObject, *fileData ) );
       
   121     if ( error == KErrNone || error == KErrCompletion )
       
   122     	{
       
   123         TBool isNewObject( mdeObject.Id() == 0 );
       
   124         
       
   125         if ( isNewObject || mdeObject.Placeholder() )
       
   126             {
       
   127             TRAP( error, HandleObjectPropertiesL( *aHD, *fileData, ETrue ) );
       
   128             mdeObject.SetPlaceholder( EFalse );
       
   129             }
       
   130         else
       
   131             {
       
   132             TRAP( error, HandleObjectPropertiesL( *aHD, *fileData, EFalse ) );
       
   133             }
       
   134 
       
   135         if ( error != KErrNone )
       
   136             {
       
   137             WRITELOG1( "CHarvesterOMADRMPlugin::HarvestL() - Handling object failed: ", error );
       
   138             }
       
   139     	}
       
   140     else	
       
   141         {
       
   142         WRITELOG1( "CHarvesterOMADRMPlugin::HarvestL() - TRAP error: %d", error );
       
   143         TInt convertedError = KErrNone;
       
   144         MdsUtils::ConvertTrapError( error, convertedError );
       
   145         aHD->SetErrorCode( convertedError );
       
   146         }
       
   147 
       
   148     CleanupStack::PopAndDestroy( fileData );
       
   149 	}
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // GatherDataL
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CHarvesterOMADRMPlugin::GatherDataL( CMdEObject& aMetadataObject,
       
   156 		CDRMHarvestData& aVHD )
       
   157     {
       
   158     WRITELOG( "CHarvesterOMADRMPlugin::GatherDataL" );
       
   159     
       
   160     TEntry* entry = new (ELeave) TEntry();
       
   161     CleanupStack::PushL( entry );
       
   162     
       
   163     const TDesC& uri = aMetadataObject.Uri();
       
   164     User::LeaveIfError( iFs.Entry( uri, *entry ) );
       
   165     
       
   166     aVHD.iModified = entry->iModified;
       
   167     aVHD.iFileSize = (TUint)entry->iSize;
       
   168     CleanupStack::PopAndDestroy( entry );
       
   169     
       
   170     ContentAccess::CContent* content = NULL;
       
   171     content = ContentAccess::CContent::NewLC( uri );
       
   172     
       
   173     ContentAccess::RStringAttributeSet attrSet;
       
   174     CleanupClosePushL( attrSet );
       
   175     
       
   176     attrSet.AddL( ContentAccess::EDescription );
       
   177     attrSet.AddL( ContentAccess::EMimeType );
       
   178     attrSet.AddL( ContentAccess::ETitle );
       
   179     attrSet.AddL( ContentAccess::EAuthor );
       
   180     
       
   181     User::LeaveIfError( content->GetStringAttributeSet(attrSet) );
       
   182     
       
   183     TInt err = attrSet.GetValue( ContentAccess::EDescription, aVHD.iDescription );
       
   184     if ( err != KErrNone)
       
   185         {
       
   186         WRITELOG1( "CHarvesterOMADRMPlugin::GatherDataL - ERROR: getting description failed %d", err );
       
   187         }
       
   188         
       
   189     if ( aVHD.iDescription.Length() <= 0 )
       
   190         {
       
   191         WRITELOG( "CHarvesterOMADRMPlugin::GatherDataL - no description" );
       
   192         }
       
   193     
       
   194     err = attrSet.GetValue( ContentAccess::EMimeType, aVHD.iMimetype );
       
   195     if ( err != KErrNone)
       
   196         {
       
   197         WRITELOG1( "CHarvesterOMADRMPlugin::GatherDataL - ERROR: getting mimetype failed %d", err );
       
   198         }
       
   199         
       
   200     if ( aVHD.iMimetype.Length() <= 0 )
       
   201         {
       
   202         WRITELOG( "CHarvesterOMADRMPlugin::GatherDataL - no mimetype" );
       
   203         }
       
   204     
       
   205     err = attrSet.GetValue( ContentAccess::ETitle, aVHD.iTitle );
       
   206     if ( err != KErrNone)
       
   207         {
       
   208         WRITELOG1( "CHarvesterOMADRMPlugin::GatherDataL - ERROR: getting title failed %d", err );
       
   209         }
       
   210         
       
   211     if ( aVHD.iTitle.Length() <= 0 )
       
   212         {
       
   213         WRITELOG( "CHarvesterOMADRMPlugin::GatherDataL - no title" );
       
   214         }
       
   215     
       
   216     err = attrSet.GetValue( ContentAccess::EAuthor, aVHD.iAuthor );
       
   217     if ( err != KErrNone)
       
   218         {
       
   219         WRITELOG1( "CHarvesterOMADRMPlugin::GatherDataL - ERROR: getting author failed %d", err );
       
   220         }
       
   221         
       
   222     if ( aVHD.iAuthor.Length() <= 0 )
       
   223         {
       
   224         WRITELOG( "CHarvesterOMADRMPlugin::GatherDataL - no author" );
       
   225         }
       
   226     
       
   227     err = content->GetAttribute( ContentAccess::EIsProtected, aVHD.iDrmProtected );
       
   228     if ( err != KErrNone)
       
   229         {
       
   230         WRITELOG1( "CHarvesterOMADRMPlugin::GatherDataL - ERROR: getting protection info failed %d", err );
       
   231         }
       
   232         
       
   233     CleanupStack::PopAndDestroy( 2, content );
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // HandleNewObjectL
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CHarvesterOMADRMPlugin::HandleObjectPropertiesL(
       
   241 		CHarvesterData& aHD,
       
   242 		CDRMHarvestData& aVHD,
       
   243 		TBool aIsAdd )
       
   244     {
       
   245     WRITELOG("CHarvesterOMADRMPlugin - HandleNewObject ");
       
   246     CMdEObject& mdeObject = aHD.MdeObject();
       
   247 
       
   248     if( !iPropDefs )
       
   249     	{
       
   250     	CMdEObjectDef& objectDef = mdeObject.Def();
       
   251     	iPropDefs = CHarvesterOmaDrmPluginPropertyDefs::NewL( objectDef );
       
   252     	}
       
   253     
       
   254     TTimeIntervalSeconds timeOffset = User::UTCOffset();
       
   255     
       
   256     if( ! mdeObject.Placeholder() )
       
   257     	{
       
   258     	// Creation date
       
   259     	TTime localTime = aVHD.iModified + timeOffset;
       
   260     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   261     			*iPropDefs->iCreationDatePropertyDef, &localTime, aIsAdd );
       
   262     	// Last modified date
       
   263     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   264     			*iPropDefs->iLastModifiedDatePropertyDef, &aVHD.iModified, aIsAdd );
       
   265     	// File size
       
   266     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   267     			*iPropDefs->iSizePropertyDef, &aVHD.iFileSize, aIsAdd );
       
   268     	}
       
   269     // DRM protection
       
   270     CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   271     		*iPropDefs->iDrmPropertyDef, &aVHD.iDrmProtected, aIsAdd );
       
   272     
       
   273     // Item Type
       
   274     if(aVHD.iMimetype.Length() > 0)
       
   275     	{
       
   276     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   277     			*iPropDefs->iItemTypePropertyDef, &aVHD.iMimetype, aIsAdd );
       
   278     	}
       
   279     // Title (is set from URI by default)
       
   280     if(aVHD.iTitle.Length() > 0)
       
   281     	{
       
   282     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   283     			*iPropDefs->iTitlePropertyDef, &aVHD.iTitle, EFalse );
       
   284     	}
       
   285     // Description
       
   286     if(aVHD.iDescription.Length() > 0)
       
   287     	{
       
   288     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   289     			*iPropDefs->iDescriptionPropertyDef, &aVHD.iDescription, aIsAdd );
       
   290     	}   
       
   291     // Author
       
   292     if(aVHD.iAuthor.Length() > 0)
       
   293     	{
       
   294     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   295     			*iPropDefs->iAuthorPropertyDef, &aVHD.iAuthor, aIsAdd );
       
   296     	}
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // ChangeObjectType
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 void CHarvesterOMADRMPlugin::GetObjectType( const TDesC& aUri, TDes& aObjectType )
       
   304 	{
       
   305 	ContentAccess::CContent* content = NULL;
       
   306     TBuf16<KMaxDataTypeLength> mime;
       
   307     
       
   308 	TRAPD( err, content = ContentAccess::CContent::NewL( aUri ) );
       
   309 	if (err == KErrNone) 
       
   310 		{
       
   311 		err = content->GetStringAttribute( ContentAccess::EMimeType, mime );
       
   312 		delete content;
       
   313 		}
       
   314     
       
   315 	if( mime == KSvgMime )
       
   316 	    {
       
   317 	    WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - ERROR: mimetype %S. Not supported", &mime );
       
   318 	     aObjectType.Zero();
       
   319 	     return;
       
   320 	    }
       
   321 	
       
   322     if( err == KErrNone )
       
   323     	{
       
   324 	    TPtrC ptrImage( KImage );
       
   325 		if( MdsUtils::Find( mime, ptrImage ) != KErrNotFound )
       
   326 			{
       
   327 			WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - mimetype %S. Object type changed to Image", &mime );
       
   328 			aObjectType.Copy( KImage );
       
   329 			return;
       
   330 			}
       
   331 		
       
   332 		TPtrC ptrVideo( KVideo );
       
   333 		if( MdsUtils::Find( mime, ptrVideo ) != KErrNotFound )
       
   334 			{
       
   335 			WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - mimetype %S. Object type changed to Video", &mime );
       
   336 			aObjectType.Copy( KVideo );
       
   337 			return;
       
   338 			}
       
   339 		
       
   340         TPtrC ptrAudio( KAudio );
       
   341         if( MdsUtils::Find( mime, ptrAudio ) != KErrNotFound )
       
   342             {
       
   343             WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - mimetype %S. Object type changed to Audio", &mime );
       
   344             aObjectType.Copy( KAudio );
       
   345             return;
       
   346             }		
       
   347 		
       
   348 		TPtrC ptrRm( KRmMimetype );
       
   349 		if( MdsUtils::Find( mime, ptrRm ) != KErrNotFound )
       
   350 			{
       
   351 			WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - mimetype %S. Object type changed to Rm", &mime );
       
   352 			aObjectType.Copy( KVideo );
       
   353 			return;
       
   354 			}
       
   355     	}
       
   356     
       
   357 	WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - ERROR: mimetype %S. No object type found", &mime );
       
   358 	aObjectType.Zero();
       
   359 	}