mmappfw_plat/collection_helper_api/tsrc/CollectionHelperTestClass/src/CollectionHelperTestClassBlocks.cpp
branchRCL_3
changeset 17 780c925249c1
parent 0 a2952bb97e68
child 42 4aca42fa4eb1
equal deleted inserted replaced
15:d240f0a77280 17:780c925249c1
    28 #include <mpxmediadrmdefs.h>
    28 #include <mpxmediadrmdefs.h>
    29 #include <mpxmediaarray.h>
    29 #include <mpxmediaarray.h>
    30 #include <mpxmediacontainerdefs.h>
    30 #include <mpxmediacontainerdefs.h>
    31 #include <mpxattribute.h>
    31 #include <mpxattribute.h>
    32 #include "debug.h"
    32 #include "debug.h"
       
    33 #include <mpxmediamtpdefs.h>
    33 
    34 
    34 // EXTERNAL DATA STRUCTURES
    35 // EXTERNAL DATA STRUCTURES
    35 //extern  ?external_data;
    36 //extern  ?external_data;
    36 
    37 
    37 // EXTERNAL FUNCTION PROTOTYPES  
    38 // EXTERNAL FUNCTION PROTOTYPES  
   132         // Second is the actual implementation member function. 
   133         // Second is the actual implementation member function. 
   133         ENTRY( "OpenCollectionUtility", CCollectionHelperTestClass::OpenCollectionUtilityL ),
   134         ENTRY( "OpenCollectionUtility", CCollectionHelperTestClass::OpenCollectionUtilityL ),
   134         ENTRY( "NewUiHelper", CCollectionHelperTestClass::NewUiHelperL ),
   135         ENTRY( "NewUiHelper", CCollectionHelperTestClass::NewUiHelperL ),
   135         ENTRY( "NewHelper", CCollectionHelperTestClass::NewHelperL ),
   136         ENTRY( "NewHelper", CCollectionHelperTestClass::NewHelperL ),
   136         ENTRY( "NewCachedHelper", CCollectionHelperTestClass::NewCachedHelperL ),
   137         ENTRY( "NewCachedHelper", CCollectionHelperTestClass::NewCachedHelperL ),
       
   138         ENTRY( "AddSong", CCollectionHelperTestClass::AddSongL ),
       
   139         ENTRY( "RemoveSong", CCollectionHelperTestClass::RemoveSongL ),
       
   140         ENTRY( "AddAbstractAlbum", CCollectionHelperTestClass::AddAbstractAlbumL ),
       
   141        ENTRY( "RemoveAbstractAlbum", CCollectionHelperTestClass::RemoveAbstractAlbumL ),
       
   142         ENTRY( "SetAbstractAlbum", CCollectionHelperTestClass::SetAbstractAlbumL ),
       
   143         ENTRY( "SetSongAlbumArtist", CCollectionHelperTestClass::SetSongAlbumArtistL ),
       
   144         ENTRY( "GetSongAlbumArtist", CCollectionHelperTestClass::GetSongAlbumArtistL ),
       
   145 ENTRY( "SetAbstractAlbumArtist", CCollectionHelperTestClass::SetAbstractAlbumArtistL ),
       
   146 ENTRY( "GetAbstractAlbumArtist", CCollectionHelperTestClass::GetAbstractAlbumArtistL ),
       
   147 ENTRY( "UpdateAbstractAlbumName", CCollectionHelperTestClass::UpdateAbstractAlbumNameL ),
       
   148   ENTRY("GetAbstractAlbumAndSongs",CCollectionHelperTestClass::GetAbstractAlbumAndSongsL),
       
   149         ENTRY( "RenameAbstractAlbum", CCollectionHelperTestClass::RenameAbstractAlbumL ),
   137         ENTRY( "CloseUiHelper", CCollectionHelperTestClass::CloseUiHelperL ),
   150         ENTRY( "CloseUiHelper", CCollectionHelperTestClass::CloseUiHelperL ),
   138         ENTRY( "CloseHelper", CCollectionHelperTestClass::CloseHelperL ),
   151         ENTRY( "CloseHelper", CCollectionHelperTestClass::CloseHelperL ),
   139         ENTRY( "CloseCachedHelper", CCollectionHelperTestClass::CloseCachedHelperL ),        
   152         ENTRY( "CloseCachedHelper", CCollectionHelperTestClass::CloseCachedHelperL ),        
   140         };
   153 		};
   141 
   154 
   142     const TInt count = sizeof( KFunctions ) / 
   155     const TInt count = sizeof( KFunctions ) / 
   143                         sizeof( TStifFunctionInfo );
   156                         sizeof( TStifFunctionInfo );
   144 
   157 
   145     return RunInternalL( KFunctions, count, aItem );
   158     return RunInternalL( KFunctions, count, aItem );
   509 
   522 
   510 	TRAPD( result, iCachedHelper = CMPXCollectionHelperFactory::NewCollectionCachedHelperL() ); 
   523 	TRAPD( result, iCachedHelper = CMPXCollectionHelperFactory::NewCollectionCachedHelperL() ); 
   511 
   524 
   512 	return result;
   525 	return result;
   513 	}
   526 	}
       
   527 
       
   528 
       
   529 //Removing song from collection
       
   530 //By calling CMPXCollectionCachedHelper API RemoveL
       
   531 TInt CCollectionHelperTestClass::RemoveSongL(CStifItemParser& /*aItem*/)
       
   532     {
       
   533 	FTRACE(FPrint(_L("CCollectionHelperTest::RemoveSongL")));
       
   534 	TRAPD(result, iCachedHelper->RemoveL(KFileWmaSong, EMPXSong));
       
   535 	iLog->Log(_L("CCollectionHelperTestClass::RemoveSong done with result=[%d]"), result);
       
   536 	return result;
       
   537 	}
       
   538 
       
   539 //Removing AbstractAlbum from collection
       
   540 //By calling CMPXCollectionCachedHelper API RemoveL
       
   541 //precondition:  e:\\data\\sounds\\digital\\1.alb  on test HW
       
   542 //output: 1.alb is delete from MPX DB
       
   543 TInt CCollectionHelperTestClass::RemoveAbstractAlbumL(CStifItemParser& /*aItem*/)
       
   544   {
       
   545 	FTRACE(FPrint(_L("CCollectionHelperTest::RemoveAbstractAlbumL")));
       
   546 	TRAPD(result, iCachedHelper->RemoveL(KAbstractalbum1, EMPXAbstractAlbum));
       
   547 	iLog->Log(_L("CCollectionHelperTestClass::RemoveAbstractAlbumL done with result=[%d]"), result);
       
   548 	return result;
       
   549 	}
       
   550 //Adds song to the database
       
   551 //WMP to MTP step1
       
   552 //By calling CMPXCollectionCachedHelper API AddL
       
   553 //precondition:  c:\\data\\sounds\\digital\\1.wma  on test emulator
       
   554 //precondition:  e:\\data\\sounds\\digital\\1.wma  on test HW
       
   555 //output: 1.wma is added into MPX DB
       
   556 TInt CCollectionHelperTestClass::AddSongL(CStifItemParser& /*aItem*/ )
       
   557     {
       
   558     FTRACE(FPrint(_L("CCollectionHelperTest::AddSongL")));
       
   559     //Does a record already exist for this abstractalbum?
       
   560     //this is the part to check if the song already exist in db?
       
   561     TInt result;
       
   562     TPtrC name(KFileWmaSong);
       
   563     TInt mediafound = FindMediaL(name, EMPXSong);
       
   564     
       
   565     //media already in collection DB, no need to add
       
   566     if (mediafound == 1)
       
   567         {
       
   568         return 0;
       
   569         }
       
   570 
       
   571     else if (mediafound == 0)  //media not in collection DB, continue to add*/
       
   572         {
       
   573         // Create media properties for the song will added
       
   574         iLog->Log(_L("Create media properties"));
       
   575         RArray<TInt> contentIDs;
       
   576         contentIDs.AppendL(KMPXMediaIdGeneral);
       
   577         contentIDs.AppendL(KMPXMediaIdAudio);
       
   578         contentIDs.AppendL(KMPXMediaIdMusic);
       
   579         contentIDs.AppendL(KMPXMediaIdMTP);
       
   580 
       
   581         CMPXMedia* media = CMPXMedia::NewL(contentIDs.Array());
       
   582         CleanupStack::PushL(media);
       
   583         contentIDs.Close();
       
   584 
       
   585         // MPXMedia default types
       
   586         media->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem);
       
   587         media->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXSong);
       
   588 
       
   589         // File Path
       
   590         TParsePtrC parse(name);
       
   591 
       
   592         media->SetTextValueL(KMPXMediaGeneralUri, name);
       
   593         media->SetTextValueL(KMPXMediaGeneralDrive, parse.Drive());
       
   594 
       
   595         // Title
       
   596 		media->SetTextValueL(KMPXMediaGeneralTitle, parse.NameAndExt());
       
   597 		// Comment
       
   598 		media->SetTextValueL(KMPXMediaGeneralComment, KNullDesC);
       
   599 		// Artist
       
   600 		media->SetTextValueL(KMPXMediaMusicArtist, KNullDesC);
       
   601 		// Album
       
   602 		media->SetTextValueL(KMPXMediaMusicAlbum, KNullDesC);
       
   603 		//AlbumArtist
       
   604 		media->SetTextValueL(KMPXMediaMusicAlbumArtist, KAlbumArtistShort);
       
   605 		// Track
       
   606 		media->SetTextValueL(KMPXMediaMusicAlbumTrack, KNullDesC);
       
   607 		// Genre
       
   608 		media->SetTextValueL(KMPXMediaMusicGenre, KNullDesC);
       
   609 		// Composer
       
   610 		media->SetTextValueL(KMPXMediaMusicComposer, KNullDesC);
       
   611 		// URL
       
   612 		media->SetTextValueL(KMPXMediaMusicURL, KNullDesC);
       
   613 		iLog->Log(_L("Default values set to Media"));
       
   614 
       
   615         // Update MPX WMP Roundtrip Metadata of the media object
       
   616         media->SetTObjectValueL<TBool>(KMPXMediaGeneralDeleted, EFalse);
       
   617         media->SetTObjectValueL<TBool>(KMPXMediaGeneralModified, EFalse);
       
   618         media->SetTObjectValueL<TBool>(KMPXMediaGeneralSynchronized, ETrue);
       
   619 
       
   620         media->SetTObjectValueL<TUint>(KMPXMediaGeneralFlags, KMPXMediaGeneralFlagsIsInvalid|KMPXMediaGeneralFlagsIsCorrupted);
       
   621 
       
   622         // Add new media to collection
       
   623         TRAP(result, iCachedHelper->AddL(media));
       
   624         FTRACE(FPrint(_L("CCollectionHelperTestClass::AddSongL, Media added into collection")));
       
   625 
       
   626         CleanupStack::PopAndDestroy(media);
       
   627         }
       
   628 	iLog->Log(_L("CCollectionHelperTestClass::AddSongL done with result=[%d]"), result);
       
   629 	
       
   630 	return result;
       
   631     }
       
   632 
       
   633 //Adds abstractalbum to the database, *.alb file
       
   634 //WMP to MTP step2
       
   635 //By calling CMPXCollectionCachedHelper API AddL
       
   636 //precondition:  c:\\data\\sounds\\digital\\1.alb  on test emulator
       
   637 //precondition:  e:\\data\\sounds\\digital\\1.alb  on test HW
       
   638 //output: 1.alb is added into MPX DB
       
   639 TInt  CCollectionHelperTestClass::AddAbstractAlbumL(CStifItemParser& /*aItem*/)
       
   640    {
       
   641 	FTRACE(FPrint(_L("CCollectionHelperTestClass::AddAbstractAlbumL")));
       
   642     TInt result;
       
   643 	TPtrC name(KAbstractalbum1);
       
   644     TInt mediafound = FindMediaL(name, EMPXAbstractAlbum);
       
   645     
       
   646     //media already in collection DB, no need to add
       
   647     if (mediafound == 1)
       
   648         {
       
   649         return 0;
       
   650         }
       
   651 
       
   652     else if(mediafound == 0)  // media not in collection DB, continue to add*/
       
   653         {
       
   654         RArray<TInt> contentIDs;
       
   655         contentIDs.AppendL(KMPXMediaIdGeneral);
       
   656 
       
   657         CMPXMediaArray* abstractalbumArray = CMPXMediaArray::NewL();
       
   658         CleanupStack::PushL(abstractalbumArray);
       
   659 
       
   660         CMPXMedia* media = CMPXMedia::NewL(contentIDs.Array());
       
   661         CleanupStack::PushL(media);
       
   662         contentIDs.Close();
       
   663 
       
   664         // MPXMedia default types
       
   665         media->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem);
       
   666         //EMPXAbstractAlbum is the new category added for non-embedded art
       
   667         media->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXAbstractAlbum);
       
   668 
       
   669         // File Path
       
   670         media->SetTextValueL(KMPXMediaGeneralUri, name);
       
   671         TParsePtrC parse(name);
       
   672         media->SetTextValueL(KMPXMediaGeneralDrive, parse.Drive());
       
   673         media->SetTextValueL(KMPXMediaGeneralTitle, parse.Name());
       
   674 
       
   675         //AlbumArtist
       
   676         media->SetTextValueL(KMPXMediaMusicAlbumArtist, KAlbumArtistShort);
       
   677         media->SetTObjectValueL<TBool>(KMPXMediaGeneralSynchronized, ETrue);
       
   678         media->SetTObjectValueL( KMPXMediaMTPSampleDataFlag, EFalse );
       
   679         media->SetCObjectValueL(KMPXMediaArrayContents, abstractalbumArray);
       
   680         media->SetTObjectValueL(KMPXMediaArrayCount, abstractalbumArray->Count());
       
   681 
       
   682         // Add new media to collection
       
   683         TRAP( result, iCachedHelper->AddL(media));
       
   684         CleanupStack::PopAndDestroy(media);
       
   685 
       
   686         // Clear the array
       
   687         CleanupStack::PopAndDestroy(abstractalbumArray);
       
   688         }
       
   689     iLog->Log(_L("CCollectionHelperTestClass::AddAbstractAlbumL done with result=[%d]"), result);
       
   690 	return result;
       
   691    }
       
   692  
       
   693 //Associate abstractalbum with songs
       
   694 //WMP to MTP step3
       
   695 //By calling CMPXCollectionCachedHelper API SetL
       
   696 //precondition on emulator:  c:\\data\\sounds\\digital\\1.wma
       
   697 //                           c:\\data\\sounds\\digital\\1.alb
       
   698 //precondition on HW      :  f:\\1.wma
       
   699 //                           f:\\1.alb
       
   700 //output: 1.wma and 1.alb is associated
       
   701 TInt CCollectionHelperTestClass::SetAbstractAlbumL(CStifItemParser& /*aItem*/)
       
   702  {
       
   703     FTRACE(FPrint(_L("CCollectionHelperTest::SetAbstractAlbumL")));
       
   704 
       
   705     CMPXMediaArray* mediaArray = CMPXMediaArray::NewL();
       
   706     CleanupStack::PushL(mediaArray);
       
   707     //add songs to media array
       
   708     AttachSongsL(mediaArray, KFileWmaSong());
       
   709     iLog->Log(_L("song added to abstractalbumArray, mediaArray->Count()=%d"), mediaArray->Count() );
       
   710     RArray<TInt> contentIDs;
       
   711     contentIDs.AppendL(KMPXMediaIdGeneral);
       
   712 
       
   713     CMPXMedia* abstractalbumMedia = CMPXMedia::NewL(contentIDs.Array());
       
   714     CleanupStack::PushL(abstractalbumMedia);
       
   715     contentIDs.Close();
       
   716 
       
   717     abstractalbumMedia->SetTObjectValueL(KMPXMediaGeneralType, EMPXItem);
       
   718     abstractalbumMedia->SetTObjectValueL(KMPXMediaGeneralCategory, EMPXAbstractAlbum);
       
   719 
       
   720     abstractalbumMedia->SetTextValueL(KMPXMediaGeneralUri, KAbstractalbum1());
       
   721 
       
   722     TParsePtrC parse(KAbstractalbum1());
       
   723     abstractalbumMedia->SetTextValueL(KMPXMediaGeneralDrive, parse.Drive());
       
   724     abstractalbumMedia->SetTObjectValueL<TBool>(KMPXMediaGeneralSynchronized, ETrue);
       
   725 
       
   726     abstractalbumMedia->SetCObjectValueL(KMPXMediaArrayContents, mediaArray);
       
   727     abstractalbumMedia->SetTObjectValueL(KMPXMediaArrayCount, mediaArray->Count());
       
   728 
       
   729     TRAPD( result, iCachedHelper->SetL(abstractalbumMedia));
       
   730     CleanupStack::PopAndDestroy(abstractalbumMedia);
       
   731 
       
   732     // Clear the array
       
   733     CleanupStack::PopAndDestroy(mediaArray);
       
   734     iLog->Log(_L("CCollectionHelperTestClass::SetAbstractAlbumL done with result=[%d]"), result);
       
   735 	
       
   736     return result;
       
   737 }
       
   738 
       
   739 //Update AlbumArtist field in Music table
       
   740 //By calling CMPXCollectionCachedHelper API SetL
       
   741 //precondition on emulator:  c:\\data\\sounds\\digital\\1.wma
       
   742 //precondition on HW:  f:\\1.wma
       
   743 //output: MUSIC.AlbumArtist field of song 1.wma is changed
       
   744 TInt CCollectionHelperTestClass::SetSongAlbumArtistL(CStifItemParser& /*aItem*/)
       
   745  {
       
   746     FTRACE(FPrint(_L("CCollectionHelperTest::SetSongAlbumArtistL")));
       
   747 
       
   748     CMPXMedia* media = NULL;
       
   749 
       
   750     // Creat media properties for the song
       
   751     RArray<TInt> contentIDs;
       
   752     contentIDs.AppendL( KMPXMediaIdGeneral );
       
   753     contentIDs.AppendL( KMPXMediaIdAudio );
       
   754     contentIDs.AppendL( KMPXMediaIdMusic );
       
   755     contentIDs.AppendL( KMPXMediaIdMTP );
       
   756 
       
   757     media = CMPXMedia::NewL( contentIDs.Array() );
       
   758     CleanupStack::PushL( media ); // + media
       
   759     contentIDs.Close();
       
   760 
       
   761     media->SetTObjectValueL<TMPXGeneralCategory>(
       
   762         KMPXMediaGeneralCategory,
       
   763         EMPXSong );
       
   764 
       
   765     // MPXMedia default types
       
   766     media->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXItem );
       
   767 
       
   768     // Get file path
       
   769     media->SetTextValueL( KMPXMediaGeneralUri, KFileWmaSong() );   //wma test file
       
   770 
       
   771     media->SetTextValueL( KMPXMediaGeneralDrive, KStoreRoot() );
       
   772     media->SetTextValueL( KMPXMediaMusicAlbumArtist, KAlbumArtistShort());
       
   773 
       
   774     TRAPD( result, iCachedHelper->SetL(media));
       
   775 
       
   776    CleanupStack::PopAndDestroy( media ); // - media
       
   777     iLog->Log(_L("CCollectionHelperTestClass::SetSongAlbumArtistL done with result=[%d]"), result);
       
   778 	
       
   779    return result;
       
   780 }
       
   781 //Retrive MUSIC.AlbumArtist field
       
   782 //By calling CMPXCollectionCachedHelper GetL
       
   783 //precondition on emulator:  c:\\data\\sounds\\digital\\1.wma
       
   784 //precondition on HW:  f:\\1.wma
       
   785 //output: song 1.wma is returned and MUSIC.AlbumArtist field of song 1.wma is retrived.
       
   786 TInt CCollectionHelperTestClass::GetSongAlbumArtistL(CStifItemParser& /*aItem*/)
       
   787 {
       
   788     FTRACE(FPrint(_L("CCollectionHelperTest::GetSongAlbumArtistL")));
       
   789     TMPXGeneralCategory category = EMPXSong;
       
   790    // CMPXMedia* foundMedia= NULL;
       
   791 
       
   792    const CMPXMedia& foundMedia = iCachedHelper->GetL( KFileWmaSong(), category );
       
   793 
       
   794     if (foundMedia.IsSupported(KMPXMediaMusicAlbumArtist))
       
   795         {
       
   796         const TDesC& albumartist = foundMedia.ValueText( KMPXMediaMusicAlbumArtist );
       
   797 	    }
       
   798    iLog->Log(_L("CCollectionHelperTestClass::GetSongAlbumArtistL done "));
       
   799 
       
   800    return 1;
       
   801 }
       
   802 
       
   803 
       
   804 
       
   805 //Update ABSTRACTALBUM.AlbumArtist
       
   806 //Update AlbumArtist field in Abstractalbum table
       
   807 //By calling CMPXCollectionCachedHelper API SetL
       
   808 //precondition on emulator:  c:\\data\\sounds\\digital\\1.alb
       
   809 //precondition on HW:  f:\\1.alb
       
   810 //output: ABSTRACTALBUM.AlbumArtist field of abstractalbum 1.alb is changed
       
   811 TInt CCollectionHelperTestClass::SetAbstractAlbumArtistL(CStifItemParser& /*aItem*/)
       
   812  {
       
   813     FTRACE(FPrint(_L("CCollectionHelperTest::SetAbstractAlbumArtistL")));
       
   814 
       
   815     CMPXMedia* media = NULL;
       
   816 
       
   817     RArray<TInt> contentIDs;
       
   818     contentIDs.AppendL( KMPXMediaIdGeneral );
       
   819 
       
   820     media = CMPXMedia::NewL( contentIDs.Array() );
       
   821     CleanupStack::PushL( media ); // + media
       
   822     contentIDs.Close();
       
   823     media->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory,
       
   824            EMPXAbstractAlbum );
       
   825     media->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXItem );
       
   826 
       
   827     media->SetTextValueL( KMPXMediaGeneralUri, KAbstractalbum1() );
       
   828     media->SetTextValueL( KMPXMediaGeneralDrive, KStoreRoot() );
       
   829 
       
   830     media->SetTextValueL( KMPXMediaMusicAlbumArtist, KAlbumArtistShort() );
       
   831 
       
   832     TRAPD( result, iCachedHelper->SetL(media));
       
   833 
       
   834     CleanupStack::PopAndDestroy(media);
       
   835     iLog->Log(_L("CCollectionHelperTestClass::SetAbstractAlbumArtistL done with result=[%d]"), result);
       
   836 
       
   837 
       
   838     return result;
       
   839 }
       
   840 
       
   841 //Retrieve ABSTRACTALBUM.AlbumArtist
       
   842 //By calling CMPXCollectionCachedHelper API GetL
       
   843 //precondition on emulator:  c:\\data\\sounds\\digital\\1.alb
       
   844 //precondition on HW:  f:\\1.alb
       
   845 //output: abstractalbum 1.alb is returned and ABSTRACTALBUM.AlbumArtist field of 1.alb is retrived.
       
   846 TInt CCollectionHelperTestClass::GetAbstractAlbumArtistL(CStifItemParser& /*aItem*/)
       
   847     {
       
   848 	FTRACE(FPrint(_L("CCollectionHelperTest::GetAbstractAlbumArtistL")));
       
   849     TMPXGeneralCategory category = EMPXAbstractAlbum;
       
   850     const CMPXMedia& foundMedia = iCachedHelper->GetL( KAbstractalbum1(), category );   //wma test file
       
   851 
       
   852 
       
   853     //print out foundMedia attributes
       
   854     if (foundMedia.IsSupported(KMPXMediaMusicAlbumArtist))
       
   855         {
       
   856 		iLog->Log(_L("CCollectionHelperTestClass::GetAbstractAlbumArtistL, ABSTRACTALBUM.AlbumArtist retrived"));
       
   857 
       
   858 
       
   859         
       
   860 
       
   861          const TDesC& albumartist = foundMedia.ValueText( KMPXMediaMusicAlbumArtist );
       
   862 
       
   863         }
       
   864 
       
   865 		if (foundMedia.IsSupported(KMPXMediaGeneralTitle))
       
   866 		 {
       
   867 
       
   868 		  
       
   869 			  //  HBufC* albumartist;
       
   870 			   //     albumartist = foundMedia.ValueText( KMPXMediaMusicAlbumArtist ).AllocLC(); // + data
       
   871 				 const TDesC& name = foundMedia.ValueText( KMPXMediaGeneralTitle );
       
   872 				 iLog->Log(_L("CCollectionHelperTestClass::GetAbstractAlbumArtistL, ABSTRACTALBUM.name retrived"));
       
   873 				 
       
   874 	
       
   875 
       
   876 		}
       
   877 		if (foundMedia.IsSupported(KMPXMediaGeneralUri))
       
   878 			 {
       
   879 
       
   880 			  
       
   881 				  //  HBufC* albumartist;
       
   882 				   //     albumartist = foundMedia.ValueText( KMPXMediaMusicAlbumArtist ).AllocLC(); // + data
       
   883 		     const TDesC& uri = foundMedia.ValueText( KMPXMediaGeneralUri );
       
   884 			 iLog->Log(_L("CCollectionHelperTestClass::GetAbstractAlbumArtistL, ABSTRACTALBUM.uri retrived"));
       
   885 					  
       
   886 			}
       
   887 	iLog->Log(_L("CCollectionHelperTestClass::GetAbstractAlbumArtistL done"));
       
   888 	return 1;
       
   889 	}
       
   890 
       
   891 
       
   892 //Update ABSTRACTALBUM.Name
       
   893 //Update Name field in Abstractalbum table
       
   894 //By calling CMPXCollectionCachedHelper API SetL
       
   895 //precondition on emulator:  c:\\data\\sounds\\digital\\1.alb
       
   896 //precondition on HW:  f:\\1.alb
       
   897 //output: ABSTRACTALBUM.name field of 1.alb is changed.
       
   898 TInt CCollectionHelperTestClass::UpdateAbstractAlbumNameL(CStifItemParser& /*aItem*/)
       
   899  {
       
   900 	FTRACE(FPrint(_L("CCollectionHelperTest::UpdateAbstractAlbumNameL")));
       
   901     CMPXMedia* media = NULL;
       
   902 
       
   903     // Creat media properties for the song
       
   904     RArray<TInt> contentIDs;
       
   905     contentIDs.AppendL( KMPXMediaIdGeneral );
       
   906 
       
   907 	media = CMPXMedia::NewL( contentIDs.Array() );
       
   908 	
       
   909 	CleanupStack::PushL( media ); // + media
       
   910 	contentIDs.Close();           //- contentIDs
       
   911 
       
   912     media->SetTObjectValueL<TMPXGeneralCategory>(
       
   913         KMPXMediaGeneralCategory,
       
   914         EMPXAbstractAlbum );
       
   915 
       
   916     media->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXItem );
       
   917 
       
   918 	media->SetTextValueL( KMPXMediaGeneralUri, KAbstractalbum1() );
       
   919 	media->SetTextValueL( KMPXMediaGeneralDrive, KStoreRoot() );
       
   920 
       
   921 	//media->SetTextValueL( KMPXMediaMusicAlbumArtist, KAbstractAlbumName() );
       
   922     media->SetTextValueL( KMPXMediaGeneralTitle, KAbstractAlbumName() );
       
   923    // media->SetTextValueL( KMPXMediaMusicAlbumArtFileName, KNewAbstractAlbumName() );
       
   924 
       
   925 	TRAPD( result, iCachedHelper->SetL(media));
       
   926     CleanupStack::PopAndDestroy(media);  // - media
       
   927 
       
   928     iLog->Log(_L("CCollectionHelperTestClass::UpdateAbstractAlbumNameL, done with result[%d]"), result);
       
   929     return result;
       
   930 }
       
   931 
       
   932 
       
   933 //Find all abstractalbums on KStoreRoot
       
   934 //Find all songs associated with the found Abstractalbums
       
   935 //By calling CMPXCollectionCachedHelper API GetL
       
   936 //precondition on emulator:  c:\\data\\sounds\\digital\\1.wma
       
   937 //                           c:\\data\\sounds\\digital\\1.alb
       
   938 //1.wma and 1.alb are associated
       
   939 //precondition on HW      :  f:\\1.wma
       
   940 //                           f:\\1.alb
       
   941 //1.wma and 1.alb are associated
       
   942 //all AbstractAlbum on drive c: (e:) is returned, all songs associated with the returned AbstractAlbum are returned.
       
   943 TInt CCollectionHelperTestClass::GetAbstractAlbumAndSongsL(CStifItemParser& /*aItem*/)
       
   944     {
       
   945  	FTRACE(FPrint(_L("CCollectionHelperTest::GetAlbumAndSongsL")));
       
   946  	TUint32 abstractalbumId(0);
       
   947     RArray<TInt> contentIDs;
       
   948     contentIDs.AppendL(KMPXMediaIdGeneral);
       
   949 
       
   950     CMPXMedia* searchMedia = CMPXMedia::NewL(contentIDs.Array());
       
   951     CleanupStack::PushL(searchMedia);
       
   952     contentIDs.Close();
       
   953 
       
   954     searchMedia->SetTObjectValueL(KMPXMediaGeneralType, EMPXItem);
       
   955     searchMedia->SetTObjectValueL(KMPXMediaGeneralCategory, EMPXAbstractAlbum);
       
   956     searchMedia->SetTextValueL(KMPXMediaGeneralDrive, KStoreRoot());
       
   957 
       
   958     RArray<TMPXAttribute> abstractalbumAttributes;
       
   959     CleanupClosePushL(abstractalbumAttributes);
       
   960     abstractalbumAttributes.AppendL(KMPXMediaGeneralId);
       
   961     abstractalbumAttributes.AppendL(KMPXMediaGeneralTitle);
       
   962     abstractalbumAttributes.AppendL(KMPXMediaGeneralUri);
       
   963 
       
   964    //foundMedia will hold all .alb on KStoreRoot()
       
   965    CMPXMedia* foundMedia = NULL;
       
   966    TRAPD( err, foundMedia = iCachedHelper->FindAllL(
       
   967             *searchMedia, abstractalbumAttributes.Array()));
       
   968 
       
   969    iLog->Log(_L("CCollectionHelperTestClass::GetAlbumAndSongsL, foundMedia assigned from FindAllL"));
       
   970 
       
   971    CleanupStack::PopAndDestroy(&abstractalbumAttributes);
       
   972    CleanupStack::PopAndDestroy(searchMedia);
       
   973    CleanupStack::PushL(foundMedia);  //+ foundMedia
       
   974 
       
   975    if ( err != KErrNone )
       
   976        {
       
   977        iLog->Log(_L("CCollectionHelperTestClass::GetAlbumAndSongsL, err = [%d]"), err );
       
   978        iCachedHelper->Close();
       
   979        iCachedHelper = NULL;
       
   980        User::Leave( KErrGeneral );
       
   981        }
       
   982 
       
   983    if (!foundMedia->IsSupported(KMPXMediaArrayCount))
       
   984        {
       
   985        User::Leave(KErrNotSupported);
       
   986        }
       
   987 
       
   988    TInt foundItemCount = *foundMedia->Value<TInt>(KMPXMediaArrayCount);
       
   989    iLog->Log(_L("CCollectionHelperTestClass::GetAlbumAndSongsL, foundItemCount=%d"), foundItemCount );
       
   990 
       
   991    CMPXMediaArray* foundArray =
       
   992        foundMedia->Value<CMPXMediaArray>(KMPXMediaArrayContents);
       
   993    CleanupStack::PopAndDestroy(foundMedia);
       
   994 
       
   995    for (TInt j = 0; j < foundItemCount; ++j)
       
   996         {
       
   997         CMPXMedia* abstractalbumMedia = CMPXMedia::NewL(*(*foundArray)[j]);
       
   998         CleanupStack::PushL(abstractalbumMedia);
       
   999 
       
  1000         //to print out founded media attributes
       
  1001         if (abstractalbumMedia->IsSupported(KMPXMediaGeneralTitle))
       
  1002             {
       
  1003 	        const TDesC& name = abstractalbumMedia->ValueText( KMPXMediaGeneralTitle );
       
  1004             iLog->Log(_L("CCollectionHelperTestClass::GetAlbumAndSongsL, found abstractalbumName = [%s]"), name );
       
  1005 	        }
       
  1006 
       
  1007         if (abstractalbumMedia->IsSupported(KMPXMediaGeneralId))
       
  1008             {
       
  1009             abstractalbumId = abstractalbumMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
  1010             abstractalbumMedia->ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
       
  1011             }
       
  1012 
       
  1013         // find the media object that contains a list of songs in the abstractalbum
       
  1014         RArray<TInt> contentIDs;
       
  1015         contentIDs.AppendL(KMPXMediaIdGeneral);
       
  1016 
       
  1017         CMPXMedia* searchMediaSong = CMPXMedia::NewL(contentIDs.Array());
       
  1018         CleanupStack::PushL(searchMediaSong);
       
  1019         contentIDs.Close();
       
  1020 
       
  1021         searchMediaSong->SetTObjectValueL(KMPXMediaGeneralType, EMPXGroup);
       
  1022 
       
  1023         searchMediaSong->SetTObjectValueL(KMPXMediaGeneralCategory, EMPXSong);
       
  1024         searchMediaSong->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, abstractalbumId);
       
  1025 
       
  1026         RArray<TMPXAttribute> songAttributes;
       
  1027         CleanupClosePushL(songAttributes);
       
  1028         songAttributes.AppendL(KMPXMediaGeneralId);
       
  1029         songAttributes.AppendL(KMPXMediaGeneralUri);
       
  1030 
       
  1031         //search from MPX collection to get all songs associated with .alb
       
  1032         CMPXMedia* foundSongs = NULL;
       
  1033         TRAPD( err, foundSongs = iCachedHelper->FindAllL(
       
  1034             *searchMediaSong, songAttributes.Array()));
       
  1035 
       
  1036         CleanupStack::PopAndDestroy(&songAttributes);
       
  1037         CleanupStack::PopAndDestroy(searchMediaSong);
       
  1038         CleanupStack::PopAndDestroy(abstractalbumMedia);
       
  1039 
       
  1040         CleanupStack::PushL( foundSongs ); // + foundSongs
       
  1041         if ( err != KErrNone )
       
  1042             {
       
  1043             iLog->Log(_L("CCollectionHelperTestClass::GetAlbumAndSongsL, err = [%d]"), err );
       
  1044             iCachedHelper->Close();
       
  1045             iCachedHelper = NULL;
       
  1046             User::Leave( KErrGeneral );
       
  1047             }
       
  1048 
       
  1049         if (!foundSongs->IsSupported(KMPXMediaArrayCount))
       
  1050             {
       
  1051             User::Leave(KErrNotSupported);
       
  1052             }
       
  1053 
       
  1054         // Number of references
       
  1055         TInt numOfSongsRefs = *foundSongs->Value<TInt>(KMPXMediaArrayCount);
       
  1056         iLog->Log(_L("CCollectionHelperTestClass::GetAlbumAndSongsL, numOfSongsRefs=%d"), numOfSongsRefs );
       
  1057         CleanupStack::PopAndDestroy( foundSongs ); // - foundSong
       
  1058     }
       
  1059    return 1;
       
  1060  }
       
  1061 
       
  1062 
       
  1063 //By calling CMPXCollectionCachedHelper API RenameL
       
  1064 //precondition on emulator:  c:\\data\\sounds\\digital\\1.wma
       
  1065 //                           c:\\data\\sounds\\digital\\1.alb
       
  1066 //1.wma and 1.alb are associated
       
  1067 //precondition on HW      :  f:\\1.wma
       
  1068 //                           f:\\1.alb
       
  1069 //output: 1.alb is renamed to 2.alb and all songs associated with 1.alb are updated in MUSIC table
       
  1070 TInt CCollectionHelperTestClass::RenameAbstractAlbumL(CStifItemParser& /*aItem*/)
       
  1071    {
       
  1072 	TRAPD( result, iCachedHelper->RenameL( KAbstractalbum1, KAbstractalbum2, EMPXAbstractAlbum ) );
       
  1073 	iLog->Log(_L("CCollectionHelperTestClass::RenameAbstractAlbumL, done with result=[%d]"));
       
  1074 	
       
  1075 	return result;
       
  1076 	}
       
  1077 
       
  1078 //Helper function for Finding in the MPX DB
       
  1079 //By calling CMPXCollectionCachedHelper API FindAllL
       
  1080 //output: all media with filename: aPath and aCategory is returned
       
  1081 TInt CCollectionHelperTestClass::FindMediaL(const TDesC& aPath, TMPXGeneralCategory aCategory)
       
  1082 {
       
  1083     FTRACE(FPrint(_L("CCollectionHelperTestClass::FindL")));
       
  1084 	// Check does a record already exist for this aPath(URI)?
       
  1085 	RArray<TInt> contentIDs;
       
  1086     contentIDs.AppendL( KMPXMediaIdGeneral );
       
  1087 
       
  1088     CMPXMedia* searchMedia = CMPXMedia::NewL( contentIDs.Array() );
       
  1089     CleanupStack::PushL( searchMedia ); // + searchMedia
       
  1090     contentIDs.Close();
       
  1091     searchMedia->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem );
       
  1092     searchMedia->SetTObjectValueL( KMPXMediaGeneralCategory, aCategory );
       
  1093     searchMedia->SetTextValueL( KMPXMediaGeneralUri, aPath );
       
  1094     
       
  1095 //note: some of the attributes are not needed
       
  1096     RArray<TMPXAttribute> mediaAttributes;
       
  1097     CleanupClosePushL( mediaAttributes ); // + mediaAttributes
       
  1098     mediaAttributes.AppendL( KMPXMediaGeneralId );
       
  1099     mediaAttributes.AppendL( KMPXMediaGeneralTitle );
       
  1100     mediaAttributes.AppendL( KMPXMediaGeneralUri );
       
  1101 
       
  1102     CMPXMedia* foundMedia = iCachedHelper->FindAllL( *searchMedia,
       
  1103         mediaAttributes.Array() );
       
  1104 
       
  1105     CleanupStack::PopAndDestroy( &mediaAttributes ); // - mediaAttributes
       
  1106     CleanupStack::PopAndDestroy( searchMedia ); // - searchMedia
       
  1107     CleanupStack::PushL( foundMedia ); // + foundMedia
       
  1108 
       
  1109     if ( !foundMedia->IsSupported( KMPXMediaArrayCount ) )
       
  1110         {
       
  1111         CleanupStack::PopAndDestroy( foundMedia ); // - foundMedia
       
  1112         return KErrNotSupported;
       
  1113         }
       
  1114     TInt foundItemCount = *foundMedia->Value<TInt>( KMPXMediaArrayCount );
       
  1115     CleanupStack::PopAndDestroy( foundMedia ); // - foundMedia
       
  1116     
       
  1117     iLog->Log(_L("CCollectionHelperTestClass::FindMediaL, foundItemCount=[%d]"), foundItemCount);
       
  1118     if ( foundItemCount >1) //more than 1 same item in collection
       
  1119         {
       
  1120 	    iLog->Log(_L("CCollectionHelperTestClass::FindMediaL, error, find more than 1 same media in collection"));
       
  1121         return  KErrGeneral;
       
  1122 	    }
       
  1123 
       
  1124     else if ( foundItemCount ==0 || foundItemCount ==1 ) //no such item in collection
       
  1125         {
       
  1126         iLog->Log(_L("CCollectionHelperTestClass::FindMediaL, error, no this item in collection"));
       
  1127         return  foundItemCount;
       
  1128         }
       
  1129 
       
  1130     return KErrNone;
       
  1131     }
       
  1132 
       
  1133 
       
  1134 
       
  1135 //Helper function for appending songs for SetAbstractAlbumL()
       
  1136 void CCollectionHelperTestClass::AttachSongsL(CMPXMediaArray* aAbstractAlbumArray, const TDesC& aPath)
       
  1137 {
       
  1138 	FTRACE(FPrint(_L("CCollectionHelperTestClass::AttachSongsL")));
       
  1139     RArray<TInt> contentIDs;
       
  1140     contentIDs.AppendL(KMPXMediaIdGeneral);
       
  1141     contentIDs.AppendL(KMPXMediaIdAudio);
       
  1142     contentIDs.AppendL(KMPXMediaIdMusic);
       
  1143     contentIDs.AppendL(KMPXMediaIdMTP);
       
  1144     CMPXMedia* media = CMPXMedia::NewL(contentIDs.Array());
       
  1145     CleanupStack::PushL(media);
       
  1146     contentIDs.Close();
       
  1147 
       
  1148     // MPXMedia default types
       
  1149     media->SetTObjectValueL<TMPXGeneralType>(KMPXMediaGeneralType, EMPXItem);
       
  1150     media->SetTObjectValueL<TMPXGeneralCategory>(KMPXMediaGeneralCategory, EMPXSong);
       
  1151     // File Path
       
  1152     TParsePtrC parse(aPath);
       
  1153     media->SetTextValueL(KMPXMediaGeneralUri, aPath);
       
  1154     media->SetTextValueL(KMPXMediaGeneralDrive, parse.Drive());
       
  1155 
       
  1156     // Add media into array contents
       
  1157     aAbstractAlbumArray->AppendL(media);
       
  1158     CleanupStack::Pop(media);
       
  1159 }
       
  1160 
   514 // -----------------------------------------------------------------------------
  1161 // -----------------------------------------------------------------------------
   515 // CCollectionHelperTestClass::CloseUiHelperL()
  1162 // CCollectionHelperTestClass::CloseUiHelperL()
   516 // Returns: Symbian OS errors.
  1163 // Returns: Symbian OS errors.
   517 // -----------------------------------------------------------------------------
  1164 // -----------------------------------------------------------------------------
   518 
  1165