comparison browser_side/menu.py @ 431:4fcf9bac109c

browser_side: roster management menus are now imported from the backend
author souliane <souliane@mailoo.org>
date Mon, 07 Apr 2014 23:31:21 +0200
parents f539f6f8ee9c
children 8ecc5a7062e4
comparison
equal deleted inserted replaced
430:a927a98b398d 431:4fcf9bac109c
104 try: 104 try:
105 menu_bar = menus_dict[menu_name] 105 menu_bar = menus_dict[menu_name]
106 except KeyError: 106 except KeyError:
107 menu_bar = menus_dict[menu_name] = MenuBar(vertical=True) 107 menu_bar = menus_dict[menu_name] = MenuBar(vertical=True)
108 menus_order.append((menu_name, menu_name_i18n, icon)) 108 menus_order.append((menu_name, menu_name_i18n, icon))
109 menu_bar.addItem(item_name_i18n, menu_cmd) 109 if item_name_i18n and menu_cmd:
110 menu_bar.addItem(item_name_i18n, menu_cmd)
110 111
111 addMenu("General", _("General"), _("Web widget"), 'home', MenuCmd(self, "onWebWidget")) 112 addMenu("General", _("General"), _("Web widget"), 'home', MenuCmd(self, "onWebWidget"))
112 addMenu("General", _("General"), _("Disconnect"), 'home', MenuCmd(self, "onDisconnect")) 113 addMenu("General", _("General"), _("Disconnect"), 'home', MenuCmd(self, "onDisconnect"))
113 addMenu("Contacts", _("Contacts"), _("Add contact"), 'social', MenuCmd(self, "onAddContact")) 114 addMenu("Contacts", _("Contacts"), None, 'social', None)
114 addMenu("Contacts", _("Contacts"), _("Update contact"), 'social', MenuCmd(self, "onUpdateContact"))
115 addMenu("Contacts", _("Contacts"), _("Remove contact"), 'social', MenuCmd(self, "onRemoveContact"))
116 addMenu("Contacts", _("Contacts"), _("Manage groups"), 'social', MenuCmd(self, "onManageContactGroups"))
117 addMenu("Groups", _("Groups"), _("Discussion"), 'social', MenuCmd(self, "onJoinRoom")) 115 addMenu("Groups", _("Groups"), _("Discussion"), 'social', MenuCmd(self, "onJoinRoom"))
118 addMenu("Groups", _("Groups"), _("Collective radio"), 'social', MenuCmd(self, "onCollectiveRadio")) 116 addMenu("Groups", _("Groups"), _("Collective radio"), 'social', MenuCmd(self, "onCollectiveRadio"))
119 addMenu("Games", _("Games"), _("Tarot"), 'games', MenuCmd(self, "onTarotGame")) 117 addMenu("Games", _("Games"), _("Tarot"), 'games', MenuCmd(self, "onTarotGame"))
120 addMenu("Games", _("Games"), _("Xiangqi"), 'games', MenuCmd(self, "onXiangqiGame")) 118 addMenu("Games", _("Games"), _("Xiangqi"), 'games', MenuCmd(self, "onXiangqiGame"))
121 119
134 print "WARNING: skipping menu with a path of lenght 1 [%s]" % path[0] 132 print "WARNING: skipping menu with a path of lenght 1 [%s]" % path[0]
135 continue 133 continue
136 item_name_i18n = ' | '.join(path_i18n[1:]) 134 item_name_i18n = ' | '.join(path_i18n[1:])
137 addMenu(menu_name, menu_name_i18n, item_name_i18n, 'plugins', PluginMenuCmd(self.host, action_id)) 135 addMenu(menu_name, menu_name_i18n, item_name_i18n, 'plugins', PluginMenuCmd(self.host, action_id))
138 136
137 # menu items that should be displayed after the automatically added ones
138 addMenu("Contacts", _("Contacts"), _("Manage groups"), 'social', MenuCmd(self, "onManageContactGroups"))
139
139 menus_order.append(None) # we add separator 140 menus_order.append(None) # we add separator
140 141
141 addMenu("Help", _("Help"), _("Social contract"), 'help', MenuCmd(self, "onSocialContract")) 142 addMenu("Help", _("Help"), _("Social contract"), 'help', MenuCmd(self, "onSocialContract"))
142 addMenu("Help", _("Help"), _("About"), 'help', MenuCmd(self, "onAbout")) 143 addMenu("Help", _("Help"), _("About"), 'help', MenuCmd(self, "onAbout"))
143 addMenu("Settings", _("Settings"), _("Account"), 'settings', MenuCmd(self, "onAccount")) 144 addMenu("Settings", _("Settings"), _("Account"), 'settings', MenuCmd(self, "onAccount"))
192 """) 193 """)
193 _dialog = dialog.GenericDialog("About", _about) 194 _dialog = dialog.GenericDialog("About", _about)
194 _dialog.show() 195 _dialog.show()
195 196
196 #Contact menu 197 #Contact menu
197 def onAddContact(self):
198 """Q&D contact addition"""
199 _dialog = None
200 edit = TextBox()
201
202 def addContactCb(sender):
203 if not re.match(r'^.+@.+\..+', edit.getText(), re.IGNORECASE):
204 Window.alert('You must enter a valid contact JID (like "contact@%s")' % self.host._defaultDomain)
205 _dialog.show()
206 else:
207 self.host.bridge.call('addContact', None, edit.getText(), '', _dialog.getSelectedGroups())
208
209 label = Label("New contact identifier (JID):")
210 edit.setText('@%s' % self.host._defaultDomain)
211 edit.setWidth('100%')
212 _dialog = dialog.GroupSelector([label, edit], self.host.contact_panel.getGroups(), [],
213 "Add", addContactCb)
214 _dialog.setHTML('Adding contact')
215 _dialog.show()
216
217 def onUpdateContact(self):
218 _dialog = None
219 _contacts_list = ListBox()
220
221 def updateContactCb(sender):
222 _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex())
223 self.host.bridge.call('updateContact', None, _jid, '', _dialog.getSelectedGroups())
224
225 def onContactChange(_list):
226 _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex())
227 groups = self.host.contact_panel.getContactGroups(_jid)
228 _dialog.setGroupsSelected(groups)
229
230 for contact in self.host.contact_panel.getContacts():
231 _contacts_list.addItem(contact)
232 _contacts_list.addChangeListener(onContactChange)
233 _jid = _contacts_list.getValue(_contacts_list.getSelectedIndex())
234 _selected_groups = self.host.contact_panel.getContactGroups(_jid)
235 _dialog = dialog.GroupSelector([Label('Which contact do you want to update ?'), _contacts_list],
236 self.host.contact_panel.getGroups(), _selected_groups,
237 "Update", updateContactCb)
238 _dialog.setHTML('Updating contact')
239 _dialog.show()
240
241 def onRemoveContact(self):
242 _dialog = None
243 _contacts_list = ListBox()
244
245 def secondConfirmCb(confirm):
246 if confirm:
247 for contact in _contacts_list.getSelectedValues():
248 self.host.bridge.call('delContact', None, contact)
249 else:
250 _dialog.show()
251
252 def dialogCb(confirm):
253 if confirm:
254 html_list = ''.join(['<li>%s</li>' % html_sanitize(contact) for contact in _contacts_list.getSelectedValues()])
255 html_body = "Are you sure to remove the following contacts from your contact list ?<ul>%s</ul>" % html_list
256 dialog.ConfirmDialog(secondConfirmCb, html_body).show()
257
258 for contact in self.host.contact_panel.getContacts():
259 _contacts_list.addItem(contact)
260 _dialog = dialog.GenericConfirmDialog([_contacts_list], dialogCb, "Who do you want to remove from your contacts ?")
261 _dialog.show()
262
263 def onManageContactGroups(self): 198 def onManageContactGroups(self):
264 """Open the contact groups manager.""" 199 """Open the contact groups manager."""
265 200
266 def onCloseCallback(): 201 def onCloseCallback():
267 pass 202 pass