photosgallery/viewframework/dataprovider/src/glxmedialistmulmodelproviderimpl.cpp
branchRCL_3
changeset 26 5b3385a43d68
child 27 34937ec34dac
equal deleted inserted replaced
25:8e5f6eea9c9f 26:5b3385a43d68
       
     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:  Implementation class for Medialist Access for Data   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxmedialistmulmodelproviderimpl.h"      // The actual implemntation for providign the data to the clients is done here
       
    22 #include "glxbindingset.h"                         // This basically holds the bindings required to populate the visual item
       
    23 #include <mglxmedialist.h>                         // Interface for reading lists of media items
       
    24 #include "glxthumbnailinfo.h"
       
    25 #include "glxattributerequirement.h"               // This class will set the required attribute to the medialist
       
    26 #include "glxerrormanager.h"                       // for handling the error attribute that may be attached to items
       
    27 #include "glxthumbnailattributeinfo.h"
       
    28 #include "glxmulbindingsetfactory.h"               // CreateBindingSetL creates instance of Binding set
       
    29 #include <mul/imulcoverflowwidget.h>               // An interface for Multimedia coverflow Widget
       
    30 #include <glxresolutionutility.h>                  // Singleton containing resolution utility methods
       
    31 #include <glxtracer.h>
       
    32 #include <glxlog.h>                                // Logging
       
    33 #include <glxuiutility.h>                          // Alf utils lib glxalfutils.lib
       
    34 #include "glxtexturemanager.h"
       
    35 
       
    36 
       
    37 static const char* const KListWidget = "ListWidget";
       
    38 static const char* const KCoverFlowWidget = "CoverflowWidget";
       
    39 
       
    40 using namespace Alf;
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // NewL
       
    44 // ----------------------------------------------------------------------------
       
    45 //
       
    46 CGlxMediaListMulModelProviderImpl* CGlxMediaListMulModelProviderImpl::NewL( 
       
    47 	CAlfEnv& aEnv,
       
    48 	IMulWidget& aWidget,
       
    49 	MGlxMediaList& aMediaList,
       
    50 	const TGlxMulBindingSetFactory& aFactory,
       
    51 	Alf::mulwidget::TLogicalTemplate aDefaultTemplate,
       
    52 	TInt aDataWindowSize )
       
    53     {
       
    54     TRACER("CGlxMediaListMulModelProviderImpl::NewL");
       
    55     CGlxMediaListMulModelProviderImpl* self = 
       
    56         new ( ELeave) CGlxMediaListMulModelProviderImpl( aWidget, aMediaList );
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL( aEnv, aFactory, aDefaultTemplate, aDataWindowSize );
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62     
       
    63 // ----------------------------------------------------------------------------
       
    64 // Constructor
       
    65 // ----------------------------------------------------------------------------
       
    66 //
       
    67 CGlxMediaListMulModelProviderImpl::CGlxMediaListMulModelProviderImpl( 
       
    68     IMulWidget& aWidget, MGlxMediaList& aMediaList )
       
    69         : CGlxMulModelProviderBase( aWidget ), iMediaList( aMediaList ),iWidget(aWidget)
       
    70     {
       
    71     }
       
    72 
       
    73 // ----------------------------------------------------------------------------
       
    74 // ConstructL
       
    75 // ----------------------------------------------------------------------------
       
    76 //
       
    77 void CGlxMediaListMulModelProviderImpl::ConstructL( CAlfEnv& aEnv, 
       
    78 													const TGlxMulBindingSetFactory& aFactory, 
       
    79 													Alf::mulwidget::TLogicalTemplate aDefaultTemplate, TInt aDataWindowSize ) 
       
    80     {
       
    81     TRACER("CGlxMediaListMulModelProviderImpl::ConstructL");
       
    82     BaseConstructL( aEnv, aDefaultTemplate, aDataWindowSize );
       
    83 	iMediaList.AddMediaListObserverL(this);
       
    84 	iUiUtility = CGlxUiUtility::UtilityL();
       
    85 	iAttributeRequirements = CGlxAttributeRequirements::NewL( iMediaList);
       
    86     iBindingSet = aFactory.CreateBindingSetL( *this );
       
    87         
       
    88     TInt height;
       
    89     TInt width;
       
    90     iWidget.GetIconSize(aDefaultTemplate,Alf::mulvisualitem::KMulIcon1,height,width); 
       
    91     TSize thumbnailSize(width,height);
       
    92 
       
    93 	iBindingSet->AddRequirementsL( *iAttributeRequirements ,thumbnailSize );
       
    94 	if( iMediaList.Count() > 0 )
       
    95 	    {
       
    96 	    HandleItemAddedL( 0, iMediaList.Count() - 1, &iMediaList );
       
    97 		if(!iUiUtility->IsPenSupported())
       
    98 			{			
       
    99 			CMPXCollectionPath* path = iMediaList.PathLC( NGlxListDefs::EPathFocusOrSelection );
       
   100 			iBindingSet->HandleItemChangedL( *path ); 
       
   101 			CleanupStack::PopAndDestroy( path );
       
   102 			}
       
   103 		iMediaIDForTextureDeletion = iMediaList.Item(iMediaList.FocusIndex()).Id();
       
   104 	    }
       
   105 	    
       
   106 	if(UString( KListWidget ) == UString(iWidget.widgetName() ) ||  UString( KCoverFlowWidget ) == UString(iWidget.widgetName() ) )
       
   107 	    {
       
   108 	    AddWidgetEventHandler();
       
   109 	    }
       
   110     } 
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 // Destructor
       
   114 // ----------------------------------------------------------------------------
       
   115 //
       
   116 CGlxMediaListMulModelProviderImpl::~CGlxMediaListMulModelProviderImpl()
       
   117     {
       
   118     TRACER("CGlxMediaListMulModelProviderImpl::~CGlxMediaListMulModelProviderImpl");
       
   119     delete iBindingSet;
       
   120     delete iAttributeRequirements;
       
   121     iMediaList.RemoveMediaListObserver( this );
       
   122     if (iUiUtility)
       
   123         {
       
   124         iUiUtility->Close();
       
   125         }
       
   126     
       
   127     }
       
   128 
       
   129 // ----------------------------------------------------------------------------
       
   130 // HandleBindingChanged
       
   131 // ----------------------------------------------------------------------------
       
   132 // 
       
   133 void CGlxMediaListMulModelProviderImpl::HandleBindingChanged( 
       
   134         const CGlxBinding& aBinding )
       
   135     {
       
   136     TRACER("CGlxMediaListMulModelProviderImpl::HandleBindingChanged");
       
   137     SetDataT( aBinding, iMediaList.Item(iMediaList.FocusIndex()), 
       
   138                 iMediaList.FocusIndex() );
       
   139     
       
   140     }
       
   141     
       
   142 // ----------------------------------------------------------------------------
       
   143 // HandleFocusChanged
       
   144 // ----------------------------------------------------------------------------
       
   145 //     
       
   146 void CGlxMediaListMulModelProviderImpl::HandleFocusChanged( TInt 
       
   147 	    /*aNewFocusIndex*/, TInt /*aPreviousFocusIndex*/ )	
       
   148 	{
       
   149 	TRACER("CGlxMediaListMulModelProviderImpl::HandleFocusChanged");
       
   150     if (CGlxBinding::EUpdateRequested == iBindingSet->HandleFocusChanged( ETrue ) )
       
   151         {
       
   152         UpdateItems( iMediaList.FocusIndex(), 1 );
       
   153         }
       
   154    	}  
       
   155 	
       
   156 // ----------------------------------------------------------------------------
       
   157 // HandleFocusChangedL
       
   158 // ----------------------------------------------------------------------------
       
   159 //	
       
   160 void CGlxMediaListMulModelProviderImpl::HandleFocusChangedL( NGlxListDefs::TFocusChangeType /*aType*/, 
       
   161         TInt aNewIndex, TInt aOldIndex, MGlxMediaList* aList )	  
       
   162 	{
       
   163 	TRACER("CGlxMediaListMulModelProviderImpl::HandleFocusChangedL");
       
   164 	CMPXCollectionPath* path = iMediaList.PathLC( NGlxListDefs::EPathFocusOrSelection );
       
   165 	if ( aNewIndex != FocusIndex() )
       
   166 	    {
       
   167 	    // focus was changed not by the widget, but by some other reason (e.g., item insertion)
       
   168 	   	//Aki changes -  todo
       
   169 	    SetFocusIndex( aNewIndex );
       
   170 	    }
       
   171 	iBindingSet->HandleItemChangedL( *path );  // Item changed is handled first before Updating the List - see line 168 moved from here
       
   172 	if( aList->FocusIndex() >=0 && aOldIndex <= aList->Count() -1 && aOldIndex!=-1 ) 
       
   173 	    {
       
   174         UpdateItems( aOldIndex, 1 );    
       
   175         UpdateItems( aNewIndex, 1 ); 
       
   176         }
       
   177 	
       
   178 	CleanupStack::PopAndDestroy( path );
       
   179 	// Check for the deletion of a media item and delete the texture of the deleted media item.
       
   180 	// Deleting the texture after removing the item from the mul model and updating the new image.
       
   181 	// Hence the texture deletion is done at a later stage here instead of in HandleItemRemovedL().
       
   182 	if ((aNewIndex == aOldIndex) && (iMediaIDForTextureDeletion.Value()
       
   183             != KGlxInvalidIdValue) || (aNewIndex == KErrNotFound && aOldIndex
       
   184             == 0))
       
   185         {
       
   186         iUiUtility->GlxTextureManager().RemoveTexture(
       
   187                 iMediaIDForTextureDeletion, EFalse);
       
   188         }
       
   189     
       
   190     // Storing the focussed media id for use during the focussed media item deletion operation
       
   191     if (aNewIndex >= 0 && aNewIndex < aList->Count())
       
   192         {
       
   193         iMediaIDForTextureDeletion = aList->Item(aNewIndex).Id();
       
   194         }
       
   195     else
       
   196         {
       
   197         iMediaIDForTextureDeletion.SetValue(KGlxInvalidIdValue);
       
   198         }
       
   199 	}
       
   200 
       
   201 // ----------------------------------------------------------------------------
       
   202 // HandleItemAddedL
       
   203 // ----------------------------------------------------------------------------
       
   204 //
       
   205 void CGlxMediaListMulModelProviderImpl::HandleItemAddedL( TInt aStartIndex, 
       
   206         TInt aEndIndex, MGlxMediaList* aList )
       
   207     {
       
   208     TRACER("CGlxMediaListMulModelProviderImpl::HandleItemAddedL");
       
   209     GLX_LOG_INFO1("HandleItemAddedL::aStartIndex %d", aStartIndex);
       
   210     GLX_LOG_INFO1("HandleItemAddedL::aEndIndex %d", aEndIndex);
       
   211     
       
   212     InsertItemsL( aStartIndex, aEndIndex - aStartIndex + 1, aList->FocusIndex() );
       
   213     }
       
   214 
       
   215 // ----------------------------------------------------------------------------
       
   216 // HandleItemRemoved
       
   217 // ----------------------------------------------------------------------------
       
   218 //
       
   219 void CGlxMediaListMulModelProviderImpl::HandleItemRemovedL( TInt aStartIndex, 
       
   220         TInt aEndIndex, MGlxMediaList* /*aList*/ )
       
   221     {
       
   222     TRACER("CGlxMediaListMulModelProviderImpl::HandleItemRemovedL");
       
   223     RemoveItems( aStartIndex, aEndIndex - aStartIndex + 1 );
       
   224     }
       
   225 
       
   226 // ----------------------------------------------------------------------------
       
   227 // HandleAttributesAvailableL
       
   228 // ----------------------------------------------------------------------------
       
   229 //
       
   230 void CGlxMediaListMulModelProviderImpl::HandleAttributesAvailableL( TInt aIndex, 
       
   231         const RArray<TMPXAttribute>& aAttributes, MGlxMediaList* /*aList*/ )
       
   232     {
       
   233     TRACER("CGlxMediaListMulModelProviderImpl::HandleAttributesAvailableL");
       
   234     GLX_LOG_INFO1("HandleAttributesAvailableL::Index %d", aIndex);
       
   235     
       
   236      if(iBindingSet->HasRelevantAttributes( aAttributes ) )
       
   237         {
       
   238         UpdateItems( aIndex, 1 );
       
   239         }
       
   240     }
       
   241 
       
   242 // ----------------------------------------------------------------------------
       
   243 // HandleError
       
   244 // ----------------------------------------------------------------------------
       
   245 //
       
   246 void CGlxMediaListMulModelProviderImpl::HandleError( TInt aError )
       
   247     {
       
   248     TRACER("CGlxMediaListMulModelProviderImpl::HandleError");
       
   249     TRAP_IGNORE( DoHandleErrorL( aError ) );
       
   250     }
       
   251 
       
   252 // ----------------------------------------------------------------------------
       
   253 // HandleError
       
   254 // ----------------------------------------------------------------------------
       
   255 //
       
   256 void CGlxMediaListMulModelProviderImpl::DoHandleErrorL( TInt /*aError*/ )
       
   257     {
       
   258     TRACER("CGlxMediaListMulModelProviderImpl::DoHandleErrorL");
       
   259     // Check for items for which fetching a thumbnail has failed, and replace
       
   260     // the default icon with broken icon
       
   261 	TInt count = iMediaList.Count();
       
   262 	for ( TInt i = 0; i < count; i++ )
       
   263 	    {
       
   264 	    const TGlxMedia& item = iMediaList.Item( i );
       
   265         TInt thumbnailError = GlxErrorManager::HasAttributeErrorL(
       
   266                                 item.Properties(), KGlxMediaIdThumbnail );
       
   267         if( thumbnailError )
       
   268             {
       
   269             UpdateItems( i , 1 );
       
   270             }
       
   271 	    }
       
   272     }
       
   273     
       
   274 // ----------------------------------------------------------------------------
       
   275 // ProvideData
       
   276 // ----------------------------------------------------------------------------
       
   277 //
       
   278 void  CGlxMediaListMulModelProviderImpl::ProvideData (int aIndex, int aCount, 
       
   279 	MulDataPath /*aPath*/)
       
   280     {
       
   281     TRACER("CGlxMediaListMulModelProviderImpl::ProvideData");
       
   282     GLX_LOG_INFO1("ProvideData::aCount %d", aCount);
       
   283     
       
   284     if( KErrNotFound != iMediaList.FocusIndex() )
       
   285         {
       
   286         for(int i = aIndex; i < aIndex + aCount ; i++)
       
   287             {
       
   288 		    SetDataT( *iBindingSet, iMediaList.Item(i), i );            
       
   289             }
       
   290         }
       
   291     else
       
   292     	return;
       
   293     
       
   294     }
       
   295 
       
   296 void CGlxMediaListMulModelProviderImpl::HandleOrientationChanged()
       
   297 	{
       
   298 	TRACER("CGlxMediaListMulModelProviderImpl::HandleOrientationChanged");
       
   299 	//Fix for ESLM-7VGCS8
       
   300     //Since iBindingSet->AddRequirementsL() will change the iFsThumbnailContext's
       
   301     //thumbnail size due to which  thumbnail fetched for old context is getting
       
   302     //deleted in clean-up. But actually S60 TNM provides same thumbnail for both
       
   303     //the configurations requests,So it is unneccesary to delete the existing
       
   304     //thumbnail and request for the same. To avoid this ,iBindingSet->AddRequirementsL()
       
   305     //and UpdateItems() is removed so that  the context will not be changed
       
   306     //and the thumbnail deletion will not happen.
       
   307   	}
       
   308 
       
   309 // ----------------------------------------------------------------------------
       
   310 // HandleItemModifiedL
       
   311 // ----------------------------------------------------------------------------
       
   312 //  
       
   313 void CGlxMediaListMulModelProviderImpl::HandleItemModifiedL( const RArray<TInt>& aItemIndexes,
       
   314     MGlxMediaList* aList )
       
   315     {
       
   316     //Bug fix for PKAA-7NRBYZ
       
   317     //First remove all the textures from the list in the texture manager
       
   318     //otherwise it would not create a new texture for the modified image.
       
   319     for(TInt index = 0;index<aItemIndexes.Count();index++)
       
   320         {
       
   321         TGlxMedia media = aList->Item(aItemIndexes[index]);
       
   322 
       
   323         iUiUtility->GlxTextureManager().RemoveTexture(media.Id(),ETrue);
       
   324         }            
       
   325     //Now update the items, this would create the new textures and update the view.
       
   326     for(TInt index = 0;index<aItemIndexes.Count();index++)
       
   327         UpdateItems(aItemIndexes[index],1);
       
   328     }
       
   329 
       
   330 // ----------------------------------------------------------------------------
       
   331 // UpdateItems
       
   332 // ----------------------------------------------------------------------------
       
   333 //  
       
   334 void CGlxMediaListMulModelProviderImpl::UpdateItems( TInt aIndex, TInt aCount )
       
   335     {
       
   336     TRACER("CGlxMediaListMulModelProviderImpl::UpdateItems");
       
   337     CGlxMulModelProviderBase::UpdateItems(aIndex, aCount);
       
   338     }
       
   339 	
       
   340 // ----------------------------------------------------------------------------
       
   341 // AnimateDRMGifItem
       
   342 // ----------------------------------------------------------------------------
       
   343 // 
       
   344 void CGlxMediaListMulModelProviderImpl::AnimateDRMGifItem( TBool aAnimate )
       
   345     {
       
   346     CGlxMulModelProviderBase::AnimateDRMGifItem(aAnimate);
       
   347     }