photosgallery/viewframework/dataprovider/src/glxthumbnailvarianttype.cpp
changeset 0 4e91876724a2
child 3 9a9c174934f5
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:    Makes the Decision to Create Thumbnail Texture or Icon Texture
       
    15 *                 Considering Drm Validity and Thumbnail Availabilty
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "glxmulthumbnailvarianttype.h"
       
    23 #include <data_caging_path_literals.hrh>
       
    24 #include <alf/ialfvarianttype.h>
       
    25 #include "glxuiutility.h"
       
    26 #include "glxtexturemanager.h"
       
    27 #include <glxerrormanager.h>
       
    28 #include <glxmedia.h>
       
    29 #include <glxthumbnailattributeinfo.h>
       
    30 #include <glxicons.mbg>
       
    31 #include <glxlog.h>    // Logging
       
    32 #include <glxtracer.h>
       
    33 #include <glxdrmutility.h>
       
    34 #include <mglxmedialist.h>
       
    35 _LIT(KGlxIconsFilename, "glxicons.mif");
       
    36 
       
    37 
       
    38 // ----------------------------------------------------------------------------
       
    39 // NewL
       
    40 // ----------------------------------------------------------------------------
       
    41 //
       
    42 GlxThumbnailVariantType* GlxThumbnailVariantType::NewL( const TGlxMedia& aMedia, const TSize& aSize, 
       
    43 	TBool aIsFocused  )
       
    44 	{
       
    45 	TRACER("GlxThumbnailVariantType::NewL");
       
    46 	GlxThumbnailVariantType* self = GlxThumbnailVariantType::NewLC( aMedia, 
       
    47 		aSize, aIsFocused );
       
    48 	CleanupStack::Pop( self );
       
    49 	return self;
       
    50 	}
       
    51 
       
    52 // ----------------------------------------------------------------------------
       
    53 // NewLC
       
    54 // ----------------------------------------------------------------------------
       
    55 //
       
    56 GlxThumbnailVariantType* GlxThumbnailVariantType::NewLC( const TGlxMedia& aMedia, const TSize& aSize, 
       
    57 	TBool aIsFocused )
       
    58 	{
       
    59 	TRACER("GlxThumbnailVariantType::NewLC");
       
    60 	
       
    61 	GlxThumbnailVariantType* self = new ( EMM ) GlxThumbnailVariantType(
       
    62 		aMedia, aSize, aIsFocused );
       
    63 	CleanupStack::PushL( self );
       
    64 	self->ConstructL( aMedia, aSize, aIsFocused );
       
    65 	return self;
       
    66 	}
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // constructor
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 GlxThumbnailVariantType::GlxThumbnailVariantType( const TGlxMedia& /*aMedia*/, 
       
    73     const TSize& /*aSize*/, TBool /*aIsFocused*/ )
       
    74     {
       
    75     
       
    76     }
       
    77 
       
    78 // ----------------------------------------------------------------------------
       
    79 // ConstructL
       
    80 // ----------------------------------------------------------------------------
       
    81 //
       
    82 void GlxThumbnailVariantType::ConstructL( const TGlxMedia& aMedia, const TSize& aSize, 
       
    83 		TBool aIsFocused )   
       
    84 	{
       
    85 
       
    86 	TRACER("GlxThumbnailVariantType::ConstructL");    
       
    87     GLX_DEBUG2("GlxThumbnailVariantType::ConstructL Media Id=%d", aMedia.Id().Value());	
       
    88     iUiUtility = CGlxUiUtility::UtilityL();
       
    89     
       
    90     TBool drm = EFalse;
       
    91     TGlxMediaGeneralRightsValidity isValid = EGlxDrmRightsValidityUnknown;
       
    92 	
       
    93 	if(aMedia.GetDrmProtected(drm))
       
    94         {
       
    95         GLX_DEBUG1("GlxThumbnailVariantType::ConstructL CGlxDRMUtility::InstanceL");        
       
    96         iDrmUtility = CGlxDRMUtility::InstanceL();
       
    97         aMedia.GetDrmValidity(isValid);
       
    98         }
       
    99 
       
   100 	TBool fsTnmAvailable = HasRelevantThumbnail(aMedia,aSize);    
       
   101     
       
   102     TIconInfo icon;
       
   103     
       
   104     TSize defaultSize = iUiUtility->GetGridIconSize();
       
   105     
       
   106     TFileName resFile(KDC_APP_BITMAP_DIR);
       
   107 	resFile.Append(KGlxIconsFilename);
       
   108 	
       
   109 	TInt frameCount = 0;
       
   110 	aMedia.GetFrameCount(frameCount);
       
   111 	
       
   112 	const TDesC& uri = aMedia.Uri();
       
   113     GLX_DEBUG2("GlxThumbnailVariantType::ConstructL() uri.Length()=%d", uri.Length());  
       
   114     
       
   115 	TInt thumbnailError = GlxErrorManager::HasAttributeErrorL(
       
   116                                 aMedia.Properties(), KGlxMediaIdThumbnail );
       
   117                                 	
       
   118 	TInt err = KErrNone;
       
   119 	TBool expired = EFalse;
       
   120   
       
   121     if ( aIsFocused && frameCount > 1 && (fsTnmAvailable) )
       
   122         {
       
   123         GLX_DEBUG1("GlxThumbnailVariantType::CreateAnimatedGifTextureL");
       
   124         TRAP( err, mTextureId = iUiUtility->GlxTextureManager().
       
   125             CreateAnimatedGifTextureL( uri, aSize ).Id() );
       
   126         }
       
   127     //URI length could be zero for Media Id based Thumbnail fetch
       
   128     else if ( fsTnmAvailable ) 
       
   129 	    {
       
   130 	    GLX_DEBUG1("GlxThumbnailVariantType::CreateThumbnailTextureL");
       
   131 	    TMPXGeneralCategory cat = aMedia.Category();
       
   132 	    if(drm)
       
   133             {
       
   134             expired = iDrmUtility->CheckOpenRightsL(uri, (cat == EMPXImage));
       
   135             if( expired )
       
   136                 {
       
   137                 // 200 is to Consume rights only while opening DRM items 
       
   138                 // in Cover Flow Widget
       
   139                 if ( aSize.iWidth > 200 && aIsFocused)
       
   140                     {  
       
   141                     ConsumeDRMRightsL( aMedia );                
       
   142                     }
       
   143                 if ( isValid )
       
   144                     {
       
   145                     // Fix for EABI-7RL9DD
       
   146                     // Replaced defaultSize with aSize
       
   147                     TRAP( err, mTextureId = iUiUtility->GlxTextureManager().CreateThumbnailTextureL(
       
   148                                                     aMedia, aMedia.IdSpaceId(), aSize, this ).Id() );
       
   149                     }
       
   150                 }
       
   151             else
       
   152                 {
       
   153                 TRAP( err, mTextureId = iUiUtility->GlxTextureManager().CreateIconTextureL( 
       
   154                                                     EMbmGlxiconsQgn_prop_image_notcreated, resFile, defaultSize ).Id() );
       
   155                 // check if rights have expired
       
   156                 // show expiry note
       
   157                 if( aSize.iWidth > 200  && aIsFocused )
       
   158                     {
       
   159                     iDrmUtility->ShowRightsInfoL(uri);
       
   160                     }                              
       
   161                 }
       
   162             } 
       
   163 		else
       
   164 		    {
       
   165 			TRAP( err, mTextureId = iUiUtility->GlxTextureManager().CreateThumbnailTextureL( 
       
   166 				aMedia, aMedia.IdSpaceId(), aSize, this ).Id() );
       
   167 		    }
       
   168 	    }
       
   169     else if ( aMedia.GetIconInfo(icon) )
       
   170 	    {  
       
   171 	    GLX_DEBUG1("GlxThumbnailVariantType::CreateIconTextureL");
       
   172         TRAP( err, mTextureId = iUiUtility->GlxTextureManager().CreateIconTextureL( 
       
   173     	    icon.bitmapId, resFile, defaultSize ).Id() );
       
   174         }
       
   175 	else if ( KErrNone == thumbnailError || KErrArgument == thumbnailError || ( drm && isValid == EGlxDrmRightsInvalid ) )
       
   176 	          
       
   177 	    {    
       
   178 		//Try and see if we can scale and show the grid tnm else show the default
       
   179 	    TBool isGridTnmShown = EFalse;		
       
   180 	    if(HasRelevantThumbnail(aMedia,defaultSize))
       
   181 	        {
       
   182 	        TSize origSize;
       
   183 	        if(aMedia.GetDimensions(origSize))
       
   184                 {
       
   185 				//Currently scaling the grid TNM's only if their original size > grid size.
       
   186 				//Have to relook at this.
       
   187                 if(origSize.iWidth > defaultSize.iWidth && origSize.iHeight > defaultSize.iHeight)
       
   188                       {
       
   189 					  GLX_DEBUG1("GlxThumbnailVariantType::CreateIconTextureL::ScaledTnm");
       
   190                       TRAP( err, mTextureId = iUiUtility->GlxTextureManager().CreateThumbnailTextureL( 
       
   191                                 aMedia, aMedia.IdSpaceId(), aSize, this, ETrue ).Id() );
       
   192 					  if(err == KErrNone)
       
   193 					      {
       
   194 	                      isGridTnmShown = ETrue;
       
   195 						  }
       
   196                       }
       
   197                 }
       
   198 	        }
       
   199 	    if(!isGridTnmShown)
       
   200 	        {	    
       
   201 			GLX_DEBUG1("GlxThumbnailVariantType::CreateThumbnailTextureL::Default");
       
   202 	        TRAP( err, mTextureId = iUiUtility->GlxTextureManager().CreateIconTextureL( 
       
   203 	                EMbmGlxiconsQgn_prop_image_notcreated, resFile, defaultSize ).Id() );
       
   204 	        }
       
   205 	    }
       
   206 	else
       
   207 		{
       
   208 		GLX_DEBUG1("GlxThumbnailVariantType::CreateIconTextureL::Corrupt");
       
   209 	    TRAP( err, mTextureId = iUiUtility->GlxTextureManager().CreateIconTextureL( 
       
   210 	    	EMbmGlxiconsQgn_prop_image_corrupted, resFile, defaultSize ).Id() );
       
   211 		}
       
   212     
       
   213      if ( KErrNone != err )
       
   214         {
       
   215 		GLX_DEBUG2("GlxThumbnailVariantType::ConstructL() ERROR err=%d", err);
       
   216         throw std::bad_alloc();
       
   217         }
       
   218     }
       
   219  
       
   220 void GlxThumbnailVariantType::ConsumeDRMRightsL( const TGlxMedia& aMedia )
       
   221     {
       
   222     TRACER("GlxThumbnailVariantType::ConsumeDRMRightsL");
       
   223     
       
   224     const CGlxMedia* media = aMedia.Properties();
       
   225     
       
   226     if(media)
       
   227         {
       
   228         if(aMedia.IsDrmProtected())
       
   229             {
       
   230     
       
   231             TMPXGeneralCategory cat = aMedia.Category();
       
   232             const TDesC& uri = aMedia.Uri();
       
   233             if( cat != EMPXNoCategory && uri.Length() > 0 )
       
   234                 {
       
   235                     
       
   236                 // check if rights have expired
       
   237                 TBool expired = !iDrmUtility->CheckOpenRightsL(uri, (cat == EMPXImage));
       
   238                                     
       
   239                 if(expired)
       
   240                     {
       
   241                     return;
       
   242                     }
       
   243                 
       
   244                 TSize size;
       
   245                 if(EMPXImage == cat && aMedia.GetDimensions(size))          
       
   246                     {                    
       
   247                     // check size
       
   248                     TSize bmpSize = ThumbnailSize(media);
       
   249                     
       
   250                     if(ConsumeRightsBasedOnSize(size, bmpSize))
       
   251                         {
       
   252                         // pass URI to DRM utility
       
   253                         iDrmUtility->ConsumeRightsL(uri);                        
       
   254                         }       
       
   255                     }
       
   256                 }     
       
   257             }
       
   258         else
       
   259             {
       
   260             // not an DRM'd item no need to check again             
       
   261             }
       
   262         }
       
   263     
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // ConsumeRightsBasedOnSize - check if DRM rights should be consumed
       
   268 // -----------------------------------------------------------------------------
       
   269 //    
       
   270 TBool GlxThumbnailVariantType::ConsumeRightsBasedOnSize(
       
   271                                        TSize aImageSize, TSize aBitmapSize)
       
   272     {
       
   273     TRACER("CGlxCommandHandlerDrm::ConsumeRightsBasedOnSize");
       
   274     
       
   275     TBool drmRightsChecked = EFalse;
       
   276     // minimum size (111 x 83)
       
   277     TInt minSize = KGlxThumbnailDrmWidth * KGlxThumbnailDrmHeight;
       
   278     //TInt minSize =  111*83 ;
       
   279     // size of actual image
       
   280     TInt imgSize = aImageSize.iWidth * aImageSize.iHeight;
       
   281     
       
   282     // bitmap size
       
   283     TInt bmpSize = aBitmapSize.iWidth * aBitmapSize.iHeight;
       
   284     
       
   285     // size of HUI display
       
   286     TSize dispSize = iUiUtility->DisplaySize();
       
   287     
       
   288     
       
   289     if(dispSize.iWidth>0 && dispSize.iHeight>0)
       
   290         {
       
   291         TReal widthRatio = (TReal)aImageSize.iWidth/(TReal)dispSize.iWidth;
       
   292         TReal heightRatio = (TReal)aImageSize.iHeight/(TReal)dispSize.iHeight;
       
   293         
       
   294         if(widthRatio > heightRatio)
       
   295             {
       
   296             dispSize.iHeight = aImageSize.iHeight / widthRatio;
       
   297             }
       
   298         else
       
   299             {
       
   300             if(heightRatio>0)
       
   301                 {
       
   302                 dispSize.iWidth = aImageSize.iWidth / heightRatio;
       
   303                 }
       
   304             }
       
   305         }     
       
   306         
       
   307     TInt visSize2 = dispSize.iWidth * dispSize.iHeight;
       
   308     
       
   309     // if thumbnail is smaller than visual use this for comparison
       
   310     if(bmpSize < visSize2)
       
   311         {
       
   312         visSize2 = bmpSize;
       
   313         }
       
   314     
       
   315     // is bmp smaller than 1/4 of image size    
       
   316     if(imgSize/4 < minSize)
       
   317         {
       
   318         minSize = imgSize/4;
       
   319         }   
       
   320     
       
   321     if(visSize2 >= minSize)
       
   322         {        
       
   323         drmRightsChecked = ETrue;
       
   324         }
       
   325     
       
   326     return drmRightsChecked;
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // ThumbnailSizeAndQuality - search for largest available thumbnail
       
   331 // -----------------------------------------------------------------------------
       
   332 // 
       
   333 TSize GlxThumbnailVariantType::ThumbnailSize(const CGlxMedia* aMedia)
       
   334     {
       
   335     TRACER("CGlxCommandHandlerDrm::ThumbnailSize");
       
   336     TSize bmpSize(0,0);
       
   337     
       
   338     TArray<TMPXAttribute> attr = aMedia->Attributes();
       
   339     
       
   340     TInt selectedHeight = 0;
       
   341     TInt selectedWidth = 0;
       
   342     
       
   343     TInt count = attr.Count();
       
   344     for(TInt i=0; i<count; i++)
       
   345         {
       
   346         
       
   347         if ( KGlxMediaIdThumbnail == attr[i].ContentId()
       
   348             && GlxIsFullThumbnailAttribute(attr[i].AttributeId()) )
       
   349             {
       
   350             // Get selected Quality, height and width from attribute
       
   351             const CGlxThumbnailAttribute* thumbAtt =  
       
   352                     static_cast<const CGlxThumbnailAttribute*>
       
   353                          (aMedia->ValueCObject( attr[i]));
       
   354                          
       
   355             if(thumbAtt)
       
   356                 {
       
   357                 
       
   358                 selectedHeight = thumbAtt->iDimensions.iHeight;
       
   359                 selectedWidth = thumbAtt->iDimensions.iWidth;
       
   360                 
       
   361                 if((selectedHeight * selectedWidth) > 
       
   362                     (bmpSize.iHeight * bmpSize.iWidth))
       
   363                     {
       
   364                     bmpSize.iWidth = selectedWidth;
       
   365                     bmpSize.iHeight = selectedHeight;
       
   366                     }
       
   367                 }
       
   368             }
       
   369         }
       
   370     return bmpSize;
       
   371     }
       
   372 // ----------------------------------------------------------------------------
       
   373 // destructor
       
   374 // ----------------------------------------------------------------------------
       
   375 //
       
   376 GlxThumbnailVariantType::~GlxThumbnailVariantType() 
       
   377     {
       
   378     TRACER("GlxThumbnailVariantType::~GlxThumbnailVariantType");
       
   379     if(  iDrmUtility )
       
   380         {
       
   381         iDrmUtility->Close();
       
   382         }
       
   383     
       
   384     if ( iUiUtility)
       
   385 		{
       
   386 //		iUiUtility->GlxTextureManager().RemoveTexture( mTextureId );
       
   387 		iUiUtility->Close ();
       
   388 		}
       
   389     }
       
   390     
       
   391     
       
   392 void GlxThumbnailVariantType::TextureContentChangedL( TBool /*aHasContent*/ , CAlfTexture* /*aNewTexture*/)
       
   393     {
       
   394     
       
   395     }
       
   396 // ----------------------------------------------------------------------------
       
   397 // integer
       
   398 // ----------------------------------------------------------------------------
       
   399 //
       
   400 int GlxThumbnailVariantType::integer() const
       
   401     {
       
   402     TRACER("GlxThumbnailVariantType::integer");
       
   403     return mTextureId;
       
   404     }
       
   405 
       
   406 // ----------------------------------------------------------------------------
       
   407 // HasRelevantThumbnail
       
   408 // ----------------------------------------------------------------------------
       
   409 //
       
   410 TBool GlxThumbnailVariantType::HasRelevantThumbnail(const TGlxMedia& aMedia, 
       
   411                                                     const TSize& aSize)
       
   412     {
       
   413     TRACER("GlxThumbnailVariantType::HasRelevantThumbnail()");
       
   414     
       
   415     TMPXAttribute tnAttribQuality(KGlxMediaIdThumbnail, 
       
   416                                      GlxFullThumbnailAttributeId( ETrue, 
       
   417                                      aSize.iWidth, aSize.iHeight ) );                                           
       
   418 
       
   419     TMPXAttribute tnAttribSpeed(KGlxMediaIdThumbnail, 
       
   420                                      GlxFullThumbnailAttributeId( EFalse, 
       
   421                                      aSize.iWidth, aSize.iHeight ) );
       
   422     
       
   423     const CGlxThumbnailAttribute* qualityTn = aMedia.ThumbnailAttribute(
       
   424             tnAttribQuality );
       
   425     const CGlxThumbnailAttribute* speedTn = aMedia.ThumbnailAttribute(
       
   426             tnAttribSpeed );
       
   427     if ( qualityTn || speedTn )
       
   428         {
       
   429         GLX_LOG_INFO("GlxThumbnailVariantType::HasRelevantThumbnail() - TN avail");
       
   430         return ETrue;
       
   431         }
       
   432     return EFalse;
       
   433     }
       
   434 
       
   435 // ----------------------------------------------------------------------------
       
   436 // type
       
   437 // ----------------------------------------------------------------------------
       
   438 //
       
   439 Alf::IMulVariantType::TMulType GlxThumbnailVariantType::Type() const
       
   440     {
       
   441     TRACER("GlxThumbnailVariantType::type");
       
   442     return EInt;
       
   443     }
       
   444 
       
   445 // ----------------------------------------------------------------------------
       
   446 // NewL
       
   447 // ----------------------------------------------------------------------------
       
   448 //
       
   449 GlxIconVariantType* GlxIconVariantType::NewL(TInt aIconId, TFileName aFileName,
       
   450                                                            const TSize& aSize)
       
   451 	{
       
   452 	TRACER("GlxIconVariantType::NewL");
       
   453 	GlxIconVariantType* self = GlxIconVariantType::NewLC( aIconId, 
       
   454 			aFileName, aSize );
       
   455 	CleanupStack::Pop( self );
       
   456 	return self;
       
   457 	}
       
   458 	
       
   459 // ----------------------------------------------------------------------------
       
   460 // NewLC
       
   461 // ----------------------------------------------------------------------------
       
   462 //
       
   463 GlxIconVariantType* GlxIconVariantType::NewLC( TInt aIconId, TFileName aFileName, const TSize& aSize )
       
   464 	{
       
   465 	TRACER("GlxIconVariantType::NewLC");
       
   466 	GlxIconVariantType* self = new ( EMM ) GlxIconVariantType( aIconId, 
       
   467 			aFileName, aSize );
       
   468 	CleanupStack::PushL( self );
       
   469 	self->ConstructL( aIconId, aFileName, aSize );
       
   470 	return self;
       
   471 	
       
   472 	}
       
   473 	
       
   474 // ----------------------------------------------------------------------------
       
   475 // ConstructL
       
   476 // ----------------------------------------------------------------------------
       
   477 //	
       
   478 void GlxIconVariantType::ConstructL( TInt aIconId, TFileName aFileName, 
       
   479                                      const TSize& aSize )
       
   480 	{
       
   481     TRACER("GlxIconVariantType::ConstructL");
       
   482     iUiUtility = CGlxUiUtility::UtilityL();
       
   483     
       
   484     TRAPD( err, mIconId = iUiUtility->GlxTextureManager().CreateIconTextureL( 
       
   485             aIconId, aFileName, aSize).Id() );
       
   486         
       
   487     if ( KErrNone != err )
       
   488         {
       
   489         throw std::bad_alloc();
       
   490         }
       
   491 	}
       
   492 
       
   493 // ----------------------------------------------------------------------------
       
   494 // constructor
       
   495 // ----------------------------------------------------------------------------
       
   496 //
       
   497 GlxIconVariantType::GlxIconVariantType( TInt /*aIconId*/, TFileName /*aFileName*/,
       
   498 	const TSize& /*aSize*/ )
       
   499     {
       
   500     
       
   501     }
       
   502     
       
   503 // ----------------------------------------------------------------------------
       
   504 // destructor
       
   505 // ----------------------------------------------------------------------------
       
   506 //
       
   507 GlxIconVariantType::~GlxIconVariantType() 
       
   508     {
       
   509    
       
   510     TRACER("GlxIconVariantType::~GlxIconVariantType");
       
   511 	if ( iUiUtility)
       
   512 		{
       
   513 //		iUiUtility->GlxTextureManager().RemoveTexture( mTextureId );
       
   514 		iUiUtility->Close ();
       
   515 		}
       
   516     }
       
   517     
       
   518 // ----------------------------------------------------------------------------
       
   519 // integer
       
   520 // ----------------------------------------------------------------------------
       
   521 //
       
   522 int GlxIconVariantType::integer() const
       
   523     {
       
   524     TRACER("GlxIconVariantType::integer");
       
   525     return mIconId;
       
   526     }
       
   527 
       
   528 // ----------------------------------------------------------------------------
       
   529 // type
       
   530 // ----------------------------------------------------------------------------
       
   531 //
       
   532 Alf::IMulVariantType::TMulType GlxIconVariantType::Type() const
       
   533     {
       
   534     TRACER("GlxIconVariantType::type");
       
   535     return EInt;
       
   536     }