|
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: Implementation of CLWPLayerAppUi |
|
15 * |
|
16 */ |
|
17 |
|
18 // Version : %version: 7 % |
|
19 |
|
20 |
|
21 #include <DocumentHandler.h> |
|
22 #include <s32mem.h> |
|
23 #include <AiwGenericParam.h> |
|
24 #include <apgwgnam.h> |
|
25 #include <lwplayer.rsg> |
|
26 #include <aknappui.h> |
|
27 #include <StringLoader.h> |
|
28 #include <aknnotewrappers.h> |
|
29 #include <videoplayeractivationmessage.h> |
|
30 |
|
31 #include "lwplayerappui.h" |
|
32 #include "lwpuids.hrh" |
|
33 #include "mpxvideo_debug.h" |
|
34 |
|
35 const TInt KEVENTBLOCKTIMEOUT = 1000000; |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CLWPlayerAppUi::ConstructL |
|
39 // Symbian 2nd phase constructor can leave. |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 void CLWPlayerAppUi::ConstructL() |
|
43 { |
|
44 MPX_DEBUG(_L("CLWPlayerAppUi::ConstructL()")); |
|
45 |
|
46 BaseConstructL( EAknEnableSkin ); |
|
47 |
|
48 iEmbeddedMPCreated = EFalse; |
|
49 |
|
50 iAllowEvents = ETrue; |
|
51 |
|
52 iCloseAO = CIdle::NewL( CActive::EPriorityStandard ); |
|
53 |
|
54 iBlockEventsTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
55 } |
|
56 |
|
57 // ----------------------------------------------------------------------------- |
|
58 // CLWPlayerAppUi::~CLWPlayerAppUi() |
|
59 // Destructor |
|
60 // Frees reserved resources |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CLWPlayerAppUi::~CLWPlayerAppUi() |
|
64 { |
|
65 MPX_DEBUG(_L("CLWPlayerAppUi::~CLWPlayerAppUi()")); |
|
66 |
|
67 delete iDocHandler; |
|
68 |
|
69 if ( iCloseAO ) |
|
70 { |
|
71 delete iCloseAO; |
|
72 iCloseAO = NULL; |
|
73 } |
|
74 |
|
75 if ( iBlockEventsTimer ) |
|
76 { |
|
77 iBlockEventsTimer->Cancel(); |
|
78 delete iBlockEventsTimer; |
|
79 iBlockEventsTimer = NULL; |
|
80 } |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // CLWPlayerAppUi::HandleCommandL |
|
85 // ----------------------------------------------------------------------------- |
|
86 // |
|
87 void CLWPlayerAppUi::HandleCommandL(TInt aCommand) |
|
88 { |
|
89 MPX_DEBUG(_L("CLWPlayerAppUi::HandleCommandL(%d)"), aCommand); |
|
90 |
|
91 switch ( aCommand ) |
|
92 { |
|
93 case EAknSoftkeyBack: |
|
94 case EEikCmdExit: |
|
95 Exit(); |
|
96 break; |
|
97 default: |
|
98 break; |
|
99 } |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // New Methods added for Progressive Download |
|
104 // ----------------------------------------------------------------------------- |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // CLWPlayerAppUi::ProcessCommandParametersL |
|
108 // |
|
109 // When Prog Download is started, RApaLsSession creates |
|
110 // this Document and calls ProcessCommandParametersL. |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 TBool CLWPlayerAppUi::ProcessCommandParametersL( CApaCommandLine& aCommandLine ) |
|
114 { |
|
115 MPX_DEBUG(_L("CLWPlayerAppUi::ProcessCommandParametersL()")); |
|
116 |
|
117 // |
|
118 // Since download manager can send multiple events with the same data |
|
119 // Block events from Download Manager for a short time |
|
120 // |
|
121 BlockEvents(); |
|
122 |
|
123 // |
|
124 // Convert aFilename to 8-bit and convert to generic params |
|
125 // |
|
126 TPtrC param = aCommandLine.DocumentName(); |
|
127 |
|
128 if ( param.Length() ) |
|
129 { |
|
130 HBufC8* param8 = HBufC8::NewLC( param.Length() ); |
|
131 param8->Des().Copy( param ); |
|
132 ExtractGenericParamsL( *param8 ); |
|
133 CleanupStack::PopAndDestroy( param8 ); |
|
134 } |
|
135 |
|
136 return ETrue; |
|
137 } |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CLWPlayerAppUi::HandleMessageL |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 MCoeMessageObserver::TMessageResponse |
|
144 CLWPlayerAppUi::HandleMessageL( TUint32 aClientHandleOfTWG, |
|
145 TUid aMessageUid, |
|
146 const TDesC8& aMessageParameters ) |
|
147 { |
|
148 MPX_DEBUG(_L("CLWPlayerAppUi::HandleMessageL()")); |
|
149 |
|
150 if ( iAllowEvents && iEmbeddedMPCreated ) |
|
151 { |
|
152 // |
|
153 // pass the message to Media Player |
|
154 // |
|
155 SendMessageL( aMessageParameters ); |
|
156 |
|
157 // |
|
158 // Since download manager can send multiple events with the same data |
|
159 // Block events from Download Manager for a short time |
|
160 // |
|
161 BlockEvents(); |
|
162 } |
|
163 |
|
164 return CAknAppUi::HandleMessageL( aClientHandleOfTWG, |
|
165 aMessageUid, |
|
166 aMessageParameters ); |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CLWPlayerAppUi::ExtractGenericParamsL |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CLWPlayerAppUi::ExtractGenericParamsL( const TDesC8& aParams ) |
|
174 { |
|
175 MPX_DEBUG(_L("CLWPlayerAppUi::ExtractGenericParamsL()")); |
|
176 |
|
177 CBufFlat* paramBuf = CBufFlat::NewL( /*anExpandSize*/1 ); |
|
178 CleanupStack::PushL( paramBuf ); |
|
179 paramBuf->InsertL( 0, aParams ); |
|
180 RBufReadStream readStream( *paramBuf ); |
|
181 |
|
182 CAiwGenericParamList* genParList = CAiwGenericParamList::NewLC(readStream); |
|
183 |
|
184 TInt index = 0; |
|
185 |
|
186 // |
|
187 // Unpack fileName |
|
188 // |
|
189 const TAiwGenericParam* paramFileName = |
|
190 genParList->FindFirst( index, EGenericParamFile, EVariantTypeDesC ); |
|
191 |
|
192 TPtrC fileName; |
|
193 |
|
194 // |
|
195 // If the parameter was not found, KErrNotFound is returned |
|
196 // |
|
197 if ( index == KErrNotFound ) |
|
198 { |
|
199 // |
|
200 // Invalid parameter listing. Set error so message will |
|
201 // be displayed and LWP will exit |
|
202 // |
|
203 HandleErrorL( KErrArgument ); |
|
204 } |
|
205 else |
|
206 { |
|
207 fileName.Set( paramFileName->Value().AsDes() ); |
|
208 |
|
209 MPX_DEBUG(_L(" filename = %S"), &fileName); |
|
210 |
|
211 if ( !iEmbeddedMPCreated ) |
|
212 { |
|
213 // |
|
214 // Launch the Media Player for ProgDL playback |
|
215 // Ignore the errors since the Media Player is |
|
216 // responsible for all error messages once launched. |
|
217 // |
|
218 TRAPD( err, LaunchMediaPlayerL( fileName, genParList ) ); |
|
219 |
|
220 if ( err != KErrNone ) |
|
221 { |
|
222 ActivateClosePlayerActiveObject(); |
|
223 } |
|
224 } |
|
225 } |
|
226 |
|
227 CleanupStack::PopAndDestroy( genParList ); |
|
228 CleanupStack::PopAndDestroy( paramBuf ); |
|
229 } |
|
230 |
|
231 TInt |
|
232 CLWPlayerAppUi::LaunchMediaPlayerL( const TDesC& afilename, |
|
233 const CAiwGenericParamList* aparamList ) |
|
234 { |
|
235 MPX_DEBUG(_L("CLWPlayerAppUi::LaunchMediaPlayerL(%S)"), &afilename); |
|
236 |
|
237 |
|
238 // |
|
239 // The download manager has already performed recognition on the file |
|
240 // using the cenrep keys. The LW Player should always launch the MP in |
|
241 // embedded mode. Using the MP UID to ensure that it is used. |
|
242 // |
|
243 TDataType datatype( KFUSIONPLAYERUID ); |
|
244 |
|
245 CDocumentHandler& handler = DocumentHandlerL(); |
|
246 |
|
247 RFile file; |
|
248 |
|
249 // |
|
250 // Call the document handler to open the file |
|
251 // It will leave if the filename is not present |
|
252 // |
|
253 TRAPD( err, handler.OpenTempFileL( afilename, file )); |
|
254 |
|
255 if ( err == KErrNotFound ) |
|
256 { |
|
257 HandleErrorL( err ); |
|
258 } |
|
259 else if ( err != KErrNone ) |
|
260 { |
|
261 User::Leave( err ); |
|
262 } |
|
263 else |
|
264 { |
|
265 CleanupClosePushL( file ); |
|
266 |
|
267 TRAPD( err, handler.OpenFileEmbeddedL( file, datatype, *aparamList ) ); |
|
268 |
|
269 // |
|
270 // ignore some document handler errors |
|
271 // |
|
272 if ( err == KErrServerTerminated ) |
|
273 { |
|
274 // |
|
275 // Document handler leaves with -15 if end key is pressed when |
|
276 // embedded application is not fully started or embedded |
|
277 // application panics in start up. So we can only close the |
|
278 // App in this point and hope that user is press end key |
|
279 // |
|
280 ActivateClosePlayerActiveObject(); |
|
281 } |
|
282 else if ( err != KErrNone ) |
|
283 { |
|
284 // Reset error since it was handled here and |
|
285 // the program will exit |
|
286 // |
|
287 User::Leave( err ); |
|
288 } |
|
289 |
|
290 iEmbeddedMPCreated = ETrue; |
|
291 |
|
292 CleanupStack::PopAndDestroy( &file ); // file.Close() |
|
293 } |
|
294 |
|
295 return KErrNone; |
|
296 } |
|
297 |
|
298 CDocumentHandler& CLWPlayerAppUi::DocumentHandlerL() |
|
299 { |
|
300 MPX_DEBUG(_L("CLWPlayerAppUi::DocumentHandlerL()")); |
|
301 |
|
302 if ( !iDocHandler ) |
|
303 { |
|
304 iDocHandler = CDocumentHandler::NewL(); |
|
305 } |
|
306 |
|
307 iDocHandler->SetExitObserver( this ); |
|
308 |
|
309 return *iDocHandler; |
|
310 } |
|
311 |
|
312 // ----------------------------------------------------------------------------- |
|
313 // CLWPlayerAppUi::NotifyExit |
|
314 // Called when user exits |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 void CLWPlayerAppUi::HandleServerAppExit(TInt aReason) |
|
318 { |
|
319 MPX_DEBUG(_L("CLWPlayerAppUi::HandleServerAppExit(%d)"), aReason); |
|
320 |
|
321 // |
|
322 // should exit here - MP terminated, if MP BACK it will bring up Browser |
|
323 // |
|
324 ActivateClosePlayerActiveObject(); |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CLWPlayerAppUi::SendMessageL |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 TInt CLWPlayerAppUi::SendMessageL(const TDesC8& aMessageParameters) |
|
332 { |
|
333 MPX_DEBUG(_L("CLWPlayerAppUi::SendMessageL()")); |
|
334 |
|
335 TInt ret = KErrNone; |
|
336 |
|
337 // |
|
338 // find the task number of the Media Player which is playing |
|
339 // the ProgDL |
|
340 // |
|
341 RArray<RWsSession::TWindowGroupChainInfo> wgs; |
|
342 User::LeaveIfError(iCoeEnv->WsSession().WindowGroupList(0, &wgs)); |
|
343 TBool progDLWindowGroup = EFalse; |
|
344 TInt count = wgs.Count(); |
|
345 TInt LWPwgId=0; |
|
346 |
|
347 CApaWindowGroupName::FindByAppUid( KLWPLAYERUID , |
|
348 iCoeEnv->WsSession(), |
|
349 LWPwgId ); |
|
350 |
|
351 TApaTask task( iCoeEnv->WsSession() ); |
|
352 |
|
353 // |
|
354 // initialise task to non-existant task |
|
355 // |
|
356 task.SetWgId( 0 ); |
|
357 |
|
358 // |
|
359 // wgId = 0 tells FindAppByUid to start looking for apps |
|
360 // |
|
361 TInt wgId = 0; |
|
362 |
|
363 while ( ( wgId != KErrNotFound ) && ! progDLWindowGroup ) |
|
364 { |
|
365 CApaWindowGroupName::FindByAppUid( KFUSIONPLAYERUID, |
|
366 iCoeEnv->WsSession(), |
|
367 wgId ); |
|
368 |
|
369 for ( TInt i=0 ; i<count ; i++ ) |
|
370 { |
|
371 const RWsSession::TWindowGroupChainInfo& info = wgs[i]; |
|
372 |
|
373 // find the window group id and check that it's parent id is LWP |
|
374 if ( info.iId == wgId && info.iParentId == LWPwgId ) |
|
375 { |
|
376 progDLWindowGroup = ETrue; |
|
377 break; |
|
378 } |
|
379 } |
|
380 }; |
|
381 |
|
382 wgs.Close(); |
|
383 |
|
384 if ( progDLWindowGroup ) |
|
385 { |
|
386 task.SetWgId(wgId); |
|
387 } |
|
388 |
|
389 if ( task.Exists() ) |
|
390 { |
|
391 task.BringToForeground(); |
|
392 |
|
393 // |
|
394 // 8-bit buffer is required. |
|
395 // Uid is not used |
|
396 // |
|
397 ret = task.SendMessage( TUid::Uid( KVideoPlayerStartPDlPlayer ), aMessageParameters ); |
|
398 } |
|
399 |
|
400 return ret; |
|
401 } |
|
402 |
|
403 // ----------------------------------------------------------------------------- |
|
404 // CLWPlayerAppUi::HandleErrorL |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 void CLWPlayerAppUi::HandleErrorL( TInt aError ) |
|
408 { |
|
409 MPX_DEBUG(_L("CLWPlayerAppUi::HandleErrorL(%d)"), aError); |
|
410 |
|
411 HBufC* text; |
|
412 |
|
413 switch ( aError ) |
|
414 { |
|
415 case KErrNotFound: |
|
416 { |
|
417 text = StringLoader::LoadLC( R_LWP_CLIP_MISSING ); |
|
418 break; |
|
419 } |
|
420 case KErrArgument: |
|
421 default: |
|
422 { |
|
423 text = StringLoader::LoadLC( R_LWP_INVALID_CLIP ); |
|
424 break; |
|
425 } |
|
426 } |
|
427 |
|
428 CAknInformationNote* dlg = new (ELeave) CAknInformationNote(ETrue); |
|
429 dlg->ExecuteLD( text->Des() ); |
|
430 CleanupStack::PopAndDestroy(text); |
|
431 |
|
432 // |
|
433 // After the error message, Exit the Light Weight Player |
|
434 // |
|
435 ActivateClosePlayerActiveObject(); |
|
436 } |
|
437 |
|
438 // ------------------------------------------------------------------------------------------------- |
|
439 // CLWPlayerAppUi::ActivateClosePlayerActiveObject |
|
440 // ------------------------------------------------------------------------------------------------- |
|
441 // |
|
442 void CLWPlayerAppUi::ActivateClosePlayerActiveObject() |
|
443 { |
|
444 MPX_ENTER_EXIT(_L("CLWPlayerAppUi::ActivateClosePlayerActiveObject()")); |
|
445 |
|
446 if ( ! iCloseAO->IsActive() ) |
|
447 { |
|
448 iCloseAO->Start( TCallBack( CLWPlayerAppUi::CloseLWPlayerL, this ) ); |
|
449 } |
|
450 } |
|
451 |
|
452 // ----------------------------------------------------------------------------- |
|
453 // CLWPlayerAppUi::ClosePlayerL |
|
454 // ----------------------------------------------------------------------------- |
|
455 // |
|
456 TInt CLWPlayerAppUi::CloseLWPlayerL( TAny* aPtr ) |
|
457 { |
|
458 MPX_DEBUG(_L("CLWPlayerAppUi::ClosePlayerL()")); |
|
459 |
|
460 static_cast<CLWPlayerAppUi*>(aPtr)->DoCloseLWPlayerL(); |
|
461 return KErrNone; |
|
462 } |
|
463 |
|
464 // ------------------------------------------------------------------------------------------------- |
|
465 // CLWPlayerAppUi::DoClosePlayerL |
|
466 // ------------------------------------------------------------------------------------------------- |
|
467 // |
|
468 void CLWPlayerAppUi::DoCloseLWPlayerL() |
|
469 { |
|
470 MPX_ENTER_EXIT(_L("CLWPlayerAppUi::DoClosePlayerL()")); |
|
471 |
|
472 HandleCommandL( EEikCmdExit ); |
|
473 } |
|
474 |
|
475 // ------------------------------------------------------------------------------------------------- |
|
476 // CLWPlayerAppUi::HandleBlockEventsTimeout |
|
477 // ------------------------------------------------------------------------------------------------- |
|
478 // |
|
479 TInt CLWPlayerAppUi::HandleBlockEventsTimeout( TAny* aPtr ) |
|
480 { |
|
481 MPX_DEBUG(_L("CLWPlayerAppUi::HandleEventBlockTimeout()")); |
|
482 |
|
483 static_cast<CLWPlayerAppUi*>(aPtr)->UnblockEvents(); |
|
484 |
|
485 return KErrNone; |
|
486 } |
|
487 |
|
488 // ------------------------------------------------------------------------------------------------- |
|
489 // CLWPlayerAppUi::BlockEvents |
|
490 // ------------------------------------------------------------------------------------------------- |
|
491 // |
|
492 void CLWPlayerAppUi::BlockEvents() |
|
493 { |
|
494 MPX_DEBUG(_L("CLWPlayerAppUi::BlockEvents()")); |
|
495 |
|
496 // |
|
497 // Message received from Browser |
|
498 // Block other messages for 1 second to prevent double click errors |
|
499 // |
|
500 iAllowEvents = EFalse; |
|
501 |
|
502 if ( iBlockEventsTimer->IsActive() ) |
|
503 { |
|
504 iBlockEventsTimer->Cancel(); |
|
505 } |
|
506 |
|
507 iBlockEventsTimer->Start( KEVENTBLOCKTIMEOUT, |
|
508 0, |
|
509 TCallBack( CLWPlayerAppUi::HandleBlockEventsTimeout, this ) ); |
|
510 } |
|
511 |
|
512 // ------------------------------------------------------------------------------------------------- |
|
513 // CLWPlayerAppUi::UnblockEvents |
|
514 // ------------------------------------------------------------------------------------------------- |
|
515 // |
|
516 void CLWPlayerAppUi::UnblockEvents() |
|
517 { |
|
518 MPX_DEBUG(_L("CLWPlayerAppUi::UnblockEvents()")); |
|
519 |
|
520 iAllowEvents = ETrue; |
|
521 |
|
522 if ( iBlockEventsTimer->IsActive() ) |
|
523 { |
|
524 iBlockEventsTimer->Cancel(); |
|
525 } |
|
526 } |
|
527 |
|
528 // End of File |