mmappcomponents/collectionhelper/src/mpxcollectioncachedhelper.cpp
changeset 0 a2952bb97e68
child 17 780c925249c1
child 25 d881023c13eb
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Extended collection helper with an internal caching array
       
    15 *  Version     : %version: da1mmcf#27.1.12 % 
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <e32base.h>
       
    21 #include <mpxmedia.h>
       
    22 #include <mpxmediaarray.h>
       
    23 
       
    24 #include <mpxmediageneraldefs.h>
       
    25 #include <mpxmediamusicdefs.h>
       
    26 #include <mpxmediaaudiodefs.h>
       
    27 #include <mpxmediadrmdefs.h>
       
    28 #include <mpxmediacontainerdefs.h>
       
    29 #include <mpxcommandgeneraldefs.h>
       
    30 #include <mpxcollectioncommanddefs.h>
       
    31 #include <mpxmediamtpdefs.h>
       
    32 
       
    33 #include <mpxcollectionutility.h>
       
    34 #include <mpxharvesterutility.h>
       
    35 
       
    36 #include <mpxlog.h>
       
    37 
       
    38 #include "mpxcollectioncachedhelper.h"
       
    39 #include "mpxcollectionhelpercommon.h"
       
    40 #include <mpxmetadataextractor.h>
       
    41 
       
    42 // CONSTANTS
       
    43 const TInt KCacheCount = 10;
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // Constructor
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CMPXCollectionCachedHelper::CMPXCollectionCachedHelper() :
       
    52 #ifdef RD_MPX_COLLECTION_CACHE
       
    53     CMPXCollectionHelperImp(EFalse),iNotInCache(ETrue), iHitFoundMedia(0),
       
    54     iNotHitInCache(0), iLookingInCache(0),iLookingInUnknowCache(0),
       
    55 #endif //RD_MPX_COLLECTION_CACHE
       
    56     iMetadataExtractor(NULL)
       
    57     {
       
    58     }
       
    59 
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // 2nd Phase Constructor
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 void CMPXCollectionCachedHelper::ConstructL()
       
    66     {
       
    67     MPX_DEBUG1("CMPXCollectionCachedHelper::ConstructL <--");
       
    68     iCache = CMPXMediaArray::NewL();
       
    69     CMPXCollectionHelperImp::ConstructL();
       
    70 
       
    71 #ifdef RD_MPX_COLLECTION_CACHE
       
    72     MPX_DEBUG1("CMPXCollectionCachedHelper::ConstructL Todd advancedcache");
       
    73     // cache for unknown artist
       
    74     TMPXItemId artistId = NULL;
       
    75     TRAPD(err, artistId = GetArtistIdL( KNullDesC(), iMusicCollectionId ));
       
    76     if ( err || artistId == (TMPXItemId)0 )
       
    77         {
       
    78         MPX_DEBUG2("CMPXCollectionCachedHelper::ConstructL no known artist id %d", err);
       
    79         }
       
    80     else
       
    81         {
       
    82         // Get songs that belong to the unknown artist
       
    83         GetSongsL( artistId, iMusicCollectionId, ETrue );
       
    84         }
       
    85 #endif //RD_MPX_COLLECTION_CACHE
       
    86     User::LeaveIfError( iFs.Connect() );
       
    87     User::LeaveIfError( iAppArc.Connect() );
       
    88     iMetadataExtractor = CMPXMetadataExtractor::NewL( iFs, iAppArc, iSupportedTypes);
       
    89     MPX_DEBUG1("CMPXCollectionCachedHelper::ConstructL -->");
       
    90     }
       
    91 
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // Two-Phased Constructor
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CMPXCollectionCachedHelper* CMPXCollectionCachedHelper::NewL()
       
    98     {
       
    99     CMPXCollectionCachedHelper* self = CMPXCollectionCachedHelper::NewLC();
       
   100     CleanupStack::Pop( self );
       
   101     return self;
       
   102     }
       
   103 
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // Two-Phased Constructor
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 CMPXCollectionCachedHelper* CMPXCollectionCachedHelper::NewLC()
       
   110     {
       
   111     CMPXCollectionCachedHelper* self = new( ELeave ) CMPXCollectionCachedHelper();
       
   112     CleanupStack::PushL( self );
       
   113     self->ConstructL();
       
   114     return self;
       
   115     }
       
   116 
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Destructor
       
   120 // ---------------------------------------------------------------------------
       
   121 //
       
   122 CMPXCollectionCachedHelper::~CMPXCollectionCachedHelper()
       
   123     {
       
   124     Commit();
       
   125     delete iFoundMedia;
       
   126 #ifdef RD_MPX_COLLECTION_CACHE
       
   127     if ( iCachedArtistArray )
       
   128         {
       
   129         delete iCachedArtistArray;
       
   130         }
       
   131     if ( iCachedUnknownArtistArray )
       
   132         {
       
   133         delete iCachedUnknownArtistArray;
       
   134         }
       
   135 #endif //RD_MPX_COLLECTION_CACHE
       
   136     delete iCache;
       
   137     iOp.Close();
       
   138     if (iMetadataExtractor)
       
   139         {
       
   140         delete iMetadataExtractor;
       
   141         }
       
   142     iFs.Close();
       
   143     iAppArc.Close();
       
   144     iSupportedTypes.ResetAndDestroy();
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // Add a media object
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CMPXCollectionCachedHelper::AddL( CMPXMedia* aMedia )
       
   152     {
       
   153     MPX_FUNC("CMPXCollectionCachedHelper::::AddL");    
       
   154     // Commit when we have cached more than a set amount
       
   155     //
       
   156     if( iCache->Count() >= KCacheCount)
       
   157         {
       
   158         Commit();
       
   159         }
       
   160     
       
   161     // Extract album art from the file
       
   162     iMetadataExtractor->ExtractAlbumArtL( aMedia );
       
   163     
       
   164     CMPXMedia* copy = CMPXMedia::NewL( *aMedia );
       
   165     CleanupStack::PushL( copy );
       
   166     iCache->AppendL( copy );  // ownership x-fer
       
   167     CleanupStack::Pop( copy );
       
   168     iOp.AppendL( EAdd );
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // Remove a media object
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 void CMPXCollectionCachedHelper::RemoveL( const TDesC& aFile, 
       
   176                                           TMPXGeneralCategory aItemCat )
       
   177     {
       
   178     MPX_FUNC("CMPXCollectionCachedHelper::RemoveL");
       
   179     MPX_DEBUG3("aFile %S, category %d", &aFile, aItemCat);
       
   180     
       
   181     Commit();
       
   182     
       
   183     ::InitializeCollectionPluginsL( *iCollectionUtil );
       
   184     
       
   185     //
       
   186     // ask harvester to remove the file if any of the following is true:
       
   187     // 1) removing a song
       
   188     // 2) removing a playlist scanned through file system.
       
   189     //
       
   190     //    There are 3 types of playlists. The ones created from the device
       
   191     //    are virtual playlists which have file extension .vir. There are
       
   192     //    no physical playlist files associated with them; hence not
       
   193     //    registered with harvester. For virtual playlists, IsPlaylistL
       
   194     //    will return EFalse because there is not a playlist plugin that
       
   195     //    deals with .vir playlist files.
       
   196     //
       
   197     //    The ones synced from PC through MTP have file extension .pla.
       
   198     //    There are 0-byte .pla files associated with them but they
       
   199     //    are not registered with harvester either. IsPlaylistL will also
       
   200     //    return EFalse because there is not a playlist plugin that deals
       
   201     //    with .pla.
       
   202     //
       
   203     //    The 3rd type of playlists is .m3u on the file system. They are
       
   204     //    added to the collection through file scan and registered with
       
   205     //    harvester. IsPlaylistL will return ETrue.
       
   206     //
       
   207     //    For now virtual playlists and synced playlists are assumed to
       
   208     //    be in the music collection for now until there is a generic way
       
   209     //    resolving collections aside from using file extension or UID.
       
   210     //
       
   211     TInt collection(iMusicCollectionId.iUid);
       
   212     if (aItemCat == EMPXSong || iHvsUtility->IsPlaylistL(aFile))
       
   213         {
       
   214         // Remove from the harvester
       
   215         collection = iHvsUtility->RemoveFileL( aFile );
       
   216         }
       
   217     
       
   218     // Remove from the collection
       
   219     // Construct a CMPXMedia object with URI and collection
       
   220     //
       
   221     RArray<TInt> contID;
       
   222     CleanupClosePushL( contID );
       
   223     contID.AppendL( KMPXMediaIdGeneral );
       
   224     CMPXMedia* media = CMPXMedia::NewL( contID.Array() );
       
   225     CleanupStack::PopAndDestroy(&contID);
       
   226     CleanupStack::PushL( media );
       
   227     
       
   228     media->SetTextValueL( KMPXMediaGeneralUri, aFile );
       
   229     media->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, TUid::Uid( collection ) );
       
   230     media->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem );
       
   231     media->SetTObjectValueL( KMPXMediaGeneralCategory, aItemCat );
       
   232     
       
   233     // set up remove media command
       
   234     CMPXCommand* command = CMPXMedia::NewL();
       
   235     CleanupStack::PushL(command);
       
   236     
       
   237     command->SetTObjectValueL<TMPXCommandId>(
       
   238         KMPXCommandGeneralId, KMPXCommandIdCollectionRemoveMedia);
       
   239     command->SetTObjectValueL<TBool>(
       
   240         KMPXCommandGeneralDoSync, ETrue);
       
   241     command->SetTObjectValueL<TInt>(
       
   242         KMPXCommandGeneralCollectionId, collection);
       
   243     command->SetCObjectValueL(
       
   244         TMPXAttribute(KMPXCommandIdCollectionRemoveMedia, EMPXCommandCollectionRemoveMedia), 
       
   245         media);   
       
   246     command->SetTObjectValueL<TBool>(
       
   247         TMPXAttribute(KMPXCommandIdCollectionRemoveMedia, EMPXCommandCollectionRemoveMediaDeleteRecord), ETrue);         
       
   248     
       
   249     // send sync remove media command    
       
   250     iCollectionUtil->Collection().CommandL(*command);
       
   251 
       
   252     //
       
   253     // return command should contain error attribute
       
   254     //
       
   255     if (!command->IsSupported(TMPXAttribute(KMPXCommandIdCollectionRemoveMedia, EMPXCommandCollectionRemoveMediaError)))
       
   256         {
       
   257         User::Leave(KErrAbort);
       
   258         }
       
   259     
       
   260     //
       
   261     // abandon operation if an error occured cleaning up deleted medias from the collection
       
   262     //
       
   263     TInt error =
       
   264          command->ValueTObjectL<TInt>(
       
   265             TMPXAttribute(KMPXCommandIdCollectionRemoveMedia, EMPXCommandCollectionRemoveMediaError));
       
   266     User::LeaveIfError(error);
       
   267     
       
   268     //
       
   269     // reset found media if it's been deleted
       
   270     //
       
   271     if (iFoundMedia &&
       
   272         iFoundMedia->ValueText(KMPXMediaGeneralUri).CompareF(aFile) == 0)
       
   273         {
       
   274         delete iFoundMedia;
       
   275         iFoundMedia = NULL;
       
   276         }    
       
   277 
       
   278     CleanupStack::PopAndDestroy(2, media ); // command and media
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // Remove a media object
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 void CMPXCollectionCachedHelper::CleanupDeletedMediasL()
       
   286     {
       
   287     MPX_FUNC("CMPXCollectionCachedHelper::CleanupDeletedMediasL");
       
   288     
       
   289     Commit();
       
   290     
       
   291     ::InitializeCollectionPluginsL( *iCollectionUtil );
       
   292 
       
   293     //
       
   294     // set up the command to send to the collection
       
   295     //
       
   296     CMPXCommand* command = CMPXMedia::NewL();
       
   297     CleanupStack::PushL(command);
       
   298     
       
   299     command->SetTObjectValueL<TMPXCommandId>(
       
   300         KMPXCommandGeneralId, KMPXCommandIdCollectionCleanupDeletedMedias);
       
   301     command->SetTObjectValueL<TBool>(
       
   302         KMPXCommandGeneralDoSync, ETrue);
       
   303     command->SetTObjectValueL<TInt>(
       
   304         KMPXCommandGeneralCollectionId, iMusicCollectionId.iUid);
       
   305     
       
   306     // send sync cleanup command    
       
   307     iCollectionUtil->Collection().CommandL(*command);
       
   308     
       
   309     //
       
   310     // return command should contain error attribute
       
   311     //
       
   312     if (!command->IsSupported(TMPXAttribute(KMPXCommandIdCollectionCleanupDeletedMedias, EMPXCommandCollectionCleanupError)))
       
   313         {
       
   314         User::Leave(KErrAbort);
       
   315         }
       
   316     
       
   317     //
       
   318     // abandon operation if an error occured cleaning up deleted medias from the collection
       
   319     //
       
   320     TInt error =
       
   321         command->ValueTObjectL<TInt>(
       
   322             TMPXAttribute(KMPXCommandIdCollectionCleanupDeletedMedias, EMPXCommandCollectionCleanupError));
       
   323     User::LeaveIfError(error); 
       
   324     
       
   325     CleanupStack::PopAndDestroy(command);
       
   326     }
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // Update a media object
       
   330 // ---------------------------------------------------------------------------
       
   331 //    
       
   332 void CMPXCollectionCachedHelper::SetL( CMPXMedia*& aMedia )
       
   333     {
       
   334     MPX_DEBUG1("CMPXCollectionCachedHelper::::SetL <--");     
       
   335     
       
   336     const TDesC& newUri = aMedia->ValueText( KMPXMediaGeneralUri );
       
   337     TInt count( iCache->Count() );
       
   338     
       
   339     // Take advantage that MTP always try to access the most recent item
       
   340     //
       
   341     CMPXMedia* media( NULL );
       
   342     for( TInt i=count-1; i>=0; --i )
       
   343         {
       
   344         const TDesC& uri = iCache->AtL(i)->ValueText( KMPXMediaGeneralUri );
       
   345         if( newUri.CompareF( uri ) == 0 )
       
   346             {
       
   347             MPX_DEBUG2("Found existing media, index %i", i);
       
   348             media = iCache->AtL(i);
       
   349             break;
       
   350             }
       
   351         }
       
   352     
       
   353     // Not found in the array
       
   354     if( !media )
       
   355         {
       
   356         CMPXMedia* copy = CMPXMedia::NewL( *aMedia );
       
   357         CleanupStack::PushL( copy );
       
   358         iCache->AppendL( copy );  // ownership x-fer
       
   359         CleanupStack::Pop( copy );
       
   360         iOp.AppendL( ESet );
       
   361         }
       
   362     else
       
   363         {
       
   364         // Update existing media object already in the array
       
   365         //
       
   366         DoAppendGeneralL( *aMedia, *media );
       
   367         DoAppendMusicL( *aMedia, *media );
       
   368         DoAppendAudioL( *aMedia, *media );
       
   369         DoAppendDRML( *aMedia, *media ); 
       
   370         DoAppendContainerL( *aMedia, *media );
       
   371         DoAppendMTPL( *aMedia, *media ); 
       
   372         }
       
   373     MPX_DEBUG1("CMPXCollectionCachedHelper::::SetL -->");     
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // Renames a file
       
   378 // ---------------------------------------------------------------------------
       
   379 //    
       
   380 void CMPXCollectionCachedHelper::RenameL( const TDesC& aOldUri,
       
   381                                           const TDesC& aNewUri,
       
   382                                           TMPXGeneralCategory aItemCat )
       
   383     {
       
   384     TInt count = iCache->Count();
       
   385     
       
   386     // Take advantage that MTP always try to access the most recent item
       
   387     //
       
   388     CMPXMedia* media( NULL );
       
   389     for( TInt i=count-1; i>=0; --i )
       
   390         {
       
   391         const TDesC& uri = iCache->AtL(i)->ValueText( KMPXMediaGeneralUri );
       
   392         if( aOldUri.CompareF( uri ) == 0 )
       
   393             {
       
   394             MPX_DEBUG2("Found existing media, index %i", i);
       
   395             media = iCache->AtL(i);
       
   396             break;
       
   397             }
       
   398         }
       
   399     
       
   400     // Not found in the array
       
   401     if( !media )
       
   402         {
       
   403         Commit();
       
   404         CMPXCollectionHelperImp::RenameL(aOldUri, aNewUri, aItemCat);
       
   405         }
       
   406     else
       
   407         {
       
   408         // Update existing media object already in the array
       
   409         //
       
   410         media->SetTextValueL(KMPXMediaGeneralUri, aNewUri);
       
   411         }
       
   412         
       
   413     if (iFoundMedia &&
       
   414         iFoundMedia->ValueText(KMPXMediaGeneralUri).CompareF(aOldUri) == 0)
       
   415         {
       
   416         iFoundMedia->SetTextValueL(KMPXMediaGeneralUri, aNewUri);
       
   417         }        
       
   418     }
       
   419 
       
   420 
       
   421 #ifdef RD_MPX_COLLECTION_CACHE
       
   422 // ---------------------------------------------------------------------------
       
   423 // Gets the media object of the supplied attributes
       
   424 // ---------------------------------------------------------------------------
       
   425 //    
       
   426 void CMPXCollectionCachedHelper::GetSongL( const TDesC& aFile, 
       
   427     TMPXGeneralCategory aItemCat, TUid aCollectionUId )
       
   428     {
       
   429     MPX_DEBUG1("CMPXCollectionCachedHelper::GetSongL <--");
       
   430     RArray<TMPXAttribute> attributes;
       
   431     CleanupClosePushL(attributes);
       
   432 
       
   433     attributes.AppendL(
       
   434         TMPXAttribute(KMPXMediaIdGeneral,
       
   435                       EMPXMediaGeneralTitle | EMPXMediaGeneralDate |
       
   436                       EMPXMediaGeneralDuration | EMPXMediaGeneralComment |
       
   437                       EMPXMediaGeneralUri ));
       
   438     attributes.AppendL(
       
   439         TMPXAttribute(KMPXMediaIdMusic,
       
   440                       EMPXMediaMusicArtist | EMPXMediaMusicAlbum |
       
   441                       EMPXMediaMusicAlbumTrack | EMPXMediaMusicComposer |
       
   442                       EMPXMediaMusicYear | EMPXMediaMusicGenre));
       
   443 
       
   444     attributes.AppendL(KMPXMediaAudioAudioAll);
       
   445     attributes.AppendL(KMPXMediaMTPAll);
       
   446 
       
   447     delete iFoundMedia;
       
   448     iFoundMedia = NULL;
       
   449     iFoundMedia = CMPXCollectionHelperImp::GetL( aFile, attributes.Array(), aItemCat );
       
   450     if ( !iFoundMedia )
       
   451         {
       
   452         User::Leave(KErrNotFound);
       
   453         }
       
   454     iFoundMedia->SetTObjectValueL<TUid>(
       
   455         KMPXMediaGeneralCollectionId, aCollectionUId );
       
   456 
       
   457     CleanupStack::PopAndDestroy(&attributes);
       
   458     //MPX_DEBUG1("Artist name =");
       
   459     //RDebug::RawPrint(iFoundMedia->ValueText( KMPXMediaMusicArtist));
       
   460     MPX_DEBUG1("CMPXCollectionCachedHelper::GetSongL -->");
       
   461     }
       
   462 
       
   463 
       
   464 
       
   465         
       
   466 // ---------------------------------------------------------------------------
       
   467 // Gets the artist id for the media object
       
   468 // ---------------------------------------------------------------------------
       
   469 //    
       
   470 TMPXItemId CMPXCollectionCachedHelper::GetArtistIdL( const TDesC& aArtist, 
       
   471     TUid aCollectionUId )
       
   472     {
       
   473     MPX_DEBUG1("CMPXCollectionCachedHelper::GetArtistIdL <--");
       
   474     CMPXMedia* search = CMPXMedia::NewL();
       
   475     CleanupStack::PushL(search);
       
   476     search->SetTObjectValueL(KMPXMediaGeneralType, EMPXItem);        
       
   477     search->SetTObjectValueL(KMPXMediaGeneralCategory, EMPXArtist);
       
   478     search->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, aCollectionUId );
       
   479     search->SetTextValueL( KMPXMediaGeneralTitle, aArtist );
       
   480            
       
   481     RArray<TMPXAttribute> attributes;
       
   482     CleanupClosePushL(attributes);
       
   483     attributes.AppendL(KMPXMediaGeneralId);
       
   484 
       
   485     CMPXMedia* result =
       
   486         CMPXCollectionHelperImp::FindAllL(*search, attributes.Array());
       
   487     CleanupStack::PopAndDestroy(&attributes);
       
   488     CleanupStack::PopAndDestroy(search);
       
   489     CleanupStack::PushL(result);
       
   490     const CMPXMediaArray* results =
       
   491         result->Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
   492     if( !results )
       
   493         {
       
   494         User::Leave( KErrNoMemory );
       
   495         }
       
   496     
       
   497     TMPXItemId artistId = 0;
       
   498     if ( !results->Count() || aArtist == KNullDesC )
       
   499     	{
       
   500 	    CleanupStack::PopAndDestroy(result);
       
   501     	return TMPXItemId(0);
       
   502     	}
       
   503 
       
   504     artistId = results->AtL(0)->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
   505     CleanupStack::PopAndDestroy(result);
       
   506 
       
   507     
       
   508     MPX_DEBUG1("CMPXCollectionCachedHelper::GetArtistIdL -->");
       
   509     return artistId;
       
   510     }
       
   511 
       
   512 
       
   513 
       
   514 // ---------------------------------------------------------------------------
       
   515 // Gets the artist id for the media object
       
   516 // ---------------------------------------------------------------------------
       
   517 //    
       
   518 void CMPXCollectionCachedHelper::GetSongsL( TMPXItemId aArtistId, 
       
   519     TUid aCollectionUId, TBool aUnknownArtist )
       
   520     {
       
   521     MPX_DEBUG1("CMPXCollectionCachedHelper::GetSongsLL <--");
       
   522 
       
   523     RArray<TMPXAttribute> attributes;
       
   524     CleanupClosePushL(attributes);
       
   525     
       
   526     if ((aArtistId == (TMPXItemId)0) || aUnknownArtist )
       
   527 	    {
       
   528 	    CleanupStack::PopAndDestroy(&attributes);	    
       
   529 	    return;
       
   530 	    }
       
   531 
       
   532     attributes.AppendL(
       
   533         TMPXAttribute(KMPXMediaIdGeneral,
       
   534                       EMPXMediaGeneralTitle | EMPXMediaGeneralDate |
       
   535                       EMPXMediaGeneralDuration | EMPXMediaGeneralComment |
       
   536                       EMPXMediaGeneralUri ));
       
   537     attributes.AppendL(
       
   538         TMPXAttribute(KMPXMediaIdMusic,
       
   539                       EMPXMediaMusicArtist | EMPXMediaMusicAlbum |
       
   540                       EMPXMediaMusicAlbumTrack | EMPXMediaMusicComposer |
       
   541                       EMPXMediaMusicYear | EMPXMediaMusicGenre));
       
   542 
       
   543     attributes.AppendL(KMPXMediaAudioAudioAll);
       
   544     attributes.AppendL(KMPXMediaMTPAll);
       
   545     
       
   546     CMPXMedia* search = CMPXMedia::NewL();
       
   547     CleanupStack::PushL( search );
       
   548     search->SetTObjectValueL( KMPXMediaGeneralType, EMPXGroup);
       
   549     search->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXSong );
       
   550     search->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, aCollectionUId );
       
   551     search->SetTObjectValueL<TMPXItemId>( KMPXMediaGeneralId, aArtistId );
       
   552 
       
   553     // Search in synch mode
       
   554     CMPXMedia* result = CMPXCollectionHelperImp::FindAllL( *search, attributes.Array() );
       
   555     CleanupStack::PopAndDestroy( search );
       
   556     CleanupStack::PopAndDestroy(&attributes);
       
   557 
       
   558     CleanupStack::PushL(result);    
       
   559     if( result->IsSupported( KMPXMediaArrayContents ) )
       
   560         {
       
   561         if ( !aUnknownArtist )
       
   562             { // cache for known artist
       
   563             if ( iCachedArtistArray )
       
   564                 {
       
   565                 delete iCachedArtistArray;
       
   566                 iCachedArtistArray = NULL;
       
   567                 }          
       
   568             CMPXMediaArray* ary = result->Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
   569             iCachedArtistArray = CMPXMediaArray::NewL(*ary);
       
   570             MPX_DEBUG2("Known Artist Array count()=%d", iCachedArtistArray->Count());
       
   571             }
       
   572         else // cache for unknown artist
       
   573             {
       
   574             if ( iCachedUnknownArtistArray )
       
   575                 {
       
   576                 delete iCachedUnknownArtistArray;
       
   577                 iCachedUnknownArtistArray = NULL;
       
   578                 }          
       
   579             CMPXMediaArray* ary = result->Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
   580             iCachedUnknownArtistArray = CMPXMediaArray::NewL(*ary);
       
   581             MPX_DEBUG2("Unknown Artist Array count()=%d", iCachedUnknownArtistArray->Count());
       
   582             }
       
   583       }
       
   584 
       
   585 
       
   586     CleanupStack::PopAndDestroy(result);
       
   587 
       
   588     MPX_DEBUG1("CMPXCollectionCachedHelper::GetSongsLL -->");
       
   589     }
       
   590 
       
   591 #endif //RD_MPX_COLLECTION_CACHE
       
   592 
       
   593     
       
   594 // ---------------------------------------------------------------------------
       
   595 // Gets the attributes of some media object
       
   596 // ---------------------------------------------------------------------------
       
   597 //    
       
   598 const CMPXMedia& CMPXCollectionCachedHelper::GetL( const TDesC& aFile, 
       
   599                                                    TMPXGeneralCategory aItemCat )
       
   600     {
       
   601     
       
   602 #ifdef RD_MPX_COLLECTION_CACHE
       
   603     Commit();
       
   604 
       
   605     if (aItemCat != EMPXSong && aItemCat != EMPXPlaylist)
       
   606         {
       
   607         User::Leave(KErrArgument);
       
   608         }
       
   609 
       
   610     MPX_DEBUG1("CMPXCollectionCachedHelper::GetL (advanced cache version) <--");
       
   611     MPX_DEBUG2("aFile %S", &aFile);
       
   612 
       
   613     // If the iFoundMedia is cached
       
   614     if ( iFoundMedia )
       
   615         {
       
   616         // and if asking for the same file, just return.
       
   617         if ( iFoundMedia->ValueText(KMPXMediaGeneralUri).CompareF(aFile) == 0 )
       
   618             {
       
   619             iHitFoundMedia++;
       
   620             return *iFoundMedia;
       
   621             }
       
   622         // and if not asking for the same file, seach through cacahed array.
       
   623         // It probably cached in the cached artist array
       
   624         else if ( iCachedArtistArray && iCachedArtistArray->Count() )
       
   625             {
       
   626             TInt count( iCachedArtistArray->Count() );
       
   627             iNotInCache = ETrue;
       
   628             iLookingInCache++;            
       
   629             MPX_DEBUG1("CMPXCollectionCachedHelper::GetL looking into cache <--");
       
   630             for( TInt i=0; i<count; i++ )
       
   631                 {
       
   632                 CMPXMedia& m = *iCachedArtistArray->AtL(i);
       
   633                 //RDebug::Printf("Checking... begin");
       
   634                 //RDebug::RawPrint(m.ValueText(KMPXMediaGeneralUri));
       
   635                 if ( m.ValueText(KMPXMediaGeneralUri).CompareF(aFile) == 0 )
       
   636                     {
       
   637                     delete iFoundMedia;
       
   638                     iFoundMedia = NULL;
       
   639                     iFoundMedia = CMPXMedia::NewL( m );
       
   640                     iNotInCache = EFalse;
       
   641                     MPX_DEBUG1("CMPXCollectionCachedHelper::GetL found in cache <--");
       
   642                     break;
       
   643                     }
       
   644                 }
       
   645             // if not in cached artist array, try with unknown array 
       
   646             if ( iNotInCache && iCachedUnknownArtistArray && iCachedUnknownArtistArray->Count() )
       
   647                 {
       
   648                 MPX_DEBUG1("CMPXCollectionCachedHelper::GetL looking into unknown cache <--");
       
   649                 iLookingInUnknowCache++;                    
       
   650                 count = iCachedUnknownArtistArray->Count();
       
   651                 for( TInt i=0; i<count; i++ )
       
   652                     {
       
   653                     CMPXMedia& m = *iCachedUnknownArtistArray->AtL(i);
       
   654                     if ( m.ValueText(KMPXMediaGeneralUri).CompareF(aFile) == 0 )
       
   655                         {
       
   656                         MPX_DEBUG1("CMPXCollectionCachedHelper::GetL found unknown cache <--");
       
   657                         delete iFoundMedia;
       
   658                         iFoundMedia = NULL;
       
   659                         iFoundMedia = CMPXMedia::NewL( m );
       
   660                         iNotInCache = EFalse;
       
   661                         break;
       
   662                         }
       
   663                     }
       
   664                 }
       
   665             }
       
   666         }
       
   667 
       
   668 
       
   669         
       
   670     // No cache or not finding anything in the cached artist arraies
       
   671     // it got to search the song in db and also create cache for the new artist
       
   672     if ( !iFoundMedia || !iCachedArtistArray || iNotInCache )
       
   673         {
       
   674         MPX_DEBUG4("CMPXCollectionCachedHelper::GetL looking in db <-- iFoundMedia=%x iCachedArtistArray=%x, iNotInCache=%d", iFoundMedia, iCachedArtistArray, iNotInCache);
       
   675         TInt col(iMusicCollectionId.iUid);
       
   676         if (aItemCat == EMPXSong || iHvsUtility->IsPlaylistL(aFile))    
       
   677             {
       
   678             TRAPD(err, col = iHvsUtility->FindCollectionIdL( aFile ));
       
   679             if (err != KErrNone)
       
   680             	{
       
   681             	MPX_DEBUG2("CMPXCollectionCachedHelper::GetL error $", err);
       
   682             	}
       
   683             }
       
   684         // to get single song that matches the supplied URI
       
   685 
       
   686         GetSongL(aFile, aItemCat, TUid::Uid(col)); 
       
   687 
       
   688         if ( aItemCat == EMPXPlaylist )
       
   689             {
       
   690             return *iFoundMedia; // no need to cache for playlist request
       
   691             }
       
   692 
       
   693         iNotHitInCache++;
       
   694 
       
   695         // Get Artist Id
       
   696         TMPXItemId artistId = (TMPXItemId)0;
       
   697         if ( iFoundMedia->IsSupported(KMPXMediaMusicArtist) 
       
   698         	&& iFoundMedia->ValueText(KMPXMediaMusicArtist).Length() )
       
   699 	        {
       
   700 	        TRAPD(err, artistId = GetArtistIdL( 
       
   701 	            iFoundMedia->ValueText(KMPXMediaMusicArtist), TUid::Uid(col) ));
       
   702 	        if ( err )
       
   703 	            {
       
   704 	            artistId = GetArtistIdL( KNullDesC(), TUid::Uid(col) );
       
   705 	            }
       
   706 	        }
       
   707 	    else 
       
   708 		    {
       
   709 	        artistId = GetArtistIdL( KNullDesC(), TUid::Uid(col) );
       
   710 		    }
       
   711         // Get songs that belongs to the same artist id
       
   712         GetSongsL( artistId, TUid::Uid(col), EFalse );
       
   713         }
       
   714 
       
   715     MPX_DEBUG1("CMPXCollectionCachedHelper::GetL -->");
       
   716     return *iFoundMedia;
       
   717     
       
   718 #else  //RD_MPX_COLLECTION_CACHE
       
   719 
       
   720     MPX_DEBUG1("CMPXCollectionCachedHelper::GetL <--");
       
   721 
       
   722     if (aItemCat != EMPXSong && aItemCat != EMPXPlaylist)
       
   723         {
       
   724         User::Leave(KErrArgument);
       
   725         }
       
   726 
       
   727     // Do reverse search on cache 
       
   728     for( TInt i = iCache->Count()-1; i >= 0; --i )
       
   729         {
       
   730         CMPXMedia* media = iCache->AtL(i);
       
   731         if( media &&
       
   732                 media->ValueText(KMPXMediaGeneralUri).CompareF(aFile) == 0 )
       
   733             {
       
   734             return *media;
       
   735             }
       
   736         }
       
   737     
       
   738     if (!iFoundMedia ||
       
   739         iFoundMedia->ValueText(KMPXMediaGeneralUri).CompareF(aFile) != 0)
       
   740         {
       
   741         delete iFoundMedia;
       
   742         iFoundMedia = NULL;
       
   743         
       
   744         Commit();
       
   745 
       
   746         RArray<TMPXAttribute> attributes;
       
   747         CleanupClosePushL(attributes);
       
   748 
       
   749         attributes.AppendL(
       
   750             TMPXAttribute(KMPXMediaIdGeneral,
       
   751                           EMPXMediaGeneralTitle | EMPXMediaGeneralDate |
       
   752                           EMPXMediaGeneralDuration | EMPXMediaGeneralComment |
       
   753                           EMPXMediaGeneralUri ));
       
   754         attributes.AppendL(
       
   755             TMPXAttribute(KMPXMediaIdMusic,
       
   756                           EMPXMediaMusicArtist | EMPXMediaMusicAlbum |
       
   757                           EMPXMediaMusicAlbumTrack | EMPXMediaMusicComposer |
       
   758                           EMPXMediaMusicYear | EMPXMediaMusicGenre));
       
   759         attributes.AppendL(KMPXMediaAudioAudioAll);
       
   760         attributes.AppendL(KMPXMediaMTPAll);
       
   761 
       
   762         iFoundMedia = CMPXCollectionHelperImp::GetL( aFile, attributes.Array(), aItemCat );
       
   763         
       
   764         CleanupStack::PopAndDestroy(&attributes);
       
   765         }
       
   766     MPX_DEBUG1("CMPXCollectionCachedHelper::GetL -->");
       
   767     return *iFoundMedia;
       
   768 
       
   769 #endif //RD_MPX_COLLECTION_CACHE
       
   770         
       
   771     }
       
   772 
       
   773 // ---------------------------------------------------------------------------
       
   774 // Find some media
       
   775 // ---------------------------------------------------------------------------
       
   776 //
       
   777 CMPXMedia* CMPXCollectionCachedHelper::FindAllL( CMPXMedia& aCriteria, 
       
   778                      const TArray<TMPXAttribute>& aAttrs )
       
   779     {
       
   780     Commit();
       
   781     
       
   782     return CMPXCollectionHelperImp::FindAllL( aCriteria, aAttrs );
       
   783     }
       
   784 
       
   785 // ---------------------------------------------------------------------------
       
   786 // Close function to destroy this object
       
   787 // ---------------------------------------------------------------------------
       
   788 //                                 
       
   789 void CMPXCollectionCachedHelper::Close()
       
   790     {
       
   791 #ifdef RD_MPX_COLLECTION_CACHE
       
   792     MPX_DEBUG2("mpx perf result iHitFoundMedia=%d", iHitFoundMedia);
       
   793     MPX_DEBUG2("mpx pref result iNotHitInCache=%d", iNotHitInCache);
       
   794     MPX_DEBUG2("mpx perf result iLookingInCache=%d", iLookingInCache);
       
   795     MPX_DEBUG2("mpx perf result iLookingInUnknowCache=%d", iLookingInUnknowCache);
       
   796 #endif //RD_MPX_COLLECTION_CACHE
       
   797     delete this;  
       
   798     }
       
   799 
       
   800 // ---------------------------------------------------------------------------
       
   801 // Commits all transactions left in the helper
       
   802 // ---------------------------------------------------------------------------
       
   803 //   
       
   804 void CMPXCollectionCachedHelper::Commit()
       
   805     {
       
   806     MPX_DEBUG2("CMPXCollectionCachedHelper::Commit %d <--", iCache->Count());
       
   807     TInt error( KErrNotFound );
       
   808     TInt count( iCache->Count() );
       
   809     
       
   810     for( TInt i=0; i<count; ++i )
       
   811         {
       
   812         CMPXMedia* media = (*iCache)[0];
       
   813         if( media )
       
   814             {
       
   815             switch( iOp[0] )
       
   816                 {
       
   817                 case EAdd:
       
   818                     {
       
   819                     TRAP(error,
       
   820                         CMPXCollectionHelperImp::AddL( media );
       
   821                         );
       
   822                     break;
       
   823                     }
       
   824                 case ESet:
       
   825                     {
       
   826                     TRAP(error,
       
   827                         CMPXCollectionHelperImp::SetL( media );
       
   828                         );
       
   829                     break;
       
   830                     }
       
   831                 default:
       
   832                     {
       
   833                     ASSERT(0);
       
   834                     break;
       
   835                     }
       
   836                 }
       
   837         
       
   838             }
       
   839         else
       
   840             {
       
   841             error = KErrNoMemory;
       
   842             }
       
   843         
       
   844         if (!error &&
       
   845             iFoundMedia &&
       
   846             iFoundMedia->ValueText(KMPXMediaGeneralUri).CompareF(media->ValueText(KMPXMediaGeneralUri)) == 0)
       
   847             {
       
   848             TRAP_IGNORE( 
       
   849                     DoAppendGeneralL( *media, *iFoundMedia );
       
   850                     DoAppendMusicL( *media, *iFoundMedia );
       
   851                     DoAppendAudioL( *media, *iFoundMedia );
       
   852                     DoAppendDRML( *media, *iFoundMedia ); 
       
   853                     DoAppendContainerL( *media, *iFoundMedia );
       
   854                     DoAppendMTPL( *media, *iFoundMedia ); 
       
   855                     );
       
   856             }            
       
   857             
       
   858         iCache->Remove(0);
       
   859         iOp.Remove(0);        
       
   860         }
       
   861     
       
   862     MPX_DEBUG1("CMPXCollectionCachedHelper::Commit -->");        
       
   863     }
       
   864 
       
   865 // ---------------------------------------------------------------------------
       
   866 // Copies general media information
       
   867 // ---------------------------------------------------------------------------
       
   868 //  
       
   869 void CMPXCollectionCachedHelper::DoAppendGeneralL( CMPXMedia& aSrc, 
       
   870                                                    CMPXMedia& aDestination )
       
   871     {
       
   872     MPX_DEBUG1("CMPXCollectionCachedHelper::DoAppendGeneralL <--");     
       
   873     
       
   874     // Note: Only a subset used by MTP...
       
   875     //
       
   876     TUint atts = aSrc.AttributesSet( KMPXMediaIdGeneral );
       
   877     if( atts&EMPXMediaGeneralUri )  // text
       
   878         {
       
   879         aDestination.SetTextValueL( KMPXMediaGeneralUri,
       
   880                      aSrc.ValueText(KMPXMediaGeneralUri )
       
   881                                   );
       
   882         }
       
   883     if( atts&EMPXMediaGeneralDrive )  // text
       
   884         {
       
   885         aDestination.SetTextValueL( KMPXMediaGeneralDrive,
       
   886                      aSrc.ValueText(KMPXMediaGeneralDrive )
       
   887                                   );
       
   888         }
       
   889     if( atts&EMPXMediaGeneralTitle ) // text
       
   890         {
       
   891         aDestination.SetTextValueL( KMPXMediaGeneralTitle,
       
   892                      aSrc.ValueText(KMPXMediaGeneralTitle )
       
   893                                   );
       
   894         }
       
   895     if( atts&EMPXMediaGeneralComment ) //text
       
   896         {
       
   897         aDestination.SetTextValueL( KMPXMediaGeneralComment,
       
   898                      aSrc.ValueText(KMPXMediaGeneralComment ) 
       
   899                                   );
       
   900         }
       
   901     if( atts&EMPXMediaGeneralMimeType ) //text
       
   902         {
       
   903         aDestination.SetTextValueL( KMPXMediaGeneralMimeType,
       
   904                      aSrc.ValueText(KMPXMediaGeneralMimeType ) 
       
   905                                   );
       
   906         }
       
   907     if( atts&EMPXMediaGeneralDate ) // TInt64
       
   908         {
       
   909         aDestination.SetTObjectValueL( KMPXMediaGeneralDate,
       
   910                     aSrc.ValueTObjectL<TInt64>(KMPXMediaGeneralDate ) 
       
   911                                      );
       
   912         }
       
   913     if( atts&EMPXMediaGeneralDuration ) // TInt
       
   914         {
       
   915         aDestination.SetTObjectValueL( KMPXMediaGeneralDuration,
       
   916                     aSrc.ValueTObjectL<TInt>( KMPXMediaGeneralDuration ) 
       
   917                                      );
       
   918         }
       
   919     if( atts&EMPXMediaGeneralSynchronized ) // TBool
       
   920         {
       
   921         aDestination.SetTObjectValueL( KMPXMediaGeneralSynchronized,
       
   922                     aSrc.ValueTObjectL<TBool>( KMPXMediaGeneralSynchronized ) 
       
   923                                      );
       
   924         }
       
   925     if( atts&EMPXMediaGeneralDeleted ) // TBool
       
   926         {
       
   927         aDestination.SetTObjectValueL( KMPXMediaGeneralDeleted,
       
   928                     aSrc.ValueTObjectL<TBool>( KMPXMediaGeneralDeleted ) 
       
   929                                      );
       
   930         }
       
   931     if( atts&EMPXMediaGeneralModified )  // TBool
       
   932         {
       
   933         aDestination.SetTObjectValueL( KMPXMediaGeneralModified,
       
   934                     aSrc.ValueTObjectL<TBool>( KMPXMediaGeneralModified ) 
       
   935                                      );
       
   936         }
       
   937     if( atts&KMPXMediaGeneralFlags.iAttributeId )  // TUint
       
   938         {
       
   939         aDestination.SetTObjectValueL( KMPXMediaGeneralFlags,
       
   940                     aSrc.ValueTObjectL<TUint>( KMPXMediaGeneralFlags ) 
       
   941                                      );
       
   942         }
       
   943     MPX_DEBUG1("CMPXCollectionCachedHelper::DoAppendGeneralL -->");     
       
   944     }
       
   945 
       
   946 // ---------------------------------------------------------------------------
       
   947 // Copies music media information
       
   948 // ---------------------------------------------------------------------------
       
   949 //  
       
   950 void CMPXCollectionCachedHelper::DoAppendMusicL( CMPXMedia& aSrc, 
       
   951                                                  CMPXMedia& aDestination )
       
   952     {
       
   953     MPX_DEBUG1("CMPXCollectionCachedHelper::DoAppendMusicL <--");     
       
   954     TUint atts = aSrc.AttributesSet( KMPXMediaIdMusic );
       
   955     
       
   956     // Note: Only a subset used by MTP...
       
   957     //
       
   958     if( atts&EMPXMediaMusicArtist ) // Text
       
   959         {
       
   960         aDestination.SetTextValueL( KMPXMediaMusicArtist,
       
   961                      aSrc.ValueText(KMPXMediaMusicArtist ) 
       
   962                                   );
       
   963         }
       
   964     if( atts&EMPXMediaMusicAlbum ) // Text
       
   965         {
       
   966         aDestination.SetTextValueL( KMPXMediaMusicAlbum,
       
   967                      aSrc.ValueText(KMPXMediaMusicAlbum ) 
       
   968                                   );
       
   969         }
       
   970     if( atts&EMPXMediaMusicAlbumTrack ) // Text
       
   971         {
       
   972         aDestination.SetTextValueL( KMPXMediaMusicAlbumTrack,
       
   973                      aSrc.ValueText(KMPXMediaMusicAlbumTrack ) 
       
   974                                   );
       
   975         }
       
   976     if( atts&EMPXMediaMusicComposer ) // Text
       
   977         {
       
   978         aDestination.SetTextValueL( KMPXMediaMusicComposer,
       
   979                      aSrc.ValueText(KMPXMediaMusicComposer ) 
       
   980                                   );
       
   981         }
       
   982     if( atts&EMPXMediaMusicYear ) // TInt64
       
   983         {
       
   984         aDestination.SetTObjectValueL<TInt64>( KMPXMediaMusicYear,
       
   985                           aSrc.ValueTObjectL<TInt64>( KMPXMediaMusicYear ) 
       
   986                                   );
       
   987         }
       
   988     if( atts&EMPXMediaMusicGenre ) // Text
       
   989         {
       
   990         aDestination.SetTextValueL( KMPXMediaMusicGenre,
       
   991                      aSrc.ValueText(KMPXMediaMusicGenre ) 
       
   992                                   );
       
   993         }
       
   994     if( atts&EMPXMediaMusicRating )  // TInt
       
   995         {
       
   996         aDestination.SetTObjectValueL( KMPXMediaMusicRating,
       
   997              aSrc.ValueTObjectL<TInt>( KMPXMediaMusicRating ) 
       
   998                                      );   
       
   999         }
       
  1000     MPX_DEBUG1("CMPXCollectionCachedHelper::DoAppendMusicL -->");     
       
  1001     }
       
  1002 
       
  1003 // ---------------------------------------------------------------------------
       
  1004 // Copies Audio media information
       
  1005 // ---------------------------------------------------------------------------
       
  1006 //  
       
  1007 void CMPXCollectionCachedHelper::DoAppendAudioL( CMPXMedia& aSrc, 
       
  1008                                                  CMPXMedia& aDestination )
       
  1009     {
       
  1010     MPX_DEBUG1("CMPXCollectionCachedHelper::DoAppendAudioL <--");     
       
  1011     TUint atts = aSrc.AttributesSet( KMPXMediaIdAudio );
       
  1012     if( atts&EMPXMediaAudioBitrate ) // TInt
       
  1013         {
       
  1014         aDestination.SetTObjectValueL( KMPXMediaAudioBitrate,
       
  1015              aSrc.ValueTObjectL<TInt>( KMPXMediaAudioBitrate ) 
       
  1016                                      );
       
  1017         }
       
  1018     if( atts&EMPXMediaAudioSamplerate ) // TInt
       
  1019         {
       
  1020         aDestination.SetTObjectValueL( KMPXMediaAudioSamplerate,
       
  1021              aSrc.ValueTObjectL<TInt>( KMPXMediaAudioSamplerate ) 
       
  1022                                      );
       
  1023         }
       
  1024     if( atts&EMPXMediaAudioNumberOfChannels ) // TInt
       
  1025         {
       
  1026         aDestination.SetTObjectValueL( KMPXMediaAudioNumberOfChannels,
       
  1027              aSrc.ValueTObjectL<TInt>( KMPXMediaAudioNumberOfChannels ) 
       
  1028                                      );
       
  1029         }
       
  1030     if( atts&EMPXMediaAudioCodec ) // TInt
       
  1031         {
       
  1032         aDestination.SetTObjectValueL( KMPXMediaAudioAudioCodec,
       
  1033              aSrc.ValueTObjectL<TInt>( KMPXMediaAudioAudioCodec ) 
       
  1034                                      );
       
  1035         }
       
  1036     MPX_DEBUG1("CMPXCollectionCachedHelper::DoAppendAudioL -->");     
       
  1037     }
       
  1038 
       
  1039 // ---------------------------------------------------------------------------
       
  1040 // Copies DRM media information
       
  1041 // ---------------------------------------------------------------------------
       
  1042 //  
       
  1043 void CMPXCollectionCachedHelper::DoAppendDRML( CMPXMedia& aSrc, 
       
  1044                                                CMPXMedia& aDestination )
       
  1045     {
       
  1046     MPX_DEBUG1("CMPXCollectionCachedHelper::DoAppendDRML <--");     
       
  1047     TUint atts = aSrc.AttributesSet( KMPXMediaIdDrm );
       
  1048     
       
  1049     // Note: Only a subset used by MTP...
       
  1050     //
       
  1051     if( atts&EMPXMediaDrmProtected )  // TBool
       
  1052         {
       
  1053         aDestination.SetTObjectValueL( KMPXMediaDrmProtected,
       
  1054             aSrc.ValueTObjectL<TBool>( KMPXMediaDrmProtected ) 
       
  1055                                      );
       
  1056         }
       
  1057     if( atts&EMPXMediaDrmRightsStatus )  // TInt
       
  1058         {
       
  1059         aDestination.SetTObjectValueL( KMPXMediaDrmRightsStatus,
       
  1060              aSrc.ValueTObjectL<TInt>( KMPXMediaDrmRightsStatus ) 
       
  1061                                      );
       
  1062         }
       
  1063     MPX_DEBUG1("CMPXCollectionCachedHelper::DoAppendDRML -->");     
       
  1064     }
       
  1065 
       
  1066 // ---------------------------------------------------------------------------
       
  1067 // Copies array information
       
  1068 // ---------------------------------------------------------------------------
       
  1069 //  
       
  1070 void CMPXCollectionCachedHelper::DoAppendContainerL( CMPXMedia& aSrc,
       
  1071                                                      CMPXMedia& aDestination )
       
  1072     {
       
  1073     MPX_FUNC("CMPXCollectionCachedHelper::DoAppendContainerL");     
       
  1074     
       
  1075     TUint atts = aSrc.AttributesSet( KMPXMediaIdContainer );
       
  1076     
       
  1077     if( atts&EMPXMediaArrayContents )
       
  1078         {
       
  1079         const CMPXMediaArray* medias =
       
  1080             aSrc.Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
  1081         if( !medias )
       
  1082             {
       
  1083             User::Leave( KErrNoMemory );
       
  1084             }
       
  1085         
       
  1086         aDestination.SetCObjectValueL(
       
  1087             KMPXMediaArrayContents, 
       
  1088             const_cast<CMPXMediaArray*>(medias));
       
  1089         }
       
  1090     if( atts&EMPXMediaArrayCount )  // TInt
       
  1091         {
       
  1092         aDestination.SetTObjectValueL( KMPXMediaArrayCount,
       
  1093              aSrc.ValueTObjectL<TInt>( KMPXMediaArrayCount ) 
       
  1094                                      );
       
  1095         }
       
  1096     }
       
  1097 
       
  1098 // ---------------------------------------------------------------------------
       
  1099 // Copies mtp information
       
  1100 // ---------------------------------------------------------------------------
       
  1101 // 
       
  1102 void CMPXCollectionCachedHelper::DoAppendMTPL( CMPXMedia& aSrc, 
       
  1103                                                CMPXMedia& aDestination )
       
  1104     {
       
  1105     MPX_FUNC("CMPXCollectionCachedHelper::DoAppendMTPL");
       
  1106     
       
  1107     TUint atts = aSrc.AttributesSet( KMPXMediaIdMTP );
       
  1108     
       
  1109     if( atts&KMPXMediaMTPDrmStatus.iAttributeId)
       
  1110         {
       
  1111         TUint16 val = aSrc.ValueTObjectL<TUint16>(KMPXMediaMTPDrmStatus);
       
  1112         aDestination.SetTObjectValueL( KMPXMediaMTPDrmStatus, val );
       
  1113         }
       
  1114     }
       
  1115             
       
  1116 // END OF FILE