videocollection/mpxmyvideoscollection/src/vcxmyvideosvideocache.cpp
changeset 34 bbb98528c666
parent 30 4f111d64a341
child 35 3738fe97f027
--- a/videocollection/mpxmyvideoscollection/src/vcxmyvideosvideocache.cpp	Thu Apr 01 23:13:36 2010 +0300
+++ b/videocollection/mpxmyvideoscollection/src/vcxmyvideosvideocache.cpp	Thu Apr 01 23:22:15 2010 +0300
@@ -29,10 +29,8 @@
 #include <mpxmediavideodefs.h>
 #include "vcxmyvideosvideocache.h"
 #include "vcxmyvideoscollectionplugin.h"
-#include "vcxmyvideosdownloadutil.h"
 #include "vcxmyvideoscollectionutil.h"
 #include "vcxmyvideoscategories.h"
-#include "vcxmyvideosdownloadcache.h"
 #include "vcxmyvideosmessagelist.h"
 #include "vcxmyvideosopenhandler.h"
 
@@ -66,9 +64,6 @@
     MPX_FUNC("CVcxMyVideosVideoCache::~CVcxMyVideosVideoCache");
     
     delete iVideoList;
-    delete iDownloadCache;
-    delete iCenRep;
-    
     DeletePartialList();
     }
 
@@ -94,7 +89,6 @@
     iVideoList          = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL();
     iVideoListIsPartial = ETrue;
 
-    iDownloadCache = CVcxMyVideosDownloadCache::NewL();
     iPartialVideoList.Reset();
     }
 
@@ -269,72 +263,6 @@
     }
 
 // ----------------------------------------------------------------------------
-// CVcxMyVideosVideoCache::FindVideoByDownloadIdL
-// ----------------------------------------------------------------------------
-//
-CMPXMedia* CVcxMyVideosVideoCache::FindVideoByDownloadIdL( TUint aDownloadId )
-    {
-    MPX_FUNC("CVcxMyVideosVideoCache::FindVideoByDownloadIdL()");
-    
-    MPX_DEBUG2("CVcxMyVideosVideoCache:: looking for MPX item  with download ID %d from cache", aDownloadId);
-        
-    if ( aDownloadId == 0 )
-        {
-        MPX_DEBUG1("CVcxMyVideosVideoCache:: dl id == 0 -> NOT FOUND");
-        return NULL;
-        }
-    
-    if ( !iVideoList )
-        {
-        MPX_DEBUG1("CVcxMyVideosVideoCache:: iVideoList is NULL -> NOT FOUND");
-        return NULL;
-        }
-
-    CMPXMedia* video = iDownloadCache->Get( aDownloadId );
-    if ( video )
-        {
-        MPX_DEBUG1("CVcxMyVideosVideoCache:: found from Download Cache");
-        return video;
-        }
-
-    MPX_DEBUG1("CVcxMyVideosVideoCache:: not found from Download Cache");
-
-    CMPXMediaArray* cachedVideoArray = iVideoList->Value<CMPXMediaArray>(
-                                KMPXMediaArrayContents);
-              
-    TUint32 downloadId;
-    TInt count = cachedVideoArray->Count();
-    for ( TInt i = 0; i < count; i++ )
-        {
-        downloadId = TVcxMyVideosCollectionUtil::DownloadIdL( *cachedVideoArray->AtL( i ) );
-        if ( downloadId == aDownloadId )
-            {
-            MPX_DEBUG1("CVcxMyVideosVideoCache:: found from iVideoList");
-            MPX_DEBUG1("CVcxMyVideosVideoCache:: adding to iDownloadCache");
-            iDownloadCache->Add( downloadId, (*cachedVideoArray)[i] );
-            return (*cachedVideoArray)[i];
-            }
-        }
-    
-    count = iPartialVideoList.Count();  
-    for ( TInt i = 0; i < count; i++ )
-        {
-        downloadId = TVcxMyVideosCollectionUtil::DownloadIdL( *(iPartialVideoList[i]) );
-        if ( downloadId ==  aDownloadId )
-            {
-            MPX_DEBUG1("CVcxMyVideosVideoCache:: found from iPartialVideoList");
-            MPX_DEBUG1("CVcxMyVideosVideoCache:: adding to iDownloadCache");
-            iDownloadCache->Add( downloadId, iPartialVideoList[i] );
-            return iPartialVideoList[i];
-            }       
-        }
-        
-    MPX_DEBUG1("CVcxMyVideosVideoCache:: NOT FOUND");
-    return NULL;
-    }
-
-
-// ----------------------------------------------------------------------------
 // CVcxMyVideosVideoCache::GetVideosL
 // ----------------------------------------------------------------------------
 //
@@ -359,14 +287,14 @@
 // CVcxMyVideosVideoCache::AddVideosFromMdsL
 // Called when item inserted events arrive from mds or from
 // KVcxCommandMyVideosGetMediasByMpxId cmd handler.
-// Synchronizing with downloads is not done here, caller must take care of it.
 // If mpx item is already in cache, or MDS does not contain the item (or was not video item),
 // then it is removed from aMdsIds. Ie after this function call aMdsIds contains
-// only IDs which are actually added to cache.
+// only IDs which are actually added to cache. aNonVideoIds will contain IDs
+// which were not video objects.
 // ----------------------------------------------------------------------------
 //    
 void CVcxMyVideosVideoCache::AddVideosFromMdsL( RArray<TUint32>& aMdsIds,
-        TBool& aListFetchingWasCanceled )
+        TBool& aListFetchingWasCanceled, RArray<TUint32>* aNonVideoIds  )
     {
     MPX_FUNC("CVcxMyVideosVideoCache::AddVideosFromMdsL");
 
@@ -416,13 +344,17 @@
                 }
             else
                 {
-                MPX_DEBUG2("CVcxMyVideosVideoCache:: video with %d ID not found from MDS -> skipping add to cache and deleting from id array", aMdsIds[j] );
+                MPX_DEBUG2("CVcxMyVideosVideoCache:: video with %d ID not found from MDS -> prob non video object, skipping add to cache", aMdsIds[j] );
                 aMdsIds.Remove( j );
+                if ( aNonVideoIds )
+                    {
+                    aNonVideoIds->AppendL( j );
+                    }
                 }
             }
         else
             {
-            MPX_DEBUG2("CVcxMyVideosVideoCache:: %d was already in cache -> skipping add, and deleting from id array", aMdsIds[j]);
+            MPX_DEBUG2("CVcxMyVideosVideoCache:: %d was already in cache -> skipping add", aMdsIds[j]);
             aMdsIds.Remove( j );
             }
         }
@@ -958,23 +890,7 @@
             changed = ETrue;
             }
         }
-    // 18
-    if ( aVideo.IsSupported( KVcxMediaMyVideosDownloadId ) )
-        {
-        TUint32 downloadIdInCache( TVcxMyVideosCollectionUtil::DownloadIdL( *videoInCache ) );
-        TUint32 downloadIdInNew( TVcxMyVideosCollectionUtil::DownloadIdL( aVideo ) );
-        if (  downloadIdInNew != downloadIdInCache )
-            {
-            videoInCache->SetTObjectValueL<TUint32>( KVcxMediaMyVideosDownloadId,
-                    downloadIdInNew );
 
-            if ( downloadIdInNew == 0 )
-                {
-                iDownloadCache->Delete( videoInCache );
-                }
-            changed = ETrue;
-            }
-        }
     // 19
     if ( aVideo.IsSupported( KVcxMediaMyVideosRating ) )
         {
@@ -1012,10 +928,6 @@
             videoInCache->SetTObjectValueL<TUint32>( KVcxMediaMyVideosAudioFourCc,
                     AudioFourCcInNew );
 
-            if ( AudioFourCcInNew == 0 )
-                {
-                iDownloadCache->Delete( videoInCache );
-                }
             changed = ETrue;
             }
         }
@@ -1322,18 +1234,17 @@
 //    
 TVcxMyVideosSortingOrder CVcxMyVideosVideoCache::SortingOrderL()
     {
-
-    if( !iCenRep ) 
-        {
-        TUid uid;
-        uid.iUid = KVcxMyVideosCollectionCenrepUid;
-		iCenRep = CRepository::NewL( uid );
-        }
+    TUid uid;
+    uid.iUid = KVcxMyVideosCollectionCenrepUid;
+    CRepository* cenRep = CRepository::NewL( uid );
+    CleanupStack::PushL( cenRep ); // 1->
     
     TInt sortingOrderInCenrep;
 
-    TInt cenRepError = iCenRep->Get( KVcxMyVideosCollectionCenrepKeySortingOrder,
+    TInt cenRepError = cenRep->Get( KVcxMyVideosCollectionCenrepKeySortingOrder,
             sortingOrderInCenrep );
+
+    CleanupStack::PopAndDestroy( cenRep ); // <-1
     
     TVcxMyVideosSortingOrder sortingOrder;
     
@@ -1433,8 +1344,6 @@
         return KErrNotFound;
         }
 
-    iDownloadCache->Delete( video );
-
     TUint32 flags( 0 );
 	if ( video->IsSupported( KMPXMediaGeneralFlags ) )
 	    {
@@ -1534,10 +1443,6 @@
         }
         
     iVideoListIsPartial = ETrue;
-
-    delete iDownloadCache;
-    iDownloadCache = NULL;
-    iDownloadCache = CVcxMyVideosDownloadCache::NewL();
                 
     iCollection.CategoriesL().ResetVideoCountersL(); //this does not send events
     }
@@ -1576,10 +1481,6 @@
     iVideoList = NULL;
     iVideoList = newList;
     CleanupStack::Pop( newList ); // <-1
-
-    delete iDownloadCache;
-    iDownloadCache = NULL;
-    iDownloadCache = CVcxMyVideosDownloadCache::NewL();
     }
 // End of file