|
1 /* |
|
2 * Copyright (c) 2008-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: AIW command handler base class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "glxcommandhandleraiwbase.h" |
|
22 |
|
23 #include <glxattributecontext.h> |
|
24 #include <glxattributeretriever.h> |
|
25 #include <mglxmedialist.h> |
|
26 #include <glxuiutilities.rsg> |
|
27 #include <glxgeneraluiutilities.h> |
|
28 #include <glxcommandhandlers.hrh> |
|
29 #include <glxtracer.h> |
|
30 #include <glxassert.h> |
|
31 #include <glxuistd.h> |
|
32 |
|
33 #include "glxaiwservicehandler.h" |
|
34 |
|
35 #include <glxresourceutilities.h> // for CGlxResourceUtilities |
|
36 #include <data_caging_path_literals.hrh> |
|
37 |
|
38 const TInt KGlxAiwDefaultMaxSelectedItems = 200; |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // Constructor |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 CGlxCommandHandlerAiwBase::CGlxCommandHandlerAiwBase( |
|
45 MGlxMediaListProvider* aMediaListProvider, TInt aMenuResource ) |
|
46 : CGlxMediaListCommandHandler( aMediaListProvider ), |
|
47 iMenuResource( aMenuResource ) |
|
48 { |
|
49 iAppUi = static_cast< CAknAppUi* >( CCoeEnv::Static()->AppUi() ); |
|
50 } |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // ConstructL |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void CGlxCommandHandlerAiwBase::ConstructL() |
|
57 { |
|
58 |
|
59 TParse parse; |
|
60 parse.Set(KGlxUiUtilitiesResource, &KDC_APP_RESOURCE_DIR, NULL); |
|
61 TFileName resourceFile; |
|
62 resourceFile.Append(parse.FullName()); |
|
63 CGlxResourceUtilities::GetResourceFilenameL(resourceFile); |
|
64 |
|
65 iResourceOffset = CCoeEnv::Static()->AddResourceFileL(resourceFile); |
|
66 |
|
67 iAiwServiceHandler = CGlxAiwServiceHandler::InstanceL(); |
|
68 |
|
69 iAiwServiceHandler->AttachMenuL( iMenuResource, AiwInterestResource() ); |
|
70 |
|
71 // Add supported command |
|
72 TCommandInfo info(CommandId()); |
|
73 // Filter out static items |
|
74 info.iMinSelectionLength = 1; |
|
75 info.iMaxSelectionLength = MaxSelectedItems(); |
|
76 info.iStopAnimationForExecution = ETrue; |
|
77 info.iCategoryFilter = EMPXCommand; |
|
78 info.iCategoryRule = TCommandInfo::EForbidAll; |
|
79 AddCommandL(info); |
|
80 |
|
81 |
|
82 } |
|
83 |
|
84 // ----------------------------------------------------------------------------- |
|
85 // Destructor |
|
86 // ----------------------------------------------------------------------------- |
|
87 // |
|
88 CGlxCommandHandlerAiwBase::~CGlxCommandHandlerAiwBase() |
|
89 { |
|
90 if (iAiwServiceHandler) |
|
91 { |
|
92 iAiwServiceHandler->Close(); |
|
93 } |
|
94 if (iResourceOffset) |
|
95 { |
|
96 CCoeEnv::Static()->DeleteResourceFile(iResourceOffset); |
|
97 } |
|
98 |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // DoActivateL |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CGlxCommandHandlerAiwBase::DoActivateL(TInt /*aViewId*/) |
|
106 { |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // Deactivate |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CGlxCommandHandlerAiwBase::Deactivate() |
|
114 { |
|
115 } |
|
116 |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // DoExecuteL |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 |
|
123 |
|
124 TBool CGlxCommandHandlerAiwBase::DoExecuteL(TInt aCommandId, |
|
125 MGlxMediaList& /* aList */) |
|
126 { |
|
127 TBool consumed = EFalse; |
|
128 |
|
129 // Check whether we can handle this command. |
|
130 // Because BypassFiltersForExecute is enabled, we receive all command IDs. |
|
131 if (iAiwServiceHandler->IsSameCommand( aCommandId, AiwCommandId() ) |
|
132 && AiwItemEnabledL() ) |
|
133 { |
|
134 // Stop animations |
|
135 iAppUi->ProcessCommandL( EGlxCmdDisableAnimations ); |
|
136 |
|
137 // Now gather the AIW parameters only for this service |
|
138 // The InParam list at this point is empty (and must be empty). |
|
139 GatherAiwParametersL(*iAiwServiceHandler); |
|
140 iAiwServiceHandler->AppendInParamsL(); |
|
141 |
|
142 TRAPD( err, iAiwServiceHandler->ExecuteMenuCmdL( aCommandId, 0, this ) ); |
|
143 |
|
144 // If there is an error we must restart animations. then we can leave |
|
145 if (KErrNone != err) |
|
146 { |
|
147 // Restart animations |
|
148 iAppUi->ProcessCommandL( EGlxCmdEnableAnimations ); |
|
149 |
|
150 User::Leave( err ); |
|
151 } |
|
152 // After executing aiw command reset params list and menuInitialized flag |
|
153 // so that next iptions menu initialization takes new params list |
|
154 iAiwServiceHandler->ResetMenuInitialisedFlag(); |
|
155 consumed = ETrue; |
|
156 } |
|
157 |
|
158 return consumed; |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // DoDynInitMenuPaneL |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 void CGlxCommandHandlerAiwBase::DoDynInitMenuPaneL(TInt aResourceId, |
|
166 CEikMenuPane* aMenuPane) |
|
167 { |
|
168 if (aMenuPane) |
|
169 { |
|
170 if (iAiwServiceHandler->HandleSubmenuL( *aMenuPane )) |
|
171 { |
|
172 // AIW handles AIW sub-menus so do nothing else here |
|
173 return; |
|
174 } |
|
175 |
|
176 TInt err = KErrNone; |
|
177 TInt itemPos = 0; |
|
178 if (aMenuPane->MenuItemExists(CommandId(), itemPos)) |
|
179 { |
|
180 if (!AiwItemEnabledL()) |
|
181 { |
|
182 err = KErrGeneral; |
|
183 } |
|
184 } |
|
185 if (err == KErrNone && iAiwServiceHandler->IsAiwMenu(aResourceId) ) |
|
186 { |
|
187 AiwDoDynInitMenuPaneL(aResourceId, aMenuPane); |
|
188 |
|
189 // Initialize menu pane |
|
190 TRAP(err, iAiwServiceHandler->InitializeMenuPaneL( |
|
191 *aMenuPane, aResourceId, EGlxCmdAiwBase)); |
|
192 } |
|
193 |
|
194 if (err != KErrNone) |
|
195 { |
|
196 // If there's been any error (e.g. incomplete attributes due to |
|
197 // user cancellation), then remove command from menu |
|
198 TInt pos; |
|
199 if (aMenuPane->MenuItemExists(CommandId(), pos)) |
|
200 { |
|
201 aMenuPane->SetItemDimmed(CommandId(), ETrue); |
|
202 } |
|
203 } |
|
204 } |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // AppendDefaultAiwParameterL |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 /// parameter should also be of format aParameter, so glxAiwServiceHandler => aAiwServiceHandler |
|
212 TBool CGlxCommandHandlerAiwBase::AppendDefaultAiwParameterL(const TGlxMedia& aItem, |
|
213 CGlxAiwServiceHandler& aAiwServiceHandler, |
|
214 TBool aAddUri, |
|
215 TBool aAddMimeType) |
|
216 { |
|
217 TBool successUri = ETrue; |
|
218 TBool successMimeType = ETrue; |
|
219 |
|
220 // First check to see if we need to add the Uri |
|
221 if (aAddUri) |
|
222 { |
|
223 successUri = AppendTextParameterL(aItem, aAiwServiceHandler, aItem.Uri(), EGenericParamFile); |
|
224 } |
|
225 |
|
226 // Then check to see if we need the mime type |
|
227 if (aAddMimeType) |
|
228 { |
|
229 successMimeType = AppendTextParameterL(aItem, aAiwServiceHandler, aItem.MimeType(), EGenericParamMIMEType); |
|
230 } |
|
231 |
|
232 return successUri && successMimeType; |
|
233 } |
|
234 |
|
235 // ----------------------------------------------------------------------------- |
|
236 // AppendTextParameterL |
|
237 // ----------------------------------------------------------------------------- |
|
238 // |
|
239 TBool CGlxCommandHandlerAiwBase::AppendTextParameterL(const TGlxMedia& aItem, |
|
240 CGlxAiwServiceHandler& aAiwServiceHandler, |
|
241 const TDesC& aText, |
|
242 TGenericParamIdValue aGenericParamIdValue) |
|
243 { |
|
244 TBool success = EFalse; |
|
245 |
|
246 if (aText != KNullDesC) |
|
247 { |
|
248 aAiwServiceHandler.AddParamL(aItem.Id(), TAiwGenericParam( aGenericParamIdValue, TAiwVariant( aText ) ) ); |
|
249 |
|
250 success = ETrue; |
|
251 } |
|
252 |
|
253 return success; |
|
254 } |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // BypassFiltersForExecute |
|
258 // ----------------------------------------------------------------------------- |
|
259 // |
|
260 TBool CGlxCommandHandlerAiwBase::BypassFiltersForExecute() const |
|
261 { |
|
262 // We need to bypass the MediaListCommandHandler filters for execution. |
|
263 // Because Aiw assigns its own IDs for items added to the menu, we don't |
|
264 // know which command IDs we actually support. |
|
265 // By returning true, we receive all commands in DoExecuteL. |
|
266 return ETrue; |
|
267 } |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // BypassFiltersForExecute |
|
271 // ----------------------------------------------------------------------------- |
|
272 // |
|
273 TBool CGlxCommandHandlerAiwBase::BypassFiltersForMenu() const |
|
274 { |
|
275 // We need to bypass the MediaListCommandHandler filters for menu init. |
|
276 // Due to the AIW commands appearing in a submenu, we need to make sure |
|
277 // they are not automatically filtered out because they aren't |
|
278 // listed in our "Supported" command set |
|
279 // (We don't know which command values will be assigned by AIW) |
|
280 return ETrue; |
|
281 } |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // GatherAiwParametersL |
|
285 // ----------------------------------------------------------------------------- |
|
286 // |
|
287 TBool CGlxCommandHandlerAiwBase::GatherAiwParametersL(CGlxAiwServiceHandler& aAiwServiceHandler) |
|
288 { |
|
289 |
|
290 TRACER("CGlxCommandHandlerAiwBase::GatherAiwParametersL()"); |
|
291 TInt allFound = ETrue; |
|
292 |
|
293 MGlxMediaList& mediaList = MediaList(); |
|
294 |
|
295 // Iterate through selected items to gather the parameters for AIW |
|
296 |
|
297 TGlxSelectionIterator iterator; |
|
298 iterator.SetToFirst(&mediaList); |
|
299 TInt index = KErrNotFound; |
|
300 |
|
301 while (KErrNotFound != (index = iterator++) && allFound) |
|
302 { |
|
303 allFound = AppendAiwParameterL(mediaList.Item(index), aAiwServiceHandler); |
|
304 } |
|
305 |
|
306 return allFound; |
|
307 } |
|
308 |
|
309 |
|
310 // ----------------------------------------------------------------------------- |
|
311 // PreDynInitMenuPaneL |
|
312 // ----------------------------------------------------------------------------- |
|
313 // |
|
314 void CGlxCommandHandlerAiwBase::PreDynInitMenuPaneL( TInt aResourceId ) |
|
315 { |
|
316 if( AiwItemEnabledL() && iAiwServiceHandler->IsAiwMenu( aResourceId ) ) |
|
317 { |
|
318 GatherAiwParametersL(*iAiwServiceHandler); |
|
319 } |
|
320 } |
|
321 |
|
322 // ----------------------------------------------------------------------------- |
|
323 // MaxSelectedItems |
|
324 // ----------------------------------------------------------------------------- |
|
325 // |
|
326 TInt CGlxCommandHandlerAiwBase::MaxSelectedItems() const |
|
327 { |
|
328 return KGlxAiwDefaultMaxSelectedItems; |
|
329 } |
|
330 |
|
331 // ----------------------------------------------------------------------------- |
|
332 // HandleNotifyL |
|
333 // ----------------------------------------------------------------------------- |
|
334 // |
|
335 TInt CGlxCommandHandlerAiwBase::HandleNotifyL( |
|
336 TInt /*aCmdId*/, |
|
337 TInt aEventId, |
|
338 CAiwGenericParamList& /*aEventParamList*/, |
|
339 const CAiwGenericParamList& /*aInParamList*/) |
|
340 { |
|
341 switch ( aEventId ) |
|
342 { |
|
343 case KAiwEventCompleted: |
|
344 case KAiwEventCanceled: |
|
345 case KAiwEventError: |
|
346 case KAiwEventStopped: |
|
347 { |
|
348 // Restart animations |
|
349 iAppUi->ProcessCommandL(EGlxCmdEnableAnimations); |
|
350 } |
|
351 break; |
|
352 } |
|
353 |
|
354 return KErrNone; |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // AiwDoDynInitMenuPaneL |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 void CGlxCommandHandlerAiwBase::AiwDoDynInitMenuPaneL(TInt /*aResourceId*/, |
|
362 CEikMenuPane* /*aMenuPane*/) |
|
363 { |
|
364 // Do nothing by default, may be overridden |
|
365 } |
|
366 |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // AiwItemEnabledL |
|
370 // ----------------------------------------------------------------------------- |
|
371 // |
|
372 TBool CGlxCommandHandlerAiwBase::AiwItemEnabledL() |
|
373 { |
|
374 TBool enabled = EFalse; |
|
375 |
|
376 MGlxMediaList& mediaList = MediaList(); |
|
377 if (mediaList.Count() == 0) |
|
378 { |
|
379 return EFalse; |
|
380 } |
|
381 if ( mediaList.SelectionCount() == 0 ) |
|
382 { |
|
383 // No items in selection list. Check if focus item is static |
|
384 TInt focusIndex = mediaList.FocusIndex(); |
|
385 if(focusIndex != KErrNotFound) |
|
386 { |
|
387 if (!mediaList.Item(focusIndex).IsStatic()) |
|
388 { |
|
389 // Not static - so enable |
|
390 enabled = ETrue; |
|
391 } |
|
392 } |
|
393 } |
|
394 else if ( mediaList.SelectionCount() <= MaxSelectedItems() ) |
|
395 { |
|
396 // Count of selected items within range, so enable |
|
397 enabled = ETrue; |
|
398 } |
|
399 |
|
400 return enabled; |
|
401 } |
|
402 |
|
403 // ----------------------------------------------------------------------------- |
|
404 // AiwMenuCmdIdL |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 TInt CGlxCommandHandlerAiwBase::AiwMenuCmdIdL( const TDesC& aMenuItemText, |
|
408 CEikMenuPane* aMenuPane ) |
|
409 { |
|
410 TInt index = 0; |
|
411 TInt cmdId = KErrNotFound; |
|
412 TInt count = aMenuPane->NumberOfItemsInPane(); |
|
413 |
|
414 // Traverse through menupane until menu text required is found |
|
415 // or there are no more items in menupane |
|
416 while( index < count && aMenuItemText.CompareC( aMenuPane-> |
|
417 ItemDataByIndexL( index ).iText ) ) |
|
418 { |
|
419 index++; |
|
420 } |
|
421 // if count less than count then required item text is found, so get commandId for it |
|
422 if( index < count ) |
|
423 { |
|
424 cmdId = aMenuPane->ItemDataByIndexL( index ).iCommandId ; |
|
425 } |
|
426 |
|
427 return cmdId; |
|
428 } |
|
429 |