30
|
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: App for Action handler
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <apgcli.h>
|
|
20 |
#include <apacmdln.h>
|
|
21 |
#include <apgtask.h>
|
|
22 |
#include <vwsdef.h>
|
|
23 |
#include <eikenv.h>
|
|
24 |
#include <eikappui.h>
|
|
25 |
#include <liwvariant.h>
|
|
26 |
|
|
27 |
#include "ahproperties.hrh"
|
|
28 |
#include "ahpapplauncher.h"
|
|
29 |
|
|
30 |
// ======== MEMBER FUNCTIONS ========
|
|
31 |
|
|
32 |
// ----------------------------------------------------------------------------
|
|
33 |
// Symbian 2nd phase constructor can leave.
|
|
34 |
// ----------------------------------------------------------------------------
|
|
35 |
//
|
|
36 |
void CAHAppLauncher::ConstructL()
|
|
37 |
{
|
|
38 |
iEnv = CEikonEnv::Static( );
|
|
39 |
}
|
|
40 |
|
|
41 |
// ----------------------------------------------------------------------------
|
|
42 |
// Two-phased constructor.
|
|
43 |
// ----------------------------------------------------------------------------
|
|
44 |
//
|
|
45 |
CAHAppLauncher* CAHAppLauncher::NewL()
|
|
46 |
{
|
|
47 |
CAHAppLauncher* self = CAHAppLauncher::NewLC( );
|
|
48 |
CleanupStack::Pop( self );
|
|
49 |
return self;
|
|
50 |
}
|
|
51 |
|
|
52 |
// ----------------------------------------------------------------------------
|
|
53 |
// Two-phased constructor.
|
|
54 |
// ----------------------------------------------------------------------------
|
|
55 |
//
|
|
56 |
CAHAppLauncher* CAHAppLauncher::NewLC()
|
|
57 |
{
|
|
58 |
CAHAppLauncher* self = new( ELeave ) CAHAppLauncher;
|
|
59 |
CleanupStack::PushL( self );
|
|
60 |
self->ConstructL( );
|
|
61 |
return self;
|
|
62 |
}
|
|
63 |
|
|
64 |
// ---------------------------------------------------------------------------
|
|
65 |
// destructor
|
|
66 |
// ---------------------------------------------------------------------------
|
|
67 |
CAHAppLauncher::~CAHAppLauncher()
|
|
68 |
{
|
|
69 |
}
|
|
70 |
|
|
71 |
// ---------------------------------------------------------------------------
|
|
72 |
// Executes provided action
|
|
73 |
// ---------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
TInt CAHAppLauncher::ExecuteTypeLaunchL( const CLiwMap* aMap )
|
|
76 |
{
|
|
77 |
TInt errCode(KErrArgument);
|
|
78 |
RBuf launchMethod;
|
|
79 |
CleanupClosePushL( launchMethod );
|
|
80 |
|
|
81 |
if ( !ExtractDesL( aMap, launchMethod, KLaunchMethod ) )
|
|
82 |
{
|
|
83 |
if ( !launchMethod.CompareF( KLaunchMethodValueCmdLine ) )
|
|
84 |
{
|
|
85 |
errCode = ExecuteCommmandLineL( aMap );
|
|
86 |
}
|
|
87 |
else if ( !launchMethod.CompareF( KLaunchMethodValueMessageWithDoc )
|
|
88 |
|| !launchMethod.CompareF( KLaunchMethodValueMessageWithTail ) )
|
|
89 |
{
|
|
90 |
errCode = ExecuteApaMessageL( aMap );
|
|
91 |
}
|
|
92 |
}
|
|
93 |
|
|
94 |
CleanupStack::PopAndDestroy( &launchMethod );
|
|
95 |
return errCode;
|
|
96 |
}
|
|
97 |
|
|
98 |
// ---------------------------------------------------------------------------
|
|
99 |
// Executes provided command line action
|
|
100 |
// ---------------------------------------------------------------------------
|
|
101 |
//
|
|
102 |
TInt CAHAppLauncher::ExecuteCommmandLineL( const CLiwMap* aMap )
|
|
103 |
{
|
|
104 |
TInt errCode(KErrArgument);
|
|
105 |
TUid appUid= TUid::Null( );
|
|
106 |
|
|
107 |
if ( !ExtractUidL( aMap, appUid, KApplicationUid ) )
|
|
108 |
{
|
|
109 |
// app not yet running
|
|
110 |
RApaLsSession appSession;
|
|
111 |
CleanupClosePushL( appSession );
|
|
112 |
User::LeaveIfError( appSession.Connect( ) );
|
|
113 |
|
|
114 |
CApaCommandLine* cmd = CApaCommandLine::NewLC( );
|
|
115 |
cmd->SetCommandL( GetCommandL( aMap ) );
|
|
116 |
RBuf documentNameValue;
|
|
117 |
CleanupClosePushL( documentNameValue );
|
|
118 |
if( !ExtractDesL( aMap, documentNameValue, KDocumentName ) )
|
|
119 |
{
|
|
120 |
cmd->SetDocumentNameL( documentNameValue );
|
|
121 |
}
|
|
122 |
TApaAppInfo appInfo;
|
|
123 |
appSession.GetAppInfo( appInfo, appUid );
|
|
124 |
cmd->SetExecutableNameL( appInfo.iFullName );
|
|
125 |
errCode = appSession.StartApp( *cmd );
|
|
126 |
|
|
127 |
CleanupStack::PopAndDestroy( &documentNameValue );
|
|
128 |
CleanupStack::PopAndDestroy( cmd );
|
|
129 |
CleanupStack::PopAndDestroy( &appSession );
|
|
130 |
}
|
|
131 |
|
|
132 |
return errCode;
|
|
133 |
}
|
|
134 |
|
|
135 |
// ---------------------------------------------------------------------------
|
|
136 |
// Executes provided apa message action
|
|
137 |
// ---------------------------------------------------------------------------
|
|
138 |
//
|
|
139 |
TInt CAHAppLauncher::ExecuteApaMessageL( const CLiwMap* aMap )
|
|
140 |
{
|
|
141 |
TInt errCode(KErrArgument);
|
|
142 |
TUid appUid= TUid::Null( );
|
|
143 |
if ( !ExtractUidL( aMap, appUid, KApplicationUid ) )
|
|
144 |
{
|
|
145 |
TApaTaskList taskList( iEnv->WsSession() );
|
|
146 |
TApaTask task = taskList.FindApp( appUid );
|
|
147 |
if ( task.Exists( ) )
|
|
148 |
{
|
|
149 |
TUid messageUid= TUid::Null( );
|
|
150 |
|
|
151 |
RBuf8 additionalData;
|
|
152 |
CleanupClosePushL( additionalData );
|
|
153 |
if ( !ExtractUidL( aMap, messageUid, KMessageUid )
|
|
154 |
&& !ExtractDes8L( aMap, additionalData, KAdditionalData ) )
|
|
155 |
{
|
|
156 |
errCode = task.SendMessage( messageUid, additionalData );
|
|
157 |
}
|
|
158 |
CleanupStack::PopAndDestroy( &additionalData );
|
|
159 |
}
|
|
160 |
else
|
|
161 |
{ // app not yet running
|
|
162 |
RBuf launchMethod;
|
|
163 |
CleanupClosePushL( launchMethod );
|
|
164 |
if ( !ExtractDesL( aMap, launchMethod, KLaunchMethod ) )
|
|
165 |
{
|
|
166 |
if ( !launchMethod.CompareF( KLaunchMethodValueMessageWithDoc ) )
|
|
167 |
{
|
|
168 |
errCode = StartDocumentL( aMap ) ;
|
|
169 |
}
|
|
170 |
else if ( !launchMethod.CompareF( KLaunchMethodValueMessageWithTail ) )
|
|
171 |
{
|
|
172 |
errCode = StartAppL( aMap );
|
|
173 |
}
|
|
174 |
}
|
|
175 |
CleanupStack::PopAndDestroy( &launchMethod );
|
|
176 |
}
|
|
177 |
}
|
|
178 |
return errCode;
|
|
179 |
|
|
180 |
}
|
|
181 |
// ---------------------------------------------------------------------------
|
|
182 |
// Start document
|
|
183 |
// ---------------------------------------------------------------------------
|
|
184 |
//
|
|
185 |
TInt CAHAppLauncher::StartDocumentL( const CLiwMap* aMap )
|
|
186 |
{
|
|
187 |
TInt errCode(KErrArgument);
|
|
188 |
TUid appUid= TUid::Null( );
|
|
189 |
RBuf documentNameValue;
|
|
190 |
CleanupClosePushL( documentNameValue );
|
|
191 |
if ( !ExtractUidL( aMap, appUid, KApplicationUid )
|
|
192 |
&& !ExtractDesL( aMap, documentNameValue, KDocumentName ) )
|
|
193 |
{
|
|
194 |
RApaLsSession appArcSession;
|
|
195 |
CleanupClosePushL( appArcSession );
|
|
196 |
User::LeaveIfError( appArcSession.Connect( ) );
|
|
197 |
TThreadId id;
|
|
198 |
errCode = appArcSession.StartDocument( documentNameValue, appUid, id );
|
|
199 |
CleanupStack::PopAndDestroy( &appArcSession );
|
|
200 |
}
|
|
201 |
CleanupStack::PopAndDestroy( &documentNameValue );
|
|
202 |
return errCode;
|
|
203 |
}
|
|
204 |
// ---------------------------------------------------------------------------
|
|
205 |
// Starts application
|
|
206 |
// ---------------------------------------------------------------------------
|
|
207 |
//
|
|
208 |
TInt CAHAppLauncher::StartAppL( const CLiwMap* aMap )
|
|
209 |
{
|
|
210 |
TInt errCode(KErrArgument);
|
|
211 |
TUid appUid= TUid::Null( );
|
|
212 |
RBuf8 additionalData;
|
|
213 |
CleanupClosePushL( additionalData );
|
|
214 |
if ( !ExtractUidL( aMap, appUid, KApplicationUid )
|
|
215 |
&& !ExtractDes8L( aMap, additionalData, KAdditionalData ) )
|
|
216 |
{
|
|
217 |
RApaLsSession appArcSession;
|
|
218 |
CleanupClosePushL( appArcSession );
|
|
219 |
User::LeaveIfError( appArcSession.Connect( ) );
|
|
220 |
TApaAppInfo appInfo;
|
|
221 |
errCode = appArcSession.GetAppInfo( appInfo, appUid );
|
|
222 |
if ( errCode == KErrNone )
|
|
223 |
{
|
|
224 |
CApaCommandLine* cmdLine = CApaCommandLine::NewLC( );
|
|
225 |
cmdLine->SetExecutableNameL( appInfo.iFullName );
|
|
226 |
cmdLine->SetCommandL( EApaCommandRun );
|
|
227 |
cmdLine->SetTailEndL( additionalData );
|
|
228 |
|
|
229 |
errCode = appArcSession.StartApp( *cmdLine );
|
|
230 |
CleanupStack::PopAndDestroy( cmdLine );
|
|
231 |
}
|
|
232 |
CleanupStack::PopAndDestroy( &appArcSession );
|
|
233 |
}
|
|
234 |
CleanupStack::PopAndDestroy( &additionalData );
|
|
235 |
return errCode;
|
|
236 |
}
|
|
237 |
// ----------------------------------------------------------------------------
|
|
238 |
// Executes provided action - activate view
|
|
239 |
// ----------------------------------------------------------------------------
|
|
240 |
//
|
|
241 |
TInt CAHAppLauncher::ExecuteActivateViewL( const CLiwMap* aMap )
|
|
242 |
{
|
|
243 |
TInt errCode(KErrGeneral);
|
|
244 |
if ( iEnv )
|
|
245 |
{
|
|
246 |
CCoeAppUi* appui = iEnv-> EikAppUi( );
|
|
247 |
if ( appui )
|
|
248 |
{
|
|
249 |
TUid messageUid= TUid::Null( );
|
|
250 |
TVwsViewId viewId;
|
|
251 |
if ( !ExtractViewIdL( aMap, viewId ) )
|
|
252 |
{
|
|
253 |
RBuf8 additionalData;
|
|
254 |
CleanupClosePushL( additionalData );
|
|
255 |
if ( !ExtractUidL( aMap, messageUid, KMessageUid )
|
|
256 |
&& !ExtractDes8L( aMap, additionalData, KAdditionalData ) )
|
|
257 |
{
|
|
258 |
appui->ActivateViewL( viewId, messageUid, additionalData );
|
|
259 |
}
|
|
260 |
else
|
|
261 |
{
|
|
262 |
appui->ActivateViewL( viewId );
|
|
263 |
}
|
|
264 |
errCode = KErrNone;
|
|
265 |
CleanupStack::PopAndDestroy( &additionalData );
|
|
266 |
}
|
|
267 |
}
|
|
268 |
}
|
|
269 |
return errCode;
|
|
270 |
}
|
|
271 |
|
|
272 |
// ---------------------------------------------------------------------------
|
|
273 |
// Executes provided action
|
|
274 |
// ---------------------------------------------------------------------------
|
|
275 |
//
|
|
276 |
TInt CAHAppLauncher::ExecuteActionL( const CLiwMap* aMap )
|
|
277 |
{
|
|
278 |
TInt errCode(KErrNotFound);
|
|
279 |
RBuf type;
|
|
280 |
CleanupClosePushL( type );
|
|
281 |
errCode = ExtractDesL( aMap, type, KType );
|
|
282 |
|
|
283 |
if ( errCode == KErrNone )
|
|
284 |
{
|
|
285 |
if ( !type.CompareF( KActionValueLaunchApplication ) )
|
|
286 |
{
|
|
287 |
errCode = ExecuteTypeLaunchL( aMap );
|
|
288 |
}
|
|
289 |
else if ( !type.CompareF( KActionValueViewActivation ) )
|
|
290 |
{
|
|
291 |
errCode = ExecuteActivateViewL( aMap );
|
|
292 |
}
|
|
293 |
}
|
|
294 |
CleanupStack::PopAndDestroy( &type );
|
|
295 |
return errCode;
|
|
296 |
}
|
|
297 |
|
|
298 |
// ---------------------------------------------------------------------------
|
|
299 |
//
|
|
300 |
// ---------------------------------------------------------------------------
|
|
301 |
//
|
|
302 |
TInt CAHAppLauncher::ExtractDesL( const CLiwMap* aMap,
|
|
303 |
RBuf& aString, const TDesC8& aMapName )
|
|
304 |
{
|
|
305 |
TInt errCode(KErrNotFound);
|
|
306 |
TLiwVariant variant;
|
|
307 |
variant.PushL( );
|
|
308 |
TPtrC tempString( KNullDesC );
|
|
309 |
if ( aMap->FindL( aMapName, variant ) )
|
|
310 |
{
|
|
311 |
variant.Get( tempString );
|
|
312 |
aString.ReAllocL( tempString.Length( ) );
|
|
313 |
aString.Append( tempString );
|
|
314 |
errCode = KErrNone;
|
|
315 |
}
|
|
316 |
CleanupStack::PopAndDestroy( &variant );
|
|
317 |
return errCode;
|
|
318 |
}
|
|
319 |
|
|
320 |
// ---------------------------------------------------------------------------
|
|
321 |
//
|
|
322 |
// ---------------------------------------------------------------------------
|
|
323 |
//
|
|
324 |
TInt CAHAppLauncher::ExtractDes8L( const CLiwMap* aMap,
|
|
325 |
RBuf8& aString, const TDesC8& aMapName )
|
|
326 |
{
|
|
327 |
TInt errCode(KErrNotFound);
|
|
328 |
TLiwVariant variant;
|
|
329 |
variant.PushL( );
|
|
330 |
TPtrC8 tempString( KNullDesC8 );
|
|
331 |
if ( aMap->FindL( aMapName, variant ) )
|
|
332 |
{
|
|
333 |
variant.Get( tempString );
|
|
334 |
aString.ReAllocL( tempString.Length( ) );
|
|
335 |
aString.Append( tempString );
|
|
336 |
errCode = KErrNone;
|
|
337 |
}
|
|
338 |
CleanupStack::PopAndDestroy( &variant );
|
|
339 |
return errCode;
|
|
340 |
}
|
|
341 |
|
|
342 |
// ---------------------------------------------------------------------------
|
|
343 |
//
|
|
344 |
// ---------------------------------------------------------------------------
|
|
345 |
//
|
|
346 |
TInt CAHAppLauncher::ExtractUidL( const CLiwMap* aMap, TUid& aUid,
|
|
347 |
const TDesC8& aMapName )
|
|
348 |
|
|
349 |
{
|
|
350 |
TInt errCode(KErrNotFound);
|
|
351 |
TInt32 temp;
|
|
352 |
TLiwVariant variant;
|
|
353 |
variant.PushL( );
|
|
354 |
if ( aMap->FindL( aMapName, variant ) )
|
|
355 |
{
|
|
356 |
variant.Get( temp );
|
|
357 |
aUid = TUid::Uid( temp );
|
|
358 |
errCode = KErrNone;
|
|
359 |
}
|
|
360 |
CleanupStack::PopAndDestroy( &variant );
|
|
361 |
return errCode;
|
|
362 |
}
|
|
363 |
|
|
364 |
// ---------------------------------------------------------------------------
|
|
365 |
//
|
|
366 |
// ---------------------------------------------------------------------------
|
|
367 |
//
|
|
368 |
TInt CAHAppLauncher::ExtractViewIdL( const CLiwMap* aMap, TVwsViewId& aViewId )
|
|
369 |
|
|
370 |
{
|
|
371 |
TInt errCode(KErrNotFound);
|
|
372 |
TLiwVariant variant;
|
|
373 |
if ( aMap->FindL( KViewId, variant ) )
|
|
374 |
{
|
|
375 |
variant.Get( aViewId.iViewUid.iUid );
|
|
376 |
variant.Reset( );
|
|
377 |
if ( aMap->FindL( KViewAppUid, variant ) )
|
|
378 |
{
|
|
379 |
variant.Get( aViewId.iAppUid.iUid );
|
|
380 |
variant.Reset( );
|
|
381 |
errCode = KErrNone;
|
|
382 |
}
|
|
383 |
}
|
|
384 |
|
|
385 |
return errCode;
|
|
386 |
}
|
|
387 |
|
|
388 |
// ---------------------------------------------------------------------------
|
|
389 |
//
|
|
390 |
// ---------------------------------------------------------------------------
|
|
391 |
//
|
|
392 |
TApaCommand CAHAppLauncher::GetCommandL( const CLiwMap* aMap )
|
|
393 |
{
|
|
394 |
TApaCommand command(EApaCommandOpen);
|
|
395 |
RBuf appCommand;
|
|
396 |
CleanupClosePushL( appCommand );
|
|
397 |
if ( ExtractDesL( aMap, appCommand, KApaCommand ) == KErrNone )
|
|
398 |
{
|
|
399 |
if( appCommand.Compare( KApaCommandBackground ) == KErrNone )
|
|
400 |
{
|
|
401 |
command = EApaCommandBackground;
|
|
402 |
}
|
|
403 |
}
|
|
404 |
CleanupStack::PopAndDestroy( &appCommand );
|
|
405 |
return command;
|
|
406 |
}
|
|
407 |
|
|
408 |
// End of file
|