photosgallery/viewframework/medialists/inc/glxthumbnailcontext.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:    Fetch context to retrieve thumbnails
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_GLXTHUMBNAILCONTEXT_H
       
    22 #define C_GLXTHUMBNAILCONTEXT_H
       
    23 
       
    24 #include <e32std.h>
       
    25 #include "mglxfetchcontext.h"
       
    26 #include "glxmedialistiterator.h"
       
    27 #include <mglxresolutionchangeobserver.h>
       
    28 
       
    29 // Forward declarations
       
    30 
       
    31 class CGlxAttributeContext;
       
    32 class CGlxDRMUtility;
       
    33 class CGlxResolutionUtility;
       
    34 class MGlxCache;
       
    35 class MGlxMediaList;
       
    36 class TGlxMedia;
       
    37 
       
    38 /**
       
    39  *  CGlxThumbnailContext
       
    40  *
       
    41  *  Fetch context to retrieve thumbnails
       
    42  *
       
    43  *  @lib glxmedialists.lib
       
    44  */
       
    45 class CGlxThumbnailContext : public CBase, public MGlxFetchContext,
       
    46         public MGlxResolutionChangeObserver
       
    47 	{
       
    48 public:
       
    49     /**
       
    50 	 * Constructor
       
    51 	 * @param aIterator Iterator that determines the order of thumbnail 
       
    52 	 *  	  retrieval and for which items thumbnails are and are not retrieved
       
    53 	 */
       
    54 	IMPORT_C static CGlxThumbnailContext* NewL(MGlxMediaListIterator* aIterator);
       
    55 
       
    56 	/**
       
    57 	 * Constructor
       
    58 	 * @param aIterator Iterator that determines the order of thumbnail 
       
    59 	 *  	  retrieval and for which items thumbnails are and are not retrieved
       
    60 	 */
       
    61 	IMPORT_C CGlxThumbnailContext(MGlxMediaListIterator* aIterator);
       
    62 	IMPORT_C ~CGlxThumbnailContext();
       
    63 
       
    64 	/**
       
    65 	 * Adds a fetch specification for an individual item
       
    66 	 * @param aWidth the width of required bitmap. The context
       
    67 	 *				 may retrieve first a thumbnail of difference size
       
    68 	 *				 if it thinks it helps user experience.
       
    69 	 * @param aHeight the width of required bitmap. 
       
    70 	 * @param aFocusOffset Delta to focus. 0 means focus.
       
    71 	 */
       
    72 	IMPORT_C void AddSpecForItemL(TInt aWidth, TInt aHeight, TInt aFocusOffset);
       
    73 
       
    74 	/**
       
    75 	 * Sets the default fetch specification. The context uses this
       
    76 	 * for all items that do not have a specific spec added.
       
    77 	 * @param aWidth the width of required bitmap. The context
       
    78 	 *				 may retrieve first a thumbnail of difference size
       
    79 	 *				 if it thinks it helps user experience.
       
    80 	 * @param aHeight the heigth of required bitmap. 
       
    81 	 */
       
    82 	IMPORT_C void SetDefaultSpec(TInt aWidth, TInt aHeight);
       
    83 
       
    84     /**
       
    85      * Set whether only high quality thumbnails are wanted.
       
    86      * @param aHighQualityOnly ETrue to skip fetching low quality thumbnails.
       
    87      */
       
    88     IMPORT_C void SetHighQualityOnly( TBool aHighQualityOnly );
       
    89 
       
    90 public: // From MGlxFetchContext
       
    91     /// See @ref MGlxFetchContext::AttributeRequestL
       
    92     TInt AttributeRequestL(const MGlxMediaList* aList, RArray<TInt>& aItemIndices, 
       
    93     	RArray<TMPXAttribute>& aAttributes, CMPXAttributeSpecs*& aDetailedSpecs) const;
       
    94 
       
    95     /// See @ref MGlxFetchContext::AllAttributesL
       
    96     void AllAttributesL(const MGlxMediaList* aList, TInt aListIndex, 
       
    97     	RArray<TMPXAttribute>& aAttributes) const;
       
    98 
       
    99     /// See @ref MGlxFetchContext::RequestCountL
       
   100     TInt RequestCountL(const MGlxMediaList* aList) const;
       
   101 
       
   102 protected:
       
   103     /**
       
   104     * 2nd phase construction
       
   105     */
       
   106     void ConstructL();
       
   107 
       
   108 private:    // From MGlxResolutionChangeObserver
       
   109     void HandleResolutionChangedL();
       
   110 
       
   111 private: 
       
   112         /**
       
   113          * Select the best thumbnail for processing
       
   114          *
       
   115          * @param aList pointer to media list
       
   116          * @param aError indication of any errors encountered when selecting item
       
   117          */
       
   118         TInt SelectItemL(const MGlxMediaList* aList, TInt& aError) const;
       
   119 
       
   120         /**
       
   121          * Calculates a score for thumbnail retrieval
       
   122          *
       
   123          * @param aIndexInList index of the item in the list
       
   124          * @param aList pointer to media list
       
   125          * @param aDistance Distance from highest priority index
       
   126          * @param aError indication of any errors encountered when calculating score
       
   127          *
       
   128          * @returns a score of how important processing this item's
       
   129          * 			thumbnail is. The higher, the more important.
       
   130          */
       
   131 	TUint GetThumbnailScoreL(TInt aIndexInList, const MGlxMediaList* aList,
       
   132 		TInt aDistance, TInt& aError) const;
       
   133 
       
   134     /** Item to specify what kind of thumbnail is needed */
       
   135     struct TFetchSpec
       
   136         {
       
   137         inline TFetchSpec() { iPossWidth = 0; iPossHeight = 0; };
       
   138 
       
   139         /** Width of the thumbnail */
       
   140         TReal32 iPossWidth;
       
   141 
       
   142         /** Height of the thumbnail */
       
   143         TReal32 iPossHeight;
       
   144         };
       
   145 
       
   146     /** 
       
   147     * Item to specify what kind of thumbnail is needed 
       
   148     * for which item (compared to focus)
       
   149     */
       
   150     struct TAssignedFetchSpec : public TFetchSpec
       
   151         {
       
   152         inline TAssignedFetchSpec() { iFocusOffset = 0; };
       
   153 
       
   154         /** Compares two specs by focus offset. Used for RArray::Find() */
       
   155         static TBool Match( const TAssignedFetchSpec& aSpec1,
       
   156                             const TAssignedFetchSpec& aSpec2 );
       
   157 
       
   158         /** Delta to focus. If zero, then focused item */
       
   159         TInt iFocusOffset;
       
   160         };
       
   161 
       
   162     /**
       
   163      * Get the fetch spec to be used for a given media item.
       
   164      * @param aListIndex Index of current item
       
   165      * @param aList Pointer to media list
       
   166      * @return Reference to fetch spec to use for the given item.
       
   167      */
       
   168     const TFetchSpec& SpecForIndex(TInt aListIndex,
       
   169                                     const MGlxMediaList* aList) const;
       
   170 
       
   171     /**
       
   172      * Get the size in pixels for a fetch spec.
       
   173      * @param aSpec Reference to fetch spec.
       
   174      * @return Size in pixels for the current screen resolution.
       
   175      */
       
   176     TSize SizeFromSpec( const TFetchSpec& aSpec ) const;
       
   177 
       
   178     /**
       
   179      * Check whether a given item has any full thumbnail attributes.
       
   180      * @param aItem Media item to check.
       
   181      * @return ETrue if a full thumbnail attribute is present.
       
   182      */
       
   183     TBool HasFullThumbnail( const TGlxMedia& aItem ) const;
       
   184 
       
   185     /**
       
   186      * Check DRM status of item at given index. Updates the fetch spec
       
   187      * for an item with invalid DRM
       
   188      * @param aListIndex index of current item
       
   189      * @param aList pointer to media list
       
   190      * @param aSpec reference to fetch spec
       
   191 	 * @return ETrue if the item at index is not protected or has valid rights
       
   192      */
       
   193     TBool CheckDRMStatusL( TInt aListIndex, const MGlxMediaList* aList,
       
   194                                         TSize& aSize ) const;           
       
   195 
       
   196 private:
       
   197     /** Specs applies to individual items */
       
   198     RArray<TAssignedFetchSpec> iSpecs;
       
   199 
       
   200     /** Request spec that is applied to all other items than in iSpecs */
       
   201     TFetchSpec iDefaultSpec;
       
   202 
       
   203     /** Whether to skip fetching low quality thumbnails */
       
   204     TBool iHighQualityOnly;
       
   205 
       
   206     /** Iterator for traversing the list */
       
   207     MGlxMediaListIterator* iIterator;	
       
   208 
       
   209     /** Cache manager interface (owned) */
       
   210     MGlxCache* iCache;
       
   211 
       
   212     /** Utility to translate between pixels and poss units */
       
   213     CGlxResolutionUtility* iResolutionUtility;
       
   214 
       
   215     /** DRM utility for checking rights */
       
   216     CGlxDRMUtility* iDrmUtility;
       
   217 
       
   218     /** Attribute context to fetch DRM attributes */
       
   219     CGlxAttributeContext* iDrmFetchContext;
       
   220     
       
   221     /** Size of the default spec */
       
   222     TSize iDefaultSpecSize;
       
   223     };
       
   224 
       
   225 /**
       
   226  *  CGlxDefaultAttributeContext
       
   227  *
       
   228  *  Fetch context to retrieve MPX attributes starting from focus outward
       
   229  *
       
   230  *  @lib glxmedialists.lib
       
   231  */
       
   232 class CGlxDefaultThumbnailContext : public CGlxThumbnailContext
       
   233 	{
       
   234 public:
       
   235 	IMPORT_C static CGlxDefaultThumbnailContext* NewL();
       
   236 	IMPORT_C ~CGlxDefaultThumbnailContext();
       
   237 
       
   238 	/**
       
   239 	 * Set the range offsets. These determine the outer limits
       
   240 	 * of attributes to be retrieved, compared to current focus in
       
   241 	 * the list
       
   242 	 * If ranges not defined, retrieves the attributes for focused item only
       
   243 	 */
       
   244     IMPORT_C void SetRangeOffsets(TInt aFrontOffset, TInt aRearOffset);
       
   245 
       
   246 private:
       
   247 	CGlxDefaultThumbnailContext();
       
   248 
       
   249 private:
       
   250 	TGlxFromFocusOutwardIterator iFromFocusIterator;	
       
   251 	};
       
   252 
       
   253 #endif // C_GLXTHUMBNAILCONTEXT_H
       
   254