|
1 /* |
|
2 * Copyright (c) 2005-2006 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: Content plugin event handler |
|
15 * |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 |
|
20 // User includes |
|
21 #include <aiutility.h> |
|
22 #include <aiplugintool.h> |
|
23 #include <aicontentrequest.h> |
|
24 |
|
25 #include "aipluginfactory.h" |
|
26 #include "aiconsts.h" |
|
27 #include "debug.h" |
|
28 |
|
29 #include "aieventhandler.h" |
|
30 |
|
31 // Constants |
|
32 const TInt KAILenOfParenthesis( 2 ); |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 // ---------------------------------------------------------------------------- |
|
37 // CAiEventHandler::NewL() |
|
38 // |
|
39 // ---------------------------------------------------------------------------- |
|
40 // |
|
41 CAiEventHandler* CAiEventHandler::NewL( |
|
42 CAiPluginFactory& aFactory ) |
|
43 { |
|
44 CAiEventHandler* self = |
|
45 new ( ELeave ) CAiEventHandler( aFactory ); |
|
46 |
|
47 CleanupStack::PushL( self ); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ---------------------------------------------------------------------------- |
|
54 // CAiEventHandler::ConstructL() |
|
55 // |
|
56 // ---------------------------------------------------------------------------- |
|
57 // |
|
58 void CAiEventHandler::ConstructL() |
|
59 { |
|
60 iPluginTool = AiUtility::CreatePluginToolL(); |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------------------------- |
|
64 // CAiEventHandler::~CAiEventHandler() |
|
65 // |
|
66 // ---------------------------------------------------------------------------- |
|
67 // |
|
68 CAiEventHandler::~CAiEventHandler() |
|
69 { |
|
70 Release( iPluginTool ); |
|
71 } |
|
72 |
|
73 // ---------------------------------------------------------------------------- |
|
74 // CAiEventHandler::CAiEventHandler() |
|
75 // |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 CAiEventHandler::CAiEventHandler( CAiPluginFactory& aFactory ) |
|
79 : iFactory( aFactory ) |
|
80 { |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------------------------- |
|
84 // CAiEventHandler::HandlePluginEvent() |
|
85 // |
|
86 // ---------------------------------------------------------------------------- |
|
87 // |
|
88 void CAiEventHandler::HandlePluginEvent( const TDesC& aParam ) |
|
89 { |
|
90 const TInt separatorPos( aParam.Locate( KPluginEventSeparator ) ); |
|
91 |
|
92 if( separatorPos == KErrNotFound ) |
|
93 { |
|
94 return; |
|
95 } |
|
96 |
|
97 // Extract plugin name |
|
98 TPtrC pluginName( aParam.Left( separatorPos ) ); |
|
99 |
|
100 // Extract event and parameter string |
|
101 TPtrC eventNameAndParams( aParam.Mid( separatorPos + 1 ) ); |
|
102 |
|
103 // Find parameter string position |
|
104 const TInt paramsPos( |
|
105 eventNameAndParams.Locate( KEventParameterSeparator ) ); |
|
106 |
|
107 // Extract event name |
|
108 TPtrC eventName( paramsPos < 0 ? eventNameAndParams : |
|
109 eventNameAndParams.Left( paramsPos ) ); |
|
110 |
|
111 // Calculate actual parameter string length by ignoring parenthesis |
|
112 TInt paramsLength( |
|
113 eventNameAndParams.Length() - paramsPos - KAILenOfParenthesis ); |
|
114 |
|
115 // Extract paramenters |
|
116 TPtrC param( paramsPos < 0 ? KNullDesC() : |
|
117 eventNameAndParams.Mid( paramsPos + 1, Max( 0, paramsLength ) ) ); |
|
118 |
|
119 // Resolve plugin |
|
120 CHsContentPublisher* publisher( NULL ); |
|
121 |
|
122 __TIME( "FW: Lookup plug-in by name", |
|
123 publisher = iFactory.PluginByName( pluginName ); |
|
124 ); |
|
125 |
|
126 __PRINT( __DBG_FORMAT( |
|
127 "\t[I]\t Event: %S to plug-in by addr 0x%x" ), &aParam, publisher ); |
|
128 |
|
129 if( publisher ) |
|
130 { |
|
131 // Resolve plugin specific event id |
|
132 TInt eventId( KErrNotFound ); |
|
133 |
|
134 TRAP_IGNORE( GetIdL( *publisher, |
|
135 CHsContentPublisher::EPublisherEvents, eventName, eventId ) ); |
|
136 |
|
137 if( eventId != KErrNotFound ) |
|
138 { |
|
139 publisher->HandleEvent( eventId, param ); |
|
140 } |
|
141 else |
|
142 { |
|
143 publisher->HandleEvent( eventName, param ); |
|
144 } |
|
145 } |
|
146 } |
|
147 |
|
148 // ---------------------------------------------------------------------------- |
|
149 // CAiEventHandler::HandlePluginEventL() |
|
150 // |
|
151 // ---------------------------------------------------------------------------- |
|
152 // |
|
153 void CAiEventHandler::HandlePluginEventL( |
|
154 const THsPublisherInfo& aPublisherInfo, const TDesC& aParam ) |
|
155 { |
|
156 // Resolve plugin |
|
157 CHsContentPublisher* publisher( |
|
158 iFactory.PluginByInfo( aPublisherInfo ) ); |
|
159 |
|
160 if( publisher ) |
|
161 { |
|
162 const TInt separatorPos( aParam.Locate( KPluginEventSeparator ) ); |
|
163 |
|
164 // Extract event and parameter string |
|
165 TPtrC eventNameAndParams( aParam.Mid( separatorPos + 1 ) ); |
|
166 |
|
167 // Find parameter string position |
|
168 const TInt paramsPos( |
|
169 eventNameAndParams.Locate( KEventParameterSeparator ) ); |
|
170 |
|
171 // Extract event name |
|
172 TPtrC eventName( paramsPos < 0 ? |
|
173 eventNameAndParams : eventNameAndParams.Left( paramsPos ) ); |
|
174 |
|
175 // Calculate actual parameter string length by ignoring parenthesis |
|
176 TInt paramsLength( |
|
177 eventNameAndParams.Length() - paramsPos - KAILenOfParenthesis ); |
|
178 |
|
179 // Extract paramenters |
|
180 TPtrC param( paramsPos < 0 ? KNullDesC() : |
|
181 eventNameAndParams.Mid( paramsPos + 1, Max( 0, paramsLength ) ) ); |
|
182 |
|
183 // Resolve plugin specific event id |
|
184 TInt eventId( KErrNotFound ); |
|
185 |
|
186 GetIdL( *publisher, |
|
187 CHsContentPublisher::EPublisherEvents, eventName, eventId ); |
|
188 |
|
189 if( eventId != KErrNotFound ) |
|
190 { |
|
191 publisher->HandleEvent( eventId, param ); |
|
192 } |
|
193 else |
|
194 { |
|
195 publisher->HandleEvent( eventName, param ); |
|
196 } |
|
197 } |
|
198 } |
|
199 |
|
200 // ---------------------------------------------------------------------------- |
|
201 // CAiEventHandler::HasMenuItemL() |
|
202 // |
|
203 // ---------------------------------------------------------------------------- |
|
204 // |
|
205 TBool CAiEventHandler::HasMenuItemL( const THsPublisherInfo& aPublisherInfo, |
|
206 const TDesC& aMenuItem ) |
|
207 { |
|
208 // Resolve plugin |
|
209 CHsContentPublisher* publisher( |
|
210 iFactory.PluginByInfo( aPublisherInfo ) ); |
|
211 |
|
212 if( publisher ) |
|
213 { |
|
214 return publisher->HasMenuItem( aMenuItem ); |
|
215 } |
|
216 |
|
217 return EFalse; |
|
218 } |
|
219 |
|
220 // ---------------------------------------------------------------------------- |
|
221 // CAiEventHandler::RefreshContent() |
|
222 // |
|
223 // ---------------------------------------------------------------------------- |
|
224 // |
|
225 TBool CAiEventHandler::RefreshContent( const TDesC& aContentCid ) |
|
226 { |
|
227 TRAPD( error, RefreshContentL( aContentCid ) ); |
|
228 |
|
229 return ( error == KErrNone ); |
|
230 } |
|
231 |
|
232 // ---------------------------------------------------------------------------- |
|
233 // CAiEventHandler::RefreshContent() |
|
234 // |
|
235 // ---------------------------------------------------------------------------- |
|
236 // |
|
237 TBool CAiEventHandler::RefreshContent( const THsPublisherInfo& aPublisherInfo, |
|
238 const TDesC& aContentCid ) |
|
239 { |
|
240 // Resolve plugin |
|
241 CHsContentPublisher* publisher( |
|
242 iFactory.PluginByInfo( aPublisherInfo ) ); |
|
243 |
|
244 if( publisher ) |
|
245 { |
|
246 TInt id( KErrNotFound ); |
|
247 |
|
248 TRAP_IGNORE( GetIdL( *publisher, |
|
249 CHsContentPublisher::EPublisherContent, aContentCid, id ) ); |
|
250 |
|
251 if ( id != KErrNotFound ) |
|
252 { |
|
253 MAiContentRequest* handler = static_cast< MAiContentRequest* >( |
|
254 publisher->GetProperty( CHsContentPublisher::EContentRequest ) ); |
|
255 |
|
256 if ( handler ) |
|
257 { |
|
258 return handler->RefreshContent( id ); |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 return EFalse; |
|
264 } |
|
265 |
|
266 // ---------------------------------------------------------------------------- |
|
267 // CAiEventHandler::SuspendContent() |
|
268 // |
|
269 // ---------------------------------------------------------------------------- |
|
270 // |
|
271 TBool CAiEventHandler::SuspendContent( const THsPublisherInfo& aPublisherInfo, |
|
272 const TDesC& aContentCid ) |
|
273 { |
|
274 // Resolve plugin |
|
275 CHsContentPublisher* publisher( |
|
276 iFactory.PluginByInfo( aPublisherInfo ) ); |
|
277 |
|
278 if( publisher ) |
|
279 { |
|
280 TInt id( KErrNotFound ); |
|
281 |
|
282 TRAP_IGNORE( GetIdL( *publisher, |
|
283 CHsContentPublisher::EPublisherContent, aContentCid, id ) ); |
|
284 |
|
285 if ( id != KErrNotFound ) |
|
286 { |
|
287 MAiContentRequest* handler = static_cast< MAiContentRequest* >( |
|
288 publisher->GetProperty( CHsContentPublisher::EContentRequest ) ); |
|
289 |
|
290 if ( handler ) |
|
291 { |
|
292 return handler->SuspendContent( id ); |
|
293 } |
|
294 } |
|
295 } |
|
296 |
|
297 return EFalse; |
|
298 } |
|
299 |
|
300 // ---------------------------------------------------------------------------- |
|
301 // CAiEventHandler::GetIdL() |
|
302 // |
|
303 // ---------------------------------------------------------------------------- |
|
304 // |
|
305 void CAiEventHandler::GetIdL( CHsContentPublisher& aContentPublisher, |
|
306 CHsContentPublisher::TProperty aProperty, const TDesC& aName, TInt& aId ) |
|
307 { |
|
308 MAiContentItemIterator* iterator = |
|
309 iPluginTool->ContentItemIterator( aContentPublisher, aProperty ); |
|
310 |
|
311 if( iterator ) |
|
312 { |
|
313 const TAiContentItem& ci( iterator->ItemL( aName ) ); |
|
314 aId = ci.id; |
|
315 } |
|
316 else |
|
317 { |
|
318 aId = KErrNotFound; |
|
319 } |
|
320 } |
|
321 |
|
322 // ---------------------------------------------------------------------------- |
|
323 // CAiEventHandler::RefreshContentL() |
|
324 // |
|
325 // ---------------------------------------------------------------------------- |
|
326 // |
|
327 TInt CAiEventHandler::RefreshContentL( const TDesC& aContentCid ) |
|
328 { |
|
329 TInt retval( KErrNotFound ); |
|
330 |
|
331 // Look up plug-in and content item and delegate to plug-in's |
|
332 // MAiContentRequest implementation. |
|
333 |
|
334 // Find plugin name |
|
335 TInt pos( aContentCid.Locate( KPluginEventSeparator ) ); |
|
336 |
|
337 if( pos == KErrNotFound ) |
|
338 { |
|
339 return retval; |
|
340 } |
|
341 |
|
342 TPtrC pluginName( aContentCid.Left( pos ) ); |
|
343 |
|
344 CHsContentPublisher* publisher( iFactory.PluginByName( pluginName ) ); |
|
345 |
|
346 if( !publisher ) |
|
347 { |
|
348 return retval; |
|
349 } |
|
350 |
|
351 // Extract content id |
|
352 TPtrC cid( aContentCid.Mid( ++pos ) ); |
|
353 TInt id( 0 ); |
|
354 |
|
355 MAiContentRequest* handler( NULL ); |
|
356 |
|
357 TRAPD( error, GetIdL( *publisher, |
|
358 CHsContentPublisher::EPublisherContent, cid, id ) ); |
|
359 |
|
360 if ( !error ) |
|
361 { |
|
362 handler = static_cast< MAiContentRequest* >( |
|
363 publisher->GetProperty( CHsContentPublisher::EContentRequest ) ); |
|
364 } |
|
365 else |
|
366 { |
|
367 GetIdL( *publisher, |
|
368 CHsContentPublisher::EPublisherResources, cid, id ); |
|
369 |
|
370 handler = static_cast< MAiContentRequest* >( |
|
371 publisher->GetProperty( CHsContentPublisher::EResourceRequest ) ); |
|
372 } |
|
373 |
|
374 // Forward event to plugin |
|
375 if( handler && handler->RefreshContent( id ) ) |
|
376 { |
|
377 retval = KErrNone; |
|
378 } |
|
379 |
|
380 return retval; |
|
381 } |
|
382 |
|
383 // End of File. |