annotate frontends/wix/gateways.py @ 35:c45deebb40a5

Wix: Registration form management (not finished yet) - impoved xml conversion in xml_tools
author Goffi <goffi@goffi.org>
date Sun, 13 Dec 2009 20:24:48 +1100
parents d6b613764dd7
children a61beb21d16d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/python
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
3
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
4 """
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
5 wix: a SAT frontend
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
7
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
11 (at your option) any later version.
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
12
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
16 GNU General Public License for more details.
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
17
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
20 """
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
21
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
22
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
23
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
24 import wx
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
25 import pdb
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from xml.dom import minidom
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from logging import debug, info, error
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from tools.jid import JID
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
29
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
30
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
31 class GatewaysManager(wx.Frame):
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
32 def __init__(self, host, gateways, title="Gateways manager"):
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
33 super(GatewaysManager, self).__init__(None, title=title)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
34
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
35 self.host = host
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
36
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
37 #Fonts
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
38 self.normal_font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
39 self.bold_font = wx.Font(8, wx.DEFAULT, wx.NORMAL, wx.BOLD)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
40 self.italic_font = wx.Font(8, wx.DEFAULT, wx.FONTSTYLE_ITALIC, wx.NORMAL)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
41
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
42
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
43 self.modified = {} # dict of modified data (i.e. what we have to save)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
44 self.ctl_list = {} # usefull to access ctrl, key = (name, category)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
45
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.sizer = wx.BoxSizer(wx.VERTICAL)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
47 self.panel = wx.Panel(self)
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
48 self.panel.sizer = wx.FlexGridSizer(cols=4)
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.panel.SetSizer(self.panel.sizer)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.panel.SetAutoLayout(True)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.sizer.Add(self.panel, 1, flag=wx.EXPAND)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.SetSizer(self.sizer)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
53 self.SetAutoLayout(True)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
54
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
55 #events
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
56 self.Bind(wx.EVT_CLOSE, self.onClose, self)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
57
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
58 self.MakeModal()
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
59 self.panel.sizer.Add(wx.Window(self.panel, -1))
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
60 title_name = wx.StaticText(self.panel, -1, "Name")
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
61 title_name.SetFont(self.bold_font)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
62 title_type = wx.StaticText(self.panel, -1, "Type")
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
63 title_type.SetFont(self.bold_font)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
64 self.panel.sizer.Add(title_name)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
65 self.panel.sizer.Add(title_type)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
66 self.panel.sizer.Add(wx.Window(self.panel, -1))
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
67
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
68 for gateway in gateways:
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
69 self.addGateway(gateway, gateways[gateway])
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
70
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
71
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.panel.sizer.Fit(self)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
73
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.Show()
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
75
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
76 def addGateway(self, gateway, param):
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
77
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
78
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
79
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
80 #First The icon
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
81 isz = (16,16)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
82 im_icon = wx.StaticBitmap(self.panel, -1, wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD, wx.ART_TOOLBAR, isz))
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
83
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
84 #Then the name
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
85
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
86 label=wx.StaticText(self.panel, -1, param['name'])
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
87 label.SetFont(self.normal_font)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
88
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
89 #Then the transport type message
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
90
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
91 type_label_txt = 'Unknown IM'
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
92
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
93 if param['type'] == 'irc':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
94 type_label_txt = "Internet Relay Chat"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
95 elif param['type'] == 'xmpp':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
96 type_label_txt = "XMPP"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
97 elif param['type'] == 'qq':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
98 type_label_txt = "Tencent QQ"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
99 elif param['type'] == 'simple':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
100 type_label_txt = "SIP/SIMPLE"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
101 elif param['type'] == 'icq':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
102 type_label_txt = "ICQ"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
103 elif param['type'] == 'yahoo':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
104 type_label_txt = "Yahoo! Messenger"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
105 elif param['type'] == 'gadu-gadu':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
106 type_label_txt = "Gadu-Gadu"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
107 elif param['type'] == 'aim':
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
108 type_label_txt = "AOL Instant Messenger"
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
109 elif param['type'] == 'msn':
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
110 type_label_txt = 'Windows Live Messenger'
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
111
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
112 type_label_txt = type_label_txt
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
113
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
114 type_label = wx.StaticText(self.panel, -1, type_label_txt)
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
115 type_label.SetFont(self.italic_font)
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
116
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
117 #The buttons
30
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 29
diff changeset
118 def register_cb(event):
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 29
diff changeset
119 """Called when register button is clicked"""
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 29
diff changeset
120 gateway_jid = event.GetEventObject().gateway_jid
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 29
diff changeset
121 id = self.host.bridge.in_band_register(gateway_jid)
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 29
diff changeset
122 self.host.current_action_ids.add(id)
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 29
diff changeset
123 print "register id:",id
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 29
diff changeset
124 event.Skip()
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 29
diff changeset
125
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
126 button_font = wx.Font(6, wx.DEFAULT, wx.NORMAL, wx.BOLD)
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
127 reg_button = wx.Button(self.panel, -1, "Register", size=wx.Size(-1, 8))
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
128 reg_button.SetFont(button_font)
30
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 29
diff changeset
129 reg_button.gateway_jid = JID(gateway)
d6b613764dd7 new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents: 29
diff changeset
130 self.panel.Bind(wx.EVT_BUTTON, register_cb, reg_button)
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
131
29
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
132 self.panel.sizer.Add(im_icon)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
133 self.panel.sizer.Add(label)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
134 self.panel.sizer.Add(type_label)
df3b0b5ac49e Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents: 28
diff changeset
135 self.panel.sizer.Add(reg_button, 1, wx.EXPAND)
28
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
136
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
137
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
138 def onClose(self, event):
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
139 """Close event"""
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
140 debug("close")
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
141 #now we save the modifier params
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
142 self.MakeModal(False)
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
143 event.Skip()
c2b131e4e262 wix: new gateways manager
Goffi <goffi@goffi.org>
parents:
diff changeset
144