|
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: Photos command handler base class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <glxsingletonstore.h> |
|
22 |
|
23 #include "glxaiwservicehandler.h" |
|
24 #include "glxaiwmedia.h" |
|
25 #include "AiwServiceHandler.h" |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // InstanceL |
|
29 // ----------------------------------------------------------------------------- |
|
30 // |
|
31 CGlxAiwServiceHandler* CGlxAiwServiceHandler::InstanceL() |
|
32 { |
|
33 return CGlxSingletonStore::InstanceL(&NewL); |
|
34 } |
|
35 |
|
36 // ----------------------------------------------------------------------------- |
|
37 // Close |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 void CGlxAiwServiceHandler::Close() |
|
41 { |
|
42 CGlxSingletonStore::Close( this ); |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // NewL |
|
47 // ----------------------------------------------------------------------------- |
|
48 // |
|
49 CGlxAiwServiceHandler* CGlxAiwServiceHandler::NewL() |
|
50 { |
|
51 CGlxAiwServiceHandler* self = new (ELeave) CGlxAiwServiceHandler(); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(self); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // Constructor |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 CGlxAiwServiceHandler::CGlxAiwServiceHandler() |
|
63 { |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // Destructor |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 CGlxAiwServiceHandler::~CGlxAiwServiceHandler() |
|
71 { |
|
72 iAiwMediaArray.ResetAndDestroy(); |
|
73 iAiwMediaArray.Close(); |
|
74 delete iAiwServiceHandler; |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // 2nd phase constructor |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 void CGlxAiwServiceHandler::ConstructL() |
|
82 { |
|
83 iAiwServiceHandler = CAiwServiceHandler::NewL(); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // AddParamL |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 void CGlxAiwServiceHandler::AddParamL(const TGlxMediaId& aId, const TAiwGenericParam& aParam ) |
|
91 { |
|
92 // This method is called to add parameters to the iInParams. |
|
93 // This should be called by each command handler before InitializeMenuPaneL is called at all. |
|
94 // This ensures that the entire list on InParams is built for all command handlers before |
|
95 // initializing the menu. |
|
96 // When InitializeMenuPaneL is called it destroys the inParams making it necessary to |
|
97 // aquire and append to the iInParams again should this be necessary. |
|
98 |
|
99 if ( ENotInitialised != iInitialisedMenu ) |
|
100 { |
|
101 // This is either the very first time or the first time since calling InitializeMenuPaneL |
|
102 iInitialisedMenu = ENotInitialised; |
|
103 // Set iInParams to Null. This will force a call to the service Handler to aquire |
|
104 // the pointer to the new set of InParams (yet to be appended too). |
|
105 iInParams = NULL; |
|
106 } |
|
107 |
|
108 if (!iInParams) |
|
109 { |
|
110 // Must aquire a pointer to the new set of InParams |
|
111 iInParams = &iAiwServiceHandler->InParamListL(); |
|
112 } |
|
113 |
|
114 // Get the Index of the TGlxMediaId in the array |
|
115 TInt index = FindId(aId); |
|
116 CGlxAiwMedia* media = NULL; |
|
117 |
|
118 if (KErrNotFound == index) |
|
119 { |
|
120 // The TGlxMediaId was not found. so create a new entry |
|
121 media = new (ELeave) CGlxAiwMedia(aId); |
|
122 CleanupStack::PushL(media); |
|
123 TLinearOrder<CGlxAiwMedia> orderer (&AiwMediaOrderById); |
|
124 iAiwMediaArray.InsertInOrderL(media, orderer); |
|
125 CleanupStack::Pop(media); |
|
126 } |
|
127 else |
|
128 { |
|
129 // The TGlxMediaId was found so use the current entry |
|
130 media = iAiwMediaArray[index]; |
|
131 } |
|
132 |
|
133 // Add the parameter (method checks for duplicates. |
|
134 media->AddParamL(aParam); |
|
135 |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // FindId |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 TInt CGlxAiwServiceHandler::FindId(const TGlxMediaId& aId) |
|
143 { |
|
144 // Now we can find the CGlxAiwMedia in the list with an Id equal to aId |
|
145 TInt index = iAiwMediaArray.FindInOrder(aId, (&AiwMediaOrderByMediaId)); |
|
146 |
|
147 return index; |
|
148 |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // AiwMediaOrderByMediaId (static method) |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 TInt CGlxAiwServiceHandler::AiwMediaOrderByMediaId( const TGlxMediaId* aMediaId, const CGlxAiwMedia& aAiwMedia ) |
|
156 { |
|
157 const TGlxMediaId& Id = aAiwMedia.Id(); |
|
158 |
|
159 if (*aMediaId < Id) |
|
160 { |
|
161 return -1; |
|
162 } |
|
163 if (*aMediaId > Id) |
|
164 { |
|
165 return 1; |
|
166 } |
|
167 |
|
168 return 0; |
|
169 } |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // AiwMediaOrderById (static method) |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 TInt CGlxAiwServiceHandler::AiwMediaOrderById( const CGlxAiwMedia& aAiwMedia1, const CGlxAiwMedia& aAiwMedia2 ) |
|
176 { |
|
177 const TGlxMediaId& mediaId = aAiwMedia1.Id(); |
|
178 |
|
179 return AiwMediaOrderByMediaId(&mediaId, aAiwMedia2); |
|
180 } |
|
181 |
|
182 // ----------------------------------------------------------------------------- |
|
183 // AppendInParamsL |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 void CGlxAiwServiceHandler::AppendInParamsL() |
|
187 { |
|
188 // Iterate through array backwards because removing the last tem causes |
|
189 // little effort. |
|
190 |
|
191 TInt count = 0; |
|
192 |
|
193 while ((count = iAiwMediaArray.Count()) > 0) |
|
194 { |
|
195 // get the last element |
|
196 CGlxAiwMedia* media = iAiwMediaArray[count - 1]; |
|
197 |
|
198 // Now get all the parameters associated with the element |
|
199 media->AppendToInParamsL(*iInParams); |
|
200 |
|
201 // Remove it from array |
|
202 iAiwMediaArray.Remove(count - 1); |
|
203 // Destroy the CGlxAiwMedia |
|
204 delete media; |
|
205 } |
|
206 // Tidy up the array |
|
207 iAiwMediaArray.ResetAndDestroy(); |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // ResetMenuInitialisedFlag |
|
212 // ----------------------------------------------------------------------------- |
|
213 // |
|
214 void CGlxAiwServiceHandler::ResetMenuInitialisedFlag() |
|
215 { |
|
216 iInitialisedMenu = ENotInitialised; |
|
217 // Also set params list to NULL before creating new params list |
|
218 iInParams = NULL; |
|
219 } |
|
220 |
|
221 // ----------------------------------------------------------------------------- |
|
222 // InitializeMenuPaneL |
|
223 // ----------------------------------------------------------------------------- |
|
224 // |
|
225 void CGlxAiwServiceHandler::InitializeMenuPaneL(CEikMenuPane& aMenuPane, TInt aResourceId, TInt aBaseMenuCmdId) |
|
226 { |
|
227 // All the parameters for all command handlers should now be appended in iInParams |
|
228 // Calling InitializeMenuPaneL will destroy the values in iInParams. Hence the need to |
|
229 // record when this is done by using iIsMenuInitialized. |
|
230 |
|
231 if ( ENotInitialised == iInitialisedMenu ) |
|
232 { |
|
233 AppendInParamsL(); |
|
234 |
|
235 if(iInParams) |
|
236 { |
|
237 iAiwServiceHandler->InitializeMenuPaneL(aMenuPane, aResourceId, aBaseMenuCmdId, *iInParams); |
|
238 } |
|
239 |
|
240 iInitialisedMenu = EMainMenuInitialised; |
|
241 } |
|
242 } |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // AttachMenuL |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 void CGlxAiwServiceHandler::AttachMenuL(TInt aMenuResource, TInt aAiwInterestResource) |
|
249 { |
|
250 iAiwServiceHandler->AttachMenuL( aMenuResource, aAiwInterestResource ); |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // IsSameCommand |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 TBool CGlxAiwServiceHandler::IsSameCommand(TInt aCommandId, TInt aAiwCommandId) |
|
258 { |
|
259 return ( iAiwServiceHandler->ServiceCmdByMenuCmd( aCommandId ) == aAiwCommandId ); |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // ExecuteMenuCmdL |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 void CGlxAiwServiceHandler::ExecuteMenuCmdL(TInt aMenuCmdId, TUint aCmdOptions, MAiwNotifyCallback* aCallback) |
|
267 { |
|
268 CAiwGenericParamList& outParams = iAiwServiceHandler->OutParamListL(); |
|
269 |
|
270 iAiwServiceHandler->ExecuteMenuCmdL(aMenuCmdId, *iInParams, outParams, aCmdOptions, aCallback); |
|
271 } |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // HandleSubmenuL |
|
275 // ----------------------------------------------------------------------------- |
|
276 // |
|
277 |
|
278 TBool CGlxAiwServiceHandler::HandleSubmenuL(CEikMenuPane& aPane) |
|
279 { |
|
280 // If main menu is initialize then only check for submenu |
|
281 if ( EMainMenuInitialised == iInitialisedMenu ) |
|
282 { |
|
283 if ( iAiwServiceHandler->HandleSubmenuL(aPane) ) |
|
284 { |
|
285 iInitialisedMenu = ESubMenuInitialised; |
|
286 } |
|
287 } |
|
288 return ( ESubMenuInitialised == iInitialisedMenu ); |
|
289 } |
|
290 |
|
291 // ----------------------------------------------------------------------------- |
|
292 // IsAiwMenu |
|
293 // ----------------------------------------------------------------------------- |
|
294 // |
|
295 TBool CGlxAiwServiceHandler::IsAiwMenu(TInt aMenuResourceId) |
|
296 { |
|
297 return iAiwServiceHandler->IsAiwMenu(aMenuResourceId); |
|
298 } |
|
299 |
|
300 // ----------------------------------------------------------------------------- |
|
301 // GetInParams (for testing only) |
|
302 // ----------------------------------------------------------------------------- |
|
303 // |
|
304 CAiwGenericParamList& CGlxAiwServiceHandler::GetInParams() |
|
305 { |
|
306 return *iInParams; |
|
307 } |
|
308 |
|
309 |
|
310 |