ui/uiengine/medialists/src/glxmedialist.cpp
changeset 23 74c9f037fd5d
child 26 c499df2dbb33
equal deleted inserted replaced
5:f7f0874bfe7d 23:74c9f037fd5d
       
     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 #include "glxmedialist.h"
       
    22 
       
    23 #include <glxcollectionplugintype.hrh>
       
    24 
       
    25 #include <glxassert.h>
       
    26 #include <glxcollectiongeneraldefs.h>
       
    27 #include <glxerrorposter.h>
       
    28 #include <mpxcollectionmessage.h>
       
    29 #include <mpxcollectionmessagedefs.h>
       
    30 #include <mpxcollectionutility.h>
       
    31 #include <mpxcommandgeneraldefs.h>
       
    32 #include <mpxmessagegeneraldefs.h>
       
    33 #include <glxtracer.h>
       
    34 #include <glxlog.h>
       
    35 #include "glxcachemanager.h"
       
    36 #include "glxmedialistarray.h"
       
    37 #include "glxnavigablelist.h"
       
    38 #include "mglxfetchcontext.h"
       
    39 #include "mglxmedialistobserver.h"
       
    40 #include "glxmediastaticitemdefs.h"
       
    41 
       
    42 namespace NGlxMediaList
       
    43     {
       
    44     /**
       
    45      * Interface to notify observers. Allows different notifications to use
       
    46      * the same (complicated) iteration loop
       
    47      */
       
    48     class TNotificationStrategy 
       
    49         {
       
    50         public:
       
    51             TNotificationStrategy( MGlxMediaList& aList )
       
    52                     : iList( aList )
       
    53                 {
       
    54                 }
       
    55                 
       
    56             /** 
       
    57              * Notify observer
       
    58              * @param aObserver Observer to notify 
       
    59              */
       
    60             virtual void NotifyL( MGlxMediaListObserver& aObserver ) = 0;
       
    61         
       
    62         protected:
       
    63             MGlxMediaList& iList;
       
    64         };
       
    65 
       
    66     /**
       
    67      * Notification strategy for items being added
       
    68      */
       
    69     class TItemsAddedNotificationStrategy : public TNotificationStrategy 
       
    70         {
       
    71         public:
       
    72             /**
       
    73              * Constructor 
       
    74              * @param aFirstAddedIndex Index of the first item added
       
    75              * @param aCount number of items added
       
    76              * @param aList Media list that sends the notification
       
    77              */
       
    78             TItemsAddedNotificationStrategy( TInt aFirstAddedIndex, 
       
    79                 TInt aCount, MGlxMediaList& aList )
       
    80                     : TNotificationStrategy( aList )
       
    81                 {
       
    82                 iFirstAddedIndex = aFirstAddedIndex;
       
    83                 iLastAddedIndex = aFirstAddedIndex + aCount - 1;
       
    84                 }
       
    85                 
       
    86             // From MGlxNotificationStrategy
       
    87             void NotifyL( MGlxMediaListObserver& aObserver )
       
    88                 {
       
    89                 aObserver.HandleItemAddedL( iFirstAddedIndex, iLastAddedIndex, 
       
    90                     &iList );
       
    91                 }        
       
    92                 
       
    93         private:
       
    94             /// Index of the first item added
       
    95             TInt iFirstAddedIndex;
       
    96             /// Index of the last item added
       
    97             TInt iLastAddedIndex;
       
    98         };
       
    99 
       
   100     /**
       
   101      * Notification strategy for items being removed
       
   102      */
       
   103     class TItemsRemovedNotificationStrategy : public TNotificationStrategy 
       
   104         {
       
   105         public:
       
   106             /**
       
   107              * Constructor 
       
   108              * @param aFirstRemovedIndex Index of the first item removed
       
   109              * @param aCount number of items removed
       
   110              * @param aList Media list that sends the notification
       
   111              */
       
   112             TItemsRemovedNotificationStrategy( TInt aFirstRemovedIndex, 
       
   113                 TInt aCount, MGlxMediaList& aList )
       
   114                     : TNotificationStrategy( aList )
       
   115                 {
       
   116                 iFirstRemovedIndex = aFirstRemovedIndex;
       
   117                 iLastRemovedIndex = aFirstRemovedIndex + aCount - 1;
       
   118                 }
       
   119                 
       
   120             // From MGlxNotificationStrategy
       
   121             void NotifyL( MGlxMediaListObserver& aObserver )
       
   122                 {
       
   123                 aObserver.HandleItemRemovedL( iFirstRemovedIndex, 
       
   124                     iLastRemovedIndex, &iList );
       
   125                 }        
       
   126                 
       
   127         private:
       
   128             /// Index of the first item removed
       
   129             TInt iFirstRemovedIndex;
       
   130             /// Index of the last item removed
       
   131             TInt iLastRemovedIndex;
       
   132         };
       
   133 
       
   134     /**
       
   135      * Notification strategy for focus being changed
       
   136      */
       
   137     class TFocusChangedNotificationStrategy : public TNotificationStrategy 
       
   138         {
       
   139         public:
       
   140             /**
       
   141              * Constructor 
       
   142              * @param aFirstRemovedIndex Index of the first item removed
       
   143              * @param aCount number of items removed
       
   144              * @param aList Media list that sends the notification
       
   145              */
       
   146             TFocusChangedNotificationStrategy( NGlxListDefs::TFocusChangeType aType, 
       
   147                 TInt aNewIndex, TInt aOldIndex, MGlxMediaList& aList )
       
   148                     : TNotificationStrategy( aList )
       
   149                 {
       
   150                 iType = aType;
       
   151                 iNewIndex = aNewIndex;
       
   152                 iOldIndex = aOldIndex;
       
   153                 }
       
   154                 
       
   155             // From MGlxNotificationStrategy
       
   156             void NotifyL( MGlxMediaListObserver& aObserver )
       
   157                 {
       
   158                 aObserver.HandleFocusChangedL( iType, iNewIndex, iOldIndex, &iList );
       
   159                 }        
       
   160                 
       
   161         private:
       
   162             /// Focus change type
       
   163             NGlxListDefs::TFocusChangeType iType;
       
   164             /// New focus index
       
   165             TInt iNewIndex;
       
   166             /// Old focus index
       
   167             TInt iOldIndex;
       
   168         };
       
   169 
       
   170     /**
       
   171      * Notification strategy for selection being changed
       
   172      */
       
   173     class TItemSelectedNotificationStrategy : public TNotificationStrategy 
       
   174         {
       
   175         public:
       
   176             /**
       
   177              * Constructor 
       
   178              * @param aIndex Index of item being selected/deselected
       
   179              * @param aSelected Selection/deselection info
       
   180              * @param aList Media list that sends the notification
       
   181              */
       
   182             TItemSelectedNotificationStrategy( TInt aIndex, TBool aSelected,
       
   183                 MGlxMediaList& aList )
       
   184                     : TNotificationStrategy( aList )
       
   185                 {
       
   186                 iIndex = aIndex;
       
   187                 iSelected = aSelected;
       
   188                 }
       
   189                 
       
   190             // From MGlxNotificationStrategy
       
   191             void NotifyL( MGlxMediaListObserver& aObserver )
       
   192                 {
       
   193                 aObserver.HandleItemSelectedL( iIndex, iSelected, &iList );
       
   194                 }        
       
   195                 
       
   196         private:
       
   197             /// Index of item being selected/deselected
       
   198             TInt iIndex;
       
   199             /// Selection/deselection info
       
   200             TBool iSelected;
       
   201         };    
       
   202 
       
   203     /**
       
   204      * Notification strategy for command being completed
       
   205      */
       
   206     class TCommandCompletedNotificationStrategy : public TNotificationStrategy 
       
   207         {
       
   208         public:
       
   209             /**
       
   210              * Constructor 
       
   211              * @param aSessionId Session id of client that issued the command
       
   212              * @param aCommand Command which was completed
       
   213              * @param aError Error code from execution of the command
       
   214              * @param aList Media list that sends the notification
       
   215              */
       
   216             TCommandCompletedNotificationStrategy( TAny* aSessionId, 
       
   217                 CMPXCommand* aCommand, TInt aError, MGlxMediaList& aList )
       
   218                     : TNotificationStrategy( aList )
       
   219                 {
       
   220                 iSessionId = aSessionId;
       
   221                 iCommand = aCommand;
       
   222                 iError = aError;
       
   223                 }
       
   224                 
       
   225             // From MGlxNotificationStrategy
       
   226             void NotifyL( MGlxMediaListObserver& aObserver )
       
   227                 {
       
   228                 /// @todo: make this call leaving
       
   229                 aObserver.HandleCommandCompleteL( iSessionId, iCommand, iError, &iList );
       
   230                 }        
       
   231 
       
   232         private:
       
   233             /// Session id of client that issued the command
       
   234             TAny* iSessionId;
       
   235             /// Command which was completed
       
   236             CMPXCommand* iCommand;
       
   237             /// Error code 
       
   238             TBool iError;
       
   239         };            
       
   240         
       
   241         
       
   242 
       
   243     /**
       
   244      * Notification strategy for list population
       
   245      */
       
   246     class TListPopulatedNotificationStrategy : public TNotificationStrategy 
       
   247         {
       
   248         public:
       
   249             /**
       
   250              * Constructor 
       
   251              * @param aList Media list that sends the notification
       
   252              */
       
   253             TListPopulatedNotificationStrategy ( MGlxMediaList& aList )
       
   254                     : TNotificationStrategy( aList )
       
   255                 {
       
   256                 }
       
   257                 
       
   258             // From MGlxNotificationStrategy
       
   259             void NotifyL( MGlxMediaListObserver& aObserver )
       
   260                 {
       
   261                 aObserver.HandlePopulatedL( &iList );
       
   262                 }        
       
   263         }; 
       
   264 
       
   265     /**
       
   266      * Notification strategy for messages
       
   267      */
       
   268     class TMessageNotificationStrategy : public TNotificationStrategy
       
   269         {
       
   270         public:
       
   271             /**
       
   272              * Constructor
       
   273              * @param aList Media list that sends the notification
       
   274              */
       
   275             TMessageNotificationStrategy ( const CMPXMessage& aMessage, MGlxMediaList& aList ) :
       
   276                     TNotificationStrategy( aList ),
       
   277                     iMessage( aMessage )
       
   278                 {
       
   279                 }
       
   280 
       
   281             // From MGlxNotificationStrategy
       
   282             void NotifyL( MGlxMediaListObserver& aObserver )
       
   283                 {
       
   284                 aObserver.HandleMessageL( iMessage, &iList );
       
   285                 }
       
   286 
       
   287         private:
       
   288             /// Message which was received
       
   289             const CMPXMessage& iMessage;
       
   290         };
       
   291     } // namespace NGlxMediaList
       
   292     
       
   293 using namespace NGlxMediaList;
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // Returns a new/existing media list interface
       
   297 // -----------------------------------------------------------------------------
       
   298 CGlxMediaList* CGlxMediaList::InstanceL(const CMPXCollectionPath& aPath, 
       
   299         const TGlxHierarchyId& aHierarchyId, CMPXFilter* aFilter)
       
   300     {
       
   301     TRACER("CGlxMediaList::InstanceL" );
       
   302     
       
   303     CGlxMediaListArray* mediaListArray = CGlxMediaListArray::InstanceL();
       
   304     CleanupClosePushL(*mediaListArray);
       
   305     
       
   306     RPointerArray<CGlxMediaList>& mediaLists =  mediaListArray->Array();
       
   307 
       
   308     TInt matchIndex = KErrNotFound;
       
   309     CGlxMediaList* mediaListInstance = NULL; // List to return
       
   310 
       
   311     // Try to find an existing media list to return (by matching the path)
       
   312     TInt listCount = mediaLists.Count();
       
   313     for (TInt count = 0; count < listCount; ++count)
       
   314         {
       
   315         CGlxMediaList* mediaList = mediaLists[count];
       
   316 
       
   317         // See if path's and hierarchy id's match
       
   318         // Filter is ignored
       
   319         if (mediaList->Equals(aPath) && (mediaList->iHierarchyId == aHierarchyId))
       
   320             {
       
   321             // Found a match
       
   322             matchIndex = count;
       
   323             mediaListInstance = mediaList;
       
   324             break;
       
   325             }
       
   326         }
       
   327 
       
   328     // Create a new media list if could not use an existing one
       
   329     if (matchIndex == KErrNotFound)
       
   330         {
       
   331         __ASSERT_DEBUG(!mediaListInstance, Panic(EGlxPanicAlreadyInitialised));
       
   332 
       
   333         mediaListInstance = CGlxMediaList::NewLC(aHierarchyId);
       
   334 
       
   335         // Set specified filter (if any) before opening the collection to path
       
   336         mediaListInstance->SetFilterL(aFilter);
       
   337         mediaListInstance->OpenL(aPath);
       
   338 
       
   339         // Insert media list as highest priority
       
   340         mediaLists.InsertL(mediaListInstance, 0);
       
   341         CleanupStack::Pop(mediaListInstance);
       
   342         }
       
   343     else
       
   344         {
       
   345         __ASSERT_DEBUG(mediaListInstance, Panic(EGlxPanicNullPointer));
       
   346 
       
   347         // Match found, set as highest priority
       
   348         mediaLists.InsertL(mediaListInstance, 0);
       
   349         mediaLists.Remove(matchIndex + 1);
       
   350         }
       
   351 
       
   352     mediaListInstance->AddReference(); // Add user
       
   353 
       
   354     CleanupStack::PopAndDestroy(mediaListArray);
       
   355     
       
   356     return mediaListInstance;
       
   357     }
       
   358 
       
   359 // -----------------------------------------------------------------------------
       
   360 // Gives an array of all media lists in current use
       
   361 // -----------------------------------------------------------------------------
       
   362 RPointerArray<CGlxMediaList>& CGlxMediaList::MediaListsL()
       
   363     {
       
   364     TRACER("CGlxMediaList::MediaListsL" );
       
   365     
       
   366     CGlxMediaListArray* mediaListArray = CGlxMediaListArray::InstanceL();
       
   367     RPointerArray<CGlxMediaList>& array = mediaListArray->Array();
       
   368     mediaListArray->Close();
       
   369     return array;
       
   370     }
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // OfferMedia
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 void CGlxMediaList::OfferMedia(const TGlxIdSpaceId& aIdSpaceId, CGlxMedia* aMedia) 
       
   377     {
       
   378     TRACER("CGlxMediaList::OfferMedia" );
       
   379 
       
   380     // try to find the matching item in this list
       
   381     TInt index = Index( aIdSpaceId, aMedia->Id() );
       
   382     // if matching item found, link media object
       
   383     if ( KErrNotFound != index )
       
   384         {
       
   385         TGlxMedia& item = iItemList->Item( index );
       
   386 
       
   387         // static items should not be offered
       
   388         if ( !item.IsStatic() )
       
   389             {
       
   390             item.SetMedia( aMedia, *this, index );
       
   391             }
       
   392         }
       
   393     }
       
   394 
       
   395 // -----------------------------------------------------------------------------
       
   396 // NotifyThumbnailAvailableL
       
   397 // -----------------------------------------------------------------------------
       
   398 //
       
   399 void CGlxMediaList::HandleAttributesAvailableL(TInt aIndex, 
       
   400         const RArray<TMPXAttribute>& aAttributes)
       
   401     {
       
   402     TRACER("CGlxMediaList::HandleAttributesAvailableL" );
       
   403 
       
   404     __ASSERT_DEBUG(aIndex >= 0, Panic(EGlxPanicLogicError)); // Must exist
       
   405     // Need to get exact count of iItemListObservers at
       
   406     // every iteration because it is possible that 
       
   407     // RemoveMediaListObserver might call during this iteration
       
   408     for (TInt i = 0; i < iItemListObservers.Count(); i++)
       
   409         {
       
   410         iItemListObservers[i]->HandleAttributesAvailableL(aIndex, aAttributes, this);
       
   411         }
       
   412     }
       
   413 
       
   414 // -----------------------------------------------------------------------------
       
   415 // Ask if the list has any requests to place
       
   416 // -----------------------------------------------------------------------------
       
   417 //
       
   418 void CGlxMediaList::AttributeRequestL(RArray<TInt>& aItemIndexes,
       
   419 		RArray<TGlxMediaId>& aItemIds, 
       
   420         RArray<TMPXAttribute>& aAttributes, 
       
   421         CMPXAttributeSpecs*& aDetailedSpecs) const
       
   422     {
       
   423     TRACER("CGlxMediaList::AttributeRequestL" );
       
   424     
       
   425     // Find the highest priority context that has something to request
       
   426     TInt count = iContexts.Count();
       
   427     for (TInt i = 0; i < count; i++)
       
   428         {
       
   429         // Determine items (referenced by index) to request attributes for
       
   430         iContexts[i].iContext->AttributeRequestL(this, aItemIndexes, aAttributes, aDetailedSpecs);
       
   431 
       
   432         // Map item indices to item Ids
       
   433         TInt itemIndicesCount = aItemIndexes.Count();
       
   434         for (TInt itemIndicesCounter = 0; itemIndicesCounter < itemIndicesCount; ++itemIndicesCounter)
       
   435             {
       
   436             const TGlxMedia& item = iItemList->Item( aItemIndexes[itemIndicesCounter] );
       
   437             if (!item.IsStatic())
       
   438                 {
       
   439                 aItemIds.AppendL( item.Id() );
       
   440                 }
       
   441             }
       
   442 
       
   443         // break if context has something to request
       
   444         if (itemIndicesCount > 0)
       
   445             {
       
   446             break;
       
   447             }
       
   448         }
       
   449     }
       
   450 
       
   451 // ---------------------------------------------------------------------------
       
   452 // AllAttributesL
       
   453 // ---------------------------------------------------------------------------
       
   454 //
       
   455 void CGlxMediaList::GetRequiredAttributesL(TInt aIndex, RArray<TMPXAttribute>& aAttributes)
       
   456     {
       
   457     TRACER("CGlxMediaList::GetRequiredAttributesL" );
       
   458     
       
   459     TLinearOrder<TMPXAttribute> orderer (&AttributeOrder);
       
   460 
       
   461     // Determine all attributes to request for an item, for all contexts
       
   462     TInt contextCount = iContexts.Count();
       
   463     for ( TInt contextIndex = 0; contextIndex < contextCount; contextIndex++ )
       
   464         {
       
   465         const MGlxFetchContext* context = iContexts[contextIndex].iContext;
       
   466         if ( context )
       
   467             {
       
   468             // Determine all attributes to request for an item, for this context
       
   469             context->AllAttributesL(this, aIndex, aAttributes);
       
   470 
       
   471             }
       
   472         }
       
   473     }
       
   474 
       
   475 // ---------------------------------------------------------------------------
       
   476 // AttributeOrder
       
   477 // ---------------------------------------------------------------------------
       
   478 //
       
   479 TInt CGlxMediaList::AttributeOrder(const TMPXAttribute& aItem1, 
       
   480         const TMPXAttribute& aItem2) 
       
   481     {
       
   482     TRACER("CGlxMediaList::AttributeOrder");
       
   483             
       
   484     TInt contentId1 = aItem1.ContentId();
       
   485     TInt contentId2 = aItem2.ContentId();
       
   486 
       
   487     if (contentId1 < contentId2) 
       
   488         {
       
   489         return -1;
       
   490         }
       
   491 
       
   492     if (contentId1 > contentId2) 
       
   493         {
       
   494         return 1;
       
   495         }
       
   496 
       
   497     TUint attributeId1 = aItem1.AttributeId();
       
   498     TUint attributeId2 = aItem2.AttributeId();
       
   499 
       
   500     if (attributeId1 < attributeId2) 
       
   501         {
       
   502         return -1;
       
   503         }
       
   504 
       
   505     if (attributeId1 > attributeId2) 
       
   506         {
       
   507         return 1;
       
   508         }
       
   509 
       
   510     return 0;
       
   511     }
       
   512 
       
   513 // ---------------------------------------------------------------------------
       
   514 // AttributeOrderReversed
       
   515 // ---------------------------------------------------------------------------
       
   516 //
       
   517 TInt CGlxMediaList::AttributeOrderReversed(const TMPXAttribute& aItem1, 
       
   518         const TMPXAttribute& aItem2) 
       
   519     {
       
   520     TRACER("CGlxMediaList::AttributeOrderReversed");
       
   521     
       
   522     return -AttributeOrder(aItem1, aItem2);
       
   523     }
       
   524 
       
   525 // ---------------------------------------------------------------------------
       
   526 // Remore references to the media object
       
   527 // ---------------------------------------------------------------------------
       
   528 //
       
   529 void CGlxMediaList::RemoveReference( TInt aIndex )
       
   530     {
       
   531     TRACER( "CGlxMediaList::RemoveReference" );
       
   532     GLX_ASSERT_DEBUG( iItemList, Panic( EGlxPanicNotInitialised ), 
       
   533         "not ready to remove references" );
       
   534     
       
   535     GLX_LOG_INFO1( "CGlxMediaList::RemoveReference %d", aIndex );
       
   536     iItemList->RemoveReference( aIndex );
       
   537     }
       
   538 
       
   539 // ---------------------------------------------------------------------------
       
   540 // HandleError
       
   541 // ---------------------------------------------------------------------------
       
   542 //
       
   543 void CGlxMediaList::HandleError(TInt aError)
       
   544     {
       
   545     TRACER( "CGlxMediaList::HandleError");    
       
   546     GLX_LOG_INFO1( "CGlxMediaList::HandleError %d", aError );
       
   547     TInt obsCount = iItemListObservers.Count();
       
   548     for (TInt obsIdx = 0; obsIdx < obsCount; ++obsIdx)
       
   549         {
       
   550         iItemListObservers[obsIdx]->HandleError(aError);
       
   551         }
       
   552     }
       
   553 
       
   554 // -----------------------------------------------------------------------------
       
   555 // Releases a media list interface
       
   556 // -----------------------------------------------------------------------------
       
   557 void CGlxMediaList::Close()
       
   558     {
       
   559     TRACER( "CGlxMediaList::Close" );
       
   560     
       
   561     RPointerArray<CGlxMediaList>& mediaLists = iMediaListArray->Array();
       
   562 
       
   563     TInt listCount = mediaLists.Count();
       
   564     for (TInt count = 0; count < listCount; ++count)
       
   565         {
       
   566         CGlxMediaList* mediaList = mediaLists[count];
       
   567 
       
   568         if (mediaList == this)
       
   569             {
       
   570             TInt referenceCount = mediaList->RemoveReference();
       
   571             if (referenceCount == 0)
       
   572                 {
       
   573                 mediaLists.Remove(count);
       
   574                 mediaLists.Compress();
       
   575 
       
   576                 delete mediaList;
       
   577                 break;
       
   578                 }
       
   579             }
       
   580         }
       
   581     }
       
   582 
       
   583 // -----------------------------------------------------------------------------
       
   584 // Id
       
   585 // From MGlxMediaList
       
   586 // -----------------------------------------------------------------------------
       
   587 //
       
   588 TGlxMediaListId CGlxMediaList::Id() const
       
   589     {
       
   590     TRACER( "CGlxMediaList::Id" );
       
   591     
       
   592     return TGlxMediaListId((unsigned int)(void*)this);	
       
   593     }
       
   594 
       
   595 // -----------------------------------------------------------------------------
       
   596 // Count
       
   597 // From MGlxMediaList
       
   598 // -----------------------------------------------------------------------------
       
   599 //
       
   600 TInt CGlxMediaList::Count(NGlxListDefs::TCountType aType) const
       
   601     {
       
   602     TRACER("CGlxMediaList::Count");
       
   603     
       
   604     return iItemList->Count( aType );    
       
   605     }
       
   606 
       
   607 // -----------------------------------------------------------------------------
       
   608 // FocusIndex
       
   609 // From MGlxMediaList
       
   610 // -----------------------------------------------------------------------------
       
   611 //
       
   612 TInt CGlxMediaList::FocusIndex() const
       
   613     {
       
   614     TRACER("CGlxMediaList::FocusIndex");
       
   615     
       
   616     return iItemList->FocusIndex();    
       
   617     }
       
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // SetFocusL
       
   621 // -----------------------------------------------------------------------------
       
   622 //
       
   623 void CGlxMediaList::SetFocusL(NGlxListDefs::TFocusSetType aType, TInt aValue)
       
   624     {
       
   625     TRACER("CGlxMediaList::SetFocusL");
       
   626     
       
   627     GLX_LOG_INFO1( "CGlxMediaList::SetFocusL %d", aValue );
       
   628     iItemList->SetFocus( aType, aValue );
       
   629     }
       
   630 
       
   631 // -----------------------------------------------------------------------------
       
   632 // Item
       
   633 // From MGlxMediaList
       
   634 // -----------------------------------------------------------------------------
       
   635 //
       
   636 const TGlxMedia& CGlxMediaList::Item(TInt aIndex) const
       
   637     {
       
   638     TRACER("CGlxMediaList::Item");
       
   639     
       
   640     return iItemList->Item( aIndex );    
       
   641     }
       
   642 
       
   643 // -----------------------------------------------------------------------------
       
   644 // Index
       
   645 // From MGlxMediaList
       
   646 // -----------------------------------------------------------------------------
       
   647 //
       
   648 TInt CGlxMediaList::Index(const TGlxIdSpaceId& aIdSpaceId, const TGlxMediaId& aId) const
       
   649     {
       
   650     TRACER("CGlxMediaList::Index");
       
   651     
       
   652     return iItemList->Index( aIdSpaceId, aId );    
       
   653     }
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // AddMediaListObserverL
       
   657 // From MGlxMediaList
       
   658 // -----------------------------------------------------------------------------
       
   659 //
       
   660 void CGlxMediaList::AddMediaListObserverL(MGlxMediaListObserver* aObserver)
       
   661     {
       
   662     TRACER("CGlxMediaList::AddMediaListObserverL");    
       
   663     GLX_LOG_INFO1( "CGlxMediaList::AddMediaListObserverL(0x%x)", aObserver );
       
   664 
       
   665     // Make sure the observer is not already in the array
       
   666     __ASSERT_DEBUG(iItemListObservers.Find(aObserver) == -1, Panic(EGlxPanicIllegalArgument)); // Observer already added
       
   667 
       
   668     iItemListObservers.AppendL(aObserver);
       
   669     }
       
   670 
       
   671 // -----------------------------------------------------------------------------
       
   672 // RemoveMediaListObserver
       
   673 // From MGlxMediaList
       
   674 // -----------------------------------------------------------------------------
       
   675 //	
       
   676 void CGlxMediaList::RemoveMediaListObserver(MGlxMediaListObserver* aObserver)
       
   677     {
       
   678     TRACER("CGlxMediaList::RemoveMediaListObserver");    
       
   679     GLX_LOG_INFO1( "CGlxMediaList::RemoveMediaListObserver(0x%x)", aObserver );
       
   680 
       
   681     TInt index = iItemListObservers.Find(aObserver);
       
   682 
       
   683     // Make sure the observer is in the array
       
   684     // LOG THIS! __ASSERT_DEBUG(index != -1, Panic(EGlxPanicIllegalArgument)); // No such observer
       
   685 
       
   686     if (index != KErrNotFound) 
       
   687         {
       
   688         iItemListObservers.Remove(index);	
       
   689         }
       
   690     }
       
   691 
       
   692 // -----------------------------------------------------------------------------
       
   693 // AddContextL
       
   694 // From MGlxMediaList
       
   695 // -----------------------------------------------------------------------------
       
   696 //	
       
   697 void CGlxMediaList::AddContextL(const MGlxFetchContext* aContext, 
       
   698         TInt aPriority)
       
   699     {
       
   700     TRACER("CGlxMediaList::AddContextL");    
       
   701     GLX_LOG_INFO1( "CGlxMediaList::AddContextL(0x%x)", aContext );
       
   702 
       
   703     if (!aContext)
       
   704         {
       
   705         return;
       
   706         }
       
   707 
       
   708     // Add the new context in priority order
       
   709     TContext context;
       
   710     context.iContext = aContext;
       
   711     context.iPriority = aPriority;
       
   712 
       
   713 #ifdef _DEBUG
       
   714 
       
   715     // Make sure no duplicate entries
       
   716     TIdentityRelation<CGlxMediaList::TContext> match (&CGlxMediaList::TContext::Match);
       
   717     __ASSERT_DEBUG(iContexts.Find(context, match) == KErrNotFound, Panic(EGlxPanicAlreadyAdded));
       
   718 
       
   719 #endif // _DEBUG
       
   720 
       
   721     TLinearOrder<CGlxMediaList::TContext> orderer (&CGlxMediaList::TContext::Compare);
       
   722     TInt ret = iContexts.InsertInOrderAllowRepeats(context, orderer); 
       
   723     User::LeaveIfError(ret);
       
   724 
       
   725     iManager->HandleWindowChangedL(this);
       
   726     }
       
   727 
       
   728 // -----------------------------------------------------------------------------
       
   729 // RemoveContext
       
   730 // From MGlxMediaList
       
   731 // -----------------------------------------------------------------------------
       
   732 //	
       
   733 void CGlxMediaList::RemoveContext(const MGlxFetchContext* aContext)
       
   734     {
       
   735     TRACER("CGlxMediaList::RemoveContext");    
       
   736     GLX_LOG_INFO1( "CGlxMediaList::RemoveContext(0x%x)", aContext );
       
   737 
       
   738     if (!aContext)
       
   739         {
       
   740         return;
       
   741         }
       
   742 
       
   743     TIdentityRelation<CGlxMediaList::TContext> match (&CGlxMediaList::TContext::Match);
       
   744     TContext context;
       
   745     context.iContext = aContext;
       
   746     context.iPriority = 0;
       
   747     TInt index = iContexts.Find(context, match);
       
   748 
       
   749     // remove the context if it was found, just ignore if its not found
       
   750     if (index != KErrNotFound) 
       
   751         {
       
   752         iContexts.Remove(index);
       
   753         // notify cache manager: garbage collection needs to be run to free the 
       
   754         // items that the removed context required
       
   755         TRAP_IGNORE( iManager->HandleWindowChangedL( this ) );
       
   756         }
       
   757     }
       
   758 
       
   759 // -----------------------------------------------------------------------------
       
   760 // Returns the isolated collection, that is used by this media list
       
   761 // -----------------------------------------------------------------------------
       
   762 //
       
   763 MMPXCollection& CGlxMediaList::Collection() const
       
   764     {
       
   765     TRACER("CGlxMediaList::Collection");
       
   766     __ASSERT_DEBUG(iCollectionUtility != NULL, Panic(EGlxPanicNullPointer));
       
   767     return iCollectionUtility->Collection();
       
   768     }
       
   769 
       
   770 // -----------------------------------------------------------------------------
       
   771 // Returns the current path
       
   772 // -----------------------------------------------------------------------------
       
   773 CMPXCollectionPath* CGlxMediaList::PathLC(NGlxListDefs::TPathType aType) const
       
   774     {
       
   775     TRACER("CGlxMediaList::PathLC");  
       
   776 
       
   777     CMPXCollectionPath* path = CMPXCollectionPath::NewL();
       
   778     CleanupStack::PushL(path);
       
   779 
       
   780     // Add navigation to parent
       
   781     PathPopulateParentL( *path );
       
   782 
       
   783     if ( aType == NGlxListDefs::EPathAllOrSelection ||
       
   784          aType == NGlxListDefs:: EPathFocusOrSelection )
       
   785         {
       
   786         // If selection exists, add only selection
       
   787         // Otherwise add all items or focused item
       
   788         if ( iItemList->SelectedItemIndices().Count() > 0 )
       
   789             {
       
   790             PathPopulateSelectionL( *path );
       
   791             }
       
   792         else
       
   793             {
       
   794             if ( aType == NGlxListDefs::EPathAllOrSelection )
       
   795                 {
       
   796                 PathPopulateAllL( *path );
       
   797                 }
       
   798             else if ( aType == NGlxListDefs:: EPathFocusOrSelection )
       
   799                 {
       
   800                 PathPopulateFocusL( *path );
       
   801                 }
       
   802             }
       
   803         }
       
   804 
       
   805     return path;
       
   806     }
       
   807 
       
   808 // -----------------------------------------------------------------------------
       
   809 // Determines if an item has been selected
       
   810 // -----------------------------------------------------------------------------
       
   811 TBool CGlxMediaList::IsSelected(TInt aIndex) const
       
   812     {
       
   813     TRACER("CGlxMediaList::IsSelected");    
       
   814     GLX_LOG_INFO1( "CGlxMediaList::IsSelected %d", aIndex );
       
   815     return iItemList->IsSelected( aIndex );
       
   816     }
       
   817 
       
   818 // -----------------------------------------------------------------------------
       
   819 // Handles item selection/deselection
       
   820 // -----------------------------------------------------------------------------
       
   821 void CGlxMediaList::SetSelectedL(TInt aIndex, TBool aSelected)
       
   822     {
       
   823     TRACER("CGlxMediaList::SetSelectedL");    
       
   824     GLX_LOG_INFO2( "CGlxMediaList::SetSelectedL %d:%d", aIndex, aSelected );
       
   825     iItemList->SetSelectedL( aIndex, aSelected );
       
   826     }
       
   827 
       
   828 // -----------------------------------------------------------------------------
       
   829 // Returns selection count
       
   830 // -----------------------------------------------------------------------------
       
   831 TInt CGlxMediaList::SelectionCount() const
       
   832     {
       
   833     TRACER("CGlxMediaList::SelectionCount");
       
   834     
       
   835     return iItemList->SelectedItemIndices().Count();
       
   836     }
       
   837 
       
   838 // -----------------------------------------------------------------------------
       
   839 // Returns selected item index from selection
       
   840 // -----------------------------------------------------------------------------
       
   841 TInt CGlxMediaList::SelectedItemIndex(TInt aSelectionIndex) const
       
   842     {
       
   843     TRACER("CGlxMediaList::SelectedItemIndex");    
       
   844     GLX_LOG_INFO1( "CGlxMediaList::SelectedItemIndex %d", aSelectionIndex );
       
   845     return iItemList->SelectedItemIndices()[ aSelectionIndex ];
       
   846     }
       
   847 
       
   848 // -----------------------------------------------------------------------------
       
   849 // Sends a command to the collection
       
   850 // -----------------------------------------------------------------------------
       
   851 void CGlxMediaList::CommandL(CMPXCommand& aCommand)
       
   852     {
       
   853     TRACER("CGlxMediaList::CommandL");
       
   854 
       
   855     // Multiple commands should not happen
       
   856     __ASSERT_DEBUG( !iCommandPending, Panic( EGlxPanicLogicError ) );
       
   857 
       
   858     // Send the command
       
   859     Collection().CommandL( aCommand );
       
   860 
       
   861     // Use the sessionId to indicate that a command is pending
       
   862     __ASSERT_DEBUG( aCommand.IsSupported( KMPXCommandGeneralSessionId ), 
       
   863                     Panic( EGlxPanicLogicError ) );
       
   864 
       
   865     iCommandPending = aCommand.ValueTObjectL<TAny*>( KMPXCommandGeneralSessionId );
       
   866     }
       
   867 
       
   868 // -----------------------------------------------------------------------------
       
   869 // Cancels a command on the collection
       
   870 // -----------------------------------------------------------------------------
       
   871 void CGlxMediaList::CancelCommand()
       
   872     {
       
   873     TRACER("CGlxMediaList::CancelCommand");
       
   874 
       
   875     // Cancelling a non issued command should not happen
       
   876     __ASSERT_DEBUG( iCommandPending, Panic( EGlxPanicLogicError ) );
       
   877 
       
   878     // Cancel command
       
   879     Collection().CancelRequest();
       
   880     iCommandPending = NULL;
       
   881     }
       
   882 
       
   883 // -----------------------------------------------------------------------------
       
   884 // Specify filter on the media list
       
   885 // -----------------------------------------------------------------------------
       
   886 void CGlxMediaList::SetFilterL(CMPXFilter* aFilter)
       
   887     {
       
   888     TRACER("CGlxMediaList::SetFilterL");
       
   889     
       
   890     // This method now takes a copy of the filter. It does not take ownership of aFilter
       
   891     
       
   892     CMPXFilter* tempFilter = NULL;
       
   893     
       
   894     if (aFilter)
       
   895         {
       
   896         // Create copy of filter
       
   897         tempFilter = CMPXFilter::NewL(*aFilter);
       
   898         CleanupStack::PushL(tempFilter);
       
   899         }
       
   900     
       
   901     // Set filter on the collection
       
   902     Collection().SetFilterL(aFilter);
       
   903 
       
   904     // Re-open collection if filter has been applied and list is already populated
       
   905     if ( iIsPopulated )
       
   906         {
       
   907         ReOpenL();
       
   908 
       
   909         iReorderPending = ETrue;
       
   910         }
       
   911 
       
   912     delete iFilter;
       
   913     iFilter = NULL;
       
   914 
       
   915     if (aFilter)
       
   916         {
       
   917         // SetFilterL did not leave. So take ownership of copy
       
   918         CleanupStack::Pop(tempFilter);
       
   919         iFilter = tempFilter;
       
   920         }
       
   921     }
       
   922 
       
   923 // -----------------------------------------------------------------------------
       
   924 // Returns filter on the media list
       
   925 // -----------------------------------------------------------------------------
       
   926 CMPXFilter* CGlxMediaList::Filter() const
       
   927     {
       
   928     TRACER("CGlxMediaList::Filter");
       
   929     
       
   930     return iFilter;
       
   931     }
       
   932 
       
   933 // ---------------------------------------------------------------------------
       
   934 // IdSpaceId
       
   935 // ---------------------------------------------------------------------------
       
   936 //
       
   937 TGlxIdSpaceId CGlxMediaList::IdSpaceId(TInt aIndex) const
       
   938     {
       
   939     TRACER("CGlxMediaList::IdSpaceId");
       
   940     
       
   941     ///@todo Delegate id space to item list.
       
   942     if (Count() && iItemList->Item(aIndex).IsStatic())
       
   943     	{
       
   944     	return KGlxStaticItemIdSpaceId;
       
   945     	}
       
   946     else
       
   947     	{
       
   948     	return iIdSpaceId;
       
   949     	}
       
   950     }
       
   951 
       
   952 // ---------------------------------------------------------------------------
       
   953 // CGlxMediaList::IsPopulated()
       
   954 // ---------------------------------------------------------------------------
       
   955 //
       
   956 TBool CGlxMediaList::IsPopulated() const
       
   957     {
       
   958     TRACER("CGlxMediaList::IsPopulated");
       
   959     
       
   960     return iIsPopulated;
       
   961     }
       
   962 
       
   963 
       
   964 // -----------------------------------------------------------------------------
       
   965 // Add a static item
       
   966 // -----------------------------------------------------------------------------
       
   967 //
       
   968 void CGlxMediaList::AddStaticItemL( CGlxMedia* aStaticItem, 
       
   969         NGlxListDefs::TInsertionPosition aTargetPosition )
       
   970     {
       
   971     TRACER("CGlxMediaList::AddStaticItemL");    
       
   972     
       
   973     iItemList->AddStaticItemL( aStaticItem, aTargetPosition );
       
   974     }
       
   975 
       
   976 // -----------------------------------------------------------------------------
       
   977 // Remove a static item
       
   978 // -----------------------------------------------------------------------------
       
   979 //
       
   980 void CGlxMediaList::RemoveStaticItem(const TGlxMediaId& aItemId)
       
   981 	{
       
   982 	TRACER("CGlxMediaList::RemoveStaticItem");
       
   983     
       
   984     iItemList->Remove(TGlxIdSpaceId(KGlxStaticItemIdSpaceId), aItemId);
       
   985 	}
       
   986 
       
   987 // -----------------------------------------------------------------------------
       
   988 // Enable/disable static items
       
   989 // -----------------------------------------------------------------------------
       
   990 //
       
   991 void CGlxMediaList::SetStaticItemsEnabled( TBool aEnabled )
       
   992     {
       
   993     TRACER("CGlxMediaList::SetStaticItemsEnabled");
       
   994     
       
   995     iItemList->SetStaticItemsEnabled( aEnabled );
       
   996     }
       
   997     
       
   998 // -----------------------------------------------------------------------------
       
   999 // return ETrue if static items are enabled
       
  1000 // -----------------------------------------------------------------------------
       
  1001 //
       
  1002 TBool CGlxMediaList::IsStaticItemsEnabled() const
       
  1003     {
       
  1004     TRACER("CGlxMediaList::IsStaticItemsEnabled");
       
  1005         
       
  1006     return iItemList->IsStaticItemsEnabled();
       
  1007     }
       
  1008 
       
  1009 // -----------------------------------------------------------------------------
       
  1010 // Sets the initial focus position
       
  1011 // -----------------------------------------------------------------------------
       
  1012 //
       
  1013 void CGlxMediaList::SetFocusInitialPosition(NGlxListDefs::TFocusInitialPosition aFocusInitialPosition)
       
  1014     {
       
  1015     TRACER("CGlxMediaList::SetFocusInitialPosition");    
       
  1016     
       
  1017     iItemList->SetFocusInitialPosition( aFocusInitialPosition );
       
  1018     }
       
  1019 
       
  1020 // -----------------------------------------------------------------------------
       
  1021 // Resets the focus to the initial position
       
  1022 // -----------------------------------------------------------------------------
       
  1023 //
       
  1024 void CGlxMediaList::ResetFocus()
       
  1025     {
       
  1026     TRACER("CGlxMediaList::ResetFocus");
       
  1027         
       
  1028     iItemList->ResetFocus();
       
  1029     }
       
  1030 
       
  1031 // ---------------------------------------------------------------------------
       
  1032 // From MMPXCollectionObserver
       
  1033 // Handle collection message
       
  1034 // ---------------------------------------------------------------------------
       
  1035 void CGlxMediaList::HandleCollectionMessageL(const CMPXMessage& aMessage)
       
  1036     {
       
  1037     TRACER("CGlxMediaList::HandleCollectionMessageL");
       
  1038     
       
  1039     
       
  1040     if (aMessage.IsSupported(KMPXMessageGeneralId))
       
  1041         {
       
  1042         TInt messageId = aMessage.ValueTObjectL<TInt>(KMPXMessageGeneralId);
       
  1043         if ( messageId == KMPXMessageGeneral )
       
  1044             {
       
  1045             if (!aMessage.IsSupported(KMPXMessageGeneralEvent) ||
       
  1046                 !aMessage.IsSupported(KMPXMessageGeneralType))
       
  1047                 {
       
  1048                 return;
       
  1049                 }
       
  1050 
       
  1051             TInt messageEvent = aMessage.ValueTObjectL<TInt>(KMPXMessageGeneralEvent);
       
  1052             if (messageEvent == TMPXCollectionMessage::EPathChanged)
       
  1053                 {
       
  1054                 GLX_LOG_INFO("CGlxMediaList::HandleCollectionMessageL() EPathChanged");
       
  1055 
       
  1056                 TInt messageType = aMessage.ValueTObjectL<TInt>(KMPXMessageGeneralType);
       
  1057                 switch (messageType)
       
  1058                     {
       
  1059                     case EMcPathChangedByOpen:
       
  1060                         {
       
  1061                         HandleOpenL();
       
  1062                         break;
       
  1063                         }
       
  1064                     case EMcPathChangedByCollectionChange:
       
  1065                         {
       
  1066                         break;
       
  1067                         }
       
  1068                     default:
       
  1069                         __ASSERT_DEBUG(EFalse, Panic(EGlxPanicLogicError));
       
  1070                         break;
       
  1071                     }
       
  1072                 }
       
  1073             }
       
  1074         else if (messageId == KMPXMessageIdItemChanged)
       
  1075             {
       
  1076             if (!aMessage.IsSupported(KMPXMessageMediaGeneralCategory) ||
       
  1077                 !aMessage.IsSupported(KMPXMessageChangeEventType) ||
       
  1078                 !aMessage.IsSupported(KMPXMessageMediaGeneralId))
       
  1079                 {
       
  1080                 return;
       
  1081                 }
       
  1082 
       
  1083             TMPXChangeEventType messageType = aMessage.ValueTObjectL<TMPXChangeEventType>(KMPXMessageChangeEventType);
       
  1084             switch (messageType)
       
  1085                 {
       
  1086                 case EMPXItemModified:
       
  1087                     {
       
  1088                     RArray<TMPXAttribute> attributes;
       
  1089                     CleanupClosePushL(attributes);
       
  1090                     TMPXItemId itemId = aMessage.ValueTObjectL<TMPXItemId>(KMPXMessageMediaGeneralId);
       
  1091                     HandleItemModifiedL(itemId, attributes);
       
  1092                     CleanupStack::PopAndDestroy(&attributes);
       
  1093                     iManager->HandleWindowChangedL(this);
       
  1094 
       
  1095                     // Drop through to perform sync, in case the order has changed
       
  1096                     }
       
  1097                 case EMPXItemInserted:
       
  1098                 case EMPXItemDeleted:
       
  1099                 default:
       
  1100                     // Items have changed, determine whether to sync now
       
  1101                     // or resync later if a sync is already pending after opening
       
  1102                     if ( iSyncStatus == KNonePending )
       
  1103                         {
       
  1104                         ReOpenL(); // force re-opens
       
  1105 
       
  1106                         iSyncStatus = KSyncPending;
       
  1107                         }
       
  1108                     else
       
  1109                         {
       
  1110                         iSyncStatus = KResyncPending;
       
  1111                         }
       
  1112                     break;
       
  1113                 }
       
  1114             }
       
  1115         else // received message isn't handled by media list
       
  1116             {
       
  1117             // Inform observers of message
       
  1118             TMessageNotificationStrategy strategy( aMessage, *this );
       
  1119             NotifyObservers( strategy );
       
  1120             }
       
  1121         }
       
  1122     }
       
  1123 
       
  1124 // ---------------------------------------------------------------------------
       
  1125 // From MMPXCollectionObserver
       
  1126 // Handles the collection entries being opened. Typically called
       
  1127 // when client has Open()'d a folder
       
  1128 // ---------------------------------------------------------------------------
       
  1129 //
       
  1130 void CGlxMediaList::HandleOpenL(const CMPXMedia& /*aEntries*/, TInt /*aIndex*/,
       
  1131         TBool /*aComplete*/, TInt aError)
       
  1132     {
       
  1133     TRACER("CGlxMediaList::HandleOpenL");
       
  1134     
       
  1135     /// @todo Need to handle errors
       
  1136     __ASSERT_DEBUG(aError == KErrNone, Panic(EGlxPanicLogicError));
       
  1137     HandleOpenL();
       
  1138     }
       
  1139 
       
  1140 // -----------------------------------------------------------------------------
       
  1141 // HandleOpenL
       
  1142 // -----------------------------------------------------------------------------
       
  1143 //
       
  1144 void CGlxMediaList::HandleOpenL()
       
  1145     {
       
  1146     TRACER("CGlxMediaList::HandleOpenL");
       
  1147 
       
  1148     // if we dont have the item list constructed
       
  1149     // dont do anything as it would lead to a crash
       
  1150     if( iItemList )
       
  1151         {
       
  1152         PopulateL();
       
  1153         // Sync (via population) has now occured,
       
  1154         // determine whether to resync if one is pending
       
  1155         if ( iSyncStatus == KResyncPending )
       
  1156             {
       
  1157             ReOpenL();
       
  1158 
       
  1159             iSyncStatus = KSyncPending;
       
  1160             }
       
  1161 
       
  1162         iManager->HandleWindowChangedL(this);
       
  1163         }
       
  1164     }
       
  1165 
       
  1166 // ---------------------------------------------------------------------------
       
  1167 // From MMPXCollectionObserver
       
  1168 // Handles the collection entries being opened. Typically called
       
  1169 // when client has Open()'d an item. Client typically responds by
       
  1170 // 'playing' the item
       
  1171 // ---------------------------------------------------------------------------
       
  1172 //
       
  1173 void CGlxMediaList::HandleOpenL(const CMPXCollectionPlaylist& /*aPlaylist*/,
       
  1174         TInt /*aError*/)
       
  1175     {
       
  1176     TRACER("CGlxMediaList::HandleOpenL" );
       
  1177     __ASSERT_DEBUG(EFalse, Panic(EGlxPanicLogicError));
       
  1178     }
       
  1179 
       
  1180 // ---------------------------------------------------------------------------
       
  1181 // From MMPXCollectionObserver
       
  1182 // Handle extended media properties
       
  1183 // ---------------------------------------------------------------------------
       
  1184 //
       
  1185 void CGlxMediaList::HandleCollectionMediaL(const CMPXMedia& aMedia, TInt aError)
       
  1186     {
       
  1187     TRACER("CGlxMediaList::HandleCollectionMediaL" );
       
  1188 
       
  1189     iManager->HandleCollectionMediaL(iIdSpaceId, aMedia, aError);
       
  1190     }
       
  1191 
       
  1192 // ---------------------------------------------------------------------------
       
  1193 // From MMPXCollectionObserver
       
  1194 // Handle command completion
       
  1195 // ---------------------------------------------------------------------------
       
  1196 //
       
  1197 void CGlxMediaList::HandleCommandComplete(CMPXCommand* aCommandResult, TInt aError)
       
  1198     {
       
  1199     TRACER("CGlxMediaList::HandleCommandComplete" );
       
  1200 
       
  1201     // SessionId is stored in iCommandPending
       
  1202     TAny* sessionId = iCommandPending;
       
  1203 
       
  1204     // Clear command pending flag here, in case an observer issues another command
       
  1205     iCommandPending = NULL;
       
  1206 
       
  1207     TCommandCompletedNotificationStrategy strategy( sessionId, aCommandResult, aError, *this );
       
  1208     NotifyObservers( strategy );
       
  1209     }
       
  1210 
       
  1211 // -----------------------------------------------------------------------------
       
  1212 // NewLC
       
  1213 // -----------------------------------------------------------------------------
       
  1214 //
       
  1215 CGlxMediaList* CGlxMediaList::NewLC(const TGlxHierarchyId& aHierarchyId)
       
  1216     {
       
  1217     TRACER("CGlxMediaList::NewLC" );
       
  1218     
       
  1219     CGlxMediaList* obj = new (ELeave) CGlxMediaList(aHierarchyId);
       
  1220     CleanupStack::PushL(obj);
       
  1221     obj->ConstructL();
       
  1222     return obj;
       
  1223     }
       
  1224 
       
  1225 // -----------------------------------------------------------------------------
       
  1226 // Constructor
       
  1227 // -----------------------------------------------------------------------------
       
  1228 //
       
  1229 CGlxMediaList::CGlxMediaList(const TGlxHierarchyId& aHierarchyId) :
       
  1230     iIdSpaceId(KGlxIdNone),
       
  1231     iHierarchyId(aHierarchyId), iVisibleWindowIndex( 0 )
       
  1232     {
       
  1233     TRACER("CGlxMediaList::CGlxMediaList");
       
  1234     
       
  1235     __ASSERT_DEBUG(KErrNotFound == -1, Panic(EGlxPanicDebugUnexpectedError));
       
  1236     }
       
  1237 
       
  1238 // -----------------------------------------------------------------------------
       
  1239 // Destructor
       
  1240 // -----------------------------------------------------------------------------
       
  1241 //
       
  1242 CGlxMediaList::~CGlxMediaList()
       
  1243     {
       
  1244     TRACER("CGlxMediaList::~CGlxMediaList" );
       
  1245     
       
  1246     if (iCollectionUtility)
       
  1247         {
       
  1248         iCollectionUtility->Close();
       
  1249         }
       
  1250 
       
  1251     iErrorPoster->Close();
       
  1252 
       
  1253     iItemListObservers.Close();
       
  1254     __ASSERT_DEBUG(iContexts.Count() == 0, Panic(EGlxPanicLogicError)); // Release all contexts
       
  1255     iContexts.Close();
       
  1256     iPath.Close();
       
  1257 
       
  1258     delete iItemList;
       
  1259     delete iFilter;
       
  1260     
       
  1261     if (iMediaListArray)
       
  1262     	{
       
  1263     	iMediaListArray->Close();
       
  1264     	}
       
  1265     
       
  1266     iCountAttributes.Close();
       
  1267 
       
  1268     // close the manager last as it may delete the cache and thus the CGlxMedia 
       
  1269     // objects.. item list destructor manipulates those objects so need to do it in this order
       
  1270 	if(iManager)
       
  1271 		{
       
  1272 		iManager->HandleListDeleted( this );
       
  1273 		iManager->Close();
       
  1274 		}    
       
  1275     }
       
  1276 
       
  1277 // -----------------------------------------------------------------------------
       
  1278 // ConstructL
       
  1279 // -----------------------------------------------------------------------------
       
  1280 //
       
  1281 void CGlxMediaList::ConstructL()
       
  1282     {
       
  1283     TRACER("CGlxMediaList::ConstructL" );
       
  1284     
       
  1285     iCollectionUtility = MMPXCollectionUtility::NewL(this, KMcModeIsolated);
       
  1286     iManager = CGlxCacheManager::InstanceL();
       
  1287     iErrorPoster = CGlxErrorPoster::InstanceL();
       
  1288     iMediaListArray = CGlxMediaListArray::InstanceL();
       
  1289     iCountAttributes.AppendL(KGlxMediaCollectionPluginSpecificSubTitle);
       
  1290     iCountAttributes.AppendL(KGlxMediaGeneralSlideshowableContent);
       
  1291     }
       
  1292 
       
  1293 // -----------------------------------------------------------------------------
       
  1294 // Initialize the media list
       
  1295 // -----------------------------------------------------------------------------
       
  1296 //
       
  1297 void CGlxMediaList::OpenL(const CMPXCollectionPath& aPath)
       
  1298     {
       
  1299     TRACER("CGlxMediaList::OpenL" );
       
  1300     
       
  1301     __ASSERT_DEBUG(iPath.Count() == 0, Panic(EGlxPanicAlreadyInitialised));
       
  1302 
       
  1303     // Copy the path's depth dimension
       
  1304     TInt levels = aPath.Levels();
       
  1305 
       
  1306     iPath.ReserveL(levels);
       
  1307     for (TInt level = 0; level < levels; level++) 
       
  1308         {
       
  1309         TGlxMediaId id(aPath.Id(level));
       
  1310         iPath.Append(id); 
       
  1311         }
       
  1312 
       
  1313     
       
  1314 	// Id space ids will no longer be retrieved from the collection framework
       
  1315 	// See ID:  ESLU-7C8CVN Inc9 MP: Error "Program closed: Music player" occurs if 
       
  1316     // user presses Rocker Select key continually in Album art view.
       
  1317     
       
  1318     // Consider the following scenario:
       
  1319     // 1. User launches fetcher dialog
       
  1320     // 2. Fetcher opens a medialist
       
  1321     // 3. MGlxMediaList::InstanceL starts an async wait loop allowing other active objects to run
       
  1322     // 4. User cancels fetcher
       
  1323     // 5. Fetcher does not have a handle to the MGlxMediaList so it cannot cancel or close it.
       
  1324     // --> We leak a medialist and leave an async wait loop in client processes active scheduler.
       
  1325 
       
  1326     if (levels)
       
  1327     	{
       
  1328     	iIdSpaceId = aPath.Id(0);
       
  1329     	}
       
  1330     else
       
  1331     	{
       
  1332     	iIdSpaceId = KGlxIdSpaceIdRoot;
       
  1333     	}
       
  1334     
       
  1335     iItemList = CGlxNavigableList::NewL( iIdSpaceId, *this, *this );
       
  1336 
       
  1337     OpenCollectionL( aPath );
       
  1338     }
       
  1339 
       
  1340 // -----------------------------------------------------------------------------
       
  1341 // AddReference
       
  1342 // -----------------------------------------------------------------------------
       
  1343 //
       
  1344 TInt CGlxMediaList::AddReference()
       
  1345     {
       
  1346     TRACER("CGlxMediaList::AddReference");
       
  1347     
       
  1348     iReferenceCount++;
       
  1349     return iReferenceCount;
       
  1350     }
       
  1351     
       
  1352 // -----------------------------------------------------------------------------
       
  1353 // RemoveReference
       
  1354 // -----------------------------------------------------------------------------
       
  1355 //
       
  1356 TInt CGlxMediaList::RemoveReference()
       
  1357     {
       
  1358     TRACER("CGlxMediaList::RemoveReference");
       
  1359     
       
  1360     __ASSERT_ALWAYS(iReferenceCount > 0, Panic(EGlxPanicLogicError));
       
  1361     iReferenceCount--;
       
  1362     return iReferenceCount;
       
  1363     }
       
  1364     
       
  1365 // -----------------------------------------------------------------------------
       
  1366 // ReferenceCount
       
  1367 // -----------------------------------------------------------------------------
       
  1368 //
       
  1369 TInt CGlxMediaList::ReferenceCount() const
       
  1370     {
       
  1371     TRACER("CGlxMediaList::ReferenceCount");
       
  1372     
       
  1373     return iReferenceCount;
       
  1374     }
       
  1375 
       
  1376 // -----------------------------------------------------------------------------
       
  1377 // Returns ETrue if this media list refers to the path
       
  1378 // -----------------------------------------------------------------------------
       
  1379 //
       
  1380 TBool CGlxMediaList::Equals(const CMPXCollectionPath& aPath) const 
       
  1381     {
       
  1382     TRACER("CGlxMediaList::Equals" );
       
  1383     
       
  1384     TInt myLevels = iPath.Count();
       
  1385     TInt pathLevels = aPath.Levels();
       
  1386     if (myLevels != pathLevels)
       
  1387         {
       
  1388         return EFalse;
       
  1389         }
       
  1390 
       
  1391     // Check if path's match
       
  1392     for (TInt i = 0; i < myLevels; i++) 
       
  1393         {
       
  1394         if (iPath[i] != TGlxMediaId(aPath.Id(i)))
       
  1395             {
       
  1396             return EFalse;
       
  1397             }
       
  1398         }
       
  1399 
       
  1400     return ETrue; // Match		
       
  1401     }
       
  1402 
       
  1403 // -----------------------------------------------------------------------------
       
  1404 // Determines if a filter has been set
       
  1405 // -----------------------------------------------------------------------------
       
  1406 TBool CGlxMediaList::IsFiltered() const
       
  1407     {
       
  1408     TRACER("CGlxMediaList::IsFiltered");
       
  1409     
       
  1410     return iFilter != NULL;
       
  1411     }
       
  1412 
       
  1413 // -----------------------------------------------------------------------------
       
  1414 // Synchronise the media list
       
  1415 // -----------------------------------------------------------------------------
       
  1416 void CGlxMediaList::ReOpenL()
       
  1417     {
       
  1418     TRACER("CGlxMediaList::ReOpenL" );
       
  1419     
       
  1420     // We must not re-open the list before it has been opened the first time
       
  1421     // note - this can happen if update messages are received whilst retreiving
       
  1422     // the id space id
       
  1423     if ( !iItemList )
       
  1424         {
       
  1425         return;
       
  1426         }
       
  1427     
       
  1428     CMPXCollectionPath* path = PathLC( NGlxListDefs::EPathParent );
       
  1429 
       
  1430     OpenCollectionL( *path );
       
  1431 
       
  1432     CleanupStack::PopAndDestroy(path);
       
  1433     }
       
  1434 
       
  1435 // -----------------------------------------------------------------------------
       
  1436 // Populates the list, i.e., opens the collection with the path
       
  1437 // -----------------------------------------------------------------------------
       
  1438 //
       
  1439 void CGlxMediaList::PopulateL()
       
  1440     {
       
  1441     TRACER("CGlxMediaList::PopulateL" );
       
  1442 
       
  1443     // Reserve space for all items in cache, that this media list is a potential user
       
  1444     // This allows SetContentsL to build user links without having to reserve space
       
  1445     iManager->ReserveUsersL( iIdSpaceId, CGlxMediaList::MediaListsL().Count() );
       
  1446 
       
  1447     CMPXCollectionPath* path = Collection().PathL();
       
  1448     CleanupStack::PushL(path);
       
  1449 
       
  1450     if ( iReorderPending )
       
  1451         {
       
  1452         iItemList->ReorderContentsL( *path, *iManager );
       
  1453         iReorderPending = EFalse;
       
  1454         }
       
  1455     else
       
  1456         {
       
  1457         iItemList->SetContentsL( *path, *iManager );
       
  1458 
       
  1459         // Sync has now occured,
       
  1460         // if only a sync was pending, clear sync status
       
  1461         if ( iSyncStatus == KSyncPending )
       
  1462             {
       
  1463             iSyncStatus = KNonePending;
       
  1464             }
       
  1465         }
       
  1466 
       
  1467     CleanupStack::PopAndDestroy(path);
       
  1468 
       
  1469     // The list contents may have changed, so update each used media with the
       
  1470     // current index into the list
       
  1471     UpdateMedia();
       
  1472 
       
  1473     // Inform observers of first time population
       
  1474     if (!iIsPopulated)
       
  1475         {
       
  1476         TListPopulatedNotificationStrategy strategy( *this );
       
  1477         NotifyObservers( strategy );
       
  1478         iIsPopulated = ETrue; // Do this only once.
       
  1479         }
       
  1480     }
       
  1481 
       
  1482 // -----------------------------------------------------------------------------
       
  1483 // Handles item modifications
       
  1484 // -----------------------------------------------------------------------------
       
  1485 void CGlxMediaList::HandleItemModifiedL(TInt aId, const RArray<TMPXAttribute>& aAttributes)
       
  1486     {
       
  1487     TRACER("CGlxMediaList::HandleItemModifiedL");
       
  1488     GLX_LOG_INFO1( "CGlxMediaList::HandleItemModifiedL %d", aId );
       
  1489     TGlxMediaId id(aId);
       
  1490 
       
  1491     /// @todo: Check that the correct IdSpaceId is being used here
       
  1492     
       
  1493     TInt index = Index(iIdSpaceId, id);
       
  1494 
       
  1495     if (index != KErrNotFound)
       
  1496         {
       
  1497         iManager->HandleItemModified(iIdSpaceId, id, aAttributes);
       
  1498 
       
  1499         RArray<TInt> itemIndices;
       
  1500         CleanupClosePushL(itemIndices);
       
  1501         itemIndices.AppendL(index);
       
  1502 
       
  1503         // Inform observers of modified items
       
  1504         TInt obsCount = iItemListObservers.Count();
       
  1505         GLX_DEBUG2("ML:HandleItemModifiedL obsCount=%d", obsCount);
       
  1506         for (TInt obsIdx = 0; obsIdx < obsCount; obsIdx++)
       
  1507             {
       
  1508             MGlxMediaListObserver* obs = iItemListObservers[obsIdx];
       
  1509             obs->HandleItemModifiedL(itemIndices, this);
       
  1510             }
       
  1511 
       
  1512         CleanupStack::PopAndDestroy(&itemIndices);
       
  1513         }
       
  1514     }
       
  1515 
       
  1516 // -----------------------------------------------------------------------------
       
  1517 // NotifyObserversOfMediaL
       
  1518 // -----------------------------------------------------------------------------
       
  1519 //
       
  1520 void CGlxMediaList::NotifyObserversOfMediaL(TInt aListIndex)
       
  1521     {
       
  1522     TRACER("CGlxMediaList::NotifyObserversOfMediaL");
       
  1523     GLX_LOG_INFO1( "CGlxMediaList::NotifyObserversOfMediaL %d", aListIndex );
       
  1524     TInt count = iItemListObservers.Count();
       
  1525     for (TInt i = 0; i < count; i++)
       
  1526         {
       
  1527         iItemListObservers[i]->HandleMediaL(aListIndex, this);
       
  1528         }
       
  1529     }
       
  1530         
       
  1531 // -----------------------------------------------------------------------------
       
  1532 // Notify observers of items added
       
  1533 // -----------------------------------------------------------------------------
       
  1534 //
       
  1535 void CGlxMediaList::HandleItemsAdded( TInt aAddedAtIndex, TInt aCount )
       
  1536     {
       
  1537     TRACER("CGlxMediaList::HandleItemsAdded");
       
  1538     
       
  1539     TItemsAddedNotificationStrategy strategy( aAddedAtIndex, aCount, *this );
       
  1540     NotifyObservers( strategy );
       
  1541     }
       
  1542 
       
  1543 // -----------------------------------------------------------------------------
       
  1544 // Notify observers of items removed
       
  1545 // -----------------------------------------------------------------------------
       
  1546 //
       
  1547 void CGlxMediaList::HandleItemsRemoved( TInt aRemovedFromIndex, TInt aCount )
       
  1548     {
       
  1549     TRACER("CGlxMediaList::HandleItemsRemoved");
       
  1550     
       
  1551     TItemsRemovedNotificationStrategy strategy( aRemovedFromIndex, aCount,
       
  1552         *this );
       
  1553     NotifyObservers( strategy );
       
  1554     }
       
  1555 
       
  1556 // -----------------------------------------------------------------------------
       
  1557 // Notify observers of focus change
       
  1558 // -----------------------------------------------------------------------------
       
  1559 //
       
  1560 void CGlxMediaList::HandleFocusChanged( NGlxListDefs::TFocusChangeType aType, 
       
  1561         TInt aNewIndex, TInt aOldIndex )
       
  1562     {
       
  1563     TRACER("CGlxMediaList::HandleFocusChanged");
       
  1564     
       
  1565     TFocusChangedNotificationStrategy strategy( aType, aNewIndex, aOldIndex,
       
  1566         *this );
       
  1567     NotifyObservers( strategy );
       
  1568     }
       
  1569 
       
  1570 // -----------------------------------------------------------------------------
       
  1571 // Notify observers of selection having changed
       
  1572 // -----------------------------------------------------------------------------
       
  1573 //
       
  1574 void CGlxMediaList::HandleItemSelected( TInt aIndex, TBool aSelected )
       
  1575     {
       
  1576     TRACER("CGlxMediaList::HandleItemSelected");
       
  1577     
       
  1578     TItemSelectedNotificationStrategy strategy( aIndex, aSelected, *this );
       
  1579     NotifyObservers( strategy );
       
  1580     }
       
  1581 
       
  1582 // -----------------------------------------------------------------------------
       
  1583 // Call strategy object for each observer
       
  1584 // -----------------------------------------------------------------------------
       
  1585 //
       
  1586 void CGlxMediaList::NotifyObservers( TNotificationStrategy& aStrategy )
       
  1587     {
       
  1588     TRACER("CGlxMediaList::NotifyObservers");
       
  1589     
       
  1590     // Notify all observers, even if some of them leave leave.
       
  1591     // "i" needs to be volatile, so that it does not get optimised into a 
       
  1592     // register. If i were in a register and observer left, i's new value 
       
  1593     // would be lost. 
       
  1594     volatile TInt i = iItemListObservers.Count() - 1;
       
  1595     
       
  1596     // Loop count + 1 times, so that iManager also gets notified if last 
       
  1597     // observer leaves. Iterate backwards in case observes remove themselves
       
  1598     // from the observer array during the callbacks.
       
  1599     while ( i >= -1 ) // usually tested only twice
       
  1600         {
       
  1601         TRAPD( err, 
       
  1602             {
       
  1603             while ( i >= 0 )
       
  1604                 {
       
  1605                 aStrategy.NotifyL( *iItemListObservers[ i ] );
       
  1606                 i--;
       
  1607                 }
       
  1608 
       
  1609             iManager->HandleWindowChangedL( this );
       
  1610             }
       
  1611         );
       
  1612         
       
  1613         if ( err != KErrNone )
       
  1614             {
       
  1615             iErrorPoster->PostError(err);
       
  1616             }
       
  1617 
       
  1618         i--;
       
  1619         }
       
  1620     }
       
  1621 
       
  1622 // -----------------------------------------------------------------------------
       
  1623 // Populates the path with hierarchy to parent
       
  1624 // -----------------------------------------------------------------------------
       
  1625 //
       
  1626 inline void CGlxMediaList::PathPopulateParentL(CMPXCollectionPath& aPath) const
       
  1627     {
       
  1628     TRACER("CGlxMediaList::PathPopulateParentL");
       
  1629     
       
  1630     // Add navigational hierarchy to path
       
  1631     TInt pathCount = iPath.Count();
       
  1632     for (TInt i = 0; i < pathCount; ++i)
       
  1633         {
       
  1634         aPath.AppendL( iPath[ i ].Value() );
       
  1635         }
       
  1636     }
       
  1637 
       
  1638 // -----------------------------------------------------------------------------
       
  1639 // Populates the path with all items and sets the focus
       
  1640 // -----------------------------------------------------------------------------
       
  1641 //
       
  1642 inline void CGlxMediaList::PathPopulateAllL(CMPXCollectionPath& aPath) const
       
  1643     {
       
  1644     TRACER("CGlxMediaList::PathPopulateAllL");
       
  1645     
       
  1646     RArray<TMPXItemId> mpxIds;
       
  1647     CleanupClosePushL( mpxIds );
       
  1648 
       
  1649     // Reserve space for all items
       
  1650     TInt itemCount = iItemList->Count();
       
  1651     mpxIds.ReserveL( itemCount );
       
  1652 
       
  1653     // Obtain TMPXItemId for each item
       
  1654     for (TInt i = 0; i < itemCount; ++i)
       
  1655         {
       
  1656         if ( !iItemList->Item( i ).IsStatic() )
       
  1657             {
       
  1658             mpxIds.AppendL( iItemList->Item( i ).Id().Value() );
       
  1659             }
       
  1660         }
       
  1661 
       
  1662     // Add Ids to current level in path
       
  1663     aPath.AppendL( mpxIds.Array() );
       
  1664 
       
  1665     // Set focused item
       
  1666     TInt focusIndex = FocusIndex();
       
  1667     if ( focusIndex >= 0 )
       
  1668         {
       
  1669         if ( !iItemList->Item( focusIndex ).IsStatic() )
       
  1670             {
       
  1671             aPath.Set( focusIndex - iItemList->Count( NGlxListDefs::ECountPreStatic ) );
       
  1672             }
       
  1673         }
       
  1674 
       
  1675     CleanupStack::PopAndDestroy( &mpxIds );
       
  1676     }
       
  1677 
       
  1678 // -----------------------------------------------------------------------------
       
  1679 // Populates the path with focused item and sets the focus
       
  1680 // -----------------------------------------------------------------------------
       
  1681 //
       
  1682 inline void CGlxMediaList::PathPopulateFocusL(CMPXCollectionPath& aPath) const
       
  1683     {
       
  1684     TRACER("CGlxMediaList::PathPopulateFocusL");
       
  1685     
       
  1686     // Obtain focused item
       
  1687     TInt focusIndex = FocusIndex();
       
  1688     if ( focusIndex >= 0 )
       
  1689         {
       
  1690         const TGlxMedia& item = iItemList->Item( focusIndex );
       
  1691         if ( !item.IsStatic() )
       
  1692             {
       
  1693             // Add focused item to path
       
  1694             aPath.AppendL( item.Id().Value() );
       
  1695             aPath.Set( 0 );
       
  1696             }
       
  1697         }
       
  1698     }
       
  1699 
       
  1700 // -----------------------------------------------------------------------------
       
  1701 // Populates the path with selected items and selects all
       
  1702 // -----------------------------------------------------------------------------
       
  1703 //
       
  1704 inline void CGlxMediaList::PathPopulateSelectionL(CMPXCollectionPath& aPath) const
       
  1705     {
       
  1706     TRACER("CGlxMediaList::PathPopulateSelectionL");
       
  1707     
       
  1708     RArray<TMPXItemId> mpxIds;
       
  1709     CleanupClosePushL( mpxIds );
       
  1710 
       
  1711     // Reserve space for all items
       
  1712     TInt selectionCount = iItemList->SelectedItemIndices().Count();
       
  1713     mpxIds.ReserveL( selectionCount );
       
  1714 
       
  1715     // Obtain TMPXItemId for each item
       
  1716     for (TInt i = 0; i < selectionCount; ++i)
       
  1717         {
       
  1718         TInt selectedItemIndex = iItemList->SelectedItemIndices()[ i ];
       
  1719         mpxIds.AppendL( iItemList->Item( selectedItemIndex ).Id().Value() );
       
  1720         }
       
  1721 
       
  1722     // Add Ids to current level in path
       
  1723     aPath.AppendL( mpxIds.Array() );
       
  1724 
       
  1725     // Set selection
       
  1726     aPath.SelectAllL();
       
  1727 
       
  1728     CleanupStack::PopAndDestroy( &mpxIds );
       
  1729     }
       
  1730 
       
  1731 // -----------------------------------------------------------------------------
       
  1732 // Updates each media used by this media list with the current index
       
  1733 // -----------------------------------------------------------------------------
       
  1734 //
       
  1735 inline void CGlxMediaList::UpdateMedia()
       
  1736     {
       
  1737     TRACER("CGlxMediaList::UpdateMedia");
       
  1738     
       
  1739     TInt count = iItemList->Count();
       
  1740     for (TInt i = 0; i < count; ++i)
       
  1741         {
       
  1742         TGlxMedia& item = iItemList->Item( i );
       
  1743 
       
  1744         // static items should not be updated
       
  1745         if ( !item.IsStatic() )
       
  1746             {
       
  1747             item.UpdateMedia( *this, i );
       
  1748             UpdateMediaInvalidateAttributesChangedByCounts(item);
       
  1749             }
       
  1750         }
       
  1751     }
       
  1752 
       
  1753 // -----------------------------------------------------------------------------
       
  1754 // Updates each media used by this media list with the current index
       
  1755 // -----------------------------------------------------------------------------
       
  1756 //
       
  1757 inline void CGlxMediaList::UpdateMediaInvalidateAttributesChangedByCounts(TGlxMedia& aItem)
       
  1758     {
       
  1759     TRACER("CGlxMediaList::UpdateMediaInvalidateAttributesChangedByCounts");
       
  1760     
       
  1761     iManager->HandleItemModified(iIdSpaceId, aItem.Id(), iCountAttributes);
       
  1762     }
       
  1763     
       
  1764 // -----------------------------------------------------------------------------
       
  1765 // Opens a collection at the appropriate level
       
  1766 // -----------------------------------------------------------------------------
       
  1767 //
       
  1768 void CGlxMediaList::OpenCollectionL(const CMPXCollectionPath& aPath)
       
  1769     {
       
  1770     TRACER("CGlxMediaList::OpenCollectionL");
       
  1771     
       
  1772     // Open the level
       
  1773     if ( aPath.Levels() == 0 )
       
  1774         {
       
  1775         Collection().OpenL( TUid::Uid( EGlxCollectionPluginShowInMainListView ) );
       
  1776         }
       
  1777     else
       
  1778         {
       
  1779         Collection().OpenL( aPath );
       
  1780         }
       
  1781     }
       
  1782 
       
  1783 
       
  1784 // -----------------------------------------------------------------------------
       
  1785 // Compare contexts by pointer
       
  1786 // -----------------------------------------------------------------------------
       
  1787 //
       
  1788 TBool CGlxMediaList::TContext::Match(const TContext& a1, const TContext& a2)
       
  1789     {
       
  1790     TRACER("CGlxMediaList::TContext::Match");
       
  1791     
       
  1792     return a1.iContext == a2.iContext;
       
  1793     }
       
  1794 
       
  1795 // -----------------------------------------------------------------------------
       
  1796 // Compare contexts by priority
       
  1797 // -----------------------------------------------------------------------------
       
  1798 //
       
  1799 TBool CGlxMediaList::TContext::Compare(const TContext& a1, const TContext& a2)
       
  1800     {
       
  1801     TRACER("CGlxMediaList::TContext::Compare");
       
  1802     
       
  1803     return a2.iPriority - a1.iPriority;
       
  1804     }
       
  1805 
       
  1806 // -----------------------------------------------------------------------------
       
  1807 // Set the visible dataWindow index
       
  1808 // -----------------------------------------------------------------------------
       
  1809 //
       
  1810 void CGlxMediaList::SetVisibleWindowIndexL( TInt aIndex )
       
  1811     {
       
  1812     TRACER("CGlxMediaList::SetVisibleWindowIndexL");
       
  1813     __ASSERT_ALWAYS( aIndex <= Count(), Panic( EGlxPanicIllegalArgument ) );
       
  1814     if( aIndex != iVisibleWindowIndex )
       
  1815         {
       
  1816         iVisibleWindowIndex = aIndex;
       
  1817         GLX_DEBUG2("SetVisibleWindowIndexL() iVisibleWindowIndex=%d",
       
  1818                                                         iVisibleWindowIndex);
       
  1819         iManager->HandleWindowChangedL(this);
       
  1820         iManager->RefreshL();
       
  1821         }
       
  1822     }
       
  1823     
       
  1824 // -----------------------------------------------------------------------------
       
  1825 // Returns visible dataWindow index
       
  1826 // -----------------------------------------------------------------------------
       
  1827 //
       
  1828 TInt CGlxMediaList::VisibleWindowIndex() const
       
  1829     {
       
  1830     TRACER("CGlxMediaList::VisibleWindowIndex");
       
  1831     return iVisibleWindowIndex;
       
  1832     }
       
  1833 
       
  1834 // -----------------------------------------------------------------------------
       
  1835 // Cancels the pending attribute/thumbnail requests 
       
  1836 // -----------------------------------------------------------------------------
       
  1837 
       
  1838 void CGlxMediaList::CancelPreviousRequests()
       
  1839 	{
       
  1840 	TRACER("CGlxMediaList::CancelPreviousRequests");	
       
  1841 	
       
  1842 	TInt focusIndex = FocusIndex();
       
  1843 	
       
  1844 	if(focusIndex >= KErrNone)
       
  1845 		{	
       
  1846 		if(!Item(focusIndex).Properties())
       
  1847 			{
       
  1848 			// If media is NULL, cancel the previous pending request.
       
  1849 			// Place a new request for the item in focus, to fetch the media attributes
       
  1850 			iManager->CancelPreviousRequest();		
       
  1851 			}
       
  1852 		}
       
  1853 	}