hsappkeyhandler/src/hsappkeyplugin.cpp
author hgs
Mon, 18 Oct 2010 10:44:15 +0300
changeset 127 7b66bc3c6dc9
parent 116 305818acdca4
permissions -rw-r--r--
201041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
92
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  Main plugin class
116
hgs
parents: 112
diff changeset
    15
*
92
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
#include <w32std.h>
hgs
parents:
diff changeset
    19
#include <eikenv.h>
hgs
parents:
diff changeset
    20
#include <apgtask.h>
hgs
parents:
diff changeset
    21
#include <apgcli.h>
102
hgs
parents: 93
diff changeset
    22
#include <e32property.h>
92
hgs
parents:
diff changeset
    23
#include <hb/hbcore/hbdevicedialogsymbian.h>
116
hgs
parents: 112
diff changeset
    24
#include <hb/hbcore/hbsymbianvariant.h>
102
hgs
parents: 93
diff changeset
    25
#include <tspropertydefs.h>
107
hgs
parents: 102
diff changeset
    26
#include <afactivitylauncher.h>
hgs
parents: 102
diff changeset
    27
#include <homescreendomainpskeys.h>
92
hgs
parents:
diff changeset
    28
#include "hsappkeyplugin.h"
hgs
parents:
diff changeset
    29
116
hgs
parents: 112
diff changeset
    30
_LIT( KHsActivactionUri, "appto://20022F35?activityname=HsIdleView" );
hgs
parents: 112
diff changeset
    31
_LIT( KAppLibActivactionUri, "appto://20022F35?activityname=AppLibMainView" );
127
hgs
parents: 116
diff changeset
    32
_LIT( KHsHomeKeyPressedOnBackground, "appto://20022F35?activityname=HsHomeKeyPressedOnBackground" );
116
hgs
parents: 112
diff changeset
    33
_LIT( KTsPluginName, "com.nokia.taskswitcher.tsdevicedialogplugin/1.0" );
92
hgs
parents:
diff changeset
    34
hgs
parents:
diff changeset
    35
hgs
parents:
diff changeset
    36
// ======== MEMBER FUNCTIONS ========
hgs
parents:
diff changeset
    37
hgs
parents:
diff changeset
    38
// ---------------------------------------------------------------------------
116
hgs
parents: 112
diff changeset
    39
//
92
hgs
parents:
diff changeset
    40
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    41
//
hgs
parents:
diff changeset
    42
CHsAppKeyPlugin::CHsAppKeyPlugin()
116
hgs
parents: 112
diff changeset
    43
    : iEikEnv( CEikonEnv::Static() ) // codescanner::eikonenvstatic
hgs
parents: 112
diff changeset
    44
    {
hgs
parents: 112
diff changeset
    45
    }
92
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    48
// Two-phased constructor.
hgs
parents:
diff changeset
    49
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    50
//
hgs
parents:
diff changeset
    51
CHsAppKeyPlugin* CHsAppKeyPlugin::NewL()
116
hgs
parents: 112
diff changeset
    52
    {
hgs
parents: 112
diff changeset
    53
    CHsAppKeyPlugin* self = new ( ELeave ) CHsAppKeyPlugin;
92
hgs
parents:
diff changeset
    54
    return self;
116
hgs
parents: 112
diff changeset
    55
    }
hgs
parents: 112
diff changeset
    56
92
hgs
parents:
diff changeset
    57
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    58
// C++ Destructor
hgs
parents:
diff changeset
    59
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    60
//
hgs
parents:
diff changeset
    61
CHsAppKeyPlugin::~CHsAppKeyPlugin()
116
hgs
parents: 112
diff changeset
    62
    {
hgs
parents: 112
diff changeset
    63
    delete iDialog;
hgs
parents: 112
diff changeset
    64
    }
92
hgs
parents:
diff changeset
    65
hgs
parents:
diff changeset
    66
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    67
// From MHbDeviceDialogObserver
116
hgs
parents: 112
diff changeset
    68
//
92
hgs
parents:
diff changeset
    69
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    70
//
116
hgs
parents: 112
diff changeset
    71
void CHsAppKeyPlugin::DataReceived( CHbSymbianVariantMap& /*aData*/ )
hgs
parents: 112
diff changeset
    72
    {
92
hgs
parents:
diff changeset
    73
    //no implementation required
116
hgs
parents: 112
diff changeset
    74
    }
92
hgs
parents:
diff changeset
    75
hgs
parents:
diff changeset
    76
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    77
// From MHbDeviceDialogObserver
116
hgs
parents: 112
diff changeset
    78
//
92
hgs
parents:
diff changeset
    79
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    80
//
116
hgs
parents: 112
diff changeset
    81
void CHsAppKeyPlugin::DeviceDialogClosed( TInt /*aCompletionCode*/ )
hgs
parents: 112
diff changeset
    82
    {
hgs
parents: 112
diff changeset
    83
    delete iDialog;
hgs
parents: 112
diff changeset
    84
    iDialog = 0;
hgs
parents: 112
diff changeset
    85
    }
92
hgs
parents:
diff changeset
    86
hgs
parents:
diff changeset
    87
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    88
// From CSysapKeyHandlerPlugin
116
hgs
parents: 112
diff changeset
    89
//
92
hgs
parents:
diff changeset
    90
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
    91
//
116
hgs
parents: 112
diff changeset
    92
TKeyResponse CHsAppKeyPlugin::HandleKeyEventL( const TKeyEvent& aKeyEvent,  
hgs
parents: 112
diff changeset
    93
                                               TEventCode /*aType*/ )
hgs
parents: 112
diff changeset
    94
    {
hgs
parents: 112
diff changeset
    95
    TKeyResponse retVal( EKeyWasNotConsumed );
hgs
parents: 112
diff changeset
    96
    if ( aKeyEvent.iCode == EKeyApplication0 )
hgs
parents: 112
diff changeset
    97
        {
hgs
parents: 112
diff changeset
    98
        if ( aKeyEvent.iRepeats > 0 )
hgs
parents: 112
diff changeset
    99
            {
hgs
parents: 112
diff changeset
   100
            HandleLongPressL();
hgs
parents: 112
diff changeset
   101
            }
hgs
parents: 112
diff changeset
   102
        else
hgs
parents: 112
diff changeset
   103
            {
hgs
parents: 112
diff changeset
   104
            HandleShortPressL();
hgs
parents: 112
diff changeset
   105
            }
hgs
parents: 112
diff changeset
   106
        retVal = EKeyWasConsumed;
92
hgs
parents:
diff changeset
   107
        }
116
hgs
parents: 112
diff changeset
   108
    return retVal;
92
hgs
parents:
diff changeset
   109
    }
hgs
parents:
diff changeset
   110
hgs
parents:
diff changeset
   111
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   112
// From CSysapKeyHandlerPlugin
116
hgs
parents: 112
diff changeset
   113
//
92
hgs
parents:
diff changeset
   114
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   115
//
116
hgs
parents: 112
diff changeset
   116
void CHsAppKeyPlugin::ProvideKeyEventsL( RArray<TKeyEvent>& aKeyEventArray ) // codescanner::LFunctionCantLeave
hgs
parents: 112
diff changeset
   117
    {
92
hgs
parents:
diff changeset
   118
    TKeyEvent key;
hgs
parents:
diff changeset
   119
    key.iCode = EKeyApplication0;
hgs
parents:
diff changeset
   120
    key.iScanCode = EStdKeyApplication0;
hgs
parents:
diff changeset
   121
    key.iModifiers = 0;
102
hgs
parents: 93
diff changeset
   122
    key.iRepeats = 0;
116
hgs
parents: 112
diff changeset
   123
    aKeyEventArray.Append( key );
hgs
parents: 112
diff changeset
   124
102
hgs
parents: 93
diff changeset
   125
    TKeyEvent longkey;
hgs
parents: 93
diff changeset
   126
    longkey.iCode = EKeyApplication0;
hgs
parents: 93
diff changeset
   127
    longkey.iScanCode = EStdKeyApplication0;
hgs
parents: 93
diff changeset
   128
    longkey.iModifiers = 0;
hgs
parents: 93
diff changeset
   129
    longkey.iRepeats = 1;
116
hgs
parents: 112
diff changeset
   130
    aKeyEventArray.Append( longkey );
hgs
parents: 112
diff changeset
   131
    }
92
hgs
parents:
diff changeset
   132
hgs
parents:
diff changeset
   133
// ---------------------------------------------------------------------------
116
hgs
parents: 112
diff changeset
   134
//
92
hgs
parents:
diff changeset
   135
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   136
//
hgs
parents:
diff changeset
   137
void CHsAppKeyPlugin::HandleShortPressL()
116
hgs
parents: 112
diff changeset
   138
    {
hgs
parents: 112
diff changeset
   139
    TInt value( 0 );
hgs
parents: 112
diff changeset
   140
    RProperty::Get( TsProperty::KCategory, TsProperty::KVisibilityKey, value );
hgs
parents: 112
diff changeset
   141
    if ( value )
hgs
parents: 112
diff changeset
   142
        {
112
hgs
parents: 107
diff changeset
   143
        // when Task Switcher dialog is visible, Appkey is used to dismiss it
116
hgs
parents: 112
diff changeset
   144
        DismissTaskSwitcher();
112
hgs
parents: 107
diff changeset
   145
        }
116
hgs
parents: 112
diff changeset
   146
    else
hgs
parents: 112
diff changeset
   147
        {
112
hgs
parents: 107
diff changeset
   148
        // when there is no Task Switcher dialog, Appkey is used to switch between Applib and HomeScreen
hgs
parents: 107
diff changeset
   149
        RApaLsSession apaLsSession;
116
hgs
parents: 112
diff changeset
   150
        CleanupClosePushL( apaLsSession );
hgs
parents: 112
diff changeset
   151
        User::LeaveIfError( apaLsSession.Connect() );
hgs
parents: 112
diff changeset
   152
        CAfActivityLauncher* activityEnabler =
hgs
parents: 112
diff changeset
   153
            CAfActivityLauncher::NewLC( apaLsSession,
hgs
parents: 112
diff changeset
   154
                                        iEikEnv->WsSession() );
hgs
parents: 112
diff changeset
   155
        TInt state( 0 );
hgs
parents: 112
diff changeset
   156
        RProperty::Get( KHsCategoryUid, KHsCategoryStateKey, state );
hgs
parents: 112
diff changeset
   157
        if ( state == EHomeScreenWidgetViewForeground )
hgs
parents: 112
diff changeset
   158
            {
hgs
parents: 112
diff changeset
   159
            activityEnabler->launchActivityL( KAppLibActivactionUri );
hgs
parents: 112
diff changeset
   160
            }
127
hgs
parents: 116
diff changeset
   161
        else if ( (state & EHomeScreenApplicationBackground) == EHomeScreenApplicationBackground)
hgs
parents: 116
diff changeset
   162
            {
hgs
parents: 116
diff changeset
   163
            activityEnabler->launchActivityL( KHsHomeKeyPressedOnBackground );
hgs
parents: 116
diff changeset
   164
            }
hgs
parents: 116
diff changeset
   165
        else 
116
hgs
parents: 112
diff changeset
   166
            {
hgs
parents: 112
diff changeset
   167
            activityEnabler->launchActivityL( KHsActivactionUri );
127
hgs
parents: 116
diff changeset
   168
            }    
116
hgs
parents: 112
diff changeset
   169
        CleanupStack::PopAndDestroy( activityEnabler );
hgs
parents: 112
diff changeset
   170
        CleanupStack::PopAndDestroy( &apaLsSession );
hgs
parents: 112
diff changeset
   171
        }
112
hgs
parents: 107
diff changeset
   172
    }
92
hgs
parents:
diff changeset
   173
hgs
parents:
diff changeset
   174
// ---------------------------------------------------------------------------
116
hgs
parents: 112
diff changeset
   175
//
92
hgs
parents:
diff changeset
   176
// ---------------------------------------------------------------------------
hgs
parents:
diff changeset
   177
//
hgs
parents:
diff changeset
   178
void CHsAppKeyPlugin::HandleLongPressL()
116
hgs
parents: 112
diff changeset
   179
    {
hgs
parents: 112
diff changeset
   180
    TInt tsVisible( 0 );
hgs
parents: 112
diff changeset
   181
    RProperty::Get( TsProperty::KCategory,
102
hgs
parents: 93
diff changeset
   182
                    TsProperty::KVisibilityKey,
116
hgs
parents: 112
diff changeset
   183
                    tsVisible );
hgs
parents: 112
diff changeset
   184
    if ( tsVisible ) 
hgs
parents: 112
diff changeset
   185
        {
hgs
parents: 112
diff changeset
   186
        DismissTaskSwitcher();
hgs
parents: 112
diff changeset
   187
        } 
hgs
parents: 112
diff changeset
   188
    else 
hgs
parents: 112
diff changeset
   189
        {
hgs
parents: 112
diff changeset
   190
        if ( !iDialog )
hgs
parents: 112
diff changeset
   191
            {
hgs
parents: 112
diff changeset
   192
            iDialog = CHbDeviceDialogSymbian::NewL();
102
hgs
parents: 93
diff changeset
   193
            CHbSymbianVariantMap* params = CHbSymbianVariantMap::NewL();
116
hgs
parents: 112
diff changeset
   194
            if ( KErrNone != iDialog->Show( KTsPluginName, *params, this ) )
hgs
parents: 112
diff changeset
   195
                {
hgs
parents: 112
diff changeset
   196
                delete iDialog;
hgs
parents: 112
diff changeset
   197
                iDialog = 0;
hgs
parents: 112
diff changeset
   198
                }
hgs
parents: 112
diff changeset
   199
            delete params;
102
hgs
parents: 93
diff changeset
   200
            }
92
hgs
parents:
diff changeset
   201
        }
hgs
parents:
diff changeset
   202
    }
hgs
parents:
diff changeset
   203
116
hgs
parents: 112
diff changeset
   204
// ---------------------------------------------------------------------------
hgs
parents: 112
diff changeset
   205
//
hgs
parents: 112
diff changeset
   206
// ---------------------------------------------------------------------------
hgs
parents: 112
diff changeset
   207
//
hgs
parents: 112
diff changeset
   208
void CHsAppKeyPlugin::DismissTaskSwitcher()
hgs
parents: 112
diff changeset
   209
    {
hgs
parents: 112
diff changeset
   210
    // @todo: remove notification through property when SharedDialog flag
hgs
parents: 112
diff changeset
   211
    // is implemented in Orbit.
hgs
parents: 112
diff changeset
   212
    if ( !iDialog )
hgs
parents: 112
diff changeset
   213
        {
hgs
parents: 112
diff changeset
   214
        // dismiss dialog launched from HomeScreen
hgs
parents: 112
diff changeset
   215
        User::LeaveIfError( RProperty::Set( TsProperty::KCategory, TsProperty::KDismissRequestKey, 1 ) );
hgs
parents: 112
diff changeset
   216
        }
hgs
parents: 112
diff changeset
   217
    else
hgs
parents: 112
diff changeset
   218
        {
hgs
parents: 112
diff changeset
   219
        // dismiss dialog launched by this plugin
hgs
parents: 112
diff changeset
   220
        delete iDialog;
hgs
parents: 112
diff changeset
   221
        iDialog = 0;
hgs
parents: 112
diff changeset
   222
        }
hgs
parents: 112
diff changeset
   223
    }