Mercurial > libervia-backend
annotate frontends/src/primitivus/gateways.py @ 613:0730fc83ef51
quick frontend, jp: fix locales
author | Thomas Preud'homme <robotux@celest.fr> |
---|---|
date | Sun, 07 Apr 2013 22:54:47 +0200 |
parents | 84a6e83157c2 |
children | bfabeedbf32e |
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 |
20 import urwid | |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
175
diff
changeset
|
21 from urwid_satext import sat_widgets |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
22 from sat_frontends.quick_frontend.quick_gateways import QuickGatewaysManager |
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
23 from sat.tools.jid import JID |
173 | 24 |
25 | |
26 class GatewaysManager(urwid.WidgetWrap, QuickGatewaysManager): | |
27 | |
28 def __init__(self, host, gateways, title=_("Gateways manager"), server=None): | |
29 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
|
30 if server: |
8537df794f74
Primitivus: gateways: current server is now shown in title
Goffi <goffi@goffi.org>
parents:
173
diff
changeset
|
31 title+=" (%s)" % server |
173 | 32 widget_list = urwid.SimpleListWalker([]) |
33 widget_list.append(urwid.Text(self.WARNING_MSG)) | |
34 widget_list.append(urwid.Divider('-')) | |
35 for gateway in gateways: | |
36 self.addGateway(widget_list,gateway, gateways[gateway]) | |
37 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
|
38 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
|
39 go_button = sat_widgets.CustomButton( _("GO !"),self.browseExternalServer) |
173 | 40 ext_serv_col = urwid.Columns([self.ext_serv,('fixed',go_button.getSize(),go_button)]) |
41 widget_list.append(ext_serv_col) | |
42 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
|
43 decorated = sat_widgets.LabelLine(list_wid, sat_widgets.SurroundedText(title)) |
173 | 44 urwid.WidgetWrap.__init__(self, decorated) |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
45 |
173 | 46 def browseExternalServer(self, button): |
47 """Open the gateway manager on given server""" | |
48 server = self.ext_serv.get_edit_text() | |
49 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
|
50 popup = sat_widgets.Alert(_("Error"), _("You must enter an external server JID"), ok_cb=self.host.removePopUp) |
173 | 51 self.host.showPopUp(popup) |
52 return | |
546
9dd297c513b4
primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
53 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
|
54 self.host.current_action_ids.add(action_id) |
9dd297c513b4
primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
55 self.host.current_action_ids_cb[action_id] = self.host.onGatewaysFound |
173 | 56 self.host.removeWindow() |
57 | |
58 def addGateway(self, widget_list, gateway, param): | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
59 |
173 | 60 widget_col = [] |
61 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
|
62 |
173 | 63 #Then the transport type message |
64 widget_col.append(('weight',6,urwid.Text(self.getGatewayDesc(param['type'])))) | |
65 | |
66 #The buttons | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
67 |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
175
diff
changeset
|
68 reg_button = sat_widgets.CustomButton( _("Register"), self.onRegister) |
173 | 69 reg_button.gateway_jid = JID(gateway) |
70 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
|
71 unreg_button = sat_widgets.CustomButton( _("Unregister"), self.onUnregister) |
173 | 72 unreg_button.gateway_jid = JID(gateway) |
73 widget_col.append(('fixed',unreg_button.getSize(),unreg_button)) | |
74 widget_list.append(urwid.Columns(widget_col,1)) | |
587
952322b1d490
Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
572
diff
changeset
|
75 |
173 | 76 def onRegister(self, button): |
77 """Called when register button is clicked""" | |
78 gateway_jid = button.gateway_jid | |
546
9dd297c513b4
primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
79 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
|
80 self.host.current_action_ids.add(action_id) |
173 | 81 |
82 def onUnregister(self, button): | |
83 """Called when unregister button is clicked""" | |
84 gateway_jid = button.gateway_jid | |
546
9dd297c513b4
primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
85 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
|
86 self.host.current_action_ids.add(action_id) |