Mercurial > libervia-web
comparison 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 |
comparison
equal
deleted
inserted
replaced
590:1bffc4c244c3 | 679:a90cc8fc9605 |
---|---|
19 | 19 |
20 import pyjd # this is dummy in pyjs | 20 import pyjd # this is dummy in pyjs |
21 from sat.core.log import getLogger | 21 from sat.core.log import getLogger |
22 log = getLogger(__name__) | 22 log = getLogger(__name__) |
23 | 23 |
24 from sat.core.i18n import _ | |
25 | |
26 from pyjamas.ui.SimplePanel import SimplePanel | |
27 from pyjamas.ui.HTML import HTML | 24 from pyjamas.ui.HTML import HTML |
28 from pyjamas.ui.Frame import Frame | 25 from pyjamas.ui.Frame import Frame |
29 from pyjamas import Window | |
30 | 26 |
31 from constants import Const as C | 27 from constants import Const as C |
32 import jid | |
33 import file_tools | 28 import file_tools |
34 import xmlui | 29 import xmlui |
35 import panels | 30 import chat |
36 import dialog | 31 import dialog |
37 import contact_group | 32 import contact_group |
38 import base_menu | 33 import base_menu |
39 from base_menu import MenuCmd | 34 from sat_browser import html_tools |
35 | |
36 | |
37 unicode = str # FIXME: pyjamas workaround | |
40 | 38 |
41 | 39 |
42 class MainMenuBar(base_menu.GenericMenuBar): | 40 class MainMenuBar(base_menu.GenericMenuBar): |
43 """The main menu bar which is displayed on top of the document""" | 41 """The main menu bar which is displayed on top of the document""" |
44 | 42 |
47 def __init__(self, host): | 45 def __init__(self, host): |
48 styles = {'moved_popup': 'menuLastPopup', 'menu_bar': 'mainMenuBar'} | 46 styles = {'moved_popup': 'menuLastPopup', 'menu_bar': 'mainMenuBar'} |
49 base_menu.GenericMenuBar.__init__(self, host, vertical=False, styles=styles) | 47 base_menu.GenericMenuBar.__init__(self, host, vertical=False, styles=styles) |
50 | 48 |
51 @classmethod | 49 @classmethod |
52 def getCategoryHTML(cls, menu_name_i18n, type_): | 50 def getCategoryHTML(cls, category): |
53 return cls.ITEM_TPL % (type_, menu_name_i18n) | 51 name = html_tools.html_sanitize(category.name) |
52 return cls.ITEM_TPL % (category.icon, name) if category.icon is not None else name | |
54 | 53 |
55 | 54 ## callbacks |
56 class MainMenuPanel(SimplePanel): | |
57 """Container for the main menu bar""" | |
58 | |
59 def __init__(self, host): | |
60 self.host = host | |
61 SimplePanel.__init__(self) | |
62 self.setStyleName('menuContainer') | |
63 self.menu_bar = MainMenuBar(self.host) | |
64 | |
65 def addMenuItem(self, *args): | |
66 self.menu_bar.addMenuItem(*args) | |
67 | |
68 def addCategory(self, *args): | |
69 self.menu_bar.addCategory(*args) | |
70 | |
71 def createMenus(self): | |
72 self.addMenuItem("General", [_("General"), _("Web widget")], 'home', MenuCmd(self, "onWebWidget")) | |
73 self.addMenuItem("General", [_("General"), _("Disconnect")], 'home', MenuCmd(self, "onDisconnect")) | |
74 self.addCategory("Contacts", _("Contacts"), 'social') # save the position for this category | |
75 self.addMenuItem("Groups", [_("Groups"), _("Discussion")], 'social', MenuCmd(self, "onJoinRoom")) | |
76 self.addMenuItem("Groups", [_("Groups"), _("Collective radio")], 'social', MenuCmd(self, "onCollectiveRadio")) | |
77 self.addMenuItem("Games", [_("Games"), _("Tarot")], 'games', MenuCmd(self, "onTarotGame")) | |
78 self.addMenuItem("Games", [_("Games"), _("Xiangqi")], 'games', MenuCmd(self, "onXiangqiGame")) | |
79 | |
80 # additional menus | |
81 self.menu_bar.addCachedMenus(C.MENU_GLOBAL) | |
82 | |
83 # menu items that should be displayed after the automatically added ones | |
84 self.addMenuItem("Contacts", [_("Contacts"), _("Manage groups")], 'social', MenuCmd(self, "onManageContactGroups")) | |
85 | |
86 self.menu_bar.addSeparator() | |
87 | |
88 self.addMenuItem("Help", [_("Help"), _("Social contract")], 'help', MenuCmd(self, "onSocialContract")) | |
89 self.addMenuItem("Help", [_("Help"), _("About")], 'help', MenuCmd(self, "onAbout")) | |
90 self.addMenuItem("Settings", [_("Settings"), _("Account")], 'settings', MenuCmd(self, "onAccount")) | |
91 self.addMenuItem("Settings", [_("Settings"), _("Parameters")], 'settings', MenuCmd(self, "onParameters")) | |
92 | |
93 # XXX: temporary, will change when a full profile will be managed in SàT | |
94 self.addMenuItem("Settings", [_("Settings"), _("Upload avatar")], 'settings', MenuCmd(self, "onAvatarUpload")) | |
95 | |
96 self.add(self.menu_bar) | |
97 | 55 |
98 # General menu | 56 # General menu |
99 def onWebWidget(self): | |
100 web_panel = panels.WebPanel(self.host, "http://www.goffi.org") | |
101 self.host.addWidget(web_panel) | |
102 self.host.setSelected(web_panel) | |
103 | 57 |
104 def onDisconnect(self): | 58 def onDisconnect(self): |
105 def confirm_cb(answer): | 59 def confirm_cb(answer): |
106 if answer: | 60 if answer: |
107 # FIXME: are we sure the triggers finished their jobs when the backend disconnect? | 61 self.host.disconnect(C.PROF_KEY_NONE) |
108 # FIXME: disconnection on timeout is not handled yet... | |
109 for plugin in self.host.plugins.values(): | |
110 if hasattr(plugin, 'profileDisconnected'): | |
111 plugin.profileDisconnected() | |
112 log.info("disconnection") | |
113 self.host.bridge.call('disconnect', None) | |
114 _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to disconnect ?") | 62 _dialog = dialog.ConfirmDialog(confirm_cb, text="Do you really want to disconnect ?") |
115 _dialog.show() | 63 _dialog.show() |
116 | 64 |
117 def onSocialContract(self): | 65 #Contact menu |
118 _frame = Frame('contrat_social.html') | |
119 _frame.setStyleName('infoFrame') | |
120 _dialog = dialog.GenericDialog("Contrat Social", _frame) | |
121 _dialog.setSize('80%', '80%') | |
122 _dialog.show() | |
123 | 66 |
124 def onAbout(self): | |
125 _about = HTML("""<b>Libervia</b>, a Salut à Toi project<br /> | |
126 <br /> | |
127 You can contact the author at <a href="mailto:goffi@goffi.org">goffi@goffi.org</a><br /> | |
128 Blog available (mainly in french) at <a href="http://www.goffi.org" target="_blank">http://www.goffi.org</a><br /> | |
129 Project page: <a href="http://sat.goffi.org"target="_blank">http://sat.goffi.org</a><br /> | |
130 <br /> | |
131 Any help welcome :) | |
132 <p style='font-size:small;text-align:center'>This project is dedicated to Roger Poisson</p> | |
133 """) | |
134 _dialog = dialog.GenericDialog("About", _about) | |
135 _dialog.show() | |
136 | |
137 #Contact menu | |
138 def onManageContactGroups(self): | 67 def onManageContactGroups(self): |
139 """Open the contact groups manager.""" | 68 """Open the contact groups manager.""" |
140 | 69 |
141 def onCloseCallback(): | 70 def onCloseCallback(): |
142 pass | 71 pass |
146 #Group menu | 75 #Group menu |
147 def onJoinRoom(self): | 76 def onJoinRoom(self): |
148 | 77 |
149 def invite(room_jid, contacts): | 78 def invite(room_jid, contacts): |
150 for contact in contacts: | 79 for contact in contacts: |
151 self.host.bridge.call('inviteMUC', None, contact, room_jid) | 80 self.host.bridge.call('inviteMUC', None, unicode(contact), unicode(room_jid)) |
152 | |
153 def join(room_jid, contacts): | 81 def join(room_jid, contacts): |
154 if self.host.whoami: | 82 if self.host.whoami: |
155 nick = self.host.whoami.node | 83 nick = self.host.whoami.node |
156 if room_jid not in [room.bare for room in self.host.room_list]: | 84 contact_list = self.host.contact_list |
157 self.host.bridge.call('joinMUC', lambda room_jid: invite(room_jid, contacts), room_jid, nick) | 85 if room_jid is None or room_jid not in contact_list.getSpecials(C.CONTACT_SPECIAL_GROUP): |
86 room_jid_s = unicode(room_jid) if room_jid else '' | |
87 self.host.bridge.call('joinMUC', lambda room_jid: invite(room_jid, contacts), room_jid_s, nick) | |
158 else: | 88 else: |
159 self.host.getOrCreateLiberviaWidget(panels.ChatPanel, {'item': room_jid, 'type_': "group"}, True, jid.JID(room_jid).bare) | 89 self.host.displayWidget(chat.Chat, room_jid, type_="group", new_tab=room_jid) |
160 invite(room_jid, contacts) | 90 invite(room_jid, contacts) |
161 | 91 |
162 dialog.RoomAndContactsChooser(self.host, join, ok_button="Join", visible=(True, False)) | 92 dialog.RoomAndContactsChooser(self.host, join, ok_button="Join", visible=(True, False)) |
163 | 93 |
164 def onCollectiveRadio(self): | 94 # Help menu |
165 def callback(room_jid, contacts): | |
166 self.host.bridge.call('launchRadioCollective', None, contacts, room_jid) | |
167 dialog.RoomAndContactsChooser(self.host, callback, ok_button="Choose", title="Collective Radio", visible=(False, True)) | |
168 | 95 |
169 #Game menu | 96 def onSocialContract(self): |
170 def onTarotGame(self): | 97 _frame = Frame('contrat_social.html') |
171 def onPlayersSelected(room_jid, other_players): | 98 _frame.setStyleName('infoFrame') |
172 self.host.bridge.call('launchTarotGame', None, other_players, room_jid) | 99 _dialog = dialog.GenericDialog("Contrat Social", _frame) |
173 dialog.RoomAndContactsChooser(self.host, onPlayersSelected, 3, title="Tarot", title_invite="Please select 3 other players", visible=(False, True)) | 100 _dialog.setSize('80%', '80%') |
101 _dialog.show() | |
174 | 102 |
175 def onXiangqiGame(self): | 103 def onAbout(self): |
176 Window.alert("A Xiangqi game is planed, but not available yet") | 104 _about = HTML("""<b>Libervia</b>, a Salut à Toi project<br /> |
105 <br /> | |
106 You can contact the authors at <a href="mailto:contact@salut-a-toi.org">contact@salut-a-toi.org</a><br /> | |
107 Blog available (mainly in french) at <a href="http://www.goffi.org" target="_blank">http://www.goffi.org</a><br /> | |
108 Project page: <a href="http://salut-a-toi.org"target="_blank">http://salut-a-toi.org</a><br /> | |
109 <br /> | |
110 Any help welcome :) | |
111 <p style='font-size:small;text-align:center'>This project is dedicated to Roger Poisson</p> | |
112 """) | |
113 _dialog = dialog.GenericDialog("About", _about) | |
114 _dialog.show() | |
177 | 115 |
178 #Settings menu | 116 #Settings menu |
179 | 117 |
180 def onAccount(self): | 118 def onAccount(self): |
181 def gotUI(xml_ui): | 119 def gotUI(xml_ui): |