// --------------------------------------------------------------------------
// 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);
            }
        }
    }
}
// ----------------------------------------------------------------------------------------------------------
// Find the items matching the media specifications
// ----------------------------------------------------------------------------------------------------------
//
void CTestCollectionPlugin::FindAllL(const CMPXMedia& aCriteria, const TArray<TMPXAttribute>& aAttrs)
{
    LOG1(_L("CTestCollectionPlugin::FindAllL"));
    const TDesC& title = aCriteria.ValueText( KMPXMediaGeneralTitle );
    if(title == _L("CollectionPluginTest0128") ||
            title == _L("CollectionPluginTest0129") )
    {
        // Return exact copy
        CMPXMedia* media = CMPXMedia::NewL();
        (*media) = aCriteria;
        CleanupStack::PushL( media );
        media->SetTObjectValueL<TInt>(KMPXMediaGeneralSize, aAttrs.Count());
        iObs->HandleFindAll(media, KErrNone);
        CleanupStack::PopAndDestroy( media );
    }
    else if(title == _L("CollectionPluginTest0130") )
    {
        // Return error
        CMPXMedia* media = CMPXMedia::NewL();
        (*media) = aCriteria;
        CleanupStack::PushL( media );
        media->SetTObjectValueL<TInt>(KMPXMediaGeneralSize, aAttrs.Count());
        iObs->HandleFindAll(media, KErrArgument);
        CleanupStack::PopAndDestroy( media );
    }
    else
    {
        User::Panic(_L("CTestCollectionPlugin::FindAllL panic"), 1); // magic number
    }
}
// ----------------------------------------------------------------------------------------------------------
// Adds an item (song or playlist) to the collection
// ----------------------------------------------------------------------------------------------------------
//
void CTestCollectionPlugin::AddL (const CMPXMedia& aMedia)
{
    LOG1(_L("CTestCollectionPlugin::AddL"));
    CMPXMessage* message = CMPXMessage::NewL();
    CleanupStack::PushL( message );

    const TDesC& title = aMedia.ValueText( KMPXMediaGeneralTitle );

    if(title == _L("CollectionPluginTest0078") )
    {
        FillItemChangeMessageL(*message, 78, EMPXItemInserted, EMPXOther);
    }
    else if(title == _L("CollectionPluginTest0079"))
    {
        FillItemChangeMessageL(*message, 79, EMPXItemInserted, EMPXSong);
    }
    else if(title == _L("CollectionPluginTest0080"))
    {
        FillItemChangeMessageL(*message, 80, EMPXItemInserted, EMPXPlaylist);
    }
    else
    {
        User::Panic(_L("CTestCollectionPlugin::AddL panic"), 1); // magic number
    }
    iObs->HandleMessage( *message );
    CleanupStack::PopAndDestroy( message );
}
// ----------------------------------------------------------------------------
// Create the playback utility object
// ----------------------------------------------------------------------------
//
EXPORT_C void CMPXAlbumArtUtility::ExtractAlbumArtL(const CMPXMedia& aMedia,
                                            MMPXAlbumArtUtilityObserver& aObs,
                                            const TSize& aSize, 
                                            TDisplayMode aDisplayMode /*= EColor64K*/)
    {
    MPX_FUNC_EX( "CMPXAlbumArtUtility::ExtractAlbumArtL" );

    if ( iCurrentOp != EIdle )
        {
        User::Leave( KErrNotReady );
        }

    if ( aMedia.IsSupported( KMPXMediaMusicAlbumArtFileName ) )
        {
        if ( aMedia.ValueText( KMPXMediaMusicAlbumArtFileName ).Length() == 0)
            {
            User::Leave( KErrNotFound );
            }
        }

    if ( aMedia.IsSupported( KMPXMediaGeneralUri ) &&
         aMedia.IsSupported( KMPXMediaMusicAlbumArtFileName ))
        {
        if ( aMedia.ValueText( KMPXMediaGeneralUri ).CompareF( 
             aMedia.ValueText( KMPXMediaMusicAlbumArtFileName ) ) == 0 )
            { // embedded album art            
            iObs = &aObs;
            delete iAlbumArt;
            iAlbumArt = NULL;
            iAlbumArt = iImageUtil->ExtractL( aMedia.ValueText( KMPXMediaMusicAlbumArtFileName ) );
            if ( iAlbumArt )
                {
                iCurrentOp = EExtractAlbumArtL;
                iObs->ExtractAlbumArtStarted();
                SetActive();
                iImageUtil->Decode( iStatus, *iAlbumArt, *iBitmap, aSize, aDisplayMode );                
                }
            else
                {
                User::Leave( KErrUnderflow );
                }            
            }
        else
            {
            iCurrentOp = EExtractAlbumArtL;
            // TO-DO: if we save externalize bitmap, we only need to internalize bitmap here.
            iObs->ExtractAlbumArtStarted();
            SetActive();
            iImageUtil->Decode( iStatus, aMedia.ValueText( 
                KMPXMediaMusicAlbumArtFileName ), *iBitmap, aSize, aDisplayMode );
            }    
        }
    else
        {
        User::Leave( KErrNotFound );
        }
    }
// ----------------------------------------------------------------------------------------------------------
// 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;
    }
}
// ----------------------------------------------------------------------------------------------------------
// Filter out media in aMediaArray which match aFilter
// ----------------------------------------------------------------------------------------------------------
//
void CTestCollectionPlugin::FilterMediaArray(CMPXMediaArray& aMediaArray, CMPXFilter* aFilter)
{
    if(aFilter )
    {
        TArray<TMPXAttribute> filterAttr = aFilter->Attributes();
        TInt arrCnt = aMediaArray.Count();
        for(TInt i = arrCnt-1; i >= 0; i--) // Remove from the back
        {
            CMPXMedia* media = aMediaArray[i];
            for(TInt ii = 0; ii < filterAttr.Count(); ii++)
            {
                TMPXAttribute attr = filterAttr[ii];
                if( media->IsSupported( attr ) )
                {
                    TBool match = EFalse;
                    if(attr == KMPXMediaGeneralId)
                    {
                        TInt filterId = *aFilter->Value<TInt>( attr );
                        TInt mediaId = *media->Value<TInt>( attr );
                        if(filterId == mediaId)
                            match = ETrue;
                    }
                    else if(attr == KMPXMediaGeneralTitle || attr == KMPXMediaGeneralUri)
                    {
                        const TDesC& filterText = aFilter->ValueText( attr );
                        const TDesC& mediaText = media->ValueText( attr );
                        if(filterText == mediaText)
                            match = ETrue;
                    }
                    if( match )
                    {
                        aMediaArray.Remove( i );
                        break;
                    }
                }
            }
        }
    }
}
// ----------------------------------------------------------------------------
// Adds an item to the collection
// ----------------------------------------------------------------------------
//
void CGlxMediaListsTestCollectionPlugin::AddL(const CMPXMedia& aNewMedia)
    {
    TInt error = KErrNotSupported;
    TInt idAdded = iItemAddedId;

    TMPXGeneralCategory category
            = *aNewMedia.Value<TMPXGeneralCategory>(KMPXMediaGeneralCategory);

    if ( EMPXAlbum == category )
        {
        const TDesC& title = aNewMedia.ValueText(KMPXMediaGeneralTitle);

	InsertItemL(KNullDesC, title, _iItemDBHackAlbums);
        error = KErrNone;
        }
    else if ( EMPXImage == category )
	{
	InsertItemL(_L("c:\\newitem1.jpg"), _L("newitem"), _iItemDBHackContent, TTime(_L("20061105:092527.")), 125371, _L("E:"));
	error = KErrNone;
	}

    if ( iObs )
        {
        if ( KErrNone != error )
            {
            User::Leave(error);
            }
        else
            {
		CMPXMessage* message = CMPXMessage::NewL();
		CleanupStack::PushL(message);

		message->SetTObjectValueL<TMPXMessageId>(KMPXMessageGeneralId, KMPXMessageIdItemChanged);
		message->SetTObjectValueL<TUid>(KMPXMessageCollectionId, TUid::Uid(KGlxMediaListsTestCollectionImplementationUid));
		message->SetTObjectValueL<TMPXChangeEventType>(KMPXMessageChangeEventType, EMPXItemInserted);
		message->SetTObjectValueL<TMPXGeneralCategory>(KMPXMessageMediaGeneralCategory, category);
		message->SetTObjectValueL<TMPXItemId>(KMPXMessageMediaGeneralId, TMPXItemId(idAdded));

		iObs->HandleMessage(*message);

		CleanupStack::PopAndDestroy(message);

/*		    TMPXCollectionChangeEvent event = {TUid::Uid(KGlxMediaListsTestCollectionImplementationUid), idAdded, EMcItemInserted};
		    RArray<TMPXCollectionChangeEvent> events;
		    CleanupClosePushL(events);
		    events.AppendL(event);
		    iObs->HandleChange(events.Array());
		    CleanupStack::PopAndDestroy(&events);
*/          }
        }
    }
// ----------------------------------------------------------------------------------------------------------
// Remove an item from the collection database using the given media properties
// ----------------------------------------------------------------------------------------------------------
//
void CTestCollectionPlugin::RemoveL (const CMPXMedia& aMedia)
{
    LOG1(_L("CTestCollectionPlugin::RemoveL"));
    const TDesC& title = aMedia.ValueText( KMPXMediaGeneralTitle );

    // a list of change event messages a result of the item being removed
    CMPXMessageArray* itemChangedMessages = CMPXMessageArray::NewL();
    CleanupStack::PushL(itemChangedMessages);

    if(title == _L("CollectionPluginTest0099") )
    {
        CMPXMessage* message = CMPXMessage::NewL();
        CleanupStack::PushL(message);
        FillItemChangeMessageL(*message, 99, EMPXItemDeleted, EMPXSong);
        itemChangedMessages->AppendL( *message );
        CleanupStack::PopAndDestroy(message);
    }
    else if(title == _L("CollectionPluginTest0100") )
    {
        CMPXMessage* message = CMPXMessage::NewL();
        CleanupStack::PushL(message);
        FillItemChangeMessageL(*message, 100, EMPXItemDeleted, EMPXSong);
        itemChangedMessages->AppendL( *message );
        CleanupStack::PopAndDestroy(message);
        message = NULL;
        message = CMPXMessage::NewL();
        CleanupStack::PushL(message);
        FillItemChangeMessageL(*message, 100, EMPXItemDeleted, EMPXSong);
        itemChangedMessages->AppendL( *message );
        CleanupStack::PopAndDestroy(message);
    }
    else
    {
        User::Panic(_L("CTestCollectionPlugin::RemoveL panic"), 1); // magic number
    }

    CMPXMessage* message = CMPXMessage::NewL();
    CleanupStack::PushL(message);

    message->SetTObjectValueL<TMPXMessageId>(
        TMPXAttribute(KMPXMessageContentIdGeneral, EMPXMessageGeneralId), KMPXMessageIdItemChanged);
    message->SetCObjectValueL(
        TMPXAttribute(KMPXMessageIdContainer, EMPXMessageArrayContents), itemChangedMessages);
    message->SetTObjectValueL(
        TMPXAttribute(KMPXMessageIdContainer, EMPXMessageArrayCount), itemChangedMessages->Count());

    iObs->HandleMessage( *message );
    CleanupStack::PopAndDestroy(2, itemChangedMessages);    // message, itemChangedMessages
}
/*!
 Stub function.
*/
void MMPXCollectionUiHelper::RenameL( const CMPXMedia& aMedia,
                              MMPXCHelperObserver* aObserver )
{
    Q_UNUSED(aObserver);
    iValidRename = EFalse;
    TMPXGeneralType mediaType =
            aMedia.ValueTObjectL<TMPXGeneralType>(KMPXMediaGeneralType);

    TMPXGeneralCategory mediaCategory =
            aMedia.ValueTObjectL<TMPXGeneralCategory>(KMPXMediaGeneralCategory);
    
    if ( mediaType == EMPXItem && mediaCategory == EMPXPlaylist ){
        iValidRename = ETrue;
    }
    iPlaylistId = aMedia.ValueTObjectL<TMPXItemId>(KMPXMediaGeneralId);
    const TDesC& title = aMedia.ValueText(KMPXMediaGeneralTitle);
    iRenameTitle = QString::fromUtf16(title.Ptr(), title.Length());
}
示例#11
0
// ----------------------------------------------------------------------------
// 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);
    }
// ---------------------------------------------------------------------------
// 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 );
    }
// ----------------------------------------------------------------------------------------------------------
// Navigates to the given path
// ----------------------------------------------------------------------------------------------------------
//
void CTestCollectionPlugin::OpenL(const CMPXCollectionPath& aPath,
                                  const TArray<TMPXAttribute>& aAttrs,
                                  CMPXFilter* aFilter)
{
    LOG1(_L("CTestCollectionPlugin::OpenL"));
    LogPath( aPath );
    TMPXOpenMode openMode = aPath.OpenNextMode();
    TInt idIndex = aPath.Levels() - 1;
    LOG2(_L("TMPXOpendMode=%d"), openMode);
    LOG2(_L("aFilter=%x"), aFilter);

    RArray<TInt> supportedIds;
    CleanupClosePushL(supportedIds);
    supportedIds.AppendL(KMPXMediaIdContainer);
    supportedIds.AppendL(KMPXMediaIdGeneral);

    CMPXMedia* entries = CMPXMedia::NewL(supportedIds.Array());
    CleanupStack::PopAndDestroy(&supportedIds);
    CleanupStack::PushL(entries);
    entries->SetTObjectValueL<TMPXItemId>(TMPXAttribute(KMPXMediaIdGeneral,EMPXMediaGeneralId), aPath.Id(idIndex));

    if(aPath.Levels() == 1)
    {
        // Plugin's root level
        RArray<TInt> ids;
        CleanupClosePushL( ids );
        ids.Append( 11 );
        ids.Append( 12 );
        ids.Append( 13 );
        ids.Append( 990 );  // for Playback Framework Test
        RArray<TMPXAttribute> attrs;
        CleanupClosePushL( attrs );
        attrs.Append( KMPXMediaGeneralId );
        attrs.Append( KMPXMediaGeneralUri );
        attrs.Append( KMPXMediaGeneralTitle );

        CMPXMediaArray* array=CMPXMediaArray::NewL();
        CleanupStack::PushL( array );

        const TArray<TMPXAttribute>& tempRef = aAttrs.Count() == 0? attrs.Array() : aAttrs;
        AddMediaL(*array, ids, tempRef);
        FilterMediaArray(*array, aFilter);

        entries->SetCObjectValueL (TMPXAttribute(KMPXMediaIdContainer,EMPXMediaArrayContents),array);
        entries->SetTObjectValueL (TMPXAttribute(KMPXMediaIdContainer,EMPXMediaArrayCount),array->Count());

        iObs->HandleOpen (entries, KErrNone);
        CleanupStack::PopAndDestroy(3, &ids);   // attrs, array, ids
    }
    else if(aPath.Levels() == 2)
    {
        // Opening plugin's root menu
        TInt topLevId = aPath.Id(1);
        RArray<TInt> ids;
        CleanupClosePushL( ids );
        RArray<TMPXAttribute> attrs;
        CleanupClosePushL( attrs );
        CMPXMediaArray* array=CMPXMediaArray::NewL();
        CleanupStack::PushL( array );

        attrs.Append( KMPXMediaGeneralId );
        attrs.Append( KMPXMediaGeneralUri );
        attrs.Append( KMPXMediaGeneralTitle );
        if(topLevId == 11)
        {
            ids.Append( 211 );
            ids.Append( 212 );
            ids.Append( 213 );
        }
        else if(topLevId == 12)
        {
            ids.Append( 221 );
        }
        else if(topLevId == 13)
        {
            ids.Append( 231 );
            ids.Append( 232 );
        }
        else if(topLevId == 990)
        {
            ids.Append( 9901 );
            ids.Append( 9902 );
            ids.Append( 9903 );
            ids.Append( 9904 );
            ids.Append( 9905 );
            ids.Append( 9906 );
            ids.Append( 9907 );
        }
        const TArray<TMPXAttribute>& tempRef = aAttrs.Count() == 0? attrs.Array() : aAttrs;
        AddMediaL(*array, ids, tempRef);
        FilterMediaArray(*array, aFilter);

        entries->SetCObjectValueL (TMPXAttribute(KMPXMediaIdContainer,EMPXMediaArrayContents),array);
        entries->SetTObjectValueL (TMPXAttribute(KMPXMediaIdContainer,EMPXMediaArrayCount),array->Count());

        iObs->HandleOpen (entries, KErrNone);
        CleanupStack::PopAndDestroy(3, &ids);   // attrs, array, ids
    }
    else if(aPath.Levels() == 3)
    {
        // Opening plugin's 2nd
        TInt secLevId = aPath.Id(2);

        RArray<TInt> ids;
        CleanupClosePushL( ids );
        RArray<TMPXAttribute> attrs;
        CleanupClosePushL( attrs );
        CMPXMediaArray* array=CMPXMediaArray::NewL();
        CleanupStack::PushL( array );

        attrs.Append( KMPXMediaGeneralId );
        attrs.Append( KMPXMediaGeneralUri );
        attrs.Append( KMPXMediaGeneralTitle );
        switch( secLevId )
        {
        case 211:
            ids.Append( 3111 );
            break;
        case 212:
            ids.Append( 3121 );
            break;
        case 213:
            ids.Append( 3131 );
            break;
        case 221:
            // Empty
            break;
        case 231:
            ids.Append( 3311 );
            break;
        case 232:
            ids.Append( 3321 );
            break;
        };
        const TArray<TMPXAttribute>& tempRef = aAttrs.Count() == 0? attrs.Array() : aAttrs;
        AddMediaL(*array, ids, tempRef);
        FilterMediaArray(*array, aFilter);

        entries->SetCObjectValueL (TMPXAttribute(KMPXMediaIdContainer,EMPXMediaArrayContents),array);
        entries->SetTObjectValueL (TMPXAttribute(KMPXMediaIdContainer,EMPXMediaArrayCount),array->Count());

        iObs->HandleOpen (entries, KErrNone);
        CleanupStack::PopAndDestroy(3, &ids);   // attrs, array, ids
    }
    else
    {
        User::Leave( KErrNotFound );
    }
    CleanupStack::PopAndDestroy( entries );
}
// ---------------------------------------------------------------------------
// 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;
    }
// ---------------------------------------------------------------------------
// From MMPXPlaybackCallback
// Handle media
// ---------------------------------------------------------------------------
//
void CAiPlayerPluginEngine::HandleMediaL( const CMPXMedia& aMedia, 
        TInt aError )
    {
    if ( KErrNone == aError )
        {
        delete iUri;
        iUri = NULL;
        if (aMedia.IsSupported(KMPXMediaGeneralUri))
            {
            TParsePtrC filePath(aMedia.ValueText(KMPXMediaGeneralUri) );
            iUri = filePath.FullName().AllocL();
            }
        
		delete iTitle;
		iTitle = NULL;
        if ( aMedia.IsSupported( KMPXMediaGeneralTitle ) )
            {
            iTitle = ( aMedia.ValueText( KMPXMediaGeneralTitle ) ).AllocL();
            }
        else if ( aMedia.IsSupported( KMPXMediaGeneralDuration))
        {
            RDebug::Print(_L("duration found"));
            TInt val=aMedia.ValueTObjectL<TInt>( KMPXMediaGeneralDuration );
            RDebug::Print(_L("val %d"),val);
            iDuration=val/KMPXOneSecInMilliSecs;
        }
        else if ( aMedia.IsSupported( KMPXMediaGeneralUri ) )
            {
            TParsePtrC filePath( aMedia.ValueText( KMPXMediaGeneralUri ) );
            iTitle = (filePath.Name()).AllocL();
            }
		delete iArtist;
		iArtist = NULL;
		if ( aMedia.IsSupported( KMPXMediaMusicArtist ) )
		    {
		    iArtist = ( aMedia.ValueText( KMPXMediaMusicArtist ) ).AllocL();
		    }

		iObserver->TrackInfoChanged(iTitle ? *iTitle : KNullDesC(), iArtist ? *iArtist : KNullDesC());

		if (!iSkipping)
            {
            if (iExtractingAlbumArt)
                {
                if (iAlbumArtUtil){iAlbumArtUtil->CancelRequest();}
                iExtractingAlbumArt=EFalse;
                }
            
            if ( aMedia.IsSupported( KMPXMediaMusicAlbumArtFileName ) )
                {
                delete iMedia;
                iMedia=NULL;
                iMedia = CMPXMedia::NewL( aMedia );
                TRAPD(err,iAlbumArtUtil->ExtractAlbumArtL(
                        *iMedia,
                        *this,
                        KAlbumArtSize,
                        EFalse));
                
                if (err != KErrNone)
                    {
                    iObserver->AlbumArtChanged(NULL);
                    }
                }
            else
                {
                iObserver->AlbumArtChanged(NULL);
                }

            }
		else
		    {
		    iObserver->AlbumArtChanged(NULL);
		    }
        }
    }
// ---------------------------------------------------------------------------
// From MMPXPlaybackCallback
// Handle media
// ---------------------------------------------------------------------------
//
void CAiPlayerPluginEngine::HandleMediaL( const CMPXMedia& aMedia, 
        TInt aError )
    {
    //MPX_DEBUG1("CAiPlayerPluginEngine::HandleMediaL");
    if ( KErrNone == aError )
        {
        delete iUri;
        iUri = NULL;
        if (aMedia.IsSupported(KMPXMediaGeneralUri))
            {
            TParsePtrC filePath(aMedia.ValueText(KMPXMediaGeneralUri) );
            iUri = filePath.FullName().AllocL();
            }
        
		delete iTitle;
		iTitle = NULL;
        if ( aMedia.IsSupported( KMPXMediaGeneralTitle ) )
            {
            iTitle = ( aMedia.ValueText( KMPXMediaGeneralTitle ) ).AllocL();
            }
        else if ( aMedia.IsSupported( KMPXMediaGeneralUri ) )
            {
            TParsePtrC filePath( aMedia.ValueText( KMPXMediaGeneralUri ) );
            iTitle = (filePath.Name()).AllocL();
            }
		delete iArtist;
		iArtist = NULL;
		iArtist = ( aMedia.ValueText( KMPXMediaMusicArtist ) ).AllocL();
		
		iObserver->TrackInfoChanged( *iTitle, *iArtist );
        
		if (!iSkipping)
            {
            if (iExtractingAlbumArt)
                {
                //iAlbumArtUtil->CancelRequest();
                iExtractingAlbumArt=EFalse;
                }
            /*
            if ( aMedia.IsSupported( KMPXMediaMusicAlbumArtFileName ) )
                {
                delete iMedia;
                iMedia=NULL;
                iMedia = CMPXMedia::NewL( aMedia );
             
                TRAPD(err,iAlbumArtUtil->ExtractAlbumArtL(
                        *iMedia,
                        *this,
                        TSize(70,70)));
                
                if (err != KErrNone)
                    {
                    iObserver->AlbumArtChanged(NULL);
                    }
                }
            else
                {
                iObserver->AlbumArtChanged(NULL);
                }
                */
            }
		else
		    {
		    iObserver->AlbumArtChanged(NULL);
		    }
        }
    }
void T_CGlxCache::T_CGlxCache_MediaUpdatedLL(  )
    {
    // Create helper class
    T_CacheTestHelpers cacheTestHelper(iCGlxCache);

    // New media
    CMPXMedia* newMedia3 = CMPXMedia::NewL();
    CleanupStack::PushL(newMedia3);

    newMedia3->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(KMediaId3));

    EUNIT_PRINT(_L("Add new media"));
    iCGlxCache->MediaUpdatedL(*newMedia3);

    EUNIT_PRINT(_L("Check new media added"));
    EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool().Count() == 3, "Cache doesn't contain three items");

    TInt cachedNewMedia3Index = cacheTestHelper.ItemPool().FindInOrder(TGlxMediaId(KMediaId3), T_CacheTestHelpers::MediaItemOrderByKey);
    EUNIT_ASSERT_DESC(cachedNewMedia3Index != KErrNotFound, "New media not added to cache");

    CleanupStack::PopAndDestroy(newMedia3);

    // Multiple new media
    CMPXMedia* newMultipleMedia = CMPXMedia::NewL();
    CleanupStack::PushL(newMultipleMedia);

    CMPXMediaArray* newMediaArray = CMPXMediaArray::NewL();
    CleanupStack::PushL(newMediaArray);

    CMPXMedia* newMedia4 = CMPXMedia::NewL();
    CleanupStack::PushL(newMedia4);

    newMedia4->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(KMediaId4));

    newMediaArray->AppendL(newMedia4);
    CleanupStack::Pop(newMedia4);

    CMPXMedia* newMedia5 = CMPXMedia::NewL();
    CleanupStack::PushL(newMedia5);

    newMedia5->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, TMPXItemId(KMediaId5));

    newMediaArray->AppendL(newMedia5);
    CleanupStack::Pop(newMedia5);

    newMultipleMedia->SetCObjectValueL(KMPXMediaArrayContents, newMediaArray);
    newMultipleMedia->SetTObjectValueL(KMPXMediaArrayCount, newMediaArray->Count());

    EUNIT_PRINT(_L("Add multiple new media"));
    iCGlxCache->MediaUpdatedL(*newMultipleMedia);

    CleanupStack::PopAndDestroy(newMediaArray);
    CleanupStack::PopAndDestroy(newMultipleMedia);

    EUNIT_PRINT(_L("Check multiple new media added"));
    EUNIT_ASSERT_DESC(cacheTestHelper.ItemPool().Count() == 5, "Cache doesn't contain five items");

    TInt cachedNewMedia4Index = cacheTestHelper.ItemPool().FindInOrder(TGlxMediaId(KMediaId4), T_CacheTestHelpers::MediaItemOrderByKey);
    TInt cachedNewMedia5Index = cacheTestHelper.ItemPool().FindInOrder(TGlxMediaId(KMediaId5), T_CacheTestHelpers::MediaItemOrderByKey);
    EUNIT_ASSERT_DESC((cachedNewMedia4Index != KErrNotFound) && (cachedNewMedia5Index != KErrNotFound), "Multiple new media not added to cache");
    }