photosgallery/viewframework/commandhandlers/commandhandlerbase/inc/glxmedialistcommandhandler.h
changeset 0 4e91876724a2
child 25 191387a8b767
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:    Media List Command Handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef __C_GLXMEDIALISTCOMMANDHANDLER_H
       
    22 #define __C_GLXMEDIALISTCOMMANDHANDLER_H
       
    23 
       
    24 #include "glxcommandhandler.h"
       
    25 
       
    26 #include <e32base.h>
       
    27 #include <mpxcollectionobserver.h>
       
    28 #include <mpxmediageneraldefs.h>
       
    29 #include <mglxmedialistobserver.h>
       
    30 
       
    31 class MGlxMediaList;
       
    32 class CAknProgressDialog;
       
    33 class MGlxMediaListProvider;
       
    34 class CEikProgressInfo;
       
    35 class UT_CGlxMediaListCommandHandler;
       
    36 class t_cglxcommandhandlercopytohomenetwork;
       
    37     
       
    38 /**
       
    39  * @class CGlxMediaListCommandHandler
       
    40  *  
       
    41  * Command handler that acts on a media list. This class handles basic
       
    42  * and most common command filtering, i.e., checking whether the 
       
    43  * command is active based on a selection
       
    44  *
       
    45  * @ingroup glx_group_command_handlers
       
    46  *
       
    47  * Filters:  
       
    48  *  - Disable if selection contains only system items (see @ref glx_colifspec_medial)
       
    49  *       - This allows disabling commands that are not allowed for system items (such as favourites album)
       
    50  *   - Disable if selection size is too small or too large
       
    51  *      - This allows filtering out an empty view (except for marking commands)
       
    52  *      - This allows filtering out static items (except for marking commands)
       
    53  *      - This allows filtering when other than 1 item has been selected
       
    54  *         - Use case: rename item, and play video
       
    55  *  - Disable for static item 
       
    56  *      - This can be achieved by setting minimum selection lenght to 1 (or more), since
       
    57  *        static items are not part of selection
       
    58  *      - Specific static item disabling should only be required when dealing with marking commands, 
       
    59  *        since static items do not belong to the selection. There is a selection,
       
    60  *        all commands (except marking commands) act on the selected items. If nothing
       
    61  *        is selected, focus is treated as selection. If nothing is selected, and 
       
    62  *        a static item is focused, selection size will be 0.
       
    63  *        Hence, it is faster and simpler to use selection size min and max to filter out 
       
    64  *        static items.
       
    65  *  - Disabling when view is empty can be achieved via min and max selection length, except 
       
    66  *    for marking commands, which need to if view is empty: 
       
    67  *      - (Mark all and Mark multiple need to be available also when there is no selection 
       
    68  *        zero and focus is on a static item, but not if the view is empty, hence a 
       
    69  *        separate check for empty view is needed for marking.)
       
    70  *  - Disable if system item 
       
    71  *  - Disable by item type: Image/video/static item/album/tag
       
    72  *     - Use case: Filter out static items for marking command handler
       
    73  *        
       
    74  * @lib glxviewbase.lib
       
    75  */
       
    76 class CGlxMediaListCommandHandler : public CGlxCommandHandler
       
    77     {
       
    78 public: 
       
    79     /**
       
    80      * Command info. Represents one command id. 
       
    81      * Command is enabled by default, unless member variables are modified
       
    82      */
       
    83     struct TCommandInfo 
       
    84         {
       
    85         /**
       
    86          * Constructor that sets all filters not to apply, so
       
    87          * command is enabled by default
       
    88          */
       
    89         IMPORT_C TCommandInfo(TInt aCommandId);
       
    90 
       
    91         /// Supported command id
       
    92         TInt iCommandId;
       
    93            
       
    94         /// Stop GIF animation before execution
       
    95         TBool iStopAnimationForExecution;
       
    96         
       
    97         /// Disable command if only system items in selection
       
    98         TBool iDisallowSystemItems;
       
    99 
       
   100         /// Disable command if only DRM-protected items in selection
       
   101         TBool iDisallowDRM;
       
   102 
       
   103         /// Disable command if selection smaller than. Default 0.
       
   104         TInt iMinSelectionLength;
       
   105         /// Disable command if selection larger than. Default KMaxTInt.
       
   106         TInt iMaxSelectionLength;
       
   107         
       
   108         /// Enable only if selected container(s) contains this or more items
       
   109         TInt iMinSlideshowPlayableContainedItemCount;
       
   110         
       
   111         /// Filter out animated GIFs
       
   112         TBool iDisallowAnimatedGIFs;
       
   113         
       
   114         /// Disable if <b>focused</b> item is / is not of the category 
       
   115         /// See @ref CGlxMediaListCommandHandler::iCategoryRule
       
   116         /// Default is EMPXNoCategory
       
   117         TMPXGeneralCategory iCategoryFilter;    
       
   118         
       
   119         /// If ETrue, 
       
   120         /// If EFalse, disables command if all items ARE of category
       
   121         /// Default
       
   122         /// See @ref CGlxMediaListCommandHandler::iCategoryFilter
       
   123         enum TCategoryRule 
       
   124             {
       
   125             EIgnore,       // Ignore category
       
   126             ERequireAll,   // disables command if all items are NOT of category
       
   127             EForbidAll     // disables command if all items ARE of category
       
   128             };
       
   129         TCategoryRule iCategoryRule; 
       
   130         
       
   131         /// Viewing Statws. Used to filter what commands are on display
       
   132         /// relative to Browsing or Viewing
       
   133         /// These are bitwise to enable a command to declare more than
       
   134         /// one state at a time.
       
   135         enum TViewingState 
       
   136             {
       
   137             EViewingStateUndefined = 0xFFFFFFFF,
       
   138             EViewingStateBrowse = 0x01,             // Tile View
       
   139             EViewingStateView = 0x02                // Full Screen view
       
   140             };
       
   141         
       
   142         // Records the current viewing state    
       
   143         TViewingState iViewingState;
       
   144         };
       
   145 
       
   146 public:    
       
   147     /**
       
   148      * Destructor
       
   149      */
       
   150     IMPORT_C virtual ~CGlxMediaListCommandHandler();
       
   151 
       
   152     /**
       
   153      * Constructor
       
   154      * @param aMediaListProvider The owner of the media list to use
       
   155      */
       
   156     IMPORT_C CGlxMediaListCommandHandler( MGlxMediaListProvider* aMediaListProvider, 
       
   157     											TBool aIsToolbarCommand = EFalse );
       
   158     
       
   159 public: // From MGlxCommandHandler
       
   160     /// See @ref MGlxCommandHandler::ExecuteL */
       
   161     IMPORT_C virtual TBool ExecuteL(TInt aCommand);
       
   162 
       
   163     /// See @ref MGlxCommandHandler::DynInitMenuPaneL */
       
   164     IMPORT_C virtual void DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane);
       
   165     
       
   166     /**
       
   167      * See @ref MGlxCommandHandler::Deactivate 
       
   168      * Default implementation does nothing
       
   169      */
       
   170     IMPORT_C virtual void Deactivate();
       
   171     
       
   172     /**
       
   173      * See @ref MGlxCommandHandler::OfferKeyEventL 
       
   174      * Default implementation does nothing
       
   175      */
       
   176     IMPORT_C virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
       
   177 
       
   178     /**
       
   179      * See @ref MGlxCommandHandler::PreDynInitMenuPaneL 
       
   180      * Default implementation does nothing
       
   181      * @param aResourceId Menu resource id.
       
   182      */
       
   183 	IMPORT_C virtual void PreDynInitMenuPaneL( TInt aResourceId );
       
   184    	
       
   185     /**
       
   186 	 * See @ref MGlxCommandHandler::GetRequiredAttributesL
       
   187      */
       
   188     IMPORT_C void GetRequiredAttributesL(RArray< TMPXAttribute >& aAttributes, 
       
   189     		                              TBool aFilterUsingSelection,
       
   190     		                              TBool aFilterUsingCommandId,
       
   191     		                              TInt aCommandId = 0) const;
       
   192     
       
   193 protected: 
       
   194     /**
       
   195      * Execute the command, if applicable. Called after basic filtering
       
   196      * @param aCommand The command to handle
       
   197      * @return ETrue iff command was handled
       
   198      * @see BypassFiltersForExecute
       
   199      */
       
   200     virtual TBool DoExecuteL(TInt aCommandId, MGlxMediaList& aList) = 0;
       
   201     
       
   202     /**
       
   203      * See @ref CGlxCommandHandler::DoActivateL 
       
   204      * Default implementation does nothing
       
   205      */
       
   206     IMPORT_C virtual void DoActivateL( TInt aViewId );
       
   207     
       
   208     /**
       
   209      * Check if command is disabled. Allows deriving class to provide
       
   210      * more elaborate filtering that supported by this class.
       
   211      * Default implementation returns EFalse.
       
   212      * @return ETrue if command is disabled
       
   213      */
       
   214     IMPORT_C virtual TBool DoIsDisabled(TInt aCommandId, MGlxMediaList& aList) const;
       
   215 
       
   216     /**
       
   217      * Allow deriving classes to make any further alterations to the menu pane.
       
   218      * Only called on classes with at least on enabled command present in menu
       
   219 	   * @param aResourceId The resource ID of the menu
       
   220 	   * @param aMenuPane The in-memory representation of the menu pane
       
   221 	   * @see BypassFiltersForMenu
       
   222 	   */
       
   223     IMPORT_C virtual void DoDynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane);
       
   224 
       
   225     /**
       
   226      * If deriving class returns true for this, ALL commands will be sent to DoExecuteL
       
   227      * @return Whether to bypass filters for command execution
       
   228      */
       
   229     IMPORT_C virtual TBool BypassFiltersForExecute() const;
       
   230 
       
   231     /**
       
   232      * If deriving class returns true for this, ALL menus will be passed to DoDynInitMenuPaneL
       
   233      * @return Whether to bypass filters for menu initialization
       
   234      */
       
   235     IMPORT_C virtual TBool BypassFiltersForMenu() const;
       
   236     
       
   237     /**
       
   238      * Optionally implemented by deriving classes to specify attributes that should be retrieved
       
   239      * @param aAttributes array to append attributes to.
       
   240      * @param aFilterUsingSelection If ETrue, the deriving class should only append
       
   241      *        attributes relevant to the current selection, If EFalse all attributes
       
   242      *        should be appended.
       
   243      */
       
   244     IMPORT_C virtual void DoGetRequiredAttributesL( RArray<TMPXAttribute>& aAttributes, TBool aFilterUsingSelection) const;
       
   245 
       
   246 protected:
       
   247     /**
       
   248      * Returns a reference to the current media list
       
   249      * @return reference to the current media list
       
   250      */
       
   251     IMPORT_C MGlxMediaList& MediaList();
       
   252 
       
   253     /**
       
   254      * Returns a const reference to the current media list
       
   255      * @return const reference to the current media list
       
   256      */
       
   257     IMPORT_C const MGlxMediaList& MediaList() const;
       
   258     /**
       
   259      * AddCommandL
       
   260      */
       
   261     IMPORT_C void AddCommandL(const TCommandInfo& aCommand);
       
   262 
       
   263     /**
       
   264       * Check if the command handler is currently disabled
       
   265       */
       
   266     IMPORT_C TBool IsDisabledL(TInt aCommandId, MGlxMediaList& aList) const;
       
   267 
       
   268     /** 
       
   269      * @return ETrue if command is handled by this command handler
       
   270      */ 
       
   271     IMPORT_C TBool IsSupported(TInt aCommandId) const;
       
   272 
       
   273     /**
       
   274      * @return the length of selection
       
   275      *         If static item is focused, length is 0
       
   276      *         If list is empty, lenght is 0
       
   277      *         If no items are selected, but a non-static item is focused length is 1
       
   278      */
       
   279     IMPORT_C TInt SelectionLength() const;
       
   280     
       
   281     /**
       
   282      * @return command info by index
       
   283      */
       
   284     IMPORT_C TCommandInfo& CommandInfo(TInt aIndex);
       
   285     
       
   286     /**
       
   287      * @return the current viewing state.
       
   288      */
       
   289 
       
   290     IMPORT_C TCommandInfo::TViewingState ViewingState() const;
       
   291 
       
   292     /**
       
   293      * @return command info by index
       
   294      */
       
   295     const TCommandInfo& CommandInfo(TInt aIndex) const;
       
   296    	
       
   297 private:
       
   298     /**
       
   299      * @return index of command in command info array or KErrNotFound
       
   300      */
       
   301     TInt CommandInfoIndex(TInt aCommandId) const;
       
   302 
       
   303     /**
       
   304      * Check if a given command (menu option) is viewable in the current view
       
   305      * @param aInfo The command in question.
       
   306      * @return ETrue if viewable, EFalse if not.
       
   307      */
       
   308         
       
   309     TBool IsViewable(const TCommandInfo& aInfo) const;
       
   310     
       
   311     /**
       
   312      * Checks to see if the command handler is disabled
       
   313      * based on the selection and IsViewable(). Other
       
   314      * conditions may also disable the command handler.
       
   315      * @param aInfo The command in question.
       
   316      * @return ETrue, if the command handler is disabled
       
   317      * EFalse if the command handler may not be disabled.
       
   318      */
       
   319     TBool IsDisabled(const TCommandInfo& aInfo) const;
       
   320     
       
   321     /**
       
   322 	 * Append required attributes to aAttributes
       
   323 	 * @param aAttributes array to append attributes to.
       
   324 	 * @param aFilterUsingSelection If ETrue, the deriving class should only append
       
   325 	 *        attributes relevant to the current selection, If EFalse all attributes
       
   326 	 *        should be appended.
       
   327 	 */
       
   328     void GetRequiredAttributesL(RArray< TMPXAttribute >& aAttributes, 
       
   329                                      TBool aFilterUsingSelection) const;
       
   330     
       
   331 private:
       
   332 
       
   333     /** Provider of media list */
       
   334     MGlxMediaListProvider* iMediaListProvider;
       
   335     
       
   336     /** Command info array */
       
   337     RArray<TCommandInfo> iCommandInfoArray;
       
   338     
       
   339     /** Current viewing state */
       
   340     TCommandInfo::TViewingState iCurrentViewingState;
       
   341     
       
   342     friend class UT_CGlxMediaListCommandHandler;
       
   343     friend class t_cglxcommandhandlercopytohomenetwork;
       
   344     };
       
   345     
       
   346 #endif // __C_GLXMEDIALISTCOMMANDHANDLER_H