114
|
1 |
/*
|
|
2 |
* Copyright (c) 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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
#include "menuapphandler.h"
|
|
18 |
#include "mcsmenuitem.h"
|
|
19 |
#include "menucompletedoperation.h"
|
|
20 |
#include "menuuninstalloperation.h"
|
|
21 |
#include "menutasklist.h"
|
|
22 |
|
|
23 |
#include <mcsmenuutils.h>
|
|
24 |
#include <w32std.h>
|
|
25 |
#include <apgtask.h>
|
|
26 |
#include <apgcli.h>
|
|
27 |
#include <eikenv.h>
|
|
28 |
#include <eikappui.h>
|
|
29 |
#include <vwsdef.h>
|
|
30 |
|
|
31 |
// ================= MEMBER FUNCTIONS =======================
|
|
32 |
|
|
33 |
// ---------------------------------------------------------
|
|
34 |
// CMenuAppHandler::~CMenuAppHandler
|
|
35 |
// ---------------------------------------------------------
|
|
36 |
//
|
|
37 |
CMenuAppHandler::~CMenuAppHandler()
|
|
38 |
{
|
|
39 |
}
|
|
40 |
|
|
41 |
// ---------------------------------------------------------
|
|
42 |
// CMenuAppHandler::NewL
|
|
43 |
// ---------------------------------------------------------
|
|
44 |
//
|
|
45 |
CMenuAppHandler* CMenuAppHandler::NewL( RMenu &aMenu )
|
|
46 |
{
|
|
47 |
CMenuAppHandler* handler = new (ELeave) CMenuAppHandler( aMenu );
|
|
48 |
CleanupStack::PushL( handler );
|
|
49 |
handler->ConstructL();
|
|
50 |
CleanupStack::Pop( handler );
|
|
51 |
return handler;
|
|
52 |
}
|
|
53 |
|
|
54 |
// ---------------------------------------------------------
|
|
55 |
// CMenuAppHandler::CMenuAppHandler
|
|
56 |
// ---------------------------------------------------------
|
|
57 |
//
|
|
58 |
CMenuAppHandler::CMenuAppHandler( RMenu &aMenu )
|
|
59 |
: CMenuHandlerPlugin( aMenu )
|
|
60 |
{
|
|
61 |
iEikEnv = CEikonEnv::Static();
|
|
62 |
}
|
|
63 |
|
|
64 |
// ---------------------------------------------------------
|
|
65 |
// CMenuAppHandler::ConstructL
|
|
66 |
// ---------------------------------------------------------
|
|
67 |
//
|
|
68 |
void CMenuAppHandler::ConstructL()
|
|
69 |
{
|
|
70 |
BaseConstructL();
|
|
71 |
}
|
|
72 |
|
|
73 |
// ---------------------------------------------------------
|
|
74 |
// CMenuAppHandler::SupportsType
|
|
75 |
// ---------------------------------------------------------
|
|
76 |
//
|
|
77 |
TBool CMenuAppHandler::SupportsType( const TDesC& aType )
|
|
78 |
{
|
|
79 |
if ( !aType.Compare( KMenuTypeApp() ) )
|
|
80 |
{
|
|
81 |
return ETrue;
|
|
82 |
}
|
|
83 |
return EFalse;
|
|
84 |
}
|
|
85 |
|
|
86 |
// ---------------------------------------------------------
|
|
87 |
// CMenuAppHandler::HandleCommandL
|
|
88 |
// ---------------------------------------------------------
|
|
89 |
//
|
|
90 |
CMenuOperation* CMenuAppHandler::HandleCommandL(
|
|
91 |
CMenuItem& aItem,
|
|
92 |
const TDesC8& aCommand,
|
|
93 |
const TDesC8& aParams,
|
|
94 |
TRequestStatus& aStatus )
|
|
95 |
{
|
|
96 |
if ( aCommand == KMenuCmdOpen() && aItem.Type() == KMenuTypeApp() )
|
|
97 |
{
|
|
98 |
TBool attrExists = ETrue;
|
|
99 |
TPtrC url = aItem.GetAttributeL( KMenuAttrUid(), attrExists );
|
|
100 |
|
|
101 |
if ( !attrExists )
|
|
102 |
{
|
|
103 |
User::Leave( KErrCorrupt );
|
|
104 |
}
|
|
105 |
|
|
106 |
TUint appUidNo;
|
|
107 |
TInt err = MenuUtils::GetTUint( url, appUidNo );
|
|
108 |
if ( err != KErrNone )
|
|
109 |
{
|
|
110 |
User::Leave( KErrCorrupt );
|
|
111 |
}
|
|
112 |
|
|
113 |
TInt viewId;
|
|
114 |
TPtrC view = aItem.GetAttributeL( KMenuAttrView(), attrExists );
|
|
115 |
|
|
116 |
if ( attrExists )
|
|
117 |
{
|
|
118 |
err = MenuUtils::GetTUint( view, (TUint &)viewId );
|
|
119 |
if( err != KErrNone )
|
|
120 |
{
|
|
121 |
User::Leave( KErrCorrupt );
|
|
122 |
}
|
|
123 |
}
|
|
124 |
else
|
|
125 |
{
|
|
126 |
viewId = -1;
|
|
127 |
}
|
|
128 |
|
|
129 |
LaunchApplicationL( TUid::Uid( appUidNo ), aParams, viewId );
|
|
130 |
|
|
131 |
return CMenuCompletedOperation::NewL
|
|
132 |
( iMenu, CActive::EPriorityStandard, aStatus, KErrNone );
|
|
133 |
}
|
|
134 |
else if ( aCommand == KMenuCmdRemove() && aItem.Type() == KMenuTypeApp() )
|
|
135 |
{
|
|
136 |
return CMenuUninstallOperation::NewL
|
|
137 |
( iMenu, CActive::EPriorityStandard, aStatus, aItem );
|
|
138 |
}
|
|
139 |
User::Leave ( KErrNotSupported );
|
|
140 |
return NULL;
|
|
141 |
}
|
|
142 |
|
|
143 |
// ---------------------------------------------------------
|
|
144 |
// CMenuAppHandler::LaunchApplicationL
|
|
145 |
// ---------------------------------------------------------
|
|
146 |
//
|
|
147 |
void CMenuAppHandler::LaunchApplicationL( const TUid aUid, const TDesC8 &aParam, TInt aViewId )
|
|
148 |
{
|
|
149 |
if ( aViewId > 0 && iEikEnv )
|
|
150 |
{
|
|
151 |
TUid viewId = TUid::Uid( aViewId );
|
|
152 |
TVwsViewId view( aUid, viewId );
|
|
153 |
iEikEnv->EikAppUi()->ActivateViewL( view );
|
|
154 |
}
|
|
155 |
else
|
|
156 |
{
|
|
157 |
RWsSession wsSession;
|
|
158 |
User::LeaveIfError( wsSession.Connect() );
|
|
159 |
CleanupClosePushL<RWsSession>( wsSession );
|
|
160 |
|
|
161 |
CMenuTaskList* taskList = CMenuTaskList::NewL( wsSession );
|
|
162 |
TApaTask task = taskList->FindRootApp( aUid );
|
|
163 |
delete taskList;
|
|
164 |
|
|
165 |
if ( task.Exists() )
|
|
166 |
{
|
|
167 |
task.BringToForeground();
|
|
168 |
}
|
|
169 |
else
|
|
170 |
{
|
|
171 |
TApaAppInfo appInfo;
|
|
172 |
TApaAppCapabilityBuf capabilityBuf;
|
|
173 |
RApaLsSession appArcSession;
|
|
174 |
User::LeaveIfError( appArcSession.Connect() );
|
|
175 |
CleanupClosePushL<RApaLsSession>( appArcSession );
|
|
176 |
|
|
177 |
User::LeaveIfError( appArcSession.GetAppInfo( appInfo, aUid ) );
|
|
178 |
User::LeaveIfError( appArcSession.GetAppCapability( capabilityBuf, aUid ) );
|
|
179 |
|
|
180 |
TApaAppCapability& caps = capabilityBuf();
|
|
181 |
TFileName appName = appInfo.iFullName;
|
|
182 |
CApaCommandLine* cmdLine = CApaCommandLine::NewLC();
|
|
183 |
cmdLine->SetExecutableNameL( appName );
|
|
184 |
|
|
185 |
if ( caps.iLaunchInBackground )
|
|
186 |
{
|
|
187 |
cmdLine->SetCommandL( EApaCommandBackground );
|
|
188 |
}
|
|
189 |
else
|
|
190 |
{
|
|
191 |
cmdLine->SetCommandL( EApaCommandRun );
|
|
192 |
}
|
|
193 |
|
|
194 |
cmdLine->SetTailEndL( aParam );
|
|
195 |
|
|
196 |
User::LeaveIfError( appArcSession.StartApp( *cmdLine ) );
|
|
197 |
|
|
198 |
CleanupStack::PopAndDestroy( cmdLine );
|
|
199 |
CleanupStack::PopAndDestroy( &appArcSession );
|
|
200 |
}
|
|
201 |
CleanupStack::PopAndDestroy( &wsSession );
|
|
202 |
}
|
|
203 |
}
|