Mercurial > libervia-backend
annotate frontends/wix/main_window.py @ 72:f271fff3a713
MUC implementation: first draft
/!\ the experimental muc branche of wokkel must be used
- bridge: new roomJoined signal
- wix: contact list widget is now in a separate file, and manage different kinds of presentation
- wix: chat window now manage group chat (first draft, not working yet)
- wix: constants are now in a separate class, so then can be accessible from everywhere
- wix: new menu to join room (do nothing yet, except entering in a test room)
- new plugin for xep 0045 (MUC), use wokkel experimental MUC branch
- plugins: the profile is now given for get_handler, cause it can be used internally by a plugin (e.g.: xep-0045 plugin)
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 21 Mar 2010 10:28:55 +1100 |
parents | 8f2ed279784b |
children | 7322a41f8a8e |
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 | |
35
c45deebb40a5
Wix: Registration form management (not finished yet)
Goffi <goffi@goffi.org>
parents:
33
diff
changeset
|
30 from form import Form |
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 self.createMenus() | |
68 | 80 for i in range(self.menuBar.GetMenuCount()): |
81 self.menuBar.EnableTop(i, False) | |
0 | 82 |
83 #ToolBar | |
84 self.tools=self.CreateToolBar() | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
85 self.statusBox = wx.ComboBox(self.tools, -1, "Online", choices=[status[1] for status in const_STATUS], |
0 | 86 style=wx.CB_DROPDOWN | wx.CB_READONLY) |
87 self.tools.AddControl(self.statusBox) | |
88 self.tools.AddSeparator() | |
89 self.statusTxt=wx.TextCtrl(self.tools, -1, style = wx.TE_PROCESS_ENTER) | |
90 self.tools.AddControl(self.statusTxt) | |
91 self.Bind(wx.EVT_COMBOBOX, self.onStatusChange, self.statusBox) | |
92 self.Bind(wx.EVT_TEXT_ENTER, self.onStatusChange, self.statusTxt) | |
93 self.tools.Disable() | |
11 | 94 |
95 #tray icon | |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
96 ticon = wx.Icon(IMAGE_DIR+'/crystal/tray_icon.xpm', wx.BITMAP_TYPE_XPM) |
11 | 97 self.tray_icon = wx.TaskBarIcon() |
70 | 98 self.tray_icon.SetIcon(ticon, _("Wix jabber client")) |
11 | 99 wx.EVT_TASKBAR_LEFT_UP(self.tray_icon, self.onTrayClick) |
100 | |
0 | 101 |
102 #events | |
103 self.Bind(wx.EVT_CLOSE, self.onClose, self) | |
104 | |
105 QuickApp.__init__(self) | |
68 | 106 #self.plug_profile() #gof: |
107 | |
108 #profile panel | |
109 self.profile_pan = ProfileManager(self) | |
110 #self.profile_pan.Hide() #gof: | |
111 self.sizer.Add(self.profile_pan, 1, flag=wx.EXPAND) | |
52 | 112 |
0 | 113 self.Show() |
114 | |
68 | 115 def plug_profile(self, profile_key='@DEFAULT@'): |
116 """Hide profile panel then plug profile""" | |
117 self.profile_pan.Hide() | |
118 self.contactList.Show() | |
119 self.sizer.Layout() | |
120 for i in range(self.menuBar.GetMenuCount()): | |
121 self.menuBar.EnableTop(i, True) | |
122 super(MainWindow, self).plug_profile(profile_key) | |
123 if not self.bridge.isConnected(profile_key): | |
124 self.bridge.connect(profile_key) | |
125 | |
0 | 126 def createMenus(self): |
70 | 127 info(_("Creating menus")) |
0 | 128 connectMenu = wx.Menu() |
70 | 129 connectMenu.Append(idCONNECT, _("&Connect CTRL-c"),_(" Connect to the server")) |
130 connectMenu.Append(idDISCONNECT, _("&Disconnect CTRL-d"),_(" Disconnect from the server")) | |
131 connectMenu.Append(idPARAM,_("&Parameters"),_(" Configure the program")) | |
0 | 132 connectMenu.AppendSeparator() |
70 | 133 connectMenu.Append(idEXIT,_("E&xit"),_(" Terminate the program")) |
0 | 134 contactMenu = wx.Menu() |
70 | 135 contactMenu.Append(idADD_CONTACT, _("&Add contact"),_(" Add a contact to your list")) |
136 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
|
137 contactMenu.AppendSeparator() |
70 | 138 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
|
139 communicationMenu = wx.Menu() |
72 | 140 communicationMenu.Append(idJOIN_ROOM, _("&Join Room"),_(" Join a Multi-User Chat room")) |
70 | 141 communicationMenu.Append(idFIND_GATEWAYS, _("&Find Gateways"),_(" Find gateways to legacy IM")) |
68 | 142 self.menuBar = wx.MenuBar() |
70 | 143 self.menuBar.Append(connectMenu,_("&General")) |
144 self.menuBar.Append(contactMenu,_("&Contacts")) | |
145 self.menuBar.Append(communicationMenu,_("&Communication")) | |
68 | 146 self.SetMenuBar(self.menuBar) |
0 | 147 |
148 #events | |
149 wx.EVT_MENU(self, idCONNECT, self.onConnectRequest) | |
1 | 150 wx.EVT_MENU(self, idDISCONNECT, self.onDisconnectRequest) |
0 | 151 wx.EVT_MENU(self, idPARAM, self.onParam) |
152 wx.EVT_MENU(self, idEXIT, self.onExit) | |
153 wx.EVT_MENU(self, idADD_CONTACT, self.onAddContact) | |
154 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
|
155 wx.EVT_MENU(self, idSHOW_PROFILE, self.onShowProfile) |
72 | 156 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
|
157 wx.EVT_MENU(self, idFIND_GATEWAYS, self.onFindGateways) |
0 | 158 |
159 | |
67
0e50dd3a234a
message sending bug fixes + sortilege update
Goffi <goffi@goffi.org>
parents:
66
diff
changeset
|
160 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
|
161 QuickApp.newMessage(self, from_jid, msg, type, to_jid, profile) |
0 | 162 |
72 | 163 def roomJoined(self, room_id, room_service, room_nicks, user_nick, profile): |
164 super(MainWindow, self).roomJoined(room_id, room_service, room_nicks, user_nick, profile) | |
165 self.chat_wins[room_id+'@'+room_service].setType("group") | |
166 self.chat_wins[room_id+'@'+room_service].setPresents([user_nick]+room_nicks) | |
167 | |
0 | 168 def showAlert(self, message): |
169 # TODO: place this in a separate class | |
170 popup=wx.PopupWindow(self) | |
171 ### following code come from wxpython demo | |
172 popup.SetBackgroundColour("CADET BLUE") | |
173 st = wx.StaticText(popup, -1, message, pos=(10,10)) | |
174 sz = st.GetBestSize() | |
175 popup.SetSize( (sz.width+20, sz.height+20) ) | |
176 x=(wx.DisplaySize()[0]-popup.GetSize()[0])/2 | |
177 popup.SetPosition((x,0)) | |
178 popup.Show() | |
179 wx.CallLater(5000,popup.Destroy) | |
180 | |
181 def showDialog(self, message, title="", type="info"): | |
182 if type == 'info': | |
183 flags = wx.OK | wx.ICON_INFORMATION | |
184 elif type == 'error': | |
185 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
|
186 elif type == 'yes/no': |
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
187 flags = wx.YES_NO | wx.ICON_QUESTION |
0 | 188 else: |
189 flags = wx.OK | wx.ICON_INFORMATION | |
70 | 190 error(_('unmanaged dialog type: %s'), type) |
0 | 191 dlg = wx.MessageDialog(self, message, title, flags) |
192 answer = dlg.ShowModal() | |
193 dlg.Destroy() | |
194 return True if (answer == wx.ID_YES or answer == wx.ID_OK) else False | |
195 | |
196 def setStatusOnline(self, online=True): | |
197 """enable/disable controls, must be called when local user online status change""" | |
198 if online: | |
199 self.SetStatusText(msgONLINE) | |
200 self.tools.Enable() | |
201 else: | |
202 self.SetStatusText(msgOFFLINE) | |
203 self.tools.Disable() | |
204 return | |
205 | |
206 def askConfirmation(self, type, id, data): | |
207 #TODO: refactor this in QuickApp | |
70 | 208 debug (_("Confirmation asked")) |
0 | 209 answer_data={} |
210 if type == "FILE_TRANSFERT": | |
70 | 211 debug (_("File transfert confirmation asked")) |
212 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"]}, | |
213 _('File Request'), | |
0 | 214 wx.YES_NO | wx.ICON_QUESTION |
215 ) | |
216 answer=dlg.ShowModal() | |
217 if answer==wx.ID_YES: | |
70 | 218 filename = wx.FileSelector(_("Where do you want to save the file ?"), flags = wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT) |
0 | 219 if filename: |
220 answer_data["dest_path"] = filename | |
221 self.bridge.confirmationAnswer(id, True, answer_data) | |
70 | 222 self.waitProgress(id, _("File Transfer"), _("Copying %s") % os.path.basename(filename)) |
0 | 223 else: |
224 answer = wx.ID_NO | |
225 if answer==wx.ID_NO: | |
226 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
|
227 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
228 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
|
229 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
230 elif type == "YES/NO": |
70 | 231 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
|
232 dlg = wx.MessageDialog(self, data["message"], |
70 | 233 _('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
|
234 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
|
235 ) |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
236 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
|
237 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
|
238 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
|
239 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
|
240 self.bridge.confirmationAnswer(id, False, {}) |
0 | 241 |
242 dlg.Destroy() | |
243 | |
22
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
244 def actionResult(self, type, id, data): |
70 | 245 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
|
246 if not id in self.current_action_ids: |
70 | 247 debug (_('unknown id, ignoring')) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
248 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
|
249 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
|
250 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
|
251 elif type == "SUCCESS": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
252 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
|
253 dlg = wx.MessageDialog(self, data["message"], |
70 | 254 _('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
|
255 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
|
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.ShowModal() |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
258 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
|
259 elif type == "ERROR": |
23
925ab466c5ec
better presentation for register new account
Goffi <goffi@goffi.org>
parents:
22
diff
changeset
|
260 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
|
261 dlg = wx.MessageDialog(self, data["message"], |
70 | 262 _('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
|
263 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
|
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 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 dlg.Destroy() |
33
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
267 elif type == "FORM": |
b9bb5d8e0cc7
In-band-registration: data form 2 xml conversion
Goffi <goffi@goffi.org>
parents:
28
diff
changeset
|
268 self.current_action_ids.remove(id) |
70 | 269 debug (_("Form received")) |
270 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
|
271 elif type == "RESULT": |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
272 self.current_action_ids.remove(id) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
273 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
|
274 callback = self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
275 del self.current_action_ids_cb[id] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
276 callback(data) |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
277 elif type == "DICT_DICT": |
28 | 278 self.current_action_ids.remove(id) |
279 if self.current_action_ids_cb.has_key(id): | |
280 callback = self.current_action_ids_cb[id] | |
281 del self.current_action_ids_cb[id] | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
282 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
|
283 else: |
70 | 284 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
|
285 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
|
286 |
bb72c29f3432
added action cb mechanism for buttons. Tested with a temporary new user registration button.
Goffi <goffi@goffi.org>
parents:
18
diff
changeset
|
287 |
0 | 288 |
289 def progressCB(self, id, title, message): | |
290 data = self.bridge.getProgress(id) | |
291 if data: | |
292 if not data['position']: | |
293 data['position'] = '0' | |
294 if not self.pbar: | |
295 #first answer, we must construct the bar | |
296 self.pbar = wx.ProgressDialog(title, message, int(data['size']), None, | |
297 wx.PD_SMOOTH | wx.PD_ELAPSED_TIME | wx.PD_ESTIMATED_TIME | wx.PD_REMAINING_TIME) | |
298 self.pbar.finish_value = int(data['size']) | |
299 | |
300 self.pbar.Update(int(data['position'])) | |
301 elif self.pbar: | |
302 self.pbar.Update(self.pbar.finish_value) | |
303 return | |
304 | |
305 wx.CallLater(10, self.progressCB, id, title, message) | |
306 | |
307 def waitProgress (self, id, title, message): | |
308 self.pbar = None | |
309 wx.CallLater(10, self.progressCB, id, title, message) | |
310 | |
311 | |
312 | |
313 ### events ### | |
314 | |
315 def onContactActivated(self, jid): | |
70 | 316 debug (_("onContactActivated: %s"), jid) |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
317 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
|
318 self.chat_wins[jid.short].Hide() |
0 | 319 else: |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
320 self.chat_wins[jid.short].Show() |
0 | 321 |
322 def onConnectRequest(self, e): | |
68 | 323 self.bridge.connect(self.profile) |
0 | 324 |
1 | 325 def onDisconnectRequest(self, e): |
68 | 326 self.bridge.disconnect(self.profile) |
1 | 327 |
0 | 328 def __updateStatus(self): |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
329 show = filter(lambda x:x[1] == self.statusBox.GetValue(), const_STATUS)[0][0] |
0 | 330 status = self.statusTxt.GetValue() |
51
8c67ea98ab91
frontend improved to take into account new SàT features
Goffi <goffi@goffi.org>
parents:
42
diff
changeset
|
331 self.bridge.setPresence(show=show, statuses={'default':status}) #FIXME: manage multilingual statuses |
0 | 332 |
333 def onStatusChange(self, e): | |
70 | 334 debug(_("Status change request")) |
0 | 335 self.__updateStatus() |
336 | |
337 def onParam(self, e): | |
70 | 338 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
|
339 param=Param(self) |
0 | 340 |
341 def onExit(self, e): | |
342 self.Close() | |
343 | |
344 def onAddContact(self, e): | |
70 | 345 debug(_("Add contact request")) |
0 | 346 dlg = wx.TextEntryDialog( |
70 | 347 self, _('Please enter new contact JID'), |
348 _('Adding a contact'), _('name@server.tld')) | |
0 | 349 |
350 if dlg.ShowModal() == wx.ID_OK: | |
351 jid=JID(dlg.GetValue()) | |
352 if jid.is_valid(): | |
353 self.bridge.addContact(jid.short) | |
354 else: | |
70 | 355 error (_("'%s' is an invalid JID !"), jid) |
0 | 356 #TODO: notice the user |
357 | |
358 dlg.Destroy() | |
359 | |
360 def onRemoveContact(self, e): | |
70 | 361 debug(_("Remove contact request")) |
0 | 362 target = self.contactList.getSelection() |
363 if not target: | |
70 | 364 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), |
365 _('Error'), | |
0 | 366 wx.OK | wx.ICON_ERROR |
367 ) | |
368 dlg.ShowModal() | |
369 dlg.Destroy() | |
370 return | |
371 | |
70 | 372 dlg = wx.MessageDialog(self, _("Are you sure you want to delete %s from your roster list ?") % target.short, |
373 _('Contact suppression'), | |
0 | 374 wx.YES_NO | wx.ICON_QUESTION |
375 ) | |
376 | |
377 if dlg.ShowModal() == wx.ID_YES: | |
70 | 378 info(_("Unsubscribing %s presence"), target.short) |
0 | 379 self.bridge.delContact(target.short) |
380 | |
381 dlg.Destroy() | |
382 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
383 def onShowProfile(self, e): |
70 | 384 debug(_("Show contact's profile request")) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
385 target = self.contactList.getSelection() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
386 if not target: |
70 | 387 dlg = wx.MessageDialog(self, _("You haven't selected any contact !"), |
388 _('Error'), | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
389 wx.OK | wx.ICON_ERROR |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
390 ) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
391 dlg.ShowModal() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
392 dlg.Destroy() |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
393 return |
64 | 394 id = self.bridge.getCard(target.short) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
395 self.current_action_ids.add(id) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
396 self.current_action_ids_cb[id] = self.onProfileReceived |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
397 |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
398 def onProfileReceived(self, data): |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
399 """Called when a profile is received""" |
70 | 400 debug (_('Profile received: [%s]') % data) |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
401 profile=Profile(self, data) |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
402 |
72 | 403 def onJoinRoom(self, e): |
404 warning('FIXME: temporary menu, must be improved') | |
405 self.bridge.joinMUC("conference.necton2.int", "test", "Goffi \o/", self.profile) | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
406 |
25
53e921c8a357
new plugin: gateways plugin, and first implementation of findGateways
Goffi <goffi@goffi.org>
parents:
23
diff
changeset
|
407 def onFindGateways(self, e): |
70 | 408 debug(_("Find Gateways request")) |
66
8147b4f40809
SàT: multi-profile: DBus signals and frontend adaptation (first draft)
Goffi <goffi@goffi.org>
parents:
64
diff
changeset
|
409 id = self.bridge.findGateways(self.profiles[self.profile]['whoami'].domain) |
28 | 410 self.current_action_ids.add(id) |
411 self.current_action_ids_cb[id] = self.onGatewaysFound | |
412 | |
42
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
413 def onGatewaysFound(self, data): |
28 | 414 """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
|
415 target = data['__private__']['target'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
416 del data['__private__'] |
874de3020e1c
Initial VCard (XEP-0054) support + misc fixes
Goffi <goffi@goffi.org>
parents:
38
diff
changeset
|
417 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
|
418 |
0 | 419 def onClose(self, e): |
70 | 420 info(_("Exiting...")) |
0 | 421 e.Skip() |
11 | 422 |
423 def onTrayClick(self, e): | |
70 | 424 debug(_("Tray Click")) |
11 | 425 if self.IsShown(): |
426 self.Hide() | |
427 else: | |
428 self.Show() | |
429 self.Raise() | |
430 e.Skip() | |
0 | 431 |