|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Used for handling XUIKON events |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "aixuikoneventhandler.h" |
|
20 #include "aifweventhandler.h" |
|
21 #include "aiuieventhandler.h" |
|
22 #include "aiapplicationeventhandler.h" |
|
23 #include "aiconsts.h" |
|
24 #include "xmluicontroller.h" |
|
25 #include "aixmluiconstants.h" |
|
26 #include "aixmluiutils.h" |
|
27 #include "contentrenderer.h" |
|
28 #include <activeidle2domainpskeys.h> |
|
29 #include <activeidle2domaincrkeys.h> |
|
30 #include <csxhelp/hmsc.hlp.hrh> |
|
31 #include <aisystemuids.hrh> |
|
32 |
|
33 #include "xnnodeappif.h" |
|
34 #include "xnuiengineappif.h" |
|
35 #include "xnproperty.h" |
|
36 #include "xndomnode.h" |
|
37 #include "xntype.h" |
|
38 #include "xndomlist.h" // for cxndomlist |
|
39 #include "xndomattribute.h" // for cxndomattribute |
|
40 #include <e32svr.h> |
|
41 #include <aiutility.h> |
|
42 #include <aistrparser.h> |
|
43 #include <layoutmetadata.cdl.h> |
|
44 #include <e32property.h> |
|
45 #include <centralrepository.h> |
|
46 #include <AknUtils.h> |
|
47 #include <akntoolbar.h> |
|
48 #include <aknappui.h> |
|
49 #include <hlplch.h> |
|
50 #include <aknlistquerydialog.h> |
|
51 #include <ai3xmlui.rsg> |
|
52 #include <aknnotewrappers.h> |
|
53 #include <StringLoader.h> |
|
54 #include "xndompropertyvalue.h" |
|
55 #include "xnnodeappif.h" |
|
56 #include "appui.h" |
|
57 #include "xndomproperty.h" |
|
58 #include "xnplugindefs.h" |
|
59 #include "aieventhandler.h" |
|
60 |
|
61 const TInt KAiMaxNumberCharacters = 5; |
|
62 |
|
63 namespace AiXmlUiController |
|
64 { |
|
65 class CAIXuikonEventHandler::CNullEventHandler : |
|
66 public CBase, |
|
67 public MAiFwEventHandler, |
|
68 public MAiUiEventHandler, |
|
69 public MAiApplicationEventHandler |
|
70 { |
|
71 |
|
72 private: // from MAiFwEventHandler |
|
73 void AppEnvReadyL(); |
|
74 void HandleUiReadyEventL( CAiUiController& aUiController ); |
|
75 void HandleActivateUI(); |
|
76 void HandleUiShutdown( CAiUiController& aUiController ); |
|
77 void CriticalStartupPhaseOver( TInt aStageInteger ); |
|
78 void HandleLoadPluginL( const TAiPublisherInfo& aPublisherInfo ); |
|
79 void HandleDestroyPluginL( const TAiPublisherInfo& aPublisherInfo ); |
|
80 void HandlePluginEvent( const TDesC& aParam ); |
|
81 void HandlePluginEventL( const TAiPublisherInfo& aPublisherInfo, const TDesC& aParam ); |
|
82 TBool HasMenuItemL( const TAiPublisherInfo& aPublisherInfo, const TDesC& aMenuItem ); |
|
83 TBool RefreshContent( const TDesC& aContentCid ); |
|
84 TBool QueryIsMenuOpen(); |
|
85 void ProcessStateChange( TAifwStates aSate ); |
|
86 |
|
87 private: // from MAiUiEventHandler |
|
88 TBool HandleUiEvent( TAny* aEvent, const TDesC8& aParam ); |
|
89 |
|
90 private: // from MAiApplicationEventHandler |
|
91 TBool HandleApplicationEvent( TInt aEvent, const TDesC8& aParam ); |
|
92 }; |
|
93 } |
|
94 |
|
95 using namespace AiXmlUiController; |
|
96 using namespace AiUiDef::xml::event; |
|
97 |
|
98 // ======== MEMBER FUNCTIONS ======== |
|
99 // ---------------------------------------------------------------------------- |
|
100 // CAIXuikonEventHandler::CAIXuikonEventHandler() |
|
101 // ---------------------------------------------------------------------------- |
|
102 // |
|
103 CAIXuikonEventHandler::CAIXuikonEventHandler( CXmlUiController& aUiController, |
|
104 CContentRenderer& aRenderer ) |
|
105 : iUiController(aUiController), |
|
106 iContentRenderer(aRenderer) |
|
107 { |
|
108 } |
|
109 |
|
110 // ---------------------------------------------------------------------------- |
|
111 // CAIXuikonEventHandler::ConstructL() |
|
112 // ---------------------------------------------------------------------------- |
|
113 // |
|
114 void CAIXuikonEventHandler::ConstructL() |
|
115 { |
|
116 iStrParser = AiUtility::CreateStrParserL(); |
|
117 iNullEventHandler = new ( ELeave ) CNullEventHandler; |
|
118 iFwEventHandler = iNullEventHandler; |
|
119 iUiEventHandler = iNullEventHandler; |
|
120 iApplicationEventHandler = iNullEventHandler; |
|
121 } |
|
122 |
|
123 // ---------------------------------------------------------------------------- |
|
124 // CAIXuikonEventHandler::NewL() |
|
125 // ---------------------------------------------------------------------------- |
|
126 // |
|
127 CAIXuikonEventHandler* CAIXuikonEventHandler::NewL( |
|
128 CXmlUiController& aUiController, |
|
129 CContentRenderer& aRenderer ) |
|
130 { |
|
131 CAIXuikonEventHandler* self = |
|
132 new ( ELeave ) CAIXuikonEventHandler( aUiController, aRenderer ); |
|
133 CleanupStack::PushL( self ); |
|
134 self->ConstructL(); |
|
135 CleanupStack::Pop( self ); |
|
136 return self; |
|
137 } |
|
138 |
|
139 // ---------------------------------------------------------------------------- |
|
140 // CAIXuikonEventHandler::~CAIXuikonEventHandler() |
|
141 // ---------------------------------------------------------------------------- |
|
142 // |
|
143 CAIXuikonEventHandler::~CAIXuikonEventHandler() |
|
144 { |
|
145 delete iNullEventHandler; |
|
146 delete iVolumeEvent; |
|
147 |
|
148 Release( iStrParser ); |
|
149 } |
|
150 |
|
151 // ---------------------------------------------------------------------------- |
|
152 // CAIXuikonEventHandler::SetFwEventHandler() |
|
153 // ---------------------------------------------------------------------------- |
|
154 // |
|
155 void CAIXuikonEventHandler::SetFwEventHandler( |
|
156 MAiFwEventHandler* aFwEventHandler ) |
|
157 { |
|
158 if ( aFwEventHandler ) |
|
159 { |
|
160 iFwEventHandler = aFwEventHandler; |
|
161 } |
|
162 else |
|
163 { |
|
164 iFwEventHandler = iNullEventHandler; |
|
165 } |
|
166 } |
|
167 |
|
168 // ---------------------------------------------------------------------------- |
|
169 // CAIXuikonEventHandler::SetUiEventHandler() |
|
170 // ---------------------------------------------------------------------------- |
|
171 // |
|
172 void CAIXuikonEventHandler::SetUiEventHandler( |
|
173 MAiUiEventHandler* aUiEventHandler ) |
|
174 { |
|
175 if ( aUiEventHandler ) |
|
176 { |
|
177 iUiEventHandler = aUiEventHandler; |
|
178 } |
|
179 else |
|
180 { |
|
181 iUiEventHandler = iNullEventHandler; |
|
182 } |
|
183 } |
|
184 |
|
185 // ---------------------------------------------------------------------------- |
|
186 // CAIXuikonEventHandler::SetApplicationEventHandler() |
|
187 // ---------------------------------------------------------------------------- |
|
188 // |
|
189 void CAIXuikonEventHandler::SetApplicationEventHandler( |
|
190 MAiApplicationEventHandler* aApplicationEventHandler ) |
|
191 { |
|
192 if ( aApplicationEventHandler ) |
|
193 { |
|
194 iApplicationEventHandler = aApplicationEventHandler; |
|
195 } |
|
196 else |
|
197 { |
|
198 iApplicationEventHandler = iNullEventHandler; |
|
199 } |
|
200 } |
|
201 |
|
202 // ---------------------------------------------------------------------------- |
|
203 // CAIXuikonEventHandler::HandleXuikonEventL() |
|
204 // ---------------------------------------------------------------------------- |
|
205 // |
|
206 void CAIXuikonEventHandler::HandleXuikonEventL( CXnNodeAppIf& aOrigin, |
|
207 CXnNodeAppIf& /*aTrigger*/, CXnDomNode& aTriggerDefinition, |
|
208 CXnDomNode& aEvent ) |
|
209 { |
|
210 DispatchEventL( aEvent, aOrigin, aTriggerDefinition ); |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------------------------------- |
|
214 // CAIXuikonEventHandler::HandleXuikonActionL() |
|
215 // ---------------------------------------------------------------------------- |
|
216 // |
|
217 inline TBool CAIXuikonEventHandler::HandleSystemEventL( |
|
218 const TDesC8& aEventText, CXnDomNode& aEvent ) |
|
219 { |
|
220 const TDesC8& prefix( AiUiDef::xml::event::KEventHandlerPrefix ); |
|
221 TInt pos( aEventText.Find( prefix ) ); |
|
222 if ( pos != 0 ) |
|
223 { |
|
224 // Event is not targeted here |
|
225 return EFalse; |
|
226 } |
|
227 CAIEventHandler* handler = CAIEventHandler::NewL( iUiController ); |
|
228 CleanupStack::PushL( handler ); |
|
229 handler->HandleEventL( aEventText, aEvent ); |
|
230 CleanupStack::PopAndDestroy( handler ); |
|
231 return ETrue; |
|
232 } |
|
233 |
|
234 |
|
235 // ---------------------------------------------------------------------------- |
|
236 // CAIXuikonEventHandler::ParseParameterStringL() |
|
237 // ---------------------------------------------------------------------------- |
|
238 // |
|
239 void CAIXuikonEventHandler::ParseParameterStringL( const TDesC8& aSourcePtr, |
|
240 TPtrC8& aTargetPtr ) |
|
241 { |
|
242 // Parses parameter string between the first '(' and last ')' |
|
243 // Trailing and heading white spaces ARE NOT handled! |
|
244 |
|
245 const TInt separatorPos = aSourcePtr.Locate( KEventParameterSeparator ); |
|
246 User::LeaveIfError( separatorPos ); |
|
247 |
|
248 const TInt eventSeparatorPos = aSourcePtr.LocateReverse( |
|
249 KEventParameterSeparatorEnd ); |
|
250 User::LeaveIfError( eventSeparatorPos ); |
|
251 |
|
252 // separatorPos + 1 must be smaller than eventSeparatorPos - 1 |
|
253 User::LeaveIfError( ( eventSeparatorPos ) - ( separatorPos + 1 ) ); |
|
254 |
|
255 // Extract event and parameter string |
|
256 TPtrC8 menuName( aSourcePtr.Mid( separatorPos + 1, |
|
257 ( eventSeparatorPos ) - ( separatorPos + 1 ) ) ); |
|
258 |
|
259 aTargetPtr.Set( menuName ); |
|
260 } |
|
261 |
|
262 // ---------------------------------------------------------------------------- |
|
263 // CAIXuikonEventHandler::HandleUiEventL() |
|
264 // ---------------------------------------------------------------------------- |
|
265 // |
|
266 inline TBool CAIXuikonEventHandler::HandleUiEventL( const TDesC8& aEventText, |
|
267 CXnNodeAppIf& aOrigin ) |
|
268 { |
|
269 if ( aEventText.Left( KUiEventPrefix().Length() ) == KUiEventPrefix ) |
|
270 { |
|
271 iUiEventHandler->HandleUiEvent( (TAny*)&aOrigin, aEventText ); |
|
272 |
|
273 return ETrue; |
|
274 } |
|
275 |
|
276 return EFalse; |
|
277 } |
|
278 |
|
279 // ---------------------------------------------------------------------------- |
|
280 // CAIXuikonEventHandler::HandleApplicationEventL() |
|
281 // ---------------------------------------------------------------------------- |
|
282 // |
|
283 inline TBool CAIXuikonEventHandler::HandleApplicationEventL( |
|
284 const TDesC8& aEventText ) |
|
285 { |
|
286 return iApplicationEventHandler->HandleApplicationEvent( 0, aEventText ); |
|
287 } |
|
288 |
|
289 // ---------------------------------------------------------------------------- |
|
290 // CAIXuikonEventHandler::VolumeChanged() |
|
291 // ---------------------------------------------------------------------------- |
|
292 // |
|
293 void CAIXuikonEventHandler::VolumeChanged( TInt aValue ) |
|
294 { |
|
295 TRAP_IGNORE( |
|
296 // Ignore errors, missing one event is not fatal enough to panic |
|
297 HBufC* volumeString( HBufC::NewLC( KAiMaxNumberCharacters ) ); |
|
298 |
|
299 volumeString->Des().Num( aValue ); |
|
300 |
|
301 HBufC* eventString( iVolumeEvent->AllocLC() ); |
|
302 |
|
303 TInt foundAt( eventString->Des().Find( KTargetSliderVolumeValue ) ); |
|
304 |
|
305 if( foundAt >= 0 ) |
|
306 { |
|
307 eventString->Des().Replace( foundAt, |
|
308 KTargetSliderVolumeValue().Length(), *volumeString ); |
|
309 } |
|
310 |
|
311 // TODO: implement namespace properly |
|
312 iFwEventHandler->HandlePluginEvent( *eventString ); |
|
313 |
|
314 CleanupStack::PopAndDestroy( 2, volumeString ); |
|
315 ); // TRAP_IGNORE |
|
316 } |
|
317 |
|
318 // ---------------------------------------------------------------------------- |
|
319 // CAIXuikonEventHandler::HandlePluginEventL() |
|
320 // ---------------------------------------------------------------------------- |
|
321 // |
|
322 inline |
|
323 void CAIXuikonEventHandler::HandlePluginEventL( CXnDomNode& aEvent ) |
|
324 { |
|
325 const TDesC8& event8( |
|
326 aEvent.AttributeValue( XnPropertyNames::action::event::KName ) ); |
|
327 |
|
328 HBufC16* event( NULL ); |
|
329 |
|
330 event = iStrParser->CopyToBufferL( event, event8 ); |
|
331 |
|
332 if ( !event || *event == KNullDesC ) |
|
333 { |
|
334 // No event defined |
|
335 return; |
|
336 } |
|
337 |
|
338 CleanupStack::PushL( event ); |
|
339 |
|
340 TXnUiEngineAppIf* engine( iUiController.UiEngineL() ); |
|
341 |
|
342 const TDesC8& broadcast( |
|
343 aEvent.AttributeValue( XnPropertyNames::action::event::KBroadcast ) ); |
|
344 |
|
345 if ( broadcast == XnPropertyNames::KTrue ) |
|
346 { |
|
347 // Broadcast events are allowed only from view's namespace |
|
348 if ( engine->ActiveView()->Namespace() == aEvent.Namespace() ) |
|
349 { |
|
350 _LIT8( KGlobal, "global" ); |
|
351 |
|
352 // Get all plugins |
|
353 RPointerArray< CXnNodeAppIf > |
|
354 list( engine->FindContentSourceNodesL( KGlobal ) ); |
|
355 |
|
356 CleanupClosePushL( list ); |
|
357 |
|
358 // Broadcast event to all plugins |
|
359 for ( TInt i = 0; i < list.Count(); i++ ) |
|
360 { |
|
361 TAiPublisherInfo info; |
|
362 |
|
363 iUiController.PublisherInfoL( *list[i], info ); |
|
364 |
|
365 // Forward event to AiFw |
|
366 iFwEventHandler->HandlePluginEventL( info, *event ); |
|
367 } |
|
368 |
|
369 CleanupStack::PopAndDestroy( &list ); |
|
370 } |
|
371 } |
|
372 else |
|
373 { |
|
374 const TDesC8& ns( aEvent.Namespace() ); |
|
375 |
|
376 // Get plugins from the event's namespace |
|
377 RPointerArray< CXnNodeAppIf > |
|
378 list( engine->FindContentSourceNodesL( ns ) ); |
|
379 |
|
380 CleanupClosePushL( list ); |
|
381 |
|
382 if ( list.Count() == 1 ) |
|
383 { |
|
384 // Only one data plugin in this namespace, |
|
385 // it must handle this event. |
|
386 TAiPublisherInfo info; |
|
387 |
|
388 iUiController.PublisherInfoL( *list[0], info ); |
|
389 |
|
390 // Forward event to AiFw |
|
391 iFwEventHandler->HandlePluginEventL( info, *event ); |
|
392 } |
|
393 else if ( list.Count() > 1 ) |
|
394 { |
|
395 const TDesC8& destination( |
|
396 aEvent.AttributeValue( |
|
397 XnPropertyNames::action::event::KDestination ) ); |
|
398 |
|
399 // Multiple data plugins in this namespace, |
|
400 // resolve destination |
|
401 CXnNodeAppIf* eventHandler( |
|
402 engine->FindNodeByIdL( destination, ns ) ); |
|
403 |
|
404 if ( eventHandler ) |
|
405 { |
|
406 TAiPublisherInfo info; |
|
407 |
|
408 iUiController.PublisherInfoL( *eventHandler, info ); |
|
409 |
|
410 // Forward event to AiFw |
|
411 iFwEventHandler->HandlePluginEventL( info, *event ); |
|
412 } |
|
413 else |
|
414 { |
|
415 // No exact destination defined, |
|
416 // try to find a correct plugin based on event |
|
417 const TInt pos( event->Locate( KPluginEventSeparator ) ); |
|
418 |
|
419 if ( pos != KErrNotFound ) |
|
420 { |
|
421 // Extract plugin name |
|
422 TPtrC pluginName( event->Left( pos ) ); |
|
423 |
|
424 for ( TInt i = 0; i < list.Count(); i++ ) |
|
425 { |
|
426 TAiPublisherInfo info; |
|
427 |
|
428 iUiController.PublisherInfoL( *list[i], info ); |
|
429 |
|
430 if( info.iName == pluginName ) |
|
431 { |
|
432 // Forward Plug-in events to AI FW for further |
|
433 // dispatching to the target Plug-in |
|
434 iFwEventHandler->HandlePluginEventL( info,*event ); |
|
435 break; |
|
436 } |
|
437 } |
|
438 } |
|
439 } |
|
440 } |
|
441 |
|
442 CleanupStack::PopAndDestroy( &list ); |
|
443 } |
|
444 |
|
445 CleanupStack::PopAndDestroy( event ); |
|
446 } |
|
447 |
|
448 // ---------------------------------------------------------------------------- |
|
449 // CAIXuikonEventHandler::DispatchEventL() |
|
450 // ---------------------------------------------------------------------------- |
|
451 // |
|
452 void CAIXuikonEventHandler::DispatchEventL( CXnDomNode& aEvent, |
|
453 CXnNodeAppIf& aOrigin, CXnDomNode& /*aTriggerDefinition*/ ) |
|
454 { |
|
455 const TDesC8& aEventString8( |
|
456 aEvent.AttributeValue( XnPropertyNames::action::event::KName ) ); |
|
457 |
|
458 // First check if the event is a XUIKON-specific event |
|
459 if( !HandleSystemEventL( aEventString8, aEvent ) ) |
|
460 { |
|
461 // Next check if it is a UI event |
|
462 if( !HandleUiEventL( aEventString8, aOrigin ) ) |
|
463 { |
|
464 // Next check if it is an application event |
|
465 if( !HandleApplicationEventL( aEventString8 ) ) |
|
466 { |
|
467 // Assume that it is a Plug-in event |
|
468 HandlePluginEventL( aEvent ); |
|
469 } |
|
470 } |
|
471 } |
|
472 } |
|
473 |
|
474 // CAIXuikonEventHandler::CNullEventHandler |
|
475 void CAIXuikonEventHandler::CNullEventHandler::AppEnvReadyL() |
|
476 { |
|
477 } |
|
478 |
|
479 void CAIXuikonEventHandler::CNullEventHandler::HandleUiReadyEventL |
|
480 ( CAiUiController& /*aUiController*/ ) |
|
481 { |
|
482 } |
|
483 |
|
484 void CAIXuikonEventHandler::CNullEventHandler::HandleActivateUI() |
|
485 { |
|
486 } |
|
487 |
|
488 void CAIXuikonEventHandler::CNullEventHandler::HandlePluginEvent |
|
489 ( const TDesC& /*aParam*/ ) |
|
490 { |
|
491 } |
|
492 |
|
493 void CAIXuikonEventHandler::CNullEventHandler::HandlePluginEventL |
|
494 (const TAiPublisherInfo& /*aPublisherInfo*/, const TDesC& /*aParam*/ ) |
|
495 { |
|
496 } |
|
497 |
|
498 TBool CAIXuikonEventHandler::CNullEventHandler::HasMenuItemL( |
|
499 const TAiPublisherInfo& /*aPublisherInfo*/, const TDesC& /*aMenuItem*/ ) |
|
500 { |
|
501 return EFalse; |
|
502 } |
|
503 |
|
504 void CAIXuikonEventHandler::CNullEventHandler::HandleUiShutdown |
|
505 ( CAiUiController& /*aUiController*/ ) |
|
506 { |
|
507 } |
|
508 |
|
509 TBool CAIXuikonEventHandler::CNullEventHandler::RefreshContent( |
|
510 const TDesC& /*aContentCid*/ ) |
|
511 { |
|
512 return EFalse; |
|
513 } |
|
514 |
|
515 void CAIXuikonEventHandler::CNullEventHandler::CriticalStartupPhaseOver( |
|
516 TInt /*aStageInteger*/ ) |
|
517 { |
|
518 } |
|
519 |
|
520 TBool CAIXuikonEventHandler::CNullEventHandler::QueryIsMenuOpen() |
|
521 { |
|
522 return EFalse; |
|
523 } |
|
524 |
|
525 void CAIXuikonEventHandler::CNullEventHandler::ProcessStateChange( |
|
526 TAifwStates /*aSate*/) |
|
527 { |
|
528 } |
|
529 |
|
530 void CAIXuikonEventHandler::CNullEventHandler::HandleLoadPluginL( |
|
531 const TAiPublisherInfo& /*aPluginToLoad*/ ) |
|
532 { |
|
533 } |
|
534 |
|
535 void CAIXuikonEventHandler::CNullEventHandler::HandleDestroyPluginL( |
|
536 const TAiPublisherInfo& /*aPluginToDestroy*/ ) |
|
537 { |
|
538 } |
|
539 |
|
540 TBool CAIXuikonEventHandler::CNullEventHandler::HandleUiEvent |
|
541 (TAny* /*aEvent*/, const TDesC8& /*aParam*/) |
|
542 { |
|
543 return EFalse; |
|
544 } |
|
545 |
|
546 TBool CAIXuikonEventHandler::CNullEventHandler::HandleApplicationEvent |
|
547 (TInt /*aEvent*/, const TDesC8& /*aParam*/) |
|
548 { |
|
549 return EFalse; |
|
550 } |
|
551 |
|
552 // End of file |