videocollection/mpxmyvideoscollection/src/vcxmyvideosvideocache.cpp
branchRCL_3
changeset 16 67eb01668b0e
parent 8 ce5ada96ab30
child 18 baf439b22ddd
equal deleted inserted replaced
15:8f0df5c82986 16:67eb01668b0e
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:    Video list cache. Contains cached data from MDS.*
    14 * Description:   Video list cache. Contains cached data from MDS.*
    15 */
    15 */
    16 
    16 
    17 
    17 
    18 
    18 
    19 
    19 
    28 #include <centralrepository.h>
    28 #include <centralrepository.h>
    29 #include <collate.h>
    29 #include <collate.h>
    30 #include <mpxmediavideodefs.h>
    30 #include <mpxmediavideodefs.h>
    31 #include "vcxmyvideosvideocache.h"
    31 #include "vcxmyvideosvideocache.h"
    32 #include "vcxmyvideoscollectionplugin.h"
    32 #include "vcxmyvideoscollectionplugin.h"
    33 #include "vcxmyvideosdownloadutil.h"
       
    34 #include "vcxmyvideoscollectionutil.h"
    33 #include "vcxmyvideoscollectionutil.h"
    35 #include "vcxmyvideoscategories.h"
    34 #include "vcxmyvideoscategories.h"
    36 #include "vcxmyvideosdownloadcache.h"
       
    37 #include "vcxmyvideosmessagelist.h"
    35 #include "vcxmyvideosmessagelist.h"
    38 #include "vcxmyvideosopenhandler.h"
    36 #include "vcxmyvideosopenhandler.h"
    39 
    37 #include "vcxmyvideosalbums.h"
    40 //       If video list fetching is going on and at the same time add/delete events
       
    41 //       arrive from mds, what to do?
       
    42 
    38 
    43 // ============================ MEMBER FUNCTIONS ==============================
    39 // ============================ MEMBER FUNCTIONS ==============================
       
    40 
       
    41 // ----------------------------------------------------------------------------
       
    42 // constructor.
       
    43 // ----------------------------------------------------------------------------
       
    44 //
       
    45 TVcxMyVideosVideo::TVcxMyVideosVideo()
       
    46 :iMdsId( 0 ), iVideo( NULL ), iPos( KErrNotFound )
       
    47     {
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // TVcxMyVideosVideo::operator=
       
    52 // ---------------------------------------------------------------------------
       
    53 //                
       
    54 TVcxMyVideosVideo& TVcxMyVideosVideo::operator=( const TVcxMyVideosVideo& aVideo )
       
    55     {
       
    56     Set( aVideo.iMdsId, aVideo.iPos, aVideo.iVideo );
       
    57     return *this;
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // TVcxMyVideosVideo::Set
       
    62 // ----------------------------------------------------------------------------
       
    63 //
       
    64 void TVcxMyVideosVideo::Set( TUint32 aMdsId, TInt aPos, CMPXMedia* aVideo )
       
    65     {
       
    66     iMdsId = aMdsId;
       
    67     iPos   = aPos;
       
    68     iVideo = aVideo;
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // CVcxMyVideosVideoListIndex::NewL
       
    73 // ----------------------------------------------------------------------------
       
    74 //
       
    75 CVcxMyVideosVideoListIndex* CVcxMyVideosVideoListIndex::NewL()
       
    76     {
       
    77     CVcxMyVideosVideoListIndex* self = new (ELeave) CVcxMyVideosVideoListIndex();
       
    78     CleanupStack::PushL(self);
       
    79     self->ConstructL();
       
    80     CleanupStack::Pop(self);
       
    81     return self;    
       
    82     }
       
    83 
       
    84 // ----------------------------------------------------------------------------
       
    85 // CVcxMyVideosVideoListIndex::CVcxMyVideosVideoListIndex
       
    86 // ----------------------------------------------------------------------------
       
    87 //
       
    88 CVcxMyVideosVideoListIndex::CVcxMyVideosVideoListIndex()
       
    89     {
       
    90     
       
    91     }
       
    92 
       
    93 // ----------------------------------------------------------------------------
       
    94 // CVcxMyVideosVideoListIndex::ConstructL
       
    95 // ----------------------------------------------------------------------------
       
    96 //
       
    97 void CVcxMyVideosVideoListIndex::ConstructL ()
       
    98     {
       
    99     iVideoArray.Reset();
       
   100     }
       
   101 
       
   102 // ----------------------------------------------------------------------------
       
   103 // CVcxMyVideosVideoListIndex::~CVcxMyVideosVideoListIndex
       
   104 // ----------------------------------------------------------------------------
       
   105 //
       
   106 CVcxMyVideosVideoListIndex::~CVcxMyVideosVideoListIndex()
       
   107     {
       
   108     iVideoArray.Close();
       
   109     }
       
   110 
       
   111 // ----------------------------------------------------------------------------
       
   112 // CVcxMyVideosVideoListIndex::~CVcxMyVideosVideoListIndex
       
   113 // ----------------------------------------------------------------------------
       
   114 //
       
   115 void CVcxMyVideosVideoListIndex::SetL( const CMPXMedia& aVideoList )
       
   116     {
       
   117     CMPXMediaArray* mediaArray = TVcxMyVideosCollectionUtil::MediaArrayL( aVideoList );
       
   118     TInt count = mediaArray->Count();
       
   119     iVideoArray.Reset();
       
   120     iVideoArray.ReserveL( count );
       
   121     for ( TInt i = 0; i < count; i++ )
       
   122         {
       
   123         AddL( mediaArray->AtL( i ), i );
       
   124         }
       
   125     }
       
   126 
       
   127 // ----------------------------------------------------------------------------
       
   128 // CVcxMyVideosVideoListIndex::Find
       
   129 // ----------------------------------------------------------------------------
       
   130 //
       
   131 TInt CVcxMyVideosVideoListIndex::Find( TUint32 aMdsId, TVcxMyVideosVideo& aVideo )
       
   132     {
       
   133     const TLinearOrder<TVcxMyVideosVideo> KOrderByMdsId(
       
   134             CVcxMyVideosVideoListIndex::CompareVideosByMdsId );
       
   135     
       
   136     TInt index;
       
   137     TVcxMyVideosVideo video;
       
   138     video.iMdsId = aMdsId;
       
   139     TInt err = iVideoArray.FindInOrder( video, index, KOrderByMdsId );
       
   140     
       
   141     if ( err != KErrNone )
       
   142         {
       
   143         return KErrNotFound;
       
   144         }
       
   145     
       
   146     aVideo = iVideoArray[index];
       
   147     return KErrNone;
       
   148     }
       
   149 
       
   150 // ----------------------------------------------------------------------------
       
   151 // CVcxMyVideosVideoListIndex::Remove
       
   152 // ----------------------------------------------------------------------------
       
   153 //
       
   154 TInt CVcxMyVideosVideoListIndex::Remove( TUint32 aMdsId, TBool aCompress )
       
   155     {
       
   156     const TLinearOrder<TVcxMyVideosVideo> KOrderByMdsId(
       
   157             CVcxMyVideosVideoListIndex::CompareVideosByMdsId );
       
   158 
       
   159     TVcxMyVideosVideo video;
       
   160     video.iMdsId = aMdsId;
       
   161     TInt pos;
       
   162     TInt posInVideoList;
       
   163     TInt err = iVideoArray.FindInOrder( video, pos, KOrderByMdsId );
       
   164     if ( err == KErrNone )
       
   165         {
       
   166         posInVideoList = iVideoArray[pos].iPos;
       
   167         iVideoArray.Remove( pos );
       
   168 
       
   169         // update all indexes which are bigger than posInVideoList
       
   170         TInt count = iVideoArray.Count();
       
   171         for ( TInt i = 0; i < count; i++ )
       
   172             {
       
   173             if ( iVideoArray[i].iPos > posInVideoList )
       
   174                 {
       
   175                 iVideoArray[i].iPos--;
       
   176                 }
       
   177             }
       
   178         }
       
   179     
       
   180     if ( aCompress )
       
   181         {
       
   182         iVideoArray.Compress();
       
   183         }
       
   184     
       
   185     return err;
       
   186     }
       
   187     
       
   188 // ----------------------------------------------------------------------------
       
   189 // CVcxMyVideosVideoListIndex::AddL
       
   190 // ----------------------------------------------------------------------------
       
   191 //
       
   192 void CVcxMyVideosVideoListIndex::AddL( CMPXMedia* aVideo, TInt aPos )
       
   193     {
       
   194     TVcxMyVideosVideo video;
       
   195     video.Set( TVcxMyVideosCollectionUtil::IdL( *aVideo ).iId1, aPos, aVideo );
       
   196 
       
   197     const TLinearOrder<TVcxMyVideosVideo> KOrderByMdsId(
       
   198             CVcxMyVideosVideoListIndex::CompareVideosByMdsId );
       
   199 
       
   200     // update indexes
       
   201     TInt count = iVideoArray.Count();
       
   202     for ( TInt i = 0; i < count; i++ )
       
   203         {
       
   204         if ( iVideoArray[i].iPos >= aPos )
       
   205             {
       
   206             iVideoArray[i].iPos++;
       
   207             }
       
   208         }
       
   209 
       
   210     iVideoArray.InsertInOrderAllowRepeatsL( video, KOrderByMdsId );
       
   211 
       
   212     }
       
   213 
       
   214 #ifdef _DEBUG
       
   215 // ----------------------------------------------------------------------------
       
   216 // CVcxMyVideosVideoListIndex::VideoArray
       
   217 // ----------------------------------------------------------------------------
       
   218 //
       
   219 const RArray<TVcxMyVideosVideo>& CVcxMyVideosVideoListIndex::VideoArray()
       
   220     {
       
   221     return iVideoArray;
       
   222     }
       
   223 #endif
       
   224 
       
   225 // ----------------------------------------------------------------------------
       
   226 // CVcxMyVideosVideoListIndex::Sort
       
   227 // ----------------------------------------------------------------------------
       
   228 //
       
   229 void CVcxMyVideosVideoListIndex::Sort()
       
   230     {
       
   231     const TLinearOrder<TVcxMyVideosVideo> KOrderByMdsId(
       
   232             CVcxMyVideosVideoListIndex::CompareVideosByMdsId );
       
   233 
       
   234     iVideoArray.Sort( KOrderByMdsId );    
       
   235     }
       
   236 
       
   237 // ----------------------------------------------------------------------------
       
   238 // CVcxMyVideosVideoListIndex::CompareVideosByMdsId
       
   239 // ----------------------------------------------------------------------------
       
   240 //
       
   241 TInt CVcxMyVideosVideoListIndex::CompareVideosByMdsId( const TVcxMyVideosVideo& aVideo1,
       
   242             const TVcxMyVideosVideo& aVideo2 )
       
   243     {
       
   244     if ( aVideo1.iMdsId == aVideo2.iMdsId )
       
   245         {
       
   246         return 0;
       
   247         }
       
   248 
       
   249     if ( aVideo1.iMdsId < aVideo2.iMdsId )
       
   250         {
       
   251         return -1;
       
   252         }
       
   253     return 1;    
       
   254     }
    44 
   255 
    45 // ----------------------------------------------------------------------------
   256 // ----------------------------------------------------------------------------
    46 // Two-phased constructor.
   257 // Two-phased constructor.
    47 // ----------------------------------------------------------------------------
   258 // ----------------------------------------------------------------------------
    48 //
   259 //
    65 CVcxMyVideosVideoCache::~CVcxMyVideosVideoCache()
   276 CVcxMyVideosVideoCache::~CVcxMyVideosVideoCache()
    66     {
   277     {
    67     MPX_FUNC("CVcxMyVideosVideoCache::~CVcxMyVideosVideoCache");
   278     MPX_FUNC("CVcxMyVideosVideoCache::~CVcxMyVideosVideoCache");
    68     
   279     
    69     delete iVideoList;
   280     delete iVideoList;
    70     delete iDownloadCache;
       
    71     delete iCenRep;
       
    72     
       
    73     DeletePartialList();
   281     DeletePartialList();
       
   282     delete iVideoListIndex;
    74     }
   283     }
    75 
   284 
    76 // ----------------------------------------------------------------------------
   285 // ----------------------------------------------------------------------------
    77 // Constructor.
   286 // Constructor.
    78 // ----------------------------------------------------------------------------
   287 // ----------------------------------------------------------------------------
    91 void CVcxMyVideosVideoCache::ConstructL ()
   300 void CVcxMyVideosVideoCache::ConstructL ()
    92     {
   301     {
    93     MPX_FUNC("CVcxMyVideosVideoCache::ConstructL");
   302     MPX_FUNC("CVcxMyVideosVideoCache::ConstructL");
    94 
   303 
    95     iVideoList          = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL();
   304     iVideoList          = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL();
    96     iVideoListIsPartial = ETrue;
   305     SetComplete( EFalse );
    97 
   306     
    98     iDownloadCache = CVcxMyVideosDownloadCache::NewL();
       
    99     iPartialVideoList.Reset();
   307     iPartialVideoList.Reset();
       
   308     iVideoListIndex = CVcxMyVideosVideoListIndex::NewL();
   100     }
   309     }
   101 
   310 
   102 // ----------------------------------------------------------------------------------------------------------
   311 // ----------------------------------------------------------------------------------------------------------
   103 // CVcxMyVideosVideoCache::CreateVideoListByOriginL
   312 // CVcxMyVideosVideoCache::CreateVideoListByOriginL
   104 // ----------------------------------------------------------------------------------------------------------
   313 // ----------------------------------------------------------------------------------------------------------
   217     
   426     
   218     if ( !iVideoList )
   427     if ( !iVideoList )
   219         {
   428         {
   220         return NULL;
   429         return NULL;
   221         }
   430         }
   222         
   431     
       
   432     if ( IsComplete() )
       
   433         {
       
   434         TVcxMyVideosVideo video;
       
   435         TInt pos = iVideoListIndex->Find( aMdsId, video );
       
   436         if ( pos != KErrNotFound )
       
   437             {
       
   438             aPos = video.iPos;
       
   439             MPX_DEBUG2("CVcxMyVideosVideoCache::FindVideoByMdsIdL found %d from index", aMdsId );
       
   440             return video.iVideo;
       
   441             }
       
   442         }
       
   443     
   223     CMPXMediaArray* cachedVideoArray = iVideoList->Value<CMPXMediaArray>(
   444     CMPXMediaArray* cachedVideoArray = iVideoList->Value<CMPXMediaArray>(
   224                                 KMPXMediaArrayContents);
   445                                 KMPXMediaArrayContents);
   225    
   446    
   226     TMPXItemId mpxItemId;
   447     TMPXItemId mpxItemId;
   227     CMPXMedia* media;
   448     CMPXMedia* media;
   258     MPX_DEBUG2("CVcxMyVideosCollectionPlugin::FindVideoByMdsIdL() MDSID %d NOT FOUND", aMdsId);
   479     MPX_DEBUG2("CVcxMyVideosCollectionPlugin::FindVideoByMdsIdL() MDSID %d NOT FOUND", aMdsId);
   259     return NULL;
   480     return NULL;
   260     }
   481     }
   261 
   482 
   262 // ----------------------------------------------------------------------------
   483 // ----------------------------------------------------------------------------
   263 // CVcxMyVideosVideoCache::FindVideoByDownloadIdL
       
   264 // ----------------------------------------------------------------------------
       
   265 //
       
   266 CMPXMedia* CVcxMyVideosVideoCache::FindVideoByDownloadIdL( TUint aDownloadId )
       
   267     {
       
   268     MPX_FUNC("CVcxMyVideosVideoCache::FindVideoByDownloadIdL()");
       
   269     
       
   270     MPX_DEBUG2("CVcxMyVideosVideoCache:: looking for MPX item  with download ID %d from cache", aDownloadId);
       
   271         
       
   272     if ( aDownloadId == 0 )
       
   273         {
       
   274         MPX_DEBUG1("CVcxMyVideosVideoCache:: dl id == 0 -> NOT FOUND");
       
   275         return NULL;
       
   276         }
       
   277     
       
   278     if ( !iVideoList )
       
   279         {
       
   280         MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoList is NULL -> NOT FOUND");
       
   281         return NULL;
       
   282         }
       
   283 
       
   284     CMPXMedia* video = iDownloadCache->Get( aDownloadId );
       
   285     if ( video )
       
   286         {
       
   287         MPX_DEBUG1("CVcxMyVideosVideoCache:: found from Download Cache");
       
   288         return video;
       
   289         }
       
   290 
       
   291     MPX_DEBUG1("CVcxMyVideosVideoCache:: not found from Download Cache");
       
   292 
       
   293     CMPXMediaArray* cachedVideoArray = iVideoList->Value<CMPXMediaArray>(
       
   294                                 KMPXMediaArrayContents);
       
   295               
       
   296     TUint32 downloadId;
       
   297     TInt count = cachedVideoArray->Count();
       
   298     for ( TInt i = 0; i < count; i++ )
       
   299         {
       
   300         downloadId = TVcxMyVideosCollectionUtil::DownloadIdL( *cachedVideoArray->AtL( i ) );
       
   301         if ( downloadId == aDownloadId )
       
   302             {
       
   303             MPX_DEBUG1("CVcxMyVideosVideoCache:: found from iVideoList");
       
   304             MPX_DEBUG1("CVcxMyVideosVideoCache:: adding to iDownloadCache");
       
   305             iDownloadCache->Add( downloadId, (*cachedVideoArray)[i] );
       
   306             return (*cachedVideoArray)[i];
       
   307             }
       
   308         }
       
   309     
       
   310     count = iPartialVideoList.Count();  
       
   311     for ( TInt i = 0; i < count; i++ )
       
   312         {
       
   313         downloadId = TVcxMyVideosCollectionUtil::DownloadIdL( *(iPartialVideoList[i]) );
       
   314         if ( downloadId ==  aDownloadId )
       
   315             {
       
   316             MPX_DEBUG1("CVcxMyVideosVideoCache:: found from iPartialVideoList");
       
   317             MPX_DEBUG1("CVcxMyVideosVideoCache:: adding to iDownloadCache");
       
   318             iDownloadCache->Add( downloadId, iPartialVideoList[i] );
       
   319             return iPartialVideoList[i];
       
   320             }       
       
   321         }
       
   322         
       
   323     MPX_DEBUG1("CVcxMyVideosVideoCache:: NOT FOUND");
       
   324     return NULL;
       
   325     }
       
   326 
       
   327 
       
   328 // ----------------------------------------------------------------------------
       
   329 // CVcxMyVideosVideoCache::GetVideosL
   484 // CVcxMyVideosVideoCache::GetVideosL
   330 // ----------------------------------------------------------------------------
   485 // ----------------------------------------------------------------------------
   331 //
   486 //
   332 CMPXMedia* CVcxMyVideosVideoCache::GetVideosL( RArray<TUint32> aMdsIds )
   487 CMPXMedia* CVcxMyVideosVideoCache::GetVideosL( RArray<TUint32>& aMdsIds )
   333     {
   488     {
   334     CMPXMessage* videoList = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL();
   489     CMPXMessage* videoList = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL();
   335     CleanupStack::PushL( videoList ); // 1->
   490     CleanupStack::PushL( videoList ); // 1->
   336 
   491 
   337     // copy from iVideoList
   492     // copy from iVideoList
   348     
   503     
   349 // ----------------------------------------------------------------------------
   504 // ----------------------------------------------------------------------------
   350 // CVcxMyVideosVideoCache::AddVideosFromMdsL
   505 // CVcxMyVideosVideoCache::AddVideosFromMdsL
   351 // Called when item inserted events arrive from mds or from
   506 // Called when item inserted events arrive from mds or from
   352 // KVcxCommandMyVideosGetMediasByMpxId cmd handler.
   507 // KVcxCommandMyVideosGetMediasByMpxId cmd handler.
   353 // Synchronizing with downloads is not done here, caller must take care of it.
       
   354 // If mpx item is already in cache, or MDS does not contain the item (or was not video item),
   508 // If mpx item is already in cache, or MDS does not contain the item (or was not video item),
   355 // then it is removed from aMdsIds. Ie after this function call aMdsIds contains
   509 // then it is removed from aMdsIds. Ie after this function call aMdsIds contains
   356 // only IDs which are actually added to cache.
   510 // only IDs which are actually added to cache. aNonVideoIds will contain IDs
       
   511 // which were not video objects.
   357 // ----------------------------------------------------------------------------
   512 // ----------------------------------------------------------------------------
   358 //    
   513 //    
   359 void CVcxMyVideosVideoCache::AddVideosFromMdsL( RArray<TUint32>& aMdsIds,
   514 void CVcxMyVideosVideoCache::AddVideosFromMdsL( RArray<TUint32>& aMdsIds,
   360         TBool& aListFetchingWasCanceled )
   515         TBool& aListFetchingWasCanceled, RArray<TUint32>* aNonVideoIds  )
   361     {
   516     {
   362     MPX_FUNC("CVcxMyVideosVideoCache::AddVideosFromMdsL");
   517     MPX_FUNC("CVcxMyVideosVideoCache::AddVideosFromMdsL");
   363 
   518 
   364     TVcxMyVideosSortingOrder sortingOrder = SortingOrderL();
   519     TVcxMyVideosSortingOrder sortingOrder = SortingOrderL();
   365   
   520   
   373         TInt pos;
   528         TInt pos;
   374         if ( !FindVideoByMdsIdL( aMdsIds[j], pos ) )
   529         if ( !FindVideoByMdsIdL( aMdsIds[j], pos ) )
   375             {
   530             {
   376             MPX_DEBUG2("CVcxMyVideosVideoCache:: MDSID(%d) not found from cache, ok", aMdsIds[j]);
   531             MPX_DEBUG2("CVcxMyVideosVideoCache:: MDSID(%d) not found from cache, ok", aMdsIds[j]);
   377             
   532             
       
   533             //TODO: This doesnt work with new mds cmd queue. Cancel must be done if there is _any_ async req going on.
       
   534             //      Maybe the fetching could be changed to asynchronous...
   378             if ( iCollection.iMyVideosMdsDb->iVideoListFetchingIsOngoing )
   535             if ( iCollection.iMyVideosMdsDb->iVideoListFetchingIsOngoing )
   379                 {
   536                 {
   380                 // If list fetching is not canceled, CreateVideoObjectL will leave with KErrNotReady.
   537                 // If list fetching is not canceled, CreateVideoObjectL will leave with KErrNotReady.
   381                 MPX_DEBUG1("CVcxMyVideosVideoCache:: video list fetching is ongoing, canceling it to be able to fetch single items!");
   538                 MPX_DEBUG1("CVcxMyVideosVideoCache:: video list fetching is ongoing, canceling it to be able to fetch single items!");
   382                 iCollection.iMyVideosMdsDb->Cancel();
   539                 iCollection.iMyVideosMdsDb->Cancel();
   403                     
   560                     
   404                 MPX_DEBUG3("CVcxMyVideosVideoCache:: %d (pointer = %x) added to cache", aMdsIds[j], videoToCache);
   561                 MPX_DEBUG3("CVcxMyVideosVideoCache:: %d (pointer = %x) added to cache", aMdsIds[j], videoToCache);
   405                 }
   562                 }
   406             else
   563             else
   407                 {
   564                 {
   408                 MPX_DEBUG2("CVcxMyVideosVideoCache:: video with %d ID not found from MDS -> skipping add to cache and deleting from id array", aMdsIds[j] );
   565                 MPX_DEBUG2("CVcxMyVideosVideoCache:: video with %d ID not found from MDS -> prob non video object, skipping add to cache", aMdsIds[j] );
       
   566                 if ( aNonVideoIds )
       
   567                     {
       
   568                     aNonVideoIds->AppendL( aMdsIds[j] );
       
   569                     }
   409                 aMdsIds.Remove( j );
   570                 aMdsIds.Remove( j );
   410                 }
   571                 }
   411             }
   572             }
   412         else
   573         else
   413             {
   574             {
   414             MPX_DEBUG2("CVcxMyVideosVideoCache:: %d was already in cache -> skipping add, and deleting from id array", aMdsIds[j]);
   575             MPX_DEBUG2("CVcxMyVideosVideoCache:: %d was already in cache -> skipping add", aMdsIds[j]);
   415             aMdsIds.Remove( j );
   576             aMdsIds.Remove( j );
   416             }
   577             }
   417         }
   578         }
   418 
   579 
   419     }
   580     }
   425 //
   586 //
   426 TInt CVcxMyVideosVideoCache::AddL( CMPXMedia* aVideo, TVcxMyVideosSortingOrder aSortingOrder )
   587 TInt CVcxMyVideosVideoCache::AddL( CMPXMedia* aVideo, TVcxMyVideosSortingOrder aSortingOrder )
   427     {
   588     {
   428     MPX_FUNC("CVcxMyVideosVideoCache::AddL");
   589     MPX_FUNC("CVcxMyVideosVideoCache::AddL");
   429     
   590     
   430     if ( iVideoListIsPartial )
   591     if ( !IsComplete() )
   431         {
   592         {
   432         MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoList is partial, adding to iPartialVideoList");
   593         MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoList is partial, adding to iPartialVideoList");
   433         return AddToPartialListL( aVideo );
   594         return AddToPartialListL( aVideo );
   434         }
   595         }
   435     else
   596     else
   576 
   737 
   577     MPX_DEBUG2("CVcxMyVideosVideoCache:: aForce = %d", aForce );
   738     MPX_DEBUG2("CVcxMyVideosVideoCache:: aForce = %d", aForce );
   578     
   739     
   579     TVcxMyVideosSortingOrder sortingOrder = SortingOrderL();
   740     TVcxMyVideosSortingOrder sortingOrder = SortingOrderL();
   580         
   741         
   581     if ( iCollection.iMyVideosMdsDb->iVideoListFetchingIsOngoing
   742     if ( iIsFetchingVideoList
   582             && sortingOrder == iLastSortingOrder && !aForce )
   743             && sortingOrder == iLastSortingOrder && !aForce )
   583         {
   744         {
   584         MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoList creation is already ongoing, skipping");
   745         MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoList creation is already ongoing, skipping");
   585         return;
   746         return;
   586         }
   747         }
   587                    
   748                    
   588     if ( iVideoListIsPartial || (sortingOrder != iLastSortingOrder) || aForce )
   749     if ( !IsComplete() || (sortingOrder != iLastSortingOrder) || aForce )
   589         {
   750         {
   590         MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoList was partial or in wrong order or aForce was ETrue, recreating");
   751         MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoList was partial or in wrong order or aForce was ETrue, recreating");
   591 
   752 
   592         if ( iCollection.iMyVideosMdsDb->iVideoListFetchingIsOngoing )
   753         if ( iIsFetchingVideoList )
   593             {
   754             {
   594             MPX_DEBUG1("CVcxMyVideosVideoCache:: video list fetching is ongoing, canceling it");
   755             MPX_DEBUG1("CVcxMyVideosVideoCache:: video list fetching is ongoing, canceling it");
   595             iCollection.iMyVideosMdsDb->Cancel();
   756             iCollection.iMyVideosMdsDb->Cancel( CVcxMyVideosMdsDb::EGetVideoList );
       
   757             iIsFetchingVideoList = EFalse;
   596             }
   758             }
   597         
   759         
   598         ResetVideoListL();
   760         ResetVideoListL();
   599                         
   761                         
   600         TBool ascending = ETrue;
   762         TBool ascending = ETrue;
   616                 sortingOrder,
   778                 sortingOrder,
   617                 ascending,
   779                 ascending,
   618                 EFalse /* brief list */,
   780                 EFalse /* brief list */,
   619                 iVideoList /* use existing */ );
   781                 iVideoList /* use existing */ );
   620 
   782 
       
   783         iIsFetchingVideoList = ETrue;
   621         iLastSortingOrder   = sortingOrder;
   784         iLastSortingOrder   = sortingOrder;
   622         iVideoListIsPartial = ETrue;
   785         SetComplete( EFalse );
   623         }
   786         }
   624     else
   787     else
   625         {
   788         {
   626         MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoList is complete and in right sorting order, doing nothing");
   789         MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoList is complete and in right sorting order, doing nothing");
   627         }              
   790         }              
   646         }
   809         }
   647 
   810 
   648     TBool changed = EFalse;
   811     TBool changed = EFalse;
   649         
   812         
   650     // 1 MPX ID cant be changed
   813     // 1 MPX ID cant be changed
   651     // 2 
   814     // 2
   652     if ( aVideo.IsSupported( KMPXMediaGeneralTitle ) )
   815     if ( aVideo.IsSupported( KMPXMediaGeneralTitle ) )
   653         {
   816         {
   654         if ( videoInCache->ValueText( KMPXMediaGeneralTitle ) !=
   817         if ( videoInCache->ValueText( KMPXMediaGeneralTitle ) !=
   655                 aVideo.ValueText( KMPXMediaGeneralTitle ) )
   818                 aVideo.ValueText( KMPXMediaGeneralTitle ) )
   656             {
   819             {
   680         MPX_DEBUG2("CVcxMyVideosVideoCache:: old file path: %S", &videoInCache->ValueText( KMPXMediaGeneralUri ));
   843         MPX_DEBUG2("CVcxMyVideosVideoCache:: old file path: %S", &videoInCache->ValueText( KMPXMediaGeneralUri ));
   681         MPX_DEBUG2("CVcxMyVideosVideoCache:: new file path: %S", &aVideo.ValueText( KMPXMediaGeneralUri ));
   844         MPX_DEBUG2("CVcxMyVideosVideoCache:: new file path: %S", &aVideo.ValueText( KMPXMediaGeneralUri ));
   682 
   845 
   683         if ( videoInCache->ValueText( KMPXMediaGeneralUri ) !=
   846         if ( videoInCache->ValueText( KMPXMediaGeneralUri ) !=
   684                aVideo.ValueText( KMPXMediaGeneralUri ) ) 
   847                aVideo.ValueText( KMPXMediaGeneralUri ) ) 
   685             {
   848             {            
   686 #if 0 // this should be in mds, or mds should keep title empty if it is not set by client
       
   687             TParse parse;
       
   688             HBufC* oldTitle = HBufC::NewL( videoInCache->ValueText( KMPXMediaGeneralTitle ).Length() );
       
   689             CleanupStack::PushL( oldTitle ); // 1->
       
   690             oldTitle->Des() = videoInCache->ValueText( KMPXMediaGeneralTitle );
       
   691             oldTitle->Des().LowerCase();
       
   692             
       
   693             parse.Set( videoInCache->ValueText( KMPXMediaGeneralUri ), NULL, NULL );
       
   694             MPX_DEBUG2("CVcxMyVideosVideoCache:: title generated from old file name: %S", &parse.Name());
       
   695             MPX_DEBUG2("CVcxMyVideosVideoCache:: old title (lower cased): %S", oldTitle);
       
   696             if ( parse.Name() == *oldTitle )
       
   697                 {
       
   698                 // filename has been used as a title -> update title also to new filename
       
   699                 MPX_DEBUG1("CVcxMyVideosVideoCache:: filename has been used as a title -> changing title to new filename");
       
   700                 parse.Set( aVideo.ValueText( KMPXMediaGeneralUri ), NULL, NULL );
       
   701                 videoInCache->SetTextValueL( KMPXMediaGeneralTitle, parse.Name() );
       
   702                 
       
   703                 //updates sorting order and category attributes if necessarry
       
   704                 HandleVideoTitleModifiedL( videoInCache );
       
   705                 }
       
   706             CleanupStack::PopAndDestroy( oldTitle ); // <-1
       
   707 #endif
       
   708             
       
   709             videoInCache->SetTextValueL( KMPXMediaGeneralUri,
   849             videoInCache->SetTextValueL( KMPXMediaGeneralUri,
   710                     aVideo.ValueText( KMPXMediaGeneralUri ) );
   850                     aVideo.ValueText( KMPXMediaGeneralUri ) );
   711     
   851     
   712             changed = ETrue;
   852             changed = ETrue;
   713             }
   853             }
   761                 MoveToCorrectPlaceL( *videoInCache, sortingOrder );
   901                 MoveToCorrectPlaceL( *videoInCache, sortingOrder );
   762                 videoInCache = FindVideoByMdsIdL( aVideo.ValueTObjectL<TMPXItemId>(
   902                 videoInCache = FindVideoByMdsIdL( aVideo.ValueTObjectL<TMPXItemId>(
   763                         KMPXMediaGeneralId ).iId1, pos );
   903                         KMPXMediaGeneralId ).iId1, pos );
   764 
   904 
   765                 iCollection.CategoriesL().GenerateCategoryModifiedEventL(
   905                 iCollection.CategoriesL().GenerateCategoryModifiedEventL(
   766                         *videoInCache, ETrue /* flush */, EVcxMyVideosVideoListOrderChanged );
   906                         *videoInCache, EFalse /* dont flush */, EVcxMyVideosVideoListOrderChanged );
   767                 }
   907                 }
   768 
   908 
   769             changed = ETrue;
   909             changed = ETrue;
   770             }
   910             }
   771         }
   911         }
   781         // Play pos is written only after playback. Reset new video flag
   921         // Play pos is written only after playback. Reset new video flag
   782         // now, so there's no need for changing the flag explitically
   922         // now, so there's no need for changing the flag explitically
   783         if ( aVideo.IsSupported( KMPXMediaGeneralLastPlaybackPosition ) )
   923         if ( aVideo.IsSupported( KMPXMediaGeneralLastPlaybackPosition ) )
   784             {
   924             {
   785             newFlags &= ~EVcxMyVideosVideoNew;
   925             newFlags &= ~EVcxMyVideosVideoNew;
   786             MPX_DEBUG3("CVcxMyVideosVideoCache:: %x -> %x", oldFlags, newFlags);
   926             MPX_DEBUG3("CVcxMyVideosVideoCache:: flags: %x -> %x", oldFlags, newFlags);
   787             }
   927             }
   788 
   928 
   789         if ( oldFlags != newFlags )
   929         if ( oldFlags != newFlags )
   790             {        
   930             {        
   791             videoInCache->SetTObjectValueL<TUint32>( KMPXMediaGeneralFlags, newFlags );
   931             videoInCache->SetTObjectValueL<TUint32>( KMPXMediaGeneralFlags, newFlags );
   802                 
   942                 
   803                 iCollection.CategoriesL().NewVideoFlagChangedL(
   943                 iCollection.CategoriesL().NewVideoFlagChangedL(
   804                         oldFlags, newFlags,
   944                         oldFlags, newFlags,
   805                         origin,
   945                         origin,
   806                         modified );
   946                         modified );
   807                 
   947 
   808                 if ( !(newFlags & EVcxMyVideosVideoNew) && 
   948 #ifndef VIDEO_COLLECTION_PLUGIN_TB92
   809                         origin == EVcxMyVideosOriginDownloaded )
   949                 iCollection.AlbumsL().NewVideoFlagChangedL(
   810                     {
   950                         TVcxMyVideosCollectionUtil::IdL( *videoInCache ).iId1 );
   811                     MPX_DEBUG1("CVcxMyVideosVideoCache::UpdateVideoL - Count of new videos in Downloaded origin has decreased, sending mediator event to notification launcher");                   
   951 #endif
   812                     iCollection.NotifyNewVideosCountDecreasedL( *videoInCache );
       
   813                     }
       
   814                 }
   952                 }
   815             changed = ETrue;
   953             changed = ETrue;
   816             }
   954             }
   817         }
   955         }
   818     // 8
   956     // 8
   945             videoInCache->SetTObjectValueL<TInt>( KMPXMediaGeneralLastPlaybackPosition,
  1083             videoInCache->SetTObjectValueL<TInt>( KMPXMediaGeneralLastPlaybackPosition,
   946                     aVideo.ValueTObjectL<TInt>( KMPXMediaGeneralLastPlaybackPosition ) );
  1084                     aVideo.ValueTObjectL<TInt>( KMPXMediaGeneralLastPlaybackPosition ) );
   947             changed = ETrue;
  1085             changed = ETrue;
   948             }
  1086             }
   949         }
  1087         }
   950     // 18
  1088 
   951     if ( aVideo.IsSupported( KVcxMediaMyVideosDownloadId ) )
       
   952         {
       
   953         TUint32 downloadIdInCache( TVcxMyVideosCollectionUtil::DownloadIdL( *videoInCache ) );
       
   954         TUint32 downloadIdInNew( TVcxMyVideosCollectionUtil::DownloadIdL( aVideo ) );
       
   955         if (  downloadIdInNew != downloadIdInCache )
       
   956             {
       
   957             videoInCache->SetTObjectValueL<TUint32>( KVcxMediaMyVideosDownloadId,
       
   958                     downloadIdInNew );
       
   959 
       
   960             if ( downloadIdInNew == 0 )
       
   961                 {
       
   962                 iDownloadCache->Delete( videoInCache );
       
   963                 }
       
   964             changed = ETrue;
       
   965             }
       
   966         }
       
   967     // 19
  1089     // 19
   968     if ( aVideo.IsSupported( KVcxMediaMyVideosRating ) )
  1090     if ( aVideo.IsSupported( KVcxMediaMyVideosRating ) )
   969         {
  1091         {
   970         TUint8 ratingInCache( TVcxMyVideosCollectionUtil::RatingL( *videoInCache ) );
  1092         TUint8 ratingInCache( TVcxMyVideosCollectionUtil::RatingL( *videoInCache ) );
   971         TUint8 ratingInNew( TVcxMyVideosCollectionUtil::RatingL( aVideo ) );
  1093         TUint8 ratingInNew( TVcxMyVideosCollectionUtil::RatingL( aVideo ) );
   999         if (  AudioFourCcInNew != AudioFourCcInCache )
  1121         if (  AudioFourCcInNew != AudioFourCcInCache )
  1000             {
  1122             {
  1001             videoInCache->SetTObjectValueL<TUint32>( KVcxMediaMyVideosAudioFourCc,
  1123             videoInCache->SetTObjectValueL<TUint32>( KVcxMediaMyVideosAudioFourCc,
  1002                     AudioFourCcInNew );
  1124                     AudioFourCcInNew );
  1003 
  1125 
  1004             if ( AudioFourCcInNew == 0 )
       
  1005                 {
       
  1006                 iDownloadCache->Delete( videoInCache );
       
  1007                 }
       
  1008             changed = ETrue;
  1126             changed = ETrue;
  1009             }
  1127             }
  1010         }
  1128         }
  1011 
  1129 
  1012     // 22
  1130     // 22
  1045                     aVideo.ValueText( KMPXMediaVideoArtist ) );
  1163                     aVideo.ValueText( KMPXMediaVideoArtist ) );
  1046 
  1164 
  1047             changed = ETrue;
  1165             changed = ETrue;
  1048             }
  1166             }
  1049         }
  1167         }
  1050         
  1168     
       
  1169     if ( changed )
       
  1170         {
       
  1171         iCollection.iMessageList->SendL();
       
  1172         }
       
  1173     
  1051     return changed;    
  1174     return changed;    
  1052     }
  1175     }
  1053 
  1176 
  1054 // ----------------------------------------------------------------------------
  1177 // ----------------------------------------------------------------------------
  1055 // CVcxMyVideosVideoCache::HandleVideoTitleModifiedL
  1178 // CVcxMyVideosVideoCache::HandleVideoTitleModifiedL
  1065 
  1188 
  1066     TBool modified = EFalse;
  1189     TBool modified = EFalse;
  1067     iCollection.CategoriesL().UpdateCategoryNewVideoNameAndDateL(
  1190     iCollection.CategoriesL().UpdateCategoryNewVideoNameAndDateL(
  1068             *aVideoInCache, modified );
  1191             *aVideoInCache, modified );
  1069 
  1192 
       
  1193 #ifndef VIDEO_COLLECTION_PLUGIN_TB92
       
  1194     iCollection.AlbumsL().VideoTitleChangedL(
       
  1195             TVcxMyVideosCollectionUtil::IdL( *aVideoInCache ).iId1 );
       
  1196 #endif
       
  1197     
  1070     TVcxMyVideosSortingOrder sortingOrder = SortingOrderL();
  1198     TVcxMyVideosSortingOrder sortingOrder = SortingOrderL();
  1071     if ( sortingOrder == EVcxMyVideosSortingName )
  1199     if ( sortingOrder == EVcxMyVideosSortingName )
  1072         {
  1200         {
  1073         MPX_DEBUG1(" Title modified and sorting by Name -> moving item to correct place");
  1201         MPX_DEBUG1(" Title modified and sorting by Name -> moving item to correct place");
  1074         
  1202         
  1352         return KErrAlreadyExists;
  1480         return KErrAlreadyExists;
  1353         }
  1481         }
  1354         
  1482         
  1355     TInt pos = FindCorrectPositionL( aVideo, aSortingOrder );
  1483     TInt pos = FindCorrectPositionL( aVideo, aSortingOrder );
  1356 
  1484 
  1357     CMPXMediaArray* cachedVideoArray = NULL;            
  1485     CMPXMediaArray* cachedVideoArray = iVideoList->Value<CMPXMediaArray>(
  1358     cachedVideoArray = iVideoList->Value<CMPXMediaArray>(
       
  1359             KMPXMediaArrayContents );
  1486             KMPXMediaArrayContents );
  1360 
  1487 
  1361     if ( pos > (cachedVideoArray->Count() -1) )
  1488     if ( pos > (cachedVideoArray->Count() -1) )
  1362         {
  1489         {
  1363         cachedVideoArray->AppendL( aVideo );                    
  1490         cachedVideoArray->AppendL( aVideo );
  1364         }
  1491         }
  1365     else
  1492     else
  1366         {
  1493         {
  1367         cachedVideoArray->InsertL( aVideo, pos );
  1494         cachedVideoArray->InsertL( aVideo, pos );
  1368         }
  1495         }
  1369         
  1496     iVideoListIndex->AddL( cachedVideoArray->AtL( pos ), pos );
       
  1497 #ifdef _DEBUG
       
  1498     CheckVideoListIndexL();
       
  1499 #endif
       
  1500     
  1370     if ( aUpdateCategories )
  1501     if ( aUpdateCategories )
  1371         {
  1502         {
  1372         iCollection.CategoriesL().VideoAddedL( aVideo );
  1503         iCollection.CategoriesL().VideoAddedL( aVideo );
       
  1504 #ifndef VIDEO_COLLECTION_PLUGIN_TB92
       
  1505         iCollection.AlbumsL().VideoAddedOrRemovedFromCacheL( aVideo );
       
  1506 #endif
  1373         }
  1507         }
  1374 
  1508 
  1375     return KErrNone;
  1509     return KErrNone;
  1376     }
  1510     }
  1377 
  1511 
  1405     return RemoveL( TVcxMyVideosCollectionUtil::IdL( aVideo ).iId1, aUpdateCategories );
  1539     return RemoveL( TVcxMyVideosCollectionUtil::IdL( aVideo ).iId1, aUpdateCategories );
  1406     }
  1540     }
  1407 
  1541 
  1408 // ----------------------------------------------------------------------------
  1542 // ----------------------------------------------------------------------------
  1409 // CVcxMyVideosVideoCache::RemoveL
  1543 // CVcxMyVideosVideoCache::RemoveL
       
  1544 // All removes end up here (except ResetVideoListL).
  1410 // ----------------------------------------------------------------------------
  1545 // ----------------------------------------------------------------------------
  1411 //
  1546 //
  1412 TInt CVcxMyVideosVideoCache::RemoveL( TUint32 aMdsId, TBool aUpdateCategories )
  1547 TInt CVcxMyVideosVideoCache::RemoveL( TUint32 aMdsId, TBool aUpdateCategories )
  1413     {
  1548     {
  1414     MPX_FUNC("CVcxMyVideosVideoCache::RemoveL");
  1549     MPX_FUNC("CVcxMyVideosVideoCache::RemoveL");
  1419     if ( !video )
  1554     if ( !video )
  1420         {
  1555         {
  1421         MPX_DEBUG1("CVcxMyVideosVideoCache:: RemoveL failed since the item wasn't on cache");
  1556         MPX_DEBUG1("CVcxMyVideosVideoCache:: RemoveL failed since the item wasn't on cache");
  1422         return KErrNotFound;
  1557         return KErrNotFound;
  1423         }
  1558         }
  1424 
       
  1425     iDownloadCache->Delete( video );
       
  1426 
       
  1427     TUint32 flags( 0 );
       
  1428 	if ( video->IsSupported( KMPXMediaGeneralFlags ) )
       
  1429 	    {
       
  1430 		flags = video->ValueTObjectL<TUint32>( KMPXMediaGeneralFlags );
       
  1431 		}
       
  1432     
       
  1433     if ( ( flags & EVcxMyVideosVideoNew ) && 
       
  1434             TVcxMyVideosCollectionUtil::OriginL( *video ) == EVcxMyVideosOriginDownloaded )
       
  1435         {       
       
  1436         MPX_DEBUG1("CVcxMyVideosVideoCache::RemoveL - New video has been removed from Downloaded origin -> sending mediator event to notification launcher");
       
  1437         iCollection.NotifyNewVideosCountDecreasedL( *video );
       
  1438         }
       
  1439     
  1559     
  1440     if ( aUpdateCategories &&
  1560     if ( aUpdateCategories &&
  1441             pos != KErrNotFound /* no need to update if item is on iPartialVideoList*/ )
  1561             pos != KErrNotFound /* no need to update if item is on iPartialVideoList*/ )
  1442         {
  1562         {
  1443         iCollection.CategoriesL().VideoRemovedL( *video );
  1563         iCollection.CategoriesL().VideoRemovedL( *video );
       
  1564 #ifndef VIDEO_COLLECTION_PLUGIN_TB92
       
  1565         iCollection.AlbumsL().VideoAddedOrRemovedFromCacheL( *video );
       
  1566 #endif
  1444         }
  1567         }
  1445         
  1568         
  1446     if ( pos != KErrNotFound )
  1569     if ( pos != KErrNotFound )
  1447         {
  1570         {
  1448         CMPXMediaArray* cachedVideoArray = iVideoList->Value<CMPXMediaArray>(
  1571         CMPXMediaArray* cachedVideoArray = iVideoList->Value<CMPXMediaArray>(
  1449                 KMPXMediaArrayContents );
  1572                 KMPXMediaArrayContents );
  1450         
  1573         
  1451         MPX_DEBUG2("CVcxMyVideosVideoCache:: %d removed from iVideoList", aMdsId);
  1574         MPX_DEBUG2("CVcxMyVideosVideoCache:: %d removed from iVideoList", aMdsId);
  1452         cachedVideoArray->Remove( pos );
  1575         cachedVideoArray->Remove( pos );
       
  1576         iVideoListIndex->Remove( aMdsId, ETrue /* compress */);
       
  1577 #ifdef _DEBUG
       
  1578         CheckVideoListIndexL();
       
  1579 #endif
  1453         }
  1580         }
  1454     else
  1581     else
  1455         {
  1582         {
  1456         MPX_DEBUG2("CVcxMyVideosVideoCache:: %d removed from iPartialVideoList", aMdsId);
  1583         MPX_DEBUG2("CVcxMyVideosVideoCache:: %d removed from iPartialVideoList", aMdsId);
  1457         iPartialVideoList.Remove( PosOnPartialVideoListL( *video ) );
  1584         iPartialVideoList.Remove( PosOnPartialVideoListL( *video ) );
  1481 //
  1608 //
  1482 void CVcxMyVideosVideoCache::ResetVideoListL()
  1609 void CVcxMyVideosVideoCache::ResetVideoListL()
  1483     {
  1610     {
  1484     MPX_FUNC("CVcxMyVideosVideoCache::ResetVideoListL");
  1611     MPX_FUNC("CVcxMyVideosVideoCache::ResetVideoListL");
  1485 
  1612 
  1486     iCollection.iMyVideosMdsDb->Cancel();
  1613     iCollection.iMyVideosMdsDb->Cancel( CVcxMyVideosMdsDb::EGetVideoList );
  1487 
  1614 
  1488     CMPXMediaArray* mediaArray =
  1615     CMPXMediaArray* mediaArray =
  1489             iVideoList->ValueCObjectL<CMPXMediaArray>( KMPXMediaArrayContents );
  1616             iVideoList->ValueCObjectL<CMPXMediaArray>( KMPXMediaArrayContents );
  1490     CleanupStack::PushL( mediaArray ); // 1->
  1617     CleanupStack::PushL( mediaArray ); // 1->
  1491     
  1618     
  1519                     mediaArray );
  1646                     mediaArray );
  1520             CleanupStack::PopAndDestroy( mediaArray ); // <-1
  1647             CleanupStack::PopAndDestroy( mediaArray ); // <-1
  1521             }
  1648             }
  1522         }
  1649         }
  1523         
  1650         
  1524     iVideoListIsPartial = ETrue;
  1651     SetComplete( EFalse );
  1525 
       
  1526     delete iDownloadCache;
       
  1527     iDownloadCache = NULL;
       
  1528     iDownloadCache = CVcxMyVideosDownloadCache::NewL();
       
  1529                 
  1652                 
  1530     iCollection.CategoriesL().ResetVideoCountersL(); //this does not send events
  1653     iCollection.CategoriesL().ResetVideoCountersL(); //this does not send events
  1531     }
  1654     }
  1532 
  1655 
  1533 // ----------------------------------------------------------------------------
  1656 // ----------------------------------------------------------------------------
  1561         }
  1684         }
  1562     
  1685     
  1563     delete iVideoList;
  1686     delete iVideoList;
  1564     iVideoList = NULL;
  1687     iVideoList = NULL;
  1565     iVideoList = newList;
  1688     iVideoList = newList;
       
  1689     
       
  1690     iVideoListIndex->SetL( *iVideoList );
       
  1691 #ifdef _DEBUG
       
  1692     CheckVideoListIndexL();
       
  1693 #endif
       
  1694     
  1566     CleanupStack::Pop( newList ); // <-1
  1695     CleanupStack::Pop( newList ); // <-1
  1567 
  1696     }
  1568     delete iDownloadCache;
  1697 
  1569     iDownloadCache = NULL;
  1698 // ----------------------------------------------------------------------------
  1570     iDownloadCache = CVcxMyVideosDownloadCache::NewL();
  1699 // CVcxMyVideosVideoCache::IsComplete
  1571     }
  1700 // ----------------------------------------------------------------------------
       
  1701 //
       
  1702 TBool CVcxMyVideosVideoCache::IsComplete()
       
  1703     {
       
  1704     return iVideoListIsComplete;
       
  1705     }
       
  1706 
       
  1707 // ----------------------------------------------------------------------------
       
  1708 // CVcxMyVideosVideoCache::SetComplete
       
  1709 // ----------------------------------------------------------------------------
       
  1710 //
       
  1711 void CVcxMyVideosVideoCache::SetComplete( TBool aComplete )
       
  1712     {
       
  1713     if ( !iVideoListIsComplete && aComplete )
       
  1714         {
       
  1715         MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoList turned to complete, setting up iVideoListIndex");
       
  1716         iVideoListIndex->SetL( *iVideoList );
       
  1717 #ifdef _DEBUG
       
  1718         CheckVideoListIndexL();
       
  1719 #endif
       
  1720         }
       
  1721     iVideoListIsComplete = aComplete;
       
  1722     }
       
  1723 
       
  1724 #ifdef _DEBUG
       
  1725 // ----------------------------------------------------------------------------
       
  1726 // CVcxMyVideosVideoCache::SetComplete
       
  1727 // ----------------------------------------------------------------------------
       
  1728 //
       
  1729 void CVcxMyVideosVideoCache::CheckVideoListIndexL()
       
  1730     {
       
  1731     if ( !IsComplete() )
       
  1732         {
       
  1733         return;
       
  1734         }
       
  1735     
       
  1736     TInt pos;
       
  1737     TInt mdsId;
       
  1738     CMPXMedia* video;
       
  1739     CMPXMediaArray* mediaArray = TVcxMyVideosCollectionUtil::MediaArrayL( *iVideoList );
       
  1740     TInt count = iVideoListIndex->VideoArray().Count();
       
  1741     for ( TInt i = 0; i < count; i++ )
       
  1742         {
       
  1743         pos   = iVideoListIndex->VideoArray()[i].iPos;
       
  1744         mdsId = iVideoListIndex->VideoArray()[i].iMdsId;
       
  1745         video = iVideoListIndex->VideoArray()[i].iVideo;
       
  1746         
       
  1747         if ( pos < 0 || pos > mediaArray->Count() -1 )
       
  1748             {
       
  1749             MPX_DEBUG3( "CVcxMyVideosVideoCache:: iVideoListIndex->iVideoArray[%d].iPos out of range -> Panic",
       
  1750                     i, pos );
       
  1751             _LIT( KVideoListIndexPosCorrupted, "iVideoListIndex pos");
       
  1752             User::Panic( KVideoListIndexPosCorrupted, KErrCorrupt ); 
       
  1753             }
       
  1754         
       
  1755         if ( mediaArray->AtL( pos ) != video )
       
  1756             {
       
  1757             MPX_DEBUG3( "CVcxMyVideosVideoCache:: iVideoListIndex->iVideoArray[%d].iVideo != mediaArray->AtL( %d ) -> Panic",
       
  1758                     i, pos );
       
  1759             _LIT( KVideoListIndexVideoCorrupted, "iVideoListIndex video pointer");
       
  1760             User::Panic( KVideoListIndexVideoCorrupted, KErrCorrupt );
       
  1761             }
       
  1762         
       
  1763         if ( TVcxMyVideosCollectionUtil::IdL( *mediaArray->AtL( pos ) ).iId1 != 
       
  1764                 mdsId )
       
  1765             {
       
  1766             MPX_DEBUG3( "CVcxMyVideosVideoCache:: iVideoListIndex->iVideoArray[%d].iMdsId != MDSID in mediaArray->AtL( %d ) -> Panic",
       
  1767                     i, pos );
       
  1768             _LIT( KVideoListIndexMdsIdCorrupted, "iVideoListIndex MDS ID");
       
  1769             User::Panic( KVideoListIndexMdsIdCorrupted, KErrCorrupt );        
       
  1770             }
       
  1771         }
       
  1772     MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoListIndex check OK");
       
  1773     }
       
  1774 #endif
       
  1775 
  1572 // End of file
  1776 // End of file
  1573 
  1777