videocollection/mpxmyvideoscollection/src/vcxmyvideoscategories.cpp
changeset 0 96612d01cf9f
child 8 ce5ada96ab30
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008 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:    Categories related functionality*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <mpxlog.h>
       
    22 #include <mpxmediacontainerdefs.h>
       
    23 #include <mpxmediageneraldefs.h>
       
    24 #include <mpxcollectionpluginobserver.h>
       
    25 #include <mpxmessagegeneraldefs.h>
       
    26 #include <mpxcommandgeneraldefs.h>
       
    27 #include <mpxcollectioncommanddefs.h>
       
    28 #include <mpxmessagecontainerdefs.h>
       
    29 #include "vcxmyvideoscollectionplugin.h"
       
    30 #include "vcxmyvideoscategories.h"
       
    31 #include "vcxmyvideoscollectionutil.h"
       
    32 #include "vcxmyvideosvideocache.h"
       
    33 #include "vcxmyvideosmessagelist.h"
       
    34 
       
    35 _LIT(KVcxMyVideosAllVideosCategoryText, "All videos");
       
    36 _LIT(KVcxMyVideosDownloadsCategoryText, "Downloads");
       
    37 _LIT(KVcxMyVideosTvRecordingsCategoryText, "TV recordings");
       
    38 _LIT(KVcxMyVideosCapturedVideosCategoryText, "Captured videos");
       
    39 _LIT(KVcxMyVideosOtherCategoryText, "Other");
       
    40 
       
    41 const TInt KVcxMyVideosAllVideosCategoryIndex    = 0;
       
    42 const TInt KVcxMyVideosDownloadsCategoryIndex    = 1;
       
    43 const TInt KVcxMyVideosTvRecordingsCategoryIndex = 2;
       
    44 const TInt KVcxMyVideosCapturedCategoryIndex     = 3;
       
    45 const TInt KVcxMyVideosOtherCategoryIndex        = 4;
       
    46 
       
    47 
       
    48 // ============================ MEMBER FUNCTIONS ==============================
       
    49 
       
    50 // ----------------------------------------------------------------------------
       
    51 // Two-phased constructor.
       
    52 // ----------------------------------------------------------------------------
       
    53 //
       
    54 CVcxMyVideosCategories* CVcxMyVideosCategories::NewL(
       
    55     CVcxMyVideosCollectionPlugin& aCollection )
       
    56     {
       
    57     MPX_FUNC("CVcxMyVideosCategories::NewL");
       
    58 
       
    59     CVcxMyVideosCategories* self = new (ELeave) CVcxMyVideosCategories( aCollection );
       
    60     CleanupStack::PushL(self);
       
    61     self->ConstructL();
       
    62     CleanupStack::Pop(self);
       
    63     return self;
       
    64     }
       
    65 
       
    66 // ----------------------------------------------------------------------------
       
    67 // Destructor.
       
    68 // ----------------------------------------------------------------------------
       
    69 //
       
    70 CVcxMyVideosCategories::~CVcxMyVideosCategories()
       
    71     {
       
    72     MPX_FUNC("CVcxMyVideosCategories::~CVcxMyVideosCategories");
       
    73     
       
    74     delete iList;
       
    75     iModifiedCategories.Close();
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // Constructor.
       
    80 // ----------------------------------------------------------------------------
       
    81 //
       
    82 CVcxMyVideosCategories::CVcxMyVideosCategories( CVcxMyVideosCollectionPlugin& aCollection )
       
    83 : iCollection( aCollection )
       
    84     {
       
    85     MPX_FUNC("CVcxMyVideosCategories::CVcxMyVideosCategories");
       
    86     }
       
    87 
       
    88 // ----------------------------------------------------------------------------
       
    89 // Symbian 2nd phase constructor can leave.
       
    90 // ----------------------------------------------------------------------------
       
    91 //
       
    92 void CVcxMyVideosCategories::ConstructL ()
       
    93     {
       
    94     MPX_FUNC("CVcxMyVideosCategories::ConstructL");
       
    95     iList      = CreateCategoryListL();
       
    96     iListArray = iList->Value<CMPXMediaArray>( KMPXMediaArrayContents );   
       
    97 
       
    98     TInt categoryCount = iListArray->Count();
       
    99     for ( TInt i = 0; i < categoryCount; i++ )
       
   100         {
       
   101         iModifiedCategories.Append( EFalse );
       
   102         }
       
   103 
       
   104     }
       
   105     
       
   106 // ----------------------------------------------------------------------------------------------------------
       
   107 // CVcxMyVideosCategories::CreateCategoryListL
       
   108 // ----------------------------------------------------------------------------------------------------------
       
   109 //
       
   110 CMPXMedia* CVcxMyVideosCategories::CreateCategoryListL()
       
   111     {
       
   112     //first level
       
   113 
       
   114     CMPXMedia* entries = TVcxMyVideosCollectionUtil::CreateEmptyMediaListL();
       
   115     CleanupStack::PushL( entries ); // 1->
       
   116     entries->SetTObjectValueL<TMPXItemId>(KMPXMediaGeneralId, 0 /*aPath.Id( 0 )*/);
       
   117     CMPXMediaArray* entryArray = entries->Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
   118 
       
   119     AppendCategoryToArrayL( KVcxMyVideosAllVideosCategoryText,
       
   120             TMPXItemId( KVcxMvcCategoryIdAll, 1), *entryArray );
       
   121 
       
   122     AppendCategoryToArrayL( KVcxMyVideosDownloadsCategoryText,
       
   123             TMPXItemId( KVcxMvcCategoryIdDownloads, 1 ), *entryArray );
       
   124 
       
   125     AppendCategoryToArrayL( KVcxMyVideosTvRecordingsCategoryText,
       
   126             TMPXItemId( KVcxMvcCategoryIdTvRecordings, 1 ), *entryArray );
       
   127 
       
   128     AppendCategoryToArrayL( KVcxMyVideosCapturedVideosCategoryText,
       
   129             TMPXItemId( KVcxMvcCategoryIdCaptured, 1), *entryArray );
       
   130 
       
   131     AppendCategoryToArrayL( KVcxMyVideosOtherCategoryText,
       
   132             TMPXItemId( KVcxMvcCategoryIdOther, 1 ), *entryArray );
       
   133 
       
   134     entries->SetTObjectValueL( KMPXMediaArrayCount, entryArray->Count() );
       
   135 
       
   136     CleanupStack::Pop( entries ); // <-1
       
   137 
       
   138     return entries;
       
   139     }
       
   140 
       
   141 // ----------------------------------------------------------------------------------------------------------
       
   142 // CVcxMyVideosCategories::AppendCategoryToArrayL
       
   143 // ----------------------------------------------------------------------------------------------------------
       
   144 //
       
   145 void CVcxMyVideosCategories::AppendCategoryToArrayL( const TDesC& aTitle, TMPXItemId aId,
       
   146         CMPXMediaArray& aCategoryArray )
       
   147     {
       
   148     RArray<TInt> supportedIds;
       
   149     CleanupClosePushL( supportedIds ); // 1->
       
   150     supportedIds.AppendL( KMPXMediaIdGeneral );
       
   151 
       
   152     CMPXMedia* category = CMPXMedia::NewL( supportedIds.Array() );
       
   153     CleanupStack::PushL( category ); // 2->
       
   154     category->SetTextValueL( KMPXMediaGeneralTitle, aTitle );
       
   155     category->SetTObjectValueL( KMPXMediaGeneralId, aId );
       
   156     category->SetTObjectValueL( KMPXMediaGeneralType, EMPXGroup );
       
   157     category->SetTObjectValueL( KMPXMediaGeneralCategory, EMPXNoCategory );
       
   158     category->SetTObjectValueL( KVcxMediaMyVideosCategoryItemCount, 0 );
       
   159     category->SetTObjectValueL( KVcxMediaMyVideosCategoryNewItemCount, 0 );
       
   160     aCategoryArray.AppendL( category );
       
   161     CleanupStack::Pop( category );                // <-2
       
   162     CleanupStack::PopAndDestroy( &supportedIds ); // <-1
       
   163     }
       
   164 
       
   165 // ----------------------------------------------------------------------------
       
   166 // CVcxMyVideosCategories::UpdateCategoriesL
       
   167 // Called by iCollection when fetching the video list from mds incrementally.
       
   168 // ----------------------------------------------------------------------------
       
   169 //
       
   170 void CVcxMyVideosCategories::UpdateCategoriesL( CMPXMedia& aVideoList,
       
   171         TInt aNewItemsStartIndex )
       
   172     {    
       
   173     CMPXMediaArray* categoryArray = iList->Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
   174     TInt categoryCount            = categoryArray->Count();
       
   175 
       
   176     RArray<TInt> videosIncrements;
       
   177     videosIncrements.Reset();
       
   178     CleanupClosePushL( videosIncrements ); // 1->
       
   179 
       
   180     RArray<TInt> newVideosIncrements;
       
   181     newVideosIncrements.Reset();
       
   182     CleanupClosePushL( newVideosIncrements ); // 2->
       
   183 
       
   184     TInt i;
       
   185     for ( i = 0; i < categoryCount; i++ )
       
   186         {
       
   187         videosIncrements.AppendL( 0 );
       
   188         newVideosIncrements.Append( 0 );
       
   189         }
       
   190 
       
   191     CMPXMediaArray* videoListArray = aVideoList.Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
   192     TInt videoListCount            = videoListArray->Count();
       
   193 
       
   194     videosIncrements[KVcxMyVideosAllVideosCategoryIndex] = videoListCount - aNewItemsStartIndex;
       
   195     
       
   196     CMPXMedia* media;
       
   197     for ( i = aNewItemsStartIndex; i < videoListCount; i++ )
       
   198         {
       
   199         TUint8 origin = EVcxMyVideosOriginOther;
       
   200         
       
   201         media = videoListArray->AtL( i );
       
   202         
       
   203         if ( media->IsSupported( KVcxMediaMyVideosOrigin ) )
       
   204             {
       
   205             origin = media->ValueTObjectL<TUint8>( KVcxMediaMyVideosOrigin );                
       
   206             }
       
   207         
       
   208         TBool newVideo = EFalse;
       
   209         TUint32 flags  = 0;
       
   210         
       
   211         if ( media->IsSupported( KMPXMediaGeneralFlags ) )
       
   212             {
       
   213             flags = media->ValueTObjectL<TUint32>( KMPXMediaGeneralFlags );
       
   214             if ( flags & EVcxMyVideosVideoNew )
       
   215                 {
       
   216                 newVideo = ETrue;
       
   217                 newVideosIncrements[KVcxMyVideosAllVideosCategoryIndex]++;
       
   218                 }
       
   219             }
       
   220         
       
   221         switch ( origin )
       
   222             {
       
   223             case EVcxMyVideosOriginDownloaded:
       
   224                 videosIncrements[KVcxMyVideosDownloadsCategoryIndex]++;
       
   225                 if ( newVideo )
       
   226                     {
       
   227                     newVideosIncrements[KVcxMyVideosDownloadsCategoryIndex]++;
       
   228                     }
       
   229                 break;
       
   230                 
       
   231             case EVcxMyVideosOriginCapturedWithCamera:
       
   232                 videosIncrements[KVcxMyVideosCapturedCategoryIndex]++;
       
   233                 if ( newVideo )
       
   234                     {
       
   235                     newVideosIncrements[KVcxMyVideosCapturedCategoryIndex]++;
       
   236                     }
       
   237                 break;
       
   238                                 
       
   239             case EVcxMyVideosOriginTvRecording:
       
   240                 videosIncrements[KVcxMyVideosTvRecordingsCategoryIndex]++;
       
   241                 if ( newVideo )
       
   242                     {
       
   243                     newVideosIncrements[KVcxMyVideosTvRecordingsCategoryIndex]++;
       
   244                     }
       
   245                 break;
       
   246 
       
   247             case EVcxMyVideosOriginSideLoaded:                
       
   248             case EVcxMyVideosOriginOther:
       
   249             default:
       
   250                 videosIncrements[KVcxMyVideosOtherCategoryIndex]++;
       
   251                 if ( newVideo )
       
   252                     {
       
   253                     newVideosIncrements[KVcxMyVideosOtherCategoryIndex]++;
       
   254                     }
       
   255                 break;
       
   256             }
       
   257         }
       
   258 
       
   259     // Update videos counts
       
   260     UpdateVideosCountL( *categoryArray, videosIncrements, newVideosIncrements );
       
   261 
       
   262     CleanupStack::PopAndDestroy( &newVideosIncrements ); // <-1
       
   263     CleanupStack::PopAndDestroy( &videosIncrements ); // <-1
       
   264     }
       
   265 
       
   266 // ----------------------------------------------------------------------------
       
   267 // CVcxMyVideosCategories::UpdateVideosCountL
       
   268 // ----------------------------------------------------------------------------
       
   269 //
       
   270 void CVcxMyVideosCategories::UpdateVideosCountL( CMPXMediaArray& aCategoryArray,
       
   271     RArray<TInt>& aVideosIncrements, RArray<TInt>& aNewVideosIncrements )
       
   272     {
       
   273     TBool modified = EFalse;
       
   274     TInt categoryCount = aCategoryArray.Count();
       
   275     CMPXMedia* category;
       
   276     
       
   277     for ( TInt i = 0; i < categoryCount; i++ )
       
   278         {
       
   279         if ( aVideosIncrements[i] != 0 )
       
   280             {
       
   281             category = aCategoryArray.AtL( i );
       
   282 
       
   283             UpdateVideosCountL( *category, aVideosIncrements[i], KVcxMediaMyVideosCategoryItemCount,
       
   284                     EVcxMyVideosListNoInfo );
       
   285 
       
   286             modified = ETrue;
       
   287             }
       
   288 
       
   289         if ( aNewVideosIncrements[i] != 0 )
       
   290             {
       
   291             category = aCategoryArray.AtL( i );
       
   292 
       
   293             UpdateVideosCountL( *category, aNewVideosIncrements[i], KVcxMediaMyVideosCategoryNewItemCount,
       
   294                     EVcxMyVideosListNoInfo );
       
   295 
       
   296             modified = ETrue;
       
   297             }
       
   298 
       
   299         }
       
   300     if ( modified )
       
   301         {
       
   302         iCollection.iMessageList->SendL();
       
   303         }
       
   304     }
       
   305 
       
   306 // ----------------------------------------------------------------------------
       
   307 // CVcxMyVideosCategories::UpdateVideosCountL
       
   308 // ----------------------------------------------------------------------------
       
   309 //
       
   310 void CVcxMyVideosCategories::UpdateVideosCountL( CMPXMedia& aCategory,
       
   311     TInt aIncrement, TMPXAttributeData aCountAttribute, TInt aEventInfo )
       
   312     {
       
   313     if ( aIncrement != 0 )
       
   314         {
       
   315         AddToTUint32AttributeL( aCategory, aIncrement, aCountAttribute );
       
   316                 
       
   317         iCollection.iMessageList->AddEventL( aCategory.ValueTObjectL<TMPXItemId>(
       
   318                 KMPXMediaGeneralId ), EMPXItemModified, aEventInfo );
       
   319         }
       
   320     }
       
   321 
       
   322 // ----------------------------------------------------------------------------
       
   323 // CVcxMyVideosCategories::VideosAddedL
       
   324 // ----------------------------------------------------------------------------
       
   325 //
       
   326 void CVcxMyVideosCategories::VideosAddedL( RArray<TUint32>& aIds )
       
   327     {
       
   328     VideosAddedOrRemovedL( aIds, ETrue );
       
   329     }
       
   330 
       
   331 // ----------------------------------------------------------------------------
       
   332 // CVcxMyVideosCategories::VideosRemovedL
       
   333 // ----------------------------------------------------------------------------
       
   334 //
       
   335 void CVcxMyVideosCategories::VideosRemovedL( RArray<TUint32>& aIds )
       
   336     {
       
   337     VideosAddedOrRemovedL( aIds, EFalse );
       
   338     }
       
   339 
       
   340 // ----------------------------------------------------------------------------
       
   341 // CVcxMyVideosCategories::VideoAddedL
       
   342 // ----------------------------------------------------------------------------
       
   343 //
       
   344 void CVcxMyVideosCategories::VideoAddedL( TUint32 aMdsId )
       
   345     {
       
   346     TInt pos( KErrNotFound );
       
   347     CMPXMedia* video = iCollection.iCache->FindVideoByMdsIdL( aMdsId, pos );
       
   348     if ( pos != KErrNotFound )
       
   349         {
       
   350         VideoAddedOrRemovedL( *video, ETrue );
       
   351         }
       
   352     }
       
   353 
       
   354 // ----------------------------------------------------------------------------
       
   355 // CVcxMyVideosCategories::VideoAddedL
       
   356 // ----------------------------------------------------------------------------
       
   357 //
       
   358 void CVcxMyVideosCategories::VideoAddedL( CMPXMedia& aVideo )
       
   359     {
       
   360     VideoAddedOrRemovedL( aVideo, ETrue );
       
   361     }
       
   362 
       
   363 // ----------------------------------------------------------------------------
       
   364 // CVcxMyVideosCategories::VideoRemovedL
       
   365 // ----------------------------------------------------------------------------
       
   366 //
       
   367 void CVcxMyVideosCategories::VideoRemovedL( TUint32 aMdsId )
       
   368     {
       
   369     TInt pos( KErrNotFound );
       
   370     CMPXMedia* video = iCollection.iCache->FindVideoByMdsIdL( aMdsId, pos );
       
   371     if ( pos != KErrNotFound )
       
   372         {
       
   373         VideoAddedOrRemovedL( *video, EFalse );
       
   374         }
       
   375     }
       
   376 
       
   377 // ----------------------------------------------------------------------------
       
   378 // CVcxMyVideosCategories::VideoRemovedL
       
   379 // ----------------------------------------------------------------------------
       
   380 //
       
   381 void CVcxMyVideosCategories::VideoRemovedL( CMPXMedia& aVideo )
       
   382     {
       
   383     VideoAddedOrRemovedL( aVideo, EFalse );
       
   384     }
       
   385     
       
   386 // ----------------------------------------------------------------------------
       
   387 // CVcxMyVideosCategories::VideosAddedOrRemovedL
       
   388 // ----------------------------------------------------------------------------
       
   389 //
       
   390 void CVcxMyVideosCategories::VideosAddedOrRemovedL(
       
   391         RArray<TUint32>& aIds, TBool aAdded )
       
   392     {
       
   393     TInt count = aIds.Count();
       
   394     for ( TInt i = 0; i < count; i++ )
       
   395         {
       
   396         VideoAddedOrRemovedL( aIds[i], aAdded );
       
   397         }
       
   398     }
       
   399     
       
   400 // ----------------------------------------------------------------------------
       
   401 // CVcxMyVideosCategories::VideoAddedOrRemovedL
       
   402 // ----------------------------------------------------------------------------
       
   403 //
       
   404 void CVcxMyVideosCategories::VideoAddedOrRemovedL( TUint32 aMdsId, TBool aAdded )
       
   405     {    
       
   406     TInt pos( KErrNotFound );
       
   407     CMPXMedia* video = iCollection.iCache->FindVideoByMdsIdL( aMdsId, pos );
       
   408     if ( pos != KErrNotFound )
       
   409         {
       
   410         VideoAddedOrRemovedL( *video, aAdded );
       
   411         }
       
   412     }
       
   413 
       
   414 // ----------------------------------------------------------------------------
       
   415 // CVcxMyVideosCategories::VideoAddedOrRemovedL
       
   416 // All remove&add calls eventually come here.
       
   417 // ----------------------------------------------------------------------------
       
   418 //
       
   419 void CVcxMyVideosCategories::VideoAddedOrRemovedL( CMPXMedia& aVideo, TBool aAdded )
       
   420     {
       
   421     MPX_FUNC("CVcxMyVideosCategories::VideoAddedOrRemovedL()");
       
   422 
       
   423     ResetModifiedCategoriesArray();
       
   424 
       
   425     TInt categoryIndex  = CategoryIndex( TVcxMyVideosCollectionUtil::OriginL( aVideo ) );
       
   426     CMPXMedia* category = iListArray->AtL( categoryIndex );
       
   427     // every event updates always 2 categories, all and something else
       
   428     UpdateCategoryL( *category, categoryIndex, aVideo, aAdded );
       
   429 
       
   430     //iMessageArray will discard duplicates
       
   431     AddEventsFromModifiedCategoriesArrayL();
       
   432     }
       
   433     
       
   434 // ----------------------------------------------------------------------------
       
   435 // CVcxMyVideosCategories::UpdateCategoryL
       
   436 // ----------------------------------------------------------------------------
       
   437 //
       
   438 void CVcxMyVideosCategories::UpdateCategoryL( CMPXMedia& aCategory, TInt aCategoryIndex,
       
   439         CMPXMedia& aVideo, TBool aAdded )
       
   440     {
       
   441     MPX_FUNC("CVcxMyVideosCategories::UpdateCategoryL");
       
   442 
       
   443     TInt addition = 0;
       
   444     
       
   445     if ( aAdded )
       
   446         {
       
   447         MPX_DEBUG1("CVcxMyVideosCategories:: video added");
       
   448         if ( TVcxMyVideosCollectionUtil::FlagsL( aVideo ) & EVcxMyVideosVideoNew )
       
   449             {
       
   450             TInt64 newItemsDate( 0 );
       
   451             if ( aVideo.IsSupported( KMPXMediaGeneralDate ) )
       
   452                 {
       
   453                 newItemsDate = aVideo.ValueTObjectL<TInt64>( KMPXMediaGeneralDate );
       
   454                 }
       
   455             TInt64 prevNewDate( 0 );
       
   456             if ( aCategory.IsSupported( KMPXMediaGeneralDate ) )
       
   457                 {
       
   458                 prevNewDate = aCategory.ValueTObjectL<TInt64>( KMPXMediaGeneralDate );
       
   459                 }
       
   460 
       
   461             if ( static_cast<TInt64>(newItemsDate) > static_cast<TInt64>(prevNewDate) )
       
   462                 {                    
       
   463                 MPX_DEBUG1("CVcxMyVideosCategories:: EMPXItemInserted -> changing new video name");
       
   464                 aCategory.SetTextValueL( KVcxMediaMyVideosCategoryNewItemName,
       
   465                         aVideo.ValueText( KMPXMediaGeneralTitle ) );
       
   466                 aCategory.SetTObjectValueL( KMPXMediaGeneralDate, newItemsDate ); 
       
   467                 iListArray->AtL( KVcxMyVideosAllVideosCategoryIndex)->SetTextValueL(
       
   468                         KVcxMediaMyVideosCategoryNewItemName,
       
   469                         aVideo.ValueText( KMPXMediaGeneralTitle ) );
       
   470                 iListArray->AtL( KVcxMyVideosAllVideosCategoryIndex)->SetTObjectValueL(
       
   471                         KMPXMediaGeneralDate, newItemsDate );
       
   472                 iModifiedCategories[aCategoryIndex]                     = ETrue;
       
   473                 iModifiedCategories[KVcxMyVideosAllVideosCategoryIndex] = ETrue;
       
   474                 }
       
   475             }
       
   476         addition = 1;
       
   477         }
       
   478     else
       
   479         {
       
   480         MPX_DEBUG1("CVcxMyVideosCategories:: video deleted");
       
   481 
       
   482         TBool modified = EFalse;
       
   483         RArray<TUint32> ignoredIds;
       
   484         ignoredIds.Reset();
       
   485         CleanupClosePushL( ignoredIds ); // 1->
       
   486         if ( !aAdded )
       
   487             {
       
   488             ignoredIds.AppendL( TVcxMyVideosCollectionUtil::IdL( aVideo ) );
       
   489             }
       
   490         UpdateCategoryNewVideoNameAndDateL( -1 /* -1 origin resolves to All category */,
       
   491                 modified, ignoredIds );
       
   492         UpdateCategoryNewVideoNameAndDateL( TVcxMyVideosCollectionUtil::OriginL( aVideo ),
       
   493                 modified, ignoredIds );
       
   494         CleanupStack::PopAndDestroy( &ignoredIds ); // <-1
       
   495 
       
   496         if ( modified )
       
   497             {
       
   498             iModifiedCategories[aCategoryIndex]                     = ETrue;
       
   499             iModifiedCategories[KVcxMyVideosAllVideosCategoryIndex] = ETrue;
       
   500             }
       
   501             
       
   502         addition = -1;
       
   503         }
       
   504         
       
   505     
       
   506     if ( addition != 0 )
       
   507         {
       
   508         AddToTUint32AttributeL( aCategory, addition, KVcxMediaMyVideosCategoryItemCount );
       
   509         AddToTUint32AttributeL( *(iListArray->AtL( KVcxMyVideosAllVideosCategoryIndex) ),
       
   510                 addition, KVcxMediaMyVideosCategoryItemCount );
       
   511         if ( TVcxMyVideosCollectionUtil::FlagsL( aVideo ) & EVcxMyVideosVideoNew )
       
   512             {
       
   513             AddToTUint32AttributeL( aCategory, addition, KVcxMediaMyVideosCategoryNewItemCount );
       
   514             AddToTUint32AttributeL( *(iListArray->AtL( KVcxMyVideosAllVideosCategoryIndex) ),
       
   515                     addition, KVcxMediaMyVideosCategoryNewItemCount );
       
   516             }
       
   517         iModifiedCategories[aCategoryIndex]                     = ETrue;
       
   518         iModifiedCategories[KVcxMyVideosAllVideosCategoryIndex] = ETrue;
       
   519         }
       
   520     }
       
   521 
       
   522 // ----------------------------------------------------------------------------
       
   523 // CVcxMyVideosCategories::AddToTUint32AttributeL
       
   524 // ----------------------------------------------------------------------------
       
   525 //
       
   526 void CVcxMyVideosCategories::AddToTUint32AttributeL( CMPXMedia& aCategory, TInt aAddition,
       
   527         TMPXAttributeData aAttribute )
       
   528     {
       
   529     TUint32 previousCount = 0;
       
   530     if ( aCategory.IsSupported( aAttribute ) )
       
   531         {
       
   532         previousCount = aCategory.ValueTObjectL<TUint32>( aAttribute );
       
   533         }
       
   534     
       
   535     TInt totalCount = previousCount + aAddition;
       
   536     if ( totalCount < 0 )
       
   537         {
       
   538         totalCount = 0;
       
   539         }
       
   540     aCategory.SetTObjectValueL<TUint32>( aAttribute, totalCount );
       
   541 
       
   542     MPX_DEBUG2("CVcxMyVideosCategories::AddToTUint32AttributeL() attribute(%x): ", aAttribute );
       
   543     MPX_DEBUG3("CVcxMyVideosCategories::AddToTUint32AttributeL() %d -> %d", previousCount, totalCount);
       
   544     }
       
   545 
       
   546 // ----------------------------------------------------------------------------
       
   547 // CVcxMyVideosCategories::CategoryIndex
       
   548 // ----------------------------------------------------------------------------
       
   549 //
       
   550 TInt CVcxMyVideosCategories::CategoryIndex( TInt aOrigin )
       
   551     {
       
   552     switch ( aOrigin )
       
   553         {
       
   554         case -1:
       
   555             return KVcxMyVideosAllVideosCategoryIndex;
       
   556             
       
   557         case EVcxMyVideosOriginDownloaded:
       
   558             return KVcxMyVideosDownloadsCategoryIndex;
       
   559             
       
   560         case EVcxMyVideosOriginCapturedWithCamera:
       
   561             return KVcxMyVideosCapturedCategoryIndex;
       
   562                             
       
   563         case EVcxMyVideosOriginTvRecording:
       
   564             return KVcxMyVideosTvRecordingsCategoryIndex;
       
   565 
       
   566         case EVcxMyVideosOriginSideLoaded:                
       
   567         case EVcxMyVideosOriginOther:
       
   568         default:
       
   569             return KVcxMyVideosOtherCategoryIndex;
       
   570         }
       
   571     }     
       
   572 
       
   573 // ----------------------------------------------------------------------------
       
   574 // CVcxMyVideosCategories::NewVideoFlagChangedL
       
   575 // ----------------------------------------------------------------------------
       
   576 //
       
   577 void CVcxMyVideosCategories::NewVideoFlagChangedL( TUint32 aOldFlag, TUint32 aNewFlag,
       
   578         TUint8 aOrigin, TBool& aModified )
       
   579     {
       
   580     CMPXMedia* categoryAll;
       
   581     CMPXMedia* categoryByOrigin;
       
   582     TBool modified = EFalse;
       
   583     
       
   584     if ( (aOldFlag & EVcxMyVideosVideoNew) && !(aNewFlag & EVcxMyVideosVideoNew) )
       
   585         {
       
   586         // new flag cleared -> update counters
       
   587         categoryByOrigin = iListArray->AtL( CategoryIndex( aOrigin ) );
       
   588         AddToTUint32AttributeL( *categoryByOrigin, -1, KVcxMediaMyVideosCategoryNewItemCount );
       
   589         categoryAll = iListArray->AtL( KVcxMyVideosAllVideosCategoryIndex );
       
   590         AddToTUint32AttributeL( *categoryAll, -1, KVcxMediaMyVideosCategoryNewItemCount );
       
   591         aModified = ETrue;
       
   592         modified  = ETrue;
       
   593         } 
       
   594     else if ( !(aOldFlag & EVcxMyVideosVideoNew) && (aNewFlag & EVcxMyVideosVideoNew) )
       
   595         {
       
   596         // new flag set -> update counters
       
   597         categoryByOrigin = iListArray->AtL( CategoryIndex( aOrigin ) );
       
   598         AddToTUint32AttributeL( *categoryByOrigin, 1, KVcxMediaMyVideosCategoryNewItemCount );
       
   599         categoryAll = iListArray->AtL( KVcxMyVideosAllVideosCategoryIndex );
       
   600         AddToTUint32AttributeL( *categoryAll, 1, KVcxMediaMyVideosCategoryNewItemCount );
       
   601         aModified = ETrue;
       
   602         modified  = ETrue;
       
   603         }
       
   604         
       
   605     if ( modified )
       
   606         {
       
   607         TMPXItemId mpxId( categoryByOrigin->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) );
       
   608         iCollection.iMessageList->AddEventL( mpxId, EMPXItemModified );
       
   609 
       
   610         mpxId = categoryAll->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
   611         iCollection.iMessageList->AddEventL( mpxId, EMPXItemModified );
       
   612         } 
       
   613     }
       
   614 
       
   615 // ----------------------------------------------------------------------------
       
   616 // CVcxMyVideosCategories::ResetVideoCountersL
       
   617 // ----------------------------------------------------------------------------
       
   618 //
       
   619 void CVcxMyVideosCategories::ResetVideoCountersL()
       
   620     {
       
   621     TInt count = iListArray->Count();
       
   622     
       
   623     for ( TInt i = 0; i < count; i++ )
       
   624         {
       
   625         iListArray->AtL( i )->SetTObjectValueL<TUint32>(
       
   626                 KVcxMediaMyVideosCategoryNewItemCount, 0 );
       
   627         iListArray->AtL( i )->SetTObjectValueL<TUint32>(
       
   628                 KVcxMediaMyVideosCategoryItemCount, 0 );
       
   629         }
       
   630     }
       
   631 
       
   632 /*
       
   633 
       
   634 New video name generation:
       
   635 
       
   636 1. When new video list is created: calculate new video names from scratch at the end of list creation.
       
   637 2. Item is removed (mds remove event): calculate from scratch to the categories which are affected.
       
   638 3. Item is added (mds add event): If new item && date is newer than previous -> put it to categories which are affected.
       
   639 4. Items new flag is modified: calculate from scratch to the categories which are affected.
       
   640 5. Items title is modified: calculate from scratch to the categories which are affected.
       
   641 */
       
   642 
       
   643 // ----------------------------------------------------------------------------
       
   644 // CVcxMyVideosCategories::UpdateCategoriesNewVideoNamesL
       
   645 // ----------------------------------------------------------------------------
       
   646 //
       
   647 void CVcxMyVideosCategories::UpdateCategoriesNewVideoNamesL()
       
   648     {
       
   649     MPX_FUNC("CVcxMyVideosCategories::UpdateCategoriesNewVideoNamesL");
       
   650     
       
   651     RArray<TUint32> ignoredIds;
       
   652     ignoredIds.Reset();
       
   653     CleanupClosePushL( ignoredIds ); // 1->
       
   654     TBool modified = EFalse;
       
   655     UpdateCategoryNewVideoNameAndDateL( -1 /* all category */, modified, ignoredIds );
       
   656     UpdateCategoryNewVideoNameAndDateL( EVcxMyVideosOriginCapturedWithCamera, modified,
       
   657             ignoredIds );
       
   658     UpdateCategoryNewVideoNameAndDateL( EVcxMyVideosOriginDownloaded, modified, ignoredIds );
       
   659     UpdateCategoryNewVideoNameAndDateL( EVcxMyVideosOriginTvRecording, modified, ignoredIds );
       
   660     UpdateCategoryNewVideoNameAndDateL( EVcxMyVideosOriginOther, modified, ignoredIds );
       
   661     CleanupStack::PopAndDestroy( &ignoredIds ); // <-1
       
   662     
       
   663     if ( modified )
       
   664         {
       
   665         // flush event list
       
   666         MPX_DEBUG1("CVcxMyVideosCategories:: sending event list");
       
   667         iCollection.iMessageList->SendL();
       
   668         }
       
   669     }
       
   670 
       
   671 // ----------------------------------------------------------------------------
       
   672 // CVcxMyVideosCategories::UpdateCategoryNewVideoNameAndDateL
       
   673 // ----------------------------------------------------------------------------
       
   674 //    
       
   675 void CVcxMyVideosCategories::UpdateCategoryNewVideoNameAndDateL( TInt aOrigin, TBool& aModified,
       
   676         RArray<TUint32>& aIgnoredIds )
       
   677     {   
       
   678     MPX_FUNC("CVcxMyVideosCategories::UpdateCategoryNewVideoNameAndDateL");
       
   679 
       
   680     TPtrC prevNewVideoName;
       
   681     TPtrC currentNewVideoName;
       
   682     
       
   683     CMPXMedia* videoList = iCollection.iCache->iVideoList;
       
   684     
       
   685     TInt categoryIndex = CategoryIndex( aOrigin );
       
   686      
       
   687     prevNewVideoName.Set( iListArray->AtL( categoryIndex )->ValueText(
       
   688             KVcxMediaMyVideosCategoryNewItemName ) );
       
   689     CMPXMedia* newVideo;
       
   690     currentNewVideoName.Set( CalculateNewVideoNameL( *videoList, aOrigin, aIgnoredIds, newVideo ) );
       
   691     if ( currentNewVideoName.CompareF( prevNewVideoName ) != 0 )
       
   692         {
       
   693         iListArray->AtL( categoryIndex )->SetTextValueL(
       
   694                 KVcxMediaMyVideosCategoryNewItemName, currentNewVideoName );
       
   695         MPX_DEBUG3("CVcxMyVideosCategories:: Category[%d] New Video Name changed to %S",
       
   696                 categoryIndex, &currentNewVideoName);
       
   697 
       
   698         if ( newVideo )
       
   699             {
       
   700             TInt64 newDate( 0 );
       
   701             if ( newVideo->IsSupported( KMPXMediaGeneralDate ) )
       
   702                 {
       
   703                 newDate = newVideo->ValueTObjectL<TInt64>( KMPXMediaGeneralDate );
       
   704                 }
       
   705                 
       
   706             iListArray->AtL( categoryIndex )->SetTObjectValueL( KMPXMediaGeneralDate, newDate );
       
   707             }
       
   708         else
       
   709             {
       
   710             iListArray->AtL( categoryIndex )->SetTObjectValueL( KMPXMediaGeneralDate, 0 );
       
   711             }
       
   712             
       
   713         MPX_DEBUG1("CVcxMyVideosCategories:: adding event");
       
   714         
       
   715         TMPXItemId mpxId = iListArray->AtL( categoryIndex )->ValueTObjectL<TMPXItemId>(
       
   716                 KMPXMediaGeneralId );
       
   717         iCollection.iMessageList->AddEventL( mpxId, EMPXItemModified );
       
   718 
       
   719         aModified = ETrue;
       
   720         }
       
   721     }
       
   722 
       
   723 // ----------------------------------------------------------------------------
       
   724 // CVcxMyVideosCategories::CalculateNewVideoNameL
       
   725 // ----------------------------------------------------------------------------
       
   726 //    
       
   727 const TDesC& CVcxMyVideosCategories::CalculateNewVideoNameL( CMPXMedia& aVideoList,
       
   728         TInt aOrigin, RArray<TUint32>& aIgnoredIds, CMPXMedia*& aNewVideo )
       
   729     {
       
   730     MPX_FUNC("CVcxMyVideosCategories::CalculateNewVideoNameL");
       
   731 
       
   732     if ( aOrigin == EVcxMyVideosOriginSideLoaded )
       
   733         {
       
   734         aOrigin = EVcxMyVideosOriginOther;
       
   735         }
       
   736         
       
   737     CMPXMediaArray* videoArray = aVideoList.Value<CMPXMediaArray>(
       
   738             KMPXMediaArrayContents );
       
   739     
       
   740     TInt64 latestCreationDate = 0;
       
   741     TInt64 currentItemsCreationDate;
       
   742     TInt currentLatestItemIndex   = -1;
       
   743     TUint8 origin;
       
   744     TUint32 flags;
       
   745     CMPXMedia* video;
       
   746     TInt count = videoArray->Count();
       
   747     for ( TInt i = 0; i < count; i++ )
       
   748         {
       
   749         video = videoArray->AtL( i );
       
   750 
       
   751         // Handle only items which are not on ignore list (aIgnoredIds).
       
   752         // Items on ignore list are going to be deleted, they just hang around
       
   753         // on the list at this point.
       
   754         if ( aIgnoredIds.Find( video->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ).iId1 )
       
   755                 == KErrNotFound )
       
   756             {
       
   757             // IsSupported check omitted since this value should be set always
       
   758             flags = video->ValueTObjectL<TUint32>( KMPXMediaGeneralFlags );
       
   759             if ( flags & EVcxMyVideosVideoNew )
       
   760                 {
       
   761                 origin = TVcxMyVideosCollectionUtil::OriginL( *video );
       
   762                 if ( aOrigin == -1 || aOrigin == origin )
       
   763                     {
       
   764                     currentItemsCreationDate = video->ValueTObjectL<TInt64>(
       
   765                             KMPXMediaGeneralDate ); 
       
   766                     if ( latestCreationDate < currentItemsCreationDate )
       
   767                         {
       
   768                         latestCreationDate     = currentItemsCreationDate;
       
   769                         currentLatestItemIndex = i;
       
   770                         aNewVideo              = video;
       
   771                         }
       
   772                     }
       
   773                 }
       
   774             }
       
   775         else
       
   776             {
       
   777             MPX_DEBUG1("CVcxMyVideosCategories:: item is on ignore list, skipping");
       
   778             }
       
   779         }
       
   780 
       
   781     if ( currentLatestItemIndex == -1 )
       
   782         {
       
   783         aNewVideo = NULL;
       
   784         return KNullDesC;
       
   785         }
       
   786     else
       
   787         {
       
   788         MPX_DEBUG2("CVcxMyVideosCategories:: returning %S",
       
   789                 &videoArray->AtL( currentLatestItemIndex )->ValueText( KMPXMediaGeneralTitle ) );
       
   790         return videoArray->AtL( currentLatestItemIndex )->ValueText( KMPXMediaGeneralTitle );
       
   791         }
       
   792         
       
   793     }
       
   794 
       
   795 // ----------------------------------------------------------------------------
       
   796 // CVcxMyVideosCategories::UpdateCategoryNewVideoNameAndDateL
       
   797 // Called when video is updated in a way that it affects category new
       
   798 // video name.
       
   799 // ----------------------------------------------------------------------------
       
   800 //
       
   801 void CVcxMyVideosCategories::UpdateCategoryNewVideoNameAndDateL( CMPXMedia& aVideo,
       
   802         TBool& aModified )
       
   803     {
       
   804     //       mpx items for current category new video names should be saved and used to
       
   805     //       speed up this func
       
   806     
       
   807     TBool modified = EFalse;
       
   808     RArray<TUint32> ignoredIds;
       
   809     ignoredIds.Reset();
       
   810     CleanupClosePushL( ignoredIds ); // 1->
       
   811     UpdateCategoryNewVideoNameAndDateL( -1 /* -1 origin resolves to All category */, modified,
       
   812             ignoredIds );
       
   813     UpdateCategoryNewVideoNameAndDateL( TVcxMyVideosCollectionUtil::OriginL( aVideo ), modified,
       
   814             ignoredIds );
       
   815 
       
   816     if ( modified )
       
   817         {
       
   818         aModified = ETrue;
       
   819         }
       
   820     CleanupStack::PopAndDestroy( &ignoredIds ); // <-1
       
   821     }
       
   822 
       
   823 // ----------------------------------------------------------------------------
       
   824 // CVcxMyVideosCategories::GenerateCategoryModifiedEventL
       
   825 // Called when video is updated in a way that it modifies categories in a way
       
   826 // that event is sent.
       
   827 // ----------------------------------------------------------------------------
       
   828 //
       
   829 void CVcxMyVideosCategories::GenerateCategoryModifiedEventL( CMPXMedia& aMedia,
       
   830         TBool aFlushMessageList, TInt32 aExtraInfo )
       
   831     {
       
   832     TMPXItemId mpxId = iListArray->AtL( 0 /* All category*/ )->ValueTObjectL<TMPXItemId>(
       
   833             KMPXMediaGeneralId );
       
   834     
       
   835     MPX_DEBUG2("CVcxMyVideosCategories:: adding modify event for category[0], extra info = %d", aExtraInfo );
       
   836     iCollection.iMessageList->AddEventL( mpxId, EMPXItemModified, aExtraInfo );
       
   837     mpxId = iListArray->AtL( CategoryIndex(
       
   838             TVcxMyVideosCollectionUtil::OriginL( aMedia ) ) )->ValueTObjectL<TMPXItemId>(
       
   839             KMPXMediaGeneralId );
       
   840 
       
   841     MPX_DEBUG3("CVcxMyVideosCategories:: adding modify event for category[%d], extra info = %d", mpxId.iId1, aExtraInfo );
       
   842     iCollection.iMessageList->AddEventL( mpxId, EMPXItemModified, aExtraInfo );
       
   843 
       
   844     if ( aFlushMessageList )
       
   845         {
       
   846         iCollection.iMessageList->SendL();
       
   847         }
       
   848     }
       
   849 
       
   850 // ----------------------------------------------------------------------------
       
   851 // CVcxMyVideosCategories::OriginChangedL
       
   852 // Called when videos origin is changed (Video moves from one category to other).
       
   853 // ----------------------------------------------------------------------------
       
   854 //
       
   855 void CVcxMyVideosCategories::OriginChangedL( CMPXMedia& aVideo, TUint8 aPrevOrigin,
       
   856         TUint8 aNewOrigin )
       
   857     {
       
   858     CMPXMediaArray* categoryArray = iList->Value<CMPXMediaArray>( KMPXMediaArrayContents );
       
   859 
       
   860     UpdateVideosCountL( *(categoryArray->AtL( CategoryIndex( aPrevOrigin ) )),
       
   861             -1, KVcxMediaMyVideosCategoryItemCount, EVcxMyVideosVideoListOrderChanged ); //event added but not sent
       
   862 
       
   863     UpdateVideosCountL( *(categoryArray->AtL( CategoryIndex( aNewOrigin ) )),
       
   864             1, KVcxMediaMyVideosCategoryItemCount, EVcxMyVideosVideoListOrderChanged ); //event added but not sent
       
   865 
       
   866     if ( TVcxMyVideosCollectionUtil::FlagsL( aVideo ) & EVcxMyVideosVideoNew )
       
   867         {
       
   868         UpdateVideosCountL( *(categoryArray->AtL( CategoryIndex( aPrevOrigin ) )),
       
   869                 -1, KVcxMediaMyVideosCategoryNewItemCount, EVcxMyVideosVideoListOrderChanged ); //this event will be optimized away at iCollection.iMessageList
       
   870 
       
   871         UpdateVideosCountL( *(categoryArray->AtL( CategoryIndex( aNewOrigin ) )),
       
   872                 1, KVcxMediaMyVideosCategoryNewItemCount, EVcxMyVideosVideoListOrderChanged ); //this event will be optimized away at iCollection.iMessageList
       
   873         }
       
   874     
       
   875     RArray<TUint32> ignoredIds;
       
   876     ignoredIds.Reset();
       
   877     CleanupClosePushL( ignoredIds ); // 1->
       
   878     TBool modified = EFalse;
       
   879     UpdateCategoryNewVideoNameAndDateL( aPrevOrigin, modified, ignoredIds );
       
   880     UpdateCategoryNewVideoNameAndDateL( aNewOrigin, modified, ignoredIds );
       
   881 
       
   882     CleanupStack::PopAndDestroy( &ignoredIds ); // <-1
       
   883     iCollection.iMessageList->SendL();
       
   884     }
       
   885 
       
   886 // ----------------------------------------------------------------------------
       
   887 // CVcxMyVideosCategories::ResetModifiedCategoriesArray
       
   888 // ----------------------------------------------------------------------------
       
   889 //
       
   890 void CVcxMyVideosCategories::ResetModifiedCategoriesArray()
       
   891     {
       
   892     TInt count = iModifiedCategories.Count();
       
   893     for ( TInt i = 0; i < count; i++ )
       
   894         {
       
   895         iModifiedCategories[i] = EFalse;
       
   896         }
       
   897     }
       
   898 
       
   899 // ----------------------------------------------------------------------------
       
   900 // CVcxMyVideosCategories::AddEventsFromModifiedCategoriesArrayL
       
   901 // ----------------------------------------------------------------------------
       
   902 //
       
   903 void CVcxMyVideosCategories::AddEventsFromModifiedCategoriesArrayL()
       
   904     {
       
   905     TMPXItemId mpxId;
       
   906     TInt count = iModifiedCategories.Count();
       
   907     for ( TInt i = 0; i < count; i++ )
       
   908         {
       
   909         if ( iModifiedCategories[i] )
       
   910             {
       
   911             MPX_DEBUG2("CVcxMyVideosCategories:: category[%d] modified, adding event.", i);
       
   912             mpxId = iListArray->AtL(i)->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
   913             iCollection.iMessageList->AddEventL( mpxId, EMPXItemModified );
       
   914             }
       
   915         }
       
   916     }
       
   917 
       
   918 // End of file
       
   919