32 #include <drmutility.h> |
32 #include <drmutility.h> |
33 #include <bautils.h> |
33 #include <bautils.h> |
34 #include "vcxmyvideoscollectionplugin.h" |
34 #include "vcxmyvideoscollectionplugin.h" |
35 #include "vcxmyvideoscollection.hrh" |
35 #include "vcxmyvideoscollection.hrh" |
36 #include "vcxmyvideoscollectionutil.h" |
36 #include "vcxmyvideoscollectionutil.h" |
37 #include "vcxmyvideosdownloadutil.h" |
|
38 #include "vcxmyvideosvideocache.h" |
37 #include "vcxmyvideosvideocache.h" |
39 #include "vcxmyvideoscategories.h" |
38 #include "vcxmyvideoscategories.h" |
40 #include "vcxmyvideosmessagelist.h" |
39 #include "vcxmyvideosmessagelist.h" |
41 #include "vcxmyvideosasyncfileoperations.h" |
40 #include "vcxmyvideosasyncfileoperations.h" |
42 #include "vcxmyvideosasyncfilecopy.h" |
41 #include "vcxmyvideosasyncfilecopy.h" |
61 // ---------------------------------------------------------------------------- |
60 // ---------------------------------------------------------------------------- |
62 // Destructor. |
61 // Destructor. |
63 // ---------------------------------------------------------------------------- |
62 // ---------------------------------------------------------------------------- |
64 // |
63 // |
65 CVcxMyVideosAsyncFileOperations::~CVcxMyVideosAsyncFileOperations() |
64 CVcxMyVideosAsyncFileOperations::~CVcxMyVideosAsyncFileOperations() |
66 { |
65 { |
67 iOperationIdArray.Close(); |
66 iOperationIdArray.Close(); |
68 iOperationResult.Close(); |
67 iOperationResult.Close(); |
69 delete iFileCopier; |
68 delete iFileCopier; |
70 delete iMediaForMoveOp; |
69 delete iMediaForMoveOp; |
71 delete iMediaForCopyOp; |
70 delete iMediaForCopyOp; |
218 |
217 |
219 // ---------------------------------------------------------------------------- |
218 // ---------------------------------------------------------------------------- |
220 // CVcxMyVideosAsyncFileOperations::HandleMoveOrCopyStepL |
219 // CVcxMyVideosAsyncFileOperations::HandleMoveOrCopyStepL |
221 // ---------------------------------------------------------------------------- |
220 // ---------------------------------------------------------------------------- |
222 // |
221 // |
223 TBool CVcxMyVideosAsyncFileOperations::HandleMoveOrCopyStepL() |
222 MVcxMyVideosActiveTaskObserver::TStepResult |
|
223 CVcxMyVideosAsyncFileOperations::HandleMoveOrCopyStepL() |
224 { |
224 { |
225 // Reset inactivity timer. This will prevent ThumbAGDaemon start running while |
225 // Reset inactivity timer. This will prevent ThumbAGDaemon start running while |
226 // Move/copy is ongoing and failing the operation due to locked file handle. |
226 // Move/copy is ongoing and failing the operation due to locked file handle. |
227 User::ResetInactivityTime(); |
227 User::ResetInactivityTime(); |
228 |
228 |
229 CMPXMedia& cmd = iCollection.iActiveTask->GetCommand(); |
229 CMPXMedia& cmd = iCollection.iActiveTask->GetCommand(); |
230 |
230 |
231 TBool done; |
231 MVcxMyVideosActiveTaskObserver::TStepResult stepResult; |
232 |
232 |
233 if ( iCurrentOperationIndex == 0 && !iFileCopier->CopyIsOngoing() ) |
233 if ( iCurrentOperationIndex == 0 && !iFileCopier->CopyIsOngoing() ) |
234 { |
234 { |
235 InitMoveOrCopyOperationsL( cmd ); |
235 InitMoveOrCopyOperationsL( cmd ); |
236 } |
236 } |
237 |
237 |
238 TRAPD( err, MoveOrCopyVideoL( iOperationIdArray[iCurrentOperationIndex], |
238 TRAPD( err, MoveOrCopyVideoL( iOperationIdArray[iCurrentOperationIndex] ) ); |
239 iTargetDrive )); |
|
240 |
239 |
241 if ( iFileCopier->CopyIsOngoing() && err == KErrNone ) |
240 if ( iFileCopier->CopyIsOngoing() && err == KErrNone ) |
242 { |
241 { |
243 // copy didnt finish yet, lets do some more steps before jumping to next file |
242 // copy didnt finish yet, lets do some more steps before jumping to next file |
244 return EFalse; |
243 return MVcxMyVideosActiveTaskObserver::EMoreToCome; |
245 } |
244 } |
246 |
245 |
247 iOperationResult.AppendL( err ); |
246 iOperationResult.AppendL( err ); |
248 |
247 |
249 iCurrentOperationIndex++; |
248 iCurrentOperationIndex++; |
250 |
249 |
251 // End operations |
250 // End operations |
252 if ( iCurrentOperationIndex > (iOperationIdArray.Count() - 1) ) |
251 if ( iCurrentOperationIndex > (iOperationIdArray.Count() - 1) ) |
253 { |
252 { |
254 iCurrentOperationIndex = 0; |
253 iCurrentOperationIndex = 0; |
255 done = ETrue; |
254 stepResult = MVcxMyVideosActiveTaskObserver::EDone; |
256 if ( iIsMoveOperation ) |
255 if ( iIsMoveOperation ) |
257 { |
256 { |
258 SendOperationRespL( KVcxMessageMyVideosMoveResp ); |
257 SendOperationRespL( KVcxMessageMyVideosMoveResp ); |
259 } |
258 } |
260 else |
259 else |
262 SendOperationRespL( KVcxMessageMyVideosCopyResp ); |
261 SendOperationRespL( KVcxMessageMyVideosCopyResp ); |
263 } |
262 } |
264 } |
263 } |
265 else |
264 else |
266 { |
265 { |
267 done = EFalse; |
266 stepResult = MVcxMyVideosActiveTaskObserver::EMoreToCome; |
268 } |
267 } |
269 |
268 |
270 return done; |
269 return stepResult; |
271 } |
270 } |
272 |
271 |
273 // ---------------------------------------------------------------------------- |
272 // ---------------------------------------------------------------------------- |
274 // CVcxMyVideosAsyncFileOperations::InitMoveOrCopyOperationsL |
273 // CVcxMyVideosAsyncFileOperations::InitMoveOrCopyOperationsL |
275 // ---------------------------------------------------------------------------- |
274 // ---------------------------------------------------------------------------- |
327 // CVcxMyVideosAsyncFileOperations::CancelOperationL |
326 // CVcxMyVideosAsyncFileOperations::CancelOperationL |
328 // Called when leave or cancel occurs for the operation, generates resp msg. |
327 // Called when leave or cancel occurs for the operation, generates resp msg. |
329 // ---------------------------------------------------------------------------- |
328 // ---------------------------------------------------------------------------- |
330 // |
329 // |
331 void CVcxMyVideosAsyncFileOperations::CancelOperationL( TInt aErr ) |
330 void CVcxMyVideosAsyncFileOperations::CancelOperationL( TInt aErr ) |
332 { |
331 { |
333 if ( iCollection.iActiveTask->IsActive() ) |
332 if ( iCollection.iActiveTask->IsActive() ) |
334 { |
333 { |
335 TInt mvCmdId = -1; |
334 TInt mvCmdId = -1; |
336 CMPXMedia& cmd = iCollection.iActiveTask->GetCommand(); |
335 CMPXMedia& cmd = iCollection.iActiveTask->GetCommand(); |
337 TMPXCommandId commandId = *cmd.Value<TMPXCommandId>( KMPXCommandGeneralId ); |
336 TMPXCommandId commandId = *cmd.Value<TMPXCommandId>( KMPXCommandGeneralId ); |
438 |
437 |
439 // ---------------------------------------------------------------------------- |
438 // ---------------------------------------------------------------------------- |
440 // CVcxMyVideosAsyncFileOperations::MoveOrCopyVideoL |
439 // CVcxMyVideosAsyncFileOperations::MoveOrCopyVideoL |
441 // ---------------------------------------------------------------------------- |
440 // ---------------------------------------------------------------------------- |
442 // |
441 // |
443 void CVcxMyVideosAsyncFileOperations::MoveOrCopyVideoL( TUint32 aMdsId, TInt aTargetDrive ) |
442 void CVcxMyVideosAsyncFileOperations::MoveOrCopyVideoL( TUint32 aMdsId ) |
444 { |
443 { |
445 if ( iFileCopier->CopyIsOngoing() ) |
444 if ( iFileCopier->CopyIsOngoing() ) |
446 { |
445 { |
447 TInt err = iFileCopier->DoNextBlockCopy(); |
446 TInt err = iFileCopier->DoNextBlockCopy(); |
448 if ( err != KErrNone || !iFileCopier->CopyIsOngoing() ) |
447 if ( err != KErrNone || !iFileCopier->CopyIsOngoing() ) |
451 } |
450 } |
452 return; |
451 return; |
453 } |
452 } |
454 |
453 |
455 //New file copy starts -> do sanity checks and mds and collection preparations |
454 //New file copy starts -> do sanity checks and mds and collection preparations |
456 InitSingleMoveOrCopyL( aMdsId, aTargetDrive ); |
455 InitSingleMoveOrCopyL( aMdsId ); |
457 |
456 |
458 MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: copying: %S", &iSourcePath); |
457 MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: copying: %S", &iSourcePath); |
459 MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: to : %S", &iTargetPath); |
458 MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: to : %S", &iTargetPath); |
460 |
459 |
461 TBool completed = ETrue; // set to avoid warning |
460 TBool completed = ETrue; // set to avoid warning |
469 |
468 |
470 // ---------------------------------------------------------------------------- |
469 // ---------------------------------------------------------------------------- |
471 // CVcxMyVideosAsyncFileOperations::InitSingleMoveOrCopyL |
470 // CVcxMyVideosAsyncFileOperations::InitSingleMoveOrCopyL |
472 // ---------------------------------------------------------------------------- |
471 // ---------------------------------------------------------------------------- |
473 // |
472 // |
474 void CVcxMyVideosAsyncFileOperations::InitSingleMoveOrCopyL( TUint32 aMdsId, TInt aTargetDrive ) |
473 void CVcxMyVideosAsyncFileOperations::InitSingleMoveOrCopyL( TUint32 aMdsId ) |
475 { |
474 { |
476 //get media from cache or mds |
475 //get media from cache or mds |
477 TInt pos; |
476 TInt pos; |
478 CMPXMedia* videoInCache = iCollection.iCache->FindVideoByMdsIdL( aMdsId, pos ); |
477 CMPXMedia* videoInCache = iCollection.iCache->FindVideoByMdsIdL( aMdsId, pos ); |
479 |
478 |
495 } |
494 } |
496 |
495 |
497 CleanupStack::PushL( video ); // 1-> |
496 CleanupStack::PushL( video ); // 1-> |
498 |
497 |
499 // sanity checks |
498 // sanity checks |
500 if ( video->ValueTObjectL<TUint32>( KVcxMediaMyVideosDownloadId ) != 0 ) |
499 if ( TVcxMyVideosCollectionUtil::DownloadIdL( *video ) != 0 ) |
501 { |
500 { |
502 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: file is being downloaded, fail, leaving with KErrInUse code."); |
501 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: file is being downloaded, fail, leaving with KErrInUse code."); |
503 User::Leave( KErrInUse ); |
502 User::Leave( KErrInUse ); |
504 } |
503 } |
505 |
504 |
506 iSourcePath = video->ValueText( KMPXMediaGeneralUri ); |
505 iSourcePath = video->ValueText( KMPXMediaGeneralUri ); |
507 |
506 |
508 if ( !DriveHasEnoughFreeSpaceL( iSourcePath, aTargetDrive ) ) |
507 if ( !DriveHasEnoughFreeSpaceL( iSourcePath, iTargetDrive ) ) |
509 { |
508 { |
510 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: target drive full -> skipping"); |
509 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: target drive full -> skipping"); |
511 User::Leave( KErrDiskFull ); |
510 User::Leave( KErrDiskFull ); |
512 } |
511 } |
513 |
512 |
520 } |
519 } |
521 |
520 |
522 TInt sourceDrive; |
521 TInt sourceDrive; |
523 User::LeaveIfError( iCollection.iFs.CharToDrive( iSourcePath[0], sourceDrive ) ); |
522 User::LeaveIfError( iCollection.iFs.CharToDrive( iSourcePath[0], sourceDrive ) ); |
524 |
523 |
525 if ( sourceDrive == aTargetDrive ) |
524 if ( sourceDrive == iTargetDrive ) |
526 { |
525 { |
527 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: source and target drives are the same, leaving with KErrAlreadyExists."); |
526 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: source and target drives are the same, leaving with KErrAlreadyExists."); |
528 CleanupStack::PopAndDestroy( video ); // <-1 |
527 CleanupStack::PopAndDestroy( video ); // <-1 |
529 User::Leave( KErrAlreadyExists ); |
528 User::Leave( KErrAlreadyExists ); |
530 } |
529 } |
531 |
530 |
532 GenerateTargetPathForMoveOrCopyL( iSourcePath, iTargetPath, aTargetDrive ); |
531 GenerateTargetPathForMoveOrCopyL( iSourcePath, iTargetPath, iTargetDrive ); |
533 |
532 |
534 MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: target path = %S", &iTargetPath ); |
533 MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: target path = %S", &iTargetPath ); |
535 |
534 |
536 // update mds and cache |
535 // update mds and cache |
537 delete iMediaForMoveOp; |
536 delete iMediaForMoveOp; |
680 _LIT(KDataDes, "data"); |
679 _LIT(KDataDes, "data"); |
681 |
680 |
682 if ( sourceDrive == systemDrive ) |
681 if ( sourceDrive == systemDrive ) |
683 { |
682 { |
684 //remove *:\data\* from the path |
683 //remove *:\data\* from the path |
685 TPtrC pathData( aSourcePath.Mid(3,4) ); |
684 const TInt dataWordStartPos = 3; |
|
685 const TInt dataWordLength = 4; |
|
686 |
|
687 TPtrC pathData( aSourcePath.Mid( dataWordStartPos, dataWordLength ) ); |
686 MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: sourcePath.Mid(3,4)= %S", &pathData); |
688 MPX_DEBUG2("CVcxMyVideosAsyncFileOperations:: sourcePath.Mid(3,4)= %S", &pathData); |
687 |
689 |
688 if ( aSourcePath.Mid(3,4) == KDataDes ) |
690 if ( pathData == KDataDes ) |
689 { |
691 { |
690 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: source drive is system drive and 'data' exists in sourcePath"); |
692 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: source drive is system drive and 'data' exists in sourcePath"); |
691 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: not copying 'data' to the target path"); |
693 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: not copying 'data' to the target path"); |
692 aTargetPath.Append( aSourcePath.Mid( 7 ) ); |
694 |
|
695 const TInt skipDataWordPos = 7; |
|
696 aTargetPath.Append( aSourcePath.Mid( skipDataWordPos ) ); |
693 } |
697 } |
694 else |
698 else |
695 { |
699 { |
696 aTargetPath.Append( aSourcePath.Mid( 2 ) ); |
700 const TInt dontSkipDataWordPos = 2; |
|
701 aTargetPath.Append( aSourcePath.Mid( dontSkipDataWordPos ) ); |
697 } |
702 } |
698 } |
703 } |
699 else if ( aTargetDrive == systemDrive ) |
704 else if ( aTargetDrive == systemDrive ) |
700 { |
705 { |
701 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: target drive is system drive -> adding 'data' to path"); |
706 MPX_DEBUG1("CVcxMyVideosAsyncFileOperations:: target drive is system drive -> adding 'data' to path"); |
716 |
721 |
717 // ---------------------------------------------------------------------------- |
722 // ---------------------------------------------------------------------------- |
718 // CVcxMyVideosAsyncFileOperations::HandleDeleteStepL |
723 // CVcxMyVideosAsyncFileOperations::HandleDeleteStepL |
719 // ---------------------------------------------------------------------------- |
724 // ---------------------------------------------------------------------------- |
720 // |
725 // |
721 TBool CVcxMyVideosAsyncFileOperations::HandleDeleteStepL() |
726 MVcxMyVideosActiveTaskObserver::TStepResult CVcxMyVideosAsyncFileOperations::HandleDeleteStepL() |
722 { |
727 { |
723 // Reset inactivity timer. This will prevent ThumbAGDaemon start running while |
728 // Reset inactivity timer. This will prevent ThumbAGDaemon start running while |
724 // delete is ongoing and failing the operation due to locked file handle. |
729 // delete is ongoing and failing the operation due to locked file handle. |
725 User::ResetInactivityTime(); |
730 User::ResetInactivityTime(); |
726 |
731 |
727 CMPXMedia& cmd = iCollection.iActiveTask->GetCommand(); |
732 CMPXMedia& cmd = iCollection.iActiveTask->GetCommand(); |
728 |
733 |
729 //no sanity checks for array items, since we want to generate all events, even if there is nothing to delete |
734 //no sanity checks for array items, since we want to generate all events, even if there is nothing to delete |
730 |
735 |
731 TBool done; |
736 MVcxMyVideosActiveTaskObserver::TStepResult stepResult; |
732 |
737 |
733 TUint32 cmdId = cmd.ValueTObjectL<TUint32>( KVcxMediaMyVideosCommandId ); |
738 TUint32 cmdId = cmd.ValueTObjectL<TUint32>( KVcxMediaMyVideosCommandId ); |
734 |
739 |
735 // Start operations |
740 // Start operations |
736 if ( iCurrentOperationIndex == 0 ) |
741 if ( iCurrentOperationIndex == 0 ) |