photosgallery/viewframework/commandhandlers/commoncommandhandlers/src/glxcommandhandlerslideshow.cpp
changeset 0 4e91876724a2
child 2 7d9067c6fcb1
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:    Slideshow command handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxcommandhandlerslideshow.h"
       
    22 
       
    23 #include <data_caging_path_literals.hrh>
       
    24 #include <mpxcollectionpath.h>
       
    25 #include <mpxmediadrmdefs.h>                     // for KMPXMediaDrmProtected
       
    26 #include <mpxviewutility.h>			 
       
    27 #include <aknViewAppUi.h>
       
    28 
       
    29 #include <glxuiutilities.rsg>
       
    30 #include <mglxmedialist.h>
       
    31 #include <glxuistd.h>
       
    32 #include <glxcommandhandlers.hrh>
       
    33 #include <glxresourceutilities.h>                // for CGlxResourceUtilities
       
    34 #include <glxattributecontext.h>                 // for CGlxAttributeContext
       
    35 #include <glxmedia.h>                            // for TGlxMedia
       
    36 #include <StringLoader.h>                        // for stringloader
       
    37 #include <glxlog.h>
       
    38 
       
    39 #include "shwslideshowviewplugin.hrh"		 // for the slideshow view's UID
       
    40 #include "shwslideshowsettingsplugin_UID.hrh"// for slideshow setting dlg UID
       
    41 #include "glxuiutility.h"
       
    42 #include "glxscreenfurniture.h"
       
    43 #include <glxicons.mbg>
       
    44 #include <glxsetappstate.h> // set PCFW app state
       
    45 #include <glxsettingsmodel.h>
       
    46 #include <glxupnprenderer.h> // get UPnP state
       
    47 #include <glxgeneraluiutilities.h>
       
    48 namespace
       
    49 	{
       
    50 	const TInt KShwDefaultBufferSize = 128;
       
    51 	}
       
    52 
       
    53 // This class does not have access to a CEikonEnv and hence 
       
    54 // pls ignore the code scanner warning - Using CEikonEnv::Static	
       
    55 #define GetAppUi() (dynamic_cast<CAknViewAppUi*>(CEikonEnv::Static()->EikAppUi()))
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // Two-phased constructor.
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C CGlxCommandHandlerSlideshow* CGlxCommandHandlerSlideshow::NewL(
       
    62     MGlxMediaListProvider* aMediaListProvider, TBool aStepBack, TBool aHasToolbarItem )
       
    63     {
       
    64     GLX_LOG_INFO( "CGlxCommandHandlerSlideshow::NewL" );
       
    65     CGlxCommandHandlerSlideshow* self = new ( ELeave )
       
    66     	CGlxCommandHandlerSlideshow(aMediaListProvider, aStepBack, aHasToolbarItem);
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70     return self;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // C++ default constructor can NOT contain any code, that
       
    75 // might leave.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CGlxCommandHandlerSlideshow::CGlxCommandHandlerSlideshow( MGlxMediaListProvider*
       
    79 	aMediaListProvider, TBool aStepBack, TBool aHasToolbarItem )
       
    80     : CGlxMediaListCommandHandler(aMediaListProvider, aHasToolbarItem), iStepBack(aStepBack)
       
    81     {
       
    82     // Do nothing
       
    83     }
       
    84  
       
    85 // ---------------------------------------------------------------------------
       
    86 // Symbian 2nd phase constructor can leave.
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 void CGlxCommandHandlerSlideshow::ConstructL()
       
    90     {
       
    91     GLX_LOG_INFO( "CGlxCommandHandlerSlideshow::ConstructL" );
       
    92     
       
    93     // Get a handle 
       
    94     iUiUtility = CGlxUiUtility::UtilityL();
       
    95 
       
    96     // Load resource file
       
    97 	TParse parse;
       
    98     parse.Set(KGlxUiUtilitiesResource, &KDC_APP_RESOURCE_DIR, NULL);
       
    99     TFileName resourceFile;
       
   100     resourceFile.Append(parse.FullName());
       
   101     CGlxResourceUtilities::GetResourceFilenameL(resourceFile);  
       
   102    	iResourceOffset = CCoeEnv::Static()->AddResourceFileL( resourceFile );
       
   103 
       
   104    // CGlxSettingsModel* model = CGlxSettingsModel::InstanceL();
       
   105     iShowInToolbar = ETrue; //model->ShowSlideshowInToolbar();
       
   106    // model->Close();
       
   107 
       
   108    	// Add supported commands with filter fields
       
   109    	// Play slideshow forwards
       
   110    	TCommandInfo info( EGlxCmdSlideshowPlay );
       
   111    	// Disable for static items and dont enable empty slideshow
       
   112     info.iMinSelectionLength = 1;
       
   113    	// Enable only for albums that have more than one item
       
   114     info.iMinSlideshowPlayableContainedItemCount = 1;
       
   115     // Disable for animated GIFs
       
   116     info.iDisallowAnimatedGIFs = ETrue;
       
   117     // Disable DRM protected content
       
   118     info.iDisallowDRM = ETrue;
       
   119     // Note! cannot just require all to be images as user can also start 
       
   120     // slideshow for a whole album from list view and in that case
       
   121     // selection contains a container
       
   122 	// Disable all videos
       
   123 	TMPXGeneralCategory categoryFilter = EMPXVideo;
       
   124 	// Disable the command for videos
       
   125 	TCommandInfo::TCategoryRule categoryRule = TCommandInfo::EForbidAll;
       
   126 	info.iCategoryFilter = categoryFilter;
       
   127 	info.iCategoryRule = categoryRule;
       
   128    	AddCommandL( info );
       
   129    	
       
   130    	// Play slideshow backwards: only the id changes
       
   131    	//info.iCommandId = EGlxCmdSlideshowPlayBackwards;
       
   132    	//AddCommandL( info );
       
   133 
       
   134     // new info to get the default filters
       
   135    	TCommandInfo info_show_always( EGlxCmdSlideshowSettings );
       
   136    	// Disable for empty views and views with only static items
       
   137     info_show_always.iMinSelectionLength = 1;
       
   138    	// slideshow settings
       
   139    	AddCommandL( info_show_always );
       
   140 
       
   141    	// Menu
       
   142    	info_show_always.iCommandId = EGlxCmdSlideshow;
       
   143    	AddCommandL( info_show_always );
       
   144 
       
   145     // Dummy command to get UPnP state
       
   146     TCommandInfo infoUpnpState( EGlxCmdShowViaUpnpStateChanged );
       
   147     AddCommandL( infoUpnpState );
       
   148 
       
   149    	// Buffer
       
   150    	iBufFlat = CBufFlat::NewL( KShwDefaultBufferSize );
       
   151 	}
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // Destructor
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 EXPORT_C CGlxCommandHandlerSlideshow::~CGlxCommandHandlerSlideshow()
       
   158     {
       
   159     GLX_LOG_INFO( "CGlxCommandHandlerSlideshow::~CGlxCommandHandlerSlideshow" );
       
   160     if ( iResourceOffset )
       
   161         {
       
   162         CCoeEnv::Static()->DeleteResourceFile(iResourceOffset);
       
   163         }
       
   164 
       
   165 	if (iUiUtility)
       
   166         {
       
   167         iUiUtility->Close();
       
   168         }
       
   169 
       
   170   	delete iBufFlat;
       
   171   	delete iBuffer;
       
   172     }
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // DoActivateL
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 void CGlxCommandHandlerSlideshow::DoActivateL(TInt aViewId)
       
   179     {
       
   180     GLX_LOG_INFO( "CGlxCommandHandlerSlideshow::DoActivateL" );    
       
   181     iViewId = aViewId;
       
   182 
       
   183     // for media list item "focus changed" notification
       
   184     MGlxMediaList& mediaList( MediaList() );
       
   185     mediaList.AddMediaListObserverL( this );
       
   186     }
       
   187 
       
   188 
       
   189 // ----------------------------------------------------------------------------
       
   190 // Deactivate
       
   191 // ----------------------------------------------------------------------------
       
   192 void CGlxCommandHandlerSlideshow::Deactivate()
       
   193     {
       
   194     GLX_LOG_INFO( "CGlxCommandHandlerSlideshow::Deactivate" );       
       
   195 
       
   196     MGlxMediaList& mediaList( MediaList() );
       
   197     mediaList.RemoveMediaListObserver( this );
       
   198     }
       
   199 
       
   200 // ----------------------------------------------------------------------------
       
   201 // IsSlideshowPlayableOnFocusedContainer
       
   202 // ----------------------------------------------------------------------------
       
   203 //
       
   204 TBool CGlxCommandHandlerSlideshow::IsSlideshowNotPlayableOnFocusedContainer
       
   205             (TInt aCommandId, MGlxMediaList& aList)
       
   206     {
       
   207     TBool slideshowDisabled = EFalse;
       
   208 
       
   209     // get the media item
       
   210     const TGlxMedia& item = aList.Item( aList.FocusIndex() );
       
   211     const TCommandInfo& info = CommandInfo(aCommandId);    
       
   212 
       
   213     // Check minimum item count if not yet disabled by previous rules
       
   214     TInt count(0);        
       
   215 
       
   216     if( (info.iMinSlideshowPlayableContainedItemCount )&&
       
   217             ( item.GetSlideshowPlayableContainedItemCount(count) ) )
       
   218         {
       
   219         // disable if less than required amount of items in container 
       
   220         // (ignore non-containers, i.e. -1)
       
   221         if( count != -1 )
       
   222             {
       
   223             slideshowDisabled = ( count < info.iMinSlideshowPlayableContainedItemCount );
       
   224             }
       
   225         }
       
   226     return slideshowDisabled;
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // DoExecute - the relevant action for the command id
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 TBool CGlxCommandHandlerSlideshow::DoExecuteL(TInt aCommandId,
       
   234 	MGlxMediaList& aList )
       
   235 	{
       
   236     GLX_LOG_INFO( "CGlxCommandHandlerSlideshow::DoExecuteL" );
       
   237 	TBool handledCommand = ETrue;
       
   238 	
       
   239 	switch (aCommandId)
       
   240 		{
       
   241         case EGlxCmdSlideshowPlay:
       
   242 	        {        
       
   243 	        // This check has to be done again here since Slideshow can be 
       
   244 	        // activated from toolbar even when there are non-slideshow playable 
       
   245 	        // items in a container and when that container is focused.	
       
   246 	        if( IsSlideshowNotPlayableOnFocusedContainer( aCommandId, aList ) )
       
   247 	            {
       
   248 	            HBufC* popupText = NULL;
       
   249 	            	            
       
   250 	            //Load the "No Images to Play Slideshow" string from the resource file
       
   251 	            popupText = StringLoader::LoadLC( R_GLX_NO_IMAGES_TO_PLAY_SLIDESHOW );
       
   252 	            
       
   253 	            // Show the Info Note.
       
   254 	            GlxGeneralUiUtilities::ShowInfoNoteL( popupText->Des(), EFalse );  
       
   255 	            
       
   256 	            // LoadLC will push text on to cleanupstack, 
       
   257 	            // hence it should be poped and destroyed
       
   258 	            CleanupStack::PopAndDestroy( popupText );
       
   259 	            }
       
   260 	        else
       
   261 	            {
       
   262             // Activate the slideshow view to play forwards
       
   263             ActivateViewL( NShwSlideshow::EPlayForwards );
       
   264             
       
   265             // set PCFW app state
       
   266             GlxSetAppState::SetState(EGlxInSlideshowView);
       
   267 	            }
       
   268             break;
       
   269             }
       
   270        /* case EGlxCmdSlideshowPlayBackwards:
       
   271             {
       
   272             // Activate the slideshow view to play backwards
       
   273             ActivateViewL( NShwSlideshow::EPlayBackwards );
       
   274             
       
   275             // set PCFW app state
       
   276             GlxSetAppState::SetState(EGlxInSlideshowView);
       
   277             
       
   278             break;
       
   279             }  */          
       
   280 		case EGlxCmdSlideshowSettings:
       
   281 			{
       
   282 			// In order for the Settings Dialogs Akn StatusPane to become 
       
   283 			// visible the the Hui display should be deactivated & activated
       
   284 			// before & after the Settings Dialog (which is uses the Akn 
       
   285 			// framework) is activated & deactivated respectively.
       
   286 			// Activating and deactivating the HUI within the Settings 
       
   287 			// Dialog class will cause a Cone 8 panic.
       
   288 			
       
   289 			// hide HUI display
       
   290 			CGlxUiUtility::HideAlfDisplayL();
       
   291 				{
       
   292 				MMPXViewUtility* viewUtility = MMPXViewUtility::UtilityL();
       
   293 				CleanupClosePushL(*viewUtility);
       
   294 	            
       
   295 	            // Activate the slideshow settings dialog
       
   296 	            viewUtility->ActivateViewL(
       
   297 	            	TUid::Uid(KShwSettingsDlgImplementationUid));
       
   298 	            	            
       
   299 	            CleanupStack::PopAndDestroy(viewUtility);	
       
   300 				}
       
   301 			// show HUI display
       
   302 			CGlxUiUtility::ShowAlfDisplayL();           	
       
   303 			GetAppUi()->ProcessCommandL(EGlxCmdResetView);
       
   304             break;
       
   305             }
       
   306         case EGlxCmdShowViaUpnpStateChanged:
       
   307 			{
       
   308         	handledCommand = EFalse;
       
   309 			break;
       
   310 			}
       
   311         default:
       
   312         	{
       
   313         	handledCommand = EFalse;
       
   314         	break;
       
   315         	}
       
   316 		}
       
   317 		
       
   318 	return handledCommand;
       
   319 	}
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // DoIsDisabled
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 TBool CGlxCommandHandlerSlideshow::DoIsDisabled(
       
   326     TInt /*aCommandId*/, MGlxMediaList& /*aList*/) const
       
   327     {
       
   328     // Disable if UPnP is active
       
   329     return ( GlxUpnpRenderer::Status() == NGlxUpnpRenderer::EActive );
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // BypassFiltersForExecute
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 TBool CGlxCommandHandlerSlideshow::BypassFiltersForExecute() const
       
   337     {
       
   338     // Always bypass filters to minimise the time spent by the base class
       
   339     // when it initialises the slideshow menu item.
       
   340     return ETrue;
       
   341     }
       
   342 
       
   343 // ----------------------------------------------------------------------------
       
   344 // HandleFocusChangedL
       
   345 // ----------------------------------------------------------------------------
       
   346 void CGlxCommandHandlerSlideshow::HandleFocusChangedL(
       
   347                 NGlxListDefs::TFocusChangeType /*aType*/,
       
   348                 TInt /*aNewIndex*/, TInt /*aOldIndex*/, MGlxMediaList* /*aList*/ )
       
   349     {
       
   350     GLX_FUNC("CGlxCommandHandlerSlideshow::HandleFocusChangedL");
       
   351 
       
   352     }
       
   353 
       
   354 // ---------------------------------------------------------------------------
       
   355 // HandleItemAddedL
       
   356 // ---------------------------------------------------------------------------
       
   357 //
       
   358 void CGlxCommandHandlerSlideshow::HandleItemAddedL(TInt /*aStartIndex*/,
       
   359             TInt /*aEndIndex*/, MGlxMediaList* /*aList*/)
       
   360     {
       
   361     }
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // HandleMediaL
       
   365 // ---------------------------------------------------------------------------
       
   366 //
       
   367 void CGlxCommandHandlerSlideshow::HandleMediaL(TInt /*aListIndex*/,
       
   368             MGlxMediaList* /*aList*/)
       
   369     {
       
   370     }
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 // HandleItemRemovedL
       
   374 // ---------------------------------------------------------------------------
       
   375 //
       
   376 void CGlxCommandHandlerSlideshow::HandleItemRemovedL(TInt /*aStartIndex*/,
       
   377             TInt /*aEndIndex*/, MGlxMediaList* /*aList*/)
       
   378     {
       
   379     }
       
   380 
       
   381 // ---------------------------------------------------------------------------
       
   382 // HandleItemModifiedL
       
   383 // ---------------------------------------------------------------------------
       
   384 //
       
   385 void CGlxCommandHandlerSlideshow::HandleItemModifiedL(
       
   386             const RArray<TInt>& /*aItemIndexes*/, MGlxMediaList* /*aList*/)
       
   387     {
       
   388     }
       
   389 
       
   390 // ---------------------------------------------------------------------------
       
   391 // HandleAttributesAvailableL
       
   392 // ---------------------------------------------------------------------------
       
   393 //
       
   394 void CGlxCommandHandlerSlideshow::HandleAttributesAvailableL(
       
   395             TInt aItemIndex, const RArray<TMPXAttribute>& aAttributes,
       
   396             MGlxMediaList* /*aList*/ )
       
   397     {
       
   398     if ( iShowInToolbar && MediaList().FocusIndex() == aItemIndex )
       
   399         {
       
   400         TIdentityRelation<TMPXAttribute> match( TMPXAttribute::MatchContentId );
       
   401 
       
   402         if ( aAttributes.Find( KMPXMediaGeneralCategory, match ) >= 0
       
   403             || aAttributes.Find( KMPXMediaDrmProtected, match ) >= 0
       
   404             || aAttributes.Find( KGlxMediaGeneralFramecount, match ) >= 0 )
       
   405             {
       
   406             UpdateToolbar();
       
   407             }
       
   408         }
       
   409     }
       
   410 
       
   411 // ---------------------------------------------------------------------------
       
   412 // HandleItemSelectedL
       
   413 // ---------------------------------------------------------------------------
       
   414 //
       
   415 void CGlxCommandHandlerSlideshow::HandleItemSelectedL(TInt /*aIndex*/,
       
   416             TBool /*aSelected*/, MGlxMediaList* /*aList*/)
       
   417     {
       
   418     }
       
   419 
       
   420 // ---------------------------------------------------------------------------
       
   421 // HandleMessageL
       
   422 // ---------------------------------------------------------------------------
       
   423 //
       
   424 void CGlxCommandHandlerSlideshow::HandleMessageL(
       
   425             const CMPXMessage& /*aMessage*/, MGlxMediaList* /*aList*/)
       
   426     {
       
   427     }
       
   428 
       
   429 // -----------------------------------------------------------------------------
       
   430 // ActivateViewL - launch the view 
       
   431 // -----------------------------------------------------------------------------
       
   432 //
       
   433 void CGlxCommandHandlerSlideshow::ActivateViewL( NShwSlideshow::TPlayDirection
       
   434 	aPlaybackDirection )
       
   435 	{
       
   436     GLX_LOG_INFO( "CGlxCommandHandlerSlideshow::ActivateViewL" );
       
   437     
       
   438     // Determine the path from the media list
       
   439     CMPXCollectionPath* path = MediaList().PathLC();
       
   440 	// Ensure the path's at the correct level for the view
       
   441 	if ( iStepBack && path->Levels() > 0 )
       
   442 		{
       
   443 		path->Back();
       
   444 		}
       
   445 	// Stream the data buffer
       
   446 	RBufWriteStream stream;
       
   447 	stream.Open( *iBufFlat );
       
   448 	CleanupClosePushL( stream );
       
   449 	// Write out the playback direction
       
   450 	stream.WriteInt32L( aPlaybackDirection );
       
   451 	stream.CommitL();
       
   452 	// Externalize the path to the stream	
       
   453 	path->ExternalizeL( stream );
       
   454 	
       
   455 	// ActivateViewL takes a TDesC*, rather than a TDesC8
       
   456 	// so copy the data accordingly
       
   457 	if ( iBuffer )
       
   458 		{
       
   459 		delete iBuffer;
       
   460 		iBuffer = NULL;
       
   461 		}
       
   462 	
       
   463 	TInt length = iBufFlat->Size();
       
   464 	iBuffer = HBufC::NewL( length );
       
   465 	TPtr bufferPtr = iBuffer->Des();
       
   466 	TPtr8 ptr = iBufFlat->Ptr( 0 );
       
   467 	bufferPtr.Copy( ptr );
       
   468 
       
   469    	// Get the view utility
       
   470     MMPXViewUtility* viewUtility = MMPXViewUtility::UtilityL();
       
   471 	CleanupClosePushL( *viewUtility );
       
   472     
       
   473     viewUtility->ActivateViewL( TUid::Uid(KShwSlideshowViewImplementationId),
       
   474     	iBuffer );
       
   475     	
       
   476     // set the view navigation direction so that previous view keeps its
       
   477     // media list and focus
       
   478     iUiUtility->SetViewNavigationDirection( EGlxNavigationForwards );
       
   479 
       
   480     CleanupStack::PopAndDestroy( 3, path ); // viewUtility, stream and path
       
   481 	}
       
   482 
       
   483 // ---------------------------------------------------------------------------
       
   484 // UpdateToolbarL
       
   485 // ---------------------------------------------------------------------------
       
   486 //
       
   487 void CGlxCommandHandlerSlideshow::UpdateToolbar()
       
   488     {
       
   489     TBool visible = EFalse;
       
   490 
       
   491     if ( GlxUpnpRenderer::Status() != NGlxUpnpRenderer::EActive )
       
   492         {
       
   493         TInt focus = MediaList().FocusIndex();
       
   494 
       
   495         if ( focus >= 0 )
       
   496             {
       
   497             const TGlxMedia& media = MediaList().Item( focus );
       
   498 
       
   499             TInt frameCount = 0;
       
   500             // get count, ignore return value
       
   501             (void)media.GetFrameCount( frameCount );
       
   502 
       
   503             // medialistcommandhandler has added these attributes to a low
       
   504             // priority fetch context when command was loaded so the values
       
   505             // should be loaded
       
   506             visible = ( EMPXImage == media.Category()
       
   507                     && !media.IsDrmProtected()
       
   508                     && 1 == frameCount );
       
   509             }
       
   510         }
       
   511 
       
   512     iUiUtility->ScreenFurniture()->SetToolbarItemVisibility(
       
   513             EGlxCmdSlideshowPlay, visible );
       
   514     }    
       
   515     
       
   516 
       
   517 // ---------------------------------------------------------------------------
       
   518 // PopulateToolbar
       
   519 // ---------------------------------------------------------------------------
       
   520 //
       
   521 void CGlxCommandHandlerSlideshow::PopulateToolbarL()
       
   522 	{
       
   523 	
       
   524 	iUiUtility->ScreenFurniture()->SetTooltipL( EGlxCmdSlideshowPlay, CAknButton::EPositionLeft );
       
   525 	}
       
   526 
       
   527 // End of File