|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 |
|
20 #include "menuhandlereng.h" |
|
21 #include "mcsmenuhandler.h" |
|
22 #include "mcsmenuhandlerplugin.h" |
|
23 #include "mcsmenuhandlerplugin.hrh" |
|
24 #include "mcsdef.h" |
|
25 #include "mcsmenuitem.h" |
|
26 #include "menuuid.hrh" |
|
27 |
|
28 // ================= MEMBER FUNCTIONS ======================= |
|
29 |
|
30 /** |
|
31 * Cleanupstack support method, calls RImplInfoPtrArray::ResetAndDestroy() |
|
32 * of the passed argument (array). |
|
33 * @param aArray Array. |
|
34 */ |
|
35 LOCAL_C void ResetAndDestroyArray( TAny* aArray ) |
|
36 { |
|
37 ((RImplInfoPtrArray*)aArray)->ResetAndDestroy(); |
|
38 } |
|
39 |
|
40 |
|
41 // ================= MEMBER FUNCTIONS ======================= |
|
42 |
|
43 // --------------------------------------------------------- |
|
44 // CMenuHandlerEng::~CMenuHandlerEng |
|
45 // --------------------------------------------------------- |
|
46 // |
|
47 CMenuHandlerEng::~CMenuHandlerEng() |
|
48 { |
|
49 iHandlers.ResetAndDestroy(); |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------- |
|
53 // CMenuHandlerEng::NewL |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 CMenuHandlerEng* CMenuHandlerEng::NewL( RMenu& aMenu ) |
|
57 { |
|
58 CMenuHandlerEng* eng = new (ELeave) CMenuHandlerEng( aMenu ); |
|
59 return eng; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------- |
|
63 // CMenuHandlerEng::CMenuHandlerEng |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 CMenuHandlerEng::CMenuHandlerEng( RMenu& aMenu ): iMenu( aMenu ) |
|
67 { |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------- |
|
71 // CMenuHandlerEng::HandleCommandL |
|
72 // --------------------------------------------------------- |
|
73 // |
|
74 CMenuOperation* CMenuHandlerEng::HandleCommandL( |
|
75 CMenuItem& aItem, |
|
76 const TDesC8& aCommand, |
|
77 const TDesC8& aParams, |
|
78 TRequestStatus& aStatus ) |
|
79 { |
|
80 // Currently, we load handlers on demand and never unload them. |
|
81 // As there aren't many types of items, this seems appropriate. |
|
82 CMenuHandler* handler = FindHandler( aItem.Type() ); |
|
83 if ( !handler ) |
|
84 { |
|
85 handler = LoadHandlerL( aItem.Type() ); |
|
86 } |
|
87 if ( handler ) |
|
88 { |
|
89 return handler->HandleCommandL( aItem, aCommand, aParams, aStatus ); |
|
90 } |
|
91 User::Leave( KErrNotSupported ); |
|
92 return NULL; |
|
93 } |
|
94 |
|
95 // --------------------------------------------------------- |
|
96 // CMenuHandlerEng::FindHandler |
|
97 // --------------------------------------------------------- |
|
98 // |
|
99 CMenuHandler* CMenuHandlerEng::FindHandler( const TDesC& aType ) |
|
100 { |
|
101 for ( TInt i = 0; i < iHandlers.Count(); i++ ) |
|
102 { |
|
103 CMenuHandler* handler = iHandlers[i]; |
|
104 if ( handler->SupportsType( aType ) ) |
|
105 { |
|
106 return handler; |
|
107 } |
|
108 } |
|
109 return NULL; |
|
110 } |
|
111 |
|
112 // --------------------------------------------------------- |
|
113 // CMenuHandlerEng::LoadHandlerL |
|
114 // --------------------------------------------------------- |
|
115 // |
|
116 CMenuHandler* CMenuHandlerEng::LoadHandlerL( const TDesC& aType ) |
|
117 { |
|
118 CMenuHandlerPlugin* handler = NULL; |
|
119 TBuf8<KMenuMaxTypeLen> type; |
|
120 type.Copy( aType ); |
|
121 TEComResolverParams resolverParams; |
|
122 resolverParams.SetDataType( type ); |
|
123 RImplInfoPtrArray implInfoArray; |
|
124 CleanupStack::PushL( TCleanupItem( ResetAndDestroyArray, &implInfoArray ) ); |
|
125 REComSession::ListImplementationsL |
|
126 ( TUid::Uid( MENU_HANDLER_IF_UID ), resolverParams, implInfoArray ); |
|
127 |
|
128 __ASSERT_DEBUG( implInfoArray.Count() <= 1, User::Invariant() ); |
|
129 |
|
130 if ( implInfoArray.Count() != 0 ) |
|
131 { |
|
132 TUid implUid = implInfoArray[ 0 ]->ImplementationUid(); |
|
133 handler = CMenuHandlerPlugin::NewL( implUid, iMenu ); |
|
134 CleanupStack::PushL( handler ); |
|
135 // Here we check if this is the handler we need. Currently we only do |
|
136 // a sanity check for the handler (it should support the registered |
|
137 // types!), but later this can be extended with better support query. |
|
138 // E.g. support for type AND command, etc. |
|
139 if ( handler->SupportsType( aType ) ) |
|
140 { |
|
141 iHandlers.AppendL( handler ); |
|
142 CleanupStack::Pop( handler ); |
|
143 } |
|
144 else |
|
145 { |
|
146 CleanupStack::PopAndDestroy( handler ); |
|
147 handler = NULL; |
|
148 } |
|
149 } |
|
150 |
|
151 CleanupStack::PopAndDestroy( &implInfoArray ); |
|
152 return handler; |
|
153 } |