photosgallery/viewframework/medialists/src/glxstaticitemlist.cpp
changeset 0 4e91876724a2
child 20 d1bdfdf534bd
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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 "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:    List of media items
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // my include
       
    22 #include "glxstaticitemlist.h"
       
    23 
       
    24 // system includes
       
    25 #include <glxassert.h>
       
    26 #include <glxtracer.h>
       
    27 
       
    28 // user includes
       
    29 #include "glxitemlist.h"
       
    30 #include "glxmediastaticitemdefs.h"
       
    31 
       
    32 using namespace NGlxListDefs;
       
    33 
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // Destructor
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 CGlxStaticItemList::RStaticMediaArray::~RStaticMediaArray()
       
    40     {
       
    41     TRACER( "CGlxStaticItemList::RStaticMediaArray::~RStaticMediaArray" );
       
    42     
       
    43     // delete owned static items
       
    44     TInt count = Count();
       
    45     for ( TInt i = 0 ; i < count; i++ )
       
    46         {
       
    47         Delete( i );
       
    48         }
       
    49     Close();
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // Delete item at index
       
    54 // -----------------------------------------------------------------------------
       
    55 void CGlxStaticItemList::RStaticMediaArray::Delete( TInt aIndex )
       
    56     {
       
    57     TRACER( "CGlxStaticItemList::RStaticMediaArray::Delete" );
       
    58     
       
    59     delete ( (*this)[ aIndex ] ).Properties();
       
    60     }
       
    61     
       
    62 // -----------------------------------------------------------------------------
       
    63 // CGlxStaticItemList class implementation
       
    64 // -----------------------------------------------------------------------------
       
    65     
       
    66 // -----------------------------------------------------------------------------
       
    67 // Two-phase constructor
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 CGlxStaticItemList* CGlxStaticItemList::NewL( const TGlxIdSpaceId& aIdSpaceId,
       
    71         MGlxItemListObserver& aObserver, MGlxMediaUser& aMediaUser )
       
    72     {
       
    73     TRACER( "CGlxStaticItemList::NewL");
       
    74     CGlxStaticItemList* self = new (ELeave) CGlxStaticItemList( aObserver );
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL( aIdSpaceId, aMediaUser );
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // Constructor
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 CGlxStaticItemList::CGlxStaticItemList( MGlxItemListObserver& aObserver )
       
    86         : iObserver( aObserver )
       
    87     {
       
    88     TRACER( "CGlxStaticItemList::CGlxStaticItemList" );
       
    89     
       
    90     // Enable static items by default
       
    91     iStaticItemsEnabled = ETrue;
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // Second-phase constructor
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void CGlxStaticItemList::ConstructL( const TGlxIdSpaceId& aIdSpaceId,
       
    99         MGlxMediaUser& aMediaUser )
       
   100     {
       
   101     TRACER( "CGlxStaticItemList::ConstructL" );
       
   102     
       
   103     iItemList = CGlxItemList::NewL( aIdSpaceId, *this, aMediaUser );
       
   104     __TEST_INVARIANT;
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // Destructor
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 CGlxStaticItemList::~CGlxStaticItemList()
       
   112     {
       
   113     TRACER( "CGlxStaticItemList::~CGlxStaticItemList" );
       
   114     
       
   115     delete iItemList;
       
   116     // iFrontStaticItems and iRearStaticItems have a destructor that closes them
       
   117     }
       
   118     
       
   119 // -----------------------------------------------------------------------------
       
   120 // return id space id
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 const TGlxIdSpaceId& CGlxStaticItemList::IdSpaceId() const
       
   124     {
       
   125     TRACER( "CGlxStaticItemList::IdSpaceId");
       
   126     return iItemList->IdSpaceId();
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // Synchronise contents of the list with the collection path
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 void CGlxStaticItemList::SetContentsL( const CMPXCollectionPath& aPath, 
       
   134         const MGlxMediaPool& aMediaPool )
       
   135     {
       
   136     TRACER( "CGlxStaticItemList::SetContentsL" );
       
   137     
       
   138     __TEST_INVARIANT;
       
   139     iItemList->SetContentsL( aPath, aMediaPool );
       
   140     __TEST_INVARIANT;
       
   141     }
       
   142     
       
   143 // -----------------------------------------------------------------------------
       
   144 // Remove an item form the list
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 void CGlxStaticItemList::Remove( const TGlxIdSpaceId& aIdSpaceId, 
       
   148         const TGlxMediaId& aItemId )
       
   149     {
       
   150     TRACER( "CGlxStaticItemList::Remove" );
       
   151 
       
   152     __TEST_INVARIANT;
       
   153 
       
   154     if ( aIdSpaceId == KGlxStaticItemIdSpaceId )
       
   155         {
       
   156         DeleteStaticItem( aItemId );
       
   157         }
       
   158     else 
       
   159         {
       
   160         iItemList->Remove( aIdSpaceId, aItemId );
       
   161         }
       
   162     
       
   163     __TEST_INVARIANT;
       
   164     }
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // Remove any pointers to the media object at the specified index
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 void CGlxStaticItemList::RemoveReference( TInt aIndex )
       
   171     {
       
   172     TRACER( "CGlxStaticItemList::RemoveReference" );
       
   173 
       
   174     __ASSERT_DEBUG( aIndex >= iCountCurrentFrontStatic && 
       
   175                     aIndex < iCountCurrentFrontStatic + CountNonStatic(), 
       
   176                     Panic( EGlxPanicIllegalArgument ) );
       
   177 
       
   178     return iItemList->RemoveReference( aIndex - iCountCurrentFrontStatic );
       
   179     }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // Add a static item
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 void CGlxStaticItemList::AddStaticItemL( CGlxMedia* aStaticItem, 
       
   186         TInsertionPosition aTargetPosition )
       
   187     {
       
   188     TRACER( "CGlxStaticItemList::AddStaticItemL" );
       
   189     __TEST_INVARIANT;
       
   190 
       
   191     if ( !aStaticItem )
       
   192         {
       
   193         GLX_LOG_WARNING( "Supplied static item is null" );
       
   194         return;
       
   195         }
       
   196 
       
   197    __ASSERT_DEBUG( aStaticItem->Id() != KGlxIdNone, Panic( EGlxPanicIllegalArgument ) ); // Must have an id defined,
       
   198 
       
   199     // Since ownership is given, it is assumed that this function is free to 
       
   200     // modify the static item
       
   201     SetupStaticItemL( *aStaticItem );
       
   202 
       
   203     // make reservations to arrays so that the object supplied as parameter
       
   204     // can be safely modified. Assumption is that client has pushed aStaticItem
       
   205     // to cleanup stack.
       
   206     // for simplicity, reserve in both static arrays, although only one is needed
       
   207     iRearStaticItems.ReserveL( iRearStaticItems.Count() + 1 ); // Space for one new item
       
   208     iFrontStaticItems.ReserveL( iFrontStaticItems.Count() + 1 ); // Space for one new item
       
   209     
       
   210     // try to replace existing static item with the same id, if any
       
   211     // TryReplaceStaticItem only replaces the item if the item exists
       
   212     // in the same position (list beginning/end) as the new one
       
   213     if ( !TryReplaceStaticItem( *aStaticItem, aTargetPosition ) )
       
   214         {
       
   215         // TryReplaceStaticItem will fail if the item already exists, but in the 
       
   216         // other end of the list (aTargetPosition). Therefore, need to try to
       
   217         // delete the static item, if any.
       
   218         // this call notifies the observer of item being removed
       
   219         DeleteStaticItem( aStaticItem->Id() ); 
       
   220         
       
   221         // add the item to static item list, notified observer if
       
   222         // static items currently active
       
   223         AddStaticItem( *aStaticItem, aTargetPosition );
       
   224         }
       
   225 
       
   226     __TEST_INVARIANT;
       
   227     }
       
   228     
       
   229 // -----------------------------------------------------------------------------
       
   230 // Try to replace and existing static item 
       
   231 // inline private member function only in cpp file, so will be inlined in arm
       
   232 // (ok as long as called only once)
       
   233 // -----------------------------------------------------------------------------
       
   234 //
       
   235 inline TBool CGlxStaticItemList::TryReplaceStaticItem( CGlxMedia& aStaticItem, 
       
   236         TInsertionPosition aTargetPosition )
       
   237     {
       
   238     TRACER( "CGlxStaticItemList::TryReplaceStaticItem" );
       
   239     
       
   240     GLX_ASSERT_DEBUG(aTargetPosition == EInsertFirst || aTargetPosition == EInsertLast, Panic(EGlxPanicLogicError), "Unknown static item target position");
       
   241     
       
   242     if (aTargetPosition == EInsertFirst)
       
   243         {
       
   244         return TryReplaceStaticItem( aStaticItem, iFrontStaticItems );
       
   245         }
       
   246     else 
       
   247         {
       
   248         return TryReplaceStaticItem( aStaticItem, iRearStaticItems );
       
   249         }
       
   250     }
       
   251 
       
   252 // -----------------------------------------------------------------------------
       
   253 // Try to replace and existing static item 
       
   254 // -----------------------------------------------------------------------------
       
   255 //
       
   256 TBool CGlxStaticItemList::TryReplaceStaticItem( CGlxMedia& aStaticItem, 
       
   257         RStaticMediaArray& aStaticItemArray )
       
   258     {
       
   259     TRACER( "CGlxStaticItemList::TryReplaceStaticItem");
       
   260     
       
   261     // try to find a static item with the same id in the array.
       
   262     // if found, replace the original static item with the new one
       
   263     TInt index = Index( aStaticItem.Id(), aStaticItemArray );
       
   264     if ( KErrNotFound != index )
       
   265         {
       
   266         // delete old static itemm does not remove space from array
       
   267         aStaticItemArray.Delete( index );
       
   268         // take ownership of the static item
       
   269         aStaticItemArray[ index ] = TGlxMedia( aStaticItem );
       
   270 
       
   271         GLX_LOG_INFO( "Existing static item replaced" );
       
   272         return ETrue; // replaced
       
   273         }
       
   274     
       
   275     return EFalse; // not replaced
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // Remove static item
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CGlxStaticItemList::DeleteStaticItem( const TGlxMediaId& aId )
       
   283     {
       
   284     TRACER( "CGlxStaticItemList::DeleteStaticItem");
       
   285     
       
   286     // blindly try both arrays, does nothing if item not found
       
   287     DeleteStaticItem( aId, iFrontStaticItems, 0, 
       
   288         iCountCurrentFrontStatic ); 
       
   289     DeleteStaticItem( aId, iRearStaticItems, FirstPostStaticIndex(), 
       
   290         iCountCurrentRearStatic ); 
       
   291     }
       
   292 
       
   293 // -----------------------------------------------------------------------------
       
   294 // Remove static item
       
   295 // -----------------------------------------------------------------------------
       
   296 //
       
   297 void CGlxStaticItemList::DeleteStaticItem( const TGlxMediaId& aId, 
       
   298         RStaticMediaArray& aStaticItemArray, TInt aArrayOffset, 
       
   299         TInt& aCountCurrentStatic )
       
   300     {
       
   301     TRACER( "CGlxStaticItemList::DeleteStaticItem");
       
   302     
       
   303     TInt index = Index( aId, aStaticItemArray );
       
   304     if ( KErrNotFound != index )
       
   305         {
       
   306         // delete old static item, does not remove space from array
       
   307         aStaticItemArray.Delete( index );
       
   308         
       
   309         // remove item from array
       
   310         aStaticItemArray.Remove( index );
       
   311         
       
   312          if ( iStaticItemsEnabled )
       
   313             {
       
   314             // Remove from static item count
       
   315             aCountCurrentStatic--;
       
   316             // notify observer
       
   317             iObserver.HandleItemsRemoved( index + aArrayOffset, 1 );
       
   318             }
       
   319         }
       
   320     }
       
   321 
       
   322 // -----------------------------------------------------------------------------
       
   323 // Add a static item
       
   324 // -----------------------------------------------------------------------------
       
   325 //
       
   326 void CGlxStaticItemList::AddStaticItem( CGlxMedia& aStaticItem, 
       
   327         NGlxListDefs::TInsertionPosition aTargetPosition )
       
   328     {
       
   329     TRACER( "CGlxStaticItemList::AddStaticItem");
       
   330     
       
   331     // add the item to static item list, notified observer if
       
   332     // static items currently active
       
   333     if ( EInsertFirst == aTargetPosition )
       
   334         {
       
   335         AddFrontStaticItem( aStaticItem );
       
   336         }
       
   337     else 
       
   338         {
       
   339         AddRearStaticItem( aStaticItem );
       
   340         }
       
   341     }
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // Add static item to the front of the list
       
   345 // inline private member function only in cpp file, so will be inlined in arm
       
   346 // (ok as long as called only once)
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 inline void CGlxStaticItemList::AddFrontStaticItem( CGlxMedia& aStaticItem )
       
   350     {
       
   351     TRACER( "CGlxStaticItemList::AddFrontStaticItem");
       
   352     
       
   353     // Add to the beginning of front static item array
       
   354     iFrontStaticItems.Insert( TGlxMedia( aStaticItem ), 0 );
       
   355     // ignore return value, since assumes reservation was made to the array 
       
   356     // prior to calling this function, i.e. cannot fail
       
   357 
       
   358     // if static items are currently enabled, add item to the main item list
       
   359     if ( iStaticItemsEnabled )
       
   360         {
       
   361         iCountCurrentFrontStatic++;
       
   362         
       
   363         // notify of item being added 
       
   364         iObserver.HandleItemsAdded( 0, 1 );
       
   365         }
       
   366     }
       
   367 
       
   368 // -----------------------------------------------------------------------------
       
   369 // Add static item to the front of the end of the list
       
   370 // inline private member function only in cpp file, so will be inlined in arm
       
   371 // (ok as long as called only once)
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 inline void CGlxStaticItemList::AddRearStaticItem( CGlxMedia& aStaticItem )
       
   375     {
       
   376     TRACER( "CGlxStaticItemList::AddRearStaticItem");
       
   377     
       
   378     // Add to the end of rear static item array
       
   379     iRearStaticItems.Append( TGlxMedia( aStaticItem ) );
       
   380     // ignore return value, since assumes reservation was made to the array 
       
   381     // prior to calling this function, i.e. cannot fail
       
   382     
       
   383     // if static items are currently enabled, add item to the main item list
       
   384     if ( iStaticItemsEnabled )
       
   385         {
       
   386         iCountCurrentRearStatic++;
       
   387 
       
   388         // notify of item being added 
       
   389         TInt addIndex = CountAll() - 1;
       
   390         iObserver.HandleItemsAdded( addIndex, 1 );
       
   391         }
       
   392     }
       
   393  
       
   394 // -----------------------------------------------------------------------------
       
   395 // Make static item ready to be added to the list
       
   396 // inline private member function only in cpp file, so will be inlined in arm
       
   397 // (ok as long as called only once)
       
   398 // -----------------------------------------------------------------------------
       
   399 //
       
   400 inline void CGlxStaticItemList::SetupStaticItemL( CGlxMedia& aStaticItem )
       
   401     {
       
   402     TRACER( "CGlxStaticItemList::SetupStaticItemL");
       
   403     
       
   404     // add static attribute, so that can later check if this item is static
       
   405     aStaticItem.SetTObjectValueL<TBool>( KGlxMediaStaticItem, ETrue );
       
   406              
       
   407     // set media category attribute to "command", unless already defined by client
       
   408     if( !aStaticItem.IsSupported( KMPXMediaGeneralCategory ) )
       
   409         {
       
   410         aStaticItem.SetTObjectValueL( KMPXMediaGeneralCategory, EMPXCommand );
       
   411         }
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // return ETrue if static items are enabled
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 TBool CGlxStaticItemList::IsStaticItemsEnabled() const
       
   419     {
       
   420     TRACER( "CGlxStaticItemList::IsStaticItemsEnabled");
       
   421     
       
   422     return iStaticItemsEnabled;
       
   423     }
       
   424         
       
   425 // -----------------------------------------------------------------------------
       
   426 // Enable/disable static items
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 void CGlxStaticItemList::SetStaticItemsEnabled( TBool aEnabled )
       
   430     {
       
   431     TRACER( "CGlxStaticItemList::SetStaticItemsEnabled");
       
   432     GLX_LOG_INFO1( "CGlxStaticItemList::SetStaticItemsEnabled: %b", aEnabled );
       
   433     __TEST_INVARIANT;
       
   434 
       
   435     iStaticItemsEnabled = aEnabled;
       
   436     if ( aEnabled )
       
   437         {
       
   438         EnableFrontStaticItems();
       
   439         EnableRearStaticItems(); 
       
   440         }
       
   441     else
       
   442         {
       
   443         DisableFrontStaticItems();
       
   444         DisableRearStaticItems(); 
       
   445         }
       
   446     
       
   447     __TEST_INVARIANT;
       
   448     }
       
   449 
       
   450 // -----------------------------------------------------------------------------
       
   451 // Enable front static items
       
   452 // inline private member function only in cpp file, so will be inlined in arm
       
   453 // (ok as long as called only once)
       
   454 // -----------------------------------------------------------------------------
       
   455 //
       
   456 inline void CGlxStaticItemList::EnableFrontStaticItems()
       
   457     {
       
   458     TRACER( "CGlxStaticItemList::EnableFrontStaticItems");
       
   459     
       
   460     // Notify only if current static item count is zero and there is more than
       
   461     // one fron static item
       
   462     if ( iCountCurrentFrontStatic < iFrontStaticItems.Count() )
       
   463         {
       
   464         // Add front items and notify observer
       
   465         iCountCurrentFrontStatic = iFrontStaticItems.Count();
       
   466         iObserver.HandleItemsAdded( 0, iCountCurrentFrontStatic );
       
   467         }
       
   468     }
       
   469     
       
   470 // -----------------------------------------------------------------------------
       
   471 // Enable rear static items
       
   472 // inline private member function only in cpp file, so will be inlined in arm
       
   473 // (ok as long as called only once)
       
   474 // -----------------------------------------------------------------------------
       
   475 //
       
   476 inline void CGlxStaticItemList::EnableRearStaticItems()
       
   477     {
       
   478     TRACER( "CGlxStaticItemList::EnableRearStaticItems");
       
   479     
       
   480     // Notify only if current static item count is zero and there is more than
       
   481     // one fron static item
       
   482     if ( iCountCurrentRearStatic < iRearStaticItems.Count() )
       
   483         {
       
   484         // Add rear items and notify observer
       
   485         iCountCurrentRearStatic = iRearStaticItems.Count();
       
   486         iObserver.HandleItemsAdded( FirstPostStaticIndex(), 
       
   487             iCountCurrentRearStatic );
       
   488         }
       
   489     }
       
   490 
       
   491 // -----------------------------------------------------------------------------
       
   492 // Disable static items from the front
       
   493 // inline private member function only in cpp file, so will be inlined in arm
       
   494 // (ok as long as called only once)
       
   495 // -----------------------------------------------------------------------------
       
   496 //
       
   497 inline void CGlxStaticItemList::DisableFrontStaticItems()
       
   498     {
       
   499     TRACER( "CGlxStaticItemList::DisableFrontStaticItems");
       
   500     
       
   501     // Remove static items from front
       
   502     if ( iCountCurrentFrontStatic > 0 )
       
   503         {
       
   504         TInt removedCount = iCountCurrentFrontStatic;
       
   505         iCountCurrentFrontStatic = 0;
       
   506 
       
   507         // Notify observer
       
   508         iObserver.HandleItemsRemoved( 0, removedCount );
       
   509         }
       
   510     }
       
   511     
       
   512 // -----------------------------------------------------------------------------
       
   513 // Enable static items from the front
       
   514 // inline private member function only in cpp file, so will be inlined in arm
       
   515 // (ok as long as called only once)
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 inline void CGlxStaticItemList::DisableRearStaticItems()
       
   519     {
       
   520     TRACER( "CGlxStaticItemList::DisableRearStaticItems");
       
   521     
       
   522     // Remove static items from rear
       
   523     if ( iCountCurrentRearStatic > 0 )
       
   524         {
       
   525         TInt removedCount = iCountCurrentRearStatic;
       
   526         iCountCurrentRearStatic = 0;
       
   527 
       
   528         // Notify observer
       
   529         iObserver.HandleItemsRemoved( FirstPostStaticIndex(), removedCount );
       
   530         }
       
   531     }
       
   532     
       
   533 // -----------------------------------------------------------------------------
       
   534 // Return count
       
   535 // -----------------------------------------------------------------------------
       
   536 //
       
   537 TInt CGlxStaticItemList::Count( NGlxListDefs::TCountType aType ) const
       
   538     {
       
   539     TRACER( "CGlxStaticItemList::Count");
       
   540     
       
   541     switch ( aType )  
       
   542         {        
       
   543         case ECountAllStatic:
       
   544             return CountStatic();
       
   545             
       
   546         case ECountPreStatic:
       
   547             return iCountCurrentFrontStatic;
       
   548             
       
   549         case ECountPostStatic:
       
   550             return iCountCurrentRearStatic;  
       
   551          
       
   552         case ECountNonStatic:
       
   553             return CountNonStatic();
       
   554             
       
   555         default:
       
   556             GLX_LOG_WARNING( "Unsupported count type" );
       
   557             // Fall through, and return all count as default
       
   558         case ECountAll:                                     
       
   559             return CountAll();
       
   560         }
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // Return count of all items
       
   565 // inline private member function only in cpp file, so will be inlined in arm
       
   566 // -----------------------------------------------------------------------------
       
   567 //
       
   568 inline TInt CGlxStaticItemList::CountStatic() const
       
   569     {
       
   570     TRACER( "CGlxStaticItemList::CountStatic");
       
   571     
       
   572     return iCountCurrentFrontStatic + iCountCurrentRearStatic;
       
   573     }
       
   574 
       
   575 // -----------------------------------------------------------------------------
       
   576 // Return count of non-static items
       
   577 // inline private member function only in cpp file, so will be inlined in arm
       
   578 // -----------------------------------------------------------------------------
       
   579 //
       
   580 inline TInt CGlxStaticItemList::CountNonStatic() const
       
   581     {
       
   582     TRACER( "CGlxStaticItemList::CountNonStatic");
       
   583     
       
   584     return iItemList->Count(); 
       
   585     }
       
   586 
       
   587 // -----------------------------------------------------------------------------
       
   588 // Return count of all items
       
   589 // inline private member function only in cpp file, so will be inlined in arm
       
   590 // -----------------------------------------------------------------------------
       
   591 //
       
   592 inline TInt CGlxStaticItemList::CountAll() const
       
   593     {
       
   594     TRACER( "CGlxStaticItemList::CountAll");
       
   595     
       
   596     return iCountCurrentFrontStatic + iItemList->Count() + iCountCurrentRearStatic;
       
   597     }
       
   598     
       
   599 // -----------------------------------------------------------------------------
       
   600 // Index of the first post static item
       
   601 // -----------------------------------------------------------------------------
       
   602 //
       
   603 TInt CGlxStaticItemList::FirstPostStaticIndex() const
       
   604     {
       
   605     TRACER( "CGlxStaticItemList::FirstPostStaticIndex");
       
   606     
       
   607     return iCountCurrentFrontStatic + iItemList->Count();
       
   608     }
       
   609     
       
   610 // -----------------------------------------------------------------------------
       
   611 // Return item by index
       
   612 // -----------------------------------------------------------------------------
       
   613 //
       
   614 TGlxMedia& CGlxStaticItemList::Item( TInt aIndex )
       
   615     {
       
   616     TRACER( "CGlxStaticItemList::Item");
       
   617     
       
   618     // test if a front static index
       
   619     if ( aIndex < iCountCurrentFrontStatic )
       
   620         {
       
   621         return iFrontStaticItems[ aIndex ];
       
   622         }
       
   623     
       
   624     // test if normal index
       
   625     if ( aIndex < iCountCurrentFrontStatic + CountNonStatic() )
       
   626         {
       
   627         return iItemList->Item( aIndex - iCountCurrentFrontStatic );
       
   628        }
       
   629         
       
   630     // must be a rear static index
       
   631     return iRearStaticItems[ aIndex - iCountCurrentFrontStatic - CountNonStatic() ];
       
   632     }
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 // Return index by id
       
   636 // -----------------------------------------------------------------------------
       
   637 //
       
   638 TInt CGlxStaticItemList::Index( const TGlxIdSpaceId& aIdSpaceId, 
       
   639         const TGlxMediaId& aId ) const
       
   640     {
       
   641     TRACER( "CGlxStaticItemList::Index");
       
   642     
       
   643     if ( KGlxStaticItemIdSpaceId == aIdSpaceId.Value() )
       
   644         {
       
   645         // try to find from front static items; may return KErrNotFound
       
   646         TInt index = Index( aId, iFrontStaticItems );
       
   647         if ( KErrNotFound != index )
       
   648             {
       
   649             return index;
       
   650             }
       
   651 
       
   652         // Try rear static items
       
   653         index = Index( aId, iRearStaticItems );
       
   654         if ( KErrNotFound != index )
       
   655             {
       
   656             return index + FirstPostStaticIndex();
       
   657             }
       
   658         }
       
   659     else
       
   660         {
       
   661         // Look at the main list first (most likely case)
       
   662         TInt index = iItemList->Index( aIdSpaceId, aId );
       
   663         if ( KErrNotFound != index )
       
   664             {
       
   665             return index + iCountCurrentFrontStatic;
       
   666             }
       
   667         }
       
   668         
       
   669     // No such id
       
   670     return KErrNotFound;
       
   671     }
       
   672 
       
   673 // -----------------------------------------------------------------------------
       
   674 // Return index by id
       
   675 // -----------------------------------------------------------------------------
       
   676 //
       
   677 TInt CGlxStaticItemList::Index( const TGlxMediaId& aId, 
       
   678         const RStaticMediaArray& aStaticItems ) const
       
   679     {
       
   680     TRACER( "CGlxStaticItemList::Index");
       
   681     
       
   682     // set up comparison functor
       
   683     TIdentityRelation< TGlxMedia > match ( &TGlxMedia::MatchById );
       
   684     // create dummy object to compare against
       
   685     // Create to stack directly, CMedia constructor NULLs all member variables
       
   686     TGlxMedia mediaToCompare( aId ); 
       
   687 
       
   688     return aStaticItems.Find( mediaToCompare, match );
       
   689     }
       
   690 
       
   691 // -----------------------------------------------------------------------------
       
   692 // Handle items being added
       
   693 // -----------------------------------------------------------------------------
       
   694 //
       
   695 void CGlxStaticItemList::HandleItemsAdded( TInt aFirstInsertedIndex, 
       
   696         TInt aCount )
       
   697     {
       
   698     TRACER( "CGlxStaticItemList::HandleItemsAdded");
       
   699     
       
   700     // there may be static items at the front of the list, so adjust and forward
       
   701     // to observer
       
   702     iObserver.HandleItemsAdded( aFirstInsertedIndex + iCountCurrentFrontStatic,
       
   703         aCount );
       
   704     }
       
   705 
       
   706 // -----------------------------------------------------------------------------
       
   707 // Handle items being removed
       
   708 // -----------------------------------------------------------------------------
       
   709 //
       
   710 void CGlxStaticItemList::HandleItemsRemoved( TInt aRemovedFromIndex, TInt aCount )  
       
   711     {
       
   712     TRACER( "CGlxStaticItemList::HandleItemsRemoved");
       
   713     
       
   714     // there may be static items at the front of the list, so adjust and forward
       
   715     // to observer
       
   716     iObserver.HandleItemsRemoved( aRemovedFromIndex + iCountCurrentFrontStatic,
       
   717         aCount );
       
   718     }
       
   719     
       
   720 // ---------------------------------------------------------------------------
       
   721 // Test invariant
       
   722 // ---------------------------------------------------------------------------
       
   723 void CGlxStaticItemList::__DbgTestInvariant() const
       
   724     {
       
   725     TRACER( "CGlxStaticItemList::__DbgTestInvariant");
       
   726     
       
   727     #ifdef _DEBUG
       
   728     
       
   729     __ASSERT_DEBUG( &iObserver, Panic( EGlxPanicIllegalState ) ); // Null observer
       
   730     __ASSERT_DEBUG( iItemList, Panic( EGlxPanicIllegalState ) ); // No list
       
   731 
       
   732     // Make sure static item counts are zero when static items are disabled
       
   733     __ASSERT_DEBUG( ( iCountCurrentFrontStatic == 0 && iCountCurrentRearStatic == 0 )
       
   734          || iStaticItemsEnabled, Panic( EGlxPanicIllegalState ) ); // No list
       
   735    
       
   736     // Make sure static item counts are match array counts when static items are enabled
       
   737     __ASSERT_DEBUG( ( iCountCurrentFrontStatic == iFrontStaticItems.Count() 
       
   738          && iCountCurrentRearStatic == iRearStaticItems.Count() )
       
   739          || !iStaticItemsEnabled, Panic( EGlxPanicIllegalState ) ); // No list
       
   740 
       
   741     #endif // _DEBUG
       
   742     }