photosgallery/slideshow/engine/controlsrc/shweffectcontrol.cpp
changeset 0 4e91876724a2
child 14 ce1c7ad1f18b
child 16 0bc0ea26031e
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:    The effect control for the slideshow
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // CLASS HEADER
       
    22 #include "shweffectcontrol.h"
       
    23 
       
    24 // EXTERNAL INCLUDES
       
    25 #include <mglxvisuallist.h>
       
    26 #include <mglxmedialist.h>
       
    27 #include <glxlog.h>
       
    28 #include <glxtracer.h>
       
    29 #include <AknUtils.h>
       
    30 // INTERNAL INCLUDES
       
    31 #include "shweffectmanager.h"
       
    32 #include "shweffect.h"
       
    33 #include "shwthumbnailloader.h"
       
    34 #include "shwslideshowenginepanic.h"
       
    35 #include "shwcallback.h"
       
    36 #include "shwtimer.h"
       
    37 #include "shwconstants.h"
       
    38 
       
    39 using namespace NShwSlideshow;
       
    40 
       
    41 // LOCAL NAMESPACE
       
    42 namespace
       
    43     {
       
    44     // local constants, the visual list range
       
    45     const TInt KRangeLeftFromFocus = -1;
       
    46     const TInt KRangeRightFromFocus = 1;
       
    47     }
       
    48 
       
    49 // LOCAL FUNCTIONS AND CONSTANTS
       
    50 // -----------------------------------------------------------------------------
       
    51 // C++ Constructor. Save a few bits of rom with inlining
       
    52 // -----------------------------------------------------------------------------
       
    53 inline CShwEffectControl::CShwEffectControl(
       
    54         MShwEffectManager& aEffectManager, 
       
    55         MGlxVisualList& aVisualList,
       
    56         MGlxMediaList& aMediaList,
       
    57         TSize aScreenSize )
       
    58     : iEffectManager( aEffectManager ),
       
    59     iVisualList( aVisualList ),
       
    60     iMediaList( aMediaList ),
       
    61 	iEffectLoopRestarted( EFalse ),
       
    62 	iFailedThumbnailIndex( KErrNotFound )
       
    63     {
       
    64     // initialize the default layout chain
       
    65     iDefaultIconLayout.SetOpacity( KMaxOpacity, 0 );
       
    66     iDefaultIconLayout.SetSize( aScreenSize.iWidth, aScreenSize.iHeight, 0 );
       
    67     // initialise the not visible layout
       
    68     iNotVisibleLayout.SetOpacity(KMinOpacity,0);
       
    69     iNotVisibleLayout.SetSize( 0, 0, 0 );
       
    70    iSplitter.SetDefaultLayout(&iNotVisibleLayout);
       
    71     // initialise the paused layout
       
    72     iPausedLayout.SetOpacity( KMaxOpacity, 0);
       
    73     iPausedLayout.SetSize( aScreenSize.iWidth, aScreenSize.iHeight, 0 );    
       
    74     }
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // NewL. Static construction
       
    78 // -----------------------------------------------------------------------------
       
    79 CShwEffectControl* CShwEffectControl::NewL(
       
    80     MShwEffectManager& aEffectManager, 
       
    81     MGlxVisualList& aVisualList,
       
    82     MGlxMediaList& aMediaList,
       
    83     TSize aScreenSize )
       
    84     {
       
    85     TRACER("CShwEffectControl* CShwEffectControl::NewL");
       
    86     GLX_LOG_INFO( "CShwEffectControl::NewL" );
       
    87     CShwEffectControl* self = 
       
    88         new( ELeave ) CShwEffectControl(
       
    89             aEffectManager, 
       
    90             aVisualList,
       
    91             aMediaList,
       
    92             aScreenSize );
       
    93 
       
    94     // 2nd phase construct
       
    95     CleanupStack::PushL( self );
       
    96     self->ConstructL();
       
    97     CleanupStack::Pop( self );
       
    98     return self;
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // Destructor.
       
   103 // -----------------------------------------------------------------------------
       
   104 CShwEffectControl::~CShwEffectControl()
       
   105     {
       
   106     TRACER("CShwEffectControl::~CShwEffectControl()");
       
   107     GLX_LOG_INFO( "CShwEffectControl::~CShwEffectControl" );
       
   108 
       
   109     iPausedVisuals.Close();   
       
   110 
       
   111     // stop observing the visual list
       
   112     iVisualList.RemoveObserver( this );
       
   113     // delete timer, it cancels itself
       
   114     delete iTransitionTimer;
       
   115     // remove viewing context
       
   116     iVisualList.RemoveContext( iContextId );
       
   117     // delete the thumbnail loader
       
   118     delete iThumbnailLoader;
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // ConstructL.
       
   123 // -----------------------------------------------------------------------------
       
   124 void CShwEffectControl::ConstructL()
       
   125     {
       
   126     TRACER("CShwEffectControl::ConstructL()");
       
   127     GLX_LOG_INFO( "CShwEffectControl::ConstructL" );
       
   128 
       
   129     // create thumbnail loader for the medialist
       
   130     iThumbnailLoader  = CShwThumbnailLoader::NewL( iMediaList, *this );
       
   131 
       
   132     // create the timer to end the transition phase
       
   133     iTransitionTimer = CShwTimer::NewL( CActive::EPriorityStandard );
       
   134 
       
   135     // add us as visual list observer
       
   136     iVisualList.AddObserverL( this );
       
   137 
       
   138     // specify viewing range for the visual list
       
   139     iContextId = iVisualList.AddContextL(
       
   140         KRangeLeftFromFocus, KRangeRightFromFocus );
       
   141 
       
   142     // initialize splitter
       
   143     iSplitter.SetVisualListL( &iVisualList );
       
   144     // add the splitter layout on the bottom
       
   145     //subhasis commented 1 line
       
   146 	//API depricated in visual list manager
       
   147     iVisualList.AddLayoutL( &iSplitter );
       
   148     }
       
   149 
       
   150 // -----------------------------------------------------------------------------
       
   151 // SendTransitionReadyL.
       
   152 // -----------------------------------------------------------------------------
       
   153 TInt CShwEffectControl::SendTransitionReadyL()
       
   154     {
       
   155     TRACER("CShwEffectControl::SendTransitionReadyL()");
       
   156     GLX_LOG_INFO( "CShwEffectControl::SendTransitionReadyL" );
       
   157     // cancel the timer
       
   158     iTransitionTimer->Cancel();
       
   159     // we need to remove the high quality thumbnails we dont plan
       
   160     // to show in near future, so focus minus range to left 
       
   161     // is the first to unload
       
   162     TInt indexToUnloadBackwards = NextListIndex( KRangeLeftFromFocus );
       
   163     // check that this index is not in focus or next from focus
       
   164     // this can happen if the list to play is really short
       
   165     TInt focusIndex = iMediaList.FocusIndex();
       
   166     if( ( indexToUnloadBackwards != focusIndex )&&
       
   167         ( indexToUnloadBackwards != NextListIndex( KNavigateForwards ) ) )
       
   168         {
       
   169         // ok, not visible so can unload
       
   170         iThumbnailLoader->Unload( indexToUnloadBackwards );
       
   171         }
       
   172     // send the event
       
   173     TShwEventTransitionReady transitionReady;
       
   174     SendEventL( &transitionReady );
       
   175     // return KErrNone, return value is ignored by CPeriodic
       
   176     return KErrNone;
       
   177     }
       
   178 
       
   179 // -----------------------------------------------------------------------------
       
   180 // NotifyL.
       
   181 // -----------------------------------------------------------------------------
       
   182 void CShwEffectControl::NotifyL( MShwEvent* aEvent )
       
   183     {
       
   184     TRACER("CShwEffectControl::NotifyL");
       
   185     // we got an event
       
   186     // is it initialize
       
   187     TShwEventInitialize* init = 
       
   188         dynamic_cast<TShwEventInitialize*>( aEvent );
       
   189     // is it start view
       
   190     TShwEventStartView* viewEvent = 
       
   191         dynamic_cast<TShwEventStartView*>( aEvent );
       
   192     // start transition?
       
   193     TShwEventStartTransition* transEvent = 
       
   194         dynamic_cast<TShwEventStartTransition*>( aEvent );
       
   195     // was it a pause or resume event?
       
   196     TShwEventPause* pauseEvent = 
       
   197         dynamic_cast<TShwEventPause*>( aEvent );
       
   198     TShwEventResume* resumeEvent = 
       
   199         dynamic_cast<TShwEventResume*>( aEvent );
       
   200     // or a navigation event?
       
   201     TShwEventNextImage* nextImageEvent = 
       
   202         dynamic_cast< TShwEventNextImage* >( aEvent );
       
   203     TShwEventPreviousImage* previousImageEvent =
       
   204         dynamic_cast< TShwEventPreviousImage* >( aEvent );
       
   205     TShwEventToggleControlUi* toggleControlUiEvent = 
       
   206         dynamic_cast< TShwEventToggleControlUi* >( aEvent );
       
   207 
       
   208     // process init event
       
   209     if( init )
       
   210         {
       
   211         // prepare the first effect and load the correct size thumbnail
       
   212         // thumbnail loader ensures that the size attribute is available
       
   213         PrepareAndLoadImageToViewL();
       
   214         }
       
   215     // process start view event
       
   216     else if( viewEvent )
       
   217         {
       
   218         HandleStartViewEventL( *viewEvent );
       
   219         }
       
   220     // process start transition event
       
   221     else if( transEvent )
       
   222         {
       
   223         HandleStartTransitionEventL( *transEvent );
       
   224         }
       
   225     // process pause event
       
   226     else if( pauseEvent )
       
   227         {
       
   228         HandlePauseEventL();
       
   229         }
       
   230     // process resume event
       
   231     else if( resumeEvent )
       
   232         {
       
   233         HandleResumeEventL();
       
   234         }
       
   235     // process user navigate to next
       
   236     else if( nextImageEvent )
       
   237         {
       
   238         HandleNextImageEventL();
       
   239         }
       
   240     // process toggling UI by pressing selection key
       
   241     else if( toggleControlUiEvent )
       
   242         {
       
   243         HandleToggleControlUiEventL();
       
   244         }
       
   245     // process user navigate to previous
       
   246     else if ( previousImageEvent )
       
   247         {
       
   248         HandlePreviousImageEventL();
       
   249         }
       
   250     // no other events are interesting for us
       
   251     }
       
   252 
       
   253 // -----------------------------------------------------------------------------
       
   254 // HandleFocusChangedL.
       
   255 // -----------------------------------------------------------------------------
       
   256 void CShwEffectControl::HandleFocusChangedL(
       
   257     TInt aFocusIndex, TReal32 /*aItemsPerSecond*/, MGlxVisualList* /*aList*/,
       
   258     NGlxListDefs::TFocusChangeType /*aType*/ )
       
   259     {
       
   260     TRACER("CShwEffectControl::HandleFocusChangedL");
       
   261     GLX_LOG_INFO1( "CShwEffectControl::HandleFocusChangedL %d", aFocusIndex );
       
   262     // set current as previous
       
   263     iPreviousVisual = iCurrentVisual;
       
   264     // take new current
       
   265     iCurrentVisual = iVisualList.Visual( aFocusIndex );
       
   266     // we need to remove the high quality thumbnails we dont plan
       
   267     // to show in near future, so focus minus range to left minus one
       
   268     // is the first to unload
       
   269     TInt indexToUnloadBackwards = NextListIndex( KRangeLeftFromFocus - 1 );
       
   270     // check that this index is not in focus or next from focus
       
   271     // this can happen if the list to play is really short
       
   272     if( ( indexToUnloadBackwards != aFocusIndex )&&
       
   273         ( indexToUnloadBackwards != NextListIndex( KNavigateForwards ) ) )
       
   274         {
       
   275         // ok, not visible so can unload
       
   276         iThumbnailLoader->Unload( indexToUnloadBackwards );
       
   277         }
       
   278     // unload also range + 1 as user might navigate backwards fast
       
   279     TInt indexToUnloadForwards = NextListIndex( KRangeRightFromFocus + 1 );
       
   280     // check that this index is not in focus or next from focus
       
   281     // this can happen if the list to play is really short
       
   282     if( ( indexToUnloadForwards != aFocusIndex )&&
       
   283         ( indexToUnloadForwards != NextListIndex( KNavigateForwards ) ) )
       
   284         {
       
   285         // ok, not visible so can unload
       
   286         iThumbnailLoader->Unload( indexToUnloadForwards );
       
   287         }
       
   288     }
       
   289 
       
   290 // -----------------------------------------------------------------------------
       
   291 // HandleSizeChanged.
       
   292 // -----------------------------------------------------------------------------
       
   293 void CShwEffectControl::HandleSizeChanged(
       
   294     const TSize& /*aSize*/, MGlxVisualList* /*aList*/ )
       
   295     {
       
   296     // nothing to be done
       
   297     }
       
   298 // -----------------------------------------------------------------------------
       
   299 // HandleToggleControlUiEventL.
       
   300 // -----------------------------------------------------------------------------
       
   301 void CShwEffectControl::HandleToggleControlUiEventL()
       
   302     {
       
   303     // nothing to be done
       
   304     }
       
   305  
       
   306 // -----------------------------------------------------------------------------
       
   307 // HandleVisualRemoved.
       
   308 // -----------------------------------------------------------------------------
       
   309 void CShwEffectControl::HandleVisualRemoved(
       
   310     const CAlfVisual* aVisual, MGlxVisualList* /*aList*/ )
       
   311     {
       
   312     TRACER("CShwEffectControl::HandleVisualRemoved");
       
   313     GLX_LOG_INFO( "CShwEffectControl::HandleVisualRemoved" );
       
   314     // remove the layout for this visual just to make sure we dont use it
       
   315     //subhasis commented 1 line
       
   316 	//API depricated in visual list manager
       
   317     iSplitter.RemoveLayout( aVisual );
       
   318     }
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // HandleVisualAddedL.
       
   322 // -----------------------------------------------------------------------------
       
   323 void CShwEffectControl::HandleVisualAddedL(
       
   324     CAlfVisual* /*aVisual*/, TInt /*aIndex*/, MGlxVisualList* /*aList*/ )
       
   325     {
       
   326     // nothing to be done
       
   327     }
       
   328 
       
   329 // -----------------------------------------------------------------------------
       
   330 // HandleThumbnailLoadedL.
       
   331 // -----------------------------------------------------------------------------
       
   332 void CShwEffectControl::HandleThumbnailLoadedL( TInt aIndex )
       
   333     {
       
   334     TRACER("CShwEffectControl::HandleThumbnailLoadedL");
       
   335     TInt focus = iVisualList.FocusIndex();
       
   336     GLX_LOG_INFO2( 
       
   337         "CShwEffectControl::HandleThumbnailLoadedL %d, focus %d", aIndex, focus );
       
   338     // check the index
       
   339     // was it on focus, we cannot check the state as it can be either
       
   340     // view or transition because of user navigation
       
   341     if( aIndex == focus )
       
   342         {
       
   343         GLX_LOG_INFO( 
       
   344             "HandleThumbnailLoadedL - sending TShwEventReadyToView" );
       
   345         // its focus index so lets send ready to view
       
   346         // send ready to view event
       
   347         TShwEventReadyToView readyToView;
       
   348         SendEventL( &readyToView );
       
   349         }
       
   350     // is it next from focus
       
   351     else if( aIndex == NextListIndex( KNavigateForwards ) )
       
   352         {
       
   353         GLX_LOG_INFO( 
       
   354             "HandleThumbnailLoadedL - sending TShwEventReadyToAdvance" );
       
   355         // send ready to advance command, 
       
   356         // it tells the observers that we are ready to advance to next image
       
   357         TShwEventReadyToAdvance readyToAdvance;
       
   358         SendEventL( &readyToAdvance );
       
   359         }
       
   360     }
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // HandleThumbnailLoadFailureL.
       
   364 // -----------------------------------------------------------------------------
       
   365 void CShwEffectControl::HandleThumbnailLoadFailureL( TInt aIndex )
       
   366     {
       
   367     TRACER("CShwEffectControl::HandleThumbnailLoadFailureL");
       
   368     GLX_LOG_INFO1( "CShwEffectControl::HandleThumbnailLoadFailureL %d", aIndex );
       
   369     // We cant remove the errornous item from the medialist so 
       
   370     // at the moment we just proceed as normal
       
   371     // user will then see a broken icon for a while
       
   372     // we need to remember this index however as we dont want to start the
       
   373     // effect for it
       
   374     iFailedThumbnailIndex = aIndex;
       
   375     HandleThumbnailLoadedL( aIndex );
       
   376     }
       
   377 
       
   378 // -----------------------------------------------------------------------------
       
   379 // HandleMediaListEmpty
       
   380 // -----------------------------------------------------------------------------
       
   381 void CShwEffectControl::HandleMediaListEmpty()
       
   382     {
       
   383     TRACER("CShwEffectControl::HandleMediaListEmpty");
       
   384     GLX_LOG_INFO( "CShwEffectControl::HandleMediaListEmpty" );
       
   385     // need to remove the contexts from medialist as closing down will 
       
   386     // take a while
       
   387     // stop observing the visual list
       
   388     iVisualList.RemoveObserver( this );
       
   389     // delete the thumbnail loader
       
   390     delete iThumbnailLoader;
       
   391     // set to NULL to prevent double delete
       
   392     iThumbnailLoader = NULL;
       
   393     // send fatal error message
       
   394     TShwEventFatalError errmessage;
       
   395     // need to TRAP as we cannot leave
       
   396     TRAPD( error, SendEventL( &errmessage ) );
       
   397     // was there an error
       
   398     if( error != KErrNone )
       
   399         {
       
   400         // panic engine as nothing else can be done
       
   401         NShwEngine::Panic( NShwEngine::EEngineFatalError );
       
   402         }
       
   403     }
       
   404 
       
   405 // -----------------------------------------------------------------------------
       
   406 // PrepareAndLoadImageToViewL
       
   407 // -----------------------------------------------------------------------------
       
   408 void CShwEffectControl::PrepareAndLoadImageToViewL()
       
   409     {
       
   410     TRACER("CShwEffectControl::PrepareAndLoadImageToViewL");
       
   411     // get current index
       
   412     TInt currentIndex = iVisualList.FocusIndex();
       
   413     // get current effect
       
   414     MShwEffect* currentEffect = iEffectManager.CurrentEffect();
       
   415     __ASSERT_ALWAYS( 
       
   416         currentEffect, NShwEngine::Panic( NShwEngine::ENullCurrentEffect ) );
       
   417     // set the current visual, since on first time there has not been navigation
       
   418     iCurrentVisual = iVisualList.Visual( currentIndex );
       
   419     /// get the image size from thumbnail loader
       
   420     TSize imgSize = iThumbnailLoader->ImageSizeL( currentIndex );
       
   421     // tell the effect to prepare for viewing current visual
       
   422     // thumbnail size is returned
       
   423     TSize thumbnailSize = 
       
   424         currentEffect->PrepareViewL( iCurrentVisual, imgSize );
       
   425     // ask the thumbnail loader to load the thumbnail
       
   426     // once the thumbnail is loaded, we get a callback
       
   427     iThumbnailLoader->LoadAndNotifyL(
       
   428         currentIndex, thumbnailSize );
       
   429     }
       
   430 
       
   431 // -----------------------------------------------------------------------------
       
   432 // HandleStartViewEventL.
       
   433 // -----------------------------------------------------------------------------
       
   434 void CShwEffectControl::HandleStartViewEventL( TShwEventStartView& aEvent )
       
   435     {
       
   436     TRACER("CShwEffectControl::HandleStartViewEventL");
       
   437     GLX_LOG_INFO( "CShwEffectControl::HandleStartViewEventL" );
       
   438 
       
   439     // remember the current view length, it is packaged into the event
       
   440     iViewDuration = aEvent.Parameter();
       
   441 
       
   442     // update the state
       
   443     iState = EShwEffectStateInView;
       
   444     
       
   445 	//following code commented to remove layout dependency
       
   446 	//! to be refactored
       
   447 	 
       
   448 	// get the focus index
       
   449 	TInt currentIndex = iVisualList.FocusIndex();
       
   450     // tell effect to exit transition
       
   451     // if we got view event and loop is already started
       
   452    if( iEffectLoopRestarted )
       
   453         {
       
   454         // exit transition for the previous effect and visual
       
   455         // this is done first since the next effect may be same
       
   456         // as previous
       
   457         iPreviousEffect->ExitTransition( iPreviousVisual );
       
   458         // remove layout from splitter
       
   459         iSplitter.RemoveLayout( iPreviousVisual );
       
   460         }
       
   461     else
       
   462         {
       
   463         // get the current effect
       
   464         MShwEffect* currentEffect = iEffectManager.CurrentEffect();
       
   465         // remove the old layout
       
   466         iSplitter.RemoveLayout( iCurrentVisual );
       
   467         // was this thumbnail succesfully loaded?
       
   468 		if ( iFailedThumbnailIndex == currentIndex )
       
   469 		    {
       
   470         	// set the temporary layout for default icon
       
   471         	iSplitter.SetLayoutL( &iDefaultIconLayout, iCurrentVisual );
       
   472 		    }
       
   473 		else
       
   474 		    {
       
   475 		    // Set paused effect on current visual 
       
   476 		    //if(iPausedVisuals.Count())
       
   477 		    //    {
       
   478 		    //	iSplitter.SetLayoutL( &iPausedLayout, iCurrentVisual );
       
   479 		    //	}
       
   480 			//else
       
   481 			//    {
       
   482 	            // enter the view mode for visual
       
   483 	            // ask the layout chain and set that to the current visual
       
   484 	            // set also effect fade-in
       
   485 	        		iSplitter.SetLayoutL( 
       
   486 	    			currentEffect->EnterViewL( 
       
   487 	    				iCurrentVisual, 
       
   488 	    				iViewDuration, 
       
   489 	    				KFirstEffectFadeInDuration ), 
       
   490 	    			iCurrentVisual );
       
   491 		      //  }
       
   492 		    }
       
   493 		// bring the focus visual to the front
       
   494 		iCurrentVisual->MoveToFront();    
       
   495 		}
       
   496 	//parts of the code commented to remove layout dependency
       
   497 	//! to be refactored
       
   498     // get next index forwards
       
   499     TInt nextIndex = NextListIndex( KNavigateForwards );
       
   500     // need to tell the next effect to prepare for the view
       
   501     // get next effect
       
   502     MShwEffect* nextEffect = iEffectManager.Effect( KNavigateForwards );
       
   503     // get next visual
       
   504     CAlfVisual* nextVisual = iVisualList.Visual( nextIndex );
       
   505     // get the real size of the image
       
   506     TSize imgSize = iThumbnailLoader->ImageSizeL( nextIndex );
       
   507     // tell the effect to prepare to view the next visual
       
   508     // thumbnail size is returned
       
   509     TSize thumbnailSize = 
       
   510        nextEffect->PrepareViewL( nextVisual, imgSize );
       
   511     // ask the thumbnail loader to load next thumbnail
       
   512     iThumbnailLoader->LoadAndNotifyL( nextIndex, thumbnailSize );
       
   513     }
       
   514 
       
   515 // -----------------------------------------------------------------------------
       
   516 // HandleStartTransitionEventL.
       
   517 // -----------------------------------------------------------------------------
       
   518 void CShwEffectControl::HandleStartTransitionEventL( 
       
   519     TShwEventStartTransition& aEvent )
       
   520     {
       
   521     TRACER("CShwEffectControl::HandleStartTransitionEventL");
       
   522     GLX_LOG_INFO( "CShwEffectControl::HandleStartTransitionEventL" );
       
   523 	//following code was commented to remove layout dependency
       
   524 	//! to be refactored
       
   525     // update the state
       
   526     iState = EShwEffectStateInTransition;
       
   527 
       
   528     // duration is in event parameters
       
   529     TInt duration = aEvent.Parameter();
       
   530     // enter current effects transition mode for current visual
       
   531     // get current effect
       
   532     MShwEffect* currentEffect = iEffectManager.CurrentEffect();
       
   533     // inform the effect that view mode ended
       
   534     currentEffect->ExitView( iCurrentVisual );
       
   535     // remove the view layout
       
   536     iSplitter.RemoveLayout( iCurrentVisual );
       
   537     // add the layout chain to the current visual
       
   538     iSplitter.SetLayoutL(
       
   539         currentEffect->EnterTransitionL(
       
   540             iCurrentVisual, duration ), iCurrentVisual );
       
   541     // ok, now we have the loop started so next time we get view_event 
       
   542     // we stop this transition
       
   543     iEffectLoopRestarted = ETrue;
       
   544 
       
   545     // enter next effects view mode for next visual
       
   546     // get next effect, given the direction stored in the event
       
   547     MShwEffect* nextEffect = iEffectManager.Effect( KNavigateForwards );
       
   548     // get next list index forwards
       
   549     TInt nextIndex = NextListIndex( KNavigateForwards );
       
   550     GLX_LOG_INFO1( "CShwEffectControl::NextVisual, %d", nextIndex );
       
   551     // get next visual, focus plus 1 modulo itemcount
       
   552     CAlfVisual* nextVisual = iVisualList.Visual( nextIndex );
       
   553 
       
   554     // remove old layout
       
   555     iSplitter.RemoveLayout( nextVisual );
       
   556     // was the next thumbnail succesfully loaded?
       
   557 	if ( iFailedThumbnailIndex == nextIndex )
       
   558 	    {
       
   559 		TAlfTimedValue opacity(KMaxOpacity,0);
       
   560 		// Set Opacity to make it visible
       
   561 		nextVisual->SetOpacity(opacity);
       
   562     	// set the temporary layout for default icon
       
   563     	iSplitter.SetLayoutL( &iDefaultIconLayout, nextVisual );
       
   564 	    }
       
   565 	else
       
   566 	    {
       
   567         // enter view mode for the effect
       
   568         // add the layout chain to the current visual
       
   569         iSplitter.SetLayoutL(
       
   570             nextEffect->EnterViewL( nextVisual, iViewDuration, duration ), 
       
   571                 nextVisual );
       
   572 	    }
       
   573 
       
   574 
       
   575     // proceed on the list, 1 step forward
       
   576     NavigateListL( KNavigateForwards );
       
   577 
       
   578     
       
   579 	// fix for EVTY-7H8BV5
       
   580 	// When transition is happening from current to next visual, we are seeing next to next visual 
       
   581 	// which is not needed so making next to next visual to invisible
       
   582     TInt nextToNextIndex = NextListIndex( KNavigateForwards );
       
   583     CAlfVisual* nextToNextVisual = iVisualList.Visual( nextToNextIndex );
       
   584 	if(nextToNextVisual != iPreviousVisual)    
       
   585 		{
       
   586 		TAlfTimedValue opacity(KMinOpacity,0);
       
   587 		nextToNextVisual->SetOpacity(opacity);	    				
       
   588 		}
       
   589 
       
   590     // need to send ready to view as in the normal case we already are 
       
   591     // (the image is already there)
       
   592     TShwEventReadyToView readyToView;
       
   593     SendEventL( &readyToView );
       
   594 
       
   595     // need to start timer to send the transition ready
       
   596     iTransitionTimer->Start(
       
   597         duration, duration, 
       
   598         TShwCallBack< CShwEffectControl, SendTransitionReadyL >( this ) );
       
   599     }
       
   600 
       
   601 // -----------------------------------------------------------------------------
       
   602 // HandlePauseEventL.
       
   603 // -----------------------------------------------------------------------------
       
   604 void CShwEffectControl::HandlePauseEventL()
       
   605     {
       
   606     TRACER("CShwEffectControl::HandlePauseEventL");
       
   607     GLX_LOG_INFO( "CShwEffectControl::HandlePauseEventL" );
       
   608 
       
   609     // Need to know if user navigates during pause
       
   610     iUserNavigated = EFalse;
       
   611 
       
   612     // if we are in transition, pause the timer
       
   613     if ( iState == EShwEffectStateInTransition )
       
   614         {
       
   615         iTransitionTimer->Pause();
       
   616         iPausedVisuals.AppendL(iPreviousVisual);
       
   617         }
       
   618     // Store the current visual
       
   619     iPausedVisuals.AppendL(iCurrentVisual);
       
   620 	//subhasis commented 1 line
       
   621 	//API depricated in visual list manager
       
   622     iSplitter.RemoveLayout( iCurrentVisual );
       
   623     iSplitter.SetLayoutL( &iPausedLayout, iCurrentVisual );
       
   624     // we need to pause all effects as user may navigate while we are in pause
       
   625     // and user navigation may change the current and next effect
       
   626     RPointerArray< MShwEffect > effects;
       
   627     // need to close the array in case of a leave
       
   628     CleanupClosePushL( effects );
       
   629     iEffectManager.GetActiveEffectsL( effects );
       
   630     // loop through all active ones
       
   631     for( TInt i = 0; i < effects.Count(); ++i )
       
   632         {
       
   633         // get the effect and pause it
       
   634         effects[ i ]->PauseL();
       
   635         }
       
   636     CleanupStack::PopAndDestroy( &effects );
       
   637     }
       
   638 
       
   639 // -----------------------------------------------------------------------------
       
   640 // HandleResumeEventL.
       
   641 // -----------------------------------------------------------------------------
       
   642 void CShwEffectControl::HandleResumeEventL()
       
   643     {
       
   644     TRACER("CShwEffectControl::HandleResumeEventL");
       
   645     GLX_LOG_INFO( "CShwEffectControl::HandleResumeEventL" );
       
   646     // we need to resume all effects as user may navigate while we are in pause
       
   647     // and user navigation may change the current and next effect
       
   648     RPointerArray< MShwEffect > effects;
       
   649     // need to close the array in case of a leave
       
   650     CleanupClosePushL( effects );
       
   651     iEffectManager.GetActiveEffectsL( effects );
       
   652     // loop through all active ones
       
   653     for( TInt i = 0; i < effects.Count(); ++i )
       
   654         {
       
   655         // get the effect and pause it
       
   656         effects[ i ]->Resume();
       
   657         }
       
   658     CleanupStack::PopAndDestroy( &effects );
       
   659 
       
   660     // did user navigate while paused?
       
   661     if( iUserNavigated )
       
   662         {
       
   663         // resume and cancel the transition timer for its next use
       
   664         // if user navigates while pause 
       
   665         // we never continue from transition so we need
       
   666         // to resume the timer, otherwise it stays paused forever
       
   667         iTransitionTimer->Resume();
       
   668         iTransitionTimer->Cancel();
       
   669         }
       
   670     // if we are in transition, resume the timer
       
   671     else if ( iState == EShwEffectStateInTransition )
       
   672         {
       
   673         // restart timer to continue the transition
       
   674         iTransitionTimer->Resume();
       
   675 	    TInt count = iPausedVisuals.Count();
       
   676 	    if (count > 0)    
       
   677 	        {
       
   678             while (count > 0)
       
   679 		        {
       
   680 		        // unpause and remove the visuals
       
   681     		    //iPausedVisuals[count]->Resume();
       
   682 		        iPausedVisuals.Remove(--count);
       
   683 		        }
       
   684 	        }
       
   685         }
       
   686     }
       
   687 
       
   688 // -----------------------------------------------------------------------------
       
   689 // HandleNextImageEventL.
       
   690 // -----------------------------------------------------------------------------
       
   691 void CShwEffectControl::HandleNextImageEventL()
       
   692     {
       
   693     TRACER("CShwEffectControl::HandleNextImageEventL");
       
   694     GLX_LOG_INFO( "CShwEffectControl::HandleNextImageEventL" );
       
   695 
       
   696     // reset the flag so that we do prepare and start view for the visual
       
   697     iEffectLoopRestarted = EFalse;
       
   698     // set user navigate flag so that we do ExitView in resume
       
   699     iUserNavigated = ETrue;
       
   700 
       
   701     // get current effect
       
   702     MShwEffect* currentEffect = iEffectManager.CurrentEffect();
       
   703     // inform the effect that view mode ended
       
   704     currentEffect->ExitView( iCurrentVisual );
       
   705     // remove the view layout
       
   706     //subhasis commented 1 line
       
   707 	//API depricated in visual list manager
       
   708     iSplitter.RemoveLayout( iCurrentVisual );
       
   709     // were we in transition
       
   710     if ( iState == EShwEffectStateInTransition )
       
   711         {
       
   712         // we're in transition so the navigation is complete but we
       
   713         // want to view to the current visual immediately
       
   714         // in transition two effects exist, previous and current
       
   715         // and we're moving from the previous visual to the current visual
       
   716 
       
   717         // remove the layout from previous
       
   718         //subhasis commented 1 line
       
   719 		//API depricated in visual list manager
       
   720         iSplitter.RemoveLayout( iPreviousVisual );
       
   721         // cancel the timer to prevent a duplicate start view event
       
   722         iTransitionTimer->Cancel();
       
   723         }
       
   724     else
       
   725         {
       
   726         // we're in the view state
       
   727         // so we want to stop viewing the current visual
       
   728         // and show the next one
       
   729 
       
   730         // proceed on the list, 1 step forward
       
   731         NavigateListL( KNavigateForwards );
       
   732 
       
   733         // set the temporary layout for default icon
       
   734         iSplitter.SetLayoutL( &iDefaultIconLayout, iCurrentVisual );
       
   735         }
       
   736 
       
   737     // call prepareview for the effect and load the image
       
   738     PrepareAndLoadImageToViewL();
       
   739     }
       
   740 
       
   741 // -----------------------------------------------------------------------------
       
   742 // HandlePreviousImageEventL.
       
   743 // -----------------------------------------------------------------------------
       
   744 void CShwEffectControl::HandlePreviousImageEventL()
       
   745     {
       
   746     TRACER("CShwEffectControl::HandlePreviousImageEventL");
       
   747     GLX_LOG_INFO( "CShwEffectControl::HandlePreviousImageEventL" );
       
   748 
       
   749     // reset the flag so that we do prepare and start view for the visual
       
   750     iEffectLoopRestarted = EFalse;
       
   751     // set user navigate flag so that we do EnterView in next StartView
       
   752     iUserNavigated = ETrue;
       
   753 
       
   754     // ExitView - current
       
   755     // get current effect
       
   756     MShwEffect* currentEffect = iEffectManager.CurrentEffect();
       
   757     // inform the effect that view mode ended
       
   758     currentEffect->ExitView( iCurrentVisual );
       
   759     // remove the current layout
       
   760     //subhasis commented 1 line
       
   761 	//API depricated in visual list manager
       
   762     iSplitter.RemoveLayout( iCurrentVisual );
       
   763     // remove the previous layout as well, its no-op if there wasnt one
       
   764     iSplitter.RemoveLayout( iPreviousVisual );
       
   765     // proceed on the list, 1 step backwards
       
   766     NavigateListL( KNavigateBackwards );
       
   767 
       
   768     // were we in transition
       
   769     if ( iState == EShwEffectStateInTransition )
       
   770         {
       
   771         // as we're in transition, the focus index has already been
       
   772         // updated to the next item so we need to step back
       
   773 
       
   774         // cancel the timer to prevent a duplicate start view event
       
   775         iTransitionTimer->Cancel();
       
   776         }
       
   777     else
       
   778         {
       
   779         // EnterView - previous
       
   780         // set the temporary layout for default icon
       
   781         iSplitter.SetLayoutL( &iDefaultIconLayout, iCurrentVisual );
       
   782         }
       
   783 
       
   784     // call prepareview for the effect and load the image
       
   785     PrepareAndLoadImageToViewL();
       
   786     }
       
   787 
       
   788 // -----------------------------------------------------------------------------
       
   789 // NavigateListL.
       
   790 // -----------------------------------------------------------------------------
       
   791 void CShwEffectControl::NavigateListL( TInt aDirection )
       
   792     {
       
   793     TRACER("CShwEffectControl::NavigateListL");
       
   794 	// reset the failed index value as the failure might be temporary
       
   795 	iFailedThumbnailIndex = KErrNotFound;
       
   796     // navigate the visual list
       
   797     iVisualList.NavigateL( aDirection );
       
   798     // store current effect as previous
       
   799     iPreviousEffect = iEffectManager.CurrentEffect();
       
   800     // navigate to the next effect
       
   801     iEffectManager.ProceedToEffect( aDirection );
       
   802     }
       
   803 
       
   804 // -----------------------------------------------------------------------------
       
   805 // NextListIndex.
       
   806 // -----------------------------------------------------------------------------
       
   807 TInt CShwEffectControl::NextListIndex( TInt aDirection )
       
   808     {
       
   809     TRACER("CShwEffectControl::NextListIndex");
       
   810     // next index in list is focus plus direction and then wrap around
       
   811     TInt newIndex = 
       
   812         ( iVisualList.FocusIndex() + aDirection ) % iVisualList.ItemCount();
       
   813     if( newIndex < 0 )
       
   814         {
       
   815         // navigating left
       
   816         // sign for modulo is the same as left side so need to add itemcount
       
   817         newIndex += iVisualList.ItemCount();
       
   818         }
       
   819     return newIndex;
       
   820     }