ui/uiengine/medialists/src/glxthumbnailutility.cpp
changeset 23 74c9f037fd5d
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:    Common utility for thumbnail attributes
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // my include
       
    22 #include "glxthumbnailutility.h"
       
    23 
       
    24 // system includes
       
    25 #include <glxtracer.h>
       
    26 
       
    27 // user includes
       
    28 #include "glxmedia.h"
       
    29 #include "glxthumbnailattributeinfo.h"
       
    30 
       
    31 // ---------------------------------------------------------------------------
       
    32 // ClosestThumbnail
       
    33 // ---------------------------------------------------------------------------
       
    34 //
       
    35 EXPORT_C /*static*/ TInt GlxThumbnailUtility::ClosestThumbnail(
       
    36         const TSize& aDesiredSize, const CGlxMedia& aMedia, TBool aDrmValid )
       
    37     {
       
    38     TRACER("GlxThumbnailUtility::ClosestThumbnail");
       
    39     
       
    40     TInt selectedIndex = KErrNotFound;
       
    41     TInt selectedQuality = 0;
       
    42     TSize selectedSize;     // Default constructor sets to zero
       
    43     TInt count = aMedia.Count();
       
    44 
       
    45     for ( TInt i = 0; i < count; i++ )
       
    46         {
       
    47         const TMPXAttribute& attr( aMedia.Attribute( i ) );
       
    48 
       
    49         // is it a thumbnail
       
    50         if ( GlxThumbnailUtility::IsFullThumbnail( attr ))
       
    51             {
       
    52             const CGlxThumbnailAttribute* thumbnail
       
    53                     = static_cast<const CGlxThumbnailAttribute*>(
       
    54                                                 aMedia.ValueCObject( attr ) );
       
    55 
       
    56             if ( thumbnail )
       
    57                 {
       
    58                 // Check to see if this is to be the preferred attribute
       
    59                 TBool preferThis = ETrue;
       
    60                 TInt quality = thumbnail->iThumbnailQuality;
       
    61                 TSize size( thumbnail->iDimensions );
       
    62 
       
    63                 // Compare aspect ratios of required size and
       
    64                 // this size to decide if using heights or widths
       
    65                 if ( size.iHeight * aDesiredSize.iWidth
       
    66                         >= aDesiredSize.iHeight * size.iWidth )
       
    67                     {
       
    68                     // using heights
       
    69                     preferThis = PreferThisAttribute( size.iHeight,
       
    70                             selectedSize.iHeight, aDesiredSize.iHeight,
       
    71                             quality, selectedQuality, aDrmValid );
       
    72                     }
       
    73                 else
       
    74                     {
       
    75                     // using widths
       
    76                     preferThis = PreferThisAttribute( size.iWidth,
       
    77                             selectedSize.iWidth, aDesiredSize.iWidth,
       
    78                             quality, selectedQuality, aDrmValid );
       
    79                     }
       
    80 
       
    81                 if ( preferThis )
       
    82                     {
       
    83                     // Set this one as preferred so far
       
    84                     selectedIndex = i;
       
    85                     selectedQuality = quality;
       
    86                     selectedSize = size;
       
    87                     }
       
    88                 }
       
    89             }
       
    90         }
       
    91 
       
    92     return selectedIndex;
       
    93     }
       
    94 
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // IsFullThumbnail
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 EXPORT_C /*static*/ TBool GlxThumbnailUtility::IsFullThumbnail(const TMPXAttribute& aAttr)
       
   101 	{
       
   102 	TRACER("GlxThumbnailUtility::IsFullThumbnail");
       
   103 	
       
   104 	return ((KGlxMediaIdThumbnail == aAttr.ContentId()) 
       
   105     			&& GlxIsFullThumbnailAttribute(aAttr.AttributeId()));
       
   106 	}
       
   107 
       
   108 	
       
   109 // -----------------------------------------------------------------------------
       
   110 // PreferThisAttribute
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 /*static*/ TBool GlxThumbnailUtility::PreferThisAttribute(
       
   114                 TInt aThisDimen, TInt aSelectedDimen, TInt aReqDimen,
       
   115                 TInt aThisQuality, TInt aSelectedQuality, TBool aDrmValid )
       
   116     {
       
   117     TRACER("GlxThumbnailUtility::PreferThisAttribute");
       
   118     
       
   119     TBool preferThis = ETrue;
       
   120 
       
   121     if ( aThisDimen == aSelectedDimen )
       
   122         {
       
   123         // Only interested if better quality 
       
   124         preferThis = ( aThisQuality > aSelectedQuality );
       
   125         }
       
   126     else if ( aThisDimen < aReqDimen )
       
   127         {
       
   128         // Only interested if this one is larger than the selected one
       
   129         preferThis = ( aSelectedDimen < aThisDimen );
       
   130         }
       
   131     else if ( aThisDimen > aReqDimen )
       
   132         {
       
   133         // Only interested if the selected one is smaller than requested
       
   134         // or this one is smaller than the selected one
       
   135         preferThis = ( aDrmValid &&
       
   136             ( aSelectedDimen < aReqDimen || aThisDimen < aSelectedDimen ) );
       
   137         }
       
   138     else    // aThisDimen == aReqDimen
       
   139         {
       
   140         // The right size, so choose it
       
   141         }
       
   142 
       
   143     return preferThis;
       
   144     }