annotate frontends/src/primitivus/gateways.py @ 801:02ee9ef95277

plugin XEP-0045, primitivus: added MUC configuration
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:06:12 +0100
parents bfabeedbf32e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
4 # Primitivus: a SAT frontend
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
10 # (at your option) any later version.
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
15 # GNU Affero General Public License for more details.
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 587
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 609
diff changeset
20 from sat.core.i18n import _
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import urwid
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 175
diff changeset
22 from urwid_satext import sat_widgets
225
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
23 from sat_frontends.quick_frontend.quick_gateways import QuickGatewaysManager
fd9b7834d98a distutils installation script, draft
Goffi <goffi@goffi.org>
parents: 223
diff changeset
24 from sat.tools.jid import JID
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
25
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
26
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
27 class GatewaysManager(urwid.WidgetWrap, QuickGatewaysManager):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
28
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
29 def __init__(self, host, gateways, title=_("Gateways manager"), server=None):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
30 QuickGatewaysManager.__init__(self, host, gateways, server)
175
8537df794f74 Primitivus: gateways: current server is now shown in title
Goffi <goffi@goffi.org>
parents: 173
diff changeset
31 if server:
8537df794f74 Primitivus: gateways: current server is now shown in title
Goffi <goffi@goffi.org>
parents: 173
diff changeset
32 title+=" (%s)" % server
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
33 widget_list = urwid.SimpleListWalker([])
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
34 widget_list.append(urwid.Text(self.WARNING_MSG))
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
35 widget_list.append(urwid.Divider('-'))
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
36 for gateway in gateways:
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
37 self.addGateway(widget_list,gateway, gateways[gateway])
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
38 widget_list.append(urwid.Divider())
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 175
diff changeset
39 self.ext_serv = sat_widgets.AdvancedEdit(_("Use external XMPP server: "))
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 175
diff changeset
40 go_button = sat_widgets.CustomButton( _("GO !"),self.browseExternalServer)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
41 ext_serv_col = urwid.Columns([self.ext_serv,('fixed',go_button.getSize(),go_button)])
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
42 widget_list.append(ext_serv_col)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
43 list_wid = urwid.ListBox(widget_list)
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 175
diff changeset
44 decorated = sat_widgets.LabelLine(list_wid, sat_widgets.SurroundedText(title))
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
45 urwid.WidgetWrap.__init__(self, decorated)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
46
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
47 def browseExternalServer(self, button):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
48 """Open the gateway manager on given server"""
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
49 server = self.ext_serv.get_edit_text()
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
50 if not server:
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 175
diff changeset
51 popup = sat_widgets.Alert(_("Error"), _("You must enter an external server JID"), ok_cb=self.host.removePopUp)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.host.showPopUp(popup)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
53 return
546
9dd297c513b4 primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents: 480
diff changeset
54 action_id = self.host.bridge.findGateways(server, self.host.profile)
9dd297c513b4 primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents: 480
diff changeset
55 self.host.current_action_ids.add(action_id)
9dd297c513b4 primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents: 480
diff changeset
56 self.host.current_action_ids_cb[action_id] = self.host.onGatewaysFound
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
57 self.host.removeWindow()
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
58
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def addGateway(self, widget_list, gateway, param):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
60
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
61 widget_col = []
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
62 widget_col.append(('weight',4,urwid.Text(unicode(param['name'])))) #FIXME: unicode to be remove when DBus bridge will not give dbus.String anymore
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
63
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
64 #Then the transport type message
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
65 widget_col.append(('weight',6,urwid.Text(self.getGatewayDesc(param['type']))))
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
66
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
67 #The buttons
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
68
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 175
diff changeset
69 reg_button = sat_widgets.CustomButton( _("Register"), self.onRegister)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
70 reg_button.gateway_jid = JID(gateway)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
71 widget_col.append(('fixed',reg_button.getSize(),reg_button))
222
3198bfd66daa primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents: 175
diff changeset
72 unreg_button = sat_widgets.CustomButton( _("Unregister"), self.onUnregister)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
73 unreg_button.gateway_jid = JID(gateway)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
74 widget_col.append(('fixed',unreg_button.getSize(),unreg_button))
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
75 widget_list.append(urwid.Columns(widget_col,1))
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 572
diff changeset
76
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
77 def onRegister(self, button):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
78 """Called when register button is clicked"""
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
79 gateway_jid = button.gateway_jid
546
9dd297c513b4 primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents: 480
diff changeset
80 action_id = self.host.bridge.in_band_register(gateway_jid, self.host.profile)
9dd297c513b4 primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents: 480
diff changeset
81 self.host.current_action_ids.add(action_id)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
82
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
83 def onUnregister(self, button):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
84 """Called when unregister button is clicked"""
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
85 gateway_jid = button.gateway_jid
546
9dd297c513b4 primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents: 480
diff changeset
86 action_id = self.host.bridge.gatewayRegister("CANCEL",gateway_jid, None, self.host.profile)
9dd297c513b4 primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents: 480
diff changeset
87 self.host.current_action_ids.add(action_id)