harvester/harvesterplugins/OMADRMPlugin/src/harvesteromadrmplugin.cpp
changeset 28 c461c7fa72c2
parent 25 8e4539ab1889
child 40 910a23996aa0
child 45 a93990e5815e
child 54 a3cc46f37772
equal deleted inserted replaced
25:8e4539ab1889 28:c461c7fa72c2
    15 */
    15 */
    16 
    16 
    17 
    17 
    18 #include <e32base.h>
    18 #include <e32base.h>
    19 #include <caf/caf.h>
    19 #include <caf/caf.h>
       
    20 #include <pathinfo.h>
    20 
    21 
    21 #include "mdsutils.h"
    22 #include "mdsutils.h"
    22 #include "harvesteromadrmplugin.h"
    23 #include "harvesteromadrmplugin.h"
    23 #include "harvesterlog.h"
    24 #include "harvesterlog.h"
       
    25 #include "harvestercommon.h"
    24 #include "mdeobjectwrapper.h"
    26 #include "mdeobjectwrapper.h"
    25 #include "mdscommoninternal.h"
    27 #include "mdscommoninternal.h"
    26 #include <harvesterdata.h>
    28 #include <harvesterdata.h>
    27 
    29 
    28 #include <mdenamespacedef.h>
    30 #include <mdenamespacedef.h>
    36 _LIT(KVideo, "Video");
    38 _LIT(KVideo, "Video");
    37 _LIT(KAudio, "Audio");
    39 _LIT(KAudio, "Audio");
    38 _LIT(KRmMimetype, "realmedia");
    40 _LIT(KRmMimetype, "realmedia");
    39 
    41 
    40 _LIT( KSvgMime, "image/svg+xml" );
    42 _LIT( KSvgMime, "image/svg+xml" );
       
    43 _LIT( KRingingToneMime, "application/vnd.nokia.ringing-tone" );
    41 
    44 
    42 _LIT(KInUse, "InUse");
    45 _LIT(KInUse, "InUse");
    43 
    46 
    44 CHarvesterOmaDrmPluginPropertyDefs::CHarvesterOmaDrmPluginPropertyDefs() : CBase()
    47 CHarvesterOmaDrmPluginPropertyDefs::CHarvesterOmaDrmPluginPropertyDefs() : CBase()
    45 	{
    48 	{
    54 	iCreationDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KCreationDateProperty );
    57 	iCreationDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KCreationDateProperty );
    55 	iLastModifiedDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty );
    58 	iLastModifiedDatePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KLastModifiedDateProperty );
    56 	iSizePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty );
    59 	iSizePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KSizeProperty );
    57 	iItemTypePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty );
    60 	iItemTypePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty );
    58 	iTitlePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty );
    61 	iTitlePropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty );
       
    62 	iDefaultFolderPropertyDef = &objectDef.GetPropertyDefL( MdeConstants::Object::KInDefaultFolder );
    59 
    63 
    60 	CMdEObjectDef& mediaDef = nsDef.GetObjectDefL( MdeConstants::MediaObject::KMediaObject );
    64 	CMdEObjectDef& mediaDef = nsDef.GetObjectDefL( MdeConstants::MediaObject::KMediaObject );
    61 	iDrmPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDRMProperty );
    65 	iDrmPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDRMProperty );
    62 	iDescriptionPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDescriptionProperty );
    66 	iDescriptionPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KDescriptionProperty );
    63 	iAuthorPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KAuthorProperty );
    67 	iAuthorPropertyDef = &mediaDef.GetPropertyDefL( MdeConstants::MediaObject::KAuthorProperty );
   102 */
   106 */
   103 CHarvesterOMADRMPlugin::~CHarvesterOMADRMPlugin()
   107 CHarvesterOMADRMPlugin::~CHarvesterOMADRMPlugin()
   104 	{
   108 	{
   105 	WRITELOG("CHarvesterOMADRMPlugin::~CHarvesterOMADRMPlugin()");
   109 	WRITELOG("CHarvesterOMADRMPlugin::~CHarvesterOMADRMPlugin()");
   106 	
   110 	
       
   111     delete iPhoneImagesPath;
       
   112     delete iMmcImagesPath;
       
   113     
       
   114     delete iPhoneVideosPath;
       
   115     delete iMmcVideosPath;
       
   116     
       
   117     delete iPhoneSoundsPath;
       
   118     delete iMmcSoundsPath;
       
   119 	
   107 	delete iPropDefs;
   120 	delete iPropDefs;
   108 	}
   121 	}
   109 
   122 
   110 /**
   123 /**
   111 * 2nd phase constructor
   124 * 2nd phase constructor
   112 */
   125 */
   113 void CHarvesterOMADRMPlugin::ConstructL()
   126 void CHarvesterOMADRMPlugin::ConstructL()
   114 	{
   127 	{
   115 	WRITELOG( "CHarvesterOMADRMPlugin::ConstructL()" );
   128 	WRITELOG( "CHarvesterOMADRMPlugin::ConstructL()" );
       
   129 	
       
   130 	TFileName phoneRoot = PathInfo::PhoneMemoryRootPath();
       
   131 	TFileName mmcRoot = PathInfo::MemoryCardRootPath();
       
   132 	
       
   133 	TFileName images = PathInfo::ImagesPath();
       
   134 	
       
   135     TFileName phoneImagePath( phoneRoot );
       
   136     phoneImagePath.Append( images );
       
   137     iPhoneImagesPath = phoneImagePath.AllocL();
       
   138 
       
   139     TFileName mmcImagePath( mmcRoot );
       
   140     mmcImagePath.Append( images );
       
   141     iMmcImagesPath = mmcImagePath.Right( mmcImagePath.Length() - 1 ).AllocL();
       
   142     
       
   143     TFileName videos = PathInfo::VideosPath();
       
   144     
       
   145     TFileName phoneVideoPath( phoneRoot );
       
   146     phoneVideoPath.Append( videos );
       
   147     iPhoneVideosPath = phoneVideoPath.AllocL();
       
   148 
       
   149     TFileName mmcVideoPath( mmcRoot );
       
   150     mmcVideoPath.Append( videos );
       
   151     iMmcVideosPath = mmcVideoPath.Right( mmcVideoPath.Length() - 1 ).AllocL();
       
   152     
       
   153     TFileName sounds = PathInfo::SoundsPath();
       
   154     
       
   155     TFileName phoneSoundPath( phoneRoot );
       
   156     phoneSoundPath.Append( sounds );
       
   157     iPhoneSoundsPath = phoneSoundPath.AllocL();
       
   158 
       
   159     TFileName mmcSoundPath( mmcRoot );
       
   160     mmcSoundPath.Append( sounds );
       
   161     iMmcSoundsPath = mmcSoundPath.Right( mmcSoundPath.Length() - 1 ).AllocL();
   116 	}
   162 	}
   117 
   163 
   118 void CHarvesterOMADRMPlugin::HarvestL( CHarvesterData* aHD )
   164 void CHarvesterOMADRMPlugin::HarvestL( CHarvesterData* aHD )
   119 	{
   165 	{
   120     CMdEObject& mdeObject = aHD->MdeObject();
   166     CMdEObject& mdeObject = aHD->MdeObject();
   248         
   294         
   249     CleanupStack::PopAndDestroy( 3 ); // content, data, attrSet
   295     CleanupStack::PopAndDestroy( 3 ); // content, data, attrSet
   250     }
   296     }
   251 
   297 
   252 // ---------------------------------------------------------------------------
   298 // ---------------------------------------------------------------------------
   253 // HandleNewObjectL
   299 // HandleObjectPropertiesL
   254 // ---------------------------------------------------------------------------
   300 // ---------------------------------------------------------------------------
   255 //
   301 //
   256 void CHarvesterOMADRMPlugin::HandleObjectPropertiesL(
   302 void CHarvesterOMADRMPlugin::HandleObjectPropertiesL(
   257 		CHarvesterData& aHD,
   303 		CHarvesterData& aHD,
   258 		CDRMHarvestData& aVHD,
   304 		CDRMHarvestData& aVHD,
   281     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
   327     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
   282     			*iPropDefs->iLastModifiedDatePropertyDef, &aVHD.iModified, aIsAdd );
   328     			*iPropDefs->iLastModifiedDatePropertyDef, &aVHD.iModified, aIsAdd );
   283     	// File size
   329     	// File size
   284     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
   330     	CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, 
   285     			*iPropDefs->iSizePropertyDef, &aVHD.iFileSize, aIsAdd );
   331     			*iPropDefs->iSizePropertyDef, &aVHD.iFileSize, aIsAdd );
       
   332 
       
   333     	TPtrC objectDefName( mdeObject.Def().Name() );
       
   334         if( objectDefName == MdeConstants::Image::KImageObject )
       
   335             {
       
   336             const TDesC& uri = mdeObject.Uri();
       
   337             if( uri.FindF( iMmcImagesPath->Des()) != KErrNotFound ||
       
   338                 uri.FindF( iPhoneImagesPath->Des()) != KErrNotFound ||
       
   339                 uri.FindF( KDCIMFolder ) != KErrNotFound )
       
   340                 {
       
   341                 TBool inDefaultFolder( ETrue );
       
   342                 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iDefaultFolderPropertyDef, &inDefaultFolder, aIsAdd );
       
   343                 }
       
   344             else
       
   345                 {
       
   346                 TBool inDefaultFolder( EFalse );
       
   347                 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iDefaultFolderPropertyDef, &inDefaultFolder, aIsAdd );    
       
   348                 }    
       
   349             }
       
   350         else if( objectDefName == MdeConstants::Video::KVideoObject )
       
   351             {
       
   352             const TDesC& uri = mdeObject.Uri();
       
   353             if( uri.FindF( iMmcVideosPath->Des()) != KErrNotFound ||
       
   354                 uri.FindF( iPhoneVideosPath->Des()) != KErrNotFound ||
       
   355                 uri.FindF( KDCIMFolder ) != KErrNotFound )
       
   356                 {
       
   357                 TBool inDefaultFolder( ETrue );
       
   358                 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iDefaultFolderPropertyDef, &inDefaultFolder, aIsAdd );
       
   359                 }
       
   360             else
       
   361                 {
       
   362                 TBool inDefaultFolder( EFalse );
       
   363                 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iDefaultFolderPropertyDef, &inDefaultFolder, aIsAdd );    
       
   364                 }    
       
   365             }
       
   366         else if( objectDefName == MdeConstants::Audio::KAudioObject )
       
   367             {
       
   368             const TDesC& uri = mdeObject.Uri();
       
   369             if( uri.FindF( iMmcSoundsPath->Des()) != KErrNotFound ||
       
   370                 uri.FindF( iPhoneSoundsPath->Des()) != KErrNotFound )
       
   371                 {
       
   372                 TBool inDefaultFolder( ETrue );
       
   373                 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iDefaultFolderPropertyDef, &inDefaultFolder, aIsAdd );
       
   374                 }
       
   375             else
       
   376                 {
       
   377                 TBool inDefaultFolder( EFalse );
       
   378                 CMdeObjectWrapper::HandleObjectPropertyL(mdeObject, *iPropDefs->iDefaultFolderPropertyDef, &inDefaultFolder, aIsAdd );    
       
   379                 }     
       
   380             }
   286     	}
   381     	}
   287     
   382         
   288     // Item Type
   383     // Item Type
   289     if(aVHD.iMimetype.Length() > 0)
   384     if(aVHD.iMimetype.Length() > 0)
   290         {
   385         {
   291         TBool isAdd( EFalse );
   386         TBool isAdd( EFalse );
   292         CMdEProperty* prop = NULL;
   387         CMdEProperty* prop = NULL;
   342 	if (err == KErrNone) 
   437 	if (err == KErrNone) 
   343 		{
   438 		{
   344 		err = content->GetStringAttribute( ContentAccess::EMimeType, mime );
   439 		err = content->GetStringAttribute( ContentAccess::EMimeType, mime );
   345 		delete content;
   440 		delete content;
   346 		}
   441 		}
       
   442 
       
   443 #ifdef _DEBUG
       
   444     if( err == KErrInUse || err == KErrLocked )
       
   445         {
       
   446         TPtrC fileName( aUri.Mid(2) );
       
   447         WRITELOG1( "CHarvesterOMADRMPlugin :: Checking open file handles to %S", &fileName );
       
   448 
       
   449         CFileList* fileList = 0;
       
   450         TOpenFileScan fileScan( iFs );
       
   451 
       
   452         TRAP_IGNORE( fileScan.NextL( fileList ) );   
       
   453           
       
   454         while ( fileList )   
       
   455             {
       
   456             const TInt count( fileList->Count() ); 
       
   457             for (TInt i = 0; i < count; i++ )   
       
   458                 {   
       
   459                 if ( (*fileList)[i].iName == aUri.Mid(2) )
       
   460                     {
       
   461                     TFullName processName;
       
   462                     TFindThread find(_L("*"));
       
   463                     while( find.Next( processName ) == KErrNone )
       
   464                         {
       
   465                         RThread thread;
       
   466                         TInt error = thread.Open( processName );
       
   467              
       
   468                         if ( error == KErrNone )
       
   469                             {
       
   470                             if ( thread.Id().Id() ==  fileScan.ThreadId() )
       
   471                                 {
       
   472                                 processName = thread.Name();
       
   473                                 thread.Close();
       
   474                                 WRITELOG1( "CHarvesterOMADRMPlugin :: %S has a file handle open", &processName );
       
   475                                 break;
       
   476                                 }
       
   477                             thread.Close();
       
   478                             }
       
   479                         }
       
   480                     }
       
   481                 }
       
   482             TRAP_IGNORE( fileScan.NextL( fileList ) );   
       
   483             } 
       
   484         }
       
   485 #endif
   347 	
   486 	
   348 	if( err == KErrInUse || err == KErrLocked )
   487 	if( err == KErrInUse || err == KErrLocked )
   349 	    {
   488 	    {
   350 	    aObjectType.Copy( KInUse() );
   489 	    aObjectType.Copy( KInUse() );
   351 	    return;
   490 	    return;
   389 			{
   528 			{
   390 			WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - mimetype %S. Object type changed to Rm", &mime );
   529 			WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - mimetype %S. Object type changed to Rm", &mime );
   391 			aObjectType.Copy( KVideo );
   530 			aObjectType.Copy( KVideo );
   392 			return;
   531 			return;
   393 			}
   532 			}
       
   533 		
       
   534 	    if( mime == KRingingToneMime )
       
   535 	        {
       
   536 	        WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - mimetype %S. Object type changed to Audio", &mime );
       
   537 	        aObjectType.Copy( KAudio );
       
   538 	        return;
       
   539 	        }
   394     	}
   540     	}
   395     
   541     
   396 	WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - ERROR: mimetype %S. No object type found", &mime );
   542 	WRITELOG1( "CHarvesterOMADRMPlugin::GetObjectType - ERROR: mimetype %S. No object type found", &mime );
   397 	aObjectType.Zero();
   543 	aObjectType.Zero();
   398 	}
   544 	}