Mercurial > libervia-backend
annotate frontends/wix/main_window.py @ 42:874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
- new xep-0054 plugin, avatar are cached, new getProfile bridge method
- gateways plugin (XEP-0100): new __private__ key in resulting data, used to keep target jid
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 21 Dec 2009 13:22:11 +1100 |
parents | 3e24753b9e0b |
children | 8c67ea98ab91 |
rev | line source |
---|---|
0 | 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 import wx | |
24 from chat import Chat | |
25 from param import Param | |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
26 from form import Form |
28 | 27 from gateways import GatewaysManager |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
28 from profile import Profile |
0 | 29 import gobject |
30 import os.path | |
31 import pdb | |
32 from tools.jid import JID | |
33 from logging import debug, info, error | |
34 from quick_frontend.quick_chat_list import QuickChatList | |
35 from quick_frontend.quick_contact_list import QuickContactList | |
36 from quick_frontend.quick_app import QuickApp | |
37 | |
38 | |
39 msgOFFLINE = "offline" | |
40 msgONLINE = "online" | |
41 idCONNECT = 1 | |
1 | 42 idDISCONNECT = 2 |
43 idEXIT = 3 | |
44 idPARAM = 4 | |
45 idADD_CONTACT = 5 | |
46 idREMOVE_CONTACT = 6 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
47 idSHOW_PROFILE = 7 |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
48 idFIND_GATEWAYS = 8 |
0 | 49 const_DEFAULT_GROUP = "Unclassed" |
50 const_STATUS = {"Online":"", | |
51 "Want to discuss":"chat", | |
52 "AFK":"away", | |
53 "Do Not Disturb":"dnd", | |
54 "Away":"xa"} | |
55 | |
56 class ChatList(QuickChatList): | |
57 """This class manage the list of chat windows""" | |
58 | |
59 def __init__(self, host): | |
60 QuickChatList.__init__(self, host) | |
61 | |
62 def createChat(self, name): | |
63 return Chat(name, self.host) | |
64 | |
65 | |
66 | |
67 class ContactList(wx.TreeCtrl, QuickContactList): | |
68 """Customized control to manage contacts.""" | |
69 | |
70 def __init__(self, parent): | |
71 wx.TreeCtrl.__init__(self, parent, style = wx.TR_HIDE_ROOT | wx.TR_HAS_BUTTONS) | |
72 QuickContactList.__init__(self) | |
73 self.jid_ids={} | |
74 self.groups={} | |
75 self.root=self.AddRoot("") | |
76 self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.onActivated, self) | |
77 | |
78 #icons | |
79 isz = (16,16) | |
80 il = wx.ImageList(isz[0], isz[1]) | |
81 self.icon_online = il.Add(wx.ArtProvider_GetBitmap(wx.ART_TICK_MARK, wx.ART_OTHER, isz)) | |
82 self.icon_unavailable = il.Add(wx.ArtProvider_GetBitmap(wx.ART_CROSS_MARK, wx.ART_OTHER, isz)) | |
83 self.AssignImageList(il) | |
84 | |
85 self.__addNode(const_DEFAULT_GROUP) | |
86 | |
87 def __addNode(self, label): | |
88 """Add an item container""" | |
89 ret=self.AppendItem(self.root, label) | |
90 self.SetPyData(ret, "[node]") | |
91 self.SetItemBold(ret) | |
92 self.groups[label]=ret | |
93 | |
94 def replace(self, jid, name="", show="", status="", group=""): | |
95 debug("status = %s show = %s",status, show) | |
96 if not self.jid_ids.has_key(jid): | |
97 self.add(jid, name, show, status, group) | |
98 else: | |
99 debug ("updating %s",jid) | |
100 self.__presentItem(jid, name, show, status, group) | |
101 | |
102 def __presentItem(self, jid, name, show, status, group): | |
103 """Make a nice presentation of the contact in the list.""" | |
104 id=self.jid_ids[jid] | |
105 label= "%s [%s] \n %s" % ((name or jid), (show or "online"), status) | |
106 self.SetItemText(id, label) | |
107 | |
108 # icon | |
109 if not show or show=="chat": | |
110 self.SetItemImage(id, self.icon_online) | |
111 else: | |
112 self.SetItemImage(id, self.icon_unavailable) | |
113 | |
114 #colour | |
115 if not show: | |
116 self.SetItemTextColour(id, wx.BLACK) | |
117 elif show=="chat": | |
118 self.SetItemTextColour(id, wx.GREEN) | |
119 elif show=="away": | |
120 self.SetItemTextColour(id, wx.BLUE) | |
121 else: | |
122 self.SetItemTextColour(id, wx.RED) | |
123 | |
124 def add(self, jid, name="", show="", status="", group=""): | |
125 """add a contact to the list""" | |
126 debug ("adding %s",jid) | |
127 dest_group=group or const_DEFAULT_GROUP | |
128 if not self.groups.has_key(dest_group): | |
129 self.__addNode(dest_group) | |
130 self.jid_ids[jid]=self.AppendItem(self.groups[dest_group], "") | |
131 self.__presentItem(jid, name, show, status, group) | |
132 self.SetPyData(self.jid_ids[jid], "[contact]"+jid) | |
133 self.EnsureVisible(self.jid_ids[jid]) | |
134 self.Refresh() #FIXME: Best way ? | |
135 | |
136 def remove(self, jid): | |
137 """remove a contact from the list""" | |
138 debug ("removing %s",jid) | |
139 self.Delete(self.jid_ids[jid]) | |
140 del self.jid_ids[jid] | |
141 self.Refresh() #FIXME: Best way ? | |
142 | |
143 def onActivated(self, event): | |
144 """Called when a contact is clicked or activated with keyboard.""" | |
145 if self.GetPyData(event.GetItem()).startswith("[contact]"): | |
146 self.onActivatedCB(self.GetPyData(event.GetItem())[9:]) | |
147 else: | |
148 event.Skip() | |
149 | |
150 def getSelection(self): | |
151 """Return the selected contact, or an empty string if there is not""" | |
152 data = self.GetPyData(self.GetSelection()) | |
153 if not data or not data.startswith("[contact]"): | |
154 return "" | |
155 return JID(data[9:]) | |
156 | |
157 def registerActivatedCB(self, cb): | |
158 """Register a callback with manage contact activation.""" | |
159 self.onActivatedCB=cb | |
160 | |
161 class MainWindow(wx.Frame, QuickApp): | |
162 """main app window""" | |
163 | |
164 def __init__(self): | |
165 wx.Frame.__init__(self,None, title="SAT Wix", size=(400,200)) | |
166 | |
167 | |
168 #Frame elements | |
169 self.contactList = ContactList(self) | |
170 self.contactList.registerActivatedCB(self.onContactActivated) | |
171 self.chat_wins=ChatList(self) | |
172 self.CreateStatusBar() | |
173 self.SetStatusText(msgOFFLINE) | |
174 self.createMenus() | |
175 | |
176 #ToolBar | |
177 self.tools=self.CreateToolBar() | |
178 self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=const_STATUS.keys(), | |
179 style=wx.CB_DROPDOWN | wx.CB_READONLY) | |
180 self.tools.AddControl(self.statusBox) | |
181 self.tools.AddSeparator() | |
182 self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER) | |
183 self.tools.AddControl(self.statusTxt) | |
184 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox) | |
185 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt) | |
186 self.tools.Disable() | |
11 | 187 |
188 #tray icon | |
189 ticon = wx.Icon("images/tray_icon.xpm", wx.BITMAP_TYPE_XPM) | |
190 self.tray_icon = wx.TaskBarIcon() | |
191 self.tray_icon.SetIcon(ticon, "Wix jabber client") | |
192 wx.EVT_TASKBAR_LEFT_UP(self.tray_icon, self.onTrayClick) | |
193 | |
0 | 194 |
195 #events | |
196 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
197 | |
198 QuickApp.__init__(self) | |
199 | |
200 self.Show() | |
201 | |
202 def createMenus(self): | |
203 info("Creating menus") | |
204 connectMenu = wx.Menu() | |
205 connectMenu.Append(idCONNECT, "&Connect CTRL-c"," Connect to the server") | |
1 | 206 connectMenu.Append(idDISCONNECT, "&Disconnect CTRL-d"," Disconnect from the server") |
0 | 207 connectMenu.Append(idPARAM,"&Parameters"," Configure the program") |
208 connectMenu.AppendSeparator() | |
209 connectMenu.Append(idEXIT,"E&xit"," Terminate the program") | |
210 contactMenu = wx.Menu() | |
211 contactMenu.Append(idADD_CONTACT, "&Add contact"," Add a contact to your list") | |
212 contactMenu.Append(idREMOVE_CONTACT, "&Remove contact"," Remove the selected contact from your list") | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
213 contactMenu.AppendSeparator() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
214 contactMenu.Append(idSHOW_PROFILE, "&Show profile", " Show contact's profile") |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
215 communicationMenu = wx.Menu() |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
216 communicationMenu.Append(idFIND_GATEWAYS, "&Find Gateways"," Find gateways to legacy IM") |
0 | 217 menuBar = wx.MenuBar() |
218 menuBar.Append(connectMenu,"&General") | |
219 menuBar.Append(contactMenu,"&Contacts") | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
220 menuBar.Append(communicationMenu,"&Communication") |
0 | 221 self.SetMenuBar(menuBar) |
222 | |
223 #events | |
224 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest) | |
1 | 225 wx.EVT_MENU(self, idDISCONNECT, self.onDisconnectRequest) |
0 | 226 wx.EVT_MENU(self, idPARAM, self.onParam) |
227 wx.EVT_MENU(self, idEXIT, self.onExit) | |
228 wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact) | |
229 wx.EVT_MENU(self, idREMOVE_CONTACT, self.onRemoveContact) | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
230 wx.EVT_MENU(self, idSHOW_PROFILE, self.onShowProfile) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
231 wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways) |
0 | 232 |
233 | |
234 def newMessage(self, from_jid, msg, type, to_jid): | |
235 QuickApp.newMessage(self, from_jid, msg, type, to_jid) | |
236 | |
237 def showAlert(self, message): | |
238 # TODO: place this in a separate class | |
239 popup=wx.PopupWindow(self) | |
240 ### following code come from wxpython demo | |
241 popup.SetBackgroundColour("CADET BLUE") | |
242 st = wx.StaticText(popup, -1, message, pos=(10,10)) | |
243 sz = st.GetBestSize() | |
244 popup.SetSize( (sz.width+20, sz.height+20) ) | |
245 x=(wx.DisplaySize()[0]-popup.GetSize()[0])/2 | |
246 popup.SetPosition((x,0)) | |
247 popup.Show() | |
248 wx.CallLater(5000,popup.Destroy) | |
249 | |
250 def showDialog(self, message, title="", type="info"): | |
251 if type == 'info': | |
252 flags = wx.OK | wx.ICON_INFORMATION | |
253 elif type == 'error': | |
254 flags = wx.OK | wx.ICON_ERROR | |
255 elif type == 'question': | |
256 flags = wx.OK | wx.ICON_QUESTION | |
257 else: | |
258 flags = wx.OK | wx.ICON_INFORMATION | |
259 dlg = wx.MessageDialog(self, message, title, flags) | |
260 answer = dlg.ShowModal() | |
261 dlg.Destroy() | |
262 return True if (answer == wx.ID_YES or answer == wx.ID_OK) else False | |
263 | |
264 def setStatusOnline(self, online=True): | |
265 """enable/disable controls, must be called when local user online status change""" | |
266 if online: | |
267 self.SetStatusText(msgONLINE) | |
268 self.tools.Enable() | |
269 else: | |
270 self.SetStatusText(msgOFFLINE) | |
271 self.tools.Disable() | |
272 return | |
273 | |
274 | |
275 def presenceUpdate(self, jabber_id, type, show, status, priority): | |
276 QuickApp.presenceUpdate(self, jabber_id, type, show, status, priority) | |
277 | |
278 def askConfirmation(self, type, id, data): | |
279 #TODO: refactor this in QuickApp | |
280 debug ("Confirmation asked") | |
281 answer_data={} | |
282 if type == "FILE_TRANSFERT": | |
283 debug ("File transfert confirmation asked") | |
284 dlg = wx.MessageDialog(self, "The contact %s wants to send you the file %s\nDo you accept ?" % (data["from"], data["filename"]), | |
285 'File Request', | |
286 wx.YES_NO | wx.ICON_QUESTION | |
287 ) | |
288 answer=dlg.ShowModal() | |
289 if answer==wx.ID_YES: | |
290 filename = wx.FileSelector("Where do you want to save the file ?", flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) | |
291 if filename: | |
292 answer_data["dest_path"] = filename | |
293 self.bridge.confirmationAnswer(id, True, answer_data) | |
294 self.waitProgress(id, "File Transfer", "Copying %s" % os.path.basename(filename)) | |
295 else: | |
296 answer = wx.ID_NO | |
297 if answer==wx.ID_NO: | |
298 self.bridge.confirmationAnswer(id, False, answer_data) | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
299 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
300 dlg.Destroy() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
301 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
302 elif type == "YES/NO": |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
303 debug ("Yes/No confirmation asked") |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
304 dlg = wx.MessageDialog(self, data["message"], |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
305 'Confirmation', |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
306 wx.YES_NO | wx.ICON_QUESTION |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
307 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
308 answer=dlg.ShowModal() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
309 if answer==wx.ID_YES: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
310 self.bridge.confirmationAnswer(id, True, {}) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
311 if answer==wx.ID_NO: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
312 self.bridge.confirmationAnswer(id, False, {}) |
0 | 313 |
314 dlg.Destroy() | |
315 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
316 def actionResult(self, type, id, data): |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
317 debug ("actionResult: type = [%s] id = [%s] data = [%s]" % (type, id, data)) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
318 if type == "SUPPRESS": |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
319 self.current_action_ids.remove(id) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
320 elif type == "SUCCESS": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
321 self.current_action_ids.remove(id) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
322 dlg = wx.MessageDialog(self, data["message"], |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
323 'Success', |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
324 wx.OK | wx.ICON_INFORMATION |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
325 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
326 dlg.ShowModal() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
327 dlg.Destroy() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
328 elif type == "ERROR": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
329 self.current_action_ids.remove(id) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
330 dlg = wx.MessageDialog(self, data["message"], |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
331 'Error', |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
332 wx.OK | wx.ICON_ERROR |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
333 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
334 dlg.ShowModal() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
335 dlg.Destroy() |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
336 elif type == "FORM": |
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
337 self.current_action_ids.remove(id) |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
338 debug ("Form received") |
36 | 339 form=Form(self, title='Registration', target = data['target'], type = data['type'], xml_data = data['xml']) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
340 elif type == "RESULT": |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
341 self.current_action_ids.remove(id) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
342 if self.current_action_ids_cb.has_key(id): |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
343 callback = self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
344 del self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
345 callback(data) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
346 elif type == "DICT_DICT": |
28 | 347 self.current_action_ids.remove(id) |
348 if self.current_action_ids_cb.has_key(id): | |
349 callback = self.current_action_ids_cb[id] | |
350 del self.current_action_ids_cb[id] | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
351 callback(data) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
352 print ("Dict of dict found as result") |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
353 else: |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
354 error ("FIXME FIXME FIXME: type [%s] not implemented" % type) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
355 raise NotImplementedError |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
356 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
357 |
0 | 358 |
359 def progressCB(self, id, title, message): | |
360 data = self.bridge.getProgress(id) | |
361 if data: | |
362 if not data['position']: | |
363 data['position'] = '0' | |
364 if not self.pbar: | |
365 #first answer, we must construct the bar | |
366 self.pbar = wx.ProgressDialog(title, message, int(data['size']), None, | |
367 wx.PD_SMOOTH | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME) | |
368 self.pbar.finish_value = int(data['size']) | |
369 | |
370 self.pbar.Update(int(data['position'])) | |
371 elif self.pbar: | |
372 self.pbar.Update(self.pbar.finish_value) | |
373 return | |
374 | |
375 wx.CallLater(10, self.progressCB, id, title, message) | |
376 | |
377 def waitProgress (self, id, title, message): | |
378 self.pbar = None | |
379 wx.CallLater(10, self.progressCB, id, title, message) | |
380 | |
381 | |
382 | |
383 ### events ### | |
384 | |
385 def onContactActivated(self, jid): | |
386 debug ("onContactActivated: %s", jid) | |
387 if self.chat_wins[jid].IsShown(): | |
388 self.chat_wins[jid].Hide() | |
389 else: | |
390 self.chat_wins[jid].Show() | |
391 | |
392 def onConnectRequest(self, e): | |
393 self.bridge.connect() | |
394 | |
1 | 395 def onDisconnectRequest(self, e): |
396 self.bridge.disconnect() | |
397 | |
0 | 398 def __updateStatus(self): |
399 show = const_STATUS[self.statusBox.GetValue()] | |
400 status = self.statusTxt.GetValue() | |
401 self.bridge.setPresence(show=show, status=status) | |
402 | |
403 def onStatusChange(self, e): | |
404 debug("Status change request") | |
405 self.__updateStatus() | |
406 | |
407 def onParam(self, e): | |
408 debug("Param request") | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
409 param=Param(self) |
0 | 410 |
411 def onExit(self, e): | |
412 self.Close() | |
413 | |
414 def onAddContact(self, e): | |
415 debug("Add contact request") | |
416 dlg = wx.TextEntryDialog( | |
417 self, 'Please enter new contact JID', | |
38 | 418 'Adding a contact', 'name@server.tld') |
0 | 419 |
420 if dlg.ShowModal() == wx.ID_OK: | |
421 jid=JID(dlg.GetValue()) | |
422 if jid.is_valid(): | |
423 self.bridge.addContact(jid.short) | |
424 else: | |
425 error ("'%s' is an invalid JID !", jid) | |
426 #TODO: notice the user | |
427 | |
428 dlg.Destroy() | |
429 | |
430 def onRemoveContact(self, e): | |
431 debug("Remove contact request") | |
432 target = self.contactList.getSelection() | |
433 if not target: | |
434 dlg = wx.MessageDialog(self, "You haven't selected any contact !", | |
435 'Error', | |
436 wx.OK | wx.ICON_ERROR | |
437 ) | |
438 dlg.ShowModal() | |
439 dlg.Destroy() | |
440 return | |
441 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
442 dlg = wx.MessageDialog(self, "Are you sure you want to delete %s from your roster list ?" % target.short, |
0 | 443 'Contact suppression', |
444 wx.YES_NO | wx.ICON_QUESTION | |
445 ) | |
446 | |
447 if dlg.ShowModal() == wx.ID_YES: | |
448 info("Unsubsribing %s presence", target.short) | |
449 self.bridge.delContact(target.short) | |
450 | |
451 dlg.Destroy() | |
452 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
453 def onShowProfile(self, e): |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
454 debug("Show contact's profile request") |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
455 target = self.contactList.getSelection() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
456 if not target: |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
457 dlg = wx.MessageDialog(self, "You haven't selected any contact !", |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
458 'Error', |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
459 wx.OK | wx.ICON_ERROR |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
460 ) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
461 dlg.ShowModal() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
462 dlg.Destroy() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
463 return |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
464 id = self.bridge.getProfile(target.short) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
465 self.current_action_ids.add(id) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
466 self.current_action_ids_cb[id] = self.onProfileReceived |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
467 |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
468 def onProfileReceived(self, data): |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
469 """Called when a profile is received""" |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
470 debug ('Profile received: [%s]' % data) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
471 profile=Profile(self, data) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
472 |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
473 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
474 def onFindGateways(self, e): |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
475 debug("Find Gateways request") |
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
476 id = self.bridge.findGateways(self.whoami.domain) |
28 | 477 self.current_action_ids.add(id) |
478 self.current_action_ids_cb[id] = self.onGatewaysFound | |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
479 print "Find Gateways id=", id |
28 | 480 |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
481 def onGatewaysFound(self, data): |
28 | 482 """Called when SàT has found the server gateways""" |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
483 target = data['__private__']['target'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
484 del data['__private__'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
485 gatewayManager = GatewaysManager(self, data, server=target) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
486 |
0 | 487 def onClose(self, e): |
488 info("Exiting...") | |
489 e.Skip() | |
11 | 490 |
491 def onTrayClick(self, e): | |
492 debug("Tray Click") | |
493 if self.IsShown(): | |
494 self.Hide() | |
495 else: | |
496 self.Show() | |
497 self.Raise() | |
498 e.Skip() | |
0 | 499 |