comparison browser_side/menu.py @ 268:79970bf6af93

browser_side: added class RoomAndContactsChooser: - unified UI for all the MUC menu items callbacks to join a room, invite people and start a game
author souliane <souliane@mailoo.org>
date Sun, 17 Nov 2013 17:57:14 +0100
parents 377de26d5bc2
children 0cb9869b42b6
comparison
equal deleted inserted replaced
267:a76243c02074 268:79970bf6af93
225 Window.alert('You must enter a valid contact JID (like "contact@%s")' % self.host._defaultDomain) 225 Window.alert('You must enter a valid contact JID (like "contact@%s")' % self.host._defaultDomain)
226 _dialog.show() 226 _dialog.show()
227 else: 227 else:
228 self.host.bridge.call('addContact', None, edit.getText(), '', _dialog.getSelectedGroups() ) 228 self.host.bridge.call('addContact', None, edit.getText(), '', _dialog.getSelectedGroups() )
229 229
230 label = Label("new contact identifier (JID):") 230 label = Label("New contact identifier (JID):")
231 edit.setText('@%s' % self.host._defaultDomain) 231 edit.setText('@%s' % self.host._defaultDomain)
232 edit.setWidth('100%') 232 edit.setWidth('100%')
233 _dialog = dialog.GroupSelector([label, edit], self.host.contact_panel.getGroups(), [], 233 _dialog = dialog.GroupSelector([label, edit], self.host.contact_panel.getGroups(), [],
234 "Add", addContactCb) 234 "Add", addContactCb)
235 _dialog.setHTML('Adding contact') 235 _dialog.setHTML('Adding contact')
289 289
290 ContactGroupEditor(self.host, None, onCloseCallback) 290 ContactGroupEditor(self.host, None, onCloseCallback)
291 291
292 #Group menu 292 #Group menu
293 def onJoinRoom(self): 293 def onJoinRoom(self):
294 _dialog = None 294
295 _edit = None 295 def invite(room_jid, contacts):
296 296 for contact in contacts:
297 def onOK(sender): 297 self.host.bridge.call('inviteMUC', None, contact, room_jid)
298 if not _edit.getText(): 298
299 Window.alert('You must enter a room jid in the form room@chat.%s' % self.host._defaultDomain) 299 def join(room_jid, contacts):
300 if self.host.whoami: 300 if self.host.whoami:
301 nick = self.host.whoami.node 301 nick = self.host.whoami.node
302 self.host.bridge.call('joinMUC', None, _edit.getText(), nick) 302 if room_jid not in [room.bare for room in self.host.room_list]:
303 _dialog.hide() 303 self.host.bridge.call('joinMUC', lambda room_jid: invite(room_jid, contacts), room_jid, nick)
304 304 else:
305 def onCancel(sender): 305 self.host.getOrCreateLiberviaWidget(panels.ChatPanel, (room_jid, "group"), True, JID(room_jid).bare)
306 _dialog.hide() 306 invite(room_jid, contacts)
307 307
308 _main_panel = VerticalPanel() 308 dialog.RoomAndContactsChooser(self.host, join, ok_button="Join", visible=(True, False))
309 _label = Label("Discussion room:")
310 _edit = TextBox()
311 _edit.setText('sat@chat.jabberfr.org')
312 hpanel = HorizontalPanel()
313 hpanel.add(_label)
314 hpanel.add(_edit)
315 _main_panel.add(hpanel)
316 button_panel = HorizontalPanel()
317 button_panel.addStyleName("marginAuto")
318 button_panel.add(Button("Join", onOK))
319 button_panel.add(Button("Cancel", onCancel))
320 _main_panel.add(button_panel)
321 _dialog = DialogBox(centered=True)
322 _dialog.setHTML('Group discussions')
323 _dialog.setWidget(_main_panel)
324 _dialog.show()
325 309
326 def onCollectiveRadio(self): 310 def onCollectiveRadio(self):
327 def onContactsSelected(contacts): 311 def callback(room_jid, contacts):
328 print("let's go :)") 312 self.host.bridge.call('launchRadioCollective', None, contacts, room_jid)
329 self.host.bridge.call('launchRadioCollective', None, contacts) 313 dialog.RoomAndContactsChooser(self.host, callback, ok_button="Choose", visible=(False, True))
330 dialog.ContactsChooser(self.host, onContactsSelected, None, text="Please select contacts to invite").getContacts()
331 314
332 #Game menu 315 #Game menu
333
334 def onTarotGame(self): 316 def onTarotGame(self):
335 #Window.alert("Tarot selected") 317 def onPlayersSelected(room_jid, other_players):
336 #self.host.tab_panel.add(EmptyPanel(self.host), "Tarot") 318 self.host.bridge.call('launchTarotGame', None, other_players, room_jid)
337 def onPlayersSelected(other_players): 319 dialog.RoomAndContactsChooser(self.host, onPlayersSelected, 3, title_invite="Please select 3 other players", visible=(False, True))
338 self.host.bridge.call('launchTarotGame', None, other_players)
339 dialog.ContactsChooser(self.host, onPlayersSelected, 3, text="Please select 3 other players").getContacts()
340 320
341 def onXiangqiGame(self): 321 def onXiangqiGame(self):
342 Window.alert("A Xiangqi game is planed, but not available yet") 322 Window.alert("A Xiangqi game is planed, but not available yet")
343 323
344 #Settings menu 324 #Settings menu