29
|
1 |
/*
|
|
2 |
* Copyright (c) 2007-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: Class that provides centralized access for UI classes
|
|
15 |
* to logic handling
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
|
|
21 |
#include <eikenv.h>
|
|
22 |
#include <coeaui.h>
|
|
23 |
#include <coemain.h>
|
|
24 |
#include <barsread.h>
|
|
25 |
#include <eikmenup.h>
|
|
26 |
|
|
27 |
|
|
28 |
#include "cimcvmenuextensionmanager.h"
|
|
29 |
#include "cimcvcommandinfo.h"
|
|
30 |
|
|
31 |
#include "cvmenucommandinfo.hrh"
|
|
32 |
#include "vimpstcustomcleanupapi.h"
|
|
33 |
|
|
34 |
|
|
35 |
// ================= MEMBER FUNCTIONS =======================
|
|
36 |
|
|
37 |
// ---------------------------------------------------------------------------
|
|
38 |
// CIMCVMenuExtensionManager::CIMCVMenuExtensionManager
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
//
|
|
41 |
CIMCVMenuExtensionManager::CIMCVMenuExtensionManager( )
|
|
42 |
: iNewCommands( ECVMenuExtensionFirstFreeCommand )
|
|
43 |
{
|
|
44 |
|
|
45 |
}
|
|
46 |
|
|
47 |
// ---------------------------------------------------------------------------
|
|
48 |
// CIMCVMenuExtensionManager::ConstructL
|
|
49 |
// ---------------------------------------------------------------------------
|
|
50 |
//
|
|
51 |
void CIMCVMenuExtensionManager::ConstructL()
|
|
52 |
{
|
|
53 |
LoadPluginL( );
|
|
54 |
}
|
|
55 |
|
|
56 |
// ---------------------------------------------------------------------------
|
|
57 |
// CIMCVMenuExtensionManager::NewL
|
|
58 |
// ---------------------------------------------------------------------------
|
|
59 |
//
|
|
60 |
CIMCVMenuExtensionManager* CIMCVMenuExtensionManager::NewL( )
|
|
61 |
{
|
|
62 |
CIMCVMenuExtensionManager* self = NewLC( );
|
|
63 |
CleanupStack::Pop(self);
|
|
64 |
return self;
|
|
65 |
}
|
|
66 |
|
|
67 |
// ---------------------------------------------------------------------------
|
|
68 |
// CIMCVMenuExtensionManager::NewLC
|
|
69 |
// ---------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
CIMCVMenuExtensionManager* CIMCVMenuExtensionManager::NewLC()
|
|
72 |
{
|
|
73 |
CIMCVMenuExtensionManager* self =
|
|
74 |
new (ELeave) CIMCVMenuExtensionManager( );
|
|
75 |
CleanupStack::PushL( self );
|
|
76 |
self->ConstructL();
|
|
77 |
return self;
|
|
78 |
}
|
|
79 |
|
|
80 |
// ---------------------------------------------------------------------------
|
|
81 |
// CIMCVMenuExtensionManager::~CIMCVMenuExtensionManager
|
|
82 |
// ---------------------------------------------------------------------------
|
|
83 |
//
|
|
84 |
CIMCVMenuExtensionManager::~CIMCVMenuExtensionManager()
|
|
85 |
{
|
|
86 |
iCommandIdMap.ResetAndDestroy();
|
|
87 |
iCommandIdMap.Close();
|
|
88 |
// Reset and destroy the contents of the owned arrays,
|
|
89 |
// this will delete the plugins.
|
|
90 |
iPlugins.ResetAndDestroy();
|
|
91 |
iPlugins.Close();
|
|
92 |
|
|
93 |
// Close the ECOM interface
|
|
94 |
REComSession::FinalClose();
|
|
95 |
}
|
|
96 |
|
|
97 |
// ----------------------------------------------------------------------------
|
|
98 |
// CIMCVMenuExtensionManager::LoadPluginL
|
|
99 |
// Loads all plugins
|
|
100 |
// (other items were commented in a header).
|
|
101 |
// ----------------------------------------------------------------------------
|
|
102 |
//
|
|
103 |
void CIMCVMenuExtensionManager::LoadPluginL( )
|
|
104 |
{
|
|
105 |
// plugininfo array, Owned
|
|
106 |
RImplInfoPtrArray pluginInfo;
|
|
107 |
CustomCleanupResetAndDestroyPushL(pluginInfo);
|
|
108 |
iPlugins.ResetAndDestroy();
|
|
109 |
REComSession::ListImplementationsL( KMenuCustomisationInterfaceUid,pluginInfo );
|
|
110 |
TInt pluginCount = pluginInfo.Count();
|
|
111 |
|
|
112 |
for ( TInt pluginIndex(0); pluginIndex < pluginCount; ++pluginIndex )
|
|
113 |
{
|
|
114 |
TUid pluginUid = pluginInfo[pluginIndex]->ImplementationUid();
|
|
115 |
// Creates the plugin and transfers ownership of the services
|
|
116 |
// object to the plugin.
|
|
117 |
CIMCVMenuExtension* plugin = NULL;
|
|
118 |
TRAPD(error, plugin = CIMCVMenuExtension::CreateImplementationL( pluginUid ));
|
|
119 |
|
|
120 |
if(KErrNone != error)
|
|
121 |
{
|
|
122 |
// handle the error here.
|
|
123 |
}
|
|
124 |
else
|
|
125 |
{
|
|
126 |
//if its here its sure that plugin is not null;
|
|
127 |
CleanupStack::PushL( plugin);
|
|
128 |
|
|
129 |
//map the plugin commands to CV commands,
|
|
130 |
//assings the command maintained in the commandpool,
|
|
131 |
//for more details see
|
|
132 |
MapCommandL(*plugin,pluginUid.iUid);
|
|
133 |
|
|
134 |
//add the plugin to the array
|
|
135 |
CPluginInfo* newPlugin = new ( ELeave ) CIMCVMenuExtensionManager::CPluginInfo( plugin, pluginUid);
|
|
136 |
CleanupStack::PushL( newPlugin );
|
|
137 |
iPlugins.AppendL( newPlugin );
|
|
138 |
CleanupStack::Pop( newPlugin );
|
|
139 |
|
|
140 |
CleanupStack::Pop( plugin );
|
|
141 |
}
|
|
142 |
|
|
143 |
}
|
|
144 |
|
|
145 |
CleanupStack::PopAndDestroy();
|
|
146 |
|
|
147 |
}
|
|
148 |
|
|
149 |
|
|
150 |
// ----------------------------------------------------------------------------
|
|
151 |
// CIMCVMenuExtensionManager::OfferMenuPaneToPluginsL
|
|
152 |
// Generates the list of active plugins
|
|
153 |
// ----------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
void CIMCVMenuExtensionManager::OfferMenuPaneToPlugins(TInt aPreviousId, CEikMenuPane& aMenuPane,TUint aServiceId)
|
|
156 |
{
|
|
157 |
// Get the number of plugins
|
|
158 |
const TInt count = iPlugins.Count();
|
|
159 |
// Loop though all the command handlers, If DynInitMenuPaneL leaves for one plugin, a plugin
|
|
160 |
// error message will be displayed and the loop will continue with
|
|
161 |
// the next command handler. If none of the plugins leave, there will
|
|
162 |
// be only one TRAP used.
|
|
163 |
for ( TInt index = 0; index < count; ++index )
|
|
164 |
{
|
|
165 |
//trap is required if one plugin leaves then it should continue with other plugins.
|
|
166 |
TRAPD(error,iPlugins[index]->Plugin().DynInitMenuPaneL( aPreviousId,
|
|
167 |
aMenuPane,aServiceId ));
|
|
168 |
if(KErrNone != error)
|
|
169 |
{
|
|
170 |
//display the appropriate error note for leaving;
|
|
171 |
}
|
|
172 |
|
|
173 |
}
|
|
174 |
|
|
175 |
}
|
|
176 |
// ----------------------------------------------------------------------------
|
|
177 |
// CIMCVMenuExtensionManager::OfferHandleCommandToPluginsL
|
|
178 |
// Generates the list of active plugins
|
|
179 |
// ----------------------------------------------------------------------------
|
|
180 |
//
|
|
181 |
TBool CIMCVMenuExtensionManager::OfferHandleCommandToPlugins(TInt aCommandId)
|
|
182 |
{
|
|
183 |
//Get the number of plugins loaded
|
|
184 |
const TInt count = iPlugins.Count();
|
|
185 |
|
|
186 |
TBool retval = EFalse;
|
|
187 |
// Loop though all the command handlers,
|
|
188 |
// If HandleCommandL leaves for one plugin, a plugin
|
|
189 |
// error message will be displayed and the loop will continue with
|
|
190 |
// the next plugin. If none of the plugins leave, there will
|
|
191 |
// be only one TRAP used.
|
|
192 |
for ( TInt index = 0; index < count; ++index )
|
|
193 |
{
|
|
194 |
TRAPD( error,retval = iPlugins[index]->Plugin().HandleCommandL( aCommandId ));
|
|
195 |
|
|
196 |
if ( KErrNone != error )
|
|
197 |
{
|
|
198 |
// Report a problem with plugin.
|
|
199 |
}
|
|
200 |
}
|
|
201 |
return retval;
|
|
202 |
}
|
|
203 |
|
|
204 |
// ----------------------------------------------------------------------------
|
|
205 |
// CIMCVMenuExtensionManager::CPluginInfo::CPluginInfo(
|
|
206 |
// C++ constructor
|
|
207 |
// (other items were commented in a header).
|
|
208 |
// ----------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
CIMCVMenuExtensionManager::CPluginInfo::CPluginInfo(
|
|
211 |
CIMCVMenuExtension* aPlugin,
|
|
212 |
TUid aPluginUid )
|
|
213 |
: iPlugin( aPlugin ),
|
|
214 |
iPluginUid( aPluginUid )
|
|
215 |
{
|
|
216 |
|
|
217 |
}
|
|
218 |
// ----------------------------------------------------------------------------
|
|
219 |
// CIMCVMenuExtensionManager::CPluginInfo::~CPluginInfo(
|
|
220 |
// C++ destructor
|
|
221 |
// (other items were commented in a header).
|
|
222 |
// ----------------------------------------------------------------------------
|
|
223 |
//
|
|
224 |
|
|
225 |
CIMCVMenuExtensionManager::CPluginInfo::~CPluginInfo()
|
|
226 |
{
|
|
227 |
delete iPlugin;
|
|
228 |
}
|
|
229 |
|
|
230 |
// ----------------------------------------------------------------------------
|
|
231 |
// CIMCVMenuExtensionManager::CPluginInfo::Plugin
|
|
232 |
// returns a reference to the plugin
|
|
233 |
// (other items were commented in a header).
|
|
234 |
// ----------------------------------------------------------------------------
|
|
235 |
//
|
|
236 |
CIMCVMenuExtension& CIMCVMenuExtensionManager::CPluginInfo::Plugin()
|
|
237 |
{
|
|
238 |
return *iPlugin;
|
|
239 |
}
|
|
240 |
|
|
241 |
|
|
242 |
// ----------------------------------------------------------------------------
|
|
243 |
// CIMCVMenuExtensionManager::MapCommandL
|
|
244 |
// (other items were commented in a header).
|
|
245 |
// ----------------------------------------------------------------------------
|
|
246 |
//
|
|
247 |
void CIMCVMenuExtensionManager::MapCommandL( CIMCVMenuExtension& aMenuExtension, TInt32 aPluginId )
|
|
248 |
{
|
|
249 |
TInt res = aMenuExtension.CommandInfoResource();
|
|
250 |
if( res != KErrNotFound )
|
|
251 |
{
|
|
252 |
TResourceReader reader;
|
|
253 |
CCoeEnv::Static()->CreateResourceReaderLC( reader, res );
|
|
254 |
TInt resCount = reader.ReadInt16();
|
|
255 |
for( TInt j = 0; j < resCount; j++ )
|
|
256 |
{
|
|
257 |
CIMCVCommandInfo* commandInfo = NULL;
|
|
258 |
commandInfo = CIMCVCommandInfo::NewLC( reader,
|
|
259 |
aPluginId,
|
|
260 |
iNewCommands );
|
|
261 |
User::LeaveIfError( iCommandIdMap.Append( commandInfo ) );
|
|
262 |
CleanupStack::Pop(); // commandInfo
|
|
263 |
}
|
|
264 |
CleanupStack::PopAndDestroy(); // reader
|
|
265 |
aMenuExtension.RegisterCommandMapper( *this );
|
|
266 |
|
|
267 |
}
|
|
268 |
}
|
|
269 |
// ----------------------------------------------------------------------------
|
|
270 |
// CIMCVMenuExtensionManager::GetNewCommand
|
|
271 |
// from MComandMapper
|
|
272 |
// ----------------------------------------------------------------------------
|
|
273 |
//
|
|
274 |
|
|
275 |
TInt CIMCVMenuExtensionManager::GetOldCommand( TInt32 aPluginId, TInt aNewCommand,
|
|
276 |
TInt& aOldCommand ) const
|
|
277 |
{
|
|
278 |
TInt mapCount = iCommandIdMap.Count();
|
|
279 |
TInt err( KErrNotFound );
|
|
280 |
for( TInt i = 0; i < mapCount && err; i++ )
|
|
281 |
{
|
|
282 |
CIMCVCommandInfo* info = iCommandIdMap[i];
|
|
283 |
if( info->PluginId() == aPluginId && info->NewCommandId() == aNewCommand )
|
|
284 |
{
|
|
285 |
aOldCommand = info->OldCommandId();
|
|
286 |
err = KErrNone;
|
|
287 |
break;
|
|
288 |
}
|
|
289 |
}
|
|
290 |
return err;
|
|
291 |
}
|
|
292 |
// ----------------------------------------------------------------------------
|
|
293 |
// CIMCVMenuExtensionManager::GetNewCommand
|
|
294 |
// from MComandMapper
|
|
295 |
// ----------------------------------------------------------------------------
|
|
296 |
//
|
|
297 |
|
|
298 |
TInt CIMCVMenuExtensionManager::GetNewCommand( TInt32 aPluginId, TInt aOldCommand,
|
|
299 |
TInt& aNewCommand ) const
|
|
300 |
{
|
|
301 |
TInt mapCount = iCommandIdMap.Count();
|
|
302 |
TInt err( KErrNotFound );
|
|
303 |
|
|
304 |
for( TInt i = 0; i < mapCount && err; i++ )
|
|
305 |
{
|
|
306 |
CIMCVCommandInfo* info = iCommandIdMap[i];
|
|
307 |
if( info->PluginId() == aPluginId && info->OldCommandId() == aOldCommand )
|
|
308 |
{
|
|
309 |
aNewCommand = info->NewCommandId();
|
|
310 |
err = KErrNone;
|
|
311 |
break;
|
|
312 |
}
|
|
313 |
}
|
|
314 |
|
|
315 |
return err;
|
|
316 |
}
|
|
317 |
|
|
318 |
|
|
319 |
// End of file
|