// ----------------------------------------------------------------------------------------------------------
// Remove an item from the collection database using the given path
// ----------------------------------------------------------------------------------------------------------
//
void CTestCollectionPlugin::RemoveL (const CMPXCollectionPath& aPath)
{
    LOG1(_L("CTestCollectionPlugin::RemoveL"));
    LogPath( aPath );
    CDesCArrayFlat* fp = new (ELeave) CDesCArrayFlat(8);
    CleanupStack::PushL( fp );
    switch( aPath.Levels() )
    {
    case 2:
        if(aPath.Id() == 14)
        {   // Test0091
            iObs->HandleRemove( *fp, KErrNotFound );
        }
        break;
    case 3:
        if(aPath.Id() == 212)
        {   // Test0090
            fp->AppendL( _L("\\song3121.ts") );
            fp->AppendL( _L("\\song3122.ts") );
            fp->AppendL( _L("\\song3123.tp") );
            iObs->HandleRemove( *fp, KErrNone );
        }
        break;
    case 4:
        if(aPath.Id() == 3111)
        {   // Test0088
            fp->AppendL( _L("\\song3111.ts") );
            iObs->HandleRemove( *fp, KErrNone );
        }
        break;
    default:
        User::Panic(_L("CTestCollectionPlugin::RemoveL panic"), 1); // magic number
    }
    CleanupStack::PopAndDestroy( fp );
}
// ----------------------------------------------------------------------------
// Navigates to the given path
// ----------------------------------------------------------------------------
//
void CGlxMediaListsTestCollectionPlugin::OpenL(const CMPXCollectionPath& aPath,
                   const TArray<TMPXAttribute>& /*aAttrs*/,
                   CMPXFilter* /*aFilter*/)
    {
    RArray<TInt> supportedIds;
    CleanupClosePushL(supportedIds);
    supportedIds.AppendL(KMPXMediaIdContainer);
    supportedIds.AppendL(KMPXMediaIdGeneral);
    iOpenEntries = CMPXMedia::NewL(supportedIds.Array());

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

 	if ( aPath.Levels() == 1 ) 
 		{
 		TInt count = _iItemDBHackAlbums.Count();
 		for ( TInt i = 0; i < count; i++ )
 			{
 			AppendL(_iItemDBHackAlbums[i]->iId, *_iItemDBHackAlbums[i]->iTitle, *array, EMPXGroup, EMPXAlbum);
 			}
 		}
 	else if ( aPath.Levels() == 2 ) 
 		{
 		TInt count = _iItemDBHackContent.Count();
 		for ( TInt i = 0; i < count; i++ )
 			{
 			AppendL(_iItemDBHackContent[i]->iId, *_iItemDBHackContent[i]->iTitle, *array, EMPXItem, EMPXImage);
 			}

		StartEvents();
 		}
 	else 
 		{
 		__DEBUG_ONLY(Panic(EGlxPanicDebugUnexpectedError));
 		}
    
    iOpenEntries->SetCObjectValueL(KMPXMediaArrayContents, array);
    iOpenEntries->SetTObjectValueL(KMPXMediaArrayCount, array->Count());

    CleanupStack::PopAndDestroy(array);    

	//iObs->HandleOpen(*iOpenEntries, KErrNone);
	
    AsyncNotifyL(iOpenEntries, KErrNone, CGlxAsyncNotifier::EOpen);
        
    CleanupStack::PopAndDestroy(&supportedIds);        
    }
// ----------------------------------------------------------------------------------------------------------
// 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 );
}