Primitivus: added Gateways support

This commit is contained in:
Goffi 2010-08-12 13:18:22 +08:00
commit fa3557cbef
3 changed files with 189 additions and 39 deletions

View file

@ -0,0 +1,86 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Primitivus: a SAT frontend
Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import urwid
import custom_widgets
from tools.jid import JID
from quick_frontend.quick_gateways import QuickGatewaysManager
class GatewaysManager(urwid.WidgetWrap, QuickGatewaysManager):
def __init__(self, host, gateways, title=_("Gateways manager"), server=None):
QuickGatewaysManager.__init__(self, host, gateways, server)
widget_list = urwid.SimpleListWalker([])
widget_list.append(urwid.Text(self.WARNING_MSG))
widget_list.append(urwid.Divider('-'))
for gateway in gateways:
self.addGateway(widget_list,gateway, gateways[gateway])
widget_list.append(urwid.Divider())
self.ext_serv = custom_widgets.AdvancedEdit(_("Use external XMPP server: "))
go_button = custom_widgets.CustomButton( _("GO !"),self.browseExternalServer)
ext_serv_col = urwid.Columns([self.ext_serv,('fixed',go_button.getSize(),go_button)])
widget_list.append(ext_serv_col)
list_wid = urwid.ListBox(widget_list)
decorated = custom_widgets.LabelLine(list_wid, custom_widgets.SurroundedText(title))
urwid.WidgetWrap.__init__(self, decorated)
def browseExternalServer(self, button):
"""Open the gateway manager on given server"""
server = self.ext_serv.get_edit_text()
if not server:
popup = custom_widgets.Alert(_("Error"), _("You must enter an external server JID"), ok_cb=self.host.removePopUp)
self.host.showPopUp(popup)
return
id = self.host.bridge.findGateways(server, self.host.profile)
self.host.current_action_ids.add(id)
self.host.current_action_ids_cb[id] = self.host.onGatewaysFound
self.host.removeWindow()
def addGateway(self, widget_list, gateway, param):
widget_col = []
widget_col.append(('weight',4,urwid.Text(unicode(param['name'])))) #FIXME: unicode to be remove when DBus bridge will not give dbus.String anymore
#Then the transport type message
widget_col.append(('weight',6,urwid.Text(self.getGatewayDesc(param['type']))))
#The buttons
reg_button = custom_widgets.CustomButton( _("Register"), self.onRegister)
reg_button.gateway_jid = JID(gateway)
widget_col.append(('fixed',reg_button.getSize(),reg_button))
unreg_button = custom_widgets.CustomButton( _("Unregister"), self.onUnregister)
unreg_button.gateway_jid = JID(gateway)
widget_col.append(('fixed',unreg_button.getSize(),unreg_button))
widget_list.append(urwid.Columns(widget_col,1))
def onRegister(self, button):
"""Called when register button is clicked"""
gateway_jid = button.gateway_jid
id = self.host.bridge.in_band_register(gateway_jid, self.host.profile)
self.host.current_action_ids.add(id)
def onUnregister(self, button):
"""Called when unregister button is clicked"""
gateway_jid = button.gateway_jid
id = self.host.bridge.gatewayRegister("CANCEL",gateway_jid, None, self.host.profile)
self.host.current_action_ids.add(id)

View file

@ -28,6 +28,7 @@ import urwid
from profile_manager import ProfileManager
from contact_list import ContactList
from chat import Chat
from gateways import GatewaysManager
import custom_widgets
import pdb
import logging
@ -191,6 +192,7 @@ class PrimitivusApp(QuickApp):
menu.addMenu(contact, _("Remove contact"), self.onRemoveContactRequest)
communication = _("Communication")
menu.addMenu(communication, _("Join room"), self.onJoinRoomRequest, 'meta j')
menu.addMenu(communication, _("Find Gateways"), self.onFindGatewaysRequest, 'meta g')
#additionals menus
#FIXME: do this in a more generic way (in quickapp)
add_menus = self.bridge.getMenus()
@ -316,12 +318,30 @@ class PrimitivusApp(QuickApp):
misc = {}
#FIXME FIXME FIXME: must clean all this crap !
title = _('Form')
if data['type'] == _('registration'):
if data['type'] == 'registration':
title = _('Registration')
misc['target'] = data['target']
misc['action_back'] = self.bridge.gatewayRegister
ui = XMLUI(self, title=title, xml_data = data['xml'], misc = misc)
self.addWindow(ui)
if data['type'] == 'registration':
ui.show('popup')
else:
ui.show('window')
elif type == "ERROR":
self.current_action_ids.remove(id)
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
elif type == "RESULT":
self.current_action_ids.remove(id)
if self.current_action_ids_cb.has_key(id):
callback = self.current_action_ids_cb[id]
del self.current_action_ids_cb[id]
callback(data)
elif type == "DICT_DICT":
self.current_action_ids.remove(id)
if self.current_action_ids_cb.has_key(id):
callback = self.current_action_ids_cb[id]
del self.current_action_ids_cb[id]
callback(data)
else:
error (_("FIXME FIXME FIXME: type [%s] not implemented") % type)
raise NotImplementedError
@ -335,7 +355,7 @@ class PrimitivusApp(QuickApp):
else:
message = _("'%s' is an invalid JID !") % room_jid
error (message)
custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)
self.showPopUp(custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
def onAddContact(self, button, edit):
self.removePopUp()
@ -345,14 +365,14 @@ class PrimitivusApp(QuickApp):
else:
message = _("'%s' is an invalid JID !") % jid
error (message)
custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)
self.showPopUp(custom_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
def onRemoveContact(self, button):
self.removePopUp()
info(_("Unsubscribing %s presence"),self.contactList.get_contact())
self.bridge.delContact(self.contactList.get_contact(), profile_key=self.profile)
#Menu events#
#MENU EVENTS#
def onConnectRequest(self, menu):
self.bridge.connect(self.profile)
@ -371,6 +391,12 @@ class PrimitivusApp(QuickApp):
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)
self.showPopUp(pop_up_widget)
def onFindGatewaysRequest(self, e):
debug(_("Find Gateways request"))
id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain, self.profile)
self.current_action_ids.add(id)
self.current_action_ids_cb[id] = self.onGatewaysFound
def onAddContactRequest(self, menu):
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)
self.showPopUp(pop_up_widget)
@ -385,7 +411,15 @@ class PrimitivusApp(QuickApp):
def onAboutRequest(self, menu):
self.showPopUp(custom_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
#MISC CALLBACKS#
def onGatewaysFound(self, data):
"""Called when SàT has found the server gateways"""
target = data['__private__']['target']
del data['__private__']
gatewayManager = GatewaysManager(self, data, server=target)
self.addWindow(gatewayManager)
sat = PrimitivusApp()
sat.start()

View file

@ -38,8 +38,6 @@ class ProfileManager(urwid.WidgetWrap):
self.list_profile = List(profiles, style=['single'], align='center', on_click=self.onProfileChange)
#toto = urwid.Padding(urwid.Text('toto'), align='center')
#new & delete buttons
buttons = [urwid.Button(_("New"), self.onNewProfile),
urwid.Button(_("Delete"), self.onDeleteProfile)]