photosgallery/viewframework/medialists/inc/glxitemlist.h
changeset 0 4e91876724a2
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 #ifndef __C_GLXITEMLIST_H__
       
    22 #define __C_GLXITEMLIST_H__
       
    23 
       
    24 #include <e32std.h>
       
    25 #include "glxmedia.h"
       
    26 
       
    27 // Forward declarations
       
    28 class CMPXCollectionPath;
       
    29 class MGlxItemListObserver;
       
    30 class MGlxMediaUser;
       
    31 class MGlxMediaPool;
       
    32 
       
    33 namespace NGlxItemList
       
    34     {
       
    35     class MListModificationStrategy;
       
    36     class TDifferenceInfo;
       
    37     }
       
    38 
       
    39 /**
       
    40  * CGlxItemList
       
    41  *
       
    42  * List that has media items
       
    43  *
       
    44  * @author Aki Vanhatalo
       
    45  *
       
    46  * @internal reviewed 17/07/2007 by Kimmo Hoikka
       
    47  *
       
    48  * @ingroup mlm_media_list_manager_design
       
    49  */
       
    50 NONSHARABLE_CLASS( CGlxItemList ) : public CBase
       
    51     {
       
    52 public:
       
    53      /**
       
    54       * Constructor
       
    55       * @param aIdSpaceId id of id space in which list item ids are
       
    56       * @param aObserver Observer to be notified of item addition/removal
       
    57       * @param aMediaUser User class of media objects - media objects that 
       
    58       *                   this list links to will be linked to the user, so that 
       
    59       *                   cache manager is able to quickly access the media lists 
       
    60       *                   that use particular media objects
       
    61       */
       
    62     static CGlxItemList* NewL( const TGlxIdSpaceId& aIdSpaceId, 
       
    63         MGlxItemListObserver& aObserver, MGlxMediaUser& aMediaUser );    
       
    64         
       
    65     /** 
       
    66      * Destructor
       
    67      */
       
    68     ~CGlxItemList();
       
    69     
       
    70     /**
       
    71      * @return id space id
       
    72      */
       
    73     inline const TGlxIdSpaceId& IdSpaceId() const;
       
    74     
       
    75     /**
       
    76      * Synchronises the list with new path 
       
    77      * Sends added/removed notifications as necessary
       
    78      * Note: Does not send "perfect" notification if the order of the items 
       
    79      * has been changed. Hence, this function cannot be reliably used when 
       
    80      * sort order has changed
       
    81      *
       
    82      * @param aSource path with item ids. 
       
    83      * @param aMediaPool interface from which to ask for media items
       
    84      */
       
    85     void SetContentsL( const CMPXCollectionPath& aSource, const MGlxMediaPool& aMediaPool );
       
    86     
       
    87     /**
       
    88      * Remove an item form the list
       
    89      * Sends removed notification
       
    90      *
       
    91      * @param aItemId Id of item to remove
       
    92      * @param aIdSpaceId Id space of the item
       
    93      */
       
    94     void Remove( const TGlxIdSpaceId& aIdSpaceId, const TGlxMediaId& aItemId );
       
    95 
       
    96     /**
       
    97      * Remove any pointers to the media object at the specified index
       
    98      * @param aIndex index of media object from which to remove a reference
       
    99      */
       
   100     void RemoveReference( TInt aIndex );
       
   101 
       
   102     /** 
       
   103      * @return count of items in the list
       
   104      */
       
   105     inline TInt Count() const;
       
   106 
       
   107     /** 
       
   108      * @return item at index
       
   109      */
       
   110     inline TGlxMedia& Item( TInt aIndex );
       
   111 
       
   112     /** 
       
   113      * @param aId Id of item for which index is needed
       
   114      * @return index of item with id aId or KErrNotFound
       
   115      */
       
   116     TInt Index( const TGlxIdSpaceId& aIdSpaceId, const TGlxMediaId& aId ) const;
       
   117 
       
   118 private:
       
   119     /**
       
   120      * Constructor
       
   121      * @param aIdSpaceId id of id space in which list item ids are
       
   122      * @param aObserver Observer to be notified
       
   123      * @param aMediaUser User class of media objects - media objects that 
       
   124      *                   this list links to will be linked to the user, so that 
       
   125      *                   cache manager is able to quickly access the media lists 
       
   126      *                   that use particular media objects
       
   127      */
       
   128     CGlxItemList( const TGlxIdSpaceId& aIdSpaceId,
       
   129         MGlxItemListObserver& aObserver, MGlxMediaUser& aMediaUser );
       
   130            
       
   131     /**
       
   132      * Process differences between source and current list
       
   133      * @param aSource source list 
       
   134      * @param aStrategy strategy object that contains the logic of how to
       
   135      *                  process the differences that are found
       
   136      */
       
   137     void ProcessDifferences( const CMPXCollectionPath& aSource, 
       
   138             NGlxItemList::MListModificationStrategy& aStrategy );
       
   139 
       
   140     /**
       
   141      * Find the first matches in the source and current lists.
       
   142      * @param aInfo object that contains start-search-from indexes in source 
       
   143      *              and current list
       
   144      * @param aSource source list
       
   145      * @param aSourceMatchIndex On return, contains the index of matching 
       
   146      *                          source item, or if not found, the count of
       
   147      *                          source list. (Returning count simplifies 
       
   148      *                          client functions algorithm)
       
   149      * @param aTargetMatchIndex On return, contains the index of matching 
       
   150      *                          target item, or if not found, the count of
       
   151      *                          target (current) list. (Returning count 
       
   152      *                          simplifies client functions algorithm)
       
   153      */
       
   154     void FindMatchingItems( const NGlxItemList::TDifferenceInfo& aInfo, 
       
   155         const CMPXCollectionPath& aSource, TInt& aSourceMatchIndex, 
       
   156         TInt& aTargetMatchIndex );
       
   157         
       
   158     /**
       
   159      * Process difference that would require removing items to eliminate.
       
   160      * Forwards the actual "remove" request to the modification strategy
       
   161      * @param aTargetMatchIndex Index until which items need to be removed
       
   162      * @param aInfo Info of indexes needed to remove the items.
       
   163      *              Strategy can modify these indexes
       
   164      * @param aStrategy strategy object that contains the logic of how to
       
   165      *                  process the differences that are found
       
   166      */
       
   167     void ProcessRemove( TInt aTargetMatchIndex, NGlxItemList::TDifferenceInfo& aInfo, 
       
   168             NGlxItemList::MListModificationStrategy& aStrategy );
       
   169             
       
   170     /**
       
   171      * Process difference that would require inserting items to eliminate.
       
   172      * Forwards the actual "insert" request to the modification strategy
       
   173      * @param aSourceMatchIndex Index to which items need to be copies
       
   174      * @param aInfo Info of indexes needed to insert the items.
       
   175      *              Strategy can modify these indexes
       
   176      * @param aStrategy strategy object that contains the logic of how to
       
   177      *                  process the differences that are found
       
   178      */
       
   179     void ProcessInsert( TInt aSourceMatchIndex, NGlxItemList::TDifferenceInfo& aInfo, 
       
   180             NGlxItemList::MListModificationStrategy& aStrategy );
       
   181 
       
   182     /** 
       
   183      * @return item at index, non-const
       
   184      */
       
   185     inline TGlxMedia& operator[] ( TInt aIndex );
       
   186     
       
   187 private:
       
   188     /// Media items in this list
       
   189     RArray< TGlxMedia > iItems;
       
   190     
       
   191     /// The id of the "space" of unique item ids 
       
   192     TGlxIdSpaceId iIdSpaceId;
       
   193     
       
   194     /// User of media objects. Used for building a link from media object 
       
   195     /// (CGlxMedia) to its used when building a link from item (TGlxMedia) 
       
   196     /// to media object
       
   197     MGlxMediaUser& iMediaUser;
       
   198     
       
   199     /// Observer for changes
       
   200     MGlxItemListObserver& iObserver; 
       
   201 
       
   202     __DECLARE_TEST;
       
   203     };
       
   204 
       
   205 #include "glxitemlist.inl" 
       
   206     
       
   207 #endif // __C_GLXITEMLIST_H__