Mercurial > libervia-backend
annotate frontends/wix/main_window.py @ 189:757518d05833
Primitivus: added nick completion
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 18 Aug 2010 20:50:45 +0800 |
parents | fd2db62ea5eb |
children | 1438a1337732 |
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 | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
105
diff
changeset
|
102 |
0 | 103 QuickApp.__init__(self) |
68 | 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.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND) | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
105
diff
changeset
|
113 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
105
diff
changeset
|
114 self.postInit() |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
105
diff
changeset
|
115 |
0 | 116 self.Show() |
117 | |
68 | 118 def plug_profile(self, profile_key='@DEFAULT@'): |
119 """Hide profile panel then plug profile""" | |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
120 debug (_('plugin profile %s' % profile_key)) |
68 | 121 self.profile_pan.Hide() |
122 self.contactList.Show() | |
123 self.sizer.Layout() | |
124 for i in range(self.menuBar.GetMenuCount()): | |
125 self.menuBar.EnableTop(i, True) | |
126 super(MainWindow, self).plug_profile(profile_key) | |
127 | |
0 | 128 def createMenus(self): |
70 | 129 info(_("Creating menus")) |
0 | 130 connectMenu = wx.Menu() |
70 | 131 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server")) |
132 connectMenu.Append(idDISCONNECT, _("&Disconnect CTRL-d"),_(" Disconnect from the server")) | |
133 connectMenu.Append(idPARAM,_("&Parameters"),_(" Configure the program")) | |
0 | 134 connectMenu.AppendSeparator() |
70 | 135 connectMenu.Append(idEXIT,_("E&xit"),_(" Terminate the program")) |
0 | 136 contactMenu = wx.Menu() |
70 | 137 contactMenu.Append(idADD_CONTACT, _("&Add contact"),_(" Add a contact to your list")) |
138 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
|
139 contactMenu.AppendSeparator() |
70 | 140 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
|
141 communicationMenu = wx.Menu() |
72 | 142 communicationMenu.Append(idJOIN_ROOM, _("&Join Room"),_(" Join a Multi-User Chat room")) |
70 | 143 communicationMenu.Append(idFIND_GATEWAYS, _("&Find Gateways"),_(" Find gateways to legacy IM")) |
68 | 144 self.menuBar = wx.MenuBar() |
70 | 145 self.menuBar.Append(connectMenu,_("&General")) |
146 self.menuBar.Append(contactMenu,_("&Contacts")) | |
147 self.menuBar.Append(communicationMenu,_("&Communication")) | |
68 | 148 self.SetMenuBar(self.menuBar) |
0 | 149 |
101 | 150 #additionals menus |
151 #FIXME: do this in a more generic way (in quickapp) | |
152 add_menus = self.bridge.getMenus() | |
153 for menu in add_menus: | |
154 category,item,type = menu | |
155 assert(type=="NORMAL") #TODO: manage other types | |
156 menu_idx = self.menuBar.FindMenu(category) | |
157 current_menu = None | |
158 if menu_idx == wx.NOT_FOUND: | |
159 #the menu is new, we create it | |
160 current_menu = wx.Menu() | |
161 self.menuBar.Append(current_menu, category) | |
162 else: | |
163 current_menu = self.menuBar.GetMenu(menu_idx) | |
164 assert(current_menu != None) | |
165 item_id = wx.NewId() | |
166 help_string = self.bridge.getMenuHelp(category, item, type) | |
167 current_menu.Append(item_id, item, help = help_string) | |
168 #now we register the event | |
169 def event_answer(e): | |
170 id = self.bridge.callMenu(category, item, type) | |
171 self.current_action_ids.add(id) | |
172 wx.EVT_MENU(self, item_id, event_answer) | |
173 | |
174 | |
0 | 175 #events |
176 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest) | |
1 | 177 wx.EVT_MENU(self, idDISCONNECT, self.onDisconnectRequest) |
0 | 178 wx.EVT_MENU(self, idPARAM, self.onParam) |
179 wx.EVT_MENU(self, idEXIT, self.onExit) | |
180 wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact) | |
181 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
|
182 wx.EVT_MENU(self, idSHOW_PROFILE, self.onShowProfile) |
72 | 183 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
|
184 wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways) |
0 | 185 |
186 | |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
187 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
|
188 QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile) |
0 | 189 |
72 | 190 def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile): |
191 super(MainWindow, self).roomJoined(room_id, room_service, room_nicks, user_nick, profile) | |
192 | |
0 | 193 def showAlert(self, message): |
194 # TODO: place this in a separate class | |
195 popup=wx.PopupWindow(self) | |
196 ### following code come from wxpython demo | |
197 popup.SetBackgroundColour("CADET BLUE") | |
198 st = wx.StaticText(popup, -1, message, pos=(10,10)) | |
199 sz = st.GetBestSize() | |
200 popup.SetSize( (sz.width+20, sz.height+20) ) | |
201 x=(wx.DisplaySize()[0]-popup.GetSize()[0])/2 | |
202 popup.SetPosition((x,0)) | |
203 popup.Show() | |
204 wx.CallLater(5000,popup.Destroy) | |
205 | |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
206 def showDialog(self, message, title="", type="info", answer_cb = None, answer_data = None): |
0 | 207 if type == 'info': |
208 flags = wx.OK | wx.ICON_INFORMATION | |
209 elif type == 'error': | |
210 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
|
211 elif type == 'yes/no': |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
212 flags = wx.YES_NO | wx.ICON_QUESTION |
0 | 213 else: |
214 flags = wx.OK | wx.ICON_INFORMATION | |
70 | 215 error(_('unmanaged dialog type: %s'), type) |
0 | 216 dlg = wx.MessageDialog(self, message, title, flags) |
217 answer = dlg.ShowModal() | |
218 dlg.Destroy() | |
182
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
219 if answer_cb: |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
220 data = [answer_data] if answer_data else [] |
556c2bd7c344
Primitivus now implement showDialog + new "newAlert" bridge method to show a dialog from core
Goffi <goffi@goffi.org>
parents:
180
diff
changeset
|
221 answer_cb(True if (answer == wx.ID_YES or answer == wx.ID_OK) else False, *data) |
0 | 222 |
223 def setStatusOnline(self, online=True): | |
224 """enable/disable controls, must be called when local user online status change""" | |
225 if online: | |
226 self.SetStatusText(msgONLINE) | |
227 self.tools.Enable() | |
228 else: | |
229 self.SetStatusText(msgOFFLINE) | |
230 self.tools.Disable() | |
231 return | |
232 | |
233 def askConfirmation(self, type, id, data): | |
234 #TODO: refactor this in QuickApp | |
70 | 235 debug (_("Confirmation asked")) |
0 | 236 answer_data={} |
237 if type == "FILE_TRANSFERT": | |
70 | 238 debug (_("File transfert confirmation asked")) |
239 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"]}, | |
240 _('File Request'), | |
0 | 241 wx.YES_NO | wx.ICON_QUESTION |
242 ) | |
243 answer=dlg.ShowModal() | |
244 if answer==wx.ID_YES: | |
70 | 245 filename = wx.FileSelector(_("Where do you want to save the file ?"), flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) |
0 | 246 if filename: |
247 answer_data["dest_path"] = filename | |
248 self.bridge.confirmationAnswer(id, True, answer_data) | |
70 | 249 self.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename)) |
0 | 250 else: |
251 answer = wx.ID_NO | |
252 if answer==wx.ID_NO: | |
253 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
|
254 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
255 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
|
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 elif type == "YES/NO": |
70 | 258 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
|
259 dlg = wx.MessageDialog(self, data["message"], |
70 | 260 _('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
|
261 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
|
262 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
263 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
|
264 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
|
265 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
|
266 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
|
267 self.bridge.confirmationAnswer(id, False, {}) |
0 | 268 |
269 dlg.Destroy() | |
270 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
271 def actionResult(self, type, id, data): |
70 | 272 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
|
273 if not id in self.current_action_ids: |
70 | 274 debug (_('unknown id, ignoring')) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
275 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
|
276 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
|
277 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
|
278 elif type == "SUCCESS": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
279 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
|
280 dlg = wx.MessageDialog(self, data["message"], |
70 | 281 _('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
|
282 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
|
283 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
284 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
|
285 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
|
286 elif type == "ERROR": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
287 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
|
288 dlg = wx.MessageDialog(self, data["message"], |
70 | 289 _('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
|
290 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
|
291 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
292 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
|
293 dlg.Destroy() |
103 | 294 elif type == "XMLUI": |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
295 self.current_action_ids.remove(id) |
103 | 296 debug (_("XML user interface received")) |
91 | 297 misc = {} |
298 #FIXME FIXME FIXME: must clean all this crap ! | |
299 title = _('Form') | |
300 if data['type'] == _('registration'): | |
103 | 301 title = _('Registration') |
91 | 302 misc['target'] = data['target'] |
303 misc['action_back'] = self.bridge.gatewayRegister | |
103 | 304 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
|
305 elif type == "RESULT": |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
306 self.current_action_ids.remove(id) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
307 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
|
308 callback = self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
309 del self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
310 callback(data) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
311 elif type == "DICT_DICT": |
28 | 312 self.current_action_ids.remove(id) |
313 if self.current_action_ids_cb.has_key(id): | |
314 callback = self.current_action_ids_cb[id] | |
315 del self.current_action_ids_cb[id] | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
316 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
|
317 else: |
70 | 318 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
|
319 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
|
320 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
321 |
0 | 322 |
323 def progressCB(self, id, title, message): | |
324 data = self.bridge.getProgress(id) | |
325 if data: | |
326 if not self.pbar: | |
327 #first answer, we must construct the bar | |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
120
diff
changeset
|
328 self.pbar = wx.ProgressDialog(title, message, float(data['size']), None, |
0 | 329 wx.PD_SMOOTH | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME) |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
120
diff
changeset
|
330 self.pbar.finish_value = float(data['size']) |
0 | 331 |
332 self.pbar.Update(int(data['position'])) | |
333 elif self.pbar: | |
334 self.pbar.Update(self.pbar.finish_value) | |
335 return | |
336 | |
337 wx.CallLater(10, self.progressCB, id, title, message) | |
338 | |
339 def waitProgress (self, id, title, message): | |
340 self.pbar = None | |
341 wx.CallLater(10, self.progressCB, id, title, message) | |
342 | |
343 | |
344 | |
345 ### events ### | |
346 | |
347 def onContactActivated(self, jid): | |
70 | 348 debug (_("onContactActivated: %s"), jid) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
349 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
|
350 self.chat_wins[jid.short].Hide() |
0 | 351 else: |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
352 self.chat_wins[jid.short].Show() |
0 | 353 |
354 def onConnectRequest(self, e): | |
68 | 355 self.bridge.connect(self.profile) |
0 | 356 |
1 | 357 def onDisconnectRequest(self, e): |
68 | 358 self.bridge.disconnect(self.profile) |
1 | 359 |
0 | 360 def __updateStatus(self): |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
361 show = filter(lambda x:x[1] == self.statusBox.GetValue(), const_STATUS)[0][0] |
0 | 362 status = self.statusTxt.GetValue() |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
363 self.bridge.setPresence(show=show, statuses={'default':status}, profile_key=self.profile) #FIXME: manage multilingual statuses |
0 | 364 |
365 def onStatusChange(self, e): | |
70 | 366 debug(_("Status change request")) |
0 | 367 self.__updateStatus() |
368 | |
369 def onParam(self, e): | |
70 | 370 debug(_("Param request")) |
105 | 371 #xmlui = self.bridge.getParamsUI(self.profile) |
372 #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
|
373 param=Param(self) |
0 | 374 |
375 def onExit(self, e): | |
376 self.Close() | |
377 | |
378 def onAddContact(self, e): | |
70 | 379 debug(_("Add contact request")) |
0 | 380 dlg = wx.TextEntryDialog( |
70 | 381 self, _('Please enter new contact JID'), |
382 _('Adding a contact'), _('name@server.tld')) | |
0 | 383 |
384 if dlg.ShowModal() == wx.ID_OK: | |
385 jid=JID(dlg.GetValue()) | |
386 if jid.is_valid(): | |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
387 self.bridge.addContact(jid.short, profile_key=self.profile) |
0 | 388 else: |
70 | 389 error (_("'%s' is an invalid JID !"), jid) |
0 | 390 #TODO: notice the user |
391 | |
392 dlg.Destroy() | |
393 | |
394 def onRemoveContact(self, e): | |
70 | 395 debug(_("Remove contact request")) |
0 | 396 target = self.contactList.getSelection() |
397 if not target: | |
70 | 398 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), |
399 _('Error'), | |
0 | 400 wx.OK | wx.ICON_ERROR |
401 ) | |
402 dlg.ShowModal() | |
403 dlg.Destroy() | |
404 return | |
405 | |
70 | 406 dlg = wx.MessageDialog(self, _("Are you sure you want to delete %s from your roster list ?") % target.short, |
407 _('Contact suppression'), | |
0 | 408 wx.YES_NO | wx.ICON_QUESTION |
409 ) | |
410 | |
411 if dlg.ShowModal() == wx.ID_YES: | |
70 | 412 info(_("Unsubscribing %s presence"), target.short) |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
413 self.bridge.delContact(target.short, profile_key=self.profile) |
0 | 414 |
415 dlg.Destroy() | |
416 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
417 def onShowProfile(self, e): |
70 | 418 debug(_("Show contact's profile request")) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
419 target = self.contactList.getSelection() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
420 if not target: |
70 | 421 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), |
422 _('Error'), | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
423 wx.OK | wx.ICON_ERROR |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
424 ) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
425 dlg.ShowModal() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
426 dlg.Destroy() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
427 return |
89
23caf1051099
multi-profile/subscription misc fixes
Goffi <goffi@goffi.org>
parents:
85
diff
changeset
|
428 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
|
429 self.current_action_ids.add(id) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
430 self.current_action_ids_cb[id] = self.onProfileReceived |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
431 |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
432 def onProfileReceived(self, data): |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
433 """Called when a profile is received""" |
70 | 434 debug (_('Profile received: [%s]') % data) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
435 profile=Profile(self, data) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
436 |
72 | 437 def onJoinRoom(self, e): |
438 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
|
439 #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
|
440 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
|
441 self, _("Please enter MUC's JID"), |
120 | 442 _('Entering a MUC room'), 'test@conference.necton2.int') |
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 #_('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
|
444 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
|
445 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
|
446 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
|
447 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
|
448 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
|
449 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
|
450 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
451 def onFindGateways(self, e): |
70 | 452 debug(_("Find Gateways request")) |
102 | 453 id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain, self.profile) |
28 | 454 self.current_action_ids.add(id) |
455 self.current_action_ids_cb[id] = self.onGatewaysFound | |
456 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
457 def onGatewaysFound(self, data): |
28 | 458 """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
|
459 target = data['__private__']['target'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
460 del data['__private__'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
461 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
|
462 |
0 | 463 def onClose(self, e): |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
464 QuickApp.onExit(self) |
70 | 465 info(_("Exiting...")) |
183
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
466 for win in self.chat_wins: |
9ee4a1d0d7fb
Added auto(dis)connect params + misc
Goffi <goffi@goffi.org>
parents:
182
diff
changeset
|
467 self.chat_wins[win].Destroy() |
0 | 468 e.Skip() |
11 | 469 |
470 def onTrayClick(self, e): | |
70 | 471 debug(_("Tray Click")) |
11 | 472 if self.IsShown(): |
473 self.Hide() | |
474 else: | |
475 self.Show() | |
476 self.Raise() | |
477 e.Skip() | |
0 | 478 |