hsappkeyhandler/src/hsappkeyplugin.cpp
branchRCL_3
changeset 113 0efa10d348c0
equal deleted inserted replaced
111:053c6c7c14f3 113:0efa10d348c0
       
     1 /*
       
     2 * Copyright (c) 2007-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:  Main plugin class
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <w32std.h>
       
    20 #include <eikenv.h>
       
    21 #include <apgtask.h>
       
    22 #include <apgcli.h>
       
    23 #include <e32property.h>
       
    24 #include <hb/hbcore/hbdevicedialogsymbian.h>
       
    25 #include <hb/hbcore/hbsymbianvariant.h> 
       
    26 #include <tspropertydefs.h>
       
    27 #include <afactivitylauncher.h>
       
    28 #include <homescreendomainpskeys.h>
       
    29 #include "hsappkeyplugin.h"
       
    30 
       
    31 _LIT(KHsActivactionUri, "appto://20022F35?activityname=HsIdleView");
       
    32 _LIT(KAppLibActivactionUri, "appto://20022F35?activityname=AppLibMainView");
       
    33 _LIT(KTsPluginName, "com.nokia.taskswitcher.tsdevicedialogplugin/1.0");
       
    34 
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // 
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CHsAppKeyPlugin::CHsAppKeyPlugin()
       
    43 : iEikEnv( CEikonEnv::Static() )
       
    44 {
       
    45 }
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // Two-phased constructor.
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CHsAppKeyPlugin* CHsAppKeyPlugin::NewL()
       
    52 {
       
    53     CHsAppKeyPlugin* self = new (ELeave) CHsAppKeyPlugin;
       
    54     return self;
       
    55 }
       
    56     
       
    57 // ---------------------------------------------------------------------------
       
    58 // C++ Destructor
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CHsAppKeyPlugin::~CHsAppKeyPlugin()
       
    62 {
       
    63     delete mDialog;
       
    64 }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // From MHbDeviceDialogObserver
       
    68 // 
       
    69 // ---------------------------------------------------------------------------
       
    70 //
       
    71 void CHsAppKeyPlugin::DataReceived(CHbSymbianVariantMap& /*aData*/)
       
    72 {
       
    73     //no implementation required
       
    74 }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // From MHbDeviceDialogObserver
       
    78 // 
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 void CHsAppKeyPlugin::DeviceDialogClosed(TInt /*aCompletionCode*/)
       
    82 {
       
    83     delete mDialog;
       
    84     mDialog = 0;
       
    85 }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // From CSysapKeyHandlerPlugin
       
    89 // 
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 TKeyResponse CHsAppKeyPlugin::HandleKeyEventL(const TKeyEvent &aKeyEvent, 
       
    93                                               TEventCode /*aType*/)
       
    94 {
       
    95     TKeyResponse retVal(EKeyWasNotConsumed);
       
    96     if (aKeyEvent.iCode == EKeyApplication0) {
       
    97         if (iSecondEvent) {
       
    98             if (aKeyEvent.iRepeats > 0)
       
    99                 HandleLongPressL();
       
   100             else 
       
   101                 HandleShortPressL();
       
   102             retVal = EKeyWasConsumed;
       
   103         }
       
   104         iSecondEvent = !iSecondEvent; 
       
   105     }
       
   106     return retVal;
       
   107 }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // From CSysapKeyHandlerPlugin
       
   111 // 
       
   112 // ---------------------------------------------------------------------------
       
   113 //
       
   114 void CHsAppKeyPlugin::ProvideKeyEventsL(RArray<TKeyEvent>& aKeyEventArray) 
       
   115 {
       
   116     TKeyEvent key;
       
   117     key.iCode = EKeyApplication0;
       
   118     key.iScanCode = EStdKeyApplication0;
       
   119     key.iModifiers = 0;
       
   120     key.iRepeats = 0;
       
   121     aKeyEventArray.Append(key);
       
   122     
       
   123     TKeyEvent longkey;
       
   124     longkey.iCode = EKeyApplication0;
       
   125     longkey.iScanCode = EStdKeyApplication0;
       
   126     longkey.iModifiers = 0;
       
   127     longkey.iRepeats = 1;
       
   128     aKeyEventArray.Append(longkey);
       
   129 
       
   130 }
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // 
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 void CHsAppKeyPlugin::HandleShortPressL()
       
   137 {   
       
   138     TInt value(0);
       
   139     RProperty::Get(TsProperty::KCategory, TsProperty::KVisibilityKey, value);
       
   140     if (value) {
       
   141         // when Task Switcher dialog is visible, Appkey is used to dismiss it
       
   142     
       
   143         // @todo: remove notification through property when SharedDialog flag
       
   144         // is implemented in Orbit.
       
   145         if (!mDialog) {
       
   146             // dismiss dialog launched from HomeScreen
       
   147             User::LeaveIfError(RProperty::Set(TsProperty::KCategory, TsProperty::KDismissRequestKey, 1));
       
   148         } else {
       
   149             // dismiss dialog launched by this plugin
       
   150             delete mDialog;
       
   151             mDialog = 0;
       
   152         }
       
   153     } else {
       
   154         // when there is no Task Switcher dialog, Appkey is used to switch between Applib and HomeScreen
       
   155         RApaLsSession apaLsSession;
       
   156         CleanupClosePushL(apaLsSession);
       
   157         User::LeaveIfError(apaLsSession.Connect());
       
   158         CAfActivityLauncher *activityEnabler = 
       
   159             CAfActivityLauncher::NewLC(apaLsSession, 
       
   160                                        iEikEnv->WsSession());
       
   161         TInt state(0);
       
   162         RProperty::Get(KHsCategoryUid, KHsCategoryStateKey, state);
       
   163         if (state == EHomeScreenIdleState) {
       
   164             activityEnabler->launchActivityL(KAppLibActivactionUri);
       
   165         } else {
       
   166             activityEnabler->launchActivityL(KHsActivactionUri);
       
   167         }    
       
   168         CleanupStack::PopAndDestroy(activityEnabler);
       
   169         CleanupStack::PopAndDestroy(&apaLsSession);
       
   170     }
       
   171 }
       
   172 
       
   173 // ---------------------------------------------------------------------------
       
   174 // 
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 void CHsAppKeyPlugin::HandleLongPressL()
       
   178 {
       
   179     if( !mDialog ) {
       
   180         TInt value( 0 );
       
   181         RProperty::Get( TsProperty::KCategory, 
       
   182                     TsProperty::KVisibilityKey,
       
   183                     value );
       
   184         if(!value) {
       
   185             mDialog = CHbDeviceDialogSymbian::NewL();    
       
   186             CHbSymbianVariantMap* params = CHbSymbianVariantMap::NewL();
       
   187             if(KErrNone != mDialog->Show(KTsPluginName,*params,this)) {
       
   188                 delete mDialog;
       
   189                 mDialog = 0;
       
   190             }
       
   191             delete params;
       
   192         }
       
   193     }
       
   194 }
       
   195 //  End of File
       
   196 
       
   197