mmappcomponents/collectionhelper/src/mpxcollectioncachedhelper.cpp
branchRCL_3
changeset 56 63223d4fd956
parent 55 6c1dfe4da5dd
child 59 666f9a5a90a9
equal deleted inserted replaced
55:6c1dfe4da5dd 56:63223d4fd956
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  Extended collection helper with an internal caching array
    14 * Description:  Extended collection helper with an internal caching array
    15 *  Version     : %version: da1mmcf#27.1.12.3.5 % 
    15 *  Version     : %version: e003sa33#27.1.12.1.3 % 
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 
    19 
    20 #include <e32base.h>
    20 #include <e32base.h>
    41 
    41 
    42 #include "mpxcollectioncachedhelper.h"
    42 #include "mpxcollectioncachedhelper.h"
    43 #include "mpxcollectionhelpercommon.h"
    43 #include "mpxcollectionhelpercommon.h"
    44 #include <mpxmetadataextractor.h>
    44 #include <mpxmetadataextractor.h>
    45 
    45 
    46 #include <MetaDataUtility.h>        // for SetMissingMetadataL
       
    47 #include <MetaDataFieldContainer.h> // for SetMissingMetadataL
       
    48 
       
    49 // CONSTANTS
    46 // CONSTANTS
    50 const TInt KCacheCount = 10;
    47 const TInt KCacheCount = 10;
    51 
       
    52 _LIT( K3GPFileExt, ".3gp" );
       
    53 _LIT( K3G2FileExt, ".3g2" );
       
    54 _LIT( KODFFileExt, ".odf" );
       
    55 _LIT( KO4AFileExt, ".o4a" );
       
    56 
    48 
    57 // ======== MEMBER FUNCTIONS ========
    49 // ======== MEMBER FUNCTIONS ========
    58 
    50 
    59 // ---------------------------------------------------------------------------
    51 // ---------------------------------------------------------------------------
    60 // Constructor
    52 // Constructor
   890             {
   882             {
   891             switch( iOp[0] )
   883             switch( iOp[0] )
   892                 {
   884                 {
   893                 case EAdd:
   885                 case EAdd:
   894                     {
   886                     {
   895                     TRAP( error, SetMissingMetadataL( media ) );    // doing this only before initial add
       
   896                     MPX_DEBUG2( "CMPXCollectionCachedHelper::Commit, SetMissingMetadataL, err = %d", error );
       
   897 
       
   898                     TRAP(error,
   887                     TRAP(error,
   899                         CMPXCollectionHelperImp::AddL( media );
   888                         CMPXCollectionHelperImp::AddL( media );
   900                         );
   889                         );
   901                     break;
   890                     break;
   902                     }
   891                     }
  1197         {
  1186         {
  1198         TUint16 val = aSrc.ValueTObjectL<TUint16>(KMPXMediaMTPDrmStatus);
  1187         TUint16 val = aSrc.ValueTObjectL<TUint16>(KMPXMediaMTPDrmStatus);
  1199         aDestination.SetTObjectValueL( KMPXMediaMTPDrmStatus, val );
  1188         aDestination.SetTObjectValueL( KMPXMediaMTPDrmStatus, val );
  1200         }
  1189         }
  1201     }
  1190     }
  1202 
       
  1203 // ---------------------------------------------------------------------------
       
  1204 // Attempt to set missing Metadata info in specific case
       
  1205 // ---------------------------------------------------------------------------
       
  1206 // 
       
  1207 void CMPXCollectionCachedHelper::SetMissingMetadataL(CMPXMedia* aMedia)
       
  1208     {
       
  1209     MPX_FUNC("CMPXCollectionCachedHelper::SetMissingMetadataL");
       
  1210     
       
  1211     const TDesC& path = aMedia->ValueText(KMPXMediaGeneralUri);
       
  1212     TParsePtrC parse( path );
       
  1213 
       
  1214     // only do this for file that might not be natively supported by PC
       
  1215     if ( ( parse.Ext().CompareF(K3GPFileExt) == 0 )
       
  1216         || ( parse.Ext().CompareF(K3G2FileExt) == 0 )
       
  1217         || ( parse.Ext().CompareF(KODFFileExt) == 0 )
       
  1218         || ( parse.Ext().CompareF(KO4AFileExt) == 0 ) )
       
  1219         {
       
  1220         TBool isTitleMissing = EFalse;
       
  1221         TBool isArtistMissing = EFalse;
       
  1222         TBool isAlbumMissing = EFalse;
       
  1223 
       
  1224         if ( aMedia->ValueText( KMPXMediaGeneralTitle ).Length() == 0 )
       
  1225             isTitleMissing = ETrue;
       
  1226     
       
  1227         if ( aMedia->ValueText( KMPXMediaMusicArtist ).Length() == 0 )
       
  1228             isArtistMissing = ETrue;
       
  1229     
       
  1230         if ( aMedia->ValueText( KMPXMediaMusicAlbum ).Length() == 0 )
       
  1231             isAlbumMissing = ETrue;
       
  1232 
       
  1233         MPX_DEBUG4("CMPXCollectionCachedHelper::SetMissingMetadataL, isTitleMissing = %d, isArtistMissing = %d, isAlbumMissing = %d", isTitleMissing, isArtistMissing, isAlbumMissing);
       
  1234 
       
  1235         // only do this if one of the following is missing:
       
  1236         // - Title
       
  1237         // - Artist
       
  1238         // - Album
       
  1239         // but can easily be extended to support any category field like: composer, genre
       
  1240         if ( isTitleMissing || isArtistMissing || isAlbumMissing )
       
  1241             {
       
  1242             // metadataextractor should be used instead, but not until CreateMediaL can be called without add/TN of the embedded art
       
  1243             // CR is needed to add parameter (TBool aAlbumArtNeeded = ETrue)  // ETrue by default, for all existing caller
       
  1244             // for now use MDU instead
       
  1245             CMetaDataUtility* metadataUtility = CMetaDataUtility::NewL();
       
  1246             
       
  1247             CleanupStack::PushL( metadataUtility );
       
  1248             metadataUtility->OpenFileL( path );
       
  1249             
       
  1250             MPX_DEBUG1( "CMPXCollectionCachedHelper::SetMissingMetadataL, CMetaDataUtility::OpenFileL succeed" );
       
  1251             
       
  1252             const CMetaDataFieldContainer& metaCont = metadataUtility->MetaDataFieldsL();
       
  1253         
       
  1254             for ( TInt i = 0; i < metaCont.Count(); i++ )
       
  1255                 {
       
  1256                 TMetaDataFieldId fieldType;
       
  1257                 TMPXAttributeData attribute;
       
  1258             
       
  1259                 metaCont.FieldIdAt( i, fieldType );  // get the field type
       
  1260                 
       
  1261                 switch ( fieldType )
       
  1262                     {
       
  1263                     case EMetaDataSongTitle:    // fall through
       
  1264                     case EMetaDataArtist:       // fall through
       
  1265                     case EMetaDataAlbum:
       
  1266                         {
       
  1267                         if ( ( isTitleMissing && ( fieldType == EMetaDataSongTitle ) )
       
  1268                             || ( isArtistMissing && ( fieldType == EMetaDataArtist ) )
       
  1269                             || ( isAlbumMissing && ( fieldType == EMetaDataAlbum ) ) )
       
  1270                             {
       
  1271                             HBufC* value = metaCont.At( i, fieldType ).AllocL();
       
  1272                             CleanupStack::PushL( value );
       
  1273                             
       
  1274                             TPtr valptr = value->Des();
       
  1275                             valptr.Trim();
       
  1276 
       
  1277                             // replace '\t' as ' '
       
  1278                             for ( TInt i = 0; i < value->Length(); i++ )
       
  1279                                 {
       
  1280                                 if ( valptr[i] == TText( '\t' ) )
       
  1281                                     valptr[i] = TText( ' ' );
       
  1282                                 }
       
  1283                             
       
  1284                             if ( fieldType == EMetaDataSongTitle )
       
  1285                                 attribute = KMPXMediaGeneralTitle;
       
  1286                             else if ( fieldType == EMetaDataArtist )
       
  1287                                 attribute = KMPXMediaMusicArtist;
       
  1288                             else
       
  1289                                 attribute = KMPXMediaMusicAlbum;
       
  1290 
       
  1291                             MPX_DEBUG3( "fieldType = %d, value = %S", fieldType, &valptr );
       
  1292                             aMedia->SetTextValueL( attribute , *value );
       
  1293                             CleanupStack::PopAndDestroy( value );                                
       
  1294                             }
       
  1295                         }
       
  1296 
       
  1297                         break;
       
  1298 
       
  1299                     default:
       
  1300 
       
  1301                         break;
       
  1302                     }
       
  1303                 }
       
  1304 
       
  1305             metadataUtility->ResetL();
       
  1306             CleanupStack::PopAndDestroy( metadataUtility );
       
  1307             }
       
  1308         }
       
  1309     }
       
  1310             
  1191             
  1311 // END OF FILE
  1192 // END OF FILE