|
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: Application list for settings listbox |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <e32cmn.h> |
|
20 #include <msvuids.h> // For KMsvRootIndexEntryIdValue |
|
21 #include <SenduiMtmUids.h> |
|
22 #include <StringLoader.h> |
|
23 #include <aistrcnv.h> |
|
24 #include <featmgr.h> |
|
25 #include <mcsmenuitem.h> |
|
26 #include <mcsmenufilter.h> |
|
27 |
|
28 #include "mcspluginsettingsapplist.h" |
|
29 #include "mcspluginsettingsmodel.h" |
|
30 #include "mcspluginwatcher.h" |
|
31 |
|
32 _LIT( KMyMenuData, "matrixmenudata" ); |
|
33 _LIT( KMenuTypeShortcut, "menu:shortcut" ); |
|
34 _LIT( KMenuAttrRefcount, "ref_count" ); |
|
35 _LIT( KMenuParamMailbox, "mailbox:" ); |
|
36 _LIT( KMenuAttrParameter, "param" ); |
|
37 _LIT( KMenuAttrLocked, "locked" ); |
|
38 _LIT( KMenuIconFile, "aimcsplugin.mif" ); |
|
39 _LIT( KMenuIconId, "16388" ); |
|
40 _LIT( KMenuMaskId, "16389" ); |
|
41 _LIT( KMailboxUid, "0x100058c5" ); |
|
42 _LIT( KInitialRefCount, "1" ); |
|
43 _LIT( KMCSFolder, "mcsplugin_folder" ); |
|
44 _LIT( KSuiteName, "suite_name" ); |
|
45 _LIT8( KItemLocked, "locked"); |
|
46 _LIT8( KProperValueFolder, "folder" ); |
|
47 _LIT8( KProperValueSuite, "suite" ); |
|
48 |
|
49 |
|
50 |
|
51 // ======== MEMBER FUNCTIONS ======== |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // First-phase construction |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CMCSPluginSettingsAppList::CMCSPluginSettingsAppList() |
|
58 { |
|
59 iMCSPluginFolderId = 0; |
|
60 } |
|
61 |
|
62 // --------------------------------------------------------------------------- |
|
63 // Second-phase construction |
|
64 // --------------------------------------------------------------------------- |
|
65 // |
|
66 void CMCSPluginSettingsAppList::ConstructL() |
|
67 { |
|
68 iMsvSession = CMsvSession::OpenAsObserverL(*this); |
|
69 |
|
70 iMenu.OpenL( KMyMenuData ); |
|
71 iSaveWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::EOperation ); |
|
72 iUpdateWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::EOperation ); |
|
73 iRemoveWatcher = CMCSPluginWatcher::NewL( CMCSPluginWatcher::EOperation ); |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // Two-phased constructor |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 CMCSPluginSettingsAppList* CMCSPluginSettingsAppList::NewL() |
|
81 { |
|
82 CMCSPluginSettingsAppList* self = new (ELeave) CMCSPluginSettingsAppList(); |
|
83 CleanupStack::PushL(self); |
|
84 self->ConstructL(); |
|
85 CleanupStack::Pop(self); |
|
86 return self; |
|
87 } |
|
88 |
|
89 // --------------------------------------------------------------------------- |
|
90 // Destructor |
|
91 // --------------------------------------------------------------------------- |
|
92 // |
|
93 CMCSPluginSettingsAppList::~CMCSPluginSettingsAppList() |
|
94 { |
|
95 delete iMsvSession; |
|
96 |
|
97 iListItems.ResetAndDestroy(); |
|
98 iMenu.Close(); |
|
99 delete iSaveWatcher; |
|
100 delete iUpdateWatcher; |
|
101 delete iRemoveWatcher; |
|
102 |
|
103 } |
|
104 |
|
105 // --------------------------------------------------------------------------- |
|
106 // From MDesCArray |
|
107 // Returns the number of descriptor elements in a descriptor array. |
|
108 // --------------------------------------------------------------------------- |
|
109 // |
|
110 TInt CMCSPluginSettingsAppList::MdcaCount() const |
|
111 { |
|
112 return iListItems.Count(); |
|
113 } |
|
114 |
|
115 // --------------------------------------------------------------------------- |
|
116 // From MDesCArray |
|
117 // Indexes into a descriptor array. |
|
118 // --------------------------------------------------------------------------- |
|
119 // |
|
120 TPtrC CMCSPluginSettingsAppList::MdcaPoint( TInt aIndex ) const |
|
121 { |
|
122 if (aIndex < 0 || aIndex >= iListItems.Count()) |
|
123 { |
|
124 TPtrC ret(KNullDesC); |
|
125 return ret; |
|
126 } |
|
127 CMenuItem* item = iListItems[aIndex]; |
|
128 TBool attrExists; |
|
129 TPtrC itm; |
|
130 TRAP_IGNORE( |
|
131 itm.Set( item->GetAttributeL( KMenuAttrLongName, attrExists ) ); |
|
132 ) |
|
133 return itm; |
|
134 } |
|
135 |
|
136 // --------------------------------------------------------------------------- |
|
137 // From class MMsvSessionObserver. |
|
138 // Handles an event from the message server. |
|
139 // --------------------------------------------------------------------------- |
|
140 // |
|
141 void CMCSPluginSettingsAppList::HandleSessionEventL( |
|
142 TMsvSessionEvent /*aEvent*/, |
|
143 TAny* /*aArg1*/, |
|
144 TAny* /*aArg2*/, |
|
145 TAny* /*aArg3*/ ) |
|
146 { |
|
147 |
|
148 } |
|
149 |
|
150 // --------------------------------------------------------------------------- |
|
151 // Starts the asynchronous application list initialization. |
|
152 // --------------------------------------------------------------------------- |
|
153 // |
|
154 void CMCSPluginSettingsAppList::StartL() |
|
155 { |
|
156 iListItems.ResetAndDestroy(); |
|
157 AddMailboxesL(); |
|
158 AddStaticItemsL(); |
|
159 } |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // Iterates thru the application list and tries to find a menuitem which |
|
163 // matches given property map from HSPS |
|
164 // --------------------------------------------------------------------------- |
|
165 // |
|
166 TSettingItem CMCSPluginSettingsAppList::FindItemL( |
|
167 RPointerArray<HSPluginSettingsIf::CPropertyMap>& aProperties ) |
|
168 { |
|
169 TBool attrExists( EFalse ); |
|
170 TSettingItem settingItem = { KErrNotFound, EApplication, EFalse }; |
|
171 TBool isFolder = EFalse; |
|
172 TBool isSuite = EFalse; |
|
173 |
|
174 // check if the item is folder or suite |
|
175 for ( TInt j = 0; j < aProperties.Count(); j++ ) |
|
176 { |
|
177 if( aProperties[j]->Name() == KType ) |
|
178 { |
|
179 |
|
180 if ( aProperties[j]->Value() == KProperValueFolder ) |
|
181 { |
|
182 isFolder = ETrue; |
|
183 } |
|
184 |
|
185 if ( aProperties[j]->Value() == KProperValueSuite ) |
|
186 { |
|
187 isSuite = ETrue; |
|
188 } |
|
189 break; |
|
190 } |
|
191 } |
|
192 |
|
193 TBool itemFound( EFalse ); |
|
194 |
|
195 // compare name/value pairs with every menu item in the list |
|
196 for ( TInt i = 0; i < iListItems.Count() && !itemFound; i++ ) |
|
197 { |
|
198 TBool match( ETrue ); |
|
199 CMenuItem* item = iListItems[ i ]; |
|
200 |
|
201 for ( TInt j = 0; j < aProperties.Count() && match; j++ ) |
|
202 { |
|
203 // type and locked properties skipped |
|
204 if ( aProperties[j]->Name() != KType && |
|
205 aProperties[j]->Name() != KItemLocked ) |
|
206 { |
|
207 HBufC* attrName( NULL ); |
|
208 attrName = AiUtility::CopyToBufferL( attrName, |
|
209 aProperties[j]->Name()); |
|
210 CleanupStack::PushL( attrName ); |
|
211 TPtrC attr = item->GetAttributeL( *attrName, attrExists ); |
|
212 |
|
213 HBufC* attrValue( NULL ); |
|
214 attrValue = AiUtility::CopyToBufferL( attrValue, |
|
215 aProperties[j]->Value()); |
|
216 CleanupStack::PushL( attrValue ); |
|
217 |
|
218 // in case of folder, we just have to compare id |
|
219 // which is stored in param attribute |
|
220 if ( isFolder && *attrName == KMenuAttrParameter ) |
|
221 { |
|
222 // convert id to integer |
|
223 TInt id; |
|
224 TLex16 lextmp( attrValue->Ptr() ); |
|
225 lextmp.Val( id ); |
|
226 |
|
227 if ( item->Id() != id ) |
|
228 { |
|
229 match = EFalse; |
|
230 } |
|
231 CleanupStack::PopAndDestroy( attrValue ); |
|
232 CleanupStack::PopAndDestroy( attrName ); |
|
233 break; |
|
234 } |
|
235 |
|
236 // in case of suite, we just have to compare suite_name |
|
237 // which is stored in param attribute |
|
238 if ( isSuite && *attrName == KMenuAttrParameter ) |
|
239 { |
|
240 TBool exists; |
|
241 TPtrC suitename = item->GetAttributeL( KSuiteName, exists ); |
|
242 |
|
243 if ( !exists || suitename != *attrValue ) |
|
244 { |
|
245 match = EFalse; |
|
246 } |
|
247 CleanupStack::PopAndDestroy( attrValue ); |
|
248 CleanupStack::PopAndDestroy( attrName ); |
|
249 break; |
|
250 } |
|
251 |
|
252 // otherwise, compare attributes from HSPS and from menuitem |
|
253 // if there is no match, move to the next item in the list |
|
254 if ( attr != *attrValue ) |
|
255 { |
|
256 match = EFalse; |
|
257 } |
|
258 CleanupStack::PopAndDestroy( attrValue ); |
|
259 CleanupStack::PopAndDestroy( attrName ); |
|
260 } |
|
261 } |
|
262 |
|
263 if ( match ) |
|
264 { |
|
265 settingItem.id = i; |
|
266 settingItem.type = EApplication; |
|
267 itemFound = ETrue; |
|
268 } |
|
269 } |
|
270 return settingItem; |
|
271 } |
|
272 |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // Returns menuitems at given index. Since this method is called during |
|
276 // adding the item to the Desktop widget, we also have to increment |
|
277 // ref_count attribute if the item is run-time generated (i.e. Mailbox) |
|
278 // --------------------------------------------------------------------------- |
|
279 // |
|
280 CMenuItem& CMCSPluginSettingsAppList::ItemL( const TInt& aIndex ) |
|
281 { |
|
282 |
|
283 CMenuItem* menuItem( NULL ); |
|
284 |
|
285 // check if index in within the list boundaries |
|
286 if ( aIndex >= 0 && aIndex < iListItems.Count() ) |
|
287 { |
|
288 |
|
289 menuItem = iListItems[ aIndex ]; |
|
290 |
|
291 TBool hasParam = EFalse; |
|
292 CleanupStack::PushL( menuItem ); |
|
293 TPtrC param = menuItem->GetAttributeL( KMenuAttrParameter, hasParam ); |
|
294 CleanupStack::Pop( menuItem ); |
|
295 |
|
296 // if item is a mailbox, add it to MCS |
|
297 // (if it is not already there) |
|
298 if ( hasParam && param.Find( KMenuParamMailbox ) != KErrNotFound ) |
|
299 { |
|
300 |
|
301 // set up a filter for finding the mailbox |
|
302 // with given ID in MCS |
|
303 CMenuFilter* filter = CMenuFilter::NewL(); |
|
304 CleanupStack::PushL( filter ); |
|
305 |
|
306 filter->SetType( KMenuTypeShortcut ); |
|
307 filter->HaveAttributeL( KMenuAttrParameter, param ); |
|
308 |
|
309 // search menu from the Root folder with the filter |
|
310 const TInt rootId = iMenu.RootFolderL(); |
|
311 RArray<TMenuItem> itemArray; |
|
312 CleanupClosePushL( itemArray ); |
|
313 iMenu.GetItemsL( itemArray, rootId, filter, ETrue ); |
|
314 |
|
315 // save the number of findings |
|
316 TInt count( itemArray.Count() ); |
|
317 |
|
318 // if MenuItem does not exist in MCS |
|
319 if ( count == 0 ) |
|
320 { |
|
321 // save the item into Matrixmenudata.xml |
|
322 // the "op" variable is cleaned up by iSaveWatcher when asynchronous |
|
323 // operation finishes |
|
324 CleanupStack::PushL( menuItem ); |
|
325 CMenuOperation* op = menuItem->SaveL( iSaveWatcher->iStatus ); |
|
326 CleanupStack::Pop( menuItem ); |
|
327 iSaveWatcher->Watch( op ); |
|
328 } |
|
329 else |
|
330 { |
|
331 // Item already exists in MCS |
|
332 // If it has reference counter, increment it before returning. |
|
333 CMenuItem* itm = CMenuItem::OpenL( iMenu, itemArray[ 0 ] ); |
|
334 |
|
335 TInt newRefCount = UpdateMenuItemsRefCountL( itm, 1 ); |
|
336 if ( newRefCount > -1 ) |
|
337 { |
|
338 CleanupStack::PushL( itm ); |
|
339 CMenuOperation* op = itm->SaveL( iSaveWatcher->iStatus ); |
|
340 CleanupStack::PopAndDestroy( itm ); |
|
341 iSaveWatcher->Watch( op ); |
|
342 } |
|
343 } |
|
344 CleanupStack::PopAndDestroy( &itemArray ); |
|
345 CleanupStack::PopAndDestroy( filter ); |
|
346 } |
|
347 } |
|
348 return *menuItem; |
|
349 } |
|
350 |
|
351 // --------------------------------------------------------------------------- |
|
352 // Helper method for comparing names of two menuitems. Used to sort the list |
|
353 // of items. |
|
354 // --------------------------------------------------------------------------- |
|
355 // |
|
356 TInt CMCSPluginSettingsAppList::CompareNameL( const CMenuItem& aFirst, |
|
357 const CMenuItem& aSecond ) |
|
358 { |
|
359 TBool exists( EFalse ); |
|
360 CMenuItem& first = const_cast<CMenuItem&>(aFirst); |
|
361 CMenuItem& second = const_cast<CMenuItem&>(aSecond); |
|
362 |
|
363 TPtrC name1 = first.GetAttributeL( KMenuAttrLongName, exists ); |
|
364 TPtrC name2 = second.GetAttributeL( KMenuAttrLongName, exists ); |
|
365 |
|
366 return name1.CompareC( name2 ); |
|
367 } |
|
368 |
|
369 // --------------------------------------------------------------------------- |
|
370 // Adds the static list items to the application list. |
|
371 // --------------------------------------------------------------------------- |
|
372 // |
|
373 void CMCSPluginSettingsAppList::AddStaticItemsL() |
|
374 { |
|
375 TLinearOrder<CMenuItem> sortMethod( CMCSPluginSettingsAppList::CompareNameL ); |
|
376 |
|
377 CMenuFilter* filter = CMenuFilter::NewL(); |
|
378 CleanupStack::PushL( filter ); |
|
379 |
|
380 // skip run-time generated items |
|
381 filter->DoNotHaveAttributeL( KMenuAttrRefcount ); |
|
382 filter->DoNotHaveAttributeL( KMenuAttrLocked ); |
|
383 const TInt rootId = iMenu.RootFolderL(); |
|
384 RArray<TMenuItem> itemArray; |
|
385 CleanupClosePushL( itemArray ); |
|
386 iMenu.GetItemsL( itemArray, rootId, filter, ETrue ); |
|
387 |
|
388 TInt count( itemArray.Count() ); |
|
389 |
|
390 for ( TInt i = 0; i < count; i++ ) |
|
391 { |
|
392 TPtrC type = itemArray[ i ].Type(); |
|
393 |
|
394 // we add applications, shortcuts, folders and suites to the list |
|
395 if ( type == KMenuTypeApp || type == KMenuTypeShortcut || |
|
396 type == KMenuTypeFolder || type == KMenuTypeSuite ) |
|
397 { |
|
398 CMenuItem* menuItem = CMenuItem::OpenL( iMenu, itemArray[ i ] ); |
|
399 CleanupStack::PushL( menuItem ); |
|
400 |
|
401 // only non-hidden and non-missing items should be offered to the user |
|
402 if ( ( menuItem->Flags() & TMenuItem::EHidden ) == EFalse && |
|
403 ( menuItem->Flags() & TMenuItem::EMissing ) == EFalse ) |
|
404 { |
|
405 User::LeaveIfError( iListItems.InsertInOrderAllowRepeats( menuItem, sortMethod ) ); |
|
406 CleanupStack::Pop( menuItem ); |
|
407 } |
|
408 else |
|
409 { |
|
410 CleanupStack::PopAndDestroy( menuItem ); |
|
411 } |
|
412 menuItem = NULL; |
|
413 } |
|
414 } |
|
415 |
|
416 CleanupStack::PopAndDestroy( &itemArray ); |
|
417 CleanupStack::PopAndDestroy( filter ); |
|
418 } |
|
419 |
|
420 |
|
421 // --------------------------------------------------------------------------- |
|
422 // Returns the root entry containing mailboxes. |
|
423 // --------------------------------------------------------------------------- |
|
424 // |
|
425 CMsvEntry* CMCSPluginSettingsAppList::GetRootEntryL() |
|
426 { |
|
427 return iMsvSession->GetEntryL(KMsvRootIndexEntryIdValue); |
|
428 } |
|
429 |
|
430 // --------------------------------------------------------------------------- |
|
431 // Adds remote mailboxes to the application list. |
|
432 // --------------------------------------------------------------------------- |
|
433 // |
|
434 void CMCSPluginSettingsAppList::AddMailboxesL() |
|
435 { |
|
436 |
|
437 iListItems.ResetAndDestroy(); |
|
438 CMsvEntry* rootEntry = GetRootEntryL(); |
|
439 CleanupStack::PushL(rootEntry); |
|
440 TBuf<255> mailboxId; |
|
441 |
|
442 for ( TInt i = rootEntry->Count() - 1; i >= 0; --i ) |
|
443 { |
|
444 const TMsvEntry& tentry = (*rootEntry)[i]; |
|
445 |
|
446 if (tentry.iMtm == KSenduiMtmImap4Uid || tentry.iMtm == KSenduiMtmPop3Uid) |
|
447 { |
|
448 mailboxId.Num( tentry.Id() ); |
|
449 AddMailboxL( tentry.iDetails, mailboxId ); |
|
450 } |
|
451 } |
|
452 CleanupStack::PopAndDestroy(rootEntry); |
|
453 } |
|
454 |
|
455 // --------------------------------------------------------------------------- |
|
456 // Adds a mailbox to the list. |
|
457 // --------------------------------------------------------------------------- |
|
458 // |
|
459 void CMCSPluginSettingsAppList::AddMailboxL( const TDesC& aMailbox, |
|
460 const TDesC& aMailboxId ) |
|
461 { |
|
462 // prepare param value |
|
463 HBufC* params = HBufC::NewLC( KMenuParamMailbox().Length() + aMailboxId.Length() ); |
|
464 params->Des().Copy( KMenuParamMailbox ); |
|
465 params->Des().Append( aMailboxId ); |
|
466 TPtrC paramValue( params->Des() ); |
|
467 |
|
468 TLinearOrder<CMenuItem> sortMethod( CMCSPluginSettingsAppList::CompareNameL ); |
|
469 CMenuItem* newItem = CMenuItem::CreateL( iMenu, |
|
470 KMenuTypeShortcut, |
|
471 GetMCSPluginFolderIdL(), |
|
472 0 ); |
|
473 CleanupStack::PushL( newItem ); |
|
474 |
|
475 // mailbox is a shortcut item with "mailbox:mailboxID" parameter |
|
476 newItem->SetAttributeL( KMenuAttrUid, KMailboxUid ); |
|
477 newItem->SetAttributeL( KMenuAttrLongName, aMailbox ); |
|
478 newItem->SetAttributeL( KMenuAttrParameter, paramValue ); |
|
479 newItem->SetAttributeL( KMenuAttrRefcount, KInitialRefCount ); |
|
480 |
|
481 // setting icon for the shortcut |
|
482 newItem->SetAttributeL( KMenuAttrIconFile, KMenuIconFile ); |
|
483 newItem->SetAttributeL( KMenuAttrIconId, KMenuIconId ); |
|
484 newItem->SetAttributeL( KMenuAttrMaskId, KMenuMaskId ); |
|
485 |
|
486 // append the item into iListItems lists |
|
487 User::LeaveIfError( iListItems.InsertInOrderAllowRepeats( newItem, sortMethod ) ); |
|
488 CleanupStack::Pop( newItem ); |
|
489 CleanupStack::PopAndDestroy( params ); |
|
490 } |
|
491 |
|
492 // --------------------------------------------------------------------------- |
|
493 // Removes run-time generated menuitem (i.e. Mailbox) from MCS |
|
494 // If the item at given index is not run-time generated, return |
|
495 // --------------------------------------------------------------------------- |
|
496 // |
|
497 void CMCSPluginSettingsAppList::RemoveMenuItemL( TInt aIndex ) |
|
498 { |
|
499 |
|
500 if ( aIndex < 0 || aIndex > iListItems.Count() - 1 ) |
|
501 { |
|
502 return; |
|
503 } |
|
504 |
|
505 CMenuItem* menuItem = iListItems[ aIndex ]; |
|
506 |
|
507 TBool hasParam = ETrue; |
|
508 TPtrC param = menuItem->GetAttributeL( KMenuAttrParameter, hasParam ); |
|
509 |
|
510 if ( !hasParam ) |
|
511 { |
|
512 // nothing to do |
|
513 return; |
|
514 } |
|
515 |
|
516 // set up a filter for finding the mailbox |
|
517 // with given ID in MCS |
|
518 CMenuFilter* filter = CMenuFilter::NewL(); |
|
519 CleanupStack::PushL( filter ); |
|
520 |
|
521 filter->SetType( KMenuTypeShortcut ); |
|
522 filter->HaveAttributeL( KMenuAttrParameter, param ); |
|
523 |
|
524 // search menu from the Root folder with the filter |
|
525 const TInt rootId = iMenu.RootFolderL(); |
|
526 RArray<TMenuItem> itemArray; |
|
527 CleanupClosePushL( itemArray ); |
|
528 iMenu.GetItemsL( itemArray, rootId, filter, ETrue ); |
|
529 |
|
530 // save the number of findings |
|
531 TInt count( itemArray.Count() ); |
|
532 |
|
533 if ( count > 0 ) |
|
534 { |
|
535 // Item already exists in MCS |
|
536 // If it has reference counter, increment it before returning. |
|
537 CMenuItem* itm = CMenuItem::OpenL( iMenu, itemArray[ 0 ] ); |
|
538 |
|
539 // decrement ref_count attribute |
|
540 TInt newRefCount = UpdateMenuItemsRefCountL( itm, -1 ); |
|
541 if ( newRefCount > 0 ) |
|
542 { |
|
543 CleanupStack::PushL( itm ); |
|
544 CMenuOperation* op = itm->SaveL( iUpdateWatcher->iStatus ); |
|
545 CleanupStack::Pop( itm ); |
|
546 iUpdateWatcher->Watch( op ); |
|
547 } |
|
548 else if ( newRefCount == 0 ) |
|
549 { |
|
550 // counter reached 0 -> item is not referenced by any shortcut |
|
551 // so remove it from MCS |
|
552 if ( iRemoveWatcher->IsActive() ) |
|
553 { |
|
554 return; |
|
555 } |
|
556 CMenuOperation* op = iMenu.RemoveL( itm->Id(), iRemoveWatcher->iStatus ); |
|
557 iRemoveWatcher->Watch( op ); |
|
558 } |
|
559 delete itm; |
|
560 } |
|
561 CleanupStack::PopAndDestroy( &itemArray ); |
|
562 CleanupStack::PopAndDestroy( filter ); |
|
563 } |
|
564 |
|
565 // --------------------------------------------------------------------------- |
|
566 // Gets MCS Plugin folder ID. This hidden folder in matrixmenudata.xml is used |
|
567 // for storing run-time generated menuitems |
|
568 // --------------------------------------------------------------------------- |
|
569 // |
|
570 TInt CMCSPluginSettingsAppList::GetMCSPluginFolderIdL() |
|
571 { |
|
572 |
|
573 if ( iMCSPluginFolderId == 0 ) |
|
574 { |
|
575 CMenuItem* item( NULL ); |
|
576 CMenuFilter* filter = CMenuFilter::NewL(); |
|
577 CleanupStack::PushL( filter ); |
|
578 filter->SetType( KMenuTypeFolder ); |
|
579 filter->HaveAttributeL( KMenuAttrLongName, KMCSFolder ); |
|
580 const TInt rootId = iMenu.RootFolderL(); |
|
581 RArray<TMenuItem> itemArray; |
|
582 CleanupClosePushL( itemArray ); |
|
583 iMenu.GetItemsL( itemArray, rootId, filter, ETrue ); |
|
584 if ( itemArray.Count() > 0 ) |
|
585 { |
|
586 item = CMenuItem::OpenL( iMenu, itemArray[ 0 ] ); |
|
587 iMCSPluginFolderId = item->Id(); |
|
588 } |
|
589 else |
|
590 { |
|
591 iMCSPluginFolderId = iMenu.RootFolderL(); |
|
592 } |
|
593 CleanupStack::PopAndDestroy( &itemArray ); |
|
594 CleanupStack::PopAndDestroy( filter ); |
|
595 delete item; |
|
596 } |
|
597 return iMCSPluginFolderId; |
|
598 |
|
599 } |
|
600 |
|
601 // --------------------------------------------------------------------------- |
|
602 // Helper method for updating ref_count attribute of run-time generated |
|
603 // menuitems |
|
604 // --------------------------------------------------------------------------- |
|
605 // |
|
606 TInt CMCSPluginSettingsAppList::UpdateMenuItemsRefCountL( CMenuItem* aItem, |
|
607 TInt aValueToAdd ) |
|
608 { |
|
609 |
|
610 TBool exists = EFalse; |
|
611 CleanupStack::PushL( aItem ); |
|
612 TPtrC param = aItem->GetAttributeL( KMenuAttrRefcount, exists ); |
|
613 CleanupStack::Pop( aItem ); |
|
614 if ( exists ) |
|
615 { |
|
616 TInt references; |
|
617 TLex16 lextmp( param ); |
|
618 lextmp.Val( references ); |
|
619 references += aValueToAdd; |
|
620 TBuf<128> buf; |
|
621 buf.NumUC( references ); |
|
622 // set new ref_count |
|
623 CleanupStack::PushL( aItem ); |
|
624 aItem->SetAttributeL( KMenuAttrRefcount, buf ); |
|
625 CleanupStack::Pop( aItem ); |
|
626 // return new ref_count |
|
627 return references; |
|
628 } |
|
629 return -1; |
|
630 } |
|
631 |
|
632 |
|
633 // End of File. |