hsappkeyhandler/src/hsappkeyplugin.cpp
changeset 109 e0aa398e6810
parent 73 4bc7b118b3df
child 115 3ab5c078b490
--- a/hsappkeyhandler/src/hsappkeyplugin.cpp	Tue Jul 06 14:37:10 2010 +0300
+++ b/hsappkeyhandler/src/hsappkeyplugin.cpp	Wed Aug 18 10:05:49 2010 +0300
@@ -20,11 +20,16 @@
 #include <eikenv.h>
 #include <apgtask.h>
 #include <apgcli.h>
+#include <e32property.h>
 #include <hb/hbcore/hbdevicedialogsymbian.h>
 #include <hb/hbcore/hbsymbianvariant.h> 
+#include <tspropertydefs.h>
+#include <afactivitylauncher.h>
+#include <homescreendomainpskeys.h>
 #include "hsappkeyplugin.h"
 
-const TUid KHSAppUid  = { 0x20022F35 };
+_LIT(KHsActivactionUri, "appto://20022F35?activityname=HsIdleView");
+_LIT(KAppLibActivactionUri, "appto://20022F35?activityname=AppLibMainView");
 _LIT(KTsPluginName, "com.nokia.taskswitcher.tsdevicedialogplugin/1.0");
 
 
@@ -46,12 +51,6 @@
 CHsAppKeyPlugin* CHsAppKeyPlugin::NewL()
 {
     CHsAppKeyPlugin* self = new (ELeave) CHsAppKeyPlugin;
-    self->iEikEnv->RootWin().CaptureLongKey(EKeyApplication0, 
-                                            EKeyApplication0, 
-                                            0, 
-                                            0, 
-                                            0, 
-                                            ELongCaptureWaitShort);
     return self;
 }
     
@@ -119,7 +118,16 @@
     key.iCode = EKeyApplication0;
     key.iScanCode = EStdKeyApplication0;
     key.iModifiers = 0;
+    key.iRepeats = 0;
     aKeyEventArray.Append(key);
+    
+    TKeyEvent longkey;
+    longkey.iCode = EKeyApplication0;
+    longkey.iScanCode = EStdKeyApplication0;
+    longkey.iModifiers = 0;
+    longkey.iRepeats = 1;
+    aKeyEventArray.Append(longkey);
+
 }
 
 // ---------------------------------------------------------------------------
@@ -127,28 +135,22 @@
 // ---------------------------------------------------------------------------
 //
 void CHsAppKeyPlugin::HandleShortPressL()
-{    
-    RWsSession& ws = iEikEnv->WsSession();
-    TApaTaskList appList(ws);
-    TApaTask task = appList.FindApp(KHSAppUid);
-
-    if (task.Exists()) {
-        task.BringToForeground();
-    } else {        
-        RApaLsSession apaLsSession;
-        User::LeaveIfError(apaLsSession.Connect());
-        CleanupClosePushL(apaLsSession);
-        
-        TApaAppInfo appInfo;
-        apaLsSession.GetAppInfo(appInfo, KHSAppUid );
-        
-        CApaCommandLine *cmdLine = CApaCommandLine::NewLC();
-        cmdLine->SetExecutableNameL(appInfo.iFullName);
-        User::LeaveIfError( apaLsSession.StartApp(*cmdLine));
-    
-        CleanupStack::PopAndDestroy(cmdLine);
-        CleanupStack::PopAndDestroy(&apaLsSession);
-    }
+{   
+    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);
     delete mDialog;
     mDialog =0;
 }
@@ -160,15 +162,20 @@
 void CHsAppKeyPlugin::HandleLongPressL()
 {
     if( !mDialog ) {
-         mDialog = CHbDeviceDialogSymbian ::NewL();
-        
-        CHbSymbianVariantMap* params = CHbSymbianVariantMap::NewL();
-        
+        TInt value( 0 );
+        RProperty::Get( TsProperty::KCategory, 
+                    TsProperty::KVisibilityKey,
+                    value );
+        if(!value){
+            mDialog = CHbDeviceDialogSymbian::NewL();
+    
+            CHbSymbianVariantMap* params = CHbSymbianVariantMap::NewL();
         if(KErrNone != mDialog->Show(KTsPluginName,*params,this)) {
             delete mDialog;
             mDialog = 0;
+            }
+        delete params;
         }
-        delete params;
     }
 }
 //  End of File