harvester/monitorplugins/fileplugin/src/fileeventhandlerao.cpp
branchRCL_3
changeset 63 e538444823de
parent 57 2872ae438bf7
equal deleted inserted replaced
57:2872ae438bf7 63:e538444823de
    14 * Description:  Handles monitored file creations, modifications and deletions.*
    14 * Description:  Handles monitored file creations, modifications and deletions.*
    15 */
    15 */
    16 
    16 
    17 #include <collate.h>
    17 #include <collate.h>
    18 #include <mdeobject.h>
    18 #include <mdeobject.h>
    19 #include <pathinfo.h>
       
    20 
    19 
    21 #include "fileeventhandlerao.h"
    20 #include "fileeventhandlerao.h"
    22 #include "harvesterlog.h"
    21 #include "harvesterlog.h"
    23 #include "fsutil.h"
    22 #include "fsutil.h"
    24 #include "mdeconstants.h"
    23 #include "mdeconstants.h"
    82     	}
    81     	}
    83     error = iFs.Connect();
    82     error = iFs.Connect();
    84     User::LeaveIfError( error );
    83     User::LeaveIfError( error );
    85     
    84     
    86     TRAP( error, ReadCacheSizeFromCenrepL() );
    85     TRAP( error, ReadCacheSizeFromCenrepL() );
    87 	
       
    88     if ( error == KErrNone )
    86     if ( error == KErrNone )
    89     	{
    87     	{
    90     	iQueue.Reserve( iCacheSize );
    88     	iQueue.Reserve( iCacheSize );
    91     	}
    89     	}
    92     
    90     
    93     iEventArray = new (ELeave) CArrayFixSeg< TMdsFSPStatus >( KMaxEventsGranularity );
    91     iEventArray = new (ELeave) CArrayFixSeg< TMdsFSPStatus >( KMaxEventsGranularity );
    94     
       
    95     TFileName phoneRoot = PathInfo::PhoneMemoryRootPath();
       
    96     TFileName mmcRoot = PathInfo::MemoryCardRootPath();
       
    97     
       
    98     TFileName images = PathInfo::ImagesPath();
       
    99     
       
   100     TFileName phoneImagePath( phoneRoot );
       
   101     phoneImagePath.Append( images );
       
   102     iPhoneImagesPath = phoneImagePath.AllocL();
       
   103 
       
   104     TFileName mmcImagePath( mmcRoot );
       
   105     mmcImagePath.Append( images );
       
   106     iMmcImagesPath = mmcImagePath.Right( mmcImagePath.Length() - 1 ).AllocL();
       
   107     
       
   108     TFileName videos = PathInfo::VideosPath();
       
   109     
       
   110     TFileName phoneVideoPath( phoneRoot );
       
   111     phoneVideoPath.Append( videos );
       
   112     iPhoneVideosPath = phoneVideoPath.AllocL();
       
   113 
       
   114     TFileName mmcVideoPath( mmcRoot );
       
   115     mmcVideoPath.Append( videos );
       
   116     iMmcVideosPath = mmcVideoPath.Right( mmcVideoPath.Length() - 1 ).AllocL();
       
   117     
       
   118     TFileName sounds = PathInfo::SoundsPath();
       
   119     
       
   120     TFileName phoneSoundPath( phoneRoot );
       
   121     phoneSoundPath.Append( sounds );
       
   122     iPhoneSoundsPath = phoneSoundPath.AllocL();
       
   123 
       
   124     TFileName mmcSoundPath( mmcRoot );
       
   125     mmcSoundPath.Append( sounds );
       
   126     iMmcSoundsPath = mmcSoundPath.Right( mmcSoundPath.Length() - 1 ).AllocL();
       
   127     }
    92     }
   128 
    93 
   129 // ---------------------------------------------------------------------------
    94 // ---------------------------------------------------------------------------
   130 // CFileEventHandlerAO::~CFileEventHandlerAO()
    95 // CFileEventHandlerAO::~CFileEventHandlerAO()
   131 // ---------------------------------------------------------------------------
    96 // ---------------------------------------------------------------------------
   137     Cancel();
   102     Cancel();
   138     
   103     
   139     iFs.Close();
   104     iFs.Close();
   140     
   105     
   141     delete iMapper;
   106     delete iMapper;
   142     iMapper = NULL;
       
   143     
       
   144     delete iMoveTimer;
   107     delete iMoveTimer;
   145     iMoveTimer = NULL;
       
   146     
       
   147     delete iFolderRenamer;
   108     delete iFolderRenamer;
   148     iFolderRenamer = NULL;
       
   149     
   109     
   150     delete iEventArray;
   110     delete iEventArray;
   151     iEventArray = NULL;
       
   152     
   111     
   153     iQueue.ResetAndDestroy();
   112     iQueue.ResetAndDestroy();
   154     iQueue.Close();
   113     iQueue.Close();
   155 	
   114 	
   156     iUriArray.ResetAndDestroy();
   115     iUriArray.ResetAndDestroy();
   157     iUriArray.Close();
   116     iUriArray.Close();
   158     
       
   159     delete iPhoneImagesPath;
       
   160 	iPhoneImagesPath = NULL;
       
   161     delete iMmcImagesPath;
       
   162 	iMmcImagesPath = NULL;
       
   163     
       
   164     delete iPhoneVideosPath;
       
   165 	iPhoneVideosPath = NULL;
       
   166     delete iMmcVideosPath;
       
   167 	iMmcVideosPath = NULL;
       
   168     
       
   169     delete iPhoneSoundsPath;
       
   170 	iPhoneSoundsPath = NULL;
       
   171     delete iMmcSoundsPath;
       
   172 	iMmcSoundsPath = NULL;
       
   173     }
   117     }
   174 
   118 
   175 
   119 
   176 
   120 
   177 // ---------------------------------------------------------------------------
   121 // ---------------------------------------------------------------------------
   200     			iQueue.Remove( 0 );
   144     			iQueue.Remove( 0 );
   201 
   145 
   202     			ResetEvent();
   146     			ResetEvent();
   203     			item->GetAsFspStatus(iEvent);
   147     			item->GetAsFspStatus(iEvent);
   204     			delete item;
   148     			delete item;
   205     			item = NULL;
       
   206     			
   149     			
   207     			if( iEvent.iFileEventType == EMdsFileDeleted )
   150     			if( iEvent.iFileEventType == EMdsFileDeleted )
   208     			    {
   151     			    {
   209     			    iEventArray->AppendL( iEvent );
   152     			    iEventArray->AppendL( iEvent );
   210     			    TInt limit( KMaxEventsAtTime );
   153     			    TInt limit( KMaxEventsAtTime );
   308             WRITELOG1( "CFileEventHandlerAO::HandleNotificationL - ignored attribs changed event for %S", &status.iFileName );
   251             WRITELOG1( "CFileEventHandlerAO::HandleNotificationL - ignored attribs changed event for %S", &status.iFileName );
   309             return;        
   252             return;        
   310             }
   253             }
   311         }
   254         }
   312 
   255 
   313     // If internal origin value is used for evaluation, set it default value
       
   314     if( origin == KOriginIgnoreAttribsChanged ||
       
   315         origin == KOriginFastHarvest )
       
   316         {
       
   317         origin = MdeConstants::Object::EOther;
       
   318         }
       
   319     
       
   320     // ignore created file event if extension is not supported by any harverter plugin
   256     // ignore created file event if extension is not supported by any harverter plugin
   321     if( EMdsFileCreated == status.iFileEventType && 
   257     if( EMdsFileCreated == status.iFileEventType && 
   322     		status.iFileName.Length() > 0 )
   258     		status.iFileName.Length() > 0 )
   323     	{
   259     	{
   324     	if( !iHarvesterPluginFactory->IsSupportedFileExtension( 
   260     	if( !iHarvesterPluginFactory->IsSupportedFileExtension( 
   512         {
   448         {
   513         const TItemId removedId = iMdeSession->Session()->RemoveObjectL( 
   449         const TItemId removedId = iMdeSession->Session()->RemoveObjectL( 
   514         		newObject->Id() );
   450         		newObject->Id() );
   515         if ( removedId != KNoId )
   451         if ( removedId != KNoId )
   516         	{
   452         	{
   517             SetTitleL( oldObject , aNewUrl );
       
   518 	        oldObject->SetUriL( aNewUrl );
   453 	        oldObject->SetUriL( aNewUrl );
   519 	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   454 	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   520 	        oldObject->SetMediaId( mediaId );
   455 	        oldObject->SetMediaId( mediaId );
   521         	}
   456         	}
   522         }
   457         }
   526         CleanupStack::PopAndDestroy( newObject );
   461         CleanupStack::PopAndDestroy( newObject );
   527         }
   462         }
   528 
   463 
   529     if ( oldObject )
   464     if ( oldObject )
   530         {
   465         {
   531         CheckDefaultFolderL( oldObject );
       
   532         SetModifiedTimeL( oldObject, aNewUrl );
   466         SetModifiedTimeL( oldObject, aNewUrl );
   533         TOrigin origin = OriginFromMdEObjectL( *oldObject );
   467         TOrigin origin = OriginFromMdEObjectL( *oldObject );
   534         if( origin == MdeConstants::Object::EOther)
   468         if( origin == MdeConstants::Object::EOther)
   535         	{
   469         	{
   536         	OriginToMdEObjectL( *oldObject, aOrigin );
   470         	OriginToMdEObjectL( *oldObject, aOrigin );
   704                 if ( oldObject )
   638                 if ( oldObject )
   705                     {
   639                     {
   706                     CleanupStack::PushL( oldObject );
   640                     CleanupStack::PushL( oldObject );
   707                     SetTitleL( oldObject , aNewUrl );
   641                     SetTitleL( oldObject , aNewUrl );
   708         	        oldObject->SetUriL( aNewUrl );
   642         	        oldObject->SetUriL( aNewUrl );
   709         	        CheckDefaultFolderL( oldObject );
       
   710         	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   643         	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   711         	        oldObject->SetMediaId( mediaId );
   644         	        oldObject->SetMediaId( mediaId );
   712         	        SetModifiedTimeL( oldObject, aNewUrl );
       
   713         	        TOrigin origin = OriginFromMdEObjectL( *oldObject );
   645         	        TOrigin origin = OriginFromMdEObjectL( *oldObject );
   714         	        if( origin == MdeConstants::Object::EOther)
   646         	        if( origin == MdeConstants::Object::EOther)
   715         	        	{
   647         	        	{
   716         	        	OriginToMdEObjectL( *oldObject, aOrigin );
   648         	        	OriginToMdEObjectL( *oldObject, aOrigin );
   717         	        	}
   649         	        	}
   728             if ( oldObject )
   660             if ( oldObject )
   729                 {
   661                 {
   730                 CleanupStack::PushL( oldObject );
   662                 CleanupStack::PushL( oldObject );
   731                 SetTitleL( oldObject , aNewUrl );
   663                 SetTitleL( oldObject , aNewUrl );
   732     	        oldObject->SetUriL( aNewUrl );
   664     	        oldObject->SetUriL( aNewUrl );
   733     	        CheckDefaultFolderL( oldObject );
       
   734     	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   665     	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   735     	        oldObject->SetMediaId( mediaId );
   666     	        oldObject->SetMediaId( mediaId );
   736     	        SetModifiedTimeL( oldObject, aNewUrl );
   667     	        SetModifiedTimeL( oldObject, aNewUrl );
   737     	        TOrigin origin = OriginFromMdEObjectL( *oldObject );
   668     	        TOrigin origin = OriginFromMdEObjectL( *oldObject );
   738     	        if( origin == MdeConstants::Object::EOther)
   669     	        if( origin == MdeConstants::Object::EOther)
   845 // CFileEventHandlerAO::FormatL()
   776 // CFileEventHandlerAO::FormatL()
   846 // ---------------------------------------------------------------------------
   777 // ---------------------------------------------------------------------------
   847 //
   778 //
   848 void CFileEventHandlerAO::FormatL( TUint32 aOldMediaId, TBool aSubClose )
   779 void CFileEventHandlerAO::FormatL( TUint32 aOldMediaId, TBool aSubClose )
   849 	{
   780 	{
   850 	WRITELOG2( "CFileEventHandlerAO::FormatL - old media ID %d subclose %d", 
   781 	WRITELOG2( "CFileEventHandlerAO::FormatL - old media ID %u subclose %d", 
   851 			aOldMediaId, aSubClose );
   782 			aOldMediaId, aSubClose );
   852 
   783 
   853 	if ( aOldMediaId )
   784 	if ( aOldMediaId )
   854 		{
   785 		{
   855 		iMdeSession->SetFilesToNotPresent( aOldMediaId );
   786 		iMdeSession->SetFilesToNotPresent( aOldMediaId );
  1049         {
   980         {
  1050         aOldObject->AddTimePropertyL( *iTimePropertyDef , time );
   981         aOldObject->AddTimePropertyL( *iTimePropertyDef , time );
  1051         }
   982         }
  1052     }
   983     }
  1053 
   984 
  1054 //---------------------------------------------------------------------------
       
  1055 // CFileEventHandlerAO::CheckDefaultFolderL()
       
  1056 // ---------------------------------------------------------------------------
       
  1057 //   
       
  1058 void CFileEventHandlerAO::CheckDefaultFolderL( CMdEObject* aOldObject )
       
  1059     {
       
  1060     if( !iDefaultFolderPropertyDef )
       
  1061         {
       
  1062         iDefaultFolderPropertyDef = &aOldObject->Def().GetPropertyDefL( 
       
  1063                        MdeConstants::Object::KInDefaultFolder );
       
  1064         }
       
  1065     
       
  1066     CMdEProperty* folderProp = NULL;
       
  1067     aOldObject->Property( *iDefaultFolderPropertyDef, folderProp );
       
  1068     
       
  1069     TBool inDefaultFolder( EFalse );
       
  1070     TPtrC objectDefName( aOldObject->Def().Name() );
       
  1071     if( objectDefName == MdeConstants::Image::KImageObject )
       
  1072         {
       
  1073         const TDesC& uri = aOldObject->Uri();
       
  1074         if( uri.FindF( iMmcImagesPath->Des()) != KErrNotFound ||
       
  1075             uri.FindF( iPhoneImagesPath->Des()) != KErrNotFound ||
       
  1076             uri.FindF( KDCIMFolder ) != KErrNotFound )
       
  1077             {
       
  1078             inDefaultFolder = ETrue; 
       
  1079             }    
       
  1080         }
       
  1081     else if( objectDefName == MdeConstants::Video::KVideoObject )
       
  1082         {
       
  1083         const TDesC& uri = aOldObject->Uri();
       
  1084         if( uri.FindF( iMmcVideosPath->Des()) != KErrNotFound ||
       
  1085             uri.FindF( iPhoneVideosPath->Des()) != KErrNotFound ||
       
  1086             uri.FindF( KDCIMFolder ) != KErrNotFound )
       
  1087             {
       
  1088             inDefaultFolder = ETrue; 
       
  1089             }    
       
  1090         }
       
  1091     else if( objectDefName == MdeConstants::Audio::KAudioObject )
       
  1092         {
       
  1093         const TDesC& uri = aOldObject->Uri();
       
  1094         if( uri.FindF( iMmcSoundsPath->Des()) != KErrNotFound ||
       
  1095             uri.FindF( iPhoneSoundsPath->Des()) != KErrNotFound )
       
  1096             {
       
  1097             inDefaultFolder = ETrue;
       
  1098             } 
       
  1099         }
       
  1100 
       
  1101     if( folderProp )
       
  1102         {
       
  1103         folderProp->SetBoolValueL( inDefaultFolder );
       
  1104         }
       
  1105     else
       
  1106         {
       
  1107         aOldObject->AddBoolPropertyL( *iDefaultFolderPropertyDef, inDefaultFolder );
       
  1108         }
       
  1109     }
       
  1110