diff src/browser/sat_browser/menu.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 a8fddccf5b84
children 801eb94aa869
line wrap: on
line diff
--- a/src/browser/sat_browser/menu.py	Tue Mar 17 20:28:41 2015 +0100
+++ b/src/browser/sat_browser/menu.py	Tue Mar 17 20:42:02 2015 +0100
@@ -21,22 +21,17 @@
 from sat.core.log import getLogger
 log = getLogger(__name__)
 
-from sat.core.i18n import _
-
-from pyjamas.ui.SimplePanel import SimplePanel
 from pyjamas.ui.HTML import HTML
 from pyjamas.ui.Frame import Frame
-from pyjamas import Window
 
 from constants import Const as C
 import file_tools
 import xmlui
 import chat
-import widget
 import dialog
 import contact_group
 import base_menu
-from base_menu import MenuCmd
+from sat_browser import html_tools
 
 
 unicode = str  # FIXME: pyjamas workaround
@@ -52,38 +47,13 @@
         base_menu.GenericMenuBar.__init__(self, host, vertical=False, styles=styles)
 
     @classmethod
-    def getCategoryHTML(cls, menu_name_i18n, type_):
-        return cls.ITEM_TPL % (type_, menu_name_i18n)
-
-    def createMenus(self):
-        self.addMenuItem("General", [_("General"), _("Web widget")], 'home', MenuCmd(self, "onWebWidget"))
-        self.addMenuItem("General", [_("General"), _("Disconnect")], 'home', MenuCmd(self, "onDisconnect"))
-        self.addCategory("Contacts", _("Contacts"), 'social')  # save the position for this category
-        self.addMenuItem("Groups", [_("Groups"), _("Discussion")], 'social', MenuCmd(self, "onJoinRoom"))
-        self.addMenuItem("Groups", [_("Groups"), _("Collective radio")], 'social', MenuCmd(self, "onCollectiveRadio"))
-        self.addMenuItem("Games", [_("Games"), _("Tarot")], 'games', MenuCmd(self, "onTarotGame"))
-        self.addMenuItem("Games", [_("Games"), _("Xiangqi")], 'games', MenuCmd(self, "onXiangqiGame"))
+    def getCategoryHTML(cls, category):
+        name = html_tools.html_sanitize(category.name)
+        return cls.ITEM_TPL % (category.icon, name) if category.icon is not None else name
 
-        # additional menus
-        self.addCachedMenus(C.MENU_GLOBAL)
-
-        # menu items that should be displayed after the automatically added ones
-        self.addMenuItem("Contacts", [_("Contacts"), _("Manage groups")], 'social', MenuCmd(self, "onManageContactGroups"))
-
-        self.addSeparator()
-
-        self.addMenuItem("Help", [_("Help"), _("Social contract")], 'help', MenuCmd(self, "onSocialContract"))
-        self.addMenuItem("Help", [_("Help"), _("About")], 'help', MenuCmd(self, "onAbout"))
-        self.addMenuItem("Settings", [_("Settings"), _("Account")], 'settings', MenuCmd(self, "onAccount"))
-        self.addMenuItem("Settings", [_("Settings"), _("Parameters")], 'settings', MenuCmd(self, "onParameters"))
-
-        # XXX: temporary, will change when a full profile will be managed in SàT
-        self.addMenuItem("Settings", [_("Settings"), _("Upload avatar")], 'settings', MenuCmd(self, "onAvatarUpload"))
+    ## callbacks
 
     # General menu
-    def onWebWidget(self):
-        web_widget = self.host.displayWidget(widget.WebWidget, C.WEB_PANEL_DEFAULT_URL)
-        self.host.setSelected(web_widget)
 
     def onDisconnect(self):
         def confirm_cb(answer):
@@ -92,6 +62,37 @@
         _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to disconnect ?")
         _dialog.show()
 
+    #Contact menu
+
+    def onManageContactGroups(self):
+        """Open the contact groups manager."""
+
+        def onCloseCallback():
+            pass
+
+        contact_group.ContactGroupEditor(self.host, None, onCloseCallback)
+
+    #Group menu
+    def onJoinRoom(self):
+
+        def invite(room_jid, contacts):
+            for contact in contacts:
+                self.host.bridge.call('inviteMUC', None, unicode(contact), unicode(room_jid))
+        def join(room_jid, contacts):
+            if self.host.whoami:
+                nick = self.host.whoami.node
+                contact_list = self.host.contact_list
+                if room_jid is None or room_jid not in contact_list.getSpecials(C.CONTACT_SPECIAL_GROUP):
+                    room_jid_s = unicode(room_jid) if room_jid else ''
+                    self.host.bridge.call('joinMUC', lambda room_jid: invite(room_jid, contacts), room_jid_s, nick)
+                else:
+                    self.host.displayWidget(chat.Chat, room_jid, type_="group", new_tab=room_jid)
+                    invite(room_jid, contacts)
+
+        dialog.RoomAndContactsChooser(self.host, join, ok_button="Join", visible=(True, False))
+
+    # Help menu
+
     def onSocialContract(self):
         _frame = Frame('contrat_social.html')
         _frame.setStyleName('infoFrame')
@@ -112,53 +113,6 @@
         _dialog = dialog.GenericDialog("About", _about)
         _dialog.show()
 
-    #Contact menu
-    def onManageContactGroups(self):
-        """Open the contact groups manager."""
-
-        def onCloseCallback():
-            pass
-
-        contact_group.ContactGroupEditor(self.host, None, onCloseCallback)
-
-    #Group menu
-    def onJoinRoom(self):
-
-        def invite(room_jid, contacts):
-            for contact in contacts:
-                self.host.bridge.call('inviteMUC', None, unicode(contact), unicode(room_jid))
-
-        def join(room_jid, contacts):
-            if self.host.whoami:
-                nick = self.host.whoami.node
-                contact_list = self.host.contact_list
-                if room_jid is None or room_jid not in contact_list.getSpecials(C.CONTACT_SPECIAL_GROUP):
-                    room_jid_s = unicode(room_jid) if room_jid else ''
-                    self.host.bridge.call('joinMUC', lambda room_jid: invite(room_jid, contacts), room_jid_s, nick)
-                else:
-                    self.host.displayWidget(chat.Chat, room_jid, type_="group", new_tab=room_jid)
-                    invite(room_jid, contacts)
-
-        dialog.RoomAndContactsChooser(self.host, join, ok_button="Join", visible=(True, False))
-
-    def onCollectiveRadio(self):
-        def callback(room_jid, contacts):
-            contacts = [unicode(contact) for contact in contacts]
-            room_jid_s = unicode(room_jid) if room_jid else ''
-            self.host.bridge.call('launchRadioCollective', None, contacts, room_jid_s)
-        dialog.RoomAndContactsChooser(self.host, callback, ok_button="Choose", title="Collective Radio", visible=(False, True))
-
-    #Game menu
-    def onTarotGame(self):
-        def onPlayersSelected(room_jid, other_players):
-            other_players = [unicode(contact) for contact in other_players]
-            room_jid_s = unicode(room_jid) if room_jid else ''
-            self.host.bridge.call('launchTarotGame', None, other_players, room_jid_s)
-        dialog.RoomAndContactsChooser(self.host, onPlayersSelected, 3, title="Tarot", title_invite="Please select 3 other players", visible=(False, True))
-
-    def onXiangqiGame(self):
-        Window.alert("A Xiangqi game is planed, but not available yet")
-
     #Settings menu
 
     def onAccount(self):