15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
18 |
19 #include <bautils.h> |
19 #include <bautils.h> |
20 #include <mtp/mmtpdataproviderframework.h> |
|
21 #include <mtp/mmtpobjectmgr.h> |
20 #include <mtp/mmtpobjectmgr.h> |
22 #include <mtp/mmtpstoragemgr.h> |
21 #include <mtp/mmtpstoragemgr.h> |
23 #include <mtp/cmtpobjectmetadata.h> |
|
24 #include <mtp/cmtptypearray.h> |
22 #include <mtp/cmtptypearray.h> |
25 #include <mtp/cmtptypestring.h> |
23 #include <mtp/cmtptypestring.h> |
26 #include <mtp/cmtptypeobjectproplist.h> |
24 #include <mtp/cmtptypeobjectproplist.h> |
27 |
25 |
28 #include "cmoveobject.h" |
26 #include "cmoveobject.h" |
294 iSameStorage = EFalse; |
292 iSameStorage = EFalse; |
295 |
293 |
296 // Move the file first no matter if it will fail in Get/SetPreviousPropertiesL |
294 // Move the file first no matter if it will fail in Get/SetPreviousPropertiesL |
297 // Already trapped inside |
295 // Already trapped inside |
298 GetPreviousPropertiesL( *iObjectInfo ); |
296 GetPreviousPropertiesL( *iObjectInfo ); |
299 TRAPD( err, SetPropertiesL( oldFileName, aNewFileName ) ); |
297 TRAPD( err, SetPropertiesL( aNewFileName ) ); |
300 |
298 |
301 CFileMan* fileMan = CFileMan::NewL( iFramework.Fs() ); |
299 CFileMan* fileMan = CFileMan::NewL( iFramework.Fs() ); |
302 err = fileMan->Move( oldFileName, aNewFileName ); |
300 err = fileMan->Move( oldFileName, aNewFileName ); |
303 |
301 |
304 if ( err != KErrNone ) |
302 if ( err != KErrNone ) |
358 aObject.Uint( CMTPObjectMetaData::ENonConsumable ) ); |
356 aObject.Uint( CMTPObjectMetaData::ENonConsumable ) ); |
359 break; |
357 break; |
360 |
358 |
361 case EMTPObjectPropCodeName: |
359 case EMTPObjectPropCodeName: |
362 case EMTPObjectPropCodeDateAdded: |
360 case EMTPObjectPropCodeDateAdded: |
363 if ( ( propCode == EMTPObjectPropCodeName ) |
361 case EMTPObjectPropCodeAlbumArtist: |
364 || ( !MmMtpDpUtility::IsVideoL( aObject.DesC( CMTPObjectMetaData::ESuid ), iFramework ) |
362 { |
365 && ( propCode == EMTPObjectPropCodeDateAdded ) ) ) |
363 CMTPTypeString* textData = CMTPTypeString::NewLC(); // + textData |
|
364 |
|
365 TRAP( err, iDpConfig.GetWrapperL().GetObjectMetadataValueL( propCode, |
|
366 *textData, |
|
367 aObject ) ); |
|
368 PRINT1( _L( "MM MTP <> CMoveObject::GetPreviousPropertiesL err = %d" ), err ); |
|
369 |
|
370 if ( err == KErrNone ) |
366 { |
371 { |
367 CMTPTypeString* textData = CMTPTypeString::NewLC(); // + textData |
372 iPropertyElement = &( iPropertyList->ReservePropElemL( handle, propCode ) ); |
368 |
373 iPropertyElement->SetStringL( CMTPTypeObjectPropListElement::EValue, |
369 TRAP( err, iDpConfig.GetWrapperL().GetObjectMetadataValueL( propCode, |
374 textData->StringChars() ); |
370 *textData, |
|
371 aObject ) ); |
|
372 |
|
373 PRINT1( _L( "MM MTP <> CMoveObject::GetPreviousPropertiesL err = %d" ), err ); |
|
374 |
|
375 if ( err == KErrNone ) |
|
376 { |
|
377 iPropertyElement = &( iPropertyList->ReservePropElemL( handle, propCode ) ); |
|
378 iPropertyElement->SetStringL( CMTPTypeObjectPropListElement::EValue, |
|
379 textData->StringChars() ); |
|
380 } |
|
381 else |
|
382 { |
|
383 iPropertyElement = NULL; |
|
384 } |
|
385 |
|
386 CleanupStack::PopAndDestroy( textData ); // - textData |
|
387 } |
375 } |
|
376 else |
|
377 { |
|
378 iPropertyElement = NULL; |
|
379 } |
|
380 |
|
381 CleanupStack::PopAndDestroy( textData ); // - textData |
|
382 } |
388 break; |
383 break; |
389 |
384 |
390 default: |
385 default: |
391 { |
386 { |
392 ServiceGetSpecificObjectPropertyL( propCode, handle, aObject ); |
387 ServiceGetSpecificObjectPropertyL( propCode, handle, aObject ); |
485 // ----------------------------------------------------------------------------- |
481 // ----------------------------------------------------------------------------- |
486 // CMoveObject::SetPropertiesL |
482 // CMoveObject::SetPropertiesL |
487 // Set the object properties in the object property store. |
483 // Set the object properties in the object property store. |
488 // ----------------------------------------------------------------------------- |
484 // ----------------------------------------------------------------------------- |
489 // |
485 // |
490 void CMoveObject::SetPropertiesL( const TDesC& aOldFileName, |
486 void CMoveObject::SetPropertiesL( const TDesC& aNewFileName ) |
491 const TDesC& aNewFileName ) |
487 { |
492 { |
488 PRINT1( _L( "MM MTP => CMoveObject::SetPropertiesL, aNewFileName = %S" ), &aNewFileName ); |
493 PRINT2( _L( "MM MTP => CMoveObject::SetPropertiesL aOldFileName = %S, aNewFileName = %S" ), |
489 |
494 &aOldFileName, |
490 TUint32 formatCode = iObjectInfo->Uint( CMTPObjectMetaData::EFormatCode ); |
495 &aNewFileName ); |
491 if ( formatCode == EMTPFormatCodeAbstractAudioVideoPlaylist ) |
|
492 { |
|
493 // This is used to keep the same behavior in mass storage and device file manager. |
|
494 PRINT( _L( "MM MTP <> CMoveObject::SetPropertiesL Playlist file do not update the MPX DB" ) ); |
|
495 } |
|
496 else |
|
497 // TODO: Need rollback mechanism for consistant with image dp in fw. |
|
498 // Not sure if it should be trap if something wrong with MPX db. |
|
499 { |
|
500 if ( iSameStorage ) |
|
501 { |
|
502 iDpConfig.GetWrapperL().RenameObjectL( *iObjectInfo, aNewFileName ); |
|
503 } |
|
504 else // if the two object in different storage, we should delete the old one and insert new one |
|
505 { |
|
506 iDpConfig.GetWrapperL().DeleteObjectL( *iObjectInfo ); |
|
507 iDpConfig.GetWrapperL().AddObjectL( *iObjectInfo ); |
|
508 |
|
509 // Only leave when getting proplist element from data received by fw. |
|
510 // It should not happen after ReceiveDataL in which construction of proplist already succeed. |
|
511 SetPreviousPropertiesL(); |
|
512 } |
|
513 } |
496 |
514 |
497 iObjectInfo->SetDesCL( CMTPObjectMetaData::ESuid, aNewFileName ); |
515 iObjectInfo->SetDesCL( CMTPObjectMetaData::ESuid, aNewFileName ); |
498 iObjectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId ); |
516 iObjectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId ); |
499 iObjectInfo->SetUint( CMTPObjectMetaData::EParentHandle, iNewParentHandle ); |
517 iObjectInfo->SetUint( CMTPObjectMetaData::EParentHandle, iNewParentHandle ); |
500 iFramework.ObjectMgr().ModifyObjectL( *iObjectInfo ); |
518 iFramework.ObjectMgr().ModifyObjectL( *iObjectInfo ); |
501 |
519 |
502 TUint32 formatCode = iObjectInfo->Uint( CMTPObjectMetaData::EFormatCode ); |
|
503 if ( formatCode == EMTPFormatCodeAbstractAudioVideoPlaylist ) |
|
504 { |
|
505 // This is used to keep the same behavior in mass storage and device file manager. |
|
506 PRINT( _L( "MM MTP <> CMoveObject::SetPropertiesL Playlist file do not update the MPX DB" ) ); |
|
507 } |
|
508 else |
|
509 // TODO: Need rollback mechanism for consistant with image dp in fw. |
|
510 // Not sure if it should be trap if something wrong with MPX db. |
|
511 { |
|
512 if ( iSameStorage ) |
|
513 { |
|
514 iDpConfig.GetWrapperL().RenameObjectL( aOldFileName, aNewFileName ); |
|
515 } |
|
516 else // if the two object in different storage, we should delete the old one and insert new one |
|
517 { |
|
518 iDpConfig.GetWrapperL().DeleteObjectL( aOldFileName, formatCode ); |
|
519 |
|
520 TUint32 subFormatCode = iObjectInfo->Uint( CMTPObjectMetaData::EFormatSubCode ); |
|
521 iDpConfig.GetWrapperL().AddObjectL( aNewFileName, |
|
522 formatCode, |
|
523 subFormatCode ); |
|
524 |
|
525 // Only leave when getting proplist element from data received by fw. |
|
526 // It should not happen after ReceiveDataL in which construction of proplist already succeed. |
|
527 SetPreviousPropertiesL(); |
|
528 } |
|
529 } |
|
530 |
|
531 // It's not necessary to change references of playlists since Reference DB is used PUID |
520 // It's not necessary to change references of playlists since Reference DB is used PUID |
532 |
521 |
533 PRINT( _L( "MM MTP <= CMoveObject::SetPropertiesL" ) ); |
522 PRINT( _L( "MM MTP <= CMoveObject::SetPropertiesL" ) ); |
534 } |
523 } |
535 |
524 |