harvester/monitorplugins/fileplugin/src/fileeventhandlerao.cpp
changeset 45 a93990e5815e
parent 25 8e4539ab1889
child 52 40db28bb26b8
equal deleted inserted replaced
36:aa5a574040a4 45:a93990e5815e
    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>
    19 
    20 
    20 #include "fileeventhandlerao.h"
    21 #include "fileeventhandlerao.h"
    21 #include "harvesterlog.h"
    22 #include "harvesterlog.h"
    22 #include "fsutil.h"
    23 #include "fsutil.h"
    23 #include "mdeconstants.h"
    24 #include "mdeconstants.h"
    81     	}
    82     	}
    82     error = iFs.Connect();
    83     error = iFs.Connect();
    83     User::LeaveIfError( error );
    84     User::LeaveIfError( error );
    84     
    85     
    85     TRAP( error, ReadCacheSizeFromCenrepL() );
    86     TRAP( error, ReadCacheSizeFromCenrepL() );
       
    87 	
    86     if ( error == KErrNone )
    88     if ( error == KErrNone )
    87     	{
    89     	{
    88     	iQueue.Reserve( iCacheSize );
    90     	iQueue.Reserve( iCacheSize );
    89     	}
    91     	}
    90     
    92     
    91     iEventArray = new (ELeave) CArrayFixSeg< TMdsFSPStatus >( KMaxEventsGranularity );
    93     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();
    92     }
   127     }
    93 
   128 
    94 // ---------------------------------------------------------------------------
   129 // ---------------------------------------------------------------------------
    95 // CFileEventHandlerAO::~CFileEventHandlerAO()
   130 // CFileEventHandlerAO::~CFileEventHandlerAO()
    96 // ---------------------------------------------------------------------------
   131 // ---------------------------------------------------------------------------
   102     Cancel();
   137     Cancel();
   103     
   138     
   104     iFs.Close();
   139     iFs.Close();
   105     
   140     
   106     delete iMapper;
   141     delete iMapper;
       
   142     iMapper = NULL;
       
   143     
   107     delete iMoveTimer;
   144     delete iMoveTimer;
       
   145     iMoveTimer = NULL;
       
   146     
   108     delete iFolderRenamer;
   147     delete iFolderRenamer;
       
   148     iFolderRenamer = NULL;
   109     
   149     
   110     delete iEventArray;
   150     delete iEventArray;
       
   151     iEventArray = NULL;
   111     
   152     
   112     iQueue.ResetAndDestroy();
   153     iQueue.ResetAndDestroy();
   113     iQueue.Close();
   154     iQueue.Close();
   114 	
   155 	
   115     iUriArray.ResetAndDestroy();
   156     iUriArray.ResetAndDestroy();
   116     iUriArray.Close();
   157     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;
   117     }
   173     }
   118 
   174 
   119 
   175 
   120 
   176 
   121 // ---------------------------------------------------------------------------
   177 // ---------------------------------------------------------------------------
   144     			iQueue.Remove( 0 );
   200     			iQueue.Remove( 0 );
   145 
   201 
   146     			ResetEvent();
   202     			ResetEvent();
   147     			item->GetAsFspStatus(iEvent);
   203     			item->GetAsFspStatus(iEvent);
   148     			delete item;
   204     			delete item;
       
   205     			item = NULL;
   149     			
   206     			
   150     			if( iEvent.iFileEventType == EMdsFileDeleted )
   207     			if( iEvent.iFileEventType == EMdsFileDeleted )
   151     			    {
   208     			    {
   152     			    iEventArray->AppendL( iEvent );
   209     			    iEventArray->AppendL( iEvent );
   153     			    TInt limit( KMaxEventsAtTime );
   210     			    TInt limit( KMaxEventsAtTime );
   439         {
   496         {
   440         const TItemId removedId = iMdeSession->Session()->RemoveObjectL( 
   497         const TItemId removedId = iMdeSession->Session()->RemoveObjectL( 
   441         		newObject->Id() );
   498         		newObject->Id() );
   442         if ( removedId != KNoId )
   499         if ( removedId != KNoId )
   443         	{
   500         	{
       
   501             SetTitleL( oldObject , aNewUrl );
   444 	        oldObject->SetUriL( aNewUrl );
   502 	        oldObject->SetUriL( aNewUrl );
   445 	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   503 	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   446 	        oldObject->SetMediaId( mediaId );
   504 	        oldObject->SetMediaId( mediaId );
   447         	}
   505         	}
   448         }
   506         }
   452         CleanupStack::PopAndDestroy( newObject );
   510         CleanupStack::PopAndDestroy( newObject );
   453         }
   511         }
   454 
   512 
   455     if ( oldObject )
   513     if ( oldObject )
   456         {
   514         {
       
   515         CheckDefaultFolderL( oldObject );
   457         SetModifiedTimeL( oldObject, aNewUrl );
   516         SetModifiedTimeL( oldObject, aNewUrl );
   458         TOrigin origin = OriginFromMdEObjectL( *oldObject );
   517         TOrigin origin = OriginFromMdEObjectL( *oldObject );
   459         if( origin == MdeConstants::Object::EOther)
   518         if( origin == MdeConstants::Object::EOther)
   460         	{
   519         	{
   461         	OriginToMdEObjectL( *oldObject, aOrigin );
   520         	OriginToMdEObjectL( *oldObject, aOrigin );
   629                 if ( oldObject )
   688                 if ( oldObject )
   630                     {
   689                     {
   631                     CleanupStack::PushL( oldObject );
   690                     CleanupStack::PushL( oldObject );
   632                     SetTitleL( oldObject , aNewUrl );
   691                     SetTitleL( oldObject , aNewUrl );
   633         	        oldObject->SetUriL( aNewUrl );
   692         	        oldObject->SetUriL( aNewUrl );
       
   693         	        CheckDefaultFolderL( oldObject );
   634         	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   694         	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   635         	        oldObject->SetMediaId( mediaId );
   695         	        oldObject->SetMediaId( mediaId );
       
   696         	        SetModifiedTimeL( oldObject, aNewUrl );
   636         	        TOrigin origin = OriginFromMdEObjectL( *oldObject );
   697         	        TOrigin origin = OriginFromMdEObjectL( *oldObject );
   637         	        if( origin == MdeConstants::Object::EOther)
   698         	        if( origin == MdeConstants::Object::EOther)
   638         	        	{
   699         	        	{
   639         	        	OriginToMdEObjectL( *oldObject, aOrigin );
   700         	        	OriginToMdEObjectL( *oldObject, aOrigin );
   640         	        	}
   701         	        	}
   651             if ( oldObject )
   712             if ( oldObject )
   652                 {
   713                 {
   653                 CleanupStack::PushL( oldObject );
   714                 CleanupStack::PushL( oldObject );
   654                 SetTitleL( oldObject , aNewUrl );
   715                 SetTitleL( oldObject , aNewUrl );
   655     	        oldObject->SetUriL( aNewUrl );
   716     	        oldObject->SetUriL( aNewUrl );
       
   717     	        CheckDefaultFolderL( oldObject );
   656     	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   718     	        TUint32 mediaId = FSUtil::MediaID( iFs, aNewUrl );
   657     	        oldObject->SetMediaId( mediaId );
   719     	        oldObject->SetMediaId( mediaId );
   658     	        SetModifiedTimeL( oldObject, aNewUrl );
   720     	        SetModifiedTimeL( oldObject, aNewUrl );
   659     	        TOrigin origin = OriginFromMdEObjectL( *oldObject );
   721     	        TOrigin origin = OriginFromMdEObjectL( *oldObject );
   660     	        if( origin == MdeConstants::Object::EOther)
   722     	        if( origin == MdeConstants::Object::EOther)
   971         {
  1033         {
   972         aOldObject->AddTimePropertyL( *iTimePropertyDef , time );
  1034         aOldObject->AddTimePropertyL( *iTimePropertyDef , time );
   973         }
  1035         }
   974     }
  1036     }
   975 
  1037 
       
  1038 //---------------------------------------------------------------------------
       
  1039 // CFileEventHandlerAO::CheckDefaultFolderL()
       
  1040 // ---------------------------------------------------------------------------
       
  1041 //   
       
  1042 void CFileEventHandlerAO::CheckDefaultFolderL( CMdEObject* aOldObject )
       
  1043     {
       
  1044     if( !iDefaultFolderPropertyDef )
       
  1045         {
       
  1046         iDefaultFolderPropertyDef = &aOldObject->Def().GetPropertyDefL( 
       
  1047                        MdeConstants::Object::KInDefaultFolder );
       
  1048         }
       
  1049     
       
  1050     CMdEProperty* folderProp = NULL;
       
  1051     aOldObject->Property( *iDefaultFolderPropertyDef, folderProp );
       
  1052     
       
  1053     TBool inDefaultFolder( EFalse );
       
  1054     TPtrC objectDefName( aOldObject->Def().Name() );
       
  1055     if( objectDefName == MdeConstants::Image::KImageObject )
       
  1056         {
       
  1057         const TDesC& uri = aOldObject->Uri();
       
  1058         if( uri.FindF( iMmcImagesPath->Des()) != KErrNotFound ||
       
  1059             uri.FindF( iPhoneImagesPath->Des()) != KErrNotFound ||
       
  1060             uri.FindF( KDCIMFolder ) != KErrNotFound )
       
  1061             {
       
  1062             inDefaultFolder = ETrue; 
       
  1063             }    
       
  1064         }
       
  1065     else if( objectDefName == MdeConstants::Video::KVideoObject )
       
  1066         {
       
  1067         const TDesC& uri = aOldObject->Uri();
       
  1068         if( uri.FindF( iMmcVideosPath->Des()) != KErrNotFound ||
       
  1069             uri.FindF( iPhoneVideosPath->Des()) != KErrNotFound ||
       
  1070             uri.FindF( KDCIMFolder ) != KErrNotFound )
       
  1071             {
       
  1072             inDefaultFolder = ETrue; 
       
  1073             }    
       
  1074         }
       
  1075     else if( objectDefName == MdeConstants::Audio::KAudioObject )
       
  1076         {
       
  1077         const TDesC& uri = aOldObject->Uri();
       
  1078         if( uri.FindF( iMmcSoundsPath->Des()) != KErrNotFound ||
       
  1079             uri.FindF( iPhoneSoundsPath->Des()) != KErrNotFound )
       
  1080             {
       
  1081             inDefaultFolder = ETrue;
       
  1082             } 
       
  1083         }
       
  1084 
       
  1085     if( folderProp )
       
  1086         {
       
  1087         folderProp->SetBoolValueL( inDefaultFolder );
       
  1088         }
       
  1089     else
       
  1090         {
       
  1091         aOldObject->AddBoolPropertyL( *iDefaultFolderPropertyDef, inDefaultFolder );
       
  1092         }
       
  1093     }
       
  1094