photosgallery/viewframework/dataprovider/src/glxdetailsmulmodelproviderimpl.cpp
changeset 0 4e91876724a2
child 18 bcb43dc84c44
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:    Implementation class for details data provider
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxdetailsmulmodelproviderimpl.h"   // This is the implementation class of details data provider 
       
    22 #include "glxattributerequirement.h"          // This class will set the required attribute to the medialist
       
    23 #include "glxbindingset.h"                    // This basically holds the bindings required to populate the visual item
       
    24 #include "glxbinding.h"                       // This class holds the bindings required to populate the visual item
       
    25 #include "glxmulbindingsetfactory.h"          // CreateBindingSetL creates instance of Binding set
       
    26 #include <mglxmedialist.h>                    // Interface for reading lists of media items
       
    27 #include <glxlog.h>                           // Logging
       
    28 #include <glxtracer.h>
       
    29 #include <eikmenup.h>                         // A helper class for extending CEikMenuPaneItem without breaking binary  
       
    30 #include <glxuistd.h>                         // attribute/thumbnail fetch context priority definitions
       
    31 #include "glxdetailsboundcommand.h"           // Handles user commands
       
    32 #include "glxerrormanager.h"                       // for handling the error attribute that may be attached to items
       
    33 #include "glxthumbnailattributeinfo.h"
       
    34 #include "glxdetailsboundcommand.hrh" 
       
    35 /** Error Id EMPY-7MKDHP **/
       
    36 #include "mglxmetadatadialogobserver.h" 		//for call back to dailog
       
    37 #include <glxcommandhandlers.hrh>
       
    38 using namespace Alf;
       
    39 
       
    40 // ----------------------------------------------------------------------------
       
    41 // NewL
       
    42 // ----------------------------------------------------------------------------
       
    43 //
       
    44 CGlxDetailsMulModelProviderImpl* CGlxDetailsMulModelProviderImpl::NewL(
       
    45      CAlfEnv& aEnv, 
       
    46      Alf::IMulWidget& aWidget, 
       
    47      MGlxMediaList& aMediaList, 
       
    48      Alf::mulwidget::TLogicalTemplate aDefaultTemplate, 
       
    49      TInt aDataWindowSize )
       
    50   	{
       
    51   	TRACER("CGlxDetailsMulModelProviderImpl::NewL");
       
    52   	CGlxDetailsMulModelProviderImpl* self = new ( ELeave )CGlxDetailsMulModelProviderImpl( aWidget, aMediaList, aDefaultTemplate, aDataWindowSize);
       
    53   	CleanupStack::PushL( self );
       
    54   	self->ConstructL( aEnv, aDefaultTemplate, aDataWindowSize );
       
    55   	CleanupStack::Pop( self );
       
    56   	return self;
       
    57   	}
       
    58   	
       
    59 // ----------------------------------------------------------------------------
       
    60 // ConstructL
       
    61 // ----------------------------------------------------------------------------
       
    62 //  	
       
    63 void CGlxDetailsMulModelProviderImpl::ConstructL(
       
    64     CAlfEnv& aEnv, 
       
    65     Alf::mulwidget::TLogicalTemplate aDefaultTemplate,
       
    66     TInt aDataWindowSize )
       
    67     {
       
    68     TRACER("CGlxDetailsMulModelProviderImpl::ConstructL");
       
    69     BaseConstructL( aEnv, aDefaultTemplate, aDataWindowSize );
       
    70     iMediaList.AddMediaListObserverL(this);
       
    71    	iAttributeRequirements = CGlxAttributeRequirements::NewL( iMediaList );
       
    72    	AddWidgetEventHandler();
       
    73     }
       
    74 // ----------------------------------------------------------------------------
       
    75 // Destructor
       
    76 // ----------------------------------------------------------------------------
       
    77 //	            	
       
    78 CGlxDetailsMulModelProviderImpl::~CGlxDetailsMulModelProviderImpl()
       
    79 	{
       
    80 	TRACER("CGlxDetailsMulModelProviderImpl::~CGlxDetailsMulModelProviderImpl");
       
    81     iEntries.ResetAndDestroy();
       
    82 	iEntries.Close();
       
    83 	iMediaList.RemoveMediaListObserver( this );
       
    84 	delete 	iAttributeRequirements;				
       
    85 	}
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // AddEntryL
       
    89 // ----------------------------------------------------------------------------
       
    90 //	    					
       
    91 void CGlxDetailsMulModelProviderImpl::AddEntryL( const TGlxMulBindingSetFactory& aFactory )
       
    92 	{
       
    93 	TRACER("CGlxDetailsMulModelProviderImpl::AddEntryL");
       
    94 	CGlxBindingSet* bindingSet = aFactory.CreateBindingSetL( *this );
       
    95 	CleanupStack::PushL( bindingSet);
       
    96 	iEntries.Append( bindingSet );
       
    97 	CleanupStack::Pop( bindingSet );
       
    98     TSize Size;
       
    99     bindingSet->AddRequirementsL(*iAttributeRequirements,Size);
       
   100 	InsertItemsL( iEntries.Count() - 1, 1 );
       
   101 	}
       
   102 					
       
   103 // ----------------------------------------------------------------------------
       
   104 // OfferCommandL
       
   105 // ----------------------------------------------------------------------------
       
   106 //	    					
       
   107 TBool CGlxDetailsMulModelProviderImpl::OfferCommandL( TInt aCommandId )
       
   108 	{
       
   109 	TRACER("CGlxDetailsMulModelProviderImpl::OfferCommandL");
       
   110 	MGlxBoundCommand* command = BoundCommand( FocusIndex() );
       
   111     if ( command ) 
       
   112         {
       
   113         return command->OfferCommandL( aCommandId , iMediaList );
       
   114         }
       
   115     return EFalse;				
       
   116 	}
       
   117 
       
   118 // ----------------------------------------------------------------------------
       
   119 // HasCommandL
       
   120 // ----------------------------------------------------------------------------
       
   121 //
       
   122 TBool CGlxDetailsMulModelProviderImpl::HasCommandL( CEikMenuPane& aMenuPane, const TInt aCommandId )
       
   123     {
       
   124     TRACER("CGlxDetailsMulModelProviderImpl::HasCommandL");
       
   125     TInt count = aMenuPane.NumberOfItemsInPane();
       
   126     TInt i = -1;
       
   127     while ( ++i < count )
       
   128         {
       
   129         if ( aCommandId == aMenuPane.ItemDataByIndexL( i ).iCommandId )
       
   130             {
       
   131             return ETrue;
       
   132             }
       
   133         }
       
   134     return EFalse; 
       
   135     }
       
   136 // ----------------------------------------------------------------------------
       
   137 // InitMenuL
       
   138 // ----------------------------------------------------------------------------
       
   139 //	    					
       
   140 void CGlxDetailsMulModelProviderImpl::InitMenuL( CEikMenuPane& aMenu )
       
   141 	{
       
   142 	TRACER("CGlxDetailsMulModelProviderImpl::InitMenuL");
       
   143 	//CEikMenuPane::SetItemDimmed will panic if the menu item does not exist
       
   144  	if ( HasCommandL( aMenu, KGlxEditBoundMenuCommandId ) )
       
   145 		{
       
   146 		// Disable by default, bound command will enable if needed
       
   147 		aMenu.SetItemDimmed( KGlxEditBoundMenuCommandId, ETrue );
       
   148 		const MGlxBoundCommand* command = BoundCommand( FocusIndex() );
       
   149 		if ( command )
       
   150 			{
       
   151 			command->InitMenuL( aMenu );
       
   152 			}
       
   153 		}
       
   154 	else
       
   155 		{
       
   156 		// no implementation	
       
   157 		}
       
   158 	
       
   159 	
       
   160 	if ( HasCommandL( aMenu, KGlxDeleteBoundMenuCommandId ) )
       
   161 		{
       
   162 		// Disable by default, bound command will enable if needed
       
   163 		aMenu.SetItemDimmed( KGlxDeleteBoundMenuCommandId, ETrue );
       
   164 		const MGlxBoundCommand* command = BoundCommand( FocusIndex() );
       
   165 		if ( command )
       
   166 			{
       
   167 			command->InitMenuL( aMenu );
       
   168 			}
       
   169 		}
       
   170 		else
       
   171 		{
       
   172 		// no implementation	
       
   173 		}
       
   174 		
       
   175 	if ( HasCommandL( aMenu, KGlxViewBoundMenuCommandId ) )
       
   176 		{
       
   177 		// Disable by default, bound command will enable if needed
       
   178 		aMenu.SetItemDimmed( KGlxViewBoundMenuCommandId, ETrue );
       
   179 		const MGlxBoundCommand* command = BoundCommand( FocusIndex() );
       
   180 		if ( command )
       
   181 			{
       
   182 			command->InitMenuL( aMenu );
       
   183 			}
       
   184 		}
       
   185 	else
       
   186 		{
       
   187 		// no implementation	
       
   188 		}
       
   189 	if ( HasCommandL( aMenu, EGlxCmdAiwShowMap ) )
       
   190 		{
       
   191 		// Disable by default, bound command will enable if needed
       
   192 		aMenu.SetItemDimmed( EGlxCmdAiwShowMap, ETrue );
       
   193 		const MGlxBoundCommand* command = BoundCommand( FocusIndex() );
       
   194 		if ( command )
       
   195 			{
       
   196 			command->InitMenuL( aMenu );
       
   197 			}
       
   198 		}
       
   199 	else
       
   200 		{
       
   201 		// no implementation	
       
   202 		}	
       
   203 }
       
   204 
       
   205 // ----------------------------------------------------------------------------
       
   206 // CGlxDetailsMulModelProviderImpl
       
   207 // ----------------------------------------------------------------------------
       
   208 //	    					
       
   209 CGlxDetailsMulModelProviderImpl::CGlxDetailsMulModelProviderImpl(
       
   210     Alf::IMulWidget& aWidget, 
       
   211 	MGlxMediaList& aMediaList,
       
   212 	Alf::mulwidget::TLogicalTemplate /*aDefaultTemplate*/,
       
   213 	TInt /*aDataWindowSize*/ ):
       
   214 	    CGlxMulModelProviderBase(aWidget), iMediaList( aMediaList )
       
   215 	{
       
   216 	}
       
   217 
       
   218 // ----------------------------------------------------------------------------
       
   219 // HandleBindingChanged
       
   220 // ----------------------------------------------------------------------------
       
   221 //	    					
       
   222 void CGlxDetailsMulModelProviderImpl::HandleBindingChanged( const CGlxBinding& /*aBinding*/ )
       
   223 	{
       
   224 	 for(TInt i = 0; i < iEntries.Count(); i++)
       
   225          {
       
   226          UpdateItems( i, 1 );
       
   227          }
       
   228 	}
       
   229 
       
   230 // ----------------------------------------------------------------------------
       
   231 // HandleFocusChanged
       
   232 // ----------------------------------------------------------------------------
       
   233 //	    
       
   234 void CGlxDetailsMulModelProviderImpl::HandleFocusChanged( TInt aNewFocus, TInt aPreviousFocus )
       
   235 	{
       
   236 	TRACER("CGlxDetailsMulModelProviderImpl::HandleFocusChanged");
       
   237 	if ( aPreviousFocus != -1 )
       
   238 	    {
       
   239         if ( CGlxBinding::EUpdateRequested == 
       
   240             iEntries[ aPreviousFocus ]->HandleFocusChanged( EFalse ) )
       
   241             {
       
   242             UpdateItems( aPreviousFocus, 1 );
       
   243             //UpdateItemL( *iEntries[ aPreviousFocus ], media, aPreviousFocus );
       
   244             }
       
   245         }
       
   246     
       
   247     if ( aNewFocus != -1 )
       
   248         {
       
   249         if ( CGlxBinding::EUpdateRequested == 
       
   250             iEntries[ aNewFocus ]->HandleFocusChanged( ETrue ) )
       
   251             {
       
   252             UpdateItems( aNewFocus, 1 );
       
   253             //UpdateItemL( *iEntries[ aNewFocus ], media, aNewFocus );
       
   254             }
       
   255         }
       
   256 	}
       
   257 
       
   258 // ----------------------------------------------------------------------------
       
   259 // HandleAttributesAvailableL
       
   260 // ----------------------------------------------------------------------------
       
   261 //	
       
   262 void CGlxDetailsMulModelProviderImpl::HandleAttributesAvailableL( TInt aIndex, 
       
   263         const RArray<TMPXAttribute>& aAttributes, MGlxMediaList* aList )
       
   264     {
       
   265     TRACER("CGlxDetailsMulModelProviderImpl::HandleAttributesAvailableL");
       
   266     if ( aList->FocusIndex() == aIndex )
       
   267         {
       
   268         for(TInt i = 0; i < iEntries.Count(); i++)
       
   269             {
       
   270             if(iEntries[i]->HasRelevantAttributes(aAttributes) )
       
   271                 {
       
   272 		        UpdateItems( i, 1 );
       
   273                 }
       
   274             }
       
   275         }
       
   276     }
       
   277 
       
   278 // ----------------------------------------------------------------------------
       
   279 // ProvideData
       
   280 // ----------------------------------------------------------------------------
       
   281 //
       
   282 void  CGlxDetailsMulModelProviderImpl::ProvideData (int aIndex, int aCount, 
       
   283     MulDataPath /*aPath*/)
       
   284     {
       
   285     TRACER("CGlxDetailsMulModelProviderImpl::ProvideData");
       
   286 	for( int i = aIndex;i < aIndex + aCount ; i++)
       
   287 		{
       
   288 		if( KErrNotFound != iMediaList.FocusIndex())
       
   289 			{
       
   290 			SetDataT( *iEntries[ i ], iMediaList.Item(iMediaList.FocusIndex()), i ) ;
       
   291 			}
       
   292 		}       
       
   293     }       
       
   294         
       
   295 // ----------------------------------------------------------------------------
       
   296 // HandleItemAddedL
       
   297 // ----------------------------------------------------------------------------
       
   298 //
       
   299 void  CGlxDetailsMulModelProviderImpl::HandleItemAddedL(TInt /*aStartIndex*/, TInt /*aEndIndex*/,
       
   300     MGlxMediaList* /*aList*/ )
       
   301     {
       
   302     TRACER("CGlxDetailsMulModelProviderImpl::HandleItemAddedL");
       
   303     TInt count = iEntries.Count();
       
   304     for(int i = 0; i < count; i++)
       
   305         {
       
   306 	     UpdateItems( i , 1 );
       
   307         }
       
   308     }
       
   309 // ----------------------------------------------------------------------------
       
   310 // HandleError
       
   311 // ----------------------------------------------------------------------------
       
   312 //
       
   313 void CGlxDetailsMulModelProviderImpl::HandleError( TInt aError )
       
   314     {
       
   315     TRACER("CGlxDetailsMulModelProviderImpl::HandleError");
       
   316     TRAP_IGNORE( DoHandleErrorL( aError ) );
       
   317     }
       
   318 
       
   319 // ----------------------------------------------------------------------------
       
   320 // HandleError
       
   321 // ----------------------------------------------------------------------------
       
   322 //
       
   323 void CGlxDetailsMulModelProviderImpl::DoHandleErrorL( TInt /*aError*/ )
       
   324     {
       
   325     TRACER("CGlxDetailsMulModelProviderImpl::DoHandleErrorL");
       
   326     // Check for items for which fetching a thumbnail has failed, and replace
       
   327     // the default icon with broken icon
       
   328     TInt count = iMediaList.Count();
       
   329     for ( TInt i = 0; i < count; i++ )
       
   330         {
       
   331         const TGlxMedia& item = iMediaList.Item( i );
       
   332         TInt thumbnailError = GlxErrorManager::HasAttributeErrorL(
       
   333                                 item.Properties(), KGlxMediaIdThumbnail );
       
   334         if( thumbnailError )
       
   335             {
       
   336             UpdateItems( i , 1 );
       
   337             }
       
   338         }
       
   339     }
       
   340 // ----------------------------------------------------------------------------
       
   341 // HideLocationMenuItem
       
   342 // ----------------------------------------------------------------------------
       
   343 //
       
   344 void CGlxDetailsMulModelProviderImpl::HideLocationMenuItem( CEikMenuPane& aMenu )
       
   345     {
       
   346     if ( HasCommandL( aMenu, EGlxCmdAiwBase ) )
       
   347         {
       
   348         const MGlxBoundCommand* command = BoundCommand( FocusIndex() );
       
   349         if ( command )
       
   350             {
       
   351             command->HideLocationMenuItem( aMenu );
       
   352             }
       
   353         }
       
   354     }
       
   355 
       
   356 // ----------------------------------------------------------------------------
       
   357 // EnableMskL
       
   358 // ----------------------------------------------------------------------------
       
   359 //
       
   360 void CGlxDetailsMulModelProviderImpl::EnableMskL()
       
   361     {
       
   362     TRACER("CGlxDetailsMulModelProviderImpl::EnableMskL");
       
   363     MGlxBoundCommand* command = BoundCommand( FocusIndex() );
       
   364     if ( command )
       
   365         {
       
   366         command->ChangeMskL();
       
   367         }
       
   368     }
       
   369 
       
   370 // ----------------------------------------------------------------------------
       
   371 // SetDetailsDailogObserver
       
   372 // ----------------------------------------------------------------------------
       
   373 //
       
   374 void CGlxDetailsMulModelProviderImpl::SetDetailsDailogObserver( MGlxMetadataDialogObserver& aObserver )
       
   375     {
       
   376     TRACER("CGlxDetailsMulModelProviderImpl::SetDetailsDailogObserver");
       
   377 	/** Error Id EMPY-7MKDHP **/
       
   378 	MGlxBoundCommand* command = BoundCommand( FocusIndex() );
       
   379 	if ( command )
       
   380 	    {
       
   381 	    command->SetDetailsDailogObserver( aObserver ) ;
       
   382 	    }
       
   383     }
       
   384 
       
   385 
       
   386 // ----------------------------------------------------------------------------
       
   387 // HandleCommandCompleteL
       
   388 // ----------------------------------------------------------------------------
       
   389 //  
       
   390 void CGlxDetailsMulModelProviderImpl::HandleCommandCompleteL(TAny* /*aSessionId*/,
       
   391        CMPXCommand* /*aCommandResult*/, TInt aError, MGlxMediaList* /*aList*/)
       
   392     {
       
   393     TRACER("CGlxDetailsMulModelProviderImpl::HandleCommandCompleteL");
       
   394     TGlxMedia media = iMediaList.Item(iMediaList.FocusIndex()) ;
       
   395     media.DeleteLocationAttribute();
       
   396     if ( aError == KErrNone )
       
   397         {
       
   398 	   	UpdateItems( FocusIndex(), 1 );   
       
   399         }
       
   400     }