Mercurial > libervia-web
diff src/browser/sat_browser/menu.py @ 679:a90cc8fc9605
merged branch frontends_multi_profiles
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 18 Mar 2015 16:15:18 +0100 |
parents | 849ffb24d5bf |
children | 801eb94aa869 |
line wrap: on
line diff
--- a/src/browser/sat_browser/menu.py Thu Feb 05 12:05:32 2015 +0100 +++ b/src/browser/sat_browser/menu.py Wed Mar 18 16:15:18 2015 +0100 @@ -21,22 +21,20 @@ 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 jid import file_tools import xmlui -import panels +import chat import dialog import contact_group import base_menu -from base_menu import MenuCmd +from sat_browser import html_tools + + +unicode = str # FIXME: pyjamas workaround class MainMenuBar(base_menu.GenericMenuBar): @@ -49,92 +47,23 @@ 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) - - -class MainMenuPanel(SimplePanel): - """Container for the main menu bar""" - - def __init__(self, host): - self.host = host - SimplePanel.__init__(self) - self.setStyleName('menuContainer') - self.menu_bar = MainMenuBar(self.host) - - def addMenuItem(self, *args): - self.menu_bar.addMenuItem(*args) - - def addCategory(self, *args): - self.menu_bar.addCategory(*args) + 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 - 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")) - - # additional menus - self.menu_bar.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.menu_bar.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")) - - self.add(self.menu_bar) + ## callbacks # General menu - def onWebWidget(self): - web_panel = panels.WebPanel(self.host, "http://www.goffi.org") - self.host.addWidget(web_panel) - self.host.setSelected(web_panel) def onDisconnect(self): def confirm_cb(answer): if answer: - # FIXME: are we sure the triggers finished their jobs when the backend disconnect? - # FIXME: disconnection on timeout is not handled yet... - for plugin in self.host.plugins.values(): - if hasattr(plugin, 'profileDisconnected'): - plugin.profileDisconnected() - log.info("disconnection") - self.host.bridge.call('disconnect', None) + self.host.disconnect(C.PROF_KEY_NONE) _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to disconnect ?") _dialog.show() - def onSocialContract(self): - _frame = Frame('contrat_social.html') - _frame.setStyleName('infoFrame') - _dialog = dialog.GenericDialog("Contrat Social", _frame) - _dialog.setSize('80%', '80%') - _dialog.show() + #Contact menu - def onAbout(self): - _about = HTML("""<b>Libervia</b>, a Salut à Toi project<br /> -<br /> -You can contact the author at <a href="mailto:goffi@goffi.org">goffi@goffi.org</a><br /> -Blog available (mainly in french) at <a href="http://www.goffi.org" target="_blank">http://www.goffi.org</a><br /> -Project page: <a href="http://sat.goffi.org"target="_blank">http://sat.goffi.org</a><br /> -<br /> -Any help welcome :) -<p style='font-size:small;text-align:center'>This project is dedicated to Roger Poisson</p> -""") - _dialog = dialog.GenericDialog("About", _about) - _dialog.show() - - #Contact menu def onManageContactGroups(self): """Open the contact groups manager.""" @@ -148,32 +77,41 @@ def invite(room_jid, contacts): for contact in contacts: - self.host.bridge.call('inviteMUC', None, contact, room_jid) - + 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 - if room_jid not in [room.bare for room in self.host.room_list]: - self.host.bridge.call('joinMUC', lambda room_jid: invite(room_jid, contacts), room_jid, nick) + 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.getOrCreateLiberviaWidget(panels.ChatPanel, {'item': room_jid, 'type_': "group"}, True, jid.JID(room_jid).bare) + 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): - self.host.bridge.call('launchRadioCollective', None, contacts, room_jid) - dialog.RoomAndContactsChooser(self.host, callback, ok_button="Choose", title="Collective Radio", visible=(False, True)) + # Help menu + + def onSocialContract(self): + _frame = Frame('contrat_social.html') + _frame.setStyleName('infoFrame') + _dialog = dialog.GenericDialog("Contrat Social", _frame) + _dialog.setSize('80%', '80%') + _dialog.show() - #Game menu - def onTarotGame(self): - def onPlayersSelected(room_jid, other_players): - self.host.bridge.call('launchTarotGame', None, other_players, room_jid) - 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") + def onAbout(self): + _about = HTML("""<b>Libervia</b>, a Salut à Toi project<br /> +<br /> +You can contact the authors at <a href="mailto:contact@salut-a-toi.org">contact@salut-a-toi.org</a><br /> +Blog available (mainly in french) at <a href="http://www.goffi.org" target="_blank">http://www.goffi.org</a><br /> +Project page: <a href="http://salut-a-toi.org"target="_blank">http://salut-a-toi.org</a><br /> +<br /> +Any help welcome :) +<p style='font-size:small;text-align:center'>This project is dedicated to Roger Poisson</p> +""") + _dialog = dialog.GenericDialog("About", _about) + _dialog.show() #Settings menu