diff src/browser/sat_browser/contact_widget.py @ 676:849ffb24d5bf frontends_multi_profiles

browser side: menus refactorisation: - use of the new quick_frontends.quick_menus module, resulting in a big code simplification in Libervia - menu are added in there respective modules: main menus are done directely in libervia_main, while tarot and radiocol menus are done in game_tarot and game_radiocol - launchAction has the same signature as in QuickApp - base_menu: there are now 2 classes to launch an action: MenuCmd which manage quick_menus classes, and SimpleCmd to launch a generic callback - base_menu: MenuNode has been removed as logic is now in quick_menus - base_menu: GenericMenuBar.update method can be called to fully (re)build the menus - base_widget: removed WidgetSubMenuBar which is no more useful (GenericMenuBar do the same thing) - plugin_menu_context is used in LiberviaWidget and other classes with menus to indicate which menu types must be used - otr menus hooks are temporarily removed, will be fixed soon
author Goffi <goffi@goffi.org>
date Tue, 17 Mar 2015 20:42:02 +0100
parents 2201ff543a05
children e876f493dccc
line wrap: on
line diff
--- a/src/browser/sat_browser/contact_widget.py	Tue Mar 17 20:28:41 2015 +0100
+++ b/src/browser/sat_browser/contact_widget.py	Tue Mar 17 20:42:02 2015 +0100
@@ -22,6 +22,7 @@
 log = getLogger(__name__)
 
 from sat.core import exceptions
+from sat_frontends.quick_frontend import quick_menus
 from pyjamas.ui.VerticalPanel import VerticalPanel
 from pyjamas.ui.HTML import HTML
 from pyjamas.ui.Image import Image
@@ -114,24 +115,23 @@
 
 class ContactBox(VerticalPanel, ClickHandler, libervia_widget.DragLabel):
 
-    def __init__(self, host, jid_, style_name=None, menu_types=None, display=C.CONTACT_DEFAULT_DISPLAY):
+    def __init__(self, host, jid_, style_name=None, display=C.CONTACT_DEFAULT_DISPLAY, plugin_menu_context=None):
         """
         @param host (SatWebFrontend): host instance
         @param jid_ (jid.JID): contact JID
         @param style_name (unicode): CSS style name
-        @param menu_types (tuple): define the menu types that fit this
-            contact panel, with values from the menus type constants.
         @param contacts_display (tuple): prioritize the display methods of the
             contact's label with values in ("jid", "nick", "bare", "resource").
+        @param plugin_menu_context (iterable): contexts of menus to have (list of C.MENU_* constant)
 
         """
+        self.plugin_menu_context = [] if plugin_menu_context is None else plugin_menu_context
         VerticalPanel.__init__(self, StyleName=style_name or 'contactBox', VerticalAlignment='middle')
         ClickHandler.__init__(self)
         libervia_widget.DragLabel.__init__(self, jid_, "CONTACT", host)
         self.jid = jid_
         self.label = ContactLabel(host, self.jid, display=display)
-        self.menu_types = menu_types
-        self.avatar = ContactMenuBar(self, host) if menu_types else Image()
+        self.avatar = ContactMenuBar(self, host) if plugin_menu_context else Image()
         try:  # FIXME: dirty hack to force using an Image when the menu is actually empty
             self.avatar.items[0]
         except IndexError:
@@ -141,10 +141,6 @@
         self.add(self.label)
         self.addClickListener(self)
 
-    def addMenus(self, menu_bar):
-        for menu_type in self.menu_types:
-            menu_bar.addCachedMenus(menu_type, {'jid': unicode(self.jid.bare)})
-
     def setAlert(self, alert):
         """Show a visual indicator
 
@@ -172,3 +168,5 @@
             pass
         else:
             self.setAlert(False)
+
+quick_menus.QuickMenusManager.addDataCollector(C.MENU_JID_CONTEXT, lambda caller, dummy: {'jid': unicode(caller.jid.bare)})