diff -r dbfb5e38438b -r 305818acdca4 hsappkeyhandler/src/hsappkeyplugin.cpp --- a/hsappkeyhandler/src/hsappkeyplugin.cpp Wed Aug 18 10:39:24 2010 +0300 +++ b/hsappkeyhandler/src/hsappkeyplugin.cpp Mon Sep 13 13:26:33 2010 +0300 @@ -12,186 +12,207 @@ * Contributors: * * Description: Main plugin class - * +* */ - #include #include #include #include #include #include -#include +#include #include #include #include #include "hsappkeyplugin.h" -_LIT(KHsActivactionUri, "appto://20022F35?activityname=HsIdleView"); -_LIT(KAppLibActivactionUri, "appto://20022F35?activityname=AppLibMainView"); -_LIT(KTsPluginName, "com.nokia.taskswitcher.tsdevicedialogplugin/1.0"); +_LIT( KHsActivactionUri, "appto://20022F35?activityname=HsIdleView" ); +_LIT( KAppLibActivactionUri, "appto://20022F35?activityname=AppLibMainView" ); +_LIT( KTsPluginName, "com.nokia.taskswitcher.tsdevicedialogplugin/1.0" ); // ======== MEMBER FUNCTIONS ======== // --------------------------------------------------------------------------- -// +// // --------------------------------------------------------------------------- // CHsAppKeyPlugin::CHsAppKeyPlugin() -: iEikEnv( CEikonEnv::Static() ) -{ -} + : iEikEnv( CEikonEnv::Static() ) // codescanner::eikonenvstatic + { + } // --------------------------------------------------------------------------- // Two-phased constructor. // --------------------------------------------------------------------------- // CHsAppKeyPlugin* CHsAppKeyPlugin::NewL() -{ - CHsAppKeyPlugin* self = new (ELeave) CHsAppKeyPlugin; + { + CHsAppKeyPlugin* self = new ( ELeave ) CHsAppKeyPlugin; return self; -} - + } + // --------------------------------------------------------------------------- // C++ Destructor // --------------------------------------------------------------------------- // CHsAppKeyPlugin::~CHsAppKeyPlugin() -{ - delete mDialog; -} + { + delete iDialog; + } // --------------------------------------------------------------------------- // From MHbDeviceDialogObserver -// +// // --------------------------------------------------------------------------- // -void CHsAppKeyPlugin::DataReceived(CHbSymbianVariantMap& /*aData*/) -{ +void CHsAppKeyPlugin::DataReceived( CHbSymbianVariantMap& /*aData*/ ) + { //no implementation required -} + } // --------------------------------------------------------------------------- // From MHbDeviceDialogObserver -// +// // --------------------------------------------------------------------------- // -void CHsAppKeyPlugin::DeviceDialogClosed(TInt /*aCompletionCode*/) -{ - delete mDialog; - mDialog = 0; -} +void CHsAppKeyPlugin::DeviceDialogClosed( TInt /*aCompletionCode*/ ) + { + delete iDialog; + iDialog = 0; + } // --------------------------------------------------------------------------- // From CSysapKeyHandlerPlugin -// +// // --------------------------------------------------------------------------- // -TKeyResponse CHsAppKeyPlugin::HandleKeyEventL(const TKeyEvent &aKeyEvent, - TEventCode /*aType*/) -{ - TKeyResponse retVal(EKeyWasNotConsumed); - if (aKeyEvent.iCode == EKeyApplication0) { - if (iSecondEvent) { - if (aKeyEvent.iRepeats > 0) - HandleLongPressL(); - else - HandleShortPressL(); - retVal = EKeyWasConsumed; +TKeyResponse CHsAppKeyPlugin::HandleKeyEventL( const TKeyEvent& aKeyEvent, + TEventCode /*aType*/ ) + { + TKeyResponse retVal( EKeyWasNotConsumed ); + if ( aKeyEvent.iCode == EKeyApplication0 ) + { + if ( aKeyEvent.iRepeats > 0 ) + { + HandleLongPressL(); + } + else + { + HandleShortPressL(); + } + retVal = EKeyWasConsumed; } - iSecondEvent = !iSecondEvent; + return retVal; } - return retVal; -} // --------------------------------------------------------------------------- // From CSysapKeyHandlerPlugin -// +// // --------------------------------------------------------------------------- // -void CHsAppKeyPlugin::ProvideKeyEventsL(RArray& aKeyEventArray) -{ +void CHsAppKeyPlugin::ProvideKeyEventsL( RArray& aKeyEventArray ) // codescanner::LFunctionCantLeave + { TKeyEvent key; key.iCode = EKeyApplication0; key.iScanCode = EStdKeyApplication0; key.iModifiers = 0; key.iRepeats = 0; - aKeyEventArray.Append(key); - + aKeyEventArray.Append( key ); + TKeyEvent longkey; longkey.iCode = EKeyApplication0; longkey.iScanCode = EStdKeyApplication0; longkey.iModifiers = 0; longkey.iRepeats = 1; - aKeyEventArray.Append(longkey); - -} + aKeyEventArray.Append( longkey ); + } // --------------------------------------------------------------------------- -// +// // --------------------------------------------------------------------------- // void CHsAppKeyPlugin::HandleShortPressL() -{ - TInt value(0); - RProperty::Get(TsProperty::KCategory, TsProperty::KVisibilityKey, value); - if (value) { + { + TInt value( 0 ); + RProperty::Get( TsProperty::KCategory, TsProperty::KVisibilityKey, value ); + if ( value ) + { // when Task Switcher dialog is visible, Appkey is used to dismiss it - - // @todo: remove notification through property when SharedDialog flag - // is implemented in Orbit. - if (!mDialog) { - // dismiss dialog launched from HomeScreen - User::LeaveIfError(RProperty::Set(TsProperty::KCategory, TsProperty::KDismissRequestKey, 1)); - } else { - // dismiss dialog launched by this plugin - delete mDialog; - mDialog = 0; + DismissTaskSwitcher(); } - } else { + else + { // when there is no Task Switcher dialog, Appkey is used to switch between Applib and HomeScreen RApaLsSession apaLsSession; - CleanupClosePushL(apaLsSession); - User::LeaveIfError(apaLsSession.Connect()); - CAfActivityLauncher *activityEnabler = - CAfActivityLauncher::NewLC(apaLsSession, - iEikEnv->WsSession()); - TInt state(0); - RProperty::Get(KHsCategoryUid, KHsCategoryStateKey, state); - if (state == EHomeScreenIdleState) { - activityEnabler->launchActivityL(KAppLibActivactionUri); - } else { - activityEnabler->launchActivityL(KHsActivactionUri); - } - CleanupStack::PopAndDestroy(activityEnabler); - CleanupStack::PopAndDestroy(&apaLsSession); + CleanupClosePushL( apaLsSession ); + User::LeaveIfError( apaLsSession.Connect() ); + CAfActivityLauncher* activityEnabler = + CAfActivityLauncher::NewLC( apaLsSession, + iEikEnv->WsSession() ); + TInt state( 0 ); + RProperty::Get( KHsCategoryUid, KHsCategoryStateKey, state ); + if ( state == EHomeScreenWidgetViewForeground ) + { + activityEnabler->launchActivityL( KAppLibActivactionUri ); + } + else + { + activityEnabler->launchActivityL( KHsActivactionUri ); + } + CleanupStack::PopAndDestroy( activityEnabler ); + CleanupStack::PopAndDestroy( &apaLsSession ); + } } -} // --------------------------------------------------------------------------- -// +// // --------------------------------------------------------------------------- // void CHsAppKeyPlugin::HandleLongPressL() -{ - if( !mDialog ) { - TInt value( 0 ); - RProperty::Get( TsProperty::KCategory, + { + TInt tsVisible( 0 ); + RProperty::Get( TsProperty::KCategory, TsProperty::KVisibilityKey, - value ); - if(!value) { - mDialog = CHbDeviceDialogSymbian::NewL(); + tsVisible ); + if ( tsVisible ) + { + DismissTaskSwitcher(); + } + else + { + if ( !iDialog ) + { + iDialog = CHbDeviceDialogSymbian::NewL(); CHbSymbianVariantMap* params = CHbSymbianVariantMap::NewL(); - if(KErrNone != mDialog->Show(KTsPluginName,*params,this)) { - delete mDialog; - mDialog = 0; + if ( KErrNone != iDialog->Show( KTsPluginName, *params, this ) ) + { + delete iDialog; + iDialog = 0; + } + delete params; } - delete params; } } -} -// End of File - +// --------------------------------------------------------------------------- +// +// --------------------------------------------------------------------------- +// +void CHsAppKeyPlugin::DismissTaskSwitcher() + { + // @todo: remove notification through property when SharedDialog flag + // is implemented in Orbit. + if ( !iDialog ) + { + // dismiss dialog launched from HomeScreen + User::LeaveIfError( RProperty::Set( TsProperty::KCategory, TsProperty::KDismissRequestKey, 1 ) ); + } + else + { + // dismiss dialog launched by this plugin + delete iDialog; + iDialog = 0; + } + }