15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 #include <bautils.h> |
18 #include <bautils.h> |
19 |
19 |
20 #include <mtp/mmtpdataproviderframework.h> |
|
21 #include <mtp/mmtpobjectmgr.h> |
20 #include <mtp/mmtpobjectmgr.h> |
22 #include <mtp/mmtpreferencemgr.h> |
21 #include <mtp/mmtpreferencemgr.h> |
23 #include <mtp/mmtpstoragemgr.h> |
22 #include <mtp/mmtpstoragemgr.h> |
24 #include <mtp/cmtpobjectmetadata.h> |
|
25 #include <mtp/cmtptypestring.h> |
23 #include <mtp/cmtptypestring.h> |
26 #include <mtp/cmtptypearray.h> |
24 #include <mtp/cmtptypearray.h> |
27 #include <mtp/cmtptypeobjectproplist.h> |
25 #include <mtp/cmtptypeobjectproplist.h> |
28 |
26 |
29 #include "ccopyobject.h" |
27 #include "ccopyobject.h" |
91 MMmMtpDpConfig& aDpConfig ) : |
90 MMmMtpDpConfig& aDpConfig ) : |
92 CRequestProcessor( aFramework, |
91 CRequestProcessor( aFramework, |
93 aConnection, |
92 aConnection, |
94 sizeof( KMTPCopyObjectPolicy ) / sizeof( TMTPRequestElementInfo ), |
93 sizeof( KMTPCopyObjectPolicy ) / sizeof( TMTPRequestElementInfo ), |
95 KMTPCopyObjectPolicy ), |
94 KMTPCopyObjectPolicy ), |
96 iDpConfig( aDpConfig ) |
95 iDpConfig( aDpConfig ), |
|
96 iSourceObject( NULL ), |
|
97 iTargetObject( NULL ) |
97 { |
98 { |
98 PRINT( _L( "Operation: CopyObject(0x101A)" ) ); |
99 PRINT( _L( "Operation: CopyObject(0x101A)" ) ); |
99 } |
100 } |
100 |
101 |
101 // ----------------------------------------------------------------------------- |
102 // ----------------------------------------------------------------------------- |
142 RBuf newObjectName; |
143 RBuf newObjectName; |
143 newObjectName.CreateL( KMaxFileName ); |
144 newObjectName.CreateL( KMaxFileName ); |
144 newObjectName.CleanupClosePushL(); // + newObjectName |
145 newObjectName.CleanupClosePushL(); // + newObjectName |
145 newObjectName = *iDest; |
146 newObjectName = *iDest; |
146 |
147 |
147 const TDesC& suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) ); |
148 const TDesC& suid( iSourceObject->DesC( CMTPObjectMetaData::ESuid ) ); |
148 TParsePtrC fileNameParser( suid ); |
149 TParsePtrC fileNameParser( suid ); |
149 if ( ( newObjectName.Length() + fileNameParser.NameAndExt().Length() ) |
150 if ( ( newObjectName.Length() + fileNameParser.NameAndExt().Length() ) |
150 <= newObjectName.MaxLength() ) |
151 <= newObjectName.MaxLength() ) |
151 { |
152 { |
152 newObjectName.Append( fileNameParser.NameAndExt() ); |
153 newObjectName.Append( fileNameParser.NameAndExt() ); |
211 PRINT( _L( "MM MTP <= CCopyObject::GetParametersL" ) ); |
212 PRINT( _L( "MM MTP <= CCopyObject::GetParametersL" ) ); |
212 } |
213 } |
213 |
214 |
214 // ----------------------------------------------------------------------------- |
215 // ----------------------------------------------------------------------------- |
215 // CCopyObject::SetDefaultParentObjectL |
216 // CCopyObject::SetDefaultParentObjectL |
216 // Get a default parent object, ff the request does not specify a parent object, |
217 // Set a default destination, if the request does not specify a parent object, |
217 // ----------------------------------------------------------------------------- |
218 // ----------------------------------------------------------------------------- |
218 // |
219 // |
219 void CCopyObject::SetDefaultParentObjectL() |
220 void CCopyObject::SetDefaultParentObjectL() |
220 { |
221 { |
221 PRINT( _L( "MM MTP => CCopyObject::SetDefaultParentObjectL" ) ); |
222 PRINT( _L( "MM MTP => CCopyObject::SetDefaultParentObjectL" ) ); |
296 // A helper function of CopyFileL |
297 // A helper function of CopyFileL |
297 // ----------------------------------------------------------------------------- |
298 // ----------------------------------------------------------------------------- |
298 // |
299 // |
299 TUint32 CCopyObject::CopyFileL( const TDesC& aNewFileName ) |
300 TUint32 CCopyObject::CopyFileL( const TDesC& aNewFileName ) |
300 { |
301 { |
301 const TDesC& suid( iObjectInfo->DesC( CMTPObjectMetaData::ESuid ) ); |
302 PRINT( _L( "MM MTP => CCopyObject::CopyFileL" ) ); |
302 PRINT2( _L( "MM MTP => CCopyObject::CopyFileL old name = %S, aNewFileName = %S" ), |
303 |
303 &suid, |
304 GetPreviousPropertiesL(); |
304 &aNewFileName ); |
|
305 |
|
306 GetPreviousPropertiesL( *iObjectInfo ); |
|
307 |
305 |
308 // TODO: Need rollback mechanism for consistant with image dp in fw. |
306 // TODO: Need rollback mechanism for consistant with image dp in fw. |
309 // Not sure if it should be trap if something wrong with MPX db. |
307 // Not sure if it should be trap if something wrong with MPX db. |
310 TUint32 handle = AddObjectToStoreL( suid, aNewFileName ); |
308 TPtrC oldFileName( iSourceObject->DesC( CMTPObjectMetaData::ESuid ) ); |
|
309 TUint32 handle = AddObjectToStoreL( oldFileName, aNewFileName ); |
311 |
310 |
312 // Only leave when getting proplist element from data received by fw. |
311 // Only leave when getting proplist element from data received by fw. |
313 // It should not happen after ReceiveDataL in which construction of proplist already succeed. |
312 // It should not happen after ReceiveDataL in which construction of proplist already succeed. |
314 SetPreviousPropertiesL( *iObjectInfo ); |
313 SetPreviousPropertiesL(); |
315 |
314 |
316 CFileMan* fileMan = CFileMan::NewL( iFramework.Fs() ); |
315 CFileMan* fileMan = CFileMan::NewL( iFramework.Fs() ); |
317 User::LeaveIfError( fileMan->Copy( suid, aNewFileName ) ); |
316 User::LeaveIfError( fileMan->Copy( oldFileName, aNewFileName ) ); |
318 delete fileMan; |
317 delete fileMan; |
319 fileMan = NULL; |
318 fileMan = NULL; |
320 |
319 |
321 User::LeaveIfError( iFramework.Fs().SetModified( aNewFileName, |
320 PRINT( _L( "MM MTP <= CCopyObject::CopyFileL" ) ); |
322 iPreviousModifiedTime ) ); |
|
323 |
|
324 PRINT1( _L( "MM MTP <= CCopyObject::CopyFileL handle = 0x%x" ), handle ); |
|
325 |
|
326 return handle; |
321 return handle; |
327 } |
322 } |
328 |
323 |
329 // ----------------------------------------------------------------------------- |
324 // ----------------------------------------------------------------------------- |
330 // CCopyObject::GetPreviousPropertiesL |
325 // CCopyObject::GetPreviousPropertiesL |
331 // Save the object properties before doing the copy |
326 // Save the object properties before doing the copy |
332 // ----------------------------------------------------------------------------- |
327 // ----------------------------------------------------------------------------- |
333 // |
328 // |
334 void CCopyObject::GetPreviousPropertiesL( const CMTPObjectMetaData& aObject ) |
329 void CCopyObject::GetPreviousPropertiesL() |
335 { |
330 { |
336 PRINT( _L( "MM MTP => CCopyObject::GetPreviousPropertiesL" ) ); |
331 PRINT( _L( "MM MTP => CCopyObject::GetPreviousPropertiesL" ) ); |
337 |
332 |
338 const TDesC& suid( aObject.DesC( CMTPObjectMetaData::ESuid ) ); |
333 TUint formatCode = iSourceObject->Uint( CMTPObjectMetaData::EFormatCode ); |
339 User::LeaveIfError( iFramework.Fs().Modified( suid, iPreviousModifiedTime ) ); |
|
340 |
|
341 TUint formatCode = aObject.Uint( CMTPObjectMetaData::EFormatCode ); |
|
342 const RArray<TUint>* properties = iDpConfig.GetSupportedPropertiesL( formatCode ); |
334 const RArray<TUint>* properties = iDpConfig.GetSupportedPropertiesL( formatCode ); |
343 TInt count = properties->Count(); |
335 TInt count = properties->Count(); |
344 |
336 |
345 TInt err = KErrNone; |
337 TInt err = KErrNone; |
346 TUint16 propCode; |
338 TUint16 propCode; |
347 TUint32 handle = aObject.Uint( CMTPObjectMetaData::EHandle ); |
339 TUint32 handle = iSourceObject->Uint( CMTPObjectMetaData::EHandle ); |
348 |
340 |
349 if ( iPropertyElement != NULL ) |
341 if ( iPropertyElement != NULL ) |
350 { |
342 { |
351 delete iPropertyElement; |
343 delete iPropertyElement; |
352 iPropertyElement = NULL; |
344 iPropertyElement = NULL; |
370 break; |
362 break; |
371 |
363 |
372 case EMTPObjectPropCodeNonConsumable: |
364 case EMTPObjectPropCodeNonConsumable: |
373 iPropertyElement = &( iPropertyList->ReservePropElemL( handle, propCode ) ); |
365 iPropertyElement = &( iPropertyList->ReservePropElemL( handle, propCode ) ); |
374 iPropertyElement->SetUint8L( CMTPTypeObjectPropListElement::EValue, |
366 iPropertyElement->SetUint8L( CMTPTypeObjectPropListElement::EValue, |
375 aObject.Uint( CMTPObjectMetaData::ENonConsumable ) ); |
367 iSourceObject->Uint( CMTPObjectMetaData::ENonConsumable ) ); |
376 break; |
368 break; |
377 |
369 |
378 case EMTPObjectPropCodeName: |
370 case EMTPObjectPropCodeName: |
379 case EMTPObjectPropCodeDateAdded: |
371 case EMTPObjectPropCodeDateAdded: |
380 if ( ( propCode == EMTPObjectPropCodeName ) |
372 case EMTPObjectPropCodeAlbumArtist: |
381 || ( !MmMtpDpUtility::IsVideoL( aObject.DesC( CMTPObjectMetaData::ESuid ), iFramework ) |
373 { |
382 && ( propCode == EMTPObjectPropCodeDateAdded ) ) ) |
374 CMTPTypeString* textData = CMTPTypeString::NewLC(); // + textData |
|
375 |
|
376 TRAP( err, iDpConfig.GetWrapperL().GetObjectMetadataValueL( propCode, |
|
377 *textData, |
|
378 *iSourceObject ) ); |
|
379 |
|
380 PRINT1( _L( "MM MTP <> CCopyObject::GetPreviousPropertiesL err = %d" ), err ); |
|
381 |
|
382 if ( err == KErrNone ) |
383 { |
383 { |
384 CMTPTypeString* textData = CMTPTypeString::NewLC(); // + textData |
384 iPropertyElement = &( iPropertyList->ReservePropElemL( handle, propCode ) ); |
385 |
385 iPropertyElement->SetStringL( CMTPTypeObjectPropListElement::EValue, |
386 TRAP( err, iDpConfig.GetWrapperL().GetObjectMetadataValueL( propCode, |
386 textData->StringChars() ); |
387 *textData, |
|
388 aObject ) ); |
|
389 |
|
390 PRINT1( _L( "MM MTP <> CCopyObject::GetPreviousPropertiesL err = %d" ), err ); |
|
391 |
|
392 if ( err == KErrNone ) |
|
393 { |
|
394 iPropertyElement = &( iPropertyList->ReservePropElemL( handle, propCode ) ); |
|
395 iPropertyElement->SetStringL( CMTPTypeObjectPropListElement::EValue, |
|
396 textData->StringChars() ); |
|
397 } |
|
398 else |
|
399 { |
|
400 iPropertyElement = NULL; |
|
401 } |
|
402 |
|
403 CleanupStack::PopAndDestroy( textData ); // - textData |
|
404 } |
387 } |
|
388 else |
|
389 { |
|
390 iPropertyElement = NULL; |
|
391 } |
|
392 |
|
393 CleanupStack::PopAndDestroy( textData ); // - textData |
|
394 } |
405 break; |
395 break; |
406 |
396 |
407 default: |
397 default: |
408 { |
398 { |
409 ServiceGetSpecificObjectPropertyL( propCode, handle, aObject ); |
399 ServiceGetSpecificObjectPropertyL( propCode, handle, *iSourceObject ); |
410 } |
400 } |
411 break; |
401 break; |
412 } |
402 } |
413 |
403 |
414 if ( iPropertyElement != NULL ) |
404 if ( iPropertyElement != NULL ) |
424 // ----------------------------------------------------------------------------- |
414 // ----------------------------------------------------------------------------- |
425 // CCopyObject::SetPreviousPropertiesL |
415 // CCopyObject::SetPreviousPropertiesL |
426 // Set the object properties after doing the copy |
416 // Set the object properties after doing the copy |
427 // ----------------------------------------------------------------------------- |
417 // ----------------------------------------------------------------------------- |
428 // |
418 // |
429 void CCopyObject::SetPreviousPropertiesL( const CMTPObjectMetaData& aObject ) |
419 void CCopyObject::SetPreviousPropertiesL() |
430 { |
420 { |
431 PRINT( _L( "MM MTP => CCopyObject::SetPreviousPropertiesL" ) ); |
421 PRINT( _L( "MM MTP => CCopyObject::SetPreviousPropertiesL" ) ); |
432 |
422 |
433 TMTPResponseCode respcode = EMTPRespCodeOK; |
423 TMTPResponseCode respcode = EMTPRespCodeOK; |
434 |
424 |
459 case EMTPObjectPropCodeDateModified: |
449 case EMTPObjectPropCodeDateModified: |
460 case EMTPObjectPropCodeDateAdded: |
450 case EMTPObjectPropCodeDateAdded: |
461 break; |
451 break; |
462 |
452 |
463 case EMTPObjectPropCodeNonConsumable: |
453 case EMTPObjectPropCodeNonConsumable: |
464 iObjectInfo->SetUint( CMTPObjectMetaData::ENonConsumable, |
454 iTargetObject->SetUint( CMTPObjectMetaData::ENonConsumable, |
465 element.Uint8L( CMTPTypeObjectPropListElement::EValue ) ); |
455 element.Uint8L( CMTPTypeObjectPropListElement::EValue ) ); |
466 // TODO: need to reconsider, |
456 // TODO: need to reconsider, |
467 // should wait all property setting finished then insert object, or not? |
457 // should wait all property setting finished then insert object, or not? |
468 // need to investigate if it will affect performance result |
458 // need to investigate if it will affect performance result |
469 iFramework.ObjectMgr().ModifyObjectL( *iObjectInfo ); |
459 iFramework.ObjectMgr().ModifyObjectL( *iTargetObject ); |
470 break; |
460 break; |
471 |
461 |
472 case EMTPObjectPropCodeName: |
462 case EMTPObjectPropCodeName: |
|
463 case EMTPObjectPropCodeAlbumArtist: |
473 { |
464 { |
474 CMTPTypeString *stringData = CMTPTypeString::NewLC( element.StringL( CMTPTypeObjectPropListElement::EValue ) ); // + stringData |
465 CMTPTypeString *stringData = CMTPTypeString::NewLC( element.StringL( CMTPTypeObjectPropListElement::EValue ) ); // + stringData |
475 |
466 |
476 respcode = iDpConfig.PropSettingUtility()->SetMetaDataToWrapper( iDpConfig, |
467 respcode = iDpConfig.PropSettingUtility()->SetMetaDataToWrapper( iDpConfig, |
477 propertyCode, |
468 propertyCode, |
478 *stringData, |
469 *stringData, |
479 aObject ); |
470 *iTargetObject ); |
480 |
471 |
481 CleanupStack::PopAndDestroy( stringData ); // - stringData |
472 CleanupStack::PopAndDestroy( stringData ); // - stringData |
482 } |
473 } |
483 break; |
474 break; |
484 |
475 |
485 default: |
476 default: |
486 { |
477 { |
487 respcode = iDpConfig.PropSettingUtility()->SetSpecificObjectPropertyL( iDpConfig, |
478 respcode = iDpConfig.PropSettingUtility()->SetSpecificObjectPropertyL( iDpConfig, |
488 propertyCode, |
479 propertyCode, |
489 aObject, |
480 *iTargetObject, |
490 element ); |
481 element ); |
491 } |
482 } |
492 break; |
483 break; |
493 } |
484 } |
494 } // end of for loop |
485 } // end of for loop |
512 { |
503 { |
513 PRINT2( _L( "MM MTP => CCopyObject::AddObjectToStoreL aOldObjectName = %S, aNewObjectName = %S" ), |
504 PRINT2( _L( "MM MTP => CCopyObject::AddObjectToStoreL aOldObjectName = %S, aNewObjectName = %S" ), |
514 &aOldObjectName, |
505 &aOldObjectName, |
515 &aNewObjectName ); |
506 &aNewObjectName ); |
516 |
507 |
517 CMTPObjectMetaData* objectInfo = CMTPObjectMetaData::NewLC(); // + objectInfo |
508 iTargetObject = CMTPObjectMetaData::NewL(); |
518 |
509 |
519 // 1. Add new object into objectMgr db |
510 // 1. Add new object into objectMgr db |
520 objectInfo->SetUint( CMTPObjectMetaData::EDataProviderId, iObjectInfo->Uint( CMTPObjectMetaData::EDataProviderId ) ); |
511 iTargetObject->SetUint( CMTPObjectMetaData::EDataProviderId, iSourceObject->Uint( CMTPObjectMetaData::EDataProviderId ) ); |
521 TUint formatCode = iObjectInfo->Uint( CMTPObjectMetaData::EFormatCode ); |
512 TUint formatCode = iSourceObject->Uint( CMTPObjectMetaData::EFormatCode ); |
522 objectInfo->SetUint( CMTPObjectMetaData::EFormatCode, formatCode ); |
513 iTargetObject->SetUint( CMTPObjectMetaData::EFormatCode, formatCode ); |
523 TUint subFormatCode = iObjectInfo->Uint( CMTPObjectMetaData::EFormatSubCode ); |
514 TUint subFormatCode = iSourceObject->Uint( CMTPObjectMetaData::EFormatSubCode ); |
524 objectInfo->SetUint( CMTPObjectMetaData::EFormatSubCode, subFormatCode ); |
515 iTargetObject->SetUint( CMTPObjectMetaData::EFormatSubCode, subFormatCode ); |
525 objectInfo->SetUint( CMTPObjectMetaData::EParentHandle, iNewParentHandle ); |
516 iTargetObject->SetUint( CMTPObjectMetaData::EParentHandle, iNewParentHandle ); |
526 objectInfo->SetUint( CMTPObjectMetaData::EStorageId, iStorageId ); |
517 iTargetObject->SetUint( CMTPObjectMetaData::EStorageId, iStorageId ); |
527 objectInfo->SetDesCL( CMTPObjectMetaData::ESuid, aNewObjectName ); |
518 iTargetObject->SetDesCL( CMTPObjectMetaData::ESuid, aNewObjectName ); |
528 iFramework.ObjectMgr().InsertObjectL( *objectInfo ); |
519 iFramework.ObjectMgr().InsertObjectL( *iTargetObject ); |
529 |
520 |
530 // 2. Add new object into MPX db |
521 // 2. Add new object into MPX db |
531 iDpConfig.GetWrapperL().AddObjectL( aNewObjectName, formatCode, subFormatCode ); |
522 iDpConfig.GetWrapperL().AddObjectL( *iTargetObject ); |
532 |
523 |
533 // 3. Set references into references db |
524 // 3. Set references into references db |
534 if ( formatCode == EMTPFormatCodeM3UPlaylist ) |
525 if ( formatCode == EMTPFormatCodeM3UPlaylist ) |
535 { |
526 { |
536 MMTPReferenceMgr& referenceMgr = iFramework.ReferenceMgr(); |
527 MMTPReferenceMgr& referenceMgr = iFramework.ReferenceMgr(); |
537 CDesCArray* references = referenceMgr.ReferencesLC( aOldObjectName ); // + references |
528 CDesCArray* references = referenceMgr.ReferencesLC( aOldObjectName ); // + references |
538 referenceMgr.SetReferencesL( aNewObjectName, *references ); |
529 referenceMgr.SetReferencesL( aNewObjectName, *references ); |
539 CleanupStack::PopAndDestroy( references ); // - references |
530 CleanupStack::PopAndDestroy( references ); // - references |
540 } |
531 } |
541 |
532 |
542 TUint32 handle = objectInfo->Uint( CMTPObjectMetaData::EHandle ); |
533 TUint32 handle = iTargetObject->Uint( CMTPObjectMetaData::EHandle ); |
543 CleanupStack::PopAndDestroy( objectInfo ); // - objectInfo |
|
544 |
534 |
545 PRINT1( _L( "MM MTP <= CCopyObject::AddObjectToStoreL handle = 0x%x" ), handle ); |
535 PRINT1( _L( "MM MTP <= CCopyObject::AddObjectToStoreL handle = 0x%x" ), handle ); |
546 return handle; |
536 return handle; |
547 } |
537 } |
548 |
538 |