harvester/harvesterplugins/WMVPlugin/src/harvesterwmvplugin.cpp
changeset 0 c53acadfccc6
child 3 6752808b2036
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2007-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 metadata from wmv video file 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <caf/content.h>
       
    20 
       
    21 #include "mdsutils.h"
       
    22 #include "harvesterdata.h"
       
    23 #include "harvesterlog.h"
       
    24 #include "harvesterwmvplugin.h"
       
    25 #include <mdenamespacedef.h>
       
    26 #include <mdeobjectdef.h>
       
    27 #include "mdeobject.h"
       
    28 #include "mdetextproperty.h"
       
    29 #include "mdeobjectwrapper.h"
       
    30 
       
    31 CHarvesterWmvPluginPropertyDefs::CHarvesterWmvPluginPropertyDefs() : CBase()
       
    32 	{
       
    33 	}
       
    34 
       
    35 void CHarvesterWmvPluginPropertyDefs::ConstructL(CMdEObjectDef& aObjectDef)
       
    36 	{
       
    37 	CMdENamespaceDef& nsDef = aObjectDef.NamespaceDef();
       
    38 	
       
    39 	// Common property definitions
       
    40 	CMdEObjectDef& objectDef = nsDef.GetObjectDefL( MdeConstants::Object::KBaseObject );
       
    41 	iCreationDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KCreationDateProperty );
       
    42 	iLastModifiedDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty );
       
    43 	iSizePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty );
       
    44 	iItemTypePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty );
       
    45 	}
       
    46 
       
    47 CHarvesterWmvPluginPropertyDefs* CHarvesterWmvPluginPropertyDefs::NewL(CMdEObjectDef& aObjectDef)
       
    48 	{
       
    49 	CHarvesterWmvPluginPropertyDefs* self = 
       
    50 		new (ELeave) CHarvesterWmvPluginPropertyDefs();
       
    51 	CleanupStack::PushL( self );
       
    52 	self->ConstructL( aObjectDef );
       
    53 	CleanupStack::Pop( self );
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 // ======== MEMBER FUNCTIONS ========
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Constructor
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CHarvesterWMVPlugin* CHarvesterWMVPlugin::NewL()
       
    64     {
       
    65     CHarvesterWMVPlugin* self = new(ELeave) CHarvesterWMVPlugin();
       
    66     CleanupStack::PushL(self);
       
    67     self->ConstructL();
       
    68     CleanupStack::Pop(self);
       
    69 
       
    70     return self;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // Destructor
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CHarvesterWMVPlugin::~CHarvesterWMVPlugin()
       
    78     {
       
    79     WRITELOG( "CHarvesterWMVPlugin::~CHarvesterWMVPlugin()" );
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // Harvest file
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CHarvesterWMVPlugin::HarvestL( CHarvesterData* aHD )    
       
    87     {
       
    88     WRITELOG( "CHarvesterWMVPlugin::Harvest()" );
       
    89     CMdEObject& mdeObject = aHD->MdeObject();
       
    90     
       
    91     CHarvesterWmvClipDetails* clipDetails = CHarvesterWmvClipDetails::NewL();
       
    92     CleanupStack::PushL( clipDetails );
       
    93     
       
    94     TRAPD( error, GatherDataL( mdeObject, *clipDetails ) );
       
    95     if ( error == KErrNone || error == KErrCompletion )
       
    96     	{
       
    97     	TBool isNewObject( mdeObject.Id() == 0 );
       
    98         
       
    99         if ( isNewObject || mdeObject.Placeholder() )
       
   100             {
       
   101             TRAP( error, HandleObjectPropertiesL( *aHD, *clipDetails, ETrue ) );
       
   102             mdeObject.SetPlaceholder( EFalse );
       
   103             }
       
   104         else
       
   105             {
       
   106             TRAP( error, HandleObjectPropertiesL( *aHD, *clipDetails, EFalse ) );
       
   107             }
       
   108 
       
   109         if ( error != KErrNone )
       
   110             {
       
   111             WRITELOG1( "CHarvesterWMVPlugin::HarvestL() - Handling object failed: ", error );
       
   112             }
       
   113     	}
       
   114     else
       
   115         {
       
   116         TInt convertedError = KErrNone;
       
   117         MdsUtils::ConvertTrapError( error, convertedError );
       
   118         aHD->SetErrorCode( convertedError );
       
   119         }
       
   120     
       
   121     CleanupStack::PopAndDestroy( clipDetails );
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // Default constructor
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 CHarvesterWMVPlugin::CHarvesterWMVPlugin() : CHarvesterPlugin(), iPropDefs( NULL )
       
   129     {
       
   130     }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // 2nd phase constructor
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CHarvesterWMVPlugin::ConstructL()
       
   137     {
       
   138     WRITELOG( "CHarvesterWMVPlugin::ConstructL()" );
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // GatherDataL
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CHarvesterWMVPlugin::GatherDataL( CMdEObject& aMetadataObject, CHarvesterWmvClipDetails& aClipDetails )
       
   146     {
       
   147     WRITELOG( "CHarvesterWMVPlugin::GatherDataL()" );
       
   148        
       
   149     const TDesC& uri = aMetadataObject.Uri();
       
   150 
       
   151     TInt error ( KErrNone );
       
   152     TEntry* entry = new (ELeave) TEntry();
       
   153     CleanupStack::PushL( entry );
       
   154 
       
   155     User::LeaveIfError( iFs.Entry( uri, *entry ) );
       
   156 
       
   157     aClipDetails.iModifiedDate = entry->iModified;
       
   158     aClipDetails.iFileSize = (TUint)entry->iSize;
       
   159     
       
   160     CleanupStack::PopAndDestroy( entry );
       
   161     
       
   162     ContentAccess::CContent* content = ContentAccess::CContent::NewLC( uri );
       
   163 
       
   164     //Mime type check
       
   165     error = content->GetStringAttribute( ContentAccess::EMimeType, aClipDetails.iMimeType );
       
   166     if (  error != KErrNone )
       
   167         {
       
   168         WRITELOG( "CHarvesterWMVPlugin - Could not resolve mime type, leave!" );
       
   169         User::Leave( KErrNotSupported );
       
   170         }
       
   171 
       
   172     CleanupStack::PopAndDestroy( content );  
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // Handle object properties
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void CHarvesterWMVPlugin::HandleObjectPropertiesL( 
       
   180     CHarvesterData& aHD,
       
   181     CHarvesterWmvClipDetails& aClipDetails,
       
   182     TBool aIsAdd )
       
   183     {
       
   184     WRITELOG( "CHarvesterWMVPlugin::HandleObjectPropertiesL()" );
       
   185     
       
   186     CMdEObject& mdeObject = aHD.MdeObject();
       
   187     
       
   188     if( !iPropDefs )
       
   189 		{
       
   190 		CMdEObjectDef& objectDef = mdeObject.Def();
       
   191 		iPropDefs = CHarvesterWmvPluginPropertyDefs::NewL( objectDef );
       
   192 		}
       
   193     
       
   194     if( ! mdeObject.Placeholder() )
       
   195     	{
       
   196         // Creation date
       
   197     	TTimeIntervalSeconds timeOffset = User::UTCOffset();
       
   198     	TTime localModifiedDate = aClipDetails.iModifiedDate + timeOffset;
       
   199     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   200     			*iPropDefs->iCreationDatePropertyDef, &localModifiedDate, aIsAdd );
       
   201     	// Last modified date
       
   202     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   203     			*iPropDefs->iLastModifiedDatePropertyDef, &aClipDetails.iModifiedDate, aIsAdd );
       
   204     	// File size
       
   205     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   206     			*iPropDefs->iSizePropertyDef, &aClipDetails.iFileSize, aIsAdd );
       
   207     	}
       
   208 
       
   209     // Mime Type
       
   210     CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
       
   211     		*iPropDefs->iItemTypePropertyDef, &aClipDetails.iMimeType, aIsAdd );
       
   212     }