Mercurial > libervia-backend
changeset 173:ec6611445a5b
Primitivus: added Gateways support
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 12 Aug 2010 13:18:22 +0800 |
parents | 726786e914c3 |
children | fbae69247b15 |
files | frontends/primitivus/gateways.py frontends/primitivus/primitivus frontends/primitivus/profile_manager.py frontends/quick_frontend/quick_gateways.py frontends/wix/gateways.py |
diffstat | 5 files changed, 189 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontends/primitivus/gateways.py Thu Aug 12 13:18:22 2010 +0800 @@ -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)
--- a/frontends/primitivus/primitivus Thu Aug 12 13:18:11 2010 +0800 +++ b/frontends/primitivus/primitivus Thu Aug 12 13:18:22 2010 +0800 @@ -28,6 +28,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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()
--- a/frontends/primitivus/profile_manager.py Thu Aug 12 13:18:11 2010 +0800 +++ b/frontends/primitivus/profile_manager.py Thu Aug 12 13:18:22 2010 +0800 @@ -38,8 +38,6 @@ 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)]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/frontends/quick_frontend/quick_gateways.py Thu Aug 12 13:18:22 2010 +0800 @@ -0,0 +1,57 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +""" +helper class for making 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/>. +""" + + + + +class QuickGatewaysManager(): + + + def __init__(self, host, gateways, title=_("Gateways manager"), server=None): + self.WARNING_MSG = _(u"""Be careful ! Gateways allow you to use an external IM (legacy IM), so you can see your contact as jabber contacts. +But when you do this, all your messages go throught the external legacy IM server, it is a huge privacy issue (i.e.: all your messages throught the gateway can be monitored, recorded, analyzed by the external server, most of time a private company).""") + self.host = host + + def getGatewayDesc(self, gat_type): + """Return a human readable description of gateway type + @param gat_type: type of gateway, as given by SàT""" + desc = _('Unknown IM') + + if gat_type == 'irc': + desc = "Internet Relay Chat" + elif gat_type == 'xmpp': + desc = "XMPP" + elif gat_type == 'qq': + desc = "Tencent QQ" + elif gat_type == 'simple': + desc = "SIP/SIMPLE" + elif gat_type == 'icq': + desc = "ICQ" + elif gat_type == 'yahoo': + desc = "Yahoo! Messenger" + elif gat_type == 'gadu-gadu': + desc = "Gadu-Gadu" + elif gat_type == 'aim': + desc = "AOL Instant Messenger" + elif gat_type == 'msn': + desc = 'Windows Live Messenger' + + return desc
--- a/frontends/wix/gateways.py Thu Aug 12 13:18:11 2010 +0800 +++ b/frontends/wix/gateways.py Thu Aug 12 13:18:22 2010 +0800 @@ -26,15 +26,14 @@ from xml.dom import minidom from logging import debug, info, error from tools.jid import JID +from quick_frontend.quick_gateways import QuickGatewaysManager -WARNING_MSG = _(u"""Be careful ! Gateways allow you to use an external IM (legacy IM), so you can see your contact as jabber contacts. -But when you do this, all your messages go throught the external legacy IM server, it is a huge privacy issue (i.e.: all your messages throught the gateway can be monitored, recorded, analyzed by the external server, most of time a private company).""") +class GatewaysManager(wx.Frame,QuickGatewaysManager): -class GatewaysManager(wx.Frame): def __init__(self, host, gateways, title=_("Gateways manager"), server=None): - super(GatewaysManager, self).__init__(None, title=title) + wx.Frame.__init__(self, None, title=title) + QuickGatewaysManager.__init__(self, host, gateways, server) - self.host = host if server: self.SetTitle(title+" (%s)" % server) @@ -49,7 +48,7 @@ self.ctl_list = {} # usefull to access ctrl, key = (name, category) self.sizer = wx.BoxSizer(wx.VERTICAL) - warning = wx.TextCtrl(self, -1, value=WARNING_MSG, style = wx.TE_MULTILINE | + warning = wx.TextCtrl(self, -1, value=self.WARNING_MSG, style = wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_LEFT) warning.SetFont(self.bold_font) @@ -113,8 +112,6 @@ def addGateway(self, gateway, param): - - #First The icon isz = (16,16) @@ -126,29 +123,7 @@ label.SetFont(self.normal_font) #Then the transport type message - - type_label_txt = _('Unknown IM') - - if param['type'] == 'irc': - type_label_txt = "Internet Relay Chat" - elif param['type'] == 'xmpp': - type_label_txt = "XMPP" - elif param['type'] == 'qq': - type_label_txt = "Tencent QQ" - elif param['type'] == 'simple': - type_label_txt = "SIP/SIMPLE" - elif param['type'] == 'icq': - type_label_txt = "ICQ" - elif param['type'] == 'yahoo': - type_label_txt = "Yahoo! Messenger" - elif param['type'] == 'gadu-gadu': - type_label_txt = "Gadu-Gadu" - elif param['type'] == 'aim': - type_label_txt = "AOL Instant Messenger" - elif param['type'] == 'msn': - type_label_txt = 'Windows Live Messenger' - - type_label_txt = type_label_txt + type_label_txt = self.getGatewayDesc(param['type']) type_label = wx.StaticText(self.panel, -1, type_label_txt) type_label.SetFont(self.italic_font)