diff -r 79311d856354 -r 7be2816dbabd idlehomescreen/widgetmanager/src/wmplugin.cpp --- a/idlehomescreen/widgetmanager/src/wmplugin.cpp Tue Apr 27 16:26:12 2010 +0300 +++ b/idlehomescreen/widgetmanager/src/wmplugin.cpp Tue May 11 16:02:39 2010 +0300 @@ -38,6 +38,9 @@ #include "wminstaller.h" #include "wmlistbox.h" +const TInt KExecuteCommandDelay( 50000 ); // 50ms +const TInt KMaxCmdExecutionCount( 6 ); + // --------------------------------------------------------- // CWmPlugin::NewL // --------------------------------------------------------- @@ -57,6 +60,12 @@ // CWmPlugin::~CWmPlugin() { + if ( iLauncher && iLauncher->IsActive() ) + { + iLauncher->Cancel(); + } + delete iLauncher; + if ( iWmInstaller && iWmInstaller->IsActive() ) { @@ -77,6 +86,7 @@ CWmPlugin::CWmPlugin() { iPreviousViewUid.iViewUid = KNullUid; + iExecutionCount = 0; } // --------------------------------------------------------- @@ -106,6 +116,9 @@ CleanupStack::PushL( mainView ); iViewAppUi->AddViewL( mainView ); CleanupStack::Pop( mainView ); + + // laucher for adding widgets. + iLauncher = CPeriodic::NewL( CActive::EPriorityIdle ); } // --------------------------------------------------------- @@ -246,12 +259,23 @@ iEffectManager->UiRendered(); } - TRAPD( err, ExecuteCommandL(); ); - if ( KErrNone != err ) + if ( !iEffectManager->IsEffectActive() ) + { + // launch effect without delay + iExecutionCount = KMaxCmdExecutionCount; + iLauncher->Start( 0, 0, TCallBack( ExecuteCommand, this ) ); + } + else { - delete iPostponedContent; - iPostponedContent = NULL; - iPostponedCommand = ENone; + // maximum wait time is 300ms (6 x 50ms) + if ( !iLauncher->IsActive() ) + { + iExecutionCount++; + iLauncher->Start( + KExecuteCommandDelay, + KExecuteCommandDelay, + TCallBack( ExecuteCommand, this ) ); + } } } @@ -285,20 +309,53 @@ } // --------------------------------------------------------- -// CWmPlugin::ExecuteCommandL +// CWmPlugin::ExecuteCommand +// --------------------------------------------------------- +// +TInt CWmPlugin::ExecuteCommand( TAny* aSelf ) + { + CWmPlugin* plugin = static_cast( aSelf ); + plugin->DoExecuteCommand(); + return 0; + } + +// --------------------------------------------------------- +// CWmPlugin::DoExecuteCommand // --------------------------------------------------------- // -void CWmPlugin::ExecuteCommandL() +void CWmPlugin::DoExecuteCommand() { - if ( iPostponedCommand == EAddToHomescreen ) + // prevent multiple events + if ( iLauncher->IsActive() ) + { + iLauncher->Cancel(); + } + + if ( !iEffectManager->IsEffectActive() || + iExecutionCount == KMaxCmdExecutionCount ) { - TInt err = ContentController().AddWidgetL( *iPostponedContent ); - if ( err != KErrNone ) - ShowErrorNoteL( err ); + if ( iPostponedCommand == EAddToHomescreen ) + { + TRAP_IGNORE( + TInt err( KErrNone ); + err = ContentController().AddWidgetL( *iPostponedContent ); + if ( KErrNone != err ) + ShowErrorNoteL( err ); + ); + } + iPostponedCommand = ENone; + delete iPostponedContent; + iPostponedContent = NULL; + iExecutionCount = 0; // reset counter } - iPostponedCommand = ENone; - delete iPostponedContent; - iPostponedContent = NULL; + else + { + iExecutionCount++; + iLauncher->Start( + KExecuteCommandDelay, + KExecuteCommandDelay, + TCallBack( ExecuteCommand, this ) ); + } } // ---------------------------------------------------------