videocollection/hgmyvideos/src/vcxhgmyvideosvideolist.cpp
branchRCL_3
changeset 57 befca0ec475f
equal deleted inserted replaced
56:839377eedc2b 57:befca0ec475f
       
     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:      Class for providing video list.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <collate.h>
       
    22 #include <mpxmedia.h>
       
    23 #include <mpxmediaarray.h>
       
    24 #include <mpxmediageneraldefs.h>
       
    25 #include "vcxhgmyvideosvideolist.h"
       
    26 #include "vcxhgmyvideosvideolistitem.h"
       
    27 #include "IptvDebug.h"
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // CVcxHgMyVideosVideoList::NewL()
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CVcxHgMyVideosVideoList* CVcxHgMyVideosVideoList::NewL()
       
    36     {
       
    37     CVcxHgMyVideosVideoList* self = 
       
    38         CVcxHgMyVideosVideoList::NewLC();
       
    39     CleanupStack::Pop( self );
       
    40     return self;
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CVcxHgMyVideosVideoList::NewLC()
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CVcxHgMyVideosVideoList* CVcxHgMyVideosVideoList::NewLC()
       
    48     {
       
    49     CVcxHgMyVideosVideoList* self = 
       
    50         new (ELeave) CVcxHgMyVideosVideoList();
       
    51     CleanupStack::PushL( self );
       
    52     return self;
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CVcxHgMyVideosVideoList::CVcxHgMyVideosVideoList()
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CVcxHgMyVideosVideoList::CVcxHgMyVideosVideoList()
       
    60     {
       
    61     // No implementation required.
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CVcxHgMyVideosVideoList::~CVcxHgMyVideosVideoList()
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 CVcxHgMyVideosVideoList::~CVcxHgMyVideosVideoList()
       
    69     {
       
    70     RemoveVideoList();
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CVcxHgMyVideosVideoList::RemoveVideoList()
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CVcxHgMyVideosVideoList::RemoveVideoList()
       
    78     {
       
    79     iVideoList.ResetAndDestroy();
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CVcxHgMyVideosVideoList::ReplaceVideoListL()
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void CVcxHgMyVideosVideoList::ReplaceVideoListL( CMPXMediaArray& aVideoList )
       
    87     {
       
    88     IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # CVcxHgMyVideosVideoList::ReplaceVideoListL() - Enter" );
       
    89     
       
    90     // Removes the all videos from array.
       
    91     RemoveVideoList();
       
    92            
       
    93     TInt count = aVideoList.Count();
       
    94     iVideoList.ReserveL( count );
       
    95     for ( TInt i = 0; i < count; i++ )
       
    96         {
       
    97         CMPXMedia* media = CMPXMedia::NewL( *( aVideoList[i] ) ); 
       
    98         if ( media )
       
    99             {
       
   100             CVcxHgMyVideosVideoListItem* item = CVcxHgMyVideosVideoListItem::NewLC( media );
       
   101             iVideoList.AppendL( item );
       
   102             CleanupStack::Pop( item );
       
   103             }
       
   104         }        
       
   105     IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # CVcxHgMyVideosVideoList::ReplaceVideoListL() - Exit" );
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // 
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 TBool CVcxHgMyVideosVideoList::HasSameItemsL( const CMPXMediaArray& aVideoList )
       
   113     {
       
   114     TInt count( iVideoList.Count() );
       
   115     if ( aVideoList.Count() != count || count == 0 )
       
   116         {
       
   117         return EFalse;
       
   118         }
       
   119 
       
   120     TBool isSame( ETrue );
       
   121     CMPXMedia* oldMedia = NULL;
       
   122     CMPXMedia* newMedia = NULL;
       
   123     for ( TInt i = 0; i < count; i++ )
       
   124         {
       
   125         oldMedia = iVideoList[i]->Media();
       
   126         newMedia = aVideoList[i];
       
   127         if ( oldMedia && oldMedia->IsSupported( KMPXMediaGeneralId )
       
   128                 && newMedia && newMedia->IsSupported( KMPXMediaGeneralId ) )
       
   129             {
       
   130             if ( oldMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) != 
       
   131                     newMedia->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) )
       
   132                 {
       
   133                 isSame = EFalse;
       
   134                 break;
       
   135                 }
       
   136             }
       
   137         }
       
   138     return isSame;
       
   139     }
       
   140 
       
   141 // -----------------------------------------------------------------------------
       
   142 // CVcxHgMyVideosVideoList::VideoCount()
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 TInt CVcxHgMyVideosVideoList::VideoCount()
       
   146     {
       
   147     return iVideoList.Count();
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // CVcxHgMyVideosVideoList::RemoveVideo()
       
   152 // -----------------------------------------------------------------------------
       
   153 //
       
   154 TInt CVcxHgMyVideosVideoList::RemoveVideo( TMPXItemId aMpxItemId )
       
   155     {
       
   156     TInt index = IndexByMPXItemId( aMpxItemId );
       
   157     
       
   158     if ( index != KErrNotFound )
       
   159         {
       
   160         delete iVideoList[index];
       
   161         iVideoList.Remove( index );
       
   162         }
       
   163     return index;
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CVcxHgMyVideosVideoList::MPXMedia()
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 CMPXMedia* CVcxHgMyVideosVideoList::MPXMedia( TInt aIndex )
       
   171     {
       
   172     if ( aIndex >= 0 && aIndex < iVideoList.Count() )
       
   173         {
       
   174         return iVideoList[aIndex]->Media();
       
   175         }
       
   176     return NULL;
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // CVcxHgMyVideosVideoList::MPXMediaByUri()
       
   181 // -----------------------------------------------------------------------------
       
   182 //
       
   183 CMPXMedia* CVcxHgMyVideosVideoList::MPXMediaByUri( const TDesC& aUri )
       
   184     {
       
   185     CMPXMedia* media = NULL;
       
   186     TInt count( iVideoList.Count() );
       
   187     
       
   188     for ( TInt i = 0; i < count; i++ )
       
   189         {
       
   190         media = iVideoList[i]->Media();
       
   191             
       
   192         if ( media && media->IsSupported( KMPXMediaGeneralUri ) )
       
   193             {
       
   194             if ( aUri.CompareF( media->ValueText( KMPXMediaGeneralUri ) ) == 0 )
       
   195                 {
       
   196                 return media;
       
   197                 }
       
   198             }
       
   199         }
       
   200     return NULL;
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CVcxHgMyVideosVideoList::MPXMediaByMPXItemId()
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 CMPXMedia* CVcxHgMyVideosVideoList::MPXMediaByMPXItemId( TMPXItemId aMpxItemId )
       
   208     {
       
   209     CMPXMedia* media = NULL;
       
   210     TInt count( iVideoList.Count() );
       
   211     
       
   212     for ( TInt i = 0; i < count; i++ )
       
   213         {
       
   214         media = iVideoList[i]->Media();
       
   215 
       
   216         if ( media && media->IsSupported( KMPXMediaGeneralId ) )
       
   217             {         
       
   218             if ( aMpxItemId == media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) )
       
   219                 {
       
   220                 return media;
       
   221                 }
       
   222             }
       
   223         }        
       
   224     return NULL;
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CVcxHgMyVideosVideoList::ArrayIndexToMpxItemIdL()
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 TMPXItemId CVcxHgMyVideosVideoList::ArrayIndexToMpxItemIdL( TInt aArrayIndex )
       
   232     {
       
   233     if ( aArrayIndex < 0 || aArrayIndex >= iVideoList.Count() )
       
   234         {
       
   235         User::Leave( KErrArgument );
       
   236         }
       
   237 
       
   238     return iVideoList[aArrayIndex]->Media()->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId );
       
   239     }
       
   240 
       
   241 // -----------------------------------------------------------------------------
       
   242 // CVcxHgMyVideosVideoList::IndexByMPXItemId()
       
   243 // -----------------------------------------------------------------------------
       
   244 //
       
   245 TInt CVcxHgMyVideosVideoList::IndexByMPXItemId( TMPXItemId aMpxItemId )
       
   246     {
       
   247     CMPXMedia* media = NULL;
       
   248     TInt count( iVideoList.Count() );
       
   249     
       
   250     for ( TInt i = 0; i < count; i++ )
       
   251         {
       
   252         media = iVideoList[i]->Media();
       
   253 
       
   254         if ( media && media->IsSupported( KMPXMediaGeneralId ) )
       
   255             {           
       
   256             if ( aMpxItemId == media->ValueTObjectL<TMPXItemId>( KMPXMediaGeneralId ) )
       
   257                 {
       
   258                 return i;
       
   259                 }
       
   260             }
       
   261         }        
       
   262     return KErrNotFound;
       
   263     }
       
   264 
       
   265 // ----------------------------------------------------------------------------
       
   266 // CVcxHgMyVideosVideoList::AddToCorrectPlaceL()
       
   267 // ----------------------------------------------------------------------------
       
   268 //
       
   269 void CVcxHgMyVideosVideoList::AddToCorrectPlaceL( CMPXMedia* aVideo,
       
   270         TVcxMyVideosSortingOrder aSortingOrder )
       
   271     {
       
   272     IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # CVcxHgMyVideosVideoList::AddToCorrectPlaceL() - Enter" );
       
   273     
       
   274     if ( aVideo )
       
   275         {        
       
   276         // Ownership of aVideo is transferred.
       
   277         CVcxHgMyVideosVideoListItem* video = CVcxHgMyVideosVideoListItem::NewL( aVideo );
       
   278         CleanupStack::PushL( video );
       
   279 		
       
   280 		TLinearOrder<CVcxHgMyVideosVideoListItem> sortOrder( 
       
   281             CVcxHgMyVideosVideoListItem::CompareByDate ); 
       
   282             
       
   283         switch( aSortingOrder )
       
   284             {
       
   285             case EVcxMyVideosSortingName:
       
   286                 {
       
   287                 sortOrder = CVcxHgMyVideosVideoListItem::CompareByName;
       
   288                 }
       
   289                 break;
       
   290                 
       
   291             case EVcxMyVideosSortingSize:
       
   292                 {
       
   293                 sortOrder = CVcxHgMyVideosVideoListItem::CompareBySize;
       
   294                 }
       
   295                 break;
       
   296                 
       
   297             case EVcxMyVideosSortingCreationDate:
       
   298                 {
       
   299                 sortOrder = CVcxHgMyVideosVideoListItem::CompareByDate;
       
   300                 }
       
   301                 break;
       
   302                 
       
   303             case EVcxMyVideosSortingModified:
       
   304             case EVcxMyVideosSortingId:
       
   305             default:
       
   306                 {
       
   307                 CleanupStack::PopAndDestroy( video );
       
   308                 IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # CVcxHgMyVideosVideoList::AddToCorrectPlaceL() - LEAVE: Invalid sort order" );
       
   309                 User::Leave( KErrNotSupported );
       
   310                 }
       
   311                 break;
       
   312             }
       
   313                 
       
   314         // Ownership of video is transferred.
       
   315         iVideoList.InsertInOrderAllowRepeatsL( video, sortOrder );
       
   316         
       
   317         CleanupStack::Pop( video );
       
   318         }
       
   319     
       
   320     IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # CVcxHgMyVideosVideoList::AddToCorrectPlaceL() - Exit" );
       
   321     }
       
   322 
       
   323 // -----------------------------------------------------------------------------
       
   324 // CVcxHgMyVideosVideoList::ResortVideoListL()
       
   325 // -----------------------------------------------------------------------------
       
   326 //
       
   327 void CVcxHgMyVideosVideoList::ResortVideoListL( const TVcxMyVideosSortingOrder& aSortingOrder )
       
   328     {    
       
   329     IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # CVcxHgMyVideosVideoList::ResortVideoListL() - Enter" );
       
   330     
       
   331     TLinearOrder<CVcxHgMyVideosVideoListItem> sortOrder( 
       
   332         CVcxHgMyVideosVideoListItem::CompareByDate );
       
   333     
       
   334     switch ( aSortingOrder )
       
   335         {
       
   336         case EVcxMyVideosSortingName:
       
   337             {
       
   338             sortOrder = CVcxHgMyVideosVideoListItem::CompareByName;
       
   339             }
       
   340             break;
       
   341             
       
   342         case EVcxMyVideosSortingSize:
       
   343             {
       
   344             sortOrder = CVcxHgMyVideosVideoListItem::CompareBySize;
       
   345             }
       
   346             break;
       
   347             
       
   348         case EVcxMyVideosSortingCreationDate:
       
   349             {
       
   350             sortOrder = CVcxHgMyVideosVideoListItem::CompareByDate;
       
   351             }
       
   352             break;
       
   353             
       
   354         case EVcxMyVideosSortingModified:
       
   355         case EVcxMyVideosSortingId:
       
   356         default:
       
   357             {
       
   358             IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # CVcxHgMyVideosVideoList::ResortVideoListL() - LEAVE: Invalid sort order" );
       
   359             User::Leave( KErrNotSupported );
       
   360             }
       
   361             break;
       
   362         }
       
   363     iVideoList.Sort( sortOrder );   
       
   364     IPTVLOGSTRING_LOW_LEVEL( "MPX My Videos UI # CVcxHgMyVideosVideoList::ResortVideoListL() - Exit" );
       
   365     }