mmappcomponents/mmmtpdataprovider/src/cmmmtpdpmetadataaccesswrapper.cpp
branchRCL_3
changeset 23 4740b34b83ce
parent 19 51035f0751c2
child 28 f56ec6ce2732
equal deleted inserted replaced
19:51035f0751c2 23:4740b34b83ce
    44     return me;
    44     return me;
    45     }
    45     }
    46 
    46 
    47 CMmMtpDpMetadataAccessWrapper::CMmMtpDpMetadataAccessWrapper( MMTPDataProviderFramework& aFramework ) :
    47 CMmMtpDpMetadataAccessWrapper::CMmMtpDpMetadataAccessWrapper( MMTPDataProviderFramework& aFramework ) :
    48     iFramework( aFramework ),
    48     iFramework( aFramework ),
    49     iFs( aFramework.Fs() )
    49     iFs( aFramework.Fs() ),
       
    50     iOpenCount( 0 )
    50     {
    51     {
    51     // Do nothing
    52     // Do nothing
    52     }
    53     }
    53 
    54 
    54 // ---------------------------------------------------------------------------
    55 // ---------------------------------------------------------------------------
   348 // Called when the MTP session is initialised
   349 // Called when the MTP session is initialised
   349 // -----------------------------------------------------------------------------
   350 // -----------------------------------------------------------------------------
   350 //
   351 //
   351 void CMmMtpDpMetadataAccessWrapper::OpenSessionL()
   352 void CMmMtpDpMetadataAccessWrapper::OpenSessionL()
   352     {
   353     {
   353     iOpenSession = ETrue;
   354     iOpenCount++;
   354     }
   355     }
   355 
   356 
   356 // -----------------------------------------------------------------------------
   357 // -----------------------------------------------------------------------------
   357 // CMmMtpDpMetadataAccessWrapper::CloseSessionL
   358 // CMmMtpDpMetadataAccessWrapper::CloseSessionL
   358 //
   359 //
   359 // -----------------------------------------------------------------------------
   360 // -----------------------------------------------------------------------------
   360 //
   361 //
   361 void CMmMtpDpMetadataAccessWrapper::CloseSessionL()
   362 void CMmMtpDpMetadataAccessWrapper::CloseSessionL()
   362     {
   363     {
   363     if ( iOpenSession )
   364     PRINT1( _L( "MM MTP <> CMmMtpDpMetadataAccessWrapper::CloseSessionL count = %d" ), iOpenCount );
   364         {
   365 
   365         PRINT( _L( "MM MTP <> CMmMtpDpMetadataAccessWrapper::CloseSessionL close" ) );
   366     if ( iOpenCount >= 1 )
   366         iMmMtpDpMetadataVideoAccess->CloseSessionL();
   367         {
   367         iOpenSession = EFalse;
   368         iOpenCount--;
       
   369 
       
   370         if ( iOpenCount == 0 )
       
   371             {
       
   372             PRINT( _L( "MM MTP <> CMmMtpDpMetadataAccessWrapper::CloseSessionL close" ) );
       
   373             iMmMtpDpMetadataMpxAccess->CloseSession();
       
   374             iMmMtpDpMetadataVideoAccess->CloseSessionL();
       
   375             }
   368         }
   376         }
   369     else
   377     else
   370         {
   378         {
   371         PRINT( _L( "MM MTP <> CMmMtpDpMetadataAccessWrapper::CloseSessionL alreay close" ) );
   379         PRINT( _L( "MM MTP <> CMmMtpDpMetadataAccessWrapper::CloseSessionL already close" ) );
   372         }
   380         }
   373     }
   381     }
   374 
   382 
   375 // ---------------------------------------------------------------------------
   383 // ---------------------------------------------------------------------------
   376 // CMmMtpDpMetadataAccessWrapper::Category
   384 // CMmMtpDpMetadataAccessWrapper::Category
   388         case EMTPFormatCode3GPContainer:
   396         case EMTPFormatCode3GPContainer:
   389             {
   397             {
   390             TUint aSubFormatCode = aObject.Uint( CMTPObjectMetaData::EFormatSubCode );
   398             TUint aSubFormatCode = aObject.Uint( CMTPObjectMetaData::EFormatSubCode );
   391             if ( aSubFormatCode == EMTPSubFormatCodeUnknown )
   399             if ( aSubFormatCode == EMTPSubFormatCodeUnknown )
   392                 {
   400                 {
   393                 category = ContainerCategory( aObject.DesC( CMTPObjectMetaData::ESuid ) );
   401                 TRAP_IGNORE( category = ContainerCategoryL( aObject.DesC( CMTPObjectMetaData::ESuid ) ) );
   394                 if ( category == EMPXSong )
   402                 if ( category == EMPXSong )
   395                     aSubFormatCode = EMTPSubFormatCodeAudio;
   403                     aSubFormatCode = EMTPSubFormatCodeAudio;
   396                 else if ( category == EMPXVideo )
   404                 else if ( category == EMPXVideo )
   397                     aSubFormatCode = EMTPSubFormatCodeVideo;
   405                     aSubFormatCode = EMTPSubFormatCodeVideo;
   398                 else
   406                 else
   399                     aSubFormatCode = EMTPSubFormatCodeUndefine;
   407                     aSubFormatCode = EMTPSubFormatCodeUndefined;
   400                 const_cast<CMTPObjectMetaData&>(aObject).SetUint( CMTPObjectMetaData::EFormatSubCode, aSubFormatCode );
   408                 const_cast<CMTPObjectMetaData&>(aObject).SetUint( CMTPObjectMetaData::EFormatSubCode, aSubFormatCode );
   401                 // If object doesn't exist, do nothing
   409                 // If object doesn't exist, do nothing
   402                 TRAP_IGNORE( iFramework.ObjectMgr().ModifyObjectL( aObject ) );
   410                 TRAP_IGNORE( iFramework.ObjectMgr().ModifyObjectL( aObject ) );
   403                 }
   411                 }
   404             else if ( aSubFormatCode == EMTPSubFormatCodeAudio )
   412             else if ( aSubFormatCode == EMTPSubFormatCodeAudio )
   405                 category = EMPXSong;
   413                 category = EMPXSong;
   406             else if ( aSubFormatCode == EMTPSubFormatCodeVideo )
   414             else if ( aSubFormatCode == EMTPSubFormatCodeVideo )
   407                 category = EMPXVideo;
   415                 category = EMPXVideo;
   408             else if( aSubFormatCode == EMTPSubFormatCodeUndefine )
   416             else if( aSubFormatCode == EMTPSubFormatCodeUndefined )
   409                 category = EMPXOther;
   417                 category = EMPXOther;
   410             }
   418             }
   411             break;
   419             break;
   412 
   420 
   413         case EMTPFormatCodeMP3:
   421         case EMTPFormatCodeMP3:
   443         }
   451         }
   444     PRINT1( _L( "MM MTP <= CMmMtpDpMetadataAccessWrapper::Category category = %d" ), category );
   452     PRINT1( _L( "MM MTP <= CMmMtpDpMetadataAccessWrapper::Category category = %d" ), category );
   445     return category;
   453     return category;
   446     }
   454     }
   447 
   455 
   448 TMPXGeneralCategory CMmMtpDpMetadataAccessWrapper::ContainerCategory( const TDesC& aFullFileName )
   456 TMPXGeneralCategory CMmMtpDpMetadataAccessWrapper::ContainerCategoryL( const TDesC& aFullFileName )
   449     {
   457     {
   450     PRINT1( _L( "MM MTP => CMmMtpDpMetadataAccessWrapper::ContainerCategory aFullFileName = %S" ), &aFullFileName );
   458     PRINT1( _L( "MM MTP => CMmMtpDpMetadataAccessWrapper::ContainerCategoryL aFullFileName = %S" ), &aFullFileName );
   451 
   459 
   452     TMPXGeneralCategory category = EMPXNoCategory;
   460     TMPXGeneralCategory category = EMPXNoCategory;
   453     TParsePtrC pathParser( aFullFileName );
   461     TParsePtrC pathParser( aFullFileName );
   454     TPtrC ext( pathParser.Ext() );
   462     TPtrC ext( pathParser.Ext() );
   455 
   463 
   456     if ( ext.Length() <= 0 )
   464     if ( ext.Length() <= 0 )
   457         category = EMPXOther;
   465         category = EMPXOther;
   458 
   466     else if ( ext.CompareF( KTxtExtensionO4A ) == 0
   459     if ( ext.CompareF( KTxtExtensionMP4 ) == 0
   467         || ext.CompareF( KTxtExtensionM4A ) == 0 )
   460         || ext.CompareF( KTxtExtension3GP ) == 0
   468         category = EMPXSong;
   461         || ext.CompareF( KTxtExtension3G2 ) == 0
   469     else if ( ext.CompareF( KTxtExtensionO4V ) == 0 )
   462         || ext.CompareF( KTxtExtensionODF ) == 0
   470         category = EMPXVideo;
   463         || ext.CompareF( KTxtExtensionASF ) == 0 )
   471     else
   464         {
   472         {
   465         HBufC8* mimetype = MmMtpDpUtility::ContainerMimeType( aFullFileName );
   473         HBufC8* mimetype = NULL;
       
   474 
       
   475         if ( ext.CompareF( KTxtExtensionMP4 ) == 0
       
   476             || ext.CompareF( KTxtExtension3GP ) == 0
       
   477             || ext.CompareF( KTxtExtension3G2 ) == 0 )
       
   478             mimetype = MmMtpDpUtility::Mp4MimeTypeL( aFullFileName );
       
   479         else if ( ext.CompareF( KTxtExtensionODF ) == 0 )
       
   480             mimetype = MmMtpDpUtility::OdfMimeTypeL( aFullFileName );
       
   481         else if ( ext.CompareF( KTxtExtensionASF ) == 0 )
       
   482             mimetype = MmMtpDpUtility::AsfMimeTypeL( aFullFileName );
   466         if ( mimetype != NULL )
   483         if ( mimetype != NULL )
   467             {
   484             {
   468             TMmMtpSubFormatCode subFormatCode = MmMtpDpUtility::SubFormatCodeFromMime( *mimetype );
   485             TMmMtpSubFormatCode subFormatCode =
       
   486                 MmMtpDpUtility::SubFormatCodeFromMime( *mimetype );
   469 
   487 
   470             if ( subFormatCode == EMTPSubFormatCodeVideo )
   488             if ( subFormatCode == EMTPSubFormatCodeVideo )
   471                 category = EMPXVideo;
   489                 category = EMPXVideo;
   472             else if( subFormatCode == EMTPSubFormatCodeAudio )
   490             else if( subFormatCode == EMTPSubFormatCodeAudio )
   473                 category = EMPXSong;
   491                 category = EMPXSong;
   474             else
   492             else
   475                 category = EMPXOther;
   493                 category = EMPXOther;
   476             }
   494             }
   477         }
   495         }
   478     else if ( ext.CompareF( KTxtExtensionO4V ) == 0 )
   496 
   479         category = EMPXVideo;
   497     PRINT1( _L( "MM MTP <= CMmMtpDpMetadataAccessWrapper::ContainerCategoryL, category = %d" ), category );
   480     else
       
   481         category = EMPXOther;
       
   482 
       
   483     PRINT1( _L( "MM MTP <= CMmMtpDpMetadataAccessWrapper::ContainerCategory, category = %d" ), category );
       
   484     return category;
   498     return category;
   485     }
   499     }
   486 
   500 
   487 // ---------------------------------------------------------------------------
   501 // ---------------------------------------------------------------------------
   488 // CMmMtpDpMetadataAccessWrapper::GetAllAbstractMediaL
   502 // CMmMtpDpMetadataAccessWrapper::GetAllAbstractMediaL
   516 // -----------------------------------------------------------------------------
   530 // -----------------------------------------------------------------------------
   517 // CMmMtpDpMetadataAccessWrapper::AddObjectL
   531 // CMmMtpDpMetadataAccessWrapper::AddObjectL
   518 // Add object (music, video, playlist and abstract media) info to DB
   532 // Add object (music, video, playlist and abstract media) info to DB
   519 // -----------------------------------------------------------------------------
   533 // -----------------------------------------------------------------------------
   520 //
   534 //
   521 void CMmMtpDpMetadataAccessWrapper::AddObjectL( const CMTPObjectMetaData& aObject )
   535 EXPORT_C void CMmMtpDpMetadataAccessWrapper::AddObjectL( const CMTPObjectMetaData& aObject )
   522     {
   536     {
   523     PRINT( _L( "MM MTP => CMmMtpDpMetadataAccessWrapper::AddObjectL" ) );
   537     PRINT( _L( "MM MTP => CMmMtpDpMetadataAccessWrapper::AddObjectL" ) );
   524     TMPXGeneralCategory category = Category( aObject );
   538     TMPXGeneralCategory category = Category( aObject );
   525 
   539 
   526     TPtrC fullFileName( aObject.DesC( CMTPObjectMetaData::ESuid ) );
   540     TPtrC fullFileName( aObject.DesC( CMTPObjectMetaData::ESuid ) );
   529         PRINT( _L( "MM MTP => CMmMtpDpMetadataAccessWrapper::AddObjectL Addvideo" ) );
   543         PRINT( _L( "MM MTP => CMmMtpDpMetadataAccessWrapper::AddObjectL Addvideo" ) );
   530         iMmMtpDpMetadataVideoAccess->AddVideoL( fullFileName );
   544         iMmMtpDpMetadataVideoAccess->AddVideoL( fullFileName );
   531         }
   545         }
   532     else if ( category == EMPXPlaylist || category == EMPXAbstractAlbum )
   546     else if ( category == EMPXPlaylist || category == EMPXAbstractAlbum )
   533         {
   547         {
   534         PRINT( _L( "MM MTP => CMmMtpDpMetadataAccessWrapper::AddObjectL AddPlaylist" ) );
   548         PRINT( _L( "MM MTP => CMmMtpDpMetadataAccessWrapper::AddObjectL AddPlaylist/AbstractAlbum" ) );
   535         iMmMtpDpMetadataMpxAccess->AddAbstractMediaL( fullFileName,
   549         iMmMtpDpMetadataMpxAccess->AddAbstractMediaL( fullFileName,
   536             category );
   550             category );
   537         }
   551         }
   538     else if ( category == EMPXSong )
   552     else if ( category == EMPXSong )
   539         {
   553         {