173
|
1 #!/usr/bin/python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 """ |
|
5 Primitivus: a SAT frontend |
|
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) |
|
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 |
|
23 import custom_widgets |
|
24 from tools.jid import JID |
|
25 from quick_frontend.quick_gateways import QuickGatewaysManager |
|
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) |
|
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()) |
|
38 self.ext_serv = custom_widgets.AdvancedEdit(_("Use external XMPP server: ")) |
|
39 go_button = custom_widgets.CustomButton( _("GO !"),self.browseExternalServer) |
|
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) |
|
43 decorated = custom_widgets.LabelLine(list_wid, custom_widgets.SurroundedText(title)) |
|
44 urwid.WidgetWrap.__init__(self, decorated) |
|
45 |
|
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: |
|
50 popup = custom_widgets.Alert(_("Error"), _("You must enter an external server JID"), ok_cb=self.host.removePopUp) |
|
51 self.host.showPopUp(popup) |
|
52 return |
|
53 id = self.host.bridge.findGateways(server, self.host.profile) |
|
54 self.host.current_action_ids.add(id) |
|
55 self.host.current_action_ids_cb[id] = self.host.onGatewaysFound |
|
56 self.host.removeWindow() |
|
57 |
|
58 def addGateway(self, widget_list, gateway, param): |
|
59 |
|
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 |
|
62 |
|
63 #Then the transport type message |
|
64 widget_col.append(('weight',6,urwid.Text(self.getGatewayDesc(param['type'])))) |
|
65 |
|
66 #The buttons |
|
67 |
|
68 reg_button = custom_widgets.CustomButton( _("Register"), self.onRegister) |
|
69 reg_button.gateway_jid = JID(gateway) |
|
70 widget_col.append(('fixed',reg_button.getSize(),reg_button)) |
|
71 unreg_button = custom_widgets.CustomButton( _("Unregister"), self.onUnregister) |
|
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)) |
|
75 |
|
76 def onRegister(self, button): |
|
77 """Called when register button is clicked""" |
|
78 gateway_jid = button.gateway_jid |
|
79 id = self.host.bridge.in_band_register(gateway_jid, self.host.profile) |
|
80 self.host.current_action_ids.add(id) |
|
81 |
|
82 def onUnregister(self, button): |
|
83 """Called when unregister button is clicked""" |
|
84 gateway_jid = button.gateway_jid |
|
85 id = self.host.bridge.gatewayRegister("CANCEL",gateway_jid, None, self.host.profile) |
|
86 self.host.current_action_ids.add(id) |