mmappcomponents/collectionhelper/src/mpxcollectioncachedhelper.cpp
changeset 61 3b098142db83
parent 57 f4fd77a452f2
equal deleted inserted replaced
57:f4fd77a452f2 61:3b098142db83
    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.3.7 % 
    16 *
    16 *
    17 */
    17 */
    18 
    18 
    19 
    19 
    20 #include <e32base.h>
    20 #include <e32base.h>
    51 
    51 
    52 _LIT( K3GPFileExt, ".3gp" );
    52 _LIT( K3GPFileExt, ".3gp" );
    53 _LIT( K3G2FileExt, ".3g2" );
    53 _LIT( K3G2FileExt, ".3g2" );
    54 _LIT( KODFFileExt, ".odf" );
    54 _LIT( KODFFileExt, ".odf" );
    55 _LIT( KO4AFileExt, ".o4a" );
    55 _LIT( KO4AFileExt, ".o4a" );
       
    56 _LIT( KAACFileExt, ".aac" );
    56 
    57 
    57 // ======== MEMBER FUNCTIONS ========
    58 // ======== MEMBER FUNCTIONS ========
    58 
    59 
    59 // ---------------------------------------------------------------------------
    60 // ---------------------------------------------------------------------------
    60 // Constructor
    61 // Constructor
   177         cacheCount = 1;            
   178         cacheCount = 1;            
   178     
   179     
   179     if( iCache->Count() >= cacheCount)
   180     if( iCache->Count() >= cacheCount)
   180         Commit();
   181         Commit();
   181 
   182 
   182     #ifdef ABSTRACTAUDIOALBUM_INCLUDED
   183 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
   183     TBool extract = ETrue;
   184     TBool extract = ETrue;
   184     if( aMedia->IsSupported( KMPXMediaMTPSampleDataFlag ) )
   185     if( aMedia->IsSupported( KMPXMediaMTPSampleDataFlag ) )
   185         {
   186         {
   186         
   187         
   187         extract = aMedia->ValueTObjectL<TBool>( KMPXMediaMTPSampleDataFlag );
   188         extract = aMedia->ValueTObjectL<TBool>( KMPXMediaMTPSampleDataFlag );
   387     TInt count( iCache->Count() );
   388     TInt count( iCache->Count() );
   388     
   389     
   389     // Take advantage that MTP always try to access the most recent item
   390     // Take advantage that MTP always try to access the most recent item
   390     //
   391     //
   391     CMPXMedia* media( NULL );
   392     CMPXMedia* media( NULL );
       
   393     TBool anotherAbstractMediaFound = EFalse;
   392     for( TInt i=count-1; i>=0; --i )
   394     for( TInt i=count-1; i>=0; --i )
   393         {
   395         {
   394         const TDesC& uri = iCache->AtL(i)->ValueText( KMPXMediaGeneralUri );
   396         const TDesC& uri = iCache->AtL(i)->ValueText( KMPXMediaGeneralUri );
       
   397         TMPXGeneralCategory category = iCache->AtL(i)->ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory);
       
   398         MPX_DEBUG3("CMPXCollectionCachedHelper::SetL iCache[i].category = %d, uri = %S", category, &uri);
   395         if( newUri.CompareF( uri ) == 0 )
   399         if( newUri.CompareF( uri ) == 0 )
   396             {
   400             {
   397             MPX_DEBUG2("Found existing media, index %i", i);
   401             MPX_DEBUG2("Found existing media, index %i", i);
   398             media = iCache->AtL(i);
   402             media = iCache->AtL(i);
   399             break;
   403             break;
   400             }
   404             }
       
   405         else if ( category == EMPXPlaylist || category == EMPXAbstractAlbum )
       
   406             anotherAbstractMediaFound = ETrue;
   401         }
   407         }
   402     
   408     
   403     // Not found in the array
   409     // Not found in the array
   404     if( !media )
   410     if( !media )
   405         {
   411         {
   406         // If the catched count is more than KCacheCount, commit it to database.
   412         // If the catched count is more than KCacheCount, commit it to database.
   407         if( count >= KCacheCount )
   413 		// could be song or alb coming, not in the cache, and there is at least one .alb on the cache
       
   414         // commit all if another AbstractMedia is found (anotherAbstractMediaFound is on ETrue if not the current one)
       
   415         if( ( count >= KCacheCount ) || anotherAbstractMediaFound )
   408             {
   416             {
   409             Commit();
   417             Commit();
   410             }
   418             }
   411         CMPXMedia* copy = CMPXMedia::NewL( *aMedia );
   419         CMPXMedia* copy = CMPXMedia::NewL( *aMedia );
   412         CleanupStack::PushL( copy );
   420         CleanupStack::PushL( copy );
   806         iFoundMedia->ValueText(KMPXMediaGeneralUri).CompareF(aFile) != 0)
   814         iFoundMedia->ValueText(KMPXMediaGeneralUri).CompareF(aFile) != 0)
   807         {
   815         {
   808         delete iFoundMedia;
   816         delete iFoundMedia;
   809         iFoundMedia = NULL;
   817         iFoundMedia = NULL;
   810         
   818         
   811         Commit();
   819 		MPX_DEBUG1("CMPXCollectionCachedHelper::GetL, not found on the cache");
       
   820         Commit( ETrue );    // leave AbstractAlbum in cache
   812 
   821 
   813         RArray<TMPXAttribute> attributes;
   822         RArray<TMPXAttribute> attributes;
   814         CleanupClosePushL(attributes);
   823         CleanupClosePushL(attributes);
   815 
   824 
   816         attributes.AppendL(
   825         attributes.AppendL(
   851 // ---------------------------------------------------------------------------
   860 // ---------------------------------------------------------------------------
   852 //
   861 //
   853 CMPXMedia* CMPXCollectionCachedHelper::FindAllL( CMPXMedia& aCriteria, 
   862 CMPXMedia* CMPXCollectionCachedHelper::FindAllL( CMPXMedia& aCriteria, 
   854                      const TArray<TMPXAttribute>& aAttrs )
   863                      const TArray<TMPXAttribute>& aAttrs )
   855     {
   864     {
   856     Commit();
   865     TBool cacheAbstractAlbum = EFalse;
   857     
   866     TMPXGeneralCategory category = aCriteria.ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory );
       
   867     
       
   868     // leave AbstractAlbum in cache, unless the new criteria is another abstract media
       
   869     if ( ( category != EMPXPlaylist ) && ( category != EMPXAbstractAlbum ) )
       
   870         cacheAbstractAlbum = ETrue;
       
   871     
       
   872     Commit( cacheAbstractAlbum );
       
   873 
   858     return CMPXCollectionHelperImp::FindAllL( aCriteria, aAttrs );
   874     return CMPXCollectionHelperImp::FindAllL( aCriteria, aAttrs );
   859     }
   875     }
   860 
   876 
   861 // ---------------------------------------------------------------------------
   877 // ---------------------------------------------------------------------------
   862 // Close function to destroy this object
   878 // Close function to destroy this object
   875 
   891 
   876 // ---------------------------------------------------------------------------
   892 // ---------------------------------------------------------------------------
   877 // Commits all transactions left in the helper
   893 // Commits all transactions left in the helper
   878 // ---------------------------------------------------------------------------
   894 // ---------------------------------------------------------------------------
   879 //   
   895 //   
   880 void CMPXCollectionCachedHelper::Commit()
   896 void CMPXCollectionCachedHelper::Commit( TBool aCacheAbstractAlbum )
   881     {
   897     {
   882     MPX_DEBUG2("CMPXCollectionCachedHelper::Commit %d <--", iCache->Count());
   898     MPX_DEBUG2("CMPXCollectionCachedHelper::Commit %d <--", iCache->Count());
   883     TInt error( KErrNotFound );
   899     TInt error( KErrNotFound );
   884     TInt count( iCache->Count() );
   900     TInt count( iCache->Count() );
   885     
   901     TInt currentIndex = 0;
   886     for( TInt i=0; i<count; ++i )
   902     
   887         {
   903     for( TInt i = 0; i < count; ++i )
   888         CMPXMedia* media = (*iCache)[0];
   904         {
       
   905         CMPXMedia* media = (*iCache)[currentIndex];
       
   906         TMPXGeneralCategory category = media->ValueTObjectL<TMPXGeneralCategory>( KMPXMediaGeneralCategory );
       
   907         TBool needCache = EFalse;
       
   908         
       
   909         if ( ( category == EMPXAbstractAlbum ) && aCacheAbstractAlbum )
       
   910             needCache = ETrue;
       
   911         
   889         if( media )
   912         if( media )
   890             {
   913             {
   891             switch( iOp[0] )
   914             switch( iOp[currentIndex] )
   892                 {
   915                 {
   893                 case EAdd:
   916                 case EAdd:
   894                     {
   917                     {
   895                     TRAP( error, SetMissingMetadataL( media ) );    // doing this only before initial add
   918                     if ( !needCache )
   896                     MPX_DEBUG2( "CMPXCollectionCachedHelper::Commit, SetMissingMetadataL, err = %d", error );
   919                         {
   897 
   920                         TRAP( error, SetMissingMetadataL( media ) );    // doing this only before initial add
   898                     TRAP(error,
   921                         MPX_DEBUG2( "CMPXCollectionCachedHelper::Commit, SetMissingMetadataL, err = %d", error );
   899                         CMPXCollectionHelperImp::AddL( media );
   922                         TRAP( error, CMPXCollectionHelperImp::AddL( media ) );
   900                         );
   923                         }
   901                     break;
   924                     break;
   902                     }
   925                     }
   903                 case ESet:
   926                 case ESet:
   904                     {
   927                     {
   905                     TRAP(error,
   928                     TRAP( error,
   906                         CMPXCollectionHelperImp::SetL( media );
   929                         CMPXCollectionHelperImp::SetL( media );
   907                         );
   930                         );
   908                     break;
   931                     break;
   909                     }
   932                     }
   910                 default:
   933                 default:
   930                     DoAppendAudioL( *media, *iFoundMedia );
   953                     DoAppendAudioL( *media, *iFoundMedia );
   931                     DoAppendDRML( *media, *iFoundMedia ); 
   954                     DoAppendDRML( *media, *iFoundMedia ); 
   932                     DoAppendContainerL( *media, *iFoundMedia );
   955                     DoAppendContainerL( *media, *iFoundMedia );
   933                     DoAppendMTPL( *media, *iFoundMedia ); 
   956                     DoAppendMTPL( *media, *iFoundMedia ); 
   934                     );
   957                     );
   935             }            
   958             }
   936             
   959 
   937         iCache->Remove(0);
   960         if ( needCache )
   938         iOp.Remove(0);        
   961             {
       
   962             const TDesC& uri = media->ValueText(KMPXMediaGeneralUri);
       
   963 			MPX_DEBUG2("need cache uri %S", &uri);
       
   964             currentIndex++;
       
   965             }
       
   966         else
       
   967             {
       
   968             iCache->Remove( currentIndex );
       
   969             iOp.Remove( currentIndex );
       
   970             }        
   939         }
   971         }
   940     
   972     
   941     MPX_DEBUG1("CMPXCollectionCachedHelper::Commit -->");        
   973     MPX_DEBUG1("CMPXCollectionCachedHelper::Commit -->");        
   942     }
   974     }
   943 
   975 
  1212     TParsePtrC parse( path );
  1244     TParsePtrC parse( path );
  1213 
  1245 
  1214     // only do this for file that might not be natively supported by PC
  1246     // only do this for file that might not be natively supported by PC
  1215     if ( ( parse.Ext().CompareF(K3GPFileExt) == 0 )
  1247     if ( ( parse.Ext().CompareF(K3GPFileExt) == 0 )
  1216         || ( parse.Ext().CompareF(K3G2FileExt) == 0 )
  1248         || ( parse.Ext().CompareF(K3G2FileExt) == 0 )
       
  1249         || ( parse.Ext().CompareF(KAACFileExt) == 0 )
  1217         || ( parse.Ext().CompareF(KODFFileExt) == 0 )
  1250         || ( parse.Ext().CompareF(KODFFileExt) == 0 )
  1218         || ( parse.Ext().CompareF(KO4AFileExt) == 0 ) )
  1251         || ( parse.Ext().CompareF(KO4AFileExt) == 0 ) )
  1219         {
  1252         {
  1220         TBool isTitleMissing = EFalse;
  1253         TBool isTitleMissing = EFalse;
  1221         TBool isArtistMissing = EFalse;
  1254         TBool isArtistMissing = EFalse;