// ---------------------------------------------------------------------------- // 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); }
void CGlxCollectionPluginAlbums::HandleCpiAttributeResponseL(CMPXMedia* aResponse, TArray<TMPXAttribute> aCpiAttributes, TArray<TGlxMediaId> aMediaIds) { TRACER("CGlxCollectionPluginAlbums::HandleCpiAttributeResponseL"); const TInt mediaIdCount = aMediaIds.Count(); switch (mediaIdCount) { case 0: User::Leave(KErrNotSupported); break; case 1: HandleCpiAttributeResponseL(aResponse, aCpiAttributes, aMediaIds[0]); break; default: { // We have an array of CMPXMedia items if (TGlxMediaId(KGlxCollectionRootId) == aMediaIds[0]) { User::Leave(KErrNotSupported); } CMPXMediaArray* mediaArray = aResponse->ValueCObjectL<CMPXMediaArray>(KMPXMediaArrayContents); CleanupStack::PushL(mediaArray); const TInt arrayCount = mediaArray->Count(); // Sanity check if (arrayCount != mediaIdCount) { User::Leave(KErrArgument); } for (TInt index = 0; index < arrayCount; index++) { HandleCpiAttributeResponseL((*mediaArray)[index], aCpiAttributes, aMediaIds[index]); } aResponse->SetCObjectValueL(KMPXMediaArrayContents, mediaArray); CleanupStack::PopAndDestroy(mediaArray); } 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; } } } } } }
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"); }