28 #include <avkon.mbg> |
28 #include <avkon.mbg> |
29 #include <widgetmanager.mbg> |
29 #include <widgetmanager.mbg> |
30 #include <apgcli.h> |
30 #include <apgcli.h> |
31 #include <apgtask.h> |
31 #include <apgtask.h> |
32 #include <widgetregistryclient.h> // widgetreqistry |
32 #include <widgetregistryclient.h> // widgetreqistry |
33 |
33 #include <bacline.h> |
|
34 #include <EscapeUtils.h> |
34 |
35 |
35 #include "wmportalbutton.h" |
36 #include "wmportalbutton.h" |
36 #include "wmcommon.h" |
37 #include "wmcommon.h" |
37 #include "wmplugin.h" |
38 #include "wmplugin.h" |
38 #include "wmresourceloader.h" |
39 #include "wmresourceloader.h" |
39 #include "wmmaincontainer.h" |
40 #include "wmmaincontainer.h" |
40 #include "wmconfiguration.h" |
41 #include "wmconfiguration.h" |
|
42 #include "wmprocessmonitor.h" |
41 |
43 |
42 // CONSTANTS |
44 // CONSTANTS |
43 _LIT( KBrowserPrefix, "4 "); |
45 _LIT( KOviUrlPrefix, "oviurl "); |
44 |
46 _LIT( KBrowserUrlPrefix, "browserurl "); |
|
47 _LIT( KSpace, " "); |
|
48 _LIT( Kurlprefix, "4 "); |
|
49 |
|
50 const TUid KOSSBrowserUidValue = { 0x10008D39 }; |
|
51 const TInt KMaxParam = 512; |
45 // MEMBER FUNCTIONS |
52 // MEMBER FUNCTIONS |
46 |
53 |
47 // --------------------------------------------------------- |
54 // --------------------------------------------------------- |
48 // CWmPortalButton::NewL |
55 // CWmPortalButton::NewL |
49 // --------------------------------------------------------- |
56 // --------------------------------------------------------- |
152 |
161 |
153 // ready to be drawn |
162 // ready to be drawn |
154 ActivateL(); |
163 ActivateL(); |
155 } |
164 } |
156 |
165 |
157 // --------------------------------------------------------------------------- |
166 // --------------------------------------------------------- |
158 // Runs HTTP method: (starts browser or brongs browser to foreground) |
167 // CWmPortalButton::ExecuteL |
159 // --------------------------------------------------------------------------- |
168 // --------------------------------------------------------- |
160 // |
169 // |
161 void TryRunHttpL( const TDesC& aParam ) |
170 void CWmPortalButton::ExecuteL() |
|
171 { |
|
172 if ( iPortalButtonIndex == 0 ) |
|
173 { |
|
174 if ( !iProcessMonitor ) |
|
175 { |
|
176 iProcessMonitor = CWmProcessMonitor::NewL(); |
|
177 } |
|
178 if ( !iProcessMonitor->IsActive() ) |
|
179 { |
|
180 // We will have laucher for starting ovi store but until |
|
181 // it's added to SDK we need to start browser to ovi url |
|
182 if ( 0 ) |
|
183 RunOviL( iWmMainContainer->Configuration() ); |
|
184 else |
|
185 StartBrowserL( iWmMainContainer->Configuration() ); |
|
186 } |
|
187 } |
|
188 else if ( iPortalButtonIndex == 1 ) |
|
189 { |
|
190 RunOperatorL( iWmMainContainer->Configuration() ); |
|
191 } |
|
192 else |
|
193 { |
|
194 // Not supported |
|
195 User::Leave( KErrGeneral ); |
|
196 } |
|
197 } |
|
198 |
|
199 // --------------------------------------------------------- |
|
200 // CWmPortalButton::RunOviL |
|
201 // --------------------------------------------------------- |
|
202 // |
|
203 void CWmPortalButton::RunOviL( CWmConfiguration& aConf ) |
162 { |
204 { |
163 RApaLsSession session; |
205 RApaLsSession session; |
164 User::LeaveIfError( session.Connect() ); |
206 User::LeaveIfError( session.Connect() ); |
165 CleanupClosePushL( session ); |
207 CleanupClosePushL( session ); |
|
208 |
|
209 //get app info |
|
210 TApaAppInfo appInfo; |
|
211 TUid launchUid; //plan was to save uid in cenrep and fetch it from there |
|
212 launchUid = aConf.PortalButtonClientUid( iPortalButtonIndex ); |
|
213 User::LeaveIfError( session.GetAppInfo( appInfo, launchUid ) ); |
|
214 |
|
215 // Form parameter |
|
216 // it should look like this "oviurl url1 browserurl url2" |
|
217 HBufC* param = HBufC::NewLC( KMaxParam ); |
|
218 param->Des().Copy( KOviUrlPrefix ); |
|
219 HBufC* decodedParam = EscapeUtils::EscapeEncodeL( aConf.PortalButtonClientParam( iPortalButtonIndex ), EscapeUtils::EEscapeUrlEncoded ); |
|
220 CleanupStack::PushL( decodedParam ); |
|
221 param->Des().Append( *decodedParam ); |
|
222 param->Des().Append( KSpace ); |
|
223 param->Des().Append( KBrowserUrlPrefix ); |
|
224 decodedParam->Des().Copy( aConf.PortalButtonBrowserUrl( iPortalButtonIndex ) ); |
|
225 param->Des().Append( *decodedParam ); |
|
226 |
|
227 // do the launch |
|
228 RProcess process; |
|
229 User::LeaveIfError( process.Create( appInfo.iFullName, *param ) ); |
|
230 iProcessMonitor->Monitor( process ); |
|
231 process.Resume(); |
|
232 |
|
233 CleanupStack::PopAndDestroy( decodedParam ); |
|
234 CleanupStack::PopAndDestroy( param ); |
|
235 CleanupStack::PopAndDestroy( &session ); |
|
236 } |
|
237 |
|
238 // --------------------------------------------------------- |
|
239 // CWmPortalButton::StartBrowserL |
|
240 // --------------------------------------------------------- |
|
241 // |
|
242 void CWmPortalButton::StartBrowserL( CWmConfiguration& aConf ) |
|
243 { |
|
244 RApaLsSession session; |
|
245 User::LeaveIfError( session.Connect() ); |
|
246 CleanupClosePushL( session ); |
166 |
247 |
167 // browser start parameters |
248 // browser start parameters |
168 const TUid KOSSBrowserUidValue = { 0x10008D39 }; |
249 HBufC* param = HBufC::NewLC( |
169 HBufC* param = HBufC::NewLC( aParam.Length() + |
250 aConf.PortalButtonBrowserUrl( iPortalButtonIndex ).Length() + |
170 KBrowserPrefix().Length() ); |
251 Kurlprefix().Length() ); |
171 |
252 |
172 param->Des().Copy( KBrowserPrefix ); |
253 param->Des().Copy( Kurlprefix ); |
173 param->Des().Append( aParam ); |
254 param->Des().Append( aConf.PortalButtonBrowserUrl( iPortalButtonIndex ) ); |
174 |
255 |
175 TUid id( KOSSBrowserUidValue ); |
256 TUid id( KOSSBrowserUidValue ); |
176 |
257 |
177 TApaTaskList taskList( CEikonEnv::Static()->WsSession() ); |
258 TApaTaskList taskList( CEikonEnv::Static()->WsSession() ); |
178 TApaTask task = taskList.FindApp( id ); |
259 TApaTask task = taskList.FindApp( id ); |
189 if( !session.Handle() ) |
270 if( !session.Handle() ) |
190 { |
271 { |
191 User::LeaveIfError( session.Connect() ); |
272 User::LeaveIfError( session.Connect() ); |
192 } |
273 } |
193 TThreadId thread; |
274 TThreadId thread; |
194 User::LeaveIfError(session.StartDocument(*param, KOSSBrowserUidValue, thread)); |
275 User::LeaveIfError( |
|
276 session.StartDocument(*param, KOSSBrowserUidValue, thread)); |
195 } |
277 } |
196 |
278 |
197 CleanupStack::PopAndDestroy( param ); |
279 CleanupStack::PopAndDestroy( param ); |
198 CleanupStack::PopAndDestroy( &session ); |
280 CleanupStack::PopAndDestroy( &session ); |
199 } |
281 } |
200 |
282 |
201 // --------------------------------------------------------------------------- |
283 // --------------------------------------------------------- |
202 // Runs WIDGET method: (launches given widget with parameters) |
284 // CWmPortalButton::RunOperatorL |
203 // --------------------------------------------------------------------------- |
285 // --------------------------------------------------------- |
204 // |
286 // |
205 void TryRunWidgetL( const TDesC& aBundleId, const TDesC& aParam ) |
287 void CWmPortalButton::RunOperatorL( CWmConfiguration& /*aConf*/ ) |
206 { |
288 { |
207 RApaLsSession session; |
289 //TODO: current info is that this will be a widget |
208 User::LeaveIfError( session.Connect() ); |
|
209 CleanupClosePushL( session ); |
|
210 TApaAppInfo appInfo; |
|
211 TUid launchUid; |
|
212 |
|
213 // Get widget uid |
|
214 RWidgetRegistryClientSession widgetSession; |
|
215 User::LeaveIfError( widgetSession.Connect() ); |
|
216 CleanupClosePushL( widgetSession ); |
|
217 launchUid.iUid = widgetSession.GetWidgetUidL( aBundleId ); |
|
218 CleanupStack::PopAndDestroy( &widgetSession ); |
|
219 |
|
220 // prepare widget start params |
|
221 User::LeaveIfError( session.GetAppInfo( appInfo, launchUid ) ); |
|
222 CApaCommandLine* commandLine = CApaCommandLine::NewLC(); |
|
223 commandLine->SetExecutableNameL( appInfo.iFullName ); |
|
224 HBufC8* buf8 = HBufC8::NewLC( aParam.Length() ); |
|
225 buf8->Des().Copy( aParam ); |
|
226 |
|
227 // do the launch |
|
228 commandLine->SetTailEndL( *buf8 ); |
|
229 User::LeaveIfError( session.StartApp( *commandLine ) ); |
|
230 |
|
231 CleanupStack::PopAndDestroy( buf8 ); |
|
232 CleanupStack::PopAndDestroy( commandLine ); |
|
233 CleanupStack::PopAndDestroy( &session ); |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------------------------- |
|
237 // Runs APPLICATION method: (launches given application with parameters) |
|
238 // --------------------------------------------------------------------------- |
|
239 // |
|
240 void TryRunApplicationL( const TDesC& /*aApplication*/, const TDesC& /*aParam*/ ) |
|
241 { |
|
242 // This method has not been implemented |
|
243 User::Leave( KErrNotSupported ); |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // Tries to open a portal with given method and parameters. |
|
248 // this method may be called twice on a portal button, if a primary |
|
249 // method fails. |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 void TryOpenPortalL( |
|
253 CWmConfiguration::TMethod aMethod, const TDesC& aService, |
|
254 const TDesC& aParam ) |
|
255 { |
|
256 // open portal according to the method. |
|
257 if ( aMethod == CWmConfiguration::EHttp ) |
|
258 { TryRunHttpL( aParam ); } |
|
259 else if ( aMethod == CWmConfiguration::EWidget ) |
|
260 { TryRunWidgetL( aService, aParam ); } |
|
261 else if ( aMethod == CWmConfiguration::EApplication ) |
|
262 { TryRunApplicationL( aService, aParam ); } |
|
263 else |
|
264 { User::Leave( KErrNotSupported ); } |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // Opens a portal. Called when user presses a portal button. tries the |
|
269 // primary method, and if if fails, tries the secondary. If it fails, |
|
270 // gives up. |
|
271 // --------------------------------------------------------------------------- |
|
272 // |
|
273 void OpenPortalL( |
|
274 CWmConfiguration& aConfiguration, TInt aPortalIndex ) |
|
275 { |
|
276 TRAPD( err, |
|
277 TryOpenPortalL( |
|
278 aConfiguration.PortalButtonPrimaryMethod( aPortalIndex ), |
|
279 aConfiguration.PortalButtonPrimaryService( aPortalIndex ), |
|
280 aConfiguration.PortalButtonPrimaryParams( aPortalIndex ) ); ); |
|
281 if ( err != KErrNone ) |
|
282 { |
|
283 // if secondary method fails, leave will be propagated. |
|
284 TryOpenPortalL( |
|
285 aConfiguration.PortalButtonSecondaryMethod( aPortalIndex ), |
|
286 aConfiguration.PortalButtonSecondaryService( aPortalIndex ), |
|
287 aConfiguration.PortalButtonSecondaryParams( aPortalIndex ) ); |
|
288 } |
|
289 } |
|
290 |
|
291 // --------------------------------------------------------- |
|
292 // CWmPortalButton::ExecuteL |
|
293 // --------------------------------------------------------- |
|
294 // |
|
295 void CWmPortalButton::ExecuteL() |
|
296 { |
|
297 OpenPortalL( iWmMainContainer->Configuration(), iPortalButtonIndex ); |
|
298 } |
290 } |
299 |
291 |
300 // --------------------------------------------------------- |
292 // --------------------------------------------------------- |
301 // CWmPortalButton::HandleControlEventL |
293 // CWmPortalButton::HandleControlEventL |
302 // --------------------------------------------------------- |
294 // --------------------------------------------------------- |