comparison frontends/primitivus/primitivus @ 173:ec6611445a5b

Primitivus: added Gateways support
author Goffi <goffi@goffi.org>
date Thu, 12 Aug 2010 13:18:22 +0800
parents a2655a0a4eac
children a50953ac6191
comparison
equal deleted inserted replaced
172:726786e914c3 173:ec6611445a5b
26 from quick_frontend.quick_contact_management import QuickContactManagement 26 from quick_frontend.quick_contact_management import QuickContactManagement
27 import urwid 27 import urwid
28 from profile_manager import ProfileManager 28 from profile_manager import ProfileManager
29 from contact_list import ContactList 29 from contact_list import ContactList
30 from chat import Chat 30 from chat import Chat
31 from gateways import GatewaysManager
31 import custom_widgets 32 import custom_widgets
32 import pdb 33 import pdb
33 import logging 34 import logging
34 from logging import debug, info, error 35 from logging import debug, info, error
35 import sys, os 36 import sys, os
189 contact = _("Contact") 190 contact = _("Contact")
190 menu.addMenu(contact, _("Add contact"), self.onAddContactRequest) 191 menu.addMenu(contact, _("Add contact"), self.onAddContactRequest)
191 menu.addMenu(contact, _("Remove contact"), self.onRemoveContactRequest) 192 menu.addMenu(contact, _("Remove contact"), self.onRemoveContactRequest)
192 communication = _("Communication") 193 communication = _("Communication")
193 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j') 194 menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
195 menu.addMenu(communication, _("Find Gateways"), self.onFindGatewaysRequest, 'meta g')
194 #additionals menus 196 #additionals menus
195 #FIXME: do this in a more generic way (in quickapp) 197 #FIXME: do this in a more generic way (in quickapp)
196 add_menus = self.bridge.getMenus() 198 add_menus = self.bridge.getMenus()
197 def add_menu_cb(menu): 199 def add_menu_cb(menu):
198 category, item = menu 200 category, item = menu
314 self.current_action_ids.remove(id) 316 self.current_action_ids.remove(id)
315 debug (_("XML user interface received")) 317 debug (_("XML user interface received"))
316 misc = {} 318 misc = {}
317 #FIXME FIXME FIXME: must clean all this crap ! 319 #FIXME FIXME FIXME: must clean all this crap !
318 title = _('Form') 320 title = _('Form')
319 if data['type'] == _('registration'): 321 if data['type'] == 'registration':
320 title = _('Registration') 322 title = _('Registration')
321 misc['target'] = data['target'] 323 misc['target'] = data['target']
322 misc['action_back'] = self.bridge.gatewayRegister 324 misc['action_back'] = self.bridge.gatewayRegister
323 ui = XMLUI(self, title=title, xml_data = data['xml'], misc = misc) 325 ui = XMLUI(self, title=title, xml_data = data['xml'], misc = misc)
324 self.addWindow(ui) 326 if data['type'] == 'registration':
327 ui.show('popup')
328 else:
329 ui.show('window')
330 elif type == "ERROR":
331 self.current_action_ids.remove(id)
332 self.showPopUp(custom_widgets.Alert(_("Error"), unicode(data["message"]), ok_cb=self.removePopUp)) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
333 elif type == "RESULT":
334 self.current_action_ids.remove(id)
335 if self.current_action_ids_cb.has_key(id):
336 callback = self.current_action_ids_cb[id]
337 del self.current_action_ids_cb[id]
338 callback(data)
339 elif type == "DICT_DICT":
340 self.current_action_ids.remove(id)
341 if self.current_action_ids_cb.has_key(id):
342 callback = self.current_action_ids_cb[id]
343 del self.current_action_ids_cb[id]
344 callback(data)
325 else: 345 else:
326 error (_("FIXME FIXME FIXME: type [%s] not implemented") % type) 346 error (_("FIXME FIXME FIXME: type [%s] not implemented") % type)
327 raise NotImplementedError 347 raise NotImplementedError
328 348
329 ##DIALOGS CALLBACKS## 349 ##DIALOGS CALLBACKS##
333 if room_jid.is_valid(): 353 if room_jid.is_valid():
334 self.bridge.joinMUC(room_jid.domain, room_jid.node, self.profiles[self.profile]['whoami'].node, self.profile) 354 self.bridge.joinMUC(room_jid.domain, room_jid.node, self.profiles[self.profile]['whoami'].node, self.profile)
335 else: 355 else:
336 message = _("'%s' is an invalid JID !") % room_jid 356 message = _("'%s' is an invalid JID !") % room_jid
337 error (message) 357 error (message)
338 custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp) 358 self.showPopUp(custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
339 359
340 def onAddContact(self, button, edit): 360 def onAddContact(self, button, edit):
341 self.removePopUp() 361 self.removePopUp()
342 jid=JID(edit.get_edit_text()) 362 jid=JID(edit.get_edit_text())
343 if jid.is_valid(): 363 if jid.is_valid():
344 self.bridge.addContact(jid.short, profile_key=self.profile) 364 self.bridge.addContact(jid.short, profile_key=self.profile)
345 else: 365 else:
346 message = _("'%s' is an invalid JID !") % jid 366 message = _("'%s' is an invalid JID !") % jid
347 error (message) 367 error (message)
348 custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp) 368 self.showPopUp(custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
349 369
350 def onRemoveContact(self, button): 370 def onRemoveContact(self, button):
351 self.removePopUp() 371 self.removePopUp()
352 info(_("Unsubscribing %s presence"),self.contactList.get_contact()) 372 info(_("Unsubscribing %s presence"),self.contactList.get_contact())
353 self.bridge.delContact(self.contactList.get_contact(), profile_key=self.profile) 373 self.bridge.delContact(self.contactList.get_contact(), profile_key=self.profile)
354 374
355 #Menu events# 375 #MENU EVENTS#
356 def onConnectRequest(self, menu): 376 def onConnectRequest(self, menu):
357 self.bridge.connect(self.profile) 377 self.bridge.connect(self.profile)
358 378
359 def onDisconnectRequest(self, menu): 379 def onDisconnectRequest(self, menu):
360 self.bridge.disconnect(self.profile) 380 self.bridge.disconnect(self.profile)
369 def onJoinRoomRequest(self, menu): 389 def onJoinRoomRequest(self, menu):
370 """User wants to join a MUC room""" 390 """User wants to join a MUC room"""
371 pop_up_widget = custom_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'test@conference.necton2.int', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom) 391 pop_up_widget = custom_widgets.InputDialog(_("Entering a MUC room"), _("Please enter MUC's JID"), default_txt = 'test@conference.necton2.int', cancel_cb=self.removePopUp, ok_cb=self.onJoinRoom)
372 self.showPopUp(pop_up_widget) 392 self.showPopUp(pop_up_widget)
373 393
394 def onFindGatewaysRequest(self, e):
395 debug(_("Find Gateways request"))
396 id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain, self.profile)
397 self.current_action_ids.add(id)
398 self.current_action_ids_cb[id] = self.onGatewaysFound
399
374 def onAddContactRequest(self, menu): 400 def onAddContactRequest(self, menu):
375 pop_up_widget = custom_widgets.InputDialog(_("Adding a contact"), _("Please enter new contact JID"), default_txt = 'name@server.tld', cancel_cb=self.removePopUp, ok_cb=self.onAddContact) 401 pop_up_widget = custom_widgets.InputDialog(_("Adding a contact"), _("Please enter new contact JID"), default_txt = 'name@server.tld', cancel_cb=self.removePopUp, ok_cb=self.onAddContact)
376 self.showPopUp(pop_up_widget) 402 self.showPopUp(pop_up_widget)
377 403
378 def onRemoveContactRequest(self, menu): 404 def onRemoveContactRequest(self, menu):
383 pop_up_widget = custom_widgets.ConfirmDialog(_("Are you sure you want to delete the contact [%s] ?" % contact), yes_cb=self.onRemoveContact, no_cb=self.removePopUp) 409 pop_up_widget = custom_widgets.ConfirmDialog(_("Are you sure you want to delete the contact [%s] ?" % contact), yes_cb=self.onRemoveContact, no_cb=self.removePopUp)
384 self.showPopUp(pop_up_widget) 410 self.showPopUp(pop_up_widget)
385 411
386 def onAboutRequest(self, menu): 412 def onAboutRequest(self, menu):
387 self.showPopUp(custom_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp)) 413 self.showPopUp(custom_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
388 414
415 #MISC CALLBACKS#
416
417 def onGatewaysFound(self, data):
418 """Called when SàT has found the server gateways"""
419 target = data['__private__']['target']
420 del data['__private__']
421 gatewayManager = GatewaysManager(self, data, server=target)
422 self.addWindow(gatewayManager)
389 423
390 sat = PrimitivusApp() 424 sat = PrimitivusApp()
391 sat.start() 425 sat.start()
392 426