13 * |
13 * |
14 * Description: Application list for settings listbox |
14 * Description: Application list for settings listbox |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
18 |
|
19 #include <e32cmn.h> |
|
20 #include <msvuids.h> // For KMsvRootIndexEntryIdValue |
|
21 #include <SenduiMtmUids.h> |
|
22 #include <StringLoader.h> |
|
23 #include <aistrcnv.h> |
18 #include <aistrcnv.h> |
24 #include <featmgr.h> |
|
25 #include <mcsmenuitem.h> |
19 #include <mcsmenuitem.h> |
26 #include <mcsmenufilter.h> |
20 #include <mcsmenufilter.h> |
27 |
21 |
28 #include "mcspluginsettingsapplist.h" |
22 #include "mcspluginsettingsapplist.h" |
29 #include "mcspluginsettingsmodel.h" |
23 #include "mcspluginsettingsmodel.h" // For TSettingItem |
30 #include "mcspluginwatcher.h" |
|
31 |
24 |
32 _LIT( KMyMenuData, "matrixmenudata" ); |
25 _LIT( KMyMenuData, "matrixmenudata" ); |
33 _LIT( KMenuTypeShortcut, "menu:shortcut" ); |
26 _LIT( KMenuTypeShortcut, "menu:shortcut" ); |
34 _LIT( KMenuAttrRefcount, "ref_count" ); |
27 _LIT( KMenuTypeMailbox, "menu:mailbox" ); |
35 _LIT( KMenuParamMailbox, "mailbox:" ); |
|
36 _LIT( KMenuAttrParameter, "param" ); |
28 _LIT( KMenuAttrParameter, "param" ); |
37 _LIT( KMenuAttrLocked, "locked" ); |
29 _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 _LIT8( KItemLocked, "locked"); |
30 _LIT8( KItemLocked, "locked"); |
45 _LIT8( KProperValueFolder, "folder" ); |
31 _LIT8( KProperValueFolder, "folder" ); |
46 _LIT( KMenuAttrUndefUid, "0x99999991" ); |
32 _LIT( KMenuAttrUndefUid, "0x99999991" ); |
47 _LIT( KMenuItemLongName, "long_name" ); |
33 _LIT( KMenuItemLongName, "long_name" ); |
48 |
34 |
82 TMenuItem item; |
64 TMenuItem item; |
83 const TInt root = iMenu.RootFolderL(); |
65 const TInt root = iMenu.RootFolderL(); |
84 RArray<TMenuItem> items; |
66 RArray<TMenuItem> items; |
85 CleanupClosePushL( items ); |
67 CleanupClosePushL( items ); |
86 iMenu.GetItemsL( items, root, filter, ETrue ); |
68 iMenu.GetItemsL( items, root, filter, ETrue ); |
87 TMenuItem undefItem; |
|
88 |
69 |
89 if ( items.Count() > 0 ) |
70 if ( items.Count() > 0 ) |
90 { |
71 { |
91 undefItem = items[ 0 ]; |
72 iUndefinedItem = CMenuItem::OpenL( iMenu, items[ 0 ] ); |
92 CMenuItem* undefinedItem = CMenuItem::OpenL( iMenu, undefItem ); |
|
93 iUndefinedText = NULL; |
73 iUndefinedText = NULL; |
94 |
74 |
95 if ( undefinedItem ) |
75 if ( iUndefinedItem ) |
96 { |
76 { |
97 TBool exists( KErrNotFound ); |
77 TBool exists( KErrNotFound );//CleanupStack::PushL( undefinedItem ); |
98 CleanupStack::PushL( undefinedItem ); |
78 TPtrC undefined = iUndefinedItem->GetAttributeL( KMenuItemLongName, exists ); |
99 TPtrC undefined = undefinedItem->GetAttributeL( KMenuItemLongName, exists ); |
|
100 |
79 |
101 if ( exists ) |
80 if ( exists ) |
102 { |
81 { |
103 iUndefinedText = HBufC::NewMaxL( undefined.Length() ); |
82 iUndefinedText = HBufC::NewMaxL( undefined.Length() ); |
104 iUndefinedText->Des().Copy( undefined ); |
83 iUndefinedText->Des().Copy( undefined ); |
105 } |
84 } |
106 else |
85 else |
107 { |
86 { |
108 iUndefinedText = KNullDesC().Alloc(); |
87 iUndefinedText = KNullDesC().Alloc(); |
109 } |
88 } |
110 CleanupStack::PopAndDestroy( undefinedItem ); |
|
111 } |
89 } |
112 } |
90 } |
113 |
91 |
114 CleanupStack::PopAndDestroy( &items ); |
92 CleanupStack::PopAndDestroy( &items ); |
115 CleanupStack::PopAndDestroy( filter ); |
93 CleanupStack::PopAndDestroy( filter ); |
294 } |
266 } |
295 } |
267 } |
296 return settingItem; |
268 return settingItem; |
297 } |
269 } |
298 |
270 |
299 |
271 // --------------------------------------------------------------------------- |
300 // --------------------------------------------------------------------------- |
272 // Returns menuitems at given index. |
301 // Returns menuitems at given index. Since this method is called during |
273 // --------------------------------------------------------------------------- |
302 // adding the item to the Desktop widget, we also have to increment |
274 // |
303 // ref_count attribute if the item is run-time generated (i.e. Mailbox) |
275 CMenuItem* CMCSPluginSettingsAppList::ItemL( const TInt& aIndex ) |
304 // --------------------------------------------------------------------------- |
276 { |
305 // |
|
306 CMenuItem& CMCSPluginSettingsAppList::ItemL( const TInt& aIndex ) |
|
307 { |
|
308 |
|
309 CMenuItem* menuItem( NULL ); |
277 CMenuItem* menuItem( NULL ); |
310 |
278 // check if index is within the list boundaries |
311 // check if index in within the list boundaries |
|
312 if ( aIndex >= 0 && aIndex < iListItems.Count() ) |
279 if ( aIndex >= 0 && aIndex < iListItems.Count() ) |
313 { |
280 { |
314 |
|
315 menuItem = iListItems[ aIndex ]; |
281 menuItem = iListItems[ aIndex ]; |
316 |
282 } |
317 TBool hasParam = EFalse; |
283 return menuItem; |
318 CleanupStack::PushL( menuItem ); |
|
319 TPtrC param = menuItem->GetAttributeL( KMenuAttrParameter, hasParam ); |
|
320 CleanupStack::Pop( menuItem ); |
|
321 |
|
322 // if item is a mailbox, add it to MCS |
|
323 // (if it is not already there) |
|
324 if ( hasParam && param.Find( KMenuParamMailbox ) != KErrNotFound ) |
|
325 { |
|
326 |
|
327 // set up a filter for finding the mailbox |
|
328 // with given ID in MCS |
|
329 CMenuFilter* filter = CMenuFilter::NewL(); |
|
330 CleanupStack::PushL( filter ); |
|
331 |
|
332 filter->SetType( KMenuTypeShortcut ); |
|
333 filter->HaveAttributeL( KMenuAttrParameter, param ); |
|
334 |
|
335 // search menu from the Root folder with the filter |
|
336 const TInt rootId = iMenu.RootFolderL(); |
|
337 RArray<TMenuItem> itemArray; |
|
338 CleanupClosePushL( itemArray ); |
|
339 iMenu.GetItemsL( itemArray, rootId, filter, ETrue ); |
|
340 |
|
341 // save the number of findings |
|
342 TInt count( itemArray.Count() ); |
|
343 |
|
344 // if MenuItem does not exist in MCS |
|
345 if ( count == 0 ) |
|
346 { |
|
347 // save the item into Matrixmenudata.xml |
|
348 // the "op" variable is cleaned up by iSaveWatcher when asynchronous |
|
349 // operation finishes |
|
350 CleanupStack::PushL( menuItem ); |
|
351 CMenuOperation* op = menuItem->SaveL( iSaveWatcher->iStatus ); |
|
352 CleanupStack::Pop( menuItem ); |
|
353 iSaveWatcher->Watch( op ); |
|
354 } |
|
355 else |
|
356 { |
|
357 // Item already exists in MCS |
|
358 // If it has reference counter, increment it before returning. |
|
359 CMenuItem* itm = CMenuItem::OpenL( iMenu, itemArray[ 0 ] ); |
|
360 |
|
361 TInt newRefCount = UpdateMenuItemsRefCountL( itm, 1 ); |
|
362 if ( newRefCount > -1 ) |
|
363 { |
|
364 CleanupStack::PushL( itm ); |
|
365 CMenuOperation* op = itm->SaveL( iSaveWatcher->iStatus ); |
|
366 CleanupStack::PopAndDestroy( itm ); |
|
367 iSaveWatcher->Watch( op ); |
|
368 } |
|
369 } |
|
370 CleanupStack::PopAndDestroy( &itemArray ); |
|
371 CleanupStack::PopAndDestroy( filter ); |
|
372 } |
|
373 } |
|
374 return *menuItem; |
|
375 } |
284 } |
376 |
285 |
377 // --------------------------------------------------------------------------- |
286 // --------------------------------------------------------------------------- |
378 // Helper method for comparing names of two menuitems. Used to sort the list |
287 // Helper method for comparing names of two menuitems. Used to sort the list |
379 // of items. |
288 // of items. |
492 // --------------------------------------------------------------------------- |
398 // --------------------------------------------------------------------------- |
493 // |
399 // |
494 void CMCSPluginSettingsAppList::AddMailboxL( const TDesC& aMailbox, |
400 void CMCSPluginSettingsAppList::AddMailboxL( const TDesC& aMailbox, |
495 const TDesC& aMailboxId ) |
401 const TDesC& aMailboxId ) |
496 { |
402 { |
497 // prepare param value |
403 TLinearOrder<CMenuItem> sortMethod( CMCSPluginSettingsAppList::CompareNameL ); |
498 HBufC* params = HBufC::NewLC( KMenuParamMailbox().Length() + aMailboxId.Length() ); |
404 CMenuItem* newItem = CMenuItem::CreateL( iMenu, KMenuTypeMailbox, 0, 0 ); |
499 params->Des().Copy( KMenuParamMailbox ); |
405 CleanupStack::PushL( newItem ); |
500 params->Des().Append( aMailboxId ); |
406 |
501 TPtrC paramValue( params->Des() ); |
407 // mailbox is a shortcut item with "mailbox:mailboxID" parameter |
502 |
408 newItem->SetAttributeL( KMenuAttrUid, aMailboxId ); |
503 TLinearOrder<CMenuItem> sortMethod( CMCSPluginSettingsAppList::CompareNameL ); |
409 newItem->SetAttributeL( KMenuAttrLongName, aMailbox ); |
504 CMenuItem* newItem = CMenuItem::CreateL( iMenu, |
410 // Mailbox name is saved to settings into param field. |
505 KMenuTypeShortcut, |
411 newItem->SetAttributeL( KMenuAttrParameter, aMailbox ); |
506 GetMCSPluginFolderIdL(), |
412 |
507 0 ); |
413 // append the item into iListItems lists |
508 CleanupStack::PushL( newItem ); |
414 User::LeaveIfError( iListItems.InsertInOrderAllowRepeats( newItem, sortMethod ) ); |
509 |
415 CleanupStack::Pop( newItem ); |
510 // mailbox is a shortcut item with "mailbox:mailboxID" parameter |
416 } |
511 newItem->SetAttributeL( KMenuAttrUid, KMailboxUid ); |
|
512 newItem->SetAttributeL( KMenuAttrLongName, aMailbox ); |
|
513 newItem->SetAttributeL( KMenuAttrParameter, paramValue ); |
|
514 newItem->SetAttributeL( KMenuAttrRefcount, KInitialRefCount ); |
|
515 |
|
516 // setting icon for the shortcut |
|
517 newItem->SetAttributeL( KMenuAttrIconFile, KMenuIconFile ); |
|
518 newItem->SetAttributeL( KMenuAttrIconId, KMenuIconId ); |
|
519 newItem->SetAttributeL( KMenuAttrMaskId, KMenuMaskId ); |
|
520 |
|
521 // append the item into iListItems lists |
|
522 User::LeaveIfError( iListItems.InsertInOrderAllowRepeats( newItem, sortMethod ) ); |
|
523 CleanupStack::Pop( newItem ); |
|
524 CleanupStack::PopAndDestroy( params ); |
|
525 } |
|
526 |
|
527 // --------------------------------------------------------------------------- |
|
528 // Removes run-time generated menuitem (i.e. Mailbox) from MCS |
|
529 // If the item at given index is not run-time generated, return |
|
530 // --------------------------------------------------------------------------- |
|
531 // |
|
532 void CMCSPluginSettingsAppList::RemoveMenuItemL( TInt aIndex ) |
|
533 { |
|
534 |
|
535 if ( aIndex < 0 || aIndex > iListItems.Count() - 1 ) |
|
536 { |
|
537 return; |
|
538 } |
|
539 |
|
540 CMenuItem* menuItem = iListItems[ aIndex ]; |
|
541 |
|
542 TBool hasParam = ETrue; |
|
543 TPtrC param = menuItem->GetAttributeL( KMenuAttrParameter, hasParam ); |
|
544 |
|
545 if ( !hasParam ) |
|
546 { |
|
547 // nothing to do |
|
548 return; |
|
549 } |
|
550 |
|
551 // set up a filter for finding the mailbox |
|
552 // with given ID in MCS |
|
553 CMenuFilter* filter = CMenuFilter::NewL(); |
|
554 CleanupStack::PushL( filter ); |
|
555 |
|
556 filter->SetType( KMenuTypeShortcut ); |
|
557 filter->HaveAttributeL( KMenuAttrParameter, param ); |
|
558 |
|
559 // search menu from the Root folder with the filter |
|
560 const TInt rootId = iMenu.RootFolderL(); |
|
561 RArray<TMenuItem> itemArray; |
|
562 CleanupClosePushL( itemArray ); |
|
563 iMenu.GetItemsL( itemArray, rootId, filter, ETrue ); |
|
564 |
|
565 // save the number of findings |
|
566 TInt count( itemArray.Count() ); |
|
567 |
|
568 if ( count > 0 ) |
|
569 { |
|
570 // Item already exists in MCS |
|
571 // If it has reference counter, increment it before returning. |
|
572 CMenuItem* itm = CMenuItem::OpenL( iMenu, itemArray[ 0 ] ); |
|
573 |
|
574 // decrement ref_count attribute |
|
575 TInt newRefCount = UpdateMenuItemsRefCountL( itm, -1 ); |
|
576 if ( newRefCount > 0 ) |
|
577 { |
|
578 CleanupStack::PushL( itm ); |
|
579 CMenuOperation* op = itm->SaveL( iUpdateWatcher->iStatus ); |
|
580 CleanupStack::Pop( itm ); |
|
581 iUpdateWatcher->Watch( op ); |
|
582 } |
|
583 else if ( newRefCount == 0 ) |
|
584 { |
|
585 // counter reached 0 -> item is not referenced by any shortcut |
|
586 // so remove it from MCS |
|
587 if ( iRemoveWatcher->IsActive() ) |
|
588 { |
|
589 return; |
|
590 } |
|
591 CMenuOperation* op = iMenu.RemoveL( itm->Id(), iRemoveWatcher->iStatus ); |
|
592 iRemoveWatcher->Watch( op ); |
|
593 } |
|
594 delete itm; |
|
595 } |
|
596 CleanupStack::PopAndDestroy( &itemArray ); |
|
597 CleanupStack::PopAndDestroy( filter ); |
|
598 } |
|
599 |
|
600 // --------------------------------------------------------------------------- |
|
601 // Gets MCS Plugin folder ID. This hidden folder in matrixmenudata.xml is used |
|
602 // for storing run-time generated menuitems |
|
603 // --------------------------------------------------------------------------- |
|
604 // |
|
605 TInt CMCSPluginSettingsAppList::GetMCSPluginFolderIdL() |
|
606 { |
|
607 |
|
608 if ( iMCSPluginFolderId == 0 ) |
|
609 { |
|
610 CMenuItem* item( NULL ); |
|
611 CMenuFilter* filter = CMenuFilter::NewL(); |
|
612 CleanupStack::PushL( filter ); |
|
613 filter->SetType( KMenuTypeFolder ); |
|
614 filter->HaveAttributeL( KMenuAttrLongName, KMCSFolder ); |
|
615 const TInt rootId = iMenu.RootFolderL(); |
|
616 RArray<TMenuItem> itemArray; |
|
617 CleanupClosePushL( itemArray ); |
|
618 iMenu.GetItemsL( itemArray, rootId, filter, ETrue ); |
|
619 if ( itemArray.Count() > 0 ) |
|
620 { |
|
621 item = CMenuItem::OpenL( iMenu, itemArray[ 0 ] ); |
|
622 iMCSPluginFolderId = item->Id(); |
|
623 } |
|
624 else |
|
625 { |
|
626 iMCSPluginFolderId = iMenu.RootFolderL(); |
|
627 } |
|
628 CleanupStack::PopAndDestroy( &itemArray ); |
|
629 CleanupStack::PopAndDestroy( filter ); |
|
630 delete item; |
|
631 } |
|
632 return iMCSPluginFolderId; |
|
633 |
|
634 } |
|
635 |
|
636 // --------------------------------------------------------------------------- |
|
637 // Helper method for updating ref_count attribute of run-time generated |
|
638 // menuitems |
|
639 // --------------------------------------------------------------------------- |
|
640 // |
|
641 TInt CMCSPluginSettingsAppList::UpdateMenuItemsRefCountL( CMenuItem* aItem, |
|
642 TInt aValueToAdd ) |
|
643 { |
|
644 |
|
645 TBool exists = EFalse; |
|
646 CleanupStack::PushL( aItem ); |
|
647 TPtrC param = aItem->GetAttributeL( KMenuAttrRefcount, exists ); |
|
648 CleanupStack::Pop( aItem ); |
|
649 if ( exists ) |
|
650 { |
|
651 TInt references; |
|
652 TLex16 lextmp( param ); |
|
653 lextmp.Val( references ); |
|
654 references += aValueToAdd; |
|
655 TBuf<128> buf; |
|
656 buf.NumUC( references ); |
|
657 // set new ref_count |
|
658 CleanupStack::PushL( aItem ); |
|
659 aItem->SetAttributeL( KMenuAttrRefcount, buf ); |
|
660 CleanupStack::Pop( aItem ); |
|
661 // return new ref_count |
|
662 return references; |
|
663 } |
|
664 return -1; |
|
665 } |
|
666 |
|
667 |
417 |
668 // End of File. |
418 // End of File. |