Mercurial > libervia-backend
annotate frontends/wix/main_window.py @ 117:1f0fd6f03e2b
misc fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 03 Jul 2010 12:01:01 +0800 |
parents | d2630fba8dfd |
children | ded2431cea5a |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 wix: a SAT frontend | |
57 | 6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) |
0 | 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 | |
70 | 23 from quick_frontend.quick_chat_list import QuickChatList |
24 from quick_frontend.quick_app import QuickApp | |
25 from quick_frontend.quick_contact_management import QuickContactManagement | |
0 | 26 import wx |
72 | 27 from contact_list import ContactList |
0 | 28 from chat import Chat |
29 from param import Param | |
103 | 30 from xmlui import XMLUI |
28 | 31 from gateways import GatewaysManager |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
32 from profile import Profile |
68 | 33 from profile_manager import ProfileManager |
0 | 34 import gobject |
35 import os.path | |
36 import pdb | |
37 from tools.jid import JID | |
72 | 38 from logging import debug, info, warning, error |
39 import constants | |
0 | 40 |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
41 idCONNECT,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
42 idDISCONNECT,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
43 idEXIT,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
44 idPARAM,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
45 idADD_CONTACT,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
46 idREMOVE_CONTACT,\ |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
47 idSHOW_PROFILE,\ |
72 | 48 idJOIN_ROOM,\ |
49 idFIND_GATEWAYS = range(9) | |
0 | 50 |
51 class ChatList(QuickChatList): | |
52 """This class manage the list of chat windows""" | |
53 | |
54 def __init__(self, host): | |
55 QuickChatList.__init__(self, host) | |
56 | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
57 def createChat(self, target): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
58 return Chat(target, self.host) |
0 | 59 |
60 class MainWindow(wx.Frame, QuickApp): | |
61 """main app window""" | |
62 | |
63 def __init__(self): | |
68 | 64 wx.Frame.__init__(self,None, title="SàT Wix", size=(300,500)) |
56 | 65 self.CM = QuickContactManagement() #FIXME: not the best place |
0 | 66 |
68 | 67 #sizer |
68 self.sizer = wx.BoxSizer(wx.VERTICAL) | |
69 self.SetSizer(self.sizer) | |
70 | |
0 | 71 #Frame elements |
72 | 72 self.contactList = ContactList(self, self) |
0 | 73 self.contactList.registerActivatedCB(self.onContactActivated) |
68 | 74 self.contactList.Hide() |
75 self.sizer.Add(self.contactList, 1, flag=wx.EXPAND) | |
76 | |
0 | 77 self.chat_wins=ChatList(self) |
78 self.CreateStatusBar() | |
79 | |
80 #ToolBar | |
81 self.tools=self.CreateToolBar() | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
82 self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=[status[1] for status in const_STATUS], |
0 | 83 style=wx.CB_DROPDOWN | wx.CB_READONLY) |
84 self.tools.AddControl(self.statusBox) | |
85 self.tools.AddSeparator() | |
86 self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER) | |
87 self.tools.AddControl(self.statusTxt) | |
88 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox) | |
89 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt) | |
90 self.tools.Disable() | |
11 | 91 |
92 #tray icon | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
93 ticon = wx.Icon(IMAGE_DIR+'/crystal/tray_icon.xpm', wx.BITMAP_TYPE_XPM) |
11 | 94 self.tray_icon = wx.TaskBarIcon() |
70 | 95 self.tray_icon.SetIcon(ticon, _("Wix jabber client")) |
11 | 96 wx.EVT_TASKBAR_LEFT_UP(self.tray_icon, self.onTrayClick) |
97 | |
0 | 98 |
99 #events | |
100 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
101 | |
102 QuickApp.__init__(self) | |
68 | 103 #self.plug_profile() #gof: |
104 | |
101 | 105 #menus |
106 self.createMenus() | |
107 for i in range(self.menuBar.GetMenuCount()): | |
108 self.menuBar.EnableTop(i, False) | |
109 | |
68 | 110 #profile panel |
111 self.profile_pan = ProfileManager(self) | |
112 #self.profile_pan.Hide() #gof: | |
113 self.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND) | |
91 | 114 if self.options.profile: #TODO: move this to quick_app |
115 self.plug_profile(self.options.profile) | |
116 | |
81 | 117 |
0 | 118 self.Show() |
119 | |
68 | 120 def plug_profile(self, profile_key='@DEFAULT@'): |
121 """Hide profile panel then plug profile""" | |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
122 debug (_('plugin profile %s' % profile_key)) |
68 | 123 self.profile_pan.Hide() |
124 self.contactList.Show() | |
125 self.sizer.Layout() | |
126 for i in range(self.menuBar.GetMenuCount()): | |
127 self.menuBar.EnableTop(i, True) | |
128 super(MainWindow, self).plug_profile(profile_key) | |
129 if not self.bridge.isConnected(profile_key): | |
130 self.bridge.connect(profile_key) | |
131 | |
0 | 132 def createMenus(self): |
70 | 133 info(_("Creating menus")) |
0 | 134 connectMenu = wx.Menu() |
70 | 135 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server")) |
136 connectMenu.Append(idDISCONNECT, _("&Disconnect CTRL-d"),_(" Disconnect from the server")) | |
137 connectMenu.Append(idPARAM,_("&Parameters"),_(" Configure the program")) | |
0 | 138 connectMenu.AppendSeparator() |
70 | 139 connectMenu.Append(idEXIT,_("E&xit"),_(" Terminate the program")) |
0 | 140 contactMenu = wx.Menu() |
70 | 141 contactMenu.Append(idADD_CONTACT, _("&Add contact"),_(" Add a contact to your list")) |
142 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
|
143 contactMenu.AppendSeparator() |
70 | 144 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
|
145 communicationMenu = wx.Menu() |
72 | 146 communicationMenu.Append(idJOIN_ROOM, _("&Join Room"),_(" Join a Multi-User Chat room")) |
70 | 147 communicationMenu.Append(idFIND_GATEWAYS, _("&Find Gateways"),_(" Find gateways to legacy IM")) |
68 | 148 self.menuBar = wx.MenuBar() |
70 | 149 self.menuBar.Append(connectMenu,_("&General")) |
150 self.menuBar.Append(contactMenu,_("&Contacts")) | |
151 self.menuBar.Append(communicationMenu,_("&Communication")) | |
68 | 152 self.SetMenuBar(self.menuBar) |
0 | 153 |
101 | 154 #additionals menus |
155 #FIXME: do this in a more generic way (in quickapp) | |
156 add_menus = self.bridge.getMenus() | |
157 for menu in add_menus: | |
158 category,item,type = menu | |
159 assert(type=="NORMAL") #TODO: manage other types | |
160 menu_idx = self.menuBar.FindMenu(category) | |
161 current_menu = None | |
162 if menu_idx == wx.NOT_FOUND: | |
163 #the menu is new, we create it | |
164 current_menu = wx.Menu() | |
165 self.menuBar.Append(current_menu, category) | |
166 else: | |
167 current_menu = self.menuBar.GetMenu(menu_idx) | |
168 assert(current_menu != None) | |
169 item_id = wx.NewId() | |
170 help_string = self.bridge.getMenuHelp(category, item, type) | |
171 current_menu.Append(item_id, item, help = help_string) | |
172 #now we register the event | |
173 def event_answer(e): | |
174 id = self.bridge.callMenu(category, item, type) | |
175 self.current_action_ids.add(id) | |
176 wx.EVT_MENU(self, item_id, event_answer) | |
177 | |
178 | |
0 | 179 #events |
180 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest) | |
1 | 181 wx.EVT_MENU(self, idDISCONNECT, self.onDisconnectRequest) |
0 | 182 wx.EVT_MENU(self, idPARAM, self.onParam) |
183 wx.EVT_MENU(self, idEXIT, self.onExit) | |
184 wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact) | |
185 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
|
186 wx.EVT_MENU(self, idSHOW_PROFILE, self.onShowProfile) |
72 | 187 wx.EVT_MENU(self, idJOIN_ROOM, self.onJoinRoom) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
188 wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways) |
0 | 189 |
190 | |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
191 def newMessage(self, from_jid, msg, type, to_jid, profile): |
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
192 QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile) |
0 | 193 |
72 | 194 def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile): |
195 super(MainWindow, self).roomJoined(room_id, room_service, room_nicks, user_nick, profile) | |
196 | |
0 | 197 def showAlert(self, message): |
198 # TODO: place this in a separate class | |
199 popup=wx.PopupWindow(self) | |
200 ### following code come from wxpython demo | |
201 popup.SetBackgroundColour("CADET BLUE") | |
202 st = wx.StaticText(popup, -1, message, pos=(10,10)) | |
203 sz = st.GetBestSize() | |
204 popup.SetSize( (sz.width+20, sz.height+20) ) | |
205 x=(wx.DisplaySize()[0]-popup.GetSize()[0])/2 | |
206 popup.SetPosition((x,0)) | |
207 popup.Show() | |
208 wx.CallLater(5000,popup.Destroy) | |
209 | |
210 def showDialog(self, message, title="", type="info"): | |
211 if type == 'info': | |
212 flags = wx.OK | wx.ICON_INFORMATION | |
213 elif type == 'error': | |
214 flags = wx.OK | wx.ICON_ERROR | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
215 elif type == 'yes/no': |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
216 flags = wx.YES_NO | wx.ICON_QUESTION |
0 | 217 else: |
218 flags = wx.OK | wx.ICON_INFORMATION | |
70 | 219 error(_('unmanaged dialog type: %s'), type) |
0 | 220 dlg = wx.MessageDialog(self, message, title, flags) |
221 answer = dlg.ShowModal() | |
222 dlg.Destroy() | |
223 return True if (answer == wx.ID_YES or answer == wx.ID_OK) else False | |
224 | |
225 def setStatusOnline(self, online=True): | |
226 """enable/disable controls, must be called when local user online status change""" | |
227 if online: | |
228 self.SetStatusText(msgONLINE) | |
229 self.tools.Enable() | |
230 else: | |
231 self.SetStatusText(msgOFFLINE) | |
232 self.tools.Disable() | |
233 return | |
234 | |
235 def askConfirmation(self, type, id, data): | |
236 #TODO: refactor this in QuickApp | |
70 | 237 debug (_("Confirmation asked")) |
0 | 238 answer_data={} |
239 if type == "FILE_TRANSFERT": | |
70 | 240 debug (_("File transfert confirmation asked")) |
241 dlg = wx.MessageDialog(self, _("The contact %(jid)s wants to send you the file %(filename)s\nDo you accept ?") % {'jid':data["from"], 'filename':data["filename"]}, | |
242 _('File Request'), | |
0 | 243 wx.YES_NO | wx.ICON_QUESTION |
244 ) | |
245 answer=dlg.ShowModal() | |
246 if answer==wx.ID_YES: | |
70 | 247 filename = wx.FileSelector(_("Where do you want to save the file ?"), flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) |
0 | 248 if filename: |
249 answer_data["dest_path"] = filename | |
250 self.bridge.confirmationAnswer(id, True, answer_data) | |
70 | 251 self.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename)) |
0 | 252 else: |
253 answer = wx.ID_NO | |
254 if answer==wx.ID_NO: | |
255 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
|
256 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
257 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
|
258 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
259 elif type == "YES/NO": |
70 | 260 debug (_("Yes/No confirmation asked")) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
261 dlg = wx.MessageDialog(self, data["message"], |
70 | 262 _('Confirmation'), |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
263 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
|
264 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
265 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
|
266 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
|
267 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
|
268 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
|
269 self.bridge.confirmationAnswer(id, False, {}) |
0 | 270 |
271 dlg.Destroy() | |
272 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
273 def actionResult(self, type, id, data): |
70 | 274 debug (_("actionResult: type = [%(type)s] id = [%(id)s] data = [%(data)s]") % {'type':type, 'id':id, 'data':data}) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
275 if not id in self.current_action_ids: |
70 | 276 debug (_('unknown id, ignoring')) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
277 return |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
278 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
|
279 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
|
280 elif type == "SUCCESS": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
281 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
|
282 dlg = wx.MessageDialog(self, data["message"], |
70 | 283 _('Success'), |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
284 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
|
285 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
286 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
|
287 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
|
288 elif type == "ERROR": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
289 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
|
290 dlg = wx.MessageDialog(self, data["message"], |
70 | 291 _('Error'), |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
292 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
|
293 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
294 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
|
295 dlg.Destroy() |
103 | 296 elif type == "XMLUI": |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
297 self.current_action_ids.remove(id) |
103 | 298 debug (_("XML user interface received")) |
91 | 299 misc = {} |
300 #FIXME FIXME FIXME: must clean all this crap ! | |
301 title = _('Form') | |
302 if data['type'] == _('registration'): | |
103 | 303 title = _('Registration') |
91 | 304 misc['target'] = data['target'] |
305 misc['action_back'] = self.bridge.gatewayRegister | |
103 | 306 XMLUI(self, title=title, xml_data = data['xml'], misc = misc) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
307 elif type == "RESULT": |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
308 self.current_action_ids.remove(id) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
309 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
|
310 callback = self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
311 del self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
312 callback(data) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
313 elif type == "DICT_DICT": |
28 | 314 self.current_action_ids.remove(id) |
315 if self.current_action_ids_cb.has_key(id): | |
316 callback = self.current_action_ids_cb[id] | |
317 del self.current_action_ids_cb[id] | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
318 callback(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
|
319 else: |
70 | 320 error (_("FIXME FIXME FIXME: type [%s] not implemented") % type) |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
321 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
|
322 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
323 |
0 | 324 |
325 def progressCB(self, id, title, message): | |
326 data = self.bridge.getProgress(id) | |
327 if data: | |
328 if not data['position']: | |
329 data['position'] = '0' | |
330 if not self.pbar: | |
331 #first answer, we must construct the bar | |
332 self.pbar = wx.ProgressDialog(title, message, int(data['size']), None, | |
333 wx.PD_SMOOTH | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME) | |
334 self.pbar.finish_value = int(data['size']) | |
335 | |
336 self.pbar.Update(int(data['position'])) | |
337 elif self.pbar: | |
338 self.pbar.Update(self.pbar.finish_value) | |
339 return | |
340 | |
341 wx.CallLater(10, self.progressCB, id, title, message) | |
342 | |
343 def waitProgress (self, id, title, message): | |
344 self.pbar = None | |
345 wx.CallLater(10, self.progressCB, id, title, message) | |
346 | |
347 | |
348 | |
349 ### events ### | |
350 | |
351 def onContactActivated(self, jid): | |
70 | 352 debug (_("onContactActivated: %s"), jid) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
353 if self.chat_wins[jid.short].IsShown(): |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
354 self.chat_wins[jid.short].Hide() |
0 | 355 else: |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
356 self.chat_wins[jid.short].Show() |
0 | 357 |
358 def onConnectRequest(self, e): | |
68 | 359 self.bridge.connect(self.profile) |
0 | 360 |
1 | 361 def onDisconnectRequest(self, e): |
68 | 362 self.bridge.disconnect(self.profile) |
1 | 363 |
0 | 364 def __updateStatus(self): |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
365 show = filter(lambda x:x[1] == self.statusBox.GetValue(), const_STATUS)[0][0] |
0 | 366 status = self.statusTxt.GetValue() |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
367 self.bridge.setPresence(show=show, statuses={'default':status}, profile_key=self.profile) #FIXME: manage multilingual statuses |
0 | 368 |
369 def onStatusChange(self, e): | |
70 | 370 debug(_("Status change request")) |
0 | 371 self.__updateStatus() |
372 | |
373 def onParam(self, e): | |
70 | 374 debug(_("Param request")) |
105 | 375 #xmlui = self.bridge.getParamsUI(self.profile) |
376 #XMLUI(self, xml_data = xmlui) | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
377 param=Param(self) |
0 | 378 |
379 def onExit(self, e): | |
380 self.Close() | |
381 | |
382 def onAddContact(self, e): | |
70 | 383 debug(_("Add contact request")) |
0 | 384 dlg = wx.TextEntryDialog( |
70 | 385 self, _('Please enter new contact JID'), |
386 _('Adding a contact'), _('name@server.tld')) | |
0 | 387 |
388 if dlg.ShowModal() == wx.ID_OK: | |
389 jid=JID(dlg.GetValue()) | |
390 if jid.is_valid(): | |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
391 self.bridge.addContact(jid.short, profile_key=self.profile) |
0 | 392 else: |
70 | 393 error (_("'%s' is an invalid JID !"), jid) |
0 | 394 #TODO: notice the user |
395 | |
396 dlg.Destroy() | |
397 | |
398 def onRemoveContact(self, e): | |
70 | 399 debug(_("Remove contact request")) |
0 | 400 target = self.contactList.getSelection() |
401 if not target: | |
70 | 402 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), |
403 _('Error'), | |
0 | 404 wx.OK | wx.ICON_ERROR |
405 ) | |
406 dlg.ShowModal() | |
407 dlg.Destroy() | |
408 return | |
409 | |
70 | 410 dlg = wx.MessageDialog(self, _("Are you sure you want to delete %s from your roster list ?") % target.short, |
411 _('Contact suppression'), | |
0 | 412 wx.YES_NO | wx.ICON_QUESTION |
413 ) | |
414 | |
415 if dlg.ShowModal() == wx.ID_YES: | |
70 | 416 info(_("Unsubscribing %s presence"), target.short) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
417 self.bridge.delContact(target.short, profile_key=self.profile) |
0 | 418 |
419 dlg.Destroy() | |
420 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
421 def onShowProfile(self, e): |
70 | 422 debug(_("Show contact's profile request")) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
423 target = self.contactList.getSelection() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
424 if not target: |
70 | 425 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), |
426 _('Error'), | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
427 wx.OK | wx.ICON_ERROR |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
428 ) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
429 dlg.ShowModal() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
430 dlg.Destroy() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
431 return |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
432 id = self.bridge.getCard(target.short, profile_key=self.profile) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
433 self.current_action_ids.add(id) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
434 self.current_action_ids_cb[id] = self.onProfileReceived |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
435 |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
436 def onProfileReceived(self, data): |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
437 """Called when a profile is received""" |
70 | 438 debug (_('Profile received: [%s]') % data) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
439 profile=Profile(self, data) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
440 |
72 | 441 def onJoinRoom(self, e): |
442 warning('FIXME: temporary menu, must be improved') | |
80
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
443 #TODO: a proper MUC room joining dialog with nickname etc |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
444 dlg = wx.TextEntryDialog( |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
445 self, _("Please enter MUC's JID"), |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
446 _('Entering a MUC room'), _('test@conference.necton2.int')) |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
447 #_('Entering a MUC room'), _('room@muc_service.server.tld')) |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
448 if dlg.ShowModal() == wx.ID_OK: |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
449 room_jid=JID(dlg.GetValue()) |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
450 if room_jid.is_valid(): |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
451 self.bridge.joinMUC(room_jid.domain, room_jid.node, self.profiles[self.profile]['whoami'].node, self.profile) |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
452 else: |
9681f18d06bd
wix: basic dialog to join MUC room, jid node is now displayed in conversations instead of full jid
Goffi <goffi@goffi.org>
parents:
75
diff
changeset
|
453 error (_("'%s' is an invalid JID !"), room_jid) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
454 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
455 def onFindGateways(self, e): |
70 | 456 debug(_("Find Gateways request")) |
102 | 457 id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain, self.profile) |
28 | 458 self.current_action_ids.add(id) |
459 self.current_action_ids_cb[id] = self.onGatewaysFound | |
460 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
461 def onGatewaysFound(self, data): |
28 | 462 """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
|
463 target = data['__private__']['target'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
464 del data['__private__'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
465 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
|
466 |
0 | 467 def onClose(self, e): |
70 | 468 info(_("Exiting...")) |
0 | 469 e.Skip() |
11 | 470 |
471 def onTrayClick(self, e): | |
70 | 472 debug(_("Tray Click")) |
11 | 473 if self.IsShown(): |
474 self.Hide() | |
475 else: | |
476 self.Show() | |
477 self.Raise() | |
478 e.Skip() | |
0 | 479 |