|
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: Interface to MCS service |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "mcsdef.h" |
|
20 |
|
21 #include "mcsservice.h" |
|
22 #include "mcsgetlistimpl.h" |
|
23 #include "mcsexecuteaction.h" |
|
24 #include "mcsrunningapps.h" |
|
25 #include "mcsrequestnotification.h" |
|
26 #include "mcscallback.h" |
|
27 #include "mcsconstants.h" |
|
28 #include "debug.h" |
|
29 #include "mcsupdateitem.h" |
|
30 #include "mcsdeleteitem.h" |
|
31 #include "mcsorganizeimpl.h" |
|
32 //_LIT( KRunningStatus, "RunningStatus" ); |
|
33 |
|
34 // --------------------------------------------------------------------------- |
|
35 // Two-phased constructor. |
|
36 // --------------------------------------------------------------------------- |
|
37 // |
|
38 EXPORT_C CMCSService* CMCSService::NewL(const TDesC& aContent) |
|
39 { |
|
40 CMCSService* self = new (ELeave) CMCSService; |
|
41 CleanupStack::PushL( self ); |
|
42 self->ConstructL(aContent); |
|
43 CleanupStack::Pop( self ); |
|
44 return self; |
|
45 } |
|
46 |
|
47 // --------------------------------------------------------------------------- |
|
48 // Destructor. |
|
49 // --------------------------------------------------------------------------- |
|
50 // |
|
51 CMCSService::~CMCSService() |
|
52 { |
|
53 if( iReqNotifier ) |
|
54 { |
|
55 TRAP_IGNORE(iReqNotifier->StopNotificationL()); |
|
56 delete iReqNotifier; |
|
57 iReqNotifier = NULL; |
|
58 } |
|
59 iOperationManager.Close(); |
|
60 iMCS.Close(); |
|
61 delete iIgnoredAttributes; |
|
62 delete iRequiredAttributes; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // Constructor. |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 CMCSService::CMCSService() |
|
70 { |
|
71 } |
|
72 |
|
73 // --------------------------------------------------------------------------- |
|
74 // Two-phased constructor. |
|
75 // --------------------------------------------------------------------------- |
|
76 // |
|
77 void CMCSService::ConstructL(const TDesC& aContent) |
|
78 { |
|
79 iMCS.OpenL(aContent); |
|
80 iIsRegistered = EFalse; |
|
81 |
|
82 iIgnoredAttributes = new (ELeave) CDesC16ArrayFlat(1); |
|
83 iRequiredAttributes = new (ELeave) CDesC16ArrayFlat(8); |
|
84 } |
|
85 |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 // --------------------------------------------------------------------------- |
|
89 // |
|
90 void CMCSService::SetFlagInMenuitemL( CLiwMap& aInputMap, |
|
91 CMenuItem& aMenuitem, TMenuItem::TFlags aFlag) |
|
92 { |
|
93 TLiwVariant param; |
|
94 TPtrC8 key ( KNullDesC8 ); |
|
95 switch ( aFlag ) |
|
96 { |
|
97 case TMenuItem::ELockDelete: |
|
98 key.Set( KDeleteLocked ); |
|
99 break; |
|
100 case TMenuItem::ELockName: |
|
101 key.Set( KNameLocked ); |
|
102 break; |
|
103 case TMenuItem::ELockIcon: |
|
104 key.Set( KIconLocked ); |
|
105 break; |
|
106 case TMenuItem::ELockMoveInto: |
|
107 key.Set( KMoveLocked ); |
|
108 break; |
|
109 case TMenuItem::ELockItem: |
|
110 key.Set( KAddingLocked ); |
|
111 break; |
|
112 case TMenuItem::EHidden: |
|
113 key.Set( KHidden ); |
|
114 break; |
|
115 case TMenuItem::EMissing: |
|
116 key.Set( KMissing ); |
|
117 break; |
|
118 } |
|
119 if( aInputMap.FindL( key, param)) |
|
120 { |
|
121 if (param.AsTBool()) |
|
122 { |
|
123 aMenuitem.SetFlags(aFlag, ETrue); |
|
124 } |
|
125 else |
|
126 { |
|
127 aMenuitem.SetFlags(aFlag, EFalse); |
|
128 } |
|
129 aInputMap.Remove( key ); |
|
130 param.Reset(); |
|
131 } |
|
132 |
|
133 } |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // Update item and its attributes. |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 EXPORT_C void CMCSService::UpdateItemL(MMCSCallback* aCallBack, TDesC& aType, |
|
140 TInt aId, TInt aParentId, TInt aBeforeId, CLiwMap& aInputMap) |
|
141 { |
|
142 TBuf8<KMenuMaxAttrNameLen> attrname; |
|
143 TBuf16<KMenuMaxAttrNameLen> attrname16; |
|
144 TBuf16<KMenuMaxAttrValueLen> paramValStr; |
|
145 TPtrC paramvalue; |
|
146 TLiwVariant param; |
|
147 |
|
148 if( !aCallBack ) |
|
149 { |
|
150 User::Leave( KErrArgument ); |
|
151 } |
|
152 CMenuItem* menuItem; |
|
153 |
|
154 // If if is zero then create new menu item |
|
155 if (!aId) |
|
156 { |
|
157 menuItem = CMenuItem::CreateL( iMCS, aType, aParentId, aBeforeId ); |
|
158 } |
|
159 // Otherwise open existing menu item |
|
160 else |
|
161 { |
|
162 menuItem = CMenuItem::OpenL(iMCS, aId); |
|
163 } |
|
164 CleanupStack::PushL( menuItem ); |
|
165 |
|
166 attrname.Copy(KMenuAttrRefId()); |
|
167 if( aInputMap.FindL( attrname, param)) |
|
168 { |
|
169 paramValStr.Num( param.AsTInt32()); |
|
170 aInputMap.Remove(attrname); |
|
171 menuItem->SetAttributeL(KMenuAttrRefId(), paramValStr); |
|
172 } |
|
173 else |
|
174 { |
|
175 if( aType == KMenuTypeLink) |
|
176 { |
|
177 User::Leave( KErrArgument ); |
|
178 } |
|
179 } |
|
180 param.Reset(); |
|
181 |
|
182 // Flags parsing |
|
183 SetFlagInMenuitemL( aInputMap, *menuItem, TMenuItem::ELockName); |
|
184 SetFlagInMenuitemL( aInputMap, *menuItem, TMenuItem::ELockIcon); |
|
185 SetFlagInMenuitemL( aInputMap, *menuItem, TMenuItem::ELockDelete); |
|
186 SetFlagInMenuitemL( aInputMap, *menuItem, TMenuItem::ELockMoveInto); |
|
187 SetFlagInMenuitemL( aInputMap, *menuItem, TMenuItem::ELockItem); |
|
188 SetFlagInMenuitemL( aInputMap, *menuItem, TMenuItem::EHidden); |
|
189 SetFlagInMenuitemL( aInputMap, *menuItem, TMenuItem::EMissing); |
|
190 |
|
191 for(TInt index = 0; index < aInputMap.Count(); index++) |
|
192 { |
|
193 aInputMap.AtL(index, attrname); |
|
194 aInputMap.FindL( attrname, param); |
|
195 paramvalue.Set(param.AsDes()); |
|
196 attrname16.Copy(attrname); |
|
197 menuItem->SetAttributeL( attrname16, paramvalue ); |
|
198 param.Reset(); |
|
199 } |
|
200 |
|
201 CMCSUpdateItem* updateAO = CMCSUpdateItem::NewL( *menuItem, aCallBack, |
|
202 iOperationManager ); |
|
203 CleanupStack::PushL( updateAO ); |
|
204 iOperationManager.AddL( updateAO ); |
|
205 CleanupStack::Pop(updateAO); |
|
206 updateAO->UpdateItemL(); |
|
207 |
|
208 CleanupStack::Pop(menuItem); |
|
209 } |
|
210 |
|
211 // --------------------------------------------------------------------------- |
|
212 // GetListL |
|
213 // --------------------------------------------------------------------------- |
|
214 // |
|
215 EXPORT_C void CMCSService::GetListL( const CLiwGenericParamList& aInParamList, MMCSCallback* aCallBack ) |
|
216 { |
|
217 if( !aCallBack ) |
|
218 { |
|
219 User::Leave( KErrArgument ); |
|
220 } |
|
221 CMCSGetListImpl* getListAO = CMCSGetListImpl::NewL( iMCS, aCallBack, |
|
222 iOperationManager ); |
|
223 CleanupStack::PushL(getListAO); |
|
224 iOperationManager.AddL( getListAO ); |
|
225 CleanupStack::Pop(getListAO); |
|
226 getListAO->GetListL( aInParamList ); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // GetRunningAppsL |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 EXPORT_C void CMCSService::GetRunningAppsL( MMCSCallback* aCallback ) |
|
234 { |
|
235 if( !aCallback ) |
|
236 { |
|
237 User::Leave( KErrArgument ); |
|
238 } |
|
239 |
|
240 CMCSRunningApps* getRunningAppsAO = CMCSRunningApps::NewL( iMCS, aCallback, |
|
241 iOperationManager ); |
|
242 CleanupStack::PushL(getRunningAppsAO); |
|
243 iOperationManager.AddL( getRunningAppsAO ); |
|
244 CleanupStack::Pop(getRunningAppsAO); |
|
245 getRunningAppsAO->GetRunningApplicationL(); |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // ExecuteActionL |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 EXPORT_C void CMCSService::ExecuteActionL( MMCSCallback* aCallback, |
|
253 TInt aItemId, TDesC8& aAction ) |
|
254 { |
|
255 if( !aCallback ) |
|
256 { |
|
257 User::Leave( KErrArgument ); |
|
258 } |
|
259 CMCSExecuteAction* executeAO = CMCSExecuteAction::NewL( iMCS, aCallback, |
|
260 iOperationManager ); |
|
261 CleanupStack::PushL( executeAO ); |
|
262 iOperationManager.AddL( executeAO ); |
|
263 CleanupStack::Pop(executeAO); |
|
264 executeAO->ExecuteActionL( aItemId, aAction); |
|
265 } |
|
266 |
|
267 // --------------------------------------------------------------------------- |
|
268 // DeleteL |
|
269 // --------------------------------------------------------------------------- |
|
270 // |
|
271 EXPORT_C void CMCSService::DeleteL( MMCSCallback* aCallBack, TInt aItemId ) |
|
272 { |
|
273 if( !aCallBack ) |
|
274 { |
|
275 User::Leave( KErrArgument ); |
|
276 } |
|
277 CMCSDeleteItem* deleteAO = CMCSDeleteItem::NewL( iMCS, aCallBack, |
|
278 iOperationManager ); |
|
279 CleanupStack::PushL(deleteAO); |
|
280 iOperationManager.AddL( deleteAO ); |
|
281 CleanupStack::Pop(deleteAO); |
|
282 deleteAO->DeleteItemL( aItemId ); |
|
283 } |
|
284 |
|
285 |
|
286 // --------------------------------------------------------------------------- |
|
287 // Set GetRunningAppsL output to output parameter |
|
288 // --------------------------------------------------------------------------- |
|
289 // |
|
290 EXPORT_C void CMCSService::SetRunningAppsOutputL( RArray<TUid>& aOutputArray, |
|
291 CLiwGenericParamList& aOutParamList ) |
|
292 { |
|
293 //List of Maps |
|
294 TBuf8<KMenuMaxAttrNameLen> attrname; |
|
295 CLiwDefaultList *list = CLiwDefaultList::NewL(); |
|
296 CleanupStack::PushL( list ); |
|
297 |
|
298 TInt arrCount = aOutputArray.Count(); |
|
299 |
|
300 for( TInt index = 0; index < arrCount; ++index ) |
|
301 { |
|
302 CLiwDefaultMap* map = CLiwDefaultMap::NewLC(); |
|
303 |
|
304 TUid auid = aOutputArray[index]; |
|
305 attrname.Copy(KMenuAttrUid()); |
|
306 |
|
307 map->InsertL( attrname, TLiwVariant( (TInt32) aOutputArray[index].iUid )); |
|
308 |
|
309 list->AppendL( TLiwVariant( map ) ); |
|
310 |
|
311 CleanupStack::PopAndDestroy( map ); |
|
312 } |
|
313 |
|
314 aOutParamList.AppendL( TLiwGenericParam( KReturnValue, TLiwVariant( list ) ) ); |
|
315 |
|
316 CleanupStack::Pop( list ); |
|
317 list->DecRef(); |
|
318 } |
|
319 |
|
320 // --------------------------------------------------------------------------- |
|
321 // Organize |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 EXPORT_C void CMCSService::OrganizeL( MMCSCallback* aCallBack, |
|
325 TInt aMoveItemId, TInt aBeforeItemId ) |
|
326 { |
|
327 if( !aCallBack ) |
|
328 { |
|
329 User::Leave( KErrArgument ); |
|
330 } |
|
331 |
|
332 CMCSOrganizeImpl* organizeAO = CMCSOrganizeImpl::NewL( iMCS, aCallBack, |
|
333 iOperationManager ); |
|
334 CleanupStack::PushL( organizeAO ); |
|
335 iOperationManager.AddL( organizeAO ); |
|
336 CleanupStack::Pop( organizeAO );// we pop item from cleanupstack because |
|
337 //ownership was transfered to operation manager |
|
338 organizeAO->OrganizeL( aMoveItemId, aBeforeItemId ); |
|
339 } |
|
340 |
|
341 // --------------------------------------------------------------------------- |
|
342 // Organize |
|
343 // --------------------------------------------------------------------------- |
|
344 // |
|
345 EXPORT_C void CMCSService::OrganizeL( MMCSCallback* aCallBack, |
|
346 const RArray<TInt>& aList, TInt aFolderId, TInt aBeforeItemId ) |
|
347 { |
|
348 if( !aCallBack ) |
|
349 { |
|
350 User::Leave( KErrArgument ); |
|
351 } |
|
352 |
|
353 |
|
354 CMCSOrganizeImpl* organizeAO = CMCSOrganizeImpl::NewL( iMCS, aCallBack, |
|
355 iOperationManager ); |
|
356 CleanupStack::PushL( organizeAO ); |
|
357 iOperationManager.AddL( organizeAO ); |
|
358 CleanupStack::Pop( organizeAO );// we pop item from cleanupstack because |
|
359 //ownership was transfered to operation manager |
|
360 organizeAO->OrganizeL( aList, aFolderId, aBeforeItemId ); |
|
361 } |
|
362 |
|
363 // --------------------------------------------------------------------------- |
|
364 // Set RequestNotification output to output parameter |
|
365 // --------------------------------------------------------------------------- |
|
366 // |
|
367 EXPORT_C void CMCSService::SetReqNotificationOutputL( TInt aFolderId, |
|
368 TInt aEvent, CLiwGenericParamList& aOutParamList ) |
|
369 { |
|
370 |
|
371 TBuf8<KMenuMaxAttrNameLen> attrname; |
|
372 CLiwDefaultMap* map = CLiwDefaultMap::NewLC(); |
|
373 |
|
374 attrname.Copy(KMenuAttrId()); |
|
375 map->InsertL( attrname, TLiwVariant( (TInt32)aFolderId)); |
|
376 |
|
377 if(aEvent & RMenuNotifier::EItemsAddedRemoved) |
|
378 { |
|
379 map->InsertL( KAddRemove, TLiwVariant( (TBool) ETrue) ); |
|
380 |
|
381 } |
|
382 if( aEvent & RMenuNotifier::EItemsReordered) |
|
383 { |
|
384 map->InsertL( KReorder, TLiwVariant( (TBool) ETrue) ); |
|
385 } |
|
386 if( aEvent & RMenuNotifier::EItemAttributeChanged) |
|
387 { |
|
388 map->InsertL( KAttributeChange, TLiwVariant( (TBool) ETrue) ); |
|
389 } |
|
390 |
|
391 aOutParamList.AppendL( TLiwGenericParam( KReturnValue, TLiwVariant( map ) ) ); |
|
392 CleanupStack::PopAndDestroy( map ); |
|
393 } |
|
394 |
|
395 |
|
396 // --------------------------------------------------------------------------- |
|
397 // Stop Notification for changes in mcs |
|
398 // --------------------------------------------------------------------------- |
|
399 // |
|
400 EXPORT_C void CMCSService::UnRegisterObserverL() |
|
401 { |
|
402 if ( iReqNotifier == NULL ) |
|
403 { |
|
404 User::Leave( KErrNotFound ); |
|
405 } |
|
406 iReqNotifier->StopNotificationL(); |
|
407 |
|
408 delete iReqNotifier; |
|
409 iReqNotifier = NULL; |
|
410 iIsRegistered = EFalse; |
|
411 } |
|
412 |
|
413 // --------------------------------------------------------------------------- |
|
414 // Start Notification for changes in mcs |
|
415 // --------------------------------------------------------------------------- |
|
416 // |
|
417 EXPORT_C void CMCSService::RegisterObserverL(TInt aFolderId,TInt aEvents,MMCSCallback* aCallBack ) |
|
418 { |
|
419 if( !aCallBack ) |
|
420 User::Leave( KErrArgument ); |
|
421 |
|
422 if(!iIsRegistered) |
|
423 { |
|
424 iReqNotifier = CMCSReqNotification::NewL( iMCS ); |
|
425 iIsRegistered = ETrue; |
|
426 } |
|
427 iReqNotifier->StartNotificationL(aFolderId, aEvents, aCallBack); |
|
428 } |
|
429 |