annotate frontends/src/primitivus/gateways.py @ 557:4f856dd4c0d0

core: paramaters are now merged: if a parameter doens't exist in loaded xml but exists in default parameters, it is added
author Goffi <goffi@goffi.org>
date Sun, 16 Dec 2012 18:01:06 +0100
parents 9dd297c513b4
children ca13633d3b6b
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
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
5 Primitivus: a SAT frontend
459
cf005701624b copyleft date update
Goffi <goffi@goffi.org>
parents: 228
diff changeset
6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
7
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
480
2a072735e459 Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents: 459
diff changeset
9 it under the terms of the GNU Affero General Public License as published by
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
12
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
480
2a072735e459 Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents: 459
diff changeset
16 GNU Affero General Public License for more details.
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
17
480
2a072735e459 Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents: 459
diff changeset
18 You should have received a copy of the GNU Affero General Public License
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
21
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
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
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
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
28 class GatewaysManager(urwid.WidgetWrap, QuickGatewaysManager):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
29
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
30 def __init__(self, host, gateways, title=_("Gateways manager"), server=None):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
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
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
34 widget_list = urwid.SimpleListWalker([])
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
35 widget_list.append(urwid.Text(self.WARNING_MSG))
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
36 widget_list.append(urwid.Divider('-'))
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
37 for gateway in gateways:
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
38 self.addGateway(widget_list,gateway, gateways[gateway])
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
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
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
42 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
43 widget_list.append(ext_serv_col)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
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
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
46 urwid.WidgetWrap.__init__(self, decorated)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
47
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def browseExternalServer(self, button):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
49 """Open the gateway manager on given server"""
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
50 server = self.ext_serv.get_edit_text()
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
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
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.host.showPopUp(popup)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
54 return
546
9dd297c513b4 primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents: 480
diff changeset
55 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
56 self.host.current_action_ids.add(action_id)
9dd297c513b4 primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents: 480
diff changeset
57 self.host.current_action_ids_cb[action_id] = self.host.onGatewaysFound
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.host.removeWindow()
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
59
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def addGateway(self, widget_list, gateway, param):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
61
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
62 widget_col = []
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
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
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
64
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
65 #Then the transport type message
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
66 widget_col.append(('weight',6,urwid.Text(self.getGatewayDesc(param['type']))))
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
67
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
68 #The buttons
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
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
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
71 reg_button.gateway_jid = JID(gateway)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
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
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
74 unreg_button.gateway_jid = JID(gateway)
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
75 widget_col.append(('fixed',unreg_button.getSize(),unreg_button))
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
76 widget_list.append(urwid.Columns(widget_col,1))
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
77
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
78 def onRegister(self, button):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
79 """Called when register button is clicked"""
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
80 gateway_jid = button.gateway_jid
546
9dd297c513b4 primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents: 480
diff changeset
81 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
82 self.host.current_action_ids.add(action_id)
173
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
83
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
84 def onUnregister(self, button):
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
85 """Called when unregister button is clicked"""
ec6611445a5b Primitivus: added Gateways support
Goffi <goffi@goffi.org>
parents:
diff changeset
86 gateway_jid = button.gateway_jid
546
9dd297c513b4 primitivus: fixed actionResult call (fix gateways management)
Goffi <goffi@goffi.org>
parents: 480
diff changeset
87 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
88 self.host.current_action_ids.add(action_id)