photosgallery/viewframework/dataprovider/src/glxmulmodelproviderbase.cpp
changeset 0 4e91876724a2
child 12 ce1c7ad1f18b
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:  Interface to Alf Objects  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxmulmodelproviderbase.h"
       
    22 
       
    23 #include <e32err.h>
       
    24 #include <alf/alfenv.h>
       
    25 #include <alf/alfevent.h>
       
    26 #include <alf/ialfwidgetfactory.h>
       
    27 #include <alf/alfwidgetenvextension.h>
       
    28 //#include <osn/ustring.h>
       
    29 #include <mul/imulwidget.h>
       
    30 #include <mul/mulevent.h>
       
    31 #include <mul/mulvisualitem.h>
       
    32 #include <glxlog.h>  //Logging
       
    33 #include <glxtracer.h>
       
    34 #include "glxbinding.h"
       
    35 #include "glxcommandbindingutility.h"
       
    36 #include <glxnavigationalstate.h>
       
    37 #include <glxnavigationalstatedefs.h>
       
    38 
       
    39 #include <data_caging_path_literals.hrh>// for KDC_APP_RESOURCE_DIR
       
    40 #include <glxuiutilities.rsg>
       
    41 #include <glxgeneraluiutilities.h>
       
    42 #include <glxtexturemanager.h>
       
    43 #include <glxicons.mbg>
       
    44 #include <glxuistd.h>
       
    45 #include <mul/imulcoverflowwidget.h>               // An interface for Multimedia coverflow Widget
       
    46 
       
    47 using namespace Alf;
       
    48 
       
    49 static const char* const KListWidget = "ListWidget";
       
    50 static const char* const KGridWidget = "GridWidget";
       
    51 static const char* const KCoverFlowWidget = "CoverflowWidget";
       
    52 
       
    53 //@todo to be uncommented when using command binding
       
    54 //#include "glxboundcommand.h"
       
    55 
       
    56 // ----------------------------------------------------------------------------
       
    57 // BaseConstructL
       
    58 // ----------------------------------------------------------------------------
       
    59 //
       
    60 void CGlxMulModelProviderBase::BaseConstructL(
       
    61      CAlfEnv& aEnv, 
       
    62      Alf::mulwidget::TLogicalTemplate aDefaultTemplate,
       
    63      TInt aDataWindowSize )
       
    64     {
       
    65     TRACER("CGlxMulModelProviderBase::BaseConstructL");
       
    66    
       
    67     // Create navigational state 
       
    68     iNavigationalState = CGlxNavigationalState::InstanceL();
       
    69 
       
    70     iEnv = &aEnv;
       
    71 
       
    72     iDefaultTemplate = aDefaultTemplate;
       
    73         
       
    74     iDataWindowSize = aDataWindowSize;
       
    75 
       
    76     }
       
    77     
       
    78 // ----------------------------------------------------------------------------
       
    79 // Constructor
       
    80 // ----------------------------------------------------------------------------
       
    81 //
       
    82 CGlxMulModelProviderBase::CGlxMulModelProviderBase( IMulWidget& aWidget )
       
    83         : iWidget( aWidget ),iPreviousFocusIndex(-1)
       
    84     {
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // Destructor
       
    89 // ----------------------------------------------------------------------------
       
    90 //
       
    91 CGlxMulModelProviderBase::~CGlxMulModelProviderBase()
       
    92     { 
       
    93     TRACER("CGlxMulModelProviderBase::~CGlxMulModelProviderBase");
       
    94     //   remove event handler
       
    95 	iWidget.RemoveEventHandler( *this );
       
    96     if ( iNavigationalState )
       
    97           {
       
    98           iNavigationalState->Close();
       
    99           }
       
   100 	}    
       
   101  
       
   102 // ----------------------------------------------------------------------------
       
   103 // HandleItemAddedL
       
   104 // ----------------------------------------------------------------------------
       
   105 // 
       
   106 void CGlxMulModelProviderBase::HandleItemAddedL( TInt /*aStartIndex*/, TInt 
       
   107 	/*aEndIndex*/, MGlxMediaList* /*aList*/ )
       
   108 	{
       
   109 
       
   110 	}
       
   111 
       
   112 // ----------------------------------------------------------------------------
       
   113 // HandleItemRemoved
       
   114 // ----------------------------------------------------------------------------
       
   115 //	
       
   116 void CGlxMulModelProviderBase::HandleItemRemovedL( TInt /*aStartIndex*/, TInt 
       
   117 	/*aEndIndex*/, MGlxMediaList* /*aList*/ )
       
   118 	{
       
   119 
       
   120 	}
       
   121 
       
   122 // ----------------------------------------------------------------------------
       
   123 // HandleAttributesAvailableL
       
   124 // ----------------------------------------------------------------------------
       
   125 //	
       
   126 void CGlxMulModelProviderBase::HandleAttributesAvailableL( TInt /*aItemIndex*/, 
       
   127 	const RArray<TMPXAttribute>& /*aAttributes*/, MGlxMediaList* /*aList*/ )
       
   128 	{
       
   129 
       
   130 	}
       
   131 	
       
   132 // ----------------------------------------------------------------------------
       
   133 // HandleFocusChangedL
       
   134 // ----------------------------------------------------------------------------
       
   135 //	
       
   136 void CGlxMulModelProviderBase::HandleFocusChangedL( NGlxListDefs::
       
   137 	TFocusChangeType /*aType*/, TInt /*aNewIndex*/, TInt /*aOldIndex*/, MGlxMediaList* /*aList*/ )
       
   138 	{
       
   139 
       
   140 	}
       
   141 
       
   142 // ----------------------------------------------------------------------------
       
   143 // HandleItemSelected
       
   144 // ----------------------------------------------------------------------------
       
   145 //	
       
   146 void CGlxMulModelProviderBase::HandleItemSelectedL(TInt aIndex, 
       
   147 	TBool aSelected, MGlxMediaList* /*aList*/ )
       
   148 	{
       
   149 	TRACER("CGlxMulModelProviderBase::HandleItemSelectedL");
       
   150 	std::vector<int> itemIndex;	
       
   151 	itemIndex.push_back( aIndex);	
       
   152 	// changed code ---statr
       
   153 	if(aSelected) 
       
   154 	    {
       
   155 	    iModel->SetMarkedIndices(MulWidgetDef::EMulMark,itemIndex);
       
   156 	    }
       
   157 	else 
       
   158 	    {	
       
   159 	    iModel->SetMarkedIndices(MulWidgetDef::EMulUnmark,itemIndex);	
       
   160 	    }
       
   161 	}
       
   162 
       
   163 // ----------------------------------------------------------------------------
       
   164 // accept
       
   165 // ----------------------------------------------------------------------------
       
   166 //	
       
   167 bool CGlxMulModelProviderBase::accept( Alf::CAlfWidgetControl& /*aControl*/, const 
       
   168 	TAlfEvent& /*aEvent*/ ) const
       
   169 	{
       
   170 	TRACER("CGlxMulModelProviderBase::accept");
       
   171 	//Need implementation
       
   172 	return NULL;
       
   173 	}
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // offerEvent
       
   177 // ----------------------------------------------------------------------------
       
   178 //
       
   179 AlfEventStatus CGlxMulModelProviderBase::offerEvent( Alf::CAlfWidgetControl& 
       
   180 		/*aControl*/, const TAlfEvent& aEvent )
       
   181 	{
       
   182 	TRACER("CGlxMulModelProviderBase::offerEvent");
       
   183 	AlfEventStatus response = EEventNotHandled;
       
   184 	if ( aEvent.IsCustomEvent() )
       
   185 		{
       
   186 		switch ( aEvent.CustomParameter() ) 
       
   187 			{
       
   188 			case KAlfActionIdDeviceLayoutChanged:
       
   189 				{
       
   190 				HandleOrientationChanged();
       
   191 				response = EEventNotHandled;
       
   192 				}
       
   193 				break;
       
   194 			case Alf::ETypeHighlight:
       
   195 				{
       
   196 				if ( !iWithinFocusChangeCall )
       
   197 					{
       
   198 					// iWithinFocusChangeCall = ETrue;
       
   199 					HandleFocusChanged( FocusIndex(), iPreviousFocusIndex );
       
   200 					//iPreviousFocusIndex = FocusIndex();
       
   201 					//iWithinFocusChangeCall = EFalse;
       
   202 					}
       
   203 				response = EEventHandled;
       
   204 				}
       
   205 				break;
       
   206 			default:
       
   207 				break;
       
   208 			}
       
   209 		}
       
   210 	return response;
       
   211 	}
       
   212 
       
   213 // ----------------------------------------------------------------------------
       
   214 // setActiveStates
       
   215 // ----------------------------------------------------------------------------
       
   216 //
       
   217 void CGlxMulModelProviderBase::setActiveStates( unsigned int /*aStates*/ ) 
       
   218     {
       
   219     
       
   220     }
       
   221 
       
   222 // ----------------------------------------------------------------------------
       
   223 // setEventHandlerData
       
   224 // ----------------------------------------------------------------------------
       
   225 //  
       
   226 void CGlxMulModelProviderBase::setEventHandlerData( const Alf::AlfWidgetEventHandlerInitData& /*aData*/ )
       
   227     {
       
   228     
       
   229     }
       
   230 
       
   231 // ----------------------------------------------------------------------------
       
   232 // eventHandlerData
       
   233 // ----------------------------------------------------------------------------
       
   234 //  
       
   235 Alf::AlfWidgetEventHandlerInitData* CGlxMulModelProviderBase::eventHandlerData() 
       
   236     {
       
   237     TRACER("CGlxMulModelProviderBase::eventHandlerData");
       
   238     return NULL; 
       
   239     }
       
   240 
       
   241 // ----------------------------------------------------------------------------
       
   242 // makeInterface
       
   243 // ----------------------------------------------------------------------------
       
   244 //    
       
   245 Alf::IAlfInterfaceBase* CGlxMulModelProviderBase::makeInterface(const Alf::IfId& /*aType */)
       
   246     {
       
   247     TRACER("CGlxMulModelProviderBase::makeInterface");
       
   248     return this;
       
   249     }
       
   250 
       
   251 // ----------------------------------------------------------------------------
       
   252 // eventHandlerType
       
   253 // ----------------------------------------------------------------------------
       
   254 //    
       
   255 IAlfWidgetEventHandler::AlfEventHandlerType CGlxMulModelProviderBase::
       
   256     eventHandlerType() 
       
   257 	{
       
   258 	TRACER("CGlxMulModelProviderBase::eventHandlerType");
       
   259 	// To Avoid Compiler warning
       
   260 	return IAlfWidgetEventHandler::ELogicalEventHandler;
       
   261 	}
       
   262 
       
   263 // ----------------------------------------------------------------------------
       
   264 // eventExecutionPhase
       
   265 // ----------------------------------------------------------------------------
       
   266 //    
       
   267 IAlfWidgetEventHandler::AlfEventHandlerExecutionPhase 
       
   268     CGlxMulModelProviderBase::eventExecutionPhase()
       
   269 	{
       
   270 	TRACER("CGlxMulModelProviderBase::eventExecutionPhase");
       
   271 	return EBubblingPhaseEventHandler;
       
   272 	}
       
   273 
       
   274 // ----------------------------------------------------------------------------
       
   275 // UpdateItemL
       
   276 // ----------------------------------------------------------------------------
       
   277 //	
       
   278 void CGlxMulModelProviderBase::UpdateItems( TInt aIndex, TInt aCount )
       
   279     {
       
   280     TRACER("CGlxMulModelProviderBase::UpdateItems");
       
   281     try 
       
   282         {
       
   283         iModel->Update( aIndex, aCount );
       
   284         }
       
   285     catch (...)
       
   286         {
       
   287         throw std::bad_alloc();
       
   288         }
       
   289     }
       
   290 
       
   291 // ----------------------------------------------------------------------------
       
   292 // SetDataT
       
   293 // ----------------------------------------------------------------------------
       
   294 //	
       
   295 void CGlxMulModelProviderBase::SetDataT( const CGlxBinding& aBinding,
       
   296         const TGlxMedia& aMedia, TInt aAtIndex )
       
   297     {
       
   298     TRACER("CGlxMulModelProviderBase::SetDataT");
       
   299     iModel->SetData( aAtIndex, CreateItemT( aBinding, aMedia, 
       
   300         IsFocused( aAtIndex ) ) );
       
   301     }
       
   302     
       
   303 // ----------------------------------------------------------------------------
       
   304 // CreateItemT
       
   305 // ----------------------------------------------------------------------------
       
   306 //    
       
   307 auto_ptr<MulVisualItem> CGlxMulModelProviderBase::CreateItemT( 
       
   308     const CGlxBinding& aBinding, const TGlxMedia& aMedia, TBool aIsFocused )     
       
   309     {
       
   310     TRACER("CGlxMulModelProviderBase::CreateItemT");
       
   311     auto_ptr<MulVisualItem> item( new ( EMM ) MulVisualItem() );
       
   312     aBinding.PopulateT( *item, aMedia, aIsFocused );
       
   313     return item;
       
   314     }
       
   315 // ----------------------------------------------------------------------------
       
   316 // CreateModelL
       
   317 // ----------------------------------------------------------------------------
       
   318 //    
       
   319     
       
   320 void CGlxMulModelProviderBase::CreateModelL()
       
   321     {
       
   322     
       
   323     const char* KLoadNameModel( "mulmodel" );
       
   324     try 
       
   325         {
       
   326 
       
   327         IAlfWidgetFactory& widgetFactory = AlfWidgetEnvExtension::widgetFactory(*iEnv);
       
   328 
       
   329         std::auto_ptr< Alf::IMulModel > model( 
       
   330                 widgetFactory.createModel< IMulModel >( KLoadNameModel ) );
       
   331         iModel = model.release(); 
       
   332         if( iDataWindowSize > 0 )
       
   333             {
       
   334             iModel->SetDataWindow(iDataWindowSize);
       
   335             }
       
   336         iModel->SetDataProvider( *this );
       
   337         iModel->SetTemplate( iDefaultTemplate );
       
   338         }
       
   339     catch (...)
       
   340         {
       
   341         User::Leave( KErrNoMemory );
       
   342         }
       
   343     }
       
   344 // ----------------------------------------------------------------------------
       
   345 // InsertItemsL
       
   346 // ----------------------------------------------------------------------------
       
   347 //    
       
   348     
       
   349 void CGlxMulModelProviderBase::InsertItemsL( TInt aIndex, TInt aCount, TInt aMediaListFocusIndex )
       
   350     {
       
   351     TRACER("CGlxMulModelProviderBase::InsertItemsL");
       
   352     // The order of calling should be Model->Insert(..), 
       
   353     // Model->SetHighlight(..) and Widget.SetModel(..)
       
   354     // Change the order once bug EPBA-7JRDXV ( SetModel Crashes if highlight 
       
   355     // index is set >0 before setting model. )is fixed. 
       
   356     if(!iWidget.model())
       
   357         {
       
   358         CreateModelL();
       
   359         }
       
   360     
       
   361     if(iWidget.model())
       
   362         {
       
   363         iModel->SetTemplate( iDefaultTemplate );
       
   364         }
       
   365     
       
   366     iModel->Insert( aIndex, aCount );     
       
   367     
       
   368     if( aMediaListFocusIndex >= 0 )
       
   369         {
       
   370         SetFocusIndex( aMediaListFocusIndex );
       
   371         }
       
   372     
       
   373     if(!iWidget.model())
       
   374         {
       
   375         iWidget.SetModel( iModel->Accessor() );
       
   376         
       
   377         CGlxUiUtility* uiUtility = CGlxUiUtility::UtilityL();
       
   378         CleanupClosePushL( *uiUtility );
       
   379         TSize defaultIconSize = uiUtility->GetGridIconSize();
       
   380         TFileName resFile(KDC_APP_BITMAP_DIR);
       
   381         resFile.Append(KGlxIconsFilename);
       
   382         TInt defaultTextureId =  uiUtility->
       
   383                         GlxTextureManager().CreateIconTextureL( 
       
   384                         EMbmGlxiconsQgn_prop_image_notcreated, resFile, 
       
   385                         defaultIconSize ).Id();
       
   386                     
       
   387         static_cast<IMulCoverFlowWidget&>(iWidget).SetDefaultImage( defaultTextureId ) ;
       
   388         CleanupStack::PopAndDestroy( uiUtility );
       
   389         }    
       
   390 
       
   391     }
       
   392 
       
   393 // ----------------------------------------------------------------------------
       
   394 // RemoveItem
       
   395 // ----------------------------------------------------------------------------
       
   396 //    
       
   397 void CGlxMulModelProviderBase::RemoveItems( TInt aIndex, TInt aCount )
       
   398     {
       
   399     TRACER("CGlxMulModelProviderBase::RemoveItems");
       
   400     // RemoveItems does not throw according to model documentation
       
   401     iModel->Remove( aIndex, aCount );
       
   402     }    
       
   403 
       
   404 // ----------------------------------------------------------------------------
       
   405 // SetFocusIndex
       
   406 // ----------------------------------------------------------------------------
       
   407 //    
       
   408 void CGlxMulModelProviderBase::SetFocusIndex( TInt aIndex )
       
   409     {
       
   410     TRACER("CGlxMulModelProviderBase::SetFocusIndex");
       
   411     iModel->SetHighlight( aIndex );
       
   412     }
       
   413 // ----------------------------------------------------------------------------
       
   414 // IsFocused
       
   415 // ----------------------------------------------------------------------------
       
   416 //
       
   417 
       
   418 TBool CGlxMulModelProviderBase::IsFocused( TInt aIndex ) const 
       
   419     {
       
   420     TRACER("CGlxMulModelProviderBase::IsFocused");
       
   421     return aIndex == FocusIndex() && aIndex != LAST_INDEX;
       
   422     }
       
   423 
       
   424 
       
   425 
       
   426 // ----------------------------------------------------------------------------
       
   427 // FocusIndex
       
   428 // ----------------------------------------------------------------------------
       
   429 //
       
   430 
       
   431 TInt CGlxMulModelProviderBase::FocusIndex() const
       
   432     {
       
   433     TRACER("CGlxMulModelProviderBase::FocusIndex");
       
   434     TInt index = 0;
       
   435     /// @todo use multiline widget instead of this widget hack. Currently model does not have interface for highlight.
       
   436     
       
   437     // We are comparing depending on teh widget name which we are setting during the 
       
   438     // widget creation, but for that we had to do dynamic_cast which fails on hardware
       
   439     // and is not the preffered way of doing, so as of now we have to check using widget name
       
   440     
       
   441     if(UString(KListWidget) == UString(iWidget.widgetName() ) )
       
   442         {
       
   443         index = iModel->Highlight();
       
   444         }
       
   445     else if ( UString(KGridWidget) == UString(iWidget.widgetName() ) )
       
   446         {
       
   447         index = iModel->Highlight();
       
   448         }
       
   449     else if (UString(KCoverFlowWidget) == UString(iWidget.widgetName() ) )
       
   450         {
       
   451         index = iModel->Highlight();
       
   452         // Check if Model count is zero in FS view, activate back grid view.
       
   453         if (iModel->Count() ==0)
       
   454             {
       
   455             TRAP_IGNORE( iNavigationalState->ActivatePreviousViewL() );    
       
   456             }
       
   457         }
       
   458     else
       
   459         {
       
   460         return KErrGeneral;
       
   461         }
       
   462     
       
   463     return index;
       
   464     }
       
   465     
       
   466 // ----------------------------------------------------------------------------
       
   467 // HandleMessageL
       
   468 // ----------------------------------------------------------------------------
       
   469 //    
       
   470  void CGlxMulModelProviderBase::HandleMessageL( const CMPXMessage& /*aMessage*/, 
       
   471 	MGlxMediaList* /*aList*/ )
       
   472     {
       
   473     
       
   474     }
       
   475   
       
   476 // ----------------------------------------------------------------------------
       
   477 // HandleError
       
   478 // ----------------------------------------------------------------------------
       
   479 //
       
   480 void CGlxMulModelProviderBase::HandleError( TInt /*aError*/ ) 
       
   481     {
       
   482     
       
   483     }
       
   484   
       
   485 // ----------------------------------------------------------------------------
       
   486 // HandleCommandCompleteL
       
   487 // ----------------------------------------------------------------------------
       
   488 //  
       
   489 void CGlxMulModelProviderBase::HandleCommandCompleteL( TAny* /*aSessionId*/, CMPXCommand* /*aCommandResult*/, 
       
   490 	TInt /*aError*/, MGlxMediaList* /*aList*/ )
       
   491     {
       
   492     
       
   493     }
       
   494   
       
   495 // ----------------------------------------------------------------------------
       
   496 // HandleMediaL
       
   497 // ----------------------------------------------------------------------------
       
   498 //  
       
   499 void CGlxMulModelProviderBase::HandleMediaL( TInt /*aListIndex*/, MGlxMediaList* /*aList*/ )
       
   500     {
       
   501     
       
   502     }
       
   503   
       
   504 // ----------------------------------------------------------------------------
       
   505 // HandleItemModifiedL
       
   506 // ----------------------------------------------------------------------------
       
   507 //  
       
   508 void CGlxMulModelProviderBase::HandleItemModifiedL( const RArray<TInt>& /*aItemIndexes*/,
       
   509 	MGlxMediaList* /*aList*/ )
       
   510     {
       
   511     
       
   512     }
       
   513 
       
   514 // ----------------------------------------------------------------------------
       
   515 // HandleFocusChanged
       
   516 // ----------------------------------------------------------------------------
       
   517 //
       
   518 //@todo: Implementation to be done later depending on the scenario	
       
   519 void CGlxMulModelProviderBase::HandleFocusChanged( TInt /*aNewFocusIndex*/, 
       
   520 			TInt /*aPreviousFocusIndex*/ )
       
   521 	{
       
   522 	// default implementation empty
       
   523 	}
       
   524 
       
   525   
       
   526    
       
   527 // ----------------------------------------------------------------------------
       
   528 // BoundCommand
       
   529 // ----------------------------------------------------------------------------
       
   530 //
       
   531 MGlxBoundCommand* CGlxMulModelProviderBase::BoundCommand( TInt aVisualItemIndex ) const
       
   532     {
       
   533     TRACER("CGlxMulModelProviderBase::BoundCommand");
       
   534    	if ( iModel->Count() > 0 )
       
   535         {
       
   536         return GlxCommandBindingUtility::Get( Item( aVisualItemIndex ) );
       
   537         }
       
   538     return NULL;
       
   539     }
       
   540     
       
   541 // ----------------------------------------------------------------------------
       
   542 // Item
       
   543 // ----------------------------------------------------------------------------
       
   544 //
       
   545 const Alf::MulVisualItem& CGlxMulModelProviderBase::Item( TInt aIndex ) const
       
   546 	{
       
   547 	TRACER("CGlxMulModelProviderBase::Item");
       
   548 	ASSERT( aIndex >= 0 && aIndex < iModel->Count() );
       
   549 	return *(iModel->Data( aIndex ));
       
   550 	}
       
   551 
       
   552 //-----------------------------------------------------------------------------
       
   553 // HandleResolutionChanged
       
   554 //-----------------------------------------------------------------------------
       
   555 //
       
   556 void CGlxMulModelProviderBase::HandleOrientationChanged()
       
   557 	{
       
   558 	
       
   559 	}
       
   560 
       
   561 //-----------------------------------------------------------------------------
       
   562 // HandleResolutionChanged
       
   563 //-----------------------------------------------------------------------------
       
   564 //
       
   565 void CGlxMulModelProviderBase::AddWidgetEventHandler()
       
   566     {
       
   567     iWidget.AddEventHandler( *this );
       
   568     }
       
   569 
       
   570 //EOF