videocollection/mpxmyvideoscollection/src/vcxmyvideosasyncfileoperations.cpp
changeset 35 3738fe97f027
parent 34 bbb98528c666
child 38 ff53afa8ad05
equal deleted inserted replaced
34:bbb98528c666 35:3738fe97f027
    36 #include "vcxmyvideoscollectionutil.h"
    36 #include "vcxmyvideoscollectionutil.h"
    37 #include "vcxmyvideosvideocache.h"
    37 #include "vcxmyvideosvideocache.h"
    38 #include "vcxmyvideoscategories.h"
    38 #include "vcxmyvideoscategories.h"
    39 #include "vcxmyvideosmessagelist.h"
    39 #include "vcxmyvideosmessagelist.h"
    40 #include "vcxmyvideosasyncfileoperations.h"
    40 #include "vcxmyvideosasyncfileoperations.h"
       
    41 #include "vcxmyvideosasyncfilecopy.h"
    41 
    42 
    42 // ============================ MEMBER FUNCTIONS ==============================
    43 // ============================ MEMBER FUNCTIONS ==============================
    43 
    44 
    44 // ----------------------------------------------------------------------------
    45 // ----------------------------------------------------------------------------
    45 // Two-phased constructor.
    46 // Two-phased constructor.
    66     {
    67     {
    67     MPX_FUNC("CVcxMyVideosAsyncFileOperations::~CVcxMyVideosAsyncFileOperations");
    68     MPX_FUNC("CVcxMyVideosAsyncFileOperations::~CVcxMyVideosAsyncFileOperations");
    68         
    69         
    69     iOperationIdArray.Close();
    70     iOperationIdArray.Close();
    70     iOperationResult.Close();
    71     iOperationResult.Close();
       
    72     delete iFileCopier;
       
    73     delete iMediaForMoveOp;
       
    74     delete iMediaForCopyOp;
    71     }
    75     }
    72 
    76 
    73 // ----------------------------------------------------------------------------
    77 // ----------------------------------------------------------------------------
    74 // Constructor.
    78 // Constructor.
    75 // ----------------------------------------------------------------------------
    79 // ----------------------------------------------------------------------------
    76 //
    80 //
    77 CVcxMyVideosAsyncFileOperations::CVcxMyVideosAsyncFileOperations( CVcxMyVideosCollectionPlugin& aCollection )
    81 CVcxMyVideosAsyncFileOperations::CVcxMyVideosAsyncFileOperations(
       
    82         CVcxMyVideosCollectionPlugin& aCollection )
    78 : iCollection( aCollection )
    83 : iCollection( aCollection )
    79     {
    84     {
    80     MPX_FUNC("CVcxMyVideosAsyncFileOperations::CVcxMyVideosAsyncFileOperations");
    85     MPX_FUNC("CVcxMyVideosAsyncFileOperations::CVcxMyVideosAsyncFileOperations");
    81     }
    86     }
    82 
    87 
    84 // Symbian 2nd phase constructor can leave.
    89 // Symbian 2nd phase constructor can leave.
    85 // ----------------------------------------------------------------------------
    90 // ----------------------------------------------------------------------------
    86 //
    91 //
    87 void CVcxMyVideosAsyncFileOperations::ConstructL ()
    92 void CVcxMyVideosAsyncFileOperations::ConstructL ()
    88     {
    93     {
    89     MPX_FUNC("CVcxMyVideosAsyncFileOperations::ConstructL");
    94     iFileCopier = CVcxMyVideosAsyncFileCopy::NewL( iCollection.iFs );
    90     }
    95     }
    91     
    96     
    92 // ----------------------------------------------------------------------------
    97 // ----------------------------------------------------------------------------
    93 // CVcxMyVideosCollectionPlugin::DeleteVideoL
    98 // CVcxMyVideosCollectionPlugin::DeleteVideoL
    94 // ----------------------------------------------------------------------------
    99 // ----------------------------------------------------------------------------
   218     
   223     
   219 // ----------------------------------------------------------------------------
   224 // ----------------------------------------------------------------------------
   220 // CVcxMyVideosAsyncFileOperations::HandleMoveOrCopyStepL
   225 // CVcxMyVideosAsyncFileOperations::HandleMoveOrCopyStepL
   221 // ----------------------------------------------------------------------------
   226 // ----------------------------------------------------------------------------
   222 //
   227 //
   223 MVcxMyVideosActiveTaskObserver::TStepResult CVcxMyVideosAsyncFileOperations::HandleMoveOrCopyStepL()
   228 MVcxMyVideosActiveTaskObserver::TStepResult
   224     {
   229         CVcxMyVideosAsyncFileOperations::HandleMoveOrCopyStepL()
       
   230     {
       
   231     // Reset inactivity timer. This will prevent ThumbAGDaemon start running while
       
   232     // Move/copy is ongoing and failing the operation due to locked file handle.
       
   233     User::ResetInactivityTime();
       
   234     
   225     CMPXMedia& cmd = iCollection.iActiveTask->GetCommand();
   235     CMPXMedia& cmd = iCollection.iActiveTask->GetCommand();
   226     
   236     
   227     MVcxMyVideosActiveTaskObserver::TStepResult stepResult;
   237     MVcxMyVideosActiveTaskObserver::TStepResult stepResult;
   228     
   238         
   229     TBool isMoveOperation = EFalse;
   239     if ( iCurrentOperationIndex == 0 && !iFileCopier->CopyIsOngoing() )
   230     TUint32 cmdId = cmd.ValueTObjectL<TUint32>( KVcxMediaMyVideosCommandId );    
   240         {
   231     if ( cmdId == KVcxCommandMyVideosMove )
   241         InitMoveOrCopyOperationsL( cmd );        
   232         {
   242         }
   233         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: move operation");
   243 
   234         isMoveOperation = ETrue;
   244     TRAPD( err, MoveOrCopyVideoL( iOperationIdArray[iCurrentOperationIndex] ) );
   235         }
   245 
   236         
   246     if ( iFileCopier->CopyIsOngoing() && err == KErrNone )
   237     // Start operations
   247         {
   238     if ( iCurrentOperationIndex == 0 )
   248         // copy didnt finish yet, lets do some more steps before jumping to next file
   239         {
   249         return MVcxMyVideosActiveTaskObserver::EMoreToCome;
   240         if ( !cmd.IsSupported( KMPXMediaArrayContents ) )
   250         }
   241             {
   251         
   242             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: error, no array defined");
       
   243             User::Leave( KErrArgument );
       
   244             }
       
   245     
       
   246         CMPXMediaArray* idMediaArray = cmd.Value<CMPXMediaArray>(
       
   247                 KMPXMediaArrayContents );
       
   248 
       
   249         if ( idMediaArray->Count() == 0 )
       
   250             {
       
   251             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: error, no items in array ");
       
   252             User::Leave( KErrArgument );
       
   253             }
       
   254         
       
   255         iTargetDrive = cmd.ValueTObjectL<TInt32>( KVcxMediaMyVideosInt32Value );
       
   256         
       
   257         TMPXItemId mpxId;    
       
   258         iOperationIdArray.Reset();
       
   259         TInt count = idMediaArray->Count();
       
   260         for ( TInt i = 0; i < count; i++ )
       
   261             {
       
   262             mpxId = idMediaArray->AtL( i )->
       
   263                             ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
   264             MPX_DEBUG3("CVcxMyVideosAsyncFileOperations:: MPX ID: (%d, %d) will be moved ",
       
   265                     mpxId.iId1,
       
   266                     mpxId.iId2);
       
   267             iOperationIdArray.AppendL( idMediaArray->AtL( i )->
       
   268                     ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId ).iId1 );
       
   269             }
       
   270         
       
   271         iCollection.SendMyVideosMessageL( KVcxMessageMyVideosMoveOrCopyStarted, &cmd );
       
   272 
       
   273         iOperationResult.Reset();
       
   274         }
       
   275 
       
   276     TRAPD( err, MoveOrCopyVideoL( iOperationIdArray[iCurrentOperationIndex],
       
   277             iTargetDrive, isMoveOperation ));
       
   278 
       
   279     iOperationResult.AppendL( err );
   252     iOperationResult.AppendL( err );
   280     
   253     
   281     iCurrentOperationIndex++;
   254     iCurrentOperationIndex++;
   282     
   255     
   283     // End operations
   256     // End operations
   284     if ( iCurrentOperationIndex > (iOperationIdArray.Count() - 1) )
   257     if ( iCurrentOperationIndex > (iOperationIdArray.Count() - 1) )
   285         {
   258         {
   286         iCurrentOperationIndex = 0;
   259         iCurrentOperationIndex = 0;
   287         stepResult = MVcxMyVideosActiveTaskObserver::EDone;
   260         stepResult             = MVcxMyVideosActiveTaskObserver::EDone;
   288         if ( isMoveOperation )
   261         if ( iIsMoveOperation )
   289             {
   262             {
   290             SendOperationRespL( KVcxMessageMyVideosMoveResp );
   263             SendOperationRespL( KVcxMessageMyVideosMoveResp );
   291             }
   264             }
   292         else
   265         else
   293             {
   266             {
   300         }
   273         }
   301         
   274         
   302     return stepResult;
   275     return stepResult;
   303     }
   276     }
   304 
   277 
       
   278 // ----------------------------------------------------------------------------
       
   279 // CVcxMyVideosAsyncFileOperations::InitMoveOrCopyOperationsL
       
   280 // ----------------------------------------------------------------------------
       
   281 //
       
   282 void CVcxMyVideosAsyncFileOperations::InitMoveOrCopyOperationsL( CMPXMedia& aCmd )
       
   283     {
       
   284     if ( !aCmd.IsSupported( KMPXMediaArrayContents ) )
       
   285         {
       
   286         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: error, no array defined");
       
   287         User::Leave( KErrArgument );
       
   288         }
       
   289 
       
   290     CMPXMediaArray* idMediaArray = aCmd.Value<CMPXMediaArray>(
       
   291             KMPXMediaArrayContents );
       
   292 
       
   293     if ( idMediaArray->Count() == 0 )
       
   294         {
       
   295         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: error, no items in array ");
       
   296         User::Leave( KErrArgument );
       
   297         }
       
   298     
       
   299     TUint32 cmdId = aCmd.ValueTObjectL<TUint32>( KVcxMediaMyVideosCommandId );    
       
   300     if ( cmdId == KVcxCommandMyVideosMove )
       
   301         {
       
   302         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: move operation");
       
   303         iIsMoveOperation = ETrue;
       
   304         }
       
   305     else
       
   306         {
       
   307         iIsMoveOperation = EFalse;
       
   308         }
       
   309 
       
   310     iTargetDrive = aCmd.ValueTObjectL<TInt32>( KVcxMediaMyVideosInt32Value );
       
   311     
       
   312     TMPXItemId mpxId;    
       
   313     iOperationIdArray.Reset();
       
   314     TInt count = idMediaArray->Count();
       
   315     for ( TInt i = 0; i < count; i++ )
       
   316         {
       
   317         mpxId = idMediaArray->AtL( i )->
       
   318                         ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
   319         MPX_DEBUG3("CVcxMyVideosAsyncFileOperations:: MPX ID: (%d, %d) will be moved ",
       
   320                 mpxId.iId1,
       
   321                 mpxId.iId2);
       
   322         iOperationIdArray.AppendL( idMediaArray->AtL( i )->
       
   323                 ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId ).iId1 );
       
   324         }
       
   325     
       
   326     iCollection.SendMyVideosMessageL( KVcxMessageMyVideosMoveOrCopyStarted, &aCmd );
       
   327 
       
   328     iOperationResult.Reset();
       
   329     }
       
   330     
   305 // ----------------------------------------------------------------------------
   331 // ----------------------------------------------------------------------------
   306 // CVcxMyVideosAsyncFileOperations::CancelOperationL
   332 // CVcxMyVideosAsyncFileOperations::CancelOperationL
   307 // Called when leave or cancel occurs for the operation, generates resp msg.
   333 // Called when leave or cancel occurs for the operation, generates resp msg.
   308 // ----------------------------------------------------------------------------
   334 // ----------------------------------------------------------------------------
   309 //
   335 //
   325         switch ( mvCmdId )
   351         switch ( mvCmdId )
   326             {
   352             {
   327             case KVcxCommandMyVideosMove:
   353             case KVcxCommandMyVideosMove:
   328                 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: generating KVcxMessageMyVideosMoveResp");
   354                 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: generating KVcxMessageMyVideosMoveResp");
   329                 messageId = KVcxMessageMyVideosMoveResp;
   355                 messageId = KVcxMessageMyVideosMoveResp;
       
   356                 if ( iFileCopier->CopyIsOngoing() )
       
   357                     {
       
   358                     //these have to be in this order, otherwise wrong item gets removed from mds
       
   359                     TRAP_IGNORE( HandleFileCopyCompletedL( aErr ) ); // rolls mds back
       
   360                     iFileCopier->Cancel(); // removes generated file and resets variables
       
   361                     }
   330                 break;
   362                 break;
   331                 
   363                 
   332             case KVcxCommandMyVideosCopy:
   364             case KVcxCommandMyVideosCopy:
   333                 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: generating KVcxMessageMyVideosCopyResp");
   365                 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: generating KVcxMessageMyVideosCopyResp");
   334                 messageId = KVcxMessageMyVideosCopyResp;
   366                 messageId = KVcxMessageMyVideosCopyResp;
       
   367                 if ( iFileCopier->CopyIsOngoing() )
       
   368                     {
       
   369                     TRAP_IGNORE( HandleFileCopyCompletedL( aErr ) ); // rolls mds back
       
   370                     iFileCopier->Cancel(); // removes generated file and resets variables
       
   371                     }
   335                 break;
   372                 break;
   336                 
   373                 
   337             case KVcxCommandMyVideosDelete:
   374             case KVcxCommandMyVideosDelete:
   338                 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: generating KVcxMessageMyVideosDeleteResp");
   375                 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: generating KVcxMessageMyVideosDeleteResp");
   339                 messageId = KVcxMessageMyVideosDeleteResp;
   376                 messageId = KVcxMessageMyVideosDeleteResp;
   406 
   443 
   407 // ----------------------------------------------------------------------------
   444 // ----------------------------------------------------------------------------
   408 // CVcxMyVideosAsyncFileOperations::MoveOrCopyVideoL
   445 // CVcxMyVideosAsyncFileOperations::MoveOrCopyVideoL
   409 // ----------------------------------------------------------------------------
   446 // ----------------------------------------------------------------------------
   410 //
   447 //
   411 void CVcxMyVideosAsyncFileOperations::MoveOrCopyVideoL( TUint32 aMdsId, TInt aTargetDrive,
   448 void CVcxMyVideosAsyncFileOperations::MoveOrCopyVideoL( TUint32 aMdsId )
   412         TBool aMove )
   449     {
   413     {
   450     if ( iFileCopier->CopyIsOngoing() )
   414     MPX_FUNC("CVcxMyVideosAsyncFileOperations::MoveOrCopyVideoL");
   451         {
   415 
   452         TInt err = iFileCopier->DoNextBlockCopy();
   416     MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: mds id = %d", aMdsId);
   453         if ( err != KErrNone || !iFileCopier->CopyIsOngoing() )
   417     
   454             {
       
   455             HandleFileCopyCompletedL( err );
       
   456             }
       
   457         return;
       
   458         }
       
   459         
       
   460     //New file copy starts -> do sanity checks and mds and collection preparations
       
   461     InitSingleMoveOrCopyL( aMdsId );
       
   462             
       
   463     MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: copying: %S", &iSourcePath);
       
   464     MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: to     : %S", &iTargetPath);
       
   465     
       
   466     TBool completed = ETrue; // set to avoid warning
       
   467     TRAPD( err, completed = iFileCopier->CopyL( iSourcePath, iTargetPath ) );
       
   468     
       
   469     if ( completed || err )
       
   470         {
       
   471         HandleFileCopyCompletedL( err );
       
   472         }
       
   473     }    
       
   474 
       
   475 // ----------------------------------------------------------------------------
       
   476 // CVcxMyVideosAsyncFileOperations::InitSingleMoveOrCopyL
       
   477 // ----------------------------------------------------------------------------
       
   478 //
       
   479 void CVcxMyVideosAsyncFileOperations::InitSingleMoveOrCopyL( TUint32 aMdsId )
       
   480     {
   418     //get media from cache or mds
   481     //get media from cache or mds
   419     TInt pos;
   482     TInt pos;
   420     CMPXMedia* videoInCache = iCollection.iCache->FindVideoByMdsIdL( aMdsId, pos );
   483     CMPXMedia* videoInCache = iCollection.iCache->FindVideoByMdsIdL( aMdsId, pos );
   421 
   484 
   422     CMPXMedia* video = NULL;
   485     CMPXMedia* video = NULL;
   428     if ( !video )
   491     if ( !video )
   429         {
   492         {
   430         video = iCollection.iMyVideosMdsDb->CreateVideoL( aMdsId, EFalse /* brief details */ );
   493         video = iCollection.iMyVideosMdsDb->CreateVideoL( aMdsId, EFalse /* brief details */ );
   431         }
   494         }
   432         
   495         
       
   496     if ( !video )
       
   497         {
       
   498         MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: mds id %d not found from mds or cache", aMdsId);
       
   499         User::Leave( KErrNotFound );
       
   500         }
       
   501 
   433     CleanupStack::PushL( video ); // 1->
   502     CleanupStack::PushL( video ); // 1->
   434     
   503     
   435     // sanity checks
   504     // sanity checks
   436     if ( video->ValueTObjectL<TUint32>( KVcxMediaMyVideosDownloadId ) != 0 )
   505     if ( TVcxMyVideosCollectionUtil::DownloadIdL( *video ) != 0 )
   437         {
   506         {
   438         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: file is being downloaded, fail, leaving with KErrInUse code.");
   507         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: file is being downloaded, fail, leaving with KErrInUse code.");
   439         User::Leave( KErrInUse );
   508         User::Leave( KErrInUse );
   440         }
   509         }
   441 
   510 
   442     const TInt KMaxPathLength = 255;    
   511     iSourcePath = video->ValueText( KMPXMediaGeneralUri );
   443     TBuf<KMaxPathLength> sourcePath( video->ValueText( KMPXMediaGeneralUri ) );
       
   444             
   512             
   445     MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: source path = %S", &sourcePath);
   513     if ( !DriveHasEnoughFreeSpaceL( iSourcePath, iTargetDrive ) )
   446 
       
   447     if ( !DriveHasEnoughFreeSpaceL( sourcePath, aTargetDrive ) )
       
   448         {
   514         {
   449         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: target drive full -> skipping");
   515         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: target drive full -> skipping");
   450         User::Leave( KErrDiskFull );
   516         User::Leave( KErrDiskFull );
   451         }
   517         }
   452 
   518 
       
   519     TUint att = 0;
       
   520     iCollection.iFs.Att( iSourcePath, att);    
       
   521     if ( iIsMoveOperation && (att & KEntryAttReadOnly) )
       
   522         {
       
   523         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: move operation and source file is read only -> skipping");
       
   524         User::Leave( KErrAccessDenied );
       
   525         }
       
   526 
   453     TInt sourceDrive;
   527     TInt sourceDrive;
   454     User::LeaveIfError( iCollection.iFs.CharToDrive( sourcePath[0], sourceDrive ) );
   528     User::LeaveIfError( iCollection.iFs.CharToDrive( iSourcePath[0], sourceDrive ) );
   455 
   529 
   456     if ( sourceDrive == aTargetDrive )
   530     if ( sourceDrive == iTargetDrive )
   457         {
   531         {
   458         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: source and target drives are the same, doing nothing.");
   532         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: source and target drives are the same, leaving with KErrAlreadyExists.");
   459         CleanupStack::PopAndDestroy( video ); // <-1
   533         CleanupStack::PopAndDestroy( video ); // <-1
   460         return;
   534         User::Leave( KErrAlreadyExists );
   461         }
   535         }
   462 
   536     
   463     TBuf<KMaxPathLength> targetPath;
   537     GenerateTargetPathForMoveOrCopyL( iSourcePath, iTargetPath, iTargetDrive );
   464     
   538 
   465     GenerateTargetPathForMoveOrCopyL( sourcePath, targetPath, aTargetDrive );
   539     MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: target path = %S", &iTargetPath );
   466 
       
   467     MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: target path = %S", &targetPath );
       
   468     
   540     
   469     // update mds and cache
   541     // update mds and cache
   470     CMPXMedia* mediaForMoveOp = NULL;
   542     delete iMediaForMoveOp;
   471     CMPXMedia* mediaForCopyOp = NULL;
   543     iMediaForMoveOp = NULL;
   472     if ( aMove )
   544     delete iMediaForCopyOp;
       
   545     iMediaForCopyOp = NULL;
       
   546 
       
   547     if ( iIsMoveOperation )
   473         {
   548         {
   474         // Update existing media.
   549         // Update existing media.
   475         // Create new media object with only KMPXMediaGeneralId, and KMPXMediaGeneralUri
   550         // Create new media object with only KMPXMediaGeneralId, and KMPXMediaGeneralUri
   476         // attributes set, that way update is lighter operation.
   551         // attributes set, that way update is lighter operation.
   477         mediaForMoveOp = CMPXMedia::NewL();
   552         iMediaForMoveOp = CMPXMedia::NewL();
   478         CleanupStack::PushL( mediaForMoveOp ); // 2->
   553         iMediaForMoveOp->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId,
   479         mediaForMoveOp->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId,
       
   480                video->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
   554                video->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
   481         mediaForMoveOp->SetTextValueL( KMPXMediaGeneralUri, targetPath );
   555         iMediaForMoveOp->SetTextValueL( KMPXMediaGeneralUri, iTargetPath );
   482         
   556         
   483         iCollection.SetVideoL( *mediaForMoveOp );
   557         iCollection.SetVideoL( *iMediaForMoveOp );
   484         }
   558         }
   485     else
   559     else
   486         {
   560         {
   487         // Create new media.
   561         // Create new media.
   488         mediaForCopyOp = CMPXMedia::CopyL( *video );
   562         iMediaForCopyOp = CMPXMedia::CopyL( *video );
   489         CleanupStack::PushL( mediaForCopyOp ); // 2->
   563         iMediaForCopyOp->SetTextValueL( KMPXMediaGeneralUri, iTargetPath );
   490         mediaForCopyOp->SetTextValueL( KMPXMediaGeneralUri, targetPath );
   564         iCollection.AddVideoToMdsAndCacheL( *iMediaForCopyOp );
   491         iCollection.AddVideoToMdsAndCacheL( *mediaForCopyOp );
   565         }
   492         }
   566  
   493         
   567      CleanupStack::PopAndDestroy( video ); // <-1           
   494     //copy file, delete original if move case
   568     }
   495     TRAPD( err, BaflUtils::EnsurePathExistsL( iCollection.iFs, targetPath ) );
   569 
   496     
   570 
   497     TUint att = 0;
   571 // ----------------------------------------------------------------------------
   498     iCollection.iFs.Att( sourcePath, att);    
   572 // CVcxMyVideosAsyncFileOperations::HandleFileCopyCompletedL
   499     if ( aMove && (att & KEntryAttReadOnly) )
   573 // ----------------------------------------------------------------------------
   500         {
   574 //
   501         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: move operation and source file is read only -> skipping");
   575 void CVcxMyVideosAsyncFileOperations::HandleFileCopyCompletedL( TInt aErr )
   502         err = KErrAccessDenied;
   576     {
   503         }
   577     if ( aErr == KErrNone )
   504          
   578         {
   505     if ( err == KErrNone )
   579         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: Copy succeeded");
   506         {
   580         if ( iIsMoveOperation )
   507         MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: copying: %S", &sourcePath);
   581             {
   508         MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: to     : %S", &targetPath);
   582             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: move case");
   509         err = BaflUtils::CopyFile( iCollection.iFs, sourcePath, targetPath );
   583             aErr = BaflUtils::DeleteFile( iCollection.iFs, iSourcePath );
   510         if ( err == KErrNone )
   584             if ( aErr != KErrNone )
   511             {
       
   512             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: Copy succeeded");
       
   513             if ( aMove )
       
   514                 {
   585                 {
   515                 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: move case");
   586                 MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: delete for source file failed: %d", aErr );
   516                 err = BaflUtils::DeleteFile( iCollection.iFs, sourcePath );
   587                 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: deleting target file");
   517                 if ( err != KErrNone )
   588                 TInt delErr = BaflUtils::DeleteFile( iCollection.iFs, iTargetPath );
       
   589                 if ( delErr != KErrNone )
   518                     {
   590                     {
   519                     MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: delete for source file failed: %d", err );
   591                     MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: delete for target file failed: %d", delErr );
   520                     MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: deleting target file");
       
   521                     TInt delErr = BaflUtils::DeleteFile( iCollection.iFs, targetPath );
       
   522                     if ( delErr != KErrNone )
       
   523                         {
       
   524                         MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: delete for target file failed: %d", delErr );
       
   525                         }
       
   526                     }
   592                     }
   527                 }
   593                 }
   528             }
   594             }
       
   595         }
       
   596     else
       
   597         {
       
   598         MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: CopyFile failed: %d", aErr);
       
   599         }
       
   600     
       
   601     // roll mds and cache back if file operations failed
       
   602     if ( aErr != KErrNone )
       
   603         {
       
   604         if ( iIsMoveOperation )
       
   605             {
       
   606             MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: move failed %d", aErr );
       
   607             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: setting media path back and leaving." );
       
   608             iMediaForMoveOp->SetTextValueL( KMPXMediaGeneralUri, iSourcePath );
       
   609             iCollection.SetVideoL( *iMediaForMoveOp );
       
   610             }
   529         else
   611         else
   530             {
   612             {
   531             MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: CopyFile failed: %d", err);
   613             MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: copy failed %d", aErr );
   532             }
       
   533         }
       
   534     
       
   535     // roll mds and cache back if file operations failed
       
   536     if ( err != KErrNone )
       
   537         {
       
   538         if ( aMove )
       
   539             {
       
   540             MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: move failed %d", err );
       
   541             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: setting media path back and leaving." );
       
   542             mediaForMoveOp->SetTextValueL( KMPXMediaGeneralUri, sourcePath );
       
   543             iCollection.SetVideoL( *mediaForMoveOp );
       
   544             }
       
   545         else
       
   546             {
       
   547             MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: copy failed %d", err );
       
   548             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: deleting the added media object and leaving");
   614             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: deleting the added media object and leaving");
   549             iCollection.iMyVideosMdsDb->RemoveVideo( mediaForCopyOp->ValueTObjectL<TMPXItemId>(
   615             iCollection.iMyVideosMdsDb->RemoveVideo( iMediaForCopyOp->ValueTObjectL<TMPXItemId>(
   550                     KMPXMediaGeneralId ).iId1 );
   616                     KMPXMediaGeneralId ).iId1 );
   551             }
   617             }
   552         User::Leave( err );
   618         }
   553         }
   619     
   554     
   620     delete iMediaForMoveOp;
   555     if ( aMove )
   621     iMediaForMoveOp = NULL;    
   556         {
   622     delete iMediaForCopyOp;
   557         CleanupStack::PopAndDestroy( mediaForMoveOp ); // <-2
   623     iMediaForCopyOp = NULL;
   558         }
   624 
   559     else
   625     User::LeaveIfError( aErr );
   560         {
   626     
   561         CleanupStack::PopAndDestroy( mediaForCopyOp ); // <-2
   627     }
   562         }
   628     
   563     CleanupStack::PopAndDestroy( video ); // <-1
       
   564     }    
       
   565 
       
   566 // ----------------------------------------------------------------------------
   629 // ----------------------------------------------------------------------------
   567 // CVcxMyVideosAsyncFileOperations::DriveHasEnoughFreeSpaceL
   630 // CVcxMyVideosAsyncFileOperations::DriveHasEnoughFreeSpaceL
   568 // ----------------------------------------------------------------------------
   631 // ----------------------------------------------------------------------------
   569 //
   632 //
   570 TBool CVcxMyVideosAsyncFileOperations::DriveHasEnoughFreeSpaceL( const TDesC& aPath, TInt aDrive )
   633 TBool CVcxMyVideosAsyncFileOperations::DriveHasEnoughFreeSpaceL( const TDesC& aPath, TInt aDrive )
   600 //    
   663 //    
   601 void CVcxMyVideosAsyncFileOperations::GenerateTargetPathForMoveOrCopyL(
   664 void CVcxMyVideosAsyncFileOperations::GenerateTargetPathForMoveOrCopyL(
   602         const TDesC& aSourcePath, TDes& aTargetPath, TInt aTargetDrive )
   665         const TDesC& aSourcePath, TDes& aTargetPath, TInt aTargetDrive )
   603     {
   666     {
   604     MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: source path = %S", &aSourcePath );
   667     MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: source path = %S", &aSourcePath );
       
   668     
       
   669     aTargetPath.Zero();
   605     
   670     
   606     TChar targetDriveChar;
   671     TChar targetDriveChar;
   607     User::LeaveIfError( iCollection.iFs.DriveToChar( aTargetDrive, targetDriveChar ) );    
   672     User::LeaveIfError( iCollection.iFs.DriveToChar( aTargetDrive, targetDriveChar ) );    
   608     aTargetPath.Append( targetDriveChar );
   673     aTargetPath.Append( targetDriveChar );
   609     aTargetPath.Append( ':' );
   674     aTargetPath.Append( ':' );
   620     _LIT(KDataDes, "data");
   685     _LIT(KDataDes, "data");
   621         
   686         
   622     if ( sourceDrive == systemDrive )
   687     if ( sourceDrive == systemDrive )
   623         {
   688         {
   624         //remove *:\data\* from the path
   689         //remove *:\data\* from the path
   625         TPtrC pathData( aSourcePath.Mid(3,4) );
   690         const TInt dataWordStartPos = 3;
       
   691         const TInt dataWordLength   = 4;
       
   692         
       
   693         TPtrC pathData( aSourcePath.Mid( dataWordStartPos, dataWordLength ) );
   626         MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: sourcePath.Mid(3,4)= %S", &pathData);
   694         MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: sourcePath.Mid(3,4)= %S", &pathData);
   627 
   695 
   628         if ( aSourcePath.Mid(3,4) == KDataDes )
   696         if ( pathData == KDataDes )
   629             {
   697             {
   630             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: source drive is system drive and 'data' exists in sourcePath");
   698             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: source drive is system drive and 'data' exists in sourcePath");
   631             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: not copying 'data' to the target path");
   699             MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: not copying 'data' to the target path");
   632             aTargetPath.Append( aSourcePath.Mid( 7 ) );
   700             
       
   701             const TInt skipDataWordPos = 7;
       
   702             aTargetPath.Append( aSourcePath.Mid( skipDataWordPos ) );
   633             }
   703             }
   634         else
   704         else
   635             {
   705             {
   636             aTargetPath.Append( aSourcePath.Mid( 2 ) );
   706             const TInt dontSkipDataWordPos = 2;
       
   707             aTargetPath.Append( aSourcePath.Mid( dontSkipDataWordPos ) );
   637             }
   708             }
   638         }    
   709         }    
   639     else if ( aTargetDrive == systemDrive )
   710     else if ( aTargetDrive == systemDrive )
   640         {
   711         {
   641         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: target drive is system drive -> adding 'data' to path");
   712         MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: target drive is system drive -> adding 'data' to path");
   658 // CVcxMyVideosAsyncFileOperations::HandleDeleteStepL
   729 // CVcxMyVideosAsyncFileOperations::HandleDeleteStepL
   659 // ----------------------------------------------------------------------------
   730 // ----------------------------------------------------------------------------
   660 //
   731 //
   661 MVcxMyVideosActiveTaskObserver::TStepResult CVcxMyVideosAsyncFileOperations::HandleDeleteStepL()
   732 MVcxMyVideosActiveTaskObserver::TStepResult CVcxMyVideosAsyncFileOperations::HandleDeleteStepL()
   662     {
   733     {
       
   734     // Reset inactivity timer. This will prevent ThumbAGDaemon start running while
       
   735     // delete is ongoing and failing the operation due to locked file handle.
       
   736     User::ResetInactivityTime();
       
   737     
   663     CMPXMedia& cmd = iCollection.iActiveTask->GetCommand();
   738     CMPXMedia& cmd = iCollection.iActiveTask->GetCommand();
   664     
   739     
   665     //no sanity checks for array items, since we want to generate all events, even if there is nothing to delete
   740     //no sanity checks for array items, since we want to generate all events, even if there is nothing to delete
   666     
   741     
   667     MVcxMyVideosActiveTaskObserver::TStepResult stepResult;
   742     MVcxMyVideosActiveTaskObserver::TStepResult stepResult;