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