--- a/videocollection/mpxmyvideoscollection/src/vcxmyvideosopenhandler.cpp Tue Feb 02 00:12:10 2010 +0200
+++ b/videocollection/mpxmyvideoscollection/src/vcxmyvideosopenhandler.cpp Fri Apr 16 14:59:52 2010 +0300
@@ -11,11 +11,11 @@
*
* Contributors:
*
-* Description: Handles collection Open operation related functionality.*
+* Description: Handles collection Open operation related functionality.
+*
*/
-
// INCLUDE FILES
#include <e32base.h>
#include <mpxlog.h>
@@ -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,109 +114,78 @@
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)
+ //we are at root level, return main level items (categories + albums)
- // this is needed to update category counters
+ iCollection.AlbumsL().CreateAlbumListL(); //async
+
+ // 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.iObs->HandleOpen( iCollection.CategoriesL().iList, KErrNone );
+
+ CMPXMedia* itemList = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL();
+ CleanupStack::PushL( itemList );
+ TVcxMyVideosCollectionUtil::AppendToListL( *itemList, *iCollection.CategoriesL().iList );
+ TVcxMyVideosCollectionUtil::AppendToListL( *itemList, *iCollection.AlbumsL().iAlbumList );
+ 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();
-
- 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<CMPXMedia*>(NULL), KErrNotFound );
+ MPX_DEBUG2("CVcxMyVideosOpenHandler:: opening category %d", categoryId.iId1 );
+ OpenCategoryL( categoryId.iId1 );
return;
}
-
- TUint8 origin = static_cast<TUint8>( 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 );
+
+ iCollection.AlbumsL().CreateAlbumListL(); //async
+ 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<CMPXCollectionPath*> (&aPath), KErrNone);
}
@@ -213,14 +197,91 @@
} //switch
}
+// ---------------------------------------------------------------------------
+// CVcxMyVideosOpenHandler::OpenCategoryL
+// ---------------------------------------------------------------------------
+//
+void CVcxMyVideosOpenHandler::OpenCategoryL( TUint32 aCategoryId )
+ {
+ TUint8 origin = static_cast<TUint8>( 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.iVideoListIsPartial )
+ {
+ 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 );
+ 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 );
+ 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");
+ iCache.iVideoList->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath );
+ iCollection.iObs->HandleOpen( iCache.iVideoList, 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);
@@ -232,22 +293,27 @@
}
// 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
@@ -255,6 +321,8 @@
// End event arrived
iCache.iVideoListIsPartial = EFalse;
+ iCache.IsFetchingVideoList = EFalse;
+
// Create modify event for All category.
// This will cause client to make a new OpenL() call.
@@ -266,7 +334,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.
@@ -283,7 +351,25 @@
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], 2 ), 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();
@@ -293,4 +379,148 @@
iCollection.iMessageList->SendL();
}
+// ----------------------------------------------------------------------------
+// CVcxMyVideosOpenHandler::HandleAlbumOpenL
+// Album list has been fetched already.
+// ----------------------------------------------------------------------------
+//
+void CVcxMyVideosOpenHandler::HandleAlbumOpenL()
+ {
+ //TODO: If iVideoList is partial and fetching is already going on -> use the implementation below.
+ // If iVideoList is partial but fetching is not going on -> fetch only album items to iCache.
+
+ MPX_DEBUG1("CVcxMyVideosOpenHandler::HandleAlbumOpenL() start");
+
+ CVcxMyVideosAlbum* album = iCollection.AlbumsL().Album( iPendingAlbumOpenId );
+ if ( album )
+ {
+ if ( !iCollection.iCache->iVideoListIsPartial )
+ {
+ //videolist complete
+ CMPXMedia* videoList = album->CreateVideoListL();
+ videoList->SetCObjectValueL( KMPXMediaGeneralContainerPath, iPath );
+ iCollection.iObs->HandleOpen( videoList, KErrNone );
+ delete videoList;
+ iCollection.iMessageList->AddEventL( KVcxMessageMyVideosListComplete );
+ iCollection.iMessageList->SendL();
+ }
+ else
+ {
+ if ( iCollection.iCache->IsFetchingVideoList )
+ {
+ 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
+ {
+ // videolist incomplete and fetching hasn't been started
+ // TODO: Test how fast this is. If slow, then ditch the separate album fetching.
+
+ 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<CMPXMedia*>(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 );
+ 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.iMessageList->AddEventL( KVcxMessageMyVideosListComplete );
+
+ delete iAlbumVideoList;
+ iAlbumVideoList = NULL;
+ }
+
+ iCollection.iMessageList->SendL();
+
+ MPX_DEBUG1("CVcxMyVideosOpenHandler::HandleGetAlbumContentVideosRespL() exit");
+ }
+
// END OF FILE