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: cvimpstuimenuextension.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 |
|
20 #include <eikenv.h> |
|
21 #include <coeaui.h> |
|
22 #include <coemain.h> |
|
23 #include <barsread.h> |
|
24 #include <eikmenup.h> |
|
25 #include "uiservicetabtracer.h" |
|
26 |
|
27 #include "cvimpstuimenuextension.h" |
|
28 #include "ccommandinfo.h" |
|
29 |
|
30 #include "servicetabmenucommandinfo.hrh" |
|
31 #include "vimpstcustomcleanupapi.h" |
|
32 |
|
33 |
|
34 // ================= MEMBER FUNCTIONS ======================= |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // CVIMPSTUIMenuExtension::CVIMPSTUIMenuExtension |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 CVIMPSTUIMenuExtension::CVIMPSTUIMenuExtension( ) |
|
41 : iNewCommands( EServiceTabMenuExtensionFirstFreeCommand ) |
|
42 { |
|
43 TRACER_AUTO; |
|
44 } |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CVIMPSTUIMenuExtension::ConstructL |
|
48 // --------------------------------------------------------------------------- |
|
49 // |
|
50 void CVIMPSTUIMenuExtension::ConstructL() |
|
51 { |
|
52 TRACER_AUTO; |
|
53 LoadPluginL( ); |
|
54 |
|
55 |
|
56 } |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 // CVIMPSTUIMenuExtension::NewL |
|
60 // --------------------------------------------------------------------------- |
|
61 // |
|
62 CVIMPSTUIMenuExtension* CVIMPSTUIMenuExtension::NewL( ) |
|
63 { |
|
64 TRACER_AUTO; |
|
65 CVIMPSTUIMenuExtension* self = NewLC( ); |
|
66 CleanupStack::Pop(self); |
|
67 |
|
68 return self; |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // CVIMPSTUIMenuExtension::NewLC |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 CVIMPSTUIMenuExtension* CVIMPSTUIMenuExtension::NewLC() |
|
76 { |
|
77 TRACER_AUTO; |
|
78 CVIMPSTUIMenuExtension* self = |
|
79 new (ELeave) CVIMPSTUIMenuExtension( ); |
|
80 CleanupStack::PushL( self ); |
|
81 self->ConstructL(); |
|
82 |
|
83 return self; |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // CVIMPSTUIMenuExtension::~CVIMPSTUIMenuExtension |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 CVIMPSTUIMenuExtension::~CVIMPSTUIMenuExtension() |
|
91 { |
|
92 TRACER_AUTO; |
|
93 iCommandIdMap.ResetAndDestroy(); |
|
94 //iCommandIdMap.Close(); |
|
95 // Reset and destroy the contents of the owned arrays, |
|
96 // this will delete the plugins. |
|
97 iPlugins.ResetAndDestroy(); |
|
98 //iPlugins.Close(); |
|
99 |
|
100 iAIWCommandMap.ResetAndDestroy(); |
|
101 |
|
102 // Close the ECOM interface |
|
103 REComSession::FinalClose(); |
|
104 |
|
105 } |
|
106 |
|
107 // ---------------------------------------------------------------------------- |
|
108 // CVIMPSTUIMenuExtension::LoadPluginL |
|
109 // Loads all plugins |
|
110 // (other items were commented in a header). |
|
111 // ---------------------------------------------------------------------------- |
|
112 // |
|
113 void CVIMPSTUIMenuExtension::LoadPluginL( ) |
|
114 { |
|
115 TRACER_AUTO; |
|
116 // plugininfo array, Owned |
|
117 RImplInfoPtrArray pluginInfo; |
|
118 CustomCleanupResetAndDestroyPushL(pluginInfo); |
|
119 iPlugins.ResetAndDestroy(); |
|
120 REComSession::ListImplementationsL( KMenuCustomisationInterfaceUid,pluginInfo ); |
|
121 TInt pluginCount = pluginInfo.Count(); |
|
122 TRACE("plugincount: %d" ,pluginCount ); |
|
123 |
|
124 for ( TInt pluginIndex(0); pluginIndex < pluginCount; ++pluginIndex ) |
|
125 { |
|
126 TRACE("Inside for loop" ); |
|
127 TUid pluginUid = pluginInfo[pluginIndex]->ImplementationUid(); |
|
128 TRACE("ImplementationUid: %u" ,pluginUid.iUid ); |
|
129 // Creates the plugin and transfers ownership of the services |
|
130 // object to the plugin. |
|
131 CMenuExtension* plugin = NULL; |
|
132 TRAPD(error, plugin = CMenuExtension::CreateImplementationL( pluginUid )); |
|
133 |
|
134 if(KErrNone != error) |
|
135 { |
|
136 // handle the error here. |
|
137 TRACE("error loading the plugin error: %d" ,error ); |
|
138 } |
|
139 else |
|
140 { |
|
141 TRACE("plugin loaded sucessfully" ); |
|
142 //if its here its sure that plugin is not null; |
|
143 CleanupStack::PushL( plugin); |
|
144 |
|
145 TRACE("before mapcommandl" ); |
|
146 //map the plugin commands to servicetab commands, |
|
147 //assings the command maintained in the commandpool, |
|
148 //for more details see |
|
149 MapCommandL(*plugin,pluginUid.iUid); |
|
150 TRACE("after mapcommandl" ); |
|
151 |
|
152 //add the plugin to the array |
|
153 CPluginInfo* newPlugin = new ( ELeave ) CVIMPSTUIMenuExtension::CPluginInfo( plugin, pluginUid); |
|
154 CleanupStack::PushL( newPlugin ); |
|
155 iPlugins.AppendL( newPlugin ); |
|
156 CleanupStack::Pop( newPlugin ); |
|
157 |
|
158 CleanupStack::Pop( plugin ); |
|
159 } |
|
160 |
|
161 } |
|
162 CleanupStack::PopAndDestroy(); |
|
163 |
|
164 |
|
165 |
|
166 } |
|
167 |
|
168 |
|
169 // ---------------------------------------------------------------------------- |
|
170 // CVIMPSTUIMenuExtension::OfferMenuPaneToPluginsL |
|
171 // Generates the list of active plugins |
|
172 // ---------------------------------------------------------------------------- |
|
173 // |
|
174 void CVIMPSTUIMenuExtension::OfferMenuPaneToPlugins(TInt aPreviousId, CEikMenuPane& aMenuPane,TUint aServiceId) |
|
175 { |
|
176 TRACER_AUTO; |
|
177 TRACE(" aServiceId : %u" , aServiceId ); |
|
178 |
|
179 iMenuPane = &aMenuPane; |
|
180 // Get the number of plugins |
|
181 const TInt count = iPlugins.Count(); |
|
182 TRACE(" count : %d" , count ); |
|
183 // Loop though all the command handlers, If DynInitMenuPaneL leaves for one plugin, a plugin |
|
184 // error message will be displayed and the loop will continue with |
|
185 // the next command handler. If none of the plugins leave, there will |
|
186 // be only one TRAP used. |
|
187 for ( TInt index = 0; index < count; ++index ) |
|
188 { |
|
189 TRACE("inside for loop" ); |
|
190 //trap is required if one plugin leaves then it should continue with other plugins. |
|
191 TRAPD(error,iPlugins[index]->Plugin().DynInitMenuPaneL( aPreviousId, |
|
192 aMenuPane,aServiceId,*this )); |
|
193 if(KErrNone != error) |
|
194 { |
|
195 //display the appropriate error note for leaving; |
|
196 TRACE("error by one of plugind dyninitmenupanel" ); |
|
197 } |
|
198 |
|
199 } |
|
200 |
|
201 } |
|
202 // ---------------------------------------------------------------------------- |
|
203 // CVIMPSTUIMenuExtension::OfferHandleCommandToPluginsL |
|
204 // Generates the list of active plugins |
|
205 // ---------------------------------------------------------------------------- |
|
206 // |
|
207 TBool CVIMPSTUIMenuExtension::OfferHandleCommandToPlugins(TInt aCommandId) |
|
208 { |
|
209 TRACER_AUTO; |
|
210 |
|
211 //Get the number of plugins loaded |
|
212 const TInt count = iPlugins.Count(); |
|
213 TRACE("count : %d" ,count ); |
|
214 |
|
215 TBool retval = EFalse; |
|
216 // Loop though all the command handlers, |
|
217 // If HandleCommandL leaves for one plugin, a plugin |
|
218 // error message will be displayed and the loop will continue with |
|
219 // the next plugin. If none of the plugins leave, there will |
|
220 // be only one TRAP used. |
|
221 for ( TInt index = 0; index < count; ++index ) |
|
222 { |
|
223 TRAPD( error,retval = iPlugins[index]->Plugin().HandleCommandL( aCommandId )); |
|
224 |
|
225 if ( KErrNone != error ) |
|
226 { |
|
227 // Report a problem with plugin. |
|
228 } |
|
229 } |
|
230 |
|
231 |
|
232 return retval; |
|
233 } |
|
234 |
|
235 // ---------------------------------------------------------------------------- |
|
236 // CVIMPSTUIMenuExtension::CPluginInfo::CPluginInfo( |
|
237 // C++ constructor |
|
238 // (other items were commented in a header). |
|
239 // ---------------------------------------------------------------------------- |
|
240 // |
|
241 CVIMPSTUIMenuExtension::CPluginInfo::CPluginInfo( |
|
242 CMenuExtension* aPlugin, |
|
243 TUid aPluginUid ) |
|
244 : iPlugin( aPlugin ), |
|
245 iPluginUid( aPluginUid ) |
|
246 { |
|
247 TRACER_AUTO; |
|
248 |
|
249 } |
|
250 // ---------------------------------------------------------------------------- |
|
251 // CVIMPSTUIMenuExtension::CPluginInfo::~CPluginInfo( |
|
252 // C++ destructor |
|
253 // (other items were commented in a header). |
|
254 // ---------------------------------------------------------------------------- |
|
255 // |
|
256 CVIMPSTUIMenuExtension::CPluginInfo::~CPluginInfo() |
|
257 { |
|
258 TRACER_AUTO; |
|
259 delete iPlugin; |
|
260 |
|
261 } |
|
262 |
|
263 // ---------------------------------------------------------------------------- |
|
264 // CVIMPSTUIMenuExtension::CPluginInfo::Plugin |
|
265 // returns a reference to the plugin |
|
266 // (other items were commented in a header). |
|
267 // ---------------------------------------------------------------------------- |
|
268 // |
|
269 CMenuExtension& CVIMPSTUIMenuExtension::CPluginInfo::Plugin() |
|
270 { |
|
271 TRACER_AUTO; |
|
272 return *iPlugin; |
|
273 } |
|
274 |
|
275 |
|
276 // ---------------------------------------------------------------------------- |
|
277 // CVIMPSTUIMenuExtension::MapCommandL |
|
278 // (other items were commented in a header). |
|
279 // ---------------------------------------------------------------------------- |
|
280 // |
|
281 void CVIMPSTUIMenuExtension::MapCommandL( CMenuExtension& aMenuExtension, TInt32 aPluginId ) |
|
282 { |
|
283 TRACER_AUTO; |
|
284 |
|
285 TInt res = aMenuExtension.CommandInfoResource(); |
|
286 if( res != KErrNotFound ) |
|
287 { |
|
288 TResourceReader reader; |
|
289 CCoeEnv::Static()->CreateResourceReaderLC( reader, res ); |
|
290 TInt resCount = reader.ReadInt16(); |
|
291 for( TInt j = 0; j < resCount; j++ ) |
|
292 { |
|
293 CCommandInfo* commandInfo = NULL; |
|
294 commandInfo = CCommandInfo::NewLC( reader, |
|
295 aPluginId, |
|
296 iNewCommands ); |
|
297 User::LeaveIfError( iCommandIdMap.Append( commandInfo ) ); |
|
298 CleanupStack::Pop(); // commandInfo |
|
299 } |
|
300 CleanupStack::PopAndDestroy(); // reader |
|
301 aMenuExtension.RegisterCommandMapper( *this ); |
|
302 |
|
303 } |
|
304 |
|
305 |
|
306 } |
|
307 // ---------------------------------------------------------------------------- |
|
308 // CVIMPSTUIMenuExtension::GetNewCommand |
|
309 // from MComandMapper |
|
310 // ---------------------------------------------------------------------------- |
|
311 // |
|
312 |
|
313 TInt CVIMPSTUIMenuExtension::GetOldCommand( TInt32 aPluginId, TInt aNewCommand, |
|
314 TInt& aOldCommand ) const |
|
315 { |
|
316 TRACER_AUTO; |
|
317 |
|
318 TInt mapCount = iCommandIdMap.Count(); |
|
319 TInt err( KErrNotFound ); |
|
320 //TODO:: optimize searching. |
|
321 for( TInt i = 0; i < mapCount && err; i++ ) |
|
322 { |
|
323 CCommandInfo* info = iCommandIdMap[i]; |
|
324 if( info->PliginId() == aPluginId && info->NewCommandId() == aNewCommand ) |
|
325 { |
|
326 aOldCommand = info->OldCommandId(); |
|
327 err = KErrNone; |
|
328 break; |
|
329 } |
|
330 } |
|
331 |
|
332 |
|
333 return err; |
|
334 } |
|
335 // ---------------------------------------------------------------------------- |
|
336 // CVIMPSTUIMenuExtension::GetNewCommand |
|
337 // from MComandMapper |
|
338 // ---------------------------------------------------------------------------- |
|
339 // |
|
340 |
|
341 TInt CVIMPSTUIMenuExtension::GetNewCommand( TInt32 aPluginId, TInt aOldCommand, |
|
342 TInt& aNewCommand ) const |
|
343 { |
|
344 TRACER_AUTO; |
|
345 |
|
346 TInt mapCount = iCommandIdMap.Count(); |
|
347 TInt err( KErrNotFound ); |
|
348 //TODO:: optimize searching. |
|
349 for( TInt i = 0; i < mapCount && err; i++ ) |
|
350 { |
|
351 CCommandInfo* info = iCommandIdMap[i]; |
|
352 if( info->PliginId() == aPluginId && info->OldCommandId() == aOldCommand ) |
|
353 { |
|
354 aNewCommand = info->NewCommandId(); |
|
355 err = KErrNone; |
|
356 break; |
|
357 } |
|
358 } |
|
359 |
|
360 |
|
361 return err; |
|
362 } |
|
363 // ---------------------------------------------------------------------------- |
|
364 // CVIMPSTUIMenuExtension::AddToAIWCommandMap |
|
365 // ---------------------------------------------------------------------------- |
|
366 // |
|
367 void CVIMPSTUIMenuExtension::AddToAIWCommandMap(TInt aOriginalCommand, TInt aNewCommand) |
|
368 { |
|
369 TRACER_AUTO; |
|
370 TAIWCommandMapTableItem *item = new TAIWCommandMapTableItem(); |
|
371 item->iOriginalCmd = aOriginalCommand; |
|
372 item->iNewCmd = aNewCommand; |
|
373 iAIWCommandMap.Append(item); |
|
374 } |
|
375 // ---------------------------------------------------------------------------- |
|
376 // CVIMPSTUIMenuExtension::GetNewAIWCommand |
|
377 // ---------------------------------------------------------------------------- |
|
378 // |
|
379 TInt CVIMPSTUIMenuExtension::GetNewAIWCommand(TInt aOriginalCommand) |
|
380 { |
|
381 TRACER_AUTO; |
|
382 TInt count = iAIWCommandMap.Count(); |
|
383 for( TInt i=0 ; i<count ; i++ ) |
|
384 { |
|
385 if(iAIWCommandMap[i]->iOriginalCmd == aOriginalCommand) |
|
386 { |
|
387 return iAIWCommandMap[i]->iNewCmd; |
|
388 } |
|
389 } |
|
390 return KErrNotFound; |
|
391 } |
|
392 // ---------------------------------------------------------------------------- |
|
393 // CVIMPSTUIMenuExtension::ResetAIWCommandMap |
|
394 // ---------------------------------------------------------------------------- |
|
395 // |
|
396 void CVIMPSTUIMenuExtension::ResetAIWCommandMap() |
|
397 { |
|
398 iAIWCommandMap.ResetAndDestroy(); |
|
399 } |
|
400 |
|
401 // ---------------------------------------------------------------------------- |
|
402 // CVIMPSTUIMenuExtension::SetAIWItemDimmed |
|
403 // ---------------------------------------------------------------------------- |
|
404 // |
|
405 void CVIMPSTUIMenuExtension::SetAIWItemDimmed(TInt aCommand, TBool aHide) |
|
406 { |
|
407 TRACER_AUTO; |
|
408 TInt cmd = GetNewAIWCommand(aCommand); |
|
409 if(cmd != KErrNotFound) |
|
410 iMenuPane->SetItemDimmed(cmd,aHide); |
|
411 } |
|
412 |
|
413 // End of file |
|