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