Mercurial > libervia-backend
annotate frontends/wix/gateways.py @ 37:a61beb21d16d
Gateway registration, unregistration & edition
- default values added in form
- DBus bridge: fixed array of struct management when adding dynamically a method
- fixed doc for some methods
- ugly fix for presence status
- added dependency for XEP-0077 in XEP-0100 plugin
- Wix: added unregister button in gateways manager
- Wix: added privacy warning in gateways manager
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 15 Dec 2009 01:27:32 +1100 |
parents | c45deebb40a5 |
children | 2e3411a6baad |
rev | line source |
---|---|
28 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 wix: a SAT frontend | |
6 Copyright (C) 2009 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 | |
23 | |
24 import wx | |
25 import pdb | |
26 from xml.dom import minidom | |
27 from logging import debug, info, error | |
28 from tools.jid import JID | |
29 | |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
30 WARNING_MSG = u"""Be careful ! Gateways allow you to use an external IM (legacy IM), so you can see your contact as jabber contacts. |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
31 But when you do this, all your messages go throught the external legacy IM server, it is a huge privacy issue (i.e.: all your messages throught the gateway can be monitored, recorded, analyzed by the external server, most of time a private company).""" |
28 | 32 |
33 class GatewaysManager(wx.Frame): | |
34 def __init__(self, host, gateways, title="Gateways manager"): | |
35 super(GatewaysManager, self).__init__(None, title=title) | |
36 | |
37 self.host = host | |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
38 |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
39 #Fonts |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
40 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
|
41 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
|
42 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
|
43 |
28 | 44 |
45 self.modified = {} # dict of modified data (i.e. what we have to save) | |
46 self.ctl_list = {} # usefull to access ctrl, key = (name, category) | |
47 | |
48 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
49 warning = wx.TextCtrl(self, -1, value=WARNING_MSG, style = wx.TE_MULTILINE | |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
50 wx.TE_READONLY | |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
51 wx.TE_LEFT) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
52 warning.SetFont(self.bold_font) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
53 self.sizer.Add(warning, 0, wx.EXPAND) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
54 warning.ShowPosition(0) |
28 | 55 self.panel = wx.Panel(self) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
56 self.panel.sizer = wx.FlexGridSizer(cols=5) |
28 | 57 self.panel.SetSizer(self.panel.sizer) |
58 self.panel.SetAutoLayout(True) | |
59 self.sizer.Add(self.panel, 1, flag=wx.EXPAND) | |
60 self.SetSizer(self.sizer) | |
61 self.SetAutoLayout(True) | |
62 | |
63 #events | |
64 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
65 | |
66 self.MakeModal() | |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
67 self.panel.sizer.Add(wx.Window(self.panel, -1)) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
68 title_name = wx.StaticText(self.panel, -1, "Name") |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
69 title_name.SetFont(self.bold_font) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
70 title_type = wx.StaticText(self.panel, -1, "Type") |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
71 title_type.SetFont(self.bold_font) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
72 self.panel.sizer.Add(title_name) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
73 self.panel.sizer.Add(title_type) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
74 self.panel.sizer.Add(wx.Window(self.panel, -1)) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
75 self.panel.sizer.Add(wx.Window(self.panel, -1)) |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
76 |
28 | 77 for gateway in gateways: |
78 self.addGateway(gateway, gateways[gateway]) | |
79 | |
80 | |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
81 #self.panel.sizer.Fit(self) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
82 self.sizer.Fit(self) |
28 | 83 |
84 self.Show() | |
85 | |
86 def addGateway(self, gateway, param): | |
87 | |
88 | |
89 | |
90 #First The icon | |
91 isz = (16,16) | |
92 im_icon = wx.StaticBitmap(self.panel, -1, wx.ArtProvider.GetBitmap(wx.ART_GO_FORWARD, wx.ART_TOOLBAR, isz)) | |
93 | |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
94 #Then the name |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
95 |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
96 label=wx.StaticText(self.panel, -1, param['name']) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
97 label.SetFont(self.normal_font) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
98 |
28 | 99 #Then the transport type message |
100 | |
101 type_label_txt = 'Unknown IM' | |
102 | |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
103 if param['type'] == 'irc': |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
104 type_label_txt = "Internet Relay Chat" |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
105 elif param['type'] == 'xmpp': |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
106 type_label_txt = "XMPP" |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
107 elif param['type'] == 'qq': |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
108 type_label_txt = "Tencent QQ" |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
109 elif param['type'] == 'simple': |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
110 type_label_txt = "SIP/SIMPLE" |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
111 elif param['type'] == 'icq': |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
112 type_label_txt = "ICQ" |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
113 elif param['type'] == 'yahoo': |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
114 type_label_txt = "Yahoo! Messenger" |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
115 elif param['type'] == 'gadu-gadu': |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
116 type_label_txt = "Gadu-Gadu" |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
117 elif param['type'] == 'aim': |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
118 type_label_txt = "AOL Instant Messenger" |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
119 elif param['type'] == 'msn': |
28 | 120 type_label_txt = 'Windows Live Messenger' |
121 | |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
122 type_label_txt = type_label_txt |
28 | 123 |
124 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
|
125 type_label.SetFont(self.italic_font) |
28 | 126 |
127 #The buttons | |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
128 def register_cb(event): |
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
129 """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
|
130 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
|
131 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
|
132 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
|
133 print "register id:",id |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
134 self.MakeModal(False) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
135 self.Destroy() |
30
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
136 event.Skip() |
d6b613764dd7
new plugin for xep 0077 (In-Band registration): first draft
Goffi <goffi@goffi.org>
parents:
29
diff
changeset
|
137 |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
138 def unregister_cb(event): |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
139 """Called when unregister button is clicked""" |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
140 gateway_jid = event.GetEventObject().gateway_jid |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
141 id = self.host.bridge.gatewayRegister("CANCEL",gateway_jid, None) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
142 self.host.current_action_ids.add(id) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
143 print "unregister id:",id |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
144 self.MakeModal(False) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
145 self.Destroy() |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
146 event.Skip() |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
147 |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
148 button_font = wx.Font(6, wx.DEFAULT, wx.NORMAL, wx.BOLD) |
28 | 149 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
|
150 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
|
151 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
|
152 self.panel.Bind(wx.EVT_BUTTON, register_cb, reg_button) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
153 unreg_button = wx.Button(self.panel, -1, "Unregister", size=wx.Size(-1, 8)) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
154 unreg_button.SetFont(button_font) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
155 unreg_button.gateway_jid = JID(gateway) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
156 self.panel.Bind(wx.EVT_BUTTON, unregister_cb, unreg_button) |
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
157 |
29
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
158 self.panel.sizer.Add(im_icon) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
159 self.panel.sizer.Add(label) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
160 self.panel.sizer.Add(type_label) |
df3b0b5ac49e
Wix: gateways manager => better presentation
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
161 self.panel.sizer.Add(reg_button, 1, wx.EXPAND) |
37
a61beb21d16d
Gateway registration, unregistration & edition
Goffi <goffi@goffi.org>
parents:
35
diff
changeset
|
162 self.panel.sizer.Add(unreg_button, 1, wx.EXPAND) |
28 | 163 |
164 | |
165 def onClose(self, event): | |
166 """Close event""" | |
167 debug("close") | |
168 self.MakeModal(False) | |
169 event.Skip() | |
170 |