Mercurial > libervia-backend
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 |
rev | line source |
---|---|
173 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
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 | 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 | 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 | 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 | 19 |
771 | 20 from sat.core.i18n import _ |
173 | 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 | 25 |
26 | |
27 class GatewaysManager(urwid.WidgetWrap, QuickGatewaysManager): | |
28 | |
29 def __init__(self, host, gateways, title=_("Gateways manager"), server=None): | |
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 | 33 widget_list = urwid.SimpleListWalker([]) |
34 widget_list.append(urwid.Text(self.WARNING_MSG)) | |
35 widget_list.append(urwid.Divider('-')) | |
36 for gateway in gateways: | |
37 self.addGateway(widget_list,gateway, gateways[gateway]) | |
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 | 41 ext_serv_col = urwid.Columns([self.ext_serv,('fixed',go_button.getSize(),go_button)]) |
42 widget_list.append(ext_serv_col) | |
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 | 45 urwid.WidgetWrap.__init__(self, decorated) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
46 |
173 | 47 def browseExternalServer(self, button): |
48 """Open the gateway manager on given server""" | |
49 server = self.ext_serv.get_edit_text() | |
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 | 52 self.host.showPopUp(popup) |
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 | 57 self.host.removeWindow() |
58 | |
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 | 61 widget_col = [] |
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 | 64 #Then the transport type message |
65 widget_col.append(('weight',6,urwid.Text(self.getGatewayDesc(param['type'])))) | |
66 | |
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 | 70 reg_button.gateway_jid = JID(gateway) |
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 | 73 unreg_button.gateway_jid = JID(gateway) |
74 widget_col.append(('fixed',unreg_button.getSize(),unreg_button)) | |
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 | 77 def onRegister(self, button): |
78 """Called when register button is clicked""" | |
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 | 82 |
83 def onUnregister(self, button): | |
84 """Called when unregister button is clicked""" | |
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) |