// -------------------------------------------------------------------------- // CUPnPPlayListFiller::DoFillObjectL // Fills a ingle object to a playlist // -------------------------------------------------------------------------- // void CUPnPPlayListFiller::DoFillObjectL( CMPXMediaArray& aPlaylist, const CUpnpObject& aObject, TInt /*aIndex*/ ) { // Create new media object for track CMPXMedia* media = CMPXMedia::NewL(); CleanupStack::PushL( media ); // Set type media->SetTObjectValueL<TMPXGeneralType>( KMPXMediaGeneralType, EMPXItem ); // Set gategory media->SetTObjectValueL<TMPXGeneralCategory>( KMPXMediaGeneralCategory, EMPXSong ); // URI if( UPnPItemUtility::BelongsToClass( aObject , KClassAudio ) ) { ConvertToURI( *iDeviceUid, aObject, iTempBuf ); } else // item is non audio set uri to KUPnPPrefix { iTempBuf.Copy( KUPnPPrefix ); } media->SetTextValueL( KMPXMediaGeneralUri, iTempBuf ); // Title HBufC16* buf = EscapeUtils::ConvertToUnicodeFromUtf8L( aObject.Title() ); CleanupStack::PushL( buf ); media->SetTextValueL( KMPXMediaGeneralTitle, *buf ); CleanupStack::PopAndDestroy( buf ); // Add track to the object list aPlaylist.AppendL( media ); CleanupStack::Pop( media ); }
// ---------------------------------------------------------------------------------------------------------- // Add specify attribute to Media // ---------------------------------------------------------------------------------------------------------- // void CTestCollectionPlugin::AddAttrbuteL(CMPXMedia& aMedia, const TInt aId, const TDesC& aTitle, const TDesC& aUri, const TArray<TMPXAttribute>& aAttrs) { TInt attrCnt = aAttrs.Count(); for(TInt i = 0; i < attrCnt; i++) { if(aAttrs[i].ContentId() == KMPXMediaIdGeneral) { TInt attrId = aAttrs[i].AttributeId(); if(attrId & EMPXMediaGeneralId) { aMedia.SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, aId); } if(attrId & EMPXMediaGeneralTitle) { aMedia.SetTextValueL(KMPXMediaGeneralTitle, aTitle); } if(attrId & EMPXMediaGeneralUri) { aMedia.SetTextValueL(KMPXMediaGeneralUri, aUri); } } } }
// ---------------------------------------------------------------------------------------------------------- // Adding specific attribute // ---------------------------------------------------------------------------------------------------------- // void CTestCollectionPlugin::AddAttributeMusicArtistL(CMPXMedia& aMedia, const TInt aId) { switch( aId ) { case 9901: aMedia.SetTextValueL(KMPXMediaMusicArtist, _L("artist9901")); break; case 9902: aMedia.SetTextValueL(KMPXMediaMusicArtist, _L("artist9902")); break; case 9903: aMedia.SetTextValueL(KMPXMediaMusicArtist, _L("artist9903")); break; case 9904: aMedia.SetTextValueL(KMPXMediaMusicArtist, _L("artist9904")); break; case 9905: aMedia.SetTextValueL(KMPXMediaMusicArtist, _L("artist9905")); break; case 9906: aMedia.SetTextValueL(KMPXMediaMusicArtist, _L("artist9906")); break; case 9907: aMedia.SetTextValueL(KMPXMediaMusicArtist, _L("artist9907")); break; } }
// ---------------------------------------------------------------------------- // Append an item into the media array // ---------------------------------------------------------------------------- // void MPXDbUtil::AppendMediaL( CMPXMediaArray& aArray, const TDesC& aTitle, TMPXGeneralType aType, TMPXGeneralCategory aCat, TMPXPodcastType aPodcastType, TMPXPodcastCategory aPodcastCat, TMPXItemId aId, TInt aNonPermissibleActions) { MPX_FUNC("MPXDbUtil::AppendMediaL"); RArray<TInt> supportedIds; CleanupClosePushL (supportedIds); supportedIds.AppendL (KMPXMediaIdGeneral); supportedIds.AppendL (KMPXMediaIdPodcast); CMPXMedia* entry = CMPXMedia::NewL(supportedIds.Array()); CleanupStack::PushL (entry); entry->SetTextValueL (KMPXMediaGeneralTitle, aTitle); entry->SetTObjectValueL(KMPXMediaPodcastType, aPodcastType); entry->SetTObjectValueL(KMPXMediaPodcastCategoryGroup, aPodcastCat); entry->SetTObjectValueL(KMPXMediaGeneralId, aId); entry->SetTObjectValueL(KMPXMediaGeneralType, aType); entry->SetTObjectValueL(KMPXMediaGeneralCategory, aCat); // temp fix: Beryl BEGIN if ( aNonPermissibleActions != 0 ) { // set non-permissible actions entry->SetTObjectValueL(KMPXMediaGeneralNonPermissibleActions, static_cast<TMPXGeneralNonPermissibleActions>(aNonPermissibleActions)); } // temp fix: Beryl END aArray.AppendL (entry); CleanupStack::Pop (entry); CleanupStack::PopAndDestroy (&supportedIds); }
// --------------------------------------------------------------------------- // Retrieve a media object based on file path // --------------------------------------------------------------------------- // CMPXMedia* CMPXCollectionHelperImp::GetL( const TDesC& aFile, const TArray<TMPXAttribute>& aAttrs, TMPXGeneralCategory aItemCat ) { MPX_FUNC("CMPXCollectionHelperImp::GetL"); MPX_DEBUG2("aFile %S", &aFile); #ifdef ABSTRACTAUDIOALBUM_INCLUDED if (aItemCat != EMPXSong && aItemCat != EMPXPlaylist && aItemCat != EMPXAbstractAlbum) #else if (aItemCat != EMPXSong && aItemCat != EMPXPlaylist) #endif { User::Leave(KErrArgument); } // Playlists synced through MTP contains .pla extension and there // is no pla playlist plugin. We can no longer reply on harvester // utility's IsPlaylistL to determine if this is a playlist. // For now, the default collection to get this playlist is // EMPXCollectionPluginMusic for playlists. This will be revised // later when there is a generic way of resolving collections aside // from using file extension or UID. Same for virtual playlists. // // Find the collection Id from harvester for songs or playlists // scanned from the file system TInt col(iMusicCollectionId.iUid); if (aItemCat == EMPXSong || iHvsUtility->IsPlaylistL(aFile)) { col = iHvsUtility->FindCollectionIdL( aFile ); } // Search criteria // CMPXMedia* search = CMPXMedia::NewL(); CleanupStack::PushL( search ); search->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem ); search->SetTObjectValueL( KMPXMediaGeneralCategory, aItemCat ); search->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, TUid::Uid(col) ); search->SetTextValueL( KMPXMediaGeneralUri, aFile ); // Search in synch mode // CMPXMedia* result = iCollectionUtil->Collection().FindAllL( *search, aAttrs ); CleanupStack::PopAndDestroy( search ); CleanupStack::PushL(result); const CMPXMediaArray* ary(NULL); if( result->IsSupported( KMPXMediaArrayContents ) ) { ary = result->Value<CMPXMediaArray>(KMPXMediaArrayContents); if( !ary ) { User::Leave(KErrNoMemory); } } CMPXMedia* foundMedia(NULL); if ( ary && ary->Count() ) { foundMedia = CMPXMedia::NewL(*ary->AtL(0)); CleanupStack::PushL(foundMedia); foundMedia->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, TUid::Uid(col) ); CleanupStack::Pop(foundMedia); } else { User::Leave(KErrNotFound); } CleanupStack::PopAndDestroy(result); return foundMedia; }
// --------------------------------------------------------------------------- // rename a media object // --------------------------------------------------------------------------- // void CMPXCollectionHelperImp::RenameL( const TDesC& aOldUri, const TDesC& aNewUri, TMPXGeneralCategory aItemCat ) { MPX_FUNC("CMPXCollectionHelperImp::RenameL"); MPX_DEBUG3("aOldUri = %S, aNewUri = %S", &aOldUri, &aNewUri); if (aItemCat != EMPXSong && aItemCat != EMPXPlaylist && aItemCat != EMPXAbstractAlbum) { User::Leave(KErrArgument); } // find the media using the old URI RArray<TMPXAttribute> attributes; CleanupClosePushL( attributes ); attributes.AppendL(KMPXMediaGeneralId); attributes.AppendL(KMPXMediaMusicAlbumArtFileName); CMPXMedia* media = GetL(aOldUri, attributes.Array(), aItemCat); CleanupStack::PopAndDestroy(&attributes); CleanupStack::PushL(media); const TDesC& fileName(media->ValueText(KMPXMediaMusicAlbumArtFileName)); // the songs have embedded albumart. if(fileName.CompareF(aOldUri) == 0) { // change the Art filename to the new Uri media->SetTextValueL(KMPXMediaMusicAlbumArtFileName, aNewUri); // Rename the thumbnail TRAPD(err, RenameThumbnailL(aOldUri, aNewUri)); if(KErrNone != err) { MPX_DEBUG2("Thumbnail renames failed. Err: %d", err); } } // change file path to the new file path media->SetTextValueL(KMPXMediaGeneralUri, aNewUri); // ask harvester to rename the file if any of the following is true: // 1) renaming a song // 2) renaming a playlist scanned through file system. // // There are 3 types of playlists. The ones created from the device // are virtual playlists which have file extension .vir. There are // no physical playlist files associated with them; hence not // registered with harvester. For virtual playlists, IsPlaylistL // will return EFalse because there is not a playlist plugin that // deals with .vir playlist files. // // The ones synced from PC through MTP have file extension .pla. // There are 0-byte .pla files associated with them but they // are not registered with harvester either. IsPlaylistL will also // return EFalse because there is not a playlist plugin that deals // with .pla. // // The 3rd type of playlists is .m3u on the file system. They are // added to the collection through file scan and registered with // harvester. IsPlaylistL will return ETrue. if (aItemCat == EMPXSong || iHvsUtility->IsPlaylistL(aOldUri)) { const TUid& collection = media->ValueTObjectL<TUid>(KMPXMediaGeneralCollectionId); iHvsUtility->RenameFileL( aOldUri, aNewUri, collection.iUid ); } // Update collection via CMPXCommand // CMPXCommand* cmd = CMPXCommand::NewL(); CleanupStack::PushL( cmd ); cmd->SetTObjectValueL( KMPXCommandGeneralId, KMPXCommandIdCollectionSet ); TUid colId (media->ValueTObjectL<TUid>(KMPXMediaGeneralCollectionId) ); cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, colId.iUid ); cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, ETrue ); cmd->SetCObjectValueL( KMPXCommandColSetMedia, media ); iCollectionUtil->Collection().CommandL( *cmd ); CleanupStack::PopAndDestroy( cmd ); CleanupStack::PopAndDestroy(media); }
// --------------------------------------------------------------------------- // Remove a file from the collection // --------------------------------------------------------------------------- // void CMPXCollectionHelperImp::RemoveL( const TDesC& aFile, TMPXGeneralCategory aItemCat ) { MPX_FUNC("CMPXCollectionHelperImp::RemoveL"); MPX_DEBUG3("aFile %S, category %d", &aFile, aItemCat); if (aItemCat != EMPXSong && aItemCat != EMPXPlaylist) { User::Leave(KErrArgument); } // // ask harvester to remove the file if any of the following is true: // 1) removing a song // 2) removing a playlist scanned through file system. // // There are 3 types of playlists. The ones created from the device // are virtual playlists which have file extension .vir. There are // no physical playlist files associated with them; hence not // registered with harvester. For virtual playlists, IsPlaylistL // will return EFalse because there is not a playlist plugin that // deals with .vir playlist files. // // The ones synced from PC through MTP have file extension .pla. // There are 0-byte .pla files associated with them but they // are not registered with harvester either. IsPlaylistL will also // return EFalse because there is not a playlist plugin that deals // with .pla. // // The 3rd type of playlists is .m3u on the file system. They are // added to the collection through file scan and registered with // harvester. IsPlaylistL will return ETrue. // // For now virtual playlists and synced playlists are assumed to // be in the music collection for now until there is a generic way // resolving collections aside from using file extension or UID. // TInt collection(iMusicCollectionId.iUid); if (aItemCat == EMPXSong || iHvsUtility->IsPlaylistL(aFile)) { // Remove from the harvester collection = iHvsUtility->RemoveFileL( aFile ); } // Remove from the collection // Construct a CMPXMedia object with URI, collection id, type and category // RArray<TInt> contID; CleanupClosePushL( contID ); contID.AppendL( KMPXMediaIdGeneral ); CMPXMedia* media = CMPXMedia::NewL( contID.Array() ); CleanupStack::PushL( media ); media->SetTextValueL( KMPXMediaGeneralUri, aFile ); media->SetTObjectValueL<TUid>( KMPXMediaGeneralCollectionId, TUid::Uid( collection ) ); media->SetTObjectValueL( KMPXMediaGeneralType, EMPXItem ); media->SetTObjectValueL( KMPXMediaGeneralCategory, aItemCat ); // Remove the item via CMPXCommand // CMPXCommand* cmd = CMPXCommand::NewL(); CleanupStack::PushL( cmd ); cmd->SetTObjectValueL( KMPXCommandGeneralCollectionId, collection ); cmd->SetTObjectValueL( KMPXCommandGeneralId, KMPXCommandIdCollectionRemoveMedia ); cmd->SetTObjectValueL( KMPXCommandGeneralDoSync, ETrue ); cmd->SetCObjectValueL( KMPXCommandCollectionRemoveMedia, media ); cmd->SetTObjectValueL( KMPXCommandCollectionRemoveMediaDeleteRecord, ETrue ); iCollectionUtil->Collection().CommandL( *cmd ); CleanupStack::PopAndDestroy( cmd ); CleanupStack::PopAndDestroy( media ); CleanupStack::PopAndDestroy( &contID ); }