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