diff -r 8f0df5c82986 -r 67eb01668b0e videocollection/mpxmyvideoscollection/src/vcxmyvideosopenhandler.cpp --- a/videocollection/mpxmyvideoscollection/src/vcxmyvideosopenhandler.cpp Tue May 25 12:44:54 2010 +0300 +++ b/videocollection/mpxmyvideoscollection/src/vcxmyvideosopenhandler.cpp Wed Jun 09 09:44:23 2010 +0300 @@ -11,11 +11,11 @@ * * Contributors: * -* Description: Handles collection Open operation related functionality.* +* Description: Handles collection Open operation related functionality. +* */ - // INCLUDE FILES #include #include @@ -31,6 +31,8 @@ #include "vcxmyvideoscategories.h" #include "vcxmyvideosmessagelist.h" #include "vcxmyvideoscollectionutil.h" +#include "vcxmyvideosalbums.h" +#include "vcxmyvideosmdsalbums.h" // ============================ MEMBER FUNCTIONS ============================= @@ -52,6 +54,9 @@ void CVcxMyVideosOpenHandler::ConstructL() { iCategoryIdsBeingOpened.Reset(); + iVideoListsBeingOpened.Reset(); + iAlbumIdsBeingOpened.Reset(); + iAlbumVideoListsBeingOpened.Reset(); } // --------------------------------------------------------------------------- @@ -85,6 +90,16 @@ iVideoListsBeingOpened[i] = NULL; } iVideoListsBeingOpened.Close(); + + iAlbumIdsBeingOpened.Close(); + + count = iAlbumVideoListsBeingOpened.Count(); + for ( TInt i = 0; i < count; i++ ) + { + delete iAlbumVideoListsBeingOpened[i]; + iAlbumVideoListsBeingOpened[i] = NULL; + } + iAlbumVideoListsBeingOpened.Close(); } // --------------------------------------------------------------------------- @@ -99,114 +114,89 @@ MPX_DEBUG1("CVcxMyVideosOpenHandler:: path before open:"); MPX_DEBUG_PATH( aPath ); + iPath = &aPath; + + const TInt categoryLevel = 1; + const TInt videosLevel = 2; + const TInt playlistLevel = 3; + switch ( aPath.Levels() ) { - case 1: + case categoryLevel: { - //we are at root level, return main level items (categories) - - // this is needed to update category counters + //we are at root level, return main level items (categories + albums) + +#ifndef VIDEO_COLLECTION_PLUGIN_TB92 + iCollection.AlbumsL().CreateAlbumListL(); //async +#endif + + // This is needed to update category counters. + // Goes to queue if CreateAlbumListL command goes to execution TRAPD( err, iCache.CreateVideoListL() ); if ( err != KErrNone ) { - MPX_DEBUG2("iCache->CreateVideoListL() left: %d. Returning categories anyway.", err); + MPX_DEBUG2("iCache->CreateVideoListL() left: %d. Returning categories and albums anyway.", err); } - iCollection.CategoriesL().iList-> - SetTObjectValueL( KVcxMediaMyVideosVideoListIsPartial, - iCache.iVideoListIsPartial ); - - iCollection.iObs->HandleOpen( iCollection.CategoriesL().iList, KErrNone ); + CMPXMedia* itemList = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL(); + CleanupStack::PushL( itemList ); + + itemList->SetTObjectValueL( KVcxMediaMyVideosVideoListIsPartial, + !iCache.IsComplete() ); + + TVcxMyVideosCollectionUtil::AppendToListL( *itemList, *iCollection.CategoriesL().iList ); +#ifndef VIDEO_COLLECTION_PLUGIN_TB92 + TVcxMyVideosCollectionUtil::AppendToListL( *itemList, *iCollection.AlbumsL().iAlbumList ); +#endif + itemList->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath ); + iCollection.iObs->HandleOpen( itemList, KErrNone ); + CleanupStack::PopAndDestroy( itemList ); + MPX_DEBUG1("CVcxMyVideosOpenHandler:: called HandleOpen for categories + albums"); } break; - case 2: + case videosLevel: { - //we are at second level, return video list from some category + //we are at second level, return video list from some category or album - TInt categoryId = aPath.Id(); +#ifndef VIDEO_COLLECTION_PLUGIN_TB92 + iCollection.AlbumsL().CreateAlbumListL(); //async +#endif - MPX_DEBUG2("CVcxMyVideosOpenHandler:: opening category %d", categoryId); + TMPXItemId categoryId( aPath.Id() ); - if ( categoryId != KVcxMvcCategoryIdAll && - categoryId != KVcxMvcCategoryIdDownloads && - categoryId != KVcxMvcCategoryIdTvRecordings && - categoryId != KVcxMvcCategoryIdCaptured && - categoryId != KVcxMvcCategoryIdOther ) + if ( ( categoryId.iId2 == KVcxMvcMediaTypeCategory ) || + ( categoryId.iId2 == KVcxMvcMediaTypeVideo ) && + (categoryId.iId1 == KVcxMvcCategoryIdAll || + categoryId.iId1 == KVcxMvcCategoryIdDownloads || + categoryId.iId1 == KVcxMvcCategoryIdTvRecordings || + categoryId.iId1 == KVcxMvcCategoryIdCaptured || + categoryId.iId1 == KVcxMvcCategoryIdOther) ) { - MPX_DEBUG2("CVcxMyVideosOpenHandler:: category ID not valid (%d) -> calling HandleOpen with KErrNotFound", categoryId); - iCollection.iObs->HandleOpen( static_cast(NULL), KErrNotFound ); + MPX_DEBUG2("CVcxMyVideosOpenHandler:: opening category %d", categoryId.iId1 ); + OpenCategoryL( categoryId.iId1 ); return; } - - TUint8 origin = static_cast( TVcxMyVideosCollectionUtil::Origin( categoryId ) ); - - iCache.CreateVideoListL(); // Causes async call to MDS, callbacks to DoHandleCreateVideoListRespL will happen. - // If iCache.iVideoList is complete and can be used (correct sorting order), - // then nothing is done. - - if ( !iCache.iVideoListIsPartial ) + else { - MPX_DEBUG1("CVcxMyVideosOpenHandler:: videolist complete"); - - // iCache.iVideoList is complete - if ( categoryId == KVcxMvcCategoryIdAll ) + MPX_DEBUG2("CVcxMyVideosOpenHandler:: opening album %d", categoryId.iId1 ); + + iPendingAlbumOpenId = categoryId.iId1; + if ( iCollection.AlbumsL().iAlbumListIsComplete ) { - MPX_DEBUG1("CVcxMyVideosOpenHandler:: KVcxMvcCategoryIdAll: calling HandleOpen(iCache.iVideoList)"); - iCollection.iObs->HandleOpen( iCache.iVideoList, KErrNone ); + HandleAlbumOpenL(); // iPendingAlbumOpenId goes to 0 + return; } else { - MPX_DEBUG1("CVcxMyVideosOpenHandler:: other than KVcxMvcCategoryIdAll: creating new category video list"); - CMPXMedia* videoList = iCache.CreateVideoListByOriginL( origin ); - MPX_DEBUG1("CVcxMyVideosOpenHandler:: calling HandleOpen(new list)"); - iCollection.iObs->HandleOpen( videoList, KErrNone ); - delete videoList; - } - iCollection.iMessageList->AddEventL( KVcxMessageMyVideosListComplete ); - iCollection.iMessageList->SendL(); - - // No append events will arrive anymore -> we create our own version of the - // video list. - iCache.ReCreateVideoListL(); - } - else - { - MPX_DEBUG1("CVcxMyVideosOpenHandler:: video list incomplete"); - // iCache.iVideoList is incomplete - - if ( categoryId == KVcxMvcCategoryIdAll ) - { - MPX_DEBUG1("CVcxMyVideosOpenHandler:: KVcxMvcCategoryIdAll, calling HandleOpen"); - iCollection.iObs->HandleOpen( iCache.iVideoList, KErrNone ); + // We will continue at HandleAlbumOpenL when album list arrives, iPendingAlbumOpenId is left != 0 + return; } - else - { - MPX_DEBUG1("CVcxMyVideosOpenHandler:: other than KVcxMvcCategoryIdAll"); + } + } - TInt pos = iCategoryIdsBeingOpened.Find( categoryId ); - if ( pos == KErrNotFound ) - { - MPX_DEBUG1("CVcxMyVideosOpenHandler:: category was not opened yet, creating list for it"); - iCategoryIdsBeingOpened.AppendL( categoryId ); - CMPXMedia* videoList = iCache.CreateVideoListByOriginL( origin ); - iVideoListsBeingOpened.AppendL( videoList ); - MPX_DEBUG1("CVcxMyVideosOpenHandler:: calling HandleOpen"); - iCollection.iObs->HandleOpen( iCache.iVideoList, KErrNone ); - } - else - { - MPX_DEBUG1("CVcxMyVideosOpenHandler:: category was already being opened, calling HandleOpen with that"); - iCollection.iObs->HandleOpen( iVideoListsBeingOpened[pos], KErrNone ); - } - } - } - - } - break; - - case 3: + case playlistLevel: { iCollection.iObs->HandleOpen(const_cast (&aPath), KErrNone); } @@ -218,14 +208,95 @@ } //switch } +// --------------------------------------------------------------------------- +// CVcxMyVideosOpenHandler::OpenCategoryL +// --------------------------------------------------------------------------- +// +void CVcxMyVideosOpenHandler::OpenCategoryL( TUint32 aCategoryId ) + { + TUint8 origin = static_cast( TVcxMyVideosCollectionUtil::Origin( aCategoryId ) ); + + iCache.CreateVideoListL(); // Causes async call to MDS, callbacks to DoHandleCreateVideoListRespL will follow. + // If iCache.iVideoList is complete and can be used (correct sorting order), + // then nothing is done. + + if ( iCache.IsComplete() ) + { + MPX_DEBUG1("CVcxMyVideosOpenHandler:: videolist complete"); + + // iCache.iVideoList is complete + if ( aCategoryId == KVcxMvcCategoryIdAll ) + { + MPX_DEBUG1("CVcxMyVideosOpenHandler:: KVcxMvcCategoryIdAll: calling HandleOpen(iCache.iVideoList)"); + iCache.iVideoList->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath ); + iCache.iVideoList->SetTObjectValueL( KVcxMediaMyVideosInt32Value, + EVcxMyVideosVideoListComplete ); + iCollection.iObs->HandleOpen( iCache.iVideoList, KErrNone ); + } + else + { + MPX_DEBUG1("CVcxMyVideosOpenHandler:: other than KVcxMvcCategoryIdAll: creating new category video list"); + CMPXMedia* videoList = iCache.CreateVideoListByOriginL( origin ); + MPX_DEBUG1("CVcxMyVideosOpenHandler:: calling HandleOpen(new list)"); + videoList->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath ); + videoList->SetTObjectValueL( KVcxMediaMyVideosInt32Value, + EVcxMyVideosVideoListComplete ); + iCollection.iObs->HandleOpen( videoList, KErrNone ); + delete videoList; + } + iCollection.iMessageList->AddEventL( KVcxMessageMyVideosListComplete ); + iCollection.iMessageList->SendL(); + + // No append events will arrive anymore -> we create our own version of the + // video list. + iCache.ReCreateVideoListL(); + } + else + { + MPX_DEBUG1("CVcxMyVideosOpenHandler:: video list incomplete"); + // iCache.iVideoList is incomplete + + if ( aCategoryId == KVcxMvcCategoryIdAll ) + { + MPX_DEBUG1("CVcxMyVideosOpenHandler:: KVcxMvcCategoryIdAll, calling HandleOpen"); + iCache.iVideoList->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath ); + iCollection.iObs->HandleOpen( iCache.iVideoList, KErrNone ); + } + else + { + MPX_DEBUG1("CVcxMyVideosOpenHandler:: other than KVcxMvcCategoryIdAll"); + + TInt pos = iCategoryIdsBeingOpened.Find( aCategoryId ); + if ( pos == KErrNotFound ) + { + MPX_DEBUG1("CVcxMyVideosOpenHandler:: category was not opened yet, creating list for it"); + iCategoryIdsBeingOpened.AppendL( aCategoryId ); + CMPXMedia* videoList = iCache.CreateVideoListByOriginL( origin ); + CleanupStack::PushL( videoList ); + iVideoListsBeingOpened.AppendL( videoList ); + CleanupStack::Pop( videoList ); + MPX_DEBUG1("CVcxMyVideosOpenHandler:: calling HandleOpen"); + videoList->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath ); + iCollection.iObs->HandleOpen( videoList, KErrNone ); + } + else + { + MPX_DEBUG1("CVcxMyVideosOpenHandler:: category was already being opened, calling HandleOpen with that"); + iVideoListsBeingOpened[pos]->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath ); + iCollection.iObs->HandleOpen( iVideoListsBeingOpened[pos], KErrNone ); + } + } + } + } + // ---------------------------------------------------------------------------- // CVcxMyVideosOpenHandler::DoHandleCreateVideoListRespL -// New items fetched from MDS. iCache.iVideoList = aVideoList. +// New items fetched from MDS. iCollection.iCache->iVideoList = &aVideoList. // ---------------------------------------------------------------------------- // void CVcxMyVideosOpenHandler::DoHandleCreateVideoListRespL( CMPXMedia* aVideoList, TInt aNewItemsStartIndex, TBool aComplete ) - { + { MPX_FUNC("CVcxMyVideosOpenHandler::DoHandleCreateVideoListRespL()"); MPX_DEBUG2("CVcxMyVideosOpenHandler:: aComplete = %d", aComplete); @@ -237,29 +308,36 @@ } // Append new items to category video lists. All category is using iCache.iVideoList, thus no need to append to it. - TInt count = iCategoryIdsBeingOpened.Count(); - for ( TInt i = 0; i < count; i++ ) + TInt categoryCount = iCategoryIdsBeingOpened.Count(); + for ( TInt i = 0; i < categoryCount; i++ ) { iCache.AppendToListL( *iVideoListsBeingOpened[i], *aVideoList, TVcxMyVideosCollectionUtil::Origin( iCategoryIdsBeingOpened[i] ), aNewItemsStartIndex ); } - + + // Append new items to album video lists. + TInt albumCount = iAlbumVideoListsBeingOpened.Count(); + for ( TInt i = 0; i < albumCount; i++ ) + { + iCollection.iAlbums->Album( iAlbumIdsBeingOpened[i] )->AppendToVideoListL( + *aVideoList, *(iAlbumVideoListsBeingOpened[i]), aNewItemsStartIndex ); + } + if ( aComplete == 0 ) { iCollection.iMessageList->AddEventL( KVcxMessageMyVideosItemsAppended ); // Still fetching items - // Missing download fields filled from download manager - TRAP_IGNORE( iCollection.SyncVideoListWithDownloadsL( *(iCache.iVideoList), - EFalse /* dont send events */, aNewItemsStartIndex ); ); iCollection.CategoriesL().UpdateCategoriesL( *aVideoList, aNewItemsStartIndex ); } else { // End event arrived - iCache.iVideoListIsPartial = EFalse; + iCache.SetComplete( ETrue ); + iCache.iIsFetchingVideoList = EFalse; + // Create modify event for All category. // This will cause client to make a new OpenL() call. @@ -271,7 +349,7 @@ EVcxMyVideosVideoListOrderChanged ); // We dont send here, the send is at the end of this function. - for ( TInt i = 0; i < count; i++ ) + for ( TInt i = 0; i < categoryCount; i++ ) { // Create modify event for other than All categories. // This will cause client to make a new OpenL() call. @@ -288,14 +366,184 @@ iVideoListsBeingOpened.Reset(); iCategoryIdsBeingOpened.Reset(); - // all category, lets delete our copy and start using new one, this gives the full ownership to client + for ( TInt i = 0; i < albumCount; i++ ) + { + // Create modify event for albums. + // This will cause client to make a new OpenL() call. + // Also this causes collection framework to purge its possibly outdated + // (KVcxMessageMyVideosItemsAppended events don't update collection frameworks cache) cache. + MPX_DEBUG3("CVcxMyVideosOpenHandler:: adding modify event for album %d, extra info = %d", + iAlbumIdsBeingOpened[i], EVcxMyVideosVideoListOrderChanged ); + iCollection.iMessageList->AddEventL( + TMPXItemId( iAlbumIdsBeingOpened[i], KVcxMvcMediaTypeAlbum ), + EMPXItemModified, EVcxMyVideosVideoListOrderChanged ); + // We dont send here, the send is at the end of this function. + delete iAlbumVideoListsBeingOpened[i]; // we can delete our copy, client has its own copy + iAlbumVideoListsBeingOpened[i] = NULL; + } + iAlbumVideoListsBeingOpened.Reset(); + iAlbumIdsBeingOpened.Reset(); + + // All category, lets delete our copy and start using new one, this gives the full + // ownership of the list to client. Video objects will continue to point to the same shared data. iCache.ReCreateVideoListL(); iCollection.CategoriesL().UpdateCategoriesNewVideoNamesL(); + iCollection.AlbumsL().CalculateAttributesL(); + iCollection.iMessageList->AddEventL( KVcxMessageMyVideosListComplete ); } iCollection.iMessageList->SendL(); } +// ---------------------------------------------------------------------------- +// CVcxMyVideosOpenHandler::HandleAlbumOpenL +// Album list has been fetched already. +// ---------------------------------------------------------------------------- +// +void CVcxMyVideosOpenHandler::HandleAlbumOpenL() + { + MPX_DEBUG1("CVcxMyVideosOpenHandler::HandleAlbumOpenL() start"); + + CVcxMyVideosAlbum* album = iCollection.AlbumsL().Album( iPendingAlbumOpenId ); + if ( album ) + { + if ( iCollection.iCache->IsComplete() ) + { + //videolist complete + CMPXMedia* videoList = album->CreateVideoListL(); + CleanupStack::PushL( videoList ); // 1-> + videoList->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath ); + videoList->SetTObjectValueL( KVcxMediaMyVideosInt32Value, + EVcxMyVideosVideoListComplete ); + iCollection.iObs->HandleOpen( videoList, KErrNone ); + CleanupStack::PopAndDestroy( videoList ); // <-1 + iCollection.iMessageList->AddEventL( KVcxMessageMyVideosListComplete ); + iCollection.iMessageList->SendL(); + } + else + { + if ( iCollection.iCache->iIsFetchingVideoList ) + { + MPX_DEBUG1("CVcxMyVideosOpenHandler:: videolist fetching already in progress -> use that to populate album"); + + // videolist incomplete and fetching already going on + TInt pos = iAlbumIdsBeingOpened.Find( iPendingAlbumOpenId ); + if ( pos == KErrNotFound ) + { + //store video list for append events + CMPXMedia* videoList = album->CreateVideoListL(); + CleanupStack::PushL( videoList ); + iAlbumVideoListsBeingOpened.AppendL( videoList ); + CleanupStack::Pop( videoList ); + iAlbumIdsBeingOpened.AppendL( iPendingAlbumOpenId ); + videoList->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath ); + iCollection.iObs->HandleOpen( videoList, KErrNone ); + } + else + { + //video list already stored + iAlbumVideoListsBeingOpened[pos]->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath ); + iCollection.iObs->HandleOpen( iAlbumVideoListsBeingOpened[pos], + KErrNone ); + } + } + else + { + MPX_DEBUG1("CVcxMyVideosOpenHandler:: videolist partial and no fetching going on -> fetch the album videos separately"); + + delete iAlbumVideoList; + iAlbumVideoList = NULL; + iAlbumVideoList = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL(); + iCollection.iMyVideosMdsDb->iAlbums->GetAlbumContentVideosL( iPendingAlbumOpenId, + *iAlbumVideoList, *this ); + return; + } + } + } + else + { + MPX_DEBUG2("CVcxMyVideosOpenHandler:: album ID not valid (%d) -> calling HandleOpen with KErrNotFound", + iPendingAlbumOpenId); + iCollection.iObs->HandleOpen( static_cast(NULL), KErrNotFound ); + } + iPendingAlbumOpenId = 0; + + MPX_DEBUG1("CVcxMyVideosOpenHandler::HandleAlbumOpenL() exit"); + } + +// ---------------------------------------------------------------------------- +// CVcxMyVideosOpenHandler::HandleGetAlbumContentVideosResp +// ---------------------------------------------------------------------------- +// +void CVcxMyVideosOpenHandler::HandleGetAlbumContentVideosResp( + TUint32 aAlbumId, CMPXMedia& aVideoList, TInt aError, + TInt aFirstNewItemIndex, TInt aNewItemCount, TBool aComplete ) + { + TRAPD( err, HandleGetAlbumContentVideosRespL( aAlbumId, aVideoList, aError, + aFirstNewItemIndex, aNewItemCount, aComplete )); + if ( err != KErrNone ) + { + MPX_DEBUG2("CVcxMyVideosOpenHandler:: HandleGetAlbumContentVideosRespL leaved: %d", err); + } + } + +// ---------------------------------------------------------------------------- +// CVcxMyVideosOpenHandler::HandleGetAlbumContentVideosRespL +// ---------------------------------------------------------------------------- +// +void CVcxMyVideosOpenHandler::HandleGetAlbumContentVideosRespL( + TUint32 aAlbumId, CMPXMedia& /*aVideoList*/, TInt aError, + TInt /*aFirstNewItemIndex*/, TInt /*aNewItemCount*/, TBool aComplete ) + { + MPX_DEBUG1("CVcxMyVideosOpenHandler::HandleGetAlbumContentVideosRespL() start"); + + if ( aError != KErrNone ) + { + MPX_DEBUG2("CVcxMyVideosOpenHandler:: error %d occured when fetching album videos", aError ); + } + + MPX_DEBUG3("CVcxMyVideosOpenHandler:: iPendingAlbumOpenId = %d, aAlbumId = %d", iPendingAlbumOpenId, aAlbumId ); + + if ( iPendingAlbumOpenId == aAlbumId ) + { + MPX_DEBUG2("CVcxMyVideosOpenHandler:: First videos for album %d arrived, calling HandleOpen()", aAlbumId); + + iAlbumVideoList->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath ); + if ( aComplete ) + { + iAlbumVideoList->SetTObjectValueL( KVcxMediaMyVideosInt32Value, + EVcxMyVideosVideoListComplete ); + } + iCollection.iObs->HandleOpen( iAlbumVideoList, aError ); + iPendingAlbumOpenId = 0; + } + + if ( !aComplete ) + { + iCollection.iMessageList->AddEventL( KVcxMessageMyVideosItemsAppended ); + + MPX_DEBUG3("CVcxMyVideosOpenHandler:: adding modify event for album %d, extra info = %d", + aAlbumId, EVcxMyVideosVideoListOrderChanged ); + iCollection.iMessageList->AddEventL( TMPXItemId( aAlbumId, 2 ), EMPXItemModified, + EVcxMyVideosVideoListOrderChanged ); + } + else + { + //TODO: should add album id + iCollection.AlbumsL().CalculateAttributesL(); + + iCollection.iMessageList->AddEventL( KVcxMessageMyVideosListComplete ); + + + delete iAlbumVideoList; + iAlbumVideoList = NULL; + } + + iCollection.iMessageList->SendL(); + + MPX_DEBUG1("CVcxMyVideosOpenHandler::HandleGetAlbumContentVideosRespL() exit"); + } + // END OF FILE