|
1 /* |
|
2 * Copyright (c) 2008 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <w32std.h> |
|
19 #include <apgtask.h> |
|
20 #include <apgcli.h> |
|
21 #include <eikenv.h> |
|
22 #include <eikappui.h> |
|
23 #include <vwsdef.h> |
|
24 #include <AknDef.h> |
|
25 #include <AknTaskList.h> |
|
26 |
|
27 #include "caapphandlerplugin.h" |
|
28 #include "cainnerentry.h" |
|
29 #include "cauninstalloperation.h" |
|
30 |
|
31 #include "cautils.h" |
|
32 #include "cadef.h" |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CCaAppHandlerPlugin::~CCaAppHandlerPlugin() |
|
41 { |
|
42 delete iUninstallOperation; |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 CCaAppHandlerPlugin* CCaAppHandlerPlugin::NewL() |
|
50 { |
|
51 CCaAppHandlerPlugin* handler = new ( ELeave ) CCaAppHandlerPlugin(); |
|
52 CleanupStack::PushL( handler ); |
|
53 handler->ConstructL(); |
|
54 CleanupStack::Pop( handler ); |
|
55 return handler; |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------- |
|
59 // CCaAppHandlerPlugin::CCaAppHandlerPlugin |
|
60 // --------------------------------------------------------- |
|
61 // |
|
62 CCaAppHandlerPlugin::CCaAppHandlerPlugin() |
|
63 { |
|
64 iEikEnv = CEikonEnv::Static(); |
|
65 iUninstallOperation = NULL; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 // --------------------------------------------------------------------------- |
|
71 // |
|
72 void CCaAppHandlerPlugin::ConstructL() |
|
73 { |
|
74 BaseConstructL(); |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 TBool CCaAppHandlerPlugin::SupportsType( const TDesC& aType ) |
|
82 { |
|
83 if( !aType.Compare( KCaTypeApp() ) || !aType.Compare( KCaTypeWidget() ) ) |
|
84 { |
|
85 return ETrue; |
|
86 } |
|
87 return EFalse; |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void CCaAppHandlerPlugin::HandleCommandL( CCaInnerEntry& aEntry, |
|
95 const TDesC8& aCommand ) |
|
96 { |
|
97 if( aCommand == KCaCmdOpen() && aEntry.GetEntryTypeName() |
|
98 == KCaTypeApp() ) |
|
99 { |
|
100 TInt viewId( -1 ); |
|
101 TBuf<KCaMaxAttrValueLen> viewIdValue; |
|
102 if( aEntry.FindAttribute( KCaAttrView(), viewIdValue ) ) |
|
103 { |
|
104 if( MenuUtils::GetTUint( viewIdValue, (TUint& ) viewId ) |
|
105 != KErrNone ) |
|
106 { |
|
107 User::Leave( KErrCorrupt ); |
|
108 } |
|
109 } |
|
110 LaunchApplicationL( TUid::Uid( aEntry.GetUid() ), KNullDesC8(), |
|
111 viewId ); |
|
112 } |
|
113 else if( aCommand == KCaCmdClose() && aEntry.GetEntryTypeName() |
|
114 == KCaTypeApp() ) |
|
115 { |
|
116 CloseApplicationL( aEntry ); |
|
117 } |
|
118 else if( aCommand == KCaCmdRemove() |
|
119 && ( aEntry.GetEntryTypeName() == KCaTypeApp() |
|
120 || aEntry.GetEntryTypeName() == KCaTypeWidget() ) ) |
|
121 { |
|
122 if( iUninstallOperation && iUninstallOperation->IsActive() ) |
|
123 { |
|
124 User::Leave( KErrInUse ); |
|
125 } |
|
126 delete iUninstallOperation; |
|
127 iUninstallOperation = NULL; |
|
128 iUninstallOperation = CCaUninstallOperation::NewL( aEntry ); |
|
129 } |
|
130 else |
|
131 { |
|
132 User::Leave( KErrNotSupported ); |
|
133 } |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // |
|
138 // --------------------------------------------------------------------------- |
|
139 // |
|
140 void CCaAppHandlerPlugin::LaunchApplicationL( const TUid aUid, |
|
141 const TDesC8 &aParam, TInt aViewId ) |
|
142 { |
|
143 if( aViewId > 0 && iEikEnv ) |
|
144 { |
|
145 TUid viewId = TUid::Uid( aViewId ); |
|
146 TVwsViewId view( aUid, viewId ); |
|
147 iEikEnv->EikAppUi()->ActivateViewL( view ); |
|
148 } |
|
149 else |
|
150 { |
|
151 RWsSession wsSession; |
|
152 User::LeaveIfError( wsSession.Connect() ); |
|
153 CleanupClosePushL<RWsSession> ( wsSession ); |
|
154 |
|
155 CAknTaskList* taskList = CAknTaskList::NewL( wsSession ); |
|
156 TApaTask task = taskList->FindRootApp( aUid ); |
|
157 delete taskList; |
|
158 |
|
159 if( task.Exists() ) |
|
160 { |
|
161 task.BringToForeground(); |
|
162 } |
|
163 else |
|
164 { |
|
165 TApaAppInfo appInfo; |
|
166 TApaAppCapabilityBuf capabilityBuf; |
|
167 RApaLsSession appArcSession; |
|
168 User::LeaveIfError( appArcSession.Connect() ); |
|
169 CleanupClosePushL<RApaLsSession> ( appArcSession ); |
|
170 |
|
171 User::LeaveIfError( appArcSession.GetAppInfo( appInfo, aUid ) ); |
|
172 User::LeaveIfError( appArcSession.GetAppCapability( |
|
173 capabilityBuf, aUid ) ); |
|
174 |
|
175 TApaAppCapability& caps = capabilityBuf(); |
|
176 TFileName appName = appInfo.iFullName; |
|
177 CApaCommandLine* cmdLine = CApaCommandLine::NewLC(); |
|
178 cmdLine->SetExecutableNameL( appName ); |
|
179 |
|
180 if( caps.iLaunchInBackground ) |
|
181 { |
|
182 cmdLine->SetCommandL( EApaCommandBackground ); |
|
183 } |
|
184 else |
|
185 { |
|
186 cmdLine->SetCommandL( EApaCommandRun ); |
|
187 } |
|
188 |
|
189 cmdLine->SetTailEndL( aParam ); |
|
190 |
|
191 User::LeaveIfError( appArcSession.StartApp( *cmdLine ) ); |
|
192 |
|
193 CleanupStack::PopAndDestroy( cmdLine ); |
|
194 CleanupStack::PopAndDestroy( &appArcSession ); |
|
195 } |
|
196 CleanupStack::PopAndDestroy( &wsSession ); |
|
197 } |
|
198 } |
|
199 |
|
200 // --------------------------------------------------------------------------- |
|
201 // |
|
202 // --------------------------------------------------------------------------- |
|
203 // |
|
204 void CCaAppHandlerPlugin::CloseApplicationL( CCaInnerEntry& aEntry ) |
|
205 { |
|
206 RWsSession wsSession; |
|
207 User::LeaveIfError( wsSession.Connect() ); |
|
208 CleanupClosePushL<RWsSession> ( wsSession ); |
|
209 |
|
210 if( ( aEntry.GetFlags() & ERunning ) && |
|
211 ( !( aEntry.GetFlags() & ESystem ) ) ) |
|
212 { |
|
213 RBuf value; |
|
214 CleanupClosePushL( value ); |
|
215 value.CreateL( KCaMaxAttrValueLen ); |
|
216 if( aEntry.FindAttribute( KCaAttrWindowGroupId, value )) |
|
217 { |
|
218 TInt wgId( KErrNotFound ); |
|
219 TLex16 parser(value); |
|
220 if ( KErrNone == parser.Val( wgId ) && wgId > 0 ) |
|
221 { |
|
222 TWsEvent event; |
|
223 event.SetTimeNow(); |
|
224 event.SetType( KAknShutOrHideApp ); |
|
225 wsSession.SendEventToWindowGroup( wgId, event ); |
|
226 } |
|
227 } |
|
228 CleanupStack::PopAndDestroy( &value ); |
|
229 } |
|
230 |
|
231 CleanupStack::PopAndDestroy( &wsSession ); |
|
232 } |
|
233 |