|
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 <hb/hbcore/hbdevicedialogsymbian.h> |
|
24 #include <hb/hbcore/hbsymbianvariant.h> |
|
25 #include "hsappkeyplugin.h" |
|
26 |
|
27 const TUid KHSAppUid = { 0x20022F35 }; |
|
28 _LIT(KTsPluginName, "com.nokia.taskswitcher.tsdevicedialogplugin/1.0"); |
|
29 |
|
30 |
|
31 // ======== MEMBER FUNCTIONS ======== |
|
32 |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 CHsAppKeyPlugin::CHsAppKeyPlugin() |
|
38 : iEikEnv( CEikonEnv::Static() ) |
|
39 { |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // Two-phased constructor. |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CHsAppKeyPlugin* CHsAppKeyPlugin::NewL() |
|
47 { |
|
48 CHsAppKeyPlugin* self = new (ELeave) CHsAppKeyPlugin; |
|
49 self->iEikEnv->RootWin().CaptureLongKey(EKeyApplication0, |
|
50 EKeyApplication0, |
|
51 0, |
|
52 0, |
|
53 0, |
|
54 ELongCaptureWaitShort); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // C++ Destructor |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CHsAppKeyPlugin::~CHsAppKeyPlugin() |
|
63 { |
|
64 delete mDialog; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // From MHbDeviceDialogObserver |
|
69 // |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 void CHsAppKeyPlugin::DataReceived(CHbSymbianVariantMap& /*aData*/) |
|
73 { |
|
74 //no implementation required |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // From MHbDeviceDialogObserver |
|
79 // |
|
80 // --------------------------------------------------------------------------- |
|
81 // |
|
82 void CHsAppKeyPlugin::DeviceDialogClosed(TInt /*aCompletionCode*/) |
|
83 { |
|
84 delete mDialog; |
|
85 mDialog = 0; |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // From CSysapKeyHandlerPlugin |
|
90 // |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 TKeyResponse CHsAppKeyPlugin::HandleKeyEventL( const TKeyEvent& aKeyEvent , |
|
94 TEventCode /*aType*/ |
|
95 ) |
|
96 { |
|
97 TKeyResponse retVal(EKeyWasNotConsumed); |
|
98 if (aKeyEvent.iCode == EKeyApplication0) { |
|
99 if (iSecondEvent) { |
|
100 if (aKeyEvent.iRepeats > 0) |
|
101 HandleLongPressL(); |
|
102 else |
|
103 HandleShortPressL(); |
|
104 retVal = EKeyWasConsumed; |
|
105 } |
|
106 iSecondEvent =!iSecondEvent; |
|
107 } |
|
108 return retVal; |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // From CSysapKeyHandlerPlugin |
|
113 // |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 void CHsAppKeyPlugin::ProvideKeyEventsL(RArray<TKeyEvent>& aKeyEventArray) |
|
117 { |
|
118 TKeyEvent key; |
|
119 key.iCode = EKeyApplication0; |
|
120 key.iScanCode = EStdKeyApplication0; |
|
121 key.iModifiers = 0; |
|
122 aKeyEventArray.Append(key); |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CHsAppKeyPlugin::HandleShortPressL() |
|
130 { |
|
131 RWsSession& ws = iEikEnv->WsSession(); |
|
132 TApaTaskList appList(ws); |
|
133 TApaTask task = appList.FindApp(KHSAppUid); |
|
134 |
|
135 if (task.Exists()) { |
|
136 task.BringToForeground(); |
|
137 } else { |
|
138 RApaLsSession apaLsSession; |
|
139 User::LeaveIfError(apaLsSession.Connect()); |
|
140 CleanupClosePushL(apaLsSession); |
|
141 |
|
142 TApaAppInfo appInfo; |
|
143 apaLsSession.GetAppInfo(appInfo, KHSAppUid ); |
|
144 |
|
145 CApaCommandLine *cmdLine = CApaCommandLine::NewLC(); |
|
146 cmdLine->SetExecutableNameL(appInfo.iFullName); |
|
147 User::LeaveIfError( apaLsSession.StartApp(*cmdLine)); |
|
148 |
|
149 CleanupStack::PopAndDestroy(cmdLine); |
|
150 CleanupStack::PopAndDestroy(&apaLsSession); |
|
151 } |
|
152 delete mDialog; |
|
153 mDialog =0; |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 void CHsAppKeyPlugin::HandleLongPressL() |
|
161 { |
|
162 if( !mDialog ) { |
|
163 mDialog = CHbDeviceDialogSymbian ::NewL(); |
|
164 |
|
165 CHbSymbianVariantMap* params = CHbSymbianVariantMap::NewL(); |
|
166 |
|
167 if(KErrNone != mDialog->Show(KTsPluginName,*params,this)) { |
|
168 delete mDialog; |
|
169 } |
|
170 delete params; |
|
171 } |
|
172 } |
|
173 // End of File |
|
174 |
|
175 |