videocollection/mpxmyvideoscollection/src/vcxmyvideosopenhandler.cpp
changeset 0 96612d01cf9f
child 10 ce5ada96ab30
child 15 cf5481c2bc0b
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Handles collection Open operation related functionality.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <e32base.h>
       
    21 #include <mpxlog.h>
       
    22 #include <mpxcollectionplugin.h>
       
    23 #include <mpxcollectionpluginobserver.h>
       
    24 #include <mpxmediacontainerdefs.h>
       
    25 #include <mpxmediageneraldefs.h>
       
    26 
       
    27 #include "vcxmyvideoscollectionplugin.h"
       
    28 #include "vcxmyvideosopenhandler.h"
       
    29 #include "vcxmyvideosvideocache.h"
       
    30 #include "vcxmyvideosmdsdb.h"
       
    31 #include "vcxmyvideoscategories.h"
       
    32 #include "vcxmyvideosmessagelist.h"
       
    33 #include "vcxmyvideoscollectionutil.h"
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS =============================
       
    36 
       
    37 // ---------------------------------------------------------------------------
       
    38 // Constructor
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 CVcxMyVideosOpenHandler::CVcxMyVideosOpenHandler( CVcxMyVideosCollectionPlugin& aCollection,
       
    42         CVcxMyVideosVideoCache& aCache,
       
    43         CVcxMyVideosMdsDb& aMds )
       
    44 : iCollection( aCollection ), iCache( aCache ), iMds( aMds )
       
    45     {
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // 2nd-phase constructor
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 void CVcxMyVideosOpenHandler::ConstructL()
       
    53     {
       
    54     iCategoryIdsBeingOpened.Reset();
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // Two-Phase Constructor
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CVcxMyVideosOpenHandler* CVcxMyVideosOpenHandler::NewL( CVcxMyVideosCollectionPlugin& aCollection,
       
    62         CVcxMyVideosVideoCache& aCache,
       
    63         CVcxMyVideosMdsDb& aMds )
       
    64     {
       
    65     CVcxMyVideosOpenHandler* self = new(ELeave) CVcxMyVideosOpenHandler( aCollection,
       
    66             aCache, aMds );
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70     return self;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // Destructor
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CVcxMyVideosOpenHandler::~CVcxMyVideosOpenHandler()
       
    78     {
       
    79     iCategoryIdsBeingOpened.Close();
       
    80     
       
    81     TInt count = iVideoListsBeingOpened.Count();
       
    82     for ( TInt i = 0; i < count; i++ )
       
    83         {
       
    84         delete iVideoListsBeingOpened[i];
       
    85         iVideoListsBeingOpened[i] = NULL; 
       
    86         }
       
    87     iVideoListsBeingOpened.Close();
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CVcxMyVideosOpenHandler::OpenL
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 void CVcxMyVideosOpenHandler::OpenL(
       
    95     const CMPXCollectionPath& aPath )
       
    96     {
       
    97     MPX_FUNC("CVcxMyVideosOpenHandler::OpenL");
       
    98 
       
    99     MPX_DEBUG1("CVcxMyVideosOpenHandler:: path before open:");
       
   100     MPX_DEBUG_PATH( aPath );
       
   101 
       
   102     switch ( aPath.Levels() )
       
   103         {
       
   104         case 1:
       
   105             {
       
   106             //we are at root level, return main level items (categories)
       
   107             
       
   108             // this is needed to update category counters
       
   109             TRAPD( err, iCache.CreateVideoListL() );
       
   110             
       
   111             if ( err != KErrNone )
       
   112                 {
       
   113                 MPX_DEBUG2("iCache->CreateVideoListL() left: %d. Returning categories anyway.", err);
       
   114                 }
       
   115             iCollection.iObs->HandleOpen( iCollection.CategoriesL().iList, KErrNone );
       
   116             }
       
   117             break;
       
   118 
       
   119         case 2:
       
   120             {
       
   121             //we are at second level, return video list from some category
       
   122 
       
   123             TInt categoryId = aPath.Id();
       
   124 
       
   125             MPX_DEBUG2("CVcxMyVideosOpenHandler:: opening category %d", categoryId);
       
   126             
       
   127             if ( categoryId != KVcxMvcCategoryIdAll &&
       
   128                  categoryId != KVcxMvcCategoryIdDownloads &&
       
   129                  categoryId != KVcxMvcCategoryIdTvRecordings &&
       
   130                  categoryId != KVcxMvcCategoryIdCaptured &&
       
   131                  categoryId != KVcxMvcCategoryIdOther )
       
   132                 {
       
   133                 MPX_DEBUG2("CVcxMyVideosOpenHandler:: category ID not valid (%d) -> calling HandleOpen with KErrNotFound", categoryId);
       
   134                 iCollection.iObs->HandleOpen( static_cast<CMPXMedia*>(NULL), KErrNotFound );
       
   135                 return;
       
   136                 }
       
   137 
       
   138             TUint8 origin = static_cast<TUint8>( TVcxMyVideosCollectionUtil::Origin( categoryId ) );
       
   139 
       
   140             iCache.CreateVideoListL(); // Causes async call to MDS, callbacks to DoHandleCreateVideoListRespL will happen.
       
   141                                        // If iCache.iVideoList is complete and can be used (correct sorting order),
       
   142                                        // then nothing is done.
       
   143 
       
   144             if ( !iCache.iVideoListIsPartial )
       
   145                 {
       
   146                 MPX_DEBUG1("CVcxMyVideosOpenHandler:: videolist complete");
       
   147 
       
   148                 // iCache.iVideoList is complete
       
   149                 if ( categoryId == KVcxMvcCategoryIdAll )
       
   150                     {
       
   151                     MPX_DEBUG1("CVcxMyVideosOpenHandler:: KVcxMvcCategoryIdAll: calling HandleOpen(iCache.iVideoList)");
       
   152                     iCollection.iObs->HandleOpen( iCache.iVideoList, KErrNone );                    
       
   153                     }
       
   154                 else
       
   155                     {
       
   156                     MPX_DEBUG1("CVcxMyVideosOpenHandler:: other than KVcxMvcCategoryIdAll: creating new category video list");
       
   157                     CMPXMedia* videoList = iCache.CreateVideoListByOriginL( origin );
       
   158                     MPX_DEBUG1("CVcxMyVideosOpenHandler:: calling HandleOpen(new list)");
       
   159                     iCollection.iObs->HandleOpen( videoList, KErrNone );
       
   160                     delete videoList;
       
   161                     }
       
   162                 iCollection.iMessageList->AddEventL( KVcxMessageMyVideosListComplete );
       
   163                 iCollection.iMessageList->SendL();
       
   164 
       
   165                 // No append events will arrive anymore -> we create our own version of the
       
   166                 // video list.
       
   167                 iCache.ReCreateVideoListL();
       
   168                 }
       
   169             else
       
   170                 {
       
   171                 MPX_DEBUG1("CVcxMyVideosOpenHandler:: video list incomplete");
       
   172                 // iCache.iVideoList is incomplete                
       
   173 
       
   174                 if ( categoryId == KVcxMvcCategoryIdAll )
       
   175                     {
       
   176                     MPX_DEBUG1("CVcxMyVideosOpenHandler:: KVcxMvcCategoryIdAll, calling HandleOpen");
       
   177                     iCollection.iObs->HandleOpen( iCache.iVideoList, KErrNone  );
       
   178                     }
       
   179                 else
       
   180                     {   
       
   181                     MPX_DEBUG1("CVcxMyVideosOpenHandler:: other than KVcxMvcCategoryIdAll");
       
   182 
       
   183                     TInt pos = iCategoryIdsBeingOpened.Find( categoryId );
       
   184                     if ( pos == KErrNotFound )
       
   185                         {
       
   186                         MPX_DEBUG1("CVcxMyVideosOpenHandler:: category was not opened yet, creating list for it");
       
   187                         iCategoryIdsBeingOpened.AppendL( categoryId ); 
       
   188                         CMPXMedia* videoList = iCache.CreateVideoListByOriginL( origin );
       
   189                         iVideoListsBeingOpened.AppendL( videoList );
       
   190                         MPX_DEBUG1("CVcxMyVideosOpenHandler:: calling HandleOpen");
       
   191                         iCollection.iObs->HandleOpen( iCache.iVideoList, KErrNone  );
       
   192                         }
       
   193                     else
       
   194                         {
       
   195                         MPX_DEBUG1("CVcxMyVideosOpenHandler:: category was already being opened, calling HandleOpen with that");                        
       
   196                         iCollection.iObs->HandleOpen( iVideoListsBeingOpened[pos], KErrNone  );
       
   197                         }
       
   198                     }
       
   199                 }
       
   200 
       
   201             }
       
   202             break;
       
   203 
       
   204         case 3:
       
   205 			{
       
   206 			iCollection.iObs->HandleOpen(const_cast<CMPXCollectionPath*> (&aPath), KErrNone);
       
   207 			}
       
   208 			break;
       
   209 
       
   210         default:
       
   211             break;
       
   212 
       
   213         } //switch
       
   214     }
       
   215 
       
   216 // ----------------------------------------------------------------------------
       
   217 // CVcxMyVideosOpenHandler::DoHandleCreateVideoListRespL
       
   218 // New items fetched from MDS. iCache.iVideoList = aVideoList.
       
   219 // ----------------------------------------------------------------------------
       
   220 //
       
   221 void CVcxMyVideosOpenHandler::DoHandleCreateVideoListRespL(
       
   222         CMPXMedia* aVideoList, TInt aNewItemsStartIndex, TBool aComplete )
       
   223     {
       
   224     MPX_FUNC("CVcxMyVideosOpenHandler::DoHandleCreateVideoListRespL()");
       
   225 
       
   226     MPX_DEBUG2("CVcxMyVideosOpenHandler:: aComplete = %d", aComplete);
       
   227     
       
   228     if ( aNewItemsStartIndex != KErrNotFound )
       
   229         {
       
   230         //iCache.iVideoList now contains new items, tell iCache to check if partial list contains the new items
       
   231         iCache.CheckForPartialVideoListItemsL( aNewItemsStartIndex );
       
   232         }
       
   233 
       
   234     // Append new items to category video lists. All category is using iCache.iVideoList, thus no need to append to it.
       
   235     TInt count = iCategoryIdsBeingOpened.Count();
       
   236     for ( TInt i = 0; i < count; i++ )
       
   237         {
       
   238         iCache.AppendToListL( *iVideoListsBeingOpened[i], *aVideoList,
       
   239                 TVcxMyVideosCollectionUtil::Origin( iCategoryIdsBeingOpened[i] ),
       
   240                 aNewItemsStartIndex );
       
   241         }
       
   242             
       
   243     if ( aComplete == 0 )
       
   244         {
       
   245         iCollection.iMessageList->AddEventL( KVcxMessageMyVideosItemsAppended );
       
   246 
       
   247         // Still fetching items
       
   248         // Missing download fields filled from download manager
       
   249         TRAP_IGNORE( iCollection.SyncVideoListWithDownloadsL( *(iCache.iVideoList),
       
   250                 EFalse /* dont send events */, aNewItemsStartIndex ); ); 
       
   251         iCollection.CategoriesL().UpdateCategoriesL( *aVideoList, aNewItemsStartIndex );
       
   252         }                           
       
   253     else
       
   254         {
       
   255         // End event arrived
       
   256         
       
   257         iCache.iVideoListIsPartial = EFalse;
       
   258 
       
   259         // Create modify event for All category.
       
   260         // This will cause client to make a new OpenL() call.
       
   261         // Also this causes collection framework to purge its possibly outdated
       
   262         // (KVcxMessageMyVideosItemsAppended events don't update collection framework cache) cache.
       
   263         MPX_DEBUG3("CVcxMyVideosOpenHandler:: adding modify event for category[%d], extra info = %d",
       
   264                 KVcxMvcCategoryIdAll, EVcxMyVideosVideoListOrderChanged );
       
   265         iCollection.iMessageList->AddEventL( TMPXItemId( KVcxMvcCategoryIdAll, 1 ), EMPXItemModified,
       
   266                 EVcxMyVideosVideoListOrderChanged );
       
   267         // We dont send here, the send is at the end of this function.
       
   268 
       
   269         for ( TInt i = 0; i < count; i++ )
       
   270             {
       
   271             // Create modify event for other than All categories.
       
   272             // This will cause client to make a new OpenL() call.
       
   273             // Also this causes collection framework to purge its possibly outdated
       
   274             // (KVcxMessageMyVideosItemsAppended events don't update collection frameworks cache) cache.
       
   275             MPX_DEBUG3("CVcxMyVideosOpenHandler:: adding modify event for category[%d], extra info = %d",
       
   276                     iCategoryIdsBeingOpened[i], EVcxMyVideosVideoListOrderChanged );
       
   277             iCollection.iMessageList->AddEventL( TMPXItemId( iCategoryIdsBeingOpened[i], 1 ), EMPXItemModified,
       
   278                     EVcxMyVideosVideoListOrderChanged );
       
   279             // We dont send here, the send is at the end of this function.
       
   280             delete iVideoListsBeingOpened[i]; // we can delete our copy, client has its own copy
       
   281             iVideoListsBeingOpened[i] = NULL;
       
   282             }
       
   283         iVideoListsBeingOpened.Reset();
       
   284         iCategoryIdsBeingOpened.Reset();
       
   285 
       
   286         // all category, lets delete our copy and start using new one, this gives the full ownership to client
       
   287         iCache.ReCreateVideoListL();
       
   288 
       
   289         iCollection.CategoriesL().UpdateCategoriesNewVideoNamesL();
       
   290 
       
   291         iCollection.iMessageList->AddEventL( KVcxMessageMyVideosListComplete );
       
   292         }
       
   293     iCollection.iMessageList->SendL();
       
   294     }
       
   295 
       
   296 // END OF FILE