11 // Contributors: |
11 // Contributors: |
12 // |
12 // |
13 // Description: |
13 // Description: |
14 // |
14 // |
15 |
15 |
|
16 #include <bautils.h> |
16 #include <mtp/cmtpstoragemetadata.h> |
17 #include <mtp/cmtpstoragemetadata.h> |
17 #include <mtp/mmtpconnection.h> |
18 #include <mtp/mmtpconnection.h> |
18 #include <mtp/mmtpdataproviderframework.h> |
19 #include <mtp/mmtpdataproviderframework.h> |
|
20 #include <mtp/mmtpobjectmgr.h> |
19 #include <mtp/mtpdataproviderapitypes.h> |
21 #include <mtp/mtpdataproviderapitypes.h> |
20 #include <mtp/tmtptyperequest.h> |
22 #include <mtp/tmtptyperequest.h> |
|
23 #include <mtp/cmtptypestring.h> |
|
24 #include <mtp/cmtpobjectmetadata.h> |
21 |
25 |
22 #include "cmtpdevdpexclusionmgr.h" |
26 #include "cmtpdevdpexclusionmgr.h" |
23 #include "cmtpdevicedatastore.h" |
27 #include "cmtpdevicedatastore.h" |
24 #include "cmtpdevicedp.h" |
28 #include "cmtpdevicedp.h" |
25 #include "cmtpdevicedpconfigmgr.h" |
29 #include "cmtpdevicedpconfigmgr.h" |
353 |
357 |
354 } |
358 } |
355 CleanupStack::PopAndDestroy(&extnUidArray); |
359 CleanupStack::PopAndDestroy(&extnUidArray); |
356 } |
360 } |
357 |
361 |
|
362 void CMTPDeviceDataProvider::AddFolderRecursiveL( const TMTPNotificationParamsFolderChange& aFolder ) |
|
363 { |
|
364 __FLOG(_L8("AddFolderRecursiveL - Entry")); |
|
365 |
|
366 TPtrC folderRight( aFolder.iFolderChanged ); |
|
367 __FLOG_VA((_L16("Folder Addition - DriveAndFullPath:%S"), &folderRight )); |
|
368 |
|
369 if ( !BaflUtils::FolderExists( Framework().Fs(), folderRight )) |
|
370 { |
|
371 __FLOG(_L8("Folder not exist in file system")); |
|
372 User::Leave( KErrArgument ); |
|
373 } |
|
374 |
|
375 TUint32 parentHandle( KMTPHandleNoParent ); |
|
376 TUint32 handle( KMTPHandleNoParent ); |
|
377 TInt pos( KErrNotFound ); |
|
378 TInt lengthOfRight( folderRight.Length()); |
|
379 TFileName folderLeft; |
|
380 |
|
381 _LIT( KRootFolder, "?:\\"); |
|
382 |
|
383 /* |
|
384 Go through from beginning. |
|
385 when this while end, folderLeft keeps the top |
|
386 layer folder which has no handle |
|
387 */ |
|
388 do |
|
389 { |
|
390 pos = folderRight.Locate( KPathDelimiter ); |
|
391 if ( KErrNotFound == pos ) |
|
392 { |
|
393 break; |
|
394 } |
|
395 folderLeft.Append( folderRight.Left( pos + 1 )); |
|
396 lengthOfRight = folderRight.Length()-pos -1; |
|
397 folderRight.Set( folderRight.Right( lengthOfRight )); |
|
398 |
|
399 if ( KErrNotFound != folderLeft.Match( KRootFolder )) |
|
400 { |
|
401 //first time, root folder |
|
402 //continue |
|
403 continue; |
|
404 } |
|
405 parentHandle = handle; |
|
406 handle = Framework().ObjectMgr().HandleL( folderLeft ); |
|
407 } |
|
408 while( KMTPHandleNone != handle ); |
|
409 |
|
410 |
|
411 if ( KMTPHandleNone == handle ) |
|
412 { |
|
413 __FLOG(_L8("need to add entry into mtp database")); |
|
414 |
|
415 CMTPObjectMetaData* folderObject = CMTPObjectMetaData::NewL(); |
|
416 TUint32 storageId = GetStorageIdL( folderLeft ); |
|
417 |
|
418 while( 1 ) |
|
419 { |
|
420 parentHandle = AddEntryL( folderLeft, parentHandle, storageId, *folderObject ); |
|
421 OnDeviceFolderChangedL( EMTPEventCodeObjectAdded, *folderObject ); |
|
422 |
|
423 pos = folderRight.Locate( KPathDelimiter ); |
|
424 lengthOfRight = folderRight.Length()-pos -1; |
|
425 if ( KErrNotFound == pos ) |
|
426 { |
|
427 break; |
|
428 } |
|
429 folderLeft.Append( folderRight.Left( pos + 1 )); |
|
430 folderRight.Set( folderRight.Right( lengthOfRight )); |
|
431 } |
|
432 |
|
433 delete folderObject; |
|
434 } |
|
435 |
|
436 __FLOG(_L8("AddFolderRecursiveL - Exit")); |
|
437 } |
|
438 |
|
439 TUint32 CMTPDeviceDataProvider::AddEntryL( const TDesC& aPath, TUint32 aParentHandle, TUint32 aStorageId, CMTPObjectMetaData& aObjectInfo ) |
|
440 { |
|
441 __FLOG(_L8("AddEntryL - Entry")); |
|
442 |
|
443 TBool isFolder( EFalse ); |
|
444 BaflUtils::IsFolder( Framework().Fs(), aPath, isFolder ); |
|
445 |
|
446 __ASSERT_ALWAYS( isFolder, User::Leave( KErrArgument )); |
|
447 __ASSERT_ALWAYS( aParentHandle != KMTPHandleNone, User::Leave( KErrArgument )); |
|
448 __ASSERT_ALWAYS( Framework().StorageMgr().ValidStorageId( aStorageId ), User::Invariant()); |
|
449 |
|
450 __FLOG_VA((_L16("Add Entry for Path:%S"), &aPath )); |
|
451 aObjectInfo.SetUint( CMTPObjectMetaData::EDataProviderId, Framework().DataProviderId() ); |
|
452 aObjectInfo.SetUint( CMTPObjectMetaData::EFormatCode, EMTPFormatCodeAssociation ); |
|
453 aObjectInfo.SetUint( CMTPObjectMetaData::EStorageId, aStorageId ); |
|
454 aObjectInfo.SetDesCL( CMTPObjectMetaData::ESuid, aPath ); |
|
455 aObjectInfo.SetUint( CMTPObjectMetaData::EFormatSubCode, EMTPAssociationTypeGenericFolder ); |
|
456 aObjectInfo.SetUint( CMTPObjectMetaData::EParentHandle, aParentHandle ); |
|
457 aObjectInfo.SetUint( CMTPObjectMetaData::ENonConsumable, EMTPConsumable ); |
|
458 |
|
459 //For example |
|
460 //C:\\Documents\\Sample\\Sample1\\ |
|
461 //Then "Sample1" is inserted into folderObjects |
|
462 TUint length = aPath.Length()-1;//remove '\' |
|
463 TPtrC tailFolder( aPath.Ptr(), length ); |
|
464 TInt pos = tailFolder.LocateReverse( KPathDelimiter ) + 1; |
|
465 tailFolder.Set( tailFolder.Right(length - pos)); |
|
466 |
|
467 aObjectInfo.SetDesCL( CMTPObjectMetaData::EName, tailFolder ); |
|
468 |
|
469 Framework().ObjectMgr().InsertObjectL( aObjectInfo ); |
|
470 __FLOG(_L8("AddEntryL - Exit")); |
|
471 |
|
472 return aObjectInfo.Uint( CMTPObjectMetaData::EHandle ); |
|
473 } |
|
474 |
|
475 TUint32 CMTPDeviceDataProvider::GetStorageIdL( const TDesC& aPath ) |
|
476 { |
|
477 __FLOG(_L8("GetStorageId - Entry")); |
|
478 |
|
479 TChar driveLetter = aPath[0]; |
|
480 TInt drive; |
|
481 User::LeaveIfError( Framework().Fs().CharToDrive( driveLetter, drive )); |
|
482 |
|
483 __FLOG(_L8("GetStorageId - Exit")); |
|
484 |
|
485 return Framework().StorageMgr().FrameworkStorageId( static_cast<TDriveNumber>( drive )); |
|
486 } |
|
487 |
|
488 void CMTPDeviceDataProvider::OnDeviceFolderChangedL( TMTPEventCode aEventCode, CMTPObjectMetaData& aObjectInfo ) |
|
489 { |
|
490 __FLOG(_L8("OnDeviceFolderChangedL - Entry")); |
|
491 |
|
492 iEvent.Reset(); |
|
493 |
|
494 switch( aEventCode ) |
|
495 { |
|
496 case EMTPEventCodeObjectAdded: |
|
497 { |
|
498 __FLOG(_L8("Send event for object add")); |
|
499 iEvent.SetUint16( TMTPTypeEvent::EEventCode, EMTPEventCodeObjectAdded ); |
|
500 iEvent.SetUint32( TMTPTypeEvent::EEventSessionID, KMTPSessionAll ); |
|
501 iEvent.SetUint32( TMTPTypeEvent::EEventTransactionID, KMTPTransactionIdNone ); |
|
502 TUint32 handle = aObjectInfo.Uint( CMTPObjectMetaData::EHandle ); |
|
503 iEvent.SetUint32( TMTPTypeEvent::EEventParameter1, handle ); |
|
504 } |
|
505 break; |
|
506 default: |
|
507 break; |
|
508 } |
|
509 |
|
510 Framework().SendEventL(iEvent); |
|
511 |
|
512 __FLOG(_L8("OnDeviceFolderChangedL - Exit")); |
|
513 } |
|
514 |
358 /** |
515 /** |
359 Second phase constructor. |
516 Second phase constructor. |
360 */ |
517 */ |
361 void CMTPDeviceDataProvider::ConstructL() |
518 void CMTPDeviceDataProvider::ConstructL() |
362 { |
519 { |