30 #include "rmtputility.h" |
30 #include "rmtputility.h" |
31 #include "cmtpdataprovidercontroller.h" |
31 #include "cmtpdataprovidercontroller.h" |
32 #include "cmtpextensionmapping.h" |
32 #include "cmtpextensionmapping.h" |
33 #include "cmtpdataprovider.h" |
33 #include "cmtpdataprovider.h" |
34 #include "mtpframeworkconst.h" |
34 #include "mtpframeworkconst.h" |
|
35 #include "mtpdebug.h" |
|
36 #include "OstTraceDefinitions.h" |
|
37 #ifdef OST_TRACE_COMPILER_IN_USE |
|
38 #include "rmtputilityTraces.h" |
|
39 #endif |
|
40 |
35 |
41 |
36 using namespace ContentAccess; |
42 using namespace ContentAccess; |
37 // Class constants. |
43 // Class constants. |
38 const TInt KMTPDateStringLength = 15; |
44 const TInt KMTPDateStringLength = 15; |
39 const TInt KMTPDateStringTIndex = 8; |
45 const TInt KMTPDateStringTIndex = 8; |
47 _LIT( KMimeTypeAudio3gpp, "audio/3gpp" ); |
53 _LIT( KMimeTypeAudio3gpp, "audio/3gpp" ); |
48 _LIT( KMimeTypeVideo3gpp, "video/3gpp" ); |
54 _LIT( KMimeTypeVideo3gpp, "video/3gpp" ); |
49 _LIT( KMimeTypeAudioMp4, "audio/mp4" ); |
55 _LIT( KMimeTypeAudioMp4, "audio/mp4" ); |
50 _LIT( KMimeTypeVideoMp4, "video/mp4" ); |
56 _LIT( KMimeTypeVideoMp4, "video/mp4" ); |
51 |
57 |
52 __FLOG_STMT(_LIT8(KComponent,"RMTPUtility");) |
|
53 |
|
54 RMTPUtility::RMTPUtility(): |
58 RMTPUtility::RMTPUtility(): |
55 iFramework(NULL) |
59 iFramework(NULL) |
56 { |
60 { |
57 } |
61 } |
58 |
62 |
59 void RMTPUtility::OpenL(MMTPDataProviderFramework& aFramework) |
63 void RMTPUtility::OpenL(MMTPDataProviderFramework& aFramework) |
60 { |
64 { |
61 __FLOG_OPEN(KMTPSubsystem, KComponent); |
65 OstTraceFunctionEntry0( RMTPUTILITY_OPENL_ENTRY ); |
62 __FLOG(_L8("OpenL - Entry")); |
|
63 |
66 |
64 iFramework = &aFramework; |
67 iFramework = &aFramework; |
65 iSingleton.OpenL(); |
68 iSingleton.OpenL(); |
66 |
69 |
67 __FLOG(_L8("OpenL - Exit")); |
70 OstTraceFunctionExit0( RMTPUTILITY_OPENL_EXIT ); |
68 } |
71 } |
69 |
72 |
70 void RMTPUtility::Close() |
73 void RMTPUtility::Close() |
71 { |
74 { |
72 iSingleton.Close(); |
75 iSingleton.Close(); |
73 iFramework = NULL; |
76 iFramework = NULL; |
74 iFormatMappings.ResetAndDestroy(); |
77 iFormatMappings.ResetAndDestroy(); |
75 __FLOG_CLOSE; |
|
76 } |
78 } |
77 |
79 |
78 /* |
80 /* |
79 * Convert the TTime to the MTP datatime string |
81 * Convert the TTime to the MTP datatime string |
80 * |
82 * |
103 * TTime string format : YYYYMMDD:HHMMSS.MMMMMM |
105 * TTime string format : YYYYMMDD:HHMMSS.MMMMMM |
104 * |
106 * |
105 */ |
107 */ |
106 EXPORT_C TBool RMTPUtility::MTPTimeStr2TTime(const TDesC& aTimeString, TTime& aRet) const |
108 EXPORT_C TBool RMTPUtility::MTPTimeStr2TTime(const TDesC& aTimeString, TTime& aRet) const |
107 { |
109 { |
108 __FLOG(_L8("ConvertMTPTimeStr2TTimeL - Entry")); |
110 OstTraceFunctionEntry0( RMTPUTILITY_MTPTIMESTR2TTIME_ENTRY ); |
109 |
111 |
110 TBool result = EFalse; |
112 TBool result = EFalse; |
111 TInt year = 0; |
113 TInt year = 0; |
112 TMonth month = EJanuary; |
114 TMonth month = EJanuary; |
113 TInt day = 0; |
115 TInt day = 0; |
250 return result; |
253 return result; |
251 } |
254 } |
252 |
255 |
253 EXPORT_C void RMTPUtility::RenameObjectL( TUint aObjectHandle, const TDesC& aNewName ) |
256 EXPORT_C void RMTPUtility::RenameObjectL( TUint aObjectHandle, const TDesC& aNewName ) |
254 { |
257 { |
255 __FLOG(_L8("RenameAssocationObjectL - Entry")); |
258 OstTraceFunctionEntry0( RMTPUTILITY_RENAMEOBJECTL_ENTRY ); |
256 |
259 |
257 CMTPObjectMetaData* meta = CMTPObjectMetaData::NewLC(); |
260 CMTPObjectMetaData* meta = CMTPObjectMetaData::NewLC(); |
258 |
261 |
259 if( !iFramework->ObjectMgr().ObjectL(aObjectHandle, *meta) ) |
262 if( !iFramework->ObjectMgr().ObjectL(aObjectHandle, *meta) ) |
260 { |
263 { |
|
264 OstTrace1( TRACE_ERROR, RMTPUTILITY_RENAMEOBJECTL, "Object information associated with the object handle %d doesn't exist", aObjectHandle ); |
261 User::Leave(KErrNotFound); |
265 User::Leave(KErrNotFound); |
262 } |
266 } |
263 |
267 |
264 if( !BaflUtils::FileExists( iFramework->Fs(), meta->DesC(CMTPObjectMetaData::ESuid) ) ) |
268 if( !BaflUtils::FileExists( iFramework->Fs(), meta->DesC(CMTPObjectMetaData::ESuid) ) ) |
265 { |
269 { |
|
270 OstTraceExt1( TRACE_ERROR, DUP1_RMTPUTILITY_RENAMEOBJECTL, "%S doesn't exist", meta->DesC(CMTPObjectMetaData::ESuid)); |
266 User::Leave(KErrNotFound); |
271 User::Leave(KErrNotFound); |
267 } |
272 } |
268 |
273 |
269 TFileName filename; |
274 TFileName filename; |
270 User::LeaveIfError(BaflUtils::MostSignificantPartOfFullName(meta->DesC(CMTPObjectMetaData::ESuid), filename)); |
275 LEAVEIFERROR(BaflUtils::MostSignificantPartOfFullName(meta->DesC(CMTPObjectMetaData::ESuid), filename), |
|
276 OstTraceExt1( TRACE_ERROR, DUP2_RMTPUTILITY_RENAMEOBJECTL, "extract most significant part of %S failed", meta->DesC(CMTPObjectMetaData::ESuid))); |
271 RBuf oldFullName; |
277 RBuf oldFullName; |
272 oldFullName.CleanupClosePushL(); |
278 oldFullName.CleanupClosePushL(); |
273 |
279 |
274 TInt maxLen = (KMaxFileName > meta->DesC(CMTPObjectMetaData::ESuid).Length()? KMaxFileName: meta->DesC(CMTPObjectMetaData::ESuid).Length()); |
280 TInt maxLen = (KMaxFileName > meta->DesC(CMTPObjectMetaData::ESuid).Length()? KMaxFileName: meta->DesC(CMTPObjectMetaData::ESuid).Length()); |
275 oldFullName.CreateL(maxLen); |
281 oldFullName.CreateL(maxLen); |
297 newFullName.Append(aNewName); |
303 newFullName.Append(aNewName); |
298 |
304 |
299 if(meta->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeAssociation) |
305 if(meta->Uint(CMTPObjectMetaData::EFormatCode) != EMTPFormatCodeAssociation) |
300 { |
306 { |
301 // Modify the filename |
307 // Modify the filename |
302 User::LeaveIfError( iFramework->Fs().Rename(meta->DesC(CMTPObjectMetaData::ESuid), newFullName) ); |
308 LEAVEIFERROR( iFramework->Fs().Rename(meta->DesC(CMTPObjectMetaData::ESuid), newFullName), |
303 |
309 OstTraceExt2( TRACE_ERROR, DUP3_RMTPUTILITY_RENAMEOBJECTL, "Rename %S to %S failed!", |
|
310 meta->DesC(CMTPObjectMetaData::ESuid), newFullName)); |
304 meta->SetDesCL( CMTPObjectMetaData::ESuid, newFullName ); |
311 meta->SetDesCL( CMTPObjectMetaData::ESuid, newFullName ); |
305 iFramework->ObjectMgr().ModifyObjectL(*meta); |
312 iFramework->ObjectMgr().ModifyObjectL(*meta); |
306 } |
313 } |
307 else |
314 else |
308 { |
315 { |
309 // Add backslash. |
316 // Add backslash. |
310 _LIT(KBackSlash, "\\"); |
317 _LIT(KBackSlash, "\\"); |
311 newFullName.Append(KBackSlash); |
318 newFullName.Append(KBackSlash); |
312 // Modify the filename |
319 // Modify the filename |
313 User::LeaveIfError( iFramework->Fs().Rename(meta->DesC(CMTPObjectMetaData::ESuid), newFullName) ); |
320 LEAVEIFERROR( iFramework->Fs().Rename(meta->DesC(CMTPObjectMetaData::ESuid), newFullName), |
|
321 OstTraceExt2( TRACE_ERROR, DUP4_RMTPUTILITY_RENAMEOBJECTL, "Rename %S to %S failed!", |
|
322 meta->DesC(CMTPObjectMetaData::ESuid), newFullName)); |
314 |
323 |
315 meta->SetDesCL( CMTPObjectMetaData::ESuid, newFullName ); |
324 meta->SetDesCL( CMTPObjectMetaData::ESuid, newFullName ); |
316 iFramework->ObjectMgr().ModifyObjectL(*meta); |
325 iFramework->ObjectMgr().ModifyObjectL(*meta); |
317 |
326 |
318 RenameAllChildrenL( meta->Uint(CMTPObjectMetaData::EStorageId), meta->Uint(CMTPObjectMetaData::EHandle), newFullName, oldFullName); |
327 RenameAllChildrenL( meta->Uint(CMTPObjectMetaData::EStorageId), meta->Uint(CMTPObjectMetaData::EHandle), newFullName, oldFullName); |
323 iSingleton.DpController().NotifyDataProvidersL(EMTPRenameObject, static_cast<TAny*>(¶m)); |
332 iSingleton.DpController().NotifyDataProvidersL(EMTPRenameObject, static_cast<TAny*>(¶m)); |
324 } |
333 } |
325 } |
334 } |
326 |
335 |
327 CleanupStack::PopAndDestroy(3);//oldFullName, newFullName,meta |
336 CleanupStack::PopAndDestroy(3);//oldFullName, newFullName,meta |
328 __FLOG(_L8("RenameAssocationObjectL - Exit")); |
337 OstTraceFunctionExit0( RMTPUTILITY_RENAMEOBJECTL_EXIT ); |
329 } |
338 } |
330 |
339 |
331 EXPORT_C TMTPFormatCode RMTPUtility::FormatFromFilename( const TDesC& aFullFileName ) |
340 EXPORT_C TMTPFormatCode RMTPUtility::FormatFromFilename( const TDesC& aFullFileName ) |
332 { |
341 { |
333 if ( aFullFileName.Right( 1 ).CompareF( KTxtBackSlash ) == 0 ) |
342 if ( aFullFileName.Right( 1 ).CompareF( KTxtBackSlash ) == 0 ) |
372 TInt err = KErrNone; |
381 TInt err = KErrNone; |
373 |
382 |
374 if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 ) |
383 if ( file.Ext().CompareF( KTxtExtensionODF ) == 0 ) |
375 { |
384 { |
376 TRAP( err, mime = OdfMimeTypeL( aFullPath ) ); |
385 TRAP( err, mime = OdfMimeTypeL( aFullPath ) ); |
377 __FLOG_VA((_L("ContainerMimeType err %d mime %S"), err, mime)); |
386 OstTraceExt2( TRACE_NORMAL, RMTPUTILITY_CONTAINERMIMETYPE, "ContainerMimeType err %d mime %S", err, *mime ); |
378 } |
387 } |
379 return mime; |
388 return mime; |
380 } |
389 } |
381 |
390 |
382 EXPORT_C void RMTPUtility::FormatExtensionMapping() |
391 EXPORT_C void RMTPUtility::FormatExtensionMapping() |
474 return 1; |
483 return 1; |
475 } |
484 } |
476 |
485 |
477 void RMTPUtility::RenameAllChildrenL(TUint32 aStorageId, TUint32 aParentHandle, const TDesC& aNewFolderName, const TDesC& aOldFolderName) |
486 void RMTPUtility::RenameAllChildrenL(TUint32 aStorageId, TUint32 aParentHandle, const TDesC& aNewFolderName, const TDesC& aOldFolderName) |
478 { |
487 { |
479 __FLOG(_L8("RenameAllChildrenL - Entry")); |
488 OstTraceFunctionEntry0( RMTPUTILITY_RENAMEALLCHILDRENL_ENTRY ); |
480 |
489 |
481 CMTPObjectMetaData* objectInfo(CMTPObjectMetaData::NewLC()); |
490 CMTPObjectMetaData* objectInfo(CMTPObjectMetaData::NewLC()); |
482 TInt count = 0; |
491 TInt count = 0; |
483 RArray<TUint> handles; |
492 RArray<TUint> handles; |
484 CleanupClosePushL(handles); |
493 CleanupClosePushL(handles); |
488 TEntry entry; |
497 TEntry entry; |
489 for(TInt i(0); (i < count); ++i) |
498 for(TInt i(0); (i < count); ++i) |
490 { |
499 { |
491 if (!iFramework->ObjectMgr().ObjectL(handles[i], *objectInfo)) |
500 if (!iFramework->ObjectMgr().ObjectL(handles[i], *objectInfo)) |
492 { |
501 { |
|
502 OstTrace1( TRACE_ERROR, DUP1_RMTPUTILITY_RENAMEALLCHILDRENL, "Object information associated with the object handle %d doesn't exist", handles[i]); |
493 User::Leave(KErrCorrupt); |
503 User::Leave(KErrCorrupt); |
494 } |
504 } |
495 |
505 |
496 /** |
506 /** |
497 * [SP-Format-0x3002]Special processing for PictBridge DP which own 6 dps file with format 0x3002, |
507 * [SP-Format-0x3002]Special processing for PictBridge DP which own 6 dps file with format 0x3002, |
544 |
554 |
545 CleanupStack::PopAndDestroy(2); // rightPartName, entryName |
555 CleanupStack::PopAndDestroy(2); // rightPartName, entryName |
546 } |
556 } |
547 |
557 |
548 CleanupStack::PopAndDestroy(2); //objectInfo; &handles; |
558 CleanupStack::PopAndDestroy(2); //objectInfo; &handles; |
549 |
559 |
550 __FLOG(_L8("RenameAllChildrenL - Exit")); |
560 OstTraceFunctionExit0( RMTPUTILITY_RENAMEALLCHILDRENL_EXIT ); |
551 } |
561 } |
552 |
562 |
553 void RMTPUtility::GetAllDecendents(TUint32 aStorageId, TUint aParentHandle, RArray<TUint>& aHandles) const |
563 void RMTPUtility::GetAllDecendents(TUint32 aStorageId, TUint aParentHandle, RArray<TUint>& aHandles) const |
554 { |
564 { |
555 TInt index = 0; |
565 TInt index = 0; |
611 { |
621 { |
612 mimebuf = HBufC::New( buffer->Length() ); |
622 mimebuf = HBufC::New( buffer->Length() ); |
613 |
623 |
614 if (mimebuf == NULL) |
624 if (mimebuf == NULL) |
615 { |
625 { |
616 User::LeaveIfError( KErrNotFound ); |
626 OstTrace0( TRACE_ERROR, RMTPUTILITY_ODFMIMETYPEL, "malloc buffer for mime failed!" ); |
|
627 User::Leave(KErrNotFound); |
617 } |
628 } |
618 mimebuf->Des().Copy( *buffer ); |
629 mimebuf->Des().Copy( *buffer ); |
619 |
630 |
620 } |
631 } |
621 |
632 |
622 // leave if NULL |
633 // leave if NULL |
623 if ( mimebuf == NULL ) |
634 if ( mimebuf == NULL ) |
624 { |
635 { |
|
636 OstTrace0( TRACE_ERROR, DUP1_RMTPUTILITY_ODFMIMETYPEL, "malloc buffer for mime failed!" ); |
625 User::Leave( KErrNotFound ); |
637 User::Leave( KErrNotFound ); |
626 } |
638 } |
627 |
639 |
628 CleanupStack::PopAndDestroy( buffer ); // - buffer |
640 CleanupStack::PopAndDestroy( buffer ); // - buffer |
629 CleanupStack::PopAndDestroy( content ); // - content |
641 CleanupStack::PopAndDestroy( content ); // - content |
630 } |
642 } |
631 else |
643 else |
632 { |
644 { |
|
645 OstTrace0( TRACE_ERROR, DUP2_RMTPUTILITY_ODFMIMETYPEL, "Not ODF type file!" ); |
633 User::Leave( KErrNotSupported ); |
646 User::Leave( KErrNotSupported ); |
634 } |
647 } |
635 |
648 |
636 return mimebuf; |
649 return mimebuf; |
637 } |
650 } |
641 TLex lex(aString.Mid(2)); //skip 0x |
654 TLex lex(aString.Mid(2)); //skip 0x |
642 TUint formatCode = EMTPFormatCodeUndefined; |
655 TUint formatCode = EMTPFormatCodeUndefined; |
643 lex.Val(formatCode, EHex); |
656 lex.Val(formatCode, EHex); |
644 aMapping.SetFormatCode(static_cast<TMTPFormatCode>(formatCode)); |
657 aMapping.SetFormatCode(static_cast<TMTPFormatCode>(formatCode)); |
645 aState = Extension; |
658 aState = Extension; |
646 __FLOG_VA((_L("ParseFormatCode %S, 0x%x"), &aString, formatCode)); |
659 OstTraceExt2( TRACE_NORMAL, RMTPUTILITY_PARSEFORMATCODE, "ParseFormatCode %S, 0x%x", aString, formatCode ); |
647 } |
660 } |
648 void RMTPUtility::ParseExtension(const TDesC& aString, CMTPExtensionMapping& aMapping, TParseState& aState) |
661 void RMTPUtility::ParseExtension(const TDesC& aString, CMTPExtensionMapping& aMapping, TParseState& aState) |
649 { |
662 { |
650 aMapping.SetExtensionL(aString); |
663 aMapping.SetExtensionL(aString); |
651 aState = EMimeType; |
664 aState = EMimeType; |
652 __FLOG_VA((_L("ParseExtension %S"), &aString)); |
665 OstTraceExt1( TRACE_NORMAL, RMTPUTILITY_PARSEEXTENSION, "ParseExtension %S", aString ); |
653 } |
666 } |
654 void RMTPUtility::ParseMimeType(const TDesC& aString, CMTPExtensionMapping& aMapping, TParseState& aState) |
667 void RMTPUtility::ParseMimeType(const TDesC& aString, CMTPExtensionMapping& aMapping, TParseState& aState) |
655 { |
668 { |
656 aMapping.SetMIMETypeL(aString); |
669 aMapping.SetMIMETypeL(aString); |
657 aState = ESubFormatCode; |
670 aState = ESubFormatCode; |
658 __FLOG_VA((_L("ParseMimeType %S"), &aString)); |
671 OstTraceExt1( TRACE_NORMAL, RMTPUTILITY_PARSEMIMETYPEL, "ParseMimeType %S", aString ); |
659 } |
672 } |
660 void RMTPUtility::ParseSubFormatCode(const TDesC& aString, CMTPExtensionMapping& aMapping, TParseState& aState) |
673 void RMTPUtility::ParseSubFormatCode(const TDesC& aString, CMTPExtensionMapping& aMapping, TParseState& aState) |
661 { |
674 { |
662 iEnumFlag = 1; |
675 iEnumFlag = 1; |
663 TUint32 subFormatCode = 0; |
676 TUint32 subFormatCode = 0; |
674 lex.Val(iEnumFlag, EDecimal); |
687 lex.Val(iEnumFlag, EDecimal); |
675 } |
688 } |
676 } |
689 } |
677 aMapping.SetSubFormatCode(subFormatCode); |
690 aMapping.SetSubFormatCode(subFormatCode); |
678 aState = EnumerationFlag; |
691 aState = EnumerationFlag; |
679 __FLOG_VA((_L("ParseSubFormatCode %S, 0x%x"), &aString, subFormatCode)); |
692 OstTraceExt2( TRACE_NORMAL, RMTPUTILITY_PARSESUBFORMATCODE, "ParseSubFormatCode %S, 0x%x", aString, subFormatCode ); |
680 } |
693 } |
681 void RMTPUtility::ParseEnumerationFlag(const TDesC& aString, CMTPExtensionMapping& aMapping, TParseState& aState) |
694 void RMTPUtility::ParseEnumerationFlag(const TDesC& aString, CMTPExtensionMapping& aMapping, TParseState& aState) |
682 { |
695 { |
683 TUint enumFlag = iEnumFlag; //default is delegate to file DP |
696 TUint enumFlag = iEnumFlag; //default is delegate to file DP |
684 //temp code(iEnumFlag is temp the value should be 1) will remove after the correct their format string |
697 //temp code(iEnumFlag is temp the value should be 1) will remove after the correct their format string |
686 { |
699 { |
687 TLex lex(aString); |
700 TLex lex(aString); |
688 lex.Val(enumFlag, EDecimal); |
701 lex.Val(enumFlag, EDecimal); |
689 } |
702 } |
690 aMapping.SetEnumerationFlag(enumFlag); |
703 aMapping.SetEnumerationFlag(enumFlag); |
691 |
704 |
692 __FLOG_VA((_L8("ParseEnumerationFlag %S, %d"), &aString, enumFlag)); |
705 OstTraceExt2( TRACE_NORMAL, RMTPUTILITY_PARSEENUMERATIONFLAG, "ParseEnumerationFlag %S, %d", aString, enumFlag ); |
693 aState = EParseStateEnd; |
706 aState = EParseStateEnd; |
694 } |
707 } |
695 void RMTPUtility::Parse(const TDesC& aString, CMTPExtensionMapping& aMapping, TParseState& aState) |
708 void RMTPUtility::Parse(const TDesC& aString, CMTPExtensionMapping& aMapping, TParseState& aState) |
696 { |
709 { |
697 switch(aState) |
710 switch(aState) |